@goodtiming/baton-sdk 1.3.1 → 1.3.2
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/README.md +1 -1
- package/dist/index.cjs +147 -49
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -4
- package/dist/index.d.ts +9 -4
- package/dist/index.js +147 -49
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
|
-
declare const SDK_VERSION = "ts-1.3.
|
|
3
|
+
declare const SDK_VERSION = "ts-1.3.2";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Zod schemas + TS types for the Baton event stream per SPEC §11.4.
|
|
@@ -251,8 +251,10 @@ type PromptListErrorPayload = z.infer<typeof PromptListErrorPayloadSchema>;
|
|
|
251
251
|
declare const ToolListStartPayloadSchema: z.ZodObject<{}, z.core.$strict>;
|
|
252
252
|
type ToolListStartPayload = z.infer<typeof ToolListStartPayloadSchema>;
|
|
253
253
|
/** `tools/list` returned. `count` is the length of the `tools` array in that
|
|
254
|
-
* one response, this SDK's own tool included.
|
|
254
|
+
* one response, this SDK's own tool included. `surface_hash` is that of the
|
|
255
|
+
* `surface_snapshot` describing the response, when one was captured. */
|
|
255
256
|
declare const ToolListEndPayloadSchema: z.ZodObject<{
|
|
257
|
+
surface_hash: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
256
258
|
duration_ms: z.ZodDefault<z.ZodNullable<z.ZodNumber>>;
|
|
257
259
|
count: z.ZodNumber;
|
|
258
260
|
}, z.core.$strict>;
|
|
@@ -1286,6 +1288,7 @@ type ToolListStartEvent = z.infer<typeof ToolListStartEventSchema>;
|
|
|
1286
1288
|
declare const ToolListEndEventSchema: z.ZodObject<{
|
|
1287
1289
|
event_type: z.ZodDefault<z.ZodLiteral<"tool_list_end">>;
|
|
1288
1290
|
payload: z.ZodObject<{
|
|
1291
|
+
surface_hash: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1289
1292
|
duration_ms: z.ZodDefault<z.ZodNullable<z.ZodNumber>>;
|
|
1290
1293
|
count: z.ZodNumber;
|
|
1291
1294
|
}, z.core.$strict>;
|
|
@@ -2340,6 +2343,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
2340
2343
|
}, z.core.$strict>, z.ZodObject<{
|
|
2341
2344
|
event_type: z.ZodDefault<z.ZodLiteral<"tool_list_end">>;
|
|
2342
2345
|
payload: z.ZodObject<{
|
|
2346
|
+
surface_hash: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
2343
2347
|
duration_ms: z.ZodDefault<z.ZodNullable<z.ZodNumber>>;
|
|
2344
2348
|
count: z.ZodNumber;
|
|
2345
2349
|
}, z.core.$strict>;
|
|
@@ -3096,8 +3100,9 @@ interface BatonConfig {
|
|
|
3096
3100
|
* function that returns them. Read once per `withBaton` or `createBaton`.
|
|
3097
3101
|
* Without it Baton learns the tools from the lists its servers serve, so a
|
|
3098
3102
|
* process that has served none yet, such as a fresh worker, takes
|
|
3099
|
-
* `user_goal` off every call, even from a tool that declares its own.
|
|
3100
|
-
*
|
|
3103
|
+
* `user_goal` off every call, even from a tool that declares its own. The
|
|
3104
|
+
* surface snapshot comes only from the lists a server serves, never from
|
|
3105
|
+
* this. An `McpServer` does not read it. */
|
|
3101
3106
|
tools?: readonly unknown[] | (() => readonly unknown[]);
|
|
3102
3107
|
}
|
|
3103
3108
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
|
-
declare const SDK_VERSION = "ts-1.3.
|
|
3
|
+
declare const SDK_VERSION = "ts-1.3.2";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Zod schemas + TS types for the Baton event stream per SPEC §11.4.
|
|
@@ -251,8 +251,10 @@ type PromptListErrorPayload = z.infer<typeof PromptListErrorPayloadSchema>;
|
|
|
251
251
|
declare const ToolListStartPayloadSchema: z.ZodObject<{}, z.core.$strict>;
|
|
252
252
|
type ToolListStartPayload = z.infer<typeof ToolListStartPayloadSchema>;
|
|
253
253
|
/** `tools/list` returned. `count` is the length of the `tools` array in that
|
|
254
|
-
* one response, this SDK's own tool included.
|
|
254
|
+
* one response, this SDK's own tool included. `surface_hash` is that of the
|
|
255
|
+
* `surface_snapshot` describing the response, when one was captured. */
|
|
255
256
|
declare const ToolListEndPayloadSchema: z.ZodObject<{
|
|
257
|
+
surface_hash: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
256
258
|
duration_ms: z.ZodDefault<z.ZodNullable<z.ZodNumber>>;
|
|
257
259
|
count: z.ZodNumber;
|
|
258
260
|
}, z.core.$strict>;
|
|
@@ -1286,6 +1288,7 @@ type ToolListStartEvent = z.infer<typeof ToolListStartEventSchema>;
|
|
|
1286
1288
|
declare const ToolListEndEventSchema: z.ZodObject<{
|
|
1287
1289
|
event_type: z.ZodDefault<z.ZodLiteral<"tool_list_end">>;
|
|
1288
1290
|
payload: z.ZodObject<{
|
|
1291
|
+
surface_hash: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1289
1292
|
duration_ms: z.ZodDefault<z.ZodNullable<z.ZodNumber>>;
|
|
1290
1293
|
count: z.ZodNumber;
|
|
1291
1294
|
}, z.core.$strict>;
|
|
@@ -2340,6 +2343,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
2340
2343
|
}, z.core.$strict>, z.ZodObject<{
|
|
2341
2344
|
event_type: z.ZodDefault<z.ZodLiteral<"tool_list_end">>;
|
|
2342
2345
|
payload: z.ZodObject<{
|
|
2346
|
+
surface_hash: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
2343
2347
|
duration_ms: z.ZodDefault<z.ZodNullable<z.ZodNumber>>;
|
|
2344
2348
|
count: z.ZodNumber;
|
|
2345
2349
|
}, z.core.$strict>;
|
|
@@ -3096,8 +3100,9 @@ interface BatonConfig {
|
|
|
3096
3100
|
* function that returns them. Read once per `withBaton` or `createBaton`.
|
|
3097
3101
|
* Without it Baton learns the tools from the lists its servers serve, so a
|
|
3098
3102
|
* process that has served none yet, such as a fresh worker, takes
|
|
3099
|
-
* `user_goal` off every call, even from a tool that declares its own.
|
|
3100
|
-
*
|
|
3103
|
+
* `user_goal` off every call, even from a tool that declares its own. The
|
|
3104
|
+
* surface snapshot comes only from the lists a server serves, never from
|
|
3105
|
+
* this. An `McpServer` does not read it. */
|
|
3101
3106
|
tools?: readonly unknown[] | (() => readonly unknown[]);
|
|
3102
3107
|
}
|
|
3103
3108
|
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/version.ts
|
|
2
|
-
var SDK_VERSION = "ts-1.3.
|
|
2
|
+
var SDK_VERSION = "ts-1.3.2";
|
|
3
3
|
|
|
4
4
|
// src/events.ts
|
|
5
5
|
import { z } from "zod";
|
|
@@ -233,7 +233,8 @@ var PromptListErrorPayloadSchema = z.object({
|
|
|
233
233
|
var ToolListStartPayloadSchema = z.object({}).strict();
|
|
234
234
|
var ToolListEndPayloadSchema = z.object({
|
|
235
235
|
count: z.number().int(),
|
|
236
|
-
...timingShape
|
|
236
|
+
...timingShape,
|
|
237
|
+
surface_hash: z.string().nullable().optional()
|
|
237
238
|
}).strict();
|
|
238
239
|
var ToolListErrorPayloadSchema = z.object({
|
|
239
240
|
...failureShape
|
|
@@ -453,6 +454,9 @@ function isPlainObject(value) {
|
|
|
453
454
|
function isRecord(value) {
|
|
454
455
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
455
456
|
}
|
|
457
|
+
function jsonObjectCopy(value) {
|
|
458
|
+
return isRecord(value) ? JSON.parse(JSON.stringify(value)) : void 0;
|
|
459
|
+
}
|
|
456
460
|
|
|
457
461
|
// src/scrub.ts
|
|
458
462
|
var DEPTH_LIMIT = 10;
|
|
@@ -3031,12 +3035,14 @@ function standardInputJsonSchema(schema) {
|
|
|
3031
3035
|
}
|
|
3032
3036
|
}
|
|
3033
3037
|
function toolInputJsonSchema(inputSchema2) {
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3038
|
+
return toolJsonSchema(inputSchema2, "input") ?? EMPTY_OBJECT_JSON_SCHEMA;
|
|
3039
|
+
}
|
|
3040
|
+
function toolOutputJsonSchema(outputSchema) {
|
|
3041
|
+
return outputSchema ? toolJsonSchema(outputSchema, "output") : void 0;
|
|
3042
|
+
}
|
|
3043
|
+
function toolJsonSchema(schema, pipeStrategy) {
|
|
3044
|
+
const objSchema = normalizeObjectSchema(schema);
|
|
3045
|
+
return objSchema ? toJsonSchemaCompat(objSchema, { strictUnions: true, pipeStrategy }) : void 0;
|
|
3040
3046
|
}
|
|
3041
3047
|
|
|
3042
3048
|
// src/integrations/mcp/safeScrub.ts
|
|
@@ -3997,6 +4003,9 @@ function assembleSurface(serverMeta, tools) {
|
|
|
3997
4003
|
tools
|
|
3998
4004
|
};
|
|
3999
4005
|
}
|
|
4006
|
+
function isWholeList(cursor, nextCursor) {
|
|
4007
|
+
return (cursor === void 0 || cursor === null) && (nextCursor === void 0 || nextCursor === null);
|
|
4008
|
+
}
|
|
4000
4009
|
var SENT_SURFACES_CAP = 256;
|
|
4001
4010
|
var SentSurfaces = class {
|
|
4002
4011
|
hashes = /* @__PURE__ */ new Set();
|
|
@@ -4040,12 +4049,14 @@ var CLEAN_OUTCOME = { failed: false, raised: false, result: void 0 };
|
|
|
4040
4049
|
var INTENT_PARAM_NAMES = [USER_GOAL_PARAM_NAME, ...RETIRED_PARAM_NAMES];
|
|
4041
4050
|
var callSlots = new asyncHooks.AsyncLocalStorage();
|
|
4042
4051
|
var SurfaceState = class {
|
|
4043
|
-
constructor(serverMeta, sentSurfaces) {
|
|
4052
|
+
constructor(serverMeta, sentSurfaces, fromRegistry) {
|
|
4044
4053
|
this.serverMeta = serverMeta;
|
|
4045
4054
|
this.sentSurfaces = sentSurfaces;
|
|
4055
|
+
this.fromRegistry = fromRegistry;
|
|
4046
4056
|
}
|
|
4047
4057
|
serverMeta;
|
|
4048
4058
|
sentSurfaces;
|
|
4059
|
+
fromRegistry;
|
|
4049
4060
|
/** Every tool this install has seen, keyed by its CURRENT name. `disabled`
|
|
4050
4061
|
* is tracked alongside rather than pruned, so re-enabling costs nothing and
|
|
4051
4062
|
* — crucially — never needs a re-capture, which would re-read Baton's own
|
|
@@ -4053,20 +4064,74 @@ var SurfaceState = class {
|
|
|
4053
4064
|
rawTools = /* @__PURE__ */ new Map();
|
|
4054
4065
|
dirty = false;
|
|
4055
4066
|
servedOverlayId = null;
|
|
4067
|
+
listed = false;
|
|
4068
|
+
/** `null` when this version of the surface could not be captured. */
|
|
4069
|
+
captured;
|
|
4070
|
+
/** The surface each low-level request was served, keyed by the request,
|
|
4071
|
+
* which every seam passes on as it came. Kept apart from the current
|
|
4072
|
+
* surface, which another listing can change before this one's end is sent:
|
|
4073
|
+
* `surfaceAtList.test.ts`, "gives two listings that finish together each its own hash". */
|
|
4074
|
+
listedSurfaces = /* @__PURE__ */ new WeakMap();
|
|
4075
|
+
get hasSurface() {
|
|
4076
|
+
return this.fromRegistry || this.listed;
|
|
4077
|
+
}
|
|
4078
|
+
/** A low-level Server served `request` its whole list, which then is the
|
|
4079
|
+
* surface: `surfaceAtList.test.ts`, "snapshots each list as served". */
|
|
4080
|
+
servedList(request, names) {
|
|
4081
|
+
this.listed = true;
|
|
4082
|
+
for (const name of [...this.rawTools.keys()]) {
|
|
4083
|
+
if (!names.has(name)) this.pruneTool(name);
|
|
4084
|
+
}
|
|
4085
|
+
const surface = this.capture();
|
|
4086
|
+
if (surface !== null) this.listedSurfaces.set(request, surface);
|
|
4087
|
+
}
|
|
4088
|
+
/** The surface a `tools/list` request was served, when it got the whole list. */
|
|
4089
|
+
surfaceListed(request, served) {
|
|
4090
|
+
const listed = this.listedSurfaces.get(request);
|
|
4091
|
+
if (listed !== void 0) return listed;
|
|
4092
|
+
const cursor = isRecord(request.params) ? request.params.cursor : void 0;
|
|
4093
|
+
const whole = isWholeList(cursor, isRecord(served) ? served.nextCursor : void 0);
|
|
4094
|
+
return this.fromRegistry && whole ? this.capture() : null;
|
|
4095
|
+
}
|
|
4096
|
+
/** The surface as it stands, and its hash; built once per change, so a
|
|
4097
|
+
* surface that cannot be hashed is reported once, not on every request. */
|
|
4098
|
+
capture() {
|
|
4099
|
+
if (this.captured !== void 0) return this.captured;
|
|
4100
|
+
try {
|
|
4101
|
+
const snapshot = this.buildSnapshot();
|
|
4102
|
+
this.captured = { snapshot, digest: surfaceHash(snapshot) };
|
|
4103
|
+
} catch (err) {
|
|
4104
|
+
stderrLine(`baton: surface snapshot capture failed: ${printable(err)}`);
|
|
4105
|
+
this.captured = null;
|
|
4106
|
+
}
|
|
4107
|
+
return this.captured;
|
|
4108
|
+
}
|
|
4109
|
+
changed() {
|
|
4110
|
+
this.dirty = true;
|
|
4111
|
+
this.captured = void 0;
|
|
4112
|
+
}
|
|
4056
4113
|
/** `inputSchemaJson` is already converted — by `ctx.vendorToolJsonSchema`,
|
|
4057
4114
|
* which picks the spelling THIS SDK major puts on the wire. */
|
|
4058
|
-
noteTool(name, inputSchemaJson, description) {
|
|
4115
|
+
noteTool(name, inputSchemaJson, description, outputSchemaJson) {
|
|
4059
4116
|
const before = this.rawTools.get(name);
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
if (same) return;
|
|
4117
|
+
if (before !== void 0 && before.tool.description === (description ?? null)) {
|
|
4118
|
+
const sameInput = before.tool.inputSchema === inputSchemaJson || JSON.stringify(before.tool.inputSchema) === JSON.stringify(inputSchemaJson);
|
|
4119
|
+
if (sameInput && JSON.stringify(before.tool.outputSchema) === JSON.stringify(outputSchemaJson)) return;
|
|
4064
4120
|
}
|
|
4121
|
+
const tool = { name, description: description ?? null, inputSchema: inputSchemaJson };
|
|
4122
|
+
const outputSchema = jsonObjectCopy(outputSchemaJson);
|
|
4123
|
+
if (outputSchema !== void 0) tool.outputSchema = outputSchema;
|
|
4065
4124
|
this.rawTools.set(name, { disabled: before?.disabled ?? false, tool });
|
|
4066
|
-
this.
|
|
4125
|
+
this.changed();
|
|
4126
|
+
}
|
|
4127
|
+
setOutputSchema(name, outputSchemaJson) {
|
|
4128
|
+
const tool = this.rawTools.get(name)?.tool;
|
|
4129
|
+
if (tool === void 0) return;
|
|
4130
|
+
const description = typeof tool.description === "string" ? tool.description : void 0;
|
|
4131
|
+
this.noteTool(name, tool.inputSchema, description, outputSchemaJson);
|
|
4067
4132
|
}
|
|
4068
4133
|
pruneTool(name) {
|
|
4069
|
-
if (this.rawTools.delete(name)) this.
|
|
4134
|
+
if (this.rawTools.delete(name)) this.changed();
|
|
4070
4135
|
}
|
|
4071
4136
|
/** Follow a `update({name})` rename, keeping the snapshot keyed the way
|
|
4072
4137
|
* `tools/list` now renders it. */
|
|
@@ -4075,7 +4140,7 @@ var SurfaceState = class {
|
|
|
4075
4140
|
if (!entry) return;
|
|
4076
4141
|
this.rawTools.delete(from);
|
|
4077
4142
|
this.rawTools.set(to, { ...entry, tool: { ...entry.tool, name: to } });
|
|
4078
|
-
this.
|
|
4143
|
+
this.changed();
|
|
4079
4144
|
}
|
|
4080
4145
|
/** Both majors filter `tools/list` on `tool.enabled`, so a disabled tool is
|
|
4081
4146
|
* not part of the surface a client sees and must not be part of the one we
|
|
@@ -4085,7 +4150,7 @@ var SurfaceState = class {
|
|
|
4085
4150
|
const entry = this.rawTools.get(name);
|
|
4086
4151
|
if (!entry || entry.disabled === !enabled) return;
|
|
4087
4152
|
entry.disabled = !enabled;
|
|
4088
|
-
this.
|
|
4153
|
+
this.changed();
|
|
4089
4154
|
}
|
|
4090
4155
|
buildSnapshot() {
|
|
4091
4156
|
const names = [...this.rawTools.keys()].sort().filter((n) => !this.rawTools.get(n).disabled);
|
|
@@ -4360,6 +4425,7 @@ function stripIntentParams(params, ctx) {
|
|
|
4360
4425
|
return stripped;
|
|
4361
4426
|
}
|
|
4362
4427
|
async function maybeEmitSurfaceSnapshot(ctx) {
|
|
4428
|
+
if (!ctx.surfaceState.hasSurface) return;
|
|
4363
4429
|
const overlayId = ctx.perCaller?.serverOverlay?.id ?? null;
|
|
4364
4430
|
if (overlayId !== ctx.surfaceState.servedOverlayId) {
|
|
4365
4431
|
ctx.surfaceState.servedOverlayId = overlayId;
|
|
@@ -4367,17 +4433,13 @@ async function maybeEmitSurfaceSnapshot(ctx) {
|
|
|
4367
4433
|
}
|
|
4368
4434
|
if (!ctx.surfaceState.dirty) return;
|
|
4369
4435
|
ctx.surfaceState.dirty = false;
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
} catch (err) {
|
|
4376
|
-
stderrLine(`baton: surface snapshot capture failed: ${String(err)}`);
|
|
4377
|
-
return;
|
|
4378
|
-
}
|
|
4436
|
+
const surface = ctx.surfaceState.capture();
|
|
4437
|
+
if (surface !== null) await sendSurface(ctx, surface);
|
|
4438
|
+
}
|
|
4439
|
+
async function sendSurface(ctx, { snapshot, digest }) {
|
|
4440
|
+
const overlayId = ctx.perCaller?.serverOverlay?.id ?? null;
|
|
4379
4441
|
const sent = ctx.surfaceState.sentSurfaces;
|
|
4380
|
-
if (sent.wasSent(digest, overlayId)) return;
|
|
4442
|
+
if (sent.wasSent(digest, overlayId)) return digest;
|
|
4381
4443
|
sent.mark(digest, overlayId);
|
|
4382
4444
|
const seam = buildSeamAugmentations({
|
|
4383
4445
|
injectedToolNames: ctx.annotationToolName ? [ctx.annotationToolName] : [],
|
|
@@ -4394,6 +4456,16 @@ async function maybeEmitSurfaceSnapshot(ctx) {
|
|
|
4394
4456
|
});
|
|
4395
4457
|
if (ctx.captureSettings !== void 0) seam.server_overlay = overlayId;
|
|
4396
4458
|
await ctx.emitSurface(ctx.fallbackSessionId, digest, { ...snapshot, seam_augmentations: seam });
|
|
4459
|
+
return digest;
|
|
4460
|
+
}
|
|
4461
|
+
async function listedSurfaceFields(ctx, request, served) {
|
|
4462
|
+
try {
|
|
4463
|
+
const surface = isRecord(request) ? ctx.surfaceState.surfaceListed(request, served) : null;
|
|
4464
|
+
return surface === null ? {} : { surface_hash: await sendSurface(ctx, surface) };
|
|
4465
|
+
} catch (err) {
|
|
4466
|
+
stderrLine(`baton: surface snapshot capture failed: ${printable(err)}`);
|
|
4467
|
+
return {};
|
|
4468
|
+
}
|
|
4397
4469
|
}
|
|
4398
4470
|
function declaredIntentParams(vendorSchema) {
|
|
4399
4471
|
const declared2 = {};
|
|
@@ -4406,7 +4478,7 @@ function captureAndInject(name, entry, ctx) {
|
|
|
4406
4478
|
if (!entry || typeof entry !== "object") return;
|
|
4407
4479
|
const mutable = entry;
|
|
4408
4480
|
const vendorSchema = ctx.vendorToolJsonSchema(name, mutable.inputSchema);
|
|
4409
|
-
ctx.surfaceState.noteTool(name, vendorSchema, mutable.description);
|
|
4481
|
+
ctx.surfaceState.noteTool(name, vendorSchema, mutable.description, ctx.vendorOutputJsonSchema(entry));
|
|
4410
4482
|
if (declaresParam(vendorSchema, USER_GOAL_PARAM_NAME)) ctx.dropSubagentClause(name);
|
|
4411
4483
|
const isV2 = typeof mutable.executor === "function";
|
|
4412
4484
|
try {
|
|
@@ -4520,10 +4592,6 @@ function installLowLevelToolSeams(lowLevel, ctx, annotationTool, known, warnOnce
|
|
|
4520
4592
|
const name = reportTool2?.name;
|
|
4521
4593
|
if (name !== void 0 && tools.some((tool) => tool.name === name)) leaveReportNameToVendor(name);
|
|
4522
4594
|
};
|
|
4523
|
-
const read = (tools, { surface }) => {
|
|
4524
|
-
if (surface) takeReportNameIfListed(tools);
|
|
4525
|
-
readToolList(tools, ctx, surface, skipNote);
|
|
4526
|
-
};
|
|
4527
4595
|
const learn = (tools) => {
|
|
4528
4596
|
keepGoalIfDeclared(tools);
|
|
4529
4597
|
for (const tool of tools) {
|
|
@@ -4551,8 +4619,8 @@ function installLowLevelToolSeams(lowLevel, ctx, annotationTool, known, warnOnce
|
|
|
4551
4619
|
);
|
|
4552
4620
|
}
|
|
4553
4621
|
}
|
|
4554
|
-
|
|
4555
|
-
|
|
4622
|
+
takeReportNameIfListed(known.givenTools);
|
|
4623
|
+
readToolList([...known.givenTools, ...known.served.values()], ctx, false, skipNote);
|
|
4556
4624
|
};
|
|
4557
4625
|
installRequestSeam(lowLevel, TOOLS_LIST_METHOD, LOW_LEVEL_LIST_SEAM, (handler) => async (...args) => {
|
|
4558
4626
|
catchUp();
|
|
@@ -4562,8 +4630,14 @@ function installLowLevelToolSeams(lowLevel, ctx, annotationTool, known, warnOnce
|
|
|
4562
4630
|
if (listed === null) return result;
|
|
4563
4631
|
const tools = toolInfos(listed, skipTool);
|
|
4564
4632
|
learn(tools);
|
|
4565
|
-
|
|
4566
|
-
|
|
4633
|
+
takeReportNameIfListed(tools);
|
|
4634
|
+
readToolList(tools, ctx, true, skipNote);
|
|
4635
|
+
const request = args[0];
|
|
4636
|
+
const cursor = isRecord(request) && isRecord(request.params) ? request.params.cursor : void 0;
|
|
4637
|
+
if (isRecord(request) && isWholeList(cursor, result.nextCursor)) {
|
|
4638
|
+
ctx.surfaceState.servedList(request, new Set(tools.map((tool) => tool.name)));
|
|
4639
|
+
}
|
|
4640
|
+
const firstPage = cursor === void 0 || cursor === null;
|
|
4567
4641
|
return servedToolList(result, listed, ctx, firstPage && reportTool2 ? listedReportTool : void 0);
|
|
4568
4642
|
} catch (err) {
|
|
4569
4643
|
stderrLine(`baton: tools/list capture failed; serving the vendor's own result: ${printable(err)}`);
|
|
@@ -4627,7 +4701,8 @@ function toolInfos(tools, skip) {
|
|
|
4627
4701
|
try {
|
|
4628
4702
|
name = isRecord(tool) ? tool.name : void 0;
|
|
4629
4703
|
if (typeof name !== "string") continue;
|
|
4630
|
-
|
|
4704
|
+
const { description, inputSchema: inputSchema2, outputSchema } = tool;
|
|
4705
|
+
infos.push({ name, description, inputSchema: inputSchema2, outputSchema });
|
|
4631
4706
|
} catch (err) {
|
|
4632
4707
|
if (typeof name === "string") skip(name, err);
|
|
4633
4708
|
}
|
|
@@ -4635,11 +4710,16 @@ function toolInfos(tools, skip) {
|
|
|
4635
4710
|
return infos;
|
|
4636
4711
|
}
|
|
4637
4712
|
function readToolList(tools, ctx, surface, skip) {
|
|
4638
|
-
for (const { name, inputSchema: inputSchema2, description } of tools) {
|
|
4713
|
+
for (const { name, inputSchema: inputSchema2, description, outputSchema } of tools) {
|
|
4639
4714
|
try {
|
|
4640
4715
|
const schema = isRecord(inputSchema2) ? inputSchema2 : null;
|
|
4641
4716
|
if (surface) {
|
|
4642
|
-
ctx.surfaceState.noteTool(
|
|
4717
|
+
ctx.surfaceState.noteTool(
|
|
4718
|
+
name,
|
|
4719
|
+
schema ?? EMPTY_OBJECT_JSON_SCHEMA,
|
|
4720
|
+
typeof description === "string" ? description : void 0,
|
|
4721
|
+
isRecord(outputSchema) ? outputSchema : void 0
|
|
4722
|
+
);
|
|
4643
4723
|
}
|
|
4644
4724
|
const dispositions = declaredIntentParams(schema);
|
|
4645
4725
|
if (dispositions[USER_GOAL_PARAM_NAME] === "native") ctx.dropSubagentClause(name);
|
|
@@ -4675,7 +4755,7 @@ function installLifecycleSeam(lowLevel, ctx, spec) {
|
|
|
4675
4755
|
const requestParams = request?.params ?? {};
|
|
4676
4756
|
const extra = args[1];
|
|
4677
4757
|
const opened = await openLifecycleCall(ctx, spec, requestParams, extra);
|
|
4678
|
-
const fire = async (schema, payload) => {
|
|
4758
|
+
const fire = async (schema, payload, unscrubbed = {}) => {
|
|
4679
4759
|
if (opened === null) return;
|
|
4680
4760
|
await emit(
|
|
4681
4761
|
ctx.sink,
|
|
@@ -4683,7 +4763,7 @@ function installLifecycleSeam(lowLevel, ctx, spec) {
|
|
|
4683
4763
|
...opened.common,
|
|
4684
4764
|
sequence_number: ctx.counter.nextFor(opened.session),
|
|
4685
4765
|
captured_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4686
|
-
payload: scrubLifecyclePayload(ctx, { ...opened.subject, ...payload })
|
|
4766
|
+
payload: { ...scrubLifecyclePayload(ctx, { ...opened.subject, ...payload }), ...unscrubbed }
|
|
4687
4767
|
})
|
|
4688
4768
|
);
|
|
4689
4769
|
};
|
|
@@ -4694,10 +4774,15 @@ function installLifecycleSeam(lowLevel, ctx, spec) {
|
|
|
4694
4774
|
const served = await handler(...args);
|
|
4695
4775
|
if (isInputRequired(served)) return served;
|
|
4696
4776
|
const result = opened !== null && spec.rewriteResult !== void 0 ? spec.rewriteResult(ctx, served, opened.caller) : served;
|
|
4697
|
-
|
|
4698
|
-
|
|
4699
|
-
|
|
4700
|
-
|
|
4777
|
+
const duration = elapsed();
|
|
4778
|
+
await fire(
|
|
4779
|
+
spec.schemas.end,
|
|
4780
|
+
{
|
|
4781
|
+
...spec.countKey === void 0 ? {} : { count: countOf(result, spec.countKey) },
|
|
4782
|
+
duration_ms: duration
|
|
4783
|
+
},
|
|
4784
|
+
await spec.endFields?.(ctx, request, served)
|
|
4785
|
+
);
|
|
4701
4786
|
return result;
|
|
4702
4787
|
} catch (err) {
|
|
4703
4788
|
await fire(spec.schemas.error, {
|
|
@@ -4817,7 +4902,8 @@ var LIFECYCLE_SPECS = [
|
|
|
4817
4902
|
},
|
|
4818
4903
|
countKey: "tools",
|
|
4819
4904
|
startParams: NO_PARAMS,
|
|
4820
|
-
rewriteResult: (ctx, result, caller) => ctx.perCaller?.toolsFor(result, caller) ?? result
|
|
4905
|
+
rewriteResult: (ctx, result, caller) => ctx.perCaller?.toolsFor(result, caller) ?? result,
|
|
4906
|
+
endFields: listedSurfaceFields
|
|
4821
4907
|
}
|
|
4822
4908
|
];
|
|
4823
4909
|
function installLifecycleSeams(lowLevel, ctx) {
|
|
@@ -5061,6 +5147,8 @@ function wireEntry(name, entry, ctx) {
|
|
|
5061
5147
|
}
|
|
5062
5148
|
if (u.paramsSchema !== void 0) {
|
|
5063
5149
|
captureAndInject(nameRef.current, entry, ctx);
|
|
5150
|
+
} else if (u.outputSchema !== void 0) {
|
|
5151
|
+
ctx.surfaceState.setOutputSchema(nameRef.current, ctx.vendorOutputJsonSchema(entry));
|
|
5064
5152
|
}
|
|
5065
5153
|
if (typeof u.enabled === "boolean") {
|
|
5066
5154
|
ctx.surfaceState.setToolEnabled(nameRef.current, u.enabled);
|
|
@@ -5186,7 +5274,7 @@ function install(server, supplied, resolved, { sentSurfaces, warned: warned4, co
|
|
|
5186
5274
|
const counter2 = new ServerCounter(sharedCounter, fallbackSessionId);
|
|
5187
5275
|
const tenantId = resolveTenantId(config.tenantId, config.vendorId);
|
|
5188
5276
|
const serverMeta = buildServerMeta(lowLevel);
|
|
5189
|
-
const surfaceState = new SurfaceState(serverMeta, sentSurfaces);
|
|
5277
|
+
const surfaceState = new SurfaceState(serverMeta, sentSurfaces, shape === "mcpServer");
|
|
5190
5278
|
const emitSurface = async (sessionId, digest, snapshot) => {
|
|
5191
5279
|
await emit(
|
|
5192
5280
|
sink,
|
|
@@ -5246,6 +5334,15 @@ function install(server, supplied, resolved, { sentSurfaces, warned: warned4, co
|
|
|
5246
5334
|
return EMPTY_OBJECT_JSON_SCHEMA;
|
|
5247
5335
|
}
|
|
5248
5336
|
};
|
|
5337
|
+
const vendorOutputJsonSchema = (entry) => {
|
|
5338
|
+
try {
|
|
5339
|
+
const tool = entry;
|
|
5340
|
+
if (!isV2Server) return toolOutputJsonSchema(tool.outputSchema);
|
|
5341
|
+
return isRecord(tool.outputSchemaJson) ? tool.outputSchemaJson : void 0;
|
|
5342
|
+
} catch {
|
|
5343
|
+
return void 0;
|
|
5344
|
+
}
|
|
5345
|
+
};
|
|
5249
5346
|
installValidationProbe(server);
|
|
5250
5347
|
const ctx = {
|
|
5251
5348
|
sink,
|
|
@@ -5265,6 +5362,7 @@ function install(server, supplied, resolved, { sentSurfaces, warned: warned4, co
|
|
|
5265
5362
|
captureSettings: config.captureSettings,
|
|
5266
5363
|
perCaller: void 0,
|
|
5267
5364
|
vendorToolJsonSchema,
|
|
5365
|
+
vendorOutputJsonSchema,
|
|
5268
5366
|
bustSchemaMemo,
|
|
5269
5367
|
dropSubagentClause,
|
|
5270
5368
|
servedInstructions: () => lowLevel._instructions,
|
|
@@ -5753,7 +5851,7 @@ var Serving = class {
|
|
|
5753
5851
|
annotationToolName: report?.tool.name ?? "",
|
|
5754
5852
|
injectsGoal: (name) => known.dispositions.get(name)?.[USER_GOAL_PARAM_NAME] === "injected"
|
|
5755
5853
|
});
|
|
5756
|
-
const whole =
|
|
5854
|
+
const whole = isWholeList(request.params.cursor, result.nextCursor) ? surface : null;
|
|
5757
5855
|
return {
|
|
5758
5856
|
answer: { ...answer, result: listed },
|
|
5759
5857
|
surface: whole,
|