@deepstrike/sdk 0.1.12 → 0.1.14
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 +82 -52
- package/dist/collaboration/harness.js +6 -1
- package/dist/collaboration/modes/creator-verifier.d.ts +2 -2
- package/dist/collaboration/modes/creator-verifier.js +2 -2
- package/dist/collaboration/pool.d.ts +4 -35
- package/dist/collaboration/pool.js +18 -44
- package/dist/harness/harness.d.ts +19 -7
- package/dist/harness/harness.js +27 -22
- package/dist/index.d.ts +19 -7
- package/dist/index.js +15 -3
- package/dist/kernel.d.ts +1 -0
- package/dist/kernel.js +10 -1
- package/dist/memory/protocols.d.ts +0 -4
- package/dist/providers/anthropic.d.ts +7 -2
- package/dist/providers/anthropic.js +48 -9
- package/dist/providers/base.d.ts +1 -0
- package/dist/providers/base.js +6 -0
- package/dist/providers/deepseek.d.ts +4 -2
- package/dist/providers/deepseek.js +49 -1
- package/dist/providers/gemini.d.ts +4 -2
- package/dist/providers/gemini.js +24 -5
- package/dist/providers/kimi.d.ts +3 -1
- package/dist/providers/kimi.js +10 -0
- package/dist/providers/minimax.d.ts +3 -1
- package/dist/providers/minimax.js +8 -0
- package/dist/providers/ollama.d.ts +5 -2
- package/dist/providers/ollama.js +63 -7
- package/dist/providers/openai-responses.d.ts +4 -2
- package/dist/providers/openai-responses.js +23 -3
- package/dist/providers/openai.d.ts +4 -2
- package/dist/providers/openai.js +44 -3
- package/dist/providers/profiles.d.ts +502 -6
- package/dist/providers/profiles.js +225 -82
- package/dist/providers/qwen.d.ts +5 -2
- package/dist/providers/qwen.js +59 -11
- package/dist/runtime/credential-vault.d.ts +18 -0
- package/dist/runtime/credential-vault.js +33 -0
- package/dist/runtime/execution-plane.d.ts +38 -0
- package/dist/runtime/execution-plane.js +146 -0
- package/dist/runtime/mcp-proxy-plane.d.ts +51 -0
- package/dist/runtime/mcp-proxy-plane.js +204 -0
- package/dist/runtime/process-sandbox-plane.d.ts +32 -0
- package/dist/runtime/process-sandbox-plane.js +109 -0
- package/dist/runtime/remote-vpc-plane.d.ts +48 -0
- package/dist/runtime/remote-vpc-plane.js +82 -0
- package/dist/runtime/runner.d.ts +49 -0
- package/dist/runtime/runner.js +364 -0
- package/dist/runtime/session-log.d.ts +67 -0
- package/dist/runtime/session-log.js +84 -0
- package/dist/tools/index.d.ts +7 -2
- package/dist/tools/index.js +83 -0
- package/dist/types.d.ts +52 -1
- package/package.json +3 -2
- package/dist/agent.d.ts +0 -88
- package/dist/agent.js +0 -430
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export type {
|
|
1
|
+
export { RuntimeRunner, collectText } from "./runtime/runner.js";
|
|
2
|
+
export type { RuntimeOptions } from "./runtime/runner.js";
|
|
3
|
+
export { LocalExecutionPlane } from "./runtime/execution-plane.js";
|
|
4
|
+
export type { ExecutionPlane, RunContext } from "./runtime/execution-plane.js";
|
|
5
|
+
export { InMemorySessionLog, FileSessionLog } from "./runtime/session-log.js";
|
|
6
|
+
export type { SessionLog, SessionEvent } from "./runtime/session-log.js";
|
|
7
|
+
export { EnvCredentialVault, InMemoryCredentialVault, ChainedCredentialVault } from "./runtime/credential-vault.js";
|
|
8
|
+
export type { CredentialVault } from "./runtime/credential-vault.js";
|
|
9
|
+
export { ProcessSandboxPlane } from "./runtime/process-sandbox-plane.js";
|
|
10
|
+
export type { SandboxOptions } from "./runtime/process-sandbox-plane.js";
|
|
11
|
+
export { McpProxyPlane } from "./runtime/mcp-proxy-plane.js";
|
|
12
|
+
export type { McpServerConfig } from "./runtime/mcp-proxy-plane.js";
|
|
13
|
+
export { RemoteVpcPlane } from "./runtime/remote-vpc-plane.js";
|
|
14
|
+
export type { RemoteVpcOptions } from "./runtime/remote-vpc-plane.js";
|
|
3
15
|
export { AnthropicProvider } from "./providers/anthropic.js";
|
|
4
16
|
export { OpenAIChatProvider, OpenAIProvider } from "./providers/openai.js";
|
|
5
17
|
export { DeepSeekProvider } from "./providers/deepseek.js";
|
|
@@ -15,15 +27,13 @@ export type { OpenAIResponsesRunState } from "./providers/openai-responses.js";
|
|
|
15
27
|
export { endpointProfiles, modelProfiles, getModelProfile } from "./providers/profiles.js";
|
|
16
28
|
export { createProvider } from "./providers/catalog.js";
|
|
17
29
|
export type { CreateProviderOptions, EndpointProfileId } from "./providers/catalog.js";
|
|
18
|
-
export { tool, executeTools, readFile } from "./tools/index.js";
|
|
30
|
+
export { tool, streamingTool, executeTools, readFile, validateToolArguments } from "./tools/index.js";
|
|
19
31
|
export type { RegisteredTool } from "./tools/index.js";
|
|
20
32
|
export { scanSkillDir, readSkillFile } from "./skills/loader.js";
|
|
21
33
|
export type { SkillMetadata } from "./skills/loader.js";
|
|
22
34
|
export { WorkingMemory } from "./memory/working.js";
|
|
23
|
-
export type { DreamStore, DreamResult,
|
|
35
|
+
export type { DreamStore, DreamResult, SessionData, SessionMessage, MemoryEntry, CurationResult, CurationStats, } from "./memory/protocols.js";
|
|
24
36
|
export type { KnowledgeSource } from "./knowledge/source.js";
|
|
25
|
-
export { SinglePassHarness, EvalLoopHarness, HarnessLoop } from "./harness/harness.js";
|
|
26
|
-
export type { HarnessRequest, HarnessOutcome, HarnessLoopOptions, QualityGate } from "./harness/harness.js";
|
|
27
37
|
export { ScheduledPrompt } from "./signals/scheduled.js";
|
|
28
38
|
export { SignalGateway } from "./signals/gateway.js";
|
|
29
39
|
export type { RuntimeSignal, SignalSource } from "./signals/types.js";
|
|
@@ -31,7 +41,9 @@ export { PermissionManager, PermissionMode } from "./safety/permissions.js";
|
|
|
31
41
|
export type { PermissionDecision, Permission } from "./safety/permissions.js";
|
|
32
42
|
export { Governance } from "./governance.js";
|
|
33
43
|
export type { GovernanceVerdict } from "./governance.js";
|
|
34
|
-
export
|
|
44
|
+
export { SinglePassHarness, EvalLoopHarness, HarnessLoop } from "./harness/harness.js";
|
|
45
|
+
export type { HarnessRequest, HarnessOutcome, HarnessLoopOptions, QualityGate } from "./harness/harness.js";
|
|
46
|
+
export type { Message, ToolCall, ToolResult, ToolSchema, ContentPart, TextPart, ImagePart, AudioPart, StreamEvent, TextDelta, ThinkingDelta, ToolCallEvent, ToolChunk, ToolDeltaEvent, ToolSuspendEvent, ToolResultEvent, DoneEvent, ErrorEvent, PermissionRequestEvent, LLMProvider, RetryConfig, TokenUsage, ProviderToolSpec, ProviderRunState, RenderedContext, } from "./types.js";
|
|
35
47
|
export type { AcceptanceCriterion, VerificationContract, ContractCheckResult, } from "./collaboration/contract.js";
|
|
36
48
|
export { ContractBuilder, formatContractForSystemPrompt, contractToCriteriaStrings, } from "./collaboration/contract.js";
|
|
37
49
|
export { AgentPool } from "./collaboration/pool.js";
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
// ── Runtime (Layer 1.5) ────────────────────────────────────────────────────
|
|
2
|
+
export { RuntimeRunner, collectText } from "./runtime/runner.js";
|
|
3
|
+
export { LocalExecutionPlane } from "./runtime/execution-plane.js";
|
|
4
|
+
export { InMemorySessionLog, FileSessionLog } from "./runtime/session-log.js";
|
|
5
|
+
export { EnvCredentialVault, InMemoryCredentialVault, ChainedCredentialVault } from "./runtime/credential-vault.js";
|
|
6
|
+
export { ProcessSandboxPlane } from "./runtime/process-sandbox-plane.js";
|
|
7
|
+
export { McpProxyPlane } from "./runtime/mcp-proxy-plane.js";
|
|
8
|
+
export { RemoteVpcPlane } from "./runtime/remote-vpc-plane.js";
|
|
9
|
+
// ── Providers ─────────────────────────────────────────────────────────────
|
|
2
10
|
export { AnthropicProvider } from "./providers/anthropic.js";
|
|
3
11
|
export { OpenAIChatProvider, OpenAIProvider } from "./providers/openai.js";
|
|
4
12
|
export { DeepSeekProvider } from "./providers/deepseek.js";
|
|
@@ -12,14 +20,18 @@ export { OpenAIChatAdapter } from "./providers/openai-chat.js";
|
|
|
12
20
|
export { OpenAIResponsesAdapter, OpenAIResponsesProvider } from "./providers/openai-responses.js";
|
|
13
21
|
export { endpointProfiles, modelProfiles, getModelProfile } from "./providers/profiles.js";
|
|
14
22
|
export { createProvider } from "./providers/catalog.js";
|
|
15
|
-
|
|
23
|
+
// ── Tools & Skills ─────────────────────────────────────────────────────────
|
|
24
|
+
export { tool, streamingTool, executeTools, readFile, validateToolArguments } from "./tools/index.js";
|
|
16
25
|
export { scanSkillDir, readSkillFile } from "./skills/loader.js";
|
|
26
|
+
// ── Memory ─────────────────────────────────────────────────────────────────
|
|
17
27
|
export { WorkingMemory } from "./memory/working.js";
|
|
18
|
-
export { SinglePassHarness, EvalLoopHarness, HarnessLoop } from "./harness/harness.js";
|
|
19
28
|
export { ScheduledPrompt } from "./signals/scheduled.js";
|
|
20
29
|
export { SignalGateway } from "./signals/gateway.js";
|
|
30
|
+
// ── Safety & Governance ────────────────────────────────────────────────────
|
|
21
31
|
export { PermissionManager, PermissionMode } from "./safety/permissions.js";
|
|
22
32
|
export { Governance } from "./governance.js";
|
|
33
|
+
// ── Harness ────────────────────────────────────────────────────────────────
|
|
34
|
+
export { SinglePassHarness, EvalLoopHarness, HarnessLoop } from "./harness/harness.js";
|
|
23
35
|
export { ContractBuilder, formatContractForSystemPrompt, contractToCriteriaStrings, } from "./collaboration/contract.js";
|
|
24
36
|
export { AgentPool } from "./collaboration/pool.js";
|
|
25
37
|
export { ContractDrivenHarness } from "./collaboration/harness.js";
|
package/dist/kernel.d.ts
CHANGED
|
@@ -54,6 +54,7 @@ interface LoopStateMachineInstance {
|
|
|
54
54
|
goal: string;
|
|
55
55
|
criteria: string[];
|
|
56
56
|
}): LoopAction;
|
|
57
|
+
resumeAfterPreload(): LoopAction;
|
|
57
58
|
feedLlmResponse(message: Message): LoopAction;
|
|
58
59
|
feedToolResults(results: ToolResult[]): LoopAction;
|
|
59
60
|
feedTimeout(): LoopAction;
|
package/dist/kernel.js
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import { createRequire } from "module";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
2
5
|
const cjsRequire = createRequire(import.meta.url);
|
|
3
6
|
let cachedKernel;
|
|
7
|
+
function resolveCoreModule() {
|
|
8
|
+
const localCore = join(dirname(fileURLToPath(import.meta.url)), "../../../crates/deepstrike-node");
|
|
9
|
+
if (existsSync(join(localCore, "index.js")))
|
|
10
|
+
return localCore;
|
|
11
|
+
return "@deepstrike/core";
|
|
12
|
+
}
|
|
4
13
|
export function getKernel() {
|
|
5
14
|
if (!cachedKernel) {
|
|
6
|
-
cachedKernel = cjsRequire(
|
|
15
|
+
cachedKernel = cjsRequire(resolveCoreModule());
|
|
7
16
|
}
|
|
8
17
|
return cachedKernel;
|
|
9
18
|
}
|
|
@@ -46,10 +46,6 @@ export interface DreamStore {
|
|
|
46
46
|
saveSession(data: SessionData): Promise<void>;
|
|
47
47
|
}
|
|
48
48
|
/** Durable transcript storage for same-session conversational continuity. */
|
|
49
|
-
export interface SessionStore {
|
|
50
|
-
loadSession(sessionId: string): Promise<SessionData | undefined>;
|
|
51
|
-
saveSession(data: SessionData): Promise<void>;
|
|
52
|
-
}
|
|
53
49
|
export interface DreamResult {
|
|
54
50
|
sessionsProcessed: number;
|
|
55
51
|
insightsExtracted: number;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Message, RenderedContext, ToolSchema, StreamEvent, LLMProvider } from "../types.js";
|
|
1
|
+
import type { Message, RenderedContext, ToolSchema, StreamEvent, LLMProvider, RuntimePolicy } from "../types.js";
|
|
2
2
|
interface AnthropicProviderOptions {
|
|
3
3
|
baseURL?: string;
|
|
4
4
|
authMode?: "api-key" | "bearer";
|
|
@@ -14,9 +14,14 @@ export declare class AnthropicProvider implements LLMProvider {
|
|
|
14
14
|
maxRetries: number;
|
|
15
15
|
baseDelay: number;
|
|
16
16
|
}, options?: AnthropicProviderOptions);
|
|
17
|
+
runtimePolicy(): RuntimePolicy;
|
|
17
18
|
private buildTools;
|
|
18
|
-
complete(context: RenderedContext, tools: ToolSchema[]): Promise<Message>;
|
|
19
|
+
complete(context: RenderedContext, tools: ToolSchema[], extensions?: Record<string, unknown>): Promise<Message>;
|
|
19
20
|
stream(context: RenderedContext, tools: ToolSchema[], extensions?: Record<string, unknown>): AsyncIterable<StreamEvent>;
|
|
21
|
+
private requestExtensions;
|
|
22
|
+
private hasBetas;
|
|
23
|
+
private createMessage;
|
|
24
|
+
private streamMessage;
|
|
20
25
|
private buildMessages;
|
|
21
26
|
private rememberNativeBlocks;
|
|
22
27
|
private assistantReplayKey;
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import Anthropic from "@anthropic-ai/sdk";
|
|
2
2
|
import { withServerRuntimeGuard } from "../runtime/server.js";
|
|
3
|
-
import { CircuitBreaker, normalizeToolCall, toAnthropicMessages } from "./base.js";
|
|
3
|
+
import { CircuitBreaker, normalizeToolCall, omitExtensionKeys, toAnthropicMessages } from "./base.js";
|
|
4
|
+
const CLAUDE_POLICIES = {
|
|
5
|
+
"claude-opus-4-7": { maxTurns: 50 },
|
|
6
|
+
"claude-opus-4-6": { maxTurns: 50 },
|
|
7
|
+
"claude-sonnet-4-6": { maxTurns: 25 },
|
|
8
|
+
"claude-haiku-4-5": { maxTurns: 15 },
|
|
9
|
+
"claude-haiku-4-5-20251001": { maxTurns: 15 },
|
|
10
|
+
};
|
|
4
11
|
export class AnthropicProvider {
|
|
5
12
|
model;
|
|
6
13
|
client;
|
|
@@ -18,6 +25,9 @@ export class AnthropicProvider {
|
|
|
18
25
|
this.maxRetries = retry.maxRetries;
|
|
19
26
|
this.baseDelay = retry.baseDelay;
|
|
20
27
|
}
|
|
28
|
+
runtimePolicy() {
|
|
29
|
+
return CLAUDE_POLICIES[this.model] ?? {};
|
|
30
|
+
}
|
|
21
31
|
buildTools(tools) {
|
|
22
32
|
return tools.map(t => ({
|
|
23
33
|
name: t.name,
|
|
@@ -25,21 +35,23 @@ export class AnthropicProvider {
|
|
|
25
35
|
input_schema: JSON.parse(t.parameters),
|
|
26
36
|
}));
|
|
27
37
|
}
|
|
28
|
-
async complete(context, tools) {
|
|
38
|
+
async complete(context, tools, extensions) {
|
|
29
39
|
if (this.circuit.isOpen())
|
|
30
40
|
throw new Error("Circuit breaker open");
|
|
31
41
|
const system = context.systemText || undefined;
|
|
32
42
|
const msgs = this.buildMessages(context);
|
|
43
|
+
const requestExtensions = this.requestExtensions(extensions);
|
|
33
44
|
let lastErr;
|
|
34
45
|
for (let i = 0; i < this.maxRetries; i++) {
|
|
35
46
|
try {
|
|
36
|
-
const resp = await this.
|
|
47
|
+
const resp = await this.createMessage({
|
|
48
|
+
...requestExtensions,
|
|
37
49
|
model: this.model,
|
|
38
|
-
max_tokens: 8096,
|
|
50
|
+
max_tokens: typeof extensions?.max_tokens === "number" ? extensions.max_tokens : 8096,
|
|
39
51
|
...(system ? { system } : {}),
|
|
40
52
|
messages: msgs,
|
|
41
53
|
...(tools.length ? { tools: this.buildTools(tools) } : {}),
|
|
42
|
-
});
|
|
54
|
+
}, extensions);
|
|
43
55
|
this.circuit.recordSuccess();
|
|
44
56
|
let content = "";
|
|
45
57
|
const toolCalls = [];
|
|
@@ -68,19 +80,29 @@ export class AnthropicProvider {
|
|
|
68
80
|
async *stream(context, tools, extensions) {
|
|
69
81
|
const system = context.systemText || undefined;
|
|
70
82
|
const msgs = this.buildMessages(context);
|
|
83
|
+
const requestExtensions = this.requestExtensions(extensions);
|
|
71
84
|
const toolBlocks = {};
|
|
72
85
|
const nativeBlocks = {};
|
|
73
86
|
let finalText = "";
|
|
74
87
|
const finalToolCalls = [];
|
|
75
|
-
const stream = this.
|
|
88
|
+
const stream = this.streamMessage({
|
|
89
|
+
...requestExtensions,
|
|
76
90
|
model: this.model,
|
|
77
|
-
max_tokens: 8096,
|
|
91
|
+
max_tokens: typeof extensions?.max_tokens === "number" ? extensions.max_tokens : 8096,
|
|
78
92
|
...(system ? { system } : {}),
|
|
79
93
|
messages: msgs,
|
|
80
94
|
...(tools.length ? { tools: this.buildTools(tools) } : {}),
|
|
81
|
-
});
|
|
95
|
+
}, extensions);
|
|
96
|
+
let totalTokens = 0;
|
|
82
97
|
for await (const evt of stream) {
|
|
83
|
-
if (evt.type === "
|
|
98
|
+
if (evt.type === "message_start" || evt.type === "message_delta") {
|
|
99
|
+
const usage = evt.usage ?? evt.message?.usage;
|
|
100
|
+
if (usage) {
|
|
101
|
+
totalTokens = usage.input_tokens + (usage.output_tokens ?? 0);
|
|
102
|
+
yield { type: "usage", totalTokens };
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
else if (evt.type === "content_block_start") {
|
|
84
106
|
nativeBlocks[evt.index] = { ...evt.content_block };
|
|
85
107
|
if (evt.content_block.type === "tool_use") {
|
|
86
108
|
toolBlocks[evt.index] = { id: evt.content_block.id, name: evt.content_block.name, argsBuf: "" };
|
|
@@ -121,6 +143,23 @@ export class AnthropicProvider {
|
|
|
121
143
|
}
|
|
122
144
|
this.rememberNativeBlocks({ content: finalText, toolCalls: finalToolCalls }, Object.keys(nativeBlocks).map(Number).sort((a, b) => a - b).map(index => nativeBlocks[index]));
|
|
123
145
|
}
|
|
146
|
+
requestExtensions(extensions) {
|
|
147
|
+
return omitExtensionKeys(extensions, ["model", "messages", "system", "tools", "max_tokens", "stream"]);
|
|
148
|
+
}
|
|
149
|
+
hasBetas(extensions) {
|
|
150
|
+
const betas = extensions?.betas;
|
|
151
|
+
return Array.isArray(betas) && betas.length > 0;
|
|
152
|
+
}
|
|
153
|
+
createMessage(params, extensions) {
|
|
154
|
+
return this.hasBetas(extensions)
|
|
155
|
+
? this.client.beta.messages.create(params)
|
|
156
|
+
: this.client.messages.create(params);
|
|
157
|
+
}
|
|
158
|
+
streamMessage(params, extensions) {
|
|
159
|
+
return (this.hasBetas(extensions)
|
|
160
|
+
? this.client.beta.messages.stream(params)
|
|
161
|
+
: this.client.messages.stream(params));
|
|
162
|
+
}
|
|
124
163
|
buildMessages(context) {
|
|
125
164
|
return toAnthropicMessages(context.turns, message => this.nativeAssistantBlocks.get(this.assistantReplayKey(message)));
|
|
126
165
|
}
|
package/dist/providers/base.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export declare class CircuitBreaker {
|
|
|
9
9
|
recordSuccess(): void;
|
|
10
10
|
recordFailure(): void;
|
|
11
11
|
}
|
|
12
|
+
export declare function omitExtensionKeys(extensions: Record<string, unknown> | undefined, keys: readonly string[]): Record<string, unknown>;
|
|
12
13
|
export declare function normalizeToolCall(id: string, name: string, args: unknown): {
|
|
13
14
|
id: string;
|
|
14
15
|
name: string;
|
package/dist/providers/base.js
CHANGED
|
@@ -26,6 +26,12 @@ export class CircuitBreaker {
|
|
|
26
26
|
this.openedAt = Date.now();
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
+
export function omitExtensionKeys(extensions, keys) {
|
|
30
|
+
if (!extensions)
|
|
31
|
+
return {};
|
|
32
|
+
const blocked = new Set(keys);
|
|
33
|
+
return Object.fromEntries(Object.entries(extensions).filter(([key]) => !blocked.has(key)));
|
|
34
|
+
}
|
|
29
35
|
export function normalizeToolCall(id, name, args) {
|
|
30
36
|
const n = String(name ?? "").trim();
|
|
31
37
|
if (!n)
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import type { RenderedContext, ToolSchema, StreamEvent } from "../types.js";
|
|
1
|
+
import type { Message, RenderedContext, ToolSchema, StreamEvent, RuntimePolicy } from "../types.js";
|
|
2
2
|
import { OpenAIChatProvider } from "./openai.js";
|
|
3
3
|
export declare class DeepSeekProvider extends OpenAIChatProvider {
|
|
4
|
-
constructor(apiKey: string, model?:
|
|
4
|
+
constructor(apiKey: string, model?: string, retry?: {
|
|
5
5
|
maxRetries: number;
|
|
6
6
|
baseDelay: number;
|
|
7
7
|
}, baseURL?: string);
|
|
8
|
+
runtimePolicy(): RuntimePolicy;
|
|
9
|
+
complete(context: RenderedContext, tools: ToolSchema[], extensions?: Record<string, unknown>): Promise<Message>;
|
|
8
10
|
stream(context: RenderedContext, tools: ToolSchema[], extensions?: Record<string, unknown>): AsyncIterable<StreamEvent>;
|
|
9
11
|
}
|
|
@@ -1,19 +1,43 @@
|
|
|
1
1
|
import { OpenAIChatProvider } from "./openai.js";
|
|
2
2
|
import { endpointProfiles } from "./profiles.js";
|
|
3
|
+
import { omitExtensionKeys } from "./base.js";
|
|
3
4
|
const DEEPSEEK_BASE = endpointProfiles["deepseek.openai"].baseURL;
|
|
5
|
+
const DEEPSEEK_POLICIES = {
|
|
6
|
+
"deepseek-chat": { maxTurns: 25 },
|
|
7
|
+
"deepseek-reasoner": { maxTurns: 50 },
|
|
8
|
+
"deepseek-v4-flash": { maxTurns: 20 },
|
|
9
|
+
"deepseek-v4-pro": { maxTurns: 35 },
|
|
10
|
+
};
|
|
4
11
|
export class DeepSeekProvider extends OpenAIChatProvider {
|
|
5
12
|
constructor(apiKey, model = "deepseek-v4-flash", retry, baseURL = DEEPSEEK_BASE) {
|
|
6
13
|
super(apiKey, model, retry, baseURL);
|
|
7
14
|
}
|
|
15
|
+
runtimePolicy() {
|
|
16
|
+
return DEEPSEEK_POLICIES[this.model] ?? {};
|
|
17
|
+
}
|
|
18
|
+
async complete(context, tools, extensions) {
|
|
19
|
+
const thinking = extensions?.thinking === false ? "disabled" : "enabled";
|
|
20
|
+
const reasoningEffort = extensions?.reasoningEffort === "max" ? "max" : "high";
|
|
21
|
+
return super.complete(context, tools, {
|
|
22
|
+
...omitExtensionKeys(extensions, ["thinking", "reasoningEffort", "exposeReasoning", "extra_body", "reasoning_effort"]),
|
|
23
|
+
reasoning_effort: reasoningEffort,
|
|
24
|
+
extra_body: { thinking: { type: thinking } },
|
|
25
|
+
});
|
|
26
|
+
}
|
|
8
27
|
async *stream(context, tools, extensions) {
|
|
9
28
|
const exposeReasoning = extensions?.exposeReasoning ?? false;
|
|
10
29
|
const thinking = extensions?.thinking === false ? "disabled" : "enabled";
|
|
11
30
|
const reasoningEffort = extensions?.reasoningEffort === "max" ? "max" : "high";
|
|
12
31
|
const msgs = this.chat.buildMessages(context);
|
|
13
32
|
const toolCallBufs = {};
|
|
33
|
+
const emittedToolCallIndexes = new Set();
|
|
14
34
|
let reasoningContent = "";
|
|
15
35
|
let finalText = "";
|
|
16
36
|
const stream = await this.client.chat.completions.create({
|
|
37
|
+
...omitExtensionKeys(extensions, [
|
|
38
|
+
"model", "messages", "tools", "stream", "extra_body", "reasoning_effort",
|
|
39
|
+
"exposeReasoning", "thinking", "reasoningEffort",
|
|
40
|
+
]),
|
|
17
41
|
model: this.model,
|
|
18
42
|
messages: msgs,
|
|
19
43
|
...(tools.length ? { tools: this.chat.buildTools(tools) } : {}),
|
|
@@ -48,7 +72,10 @@ export class DeepSeekProvider extends OpenAIChatProvider {
|
|
|
48
72
|
id: tb.id, name: tb.name, arguments: tb.argsBuf || "{}",
|
|
49
73
|
}));
|
|
50
74
|
this.chat.rememberReplayFields({ content: finalText, toolCalls }, { reasoning_content: reasoningContent });
|
|
51
|
-
for (const tb of Object.
|
|
75
|
+
for (const [index, tb] of Object.entries(toolCallBufs)) {
|
|
76
|
+
const idx = Number(index);
|
|
77
|
+
if (emittedToolCallIndexes.has(idx))
|
|
78
|
+
continue;
|
|
52
79
|
let args = {};
|
|
53
80
|
try {
|
|
54
81
|
args = JSON.parse(tb.argsBuf || "{}");
|
|
@@ -56,9 +83,30 @@ export class DeepSeekProvider extends OpenAIChatProvider {
|
|
|
56
83
|
catch {
|
|
57
84
|
args = {};
|
|
58
85
|
}
|
|
86
|
+
emittedToolCallIndexes.add(idx);
|
|
59
87
|
yield { type: "tool_call", id: tb.id, name: tb.name, arguments: args };
|
|
60
88
|
}
|
|
61
89
|
}
|
|
62
90
|
}
|
|
91
|
+
const toolCalls = Object.values(toolCallBufs).map(tb => ({
|
|
92
|
+
id: tb.id, name: tb.name, arguments: tb.argsBuf || "{}",
|
|
93
|
+
}));
|
|
94
|
+
if (toolCalls.length) {
|
|
95
|
+
this.chat.rememberReplayFields({ content: finalText, toolCalls }, { reasoning_content: reasoningContent });
|
|
96
|
+
}
|
|
97
|
+
for (const [index, tb] of Object.entries(toolCallBufs)) {
|
|
98
|
+
const idx = Number(index);
|
|
99
|
+
if (emittedToolCallIndexes.has(idx))
|
|
100
|
+
continue;
|
|
101
|
+
let args = {};
|
|
102
|
+
try {
|
|
103
|
+
args = JSON.parse(tb.argsBuf || "{}");
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
args = {};
|
|
107
|
+
}
|
|
108
|
+
emittedToolCallIndexes.add(idx);
|
|
109
|
+
yield { type: "tool_call", id: tb.id, name: tb.name, arguments: args };
|
|
110
|
+
}
|
|
63
111
|
}
|
|
64
112
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Message, RenderedContext, ToolSchema, StreamEvent, LLMProvider } from "../types.js";
|
|
1
|
+
import type { Message, RenderedContext, ToolSchema, StreamEvent, LLMProvider, RuntimePolicy } from "../types.js";
|
|
2
2
|
export declare class GeminiProvider implements LLMProvider {
|
|
3
3
|
private readonly model;
|
|
4
4
|
private genAI;
|
|
@@ -9,6 +9,8 @@ export declare class GeminiProvider implements LLMProvider {
|
|
|
9
9
|
maxRetries: number;
|
|
10
10
|
baseDelay: number;
|
|
11
11
|
}, baseURL?: string);
|
|
12
|
-
|
|
12
|
+
runtimePolicy(): RuntimePolicy;
|
|
13
|
+
complete(context: RenderedContext, tools: ToolSchema[], extensions?: Record<string, unknown>): Promise<Message>;
|
|
13
14
|
stream(context: RenderedContext, tools: ToolSchema[], extensions?: Record<string, unknown>): AsyncIterable<StreamEvent>;
|
|
15
|
+
private modelExtensions;
|
|
14
16
|
}
|
package/dist/providers/gemini.js
CHANGED
|
@@ -3,6 +3,14 @@ import { withServerRuntimeGuard } from "../runtime/server.js";
|
|
|
3
3
|
import { CircuitBreaker, normalizeToolCall } from "./base.js";
|
|
4
4
|
import { endpointProfiles } from "./profiles.js";
|
|
5
5
|
const GEMINI_BASE = endpointProfiles["gemini.google"].baseURL;
|
|
6
|
+
const GEMINI_POLICIES = {
|
|
7
|
+
"gemini-2.5-pro": { maxTurns: 35 },
|
|
8
|
+
"gemini-2.5-flash": { maxTurns: 20 },
|
|
9
|
+
"gemini-2.0-flash": { maxTurns: 15 },
|
|
10
|
+
"gemini-2.0-flash-lite": { maxTurns: 10 },
|
|
11
|
+
"gemini-1.5-pro": { maxTurns: 30 },
|
|
12
|
+
"gemini-1.5-flash": { maxTurns: 15 },
|
|
13
|
+
};
|
|
6
14
|
function buildContents(turns) {
|
|
7
15
|
const contents = [];
|
|
8
16
|
for (const msg of turns) {
|
|
@@ -61,7 +69,10 @@ export class GeminiProvider {
|
|
|
61
69
|
this.maxRetries = retry.maxRetries;
|
|
62
70
|
this.baseDelay = retry.baseDelay;
|
|
63
71
|
}
|
|
64
|
-
|
|
72
|
+
runtimePolicy() {
|
|
73
|
+
return GEMINI_POLICIES[this.model] ?? {};
|
|
74
|
+
}
|
|
75
|
+
async complete(context, tools, extensions) {
|
|
65
76
|
if (this.circuit.isOpen())
|
|
66
77
|
throw new Error("Circuit breaker open");
|
|
67
78
|
const system = context.systemText || undefined;
|
|
@@ -71,6 +82,7 @@ export class GeminiProvider {
|
|
|
71
82
|
for (let i = 0; i < this.maxRetries; i++) {
|
|
72
83
|
try {
|
|
73
84
|
const m = this.genAI.getGenerativeModel({
|
|
85
|
+
...this.modelExtensions(extensions),
|
|
74
86
|
model: this.model,
|
|
75
87
|
...(system ? { systemInstruction: system } : {}),
|
|
76
88
|
...(geminiTools.length ? { tools: geminiTools } : {}),
|
|
@@ -111,27 +123,34 @@ export class GeminiProvider {
|
|
|
111
123
|
const contents = buildContents(context.turns);
|
|
112
124
|
const geminiTools = buildTools(tools);
|
|
113
125
|
const m = this.genAI.getGenerativeModel({
|
|
126
|
+
...this.modelExtensions(extensions),
|
|
114
127
|
model: this.model,
|
|
115
128
|
...(system ? { systemInstruction: system } : {}),
|
|
116
129
|
...(geminiTools.length ? { tools: geminiTools } : {}),
|
|
117
130
|
});
|
|
118
131
|
const result = await m.generateContentStream({ contents });
|
|
119
|
-
const
|
|
132
|
+
const toolCalls = [];
|
|
120
133
|
for await (const chunk of result.stream) {
|
|
121
134
|
for (const part of chunk.candidates?.[0]?.content.parts ?? []) {
|
|
122
135
|
if (part.text)
|
|
123
136
|
yield { type: "text_delta", delta: part.text };
|
|
124
137
|
else if (part.functionCall) {
|
|
125
138
|
const { name, args } = part.functionCall;
|
|
126
|
-
|
|
139
|
+
toolCalls.push({ id: `call_${toolCalls.length + 1}`, name, args: args });
|
|
127
140
|
}
|
|
128
141
|
}
|
|
129
142
|
}
|
|
130
|
-
for (const
|
|
131
|
-
yield { type: "tool_call", id, name: tc.name, arguments: tc.args };
|
|
143
|
+
for (const tc of toolCalls) {
|
|
144
|
+
yield { type: "tool_call", id: tc.id, name: tc.name, arguments: tc.args };
|
|
132
145
|
}
|
|
133
146
|
const usage = (await result.response).usageMetadata;
|
|
134
147
|
if (usage?.totalTokenCount)
|
|
135
148
|
yield { type: "usage", totalTokens: usage.totalTokenCount };
|
|
136
149
|
}
|
|
150
|
+
modelExtensions(extensions) {
|
|
151
|
+
if (!extensions)
|
|
152
|
+
return {};
|
|
153
|
+
const { model: _model, systemInstruction: _systemInstruction, tools: _tools, ...rest } = extensions;
|
|
154
|
+
return rest;
|
|
155
|
+
}
|
|
137
156
|
}
|
package/dist/providers/kimi.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import type { RuntimePolicy } from "../types.js";
|
|
1
2
|
import { OpenAIChatProvider } from "./openai.js";
|
|
2
3
|
export declare class KimiProvider extends OpenAIChatProvider {
|
|
3
|
-
constructor(apiKey: string, model?:
|
|
4
|
+
constructor(apiKey: string, model?: string, retry?: {
|
|
4
5
|
maxRetries: number;
|
|
5
6
|
baseDelay: number;
|
|
6
7
|
}, baseURL?: string);
|
|
8
|
+
runtimePolicy(): RuntimePolicy;
|
|
7
9
|
}
|
package/dist/providers/kimi.js
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import { OpenAIChatProvider } from "./openai.js";
|
|
2
2
|
import { endpointProfiles } from "./profiles.js";
|
|
3
3
|
const MOONSHOT_BASE = endpointProfiles["kimi.openai"].baseURL;
|
|
4
|
+
const KIMI_POLICIES = {
|
|
5
|
+
"moonshot-v1-8k": { maxTurns: 15 },
|
|
6
|
+
"moonshot-v1-32k": { maxTurns: 20 },
|
|
7
|
+
"moonshot-v1-128k": { maxTurns: 30 },
|
|
8
|
+
"kimi-k2.5": { maxTurns: 30 },
|
|
9
|
+
"kimi-k2.6": { maxTurns: 35 },
|
|
10
|
+
};
|
|
4
11
|
export class KimiProvider extends OpenAIChatProvider {
|
|
5
12
|
constructor(apiKey, model = "kimi-k2.6", retry, baseURL = MOONSHOT_BASE) {
|
|
6
13
|
super(apiKey, model, retry, baseURL);
|
|
7
14
|
}
|
|
15
|
+
runtimePolicy() {
|
|
16
|
+
return KIMI_POLICIES[this.model] ?? {};
|
|
17
|
+
}
|
|
8
18
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import type { RuntimePolicy } from "../types.js";
|
|
1
2
|
import { AnthropicProvider } from "./anthropic.js";
|
|
2
3
|
export declare class MiniMaxProvider extends AnthropicProvider {
|
|
3
|
-
constructor(apiKey: string, model?:
|
|
4
|
+
constructor(apiKey: string, model?: string, retry?: {
|
|
4
5
|
maxRetries: number;
|
|
5
6
|
baseDelay: number;
|
|
6
7
|
}, baseURL?: string);
|
|
8
|
+
runtimePolicy(): RuntimePolicy;
|
|
7
9
|
}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { AnthropicProvider } from "./anthropic.js";
|
|
2
2
|
import { endpointProfiles } from "./profiles.js";
|
|
3
|
+
const MINIMAX_POLICIES = {
|
|
4
|
+
"MiniMax-M2.7": { maxTurns: 35 },
|
|
5
|
+
"MiniMax-M2.5": { maxTurns: 25 },
|
|
6
|
+
"MiniMax-Text-01": { maxTurns: 20 },
|
|
7
|
+
};
|
|
3
8
|
export class MiniMaxProvider extends AnthropicProvider {
|
|
4
9
|
constructor(apiKey, model = "MiniMax-M2.7", retry, baseURL = endpointProfiles["minimax.anthropic"].baseURL) {
|
|
5
10
|
super(apiKey, model, retry, {
|
|
@@ -7,4 +12,7 @@ export class MiniMaxProvider extends AnthropicProvider {
|
|
|
7
12
|
authMode: "api-key",
|
|
8
13
|
});
|
|
9
14
|
}
|
|
15
|
+
runtimePolicy() {
|
|
16
|
+
return MINIMAX_POLICIES[this.model] ?? {};
|
|
17
|
+
}
|
|
10
18
|
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import type { Message, RenderedContext, ToolSchema, StreamEvent, LLMProvider } from "../types.js";
|
|
1
|
+
import type { Message, RenderedContext, ToolSchema, StreamEvent, LLMProvider, RuntimePolicy } from "../types.js";
|
|
2
2
|
export declare class OllamaProvider implements LLMProvider {
|
|
3
3
|
private readonly model;
|
|
4
4
|
private readonly baseUrl;
|
|
5
5
|
constructor(model?: string, baseUrl?: string);
|
|
6
|
+
runtimePolicy(): RuntimePolicy;
|
|
6
7
|
private toOllamaMessages;
|
|
7
|
-
|
|
8
|
+
private buildTools;
|
|
9
|
+
private requestExtensions;
|
|
10
|
+
complete(context: RenderedContext, tools: ToolSchema[], extensions?: Record<string, unknown>): Promise<Message>;
|
|
8
11
|
stream(context: RenderedContext, tools: ToolSchema[], extensions?: Record<string, unknown>): AsyncIterable<StreamEvent>;
|
|
9
12
|
}
|