stitchkit 0.68.11 → 0.70.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 (125) hide show
  1. package/README.md +30 -1
  2. package/dist/agent-runtime/coding-tool-contract.d.ts +156 -0
  3. package/dist/agent-runtime/coding-tool-contract.d.ts.map +1 -0
  4. package/dist/agent-runtime/coding-tool-files.d.ts +3 -0
  5. package/dist/agent-runtime/coding-tool-files.d.ts.map +1 -0
  6. package/dist/agent-runtime/coding-tool-paths.d.ts +20 -0
  7. package/dist/agent-runtime/coding-tool-paths.d.ts.map +1 -0
  8. package/dist/agent-runtime/coding-tool-search-patch.d.ts +3 -0
  9. package/dist/agent-runtime/coding-tool-search-patch.d.ts.map +1 -0
  10. package/dist/agent-runtime/coding-tool-shell.d.ts +3 -0
  11. package/dist/agent-runtime/coding-tool-shell.d.ts.map +1 -0
  12. package/dist/agent-runtime/coding-tools.d.ts +17 -0
  13. package/dist/agent-runtime/coding-tools.d.ts.map +1 -0
  14. package/dist/agent-runtime/compaction.d.ts +2 -0
  15. package/dist/agent-runtime/compaction.d.ts.map +1 -1
  16. package/dist/agent-runtime/contained-files.d.ts +56 -0
  17. package/dist/agent-runtime/contained-files.d.ts.map +1 -0
  18. package/dist/agent-runtime/control-schema.d.ts +1074 -0
  19. package/dist/agent-runtime/control-schema.d.ts.map +1 -0
  20. package/dist/agent-runtime/conversations.d.ts +128 -0
  21. package/dist/agent-runtime/conversations.d.ts.map +1 -0
  22. package/dist/agent-runtime/event-schema.d.ts +96 -0
  23. package/dist/agent-runtime/event-schema.d.ts.map +1 -1
  24. package/dist/agent-runtime/harness-contract.d.ts +169 -0
  25. package/dist/agent-runtime/harness-contract.d.ts.map +1 -0
  26. package/dist/agent-runtime/harness-control.d.ts +25 -0
  27. package/dist/agent-runtime/harness-control.d.ts.map +1 -0
  28. package/dist/agent-runtime/harness-file-resources.d.ts +33 -0
  29. package/dist/agent-runtime/harness-file-resources.d.ts.map +1 -0
  30. package/dist/agent-runtime/harness-resources.d.ts +5 -0
  31. package/dist/agent-runtime/harness-resources.d.ts.map +1 -0
  32. package/dist/agent-runtime/harness.d.ts +12 -0
  33. package/dist/agent-runtime/harness.d.ts.map +1 -0
  34. package/dist/agent-runtime/history.d.ts +2 -0
  35. package/dist/agent-runtime/history.d.ts.map +1 -1
  36. package/dist/agent-runtime/models.d.ts +199 -0
  37. package/dist/agent-runtime/models.d.ts.map +1 -1
  38. package/dist/agent-runtime/prompt.d.ts +2 -0
  39. package/dist/agent-runtime/prompt.d.ts.map +1 -1
  40. package/dist/agent-runtime/run-execution.d.ts.map +1 -1
  41. package/dist/agent-runtime/runtime.d.ts +11 -3
  42. package/dist/agent-runtime/runtime.d.ts.map +1 -1
  43. package/dist/agent-runtime/schemas.d.ts +49 -0
  44. package/dist/agent-runtime/schemas.d.ts.map +1 -1
  45. package/dist/agent-runtime/sqlite.d.ts +2 -0
  46. package/dist/agent-runtime/sqlite.d.ts.map +1 -1
  47. package/dist/agent-runtime/store-driver.d.ts +61 -212
  48. package/dist/agent-runtime/store-driver.d.ts.map +1 -1
  49. package/dist/agent-runtime/store.d.ts +368 -1
  50. package/dist/agent-runtime/store.d.ts.map +1 -1
  51. package/dist/agent-runtime/terminal-commit.d.ts +12 -1
  52. package/dist/agent-runtime/terminal-commit.d.ts.map +1 -1
  53. package/dist/agent-runtime/terminal-status.d.ts +8 -0
  54. package/dist/agent-runtime/terminal-status.d.ts.map +1 -1
  55. package/dist/agent-runtime-browser.d.ts +1 -0
  56. package/dist/agent-runtime-browser.d.ts.map +1 -1
  57. package/dist/agent-runtime-browser.js +217 -1
  58. package/dist/agent-runtime-coding-tools.d.ts +2 -0
  59. package/dist/agent-runtime-coding-tools.d.ts.map +1 -0
  60. package/dist/agent-runtime-coding-tools.js +766 -0
  61. package/dist/agent-runtime-harness.d.ts +2 -0
  62. package/dist/agent-runtime-harness.d.ts.map +1 -0
  63. package/dist/agent-runtime-harness.js +704 -0
  64. package/dist/agent-runtime-openrouter.d.ts +14 -1
  65. package/dist/agent-runtime-openrouter.d.ts.map +1 -1
  66. package/dist/agent-runtime-openrouter.js +211 -0
  67. package/dist/agent-runtime-sqlite-bun.js +4 -3
  68. package/dist/agent-runtime-sqlite-node.js +4 -3
  69. package/dist/agent-runtime.d.ts +5 -3
  70. package/dist/agent-runtime.d.ts.map +1 -1
  71. package/dist/agent-runtime.js +108 -2580
  72. package/dist/application/diagnostic-journal-contract.d.ts +164 -0
  73. package/dist/application/diagnostic-journal-contract.d.ts.map +1 -0
  74. package/dist/application/diagnostic-journal-manager.d.ts +12 -0
  75. package/dist/application/diagnostic-journal-manager.d.ts.map +1 -0
  76. package/dist/application/diagnostic-journal-storage.d.ts +29 -0
  77. package/dist/application/diagnostic-journal-storage.d.ts.map +1 -0
  78. package/dist/application/diagnostic-journal.d.ts +11 -0
  79. package/dist/application/diagnostic-journal.d.ts.map +1 -0
  80. package/dist/application.d.ts +2 -0
  81. package/dist/application.d.ts.map +1 -1
  82. package/dist/application.js +561 -17
  83. package/dist/browser/socket-io.d.ts.map +1 -1
  84. package/dist/cli.js +9 -6
  85. package/dist/{index-t23p2b68.js → index-0yphgata.js} +1 -1
  86. package/dist/{index-8vpzxg55.js → index-10gbbbaa.js} +103 -2
  87. package/dist/{index-hcx9yypn.js → index-38hs3a58.js} +13 -11
  88. package/dist/index-3xnq72rz.js +21 -0
  89. package/dist/index-7rey2b8s.js +73 -0
  90. package/dist/{index-22tjt2rk.js → index-aczggrty.js} +1 -1
  91. package/dist/index-bd17ytae.js +192 -0
  92. package/dist/{index-xyvxez9r.js → index-da1aqnhb.js} +5 -5
  93. package/dist/index-es0h4w26.js +63 -0
  94. package/dist/{index-hqza5nde.js → index-hsabxjz0.js} +78 -77
  95. package/dist/{index-f24xg2cw.js → index-ktsps64f.js} +4 -2
  96. package/dist/{index-2t6zt5cg.js → index-mjx0wt4c.js} +11 -7
  97. package/dist/{index-y2ctppmg.js → index-qzbg46b6.js} +10 -74
  98. package/dist/{index-bt5179zb.js → index-s8nt8c22.js} +16 -11
  99. package/dist/index-tg3m2ec5.js +157 -0
  100. package/dist/{index-hxh98zbm.js → index-vbf2p6me.js} +1 -1
  101. package/dist/index-vc498pst.js +51 -0
  102. package/dist/{index-pgsyp3xh.js → index-vj3vvpaa.js} +1 -192
  103. package/dist/index-vy5bjy07.js +2569 -0
  104. package/dist/{index-hb0mncmj.js → index-wc80at9n.js} +2 -2
  105. package/dist/{index-eqqyd9v8.js → index-wwst0td5.js} +2 -46
  106. package/dist/{index-ysphyxax.js → index-x1th9s8c.js} +23 -2
  107. package/dist/index-xbtcszs7.js +202 -0
  108. package/dist/{index-grgvpbch.js → index-y3w12g8d.js} +4 -2
  109. package/dist/index.js +51 -37
  110. package/dist/internal/ai-sdk-typed.d.ts +14 -0
  111. package/dist/internal/ai-sdk-typed.d.ts.map +1 -0
  112. package/dist/node.js +6 -5
  113. package/dist/observability/index.js +5 -4
  114. package/dist/realtime/request.d.ts +5 -0
  115. package/dist/realtime/request.d.ts.map +1 -1
  116. package/dist/remote.js +7 -6
  117. package/dist/server/index.js +13 -11
  118. package/dist/testing.js +6 -5
  119. package/dist/tool-invoker.js +7 -5
  120. package/dist/tools/agent-tool-error.d.ts +14 -0
  121. package/dist/tools/agent-tool-error.d.ts.map +1 -0
  122. package/dist/tools/agent.d.ts.map +1 -1
  123. package/dist/tools.js +24 -17
  124. package/llms-full.txt +386 -29
  125. package/package.json +10 -2
