@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/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/version.ts
|
|
2
|
-
var SDK_VERSION = "ts-0.
|
|
2
|
+
var SDK_VERSION = "ts-0.6.1";
|
|
3
3
|
|
|
4
4
|
// src/events.ts
|
|
5
5
|
import { z } from "zod";
|
|
@@ -144,6 +144,7 @@ var envelopeShape = {
|
|
|
144
144
|
// consumer names the client from `client_observed`.
|
|
145
145
|
agent_runtime: z.string().default("unknown"),
|
|
146
146
|
principal: PrincipalWireSchema.nullable().default(null),
|
|
147
|
+
organization: PrincipalWireSchema.nullable().default(null),
|
|
147
148
|
transport_observed: z.string().nullable().default(null),
|
|
148
149
|
session_id_origin: z.string().nullable().default(null),
|
|
149
150
|
client_observed: ClientObservedSchema.nullable().default(null),
|
|
@@ -735,36 +736,93 @@ var LONE_SURROGATE = /\p{Surrogate}/u;
|
|
|
735
736
|
function pythonStrip(value) {
|
|
736
737
|
return value.replace(PYTHON_STRIP, "");
|
|
737
738
|
}
|
|
738
|
-
function
|
|
739
|
+
function usableId(id) {
|
|
740
|
+
if (typeof id !== "string") return false;
|
|
741
|
+
if (LONE_SURROGATE.test(id)) return false;
|
|
742
|
+
if (id.includes("\0")) return false;
|
|
743
|
+
return pythonStrip(id) !== "";
|
|
744
|
+
}
|
|
745
|
+
function readIdentity(result, idKey) {
|
|
739
746
|
if (result === null || typeof result !== "object") return null;
|
|
740
747
|
const candidate = result;
|
|
741
|
-
|
|
742
|
-
if (
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
748
|
+
const id = candidate[idKey];
|
|
749
|
+
if (!usableId(id)) return null;
|
|
750
|
+
const displayName = typeof candidate.displayName === "string" ? candidate.displayName : void 0;
|
|
751
|
+
return { id, form: candidate.form, displayName };
|
|
752
|
+
}
|
|
753
|
+
var NO_CALLER = Object.freeze({ principal: null, organization: null });
|
|
754
|
+
function callerFor(result, warn4) {
|
|
755
|
+
try {
|
|
756
|
+
return readCaller(result, warn4);
|
|
757
|
+
} catch {
|
|
758
|
+
warn4("unreadable", "could not be read \u2014 sending neither principal nor organization.");
|
|
759
|
+
return NO_CALLER;
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
function readCaller(result, warn4) {
|
|
763
|
+
if (result === void 0 || result === null) return NO_CALLER;
|
|
764
|
+
if (typeof result !== "object") {
|
|
765
|
+
warn4("not-object", `got a ${typeof result}, not an object \u2014 sending neither principal nor organization.`);
|
|
766
|
+
return NO_CALLER;
|
|
767
|
+
}
|
|
768
|
+
if (!("principalId" in result) && !("organization" in result)) {
|
|
769
|
+
if ("organizationId" in result) {
|
|
770
|
+
return { principal: null, organization: identityFor(result, "organization", warn4) };
|
|
771
|
+
}
|
|
772
|
+
if (typeof result.userId === "string") {
|
|
773
|
+
warn4(
|
|
774
|
+
"user-id",
|
|
775
|
+
"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."
|
|
776
|
+
);
|
|
777
|
+
} else {
|
|
778
|
+
warn4("no-id", "got an object with neither principalId nor organizationId \u2014 sending neither.");
|
|
779
|
+
}
|
|
780
|
+
return NO_CALLER;
|
|
781
|
+
}
|
|
782
|
+
if ("organizationId" in result) {
|
|
783
|
+
warn4("flat-organization-id", "got principalId and organizationId side by side; put the company in `organization`.");
|
|
784
|
+
}
|
|
785
|
+
const nested = result.organization;
|
|
786
|
+
return {
|
|
787
|
+
principal: identityFor(result, "principal", warn4),
|
|
788
|
+
organization: nested == null ? null : identityFor(nested, "organization", warn4)
|
|
789
|
+
};
|
|
790
|
+
}
|
|
791
|
+
function identityFor(value, member, warn4) {
|
|
792
|
+
const idKey = member === "principal" ? "principalId" : "organizationId";
|
|
793
|
+
const identity = readIdentity(value, idKey);
|
|
794
|
+
if (identity === null) {
|
|
795
|
+
warn4(`${member}:id`, `${member} has no usable ${idKey} \u2014 sending no ${member}.`);
|
|
796
|
+
return null;
|
|
797
|
+
}
|
|
798
|
+
return identityWire(
|
|
799
|
+
identity.id,
|
|
800
|
+
identity.form,
|
|
801
|
+
identity.displayName,
|
|
802
|
+
(form) => warn4(`${member}:form`, `${member} form ${describeForm(form)} is not registered \u2014 sending "raw".`)
|
|
803
|
+
);
|
|
804
|
+
}
|
|
805
|
+
function describeForm(form) {
|
|
806
|
+
return typeof form === "string" ? JSON.stringify(form.slice(0, 32)) : `of type ${typeof form}`;
|
|
807
|
+
}
|
|
808
|
+
function identityWire(id, stated, displayName, onUnregisteredForm) {
|
|
751
809
|
let form = PRINCIPAL_FORM_RAW;
|
|
752
|
-
if (
|
|
753
|
-
if (PRINCIPAL_FORMS.has(
|
|
754
|
-
form =
|
|
810
|
+
if (stated !== void 0) {
|
|
811
|
+
if (PRINCIPAL_FORMS.has(stated)) {
|
|
812
|
+
form = stated;
|
|
755
813
|
} else {
|
|
756
|
-
onUnregisteredForm?.(
|
|
814
|
+
onUnregisteredForm?.(stated);
|
|
757
815
|
}
|
|
758
816
|
}
|
|
759
817
|
const wire = {
|
|
760
818
|
// `capCodePoints`, not `.slice()`: a plain slice counts UTF-16 units, so
|
|
761
819
|
// an astral id cut at the boundary would ship a lone surrogate.
|
|
762
|
-
id: capCodePoints(
|
|
820
|
+
id: capCodePoints(id, PRINCIPAL_ID_MAX_LEN),
|
|
763
821
|
source: PRINCIPAL_SOURCE_ASSERTED,
|
|
764
822
|
form
|
|
765
823
|
};
|
|
766
|
-
const
|
|
767
|
-
if (
|
|
824
|
+
const name = wireDisplayName(displayName);
|
|
825
|
+
if (name !== null) wire.display_name = name;
|
|
768
826
|
return wire;
|
|
769
827
|
}
|
|
770
828
|
|
|
@@ -1040,47 +1098,32 @@ async function withinHookBudget(answer) {
|
|
|
1040
1098
|
clearTimeout(timer);
|
|
1041
1099
|
}
|
|
1042
1100
|
}
|
|
1043
|
-
var
|
|
1044
|
-
function
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
warn(
|
|
1049
|
-
"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."
|
|
1050
|
-
);
|
|
1101
|
+
var warned = /* @__PURE__ */ new Set();
|
|
1102
|
+
function warnOnce(key, message) {
|
|
1103
|
+
if (warned.has(key)) return;
|
|
1104
|
+
warned.add(key);
|
|
1105
|
+
warn(`baton: resolvePrincipal ${message}`);
|
|
1051
1106
|
}
|
|
1052
|
-
async function
|
|
1053
|
-
if (hook === void 0) return
|
|
1107
|
+
async function resolveCaller(hook, call) {
|
|
1108
|
+
if (hook === void 0) return NO_CALLER;
|
|
1054
1109
|
try {
|
|
1055
1110
|
const context = buildPrincipalResolutionContext(call.extra, call.toolName, call.arguments);
|
|
1056
1111
|
const result = await withinHookBudget(hook(context));
|
|
1057
|
-
|
|
1058
|
-
if (principal === null) {
|
|
1059
|
-
warnIfPreRenameShape(result);
|
|
1060
|
-
return null;
|
|
1061
|
-
}
|
|
1062
|
-
return principalFor(principal, (form) => {
|
|
1063
|
-
warn(
|
|
1064
|
-
`baton: resolvePrincipal returned form ${describeForm(form)}, expected "raw" or "hashed" \u2014 sending it as "${PRINCIPAL_FORM_RAW}".`
|
|
1065
|
-
);
|
|
1066
|
-
});
|
|
1112
|
+
return callerFor(result, warnOnce);
|
|
1067
1113
|
} catch {
|
|
1068
|
-
return
|
|
1114
|
+
return NO_CALLER;
|
|
1069
1115
|
}
|
|
1070
1116
|
}
|
|
1071
|
-
function describeForm(form) {
|
|
1072
|
-
return typeof form === "string" ? JSON.stringify(form.slice(0, 32)) : `of type ${typeof form}`;
|
|
1073
|
-
}
|
|
1074
1117
|
|
|
1075
1118
|
// src/integrations/mcp/safeScrub.ts
|
|
1076
|
-
var
|
|
1119
|
+
var warned2 = /* @__PURE__ */ new Set();
|
|
1077
1120
|
function scrubOrNull(scrubber, value, field) {
|
|
1078
1121
|
if (value === null) return null;
|
|
1079
1122
|
try {
|
|
1080
1123
|
return scrubber(value);
|
|
1081
1124
|
} catch (err) {
|
|
1082
|
-
if (!
|
|
1083
|
-
|
|
1125
|
+
if (!warned2.has(field)) {
|
|
1126
|
+
warned2.add(field);
|
|
1084
1127
|
process.stderr.write(
|
|
1085
1128
|
`baton: scrubber threw on ${field}; that field is dropped, tool call continues. Further failures on this field will be silent: ${String(err)}
|
|
1086
1129
|
`
|
|
@@ -1253,7 +1296,7 @@ function registerAnnotationTool(server, options) {
|
|
|
1253
1296
|
"_meta"
|
|
1254
1297
|
);
|
|
1255
1298
|
const { sessionId, origin } = await resolveSessionId(options.fallbackSessionId, extra);
|
|
1256
|
-
const
|
|
1299
|
+
const caller = await resolveCaller(
|
|
1257
1300
|
options.resolvePrincipal,
|
|
1258
1301
|
{ extra, toolName: name, arguments: args }
|
|
1259
1302
|
);
|
|
@@ -1266,7 +1309,8 @@ function registerAnnotationTool(server, options) {
|
|
|
1266
1309
|
sequence_number: options.counter.next(sessionId),
|
|
1267
1310
|
captured_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1268
1311
|
consent_token: options.consentToken,
|
|
1269
|
-
principal,
|
|
1312
|
+
principal: caller.principal,
|
|
1313
|
+
organization: caller.organization,
|
|
1270
1314
|
transport_observed: observeTransport(extra),
|
|
1271
1315
|
session_id_origin: origin,
|
|
1272
1316
|
client_observed: observeClient(extra, { server, scrubber: options.scrubber }),
|
|
@@ -1498,11 +1542,14 @@ function sealKey(dsn) {
|
|
|
1498
1542
|
// src/integrations/mcp/errorResult.ts
|
|
1499
1543
|
var TOOL_ERROR_TYPE = "tool_error";
|
|
1500
1544
|
var OUTPUT_SCHEMA_MISMATCH = "output_schema_mismatch";
|
|
1545
|
+
var REFUSED = "refused";
|
|
1501
1546
|
var TASK_MODES = /* @__PURE__ */ new Set(["required", "optional"]);
|
|
1502
|
-
function requestSideFailureKind(entry) {
|
|
1547
|
+
function requestSideFailureKind(entry, validation) {
|
|
1503
1548
|
if (entry == null) return "unknown_tool";
|
|
1504
1549
|
if (entry.enabled === false) return "tool_disabled";
|
|
1505
|
-
|
|
1550
|
+
if (validation === "rejected") return "invalid_argument";
|
|
1551
|
+
if (TASK_MODES.has(entry.execution?.taskSupport)) return void 0;
|
|
1552
|
+
return validation === "unprobed" ? "invalid_argument" : REFUSED;
|
|
1506
1553
|
}
|
|
1507
1554
|
var ERROR_BODY_MAX_CODE_POINTS = 2e3;
|
|
1508
1555
|
function isErrorResult(value) {
|
|
@@ -1553,6 +1600,9 @@ function resultDerivedFields(mode, text, result, errorBody2, scrubber) {
|
|
|
1553
1600
|
function requestSideErrorFields(text, errorBody2) {
|
|
1554
1601
|
return { error_body: errorBody2(text), result: null };
|
|
1555
1602
|
}
|
|
1603
|
+
function requestSideFailureFields(kind, mode, text, result, errorBody2, scrubber) {
|
|
1604
|
+
return kind === REFUSED ? resultDerivedFields(mode, text, result ?? null, errorBody2, scrubber) : requestSideErrorFields(text(), errorBody2);
|
|
1605
|
+
}
|
|
1556
1606
|
function errorTypeOf(err) {
|
|
1557
1607
|
return err instanceof Error ? err.constructor.name : "Error";
|
|
1558
1608
|
}
|
|
@@ -2031,7 +2081,7 @@ async function openCall(ctx, toolName, extra, params, retired, registered = true
|
|
|
2031
2081
|
const [scrubbedExpected = null, scrubbedWorkflow = null] = RETIRED_PARAM_NAMES.map(
|
|
2032
2082
|
(name) => dispositions === void 0 || dispositions[name] === "native" ? null : scrubOrNull(ctx.scrubber, retired[name] ?? popText(params, name), name)
|
|
2033
2083
|
);
|
|
2034
|
-
const
|
|
2084
|
+
const caller = await resolveCaller(
|
|
2035
2085
|
ctx.resolvePrincipal,
|
|
2036
2086
|
{ extra, toolName, arguments: params }
|
|
2037
2087
|
);
|
|
@@ -2044,7 +2094,8 @@ async function openCall(ctx, toolName, extra, params, retired, registered = true
|
|
|
2044
2094
|
// it. `surface_snapshot` is deliberately not among them: it describes the
|
|
2045
2095
|
// SERVER and is captured outside any call, so it has no caller, transport
|
|
2046
2096
|
// or client to name.
|
|
2047
|
-
principal,
|
|
2097
|
+
principal: caller.principal,
|
|
2098
|
+
organization: caller.organization,
|
|
2048
2099
|
transport_observed: observeTransport(extra),
|
|
2049
2100
|
session_id_origin: origin,
|
|
2050
2101
|
client_observed: observeClient(extra, ctx),
|
|
@@ -2427,7 +2478,7 @@ function installLifecycleSeam(lowLevel, ctx, spec) {
|
|
|
2427
2478
|
async function openLifecycleCall(ctx, spec, requestParams, extra) {
|
|
2428
2479
|
try {
|
|
2429
2480
|
const parts = await resolveEnvelopeParts(ctx, extra);
|
|
2430
|
-
const
|
|
2481
|
+
const caller = await resolveCaller(ctx.resolvePrincipal, {
|
|
2431
2482
|
extra,
|
|
2432
2483
|
toolName: null,
|
|
2433
2484
|
arguments: {}
|
|
@@ -2440,7 +2491,8 @@ async function openLifecycleCall(ctx, spec, requestParams, extra) {
|
|
|
2440
2491
|
vendor_id: ctx.vendorId,
|
|
2441
2492
|
session_id: parts.sessionId,
|
|
2442
2493
|
consent_token: ctx.consentToken,
|
|
2443
|
-
principal,
|
|
2494
|
+
principal: caller.principal,
|
|
2495
|
+
organization: caller.organization,
|
|
2444
2496
|
transport_observed: observeTransport(extra),
|
|
2445
2497
|
session_id_origin: parts.origin,
|
|
2446
2498
|
client_observed: observeClient(extra, ctx),
|
|
@@ -2572,7 +2624,8 @@ function installToolsCallSeam(lowLevel, toolEntry, ctx) {
|
|
|
2572
2624
|
const slot = {
|
|
2573
2625
|
innerFired: false,
|
|
2574
2626
|
flushTerminal: null,
|
|
2575
|
-
retired: stripRetiredParams(request?.params, ctx)
|
|
2627
|
+
retired: stripRetiredParams(request?.params, ctx),
|
|
2628
|
+
validation: ctx.validationProbeLive() ? "unseen" : "unprobed"
|
|
2576
2629
|
};
|
|
2577
2630
|
let outcome = CLEAN_OUTCOME;
|
|
2578
2631
|
try {
|
|
@@ -2588,6 +2641,27 @@ function installToolsCallSeam(lowLevel, toolEntry, ctx) {
|
|
|
2588
2641
|
}
|
|
2589
2642
|
);
|
|
2590
2643
|
}
|
|
2644
|
+
var VALIDATION_PROBE = /* @__PURE__ */ Symbol("baton.validationProbe");
|
|
2645
|
+
function installValidationProbe(server) {
|
|
2646
|
+
const target = server;
|
|
2647
|
+
const original = target.validateToolInput;
|
|
2648
|
+
if (typeof original !== "function") return () => false;
|
|
2649
|
+
if (original[VALIDATION_PROBE]) return () => target.validateToolInput === original;
|
|
2650
|
+
const probe = async function(...args) {
|
|
2651
|
+
const slot = callSlots.getStore();
|
|
2652
|
+
try {
|
|
2653
|
+
const parsed = await original.apply(this, args);
|
|
2654
|
+
if (slot) slot.validation = "passed";
|
|
2655
|
+
return parsed;
|
|
2656
|
+
} catch (err) {
|
|
2657
|
+
if (slot) slot.validation = "rejected";
|
|
2658
|
+
throw err;
|
|
2659
|
+
}
|
|
2660
|
+
};
|
|
2661
|
+
Object.assign(probe, { [VALIDATION_PROBE]: true });
|
|
2662
|
+
target.validateToolInput = probe;
|
|
2663
|
+
return () => target.validateToolInput === probe;
|
|
2664
|
+
}
|
|
2591
2665
|
async function settleCall(slot, outcome, args, toolEntry, ctx) {
|
|
2592
2666
|
try {
|
|
2593
2667
|
if (slot.flushTerminal !== null) {
|
|
@@ -2598,13 +2672,13 @@ async function settleCall(slot, outcome, args, toolEntry, ctx) {
|
|
|
2598
2672
|
}
|
|
2599
2673
|
if (slot.innerFired) return;
|
|
2600
2674
|
if (!outcome.failed) return;
|
|
2601
|
-
await emitRequestSideFailure(outcome, args, slot
|
|
2675
|
+
await emitRequestSideFailure(outcome, args, slot, toolEntry, ctx);
|
|
2602
2676
|
} catch (err) {
|
|
2603
2677
|
process.stderr.write(`baton: settling a tool call failed; events dropped: ${String(err)}
|
|
2604
2678
|
`);
|
|
2605
2679
|
}
|
|
2606
2680
|
}
|
|
2607
|
-
async function emitRequestSideFailure(outcome, args,
|
|
2681
|
+
async function emitRequestSideFailure(outcome, args, slot, toolEntry, ctx) {
|
|
2608
2682
|
const request = args[0];
|
|
2609
2683
|
const toolName = request?.params?.name;
|
|
2610
2684
|
if (typeof toolName !== "string") return;
|
|
@@ -2612,8 +2686,16 @@ async function emitRequestSideFailure(outcome, args, retired, toolEntry, ctx) {
|
|
|
2612
2686
|
const entry = toolEntry(toolName);
|
|
2613
2687
|
if (entry != null && dispatchTarget(entry)?.[BATON_WRAPPED] !== true) return;
|
|
2614
2688
|
const params = { ...request?.params?.arguments ?? {} };
|
|
2615
|
-
const { common, sessionId } = await openCall(
|
|
2616
|
-
|
|
2689
|
+
const { common, sessionId } = await openCall(
|
|
2690
|
+
ctx,
|
|
2691
|
+
toolName,
|
|
2692
|
+
args[1],
|
|
2693
|
+
params,
|
|
2694
|
+
slot.retired,
|
|
2695
|
+
entry != null
|
|
2696
|
+
);
|
|
2697
|
+
const failureKind = requestSideFailureKind(entry, slot.validation);
|
|
2698
|
+
const text = () => outcome.raised ? messageOf(outcome.err) : errorText(outcome.result);
|
|
2617
2699
|
await emit(
|
|
2618
2700
|
ctx.sink,
|
|
2619
2701
|
() => ToolCallErrorEventSchema.parse({
|
|
@@ -2634,8 +2716,8 @@ async function emitRequestSideFailure(outcome, args, retired, toolEntry, ctx) {
|
|
|
2634
2716
|
error_type: outcome.raised ? errorTypeOf(outcome.err) : TOOL_ERROR_TYPE,
|
|
2635
2717
|
// ⚠ `null`, not 0. The vendor's handler never ran, so there is no
|
|
2636
2718
|
// handler duration to report; the time this call did spend was spent
|
|
2637
|
-
//
|
|
2638
|
-
//
|
|
2719
|
+
// above the handler, which is not what any other event means by this
|
|
2720
|
+
// member. §11.4 types it nullable for cases like this one.
|
|
2639
2721
|
duration_ms: null,
|
|
2640
2722
|
// ⚠ A CONDITIONAL SPREAD, not `failure_kind: failureKind`. Zod's
|
|
2641
2723
|
// `.optional()` accepts `undefined` and keeps the KEY in its output,
|
|
@@ -2645,11 +2727,13 @@ async function emitRequestSideFailure(outcome, args, retired, toolEntry, ctx) {
|
|
|
2645
2727
|
// determine the kind MUST OMIT the member, and omitting is what this
|
|
2646
2728
|
// spells.
|
|
2647
2729
|
...failureKind === void 0 ? {} : { failure_kind: failureKind },
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2730
|
+
...requestSideFailureFields(
|
|
2731
|
+
failureKind,
|
|
2732
|
+
ctx.resultCaptureMode,
|
|
2733
|
+
text,
|
|
2734
|
+
outcome.raised ? null : outcome.result,
|
|
2735
|
+
(value) => errorBody(ctx, value),
|
|
2736
|
+
ctx.scrubber
|
|
2653
2737
|
)
|
|
2654
2738
|
}
|
|
2655
2739
|
})
|
|
@@ -2752,16 +2836,16 @@ function createBaton(supplied = {}) {
|
|
|
2752
2836
|
tenantId: resolveTenantId(resolved.tenantId, resolved.vendorId)
|
|
2753
2837
|
};
|
|
2754
2838
|
const emittedSurfaceHashes = /* @__PURE__ */ new Set();
|
|
2755
|
-
const
|
|
2839
|
+
const warned3 = /* @__PURE__ */ new Set();
|
|
2756
2840
|
return {
|
|
2757
2841
|
wrap: (server) => {
|
|
2758
|
-
install(server, supplied, config, emittedSurfaceHashes,
|
|
2842
|
+
install(server, supplied, config, emittedSurfaceHashes, warned3);
|
|
2759
2843
|
},
|
|
2760
2844
|
flush: () => sink.flush(),
|
|
2761
2845
|
aclose: () => sink.aclose()
|
|
2762
2846
|
};
|
|
2763
2847
|
}
|
|
2764
|
-
function install(server, supplied, resolved, emittedSurfaceHashes,
|
|
2848
|
+
function install(server, supplied, resolved, emittedSurfaceHashes, warned3) {
|
|
2765
2849
|
const internals = server;
|
|
2766
2850
|
const serverName = usableServerName(() => ({
|
|
2767
2851
|
name: internals.server._serverInfo?.name,
|
|
@@ -2802,9 +2886,9 @@ function install(server, supplied, resolved, emittedSurfaceHashes, warned2) {
|
|
|
2802
2886
|
const memo = internals._toolInputSchemaJson;
|
|
2803
2887
|
if (memo && typeof memo === "object") delete memo[name];
|
|
2804
2888
|
};
|
|
2805
|
-
const
|
|
2806
|
-
if (
|
|
2807
|
-
|
|
2889
|
+
const warnOnce2 = (key, message) => {
|
|
2890
|
+
if (warned3.has(key)) return;
|
|
2891
|
+
warned3.add(key);
|
|
2808
2892
|
process.stderr.write(message);
|
|
2809
2893
|
};
|
|
2810
2894
|
const dropSubagentClause = (name) => {
|
|
@@ -2816,7 +2900,7 @@ function install(server, supplied, resolved, emittedSurfaceHashes, warned2) {
|
|
|
2816
2900
|
} else {
|
|
2817
2901
|
return;
|
|
2818
2902
|
}
|
|
2819
|
-
|
|
2903
|
+
warnOnce2(
|
|
2820
2904
|
"native-user-goal",
|
|
2821
2905
|
`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
|
|
2822
2906
|
`
|
|
@@ -2855,6 +2939,7 @@ function install(server, supplied, resolved, emittedSurfaceHashes, warned2) {
|
|
|
2855
2939
|
annotationToolName,
|
|
2856
2940
|
intentParamMode,
|
|
2857
2941
|
resultCaptureMode: config.resultCaptureMode ?? "full",
|
|
2942
|
+
validationProbeLive: installValidationProbe(server),
|
|
2858
2943
|
paramRegistry: /* @__PURE__ */ new Map(),
|
|
2859
2944
|
resolvePrincipal: config.resolvePrincipal,
|
|
2860
2945
|
vendorToolJsonSchema,
|
|
@@ -2868,7 +2953,7 @@ function install(server, supplied, resolved, emittedSurfaceHashes, warned2) {
|
|
|
2868
2953
|
internals.server._instructions = withVendorInstructions(
|
|
2869
2954
|
internals.server,
|
|
2870
2955
|
ours,
|
|
2871
|
-
(message) =>
|
|
2956
|
+
(message) => warnOnce2("instructions-length", message)
|
|
2872
2957
|
);
|
|
2873
2958
|
installToolsListSeam(internals.server, ctx);
|
|
2874
2959
|
installToolsCallSeam(
|
|
@@ -2975,6 +3060,7 @@ function sessionEnvelope(session) {
|
|
|
2975
3060
|
session_id_origin: session.origin,
|
|
2976
3061
|
transport_observed: TRANSPORT_LIBRARY,
|
|
2977
3062
|
principal: session.principal,
|
|
3063
|
+
organization: session.organization,
|
|
2978
3064
|
client_observed: session.clientObserved,
|
|
2979
3065
|
runtime_meta: session.turnId !== null ? { [TURN_ID_META_KEY]: session.turnId } : null
|
|
2980
3066
|
};
|
|
@@ -2991,28 +3077,16 @@ function vendorId(name, value) {
|
|
|
2991
3077
|
}
|
|
2992
3078
|
return null;
|
|
2993
3079
|
}
|
|
2994
|
-
function
|
|
2995
|
-
return { sessionId
|
|
2996
|
-
}
|
|
2997
|
-
function wirePrincipal(value) {
|
|
2998
|
-
if (value === void 0 || value === null) return null;
|
|
2999
|
-
const principal = normalizePrincipal(value);
|
|
3000
|
-
if (principal === null) {
|
|
3001
|
-
warn3("principal was given but has no usable principalId \u2014 sending none.");
|
|
3002
|
-
return null;
|
|
3003
|
-
}
|
|
3004
|
-
return principalFor(
|
|
3005
|
-
principal,
|
|
3006
|
-
(form) => warn3(`principal form ${JSON.stringify(form)} is not registered \u2014 sending "raw".`)
|
|
3007
|
-
);
|
|
3080
|
+
function blank(sessionId, origin) {
|
|
3081
|
+
return { sessionId, origin, ...NO_CALLER, clientObserved: null, turnId: null };
|
|
3008
3082
|
}
|
|
3009
3083
|
function newSession(values, scrubber, disabled) {
|
|
3010
3084
|
const id = vendorId("sessionId", values.sessionId);
|
|
3011
|
-
const base = id !== null ?
|
|
3085
|
+
const base = id !== null ? blank(id, "observed") : blank(uuid7(), "minted");
|
|
3012
3086
|
if (disabled) return base;
|
|
3013
3087
|
return {
|
|
3014
3088
|
...base,
|
|
3015
|
-
|
|
3089
|
+
...callerFor(values.principal, (_key, message) => warn3(`principal ${message}`)),
|
|
3016
3090
|
clientObserved: clientObservedFrom(values.clientInfo, values.headers, scrubber),
|
|
3017
3091
|
turnId: vendorId("turnId", values.turnId)
|
|
3018
3092
|
};
|
|
@@ -3023,7 +3097,7 @@ function runInSession(owner, session, fn) {
|
|
|
3023
3097
|
}
|
|
3024
3098
|
function sessionForCall(owner) {
|
|
3025
3099
|
const entry = current.getStore();
|
|
3026
|
-
return entry !== void 0 && entry.owner === owner ? entry.session :
|
|
3100
|
+
return entry !== void 0 && entry.owner === owner ? entry.session : blank(uuid7(), "minted");
|
|
3027
3101
|
}
|
|
3028
3102
|
var lastSequence = 0;
|
|
3029
3103
|
function nextSequence() {
|