@converge.ai/a13n 0.5.0 → 0.8.0
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 +27 -144
- package/dist/client.d.ts +32 -14
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +92 -16
- package/dist/client.js.map +1 -1
- package/dist/conversations.d.ts +134 -0
- package/dist/conversations.d.ts.map +1 -0
- package/dist/conversations.js +421 -0
- package/dist/conversations.js.map +1 -0
- package/dist/errors.d.ts +57 -44
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +97 -63
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +25 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -7
- package/dist/index.js.map +1 -1
- package/dist/models.d.ts +42 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +72 -0
- package/dist/models.js.map +1 -0
- package/dist/public-models.d.ts +673 -0
- package/dist/public-models.d.ts.map +1 -0
- package/dist/public-models.js +2 -0
- package/dist/public-models.js.map +1 -0
- package/dist/realtime/browser.d.ts +16 -0
- package/dist/realtime/browser.d.ts.map +1 -0
- package/dist/realtime/browser.js +97 -0
- package/dist/realtime/browser.js.map +1 -0
- package/dist/realtime/core.d.ts +103 -0
- package/dist/realtime/core.d.ts.map +1 -0
- package/dist/realtime/core.js +240 -0
- package/dist/realtime/core.js.map +1 -0
- package/dist/resources/base.d.ts +43 -36
- package/dist/resources/base.d.ts.map +1 -1
- package/dist/resources/base.js +222 -200
- package/dist/resources/base.js.map +1 -1
- package/dist/resources/generated.d.ts +3909 -7345
- package/dist/resources/generated.d.ts.map +1 -1
- package/dist/resources/generated.js +6478 -5842
- package/dist/resources/generated.js.map +1 -1
- package/dist/resources/interaction.js +2 -2
- package/dist/resources/interaction.js.map +1 -1
- package/dist/schema.d.ts +4180 -2696
- package/dist/schema.d.ts.map +1 -1
- package/dist/session-stream-schema.d.ts +214 -3
- package/dist/session-stream-schema.d.ts.map +1 -1
- package/dist/session-stream-schema.js +10 -1
- package/dist/session-stream-schema.js.map +1 -1
- package/dist/streams/ag-ui.d.ts +114 -0
- package/dist/streams/ag-ui.d.ts.map +1 -0
- package/dist/streams/ag-ui.js +115 -0
- package/dist/streams/ag-ui.js.map +1 -0
- package/dist/streams/session-stream.d.ts +18 -7
- package/dist/streams/session-stream.d.ts.map +1 -1
- package/dist/streams/session-stream.js +95 -19
- package/dist/streams/session-stream.js.map +1 -1
- package/dist/streams/sse.d.ts +2 -2
- package/dist/streams/sse.d.ts.map +1 -1
- package/dist/streams/sse.js +5 -5
- package/dist/streams/sse.js.map +1 -1
- package/dist/streams/thread-stream.d.ts +3 -2
- package/dist/streams/thread-stream.d.ts.map +1 -1
- package/dist/streams/thread-stream.js +12 -12
- package/dist/streams/thread-stream.js.map +1 -1
- package/dist/transport.d.ts +34 -25
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +176 -128
- package/dist/transport.js.map +1 -1
- package/dist/webhooks.d.ts +59 -0
- package/dist/webhooks.d.ts.map +1 -0
- package/dist/webhooks.js +79 -0
- package/dist/webhooks.js.map +1 -0
- package/dist/workflow.d.ts +35 -35
- package/dist/workflow.d.ts.map +1 -1
- package/dist/workflow.js +5 -1
- package/dist/workflow.js.map +1 -1
- package/openapi.json +9461 -2019
- package/package.json +9 -8
- package/THIRD_PARTY_NOTICES.txt +0 -83
- package/dist/dispatch.d.ts +0 -6
- package/dist/dispatch.d.ts.map +0 -1
- package/dist/dispatch.js +0 -19
- package/dist/dispatch.js.map +0 -1
- package/dist/semantic.d.ts +0 -262
- package/dist/semantic.d.ts.map +0 -1
- package/dist/semantic.js +0 -624
- package/dist/semantic.js.map +0 -1
- package/dist/session-stream-validation.d.ts +0 -129
- package/dist/session-stream-validation.d.ts.map +0 -1
- package/dist/session-stream-validation.js +0 -36240
- package/dist/session-stream-validation.js.map +0 -1
- package/dist/workspace-scope.d.ts +0 -2
- package/dist/workspace-scope.d.ts.map +0 -1
- package/dist/workspace-scope.js +0 -354
- package/dist/workspace-scope.js.map +0 -1
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type { SessionStreamSchemas } from "../session-stream-schema.js";
|
|
2
|
+
export type Citation = SessionStreamSchemas["Citation"];
|
|
3
|
+
export type TextMessage = Omit<SessionStreamSchemas["Item"], "kind"> & {
|
|
4
|
+
kind: "text_message";
|
|
5
|
+
readonly citations: readonly Citation[];
|
|
6
|
+
};
|
|
7
|
+
export declare function asTextMessage(value: SessionStreamSchemas["Item"]): TextMessage | undefined;
|
|
8
|
+
type EventFields = {
|
|
9
|
+
timestamp?: number;
|
|
10
|
+
subagentRunId?: string | null;
|
|
11
|
+
metadata?: Record<string, unknown> | null;
|
|
12
|
+
};
|
|
13
|
+
export type TextCitationsEvent = EventFields & {
|
|
14
|
+
type: "CUSTOM";
|
|
15
|
+
name: "a13n.text_citations";
|
|
16
|
+
value: {
|
|
17
|
+
thread_id: string;
|
|
18
|
+
run_id: string;
|
|
19
|
+
sequence: number;
|
|
20
|
+
occurred_at: string;
|
|
21
|
+
event: {
|
|
22
|
+
message_id: string;
|
|
23
|
+
citations: Citation[];
|
|
24
|
+
replace?: boolean;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
export type UnknownEvent = {
|
|
29
|
+
type: "UNKNOWN";
|
|
30
|
+
eventType: string;
|
|
31
|
+
raw: Record<string, unknown>;
|
|
32
|
+
};
|
|
33
|
+
export type AGUIEvent = (EventFields & ({
|
|
34
|
+
type: "TEXT_MESSAGE_START";
|
|
35
|
+
messageId: string;
|
|
36
|
+
role: string;
|
|
37
|
+
} | {
|
|
38
|
+
type: "TEXT_MESSAGE_CONTENT";
|
|
39
|
+
messageId: string;
|
|
40
|
+
delta: string;
|
|
41
|
+
} | {
|
|
42
|
+
type: "TEXT_MESSAGE_END";
|
|
43
|
+
messageId: string;
|
|
44
|
+
} | {
|
|
45
|
+
type: "RUN_STARTED" | "RUN_FINISHED";
|
|
46
|
+
runId: string;
|
|
47
|
+
threadId: string;
|
|
48
|
+
} | {
|
|
49
|
+
type: "RUN_ERROR";
|
|
50
|
+
message: string;
|
|
51
|
+
code?: string;
|
|
52
|
+
} | {
|
|
53
|
+
type: "TOOL_CALL_START";
|
|
54
|
+
toolCallId: string;
|
|
55
|
+
toolCallName: string;
|
|
56
|
+
parentMessageId?: string;
|
|
57
|
+
} | {
|
|
58
|
+
type: "TOOL_CALL_ARGS";
|
|
59
|
+
toolCallId: string;
|
|
60
|
+
delta: string;
|
|
61
|
+
} | {
|
|
62
|
+
type: "TOOL_CALL_END";
|
|
63
|
+
toolCallId: string;
|
|
64
|
+
} | {
|
|
65
|
+
type: "TOOL_CALL_RESULT";
|
|
66
|
+
messageId: string;
|
|
67
|
+
toolCallId: string;
|
|
68
|
+
content: string;
|
|
69
|
+
role?: string;
|
|
70
|
+
} | {
|
|
71
|
+
type: "REASONING_MESSAGE_START" | "REASONING_MESSAGE_END";
|
|
72
|
+
messageId: string;
|
|
73
|
+
} | {
|
|
74
|
+
type: "REASONING_MESSAGE_CONTENT";
|
|
75
|
+
messageId: string;
|
|
76
|
+
delta: string;
|
|
77
|
+
} | {
|
|
78
|
+
type: "STATE_SNAPSHOT";
|
|
79
|
+
snapshot: unknown;
|
|
80
|
+
} | {
|
|
81
|
+
type: "STATE_DELTA";
|
|
82
|
+
delta: unknown[];
|
|
83
|
+
} | {
|
|
84
|
+
type: "MESSAGES_SNAPSHOT";
|
|
85
|
+
messages: unknown[];
|
|
86
|
+
} | {
|
|
87
|
+
type: "STEP_STARTED" | "STEP_FINISHED";
|
|
88
|
+
stepName: string;
|
|
89
|
+
} | {
|
|
90
|
+
type: "CUSTOM";
|
|
91
|
+
name: string;
|
|
92
|
+
value: unknown;
|
|
93
|
+
} | {
|
|
94
|
+
type: "RAW";
|
|
95
|
+
event: unknown;
|
|
96
|
+
source?: string;
|
|
97
|
+
})) | TextCitationsEvent | UnknownEvent;
|
|
98
|
+
export declare function agui(raw: Record<string, unknown>): AGUIEvent;
|
|
99
|
+
export declare function isTextCitationsEvent(event: AGUIEvent): event is TextCitationsEvent;
|
|
100
|
+
interface Fragment {
|
|
101
|
+
count: number;
|
|
102
|
+
parts: string[];
|
|
103
|
+
}
|
|
104
|
+
/** Transport assembly only; display folding and durable Items remain Service-owned. */
|
|
105
|
+
export declare class Fragments {
|
|
106
|
+
private readonly maxBytes;
|
|
107
|
+
private readonly pending;
|
|
108
|
+
private size;
|
|
109
|
+
constructor(maxBytes?: number);
|
|
110
|
+
restore(value: Record<string, Fragment>): void;
|
|
111
|
+
accept(raw: Record<string, unknown>): AGUIEvent | null;
|
|
112
|
+
}
|
|
113
|
+
export {};
|
|
114
|
+
//# sourceMappingURL=ag-ui.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ag-ui.d.ts","sourceRoot":"","sources":["../../src/streams/ag-ui.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAExE,MAAM,MAAM,QAAQ,GAAG,oBAAoB,CAAC,UAAU,CAAC,CAAC;AACxD,MAAM,MAAM,WAAW,GAAG,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,GAAG;IACrE,IAAI,EAAE,cAAc,CAAC;IACrB,QAAQ,CAAC,SAAS,EAAE,SAAS,QAAQ,EAAE,CAAC;CACzC,CAAC;AACF,wBAAgB,aAAa,CAC3B,KAAK,EAAE,oBAAoB,CAAC,MAAM,CAAC,GAClC,WAAW,GAAG,SAAS,CAOzB;AACD,KAAK,WAAW,GAAG;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;CAC3C,CAAC;AACF,MAAM,MAAM,kBAAkB,GAAG,WAAW,GAAG;IAC7C,IA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,KAAK,IAAI,kBAAkB,CAS7B;AAED,UAAU,QAAQ;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AACD,uFAAuF;AACvF,qBAAa,SAAS;IAGR,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAFrC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA+B;IACvD,OAAO,CAAC,IAAI,CAAK;gBACY,QAAQ,SAAmB;IACxD,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC;IAcvC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GAAG,IAAI;CAwDvD"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { isRecord, UnexpectedResponseError } from "../errors.js";
|
|
2
|
+
export function asTextMessage(value) {
|
|
3
|
+
if (value.kind !== "text_message")
|
|
4
|
+
return undefined;
|
|
5
|
+
if (!Object.hasOwn(value, "citations"))
|
|
6
|
+
Object.defineProperty(value, "citations", {
|
|
7
|
+
get: () => value.content.citations ?? [],
|
|
8
|
+
});
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
const required = {
|
|
12
|
+
TEXT_MESSAGE_START: ["messageId", "role"],
|
|
13
|
+
TEXT_MESSAGE_CONTENT: ["messageId", "delta"],
|
|
14
|
+
TEXT_MESSAGE_END: ["messageId"],
|
|
15
|
+
RUN_STARTED: ["runId", "threadId"],
|
|
16
|
+
RUN_FINISHED: ["runId", "threadId"],
|
|
17
|
+
RUN_ERROR: ["message"],
|
|
18
|
+
TOOL_CALL_START: ["toolCallId", "toolCallName"],
|
|
19
|
+
TOOL_CALL_ARGS: ["toolCallId", "delta"],
|
|
20
|
+
TOOL_CALL_END: ["toolCallId"],
|
|
21
|
+
TOOL_CALL_RESULT: ["messageId", "toolCallId", "content"],
|
|
22
|
+
REASONING_MESSAGE_START: ["messageId"],
|
|
23
|
+
REASONING_MESSAGE_CONTENT: ["messageId", "delta"],
|
|
24
|
+
REASONING_MESSAGE_END: ["messageId"],
|
|
25
|
+
STATE_SNAPSHOT: ["snapshot"],
|
|
26
|
+
STATE_DELTA: ["delta"],
|
|
27
|
+
MESSAGES_SNAPSHOT: ["messages"],
|
|
28
|
+
STEP_STARTED: ["stepName"],
|
|
29
|
+
STEP_FINISHED: ["stepName"],
|
|
30
|
+
CUSTOM: ["name", "value"],
|
|
31
|
+
RAW: ["event"],
|
|
32
|
+
};
|
|
33
|
+
export function agui(raw) {
|
|
34
|
+
if (typeof raw.type !== "string")
|
|
35
|
+
throw new UnexpectedResponseError("AG-UI event has no type.");
|
|
36
|
+
if (!Object.hasOwn(required, raw.type))
|
|
37
|
+
return { type: "UNKNOWN", eventType: raw.type, raw };
|
|
38
|
+
if (required[raw.type].some((name) => !Object.hasOwn(raw, name)))
|
|
39
|
+
throw new UnexpectedResponseError(`Incomplete ${raw.type} AG-UI event.`);
|
|
40
|
+
return raw;
|
|
41
|
+
}
|
|
42
|
+
export function isTextCitationsEvent(event) {
|
|
43
|
+
return (event.type === "CUSTOM" &&
|
|
44
|
+
event.name === "a13n.text_citations" &&
|
|
45
|
+
isRecord(event.value) &&
|
|
46
|
+
isRecord(event.value.event) &&
|
|
47
|
+
typeof event.value.event.message_id === "string" &&
|
|
48
|
+
Array.isArray(event.value.event.citations));
|
|
49
|
+
}
|
|
50
|
+
/** Transport assembly only; display folding and durable Items remain Service-owned. */
|
|
51
|
+
export class Fragments {
|
|
52
|
+
maxBytes;
|
|
53
|
+
pending = new Map();
|
|
54
|
+
size = 0;
|
|
55
|
+
constructor(maxBytes = 64 * 1024 * 1024) {
|
|
56
|
+
this.maxBytes = maxBytes;
|
|
57
|
+
}
|
|
58
|
+
restore(value) {
|
|
59
|
+
this.pending.clear();
|
|
60
|
+
this.size = 0;
|
|
61
|
+
for (const [id, part] of Object.entries(value)) {
|
|
62
|
+
if (Array.isArray(part.parts)) {
|
|
63
|
+
this.pending.set(id, { count: part.count, parts: [...part.parts] });
|
|
64
|
+
this.size += part.parts.reduce((sum, text) => sum + text.length, 0);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (this.size > this.maxBytes || this.pending.size > 8)
|
|
68
|
+
throw new UnexpectedResponseError("Session fragment continuation exceeds assembly bounds.");
|
|
69
|
+
}
|
|
70
|
+
accept(raw) {
|
|
71
|
+
if (raw.type !== "CUSTOM" || raw.name !== "a13n.stream.fragment")
|
|
72
|
+
return agui(raw);
|
|
73
|
+
const value = raw.value;
|
|
74
|
+
if (!isRecord(value) ||
|
|
75
|
+
typeof value.id !== "string" ||
|
|
76
|
+
typeof value.data !== "string" ||
|
|
77
|
+
!Number.isSafeInteger(value.index) ||
|
|
78
|
+
!Number.isSafeInteger(value.count) ||
|
|
79
|
+
value.index < 0 ||
|
|
80
|
+
value.index >= value.count)
|
|
81
|
+
throw new UnexpectedResponseError("Invalid custom event fragment.");
|
|
82
|
+
const { id, data } = value;
|
|
83
|
+
if (value.index === 0) {
|
|
84
|
+
if (this.pending.size >= 8 || this.pending.has(id))
|
|
85
|
+
throw new UnexpectedResponseError("Overlapping custom event fragments.");
|
|
86
|
+
this.pending.set(id, { count: value.count, parts: [] });
|
|
87
|
+
}
|
|
88
|
+
const assembly = this.pending.get(id);
|
|
89
|
+
if (!assembly ||
|
|
90
|
+
assembly.count !== value.count ||
|
|
91
|
+
assembly.parts.length !== value.index ||
|
|
92
|
+
this.size + data.length > this.maxBytes)
|
|
93
|
+
throw new UnexpectedResponseError("Custom event fragment sequence is incomplete. Reopen from a snapshot.");
|
|
94
|
+
assembly.parts.push(data);
|
|
95
|
+
this.size += data.length;
|
|
96
|
+
if (assembly.parts.length !== assembly.count)
|
|
97
|
+
return null;
|
|
98
|
+
this.pending.delete(id);
|
|
99
|
+
const encoded = assembly.parts.join("");
|
|
100
|
+
this.size -= encoded.length;
|
|
101
|
+
let event;
|
|
102
|
+
try {
|
|
103
|
+
event = JSON.parse(encoded);
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
throw new UnexpectedResponseError("Reassembled custom event is invalid JSON.");
|
|
107
|
+
}
|
|
108
|
+
if (!isRecord(event) ||
|
|
109
|
+
event.type !== "CUSTOM" ||
|
|
110
|
+
event.name === "a13n.stream.fragment")
|
|
111
|
+
throw new UnexpectedResponseError("Reassembled event is not a custom event.");
|
|
112
|
+
return agui(event);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=ag-ui.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ag-ui.js","sourceRoot":"","sources":["../../src/streams/ag-ui.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAQjE,MAAM,UAAU,aAAa,CAC3B,KAAmC;IAEnC,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc;QAAE,OAAO,SAAS,CAAC;IACpD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,WAAW,CAAC;QACpC,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,WAAW,EAAE;YACxC,GAAG,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,IAAI,EAAE;SACzC,CAAC,CAAC;IACL,OAAO,KAAoB,CAAC;AAC9B,CAAC;AAoED,MAAM,QAAQ,GAAsC;IAClD,kBAAkB,EAAE,CAAC,WAAW,EAAE,MAAM,CAAC;IACzC,oBAAoB,EAAE,CAAC,WAAW,EAAE,OAAO,CAAC;IAC5C,gBAAgB,EAAE,CAAC,WAAW,CAAC;IAC/B,WAAW,EAAE,CAAC,OAAO,EAAE,UAAU,CAAC;IAClC,YAAY,EAAE,CAAC,OAAO,EAAE,UAAU,CAAC;IACnC,SAAS,EAAE,CAAC,SAAS,CAAC;IACtB,eAAe,EAAE,CAAC,YAAY,EAAE,cAAc,CAAC;IAC/C,cAAc,EAAE,CAAC,YAAY,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AC,KAAK;YAC9B,QAAQ,CAAC,KAAK,CAAC,MAAM,KAAK,KAAK,CAAC,KAAK;YACrC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,QAAQ;YAEvC,MAAM,IAAI,uBAAuB,CAC/B,uEAAuE,CACxE,CAAC;QACJ,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1B,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC;QACzB,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,KAAK,QAAQ,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC;QAC1D,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACxB,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACxC,IAAI,CAAC,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;QAC5B,IAAI,KAAc,CAAC;QACnB,IAAI,CAAC;YACH,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC9B,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,IAAI,uBAAuB,CAC/B,2CAA2C,CAC5C,CAAC;QACJ,CAAC;QACD,IACE,CAAC,QAAQ,CAAC,KAAK,CAAC;YAChB,KAAK,CAAC,IAAI,KAAK,QAAQ;YACvB,KAAK,CAAC,IAAI,KAAK,sBAAsB;YAErC,MAAM,IAAI,uBAAuB,CAC/B,0CAA0C,CAC3C,CAAC;QACJ,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;CACF"}
|
|
@@ -1,12 +1,23 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type
|
|
1
|
+
import type { BinaryBody } from "../resources/base.js";
|
|
2
|
+
import { type SessionStreamFrame as WireFrame } from "../session-stream-schema.js";
|
|
3
|
+
import { type AGUIEvent } from "./ag-ui.js";
|
|
4
|
+
type Delta = Extract<WireFrame, {
|
|
5
|
+
type: "delta";
|
|
6
|
+
}>;
|
|
7
|
+
export type SessionStreamFrame = Exclude<WireFrame, Delta> | {
|
|
8
|
+
type: "delta";
|
|
9
|
+
data: Omit<Delta["data"], "event"> & {
|
|
10
|
+
event: AGUIEvent;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export type SessionStreamEvent = SessionStreamFrame | {
|
|
14
|
+
type: "snapshot_reset";
|
|
15
|
+
};
|
|
3
16
|
export interface SessionStreamOptions {
|
|
4
17
|
signal?: AbortSignal;
|
|
5
|
-
|
|
18
|
+
reconnect?: boolean;
|
|
6
19
|
maxFrameCharacters?: number;
|
|
7
20
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*/
|
|
11
|
-
export declare function sessionStream(stream: BinaryResult, options?: SessionStreamOptions): AsyncGenerator<SessionStreamFrame>;
|
|
21
|
+
export declare function sessionStream(open: (signal: AbortSignal) => Promise<BinaryBody>, shutdown: AbortSignal, options?: SessionStreamOptions): AsyncGenerator<SessionStreamEvent>;
|
|
22
|
+
export {};
|
|
12
23
|
//# sourceMappingURL=session-stream.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-stream.d.ts","sourceRoot":"","sources":["../../src/streams/session-stream.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"session-stream.d.ts","sourceRoot":"","sources":["../../src/streams/session-stream.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAEL,KAAK,kBAAkB,IAAI,SAAS,EACrC,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAa,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvD,KAAK,KAAK,GAAG,OAAO,CAAC,SAAS,EAAE;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC;AACnD,MAAM,MAAM,kBAAkB,GAC1B,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,GACzB;IACE,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,GAAG;QAAE,KAAK,EAAE,SAAS,CAAA;KAAE,CAAC;CAC3D,CAAC;AACN,MAAM,MAAM,kBAAkB,GAC5B,kBAAkB,GAAG;IAAE,IAAI,EAAE,gBAAgB,CAAA;CAAE,CAAC;AAClD,MAAM,WAAW,oBAAoB;IACnC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAuFD,wBAAuB,aAAa,CAClC,IAAI,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,UAAU,CAAC,EAClD,QAAQ,EAAE,WAAW,EACrB,OAAO,GAAE,oBAAyB,GACjC,cAAc,CAAC,kBAAkB,CAAC,CA8CpC"}
|
|
@@ -1,36 +1,112 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { isA13nError, isRecord, UnexpectedResponseError } from "../errors.js";
|
|
2
|
+
import { sessionFrameFields, } from "../session-stream-schema.js";
|
|
3
|
+
import { delay } from "../transport.js";
|
|
4
|
+
import { Fragments } from "./ag-ui.js";
|
|
5
|
+
import { decodeSseDetailed, TruncatedStreamError } from "./sse.js";
|
|
6
|
+
async function* connection(stream, options) {
|
|
7
|
+
const fragments = new Map();
|
|
8
8
|
try {
|
|
9
|
-
if (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
throw new
|
|
9
|
+
if (!stream.response.headers
|
|
10
|
+
.get("Content-Type")
|
|
11
|
+
?.startsWith("text/event-stream"))
|
|
12
|
+
throw new UnexpectedResponseError("Expected a Session event stream.");
|
|
13
13
|
for await (const frame of decodeSseDetailed(stream.body, options.signal, options.maxFrameCharacters ?? Infinity)) {
|
|
14
|
-
|
|
15
|
-
if (!Object.hasOwn(validators, frame.event))
|
|
14
|
+
if (!Object.hasOwn(sessionFrameFields, frame.event))
|
|
16
15
|
continue;
|
|
17
16
|
if (frame.idPresent)
|
|
18
|
-
throw new
|
|
17
|
+
throw new UnexpectedResponseError("A Session frame cannot carry a replay cursor.");
|
|
19
18
|
let data;
|
|
20
19
|
try {
|
|
21
20
|
data = JSON.parse(frame.data);
|
|
22
21
|
}
|
|
23
22
|
catch {
|
|
24
|
-
throw new
|
|
23
|
+
throw new UnexpectedResponseError("Invalid Session frame JSON.");
|
|
25
24
|
}
|
|
26
|
-
const
|
|
27
|
-
if (!
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
const type = frame.event;
|
|
26
|
+
if (!isRecord(data) ||
|
|
27
|
+
sessionFrameFields[type].some((key) => !Object.hasOwn(data, key)))
|
|
28
|
+
throw new UnexpectedResponseError(`Invalid Session ${type} frame.`);
|
|
29
|
+
if (type === "items") {
|
|
30
|
+
const items = data;
|
|
31
|
+
if (!Array.isArray(items.items))
|
|
32
|
+
throw new UnexpectedResponseError("Invalid Session items frame.");
|
|
33
|
+
if (items.complete)
|
|
34
|
+
fragments.delete(items.run_id);
|
|
35
|
+
else {
|
|
36
|
+
const assembly = new Fragments();
|
|
37
|
+
const pending = items.continuation?.fragments?.pending;
|
|
38
|
+
if (pending)
|
|
39
|
+
assembly.restore(Object.fromEntries(Object.entries(pending).map(([id, part]) => [
|
|
40
|
+
id,
|
|
41
|
+
{ count: part.count, parts: part.parts ?? [] },
|
|
42
|
+
])));
|
|
43
|
+
fragments.set(items.run_id, assembly);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (type === "gap" && typeof data.run_id === "string")
|
|
47
|
+
fragments.delete(data.run_id);
|
|
48
|
+
if (type === "delta") {
|
|
49
|
+
if (!isRecord(data.event) ||
|
|
50
|
+
typeof data.run_id !== "string" ||
|
|
51
|
+
typeof data.sequence !== "number" ||
|
|
52
|
+
typeof data.attempt !== "number")
|
|
53
|
+
throw new UnexpectedResponseError("Invalid Session delta frame.");
|
|
54
|
+
let assembly = fragments.get(data.run_id);
|
|
55
|
+
if (!assembly) {
|
|
56
|
+
assembly = new Fragments();
|
|
57
|
+
fragments.set(data.run_id, assembly);
|
|
58
|
+
}
|
|
59
|
+
const event = assembly.accept(data.event);
|
|
60
|
+
if (!event)
|
|
61
|
+
continue;
|
|
62
|
+
data = { ...data, event };
|
|
63
|
+
}
|
|
64
|
+
yield { type, data };
|
|
30
65
|
}
|
|
31
66
|
}
|
|
32
67
|
finally {
|
|
33
68
|
await stream.close();
|
|
34
69
|
}
|
|
35
70
|
}
|
|
71
|
+
export async function* sessionStream(open, shutdown, options = {}) {
|
|
72
|
+
const signal = options.signal
|
|
73
|
+
? AbortSignal.any([shutdown, options.signal])
|
|
74
|
+
: shutdown;
|
|
75
|
+
let failures = 0;
|
|
76
|
+
for (;;) {
|
|
77
|
+
signal.throwIfAborted();
|
|
78
|
+
let retry = 0;
|
|
79
|
+
const opened = Date.now();
|
|
80
|
+
try {
|
|
81
|
+
yield* connection(await open(signal), { ...options, signal });
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
if (!options.reconnect ||
|
|
85
|
+
signal.aborted ||
|
|
86
|
+
(error instanceof UnexpectedResponseError &&
|
|
87
|
+
!(error instanceof TruncatedStreamError)))
|
|
88
|
+
throw error;
|
|
89
|
+
if (isA13nError(error) && error.status !== null) {
|
|
90
|
+
if (error.status >= 400 && error.status < 500 && error.status !== 429)
|
|
91
|
+
throw error;
|
|
92
|
+
const header = "retryAfter" in error && typeof error.retryAfter === "string"
|
|
93
|
+
? error.retryAfter
|
|
94
|
+
: null;
|
|
95
|
+
if (header !== null) {
|
|
96
|
+
const seconds = Number(header);
|
|
97
|
+
retry =
|
|
98
|
+
Math.max(0, Number.isFinite(seconds)
|
|
99
|
+
? seconds * 1_000
|
|
100
|
+
: Date.parse(header) - Date.now()) || 0;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (!options.reconnect)
|
|
105
|
+
return;
|
|
106
|
+
if (Date.now() - opened >= 30_000)
|
|
107
|
+
failures = 0;
|
|
108
|
+
await delay(retry || Math.random() * Math.min(30_000, 500 * 2 ** failures++), signal);
|
|
109
|
+
yield { type: "snapshot_reset" };
|
|
110
|
+
}
|
|
111
|
+
}
|
|
36
112
|
//# sourceMappingURL=session-stream.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-stream.js","sourceRoot":"","sources":["../../src/streams/session-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"session-stream.js","sourceRoot":"","sources":["../../src/streams/session-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAE9E,OAAO,EACL,kBAAkB,GAEnB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,SAAS,EAAkB,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAiBnE,KAAK,SAAS,CAAC,CAAC,UAAU,CACxB,MAAkB,EAClB,OAA6B;IAE7B,MAAM,SAAS,GAAG,IAAI,GAAG,EAAqB,CAAC;IAC/C,IAAI,CAAC;QACH,IACE,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO;aACrB,GAAG,CAAC,cAAc,CAAC;YACpB,EAAE,UAAU,CAAC,mBAAmB,CAAC;YAEnC,MAAM,IAAI,uBAAuB,CAAC,kCAAkC,CAAC,CAAC;QACxE,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,iBAAiB,CACzC,MAAM,CAAC,IAAI,EACX,OAAO,CAAC,M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,UAAU,KAAK,QAAQ;oBAC3D,CAAC,CAAC,KAAK,CAAC,UAAU;oBAClB,CAAC,CAAC,IAAI,CAAC;gBACX,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;oBACpB,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;oBAC/B,KAAK;wBACH,IAAI,CAAC,GAAG,CACN,CAAC,EACD,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC;4BACtB,CAAC,CAAC,OAAO,GAAG,KAAK;4BACjB,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CACpC,IAAI,CAAC,CAAC;gBACX,CAAC;YACH,CAAC;QACH,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,SAAS;YAAE,OAAO;QAC/B,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,IAAI,MAAM;YAAE,QAAQ,GAAG,CAAC,CAAC;QAChD,MAAM,KAAK,CACT,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,IAAI,QAAQ,EAAE,CAAC,EAChE,MAAM,CACP,CAAC;QACF,MAAM,EAAE,IAAI,EAAE,gBAAgB,EAAE,CAAC;IACnC,CAAC;AACH,CAAC"}
|
package/dist/streams/sse.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UnexpectedResponseError } from "../errors.js";
|
|
2
2
|
export interface SseFrame {
|
|
3
3
|
id: string;
|
|
4
4
|
event: string;
|
|
@@ -8,7 +8,7 @@ export interface DetailedSseFrame extends SseFrame {
|
|
|
8
8
|
idPresent: boolean;
|
|
9
9
|
}
|
|
10
10
|
/** The response ended cleanly inside an SSE frame; the incomplete frame was discarded, never dispatched. */
|
|
11
|
-
export declare class TruncatedStreamError extends
|
|
11
|
+
export declare class TruncatedStreamError extends UnexpectedResponseError {
|
|
12
12
|
}
|
|
13
13
|
/** Decode incremental UTF-8 and LF/CRLF/CR framing, including split delimiters. */
|
|
14
14
|
export declare function decodeSse(body: ReadableStream<Uint8Array>, signal?: AbortSignal): AsyncGenerator<SseFrame>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../src/streams/sse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../src/streams/sse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAEvD,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd;AACD,MAAM,WAAW,gBAAiB,SAAQ,QAAQ;IAChD,SAAS,EAAE,OAAO,CAAC;CACpB;AAGD,4GAA4G;AAC5G,qBAAa,oBAAqB,SAAQ,uBAAuB;CAAG;AAEpE,mFAAmF;AACnF,wBAAuB,SAAS,CAC9B,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,EAChC,MAAM,CAAC,EAAE,WAAW,GACnB,cAAc,CAAC,QAAQ,CAAC,CAS1B;AAED,uFAAuF;AACvF,wBAAuB,iBAAiB,CACtC,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,EAChC,MAAM,CAAC,EAAE,WAAW,EACpB,kBAAkB,SAA4B,GAC7C,cAAc,CAAC,gBAAgB,CAAC,CA4FlC"}
|
package/dist/streams/sse.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UnexpectedResponseError } from "../errors.js";
|
|
2
2
|
const defaultMaxFrameCharacters = 1024 * 1024;
|
|
3
3
|
/** The response ended cleanly inside an SSE frame; the incomplete frame was discarded, never dispatched. */
|
|
4
|
-
export class TruncatedStreamError extends
|
|
4
|
+
export class TruncatedStreamError extends UnexpectedResponseError {
|
|
5
5
|
}
|
|
6
6
|
/** Decode incremental UTF-8 and LF/CRLF/CR framing, including split delimiters. */
|
|
7
7
|
export async function* decodeSse(body, signal) {
|
|
@@ -36,7 +36,7 @@ export async function* decodeSseDetailed(body, signal, maxFrameCharacters = defa
|
|
|
36
36
|
// incomplete trailing sequence, so only the EOF flush can signal truncation.
|
|
37
37
|
if (chunk.done)
|
|
38
38
|
throw new TruncatedStreamError("The stream ended inside a UTF-8 sequence.");
|
|
39
|
-
throw new
|
|
39
|
+
throw new UnexpectedResponseError("The SSE stream contains invalid UTF-8.");
|
|
40
40
|
}
|
|
41
41
|
let boundary;
|
|
42
42
|
while ((boundary = buffer.search(/[\r\n]/)) >= 0) {
|
|
@@ -49,7 +49,7 @@ export async function* decodeSseDetailed(body, signal, maxFrameCharacters = defa
|
|
|
49
49
|
buffer = buffer.slice(boundary + width);
|
|
50
50
|
size += line.length;
|
|
51
51
|
if (size > maxFrameCharacters)
|
|
52
|
-
throw new
|
|
52
|
+
throw new UnexpectedResponseError("SSE frame exceeds the size limit.");
|
|
53
53
|
if (!line) {
|
|
54
54
|
if (values.length) {
|
|
55
55
|
signal?.throwIfAborted();
|
|
@@ -81,7 +81,7 @@ export async function* decodeSseDetailed(body, signal, maxFrameCharacters = defa
|
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
if (buffer.length + size > maxFrameCharacters)
|
|
84
|
-
throw new
|
|
84
|
+
throw new UnexpectedResponseError("SSE frame exceeds the size limit.");
|
|
85
85
|
if (chunk.done) {
|
|
86
86
|
signal?.throwIfAborted();
|
|
87
87
|
if (buffer || values.length)
|
package/dist/streams/sse.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sse.js","sourceRoot":"","sources":["../../src/streams/sse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"sse.js","sourceRoot":"","sources":["../../src/streams/sse.ts"],"names":[],"mappings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AAG,IAAI,CAAC;gBACnB,CAAC;YACH,CAAC;YACD,IAAI,MAAM,CAAC,MAAM,GAAG,IAAI,GAAG,kBAAkB;gBAC3C,MAAM,IAAI,uBAAuB,CAAC,mCAAmC,CAAC,CAAC;YACzE,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;gBACf,MAAM,EAAE,cAAc,EAAE,CAAC;gBACzB,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM;oBACzB,MAAM,IAAI,oBAAoB,CAC5B,uCAAuC,CACxC,CAAC;gBACJ,OAAO;YACT,CAAC;QACH,CAAC;IACH,CAAC;YAAS,CAAC;QACT,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAC5C,MAAM,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC7C,MAAM,CAAC,WAAW,EAAE,CAAC;IACvB,CAAC;AACH,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SessionStreamSchemas } from "../session-stream-schema.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { BinaryBody } from "../resources/base.js";
|
|
3
3
|
export interface ThreadStreamOptions {
|
|
4
4
|
signal?: AbortSignal;
|
|
5
5
|
/** Redis entry ID from the last applied delta/boundary. */
|
|
@@ -15,6 +15,7 @@ export interface ItemRef {
|
|
|
15
15
|
ordinal?: number | null;
|
|
16
16
|
response_group?: string | null;
|
|
17
17
|
failure?: Record<string, unknown> | null;
|
|
18
|
+
citations?: SessionStreamSchemas["Citation"][] | null;
|
|
18
19
|
/** Provisional automatic delivery evidence; committed Items retain the authoritative list. */
|
|
19
20
|
memory_sources?: SessionStreamSchemas["MemorySource"][] | null;
|
|
20
21
|
}
|
|
@@ -70,5 +71,5 @@ export declare function threadStream(open: (options: {
|
|
|
70
71
|
run: string;
|
|
71
72
|
position: string;
|
|
72
73
|
};
|
|
73
|
-
}) => Promise<
|
|
74
|
+
}) => Promise<BinaryBody>, shutdown: AbortSignal, options?: ThreadStreamOptions): AsyncGenerator<ThreadEvent>;
|
|
74
75
|
//# sourceMappingURL=thread-stream.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread-stream.d.ts","sourceRoot":"","sources":["../../src/streams/thread-stream.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAExE,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"thread-stream.d.ts","sourceRoot":"","sources":["../../src/streams/thread-stream.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAExE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAGvD,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,2DAA2D;IAC3D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wFAAwF;IACxF,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AACD,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,cAAc,GAAG,mBAAmB,GAAG,WAAW,GAAG,aAAa,CAAC;IACzE,KAAK,EAAE,aAAa,GAAG,WAAW,GAAG,aAAa,GAAG,QAAQ,CAAC;IAC9D,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACzC,SAAS,CAAC,EAAE,oBAAoB,CAAC,UAAU,CAAC,EAAE,GAAG,IAAI,CAAC;IACtD,8FAA8F;IAC9F,cAAc,CAAC,EAAE,oBAAoB,CAAC,cAAc,CAAC,EAAE,GAAG,IAAI,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,MAAM,EAAE,WAAW,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;CAC3C,KAAK,OAAO,CAAC,UAAU,CAAC,EACzB,QAAQ,EAAE,WAAW,EACrB,OAAO,GAAE,mBAAwB,GAChC,cAAc,CAAC,WAAW,CAAC,CAmE7B"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isA13nError, isRecord, UnexpectedResponseError } from "../errors.js";
|
|
2
2
|
import { delay } from "../transport.js";
|
|
3
3
|
import { decodeSse, TruncatedStreamError } from "./sse.js";
|
|
4
4
|
const cursorPattern = /^\d{1,20}-\d{1,20}$/;
|
|
@@ -22,16 +22,16 @@ function parseFrame(frame) {
|
|
|
22
22
|
value = JSON.parse(frame.data);
|
|
23
23
|
}
|
|
24
24
|
catch {
|
|
25
|
-
throw new
|
|
25
|
+
throw new UnexpectedResponseError("Invalid Thread frame JSON.");
|
|
26
26
|
}
|
|
27
27
|
if (!isRecord(value))
|
|
28
|
-
throw new
|
|
28
|
+
throw new UnexpectedResponseError("Invalid Thread frame data.");
|
|
29
29
|
if (frame.event === "delta" || frame.event === "boundary") {
|
|
30
30
|
if (!cursorPattern.test(frame.id) ||
|
|
31
31
|
!runSignal(value) ||
|
|
32
32
|
!natural(value.attempt) ||
|
|
33
33
|
!natural(value.sequence))
|
|
34
|
-
throw new
|
|
34
|
+
throw new UnexpectedResponseError("Invalid Thread output frame.");
|
|
35
35
|
if (frame.event === "delta") {
|
|
36
36
|
const item = value.item;
|
|
37
37
|
if (!isRecord(value.event) ||
|
|
@@ -40,7 +40,7 @@ function parseFrame(frame) {
|
|
|
40
40
|
typeof item.id === "string" &&
|
|
41
41
|
kinds.has(item.kind) &&
|
|
42
42
|
states.has(item.state))))
|
|
43
|
-
throw new
|
|
43
|
+
throw new UnexpectedResponseError("Invalid Thread delta.");
|
|
44
44
|
}
|
|
45
45
|
return {
|
|
46
46
|
cursor: frame.id,
|
|
@@ -48,7 +48,7 @@ function parseFrame(frame) {
|
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
50
|
if (frame.id)
|
|
51
|
-
throw new
|
|
51
|
+
throw new UnexpectedResponseError("A Thread signal must not advance the cursor.");
|
|
52
52
|
if (frame.event === "changed" && natural(value.version))
|
|
53
53
|
return {
|
|
54
54
|
cursor: null,
|
|
@@ -64,7 +64,7 @@ function parseFrame(frame) {
|
|
|
64
64
|
value.position !== null &&
|
|
65
65
|
!(typeof value.position === "string" &&
|
|
66
66
|
positionPattern.test(value.position)))
|
|
67
|
-
throw new
|
|
67
|
+
throw new UnexpectedResponseError("Invalid Thread gap position.");
|
|
68
68
|
return {
|
|
69
69
|
cursor: null,
|
|
70
70
|
frame: {
|
|
@@ -78,7 +78,7 @@ function parseFrame(frame) {
|
|
|
78
78
|
},
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
|
-
throw new
|
|
81
|
+
throw new UnexpectedResponseError("Unsupported Thread frame.");
|
|
82
82
|
}
|
|
83
83
|
/** Observe one thread. Signals require durable readback; neither stream delivery nor close changes execution. */
|
|
84
84
|
export async function* threadStream(open, shutdown, options = {}) {
|
|
@@ -110,7 +110,7 @@ export async function* threadStream(open, shutdown, options = {}) {
|
|
|
110
110
|
.get("Content-Type")
|
|
111
111
|
?.startsWith("text/event-stream") ||
|
|
112
112
|
!response.body) {
|
|
113
|
-
throw new
|
|
113
|
+
throw new UnexpectedResponseError("Expected a Thread event stream.");
|
|
114
114
|
}
|
|
115
115
|
for await (const raw of decodeSse(stream.body, signal)) {
|
|
116
116
|
signal.throwIfAborted();
|
|
@@ -128,9 +128,9 @@ export async function* threadStream(open, shutdown, options = {}) {
|
|
|
128
128
|
}
|
|
129
129
|
catch (error) {
|
|
130
130
|
if (signal.aborted ||
|
|
131
|
-
error
|
|
131
|
+
(isA13nError(error) && error.kind === "api_status") ||
|
|
132
132
|
// A truncated stream is a transport loss, retried like a network error.
|
|
133
|
-
(error instanceof
|
|
133
|
+
(error instanceof UnexpectedResponseError &&
|
|
134
134
|
!(error instanceof TruncatedStreamError)) ||
|
|
135
135
|
failures >= 2)
|
|
136
136
|
throw error;
|
|
@@ -139,7 +139,7 @@ export async function* threadStream(open, shutdown, options = {}) {
|
|
|
139
139
|
await stream?.close();
|
|
140
140
|
}
|
|
141
141
|
if (failures >= 2)
|
|
142
|
-
throw new
|
|
142
|
+
throw new UnexpectedResponseError("Thread stream closed without a stable connection.");
|
|
143
143
|
await delay(250 * 2 ** failures++, signal);
|
|
144
144
|
}
|
|
145
145
|
}
|