@deepstrike/sdk 0.2.6 → 0.2.8
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/dist/index.d.ts +8 -4
- package/dist/index.js +5 -2
- package/dist/kernel.d.ts +54 -0
- package/dist/kernel.js +8 -0
- package/dist/providers/anthropic.d.ts +4 -1
- package/dist/providers/anthropic.js +51 -0
- package/dist/providers/base.d.ts +6 -0
- package/dist/providers/base.js +10 -1
- package/dist/providers/catalog.js +5 -2
- package/dist/providers/deepseek.d.ts +4 -1
- package/dist/providers/deepseek.js +79 -8
- package/dist/providers/glm.d.ts +2 -1
- package/dist/providers/glm.js +7 -0
- package/dist/providers/kimi.d.ts +2 -1
- package/dist/providers/kimi.js +7 -0
- package/dist/providers/minimax.d.ts +28 -2
- package/dist/providers/minimax.js +200 -1
- package/dist/providers/openai-chat.d.ts +18 -2
- package/dist/providers/openai-chat.js +37 -3
- package/dist/providers/openai.d.ts +14 -1
- package/dist/providers/openai.js +48 -7
- package/dist/providers/profiles.d.ts +6 -0
- package/dist/providers/profiles.js +6 -0
- package/dist/providers/qwen.d.ts +3 -1
- package/dist/providers/qwen.js +20 -2
- package/dist/providers/replay-validator.d.ts +32 -0
- package/dist/providers/replay-validator.js +90 -0
- package/dist/runtime/kernel-event-log.js +22 -0
- package/dist/runtime/kernel-step.d.ts +13 -0
- package/dist/runtime/provider-replay.d.ts +16 -1
- package/dist/runtime/provider-replay.js +47 -4
- package/dist/runtime/runner.d.ts +22 -1
- package/dist/runtime/runner.js +68 -2
- package/dist/runtime/session-log.d.ts +22 -0
- package/dist/runtime/session-repair.d.ts +26 -3
- package/dist/runtime/session-repair.js +33 -32
- package/dist/types/agent.d.ts +50 -0
- package/dist/types/agent.js +110 -0
- package/dist/types.d.ts +38 -0
- 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 {
|
|
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";
|
|
@@ -41,6 +43,8 @@ export { endpointProfiles, modelProfiles, getModelProfile } from "./providers/pr
|
|
|
41
43
|
export type { ModelProfileId, ProviderId } from "./providers/profiles.js";
|
|
42
44
|
export { createProvider } from "./providers/catalog.js";
|
|
43
45
|
export type { CreateProviderOptions, EndpointProfileId } from "./providers/catalog.js";
|
|
46
|
+
export { ProviderReplayValidationError, DEGRADED_REASONING_PLACEHOLDER } from "./providers/replay-validator.js";
|
|
47
|
+
export { assessProviderReplayability, peekProviderReplay, seedProviderReplayFromEvents, isReplayCompatibleWithProvider, } from "./runtime/provider-replay.js";
|
|
44
48
|
export { tool, streamingTool, executeTools, readFile, validateToolArguments } from "./tools/index.js";
|
|
45
49
|
export type { RegisteredTool } from "./tools/index.js";
|
|
46
50
|
export { scanSkillDir, readSkillFile } from "./skills/loader.js";
|
|
@@ -57,9 +61,9 @@ export { Governance, governancePolicyToKernelEvent } from "./governance.js";
|
|
|
57
61
|
export type { GovernanceVerdict, GovernancePolicy, GovernanceConstraint } from "./governance.js";
|
|
58
62
|
export { SinglePassHarness, EvalLoopHarness, HarnessLoop } from "./harness/harness.js";
|
|
59
63
|
export type { HarnessRequest, HarnessOutcome, HarnessLoopOptions, QualityGate } from "./harness/harness.js";
|
|
60
|
-
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";
|
|
64
|
+
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, ReplayabilityAssessment, } from "./types.js";
|
|
65
|
+
export type { AgentCapabilityFilter, AgentIdentity, AgentIsolation, AgentRunSpec, AgentProcessChangedObservation, ContextInheritance, KernelAgentRole, LoopResult, MilestoneCheckResult, MilestoneContract, MilestonePhase, MilestonePolicy, SubAgentResult, TerminationReason, WorkflowSpec, WorkflowNodeSpec, WorkflowTaskSpec, WorkflowSpawnInfo, } from "./types/agent.js";
|
|
66
|
+
export { agentIdentitySub, agentRunSpecToKernel, milestoneCheckFail, milestoneCheckPass, milestoneCheckResultToKernel, subAgentResultToKernel, workflowSpecToKernel, fanoutSynthesize, generateAndFilter, verifyRules, } from "./types/agent.js";
|
|
63
67
|
export type { AcceptanceCriterion, VerificationContract, ContractCheckResult, } from "./collaboration/contract.js";
|
|
64
68
|
export { ContractBuilder, formatContractForSystemPrompt, contractToCriteriaStrings, } from "./collaboration/contract.js";
|
|
65
69
|
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,13 +21,15 @@ 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 {
|
|
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";
|
|
27
28
|
export { OpenAIResponsesAdapter, OpenAIResponsesProvider } from "./providers/openai-responses.js";
|
|
28
29
|
export { endpointProfiles, modelProfiles, getModelProfile } from "./providers/profiles.js";
|
|
29
30
|
export { createProvider } from "./providers/catalog.js";
|
|
31
|
+
export { ProviderReplayValidationError, DEGRADED_REASONING_PLACEHOLDER } from "./providers/replay-validator.js";
|
|
32
|
+
export { assessProviderReplayability, peekProviderReplay, seedProviderReplayFromEvents, isReplayCompatibleWithProvider, } from "./runtime/provider-replay.js";
|
|
30
33
|
// ── Tools & Skills ─────────────────────────────────────────────────────────
|
|
31
34
|
export { tool, streamingTool, executeTools, readFile, validateToolArguments } from "./tools/index.js";
|
|
32
35
|
export { scanSkillDir, readSkillFile } from "./skills/loader.js";
|
|
@@ -39,7 +42,7 @@ export { PermissionManager, PermissionMode } from "./safety/permissions.js";
|
|
|
39
42
|
export { Governance, governancePolicyToKernelEvent } from "./governance.js";
|
|
40
43
|
// ── Harness ────────────────────────────────────────────────────────────────
|
|
41
44
|
export { SinglePassHarness, EvalLoopHarness, HarnessLoop } from "./harness/harness.js";
|
|
42
|
-
export { agentIdentitySub, agentRunSpecToKernel, milestoneCheckFail, milestoneCheckPass, milestoneCheckResultToKernel, subAgentResultToKernel, } from "./types/agent.js";
|
|
45
|
+
export { agentIdentitySub, agentRunSpecToKernel, milestoneCheckFail, milestoneCheckPass, milestoneCheckResultToKernel, subAgentResultToKernel, workflowSpecToKernel, fanoutSynthesize, generateAndFilter, verifyRules, } from "./types/agent.js";
|
|
43
46
|
export { ContractBuilder, formatContractForSystemPrompt, contractToCriteriaStrings, } from "./collaboration/contract.js";
|
|
44
47
|
export { AgentPool } from "./collaboration/pool.js";
|
|
45
48
|
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
|
+
}
|
package/dist/providers/base.d.ts
CHANGED
|
@@ -9,6 +9,12 @@ export declare class CircuitBreaker {
|
|
|
9
9
|
recordSuccess(): void;
|
|
10
10
|
recordFailure(): void;
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Internal control flags that steer DeepStrike's own serialization/validation
|
|
14
|
+
* and must never be forwarded to any provider's wire request, regardless of the
|
|
15
|
+
* per-call omit list.
|
|
16
|
+
*/
|
|
17
|
+
export declare const INTERNAL_EXTENSION_KEYS: readonly string[];
|
|
12
18
|
export declare function omitExtensionKeys(extensions: Record<string, unknown> | undefined, keys: readonly string[]): Record<string, unknown>;
|
|
13
19
|
export declare function normalizeToolCall(id: string, name: string, args: unknown): {
|
|
14
20
|
id: string;
|
package/dist/providers/base.js
CHANGED
|
@@ -26,10 +26,19 @@ export class CircuitBreaker {
|
|
|
26
26
|
this.openedAt = Date.now();
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Internal control flags that steer DeepStrike's own serialization/validation
|
|
31
|
+
* and must never be forwarded to any provider's wire request, regardless of the
|
|
32
|
+
* per-call omit list.
|
|
33
|
+
*/
|
|
34
|
+
export const INTERNAL_EXTENSION_KEYS = [
|
|
35
|
+
"__deepstrikeThinkingEnabled",
|
|
36
|
+
"degradeMissingReasoningReplay",
|
|
37
|
+
];
|
|
29
38
|
export function omitExtensionKeys(extensions, keys) {
|
|
30
39
|
if (!extensions)
|
|
31
40
|
return {};
|
|
32
|
-
const blocked = new Set(keys);
|
|
41
|
+
const blocked = new Set([...keys, ...INTERNAL_EXTENSION_KEYS]);
|
|
33
42
|
return Object.fromEntries(Object.entries(extensions).filter(([key]) => !blocked.has(key)));
|
|
34
43
|
}
|
|
35
44
|
export function normalizeToolCall(id, name, args) {
|
|
@@ -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 {
|
|
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
|
|
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,74 @@ 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
|
-
|
|
43
|
+
const requestExtensions = {
|
|
22
44
|
...omitExtensionKeys(extensions, ["thinking", "reasoningEffort", "exposeReasoning", "extra_body", "reasoning_effort"]),
|
|
45
|
+
__deepstrikeThinkingEnabled: thinkingEnabled,
|
|
46
|
+
// Re-thread the degrade control flag (omitExtensionKeys strips internal
|
|
47
|
+
// keys) so buildChatMessages can honor it; the wire-request omit drops it.
|
|
48
|
+
...(extensions?.degradeMissingReasoningReplay === true ? { degradeMissingReasoningReplay: true } : {}),
|
|
23
49
|
reasoning_effort: reasoningEffort,
|
|
24
50
|
extra_body: { thinking: { type: thinking } },
|
|
25
|
-
}
|
|
51
|
+
};
|
|
52
|
+
if (this.circuit.isOpen())
|
|
53
|
+
throw new Error("Circuit breaker open");
|
|
54
|
+
const msgs = this.buildChatMessages(context, requestExtensions);
|
|
55
|
+
let lastErr;
|
|
56
|
+
for (let i = 0; i < this.maxRetries; i++) {
|
|
57
|
+
try {
|
|
58
|
+
const resp = await this.client.chat.completions.create({
|
|
59
|
+
...this.requestExtensions(requestExtensions),
|
|
60
|
+
model: this.model,
|
|
61
|
+
messages: msgs,
|
|
62
|
+
...(tools.length ? { tools: this.chat.buildTools(tools) } : {}),
|
|
63
|
+
});
|
|
64
|
+
this.circuit.recordSuccess();
|
|
65
|
+
const choice = resp.choices[0].message;
|
|
66
|
+
const nativeToolCalls = choice.tool_calls ?? [];
|
|
67
|
+
const toolCalls = this.chat.normalizeToolCalls(nativeToolCalls);
|
|
68
|
+
const content = choice.content ?? "";
|
|
69
|
+
this.rememberDeepSeekReplay(content, toolCalls, choice.reasoning_content, nativeToolCalls);
|
|
70
|
+
return { role: "assistant", content, tokenCount: resp.usage?.completion_tokens ?? resp.usage?.total_tokens, toolCalls };
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
lastErr = err;
|
|
74
|
+
this.circuit.recordFailure();
|
|
75
|
+
if (i < this.maxRetries - 1)
|
|
76
|
+
await new Promise(r => setTimeout(r, this.baseDelay * 2 ** i));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
throw lastErr;
|
|
26
80
|
}
|
|
27
81
|
async *stream(context, tools, extensions) {
|
|
28
82
|
const exposeReasoning = extensions?.exposeReasoning ?? false;
|
|
29
83
|
const thinking = extensions?.thinking === false ? "disabled" : "enabled";
|
|
30
84
|
const reasoningEffort = extensions?.reasoningEffort === "max" ? "max" : "high";
|
|
31
|
-
const msgs = this.
|
|
85
|
+
const msgs = this.buildChatMessages(context, extensions);
|
|
32
86
|
const toolCallBufs = {};
|
|
33
87
|
const emittedToolCallIndexes = new Set();
|
|
34
88
|
let reasoningContent = "";
|
|
@@ -36,7 +90,7 @@ export class DeepSeekProvider extends OpenAIChatProvider {
|
|
|
36
90
|
const stream = await this.client.chat.completions.create({
|
|
37
91
|
...omitExtensionKeys(extensions, [
|
|
38
92
|
"model", "messages", "tools", "stream", "stream_options", "extra_body", "reasoning_effort",
|
|
39
|
-
"exposeReasoning", "thinking", "reasoningEffort",
|
|
93
|
+
"exposeReasoning", "thinking", "reasoningEffort", "__deepstrikeThinkingEnabled",
|
|
40
94
|
]),
|
|
41
95
|
model: this.model,
|
|
42
96
|
messages: msgs,
|
|
@@ -83,7 +137,7 @@ export class DeepSeekProvider extends OpenAIChatProvider {
|
|
|
83
137
|
const toolCalls = Object.values(toolCallBufs).map(tb => ({
|
|
84
138
|
id: tb.id, name: tb.name, arguments: tb.argsBuf || "{}",
|
|
85
139
|
}));
|
|
86
|
-
this.
|
|
140
|
+
this.rememberDeepSeekReplay(finalText, toolCalls, reasoningContent, nativeToolCallsFromBuffers(toolCallBufs));
|
|
87
141
|
for (const [index, tb] of Object.entries(toolCallBufs)) {
|
|
88
142
|
const idx = Number(index);
|
|
89
143
|
if (emittedToolCallIndexes.has(idx))
|
|
@@ -103,9 +157,7 @@ export class DeepSeekProvider extends OpenAIChatProvider {
|
|
|
103
157
|
const toolCalls = Object.values(toolCallBufs).map(tb => ({
|
|
104
158
|
id: tb.id, name: tb.name, arguments: tb.argsBuf || "{}",
|
|
105
159
|
}));
|
|
106
|
-
|
|
107
|
-
this.chat.rememberReplayFields({ content: finalText, toolCalls }, { reasoning_content: reasoningContent });
|
|
108
|
-
}
|
|
160
|
+
this.rememberDeepSeekReplay(finalText, toolCalls, reasoningContent, nativeToolCallsFromBuffers(toolCallBufs));
|
|
109
161
|
for (const [index, tb] of Object.entries(toolCallBufs)) {
|
|
110
162
|
const idx = Number(index);
|
|
111
163
|
if (emittedToolCallIndexes.has(idx))
|
|
@@ -123,4 +175,23 @@ export class DeepSeekProvider extends OpenAIChatProvider {
|
|
|
123
175
|
if (totalTokens > 0)
|
|
124
176
|
yield { type: "usage", totalTokens, inputTokens, outputTokens };
|
|
125
177
|
}
|
|
178
|
+
rememberDeepSeekReplay(content, toolCalls, reasoningContent, nativeToolCalls) {
|
|
179
|
+
if (typeof reasoningContent !== "string" || !reasoningContent.trim())
|
|
180
|
+
return;
|
|
181
|
+
this.chat.rememberReplayFields({ content, toolCalls }, {
|
|
182
|
+
schema_version: 2,
|
|
183
|
+
provider: "deepseek",
|
|
184
|
+
protocol: "openai-chat",
|
|
185
|
+
model: this.model,
|
|
186
|
+
reasoning_content: reasoningContent,
|
|
187
|
+
...(nativeToolCalls.length ? { tool_calls: nativeToolCalls } : {}),
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
function nativeToolCallsFromBuffers(toolCallBufs) {
|
|
192
|
+
return Object.values(toolCallBufs).map(tb => ({
|
|
193
|
+
id: tb.id,
|
|
194
|
+
type: "function",
|
|
195
|
+
function: { name: tb.name, arguments: tb.argsBuf || "{}" },
|
|
196
|
+
}));
|
|
126
197
|
}
|
package/dist/providers/glm.d.ts
CHANGED
|
@@ -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
|
}
|
package/dist/providers/glm.js
CHANGED
package/dist/providers/kimi.d.ts
CHANGED
|
@@ -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
|
}
|
package/dist/providers/kimi.js
CHANGED
|
@@ -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
|
-
|
|
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
|
+
}
|