@deepstrike/sdk 0.2.52 → 0.2.60
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 +28 -28
- package/dist/agent-ir.d.ts +103 -0
- package/dist/agent-ir.js +134 -0
- package/dist/agent.d.ts +67 -0
- package/dist/agent.js +36 -0
- package/dist/collaboration/harness.js +1 -1
- package/dist/collaboration/modes/creator-verifier.d.ts +2 -7
- package/dist/collaboration/modes/creator-verifier.js +4 -6
- package/dist/collaboration/pool.d.ts +8 -20
- package/dist/collaboration/pool.js +27 -97
- package/dist/compat/anthropic/mcp.d.ts +15 -0
- package/dist/compat/anthropic/mcp.js +10 -0
- package/dist/compat/openai/agent.d.ts +34 -0
- package/dist/compat/openai/agent.js +24 -0
- package/dist/governance.d.ts +1 -17
- package/dist/governance.js +1 -34
- package/dist/guardrail.d.ts +6 -0
- package/dist/guardrail.js +1 -0
- package/dist/handoff-target.d.ts +12 -0
- package/dist/handoff-target.js +1 -0
- package/dist/harness/manifest.js +0 -4
- package/dist/index.d.ts +19 -7
- package/dist/index.js +8 -5
- package/dist/kernel.d.ts +2 -20
- package/dist/knowledge/public.d.ts +29 -0
- package/dist/knowledge/public.js +1 -0
- package/dist/mcp-server.d.ts +28 -0
- package/dist/mcp-server.js +1 -0
- package/dist/memory/agent.d.ts +2 -2
- package/dist/memory/agent.js +2 -2
- package/dist/memory/durable.d.ts +16 -0
- package/dist/memory/durable.js +46 -0
- package/dist/memory/in-memory-store.d.ts +9 -7
- package/dist/memory/in-memory-store.js +8 -2
- package/dist/memory/protocols.d.ts +22 -4
- package/dist/memory/public.d.ts +4 -3
- package/dist/memory/public.js +3 -2
- package/dist/providers/anthropic-adapter.d.ts +47 -0
- package/dist/providers/anthropic-adapter.js +444 -0
- package/dist/providers/anthropic-compatible.d.ts +2 -3
- package/dist/providers/anthropic-compatible.js +8 -5
- package/dist/providers/anthropic.d.ts +19 -23
- package/dist/providers/anthropic.js +169 -395
- package/dist/providers/base.js +43 -3
- package/dist/providers/capability-router.d.ts +29 -0
- package/dist/providers/capability-router.js +43 -0
- package/dist/providers/catalog.d.ts +16 -4
- package/dist/providers/catalog.js +112 -21
- package/dist/providers/content-normalization.d.ts +57 -0
- package/dist/providers/content-normalization.js +238 -0
- package/dist/providers/content-policy.d.ts +16 -0
- package/dist/providers/content-policy.js +39 -0
- package/dist/providers/credentials.d.ts +83 -0
- package/dist/providers/credentials.js +190 -0
- package/dist/providers/endpoints.d.ts +137 -0
- package/dist/providers/endpoints.js +128 -0
- package/dist/providers/factories.js +9 -3
- package/dist/providers/gemini-adapter.d.ts +33 -0
- package/dist/providers/gemini-adapter.js +272 -0
- package/dist/providers/gemini.d.ts +16 -3
- package/dist/providers/gemini.js +97 -195
- package/dist/providers/model-catalog.d.ts +37 -0
- package/dist/providers/model-catalog.js +62 -0
- package/dist/providers/model-registry.d.ts +98 -0
- package/dist/providers/model-registry.js +315 -0
- package/dist/providers/ollama-adapter.d.ts +65 -0
- package/dist/providers/ollama-adapter.js +188 -0
- package/dist/providers/ollama.d.ts +9 -4
- package/dist/providers/ollama.js +96 -109
- package/dist/providers/openai-chat-dialects.d.ts +154 -0
- package/dist/providers/openai-chat-dialects.js +179 -0
- package/dist/providers/openai-chat.d.ts +46 -18
- package/dist/providers/openai-chat.js +418 -51
- package/dist/providers/openai-responses-adapter.d.ts +42 -0
- package/dist/providers/openai-responses-adapter.js +341 -0
- package/dist/providers/openai-responses.d.ts +14 -33
- package/dist/providers/openai-responses.js +131 -264
- package/dist/providers/openai.d.ts +29 -76
- package/dist/providers/openai.js +195 -292
- package/dist/providers/protocol-adapter.d.ts +34 -0
- package/dist/providers/protocol-adapter.js +9 -0
- package/dist/providers/protocol-capabilities.d.ts +34 -0
- package/dist/providers/protocol-capabilities.js +44 -0
- package/dist/providers/provider-error.d.ts +31 -0
- package/dist/providers/provider-error.js +149 -0
- package/dist/providers/public.d.ts +26 -3
- package/dist/providers/public.js +13 -1
- package/dist/providers/registry.d.ts +7 -6
- package/dist/providers/registry.js +47 -20
- package/dist/providers/request-plan.d.ts +86 -0
- package/dist/providers/request-plan.js +175 -0
- package/dist/providers/usage-normalizer.d.ts +48 -0
- package/dist/providers/usage-normalizer.js +96 -0
- package/dist/providers/vendor-profiles.d.ts +2 -15
- package/dist/providers/vendor-profiles.js +14 -60
- package/dist/runtime/canonical-kernel-step.d.ts +1 -2
- package/dist/runtime/canonical-kernel-step.js +47 -12
- package/dist/runtime/context-policy.d.ts +10 -12
- package/dist/runtime/context-policy.js +6 -8
- package/dist/runtime/durable-content.d.ts +50 -0
- package/dist/runtime/durable-content.js +159 -0
- package/dist/runtime/execution-plane.d.ts +2 -2
- package/dist/runtime/execution-plane.js +2 -2
- package/dist/runtime/kernel-event-log.js +0 -1
- package/dist/runtime/kernel-step.d.ts +0 -1
- package/dist/runtime/kernel-step.js +4 -2
- package/dist/runtime/mcp-proxy-plane.d.ts +25 -1
- package/dist/runtime/mcp-proxy-plane.js +44 -6
- package/dist/runtime/output-schema.d.ts +1 -2
- package/dist/runtime/provider-replay.d.ts +1 -1
- package/dist/runtime/provider-replay.js +12 -27
- package/dist/runtime/reactive-session.d.ts +1 -1
- package/dist/runtime/reactive-session.js +2 -3
- package/dist/runtime/run-group.d.ts +1 -1
- package/dist/runtime/runner.d.ts +26 -40
- package/dist/runtime/runner.js +145 -63
- package/dist/runtime/session-log.d.ts +8 -1
- package/dist/runtime/session-log.js +42 -2
- package/dist/runtime/session-repair.d.ts +1 -1
- package/dist/runtime/session-repair.js +1 -1
- package/dist/runtime/sub-agent-orchestrator.d.ts +1 -1
- package/dist/runtime/sub-agent-orchestrator.js +8 -11
- package/dist/runtime/workflow-control-flow.d.ts +0 -4
- package/dist/runtime/workflow-control-flow.js +0 -16
- package/dist/session.d.ts +11 -0
- package/dist/session.js +1 -0
- package/dist/skill.d.ts +17 -0
- package/dist/skill.js +16 -0
- package/dist/skills/loader.d.ts +3 -0
- package/dist/tools/errors.d.ts +1 -3
- package/dist/tools/errors.js +1 -3
- package/dist/tools/index.d.ts +3 -0
- package/dist/types/agent.d.ts +21 -9
- package/dist/types/agent.js +30 -4
- package/dist/types.d.ts +128 -13
- package/package.json +3 -3
- package/dist/providers/deepseek.d.ts +0 -46
- package/dist/providers/deepseek.js +0 -97
- package/dist/providers/glm.d.ts +0 -25
- package/dist/providers/glm.js +0 -48
- package/dist/providers/kimi.d.ts +0 -23
- package/dist/providers/kimi.js +0 -30
- package/dist/providers/minimax.d.ts +0 -49
- package/dist/providers/minimax.js +0 -98
- package/dist/providers/profiles.d.ts +0 -1992
- package/dist/providers/profiles.js +0 -796
- package/dist/providers/qwen.d.ts +0 -38
- package/dist/providers/qwen.js +0 -97
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* spc_011-C-07: normalizes each vendor's raw postflight usage object into the shared
|
|
3
|
+
* `ProviderUsage` shape (`../types.js`). One function per wire family, not one
|
|
4
|
+
* per provider — DeepSeek/Kimi/GLM/Qwen/MiniMax's OpenAI-wire variants all route through
|
|
5
|
+
* `normalizeOpenAIUsage` via `OpenAIChatProvider` inheritance, and their Anthropic-wire variants
|
|
6
|
+
* route through `normalizeAnthropicUsage` via `AnthropicCompatibleProvider` inheritance — the
|
|
7
|
+
* "8 providers" the spec counts are 8 *providers*, not 8 independent parsing implementations.
|
|
8
|
+
*
|
|
9
|
+
* Reuses `openAICachedPromptTokens` (`./base.js`) for the OpenAI-family cache figure rather than
|
|
10
|
+
* re-deriving it — that function already covers the OpenAI/Qwen/MiniMax/GLM/Kimi standard shape
|
|
11
|
+
* plus DeepSeek's `prompt_cache_hit_tokens` variant.
|
|
12
|
+
*
|
|
13
|
+
* `TokenUsage`/`UsageEvent` are otherwise untouched by this module. Missing or malformed usage
|
|
14
|
+
* returns `undefined`; absence is not a zero-token measurement.
|
|
15
|
+
*/
|
|
16
|
+
import type { ProviderUsage } from "../types.js";
|
|
17
|
+
/**
|
|
18
|
+
* Covers both OpenAI wire shapes actually in use: Chat Completions (`prompt_tokens`/
|
|
19
|
+
* `completion_tokens`/`completion_tokens_details.reasoning_tokens`, used by `openai.ts` and every
|
|
20
|
+
* `OpenAIChatProvider` subclass) and the Responses API (`input_tokens`/`output_tokens`/
|
|
21
|
+
* `output_tokens_details.reasoning_tokens`, used by `openai-responses.ts`) — the two field-name
|
|
22
|
+
* conventions are read via fallback, and only one will ever be present on a given raw object.
|
|
23
|
+
*/
|
|
24
|
+
export declare function normalizeOpenAIUsage(usage: unknown): ProviderUsage | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Anthropic's raw `input_tokens` is UNCACHED input only (unlike OpenAI's `prompt_tokens`, which
|
|
27
|
+
* is already cache-inclusive) — `anthropic.ts`'s own `stream()` sums `input_tokens +
|
|
28
|
+
* cache_read_input_tokens + cache_creation_input_tokens` into the full prompt size for the same
|
|
29
|
+
* reason context-pressure accounting needs it (see that file's comment on why excluding cached
|
|
30
|
+
* tokens would suppress compaction until a 413). This function replicates that same sum so
|
|
31
|
+
* `ProviderUsage.inputTokens` means the same "full prompt size" thing across vendors — reading
|
|
32
|
+
* raw `input_tokens` alone here would silently undercount every cache-heavy Anthropic turn.
|
|
33
|
+
* No `reasoning_tokens`-equivalent field exists in this SDK's `Usage` type, so that field stays
|
|
34
|
+
* unset rather than guessed.
|
|
35
|
+
*/
|
|
36
|
+
export declare function normalizeAnthropicUsage(usage: unknown): ProviderUsage | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* `@google/generative-ai`'s `UsageMetadata` has no reasoning/thoughts token field and no separate
|
|
39
|
+
* cache-write count (only `cachedContentTokenCount`, a read figure) — `reasoningTokens` and
|
|
40
|
+
* `cacheCreationInputTokens` stay unset rather than invented.
|
|
41
|
+
*/
|
|
42
|
+
export declare function normalizeGeminiUsage(usage: unknown): ProviderUsage | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Ollama's final stream chunk (`done: true`) carries `prompt_eval_count`/`eval_count` — no cache
|
|
45
|
+
* or reasoning concept exists in its API at all, so both stay unset. Before this card `ollama.ts`
|
|
46
|
+
* read neither field; this is the first usage extraction it has ever had.
|
|
47
|
+
*/
|
|
48
|
+
export declare function normalizeOllamaUsage(chunk: unknown): ProviderUsage | undefined;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { openAICachedPromptTokens } from "./base.js";
|
|
2
|
+
function readNumber(obj, key) {
|
|
3
|
+
const value = obj?.[key];
|
|
4
|
+
return typeof value === "number" ? value : undefined;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Covers both OpenAI wire shapes actually in use: Chat Completions (`prompt_tokens`/
|
|
8
|
+
* `completion_tokens`/`completion_tokens_details.reasoning_tokens`, used by `openai.ts` and every
|
|
9
|
+
* `OpenAIChatProvider` subclass) and the Responses API (`input_tokens`/`output_tokens`/
|
|
10
|
+
* `output_tokens_details.reasoning_tokens`, used by `openai-responses.ts`) — the two field-name
|
|
11
|
+
* conventions are read via fallback, and only one will ever be present on a given raw object.
|
|
12
|
+
*/
|
|
13
|
+
export function normalizeOpenAIUsage(usage) {
|
|
14
|
+
const u = usage && typeof usage === "object" ? usage : undefined;
|
|
15
|
+
const rawInput = readNumber(u, "prompt_tokens") ?? readNumber(u, "input_tokens");
|
|
16
|
+
const rawOutput = readNumber(u, "completion_tokens") ?? readNumber(u, "output_tokens");
|
|
17
|
+
if (rawInput === undefined && rawOutput === undefined)
|
|
18
|
+
return undefined;
|
|
19
|
+
const inputTokens = rawInput ?? 0;
|
|
20
|
+
const outputTokens = rawOutput ?? 0;
|
|
21
|
+
const cacheReadInputTokens = openAICachedPromptTokens(usage);
|
|
22
|
+
const details = (u?.completion_tokens_details ?? u?.output_tokens_details);
|
|
23
|
+
const reasoningTokens = readNumber(details, "reasoning_tokens");
|
|
24
|
+
const providerUsage = {
|
|
25
|
+
inputTokens,
|
|
26
|
+
outputTokens,
|
|
27
|
+
...(cacheReadInputTokens > 0 ? { cacheReadInputTokens } : {}),
|
|
28
|
+
...(reasoningTokens !== undefined ? { reasoningTokens } : {}),
|
|
29
|
+
};
|
|
30
|
+
return providerUsage;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Anthropic's raw `input_tokens` is UNCACHED input only (unlike OpenAI's `prompt_tokens`, which
|
|
34
|
+
* is already cache-inclusive) — `anthropic.ts`'s own `stream()` sums `input_tokens +
|
|
35
|
+
* cache_read_input_tokens + cache_creation_input_tokens` into the full prompt size for the same
|
|
36
|
+
* reason context-pressure accounting needs it (see that file's comment on why excluding cached
|
|
37
|
+
* tokens would suppress compaction until a 413). This function replicates that same sum so
|
|
38
|
+
* `ProviderUsage.inputTokens` means the same "full prompt size" thing across vendors — reading
|
|
39
|
+
* raw `input_tokens` alone here would silently undercount every cache-heavy Anthropic turn.
|
|
40
|
+
* No `reasoning_tokens`-equivalent field exists in this SDK's `Usage` type, so that field stays
|
|
41
|
+
* unset rather than guessed.
|
|
42
|
+
*/
|
|
43
|
+
export function normalizeAnthropicUsage(usage) {
|
|
44
|
+
const u = usage && typeof usage === "object" ? usage : undefined;
|
|
45
|
+
const rawUncachedInput = readNumber(u, "input_tokens");
|
|
46
|
+
const rawCacheRead = readNumber(u, "cache_read_input_tokens");
|
|
47
|
+
const rawCacheCreation = readNumber(u, "cache_creation_input_tokens");
|
|
48
|
+
const rawOutput = readNumber(u, "output_tokens");
|
|
49
|
+
if (rawUncachedInput === undefined && rawCacheRead === undefined && rawCacheCreation === undefined && rawOutput === undefined)
|
|
50
|
+
return undefined;
|
|
51
|
+
const uncachedInput = rawUncachedInput ?? 0;
|
|
52
|
+
const cacheReadInputTokens = rawCacheRead ?? 0;
|
|
53
|
+
const cacheCreationInputTokens = rawCacheCreation ?? 0;
|
|
54
|
+
const outputTokens = rawOutput ?? 0;
|
|
55
|
+
const providerUsage = {
|
|
56
|
+
inputTokens: uncachedInput + cacheReadInputTokens + cacheCreationInputTokens,
|
|
57
|
+
outputTokens,
|
|
58
|
+
...(cacheReadInputTokens > 0 ? { cacheReadInputTokens } : {}),
|
|
59
|
+
...(cacheCreationInputTokens > 0 ? { cacheCreationInputTokens } : {}),
|
|
60
|
+
};
|
|
61
|
+
return providerUsage;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* `@google/generative-ai`'s `UsageMetadata` has no reasoning/thoughts token field and no separate
|
|
65
|
+
* cache-write count (only `cachedContentTokenCount`, a read figure) — `reasoningTokens` and
|
|
66
|
+
* `cacheCreationInputTokens` stay unset rather than invented.
|
|
67
|
+
*/
|
|
68
|
+
export function normalizeGeminiUsage(usage) {
|
|
69
|
+
const u = usage && typeof usage === "object" ? usage : undefined;
|
|
70
|
+
const rawInput = readNumber(u, "promptTokenCount");
|
|
71
|
+
const rawOutput = readNumber(u, "candidatesTokenCount");
|
|
72
|
+
if (rawInput === undefined && rawOutput === undefined)
|
|
73
|
+
return undefined;
|
|
74
|
+
const inputTokens = rawInput ?? 0;
|
|
75
|
+
const outputTokens = rawOutput ?? 0;
|
|
76
|
+
const cacheReadInputTokens = readNumber(u, "cachedContentTokenCount");
|
|
77
|
+
const providerUsage = {
|
|
78
|
+
inputTokens,
|
|
79
|
+
outputTokens,
|
|
80
|
+
...(cacheReadInputTokens ? { cacheReadInputTokens } : {}),
|
|
81
|
+
};
|
|
82
|
+
return providerUsage;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Ollama's final stream chunk (`done: true`) carries `prompt_eval_count`/`eval_count` — no cache
|
|
86
|
+
* or reasoning concept exists in its API at all, so both stay unset. Before this card `ollama.ts`
|
|
87
|
+
* read neither field; this is the first usage extraction it has ever had.
|
|
88
|
+
*/
|
|
89
|
+
export function normalizeOllamaUsage(chunk) {
|
|
90
|
+
const u = chunk && typeof chunk === "object" ? chunk : undefined;
|
|
91
|
+
const rawInput = readNumber(u, "prompt_eval_count");
|
|
92
|
+
const rawOutput = readNumber(u, "eval_count");
|
|
93
|
+
if (rawInput === undefined && rawOutput === undefined)
|
|
94
|
+
return undefined;
|
|
95
|
+
return { inputTokens: rawInput ?? 0, outputTokens: rawOutput ?? 0 };
|
|
96
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import type { ProviderId } from "./profiles.js";
|
|
1
|
+
import { endpointProfiles } from "./endpoints.js";
|
|
2
|
+
import type { ProviderId } from "./endpoints.js";
|
|
4
3
|
export type EndpointProfileKey = keyof typeof endpointProfiles;
|
|
5
4
|
export interface AnthropicVendorProfile {
|
|
6
5
|
/** Identity advertised in `descriptor().provider`. */
|
|
@@ -9,44 +8,32 @@ export interface AnthropicVendorProfile {
|
|
|
9
8
|
defaultModel: string;
|
|
10
9
|
/** Endpoint profile whose `baseURL` is the Anthropic-compatible wire for this vendor. */
|
|
11
10
|
baseURLProfileKey: EndpointProfileKey;
|
|
12
|
-
/** Recommended `maxTurns` per model id; missing model → empty policy. */
|
|
13
|
-
policies: Record<string, RuntimePolicy>;
|
|
14
11
|
}
|
|
15
|
-
export declare const DEEPSEEK_POLICIES: Record<string, RuntimePolicy>;
|
|
16
|
-
export declare const KIMI_POLICIES: Record<string, RuntimePolicy>;
|
|
17
|
-
export declare const QWEN_POLICIES: Record<string, RuntimePolicy>;
|
|
18
|
-
export declare const GLM_POLICIES: Record<string, RuntimePolicy>;
|
|
19
|
-
export declare const MINIMAX_POLICIES: Record<string, RuntimePolicy>;
|
|
20
12
|
export declare const anthropicVendorProfiles: {
|
|
21
13
|
deepseek: {
|
|
22
14
|
providerId: "deepseek";
|
|
23
15
|
defaultModel: string;
|
|
24
16
|
baseURLProfileKey: "deepseek.anthropic";
|
|
25
|
-
policies: Record<string, RuntimePolicy>;
|
|
26
17
|
};
|
|
27
18
|
kimi: {
|
|
28
19
|
providerId: "kimi";
|
|
29
20
|
defaultModel: string;
|
|
30
21
|
baseURLProfileKey: "kimi.anthropic";
|
|
31
|
-
policies: Record<string, RuntimePolicy>;
|
|
32
22
|
};
|
|
33
23
|
qwen: {
|
|
34
24
|
providerId: "qwen";
|
|
35
25
|
defaultModel: string;
|
|
36
26
|
baseURLProfileKey: "qwen.anthropic";
|
|
37
|
-
policies: Record<string, RuntimePolicy>;
|
|
38
27
|
};
|
|
39
28
|
glm: {
|
|
40
29
|
providerId: "glm";
|
|
41
30
|
defaultModel: string;
|
|
42
31
|
baseURLProfileKey: "glm.anthropic";
|
|
43
|
-
policies: Record<string, RuntimePolicy>;
|
|
44
32
|
};
|
|
45
33
|
minimax: {
|
|
46
34
|
providerId: "minimax";
|
|
47
35
|
defaultModel: string;
|
|
48
36
|
baseURLProfileKey: "minimax.anthropic";
|
|
49
|
-
policies: Record<string, RuntimePolicy>;
|
|
50
37
|
};
|
|
51
38
|
};
|
|
52
39
|
export type AnthropicVendorId = keyof typeof anthropicVendorProfiles;
|
|
@@ -1,64 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"moonshot-v1-32k": { maxTurns: 20 },
|
|
11
|
-
"moonshot-v1-128k": { maxTurns: 30 },
|
|
12
|
-
"kimi-k2.5": { maxTurns: 30 },
|
|
13
|
-
"kimi-k2.6": { maxTurns: 35 },
|
|
14
|
-
"kimi-k2-thinking": { maxTurns: 50 },
|
|
15
|
-
"kimi-k2-thinking-turbo": { maxTurns: 40 },
|
|
16
|
-
};
|
|
17
|
-
export const QWEN_POLICIES = {
|
|
18
|
-
"qwen3.7-max-preview": { maxTurns: 45 },
|
|
19
|
-
"qwen3.7-plus-preview": { maxTurns: 40 },
|
|
20
|
-
"qwen3.6-max-preview": { maxTurns: 40 },
|
|
21
|
-
"qwen3.6-plus": { maxTurns: 35 },
|
|
22
|
-
"qwen3.6-flash": { maxTurns: 20 },
|
|
23
|
-
"qwen3.6-35b-a3b": { maxTurns: 25 },
|
|
24
|
-
"qwen3.6-27b": { maxTurns: 25 },
|
|
25
|
-
"qwen3.5-plus": { maxTurns: 35 },
|
|
26
|
-
"qwen3.5-flash": { maxTurns: 20 },
|
|
27
|
-
"qwen3.5-397b-a17b": { maxTurns: 35 },
|
|
28
|
-
"qwen3.5-122b-a10b": { maxTurns: 25 },
|
|
29
|
-
"qwen3.5-35b-a3b": { maxTurns: 20 },
|
|
30
|
-
"qwen3.5-27b": { maxTurns: 20 },
|
|
31
|
-
};
|
|
32
|
-
export const GLM_POLICIES = {
|
|
33
|
-
"glm-5.2": { maxTurns: 50 },
|
|
34
|
-
"glm/glm-5.2": { maxTurns: 50 },
|
|
35
|
-
"glm-5.1": { maxTurns: 50 },
|
|
36
|
-
"glm/glm-5.1": { maxTurns: 50 },
|
|
37
|
-
"glm-4-plus": { maxTurns: 35 },
|
|
38
|
-
"glm/glm-4-plus": { maxTurns: 35 },
|
|
39
|
-
"glm-4-flash": { maxTurns: 15 },
|
|
40
|
-
"glm/glm-4-flash": { maxTurns: 15 },
|
|
41
|
-
"glm-4-air": { maxTurns: 20 },
|
|
42
|
-
"glm/glm-4-air": { maxTurns: 20 },
|
|
43
|
-
};
|
|
44
|
-
export const MINIMAX_POLICIES = {
|
|
45
|
-
"MiniMax-M3": { maxTurns: 35 },
|
|
46
|
-
"MiniMax-M3-highspeed": { maxTurns: 35 },
|
|
47
|
-
"MiniMax-M2.7": { maxTurns: 35 },
|
|
48
|
-
"MiniMax-M2.7-highspeed": { maxTurns: 35 },
|
|
49
|
-
"MiniMax-M2.5": { maxTurns: 25 },
|
|
50
|
-
"MiniMax-M2.5-highspeed": { maxTurns: 25 },
|
|
51
|
-
"MiniMax-M2.1": { maxTurns: 25 },
|
|
52
|
-
"MiniMax-M2.1-highspeed": { maxTurns: 25 },
|
|
53
|
-
"MiniMax-M2": { maxTurns: 20 },
|
|
54
|
-
"MiniMax-Text-01": { maxTurns: 20 },
|
|
55
|
-
};
|
|
1
|
+
// Single source of truth for the Anthropic-compatible vendor backends (DeepSeek,
|
|
2
|
+
// Kimi, Qwen, GLM, MiniMax). Each backend differs only by data — provider id,
|
|
3
|
+
// default model, endpoint, and per-model runtime policy — so the generic
|
|
4
|
+
// `AnthropicCompatibleProvider` reads a profile from here instead of every
|
|
5
|
+
// backend subclassing `AnthropicProvider` purely to carry configuration.
|
|
6
|
+
//
|
|
7
|
+
// Runtime policy and default model resolution live in ModelRegistry; this module
|
|
8
|
+
// only carries Anthropic-compatible transport configuration.
|
|
9
|
+
import { endpointProfiles } from "./endpoints.js";
|
|
56
10
|
export const anthropicVendorProfiles = {
|
|
57
|
-
deepseek: { providerId: "deepseek", defaultModel: "deepseek-v4-flash", baseURLProfileKey: "deepseek.anthropic"
|
|
58
|
-
kimi: { providerId: "kimi", defaultModel: "kimi-k2.6", baseURLProfileKey: "kimi.anthropic"
|
|
59
|
-
qwen: { providerId: "qwen", defaultModel: "qwen3.6-plus", baseURLProfileKey: "qwen.anthropic"
|
|
60
|
-
glm: { providerId: "glm", defaultModel: "glm-5.2", baseURLProfileKey: "glm.anthropic"
|
|
61
|
-
minimax: { providerId: "minimax", defaultModel: "MiniMax-M3", baseURLProfileKey: "minimax.anthropic"
|
|
11
|
+
deepseek: { providerId: "deepseek", defaultModel: "deepseek-v4-flash", baseURLProfileKey: "deepseek.anthropic" },
|
|
12
|
+
kimi: { providerId: "kimi", defaultModel: "kimi-k2.6", baseURLProfileKey: "kimi.anthropic" },
|
|
13
|
+
qwen: { providerId: "qwen", defaultModel: "qwen3.6-plus", baseURLProfileKey: "qwen.anthropic" },
|
|
14
|
+
glm: { providerId: "glm", defaultModel: "glm-5.2", baseURLProfileKey: "glm.anthropic" },
|
|
15
|
+
minimax: { providerId: "minimax", defaultModel: "MiniMax-M3", baseURLProfileKey: "minimax.anthropic" },
|
|
62
16
|
};
|
|
63
17
|
/** Resolve the Anthropic-compatible base URL for a vendor profile. */
|
|
64
18
|
export function anthropicVendorBaseURL(profile) {
|
|
@@ -95,8 +95,7 @@ export interface CanonicalRunnerRuntimeOptions {
|
|
|
95
95
|
}
|
|
96
96
|
/**
|
|
97
97
|
* Canonical operation runtime used by the Node host.
|
|
98
|
-
* Every durable transition below is one of the canonical
|
|
99
|
-
* envelope or synthesized host transaction reaches core or storage.
|
|
98
|
+
* Every durable transition below is one of the canonical contract's five input classes.
|
|
100
99
|
*/
|
|
101
100
|
export declare class CanonicalRunnerRuntime {
|
|
102
101
|
private readonly options;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
-
import { getKernel } from "../kernel.js";
|
|
3
2
|
import { JournalCasConflictError, MAX_CHAIN_POSITION as JOURNAL_MAX_CHAIN_POSITION, } from "./kernel-journal.js";
|
|
4
3
|
import { encodeCanonicalContentParts, kernelMessageToSdk, renderedContextToSdk, } from "./kernel-step.js";
|
|
5
4
|
export const MAX_CHAIN_POSITION = JOURNAL_MAX_CHAIN_POSITION;
|
|
@@ -12,6 +11,21 @@ function totalUsageTokens(terminal) {
|
|
|
12
11
|
const output = Number(usage.output_tokens ?? 0);
|
|
13
12
|
return Number.isSafeInteger(input + output) ? input + output : 0;
|
|
14
13
|
}
|
|
14
|
+
function canonicalProviderFailureKind(kind) {
|
|
15
|
+
switch (kind) {
|
|
16
|
+
case "transport":
|
|
17
|
+
case "rate_limit":
|
|
18
|
+
case "model_unavailable":
|
|
19
|
+
return "transport_exhausted";
|
|
20
|
+
case "auth":
|
|
21
|
+
case "invalid_request":
|
|
22
|
+
case "modality":
|
|
23
|
+
case "protocol":
|
|
24
|
+
return "protocol_error";
|
|
25
|
+
default:
|
|
26
|
+
return "unknown";
|
|
27
|
+
}
|
|
28
|
+
}
|
|
15
29
|
export function canonicalUnsupportedEffectResolution(effectId, effectKind) {
|
|
16
30
|
return {
|
|
17
31
|
kind: "resolve_effect",
|
|
@@ -343,7 +357,6 @@ export class CanonicalKernelHost {
|
|
|
343
357
|
}
|
|
344
358
|
async transition(input, options = {}) {
|
|
345
359
|
const inputJson = JSON.stringify({
|
|
346
|
-
abi_version: getKernel().kernelAbiVersion(),
|
|
347
360
|
operation_id: this.operationId,
|
|
348
361
|
input_id: options.inputId ?? `node-input-${randomUUID()}`,
|
|
349
362
|
observed_at_ms: options.observedAtMs ?? String(Date.now()),
|
|
@@ -591,7 +604,7 @@ function logicalRunSpec(raw, goal) {
|
|
|
591
604
|
...(raw.metadata && typeof raw.metadata === "object" ? { metadata: raw.metadata } : {}),
|
|
592
605
|
};
|
|
593
606
|
}
|
|
594
|
-
function canonicalWorkflowSpec(raw) {
|
|
607
|
+
function canonicalWorkflowSpec(raw, allowHostSchedulingFactors = false) {
|
|
595
608
|
const nodes = Array.isArray(raw.nodes) ? raw.nodes.map(asObject) : [];
|
|
596
609
|
const nodeIds = nodes.map((_node, index) => `wf-node${index}`);
|
|
597
610
|
return {
|
|
@@ -614,6 +627,9 @@ function canonicalWorkflowSpec(raw) {
|
|
|
614
627
|
unsupported.push("max_turns");
|
|
615
628
|
if (node.max_wall_ms !== undefined || node.maxWallMs !== undefined)
|
|
616
629
|
unsupported.push("max_wall_ms");
|
|
630
|
+
const schedulingFactors = node.scheduling_factors ?? node.schedulingFactors;
|
|
631
|
+
if (schedulingFactors !== undefined && !allowHostSchedulingFactors)
|
|
632
|
+
unsupported.push("scheduling_factors");
|
|
617
633
|
const inheritance = node.context_inheritance ?? node.contextInheritance;
|
|
618
634
|
if (unsupported.length > 0) {
|
|
619
635
|
throw new CanonicalKernelRejectedError(JSON.stringify({
|
|
@@ -634,16 +650,20 @@ function canonicalWorkflowSpec(raw) {
|
|
|
634
650
|
: [];
|
|
635
651
|
const modelHint = node.model_hint ?? node.modelHint;
|
|
636
652
|
const outputSchema = node.output_schema ?? node.outputSchema;
|
|
653
|
+
const canonicalSchedulingFactors = schedulingFactors === undefined
|
|
654
|
+
? undefined
|
|
655
|
+
: canonicalSchedulingFactorsForHost(schedulingFactors);
|
|
637
656
|
const runSpec = logicalRunSpec({
|
|
638
657
|
goal,
|
|
639
658
|
...(node.role ? { role: node.role } : {}),
|
|
640
659
|
...(node.isolation ? { isolation: node.isolation } : {}),
|
|
641
660
|
...(inheritance ? { context_inheritance: inheritance } : {}),
|
|
642
|
-
...((modelHint !== undefined || outputSchema !== undefined)
|
|
661
|
+
...((modelHint !== undefined || outputSchema !== undefined || canonicalSchedulingFactors !== undefined)
|
|
643
662
|
? {
|
|
644
663
|
metadata: {
|
|
645
664
|
...(modelHint !== undefined ? { model_hint: modelHint } : {}),
|
|
646
665
|
...(outputSchema !== undefined ? { output_schema: outputSchema } : {}),
|
|
666
|
+
...(canonicalSchedulingFactors !== undefined ? { scheduling_factors: canonicalSchedulingFactors } : {}),
|
|
647
667
|
},
|
|
648
668
|
}
|
|
649
669
|
: {}),
|
|
@@ -661,6 +681,24 @@ function canonicalWorkflowSpec(raw) {
|
|
|
661
681
|
}),
|
|
662
682
|
};
|
|
663
683
|
}
|
|
684
|
+
function canonicalSchedulingFactorsForHost(value) {
|
|
685
|
+
const raw = asObject(value);
|
|
686
|
+
const allowed = new Set(["deadline_urgency", "process_priority", "resource_pressure", "budget_pressure"]);
|
|
687
|
+
const unknown = Object.keys(raw).filter(key => !allowed.has(key));
|
|
688
|
+
if (unknown.length > 0)
|
|
689
|
+
throw new TypeError(`unknown scheduling factor(s): ${unknown.join(", ")}`);
|
|
690
|
+
const factors = {};
|
|
691
|
+
for (const key of allowed) {
|
|
692
|
+
const factor = raw[key];
|
|
693
|
+
if (factor === undefined)
|
|
694
|
+
continue;
|
|
695
|
+
if (!Number.isSafeInteger(factor) || factor < 0) {
|
|
696
|
+
throw new RangeError(`scheduling_factors.${key} must be a non-negative safe integer`);
|
|
697
|
+
}
|
|
698
|
+
factors[key] = factor;
|
|
699
|
+
}
|
|
700
|
+
return factors;
|
|
701
|
+
}
|
|
664
702
|
function sha256(value) {
|
|
665
703
|
return `sha256:${createHash("sha256").update(value).digest("hex")}`;
|
|
666
704
|
}
|
|
@@ -675,8 +713,7 @@ function providerStopReason(value) {
|
|
|
675
713
|
}
|
|
676
714
|
/**
|
|
677
715
|
* Canonical operation runtime used by the Node host.
|
|
678
|
-
* Every durable transition below is one of the canonical
|
|
679
|
-
* envelope or synthesized host transaction reaches core or storage.
|
|
716
|
+
* Every durable transition below is one of the canonical contract's five input classes.
|
|
680
717
|
*/
|
|
681
718
|
export class CanonicalRunnerRuntime {
|
|
682
719
|
options;
|
|
@@ -802,7 +839,7 @@ export class CanonicalRunnerRuntime {
|
|
|
802
839
|
kind: "start_operation",
|
|
803
840
|
entry: {
|
|
804
841
|
kind: "workflow",
|
|
805
|
-
spec: canonicalWorkflowSpec(specValue),
|
|
842
|
+
spec: canonicalWorkflowSpec(specValue, true),
|
|
806
843
|
},
|
|
807
844
|
initial_context: this.initialContext,
|
|
808
845
|
});
|
|
@@ -856,7 +893,8 @@ export class CanonicalRunnerRuntime {
|
|
|
856
893
|
}
|
|
857
894
|
case "provider_error": {
|
|
858
895
|
const message = String(event.message ?? "");
|
|
859
|
-
const
|
|
896
|
+
const hasStructuredKind = typeof event.error_kind === "string";
|
|
897
|
+
const contextOverflow = event.error_kind === "context_overflow";
|
|
860
898
|
input = contextOverflow
|
|
861
899
|
? {
|
|
862
900
|
kind: "resolve_effect",
|
|
@@ -866,7 +904,7 @@ export class CanonicalRunnerRuntime {
|
|
|
866
904
|
result: { kind: "provider", outcome: { kind: "context_overflow" } },
|
|
867
905
|
},
|
|
868
906
|
}
|
|
869
|
-
: this.failedEffect(event, "transport_exhausted", message, true);
|
|
907
|
+
: this.failedEffect(event, hasStructuredKind ? canonicalProviderFailureKind(event.error_kind) : "transport_exhausted", message, typeof event.retryable === "boolean" ? event.retryable : true);
|
|
870
908
|
break;
|
|
871
909
|
}
|
|
872
910
|
case "tool_results": {
|
|
@@ -1425,9 +1463,6 @@ export class CanonicalRunnerRuntime {
|
|
|
1425
1463
|
delete asObject(execution.entropy_watch).threshold;
|
|
1426
1464
|
delete asObject(execution.entropy_watch).hysteresis;
|
|
1427
1465
|
}
|
|
1428
|
-
if (config.tool_dispatch_gate !== undefined) {
|
|
1429
|
-
this.featurePolicy().tool_dispatch_gate = config.tool_dispatch_gate;
|
|
1430
|
-
}
|
|
1431
1466
|
if (config.knowledge_budget_ratio !== undefined) {
|
|
1432
1467
|
const context = asObject(this.config.context_policy);
|
|
1433
1468
|
context.knowledge_budget_ppm = Math.round(Number(config.knowledge_budget_ratio) * 1_000_000);
|
|
@@ -1,35 +1,33 @@
|
|
|
1
|
-
export declare const CONTEXT_POLICY_VERSION: 1;
|
|
2
1
|
export declare const PPM_SCALE: 1000000;
|
|
3
|
-
export interface
|
|
2
|
+
export interface ContextPressureThresholds {
|
|
4
3
|
snip: number;
|
|
5
4
|
micro: number;
|
|
6
5
|
collapse: number;
|
|
7
6
|
auto: number;
|
|
8
7
|
renewal: number;
|
|
9
8
|
}
|
|
10
|
-
export interface
|
|
11
|
-
pressureThresholds:
|
|
9
|
+
export interface ContextPolicy {
|
|
10
|
+
pressureThresholds: ContextPressureThresholds;
|
|
12
11
|
targetAfterCompress: number;
|
|
13
12
|
preserveRecentTurns: number;
|
|
14
13
|
renewalCarryover: number;
|
|
15
14
|
collapseOldAssistantNarration: boolean;
|
|
16
15
|
idleMicroCompactMinutes: number;
|
|
17
16
|
}
|
|
18
|
-
export interface
|
|
19
|
-
|
|
20
|
-
pressure_thresholds_ppm: ContextPressureThresholdsV1;
|
|
17
|
+
export interface ContextPolicyWire {
|
|
18
|
+
pressure_thresholds_ppm: ContextPressureThresholds;
|
|
21
19
|
target_after_compress_ppm: number;
|
|
22
20
|
preserve_recent_turns: number;
|
|
23
21
|
renewal_carryover_ppm: number;
|
|
24
22
|
collapse_old_assistant_narration: boolean;
|
|
25
23
|
idle_micro_compact_minutes: number;
|
|
26
24
|
}
|
|
27
|
-
export interface
|
|
28
|
-
pressureThresholds?: Partial<
|
|
25
|
+
export interface ContextPolicyOverrides extends Partial<Omit<ContextPolicy, "pressureThresholds">> {
|
|
26
|
+
pressureThresholds?: Partial<ContextPressureThresholds>;
|
|
29
27
|
}
|
|
30
|
-
export declare const
|
|
28
|
+
export declare const DEFAULT_CONTEXT_POLICY: Readonly<ContextPolicy>;
|
|
31
29
|
/** Resolve ergonomic partial SDK options into one complete, atomically validated policy. */
|
|
32
|
-
export declare function
|
|
30
|
+
export declare function contextPolicy(overrides?: ContextPolicyOverrides): ContextPolicy;
|
|
33
31
|
/** Convert the public ratio-based policy to the canonical integer-only ABI wire shape. */
|
|
34
|
-
export declare function
|
|
32
|
+
export declare function normalizeContextPolicy(policy: ContextPolicy): ContextPolicyWire;
|
|
35
33
|
export declare function ratioToPpm(value: number, field?: string): number;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
export const CONTEXT_POLICY_VERSION = 1;
|
|
2
1
|
export const PPM_SCALE = 1_000_000;
|
|
3
|
-
export const
|
|
2
|
+
export const DEFAULT_CONTEXT_POLICY = Object.freeze({
|
|
4
3
|
pressureThresholds: Object.freeze({ snip: 0.70, micro: 0.80, collapse: 0.90, auto: 0.95, renewal: 0.98 }),
|
|
5
4
|
targetAfterCompress: 0.65,
|
|
6
5
|
preserveRecentTurns: 2,
|
|
@@ -9,20 +8,20 @@ export const DEFAULT_CONTEXT_POLICY_V1 = Object.freeze({
|
|
|
9
8
|
idleMicroCompactMinutes: 60,
|
|
10
9
|
});
|
|
11
10
|
/** Resolve ergonomic partial SDK options into one complete, atomically validated policy. */
|
|
12
|
-
export function
|
|
11
|
+
export function contextPolicy(overrides = {}) {
|
|
13
12
|
const policy = {
|
|
14
|
-
...
|
|
13
|
+
...DEFAULT_CONTEXT_POLICY,
|
|
15
14
|
...overrides,
|
|
16
15
|
pressureThresholds: {
|
|
17
|
-
...
|
|
16
|
+
...DEFAULT_CONTEXT_POLICY.pressureThresholds,
|
|
18
17
|
...overrides.pressureThresholds,
|
|
19
18
|
},
|
|
20
19
|
};
|
|
21
|
-
|
|
20
|
+
normalizeContextPolicy(policy);
|
|
22
21
|
return policy;
|
|
23
22
|
}
|
|
24
23
|
/** Convert the public ratio-based policy to the canonical integer-only ABI wire shape. */
|
|
25
|
-
export function
|
|
24
|
+
export function normalizeContextPolicy(policy) {
|
|
26
25
|
const pressure_thresholds_ppm = {
|
|
27
26
|
snip: ratioToPpm(policy.pressureThresholds.snip, "pressureThresholds.snip"),
|
|
28
27
|
micro: ratioToPpm(policy.pressureThresholds.micro, "pressureThresholds.micro"),
|
|
@@ -44,7 +43,6 @@ export function normalizeContextPolicyV1(policy) {
|
|
|
44
43
|
throw new TypeError("collapseOldAssistantNarration must be boolean");
|
|
45
44
|
}
|
|
46
45
|
return {
|
|
47
|
-
version: CONTEXT_POLICY_VERSION,
|
|
48
46
|
pressure_thresholds_ppm,
|
|
49
47
|
target_after_compress_ppm,
|
|
50
48
|
preserve_recent_turns: policy.preserveRecentTurns,
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/** Provider-neutral durable content ABI.
|
|
2
|
+
*
|
|
3
|
+
* This is deliberately separate from provider-facing ContentPart. Durable records carry only
|
|
4
|
+
* portable content and explicit payload locators; protocol adapters decide how to serialize it.
|
|
5
|
+
*/
|
|
6
|
+
export declare class DurableContentError extends Error {
|
|
7
|
+
constructor(message: string);
|
|
8
|
+
}
|
|
9
|
+
export type DurableSource = {
|
|
10
|
+
kind: "url";
|
|
11
|
+
url: string;
|
|
12
|
+
} | {
|
|
13
|
+
kind: "base64";
|
|
14
|
+
data: string;
|
|
15
|
+
} | {
|
|
16
|
+
kind: "file_id";
|
|
17
|
+
id: string;
|
|
18
|
+
affinity: {
|
|
19
|
+
provider_id: string;
|
|
20
|
+
endpoint_id: string;
|
|
21
|
+
};
|
|
22
|
+
} | {
|
|
23
|
+
kind: "object";
|
|
24
|
+
handle: string;
|
|
25
|
+
owner: string;
|
|
26
|
+
payload_ref: string;
|
|
27
|
+
};
|
|
28
|
+
export type DurableContentBlock = {
|
|
29
|
+
type: "text";
|
|
30
|
+
text: string;
|
|
31
|
+
} | {
|
|
32
|
+
type: "image" | "audio" | "video" | "file";
|
|
33
|
+
source: DurableSource;
|
|
34
|
+
media_type?: string;
|
|
35
|
+
provider_options?: Record<string, unknown>;
|
|
36
|
+
};
|
|
37
|
+
export interface DurableContent {
|
|
38
|
+
blocks: DurableContentBlock[];
|
|
39
|
+
}
|
|
40
|
+
export interface DurableToolResult extends DurableContent {
|
|
41
|
+
call_id: string;
|
|
42
|
+
is_error: boolean;
|
|
43
|
+
}
|
|
44
|
+
import type { ToolOutputBlock } from "../types.js";
|
|
45
|
+
export declare function decodeDurableContent(value: unknown): DurableContent;
|
|
46
|
+
export declare function decodeDurableToolResult(value: unknown): DurableToolResult;
|
|
47
|
+
export declare function encodeDurableContent(content: DurableContent): Record<string, unknown>;
|
|
48
|
+
export declare function encodeDurableToolResult(result: DurableToolResult): Record<string, unknown>;
|
|
49
|
+
export declare function toolOutputBlocksToDurable(blocks: readonly ToolOutputBlock[]): DurableContentBlock[];
|
|
50
|
+
export declare function durableBlocksToToolOutput(blocks: readonly DurableContentBlock[]): ToolOutputBlock[];
|