@deepstrike/wasm 0.2.52 → 0.2.61

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.
Files changed (54) hide show
  1. package/README.md +15 -14
  2. package/dist/agent-ir.d.ts +81 -0
  3. package/dist/agent-ir.js +115 -0
  4. package/dist/agent.d.ts +140 -0
  5. package/dist/agent.js +34 -0
  6. package/dist/governance.d.ts +0 -25
  7. package/dist/governance.js +1 -53
  8. package/dist/index.d.ts +23 -8
  9. package/dist/index.js +11 -4
  10. package/dist/memory/durable.d.ts +13 -0
  11. package/dist/memory/durable.js +42 -0
  12. package/dist/memory/in-memory-store.d.ts +8 -6
  13. package/dist/memory/in-memory-store.js +8 -2
  14. package/dist/memory/index.d.ts +18 -2
  15. package/dist/providers/anthropic.d.ts +9 -0
  16. package/dist/providers/anthropic.js +12 -33
  17. package/dist/providers/content-policy.d.ts +16 -0
  18. package/dist/providers/content-policy.js +39 -0
  19. package/dist/providers/openai.d.ts +36 -17
  20. package/dist/providers/openai.js +86 -46
  21. package/dist/providers/provider-error.d.ts +22 -0
  22. package/dist/providers/provider-error.js +90 -0
  23. package/dist/providers/request-plan.d.ts +87 -0
  24. package/dist/providers/request-plan.js +153 -0
  25. package/dist/providers/stop-reason.d.ts +5 -0
  26. package/dist/providers/stop-reason.js +24 -0
  27. package/dist/runtime/canonical-kernel-step.d.ts +2 -5
  28. package/dist/runtime/canonical-kernel-step.js +40 -58
  29. package/dist/runtime/context-policy.d.ts +10 -12
  30. package/dist/runtime/context-policy.js +6 -8
  31. package/dist/runtime/durable-content.d.ts +44 -0
  32. package/dist/runtime/durable-content.js +119 -0
  33. package/dist/runtime/execution-plane.d.ts +2 -2
  34. package/dist/runtime/execution-plane.js +2 -2
  35. package/dist/runtime/kernel-event-log.js +0 -1
  36. package/dist/runtime/kernel-step.d.ts +1 -2
  37. package/dist/runtime/kernel-step.js +1 -1
  38. package/dist/runtime/provider-replay.d.ts +1 -1
  39. package/dist/runtime/provider-replay.js +12 -20
  40. package/dist/runtime/runner.d.ts +22 -18
  41. package/dist/runtime/runner.js +115 -55
  42. package/dist/runtime/session-log.d.ts +8 -1
  43. package/dist/runtime/session-repair.d.ts +1 -1
  44. package/dist/runtime/session-repair.js +1 -1
  45. package/dist/runtime/sha256.d.ts +2 -0
  46. package/dist/runtime/sha256.js +38 -0
  47. package/dist/runtime/sub-agent-orchestrator.d.ts +1 -1
  48. package/dist/runtime/sub-agent-orchestrator.js +3 -3
  49. package/dist/runtime/types/agent.d.ts +17 -7
  50. package/dist/runtime/types/agent.js +30 -4
  51. package/dist/runtime/workflow-control-flow.d.ts +0 -4
  52. package/dist/runtime/workflow-control-flow.js +0 -16
  53. package/dist/types.d.ts +58 -5
  54. package/package.json +2 -2
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  # DeepStrike WASM SDK
8
8
 
9
- Runtime framework built on a Rust kernel compiled to WebAssembly. Runs in browsers, Cloudflare Workers, Deno Deploy, and Vercel Edge — anywhere that supports `fetch` and WASM.
9
+ Build browser and edge Agents with providers, typed tools, memory interfaces, Skills, governance, and durable session evidence. The WASM SDK runs wherever `fetch` and WebAssembly are available, including browsers, Cloudflare Workers, Deno Deploy, and Vercel Edge.
10
10
 
11
11
  ## Install
12
12
 
@@ -77,7 +77,7 @@ src/
77
77
  ├── types.ts # Shared type definitions
78
78
  ├── providers/ # LLM adapters (fetch-based SSE)
79
79
  ├── tools/ # tool() helper, executeTools (no fs/shell)
80
- ├── memory/ # WorkingMemory + DreamStore interfaces
80
+ ├── memory/ # WorkingMemory + MemoryStore interfaces
81
81
  ├── knowledge/ # KnowledgeSource interface
82
82
  ├── harness/ # AttemptLoop body/judge/carry/stop policies
83
83
  ├── signals/ # RuntimeSignal, SignalSource, ScheduledPrompt
@@ -88,7 +88,7 @@ The kernel (`@deepstrike/wasm-kernel`, Rust/wasm-bindgen) owns:
88
88
  - the Canonical Kernel ABI durable `prepare → append → commit` transition contract
89
89
  - typed effects, a single effect-resolution input, observations, and terminal disposition
90
90
  - `ContextEngine` — 4-slot context with tiered history compression
