@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.
Files changed (127) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/a2a/README.md +195 -0
  3. package/a2a/src/card.ts +208 -0
  4. package/a2a/src/codec.ts +523 -0
  5. package/a2a/src/connect.ts +415 -0
  6. package/a2a/src/errors.ts +87 -0
  7. package/a2a/src/index.ts +40 -0
  8. package/a2a/src/limits.ts +43 -0
  9. package/a2a/src/pending.ts +28 -0
  10. package/a2a/src/proxy.ts +526 -0
  11. package/a2a/src/serve.ts +886 -0
  12. package/acp/README.md +3 -1
  13. package/acp/src/limits.ts +3 -16
  14. package/acp/src/mapper.ts +26 -5
  15. package/acp/src/serve.ts +6 -5
  16. package/ag-ui/README.md +2 -1
  17. package/ag-ui/src/a2ui.ts +8 -31
  18. package/ag-ui/src/ag-ui-mapper.ts +27 -1
  19. package/ag-ui/src/encrypted-value.ts +3 -3
  20. package/ag-ui/src/handler.ts +4 -4
  21. package/ag-ui/src/index.ts +0 -33
  22. package/ag-ui/src/limits.ts +5 -88
  23. package/ag-ui/src/projectors.ts +8 -6
  24. package/ag-ui/src/renderer/bind.ts +2 -1
  25. package/channels/README.md +61 -5
  26. package/channels/src/discord-gateway.ts +354 -0
  27. package/channels/src/discord.ts +873 -0
  28. package/channels/src/index.ts +4 -2
  29. package/channels/src/limits.ts +3 -19
  30. package/channels/src/pairing.ts +1 -2
  31. package/channels/src/runtime-turn.ts +10 -2
  32. package/channels/src/signal.ts +11 -19
  33. package/channels/src/slack.ts +854 -0
  34. package/channels/src/telegram.ts +22 -44
  35. package/channels/src/types.ts +5 -2
  36. package/devtools/README.md +1 -1
  37. package/driver-process/src/driver.ts +3 -1
  38. package/driver-process/src/testing.ts +1 -1
  39. package/driver-process/src/turn.ts +5 -1
  40. package/evals/README.md +11 -7
  41. package/evals/src/calibration.ts +5 -13
  42. package/evals/src/compare-experiments.ts +1 -2
  43. package/evals/src/comparison.ts +7 -25
  44. package/evals/src/curate.ts +3 -9
  45. package/evals/src/dataset.ts +0 -2
  46. package/evals/src/index.ts +3 -20
  47. package/evals/src/injection.ts +33 -6
  48. package/evals/src/judge.ts +9 -13
  49. package/evals/src/limits.ts +0 -17
  50. package/evals/src/rubric-judge.ts +5 -10
  51. package/evals/src/scenario-runner.ts +8 -4
  52. package/evals/src/scenarios.ts +5 -5
  53. package/evals/src/score.ts +3 -5
  54. package/evals/src/stats.ts +0 -2
  55. package/evals/src/threshold.ts +3 -3
  56. package/evals/src/toolless-session.ts +7 -3
  57. package/evals/src/trace.ts +8 -14
  58. package/evals/src/trajectory.ts +45 -11
  59. package/evals/src/types.ts +2 -2
  60. package/evals/src/user-simulator.ts +1 -7
  61. package/evals/src/util.ts +3 -9
  62. package/headless/README.md +20 -1
  63. package/headless/src/authority.ts +14 -1
  64. package/headless/src/errors.ts +3 -1
  65. package/headless/src/index.ts +10 -1
  66. package/headless/src/limits.ts +2 -2
  67. package/headless/src/pending.ts +4 -3
  68. package/headless/src/recover.ts +126 -0
  69. package/headless/src/resume.ts +1 -1
  70. package/host-builder/data/api.json +1308 -1367
  71. package/host-builder/data/errors.json +207 -181
  72. package/host-builder/data/examples/a2a-client.ts +125 -0
  73. package/host-builder/data/examples/a2a-server.ts +133 -0
  74. package/host-builder/data/examples/autonomous-coding-loop.ts +1 -1
  75. package/host-builder/data/examples/build-workflow.ts +2 -2
  76. package/host-builder/data/examples/caveman-ponytail.ts +1 -1
  77. package/host-builder/data/examples/channel-discord.ts +176 -0
  78. package/host-builder/data/examples/channel-slack.ts +146 -0
  79. package/host-builder/data/examples/continue-after-failure.ts +80 -0
  80. package/host-builder/data/examples/custom-adapter.ts +1 -1
  81. package/host-builder/data/examples/decision-models.ts +1 -1
  82. package/host-builder/data/examples/define-package.ts +1 -1
  83. package/host-builder/data/examples/delegate.ts +74 -9
  84. package/host-builder/data/examples/durable-loops-and-approvals.ts +11 -10
  85. package/host-builder/data/examples/governance-deny.ts +1 -1
  86. package/host-builder/data/examples/guardrail-content.ts +126 -0
  87. package/host-builder/data/examples/headless-host.ts +1 -1
  88. package/host-builder/data/examples/long-running-job.ts +129 -0
  89. package/host-builder/data/examples/long-term-memory.ts +1 -1
  90. package/host-builder/data/examples/mcp-oauth.ts +197 -0
  91. package/host-builder/data/examples/mcp-trust.ts +1 -1
  92. package/host-builder/data/examples/memory-and-wiki.ts +3 -3
  93. package/host-builder/data/examples/memory-system.ts +31 -18
  94. package/host-builder/data/examples/model-router-aggregate-budgets.ts +1 -1
  95. package/host-builder/data/examples/parallel-tools.ts +70 -0
  96. package/host-builder/data/examples/remote-agent.ts +1 -1
  97. package/host-builder/data/examples/serve-tools.ts +1 -1
  98. package/host-builder/data/examples/session-memory.ts +29 -26
  99. package/host-builder/data/examples/side-call.ts +9 -5
  100. package/host-builder/data/examples/sqlite-resume.ts +1 -1
  101. package/host-builder/data/examples/structured-output.ts +57 -0
  102. package/host-builder/data/examples.json +15 -5
  103. package/host-builder/skills/prism-host-builder/SKILL.md +1 -1
  104. package/host-builder/skills/prism-host-builder/references/choosing.md +14 -10
  105. package/host-builder/skills/prism-host-builder/references/pitfalls.md +5 -3
  106. package/host-builder/skills/prism-host-builder/references/recipes.md +5 -5
  107. package/host-builder/skills/prism-host-builder/references/verification.md +1 -1
  108. package/host-builder/src/check/runner.ts +2 -3
  109. package/host-builder/src/server.ts +2 -2
  110. package/mcp-server/README.md +3 -3
  111. package/mcp-server/src/bounds.ts +3 -3
  112. package/mcp-server/src/serve-tools.ts +2 -9
  113. package/mcp-server/src/serve.ts +2 -4
  114. package/mcp-server/src/server.ts +10 -20
  115. package/package.json +12 -6
  116. package/remote/README.md +7 -4
  117. package/remote/src/channel.ts +6 -2
  118. package/remote/src/connect.ts +9 -3
  119. package/remote/src/errors.ts +3 -1
  120. package/remote/src/limits.ts +3 -13
  121. package/remote/src/mirror.ts +2 -1
  122. package/remote/src/pending.ts +4 -3
  123. package/remote/src/protocol.ts +3 -0
  124. package/remote/src/serve.ts +43 -5
  125. package/remote/src/session-proxy.ts +28 -5
  126. package/remote/src/testing.ts +3 -1
  127. package/remote/src/wire.ts +74 -14
