@arnilo/prism-hosts 0.13.1 → 0.14.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/CHANGELOG.md +6 -0
- package/a2a/README.md +195 -0
- package/a2a/src/card.ts +208 -0
- package/a2a/src/codec.ts +523 -0
- package/a2a/src/connect.ts +415 -0
- package/a2a/src/errors.ts +87 -0
- package/a2a/src/index.ts +40 -0
- package/a2a/src/limits.ts +43 -0
- package/a2a/src/pending.ts +28 -0
- package/a2a/src/proxy.ts +526 -0
- package/a2a/src/serve.ts +886 -0
- package/acp/README.md +3 -1
- package/acp/src/limits.ts +3 -16
- package/acp/src/mapper.ts +26 -5
- package/acp/src/serve.ts +6 -5
- package/ag-ui/README.md +2 -1
- package/ag-ui/src/a2ui.ts +8 -31
- package/ag-ui/src/ag-ui-mapper.ts +27 -1
- package/ag-ui/src/encrypted-value.ts +3 -3
- package/ag-ui/src/handler.ts +4 -4
- package/ag-ui/src/index.ts +0 -33
- package/ag-ui/src/limits.ts +5 -88
- package/ag-ui/src/projectors.ts +8 -6
- package/ag-ui/src/renderer/bind.ts +2 -1
- package/channels/README.md +61 -5
- package/channels/src/discord-gateway.ts +354 -0
- package/channels/src/discord.ts +873 -0
- package/channels/src/index.ts +4 -2
- package/channels/src/limits.ts +3 -19
- package/channels/src/pairing.ts +1 -2
- package/channels/src/runtime-turn.ts +10 -2
- package/channels/src/signal.ts +11 -19
- package/channels/src/slack.ts +854 -0
- package/channels/src/telegram.ts +22 -44
- package/channels/src/types.ts +5 -2
- package/devtools/README.md +1 -1
- package/driver-process/src/driver.ts +3 -1
- package/driver-process/src/testing.ts +1 -1
- package/driver-process/src/turn.ts +5 -1
- package/evals/README.md +11 -7
- package/evals/src/calibration.ts +5 -13
- package/evals/src/compare-experiments.ts +1 -2
- package/evals/src/comparison.ts +7 -25
- package/evals/src/curate.ts +3 -9
- package/evals/src/dataset.ts +0 -2
- package/evals/src/index.ts +3 -20
- package/evals/src/injection.ts +33 -6
- package/evals/src/judge.ts +9 -13
- package/evals/src/limits.ts +0 -17
- package/evals/src/rubric-judge.ts +5 -10
- package/evals/src/scenario-runner.ts +8 -4
- package/evals/src/scenarios.ts +5 -5
- package/evals/src/score.ts +3 -5
- package/evals/src/stats.ts +0 -2
- package/evals/src/threshold.ts +3 -3
- package/evals/src/toolless-session.ts +7 -3
- package/evals/src/trace.ts +8 -14
- package/evals/src/trajectory.ts +45 -11
- package/evals/src/types.ts +2 -2
- package/evals/src/user-simulator.ts +1 -7
- package/evals/src/util.ts +3 -9
- package/headless/README.md +20 -1
- package/headless/src/authority.ts +14 -1
- package/headless/src/errors.ts +3 -1
- package/headless/src/index.ts +10 -1
- package/headless/src/limits.ts +2 -2
- package/headless/src/pending.ts +4 -3
- package/headless/src/recover.ts +126 -0
- package/headless/src/resume.ts +1 -1
- package/host-builder/data/api.json +1276 -1365
- package/host-builder/data/errors.json +199 -185
- package/host-builder/data/examples/a2a-client.ts +125 -0
- package/host-builder/data/examples/a2a-server.ts +133 -0
- package/host-builder/data/examples/autonomous-coding-loop.ts +1 -1
- package/host-builder/data/examples/build-workflow.ts +2 -2
- package/host-builder/data/examples/caveman-ponytail.ts +1 -1
- package/host-builder/data/examples/channel-discord.ts +176 -0
- package/host-builder/data/examples/channel-slack.ts +146 -0
- package/host-builder/data/examples/continue-after-failure.ts +80 -0
- package/host-builder/data/examples/custom-adapter.ts +1 -1
- package/host-builder/data/examples/decision-models.ts +1 -1
- package/host-builder/data/examples/define-package.ts +1 -1
- package/host-builder/data/examples/delegate.ts +74 -9
- package/host-builder/data/examples/durable-loops-and-approvals.ts +11 -10
- package/host-builder/data/examples/governance-deny.ts +1 -1
- package/host-builder/data/examples/guardrail-content.ts +126 -0
- package/host-builder/data/examples/headless-host.ts +1 -1
- package/host-builder/data/examples/long-running-job.ts +129 -0
- package/host-builder/data/examples/long-term-memory.ts +1 -1
- package/host-builder/data/examples/mcp-oauth.ts +197 -0
- package/host-builder/data/examples/mcp-trust.ts +1 -1
- package/host-builder/data/examples/memory-and-wiki.ts +2 -2
- package/host-builder/data/examples/memory-system.ts +19 -9
- package/host-builder/data/examples/model-router-aggregate-budgets.ts +1 -1
- package/host-builder/data/examples/parallel-tools.ts +70 -0
- package/host-builder/data/examples/remote-agent.ts +1 -1
- package/host-builder/data/examples/serve-tools.ts +1 -1
- package/host-builder/data/examples/session-memory.ts +18 -16
- package/host-builder/data/examples/side-call.ts +1 -1
- package/host-builder/data/examples/sqlite-resume.ts +1 -1
- package/host-builder/data/examples/structured-output.ts +57 -0
- package/host-builder/data/examples.json +14 -4
- package/host-builder/skills/prism-host-builder/SKILL.md +1 -1
- package/host-builder/skills/prism-host-builder/references/choosing.md +14 -10
- package/host-builder/skills/prism-host-builder/references/pitfalls.md +5 -3
- package/host-builder/skills/prism-host-builder/references/recipes.md +5 -5
- package/host-builder/skills/prism-host-builder/references/verification.md +1 -1
- package/host-builder/src/check/runner.ts +2 -3
- package/host-builder/src/server.ts +2 -2
- package/mcp-server/README.md +3 -3
- package/mcp-server/src/bounds.ts +3 -3
- package/mcp-server/src/serve-tools.ts +2 -9
- package/mcp-server/src/serve.ts +2 -4
- package/mcp-server/src/server.ts +10 -20
- package/package.json +12 -6
- package/remote/README.md +7 -4
- package/remote/src/channel.ts +6 -2
- package/remote/src/connect.ts +9 -3
- package/remote/src/errors.ts +3 -1
- package/remote/src/limits.ts +3 -13
- package/remote/src/mirror.ts +2 -1
- package/remote/src/pending.ts +4 -3
- package/remote/src/protocol.ts +3 -0
- package/remote/src/serve.ts +43 -5
- package/remote/src/session-proxy.ts +28 -5
- package/remote/src/testing.ts +3 -1
- package/remote/src/wire.ts +74 -14
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Agent,
|
|
3
|
+
isSessionNotFound,
|
|
4
|
+
type OwnershipScope,
|
|
5
|
+
type ProductionPersistenceStore,
|
|
6
|
+
type RunRecord,
|
|
7
|
+
type RunResult,
|
|
8
|
+
SESSION_NOTHING_TO_CONTINUE_CODE,
|
|
9
|
+
} from "@arnilo/prism";
|
|
10
|
+
import { HeadlessError } from "./errors.js";
|
|
11
|
+
|
|
12
|
+
const DEFAULT_PAGE_SIZE = 100;
|
|
13
|
+
const DEFAULT_RECOVERY_CONCURRENCY = 2;
|
|
14
|
+
|
|
15
|
+
/** The listing capability the sweep needs. `RunLedger` is write-only. */
|
|
16
|
+
export type RunListing = Pick<ProductionPersistenceStore, "queryRuns">;
|
|
17
|
+
|
|
18
|
+
export interface FindInterruptedRunsOptions {
|
|
19
|
+
/** Applied to the ledger query, and again to every returned record. */
|
|
20
|
+
readonly ownership: OwnershipScope;
|
|
21
|
+
/** Keep only runs started at least this long ago, so a run another process is still driving is left alone. Default 60 000. */
|
|
22
|
+
readonly olderThanMs?: number;
|
|
23
|
+
/** Rows per ledger page. Default 100. */
|
|
24
|
+
readonly pageSize?: number;
|
|
25
|
+
/** Clock for the age check. Default `Date.now`. */
|
|
26
|
+
readonly now?: () => number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface InterruptedRun {
|
|
30
|
+
readonly sessionId: string;
|
|
31
|
+
readonly runId: string;
|
|
32
|
+
readonly startedAt: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface ContinueInterruptedOptions {
|
|
36
|
+
/** Continuations at once. Default 2. */
|
|
37
|
+
readonly concurrency?: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type ContinueInterruptedOutcome =
|
|
41
|
+
| (InterruptedRun & { readonly status: "continued"; readonly result: RunResult })
|
|
42
|
+
| (InterruptedRun & { readonly status: "skipped"; readonly reason: "nothing_to_continue" | "session_not_found" })
|
|
43
|
+
| (InterruptedRun & { readonly status: "failed"; readonly error: unknown });
|
|
44
|
+
|
|
45
|
+
const OWNERSHIP_KEYS = ["tenantId", "accountId", "userId"] as const;
|
|
46
|
+
|
|
47
|
+
function scopeOf(ownership: OwnershipScope): OwnershipScope {
|
|
48
|
+
const scope: Record<string, string> = {};
|
|
49
|
+
for (const key of OWNERSHIP_KEYS) {
|
|
50
|
+
const value = ownership[key];
|
|
51
|
+
if (value !== undefined) scope[key] = value;
|
|
52
|
+
}
|
|
53
|
+
return scope;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function inScope(record: RunRecord, scope: OwnershipScope): boolean {
|
|
57
|
+
return OWNERSHIP_KEYS.every((key) => record[key] === scope[key]);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Runs the ledger still records as `running` and that started at least `olderThanMs` ago: the
|
|
62
|
+
* process driving them died. One entry per session (its newest run). A run that failed, was aborted,
|
|
63
|
+
* or suspended has a terminal ledger record and is never returned.
|
|
64
|
+
*/
|
|
65
|
+
export async function findInterruptedRuns(runs: RunListing, options: FindInterruptedRunsOptions): Promise<InterruptedRun[]> {
|
|
66
|
+
if (typeof runs?.queryRuns !== "function") throw new HeadlessError("ledger_query_unsupported");
|
|
67
|
+
if (options?.ownership === undefined || options.ownership === null || typeof options.ownership !== "object") {
|
|
68
|
+
throw new HeadlessError("invalid_ownership");
|
|
69
|
+
}
|
|
70
|
+
const olderThanMs = options.olderThanMs ?? 60_000;
|
|
71
|
+
const pageSize = options.pageSize ?? DEFAULT_PAGE_SIZE;
|
|
72
|
+
if (!Number.isFinite(olderThanMs) || olderThanMs < 0) throw new HeadlessError("invalid_limit");
|
|
73
|
+
if (!Number.isInteger(pageSize) || pageSize < 1) throw new HeadlessError("invalid_limit");
|
|
74
|
+
const scope = scopeOf(options.ownership);
|
|
75
|
+
const cutoff = (options.now ?? Date.now)() - olderThanMs;
|
|
76
|
+
const newest = new Map<string, InterruptedRun>();
|
|
77
|
+
let cursor: string | undefined;
|
|
78
|
+
do {
|
|
79
|
+
const page = await runs.queryRuns({ status: "running", ...scope, limit: pageSize, ...(cursor === undefined ? {} : { cursor }) });
|
|
80
|
+
for (const record of page.items) {
|
|
81
|
+
// The store filters; this is the fail-closed second check. SQLite ignores `toStartedAt`, so age is checked here too.
|
|
82
|
+
if (record.status !== "running" || record.finishedAt !== undefined || !inScope(record, scope)) continue;
|
|
83
|
+
const started = Date.parse(record.startedAt);
|
|
84
|
+
if (!Number.isFinite(started) || started > cutoff) continue;
|
|
85
|
+
const current = newest.get(record.sessionId);
|
|
86
|
+
if (current === undefined || Date.parse(current.startedAt) < started) {
|
|
87
|
+
newest.set(record.sessionId, { sessionId: record.sessionId, runId: record.id, startedAt: record.startedAt });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
cursor = page.items.length === 0 ? undefined : page.nextCursor;
|
|
91
|
+
} while (cursor !== undefined);
|
|
92
|
+
return [...newest.values()].sort((a, b) => a.startedAt.localeCompare(b.startedAt));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Opens each session on `agent` and calls `session.continue()`. A session that no longer owes a
|
|
97
|
+
* model turn, or that this agent cannot see, is skipped. Any other error is collected, not thrown.
|
|
98
|
+
*/
|
|
99
|
+
export async function continueInterrupted(
|
|
100
|
+
agent: Pick<Agent, "session">,
|
|
101
|
+
runs: readonly InterruptedRun[],
|
|
102
|
+
options: ContinueInterruptedOptions = {},
|
|
103
|
+
): Promise<ContinueInterruptedOutcome[]> {
|
|
104
|
+
const concurrency = options.concurrency ?? DEFAULT_RECOVERY_CONCURRENCY;
|
|
105
|
+
if (!Number.isInteger(concurrency) || concurrency < 1) throw new HeadlessError("invalid_limit");
|
|
106
|
+
const outcomes: ContinueInterruptedOutcome[] = new Array(runs.length);
|
|
107
|
+
let next = 0;
|
|
108
|
+
const worker = async () => {
|
|
109
|
+
while (next < runs.length) {
|
|
110
|
+
const index = next;
|
|
111
|
+
next += 1;
|
|
112
|
+
const run = runs[index] as InterruptedRun;
|
|
113
|
+
try {
|
|
114
|
+
const session = await agent.session({ id: run.sessionId });
|
|
115
|
+
outcomes[index] = { ...run, status: "continued", result: await session.continue() };
|
|
116
|
+
} catch (error) {
|
|
117
|
+
if (isSessionNotFound(error)) outcomes[index] = { ...run, status: "skipped", reason: "session_not_found" };
|
|
118
|
+
else if ((error as { code?: unknown } | undefined)?.code === SESSION_NOTHING_TO_CONTINUE_CODE) {
|
|
119
|
+
outcomes[index] = { ...run, status: "skipped", reason: "nothing_to_continue" };
|
|
120
|
+
} else outcomes[index] = { ...run, status: "failed", error };
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
await Promise.all(Array.from({ length: Math.min(concurrency, runs.length) }, worker));
|
|
125
|
+
return outcomes;
|
|
126
|
+
}
|
package/headless/src/resume.ts
CHANGED
|
@@ -78,7 +78,7 @@ export async function resumeWhenAnswered(
|
|
|
78
78
|
const signal = options.signal;
|
|
79
79
|
if (signal?.aborted) return { status: "aborted" };
|
|
80
80
|
const session = await authority.session(supplied.id);
|
|
81
|
-
const current = pendingDecisionsOf(await session.entries());
|
|
81
|
+
const current = pendingDecisionsOf(await session.entries(), authority.runStateBounds);
|
|
82
82
|
if (!current.length) return { status: "already_resolved" };
|
|
83
83
|
// Caller-provided descriptors never supply prompts or schemas; they must match this suspension.
|
|
84
84
|
if (pending && (pending.length !== current.length || pending.some((item, i) => item.approvalId !== current[i]?.approvalId)))
|