91
- - `Governance` — tool veto authority
91
+ - `GovernancePolicy` — declarative tool admission policy
92
92
  - `SignalRouter` — external interrupt queue
93
93
 
94
94
  ### WASM constraints vs Node SDK
@@ -110,13 +110,14 @@ The WASM SDK ships **no `readFile` built-in**. Tools must be pure JS / serializa
110
110
 
111
111
  All providers use `fetch` — no Node.js `http` module.
112
112
 
113
- | Class | Backend |
113
+ | Entry point | Backend |
114
114
  |-------|---------|
115
115
  | `AnthropicProvider` | Anthropic API (SSE) |
116
116
  | `OpenAIProvider` | OpenAI API (SSE) |
117
- | `QwenProvider` | DashScope |
118
- | `DeepSeekProvider` | DeepSeek API |
119
- | `MiniMaxProvider` | MiniMax API |
117
+ | `qwen(...)` | DashScope |
118
+ | `deepseek(...)` | DeepSeek API |
119
+ | `minimax(...)` | MiniMax API |
120
+ | `kimi(...)` | Moonshot Kimi API |
120
121
 
121
122
  ```typescript
122
123
  import { AnthropicProvider } from "@deepstrike/wasm"
@@ -175,7 +176,7 @@ const runner = new RuntimeRunner({
175
176
  })
176
177
  ```
177
178
 
178
- IndexedDB / KV can back `DreamStore` for cross-session memory. Meta-tool retrieval still lands in **history**.
179
+ IndexedDB / KV can back `MemoryStore` for cross-session memory. Meta-tool retrieval still lands in **history**.
179
180
 
180
181
  See [docs/concepts/context-slots-compression.md](../docs/concepts/context-slots-compression.md).
181
182
 
