@workglow/openai 0.3.24 → 0.3.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai/OpenAiProvider.d.ts +15 -0
- package/dist/ai/OpenAiProvider.d.ts.map +1 -1
- package/dist/ai/OpenAiQueuedProvider.d.ts +15 -0
- package/dist/ai/OpenAiQueuedProvider.d.ts.map +1 -1
- package/dist/ai/common/OpenAI_Client.d.ts +31 -0
- package/dist/ai/common/OpenAI_Client.d.ts.map +1 -1
- package/dist/ai/common/OpenAI_ModelSchema.d.ts +66 -0
- package/dist/ai/common/OpenAI_ModelSchema.d.ts.map +1 -1
- package/dist/ai/common/OpenAI_ModelSearch.d.ts.map +1 -1
- package/dist/ai/common/OpenAI_StructuredGeneration.d.ts +2 -0
- package/dist/ai/common/OpenAI_StructuredGeneration.d.ts.map +1 -1
- package/dist/ai/common/OpenAI_TextGeneration.d.ts.map +1 -1
- package/dist/ai/common/OpenAI_TextRewriter.d.ts +2 -1
- package/dist/ai/common/OpenAI_TextRewriter.d.ts.map +1 -1
- package/dist/ai/common/OpenAI_TextSummary.d.ts.map +1 -1
- package/dist/ai/common/OpenAI_ToolCalling.d.ts +2 -2
- package/dist/ai/common/OpenAI_ToolCalling.d.ts.map +1 -1
- package/dist/ai/index.d.ts +10 -0
- package/dist/ai/index.d.ts.map +1 -1
- package/dist/ai-runtime.browser.js +125 -78
- package/dist/ai-runtime.browser.js.map +9 -9
- package/dist/ai-runtime.js +125 -78
- package/dist/ai-runtime.js.map +9 -9
- package/dist/ai.browser.js +56 -1
- package/dist/ai.browser.js.map +4 -4
- package/dist/ai.js +148 -79
- package/dist/ai.js.map +11 -11
- package/package.json +12 -12
|
@@ -18,6 +18,11 @@ declare const OpenAiProvider_base: new (promiseRunFns?: readonly import("@workgl
|
|
|
18
18
|
credential_key?: string | undefined;
|
|
19
19
|
model_name: string;
|
|
20
20
|
organization?: string | undefined;
|
|
21
|
+
prompt_cache_key?: string | undefined;
|
|
22
|
+
reasoning?: {
|
|
23
|
+
effort?: "high" | "low" | "max" | "medium" | "minimal" | "none" | "xhigh" | undefined;
|
|
24
|
+
mode?: "pro" | undefined;
|
|
25
|
+
} | undefined;
|
|
21
26
|
trustedBaseUrl?: boolean | undefined;
|
|
22
27
|
};
|
|
23
28
|
title?: string | undefined;
|
|
@@ -34,6 +39,11 @@ declare const OpenAiProvider_base: new (promiseRunFns?: readonly import("@workgl
|
|
|
34
39
|
credential_key?: string | undefined;
|
|
35
40
|
model_name: string;
|
|
36
41
|
organization?: string | undefined;
|
|
42
|
+
prompt_cache_key?: string | undefined;
|
|
43
|
+
reasoning?: {
|
|
44
|
+
effort?: "high" | "low" | "max" | "medium" | "minimal" | "none" | "xhigh" | undefined;
|
|
45
|
+
mode?: "pro" | undefined;
|
|
46
|
+
} | undefined;
|
|
37
47
|
trustedBaseUrl?: boolean | undefined;
|
|
38
48
|
};
|
|
39
49
|
title?: string | undefined;
|
|
@@ -50,6 +60,11 @@ declare const OpenAiProvider_base: new (promiseRunFns?: readonly import("@workgl
|
|
|
50
60
|
credential_key?: string | undefined;
|
|
51
61
|
model_name: string;
|
|
52
62
|
organization?: string | undefined;
|
|
63
|
+
prompt_cache_key?: string | undefined;
|
|
64
|
+
reasoning?: {
|
|
65
|
+
effort?: "high" | "low" | "max" | "medium" | "minimal" | "none" | "xhigh" | undefined;
|
|
66
|
+
mode?: "pro" | undefined;
|
|
67
|
+
} | undefined;
|
|
53
68
|
trustedBaseUrl?: boolean | undefined;
|
|
54
69
|
};
|
|
55
70
|
title?: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenAiProvider.d.ts","sourceRoot":"","sources":["../../src/ai/OpenAiProvider.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC
|
|
1
|
+
{"version":3,"file":"OpenAiProvider.d.ts","sourceRoot":"","sources":["../../src/ai/OpenAiProvider.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKjD;;;;;;;;GAQG;AACH,qBAAa,cAAe,SAAQ,mBAGlC;IACS,iBAAiB,CAAC,KAAK,EAAE,WAAW,GAAG,SAAS,UAAU,EAAE,CAEpE;IAED,UAAmB,gBAAgB,IAAI,SAAS;QAAE,MAAM,EAAE,SAAS,UAAU,EAAE,CAAA;KAAE,EAAE,CAElF;CACF"}
|
|
@@ -18,6 +18,11 @@ declare const OpenAiQueuedProvider_base: new (promiseRunFns?: readonly import("@
|
|
|
18
18
|
credential_key?: string | undefined;
|
|
19
19
|
model_name: string;
|
|
20
20
|
organization?: string | undefined;
|
|
21
|
+
prompt_cache_key?: string | undefined;
|
|
22
|
+
reasoning?: {
|
|
23
|
+
effort?: "high" | "low" | "max" | "medium" | "minimal" | "none" | "xhigh" | undefined;
|
|
24
|
+
mode?: "pro" | undefined;
|
|
25
|
+
} | undefined;
|
|
21
26
|
trustedBaseUrl?: boolean | undefined;
|
|
22
27
|
};
|
|
23
28
|
title?: string | undefined;
|
|
@@ -34,6 +39,11 @@ declare const OpenAiQueuedProvider_base: new (promiseRunFns?: readonly import("@
|
|
|
34
39
|
credential_key?: string | undefined;
|
|
35
40
|
model_name: string;
|
|
36
41
|
organization?: string | undefined;
|
|
42
|
+
prompt_cache_key?: string | undefined;
|
|
43
|
+
reasoning?: {
|
|
44
|
+
effort?: "high" | "low" | "max" | "medium" | "minimal" | "none" | "xhigh" | undefined;
|
|
45
|
+
mode?: "pro" | undefined;
|
|
46
|
+
} | undefined;
|
|
37
47
|
trustedBaseUrl?: boolean | undefined;
|
|
38
48
|
};
|
|
39
49
|
title?: string | undefined;
|
|
@@ -50,6 +60,11 @@ declare const OpenAiQueuedProvider_base: new (promiseRunFns?: readonly import("@
|
|
|
50
60
|
credential_key?: string | undefined;
|
|
51
61
|
model_name: string;
|
|
52
62
|
organization?: string | undefined;
|
|
63
|
+
prompt_cache_key?: string | undefined;
|
|
64
|
+
reasoning?: {
|
|
65
|
+
effort?: "high" | "low" | "max" | "medium" | "minimal" | "none" | "xhigh" | undefined;
|
|
66
|
+
mode?: "pro" | undefined;
|
|
67
|
+
} | undefined;
|
|
53
68
|
trustedBaseUrl?: boolean | undefined;
|
|
54
69
|
};
|
|
55
70
|
title?: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenAiQueuedProvider.d.ts","sourceRoot":"","sources":["../../src/ai/OpenAiQueuedProvider.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC
|
|
1
|
+
{"version":3,"file":"OpenAiQueuedProvider.d.ts","sourceRoot":"","sources":["../../src/ai/OpenAiQueuedProvider.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAM1C;;;;;GAKG;AACH,qBAAa,oBAAqB,SAAQ,yBAGxC;IACS,iBAAiB,CAAC,KAAK,EAAE,WAAW,GAAG,SAAS,UAAU,EAAE,CAEpE;IAED,UAAmB,gBAAgB,IAAI,SAAS;QAAE,MAAM,EAAE,SAAS,UAAU,EAAE,CAAA;KAAE,EAAE,CAElF;CACF"}
|
|
@@ -13,5 +13,36 @@ type OpenAIClientClass = new (config: any) => any;
|
|
|
13
13
|
export declare function loadOpenAISDK(): Promise<OpenAIClientClass>;
|
|
14
14
|
export declare function getClient(model: OpenAiModelConfig | undefined): Promise<any>;
|
|
15
15
|
export declare function getModelName(model: OpenAiModelConfig | undefined): string;
|
|
16
|
+
/**
|
|
17
|
+
* Resolves the configured `reasoning` object for reasoning-capable models
|
|
18
|
+
* (the GPT-5.6 sol/terra/luna family and the o-series), sent verbatim as the
|
|
19
|
+
* Responses `reasoning` parameter. Returns `undefined` when unset so
|
|
20
|
+
* non-reasoning models and callers that don't opt in send no reasoning field.
|
|
21
|
+
*/
|
|
22
|
+
export declare function getReasoningConfig(model: OpenAiModelConfig | undefined): {
|
|
23
|
+
effort?: string;
|
|
24
|
+
mode?: string;
|
|
25
|
+
} | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Resolves the Responses `prompt_cache_key`. Uses an explicit
|
|
28
|
+
* `provider_config.prompt_cache_key` override when set, otherwise derives a
|
|
29
|
+
* stable key from the request's cache-relevant prefix (model + system
|
|
30
|
+
* instructions + tools) so requests sharing that prefix converge on one key and
|
|
31
|
+
* hit the cache. GPT-5.6 bills cache writes, so a stable key (not a random one)
|
|
32
|
+
* is the cost-correct default.
|
|
33
|
+
*/
|
|
34
|
+
export declare function resolvePromptCacheKey(model: OpenAiModelConfig | undefined, params: {
|
|
35
|
+
model?: unknown;
|
|
36
|
+
instructions?: unknown;
|
|
37
|
+
tools?: unknown;
|
|
38
|
+
}): string;
|
|
39
|
+
/**
|
|
40
|
+
* Applies the per-request Responses fields common to every OpenAI text run-fn:
|
|
41
|
+
* the model's `reasoning` config (when set) and a stable `prompt_cache_key`.
|
|
42
|
+
* Mutates and returns `params` so callers can inline it into the create call.
|
|
43
|
+
* Call this last, after model/instructions/tools are populated, so the cache
|
|
44
|
+
* key sees the full prefix.
|
|
45
|
+
*/
|
|
46
|
+
export declare function finalizeResponsesRequest(model: OpenAiModelConfig | undefined, params: Record<string, unknown>): Record<string, unknown>;
|
|
16
47
|
export {};
|
|
17
48
|
//# sourceMappingURL=OpenAI_Client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenAI_Client.d.ts","sourceRoot":"","sources":["../../../src/ai/common/OpenAI_Client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D;;;GAGG;AACH,eAAO,MAAM,oBAAoB,EAAE,SAAS,MAAM,EAA4C,CAAC;AAE/F,KAAK,iBAAiB,GAAG,KAAK,MAAM,EAAE,GAAG,KAAK,GAAG,CAAC;AAKlD,wBAAsB,aAAa,IAAI,OAAO,CAAC,iBAAiB,CAAC,CAShE;
|
|
1
|
+
{"version":3,"file":"OpenAI_Client.d.ts","sourceRoot":"","sources":["../../../src/ai/common/OpenAI_Client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D;;;GAGG;AACH,eAAO,MAAM,oBAAoB,EAAE,SAAS,MAAM,EAA4C,CAAC;AAE/F,KAAK,iBAAiB,GAAG,KAAK,MAAM,EAAE,GAAG,KAAK,GAAG,CAAC;AAKlD,wBAAsB,aAAa,IAAI,OAAO,CAAC,iBAAiB,CAAC,CAShE;AAkBD,wBAAsB,SAAS,CAAC,KAAK,EAAE,iBAAiB,GAAG,SAAS,gBA4BnE;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,SAAS,GAAG,MAAM,CAMzE;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,iBAAiB,GAAG,SAAS,GACnC;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAMhD;AAYD;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,iBAAiB,GAAG,SAAS,EACpC,MAAM,EAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAC;IAAC,YAAY,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,GACnE,MAAM,CASR;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,iBAAiB,GAAG,SAAS,EACpC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAKzB"}
|
|
@@ -40,6 +40,28 @@ export declare const OpenAiModelSchema: {
|
|
|
40
40
|
readonly type: "string";
|
|
41
41
|
readonly description: "OpenAI organization ID (optional).";
|
|
42
42
|
};
|
|
43
|
+
readonly prompt_cache_key: {
|
|
44
|
+
readonly type: "string";
|
|
45
|
+
readonly description: "Overrides the auto-derived Responses prompt_cache_key. Requests sharing a key share a cached prefix; leave unset to derive a stable key from the model + system instructions + tools.";
|
|
46
|
+
readonly "x-ui-hidden": true;
|
|
47
|
+
};
|
|
48
|
+
readonly reasoning: {
|
|
49
|
+
readonly type: "object";
|
|
50
|
+
readonly description: "Reasoning controls for reasoning-capable models (e.g. the GPT-5.6 sol/terra/luna family), sent on the Responses API.";
|
|
51
|
+
readonly properties: {
|
|
52
|
+
readonly effort: {
|
|
53
|
+
readonly type: "string";
|
|
54
|
+
readonly enum: readonly ["none", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
55
|
+
readonly description: "Reasoning effort. Higher effort trades latency and cost for quality.";
|
|
56
|
+
};
|
|
57
|
+
readonly mode: {
|
|
58
|
+
readonly type: "string";
|
|
59
|
+
readonly enum: readonly ["pro"];
|
|
60
|
+
readonly description: "Set to 'pro' for the quality-first pro configuration on supported models.";
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
readonly additionalProperties: false;
|
|
64
|
+
};
|
|
43
65
|
};
|
|
44
66
|
readonly required: readonly ["model_name"];
|
|
45
67
|
readonly additionalProperties: false;
|
|
@@ -106,6 +128,28 @@ export declare const OpenAiModelRecordSchema: {
|
|
|
106
128
|
readonly type: "string";
|
|
107
129
|
readonly description: "OpenAI organization ID (optional).";
|
|
108
130
|
};
|
|
131
|
+
readonly prompt_cache_key: {
|
|
132
|
+
readonly type: "string";
|
|
133
|
+
readonly description: "Overrides the auto-derived Responses prompt_cache_key. Requests sharing a key share a cached prefix; leave unset to derive a stable key from the model + system instructions + tools.";
|
|
134
|
+
readonly "x-ui-hidden": true;
|
|
135
|
+
};
|
|
136
|
+
readonly reasoning: {
|
|
137
|
+
readonly type: "object";
|
|
138
|
+
readonly description: "Reasoning controls for reasoning-capable models (e.g. the GPT-5.6 sol/terra/luna family), sent on the Responses API.";
|
|
139
|
+
readonly properties: {
|
|
140
|
+
readonly effort: {
|
|
141
|
+
readonly type: "string";
|
|
142
|
+
readonly enum: readonly ["none", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
143
|
+
readonly description: "Reasoning effort. Higher effort trades latency and cost for quality.";
|
|
144
|
+
};
|
|
145
|
+
readonly mode: {
|
|
146
|
+
readonly type: "string";
|
|
147
|
+
readonly enum: readonly ["pro"];
|
|
148
|
+
readonly description: "Set to 'pro' for the quality-first pro configuration on supported models.";
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
readonly additionalProperties: false;
|
|
152
|
+
};
|
|
109
153
|
};
|
|
110
154
|
readonly required: readonly ["model_name"];
|
|
111
155
|
readonly additionalProperties: false;
|
|
@@ -173,6 +217,28 @@ export declare const OpenAiModelConfigSchema: {
|
|
|
173
217
|
readonly type: "string";
|
|
174
218
|
readonly description: "OpenAI organization ID (optional).";
|
|
175
219
|
};
|
|
220
|
+
readonly prompt_cache_key: {
|
|
221
|
+
readonly type: "string";
|
|
222
|
+
readonly description: "Overrides the auto-derived Responses prompt_cache_key. Requests sharing a key share a cached prefix; leave unset to derive a stable key from the model + system instructions + tools.";
|
|
223
|
+
readonly "x-ui-hidden": true;
|
|
224
|
+
};
|
|
225
|
+
readonly reasoning: {
|
|
226
|
+
readonly type: "object";
|
|
227
|
+
readonly description: "Reasoning controls for reasoning-capable models (e.g. the GPT-5.6 sol/terra/luna family), sent on the Responses API.";
|
|
228
|
+
readonly properties: {
|
|
229
|
+
readonly effort: {
|
|
230
|
+
readonly type: "string";
|
|
231
|
+
readonly enum: readonly ["none", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
232
|
+
readonly description: "Reasoning effort. Higher effort trades latency and cost for quality.";
|
|
233
|
+
};
|
|
234
|
+
readonly mode: {
|
|
235
|
+
readonly type: "string";
|
|
236
|
+
readonly enum: readonly ["pro"];
|
|
237
|
+
readonly description: "Set to 'pro' for the quality-first pro configuration on supported models.";
|
|
238
|
+
};
|
|
239
|
+
};
|
|
240
|
+
readonly additionalProperties: false;
|
|
241
|
+
};
|
|
176
242
|
};
|
|
177
243
|
readonly required: readonly ["model_name"];
|
|
178
244
|
readonly additionalProperties: false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenAI_ModelSchema.d.ts","sourceRoot":"","sources":["../../../src/ai/common/OpenAI_ModelSchema.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAwB,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGzE,eAAO,MAAM,iBAAiB;mBACtB,QAAQ;;iBAEZ,QAAQ;qBACN,KAAK;qBACL,WAAW,EAAE,uCAAuC;;iBAEtD,eAAe;qBACb,IAAI,EAAE,QAAQ;qBACd,WAAW,EAAE,gCAAgC;qBAC7C,UAAU;yBACR,UAAU;6BACR,IAAI,EAAE,QAAQ;6BACd,WAAW,EAAE,yEAAyE;;yBAExF,cAAc;6BACZ,IAAI,EAAE,QAAQ;6BACd,MAAM,EAAE,YAAY;6BACpB,WAAW,EAAE,yDAAyD;6BACtE,aAAa;;yBAEf,QAAQ;6BACN,IAAI,EAAE,QA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,EACpB,qBAAqB,EACtB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"OpenAI_ModelSearch.d.ts","sourceRoot":"","sources":["../../../src/ai/common/OpenAI_ModelSearch.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,eAAe,EAEf,oBAAoB,EACpB,qBAAqB,EACtB,MAAM,cAAc,CAAC;AA2EtB;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,EAAE,eAAe,CACrD,oBAAoB,EACpB,qBAAqB,CAUtB,CAAC"}
|
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import type { AiProviderRunFn, StructuredGenerationTaskInput, StructuredGenerationTaskOutput } from "@workglow/ai";
|
|
7
|
+
import { isStrictCompatibleSchema } from "@workglow/ai/provider-utils";
|
|
7
8
|
import type { OpenAiModelConfig } from "./OpenAI_ModelSchema";
|
|
9
|
+
export { isStrictCompatibleSchema };
|
|
8
10
|
/**
|
|
9
11
|
* Streaming run-fn for `["text.generation", "json-mode"]`. Emits
|
|
10
12
|
* `object-delta` events with progressively-completed partial JSON snapshots
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenAI_StructuredGeneration.d.ts","sourceRoot":"","sources":["../../../src/ai/common/OpenAI_StructuredGeneration.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,6BAA6B,EAC7B,8BAA8B,EAC/B,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"OpenAI_StructuredGeneration.d.ts","sourceRoot":"","sources":["../../../src/ai/common/OpenAI_StructuredGeneration.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,6BAA6B,EAC7B,8BAA8B,EAC/B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AAGvE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D,OAAO,EAAE,wBAAwB,EAAE,CAAC;AAEpC;;;;;GAKG;AACH,eAAO,MAAM,kCAAkC,EAAE,eAAe,CAC9D,6BAA6B,EAC7B,8BAA8B,EAC9B,iBAAiB,CA0DlB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenAI_TextGeneration.d.ts","sourceRoot":"","sources":["../../../src/ai/common/OpenAI_TextGeneration.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,uBAAuB,EACvB,wBAAwB,EACzB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"OpenAI_TextGeneration.d.ts","sourceRoot":"","sources":["../../../src/ai/common/OpenAI_TextGeneration.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,uBAAuB,EACvB,wBAAwB,EACzB,MAAM,cAAc,CAAC;AAKtB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAoD9D;;;;;;GAMG;AACH,eAAO,MAAM,4BAA4B,EAAE,eAAe,CACxD,uBAAuB,EACvB,wBAAwB,EACxB,iBAAiB,CAsBlB,CAAC"}
|
|
@@ -7,7 +7,8 @@ import type { AiProviderRunFn, TextRewriterTaskInput, TextRewriterTaskOutput } f
|
|
|
7
7
|
import type { OpenAiModelConfig } from "./OpenAI_ModelSchema";
|
|
8
8
|
/**
|
|
9
9
|
* Streaming run-fn for `["text.rewriter"]`. Emits `text-delta` events on
|
|
10
|
-
* the `text` port and a final empty `finish` event.
|
|
10
|
+
* the `text` port and a final empty `finish` event. The rewrite instruction
|
|
11
|
+
* is sent as the Responses `instructions` (system) channel.
|
|
11
12
|
*/
|
|
12
13
|
export declare const OpenAI_TextRewriter_Stream: AiProviderRunFn<TextRewriterTaskInput, TextRewriterTaskOutput, OpenAiModelConfig>;
|
|
13
14
|
//# sourceMappingURL=OpenAI_TextRewriter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenAI_TextRewriter.d.ts","sourceRoot":"","sources":["../../../src/ai/common/OpenAI_TextRewriter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"OpenAI_TextRewriter.d.ts","sourceRoot":"","sources":["../../../src/ai/common/OpenAI_TextRewriter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAGnG,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,EAAE,eAAe,CACtD,qBAAqB,EACrB,sBAAsB,EACtB,iBAAiB,CAkBlB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenAI_TextSummary.d.ts","sourceRoot":"","sources":["../../../src/ai/common/OpenAI_TextSummary.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"OpenAI_TextSummary.d.ts","sourceRoot":"","sources":["../../../src/ai/common/OpenAI_TextSummary.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAGjG,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D;;;GAGG;AACH,eAAO,MAAM,yBAAyB,EAAE,eAAe,CACrD,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,CAkBlB,CAAC"}
|
|
@@ -7,8 +7,8 @@ import type { AiProviderRunFn, ToolCallingTaskInput, ToolCallingTaskOutput } fro
|
|
|
7
7
|
import type { OpenAiModelConfig } from "./OpenAI_ModelSchema";
|
|
8
8
|
/**
|
|
9
9
|
* Streaming run-fn for `["text.generation", "tool-use"]`. Calls the OpenAI
|
|
10
|
-
*
|
|
11
|
-
* {@link
|
|
10
|
+
* Responses endpoint with `stream: true` and forwards delta events via
|
|
11
|
+
* {@link accumulateOpenAIResponsesStream}, which emits `text-delta` and tool-call
|
|
12
12
|
* `object-delta` events plus a final empty `finish`.
|
|
13
13
|
*
|
|
14
14
|
* Defence-in-depth: each tool-call `object-delta` is filtered against
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenAI_ToolCalling.d.ts","sourceRoot":"","sources":["../../../src/ai/common/OpenAI_ToolCalling.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,oBAAoB,EACpB,qBAAqB,EAEtB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"OpenAI_ToolCalling.d.ts","sourceRoot":"","sources":["../../../src/ai/common/OpenAI_ToolCalling.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,oBAAoB,EACpB,qBAAqB,EAEtB,MAAM,cAAc,CAAC;AAStB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D;;;;;;;;GAQG;AACH,eAAO,MAAM,yBAAyB,EAAE,eAAe,CACrD,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,CAyClB,CAAC"}
|
package/dist/ai/index.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export * from "./common/OpenAI_ImageValidation";
|
|
|
9
9
|
export * from "./common/OpenAI_ModelSchema";
|
|
10
10
|
export * from "./common/OpenAI_ModelSearch";
|
|
11
11
|
export * from "./registerOpenAi";
|
|
12
|
+
import { getReasoningConfig, resolvePromptCacheKey } from "./common/OpenAI_Client";
|
|
13
|
+
import { isStrictCompatibleSchema } from "./common/OpenAI_StructuredGeneration";
|
|
12
14
|
import { OpenAiQueuedProvider } from "./OpenAiQueuedProvider";
|
|
13
15
|
/**
|
|
14
16
|
* @internal Symbols exported only for use by `@workglow/test`. Not part of the stable public API.
|
|
@@ -31,9 +33,17 @@ export declare const _testOnly: {
|
|
|
31
33
|
credential_key?: string | undefined;
|
|
32
34
|
model_name: string;
|
|
33
35
|
organization?: string | undefined;
|
|
36
|
+
prompt_cache_key?: string | undefined;
|
|
37
|
+
reasoning?: {
|
|
38
|
+
effort?: "high" | "low" | "max" | "medium" | "minimal" | "none" | "xhigh" | undefined;
|
|
39
|
+
mode?: "pro" | undefined;
|
|
40
|
+
} | undefined;
|
|
34
41
|
trustedBaseUrl?: boolean | undefined;
|
|
35
42
|
};
|
|
36
43
|
title?: string | undefined;
|
|
37
44
|
}>[];
|
|
45
|
+
readonly getReasoningConfig: typeof getReasoningConfig;
|
|
46
|
+
readonly resolvePromptCacheKey: typeof resolvePromptCacheKey;
|
|
47
|
+
readonly isStrictCompatibleSchema: typeof isStrictCompatibleSchema;
|
|
38
48
|
};
|
|
39
49
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/ai/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ai/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ai/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kBAAkB,CAAC;AAGjC,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAEnF,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D;;GAEG;AACH,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAOZ,CAAC"}
|
|
@@ -49,6 +49,39 @@ function getModelName(model) {
|
|
|
49
49
|
}
|
|
50
50
|
return name;
|
|
51
51
|
}
|
|
52
|
+
function getReasoningConfig(model) {
|
|
53
|
+
const reasoning = model?.provider_config?.reasoning;
|
|
54
|
+
if (!reasoning || reasoning.effort === undefined && reasoning.mode === undefined) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
return reasoning;
|
|
58
|
+
}
|
|
59
|
+
function fnv1aHex(input) {
|
|
60
|
+
let hash = 2166136261;
|
|
61
|
+
for (let i = 0;i < input.length; i++) {
|
|
62
|
+
hash ^= input.charCodeAt(i);
|
|
63
|
+
hash = Math.imul(hash, 16777619);
|
|
64
|
+
}
|
|
65
|
+
return (hash >>> 0).toString(16).padStart(8, "0");
|
|
66
|
+
}
|
|
67
|
+
function resolvePromptCacheKey(model, params) {
|
|
68
|
+
const override = model?.provider_config?.prompt_cache_key;
|
|
69
|
+
if (override)
|
|
70
|
+
return override;
|
|
71
|
+
const material = JSON.stringify([
|
|
72
|
+
params.model ?? "",
|
|
73
|
+
params.instructions ?? "",
|
|
74
|
+
params.tools ?? null
|
|
75
|
+
]);
|
|
76
|
+
return `wg-${fnv1aHex(material)}`;
|
|
77
|
+
}
|
|
78
|
+
function finalizeResponsesRequest(model, params) {
|
|
79
|
+
const reasoning = getReasoningConfig(model);
|
|
80
|
+
if (reasoning !== undefined)
|
|
81
|
+
params.reasoning = reasoning;
|
|
82
|
+
params.prompt_cache_key = resolvePromptCacheKey(model, params);
|
|
83
|
+
return params;
|
|
84
|
+
}
|
|
52
85
|
|
|
53
86
|
// src/ai/registerOpenAiInline.browser.ts
|
|
54
87
|
import { registerProviderInline } from "@workglow/ai/provider-utils";
|
|
@@ -351,6 +384,10 @@ var OPENAI = "OPENAI";
|
|
|
351
384
|
var OPENAI_FALLBACK = [
|
|
352
385
|
{ label: "gpt-image-2", value: "gpt-image-2" },
|
|
353
386
|
{ label: "dall-e-3", value: "dall-e-3" },
|
|
387
|
+
{ label: "gpt-5.6", value: "gpt-5.6" },
|
|
388
|
+
{ label: "gpt-5.6-sol", value: "gpt-5.6-sol" },
|
|
389
|
+
{ label: "gpt-5.6-terra", value: "gpt-5.6-terra" },
|
|
390
|
+
{ label: "gpt-5.6-luna", value: "gpt-5.6-luna" },
|
|
354
391
|
{ label: "gpt-5.5", value: "gpt-5.5" },
|
|
355
392
|
{ label: "gpt-5.4-mini", value: "gpt-5.4-mini" },
|
|
356
393
|
{ label: "gpt-5.4-nano", value: "gpt-5.4-nano" },
|
|
@@ -417,37 +454,49 @@ var OpenAI_ModelSearch_Stream = async (input, _model, _signal, emit) => {
|
|
|
417
454
|
};
|
|
418
455
|
|
|
419
456
|
// src/ai/common/OpenAI_StructuredGeneration.ts
|
|
457
|
+
import { isStrictCompatibleSchema } from "@workglow/ai/provider-utils";
|
|
420
458
|
import { parsePartialJson } from "@workglow/util/worker";
|
|
421
459
|
var OpenAI_StructuredGeneration_Stream = async (input, model, signal, emit, outputSchema) => {
|
|
422
460
|
const client = await getClient(model);
|
|
423
461
|
const modelName = getModelName(model);
|
|
424
462
|
const schema = input.outputSchema ?? outputSchema;
|
|
425
|
-
const
|
|
463
|
+
const params = {
|
|
426
464
|
model: modelName,
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
465
|
+
input: input.prompt,
|
|
466
|
+
text: {
|
|
467
|
+
format: {
|
|
468
|
+
type: "json_schema",
|
|
431
469
|
name: "structured_output",
|
|
432
470
|
schema,
|
|
433
|
-
strict:
|
|
471
|
+
strict: isStrictCompatibleSchema(schema)
|
|
434
472
|
}
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
473
|
+
}
|
|
474
|
+
};
|
|
475
|
+
if (input.maxTokens !== undefined)
|
|
476
|
+
params.max_output_tokens = input.maxTokens;
|
|
477
|
+
if (input.temperature !== undefined)
|
|
478
|
+
params.temperature = input.temperature;
|
|
479
|
+
finalizeResponsesRequest(model, params);
|
|
480
|
+
const stream = await client.responses.create({ ...params, stream: true }, { signal });
|
|
440
481
|
let accumulatedJson = "";
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
if (delta) {
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
482
|
+
let refusal = "";
|
|
483
|
+
for await (const event of stream) {
|
|
484
|
+
if (event.type === "response.output_text.delta") {
|
|
485
|
+
const delta = event.delta ?? "";
|
|
486
|
+
if (delta) {
|
|
487
|
+
accumulatedJson += delta;
|
|
488
|
+
const partial = parsePartialJson(accumulatedJson);
|
|
489
|
+
if (partial !== undefined) {
|
|
490
|
+
emit({ type: "object-delta", port: "object", objectDelta: partial });
|
|
491
|
+
}
|
|
448
492
|
}
|
|
493
|
+
} else if (event.type === "response.refusal.delta") {
|
|
494
|
+
refusal += event.delta ?? "";
|
|
449
495
|
}
|
|
450
496
|
}
|
|
497
|
+
if (refusal) {
|
|
498
|
+
emit({ type: "refusal", refusal });
|
|
499
|
+
}
|
|
451
500
|
let finalObject;
|
|
452
501
|
try {
|
|
453
502
|
finalObject = JSON.parse(accumulatedJson);
|
|
@@ -480,30 +529,34 @@ var OpenAI_TextEmbedding_Stream = async (input, model, signal, emit) => {
|
|
|
480
529
|
};
|
|
481
530
|
|
|
482
531
|
// src/ai/common/OpenAI_TextGeneration.ts
|
|
532
|
+
import { accumulateOpenAIResponsesStream, buildResponsesInput } from "@workglow/ai/provider-utils";
|
|
483
533
|
import { toOpenAIMessages } from "@workglow/ai/worker";
|
|
484
534
|
import { getLogger as getLogger2 } from "@workglow/util/worker";
|
|
485
|
-
function
|
|
535
|
+
function buildResponsesParams(input, model) {
|
|
486
536
|
const hasMessages = Array.isArray(input.messages) && input.messages.length > 0;
|
|
487
537
|
const messages = hasMessages ? toOpenAIMessages({
|
|
488
538
|
messages: input.messages,
|
|
489
539
|
systemPrompt: input.systemPrompt,
|
|
490
540
|
prompt: "",
|
|
491
541
|
tools: []
|
|
492
|
-
}) :
|
|
542
|
+
}) : undefined;
|
|
543
|
+
const { input: responsesInput, instructions } = buildResponsesInput({
|
|
544
|
+
messages,
|
|
545
|
+
prompt: hasMessages ? undefined : input.prompt,
|
|
546
|
+
systemPrompt: hasMessages ? undefined : input.systemPrompt
|
|
547
|
+
});
|
|
493
548
|
const params = {
|
|
494
549
|
model: getModelName(model),
|
|
495
|
-
|
|
550
|
+
input: responsesInput
|
|
496
551
|
};
|
|
552
|
+
if (instructions !== undefined)
|
|
553
|
+
params.instructions = instructions;
|
|
497
554
|
if (input.maxTokens !== undefined)
|
|
498
|
-
params.
|
|
555
|
+
params.max_output_tokens = input.maxTokens;
|
|
499
556
|
if (input.temperature !== undefined)
|
|
500
557
|
params.temperature = input.temperature;
|
|
501
558
|
if (input.topP !== undefined)
|
|
502
559
|
params.top_p = input.topP;
|
|
503
|
-
if (input.frequencyPenalty !== undefined)
|
|
504
|
-
params.frequency_penalty = input.frequencyPenalty;
|
|
505
|
-
if (input.presencePenalty !== undefined)
|
|
506
|
-
params.presence_penalty = input.presencePenalty;
|
|
507
560
|
return params;
|
|
508
561
|
}
|
|
509
562
|
var OpenAI_TextGeneration_Stream = async (input, model, signal, emit) => {
|
|
@@ -512,14 +565,9 @@ var OpenAI_TextGeneration_Stream = async (input, model, signal, emit) => {
|
|
|
512
565
|
logger.time(timerLabel, { model: getModelName(model) });
|
|
513
566
|
try {
|
|
514
567
|
const client = await getClient(model);
|
|
515
|
-
const params =
|
|
516
|
-
const stream = await client.
|
|
517
|
-
|
|
518
|
-
const delta = chunk.choices?.[0]?.delta?.content ?? "";
|
|
519
|
-
if (delta) {
|
|
520
|
-
emit({ type: "text-delta", port: "text", textDelta: delta });
|
|
521
|
-
}
|
|
522
|
-
}
|
|
568
|
+
const params = finalizeResponsesRequest(model, buildResponsesParams(input, model));
|
|
569
|
+
const stream = await client.responses.create({ ...params, stream: true }, { signal });
|
|
570
|
+
await accumulateOpenAIResponsesStream(stream, emit);
|
|
523
571
|
emit({ type: "finish", data: {} });
|
|
524
572
|
} finally {
|
|
525
573
|
logger.timeEnd(timerLabel, { model: getModelName(model) });
|
|
@@ -527,70 +575,66 @@ var OpenAI_TextGeneration_Stream = async (input, model, signal, emit) => {
|
|
|
527
575
|
};
|
|
528
576
|
|
|
529
577
|
// src/ai/common/OpenAI_TextRewriter.ts
|
|
578
|
+
import { accumulateOpenAIResponsesStream as accumulateOpenAIResponsesStream2 } from "@workglow/ai/provider-utils";
|
|
530
579
|
var OpenAI_TextRewriter_Stream = async (input, model, signal, emit) => {
|
|
531
580
|
const client = await getClient(model);
|
|
532
|
-
const
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
}, { signal });
|
|
541
|
-
for await (const chunk of stream) {
|
|
542
|
-
const delta = chunk.choices[0]?.delta?.content ?? "";
|
|
543
|
-
if (delta) {
|
|
544
|
-
emit({ type: "text-delta", port: "text", textDelta: delta });
|
|
545
|
-
}
|
|
546
|
-
}
|
|
581
|
+
const params = {
|
|
582
|
+
model: getModelName(model),
|
|
583
|
+
instructions: input.prompt,
|
|
584
|
+
input: input.text
|
|
585
|
+
};
|
|
586
|
+
finalizeResponsesRequest(model, params);
|
|
587
|
+
const stream = await client.responses.create({ ...params, stream: true }, { signal });
|
|
588
|
+
await accumulateOpenAIResponsesStream2(stream, emit);
|
|
547
589
|
emit({ type: "finish", data: {} });
|
|
548
590
|
};
|
|
549
591
|
|
|
550
592
|
// src/ai/common/OpenAI_TextSummary.ts
|
|
593
|
+
import { accumulateOpenAIResponsesStream as accumulateOpenAIResponsesStream3 } from "@workglow/ai/provider-utils";
|
|
551
594
|
var OpenAI_TextSummary_Stream = async (input, model, signal, emit) => {
|
|
552
595
|
const client = await getClient(model);
|
|
553
|
-
const
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
}, { signal });
|
|
562
|
-
for await (const chunk of stream) {
|
|
563
|
-
const delta = chunk.choices[0]?.delta?.content ?? "";
|
|
564
|
-
if (delta) {
|
|
565
|
-
emit({ type: "text-delta", port: "text", textDelta: delta });
|
|
566
|
-
}
|
|
567
|
-
}
|
|
596
|
+
const params = {
|
|
597
|
+
model: getModelName(model),
|
|
598
|
+
instructions: "Summarize the following text concisely.",
|
|
599
|
+
input: input.text
|
|
600
|
+
};
|
|
601
|
+
finalizeResponsesRequest(model, params);
|
|
602
|
+
const stream = await client.responses.create({ ...params, stream: true }, { signal });
|
|
603
|
+
await accumulateOpenAIResponsesStream3(stream, emit);
|
|
568
604
|
emit({ type: "finish", data: {} });
|
|
569
605
|
};
|
|
570
606
|
|
|
571
607
|
// src/ai/common/OpenAI_ToolCalling.ts
|
|
572
608
|
import {
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
609
|
+
accumulateOpenAIResponsesStream as accumulateOpenAIResponsesStream4,
|
|
610
|
+
buildResponsesInput as buildResponsesInput2,
|
|
611
|
+
buildResponsesTools,
|
|
612
|
+
mapResponsesToolChoice
|
|
576
613
|
} from "@workglow/ai/provider-utils";
|
|
577
614
|
import { filterValidToolCalls, toOpenAIMessages as toOpenAIMessages2 } from "@workglow/ai/worker";
|
|
578
615
|
var OpenAI_ToolCalling_Stream = async (input, model, signal, emit) => {
|
|
579
616
|
const client = await getClient(model);
|
|
580
617
|
const modelName = getModelName(model);
|
|
581
|
-
const tools =
|
|
582
|
-
const
|
|
583
|
-
|
|
584
|
-
|
|
618
|
+
const tools = buildResponsesTools(input.tools);
|
|
619
|
+
const { input: responsesInput, instructions } = buildResponsesInput2({
|
|
620
|
+
messages: toOpenAIMessages2(input)
|
|
621
|
+
});
|
|
622
|
+
const toolChoice = mapResponsesToolChoice(input.toolChoice);
|
|
623
|
+
const params = {
|
|
585
624
|
model: modelName,
|
|
586
|
-
|
|
587
|
-
max_completion_tokens: input.maxTokens,
|
|
588
|
-
temperature: input.temperature,
|
|
589
|
-
stream: true,
|
|
625
|
+
input: responsesInput,
|
|
590
626
|
tools,
|
|
591
627
|
tool_choice: toolChoice
|
|
592
|
-
}
|
|
593
|
-
|
|
628
|
+
};
|
|
629
|
+
if (instructions !== undefined)
|
|
630
|
+
params.instructions = instructions;
|
|
631
|
+
if (input.maxTokens !== undefined)
|
|
632
|
+
params.max_output_tokens = input.maxTokens;
|
|
633
|
+
if (input.temperature !== undefined)
|
|
634
|
+
params.temperature = input.temperature;
|
|
635
|
+
finalizeResponsesRequest(model, params);
|
|
636
|
+
const stream = await client.responses.create({ ...params, stream: true }, { signal });
|
|
637
|
+
await accumulateOpenAIResponsesStream4(stream, (event) => {
|
|
594
638
|
if (event.type === "object-delta" && event.port === "toolCalls") {
|
|
595
639
|
const validated = filterValidToolCalls(event.objectDelta, input.tools);
|
|
596
640
|
if (validated.length > 0) {
|
|
@@ -705,12 +749,15 @@ async function registerOpenAiWorker() {
|
|
|
705
749
|
await registerProviderWorker((ws) => new OpenAiProvider(OPENAI_RUN_FNS, OPENAI_PREVIEW_TASKS).registerOnWorkerServer(ws), "OpenAI");
|
|
706
750
|
}
|
|
707
751
|
export {
|
|
752
|
+
resolvePromptCacheKey,
|
|
708
753
|
registerOpenAiWorker,
|
|
709
754
|
registerOpenAiInline,
|
|
710
755
|
loadOpenAISDK,
|
|
756
|
+
getReasoningConfig,
|
|
711
757
|
getModelName,
|
|
712
758
|
getClient,
|
|
759
|
+
finalizeResponsesRequest,
|
|
713
760
|
OPENAI_ALLOWED_HOSTS
|
|
714
761
|
};
|
|
715
762
|
|
|
716
|
-
//# debugId=
|
|
763
|
+
//# debugId=782BE63C8FCCC0A964756E2164756E21
|