@@ -1,6 +1,6 @@
1
1
  export type { ChannelDeliveryJournal, ChannelDeliveryJournalOptions, ChannelReplyKeyInput } from "./delivery.js";
2
2
  export { createChannelDeliveryJournal, emptyPruneResult, isSettledReply } from "./delivery.js";
3
- export { DEFAULT_CHANNEL_LIMITS, HARD_CHANNEL_LIMITS, resolveChannelLimits } from "./limits.js";
3
+ export { DEFAULT_CHANNEL_LIMITS, resolveChannelLimits } from "./limits.js";
4
4
  export type {
5
5
  ChannelPairingConsumption,
6
6
  ChannelPairingGrant,
@@ -10,7 +10,7 @@ export type {
10
10
  ConsumeChannelPairingInput,
11
11
  CreateChannelPairingInput,
12
12
  } from "./pairing.js";
13
- export { createChannelPairingStore, DEFAULT_PAIRING_TTL_MS, HARD_PAIRING_TTL_MS } from "./pairing.js";
13
+ export { createChannelPairingStore, DEFAULT_PAIRING_TTL_MS } from "./pairing.js";
14
14
  export type { ChannelApprovalStore } from "./approvals.js";
15
15
  export { createChannelApprovalStore } from "./approvals.js";
16
16
  export { createMemoryCheckpointStore, createMemoryLeaseStore } from "./memory-stores.js";
@@ -78,5 +78,7 @@ export type {
78
78
  } from "./types.js";
79
79
  export { connectTelegram, type TelegramConnectOptions } from "./telegram.js";
80
80
  export { connectSignal, type SignalConnectOptions } from "./signal.js";
81
+ export { connectSlack, type SlackConnectOptions } from "./slack.js";
82
+ export { connectDiscord, type DiscordConnectOptions } from "./discord.js";
81
83
 
82
84
  export { channelHostUi, type ChannelHostUiOptions } from "./host-ui.js";
@@ -19,29 +19,13 @@ export const DEFAULT_CHANNEL_LIMITS: ResolvedChannelLimits = {
19
19
  maxAttachmentBytes: 1024 * 1024,
20
20
  };
21
21
 
22
- export const HARD_CHANNEL_LIMITS: ResolvedChannelLimits = {
23
- maxInputBytes: 64 * 1024,
24
- maxResponseBytes: 128 * 1024,
25
- maxPendingPerBinding: 32,
26
- maxPendingPerProcess: 500,
27
- maxActiveSessions: 16,
28
- maxRoutes: 10_000,
29
- maxSeenEventsPerConnection: 10_000,
30
- stopDeadlineMs: 5 * 60_000,
31
- retentionDays: 90,
32
- maxJournalPage: 500,
33
- maxJournalRecordBytes: 512 * 1024,
34
- leaseTtlMs: 5 * 60_000,
35
- approvalTtlMs: 5 * 60_000,
36
- maxAttachmentBytes: 4 * 1024 * 1024,
37
- };
38
-
39
22
  export function resolveChannelLimits(input: ChannelLimits = {}): ResolvedChannelLimits {
40
23
  const out = {} as Record<keyof ResolvedChannelLimits, number>;
41
24
  for (const key of Object.keys(DEFAULT_CHANNEL_LIMITS) as (keyof ResolvedChannelLimits)[]) {
42
25
  const value = input[key] ?? DEFAULT_CHANNEL_LIMITS[key];
43
- if (!Number.isFinite(value) || value < 1 || value > HARD_CHANNEL_LIMITS[key]) {
44
- throw new TypeError(`Channel limit ${key} must be a positive number no greater than ${HARD_CHANNEL_LIMITS[key]}`);
26
+ // Host-set: the host's value is the cap (plan 239 Task 5).
27
+ if (!Number.isFinite(value) || value < 1) {
28
+ throw new TypeError(`Channel limit ${key} must be a positive number`);
45
29
  }
46
30
  out[key] = value;
47
31
  }
@@ -9,7 +9,6 @@ import { CHANNEL_JOURNAL_NAMESPACES } from "./state.js";
9
9
 
10
10
  /** Review section 6: 5 minutes, host-tightenable, never longer. */
11
11
  export const DEFAULT_PAIRING_TTL_MS = 5 * 60_000;
12
- export const HARD_PAIRING_TTL_MS = 5 * 60_000;
13
12
  const TOKEN_BYTES = 32;
14
13
 
15
14
  export interface ChannelPairingRecord {
@@ -121,7 +120,7 @@ export function createChannelPairingStore(options: ChannelPairingStoreOptions):
121
120
  return r;
122
121
  },
123
122
  async create(input) {
124
- const ttl = Math.min(Math.max(1_000, input.ttlMs ?? DEFAULT_PAIRING_TTL_MS), HARD_PAIRING_TTL_MS);
123
+ const ttl = Math.max(1_000, input.ttlMs ?? DEFAULT_PAIRING_TTL_MS);
125
124
  const now = input.now ?? new Date().toISOString();
126
125
  const token = randomBytes(TOKEN_BYTES).toString("base64url");
127
126
  const record: ChannelPairingRecord = {
@@ -389,19 +389,27 @@ export function createRuntimeTurn(ctx: RuntimeContext, core: RuntimeCore) {
389
389
 
390
390
  /**
391
391
  * Assistant-text preview accumulator for one turn: cumulative, redacted, never journaled and
392
- * never allowed to fail the turn. Resets on each new assistant message so a tool-call preamble
393
- * does not leak into the preview of the answer that follows it.
392
+ * never allowed to fail the turn. Resets on each new run. A provider attempt that ends with
393
+ * `error` drops its text (plan 227 Task 4: the run may retry it), so the next delta's cumulative
394
+ * preview replaces the failed attempt's.
394
395
  */
395
396
  function createPreview(route: RouteState, isLive: () => boolean): (event: AgentEvent) => void {
396
397
  const onDelta = options.onAssistantDelta;
397
398
  if (onDelta === undefined) return () => undefined;
398
399
  let runId: string | undefined;
399
400
  let text = "";
401
+ let attemptStart = "";
400
402
  return (event) => {
401
403
  // A new run resets the preview: `run.started` replaces the retired message-start event.
402
404
  if (event.type === "run.started") {
403
405
  runId = event.runId;
404
406
  text = "";
407
+ attemptStart = "";
408
+ return;
409
+ }
410
+ if ((event.type === "turn.started" || event.type === "turn.completed") && (runId === undefined || event.runId === runId)) {
411
+ if (event.type === "turn.started") attemptStart = text;
412
+ else if (event.error) text = attemptStart;
405
413
  return;
406
414
  }
407
415
  if (event.type !== "message.delta" || event.content.type !== "text") return;
@@ -26,11 +26,8 @@ export type { ChannelConnectionHandle };
26
26
  export const SIGNAL_CLI_VERSION = "0.14.8";
27
27
 
28
28
  const DEFAULT_FRAME_BYTES = 128 * 1024;
29
- const HARD_FRAME_BYTES = 512 * 1024;
30
29
  const DEFAULT_PENDING_REQUESTS = 16;
31
- const HARD_PENDING_REQUESTS = 64;
32
30
  const DEFAULT_PENDING_EVENTS = 32;
33
- const HARD_PENDING_EVENTS = 128;
34
31
  const DEFAULT_REQUEST_TIMEOUT_MS = 10_000;
35
32
  const DEFAULT_RECONNECT_DELAY_MS = 1_000;
36
33
  const DEFAULT_MAX_RECONNECT_DELAY_MS = 30_000;
@@ -146,10 +143,11 @@ function asRecord(value: unknown): Record<string, unknown> | undefined {
146
143
  return typeof value === "object" && value !== null && !Array.isArray(value) ? (value as Record<string, unknown>) : undefined;
147
144
  }
148
145
 
149
- function bounded(value: number | undefined, fallback: number, min: number, max: number, name: string): number {
146
+ /** A host-set Signal limit, at least `min`. The host's value is the cap (plan 239 Task 5). */
147
+ function bounded(value: number | undefined, fallback: number, min: number, name: string): number {
150
148
  const resolved = value ?? fallback;
151
- if (!Number.isSafeInteger(resolved) || resolved < min || resolved > max) {
152
- throw new TypeError(`Signal ${name} must be an integer between ${min} and ${max}`);
149
+ if (!Number.isSafeInteger(resolved) || resolved < min) {
150
+ throw new TypeError(`Signal ${name} must be an integer of at least ${min}`);
153
151
  }
154
152
  return resolved;
155
153
  }
@@ -318,19 +316,13 @@ function validateOptions(options: SignalAdapterOptions): void {
318
316
  */
319
317
  export function createSignalAdapter(options: SignalAdapterOptions): SignalAdapter {
320
318
  validateOptions(options);
321
- const maxFrameBytes = bounded(options.maxFrameBytes, DEFAULT_FRAME_BYTES, 1024, HARD_FRAME_BYTES, "maxFrameBytes");
322
- const maxPendingRequests = bounded(options.maxPendingRequests, DEFAULT_PENDING_REQUESTS, 1, HARD_PENDING_REQUESTS, "maxPendingRequests");
323
- const maxPendingEvents = bounded(options.maxPendingEvents, DEFAULT_PENDING_EVENTS, 1, HARD_PENDING_EVENTS, "maxPendingEvents");
324
- const requestTimeoutMs = bounded(options.requestTimeoutMs, DEFAULT_REQUEST_TIMEOUT_MS, 100, 60_000, "requestTimeoutMs");
325
- const reconnectDelayMs = bounded(options.reconnectDelayMs, DEFAULT_RECONNECT_DELAY_MS, 1, 60_000, "reconnectDelayMs");
326
- const maxReconnectDelayMs = bounded(
327
- options.maxReconnectDelayMs,
328
- DEFAULT_MAX_RECONNECT_DELAY_MS,
329
- reconnectDelayMs,
330
- 60_000,
331
- "maxReconnectDelayMs",
332
- );
333
- const leaseTtlMs = bounded(options.leaseTtlMs, DEFAULT_LEASE_TTL_MS, 5_000, 300_000, "leaseTtlMs");
319
+ const maxFrameBytes = bounded(options.maxFrameBytes, DEFAULT_FRAME_BYTES, 1024, "maxFrameBytes");
320
+ const maxPendingRequests = bounded(options.maxPendingRequests, DEFAULT_PENDING_REQUESTS, 1, "maxPendingRequests");
321
+ const maxPendingEvents = bounded(options.maxPendingEvents, DEFAULT_PENDING_EVENTS, 1, "maxPendingEvents");
322
+ const requestTimeoutMs = bounded(options.requestTimeoutMs, DEFAULT_REQUEST_TIMEOUT_MS, 100, "requestTimeoutMs");
323
+ const reconnectDelayMs = bounded(options.reconnectDelayMs, DEFAULT_RECONNECT_DELAY_MS, 1, "reconnectDelayMs");
324
+ const maxReconnectDelayMs = bounded(options.maxReconnectDelayMs, DEFAULT_MAX_RECONNECT_DELAY_MS, reconnectDelayMs, "maxReconnectDelayMs");
325
+ const leaseTtlMs = bounded(options.leaseTtlMs, DEFAULT_LEASE_TTL_MS, 5_000, "leaseTtlMs");
334
326
  const ownerId = `signal-receiver-${randomUUID()}`;
335
327
  const connect = options.connect ?? ((socketPath: string) => createConnection(socketPath));
336
328
  const pending = new Map<string, Pending>();