@deepstrike/sdk 0.2.5 → 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.
- package/README.md +19 -0
- package/dist/index.d.ts +9 -5
- package/dist/index.js +4 -3
- package/dist/kernel.d.ts +97 -0
- package/dist/kernel.js +8 -0
- package/dist/memory/agent.d.ts +2 -47
- package/dist/providers/anthropic.d.ts +4 -1
- package/dist/providers/anthropic.js +51 -0
- package/dist/providers/catalog.js +5 -2
- package/dist/providers/deepseek.d.ts +4 -1
- package/dist/providers/deepseek.js +76 -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 +197 -1
- package/dist/providers/openai-chat.d.ts +6 -2
- package/dist/providers/openai-chat.js +20 -3
- package/dist/providers/openai.d.ts +4 -1
- package/dist/providers/openai.js +31 -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 +10 -0
- package/dist/providers/replay-validator.js +57 -0
- package/dist/runtime/kernel-event-log.js +22 -0
- package/dist/runtime/kernel-step.d.ts +13 -0
- package/dist/runtime/os-profile.d.ts +12 -0
- package/dist/runtime/os-profile.js +24 -0
- package/dist/runtime/provider-replay.d.ts +8 -1
- package/dist/runtime/provider-replay.js +37 -4
- package/dist/runtime/runner.d.ts +42 -4
- package/dist/runtime/runner.js +109 -5
- 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 +23 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -222,6 +222,23 @@ const runner = new RuntimeRunner({
|
|
|
222
222
|
timeoutMs: 60_000,
|
|
223
223
|
schedulerBudget: { maxWallMs: 300_000 },
|
|
224
224
|
|
|
225
|
+
// Resource quotas (M2) — enforced at the kernel syscall trap. Opt-in; omit for unbounded.
|
|
226
|
+
resourceQuota: {
|
|
227
|
+
maxConcurrentSubagents: 4, // deny spawn while at cap
|
|
228
|
+
maxSpawnDepth: 2, // deny spawn past nesting depth
|
|
229
|
+
memoryWritesPerWindow: { maxWrites: 20, windowMs: 60_000 }, // rate-limit writeMemory
|
|
230
|
+
},
|
|
231
|
+
|
|
232
|
+
// Long-term memory policy (set_memory_policy) — opt-in, kernel-enforced; omit for defaults.
|
|
233
|
+
memoryPolicy: {
|
|
234
|
+
memoryPath: "./.memory", // where the SDK persists/scans memories (SDK-consumed)
|
|
235
|
+
staleWarningDays: 30, // flag recalled memories older than this (SDK-consumed)
|
|
236
|
+
retrievalTopK: 5, // kernel caps query_memory requested_k to this
|
|
237
|
+
validationEnabled: true, // false → admit writes without validation
|
|
238
|
+
maxContentBytes: 10_000, // override write_memory content-size limit
|
|
239
|
+
maxNameLength: 100, // override write_memory name-length limit
|
|
240
|
+
},
|
|
241
|
+
|
|
225
242
|
// Agent OS native profile (defaults shown)
|
|
226
243
|
governancePolicy: DEFAULT_NATIVE_GOVERNANCE_POLICY,
|
|
227
244
|
attentionPolicy: DEFAULT_NATIVE_ATTENTION_POLICY, // SignalRouter queue size 64
|
|
@@ -260,6 +277,8 @@ const runner = new RuntimeRunner({
|
|
|
260
277
|
|--------|---------|
|
|
261
278
|
| `governancePolicy` | Declarative deny / ask_user / rate-limit / param rules loaded into the kernel before `start_run` |
|
|
262
279
|
| `attentionPolicy` | In-kernel signal router queue size (default 64) |
|
|
280
|
+
| `resourceQuota` | M2 declarative limits — `maxConcurrentSubagents` / `maxSpawnDepth` / `memoryWritesPerWindow` — enforced at the kernel syscall trap (`set_resource_quota`); over-quota spawns roll back, over-rate writes surface as `memory_validation_failed` |
|
|
281
|
+
| `memoryPolicy` | Long-term memory config sent as `set_memory_policy` and **kernel-enforced**: `validationEnabled: false` admits writes without validation, `maxContentBytes` / `maxNameLength` override validation limits, `retrievalTopK` caps `query_memory` breadth; `memoryPath` / `staleWarningDays` are SDK-consumed (requires `dreamStore` + `agentId` to enable memory) |
|
|
263
282
|
| `onPermissionRequest` | Resolves `tool_gated` + `suspended` → kernel `resume` with approved/denied call IDs |
|
|
264
283
|
| `compressionStore` | Writes archived messages on `compressed` observations |
|
|
265
284
|
| `asyncSummarizer` | Background LLM summary after compression; stored as `summary_upgraded` |
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export { RuntimeRunner, collectText } from "./runtime/runner.js";
|
|
2
|
-
export type { RuntimeOptions } from "./runtime/runner.js";
|
|
2
|
+
export type { RuntimeOptions, SchedulerBudget } from "./runtime/runner.js";
|
|
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";
|
|
3
6
|
export { KernelPrimitivesDashboard } from "./runtime/kernel-primitives-dashboard.js";
|
|
4
7
|
export { FilteredExecutionPlane } from "./runtime/filtered-plane.js";
|
|
5
8
|
export { SubAgentOrchestrator, defaultSubAgentOrchestrator, spawnStandalone } from "./runtime/sub-agent-orchestrator.js";
|
|
@@ -8,7 +11,8 @@ export { LocalExecutionPlane } from "./runtime/execution-plane.js";
|
|
|
8
11
|
export type { ExecutionPlane, RunContext } from "./runtime/execution-plane.js";
|
|
9
12
|
export { InMemorySessionLog, FileSessionLog } from "./runtime/session-log.js";
|
|
10
13
|
export type { SessionLog, SessionEvent } from "./runtime/session-log.js";
|
|
11
|
-
export { DEFAULT_NATIVE_ATTENTION_POLICY, DEFAULT_NATIVE_GOVERNANCE_POLICY, } from "./runtime/os-profile.js";
|
|
14
|
+
export { DEFAULT_NATIVE_ATTENTION_POLICY, DEFAULT_NATIVE_GOVERNANCE_POLICY, assertNativeProfile, osProfile, } from "./runtime/os-profile.js";
|
|
15
|
+
export type { NativeOsProfile, OsProfileId } from "./runtime/os-profile.js";
|
|
12
16
|
export { rebuildOsSnapshotFromSessionEvents, sessionLogHasRequiredCategories, } from "./runtime/os-snapshot.js";
|
|
13
17
|
export type { OsSnapshot } from "./runtime/os-snapshot.js";
|
|
14
18
|
export { categoryForKind, kernelObservationToSessionEvent } from "./runtime/kernel-event-log.js";
|
|
@@ -29,7 +33,7 @@ export { DeepSeekProvider } from "./providers/deepseek.js";
|
|
|
29
33
|
export { KimiProvider } from "./providers/kimi.js";
|
|
30
34
|
export { QwenProvider } from "./providers/qwen.js";
|
|
31
35
|
export { GeminiProvider } from "./providers/gemini.js";
|
|
32
|
-
export {
|
|
36
|
+
export { MiniMaxAnthropicProvider, MiniMaxOpenAIProvider } from "./providers/minimax.js";
|
|
33
37
|
export { OllamaProvider } from "./providers/ollama.js";
|
|
34
38
|
export { CircuitBreaker, normalizeToolCall } from "./providers/base.js";
|
|
35
39
|
export { OpenAIChatAdapter } from "./providers/openai-chat.js";
|
|
@@ -56,8 +60,8 @@ export type { GovernanceVerdict, GovernancePolicy, GovernanceConstraint } from "
|
|
|
56
60
|
export { SinglePassHarness, EvalLoopHarness, HarnessLoop } from "./harness/harness.js";
|
|
57
61
|
export type { HarnessRequest, HarnessOutcome, HarnessLoopOptions, QualityGate } from "./harness/harness.js";
|
|
58
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";
|
|
59
|
-
export type { AgentCapabilityFilter, AgentIdentity, AgentIsolation, AgentRunSpec, AgentProcessChangedObservation, ContextInheritance, KernelAgentRole, LoopResult, MilestoneCheckResult, MilestoneContract, MilestonePhase, MilestonePolicy, SubAgentResult, TerminationReason, } from "./types/agent.js";
|
|
60
|
-
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";
|
|
61
65
|
export type { AcceptanceCriterion, VerificationContract, ContractCheckResult, } from "./collaboration/contract.js";
|
|
62
66
|
export { ContractBuilder, formatContractForSystemPrompt, contractToCriteriaStrings, } from "./collaboration/contract.js";
|
|
63
67
|
export { AgentPool } from "./collaboration/pool.js";
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
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";
|
|
6
7
|
export { LocalExecutionPlane } from "./runtime/execution-plane.js";
|
|
7
8
|
export { InMemorySessionLog, FileSessionLog } from "./runtime/session-log.js";
|
|
8
|
-
export { DEFAULT_NATIVE_ATTENTION_POLICY, DEFAULT_NATIVE_GOVERNANCE_POLICY, } from "./runtime/os-profile.js";
|
|
9
|
+
export { DEFAULT_NATIVE_ATTENTION_POLICY, DEFAULT_NATIVE_GOVERNANCE_POLICY, assertNativeProfile, osProfile, } from "./runtime/os-profile.js";
|
|
9
10
|
export { rebuildOsSnapshotFromSessionEvents, sessionLogHasRequiredCategories, } from "./runtime/os-snapshot.js";
|
|
10
11
|
export { categoryForKind, kernelObservationToSessionEvent } from "./runtime/kernel-event-log.js";
|
|
11
12
|
export { NullArchiveStore, FileArchiveStore } from "./runtime/archive.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 {
|
|
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
|
@@ -4,6 +4,49 @@ export interface GovernanceVerdict {
|
|
|
4
4
|
reason?: string;
|
|
5
5
|
retryAfterMs?: number;
|
|
6
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* M2 资源配额 — declarative resource limits enforced at the kernel's single syscall trap.
|
|
9
|
+
*
|
|
10
|
+
* Installed through the versioned JSON event ABI (`set_resource_quota`), not a side-channel
|
|
11
|
+
* setter, so quota config is replayable and session-loggable like governance/scheduler config.
|
|
12
|
+
* Every field is optional; an omitted field imposes no limit, and omitting the quota entirely
|
|
13
|
+
* preserves the pre-M2 behavior of admitting all spawn / memory-write syscalls.
|
|
14
|
+
*/
|
|
15
|
+
export interface MemoryWriteRateLimit {
|
|
16
|
+
maxWrites: number;
|
|
17
|
+
windowMs: number;
|
|
18
|
+
}
|
|
19
|
+
export interface ResourceQuota {
|
|
20
|
+
/** Max sub-agents in the `running` state at once; further spawns are denied while at cap. */
|
|
21
|
+
maxConcurrentSubagents?: number;
|
|
22
|
+
/** Max sub-agent nesting depth (direct children of the root loop are depth 1). */
|
|
23
|
+
maxSpawnDepth?: number;
|
|
24
|
+
/** Rolling-window memory-write rate limit: at most `maxWrites` per any `windowMs` span. */
|
|
25
|
+
memoryWritesPerWindow?: MemoryWriteRateLimit;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Long-term memory policy — declarative knobs for the kernel's memory subsystem.
|
|
29
|
+
*
|
|
30
|
+
* Installed through the versioned JSON event ABI (`set_memory_policy`), the same channel as
|
|
31
|
+
* governance / scheduler / quota config, so memory configuration is replayable and
|
|
32
|
+
* session-loggable rather than a side-channel setter. Installing the policy is opt-in and
|
|
33
|
+
* kernel-enforced; omitted fields fall back to the kernel defaults (empty path, 2-day stale
|
|
34
|
+
* warning, top-5 retrieval, validation on). Enabling memory is still `dreamStore` + `agentId`.
|
|
35
|
+
*/
|
|
36
|
+
export interface MemoryPolicy {
|
|
37
|
+
/** Filesystem root the SDK uses to persist/scan memories; carried for SDK recall I/O. */
|
|
38
|
+
memoryPath?: string;
|
|
39
|
+
/** Age after which a recalled memory is flagged stale (days); consumed SDK-side. */
|
|
40
|
+
staleWarningDays?: number;
|
|
41
|
+
/** Upper bound on retrieval breadth: the kernel clamps `query_memory` top-k to this. */
|
|
42
|
+
retrievalTopK?: number;
|
|
43
|
+
/** When false, the kernel admits every `write_memory` without validation. */
|
|
44
|
+
validationEnabled?: boolean;
|
|
45
|
+
/** Override the kernel's `write_memory` content-size limit (bytes). */
|
|
46
|
+
maxContentBytes?: number;
|
|
47
|
+
/** Override the kernel's `write_memory` name-length limit. */
|
|
48
|
+
maxNameLength?: number;
|
|
49
|
+
}
|
|
7
50
|
export interface GovernanceInstance {
|
|
8
51
|
setIdentity(agentId: string, sessionId: string): void;
|
|
9
52
|
addPermissionRule(pattern: string, action: "allow" | "deny" | "ask_user"): void;
|
|
@@ -104,6 +147,54 @@ export interface KernelRuntimeInstance {
|
|
|
104
147
|
drainNewMessages(): Message[];
|
|
105
148
|
preservedRefs(): string[];
|
|
106
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
|
+
}
|
|
107
198
|
interface KernelModule {
|
|
108
199
|
Governance: new (defaultAction?: "allow" | "deny" | "ask_user") => GovernanceInstance;
|
|
109
200
|
KernelRuntime: new (policy: {
|
|
@@ -117,6 +208,12 @@ interface KernelModule {
|
|
|
117
208
|
extractSkillOnPass?: boolean;
|
|
118
209
|
}) => EvalPipelineInstance;
|
|
119
210
|
IdlePipeline: new (agentId: string) => IdlePipelineInstance;
|
|
211
|
+
Tournament: new (entrants: string[]) => TournamentInstance;
|
|
212
|
+
LoopUntilDone: new (conditions: StopConditionSpec[]) => LoopUntilDoneInstance;
|
|
120
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;
|
|
121
218
|
export declare function getKernel(): KernelModule;
|
|
122
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() {
|
package/dist/memory/agent.d.ts
CHANGED
|
@@ -10,53 +10,8 @@
|
|
|
10
10
|
* - SDK performs I/O and selection
|
|
11
11
|
* - LLM (Sonnet) acts as selector, not vector similarity
|
|
12
12
|
*/
|
|
13
|
-
import type { SessionData, MemoryEntry } from "./protocols.js";
|
|
14
|
-
|
|
15
|
-
* Memory metadata (matches kernel MemoryMetadata structure).
|
|
16
|
-
*/
|
|
17
|
-
export interface MemoryMetadata {
|
|
18
|
-
name: string;
|
|
19
|
-
description: string;
|
|
20
|
-
kind?: MemoryKind;
|
|
21
|
-
created_at: number;
|
|
22
|
-
updated_at: number;
|
|
23
|
-
session_id?: string;
|
|
24
|
-
user_role?: string;
|
|
25
|
-
expertise_level?: string;
|
|
26
|
-
preference_rule?: string;
|
|
27
|
-
approved_pattern?: string;
|
|
28
|
-
project_phase?: string;
|
|
29
|
-
relative_date?: string;
|
|
30
|
-
external_url?: string;
|
|
31
|
-
ticket_ref?: string;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Memory kind (4 types, mirroring Claude Code).
|
|
35
|
-
*/
|
|
36
|
-
export type MemoryKind = "user" | "feedback" | "project" | "reference";
|
|
37
|
-
/**
|
|
38
|
-
* Memory write request (SDK → kernel).
|
|
39
|
-
*/
|
|
40
|
-
export interface MemoryWriteRequest {
|
|
41
|
-
metadata: MemoryMetadata;
|
|
42
|
-
content: string;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Memory query request (kernel → SDK).
|
|
46
|
-
*/
|
|
47
|
-
export interface MemoryQuery {
|
|
48
|
-
current_context: string;
|
|
49
|
-
active_tools: string[];
|
|
50
|
-
already_surfaced: string[];
|
|
51
|
-
top_k: number;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Memory retrieval response (SDK → kernel).
|
|
55
|
-
*/
|
|
56
|
-
export interface MemoryRetrieval {
|
|
57
|
-
selected_memory_ids: string[];
|
|
58
|
-
selection_rationale: string;
|
|
59
|
-
}
|
|
13
|
+
import type { SessionData, MemoryEntry, MemoryKind, MemoryMetadata, MemoryWriteRequest, MemoryQuery, MemoryRetrieval } from "./protocols.js";
|
|
14
|
+
export type { MemoryKind, MemoryMetadata, MemoryWriteRequest, MemoryQuery, MemoryRetrieval, } from "./protocols.js";
|
|
60
15
|
/**
|
|
61
16
|
* Memory index entry (from MEMORY.md).
|
|
62
17
|
*/
|
|
@@ -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 {
|
|
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,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
|
-
|
|
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.
|
|
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.
|
|
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
|
-
|
|
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
|
}
|
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
|
+
}
|