@deepstrike/sdk 0.2.6 → 0.2.7

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.
Files changed (38) hide show
  1. package/dist/index.d.ts +5 -3
  2. package/dist/index.js +3 -2
  3. package/dist/kernel.d.ts +54 -0
  4. package/dist/kernel.js +8 -0
  5. package/dist/providers/anthropic.d.ts +4 -1
  6. package/dist/providers/anthropic.js +51 -0
  7. package/dist/providers/catalog.js +5 -2
  8. package/dist/providers/deepseek.d.ts +4 -1
  9. package/dist/providers/deepseek.js +76 -8
  10. package/dist/providers/glm.d.ts +2 -1
  11. package/dist/providers/glm.js +7 -0
  12. package/dist/providers/kimi.d.ts +2 -1
  13. package/dist/providers/kimi.js +7 -0
  14. package/dist/providers/minimax.d.ts +28 -2
  15. package/dist/providers/minimax.js +197 -1
  16. package/dist/providers/openai-chat.d.ts +6 -2
  17. package/dist/providers/openai-chat.js +20 -3
  18. package/dist/providers/openai.d.ts +4 -1
  19. package/dist/providers/openai.js +31 -7
  20. package/dist/providers/profiles.d.ts +6 -0
  21. package/dist/providers/profiles.js +6 -0
  22. package/dist/providers/qwen.d.ts +3 -1
  23. package/dist/providers/qwen.js +20 -2
  24. package/dist/providers/replay-validator.d.ts +10 -0
  25. package/dist/providers/replay-validator.js +57 -0
  26. package/dist/runtime/kernel-event-log.js +22 -0
  27. package/dist/runtime/kernel-step.d.ts +13 -0
  28. package/dist/runtime/provider-replay.d.ts +8 -1
  29. package/dist/runtime/provider-replay.js +37 -4
  30. package/dist/runtime/runner.d.ts +22 -1
  31. package/dist/runtime/runner.js +68 -2
  32. package/dist/runtime/session-log.d.ts +22 -0
  33. package/dist/runtime/session-repair.d.ts +26 -3
  34. package/dist/runtime/session-repair.js +33 -32
  35. package/dist/types/agent.d.ts +50 -0
  36. package/dist/types/agent.js +110 -0
  37. package/dist/types.d.ts +23 -0
  38. package/package.json +2 -2
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  export { RuntimeRunner, collectText } from "./runtime/runner.js";
2
2
  export type { RuntimeOptions, SchedulerBudget } from "./runtime/runner.js";
3
3
  export type { MemoryPolicy, MemoryWriteRateLimit, ResourceQuota } from "./kernel.js";
4
+ export { createTournament, createLoopUntilDone } from "./kernel.js";
5
+ export type { TournamentMatch, TournamentAction, StopConditionSpec, RoundReport, LoopAction, } from "./kernel.js";
4
6
  export { KernelPrimitivesDashboard } from "./runtime/kernel-primitives-dashboard.js";
5
7
  export { FilteredExecutionPlane } from "./runtime/filtered-plane.js";
6
8
  export { SubAgentOrchestrator, defaultSubAgentOrchestrator, spawnStandalone } from "./runtime/sub-agent-orchestrator.js";
@@ -31,7 +33,7 @@ export { DeepSeekProvider } from "./providers/deepseek.js";
31
33
  export { KimiProvider } from "./providers/kimi.js";
32
34
  export { QwenProvider } from "./providers/qwen.js";
33
35
  export { GeminiProvider } from "./providers/gemini.js";
34
- export { MiniMaxProvider } from "./providers/minimax.js";
36
+ export { MiniMaxAnthropicProvider, MiniMaxOpenAIProvider } from "./providers/minimax.js";
35
37
  export { OllamaProvider } from "./providers/ollama.js";
36
38
  export { CircuitBreaker, normalizeToolCall } from "./providers/base.js";
37
39
  export { OpenAIChatAdapter } from "./providers/openai-chat.js";
