Skip to content

Commit

Permalink
Add workers ai staging flag (#5705)
Browse files Browse the repository at this point in the history
* Add workers ai staging flag

* add `staging` option to ai binding config

---------

Co-authored-by: Rahul Sethi <5822355+RamIdeas@users.noreply.github.com>
  • Loading branch information
G4brym and RamIdeas committed Apr 29, 2024
1 parent 76a456a commit 4097759
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/thin-wasps-bathe.md
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

Add `staging` flag to AI binding
1 change: 1 addition & 0 deletions packages/wrangler/src/config/environment.ts
Expand Up @@ -632,6 +632,7 @@ export interface EnvironmentNonInheritable {
ai:
| {
binding: string;
staging?: boolean;
}
| undefined;

Expand Down
13 changes: 10 additions & 3 deletions packages/wrangler/src/config/index.ts
Expand Up @@ -183,8 +183,10 @@ export function printBindings(bindings: CfWorkerInit["bindings"]) {
return `${s.substring(0, maxLength - 3)}...`;
};

const output: { type: string; entries: { key: string; value: string }[] }[] =
[];
const output: {
type: string;
entries: { key: string; value: string | boolean }[];
}[] = [];

const {
data_blobs,
Expand Down Expand Up @@ -419,9 +421,14 @@ export function printBindings(bindings: CfWorkerInit["bindings"]) {
}

if (ai !== undefined) {
const entries: [{ key: string; value: string | boolean }] = [
{ key: "Name", value: ai.binding },
];
if (ai.staging) entries.push({ key: "Staging", value: ai.staging });

output.push({
type: "AI",
entries: [{ key: "Name", value: ai.binding }],
entries: entries,
});
}

Expand Down
Expand Up @@ -42,7 +42,7 @@ export type WorkerMetadataBinding =
| { type: "wasm_module"; name: string; part: string }
| { type: "text_blob"; name: string; part: string }
| { type: "browser"; name: string }
| { type: "ai"; name: string }
| { type: "ai"; name: string; staging?: boolean }
| { type: "version_metadata"; name: string }
| { type: "data_blob"; name: string; part: string }
| { type: "kv_namespace"; name: string; namespace_id: string }
Expand Down Expand Up @@ -329,6 +329,7 @@ export function createWorkerUploadForm(worker: CfWorkerInit): FormData {
if (bindings.ai !== undefined) {
metadataBindings.push({
name: bindings.ai.binding,
staging: bindings.ai.staging,
type: "ai",
});
}
Expand Down
1 change: 1 addition & 0 deletions packages/wrangler/src/deployment-bundle/worker.ts
Expand Up @@ -111,6 +111,7 @@ export interface CfBrowserBinding {

export interface CfAIBinding {
binding: string;
staging?: boolean;
}

/**
Expand Down

0 comments on commit 4097759

Please sign in to comment.