@openclaw/ai 2026.7.2-beta.6 → 2026.7.33
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 +5 -6
- package/dist/{anthropic-CH4UUnZr.mjs → anthropic-BML72tLz.mjs} +468 -101
- package/dist/{api-registry-DlMgPR39.d.mts → api-registry-BXYnCOIR.d.mts} +2 -1
- package/dist/{azure-openai-responses-client-compat-C7K7QfUE.mjs → azure-openai-responses-client-compat-a_O_GVQV.mjs} +2 -23
- package/dist/{azure-openai-responses-CImcwB83.mjs → azure-openai-responses-kEN8II8I.mjs} +13 -11
- package/dist/{env-api-keys-DrgeBuva.mjs → env-api-keys-CtMlqaQ4.mjs} +4 -5
- package/dist/{event-stream-YjaPW20U.d.mts → event-stream-0nZeBKl2.d.mts} +1 -1
- package/dist/{event-stream-D8n2uFee.mjs → event-stream-ReMmOTzX.mjs} +6 -14
- package/dist/event-stream.d.mts +1 -1
- package/dist/event-stream.mjs +1 -1
- package/dist/{github-copilot-headers-NCJtz9i0.mjs → github-copilot-headers-BsH5cqGj.mjs} +12 -1
- package/dist/{google-CtSg0iTS.mjs → google-DTM4O3e9.mjs} +5 -5
- package/dist/{google-shared-DNBz5rcD.mjs → google-shared-BAP0BQVi.mjs} +22 -34
- package/dist/{google-vertex-31f1uS9L.mjs → google-vertex-D58MZHCQ.mjs} +19 -6
- package/dist/host-4t713IeR.mjs +37 -0
- package/dist/{anthropic-SrGtwsJu.d.mts → index-BoTnz8cv.d.mts} +1 -27
- package/dist/index.d.mts +50 -7
- package/dist/index.mjs +5 -5
- package/dist/internal/anthropic.d.mts +62 -22
- package/dist/internal/anthropic.mjs +4 -5
- package/dist/internal/openai.d.mts +82 -98
- package/dist/internal/openai.mjs +6 -8
- package/dist/internal/runtime.d.mts +34 -13
- package/dist/internal/runtime.mjs +14 -26
- package/dist/internal/shared.d.mts +9 -26
- package/dist/internal/shared.mjs +2 -6
- package/dist/{json-parse-BvXNt1-7.mjs → json-parse-DzNSIQBq.mjs} +6 -4
- package/dist/{llm-request-activity-BjtkplhG.mjs → llm-request-activity-CehVkZP-.mjs} +19 -1
- package/dist/{mistral-CWmpvWYh.mjs → mistral-CePVNdws.mjs} +39 -141
- package/dist/model-utils-DgmOla96.mjs +69 -0
- package/dist/{openai-chatgpt-responses-B84Ibtrd.mjs → openai-chatgpt-responses-BHqbcipc.mjs} +154 -101
- package/dist/{openai-completions-DsOxhOD1.mjs → openai-completions-9qYFVS7H.mjs} +295 -81
- package/dist/{openai-responses-BT7A3sLu.mjs → openai-responses-D6l9URyV.mjs} +8 -10
- package/dist/openai-responses-shared-L3PWZvkm.mjs +1949 -0
- package/dist/{openai-tool-projection-OhX64DoP.mjs → openai-tool-projection-BPlyXt8H.mjs} +12 -32
- package/dist/providers.d.mts +2 -3
- package/dist/providers.mjs +10 -11
- package/dist/reasoning-tag-text-partitioner-axhAdUwg.mjs +394 -0
- package/dist/{src-QkygScBs.mjs → src-CZ503MYJ.mjs} +5 -24
- package/dist/{stream-first-event-timeout-BBys9hSb.mjs → stream-first-event-timeout-RjWszj8c.mjs} +22 -2
- package/dist/transform-messages-BhGF_fF4.mjs +507 -0
- package/dist/{types-bzp5k29J.d.mts → types-DRgdPqaZ.d.mts} +0 -19
- package/dist/types.d.mts +5 -5
- package/dist/types.mjs +4 -4
- package/dist/{validation-B-j7cOYp.d.mts → validation-BDMWOr8d.d.mts} +1 -1
- package/dist/{validation-DAa_yFOM.mjs → validation-FrchoOlv.mjs} +7 -2
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/npm-shrinkwrap.json +645 -0
- package/package.json +11 -36
- package/dist/anthropic-usage-DWU-x8MI.mjs +0 -459
- package/dist/cache-retention-0x979a5V.mjs +0 -12
- package/dist/deferred-event-buffer-DAvyP7qA.mjs +0 -19
- package/dist/error-coercion-DgxlWC0n.mjs +0 -15
- package/dist/host-B9GUmcra.d.mts +0 -173
- package/dist/host-Dog2WQiR.mjs +0 -369
- package/dist/index-BVVgDSdq.d.mts +0 -1
- package/dist/internal/retry-after.d.mts +0 -5
- package/dist/internal/retry-after.mjs +0 -101
- package/dist/number-coercion-DvG7SNMg.mjs +0 -129
- package/dist/openai-completions-compat-DBWjXoMZ.d.mts +0 -43
- package/dist/openai-prompt-cache-2uo_1OR1.d.mts +0 -7
- package/dist/openai-prompt-cache-mZTCdRPo.mjs +0 -12
- package/dist/openai-reasoning-compat-YgeLncHw.mjs +0 -396
- package/dist/openai-responses-shared-pXl6Wd8S.mjs +0 -392
- package/dist/openai-responses-stream-internal-Cw5txaGW.mjs +0 -2964
- package/dist/prompt-cache-stability-Cwcjv_fx.d.mts +0 -13
- package/dist/provider-error-CAEvRjry.mjs +0 -47
- package/dist/provider-options-D8bB3z9b.d.mts +0 -144
- package/dist/reasoning-tag-text-partitioner-CGDyLWUR.mjs +0 -12209
- package/dist/simple-options-9lhRrN73.mjs +0 -50
- package/dist/stream-first-event-timeout-DvDeSucC.d.mts +0 -29
- package/dist/tls-certificate-errors-DXSpluKI.mjs +0 -93
- package/dist/tool-result-text-CTpIRbYd.mjs +0 -225
- package/dist/transform-messages-C8mBqZxF.mjs +0 -2
- package/dist/transport-stream-shared-D81p90xq.mjs +0 -297
- package/dist/transports.d.mts +0 -573
- package/dist/transports.mjs +0 -4110
|
@@ -1,29 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as isRecord } from "./transform-messages-BhGF_fF4.mjs";
|
|
2
2
|
import { t as projectRuntimeToolInputSchema } from "./tool-schema-json-projection-BwNu3nDi.mjs";
|
|
3
|
-
//#region packages/ai/src/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return
|
|
12
|
-
}
|
|
13
|
-
function resolveProviderRequestCapabilities(input) {
|
|
14
|
-
return getAiTransportHost().resolveProviderRequestCapabilities(input);
|
|
15
|
-
}
|
|
16
|
-
function resolveProviderRequestPolicyConfig(input) {
|
|
17
|
-
return { headers: getAiTransportHost().resolveProviderRequestHeaders(input) };
|
|
18
|
-
}
|
|
19
|
-
function resolveModelRequestTimeoutMs(model, timeoutMs) {
|
|
20
|
-
return timeoutMs ?? getAiTransportHost().resolveModelRequestTimeoutMs(model);
|
|
21
|
-
}
|
|
22
|
-
function resolveOpenAIStrictToolSetting(model, options) {
|
|
23
|
-
return getAiTransportHost().resolveOpenAIStrictToolSetting(model, options);
|
|
24
|
-
}
|
|
25
|
-
function transformTransportMessages(messages, model, normalizeToolCallId, options) {
|
|
26
|
-
return getAiTransportHost().transformTransportMessages(messages, model, normalizeToolCallId, options);
|
|
3
|
+
//#region packages/ai/src/providers/openai-prompt-cache.ts
|
|
4
|
+
/** Maximum prompt cache key length accepted by OpenAI-compatible request metadata. */
|
|
5
|
+
const OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH = 64;
|
|
6
|
+
/** Truncates a prompt cache key by Unicode code point count. */
|
|
7
|
+
function clampOpenAIPromptCacheKey(key) {
|
|
8
|
+
if (key === void 0) return;
|
|
9
|
+
const chars = Array.from(key);
|
|
10
|
+
if (chars.length <= 64) return key;
|
|
11
|
+
return chars.slice(0, 64).join("");
|
|
27
12
|
}
|
|
28
13
|
//#endregion
|
|
29
14
|
//#region packages/ai/src/providers/openai-tool-projection.ts
|
|
@@ -50,12 +35,7 @@ function projectOpenAITools(tools) {
|
|
|
50
35
|
for (let toolIndex = 0; toolIndex < inputToolCount; toolIndex += 1) {
|
|
51
36
|
let tool;
|
|
52
37
|
try {
|
|
53
|
-
|
|
54
|
-
if (!candidate) {
|
|
55
|
-
diagnostics.push(unreadableToolDiagnostic(toolIndex));
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
tool = candidate;
|
|
38
|
+
tool = tools[toolIndex];
|
|
59
39
|
} catch {
|
|
60
40
|
diagnostics.push(unreadableToolDiagnostic(toolIndex));
|
|
61
41
|
continue;
|
|
@@ -212,4 +192,4 @@ function reconcileOpenAICompletionsToolChoice(choice, projection) {
|
|
|
212
192
|
};
|
|
213
193
|
}
|
|
214
194
|
//#endregion
|
|
215
|
-
export {
|
|
195
|
+
export { clampOpenAIPromptCacheKey as a, OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH as i, reconcileOpenAICompletionsToolChoice as n, reconcileOpenAIResponsesToolChoice as r, projectOpenAITools as t };
|
package/dist/providers.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { n as ApiRegistry } from "./api-registry-
|
|
2
|
-
import { n as clampOpenAIPromptCacheKey, t as OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH } from "./openai-prompt-cache-2uo_1OR1.mjs";
|
|
1
|
+
import { n as ApiRegistry } from "./api-registry-BXYnCOIR.mjs";
|
|
3
2
|
|
|
4
3
|
//#region packages/ai/src/providers/register-builtins.d.ts
|
|
5
4
|
/** Source id used for built-in API provider registrations. */
|
|
@@ -9,4 +8,4 @@ declare function registerBuiltInApiProviders(registry: ApiRegistry): void;
|
|
|
9
8
|
/** Restores the built-in provider registry state for tests. */
|
|
10
9
|
declare function resetApiProviders(registry: ApiRegistry): void;
|
|
11
10
|
//#endregion
|
|
12
|
-
export { BUILT_IN_API_PROVIDER_SOURCE_ID,
|
|
11
|
+
export { BUILT_IN_API_PROVIDER_SOURCE_ID, registerBuiltInApiProviders, resetApiProviders };
|
package/dist/providers.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { t as AssistantMessageEventStream } from "./event-stream-
|
|
2
|
-
import { n as clampOpenAIPromptCacheKey, t as OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH } from "./openai-prompt-cache-mZTCdRPo.mjs";
|
|
1
|
+
import { t as AssistantMessageEventStream } from "./event-stream-ReMmOTzX.mjs";
|
|
3
2
|
//#region packages/ai/src/providers/register-builtins.ts
|
|
4
3
|
/** Source id used for built-in API provider registrations. */
|
|
5
4
|
const BUILT_IN_API_PROVIDER_SOURCE_ID = "core:built-in";
|
|
@@ -64,35 +63,35 @@ function createLazyRegistration(api, importModule, select) {
|
|
|
64
63
|
};
|
|
65
64
|
}
|
|
66
65
|
const registerBuiltIns = [
|
|
67
|
-
createLazyRegistration("anthropic-messages", () => import("./anthropic-
|
|
66
|
+
createLazyRegistration("anthropic-messages", () => import("./anthropic-BML72tLz.mjs").then((n) => n.t), (module) => ({
|
|
68
67
|
stream: module.streamAnthropic,
|
|
69
68
|
streamSimple: module.streamSimpleAnthropic
|
|
70
69
|
})),
|
|
71
|
-
createLazyRegistration("openai-completions", () => import("./openai-completions-
|
|
70
|
+
createLazyRegistration("openai-completions", () => import("./openai-completions-9qYFVS7H.mjs").then((n) => n.n), (module) => ({
|
|
72
71
|
stream: module.streamOpenAICompletions,
|
|
73
72
|
streamSimple: module.streamSimpleOpenAICompletions
|
|
74
73
|
})),
|
|
75
|
-
createLazyRegistration("mistral-conversations", () => import("./mistral-
|
|
74
|
+
createLazyRegistration("mistral-conversations", () => import("./mistral-CePVNdws.mjs"), (module) => ({
|
|
76
75
|
stream: module.streamMistral,
|
|
77
76
|
streamSimple: module.streamSimpleMistral
|
|
78
77
|
})),
|
|
79
|
-
createLazyRegistration("openai-responses", () => import("./openai-responses-
|
|
78
|
+
createLazyRegistration("openai-responses", () => import("./openai-responses-D6l9URyV.mjs").then((n) => n.t), (module) => ({
|
|
80
79
|
stream: module.streamOpenAIResponses,
|
|
81
80
|
streamSimple: module.streamSimpleOpenAIResponses
|
|
82
81
|
})),
|
|
83
|
-
createLazyRegistration("azure-openai-responses", () => import("./azure-openai-responses-
|
|
82
|
+
createLazyRegistration("azure-openai-responses", () => import("./azure-openai-responses-kEN8II8I.mjs"), (module) => ({
|
|
84
83
|
stream: module.streamAzureOpenAIResponses,
|
|
85
84
|
streamSimple: module.streamSimpleAzureOpenAIResponses
|
|
86
85
|
})),
|
|
87
|
-
createLazyRegistration("openai-chatgpt-responses", () => import("./openai-chatgpt-responses-
|
|
86
|
+
createLazyRegistration("openai-chatgpt-responses", () => import("./openai-chatgpt-responses-BHqbcipc.mjs"), (module) => ({
|
|
88
87
|
stream: module.streamOpenAICodexResponses,
|
|
89
88
|
streamSimple: module.streamSimpleOpenAICodexResponses
|
|
90
89
|
})),
|
|
91
|
-
createLazyRegistration("google-generative-ai", () => import("./google-
|
|
90
|
+
createLazyRegistration("google-generative-ai", () => import("./google-DTM4O3e9.mjs"), (module) => ({
|
|
92
91
|
stream: module.streamGoogle,
|
|
93
92
|
streamSimple: module.streamSimpleGoogle
|
|
94
93
|
})),
|
|
95
|
-
createLazyRegistration("google-vertex", () => import("./google-vertex-
|
|
94
|
+
createLazyRegistration("google-vertex", () => import("./google-vertex-D58MZHCQ.mjs"), (module) => ({
|
|
96
95
|
stream: module.streamGoogleVertex,
|
|
97
96
|
streamSimple: module.streamSimpleGoogleVertex
|
|
98
97
|
}))
|
|
@@ -107,4 +106,4 @@ function resetApiProviders(registry) {
|
|
|
107
106
|
registerBuiltInApiProviders(registry);
|
|
108
107
|
}
|
|
109
108
|
//#endregion
|
|
110
|
-
export { BUILT_IN_API_PROVIDER_SOURCE_ID,
|
|
109
|
+
export { BUILT_IN_API_PROVIDER_SOURCE_ID, registerBuiltInApiProviders, resetApiProviders };
|
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
//#region packages/markdown-core/src/fences.ts
|
|
2
|
+
/** Scans fenced-code spans incrementally so chunking can carry an open fence forward. */
|
|
3
|
+
function scanFenceSpans(buffer, state) {
|
|
4
|
+
const spans = [];
|
|
5
|
+
const startsAtLineStart = state?.atLineStart ?? true;
|
|
6
|
+
let open = state?.open ? {
|
|
7
|
+
...state.open,
|
|
8
|
+
start: 0
|
|
9
|
+
} : void 0;
|
|
10
|
+
let offset = 0;
|
|
11
|
+
while (offset <= buffer.length) {
|
|
12
|
+
const nextNewline = buffer.indexOf("\n", offset);
|
|
13
|
+
const lineEnd = nextNewline === -1 ? buffer.length : nextNewline;
|
|
14
|
+
const line = buffer.slice(offset, lineEnd).replace(/\r$/, "");
|
|
15
|
+
const match = line.match(/^( {0,3})(`{3,}|~{3,})(.*)$/);
|
|
16
|
+
if (match && (offset > 0 || startsAtLineStart)) {
|
|
17
|
+
const indent = match[1];
|
|
18
|
+
const marker = match[2];
|
|
19
|
+
const markerChar = marker[0];
|
|
20
|
+
const markerLen = marker.length;
|
|
21
|
+
if (!open) open = {
|
|
22
|
+
start: offset,
|
|
23
|
+
markerChar,
|
|
24
|
+
markerLen,
|
|
25
|
+
openLine: line,
|
|
26
|
+
marker,
|
|
27
|
+
indent
|
|
28
|
+
};
|
|
29
|
+
else if (open.markerChar === markerChar && markerLen >= open.markerLen && /^[ \t]*$/.test(match[3])) {
|
|
30
|
+
const end = lineEnd;
|
|
31
|
+
spans.push({
|
|
32
|
+
start: open.start,
|
|
33
|
+
end,
|
|
34
|
+
openLine: open.openLine,
|
|
35
|
+
marker: open.marker,
|
|
36
|
+
indent: open.indent
|
|
37
|
+
});
|
|
38
|
+
open = void 0;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (nextNewline === -1) break;
|
|
42
|
+
offset = nextNewline + 1;
|
|
43
|
+
}
|
|
44
|
+
if (open) spans.push({
|
|
45
|
+
start: open.start,
|
|
46
|
+
end: buffer.length,
|
|
47
|
+
openLine: open.openLine,
|
|
48
|
+
marker: open.marker,
|
|
49
|
+
indent: open.indent
|
|
50
|
+
});
|
|
51
|
+
return {
|
|
52
|
+
spans,
|
|
53
|
+
state: {
|
|
54
|
+
atLineStart: buffer.length === 0 ? startsAtLineStart : buffer.endsWith("\n"),
|
|
55
|
+
...open ? { open: {
|
|
56
|
+
markerChar: open.markerChar,
|
|
57
|
+
markerLen: open.markerLen,
|
|
58
|
+
openLine: open.openLine,
|
|
59
|
+
marker: open.marker,
|
|
60
|
+
indent: open.indent
|
|
61
|
+
} } : {}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region packages/markdown-core/src/code-spans.ts
|
|
67
|
+
/** Creates the carry-forward state used when scanning inline code across chunks. */
|
|
68
|
+
function createInlineCodeState() {
|
|
69
|
+
return {
|
|
70
|
+
open: false,
|
|
71
|
+
ticks: 0
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/** Builds a lookup for fenced and inline code spans while preserving scanner state. */
|
|
75
|
+
function buildCodeSpanIndex(text, inlineState, fenceState) {
|
|
76
|
+
const { spans: fenceSpans, state: nextFenceState } = scanFenceSpans(text, fenceState);
|
|
77
|
+
const { spans: inlineSpans, state: nextInlineState } = parseInlineCodeSpans(text, fenceSpans, inlineState ? {
|
|
78
|
+
open: inlineState.open,
|
|
79
|
+
ticks: inlineState.ticks
|
|
80
|
+
} : createInlineCodeState());
|
|
81
|
+
return {
|
|
82
|
+
inlineState: nextInlineState,
|
|
83
|
+
fenceState: nextFenceState,
|
|
84
|
+
isInside: (index) => isInsideFenceSpan(index, fenceSpans) || isInsideInlineSpan(index, inlineSpans)
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function parseInlineCodeSpans(text, fenceSpans, initialState) {
|
|
88
|
+
const spans = [];
|
|
89
|
+
let open = initialState.open;
|
|
90
|
+
let ticks = initialState.ticks;
|
|
91
|
+
let openStart = open ? 0 : -1;
|
|
92
|
+
let i = 0;
|
|
93
|
+
while (i < text.length) {
|
|
94
|
+
const fence = findFenceSpanAtInclusive(fenceSpans, i);
|
|
95
|
+
if (fence) {
|
|
96
|
+
i = fence.end;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (text[i] !== "`") {
|
|
100
|
+
i += 1;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const runStart = i;
|
|
104
|
+
let runLength = 0;
|
|
105
|
+
while (i < text.length && text[i] === "`") {
|
|
106
|
+
runLength += 1;
|
|
107
|
+
i += 1;
|
|
108
|
+
}
|
|
109
|
+
if (!open) {
|
|
110
|
+
open = true;
|
|
111
|
+
ticks = runLength;
|
|
112
|
+
openStart = runStart;
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (runLength === ticks) {
|
|
116
|
+
spans.push([openStart, i]);
|
|
117
|
+
open = false;
|
|
118
|
+
ticks = 0;
|
|
119
|
+
openStart = -1;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (open) spans.push([openStart, text.length]);
|
|
123
|
+
return {
|
|
124
|
+
spans,
|
|
125
|
+
state: {
|
|
126
|
+
open,
|
|
127
|
+
ticks
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function findFenceSpanAtInclusive(spans, index) {
|
|
132
|
+
return spans.find((span) => index >= span.start && index < span.end);
|
|
133
|
+
}
|
|
134
|
+
function isInsideFenceSpan(index, spans) {
|
|
135
|
+
return spans.some((span) => index >= span.start && index < span.end);
|
|
136
|
+
}
|
|
137
|
+
function isInsideInlineSpan(index, spans) {
|
|
138
|
+
return spans.some(([start, end]) => index >= start && index < end);
|
|
139
|
+
}
|
|
140
|
+
//#endregion
|
|
141
|
+
//#region packages/ai/src/utils/reasoning-tag-text-partitioner.ts
|
|
142
|
+
const REASONING_TAG_RE = /<\s*(\/?)\s*(?:(?:antml:|mm:)?(?:think(?:ing)?|thought|reasoning)|antthinking)\b[^<>]*>/gi;
|
|
143
|
+
const REASONING_TAG_NAMES = [
|
|
144
|
+
"think",
|
|
145
|
+
"thinking",
|
|
146
|
+
"thought",
|
|
147
|
+
"reasoning",
|
|
148
|
+
"antthinking",
|
|
149
|
+
"antml:think",
|
|
150
|
+
"antml:thinking",
|
|
151
|
+
"antml:thought",
|
|
152
|
+
"antml:reasoning",
|
|
153
|
+
"mm:think",
|
|
154
|
+
"mm:thinking",
|
|
155
|
+
"mm:thought",
|
|
156
|
+
"mm:reasoning"
|
|
157
|
+
];
|
|
158
|
+
function createReasoningTagTextPartitioner() {
|
|
159
|
+
let buffer = "";
|
|
160
|
+
let reasoningDepth = 0;
|
|
161
|
+
let strictMode = false;
|
|
162
|
+
let emittedVisibleText = false;
|
|
163
|
+
let inlineCodeState = createInlineCodeState();
|
|
164
|
+
let fenceState;
|
|
165
|
+
let hiddenInlineCodeState = createInlineCodeState();
|
|
166
|
+
let hiddenFenceState;
|
|
167
|
+
let recoverableOpenTagText;
|
|
168
|
+
const consume = (final, recoverFullUnclosed) => {
|
|
169
|
+
const output = [];
|
|
170
|
+
const emit = (kind, text) => {
|
|
171
|
+
if (!text) return;
|
|
172
|
+
if (kind === "text" && text.trim().length > 0) emittedVisibleText = true;
|
|
173
|
+
if (kind === "text") {
|
|
174
|
+
const nextCode = buildCodeSpanIndex(text, inlineCodeState, fenceState);
|
|
175
|
+
inlineCodeState = nextCode.inlineState;
|
|
176
|
+
fenceState = nextCode.fenceState;
|
|
177
|
+
} else {
|
|
178
|
+
const nextCode = buildCodeSpanIndex(text, hiddenInlineCodeState, hiddenFenceState);
|
|
179
|
+
hiddenInlineCodeState = nextCode.inlineState;
|
|
180
|
+
hiddenFenceState = nextCode.fenceState;
|
|
181
|
+
}
|
|
182
|
+
const previous = output[output.length - 1];
|
|
183
|
+
if (previous?.kind === kind) {
|
|
184
|
+
previous.text += text;
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
output.push({
|
|
188
|
+
kind,
|
|
189
|
+
text
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
while (buffer) {
|
|
193
|
+
const activeInlineCodeState = reasoningDepth === 0 ? inlineCodeState : hiddenInlineCodeState;
|
|
194
|
+
const activeFenceState = reasoningDepth === 0 ? fenceState : hiddenFenceState;
|
|
195
|
+
const codeSpans = buildCodeSpanIndex(buffer, activeInlineCodeState, activeFenceState);
|
|
196
|
+
const hasUnclosedCode = reasoningDepth === 0 && Boolean(codeSpans.inlineState.open || codeSpans.fenceState.open);
|
|
197
|
+
const hasRawReasoning = hasRawReasoningTag(buffer);
|
|
198
|
+
const tag = findNextReasoningTag(buffer, (index) => final && hasUnclosedCode && hasRawReasoning ? false : codeSpans.isInside(index));
|
|
199
|
+
if (!tag) {
|
|
200
|
+
if (final) {
|
|
201
|
+
const recoverAsText = reasoningDepth > 0 && recoverFullUnclosed && !hasRawReasoningCloseTag(buffer);
|
|
202
|
+
const recoveredText = recoverAsText && recoverableOpenTagText ? recoverableOpenTagText + buffer : buffer;
|
|
203
|
+
emit(reasoningDepth > 0 && !recoverAsText ? "thinking" : "text", recoveredText);
|
|
204
|
+
buffer = "";
|
|
205
|
+
reasoningDepth = 0;
|
|
206
|
+
recoverableOpenTagText = void 0;
|
|
207
|
+
return output;
|
|
208
|
+
}
|
|
209
|
+
if (reasoningDepth > 0 && recoverFullUnclosed && (!emittedVisibleText || recoverableOpenTagText)) return output;
|
|
210
|
+
if (hasUnclosedCode && hasRawReasoning) {
|
|
211
|
+
const openCodeIndex = inlineCodeState.open || fenceState?.open ? 0 : findOpenCodeContextStart(buffer);
|
|
212
|
+
if (openCodeIndex !== -1) {
|
|
213
|
+
emit("text", buffer.slice(0, openCodeIndex));
|
|
214
|
+
buffer = buffer.slice(openCodeIndex);
|
|
215
|
+
return output;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
const trailingFenceStart = findTrailingFenceFragmentStart(buffer, activeInlineCodeState, activeFenceState);
|
|
219
|
+
if (trailingFenceStart !== -1) {
|
|
220
|
+
emit(reasoningDepth > 0 ? "thinking" : "text", buffer.slice(0, trailingFenceStart));
|
|
221
|
+
buffer = buffer.slice(trailingFenceStart);
|
|
222
|
+
return output;
|
|
223
|
+
}
|
|
224
|
+
const keepFrom = reasoningTagPrefixSuffixIndex(buffer, (index) => codeSpans.isInside(index));
|
|
225
|
+
if (keepFrom === -1) {
|
|
226
|
+
emit(reasoningDepth > 0 ? "thinking" : "text", buffer);
|
|
227
|
+
buffer = "";
|
|
228
|
+
return output;
|
|
229
|
+
}
|
|
230
|
+
if (reasoningDepth === 0 && keepFrom > 0 && buffer.slice(0, keepFrom).trim().length > 0 && isReasoningCloseTagPrefix(buffer.slice(keepFrom))) return output;
|
|
231
|
+
if (keepFrom > 0) {
|
|
232
|
+
emit(reasoningDepth > 0 ? "thinking" : "text", buffer.slice(0, keepFrom));
|
|
233
|
+
buffer = buffer.slice(keepFrom);
|
|
234
|
+
}
|
|
235
|
+
return output;
|
|
236
|
+
}
|
|
237
|
+
const beforeTag = buffer.slice(0, tag.index);
|
|
238
|
+
const afterTag = buffer.slice(tag.index + tag.text.length);
|
|
239
|
+
if (tag.isClose && reasoningDepth === 0) {
|
|
240
|
+
if (recoverFullUnclosed && beforeTag.trim().length > 0 && afterTag.trim().length > 0) {
|
|
241
|
+
emit("text", beforeTag + tag.text);
|
|
242
|
+
buffer = afterTag;
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
if (beforeTag.trim().length > 0 && afterTag.trim().length === 0 && !final) return output;
|
|
246
|
+
if (beforeTag.trim().length === 0 || afterTag.trim().length === 0) emit("text", beforeTag);
|
|
247
|
+
buffer = afterTag;
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
emit(reasoningDepth > 0 ? "thinking" : "text", buffer.slice(0, tag.index));
|
|
251
|
+
buffer = afterTag;
|
|
252
|
+
if (tag.isClose) {
|
|
253
|
+
reasoningDepth = Math.max(0, reasoningDepth - 1);
|
|
254
|
+
if (reasoningDepth === 0) {
|
|
255
|
+
recoverableOpenTagText = void 0;
|
|
256
|
+
hiddenInlineCodeState = createInlineCodeState();
|
|
257
|
+
hiddenFenceState = void 0;
|
|
258
|
+
}
|
|
259
|
+
} else {
|
|
260
|
+
if (reasoningDepth === 0) {
|
|
261
|
+
recoverableOpenTagText = recoverFullUnclosed && emittedVisibleText ? tag.text : void 0;
|
|
262
|
+
hiddenInlineCodeState = createInlineCodeState();
|
|
263
|
+
hiddenFenceState = void 0;
|
|
264
|
+
}
|
|
265
|
+
reasoningDepth += 1;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return output;
|
|
269
|
+
};
|
|
270
|
+
return {
|
|
271
|
+
markStrict() {
|
|
272
|
+
strictMode = true;
|
|
273
|
+
},
|
|
274
|
+
push(chunk) {
|
|
275
|
+
strictMode = true;
|
|
276
|
+
buffer += chunk;
|
|
277
|
+
return consume(false, false);
|
|
278
|
+
},
|
|
279
|
+
pushVisible(chunk) {
|
|
280
|
+
buffer += chunk;
|
|
281
|
+
return consume(false, true);
|
|
282
|
+
},
|
|
283
|
+
flush() {
|
|
284
|
+
return consume(true, !strictMode);
|
|
285
|
+
},
|
|
286
|
+
hasPending() {
|
|
287
|
+
return buffer.length > 0 || reasoningDepth > 0;
|
|
288
|
+
},
|
|
289
|
+
isInsideReasoning() {
|
|
290
|
+
return reasoningDepth > 0;
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
function hasRawReasoningTag(text) {
|
|
295
|
+
REASONING_TAG_RE.lastIndex = 0;
|
|
296
|
+
return REASONING_TAG_RE.test(text);
|
|
297
|
+
}
|
|
298
|
+
function hasRawReasoningCloseTag(text) {
|
|
299
|
+
REASONING_TAG_RE.lastIndex = 0;
|
|
300
|
+
for (;;) {
|
|
301
|
+
const match = REASONING_TAG_RE.exec(text);
|
|
302
|
+
if (!match) return false;
|
|
303
|
+
if (match[1] === "/") return true;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
function findNextReasoningTag(text, isIndexInsideCode) {
|
|
307
|
+
REASONING_TAG_RE.lastIndex = 0;
|
|
308
|
+
for (;;) {
|
|
309
|
+
const match = REASONING_TAG_RE.exec(text);
|
|
310
|
+
if (!match) return null;
|
|
311
|
+
if (!isIndexInsideCode(match.index)) return {
|
|
312
|
+
index: match.index,
|
|
313
|
+
text: match[0],
|
|
314
|
+
isClose: match[1] === "/"
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
function reasoningTagPrefixSuffixIndex(text, isIndexInsideCode) {
|
|
319
|
+
for (let index = text.lastIndexOf("<"); index >= 0;) {
|
|
320
|
+
if (!isIndexInsideCode(index) && isReasoningTagPrefix(text.slice(index))) return index;
|
|
321
|
+
if (index === 0) break;
|
|
322
|
+
index = text.lastIndexOf("<", index - 1);
|
|
323
|
+
}
|
|
324
|
+
return -1;
|
|
325
|
+
}
|
|
326
|
+
function isReasoningTagPrefix(text) {
|
|
327
|
+
const name = normalizeReasoningTagPrefixName(text);
|
|
328
|
+
return REASONING_TAG_NAMES.some((tagName) => {
|
|
329
|
+
if (tagName.startsWith(name)) return true;
|
|
330
|
+
if (!name.startsWith(tagName)) return false;
|
|
331
|
+
const rest = name.slice(tagName.length);
|
|
332
|
+
return rest.length === 0 || /^[\s/>]/.test(rest);
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
function isReasoningCloseTagPrefix(text) {
|
|
336
|
+
return text.replace(/^<\s*/, "<").replace(/^<\s*\//, "</").replace(/^<\/\s*/, "</").toLowerCase().startsWith("</") && isReasoningTagPrefix(text);
|
|
337
|
+
}
|
|
338
|
+
function normalizeReasoningTagPrefixName(text) {
|
|
339
|
+
const normalized = text.replace(/^<\s*/, "<").replace(/^<\s*\//, "</").replace(/^<\/\s*/, "</").toLowerCase();
|
|
340
|
+
return (normalized.startsWith("</") ? normalized.slice(2) : normalized.slice(1)).trimStart();
|
|
341
|
+
}
|
|
342
|
+
function findOpenCodeContextStart(text) {
|
|
343
|
+
const fence = findOpenFenceStart(text);
|
|
344
|
+
const inline = findOpenInlineCodeStart(text);
|
|
345
|
+
if (fence === -1) return inline;
|
|
346
|
+
if (inline === -1) return fence;
|
|
347
|
+
return Math.min(fence, inline);
|
|
348
|
+
}
|
|
349
|
+
function findOpenInlineCodeStart(text) {
|
|
350
|
+
let openStart = -1;
|
|
351
|
+
let openTicks = 0;
|
|
352
|
+
let index = 0;
|
|
353
|
+
while (index < text.length) {
|
|
354
|
+
if (text[index] !== "`") {
|
|
355
|
+
index += 1;
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
358
|
+
const runStart = index;
|
|
359
|
+
let runLength = 0;
|
|
360
|
+
while (index < text.length && text[index] === "`") {
|
|
361
|
+
runLength += 1;
|
|
362
|
+
index += 1;
|
|
363
|
+
}
|
|
364
|
+
if (openStart === -1) {
|
|
365
|
+
openStart = runStart;
|
|
366
|
+
openTicks = runLength;
|
|
367
|
+
} else if (runLength === openTicks) {
|
|
368
|
+
openStart = -1;
|
|
369
|
+
openTicks = 0;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
return openStart;
|
|
373
|
+
}
|
|
374
|
+
function findOpenFenceStart(text) {
|
|
375
|
+
const fenceRe = /(^|\n)(```|~~~)[^\n]*(?:\n|$)/g;
|
|
376
|
+
let open = null;
|
|
377
|
+
for (const match of text.matchAll(fenceRe)) {
|
|
378
|
+
const index = (match.index ?? 0) + match[1].length;
|
|
379
|
+
const marker = match[2] ?? "";
|
|
380
|
+
if (open !== null && open.marker === marker) open = null;
|
|
381
|
+
else if (!open) open = {
|
|
382
|
+
marker,
|
|
383
|
+
index
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
return open?.index ?? -1;
|
|
387
|
+
}
|
|
388
|
+
function findTrailingFenceFragmentStart(text, inlineState, fenceState) {
|
|
389
|
+
if (inlineState.open || fenceState?.open) return -1;
|
|
390
|
+
const lineStart = Math.max(text.lastIndexOf("\n") + 1, 0);
|
|
391
|
+
return text.slice(lineStart).match(/^( {0,3})(`{1,2}|~{1,2})$/) ? lineStart : -1;
|
|
392
|
+
}
|
|
393
|
+
//#endregion
|
|
394
|
+
export { createReasoningTagTextPartitioner as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./validation-
|
|
1
|
+
import "./validation-FrchoOlv.mjs";
|
|
2
2
|
//#region packages/llm-core/src/model-contracts/anthropic.ts
|
|
3
3
|
function normalizeClaudeModelId(modelId) {
|
|
4
4
|
const normalized = modelId?.trim().toLowerCase() ?? "";
|
|
@@ -31,7 +31,6 @@ const CLAUDE_SONNET_5_THINKING_PROFILE = {
|
|
|
31
31
|
],
|
|
32
32
|
defaultLevel: "high"
|
|
33
33
|
};
|
|
34
|
-
const CLAUDE_OPUS_5_THINKING_PROFILE = CLAUDE_SONNET_5_THINKING_PROFILE;
|
|
35
34
|
/** Resolve the canonical normalized Claude model id for one runtime model ref. */
|
|
36
35
|
function resolveClaudeModelIdentity(ref) {
|
|
37
36
|
const normalized = normalizeClaudeModelId((typeof ref.params?.canonicalModelId === "string" ? ref.params.canonicalModelId : void 0) ?? ref.id);
|
|
@@ -64,38 +63,20 @@ function resolveClaudeSonnet5ModelIdentity(ref) {
|
|
|
64
63
|
if (!match) return;
|
|
65
64
|
return normalized.slice((match.index ?? 0) + (match[0].startsWith("-") ? 1 : 0));
|
|
66
65
|
}
|
|
67
|
-
/** Resolve Claude Opus 5 through aliases, direct ids, cloud ids, or deployment metadata. */
|
|
68
|
-
function resolveClaudeOpus5ModelIdentity(ref) {
|
|
69
|
-
const normalized = resolveClaudeModelIdentity(ref);
|
|
70
|
-
if (normalized === "opus" || normalized === "opus-5") return "claude-opus-5";
|
|
71
|
-
const match = /(?:^|-)claude-opus-5(?=$|[^a-z0-9])/.exec(normalized);
|
|
72
|
-
if (!match) return;
|
|
73
|
-
return normalized.slice((match.index ?? 0) + (match[0].startsWith("-") ? 1 : 0));
|
|
74
|
-
}
|
|
75
66
|
/** Return whether a Claude model supports adaptive thinking. */
|
|
76
67
|
function supportsClaudeAdaptiveThinking(ref) {
|
|
77
68
|
const modelId = resolveClaudeModelIdentity(ref);
|
|
78
|
-
return
|
|
79
|
-
}
|
|
80
|
-
/** Return whether a Claude model has a native 1M-token context window. */
|
|
81
|
-
function supportsClaude1MContext(ref) {
|
|
82
|
-
const modelId = resolveClaudeModelIdentity(ref);
|
|
83
|
-
return resolveClaudeOpus5ModelIdentity(ref) !== void 0 || /(?:^|-)claude-(?:fable-5|mythos-(?:5|preview)|opus-4-(?:6|7|8)|sonnet-(?:5|4-6))(?=$|[^a-z0-9])/.test(modelId);
|
|
84
|
-
}
|
|
85
|
-
/** Return whether a Claude model supports Anthropic's native fast mode. */
|
|
86
|
-
function supportsClaudeFastMode(ref) {
|
|
87
|
-
const modelId = resolveClaudeModelIdentity(ref);
|
|
88
|
-
return resolveClaudeOpus5ModelIdentity(ref) !== void 0 || /(?:^|-)claude-opus-4-8(?=$|[^a-z0-9])/.test(modelId);
|
|
69
|
+
return /(?:^|-)claude-(?:fable-5|mythos-(?:5|preview)|opus-4-(?:6|7|8)|sonnet-(?:5|4-6))(?=$|[^a-z0-9])/.test(modelId);
|
|
89
70
|
}
|
|
90
71
|
/** Return whether a Claude model supports native max effort. */
|
|
91
72
|
function supportsClaudeNativeMaxEffort(ref) {
|
|
92
73
|
const modelId = resolveClaudeModelIdentity(ref);
|
|
93
|
-
return
|
|
74
|
+
return /(?:^|-)claude-(?:fable-5|mythos-5|opus-4-(?:6|7|8)|sonnet-(?:5|4-6))(?=$|[^a-z0-9])/.test(modelId);
|
|
94
75
|
}
|
|
95
76
|
/** Return whether a Claude model supports native xhigh effort. */
|
|
96
77
|
function supportsClaudeNativeXhighEffort(ref) {
|
|
97
78
|
const modelId = resolveClaudeModelIdentity(ref);
|
|
98
|
-
return
|
|
79
|
+
return /(?:^|-)claude-(?:fable-5|mythos-5|opus-4-(?:7|8)|sonnet-5)(?=$|[^a-z0-9])/.test(modelId);
|
|
99
80
|
}
|
|
100
81
|
/** Return whether a Claude model rejects caller-selected sampling parameters. */
|
|
101
82
|
function requiresClaudeDefaultSampling(ref) {
|
|
@@ -115,4 +96,4 @@ function resolveClaudeNativeThinkingLevelMap(ref) {
|
|
|
115
96
|
};
|
|
116
97
|
}
|
|
117
98
|
//#endregion
|
|
118
|
-
export {
|
|
99
|
+
export { resolveClaudeFable5ModelIdentity as a, resolveClaudeNativeThinkingLevelMap as c, supportsClaudeNativeMaxEffort as d, supportsClaudeNativeXhighEffort as f, requiresClaudeMandatoryAdaptiveThinking as i, resolveClaudeSonnet5ModelIdentity as l, CLAUDE_SONNET_5_THINKING_PROFILE as n, resolveClaudeModelIdentity as o, requiresClaudeDefaultSampling as r, resolveClaudeMythos5ModelIdentity as s, CLAUDE_FABLE_5_THINKING_PROFILE as t, supportsClaudeAdaptiveThinking as u };
|
package/dist/{stream-first-event-timeout-BBys9hSb.mjs → stream-first-event-timeout-RjWszj8c.mjs}
RENAMED
|
@@ -1,4 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
//#region packages/normalization-core/src/number-coercion.ts
|
|
2
|
+
/** Returns a number only when the input is already finite. */
|
|
3
|
+
function asFiniteNumber(value) {
|
|
4
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
5
|
+
}
|
|
6
|
+
/** Conservative upper bound for Node timer delays. */
|
|
7
|
+
const MAX_TIMER_TIMEOUT_MS = 2147e6;
|
|
8
|
+
/** Clamps finite millisecond values into the Node-safe timer range. */
|
|
9
|
+
function clampTimerTimeoutMs(valueMs, minMs = 1) {
|
|
10
|
+
const value = asFiniteNumber(valueMs);
|
|
11
|
+
if (value === void 0) return;
|
|
12
|
+
return Math.min(Math.max(Math.floor(value), Math.max(1, Math.floor(minMs))), MAX_TIMER_TIMEOUT_MS);
|
|
13
|
+
}
|
|
14
|
+
/** Resolves arbitrary timeout input with fallback and minimum timer bounds. */
|
|
15
|
+
function resolveTimerTimeoutMs(valueMs, fallbackMs, minMs = 1) {
|
|
16
|
+
const value = asFiniteNumber(valueMs) ?? asFiniteNumber(fallbackMs);
|
|
17
|
+
const min = Math.max(0, Math.floor(minMs));
|
|
18
|
+
if (value === void 0) return min;
|
|
19
|
+
return Math.min(Math.max(Math.floor(value), min), MAX_TIMER_TIMEOUT_MS);
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
2
22
|
//#region packages/ai/src/utils/stream-first-event-timeout.ts
|
|
3
23
|
function getFirstStreamEventTimeoutMs(options) {
|
|
4
24
|
return options?.firstEventTimeoutMs;
|
|
@@ -83,4 +103,4 @@ function withFirstStreamEventTimeout(stream, context) {
|
|
|
83
103
|
} };
|
|
84
104
|
}
|
|
85
105
|
//#endregion
|
|
86
|
-
export { withFirstStreamEventTimeout as a, getFirstStreamEventTimeoutMs as i, createFirstStreamEventTimeoutError as n, getFirstStreamEventTimeoutHandler as r, createFirstStreamEventAbortController as t };
|
|
106
|
+
export { withFirstStreamEventTimeout as a, getFirstStreamEventTimeoutMs as i, createFirstStreamEventTimeoutError as n, clampTimerTimeoutMs as o, getFirstStreamEventTimeoutHandler as r, resolveTimerTimeoutMs as s, createFirstStreamEventAbortController as t };
|