@goodtiming/baton-sdk 0.6.2 → 0.6.3
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 +111 -69
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -3
- package/dist/index.d.ts +8 -3
- package/dist/index.js +110 -69
- 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.6.
|
|
3
|
+
declare const SDK_VERSION = "ts-0.6.3";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Zod schemas + TS types for the Baton event stream per SPEC §11.4.
|
|
@@ -2246,9 +2246,14 @@ interface Sink {
|
|
|
2246
2246
|
/** Wait for any buffered events to reach their destination (or be
|
|
2247
2247
|
* dropped per the sink's policy). No-op for synchronous sinks. */
|
|
2248
2248
|
flush(): Promise<void>;
|
|
2249
|
-
/** Flush + release resources. After `aclose`, `write` rejects
|
|
2249
|
+
/** Flush + release resources. After `aclose`, `write` rejects with
|
|
2250
|
+
* `SinkClosedError`. */
|
|
2250
2251
|
aclose(): Promise<void>;
|
|
2251
2252
|
}
|
|
2253
|
+
/** `write` was called after `aclose`. */
|
|
2254
|
+
declare class SinkClosedError extends Error {
|
|
2255
|
+
name: string;
|
|
2256
|
+
}
|
|
2252
2257
|
/** Fail-open wrapper around `sink.write`.
|
|
2253
2258
|
*
|
|
2254
2259
|
* The MCP tool wrapper sits BEFORE the vendor's tool handler runs. A reject
|
|
@@ -3083,4 +3088,4 @@ interface IntentParam {
|
|
|
3083
3088
|
}
|
|
3084
3089
|
declare const INTENT_PARAMS: readonly IntentParam[];
|
|
3085
3090
|
|
|
3086
|
-
export { type AnnotateOptions, type AnnotationEvent, AnnotationEventSchema, type AnnotationPayload, AnnotationPayloadSchema, type AuthInfo, type Baton, type BatonConfig, BatonHandle, Client, type ClientOptions, type ClientReportEvent, ClientReportEventSchema, type ClientReportPayload, ClientReportPayloadSchema, DEFAULT_CONSENT_TOKEN, DEPTH_LIMIT, DEPTH_MARKER, type Event, EventSchema, type EventType, EventTypeSchema, FileSink, type HeaderInput, HttpSink, type HttpSinkOptions, INTENT_INSTRUCTIONS, INTENT_PARAMS, type IntentParam, type ListToolsOptions, MultiSink, type ObservedError, type Organization, PRINCIPAL_FORM_HASHED, PRINCIPAL_FORM_RAW, PRINCIPAL_SOURCE_ASSERTED, type Principal, type PrincipalForm, type PrincipalResolutionContext, PrincipalWireSchema, type PromptGetEndEvent, PromptGetEndEventSchema, type PromptGetEndPayload, PromptGetEndPayloadSchema, type PromptGetErrorEvent, PromptGetErrorEventSchema, type PromptGetErrorPayload, PromptGetErrorPayloadSchema, type PromptGetStartEvent, PromptGetStartEventSchema, type PromptGetStartPayload, PromptGetStartPayloadSchema, type PromptListEndEvent, PromptListEndEventSchema, type PromptListEndPayload, PromptListEndPayloadSchema, type PromptListErrorEvent, PromptListErrorEventSchema, type PromptListErrorPayload, PromptListErrorPayloadSchema, type PromptListStartEvent, PromptListStartEventSchema, type PromptListStartPayload, PromptListStartPayloadSchema, type ResolvePrincipalHook, type ResourceListEndEvent, ResourceListEndEventSchema, type ResourceListEndPayload, ResourceListEndPayloadSchema, type ResourceListErrorEvent, ResourceListErrorEventSchema, type ResourceListErrorPayload, ResourceListErrorPayloadSchema, type ResourceListStartEvent, ResourceListStartEventSchema, type ResourceListStartPayload, ResourceListStartPayloadSchema, type ResourceReadEndEvent, ResourceReadEndEventSchema, type ResourceReadEndPayload, ResourceReadEndPayloadSchema, type ResourceReadErrorEvent, ResourceReadErrorEventSchema, type ResourceReadErrorPayload, ResourceReadErrorPayloadSchema, type ResourceReadStartEvent, ResourceReadStartEventSchema, type ResourceReadStartPayload, ResourceReadStartPayloadSchema, type ResultCaptureMode, SDK_VERSION, Scrubber, type SessionOptions, type Sink, StdoutSink, type StdoutSinkOptions, type SupportedMcpServer, type SurfaceSnapshotEvent, SurfaceSnapshotEventSchema, type SurfaceSnapshotPayload, SurfaceSnapshotPayloadSchema, type ToolCallEndEvent, ToolCallEndEventSchema, type ToolCallEndPayload, ToolCallEndPayloadSchema, type ToolCallErrorEvent, ToolCallErrorEventSchema, type ToolCallErrorPayload, ToolCallErrorPayloadSchema, type ToolCallStartEvent, ToolCallStartEventSchema, type ToolCallStartPayload, ToolCallStartPayloadSchema, type ToolListEndEvent, ToolListEndEventSchema, type ToolListEndPayload, ToolListEndPayloadSchema, type ToolListErrorEvent, ToolListErrorEventSchema, type ToolListErrorPayload, ToolListErrorPayloadSchema, type ToolListStartEvent, ToolListStartEventSchema, type ToolListStartPayload, ToolListStartPayloadSchema, Trace, type TraceOptions, createBaton, identityScrub, principalFromOAuthEmail, principalFromOAuthSub, safeWrite, withBaton };
|
|
3091
|
+
export { type AnnotateOptions, type AnnotationEvent, AnnotationEventSchema, type AnnotationPayload, AnnotationPayloadSchema, type AuthInfo, type Baton, type BatonConfig, BatonHandle, Client, type ClientOptions, type ClientReportEvent, ClientReportEventSchema, type ClientReportPayload, ClientReportPayloadSchema, DEFAULT_CONSENT_TOKEN, DEPTH_LIMIT, DEPTH_MARKER, type Event, EventSchema, type EventType, EventTypeSchema, FileSink, type HeaderInput, HttpSink, type HttpSinkOptions, INTENT_INSTRUCTIONS, INTENT_PARAMS, type IntentParam, type ListToolsOptions, MultiSink, type ObservedError, type Organization, PRINCIPAL_FORM_HASHED, PRINCIPAL_FORM_RAW, PRINCIPAL_SOURCE_ASSERTED, type Principal, type PrincipalForm, type PrincipalResolutionContext, PrincipalWireSchema, type PromptGetEndEvent, PromptGetEndEventSchema, type PromptGetEndPayload, PromptGetEndPayloadSchema, type PromptGetErrorEvent, PromptGetErrorEventSchema, type PromptGetErrorPayload, PromptGetErrorPayloadSchema, type PromptGetStartEvent, PromptGetStartEventSchema, type PromptGetStartPayload, PromptGetStartPayloadSchema, type PromptListEndEvent, PromptListEndEventSchema, type PromptListEndPayload, PromptListEndPayloadSchema, type PromptListErrorEvent, PromptListErrorEventSchema, type PromptListErrorPayload, PromptListErrorPayloadSchema, type PromptListStartEvent, PromptListStartEventSchema, type PromptListStartPayload, PromptListStartPayloadSchema, type ResolvePrincipalHook, type ResourceListEndEvent, ResourceListEndEventSchema, type ResourceListEndPayload, ResourceListEndPayloadSchema, type ResourceListErrorEvent, ResourceListErrorEventSchema, type ResourceListErrorPayload, ResourceListErrorPayloadSchema, type ResourceListStartEvent, ResourceListStartEventSchema, type ResourceListStartPayload, ResourceListStartPayloadSchema, type ResourceReadEndEvent, ResourceReadEndEventSchema, type ResourceReadEndPayload, ResourceReadEndPayloadSchema, type ResourceReadErrorEvent, ResourceReadErrorEventSchema, type ResourceReadErrorPayload, ResourceReadErrorPayloadSchema, type ResourceReadStartEvent, ResourceReadStartEventSchema, type ResourceReadStartPayload, ResourceReadStartPayloadSchema, type ResultCaptureMode, SDK_VERSION, Scrubber, type SessionOptions, type Sink, SinkClosedError, StdoutSink, type StdoutSinkOptions, type SupportedMcpServer, type SurfaceSnapshotEvent, SurfaceSnapshotEventSchema, type SurfaceSnapshotPayload, SurfaceSnapshotPayloadSchema, type ToolCallEndEvent, ToolCallEndEventSchema, type ToolCallEndPayload, ToolCallEndPayloadSchema, type ToolCallErrorEvent, ToolCallErrorEventSchema, type ToolCallErrorPayload, ToolCallErrorPayloadSchema, type ToolCallStartEvent, ToolCallStartEventSchema, type ToolCallStartPayload, ToolCallStartPayloadSchema, type ToolListEndEvent, ToolListEndEventSchema, type ToolListEndPayload, ToolListEndPayloadSchema, type ToolListErrorEvent, ToolListErrorEventSchema, type ToolListErrorPayload, ToolListErrorPayloadSchema, type ToolListStartEvent, ToolListStartEventSchema, type ToolListStartPayload, ToolListStartPayloadSchema, Trace, type TraceOptions, createBaton, identityScrub, principalFromOAuthEmail, principalFromOAuthSub, safeWrite, withBaton };
|
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.6.
|
|
3
|
+
declare const SDK_VERSION = "ts-0.6.3";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Zod schemas + TS types for the Baton event stream per SPEC §11.4.
|
|
@@ -2246,9 +2246,14 @@ interface Sink {
|
|
|
2246
2246
|
/** Wait for any buffered events to reach their destination (or be
|
|
2247
2247
|
* dropped per the sink's policy). No-op for synchronous sinks. */
|
|
2248
2248
|
flush(): Promise<void>;
|
|
2249
|
-
/** Flush + release resources. After `aclose`, `write` rejects
|
|
2249
|
+
/** Flush + release resources. After `aclose`, `write` rejects with
|
|
2250
|
+
* `SinkClosedError`. */
|
|
2250
2251
|
aclose(): Promise<void>;
|
|
2251
2252
|
}
|
|
2253
|
+
/** `write` was called after `aclose`. */
|
|
2254
|
+
declare class SinkClosedError extends Error {
|
|
2255
|
+
name: string;
|
|
2256
|
+
}
|
|
2252
2257
|
/** Fail-open wrapper around `sink.write`.
|
|
2253
2258
|
*
|
|
2254
2259
|
* The MCP tool wrapper sits BEFORE the vendor's tool handler runs. A reject
|
|
@@ -3083,4 +3088,4 @@ interface IntentParam {
|
|
|
3083
3088
|
}
|
|
3084
3089
|
declare const INTENT_PARAMS: readonly IntentParam[];
|
|
3085
3090
|
|
|
3086
|
-
export { type AnnotateOptions, type AnnotationEvent, AnnotationEventSchema, type AnnotationPayload, AnnotationPayloadSchema, type AuthInfo, type Baton, type BatonConfig, BatonHandle, Client, type ClientOptions, type ClientReportEvent, ClientReportEventSchema, type ClientReportPayload, ClientReportPayloadSchema, DEFAULT_CONSENT_TOKEN, DEPTH_LIMIT, DEPTH_MARKER, type Event, EventSchema, type EventType, EventTypeSchema, FileSink, type HeaderInput, HttpSink, type HttpSinkOptions, INTENT_INSTRUCTIONS, INTENT_PARAMS, type IntentParam, type ListToolsOptions, MultiSink, type ObservedError, type Organization, PRINCIPAL_FORM_HASHED, PRINCIPAL_FORM_RAW, PRINCIPAL_SOURCE_ASSERTED, type Principal, type PrincipalForm, type PrincipalResolutionContext, PrincipalWireSchema, type PromptGetEndEvent, PromptGetEndEventSchema, type PromptGetEndPayload, PromptGetEndPayloadSchema, type PromptGetErrorEvent, PromptGetErrorEventSchema, type PromptGetErrorPayload, PromptGetErrorPayloadSchema, type PromptGetStartEvent, PromptGetStartEventSchema, type PromptGetStartPayload, PromptGetStartPayloadSchema, type PromptListEndEvent, PromptListEndEventSchema, type PromptListEndPayload, PromptListEndPayloadSchema, type PromptListErrorEvent, PromptListErrorEventSchema, type PromptListErrorPayload, PromptListErrorPayloadSchema, type PromptListStartEvent, PromptListStartEventSchema, type PromptListStartPayload, PromptListStartPayloadSchema, type ResolvePrincipalHook, type ResourceListEndEvent, ResourceListEndEventSchema, type ResourceListEndPayload, ResourceListEndPayloadSchema, type ResourceListErrorEvent, ResourceListErrorEventSchema, type ResourceListErrorPayload, ResourceListErrorPayloadSchema, type ResourceListStartEvent, ResourceListStartEventSchema, type ResourceListStartPayload, ResourceListStartPayloadSchema, type ResourceReadEndEvent, ResourceReadEndEventSchema, type ResourceReadEndPayload, ResourceReadEndPayloadSchema, type ResourceReadErrorEvent, ResourceReadErrorEventSchema, type ResourceReadErrorPayload, ResourceReadErrorPayloadSchema, type ResourceReadStartEvent, ResourceReadStartEventSchema, type ResourceReadStartPayload, ResourceReadStartPayloadSchema, type ResultCaptureMode, SDK_VERSION, Scrubber, type SessionOptions, type Sink, StdoutSink, type StdoutSinkOptions, type SupportedMcpServer, type SurfaceSnapshotEvent, SurfaceSnapshotEventSchema, type SurfaceSnapshotPayload, SurfaceSnapshotPayloadSchema, type ToolCallEndEvent, ToolCallEndEventSchema, type ToolCallEndPayload, ToolCallEndPayloadSchema, type ToolCallErrorEvent, ToolCallErrorEventSchema, type ToolCallErrorPayload, ToolCallErrorPayloadSchema, type ToolCallStartEvent, ToolCallStartEventSchema, type ToolCallStartPayload, ToolCallStartPayloadSchema, type ToolListEndEvent, ToolListEndEventSchema, type ToolListEndPayload, ToolListEndPayloadSchema, type ToolListErrorEvent, ToolListErrorEventSchema, type ToolListErrorPayload, ToolListErrorPayloadSchema, type ToolListStartEvent, ToolListStartEventSchema, type ToolListStartPayload, ToolListStartPayloadSchema, Trace, type TraceOptions, createBaton, identityScrub, principalFromOAuthEmail, principalFromOAuthSub, safeWrite, withBaton };
|
|
3091
|
+
export { type AnnotateOptions, type AnnotationEvent, AnnotationEventSchema, type AnnotationPayload, AnnotationPayloadSchema, type AuthInfo, type Baton, type BatonConfig, BatonHandle, Client, type ClientOptions, type ClientReportEvent, ClientReportEventSchema, type ClientReportPayload, ClientReportPayloadSchema, DEFAULT_CONSENT_TOKEN, DEPTH_LIMIT, DEPTH_MARKER, type Event, EventSchema, type EventType, EventTypeSchema, FileSink, type HeaderInput, HttpSink, type HttpSinkOptions, INTENT_INSTRUCTIONS, INTENT_PARAMS, type IntentParam, type ListToolsOptions, MultiSink, type ObservedError, type Organization, PRINCIPAL_FORM_HASHED, PRINCIPAL_FORM_RAW, PRINCIPAL_SOURCE_ASSERTED, type Principal, type PrincipalForm, type PrincipalResolutionContext, PrincipalWireSchema, type PromptGetEndEvent, PromptGetEndEventSchema, type PromptGetEndPayload, PromptGetEndPayloadSchema, type PromptGetErrorEvent, PromptGetErrorEventSchema, type PromptGetErrorPayload, PromptGetErrorPayloadSchema, type PromptGetStartEvent, PromptGetStartEventSchema, type PromptGetStartPayload, PromptGetStartPayloadSchema, type PromptListEndEvent, PromptListEndEventSchema, type PromptListEndPayload, PromptListEndPayloadSchema, type PromptListErrorEvent, PromptListErrorEventSchema, type PromptListErrorPayload, PromptListErrorPayloadSchema, type PromptListStartEvent, PromptListStartEventSchema, type PromptListStartPayload, PromptListStartPayloadSchema, type ResolvePrincipalHook, type ResourceListEndEvent, ResourceListEndEventSchema, type ResourceListEndPayload, ResourceListEndPayloadSchema, type ResourceListErrorEvent, ResourceListErrorEventSchema, type ResourceListErrorPayload, ResourceListErrorPayloadSchema, type ResourceListStartEvent, ResourceListStartEventSchema, type ResourceListStartPayload, ResourceListStartPayloadSchema, type ResourceReadEndEvent, ResourceReadEndEventSchema, type ResourceReadEndPayload, ResourceReadEndPayloadSchema, type ResourceReadErrorEvent, ResourceReadErrorEventSchema, type ResourceReadErrorPayload, ResourceReadErrorPayloadSchema, type ResourceReadStartEvent, ResourceReadStartEventSchema, type ResourceReadStartPayload, ResourceReadStartPayloadSchema, type ResultCaptureMode, SDK_VERSION, Scrubber, type SessionOptions, type Sink, SinkClosedError, StdoutSink, type StdoutSinkOptions, type SupportedMcpServer, type SurfaceSnapshotEvent, SurfaceSnapshotEventSchema, type SurfaceSnapshotPayload, SurfaceSnapshotPayloadSchema, type ToolCallEndEvent, ToolCallEndEventSchema, type ToolCallEndPayload, ToolCallEndPayloadSchema, type ToolCallErrorEvent, ToolCallErrorEventSchema, type ToolCallErrorPayload, ToolCallErrorPayloadSchema, type ToolCallStartEvent, ToolCallStartEventSchema, type ToolCallStartPayload, ToolCallStartPayloadSchema, type ToolListEndEvent, ToolListEndEventSchema, type ToolListEndPayload, ToolListEndPayloadSchema, type ToolListErrorEvent, ToolListErrorEventSchema, type ToolListErrorPayload, ToolListErrorPayloadSchema, type ToolListStartEvent, ToolListStartEventSchema, type ToolListStartPayload, ToolListStartPayloadSchema, Trace, type TraceOptions, createBaton, identityScrub, principalFromOAuthEmail, principalFromOAuthSub, safeWrite, withBaton };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/version.ts
|
|
2
|
-
var SDK_VERSION = "ts-0.6.
|
|
2
|
+
var SDK_VERSION = "ts-0.6.3";
|
|
3
3
|
|
|
4
4
|
// src/events.ts
|
|
5
5
|
import { z } from "zod";
|
|
@@ -608,10 +608,24 @@ function nextClockSequence() {
|
|
|
608
608
|
// src/sinks.ts
|
|
609
609
|
var REFUSAL_BODY_MAX_LEN = 500;
|
|
610
610
|
var REFUSAL_LOG_MS = 6e4;
|
|
611
|
+
var SinkClosedError = class extends Error {
|
|
612
|
+
name = "SinkClosedError";
|
|
613
|
+
};
|
|
614
|
+
function isSinkClosed(err) {
|
|
615
|
+
return err instanceof Error && err.name === "SinkClosedError";
|
|
616
|
+
}
|
|
617
|
+
var warnedClosed = /* @__PURE__ */ new WeakSet();
|
|
618
|
+
function droppedAfterClose(sink) {
|
|
619
|
+
PROCESS_DROPS.add("after_close");
|
|
620
|
+
if (warnedClosed.has(sink)) return;
|
|
621
|
+
warnedClosed.add(sink);
|
|
622
|
+
warn("baton: the sink is closed; further events are dropped.");
|
|
623
|
+
}
|
|
611
624
|
async function safeWrite(sink, event) {
|
|
612
625
|
try {
|
|
613
626
|
await sink.write(event);
|
|
614
627
|
} catch (err) {
|
|
628
|
+
if (isSinkClosed(err)) return droppedAfterClose(sink);
|
|
615
629
|
PROCESS_DROPS.add("write_failed");
|
|
616
630
|
process.stderr.write(`baton: sink.write failed; event dropped, tool call continues: ${printable(err)}
|
|
617
631
|
`);
|
|
@@ -664,7 +678,7 @@ var StdoutSink = class {
|
|
|
664
678
|
this.stream = options.stream ?? process.stderr;
|
|
665
679
|
}
|
|
666
680
|
async write(event) {
|
|
667
|
-
if (this.closed) throw new
|
|
681
|
+
if (this.closed) throw new SinkClosedError("StdoutSink is closed");
|
|
668
682
|
this.stream.write(JSON.stringify(event) + "\n");
|
|
669
683
|
}
|
|
670
684
|
async flush() {
|
|
@@ -681,7 +695,7 @@ var FileSink = class {
|
|
|
681
695
|
fd = null;
|
|
682
696
|
closed = false;
|
|
683
697
|
async write(event) {
|
|
684
|
-
if (this.closed) throw new
|
|
698
|
+
if (this.closed) throw new SinkClosedError("FileSink is closed");
|
|
685
699
|
this.fd ??= openSync(this.path, "a");
|
|
686
700
|
writeSync(this.fd, JSON.stringify(event) + "\n");
|
|
687
701
|
}
|
|
@@ -719,9 +733,11 @@ var MultiSink = class {
|
|
|
719
733
|
}
|
|
720
734
|
async fanOut(op) {
|
|
721
735
|
const results = await Promise.allSettled(this.sinks.map(async (sink) => op(sink)));
|
|
722
|
-
|
|
723
|
-
if (errors.length
|
|
724
|
-
if (errors.length
|
|
736
|
+
let errors = results.flatMap((r) => r.status === "rejected" ? [r.reason] : []);
|
|
737
|
+
if (errors.length < results.length) errors = errors.filter((e) => !isSinkClosed(e));
|
|
738
|
+
if (errors.length === 0) return;
|
|
739
|
+
if (errors.length === 1 || errors.every(isSinkClosed)) throw errors[0];
|
|
740
|
+
throw new AggregateError(errors, "MultiSink fan-out failures");
|
|
725
741
|
}
|
|
726
742
|
};
|
|
727
743
|
var CircuitBreaker = class {
|
|
@@ -820,7 +836,7 @@ var HttpSink = class _HttpSink {
|
|
|
820
836
|
return this.closing.signal.aborted;
|
|
821
837
|
}
|
|
822
838
|
async write(event) {
|
|
823
|
-
if (this.closed) throw new
|
|
839
|
+
if (this.closed) throw new SinkClosedError("HttpSink is closed");
|
|
824
840
|
this.enqueue(event);
|
|
825
841
|
this.unsentWarned = false;
|
|
826
842
|
void this.scheduleDrain();
|
|
@@ -2257,6 +2273,24 @@ var DisabledSink = class {
|
|
|
2257
2273
|
}
|
|
2258
2274
|
};
|
|
2259
2275
|
|
|
2276
|
+
// src/integrations/mcp/inputRequired.ts
|
|
2277
|
+
function isInputRequired(result) {
|
|
2278
|
+
try {
|
|
2279
|
+
return isRecord(result) && result.resultType === "input_required";
|
|
2280
|
+
} catch {
|
|
2281
|
+
return false;
|
|
2282
|
+
}
|
|
2283
|
+
}
|
|
2284
|
+
function resumesPausedCall(extra) {
|
|
2285
|
+
try {
|
|
2286
|
+
const req = extra?.mcpReq;
|
|
2287
|
+
if (req === void 0) return false;
|
|
2288
|
+
return req.inputResponses !== void 0 || req.requestState?.() !== void 0;
|
|
2289
|
+
} catch {
|
|
2290
|
+
return false;
|
|
2291
|
+
}
|
|
2292
|
+
}
|
|
2293
|
+
|
|
2260
2294
|
// src/integrations/mcp/handle.ts
|
|
2261
2295
|
var BatonHandle = class {
|
|
2262
2296
|
sink;
|
|
@@ -2610,6 +2644,7 @@ async function openCall(ctx, toolName, extra, params, retired, registered = true
|
|
|
2610
2644
|
runtime_meta: scrubbedMeta,
|
|
2611
2645
|
call_id: uuid7()
|
|
2612
2646
|
};
|
|
2647
|
+
if (resumesPausedCall(extra)) return { common, session };
|
|
2613
2648
|
await emit(
|
|
2614
2649
|
ctx.sink,
|
|
2615
2650
|
() => ToolCallStartEventSchema.parse({
|
|
@@ -2641,20 +2676,19 @@ function batonWrap(nameRef, original, ctx) {
|
|
|
2641
2676
|
const { common, session } = await openCall(ctx, toolName, extra, params, retired);
|
|
2642
2677
|
const terminate = async (build, replacement) => {
|
|
2643
2678
|
if (!slot) {
|
|
2644
|
-
await emit(ctx.sink, build);
|
|
2679
|
+
if (build !== null) await emit(ctx.sink, build);
|
|
2645
2680
|
return;
|
|
2646
2681
|
}
|
|
2647
2682
|
const earlier = slot.flushTerminal;
|
|
2648
2683
|
if (earlier !== null) await earlier(CLEAN_OUTCOME);
|
|
2649
2684
|
slot.flushTerminal = async (outcome) => {
|
|
2650
|
-
await emit(
|
|
2651
|
-
|
|
2652
|
-
() => replacement !== null && outcome.failed ? replacement(outcome) : build()
|
|
2653
|
-
);
|
|
2685
|
+
if (replacement !== null && outcome.failed) await emit(ctx.sink, () => replacement(outcome));
|
|
2686
|
+
else if (build !== null) await emit(ctx.sink, build);
|
|
2654
2687
|
};
|
|
2655
2688
|
};
|
|
2656
2689
|
const parkFailure = (build) => terminate(build, null);
|
|
2657
2690
|
const parkSuccess = (build, replacement) => terminate(build, replacement);
|
|
2691
|
+
const parkPause = (replacement) => terminate(null, replacement);
|
|
2658
2692
|
const startedAt = performance.now();
|
|
2659
2693
|
let result;
|
|
2660
2694
|
try {
|
|
@@ -2697,6 +2731,59 @@ function batonWrap(nameRef, original, ctx) {
|
|
|
2697
2731
|
throw err;
|
|
2698
2732
|
}
|
|
2699
2733
|
const durationMs = Math.round(performance.now() - startedAt);
|
|
2734
|
+
const failedAbove = (outcome, failureKind) => ToolCallErrorEventSchema.parse({
|
|
2735
|
+
...common,
|
|
2736
|
+
sequence_number: ctx.counter.nextFor(session),
|
|
2737
|
+
captured_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2738
|
+
payload: {
|
|
2739
|
+
tool_name: toolName,
|
|
2740
|
+
// The lane the OUTER came back on, not this one's: on 2.x the
|
|
2741
|
+
// conversion failure is converted to a returned `isError` inside
|
|
2742
|
+
// `tools/call` (`mcp-DXXb3Vv3.mjs:1402`), so `"tool_error"` is
|
|
2743
|
+
// right there. A pause the SDK rejects on 2026-07-28 raises, so
|
|
2744
|
+
// both lanes are reachable.
|
|
2745
|
+
error_type: outcome.raised ? errorTypeOf(outcome.err) : TOOL_ERROR_TYPE,
|
|
2746
|
+
// ⚠ The INNER's measurement — the vendor's handler duration —
|
|
2747
|
+
// not the outer's. Every other leg means the same thing by this
|
|
2748
|
+
// member, and widening it here for one failure kind would make
|
|
2749
|
+
// `duration_ms` mean two things in one column.
|
|
2750
|
+
duration_ms: durationMs,
|
|
2751
|
+
// Omitted, not null, when undetermined: SPEC §11.4.3 says MUST OMIT.
|
|
2752
|
+
...failureKind === void 0 ? {} : { failure_kind: failureKind },
|
|
2753
|
+
// ⚠ **WITHHELD under `"off"`, unlike the three request-side
|
|
2754
|
+
// kinds.** The message quotes the value the tool returned
|
|
2755
|
+
// ("`'not-an-int'` is not of type `integer`"), so it is
|
|
2756
|
+
// result-derived by provenance and goes — which leaves
|
|
2757
|
+
// `failure_kind` as the ONLY surviving signal for an
|
|
2758
|
+
// `output_schema_mismatch` under `"off"`, and is the measurement
|
|
2759
|
+
// that justified putting the member on the wire at all.
|
|
2760
|
+
//
|
|
2761
|
+
// ⚠ `result` is what the CLIENT received — the SDK's own error
|
|
2762
|
+
// envelope — not the vendor's rejected return value. §11.4.3
|
|
2763
|
+
// asks for the envelope that holds the flag and the reason, and
|
|
2764
|
+
// this package's own invariant is that it agrees with the
|
|
2765
|
+
// caller. Recording the rejected output TOO would need a member
|
|
2766
|
+
// nothing on the wire has; the loss is deliberate and worth
|
|
2767
|
+
// knowing when debugging one of these.
|
|
2768
|
+
...resultDerivedFields(
|
|
2769
|
+
ctx.resultCaptureMode,
|
|
2770
|
+
() => outcome.raised ? messageOf(outcome.err) : errorText(outcome.result),
|
|
2771
|
+
// ⚠ `null` on the `raised` lane, never `undefined`, and the
|
|
2772
|
+
// union is what forces the branch rather than a comment: the
|
|
2773
|
+
// scrubber would answer `undefined` and DROP the key, where the
|
|
2774
|
+
// sibling raise lane a few lines up declares `result: null`
|
|
2775
|
+
// explicitly, for the reason `ToolCallErrorPayloadSchema`
|
|
2776
|
+
// records. One shape for "no result object existed", not two.
|
|
2777
|
+
outcome.raised ? null : outcome.result ?? null,
|
|
2778
|
+
(text) => errorBody(ctx, text),
|
|
2779
|
+
ctx.scrubber
|
|
2780
|
+
)
|
|
2781
|
+
}
|
|
2782
|
+
});
|
|
2783
|
+
if (isInputRequired(result)) {
|
|
2784
|
+
await parkPause(failedAbove);
|
|
2785
|
+
return result;
|
|
2786
|
+
}
|
|
2700
2787
|
if (isErrorResult(result)) {
|
|
2701
2788
|
await parkFailure(
|
|
2702
2789
|
() => ToolCallErrorEventSchema.parse({
|
|
@@ -2739,61 +2826,7 @@ function batonWrap(nameRef, original, ctx) {
|
|
|
2739
2826
|
...endResultFields(ctx.resultCaptureMode, result, ctx.scrubber)
|
|
2740
2827
|
}
|
|
2741
2828
|
}),
|
|
2742
|
-
|
|
2743
|
-
// then the outer seam saw the call fail anyway — so what failed is the
|
|
2744
|
-
// producer's own conversion of the output (SPEC §11.4.3's
|
|
2745
|
-
// `output_schema_mismatch`). Correcting this is the whole point of the
|
|
2746
|
-
// second seam: without it this is a `tool_call_end` for a call the
|
|
2747
|
-
// CALLER saw fail, which is a success the product invented.
|
|
2748
|
-
(outcome) => ToolCallErrorEventSchema.parse({
|
|
2749
|
-
...common,
|
|
2750
|
-
sequence_number: ctx.counter.nextFor(session),
|
|
2751
|
-
captured_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2752
|
-
payload: {
|
|
2753
|
-
tool_name: toolName,
|
|
2754
|
-
// The lane the OUTER came back on, not this one's: on 2.x the
|
|
2755
|
-
// conversion failure is converted to a returned `isError` inside
|
|
2756
|
-
// `tools/call` (`mcp-DXXb3Vv3.mjs:1402`), so `"tool_error"` is
|
|
2757
|
-
// right there. A throw out of the handler is unreachable on
|
|
2758
|
-
// either major today for this lane; spelled anyway, because the
|
|
2759
|
-
// alternative is a crash on the day it stops being.
|
|
2760
|
-
error_type: outcome.raised ? errorTypeOf(outcome.err) : TOOL_ERROR_TYPE,
|
|
2761
|
-
// ⚠ The INNER's measurement — the vendor's handler duration —
|
|
2762
|
-
// not the outer's. Every other leg means the same thing by this
|
|
2763
|
-
// member, and widening it here for one failure kind would make
|
|
2764
|
-
// `duration_ms` mean two things in one column.
|
|
2765
|
-
duration_ms: durationMs,
|
|
2766
|
-
failure_kind: OUTPUT_SCHEMA_MISMATCH,
|
|
2767
|
-
// ⚠ **WITHHELD under `"off"`, unlike the three request-side
|
|
2768
|
-
// kinds.** The message quotes the value the tool returned
|
|
2769
|
-
// ("`'not-an-int'` is not of type `integer`"), so it is
|
|
2770
|
-
// result-derived by provenance and goes — which leaves
|
|
2771
|
-
// `failure_kind` as the ONLY surviving signal for this failure
|
|
2772
|
-
// under `"off"`, and is the measurement that justified putting
|
|
2773
|
-
// the member on the wire at all.
|
|
2774
|
-
//
|
|
2775
|
-
// ⚠ `result` is what the CLIENT received — the SDK's own error
|
|
2776
|
-
// envelope — not the vendor's rejected return value. §11.4.3
|
|
2777
|
-
// asks for the envelope that holds the flag and the reason, and
|
|
2778
|
-
// this package's own invariant is that it agrees with the
|
|
2779
|
-
// caller. Recording the rejected output TOO would need a member
|
|
2780
|
-
// nothing on the wire has; the loss is deliberate and worth
|
|
2781
|
-
// knowing when debugging one of these.
|
|
2782
|
-
...resultDerivedFields(
|
|
2783
|
-
ctx.resultCaptureMode,
|
|
2784
|
-
() => outcome.raised ? messageOf(outcome.err) : errorText(outcome.result),
|
|
2785
|
-
// ⚠ `null` on the `raised` lane, never `undefined`, and the
|
|
2786
|
-
// union is what forces the branch rather than a comment: the
|
|
2787
|
-
// scrubber would answer `undefined` and DROP the key, where the
|
|
2788
|
-
// sibling raise lane a few lines up declares `result: null`
|
|
2789
|
-
// explicitly, for the reason `ToolCallErrorPayloadSchema`
|
|
2790
|
-
// records. One shape for "no result object existed", not two.
|
|
2791
|
-
outcome.raised ? null : outcome.result ?? null,
|
|
2792
|
-
(text) => errorBody(ctx, text),
|
|
2793
|
-
ctx.scrubber
|
|
2794
|
-
)
|
|
2795
|
-
}
|
|
2796
|
-
})
|
|
2829
|
+
(outcome) => failedAbove(outcome, OUTPUT_SCHEMA_MISMATCH)
|
|
2797
2830
|
);
|
|
2798
2831
|
return result;
|
|
2799
2832
|
};
|
|
@@ -2959,11 +2992,12 @@ function installLifecycleSeam(lowLevel, ctx, spec) {
|
|
|
2959
2992
|
})
|
|
2960
2993
|
);
|
|
2961
2994
|
};
|
|
2962
|
-
await fire(spec.schemas.start, spec.startParams(requestParams));
|
|
2995
|
+
if (!resumesPausedCall(extra)) await fire(spec.schemas.start, spec.startParams(requestParams));
|
|
2963
2996
|
const startedAt = performance.now();
|
|
2964
2997
|
const elapsed = () => Math.round(performance.now() - startedAt);
|
|
2965
2998
|
try {
|
|
2966
2999
|
const result = await handler(...args);
|
|
3000
|
+
if (isInputRequired(result)) return result;
|
|
2967
3001
|
await fire(spec.schemas.end, {
|
|
2968
3002
|
...spec.countKey === void 0 ? {} : { count: countOf(result, spec.countKey) },
|
|
2969
3003
|
duration_ms: elapsed()
|
|
@@ -3391,7 +3425,12 @@ function install(server, supplied, resolved, sentSurfaces, warned3) {
|
|
|
3391
3425
|
seam_augmentations: snapshot.seam_augmentations
|
|
3392
3426
|
}
|
|
3393
3427
|
});
|
|
3394
|
-
|
|
3428
|
+
try {
|
|
3429
|
+
await sink.write(event);
|
|
3430
|
+
} catch (err) {
|
|
3431
|
+
if (isSinkClosed(err)) return droppedAfterClose(sink);
|
|
3432
|
+
throw err;
|
|
3433
|
+
}
|
|
3395
3434
|
};
|
|
3396
3435
|
const bustSchemaMemo = (name) => {
|
|
3397
3436
|
const memo = internals._toolInputSchemaJson;
|
|
@@ -3853,6 +3892,7 @@ var Core = class {
|
|
|
3853
3892
|
try {
|
|
3854
3893
|
await this.sink.write(event);
|
|
3855
3894
|
} catch (err) {
|
|
3895
|
+
if (isSinkClosed(err)) return droppedAfterClose(this.sink);
|
|
3856
3896
|
process.stderr.write(`baton: surface snapshot not sent; will retry: ${printable(err)}
|
|
3857
3897
|
`);
|
|
3858
3898
|
this.sentSurfaces.unmark(surface.digest);
|
|
@@ -4208,6 +4248,7 @@ export {
|
|
|
4208
4248
|
ResourceReadStartPayloadSchema,
|
|
4209
4249
|
SDK_VERSION,
|
|
4210
4250
|
Scrubber,
|
|
4251
|
+
SinkClosedError,
|
|
4211
4252
|
StdoutSink,
|
|
4212
4253
|
SurfaceSnapshotEventSchema,
|
|
4213
4254
|
SurfaceSnapshotPayloadSchema,
|