@loomwork/conversation 0.0.0-stage → 0.1.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.
Files changed (83) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +8 -0
  3. package/README.md +117 -2
  4. package/dist/access.d.ts +59 -0
  5. package/dist/access.d.ts.map +1 -0
  6. package/dist/access.js +178 -0
  7. package/dist/access.js.map +1 -0
  8. package/dist/bargeIn.d.ts +62 -0
  9. package/dist/bargeIn.d.ts.map +1 -0
  10. package/dist/bargeIn.js +110 -0
  11. package/dist/bargeIn.js.map +1 -0
  12. package/dist/budget.d.ts +82 -0
  13. package/dist/budget.d.ts.map +1 -0
  14. package/dist/budget.js +134 -0
  15. package/dist/budget.js.map +1 -0
  16. package/dist/conversation.d.ts +59 -0
  17. package/dist/conversation.d.ts.map +1 -0
  18. package/dist/conversation.js +786 -0
  19. package/dist/conversation.js.map +1 -0
  20. package/dist/conversations.d.ts +149 -0
  21. package/dist/conversations.d.ts.map +1 -0
  22. package/dist/conversations.js +498 -0
  23. package/dist/conversations.js.map +1 -0
  24. package/dist/feed.d.ts +32 -0
  25. package/dist/feed.d.ts.map +1 -0
  26. package/dist/feed.js +83 -0
  27. package/dist/feed.js.map +1 -0
  28. package/dist/hub.d.ts +119 -0
  29. package/dist/hub.d.ts.map +1 -0
  30. package/dist/hub.js +257 -0
  31. package/dist/hub.js.map +1 -0
  32. package/dist/ids.d.ts +9 -0
  33. package/dist/ids.d.ts.map +1 -0
  34. package/dist/ids.js +29 -0
  35. package/dist/ids.js.map +1 -0
  36. package/dist/index.d.ts +27 -0
  37. package/dist/index.d.ts.map +1 -0
  38. package/dist/index.js +65 -0
  39. package/dist/index.js.map +1 -0
  40. package/dist/providerError.d.ts +10 -0
  41. package/dist/providerError.d.ts.map +1 -0
  42. package/dist/providerError.js +16 -0
  43. package/dist/providerError.js.map +1 -0
  44. package/dist/reader.d.ts +53 -0
  45. package/dist/reader.d.ts.map +1 -0
  46. package/dist/reader.js +217 -0
  47. package/dist/reader.js.map +1 -0
  48. package/dist/settled.d.ts +49 -0
  49. package/dist/settled.d.ts.map +1 -0
  50. package/dist/settled.js +51 -0
  51. package/dist/settled.js.map +1 -0
  52. package/dist/signEnvelope.d.ts +51 -0
  53. package/dist/signEnvelope.d.ts.map +1 -0
  54. package/dist/signEnvelope.js +55 -0
  55. package/dist/signEnvelope.js.map +1 -0
  56. package/dist/summarizerText.d.ts +2 -0
  57. package/dist/summarizerText.d.ts.map +1 -0
  58. package/dist/summarizerText.js +9 -0
  59. package/dist/summarizerText.js.map +1 -0
  60. package/dist/turn.d.ts +67 -0
  61. package/dist/turn.d.ts.map +1 -0
  62. package/dist/turn.js +213 -0
  63. package/dist/turn.js.map +1 -0
  64. package/dist/types.d.ts +267 -0
  65. package/dist/types.d.ts.map +1 -0
  66. package/dist/types.js +18 -0
  67. package/dist/types.js.map +1 -0
  68. package/package.json +61 -3
  69. package/src/access.ts +221 -0
  70. package/src/bargeIn.ts +172 -0
  71. package/src/budget.ts +170 -0
  72. package/src/conversation.ts +961 -0
  73. package/src/conversations.ts +690 -0
  74. package/src/feed.ts +112 -0
  75. package/src/hub.ts +336 -0
  76. package/src/ids.ts +25 -0
  77. package/src/index.ts +75 -0
  78. package/src/reader.ts +274 -0
  79. package/src/settled.ts +80 -0
  80. package/src/signEnvelope.ts +76 -0
  81. package/src/summarizerText.ts +3 -0
  82. package/src/turn.ts +344 -0
  83. package/src/types.ts +271 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feed.js","sourceRoot":"","sources":["../src/feed.ts"],"names":[],"mappings":";;AAsCA,gDAyEC;AA9GD,+BAAqC;AACrC,qCAAgE;AA+BhE;;;;GAIG;AACI,KAAK,SAAS,CAAC,CAAC,kBAAkB,CACvC,IAAgB,EAChB,cAAsB,EACtB,UAAyB,EAAE;IAE3B,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;IACpC,MAAM,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AC,CAAC,CAAC;YAC3C,CAAC;YACD,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;gBACzB,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;gBACzB,OAAO;YACT,CAAC;YACD,IAAI,CAAC,IAAI,CAAC,IAAI;gBAAE,SAAS,CAAC,0BAA0B;YACpD,MAAM,IAAI,EAAE,CAAC;QACf,CAAC;IACH,CAAC;YAAS,CAAC;QACT,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,MAAM,EAAE;YAAE,GAAG,EAAE,CAAC;IACzC,CAAC;AACH,CAAC"}