@@ -3,12 +3,12 @@ import {
3
3
  inputIsQuery,
4
4
  parseSSE,
5
5
  readBoundedUtf8Lines
6
- } from "./index-t23p2b68.js";
6
+ } from "./index-0yphgata.js";
7
7
  import {
8
8
  ContractStreamFrameSchema,
9
9
  DEFAULT_CONTRACT_STREAM_FRAME_BYTES,
10
10
  parseTrailingWildcard
11
- } from "./index-pgsyp3xh.js";
11
+ } from "./index-vj3vvpaa.js";
12
12
  import {
13
13
  isRecord,
14
14
  mapObject,
@@ -1,9 +1,5 @@
1
1
  import {
2
- contractToolMountable
3
- } from "./index-y2ctppmg.js";
4
- import {
5
- projectRuntimeTool,
6
- projectToolSurface
2
+ projectRuntimeTool
7
3
  } from "./index-22by16v6.js";
8
4
 
9
5
  // src/tools/runtime-tool.ts
@@ -87,44 +83,4 @@ function runtimeToolMountable(definition, assertName = true) {
87
83
  };
88
84
  }
89
85
 
90
- // src/tools/surface.ts
91
- function collectToolSurface({
92
- surface,
93
- transport,
94
- assertUniqueNames = true,
95
- ...collectConfig
96
- }) {
97
- const entries = [];
98
- const append = (entry) => {
99
- entries.push(entry);
100
- };
101
- for (const projected of projectToolSurface(surface, transport, {
102
- extend: collectConfig.extend,
103
- flattenUnionInput: collectConfig.flattenUnionInput,
104
- assertNames: collectConfig.assertNames,
105
- assertUniqueNames
106
- })) {
107
- if (projected.kind === "contract") {
108
- const mountable = contractToolMountable(projected, collectConfig.extend);
109
- append({
110
- kind: "contract",
111
- service: projected.serviceName,
112
- action: mountable.method.key,
113
- mountable,
114
- projection: projected
115
- });
116
- } else {
117
- append({
118
- kind: "runtime",
119
- service: projected.serviceName,
120
- action: projected.action,
121
- mountable: runtimeToolMountable(projected.source, false),
122
- definition: projected.source,
123
- projection: projected
124
- });
125
- }
126
- }
127
- return entries;
128
- }
129
-
130
- export { defineRuntimeTool, createRuntimeToolFactory, collectToolSurface };
86
+ export { defineRuntimeTool, createRuntimeToolFactory, runtimeToolMountable };
@@ -44,6 +44,19 @@ var AgentToolResultPartSchema = z.object({
44
44
  outcome: z.enum(["success", "error", "interrupted"]),
45
45
  output: z.json().optional()
46
46
  });