@@ -58,8 +60,8 @@ export type { GovernanceVerdict, GovernancePolicy, GovernanceConstraint } from "
58
60
  export { SinglePassHarness, EvalLoopHarness, HarnessLoop } from "./harness/harness.js";
59
61
  export type { HarnessRequest, HarnessOutcome, HarnessLoopOptions, QualityGate } from "./harness/harness.js";
60
62
  export type { Message, ToolCall, ToolResult, ToolSchema, ContentPart, TextPart, ImagePart, AudioPart, StreamEvent, TextDelta, ThinkingDelta, ToolCallEvent, ToolChunk, ToolDeltaEvent, ToolSuspendEvent, ToolResultEvent, DoneEvent, ErrorEvent, PermissionRequestEvent, PermissionResolvedEvent, PermissionResponse, LLMProvider, RetryConfig, TokenUsage, ProviderToolSpec, ProviderRunState, ProviderReplay, RenderedContext, } from "./types.js";
61
- export type { AgentCapabilityFilter, AgentIdentity, AgentIsolation, AgentRunSpec, AgentProcessChangedObservation, ContextInheritance, KernelAgentRole, LoopResult, MilestoneCheckResult, MilestoneContract, MilestonePhase, MilestonePolicy, SubAgentResult, TerminationReason, } from "./types/agent.js";
62
- export { agentIdentitySub, agentRunSpecToKernel, milestoneCheckFail, milestoneCheckPass, milestoneCheckResultToKernel, subAgentResultToKernel, } from "./types/agent.js";
63
+ export type { AgentCapabilityFilter, AgentIdentity, AgentIsolation, AgentRunSpec, AgentProcessChangedObservation, ContextInheritance, KernelAgentRole, LoopResult, MilestoneCheckResult, MilestoneContract, MilestonePhase, MilestonePolicy, SubAgentResult, TerminationReason, WorkflowSpec, WorkflowNodeSpec, WorkflowTaskSpec, WorkflowSpawnInfo, } from "./types/agent.js";
64
+ export { agentIdentitySub, agentRunSpecToKernel, milestoneCheckFail, milestoneCheckPass, milestoneCheckResultToKernel, subAgentResultToKernel, workflowSpecToKernel, fanoutSynthesize, generateAndFilter, verifyRules, } from "./types/agent.js";
63
65
  export type { AcceptanceCriterion, VerificationContract, ContractCheckResult, } from "./collaboration/contract.js";
64
66
  export { ContractBuilder, formatContractForSystemPrompt, contractToCriteriaStrings, } from "./collaboration/contract.js";
65
67
  export { AgentPool } from "./collaboration/pool.js";
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // ── Runtime (Layer 1.5) ────────────────────────────────────────────────────
2
2
  export { RuntimeRunner, collectText } from "./runtime/runner.js";
3
+ export { createTournament, createLoopUntilDone } from "./kernel.js";
3
4
  export { KernelPrimitivesDashboard } from "./runtime/kernel-primitives-dashboard.js";
4
5
  export { FilteredExecutionPlane } from "./runtime/filtered-plane.js";
5
6
  export { SubAgentOrchestrator, defaultSubAgentOrchestrator, spawnStandalone } from "./runtime/sub-agent-orchestrator.js";
@@ -20,7 +21,7 @@ export { DeepSeekProvider } from "./providers/deepseek.js";
20
21
  export { KimiProvider } from "./providers/kimi.js";
21
22
  export { QwenProvider } from "./providers/qwen.js";
22
23
  export { GeminiProvider } from "./providers/gemini.js";
23
- export { MiniMaxProvider } from "./providers/minimax.js";
24
+ export { MiniMaxAnthropicProvider, MiniMaxOpenAIProvider } from "./providers/minimax.js";
24
25
  export { OllamaProvider } from "./providers/ollama.js";
25
26
  export { CircuitBreaker, normalizeToolCall } from "./providers/base.js";
26
27
  export { OpenAIChatAdapter } from "./providers/openai-chat.js";
