@tangle-network/agent-runtime 0.13.0 → 0.13.1
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/dist/index.d.ts +20 -1
- package/dist/index.js +73 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -740,6 +740,25 @@ interface RunDurableResult<TResult> {
|
|
|
740
740
|
}
|
|
741
741
|
declare function runDurable<TResult>(input: RunDurableInput<TResult>): Promise<RunDurableResult<TResult>>;
|
|
742
742
|
|
|
743
|
+
/**
|
|
744
|
+
* The durable-runs SQL schema as a string constant. Inlined so consumers
|
|
745
|
+
* (Cloudflare Workers via D1) can apply it without bundling a `.sql` file:
|
|
746
|
+
*
|
|
747
|
+
* import { DURABLE_SCHEMA_SQL } from '@tangle-network/agent-runtime'
|
|
748
|
+
* await env.DB.exec(DURABLE_SCHEMA_SQL)
|
|
749
|
+
*
|
|
750
|
+
* The canonical source is `src/durable/schema.sql` — this string MUST stay
|
|
751
|
+
* byte-identical to it. The build does not copy `.sql` files into `dist/`,
|
|
752
|
+
* so the constant is the only path consumers have. A unit test asserts the
|
|
753
|
+
* two stay in sync (`durable-schema.test.ts`).
|
|
754
|
+
*
|
|
755
|
+
* `DURABLE_SCHEMA_VERSION` reflects the latest migration version applied by
|
|
756
|
+
* this string. Bump it on every backwards-incompatible change AND add a new
|
|
757
|
+
* migration entry to durable_schema_info instead of mutating prior rows.
|
|
758
|
+
*/
|
|
759
|
+
declare const DURABLE_SCHEMA_VERSION = 1;
|
|
760
|
+
declare const DURABLE_SCHEMA_SQL = "-- Durable-run substrate \u2014 versioned schema for D1 / SQLite.\n--\n-- Apply once per database. Subsequent migrations append; never rewrite a\n-- prior version. See `durable_schema_info` for the migration trail.\n--\n-- Concurrency notes for D1:\n-- - SQLite supports UNIQUE constraints for first-emit-wins (`durable_events`\n-- PK is (run_id, key) \u2014 duplicate insert raises, caller treats as \"already\n-- emitted\").\n-- - Lease takeover happens via a conditional UPDATE: we only claim the lease\n-- if (lease_holder_id IS NULL OR lease_expires_at < :now) \u2014 atomic under\n-- SQLite's row-level locking.\n-- - All timestamps stored as ISO-8601 TEXT for cross-platform consistency.\n-- - `result_json` / `error_json` / `outcome_json` / `payload_json` are\n-- JSON-encoded TEXT; the application enforces canonical-JSON discipline at\n-- the boundary so the store stays type-agnostic.\n\nCREATE TABLE IF NOT EXISTS durable_schema_info (\n version INTEGER PRIMARY KEY,\n applied_at TEXT NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS durable_runs (\n run_id TEXT PRIMARY KEY,\n manifest_hash TEXT NOT NULL,\n project_id TEXT NOT NULL,\n scenario_id TEXT,\n status TEXT NOT NULL CHECK (status IN ('pending','running','completed','failed','suspended')),\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n completed_at TEXT,\n lease_holder_id TEXT,\n lease_expires_at TEXT,\n outcome_json TEXT,\n step_count INTEGER NOT NULL DEFAULT 0\n);\n\nCREATE INDEX IF NOT EXISTS idx_durable_runs_project_status ON durable_runs(project_id, status);\nCREATE INDEX IF NOT EXISTS idx_durable_runs_lease_expires ON durable_runs(lease_expires_at);\n\nCREATE TABLE IF NOT EXISTS durable_steps (\n run_id TEXT NOT NULL,\n step_index INTEGER NOT NULL,\n intent TEXT NOT NULL,\n kind TEXT NOT NULL,\n input_hash TEXT NOT NULL DEFAULT '',\n status TEXT NOT NULL CHECK (status IN ('pending','running','completed','failed')),\n attempts INTEGER NOT NULL DEFAULT 0,\n result_json TEXT,\n error_json TEXT,\n started_at TEXT,\n completed_at TEXT,\n PRIMARY KEY (run_id, step_index)\n);\n\nCREATE INDEX IF NOT EXISTS idx_durable_steps_status ON durable_steps(run_id, status);\n\nCREATE TABLE IF NOT EXISTS durable_events (\n run_id TEXT NOT NULL,\n key TEXT NOT NULL,\n payload_json TEXT,\n emitted_at TEXT NOT NULL,\n PRIMARY KEY (run_id, key)\n);\n\nINSERT OR IGNORE INTO durable_schema_info (version, applied_at)\nVALUES (1, strftime('%Y-%m-%dT%H:%M:%fZ', 'now'));\n";
|
|
761
|
+
|
|
743
762
|
/**
|
|
744
763
|
* Cloudflare Workflows integration for the durable-run substrate.
|
|
745
764
|
*
|
|
@@ -1405,4 +1424,4 @@ declare function createTraceBridge(options: TraceBridgeOptions): TraceBridge;
|
|
|
1405
1424
|
*/
|
|
1406
1425
|
declare function toAgentEvalTrace(event: RuntimeStreamEvent, options: TraceBridgeOptions): TraceEvent | undefined;
|
|
1407
1426
|
|
|
1408
|
-
export { AgentBackendContext, AgentBackendInput, AgentExecutionBackend, AgentRuntimeEvent, AgentTaskRunResult, AgentTaskRunSummary, AgentTaskSpec, AgentTaskStatus, type BackendRetryPolicy, BackendTransportError, ChatTurnError, type ChatTurnMessage, type ChatTurnOverlay, type ChatTurnSandbox, type ClassifyIntentOptions, type ClassifyIntentResult, type ConformanceIssue, type ConformanceOptions, type ConformanceResult, type D1DatabaseLike, D1DurableRunStore, type D1PreparedStatementLike, DurableAwaitEventTimeoutError, type DurableContext, DurableRunDivergenceError, DurableRunError, DurableRunInputMismatchError, DurableRunLeaseHeldError, type DurableRunManifest, type DurableRunStore, type EventRecord, FileSystemDurableRunStore, InMemoryDurableRunStore, InMemoryRuntimeSessionStore, KnowledgeReadinessDecision, RunAgentTaskOptions, RunAgentTaskStreamOptions, type RunChatTurnOptions, type RunDurableInput, type RunDurableResult, type RunOnWorkflowStepInput, type RunOutcome, type RunStatus, type RuntimeEventCollector, type RuntimeRunCompleteInput, type RuntimeRunCost, type RuntimeRunHandle, type RuntimeRunOptions, type RuntimeRunPersistenceAdapter, type RuntimeRunRow, RuntimeRunStateError, type RuntimeRunStatus, RuntimeSession, RuntimeSessionStore, RuntimeStreamEvent, type RuntimeStreamEventCollector, type RuntimeStreamEventSink, type RuntimeStreamEventSummary, type RuntimeTelemetryOptions, type SanitizedKnowledgeReadinessReport, type SanitizedKnowledgeRequirement, type ServerSentEventOptions, SessionMismatchError, type StepError, type StepKind, type StepRecord, type StepStatus, type SubagentMatcher, type TraceBridge, type TraceBridgeOptions, type WorkflowStepConfig, type WorkflowStepLike, assertProfileConformance, canonicalHash, canonicalJson, classifyIntent, composeTurnProfile, createIterableBackend, createOpenAICompatibleBackend, createRuntimeEventCollector, createRuntimeStreamEventCollector, createSandboxPromptBackend, createTraceBridge, decideKnowledgeReadiness, deriveWorkerId, encodeServerSentEvent, manifestHash, readinessServerSentEvent, runAgentTask, runAgentTaskStream, runChatTurn, runDurable, runOnWorkflowStep, runtimeStreamServerSentEvent, sandboxAsChatTurnTarget, sanitizeAgentRuntimeEvent, sanitizeKnowledgeReadinessReport, sanitizeRuntimeStreamEvent, startRuntimeRun, stepId, summarizeAgentTaskRun, toAgentEvalTrace };
|
|
1427
|
+
export { AgentBackendContext, AgentBackendInput, AgentExecutionBackend, AgentRuntimeEvent, AgentTaskRunResult, AgentTaskRunSummary, AgentTaskSpec, AgentTaskStatus, type BackendRetryPolicy, BackendTransportError, ChatTurnError, type ChatTurnMessage, type ChatTurnOverlay, type ChatTurnSandbox, type ClassifyIntentOptions, type ClassifyIntentResult, type ConformanceIssue, type ConformanceOptions, type ConformanceResult, type D1DatabaseLike, D1DurableRunStore, type D1PreparedStatementLike, DURABLE_SCHEMA_SQL, DURABLE_SCHEMA_VERSION, DurableAwaitEventTimeoutError, type DurableContext, DurableRunDivergenceError, DurableRunError, DurableRunInputMismatchError, DurableRunLeaseHeldError, type DurableRunManifest, type DurableRunStore, type EventRecord, FileSystemDurableRunStore, InMemoryDurableRunStore, InMemoryRuntimeSessionStore, KnowledgeReadinessDecision, RunAgentTaskOptions, RunAgentTaskStreamOptions, type RunChatTurnOptions, type RunDurableInput, type RunDurableResult, type RunOnWorkflowStepInput, type RunOutcome, type RunStatus, type RuntimeEventCollector, type RuntimeRunCompleteInput, type RuntimeRunCost, type RuntimeRunHandle, type RuntimeRunOptions, type RuntimeRunPersistenceAdapter, type RuntimeRunRow, RuntimeRunStateError, type RuntimeRunStatus, RuntimeSession, RuntimeSessionStore, RuntimeStreamEvent, type RuntimeStreamEventCollector, type RuntimeStreamEventSink, type RuntimeStreamEventSummary, type RuntimeTelemetryOptions, type SanitizedKnowledgeReadinessReport, type SanitizedKnowledgeRequirement, type ServerSentEventOptions, SessionMismatchError, type StepError, type StepKind, type StepRecord, type StepStatus, type SubagentMatcher, type TraceBridge, type TraceBridgeOptions, type WorkflowStepConfig, type WorkflowStepLike, assertProfileConformance, canonicalHash, canonicalJson, classifyIntent, composeTurnProfile, createIterableBackend, createOpenAICompatibleBackend, createRuntimeEventCollector, createRuntimeStreamEventCollector, createSandboxPromptBackend, createTraceBridge, decideKnowledgeReadiness, deriveWorkerId, encodeServerSentEvent, manifestHash, readinessServerSentEvent, runAgentTask, runAgentTaskStream, runChatTurn, runDurable, runOnWorkflowStep, runtimeStreamServerSentEvent, sandboxAsChatTurnTarget, sanitizeAgentRuntimeEvent, sanitizeKnowledgeReadinessReport, sanitizeRuntimeStreamEvent, startRuntimeRun, stepId, summarizeAgentTaskRun, toAgentEvalTrace };
|
package/dist/index.js
CHANGED
|
@@ -1489,6 +1489,77 @@ function cryptoRandomUuid() {
|
|
|
1489
1489
|
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
1490
1490
|
}
|
|
1491
1491
|
|
|
1492
|
+
// src/durable/schema.ts
|
|
1493
|
+
var DURABLE_SCHEMA_VERSION = 1;
|
|
1494
|
+
var DURABLE_SCHEMA_SQL = `-- Durable-run substrate \u2014 versioned schema for D1 / SQLite.
|
|
1495
|
+
--
|
|
1496
|
+
-- Apply once per database. Subsequent migrations append; never rewrite a
|
|
1497
|
+
-- prior version. See \`durable_schema_info\` for the migration trail.
|
|
1498
|
+
--
|
|
1499
|
+
-- Concurrency notes for D1:
|
|
1500
|
+
-- - SQLite supports UNIQUE constraints for first-emit-wins (\`durable_events\`
|
|
1501
|
+
-- PK is (run_id, key) \u2014 duplicate insert raises, caller treats as "already
|
|
1502
|
+
-- emitted").
|
|
1503
|
+
-- - Lease takeover happens via a conditional UPDATE: we only claim the lease
|
|
1504
|
+
-- if (lease_holder_id IS NULL OR lease_expires_at < :now) \u2014 atomic under
|
|
1505
|
+
-- SQLite's row-level locking.
|
|
1506
|
+
-- - All timestamps stored as ISO-8601 TEXT for cross-platform consistency.
|
|
1507
|
+
-- - \`result_json\` / \`error_json\` / \`outcome_json\` / \`payload_json\` are
|
|
1508
|
+
-- JSON-encoded TEXT; the application enforces canonical-JSON discipline at
|
|
1509
|
+
-- the boundary so the store stays type-agnostic.
|
|
1510
|
+
|
|
1511
|
+
CREATE TABLE IF NOT EXISTS durable_schema_info (
|
|
1512
|
+
version INTEGER PRIMARY KEY,
|
|
1513
|
+
applied_at TEXT NOT NULL
|
|
1514
|
+
);
|
|
1515
|
+
|
|
1516
|
+
CREATE TABLE IF NOT EXISTS durable_runs (
|
|
1517
|
+
run_id TEXT PRIMARY KEY,
|
|
1518
|
+
manifest_hash TEXT NOT NULL,
|
|
1519
|
+
project_id TEXT NOT NULL,
|
|
1520
|
+
scenario_id TEXT,
|
|
1521
|
+
status TEXT NOT NULL CHECK (status IN ('pending','running','completed','failed','suspended')),
|
|
1522
|
+
created_at TEXT NOT NULL,
|
|
1523
|
+
updated_at TEXT NOT NULL,
|
|
1524
|
+
completed_at TEXT,
|
|
1525
|
+
lease_holder_id TEXT,
|
|
1526
|
+
lease_expires_at TEXT,
|
|
1527
|
+
outcome_json TEXT,
|
|
1528
|
+
step_count INTEGER NOT NULL DEFAULT 0
|
|
1529
|
+
);
|
|
1530
|
+
|
|
1531
|
+
CREATE INDEX IF NOT EXISTS idx_durable_runs_project_status ON durable_runs(project_id, status);
|
|
1532
|
+
CREATE INDEX IF NOT EXISTS idx_durable_runs_lease_expires ON durable_runs(lease_expires_at);
|
|
1533
|
+
|
|
1534
|
+
CREATE TABLE IF NOT EXISTS durable_steps (
|
|
1535
|
+
run_id TEXT NOT NULL,
|
|
1536
|
+
step_index INTEGER NOT NULL,
|
|
1537
|
+
intent TEXT NOT NULL,
|
|
1538
|
+
kind TEXT NOT NULL,
|
|
1539
|
+
input_hash TEXT NOT NULL DEFAULT '',
|
|
1540
|
+
status TEXT NOT NULL CHECK (status IN ('pending','running','completed','failed')),
|
|
1541
|
+
attempts INTEGER NOT NULL DEFAULT 0,
|
|
1542
|
+
result_json TEXT,
|
|
1543
|
+
error_json TEXT,
|
|
1544
|
+
started_at TEXT,
|
|
1545
|
+
completed_at TEXT,
|
|
1546
|
+
PRIMARY KEY (run_id, step_index)
|
|
1547
|
+
);
|
|
1548
|
+
|
|
1549
|
+
CREATE INDEX IF NOT EXISTS idx_durable_steps_status ON durable_steps(run_id, status);
|
|
1550
|
+
|
|
1551
|
+
CREATE TABLE IF NOT EXISTS durable_events (
|
|
1552
|
+
run_id TEXT NOT NULL,
|
|
1553
|
+
key TEXT NOT NULL,
|
|
1554
|
+
payload_json TEXT,
|
|
1555
|
+
emitted_at TEXT NOT NULL,
|
|
1556
|
+
PRIMARY KEY (run_id, key)
|
|
1557
|
+
);
|
|
1558
|
+
|
|
1559
|
+
INSERT OR IGNORE INTO durable_schema_info (version, applied_at)
|
|
1560
|
+
VALUES (1, strftime('%Y-%m-%dT%H:%M:%fZ', 'now'));
|
|
1561
|
+
`;
|
|
1562
|
+
|
|
1492
1563
|
// src/durable/workflows.ts
|
|
1493
1564
|
async function runOnWorkflowStep(workflowStep, input) {
|
|
1494
1565
|
const stepCfg = input.stepConfig;
|
|
@@ -2791,6 +2862,8 @@ export {
|
|
|
2791
2862
|
ChatTurnError,
|
|
2792
2863
|
ConfigError,
|
|
2793
2864
|
D1DurableRunStore,
|
|
2865
|
+
DURABLE_SCHEMA_SQL,
|
|
2866
|
+
DURABLE_SCHEMA_VERSION,
|
|
2794
2867
|
DurableAwaitEventTimeoutError,
|
|
2795
2868
|
DurableRunDivergenceError,
|
|
2796
2869
|
DurableRunError,
|