@tangle-network/agent-runtime 0.18.0 → 0.19.0
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/agent.d.ts +1 -1
- package/dist/chunk-RZAOYKCO.js +51 -0
- package/dist/chunk-RZAOYKCO.js.map +1 -0
- package/dist/chunk-XLWPTPRP.js +52 -0
- package/dist/chunk-XLWPTPRP.js.map +1 -0
- package/dist/index.d.ts +4 -137
- package/dist/index.js +8 -38
- package/dist/index.js.map +1 -1
- package/dist/loops.d.ts +153 -0
- package/dist/loops.js +379 -0
- package/dist/loops.js.map +1 -0
- package/dist/profiles.d.ts +133 -0
- package/dist/profiles.js +249 -0
- package/dist/profiles.js.map +1 -0
- package/dist/runtime-run-4pbY3Jq5.d.ts +137 -0
- package/dist/{types-ByIhNRFk.d.ts → types-DlyPgeI0.d.ts} +1 -1
- package/dist/types-EKcAHfxI.d.ts +225 -0
- package/package.json +11 -1
package/dist/agent.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _tangle_network_agent_eval from '@tangle-network/agent-eval';
|
|
2
2
|
import { FindingSubject, TraceAnalystKindSpec, AnalystFinding } from '@tangle-network/agent-eval';
|
|
3
|
-
import { R as RuntimeStreamEvent } from './types-
|
|
3
|
+
import { R as RuntimeStreamEvent } from './types-DlyPgeI0.js';
|
|
4
4
|
import { I as ImprovementAdapter, K as KnowledgeAdapter, a as RunAnalystLoopResult } from './types-D_MXrmJP.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
import { AgentEvalError } from "@tangle-network/agent-eval";
|
|
3
|
+
import {
|
|
4
|
+
AgentEvalError as AgentEvalError2,
|
|
5
|
+
CaptureIntegrityError,
|
|
6
|
+
ConfigError,
|
|
7
|
+
JudgeError,
|
|
8
|
+
NotFoundError,
|
|
9
|
+
ReplayError,
|
|
10
|
+
ValidationError,
|
|
11
|
+
VerificationError
|
|
12
|
+
} from "@tangle-network/agent-eval";
|
|
13
|
+
var SessionMismatchError = class extends AgentEvalError {
|
|
14
|
+
sessionBackend;
|
|
15
|
+
requestedBackend;
|
|
16
|
+
constructor(sessionBackend, requestedBackend, options) {
|
|
17
|
+
super(
|
|
18
|
+
"validation",
|
|
19
|
+
`Cannot resume ${sessionBackend} session with ${requestedBackend} backend`,
|
|
20
|
+
options
|
|
21
|
+
);
|
|
22
|
+
this.sessionBackend = sessionBackend;
|
|
23
|
+
this.requestedBackend = requestedBackend;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var BackendTransportError = class extends AgentEvalError {
|
|
27
|
+
backend;
|
|
28
|
+
status;
|
|
29
|
+
constructor(backend, message, options) {
|
|
30
|
+
super("config", message, options);
|
|
31
|
+
this.backend = backend;
|
|
32
|
+
this.status = options?.status;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var RuntimeRunStateError = class extends AgentEvalError {
|
|
36
|
+
constructor(message, options) {
|
|
37
|
+
super("validation", message, options);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export {
|
|
42
|
+
SessionMismatchError,
|
|
43
|
+
BackendTransportError,
|
|
44
|
+
RuntimeRunStateError,
|
|
45
|
+
AgentEvalError2 as AgentEvalError,
|
|
46
|
+
ConfigError,
|
|
47
|
+
JudgeError,
|
|
48
|
+
NotFoundError,
|
|
49
|
+
ValidationError
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=chunk-RZAOYKCO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts"],"sourcesContent":["/**\n * @stable\n *\n * Error taxonomy for `@tangle-network/agent-runtime`.\n *\n * Public contract: every error this package throws as part of its consumer-\n * facing API either extends `AgentEvalError` (re-exported here for ergonomic\n * `instanceof` checks at the runtime boundary) or extends one of the\n * runtime-specific subclasses below.\n *\n * Internal invariant guards (`throw new Error('this should never happen')`)\n * remain plain `Error` — they are programmer-mistake assertions, not\n * consumer-catchable contract failures.\n *\n * Subclassing strategy: where a runtime-specific failure maps cleanly to an\n * agent-eval code (validation, config, not_found), we re-use the agent-eval\n * subclass. Runtime-only failure modes (session resume against the wrong\n * backend, backend transport errors) get fresh subclasses that still carry an\n * `AgentEvalErrorCode` so cross-package handlers can pattern-match without\n * importing the runtime.\n */\n\nimport { AgentEvalError } from '@tangle-network/agent-eval'\n\nexport {\n AgentEvalError,\n type AgentEvalErrorCode,\n CaptureIntegrityError,\n ConfigError,\n JudgeError,\n NotFoundError,\n ReplayError,\n ValidationError,\n VerificationError,\n} from '@tangle-network/agent-eval'\n\n/**\n * @stable\n *\n * Caller asked to resume a session against a backend whose `kind` does not\n * match the session's recorded backend. This is a routing bug — the same\n * session id was reused across two different backend implementations — and\n * is not retryable without picking the right backend.\n */\nexport class SessionMismatchError extends AgentEvalError {\n readonly sessionBackend: string\n readonly requestedBackend: string\n\n constructor(sessionBackend: string, requestedBackend: string, options?: { cause?: unknown }) {\n super(\n 'validation',\n `Cannot resume ${sessionBackend} session with ${requestedBackend} backend`,\n options,\n )\n this.sessionBackend = sessionBackend\n this.requestedBackend = requestedBackend\n }\n}\n\n/**\n * @stable\n *\n * A backend transport call (HTTP, gRPC, sidecar IPC) failed with a non-success\n * status. Distinct from `JudgeError` (which is structural / unrecoverable)\n * because backend failures are sometimes retryable and consumers may want to\n * branch on the upstream status code.\n */\nexport class BackendTransportError extends AgentEvalError {\n readonly backend: string\n readonly status?: number\n\n constructor(backend: string, message: string, options?: { cause?: unknown; status?: number }) {\n super('config', message, options)\n this.backend = backend\n this.status = options?.status\n }\n}\n\n/**\n * @stable\n *\n * A runtime-run lifecycle method was called in an order the state machine does\n * not allow: `persist()` before `complete()`, `complete()` twice, etc.\n */\nexport class RuntimeRunStateError extends AgentEvalError {\n constructor(message: string, options?: { cause?: unknown }) {\n super('validation', message, options)\n }\n}\n"],"mappings":";AAsBA,SAAS,sBAAsB;AAE/B;AAAA,EACE,kBAAAA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAUA,IAAM,uBAAN,cAAmC,eAAe;AAAA,EAC9C;AAAA,EACA;AAAA,EAET,YAAY,gBAAwB,kBAA0B,SAA+B;AAC3F;AAAA,MACE;AAAA,MACA,iBAAiB,cAAc,iBAAiB,gBAAgB;AAAA,MAChE;AAAA,IACF;AACA,SAAK,iBAAiB;AACtB,SAAK,mBAAmB;AAAA,EAC1B;AACF;AAUO,IAAM,wBAAN,cAAoC,eAAe;AAAA,EAC/C;AAAA,EACA;AAAA,EAET,YAAY,SAAiB,SAAiB,SAAgD;AAC5F,UAAM,UAAU,SAAS,OAAO;AAChC,SAAK,UAAU;AACf,SAAK,SAAS,SAAS;AAAA,EACzB;AACF;AAQO,IAAM,uBAAN,cAAmC,eAAe;AAAA,EACvD,YAAY,SAAiB,SAA+B;AAC1D,UAAM,cAAc,SAAS,OAAO;AAAA,EACtC;AACF;","names":["AgentEvalError"]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ValidationError
|
|
3
|
+
} from "./chunk-RZAOYKCO.js";
|
|
4
|
+
|
|
5
|
+
// src/loops/drivers/fanout-vote.ts
|
|
6
|
+
function createFanoutVoteDriver(options) {
|
|
7
|
+
if (!Number.isFinite(options.n) || options.n < 1) {
|
|
8
|
+
throw new ValidationError(`createFanoutVoteDriver: n must be >= 1, got ${options.n}`);
|
|
9
|
+
}
|
|
10
|
+
const selector = options.selector ?? defaultSelector;
|
|
11
|
+
return {
|
|
12
|
+
name: options.name ?? "fanout-vote",
|
|
13
|
+
async plan(task, history) {
|
|
14
|
+
if (history.length === 0) return Array.from({ length: options.n }, () => task);
|
|
15
|
+
return [];
|
|
16
|
+
},
|
|
17
|
+
decide(history) {
|
|
18
|
+
const scored = scoreIterations(history);
|
|
19
|
+
return selector(scored) ? "pick-winner" : "fail";
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function defaultSelector(scored) {
|
|
24
|
+
const valid = scored.filter((entry) => entry.verdict?.valid === true);
|
|
25
|
+
if (valid.length === 0) return void 0;
|
|
26
|
+
return [...valid].sort(
|
|
27
|
+
(a, b) => (b.verdict?.score ?? 0) - (a.verdict?.score ?? 0) || a.iterationIndex - b.iterationIndex
|
|
28
|
+
)[0];
|
|
29
|
+
}
|
|
30
|
+
function scoreIterations(iterations) {
|
|
31
|
+
const out = [];
|
|
32
|
+
for (const iter of iterations) {
|
|
33
|
+
if (iter.output === void 0 || iter.error) continue;
|
|
34
|
+
out.push({
|
|
35
|
+
task: iter.task,
|
|
36
|
+
output: iter.output,
|
|
37
|
+
verdict: iter.verdict,
|
|
38
|
+
iterationIndex: iter.index,
|
|
39
|
+
agentRunName: iter.agentRunName
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
function scoreFanoutVoteIterations(iterations) {
|
|
45
|
+
return scoreIterations(iterations);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export {
|
|
49
|
+
createFanoutVoteDriver,
|
|
50
|
+
scoreFanoutVoteIterations
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=chunk-XLWPTPRP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/loops/drivers/fanout-vote.ts"],"sourcesContent":["/**\n * @experimental\n *\n * FanoutVote driver — N parallel attempts in iteration 0, pick the highest-\n * scoring valid output. No second iteration: the topology is \"spawn N, score,\n * pick winner\". The kernel handles heterogeneous fanout via the\n * `agentRuns: AgentRunSpec[]` form on `runLoop`.\n */\n\nimport { ValidationError } from '../../errors'\nimport type { DefaultVerdict, Driver, Iteration } from '../types'\n\nexport type FanoutVoteDecision = 'pick-winner' | 'fail'\n\n/** @experimental */\nexport interface FanoutVoteScored<Task, Output> {\n task: Task\n output: Output\n verdict?: DefaultVerdict\n iterationIndex: number\n agentRunName: string\n}\n\n/** @experimental */\nexport interface CreateFanoutVoteDriverOptions<Task, Output> {\n /** Number of parallel attempts. Must be >= 1. */\n n: number\n /**\n * Pick the winner from the scored set. Default: highest `verdict.score`\n * among valid outputs (ties broken by smallest iteration index). When\n * no valid outputs exist, returns `undefined` and `decide()` resolves\n * to `'fail'`. The kernel still records winners structurally — this\n * selector only feeds `decide()`'s pass/fail signal.\n */\n selector?: (\n scored: FanoutVoteScored<Task, Output>[],\n ) => FanoutVoteScored<Task, Output> | undefined\n /** Stable identifier surfaced in trace events. Default `'fanout-vote'`. */\n name?: string\n}\n\n/** @experimental */\nexport function createFanoutVoteDriver<Task, Output>(\n options: CreateFanoutVoteDriverOptions<Task, Output>,\n): Driver<Task, Output, FanoutVoteDecision> {\n if (!Number.isFinite(options.n) || options.n < 1) {\n throw new ValidationError(`createFanoutVoteDriver: n must be >= 1, got ${options.n}`)\n }\n const selector = options.selector ?? defaultSelector\n return {\n name: options.name ?? 'fanout-vote',\n async plan(task, history) {\n if (history.length === 0) return Array.from({ length: options.n }, () => task)\n return []\n },\n decide(history) {\n const scored = scoreIterations(history)\n return selector(scored) ? 'pick-winner' : 'fail'\n },\n }\n}\n\nfunction defaultSelector<Task, Output>(\n scored: FanoutVoteScored<Task, Output>[],\n): FanoutVoteScored<Task, Output> | undefined {\n const valid = scored.filter((entry) => entry.verdict?.valid === true)\n if (valid.length === 0) return undefined\n return [...valid].sort(\n (a, b) =>\n (b.verdict?.score ?? 0) - (a.verdict?.score ?? 0) || a.iterationIndex - b.iterationIndex,\n )[0]\n}\n\nfunction scoreIterations<Task, Output>(\n iterations: ReadonlyArray<Iteration<Task, Output>>,\n): FanoutVoteScored<Task, Output>[] {\n const out: FanoutVoteScored<Task, Output>[] = []\n for (const iter of iterations) {\n if (iter.output === undefined || iter.error) continue\n out.push({\n task: iter.task,\n output: iter.output,\n verdict: iter.verdict,\n iterationIndex: iter.index,\n agentRunName: iter.agentRunName,\n })\n }\n return out\n}\n\n/**\n * Test helper: surface the per-iteration scored view a custom `selector`\n * would receive. Exposed so consumers writing a custom selector can test it\n * standalone without driving the full kernel.\n *\n * @experimental\n */\nexport function scoreFanoutVoteIterations<Task, Output>(\n iterations: ReadonlyArray<Iteration<Task, Output>>,\n): FanoutVoteScored<Task, Output>[] {\n return scoreIterations(iterations)\n}\n"],"mappings":";;;;;AA0CO,SAAS,uBACd,SAC0C;AAC1C,MAAI,CAAC,OAAO,SAAS,QAAQ,CAAC,KAAK,QAAQ,IAAI,GAAG;AAChD,UAAM,IAAI,gBAAgB,+CAA+C,QAAQ,CAAC,EAAE;AAAA,EACtF;AACA,QAAM,WAAW,QAAQ,YAAY;AACrC,SAAO;AAAA,IACL,MAAM,QAAQ,QAAQ;AAAA,IACtB,MAAM,KAAK,MAAM,SAAS;AACxB,UAAI,QAAQ,WAAW,EAAG,QAAO,MAAM,KAAK,EAAE,QAAQ,QAAQ,EAAE,GAAG,MAAM,IAAI;AAC7E,aAAO,CAAC;AAAA,IACV;AAAA,IACA,OAAO,SAAS;AACd,YAAM,SAAS,gBAAgB,OAAO;AACtC,aAAO,SAAS,MAAM,IAAI,gBAAgB;AAAA,IAC5C;AAAA,EACF;AACF;AAEA,SAAS,gBACP,QAC4C;AAC5C,QAAM,QAAQ,OAAO,OAAO,CAAC,UAAU,MAAM,SAAS,UAAU,IAAI;AACpE,MAAI,MAAM,WAAW,EAAG,QAAO;AAC/B,SAAO,CAAC,GAAG,KAAK,EAAE;AAAA,IAChB,CAAC,GAAG,OACD,EAAE,SAAS,SAAS,MAAM,EAAE,SAAS,SAAS,MAAM,EAAE,iBAAiB,EAAE;AAAA,EAC9E,EAAE,CAAC;AACL;AAEA,SAAS,gBACP,YACkC;AAClC,QAAM,MAAwC,CAAC;AAC/C,aAAW,QAAQ,YAAY;AAC7B,QAAI,KAAK,WAAW,UAAa,KAAK,MAAO;AAC7C,QAAI,KAAK;AAAA,MACP,MAAM,KAAK;AAAA,MACX,QAAQ,KAAK;AAAA,MACb,SAAS,KAAK;AAAA,MACd,gBAAgB,KAAK;AAAA,MACrB,cAAc,KAAK;AAAA,IACrB,CAAC;AAAA,EACH;AACA,SAAO;AACT;AASO,SAAS,0BACd,YACkC;AAClC,SAAO,gBAAgB,UAAU;AACnC;","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { AgentEvalError, KnowledgeReadinessReport, ControlEvalResult, KnowledgeRequirement } from '@tangle-network/agent-eval';
|
|
2
2
|
export { AgentEvalError, AgentEvalErrorCode, ConfigError, ControlBudget, ControlDecision, ControlEvalResult, ControlRunResult, ControlStep, DataAcquisitionPlan, JudgeError, KnowledgeReadinessReport, KnowledgeRequirement, NotFoundError, RunRecord, ValidationError } from '@tangle-network/agent-eval';
|
|
3
|
-
import { A as AgentBackendInput, a as AgentExecutionBackend, b as AgentBackendContext, R as RuntimeStreamEvent, K as KnowledgeReadinessDecision, c as RunAgentTaskOptions, d as AgentTaskRunResult, e as RunAgentTaskStreamOptions, f as
|
|
4
|
-
export {
|
|
3
|
+
import { A as AgentBackendInput, a as AgentExecutionBackend, b as AgentBackendContext, R as RuntimeStreamEvent, K as KnowledgeReadinessDecision, c as RunAgentTaskOptions, d as AgentTaskRunResult, e as RunAgentTaskStreamOptions, f as AgentRuntimeEvent, g as AgentTaskStatus, h as RuntimeSessionStore, i as RuntimeSession } from './types-DlyPgeI0.js';
|
|
4
|
+
export { j as AgentAdapter, k as AgentKnowledgeProvider, l as AgentRuntimeEventSink, m as AgentTaskContext, n as AgentTaskSpec } from './types-DlyPgeI0.js';
|
|
5
|
+
export { R as RuntimeRunHandle, a as RuntimeRunPersistenceAdapter, b as RuntimeRunRow, s as startRuntimeRun } from './runtime-run-4pbY3Jq5.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* @stable
|
|
@@ -355,140 +356,6 @@ declare function runAgentTask<TState, TAction, TActionResult, TEval extends Cont
|
|
|
355
356
|
/** @stable */
|
|
356
357
|
declare function runAgentTaskStream<TInput extends AgentBackendInput = AgentBackendInput>(options: RunAgentTaskStreamOptions<TInput>): AsyncIterable<RuntimeStreamEvent>;
|
|
357
358
|
|
|
358
|
-
/**
|
|
359
|
-
* @stable
|
|
360
|
-
*
|
|
361
|
-
* Production-run lifecycle: record what the agent did on behalf of a customer,
|
|
362
|
-
* what it cost, and how it ended.
|
|
363
|
-
*
|
|
364
|
-
* Three concerns live in this module:
|
|
365
|
-
*
|
|
366
|
-
* 1. **Lifecycle state machine** — `running` -> `completed | failed | cancelled`,
|
|
367
|
-
* enforced by `RuntimeRunStateError`. Completion is idempotent for the same
|
|
368
|
-
* status (a second `complete()` call is a no-op so retries / cleanup paths
|
|
369
|
-
* don't double-fire side effects). A different terminal status is a state
|
|
370
|
-
* error.
|
|
371
|
-
*
|
|
372
|
-
* 2. **Cost ledger** — every `llm_call` event the handle observes contributes
|
|
373
|
-
* `tokensIn`, `tokensOut`, `costUsd`, and bumps `llmCalls`. Wall time is
|
|
374
|
-
* measured from `startRuntimeRun()` to `complete()`. Surface via
|
|
375
|
-
* `handle.cost()` for cost-per-task dashboards.
|
|
376
|
-
*
|
|
377
|
-
* 3. **Persistence adapter** — `RuntimeRunPersistenceAdapter` is the seam
|
|
378
|
-
* consumers plug in to write a `RuntimeRunRow` to their D1 / postgres /
|
|
379
|
-
* KV store. The adapter receives a sanitized row shape; no telemetry
|
|
380
|
-
* payload bytes flow through it unless the consumer opts in via
|
|
381
|
-
* `RuntimeRunOptions.telemetryEvents`.
|
|
382
|
-
*/
|
|
383
|
-
|
|
384
|
-
/** @stable */
|
|
385
|
-
type RuntimeRunStatus = 'running' | 'completed' | 'failed' | 'cancelled';
|
|
386
|
-
/** @stable */
|
|
387
|
-
interface RuntimeRunCost {
|
|
388
|
-
/** Cumulative input tokens across every observed `llm_call` event. */
|
|
389
|
-
tokensIn: number;
|
|
390
|
-
/** Cumulative output tokens across every observed `llm_call` event. */
|
|
391
|
-
tokensOut: number;
|
|
392
|
-
/** Sum of `costUsd` from every observed `llm_call` event. */
|
|
393
|
-
costUsd: number;
|
|
394
|
-
/** Wall time from `startRuntimeRun()` to `complete()` (or `now()` if not yet completed). */
|
|
395
|
-
wallMs: number;
|
|
396
|
-
/** Count of `llm_call` events observed during the run. */
|
|
397
|
-
llmCalls: number;
|
|
398
|
-
}
|
|
399
|
-
/** @stable */
|
|
400
|
-
interface RuntimeRunCompleteInput {
|
|
401
|
-
status: Exclude<RuntimeRunStatus, 'running'>;
|
|
402
|
-
resultSummary?: string;
|
|
403
|
-
/** Optional explicit cost override; if omitted, the accumulated ledger is used. */
|
|
404
|
-
cost?: Partial<RuntimeRunCost>;
|
|
405
|
-
/** Stable error message when `status === 'failed'`. */
|
|
406
|
-
error?: string;
|
|
407
|
-
/** Additional adapter-specific fields merged into the persisted row. */
|
|
408
|
-
metadata?: Record<string, unknown>;
|
|
409
|
-
}
|
|
410
|
-
/** @stable */
|
|
411
|
-
interface RuntimeRunRow {
|
|
412
|
-
/** Stable runtime-side identifier. Adapters may translate to their own primary key. */
|
|
413
|
-
id: string;
|
|
414
|
-
workspaceId: string;
|
|
415
|
-
sessionId?: string;
|
|
416
|
-
agentId?: string;
|
|
417
|
-
domain?: string;
|
|
418
|
-
taskId: string;
|
|
419
|
-
scenarioId?: string;
|
|
420
|
-
status: RuntimeRunStatus;
|
|
421
|
-
resultSummary?: string;
|
|
422
|
-
error?: string;
|
|
423
|
-
cost: RuntimeRunCost;
|
|
424
|
-
startedAt: string;
|
|
425
|
-
completedAt?: string;
|
|
426
|
-
metadata?: Record<string, unknown>;
|
|
427
|
-
}
|
|
428
|
-
/** @stable */
|
|
429
|
-
interface RuntimeRunPersistenceAdapter {
|
|
430
|
-
/**
|
|
431
|
-
* Called once when `handle.persist()` runs. Implementations write `row` to
|
|
432
|
-
* their durable store (D1, postgres, KV) and return whatever the consumer
|
|
433
|
-
* wants the caller to see (often the storage-side row id). Errors thrown
|
|
434
|
-
* here propagate out of `persist()` so the caller can decide whether to
|
|
435
|
-
* retry or log-and-continue.
|
|
436
|
-
*/
|
|
437
|
-
upsert(row: RuntimeRunRow): Promise<void> | void;
|
|
438
|
-
}
|
|
439
|
-
/** @stable */
|
|
440
|
-
interface RuntimeRunOptions {
|
|
441
|
-
workspaceId: string;
|
|
442
|
-
sessionId?: string;
|
|
443
|
-
agentId?: string;
|
|
444
|
-
taskSpec: AgentTaskSpec;
|
|
445
|
-
scenarioId?: string;
|
|
446
|
-
/** Optional persistence adapter; if omitted, `persist()` is a no-op. */
|
|
447
|
-
adapter?: RuntimeRunPersistenceAdapter;
|
|
448
|
-
/** Override the row id; default = `${taskSpec.id}:${random suffix}`. */
|
|
449
|
-
id?: string;
|
|
450
|
-
/** Override the clock; default = `Date.now()`. Useful for deterministic tests. */
|
|
451
|
-
now?: () => number;
|
|
452
|
-
}
|
|
453
|
-
/** @stable */
|
|
454
|
-
interface RuntimeRunHandle {
|
|
455
|
-
/** Stable id assigned at start. */
|
|
456
|
-
readonly id: string;
|
|
457
|
-
readonly workspaceId: string;
|
|
458
|
-
readonly sessionId: string | undefined;
|
|
459
|
-
readonly taskSpec: AgentTaskSpec;
|
|
460
|
-
readonly status: RuntimeRunStatus;
|
|
461
|
-
/**
|
|
462
|
-
* Observe a single `RuntimeStreamEvent`. The handle ignores non-cost events
|
|
463
|
-
* (text deltas, tool calls) silently so consumers can pipe the whole stream
|
|
464
|
-
* through `handle.observe`. `llm_call` events update the ledger.
|
|
465
|
-
*/
|
|
466
|
-
observe(event: RuntimeStreamEvent): void;
|
|
467
|
-
/** Snapshot of the current cost ledger. Safe to call at any time. */
|
|
468
|
-
cost(): RuntimeRunCost;
|
|
469
|
-
/**
|
|
470
|
-
* Transition to a terminal state. Idempotent for the same status; throws
|
|
471
|
-
* `RuntimeRunStateError` for a different terminal status (state machines
|
|
472
|
-
* don't time-travel).
|
|
473
|
-
*/
|
|
474
|
-
complete(input: RuntimeRunCompleteInput): void;
|
|
475
|
-
/** Build the current row without writing it. Useful for tests + dry runs. */
|
|
476
|
-
toRow(metadata?: Record<string, unknown>): RuntimeRunRow;
|
|
477
|
-
/**
|
|
478
|
-
* Persist the current row via the configured adapter. Must be called after
|
|
479
|
-
* `complete()`. Idempotent for the same terminal state (the adapter sees
|
|
480
|
-
* the same row on retry).
|
|
481
|
-
*/
|
|
482
|
-
persist(metadata?: Record<string, unknown>): Promise<void>;
|
|
483
|
-
}
|
|
484
|
-
/**
|
|
485
|
-
* @stable
|
|
486
|
-
*
|
|
487
|
-
* Construct a runtime-run handle. The returned handle is mutable across its
|
|
488
|
-
* lifetime; consumers should not share it across requests.
|
|
489
|
-
*/
|
|
490
|
-
declare function startRuntimeRun(options: RuntimeRunOptions): RuntimeRunHandle;
|
|
491
|
-
|
|
492
359
|
/**
|
|
493
360
|
* @stable
|
|
494
361
|
*
|
|
@@ -637,4 +504,4 @@ declare function readinessServerSentEvent(report: KnowledgeReadinessReport, opti
|
|
|
637
504
|
/** @stable */
|
|
638
505
|
declare function runtimeStreamServerSentEvent(event: RuntimeStreamEvent, options?: RuntimeTelemetryOptions & ServerSentEventOptions): string;
|
|
639
506
|
|
|
640
|
-
export { AgentBackendContext, AgentBackendInput, AgentExecutionBackend, AgentRuntimeEvent, AgentTaskRunResult,
|
|
507
|
+
export { AgentBackendContext, AgentBackendInput, AgentExecutionBackend, AgentRuntimeEvent, AgentTaskRunResult, AgentTaskStatus, type ChatStreamEvent, type ChatTurnHooks, type ChatTurnIdentity, type ChatTurnProducer, type ChatTurnResult, DEFAULT_ROUTER_BASE_URL, InMemoryRuntimeSessionStore, type ModelInfo, type ResolvedChatModel, type RouterEnv, type RunChatTurnInput, type RuntimeEventCollector, RuntimeRunStateError, RuntimeSessionStore, RuntimeStreamEvent, type RuntimeStreamEventCollector, type RuntimeTelemetryOptions, type SanitizedKnowledgeReadinessReport, cleanModelId, createIterableBackend, createOpenAICompatibleBackend, createRuntimeEventCollector, createRuntimeStreamEventCollector, createSandboxPromptBackend, decideKnowledgeReadiness, deriveExecutionId, getModels, handleChatTurn, readinessServerSentEvent, resolveChatModel, resolveRouterBaseUrl, runAgentTask, runAgentTaskStream, runtimeStreamServerSentEvent, sanitizeAgentRuntimeEvent, sanitizeKnowledgeReadinessReport, sanitizeRuntimeStreamEvent, validateChatModelId };
|
package/dist/index.js
CHANGED
|
@@ -1,44 +1,14 @@
|
|
|
1
|
-
import "./chunk-DGUM43GV.js";
|
|
2
|
-
|
|
3
|
-
// src/errors.ts
|
|
4
|
-
import { AgentEvalError } from "@tangle-network/agent-eval";
|
|
5
1
|
import {
|
|
6
|
-
AgentEvalError
|
|
7
|
-
|
|
2
|
+
AgentEvalError,
|
|
3
|
+
BackendTransportError,
|
|
8
4
|
ConfigError,
|
|
9
5
|
JudgeError,
|
|
10
6
|
NotFoundError,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
} from "
|
|
15
|
-
|
|
16
|
-
sessionBackend;
|
|
17
|
-
requestedBackend;
|
|
18
|
-
constructor(sessionBackend, requestedBackend, options) {
|
|
19
|
-
super(
|
|
20
|
-
"validation",
|
|
21
|
-
`Cannot resume ${sessionBackend} session with ${requestedBackend} backend`,
|
|
22
|
-
options
|
|
23
|
-
);
|
|
24
|
-
this.sessionBackend = sessionBackend;
|
|
25
|
-
this.requestedBackend = requestedBackend;
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
var BackendTransportError = class extends AgentEvalError {
|
|
29
|
-
backend;
|
|
30
|
-
status;
|
|
31
|
-
constructor(backend, message, options) {
|
|
32
|
-
super("config", message, options);
|
|
33
|
-
this.backend = backend;
|
|
34
|
-
this.status = options?.status;
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
var RuntimeRunStateError = class extends AgentEvalError {
|
|
38
|
-
constructor(message, options) {
|
|
39
|
-
super("validation", message, options);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
7
|
+
RuntimeRunStateError,
|
|
8
|
+
SessionMismatchError,
|
|
9
|
+
ValidationError
|
|
10
|
+
} from "./chunk-RZAOYKCO.js";
|
|
11
|
+
import "./chunk-DGUM43GV.js";
|
|
42
12
|
|
|
43
13
|
// src/sessions.ts
|
|
44
14
|
function newRuntimeSession(backend, requestedId, metadata) {
|
|
@@ -1540,7 +1510,7 @@ function stripNewlines(value) {
|
|
|
1540
1510
|
return value.replace(/[\r\n]/g, " ");
|
|
1541
1511
|
}
|
|
1542
1512
|
export {
|
|
1543
|
-
|
|
1513
|
+
AgentEvalError,
|
|
1544
1514
|
ConfigError,
|
|
1545
1515
|
DEFAULT_ROUTER_BASE_URL,
|
|
1546
1516
|
InMemoryRuntimeSessionStore,
|