@deepstrike/sdk 0.2.27 → 0.2.30
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 +99 -15
- package/dist/harness/public.d.ts +4 -0
- package/dist/harness/public.js +3 -0
- package/dist/index.d.ts +15 -80
- package/dist/index.js +27 -54
- package/dist/memory/public.d.ts +4 -0
- package/dist/memory/public.js +3 -0
- package/dist/os/public.d.ts +18 -0
- package/dist/os/public.js +14 -0
- package/dist/planes/public.d.ts +13 -0
- package/dist/planes/public.js +9 -0
- package/dist/providers/anthropic.d.ts +11 -2
- package/dist/providers/anthropic.js +14 -9
- package/dist/providers/factories.d.ts +31 -0
- package/dist/providers/factories.js +45 -0
- package/dist/providers/openai.d.ts +14 -2
- package/dist/providers/openai.js +11 -6
- package/dist/providers/public.d.ts +10 -0
- package/dist/providers/public.js +11 -0
- package/dist/runtime/facade.d.ts +49 -0
- package/dist/runtime/facade.js +68 -0
- package/dist/runtime/runner.d.ts +21 -1
- package/dist/runtime/runner.js +103 -62
- package/dist/workflow/public.d.ts +20 -0
- package/dist/workflow/public.js +15 -0
- package/package.json +54 -2
package/README.md
CHANGED
|
@@ -76,6 +76,67 @@ const reply = await collectText(runner.run({ sessionId: "chat-1", goal: "What is
|
|
|
76
76
|
|
|
77
77
|
Use `InMemorySessionLog` for process-local sessions or `FileSessionLog` when replay should survive restarts. `wake(sessionId)` resumes from the event log without inserting a duplicate `run_started` event.
|
|
78
78
|
|
|
79
|
+
### Package layout (v0.2.30)
|
|
80
|
+
|
|
81
|
+
The root export is the **intent layer** — what you reach for to run an agent, run a workflow, author a tool, or pick a provider (~30 symbols). Advanced machinery lives behind subpaths, so the common surface stays small and tree-shakeable:
|
|
82
|
+
|
|
83
|
+
| Import | Contains |
|
|
84
|
+
|--------|----------|
|
|
85
|
+
| `@deepstrike/sdk` | `runAgent` · `runFanout` · `RuntimeRunner` · `tool` · `LocalExecutionPlane` · `InMemorySessionLog`/`FileSessionLog` · `AnthropicProvider`/`OpenAIProvider`/`OpenAIResponsesProvider` · `createProvider` · `Governance` · `AgentPool` · core types |
|
|
86
|
+
| `@deepstrike/sdk/providers` | backend factories (`deepseek`, `kimi`, `qwen`, `glm`, `minimax`, `gemini`, `ollama`), profiles, `CircuitBreaker` |
|
|
87
|
+
| `@deepstrike/sdk/workflow` | `SubAgentOrchestrator`, `spawnStandalone`, reducers, contracts, handoff/modes, agent + spec types |
|
|
88
|
+
| `@deepstrike/sdk/planes` | `WorktreeExecutionPlane`, `ProcessSandboxPlane`, `McpProxyPlane`, `RemoteVpcPlane`, archive/credential stores |
|
|
89
|
+
| `@deepstrike/sdk/memory` | `DreamStore`, `WorkingMemory`, `InMemoryDreamStore`, `KnowledgeSource` |
|
|
90
|
+
| `@deepstrike/sdk/harness` | `SinglePassHarness`, `EvalLoopHarness`, `HarnessLoop`, `judge` |
|
|
91
|
+
| `@deepstrike/sdk/os` | profiles, `KernelPrimitivesDashboard`, signals, `PermissionManager`, replay-testing utilities |
|
|
92
|
+
|
|
93
|
+
> **Migration from 0.2.x:** the kernel-lowering converters (`*ToKernel`), low-level prompt/eval builders, and the `OpenAIChatProvider` alias are no longer exported from root; backend providers, planes, memory, harness, and OS utilities moved to the subpaths above. See [`MIGRATION-v0.2.300.md`](./MIGRATION-v0.2.300.md).
|
|
94
|
+
|
|
95
|
+
### Recipes — the canonical entry points
|
|
96
|
+
|
|
97
|
+
Most apps need one of three shapes. Start with the facades and drop down to `RuntimeRunner` only when you need streaming, signals, memory, or governance hooks.
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
import { runAgent, runFanout } from "@deepstrike/sdk"
|
|
101
|
+
|
|
102
|
+
// 1) Single agent — one prompt, one model, the text back.
|
|
103
|
+
const answer = await runAgent({ provider, goal: "What is 17 + 28?", tools: [add] })
|
|
104
|
+
|
|
105
|
+
// 2) Parallel fan-out → synthesize — N workers, then a synthesis pass, over the kernel-gated DAG.
|
|
106
|
+
// Bootstraps and tears down its own kernel, so it's safe from a stateless request handler.
|
|
107
|
+
const { synthesis } = await runFanout({
|
|
108
|
+
provider,
|
|
109
|
+
tasks: [
|
|
110
|
+
"Summarize the security posture of the auth module",
|
|
111
|
+
"Summarize the data-retention posture",
|
|
112
|
+
],
|
|
113
|
+
synthesize: "Combine the worker findings into one risk summary.",
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
// 3) Full control — sub-agents, governance, signals, streaming, resume → use RuntimeRunner directly.
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
`runFanout` is sugar over the **standalone `runWorkflow`** path: with no active `run()`, `runner.runWorkflow(spec)` auto-bootstraps a kernel that owns the DAG (governed · resumable), drives it, and tears it down — exactly what a Vercel/Lambda handler needs. See [Dynamic workflows](#dynamic-workflows). For parallel work you can also give each worker its own `RuntimeRunner`; `RuntimeRunner` carries per-run state, so **never share one instance across concurrent runs** — use a fresh instance per worker (or the `AgentPool` primitive).
|
|
120
|
+
|
|
121
|
+
### Deploying to serverless / bundlers
|
|
122
|
+
|
|
123
|
+
`@deepstrike/core` is a native N-API addon; its platform binary ships via `optionalDependencies`. Bundlers (Next.js/Vercel, webpack, esbuild) don't trace `.node` files by default, so the function fails at runtime with `Cannot find module '@deepstrike/core'`. Tell your bundler to treat the package as external and trace its files:
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
// next.config.ts (Next.js / Vercel)
|
|
127
|
+
const nextConfig = {
|
|
128
|
+
serverExternalPackages: ["@deepstrike/sdk"],
|
|
129
|
+
outputFileTracingIncludes: {
|
|
130
|
+
"/api/**": ["./node_modules/@deepstrike/**/*"],
|
|
131
|
+
},
|
|
132
|
+
}
|
|
133
|
+
export default nextConfig
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
- **webpack:** add `@deepstrike/core` (and `@deepstrike/sdk`) to `externals`, or use `node-loader` for `.node` files.
|
|
137
|
+
- **esbuild:** `--external:@deepstrike/core --external:@deepstrike/sdk` and ensure the platform binary is copied next to the bundle.
|
|
138
|
+
- **Docker/standalone:** the build host's platform binary must match the runtime's (e.g. build on `linux-x64-gnu` for Vercel). Alpine images need the `-musl` binary.
|
|
139
|
+
|
|
79
140
|
Streaming:
|
|
80
141
|
|
|
81
142
|
```typescript
|
|
@@ -161,9 +222,11 @@ const outcome = await runner.runWorkflow({
|
|
|
161
222
|
{ task: "Skeptic: which flags are real violations?", role: "verify", dependsOn: [0, 1, 2] },
|
|
162
223
|
],
|
|
163
224
|
})
|
|
164
|
-
// → { completed: ["wf-node0", … ], failed: [] }
|
|
225
|
+
// → { completed: ["wf-node0", … ], failed: [], outputs: { "wf-node3": "…" } }
|
|
165
226
|
```
|
|
166
227
|
|
|
228
|
+
`runWorkflow` works **standalone** — call it on a freshly-constructed runner (e.g. inside a stateless HTTP handler) and it auto-bootstraps a kernel that owns the DAG, drives it under the same governance/quota/attention policies a full `run()` gets, and tears it down on completion. Called *during* a `run()`, it instead drives the workflow on the active kernel. Either way every node's final text comes back in `outputs`, keyed by node agent-id. To resume an interrupted standalone run, pass the prior session id: `runner.resumeWorkflow(spec, { sessionId })`.
|
|
229
|
+
|
|
167
230
|
A node's `kind` selects the control-flow shape; the same executor drives them all, every spawn passing the syscall gate:
|
|
168
231
|
|
|
169
232
|
| Node `kind` | Behavior |
|
|
@@ -185,23 +248,44 @@ A node's `kind` selects the control-flow shape; the same executor drives them al
|
|
|
185
248
|
|
|
186
249
|
## Providers
|
|
187
250
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
| `OpenAIResponsesProvider` | OpenAI Responses API | Native `previous_response_id` continuation |
|
|
193
|
-
| `AnthropicProvider` | Anthropic API | Native SSE, `ThinkingDelta` support |
|
|
194
|
-
| `QwenProvider` | DashScope | `enable_thinking` via extensions |
|
|
195
|
-
| `DeepSeekProvider` | DeepSeek API | V4 thinking controls + reasoning replay across tool turns |
|
|
196
|
-
| `MiniMaxProvider` | MiniMax API | Anthropic-compatible M2.7/M2.5 path |
|
|
197
|
-
| `OllamaProvider` | Local Ollama | `http://localhost:11434` default |
|
|
198
|
-
| `KimiProvider` | Moonshot API | K2.6 default; K2.5 also supported |
|
|
251
|
+
The root package exports the three base providers — `AnthropicProvider`, `OpenAIProvider`,
|
|
252
|
+
`OpenAIResponsesProvider` — plus `createProvider`. **Every other backend is a factory function** in
|
|
253
|
+
`@deepstrike/sdk/providers`: one per backend, with a `protocol` option where a backend speaks both the
|
|
254
|
+
OpenAI- and Anthropic-compatible wire.
|
|
199
255
|
|
|
200
|
-
|
|
256
|
+
```typescript
|
|
257
|
+
import { deepseek, kimi, minimax } from "@deepstrike/sdk/providers"
|
|
201
258
|
|
|
202
|
-
|
|
259
|
+
const ds = deepseek({ apiKey }) // OpenAI-compatible wire (default)
|
|
260
|
+
const dsA = deepseek({ apiKey, protocol: "anthropic" }) // Anthropic-compatible wire
|
|
261
|
+
const mm = minimax({ apiKey }) // MiniMax defaults to the Anthropic wire
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
| Entry | Import from | Backend |
|
|
265
|
+
|-------|-------------|---------|
|
|
266
|
+
| `OpenAIProvider` | root | OpenAI Chat Completions (and any OpenAI-compatible `/v1`) |
|
|
267
|
+
| `OpenAIResponsesProvider` | root | OpenAI Responses API (`previous_response_id` continuation) |
|
|
268
|
+
| `AnthropicProvider` | root | Anthropic Messages API (`ThinkingDelta` support) |
|
|
269
|
+
| `deepseek` · `kimi` · `qwen` · `glm` · `minimax` · `gemini` · `ollama` | `@deepstrike/sdk/providers` | the respective vendor (factory functions) |
|
|
270
|
+
|
|
271
|
+
Providers take an **options object** and share a `CircuitBreaker`. `extensions` are forwarded in both
|
|
272
|
+
`complete()` and `stream()`; SDK-owned fields (`model`, `messages`, `tools`, streaming flags) stay protected.
|
|
273
|
+
|
|
274
|
+
**Custom OpenAI-compatible endpoint** (MiMo, DeepSeek, Kimi, Qwen, GLM via their `/v1` base URL): construct
|
|
275
|
+
`OpenAIProvider` with an options object — no more positional `baseURL` hole:
|
|
276
|
+
|
|
277
|
+
```typescript
|
|
278
|
+
import { OpenAIProvider } from "@deepstrike/sdk"
|
|
279
|
+
|
|
280
|
+
const provider = new OpenAIProvider({
|
|
281
|
+
apiKey,
|
|
282
|
+
model: "mimo-v2.5-pro",
|
|
283
|
+
baseURL: "https://token-plan-cn.xiaomimimo.com/v1",
|
|
284
|
+
})
|
|
285
|
+
```
|
|
203
286
|
|
|
204
|
-
|
|
287
|
+
Prefer a dedicated backend class from `@deepstrike/sdk/providers` when one exists — they default the base
|
|
288
|
+
URL and add backend-specific reasoning handling. Any model can also be selected through the catalog: `createProvider` picks the protocol/endpoint for you:
|
|
205
289
|
|
|
206
290
|
```typescript
|
|
207
291
|
import { createProvider } from "@deepstrike/sdk"
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { SinglePassHarness, EvalLoopHarness, HarnessLoop } from "./harness.js";
|
|
2
|
+
export type { HarnessRequest, HarnessOutcome, HarnessLoopOptions, QualityGate, CriterionResult, HarnessEvent, VerdictFn, } from "./harness.js";
|
|
3
|
+
export { judge } from "../runtime/eval.js";
|
|
4
|
+
export type { Criterion, Verdict, VerdictDetail, JudgeArgs } from "../runtime/eval.js";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,90 +1,25 @@
|
|
|
1
|
+
export { runAgent, runFanout } from "./runtime/facade.js";
|
|
2
|
+
export type { RunAgentOptions, RunFanoutOptions } from "./runtime/facade.js";
|
|
1
3
|
export { RuntimeRunner, collectText } from "./runtime/runner.js";
|
|
2
|
-
export type { RuntimeOptions
|
|
3
|
-
export { builtinReducers, resolveReducer } from "./runtime/reducers.js";
|
|
4
|
-
export type { Reducer, ReducerRegistry, ReducerInput } from "./runtime/reducers.js";
|
|
5
|
-
export { loopInstruction, classifyInstruction, judgeGoal, extractLoopContinue, extractClassifyBranch, extractJudgeWinner, } from "./runtime/workflow-control-flow.js";
|
|
6
|
-
export { WorktreeExecutionPlane, GitWorktreeManager } from "./runtime/worktree-plane.js";
|
|
7
|
-
export type { WorktreeManager } from "./runtime/worktree-plane.js";
|
|
8
|
-
export { FileWorkflowStore } from "./runtime/workflow-store.js";
|
|
9
|
-
export type { MemoryPolicy, MemoryWriteRateLimit, ResourceQuota } from "./kernel.js";
|
|
10
|
-
export { KernelPrimitivesDashboard } from "./runtime/kernel-primitives-dashboard.js";
|
|
11
|
-
export { FilteredExecutionPlane } from "./runtime/filtered-plane.js";
|
|
12
|
-
export { SubAgentOrchestrator, defaultSubAgentOrchestrator, spawnStandalone } from "./runtime/sub-agent-orchestrator.js";
|
|
13
|
-
export type { SubAgentRunContext } from "./runtime/sub-agent-orchestrator.js";
|
|
4
|
+
export type { RuntimeOptions } from "./runtime/runner.js";
|
|
14
5
|
export { LocalExecutionPlane } from "./runtime/execution-plane.js";
|
|
15
6
|
export type { ExecutionPlane, RunContext } from "./runtime/execution-plane.js";
|
|
16
7
|
export { InMemorySessionLog, FileSessionLog } from "./runtime/session-log.js";
|
|
17
8
|
export type { SessionLog, SessionEvent } from "./runtime/session-log.js";
|
|
18
|
-
export {
|
|
19
|
-
export type { ReplayProviderOpts } from "./runtime/replay-provider.js";
|
|
20
|
-
export { extractRecordedMessages } from "./runtime/replay-fixture.js";
|
|
21
|
-
export { judge, buildEvalMessages, parseVerdict, verdictOutputSchema } from "./runtime/eval.js";
|
|
22
|
-
export type { Criterion, Verdict, VerdictDetail, JudgeArgs } from "./runtime/eval.js";
|
|
23
|
-
export { DEFAULT_NATIVE_ATTENTION_POLICY, DEFAULT_NATIVE_GOVERNANCE_POLICY, assertNativeProfile, osProfile, } from "./runtime/os-profile.js";
|
|
24
|
-
export type { NativeOsProfile, OsProfileId } from "./runtime/os-profile.js";
|
|
25
|
-
export { rebuildOsSnapshotFromSessionEvents, sessionLogHasRequiredCategories, } from "./runtime/os-snapshot.js";
|
|
26
|
-
export type { OsSnapshot } from "./runtime/os-snapshot.js";
|
|
27
|
-
export { categoryForKind, kernelObservationToSessionEvent } from "./runtime/kernel-event-log.js";
|
|
28
|
-
export type { KernelEventCategory } from "./runtime/kernel-event-log.js";
|
|
29
|
-
export { NullArchiveStore, FileArchiveStore } from "./runtime/archive.js";
|
|
30
|
-
export type { ArchiveStore } from "./runtime/archive.js";
|
|
31
|
-
export { EnvCredentialVault, InMemoryCredentialVault, ChainedCredentialVault } from "./runtime/credential-vault.js";
|
|
32
|
-
export type { CredentialVault } from "./runtime/credential-vault.js";
|
|
33
|
-
export { ProcessSandboxPlane } from "./runtime/process-sandbox-plane.js";
|
|
34
|
-
export type { SandboxOptions } from "./runtime/process-sandbox-plane.js";
|
|
35
|
-
export { McpProxyPlane } from "./runtime/mcp-proxy-plane.js";
|
|
36
|
-
export type { McpServerConfig } from "./runtime/mcp-proxy-plane.js";
|
|
37
|
-
export { RemoteVpcPlane } from "./runtime/remote-vpc-plane.js";
|
|
38
|
-
export type { RemoteVpcOptions } from "./runtime/remote-vpc-plane.js";
|
|
39
|
-
export { AnthropicProvider } from "./providers/anthropic.js";
|
|
40
|
-
export { OpenAIChatProvider, OpenAIProvider } from "./providers/openai.js";
|
|
41
|
-
export { DeepSeekProvider, DeepSeekAnthropicProvider } from "./providers/deepseek.js";
|
|
42
|
-
export { KimiProvider, KimiAnthropicProvider } from "./providers/kimi.js";
|
|
43
|
-
export { QwenProvider, QwenAnthropicProvider } from "./providers/qwen.js";
|
|
44
|
-
export { GLMProvider, GLMAnthropicProvider } from "./providers/glm.js";
|
|
45
|
-
export { GeminiProvider } from "./providers/gemini.js";
|
|
46
|
-
export { MiniMaxAnthropicProvider, MiniMaxOpenAIProvider } from "./providers/minimax.js";
|
|
47
|
-
export { OllamaProvider } from "./providers/ollama.js";
|
|
48
|
-
export { CircuitBreaker, normalizeToolCall } from "./providers/base.js";
|
|
49
|
-
export { OpenAIChatAdapter } from "./providers/openai-chat.js";
|
|
50
|
-
export { OpenAIResponsesAdapter, OpenAIResponsesProvider } from "./providers/openai-responses.js";
|
|
51
|
-
export type { OpenAIResponsesRunState } from "./providers/openai-responses.js";
|
|
52
|
-
export { endpointProfiles, modelProfiles, getModelProfile } from "./providers/profiles.js";
|
|
53
|
-
export type { ModelProfileId, ProviderId } from "./providers/profiles.js";
|
|
54
|
-
export { createProvider } from "./providers/catalog.js";
|
|
55
|
-
export type { CreateProviderOptions, EndpointProfileId } from "./providers/catalog.js";
|
|
56
|
-
export { ProviderReplayValidationError, DEGRADED_REASONING_PLACEHOLDER } from "./providers/replay-validator.js";
|
|
57
|
-
export { assessProviderReplayability, peekProviderReplay, seedProviderReplayFromEvents, isReplayCompatibleWithProvider, } from "./runtime/provider-replay.js";
|
|
58
|
-
export { tool, streamingTool, executeTools, readFile, validateToolArguments } from "./tools/index.js";
|
|
9
|
+
export { tool, streamingTool } from "./tools/index.js";
|
|
59
10
|
export type { RegisteredTool, ToolExecContext } from "./tools/index.js";
|
|
60
11
|
export { safeTool, ok, fail, ToolError, formatToolError } from "./tools/errors.js";
|
|
61
12
|
export type { ToolEnvelope, ToolEnvelopeOk, ToolEnvelopeFail } from "./tools/errors.js";
|
|
62
|
-
export {
|
|
63
|
-
export type {
|
|
64
|
-
export {
|
|
65
|
-
export {
|
|
66
|
-
export
|
|
67
|
-
export
|
|
68
|
-
export {
|
|
69
|
-
export {
|
|
70
|
-
export type { RuntimeSignal, SignalSource } from "./signals/types.js";
|
|
71
|
-
export { PermissionManager, PermissionMode } from "./safety/permissions.js";
|
|
72
|
-
export type { PermissionDecision, Permission } from "./safety/permissions.js";
|
|
73
|
-
export { Governance, governancePolicyToKernelEvent } from "./governance.js";
|
|
13
|
+
export { AnthropicProvider } from "./providers/anthropic.js";
|
|
14
|
+
export type { AnthropicProviderConfig } from "./providers/anthropic.js";
|
|
15
|
+
export { OpenAIProvider } from "./providers/openai.js";
|
|
16
|
+
export type { OpenAIProviderOptions } from "./providers/openai.js";
|
|
17
|
+
export { OpenAIResponsesProvider } from "./providers/openai-responses.js";
|
|
18
|
+
export { createProvider } from "./providers/catalog.js";
|
|
19
|
+
export type { CreateProviderOptions, EndpointProfileId } from "./providers/catalog.js";
|
|
20
|
+
export { Governance } from "./governance.js";
|
|
74
21
|
export type { GovernanceVerdict, GovernancePolicy, GovernanceConstraint } from "./governance.js";
|
|
75
|
-
export { SinglePassHarness, EvalLoopHarness, HarnessLoop } from "./harness/harness.js";
|
|
76
|
-
export type { HarnessRequest, HarnessOutcome, HarnessLoopOptions, QualityGate, CriterionResult, HarnessEvent, VerdictFn } from "./harness/harness.js";
|
|
77
|
-
export type { Message, ToolCall, ToolResult, ToolSchema, ContentPart, TextPart, ImagePart, AudioPart, StreamEvent, TextDelta, ThinkingDelta, ToolCallEvent, ToolChunk, ToolDeltaEvent, ToolSuspendEvent, ToolResultEvent, ToolAuditFailedEvent, DoneEvent, ErrorEvent, PermissionRequestEvent, PermissionResolvedEvent, PermissionResponse, LLMProvider, RetryConfig, TokenUsage, ProviderToolSpec, ProviderRunState, ProviderReplay, RenderedContext, ReplayabilityAssessment, CacheBreakpointStrategy, } from "./types.js";
|
|
78
|
-
export type { AgentCapabilityFilter, AgentIdentity, AgentIsolation, AgentRunSpec, AgentProcessChangedObservation, ContextInheritance, KernelAgentRole, LoopResult, MilestoneCheckResult, MilestoneContract, MilestonePhase, MilestonePolicy, SubAgentResult, TerminationReason, WorkflowSpec, WorkflowNodeSpec, WorkflowTaskSpec, WorkflowSpawnInfo, } from "./types/agent.js";
|
|
79
|
-
export { agentIdentitySub, agentRunSpecToKernel, milestoneCheckFail, milestoneCheckPass, milestoneCheckResultToKernel, subAgentResultToKernel, workflowSpecToKernel, workflowNodeSpecToKernel, submitWorkflowNodesToKernel, submitWorkflowToKernel, submitWorkflowNodesTool, startWorkflowTool, fanoutSynthesize, generateAndFilter, verifyRules, genEval, } from "./types/agent.js";
|
|
80
|
-
export type { AcceptanceCriterion, VerificationContract, ContractCheckResult, } from "./collaboration/contract.js";
|
|
81
|
-
export { ContractBuilder, formatContractForSystemPrompt, contractToCriteriaStrings, } from "./collaboration/contract.js";
|
|
82
22
|
export { AgentPool } from "./collaboration/pool.js";
|
|
83
|
-
export type {
|
|
84
|
-
export {
|
|
85
|
-
export {
|
|
86
|
-
export type { ContractOutcome, ContractHarnessOptions, Violation } from "./collaboration/harness.js";
|
|
87
|
-
export { HandoffBus } from "./collaboration/handoff.js";
|
|
88
|
-
export type { HandoffArtifact, ContractOutcomeInput } from "./collaboration/handoff.js";
|
|
89
|
-
export { CreatorVerifierMode, OrchestrationMode } from "./collaboration/modes/creator-verifier.js";
|
|
90
|
-
export type { CreatorVerifierMetrics } from "./collaboration/modes/creator-verifier.js";
|
|
23
|
+
export type { RuntimeSignal, SignalSource } from "./signals/types.js";
|
|
24
|
+
export type { Message, ToolCall, ToolResult, ToolSchema, ContentPart, TextPart, ImagePart, AudioPart, StreamEvent, TextDelta, ThinkingDelta, ToolCallEvent, ToolChunk, ToolDeltaEvent, ToolSuspendEvent, ToolResultEvent, ToolAuditFailedEvent, DoneEvent, ErrorEvent, PermissionRequestEvent, PermissionResolvedEvent, PermissionResponse, LLMProvider, RetryConfig, TokenUsage, } from "./types.js";
|
|
25
|
+
export type { WorkflowSpec, WorkflowNodeSpec, } from "./types/agent.js";
|
package/dist/index.js
CHANGED
|
@@ -1,60 +1,33 @@
|
|
|
1
|
-
//
|
|
1
|
+
// ╔══════════════════════════════════════════════════════════════════════════╗
|
|
2
|
+
// ║ @deepstrike/sdk — root surface (v0.2.30). ║
|
|
3
|
+
// ║ ║
|
|
4
|
+
// ║ This is the intent layer: run an agent, run a workflow, author a tool, ║
|
|
5
|
+
// ║ pick a provider. Advanced machinery lives behind subpaths: ║
|
|
6
|
+
// ║ @deepstrike/sdk/providers — backend provider classes + profiles ║
|
|
7
|
+
// ║ @deepstrike/sdk/workflow — orchestration, reducers, contracts, specs ║
|
|
8
|
+
// ║ @deepstrike/sdk/planes — worktree / sandbox / mcp / vpc planes ║
|
|
9
|
+
// ║ @deepstrike/sdk/memory — dream + working memory, knowledge sources ║
|
|
10
|
+
// ║ @deepstrike/sdk/harness — eval harnesses + judge ║
|
|
11
|
+
// ║ @deepstrike/sdk/os — profiles, diagnostics, signals, replay tests ║
|
|
12
|
+
// ╚══════════════════════════════════════════════════════════════════════════╝
|
|
13
|
+
// ── Start here: the canonical entry points ─────────────────────────────────
|
|
14
|
+
export { runAgent, runFanout } from "./runtime/facade.js";
|
|
2
15
|
export { RuntimeRunner, collectText } from "./runtime/runner.js";
|
|
3
|
-
|
|
4
|
-
export { loopInstruction, classifyInstruction, judgeGoal, extractLoopContinue, extractClassifyBranch, extractJudgeWinner, } from "./runtime/workflow-control-flow.js";
|
|
5
|
-
export { WorktreeExecutionPlane, GitWorktreeManager } from "./runtime/worktree-plane.js";
|
|
6
|
-
export { FileWorkflowStore } from "./runtime/workflow-store.js";
|
|
7
|
-
export { KernelPrimitivesDashboard } from "./runtime/kernel-primitives-dashboard.js";
|
|
8
|
-
export { FilteredExecutionPlane } from "./runtime/filtered-plane.js";
|
|
9
|
-
export { SubAgentOrchestrator, defaultSubAgentOrchestrator, spawnStandalone } from "./runtime/sub-agent-orchestrator.js";
|
|
16
|
+
// ── Execution plane + session log (the defaults) ────────────────────────────
|
|
10
17
|
export { LocalExecutionPlane } from "./runtime/execution-plane.js";
|
|
11
18
|
export { InMemorySessionLog, FileSessionLog } from "./runtime/session-log.js";
|
|
12
|
-
|
|
13
|
-
export {
|
|
14
|
-
export {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
export { NullArchiveStore, FileArchiveStore } from "./runtime/archive.js";
|
|
19
|
-
export { EnvCredentialVault, InMemoryCredentialVault, ChainedCredentialVault } from "./runtime/credential-vault.js";
|
|
20
|
-
export { ProcessSandboxPlane } from "./runtime/process-sandbox-plane.js";
|
|
21
|
-
export { McpProxyPlane } from "./runtime/mcp-proxy-plane.js";
|
|
22
|
-
export { RemoteVpcPlane } from "./runtime/remote-vpc-plane.js";
|
|
23
|
-
// ── Providers ─────────────────────────────────────────────────────────────
|
|
19
|
+
// ── Tool authoring ──────────────────────────────────────────────────────────
|
|
20
|
+
export { tool, streamingTool } from "./tools/index.js";
|
|
21
|
+
export { safeTool, ok, fail, ToolError, formatToolError } from "./tools/errors.js";
|
|
22
|
+
// ── Providers (base classes + the universal factory) ────────────────────────
|
|
23
|
+
// Any backend — including a custom OpenAI-compatible endpoint — is reachable via `createProvider`.
|
|
24
|
+
// Backend-specific classes (DeepSeek/Kimi/Qwen/GLM/Gemini/Ollama/MiniMax) live in `@deepstrike/sdk/providers`.
|
|
24
25
|
export { AnthropicProvider } from "./providers/anthropic.js";
|
|
25
|
-
export {
|
|
26
|
-
export {
|
|
27
|
-
export { KimiProvider, KimiAnthropicProvider } from "./providers/kimi.js";
|
|
28
|
-
export { QwenProvider, QwenAnthropicProvider } from "./providers/qwen.js";
|
|
29
|
-
export { GLMProvider, GLMAnthropicProvider } from "./providers/glm.js";
|
|
30
|
-
export { GeminiProvider } from "./providers/gemini.js";
|
|
31
|
-
export { MiniMaxAnthropicProvider, MiniMaxOpenAIProvider } from "./providers/minimax.js";
|
|
32
|
-
export { OllamaProvider } from "./providers/ollama.js";
|
|
33
|
-
export { CircuitBreaker, normalizeToolCall } from "./providers/base.js";
|
|
34
|
-
export { OpenAIChatAdapter } from "./providers/openai-chat.js";
|
|
35
|
-
export { OpenAIResponsesAdapter, OpenAIResponsesProvider } from "./providers/openai-responses.js";
|
|
36
|
-
export { endpointProfiles, modelProfiles, getModelProfile } from "./providers/profiles.js";
|
|
26
|
+
export { OpenAIProvider } from "./providers/openai.js";
|
|
27
|
+
export { OpenAIResponsesProvider } from "./providers/openai-responses.js";
|
|
37
28
|
export { createProvider } from "./providers/catalog.js";
|
|
38
|
-
|
|
39
|
-
export {
|
|
40
|
-
// ──
|
|
41
|
-
|
|
42
|
-
export { safeTool, ok, fail, ToolError, formatToolError } from "./tools/errors.js";
|
|
43
|
-
export { scanSkillDir, readSkillFile } from "./skills/loader.js";
|
|
44
|
-
// ── Memory ─────────────────────────────────────────────────────────────────
|
|
45
|
-
export { WorkingMemory } from "./memory/working.js";
|
|
46
|
-
export { InMemoryDreamStore } from "./memory/in-memory-store.js";
|
|
47
|
-
export { ScheduledPrompt } from "./signals/scheduled.js";
|
|
48
|
-
export { SignalGateway } from "./signals/gateway.js";
|
|
49
|
-
// ── Safety & Governance ────────────────────────────────────────────────────
|
|
50
|
-
export { PermissionManager, PermissionMode } from "./safety/permissions.js";
|
|
51
|
-
export { Governance, governancePolicyToKernelEvent } from "./governance.js";
|
|
52
|
-
// ── Harness ────────────────────────────────────────────────────────────────
|
|
53
|
-
export { SinglePassHarness, EvalLoopHarness, HarnessLoop } from "./harness/harness.js";
|
|
54
|
-
export { agentIdentitySub, agentRunSpecToKernel, milestoneCheckFail, milestoneCheckPass, milestoneCheckResultToKernel, subAgentResultToKernel, workflowSpecToKernel, workflowNodeSpecToKernel, submitWorkflowNodesToKernel, submitWorkflowToKernel, submitWorkflowNodesTool, startWorkflowTool, fanoutSynthesize, generateAndFilter, verifyRules, genEval, } from "./types/agent.js";
|
|
55
|
-
export { ContractBuilder, formatContractForSystemPrompt, contractToCriteriaStrings, } from "./collaboration/contract.js";
|
|
29
|
+
// ── Governance ──────────────────────────────────────────────────────────────
|
|
30
|
+
export { Governance } from "./governance.js";
|
|
31
|
+
// ── Multi-agent primitive ───────────────────────────────────────────────────
|
|
32
|
+
// Parallel fan-out / sub-agent delegation. The full orchestration layer is in `@deepstrike/sdk/workflow`.
|
|
56
33
|
export { AgentPool } from "./collaboration/pool.js";
|
|
57
|
-
export { KERNEL_ROLE_MAP } from "./collaboration/pool.js";
|
|
58
|
-
export { ContractDrivenHarness } from "./collaboration/harness.js";
|
|
59
|
-
export { HandoffBus } from "./collaboration/handoff.js";
|
|
60
|
-
export { CreatorVerifierMode, OrchestrationMode } from "./collaboration/modes/creator-verifier.js";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { WorkingMemory } from "./working.js";
|
|
2
|
+
export { InMemoryDreamStore } from "./in-memory-store.js";
|
|
3
|
+
export type { DreamStore, DreamResult, SessionData, SessionMessage, MemoryEntry, CurationResult, CurationStats, MemoryWriteRequest, MemoryQuery, MemoryRetrieval, MemoryMetadata, MemoryKind, } from "./protocols.js";
|
|
4
|
+
export type { KnowledgeSource } from "../knowledge/source.js";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { DEFAULT_NATIVE_ATTENTION_POLICY, DEFAULT_NATIVE_GOVERNANCE_POLICY, assertNativeProfile, osProfile, } from "../runtime/os-profile.js";
|
|
2
|
+
export type { NativeOsProfile, OsProfileId } from "../runtime/os-profile.js";
|
|
3
|
+
export { rebuildOsSnapshotFromSessionEvents, sessionLogHasRequiredCategories } from "../runtime/os-snapshot.js";
|
|
4
|
+
export type { OsSnapshot } from "../runtime/os-snapshot.js";
|
|
5
|
+
export type { KernelEventCategory } from "../runtime/kernel-event-log.js";
|
|
6
|
+
export { KernelPrimitivesDashboard } from "../runtime/kernel-primitives-dashboard.js";
|
|
7
|
+
export type { MemoryPolicy, MemoryWriteRateLimit, ResourceQuota } from "../kernel.js";
|
|
8
|
+
export type { SchedulerBudget } from "../runtime/runner.js";
|
|
9
|
+
export { ScheduledPrompt } from "../signals/scheduled.js";
|
|
10
|
+
export { SignalGateway } from "../signals/gateway.js";
|
|
11
|
+
export { PermissionManager, PermissionMode } from "../safety/permissions.js";
|
|
12
|
+
export type { PermissionDecision, Permission } from "../safety/permissions.js";
|
|
13
|
+
export { ReplayProvider } from "../runtime/replay-provider.js";
|
|
14
|
+
export type { ReplayProviderOpts } from "../runtime/replay-provider.js";
|
|
15
|
+
export { extractRecordedMessages } from "../runtime/replay-fixture.js";
|
|
16
|
+
export { ProviderReplayValidationError, DEGRADED_REASONING_PLACEHOLDER } from "../providers/replay-validator.js";
|
|
17
|
+
export { assessProviderReplayability, peekProviderReplay, seedProviderReplayFromEvents, isReplayCompatibleWithProvider, } from "../runtime/provider-replay.js";
|
|
18
|
+
export type { ReplayabilityAssessment } from "../types.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// `@deepstrike/sdk/os` — Agent-OS diagnostics, profiles, signal/permission machinery, replay-testing,
|
|
2
|
+
// and the scheduler/quota/policy types referenced by advanced `RuntimeOptions` fields.
|
|
3
|
+
export { DEFAULT_NATIVE_ATTENTION_POLICY, DEFAULT_NATIVE_GOVERNANCE_POLICY, assertNativeProfile, osProfile, } from "../runtime/os-profile.js";
|
|
4
|
+
export { rebuildOsSnapshotFromSessionEvents, sessionLogHasRequiredCategories } from "../runtime/os-snapshot.js";
|
|
5
|
+
export { KernelPrimitivesDashboard } from "../runtime/kernel-primitives-dashboard.js";
|
|
6
|
+
// Signals + SDK-side permissions.
|
|
7
|
+
export { ScheduledPrompt } from "../signals/scheduled.js";
|
|
8
|
+
export { SignalGateway } from "../signals/gateway.js";
|
|
9
|
+
export { PermissionManager, PermissionMode } from "../safety/permissions.js";
|
|
10
|
+
// Replay-based testing utilities.
|
|
11
|
+
export { ReplayProvider } from "../runtime/replay-provider.js";
|
|
12
|
+
export { extractRecordedMessages } from "../runtime/replay-fixture.js";
|
|
13
|
+
export { ProviderReplayValidationError, DEGRADED_REASONING_PLACEHOLDER } from "../providers/replay-validator.js";
|
|
14
|
+
export { assessProviderReplayability, peekProviderReplay, seedProviderReplayFromEvents, isReplayCompatibleWithProvider, } from "../runtime/provider-replay.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { WorktreeExecutionPlane, GitWorktreeManager } from "../runtime/worktree-plane.js";
|
|
2
|
+
export type { WorktreeManager } from "../runtime/worktree-plane.js";
|
|
3
|
+
export { FilteredExecutionPlane } from "../runtime/filtered-plane.js";
|
|
4
|
+
export { ProcessSandboxPlane } from "../runtime/process-sandbox-plane.js";
|
|
5
|
+
export type { SandboxOptions } from "../runtime/process-sandbox-plane.js";
|
|
6
|
+
export { McpProxyPlane } from "../runtime/mcp-proxy-plane.js";
|
|
7
|
+
export type { McpServerConfig } from "../runtime/mcp-proxy-plane.js";
|
|
8
|
+
export { RemoteVpcPlane } from "../runtime/remote-vpc-plane.js";
|
|
9
|
+
export type { RemoteVpcOptions } from "../runtime/remote-vpc-plane.js";
|
|
10
|
+
export { NullArchiveStore, FileArchiveStore } from "../runtime/archive.js";
|
|
11
|
+
export type { ArchiveStore } from "../runtime/archive.js";
|
|
12
|
+
export { EnvCredentialVault, InMemoryCredentialVault, ChainedCredentialVault } from "../runtime/credential-vault.js";
|
|
13
|
+
export type { CredentialVault } from "../runtime/credential-vault.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// `@deepstrike/sdk/planes` — advanced execution planes, archive stores, and credential vaults.
|
|
2
|
+
// The root package exports `LocalExecutionPlane`; specialized planes live here.
|
|
3
|
+
export { WorktreeExecutionPlane, GitWorktreeManager } from "../runtime/worktree-plane.js";
|
|
4
|
+
export { FilteredExecutionPlane } from "../runtime/filtered-plane.js";
|
|
5
|
+
export { ProcessSandboxPlane } from "../runtime/process-sandbox-plane.js";
|
|
6
|
+
export { McpProxyPlane } from "../runtime/mcp-proxy-plane.js";
|
|
7
|
+
export { RemoteVpcPlane } from "../runtime/remote-vpc-plane.js";
|
|
8
|
+
export { NullArchiveStore, FileArchiveStore } from "../runtime/archive.js";
|
|
9
|
+
export { EnvCredentialVault, InMemoryCredentialVault, ChainedCredentialVault } from "../runtime/credential-vault.js";
|
|
@@ -3,14 +3,23 @@ interface AnthropicProviderOptions {
|
|
|
3
3
|
baseURL?: string;
|
|
4
4
|
authMode?: "api-key" | "bearer";
|
|
5
5
|
}
|
|
6
|
+
/** Options-object form for `AnthropicProvider` — the recommended constructor shape. */
|
|
7
|
+
export interface AnthropicProviderConfig extends AnthropicProviderOptions {
|
|
8
|
+
apiKey: string;
|
|
9
|
+
model?: string;
|
|
10
|
+
retry?: {
|
|
11
|
+
maxRetries: number;
|
|
12
|
+
baseDelay: number;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
6
15
|
export declare class AnthropicProvider implements LLMProvider {
|
|
7
|
-
protected readonly model: string;
|
|
8
16
|
private client;
|
|
9
17
|
private circuit;
|
|
10
18
|
private maxRetries;
|
|
11
19
|
private baseDelay;
|
|
20
|
+
protected readonly model: string;
|
|
12
21
|
private nativeAssistantBlocks;
|
|
13
|
-
constructor(
|
|
22
|
+
constructor(apiKeyOrConfig: string | AnthropicProviderConfig, model?: string, retry?: {
|
|
14
23
|
maxRetries: number;
|
|
15
24
|
baseDelay: number;
|
|
16
25
|
}, options?: AnthropicProviderOptions);
|
|
@@ -13,23 +13,28 @@ const CLAUDE_POLICIES = {
|
|
|
13
13
|
"claude-3-5-haiku-latest": { maxTurns: 15 },
|
|
14
14
|
};
|
|
15
15
|
export class AnthropicProvider {
|
|
16
|
-
model;
|
|
17
16
|
client;
|
|
18
17
|
circuit;
|
|
19
18
|
maxRetries;
|
|
20
19
|
baseDelay;
|
|
20
|
+
model;
|
|
21
21
|
nativeAssistantBlocks = new Map();
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
// Accepts the options object (`new AnthropicProvider({ apiKey, model, baseURL })`) or the legacy
|
|
23
|
+
// positional form (still used by the Anthropic-compatible backend subclasses' `super(...)` calls).
|
|
24
|
+
constructor(apiKeyOrConfig, model = "claude-sonnet-4-6", retry = { maxRetries: 3, baseDelay: 1000 }, options = {}) {
|
|
25
|
+
const c = typeof apiKeyOrConfig === "string"
|
|
26
|
+
? { apiKey: apiKeyOrConfig, model, retry, ...options }
|
|
27
|
+
: { model: "claude-sonnet-4-6", retry: { maxRetries: 3, baseDelay: 1000 }, ...apiKeyOrConfig };
|
|
28
|
+
this.model = c.model ?? "claude-sonnet-4-6";
|
|
24
29
|
this.client = withServerRuntimeGuard(() => new Anthropic({
|
|
25
|
-
...(
|
|
26
|
-
? { authToken: apiKey, apiKey: null }
|
|
27
|
-
: { apiKey, authToken: null }),
|
|
28
|
-
...(
|
|
30
|
+
...(c.authMode === "bearer"
|
|
31
|
+
? { authToken: c.apiKey, apiKey: null }
|
|
32
|
+
: { apiKey: c.apiKey, authToken: null }),
|
|
33
|
+
...(c.baseURL ? { baseURL: c.baseURL } : {}),
|
|
29
34
|
}));
|
|
30
35
|
this.circuit = new CircuitBreaker();
|
|
31
|
-
this.maxRetries = retry
|
|
32
|
-
this.baseDelay = retry
|
|
36
|
+
this.maxRetries = c.retry?.maxRetries ?? 3;
|
|
37
|
+
this.baseDelay = c.retry?.baseDelay ?? 1000;
|
|
33
38
|
}
|
|
34
39
|
runtimePolicy() {
|
|
35
40
|
return CLAUDE_POLICIES[this.model] ?? {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { LLMProvider } from "../types.js";
|
|
2
|
+
/** Options for a backend provider factory. `protocol` only applies to backends with both wires. */
|
|
3
|
+
export interface BackendProviderOptions {
|
|
4
|
+
apiKey: string;
|
|
5
|
+
model?: string;
|
|
6
|
+
/** Override the endpoint base URL (defaults to the backend's profile for the chosen protocol). */
|
|
7
|
+
baseURL?: string;
|
|
8
|
+
retry?: {
|
|
9
|
+
maxRetries: number;
|
|
10
|
+
baseDelay: number;
|
|
11
|
+
};
|
|
12
|
+
/** Wire protocol for dual-protocol backends. Defaults per backend (see each factory). */
|
|
13
|
+
protocol?: "openai" | "anthropic";
|
|
14
|
+
}
|
|
15
|
+
/** DeepSeek. Defaults to the OpenAI-compatible wire (richer reasoning-replay handling). */
|
|
16
|
+
export declare function deepseek(o: BackendProviderOptions): LLMProvider;
|
|
17
|
+
/** Moonshot Kimi. Defaults to the OpenAI-compatible wire. */
|
|
18
|
+
export declare function kimi(o: BackendProviderOptions): LLMProvider;
|
|
19
|
+
/** Alibaba Qwen / DashScope. Defaults to the OpenAI-compatible (DashScope) wire. */
|
|
20
|
+
export declare function qwen(o: BackendProviderOptions): LLMProvider;
|
|
21
|
+
/** Zhipu GLM. Defaults to the OpenAI-compatible wire. */
|
|
22
|
+
export declare function glm(o: BackendProviderOptions): LLMProvider;
|
|
23
|
+
/** MiniMax. Defaults to the Anthropic-compatible wire (the primary M2.x path). */
|
|
24
|
+
export declare function minimax(o: BackendProviderOptions): LLMProvider;
|
|
25
|
+
/** Google Gemini (single wire). */
|
|
26
|
+
export declare function gemini(o: Omit<BackendProviderOptions, "protocol">): LLMProvider;
|
|
27
|
+
/** Local Ollama (single wire, no API key). */
|
|
28
|
+
export declare function ollama(o?: {
|
|
29
|
+
model?: string;
|
|
30
|
+
baseURL?: string;
|
|
31
|
+
}): LLMProvider;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { DeepSeekProvider, DeepSeekAnthropicProvider } from "./deepseek.js";
|
|
2
|
+
import { KimiProvider, KimiAnthropicProvider } from "./kimi.js";
|
|
3
|
+
import { QwenProvider, QwenAnthropicProvider } from "./qwen.js";
|
|
4
|
+
import { GLMProvider, GLMAnthropicProvider } from "./glm.js";
|
|
5
|
+
import { MiniMaxOpenAIProvider, MiniMaxAnthropicProvider } from "./minimax.js";
|
|
6
|
+
import { GeminiProvider } from "./gemini.js";
|
|
7
|
+
import { OllamaProvider } from "./ollama.js";
|
|
8
|
+
/** DeepSeek. Defaults to the OpenAI-compatible wire (richer reasoning-replay handling). */
|
|
9
|
+
export function deepseek(o) {
|
|
10
|
+
return o.protocol === "anthropic"
|
|
11
|
+
? new DeepSeekAnthropicProvider(o.apiKey, o.model, o.retry, o.baseURL)
|
|
12
|
+
: new DeepSeekProvider(o.apiKey, o.model, o.retry, o.baseURL);
|
|
13
|
+
}
|
|
14
|
+
/** Moonshot Kimi. Defaults to the OpenAI-compatible wire. */
|
|
15
|
+
export function kimi(o) {
|
|
16
|
+
return o.protocol === "anthropic"
|
|
17
|
+
? new KimiAnthropicProvider(o.apiKey, o.model, o.retry, o.baseURL)
|
|
18
|
+
: new KimiProvider(o.apiKey, o.model, o.retry, o.baseURL);
|
|
19
|
+
}
|
|
20
|
+
/** Alibaba Qwen / DashScope. Defaults to the OpenAI-compatible (DashScope) wire. */
|
|
21
|
+
export function qwen(o) {
|
|
22
|
+
return o.protocol === "anthropic"
|
|
23
|
+
? new QwenAnthropicProvider(o.apiKey, o.model, o.retry, o.baseURL)
|
|
24
|
+
: new QwenProvider(o.apiKey, o.model, o.retry, o.baseURL);
|
|
25
|
+
}
|
|
26
|
+
/** Zhipu GLM. Defaults to the OpenAI-compatible wire. */
|
|
27
|
+
export function glm(o) {
|
|
28
|
+
return o.protocol === "anthropic"
|
|
29
|
+
? new GLMAnthropicProvider(o.apiKey, o.model, o.retry, o.baseURL)
|
|
30
|
+
: new GLMProvider(o.apiKey, o.model, o.retry, o.baseURL);
|
|
31
|
+
}
|
|
32
|
+
/** MiniMax. Defaults to the Anthropic-compatible wire (the primary M2.x path). */
|
|
33
|
+
export function minimax(o) {
|
|
34
|
+
return o.protocol === "openai"
|
|
35
|
+
? new MiniMaxOpenAIProvider(o.apiKey, o.model, o.retry, o.baseURL)
|
|
36
|
+
: new MiniMaxAnthropicProvider(o.apiKey, o.model, o.retry, o.baseURL);
|
|
37
|
+
}
|
|
38
|
+
/** Google Gemini (single wire). */
|
|
39
|
+
export function gemini(o) {
|
|
40
|
+
return new GeminiProvider(o.apiKey, o.model, o.retry, o.baseURL);
|
|
41
|
+
}
|
|
42
|
+
/** Local Ollama (single wire, no API key). */
|
|
43
|
+
export function ollama(o = {}) {
|
|
44
|
+
return new OllamaProvider(o.model, o.baseURL);
|
|
45
|
+
}
|
|
@@ -3,14 +3,26 @@ import type { Message, ProviderDescriptor, ProviderReplay, ProviderRunState, Ren
|
|
|
3
3
|
import { CircuitBreaker } from "./base.js";
|
|
4
4
|
import { OpenAIChatAdapter } from "./openai-chat.js";
|
|
5
5
|
import type { ReplayabilityAssessment } from "./replay-validator.js";
|
|
6
|
+
/** Options-object form for `OpenAIProvider` — the recommended way to construct an OpenAI-compatible
|
|
7
|
+
* provider (custom `baseURL` no longer needs a positional hole). */
|
|
8
|
+
export interface OpenAIProviderOptions {
|
|
9
|
+
apiKey: string;
|
|
10
|
+
model?: string;
|
|
11
|
+
retry?: {
|
|
12
|
+
maxRetries: number;
|
|
13
|
+
baseDelay: number;
|
|
14
|
+
};
|
|
15
|
+
/** Custom OpenAI-compatible endpoint (MiMo, DeepSeek, Kimi, …). Defaults to the OpenAI API. */
|
|
16
|
+
baseURL?: string;
|
|
17
|
+
}
|
|
6
18
|
export declare class OpenAIChatProvider implements LLMProvider {
|
|
7
|
-
protected readonly model: string;
|
|
8
19
|
protected client: OpenAI;
|
|
9
20
|
protected circuit: CircuitBreaker;
|
|
10
21
|
protected maxRetries: number;
|
|
11
22
|
protected baseDelay: number;
|
|
23
|
+
protected readonly model: string;
|
|
12
24
|
protected readonly chat: OpenAIChatAdapter;
|
|
13
|
-
constructor(
|
|
25
|
+
constructor(apiKeyOrOptions: string | OpenAIProviderOptions, model?: string, retry?: {
|
|
14
26
|
maxRetries: number;
|
|
15
27
|
baseDelay: number;
|
|
16
28
|
}, baseURL?: string);
|
package/dist/providers/openai.js
CHANGED
|
@@ -26,18 +26,23 @@ const OPENAI_POLICIES = {
|
|
|
26
26
|
"o4-mini": { maxTurns: 25 },
|
|
27
27
|
};
|
|
28
28
|
export class OpenAIChatProvider {
|
|
29
|
-
model;
|
|
30
29
|
client;
|
|
31
30
|
circuit;
|
|
32
31
|
maxRetries;
|
|
33
32
|
baseDelay;
|
|
33
|
+
model;
|
|
34
34
|
chat = new OpenAIChatAdapter();
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
// Accepts either the options object (`new OpenAIProvider({ apiKey, model, baseURL })`) or the legacy
|
|
36
|
+
// positional form (still used by the backend subclasses' `super(...)` calls).
|
|
37
|
+
constructor(apiKeyOrOptions, model = "gpt-4o", retry = { maxRetries: 3, baseDelay: 1000 }, baseURL = "https://api.openai.com/v1") {
|
|
38
|
+
const o = typeof apiKeyOrOptions === "string"
|
|
39
|
+
? { apiKey: apiKeyOrOptions, model, retry, baseURL }
|
|
40
|
+
: { model: "gpt-4o", retry: { maxRetries: 3, baseDelay: 1000 }, baseURL: "https://api.openai.com/v1", ...apiKeyOrOptions };
|
|
41
|
+
this.model = o.model;
|
|
42
|
+
this.client = withServerRuntimeGuard(() => new OpenAI({ apiKey: o.apiKey, baseURL: o.baseURL }));
|
|
38
43
|
this.circuit = new CircuitBreaker();
|
|
39
|
-
this.maxRetries = retry.maxRetries;
|
|
40
|
-
this.baseDelay = retry.baseDelay;
|
|
44
|
+
this.maxRetries = o.retry.maxRetries;
|
|
45
|
+
this.baseDelay = o.retry.baseDelay;
|
|
41
46
|
}
|
|
42
47
|
runtimePolicy() {
|
|
43
48
|
return OPENAI_POLICIES[this.model] ?? {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { deepseek, kimi, qwen, glm, minimax, gemini, ollama } from "./factories.js";
|
|
2
|
+
export type { BackendProviderOptions } from "./factories.js";
|
|
3
|
+
export { OpenAIChatProvider } from "./openai.js";
|
|
4
|
+
export { CircuitBreaker } from "./base.js";
|
|
5
|
+
export { OpenAIResponsesAdapter } from "./openai-responses.js";
|
|
6
|
+
export type { OpenAIResponsesRunState } from "./openai-responses.js";
|
|
7
|
+
export { OpenAIChatAdapter } from "./openai-chat.js";
|
|
8
|
+
export { endpointProfiles, modelProfiles, getModelProfile } from "./profiles.js";
|
|
9
|
+
export type { ModelProfileId, ProviderId } from "./profiles.js";
|
|
10
|
+
export type { ProviderRunState, ProviderToolSpec, ProviderReplay, RenderedContext, CacheBreakpointStrategy } from "../types.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// `@deepstrike/sdk/providers` — backend provider factories, profiles, and provider-authoring types.
|
|
2
|
+
// The root package exports `createProvider` + the 3 base providers (Anthropic / OpenAI / OpenAIResponses);
|
|
3
|
+
// every other backend is a factory here. One function per backend (with a `protocol` option where a
|
|
4
|
+
// backend speaks both wires) replaces the old dual `<Backend>Provider`/`<Backend>AnthropicProvider` classes.
|
|
5
|
+
export { deepseek, kimi, qwen, glm, minimax, gemini, ollama } from "./factories.js";
|
|
6
|
+
// `OpenAIChatProvider` is the base OpenAI-compatible class advanced users compose/extend directly.
|
|
7
|
+
export { OpenAIChatProvider } from "./openai.js";
|
|
8
|
+
export { CircuitBreaker } from "./base.js";
|
|
9
|
+
export { OpenAIResponsesAdapter } from "./openai-responses.js";
|
|
10
|
+
export { OpenAIChatAdapter } from "./openai-chat.js";
|
|
11
|
+
export { endpointProfiles, modelProfiles, getModelProfile } from "./profiles.js";
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { ExecutionPlane } from "./execution-plane.js";
|
|
2
|
+
import type { SessionLog } from "./session-log.js";
|
|
3
|
+
import type { LLMProvider } from "../types.js";
|
|
4
|
+
import type { RegisteredTool } from "../tools/index.js";
|
|
5
|
+
import type { WorkflowTaskSpec, KernelAgentRole } from "../types/agent.js";
|
|
6
|
+
/** Shared knobs for the facade entry points. */
|
|
7
|
+
export interface RunAgentOptions {
|
|
8
|
+
provider: LLMProvider;
|
|
9
|
+
goal: string;
|
|
10
|
+
systemPrompt?: string;
|
|
11
|
+
tools?: RegisteredTool[];
|
|
12
|
+
sessionId?: string;
|
|
13
|
+
maxTokens?: number;
|
|
14
|
+
maxTurns?: number;
|
|
15
|
+
/** Persist the run (resume / audit). Defaults to an in-memory, throwaway log. */
|
|
16
|
+
sessionLog?: SessionLog;
|
|
17
|
+
/** Custom execution plane (tools, sandboxing). Overrides `tools` when both are given. */
|
|
18
|
+
executionPlane?: ExecutionPlane;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Run a single agent to completion and return its final text — `RuntimeRunner` + `run` + `collectText`
|
|
22
|
+
* in one call. Register tools by passing `tools`; everything else has a working default.
|
|
23
|
+
*/
|
|
24
|
+
export declare function runAgent(opts: RunAgentOptions): Promise<string>;
|
|
25
|
+
export interface RunFanoutOptions {
|
|
26
|
+
provider: LLMProvider;
|
|
27
|
+
/** One parallel worker per task. A string is shorthand for `{ goal }`. */
|
|
28
|
+
tasks: WorkflowTaskSpec[];
|
|
29
|
+
/** Final synthesis prompt; runs once after every worker completes, with their outputs in context. */
|
|
30
|
+
synthesize: string;
|
|
31
|
+
/** Role for the parallel workers (default `explore`) and the synthesis node (default `plan`). */
|
|
32
|
+
workerRole?: KernelAgentRole;
|
|
33
|
+
synthesisRole?: KernelAgentRole;
|
|
34
|
+
sessionId?: string;
|
|
35
|
+
maxTokens?: number;
|
|
36
|
+
maxTurns?: number;
|
|
37
|
+
sessionLog?: SessionLog;
|
|
38
|
+
executionPlane?: ExecutionPlane;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Parallel fan-out → synthesize, driven by the kernel-gated DAG (the standalone `runWorkflow` path):
|
|
42
|
+
* each task becomes a fresh-context worker node, and a final synthesis node depends on all of them.
|
|
43
|
+
* Returns the synthesis text plus every node's raw output. Safe to call from a stateless handler — it
|
|
44
|
+
* bootstraps and tears down its own kernel.
|
|
45
|
+
*/
|
|
46
|
+
export declare function runFanout(opts: RunFanoutOptions): Promise<{
|
|
47
|
+
synthesis: string;
|
|
48
|
+
outputs: Record<string, string>;
|
|
49
|
+
}>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-level facades for the two bread-and-butter cases, so a caller doesn't have to assemble
|
|
3
|
+
* `RuntimeRunner` + session log + execution plane + `collectText` by hand (integration feedback #4:
|
|
4
|
+
* the package exports ~150 symbols and the canonical entry point for common work wasn't discoverable).
|
|
5
|
+
*
|
|
6
|
+
* - `runAgent` — one prompt, one model, the text back. The 90%-case single-agent call.
|
|
7
|
+
* - `runFanout` — run N tasks in parallel, then synthesize, from a stateless request handler. Drives
|
|
8
|
+
* the kernel-gated DAG via the standalone `runWorkflow` path (governed · resumable),
|
|
9
|
+
* instead of hand-rolling a multi-runner fan-out.
|
|
10
|
+
*
|
|
11
|
+
* Both build a throwaway `RuntimeRunner` with sensible defaults; pass `sessionLog` / `executionPlane`
|
|
12
|
+
* to opt into persistence or custom tools. Reach for the underlying `RuntimeRunner` directly when you
|
|
13
|
+
* need streaming events, signals, memory, or governance hooks.
|
|
14
|
+
*/
|
|
15
|
+
import { RuntimeRunner, collectText } from "./runner.js";
|
|
16
|
+
import { LocalExecutionPlane } from "./execution-plane.js";
|
|
17
|
+
import { InMemorySessionLog } from "./session-log.js";
|
|
18
|
+
/**
|
|
19
|
+
* Run a single agent to completion and return its final text — `RuntimeRunner` + `run` + `collectText`
|
|
20
|
+
* in one call. Register tools by passing `tools`; everything else has a working default.
|
|
21
|
+
*/
|
|
22
|
+
export async function runAgent(opts) {
|
|
23
|
+
const plane = opts.executionPlane ??
|
|
24
|
+
(opts.tools ?? []).reduce((p, t) => p.register(t), new LocalExecutionPlane());
|
|
25
|
+
const runner = new RuntimeRunner({
|
|
26
|
+
provider: opts.provider,
|
|
27
|
+
executionPlane: plane,
|
|
28
|
+
sessionLog: opts.sessionLog ?? new InMemorySessionLog(),
|
|
29
|
+
maxTokens: opts.maxTokens ?? 32_000,
|
|
30
|
+
...(opts.maxTurns !== undefined ? { maxTurns: opts.maxTurns } : {}),
|
|
31
|
+
...(opts.systemPrompt !== undefined ? { systemPrompt: opts.systemPrompt } : {}),
|
|
32
|
+
});
|
|
33
|
+
return collectText(runner.run({ sessionId: opts.sessionId ?? `agent-${crypto.randomUUID()}`, goal: opts.goal }));
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Parallel fan-out → synthesize, driven by the kernel-gated DAG (the standalone `runWorkflow` path):
|
|
37
|
+
* each task becomes a fresh-context worker node, and a final synthesis node depends on all of them.
|
|
38
|
+
* Returns the synthesis text plus every node's raw output. Safe to call from a stateless handler — it
|
|
39
|
+
* bootstraps and tears down its own kernel.
|
|
40
|
+
*/
|
|
41
|
+
export async function runFanout(opts) {
|
|
42
|
+
const runner = new RuntimeRunner({
|
|
43
|
+
provider: opts.provider,
|
|
44
|
+
executionPlane: opts.executionPlane ?? new LocalExecutionPlane(),
|
|
45
|
+
sessionLog: opts.sessionLog ?? new InMemorySessionLog(),
|
|
46
|
+
maxTokens: opts.maxTokens ?? 32_000,
|
|
47
|
+
...(opts.maxTurns !== undefined ? { maxTurns: opts.maxTurns } : {}),
|
|
48
|
+
});
|
|
49
|
+
const workerRole = opts.workerRole ?? "explore";
|
|
50
|
+
const spec = {
|
|
51
|
+
nodes: [
|
|
52
|
+
...opts.tasks.map(task => ({ task, role: workerRole })),
|
|
53
|
+
{
|
|
54
|
+
task: opts.synthesize,
|
|
55
|
+
role: opts.synthesisRole ?? "plan",
|
|
56
|
+
dependsOn: opts.tasks.map((_, i) => i),
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
};
|
|
60
|
+
const outcome = await runner.runWorkflow(spec, opts.sessionId ? { sessionId: opts.sessionId } : undefined);
|
|
61
|
+
// The synthesis node is the last spec node; the kernel ids nodes `wf-node{index}`. Prefer that id,
|
|
62
|
+
// but fall back to the last completed node's output so a kernel id-scheme change can't silently
|
|
63
|
+
// return an empty synthesis.
|
|
64
|
+
const synthesisId = `wf-node${opts.tasks.length}`;
|
|
65
|
+
const lastCompleted = outcome.completed[outcome.completed.length - 1];
|
|
66
|
+
const synthesis = outcome.outputs[synthesisId] ?? (lastCompleted ? outcome.outputs[lastCompleted] : undefined) ?? "";
|
|
67
|
+
return { synthesis, outputs: outcome.outputs };
|
|
68
|
+
}
|
package/dist/runtime/runner.d.ts
CHANGED
|
@@ -230,6 +230,14 @@ export declare class RuntimeRunner {
|
|
|
230
230
|
}): Promise<MemoryEntry[]>;
|
|
231
231
|
private logMemoryRetrievalResult;
|
|
232
232
|
private createSyscallRuntime;
|
|
233
|
+
/**
|
|
234
|
+
* Lower the declarative governance / attention / scheduler-budget / resource-quota policies into a
|
|
235
|
+
* freshly-created kernel. Shared by `execute()` (full agent run) and `bootstrapWorkflowKernel()`
|
|
236
|
+
* (standalone host-driven workflow) so a workflow's DAG-node spawns are gated, queued, and quota'd
|
|
237
|
+
* exactly as a mid-run spawn would be. Must run BEFORE `start_run` so the in-kernel gate enforces
|
|
238
|
+
* every policy from the first spawn. No config ⇒ the native-profile defaults (铁律: defaults only).
|
|
239
|
+
*/
|
|
240
|
+
private applyKernelPolicies;
|
|
233
241
|
private appendMemorySyscallObservations;
|
|
234
242
|
/** Mount a tool capability on the currently-running kernel runtime. No-op if not running. */
|
|
235
243
|
mountTool(schema: ToolSchema): void;
|
|
@@ -273,11 +281,21 @@ export declare class RuntimeRunner {
|
|
|
273
281
|
runWorkflow(spec: WorkflowSpec, opts?: {
|
|
274
282
|
resumedCompleted?: string[];
|
|
275
283
|
resumedSubmissions?: Record<string, unknown>[][];
|
|
284
|
+
/** Standalone session id when bootstrapping (no active parent run). Defaults to a fresh uuid. */
|
|
285
|
+
sessionId?: string;
|
|
276
286
|
}): Promise<{
|
|
277
287
|
completed: string[];
|
|
278
288
|
failed: string[];
|
|
279
289
|
outputs: Record<string, string>;
|
|
280
290
|
}>;
|
|
291
|
+
/**
|
|
292
|
+
* Bootstrap a standalone kernel for a host-driven workflow with NO active parent run — the path a
|
|
293
|
+
* stateless request handler takes when it calls `runWorkflow(spec)` directly. Mirrors `execute()`'s
|
|
294
|
+
* pre-run kernel setup (governance / attention / quota via `applyKernelPolicies`, then `start_run`)
|
|
295
|
+
* and records a `run_started` event so the standalone run is resumable from the session log. Sets
|
|
296
|
+
* `activeKernel` / `currentSessionId`; `runWorkflow` is responsible for tearing them down.
|
|
297
|
+
*/
|
|
298
|
+
private bootstrapWorkflowKernel;
|
|
281
299
|
/**
|
|
282
300
|
* M5/G1: bootstrap an **agent-authored** workflow ("the model writes its own harness"). Unlike
|
|
283
301
|
* `runWorkflow` (the host fires the privileged `load_workflow`), this routes the spec through the
|
|
@@ -325,7 +343,9 @@ export declare class RuntimeRunner {
|
|
|
325
343
|
* Reads the session log, extracts completed workflow node agent_ids, and
|
|
326
344
|
* calls runWorkflow with resumedCompleted so the kernel skips those nodes.
|
|
327
345
|
*/
|
|
328
|
-
resumeWorkflow(spec: WorkflowSpec
|
|
346
|
+
resumeWorkflow(spec: WorkflowSpec, opts?: {
|
|
347
|
+
sessionId?: string;
|
|
348
|
+
}): Promise<{
|
|
329
349
|
completed: string[];
|
|
330
350
|
failed: string[];
|
|
331
351
|
}>;
|
package/dist/runtime/runner.js
CHANGED
|
@@ -139,6 +139,43 @@ export class RuntimeRunner {
|
|
|
139
139
|
timeoutMs: this.opts.timeoutMs !== undefined ? BigInt(this.opts.timeoutMs) : undefined,
|
|
140
140
|
});
|
|
141
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* Lower the declarative governance / attention / scheduler-budget / resource-quota policies into a
|
|
144
|
+
* freshly-created kernel. Shared by `execute()` (full agent run) and `bootstrapWorkflowKernel()`
|
|
145
|
+
* (standalone host-driven workflow) so a workflow's DAG-node spawns are gated, queued, and quota'd
|
|
146
|
+
* exactly as a mid-run spawn would be. Must run BEFORE `start_run` so the in-kernel gate enforces
|
|
147
|
+
* every policy from the first spawn. No config ⇒ the native-profile defaults (铁律: defaults only).
|
|
148
|
+
*/
|
|
149
|
+
applyKernelPolicies(runtime) {
|
|
150
|
+
// K2: lower governance / attention / scheduler / quota in ONE `configure_run` event instead of
|
|
151
|
+
// the previous 2–4 separate `set_*` / `load_governance_policy` events. The kernel applies each
|
|
152
|
+
// present field via the same path its granular event uses; absent fields are left untouched.
|
|
153
|
+
// (Requires the 0.2.30 core that ships `configure_run`.)
|
|
154
|
+
const osProfile = assertNativeProfile(this.opts.osProfile ?? "native");
|
|
155
|
+
const attentionPolicy = this.opts.attentionPolicy ?? osProfile.attentionPolicy;
|
|
156
|
+
const governancePolicy = this.opts.governancePolicy ?? osProfile.governancePolicy;
|
|
157
|
+
// Strip the event `kind` off the governance event — `configure_run.config.governance` carries the
|
|
158
|
+
// bare policy fields (default_action / rules / vetoed_tools / rate_limits / constraints).
|
|
159
|
+
const { kind: _govKind, ...governance } = governancePolicyToKernelEvent(governancePolicy);
|
|
160
|
+
const config = { governance };
|
|
161
|
+
if (attentionPolicy.maxQueueSize !== undefined) {
|
|
162
|
+
config.attention_max_queue_size = attentionPolicy.maxQueueSize;
|
|
163
|
+
}
|
|
164
|
+
if (this.opts.schedulerBudget?.maxWallMs !== undefined) {
|
|
165
|
+
config.scheduler_max_wall_ms = this.opts.schedulerBudget.maxWallMs;
|
|
166
|
+
}
|
|
167
|
+
if (this.opts.resourceQuota) {
|
|
168
|
+
const q = this.opts.resourceQuota;
|
|
169
|
+
config.resource_quota = {
|
|
170
|
+
...(q.maxConcurrentSubagents !== undefined ? { max_concurrent_subagents: q.maxConcurrentSubagents } : {}),
|
|
171
|
+
...(q.maxSpawnDepth !== undefined ? { max_spawn_depth: q.maxSpawnDepth } : {}),
|
|
172
|
+
...(q.memoryWritesPerWindow !== undefined
|
|
173
|
+
? { memory_writes_per_window: [q.memoryWritesPerWindow.maxWrites, q.memoryWritesPerWindow.windowMs] }
|
|
174
|
+
: {}),
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
kernelApply(runtime, this.pendingObservations, { kind: "configure_run", config });
|
|
178
|
+
}
|
|
142
179
|
async appendMemorySyscallObservations(sessionId, observations) {
|
|
143
180
|
if (!sessionId)
|
|
144
181
|
return;
|
|
@@ -392,21 +429,66 @@ export class RuntimeRunner {
|
|
|
392
429
|
* Returns the completed / failed node agent-ids.
|
|
393
430
|
*/
|
|
394
431
|
async runWorkflow(spec, opts) {
|
|
395
|
-
|
|
396
|
-
|
|
432
|
+
// Standalone entry: with no active parent run (e.g. a stateless HTTP handler), auto-bootstrap a
|
|
433
|
+
// kernel that owns the DAG — start_run + the same governance/quota/attention policies a full run
|
|
434
|
+
// gets — then tear it down on completion so the runner is reusable. Mid-run callers (activeKernel
|
|
435
|
+
// already set by an in-flight `run()`) keep the original in-place behavior with no teardown.
|
|
436
|
+
const bootstrapped = !this.activeKernel || !this.currentSessionId;
|
|
437
|
+
if (bootstrapped) {
|
|
438
|
+
this.bootstrapWorkflowKernel(opts?.sessionId ?? `wf-${crypto.randomUUID()}`, spec);
|
|
397
439
|
}
|
|
398
440
|
const parentSessionId = this.currentSessionId;
|
|
399
441
|
const runtime = this.activeKernel;
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
442
|
+
try {
|
|
443
|
+
const observations = kernelApply(runtime, this.pendingObservations, {
|
|
444
|
+
kind: "load_workflow",
|
|
445
|
+
spec: workflowSpecToKernel(spec),
|
|
446
|
+
parent_session_id: parentSessionId,
|
|
447
|
+
// W0-ABI resume: skip nodes already completed before an interruption.
|
|
448
|
+
...(opts?.resumedCompleted?.length ? { resumed_completed: opts.resumedCompleted } : {}),
|
|
449
|
+
// R3-1: re-apply recorded runtime submissions so dynamically-appended nodes are reconstructed.
|
|
450
|
+
...(opts?.resumedSubmissions?.length ? { resumed_submissions: opts.resumedSubmissions } : {}),
|
|
451
|
+
});
|
|
452
|
+
return await this.driveWorkflow(observations, parentSessionId, runtime);
|
|
453
|
+
}
|
|
454
|
+
finally {
|
|
455
|
+
if (bootstrapped) {
|
|
456
|
+
this.activeKernel = null;
|
|
457
|
+
this.currentSessionId = null;
|
|
458
|
+
this.pendingObservations = [];
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Bootstrap a standalone kernel for a host-driven workflow with NO active parent run — the path a
|
|
464
|
+
* stateless request handler takes when it calls `runWorkflow(spec)` directly. Mirrors `execute()`'s
|
|
465
|
+
* pre-run kernel setup (governance / attention / quota via `applyKernelPolicies`, then `start_run`)
|
|
466
|
+
* and records a `run_started` event so the standalone run is resumable from the session log. Sets
|
|
467
|
+
* `activeKernel` / `currentSessionId`; `runWorkflow` is responsible for tearing them down.
|
|
468
|
+
*/
|
|
469
|
+
bootstrapWorkflowKernel(sessionId, spec) {
|
|
470
|
+
this.interrupted = false;
|
|
471
|
+
this.abortController = new AbortController();
|
|
472
|
+
this.pendingObservations = [];
|
|
473
|
+
this.pendingSpoolOutputs.clear();
|
|
474
|
+
this.currentSessionId = sessionId;
|
|
475
|
+
const runtime = this.createSyscallRuntime();
|
|
476
|
+
this.activeKernel = runtime;
|
|
477
|
+
const goal = `workflow:${spec.nodes.length} nodes`;
|
|
478
|
+
// Best-effort run_started log so a standalone workflow can be resumed via `resumeWorkflow`. The
|
|
479
|
+
// session log is fire-and-forget here (the kernel state, not the log, drives the DAG); a logless
|
|
480
|
+
// store simply means no resume.
|
|
481
|
+
void this.opts.sessionLog.append(sessionId, {
|
|
482
|
+
kind: "run_started",
|
|
483
|
+
run_id: crypto.randomUUID(),
|
|
484
|
+
goal,
|
|
485
|
+
criteria: [],
|
|
486
|
+
agent_id: this.opts.agentId,
|
|
487
|
+
}).catch(() => { });
|
|
488
|
+
this.applyKernelPolicies(runtime);
|
|
489
|
+
// K1: no explicit `start_run` — the host `load_workflow` (fired next by `runWorkflow`) self-bootstraps
|
|
490
|
+
// the run on the 0.2.30 core, matching the agent-reachable `submit_workflow` path.
|
|
491
|
+
return runtime;
|
|
410
492
|
}
|
|
411
493
|
/**
|
|
412
494
|
* M5/G1: bootstrap an **agent-authored** workflow ("the model writes its own harness"). Unlike
|
|
@@ -575,14 +657,17 @@ export class RuntimeRunner {
|
|
|
575
657
|
* Reads the session log, extracts completed workflow node agent_ids, and
|
|
576
658
|
* calls runWorkflow with resumedCompleted so the kernel skips those nodes.
|
|
577
659
|
*/
|
|
578
|
-
async resumeWorkflow(spec) {
|
|
579
|
-
|
|
580
|
-
|
|
660
|
+
async resumeWorkflow(spec, opts) {
|
|
661
|
+
// Standalone resume: a stateless handler passes the prior `sessionId` to pick up an interrupted
|
|
662
|
+
// workflow from the session log. Mid-run callers omit it and resume the active session.
|
|
663
|
+
const sessionId = opts?.sessionId ?? this.currentSessionId;
|
|
664
|
+
if (!sessionId) {
|
|
665
|
+
throw new Error("resumeWorkflow requires an active parent run or an explicit sessionId");
|
|
581
666
|
}
|
|
582
|
-
const events = await this.opts.sessionLog.read(
|
|
667
|
+
const events = await this.opts.sessionLog.read(sessionId);
|
|
583
668
|
const resumedCompleted = recoverCompletedWorkflowNodes(events);
|
|
584
669
|
const resumedSubmissions = recoverSubmittedWorkflowNodes(events);
|
|
585
|
-
return this.runWorkflow(spec, { resumedCompleted, resumedSubmissions });
|
|
670
|
+
return this.runWorkflow(spec, { resumedCompleted, resumedSubmissions, sessionId });
|
|
586
671
|
}
|
|
587
672
|
interrupt() { this.interrupted = true; this.abortController?.abort(); }
|
|
588
673
|
async *run(req) {
|
|
@@ -919,51 +1004,7 @@ export class RuntimeRunner {
|
|
|
919
1004
|
: baseSpec;
|
|
920
1005
|
startPayload.run_spec = agentRunSpecToKernel(spec);
|
|
921
1006
|
}
|
|
922
|
-
|
|
923
|
-
const attentionPolicy = this.opts.attentionPolicy ?? osProfile.attentionPolicy;
|
|
924
|
-
const governancePolicy = this.opts.governancePolicy ?? osProfile.governancePolicy;
|
|
925
|
-
// Load the declarative governance policy into the kernel before the run starts,
|
|
926
|
-
// so the in-kernel gate enforces deny/veto/rate-limit/param before any tool runs.
|
|
927
|
-
kernelApply(runtime, this.pendingObservations, governancePolicyToKernelEvent(governancePolicy));
|
|
928
|
-
// Enable in-kernel signal routing so the kernel owns disposition + queuing.
|
|
929
|
-
kernelApply(runtime, this.pendingObservations, {
|
|
930
|
-
kind: "set_attention_policy",
|
|
931
|
-
...(attentionPolicy.maxQueueSize !== undefined
|
|
932
|
-
? { max_queue_size: attentionPolicy.maxQueueSize }
|
|
933
|
-
: {}),
|
|
934
|
-
});
|
|
935
|
-
// Set optional wall-clock budget override.
|
|
936
|
-
if (this.opts.schedulerBudget) {
|
|
937
|
-
kernelApply(runtime, this.pendingObservations, {
|
|
938
|
-
kind: "set_scheduler_budget",
|
|
939
|
-
...(this.opts.schedulerBudget.maxWallMs !== undefined
|
|
940
|
-
? { max_wall_ms: this.opts.schedulerBudget.maxWallMs }
|
|
941
|
-
: {}),
|
|
942
|
-
});
|
|
943
|
-
}
|
|
944
|
-
// Install optional resource quotas at the syscall trap (M2). Maps the ergonomic camelCase
|
|
945
|
-
// option onto the kernel's snake_case quota shape; the write-rate window is the serde tuple
|
|
946
|
-
// `[maxWrites, windowMs]`. Omitting the option leaves spawn / memory writes unbounded.
|
|
947
|
-
if (this.opts.resourceQuota) {
|
|
948
|
-
const q = this.opts.resourceQuota;
|
|
949
|
-
kernelApply(runtime, this.pendingObservations, {
|
|
950
|
-
kind: "set_resource_quota",
|
|
951
|
-
quota: {
|
|
952
|
-
...(q.maxConcurrentSubagents !== undefined
|
|
953
|
-
? { max_concurrent_subagents: q.maxConcurrentSubagents }
|
|
954
|
-
: {}),
|
|
955
|
-
...(q.maxSpawnDepth !== undefined ? { max_spawn_depth: q.maxSpawnDepth } : {}),
|
|
956
|
-
...(q.memoryWritesPerWindow !== undefined
|
|
957
|
-
? {
|
|
958
|
-
memory_writes_per_window: [
|
|
959
|
-
q.memoryWritesPerWindow.maxWrites,
|
|
960
|
-
q.memoryWritesPerWindow.windowMs,
|
|
961
|
-
],
|
|
962
|
-
}
|
|
963
|
-
: {}),
|
|
964
|
-
},
|
|
965
|
-
});
|
|
966
|
-
}
|
|
1007
|
+
this.applyKernelPolicies(runtime);
|
|
967
1008
|
// Multimodal upload: seed the user's attachments (images/audio) as a history
|
|
968
1009
|
// message before start_run pushes the "[TASK STATE]" anchor. init_task does not
|
|
969
1010
|
// clear history, so order becomes [attachment user msg, "Proceed…"] — both land
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { SubAgentOrchestrator, defaultSubAgentOrchestrator, spawnStandalone } from "../runtime/sub-agent-orchestrator.js";
|
|
2
|
+
export type { SubAgentRunContext } from "../runtime/sub-agent-orchestrator.js";
|
|
3
|
+
export { builtinReducers, resolveReducer } from "../runtime/reducers.js";
|
|
4
|
+
export type { Reducer, ReducerRegistry, ReducerInput } from "../runtime/reducers.js";
|
|
5
|
+
export { FileWorkflowStore } from "../runtime/workflow-store.js";
|
|
6
|
+
export { submitWorkflowNodesTool, startWorkflowTool, generateAndFilter, verifyRules, genEval, milestoneCheckPass, milestoneCheckFail, } from "../types/agent.js";
|
|
7
|
+
export type { AgentCapabilityFilter, AgentIdentity, AgentIsolation, AgentRunSpec, AgentProcessChangedObservation, ContextInheritance, KernelAgentRole, LoopResult, MilestoneCheckResult, MilestoneContract, MilestonePhase, MilestonePolicy, SubAgentResult, TerminationReason, WorkflowSpawnInfo, WorkflowTaskSpec, } from "../types/agent.js";
|
|
8
|
+
export type { AcceptanceCriterion, VerificationContract, ContractCheckResult } from "../collaboration/contract.js";
|
|
9
|
+
export { ContractBuilder, formatContractForSystemPrompt, contractToCriteriaStrings } from "../collaboration/contract.js";
|
|
10
|
+
export type { AgentRole, IsolatedVerifierContext, CoordinatorConfig } from "../collaboration/pool.js";
|
|
11
|
+
export { ContractDrivenHarness } from "../collaboration/harness.js";
|
|
12
|
+
export type { ContractOutcome, ContractHarnessOptions, Violation } from "../collaboration/harness.js";
|
|
13
|
+
export { HandoffBus } from "../collaboration/handoff.js";
|
|
14
|
+
export type { HandoffArtifact, ContractOutcomeInput } from "../collaboration/handoff.js";
|
|
15
|
+
export { CreatorVerifierMode, OrchestrationMode } from "../collaboration/modes/creator-verifier.js";
|
|
16
|
+
export type { CreatorVerifierMetrics } from "../collaboration/modes/creator-verifier.js";
|
|
17
|
+
export { scanSkillDir, readSkillFile } from "../skills/loader.js";
|
|
18
|
+
export type { SkillMetadata } from "../skills/loader.js";
|
|
19
|
+
export { executeTools, readFile, validateToolArguments } from "../tools/index.js";
|
|
20
|
+
export type { ToolExecContext } from "../tools/index.js";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// `@deepstrike/sdk/workflow` — multi-agent orchestration: the sub-agent host, reducers, spec builders,
|
|
2
|
+
// workflow node tools, agent/milestone types, and the collaboration (contract/handoff/mode) layer.
|
|
3
|
+
// The root package exports `runFanout`, `AgentPool`, `WorkflowSpec`/`WorkflowNodeSpec`; the advanced
|
|
4
|
+
// machinery lives here.
|
|
5
|
+
export { SubAgentOrchestrator, defaultSubAgentOrchestrator, spawnStandalone } from "../runtime/sub-agent-orchestrator.js";
|
|
6
|
+
export { builtinReducers, resolveReducer } from "../runtime/reducers.js";
|
|
7
|
+
export { FileWorkflowStore } from "../runtime/workflow-store.js";
|
|
8
|
+
export { submitWorkflowNodesTool, startWorkflowTool, generateAndFilter, verifyRules, genEval, milestoneCheckPass, milestoneCheckFail, } from "../types/agent.js";
|
|
9
|
+
export { ContractBuilder, formatContractForSystemPrompt, contractToCriteriaStrings } from "../collaboration/contract.js";
|
|
10
|
+
export { ContractDrivenHarness } from "../collaboration/harness.js";
|
|
11
|
+
export { HandoffBus } from "../collaboration/handoff.js";
|
|
12
|
+
export { CreatorVerifierMode, OrchestrationMode } from "../collaboration/modes/creator-verifier.js";
|
|
13
|
+
// Skills loader + lower-level tool execution helpers.
|
|
14
|
+
export { scanSkillDir, readSkillFile } from "../skills/loader.js";
|
|
15
|
+
export { executeTools, readFile, validateToolArguments } from "../tools/index.js";
|
package/package.json
CHANGED
|
@@ -1,10 +1,62 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepstrike/sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.30",
|
|
4
4
|
"description": "DeepStrike Node.js SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./providers": {
|
|
14
|
+
"types": "./dist/providers/public.d.ts",
|
|
15
|
+
"import": "./dist/providers/public.js"
|
|
16
|
+
},
|
|
17
|
+
"./workflow": {
|
|
18
|
+
"types": "./dist/workflow/public.d.ts",
|
|
19
|
+
"import": "./dist/workflow/public.js"
|
|
20
|
+
},
|
|
21
|
+
"./planes": {
|
|
22
|
+
"types": "./dist/planes/public.d.ts",
|
|
23
|
+
"import": "./dist/planes/public.js"
|
|
24
|
+
},
|
|
25
|
+
"./memory": {
|
|
26
|
+
"types": "./dist/memory/public.d.ts",
|
|
27
|
+
"import": "./dist/memory/public.js"
|
|
28
|
+
},
|
|
29
|
+
"./harness": {
|
|
30
|
+
"types": "./dist/harness/public.d.ts",
|
|
31
|
+
"import": "./dist/harness/public.js"
|
|
32
|
+
},
|
|
33
|
+
"./os": {
|
|
34
|
+
"types": "./dist/os/public.d.ts",
|
|
35
|
+
"import": "./dist/os/public.js"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"typesVersions": {
|
|
39
|
+
"*": {
|
|
40
|
+
"providers": [
|
|
41
|
+
"./dist/providers/public.d.ts"
|
|
42
|
+
],
|
|
43
|
+
"workflow": [
|
|
44
|
+
"./dist/workflow/public.d.ts"
|
|
45
|
+
],
|
|
46
|
+
"planes": [
|
|
47
|
+
"./dist/planes/public.d.ts"
|
|
48
|
+
],
|
|
49
|
+
"memory": [
|
|
50
|
+
"./dist/memory/public.d.ts"
|
|
51
|
+
],
|
|
52
|
+
"harness": [
|
|
53
|
+
"./dist/harness/public.d.ts"
|
|
54
|
+
],
|
|
55
|
+
"os": [
|
|
56
|
+
"./dist/os/public.d.ts"
|
|
57
|
+
]
|
|
58
|
+
}
|
|
59
|
+
},
|
|
8
60
|
"files": [
|
|
9
61
|
"dist",
|
|
10
62
|
"README.md"
|
|
@@ -20,7 +72,7 @@
|
|
|
20
72
|
},
|
|
21
73
|
"dependencies": {
|
|
22
74
|
"@anthropic-ai/sdk": "^0.99.0",
|
|
23
|
-
"@deepstrike/core": "0.2.
|
|
75
|
+
"@deepstrike/core": "0.2.30",
|
|
24
76
|
"@google/generative-ai": "^0.24.1",
|
|
25
77
|
"openai": "^5.23.2"
|
|
26
78
|
},
|