@codeworksh/aikit 0.9.3-canary.7.1.g63f07f17 → 0.9.3-canary.8.1.g9f95c5cc
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/cli.mjs +1 -1
- package/{failure-SAPyG-w2.mjs → failure-Bm4tDJMr.mjs} +27 -13
- package/failure-Bm4tDJMr.mjs.map +1 -0
- package/index.mjs +26 -4
- package/index.mjs.map +1 -1
- package/llm/failure.mjs +1 -1
- package/{modelgen-B1Ldaa1P.mjs → modelgen-BHm-jA64.mjs} +60 -13
- package/modelgen-BHm-jA64.mjs.map +1 -0
- package/modelgen.mjs +1 -1
- package/package.json +3 -3
- package/failure-SAPyG-w2.mjs.map +0 -1
- package/modelgen-B1Ldaa1P.mjs.map +0 -1
package/cli.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { r as OpenAICodexOAuthClient, t as JsonOpenAICodexAuthStorage } from "./codex-CLDBTrFm.mjs";
|
|
3
|
-
import { t as ModelgenCommand } from "./modelgen-
|
|
3
|
+
import { t as ModelgenCommand } from "./modelgen-BHm-jA64.mjs";
|
|
4
4
|
import { i as JsonGitHubCopilotAuthStorage, r as GitHubCopilotOAuthClient } from "./copilot-bFammM5T.mjs";
|
|
5
5
|
import { n as promptLine, t as openBrowser } from "./interactive-eoNnscGB.mjs";
|
|
6
6
|
import { a as oauthNotice, c as summarizeGitHubCopilot, i as oauthLoginIssue, l as summarizeOpenAICodex, n as checkOAuthProvider, r as formatOAuthSummary, s as oauthRefreshIssue } from "./summary-C_QyCVWa.mjs";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
2
|
import { a as FailureSchema, c as ModelUnavailable, d as Timeout, f as Transport, h as isFailure, i as ContentPolicy, l as Quota, m as Unknown, n as Authorization, o as InvalidRequest, p as Unavailable, r as Configuration, s as InvalidResponse, t as Authentication, u as RateLimit } from "./schema-rXSoWhic.mjs";
|
|
3
3
|
import { APICallError, EmptyResponseBodyError, InvalidArgumentError, InvalidPromptError, InvalidResponseDataError, JSONParseError, LoadAPIKeyError, LoadSettingError, NoContentGeneratedError, NoSuchModelError, TypeValidationError, UnsupportedFunctionalityError } from "@ai-sdk/provider";
|
|
4
|
-
import { RetryError } from "ai";
|
|
4
|
+
import { RetryError, StreamProviderError } from "ai";
|
|
5
5
|
//#region src/llm/failure.ts
|
|
6
6
|
var failure_exports = /* @__PURE__ */ __exportAll({
|
|
7
7
|
Authentication: () => Authentication,
|
|
@@ -71,8 +71,8 @@ const apiMetadata = (error) => {
|
|
|
71
71
|
};
|
|
72
72
|
};
|
|
73
73
|
const includes = (value, terms) => value !== void 0 && terms.some((term) => value.toLowerCase().includes(term));
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
/** Classify by provider error code, then HTTP status; shared by request and in-stream failures. */
|
|
75
|
+
const classify = (statusCode, details) => {
|
|
76
76
|
if (includes(details.code, [
|
|
77
77
|
"quota",
|
|
78
78
|
"billing",
|
|
@@ -92,36 +92,36 @@ const fromAPICall = (error) => {
|
|
|
92
92
|
_tag: "ContentPolicy",
|
|
93
93
|
...details
|
|
94
94
|
};
|
|
95
|
-
if (
|
|
95
|
+
if (statusCode === 401) return {
|
|
96
96
|
_tag: "Authentication",
|
|
97
97
|
reason: "invalid",
|
|
98
98
|
...details
|
|
99
99
|
};
|
|
100
|
-
if (
|
|
100
|
+
if (statusCode === 403) return {
|
|
101
101
|
_tag: "Authorization",
|
|
102
102
|
...details
|
|
103
103
|
};
|
|
104
|
-
if (
|
|
104
|
+
if (statusCode === 404) return {
|
|
105
105
|
_tag: "ModelUnavailable",
|
|
106
106
|
...details
|
|
107
107
|
};
|
|
108
|
-
if (
|
|
108
|
+
if (statusCode === 408) return {
|
|
109
109
|
_tag: "Timeout",
|
|
110
110
|
...details
|
|
111
111
|
};
|
|
112
|
-
if (
|
|
112
|
+
if (statusCode === 429) return {
|
|
113
113
|
_tag: "RateLimit",
|
|
114
114
|
...details
|
|
115
115
|
};
|
|
116
|
-
if (
|
|
116
|
+
if (statusCode !== void 0 && statusCode >= 500) return {
|
|
117
117
|
_tag: "Unavailable",
|
|
118
118
|
...details
|
|
119
119
|
};
|
|
120
|
-
if (
|
|
120
|
+
if (statusCode === void 0) return {
|
|
121
121
|
_tag: "Transport",
|
|
122
122
|
...details
|
|
123
123
|
};
|
|
124
|
-
if (
|
|
124
|
+
if (statusCode >= 400 && statusCode < 500) return {
|
|
125
125
|
_tag: "InvalidRequest",
|
|
126
126
|
...details
|
|
127
127
|
};
|
|
@@ -130,6 +130,19 @@ const fromAPICall = (error) => {
|
|
|
130
130
|
...details
|
|
131
131
|
};
|
|
132
132
|
};
|
|
133
|
+
/**
|
|
134
|
+
* A failure the provider reported after the stream started, e.g. OpenAI's
|
|
135
|
+
* `context_length_exceeded` event, which it sends instead of an HTTP 400 at random.
|
|
136
|
+
*/
|
|
137
|
+
const fromStreamProvider = (error) => {
|
|
138
|
+
const code = error.code === void 0 ? error.type : String(error.code);
|
|
139
|
+
return classify(error.statusCode, {
|
|
140
|
+
message: normalizeMessage(errorMessage(error)),
|
|
141
|
+
retryable: error.isRetryable,
|
|
142
|
+
...error.statusCode === void 0 ? {} : { status: error.statusCode },
|
|
143
|
+
...code === void 0 ? {} : { code }
|
|
144
|
+
});
|
|
145
|
+
};
|
|
133
146
|
const resemblesTimeout = (error) => {
|
|
134
147
|
const value = error instanceof Error ? `${error.name} ${error.message}` : String(error);
|
|
135
148
|
return /timeout|timed out/i.test(value);
|
|
@@ -158,7 +171,8 @@ function normalize(error) {
|
|
|
158
171
|
message: errorMessage(error),
|
|
159
172
|
retryable: false
|
|
160
173
|
};
|
|
161
|
-
if (APICallError.isInstance(error)) return
|
|
174
|
+
if (APICallError.isInstance(error)) return classify(error.statusCode, apiMetadata(error));
|
|
175
|
+
if (StreamProviderError.isInstance(error)) return fromStreamProvider(error);
|
|
162
176
|
if (InvalidPromptError.isInstance(error) || InvalidArgumentError.isInstance(error) || UnsupportedFunctionalityError.isInstance(error)) return {
|
|
163
177
|
_tag: "InvalidRequest",
|
|
164
178
|
message: errorMessage(error),
|
|
@@ -209,4 +223,4 @@ function fromMessage(message) {
|
|
|
209
223
|
//#endregion
|
|
210
224
|
export { fromMessage as n, normalize as r, failure_exports as t };
|
|
211
225
|
|
|
212
|
-
//# sourceMappingURL=failure-
|
|
226
|
+
//# sourceMappingURL=failure-Bm4tDJMr.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"failure-Bm4tDJMr.mjs","names":[],"sources":["../../src/llm/failure.ts"],"sourcesContent":["import {\n\tAPICallError,\n\tEmptyResponseBodyError,\n\tInvalidArgumentError,\n\tInvalidPromptError,\n\tInvalidResponseDataError,\n\tJSONParseError,\n\tLoadAPIKeyError,\n\tLoadSettingError,\n\tNoContentGeneratedError,\n\tNoSuchModelError,\n\tTypeValidationError,\n\tUnsupportedFunctionalityError,\n} from \"@ai-sdk/provider\";\nimport { RetryError, StreamProviderError } from \"ai\";\nimport type { Failure } from \"./failure/schema.ts\";\n\nexport * from \"./failure/schema.ts\";\n\ntype Metadata = Omit<Failure, \"_tag\" | \"reason\">;\n\nconst record = (value: unknown): Record<string, unknown> | undefined =>\n\ttypeof value === \"object\" && value !== null && !Array.isArray(value)\n\t\t? (value as Record<string, unknown>)\n\t\t: undefined;\n\nconst nonEmptyString = (value: unknown): string | undefined =>\n\ttypeof value === \"string\" && value.trim().length > 0 ? value.trim() : undefined;\n\nconst normalizeMessage = (message: string): string => {\n\tconst trimmed = message.trim().replace(/[.!?]+$/u, \"\");\n\treturn trimmed.replace(/^[A-Za-z]+/u, (word) => word.toLowerCase());\n};\n\nconst errorMessage = (error: unknown): string => {\n\tconst value = record(error);\n\tconst data = record(value?.data);\n\tif (value?.name === \"ProtocolAuthError\") {\n\t\treturn normalizeMessage(nonEmptyString(data?.message) ?? \"provider credentials are missing\");\n\t}\n\tif (error instanceof Error) return normalizeMessage(nonEmptyString(error.message) ?? error.name);\n\treturn normalizeMessage(nonEmptyString(error) ?? \"the provider request failed for an unknown reason\");\n};\n\nconst isProtocolAuthError = (error: unknown): boolean => {\n\tconst value = record(error);\n\treturn value?.name === \"ProtocolAuthError\";\n};\n\nconst errorCode = (data: unknown): string | undefined => {\n\tconst top = record(data);\n\tconst nested = record(top?.error);\n\treturn (\n\t\tnonEmptyString(top?.code) ??\n\t\tnonEmptyString(top?.type) ??\n\t\tnonEmptyString(nested?.code) ??\n\t\tnonEmptyString(nested?.type)\n\t);\n};\n\nconst header = (headers: Record<string, string> | undefined, name: string): string | undefined => {\n\tif (headers === undefined) return undefined;\n\tconst expected = name.toLowerCase();\n\tfor (const [key, value] of Object.entries(headers)) {\n\t\tif (key.toLowerCase() === expected) return nonEmptyString(value);\n\t}\n};\n\nconst retryAfter = (headers: Record<string, string> | undefined): number | undefined => {\n\tconst value = header(headers, \"retry-after\");\n\tif (value === undefined) return undefined;\n\tconst seconds = Number(value);\n\tif (Number.isFinite(seconds) && seconds >= 0) return seconds * 1_000;\n};\n\nconst apiMetadata = (error: APICallError): Metadata => {\n\tconst code = errorCode(error.data);\n\tconst data = record(error.data);\n\tconst nested = record(data?.error);\n\tconst structuredMessage = nonEmptyString(data?.message) ?? nonEmptyString(nested?.message);\n\tconst message = normalizeMessage(\n\t\tstructuredMessage ??\n\t\t\t(error.responseBody !== undefined && error.message.includes(error.responseBody)\n\t\t\t\t? `provider request failed${error.statusCode === undefined ? \"\" : ` with http ${error.statusCode}`}`\n\t\t\t\t: errorMessage(error)),\n\t);\n\tconst requestId =\n\t\theader(error.responseHeaders, \"x-request-id\") ??\n\t\theader(error.responseHeaders, \"x-oai-request-id\") ??\n\t\theader(error.responseHeaders, \"request-id\") ??\n\t\theader(error.responseHeaders, \"cf-ray\");\n\tconst retryAfterMs = retryAfter(error.responseHeaders);\n\treturn {\n\t\tmessage,\n\t\tretryable: error.isRetryable,\n\t\t...(error.statusCode === undefined ? {} : { status: error.statusCode }),\n\t\t...(code === undefined ? {} : { code }),\n\t\t...(requestId === undefined ? {} : { requestId }),\n\t\t...(retryAfterMs === undefined ? {} : { retryAfterMs }),\n\t};\n};\n\nconst includes = (value: string | undefined, terms: ReadonlyArray<string>): boolean =>\n\tvalue !== undefined && terms.some((term) => value.toLowerCase().includes(term));\n\n/** Classify by provider error code, then HTTP status; shared by request and in-stream failures. */\nconst classify = (statusCode: number | undefined, details: Metadata): Failure => {\n\tif (includes(details.code, [\"quota\", \"billing\", \"credit\"])) return { _tag: \"Quota\", ...details };\n\tif (\n\t\tincludes(details.code, [\n\t\t\t\"content_filter\",\n\t\t\t\"content_policy\",\n\t\t\t\"safety\",\n\t\t\t\"cyber_policy\",\n\t\t\t\"bio_policy\",\n\t\t\t\"misalignment_policy\",\n\t\t])\n\t) {\n\t\treturn { _tag: \"ContentPolicy\", ...details };\n\t}\n\tif (statusCode === 401) return { _tag: \"Authentication\", reason: \"invalid\", ...details };\n\tif (statusCode === 403) return { _tag: \"Authorization\", ...details };\n\tif (statusCode === 404) return { _tag: \"ModelUnavailable\", ...details };\n\tif (statusCode === 408) return { _tag: \"Timeout\", ...details };\n\tif (statusCode === 429) return { _tag: \"RateLimit\", ...details };\n\tif (statusCode !== undefined && statusCode >= 500) return { _tag: \"Unavailable\", ...details };\n\tif (statusCode === undefined) return { _tag: \"Transport\", ...details };\n\tif (statusCode >= 400 && statusCode < 500) return { _tag: \"InvalidRequest\", ...details };\n\treturn { _tag: \"Unknown\", ...details };\n};\n\n/**\n * A failure the provider reported after the stream started, e.g. OpenAI's\n * `context_length_exceeded` event, which it sends instead of an HTTP 400 at random.\n */\nconst fromStreamProvider = (error: StreamProviderError): Failure => {\n\t// Like apiMetadata: providers put the discriminator in `code`, or only in `type`.\n\tconst code = error.code === undefined ? error.type : String(error.code);\n\treturn classify(error.statusCode, {\n\t\tmessage: normalizeMessage(errorMessage(error)),\n\t\tretryable: error.isRetryable,\n\t\t...(error.statusCode === undefined ? {} : { status: error.statusCode }),\n\t\t...(code === undefined ? {} : { code }),\n\t});\n};\n\nconst resemblesTimeout = (error: unknown): boolean => {\n\tconst value = error instanceof Error ? `${error.name} ${error.message}` : String(error);\n\treturn /timeout|timed out/i.test(value);\n};\n\nconst resemblesTransportFailure = (error: unknown): boolean => {\n\tif (error instanceof TypeError) return true;\n\tconst value = error instanceof Error ? `${error.name} ${error.message}` : String(error);\n\treturn /fetch|network|socket|connection|econn|dns/i.test(value);\n};\n\n/** Normalize AI SDK and provider exceptions without retaining request bodies, response bodies, or headers. */\nexport function normalize(error: unknown): Failure {\n\tif (RetryError.isInstance(error) && error.lastError !== undefined && error.lastError !== error) {\n\t\treturn normalize(error.lastError);\n\t}\n\tif (LoadAPIKeyError.isInstance(error) || isProtocolAuthError(error)) {\n\t\treturn { _tag: \"Authentication\", reason: \"missing\", message: errorMessage(error), retryable: false };\n\t}\n\tif (LoadSettingError.isInstance(error)) {\n\t\treturn { _tag: \"Configuration\", message: errorMessage(error), retryable: false };\n\t}\n\tif (NoSuchModelError.isInstance(error)) {\n\t\treturn { _tag: \"ModelUnavailable\", message: errorMessage(error), retryable: false };\n\t}\n\tif (APICallError.isInstance(error)) return classify(error.statusCode, apiMetadata(error));\n\tif (StreamProviderError.isInstance(error)) return fromStreamProvider(error);\n\tif (\n\t\tInvalidPromptError.isInstance(error) ||\n\t\tInvalidArgumentError.isInstance(error) ||\n\t\tUnsupportedFunctionalityError.isInstance(error)\n\t) {\n\t\treturn { _tag: \"InvalidRequest\", message: errorMessage(error), retryable: false };\n\t}\n\tif (\n\t\tInvalidResponseDataError.isInstance(error) ||\n\t\tJSONParseError.isInstance(error) ||\n\t\tEmptyResponseBodyError.isInstance(error) ||\n\t\tNoContentGeneratedError.isInstance(error) ||\n\t\tTypeValidationError.isInstance(error)\n\t) {\n\t\treturn { _tag: \"InvalidResponse\", message: errorMessage(error), retryable: false };\n\t}\n\tif (resemblesTimeout(error)) return { _tag: \"Timeout\", message: errorMessage(error), retryable: true };\n\tif (resemblesTransportFailure(error)) {\n\t\treturn { _tag: \"Transport\", message: errorMessage(error), retryable: true };\n\t}\n\treturn { _tag: \"Unknown\", message: errorMessage(error), retryable: false };\n}\n\n/** Best-effort compatibility for terminal messages written before structured failures existed. */\nexport function fromMessage(message: string): Failure {\n\tconst normalized = normalizeMessage(message);\n\tif (/api key/i.test(normalized) && /missing|required|not set/i.test(normalized)) {\n\t\treturn { _tag: \"Authentication\", reason: \"missing\", message: normalized, retryable: false };\n\t}\n\tif (/api key|credential|token/i.test(normalized) && /invalid|expired|unauthorized/i.test(normalized)) {\n\t\treturn {\n\t\t\t_tag: \"Authentication\",\n\t\t\treason: /expired/i.test(normalized) ? \"expired\" : \"invalid\",\n\t\t\tmessage: normalized,\n\t\t\tretryable: false,\n\t\t};\n\t}\n\treturn { _tag: \"Unknown\", message: normalized, retryable: false };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAqBA,MAAM,UAAU,UACf,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK,IAC/D,QACD,KAAA;AAEJ,MAAM,kBAAkB,UACvB,OAAO,UAAU,YAAY,MAAM,KAAK,CAAC,CAAC,SAAS,IAAI,MAAM,KAAK,IAAI,KAAA;AAEvE,MAAM,oBAAoB,YAA4B;CAErD,OADgB,QAAQ,KAAK,CAAC,CAAC,QAAQ,YAAY,EACtC,CAAC,CAAC,QAAQ,gBAAgB,SAAS,KAAK,YAAY,CAAC;AACnE;AAEA,MAAM,gBAAgB,UAA2B;CAChD,MAAM,QAAQ,OAAO,KAAK;CAC1B,MAAM,OAAO,OAAO,OAAO,IAAI;CAC/B,IAAI,OAAO,SAAS,qBACnB,OAAO,iBAAiB,eAAe,MAAM,OAAO,KAAK,kCAAkC;CAE5F,IAAI,iBAAiB,OAAO,OAAO,iBAAiB,eAAe,MAAM,OAAO,KAAK,MAAM,IAAI;CAC/F,OAAO,iBAAiB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mjs";
|
|
2
2
|
import { C as NamedError, _ as optionsKey, a as KnownProviderEnumSchema, c as calculateCost, d as getModels, f as getProviders, h as modelsAreEqual, i as KnownProviderEnum, l as clampThinkingLevel, m as model_exports, n as APIMethodEnumSchema, r as ActiveThinkingLevel, s as ThinkingBudgets$1, t as APIMethodEnum, u as getModel, v as registry, y as thinkingTokenBudgetField } from "./model-Czo0SKj0.mjs";
|
|
3
3
|
import { C as ToolCallSchema, D as transformMessages, E as resolveJsonSchemaConstraint, S as AssistantMessageSchema, T as message_exports, g as shortHash, n as createOpenAICodex, r as openaiCodex, v as openAICodexTools, w as createAssistantMessage$1, x as resolveOpenAICodexToolConstraint } from "./openai-codex-MpxV35tx.mjs";
|
|
4
|
-
import { r as normalize, t as failure_exports } from "./failure-
|
|
4
|
+
import { r as normalize, t as failure_exports } from "./failure-Bm4tDJMr.mjs";
|
|
5
5
|
import { i as packageForModel, o as resolveLanguageModel, r as loadProviderFactory } from "./registry-CZtcfRPL.mjs";
|
|
6
6
|
import { i as githubCopilot, r as createGitHubCopilot } from "./github-copilot-eDhLBMfL.mjs";
|
|
7
7
|
import Type$2, { Type, Type as Type$1 } from "typebox";
|
|
@@ -377,7 +377,7 @@ const ThinkingBudgets = ThinkingBudgets$1;
|
|
|
377
377
|
const SharedOptions = Type$1.Evaluate(Type$1.Intersect([GenerationOptions, HelperOptions]));
|
|
378
378
|
/** Headroom left for the prompt when sizing a response against the context window. */
|
|
379
379
|
const CONTEXT_SAFETY_TOKENS = 4096;
|
|
380
|
-
const MIN_MAX_TOKENS =
|
|
380
|
+
const MIN_MAX_TOKENS = 16;
|
|
381
381
|
/**
|
|
382
382
|
* The model's own ceiling, unless the caller named a smaller one.
|
|
383
383
|
*
|
|
@@ -727,7 +727,10 @@ function googleThinkingLevel(mapped) {
|
|
|
727
727
|
function disabledProviderOptions(model) {
|
|
728
728
|
if (!model.reasoning) return {};
|
|
729
729
|
const key = optionsKey(model);
|
|
730
|
-
if (key === "anthropic" || key === "google-vertex-anthropic")
|
|
730
|
+
if (key === "anthropic" || key === "google-vertex-anthropic") {
|
|
731
|
+
if (model.thinkingLevelMap?.off === null) return {};
|
|
732
|
+
return { [key]: { thinking: { type: "disabled" } } };
|
|
733
|
+
}
|
|
731
734
|
if (key === "github-copilot") {
|
|
732
735
|
if (model.api?.method === APIMethodEnum.messages) return { [key]: { thinking: { type: "disabled" } } };
|
|
733
736
|
return {};
|
|
@@ -1031,6 +1034,25 @@ function normalizeOpenAICodexToolCallId(id, model, source) {
|
|
|
1031
1034
|
if (!normalizedItemId.startsWith("fc_") && !normalizedItemId.startsWith("ctc_")) normalizedItemId = normalizeOpenAICodexIdPart(`fc_${normalizedItemId}`);
|
|
1032
1035
|
return `${normalizedCallId}|${normalizedItemId}`;
|
|
1033
1036
|
}
|
|
1037
|
+
/**
|
|
1038
|
+
* OpenAI (`call_id`, at most 64 characters), Anthropic (`^[a-zA-Z0-9_-]+$`) and
|
|
1039
|
+
* OpenRouter upstreams take a foreign tool call ID verbatim, so a Codex
|
|
1040
|
+
* `call|item` ID keeps only its unique call half.
|
|
1041
|
+
*/
|
|
1042
|
+
function normalizeForeignToolCallId(id) {
|
|
1043
|
+
if (/^[a-zA-Z0-9_-]{1,64}$/.test(id)) return id;
|
|
1044
|
+
return normalizeOpenAICodexIdPart(id.split("|")[0] ?? id);
|
|
1045
|
+
}
|
|
1046
|
+
function toolCallIdNormalizer(model) {
|
|
1047
|
+
switch (model.protocol) {
|
|
1048
|
+
case KnownProviderEnum.openaiCodex: return normalizeOpenAICodexToolCallId;
|
|
1049
|
+
case KnownProviderEnum.openai:
|
|
1050
|
+
case KnownProviderEnum.anthropic:
|
|
1051
|
+
case KnownProviderEnum.googleVertexAnthropic:
|
|
1052
|
+
case KnownProviderEnum.openrouter: return normalizeForeignToolCallId;
|
|
1053
|
+
default: return;
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1034
1056
|
function isRecord(value) {
|
|
1035
1057
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1036
1058
|
}
|
|
@@ -1152,7 +1174,7 @@ function assistantMessages(message, model) {
|
|
|
1152
1174
|
}
|
|
1153
1175
|
function convertMessages(context, model) {
|
|
1154
1176
|
const messages = [];
|
|
1155
|
-
const transformedMessages = transformMessages(context.messages, model, model
|
|
1177
|
+
const transformedMessages = transformMessages(context.messages, model, toolCallIdNormalizer(model));
|
|
1156
1178
|
for (const msg of transformedMessages) {
|
|
1157
1179
|
if (msg.role === "user") {
|
|
1158
1180
|
messages.push(...userContent(msg.parts));
|