@goodtiming/baton-sdk 0.5.4 → 0.5.6
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/dist/index.cjs +33 -52
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +41 -4
- package/dist/index.d.ts +41 -4
- package/dist/index.js +33 -52
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -93,7 +93,7 @@ __export(index_exports, {
|
|
|
93
93
|
module.exports = __toCommonJS(index_exports);
|
|
94
94
|
|
|
95
95
|
// src/version.ts
|
|
96
|
-
var SDK_VERSION = "ts-0.5.
|
|
96
|
+
var SDK_VERSION = "ts-0.5.6";
|
|
97
97
|
|
|
98
98
|
// src/events.ts
|
|
99
99
|
var import_zod = require("zod");
|
|
@@ -204,7 +204,6 @@ var AnnotationPayloadSchema = import_zod.z.object({
|
|
|
204
204
|
workflow: import_zod.z.string().nullable().default(null),
|
|
205
205
|
suggested_improvement: import_zod.z.string().nullable().default(null),
|
|
206
206
|
context: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).nullable().default(null),
|
|
207
|
-
intent_source: import_zod.z.string().nullable().default(null),
|
|
208
207
|
tool_name: import_zod.z.string().nullable().default(null)
|
|
209
208
|
}).strict();
|
|
210
209
|
var SurfaceSnapshotPayloadSchema = import_zod.z.object({
|
|
@@ -240,6 +239,7 @@ var envelopeShape = {
|
|
|
240
239
|
agent_runtime: import_zod.z.string().default("unknown"),
|
|
241
240
|
principal: PrincipalWireSchema.nullable().default(null),
|
|
242
241
|
transport_observed: import_zod.z.string().nullable().default(null),
|
|
242
|
+
session_id_origin: import_zod.z.string().nullable().default(null),
|
|
243
243
|
client_observed: ClientObservedSchema.nullable().default(null),
|
|
244
244
|
call_id: import_zod.z.string().nullable().default(null),
|
|
245
245
|
runtime_meta: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).nullable().default(null)
|
|
@@ -1213,8 +1213,20 @@ function observeClient(extra, options) {
|
|
|
1213
1213
|
|
|
1214
1214
|
// src/integrations/mcp/sessionResolution.ts
|
|
1215
1215
|
async function resolveSessionId(fallbackSessionId, extra) {
|
|
1216
|
-
if (typeof extra.sessionId === "string" && extra.sessionId)
|
|
1217
|
-
|
|
1216
|
+
if (typeof extra.sessionId === "string" && extra.sessionId) {
|
|
1217
|
+
return { sessionId: extra.sessionId, origin: "observed" };
|
|
1218
|
+
}
|
|
1219
|
+
const fromHeader = sessionIdFromHeader(extra);
|
|
1220
|
+
if (fromHeader !== null) return { sessionId: fromHeader, origin: "observed" };
|
|
1221
|
+
return { sessionId: fallbackSessionId, origin: "minted" };
|
|
1222
|
+
}
|
|
1223
|
+
function sessionIdFromHeader(extra) {
|
|
1224
|
+
try {
|
|
1225
|
+
const value = extraHeaders(extra)?.get("mcp-session-id")?.trim();
|
|
1226
|
+
return value ? value : null;
|
|
1227
|
+
} catch {
|
|
1228
|
+
return null;
|
|
1229
|
+
}
|
|
1218
1230
|
}
|
|
1219
1231
|
|
|
1220
1232
|
// src/integrations/mcp/annotation.ts
|
|
@@ -1265,7 +1277,7 @@ function registerAnnotationTool(server, options) {
|
|
|
1265
1277
|
meta ? roundMetaCoordinates(meta) : null,
|
|
1266
1278
|
"_meta"
|
|
1267
1279
|
);
|
|
1268
|
-
const sessionId = await resolveSessionId(options.fallbackSessionId, extra);
|
|
1280
|
+
const { sessionId, origin } = await resolveSessionId(options.fallbackSessionId, extra);
|
|
1269
1281
|
const principal = await resolveCallPrincipal(
|
|
1270
1282
|
options.resolvePrincipal,
|
|
1271
1283
|
{ extra, toolName: name, arguments: args }
|
|
@@ -1281,6 +1293,7 @@ function registerAnnotationTool(server, options) {
|
|
|
1281
1293
|
consent_token: options.consentToken,
|
|
1282
1294
|
principal,
|
|
1283
1295
|
transport_observed: observeTransport(extra),
|
|
1296
|
+
session_id_origin: origin,
|
|
1284
1297
|
client_observed: observeClient(extra, { server, scrubber: options.scrubber }),
|
|
1285
1298
|
runtime_meta: scrubbedMeta,
|
|
1286
1299
|
payload: {
|
|
@@ -1753,18 +1766,6 @@ var BatonHandle = class {
|
|
|
1753
1766
|
}
|
|
1754
1767
|
};
|
|
1755
1768
|
|
|
1756
|
-
// src/integrations/mcp/proactiveTracker.ts
|
|
1757
|
-
var ProactiveTracker = class {
|
|
1758
|
-
emitted = /* @__PURE__ */ new Set();
|
|
1759
|
-
/** Claim the session's proactive slot. Returns true exactly once per
|
|
1760
|
-
* session (the caller should then emit); false if already claimed. */
|
|
1761
|
-
claim(sessionId) {
|
|
1762
|
-
if (this.emitted.has(sessionId)) return false;
|
|
1763
|
-
this.emitted.add(sessionId);
|
|
1764
|
-
return true;
|
|
1765
|
-
}
|
|
1766
|
-
};
|
|
1767
|
-
|
|
1768
1769
|
// src/integrations/mcp/sessionCounter.ts
|
|
1769
1770
|
var SessionCounter = class {
|
|
1770
1771
|
counters = /* @__PURE__ */ new Map();
|
|
@@ -2040,12 +2041,12 @@ function messageOf(err) {
|
|
|
2040
2041
|
async function resolveEnvelopeParts(ctx, extra) {
|
|
2041
2042
|
const meta = extraMeta(extra);
|
|
2042
2043
|
const scrubbedMeta = scrubOrNull(ctx.scrubber, meta ? roundMetaCoordinates(meta) : null, "_meta");
|
|
2043
|
-
const
|
|
2044
|
-
return {
|
|
2044
|
+
const session = await resolveSessionId(ctx.fallbackSessionId, extra);
|
|
2045
|
+
return { ...session, scrubbedMeta };
|
|
2045
2046
|
}
|
|
2046
2047
|
async function openCall(ctx, toolName, extra, params, registered = true) {
|
|
2047
2048
|
await maybeEmitSurfaceSnapshot(ctx);
|
|
2048
|
-
const { sessionId, scrubbedMeta } = await resolveEnvelopeParts(ctx, extra);
|
|
2049
|
+
const { sessionId, origin, scrubbedMeta } = await resolveEnvelopeParts(ctx, extra);
|
|
2049
2050
|
const dispositions = ctx.paramRegistry.get(toolName);
|
|
2050
2051
|
const rawIntent = extractGoalParam(params, USER_GOAL_PARAM_NAME, toolName, dispositions, registered);
|
|
2051
2052
|
const rawExpected = extractGoalParam(
|
|
@@ -2059,7 +2060,6 @@ async function openCall(ctx, toolName, extra, params, registered = true) {
|
|
|
2059
2060
|
const scrubbedIntent = scrubOrNull(ctx.scrubber, rawIntent, USER_GOAL_PARAM_NAME);
|
|
2060
2061
|
const scrubbedExpected = scrubOrNull(ctx.scrubber, rawExpected, EXPECTED_RESULT_PARAM_NAME);
|
|
2061
2062
|
const scrubbedWorkflow = scrubOrNull(ctx.scrubber, rawWorkflow, OVERALL_TASK_PARAM_NAME);
|
|
2062
|
-
const callId = uuid7();
|
|
2063
2063
|
const principal = await resolveCallPrincipal(
|
|
2064
2064
|
ctx.resolvePrincipal,
|
|
2065
2065
|
{ extra, toolName, arguments: params }
|
|
@@ -2069,35 +2069,21 @@ async function openCall(ctx, toolName, extra, params, registered = true) {
|
|
|
2069
2069
|
vendor_id: ctx.vendorId,
|
|
2070
2070
|
session_id: sessionId,
|
|
2071
2071
|
consent_token: ctx.consentToken,
|
|
2072
|
-
// Every `...common` site is an event
|
|
2073
|
-
// is deliberately not among them: it describes the
|
|
2074
|
-
// outside any call, so it has no caller, transport
|
|
2072
|
+
// Every `...common` site is an event of this call, so `call_id` rides in
|
|
2073
|
+
// it. `surface_snapshot` is deliberately not among them: it describes the
|
|
2074
|
+
// SERVER and is captured outside any call, so it has no caller, transport
|
|
2075
|
+
// or client to name.
|
|
2075
2076
|
principal,
|
|
2076
2077
|
transport_observed: observeTransport(extra),
|
|
2078
|
+
session_id_origin: origin,
|
|
2077
2079
|
client_observed: observeClient(extra, ctx),
|
|
2078
|
-
runtime_meta: scrubbedMeta
|
|
2080
|
+
runtime_meta: scrubbedMeta,
|
|
2081
|
+
call_id: uuid7()
|
|
2079
2082
|
};
|
|
2080
|
-
if (scrubbedIntent !== null && ctx.tracker.claim(sessionId)) {
|
|
2081
|
-
await emit(
|
|
2082
|
-
ctx.sink,
|
|
2083
|
-
() => AnnotationEventSchema.parse({
|
|
2084
|
-
...common,
|
|
2085
|
-
sequence_number: ctx.counter.next(sessionId),
|
|
2086
|
-
captured_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2087
|
-
payload: {
|
|
2088
|
-
intent: scrubbedIntent,
|
|
2089
|
-
expected_outcome: scrubbedExpected,
|
|
2090
|
-
intent_source: INTENT_SOURCE_PARAM,
|
|
2091
|
-
tool_name: toolName
|
|
2092
|
-
}
|
|
2093
|
-
})
|
|
2094
|
-
);
|
|
2095
|
-
}
|
|
2096
2083
|
await emit(
|
|
2097
2084
|
ctx.sink,
|
|
2098
2085
|
() => ToolCallStartEventSchema.parse({
|
|
2099
2086
|
...common,
|
|
2100
|
-
call_id: callId,
|
|
2101
2087
|
sequence_number: ctx.counter.next(sessionId),
|
|
2102
2088
|
captured_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2103
2089
|
payload: {
|
|
@@ -2111,7 +2097,7 @@ async function openCall(ctx, toolName, extra, params, registered = true) {
|
|
|
2111
2097
|
}
|
|
2112
2098
|
})
|
|
2113
2099
|
);
|
|
2114
|
-
return { common,
|
|
2100
|
+
return { common, sessionId };
|
|
2115
2101
|
}
|
|
2116
2102
|
function batonWrap(nameRef, original, ctx) {
|
|
2117
2103
|
return async (...callArgs) => {
|
|
@@ -2120,7 +2106,7 @@ function batonWrap(nameRef, original, ctx) {
|
|
|
2120
2106
|
if (slot) slot.innerFired = true;
|
|
2121
2107
|
const extra = callArgs[callArgs.length - 1];
|
|
2122
2108
|
const params = (callArgs.length > 1 ? callArgs[0] : void 0) ?? {};
|
|
2123
|
-
const { common,
|
|
2109
|
+
const { common, sessionId } = await openCall(ctx, toolName, extra, params);
|
|
2124
2110
|
const terminate = async (build, replacement) => {
|
|
2125
2111
|
if (!slot) {
|
|
2126
2112
|
await emit(ctx.sink, build);
|
|
@@ -2146,7 +2132,6 @@ function batonWrap(nameRef, original, ctx) {
|
|
|
2146
2132
|
await parkFailure(
|
|
2147
2133
|
() => ToolCallErrorEventSchema.parse({
|
|
2148
2134
|
...common,
|
|
2149
|
-
call_id: callId,
|
|
2150
2135
|
sequence_number: ctx.counter.next(sessionId),
|
|
2151
2136
|
captured_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2152
2137
|
payload: {
|
|
@@ -2182,7 +2167,6 @@ function batonWrap(nameRef, original, ctx) {
|
|
|
2182
2167
|
await parkFailure(
|
|
2183
2168
|
() => ToolCallErrorEventSchema.parse({
|
|
2184
2169
|
...common,
|
|
2185
|
-
call_id: callId,
|
|
2186
2170
|
sequence_number: ctx.counter.next(sessionId),
|
|
2187
2171
|
captured_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2188
2172
|
payload: {
|
|
@@ -2213,7 +2197,6 @@ function batonWrap(nameRef, original, ctx) {
|
|
|
2213
2197
|
await parkSuccess(
|
|
2214
2198
|
() => ToolCallEndEventSchema.parse({
|
|
2215
2199
|
...common,
|
|
2216
|
-
call_id: callId,
|
|
2217
2200
|
sequence_number: ctx.counter.next(sessionId),
|
|
2218
2201
|
captured_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2219
2202
|
payload: {
|
|
@@ -2230,7 +2213,6 @@ function batonWrap(nameRef, original, ctx) {
|
|
|
2230
2213
|
// CALLER saw fail, which is a success the product invented.
|
|
2231
2214
|
(outcome) => ToolCallErrorEventSchema.parse({
|
|
2232
2215
|
...common,
|
|
2233
|
-
call_id: callId,
|
|
2234
2216
|
sequence_number: ctx.counter.next(sessionId),
|
|
2235
2217
|
captured_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2236
2218
|
payload: {
|
|
@@ -2459,6 +2441,7 @@ async function openLifecycleCall(ctx, spec, requestParams, extra) {
|
|
|
2459
2441
|
consent_token: ctx.consentToken,
|
|
2460
2442
|
principal,
|
|
2461
2443
|
transport_observed: observeTransport(extra),
|
|
2444
|
+
session_id_origin: parts.origin,
|
|
2462
2445
|
client_observed: observeClient(extra, ctx),
|
|
2463
2446
|
runtime_meta: parts.scrubbedMeta
|
|
2464
2447
|
}
|
|
@@ -2623,7 +2606,7 @@ async function emitRequestSideFailure(outcome, args, toolEntry, ctx) {
|
|
|
2623
2606
|
const entry = toolEntry(toolName);
|
|
2624
2607
|
if (entry != null && dispatchTarget(entry)?.[BATON_WRAPPED] !== true) return;
|
|
2625
2608
|
const params = { ...request?.params?.arguments ?? {} };
|
|
2626
|
-
const { common,
|
|
2609
|
+
const { common, sessionId } = await openCall(
|
|
2627
2610
|
ctx,
|
|
2628
2611
|
toolName,
|
|
2629
2612
|
args[1],
|
|
@@ -2635,7 +2618,6 @@ async function emitRequestSideFailure(outcome, args, toolEntry, ctx) {
|
|
|
2635
2618
|
ctx.sink,
|
|
2636
2619
|
() => ToolCallErrorEventSchema.parse({
|
|
2637
2620
|
...common,
|
|
2638
|
-
call_id: callId,
|
|
2639
2621
|
sequence_number: ctx.counter.next(sessionId),
|
|
2640
2622
|
captured_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2641
2623
|
payload: {
|
|
@@ -2796,6 +2778,7 @@ function install(server, supplied, resolved, emittedSurfaceHashes) {
|
|
|
2796
2778
|
tenant_id: tenantId,
|
|
2797
2779
|
vendor_id: config.vendorId,
|
|
2798
2780
|
session_id: sessionId,
|
|
2781
|
+
session_id_origin: "minted",
|
|
2799
2782
|
consent_token: config.consentToken,
|
|
2800
2783
|
sequence_number: counter2.next(sessionId),
|
|
2801
2784
|
captured_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -2844,7 +2827,6 @@ function install(server, supplied, resolved, emittedSurfaceHashes) {
|
|
|
2844
2827
|
return { type: "object", properties: {} };
|
|
2845
2828
|
}
|
|
2846
2829
|
};
|
|
2847
|
-
const tracker = new ProactiveTracker();
|
|
2848
2830
|
const ctx = {
|
|
2849
2831
|
sink,
|
|
2850
2832
|
counter: counter2,
|
|
@@ -2862,7 +2844,6 @@ function install(server, supplied, resolved, emittedSurfaceHashes) {
|
|
|
2862
2844
|
vendorToolJsonSchema,
|
|
2863
2845
|
bustSchemaMemo,
|
|
2864
2846
|
dropSubagentClause,
|
|
2865
|
-
tracker,
|
|
2866
2847
|
surfaceState,
|
|
2867
2848
|
emitSurface
|
|
2868
2849
|
};
|