@arnilo/prism-hosts 0.13.0 → 0.14.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 +2 -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 +1308 -1367
- package/host-builder/data/errors.json +207 -181
- 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 +3 -3
- package/host-builder/data/examples/memory-system.ts +31 -18
- 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 +29 -26
- package/host-builder/data/examples/side-call.ts +9 -5
- 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 +15 -5
- 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
package/acp/README.md
CHANGED
|
@@ -25,6 +25,8 @@ serveAcp(agent, { stream, authorize? });
|
|
|
25
25
|
|
|
26
26
|
## Outputs / response / events
|
|
27
27
|
|
|
28
|
+
ACP chunks are append-only, so the mapper holds each provider attempt's `agent_message_chunk` and `agent_thought_chunk` updates until its `turn.completed` and drops them when it ends with `error`: the run may retry an attempt that failed after output ([Events](../../../docs/events.md#failed-attempts)). Clients receive each attempt's chunks when it completes rather than token by token.
|
|
29
|
+
|
|
28
30
|
`serveAcp` returns `{ closed, close() }`. A prompt resolves with an ACP `StopReason`:
|
|
29
31
|
|
|
30
32
|
| Run | StopReason |
|
|
@@ -77,7 +79,7 @@ await server.closed;
|
|
|
77
79
|
|
|
78
80
|
Unknown session, rejected or cancelled permission, a client without elicitation, and `authorize: false` fail closed. Nothing is allowed by default. Package titles and elicitation text are sent as plain text. Events pass through the agent's redactor.
|
|
79
81
|
|
|
80
|
-
No work per connection beyond the agent's own runs. Notification text is capped at 64 KiB (`maxTextBytes`). A prompt stops forwarding after 10,000 updates (`maxStreamEvents`). Load replays at most 100 message chunks (`maxReplayEvents`). Diffs are capped at 64 KiB, images at 256 KiB, and command lists at 32. These are the `
|
|
82
|
+
No work per connection beyond the agent's own runs. Notification text is capped at 64 KiB (`maxTextBytes`). A prompt stops forwarding after 10,000 updates (`maxStreamEvents`). Load replays at most 100 message chunks (`maxReplayEvents`). Diffs are capped at 64 KiB, images at 256 KiB, and command lists at 32. These are the `ACP_LIMITS` defaults; `serveAcp(agent, { limits })` sets each, and the host's value is the cap.
|
|
81
83
|
|
|
82
84
|
## Related APIs
|
|
83
85
|
|
package/acp/src/limits.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AcpError } from "./errors.js";
|
|
2
2
|
|
|
3
|
-
/** Defaults copied from `packages/ag-ui/src/limits.ts`.
|
|
3
|
+
/** Defaults copied from `packages/ag-ui/src/limits.ts`. The host sets each (`serveAcp({ limits })`); its value is the cap. */
|
|
4
4
|
export const ACP_LIMITS = {
|
|
5
5
|
maxEventBytes: 64 * 1024,
|
|
6
6
|
maxTextBytes: 64 * 1024,
|
|
@@ -13,18 +13,6 @@ export const ACP_LIMITS = {
|
|
|
13
13
|
acpCommandsPerUpdate: 32,
|
|
14
14
|
} as const;
|
|
15
15
|
|
|
16
|
-
const HARD = {
|
|
17
|
-
maxEventBytes: 1024 * 1024,
|
|
18
|
-
maxTextBytes: 1024 * 1024,
|
|
19
|
-
maxReplayEvents: 500,
|
|
20
|
-
maxStreamEvents: 100_000,
|
|
21
|
-
maxStreamBytes: 64 * 1024 * 1024,
|
|
22
|
-
acpDiffBytes: 1024 * 1024,
|
|
23
|
-
acpLocationsPerUpdate: 128,
|
|
24
|
-
acpImageBytes: 1024 * 1024,
|
|
25
|
-
acpCommandsPerUpdate: 128,
|
|
26
|
-
} as const;
|
|
27
|
-
|
|
28
16
|
export type AcpLimitName = keyof typeof ACP_LIMITS;
|
|
29
17
|
|
|
30
18
|
export type AcpLimitOptions = { readonly [K in AcpLimitName]?: number };
|
|
@@ -40,10 +28,9 @@ export function resolveAcpLimits(options: AcpLimitOptions = {}): ResolvedAcpLimi
|
|
|
40
28
|
}
|
|
41
29
|
|
|
42
30
|
function validate(name: AcpLimitName, value: number): number {
|
|
43
|
-
const hard = HARD[name];
|
|
44
31
|
const minimum = name.endsWith("Bytes") ? (name === "maxTextBytes" ? 16 : 1024) : 1;
|
|
45
|
-
if (!Number.isSafeInteger(value) || value < minimum
|
|
46
|
-
throw new AcpError("ERR_PRISM_ACP_LIMIT", `${name} must be a safe integer
|
|
32
|
+
if (!Number.isSafeInteger(value) || value < minimum) {
|
|
33
|
+
throw new AcpError("ERR_PRISM_ACP_LIMIT", `${name} must be a safe integer of at least ${minimum}`);
|
|
47
34
|
}
|
|
48
35
|
return value;
|
|
49
36
|
}
|
package/acp/src/mapper.ts
CHANGED
|
@@ -150,6 +150,17 @@ export function createAcpEventMapper(options: AcpEventMapperOptions = {}): AcpEv
|
|
|
150
150
|
let messageId: string | undefined;
|
|
151
151
|
let textDeltaSeen = false;
|
|
152
152
|
let thoughtDeltaSeen = false;
|
|
153
|
+
/**
|
|
154
|
+
* Plan 227 Task 4: ACP chunks are append-only, and a provider attempt that fails after output is
|
|
155
|
+
* retried. Between `turn.started` and `turn.completed` the attempt's chunks are held, then sent when
|
|
156
|
+
* it completes cleanly or dropped when it ends with `error`. Deltas outside an attempt pass through.
|
|
157
|
+
*/
|
|
158
|
+
let attempt: SessionUpdate[] | undefined;
|
|
159
|
+
const live = (update: SessionUpdate): SessionUpdate[] => {
|
|
160
|
+
if (!attempt) return [update];
|
|
161
|
+
attempt.push(update);
|
|
162
|
+
return [];
|
|
163
|
+
};
|
|
153
164
|
|
|
154
165
|
const text = (value: string, maxBytes = limits.maxTextBytes) =>
|
|
155
166
|
truncate(options.redactor?.redact(value) ?? value, Math.min(maxBytes, limits.maxEventBytes));
|
|
@@ -269,12 +280,12 @@ export function createAcpEventMapper(options: AcpEventMapperOptions = {}): AcpEv
|
|
|
269
280
|
if (event.content.type === "thinking") {
|
|
270
281
|
messageId ??= `${text(event.runId)}:message`;
|
|
271
282
|
thoughtDeltaSeen = true;
|
|
272
|
-
return
|
|
283
|
+
return live(thought(messageId ?? `${text(event.runId)}:message`, text(event.content.text)));
|
|
273
284
|
}
|
|
274
285
|
if (event.content.type !== "text") return [];
|
|
275
286
|
messageId ??= `${text(event.runId)}:message`;
|
|
276
287
|
textDeltaSeen = true;
|
|
277
|
-
return
|
|
288
|
+
return live(message(messageId ?? `${text(event.runId)}:message`, text(event.content.text)));
|
|
278
289
|
case "message.completed": {
|
|
279
290
|
if (event.message.role !== "assistant") return [];
|
|
280
291
|
const id = messageId ?? text(event.message.id ?? `${event.runId}:message`);
|
|
@@ -305,11 +316,21 @@ export function createAcpEventMapper(options: AcpEventMapperOptions = {}): AcpEv
|
|
|
305
316
|
event.status === "finished" ? event.result : undefined,
|
|
306
317
|
),
|
|
307
318
|
];
|
|
308
|
-
case "turn.
|
|
319
|
+
case "turn.started":
|
|
320
|
+
attempt = [];
|
|
321
|
+
return [];
|
|
322
|
+
case "turn.completed": {
|
|
309
323
|
// B2: a failed provider turn is a request-level condition, not transcript content;
|
|
310
324
|
// the agent's forward() throws ERR_PRISM_ACP_RUN when the run ends in a terminal
|
|
311
|
-
// `error` event
|
|
312
|
-
|
|
325
|
+
// `error` event. A failed attempt's held chunks are dropped: the run may retry it.
|
|
326
|
+
const held = event.error ? [] : (attempt ?? []);
|
|
327
|
+
attempt = undefined;
|
|
328
|
+
if (event.error) {
|
|
329
|
+
textDeltaSeen = false;
|
|
330
|
+
thoughtDeltaSeen = false;
|
|
331
|
+
}
|
|
332
|
+
return [...held, ...(event.usage && event.metadata ? await usage(event.usage, event.metadata.model.model) : [])];
|
|
333
|
+
}
|
|
313
334
|
case "decision.resolved":
|
|
314
335
|
return event.decisions.some((decision) => decision.outcome === "deny")
|
|
315
336
|
? [message(`${text(event.runId)}:status`, "Run denied")]
|
package/acp/src/serve.ts
CHANGED
|
@@ -14,7 +14,7 @@ import type { Agent, AgentEvent, AgentFinishReason, Decision, JsonObject, Pendin
|
|
|
14
14
|
import { isSessionNotFound } from "@arnilo/prism";
|
|
15
15
|
import manifest from "../../package.json" with { type: "json" };
|
|
16
16
|
import { AcpError } from "./errors.js";
|
|
17
|
-
import { resolveAcpLimits } from "./limits.js";
|
|
17
|
+
import { type AcpLimitOptions, type ResolvedAcpLimits, resolveAcpLimits } from "./limits.js";
|
|
18
18
|
import { createAcpEventMapper } from "./mapper.js";
|
|
19
19
|
import { decisionForPermission, elicitationRequest, PERMISSION_OPTIONS } from "./permission.js";
|
|
20
20
|
import { projectAcpPrompt } from "./prompt.js";
|
|
@@ -27,6 +27,8 @@ export interface ServeAcpOptions {
|
|
|
27
27
|
readonly stream?: Stream;
|
|
28
28
|
/** Per-connection allow/deny. Absent allows the peer. `false` is a JSON-RPC error and creates no session. */
|
|
29
29
|
readonly authorize?: (input: { readonly peer: "stdio" | "stream" }) => boolean | Promise<boolean>;
|
|
30
|
+
/** Event, text, replay, stream, diff and image bounds. Each defaults to `ACP_LIMITS`; the host's value is the cap. */
|
|
31
|
+
readonly limits?: AcpLimitOptions;
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
export interface ServeAcpHandle {
|
|
@@ -52,7 +54,7 @@ export function serveAcp(prism: Agent, options: ServeAcpOptions): ServeAcpHandle
|
|
|
52
54
|
if (options.stdio !== true && !options.stream)
|
|
53
55
|
throw new AcpError("ERR_PRISM_ACP_INPUT", "serveAcp requires { stdio: true } or { stream }");
|
|
54
56
|
const stream = options.stream ?? stdioStream();
|
|
55
|
-
const limits = resolveAcpLimits();
|
|
57
|
+
const limits = resolveAcpLimits(options.limits);
|
|
56
58
|
const host = isAcpHost(prism.config.host) ? prism.config.host : undefined;
|
|
57
59
|
const sessions = new Map<string, Session>();
|
|
58
60
|
const cancelled = new Set<string>();
|
|
@@ -96,7 +98,7 @@ export function serveAcp(prism: Agent, options: ServeAcpOptions): ServeAcpHandle
|
|
|
96
98
|
const session = sessions.get(ctx.params.sessionId);
|
|
97
99
|
if (!session) throw RequestError.invalidParams(undefined, "unknown session");
|
|
98
100
|
cancelled.delete(session.id);
|
|
99
|
-
const text = await promptText(ctx.params.prompt);
|
|
101
|
+
const text = await promptText(ctx.params.prompt, limits);
|
|
100
102
|
const command = commandOf(text, prism);
|
|
101
103
|
if (command) {
|
|
102
104
|
await prism.commands.run(command.name, command.args, { session });
|
|
@@ -322,8 +324,7 @@ async function openStored(prism: Agent, id: string): Promise<Session> {
|
|
|
322
324
|
}
|
|
323
325
|
}
|
|
324
326
|
|
|
325
|
-
async function promptText(prompt: readonly { readonly type: string }[]): Promise<string> {
|
|
326
|
-
const limits = resolveAcpLimits();
|
|
327
|
+
async function promptText(prompt: readonly { readonly type: string }[], limits: ResolvedAcpLimits): Promise<string> {
|
|
327
328
|
const projected = await projectAcpPrompt(prompt, {
|
|
328
329
|
maxBlocks: 32,
|
|
329
330
|
maxTextBytes: limits.maxTextBytes,
|
package/ag-ui/README.md
CHANGED
|
@@ -42,6 +42,7 @@ ACP v1 serving lives in [`@arnilo/prism-hosts/acp`](../acp/README.md) (plan 161)
|
|
|
42
42
|
|
|
43
43
|
## Cost, security, and failure behavior
|
|
44
44
|
|
|
45
|
+
- **Retried provider attempts:** a `turn.completed` with `error` is not a `RUN_ERROR` (the run may retry it; a final failure arrives as `run.failed`). The mapper ends the failed attempt's text and reasoning messages, and the retry's `turn.started` emits a `prism.retry` custom event (with `includeCustomEvents`) whose `discardMessageIds` names them, since AG-UI cannot retract text.
|
|
45
46
|
- **Narrow-only session ownership:** `createAgUiHandler` passes `authorization.ownership` both when opening the session (`agent.session({ id: threadId, create, ownership: authorization.ownership })`) and on `session.stream` / `session.resume`. Both session opens happen before the SSE response starts.
|
|
46
47
|
- **Indistinguishable `404` on absent or foreign sessions:** `SessionNotFoundError` and `OwnershipScopeError` map to `404 ERR_PRISM_AG_UI_NOT_FOUND` (`{"error":{"code":"ERR_PRISM_AG_UI_NOT_FOUND","message":"Session not found"}}`) before the SSE stream opens, so a response never distinguishes an absent thread from another user's thread.
|
|
47
48
|
- **Scoped pending interrupts:** the handler's in-memory `pending` interrupt map records `authorization.ownership` alongside `threadId` and `approvalId`. A resume request from a different ownership scope is rejected before any session open as a foreign interrupt (`400 ERR_PRISM_AG_UI_INPUT`, matching a wrong `threadId`).
|
|
@@ -49,7 +50,7 @@ ACP v1 serving lives in [`@arnilo/prism-hosts/acp`](../acp/README.md) (plan 161)
|
|
|
49
50
|
|
|
50
51
|
## Limits and security
|
|
51
52
|
|
|
52
|
-
Defaults / hard: request/event/state/activity/reasoning/raw 64 KiB / 1 MiB; input 128 / 1024 messages, 32 / 256 tools/contexts, 8 / 64 interrupts, 16 / 64 media parts; patches 128 / 4096 operations; JSON depth 16 / 64, properties 128 / 4096, arrays 512 / 8192; replay 100 / 500 records; queue
|
|
53
|
+
Defaults / hard: request/event/state/activity/reasoning/raw 64 KiB / 1 MiB; input 128 / 1024 messages, 32 / 256 tools/contexts, 8 / 64 interrupts, 16 / 64 media parts; patches 128 / 4096 operations; JSON depth 16 / 64, properties 128 / 4096, arrays 512 / 8192; replay 100 / 500 records; queue 4096 / 4096 events (a lagging client's adjacent deltas are coalesced; overflow fails the stream and the run still settles); stream 10,000 / 100,000 events and 10 / 64 MiB; request wall time 120 seconds / 30 minutes. SSE only; WebSocket/protobuf/push stay undeclared. Overflow closes with a bounded error. Resume decisions are bounded to 128 entries, 8 KiB reasons, and 64 KiB payloads before the kernel re-validates them.
|
|
53
54
|
|
|
54
55
|
Run the demos with `bun examples/ag-ui-server.ts` (approval interrupt/resume), `bun examples/ag-ui-a2ui.ts` (A2UI painting), and `bun examples/ag-ui-mcp-apps.ts` (MCP Apps proxy).
|
|
55
56
|
|
package/ag-ui/src/a2ui.ts
CHANGED
|
@@ -14,13 +14,9 @@ export const A2UI_ERROR_EVENT = "prism.a2ui.error";
|
|
|
14
14
|
const OP_KEYS = ["createSurface", "updateComponents", "updateDataModel", "deleteSurface"] as const;
|
|
15
15
|
|
|
16
16
|
export const DEFAULT_MAX_A2UI_OPS_PER_MESSAGE = 64;
|
|
17
|
-
export const HARD_MAX_A2UI_OPS_PER_MESSAGE = 512;
|
|
18
17
|
export const DEFAULT_MAX_A2UI_OPERATION_BYTES = 64 * 1024;
|
|
19
|
-
export const HARD_MAX_A2UI_OPERATION_BYTES = 1024 * 1024;
|
|
20
18
|
export const DEFAULT_MAX_A2UI_SURFACES_PER_RUN = 16;
|
|
21
|
-
export const HARD_MAX_A2UI_SURFACES_PER_RUN = 64;
|
|
22
19
|
export const DEFAULT_MAX_A2UI_COMPONENT_DEPTH = 32;
|
|
23
|
-
export const HARD_MAX_A2UI_COMPONENT_DEPTH = 64;
|
|
24
20
|
|
|
25
21
|
export interface AgUiA2UiLimitOptions {
|
|
26
22
|
readonly maxOperationsPerMessage?: number;
|
|
@@ -62,30 +58,10 @@ export interface AgUiA2UiPainter {
|
|
|
62
58
|
|
|
63
59
|
export function resolveAgUiA2UiLimits(options: AgUiA2UiLimitOptions = {}): ResolvedAgUiA2UiLimits {
|
|
64
60
|
return {
|
|
65
|
-
maxOperationsPerMessage: clamp(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
"maxOperationsPerMessage",
|
|
70
|
-
),
|
|
71
|
-
maxOperationBytes: clamp(
|
|
72
|
-
options.maxOperationBytes ?? DEFAULT_MAX_A2UI_OPERATION_BYTES,
|
|
73
|
-
1_024,
|
|
74
|
-
HARD_MAX_A2UI_OPERATION_BYTES,
|
|
75
|
-
"maxOperationBytes",
|
|
76
|
-
),
|
|
77
|
-
maxSurfacesPerRun: clamp(
|
|
78
|
-
options.maxSurfacesPerRun ?? DEFAULT_MAX_A2UI_SURFACES_PER_RUN,
|
|
79
|
-
1,
|
|
80
|
-
HARD_MAX_A2UI_SURFACES_PER_RUN,
|
|
81
|
-
"maxSurfacesPerRun",
|
|
82
|
-
),
|
|
83
|
-
maxComponentDepth: clamp(
|
|
84
|
-
options.maxComponentDepth ?? DEFAULT_MAX_A2UI_COMPONENT_DEPTH,
|
|
85
|
-
1,
|
|
86
|
-
HARD_MAX_A2UI_COMPONENT_DEPTH,
|
|
87
|
-
"maxComponentDepth",
|
|
88
|
-
),
|
|
61
|
+
maxOperationsPerMessage: clamp(options.maxOperationsPerMessage ?? DEFAULT_MAX_A2UI_OPS_PER_MESSAGE, 1, "maxOperationsPerMessage"),
|
|
62
|
+
maxOperationBytes: clamp(options.maxOperationBytes ?? DEFAULT_MAX_A2UI_OPERATION_BYTES, 1_024, "maxOperationBytes"),
|
|
63
|
+
maxSurfacesPerRun: clamp(options.maxSurfacesPerRun ?? DEFAULT_MAX_A2UI_SURFACES_PER_RUN, 1, "maxSurfacesPerRun"),
|
|
64
|
+
maxComponentDepth: clamp(options.maxComponentDepth ?? DEFAULT_MAX_A2UI_COMPONENT_DEPTH, 1, "maxComponentDepth"),
|
|
89
65
|
};
|
|
90
66
|
}
|
|
91
67
|
|
|
@@ -549,9 +525,10 @@ function jsonDepth(value: unknown, depth = 0): number {
|
|
|
549
525
|
return max;
|
|
550
526
|
}
|
|
551
527
|
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
528
|
+
/** A host-set A2UI limit. The host's value is the cap (plan 239 Task 5); model operations are bounded by it. */
|
|
529
|
+
function clamp(value: number, min: number, name: string): number {
|
|
530
|
+
if (!Number.isSafeInteger(value) || value < min) {
|
|
531
|
+
throw new AgUiError("ERR_PRISM_AG_UI_LIMIT", `${name} must be a safe integer of at least ${min}`);
|
|
555
532
|
}
|
|
556
533
|
return value;
|
|
557
534
|
}
|
|
@@ -54,6 +54,8 @@ export function createAgUiEventMapper(options: AgUiEventMapperOptions = {}): AgU
|
|
|
54
54
|
let activeMessage: string | undefined;
|
|
55
55
|
let activeReasoning: string | undefined;
|
|
56
56
|
let messageHasDelta = false;
|
|
57
|
+
/** Messages a failed attempt left open, named by the next `prism.retry` so a client can drop them. */
|
|
58
|
+
let discarded: string[] = [];
|
|
57
59
|
let messageSequence = 0;
|
|
58
60
|
let reasoningSequence = 0;
|
|
59
61
|
let terminal = false;
|
|
@@ -347,6 +349,21 @@ export function createAgUiEventMapper(options: AgUiEventMapperOptions = {}): AgU
|
|
|
347
349
|
const stepName = `turn:${event.turn}`;
|
|
348
350
|
activeSteps.add(stepName);
|
|
349
351
|
emit(events, { type: EventType.STEP_STARTED, stepName });
|
|
352
|
+
if (event.retry) {
|
|
353
|
+
// AG-UI cannot retract: the failed attempt's messages are already ended, and this names them.
|
|
354
|
+
await custom(events, "prism.retry", {
|
|
355
|
+
turn: event.turn,
|
|
356
|
+
attempt: event.attempt ?? event.metadata.attempt ?? 2,
|
|
357
|
+
delayMs: event.retry.delayMs,
|
|
358
|
+
error: {
|
|
359
|
+
message: text(event.retry.error.message, limits.maxErrorBytes),
|
|
360
|
+
...(event.retry.error.code === undefined ? {} : { code: text(String(event.retry.error.code), limits.maxErrorBytes) }),
|
|
361
|
+
...(event.retry.error.failureClass === undefined ? {} : { failureClass: event.retry.error.failureClass }),
|
|
362
|
+
},
|
|
363
|
+
discardMessageIds: discarded,
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
discarded = [];
|
|
350
367
|
break;
|
|
351
368
|
}
|
|
352
369
|
case "message.delta":
|
|
@@ -428,7 +445,16 @@ export function createAgUiEventMapper(options: AgUiEventMapperOptions = {}): AgU
|
|
|
428
445
|
// The turn step closes on its own completion; the attempt's usage and error ride here too.
|
|
429
446
|
if (activeSteps.delete(`turn:${event.turn}`)) emit(events, { type: EventType.STEP_FINISHED, stepName: `turn:${event.turn}` });
|
|
430
447
|
if (event.usage) await custom(events, "prism.usage", usage(event.usage));
|
|
431
|
-
|
|
448
|
+
// A failed attempt is not the run's end: the run may retry it (plan 227 Task 4), and a final
|
|
449
|
+
// failure arrives as `run.failed`. End what the attempt opened; `prism.retry` names it.
|
|
450
|
+
if (event.error) {
|
|
451
|
+
if (activeReasoning) discarded.push(activeReasoning);
|
|
452
|
+
if (activeMessage) discarded.push(activeMessage);
|
|
453
|
+
closeReasoning(events);
|
|
454
|
+
if (activeMessage) emit(events, { type: EventType.TEXT_MESSAGE_END, messageId: activeMessage });
|
|
455
|
+
activeMessage = undefined;
|
|
456
|
+
messageHasDelta = false;
|
|
457
|
+
}
|
|
432
458
|
break;
|
|
433
459
|
case "compaction.started":
|
|
434
460
|
await custom(events, "prism.compaction", { status: "started" });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AgentEvent, ThinkingContent } from "@arnilo/prism";
|
|
2
2
|
import { truncateUtf8 } from "./ag-ui-mapper.js";
|
|
3
|
-
import { DEFAULT_MAX_REASONING_BYTES
|
|
3
|
+
import { DEFAULT_MAX_REASONING_BYTES } from "./limits.js";
|
|
4
4
|
import type { AgUiReasoningProjection } from "./projection.js";
|
|
5
5
|
|
|
6
6
|
export interface CreateReasoningEncryptedValueOptions {
|
|
@@ -10,7 +10,7 @@ export interface CreateReasoningEncryptedValueOptions {
|
|
|
10
10
|
readonly content: ThinkingContent;
|
|
11
11
|
/** The Prism event carrying the thinking content. */
|
|
12
12
|
readonly event: AgentEvent;
|
|
13
|
-
/** Optional byte cap; defaults to `DEFAULT_MAX_REASONING_BYTES
|
|
13
|
+
/** Optional byte cap; defaults to `DEFAULT_MAX_REASONING_BYTES`. The host's value is the cap. */
|
|
14
14
|
readonly maxBytes?: number;
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -35,6 +35,6 @@ export function createReasoningEncryptedValue(options: CreateReasoningEncryptedV
|
|
|
35
35
|
return undefined;
|
|
36
36
|
}
|
|
37
37
|
if (typeof value !== "string" || value.length === 0) return undefined;
|
|
38
|
-
const maxBytes =
|
|
38
|
+
const maxBytes = options.maxBytes ?? DEFAULT_MAX_REASONING_BYTES;
|
|
39
39
|
return { encryptedValue: truncateUtf8(value, maxBytes) };
|
|
40
40
|
}
|
package/ag-ui/src/handler.ts
CHANGED
|
@@ -28,8 +28,7 @@ const SSE_HEADERS = {
|
|
|
28
28
|
connection: "keep-alive",
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
/**
|
|
32
|
-
const MAX_RESUME_DECISIONS = 128;
|
|
31
|
+
/** Bytes of one resume payload (`{ outcome }`), a wire field; the decision count is bounded by the kernel's pending decisions. */
|
|
33
32
|
const MAX_RESUME_PAYLOAD_BYTES = 64 * 1024;
|
|
34
33
|
const APPROVAL_OUTCOMES: ReadonlySet<string> = new Set(["allow_once", "allow_for_run", "reject_once", "reject_for_run"]);
|
|
35
34
|
|
|
@@ -260,7 +259,7 @@ async function runSource<Authorization extends AgUiAuthorization>(
|
|
|
260
259
|
signal,
|
|
261
260
|
interactive: false,
|
|
262
261
|
maxQueuedEvents: limits.maxQueuedEvents,
|
|
263
|
-
overflow: "
|
|
262
|
+
overflow: "coalesce",
|
|
264
263
|
}),
|
|
265
264
|
session,
|
|
266
265
|
input,
|
|
@@ -325,7 +324,8 @@ function readResumeDecisions(
|
|
|
325
324
|
}
|
|
326
325
|
decisions.push({ approvalId: record.approvalId, outcome: readResumeOutcome(entry.payload) });
|
|
327
326
|
}
|
|
328
|
-
|
|
327
|
+
// Each decision matched a distinct pending interrupt, so the count is bounded by the agent's `ceilings.pendingDecisions`.
|
|
328
|
+
if (decisions.length === 0) {
|
|
329
329
|
throw new AgUiError("ERR_PRISM_AG_UI_INPUT", "Resume decisions must be a non-empty bounded array");
|
|
330
330
|
}
|
|
331
331
|
return decisions;
|
package/ag-ui/src/index.ts
CHANGED
|
@@ -13,10 +13,6 @@ export {
|
|
|
13
13
|
DEFAULT_MAX_A2UI_OPS_PER_MESSAGE,
|
|
14
14
|
DEFAULT_MAX_A2UI_SURFACES_PER_RUN,
|
|
15
15
|
extractAgUiA2UiActions,
|
|
16
|
-
HARD_MAX_A2UI_COMPONENT_DEPTH,
|
|
17
|
-
HARD_MAX_A2UI_OPERATION_BYTES,
|
|
18
|
-
HARD_MAX_A2UI_OPS_PER_MESSAGE,
|
|
19
|
-
HARD_MAX_A2UI_SURFACES_PER_RUN,
|
|
20
16
|
type ResolvedAgUiA2UiLimits,
|
|
21
17
|
resolveAgUiA2UiLimits,
|
|
22
18
|
} from "./a2ui.js";
|
|
@@ -70,34 +66,6 @@ export {
|
|
|
70
66
|
DEFAULT_MAX_STREAM_EVENTS,
|
|
71
67
|
DEFAULT_MAX_TEXT_BYTES,
|
|
72
68
|
DEFAULT_REQUEST_TIMEOUT_MS,
|
|
73
|
-
HARD_AG_UI_LIMITS,
|
|
74
|
-
HARD_MAX_ACTIVITY_BYTES,
|
|
75
|
-
HARD_MAX_CURSOR_BYTES,
|
|
76
|
-
HARD_MAX_ERROR_BYTES,
|
|
77
|
-
HARD_MAX_EVENT_BYTES,
|
|
78
|
-
HARD_MAX_INPUT_CONTEXT_BYTES,
|
|
79
|
-
HARD_MAX_INPUT_CONTEXTS,
|
|
80
|
-
HARD_MAX_INPUT_INTERRUPTS,
|
|
81
|
-
HARD_MAX_INPUT_MEDIA_BYTES,
|
|
82
|
-
HARD_MAX_INPUT_MEDIA_PARTS,
|
|
83
|
-
HARD_MAX_INPUT_MESSAGES,
|
|
84
|
-
HARD_MAX_INPUT_TEXT_BYTES,
|
|
85
|
-
HARD_MAX_INPUT_TOOL_BYTES,
|
|
86
|
-
HARD_MAX_INPUT_TOOLS,
|
|
87
|
-
HARD_MAX_JSON_ARRAY_ITEMS,
|
|
88
|
-
HARD_MAX_JSON_DEPTH,
|
|
89
|
-
HARD_MAX_JSON_PROPERTIES,
|
|
90
|
-
HARD_MAX_PATCH_OPERATIONS,
|
|
91
|
-
HARD_MAX_QUEUED_EVENTS,
|
|
92
|
-
HARD_MAX_RAW_EVENT_BYTES,
|
|
93
|
-
HARD_MAX_REASONING_BYTES,
|
|
94
|
-
HARD_MAX_REPLAY_EVENTS,
|
|
95
|
-
HARD_MAX_REQUEST_BYTES,
|
|
96
|
-
HARD_MAX_STATE_BYTES,
|
|
97
|
-
HARD_MAX_STREAM_BYTES,
|
|
98
|
-
HARD_MAX_STREAM_EVENTS,
|
|
99
|
-
HARD_MAX_TEXT_BYTES,
|
|
100
|
-
HARD_REQUEST_TIMEOUT_MS,
|
|
101
69
|
type ResolvedAgUiLimits,
|
|
102
70
|
resolveAgUiLimits,
|
|
103
71
|
} from "./limits.js";
|
|
@@ -138,7 +106,6 @@ export {
|
|
|
138
106
|
createMessagesFromSessionProjection,
|
|
139
107
|
createStateFromStoreProjection,
|
|
140
108
|
DEFAULT_MAX_PROJECTOR_MESSAGES,
|
|
141
|
-
HARD_MAX_PROJECTOR_MESSAGES,
|
|
142
109
|
jsonDiff,
|
|
143
110
|
} from "./projectors.js";
|
|
144
111
|
// Task 14: reference renderer subpath (@arnilo/prism-hosts/ag-ui/renderer).
|
package/ag-ui/src/limits.ts
CHANGED
|
@@ -2,89 +2,49 @@ import { AgUiError } from "./errors.js";
|
|
|
2
2
|
|
|
3
3
|
/** Phase 7 frozen baseline transport caps. */
|
|
4
4
|
export const DEFAULT_MAX_EVENT_BYTES = 64 * 1024;
|
|
5
|
-
export const HARD_MAX_EVENT_BYTES = 1024 * 1024;
|
|
6
5
|
export const DEFAULT_MAX_TEXT_BYTES = 64 * 1024;
|
|
7
|
-
export const HARD_MAX_TEXT_BYTES = 1024 * 1024;
|
|
8
6
|
export const DEFAULT_MAX_ERROR_BYTES = 8 * 1024;
|
|
9
|
-
export const HARD_MAX_ERROR_BYTES = 64 * 1024;
|
|
10
7
|
export const DEFAULT_MAX_REQUEST_BYTES = 64 * 1024;
|
|
11
|
-
export const HARD_MAX_REQUEST_BYTES = 1024 * 1024;
|
|
12
8
|
export const DEFAULT_MAX_INPUT_MESSAGES = 128;
|
|
13
|
-
export const HARD_MAX_INPUT_MESSAGES = 1024;
|
|
14
9
|
export const DEFAULT_MAX_INPUT_TEXT_BYTES = 64 * 1024;
|
|
15
|
-
export const HARD_MAX_INPUT_TEXT_BYTES = 1024 * 1024;
|
|
16
10
|
export const DEFAULT_MAX_CURSOR_BYTES = 4 * 1024;
|
|
17
|
-
export const HARD_MAX_CURSOR_BYTES = 16 * 1024;
|
|
18
11
|
export const DEFAULT_MAX_REPLAY_EVENTS = 100;
|
|
19
|
-
export const HARD_MAX_REPLAY_EVENTS = 500;
|
|
20
12
|
export const DEFAULT_MAX_STREAM_EVENTS = 10_000;
|
|
21
|
-
export const HARD_MAX_STREAM_EVENTS = 100_000;
|
|
22
13
|
export const DEFAULT_MAX_STREAM_BYTES = 10 * 1024 * 1024;
|
|
23
|
-
export const
|
|
24
|
-
export const DEFAULT_MAX_QUEUED_EVENTS = 128;
|
|
25
|
-
export const HARD_MAX_QUEUED_EVENTS = 4096;
|
|
14
|
+
export const DEFAULT_MAX_QUEUED_EVENTS = 4096;
|
|
26
15
|
export const DEFAULT_REQUEST_TIMEOUT_MS = 120_000;
|
|
27
|
-
export const HARD_REQUEST_TIMEOUT_MS = 30 * 60_000;
|
|
28
16
|
|
|
29
|
-
/** Full AG-UI request/projection caps.
|
|
17
|
+
/** Full AG-UI request/projection caps. The host sets each; clients are bounded by the host's value. */
|
|
30
18
|
export const DEFAULT_MAX_INPUT_TOOLS = 32;
|
|
31
|
-
export const HARD_MAX_INPUT_TOOLS = 256;
|
|
32
19
|
export const DEFAULT_MAX_INPUT_CONTEXTS = 32;
|
|
33
|
-
export const HARD_MAX_INPUT_CONTEXTS = 256;
|
|
34
20
|
export const DEFAULT_MAX_INPUT_INTERRUPTS = 8;
|
|
35
|
-
export const HARD_MAX_INPUT_INTERRUPTS = 64;
|
|
36
21
|
export const DEFAULT_MAX_INPUT_MEDIA_PARTS = 16;
|
|
37
|
-
export const HARD_MAX_INPUT_MEDIA_PARTS = 64;
|
|
38
22
|
export const DEFAULT_MAX_INPUT_MEDIA_BYTES = 64 * 1024;
|
|
39
|
-
export const HARD_MAX_INPUT_MEDIA_BYTES = 1024 * 1024;
|
|
40
23
|
export const DEFAULT_MAX_INPUT_TOOL_BYTES = 16 * 1024;
|
|
41
|
-
export const HARD_MAX_INPUT_TOOL_BYTES = 256 * 1024;
|
|
42
24
|
export const DEFAULT_MAX_INPUT_CONTEXT_BYTES = 16 * 1024;
|
|
43
|
-
export const HARD_MAX_INPUT_CONTEXT_BYTES = 256 * 1024;
|
|
44
25
|
export const DEFAULT_MAX_STATE_BYTES = 64 * 1024;
|
|
45
|
-
export const HARD_MAX_STATE_BYTES = 1024 * 1024;
|
|
46
26
|
export const DEFAULT_MAX_PATCH_OPERATIONS = 128;
|
|
47
|
-
export const HARD_MAX_PATCH_OPERATIONS = 4096;
|
|
48
27
|
export const DEFAULT_MAX_ACTIVITY_BYTES = 64 * 1024;
|
|
49
|
-
export const HARD_MAX_ACTIVITY_BYTES = 1024 * 1024;
|
|
50
28
|
export const DEFAULT_MAX_REASONING_BYTES = 64 * 1024;
|
|
51
|
-
export const HARD_MAX_REASONING_BYTES = 1024 * 1024;
|
|
52
29
|
export const DEFAULT_MAX_RAW_EVENT_BYTES = 64 * 1024;
|
|
53
|
-
export const HARD_MAX_RAW_EVENT_BYTES = 1024 * 1024;
|
|
54
30
|
export const DEFAULT_MAX_JSON_DEPTH = 16;
|
|
55
|
-
export const HARD_MAX_JSON_DEPTH = 64;
|
|
56
31
|
export const DEFAULT_MAX_JSON_PROPERTIES = 128;
|
|
57
|
-
export const HARD_MAX_JSON_PROPERTIES = 4096;
|
|
58
32
|
export const DEFAULT_MAX_JSON_ARRAY_ITEMS = 512;
|
|
59
|
-
export const HARD_MAX_JSON_ARRAY_ITEMS = 8192;
|
|
60
33
|
|
|
61
34
|
/** Phase 10 frozen ACP session-lifecycle caps (scripts/phase10-freeze-manifest.json caps.acp). */
|
|
62
35
|
export const DEFAULT_MAX_ACP_SESSIONS = 32;
|
|
63
|
-
export const HARD_MAX_ACP_SESSIONS = 128;
|
|
64
36
|
export const DEFAULT_MAX_ACP_ADDITIONAL_DIRECTORIES = 8;
|
|
65
|
-
export const HARD_MAX_ACP_ADDITIONAL_DIRECTORIES = 32;
|
|
66
37
|
export const DEFAULT_MAX_ACP_ADDITIONAL_DIRECTORY_PATH_BYTES = 4 * 1024;
|
|
67
|
-
export const HARD_MAX_ACP_ADDITIONAL_DIRECTORY_PATH_BYTES = 16 * 1024;
|
|
68
38
|
export const DEFAULT_MAX_ACP_MCP_SERVERS_PER_SESSION = 8;
|
|
69
|
-
export const HARD_MAX_ACP_MCP_SERVERS_PER_SESSION = 32;
|
|
70
39
|
export const DEFAULT_MAX_ACP_MCP_SERVER_CONFIG_BYTES = 16 * 1024;
|
|
71
|
-
export const HARD_MAX_ACP_MCP_SERVER_CONFIG_BYTES = 256 * 1024;
|
|
72
40
|
export const DEFAULT_MAX_ACP_MCP_HEADER_VALUE_BYTES = 4 * 1024;
|
|
73
|
-
export const HARD_MAX_ACP_MCP_HEADER_VALUE_BYTES = 64 * 1024;
|
|
74
41
|
export const DEFAULT_MAX_ACP_SESSION_LIST_PAGE = 20;
|
|
75
|
-
export const HARD_MAX_ACP_SESSION_LIST_PAGE = 100;
|
|
76
42
|
export const DEFAULT_MAX_ACP_MODES_PER_SESSION = 16;
|
|
77
|
-
export const HARD_MAX_ACP_MODES_PER_SESSION = 64;
|
|
78
43
|
export const DEFAULT_MAX_ACP_CONFIG_OPTIONS = 16;
|
|
79
|
-
export const HARD_MAX_ACP_CONFIG_OPTIONS = 64;
|
|
80
44
|
export const DEFAULT_MAX_ACP_DIFF_BYTES = 64 * 1024;
|
|
81
|
-
export const HARD_MAX_ACP_DIFF_BYTES = 1024 * 1024;
|
|
82
45
|
export const DEFAULT_MAX_ACP_LOCATIONS_PER_UPDATE = 32;
|
|
83
|
-
export const HARD_MAX_ACP_LOCATIONS_PER_UPDATE = 128;
|
|
84
46
|
export const DEFAULT_MAX_ACP_IMAGE_BYTES = 256 * 1024;
|
|
85
|
-
export const HARD_MAX_ACP_IMAGE_BYTES = 1024 * 1024;
|
|
86
47
|
export const DEFAULT_MAX_ACP_COMMANDS_PER_UPDATE = 32;
|
|
87
|
-
export const HARD_MAX_ACP_COMMANDS_PER_UPDATE = 128;
|
|
88
48
|
|
|
89
49
|
export interface AgUiLimitOptions {
|
|
90
50
|
readonly maxEventBytes?: number;
|
|
@@ -216,49 +176,6 @@ export const DEFAULT_AG_UI_LIMITS: ResolvedAgUiLimits = {
|
|
|
216
176
|
acpCommandsPerUpdate: DEFAULT_MAX_ACP_COMMANDS_PER_UPDATE,
|
|
217
177
|
};
|
|
218
178
|
|
|
219
|
-
export const HARD_AG_UI_LIMITS: ResolvedAgUiLimits = {
|
|
220
|
-
maxEventBytes: HARD_MAX_EVENT_BYTES,
|
|
221
|
-
maxTextBytes: HARD_MAX_TEXT_BYTES,
|
|
222
|
-
maxErrorBytes: HARD_MAX_ERROR_BYTES,
|
|
223
|
-
maxRequestBytes: HARD_MAX_REQUEST_BYTES,
|
|
224
|
-
maxInputMessages: HARD_MAX_INPUT_MESSAGES,
|
|
225
|
-
maxInputTextBytes: HARD_MAX_INPUT_TEXT_BYTES,
|
|
226
|
-
maxCursorBytes: HARD_MAX_CURSOR_BYTES,
|
|
227
|
-
maxReplayEvents: HARD_MAX_REPLAY_EVENTS,
|
|
228
|
-
maxStreamEvents: HARD_MAX_STREAM_EVENTS,
|
|
229
|
-
maxStreamBytes: HARD_MAX_STREAM_BYTES,
|
|
230
|
-
maxQueuedEvents: HARD_MAX_QUEUED_EVENTS,
|
|
231
|
-
requestTimeoutMs: HARD_REQUEST_TIMEOUT_MS,
|
|
232
|
-
maxInputTools: HARD_MAX_INPUT_TOOLS,
|
|
233
|
-
maxInputContexts: HARD_MAX_INPUT_CONTEXTS,
|
|
234
|
-
maxInputInterrupts: HARD_MAX_INPUT_INTERRUPTS,
|
|
235
|
-
maxInputMediaParts: HARD_MAX_INPUT_MEDIA_PARTS,
|
|
236
|
-
maxInputMediaBytes: HARD_MAX_INPUT_MEDIA_BYTES,
|
|
237
|
-
maxInputToolBytes: HARD_MAX_INPUT_TOOL_BYTES,
|
|
238
|
-
maxInputContextBytes: HARD_MAX_INPUT_CONTEXT_BYTES,
|
|
239
|
-
maxStateBytes: HARD_MAX_STATE_BYTES,
|
|
240
|
-
maxPatchOperations: HARD_MAX_PATCH_OPERATIONS,
|
|
241
|
-
maxActivityBytes: HARD_MAX_ACTIVITY_BYTES,
|
|
242
|
-
maxReasoningBytes: HARD_MAX_REASONING_BYTES,
|
|
243
|
-
maxRawEventBytes: HARD_MAX_RAW_EVENT_BYTES,
|
|
244
|
-
maxJsonDepth: HARD_MAX_JSON_DEPTH,
|
|
245
|
-
maxJsonProperties: HARD_MAX_JSON_PROPERTIES,
|
|
246
|
-
maxJsonArrayItems: HARD_MAX_JSON_ARRAY_ITEMS,
|
|
247
|
-
acpSessions: HARD_MAX_ACP_SESSIONS,
|
|
248
|
-
acpAdditionalDirectories: HARD_MAX_ACP_ADDITIONAL_DIRECTORIES,
|
|
249
|
-
acpAdditionalDirectoryPathBytes: HARD_MAX_ACP_ADDITIONAL_DIRECTORY_PATH_BYTES,
|
|
250
|
-
acpMcpServersPerSession: HARD_MAX_ACP_MCP_SERVERS_PER_SESSION,
|
|
251
|
-
acpMcpServerConfigBytes: HARD_MAX_ACP_MCP_SERVER_CONFIG_BYTES,
|
|
252
|
-
acpMcpHeaderValueBytes: HARD_MAX_ACP_MCP_HEADER_VALUE_BYTES,
|
|
253
|
-
acpSessionListPage: HARD_MAX_ACP_SESSION_LIST_PAGE,
|
|
254
|
-
acpModesPerSession: HARD_MAX_ACP_MODES_PER_SESSION,
|
|
255
|
-
acpConfigOptions: HARD_MAX_ACP_CONFIG_OPTIONS,
|
|
256
|
-
acpDiffBytes: HARD_MAX_ACP_DIFF_BYTES,
|
|
257
|
-
acpLocationsPerUpdate: HARD_MAX_ACP_LOCATIONS_PER_UPDATE,
|
|
258
|
-
acpImageBytes: HARD_MAX_ACP_IMAGE_BYTES,
|
|
259
|
-
acpCommandsPerUpdate: HARD_MAX_ACP_COMMANDS_PER_UPDATE,
|
|
260
|
-
};
|
|
261
|
-
|
|
262
179
|
export function resolveAgUiLimits(options: AgUiLimitOptions = {}): ResolvedAgUiLimits {
|
|
263
180
|
return Object.fromEntries(
|
|
264
181
|
Object.entries(DEFAULT_AG_UI_LIMITS).map(([name, defaultValue]) => [
|
|
@@ -268,12 +185,12 @@ export function resolveAgUiLimits(options: AgUiLimitOptions = {}): ResolvedAgUiL
|
|
|
268
185
|
) as unknown as ResolvedAgUiLimits;
|
|
269
186
|
}
|
|
270
187
|
|
|
188
|
+
/** A host-set AG-UI limit. The host's value is the cap (plan 239 Task 5); clients are bounded by it. */
|
|
271
189
|
function validate(name: keyof ResolvedAgUiLimits, value: number): number {
|
|
272
|
-
const hard = HARD_AG_UI_LIMITS[name];
|
|
273
190
|
const minimum =
|
|
274
191
|
name.endsWith("Bytes") || name === "requestTimeoutMs" ? (name === "maxTextBytes" || name === "maxErrorBytes" ? 16 : 1_024) : 1;
|
|
275
|
-
if (!Number.isSafeInteger(value) || value < minimum
|
|
276
|
-
throw new AgUiError("ERR_PRISM_AG_UI_LIMIT", `${name} must be a safe integer
|
|
192
|
+
if (!Number.isSafeInteger(value) || value < minimum) {
|
|
193
|
+
throw new AgUiError("ERR_PRISM_AG_UI_LIMIT", `${name} must be a safe integer of at least ${minimum}`);
|
|
277
194
|
}
|
|
278
195
|
return value;
|
|
279
196
|
}
|
package/ag-ui/src/projectors.ts
CHANGED
|
@@ -2,9 +2,11 @@ import type { Message as AgUiMessage } from "@ag-ui/core";
|
|
|
2
2
|
import type { AgentEvent } from "@arnilo/prism";
|
|
3
3
|
import type { AgUiProjection } from "./projection.js";
|
|
4
4
|
|
|
5
|
+
const DEFAULT_MAX_STATE_BYTES = 64 * 1024;
|
|
6
|
+
const DEFAULT_MAX_PATCH_OPERATIONS = 128;
|
|
7
|
+
|
|
5
8
|
/** Default / hard caps for standard message projectors (Task 0 freeze). */
|
|
6
9
|
export const DEFAULT_MAX_PROJECTOR_MESSAGES = 128;
|
|
7
|
-
export const HARD_MAX_PROJECTOR_MESSAGES = 1024;
|
|
8
10
|
|
|
9
11
|
/** Host-owned run-state snapshot source. Prism starts no watcher. */
|
|
10
12
|
export interface AgUiStateStore {
|
|
@@ -36,7 +38,7 @@ export interface CreateActivityFromToolProgressProjectionOptions {
|
|
|
36
38
|
* (host `getMessages`) or when the live stream finishes a message.
|
|
37
39
|
*/
|
|
38
40
|
export function createMessagesFromSessionProjection(options: CreateMessagesFromSessionProjectionOptions = {}): AgUiProjection {
|
|
39
|
-
const maxMessages = clamp(options.maxMessages, DEFAULT_MAX_PROJECTOR_MESSAGES
|
|
41
|
+
const maxMessages = clamp(options.maxMessages, DEFAULT_MAX_PROJECTOR_MESSAGES);
|
|
40
42
|
const accumulated: AgUiMessage[] = [];
|
|
41
43
|
let lastKey: string | undefined;
|
|
42
44
|
|
|
@@ -84,8 +86,8 @@ export function createMessagesFromSessionProjection(options: CreateMessagesFromS
|
|
|
84
86
|
* Prism starts no background watcher.
|
|
85
87
|
*/
|
|
86
88
|
export function createStateFromStoreProjection(store: AgUiStateStore, options: CreateStateFromStoreProjectionOptions = {}): AgUiProjection {
|
|
87
|
-
const maxBytes = options.maxStateBytes ??
|
|
88
|
-
const maxOps = options.maxPatchOperations ??
|
|
89
|
+
const maxBytes = options.maxStateBytes ?? DEFAULT_MAX_STATE_BYTES;
|
|
90
|
+
const maxOps = options.maxPatchOperations ?? DEFAULT_MAX_PATCH_OPERATIONS;
|
|
89
91
|
let last: unknown;
|
|
90
92
|
let snapped = false;
|
|
91
93
|
let dirty = true;
|
|
@@ -265,8 +267,8 @@ function withinBytes(value: unknown, maxBytes: number): boolean {
|
|
|
265
267
|
}
|
|
266
268
|
}
|
|
267
269
|
|
|
268
|
-
function clamp(value: number | undefined, fallback: number
|
|
270
|
+
function clamp(value: number | undefined, fallback: number): number {
|
|
269
271
|
if (value === undefined) return fallback;
|
|
270
272
|
if (!Number.isFinite(value) || value < 1) return fallback;
|
|
271
|
-
return Math.
|
|
273
|
+
return Math.floor(value);
|
|
272
274
|
}
|
|
@@ -45,7 +45,8 @@ export interface RenderA2UiSurfaceOptions {
|
|
|
45
45
|
readonly onAction?: (action: AgUiA2UiAction) => void;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
/** Recursion bound of the client-side renderer; a host that raises `maxComponentDepth` above it gets a flattened tail. */
|
|
49
|
+
const MAX_RENDER_DEPTH = 64;
|
|
49
50
|
|
|
50
51
|
/** Render one surface model into a detached DOM node. */
|
|
51
52
|
export function renderA2UiSurface(
|