agentledger-runtime 1.0.2
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 +119 -0
- package/examples/README.md +22 -0
- package/examples/quickstart/quickstart.js +7 -0
- package/examples/travel_assistant/travel_assistant.js +396 -0
- package/package.json +21 -0
- package/src/cli.js +733 -0
- package/src/index.d.ts +235 -0
- package/src/index.js +1683 -0
- package/test/runtime.test.js +272 -0
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
export type JSONObject = Record<string, unknown>;
|
|
2
|
+
|
|
3
|
+
export interface ToolSpec {
|
|
4
|
+
name: string;
|
|
5
|
+
version?: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
sideEffect?: 'none' | 'external' | string;
|
|
8
|
+
riskLevel?: 'low' | 'medium' | 'high' | string;
|
|
9
|
+
idempotencyRequired?: boolean;
|
|
10
|
+
approvalRequired?: boolean;
|
|
11
|
+
sandboxRequired?: boolean;
|
|
12
|
+
sandboxExecutor?: string | null;
|
|
13
|
+
sandboxPolicy?: JSONObject;
|
|
14
|
+
inputSchema?: JSONObject;
|
|
15
|
+
outputSchema?: JSONObject;
|
|
16
|
+
func: (args: JSONObject) => unknown | Promise<unknown>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface RunRef {
|
|
20
|
+
runId: string;
|
|
21
|
+
stepId: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface BudgetLimits {
|
|
25
|
+
maxToolCalls?: number | null;
|
|
26
|
+
maxModelTokens?: number | null;
|
|
27
|
+
maxTotalUsd?: number | null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class NoRunnableStepError extends Error {}
|
|
31
|
+
export class RetryableAgentError extends Error {}
|
|
32
|
+
export class PermissionDeniedError extends Error {}
|
|
33
|
+
export class ApprovalRequiredError extends Error { readonly approvalId: string; }
|
|
34
|
+
export class BudgetExceededError extends Error {}
|
|
35
|
+
export class SandboxUnavailableError extends Error {}
|
|
36
|
+
|
|
37
|
+
export class LocalBlobStore {
|
|
38
|
+
constructor(root: string);
|
|
39
|
+
static open(root: string): Promise<LocalBlobStore>;
|
|
40
|
+
putJSON(value: unknown): Promise<{ digest: string; ref: string }>;
|
|
41
|
+
getJSON(ref: string): Promise<unknown>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export class JSONStore {
|
|
45
|
+
constructor(path?: string | null, data?: unknown);
|
|
46
|
+
static memory(): JSONStore;
|
|
47
|
+
static open(path: string): Promise<JSONStore>;
|
|
48
|
+
flush(): Promise<void>;
|
|
49
|
+
createRun(initialState?: JSONObject, sessionId?: string | null): Promise<RunRef>;
|
|
50
|
+
claimStep(input: { workerId: string; runId?: string | null; leaseSeconds?: number }): Promise<JSONObject>;
|
|
51
|
+
loadState(runId: string): { state: JSONObject; version: number; sessionId: string };
|
|
52
|
+
heartbeat(input: { stepId: string; leaseToken: string; leaseSeconds?: number }): Promise<number>;
|
|
53
|
+
recoverExpiredLeases(): Promise<number>;
|
|
54
|
+
cancelRun(runId: string, reason: string): Promise<number>;
|
|
55
|
+
commitStatePatch(input: { runId: string; stepId: string; leaseToken: string; baseVersion: number; patch?: JSONObject; checkpointId?: string | null }): Promise<number>;
|
|
56
|
+
markWaitingHuman(input: { runId: string; stepId: string; reason: string; approvalId?: string | null }): Promise<void>;
|
|
57
|
+
approvalRequests(runId?: string | null): JSONObject[];
|
|
58
|
+
approveRequest(approvalId: string, input?: { approver?: string; reason?: string }): Promise<JSONObject>;
|
|
59
|
+
denyRequest(approvalId: string, input?: { approver?: string; reason?: string }): Promise<JSONObject>;
|
|
60
|
+
recordCost(input: { runId: string; sessionId?: string | null; stepId?: string | null; category: string; name: string; amount: number; unit: string; metadata?: JSONObject }): Promise<string>;
|
|
61
|
+
costRecords(runId: string): JSONObject[];
|
|
62
|
+
costSummary(runId: string): JSONObject;
|
|
63
|
+
createArtifact(input: { runId: string; stepId?: string | null; name: string; content: unknown; metadata?: JSONObject }): Promise<JSONObject>;
|
|
64
|
+
artifacts(runId: string): JSONObject[];
|
|
65
|
+
finalState(runId: string): JSONObject;
|
|
66
|
+
steps(runId: string): JSONObject[];
|
|
67
|
+
events(runId: string): JSONObject[];
|
|
68
|
+
ledger(runId: string): JSONObject[];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export class ToolRegistry {
|
|
72
|
+
constructor();
|
|
73
|
+
register(spec: ToolSpec): void;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export class PolicyEngine {
|
|
77
|
+
constructor();
|
|
78
|
+
allowTool(role: string, tool: string): void;
|
|
79
|
+
denyTool(role: string, tool: string): void;
|
|
80
|
+
allowRisk(role: string, risk: string): void;
|
|
81
|
+
checkTool(role: string, toolName: string, riskLevel: string): { allowed: boolean; reason: string };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export class BudgetController {
|
|
85
|
+
constructor(limits?: BudgetLimits);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export class DisabledSandboxExecutor {
|
|
89
|
+
runTool(spec: ToolSpec, args: JSONObject, policy: JSONObject): Promise<JSONObject>;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export class LocalSandboxExecutor {
|
|
93
|
+
runTool(spec: ToolSpec, args: JSONObject, policy: JSONObject): Promise<JSONObject>;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function validateToolSchema(schema: JSONObject | undefined | null, value: unknown, path?: string): void;
|
|
97
|
+
|
|
98
|
+
export class Runtime {
|
|
99
|
+
constructor(store?: JSONStore);
|
|
100
|
+
static local(path: string): Promise<Runtime>;
|
|
101
|
+
setBudget(limits?: BudgetLimits): void;
|
|
102
|
+
setSandbox(executor: unknown): void;
|
|
103
|
+
registerTool(spec: ToolSpec): void;
|
|
104
|
+
createRun(initialState?: JSONObject): Promise<RunRef>;
|
|
105
|
+
runOnce(input: {
|
|
106
|
+
runId: string;
|
|
107
|
+
workerId?: string;
|
|
108
|
+
agentRole?: string;
|
|
109
|
+
leaseSeconds?: number;
|
|
110
|
+
agent: (ctx: AgentContext, state: JSONObject) => void | Promise<void>;
|
|
111
|
+
}): Promise<boolean>;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export class LocalWorker {
|
|
115
|
+
constructor(runtime: Runtime, options?: { workerId?: string; agentRole?: string; leaseSeconds?: number; recoverExpired?: boolean });
|
|
116
|
+
runUntilIdle(input: { runId?: string | null; maxIterations?: number; agent: (ctx: AgentContext, state: JSONObject) => void | Promise<void> }): Promise<JSONObject>;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export class WorkerService {
|
|
120
|
+
constructor(worker: LocalWorker);
|
|
121
|
+
requestStop(reason?: string): void;
|
|
122
|
+
serve(input: { runId?: string | null; maxLoops?: number; maxIdlePolls?: number | null; agent: (ctx: AgentContext, state: JSONObject) => void | Promise<void> }): Promise<JSONObject>;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export class AgentContext {
|
|
126
|
+
readonly runId: string;
|
|
127
|
+
readonly sessionId: string;
|
|
128
|
+
readonly stepId: string;
|
|
129
|
+
readonly agentRole: string;
|
|
130
|
+
readonly leaseToken: string;
|
|
131
|
+
readonly attempt: number;
|
|
132
|
+
readonly stateVersion: number;
|
|
133
|
+
readonly pendingPatch: JSONObject;
|
|
134
|
+
callTool(name: string, args?: JSONObject): Promise<unknown>;
|
|
135
|
+
writeState(key: string, value: unknown): Promise<void>;
|
|
136
|
+
createArtifact(name: string, content: unknown, metadata?: JSONObject): Promise<string>;
|
|
137
|
+
createMediaArtifact(name: string, kind: string, options?: {
|
|
138
|
+
uri?: string;
|
|
139
|
+
contentRef?: string;
|
|
140
|
+
mediaMetadata?: JSONObject;
|
|
141
|
+
lineage?: JSONObject;
|
|
142
|
+
derivedOutputs?: JSONObject;
|
|
143
|
+
metadata?: JSONObject;
|
|
144
|
+
}): Promise<string>;
|
|
145
|
+
createStreamCheckpoint(name: string, options: {
|
|
146
|
+
streamId: string;
|
|
147
|
+
consumerId: string;
|
|
148
|
+
offset: number | string;
|
|
149
|
+
watermark?: number | string;
|
|
150
|
+
chunk?: JSONObject;
|
|
151
|
+
partialResultRef?: string;
|
|
152
|
+
backpressure?: JSONObject;
|
|
153
|
+
metadata?: JSONObject;
|
|
154
|
+
}): Promise<string>;
|
|
155
|
+
recordModelCall(input: { model: string; inputTokens?: number; outputTokens?: number; totalUsd?: number }): Promise<void>;
|
|
156
|
+
heartbeat(leaseSeconds?: number): Promise<number>;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function exportEvidence(store: JSONStore, runId: string): JSONObject;
|
|
160
|
+
export function replay(store: JSONStore, runId: string): JSONObject;
|
|
161
|
+
export function costAttribution(store: JSONStore, runId: string): JSONObject;
|
|
162
|
+
export function failureAttribution(store: JSONStore, runId: string): JSONObject;
|
|
163
|
+
|
|
164
|
+
export function traceSpans(bundle: any): any[];
|
|
165
|
+
export function traceJSONL(bundle: any): string;
|
|
166
|
+
export function diffEvidence(left: any, right: any): any;
|
|
167
|
+
export function divergenceReport(left: any, right: any): any;
|
|
168
|
+
export function debugSummary(bundle: any): any;
|
|
169
|
+
|
|
170
|
+
export function simpleRun(agent: (ctx: any, state: any) => any | Promise<any>, options?: any): Promise<any>;
|
|
171
|
+
|
|
172
|
+
export function otlpTraceJSON(bundle: any, options?: any): any;
|
|
173
|
+
|
|
174
|
+
export function debugHTML(bundle: any): string;
|
|
175
|
+
|
|
176
|
+
export function planRetention(bundle: any): any;
|
|
177
|
+
export function checkBackupReadiness(bundle: any): any;
|
|
178
|
+
export function migrationsFor(dialect: string): any[];
|
|
179
|
+
export function latestSchemaVersion(dialect: string): string | null;
|
|
180
|
+
export function ddlFor(dialect: string): string;
|
|
181
|
+
export class InMemoryMCPToolServer { addTool(descriptor: any, handler: any): void; listTools(): any[]; callTool(name: string, args?: any): any; }
|
|
182
|
+
export class InMemoryMCPContextServer { addResource(options: any): void; listResources(): any[]; readResource(uri: string): any; }
|
|
183
|
+
export class MCPToolAdapter { constructor(clientCall: any); toolSpecFromDescriptor(descriptor: any): any; }
|
|
184
|
+
export class MCPContextAdapter { constructor(resourceRead: any); readToolSpec(options?: any): any; }
|
|
185
|
+
export class FunctionAdapter { constructor(func: any, options?: any); mapRunSpec(): any; asAgent(options?: any): any; }
|
|
186
|
+
export class MethodFrameworkAdapter { constructor(target: any, options?: any); mapRunSpec(): any; asAgent(): any; invoke(payload: any): any; }
|
|
187
|
+
|
|
188
|
+
export interface BoundaryLintRule { rule_id: string; pattern: string; category: string; message: string; suggestion: string; prefix?: boolean; }
|
|
189
|
+
export interface BoundaryLintFinding { path: string; line: number; column: number; rule_id: string; severity: string; callee: string; category: string; message: string; suggestion: string; }
|
|
190
|
+
export interface BoundaryLintReport { passed: boolean; scanned_files: string[]; finding_count: number; findings: BoundaryLintFinding[]; }
|
|
191
|
+
export function defaultBoundaryRules(): BoundaryLintRule[];
|
|
192
|
+
export function scanBoundarySource(path: string, source: string, rules?: BoundaryLintRule[]): BoundaryLintReport;
|
|
193
|
+
|
|
194
|
+
export interface RecoverySummary { recovered_steps: number; }
|
|
195
|
+
export interface SchedulerStepStatus { step_id: string; status: string; owner?: string | null; attempt: number; lease_until?: number | null; last_error_type?: string | null; }
|
|
196
|
+
export interface SchedulerStatus { run_id: string; run_status: string; state_version: number; steps: SchedulerStepStatus[]; cost_summary: CostSummary; }
|
|
197
|
+
export class RuntimeScheduler {
|
|
198
|
+
constructor(store: JSONStore);
|
|
199
|
+
recoverExpiredLeases(): Promise<RecoverySummary>;
|
|
200
|
+
cancelRun(runId: string, reason?: string): Promise<number>;
|
|
201
|
+
status(runId: string): SchedulerStatus;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export interface ReviewCheck { name: string; passed: boolean; severity: string; detail: string; }
|
|
205
|
+
export interface AdversarialReviewReport { passed: boolean; run_id?: string | null; checks: ReviewCheck[]; metadata: Record<string, unknown>; }
|
|
206
|
+
export function adversarialReview(bundle: EvidenceBundle | Record<string, unknown>, options?: { maxTotalUsd?: number | null }): AdversarialReviewReport;
|
|
207
|
+
|
|
208
|
+
export interface EvidenceCheck { name: string; passed: boolean; detail: string; }
|
|
209
|
+
export interface EvidenceCheckReport { passed: boolean; checks: EvidenceCheck[]; metadata?: Record<string, unknown>; }
|
|
210
|
+
export function evaluateEvidence(bundle: EvidenceBundle | Record<string, unknown>, options?: { maxTotalUsd?: number | null }): EvidenceCheckReport;
|
|
211
|
+
export function evaluateEvidenceRegression(golden: EvidenceBundle | Record<string, unknown>, current: EvidenceBundle | Record<string, unknown>, options?: { maxTotalUsdDelta?: number | null }): EvidenceCheckReport;
|
|
212
|
+
|
|
213
|
+
export interface FailureInjectionCheck { name: string; passed: boolean; detail: string; run_id?: string; }
|
|
214
|
+
export interface FailureInjectionReport { passed: boolean; checks: FailureInjectionCheck[]; }
|
|
215
|
+
export function runFailureInjectionSuite(): Promise<FailureInjectionReport>;
|
|
216
|
+
|
|
217
|
+
export interface ShadowReport { source_run_id: string; shadow_run_id: string; ok: boolean; state_diff: Record<string, unknown>; }
|
|
218
|
+
export function diffStates(source: Record<string, unknown>, shadow: Record<string, unknown>): Record<string, unknown>;
|
|
219
|
+
export function shadowReport(sourceRunId: string, shadowRunId: string, ok: boolean, sourceState: Record<string, unknown>, shadowState: Record<string, unknown>): ShadowReport;
|
|
220
|
+
|
|
221
|
+
export function builtinGoldenNames(): string[];
|
|
222
|
+
export function builtinGoldenEvidence(name: string): Promise<EvidenceBundle>;
|
|
223
|
+
export function goldenRegression(golden: EvidenceBundle, current: EvidenceBundle): EvidenceCheckReport;
|
|
224
|
+
|
|
225
|
+
export interface TimeTravelFrame { seq: number; event_id?: string; type: string; step_id?: string | null; agent_role?: string | null; state_version?: number | null; timestamp: number; state_changed: boolean; changed_keys: string[]; patch?: Record<string, unknown> | null; state_after?: Record<string, unknown> | null; }
|
|
226
|
+
export interface TimeTravelReport { run_id: string | null; at_seq: number | null; event_count: number; timeline: TimeTravelFrame[]; state_at_seq: Record<string, unknown>; selected_event: TimeTravelFrame | null; }
|
|
227
|
+
export function timeTravel(bundle: EvidenceBundle | Record<string, unknown>, options?: { atSeq?: number; includeStates?: boolean }): TimeTravelReport;
|
|
228
|
+
export function timeTravelHTML(report: TimeTravelReport): string;
|
|
229
|
+
|
|
230
|
+
export function optionalAdapterCapabilities(): Array<{ name: string; category: string; core_imports_heavy_sdks: boolean; adapter_is_optional: boolean; fail_closed_without_adapter: boolean; contract_surface: string[] }>;
|
|
231
|
+
|
|
232
|
+
export class PostgresAdapter { constructor(client: any, options?: any); migrationPlan(): any[]; applyMigrations(): Promise<void>; }
|
|
233
|
+
export class S3BlobStoreAdapter { constructor(client: any, options?: any); putJSON(value: any): Promise<{ digest: string; ref: string }>; getJSON(ref: string): Promise<any>; }
|
|
234
|
+
export class OTLPTransport { constructor(client: any, options?: any); export(payload: any): Promise<any>; }
|
|
235
|
+
export class DockerSandboxAdapter { constructor(options?: any); manifest(policy: any, command: string[]): any; }
|