@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.cjs
CHANGED
|
@@ -53,7 +53,7 @@ __export(index_exports, {
|
|
|
53
53
|
module.exports = __toCommonJS(index_exports);
|
|
54
54
|
|
|
55
55
|
// src/version.ts
|
|
56
|
-
var SDK_VERSION = "ts-1.2.
|
|
56
|
+
var SDK_VERSION = "ts-1.2.2";
|
|
57
57
|
|
|
58
58
|
// src/events.ts
|
|
59
59
|
var import_zod = require("zod");
|
|
@@ -187,7 +187,8 @@ var CaptureObservedSchema = import_zod.z.object({
|
|
|
187
187
|
settings_version: import_zod.z.number().int().min(1).optional(),
|
|
188
188
|
audience: import_zod.z.string().optional(),
|
|
189
189
|
overlay: import_zod.z.string().optional(),
|
|
190
|
-
candidate: import_zod.z.string().optional()
|
|
190
|
+
candidate: import_zod.z.string().optional(),
|
|
191
|
+
task: import_zod.z.string().optional()
|
|
191
192
|
}).strict();
|
|
192
193
|
var PrincipalWireSchema = import_zod.z.object({
|
|
193
194
|
id: import_zod.z.string(),
|
|
@@ -1930,18 +1931,18 @@ Fields:
|
|
|
1930
1931
|
- suggested_improvement: one concrete sentence on the product change that would have helped.
|
|
1931
1932
|
- 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.`;
|
|
1932
1933
|
var CLAUDE_CODE_TRUNCATION_CAP = 2087;
|
|
1933
|
-
var
|
|
1934
|
+
var BATON_SENTENCE_LENGTH_CAP = 1500;
|
|
1934
1935
|
function buildReportPointer(options) {
|
|
1935
1936
|
return REPORT_POINTER_TEMPLATE(options.vendorDisplayName, options.annotationToolName);
|
|
1936
1937
|
}
|
|
1937
|
-
function
|
|
1938
|
-
return buildReportPointer(options).length <=
|
|
1938
|
+
function fitsBatonSentenceCap(options) {
|
|
1939
|
+
return buildReportPointer(options).length <= BATON_SENTENCE_LENGTH_CAP;
|
|
1939
1940
|
}
|
|
1940
1941
|
function buildServerInstructions(options) {
|
|
1941
1942
|
const rendered = buildReportPointer(options);
|
|
1942
|
-
if (rendered.length >
|
|
1943
|
+
if (rendered.length > BATON_SENTENCE_LENGTH_CAP) {
|
|
1943
1944
|
throw new Error(
|
|
1944
|
-
`
|
|
1945
|
+
`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.`
|
|
1945
1946
|
);
|
|
1946
1947
|
}
|
|
1947
1948
|
return rendered + INSTRUCTIONS_SUBAGENT_CLAUSE;
|
|
@@ -1991,6 +1992,30 @@ function mayDeclareParam(schema, name) {
|
|
|
1991
1992
|
};
|
|
1992
1993
|
return walk2(schema);
|
|
1993
1994
|
}
|
|
1995
|
+
var VENDOR_SERVED_PIECES = [...INSTRUCTION_PIECES, "report_tool.description", "report_tool.refusal"];
|
|
1996
|
+
function servedAgentText(options) {
|
|
1997
|
+
const served = {};
|
|
1998
|
+
if (options.subagentServed) served["instructions.subagent"] = INTENT_INSTRUCTIONS;
|
|
1999
|
+
if (options.goalParamServed) {
|
|
2000
|
+
served["goal_param.description"] = buildUserGoalParamDescription({ intentParamMode: options.intentParamMode });
|
|
2001
|
+
}
|
|
2002
|
+
if (options.reportNames !== void 0) {
|
|
2003
|
+
served["instructions.report_pointer"] = buildReportPointer(options.reportNames);
|
|
2004
|
+
served["report_tool.description"] = buildAnnotationToolDescription(options.reportNames);
|
|
2005
|
+
served["report_tool.refusal"] = buildRefusalText({ annotationToolName: options.reportNames.annotationToolName });
|
|
2006
|
+
}
|
|
2007
|
+
const pieces = {};
|
|
2008
|
+
for (const [piece, text] of Object.entries(served)) {
|
|
2009
|
+
if (options.serverOverlay !== void 0 && INSTRUCTION_PIECES.includes(piece)) {
|
|
2010
|
+
const changed = changedText(text, options.serverOverlay.pieceActions(piece));
|
|
2011
|
+
pieces[piece] = { text: changed.text ?? text, source: changed.source };
|
|
2012
|
+
} else {
|
|
2013
|
+
pieces[piece] = { text, source: "default" };
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
2016
|
+
if (options.vendorServesText) for (const piece of VENDOR_SERVED_PIECES) pieces[piece] = null;
|
|
2017
|
+
return pieces;
|
|
2018
|
+
}
|
|
1994
2019
|
function instructionsSuffixServed(annotationToolName, served) {
|
|
1995
2020
|
if (annotationToolName) return true;
|
|
1996
2021
|
return typeof served === "string" && served.includes(INTENT_INSTRUCTIONS);
|
|
@@ -2010,8 +2035,19 @@ ${ours}` : vendor;
|
|
|
2010
2035
|
function vendorText(holder) {
|
|
2011
2036
|
const current2 = holder._instructions;
|
|
2012
2037
|
const written = holder[OURS];
|
|
2038
|
+
if (written === void 0) return current2;
|
|
2013
2039
|
const vendor = VENDOR_INSTRUCTIONS in holder ? holder[VENDOR_INSTRUCTIONS] : current2;
|
|
2014
|
-
|
|
2040
|
+
if (current2 === joined(vendor, written)) return vendor;
|
|
2041
|
+
return withoutOurs(current2, written) ?? current2;
|
|
2042
|
+
}
|
|
2043
|
+
function withoutOurs(current2, ours) {
|
|
2044
|
+
if (!ours || typeof current2 !== "string") return void 0;
|
|
2045
|
+
const at = current2.lastIndexOf(ours);
|
|
2046
|
+
if (at < 0) return void 0;
|
|
2047
|
+
const before = current2.slice(0, at);
|
|
2048
|
+
const after = current2.slice(at + ours.length);
|
|
2049
|
+
if (before && !before.endsWith("\n\n") || after && !after.startsWith("\n\n")) return void 0;
|
|
2050
|
+
return joined(before.slice(0, -2), after.slice(2));
|
|
2015
2051
|
}
|
|
2016
2052
|
function writeOurs(server, ours, subagent, write, warn3 = stderrLine) {
|
|
2017
2053
|
const holder = server;
|
|
@@ -2025,9 +2061,7 @@ function removeSubagentClause(server, write, warn3 = stderrLine) {
|
|
|
2025
2061
|
const holder = server;
|
|
2026
2062
|
const ours = holder[OURS];
|
|
2027
2063
|
const subagent = holder[SUBAGENT];
|
|
2028
|
-
if (ours === void 0 || !subagent || holder
|
|
2029
|
-
return false;
|
|
2030
|
-
}
|
|
2064
|
+
if (ours === void 0 || !subagent || vendorText(holder) === holder._instructions) return false;
|
|
2031
2065
|
const kept = ours.slice(0, ours.length - subagent.length);
|
|
2032
2066
|
writeOurs(server, kept.endsWith("\n\n") ? kept.slice(0, -2) : kept, null, write, warn3);
|
|
2033
2067
|
return true;
|
|
@@ -2096,9 +2130,9 @@ function toolNameCandidate(serverName) {
|
|
|
2096
2130
|
function displayNameFromServer(serverName, tool) {
|
|
2097
2131
|
if (serverName === void 0) return void 0;
|
|
2098
2132
|
const proposed = tool.annotationToolName || toolNameCandidate(serverName) || `${tool.vendorId}${SUFFIX}`;
|
|
2099
|
-
if (!
|
|
2133
|
+
if (!fitsBatonSentenceCap({ vendorDisplayName: serverName, annotationToolName: proposed })) {
|
|
2100
2134
|
warn(
|
|
2101
|
-
`baton: the server name (${serverName.length} chars) does not fit the
|
|
2135
|
+
`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.`
|
|
2102
2136
|
);
|
|
2103
2137
|
return void 0;
|
|
2104
2138
|
}
|
|
@@ -2108,9 +2142,9 @@ function annotationToolNameFromServer(serverName, vendorDisplayName) {
|
|
|
2108
2142
|
if (serverName === void 0) return void 0;
|
|
2109
2143
|
const candidate = toolNameCandidate(serverName);
|
|
2110
2144
|
if (candidate === void 0) return void 0;
|
|
2111
|
-
if (!
|
|
2145
|
+
if (!fitsBatonSentenceCap({ vendorDisplayName, annotationToolName: candidate })) {
|
|
2112
2146
|
warn(
|
|
2113
|
-
`baton: the server-derived annotation tool name ${JSON.stringify(candidate)} does not fit the
|
|
2147
|
+
`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.`
|
|
2114
2148
|
);
|
|
2115
2149
|
return void 0;
|
|
2116
2150
|
}
|
|
@@ -2119,7 +2153,7 @@ function annotationToolNameFromServer(serverName, vendorDisplayName) {
|
|
|
2119
2153
|
function toolNameForDisplayName(vendorDisplayName) {
|
|
2120
2154
|
if (isPlaceholderLiteral(vendorDisplayName)) return void 0;
|
|
2121
2155
|
const candidate = toolNameCandidate(vendorDisplayName);
|
|
2122
|
-
return candidate !== void 0 &&
|
|
2156
|
+
return candidate !== void 0 && fitsBatonSentenceCap({ vendorDisplayName, annotationToolName: candidate }) ? candidate : void 0;
|
|
2123
2157
|
}
|
|
2124
2158
|
function deriveAnnotationToolName(vendorId2, override) {
|
|
2125
2159
|
return validateAnnotationToolName(override || `${vendorId2}${SUFFIX}`);
|
|
@@ -2387,18 +2421,36 @@ var CANDIDATES_HELD = 32;
|
|
|
2387
2421
|
var CANDIDATE_READS_AT_ONCE = 4;
|
|
2388
2422
|
var CANDIDATE_START_TIMEOUT_MS = 5e3;
|
|
2389
2423
|
var CANDIDATE_ID = /^[A-Za-z0-9_-]{1,128}$/;
|
|
2390
|
-
|
|
2424
|
+
var TASK_ENV = "BATON_TASK";
|
|
2425
|
+
var TASK_HEADER = "baton-task";
|
|
2426
|
+
var TASK_ID = /^[A-Za-z0-9_.:-]{1,128}$/;
|
|
2427
|
+
function matchingId(pattern, value) {
|
|
2391
2428
|
if (typeof value !== "string") return null;
|
|
2392
2429
|
const id = stripWhiteSpace(value);
|
|
2393
|
-
return
|
|
2430
|
+
return pattern.test(id) ? id : null;
|
|
2394
2431
|
}
|
|
2395
|
-
function
|
|
2432
|
+
function headerId(headers, name, parse) {
|
|
2396
2433
|
try {
|
|
2397
|
-
return
|
|
2434
|
+
return parse(headers?.get(name));
|
|
2398
2435
|
} catch {
|
|
2399
2436
|
return null;
|
|
2400
2437
|
}
|
|
2401
2438
|
}
|
|
2439
|
+
function candidateId(value) {
|
|
2440
|
+
return matchingId(CANDIDATE_ID, value);
|
|
2441
|
+
}
|
|
2442
|
+
function headerCandidate(headers) {
|
|
2443
|
+
return headerId(headers, CANDIDATE_HEADER, candidateId);
|
|
2444
|
+
}
|
|
2445
|
+
function taskId(value) {
|
|
2446
|
+
return matchingId(TASK_ID, value);
|
|
2447
|
+
}
|
|
2448
|
+
function headerTask(headers) {
|
|
2449
|
+
return headerId(headers, TASK_HEADER, taskId);
|
|
2450
|
+
}
|
|
2451
|
+
function envTask() {
|
|
2452
|
+
return taskId(typeof process !== "undefined" ? process.env?.[TASK_ENV] : void 0);
|
|
2453
|
+
}
|
|
2402
2454
|
function envCandidate() {
|
|
2403
2455
|
const value = typeof process !== "undefined" ? process.env?.[CANDIDATE_ENV] : void 0;
|
|
2404
2456
|
if (!value) return null;
|
|
@@ -2622,15 +2674,17 @@ var SettingsFetcher = class {
|
|
|
2622
2674
|
};
|
|
2623
2675
|
var PENDING = /* @__PURE__ */ Symbol("pending");
|
|
2624
2676
|
var CaptureSettings = class {
|
|
2625
|
-
constructor(vendorId2, source, candidate = null, startTimeoutMs = CANDIDATE_START_TIMEOUT_MS) {
|
|
2677
|
+
constructor(vendorId2, source, candidate = null, task = null, startTimeoutMs = CANDIDATE_START_TIMEOUT_MS) {
|
|
2626
2678
|
this.vendorId = vendorId2;
|
|
2627
2679
|
this.source = source;
|
|
2628
2680
|
this.candidate = candidate;
|
|
2681
|
+
this.task = task;
|
|
2629
2682
|
this.startTimeoutMs = startTimeoutMs;
|
|
2630
2683
|
}
|
|
2631
2684
|
vendorId;
|
|
2632
2685
|
source;
|
|
2633
2686
|
candidate;
|
|
2687
|
+
task;
|
|
2634
2688
|
startTimeoutMs;
|
|
2635
2689
|
processDocument = null;
|
|
2636
2690
|
/** `BATON_CANDIDATE`'s read; requests wait for it. */
|
|
@@ -2676,7 +2730,10 @@ var CaptureSettings = class {
|
|
|
2676
2730
|
/** `undefined` while no document is held, and the config's values apply. */
|
|
2677
2731
|
forCaller(caller) {
|
|
2678
2732
|
const document = caller.candidate == null ? this.document : this.headerDocument(caller.candidate) ?? this.source.document;
|
|
2679
|
-
|
|
2733
|
+
const settings = document?.settingsFor(caller, this.vendorId);
|
|
2734
|
+
const task = caller.candidate == null ? this.task : caller.task;
|
|
2735
|
+
if (settings === void 0 || task == null || settings.capture.candidate === void 0) return settings;
|
|
2736
|
+
return { ...settings, capture: { ...settings.capture, task } };
|
|
2680
2737
|
}
|
|
2681
2738
|
/** Whether `test` holds for some document a request could be served under now. */
|
|
2682
2739
|
someDocument(test) {
|
|
@@ -2817,11 +2874,14 @@ async function resolveCaller(hook, call, settings, client = null) {
|
|
|
2817
2874
|
const caller = await resolveIdentity(hook, call);
|
|
2818
2875
|
if (settings === void 0) return caller;
|
|
2819
2876
|
try {
|
|
2877
|
+
const headers = extraHeaders(call.extra);
|
|
2878
|
+
const candidate = headerCandidate(headers);
|
|
2820
2879
|
const callSettings = settings.forCaller({
|
|
2821
2880
|
labels: caller.labels,
|
|
2822
2881
|
clientName: client?.info?.name ?? null,
|
|
2823
2882
|
shareKey: caller.principal?.id ?? null,
|
|
2824
|
-
candidate
|
|
2883
|
+
candidate,
|
|
2884
|
+
task: candidate === null ? null : headerTask(headers)
|
|
2825
2885
|
});
|
|
2826
2886
|
return callSettings === void 0 ? caller : { ...caller, settings: callSettings };
|
|
2827
2887
|
} catch {
|
|
@@ -2927,6 +2987,14 @@ function takesUserGoalJson(schema) {
|
|
|
2927
2987
|
const properties = schema.properties ?? {};
|
|
2928
2988
|
return isRecord(properties) && !ROOT_COMBINERS.some((key) => key in schema);
|
|
2929
2989
|
}
|
|
2990
|
+
function goalTextsServed(tools) {
|
|
2991
|
+
const schemas = Array.isArray(tools) ? tools.map((tool) => isRecord(tool) ? tool.inputSchema : void 0) : [];
|
|
2992
|
+
const native = schemas.map((schema) => declaresParam(schema, USER_GOAL_PARAM_NAME));
|
|
2993
|
+
return {
|
|
2994
|
+
goalParamServed: schemas.some((schema, i) => isRecord(schema) && !native[i] && takesUserGoalJson(schema)),
|
|
2995
|
+
subagentServed: !native.some(Boolean)
|
|
2996
|
+
};
|
|
2997
|
+
}
|
|
2930
2998
|
function withUserGoalJson(schema, intentParamMode, listRequired) {
|
|
2931
2999
|
if (!takesUserGoalJson(schema) || declaresParam(schema, USER_GOAL_PARAM_NAME)) return schema;
|
|
2932
3000
|
const properties = schema.properties ?? {};
|
|
@@ -3162,13 +3230,13 @@ function sessionIdFromHeader(extra) {
|
|
|
3162
3230
|
var TOOL_NAME_PARAM_NAME = "tool_name";
|
|
3163
3231
|
var ANNOTATION_INPUT_SHAPE = {
|
|
3164
3232
|
user_goal: import_zod3.z.string(),
|
|
3165
|
-
what_happened: import_zod3.z.string().optional(),
|
|
3166
3233
|
// Nullable so a report whose agent sends an explicit null is taken,
|
|
3167
3234
|
// not rejected by validation.
|
|
3235
|
+
what_happened: import_zod3.z.string().nullable().optional(),
|
|
3168
3236
|
tool_name: import_zod3.z.string().nullable().optional(),
|
|
3169
|
-
suggested_improvement: import_zod3.z.string().optional(),
|
|
3237
|
+
suggested_improvement: import_zod3.z.string().nullable().optional(),
|
|
3170
3238
|
// zod renders "any value" as `{}`, which some MCP clients refuse (reportToolSchema.test.ts).
|
|
3171
|
-
context: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.unknown()).meta({ additionalProperties: true }).optional()
|
|
3239
|
+
context: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.unknown()).meta({ additionalProperties: true }).nullable().optional()
|
|
3172
3240
|
};
|
|
3173
3241
|
function isReport(whatHappened) {
|
|
3174
3242
|
return typeof whatHappened === "string" && !isBlank(whatHappened);
|
|
@@ -3247,7 +3315,7 @@ function buildAnnotationTool(server, options) {
|
|
|
3247
3315
|
payload: {
|
|
3248
3316
|
// The agent-facing `user_goal` is stored as the wire key `intent`.
|
|
3249
3317
|
// eslint-disable-next-line no-restricted-syntax -- inside the emit() build thunk: a throw is already contained, and null here would fabricate a shape
|
|
3250
|
-
intent: options.scrubber(args.user_goal),
|
|
3318
|
+
intent: args.user_goal ? options.scrubber(args.user_goal) : null,
|
|
3251
3319
|
// eslint-disable-next-line no-restricted-syntax -- inside the emit() build thunk: a throw is already contained, and null here would fabricate a shape
|
|
3252
3320
|
what_happened: options.scrubber(whatHappened),
|
|
3253
3321
|
// eslint-disable-next-line no-restricted-syntax -- inside the emit() build thunk: a throw is already contained, and null here would fabricate a shape
|
|
@@ -3272,7 +3340,7 @@ var PUBLISHABLE_PREFIX = "baton_pk_";
|
|
|
3272
3340
|
var SECRET_PREFIX = "baton_sk_";
|
|
3273
3341
|
var TEST_PREFIX = "baton_tk_";
|
|
3274
3342
|
var KEY_PREFIXES = [PUBLISHABLE_PREFIX, SECRET_PREFIX, TEST_PREFIX];
|
|
3275
|
-
var KEY_RUN = /baton_(?:(?:pk|sk|tk)_[A-Za-z0-9_%-]{8,}|[A-Za-z0-9_%-]{43,})/
|
|
3343
|
+
var KEY_RUN = /baton_(?:(?:pk|sk|tk)_[A-Za-z0-9_%-]{8,}|[A-Za-z0-9_%-]{43,})/gi;
|
|
3276
3344
|
function looksLikeAKey(value) {
|
|
3277
3345
|
return KEY_PREFIXES.some((prefix) => value.startsWith(prefix));
|
|
3278
3346
|
}
|
|
@@ -3557,7 +3625,8 @@ function resolveBatonConfig(supplied) {
|
|
|
3557
3625
|
vendorId: dsn.vendorId,
|
|
3558
3626
|
refreshMs: identity.settingsRefreshMs ?? DEFAULT_SETTINGS_REFRESH_MS
|
|
3559
3627
|
}),
|
|
3560
|
-
envCandidate()
|
|
3628
|
+
envCandidate(),
|
|
3629
|
+
envTask()
|
|
3561
3630
|
)
|
|
3562
3631
|
} : {}
|
|
3563
3632
|
};
|
|
@@ -3989,7 +4058,8 @@ function buildSeamAugmentations(options) {
|
|
|
3989
4058
|
required_names: [...options.requiredParamNames].sort(),
|
|
3990
4059
|
mode: options.intentParamMode
|
|
3991
4060
|
},
|
|
3992
|
-
instructions_suffix: options.instructionsSuffix
|
|
4061
|
+
instructions_suffix: options.instructionsSuffix,
|
|
4062
|
+
agent_text: options.agentText
|
|
3993
4063
|
};
|
|
3994
4064
|
}
|
|
3995
4065
|
|
|
@@ -4344,7 +4414,13 @@ async function maybeEmitSurfaceSnapshot(ctx) {
|
|
|
4344
4414
|
intentParamNames: [USER_GOAL_PARAM_NAME],
|
|
4345
4415
|
intentParamMode: ctx.intentParamMode,
|
|
4346
4416
|
requiredParamNames: requiredParamNames(ctx.intentParamMode),
|
|
4347
|
-
instructionsSuffix: instructionsSuffixServed(ctx.annotationToolName, ctx.servedInstructions())
|
|
4417
|
+
instructionsSuffix: instructionsSuffixServed(ctx.annotationToolName, ctx.servedInstructions()),
|
|
4418
|
+
agentText: servedAgentText({
|
|
4419
|
+
reportNames: ctx.reportNames(),
|
|
4420
|
+
intentParamMode: ctx.intentParamMode,
|
|
4421
|
+
...goalTextsServed(snapshot.tools),
|
|
4422
|
+
serverOverlay: ctx.perCaller?.serverOverlay
|
|
4423
|
+
})
|
|
4348
4424
|
});
|
|
4349
4425
|
if (ctx.captureSettings !== void 0) seam.server_overlay = overlayId;
|
|
4350
4426
|
await ctx.emitSurface(ctx.fallbackSessionId, digest, { ...snapshot, seam_augmentations: seam });
|
|
@@ -4457,16 +4533,21 @@ function installLowLevelToolSeams(lowLevel, ctx, annotationTool, known, warnOnce
|
|
|
4457
4533
|
}
|
|
4458
4534
|
}
|
|
4459
4535
|
};
|
|
4536
|
+
const leaveReportNameToVendor = (name) => {
|
|
4537
|
+
warnOnce2(
|
|
4538
|
+
"report-tool-name-taken",
|
|
4539
|
+
`baton: the server lists its own tool ${JSON.stringify(name)}, so Baton's report tool is not added; set annotationToolName to another name`
|
|
4540
|
+
);
|
|
4541
|
+
reportTool2 = void 0;
|
|
4542
|
+
ctx.annotationToolName = "";
|
|
4543
|
+
reportToolTaken();
|
|
4544
|
+
};
|
|
4545
|
+
const takeReportNameIfListed = (tools) => {
|
|
4546
|
+
const name = reportTool2?.name;
|
|
4547
|
+
if (name !== void 0 && tools.some((tool) => tool.name === name)) leaveReportNameToVendor(name);
|
|
4548
|
+
};
|
|
4460
4549
|
const read = (tools, { surface }) => {
|
|
4461
|
-
if (surface
|
|
4462
|
-
warnOnce2(
|
|
4463
|
-
"report-tool-name-taken",
|
|
4464
|
-
`baton: the server lists its own tool ${JSON.stringify(reportTool2.name)}, so Baton's report tool is not added; set annotationToolName to another name`
|
|
4465
|
-
);
|
|
4466
|
-
reportTool2 = void 0;
|
|
4467
|
-
ctx.annotationToolName = "";
|
|
4468
|
-
reportToolTaken();
|
|
4469
|
-
}
|
|
4550
|
+
if (surface) takeReportNameIfListed(tools);
|
|
4470
4551
|
readToolList(tools, ctx, surface, skipNote);
|
|
4471
4552
|
};
|
|
4472
4553
|
const learn = (tools) => {
|
|
@@ -4554,6 +4635,10 @@ function installLowLevelToolSeams(lowLevel, ctx, annotationTool, known, warnOnce
|
|
|
4554
4635
|
}
|
|
4555
4636
|
return batonWrap({ current: name }, () => handler(...args), ctx, unlisted, slot?.caller)(toolArgs, args[1]);
|
|
4556
4637
|
});
|
|
4638
|
+
return () => {
|
|
4639
|
+
if (Array.isArray(known.given)) takeReportNameIfListed(toolInfos(known.given, () => {
|
|
4640
|
+
}));
|
|
4641
|
+
};
|
|
4557
4642
|
}
|
|
4558
4643
|
function lowLevelMajor(lowLevel) {
|
|
4559
4644
|
return typeof lowLevel._wrapHandler === "function" ? 2 : 1;
|
|
@@ -5197,6 +5282,7 @@ function install(server, supplied, resolved, { sentSurfaces, warned: warned4, co
|
|
|
5197
5282
|
server,
|
|
5198
5283
|
scrubber,
|
|
5199
5284
|
annotationToolName,
|
|
5285
|
+
reportNames: () => reports && ctx.annotationToolName ? { vendorDisplayName: reports.vendorDisplayName, annotationToolName: ctx.annotationToolName } : void 0,
|
|
5200
5286
|
intentParamMode,
|
|
5201
5287
|
configResultCaptureMode: config.resultCaptureMode ?? "full",
|
|
5202
5288
|
paramRegistry: /* @__PURE__ */ new Map(),
|
|
@@ -5227,7 +5313,10 @@ function install(server, supplied, resolved, { sentSurfaces, warned: warned4, co
|
|
|
5227
5313
|
get annotationToolName() {
|
|
5228
5314
|
return ctx.annotationToolName;
|
|
5229
5315
|
},
|
|
5230
|
-
pointer: () =>
|
|
5316
|
+
pointer: () => {
|
|
5317
|
+
const names = ctx.reportNames();
|
|
5318
|
+
return names && buildReportPointer(names);
|
|
5319
|
+
},
|
|
5231
5320
|
writeInstructions,
|
|
5232
5321
|
subagentLine: () => ![...ctx.paramRegistry.values()].some((d) => d[USER_GOAL_PARAM_NAME] === "native"),
|
|
5233
5322
|
injectsGoal: (name) => ctx.paramRegistry.get(name)?.[USER_GOAL_PARAM_NAME] === "injected"
|
|
@@ -5250,8 +5339,9 @@ function install(server, supplied, resolved, { sentSurfaces, warned: warned4, co
|
|
|
5250
5339
|
// `srv-..._annotate` while the instructions name the server-derived one.
|
|
5251
5340
|
annotationToolName
|
|
5252
5341
|
};
|
|
5342
|
+
let checkGivenTools;
|
|
5253
5343
|
if (shape === "lowLevel") {
|
|
5254
|
-
installLowLevelToolSeams(
|
|
5344
|
+
checkGivenTools = installLowLevelToolSeams(
|
|
5255
5345
|
lowLevel,
|
|
5256
5346
|
ctx,
|
|
5257
5347
|
annotationOptions && buildAnnotationTool(server, annotationOptions),
|
|
@@ -5295,7 +5385,10 @@ function install(server, supplied, resolved, { sentSurfaces, warned: warned4, co
|
|
|
5295
5385
|
sessionId: fallbackSessionId,
|
|
5296
5386
|
annotationToolName: name
|
|
5297
5387
|
});
|
|
5298
|
-
if (shape === "lowLevel")
|
|
5388
|
+
if (shape === "lowLevel") {
|
|
5389
|
+
checkGivenTools?.();
|
|
5390
|
+
return handle(annotationToolName);
|
|
5391
|
+
}
|
|
5299
5392
|
const resolvedAnnotationToolName = annotationOptions ? registerAnnotationTool(server, annotationOptions) : "";
|
|
5300
5393
|
const existing = internals._registeredTools;
|
|
5301
5394
|
if (existing) {
|
|
@@ -5461,7 +5554,13 @@ function snapshotPayload({ surface, digest }) {
|
|
|
5461
5554
|
intentParamNames: [USER_GOAL_PARAM_NAME],
|
|
5462
5555
|
intentParamMode: DEFAULT_INTENT_PARAM_MODE,
|
|
5463
5556
|
requiredParamNames: requiredParamNames(DEFAULT_INTENT_PARAM_MODE),
|
|
5464
|
-
instructionsSuffix: null
|
|
5557
|
+
instructionsSuffix: null,
|
|
5558
|
+
agentText: servedAgentText({
|
|
5559
|
+
reportNames: void 0,
|
|
5560
|
+
intentParamMode: DEFAULT_INTENT_PARAM_MODE,
|
|
5561
|
+
...goalTextsServed(surface.tools),
|
|
5562
|
+
vendorServesText: true
|
|
5563
|
+
})
|
|
5465
5564
|
})
|
|
5466
5565
|
};
|
|
5467
5566
|
}
|
|
@@ -5919,16 +6018,19 @@ function annotateArgs(args) {
|
|
|
5919
6018
|
}
|
|
5920
6019
|
function reportTool(options) {
|
|
5921
6020
|
const { vendorDisplayName } = options;
|
|
6021
|
+
if (isBlank(vendorDisplayName)) {
|
|
6022
|
+
throw new Error("vendorDisplayName is blank. Baton's report sentence names the server by it.");
|
|
6023
|
+
}
|
|
5922
6024
|
const derived = options.name ?? toolNameForDisplayName(vendorDisplayName);
|
|
5923
6025
|
if (derived === void 0) {
|
|
5924
6026
|
throw new Error(
|
|
5925
|
-
`vendorDisplayName ${JSON.stringify(vendorDisplayName)} gives no usable tool name, or one too long for
|
|
6027
|
+
`vendorDisplayName ${JSON.stringify(vendorDisplayName)} gives no usable tool name, or one too long for Baton's report sentence. Pass name.`
|
|
5926
6028
|
);
|
|
5927
6029
|
}
|
|
5928
6030
|
const name = validateAnnotationToolName(derived);
|
|
5929
|
-
if (!
|
|
6031
|
+
if (!fitsBatonSentenceCap({ vendorDisplayName, annotationToolName: name })) {
|
|
5930
6032
|
throw new Error(
|
|
5931
|
-
`vendorDisplayName and name ${JSON.stringify(name)} are too long together for
|
|
6033
|
+
`vendorDisplayName and name ${JSON.stringify(name)} are too long together for Baton's report sentence. Shorten one of them.`
|
|
5932
6034
|
);
|
|
5933
6035
|
}
|
|
5934
6036
|
return {
|