@goodtiming/baton-sdk 1.3.1 → 1.3.3
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 +166 -50
- 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 +166 -50
- 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.3";
|
|
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.3";
|
|
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.3";
|
|
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();
|
|
@@ -4039,13 +4048,31 @@ var wired = /* @__PURE__ */ new WeakSet();
|
|
|
4039
4048
|
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();
|
|
4051
|
+
function listedFieldsOf(tool) {
|
|
4052
|
+
const { title, annotations, outputSchema } = tool;
|
|
4053
|
+
return {
|
|
4054
|
+
...typeof title === "string" ? { title } : {},
|
|
4055
|
+
...jsonField("annotations", annotations),
|
|
4056
|
+
...jsonField("outputSchema", outputSchema)
|
|
4057
|
+
};
|
|
4058
|
+
}
|
|
4059
|
+
function jsonField(key, value) {
|
|
4060
|
+
try {
|
|
4061
|
+
const copy = jsonObjectCopy(value);
|
|
4062
|
+
return copy === void 0 ? {} : { [key]: copy };
|
|
4063
|
+
} catch {
|
|
4064
|
+
return {};
|
|
4065
|
+
}
|
|
4066
|
+
}
|
|
4042
4067
|
var SurfaceState = class {
|
|
4043
|
-
constructor(serverMeta, sentSurfaces) {
|
|
4068
|
+
constructor(serverMeta, sentSurfaces, fromRegistry) {
|
|
4044
4069
|
this.serverMeta = serverMeta;
|
|
4045
4070
|
this.sentSurfaces = sentSurfaces;
|
|
4071
|
+
this.fromRegistry = fromRegistry;
|
|
4046
4072
|
}
|
|
4047
4073
|
serverMeta;
|
|
4048
4074
|
sentSurfaces;
|
|
4075
|
+
fromRegistry;
|
|
4049
4076
|
/** Every tool this install has seen, keyed by its CURRENT name. `disabled`
|
|
4050
4077
|
* is tracked alongside rather than pruned, so re-enabling costs nothing and
|
|
4051
4078
|
* — crucially — never needs a re-capture, which would re-read Baton's own
|
|
@@ -4053,20 +4080,71 @@ var SurfaceState = class {
|
|
|
4053
4080
|
rawTools = /* @__PURE__ */ new Map();
|
|
4054
4081
|
dirty = false;
|
|
4055
4082
|
servedOverlayId = null;
|
|
4083
|
+
listed = false;
|
|
4084
|
+
/** `null` when this version of the surface could not be captured. */
|
|
4085
|
+
captured;
|
|
4086
|
+
/** The surface each low-level request was served, keyed by the request,
|
|
4087
|
+
* which every seam passes on as it came. Kept apart from the current
|
|
4088
|
+
* surface, which another listing can change before this one's end is sent:
|
|
4089
|
+
* `surfaceAtList.test.ts`, "gives two listings that finish together each its own hash". */
|
|
4090
|
+
listedSurfaces = /* @__PURE__ */ new WeakMap();
|
|
4091
|
+
get hasSurface() {
|
|
4092
|
+
return this.fromRegistry || this.listed;
|
|
4093
|
+
}
|
|
4094
|
+
/** A low-level Server served `request` its whole list, which then is the
|
|
4095
|
+
* surface: `surfaceAtList.test.ts`, "snapshots each list as served". */
|
|
4096
|
+
servedList(request, names) {
|
|
4097
|
+
this.listed = true;
|
|
4098
|
+
for (const name of [...this.rawTools.keys()]) {
|
|
4099
|
+
if (!names.has(name)) this.pruneTool(name);
|
|
4100
|
+
}
|
|
4101
|
+
const surface = this.capture();
|
|
4102
|
+
if (surface !== null) this.listedSurfaces.set(request, surface);
|
|
4103
|
+
}
|
|
4104
|
+
/** The surface a `tools/list` request was served, when it got the whole list. */
|
|
4105
|
+
surfaceListed(request, served) {
|
|
4106
|
+
const listed = this.listedSurfaces.get(request);
|
|
4107
|
+
if (listed !== void 0) return listed;
|
|
4108
|
+
const cursor = isRecord(request.params) ? request.params.cursor : void 0;
|
|
4109
|
+
const whole = isWholeList(cursor, isRecord(served) ? served.nextCursor : void 0);
|
|
4110
|
+
return this.fromRegistry && whole ? this.capture() : null;
|
|
4111
|
+
}
|
|
4112
|
+
/** The surface as it stands, and its hash; built once per change, so a
|
|
4113
|
+
* surface that cannot be hashed is reported once, not on every request. */
|
|
4114
|
+
capture() {
|
|
4115
|
+
if (this.captured !== void 0) return this.captured;
|
|
4116
|
+
try {
|
|
4117
|
+
const snapshot = this.buildSnapshot();
|
|
4118
|
+
this.captured = { snapshot, digest: surfaceHash(snapshot) };
|
|
4119
|
+
} catch (err) {
|
|
4120
|
+
stderrLine(`baton: surface snapshot capture failed: ${printable(err)}`);
|
|
4121
|
+
this.captured = null;
|
|
4122
|
+
}
|
|
4123
|
+
return this.captured;
|
|
4124
|
+
}
|
|
4125
|
+
changed() {
|
|
4126
|
+
this.dirty = true;
|
|
4127
|
+
this.captured = void 0;
|
|
4128
|
+
}
|
|
4056
4129
|
/** `inputSchemaJson` is already converted — by `ctx.vendorToolJsonSchema`,
|
|
4057
4130
|
* which picks the spelling THIS SDK major puts on the wire. */
|
|
4058
|
-
noteTool(name, inputSchemaJson, description) {
|
|
4131
|
+
noteTool(name, inputSchemaJson, description, listed) {
|
|
4059
4132
|
const before = this.rawTools.get(name);
|
|
4060
|
-
const
|
|
4061
|
-
if (before !== void 0 && before.tool.description ===
|
|
4062
|
-
|
|
4063
|
-
if (same) return;
|
|
4133
|
+
const listedJson = JSON.stringify(listed);
|
|
4134
|
+
if (before !== void 0 && before.tool.description === (description ?? null) && before.listedJson === listedJson) {
|
|
4135
|
+
if (before.tool.inputSchema === inputSchemaJson || JSON.stringify(before.tool.inputSchema) === JSON.stringify(inputSchemaJson)) return;
|
|
4064
4136
|
}
|
|
4065
|
-
|
|
4066
|
-
this.
|
|
4137
|
+
const tool = { name, description: description ?? null, inputSchema: inputSchemaJson, ...listed };
|
|
4138
|
+
this.rawTools.set(name, { disabled: before?.disabled ?? false, tool, listedJson });
|
|
4139
|
+
this.changed();
|
|
4140
|
+
}
|
|
4141
|
+
/** An McpServer `update()` that kept the input schema. */
|
|
4142
|
+
noteListing(name, description, listed) {
|
|
4143
|
+
const tool = this.rawTools.get(name)?.tool;
|
|
4144
|
+
if (tool !== void 0) this.noteTool(name, tool.inputSchema, description, listed);
|
|
4067
4145
|
}
|
|
4068
4146
|
pruneTool(name) {
|
|
4069
|
-
if (this.rawTools.delete(name)) this.
|
|
4147
|
+
if (this.rawTools.delete(name)) this.changed();
|
|
4070
4148
|
}
|
|
4071
4149
|
/** Follow a `update({name})` rename, keeping the snapshot keyed the way
|
|
4072
4150
|
* `tools/list` now renders it. */
|
|
@@ -4075,7 +4153,7 @@ var SurfaceState = class {
|
|
|
4075
4153
|
if (!entry) return;
|
|
4076
4154
|
this.rawTools.delete(from);
|
|
4077
4155
|
this.rawTools.set(to, { ...entry, tool: { ...entry.tool, name: to } });
|
|
4078
|
-
this.
|
|
4156
|
+
this.changed();
|
|
4079
4157
|
}
|
|
4080
4158
|
/** Both majors filter `tools/list` on `tool.enabled`, so a disabled tool is
|
|
4081
4159
|
* not part of the surface a client sees and must not be part of the one we
|
|
@@ -4085,7 +4163,7 @@ var SurfaceState = class {
|
|
|
4085
4163
|
const entry = this.rawTools.get(name);
|
|
4086
4164
|
if (!entry || entry.disabled === !enabled) return;
|
|
4087
4165
|
entry.disabled = !enabled;
|
|
4088
|
-
this.
|
|
4166
|
+
this.changed();
|
|
4089
4167
|
}
|
|
4090
4168
|
buildSnapshot() {
|
|
4091
4169
|
const names = [...this.rawTools.keys()].sort().filter((n) => !this.rawTools.get(n).disabled);
|
|
@@ -4360,6 +4438,7 @@ function stripIntentParams(params, ctx) {
|
|
|
4360
4438
|
return stripped;
|
|
4361
4439
|
}
|
|
4362
4440
|
async function maybeEmitSurfaceSnapshot(ctx) {
|
|
4441
|
+
if (!ctx.surfaceState.hasSurface) return;
|
|
4363
4442
|
const overlayId = ctx.perCaller?.serverOverlay?.id ?? null;
|
|
4364
4443
|
if (overlayId !== ctx.surfaceState.servedOverlayId) {
|
|
4365
4444
|
ctx.surfaceState.servedOverlayId = overlayId;
|
|
@@ -4367,17 +4446,13 @@ async function maybeEmitSurfaceSnapshot(ctx) {
|
|
|
4367
4446
|
}
|
|
4368
4447
|
if (!ctx.surfaceState.dirty) return;
|
|
4369
4448
|
ctx.surfaceState.dirty = false;
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
} catch (err) {
|
|
4376
|
-
stderrLine(`baton: surface snapshot capture failed: ${String(err)}`);
|
|
4377
|
-
return;
|
|
4378
|
-
}
|
|
4449
|
+
const surface = ctx.surfaceState.capture();
|
|
4450
|
+
if (surface !== null) await sendSurface(ctx, surface);
|
|
4451
|
+
}
|
|
4452
|
+
async function sendSurface(ctx, { snapshot, digest }) {
|
|
4453
|
+
const overlayId = ctx.perCaller?.serverOverlay?.id ?? null;
|
|
4379
4454
|
const sent = ctx.surfaceState.sentSurfaces;
|
|
4380
|
-
if (sent.wasSent(digest, overlayId)) return;
|
|
4455
|
+
if (sent.wasSent(digest, overlayId)) return digest;
|
|
4381
4456
|
sent.mark(digest, overlayId);
|
|
4382
4457
|
const seam = buildSeamAugmentations({
|
|
4383
4458
|
injectedToolNames: ctx.annotationToolName ? [ctx.annotationToolName] : [],
|
|
@@ -4394,6 +4469,16 @@ async function maybeEmitSurfaceSnapshot(ctx) {
|
|
|
4394
4469
|
});
|
|
4395
4470
|
if (ctx.captureSettings !== void 0) seam.server_overlay = overlayId;
|
|
4396
4471
|
await ctx.emitSurface(ctx.fallbackSessionId, digest, { ...snapshot, seam_augmentations: seam });
|
|
4472
|
+
return digest;
|
|
4473
|
+
}
|
|
4474
|
+
async function listedSurfaceFields(ctx, request, served) {
|
|
4475
|
+
try {
|
|
4476
|
+
const surface = isRecord(request) ? ctx.surfaceState.surfaceListed(request, served) : null;
|
|
4477
|
+
return surface === null ? {} : { surface_hash: await sendSurface(ctx, surface) };
|
|
4478
|
+
} catch (err) {
|
|
4479
|
+
stderrLine(`baton: surface snapshot capture failed: ${printable(err)}`);
|
|
4480
|
+
return {};
|
|
4481
|
+
}
|
|
4397
4482
|
}
|
|
4398
4483
|
function declaredIntentParams(vendorSchema) {
|
|
4399
4484
|
const declared2 = {};
|
|
@@ -4406,7 +4491,7 @@ function captureAndInject(name, entry, ctx) {
|
|
|
4406
4491
|
if (!entry || typeof entry !== "object") return;
|
|
4407
4492
|
const mutable = entry;
|
|
4408
4493
|
const vendorSchema = ctx.vendorToolJsonSchema(name, mutable.inputSchema);
|
|
4409
|
-
ctx.surfaceState.noteTool(name, vendorSchema, mutable.description);
|
|
4494
|
+
ctx.surfaceState.noteTool(name, vendorSchema, mutable.description, ctx.vendorListedFields(entry));
|
|
4410
4495
|
if (declaresParam(vendorSchema, USER_GOAL_PARAM_NAME)) ctx.dropSubagentClause(name);
|
|
4411
4496
|
const isV2 = typeof mutable.executor === "function";
|
|
4412
4497
|
try {
|
|
@@ -4520,10 +4605,6 @@ function installLowLevelToolSeams(lowLevel, ctx, annotationTool, known, warnOnce
|
|
|
4520
4605
|
const name = reportTool2?.name;
|
|
4521
4606
|
if (name !== void 0 && tools.some((tool) => tool.name === name)) leaveReportNameToVendor(name);
|
|
4522
4607
|
};
|
|
4523
|
-
const read = (tools, { surface }) => {
|
|
4524
|
-
if (surface) takeReportNameIfListed(tools);
|
|
4525
|
-
readToolList(tools, ctx, surface, skipNote);
|
|
4526
|
-
};
|
|
4527
4608
|
const learn = (tools) => {
|
|
4528
4609
|
keepGoalIfDeclared(tools);
|
|
4529
4610
|
for (const tool of tools) {
|
|
@@ -4551,8 +4632,8 @@ function installLowLevelToolSeams(lowLevel, ctx, annotationTool, known, warnOnce
|
|
|
4551
4632
|
);
|
|
4552
4633
|
}
|
|
4553
4634
|
}
|
|
4554
|
-
|
|
4555
|
-
|
|
4635
|
+
takeReportNameIfListed(known.givenTools);
|
|
4636
|
+
readToolList([...known.givenTools, ...known.served.values()], ctx, false, skipNote);
|
|
4556
4637
|
};
|
|
4557
4638
|
installRequestSeam(lowLevel, TOOLS_LIST_METHOD, LOW_LEVEL_LIST_SEAM, (handler) => async (...args) => {
|
|
4558
4639
|
catchUp();
|
|
@@ -4562,8 +4643,14 @@ function installLowLevelToolSeams(lowLevel, ctx, annotationTool, known, warnOnce
|
|
|
4562
4643
|
if (listed === null) return result;
|
|
4563
4644
|
const tools = toolInfos(listed, skipTool);
|
|
4564
4645
|
learn(tools);
|
|
4565
|
-
|
|
4566
|
-
|
|
4646
|
+
takeReportNameIfListed(tools);
|
|
4647
|
+
readToolList(tools, ctx, true, skipNote);
|
|
4648
|
+
const request = args[0];
|
|
4649
|
+
const cursor = isRecord(request) && isRecord(request.params) ? request.params.cursor : void 0;
|
|
4650
|
+
if (isRecord(request) && isWholeList(cursor, result.nextCursor)) {
|
|
4651
|
+
ctx.surfaceState.servedList(request, new Set(tools.map((tool) => tool.name)));
|
|
4652
|
+
}
|
|
4653
|
+
const firstPage = cursor === void 0 || cursor === null;
|
|
4567
4654
|
return servedToolList(result, listed, ctx, firstPage && reportTool2 ? listedReportTool : void 0);
|
|
4568
4655
|
} catch (err) {
|
|
4569
4656
|
stderrLine(`baton: tools/list capture failed; serving the vendor's own result: ${printable(err)}`);
|
|
@@ -4627,7 +4714,8 @@ function toolInfos(tools, skip) {
|
|
|
4627
4714
|
try {
|
|
4628
4715
|
name = isRecord(tool) ? tool.name : void 0;
|
|
4629
4716
|
if (typeof name !== "string") continue;
|
|
4630
|
-
|
|
4717
|
+
const { description, inputSchema: inputSchema2 } = tool;
|
|
4718
|
+
infos.push({ name, description, inputSchema: inputSchema2, listed: listedFieldsOf(tool) });
|
|
4631
4719
|
} catch (err) {
|
|
4632
4720
|
if (typeof name === "string") skip(name, err);
|
|
4633
4721
|
}
|
|
@@ -4635,11 +4723,16 @@ function toolInfos(tools, skip) {
|
|
|
4635
4723
|
return infos;
|
|
4636
4724
|
}
|
|
4637
4725
|
function readToolList(tools, ctx, surface, skip) {
|
|
4638
|
-
for (const { name, inputSchema: inputSchema2, description } of tools) {
|
|
4726
|
+
for (const { name, inputSchema: inputSchema2, description, listed } of tools) {
|
|
4639
4727
|
try {
|
|
4640
4728
|
const schema = isRecord(inputSchema2) ? inputSchema2 : null;
|
|
4641
4729
|
if (surface) {
|
|
4642
|
-
ctx.surfaceState.noteTool(
|
|
4730
|
+
ctx.surfaceState.noteTool(
|
|
4731
|
+
name,
|
|
4732
|
+
schema ?? EMPTY_OBJECT_JSON_SCHEMA,
|
|
4733
|
+
typeof description === "string" ? description : void 0,
|
|
4734
|
+
listed
|
|
4735
|
+
);
|
|
4643
4736
|
}
|
|
4644
4737
|
const dispositions = declaredIntentParams(schema);
|
|
4645
4738
|
if (dispositions[USER_GOAL_PARAM_NAME] === "native") ctx.dropSubagentClause(name);
|
|
@@ -4675,7 +4768,7 @@ function installLifecycleSeam(lowLevel, ctx, spec) {
|
|
|
4675
4768
|
const requestParams = request?.params ?? {};
|
|
4676
4769
|
const extra = args[1];
|
|
4677
4770
|
const opened = await openLifecycleCall(ctx, spec, requestParams, extra);
|
|
4678
|
-
const fire = async (schema, payload) => {
|
|
4771
|
+
const fire = async (schema, payload, unscrubbed = {}) => {
|
|
4679
4772
|
if (opened === null) return;
|
|
4680
4773
|
await emit(
|
|
4681
4774
|
ctx.sink,
|
|
@@ -4683,7 +4776,7 @@ function installLifecycleSeam(lowLevel, ctx, spec) {
|
|
|
4683
4776
|
...opened.common,
|
|
4684
4777
|
sequence_number: ctx.counter.nextFor(opened.session),
|
|
4685
4778
|
captured_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4686
|
-
payload: scrubLifecyclePayload(ctx, { ...opened.subject, ...payload })
|
|
4779
|
+
payload: { ...scrubLifecyclePayload(ctx, { ...opened.subject, ...payload }), ...unscrubbed }
|
|
4687
4780
|
})
|
|
4688
4781
|
);
|
|
4689
4782
|
};
|
|
@@ -4694,10 +4787,15 @@ function installLifecycleSeam(lowLevel, ctx, spec) {
|
|
|
4694
4787
|
const served = await handler(...args);
|
|
4695
4788
|
if (isInputRequired(served)) return served;
|
|
4696
4789
|
const result = opened !== null && spec.rewriteResult !== void 0 ? spec.rewriteResult(ctx, served, opened.caller) : served;
|
|
4697
|
-
|
|
4698
|
-
|
|
4699
|
-
|
|
4700
|
-
|
|
4790
|
+
const duration = elapsed();
|
|
4791
|
+
await fire(
|
|
4792
|
+
spec.schemas.end,
|
|
4793
|
+
{
|
|
4794
|
+
...spec.countKey === void 0 ? {} : { count: countOf(result, spec.countKey) },
|
|
4795
|
+
duration_ms: duration
|
|
4796
|
+
},
|
|
4797
|
+
await spec.endFields?.(ctx, request, served)
|
|
4798
|
+
);
|
|
4701
4799
|
return result;
|
|
4702
4800
|
} catch (err) {
|
|
4703
4801
|
await fire(spec.schemas.error, {
|
|
@@ -4817,7 +4915,8 @@ var LIFECYCLE_SPECS = [
|
|
|
4817
4915
|
},
|
|
4818
4916
|
countKey: "tools",
|
|
4819
4917
|
startParams: NO_PARAMS,
|
|
4820
|
-
rewriteResult: (ctx, result, caller) => ctx.perCaller?.toolsFor(result, caller) ?? result
|
|
4918
|
+
rewriteResult: (ctx, result, caller) => ctx.perCaller?.toolsFor(result, caller) ?? result,
|
|
4919
|
+
endFields: listedSurfaceFields
|
|
4821
4920
|
}
|
|
4822
4921
|
];
|
|
4823
4922
|
function installLifecycleSeams(lowLevel, ctx) {
|
|
@@ -5061,6 +5160,13 @@ function wireEntry(name, entry, ctx) {
|
|
|
5061
5160
|
}
|
|
5062
5161
|
if (u.paramsSchema !== void 0) {
|
|
5063
5162
|
captureAndInject(nameRef.current, entry, ctx);
|
|
5163
|
+
} else {
|
|
5164
|
+
const { description } = entry;
|
|
5165
|
+
ctx.surfaceState.noteListing(
|
|
5166
|
+
nameRef.current,
|
|
5167
|
+
typeof description === "string" ? description : void 0,
|
|
5168
|
+
ctx.vendorListedFields(entry)
|
|
5169
|
+
);
|
|
5064
5170
|
}
|
|
5065
5171
|
if (typeof u.enabled === "boolean") {
|
|
5066
5172
|
ctx.surfaceState.setToolEnabled(nameRef.current, u.enabled);
|
|
@@ -5186,7 +5292,7 @@ function install(server, supplied, resolved, { sentSurfaces, warned: warned4, co
|
|
|
5186
5292
|
const counter2 = new ServerCounter(sharedCounter, fallbackSessionId);
|
|
5187
5293
|
const tenantId = resolveTenantId(config.tenantId, config.vendorId);
|
|
5188
5294
|
const serverMeta = buildServerMeta(lowLevel);
|
|
5189
|
-
const surfaceState = new SurfaceState(serverMeta, sentSurfaces);
|
|
5295
|
+
const surfaceState = new SurfaceState(serverMeta, sentSurfaces, shape === "mcpServer");
|
|
5190
5296
|
const emitSurface = async (sessionId, digest, snapshot) => {
|
|
5191
5297
|
await emit(
|
|
5192
5298
|
sink,
|
|
@@ -5246,6 +5352,15 @@ function install(server, supplied, resolved, { sentSurfaces, warned: warned4, co
|
|
|
5246
5352
|
return EMPTY_OBJECT_JSON_SCHEMA;
|
|
5247
5353
|
}
|
|
5248
5354
|
};
|
|
5355
|
+
const vendorListedFields = (entry) => {
|
|
5356
|
+
try {
|
|
5357
|
+
if (!isRecord(entry)) return {};
|
|
5358
|
+
const outputSchema = isV2Server ? entry.outputSchemaJson : toolOutputJsonSchema(entry.outputSchema);
|
|
5359
|
+
return listedFieldsOf({ title: entry.title, annotations: entry.annotations, outputSchema });
|
|
5360
|
+
} catch {
|
|
5361
|
+
return {};
|
|
5362
|
+
}
|
|
5363
|
+
};
|
|
5249
5364
|
installValidationProbe(server);
|
|
5250
5365
|
const ctx = {
|
|
5251
5366
|
sink,
|
|
@@ -5265,6 +5380,7 @@ function install(server, supplied, resolved, { sentSurfaces, warned: warned4, co
|
|
|
5265
5380
|
captureSettings: config.captureSettings,
|
|
5266
5381
|
perCaller: void 0,
|
|
5267
5382
|
vendorToolJsonSchema,
|
|
5383
|
+
vendorListedFields,
|
|
5268
5384
|
bustSchemaMemo,
|
|
5269
5385
|
dropSubagentClause,
|
|
5270
5386
|
servedInstructions: () => lowLevel._instructions,
|
|
@@ -5753,7 +5869,7 @@ var Serving = class {
|
|
|
5753
5869
|
annotationToolName: report?.tool.name ?? "",
|
|
5754
5870
|
injectsGoal: (name) => known.dispositions.get(name)?.[USER_GOAL_PARAM_NAME] === "injected"
|
|
5755
5871
|
});
|
|
5756
|
-
const whole =
|
|
5872
|
+
const whole = isWholeList(request.params.cursor, result.nextCursor) ? surface : null;
|
|
5757
5873
|
return {
|
|
5758
5874
|
answer: { ...answer, result: listed },
|
|
5759
5875
|
surface: whole,
|