@openclaw/ai 2026.9.7 → 2026.10.1-beta.1
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/README.md +4 -1
- package/dist/{anthropic-Cw2pgccz.mjs → anthropic-CZv6XFER.mjs} +52 -147
- package/dist/{anthropic-payload-policy-NIPVYXPq.d.mts → anthropic-payload-policy-BhCcgNdm.d.mts} +7 -4
- package/dist/{anthropic-stream-reducer-D9MCkl8Z.mjs → anthropic-stream-reducer-BQ1tjd7x.mjs} +369 -233
- package/dist/{api-registry-D-nbmSqr.d.mts → api-registry-DpU0Rj-I.d.mts} +4 -4
- package/dist/{provider-transcript-transform-JbFbHV8h.mjs → assistant-output-OLm-Oln0.mjs} +17 -17
- package/dist/{assistant-text-phase-C20rxWwP.mjs → assistant-text-phase-Bl1aDCB7.mjs} +2 -8
- package/dist/{azure-openai-responses-BwT3-X8P.mjs → azure-openai-responses-DH7bd3QT.mjs} +12 -17
- package/dist/{azure-openai-responses-client-compat-C7K7QfUE.mjs → azure-openai-responses-client-compat-D0dvJMbZ.mjs} +3 -10
- package/dist/{base64-C1PsYcRQ.mjs → base64-C8CdcsjU.mjs} +3 -45
- package/dist/cloudflare-5qSGvIUH.mjs +39 -0
- package/dist/{diagnostics-CJaB6g8J.mjs → diagnostics-Caj-4RBA.mjs} +19 -37
- package/dist/diagnostics.d.mts +4 -4
- package/dist/diagnostics.mjs +2 -2
- package/dist/{event-stream-vd9UnCAU.mjs → event-stream-C5AbCAaZ.mjs} +29 -1
- package/dist/event-stream-DqDQWqiy.d.mts +1 -0
- package/dist/{event-stream-DOPFYVqs.d.mts → event-stream-DrRM_90c.d.mts} +1 -1
- package/dist/event-stream.d.mts +2 -2
- package/dist/event-stream.mjs +1 -1
- package/dist/{github-copilot-request-facts-BTEBMeOv.mjs → github-copilot-request-facts-DEE6gcB9.mjs} +3 -1
- package/dist/{google-BfapkS_K.mjs → google-1WLOtb8w.mjs} +12 -9
- package/dist/{google-interactions-DW3iXzjc.mjs → google-interactions-wrnE6MLw.mjs} +39 -49
- package/dist/{google-messages-CtjVtVot.mjs → google-messages-BwPPycw6.mjs} +11 -17
- package/dist/{google-shared-Y2YfotEu.mjs → google-shared-Eql1OMPU.mjs} +5 -6
- package/dist/{google-vertex-Dov4kBWu.mjs → google-vertex-0LrlRoO3.mjs} +11 -11
- package/dist/{host-rxlNaBwm.d.mts → host-BinBeGcQ.d.mts} +12 -4
- package/dist/{host-CHi3X87F.mjs → host-DCW52iHe.mjs} +57 -9
- package/dist/{host-policy-BOAwRg_M.mjs → host-policy-B3jc4Rpn.mjs} +9 -2
- package/dist/{index-D6KsSE74.d.mts → index-a8e_oKnu.d.mts} +7 -5
- package/dist/index.d.mts +23 -7
- package/dist/index.mjs +7 -7
- package/dist/internal/anthropic.d.mts +6 -6
- package/dist/internal/anthropic.mjs +5 -5
- package/dist/internal/google-model-family.mjs +1 -1
- package/dist/internal/openai-completions-compat.d.mts +1 -1
- package/dist/internal/openai-completions-compat.mjs +1 -1
- package/dist/internal/openai-responses-payload-policy.d.mts +1 -1
- package/dist/internal/openai-responses-payload-policy.mjs +2 -2
- package/dist/internal/openai.d.mts +14 -10
- package/dist/internal/openai.mjs +12 -12
- package/dist/internal/runtime.d.mts +18 -9
- package/dist/internal/runtime.mjs +9 -9
- package/dist/internal/shared.d.mts +6 -4
- package/dist/internal/shared.mjs +6 -6
- package/dist/internal/tool-schema.mjs +1 -1
- package/dist/json-schema-Bp07Qui3.mjs +22 -0
- package/dist/{llm-request-activity-BjtkplhG.mjs → llm-request-activity-D8f_oxHj.mjs} +1 -2
- package/dist/{mistral-RS6mboC-.mjs → mistral-DSt4vQAO.mjs} +18 -29
- package/dist/number-coercion-V8-BhME4.mjs +47 -0
- package/dist/{openai-chatgpt-responses-CYbidtrn.mjs → openai-chatgpt-responses-BC2x0Oqx.mjs} +215 -164
- package/dist/openai-completions-DNyHnXKg.mjs +25 -0
- package/dist/{openai-completions-compat-qJjmqQ71.d.mts → openai-completions-compat-BYdYpXhU.d.mts} +3 -3
- package/dist/{openai-completions-compat-BOVWBZDn.mjs → openai-completions-compat-BdmlhD4u.mjs} +30 -23
- package/dist/{openai-completions-stream-CDCuw3DP.mjs → openai-completions-transport-DWM2mQDB.mjs} +389 -76
- package/dist/{openai-prompt-cache-CouErLh7.d.mts → openai-prompt-cache-45-AH_xv.d.mts} +2 -2
- package/dist/{openai-prompt-cache-D2V7MqR7.mjs → openai-prompt-cache-I8YQTzf8.mjs} +1 -1
- package/dist/{openai-responses-compaction-replay-DiYn-gFM.d.mts → openai-responses-compaction-replay-BClApUIf.d.mts} +4 -4
- package/dist/{openai-responses-compaction-window-UNK1GDpy.mjs → openai-responses-compaction-window-m878aVpU.mjs} +25 -83
- package/dist/{openai-reasoning-effort-ConhwkeX.mjs → openai-responses-contracts-BKu8O7l4.mjs} +106 -7
- package/dist/{openai-responses-contracts-D1iZ0njF.d.mts → openai-responses-contracts-Br5IIw_h.d.mts} +16 -5
- package/dist/openai-responses-prompt-observer-internal-CCg7B6l4.mjs +32 -0
- package/dist/{openai-responses-shared-DL4ulQn7.mjs → openai-responses-shared-C7oVyjED.mjs} +297 -312
- package/dist/{openai-responses-terminal-usage-BE7lf7nW.d.mts → openai-responses-terminal-usage-DgImcyJu.d.mts} +2 -2
- package/dist/{openai-responses-CKCBEc2W.mjs → openai-responses-uZ5oWSp7.mjs} +12 -21
- package/dist/{openai-tool-schema-vsl-cE-n.mjs → openai-tool-schema-DYNePiF8.mjs} +66 -36
- package/dist/{openai-transport-params-BwlpzX-2.mjs → openai-transport-params-JFsnIyto.mjs} +25 -30
- package/dist/openai-web-search-tools-Cfu0uLyN.mjs +14 -0
- package/dist/{positive-integer-CjN5OJbH.mjs → positive-integer-CwLi8LUL.mjs} +1 -1
- package/dist/{provider-error-CwT_j2v0.mjs → provider-error-DQBE1bUQ.mjs} +17 -28
- package/dist/{provider-options-Df7ov0K1.d.mts → provider-options-D5ABCV_l.d.mts} +2 -2
- package/dist/{provider-replay-context-DsyI5jOP.mjs → provider-replay-context-C7Bmi84a.mjs} +6 -2
- package/dist/{provider-transport-turn-state-BheUi_hl.mjs → provider-transport-turn-state-_M2kLdUE.mjs} +25 -3
- package/dist/{provider-types-d4XnoZMd.d.mts → provider-types-F8Mqc9Ma.d.mts} +3 -3
- package/dist/provider-types.d.mts +6 -6
- package/dist/providers.d.mts +2 -2
- package/dist/providers.mjs +14 -26
- package/dist/{reasoning-tag-text-partitioner-B6FIIBt6.mjs → reasoning-tag-text-partitioner-Ju9VpUGl.mjs} +23 -37
- package/dist/required-api-key-D4kn3252.mjs +9 -0
- package/dist/sanitize-unicode-CjDG6jJx.d.mts +5 -0
- package/dist/{session-affinity-Bcunsn4I.mjs → session-affinity-DA4WHv1h.mjs} +2 -6
- package/dist/session-resources-D1wgDQ8C.mjs +40 -0
- package/dist/{simple-options-CGAkCwtM.mjs → simple-options-BkKTXxhp.mjs} +7 -11
- package/dist/{src-H4aXcFuX.mjs → src-B0NIt2UK.mjs} +7 -4
- package/dist/stream-DSdzKsDK.mjs +275 -0
- package/dist/{stream-first-event-timeout-B9o0S4SZ.mjs → stream-first-event-timeout-D9ZmL_s9.mjs} +3 -3
- package/dist/{string-coerce-fsri9iCu.mjs → string-coerce-CtgOVOSv.mjs} +5 -1
- package/dist/{string-normalization-J9ZiLfGO.mjs → string-normalization-PN10hf6d.mjs} +1 -1
- package/dist/{transport-utils-C-4bf2Ok.mjs → text-signature-MLwfi6fq.mjs} +18 -18
- package/dist/{transport-stream-shared-yYhXa4kX.d.mts → transport-stream-shared-BcAKh2XH.d.mts} +6 -19
- package/dist/{transport-stream-shared-Dh5qKJ8e.mjs → transport-stream-shared-CxXXz_Dd.mjs} +171 -56
- package/dist/transports.d.mts +22 -23
- package/dist/transports.mjs +251 -495
- package/dist/types-BuiEBM3u.d.mts +1 -0
- package/dist/types-CQc6JNG4.mjs +69 -0
- package/dist/{types-CLLR3eB4.d.mts → types-DvzmWW8J.d.mts} +58 -6
- package/dist/types.d.mts +6 -6
- package/dist/types.mjs +5 -5
- package/dist/usage-CJH5D6Ea.mjs +19 -0
- package/dist/{validation-Cat2wQsc.d.mts → validation-B3lQt_VE.d.mts} +1 -1
- package/dist/{validation-BFZc40Ig.mjs → validation-DbqlIfDn.mjs} +15 -30
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +4 -4
- package/dist/cache-retention-0x979a5V.mjs +0 -12
- package/dist/event-stream-CMQfX_yr.d.mts +0 -1
- package/dist/github-copilot-headers-B37TB3rB.mjs +0 -30
- package/dist/openai-completions-D14ihPYk.mjs +0 -188
- package/dist/openai-provider-client-CwfsGBbA.mjs +0 -24
- package/dist/openai-responses-contracts-CLxnqS9p.mjs +0 -81
- package/dist/openai-responses-prompt-observer-internal-iAqLb4tk.mjs +0 -198
- package/dist/sanitize-unicode-BZiVbGwK.d.mts +0 -24
- package/dist/session-resources-CkR4WWy1.mjs +0 -21
- package/dist/stream-DDsCBgd-.mjs +0 -68
- package/dist/types-CB-_vNyI.d.mts +0 -1
- package/dist/types-LFWwv0cF.mjs +0 -8
package/dist/providers.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { t as AssistantMessageEventStream } from "./event-stream-
|
|
2
|
-
import { n as projectProviderError } from "./provider-error-
|
|
3
|
-
import { n as clampOpenAIPromptCacheKey, t as OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH } from "./openai-prompt-cache-
|
|
1
|
+
import { t as AssistantMessageEventStream } from "./event-stream-C5AbCAaZ.mjs";
|
|
2
|
+
import { n as projectProviderError } from "./provider-error-DQBE1bUQ.mjs";
|
|
3
|
+
import { n as clampOpenAIPromptCacheKey, t as OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH } from "./openai-prompt-cache-I8YQTzf8.mjs";
|
|
4
|
+
import { t as createZeroUsage } from "./usage-CJH5D6Ea.mjs";
|
|
4
5
|
//#region packages/ai/src/providers/register-builtins.ts
|
|
5
6
|
/** Source id used for built-in API provider registrations. */
|
|
6
7
|
const BUILT_IN_API_PROVIDER_SOURCE_ID = "core:built-in";
|
|
@@ -15,20 +16,7 @@ function createLazyLoadErrorMessage(model, error, signal) {
|
|
|
15
16
|
api: model.api,
|
|
16
17
|
provider: model.provider,
|
|
17
18
|
model: model.id,
|
|
18
|
-
usage:
|
|
19
|
-
input: 0,
|
|
20
|
-
output: 0,
|
|
21
|
-
cacheRead: 0,
|
|
22
|
-
cacheWrite: 0,
|
|
23
|
-
totalTokens: 0,
|
|
24
|
-
cost: {
|
|
25
|
-
input: 0,
|
|
26
|
-
output: 0,
|
|
27
|
-
cacheRead: 0,
|
|
28
|
-
cacheWrite: 0,
|
|
29
|
-
total: 0
|
|
30
|
-
}
|
|
31
|
-
},
|
|
19
|
+
usage: createZeroUsage(),
|
|
32
20
|
...projectProviderError(error, signal),
|
|
33
21
|
timestamp: Date.now()
|
|
34
22
|
};
|
|
@@ -62,39 +50,39 @@ function createLazyRegistration(api, importModule, select) {
|
|
|
62
50
|
};
|
|
63
51
|
}
|
|
64
52
|
const registerBuiltIns = [
|
|
65
|
-
createLazyRegistration("anthropic-messages", () => import("./anthropic-
|
|
53
|
+
createLazyRegistration("anthropic-messages", () => import("./anthropic-CZv6XFER.mjs").then((n) => n.t), (module) => ({
|
|
66
54
|
stream: module.streamAnthropic,
|
|
67
55
|
streamSimple: module.streamSimpleAnthropic
|
|
68
56
|
})),
|
|
69
|
-
createLazyRegistration("openai-completions", () => import("./openai-completions-
|
|
57
|
+
createLazyRegistration("openai-completions", () => import("./openai-completions-DNyHnXKg.mjs").then((n) => n.t), (module) => ({
|
|
70
58
|
stream: module.streamOpenAICompletions,
|
|
71
59
|
streamSimple: module.streamSimpleOpenAICompletions
|
|
72
60
|
})),
|
|
73
|
-
createLazyRegistration("mistral-conversations", () => import("./mistral-
|
|
61
|
+
createLazyRegistration("mistral-conversations", () => import("./mistral-DSt4vQAO.mjs"), (module) => ({
|
|
74
62
|
stream: module.streamMistral,
|
|
75
63
|
streamSimple: module.streamSimpleMistral
|
|
76
64
|
})),
|
|
77
|
-
createLazyRegistration("openai-responses", () => import("./openai-responses-
|
|
65
|
+
createLazyRegistration("openai-responses", () => import("./openai-responses-uZ5oWSp7.mjs").then((n) => n.t), (module) => ({
|
|
78
66
|
stream: module.streamOpenAIResponses,
|
|
79
67
|
streamSimple: module.streamSimpleOpenAIResponses
|
|
80
68
|
})),
|
|
81
|
-
createLazyRegistration("azure-openai-responses", () => import("./azure-openai-responses-
|
|
69
|
+
createLazyRegistration("azure-openai-responses", () => import("./azure-openai-responses-DH7bd3QT.mjs"), (module) => ({
|
|
82
70
|
stream: module.streamAzureOpenAIResponses,
|
|
83
71
|
streamSimple: module.streamSimpleAzureOpenAIResponses
|
|
84
72
|
})),
|
|
85
|
-
createLazyRegistration("openai-chatgpt-responses", () => import("./openai-chatgpt-responses-
|
|
73
|
+
createLazyRegistration("openai-chatgpt-responses", () => import("./openai-chatgpt-responses-BC2x0Oqx.mjs"), (module) => ({
|
|
86
74
|
stream: module.streamOpenAICodexResponses,
|
|
87
75
|
streamSimple: module.streamSimpleOpenAICodexResponses
|
|
88
76
|
})),
|
|
89
|
-
createLazyRegistration("google-generative-ai", () => import("./google-
|
|
77
|
+
createLazyRegistration("google-generative-ai", () => import("./google-1WLOtb8w.mjs"), (module) => ({
|
|
90
78
|
stream: module.streamGoogle,
|
|
91
79
|
streamSimple: module.streamSimpleGoogle
|
|
92
80
|
})),
|
|
93
|
-
createLazyRegistration("google-interactions", () => import("./google-interactions-
|
|
81
|
+
createLazyRegistration("google-interactions", () => import("./google-interactions-wrnE6MLw.mjs"), (module) => ({
|
|
94
82
|
stream: module.streamGoogleInteractions,
|
|
95
83
|
streamSimple: module.streamSimpleGoogleInteractions
|
|
96
84
|
})),
|
|
97
|
-
createLazyRegistration("google-vertex", () => import("./google-vertex-
|
|
85
|
+
createLazyRegistration("google-vertex", () => import("./google-vertex-0LrlRoO3.mjs"), (module) => ({
|
|
98
86
|
stream: module.streamGoogleVertex,
|
|
99
87
|
streamSimple: module.streamSimpleGoogleVertex
|
|
100
88
|
}))
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-BhDjJH2R.mjs";
|
|
2
|
-
import "./provider-error-
|
|
2
|
+
import "./provider-error-DQBE1bUQ.mjs";
|
|
3
3
|
import { t as expectDefined } from "./expect-lbe3Hgrh.mjs";
|
|
4
4
|
//#region node_modules/.pnpm/mdast-util-to-string@4.0.0/node_modules/mdast-util-to-string/lib/index.js
|
|
5
5
|
/**
|
|
@@ -11931,14 +11931,11 @@ function reduceReasoningText(text, codeSpans, state, options) {
|
|
|
11931
11931
|
const scan = scanReasoningTags(text.slice(start), options.final);
|
|
11932
11932
|
const tags = [];
|
|
11933
11933
|
for (const scannedTag of scan.tags) {
|
|
11934
|
-
const
|
|
11935
|
-
|
|
11936
|
-
|
|
11937
|
-
|
|
11938
|
-
|
|
11939
|
-
text: scannedTag.text
|
|
11940
|
-
};
|
|
11941
|
-
if (!isInsideCode(tag.index, codeSpans)) tags.push(tag);
|
|
11934
|
+
const index = scannedTag.index + start;
|
|
11935
|
+
if (!isInsideCode(index, codeSpans)) tags.push({
|
|
11936
|
+
...scannedTag,
|
|
11937
|
+
index
|
|
11938
|
+
});
|
|
11942
11939
|
}
|
|
11943
11940
|
const mustParseRemainder = [];
|
|
11944
11941
|
if (options.scope === "leading") {
|
|
@@ -11950,9 +11947,7 @@ function reduceReasoningText(text, codeSpans, state, options) {
|
|
|
11950
11947
|
}
|
|
11951
11948
|
}
|
|
11952
11949
|
let cursor = start;
|
|
11953
|
-
for (
|
|
11954
|
-
const tag = tags[tagIndex];
|
|
11955
|
-
if (!tag) continue;
|
|
11950
|
+
for (const [tagIndex, tag] of tags.entries()) {
|
|
11956
11951
|
const beforeTag = text.slice(cursor, tag.index);
|
|
11957
11952
|
append(beforeTag);
|
|
11958
11953
|
const tagEnd = tag.index + tag.text.length;
|
|
@@ -12094,6 +12089,19 @@ function createReasoningTagTextPartitioner() {
|
|
|
12094
12089
|
else target.push({ ...addition });
|
|
12095
12090
|
}
|
|
12096
12091
|
};
|
|
12092
|
+
const reduceSafePrefix = (start, end, probeEnd, output) => {
|
|
12093
|
+
const scan = scanReasoningTags(source.slice(start, end), false);
|
|
12094
|
+
const reduceEnd = scan.pendingStart === void 0 ? end : start + scan.pendingStart;
|
|
12095
|
+
merge(output, reduceReasoningText(source.slice(start, reduceEnd), [], reduction, {
|
|
12096
|
+
final: false,
|
|
12097
|
+
mode: "visible",
|
|
12098
|
+
scope: "all"
|
|
12099
|
+
}));
|
|
12100
|
+
emitted = reduceEnd;
|
|
12101
|
+
fastPathCheckedThrough = reduceEnd;
|
|
12102
|
+
if (scan.pendingStart !== void 0) startPendingTagProbe(reduceEnd, probeEnd);
|
|
12103
|
+
holdStart = reduction.depth > 0 || scan.pendingStart !== void 0 ? emitted : void 0;
|
|
12104
|
+
};
|
|
12097
12105
|
const emitSafePrefix = (limit, output, appended) => {
|
|
12098
12106
|
if (strictMode) {
|
|
12099
12107
|
holdStart ??= emitted;
|
|
@@ -12103,17 +12111,7 @@ function createReasoningTagTextPartitioner() {
|
|
|
12103
12111
|
holdStart ??= emitted;
|
|
12104
12112
|
const segment = source.slice(emitted, limit);
|
|
12105
12113
|
if (!fastPathCodeSafe || /[\r\n`]/u.test(segment)) return;
|
|
12106
|
-
|
|
12107
|
-
const reduceEnd = scan.pendingStart === void 0 ? limit : emitted + scan.pendingStart;
|
|
12108
|
-
merge(output, reduceReasoningText(source.slice(emitted, reduceEnd), [], reduction, {
|
|
12109
|
-
final: false,
|
|
12110
|
-
mode: "visible",
|
|
12111
|
-
scope: "all"
|
|
12112
|
-
}));
|
|
12113
|
-
emitted = reduceEnd;
|
|
12114
|
-
fastPathCheckedThrough = reduceEnd;
|
|
12115
|
-
if (scan.pendingStart !== void 0) startPendingTagProbe(reduceEnd, limit);
|
|
12116
|
-
holdStart = reduction.depth > 0 || scan.pendingStart !== void 0 ? emitted : void 0;
|
|
12114
|
+
reduceSafePrefix(emitted, limit, limit, output);
|
|
12117
12115
|
return;
|
|
12118
12116
|
}
|
|
12119
12117
|
if (holdStart !== void 0 || emitted >= limit) return;
|
|
@@ -12180,19 +12178,7 @@ function createReasoningTagTextPartitioner() {
|
|
|
12180
12178
|
source.indexOf("\n", special)
|
|
12181
12179
|
].filter((index) => index !== -1 && index < limit);
|
|
12182
12180
|
const safeLimit = boundaries.length > 0 ? Math.min(...boundaries) : limit;
|
|
12183
|
-
|
|
12184
|
-
const reduceEnd = pendingAt === void 0 ? safeLimit : special + pendingAt;
|
|
12185
|
-
merge(output, reduceReasoningText(source.slice(special, reduceEnd), [], reduction, {
|
|
12186
|
-
final: false,
|
|
12187
|
-
mode: "visible",
|
|
12188
|
-
scope: "all"
|
|
12189
|
-
}));
|
|
12190
|
-
emitted = reduceEnd;
|
|
12191
|
-
fastPathCheckedThrough = reduceEnd;
|
|
12192
|
-
if (pendingAt !== void 0) {
|
|
12193
|
-
holdStart = reduceEnd;
|
|
12194
|
-
startPendingTagProbe(reduceEnd, limit);
|
|
12195
|
-
} else holdStart = reduction.depth > 0 ? emitted : void 0;
|
|
12181
|
+
reduceSafePrefix(special, safeLimit, limit, output);
|
|
12196
12182
|
}
|
|
12197
12183
|
};
|
|
12198
12184
|
const processBlock = (end, final, output, parsedCodeSpans, parsedRetainStart) => {
|
|
@@ -12350,7 +12336,7 @@ function createReasoningTagTextPartitioner() {
|
|
|
12350
12336
|
const codeSpans = ownership.codeSpans;
|
|
12351
12337
|
nonFinalRetainStart = ownership.retainStart;
|
|
12352
12338
|
nonFinalOpenEndedCode = codeSpans.some(([, spanEnd]) => spanEnd === source.length);
|
|
12353
|
-
if (!
|
|
12339
|
+
if (!nonFinalOpenEndedCode) compactCommittedSource(ownership.retainStart);
|
|
12354
12340
|
}
|
|
12355
12341
|
}
|
|
12356
12342
|
if (final) compactCommittedSource(source.length);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { n as getEnvApiKey } from "./env-api-keys-CyX4VKGO.mjs";
|
|
2
|
+
//#region packages/ai/src/utils/required-api-key.ts
|
|
3
|
+
function requireApiKey(provider, apiKey) {
|
|
4
|
+
const resolved = apiKey || getEnvApiKey(provider);
|
|
5
|
+
if (!resolved) throw new Error(`No API key for provider: ${provider}`);
|
|
6
|
+
return resolved;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { requireApiKey as t };
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
//#region packages/ai/src/transports/session-affinity.ts
|
|
2
2
|
function isOpencodeEndpoint(baseUrl) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
return url.protocol === "https:" && url.hostname.replace(/\.$/, "") === "opencode.ai";
|
|
6
|
-
} catch {
|
|
7
|
-
return false;
|
|
8
|
-
}
|
|
3
|
+
const url = URL.parse(baseUrl);
|
|
4
|
+
return url?.protocol === "https:" && url.hostname.replace(/\.$/, "") === "opencode.ai";
|
|
9
5
|
}
|
|
10
6
|
/** Required conversation identity is independent of optional prompt caching. */
|
|
11
7
|
function resolveOpencodeSessionHeaders(model, options) {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
//#region packages/ai/src/session-resources.ts
|
|
2
|
+
const sessionResourceCleanups = /* @__PURE__ */ new Set();
|
|
3
|
+
const sessionResourceCleanupObservers = /* @__PURE__ */ new Set();
|
|
4
|
+
const sessionResourceOwnerIds = /* @__PURE__ */ new WeakMap();
|
|
5
|
+
let nextSessionResourceOwnerId = 1;
|
|
6
|
+
/** Returns a process-local key that keeps retained resources separated by runtime owner. */
|
|
7
|
+
function getSessionResourceOwnerId(owner) {
|
|
8
|
+
const existing = sessionResourceOwnerIds.get(owner);
|
|
9
|
+
if (existing !== void 0) return existing;
|
|
10
|
+
const id = nextSessionResourceOwnerId++;
|
|
11
|
+
sessionResourceOwnerIds.set(owner, id);
|
|
12
|
+
return id;
|
|
13
|
+
}
|
|
14
|
+
/** Registers a session-resource cleanup hook and returns an unregister function. */
|
|
15
|
+
function registerSessionResourceCleanup(cleanup) {
|
|
16
|
+
sessionResourceCleanups.add(cleanup);
|
|
17
|
+
return () => {
|
|
18
|
+
sessionResourceCleanups.delete(cleanup);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** Registers metadata cleanup that runs only after every resource cleanup succeeds. */
|
|
22
|
+
function registerSessionResourceCleanupObserver(observer) {
|
|
23
|
+
sessionResourceCleanupObservers.add(observer);
|
|
24
|
+
return () => {
|
|
25
|
+
sessionResourceCleanupObservers.delete(observer);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/** Runs all registered cleanup hooks, aggregating failures after every hook has run. */
|
|
29
|
+
function cleanupSessionResources(sessionId, owner) {
|
|
30
|
+
const errors = [];
|
|
31
|
+
for (const cleanup of sessionResourceCleanups) try {
|
|
32
|
+
cleanup(sessionId, owner);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
errors.push(error);
|
|
35
|
+
}
|
|
36
|
+
if (errors.length > 0) throw new AggregateError(errors, "Failed to cleanup session resources");
|
|
37
|
+
for (const observer of sessionResourceCleanupObservers) observer(sessionId, owner);
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
export { registerSessionResourceCleanupObserver as i, getSessionResourceOwnerId as n, registerSessionResourceCleanup as r, cleanupSessionResources as t };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { o as isRecord } from "./record-coerce-CNDovvft.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { n as normalizeLowercaseStringOrEmpty } from "./string-coerce-CtgOVOSv.mjs";
|
|
3
|
+
import { M as hasMediaPayload, r as getAiTransportHost } from "./host-DCW52iHe.mjs";
|
|
4
|
+
import { g as responsesServiceTierObserver } from "./openai-responses-contracts-BKu8O7l4.mjs";
|
|
5
|
+
import { o as truncateUtf16Safe } from "./provider-error-DQBE1bUQ.mjs";
|
|
6
|
+
import { P as sanitizeSurrogates, i as copyProviderAcceptanceObserver } from "./transport-stream-shared-CxXXz_Dd.mjs";
|
|
6
7
|
//#region packages/ai/src/utils/prompt-cache-stability.ts
|
|
7
8
|
/**
|
|
8
9
|
* Prompt-cache normalization helpers. They keep generated prompt sections
|
|
@@ -33,11 +34,6 @@ function normalizePromptCapabilityIds(capabilities) {
|
|
|
33
34
|
}
|
|
34
35
|
//#endregion
|
|
35
36
|
//#region packages/ai/src/utils/system-prompt-cache-boundary.ts
|
|
36
|
-
/**
|
|
37
|
-
* System prompt cache-boundary helpers.
|
|
38
|
-
*
|
|
39
|
-
* Keeps stable prompt prefixes separate from dynamic runtime additions for provider prompt caching.
|
|
40
|
-
*/
|
|
41
37
|
const SYSTEM_PROMPT_CACHE_BOUNDARY = "\n<!-- OPENCLAW_CACHE_BOUNDARY -->\n";
|
|
42
38
|
/** Producer-delimited Runtime facts; instructions must remain outside this region. */
|
|
43
39
|
const SYSTEM_PROMPT_RELOCATABLE_BOUNDARY = "\n<!-- OPENCLAW-RELOCATABLE-BOUNDARY -->\n";
|
|
@@ -80,8 +76,7 @@ function prependSystemPromptAdditionAfterCacheBoundary(params) {
|
|
|
80
76
|
const split = splitSystemPromptCacheBoundary(params.systemPrompt);
|
|
81
77
|
if (!split) return `${systemPromptAddition}\n\n${params.systemPrompt}`;
|
|
82
78
|
const dynamicSuffix = split.dynamicSuffix ? normalizeStructuredPromptSection(split.dynamicSuffix) : "";
|
|
83
|
-
|
|
84
|
-
return `${split.stablePrefix}${SYSTEM_PROMPT_CACHE_BOUNDARY}${systemPromptAddition}\n\n${dynamicSuffix}`;
|
|
79
|
+
return `${split.stablePrefix}${SYSTEM_PROMPT_CACHE_BOUNDARY}${systemPromptAddition}${dynamicSuffix ? `\n\n${dynamicSuffix}` : ""}`;
|
|
85
80
|
}
|
|
86
81
|
//#endregion
|
|
87
82
|
//#region packages/ai/src/providers/tool-result-text.ts
|
|
@@ -318,6 +313,7 @@ function buildBaseOptions(model, options, apiKey) {
|
|
|
318
313
|
metadata: options?.metadata
|
|
319
314
|
};
|
|
320
315
|
reasoningTagTextPolicy.copy(options, baseOptions);
|
|
316
|
+
responsesServiceTierObserver.copy(options, baseOptions);
|
|
321
317
|
modelRequestBodyState(baseOptions, options);
|
|
322
318
|
return copyProviderAcceptanceObserver(options, baseOptions);
|
|
323
319
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "./diagnostics-DzrF1h4J.mjs";
|
|
2
|
-
import "./validation-
|
|
2
|
+
import "./validation-DbqlIfDn.mjs";
|
|
3
3
|
//#region packages/llm-core/src/model-contracts/anthropic.ts
|
|
4
4
|
function normalizeClaudeModelId(modelId) {
|
|
5
5
|
const normalized = modelId?.trim().toLowerCase() ?? "";
|
|
@@ -66,6 +66,10 @@ function resolveClaudeMythos5ModelIdentity(ref) {
|
|
|
66
66
|
function bindsClaudeThinkingPrefix(ref) {
|
|
67
67
|
return resolveClaudeOpus55ModelIdentity(ref) !== void 0 || resolveClaudeSonnet55ModelIdentity(ref) !== void 0 || /^claude-fable-5-1(?=$|[^a-z0-9])/.test(resolveClaudeModelIdentity(ref));
|
|
68
68
|
}
|
|
69
|
+
/** Return whether Claude accepts operator instructions within conversation history. */
|
|
70
|
+
function supportsClaudeInHistorySystemMessages(ref) {
|
|
71
|
+
return resolveClaudeOpus5ModelIdentity(ref) !== void 0 || resolveClaudeSonnet5ModelIdentity(ref) !== void 0 || resolveClaudeFable5ModelIdentity(ref) !== void 0 || resolveClaudeMythos5ModelIdentity(ref) !== void 0 || /^claude-opus-4-8(?=$|[^a-z0-9])/.test(resolveClaudeModelIdentity(ref));
|
|
72
|
+
}
|
|
69
73
|
/** Return whether a Claude model requires adaptive thinking instead of manual budgets. */
|
|
70
74
|
function requiresClaudeMandatoryAdaptiveThinking(ref) {
|
|
71
75
|
const modelId = resolveClaudeModelIdentity(ref);
|
|
@@ -110,8 +114,7 @@ function supportsClaudeAdaptiveThinking(ref) {
|
|
|
110
114
|
}
|
|
111
115
|
/** Return whether a Claude model has a native 1M-token context window. */
|
|
112
116
|
function supportsClaude1MContext(ref) {
|
|
113
|
-
|
|
114
|
-
return resolveClaudeOpus5ModelIdentity(ref) !== void 0 || resolveClaudeSonnet5ModelIdentity(ref) !== void 0 || /(?:^|-)claude-(?:fable-5|mythos-(?:5|preview)|opus-4-(?:6|7|8)|sonnet-4-6)(?=$|[^a-z0-9])/.test(modelId);
|
|
117
|
+
return supportsClaudeAdaptiveThinking(ref);
|
|
115
118
|
}
|
|
116
119
|
/** Return whether a Claude model supports Anthropic's native fast mode. */
|
|
117
120
|
function supportsClaudeFastMode(ref) {
|
|
@@ -219,4 +222,4 @@ function calculateUsageCost(usage, pricing) {
|
|
|
219
222
|
return cost;
|
|
220
223
|
}
|
|
221
224
|
//#endregion
|
|
222
|
-
export { supportsClaudeFastMode as C, supportsClaudeAdaptiveThinking as S,
|
|
225
|
+
export { supportsClaudeFastMode as C, supportsClaudeNativeXhighEffort as E, supportsClaudeAdaptiveThinking as S, supportsClaudeNativeMaxEffort as T, resolveClaudeOpus55ModelIdentity as _, CLAUDE_OPUS_55_THINKING_PROFILE as a, resolveClaudeSonnet5ModelIdentity as b, CLAUDE_SONNET_5_THINKING_PROFILE as c, requiresClaudeDefaultSampling as d, requiresClaudeMandatoryAdaptiveThinking as f, resolveClaudeNativeThinkingLevelMap as g, resolveClaudeMythos5ModelIdentity as h, CLAUDE_FABLE_5_THINKING_PROFILE as i, bindsClaudeThinkingPrefix as l, resolveClaudeModelIdentity as m, normalizeModelCostConfig as n, CLAUDE_OPUS_5_THINKING_PROFILE as o, resolveClaudeFable5ModelIdentity as p, normalizeResolvedPricing as r, CLAUDE_SONNET_55_THINKING_PROFILE as s, calculateUsageCost as t, requiresClaudeBetweenToolsThinking as u, resolveClaudeOpus5ModelIdentity as v, supportsClaudeInHistorySystemMessages as w, supportsClaude1MContext as x, resolveClaudeSonnet55ModelIdentity as y };
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { i as bindAssistantMessageEventStream, o as getEventStreamCompletion } from "./event-stream-C5AbCAaZ.mjs";
|
|
2
|
+
import { i as getDefaultAiTransportHost, n as createAiTransportHost, o as runWithAiTransportHost, s as supportsScopedAiTransportHosts } from "./host-DCW52iHe.mjs";
|
|
3
|
+
import { i as registerSessionResourceCleanupObserver, t as cleanupSessionResources } from "./session-resources-D1wgDQ8C.mjs";
|
|
4
|
+
//#region packages/ai/src/api-registry.ts
|
|
5
|
+
function wrapStream(api, stream) {
|
|
6
|
+
return (model, context, options) => {
|
|
7
|
+
if (model.api !== api) throw new Error(`Mismatched api: ${model.api} expected ${api}`);
|
|
8
|
+
return stream(model, context, options);
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/** Creates an isolated provider registry for one runtime or tenant. */
|
|
12
|
+
function createApiRegistry() {
|
|
13
|
+
const providers = /* @__PURE__ */ new Map();
|
|
14
|
+
function registerApiProvider(provider, sourceId) {
|
|
15
|
+
providers.set(provider.api, {
|
|
16
|
+
provider: {
|
|
17
|
+
api: provider.api,
|
|
18
|
+
stream: wrapStream(provider.api, provider.stream),
|
|
19
|
+
streamSimple: wrapStream(provider.api, provider.streamSimple)
|
|
20
|
+
},
|
|
21
|
+
sourceId
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
function getApiProvider(api) {
|
|
25
|
+
return providers.get(api)?.provider;
|
|
26
|
+
}
|
|
27
|
+
function getApiProviders() {
|
|
28
|
+
return Array.from(providers.values(), (entry) => entry.provider);
|
|
29
|
+
}
|
|
30
|
+
function unregisterApiProviders(sourceId) {
|
|
31
|
+
for (const [api, entry] of providers.entries()) if (entry.sourceId === sourceId) providers.delete(api);
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
registerApiProvider,
|
|
35
|
+
getApiProvider,
|
|
36
|
+
getApiProviders,
|
|
37
|
+
unregisterApiProviders,
|
|
38
|
+
clearApiProviders: () => providers.clear()
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region packages/ai/src/stream.ts
|
|
43
|
+
const defaultHostSessionReferences = /* @__PURE__ */ new Set();
|
|
44
|
+
const defaultHostSessionFinalizer = new FinalizationRegistry((reference) => defaultHostSessionReferences.delete(reference));
|
|
45
|
+
function trackDefaultHostSessions(sessions) {
|
|
46
|
+
const reference = new WeakRef(sessions);
|
|
47
|
+
defaultHostSessionReferences.add(reference);
|
|
48
|
+
defaultHostSessionFinalizer.register(sessions, reference, reference);
|
|
49
|
+
}
|
|
50
|
+
registerSessionResourceCleanupObserver((sessionId, owner) => {
|
|
51
|
+
for (const reference of defaultHostSessionReferences) {
|
|
52
|
+
const sessions = reference.deref();
|
|
53
|
+
if (!sessions) {
|
|
54
|
+
defaultHostSessionReferences.delete(reference);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const pruneOwners = (owners) => {
|
|
58
|
+
if (owner) owners.delete(owner);
|
|
59
|
+
else owners.clear();
|
|
60
|
+
return owners.size === 0;
|
|
61
|
+
};
|
|
62
|
+
if (sessionId) {
|
|
63
|
+
const owners = sessions.get(sessionId);
|
|
64
|
+
if (owners && pruneOwners(owners)) sessions.delete(sessionId);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
for (const [ownedSessionId, owners] of sessions) if (pruneOwners(owners)) sessions.delete(ownedSessionId);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
function retainUnscopedStreamLifetime(stream, runWithHost) {
|
|
71
|
+
let releaseLifetime;
|
|
72
|
+
const lifetime = new Promise((resolve) => {
|
|
73
|
+
releaseLifetime = resolve;
|
|
74
|
+
});
|
|
75
|
+
runWithHost(() => lifetime);
|
|
76
|
+
let released = false;
|
|
77
|
+
let resultSettled = false;
|
|
78
|
+
let bufferSettled = false;
|
|
79
|
+
const releaseIfSettled = () => {
|
|
80
|
+
if (!released && resultSettled && bufferSettled) {
|
|
81
|
+
released = true;
|
|
82
|
+
releaseLifetime();
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
const push = stream.push.bind(stream);
|
|
86
|
+
const end = stream.end.bind(stream);
|
|
87
|
+
const result = stream.result.bind(stream);
|
|
88
|
+
const iterate = stream[Symbol.asyncIterator].bind(stream);
|
|
89
|
+
const bufferedEvents = [];
|
|
90
|
+
const bufferWaiters = /* @__PURE__ */ new Set();
|
|
91
|
+
let bufferError;
|
|
92
|
+
let resultPromise;
|
|
93
|
+
const wrapIterationError = (error) => new Error("Stream iteration failed", { cause: error });
|
|
94
|
+
const notifyBufferWaiters = () => {
|
|
95
|
+
for (const resolve of bufferWaiters) resolve();
|
|
96
|
+
bufferWaiters.clear();
|
|
97
|
+
};
|
|
98
|
+
const observeResult = () => {
|
|
99
|
+
if (!resultPromise) {
|
|
100
|
+
let providerResult;
|
|
101
|
+
try {
|
|
102
|
+
providerResult = runWithHost(result);
|
|
103
|
+
} catch (error) {
|
|
104
|
+
providerResult = Promise.reject(new Error("Stream result failed", { cause: error }));
|
|
105
|
+
}
|
|
106
|
+
providerResult.then(() => {
|
|
107
|
+
resultSettled = true;
|
|
108
|
+
releaseIfSettled();
|
|
109
|
+
}, () => {
|
|
110
|
+
resultSettled = true;
|
|
111
|
+
releaseIfSettled();
|
|
112
|
+
});
|
|
113
|
+
resultPromise = providerResult;
|
|
114
|
+
}
|
|
115
|
+
return resultPromise;
|
|
116
|
+
};
|
|
117
|
+
(async () => {
|
|
118
|
+
try {
|
|
119
|
+
const iterator = runWithHost(iterate);
|
|
120
|
+
while (true) {
|
|
121
|
+
const next = await runWithHost(() => iterator.next());
|
|
122
|
+
if (next.done) return;
|
|
123
|
+
bufferedEvents.push(next.value);
|
|
124
|
+
notifyBufferWaiters();
|
|
125
|
+
}
|
|
126
|
+
} catch (error) {
|
|
127
|
+
bufferError = wrapIterationError(error);
|
|
128
|
+
} finally {
|
|
129
|
+
bufferSettled = true;
|
|
130
|
+
notifyBufferWaiters();
|
|
131
|
+
observeResult().catch(() => {});
|
|
132
|
+
releaseIfSettled();
|
|
133
|
+
}
|
|
134
|
+
})();
|
|
135
|
+
return {
|
|
136
|
+
push: (event) => runWithHost(() => push(event)),
|
|
137
|
+
end: (message) => runWithHost(() => end(message)),
|
|
138
|
+
result: observeResult,
|
|
139
|
+
[Symbol.asyncIterator]() {
|
|
140
|
+
let index = 0;
|
|
141
|
+
let done = false;
|
|
142
|
+
const next = async () => {
|
|
143
|
+
if (done) return {
|
|
144
|
+
done: true,
|
|
145
|
+
value: void 0
|
|
146
|
+
};
|
|
147
|
+
if (index < bufferedEvents.length) {
|
|
148
|
+
const value = bufferedEvents[index];
|
|
149
|
+
if (value === void 0) throw new Error("Buffered stream event is missing");
|
|
150
|
+
index += 1;
|
|
151
|
+
return {
|
|
152
|
+
done: false,
|
|
153
|
+
value
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
if (bufferSettled) {
|
|
157
|
+
if (bufferError) throw bufferError;
|
|
158
|
+
done = true;
|
|
159
|
+
return {
|
|
160
|
+
done: true,
|
|
161
|
+
value: void 0
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
await new Promise((resolve) => {
|
|
165
|
+
bufferWaiters.add(resolve);
|
|
166
|
+
});
|
|
167
|
+
return next();
|
|
168
|
+
};
|
|
169
|
+
return {
|
|
170
|
+
[Symbol.asyncIterator]() {
|
|
171
|
+
return this;
|
|
172
|
+
},
|
|
173
|
+
next,
|
|
174
|
+
async return(value) {
|
|
175
|
+
done = true;
|
|
176
|
+
notifyBufferWaiters();
|
|
177
|
+
return {
|
|
178
|
+
done: true,
|
|
179
|
+
value
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
function createRuntime(registry, transportHost) {
|
|
187
|
+
const explicitHost = transportHost === void 0 ? void 0 : createAiTransportHost(transportHost);
|
|
188
|
+
const defaultHostsBySession = /* @__PURE__ */ new Map();
|
|
189
|
+
if (!explicitHost) trackDefaultHostSessions(defaultHostsBySession);
|
|
190
|
+
const resolveRuntimeHost = () => explicitHost ?? getDefaultAiTransportHost();
|
|
191
|
+
const startStream = (start, sessionId) => {
|
|
192
|
+
const host = resolveRuntimeHost();
|
|
193
|
+
if (!explicitHost) {
|
|
194
|
+
const hosts = defaultHostsBySession.get(sessionId) ?? /* @__PURE__ */ new Set();
|
|
195
|
+
hosts.add(host);
|
|
196
|
+
defaultHostsBySession.set(sessionId, hosts);
|
|
197
|
+
}
|
|
198
|
+
const runWithStreamHost = (operation) => runWithAiTransportHost(host, operation);
|
|
199
|
+
const started = runWithStreamHost(start);
|
|
200
|
+
const completion = getEventStreamCompletion(started);
|
|
201
|
+
const bound = bindAssistantMessageEventStream(started, runWithStreamHost);
|
|
202
|
+
if (completion) {
|
|
203
|
+
if (!supportsScopedAiTransportHosts()) {
|
|
204
|
+
let producerSettled = false;
|
|
205
|
+
const observedCompletion = completion.then(() => {
|
|
206
|
+
producerSettled = true;
|
|
207
|
+
}, (error) => {
|
|
208
|
+
producerSettled = true;
|
|
209
|
+
throw error;
|
|
210
|
+
});
|
|
211
|
+
runWithStreamHost(() => observedCompletion);
|
|
212
|
+
const result = runWithStreamHost(() => started.result());
|
|
213
|
+
return bindAssistantMessageEventStream(started, (operation) => producerSettled ? operation() : runWithStreamHost(operation), { result: () => result });
|
|
214
|
+
}
|
|
215
|
+
runWithStreamHost(() => completion);
|
|
216
|
+
}
|
|
217
|
+
return !completion && !supportsScopedAiTransportHosts() ? retainUnscopedStreamLifetime(started, runWithStreamHost) : bound;
|
|
218
|
+
};
|
|
219
|
+
function resolveApiProvider(api) {
|
|
220
|
+
const provider = registry.getApiProvider(api);
|
|
221
|
+
if (!provider) throw new Error(`No API provider registered for api: ${api}`);
|
|
222
|
+
return provider;
|
|
223
|
+
}
|
|
224
|
+
function stream(model, context, options) {
|
|
225
|
+
return startStream(() => resolveApiProvider(model.api).stream(model, context, options), options?.sessionId);
|
|
226
|
+
}
|
|
227
|
+
async function complete(model, context, options) {
|
|
228
|
+
return stream(model, context, options).result();
|
|
229
|
+
}
|
|
230
|
+
function streamSimple(model, context, options) {
|
|
231
|
+
return startStream(() => resolveApiProvider(model.api).streamSimple(model, context, options), options?.sessionId);
|
|
232
|
+
}
|
|
233
|
+
async function completeSimple(model, context, options) {
|
|
234
|
+
return streamSimple(model, context, options).result();
|
|
235
|
+
}
|
|
236
|
+
function cleanupSessionResources$1(sessionId) {
|
|
237
|
+
if (!supportsScopedAiTransportHosts()) {
|
|
238
|
+
cleanupSessionResources(sessionId);
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
const usedHosts = /* @__PURE__ */ new Set();
|
|
242
|
+
if (!explicitHost) {
|
|
243
|
+
if (sessionId) for (const host of defaultHostsBySession.get(sessionId) ?? []) usedHosts.add(host);
|
|
244
|
+
else for (const owners of defaultHostsBySession.values()) for (const host of owners) usedHosts.add(host);
|
|
245
|
+
usedHosts.add(getDefaultAiTransportHost());
|
|
246
|
+
}
|
|
247
|
+
const hosts = explicitHost ? [explicitHost] : [...usedHosts];
|
|
248
|
+
const errors = [];
|
|
249
|
+
for (const host of hosts) try {
|
|
250
|
+
runWithAiTransportHost(host, () => cleanupSessionResources(sessionId, host));
|
|
251
|
+
} catch (error) {
|
|
252
|
+
errors.push(error);
|
|
253
|
+
}
|
|
254
|
+
if (errors.length > 0) throw new AggregateError(errors, "Failed to cleanup runtime session resources");
|
|
255
|
+
}
|
|
256
|
+
return {
|
|
257
|
+
registry,
|
|
258
|
+
stream,
|
|
259
|
+
complete,
|
|
260
|
+
streamSimple,
|
|
261
|
+
completeSimple,
|
|
262
|
+
cleanupSessionResources: cleanupSessionResources$1
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
/** Creates an isolated LLM runtime backed by the supplied provider registry. */
|
|
266
|
+
function createLlmRuntime(registry = createApiRegistry()) {
|
|
267
|
+
return createRuntime(registry);
|
|
268
|
+
}
|
|
269
|
+
/** Creates a Node runtime whose provider work retains an explicit transport host. */
|
|
270
|
+
function createNodeLlmRuntime(registry = createApiRegistry(), transportHost = {}) {
|
|
271
|
+
if (!supportsScopedAiTransportHosts()) throw new Error("Explicit AI transport hosts require Node.js async context support");
|
|
272
|
+
return createRuntime(registry, transportHost);
|
|
273
|
+
}
|
|
274
|
+
//#endregion
|
|
275
|
+
export { createNodeLlmRuntime as n, createApiRegistry as r, createLlmRuntime as t };
|
package/dist/{stream-first-event-timeout-B9o0S4SZ.mjs → stream-first-event-timeout-D9ZmL_s9.mjs}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { i as clampTimerTimeoutMs } from "./number-coercion-V8-BhME4.mjs";
|
|
2
2
|
//#region packages/ai/src/utils/stream-first-event-timeout.ts
|
|
3
3
|
function getFirstStreamEventTimeoutMs(options) {
|
|
4
4
|
return options?.firstEventTimeoutMs;
|
|
@@ -21,14 +21,14 @@ function createFirstStreamEventTimeoutError(context) {
|
|
|
21
21
|
function createFirstStreamEventAbortController(parentSignal) {
|
|
22
22
|
const controller = new AbortController();
|
|
23
23
|
const abortFromParent = () => {
|
|
24
|
-
|
|
24
|
+
controller.abort(parentSignal?.reason);
|
|
25
25
|
};
|
|
26
26
|
if (parentSignal?.aborted) abortFromParent();
|
|
27
27
|
else parentSignal?.addEventListener("abort", abortFromParent, { once: true });
|
|
28
28
|
return {
|
|
29
29
|
signal: controller.signal,
|
|
30
30
|
abort(reason) {
|
|
31
|
-
|
|
31
|
+
controller.abort(reason);
|
|
32
32
|
},
|
|
33
33
|
dispose() {
|
|
34
34
|
parentSignal?.removeEventListener("abort", abortFromParent);
|
|
@@ -13,6 +13,10 @@ function normalizeNullableString(value) {
|
|
|
13
13
|
function normalizeOptionalString(value) {
|
|
14
14
|
return normalizeNullableString(value) ?? void 0;
|
|
15
15
|
}
|
|
16
|
+
/** Rejects only empty or non-string values while preserving whitespace. */
|
|
17
|
+
function readNonEmptyStringPreservingWhitespace(value) {
|
|
18
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
19
|
+
}
|
|
16
20
|
/** Stringifies primitive ids/flags before applying optional string normalization. */
|
|
17
21
|
function normalizeStringifiedOptionalString(value) {
|
|
18
22
|
if (typeof value === "string") return normalizeOptionalString(value);
|
|
@@ -31,4 +35,4 @@ function hasNonEmptyString(value) {
|
|
|
31
35
|
return normalizeOptionalString(value) !== void 0;
|
|
32
36
|
}
|
|
33
37
|
//#endregion
|
|
34
|
-
export { normalizeOptionalString as a, normalizeOptionalLowercaseString as i, normalizeLowercaseStringOrEmpty as n, normalizeStringifiedOptionalString as o, normalizeNullableString as r,
|
|
38
|
+
export { normalizeOptionalString as a, readStringValue as c, normalizeOptionalLowercaseString as i, normalizeLowercaseStringOrEmpty as n, normalizeStringifiedOptionalString as o, normalizeNullableString as r, readNonEmptyStringPreservingWhitespace as s, hasNonEmptyString as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as normalizeOptionalString } from "./string-coerce-
|
|
1
|
+
import { a as normalizeOptionalString } from "./string-coerce-CtgOVOSv.mjs";
|
|
2
2
|
//#region packages/normalization-core/src/string-normalization.ts
|
|
3
3
|
/** Coerces entries to strings, trims them, and drops empty results. */
|
|
4
4
|
function normalizeStringEntries(list) {
|