47
+ var AgentToolApprovalRequestPartSchema = z.object({
48
+ type: z.literal("tool-approval-request"),
49
+ approvalId: z.string().min(1),
50
+ callId: z.string().min(1),
51
+ isAutomatic: z.boolean().optional(),
52
+ signature: z.string().min(1).optional()
53
+ });
54
+ var AgentToolApprovalResponsePartSchema = z.object({
55
+ type: z.literal("tool-approval-response"),
56
+ approvalId: z.string().min(1),
57
+ approved: z.boolean(),
58
+ reason: z.string().min(1).optional()
59
+ });
47
60
  var AgentOpaquePartSchema = z.object({
48
61
  type: z.literal("provider"),
49
62
  envelope: AgentProviderEnvelopeSchema
@@ -59,10 +72,18 @@ var AgentMessagePartSchema = z.discriminatedUnion("type", [
59
72
  AgentSourcePartSchema,
60
73
  AgentToolCallPartSchema,
61
74
  AgentToolResultPartSchema,
75
+ AgentToolApprovalRequestPartSchema,
76
+ AgentToolApprovalResponsePartSchema,
62
77
  AgentOpaquePartSchema,
63
78
  AgentControlPartSchema
64
79
  ]);
65
- var AgentMessageRoleSchema = z.enum(["user", "assistant", "system", "summary"]);
80
+ var AgentMessageRoleSchema = z.enum([
81
+ "user",
82
+ "assistant",
83
+ "tool",
84
+ "system",
85
+ "summary"
86
+ ]);
66
87
  var AgentMessageStatusSchema = z.enum([
67
88
  "committed",
68
89
  "streaming",
@@ -256,4 +277,4 @@ var AgentRunMetricsSchema = z.object({
256
277
  ttftMs: z.number().nonnegative().optional()
257
278
  });
258
279
 
259
- export { AgentRecordIdSchema, AgentRecordVersionSchema, AgentTimestampSchema, AgentJsonObjectSchema, AgentProviderEnvelopeSchema, AgentTextPartSchema, AgentReasoningPartSchema, AgentFilePartSchema, AgentSourcePartSchema, AgentToolCallPartSchema, AgentToolResultPartSchema, AgentOpaquePartSchema, AgentControlPartSchema, AgentMessagePartSchema, AgentMessageRoleSchema, AgentMessageStatusSchema, AgentMessageSchema, AgentAssistantPlaceholderSchema, AgentRunStateSchema, AgentRunQueuePrioritySchema, AgentTerminalReasonSchema, runStateForTerminalReason, AgentProvenanceSchema, AgentUsageValueSchema, AgentCostValueSchema, AgentUsageSchema, AgentRunSchema, AgentSnapshotSchema, AgentRunMetricsSchema };
280
+ export { AgentRecordIdSchema, AgentRecordVersionSchema, AgentTimestampSchema, AgentJsonObjectSchema, AgentProviderEnvelopeSchema, AgentTextPartSchema, AgentReasoningPartSchema, AgentFilePartSchema, AgentSourcePartSchema, AgentToolCallPartSchema, AgentToolResultPartSchema, AgentToolApprovalRequestPartSchema, AgentToolApprovalResponsePartSchema, AgentOpaquePartSchema, AgentControlPartSchema, AgentMessagePartSchema, AgentMessageRoleSchema, AgentMessageStatusSchema, AgentMessageSchema, AgentAssistantPlaceholderSchema, AgentRunStateSchema, AgentRunQueuePrioritySchema, AgentTerminalReasonSchema, runStateForTerminalReason, AgentProvenanceSchema, AgentUsageValueSchema, AgentCostValueSchema, AgentUsageSchema, AgentRunSchema, AgentSnapshotSchema, AgentRunMetricsSchema };
@@ -0,0 +1,202 @@
1
+ // src/agent-runtime/contained-files.ts
2
+ import { constants } from "node:fs";
3
+ import { open, readdir, realpath } from "node:fs/promises";
4
+ import path from "node:path";
5
+ function descriptorPath(handle) {
6
+ if (process.platform === "linux")
7
+ return `/proc/self/fd/${handle.fd}`;
8
+ if (process.platform === "darwin" || process.platform === "freebsd") {
9
+ return `/dev/fd/${handle.fd}`;
10
+ }
11
+ throw new Error("Contained filesystem operations require descriptor paths on this platform");
12
+ }
13
+ async function openPinnedDirectory(absolute) {
14
+ const expected = await realpath(absolute);
15
+ const handle = await open(expected, constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW);
16
+ try {
17
+ if (await realpath(descriptorPath(handle)) !== expected) {
18
+ throw new Error("Contained directory identity changed while opening");
19
+ }
20
+ return handle;
21
+ } catch (error) {
22
+ await handle.close();
23
+ throw error;
24
+ }
25
+ }
26
+ function safeSegments(relative) {
27
+ if (path.isAbsolute(relative))
28
+ throw new Error("Contained paths must be relative");
29
+ const segments = relative.split(/[\\/]/u);
30
+ if (segments.length === 0 || segments.some((segment) => segment === "" || segment === "." || segment === "..")) {
31
+ throw new Error("Contained path has invalid segments");
32
+ }
33
+ return segments;
34
+ }
35
+ async function openContainedParent(root, relative) {
36
+ const segments = safeSegments(relative);
37
+ const basename = segments.pop();
38
+ if (!basename)
39
+ throw new Error("Contained path is missing a basename");
40
+ let current = await openPinnedDirectory(root);
41
+ try {
42
+ for (const segment of segments) {
43
+ const next = await open(path.join(descriptorPath(current), segment), constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW);
44
+ const metadata = await next.stat();
45
+ if (!metadata.isDirectory()) {
46
+ await next.close();
47
+ throw new Error("Contained ancestor is not a directory");
48
+ }
49
+ await current.close();
50
+ current = next;
51
+ }
52
+ return { handle: current, path: descriptorPath(current), basename };
53
+ } catch (error) {
54
+ await current.close();
55
+ throw error;
56
+ }
57
+ }
58
+ async function openContainedFile(root, relative) {
59
+ const parent = await openContainedParent(root, relative);
60
+ try {
61
+ const handle = await open(path.join(parent.path, parent.basename), constants.O_RDONLY | constants.O_NOFOLLOW);
62
+ const metadata = await handle.stat();
63
+ if (!metadata.isFile()) {
64
+ await handle.close();
65
+ throw new Error("Contained path is not a regular file");
66
+ }
67
+ return handle;
68
+ } finally {
69
+ await parent.handle.close();
70
+ }
71
+ }
72
+ function sameIdentity(left, right) {
73
+ return left.dev === right.dev && left.ino === right.ino;
74
+ }
75
+ async function assertContainedFileCurrent(root, relative, expected) {
76
+ const current = await openContainedFile(root, relative);
77
+ try {
78
+ if (!sameIdentity(await expected.stat(), await current.stat())) {
79
+ throw new Error("Contained file identity changed during authorization");
80
+ }
81
+ } finally {
82
+ await current.close();
83
+ }
84
+ }
85
+ async function assertContainedParentCurrent(root, relative, expected) {
86
+ const current = await openContainedParent(root, relative);
87
+ try {
88
+ if (!sameIdentity(await expected.stat(), await current.handle.stat())) {
89
+ throw new Error("Contained parent identity changed during authorization");
90
+ }
91
+ } finally {
92
+ await current.handle.close();
93
+ }
94
+ }
95
+ async function readContainedUtf8Handle(handle, maxBytes) {
96
+ const metadata = await handle.stat();
97
+ if (!metadata.isFile())
98
+ throw new Error("Contained path is not a regular file");
99
+ if (metadata.size > maxBytes)
100
+ throw new Error("Contained file exceeds byte budget");
101
+ const buffer = Buffer.alloc(metadata.size);
102
+ let offset = 0;
103
+ while (offset < buffer.byteLength) {
104
+ const { bytesRead } = await handle.read(buffer, offset, buffer.byteLength - offset, offset);
105
+ if (bytesRead === 0)
106
+ break;
107
+ offset += bytesRead;
108
+ }
109
+ if (offset !== metadata.size)
110
+ throw new Error("Contained file changed while being read");
111
+ return {
112
+ text: new TextDecoder("utf-8", { fatal: true }).decode(buffer),
113
+ bytes: offset,
114
+ mode: metadata.mode
115
+ };
116
+ }
117
+ async function walkContainedFiles(input) {
118
+ const scan = await scanContainedFiles({ ...input, symlinks: "refuse" });
119
+ if (scan.truncated)
120
+ throw new Error("Contained file traversal exceeded its bounds");
121
+ return scan.files;
122
+ }
123
+ async function scanContainedFiles(input) {
124
+ const files = [];
125
+ let truncated = false;
126
+ let skippedDirectories = 0;
127
+ let skippedSymlinks = 0;
128
+ const root = await openPinnedDirectory(input.root);
129
+ const visit = async (directory, relativeDirectory, depth) => {
130
+ if (truncated)
131
+ return;
132
+ if (depth > input.maxDepth) {
133
+ truncated = true;
134
+ return;
135
+ }
136
+ const entries = await readdir(descriptorPath(directory), { withFileTypes: true });
137
+ entries.sort((left, right) => left.name.localeCompare(right.name));
138
+ for (const entry of entries) {
139
+ const relative = relativeDirectory ? path.join(relativeDirectory, entry.name) : entry.name;
140
+ const anchored = path.join(descriptorPath(directory), entry.name);
141
+ if (entry.isSymbolicLink()) {
142
+ if (input.symlinks === "refuse") {
143
+ throw new Error(`Contained file traversal refuses symlink: ${relative}`);
144
+ }
145
+ skippedSymlinks += 1;
146
+ continue;
147
+ }
148
+ if (entry.isDirectory()) {
149
+ if (input.excludeDirectory?.(relative)) {
150
+ skippedDirectories += 1;
151
+ continue;
152
+ }
153
+ let child;
154
+ try {
155
+ child = await open(anchored, constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW);
156
+ } catch (error) {
157
+ if (input.symlinks === "skip") {
158
+ skippedSymlinks += 1;
159
+ continue;
160
+ }
161
+ throw error;
162
+ }
163
+ try {
164
+ await visit(child, relative, depth + 1);
165
+ } finally {
166
+ await child.close();
167
+ }
168
+ continue;
169
+ }
170
+ if (!entry.isFile())
171
+ continue;
172
+ if (files.length >= input.maxFiles) {
173
+ truncated = true;
174
+ return;
175
+ }
176
+ let content;
177
+ if (input.readMaxBytes !== undefined) {
178
+ try {
179
+ const handle = await open(anchored, constants.O_RDONLY | constants.O_NOFOLLOW);
180
+ try {
181
+ content = await readContainedUtf8Handle(handle, input.readMaxBytes);
182
+ } finally {
183
+ await handle.close();
184
+ }
185
+ } catch (error) {
186
+ if (input.skipUnreadable)
187
+ continue;
188
+ throw error;
189
+ }
190
+ }
191
+ files.push({ absolute: relative, relative, ...content && { content } });
192
+ }
193
+ };
194
+ try {
195
+ await visit(root, "", 0);
196
+ } finally {
197
+ await root.close();
198
+ }
199
+ return { files, truncated, skippedDirectories, skippedSymlinks };
200
+ }
201
+
202
+ export { openContainedParent, openContainedFile, assertContainedFileCurrent, assertContainedParentCurrent, readContainedUtf8Handle, walkContainedFiles, scanContainedFiles };
@@ -1,8 +1,10 @@
1
1
  import {
2
2
  collectTools,
3
- createToolRunner,
3
+ createToolRunner
4
+ } from "./index-7rey2b8s.js";
5
+ import {
4
6
  toolErrorFromResult
5
- } from "./index-y2ctppmg.js";
7
+ } from "./index-qzbg46b6.js";
6
8
  import {
7
9
  assertUniqueToolName
8
10
  } from "./index-22by16v6.js";
package/dist/index.js CHANGED
@@ -1492,13 +1492,18 @@ function observeRealtimeRequestPhase(trace, phase) {
1492
1492
  phase,
1493
1493
  elapsedMs: performance.now() - trace.startedAt
1494
1494
  };
1495
- try {
1496
- const result = trace.observe(observation);
1497
- if (result)
1498
- Promise.resolve(result).catch(() => {
1499
- return;
1500
- });
1501
- } catch {}
1495
+ const observers = trace.observeRequest && trace.observeRequest !== trace.observeClient ? [trace.observeClient, trace.observeRequest] : [trace.observeClient ?? trace.observeRequest];
1496
+ for (const observer of observers) {
1497
+ if (!observer)
1498
+ continue;
1499
+ try {
1500
+ const result = observer(observation);
1501
+ if (result)
1502
+ Promise.resolve(result).catch(() => {
1503
+ return;
1504
+ });
1505
+ } catch {}
1506
+ }
1502
1507
  }
1503
1508
  function socketIoPacketIdentity(data, expected) {
1504
1509
  if (typeof data !== "string")
@@ -1636,7 +1641,7 @@ function bindRealtimeClient(contract, transport, { onRejected, logger } = {}) {
1636
1641
  if (!definition?.ack) {
1637
1642
  throw new Error(`Realtime request "${event}" has no acknowledgement schema`);
1638
1643
  }
1639
- const pending = transport.emitWithAck(event, parsedArgs, { timeoutMs });
1644
+ const pending = transport.emitWithAck(event, parsedArgs, options);
1640
1645
  const trace = realtimeRequestTraces.get(pending);
1641
1646
  if (trace)
1642
1647
  realtimeRequestTraces.delete(pending);
@@ -1684,6 +1689,7 @@ function createSocketIOClientInternal(config, onRequestPhase) {
1684
1689
  let reconnectTimer = null;
1685
1690
  const pendingRequestDisconnects = new Set;
1686
1691
  const requestTracesByNativeKey = new Map;
1692
+ const observedRequestEngines = new WeakSet;
1687
1693
  let startingRequestTrace = null;
1688
1694
  const serverDisconnectDelay = config.reconnectOnServerDisconnect ?? 1000;
1689
1695
  const connectionListeners = new Set;
@@ -1701,6 +1707,36 @@ function createSocketIOClientInternal(config, onRequestPhase) {
1701
1707
  reconnectTimer = null;
1702
1708
  }
1703
1709
  }
1710
+ function attachRequestPhaseEngineListeners(target) {
1711
+ const engine = target.io.engine;
1712
+ if (!engine || observedRequestEngines.has(engine))
1713
+ return;
1714
+ observedRequestEngines.add(engine);
1715
+ engine.on("packetCreate", (packet) => {
1716
+ if (!startingRequestTrace || packet.type !== "message")
1717
+ return;
1718
+ const identity = socketIoPacketIdentity(packet.data, "event");
1719
+ if (!identity)
1720
+ return;
1721
+ const key = packetIdentityKey(identity);
1722
+ startingRequestTrace.nativeKey = key;
1723
+ requestTracesByNativeKey.set(key, startingRequestTrace);
1724
+ observeRealtimeRequestPhase(startingRequestTrace, "engine-handoff");
1725
+ });
1726
+ engine.on("packet", (packet) => {
1727
+ if (packet.type !== "message")
1728
+ return;
1729
+ const identity = socketIoPacketIdentity(packet.data, "ack");
1730
+ if (!identity)
1731
+ return;
1732
+ const key = packetIdentityKey(identity);
1733
+ const trace = requestTracesByNativeKey.get(key);
1734
+ if (!trace || trace.closed)
1735
+ return;
1736
+ observeRealtimeRequestPhase(trace, "engine-ack-received");
1737
+ requestTracesByNativeKey.delete(key);
1738
+ });
1739
+ }
1704
1740
  function openSocket(io) {
1705
1741
  if (!desiredConnected || socket)
1706
1742
  return;
@@ -1720,33 +1756,8 @@ function createSocketIOClientInternal(config, onRequestPhase) {
1720
1756
  });
1721
1757
  if (onRequestPhase) {
1722
1758
  socket.io.on("open", () => {
1723
- const engine = socket?.io.engine;
1724
- if (!engine)
1725
- return;
1726
- engine.on("packetCreate", (packet) => {
1727
- if (!startingRequestTrace || packet.type !== "message")
1728
- return;
1729
- const identity = socketIoPacketIdentity(packet.data, "event");
1730
- if (!identity)
1731
- return;
1732
- const key = packetIdentityKey(identity);
1733
- startingRequestTrace.nativeKey = key;
1734
- requestTracesByNativeKey.set(key, startingRequestTrace);
1735
- observeRealtimeRequestPhase(startingRequestTrace, "engine-handoff");
1736
- });
1737
- engine.on("packet", (packet) => {
1738
- if (packet.type !== "message")
1739
- return;
1740
- const identity = socketIoPacketIdentity(packet.data, "ack");
1741
- if (!identity)
1742
- return;
1743
- const key = packetIdentityKey(identity);
1744
- const trace = requestTracesByNativeKey.get(key);
1745
- if (!trace || trace.closed)
1746
- return;
1747
- observeRealtimeRequestPhase(trace, "engine-ack-received");
1748
- requestTracesByNativeKey.delete(key);
1749
- });
1759
+ if (socket)
1760
+ attachRequestPhaseEngineListeners(socket);
1750
1761
  });
1751
1762
  }
1752
1763
  socket.on("connect", () => notifyConnection(true));
@@ -1858,11 +1869,12 @@ function createSocketIOClientInternal(config, onRequestPhase) {
1858
1869
  return true;
1859
1870
  },
1860
1871
  emitWithAck(event, args, options) {
1861
- const trace = onRequestPhase ? {
1872
+ const trace = onRequestPhase || options.onPhase ? {
1862
1873
  requestId: crypto.randomUUID(),
1863
1874
  event,
1864
1875
  startedAt: performance.now(),
1865
- observe: onRequestPhase,
1876
+ observeClient: onRequestPhase,
1877
+ observeRequest: options.onPhase,
1866
1878
  closed: false
1867
1879
  } : undefined;
1868
1880
  const closeTrace = (phase) => {
@@ -1881,6 +1893,8 @@ function createSocketIOClientInternal(config, onRequestPhase) {
1881
1893
  realtimeRequestTraces.set(pending2, trace);
1882
1894
  return pending2;
1883
1895
  }
1896
+ if (trace)
1897
+ attachRequestPhaseEngineListeners(active);
1884
1898
  const pending = new Promise((resolve, reject) => {
1885
1899
  let settled = false;
1886
1900
  const finish = (result) => {
@@ -0,0 +1,14 @@
1
+ import { type ModelMessage, streamText, type ToolSet } from 'ai';
2
+ /**
3
+ * AI SDK derives conditional `toolsContext` requirements from each structural tool in a generic
4
+ * set. AgentRuntime receives that set after canonical mounting, so TypeScript cannot prove the
5
+ * conditional options object even though the SDK validates it at this adapter boundary.
6
+ */
7
+ export declare function streamAgentTextBoundary<TOOLS extends ToolSet>(options: unknown): ReturnType<typeof streamText<TOOLS, never>>;
8
+ /**
9
+ * `modelMessageSchema` in the current AI SDK runtime validates approval requests but strips their
10
+ * optional signature even though the public type and approval verifier require it. Validate the
11
+ * full message first, then restore only the already-validated string at this SDK adapter boundary.
12
+ */
13
+ export declare function modelMessageWithApprovalSignature(input: unknown): ModelMessage;
14
+ //# sourceMappingURL=ai-sdk-typed.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-sdk-typed.d.ts","sourceRoot":"","sources":["../../src/internal/ai-sdk-typed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAsB,UAAU,EAAE,KAAK,OAAO,EAAE,MAAM,IAAI,CAAC;AAGrF;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,SAAS,OAAO,EAC3D,OAAO,EAAE,OAAO,GACf,UAAU,CAAC,OAAO,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAI7C;AAED;;;;GAIG;AACH,wBAAgB,iCAAiC,CAAC,KAAK,EAAE,OAAO,GAAG,YAAY,CAsB9E"}
package/dist/node.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  createHandler,
6
6
  createSocketIOServer,
7
7
  createUnixClientTransport
8
- } from "./index-hcx9yypn.js";
8
+ } from "./index-38hs3a58.js";
9
9
  import {
10
10
  createImplement,
11
11
  createImplementRegistry,
@@ -14,8 +14,8 @@ import {
14
14
  createScopedImplementRegistry,
15
15
  implement,
16
16
  implementRegistry
17
- } from "./index-hxh98zbm.js";
18
- import"./index-f24xg2cw.js";
17
+ } from "./index-vbf2p6me.js";
18
+ import"./index-ktsps64f.js";
19
19
  import"./index-7b188kmz.js";
20
20
  import {
21
21
  ShutdownOptionsSchema,
@@ -24,8 +24,8 @@ import {
24
24
  ShutdownStatusSchema,
25
25
  createServerLifecycle
26
26
  } from "./index-dk6e56g0.js";
27
- import"./index-pgsyp3xh.js";
28
- import"./index-qyrqwr4c.js";
27
+ import"./index-bd17ytae.js";
28
+ import"./index-vj3vvpaa.js";
29
29
  import {
30
30
  AppError,
31
31
  appError,
@@ -36,6 +36,7 @@ import {
36
36
  rateLimited,
37
37
  unauthorized
38
38
  } from "./index-0w9abg87.js";
39
+ import"./index-qyrqwr4c.js";
39
40
  import"./index-6k1937bx.js";
40
41
  // src/server/node.ts
41
42
  import { serve } from "srvx/node";
@@ -10,7 +10,7 @@ import {
10
10
  redact,
11
11
  sanitizePayload,
12
12
  truncatePreview
13
- } from "../index-22tjt2rk.js";
13
+ } from "../index-aczggrty.js";
14
14
  import {
15
15
  getRequestContext,
16
16
  getTraceId,
@@ -21,7 +21,7 @@ import {
21
21
  setRequestError,
22
22
  setRequestUser,
23
23
  wrapInRequestContext
24
- } from "../index-f24xg2cw.js";
24
+ } from "../index-ktsps64f.js";
25
25
  import {
26
26
  childSpan,
27
27
  createTraceContext,
@@ -30,11 +30,12 @@ import {
30
30
  recordedErrorMessage,
31
31
  resolvePropagationContext,
32
32
  resolveTraceContext
33
- } from "../index-pgsyp3xh.js";
33
+ } from "../index-bd17ytae.js";
34
+ import"../index-vj3vvpaa.js";
35
+ import"../index-0w9abg87.js";
34
36
  import {
35
37
  isRecord
36
38
  } from "../index-qyrqwr4c.js";
37
- import"../index-0w9abg87.js";
38
39
  import"../index-6k1937bx.js";
39
40
 
40
41
  // src/observability/audit.ts
@@ -27,6 +27,11 @@ export type RealtimeRequestPhaseHook = (event: RealtimeRequestPhaseEvent) => voi
27
27
  export interface RealtimeRequestOptions {
28
28
  /** Maximum acknowledgement wait in milliseconds. Must be finite and > 0. */
29
29
  timeoutMs: number;
30
+ /**
31
+ * Observe phases for this invocation only. Correlate through the hook's local
32
+ * closure; no caller metadata is retained or transmitted with the request.
33
+ */
34
+ onPhase?: RealtimeRequestPhaseHook;
30
35
  }
31
36
  export declare class RealtimeRequestTimeoutError extends Error {
32
37
  readonly code = "REALTIME_REQUEST_TIMEOUT";
@@ -1 +1 @@
1
- {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/realtime/request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAE/D,4EAA4E;AAC5E,eAAO,MAAM,0BAA0B;;;;;;EAMrC,CAAC;AAEH,gFAAgF;AAChF,eAAO,MAAM,+BAA+B;;;;;;;;;;;kBAOjC,CAAC;AAEZ,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAC9E,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,+BAA+B,CAAC,CAAC;AACxF,MAAM,MAAM,wBAAwB,GAAG,CACrC,KAAK,EAAE,yBAAyB,KAC7B,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE1B,MAAM,WAAW,sBAAsB;IACrC,4EAA4E;IAC5E,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,qBAAa,2BAA4B,SAAQ,KAAK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D,YACE,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,sBAAsB,EAAE,EAOlC;CACF"}
package/dist/remote.js CHANGED
@@ -1,17 +1,18 @@
1
1
  import {
2
2
  ApiError,
3
3
  createClient
4
- } from "./index-hb0mncmj.js";
5
- import"./index-t23p2b68.js";
4
+ } from "./index-wc80at9n.js";
5
+ import"./index-0yphgata.js";
6
+ import"./index-bd17ytae.js";
6
7
  import {
7
8
  mergeMeta
8
- } from "./index-pgsyp3xh.js";
9
- import {
10
- isRecord
11
- } from "./index-qyrqwr4c.js";
9
+ } from "./index-vj3vvpaa.js";
12
10
  import {
13
11
  AppError
14
12
  } from "./index-0w9abg87.js";
13
+ import {
14
+ isRecord
15
+ } from "./index-qyrqwr4c.js";
15
16
  import"./index-6k1937bx.js";
16
17
 
17
18
  // src/tools/remote.ts
@@ -13,7 +13,7 @@ import {
13
13
  sseRoute,
14
14
  streamingRoute,
15
15
  webSocketLane
16
- } from "../index-hcx9yypn.js";
16
+ } from "../index-38hs3a58.js";
17
17
  import {
18
18
  composeAuthHooks,
19
19
  createAuthHook,
@@ -26,7 +26,7 @@ import {
26
26
  signJwt,
27
27
  verifyJwt,
28
28
  verifyPkce
29
- } from "../index-xyvxez9r.js";
29
+ } from "../index-da1aqnhb.js";
30
30
  import {
31
31
  DEFAULT_CORS_ALLOW_HEADERS,
32
32
  DEFAULT_CORS_EXPOSE_HEADERS,
@@ -40,7 +40,7 @@ import {
40
40
  defineMultipartStream,
41
41
  implement,
42
42
  implementRegistry
43
- } from "../index-hxh98zbm.js";
43
+ } from "../index-vbf2p6me.js";
44
44
  import {
45
45
  extractIp,
46
46
  generateTraceId,
@@ -48,7 +48,7 @@ import {
48
48
  getTraceId,
49
49
  resolveSocketIp,
50
50
  resolveTraceId
51
- } from "../index-f24xg2cw.js";
51
+ } from "../index-ktsps64f.js";
52
52
  import {
53
53
  isWithinDir,
54
54
  realPathWithinDir
@@ -69,19 +69,18 @@ import {
69
69
  inputIsQuery,
70
70
  parseSSE,
71
71
  streamSSE
72
- } from "../index-t23p2b68.js";
72
+ } from "../index-0yphgata.js";
73
73
  import {
74
- DEFAULT_CONTRACT_STREAM_FRAME_BYTES,
75
74
  errorCode,
76
75
  formatZodError,
77
- joinRoutePath,
78
76
  normalizeError,
79
- parseTrailingWildcard,
80
77
  zodIssues
81
- } from "../index-pgsyp3xh.js";
78
+ } from "../index-bd17ytae.js";
82
79
  import {
83
- isRecord
84
- } from "../index-qyrqwr4c.js";
80
+ DEFAULT_CONTRACT_STREAM_FRAME_BYTES,
81
+ joinRoutePath,
82
+ parseTrailingWildcard
83
+ } from "../index-vj3vvpaa.js";
85
84
  import {
86
85
  AppError,
87
86
  STITCH_ERROR_STATUS,
@@ -94,6 +93,9 @@ import {
94
93
  rateLimited,
95
94
  unauthorized
96
95
  } from "../index-0w9abg87.js";
96
+ import {
97
+ isRecord
98
+ } from "../index-qyrqwr4c.js";
97
99
  import"../index-6k1937bx.js";
98
100
  // src/server/bun.ts
99
101
  import { chmodSync, statSync, unlinkSync } from "node:fs";