@arnilo/prism 0.6.0 → 0.8.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/CHANGELOG.md +79 -5
- package/README.md +12 -11
- package/dist/agent-approval.d.ts +4 -0
- package/dist/agent-approval.js +5 -1
- package/dist/agent-definitions.js +1 -0
- package/dist/agent-run-lifecycle.js +39 -4
- package/dist/agent-run-state.d.ts +18 -0
- package/dist/agent-run-state.js +39 -9
- package/dist/agent-session/helpers.js +6 -1
- package/dist/agent-session/session/assemble.js +159 -7
- package/dist/agent-session/session/persist.d.ts +16 -0
- package/dist/agent-session/session/persist.js +64 -4
- package/dist/agent-session/session/provider-round.d.ts +3 -3
- package/dist/agent-session/session/provider-round.js +12 -6
- package/dist/agent-session/session/tool-round.js +5 -1
- package/dist/agent-session/session/types.d.ts +22 -1
- package/dist/agent-session/session.d.ts +16 -0
- package/dist/agent-session/session.js +42 -3
- package/dist/artifacts.d.ts +39 -1
- package/dist/artifacts.js +73 -0
- package/dist/attention-compiler.d.ts +121 -0
- package/dist/attention-compiler.js +479 -0
- package/dist/checkpoints.js +7 -11
- package/dist/cli-init.js +20 -6
- package/dist/context-budget.d.ts +20 -1
- package/dist/context-budget.js +10 -1
- package/dist/contracts-core/agent.d.ts +7 -0
- package/dist/contracts-core/attention.d.ts +66 -0
- package/dist/contracts-core/attention.js +2 -0
- package/dist/contracts-core/compaction.d.ts +59 -0
- package/dist/contracts-core/compaction.js +77 -1
- package/dist/contracts-core/content.d.ts +5 -0
- package/dist/contracts-core/loop.d.ts +42 -0
- package/dist/contracts-core/provider.d.ts +4 -0
- package/dist/contracts-core/run-limits.d.ts +2 -0
- package/dist/contracts-core.d.ts +1 -0
- package/dist/contracts-core.js +1 -0
- package/dist/contracts-protocol.d.ts +44 -3
- package/dist/contracts-run-state.d.ts +32 -5
- package/dist/evidence-grounding.d.ts +29 -0
- package/dist/evidence-grounding.js +162 -0
- package/dist/host-composition.d.ts +91 -0
- package/dist/host-composition.js +279 -0
- package/dist/index.d.ts +13 -6
- package/dist/index.js +7 -4
- package/dist/input.d.ts +13 -1
- package/dist/input.js +40 -1
- package/dist/provider-events.d.ts +3 -1
- package/dist/provider-events.js +2 -2
- package/dist/providers/transport.d.ts +3 -1
- package/dist/providers/transport.js +36 -0
- package/dist/redaction.js +18 -2
- package/dist/run-bundle.d.ts +89 -0
- package/dist/run-bundle.js +149 -0
- package/dist/secure-agent.d.ts +2 -0
- package/dist/secure-agent.js +6 -1
- package/dist/testing/state-concurrency-conformance.js +5 -12
- package/dist/tool-result-fold.d.ts +12 -0
- package/dist/tool-result-fold.js +13 -6
- package/dist/tools.d.ts +10 -0
- package/dist/tools.js +41 -0
- package/docs/acp-agent.md +42 -11
- package/docs/acp.md +2 -1
- package/docs/ag-ui.md +10 -3
- package/docs/agent-definitions.md +9 -1
- package/docs/agent-events.md +4 -1
- package/docs/agent-loops.md +33 -0
- package/docs/agent-session-runtime.md +8 -7
- package/docs/attention-compiler.md +272 -0
- package/docs/cli-rpc.md +4 -2
- package/docs/coding-agent-tools.md +1 -1
- package/docs/coding-security.md +6 -3
- package/docs/coding-tools.md +0 -1
- package/docs/coding-workspaces.md +22 -0
- package/docs/compaction-and-retry.md +36 -4
- package/docs/compaction-observational-memory.md +63 -10
- package/docs/connected-apps.md +116 -0
- package/docs/context-and-skills.md +17 -2
- package/docs/conversations.md +1 -1
- package/docs/core.md +1 -1
- package/docs/dev-inspector.md +4 -0
- package/docs/device-adapters.md +1 -0
- package/docs/diagrams.md +6 -6
- package/docs/document-reader.md +18 -10
- package/docs/documents.md +40 -11
- package/docs/durable-runs.md +87 -0
- package/docs/enterprise-postgres-state.md +6 -2
- package/docs/evaluations.md +168 -4
- package/docs/execution-timeline.md +186 -0
- package/docs/guardrails.md +33 -0
- package/docs/history/0.7.0-primitive-review.md +254 -0
- package/docs/history/079-messaging-primitive-review.md +391 -0
- package/docs/history/080-messaging-followon-primitive-review.md +234 -0
- package/docs/history/081-connected-apps-primitive-review.md +74 -0
- package/docs/history/083-prism-work-primitive-review.md +84 -0
- package/docs/history/084-primitive-review.md +96 -0
- package/docs/history/085-honesty-and-cut-primitive-review.md +91 -0
- package/docs/history/README.md +5 -0
- package/docs/history/migration-0.0.md +2 -2
- package/docs/history/release-handoffs.md +75 -1
- package/docs/host-compositions.md +149 -0
- package/docs/host-security.md +2 -2
- package/docs/hosted-sandboxes.md +94 -0
- package/docs/index.md +82 -45
- package/docs/input-and-prompt-assembly.md +1 -0
- package/docs/knowledge-sync.md +84 -0
- package/docs/language-intelligence.md +1 -1
- package/docs/live-testing.md +8 -3
- package/docs/mcp-tools.md +3 -1
- package/docs/memory-fabric.md +416 -0
- package/docs/messaging-channel-operations.md +166 -0
- package/docs/messaging-channels.md +150 -0
- package/docs/migrate-to-0.5.md +1 -1
- package/docs/migrate-to-0.6.md +1 -0
- package/docs/migrate-to-0.7.md +345 -0
- package/docs/migrate-to-0.8.md +124 -0
- package/docs/migration.md +43 -1
- package/docs/model-registry.md +12 -2
- package/docs/model-routing.md +79 -4
- package/docs/multi-agent-patterns.md +20 -6
- package/docs/observability.md +52 -1
- package/docs/openapi-tools.md +1 -1
- package/docs/operations.md +14 -4
- package/docs/options-index.md +47 -3
- package/docs/peer-dependencies.md +12 -10
- package/docs/postgres-persistence.md +1 -1
- package/docs/process-sessions.md +3 -1
- package/docs/prompt-registry.md +1 -1
- package/docs/provider-caching.md +4 -2
- package/docs/provider-conformance.md +1 -1
- package/docs/provider-layer.md +2 -2
- package/docs/provider-packages.md +22 -22
- package/docs/providers/bedrock.md +71 -7
- package/docs/providers/neuralwatt.md +5 -1
- package/docs/providers/openai.md +1 -1
- package/docs/rag.md +24 -8
- package/docs/realtime-voice.md +87 -0
- package/docs/release-and-install.md +53 -45
- package/docs/run-bundle.md +92 -0
- package/docs/runs-and-usage.md +17 -2
- package/docs/server.md +7 -3
- package/docs/sheets.md +9 -9
- package/docs/signal-channel.md +112 -0
- package/docs/speech.md +7 -1
- package/docs/sqlite-persistence.md +1 -1
- package/docs/supervisors.md +33 -5
- package/docs/telegram-channel.md +157 -0
- package/docs/testing.md +2 -2
- package/docs/thinking-and-reasoning.md +3 -1
- package/docs/tools.md +6 -5
- package/docs/web-tools.md +2 -1
- package/docs/wiki.md +1 -1
- package/docs/work-artifacts-and-review.md +14 -4
- package/docs/work-connectors.md +12 -10
- package/docs/work-sandbox.md +115 -0
- package/docs/work-tools.md +50 -18
- package/docs/workflows.md +69 -1
- package/docs/working-and-semantic-memory.md +25 -14
- package/package.json +5 -3
- package/templates/README.md +2 -0
- package/templates/business-worker/README.md.tmpl +19 -0
- package/templates/business-worker/env.example.tmpl +1 -0
- package/templates/business-worker/gitignore.tmpl +11 -0
- package/templates/business-worker/manifest.json +12 -0
- package/templates/business-worker/package.json.tmpl +23 -0
- package/templates/business-worker/src/agent.ts.tmpl +92 -0
- package/templates/business-worker/src/index.ts.tmpl +13 -0
- package/templates/business-worker/src/tests/agent.test.ts.tmpl +77 -0
- package/templates/business-worker/tsconfig.json.tmpl +15 -0
- package/templates/personal-assistant/README.md.tmpl +18 -0
- package/templates/personal-assistant/env.example.tmpl +1 -0
- package/templates/personal-assistant/gitignore.tmpl +11 -0
- package/templates/personal-assistant/manifest.json +11 -0
- package/templates/personal-assistant/package.json.tmpl +23 -0
- package/templates/personal-assistant/src/agent.ts.tmpl +65 -0
- package/templates/personal-assistant/src/index.ts.tmpl +13 -0
- package/templates/personal-assistant/src/tests/agent.test.ts.tmpl +28 -0
- package/templates/personal-assistant/tsconfig.json.tmpl +15 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** Attention Compiler contracts (plan 074 Tasks 2–5). Opt-in per-turn gate that measures the
|
|
2
|
+
* assembled input and mutates a history clone only after a host ratio of the model input
|
|
3
|
+
* cap. `resolveRunAttentionCompiler` turns the agent setting plus an optional run overlay
|
|
4
|
+
* into the frozen handle the session hands to assembly; nothing declared here runs on its
|
|
5
|
+
* own, and omitting the option keeps today's request bytes. */
|
|
6
|
+
import type { CompactionTrigger } from "./compaction.js";
|
|
7
|
+
import type { ModelConfig } from "./content.js";
|
|
8
|
+
/** Input-cap resolution inputs shared by the compiler and `input_ratio` compaction triggers. */
|
|
9
|
+
export interface AttentionInputCapOptions {
|
|
10
|
+
/** Host cap; when set it wins over `model.limits.contextWindow` (C2). */
|
|
11
|
+
readonly maxInputTokens?: number;
|
|
12
|
+
/** Output + next-turn headroom subtracted from the window (default 1024). */
|
|
13
|
+
readonly reserveTokens?: number;
|
|
14
|
+
}
|
|
15
|
+
export interface AttentionCompilerOptions extends AttentionInputCapOptions {
|
|
16
|
+
/** Fraction of `inputCap` that triggers mutation; in `(0, 1)` (default 0.75). */
|
|
17
|
+
readonly triggerRatio?: number;
|
|
18
|
+
/** Where compaction should fire relative to `triggerRatio`; must exceed it (default 0.9). */
|
|
19
|
+
readonly compactRatio?: number;
|
|
20
|
+
/** Newest thinking-bearing assistant turns kept intact (default 1). */
|
|
21
|
+
readonly thinkingKeepTurns?: number;
|
|
22
|
+
/** Newest tool results kept full (default 3). */
|
|
23
|
+
readonly keepLast?: number;
|
|
24
|
+
/** Tool names whose results are never stubbed, whatever the ratio. */
|
|
25
|
+
readonly excludeTools?: readonly string[];
|
|
26
|
+
}
|
|
27
|
+
/** Where the compiler is switched on: `true` uses the defaults, an object tunes them, `false`
|
|
28
|
+
* (or omitted) leaves requests byte-for-byte as they are without the compiler. On
|
|
29
|
+
* `RunOptions` the same shape is an overlay: `false` disables, `true` is a no-op, and an
|
|
30
|
+
* object may only *relax* the agent setting (see `resolveRunAttentionCompiler`). */
|
|
31
|
+
export type AttentionCompilerSetting = boolean | AttentionCompilerOptions;
|
|
32
|
+
export interface AttentionCompilerContext {
|
|
33
|
+
/** Model limits used to resolve the input cap; ignored when `maxInputTokens` is set. */
|
|
34
|
+
readonly model?: Pick<ModelConfig, "limits">;
|
|
35
|
+
/** Validated at create so an unknown trigger type fails at config time, not on turn one. */
|
|
36
|
+
readonly compactionTrigger?: CompactionTrigger;
|
|
37
|
+
}
|
|
38
|
+
/** Validated, frozen configuration returned by `createAttentionCompiler`. */
|
|
39
|
+
export interface AttentionCompiler {
|
|
40
|
+
readonly inputCap: number;
|
|
41
|
+
readonly reserveTokens: number;
|
|
42
|
+
readonly triggerRatio: number;
|
|
43
|
+
readonly compactRatio: number;
|
|
44
|
+
readonly thinkingKeepTurns: number;
|
|
45
|
+
readonly keepLast: number;
|
|
46
|
+
readonly excludeTools: readonly string[];
|
|
47
|
+
}
|
|
48
|
+
/** One mutated turn. Under-ratio turns emit nothing and produce no report (C14). */
|
|
49
|
+
export interface AttentionReport {
|
|
50
|
+
/** Estimated tokens measured before this turn's mutation — the value compared to the ratio. */
|
|
51
|
+
readonly used: number;
|
|
52
|
+
/** Estimated tokens of the same request after this turn's mutation: the cost curve is `used` → `usedAfter`. */
|
|
53
|
+
readonly usedAfter: number;
|
|
54
|
+
readonly inputCap: number;
|
|
55
|
+
readonly triggerRatio: number;
|
|
56
|
+
/** Thinking turns absent from this request; rows re-applied from the sticky frontier count again. */
|
|
57
|
+
readonly droppedThinkingTurns: number;
|
|
58
|
+
/** Tool results stubbed in this request; rows re-applied from the sticky frontier count again. */
|
|
59
|
+
readonly stubbedToolResults: number;
|
|
60
|
+
/** Payload bytes the stubs took out of this request (never the stub text itself). */
|
|
61
|
+
readonly stubbedBytes: number;
|
|
62
|
+
/** True when the gate stopped with eligible rows left: the sticky frontier is partial. */
|
|
63
|
+
readonly truncated: boolean;
|
|
64
|
+
readonly runId?: string;
|
|
65
|
+
readonly sessionId?: string;
|
|
66
|
+
}
|
|
@@ -21,15 +21,74 @@ export interface CompactionResult {
|
|
|
21
21
|
readonly entries?: readonly SessionEntry[];
|
|
22
22
|
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
23
23
|
}
|
|
24
|
+
/** Inputs a compaction trigger decides on. Estimates and ids only — never raw payloads. */
|
|
25
|
+
export interface CompactionTriggerContext {
|
|
26
|
+
readonly sessionId: string;
|
|
27
|
+
readonly entryCount: number;
|
|
28
|
+
readonly estimatedInputTokens: number;
|
|
29
|
+
readonly inputCapTokens: number;
|
|
30
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
31
|
+
readonly signal?: AbortSignal;
|
|
32
|
+
}
|
|
33
|
+
/** Host-programmable compact-when gate (plan 074 C11). Omitted → `thresholdEntries` only. */
|
|
34
|
+
export type CompactionTrigger = {
|
|
35
|
+
readonly type: "threshold_entries";
|
|
36
|
+
readonly entries: number;
|
|
37
|
+
} | {
|
|
38
|
+
readonly type: "input_ratio";
|
|
39
|
+
readonly ratio: number;
|
|
40
|
+
} | {
|
|
41
|
+
readonly type: "custom";
|
|
42
|
+
readonly shouldCompact: (context: CompactionTriggerContext) => boolean | Promise<boolean>;
|
|
43
|
+
};
|
|
44
|
+
/** Validate a host trigger at config time, so an unknown `type` fails at create (C11). */
|
|
45
|
+
export declare function assertCompactionTrigger(trigger: CompactionTrigger): CompactionTrigger;
|
|
24
46
|
export interface CompactionOptions {
|
|
25
47
|
readonly strategy?: CompactionStrategy;
|
|
26
48
|
readonly thresholdEntries?: number;
|
|
49
|
+
/** Replaces the `thresholdEntries` gate when set; omitted keeps today's entry-count gate. */
|
|
50
|
+
readonly trigger?: CompactionTrigger;
|
|
27
51
|
readonly keepRecentEntries?: number;
|
|
28
52
|
readonly maxSummaryChars?: number;
|
|
29
53
|
readonly secrets?: readonly (string | undefined)[];
|
|
30
54
|
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
31
55
|
readonly signal?: AbortSignal;
|
|
32
56
|
}
|
|
57
|
+
/** Legacy gates a compaction decision can fall back to when no `trigger` is configured. */
|
|
58
|
+
export interface ResolveShouldCompactOptions {
|
|
59
|
+
/** Host trigger; when set it replaces the legacy gates below. */
|
|
60
|
+
readonly trigger?: CompactionTrigger;
|
|
61
|
+
/** Session gate: compact when the branch holds more than this many entries. */
|
|
62
|
+
readonly thresholdEntries?: number;
|
|
63
|
+
/** Attach-loop gate: compact when the estimated input is at or above this many tokens. */
|
|
64
|
+
readonly compactAfterTokens?: number;
|
|
65
|
+
}
|
|
66
|
+
/** Everything a compaction decision reads. Estimates only — never raw payloads. */
|
|
67
|
+
export interface ResolveShouldCompactInput {
|
|
68
|
+
readonly sessionId: string;
|
|
69
|
+
readonly entryCount: number;
|
|
70
|
+
/** Estimated tokens of the would-be input; called at most once, and only when a ratio or custom trigger reads it. */
|
|
71
|
+
readonly estimateInputTokens: () => number;
|
|
72
|
+
/** Resolved input cap (the attention compiler's `resolveInputCap`); called at most once, and only when a ratio or custom trigger reads it. */
|
|
73
|
+
readonly resolveInputCapTokens: () => number;
|
|
74
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
75
|
+
readonly signal?: AbortSignal;
|
|
76
|
+
/** Receives the failure behind a fail-closed `false`. */
|
|
77
|
+
readonly onError?: (error: unknown) => void;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The single compact-when decision used by `autoCompact` and by host attach loops that gate their
|
|
81
|
+
* own post-run compaction (plan 074 C11).
|
|
82
|
+
*
|
|
83
|
+
* Precedence: an explicit `trigger` replaces the legacy gates. Only the token gates below a `trigger`
|
|
84
|
+
* replace are lazy — a `threshold_entries` trigger, or a `custom` callback that only reads counts,
|
|
85
|
+
* never pays for the token estimate or the input cap.
|
|
86
|
+
*
|
|
87
|
+
* Failure policy: a malformed trigger throws (`assertCompactionTrigger`, config error), while a
|
|
88
|
+
* throwing `custom.shouldCompact` — including a callback that reads an unresolvable cap — decides
|
|
89
|
+
* `false` and reports through `onError`, so a host bug can never compact on a guess.
|
|
90
|
+
*/
|
|
91
|
+
export declare function resolveShouldCompact(options: ResolveShouldCompactOptions, input: ResolveShouldCompactInput): Promise<boolean>;
|
|
33
92
|
export interface CompactionMiddlewarePayload {
|
|
34
93
|
readonly context: CompactionContext;
|
|
35
94
|
readonly result: CompactionResult;
|
|
@@ -1,2 +1,78 @@
|
|
|
1
|
-
|
|
1
|
+
/** Validate a host trigger at config time, so an unknown `type` fails at create (C11). */
|
|
2
|
+
export function assertCompactionTrigger(trigger) {
|
|
3
|
+
if (typeof trigger !== "object" || trigger === null) {
|
|
4
|
+
throw new TypeError("compaction trigger must be an object");
|
|
5
|
+
}
|
|
6
|
+
switch (trigger.type) {
|
|
7
|
+
case "threshold_entries":
|
|
8
|
+
if (!Number.isSafeInteger(trigger.entries) || trigger.entries < 1) {
|
|
9
|
+
throw new TypeError("compaction trigger threshold_entries.entries must be a positive safe integer");
|
|
10
|
+
}
|
|
11
|
+
return trigger;
|
|
12
|
+
case "input_ratio":
|
|
13
|
+
if (!Number.isFinite(trigger.ratio) || trigger.ratio <= 0 || trigger.ratio >= 1) {
|
|
14
|
+
throw new TypeError("compaction trigger input_ratio.ratio must be a number in (0, 1)");
|
|
15
|
+
}
|
|
16
|
+
return trigger;
|
|
17
|
+
case "custom":
|
|
18
|
+
if (typeof trigger.shouldCompact !== "function") {
|
|
19
|
+
throw new TypeError("compaction trigger custom.shouldCompact must be a function");
|
|
20
|
+
}
|
|
21
|
+
return trigger;
|
|
22
|
+
default:
|
|
23
|
+
throw new TypeError(`unknown compaction trigger type: ${String(trigger.type)}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The single compact-when decision used by `autoCompact` and by host attach loops that gate their
|
|
28
|
+
* own post-run compaction (plan 074 C11).
|
|
29
|
+
*
|
|
30
|
+
* Precedence: an explicit `trigger` replaces the legacy gates. Only the token gates below a `trigger`
|
|
31
|
+
* replace are lazy — a `threshold_entries` trigger, or a `custom` callback that only reads counts,
|
|
32
|
+
* never pays for the token estimate or the input cap.
|
|
33
|
+
*
|
|
34
|
+
* Failure policy: a malformed trigger throws (`assertCompactionTrigger`, config error), while a
|
|
35
|
+
* throwing `custom.shouldCompact` — including a callback that reads an unresolvable cap — decides
|
|
36
|
+
* `false` and reports through `onError`, so a host bug can never compact on a guess.
|
|
37
|
+
*/
|
|
38
|
+
export async function resolveShouldCompact(options, input) {
|
|
39
|
+
let estimated;
|
|
40
|
+
let cap;
|
|
41
|
+
const estimateOnce = () => (estimated ??= input.estimateInputTokens());
|
|
42
|
+
const capOnce = () => (cap ??= input.resolveInputCapTokens());
|
|
43
|
+
const trigger = options.trigger;
|
|
44
|
+
if (trigger === undefined) {
|
|
45
|
+
if (options.thresholdEntries !== undefined)
|
|
46
|
+
return input.entryCount > options.thresholdEntries;
|
|
47
|
+
if (options.compactAfterTokens !== undefined)
|
|
48
|
+
return estimateOnce() >= options.compactAfterTokens;
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
assertCompactionTrigger(trigger);
|
|
52
|
+
if (trigger.type === "threshold_entries")
|
|
53
|
+
return input.entryCount > trigger.entries;
|
|
54
|
+
if (trigger.type === "input_ratio")
|
|
55
|
+
return estimateOnce() >= trigger.ratio * capOnce();
|
|
56
|
+
// Getter-backed so a callback that only reads counts never forces cap resolution, which throws
|
|
57
|
+
// when the active model declares no context window.
|
|
58
|
+
const context = {
|
|
59
|
+
sessionId: input.sessionId,
|
|
60
|
+
entryCount: input.entryCount,
|
|
61
|
+
get estimatedInputTokens() {
|
|
62
|
+
return estimateOnce();
|
|
63
|
+
},
|
|
64
|
+
get inputCapTokens() {
|
|
65
|
+
return capOnce();
|
|
66
|
+
},
|
|
67
|
+
...(input.metadata === undefined ? {} : { metadata: input.metadata }),
|
|
68
|
+
...(input.signal === undefined ? {} : { signal: input.signal }),
|
|
69
|
+
};
|
|
70
|
+
try {
|
|
71
|
+
return (await trigger.shouldCompact(context)) === true;
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
input.onError?.(error);
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
2
78
|
//# sourceMappingURL=compaction.js.map
|
|
@@ -7,10 +7,13 @@ export type JsonValue = JsonPrimitive | JsonObject | JsonValue[];
|
|
|
7
7
|
export interface JsonObject {
|
|
8
8
|
readonly [key: string]: JsonValue;
|
|
9
9
|
}
|
|
10
|
+
export type ProviderFailureClass = "quota" | "auth" | "rate_limited" | "transient" | "permanent" | "unknown";
|
|
10
11
|
export interface ErrorInfo {
|
|
11
12
|
readonly name?: string;
|
|
12
13
|
readonly message: string;
|
|
13
14
|
readonly code?: string | number;
|
|
15
|
+
/** Advisory classification stamped only for provider failures; it never changes retry behavior. */
|
|
16
|
+
readonly failureClass?: ProviderFailureClass;
|
|
14
17
|
/** Provider backpressure hint (e.g. from a `Retry-After` header); retry policies
|
|
15
18
|
* honor it capped at their own `maxDelayMs`. */
|
|
16
19
|
readonly retryAfterMs?: number;
|
|
@@ -102,6 +105,8 @@ export interface ModelCapabilities {
|
|
|
102
105
|
readonly output?: readonly string[];
|
|
103
106
|
readonly reasoning?: boolean;
|
|
104
107
|
readonly tools?: boolean;
|
|
108
|
+
/** Advisory, conformance-derived tool-call behavior. Absent means unknown; it never changes runtime tool validation. */
|
|
109
|
+
readonly toolCallStrictness?: "strict" | "lenient" | "legacy";
|
|
105
110
|
readonly streaming?: boolean;
|
|
106
111
|
/** Native JSON-schema structured output support for this model. */
|
|
107
112
|
readonly structuredOutput?: boolean | "json_schema";
|
|
@@ -4,6 +4,48 @@ import type { AgentEvent, AgentFinishReason, ProviderTurnResult, ToolResult } fr
|
|
|
4
4
|
import type { AgentInput } from "../input.js";
|
|
5
5
|
import type { JsonValue, Message, ToolCallContent, Usage } from "./content.js";
|
|
6
6
|
import type { ProviderRequest, StructuredOutputOptions } from "./provider.js";
|
|
7
|
+
/**
|
|
8
|
+
* Metadata-only view of a run at a provider-turn boundary (plan 084 Task 2). Hosts branch on
|
|
9
|
+
* counters, never content: tool arguments, prompts, and tool results are not fields.
|
|
10
|
+
*/
|
|
11
|
+
export interface TurnBoundaryContext {
|
|
12
|
+
readonly sessionId: string;
|
|
13
|
+
readonly runId: string;
|
|
14
|
+
/** 1-based index of the provider turn this boundary precedes. */
|
|
15
|
+
readonly turn: number;
|
|
16
|
+
/** Provider turns already completed in this run (`turn - 1`; 0 at the first boundary). */
|
|
17
|
+
readonly turns: number;
|
|
18
|
+
/** Host tool calls dispatched so far in this run. */
|
|
19
|
+
readonly toolCalls: number;
|
|
20
|
+
/** Run-total usage so far, when the provider reported any. */
|
|
21
|
+
readonly usage?: Usage;
|
|
22
|
+
readonly metadata: Readonly<Record<string, unknown>>;
|
|
23
|
+
}
|
|
24
|
+
/** Synchronous decision at a turn boundary. `stop` ends the run cleanly; `continue` runs the turn. */
|
|
25
|
+
export type TurnStopDecision = {
|
|
26
|
+
readonly action: "continue";
|
|
27
|
+
} | {
|
|
28
|
+
readonly action: "stop";
|
|
29
|
+
readonly reason: string;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Host turn policy (plan 084 Task 2). Evaluated before every provider request, at the same
|
|
33
|
+
* boundary a `checkpointPolicy: "every-turn"` checkpoint is written. Omit it and the run keeps
|
|
34
|
+
* its exact 0.8.x turn structure (no callback, no reads).
|
|
35
|
+
*/
|
|
36
|
+
export interface TurnPolicyOptions {
|
|
37
|
+
/**
|
|
38
|
+
* Clean turn cap. Reaching it stops the run (`stopReason: "turn_limit"`) instead of failing it
|
|
39
|
+
* with a limit breach. A run overlay may only narrow `limits.maxTurns`; widening throws.
|
|
40
|
+
*/
|
|
41
|
+
readonly maxTurns?: number;
|
|
42
|
+
/**
|
|
43
|
+
* Consulted before every provider request. Returning `stop` ends the run cleanly with
|
|
44
|
+
* `stopReason: "host_policy"` and a resumable checkpoint (`decision: "continue"` resumes it).
|
|
45
|
+
* Must be synchronous and must not throw; a throw fails the run with `ERR_PRISM_TURN_POLICY`.
|
|
46
|
+
*/
|
|
47
|
+
readonly stop?: (context: TurnBoundaryContext) => TurnStopDecision;
|
|
48
|
+
}
|
|
7
49
|
export interface LoopContext {
|
|
8
50
|
readonly sessionId: string;
|
|
9
51
|
readonly runId: string;
|
|
@@ -83,6 +83,10 @@ export interface RealtimeSession {
|
|
|
83
83
|
close(reason?: string, options?: {
|
|
84
84
|
readonly signal?: AbortSignal;
|
|
85
85
|
}): Promise<void>;
|
|
86
|
+
/** Return a host-dispatched tool result. Omitted on transports that cannot complete tools. */
|
|
87
|
+
completeTool?(callId: string, output: string, options?: {
|
|
88
|
+
readonly signal?: AbortSignal;
|
|
89
|
+
}): Promise<void>;
|
|
86
90
|
}
|
|
87
91
|
/** Factory a provider exposes for realtime sessions; not part of `AIProvider`. */
|
|
88
92
|
export type RealtimeSessionFactory = (options: RealtimeSessionOptions) => RealtimeSession;
|
|
@@ -70,6 +70,8 @@ export interface GuardrailContext<S extends GuardrailStage> {
|
|
|
70
70
|
readonly runId: string;
|
|
71
71
|
readonly toolCallId?: string;
|
|
72
72
|
readonly toolName?: string;
|
|
73
|
+
/** Same-run completed host tool results, available only at the output stage. */
|
|
74
|
+
readonly toolResults?: S extends "output" ? readonly ToolResult[] : never;
|
|
73
75
|
readonly metadata: Readonly<Record<string, unknown>>;
|
|
74
76
|
readonly signal: AbortSignal;
|
|
75
77
|
}
|
package/dist/contracts-core.d.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* of `./contracts-core.js` is unchanged (0.1.4 barrel precedent). */
|
|
4
4
|
export type { AudioContent, DocumentContent, FileContent } from "./content.js";
|
|
5
5
|
export * from "./contracts-core/agent.js";
|
|
6
|
+
export * from "./contracts-core/attention.js";
|
|
6
7
|
export * from "./contracts-core/batch.js";
|
|
7
8
|
export * from "./contracts-core/compaction.js";
|
|
8
9
|
export * from "./contracts-core/content.js";
|
package/dist/contracts-core.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AgentLoopOptions, AgentLoopStrategy, ArtifactValidation, CompactionOptions, ContentBlock, ErrorInfo, GuardrailRecord, Guardrails, InstructionInjector, JsonObject, Message, ModelConfig, OwnershipScope, ProviderRequestOptions, ProviderRequestPolicy, ProviderResolver, RetryOptions, RunLimitBreach, RunLimits, Skill, SubscriberOverflowPolicy, SystemPromptConfig, ToolCallAuthority, ToolCallContent, Usage } from "./contracts-core.js";
|
|
1
|
+
import type { AgentLoopOptions, AgentLoopStrategy, ArtifactValidation, CompactionOptions, ContentBlock, ErrorInfo, GuardrailRecord, Guardrails, InstructionInjector, JsonObject, Message, ModelConfig, OwnershipScope, ProviderRequestOptions, ProviderRequestPolicy, ProviderResolver, RetryOptions, RunLimitBreach, RunLimits, Skill, SubscriberOverflowPolicy, SystemPromptConfig, ToolCallAuthority, ToolCallContent, TurnPolicyOptions, Usage } from "./contracts-core.js";
|
|
2
2
|
import type { AgentRunInterruption, AgentRunStateOptions } from "./contracts-run-state.js";
|
|
3
3
|
import type { SecretRedactor } from "./redaction.js";
|
|
4
4
|
import type { ToolValidator } from "./tools.js";
|
|
@@ -45,6 +45,9 @@ export type RealtimeEvent = {
|
|
|
45
45
|
} | {
|
|
46
46
|
readonly type: "tool_call";
|
|
47
47
|
readonly call: ToolCallContent;
|
|
48
|
+
} | {
|
|
49
|
+
readonly type: "usage";
|
|
50
|
+
readonly usage: Usage;
|
|
48
51
|
} | {
|
|
49
52
|
readonly type: "interrupted";
|
|
50
53
|
} | {
|
|
@@ -97,11 +100,22 @@ export interface RunOptions {
|
|
|
97
100
|
readonly activateAllSkills?: true;
|
|
98
101
|
/** Progressive: catalog (name+description) unless loaded; eager: full instructions every turn. Default progressive. */
|
|
99
102
|
readonly skillsDisclosure?: import("./skill-disclosure.js").SkillsDisclosure;
|
|
103
|
+
/**
|
|
104
|
+
* Optional per-run allow-list of registered tool names. Omitted → every registered tool (legacy).
|
|
105
|
+
* Empty → no tools this run. Unknown names fail closed. Cannot widen the agent registry or a
|
|
106
|
+
* checkpointed grant; resume intersects this list with current authority.
|
|
107
|
+
*/
|
|
108
|
+
readonly toolNames?: readonly string[];
|
|
100
109
|
/** Tools disclosure: "all" (default) sends every active tool schema; "search" sends top-k + the generated `search_tools` tool. */
|
|
101
110
|
readonly toolsDisclosure?: import("./tool-search.js").ToolsDisclosure;
|
|
102
111
|
readonly toolsSearch?: import("./tool-search.js").ToolsSearchOptions;
|
|
103
112
|
/** Opt-in projection-only fold for aged large tool results in provider view; store untouched. */
|
|
104
113
|
readonly toolResultFold?: import("./tool-result-fold.js").ToolResultFoldOptions;
|
|
114
|
+
/** Per-run overlay for `AgentConfig.attentionCompiler` (plan 074 C12): `false` disables the
|
|
115
|
+
* compiler for this run, `true` is a no-op, an object may only relax the agent setting
|
|
116
|
+
* (gate ratios up, `keepLast`/`thinkingKeepTurns` down, `excludeTools` extended). Enabling
|
|
117
|
+
* the compiler where the agent config left it off throws before the first provider turn. */
|
|
118
|
+
readonly attentionCompiler?: import("./contracts-core/attention.js").AttentionCompilerSetting;
|
|
105
119
|
readonly instructionInjectors?: readonly InstructionInjector[];
|
|
106
120
|
readonly inputLayout?: InputAssemblyLayout;
|
|
107
121
|
readonly loop?: AgentLoopStrategy | AgentLoopOptions;
|
|
@@ -111,6 +125,11 @@ export interface RunOptions {
|
|
|
111
125
|
readonly runState?: AgentRunStateOptions;
|
|
112
126
|
/** Prompt provenance: copied verbatim onto this run's start and finish ledger records. */
|
|
113
127
|
readonly promptVersion?: PromptVersionRef;
|
|
128
|
+
/**
|
|
129
|
+
* Host turn policy (plan 084 Task 2): a clean turn cap and/or a synchronous stop callback
|
|
130
|
+
* evaluated before every provider request. Omitted → no callback runs.
|
|
131
|
+
*/
|
|
132
|
+
readonly turnPolicy?: TurnPolicyOptions;
|
|
114
133
|
}
|
|
115
134
|
export interface ProviderTurnMetadata {
|
|
116
135
|
readonly providerId: string;
|
|
@@ -156,7 +175,8 @@ export interface DelegatedAgentStep {
|
|
|
156
175
|
readonly label?: string;
|
|
157
176
|
};
|
|
158
177
|
}
|
|
159
|
-
|
|
178
|
+
/** Why a run stopped cleanly. `host_policy` is a `RunOptions.turnPolicy` stop; the rest are loop ceilings (F4). */
|
|
179
|
+
export type AgentFinishReason = "turn_limit" | "token_limit" | "refusal" | "host_policy";
|
|
160
180
|
export type AgentEvent = {
|
|
161
181
|
readonly type: "agent_started";
|
|
162
182
|
readonly sessionId: string;
|
|
@@ -166,8 +186,10 @@ export type AgentEvent = {
|
|
|
166
186
|
readonly sessionId: string;
|
|
167
187
|
readonly runId: string;
|
|
168
188
|
readonly usage?: Usage;
|
|
169
|
-
/** Why the loop stopped, when a limit/ceiling ended the run cleanly (F4). Absent = natural end. */
|
|
189
|
+
/** Why the loop stopped, when a limit/ceiling or a host turn policy ended the run cleanly (F4). Absent = natural end. */
|
|
170
190
|
readonly finishReason?: AgentFinishReason;
|
|
191
|
+
/** Host stop detail from `TurnPolicyOptions.stop` (≤256 bytes, redacted). Present only with `finishReason: "host_policy"`. */
|
|
192
|
+
readonly stopDetail?: string;
|
|
171
193
|
} | {
|
|
172
194
|
readonly type: "agent_suspended";
|
|
173
195
|
readonly sessionId: string;
|
|
@@ -299,6 +321,21 @@ export type AgentEvent = {
|
|
|
299
321
|
readonly sessionId: string;
|
|
300
322
|
readonly runId?: string;
|
|
301
323
|
readonly summary: string;
|
|
324
|
+
} | {
|
|
325
|
+
/** One attention-compiler mutation (plan 074 R15/T6): measured counts only, never message text. */
|
|
326
|
+
readonly type: "attention_compiled";
|
|
327
|
+
readonly sessionId: string;
|
|
328
|
+
readonly runId?: string;
|
|
329
|
+
readonly used: number;
|
|
330
|
+
/** Estimated tokens of the same request after this turn's mutation. */
|
|
331
|
+
readonly usedAfter: number;
|
|
332
|
+
readonly inputCap: number;
|
|
333
|
+
readonly triggerRatio: number;
|
|
334
|
+
readonly droppedThinkingTurns: number;
|
|
335
|
+
readonly stubbedToolResults: number;
|
|
336
|
+
/** Payload bytes the tool stubs took out of this request. */
|
|
337
|
+
readonly stubbedBytes: number;
|
|
338
|
+
readonly truncated: boolean;
|
|
302
339
|
} | {
|
|
303
340
|
readonly type: "retry_scheduled";
|
|
304
341
|
readonly sessionId: string;
|
|
@@ -509,6 +546,10 @@ export interface RunRecord extends OwnershipScope {
|
|
|
509
546
|
readonly startedAt: string;
|
|
510
547
|
readonly finishedAt?: string;
|
|
511
548
|
readonly abortReason?: string;
|
|
549
|
+
/** Present when the loop stopped on a ceiling or host policy instead of a natural end. */
|
|
550
|
+
readonly stopReason?: AgentFinishReason;
|
|
551
|
+
/** Host stop detail from `TurnPolicyOptions.stop` (≤256 bytes, redacted). */
|
|
552
|
+
readonly stopDetail?: string;
|
|
512
553
|
readonly error?: ErrorInfo;
|
|
513
554
|
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
514
555
|
/** Provenance ref copied from `RunOptions.promptVersion` when the host supplied one. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AgentSessionCloneOptions, AgentSessionForkOptions, CheckpointStore, CompactionOptions, CompactionResult, ContentBlock, ErrorInfo, JsonObject, JsonValue, Message, ModelConfig, OwnershipScope, RunLimitBreach, SessionEntry, SubscribeOptions, ToolCallContent, Usage } from "./contracts-core.js";
|
|
2
|
-
import type { AgentEvent, RunOptions, ToolEffectKind } from "./contracts-protocol.js";
|
|
2
|
+
import type { AgentEvent, AgentFinishReason, RunOptions, ToolEffectKind } from "./contracts-protocol.js";
|
|
3
3
|
export type AgentRunStatus = "succeeded" | "failed" | "aborted" | "suspended" | "denied";
|
|
4
4
|
export type AgentRunInterruptionKind = "input_guardrail" | "tool_approval" | "elicitation";
|
|
5
5
|
export type ApprovalOutcome = "allow_once" | "allow_for_run" | "reject_once" | "reject_for_run";
|
|
@@ -143,6 +143,17 @@ export interface AgentRunStateOptions {
|
|
|
143
143
|
readonly checkpoints: CheckpointStore;
|
|
144
144
|
/** Host-authored immutable revision required for durable runs. */
|
|
145
145
|
readonly definitionRevision: string;
|
|
146
|
+
/**
|
|
147
|
+
* Durable checkpoint cadence (plan 084 Task 1). `"decision"` (default) persists only on
|
|
148
|
+
* suspension and terminal status. `"every-turn"` additionally persists a running-state
|
|
149
|
+
* checkpoint at each provider-turn boundary — after the previous turn's tool results are in
|
|
150
|
+
* the session store, before the next provider request — so a host process that dies mid-run
|
|
151
|
+
* can `resumeAgentRun(..., { decision: "continue" })` from the last turn instead of re-running
|
|
152
|
+
* the investigation. Costs one bounded, redacted checkpoint write per provider turn; the
|
|
153
|
+
* policy is recorded in the checkpoint, so a later resume keeps checkpointing without the host
|
|
154
|
+
* repeating the option.
|
|
155
|
+
*/
|
|
156
|
+
readonly checkpointPolicy?: "decision" | "every-turn";
|
|
146
157
|
/** Suspend every tool call before its side effect. */
|
|
147
158
|
readonly interruptBeforeTool?: boolean;
|
|
148
159
|
readonly maxStateBytes?: number;
|
|
@@ -183,8 +194,13 @@ export interface AgentRunState {
|
|
|
183
194
|
}
|
|
184
195
|
export interface AgentRunResume {
|
|
185
196
|
readonly expectedVersion: number;
|
|
186
|
-
/**
|
|
187
|
-
|
|
197
|
+
/**
|
|
198
|
+
* Legacy decision path. `approve` allows all pending decisions once; `deny` terminates the run
|
|
199
|
+
* as `denied`; `continue` resumes a running-state `"every-turn"` checkpoint that has no pending
|
|
200
|
+
* decisions (crash recovery). A suspended run still requires `approve`/`deny` or a decision
|
|
201
|
+
* batch — `continue` never bypasses an approval gate and is a host-API-only action.
|
|
202
|
+
*/
|
|
203
|
+
readonly decision?: "approve" | "deny" | "continue";
|
|
188
204
|
/** Batch decision path; exactly one of decision/decisions. Applied as one atomic CAS transition. */
|
|
189
205
|
readonly decisions?: readonly RunDecision[];
|
|
190
206
|
}
|
|
@@ -194,16 +210,23 @@ export interface AgentRunResumeOptions {
|
|
|
194
210
|
readonly definitionRevision: string;
|
|
195
211
|
readonly ownership?: OwnershipScope;
|
|
196
212
|
readonly fencingToken?: number;
|
|
213
|
+
/** Host abort for the resume: checked between steps and threaded into the resumed provider/tool turn. */
|
|
214
|
+
readonly signal?: AbortSignal;
|
|
197
215
|
/** Routes root decisions for nested-run approvals back to the child (e.g. supervisor). */
|
|
198
216
|
readonly resumeNestedRun?: ResumeNestedRun;
|
|
217
|
+
/**
|
|
218
|
+
* Opt-in (plan 078 Task 7): receives the reconstructed session before the resumed run
|
|
219
|
+
* starts, so an observer (e.g. the supervisor's child-event pump) can subscribe while the
|
|
220
|
+
* run is still live. The session is valid only for the duration of this resume.
|
|
221
|
+
*/
|
|
222
|
+
readonly onSession?: (session: AgentSession) => void;
|
|
199
223
|
/** Opt-in (plan 015 Task 4): restore persisted loaded-skill names into the resumed session catalog. */
|
|
200
224
|
readonly persistSessionState?: boolean;
|
|
201
225
|
/** Opt-in (plan 018 Task 6): restore persisted loaded-skill bodies (requires `persistSessionState` too). */
|
|
202
226
|
readonly includeSkillBodies?: boolean;
|
|
203
227
|
}
|
|
204
|
-
/** Bounded
|
|
228
|
+
/** Bounded live-event options for `resumeAgentRunStream()`; `signal` is inherited from the base resume options. */
|
|
205
229
|
export interface AgentRunResumeStreamOptions extends AgentRunResumeOptions, SubscribeOptions {
|
|
206
|
-
readonly signal?: AbortSignal;
|
|
207
230
|
}
|
|
208
231
|
export interface AgentRunRef {
|
|
209
232
|
readonly runId: string;
|
|
@@ -245,6 +268,10 @@ export interface AgentRunResult {
|
|
|
245
268
|
readonly error?: ErrorInfo;
|
|
246
269
|
/** String form of the abort reason when `status` is `"aborted"`. */
|
|
247
270
|
readonly abortReason?: string;
|
|
271
|
+
/** Present when the loop stopped on a ceiling or host turn policy instead of a natural end. */
|
|
272
|
+
readonly stopReason?: AgentFinishReason;
|
|
273
|
+
/** Host stop detail from `TurnPolicyOptions.stop` (≤256 bytes, redacted). */
|
|
274
|
+
readonly stopDetail?: string;
|
|
248
275
|
/** Present for durable suspended/terminal runs. Payload is redacted and bounded. */
|
|
249
276
|
readonly runState?: AgentRunState;
|
|
250
277
|
/** Present only while awaiting an operator decision. */
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Guardrail, ToolResult } from "./contracts.js";
|
|
2
|
+
export interface ClaimGroundingEvidence {
|
|
3
|
+
readonly value: number;
|
|
4
|
+
/** Refer to this governed figure as `[evidence:<ref>]` immediately after a claim. */
|
|
5
|
+
readonly ref?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ClaimGroundingEvidenceExtractorContext {
|
|
8
|
+
readonly sessionId: string;
|
|
9
|
+
readonly runId: string;
|
|
10
|
+
readonly metadata: Readonly<Record<string, unknown>>;
|
|
11
|
+
readonly toolResults: readonly ToolResult[];
|
|
12
|
+
}
|
|
13
|
+
/** Supplies host-governed figures without coupling this primitive to a host store or package. */
|
|
14
|
+
export type ClaimGroundingEvidenceExtractor = (context: ClaimGroundingEvidenceExtractorContext) => readonly ClaimGroundingEvidence[];
|
|
15
|
+
export interface ClaimGroundingGuardrailOptions {
|
|
16
|
+
/** False makes the returned guardrail a no-op. */
|
|
17
|
+
readonly requireEvidenceForNumbers: boolean;
|
|
18
|
+
/** Defaults to same-run tool results. A host extractor may return its own governed figures. */
|
|
19
|
+
readonly evidenceSources?: "tool_results" | ClaimGroundingEvidenceExtractor;
|
|
20
|
+
/** Defaults to block. Flag emits an allow record with `metadata.violation: true`. */
|
|
21
|
+
readonly onViolation?: "block" | "flag";
|
|
22
|
+
/** Exact numeric equality by default; rounded accepts half the final printed unit. */
|
|
23
|
+
readonly tolerance?: "exact" | "rounded";
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Deterministic output guardrail for figures that must be grounded in same-run tool results
|
|
27
|
+
* or host-governed evidence. It never calls a provider, store, or extractor asynchronously.
|
|
28
|
+
*/
|
|
29
|
+
export declare function createClaimGroundingGuardrail(options: ClaimGroundingGuardrailOptions): Guardrail<"output">;
|