@effect/ai-openai 4.0.0-beta.4 → 4.0.0-beta.41
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/Generated.d.ts +4060 -4038
- package/dist/Generated.d.ts.map +1 -1
- package/dist/Generated.js +1 -1
- package/dist/Generated.js.map +1 -1
- package/dist/OpenAiClient.d.ts +56 -10
- package/dist/OpenAiClient.d.ts.map +1 -1
- package/dist/OpenAiClient.js +197 -7
- package/dist/OpenAiClient.js.map +1 -1
- package/dist/OpenAiEmbeddingModel.d.ts +85 -0
- package/dist/OpenAiEmbeddingModel.d.ts.map +1 -0
- package/dist/OpenAiEmbeddingModel.js +116 -0
- package/dist/OpenAiEmbeddingModel.js.map +1 -0
- package/dist/OpenAiError.d.ts +22 -32
- package/dist/OpenAiError.d.ts.map +1 -1
- package/dist/OpenAiLanguageModel.d.ts.map +1 -1
- package/dist/OpenAiLanguageModel.js +177 -64
- package/dist/OpenAiLanguageModel.js.map +1 -1
- package/dist/OpenAiTool.d.ts +24 -24
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/errors.js +4 -4
- package/dist/internal/errors.js.map +1 -1
- package/package.json +3 -3
- package/src/Generated.ts +125 -122
- package/src/OpenAiClient.ts +323 -40
- package/src/OpenAiEmbeddingModel.ts +200 -0
- package/src/OpenAiError.ts +24 -32
- package/src/OpenAiLanguageModel.ts +218 -66
- package/src/index.ts +9 -0
- package/src/internal/errors.ts +6 -4
package/dist/OpenAiError.d.ts
CHANGED
|
@@ -54,45 +54,35 @@ export type OpenAiRateLimitMetadata = OpenAiErrorMetadata & {
|
|
|
54
54
|
readonly resetTokens: string | null;
|
|
55
55
|
};
|
|
56
56
|
declare module "effect/unstable/ai/AiError" {
|
|
57
|
-
interface
|
|
58
|
-
readonly
|
|
59
|
-
readonly openai?: OpenAiRateLimitMetadata | null;
|
|
60
|
-
};
|
|
57
|
+
interface RateLimitErrorMetadata {
|
|
58
|
+
readonly openai?: OpenAiRateLimitMetadata | null;
|
|
61
59
|
}
|
|
62
|
-
interface
|
|
63
|
-
readonly
|
|
64
|
-
readonly openai?: OpenAiErrorMetadata | null;
|
|
65
|
-
};
|
|
60
|
+
interface QuotaExhaustedErrorMetadata {
|
|
61
|
+
readonly openai?: OpenAiErrorMetadata | null;
|
|
66
62
|
}
|
|
67
|
-
interface
|
|
68
|
-
readonly
|
|
69
|
-
readonly openai?: OpenAiErrorMetadata | null;
|
|
70
|
-
};
|
|
63
|
+
interface AuthenticationErrorMetadata {
|
|
64
|
+
readonly openai?: OpenAiErrorMetadata | null;
|
|
71
65
|
}
|
|
72
|
-
interface
|
|
73
|
-
readonly
|
|
74
|
-
readonly openai?: OpenAiErrorMetadata | null;
|
|
75
|
-
};
|
|
66
|
+
interface ContentPolicyErrorMetadata {
|
|
67
|
+
readonly openai?: OpenAiErrorMetadata | null;
|
|
76
68
|
}
|
|
77
|
-
interface
|
|
78
|
-
readonly
|
|
79
|
-
readonly openai?: OpenAiErrorMetadata | null;
|
|
80
|
-
};
|
|
69
|
+
interface InvalidRequestErrorMetadata {
|
|
70
|
+
readonly openai?: OpenAiErrorMetadata | null;
|
|
81
71
|
}
|
|
82
|
-
interface
|
|
83
|
-
readonly
|
|
84
|
-
readonly openai?: OpenAiErrorMetadata | null;
|
|
85
|
-
};
|
|
72
|
+
interface InternalProviderErrorMetadata {
|
|
73
|
+
readonly openai?: OpenAiErrorMetadata | null;
|
|
86
74
|
}
|
|
87
|
-
interface
|
|
88
|
-
readonly
|
|
89
|
-
readonly openai?: OpenAiErrorMetadata | null;
|
|
90
|
-
};
|
|
75
|
+
interface InvalidOutputErrorMetadata {
|
|
76
|
+
readonly openai?: OpenAiErrorMetadata | null;
|
|
91
77
|
}
|
|
92
|
-
interface
|
|
93
|
-
readonly
|
|
94
|
-
|
|
95
|
-
|
|
78
|
+
interface StructuredOutputErrorMetadata {
|
|
79
|
+
readonly openai?: OpenAiErrorMetadata | null;
|
|
80
|
+
}
|
|
81
|
+
interface UnsupportedSchemaErrorMetadata {
|
|
82
|
+
readonly openai?: OpenAiErrorMetadata | null;
|
|
83
|
+
}
|
|
84
|
+
interface UnknownErrorMetadata {
|
|
85
|
+
readonly openai?: OpenAiErrorMetadata | null;
|
|
96
86
|
}
|
|
97
87
|
}
|
|
98
88
|
//# sourceMappingURL=OpenAiError.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenAiError.d.ts","sourceRoot":"","sources":["../src/OpenAiError.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACjC;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACjC;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;CAClC,CAAA;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,uBAAuB,GAAG,mBAAmB,GAAG;IAC1D;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IAC7B;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACjC;;OAEG;IACH,QAAQ,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAA;IACrC;;OAEG;IACH,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;CACpC,CAAA;AAED,OAAO,QAAQ,4BAA4B,CAAC;IAC1C,UAAiB,
|
|
1
|
+
{"version":3,"file":"OpenAiError.d.ts","sourceRoot":"","sources":["../src/OpenAiError.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC;;OA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IAED,UAAiB,6BAA6B;QAC5C,QAAQ,CAAC,MAAM,CAAC,EAAE,mBAAmB,GAAG,IAAI,CAAA;KAC7C;IAED,UAAiB,8BAA8B;QAC7C,QAAQ,CAAC,MAAM,CAAC,EAAE,mBAAmB,GAAG,IAAI,CAAA;KAC7C;IAED,UAAiB,oBAAoB;QACnC,QAAQ,CAAC,MAAM,CAAC,EAAE,mBAAmB,GAAG,IAAI,CAAA;KAC7C;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenAiLanguageModel.d.ts","sourceRoot":"","sources":["../src/OpenAiLanguageModel.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAGvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"OpenAiLanguageModel.d.ts","sourceRoot":"","sources":["../src/OpenAiLanguageModel.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAGvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAIrC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAA;AAM/C,OAAO,KAAK,aAAa,MAAM,kCAAkC,CAAA;AACjE,OAAO,KAAK,OAAO,MAAM,0BAA0B,CAAA;AAOnD,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAE3C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAIhD,QAAA,MAAM,gBAAgB,8UAAyC,CAAA;AAC/D,QAAA,MAAM,cAAc,69CAAsC,CAAA;AAE1D;;;GAGG;AACH,MAAM,MAAM,KAAK,GAAG,OAAO,gBAAgB,CAAC,OAAO,GAAG,OAAO,cAAc,CAAC,OAAO,CAAA;AAEnF;;GAEG;AACH,KAAK,WAAW,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM,CAAA;;;;;;;;;;;;;;;;;;;;;;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MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAA;CAwBhH,CAAA"}
|
|
@@ -8,9 +8,10 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import * as DateTime from "effect/DateTime";
|
|
10
10
|
import * as Effect from "effect/Effect";
|
|
11
|
-
import * as
|
|
11
|
+
import * as Encoding from "effect/Encoding";
|
|
12
12
|
import { dual } from "effect/Function";
|
|
13
13
|
import * as Layer from "effect/Layer";
|
|
14
|
+
import * as Option from "effect/Option";
|
|
14
15
|
import * as Predicate from "effect/Predicate";
|
|
15
16
|
import * as Redactable from "effect/Redactable";
|
|
16
17
|
import * as Schema from "effect/Schema";
|
|
@@ -21,6 +22,7 @@ import * as AiError from "effect/unstable/ai/AiError";
|
|
|
21
22
|
import * as IdGenerator from "effect/unstable/ai/IdGenerator";
|
|
22
23
|
import * as LanguageModel from "effect/unstable/ai/LanguageModel";
|
|
23
24
|
import * as AiModel from "effect/unstable/ai/Model";
|
|
25
|
+
import { toCodecOpenAI } from "effect/unstable/ai/OpenAiStructuredOutput";
|
|
24
26
|
import * as Tool from "effect/unstable/ai/Tool";
|
|
25
27
|
import * as Generated from "./Generated.js";
|
|
26
28
|
import * as InternalUtilities from "./internal/utilities.js";
|
|
@@ -45,7 +47,7 @@ export class Config extends /*#__PURE__*/ServiceMap.Service()("@effect/ai-openai
|
|
|
45
47
|
* @since 1.0.0
|
|
46
48
|
* @category constructors
|
|
47
49
|
*/
|
|
48
|
-
export const model = (model, config) => AiModel.make("openai", layer({
|
|
50
|
+
export const model = (model, config) => AiModel.make("openai", model, layer({
|
|
49
51
|
model,
|
|
50
52
|
config
|
|
51
53
|
}));
|
|
@@ -58,7 +60,7 @@ export const model = (model, config) => AiModel.make("openai", layer({
|
|
|
58
60
|
// model: (string & {}) | Model,
|
|
59
61
|
// config?: Omit<typeof Config.Service, "model">
|
|
60
62
|
// ): AiModel.Model<"openai", LanguageModel.LanguageModel | Tokenizer.Tokenizer, OpenAiClient> =>
|
|
61
|
-
// AiModel.make("openai", layerWithTokenizer({ model, config }))
|
|
63
|
+
// AiModel.make("openai", model, layerWithTokenizer({ model, config }))
|
|
62
64
|
/**
|
|
63
65
|
* Creates an OpenAI language model service.
|
|
64
66
|
*
|
|
@@ -100,7 +102,7 @@ export const make = /*#__PURE__*/Effect.fnUntraced(function* ({
|
|
|
100
102
|
options,
|
|
101
103
|
toolNameMapper
|
|
102
104
|
});
|
|
103
|
-
const responseFormat = prepareResponseFormat({
|
|
105
|
+
const responseFormat = yield* prepareResponseFormat({
|
|
104
106
|
config,
|
|
105
107
|
options
|
|
106
108
|
});
|
|
@@ -112,16 +114,20 @@ export const make = /*#__PURE__*/Effect.fnUntraced(function* ({
|
|
|
112
114
|
verbosity: config.text?.verbosity ?? null,
|
|
113
115
|
format: responseFormat
|
|
114
116
|
},
|
|
115
|
-
...(
|
|
117
|
+
...(tools ? {
|
|
116
118
|
tools
|
|
117
119
|
} : undefined),
|
|
118
|
-
...(
|
|
120
|
+
...(toolChoice ? {
|
|
119
121
|
tool_choice: toolChoice
|
|
122
|
+
} : undefined),
|
|
123
|
+
...(options.previousResponseId ? {
|
|
124
|
+
previous_response_id: options.previousResponseId
|
|
120
125
|
} : undefined)
|
|
121
126
|
};
|
|
122
127
|
return request;
|
|
123
128
|
});
|
|
124
129
|
return yield* LanguageModel.make({
|
|
130
|
+
codecTransformer: toCodecOpenAI,
|
|
125
131
|
generateText: Effect.fnUntraced(function* (options) {
|
|
126
132
|
const config = yield* makeConfig;
|
|
127
133
|
const toolNameMapper = new Tool.NameMapper(options.tools);
|
|
@@ -207,14 +213,15 @@ const prepareMessages = /*#__PURE__*/Effect.fnUntraced(function* ({
|
|
|
207
213
|
if (config.store === false && capabilities.isReasoningModel) {
|
|
208
214
|
include.add("reasoning.encrypted_content");
|
|
209
215
|
}
|
|
210
|
-
if (
|
|
216
|
+
if (codeInterpreterTool) {
|
|
211
217
|
include.add("code_interpreter_call.outputs");
|
|
212
218
|
}
|
|
213
|
-
if (
|
|
219
|
+
if (webSearchTool || webSearchPreviewTool) {
|
|
214
220
|
include.add("web_search_call.action.sources");
|
|
215
221
|
}
|
|
216
222
|
const messages = [];
|
|
217
|
-
|
|
223
|
+
const prompt = options.incrementalPrompt ?? options.prompt;
|
|
224
|
+
for (const message of prompt.content) {
|
|
218
225
|
switch (message.role) {
|
|
219
226
|
case "system":
|
|
220
227
|
{
|
|
@@ -258,7 +265,7 @@ const prepareMessages = /*#__PURE__*/Effect.fnUntraced(function* ({
|
|
|
258
265
|
});
|
|
259
266
|
}
|
|
260
267
|
if (part.data instanceof Uint8Array) {
|
|
261
|
-
const base64 =
|
|
268
|
+
const base64 = Encoding.encodeBase64(part.data);
|
|
262
269
|
const imageUrl = `data:${mediaType};base64,${base64}`;
|
|
263
270
|
content.push({
|
|
264
271
|
type: "input_image",
|
|
@@ -280,7 +287,7 @@ const prepareMessages = /*#__PURE__*/Effect.fnUntraced(function* ({
|
|
|
280
287
|
});
|
|
281
288
|
}
|
|
282
289
|
if (part.data instanceof Uint8Array) {
|
|
283
|
-
const base64 =
|
|
290
|
+
const base64 = Encoding.encodeBase64(part.data);
|
|
284
291
|
const fileName = part.fileName ?? `part-${index}.pdf`;
|
|
285
292
|
const fileData = `data:application/pdf;base64,${base64}`;
|
|
286
293
|
content.push({
|
|
@@ -569,7 +576,7 @@ const buildHttpRequestDetails = request => ({
|
|
|
569
576
|
method: request.method,
|
|
570
577
|
url: request.url,
|
|
571
578
|
urlParams: Array.from(request.urlParams),
|
|
572
|
-
hash: request.hash,
|
|
579
|
+
hash: Option.getOrUndefined(request.hash),
|
|
573
580
|
headers: Redactable.redact(request.headers)
|
|
574
581
|
});
|
|
575
582
|
const buildHttpResponseDetails = response => ({
|
|
@@ -669,9 +676,8 @@ const makeResponse = /*#__PURE__*/Effect.fnUntraced(function* ({
|
|
|
669
676
|
{
|
|
670
677
|
hasToolCalls = true;
|
|
671
678
|
const toolName = part.name;
|
|
672
|
-
const toolParams =
|
|
673
|
-
|
|
674
|
-
try: () => Tool.unsafeSecureJsonParse(toolParams),
|
|
679
|
+
const toolParams = yield* Effect.try({
|
|
680
|
+
try: () => Tool.unsafeSecureJsonParse(part.arguments),
|
|
675
681
|
catch: cause => AiError.make({
|
|
676
682
|
module: "OpenAiLanguageModel",
|
|
677
683
|
method: "makeResponse",
|
|
@@ -682,6 +688,7 @@ const makeResponse = /*#__PURE__*/Effect.fnUntraced(function* ({
|
|
|
682
688
|
})
|
|
683
689
|
})
|
|
684
690
|
});
|
|
691
|
+
const params = yield* transformToolCallParams(options.tools, part.name, toolParams);
|
|
685
692
|
parts.push({
|
|
686
693
|
type: "tool-call",
|
|
687
694
|
id: part.call_id,
|
|
@@ -1015,6 +1022,21 @@ const makeStreamResponse = /*#__PURE__*/Effect.fnUntraced(function* ({
|
|
|
1015
1022
|
const activeAnnotations = [];
|
|
1016
1023
|
// Track active reasoning items with state machine for proper concluding logic
|
|
1017
1024
|
const activeReasoning = {};
|
|
1025
|
+
const getOrCreateReasoningPart = (itemId, encryptedContent) => {
|
|
1026
|
+
const activePart = activeReasoning[itemId];
|
|
1027
|
+
if (Predicate.isNotUndefined(activePart)) {
|
|
1028
|
+
if (Predicate.isNotNullish(encryptedContent)) {
|
|
1029
|
+
activePart.encryptedContent = encryptedContent;
|
|
1030
|
+
}
|
|
1031
|
+
return activePart;
|
|
1032
|
+
}
|
|
1033
|
+
const reasoningPart = {
|
|
1034
|
+
encryptedContent: Predicate.isNotNullish(encryptedContent) ? encryptedContent : undefined,
|
|
1035
|
+
summaryParts: {}
|
|
1036
|
+
};
|
|
1037
|
+
activeReasoning[itemId] = reasoningPart;
|
|
1038
|
+
return reasoningPart;
|
|
1039
|
+
};
|
|
1018
1040
|
// Track active tool calls with optional provider-specific state
|
|
1019
1041
|
const activeToolCalls = {};
|
|
1020
1042
|
const webSearchTool = options.tools.find(tool => Tool.isProviderDefined(tool) && (tool.name === "OpenAiWebSearch" || tool.name === "OpenAiWebSearchPreview"));
|
|
@@ -1157,7 +1179,10 @@ const makeStreamResponse = /*#__PURE__*/Effect.fnUntraced(function* ({
|
|
|
1157
1179
|
{
|
|
1158
1180
|
activeToolCalls[event.output_index] = {
|
|
1159
1181
|
id: event.item.call_id,
|
|
1160
|
-
name: event.item.name
|
|
1182
|
+
name: event.item.name,
|
|
1183
|
+
functionCall: {
|
|
1184
|
+
emitted: false
|
|
1185
|
+
}
|
|
1161
1186
|
};
|
|
1162
1187
|
parts.push({
|
|
1163
1188
|
type: "tool-params-start",
|
|
@@ -1204,23 +1229,20 @@ const makeStreamResponse = /*#__PURE__*/Effect.fnUntraced(function* ({
|
|
|
1204
1229
|
}
|
|
1205
1230
|
case "reasoning":
|
|
1206
1231
|
{
|
|
1207
|
-
const
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
openai: {
|
|
1219
|
-
...makeItemIdMetadata(event.item.id),
|
|
1220
|
-
...makeEncryptedContentMetadata(event.item.encrypted_content)
|
|
1232
|
+
const reasoningPart = getOrCreateReasoningPart(event.item.id, event.item.encrypted_content);
|
|
1233
|
+
if (Predicate.isUndefined(reasoningPart.summaryParts[0])) {
|
|
1234
|
+
reasoningPart.summaryParts[0] = "active";
|
|
1235
|
+
parts.push({
|
|
1236
|
+
type: "reasoning-start",
|
|
1237
|
+
id: `${event.item.id}:0`,
|
|
1238
|
+
metadata: {
|
|
1239
|
+
openai: {
|
|
1240
|
+
...makeItemIdMetadata(event.item.id),
|
|
1241
|
+
...makeEncryptedContentMetadata(reasoningPart.encryptedContent)
|
|
1242
|
+
}
|
|
1221
1243
|
}
|
|
1222
|
-
}
|
|
1223
|
-
}
|
|
1244
|
+
});
|
|
1245
|
+
}
|
|
1224
1246
|
break;
|
|
1225
1247
|
}
|
|
1226
1248
|
case "shell_call":
|
|
@@ -1372,12 +1394,17 @@ const makeStreamResponse = /*#__PURE__*/Effect.fnUntraced(function* ({
|
|
|
1372
1394
|
}
|
|
1373
1395
|
case "function_call":
|
|
1374
1396
|
{
|
|
1397
|
+
const toolCall = activeToolCalls[event.output_index];
|
|
1398
|
+
if (Predicate.isNotUndefined(toolCall?.functionCall?.emitted) && toolCall.functionCall.emitted) {
|
|
1399
|
+
delete activeToolCalls[event.output_index];
|
|
1400
|
+
break;
|
|
1401
|
+
}
|
|
1375
1402
|
delete activeToolCalls[event.output_index];
|
|
1376
1403
|
hasToolCalls = true;
|
|
1377
1404
|
const toolName = event.item.name;
|
|
1378
|
-
const
|
|
1379
|
-
const
|
|
1380
|
-
try: () => Tool.unsafeSecureJsonParse(
|
|
1405
|
+
const toolArgs = event.item.arguments;
|
|
1406
|
+
const toolParams = yield* Effect.try({
|
|
1407
|
+
try: () => Tool.unsafeSecureJsonParse(toolArgs),
|
|
1381
1408
|
catch: cause => AiError.make({
|
|
1382
1409
|
module: "OpenAiLanguageModel",
|
|
1383
1410
|
method: "makeStreamResponse",
|
|
@@ -1388,6 +1415,7 @@ const makeStreamResponse = /*#__PURE__*/Effect.fnUntraced(function* ({
|
|
|
1388
1415
|
})
|
|
1389
1416
|
})
|
|
1390
1417
|
});
|
|
1418
|
+
const params = yield* transformToolCallParams(options.tools, toolName, toolParams);
|
|
1391
1419
|
parts.push({
|
|
1392
1420
|
type: "tool-params-end",
|
|
1393
1421
|
id: event.item.call_id
|
|
@@ -1521,7 +1549,7 @@ const makeStreamResponse = /*#__PURE__*/Effect.fnUntraced(function* ({
|
|
|
1521
1549
|
}
|
|
1522
1550
|
case "reasoning":
|
|
1523
1551
|
{
|
|
1524
|
-
const reasoningPart =
|
|
1552
|
+
const reasoningPart = getOrCreateReasoningPart(event.item.id, event.item.encrypted_content);
|
|
1525
1553
|
for (const [summaryIndex, status] of Object.entries(reasoningPart.summaryParts)) {
|
|
1526
1554
|
if (status === "active" || status === "can-conclude") {
|
|
1527
1555
|
parts.push({
|
|
@@ -1530,7 +1558,7 @@ const makeStreamResponse = /*#__PURE__*/Effect.fnUntraced(function* ({
|
|
|
1530
1558
|
metadata: {
|
|
1531
1559
|
openai: {
|
|
1532
1560
|
...makeItemIdMetadata(event.item.id),
|
|
1533
|
-
...makeEncryptedContentMetadata(
|
|
1561
|
+
...makeEncryptedContentMetadata(reasoningPart.encryptedContent)
|
|
1534
1562
|
}
|
|
1535
1563
|
}
|
|
1536
1564
|
});
|
|
@@ -1670,6 +1698,43 @@ const makeStreamResponse = /*#__PURE__*/Effect.fnUntraced(function* ({
|
|
|
1670
1698
|
}
|
|
1671
1699
|
break;
|
|
1672
1700
|
}
|
|
1701
|
+
case "response.function_call_arguments.done":
|
|
1702
|
+
{
|
|
1703
|
+
const toolCall = activeToolCalls[event.output_index];
|
|
1704
|
+
if (Predicate.isNotUndefined(toolCall?.functionCall) && !toolCall.functionCall.emitted) {
|
|
1705
|
+
hasToolCalls = true;
|
|
1706
|
+
const toolParams = yield* Effect.try({
|
|
1707
|
+
try: () => Tool.unsafeSecureJsonParse(event.arguments),
|
|
1708
|
+
catch: cause => AiError.make({
|
|
1709
|
+
module: "OpenAiLanguageModel",
|
|
1710
|
+
method: "makeStreamResponse",
|
|
1711
|
+
reason: new AiError.ToolParameterValidationError({
|
|
1712
|
+
toolName: toolCall.name,
|
|
1713
|
+
toolParams: {},
|
|
1714
|
+
description: `Failed securely JSON parse tool parameters: ${cause}`
|
|
1715
|
+
})
|
|
1716
|
+
})
|
|
1717
|
+
});
|
|
1718
|
+
const params = yield* transformToolCallParams(options.tools, toolCall.name, toolParams);
|
|
1719
|
+
parts.push({
|
|
1720
|
+
type: "tool-params-end",
|
|
1721
|
+
id: toolCall.id
|
|
1722
|
+
});
|
|
1723
|
+
parts.push({
|
|
1724
|
+
type: "tool-call",
|
|
1725
|
+
id: toolCall.id,
|
|
1726
|
+
name: toolCall.name,
|
|
1727
|
+
params,
|
|
1728
|
+
metadata: {
|
|
1729
|
+
openai: {
|
|
1730
|
+
...makeItemIdMetadata(event.item_id)
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
});
|
|
1734
|
+
toolCall.functionCall.emitted = true;
|
|
1735
|
+
}
|
|
1736
|
+
break;
|
|
1737
|
+
}
|
|
1673
1738
|
case "response.apply_patch_call_operation_diff.delta":
|
|
1674
1739
|
{
|
|
1675
1740
|
const toolCall = activeToolCalls[event.output_index];
|
|
@@ -1765,28 +1830,27 @@ const makeStreamResponse = /*#__PURE__*/Effect.fnUntraced(function* ({
|
|
|
1765
1830
|
}
|
|
1766
1831
|
case "response.reasoning_summary_part.added":
|
|
1767
1832
|
{
|
|
1768
|
-
|
|
1833
|
+
const reasoningPart = getOrCreateReasoningPart(event.item_id);
|
|
1769
1834
|
if (event.summary_index > 0) {
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
...makeItemIdMetadata(event.item_id),
|
|
1781
|
-
...makeEncryptedContentMetadata(reasoningPart.encryptedContent)
|
|
1782
|
-
}
|
|
1835
|
+
// Conclude all can-conclude parts before starting new one
|
|
1836
|
+
for (const [summaryIndex, status] of Object.entries(reasoningPart.summaryParts)) {
|
|
1837
|
+
if (status === "can-conclude") {
|
|
1838
|
+
parts.push({
|
|
1839
|
+
type: "reasoning-end",
|
|
1840
|
+
id: `${event.item_id}:${summaryIndex}`,
|
|
1841
|
+
metadata: {
|
|
1842
|
+
openai: {
|
|
1843
|
+
...makeItemIdMetadata(event.item_id),
|
|
1844
|
+
...makeEncryptedContentMetadata(reasoningPart.encryptedContent)
|
|
1783
1845
|
}
|
|
1784
|
-
}
|
|
1785
|
-
|
|
1786
|
-
|
|
1846
|
+
}
|
|
1847
|
+
});
|
|
1848
|
+
reasoningPart.summaryParts[Number(summaryIndex)] = "concluded";
|
|
1787
1849
|
}
|
|
1788
|
-
reasoningPart.summaryParts[event.summary_index] = "active";
|
|
1789
1850
|
}
|
|
1851
|
+
}
|
|
1852
|
+
if (Predicate.isUndefined(reasoningPart.summaryParts[event.summary_index])) {
|
|
1853
|
+
reasoningPart.summaryParts[event.summary_index] = "active";
|
|
1790
1854
|
parts.push({
|
|
1791
1855
|
type: "reasoning-start",
|
|
1792
1856
|
id: `${event.item_id}:${event.summary_index}`,
|
|
@@ -1816,6 +1880,7 @@ const makeStreamResponse = /*#__PURE__*/Effect.fnUntraced(function* ({
|
|
|
1816
1880
|
}
|
|
1817
1881
|
case "response.reasoning_summary_part.done":
|
|
1818
1882
|
{
|
|
1883
|
+
const reasoningPart = getOrCreateReasoningPart(event.item_id);
|
|
1819
1884
|
// When OpenAI stores message data, we can immediately conclude the
|
|
1820
1885
|
// reasoning part given that we do not need the encrypted content
|
|
1821
1886
|
if (config.store === true) {
|
|
@@ -1829,11 +1894,11 @@ const makeStreamResponse = /*#__PURE__*/Effect.fnUntraced(function* ({
|
|
|
1829
1894
|
}
|
|
1830
1895
|
});
|
|
1831
1896
|
// Mark the summary part concluded
|
|
1832
|
-
|
|
1897
|
+
reasoningPart.summaryParts[event.summary_index] = "concluded";
|
|
1833
1898
|
} else {
|
|
1834
1899
|
// Mark the summary part as can-conclude given we still need a
|
|
1835
1900
|
// final summary part with the encrypted content
|
|
1836
|
-
|
|
1901
|
+
reasoningPart.summaryParts[event.summary_index] = "can-conclude";
|
|
1837
1902
|
}
|
|
1838
1903
|
break;
|
|
1839
1904
|
}
|
|
@@ -1938,12 +2003,16 @@ const prepareTools = /*#__PURE__*/Effect.fnUntraced(function* ({
|
|
|
1938
2003
|
for (const tool of allowedTools) {
|
|
1939
2004
|
if (Tool.isUserDefined(tool)) {
|
|
1940
2005
|
const strict = Tool.getStrictMode(tool) ?? config.strictJsonSchema ?? true;
|
|
2006
|
+
const description = Tool.getDescription(tool);
|
|
2007
|
+
const parameters = yield* tryJsonSchema(tool.parametersSchema, "prepareTools");
|
|
1941
2008
|
tools.push({
|
|
1942
2009
|
type: "function",
|
|
1943
2010
|
name: tool.name,
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
2011
|
+
parameters,
|
|
2012
|
+
strict,
|
|
2013
|
+
...(Predicate.isNotUndefined(description) ? {
|
|
2014
|
+
description
|
|
2015
|
+
} : undefined)
|
|
1947
2016
|
});
|
|
1948
2017
|
}
|
|
1949
2018
|
if (Tool.isProviderDefined(tool)) {
|
|
@@ -2115,25 +2184,43 @@ const makeItemIdMetadata = itemId => Predicate.isNotUndefined(itemId) ? {
|
|
|
2115
2184
|
const makeEncryptedContentMetadata = encryptedContent => Predicate.isNotNullish(encryptedContent) ? {
|
|
2116
2185
|
encryptedContent
|
|
2117
2186
|
} : undefined;
|
|
2118
|
-
const
|
|
2187
|
+
const unsupportedSchemaError = (error, method) => AiError.make({
|
|
2188
|
+
module: "OpenAiLanguageModel",
|
|
2189
|
+
method,
|
|
2190
|
+
reason: new AiError.UnsupportedSchemaError({
|
|
2191
|
+
description: error instanceof Error ? error.message : String(error)
|
|
2192
|
+
})
|
|
2193
|
+
});
|
|
2194
|
+
const tryCodecTransform = (schema, method) => Effect.try({
|
|
2195
|
+
try: () => toCodecOpenAI(schema),
|
|
2196
|
+
catch: error => unsupportedSchemaError(error, method)
|
|
2197
|
+
});
|
|
2198
|
+
const tryJsonSchema = (schema, method) => Effect.try({
|
|
2199
|
+
try: () => Tool.getJsonSchemaFromSchema(schema, {
|
|
2200
|
+
transformer: toCodecOpenAI
|
|
2201
|
+
}),
|
|
2202
|
+
catch: error => unsupportedSchemaError(error, method)
|
|
2203
|
+
});
|
|
2204
|
+
const prepareResponseFormat = /*#__PURE__*/Effect.fnUntraced(function* ({
|
|
2119
2205
|
config,
|
|
2120
2206
|
options
|
|
2121
|
-
})
|
|
2207
|
+
}) {
|
|
2122
2208
|
if (options.responseFormat.type === "json") {
|
|
2123
2209
|
const name = options.responseFormat.objectName;
|
|
2124
2210
|
const schema = options.responseFormat.schema;
|
|
2211
|
+
const jsonSchema = yield* tryJsonSchema(schema, "prepareResponseFormat");
|
|
2125
2212
|
return {
|
|
2126
2213
|
type: "json_schema",
|
|
2127
2214
|
name,
|
|
2128
2215
|
description: AST.resolveDescription(schema.ast) ?? "Response with a JSON object",
|
|
2129
|
-
schema:
|
|
2216
|
+
schema: jsonSchema,
|
|
2130
2217
|
strict: config.strictJsonSchema ?? true
|
|
2131
2218
|
};
|
|
2132
2219
|
}
|
|
2133
2220
|
return {
|
|
2134
2221
|
type: "text"
|
|
2135
2222
|
};
|
|
2136
|
-
};
|
|
2223
|
+
});
|
|
2137
2224
|
const getModelCapabilities = modelId => {
|
|
2138
2225
|
const supportsFlexProcessing = modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
|
|
2139
2226
|
const supportsPriorityProcessing = modelId.startsWith("gpt-4") || modelId.startsWith("gpt-5-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-nano") && !modelId.startsWith("gpt-5-chat") || modelId.startsWith("o3") || modelId.startsWith("o4-mini");
|
|
@@ -2204,4 +2291,30 @@ const getUsage = usage => {
|
|
|
2204
2291
|
}
|
|
2205
2292
|
};
|
|
2206
2293
|
};
|
|
2294
|
+
const transformToolCallParams = /*#__PURE__*/Effect.fnUntraced(function* (tools, toolName, toolParams) {
|
|
2295
|
+
const tool = tools.find(tool => tool.name === toolName);
|
|
2296
|
+
if (Predicate.isUndefined(tool)) {
|
|
2297
|
+
return yield* AiError.make({
|
|
2298
|
+
module: "OpenAiLanguageModel",
|
|
2299
|
+
method: "makeResponse",
|
|
2300
|
+
reason: new AiError.ToolNotFoundError({
|
|
2301
|
+
toolName,
|
|
2302
|
+
availableTools: tools.map(tool => tool.name)
|
|
2303
|
+
})
|
|
2304
|
+
});
|
|
2305
|
+
}
|
|
2306
|
+
const {
|
|
2307
|
+
codec
|
|
2308
|
+
} = yield* tryCodecTransform(tool.parametersSchema, "makeResponse");
|
|
2309
|
+
const transform = Schema.decodeEffect(codec);
|
|
2310
|
+
return yield* transform(toolParams).pipe(Effect.mapError(error => AiError.make({
|
|
2311
|
+
module: "OpenAiLanguageModel",
|
|
2312
|
+
method: "makeResponse",
|
|
2313
|
+
reason: new AiError.ToolParameterValidationError({
|
|
2314
|
+
toolName,
|
|
2315
|
+
toolParams,
|
|
2316
|
+
description: error.issue.toString()
|
|
2317
|
+
})
|
|
2318
|
+
})));
|
|
2319
|
+
});
|
|
2207
2320
|
//# sourceMappingURL=OpenAiLanguageModel.js.map
|