@@ -39,7 +40,7 @@ export { PermissionManager, PermissionMode } from "./safety/permissions.js";
39
40
  export { Governance, governancePolicyToKernelEvent } from "./governance.js";
40
41
  // ── Harness ────────────────────────────────────────────────────────────────
41
42
  export { SinglePassHarness, EvalLoopHarness, HarnessLoop } from "./harness/harness.js";
42
- export { agentIdentitySub, agentRunSpecToKernel, milestoneCheckFail, milestoneCheckPass, milestoneCheckResultToKernel, subAgentResultToKernel, } from "./types/agent.js";
43
+ export { agentIdentitySub, agentRunSpecToKernel, milestoneCheckFail, milestoneCheckPass, milestoneCheckResultToKernel, subAgentResultToKernel, workflowSpecToKernel, fanoutSynthesize, generateAndFilter, verifyRules, } from "./types/agent.js";
43
44
  export { ContractBuilder, formatContractForSystemPrompt, contractToCriteriaStrings, } from "./collaboration/contract.js";
44
45
  export { AgentPool } from "./collaboration/pool.js";
45
46
  export { KERNEL_ROLE_MAP } from "./collaboration/pool.js";
package/dist/kernel.d.ts CHANGED
@@ -147,6 +147,54 @@ export interface KernelRuntimeInstance {
147
147
  drainNewMessages(): Message[];
148
148
  preservedRefs(): string[];
149
149
  }
