@goodtiming/baton-sdk 0.5.8 → 0.6.1
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 +12 -2
- package/dist/index.cjs +165 -91
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +260 -7
- package/dist/index.d.ts +260 -7
- package/dist/index.js +165 -91
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -34,7 +34,9 @@ server.registerTool("lookup", { inputSchema: { name: z.string() } }, async ({ na
|
|
|
34
34
|
|
|
35
35
|
Copy the DSN from **/account**. It packs four values: the collector to send to, your workspace, this server, and the key that binds them. The SDK unpacks them and builds the sink itself.
|
|
36
36
|
|
|
37
|
-
**Installing changes what your server advertises.** Each tool handler is wrapped, one sentence is added below your server's own `instructions`, and a `user_goal` parameter is added to every tool's schema and stripped again before your handler sees it. With `reportMode: "on"`,
|
|
37
|
+
**Installing changes what your server advertises.** Each tool handler is wrapped, one sentence is added below your server's own `instructions`, and a `user_goal` parameter is added to every tool's schema and stripped again before your handler sees it. With `reportMode: "on"`, an annotation tool is also registered, named from your server's own name (slugged, `<server-name>_annotate`, so `your-vendor-mcp_annotate` here), and the added text tells the agent when to report a problem with it. [What gets injected](https://goodtiming.ai/docs.html#injected-tools).
|
|
38
|
+
|
|
39
|
+
With no DSN and no sink, events go to `StdoutSink`, which writes to stderr, so a stdio server's stdout stays clean and nothing goes over the network.
|
|
38
40
|
|
|
39
41
|
**If you distribute your server, put the DSN in your source.** A stdio server runs on your user's machine, spawned by their MCP client. The official client SDKs pass it a fixed six-variable allowlist (`HOME`, `LOGNAME`, `PATH`, `SHELL`, `TERM`, `USER`), plus whatever that user wrote in their own client config. Nothing from your `.env` is in either list, so a server configured that way captures nothing while appearing to work.
|
|
40
42
|
|
|
@@ -124,7 +126,7 @@ Capture never throws into your code. Only the constructor throws, on a bad confi
|
|
|
124
126
|
|
|
125
127
|
## Who is calling
|
|
126
128
|
|
|
127
|
-
**Nothing is captured about the person behind a call unless you say how to find them.** Pass `resolvePrincipal`: it receives the request's headers, `_meta`, tool name, arguments and validated `authInfo`, and returns a `Principal` or `null`. Two ready-made hooks cover OAuth:
|
|
129
|
+
**Nothing is captured about the person behind a call unless you say how to find them.** Pass `resolvePrincipal`: it receives the request's headers, `_meta`, tool name, arguments and validated `authInfo`, and returns a `Principal`, an `Organization` or `null`. Two ready-made hooks cover OAuth:
|
|
128
130
|
|
|
129
131
|
```typescript
|
|
130
132
|
import { withBaton, principalFromOAuthEmail } from "@goodtiming/baton-sdk";
|
|
@@ -143,6 +145,14 @@ The hook runs on every tool call, every `tools/list` request and every resource
|
|
|
143
145
|
|
|
144
146
|
The id is sent exactly as your hook returns it, so the hook decides what is safe to send. To send a pseudonym instead, hash the id inside your hook and return `form: "hashed"` with it.
|
|
145
147
|
|
|
148
|
+
If your users belong to your customers' companies, return the company too, so you can filter by it:
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
{ principalId: "u_123", organization: { organizationId: "org_acme", displayName: "Acme" } }
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
If you know only the company, for example from an org-wide API key, return `{ organizationId: ... }` alone. A company is never counted as a person. It has its own `form`, so you can hash one id and not the other. The library API takes the same values in `client.session({ principal })`. If you pass only a company there, also pass your own `sessionId`: without a person, Baton cannot join that block's calls to the next one.
|
|
155
|
+
|
|
146
156
|
## Not capturing responses at all
|
|
147
157
|
|
|
148
158
|
`resultCaptureMode: "off"` and nothing **derived from what your tool returns** leaves your process — not the result, and not the reason text on a failure your handler returns rather than throws. Requests are unaffected: `params` are captured either way.
|
package/dist/index.cjs
CHANGED
|
@@ -97,7 +97,7 @@ __export(index_exports, {
|
|
|
97
97
|
module.exports = __toCommonJS(index_exports);
|
|
98
98
|
|
|
99
99
|
// src/version.ts
|
|
100
|
-
var SDK_VERSION = "ts-0.
|
|
100
|
+
var SDK_VERSION = "ts-0.6.1";
|
|
101
101
|
|
|
102
102
|
// src/events.ts
|
|
103
103
|
var import_zod = require("zod");
|
|
@@ -242,6 +242,7 @@ var envelopeShape = {
|
|
|
242
242
|
// consumer names the client from `client_observed`.
|
|
243
243
|
agent_runtime: import_zod.z.string().default("unknown"),
|
|
244
244
|
principal: PrincipalWireSchema.nullable().default(null),
|
|
245
|
+
organization: PrincipalWireSchema.nullable().default(null),
|
|
245
246
|
transport_observed: import_zod.z.string().nullable().default(null),
|
|
246
247
|
session_id_origin: import_zod.z.string().nullable().default(null),
|
|
247
248
|
client_observed: ClientObservedSchema.nullable().default(null),
|
|
@@ -833,36 +834,93 @@ var LONE_SURROGATE = /\p{Surrogate}/u;
|
|
|
833
834
|
function pythonStrip(value) {
|
|
834
835
|
return value.replace(PYTHON_STRIP, "");
|
|
835
836
|
}
|
|
836
|
-
function
|
|
837
|
+
function usableId(id) {
|
|
838
|
+
if (typeof id !== "string") return false;
|
|
839
|
+
if (LONE_SURROGATE.test(id)) return false;
|
|
840
|
+
if (id.includes("\0")) return false;
|
|
841
|
+
return pythonStrip(id) !== "";
|
|
842
|
+
}
|
|
843
|
+
function readIdentity(result, idKey) {
|
|
837
844
|
if (result === null || typeof result !== "object") return null;
|
|
838
845
|
const candidate = result;
|
|
839
|
-
|
|
840
|
-
if (
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
846
|
+
const id = candidate[idKey];
|
|
847
|
+
if (!usableId(id)) return null;
|
|
848
|
+
const displayName = typeof candidate.displayName === "string" ? candidate.displayName : void 0;
|
|
849
|
+
return { id, form: candidate.form, displayName };
|
|
850
|
+
}
|
|
851
|
+
var NO_CALLER = Object.freeze({ principal: null, organization: null });
|
|
852
|
+
function callerFor(result, warn4) {
|
|
853
|
+
try {
|
|
854
|
+
return readCaller(result, warn4);
|
|
855
|
+
} catch {
|
|
856
|
+
warn4("unreadable", "could not be read \u2014 sending neither principal nor organization.");
|
|
857
|
+
return NO_CALLER;
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
function readCaller(result, warn4) {
|
|
861
|
+
if (result === void 0 || result === null) return NO_CALLER;
|
|
862
|
+
if (typeof result !== "object") {
|
|
863
|
+
warn4("not-object", `got a ${typeof result}, not an object \u2014 sending neither principal nor organization.`);
|
|
864
|
+
return NO_CALLER;
|
|
865
|
+
}
|
|
866
|
+
if (!("principalId" in result) && !("organization" in result)) {
|
|
867
|
+
if ("organizationId" in result) {
|
|
868
|
+
return { principal: null, organization: identityFor(result, "organization", warn4) };
|
|
869
|
+
}
|
|
870
|
+
if (typeof result.userId === "string") {
|
|
871
|
+
warn4(
|
|
872
|
+
"user-id",
|
|
873
|
+
"returned { userId }, which was renamed to { principalId } in 0.3.5, so the principal is dropped from every event until it returns the new key."
|
|
874
|
+
);
|
|
875
|
+
} else {
|
|
876
|
+
warn4("no-id", "got an object with neither principalId nor organizationId \u2014 sending neither.");
|
|
877
|
+
}
|
|
878
|
+
return NO_CALLER;
|
|
879
|
+
}
|
|
880
|
+
if ("organizationId" in result) {
|
|
881
|
+
warn4("flat-organization-id", "got principalId and organizationId side by side; put the company in `organization`.");
|
|
882
|
+
}
|
|
883
|
+
const nested = result.organization;
|
|
884
|
+
return {
|
|
885
|
+
principal: identityFor(result, "principal", warn4),
|
|
886
|
+
organization: nested == null ? null : identityFor(nested, "organization", warn4)
|
|
887
|
+
};
|
|
888
|
+
}
|
|
889
|
+
function identityFor(value, member, warn4) {
|
|
890
|
+
const idKey = member === "principal" ? "principalId" : "organizationId";
|
|
891
|
+
const identity = readIdentity(value, idKey);
|
|
892
|
+
if (identity === null) {
|
|
893
|
+
warn4(`${member}:id`, `${member} has no usable ${idKey} \u2014 sending no ${member}.`);
|
|
894
|
+
return null;
|
|
895
|
+
}
|
|
896
|
+
return identityWire(
|
|
897
|
+
identity.id,
|
|
898
|
+
identity.form,
|
|
899
|
+
identity.displayName,
|
|
900
|
+
(form) => warn4(`${member}:form`, `${member} form ${describeForm(form)} is not registered \u2014 sending "raw".`)
|
|
901
|
+
);
|
|
902
|
+
}
|
|
903
|
+
function describeForm(form) {
|
|
904
|
+
return typeof form === "string" ? JSON.stringify(form.slice(0, 32)) : `of type ${typeof form}`;
|
|
905
|
+
}
|
|
906
|
+
function identityWire(id, stated, displayName, onUnregisteredForm) {
|
|
849
907
|
let form = PRINCIPAL_FORM_RAW;
|
|
850
|
-
if (
|
|
851
|
-
if (PRINCIPAL_FORMS.has(
|
|
852
|
-
form =
|
|
908
|
+
if (stated !== void 0) {
|
|
909
|
+
if (PRINCIPAL_FORMS.has(stated)) {
|
|
910
|
+
form = stated;
|
|
853
911
|
} else {
|
|
854
|
-
onUnregisteredForm?.(
|
|
912
|
+
onUnregisteredForm?.(stated);
|
|
855
913
|
}
|
|
856
914
|
}
|
|
857
915
|
const wire = {
|
|
858
916
|
// `capCodePoints`, not `.slice()`: a plain slice counts UTF-16 units, so
|
|
859
917
|
// an astral id cut at the boundary would ship a lone surrogate.
|
|
860
|
-
id: capCodePoints(
|
|
918
|
+
id: capCodePoints(id, PRINCIPAL_ID_MAX_LEN),
|
|
861
919
|
source: PRINCIPAL_SOURCE_ASSERTED,
|
|
862
920
|
form
|
|
863
921
|
};
|
|
864
|
-
const
|
|
865
|
-
if (
|
|
922
|
+
const name = wireDisplayName(displayName);
|
|
923
|
+
if (name !== null) wire.display_name = name;
|
|
866
924
|
return wire;
|
|
867
925
|
}
|
|
868
926
|
|
|
@@ -1138,47 +1196,32 @@ async function withinHookBudget(answer) {
|
|
|
1138
1196
|
clearTimeout(timer);
|
|
1139
1197
|
}
|
|
1140
1198
|
}
|
|
1141
|
-
var
|
|
1142
|
-
function
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
warn(
|
|
1147
|
-
"baton: resolvePrincipal returned { userId }, which was renamed to { principalId } in 0.3.5, so the principal is dropped from every event until the hook returns the new key."
|
|
1148
|
-
);
|
|
1199
|
+
var warned = /* @__PURE__ */ new Set();
|
|
1200
|
+
function warnOnce(key, message) {
|
|
1201
|
+
if (warned.has(key)) return;
|
|
1202
|
+
warned.add(key);
|
|
1203
|
+
warn(`baton: resolvePrincipal ${message}`);
|
|
1149
1204
|
}
|
|
1150
|
-
async function
|
|
1151
|
-
if (hook === void 0) return
|
|
1205
|
+
async function resolveCaller(hook, call) {
|
|
1206
|
+
if (hook === void 0) return NO_CALLER;
|
|
1152
1207
|
try {
|
|
1153
1208
|
const context = buildPrincipalResolutionContext(call.extra, call.toolName, call.arguments);
|
|
1154
1209
|
const result = await withinHookBudget(hook(context));
|
|
1155
|
-
|
|
1156
|
-
if (principal === null) {
|
|
1157
|
-
warnIfPreRenameShape(result);
|
|
1158
|
-
return null;
|
|
1159
|
-
}
|
|
1160
|
-
return principalFor(principal, (form) => {
|
|
1161
|
-
warn(
|
|
1162
|
-
`baton: resolvePrincipal returned form ${describeForm(form)}, expected "raw" or "hashed" \u2014 sending it as "${PRINCIPAL_FORM_RAW}".`
|
|
1163
|
-
);
|
|
1164
|
-
});
|
|
1210
|
+
return callerFor(result, warnOnce);
|
|
1165
1211
|
} catch {
|
|
1166
|
-
return
|
|
1212
|
+
return NO_CALLER;
|
|
1167
1213
|
}
|
|
1168
1214
|
}
|
|
1169
|
-
function describeForm(form) {
|
|
1170
|
-
return typeof form === "string" ? JSON.stringify(form.slice(0, 32)) : `of type ${typeof form}`;
|
|
1171
|
-
}
|
|
1172
1215
|
|
|
1173
1216
|
// src/integrations/mcp/safeScrub.ts
|
|
1174
|
-
var
|
|
1217
|
+
var warned2 = /* @__PURE__ */ new Set();
|
|
1175
1218
|
function scrubOrNull(scrubber, value, field) {
|
|
1176
1219
|
if (value === null) return null;
|
|
1177
1220
|
try {
|
|
1178
1221
|
return scrubber(value);
|
|
1179
1222
|
} catch (err) {
|
|
1180
|
-
if (!
|
|
1181
|
-
|
|
1223
|
+
if (!warned2.has(field)) {
|
|
1224
|
+
warned2.add(field);
|
|
1182
1225
|
process.stderr.write(
|
|
1183
1226
|
`baton: scrubber threw on ${field}; that field is dropped, tool call continues. Further failures on this field will be silent: ${String(err)}
|
|
1184
1227
|
`
|
|
@@ -1351,7 +1394,7 @@ function registerAnnotationTool(server, options) {
|
|
|
1351
1394
|
"_meta"
|
|
1352
1395
|
);
|
|
1353
1396
|
const { sessionId, origin } = await resolveSessionId(options.fallbackSessionId, extra);
|
|
1354
|
-
const
|
|
1397
|
+
const caller = await resolveCaller(
|
|
1355
1398
|
options.resolvePrincipal,
|
|
1356
1399
|
{ extra, toolName: name, arguments: args }
|
|
1357
1400
|
);
|
|
@@ -1364,7 +1407,8 @@ function registerAnnotationTool(server, options) {
|
|
|
1364
1407
|
sequence_number: options.counter.next(sessionId),
|
|
1365
1408
|
captured_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1366
1409
|
consent_token: options.consentToken,
|
|
1367
|
-
principal,
|
|
1410
|
+
principal: caller.principal,
|
|
1411
|
+
organization: caller.organization,
|
|
1368
1412
|
transport_observed: observeTransport(extra),
|
|
1369
1413
|
session_id_origin: origin,
|
|
1370
1414
|
client_observed: observeClient(extra, { server, scrubber: options.scrubber }),
|
|
@@ -1596,11 +1640,14 @@ function sealKey(dsn) {
|
|
|
1596
1640
|
// src/integrations/mcp/errorResult.ts
|
|
1597
1641
|
var TOOL_ERROR_TYPE = "tool_error";
|
|
1598
1642
|
var OUTPUT_SCHEMA_MISMATCH = "output_schema_mismatch";
|
|
1643
|
+
var REFUSED = "refused";
|
|
1599
1644
|
var TASK_MODES = /* @__PURE__ */ new Set(["required", "optional"]);
|
|
1600
|
-
function requestSideFailureKind(entry) {
|
|
1645
|
+
function requestSideFailureKind(entry, validation) {
|
|
1601
1646
|
if (entry == null) return "unknown_tool";
|
|
1602
1647
|
if (entry.enabled === false) return "tool_disabled";
|
|
1603
|
-
|
|
1648
|
+
if (validation === "rejected") return "invalid_argument";
|
|
1649
|
+
if (TASK_MODES.has(entry.execution?.taskSupport)) return void 0;
|
|
1650
|
+
return validation === "unprobed" ? "invalid_argument" : REFUSED;
|
|
1604
1651
|
}
|
|
1605
1652
|
var ERROR_BODY_MAX_CODE_POINTS = 2e3;
|
|
1606
1653
|
function isErrorResult(value) {
|
|
@@ -1651,6 +1698,9 @@ function resultDerivedFields(mode, text, result, errorBody2, scrubber) {
|
|
|
1651
1698
|
function requestSideErrorFields(text, errorBody2) {
|
|
1652
1699
|
return { error_body: errorBody2(text), result: null };
|
|
1653
1700
|
}
|
|
1701
|
+
function requestSideFailureFields(kind, mode, text, result, errorBody2, scrubber) {
|
|
1702
|
+
return kind === REFUSED ? resultDerivedFields(mode, text, result ?? null, errorBody2, scrubber) : requestSideErrorFields(text(), errorBody2);
|
|
1703
|
+
}
|
|
1654
1704
|
function errorTypeOf(err) {
|
|
1655
1705
|
return err instanceof Error ? err.constructor.name : "Error";
|
|
1656
1706
|
}
|
|
@@ -2129,7 +2179,7 @@ async function openCall(ctx, toolName, extra, params, retired, registered = true
|
|
|
2129
2179
|
const [scrubbedExpected = null, scrubbedWorkflow = null] = RETIRED_PARAM_NAMES.map(
|
|
2130
2180
|
(name) => dispositions === void 0 || dispositions[name] === "native" ? null : scrubOrNull(ctx.scrubber, retired[name] ?? popText(params, name), name)
|
|
2131
2181
|
);
|
|
2132
|
-
const
|
|
2182
|
+
const caller = await resolveCaller(
|
|
2133
2183
|
ctx.resolvePrincipal,
|
|
2134
2184
|
{ extra, toolName, arguments: params }
|
|
2135
2185
|
);
|
|
@@ -2142,7 +2192,8 @@ async function openCall(ctx, toolName, extra, params, retired, registered = true
|
|
|
2142
2192
|
// it. `surface_snapshot` is deliberately not among them: it describes the
|
|
2143
2193
|
// SERVER and is captured outside any call, so it has no caller, transport
|
|
2144
2194
|
// or client to name.
|
|
2145
|
-
principal,
|
|
2195
|
+
principal: caller.principal,
|
|
2196
|
+
organization: caller.organization,
|
|
2146
2197
|
transport_observed: observeTransport(extra),
|
|
2147
2198
|
session_id_origin: origin,
|
|
2148
2199
|
client_observed: observeClient(extra, ctx),
|
|
@@ -2525,7 +2576,7 @@ function installLifecycleSeam(lowLevel, ctx, spec) {
|
|
|
2525
2576
|
async function openLifecycleCall(ctx, spec, requestParams, extra) {
|
|
2526
2577
|
try {
|
|
2527
2578
|
const parts = await resolveEnvelopeParts(ctx, extra);
|
|
2528
|
-
const
|
|
2579
|
+
const caller = await resolveCaller(ctx.resolvePrincipal, {
|
|
2529
2580
|
extra,
|
|
2530
2581
|
toolName: null,
|
|
2531
2582
|
arguments: {}
|
|
@@ -2538,7 +2589,8 @@ async function openLifecycleCall(ctx, spec, requestParams, extra) {
|
|
|
2538
2589
|
vendor_id: ctx.vendorId,
|
|
2539
2590
|
session_id: parts.sessionId,
|
|
2540
2591
|
consent_token: ctx.consentToken,
|
|
2541
|
-
principal,
|
|
2592
|
+
principal: caller.principal,
|
|
2593
|
+
organization: caller.organization,
|
|
2542
2594
|
transport_observed: observeTransport(extra),
|
|
2543
2595
|
session_id_origin: parts.origin,
|
|
2544
2596
|
client_observed: observeClient(extra, ctx),
|
|
@@ -2670,7 +2722,8 @@ function installToolsCallSeam(lowLevel, toolEntry, ctx) {
|
|
|
2670
2722
|
const slot = {
|
|
2671
2723
|
innerFired: false,
|
|
2672
2724
|
flushTerminal: null,
|
|
2673
|
-
retired: stripRetiredParams(request?.params, ctx)
|
|
2725
|
+
retired: stripRetiredParams(request?.params, ctx),
|
|
2726
|
+
validation: ctx.validationProbeLive() ? "unseen" : "unprobed"
|
|
2674
2727
|
};
|
|
2675
2728
|
let outcome = CLEAN_OUTCOME;
|
|
2676
2729
|
try {
|
|
@@ -2686,6 +2739,27 @@ function installToolsCallSeam(lowLevel, toolEntry, ctx) {
|
|
|
2686
2739
|
}
|
|
2687
2740
|
);
|
|
2688
2741
|
}
|
|
2742
|
+
var VALIDATION_PROBE = /* @__PURE__ */ Symbol("baton.validationProbe");
|
|
2743
|
+
function installValidationProbe(server) {
|
|
2744
|
+
const target = server;
|
|
2745
|
+
const original = target.validateToolInput;
|
|
2746
|
+
if (typeof original !== "function") return () => false;
|
|
2747
|
+
if (original[VALIDATION_PROBE]) return () => target.validateToolInput === original;
|
|
2748
|
+
const probe = async function(...args) {
|
|
2749
|
+
const slot = callSlots.getStore();
|
|
2750
|
+
try {
|
|
2751
|
+
const parsed = await original.apply(this, args);
|
|
2752
|
+
if (slot) slot.validation = "passed";
|
|
2753
|
+
return parsed;
|
|
2754
|
+
} catch (err) {
|
|
2755
|
+
if (slot) slot.validation = "rejected";
|
|
2756
|
+
throw err;
|
|
2757
|
+
}
|
|
2758
|
+
};
|
|
2759
|
+
Object.assign(probe, { [VALIDATION_PROBE]: true });
|
|
2760
|
+
target.validateToolInput = probe;
|
|
2761
|
+
return () => target.validateToolInput === probe;
|
|
2762
|
+
}
|
|
2689
2763
|
async function settleCall(slot, outcome, args, toolEntry, ctx) {
|
|
2690
2764
|
try {
|
|
2691
2765
|
if (slot.flushTerminal !== null) {
|
|
@@ -2696,13 +2770,13 @@ async function settleCall(slot, outcome, args, toolEntry, ctx) {
|
|
|
2696
2770
|
}
|
|
2697
2771
|
if (slot.innerFired) return;
|
|
2698
2772
|
if (!outcome.failed) return;
|
|
2699
|
-
await emitRequestSideFailure(outcome, args, slot
|
|
2773
|
+
await emitRequestSideFailure(outcome, args, slot, toolEntry, ctx);
|
|
2700
2774
|
} catch (err) {
|
|
2701
2775
|
process.stderr.write(`baton: settling a tool call failed; events dropped: ${String(err)}
|
|
2702
2776
|
`);
|
|
2703
2777
|
}
|
|
2704
2778
|
}
|
|
2705
|
-
async function emitRequestSideFailure(outcome, args,
|
|
2779
|
+
async function emitRequestSideFailure(outcome, args, slot, toolEntry, ctx) {
|
|
2706
2780
|
const request = args[0];
|
|
2707
2781
|
const toolName = request?.params?.name;
|
|
2708
2782
|
if (typeof toolName !== "string") return;
|
|
@@ -2710,8 +2784,16 @@ async function emitRequestSideFailure(outcome, args, retired, toolEntry, ctx) {
|
|
|
2710
2784
|
const entry = toolEntry(toolName);
|
|
2711
2785
|
if (entry != null && dispatchTarget(entry)?.[BATON_WRAPPED] !== true) return;
|
|
2712
2786
|
const params = { ...request?.params?.arguments ?? {} };
|
|
2713
|
-
const { common, sessionId } = await openCall(
|
|
2714
|
-
|
|
2787
|
+
const { common, sessionId } = await openCall(
|
|
2788
|
+
ctx,
|
|
2789
|
+
toolName,
|
|
2790
|
+
args[1],
|
|
2791
|
+
params,
|
|
2792
|
+
slot.retired,
|
|
2793
|
+
entry != null
|
|
2794
|
+
);
|
|
2795
|
+
const failureKind = requestSideFailureKind(entry, slot.validation);
|
|
2796
|
+
const text = () => outcome.raised ? messageOf(outcome.err) : errorText(outcome.result);
|
|
2715
2797
|
await emit(
|
|
2716
2798
|
ctx.sink,
|
|
2717
2799
|
() => ToolCallErrorEventSchema.parse({
|
|
@@ -2732,8 +2814,8 @@ async function emitRequestSideFailure(outcome, args, retired, toolEntry, ctx) {
|
|
|
2732
2814
|
error_type: outcome.raised ? errorTypeOf(outcome.err) : TOOL_ERROR_TYPE,
|
|
2733
2815
|
// ⚠ `null`, not 0. The vendor's handler never ran, so there is no
|
|
2734
2816
|
// handler duration to report; the time this call did spend was spent
|
|
2735
|
-
//
|
|
2736
|
-
//
|
|
2817
|
+
// above the handler, which is not what any other event means by this
|
|
2818
|
+
// member. §11.4 types it nullable for cases like this one.
|
|
2737
2819
|
duration_ms: null,
|
|
2738
2820
|
// ⚠ A CONDITIONAL SPREAD, not `failure_kind: failureKind`. Zod's
|
|
2739
2821
|
// `.optional()` accepts `undefined` and keeps the KEY in its output,
|
|
@@ -2743,11 +2825,13 @@ async function emitRequestSideFailure(outcome, args, retired, toolEntry, ctx) {
|
|
|
2743
2825
|
// determine the kind MUST OMIT the member, and omitting is what this
|
|
2744
2826
|
// spells.
|
|
2745
2827
|
...failureKind === void 0 ? {} : { failure_kind: failureKind },
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2828
|
+
...requestSideFailureFields(
|
|
2829
|
+
failureKind,
|
|
2830
|
+
ctx.resultCaptureMode,
|
|
2831
|
+
text,
|
|
2832
|
+
outcome.raised ? null : outcome.result,
|
|
2833
|
+
(value) => errorBody(ctx, value),
|
|
2834
|
+
ctx.scrubber
|
|
2751
2835
|
)
|
|
2752
2836
|
}
|
|
2753
2837
|
})
|
|
@@ -2850,16 +2934,16 @@ function createBaton(supplied = {}) {
|
|
|
2850
2934
|
tenantId: resolveTenantId(resolved.tenantId, resolved.vendorId)
|
|
2851
2935
|
};
|
|
2852
2936
|
const emittedSurfaceHashes = /* @__PURE__ */ new Set();
|
|
2853
|
-
const
|
|
2937
|
+
const warned3 = /* @__PURE__ */ new Set();
|
|
2854
2938
|
return {
|
|
2855
2939
|
wrap: (server) => {
|
|
2856
|
-
install(server, supplied, config, emittedSurfaceHashes,
|
|
2940
|
+
install(server, supplied, config, emittedSurfaceHashes, warned3);
|
|
2857
2941
|
},
|
|
2858
2942
|
flush: () => sink.flush(),
|
|
2859
2943
|
aclose: () => sink.aclose()
|
|
2860
2944
|
};
|
|
2861
2945
|
}
|
|
2862
|
-
function install(server, supplied, resolved, emittedSurfaceHashes,
|
|
2946
|
+
function install(server, supplied, resolved, emittedSurfaceHashes, warned3) {
|
|
2863
2947
|
const internals = server;
|
|
2864
2948
|
const serverName = usableServerName(() => ({
|
|
2865
2949
|
name: internals.server._serverInfo?.name,
|
|
@@ -2900,9 +2984,9 @@ function install(server, supplied, resolved, emittedSurfaceHashes, warned2) {
|
|
|
2900
2984
|
const memo = internals._toolInputSchemaJson;
|
|
2901
2985
|
if (memo && typeof memo === "object") delete memo[name];
|
|
2902
2986
|
};
|
|
2903
|
-
const
|
|
2904
|
-
if (
|
|
2905
|
-
|
|
2987
|
+
const warnOnce2 = (key, message) => {
|
|
2988
|
+
if (warned3.has(key)) return;
|
|
2989
|
+
warned3.add(key);
|
|
2906
2990
|
process.stderr.write(message);
|
|
2907
2991
|
};
|
|
2908
2992
|
const dropSubagentClause = (name) => {
|
|
@@ -2914,7 +2998,7 @@ function install(server, supplied, resolved, emittedSurfaceHashes, warned2) {
|
|
|
2914
2998
|
} else {
|
|
2915
2999
|
return;
|
|
2916
3000
|
}
|
|
2917
|
-
|
|
3001
|
+
warnOnce2(
|
|
2918
3002
|
"native-user-goal",
|
|
2919
3003
|
`baton: tool ${JSON.stringify(name)} declares its own user_goal, so the subagent sentence was removed from the server instructions; a session that already started keeps it
|
|
2920
3004
|
`
|
|
@@ -2953,6 +3037,7 @@ function install(server, supplied, resolved, emittedSurfaceHashes, warned2) {
|
|
|
2953
3037
|
annotationToolName,
|
|
2954
3038
|
intentParamMode,
|
|
2955
3039
|
resultCaptureMode: config.resultCaptureMode ?? "full",
|
|
3040
|
+
validationProbeLive: installValidationProbe(server),
|
|
2956
3041
|
paramRegistry: /* @__PURE__ */ new Map(),
|
|
2957
3042
|
resolvePrincipal: config.resolvePrincipal,
|
|
2958
3043
|
vendorToolJsonSchema,
|
|
@@ -2966,7 +3051,7 @@ function install(server, supplied, resolved, emittedSurfaceHashes, warned2) {
|
|
|
2966
3051
|
internals.server._instructions = withVendorInstructions(
|
|
2967
3052
|
internals.server,
|
|
2968
3053
|
ours,
|
|
2969
|
-
(message) =>
|
|
3054
|
+
(message) => warnOnce2("instructions-length", message)
|
|
2970
3055
|
);
|
|
2971
3056
|
installToolsListSeam(internals.server, ctx);
|
|
2972
3057
|
installToolsCallSeam(
|
|
@@ -3073,6 +3158,7 @@ function sessionEnvelope(session) {
|
|
|
3073
3158
|
session_id_origin: session.origin,
|
|
3074
3159
|
transport_observed: TRANSPORT_LIBRARY,
|
|
3075
3160
|
principal: session.principal,
|
|
3161
|
+
organization: session.organization,
|
|
3076
3162
|
client_observed: session.clientObserved,
|
|
3077
3163
|
runtime_meta: session.turnId !== null ? { [TURN_ID_META_KEY]: session.turnId } : null
|
|
3078
3164
|
};
|
|
@@ -3089,28 +3175,16 @@ function vendorId(name, value) {
|
|
|
3089
3175
|
}
|
|
3090
3176
|
return null;
|
|
3091
3177
|
}
|
|
3092
|
-
function
|
|
3093
|
-
return { sessionId
|
|
3094
|
-
}
|
|
3095
|
-
function wirePrincipal(value) {
|
|
3096
|
-
if (value === void 0 || value === null) return null;
|
|
3097
|
-
const principal = normalizePrincipal(value);
|
|
3098
|
-
if (principal === null) {
|
|
3099
|
-
warn3("principal was given but has no usable principalId \u2014 sending none.");
|
|
3100
|
-
return null;
|
|
3101
|
-
}
|
|
3102
|
-
return principalFor(
|
|
3103
|
-
principal,
|
|
3104
|
-
(form) => warn3(`principal form ${JSON.stringify(form)} is not registered \u2014 sending "raw".`)
|
|
3105
|
-
);
|
|
3178
|
+
function blank(sessionId, origin) {
|
|
3179
|
+
return { sessionId, origin, ...NO_CALLER, clientObserved: null, turnId: null };
|
|
3106
3180
|
}
|
|
3107
3181
|
function newSession(values, scrubber, disabled) {
|
|
3108
3182
|
const id = vendorId("sessionId", values.sessionId);
|
|
3109
|
-
const base = id !== null ?
|
|
3183
|
+
const base = id !== null ? blank(id, "observed") : blank(uuid7(), "minted");
|
|
3110
3184
|
if (disabled) return base;
|
|
3111
3185
|
return {
|
|
3112
3186
|
...base,
|
|
3113
|
-
|
|
3187
|
+
...callerFor(values.principal, (_key, message) => warn3(`principal ${message}`)),
|
|
3114
3188
|
clientObserved: clientObservedFrom(values.clientInfo, values.headers, scrubber),
|
|
3115
3189
|
turnId: vendorId("turnId", values.turnId)
|
|
3116
3190
|
};
|
|
@@ -3121,7 +3195,7 @@ function runInSession(owner, session, fn) {
|
|
|
3121
3195
|
}
|
|
3122
3196
|
function sessionForCall(owner) {
|
|
3123
3197
|
const entry = current.getStore();
|
|
3124
|
-
return entry !== void 0 && entry.owner === owner ? entry.session :
|
|
3198
|
+
return entry !== void 0 && entry.owner === owner ? entry.session : blank(uuid7(), "minted");
|
|
3125
3199
|
}
|
|
3126
3200
|
var lastSequence = 0;
|
|
3127
3201
|
function nextSequence() {
|