@deepstrike/sdk 0.1.13 → 0.1.15
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 +77 -51
- 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 +9 -7
- package/dist/harness/harness.js +19 -22
- package/dist/index.d.ts +18 -6
- package/dist/index.js +14 -2
- 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 +4 -2
- package/dist/providers/anthropic.js +34 -10
- package/dist/providers/deepseek.d.ts +3 -2
- package/dist/providers/deepseek.js +9 -0
- package/dist/providers/gemini.d.ts +2 -1
- package/dist/providers/gemini.js +11 -0
- 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 +2 -1
- package/dist/providers/ollama.js +22 -0
- package/dist/providers/openai-chat.d.ts +1 -1
- package/dist/providers/openai-chat.js +5 -7
- package/dist/providers/openai-responses.d.ts +1 -0
- package/dist/providers/openai-responses.js +13 -0
- package/dist/providers/openai.d.ts +4 -1
- package/dist/providers/openai.js +28 -0
- package/dist/providers/profiles.d.ts +502 -6
- package/dist/providers/profiles.js +225 -82
- package/dist/providers/qwen.d.ts +2 -1
- package/dist/providers/qwen.js +15 -0
- 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/provider-replay.d.ts +7 -0
- package/dist/runtime/provider-replay.js +18 -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 +368 -0
- package/dist/runtime/session-log.d.ts +68 -0
- package/dist/runtime/session-log.js +84 -0
- package/dist/types.d.ts +27 -0
- package/package.json +3 -2
- package/dist/agent.d.ts +0 -90
- package/dist/agent.js +0 -499
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";
|
|
23
|
+
// ── Tools & Skills ─────────────────────────────────────────────────────────
|
|
15
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, ProviderReplay, RenderedContext, ToolSchema, StreamEvent, LLMProvider, RuntimePolicy } from "../types.js";
|
|
2
2
|
interface AnthropicProviderOptions {
|
|
3
3
|
baseURL?: string;
|
|
4
4
|
authMode?: "api-key" | "bearer";
|
|
@@ -14,6 +14,9 @@ export declare class AnthropicProvider implements LLMProvider {
|
|
|
14
14
|
maxRetries: number;
|
|
15
15
|
baseDelay: number;
|
|
16
16
|
}, options?: AnthropicProviderOptions);
|
|
17
|
+
runtimePolicy(): RuntimePolicy;
|
|
18
|
+
peekProviderReplay(message: Pick<Message, "content" | "toolCalls">): ProviderReplay | undefined;
|
|
19
|
+
seedProviderReplay(message: Pick<Message, "content" | "toolCalls">, replay: ProviderReplay): void;
|
|
17
20
|
private buildTools;
|
|
18
21
|
complete(context: RenderedContext, tools: ToolSchema[], extensions?: Record<string, unknown>): Promise<Message>;
|
|
19
22
|
stream(context: RenderedContext, tools: ToolSchema[], extensions?: Record<string, unknown>): AsyncIterable<StreamEvent>;
|
|
@@ -23,6 +26,5 @@ export declare class AnthropicProvider implements LLMProvider {
|
|
|
23
26
|
private streamMessage;
|
|
24
27
|
private buildMessages;
|
|
25
28
|
private rememberNativeBlocks;
|
|
26
|
-
private assistantReplayKey;
|
|
27
29
|
}
|
|
28
30
|
export {};
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import Anthropic from "@anthropic-ai/sdk";
|
|
2
|
+
import { assistantReplayKey } from "../runtime/provider-replay.js";
|
|
2
3
|
import { withServerRuntimeGuard } from "../runtime/server.js";
|
|
3
4
|
import { CircuitBreaker, normalizeToolCall, omitExtensionKeys, toAnthropicMessages } from "./base.js";
|
|
5
|
+
const CLAUDE_POLICIES = {
|
|
6
|
+
"claude-opus-4-7": { maxTurns: 50 },
|
|
7
|
+
"claude-opus-4-6": { maxTurns: 50 },
|
|
8
|
+
"claude-sonnet-4-6": { maxTurns: 25 },
|
|
9
|
+
"claude-haiku-4-5": { maxTurns: 15 },
|
|
10
|
+
"claude-haiku-4-5-20251001": { maxTurns: 15 },
|
|
11
|
+
};
|
|
4
12
|
export class AnthropicProvider {
|
|
5
13
|
model;
|
|
6
14
|
client;
|
|
@@ -18,6 +26,18 @@ export class AnthropicProvider {
|
|
|
18
26
|
this.maxRetries = retry.maxRetries;
|
|
19
27
|
this.baseDelay = retry.baseDelay;
|
|
20
28
|
}
|
|
29
|
+
runtimePolicy() {
|
|
30
|
+
return CLAUDE_POLICIES[this.model] ?? {};
|
|
31
|
+
}
|
|
32
|
+
peekProviderReplay(message) {
|
|
33
|
+
const blocks = this.nativeAssistantBlocks.get(assistantReplayKey(message));
|
|
34
|
+
return blocks?.length ? { native_blocks: blocks } : undefined;
|
|
35
|
+
}
|
|
36
|
+
seedProviderReplay(message, replay) {
|
|
37
|
+
if (replay.native_blocks?.length) {
|
|
38
|
+
this.nativeAssistantBlocks.set(assistantReplayKey(message), replay.native_blocks);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
21
41
|
buildTools(tools) {
|
|
22
42
|
return tools.map(t => ({
|
|
23
43
|
name: t.name,
|
|
@@ -83,8 +103,16 @@ export class AnthropicProvider {
|
|
|
83
103
|
messages: msgs,
|
|
84
104
|
...(tools.length ? { tools: this.buildTools(tools) } : {}),
|
|
85
105
|
}, extensions);
|
|
106
|
+
let totalTokens = 0;
|
|
86
107
|
for await (const evt of stream) {
|
|
87
|
-
if (evt.type === "
|
|
108
|
+
if (evt.type === "message_start" || evt.type === "message_delta") {
|
|
109
|
+
const usage = evt.usage ?? evt.message?.usage;
|
|
110
|
+
if (usage) {
|
|
111
|
+
totalTokens = usage.input_tokens + (usage.output_tokens ?? 0);
|
|
112
|
+
yield { type: "usage", totalTokens };
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
else if (evt.type === "content_block_start") {
|
|
88
116
|
nativeBlocks[evt.index] = { ...evt.content_block };
|
|
89
117
|
if (evt.content_block.type === "tool_use") {
|
|
90
118
|
toolBlocks[evt.index] = { id: evt.content_block.id, name: evt.content_block.name, argsBuf: "" };
|
|
@@ -143,17 +171,13 @@ export class AnthropicProvider {
|
|
|
143
171
|
: this.client.messages.stream(params));
|
|
144
172
|
}
|
|
145
173
|
buildMessages(context) {
|
|
146
|
-
return toAnthropicMessages(context.turns, message => this.nativeAssistantBlocks.get(
|
|
174
|
+
return toAnthropicMessages(context.turns, message => this.nativeAssistantBlocks.get(assistantReplayKey(message)));
|
|
147
175
|
}
|
|
148
176
|
rememberNativeBlocks(message, blocks) {
|
|
149
|
-
if (!
|
|
177
|
+
if (!blocks.length)
|
|
150
178
|
return;
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
return JSON.stringify({
|
|
155
|
-
content: message.content,
|
|
156
|
-
toolCalls: message.toolCalls ?? [],
|
|
157
|
-
});
|
|
179
|
+
if (!message.toolCalls?.length && !blocks.some(b => b.type === "thinking"))
|
|
180
|
+
return;
|
|
181
|
+
this.nativeAssistantBlocks.set(assistantReplayKey(message), blocks);
|
|
158
182
|
}
|
|
159
183
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type { Message, 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;
|
|
8
9
|
complete(context: RenderedContext, tools: ToolSchema[], extensions?: Record<string, unknown>): Promise<Message>;
|
|
9
10
|
stream(context: RenderedContext, tools: ToolSchema[], extensions?: Record<string, unknown>): AsyncIterable<StreamEvent>;
|
|
10
11
|
}
|
|
@@ -2,10 +2,19 @@ import { OpenAIChatProvider } from "./openai.js";
|
|
|
2
2
|
import { endpointProfiles } from "./profiles.js";
|
|
3
3
|
import { omitExtensionKeys } from "./base.js";
|
|
4
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
|
+
};
|
|
5
11
|
export class DeepSeekProvider extends OpenAIChatProvider {
|
|
6
12
|
constructor(apiKey, model = "deepseek-v4-flash", retry, baseURL = DEEPSEEK_BASE) {
|
|
7
13
|
super(apiKey, model, retry, baseURL);
|
|
8
14
|
}
|
|
15
|
+
runtimePolicy() {
|
|
16
|
+
return DEEPSEEK_POLICIES[this.model] ?? {};
|
|
17
|
+
}
|
|
9
18
|
async complete(context, tools, extensions) {
|
|
10
19
|
const thinking = extensions?.thinking === false ? "disabled" : "enabled";
|
|
11
20
|
const reasoningEffort = extensions?.reasoningEffort === "max" ? "max" : "high";
|
|
@@ -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,7 @@ export declare class GeminiProvider implements LLMProvider {
|
|
|
9
9
|
maxRetries: number;
|
|
10
10
|
baseDelay: number;
|
|
11
11
|
}, baseURL?: string);
|
|
12
|
+
runtimePolicy(): RuntimePolicy;
|
|
12
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>;
|
|
14
15
|
private modelExtensions;
|
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,6 +69,9 @@ export class GeminiProvider {
|
|
|
61
69
|
this.maxRetries = retry.maxRetries;
|
|
62
70
|
this.baseDelay = retry.baseDelay;
|
|
63
71
|
}
|
|
72
|
+
runtimePolicy() {
|
|
73
|
+
return GEMINI_POLICIES[this.model] ?? {};
|
|
74
|
+
}
|
|
64
75
|
async complete(context, tools, extensions) {
|
|
65
76
|
if (this.circuit.isOpen())
|
|
66
77
|
throw new Error("Circuit breaker open");
|
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,8 +1,9 @@
|
|
|
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;
|
|
8
9
|
private requestExtensions;
|
package/dist/providers/ollama.js
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
import { normalizeToolCall, omitExtensionKeys } from "./base.js";
|
|
2
|
+
// Prefix-based policy for local models (first match wins)
|
|
3
|
+
const OLLAMA_PREFIX_POLICIES = [
|
|
4
|
+
["deepseek-r1", { maxTurns: 40 }],
|
|
5
|
+
["qwq", { maxTurns: 35 }],
|
|
6
|
+
["llama3.3", { maxTurns: 25 }],
|
|
7
|
+
["llama3.2", { maxTurns: 20 }],
|
|
8
|
+
["llama3.1", { maxTurns: 20 }],
|
|
9
|
+
["llama3", { maxTurns: 20 }],
|
|
10
|
+
["mistral", { maxTurns: 20 }],
|
|
11
|
+
["gemma2", { maxTurns: 20 }],
|
|
12
|
+
["phi4", { maxTurns: 20 }],
|
|
13
|
+
["phi3", { maxTurns: 15 }],
|
|
14
|
+
["codellama", { maxTurns: 20 }],
|
|
15
|
+
];
|
|
2
16
|
export class OllamaProvider {
|
|
3
17
|
model;
|
|
4
18
|
baseUrl;
|
|
@@ -6,6 +20,14 @@ export class OllamaProvider {
|
|
|
6
20
|
this.model = model;
|
|
7
21
|
this.baseUrl = baseUrl;
|
|
8
22
|
}
|
|
23
|
+
runtimePolicy() {
|
|
24
|
+
const m = this.model.toLowerCase();
|
|
25
|
+
for (const [prefix, policy] of OLLAMA_PREFIX_POLICIES) {
|
|
26
|
+
if (m.startsWith(prefix))
|
|
27
|
+
return policy;
|
|
28
|
+
}
|
|
29
|
+
return { maxTurns: 20 };
|
|
30
|
+
}
|
|
9
31
|
toOllamaMessages(context) {
|
|
10
32
|
const result = [];
|
|
11
33
|
if (context.systemText)
|
|
@@ -23,5 +23,5 @@ export declare class OpenAIChatAdapter {
|
|
|
23
23
|
arguments: string;
|
|
24
24
|
}>;
|
|
25
25
|
rememberReplayFields(message: Pick<Message, "content" | "toolCalls">, fields: Record<string, unknown>): void;
|
|
26
|
-
|
|
26
|
+
peekReplayFields(message: Pick<Message, "content" | "toolCalls">): Record<string, unknown> | undefined;
|
|
27
27
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assistantReplayKey } from "../runtime/provider-replay.js";
|
|
1
2
|
import { normalizeToolCall, toOpenAIMessageParams } from "./base.js";
|
|
2
3
|
export class OpenAIChatAdapter {
|
|
3
4
|
replayFields = new Map();
|
|
@@ -18,7 +19,7 @@ export class OpenAIChatAdapter {
|
|
|
18
19
|
continue;
|
|
19
20
|
}
|
|
20
21
|
if (source.role === "assistant") {
|
|
21
|
-
const replay = this.replayFields.get(
|
|
22
|
+
const replay = this.replayFields.get(assistantReplayKey(source));
|
|
22
23
|
if (replay)
|
|
23
24
|
serialized[cursor] = { ...serialized[cursor], ...replay };
|
|
24
25
|
}
|
|
@@ -32,12 +33,9 @@ export class OpenAIChatAdapter {
|
|
|
32
33
|
.filter(Boolean);
|
|
33
34
|
}
|
|
34
35
|
rememberReplayFields(message, fields) {
|
|
35
|
-
this.replayFields.set(
|
|
36
|
+
this.replayFields.set(assistantReplayKey(message), fields);
|
|
36
37
|
}
|
|
37
|
-
|
|
38
|
-
return
|
|
39
|
-
content: message.content,
|
|
40
|
-
toolCalls: message.toolCalls ?? [],
|
|
41
|
-
});
|
|
38
|
+
peekReplayFields(message) {
|
|
39
|
+
return this.replayFields.get(assistantReplayKey(message));
|
|
42
40
|
}
|
|
43
41
|
}
|
|
@@ -35,6 +35,7 @@ export declare class OpenAIResponsesProvider implements LLMProvider {
|
|
|
35
35
|
maxRetries: number;
|
|
36
36
|
baseDelay: number;
|
|
37
37
|
}, baseURL?: string);
|
|
38
|
+
runtimePolicy(): import("../types.js").RuntimePolicy;
|
|
38
39
|
createRunState(): OpenAIResponsesRunState;
|
|
39
40
|
complete(context: RenderedContext, tools: ToolSchema[], extensions?: Record<string, unknown>): Promise<Message>;
|
|
40
41
|
stream(context: RenderedContext, tools: ToolSchema[], extensions?: Record<string, unknown>, state?: ProviderRunState): AsyncIterable<StreamEvent>;
|
|
@@ -113,6 +113,19 @@ export class OpenAIResponsesProvider {
|
|
|
113
113
|
this.maxRetries = retry.maxRetries;
|
|
114
114
|
this.baseDelay = retry.baseDelay;
|
|
115
115
|
}
|
|
116
|
+
runtimePolicy() {
|
|
117
|
+
const table = {
|
|
118
|
+
"gpt-4.1": { maxTurns: 35 },
|
|
119
|
+
"gpt-4.1-mini": { maxTurns: 20 },
|
|
120
|
+
"gpt-4.1-nano": { maxTurns: 15 },
|
|
121
|
+
"gpt-5": { maxTurns: 50 },
|
|
122
|
+
"gpt-5-mini": { maxTurns: 25 },
|
|
123
|
+
"o3": { maxTurns: 50 },
|
|
124
|
+
"o3-mini": { maxTurns: 25 },
|
|
125
|
+
"o4-mini": { maxTurns: 25 },
|
|
126
|
+
};
|
|
127
|
+
return table[this.model] ?? {};
|
|
128
|
+
}
|
|
116
129
|
createRunState() {
|
|
117
130
|
return { coveredMessageCount: 0 };
|
|
118
131
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import OpenAI from "openai";
|
|
2
|
-
import type { Message, RenderedContext, ToolSchema, StreamEvent, LLMProvider } from "../types.js";
|
|
2
|
+
import type { Message, ProviderReplay, RenderedContext, ToolSchema, StreamEvent, LLMProvider, RuntimePolicy } from "../types.js";
|
|
3
3
|
import { CircuitBreaker } from "./base.js";
|
|
4
4
|
import { OpenAIChatAdapter } from "./openai-chat.js";
|
|
5
5
|
export declare class OpenAIChatProvider implements LLMProvider {
|
|
@@ -13,6 +13,9 @@ export declare class OpenAIChatProvider implements LLMProvider {
|
|
|
13
13
|
maxRetries: number;
|
|
14
14
|
baseDelay: number;
|
|
15
15
|
}, baseURL?: string);
|
|
16
|
+
runtimePolicy(): RuntimePolicy;
|
|
17
|
+
peekProviderReplay(message: Pick<Message, "content" | "toolCalls">): ProviderReplay | undefined;
|
|
18
|
+
seedProviderReplay(message: Pick<Message, "content" | "toolCalls">, replay: ProviderReplay): void;
|
|
16
19
|
complete(context: RenderedContext, tools: ToolSchema[], extensions?: Record<string, unknown>): Promise<Message>;
|
|
17
20
|
stream(context: RenderedContext, tools: ToolSchema[], extensions?: Record<string, unknown>): AsyncIterable<StreamEvent>;
|
|
18
21
|
protected requestExtensions(extensions?: Record<string, unknown>): Record<string, unknown>;
|
package/dist/providers/openai.js
CHANGED
|
@@ -2,6 +2,20 @@ import OpenAI from "openai";
|
|
|
2
2
|
import { withServerRuntimeGuard } from "../runtime/server.js";
|
|
3
3
|
import { CircuitBreaker, omitExtensionKeys } from "./base.js";
|
|
4
4
|
import { OpenAIChatAdapter } from "./openai-chat.js";
|
|
5
|
+
const OPENAI_POLICIES = {
|
|
6
|
+
"gpt-4o": { maxTurns: 25 },
|
|
7
|
+
"gpt-4o-mini": { maxTurns: 15 },
|
|
8
|
+
"gpt-4.1": { maxTurns: 35 },
|
|
9
|
+
"gpt-4.1-mini": { maxTurns: 20 },
|
|
10
|
+
"gpt-4.1-nano": { maxTurns: 15 },
|
|
11
|
+
"gpt-5": { maxTurns: 50 },
|
|
12
|
+
"gpt-5-mini": { maxTurns: 25 },
|
|
13
|
+
"o1": { maxTurns: 50 },
|
|
14
|
+
"o1-mini": { maxTurns: 25 },
|
|
15
|
+
"o3": { maxTurns: 50 },
|
|
16
|
+
"o3-mini": { maxTurns: 25 },
|
|
17
|
+
"o4-mini": { maxTurns: 25 },
|
|
18
|
+
};
|
|
5
19
|
export class OpenAIChatProvider {
|
|
6
20
|
model;
|
|
7
21
|
client;
|
|
@@ -16,6 +30,20 @@ export class OpenAIChatProvider {
|
|
|
16
30
|
this.maxRetries = retry.maxRetries;
|
|
17
31
|
this.baseDelay = retry.baseDelay;
|
|
18
32
|
}
|
|
33
|
+
runtimePolicy() {
|
|
34
|
+
return OPENAI_POLICIES[this.model] ?? {};
|
|
35
|
+
}
|
|
36
|
+
peekProviderReplay(message) {
|
|
37
|
+
const fields = this.chat.peekReplayFields(message);
|
|
38
|
+
if (!fields?.reasoning_content)
|
|
39
|
+
return undefined;
|
|
40
|
+
return { reasoning_content: String(fields.reasoning_content) };
|
|
41
|
+
}
|
|
42
|
+
seedProviderReplay(message, replay) {
|
|
43
|
+
if (replay.reasoning_content) {
|
|
44
|
+
this.chat.rememberReplayFields(message, { reasoning_content: replay.reasoning_content });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
19
47
|
async complete(context, tools, extensions) {
|
|
20
48
|
if (this.circuit.isOpen())
|
|
21
49
|
throw new Error("Circuit breaker open");
|