stitchkit 0.103.0 → 0.103.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/dist/agent-runtime/browser-control-contract.d.ts +1118 -0
- package/dist/agent-runtime/browser-control-contract.d.ts.map +1 -0
- package/dist/agent-runtime/browser-controller.d.ts +31 -0
- package/dist/agent-runtime/browser-controller.d.ts.map +1 -0
- package/dist/agent-runtime/harness-control.d.ts.map +1 -1
- package/dist/agent-runtime/harness-realtime.d.ts +25 -0
- package/dist/agent-runtime/harness-realtime.d.ts.map +1 -0
- package/dist/agent-runtime/harness-tools.d.ts +11 -0
- package/dist/agent-runtime/harness-tools.d.ts.map +1 -0
- package/dist/agent-runtime/react.d.ts +4 -0
- package/dist/agent-runtime/react.d.ts.map +1 -0
- package/dist/agent-runtime/run-assertions.d.ts +63 -0
- package/dist/agent-runtime/run-assertions.d.ts.map +1 -0
- package/dist/entrypoints/agent-runtime/browser.d.ts +2 -0
- package/dist/entrypoints/agent-runtime/browser.d.ts.map +1 -1
- package/dist/entrypoints/agent-runtime/browser.js +235 -0
- package/dist/entrypoints/agent-runtime/harness-tools.d.ts +2 -0
- package/dist/entrypoints/agent-runtime/harness-tools.d.ts.map +1 -0
- package/dist/entrypoints/agent-runtime/harness-tools.js +32 -0
- package/dist/entrypoints/agent-runtime/harness.js +11 -226
- package/dist/entrypoints/agent-runtime/react.d.ts +2 -0
- package/dist/entrypoints/agent-runtime/react.d.ts.map +1 -0
- package/dist/entrypoints/agent-runtime/react.js +8 -0
- package/dist/entrypoints/agent-runtime/realtime.d.ts +2 -0
- package/dist/entrypoints/agent-runtime/realtime.d.ts.map +1 -0
- package/dist/entrypoints/agent-runtime/realtime.js +159 -0
- package/dist/entrypoints/agent-runtime/testing.d.ts +1 -0
- package/dist/entrypoints/agent-runtime/testing.d.ts.map +1 -1
- package/dist/entrypoints/agent-runtime/testing.js +67 -2
- package/dist/entrypoints/agent-runtime.js +23 -18
- package/dist/entrypoints/cli.js +6 -6
- package/dist/entrypoints/index.js +15 -226
- package/dist/entrypoints/node.js +7 -5
- package/dist/entrypoints/observability.js +2 -2
- package/dist/entrypoints/react.js +2 -2
- package/dist/entrypoints/remote.js +3 -3
- package/dist/entrypoints/server.js +10 -8
- package/dist/entrypoints/testing.js +3 -3
- package/dist/entrypoints/tools/invoker.js +5 -5
- package/dist/entrypoints/tools.js +23 -34
- package/dist/entrypoints/tracking.js +2 -2
- package/dist/{index-d82d3xg4.js → index-0c419yx7.js} +1 -1
- package/dist/{index-dvwj1f43.js → index-0efgsyav.js} +1 -1
- package/dist/index-20yvtn9a.js +38 -0
- package/dist/{index-a9pd417t.js → index-5vyd0fkb.js} +1 -34
- package/dist/{index-r1z0rd9c.js → index-7n68nmc6.js} +1 -1
- package/dist/index-860vjkgm.js +48 -0
- package/dist/index-c9d05kvt.js +11 -0
- package/dist/{index-m9fndta6.js → index-ds7jdhep.js} +2 -2
- package/dist/index-jn9g8xdt.js +246 -0
- package/dist/{index-n9tyz8z3.js → index-kgmh97hf.js} +1 -1
- package/dist/{index-c6aagrbd.js → index-kkk1wzsq.js} +3 -3
- package/dist/index-nggfa2yn.js +34 -0
- package/dist/{index-m79yr938.js → index-pw99k9h5.js} +1 -10
- package/dist/index-qapzv4p5.js +54 -0
- package/dist/index-r34mvse1.js +225 -0
- package/dist/index-srs8hj9c.js +10 -0
- package/dist/index-vgkbcnkc.js +29 -0
- package/dist/{index-ewbaywk5.js → index-x1dkwx5x.js} +1 -1
- package/dist/{index-xkhk5d6g.js → index-xgc94hy6.js} +5 -48
- package/dist/{index-3ct7hhq6.js → index-xwq9j1sf.js} +6 -56
- package/dist/{index-hby4qhax.js → index-yex7eg1v.js} +4 -10
- package/dist/{index-1h6gtdrj.js → index-ygkka6zn.js} +1 -1
- package/dist/{index-zs4ms3th.js → index-z3pqcy7r.js} +7 -30
- package/dist/index-ze1eph1k.js +20 -0
- package/llms/agent-runtime-browser.txt +26 -0
- package/llms/agent-runtime-harness-tools.txt +25 -0
- package/llms/agent-runtime-harness.txt +140 -1
- package/llms/agent-runtime-react.txt +21 -0
- package/llms/agent-runtime-realtime.txt +30 -0
- package/llms/agent-runtime-testing.txt +6 -0
- package/llms/stitchkit.txt +5 -1
- package/llms-full.txt +209 -1
- package/llms.txt +8 -4
- package/package.json +13 -1
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import {
|
|
2
|
+
parseRealtimeRequestArguments,
|
|
3
|
+
parseRealtimeRequestAcknowledgement,
|
|
4
|
+
createValidatedRealtimeSocket
|
|
5
|
+
} from "./index-pw99k9h5.js";
|
|
6
|
+
import {
|
|
7
|
+
randomHex
|
|
8
|
+
} from "./index-c9d05kvt.js";
|
|
9
|
+
|
|
10
|
+
// src/browser/socket-io-trace.ts
|
|
11
|
+
var realtimeRequestTraces = new WeakMap;
|
|
12
|
+
function observeRealtimeRequestPhase(trace, phase) {
|
|
13
|
+
const observation = {
|
|
14
|
+
requestId: trace.requestId,
|
|
15
|
+
event: trace.event,
|
|
16
|
+
phase,
|
|
17
|
+
elapsedMs: performance.now() - trace.startedAt
|
|
18
|
+
};
|
|
19
|
+
const observers = trace.observeRequest && trace.observeRequest !== trace.observeClient ? [trace.observeClient, trace.observeRequest] : [trace.observeClient ?? trace.observeRequest];
|
|
20
|
+
for (const observer of observers) {
|
|
21
|
+
if (!observer)
|
|
22
|
+
continue;
|
|
23
|
+
try {
|
|
24
|
+
const result = observer(observation);
|
|
25
|
+
if (result)
|
|
26
|
+
Promise.resolve(result).catch(() => {
|
|
27
|
+
return;
|
|
28
|
+
});
|
|
29
|
+
} catch {}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function socketIoPacketIdentity(data, expected) {
|
|
33
|
+
if (typeof data !== "string")
|
|
34
|
+
return null;
|
|
35
|
+
const type = data.charAt(0);
|
|
36
|
+
const binary = type === (expected === "event" ? "5" : "6");
|
|
37
|
+
if (type !== (expected === "event" ? "2" : "3") && !binary)
|
|
38
|
+
return null;
|
|
39
|
+
let offset = 1;
|
|
40
|
+
if (binary) {
|
|
41
|
+
const separator = data.indexOf("-", offset);
|
|
42
|
+
if (separator < 0)
|
|
43
|
+
return null;
|
|
44
|
+
for (let index = offset;index < separator; index += 1) {
|
|
45
|
+
const code = data.charCodeAt(index);
|
|
46
|
+
if (code < 48 || code > 57)
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
offset = separator + 1;
|
|
50
|
+
}
|
|
51
|
+
let namespace = "/";
|
|
52
|
+
if (data.charAt(offset) === "/") {
|
|
53
|
+
const separator = data.indexOf(",", offset);
|
|
54
|
+
if (separator < 0)
|
|
55
|
+
return null;
|
|
56
|
+
namespace = data.slice(offset, separator);
|
|
57
|
+
offset = separator + 1;
|
|
58
|
+
}
|
|
59
|
+
const start = offset;
|
|
60
|
+
while (offset < data.length) {
|
|
61
|
+
const code = data.charCodeAt(offset);
|
|
62
|
+
if (code < 48 || code > 57)
|
|
63
|
+
break;
|
|
64
|
+
offset += 1;
|
|
65
|
+
}
|
|
66
|
+
if (offset === start)
|
|
67
|
+
return null;
|
|
68
|
+
return { namespace, id: data.slice(start, offset) };
|
|
69
|
+
}
|
|
70
|
+
function packetIdentityKey(identity) {
|
|
71
|
+
return `${identity.namespace}:${identity.id}`;
|
|
72
|
+
}
|
|
73
|
+
function createRequestTracer(onRequestPhase) {
|
|
74
|
+
const requestTracesByNativeKey = new Map;
|
|
75
|
+
const observedRequestEngines = new WeakSet;
|
|
76
|
+
let startingRequestTrace = null;
|
|
77
|
+
return {
|
|
78
|
+
start(event, onPhase) {
|
|
79
|
+
if (!onRequestPhase && !onPhase)
|
|
80
|
+
return;
|
|
81
|
+
const trace = {
|
|
82
|
+
requestId: randomHex(16),
|
|
83
|
+
event,
|
|
84
|
+
startedAt: performance.now(),
|
|
85
|
+
observeClient: onRequestPhase,
|
|
86
|
+
observeRequest: onPhase,
|
|
87
|
+
closed: false
|
|
88
|
+
};
|
|
89
|
+
return trace;
|
|
90
|
+
},
|
|
91
|
+
close(trace, phase) {
|
|
92
|
+
if (!trace || trace.closed)
|
|
93
|
+
return;
|
|
94
|
+
trace.closed = true;
|
|
95
|
+
if (trace.nativeKey)
|
|
96
|
+
requestTracesByNativeKey.delete(trace.nativeKey);
|
|
97
|
+
observeRealtimeRequestPhase(trace, phase);
|
|
98
|
+
},
|
|
99
|
+
starting(trace, emit) {
|
|
100
|
+
startingRequestTrace = trace ?? null;
|
|
101
|
+
try {
|
|
102
|
+
return emit();
|
|
103
|
+
} finally {
|
|
104
|
+
startingRequestTrace = null;
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
observeEachOpen(target, current) {
|
|
108
|
+
if (!onRequestPhase)
|
|
109
|
+
return;
|
|
110
|
+
target.io.on("open", () => {
|
|
111
|
+
const socket = current();
|
|
112
|
+
if (socket)
|
|
113
|
+
this.observe(socket);
|
|
114
|
+
});
|
|
115
|
+
},
|
|
116
|
+
observe(target) {
|
|
117
|
+
const engine = target.io.engine;
|
|
118
|
+
if (!engine || observedRequestEngines.has(engine))
|
|
119
|
+
return;
|
|
120
|
+
observedRequestEngines.add(engine);
|
|
121
|
+
engine.on("packetCreate", (packet) => {
|
|
122
|
+
if (!startingRequestTrace || packet.type !== "message")
|
|
123
|
+
return;
|
|
124
|
+
const identity = socketIoPacketIdentity(packet.data, "event");
|
|
125
|
+
if (!identity)
|
|
126
|
+
return;
|
|
127
|
+
const key = packetIdentityKey(identity);
|
|
128
|
+
startingRequestTrace.nativeKey = key;
|
|
129
|
+
requestTracesByNativeKey.set(key, startingRequestTrace);
|
|
130
|
+
observeRealtimeRequestPhase(startingRequestTrace, "engine-handoff");
|
|
131
|
+
});
|
|
132
|
+
engine.on("packet", (packet) => {
|
|
133
|
+
if (packet.type !== "message")
|
|
134
|
+
return;
|
|
135
|
+
const identity = socketIoPacketIdentity(packet.data, "ack");
|
|
136
|
+
if (!identity)
|
|
137
|
+
return;
|
|
138
|
+
const key = packetIdentityKey(identity);
|
|
139
|
+
const trace = requestTracesByNativeKey.get(key);
|
|
140
|
+
if (!trace || trace.closed)
|
|
141
|
+
return;
|
|
142
|
+
observeRealtimeRequestPhase(trace, "engine-ack-received");
|
|
143
|
+
requestTracesByNativeKey.delete(key);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// src/browser/realtime-client.ts
|
|
150
|
+
function assertRealtimeClientTransport(transport) {
|
|
151
|
+
for (const capability of ["on", "emit", "emitWithAck", "onConnectionChange"]) {
|
|
152
|
+
if (typeof Reflect.get(transport, capability) !== "function") {
|
|
153
|
+
throw new TypeError(`Realtime client transport does not implement ${capability}()`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (typeof transport.connected !== "boolean") {
|
|
157
|
+
throw new TypeError("Realtime client transport does not expose boolean connected");
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
function bindRealtimeClient2(contract, transport, { onRejected, logger } = {}) {
|
|
161
|
+
assertRealtimeClientTransport(transport);
|
|
162
|
+
const events = createValidatedRealtimeSocket({
|
|
163
|
+
target: transport,
|
|
164
|
+
inbound: contract.serverToClient,
|
|
165
|
+
outbound: contract.clientToServer,
|
|
166
|
+
inboundDirection: "client-inbound",
|
|
167
|
+
outboundDirection: "client-outbound",
|
|
168
|
+
onRejected,
|
|
169
|
+
logger,
|
|
170
|
+
subscribe: (event, handler) => {
|
|
171
|
+
const subscribe = Reflect.get(transport, "on");
|
|
172
|
+
if (typeof subscribe !== "function") {
|
|
173
|
+
throw new Error("Socket.IO client does not implement on()");
|
|
174
|
+
}
|
|
175
|
+
const unsubscribe = Reflect.apply(subscribe, transport, [event, handler]);
|
|
176
|
+
if (typeof unsubscribe !== "function") {
|
|
177
|
+
throw new Error("Socket.IO client on() did not return an unsubscribe function");
|
|
178
|
+
}
|
|
179
|
+
return () => {
|
|
180
|
+
Reflect.apply(unsubscribe, undefined, []);
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
async function request(event, ...args) {
|
|
185
|
+
const options = args.at(-1);
|
|
186
|
+
if (!options || typeof options !== "object" || !("timeoutMs" in options)) {
|
|
187
|
+
throw new TypeError(`Realtime request "${event}" requires { timeoutMs }`);
|
|
188
|
+
}
|
|
189
|
+
const timeoutMs = options.timeoutMs;
|
|
190
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
191
|
+
throw new RangeError(`Realtime request "${event}" timeoutMs must be finite and > 0`);
|
|
192
|
+
}
|
|
193
|
+
const values = args.slice(0, -1);
|
|
194
|
+
const parsedArgs = parseRealtimeRequestArguments(contract.clientToServer, event, "client-outbound", values);
|
|
195
|
+
const definition = contract.clientToServer[event];
|
|
196
|
+
if (!definition?.ack) {
|
|
197
|
+
throw new Error(`Realtime request "${event}" has no acknowledgement schema`);
|
|
198
|
+
}
|
|
199
|
+
const pending = transport.emitWithAck(event, parsedArgs, options);
|
|
200
|
+
const trace = realtimeRequestTraces.get(pending);
|
|
201
|
+
if (trace)
|
|
202
|
+
realtimeRequestTraces.delete(pending);
|
|
203
|
+
const value = await pending;
|
|
204
|
+
let acknowledgement;
|
|
205
|
+
try {
|
|
206
|
+
acknowledgement = parseRealtimeRequestAcknowledgement(definition.ack, event, "client-inbound", value, onRejected, logger);
|
|
207
|
+
} finally {
|
|
208
|
+
if (trace && !trace.closed) {
|
|
209
|
+
trace.closed = true;
|
|
210
|
+
observeRealtimeRequestPhase(trace, "settled");
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return acknowledgement;
|
|
214
|
+
}
|
|
215
|
+
return {
|
|
216
|
+
...events,
|
|
217
|
+
get connected() {
|
|
218
|
+
return transport.connected;
|
|
219
|
+
},
|
|
220
|
+
request,
|
|
221
|
+
onConnectionChange: (listener) => transport.onConnectionChange(listener)
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export { realtimeRequestTraces, createRequestTracer, bindRealtimeClient2 };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// src/internal/optional-peer.ts
|
|
2
|
+
function isModuleNotFound(error) {
|
|
3
|
+
if (typeof error !== "object" || error === null)
|
|
4
|
+
return false;
|
|
5
|
+
const code = "code" in error ? error.code : undefined;
|
|
6
|
+
const message = "message" in error && typeof error.message === "string" ? error.message : "";
|
|
7
|
+
return code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND" || message.includes("Cannot find module") || message.includes("Cannot find package");
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { isModuleNotFound };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createBoundedSinkManager
|
|
3
|
+
} from "./index-h97tqqp1.js";
|
|
4
|
+
import {
|
|
5
|
+
AgentRuntimeEventSchema2
|
|
6
|
+
} from "./index-mnkk1ffz.js";
|
|
7
|
+
|
|
8
|
+
// src/agent-runtime/events.ts
|
|
9
|
+
function createAgentRuntimeEventSink2(config) {
|
|
10
|
+
const manager = createBoundedSinkManager({
|
|
11
|
+
write: config.write,
|
|
12
|
+
...config.maxPending !== undefined && { maxPending: config.maxPending },
|
|
13
|
+
...config.onSinkError && { onSinkError: config.onSinkError },
|
|
14
|
+
...config.onDrop && { onDrop: config.onDrop }
|
|
15
|
+
});
|
|
16
|
+
return {
|
|
17
|
+
publish(rawEvent) {
|
|
18
|
+
const event = AgentRuntimeEventSchema2.parse(rawEvent);
|
|
19
|
+
const projected = config.project?.(event) ?? (config.project ? undefined : event);
|
|
20
|
+
if (projected)
|
|
21
|
+
manager.submit(() => AgentRuntimeEventSchema2.parse(projected));
|
|
22
|
+
},
|
|
23
|
+
flush: (bound) => manager.flush(bound),
|
|
24
|
+
getStatus: () => manager.getStatus(),
|
|
25
|
+
close: (bound) => manager.close(bound)
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { createAgentRuntimeEventSink2 };
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AgentToolError2,
|
|
3
3
|
resolveToolDurability
|
|
4
|
-
} from "./index-
|
|
4
|
+
} from "./index-nggfa2yn.js";
|
|
5
5
|
import {
|
|
6
6
|
toolResultFromError,
|
|
7
7
|
toolCauseFromResult,
|
|
8
8
|
isToolExecutionControlError2
|
|
9
|
-
} from "./index-
|
|
9
|
+
} from "./index-0efgsyav.js";
|
|
10
10
|
import {
|
|
11
11
|
createToolRunner,
|
|
12
12
|
formatToolError
|
|
13
|
-
} from "./index-
|
|
13
|
+
} from "./index-kgmh97hf.js";
|
|
14
14
|
import {
|
|
15
15
|
collectToolSurface
|
|
16
|
-
} from "./index-
|
|
16
|
+
} from "./index-x1dkwx5x.js";
|
|
17
17
|
import {
|
|
18
18
|
isRecord
|
|
19
19
|
} from "./index-9jfdm5tg.js";
|
|
@@ -108,47 +108,4 @@ function mountAgent2(services, config = {}) {
|
|
|
108
108
|
return tools;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
|
|
112
|
-
function utf8Length(value) {
|
|
113
|
-
return new TextEncoder().encode(JSON.stringify(value)).byteLength;
|
|
114
|
-
}
|
|
115
|
-
function describeToolCatalog2(config) {
|
|
116
|
-
const deferred = new Set(config.deferredNames ?? []);
|
|
117
|
-
const entries = collectToolSurface({
|
|
118
|
-
surface: config,
|
|
119
|
-
transport: config.transport,
|
|
120
|
-
extend: config.extend,
|
|
121
|
-
flattenUnionInput: config.flattenUnionInput
|
|
122
|
-
}).map(({ kind, service, action, mountable }) => {
|
|
123
|
-
const schemaBytes = utf8Length(mountable.presentationSchema);
|
|
124
|
-
return {
|
|
125
|
-
name: mountable.name,
|
|
126
|
-
description: mountable.method.desc,
|
|
127
|
-
inputSchema: mountable.presentationSchema,
|
|
128
|
-
source: { kind, service, action },
|
|
129
|
-
schemaBytes,
|
|
130
|
-
deferred: deferred.has(mountable.name)
|
|
131
|
-
};
|
|
132
|
-
});
|
|
133
|
-
if (config.maxSchemaBytes !== undefined) {
|
|
134
|
-
const total = entries.reduce((sum, entry) => sum + entry.schemaBytes, 0);
|
|
135
|
-
if (total > config.maxSchemaBytes) {
|
|
136
|
-
throw new TypeError(`Tool catalog schemas use ${total} bytes, exceeding maxSchemaBytes ${config.maxSchemaBytes}`);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
return entries;
|
|
140
|
-
}
|
|
141
|
-
function buildToolManifest2(config) {
|
|
142
|
-
return collectToolSurface({
|
|
143
|
-
surface: config,
|
|
144
|
-
transport: config.transport,
|
|
145
|
-
extend: config.extend,
|
|
146
|
-
flattenUnionInput: config.flattenUnionInput
|
|
147
|
-
}).map(({ mountable }) => ({
|
|
148
|
-
name: mountable.name,
|
|
149
|
-
description: mountable.method.desc,
|
|
150
|
-
inputSchema: mountable.presentationSchema
|
|
151
|
-
}));
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
export { mountAgent2, describeToolCatalog2, buildToolManifest2 };
|
|
111
|
+
export { mountAgent2 };
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
} from "./index-b2bz0kdm.js";
|
|
18
18
|
import {
|
|
19
19
|
resolveTraceContext2
|
|
20
|
-
} from "./index-
|
|
20
|
+
} from "./index-yex7eg1v.js";
|
|
21
21
|
import {
|
|
22
22
|
DEFAULT_CONTRACT_STREAM_FRAME_BYTES2
|
|
23
23
|
} from "./index-r5c4fedv.js";
|
|
@@ -25,13 +25,12 @@ import {
|
|
|
25
25
|
joinRoutePath,
|
|
26
26
|
parseTrailingWildcard
|
|
27
27
|
} from "./index-m38ej7e5.js";
|
|
28
|
-
import {
|
|
29
|
-
createValidatedRealtimeSocket,
|
|
30
|
-
isModuleNotFound
|
|
31
|
-
} from "./index-m79yr938.js";
|
|
32
28
|
import {
|
|
33
29
|
RELEASE_HEADER2
|
|
34
30
|
} from "./index-n15jny5b.js";
|
|
31
|
+
import {
|
|
32
|
+
isModuleNotFound
|
|
33
|
+
} from "./index-srs8hj9c.js";
|
|
35
34
|
import {
|
|
36
35
|
assertCorsConfig,
|
|
37
36
|
isOriginAllowed,
|
|
@@ -50,7 +49,7 @@ import {
|
|
|
50
49
|
getRequestContext2,
|
|
51
50
|
setRequestEndpoint2,
|
|
52
51
|
setRequestError2
|
|
53
|
-
} from "./index-
|
|
52
|
+
} from "./index-7n68nmc6.js";
|
|
54
53
|
import {
|
|
55
54
|
resolveTraceId2,
|
|
56
55
|
resolveSocketIp2,
|
|
@@ -2341,55 +2340,6 @@ function bindProcessSignals2(handle, options = {}) {
|
|
|
2341
2340
|
return { promise, close };
|
|
2342
2341
|
}
|
|
2343
2342
|
|
|
2344
|
-
// src/server/realtime.ts
|
|
2345
|
-
function bindRealtimeServer2(contract, handle, options = {}) {
|
|
2346
|
-
const outbound = (target) => createValidatedRealtimeSocket({
|
|
2347
|
-
target,
|
|
2348
|
-
inbound: {},
|
|
2349
|
-
outbound: contract.serverToClient,
|
|
2350
|
-
inboundDirection: "server-inbound",
|
|
2351
|
-
outboundDirection: "server-outbound",
|
|
2352
|
-
onRejected: options.onRejected,
|
|
2353
|
-
logger: options.logger
|
|
2354
|
-
});
|
|
2355
|
-
const broadcast = outbound(handle.io);
|
|
2356
|
-
return {
|
|
2357
|
-
onConnection: (handler) => {
|
|
2358
|
-
const listener = (raw) => {
|
|
2359
|
-
const events = createValidatedRealtimeSocket({
|
|
2360
|
-
target: raw,
|
|
2361
|
-
inbound: contract.clientToServer,
|
|
2362
|
-
outbound: contract.serverToClient,
|
|
2363
|
-
inboundDirection: "server-inbound",
|
|
2364
|
-
outboundDirection: "server-outbound",
|
|
2365
|
-
onRejected: options.onRejected,
|
|
2366
|
-
logger: options.logger
|
|
2367
|
-
});
|
|
2368
|
-
const failed = (error) => {
|
|
2369
|
-
try {
|
|
2370
|
-
raw.disconnect(true);
|
|
2371
|
-
} catch {}
|
|
2372
|
-
if (options.logger)
|
|
2373
|
-
options.logger.error("Realtime connection handler failed", { error });
|
|
2374
|
-
else
|
|
2375
|
-
console.error("[stitchkit] realtime connection handler failed", error);
|
|
2376
|
-
};
|
|
2377
|
-
try {
|
|
2378
|
-
Promise.resolve(handler({ raw, events, to: (room) => outbound(raw.to(room)) })).catch(failed);
|
|
2379
|
-
} catch (error) {
|
|
2380
|
-
failed(error);
|
|
2381
|
-
}
|
|
2382
|
-
};
|
|
2383
|
-
handle.io.on("connection", listener);
|
|
2384
|
-
return () => {
|
|
2385
|
-
handle.io.off("connection", listener);
|
|
2386
|
-
};
|
|
2387
|
-
},
|
|
2388
|
-
emit: broadcast.emit,
|
|
2389
|
-
to: (room) => outbound(handle.io.to(room))
|
|
2390
|
-
};
|
|
2391
|
-
}
|
|
2392
|
-
|
|
2393
2343
|
// src/server/websocket.ts
|
|
2394
2344
|
function webSocketLane2(lane) {
|
|
2395
2345
|
const { match, handlers } = lane;
|
|
@@ -3499,4 +3449,4 @@ function createUnixClientTransport2(config) {
|
|
|
3499
3449
|
};
|
|
3500
3450
|
}
|
|
3501
3451
|
|
|
3502
|
-
export { contextContributionDelta, prepareContextContribution, mergeContextContribution, parseMultipart2, DEFAULT_STREAM_HEARTBEAT_MS2, streamingRoute2, ndjsonRoute2, sseRoute2, createHandler2, createScopedImplementRegistry2, implementRegistry2, createImplementRegistry2, bindProcessSignals2,
|
|
3452
|
+
export { contextContributionDelta, prepareContextContribution, mergeContextContribution, parseMultipart2, DEFAULT_STREAM_HEARTBEAT_MS2, streamingRoute2, ndjsonRoute2, sseRoute2, createHandler2, createScopedImplementRegistry2, implementRegistry2, createImplementRegistry2, bindProcessSignals2, webSocketLane2, composeWebSocketHandlers2, createSocketIOServer2, socketIoLane2, UnixClientTransportError2, createUnixClientTransport2 };
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
crypto.getRandomValues(arr);
|
|
5
|
-
let hex = "";
|
|
6
|
-
for (const byte of arr)
|
|
7
|
-
hex += byte.toString(16).padStart(2, "0");
|
|
8
|
-
return hex;
|
|
9
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
randomHex
|
|
3
|
+
} from "./index-c9d05kvt.js";
|
|
10
4
|
|
|
11
5
|
// src/observability/trace.ts
|
|
12
6
|
var TRACEPARENT_RE = /^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})(.*)$/i;
|
|
@@ -80,4 +74,4 @@ function resolvePropagationContext2(metadata, fallback) {
|
|
|
80
74
|
};
|
|
81
75
|
}
|
|
82
76
|
|
|
83
|
-
export {
|
|
77
|
+
export { createTraceContext2, parseTraceparent2, formatTraceparent2, resolveTraceContext2, childSpan2, resolvePropagationContext2 };
|
|
@@ -12,21 +12,19 @@ import {
|
|
|
12
12
|
AgentSnapshotSchema2
|
|
13
13
|
} from "./index-8kzct1d6.js";
|
|
14
14
|
import {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
ToolExecutionControlError2,
|
|
16
|
+
isToolExecutionControlError2
|
|
17
|
+
} from "./index-0efgsyav.js";
|
|
17
18
|
import {
|
|
18
|
-
AgentRuntimeEventSchema2,
|
|
19
19
|
agentDurableEventId2
|
|
20
20
|
} from "./index-mnkk1ffz.js";
|
|
21
21
|
import {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
} from "./index-dvwj1f43.js";
|
|
22
|
+
createLocalStepDurability2
|
|
23
|
+
} from "./index-5vyd0fkb.js";
|
|
25
24
|
import {
|
|
26
|
-
createLocalStepDurability2,
|
|
27
25
|
isAgentToolError2,
|
|
28
26
|
createToolDurabilityContext
|
|
29
|
-
} from "./index-
|
|
27
|
+
} from "./index-nggfa2yn.js";
|
|
30
28
|
import {
|
|
31
29
|
canonicalAgentJson2,
|
|
32
30
|
createToolChronology,
|
|
@@ -324,27 +322,6 @@ function createAgentSessionCoordinator2() {
|
|
|
324
322
|
};
|
|
325
323
|
}
|
|
326
324
|
|
|
327
|
-
// src/agent-runtime/events.ts
|
|
328
|
-
function createAgentRuntimeEventSink2(config) {
|
|
329
|
-
const manager = createBoundedSinkManager({
|
|
330
|
-
write: config.write,
|
|
331
|
-
...config.maxPending !== undefined && { maxPending: config.maxPending },
|
|
332
|
-
...config.onSinkError && { onSinkError: config.onSinkError },
|
|
333
|
-
...config.onDrop && { onDrop: config.onDrop }
|
|
334
|
-
});
|
|
335
|
-
return {
|
|
336
|
-
publish(rawEvent) {
|
|
337
|
-
const event = AgentRuntimeEventSchema2.parse(rawEvent);
|
|
338
|
-
const projected = config.project?.(event) ?? (config.project ? undefined : event);
|
|
339
|
-
if (projected)
|
|
340
|
-
manager.submit(() => AgentRuntimeEventSchema2.parse(projected));
|
|
341
|
-
},
|
|
342
|
-
flush: (bound) => manager.flush(bound),
|
|
343
|
-
getStatus: () => manager.getStatus(),
|
|
344
|
-
close: (bound) => manager.close(bound)
|
|
345
|
-
};
|
|
346
|
-
}
|
|
347
|
-
|
|
348
325
|
// src/agent-runtime/history.ts
|
|
349
326
|
import { modelMessageSchema as modelMessageSchema2 } from "ai";
|
|
350
327
|
|
|
@@ -4310,4 +4287,4 @@ function createAgentRuntime2(config) {
|
|
|
4310
4287
|
};
|
|
4311
4288
|
}
|
|
4312
4289
|
|
|
4313
|
-
export { AgentRuntimeConflictError2, normalizeSdkUsage, AgentContextOverflowError2, createAgentSessionCoordinator2, registerDeferredToolRepair, registerDeferredToolCatalog, deferredToolCatalog, repairedSearchCall,
|
|
4290
|
+
export { AgentRuntimeConflictError2, normalizeSdkUsage, AgentContextOverflowError2, createAgentSessionCoordinator2, registerDeferredToolRepair, registerDeferredToolCatalog, deferredToolCatalog, repairedSearchCall, projectAgentHistoryDetailed2, projectAgentHistory2, ModelInvocationTraceSchema2, CompletionInvocationInputSchema2, ModelInvocationRecordSchema2, currentModelInvocationAttempt2, createModelInvocationLedger2, createAgentToolFenceLifecycle2, AgentTokenCountSchema2, selectAgentHistory2, composeAgentPrompt2, AgentProviderStreamCutError2, classifyProviderFailure2, isToolResultFailure2, recordAgentRetryDecision2, defineStateSlot2, createAgentStateSlotStore2, renderAgentStateSlots2, agentGoalStateSlot2, agentTodoStateSlot2, createAgentRuntime2 };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// src/tools/lifecycle.ts
|
|
2
|
+
function composeToolLifecycle2(...hooks) {
|
|
3
|
+
return {
|
|
4
|
+
beforeHandle: async (ctx, endpoint) => {
|
|
5
|
+
for (const hook of hooks)
|
|
6
|
+
await hook?.beforeHandle?.(ctx, endpoint);
|
|
7
|
+
},
|
|
8
|
+
afterHandle: async (ctx, result, endpoint) => {
|
|
9
|
+
let current = result;
|
|
10
|
+
for (const hook of hooks) {
|
|
11
|
+
const transformed = await hook?.afterHandle?.(ctx, current, endpoint);
|
|
12
|
+
if (transformed !== undefined)
|
|
13
|
+
current = transformed;
|
|
14
|
+
}
|
|
15
|
+
return current;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { composeToolLifecycle2 };
|
|
@@ -7,6 +7,7 @@ Contains: API reference: `stitchkit/agent-runtime/browser` (docs/api/reference.
|
|
|
7
7
|
|
|
8
8
|
Also read:
|
|
9
9
|
- see `llms/agent-runtime.txt` for the Agent application runtime guide
|
|
10
|
+
- see `llms/agent-runtime-harness.txt` for the Agent composition guide
|
|
10
11
|
|
|
11
12
|
==============================================================================
|
|
12
13
|
# API reference: `stitchkit/agent-runtime/browser` (docs/api/reference.md)
|
|
@@ -31,3 +32,28 @@ Use this entrypoint from client components and shared DTO packages. The full
|
|
|
31
32
|
`stitchkit/agent-runtime` entrypoint remains server-only.
|
|
32
33
|
|
|
33
34
|
---
|
|
35
|
+
|
|
36
|
+
### Browser control composition
|
|
37
|
+
|
|
38
|
+
`AgentBrowserRequestSchema` / `AgentBrowserRequest` derive from the trusted control
|
|
39
|
+
protocol but exclude runtime `context`. Submit permits only strict text/file parts;
|
|
40
|
+
file ownership and metadata policy are checked by server authorization. The shared
|
|
41
|
+
`agentControlRealtimeContract` owns `agent:control` acknowledgements and `agent:delivery`.
|
|
42
|
+
|
|
43
|
+
`createAgentController` / `AgentControllerConfig` take an existing Stitchkit
|
|
44
|
+
realtime `transport`, `conversationId`, `access` (`observe` or `control`), optional
|
|
45
|
+
`timeoutMs` (10000), `maxBufferedEvents` (256), `maxBufferedBytes` (1048576) and
|
|
46
|
+
`maxPendingRequests` (32). All bounds are positive safe integers. One controller owns one
|
|
47
|
+
attachment per conversation on that transport; share the controller between views.
|
|
48
|
+
|
|
49
|
+
`AgentController` exposes stable `subscribe`, `getSnapshot`, `request(command)` and async
|
|
50
|
+
`close`. `AgentBrowserCommand` uses the canonical operations, without request/conversation identity;
|
|
51
|
+
`submit` requires a caller-owned idempotency key. Unknown-outcome mutations are never
|
|
52
|
+
replayed automatically. `AgentControllerState` distinguishes connecting, ready,
|
|
53
|
+
disconnected, error and closed and retains the canonical full `view` plus safe error
|
|
54
|
+
code/message. Errors in automatic attach/refresh appear there. Reconnect attaches again
|
|
55
|
+
and reads a snapshot; snapshot gaps coalesce, stale generations cannot overwrite state,
|
|
56
|
+
and buffers/queues are bounded. Overflow or failed refresh is visible and requires
|
|
57
|
+
explicit recovery. Closing detaches without closing the shared transport or remote run.
|
|
58
|
+
|
|
59
|
+
See [agent composition](../guide/agent-composition.md) for a complete wiring example.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# stitchkit/agent-runtime/harness-tools — stitchkit docs slice
|
|
2
|
+
|
|
3
|
+
> Generated from the `docs/` tree by `bun run gen:llms`. The index of all slices is
|
|
4
|
+
> `llms.txt` in this package.
|
|
5
|
+
|
|
6
|
+
Contains: API reference: `stitchkit/agent-runtime/harness-tools` (docs/api/reference.md)
|
|
7
|
+
|
|
8
|
+
Also read:
|
|
9
|
+
- see `llms/agent-runtime.txt` for the Agent application runtime guide
|
|
10
|
+
- see `llms/agent-runtime-harness.txt` for the Agent composition guide
|
|
11
|
+
|
|
12
|
+
==============================================================================
|
|
13
|
+
# API reference: `stitchkit/agent-runtime/harness-tools` (docs/api/reference.md)
|
|
14
|
+
==============================================================================
|
|
15
|
+
|
|
16
|
+
## `stitchkit/agent-runtime/harness-tools`
|
|
17
|
+
|
|
18
|
+
Optional evolving composition of the full `mountAgent` configuration with the runtime
|
|
19
|
+
fence. Its runtime peer is `ai`; its full tool presenter declarations also require
|
|
20
|
+
`@modelcontextprotocol/server`, as `stitchkit/tools` does. The base harness retains its
|
|
21
|
+
AI-only peer boundary. Existing custom tool callbacks need no new import.
|
|
22
|
+
|
|
23
|
+
| Export | Kind | Summary |
|
|
24
|
+
|--------|------|---------|
|
|
25
|
+
| `createAgentHarnessTools` / `AgentHarnessToolsConfig` | function / _type_ | async per-run full mount configuration (`services` plus all `AgentMountConfig` options); composes application lifecycle then runtime fence exactly once |
|