@@ -184,17 +185,17 @@ See [docs/concepts/context-slots-compression.md](../docs/concepts/context-slots-
184
185
  ## Governance
185
186
 
186
187
  ```typescript
187
- import { RuntimeRunner, AnthropicProvider, Governance } from "@deepstrike/wasm"
188
-
189
- const gov = new Governance()
190
- gov.blockTool("dangerous_tool")
188
+ import { RuntimeRunner, AnthropicProvider } from "@deepstrike/wasm"
191
189
 
192
190
  const runner = new RuntimeRunner({
193
191
  provider: new AnthropicProvider(apiKey),
194
192
  sessionLog: new InMemorySessionLog(),
195
193
  executionPlane: new LocalExecutionPlane(),
196
194
  maxTokens: 32_000,
197
- governance: gov,
195
+ governancePolicy: {
196
+ defaultAction: "allow",
197
+ rules: [{ pattern: "dangerous_tool", action: "deny" }],
198
+ },
198
199
  })
199
200
  ```
200
201
 
@@ -212,7 +213,7 @@ mem.set("step", 1)
212
213
  mem.get("step") // 1
213
214
  ```
214
215
 
215
- For cross-session recall, implement `DreamStore` and set `agentId` on `RuntimeRunner`. In-session `memory(query)` results appear in **history**; preload durable blocks with `initialMemory` → Slot 2.
216
+ For cross-session recall, implement `MemoryStore` and set `agentId` on `RuntimeRunner`. In-session `memory(query)` results appear in **history**; preload durable blocks with `initialMemory` → Slot 2.
216
217
 
217
218
  ---
218
219
 
@@ -0,0 +1,81 @@
1
+ import { Agent, type AgentOptions, type AgentToolDefinition, type Guardrail, type Handoff, type Knowledge, type MCPServer, type ModelRef, type Skill } from "./agent.js";
2
+ import type { AgentCapabilityFilter } from "./runtime/types/agent.js";
3
+ import type { RegisteredTool } from "./tools/index.js";
4
+ type JsonSchema = Record<string, unknown>;
5
+ export interface AgentDefinition extends Omit<AgentOptions, "tools"> {
6
+ tools?: Array<RegisteredTool | AgentToolDefinition>;
7
+ }
8
+ export interface AgentToolIR {
9
+ name: string;
10
+ description: string;
11
+ parameters: Record<string, unknown>;
12
+ providerOptions?: Record<string, unknown>;
13
+ }
14
+ export interface AgentMemoryIR {
15
+ kind: "durable" | "working";
16
+ namespace?: string;
17
+ }
18
+ export type AgentCapabilityIR = {
19
+ kind: "tool";
20
+ id: string;
21
+ description: string;
22
+ } | {
23
+ kind: "mcp_server";
24
+ id: string;
25
+ description: string;
26
+ } | {
27
+ kind: "skill";
28
+ id: string;
29
+ description: string;
30
+ };
31
+ export interface AgentLoweringInputs {
32
+ run: {
33
+ name: string;
34
+ model?: ModelRef;
35
+ };
36
+ context: {
37
+ description?: string;
38
+ instructions?: string;
39
+ outputSchema?: JsonSchema;
40
+ knowledge: Knowledge[];
41
+ };
42
+ capabilities: {
43
+ tools: AgentToolIR[];
44
+ mcpServers: MCPServer[];
45
+ skills: Skill[];
46
+ effective: AgentCapabilityIR[];
47
+ };
48
+ memory?: AgentMemoryIR;
49
+ delegation: {
50
+ handoffs: Handoff[];
51
+ };
52
+ governance: {
53
+ guardrails: Guardrail[];
54
+ };
55
+ }
56
+ /** Provider-neutral host descriptor. This is neither an execution plan nor a Kernel wire DTO. */
57
+ export interface AgentSpec {
58
+ name: string;
59
+ description?: string;
60
+ instructions?: string;
61
+ model?: ModelRef;
62
+ tools: AgentToolIR[];
63
+ outputSchema?: JsonSchema;
64
+ mcpServers?: MCPServer[];
65
+ skills?: Skill[];
66
+ memory?: AgentMemoryIR;
67
+ knowledge?: Knowledge[];
68
+ handoffs?: Handoff[];
69
+ guardrails?: Guardrail[];
70
+ metadata?: Record<string, unknown>;
71
+ capabilities: AgentCapabilityIR[];
72
+ capabilityFilter?: AgentCapabilityFilter;
73
+ effectiveCapabilities: AgentCapabilityIR[];
74
+ extensions: Record<string, unknown>;
75
+ inputs: AgentLoweringInputs;
76
+ }
77
+ /** Native Agents need no normalization; JSON-safe declarations remain schema-only capabilities. */
78
+ export declare function normalizeAgent(agent: Agent | AgentDefinition): Agent;
79
+ /** Pure lowering only: providers, Kernel scheduling, persistence, and grants remain outside it. */
80
+ export declare function lowerAgent(agent: Agent): AgentSpec;
81
+ export {};
@@ -0,0 +1,115 @@
1
+ import { Agent, } from "./agent.js";
2
+ import { WorkingMemory } from "./memory/index.js";
3
+ function clone(value) {
4
+ if (value === undefined || value === null || typeof value !== "object")
5
+ return value;
6
+ if (Array.isArray(value))
7
+ return value.map(clone);
8
+ const copy = {};
9
+ for (const [key, nested] of Object.entries(value))
10
+ copy[key] = clone(nested);
11
+ return copy;
12
+ }
13
+ function isRegisteredTool(tool) {
14
+ return "schema" in tool && "execute" in tool;
15
+ }
16
+ /** Native Agents need no normalization; JSON-safe declarations remain schema-only capabilities. */
17
+ export function normalizeAgent(agent) {
18
+ if (agent instanceof Agent)
19
+ return agent;
20
+ return new Agent({ ...agent, ...(agent.tools ? { tools: clone(agent.tools) } : {}) });
21
+ }
22
+ function lowerTool(tool) {
23
+ if (!isRegisteredTool(tool)) {
24
+ const parameters = clone(tool.parameters ?? { type: "object", properties: {} });
25
+ if (parameters.type !== "object") {
26
+ throw new Error(`tool "${tool.name}": parameters must be a JSON Schema with root type "object"`);
27
+ }
28
+ return {
29
+ name: tool.name,
30
+ description: tool.description ?? "",
31
+ parameters,
32
+ ...(tool.providerOptions ? { providerOptions: clone(tool.providerOptions) } : {}),
33
+ };
34
+ }
35
+ let parameters;
36
+ try {
37
+ parameters = JSON.parse(tool.schema.parameters);
38
+ }
39
+ catch {
40
+ throw new Error(`tool "${tool.schema.name}" has invalid JSON Schema parameters`);
41
+ }
42
+ if (!parameters || typeof parameters !== "object" || Array.isArray(parameters) || parameters.type !== "object") {
43
+ throw new Error(`tool "${tool.schema.name}" parameters must decode to an object`);
44
+ }
45
+ return { name: tool.schema.name, description: tool.schema.description, parameters: clone(parameters) };
46
+ }
47
+ function lowerMemory(memory) {
48
+ if (!memory)
49
+ return undefined;
50
+ if (memory instanceof WorkingMemory)
51
+ return { kind: "working" };
52
+ const reference = memory;
53
+ return { kind: "durable", ...(reference.namespace ? { namespace: reference.namespace } : {}) };
54
+ }
55
+ function capabilityAllowed(capability, filter) {
56
+ if (!filter)
57
+ return true;
58
+ const kindAllowed = !filter.allowedKinds?.length || filter.allowedKinds.includes(capability.kind);
59
+ const idAllowed = !filter.allowedIds?.length || filter.allowedIds.includes(capability.id);
60
+ return kindAllowed && idAllowed;
61
+ }
62
+ /** Pure lowering only: providers, Kernel scheduling, persistence, and grants remain outside it. */
63
+ export function lowerAgent(agent) {
64
+ const tools = (agent.tools ?? []).map(lowerTool);
65
+ const mcpServers = clone(agent.mcpServers ?? []);
66
+ const skills = clone(agent.skills ?? []);
67
+ const knowledge = clone(agent.knowledge ?? []);
68
+ const handoffs = clone(agent.handoffs ?? []);
69
+ const guardrails = clone(agent.guardrails ?? []);
70
+ const memory = lowerMemory(agent.memory);
71
+ const extensions = clone(agent.providerOptions ?? {});
72
+ const capabilities = [
73
+ ...tools.map(tool => ({ kind: "tool", id: tool.name, description: tool.description })),
74
+ ...mcpServers.map(server => ({
75
+ kind: "mcp_server",
76
+ id: server.name ?? server.transport.kind,
77
+ description: server.name ?? `${server.transport.kind} MCP server`,
78
+ })),
79
+ ...skills.map(skill => ({ kind: "skill", id: skill.name, description: skill.description ?? "" })),
80
+ ];
81
+ const capabilityFilter = agent.capabilityFilter ? clone(agent.capabilityFilter) : undefined;
82
+ const effectiveCapabilities = capabilities.filter(capability => capabilityAllowed(capability, capabilityFilter));
83
+ return {
84
+ name: agent.name,
85
+ ...(agent.description ? { description: agent.description } : {}),
86
+ ...(agent.instructions ? { instructions: agent.instructions } : {}),
87
+ ...(agent.model ? { model: clone(agent.model) } : {}),
88
+ tools,
89
+ ...(agent.outputSchema ? { outputSchema: clone(agent.outputSchema) } : {}),
90
+ ...(mcpServers.length ? { mcpServers } : {}),
91
+ ...(skills.length ? { skills } : {}),
92
+ ...(memory ? { memory } : {}),
93
+ ...(knowledge.length ? { knowledge } : {}),
94
+ ...(handoffs.length ? { handoffs } : {}),
95
+ ...(guardrails.length ? { guardrails } : {}),
96
+ ...(agent.metadata ? { metadata: clone(agent.metadata) } : {}),
97
+ capabilities,
98
+ ...(capabilityFilter ? { capabilityFilter } : {}),
99
+ effectiveCapabilities,
100
+ extensions,
101
+ inputs: {
102
+ run: { name: agent.name, ...(agent.model ? { model: clone(agent.model) } : {}) },
103
+ context: {
104
+ ...(agent.description ? { description: agent.description } : {}),
105
+ ...(agent.instructions ? { instructions: agent.instructions } : {}),
106
+ ...(agent.outputSchema ? { outputSchema: clone(agent.outputSchema) } : {}),
107
+ knowledge,
108
+ },
109
+ capabilities: { tools, mcpServers, skills, effective: effectiveCapabilities },
110
+ ...(memory ? { memory } : {}),
111
+ delegation: { handoffs },
112
+ governance: { guardrails },
113
+ },
114
+ };
115
+ }
@@ -0,0 +1,140 @@
1
+ import type { AgentCapabilityFilter } from "./runtime/types/agent.js";
2
+ import type { Memory, WorkingMemory } from "./memory/index.js";
3
+ import type { RegisteredTool } from "./tools/index.js";
4
+ type JsonSchema = Record<string, unknown>;
5
+ export interface MemoryReference {
6
+ kind?: "durable";
7
+ namespace?: string;
8
+ }
9
+ export type AgentMemory = Memory | WorkingMemory | MemoryReference;
10
+ export type ModelRef = string | ModelRequirement;
11
+ export interface ModelRequirement {
12
+ capability?: {
13
+ reasoning?: boolean;
14
+ vision?: boolean;
15
+ toolUse?: boolean;
16
+ };
17
+ contextWindow?: number;
18
+ latencyClass?: string;
19
+ costClass?: string;
20
+ }
21
+ export interface AgentToolDefinition {
22
+ name: string;
23
+ description?: string;
24
+ parameters?: Record<string, unknown>;
25
+ providerOptions?: Record<string, unknown>;
26
+ }
27
+ export type McpTransport = {
28
+ kind: "stdio";
29
+ command: string;
30
+ args?: string[];
31
+ } | {
32
+ kind: "http";
33
+ url: string;
34
+ } | {
35
+ kind: "sse";
36
+ url: string;
37
+ } | {
38
+ kind: "custom";
39
+ [key: string]: unknown;
40
+ };
41
+ export interface MCPServer {
42
+ name?: string;
43
+ transport: McpTransport;
44
+ tools?: string[];
45
+ resources?: boolean;
46
+ prompts?: boolean;
47
+ auth?: Record<string, unknown>;
48
+ metadata?: Record<string, unknown>;
49
+ providerOptions?: Record<string, unknown>;
50
+ }
51
+ export interface Skill {
52
+ name: string;
53
+ description?: string;
54
+ instructions?: string;
55
+ resources?: unknown[];
56
+ scripts?: unknown[];
57
+ tools?: unknown[];
58
+ mcpServers?: unknown[];
59
+ knowledge?: unknown[];
60
+ metadata?: Record<string, unknown>;
61
+ providerOptions?: Record<string, unknown>;
62
+ }
63
+ export type KnowledgeSourceRef = {
64
+ kind: "file";
65
+ path: string;
66
+ } | {
67
+ kind: "directory";
68
+ path: string;
69
+ } | {
70
+ kind: "text";
71
+ content: string;
72
+ } | {
73
+ kind: "url";
74
+ url: string;
75
+ } | {
76
+ kind: "vector";
77
+ retriever: unknown;
78
+ } | {
79
+ kind: "custom";
80
+ [key: string]: unknown;
81
+ };
82
+ export interface Knowledge {
83
+ id?: string;
84
+ name?: string;
85
+ source: KnowledgeSourceRef;
86
+ description?: string;
87
+ metadata?: Record<string, unknown>;
88
+ providerOptions?: Record<string, unknown>;
89
+ }
90
+ export type AgentRef = string | {
91
+ name: string;
92
+ };
93
+ export interface Handoff {
94
+ agent: AgentRef;
95
+ description?: string;
96
+ inputSchema?: JsonSchema;
97
+ metadata?: Record<string, unknown>;
98
+ providerOptions?: Record<string, unknown>;
99
+ }
100
+ export interface Guardrail {
101
+ name: string;
102
+ description?: string;
103
+ metadata?: Record<string, unknown>;
104
+ }
105
+ export interface AgentOptions {
106
+ name: string;
107
+ description?: string;
108
+ instructions?: string;
109
+ model?: ModelRef;
110
+ capabilityFilter?: AgentCapabilityFilter;
111
+ tools?: Array<RegisteredTool | AgentToolDefinition>;
112
+ mcpServers?: MCPServer[];
113
+ skills?: Skill[];
114
+ memory?: AgentMemory;
115
+ knowledge?: Knowledge[];
116
+ handoffs?: Handoff[];
117
+ providerOptions?: Record<string, unknown>;
118
+ outputSchema?: JsonSchema;
119
+ metadata?: Record<string, unknown>;
120
+ guardrails?: Guardrail[];
121
+ }
122
+ export declare class Agent {
123
+ readonly name: string;
124
+ readonly description?: string;
125
+ readonly instructions?: string;
126
+ readonly model?: ModelRef;
127
+ readonly capabilityFilter?: AgentCapabilityFilter;
128
+ readonly tools?: Array<RegisteredTool | AgentToolDefinition>;
129
+ readonly mcpServers?: MCPServer[];
130
+ readonly skills?: Skill[];
131
+ readonly memory?: AgentMemory;
132
+ readonly knowledge?: Knowledge[];
133
+ readonly handoffs?: Handoff[];
134
+ readonly providerOptions?: Record<string, unknown>;
135
+ readonly outputSchema?: JsonSchema;
136
+ readonly metadata?: Record<string, unknown>;
137
+ readonly guardrails?: Guardrail[];
138
+ constructor(options: AgentOptions);
139
+ }
140
+ export {};
package/dist/agent.js ADDED
@@ -0,0 +1,34 @@
1
+ export class Agent {
2
+ name;
3
+ description;
4
+ instructions;
5
+ model;
6
+ capabilityFilter;
7
+ tools;
8
+ mcpServers;
9
+ skills;
10
+ memory;
11
+ knowledge;
12
+ handoffs;
13
+ providerOptions;
14
+ outputSchema;
15
+ metadata;
16
+ guardrails;
17
+ constructor(options) {
18
+ this.name = options.name;
19
+ this.description = options.description;
20
+ this.instructions = options.instructions;
21
+ this.model = options.model;
22
+ this.capabilityFilter = options.capabilityFilter;
23
+ this.tools = options.tools;
24
+ this.mcpServers = options.mcpServers;
25
+ this.skills = options.skills;
26
+ this.memory = options.memory;
27
+ this.knowledge = options.knowledge;
28
+ this.handoffs = options.handoffs;
29
+ this.providerOptions = options.providerOptions;
30
+ this.outputSchema = options.outputSchema;
31
+ this.metadata = options.metadata;
32
+ this.guardrails = options.guardrails;
33
+ }
34
+ }
@@ -1,28 +1,3 @@
1
- export interface GovernanceVerdict {
2
- kind: "allow" | "deny" | "rate_limited" | "ask_user";
3
- reason?: string;
4
- retryAfterMs?: number;
5
- }
6
- type DefaultAction = "allow" | "deny" | "ask_user";
7
- type RuleAction = "allow" | "deny" | "ask_user";
8
- export declare class Governance {
9
- private _inner;
10
- private _defaultAction;
11
- private _pendingCalls;
12
- constructor(defaultAction?: DefaultAction);
13
- /** Called by Agent after the WASM kernel module is loaded. */
14
- _attach(kernel: typeof import("@deepstrike/wasm-kernel")): void;
15
- private _apply;
16
- setIdentity(agentId: string, sessionId: string): this;
17
- addPermissionRule(pattern: string, action: RuleAction): this;
18
- blockTool(name: string): this;
19
- setRateLimit(toolName: string, maxCalls: number, windowMs: number): this;
20
- requireParam(toolName: string, paramPath: string): this;
21
- allowParamValues(toolName: string, paramPath: string, allowedValues: string[]): this;
22
- limitParamRange(toolName: string, paramPath: string, min?: number, max?: number): this;
23
- setTime(nowMs: number): this;
24
- evaluate(toolName: string, argsJson: string): GovernanceVerdict;
25
- }
26
1
  type GovernancePolicyAction = "allow" | "deny" | "ask_user";
27
2
  export interface GovernancePolicy {
28
3
  defaultAction?: GovernancePolicyAction;
@@ -1,56 +1,4 @@
1
- export class Governance {
2
- _inner = null;
3
- _defaultAction;
4
- _pendingCalls = [];
5
- constructor(defaultAction = "allow") {
6
- this._defaultAction = defaultAction;
7
- }
8
- /** Called by Agent after the WASM kernel module is loaded. */
9
- _attach(kernel) {
10
- if (this._inner)
11
- return;
12
- this._inner = new kernel.Governance(this._defaultAction);
13
- for (const fn_ of this._pendingCalls)
14
- fn_(this._inner);
15
- this._pendingCalls = [];
16
- }
17
- _apply(fn) {
18
- if (this._inner)
19
- fn(this._inner);
20
- else
21
- this._pendingCalls.push(fn);
22
- return this;
23
- }
24
- setIdentity(agentId, sessionId) {
25
- return this._apply(g => g.setIdentity(agentId, sessionId));
26
- }
27
- addPermissionRule(pattern, action) {
28
- return this._apply(g => g.addPermissionRule(pattern, action));
29
- }
30
- blockTool(name) {
31
- return this._apply(g => g.blockTool(name));
32
- }
33
- setRateLimit(toolName, maxCalls, windowMs) {
34
- return this._apply(g => g.setRateLimit(toolName, maxCalls, windowMs));
35
- }
36
- requireParam(toolName, paramPath) {
37
- return this._apply(g => g.requireParam(toolName, paramPath));
38
- }
39
- allowParamValues(toolName, paramPath, allowedValues) {
40
- return this._apply(g => g.allowParamValues(toolName, paramPath, allowedValues));
41
- }
42
- limitParamRange(toolName, paramPath, min, max) {
43
- return this._apply(g => g.limitParamRange(toolName, paramPath, min, max));
44
- }
45
- setTime(nowMs) {
46
- return this._apply(g => g.setTime(nowMs));
47
- }
48
- evaluate(toolName, argsJson) {
49
- if (!this._inner)
50
- return { kind: "allow" };
51
- return this._inner.evaluate(toolName, argsJson);
52
- }
53
- }
1
+ // ─── Declarative policy (in-kernel gate) ──────────────────────────────────────
54
2
  /** I5: bucket tools into allowed/denied per the policy. Pure. Mirrors Node. */
55
3
  export function governanceFilterSchema(tools, policy) {
56
4
  if (!policy)
package/dist/index.d.ts CHANGED
@@ -7,30 +7,45 @@ export { primitiveForCategory, primitiveForKind } from "./runtime/index.js";
7
7
  export { FilteredExecutionPlane } from "./runtime/filtered-plane.js";
8
8
  export { SubAgentOrchestrator, defaultSubAgentOrchestrator, spawnStandalone } from "./runtime/sub-agent-orchestrator.js";
9
9
  export type { SubAgentRunContext } from "./runtime/sub-agent-orchestrator.js";
10
- export type { AgentCapabilityFilter, AgentIdentity, AgentIsolation, AgentRunSpec, AgentProcessChangedObservation, ContextInheritance, KernelAgentRole, LoopResult, MilestoneCheckResult, MilestoneContract, MilestonePhase, MilestonePolicy, SubAgentResult, TerminationReason, WorkflowSpec, WorkflowNodeSpec, WorkflowDependencyPolicy, WorkflowNodeStatus, WorkflowNodeOutcome, WorkflowOutcome, WorkflowTaskSpec, WorkflowSpawnInfo, } from "./runtime/types/agent.js";
10
+ export type { AgentCapabilityFilter, AgentIdentity, AgentIsolation, AgentRunSpec, AgentProcessChangedObservation, ContextInheritance, KernelAgentRole, LoopResult, MilestoneCheckResult, MilestoneContract, MilestonePhase, MilestonePolicy, SubAgentResult, TerminationReason, WorkflowSpec, WorkflowNodeSpec, SchedulingFactors, WorkflowDependencyPolicy, WorkflowNodeStatus, WorkflowNodeOutcome, WorkflowOutcome, WorkflowTaskSpec, WorkflowSpawnInfo, } from "./runtime/types/agent.js";
11
11
  export { workflowSpecToKernel, workflowNodeSpecToKernel, submitWorkflowNodesTool, startWorkflowTool, fanoutSynthesize, generateAndFilter, genEval, verifyRules } from "./runtime/types/agent.js";
12
- export { loopInstruction, classifyInstruction, judgeGoal, extractLoopContinue, extractClassifyBranch, extractJudgeWinner, } from "./runtime/workflow-control-flow.js";
13
- export { Governance } from "./governance.js";
14
- export type { GovernanceVerdict } from "./governance.js";
12
+ export { loopInstruction, classifyInstruction, judgeGoal, extractClassifyBranch, extractJudgeWinner, } from "./runtime/workflow-control-flow.js";
13
+ export { Agent } from "./agent.js";
14
+ export type { AgentMemory, AgentOptions, AgentToolDefinition, AgentRef, Guardrail, Handoff, Knowledge, KnowledgeSourceRef, MCPServer, McpTransport, MemoryReference, ModelRef, ModelRequirement, Skill, } from "./agent.js";
15
+ export { lowerAgent, normalizeAgent } from "./agent-ir.js";
16
+ export type { AgentCapabilityIR, AgentDefinition, AgentLoweringInputs, AgentMemoryIR, AgentSpec, AgentToolIR, } from "./agent-ir.js";
15
17
  export { AnthropicProvider } from "./providers/anthropic.js";
16
- export { OpenAIProvider, QwenProvider, DeepSeekProvider, MiniMaxProvider, KimiProvider } from "./providers/openai.js";
18
+ export { OpenAIProvider, qwen, deepseek, minimax, kimi } from "./providers/openai.js";
19
+ export type { OpenAIProviderOptions, BackendProviderOptions } from "./providers/openai.js";
20
+ export { ProviderError, classifyProviderError } from "./providers/provider-error.js";
21
+ export type { ProviderErrorKind, ProviderErrorOptions } from "./providers/provider-error.js";
22
+ export type { GovernancePolicy, GovernanceConstraint } from "./governance.js";
17
23
  export { tool, executeTools } from "./tools/index.js";
18
24
  export type { RegisteredTool, ToolExecContext } from "./tools/index.js";
19
25
  export { safeTool, ok, fail, ToolError, formatToolError } from "./tools/errors.js";
20
26
  export type { ToolEnvelope, ToolEnvelopeOk, ToolEnvelopeFail } from "./tools/errors.js";
21
27
  export { WorkingMemory } from "./memory/index.js";
22
- export { InMemoryDreamStore } from "./memory/in-memory-store.js";
23
- export type { InMemoryDreamStoreOptions } from "./memory/in-memory-store.js";
28
+ export { DurableMemory } from "./memory/durable.js";
29
+ export { InMemoryMemoryStore } from "./memory/in-memory-store.js";
30
+ export type { InMemoryMemoryStoreOptions } from "./memory/in-memory-store.js";
24
31
  export { memoryRetentionScore } from "./memory/retention.js";
25
32
  export { rankMemories } from "./memory/ranking.js";
26
33
  export type { RankableMemory, RankedMemory, RankOptions } from "./memory/ranking.js";
27
34
  export { extractSessionMemories, parseExtractedMemories } from "./memory/extraction.js";
28
- export type { DreamStore, SessionStore, SessionData, SessionMessage, MemoryRecord, MemoryRecall, MemoryRecallLifecycle, MemoryQuery, MemoryScope, MemoryProvenance, MemoryKind, MemoryAuthor, MemoryTrustLevel, } from "./memory/index.js";
35
+ export type { MemoryStore, Memory, MemorySearchOptions, SessionStore, SessionData, SessionMessage, MemoryRecord, MemoryRecall, MemoryRecallLifecycle, MemoryQuery, MemoryScope, MemoryProvenance, MemoryKind, MemoryAuthor, MemoryTrustLevel, } from "./memory/index.js";
29
36
  export type { KnowledgeSource } from "./knowledge/index.js";
30
37
  export { AttemptLoop, RuntimeAttemptBody, VerdictFnJudge, LlmEvalJudge, HybridJudge, continueSession, freshWithFeedback, freshWithDigest, } from "./harness/index.js";
31
38
  export type { AttemptBody, AttemptBodyContext, AttemptBodyEvent, AttemptBodyTerminal, AttemptJudge, AttemptLoopEvent, AttemptLoopOptions, AttemptOutcome, AttemptOutcomeKind, AttemptProgressEvent, AttemptRequest, CarryPolicy, JudgeContext, JudgeResult, PreparedAttempt, StopPolicy, VerdictFn, } from "./harness/index.js";
32
39
  export { ScheduledPrompt } from "./signals/index.js";
33
40
  export type { RuntimeSignal, SignalSource } from "./signals/index.js";
34
41
  export { PermissionManager, PermissionMode } from "./safety/index.js";
42
+ export { createProviderRequestPlan, createProviderRequestPlanForProvider, estimateProviderPromptTokens, measurementForPlan, normalizeProviderUsage, priceProviderUsage, recordPromptMeasurement } from "./providers/request-plan.js";
43
+ export type { CostObservation, NormalizedProviderUsage, PricingSnapshot, ProviderRequestEndpoint, ProviderRequestPlan, ProviderUsage, RecordedPromptMeasurement } from "./providers/request-plan.js";
44
+ export { decodeCanonicalStopReason, normalizeProviderStopReason } from "./providers/stop-reason.js";
45
+ export type { CanonicalStopReason } from "./providers/stop-reason.js";
46
+ export { ContentPolicyError, contentDispositionFor, requireContentDisposition } from "./providers/content-policy.js";
47
+ export type { ContentDisposition, ContentPlacement, InputModality } from "./providers/content-policy.js";
35
48
  export type { PermissionDecision } from "./safety/index.js";
36
49
  export type { Message, ToolCall, ToolResult, ToolSchema, RenderedContext, ProviderRunState, StreamEvent, TextDelta, ThinkingDelta, ToolCallEvent, ToolResultEvent, ToolAuditFailedEvent, DoneEvent, ErrorEvent, PermissionRequestEvent, PermissionResolvedEvent, PermissionResponse, EntropySample, EntropySampleEvent, EntropyAlertEvent, EntropyWatchOptions, LLMProvider, CacheBreakpointStrategy, } from "./types.js";
50
+ export { DurableContentError, decodeDurableContent, decodeDurableToolResult, encodeDurableContent, encodeDurableToolResult, toolOutputBlocksToDurable, durableBlocksToToolOutput } from "./runtime/durable-content.js";
51
+ export type { DurableContent, DurableContentBlock, DurableSource, DurableToolResult } from "./runtime/durable-content.js";
package/dist/index.js CHANGED
@@ -5,17 +5,24 @@ export { primitiveForCategory, primitiveForKind } from "./runtime/index.js";
5
5
  export { FilteredExecutionPlane } from "./runtime/filtered-plane.js";
6
6
  export { SubAgentOrchestrator, defaultSubAgentOrchestrator, spawnStandalone } from "./runtime/sub-agent-orchestrator.js";
7
7
  export { workflowSpecToKernel, workflowNodeSpecToKernel, submitWorkflowNodesTool, startWorkflowTool, fanoutSynthesize, generateAndFilter, genEval, verifyRules } from "./runtime/types/agent.js";
8
- export { loopInstruction, classifyInstruction, judgeGoal, extractLoopContinue, extractClassifyBranch, extractJudgeWinner, } from "./runtime/workflow-control-flow.js";
9
- export { Governance } from "./governance.js";
8
+ export { loopInstruction, classifyInstruction, judgeGoal, extractClassifyBranch, extractJudgeWinner, } from "./runtime/workflow-control-flow.js";
9
+ export { Agent } from "./agent.js";
10
+ export { lowerAgent, normalizeAgent } from "./agent-ir.js";
10
11
  export { AnthropicProvider } from "./providers/anthropic.js";
11
- export { OpenAIProvider, QwenProvider, DeepSeekProvider, MiniMaxProvider, KimiProvider } from "./providers/openai.js";
12
+ export { OpenAIProvider, qwen, deepseek, minimax, kimi } from "./providers/openai.js";
13
+ export { ProviderError, classifyProviderError } from "./providers/provider-error.js";
12
14
  export { tool, executeTools } from "./tools/index.js";
13
15
  export { safeTool, ok, fail, ToolError, formatToolError } from "./tools/errors.js";
14
16
  export { WorkingMemory } from "./memory/index.js";
15
- export { InMemoryDreamStore } from "./memory/in-memory-store.js";
17
+ export { DurableMemory } from "./memory/durable.js";
18
+ export { InMemoryMemoryStore } from "./memory/in-memory-store.js";
16
19
  export { memoryRetentionScore } from "./memory/retention.js";
17
20
  export { rankMemories } from "./memory/ranking.js";
18
21
  export { extractSessionMemories, parseExtractedMemories } from "./memory/extraction.js";
19
22
  export { AttemptLoop, RuntimeAttemptBody, VerdictFnJudge, LlmEvalJudge, HybridJudge, continueSession, freshWithFeedback, freshWithDigest, } from "./harness/index.js";
20
23
  export { ScheduledPrompt } from "./signals/index.js";
21
24
  export { PermissionManager, PermissionMode } from "./safety/index.js";
25
+ export { createProviderRequestPlan, createProviderRequestPlanForProvider, estimateProviderPromptTokens, measurementForPlan, normalizeProviderUsage, priceProviderUsage, recordPromptMeasurement } from "./providers/request-plan.js";
26
+ export { decodeCanonicalStopReason, normalizeProviderStopReason } from "./providers/stop-reason.js";
27
+ export { ContentPolicyError, contentDispositionFor, requireContentDisposition } from "./providers/content-policy.js";
28
+ export { DurableContentError, decodeDurableContent, decodeDurableToolResult, encodeDurableContent, encodeDurableToolResult, toolOutputBlocksToDurable, durableBlocksToToolOutput } from "./runtime/durable-content.js";
@@ -0,0 +1,13 @@
1
+ import type { Memory, MemoryRecord, MemoryScope, MemorySearchOptions, MemoryStore } from "./index.js";
2
+ /** Binds host storage to the public durable Memory contract for one agent and namespace. */
3
+ export declare class DurableMemory implements Memory {
4
+ private readonly store;
5
+ private readonly agentId;
6
+ private readonly scope;
7
+ readonly namespace: string;
8
+ constructor(store: MemoryStore, agentId: string, scope: MemoryScope);
9
+ search(query: string, options?: MemorySearchOptions): Promise<MemoryRecord[]>;
10
+ get(recordId: string): Promise<MemoryRecord | null>;
11
+ put(record: MemoryRecord): Promise<void>;
12
+ delete(recordId: string): Promise<void>;
13
+ }