@converge.ai/a13n 0.0.3-rc.1 → 0.0.90

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.
Files changed (51) hide show
  1. package/README.md +110 -39
  2. package/dist/client.d.ts +15 -0
  3. package/dist/client.d.ts.map +1 -0
  4. package/dist/client.js +18 -0
  5. package/dist/client.js.map +1 -0
  6. package/dist/errors.d.ts +26 -0
  7. package/dist/errors.d.ts.map +1 -0
  8. package/dist/errors.js +56 -0
  9. package/dist/errors.js.map +1 -0
  10. package/dist/index.d.ts +12 -1
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +5 -2
  13. package/dist/index.js.map +1 -1
  14. package/dist/resources/base.d.ts +47 -0
  15. package/dist/resources/base.d.ts.map +1 -0
  16. package/dist/resources/base.js +220 -0
  17. package/dist/resources/base.js.map +1 -0
  18. package/dist/resources/generated.d.ts +4130 -0
  19. package/dist/resources/generated.d.ts.map +1 -0
  20. package/dist/resources/generated.js +3301 -0
  21. package/dist/resources/generated.js.map +1 -0
  22. package/dist/resources/interaction.d.ts +22 -0
  23. package/dist/resources/interaction.d.ts.map +1 -0
  24. package/dist/resources/interaction.js +54 -0
  25. package/dist/resources/interaction.js.map +1 -0
  26. package/dist/schema.d.ts +13660 -0
  27. package/dist/schema.d.ts.map +1 -0
  28. package/dist/schema.js +2 -0
  29. package/dist/schema.js.map +1 -0
  30. package/dist/semantic.d.ts +270 -0
  31. package/dist/semantic.d.ts.map +1 -0
  32. package/dist/semantic.js +331 -0
  33. package/dist/semantic.js.map +1 -0
  34. package/dist/streams/sse.d.ts +13 -0
  35. package/dist/streams/sse.d.ts.map +1 -0
  36. package/dist/streams/sse.js +92 -0
  37. package/dist/streams/sse.js.map +1 -0
  38. package/dist/streams/thread-stream.d.ts +55 -0
  39. package/dist/streams/thread-stream.d.ts.map +1 -0
  40. package/dist/streams/thread-stream.js +116 -0
  41. package/dist/streams/thread-stream.js.map +1 -0
  42. package/dist/transport.d.ts +35 -0
  43. package/dist/transport.d.ts.map +1 -0
  44. package/dist/transport.js +172 -0
  45. package/dist/transport.js.map +1 -0
  46. package/dist/workspace-scope.d.ts +2 -0
  47. package/dist/workspace-scope.d.ts.map +1 -0
  48. package/dist/workspace-scope.js +166 -0
  49. package/dist/workspace-scope.js.map +1 -0
  50. package/openapi.json +29533 -0
  51. package/package.json +18 -9
