@goodtiming/baton-sdk 1.2.0 → 1.2.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/dist/index.cjs +149 -47
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +44 -1
- package/dist/index.d.ts +44 -1
- package/dist/index.js +149 -47
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/version.ts
|
|
2
|
-
var SDK_VERSION = "ts-1.2.
|
|
2
|
+
var SDK_VERSION = "ts-1.2.2";
|
|
3
3
|
|
|
4
4
|
// src/events.ts
|
|
5
5
|
import { z } from "zod";
|
|
@@ -133,7 +133,8 @@ var CaptureObservedSchema = z.object({
|
|
|
133
133
|
settings_version: z.number().int().min(1).optional(),
|
|
134
134
|
audience: z.string().optional(),
|
|
135
135
|
overlay: z.string().optional(),
|
|
136
|
-
candidate: z.string().optional()
|
|
136
|
+
candidate: z.string().optional(),
|
|
137
|
+
task: z.string().optional()
|
|
137
138
|
}).strict();
|
|
138
139
|
var PrincipalWireSchema = z.object({
|
|
139
140
|
id: z.string(),
|
|
@@ -1876,18 +1877,18 @@ Fields:
|
|
|
1876
1877
|
- suggested_improvement: one concrete sentence on the product change that would have helped.
|
|
1877
1878
|
- context: supplementary info not covered above. Common keys: plan, alternatives_considered, likely_cause, user_impact, error_class, downstream_blocked, confidence_in_intent. When no tool covers the request also missing_capability_field and requested_capability.`;
|
|
1878
1879
|
var CLAUDE_CODE_TRUNCATION_CAP = 2087;
|
|
1879
|
-
var
|
|
1880
|
+
var BATON_SENTENCE_LENGTH_CAP = 1500;
|
|
1880
1881
|
function buildReportPointer(options) {
|
|
1881
1882
|
return REPORT_POINTER_TEMPLATE(options.vendorDisplayName, options.annotationToolName);
|
|
1882
1883
|
}
|
|
1883
|
-
function
|
|
1884
|
-
return buildReportPointer(options).length <=
|
|
1884
|
+
function fitsBatonSentenceCap(options) {
|
|
1885
|
+
return buildReportPointer(options).length <= BATON_SENTENCE_LENGTH_CAP;
|
|
1885
1886
|
}
|
|
1886
1887
|
function buildServerInstructions(options) {
|
|
1887
1888
|
const rendered = buildReportPointer(options);
|
|
1888
|
-
if (rendered.length >
|
|
1889
|
+
if (rendered.length > BATON_SENTENCE_LENGTH_CAP) {
|
|
1889
1890
|
throw new Error(
|
|
1890
|
-
`
|
|
1891
|
+
`Baton's report sentence would be ${rendered.length} chars, over its ${BATON_SENTENCE_LENGTH_CAP}-char limit (Claude Code cuts server instructions at ~${CLAUDE_CODE_TRUNCATION_CAP}). Shorten vendorDisplayName or annotationToolName.`
|
|
1891
1892
|
);
|
|
1892
1893
|
}
|
|
1893
1894
|
return rendered + INSTRUCTIONS_SUBAGENT_CLAUSE;
|
|
@@ -1937,6 +1938,30 @@ function mayDeclareParam(schema, name) {
|
|
|
1937
1938
|
};
|
|
1938
1939
|
return walk2(schema);
|
|
1939
1940
|
}
|
|
1941
|
+
var VENDOR_SERVED_PIECES = [...INSTRUCTION_PIECES, "report_tool.description", "report_tool.refusal"];
|
|
1942
|
+
function servedAgentText(options) {
|
|
1943
|
+
const served = {};
|
|
1944
|
+
if (options.subagentServed) served["instructions.subagent"] = INTENT_INSTRUCTIONS;
|
|
1945
|
+
if (options.goalParamServed) {
|
|
1946
|
+
served["goal_param.description"] = buildUserGoalParamDescription({ intentParamMode: options.intentParamMode });
|
|
1947
|
+
}
|
|
1948
|
+
if (options.reportNames !== void 0) {
|
|
1949
|
+
served["instructions.report_pointer"] = buildReportPointer(options.reportNames);
|
|
1950
|
+
served["report_tool.description"] = buildAnnotationToolDescription(options.reportNames);
|
|
1951
|
+
served["report_tool.refusal"] = buildRefusalText({ annotationToolName: options.reportNames.annotationToolName });
|
|
1952
|
+
}
|
|
1953
|
+
const pieces = {};
|
|
1954
|
+
for (const [piece, text] of Object.entries(served)) {
|
|
1955
|
+
if (options.serverOverlay !== void 0 && INSTRUCTION_PIECES.includes(piece)) {
|
|
1956
|
+
const changed = changedText(text, options.serverOverlay.pieceActions(piece));
|
|
1957
|
+
pieces[piece] = { text: changed.text ?? text, source: changed.source };
|
|
1958
|
+
} else {
|
|
1959
|
+
pieces[piece] = { text, source: "default" };
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1962
|
+
if (options.vendorServesText) for (const piece of VENDOR_SERVED_PIECES) pieces[piece] = null;
|
|
1963
|
+
return pieces;
|
|
1964
|
+
}
|
|
1940
1965
|
function instructionsSuffixServed(annotationToolName, served) {
|
|
1941
1966
|
if (annotationToolName) return true;
|
|
1942
1967
|
return typeof served === "string" && served.includes(INTENT_INSTRUCTIONS);
|
|
@@ -1956,8 +1981,19 @@ ${ours}` : vendor;
|
|
|
1956
1981
|
function vendorText(holder) {
|
|
1957
1982
|
const current2 = holder._instructions;
|
|
1958
1983
|
const written = holder[OURS];
|
|
1984
|
+
if (written === void 0) return current2;
|
|
1959
1985
|
const vendor = VENDOR_INSTRUCTIONS in holder ? holder[VENDOR_INSTRUCTIONS] : current2;
|
|
1960
|
-
|
|
1986
|
+
if (current2 === joined(vendor, written)) return vendor;
|
|
1987
|
+
return withoutOurs(current2, written) ?? current2;
|
|
1988
|
+
}
|
|
1989
|
+
function withoutOurs(current2, ours) {
|
|
1990
|
+
if (!ours || typeof current2 !== "string") return void 0;
|
|
1991
|
+
const at = current2.lastIndexOf(ours);
|
|
1992
|
+
if (at < 0) return void 0;
|
|
1993
|
+
const before = current2.slice(0, at);
|
|
1994
|
+
const after = current2.slice(at + ours.length);
|
|
1995
|
+
if (before && !before.endsWith("\n\n") || after && !after.startsWith("\n\n")) return void 0;
|
|
1996
|
+
return joined(before.slice(0, -2), after.slice(2));
|
|
1961
1997
|
}
|
|
1962
1998
|
function writeOurs(server, ours, subagent, write, warn3 = stderrLine) {
|
|
1963
1999
|
const holder = server;
|
|
@@ -1971,9 +2007,7 @@ function removeSubagentClause(server, write, warn3 = stderrLine) {
|
|
|
1971
2007
|
const holder = server;
|
|
1972
2008
|
const ours = holder[OURS];
|
|
1973
2009
|
const subagent = holder[SUBAGENT];
|
|
1974
|
-
if (ours === void 0 || !subagent || holder
|
|
1975
|
-
return false;
|
|
1976
|
-
}
|
|
2010
|
+
if (ours === void 0 || !subagent || vendorText(holder) === holder._instructions) return false;
|
|
1977
2011
|
const kept = ours.slice(0, ours.length - subagent.length);
|
|
1978
2012
|
writeOurs(server, kept.endsWith("\n\n") ? kept.slice(0, -2) : kept, null, write, warn3);
|
|
1979
2013
|
return true;
|
|
@@ -2042,9 +2076,9 @@ function toolNameCandidate(serverName) {
|
|
|
2042
2076
|
function displayNameFromServer(serverName, tool) {
|
|
2043
2077
|
if (serverName === void 0) return void 0;
|
|
2044
2078
|
const proposed = tool.annotationToolName || toolNameCandidate(serverName) || `${tool.vendorId}${SUFFIX}`;
|
|
2045
|
-
if (!
|
|
2079
|
+
if (!fitsBatonSentenceCap({ vendorDisplayName: serverName, annotationToolName: proposed })) {
|
|
2046
2080
|
warn(
|
|
2047
|
-
`baton: the server name (${serverName.length} chars) does not fit the
|
|
2081
|
+
`baton: the server name (${serverName.length} chars) does not fit the budget of Baton's report sentence as the display name beside the annotation tool ${JSON.stringify(proposed)}; keeping the DSN's server segment. Pass vendorDisplayName to name the server in fewer characters.`
|
|
2048
2082
|
);
|
|
2049
2083
|
return void 0;
|
|
2050
2084
|
}
|
|
@@ -2054,9 +2088,9 @@ function annotationToolNameFromServer(serverName, vendorDisplayName) {
|
|
|
2054
2088
|
if (serverName === void 0) return void 0;
|
|
2055
2089
|
const candidate = toolNameCandidate(serverName);
|
|
2056
2090
|
if (candidate === void 0) return void 0;
|
|
2057
|
-
if (!
|
|
2091
|
+
if (!fitsBatonSentenceCap({ vendorDisplayName, annotationToolName: candidate })) {
|
|
2058
2092
|
warn(
|
|
2059
|
-
`baton: the server-derived annotation tool name ${JSON.stringify(candidate)} does not fit the
|
|
2093
|
+
`baton: the server-derived annotation tool name ${JSON.stringify(candidate)} does not fit the budget of Baton's report sentence beside the display name (${vendorDisplayName.length} chars); keeping {vendorId}_annotate. A shorter display name gets the readable one.`
|
|
2060
2094
|
);
|
|
2061
2095
|
return void 0;
|
|
2062
2096
|
}
|
|
@@ -2065,7 +2099,7 @@ function annotationToolNameFromServer(serverName, vendorDisplayName) {
|
|
|
2065
2099
|
function toolNameForDisplayName(vendorDisplayName) {
|
|
2066
2100
|
if (isPlaceholderLiteral(vendorDisplayName)) return void 0;
|
|
2067
2101
|
const candidate = toolNameCandidate(vendorDisplayName);
|
|
2068
|
-
return candidate !== void 0 &&
|
|
2102
|
+
return candidate !== void 0 && fitsBatonSentenceCap({ vendorDisplayName, annotationToolName: candidate }) ? candidate : void 0;
|
|
2069
2103
|
}
|
|
2070
2104
|
function deriveAnnotationToolName(vendorId2, override) {
|
|
2071
2105
|
return validateAnnotationToolName(override || `${vendorId2}${SUFFIX}`);
|
|
@@ -2333,18 +2367,36 @@ var CANDIDATES_HELD = 32;
|
|
|
2333
2367
|
var CANDIDATE_READS_AT_ONCE = 4;
|
|
2334
2368
|
var CANDIDATE_START_TIMEOUT_MS = 5e3;
|
|
2335
2369
|
var CANDIDATE_ID = /^[A-Za-z0-9_-]{1,128}$/;
|
|
2336
|
-
|
|
2370
|
+
var TASK_ENV = "BATON_TASK";
|
|
2371
|
+
var TASK_HEADER = "baton-task";
|
|
2372
|
+
var TASK_ID = /^[A-Za-z0-9_.:-]{1,128}$/;
|
|
2373
|
+
function matchingId(pattern, value) {
|
|
2337
2374
|
if (typeof value !== "string") return null;
|
|
2338
2375
|
const id = stripWhiteSpace(value);
|
|
2339
|
-
return
|
|
2376
|
+
return pattern.test(id) ? id : null;
|
|
2340
2377
|
}
|
|
2341
|
-
function
|
|
2378
|
+
function headerId(headers, name, parse) {
|
|
2342
2379
|
try {
|
|
2343
|
-
return
|
|
2380
|
+
return parse(headers?.get(name));
|
|
2344
2381
|
} catch {
|
|
2345
2382
|
return null;
|
|
2346
2383
|
}
|
|
2347
2384
|
}
|
|
2385
|
+
function candidateId(value) {
|
|
2386
|
+
return matchingId(CANDIDATE_ID, value);
|
|
2387
|
+
}
|
|
2388
|
+
function headerCandidate(headers) {
|
|
2389
|
+
return headerId(headers, CANDIDATE_HEADER, candidateId);
|
|
2390
|
+
}
|
|
2391
|
+
function taskId(value) {
|
|
2392
|
+
return matchingId(TASK_ID, value);
|
|
2393
|
+
}
|
|
2394
|
+
function headerTask(headers) {
|
|
2395
|
+
return headerId(headers, TASK_HEADER, taskId);
|
|
2396
|
+
}
|
|
2397
|
+
function envTask() {
|
|
2398
|
+
return taskId(typeof process !== "undefined" ? process.env?.[TASK_ENV] : void 0);
|
|
2399
|
+
}
|
|
2348
2400
|
function envCandidate() {
|
|
2349
2401
|
const value = typeof process !== "undefined" ? process.env?.[CANDIDATE_ENV] : void 0;
|
|
2350
2402
|
if (!value) return null;
|
|
@@ -2568,15 +2620,17 @@ var SettingsFetcher = class {
|
|
|
2568
2620
|
};
|
|
2569
2621
|
var PENDING = /* @__PURE__ */ Symbol("pending");
|
|
2570
2622
|
var CaptureSettings = class {
|
|
2571
|
-
constructor(vendorId2, source, candidate = null, startTimeoutMs = CANDIDATE_START_TIMEOUT_MS) {
|
|
2623
|
+
constructor(vendorId2, source, candidate = null, task = null, startTimeoutMs = CANDIDATE_START_TIMEOUT_MS) {
|
|
2572
2624
|
this.vendorId = vendorId2;
|
|
2573
2625
|
this.source = source;
|
|
2574
2626
|
this.candidate = candidate;
|
|
2627
|
+
this.task = task;
|
|
2575
2628
|
this.startTimeoutMs = startTimeoutMs;
|
|
2576
2629
|
}
|
|
2577
2630
|
vendorId;
|
|
2578
2631
|
source;
|
|
2579
2632
|
candidate;
|
|
2633
|
+
task;
|
|
2580
2634
|
startTimeoutMs;
|
|
2581
2635
|
processDocument = null;
|
|
2582
2636
|
/** `BATON_CANDIDATE`'s read; requests wait for it. */
|
|
@@ -2622,7 +2676,10 @@ var CaptureSettings = class {
|
|
|
2622
2676
|
/** `undefined` while no document is held, and the config's values apply. */
|
|
2623
2677
|
forCaller(caller) {
|
|
2624
2678
|
const document = caller.candidate == null ? this.document : this.headerDocument(caller.candidate) ?? this.source.document;
|
|
2625
|
-
|
|
2679
|
+
const settings = document?.settingsFor(caller, this.vendorId);
|
|
2680
|
+
const task = caller.candidate == null ? this.task : caller.task;
|
|
2681
|
+
if (settings === void 0 || task == null || settings.capture.candidate === void 0) return settings;
|
|
2682
|
+
return { ...settings, capture: { ...settings.capture, task } };
|
|
2626
2683
|
}
|
|
2627
2684
|
/** Whether `test` holds for some document a request could be served under now. */
|
|
2628
2685
|
someDocument(test) {
|
|
@@ -2763,11 +2820,14 @@ async function resolveCaller(hook, call, settings, client = null) {
|
|
|
2763
2820
|
const caller = await resolveIdentity(hook, call);
|
|
2764
2821
|
if (settings === void 0) return caller;
|
|
2765
2822
|
try {
|
|
2823
|
+
const headers = extraHeaders(call.extra);
|
|
2824
|
+
const candidate = headerCandidate(headers);
|
|
2766
2825
|
const callSettings = settings.forCaller({
|
|
2767
2826
|
labels: caller.labels,
|
|
2768
2827
|
clientName: client?.info?.name ?? null,
|
|
2769
2828
|
shareKey: caller.principal?.id ?? null,
|
|
2770
|
-
candidate
|
|
2829
|
+
candidate,
|
|
2830
|
+
task: candidate === null ? null : headerTask(headers)
|
|
2771
2831
|
});
|
|
2772
2832
|
return callSettings === void 0 ? caller : { ...caller, settings: callSettings };
|
|
2773
2833
|
} catch {
|
|
@@ -2873,6 +2933,14 @@ function takesUserGoalJson(schema) {
|
|
|
2873
2933
|
const properties = schema.properties ?? {};
|
|
2874
2934
|
return isRecord(properties) && !ROOT_COMBINERS.some((key) => key in schema);
|
|
2875
2935
|
}
|
|
2936
|
+
function goalTextsServed(tools) {
|
|
2937
|
+
const schemas = Array.isArray(tools) ? tools.map((tool) => isRecord(tool) ? tool.inputSchema : void 0) : [];
|
|
2938
|
+
const native = schemas.map((schema) => declaresParam(schema, USER_GOAL_PARAM_NAME));
|
|
2939
|
+
return {
|
|
2940
|
+
goalParamServed: schemas.some((schema, i) => isRecord(schema) && !native[i] && takesUserGoalJson(schema)),
|
|
2941
|
+
subagentServed: !native.some(Boolean)
|
|
2942
|
+
};
|
|
2943
|
+
}
|
|
2876
2944
|
function withUserGoalJson(schema, intentParamMode, listRequired) {
|
|
2877
2945
|
if (!takesUserGoalJson(schema) || declaresParam(schema, USER_GOAL_PARAM_NAME)) return schema;
|
|
2878
2946
|
const properties = schema.properties ?? {};
|
|
@@ -3108,13 +3176,13 @@ function sessionIdFromHeader(extra) {
|
|
|
3108
3176
|
var TOOL_NAME_PARAM_NAME = "tool_name";
|
|
3109
3177
|
var ANNOTATION_INPUT_SHAPE = {
|
|
3110
3178
|
user_goal: z2.string(),
|
|
3111
|
-
what_happened: z2.string().optional(),
|
|
3112
3179
|
// Nullable so a report whose agent sends an explicit null is taken,
|
|
3113
3180
|
// not rejected by validation.
|
|
3181
|
+
what_happened: z2.string().nullable().optional(),
|
|
3114
3182
|
tool_name: z2.string().nullable().optional(),
|
|
3115
|
-
suggested_improvement: z2.string().optional(),
|
|
3183
|
+
suggested_improvement: z2.string().nullable().optional(),
|
|
3116
3184
|
// zod renders "any value" as `{}`, which some MCP clients refuse (reportToolSchema.test.ts).
|
|
3117
|
-
context: z2.record(z2.string(), z2.unknown()).meta({ additionalProperties: true }).optional()
|
|
3185
|
+
context: z2.record(z2.string(), z2.unknown()).meta({ additionalProperties: true }).nullable().optional()
|
|
3118
3186
|
};
|
|
3119
3187
|
function isReport(whatHappened) {
|
|
3120
3188
|
return typeof whatHappened === "string" && !isBlank(whatHappened);
|
|
@@ -3193,7 +3261,7 @@ function buildAnnotationTool(server, options) {
|
|
|
3193
3261
|
payload: {
|
|
3194
3262
|
// The agent-facing `user_goal` is stored as the wire key `intent`.
|
|
3195
3263
|
// eslint-disable-next-line no-restricted-syntax -- inside the emit() build thunk: a throw is already contained, and null here would fabricate a shape
|
|
3196
|
-
intent: options.scrubber(args.user_goal),
|
|
3264
|
+
intent: args.user_goal ? options.scrubber(args.user_goal) : null,
|
|
3197
3265
|
// eslint-disable-next-line no-restricted-syntax -- inside the emit() build thunk: a throw is already contained, and null here would fabricate a shape
|
|
3198
3266
|
what_happened: options.scrubber(whatHappened),
|
|
3199
3267
|
// eslint-disable-next-line no-restricted-syntax -- inside the emit() build thunk: a throw is already contained, and null here would fabricate a shape
|
|
@@ -3218,7 +3286,7 @@ var PUBLISHABLE_PREFIX = "baton_pk_";
|
|
|
3218
3286
|
var SECRET_PREFIX = "baton_sk_";
|
|
3219
3287
|
var TEST_PREFIX = "baton_tk_";
|
|
3220
3288
|
var KEY_PREFIXES = [PUBLISHABLE_PREFIX, SECRET_PREFIX, TEST_PREFIX];
|
|
3221
|
-
var KEY_RUN = /baton_(?:(?:pk|sk|tk)_[A-Za-z0-9_%-]{8,}|[A-Za-z0-9_%-]{43,})/
|
|
3289
|
+
var KEY_RUN = /baton_(?:(?:pk|sk|tk)_[A-Za-z0-9_%-]{8,}|[A-Za-z0-9_%-]{43,})/gi;
|
|
3222
3290
|
function looksLikeAKey(value) {
|
|
3223
3291
|
return KEY_PREFIXES.some((prefix) => value.startsWith(prefix));
|
|
3224
3292
|
}
|
|
@@ -3503,7 +3571,8 @@ function resolveBatonConfig(supplied) {
|
|
|
3503
3571
|
vendorId: dsn.vendorId,
|
|
3504
3572
|
refreshMs: identity.settingsRefreshMs ?? DEFAULT_SETTINGS_REFRESH_MS
|
|
3505
3573
|
}),
|
|
3506
|
-
envCandidate()
|
|
3574
|
+
envCandidate(),
|
|
3575
|
+
envTask()
|
|
3507
3576
|
)
|
|
3508
3577
|
} : {}
|
|
3509
3578
|
};
|
|
@@ -3935,7 +4004,8 @@ function buildSeamAugmentations(options) {
|
|
|
3935
4004
|
required_names: [...options.requiredParamNames].sort(),
|
|
3936
4005
|
mode: options.intentParamMode
|
|
3937
4006
|
},
|
|
3938
|
-
instructions_suffix: options.instructionsSuffix
|
|
4007
|
+
instructions_suffix: options.instructionsSuffix,
|
|
4008
|
+
agent_text: options.agentText
|
|
3939
4009
|
};
|
|
3940
4010
|
}
|
|
3941
4011
|
|
|
@@ -4290,7 +4360,13 @@ async function maybeEmitSurfaceSnapshot(ctx) {
|
|
|
4290
4360
|
intentParamNames: [USER_GOAL_PARAM_NAME],
|
|
4291
4361
|
intentParamMode: ctx.intentParamMode,
|
|
4292
4362
|
requiredParamNames: requiredParamNames(ctx.intentParamMode),
|
|
4293
|
-
instructionsSuffix: instructionsSuffixServed(ctx.annotationToolName, ctx.servedInstructions())
|
|
4363
|
+
instructionsSuffix: instructionsSuffixServed(ctx.annotationToolName, ctx.servedInstructions()),
|
|
4364
|
+
agentText: servedAgentText({
|
|
4365
|
+
reportNames: ctx.reportNames(),
|
|
4366
|
+
intentParamMode: ctx.intentParamMode,
|
|
4367
|
+
...goalTextsServed(snapshot.tools),
|
|
4368
|
+
serverOverlay: ctx.perCaller?.serverOverlay
|
|
4369
|
+
})
|
|
4294
4370
|
});
|
|
4295
4371
|
if (ctx.captureSettings !== void 0) seam.server_overlay = overlayId;
|
|
4296
4372
|
await ctx.emitSurface(ctx.fallbackSessionId, digest, { ...snapshot, seam_augmentations: seam });
|
|
@@ -4403,16 +4479,21 @@ function installLowLevelToolSeams(lowLevel, ctx, annotationTool, known, warnOnce
|
|
|
4403
4479
|
}
|
|
4404
4480
|
}
|
|
4405
4481
|
};
|
|
4482
|
+
const leaveReportNameToVendor = (name) => {
|
|
4483
|
+
warnOnce2(
|
|
4484
|
+
"report-tool-name-taken",
|
|
4485
|
+
`baton: the server lists its own tool ${JSON.stringify(name)}, so Baton's report tool is not added; set annotationToolName to another name`
|
|
4486
|
+
);
|
|
4487
|
+
reportTool2 = void 0;
|
|
4488
|
+
ctx.annotationToolName = "";
|
|
4489
|
+
reportToolTaken();
|
|
4490
|
+
};
|
|
4491
|
+
const takeReportNameIfListed = (tools) => {
|
|
4492
|
+
const name = reportTool2?.name;
|
|
4493
|
+
if (name !== void 0 && tools.some((tool) => tool.name === name)) leaveReportNameToVendor(name);
|
|
4494
|
+
};
|
|
4406
4495
|
const read = (tools, { surface }) => {
|
|
4407
|
-
if (surface
|
|
4408
|
-
warnOnce2(
|
|
4409
|
-
"report-tool-name-taken",
|
|
4410
|
-
`baton: the server lists its own tool ${JSON.stringify(reportTool2.name)}, so Baton's report tool is not added; set annotationToolName to another name`
|
|
4411
|
-
);
|
|
4412
|
-
reportTool2 = void 0;
|
|
4413
|
-
ctx.annotationToolName = "";
|
|
4414
|
-
reportToolTaken();
|
|
4415
|
-
}
|
|
4496
|
+
if (surface) takeReportNameIfListed(tools);
|
|
4416
4497
|
readToolList(tools, ctx, surface, skipNote);
|
|
4417
4498
|
};
|
|
4418
4499
|
const learn = (tools) => {
|
|
@@ -4500,6 +4581,10 @@ function installLowLevelToolSeams(lowLevel, ctx, annotationTool, known, warnOnce
|
|
|
4500
4581
|
}
|
|
4501
4582
|
return batonWrap({ current: name }, () => handler(...args), ctx, unlisted, slot?.caller)(toolArgs, args[1]);
|
|
4502
4583
|
});
|
|
4584
|
+
return () => {
|
|
4585
|
+
if (Array.isArray(known.given)) takeReportNameIfListed(toolInfos(known.given, () => {
|
|
4586
|
+
}));
|
|
4587
|
+
};
|
|
4503
4588
|
}
|
|
4504
4589
|
function lowLevelMajor(lowLevel) {
|
|
4505
4590
|
return typeof lowLevel._wrapHandler === "function" ? 2 : 1;
|
|
@@ -5143,6 +5228,7 @@ function install(server, supplied, resolved, { sentSurfaces, warned: warned4, co
|
|
|
5143
5228
|
server,
|
|
5144
5229
|
scrubber,
|
|
5145
5230
|
annotationToolName,
|
|
5231
|
+
reportNames: () => reports && ctx.annotationToolName ? { vendorDisplayName: reports.vendorDisplayName, annotationToolName: ctx.annotationToolName } : void 0,
|
|
5146
5232
|
intentParamMode,
|
|
5147
5233
|
configResultCaptureMode: config.resultCaptureMode ?? "full",
|
|
5148
5234
|
paramRegistry: /* @__PURE__ */ new Map(),
|
|
@@ -5173,7 +5259,10 @@ function install(server, supplied, resolved, { sentSurfaces, warned: warned4, co
|
|
|
5173
5259
|
get annotationToolName() {
|
|
5174
5260
|
return ctx.annotationToolName;
|
|
5175
5261
|
},
|
|
5176
|
-
pointer: () =>
|
|
5262
|
+
pointer: () => {
|
|
5263
|
+
const names = ctx.reportNames();
|
|
5264
|
+
return names && buildReportPointer(names);
|
|
5265
|
+
},
|
|
5177
5266
|
writeInstructions,
|
|
5178
5267
|
subagentLine: () => ![...ctx.paramRegistry.values()].some((d) => d[USER_GOAL_PARAM_NAME] === "native"),
|
|
5179
5268
|
injectsGoal: (name) => ctx.paramRegistry.get(name)?.[USER_GOAL_PARAM_NAME] === "injected"
|
|
@@ -5196,8 +5285,9 @@ function install(server, supplied, resolved, { sentSurfaces, warned: warned4, co
|
|
|
5196
5285
|
// `srv-..._annotate` while the instructions name the server-derived one.
|
|
5197
5286
|
annotationToolName
|
|
5198
5287
|
};
|
|
5288
|
+
let checkGivenTools;
|
|
5199
5289
|
if (shape === "lowLevel") {
|
|
5200
|
-
installLowLevelToolSeams(
|
|
5290
|
+
checkGivenTools = installLowLevelToolSeams(
|
|
5201
5291
|
lowLevel,
|
|
5202
5292
|
ctx,
|
|
5203
5293
|
annotationOptions && buildAnnotationTool(server, annotationOptions),
|
|
@@ -5241,7 +5331,10 @@ function install(server, supplied, resolved, { sentSurfaces, warned: warned4, co
|
|
|
5241
5331
|
sessionId: fallbackSessionId,
|
|
5242
5332
|
annotationToolName: name
|
|
5243
5333
|
});
|
|
5244
|
-
if (shape === "lowLevel")
|
|
5334
|
+
if (shape === "lowLevel") {
|
|
5335
|
+
checkGivenTools?.();
|
|
5336
|
+
return handle(annotationToolName);
|
|
5337
|
+
}
|
|
5245
5338
|
const resolvedAnnotationToolName = annotationOptions ? registerAnnotationTool(server, annotationOptions) : "";
|
|
5246
5339
|
const existing = internals._registeredTools;
|
|
5247
5340
|
if (existing) {
|
|
@@ -5407,7 +5500,13 @@ function snapshotPayload({ surface, digest }) {
|
|
|
5407
5500
|
intentParamNames: [USER_GOAL_PARAM_NAME],
|
|
5408
5501
|
intentParamMode: DEFAULT_INTENT_PARAM_MODE,
|
|
5409
5502
|
requiredParamNames: requiredParamNames(DEFAULT_INTENT_PARAM_MODE),
|
|
5410
|
-
instructionsSuffix: null
|
|
5503
|
+
instructionsSuffix: null,
|
|
5504
|
+
agentText: servedAgentText({
|
|
5505
|
+
reportNames: void 0,
|
|
5506
|
+
intentParamMode: DEFAULT_INTENT_PARAM_MODE,
|
|
5507
|
+
...goalTextsServed(surface.tools),
|
|
5508
|
+
vendorServesText: true
|
|
5509
|
+
})
|
|
5411
5510
|
})
|
|
5412
5511
|
};
|
|
5413
5512
|
}
|
|
@@ -5865,16 +5964,19 @@ function annotateArgs(args) {
|
|
|
5865
5964
|
}
|
|
5866
5965
|
function reportTool(options) {
|
|
5867
5966
|
const { vendorDisplayName } = options;
|
|
5967
|
+
if (isBlank(vendorDisplayName)) {
|
|
5968
|
+
throw new Error("vendorDisplayName is blank. Baton's report sentence names the server by it.");
|
|
5969
|
+
}
|
|
5868
5970
|
const derived = options.name ?? toolNameForDisplayName(vendorDisplayName);
|
|
5869
5971
|
if (derived === void 0) {
|
|
5870
5972
|
throw new Error(
|
|
5871
|
-
`vendorDisplayName ${JSON.stringify(vendorDisplayName)} gives no usable tool name, or one too long for
|
|
5973
|
+
`vendorDisplayName ${JSON.stringify(vendorDisplayName)} gives no usable tool name, or one too long for Baton's report sentence. Pass name.`
|
|
5872
5974
|
);
|
|
5873
5975
|
}
|
|
5874
5976
|
const name = validateAnnotationToolName(derived);
|
|
5875
|
-
if (!
|
|
5977
|
+
if (!fitsBatonSentenceCap({ vendorDisplayName, annotationToolName: name })) {
|
|
5876
5978
|
throw new Error(
|
|
5877
|
-
`vendorDisplayName and name ${JSON.stringify(name)} are too long together for
|
|
5979
|
+
`vendorDisplayName and name ${JSON.stringify(name)} are too long together for Baton's report sentence. Shorten one of them.`
|
|
5878
5980
|
);
|
|
5879
5981
|
}
|
|
5880
5982
|
return {
|