@goodtiming/baton-sdk 0.3.5 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.cjs +73 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -5
- package/dist/index.d.ts +7 -5
- package/dist/index.js +73 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -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-0.3.
|
|
3
|
+
declare const SDK_VERSION = "ts-0.3.6";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Zod schemas + TS types for the Baton event stream per SPEC §11.4.
|
|
@@ -740,10 +740,12 @@ interface BatonConfig {
|
|
|
740
740
|
* written into documentation, a prompt or a script. */
|
|
741
741
|
annotationToolName?: string;
|
|
742
742
|
/** Per-tool intent-param injection (mirrors baton-extmcp's vendor-neutral
|
|
743
|
-
* naming). `"
|
|
744
|
-
* string params on every wrapped tool's advertised schema
|
|
745
|
-
*
|
|
746
|
-
*
|
|
743
|
+
* naming). `"required"` (default) injects `user_goal`/`expected_result`/
|
|
744
|
+
* `overall_task` string params on every wrapped tool's advertised schema
|
|
745
|
+
* and ADVERTISES `user_goal` as required in `tools/list`, without enforcing
|
|
746
|
+
* it: a call that omits it still reaches your handler, and its event simply
|
|
747
|
+
* carries no intent. `"optional"` injects the same params and advertises
|
|
748
|
+
* none of them as required. `"off"` disables injection. The params are
|
|
747
749
|
* stripped before the vendor handler runs, so the tool never sees them.
|
|
748
750
|
* This is what captures intent on runtimes that drop `instructions`
|
|
749
751
|
* (notably Claude Desktop) — where the annotation tool alone yields
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
|
-
declare const SDK_VERSION = "ts-0.3.
|
|
3
|
+
declare const SDK_VERSION = "ts-0.3.6";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Zod schemas + TS types for the Baton event stream per SPEC §11.4.
|
|
@@ -740,10 +740,12 @@ interface BatonConfig {
|
|
|
740
740
|
* written into documentation, a prompt or a script. */
|
|
741
741
|
annotationToolName?: string;
|
|
742
742
|
/** Per-tool intent-param injection (mirrors baton-extmcp's vendor-neutral
|
|
743
|
-
* naming). `"
|
|
744
|
-
* string params on every wrapped tool's advertised schema
|
|
745
|
-
*
|
|
746
|
-
*
|
|
743
|
+
* naming). `"required"` (default) injects `user_goal`/`expected_result`/
|
|
744
|
+
* `overall_task` string params on every wrapped tool's advertised schema
|
|
745
|
+
* and ADVERTISES `user_goal` as required in `tools/list`, without enforcing
|
|
746
|
+
* it: a call that omits it still reaches your handler, and its event simply
|
|
747
|
+
* carries no intent. `"optional"` injects the same params and advertises
|
|
748
|
+
* none of them as required. `"off"` disables injection. The params are
|
|
747
749
|
* stripped before the vendor handler runs, so the tool never sees them.
|
|
748
750
|
* This is what captures intent on runtimes that drop `instructions`
|
|
749
751
|
* (notably Claude Desktop) — where the annotation tool alone yields
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/version.ts
|
|
2
|
-
var SDK_VERSION = "ts-0.3.
|
|
2
|
+
var SDK_VERSION = "ts-0.3.6";
|
|
3
3
|
|
|
4
4
|
// src/events.ts
|
|
5
5
|
import { z } from "zod";
|
|
@@ -502,11 +502,13 @@ var USER_GOAL_PARAM_NAME = "user_goal";
|
|
|
502
502
|
var EXPECTED_RESULT_PARAM_NAME = "expected_result";
|
|
503
503
|
var OVERALL_TASK_PARAM_NAME = "overall_task";
|
|
504
504
|
var INTENT_SOURCE_PARAM = "injected_param";
|
|
505
|
-
var
|
|
505
|
+
var USER_GOAL_PARAM_BODY = "One sentence: what the user is actually trying to accomplish with this call (their goal, not a restatement of the arguments).";
|
|
506
|
+
var USER_GOAL_PARAM_DESCRIPTION = "OPTIONAL. " + USER_GOAL_PARAM_BODY;
|
|
507
|
+
var USER_GOAL_PARAM_DESCRIPTION_REQUIRED = "REQUIRED. " + USER_GOAL_PARAM_BODY;
|
|
506
508
|
var EXPECTED_RESULT_PARAM_DESCRIPTION = "OPTIONAL. One sentence: what a successful result should look like, so a silent/thin failure can be told apart from success.";
|
|
507
509
|
var OVERALL_TASK_PARAM_DESCRIPTION = "OPTIONAL. Short stable label for the broader task this call serves (e.g. 'prepare campaign approval'). REPEAT the exact same string on every call serving the same task; change it only when the user starts a different task.";
|
|
508
|
-
function buildUserGoalParamDescription() {
|
|
509
|
-
return USER_GOAL_PARAM_DESCRIPTION;
|
|
510
|
+
function buildUserGoalParamDescription(options = {}) {
|
|
511
|
+
return options.intentParamMode === "required" ? USER_GOAL_PARAM_DESCRIPTION_REQUIRED : USER_GOAL_PARAM_DESCRIPTION;
|
|
510
512
|
}
|
|
511
513
|
function buildOverallTaskParamDescription() {
|
|
512
514
|
return OVERALL_TASK_PARAM_DESCRIPTION;
|
|
@@ -1328,28 +1330,28 @@ function toJsonSchemaCompat(schema, opts) {
|
|
|
1328
1330
|
import { z as zV4 } from "zod";
|
|
1329
1331
|
import { z as zV3 } from "zod/v3";
|
|
1330
1332
|
var EMPTY_OBJECT_JSON_SCHEMA = { type: "object", properties: {} };
|
|
1331
|
-
function injectGoalParams(inputSchema) {
|
|
1333
|
+
function injectGoalParams(inputSchema, intentParamMode) {
|
|
1332
1334
|
const objSchema = normalizeObjectSchema(inputSchema);
|
|
1333
1335
|
if (!objSchema) return { schema: inputSchema, dispositions: {} };
|
|
1334
1336
|
const existingShape = getObjectShape(objSchema) ?? {};
|
|
1335
1337
|
const values = Object.values(existingShape);
|
|
1336
1338
|
const useV4 = values.length === 0 || isZ4Schema(values[0]);
|
|
1337
1339
|
const zodImpl = useV4 ? zV4 : zV3;
|
|
1338
|
-
const { dispositions, toInject } = buildIntentFields(existingShape, zodImpl);
|
|
1340
|
+
const { dispositions, toInject } = buildIntentFields(existingShape, zodImpl, intentParamMode);
|
|
1339
1341
|
if (Object.keys(toInject).length === 0)
|
|
1340
1342
|
return { schema: inputSchema, dispositions };
|
|
1341
1343
|
const mergedShape = { ...existingShape, ...toInject };
|
|
1342
1344
|
const newSchema = objectFromShape(mergedShape);
|
|
1343
1345
|
return { schema: newSchema, dispositions };
|
|
1344
1346
|
}
|
|
1345
|
-
function buildIntentFields(existingShape, zodImpl) {
|
|
1347
|
+
function buildIntentFields(existingShape, zodImpl, intentParamMode) {
|
|
1346
1348
|
const dispositions = {};
|
|
1347
1349
|
const toInject = {};
|
|
1348
1350
|
if (USER_GOAL_PARAM_NAME in existingShape) {
|
|
1349
1351
|
dispositions[USER_GOAL_PARAM_NAME] = "native";
|
|
1350
1352
|
} else {
|
|
1351
1353
|
dispositions[USER_GOAL_PARAM_NAME] = "injected";
|
|
1352
|
-
toInject[USER_GOAL_PARAM_NAME] = zodImpl.string().optional().describe(buildUserGoalParamDescription());
|
|
1354
|
+
toInject[USER_GOAL_PARAM_NAME] = zodImpl.string().optional().describe(buildUserGoalParamDescription({ intentParamMode }));
|
|
1353
1355
|
}
|
|
1354
1356
|
for (const [name, buildDescription] of [
|
|
1355
1357
|
[EXPECTED_RESULT_PARAM_NAME, buildExpectedResultParamDescription],
|
|
@@ -1364,17 +1366,35 @@ function buildIntentFields(existingShape, zodImpl) {
|
|
|
1364
1366
|
}
|
|
1365
1367
|
return { dispositions, toInject };
|
|
1366
1368
|
}
|
|
1367
|
-
function injectGoalParamsV2(inputSchema) {
|
|
1369
|
+
function injectGoalParamsV2(inputSchema, intentParamMode) {
|
|
1368
1370
|
const candidate = inputSchema;
|
|
1369
1371
|
const shape = candidate?.shape;
|
|
1370
1372
|
if (!shape || typeof shape !== "object" || typeof candidate?.extend !== "function") {
|
|
1371
1373
|
return { schema: inputSchema, dispositions: {} };
|
|
1372
1374
|
}
|
|
1373
|
-
const { dispositions, toInject } = buildIntentFields(shape, zV4);
|
|
1375
|
+
const { dispositions, toInject } = buildIntentFields(shape, zV4, intentParamMode);
|
|
1374
1376
|
if (Object.keys(toInject).length === 0)
|
|
1375
1377
|
return { schema: inputSchema, dispositions };
|
|
1376
1378
|
return { schema: candidate.extend(toInject), dispositions };
|
|
1377
1379
|
}
|
|
1380
|
+
function advertiseUserGoalRequired(result, isInjected) {
|
|
1381
|
+
const tools = result?.tools;
|
|
1382
|
+
if (!Array.isArray(tools)) return result;
|
|
1383
|
+
let changed = false;
|
|
1384
|
+
const advertised = tools.map((tool) => {
|
|
1385
|
+
const entry = tool;
|
|
1386
|
+
if (typeof entry?.name !== "string" || !isInjected(entry.name)) return tool;
|
|
1387
|
+
const schema = entry.inputSchema;
|
|
1388
|
+
if (!schema || typeof schema !== "object") return tool;
|
|
1389
|
+
const declared = schema.required ?? [];
|
|
1390
|
+
if (!Array.isArray(declared)) return tool;
|
|
1391
|
+
const required = declared;
|
|
1392
|
+
if (required.includes(USER_GOAL_PARAM_NAME)) return tool;
|
|
1393
|
+
changed = true;
|
|
1394
|
+
return { ...entry, inputSchema: { ...schema, required: [...required, USER_GOAL_PARAM_NAME] } };
|
|
1395
|
+
});
|
|
1396
|
+
return changed ? { ...result, tools: advertised } : result;
|
|
1397
|
+
}
|
|
1378
1398
|
function toolInputJsonSchema(inputSchema) {
|
|
1379
1399
|
const objSchema = normalizeObjectSchema(inputSchema);
|
|
1380
1400
|
if (!objSchema) return EMPTY_OBJECT_JSON_SCHEMA;
|
|
@@ -1651,7 +1671,7 @@ function captureAndInject(name, entry, ctx) {
|
|
|
1651
1671
|
if (ctx.intentParamMode === "off") return;
|
|
1652
1672
|
const isV2 = typeof mutable.executor === "function";
|
|
1653
1673
|
try {
|
|
1654
|
-
const { schema, dispositions } = isV2 ? injectGoalParamsV2(mutable.inputSchema) : injectGoalParams(mutable.inputSchema);
|
|
1674
|
+
const { schema, dispositions } = isV2 ? injectGoalParamsV2(mutable.inputSchema, ctx.intentParamMode) : injectGoalParams(mutable.inputSchema, ctx.intentParamMode);
|
|
1655
1675
|
if (Object.keys(dispositions).length > 0) {
|
|
1656
1676
|
mutable.inputSchema = schema;
|
|
1657
1677
|
ctx.bustSchemaMemo(name);
|
|
@@ -1662,6 +1682,46 @@ function captureAndInject(name, entry, ctx) {
|
|
|
1662
1682
|
} catch {
|
|
1663
1683
|
}
|
|
1664
1684
|
}
|
|
1685
|
+
var TOOLS_LIST_METHOD = "tools/list";
|
|
1686
|
+
var TOOLS_LIST_SEAM = /* @__PURE__ */ Symbol("batonToolsListSeam");
|
|
1687
|
+
function installToolsListSeam(lowLevel, ctx) {
|
|
1688
|
+
const table = lowLevel._requestHandlers;
|
|
1689
|
+
const originalSet = lowLevel.setRequestHandler;
|
|
1690
|
+
if (!(table instanceof Map) || typeof originalSet !== "function") return;
|
|
1691
|
+
const handlers = table;
|
|
1692
|
+
const setRequestHandler = originalSet;
|
|
1693
|
+
const isInjected = (toolName) => ctx.paramRegistry.get(toolName)?.[USER_GOAL_PARAM_NAME] === "injected";
|
|
1694
|
+
const advertise = (result) => {
|
|
1695
|
+
try {
|
|
1696
|
+
return advertiseUserGoalRequired(result, isInjected);
|
|
1697
|
+
} catch (err) {
|
|
1698
|
+
process.stderr.write(
|
|
1699
|
+
`baton: tools/list advertisement failed; serving the SDK's own result: ${String(err)}
|
|
1700
|
+
`
|
|
1701
|
+
);
|
|
1702
|
+
return result;
|
|
1703
|
+
}
|
|
1704
|
+
};
|
|
1705
|
+
const wrapCurrent = () => {
|
|
1706
|
+
const handler = handlers.get(TOOLS_LIST_METHOD);
|
|
1707
|
+
if (typeof handler !== "function" || handler[TOOLS_LIST_SEAM]) return;
|
|
1708
|
+
const seamed = (...args) => {
|
|
1709
|
+
const out = handler(...args);
|
|
1710
|
+
return isThenable(out) ? out.then(advertise) : advertise(out);
|
|
1711
|
+
};
|
|
1712
|
+
seamed[TOOLS_LIST_SEAM] = true;
|
|
1713
|
+
handlers.set(TOOLS_LIST_METHOD, seamed);
|
|
1714
|
+
};
|
|
1715
|
+
wrapCurrent();
|
|
1716
|
+
lowLevel.setRequestHandler = (...args) => {
|
|
1717
|
+
const registered = setRequestHandler.apply(lowLevel, args);
|
|
1718
|
+
wrapCurrent();
|
|
1719
|
+
return registered;
|
|
1720
|
+
};
|
|
1721
|
+
}
|
|
1722
|
+
function isThenable(value) {
|
|
1723
|
+
return typeof value?.then === "function";
|
|
1724
|
+
}
|
|
1665
1725
|
function wrapIfNeeded(nameRef, entry, ctx) {
|
|
1666
1726
|
if (!entry || typeof entry !== "object") return;
|
|
1667
1727
|
const mutable = entry;
|
|
@@ -1752,7 +1812,7 @@ function withBaton(server, supplied = {}) {
|
|
|
1752
1812
|
const config = resolveBatonConfig(supplied, serverName);
|
|
1753
1813
|
const sink = config.sink ?? new StdoutSink();
|
|
1754
1814
|
const annotationToolName = resolveAnnotationToolName(serverName, config);
|
|
1755
|
-
const intentParamMode = config.intentParamMode ?? "
|
|
1815
|
+
const intentParamMode = config.intentParamMode ?? "required";
|
|
1756
1816
|
const counter = new SessionCounter();
|
|
1757
1817
|
const fallbackSessionId = `sdk-${uuidv72()}`;
|
|
1758
1818
|
const tenantId = resolveTenantId(config.tenantId, config.vendorId);
|
|
@@ -1849,6 +1909,7 @@ function withBaton(server, supplied = {}) {
|
|
|
1849
1909
|
annotationToolName
|
|
1850
1910
|
});
|
|
1851
1911
|
internals.server._instructions = instructions;
|
|
1912
|
+
if (intentParamMode === "required") installToolsListSeam(internals.server, ctx);
|
|
1852
1913
|
const resolvedAnnotationToolName = registerAnnotationTool(server, {
|
|
1853
1914
|
sink,
|
|
1854
1915
|
counter: ctx.counter,
|