package/dist/schema.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":""}
@@ -0,0 +1,270 @@
1
+ import type { components } from "./schema.js";
2
+ import type { ServiceResources } from "./resources/generated.js";
3
+ import type { ResourceResult } from "./resources/base.js";
4
+ import { type WaitOptions } from "./resources/interaction.js";
5
+ import { type ThreadEvent } from "./streams/thread-stream.js";
6
+ type Schema = components["schemas"];
7
+ export type MessageInput = string | Schema["MessagePayload"];
8
+ /** New-Thread fields, including a one-time imported message_history seed. */
9
+ export type StartOptions = Omit<Schema["NewThread"], "agent_id" | "payload"> & {
10
+ idempotencyKey: string;
11
+ signal?: AbortSignal;
12
+ };
13
+ export type SendOptions = Omit<Schema["Message"], "agent_id" | "payload"> & {
14
+ idempotencyKey: string;
15
+ signal?: AbortSignal;
16
+ };
17
+ /** The Entry was settled without incorporation. Keep the safe IDs and original evidence. */
18
+ export declare class SubmissionDispositionError extends Error {
19
+ readonly snapshot: ResourceResult<Schema["EntryView"]>;
20
+ readonly name = "SubmissionDispositionError";
21
+ readonly threadId: string;
22
+ readonly entryId: string;
23
+ readonly status: "failed" | "withdrawn";
24
+ constructor(snapshot: ResourceResult<Schema["EntryView"]>);
25
+ }
26
+ /** Immutable projection of an authoritative exact-Run read, not an inferred stream result. */
27
+ export declare class RunOutcome {
28
+ readonly run: RunHandle;
29
+ readonly snapshot: ResourceResult<Schema["RunView"]>;
30
+ constructor(run: RunHandle, snapshot: ResourceResult<Schema["RunView"]>);
31
+ get status(): "failed" | "waiting" | "completed" | "running" | "cancelled" | "accepted";
32
+ get output(): unknown;
33
+ get pending(): {
34
+ approvals: components["schemas"]["PendingCall"][];
35
+ calls: components["schemas"]["PendingCall"][];
36
+ } | null;
37
+ get failure(): {
38
+ code: string;
39
+ message: string;
40
+ } | null;
41
+ }
42
+ export declare class RunHandle {
43
+ readonly id: string;
44
+ private readonly resources;
45
+ private readonly shutdown;
46
+ /** Original resume receipt when this handle was returned from resume(). */
47
+ readonly receipt?: ResourceResult<Schema["RunView"]> | undefined;
48
+ constructor(id: string, resources: ServiceResources, shutdown: AbortSignal,
49
+ /** Original resume receipt when this handle was returned from resume(). */
50
+ receipt?: ResourceResult<Schema["RunView"]> | undefined);
51
+ get(options?: {
52
+ signal?: AbortSignal;
53
+ }): Promise<ResourceResult<{
54
+ agent_id: string;
55
+ agent_revision_id: string;
56
+ attempts: number;
57
+ cancel_requested_at: string | null;
58
+ created_at: string;
59
+ current_attempt_id: string | null;
60
+ environment_mounts: components["schemas"]["EnvironmentMount"][];
61
+ failure: components["schemas"]["Failure"] | null;
62
+ id: string;
63
+ input?: {
64
+ [key: string]: components["schemas"]["JsonValue"];
65
+ } | null;
66
+ labels: {
67
+ [key: string]: string;
68
+ };
69
+ lineage: components["schemas"]["Lineage"];
70
+ max_attempts: number;
71
+ memory_mounts: components["schemas"]["MemoryMount"][];
72
+ options: components["schemas"]["RunOptions-Output"];
73
+ output: components["schemas"]["JsonValue"] | null;
74
+ parent_run_id: string | null;
75
+ pending: components["schemas"]["Pending"] | null;
76
+ principal_id: string;
77
+ resume: components["schemas"]["Resume"] | null;
78
+ resumed_by_id: string | null;
79
+ revision_selection: "pinned" | "default" | "inherited";
80
+ sealed_at: string | null;
81
+ session_id: string;
82
+ source_entry_id: string | null;
83
+ started_at: string | null;
84
+ status: components["schemas"]["RunStatus"];
85
+ thread_id: string;
86
+ trigger: components["schemas"]["Trigger"];
87
+ updated_at: string;
88
+ usage_at_seal: {
89
+ [key: string]: components["schemas"]["JsonValue"];
90
+ } | null;
91
+ version: number;
92
+ wait_reason: components["schemas"]["WaitReason"] | null;
93
+ workspace_id: string;
94
+ }>>;
95
+ /** Observe only this Run; waiting/failed/cancelled are distinct from completed. */
96
+ wait(options?: WaitOptions): Promise<RunOutcome>;
97
+ /** Committed Run Items; stream deltas are not a replacement for this readback. */
98
+ items(options?: {
99
+ signal?: AbortSignal;
100
+ }): Promise<ResourceResult<{
101
+ complete: boolean;
102
+ dropped: number;
103
+ items: components["schemas"]["Item"][];
104
+ position: string | null;
105
+ run: components["schemas"]["RunView"];
106
+ }>>;
107
+ interrupt(options?: {
108
+ signal?: AbortSignal;
109
+ }): Promise<ResourceResult<{
110
+ agent_id: string;
111
+ agent_revision_id: string;
112
+ attempts: number;
113
+ cancel_requested_at: string | null;
114
+ created_at: string;
115
+ current_attempt_id: string | null;
116
+ environment_mounts: components["schemas"]["EnvironmentMount"][];
117
+ failure: components["schemas"]["Failure"] | null;
118
+ id: string;
119
+ input?: {
120
+ [key: string]: components["schemas"]["JsonValue"];
121
+ } | null;
122
+ labels: {
123
+ [key: string]: string;
124
+ };
125
+ lineage: components["schemas"]["Lineage"];
126
+ max_attempts: number;
127
+ memory_mounts: components["schemas"]["MemoryMount"][];
128
+ options: components["schemas"]["RunOptions-Output"];
129
+ output: components["schemas"]["JsonValue"] | null;
130
+ parent_run_id: string | null;
131
+ pending: components["schemas"]["Pending"] | null;
132
+ principal_id: string;
133
+ resume: components["schemas"]["Resume"] | null;
134
+ resumed_by_id: string | null;
135
+ revision_selection: "pinned" | "default" | "inherited";
136
+ sealed_at: string | null;
137
+ session_id: string;
138
+ source_entry_id: string | null;
139
+ started_at: string | null;
140
+ status: components["schemas"]["RunStatus"];
141
+ thread_id: string;
142
+ trigger: components["schemas"]["Trigger"];
143
+ updated_at: string;
144
+ usage_at_seal: {
145
+ [key: string]: components["schemas"]["JsonValue"];
146
+ } | null;
147
+ version: number;
148
+ wait_reason: components["schemas"]["WaitReason"] | null;
149
+ workspace_id: string;
150
+ }>>;
151
+ /** Submit the complete pending results and optional input as one successor intent. */
152
+ resume(request: Schema["Resume"], options: {
153
+ idempotencyKey: string;
154
+ signal?: AbortSignal;
155
+ }): Promise<RunHandle>;
156
+ }
157
+ export declare class ThreadHandle {
158
+ readonly id: string;
159
+ private readonly resources;
160
+ constructor(id: string, resources: ServiceResources);
161
+ get(options?: {
162
+ signal?: AbortSignal;
163
+ }): Promise<ResourceResult<{
164
+ archived_at: string | null;
165
+ created_at: string;
166
+ current_run_id: string | null;
167
+ head_run_id: string | null;
168
+ id: string;
169
+ labels: {
170
+ [key: string]: string;
171
+ };
172
+ last_run_id: string | null;
173
+ mcp_headers: {
174
+ [key: string]: {
175
+ [key: string]: string;
176
+ };
177
+ };
178
+ message_history: components["schemas"]["MessageHistory"];
179
+ origin: "new" | "fork" | "child";
180
+ origin_run_id: string | null;
181
+ origin_thread_id: string | null;
182
+ origin_tool_call_id: string | null;
183
+ session_id: string;
184
+ subagent: string | null;
185
+ updated_at: string;
186
+ version: number;
187
+ workspace_id: string;
188
+ }>>;
189
+ entry(id: string): EntryHandle;
190
+ }
191
+ export declare class EntryHandle {
192
+ readonly id: string;
193
+ readonly threadId: string;
194
+ private readonly resources;
195
+ constructor(id: string, threadId: string, resources: ServiceResources);
196
+ get(options?: {
197
+ signal?: AbortSignal;
198
+ }): Promise<ResourceResult<{
199
+ agent_id: string | null;
200
+ agent_revision_id: string | null;
201
+ assigned_run_id: string | null;
202
+ child_run_id: string | null;
203
+ created_at: string;
204
+ delivery: components["schemas"]["Delivery"];
205
+ failure: components["schemas"]["Failure"] | null;
206
+ finished_at: string | null;
207
+ id: string;
208
+ incorporated_checkpoint_seq: number | null;
209
+ kind: "message" | "child_result";
210
+ options: components["schemas"]["RunOptions-Output"];
211
+ origin_run_id: string | null;
212
+ payload: {
213
+ [key: string]: components["schemas"]["JsonValue"];
214
+ };
215
+ position: number;
216
+ principal_id: string;
217
+ status: components["schemas"]["EntryStatus"];
218
+ thread_id: string;
219
+ }>>;
220
+ }
221
+ /** A finite, single-submission interaction. Its result is an exact committed Run read. */
222
+ export declare class Interaction implements AsyncIterable<ThreadEvent> {
223
+ private readonly interactionResources;
224
+ private readonly shutdown;
225
+ private readonly invocationSignal?;
226
+ readonly receipt: ResourceResult<Schema["Submitted"]>;
227
+ readonly thread: ThreadHandle;
228
+ readonly entry: EntryHandle;
229
+ readonly run: RunHandle | null;
230
+ private readonly observer;
231
+ private readonly observationAbort;
232
+ private outcomePromise?;
233
+ private boundPromise?;
234
+ private streamAbort?;
235
+ private closed;
236
+ private iterated;
237
+ constructor(receipt: ResourceResult<Schema["Submitted"]>, interactionResources: ServiceResources, shutdown: AbortSignal, invocationSignal?: AbortSignal | undefined);
238
+ /** Result-only usage does not open SSE. The first call fixes observation options. */
239
+ result(options?: WaitOptions): Promise<RunOutcome>;
240
+ /** Stop local observation and streaming; never interrupt the remote Run. */
241
+ close(): void;
242
+ [Symbol.asyncIterator](): AsyncGenerator<ThreadEvent>;
243
+ }
244
+ export declare class AgentHandle {
245
+ readonly id: string;
246
+ private readonly resources;
247
+ private readonly shutdown;
248
+ constructor(id: string, resources: ServiceResources, shutdown: AbortSignal);
249
+ start(input: MessageInput, options: StartOptions): Promise<Interaction>;
250
+ send(threadId: string, input: MessageInput, options: SendOptions): Promise<Interaction>;
251
+ }
252
+ export declare class AgentCollection {
253
+ private readonly resources;
254
+ private readonly shutdown;
255
+ constructor(resources: ServiceResources, shutdown: AbortSignal);
256
+ ref(id: string): AgentHandle;
257
+ }
258
+ export declare class ThreadCollection {
259
+ private readonly resources;
260
+ constructor(resources: ServiceResources);
261
+ ref(id: string): ThreadHandle;
262
+ }
263
+ export declare class RunCollection {
264
+ private readonly resources;
265
+ private readonly shutdown;
266
+ constructor(resources: ServiceResources, shutdown: AbortSignal);
267
+ ref(id: string): RunHandle;
268
+ }
269
+ export {};
270
+ //# sourceMappingURL=semantic.d.ts.map
@@ -0,0 +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,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAFhB,EAAE,EAAE,MAAM,EACF,SAAS,EAAE,gBAAgB,EAC3B,QAAQ,EAAE,WAAW;IAGlC,KAAK,CACT,KAAK,EAAE,YAAY,EACnB,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,WAAW,CAAC;IAajB,IAAI,CACR,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,YAAY,EACnB,OAAO,EAAE,WAAW,GACnB,OAAO,CAAC,WAAW,CAAC;CAcxB;AAED,qBAAa,eAAe;IAExB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBADR,SAAS,EAAE,gBAAgB,EAC3B,QAAQ,EAAE,WAAW;IAExC,GAAG,CAAC,EAAE,EAAE,MAAM;CAGf;AACD,qBAAa,gBAAgB;IACf,OAAO,CAAC,QAAQ,CAAC,SAAS;gBAAT,SAAS,EAAE,gBAAgB;IACxD,GAAG,CAAC,EAAE,EAAE,MAAM;CAGf;AACD,qBAAa,aAAa;IAEtB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBADR,SAAS,EAAE,gBAAgB,EAC3B,QAAQ,EAAE,WAAW;IAExC,GAAG,CAAC,EAAE,EAAE,MAAM;CAGf"}
@@ -0,0 +1,331 @@
1
+ import { ProtocolError } from "./errors.js";
2
+ import { observation, textPayload, waitForRun, } from "./resources/interaction.js";
3
+ import { abortable, delay } from "./transport.js";
4
+ import { threadStream } from "./streams/thread-stream.js";
5
+ /** The Entry was settled without incorporation. Keep the safe IDs and original evidence. */
6
+ export class SubmissionDispositionError extends Error {
7
+ snapshot;
8
+ name = "SubmissionDispositionError";
9
+ threadId;
10
+ entryId;
11
+ status;
12
+ constructor(snapshot) {
13
+ super(`Submission entry ${snapshot.data.id} was ${snapshot.data.status}.`);
14
+ this.snapshot = snapshot;
15
+ this.threadId = snapshot.data.thread_id;
16
+ this.entryId = snapshot.data.id;
17
+ this.status = snapshot.data.status;
18
+ }
19
+ }
20
+ /** Immutable projection of an authoritative exact-Run read, not an inferred stream result. */
21
+ export class RunOutcome {
22
+ run;
23
+ snapshot;
24
+ constructor(run, snapshot) {
25
+ this.run = run;
26
+ this.snapshot = snapshot;
27
+ }
28
+ get status() {
29
+ return this.snapshot.data.status;
30
+ }
31
+ get output() {
32
+ return this.snapshot.data.output;
33
+ }
34
+ get pending() {
35
+ return this.snapshot.data.pending;
36
+ }
37
+ get failure() {
38
+ return this.snapshot.data.failure;
39
+ }
40
+ }
41
+ export class RunHandle {
42
+ id;
43
+ resources;
44
+ shutdown;
45
+ receipt;
46
+ constructor(id, resources, shutdown,
47
+ /** Original resume receipt when this handle was returned from resume(). */
48
+ receipt) {
49
+ this.id = id;
50
+ this.resources = resources;
51
+ this.shutdown = shutdown;
52
+ this.receipt = receipt;
53
+ }
54
+ get(options = {}) {
55
+ return this.resources.runs.ref(this.id).get(options);
56
+ }
57
+ /** Observe only this Run; waiting/failed/cancelled are distinct from completed. */
58
+ async wait(options = {}) {
59
+ const snapshot = await waitForRun(async (request) => {
60
+ const result = await this.resources.runs.ref(this.id).get(request);
61
+ if (result.data.id !== this.id)
62
+ throw new ProtocolError("Service returned a different Run.");
63
+ return result;
64
+ }, this.shutdown, options);
65
+ return new RunOutcome(this, snapshot);
66
+ }
67
+ /** Committed Run Items; stream deltas are not a replacement for this readback. */
68
+ items(options = {}) {
69
+ return this.resources.runs.ref(this.id).items.get(options);
70
+ }
71
+ interrupt(options = {}) {
72
+ return this.resources.runs.ref(this.id).interrupt(options);
73
+ }
74
+ /** Submit the complete pending results and optional input as one successor intent. */
75
+ async resume(request, options) {
76
+ const receipt = await this.resources.runs
77
+ .ref(this.id)
78
+ .resume(request, options);
79
+ return new RunHandle(receipt.data.id, this.resources, this.shutdown, receipt);
80
+ }
81
+ }
82
+ export class ThreadHandle {
83
+ id;
84
+ resources;
85
+ constructor(id, resources) {
86
+ this.id = id;
87
+ this.resources = resources;
88
+ }
89
+ get(options = {}) {
90
+ return this.resources.threads.ref(this.id).get(options);
91
+ }
92
+ entry(id) {
93
+ return new EntryHandle(id, this.id, this.resources);
94
+ }
95
+ }
96
+ export class EntryHandle {
97
+ id;
98
+ threadId;
99
+ resources;
100
+ constructor(id, threadId, resources) {
101
+ this.id = id;
102
+ this.threadId = threadId;
103
+ this.resources = resources;
104
+ }
105
+ get(options = {}) {
106
+ return this.resources.threads
107
+ .ref(this.threadId)
108
+ .inbox.ref(this.id)
109
+ .get(options);
110
+ }
111
+ }
112
+ class SubmissionObserver {
113
+ receipt;
114
+ resources;
115
+ shutdown;
116
+ thread;
117
+ entry;
118
+ run;
119
+ constructor(receipt, resources, shutdown) {
120
+ this.receipt = receipt;
121
+ this.resources = resources;
122
+ this.shutdown = shutdown;
123
+ this.thread = new ThreadHandle(receipt.data.thread.id, resources);
124
+ this.entry = this.thread.entry(receipt.data.entry.id);
125
+ this.run = receipt.data.run
126
+ ? new RunHandle(receipt.data.run.id, resources, shutdown)
127
+ : null;
128
+ }
129
+ /** One observer owns both Entry incorporation and exact-Run termination. */
130
+ async wait(options = {}, onBound) {
131
+ const watch = observation(this.shutdown, options);
132
+ try {
133
+ while (true) {
134
+ watch.signal.throwIfAborted();
135
+ const entry = await abortable(this.entry.get({ signal: watch.signal }), watch.signal);
136
+ if (entry.data.id !== this.entry.id ||
137
+ entry.data.thread_id !== this.thread.id)
138
+ throw new ProtocolError("Service returned a different submission entry.");
139
+ if (entry.data.status === "failed" || entry.data.status === "withdrawn")
140
+ throw new SubmissionDispositionError(entry);
141
+ if (entry.data.status === "consumed") {
142
+ if (!entry.data.assigned_run_id)
143
+ throw new ProtocolError("Consumed submission has no incorporating Run ID.");
144
+ const run = new RunHandle(entry.data.assigned_run_id, this.resources, this.shutdown);
145
+ onBound?.(run);
146
+ while (true) {
147
+ watch.signal.throwIfAborted();
148
+ const snapshot = await abortable(run.get({ signal: watch.signal }), watch.signal);
149
+ if (snapshot.data.id !== run.id ||
150
+ snapshot.data.thread_id !== this.thread.id)
151
+ throw new ProtocolError("Service returned a different incorporating Run.");
152
+ if (["completed", "waiting", "failed", "cancelled"].includes(snapshot.data.status)) {
153
+ watch.signal.throwIfAborted();
154
+ return new RunOutcome(run, snapshot);
155
+ }
156
+ await delay(watch.pollIntervalMs, watch.signal);
157
+ }
158
+ }
159
+ // An assigned entry can return to pending at a seal; neither is incorporation.
160
+ await delay(watch.pollIntervalMs, watch.signal);
161
+ }
162
+ }
163
+ catch (error) {
164
+ if (watch.signal.aborted)
165
+ throw watch.signal.reason;
166
+ throw error;
167
+ }
168
+ finally {
169
+ watch.close();
170
+ }
171
+ }
172
+ }
173
+ /** A finite, single-submission interaction. Its result is an exact committed Run read. */
174
+ export class Interaction {
175
+ interactionResources;
176
+ shutdown;
177
+ invocationSignal;
178
+ receipt;
179
+ thread;
180
+ entry;
181
+ run;
182
+ observer;
183
+ observationAbort = new AbortController();
184
+ outcomePromise;
185
+ boundPromise;
186
+ streamAbort;
187
+ closed = false;
188
+ iterated = false;
189
+ constructor(receipt, interactionResources, shutdown, invocationSignal) {
190
+ this.interactionResources = interactionResources;
191
+ this.shutdown = shutdown;
192
+ this.invocationSignal = invocationSignal;
193
+ this.observer = new SubmissionObserver(receipt, interactionResources, shutdown);
194
+ this.receipt = receipt;
195
+ this.thread = this.observer.thread;
196
+ this.entry = this.observer.entry;
197
+ this.run = this.observer.run;
198
+ }
199
+ /** Result-only usage does not open SSE. The first call fixes observation options. */
200
+ result(options = {}) {
201
+ if (this.outcomePromise) {
202
+ if (Object.keys(options).length)
203
+ throw new TypeError("The interaction observation has already started; set options on its first result() call.");
204
+ return this.outcomePromise;
205
+ }
206
+ if (this.closed)
207
+ return Promise.reject(this.observationAbort.signal.reason);
208
+ let resolveBound;
209
+ let rejectBound;
210
+ this.boundPromise = new Promise((resolve, reject) => {
211
+ resolveBound = resolve;
212
+ rejectBound = reject;
213
+ });
214
+ // Result-only callers never await the binding promise.
215
+ void this.boundPromise.catch(() => undefined);
216
+ const signal = AbortSignal.any([
217
+ this.observationAbort.signal,
218
+ ...(this.invocationSignal ? [this.invocationSignal] : []),
219
+ ...(options.signal ? [options.signal] : []),
220
+ ]);
221
+ this.outcomePromise = this.observer.wait({ ...options, signal }, resolveBound);
222
+ void this.outcomePromise.catch(rejectBound);
223
+ return this.outcomePromise;
224
+ }
225
+ /** Stop local observation and streaming; never interrupt the remote Run. */
226
+ close() {
227
+ if (this.closed)
228
+ return;
229
+ this.closed = true;
230
+ const reason = new DOMException("Interaction closed.", "AbortError");
231
+ this.observationAbort.abort(reason);
232
+ this.streamAbort?.abort(reason);
233
+ }
234
+ async *[Symbol.asyncIterator]() {
235
+ if (this.iterated)
236
+ throw new TypeError("An interaction may be iterated only once.");
237
+ this.iterated = true;
238
+ if (this.closed)
239
+ return;
240
+ const outcome = this.result();
241
+ const run = await this.boundPromise;
242
+ if (this.closed)
243
+ return;
244
+ const streamAbort = new AbortController();
245
+ this.streamAbort = streamAbort;
246
+ // One completion reaction, independent of how many frames the consumer pulls.
247
+ void outcome.then(() => streamAbort.abort(), () => streamAbort.abort());
248
+ const stream = threadStream((options) => this.interactionResources.threads
249
+ .ref(this.thread.id)
250
+ .stream.get(options), this.shutdown, { signal: streamAbort.signal });
251
+ try {
252
+ for await (const event of stream) {
253
+ if (event.frame.type === "changed")
254
+ continue;
255
+ if (event.frame.data.run_id === run.id)
256
+ yield event;
257
+ }
258
+ }
259
+ catch (error) {
260
+ if (!streamAbort.signal.aborted)
261
+ throw error;
262
+ await outcome;
263
+ }
264
+ finally {
265
+ this.close();
266
+ }
267
+ await outcome;
268
+ }
269
+ }
270
+ export class AgentHandle {
271
+ id;
272
+ resources;
273
+ shutdown;
274
+ constructor(id, resources, shutdown) {
275
+ this.id = id;
276
+ this.resources = resources;
277
+ this.shutdown = shutdown;
278
+ }
279
+ async start(input, options) {
280
+ const { idempotencyKey, signal, ...fields } = options;
281
+ const receipt = await this.resources.threads.create({
282
+ ...fields,
283
+ agent_id: this.id,
284
+ payload: typeof input === "string" ? textPayload(input) : input,
285
+ }, { idempotencyKey, ...(signal ? { signal } : {}) });
286
+ return new Interaction(receipt, this.resources, this.shutdown, signal);
287
+ }
288
+ async send(threadId, input, options) {
289
+ const { idempotencyKey, signal, ...fields } = options;
290
+ const receipt = await this.resources.threads.ref(threadId).inbox.create({
291
+ ...fields,
292
+ agent_id: this.id,
293
+ payload: typeof input === "string" ? textPayload(input) : input,
294
+ }, { idempotencyKey, ...(signal ? { signal } : {}) });
295
+ if (receipt.data.thread.id !== threadId)
296
+ throw new ProtocolError("Service submitted to another Thread.");
297
+ return new Interaction(receipt, this.resources, this.shutdown, signal);
298
+ }
299
+ }
300
+ export class AgentCollection {
301
+ resources;
302
+ shutdown;
303
+ constructor(resources, shutdown) {
304
+ this.resources = resources;
305
+ this.shutdown = shutdown;
306
+ }
307
+ ref(id) {
308
+ return new AgentHandle(id, this.resources, this.shutdown);
309
+ }
310
+ }
311
+ export class ThreadCollection {
312
+ resources;
313
+ constructor(resources) {
314
+ this.resources = resources;
315
+ }
316
+ ref(id) {
317
+ return new ThreadHandle(id, this.resources);
318
+ }
319
+ }
320
+ export class RunCollection {
321
+ resources;
322
+ shutdown;
323
+ constructor(resources, shutdown) {
324
+ this.resources = resources;
325
+ this.shutdown = shutdown;
326
+ }
327
+ ref(id) {
328
+ return new RunHandle(id, this.resources, this.shutdown);
329
+ }
330
+ }
331
+ //# sourceMappingURL=semantic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"semantic.js","sourceRoot":"","sources":["../src/semantic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAI5C,OAAO,EACL,WAAW,EACX,WAAW,EACX,UAAU,GAEX,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAo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BAAgB;IACE;IAA7B,YAA6B,SAA2B;QAA3B,cAAS,GAAT,SAAS,CAAkB;IAAG,CAAC;IAC5D,GAAG,CAAC,EAAU;QACZ,OAAO,IAAI,YAAY,CAAC,EAAE,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IAC9C,CAAC;CACF;AACD,MAAM,OAAO,aAAa;IAEL;IACA;IAFnB,YACmB,SAA2B,EAC3B,QAAqB;QADrB,cAAS,GAAT,SAAS,CAAkB;QAC3B,aAAQ,GAAR,QAAQ,CAAa;IACrC,CAAC;IACJ,GAAG,CAAC,EAAU;QACZ,OAAO,IAAI,SAAS,CAAC,EAAE,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC1D,CAAC;CACF"}
@@ -0,0 +1,13 @@
1
+ export interface SseFrame {
2
+ id: string;
3
+ event: string;
4
+ data: string;
5
+ }
6
+ export interface DetailedSseFrame extends SseFrame {
7
+ idPresent: boolean;
8
+ }
9
+ /** Decode incremental UTF-8 and LF/CRLF/CR framing, including split delimiters. */
10
+ export declare function decodeSse(body: ReadableStream<Uint8Array>, signal?: AbortSignal): AsyncGenerator<SseFrame>;
11
+ /** Internal framing details retain whether this event carried an explicit id field. */
12
+ export declare function decodeSseDetailed(body: ReadableStream<Uint8Array>, signal?: AbortSignal): AsyncGenerator<DetailedSseFrame>;
13
+ //# sourceMappingURL=sse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../src/streams/sse.ts"],"names":[],"mappings":"AAEA,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,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,GACnB,cAAc,CAAC,gBAAgB,CAAC,CAgFlC"}