150
+ /** One pairwise match-up in a tournament round. */
151
+ export interface TournamentMatch {
152
+ id: number;
153
+ left: string;
154
+ right: string;
155
+ }
156
+ /** Discriminated action returned by {@link TournamentInstance} methods. */
157
+ export interface TournamentAction {
158
+ kind: "judgeRound" | "done";
159
+ /** `judgeRound`: 1-based round number. */
160
+ round?: number;
161
+ /** `judgeRound`: run one fresh-context judge per match (parallelisable). */
162
+ matches?: TournamentMatch[];
163
+ /** `done`: the winning entrant id. */
164
+ winner?: string;
165
+ /** `done`: number of rounds played. */
166
+ roundsUsed?: number;
167
+ }
168
+ interface TournamentInstance {
169
+ start(): TournamentAction;
170
+ feedRound(winners: string[]): TournamentAction;
171
+ isDone(): boolean;
172
+ }
173
+ /** A single loop stop predicate. `maxRounds` is required when `kind === "maxRounds"`. */
174
+ export interface StopConditionSpec {
175
+ kind: "noNewFindings" | "noErrors" | "maxRounds";
176
+ maxRounds?: number;
177
+ }
178
+ /** What the SDK reports after running a loop round's worker. */
179
+ export interface RoundReport {
180
+ newFindings: number;
181
+ errors: number;
182
+ }
183
+ /** Discriminated action returned by {@link LoopUntilDoneInstance} methods. */
184
+ export interface LoopAction {
185
+ kind: "spawn" | "done";
186
+ /** `spawn`: 1-based round number to run. */
187
+ round?: number;
188
+ /** `done`: number of rounds run. */
189
+ roundsUsed?: number;
190
+ /** `done`: which condition fired. */
191
+ reason?: "noNewFindings" | "noErrors" | "maxRounds";
192
+ }
193
+ interface LoopUntilDoneInstance {
194
+ start(): LoopAction;
195
+ feed(report: RoundReport): LoopAction;
196
+ isDone(): boolean;
197
+ }
150
198
  interface KernelModule {
151
199
  Governance: new (defaultAction?: "allow" | "deny" | "ask_user") => GovernanceInstance;
152
200
  KernelRuntime: new (policy: {
@@ -160,6 +208,12 @@ interface KernelModule {
160
208
  extractSkillOnPass?: boolean;
161
209
  }) => EvalPipelineInstance;
162
210
  IdlePipeline: new (agentId: string) => IdlePipelineInstance;
211
+ Tournament: new (entrants: string[]) => TournamentInstance;
212
+ LoopUntilDone: new (conditions: StopConditionSpec[]) => LoopUntilDoneInstance;
163
213
  }
214
+ /** Create a single-elimination tournament (pairwise comparative judging). Throws if `entrants` is empty. */
215
+ export declare function createTournament(entrants: string[]): TournamentInstance;
216
+ /** Create a loop-until-done state machine. A `maxRounds` backstop is injected if none is given. */
217
+ export declare function createLoopUntilDone(conditions: StopConditionSpec[]): LoopUntilDoneInstance;
164
218
  export declare function getKernel(): KernelModule;
165
219
  export {};
package/dist/kernel.js CHANGED
@@ -2,6 +2,14 @@ import { createRequire } from "module";
2
2
  import { existsSync } from "node:fs";
3
3
  import { dirname, join } from "node:path";
4
4
  import { fileURLToPath } from "node:url";
5
+ /** Create a single-elimination tournament (pairwise comparative judging). Throws if `entrants` is empty. */
6
+ export function createTournament(entrants) {
7
+ return new (getKernel().Tournament)(entrants);
8
+ }
9
+ /** Create a loop-until-done state machine. A `maxRounds` backstop is injected if none is given. */
10
+ export function createLoopUntilDone(conditions) {
11
+ return new (getKernel().LoopUntilDone)(conditions);
12
+ }
5
13
  const cjsRequire = createRequire(import.meta.url);
6
14
  let cachedKernel;
7
15
  function resolveCoreModule() {
@@ -1,4 +1,4 @@
1
- import type { Message, ProviderReplay, RenderedContext, ToolSchema, StreamEvent, LLMProvider, RuntimePolicy } from "../types.js";
1
+ import type { Message, ProviderDescriptor, ProviderReplay, RenderedContext, ToolSchema, StreamEvent, LLMProvider, RuntimePolicy } from "../types.js";
2
2
  interface AnthropicProviderOptions {
3
3
  baseURL?: string;
4
4
  authMode?: "api-key" | "bearer";
@@ -15,6 +15,9 @@ export declare class AnthropicProvider implements LLMProvider {
15
15
  baseDelay: number;
16
16
  }, options?: AnthropicProviderOptions);
17
17
  runtimePolicy(): RuntimePolicy;
18
+ /** Identity advertised in the descriptor; overridden by Anthropic-compatible vendors (e.g. MiniMax). */
19
+ protected providerName(): string;
20
+ descriptor(): ProviderDescriptor;
18
21
  peekProviderReplay(message: Pick<Message, "content" | "toolCalls">): ProviderReplay | undefined;
19
22
  seedProviderReplay(message: Pick<Message, "content" | "toolCalls">, replay: ProviderReplay): void;
20
23
  private buildTools;
@@ -34,6 +34,26 @@ export class AnthropicProvider {
34
34
  runtimePolicy() {
35
35
  return CLAUDE_POLICIES[this.model] ?? {};
36
36
  }
37
+ /** Identity advertised in the descriptor; overridden by Anthropic-compatible vendors (e.g. MiniMax). */
38
+ providerName() {
39
+ return "anthropic";
40
+ }
41
+ descriptor() {
42
+ return {
43
+ provider: this.providerName(),
44
+ protocol: "anthropic-messages",
45
+ model: this.model,
46
+ reasoning: {
47
+ supported: true,
48
+ preserveAcrossToolTurns: true,
49
+ requiresReplayForToolTurns: true,
50
+ },
51
+ toolCalls: {
52
+ supported: true,
53
+ requiresStrictPairing: true,
54
+ },
55
+ };
56
+ }
37
57
  peekProviderReplay(message) {
38
58
  const blocks = this.nativeAssistantBlocks.get(assistantReplayKey(message));
39
59
  return blocks?.length ? { native_blocks: blocks } : undefined;
@@ -41,7 +61,14 @@ export class AnthropicProvider {
41
61
  seedProviderReplay(message, replay) {
42
62
  if (replay.native_blocks?.length) {
43
63
  this.nativeAssistantBlocks.set(assistantReplayKey(message), replay.native_blocks);
64
+ return;
44
65
  }
66
+ // Legacy log without persisted native blocks: reconstruct neutral
67
+ // text + tool_use blocks from the transcript so a tool-use turn can be
68
+ // replayed. Thinking blocks were never persisted, so they are not recovered.
69
+ const blocks = reconstructAnthropicBlocks(message);
70
+ if (blocks.length)
71
+ this.nativeAssistantBlocks.set(assistantReplayKey(message), blocks);
45
72
  }
46
73
  buildTools(tools) {
47
74
  return tools.map((t, i) => ({
@@ -206,3 +233,27 @@ export class AnthropicProvider {
206
233
  this.nativeAssistantBlocks.set(assistantReplayKey(message), blocks);
207
234
  }
208
235
  }
236
+ /**
237
+ * Reconstruct Anthropic assistant content blocks from a neutral transcript when
238
+ * no provider replay was persisted. Only meaningful for tool-use turns: a plain
239
+ * text turn needs no native blocks to replay.
240
+ */
241
+ function reconstructAnthropicBlocks(message) {
242
+ const toolCalls = message.toolCalls ?? [];
243
+ if (!toolCalls.length)
244
+ return [];
245
+ const blocks = [];
246
+ if (message.content)
247
+ blocks.push({ type: "text", text: message.content });
248
+ for (const tc of toolCalls) {
249
+ let input = {};
250
+ try {
251
+ input = JSON.parse(tc.arguments || "{}");
252
+ }
253
+ catch {
254
+ input = {};
255
+ }
256
+ blocks.push({ type: "tool_use", id: tc.id, name: tc.name, input });
257
+ }
258
+ return blocks;
259
+ }
@@ -3,7 +3,7 @@ import { OpenAIChatProvider } from "./openai.js";
3
3
  import { DeepSeekProvider } from "./deepseek.js";
4
4
  import { KimiProvider } from "./kimi.js";
5
5
  import { OpenAIResponsesProvider } from "./openai-responses.js";
6
- import { MiniMaxProvider } from "./minimax.js";
6
+ import { MiniMaxAnthropicProvider, MiniMaxOpenAIProvider } from "./minimax.js";
7
7
  import { QwenProvider } from "./qwen.js";
8
8
  import { GeminiProvider } from "./gemini.js";
9
9
  import { GLMProvider } from "./glm.js";
@@ -43,7 +43,10 @@ export function createProvider(options) {
43
43
  }
44
44
  }
45
45
  if (providerId === "minimax" && endpoint.protocol === "anthropic-messages") {
46
- return new MiniMaxProvider(options.apiKey, model, options.retry, baseURL);
46
+ return new MiniMaxAnthropicProvider(options.apiKey, model, options.retry, baseURL);
47
+ }
48
+ if (providerId === "minimax" && endpoint.protocol === "openai-chat") {
49
+ return new MiniMaxOpenAIProvider(options.apiKey, model, options.retry, baseURL);
47
50
  }
48
51
  if (providerId === "deepseek" && endpoint.protocol === "openai-chat") {
49
52
  return new DeepSeekProvider(options.apiKey, model, options.retry, baseURL);
@@ -1,4 +1,4 @@
1
- import type { Message, RenderedContext, ToolSchema, StreamEvent, RuntimePolicy } from "../types.js";
1
+ import type { Message, ProviderDescriptor, RenderedContext, ToolSchema, StreamEvent, RuntimePolicy } from "../types.js";
2
2
  import { OpenAIChatProvider } from "./openai.js";
3
3
  export declare class DeepSeekProvider extends OpenAIChatProvider {
4
4
  constructor(apiKey: string, model?: string, retry?: {
@@ -6,6 +6,9 @@ export declare class DeepSeekProvider extends OpenAIChatProvider {
6
6
  baseDelay: number;
7
7
  }, baseURL?: string);
8
8
  runtimePolicy(): RuntimePolicy;
9
+ descriptor(): ProviderDescriptor;
10
+ protected requireNonEmptyReasoningReplayForToolTurns(extensions?: Record<string, unknown>): boolean;
9
11
  complete(context: RenderedContext, tools: ToolSchema[], extensions?: Record<string, unknown>): Promise<Message>;
10
12
  stream(context: RenderedContext, tools: ToolSchema[], extensions?: Record<string, unknown>): AsyncIterable<StreamEvent>;
13
+ private rememberDeepSeekReplay;
11
14
  }
@@ -15,20 +15,71 @@ export class DeepSeekProvider extends OpenAIChatProvider {
15
15
  runtimePolicy() {
16
16
  return DEEPSEEK_POLICIES[this.model] ?? {};
17
17
  }
18
+ descriptor() {
19
+ return {
20
+ provider: "deepseek",
21
+ protocol: "openai-chat",
22
+ model: this.model,
23
+ reasoning: {
24
+ supported: true,
25
+ preserveAcrossToolTurns: true,
26
+ requiresReplayForToolTurns: true,
27
+ },
28
+ toolCalls: {
29
+ supported: true,
30
+ requiresStrictPairing: true,
31
+ },
32
+ };
33
+ }
34
+ requireNonEmptyReasoningReplayForToolTurns(extensions) {
35
+ if (extensions?.__deepstrikeThinkingEnabled === false)
36
+ return false;
37
+ return extensions?.thinking !== false;
38
+ }
18
39
  async complete(context, tools, extensions) {
19
40
  const thinking = extensions?.thinking === false ? "disabled" : "enabled";
41
+ const thinkingEnabled = thinking !== "disabled";
20
42
  const reasoningEffort = extensions?.reasoningEffort === "max" ? "max" : "high";
21
- return super.complete(context, tools, {
43
+ const requestExtensions = {
22
44
  ...omitExtensionKeys(extensions, ["thinking", "reasoningEffort", "exposeReasoning", "extra_body", "reasoning_effort"]),
45
+ __deepstrikeThinkingEnabled: thinkingEnabled,
23
46
  reasoning_effort: reasoningEffort,
24
47
  extra_body: { thinking: { type: thinking } },
25
- });
48
+ };
49
+ if (this.circuit.isOpen())
50
+ throw new Error("Circuit breaker open");
51
+ const msgs = this.buildChatMessages(context, requestExtensions);
52
+ let lastErr;
53
+ for (let i = 0; i < this.maxRetries; i++) {
54
+ try {
55
+ const resp = await this.client.chat.completions.create({
56
+ ...this.requestExtensions(requestExtensions),
57
+ model: this.model,
58
+ messages: msgs,
59
+ ...(tools.length ? { tools: this.chat.buildTools(tools) } : {}),
60
+ });
61
+ this.circuit.recordSuccess();
62
+ const choice = resp.choices[0].message;
63
+ const nativeToolCalls = choice.tool_calls ?? [];
64
+ const toolCalls = this.chat.normalizeToolCalls(nativeToolCalls);
65
+ const content = choice.content ?? "";
66
+ this.rememberDeepSeekReplay(content, toolCalls, choice.reasoning_content, nativeToolCalls);
67
+ return { role: "assistant", content, tokenCount: resp.usage?.completion_tokens ?? resp.usage?.total_tokens, toolCalls };
68
+ }
69
+ catch (err) {
70
+ lastErr = err;
71
+ this.circuit.recordFailure();
72
+ if (i < this.maxRetries - 1)
73
+ await new Promise(r => setTimeout(r, this.baseDelay * 2 ** i));
74
+ }
75
+ }
76
+ throw lastErr;
26
77
  }
27
78
  async *stream(context, tools, extensions) {
28
79
  const exposeReasoning = extensions?.exposeReasoning ?? false;
29
80
  const thinking = extensions?.thinking === false ? "disabled" : "enabled";
30
81
  const reasoningEffort = extensions?.reasoningEffort === "max" ? "max" : "high";
31
- const msgs = this.chat.buildMessages(context);
82
+ const msgs = this.buildChatMessages(context, extensions);
32
83
  const toolCallBufs = {};
33
84
  const emittedToolCallIndexes = new Set();
34
85
  let reasoningContent = "";
@@ -36,7 +87,7 @@ export class DeepSeekProvider extends OpenAIChatProvider {
36
87
  const stream = await this.client.chat.completions.create({
37
88
  ...omitExtensionKeys(extensions, [
38
89
  "model", "messages", "tools", "stream", "stream_options", "extra_body", "reasoning_effort",
39
- "exposeReasoning", "thinking", "reasoningEffort",
90
+ "exposeReasoning", "thinking", "reasoningEffort", "__deepstrikeThinkingEnabled",
40
91
  ]),
41
92
  model: this.model,
42
93
  messages: msgs,
@@ -83,7 +134,7 @@ export class DeepSeekProvider extends OpenAIChatProvider {
83
134
  const toolCalls = Object.values(toolCallBufs).map(tb => ({
84
135
  id: tb.id, name: tb.name, arguments: tb.argsBuf || "{}",
85
136
  }));
86
- this.chat.rememberReplayFields({ content: finalText, toolCalls }, { reasoning_content: reasoningContent });
137
+ this.rememberDeepSeekReplay(finalText, toolCalls, reasoningContent, nativeToolCallsFromBuffers(toolCallBufs));
87
138
  for (const [index, tb] of Object.entries(toolCallBufs)) {
88
139
  const idx = Number(index);
89
140
  if (emittedToolCallIndexes.has(idx))
@@ -103,9 +154,7 @@ export class DeepSeekProvider extends OpenAIChatProvider {
103
154
  const toolCalls = Object.values(toolCallBufs).map(tb => ({
104
155
  id: tb.id, name: tb.name, arguments: tb.argsBuf || "{}",
105
156
  }));
106
- if (toolCalls.length || reasoningContent) {
107
- this.chat.rememberReplayFields({ content: finalText, toolCalls }, { reasoning_content: reasoningContent });
108
- }
157
+ this.rememberDeepSeekReplay(finalText, toolCalls, reasoningContent, nativeToolCallsFromBuffers(toolCallBufs));
109
158
  for (const [index, tb] of Object.entries(toolCallBufs)) {
110
159
  const idx = Number(index);
111
160
  if (emittedToolCallIndexes.has(idx))
@@ -123,4 +172,23 @@ export class DeepSeekProvider extends OpenAIChatProvider {
123
172
  if (totalTokens > 0)
124
173
  yield { type: "usage", totalTokens, inputTokens, outputTokens };
125
174
  }
175
+ rememberDeepSeekReplay(content, toolCalls, reasoningContent, nativeToolCalls) {
176
+ if (typeof reasoningContent !== "string" || !reasoningContent.trim())
177
+ return;
178
+ this.chat.rememberReplayFields({ content, toolCalls }, {
179
+ schema_version: 2,
180
+ provider: "deepseek",
181
+ protocol: "openai-chat",
182
+ model: this.model,
183
+ reasoning_content: reasoningContent,
184
+ ...(nativeToolCalls.length ? { tool_calls: nativeToolCalls } : {}),
185
+ });
186
+ }
187
+ }
188
+ function nativeToolCallsFromBuffers(toolCallBufs) {
189
+ return Object.values(toolCallBufs).map(tb => ({
190
+ id: tb.id,
191
+ type: "function",
192
+ function: { name: tb.name, arguments: tb.argsBuf || "{}" },
193
+ }));
126
194
  }
@@ -1,4 +1,4 @@
1
- import type { RuntimePolicy } from "../types.js";
1
+ import type { ProviderDescriptor, RuntimePolicy } from "../types.js";
2
2
  import { OpenAIChatProvider } from "./openai.js";
3
3
  export declare class GLMProvider extends OpenAIChatProvider {
4
4
  constructor(apiKey: string, model?: string, retry?: {
@@ -6,4 +6,5 @@ export declare class GLMProvider extends OpenAIChatProvider {
6
6
  baseDelay: number;
7
7
  }, baseURL?: string);
8
8
  runtimePolicy(): RuntimePolicy;
9
+ descriptor(): ProviderDescriptor;
9
10
  }
@@ -18,4 +18,11 @@ export class GLMProvider extends OpenAIChatProvider {
18
18
  runtimePolicy() {
19
19
  return GLM_POLICIES[this.model] ?? {};
20
20
  }
21
+ descriptor() {
22
+ return {
23
+ ...super.descriptor(),
24
+ provider: "glm",
25
+ model: this.model,
26
+ };
27
+ }
21
28
  }
@@ -1,4 +1,4 @@
1
- import type { RuntimePolicy } from "../types.js";
1
+ import type { ProviderDescriptor, RuntimePolicy } from "../types.js";
2
2
  import { OpenAIChatProvider } from "./openai.js";
3
3
  export declare class KimiProvider extends OpenAIChatProvider {
4
4
  constructor(apiKey: string, model?: string, retry?: {
@@ -6,4 +6,5 @@ export declare class KimiProvider extends OpenAIChatProvider {
6
6
  baseDelay: number;
7
7
  }, baseURL?: string);
8
8
  runtimePolicy(): RuntimePolicy;
9
+ descriptor(): ProviderDescriptor;
9
10
  }
@@ -17,4 +17,11 @@ export class KimiProvider extends OpenAIChatProvider {
17
17
  runtimePolicy() {
18
18
  return KIMI_POLICIES[this.model] ?? {};
19
19
  }
20
+ descriptor() {
21
+ return {
22
+ ...super.descriptor(),
23
+ provider: "kimi",
24
+ model: this.model,
25
+ };
26
+ }
20
27
  }
@@ -1,9 +1,35 @@
1
- import type { RuntimePolicy } from "../types.js";
1
+ import type { Message, ProviderDescriptor, RenderedContext, RuntimePolicy, StreamEvent, ToolSchema } from "../types.js";
2
2
  import { AnthropicProvider } from "./anthropic.js";
3
- export declare class MiniMaxProvider extends AnthropicProvider {
3
+ import { OpenAIChatProvider } from "./openai.js";
4
+ /**
5
+ * MiniMax over its Anthropic-compatible endpoint. Replay is carried as Anthropic
6
+ * `native_blocks` (thinking/text/tool_use), identical to the first-party
7
+ * Anthropic provider.
8
+ */
9
+ export declare class MiniMaxAnthropicProvider extends AnthropicProvider {
4
10
  constructor(apiKey: string, model?: string, retry?: {
5
11
  maxRetries: number;
6
12
  baseDelay: number;
7
13
  }, baseURL?: string);
14
+ protected providerName(): string;
8
15
  runtimePolicy(): RuntimePolicy;
9
16
  }
17
+ /**
18
+ * MiniMax over its OpenAI-compatible endpoint. Replay is carried as
19
+ * `reasoning_content` / `reasoning_details` (split reasoning), and requests
20
+ * default to `reasoning_split: true` so reasoning is returned out-of-band rather
21
+ * than embedded in the message content.
22
+ */
23
+ export declare class MiniMaxOpenAIProvider extends OpenAIChatProvider {
24
+ constructor(apiKey: string, model?: string, retry?: {
25
+ maxRetries: number;
26
+ baseDelay: number;
27
+ }, baseURL?: string);
28
+ runtimePolicy(): RuntimePolicy;
29
+ descriptor(): ProviderDescriptor;
30
+ protected requireNonEmptyReasoningReplayForToolTurns(extensions?: Record<string, unknown>): boolean;
31
+ private buildRequestExtensions;
32
+ complete(context: RenderedContext, tools: ToolSchema[], extensions?: Record<string, unknown>): Promise<Message>;
33
+ stream(context: RenderedContext, tools: ToolSchema[], extensions?: Record<string, unknown>): AsyncIterable<StreamEvent>;
34
+ private rememberMiniMaxReplay;
35
+ }