package/dist/hub.d.ts ADDED
@@ -0,0 +1,119 @@
1
+ import { type TaintedValue } from "@loomwork/classify";
2
+ import type { LlmProvider } from "@loomwork/llm";
3
+ /** A live event for a conversation. Deltas and resets only: everything durable comes from the log. */
4
+ export type LiveEvent = {
5
+ type: "delta";
6
+ conversationId: string;
7
+ turn: number;
8
+ text: string;
9
+ asker?: string;
10
+ }
11
+ /**
12
+ * ADR 0133 D6 - a readable reasoning increment of the turn's model call. A channel of its own, so no
13
+ * consumer of reply text sees it by accident; a transport serves it to the turn's ASKER and the conversation's OWNER only (`asker`
14
+ * is always set in shared mode) and only when the host opted in.
15
+ */
16
+ | {
17
+ type: "reasoning";
18
+ conversationId: string;
19
+ turn: number;
20
+ text: string;
21
+ asker?: string;
22
+ }
23
+ /** The turn's stream restarted from zero (a crash-recovered re-run asked the model again): discard the partial. */
24
+ | {
25
+ type: "reset";
26
+ conversationId: string;
27
+ turn: number;
28
+ asker?: string;
29
+ };
30
+ /** Run `fn` as the body of `turn` of `conversationId`: model deltas produced inside it are attributed to it. */
31
+ export declare function withTurnScope<T>(conversationId: string, turn: number, signal: AbortSignal, fn: () => T, ensure?: () => Promise<unknown>, asker?: string): T;
32
+ /** Maximum live subscribers per conversation. A further subscribe is refused (the caller answers 429). */
33
+ export declare const DEFAULT_MAX_SUBSCRIBERS = 64;
34
+ export declare class SubscriberLimitError extends Error {
35
+ readonly code = "SUBSCRIBER_LIMIT";
36
+ constructor(conversationId: string, limit: number);
37
+ }
38
+ export interface ConversationHubOptions {
39
+ /** Live subscribers allowed per conversation. Default {@link DEFAULT_MAX_SUBSCRIBERS}. */
40
+ maxSubscribersPerConversation?: number;
41
+ /**
42
+ * Characters of the in-progress reply kept per conversation so a subscriber that attaches (or
43
+ * reconnects) mid-stream can be caught up with {@link ConversationHub.partialOf}. 0 disables it.
44
+ * Default 65 536; beyond it the head of the partial is dropped (the catch-up is a convenience, the
45
+ * durable reply is the record).
46
+ */
47
+ maxPartialChars?: number;
48
+ }
49
+ /** The reasoning a conversation's model call has streamed so far (ADR 0133 D6). Same bound and lifetime as {@link PartialReply}. */
50
+ export interface PartialReasoning {
51
+ turn: number;
52
+ text: string;
53
+ /** Shared mode: whose turn it is. For that viewer alone, always. */
54
+ asker?: string;
55
+ }
56
+ /** The reply a conversation is streaming right now. */
57
+ export interface PartialReply {
58
+ turn: number;
59
+ text: string;
60
+ /** Shared mode: whose turn it is. The partial is for that viewer alone until the turn is classified. */
61
+ asker?: string;
62
+ }
63
+ export declare class ConversationHub {
64
+ private readonly subs;
65
+ /** The reply each conversation is streaming: also what tells a RE-RUN of a turn (a different run) from its continuation. Bounded to live turns. */
66
+ private readonly partials;
67
+ private readonly max;
68
+ private readonly maxPartial;
69
+ constructor(options?: ConversationHubOptions);
70
+ /**
71
+ * Attach a listener to ONE conversation. Events of other conversations are never delivered to it
72
+ * (the map is keyed by id; there is no wildcard). A throwing listener is isolated.
73
+ */
74
+ subscribe(conversationId: string, listener: (event: LiveEvent) => void): () => void;
75
+ subscriberCount(conversationId: string): number;
76
+ /** What the conversation has streamed of the reply in progress, if one is. Read it right after {@link subscribe}. */
77
+ partialOf(conversationId: string): PartialReply | undefined;
78
+ /** What the turn's model call has streamed of its reasoning, if any. Read it right after {@link subscribe}. */
79
+ reasoningPartialOf(conversationId: string): PartialReasoning | undefined;
80
+ publish(conversationId: string, event: LiveEvent): void;
81
+ /** The turn's reply is durable: forget its stream bookkeeping. */
82
+ endTurn(conversationId: string, turn: number): void;
83
+ /**
84
+ * Wrap a provider so a barge-in CUTS the generation. The turn's abort signal (set by
85
+ * `conversation$` in the turn scope) is merged into every request's `signal`, so a streaming
86
+ * provider stops at the next chunk and its partial text is captured (`LLM_INTERRUPTED`); a
87
+ * request outside a turn scope is passed through untouched. Register the wrapped provider:
88
+ * `createAgentModelEffect(hub.wrapProvider(provider), { stream: true, onDelta: hub.deltaSink() })`.
89
+ * Without it a barge-in still lands, but only at the next checkpoint after the model call returns.
90
+ */
91
+ wrapProvider(provider: LlmProvider): LlmProvider;
92
+ /**
93
+ * The `onDelta` to register on the model effect:
94
+ * `createAgentModelEffect(provider, { stream: true, onDelta: hub.deltaSink() })`.
95
+ *
96
+ * It attributes each delta to the conversation turn whose body is running the call (an
97
+ * AsyncLocalStorage scope set by `conversation$`), so ONE shared effect serves every
98
+ * conversation without crossing their streams. A delta outside any turn scope (a call that did not
99
+ * come from a conversation, or an effect running in another process) has no conversation and is
100
+ * dropped, never broadcast. No subscriber means no work.
101
+ */
102
+ deltaSink(): (delta: string) => void;
103
+ /**
104
+ * ADR 0133 D6 - the live reasoning sink, for the model effect's reasoning option:
105
+ * `createAgentModelEffect(provider, { reasoning: { store, live: true, onDelta: hub.reasoningSink() } })`.
106
+ * Attributed to the turn exactly as {@link deltaSink} is, kept in a bounded in-progress buffer (the
107
+ * same cap as the reply, head dropped) and published as `reasoning` events. This is the transport
108
+ * edge: the increment arrives wrapped as untrusted content and is unwrapped HERE, into the buffer and
109
+ * the event, which a transport must serve to the turn's asker and the conversation's owner alone.
110
+ */
111
+ reasoningSink(): (delta: TaintedValue<string>) => void;
112
+ /**
113
+ * The in-progress entry of the running turn, created on its first delta. A different RUN of the same
114
+ * turn (a crash-recovered process asked the model again) supersedes it - text AND reasoning - with ONE
115
+ * `reset`, whichever channel notices first.
116
+ */
117
+ private partialFor;
118
+ }
119
+ //# sourceMappingURL=hub.d.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IACH,SAAS,IAAI,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI;IAoBpC;;;;;;;OAOG;IACH,aAAa,IAAI,CAAC,KAAK,EAAE,YAAY,CAAC,MAAM,CAAC,KAAK,IAAI;IAqBtD;;;;OAIG;IACH,OAAO,CAAC,UAAU;CA2BnB"}
package/dist/hub.js ADDED
@@ -0,0 +1,257 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConversationHub = exports.SubscriberLimitError = exports.DEFAULT_MAX_SUBSCRIBERS = void 0;
4
+ exports.withTurnScope = withTurnScope;
5
+ const node_async_hooks_1 = require("node:async_hooks");
6
+ const classify_1 = require("@loomwork/classify");
7
+ const core_1 = require("@loomwork/core");
8
+ const llm_1 = require("@loomwork/llm");
9
+ const scope = new node_async_hooks_1.AsyncLocalStorage();
10
+ let runCounter = 0;
11
+ /** Run `fn` as the body of `turn` of `conversationId`: model deltas produced inside it are attributed to it. */
12
+ function withTurnScope(conversationId, turn, signal, fn, ensure, asker) {
13
+ return scope.run({
14
+ conversationId,
15
+ turn,
16
+ run: ++runCounter,
17
+ signal,
18
+ ...(ensure !== undefined && { ensure }),
19
+ ...(asker !== undefined && { asker }),
20
+ }, fn);
21
+ }
22
+ /** The request with the running turn's barge-in signal merged into its own, if there is a turn. */
23
+ function withTurnSignal(request) {
24
+ const turn = scope.getStore()?.signal;
25
+ if (turn === undefined)
26
+ return request;
27
+ return {
28
+ ...request,
29
+ signal: request.signal === undefined ? turn : AbortSignal.any([request.signal, turn]),
30
+ };
31
+ }
32
+ /** Maximum live subscribers per conversation. A further subscribe is refused (the caller answers 429). */
33
+ exports.DEFAULT_MAX_SUBSCRIBERS = 64;
34
+ const MAX_TRACKED_TURNS = 1024;
35
+ class SubscriberLimitError extends Error {
36
+ code = "SUBSCRIBER_LIMIT";
37
+ constructor(conversationId, limit) {
38
+ super(`conversation "${conversationId}" already has ${limit} live subscribers`);
39
+ this.name = "SubscriberLimitError";
40
+ }
41
+ }
42
+ exports.SubscriberLimitError = SubscriberLimitError;
43
+ class ConversationHub {
44
+ subs = new Map();
45
+ /** The reply each conversation is streaming: also what tells a RE-RUN of a turn (a different run) from its continuation. Bounded to live turns. */
46
+ partials = new Map();
47
+ max;
48
+ maxPartial;
49
+ constructor(options = {}) {
50
+ this.max = options.maxSubscribersPerConversation ?? exports.DEFAULT_MAX_SUBSCRIBERS;
51
+ this.maxPartial = options.maxPartialChars ?? 65_536;
52
+ }
53
+ /**
54
+ * Attach a listener to ONE conversation. Events of other conversations are never delivered to it
55
+ * (the map is keyed by id; there is no wildcard). A throwing listener is isolated.
56
+ */
57
+ subscribe(conversationId, listener) {
58
+ let set = this.subs.get(conversationId);
59
+ if (set === undefined) {
60
+ set = new Set();
61
+ this.subs.set(conversationId, set);
62
+ }
63
+ if (set.size >= this.max)
64
+ throw new SubscriberLimitError(conversationId, this.max);
65
+ set.add(listener);
66
+ return () => {
67
+ const cur = this.subs.get(conversationId);
68
+ if (cur === undefined)
69
+ return;
70
+ cur.delete(listener);
71
+ if (cur.size === 0)
72
+ this.subs.delete(conversationId);
73
+ };
74
+ }
75
+ subscriberCount(conversationId) {
76
+ return this.subs.get(conversationId)?.size ?? 0;
77
+ }
78
+ /** What the conversation has streamed of the reply in progress, if one is. Read it right after {@link subscribe}. */
79
+ partialOf(conversationId) {
80
+ const p = this.partials.get(conversationId);
81
+ return p === undefined || p.text === ""
82
+ ? undefined
83
+ : { turn: p.turn, text: p.text, ...(p.asker !== undefined && { asker: p.asker }) };
84
+ }
85
+ /** What the turn's model call has streamed of its reasoning, if any. Read it right after {@link subscribe}. */
86
+ reasoningPartialOf(conversationId) {
87
+ const p = this.partials.get(conversationId);
88
+ return p === undefined || p.reasoning === ""
89
+ ? undefined
90
+ : { turn: p.turn, text: p.reasoning, ...(p.asker !== undefined && { asker: p.asker }) };
91
+ }
92
+ publish(conversationId, event) {
93
+ const set = this.subs.get(conversationId);
94
+ if (set === undefined)
95
+ return;
96
+ for (const listener of [...set]) {
97
+ try {
98
+ listener(event);
99
+ }
100
+ catch {
101
+ // a listener cannot hurt the turn
102
+ }
103
+ }
104
+ }
105
+ /** The turn's reply is durable: forget its stream bookkeeping. */
106
+ endTurn(conversationId, turn) {
107
+ if (this.partials.get(conversationId)?.turn === turn)
108
+ this.partials.delete(conversationId);
109
+ }
110
+ /**
111
+ * Wrap a provider so a barge-in CUTS the generation. The turn's abort signal (set by
112
+ * `conversation$` in the turn scope) is merged into every request's `signal`, so a streaming
113
+ * provider stops at the next chunk and its partial text is captured (`LLM_INTERRUPTED`); a
114
+ * request outside a turn scope is passed through untouched. Register the wrapped provider:
115
+ * `createAgentModelEffect(hub.wrapProvider(provider), { stream: true, onDelta: hub.deltaSink() })`.
116
+ * Without it a barge-in still lands, but only at the next checkpoint after the model call returns.
117
+ */
118
+ wrapProvider(provider) {
119
+ /** A barge-in landed on THIS request (as opposed to a caller's own abort or a transport failure). */
120
+ const bargedIn = (request) => scope.getStore()?.signal.aborted === true && request.signal?.aborted !== true;
121
+ const wrapped = {
122
+ ...(provider.capabilities !== undefined && { capabilities: provider.capabilities }),
123
+ complete: async (request) => {
124
+ try {
125
+ await scope.getStore()?.ensure?.();
126
+ return await provider.complete(withTurnSignal(request));
127
+ }
128
+ catch (err) {
129
+ if (bargedIn(request))
130
+ (0, core_1.fail)(llm_1.LLM_INTERRUPTED, { content: "" }, "generation interrupted");
131
+ throw err;
132
+ }
133
+ },
134
+ };
135
+ if (provider.stream !== undefined) {
136
+ const stream = provider.stream.bind(provider);
137
+ // The kernel's own capture of a partial (`collectStream`) watches the EFFECT's signal, which a
138
+ // barge-in does not touch; so the wrapper accumulates what it forwards and raises the typed
139
+ // interruption itself, whether the provider honoured the signal or kept on yielding.
140
+ wrapped.stream = async function* (request) {
141
+ const turn = scope.getStore()?.signal;
142
+ let text = "";
143
+ try {
144
+ await scope.getStore()?.ensure?.();
145
+ for await (const chunk of stream(withTurnSignal(request))) {
146
+ if (turn?.aborted === true && request.signal?.aborted !== true) {
147
+ (0, core_1.fail)(llm_1.LLM_INTERRUPTED, { content: text }, "generation interrupted");
148
+ }
149
+ text += chunk.delta;
150
+ yield chunk;
151
+ }
152
+ }
153
+ catch (err) {
154
+ if (bargedIn(request))
155
+ (0, core_1.fail)(llm_1.LLM_INTERRUPTED, { content: text }, "generation interrupted");
156
+ throw err;
157
+ }
158
+ };
159
+ }
160
+ return wrapped;
161
+ }
162
+ /**
163
+ * The `onDelta` to register on the model effect:
164
+ * `createAgentModelEffect(provider, { stream: true, onDelta: hub.deltaSink() })`.
165
+ *
166
+ * It attributes each delta to the conversation turn whose body is running the call (an
167
+ * AsyncLocalStorage scope set by `conversation$`), so ONE shared effect serves every
168
+ * conversation without crossing their streams. A delta outside any turn scope (a call that did not
169
+ * come from a conversation, or an effect running in another process) has no conversation and is
170
+ * dropped, never broadcast. No subscriber means no work.
171
+ */
172
+ deltaSink() {
173
+ return (delta) => {
174
+ const s = scope.getStore();
175
+ if (s === undefined || delta === "")
176
+ return;
177
+ const part = this.partialFor(s);
178
+ if (this.maxPartial > 0) {
179
+ const text = part.text + delta;
180
+ part.text =
181
+ text.length > this.maxPartial ? text.slice(text.length - this.maxPartial) : text;
182
+ }
183
+ this.publish(s.conversationId, {
184
+ type: "delta",
185
+ conversationId: s.conversationId,
186
+ turn: s.turn,
187
+ text: delta,
188
+ ...(s.asker !== undefined && { asker: s.asker }),
189
+ });
190
+ };
191
+ }
192
+ /**
193
+ * ADR 0133 D6 - the live reasoning sink, for the model effect's reasoning option:
194
+ * `createAgentModelEffect(provider, { reasoning: { store, live: true, onDelta: hub.reasoningSink() } })`.
195
+ * Attributed to the turn exactly as {@link deltaSink} is, kept in a bounded in-progress buffer (the
196
+ * same cap as the reply, head dropped) and published as `reasoning` events. This is the transport
197
+ * edge: the increment arrives wrapped as untrusted content and is unwrapped HERE, into the buffer and
198
+ * the event, which a transport must serve to the turn's asker and the conversation's owner alone.
199
+ */
200
+ reasoningSink() {
201
+ return (wrapped) => {
202
+ const s = scope.getStore();
203
+ const delta = (0, classify_1.unwrapTainted)(wrapped);
204
+ if (s === undefined || delta === "")
205
+ return;
206
+ const part = this.partialFor(s);
207
+ if (this.maxPartial > 0) {
208
+ const text = part.reasoning + delta;
209
+ part.reasoning =
210
+ text.length > this.maxPartial ? text.slice(text.length - this.maxPartial) : text;
211
+ }
212
+ this.publish(s.conversationId, {
213
+ type: "reasoning",
214
+ conversationId: s.conversationId,
215
+ turn: s.turn,
216
+ text: delta,
217
+ ...(s.asker !== undefined && { asker: s.asker }),
218
+ });
219
+ };
220
+ }
221
+ /**
222
+ * The in-progress entry of the running turn, created on its first delta. A different RUN of the same
223
+ * turn (a crash-recovered process asked the model again) supersedes it - text AND reasoning - with ONE
224
+ * `reset`, whichever channel notices first.
225
+ */
226
+ partialFor(s) {
227
+ const cur = this.partials.get(s.conversationId);
228
+ if (cur !== undefined && cur.turn === s.turn && cur.run === s.run)
229
+ return cur;
230
+ if (cur !== undefined && cur.turn === s.turn) {
231
+ // The same turn, a different run: a crash-recovered process asked the model again.
232
+ this.publish(s.conversationId, {
233
+ type: "reset",
234
+ conversationId: s.conversationId,
235
+ turn: s.turn,
236
+ ...(s.asker !== undefined && { asker: s.asker }),
237
+ });
238
+ }
239
+ if (cur === undefined && this.partials.size >= MAX_TRACKED_TURNS) {
240
+ // Bounded: a turn that finished in another process never calls `endTurn` here.
241
+ const oldest = this.partials.keys().next().value;
242
+ if (oldest !== undefined)
243
+ this.partials.delete(oldest);
244
+ }
245
+ const part = {
246
+ turn: s.turn,
247
+ run: s.run,
248
+ text: "",
249
+ reasoning: "",
250
+ ...(s.asker !== undefined && { asker: s.asker }),
251
+ };
252
+ this.partials.set(s.conversationId, part);
253
+ return part;
254
+ }
255
+ }
256
+ exports.ConversationHub = ConversationHub;
257
+ //# sourceMappingURL=hub.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hub.js","sourceRoot":"","sources":["../src/hub.ts"],"names":[],"mappings":";;;AA4CA,sCAmBC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I,MAAM,KAAK,SAAS;gBAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACzD,CAAC;QACD,MAAM,IAAI,GAAY;YACpB,IAAI,EAAE,CAAC,CAAC,IAAI;YACZ,GAAG,EAAE,CAAC,CAAC,GAAG;YACV,IAAI,EAAE,EAAE;YACR,SAAS,EAAE,EAAE;YACb,GAAG,CAAC,CAAC,CAAC,KAAK,KAAK,SAAS,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;SACjD,CAAC;QACF,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;QAC1C,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAlND,0CAkNC"}
package/dist/ids.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ /** The conversation id of an execution id: generations are `<chainId>~<n>` (ADR 0109 D2). */
2
+ export declare function conversationIdOf(executionId: string): string;
3
+ /** The execution id of generation `g` of conversation `conversationId`. */
4
+ export declare function generationId(conversationId: string, g: number): string;
5
+ /** The generation number of an execution id of the chain (`0` for the first). */
6
+ export declare function generationOf(executionId: string): number;
7
+ /** A caller-chosen conversation id: no `~` (generation separator), no `::` (child separator), no reserved prefix. */
8
+ export declare function isValidConversationId(id: string): boolean;
9
+ //# sourceMappingURL=ids.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ids.d.ts","sourceRoot":"","sources":["../src/ids.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAG5D;AAED,2EAA2E;AAC3E,wBAAgB,YAAY,CAAC,cAAc,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAEtE;AAED,iFAAiF;AACjF,wBAAgB,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAKxD;AAID,qHAAqH;AACrH,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAEzD"}
package/dist/ids.js ADDED
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.conversationIdOf = conversationIdOf;
4
+ exports.generationId = generationId;
5
+ exports.generationOf = generationOf;
6
+ exports.isValidConversationId = isValidConversationId;
7
+ /** The conversation id of an execution id: generations are `<chainId>~<n>` (ADR 0109 D2). */
8
+ function conversationIdOf(executionId) {
9
+ const i = executionId.indexOf("~");
10
+ return i < 0 ? executionId : executionId.slice(0, i);
11
+ }
12
+ /** The execution id of generation `g` of conversation `conversationId`. */
13
+ function generationId(conversationId, g) {
14
+ return g === 0 ? conversationId : `${conversationId}~${g}`;
15
+ }
16
+ /** The generation number of an execution id of the chain (`0` for the first). */
17
+ function generationOf(executionId) {
18
+ const i = executionId.indexOf("~");
19
+ if (i < 0)
20
+ return 0;
21
+ const n = Number(executionId.slice(i + 1));
22
+ return Number.isSafeInteger(n) && n >= 0 ? n : 0;
23
+ }
24
+ const ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
25
+ /** A caller-chosen conversation id: no `~` (generation separator), no `::` (child separator), no reserved prefix. */
26
+ function isValidConversationId(id) {
27
+ return ID.test(id) && !id.startsWith("__loom_");
28
+ }
29
+ //# sourceMappingURL=ids.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ids.js","sourceRoot":"","sources":["../src/ids.ts"],"names":[],"mappings":";;AACA,4CAGC;AAGD,oCAEC;AAGD,oCAKC;AAKD,sDAEC;AAxBD,6FAA6F;AAC7F,SAAgB,gBAAgB,CAAC,WAAmB;IAClD,MAAM,CAAC,GAAG,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACnC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACvD,CAAC;AAED,2EAA2E;AAC3E,SAAgB,YAAY,CAAC,cAAsB,EAAE,CAAS;IAC5D,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,GAAG,cAAc,IAAI,CAAC,EAAE,CAAC;AAC7D,CAAC;AAED,iFAAiF;AACjF,SAAgB,YAAY,CAAC,WAAmB;IAC9C,MAAM,CAAC,GAAG,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACnC,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,CAAC,CAAC;IACpB,MAAM,CAAC,GAAG,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAC3C,OAAO,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,EAAE,GAAG,oCAAoC,CAAC;AAEhD,qHAAqH;AACrH,SAAgB,qBAAqB,CAAC,EAAU;IAC9C,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;AAClD,CAAC"}
@@ -0,0 +1,27 @@
1
+ export { followConversation } from "./feed";
2
+ export type { FeedItem, FollowDeps, FollowOptions } from "./feed";
3
+ export { inboxBargeIn, pendingInbox } from "./bargeIn";
4
+ export type { BargeInHandlers, BargeInSource, StoredInboxMessage } from "./bargeIn";
5
+ export { InvalidEnvelopeError, signInboxEnvelope } from "./signEnvelope";
6
+ export type { InboxEnvelopeBody } from "./signEnvelope";
7
+ export { conversation$, conversationRunner } from "./conversation";
8
+ export type { ConversationFlow, ConversationFlowOptions } from "./conversation";
9
+ export { MAX_PARTICIPANTS, ParticipantLimitError, identityKey, identityOf, logParticipants, parseIdentity, sameIdentity, senderKey, } from "./access";
10
+ export type { Identity, ParticipantChange, ParticipantDirectory } from "./access";
11
+ export { registerSharedTurnEffect, sharedTurnEffect, turnExecutionId } from "./turn";
12
+ export type { TurnInput, TurnResult } from "./turn";
13
+ export { ConversationNotFoundError, InvalidTurnError, QueueFullError, createConversations, } from "./conversations";
14
+ export type { CallOptions, Conversations, ConversationsDeps, ConversationState, ConversationStatus, SendTurnOptions, } from "./conversations";
15
+ export { ContextBudgetError, fitToWindow, fitWithSummaryFallback, heuristicTokenCounter, truncateToTokens, } from "./budget";
16
+ export type { BudgetRequest, BudgetTurn, BudgetVerdict, TokenCounter } from "./budget";
17
+ export { ConversationHub, DEFAULT_MAX_SUBSCRIBERS, SubscriberLimitError, withTurnScope, } from "./hub";
18
+ export type { ConversationHubOptions, LiveEvent, PartialReasoning, PartialReply } from "./hub";
19
+ export { InvalidCursorError, createConversationReader, findHeadGeneration, formatCursor, parseCursor, } from "./reader";
20
+ export type { ConversationReader, Position, ReadOptions, ReadResult } from "./reader";
21
+ export { conversationIdOf, generationId, generationOf, isValidConversationId } from "./ids";
22
+ export { SUMMARIZER_TEXT_TRUNCATED, summarizerText } from "./summarizerText";
23
+ export { turnSettledObserver } from "./settled";
24
+ export type { TurnSettledEvent, TurnSettledListener } from "./settled";
25
+ export { CONVERSATION_TOPIC, RECORD_SOURCE, SUMMARY_ORIGIN, USER_ORIGIN } from "./types";
26
+ export type { BudgetConfig, CarriedTurn, ConversationCarry, ConversationConfig, ConversationResult, HistoryEntry, MessageRecord, MessageStatus, SharedConfig, TurnEnvelope, } from "./types";
27
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AAC5C,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC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AAO,CAAC;AAC/F,OAAO,EACL,kBAAkB,EAClB,wBAAwB,EACxB,kBAAkB,EAClB,YAAY,EACZ,WAAW,GACZ,MAAM,UAAU,CAAC;AAClB,YAAY,EAAE,kBAAkB,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtF,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,OAAO,CAAC;AAC5F,OAAO,EAAE,yBAAyB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC7E,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,YAAY,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACzF,YAAY,EACV,YAAY,EACZ,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,aAAa,EACb,YAAY,EACZ,YAAY,GACb,MAAM,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.USER_ORIGIN = exports.SUMMARY_ORIGIN = exports.RECORD_SOURCE = exports.CONVERSATION_TOPIC = exports.turnSettledObserver = exports.summarizerText = exports.SUMMARIZER_TEXT_TRUNCATED = exports.isValidConversationId = exports.generationOf = exports.generationId = exports.conversationIdOf = exports.parseCursor = exports.formatCursor = exports.findHeadGeneration = exports.createConversationReader = exports.InvalidCursorError = exports.withTurnScope = exports.SubscriberLimitError = exports.DEFAULT_MAX_SUBSCRIBERS = exports.ConversationHub = exports.truncateToTokens = exports.heuristicTokenCounter = exports.fitWithSummaryFallback = exports.fitToWindow = exports.ContextBudgetError = exports.createConversations = exports.QueueFullError = exports.InvalidTurnError = exports.ConversationNotFoundError = exports.turnExecutionId = exports.sharedTurnEffect = exports.registerSharedTurnEffect = exports.senderKey = exports.sameIdentity = exports.parseIdentity = exports.logParticipants = exports.identityOf = exports.identityKey = exports.ParticipantLimitError = exports.MAX_PARTICIPANTS = exports.conversationRunner = exports.conversation$ = exports.signInboxEnvelope = exports.InvalidEnvelopeError = exports.pendingInbox = exports.inboxBargeIn = exports.followConversation = void 0;
4
+ var feed_1 = require("./feed");
5
+ Object.defineProperty(exports, "followConversation", { enumerable: true, get: function () { return feed_1.followConversation; } });
6
+ var bargeIn_1 = require("./bargeIn");
7
+ Object.defineProperty(exports, "inboxBargeIn", { enumerable: true, get: function () { return bargeIn_1.inboxBargeIn; } });
8
+ Object.defineProperty(exports, "pendingInbox", { enumerable: true, get: function () { return bargeIn_1.pendingInbox; } });
9
+ var signEnvelope_1 = require("./signEnvelope");
10
+ Object.defineProperty(exports, "InvalidEnvelopeError", { enumerable: true, get: function () { return signEnvelope_1.InvalidEnvelopeError; } });
11
+ Object.defineProperty(exports, "signInboxEnvelope", { enumerable: true, get: function () { return signEnvelope_1.signInboxEnvelope; } });
12
+ var conversation_1 = require("./conversation");
13
+ Object.defineProperty(exports, "conversation$", { enumerable: true, get: function () { return conversation_1.conversation$; } });
14
+ Object.defineProperty(exports, "conversationRunner", { enumerable: true, get: function () { return conversation_1.conversationRunner; } });
15
+ var access_1 = require("./access");
16
+ Object.defineProperty(exports, "MAX_PARTICIPANTS", { enumerable: true, get: function () { return access_1.MAX_PARTICIPANTS; } });
17
+ Object.defineProperty(exports, "ParticipantLimitError", { enumerable: true, get: function () { return access_1.ParticipantLimitError; } });
18
+ Object.defineProperty(exports, "identityKey", { enumerable: true, get: function () { return access_1.identityKey; } });
19
+ Object.defineProperty(exports, "identityOf", { enumerable: true, get: function () { return access_1.identityOf; } });
20
+ Object.defineProperty(exports, "logParticipants", { enumerable: true, get: function () { return access_1.logParticipants; } });
21
+ Object.defineProperty(exports, "parseIdentity", { enumerable: true, get: function () { return access_1.parseIdentity; } });
22
+ Object.defineProperty(exports, "sameIdentity", { enumerable: true, get: function () { return access_1.sameIdentity; } });
23
+ Object.defineProperty(exports, "senderKey", { enumerable: true, get: function () { return access_1.senderKey; } });
24
+ var turn_1 = require("./turn");
25
+ Object.defineProperty(exports, "registerSharedTurnEffect", { enumerable: true, get: function () { return turn_1.registerSharedTurnEffect; } });
26
+ Object.defineProperty(exports, "sharedTurnEffect", { enumerable: true, get: function () { return turn_1.sharedTurnEffect; } });
27
+ Object.defineProperty(exports, "turnExecutionId", { enumerable: true, get: function () { return turn_1.turnExecutionId; } });
28
+ var conversations_1 = require("./conversations");
29
+ Object.defineProperty(exports, "ConversationNotFoundError", { enumerable: true, get: function () { return conversations_1.ConversationNotFoundError; } });
30
+ Object.defineProperty(exports, "InvalidTurnError", { enumerable: true, get: function () { return conversations_1.InvalidTurnError; } });
31
+ Object.defineProperty(exports, "QueueFullError", { enumerable: true, get: function () { return conversations_1.QueueFullError; } });
32
+ Object.defineProperty(exports, "createConversations", { enumerable: true, get: function () { return conversations_1.createConversations; } });
33
+ var budget_1 = require("./budget");
34
+ Object.defineProperty(exports, "ContextBudgetError", { enumerable: true, get: function () { return budget_1.ContextBudgetError; } });
35
+ Object.defineProperty(exports, "fitToWindow", { enumerable: true, get: function () { return budget_1.fitToWindow; } });
36
+ Object.defineProperty(exports, "fitWithSummaryFallback", { enumerable: true, get: function () { return budget_1.fitWithSummaryFallback; } });
37
+ Object.defineProperty(exports, "heuristicTokenCounter", { enumerable: true, get: function () { return budget_1.heuristicTokenCounter; } });
38
+ Object.defineProperty(exports, "truncateToTokens", { enumerable: true, get: function () { return budget_1.truncateToTokens; } });
39
+ var hub_1 = require("./hub");
40
+ Object.defineProperty(exports, "ConversationHub", { enumerable: true, get: function () { return hub_1.ConversationHub; } });
41
+ Object.defineProperty(exports, "DEFAULT_MAX_SUBSCRIBERS", { enumerable: true, get: function () { return hub_1.DEFAULT_MAX_SUBSCRIBERS; } });
42
+ Object.defineProperty(exports, "SubscriberLimitError", { enumerable: true, get: function () { return hub_1.SubscriberLimitError; } });
43
+ Object.defineProperty(exports, "withTurnScope", { enumerable: true, get: function () { return hub_1.withTurnScope; } });
44
+ var reader_1 = require("./reader");
45
+ Object.defineProperty(exports, "InvalidCursorError", { enumerable: true, get: function () { return reader_1.InvalidCursorError; } });
46
+ Object.defineProperty(exports, "createConversationReader", { enumerable: true, get: function () { return reader_1.createConversationReader; } });
47
+ Object.defineProperty(exports, "findHeadGeneration", { enumerable: true, get: function () { return reader_1.findHeadGeneration; } });
48
+ Object.defineProperty(exports, "formatCursor", { enumerable: true, get: function () { return reader_1.formatCursor; } });
49
+ Object.defineProperty(exports, "parseCursor", { enumerable: true, get: function () { return reader_1.parseCursor; } });
50
+ var ids_1 = require("./ids");
51
+ Object.defineProperty(exports, "conversationIdOf", { enumerable: true, get: function () { return ids_1.conversationIdOf; } });
52
+ Object.defineProperty(exports, "generationId", { enumerable: true, get: function () { return ids_1.generationId; } });
53
+ Object.defineProperty(exports, "generationOf", { enumerable: true, get: function () { return ids_1.generationOf; } });
54
+ Object.defineProperty(exports, "isValidConversationId", { enumerable: true, get: function () { return ids_1.isValidConversationId; } });
55
+ var summarizerText_1 = require("./summarizerText");
56
+ Object.defineProperty(exports, "SUMMARIZER_TEXT_TRUNCATED", { enumerable: true, get: function () { return summarizerText_1.SUMMARIZER_TEXT_TRUNCATED; } });
57
+ Object.defineProperty(exports, "summarizerText", { enumerable: true, get: function () { return summarizerText_1.summarizerText; } });
58
+ var settled_1 = require("./settled");
59
+ Object.defineProperty(exports, "turnSettledObserver", { enumerable: true, get: function () { return settled_1.turnSettledObserver; } });
60
+ var types_1 = require("./types");
61
+ Object.defineProperty(exports, "CONVERSATION_TOPIC", { enumerable: true, get: function () { return types_1.CONVERSATION_TOPIC; } });
62
+ Object.defineProperty(exports, "RECORD_SOURCE", { enumerable: true, get: function () { return types_1.RECORD_SOURCE; } });
63
+ Object.defineProperty(exports, "SUMMARY_ORIGIN", { enumerable: true, get: function () { return types_1.SUMMARY_ORIGIN; } });
64
+ Object.defineProperty(exports, "USER_ORIGIN", { enumerable: true, get: function () { return types_1.USER_ORIGIN; } });
65
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,+BAA4C;AAAnC,0GAAA,kBAAkB,OAAA;AAE3B,qCAAuD;AAA9C,uGAAA,YAAY,OAAA;AAAE,uGAAA,YAAY,OAAA;AAEnC,+CAAyE;AAAhE,oHAAA,oBAAoB,OAAA;AAAE,iHAAA,iBAAiB,OAAA;AAEhD,+CAAmE;AAA1D,6GAAA,aAAa,OAAA;AAAE,kHAAA,kBAAkB,OAAA;AAE1C,mCASkB;AARhB,0GAAA,gBAAgB,OAAA;AAChB,+GAAA,qBAAqB,OAAA;AACrB,qGAAA,WAAW,OAAA;AACX,oGAAA,UAAU,OAAA;AACV,yGAAA,eAAe,OAAA;AACf,uGAAA,aAAa,OAAA;AACb,sGAAA,YAAY,OAAA;AACZ,mGAAA,SAAS,OAAA;AAGX,+BAAqF;AAA5E,gHAAA,wBAAwB,OAAA;AAAE,wGAAA,gBAAgB,OAAA;AAAE,uGAAA,eAAe,OAAA;AAEpE,iDAKyB;AAJvB,0HAAA,yBAAyB,OAAA;AACzB,iHAAA,gBAAgB,OAAA;AAChB,+GAAA,cAAc,OAAA;AACd,oHAAA,mBAAmB,OAAA;AAUrB,mCAMkB;AALhB,4GAAA,kBAAkB,OAAA;AAClB,qGAAA,WAAW,OAAA;AACX,gHAAA,sBAAsB,OAAA;AACtB,+GAAA,qBAAqB,OAAA;AACrB,0GAAA,gBAAgB,OAAA;AAGlB,6BAKe;AAJb,sGAAA,eAAe,OAAA;AACf,8GAAA,uBAAuB,OAAA;AACvB,2GAAA,oBAAoB,OAAA;AACpB,oGAAA,aAAa,OAAA;AAGf,mCAMkB;AALhB,4GAAA,kBAAkB,OAAA;AAClB,kHAAA,wBAAwB,OAAA;AACxB,4GAAA,kBAAkB,OAAA;AAClB,sGAAA,YAAY,OAAA;AACZ,qGAAA,WAAW,OAAA;AAGb,6BAA4F;AAAnF,uGAAA,gBAAgB,OAAA;AAAE,mGAAA,YAAY,OAAA;AAAE,mGAAA,YAAY,OAAA;AAAE,4GAAA,qBAAqB,OAAA;AAC5E,mDAA6E;AAApE,2HAAA,yBAAyB,OAAA;AAAE,gHAAA,cAAc,OAAA;AAClD,qCAAgD;AAAvC,8GAAA,mBAAmB,OAAA;AAE5B,iCAAyF;AAAhF,2GAAA,kBAAkB,OAAA;AAAE,sGAAA,aAAa,OAAA;AAAE,uGAAA,cAAc,OAAA;AAAE,oGAAA,WAAW,OAAA"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * A failure of the conversation's OWN model call: the provider answered with an HTTP error of any
3
+ * status, or reported an error inside a 200 stream. `@loom/agent`'s `isTerminalToolError` calls
4
+ * some of these terminal (401/403/429/5xx, stream errors) because for a TOOL loop they are a stop
5
+ * for the runtime's retry policy; for the conversation they are a failed turn with the fixed
6
+ * `model-error` reason, and the conversation keeps accepting turns. Checked BEFORE
7
+ * `isTerminalToolError`; a park, cancel, authority stop or divergence is not a provider error.
8
+ */
9
+ export declare function isProviderError(err: unknown): boolean;
10
+ //# sourceMappingURL=providerError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"providerError.d.ts","sourceRoot":"","sources":["../src/providerError.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAErD"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isProviderError = isProviderError;
4
+ const llm_1 = require("@loom/llm");
5
+ /**
6
+ * A failure of the conversation's OWN model call: the provider answered with an HTTP error of any
7
+ * status, or reported an error inside a 200 stream. `@loom/agent`'s `isTerminalToolError` calls
8
+ * some of these terminal (401/403/429/5xx, stream errors) because for a TOOL loop they are a stop
9
+ * for the runtime's retry policy; for the conversation they are a failed turn with the fixed
10
+ * `model-error` reason, and the conversation keeps accepting turns. Checked BEFORE
11
+ * `isTerminalToolError`; a park, cancel, authority stop or divergence is not a provider error.
12
+ */
13
+ function isProviderError(err) {
14
+ return err instanceof llm_1.LlmHttpError || err instanceof llm_1.LlmStreamError;
15
+ }
16
+ //# sourceMappingURL=providerError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"providerError.js","sourceRoot":"","sources":["../src/providerError.ts"],"names":[],"mappings":";;AAUA,0CAEC;AAZD,mCAAyD;AAEzD;;;;;;;GAOG;AACH,SAAgB,eAAe,CAAC,GAAY;IAC1C,OAAO,GAAG,YAAY,kBAAY,IAAI,GAAG,YAAY,oBAAc,CAAC;AACtE,CAAC"}