@arden-hq/loop 0.0.0-stage → 0.1.2

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 (223) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +121 -2
  3. package/dist/abort.d.ts +9 -0
  4. package/dist/abort.d.ts.map +1 -0
  5. package/dist/abort.js +31 -0
  6. package/dist/abort.js.map +1 -0
  7. package/dist/agent/agent.d.ts +48 -0
  8. package/dist/agent/agent.d.ts.map +1 -0
  9. package/dist/agent/agent.js +146 -0
  10. package/dist/agent/agent.js.map +1 -0
  11. package/dist/agent/background-tools.d.ts +51 -0
  12. package/dist/agent/background-tools.d.ts.map +1 -0
  13. package/dist/agent/background-tools.js +257 -0
  14. package/dist/agent/background-tools.js.map +1 -0
  15. package/dist/agent/budget.d.ts +5 -0
  16. package/dist/agent/budget.d.ts.map +1 -0
  17. package/dist/agent/budget.js +48 -0
  18. package/dist/agent/budget.js.map +1 -0
  19. package/dist/agent/config.d.ts +61 -0
  20. package/dist/agent/config.d.ts.map +1 -0
  21. package/dist/agent/config.js +99 -0
  22. package/dist/agent/config.js.map +1 -0
  23. package/dist/agent/guards.d.ts +10 -0
  24. package/dist/agent/guards.d.ts.map +1 -0
  25. package/dist/agent/guards.js +136 -0
  26. package/dist/agent/guards.js.map +1 -0
  27. package/dist/agent/history-journal.d.ts +18 -0
  28. package/dist/agent/history-journal.d.ts.map +1 -0
  29. package/dist/agent/history-journal.js +87 -0
  30. package/dist/agent/history-journal.js.map +1 -0
  31. package/dist/agent/history-projection.d.ts +6 -0
  32. package/dist/agent/history-projection.d.ts.map +1 -0
  33. package/dist/agent/history-projection.js +62 -0
  34. package/dist/agent/history-projection.js.map +1 -0
  35. package/dist/agent/interactions.d.ts +14 -0
  36. package/dist/agent/interactions.d.ts.map +1 -0
  37. package/dist/agent/interactions.js +85 -0
  38. package/dist/agent/interactions.js.map +1 -0
  39. package/dist/agent/middleware.d.ts +5 -0
  40. package/dist/agent/middleware.d.ts.map +1 -0
  41. package/dist/agent/middleware.js +55 -0
  42. package/dist/agent/middleware.js.map +1 -0
  43. package/dist/agent/model-output-projection.d.ts +27 -0
  44. package/dist/agent/model-output-projection.d.ts.map +1 -0
  45. package/dist/agent/model-output-projection.js +138 -0
  46. package/dist/agent/model-output-projection.js.map +1 -0
  47. package/dist/agent/model-output.d.ts +19 -0
  48. package/dist/agent/model-output.d.ts.map +1 -0
  49. package/dist/agent/model-output.js +172 -0
  50. package/dist/agent/model-output.js.map +1 -0
  51. package/dist/agent/model-turn.d.ts +29 -0
  52. package/dist/agent/model-turn.d.ts.map +1 -0
  53. package/dist/agent/model-turn.js +401 -0
  54. package/dist/agent/model-turn.js.map +1 -0
  55. package/dist/agent/policy.d.ts +28 -0
  56. package/dist/agent/policy.d.ts.map +1 -0
  57. package/dist/agent/policy.js +109 -0
  58. package/dist/agent/policy.js.map +1 -0
  59. package/dist/agent/provider-capabilities.d.ts +12 -0
  60. package/dist/agent/provider-capabilities.d.ts.map +1 -0
  61. package/dist/agent/provider-capabilities.js +76 -0
  62. package/dist/agent/provider-capabilities.js.map +1 -0
  63. package/dist/agent/recovery.d.ts +8 -0
  64. package/dist/agent/recovery.d.ts.map +1 -0
  65. package/dist/agent/recovery.js +21 -0
  66. package/dist/agent/recovery.js.map +1 -0
  67. package/dist/agent/replies.d.ts +3 -0
  68. package/dist/agent/replies.d.ts.map +1 -0
  69. package/dist/agent/replies.js +24 -0
  70. package/dist/agent/replies.js.map +1 -0
  71. package/dist/agent/run-state.d.ts +98 -0
  72. package/dist/agent/run-state.d.ts.map +1 -0
  73. package/dist/agent/run-state.js +454 -0
  74. package/dist/agent/run-state.js.map +1 -0
  75. package/dist/agent/run.d.ts +6 -0
  76. package/dist/agent/run.d.ts.map +1 -0
  77. package/dist/agent/run.js +462 -0
  78. package/dist/agent/run.js.map +1 -0
  79. package/dist/agent/streamed-call-history.d.ts +20 -0
  80. package/dist/agent/streamed-call-history.d.ts.map +1 -0
  81. package/dist/agent/streamed-call-history.js +71 -0
  82. package/dist/agent/streamed-call-history.js.map +1 -0
  83. package/dist/agent/streaming-tools.d.ts +23 -0
  84. package/dist/agent/streaming-tools.d.ts.map +1 -0
  85. package/dist/agent/streaming-tools.js +67 -0
  86. package/dist/agent/streaming-tools.js.map +1 -0
  87. package/dist/agent/structured-output.d.ts +27 -0
  88. package/dist/agent/structured-output.d.ts.map +1 -0
  89. package/dist/agent/structured-output.js +26 -0
  90. package/dist/agent/structured-output.js.map +1 -0
  91. package/dist/agent/tool-admission.d.ts +18 -0
  92. package/dist/agent/tool-admission.d.ts.map +1 -0
  93. package/dist/agent/tool-admission.js +22 -0
  94. package/dist/agent/tool-admission.js.map +1 -0
  95. package/dist/contracts/events.d.ts +236 -0
  96. package/dist/contracts/events.d.ts.map +1 -0
  97. package/dist/contracts/events.js +13 -0
  98. package/dist/contracts/events.js.map +1 -0
  99. package/dist/contracts/messages.d.ts +234 -0
  100. package/dist/contracts/messages.d.ts.map +1 -0
  101. package/dist/contracts/messages.js +11 -0
  102. package/dist/contracts/messages.js.map +1 -0
  103. package/dist/contracts/provider.d.ts +177 -0
  104. package/dist/contracts/provider.d.ts.map +1 -0
  105. package/dist/contracts/provider.js +26 -0
  106. package/dist/contracts/provider.js.map +1 -0
  107. package/dist/contracts/tools.d.ts +217 -0
  108. package/dist/contracts/tools.d.ts.map +1 -0
  109. package/dist/contracts/tools.js +16 -0
  110. package/dist/contracts/tools.js.map +1 -0
  111. package/dist/errors.d.ts +112 -0
  112. package/dist/errors.d.ts.map +1 -0
  113. package/dist/errors.js +190 -0
  114. package/dist/errors.js.map +1 -0
  115. package/dist/index.d.ts +34 -0
  116. package/dist/index.d.ts.map +1 -0
  117. package/dist/index.js +20 -0
  118. package/dist/index.js.map +1 -0
  119. package/dist/internal/concurrency.d.ts +11 -0
  120. package/dist/internal/concurrency.d.ts.map +1 -0
  121. package/dist/internal/concurrency.js +86 -0
  122. package/dist/internal/concurrency.js.map +1 -0
  123. package/dist/internal/stream.d.ts +25 -0
  124. package/dist/internal/stream.d.ts.map +1 -0
  125. package/dist/internal/stream.js +97 -0
  126. package/dist/internal/stream.js.map +1 -0
  127. package/dist/internal/validate.d.ts +30 -0
  128. package/dist/internal/validate.d.ts.map +1 -0
  129. package/dist/internal/validate.js +480 -0
  130. package/dist/internal/validate.js.map +1 -0
  131. package/dist/providers/kit/errors.d.ts +40 -0
  132. package/dist/providers/kit/errors.d.ts.map +1 -0
  133. package/dist/providers/kit/errors.js +48 -0
  134. package/dist/providers/kit/errors.js.map +1 -0
  135. package/dist/providers/kit/index.d.ts +10 -0
  136. package/dist/providers/kit/index.d.ts.map +1 -0
  137. package/dist/providers/kit/index.js +10 -0
  138. package/dist/providers/kit/index.js.map +1 -0
  139. package/dist/providers/kit/retry.d.ts +43 -0
  140. package/dist/providers/kit/retry.d.ts.map +1 -0
  141. package/dist/providers/kit/retry.js +118 -0
  142. package/dist/providers/kit/retry.js.map +1 -0
  143. package/dist/providers/kit/sse.d.ts +22 -0
  144. package/dist/providers/kit/sse.d.ts.map +1 -0
  145. package/dist/providers/kit/sse.js +70 -0
  146. package/dist/providers/kit/sse.js.map +1 -0
  147. package/dist/providers/openai-responses/citations.d.ts +21 -0
  148. package/dist/providers/openai-responses/citations.d.ts.map +1 -0
  149. package/dist/providers/openai-responses/citations.js +65 -0
  150. package/dist/providers/openai-responses/citations.js.map +1 -0
  151. package/dist/providers/openai-responses/continuation.d.ts +19 -0
  152. package/dist/providers/openai-responses/continuation.d.ts.map +1 -0
  153. package/dist/providers/openai-responses/continuation.js +28 -0
  154. package/dist/providers/openai-responses/continuation.js.map +1 -0
  155. package/dist/providers/openai-responses/errors.d.ts +28 -0
  156. package/dist/providers/openai-responses/errors.d.ts.map +1 -0
  157. package/dist/providers/openai-responses/errors.js +103 -0
  158. package/dist/providers/openai-responses/errors.js.map +1 -0
  159. package/dist/providers/openai-responses/history.d.ts +8 -0
  160. package/dist/providers/openai-responses/history.d.ts.map +1 -0
  161. package/dist/providers/openai-responses/history.js +93 -0
  162. package/dist/providers/openai-responses/history.js.map +1 -0
  163. package/dist/providers/openai-responses/items.d.ts +106 -0
  164. package/dist/providers/openai-responses/items.d.ts.map +1 -0
  165. package/dist/providers/openai-responses/items.js +124 -0
  166. package/dist/providers/openai-responses/items.js.map +1 -0
  167. package/dist/providers/openai-responses/parameter-schema.d.ts +11 -0
  168. package/dist/providers/openai-responses/parameter-schema.d.ts.map +1 -0
  169. package/dist/providers/openai-responses/parameter-schema.js +186 -0
  170. package/dist/providers/openai-responses/parameter-schema.js.map +1 -0
  171. package/dist/providers/openai-responses/provider.d.ts +54 -0
  172. package/dist/providers/openai-responses/provider.d.ts.map +1 -0
  173. package/dist/providers/openai-responses/provider.js +270 -0
  174. package/dist/providers/openai-responses/provider.js.map +1 -0
  175. package/dist/providers/openai-responses/request.d.ts +41 -0
  176. package/dist/providers/openai-responses/request.d.ts.map +1 -0
  177. package/dist/providers/openai-responses/request.js +276 -0
  178. package/dist/providers/openai-responses/request.js.map +1 -0
  179. package/dist/providers/openai-responses/response.d.ts +7 -0
  180. package/dist/providers/openai-responses/response.d.ts.map +1 -0
  181. package/dist/providers/openai-responses/response.js +354 -0
  182. package/dist/providers/openai-responses/response.js.map +1 -0
  183. package/dist/providers/openai-responses/stored-items.d.ts +9 -0
  184. package/dist/providers/openai-responses/stored-items.d.ts.map +1 -0
  185. package/dist/providers/openai-responses/stored-items.js +133 -0
  186. package/dist/providers/openai-responses/stored-items.js.map +1 -0
  187. package/dist/providers/openai-responses/tool-search.d.ts +12 -0
  188. package/dist/providers/openai-responses/tool-search.d.ts.map +1 -0
  189. package/dist/providers/openai-responses/tool-search.js +68 -0
  190. package/dist/providers/openai-responses/tool-search.js.map +1 -0
  191. package/dist/providers/openai-responses/tools.d.ts +33 -0
  192. package/dist/providers/openai-responses/tools.d.ts.map +1 -0
  193. package/dist/providers/openai-responses/tools.js +53 -0
  194. package/dist/providers/openai-responses/tools.js.map +1 -0
  195. package/dist/providers/openai-responses/web-search.d.ts +5 -0
  196. package/dist/providers/openai-responses/web-search.d.ts.map +1 -0
  197. package/dist/providers/openai-responses/web-search.js +114 -0
  198. package/dist/providers/openai-responses/web-search.js.map +1 -0
  199. package/dist/providers/openai-responses/websocket.d.ts +29 -0
  200. package/dist/providers/openai-responses/websocket.d.ts.map +1 -0
  201. package/dist/providers/openai-responses/websocket.js +400 -0
  202. package/dist/providers/openai-responses/websocket.js.map +1 -0
  203. package/dist/tools/dispatch.d.ts +65 -0
  204. package/dist/tools/dispatch.d.ts.map +1 -0
  205. package/dist/tools/dispatch.js +536 -0
  206. package/dist/tools/dispatch.js.map +1 -0
  207. package/dist/tools/display-title.d.ts +18 -0
  208. package/dist/tools/display-title.d.ts.map +1 -0
  209. package/dist/tools/display-title.js +50 -0
  210. package/dist/tools/display-title.js.map +1 -0
  211. package/dist/tools/search.d.ts +36 -0
  212. package/dist/tools/search.d.ts.map +1 -0
  213. package/dist/tools/search.js +224 -0
  214. package/dist/tools/search.js.map +1 -0
  215. package/dist/tools/tool.d.ts +200 -0
  216. package/dist/tools/tool.d.ts.map +1 -0
  217. package/dist/tools/tool.js +275 -0
  218. package/dist/tools/tool.js.map +1 -0
  219. package/dist/tools/truncate.d.ts +18 -0
  220. package/dist/tools/truncate.d.ts.map +1 -0
  221. package/dist/tools/truncate.js +76 -0
  222. package/dist/tools/truncate.js.map +1 -0
  223. package/package.json +67 -4
@@ -0,0 +1,234 @@
1
+ export type JsonPrimitive = string | number | boolean | null;
2
+ export type JsonValue = JsonPrimitive | ReadonlyArray<JsonValue> | {
3
+ readonly [key: string]: JsonValue;
4
+ };
5
+ export type JsonObject = Readonly<Record<string, JsonValue>>;
6
+ export type Metadata = Readonly<Record<string, unknown>>;
7
+ export type MaybePromise<A> = A | PromiseLike<A>;
8
+ export interface StandardSchemaV1<Input = unknown, Output = Input> {
9
+ readonly "~standard": StandardSchemaV1.Props<Input, Output>;
10
+ }
11
+ export declare namespace StandardSchemaV1 {
12
+ interface Props<Input = unknown, Output = Input> {
13
+ readonly version: 1;
14
+ readonly vendor: string;
15
+ readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
16
+ readonly types?: Types<Input, Output> | undefined;
17
+ }
18
+ type Result<Output> = SuccessResult<Output> | FailureResult;
19
+ interface SuccessResult<Output> {
20
+ readonly value: Output;
21
+ readonly issues?: undefined;
22
+ }
23
+ interface FailureResult {
24
+ readonly issues: ReadonlyArray<Issue>;
25
+ }
26
+ interface Issue {
27
+ readonly message: string;
28
+ readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
29
+ }
30
+ interface PathSegment {
31
+ readonly key: PropertyKey;
32
+ }
33
+ interface Types<Input = unknown, Output = Input> {
34
+ readonly input: Input;
35
+ readonly output: Output;
36
+ }
37
+ type InferInput<S extends StandardSchemaV1> = NonNullable<S["~standard"]["types"]>["input"];
38
+ type InferOutput<S extends StandardSchemaV1> = NonNullable<S["~standard"]["types"]>["output"];
39
+ }
40
+ export interface TextContent {
41
+ readonly type: "text";
42
+ readonly text: string;
43
+ }
44
+ export interface ImageContent {
45
+ readonly type: "image";
46
+ readonly media_type: string;
47
+ readonly data: string;
48
+ }
49
+ export interface AudioContent {
50
+ readonly type: "audio";
51
+ readonly media_type: string;
52
+ readonly data: string;
53
+ }
54
+ export interface ContextContent {
55
+ readonly type: "context";
56
+ readonly content_type: string;
57
+ readonly content?: string | null;
58
+ readonly metadata?: Readonly<Record<string, string>> | null;
59
+ }
60
+ export type ContentBlock = TextContent | ImageContent | AudioContent | ContextContent;
61
+ export type ModelContentBlock = ContentBlock;
62
+ export interface FunctionCall {
63
+ readonly name: string;
64
+ readonly arguments: string;
65
+ }
66
+ export interface ToolCall {
67
+ /** Native wire flag, preserved on replay. */
68
+ readonly async?: boolean;
69
+ readonly id: string;
70
+ readonly type: "function";
71
+ readonly function: FunctionCall;
72
+ readonly started_at?: number;
73
+ readonly parent_id?: string | null;
74
+ /** Sanitized display title the model wrote through the host's opt-in
75
+ * argument (`CreateToolsetOptions.displayTitle`); never a tool argument.
76
+ * Host fields from `AgentOptions.persistHost` ride beside it. */
77
+ readonly display_title?: string;
78
+ }
79
+ export type AssistantTextPhase = "commentary" | "final_answer";
80
+ export type InteractionActorType = "agent" | "workflow" | "tool" | "harness" | "user";
81
+ export interface InteractionActor extends JsonObject {
82
+ readonly type: InteractionActorType;
83
+ readonly id: string;
84
+ readonly display_name?: string;
85
+ }
86
+ export interface InteractionReference extends JsonObject {
87
+ readonly type: "message" | "run" | "tool_call" | "workflow";
88
+ readonly id: string;
89
+ }
90
+ /** Immutable model-facing snapshot of the message a human replied to. */
91
+ export interface ReplyContext extends JsonObject {
92
+ readonly messageId: string;
93
+ readonly role: "user" | "assistant";
94
+ readonly content: string;
95
+ }
96
+ interface InteractionBase extends JsonObject {
97
+ readonly from: InteractionActor;
98
+ readonly to: InteractionActor;
99
+ readonly content: string;
100
+ /** One plain line for a person's row when `content` is written for the
101
+ * recipient model; the row falls back to `content`. */
102
+ readonly preview?: string;
103
+ readonly causedBy?: InteractionReference;
104
+ }
105
+ /** `interrupted`: the sender stopped because the host restarted. */
106
+ export declare const INTERACTION_OUTCOMES: readonly ["completed", "failed", "cancelled", "needs_attention", "interrupted"];
107
+ type InteractionOutcome = (typeof INTERACTION_OUTCOMES)[number];
108
+ /** Provider-neutral communication delivered by the harness. */
109
+ export type Interaction = (InteractionBase & {
110
+ readonly kind: "message" | "assignment" | "event" | "instruction";
111
+ }) | (InteractionBase & {
112
+ readonly kind: "completion";
113
+ readonly outcome: InteractionOutcome;
114
+ });
115
+ export type AssistantOutputPart = {
116
+ readonly type: "reasoning";
117
+ readonly text: string;
118
+ } | {
119
+ readonly type: "text";
120
+ readonly text: string;
121
+ readonly phase?: AssistantTextPhase;
122
+ } | {
123
+ readonly type: "tool_call";
124
+ readonly tool_call_id: string;
125
+ readonly execution: "runtime" | "provider";
126
+ };
127
+ /**
128
+ * The fields the loop itself reads on any stored message. Everything else a
129
+ * host keeps on a message rides the open record and round-trips untouched.
130
+ */
131
+ interface MessageFields extends Metadata {
132
+ readonly message_id?: string;
133
+ /** Host idempotency key; the loop writes `tool-media:` and `async-result:` envelopes. */
134
+ readonly client_id?: string;
135
+ /** A harness-written envelope rather than authored text. */
136
+ readonly is_meta?: boolean;
137
+ }
138
+ /** Durable record that a background call was launched and how its result returns. */
139
+ export interface AsyncToolLaunch {
140
+ readonly call_id: string;
141
+ readonly delivery: "native" | "message";
142
+ }
143
+ export interface SystemMessage extends MessageFields {
144
+ readonly role: "system";
145
+ readonly content: string | ReadonlyArray<Metadata>;
146
+ }
147
+ /** Current high-priority context that belongs in the request timeline, not the stable base prompt. */
148
+ interface DeveloperMessage extends MessageFields {
149
+ readonly role: "developer";
150
+ readonly content: string | ReadonlyArray<Metadata>;
151
+ /**
152
+ * Deferred tools that stay loaded after a compaction removed the history
153
+ * that loaded them. A provider renders them in its own form; `content`
154
+ * is the plain-text fallback.
155
+ */
156
+ readonly loaded_tools?: ReadonlyArray<string>;
157
+ /**
158
+ * Deferred tools that left the catalog at this point in the conversation.
159
+ * They no longer count as loaded; if one returns, a search loads it again.
160
+ */
161
+ readonly removed_tools?: ReadonlyArray<string>;
162
+ }
163
+ export interface UserMessage extends MessageFields {
164
+ readonly role: "user";
165
+ readonly content?: string | null | ReadonlyArray<Metadata>;
166
+ /** Durable carrier; provider preparation derives the actual model role/item. */
167
+ readonly interaction?: Interaction;
168
+ readonly replyTo?: ReplyContext;
169
+ readonly async_tool_launch?: AsyncToolLaunch;
170
+ /** On the correction `hooks.checkFinalText` appended: the assistant records
171
+ * of the answer it sent back. Durable with the history, so a host that
172
+ * resumes the run knows the check already ran and what it replaced. */
173
+ readonly rejected_message_ids?: ReadonlyArray<string>;
174
+ }
175
+ export interface AssistantMessage extends MessageFields {
176
+ readonly role: "assistant";
177
+ readonly content?: string | null | ReadonlyArray<Metadata>;
178
+ readonly tool_calls?: ReadonlyArray<ToolCall>;
179
+ /** Calls the provider executed upstream, persisted with their results. */
180
+ readonly provider_tool_calls?: ReadonlyArray<ProviderToolCall> | null;
181
+ readonly reasoning_content?: string | null;
182
+ /** Provider-neutral presentation order for this model turn. */
183
+ readonly output_parts?: ReadonlyArray<AssistantOutputPart>;
184
+ /** Opaque replay state, keyed by the provider that wrote it. */
185
+ readonly provider_state?: ProviderState;
186
+ }
187
+ export interface ToolResultMessage extends MessageFields {
188
+ readonly role: "tool";
189
+ readonly tool_call_id: string;
190
+ readonly content: string;
191
+ readonly async_tool_launch?: AsyncToolLaunch;
192
+ }
193
+ export type ChatMessage = SystemMessage | DeveloperMessage | UserMessage | AssistantMessage | ToolResultMessage;
194
+ export type ModelMessage = ChatMessage;
195
+ export type Role = "system" | "developer" | "user" | "assistant" | "tool";
196
+ export interface ProviderToolCall {
197
+ readonly id: string;
198
+ readonly name: string;
199
+ readonly arguments?: Readonly<Record<string, JsonValue>>;
200
+ readonly result?: string;
201
+ readonly done?: boolean;
202
+ readonly loaded_tool_names?: ReadonlyArray<string>;
203
+ /** Bounded provider evidence projected onto tool lifecycle events. */
204
+ readonly source_refs?: ReadonlyArray<JsonObject>;
205
+ }
206
+ /**
207
+ * Provider-owned replay state, keyed by provider id. The loop persists it on
208
+ * the assistant message untouched; only the provider that wrote an entry
209
+ * reads it back.
210
+ */
211
+ export type ProviderState = Readonly<Record<string, JsonValue>>;
212
+ /** Allocate opaque message identities with the platform Web Crypto API. */
213
+ export declare const messageId: (kind: "text" | "reasoning" | "tool" | "tool-media" | "tool-load" | "tool-change") => string;
214
+ /**
215
+ * Host-supplied identity scheme for streamed text and reasoning messages,
216
+ * applied at emission: the first event carrying a message already uses its
217
+ * durable id, so deltas, terminal events, and persisted history agree by
218
+ * construction. Minting is positional — `turn` is the model-call ordinal
219
+ * within the run, `fragment` the ordinal of the output fragment the message
220
+ * belongs to (always 0 for a provider that does not emit `OutputItemReady`),
221
+ * and `index` the per-kind ordinal within that fragment. The fragment is
222
+ * persisted as its own history record under `("text", { turn, fragment,
223
+ * index: 0 })`, so a scheme that derives a record's part ids from its record
224
+ * id names each streamed part the way history will. A provider retry
225
+ * discards the attempt and re-requests the same coordinates, so a pure
226
+ * scheme re-mints exactly the retracted ids.
227
+ */
228
+ export type MessageIdMinter = (kind: "text" | "reasoning", position: {
229
+ readonly turn: number;
230
+ readonly fragment: number;
231
+ readonly index: number;
232
+ }) => string;
233
+ export {};
234
+ //# sourceMappingURL=messages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/contracts/messages.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAA;AAC5D,MAAM,MAAM,SAAS,GACjB,aAAa,GACb,aAAa,CAAC,SAAS,CAAC,GACxB;IAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAA;AACzC,MAAM,MAAM,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAA;AAC5D,MAAM,MAAM,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;AAExD,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAA;AAKhD,MAAM,WAAW,gBAAgB,CAAC,KAAK,GAAG,OAAO,EAAE,MAAM,GAAG,KAAK;IAC/D,QAAQ,CAAC,WAAW,EAAE,gBAAgB,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;CAC5D;AAED,MAAM,CAAC,OAAO,WAAW,gBAAgB,CAAC;IACxC,UAAiB,KAAK,CAAC,KAAK,GAAG,OAAO,EAAE,MAAM,GAAG,KAAK;QACpD,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAA;QACnB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;QACvB,QAAQ,CAAC,QAAQ,EA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,MAAM,SAAS,SACd,MAAM,GAAG,WAAW,GAAG,MAAM,GAAG,YAAY,GAAG,WAAW,GAAG,aAAa,KAC/E,MAAqD,CAAA;AAExD;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,eAAe,GAAG,CAC5B,IAAI,EAAE,MAAM,GAAG,WAAW,EAC1B,QAAQ,EAAE;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,KACnF,MAAM,CAAA"}
@@ -0,0 +1,11 @@
1
+ /** `interrupted`: the sender stopped because the host restarted. */
2
+ export const INTERACTION_OUTCOMES = [
3
+ "completed",
4
+ "failed",
5
+ "cancelled",
6
+ "needs_attention",
7
+ "interrupted"
8
+ ];
9
+ /** Allocate opaque message identities with the platform Web Crypto API. */
10
+ export const messageId = (kind) => `${kind}-${globalThis.crypto.randomUUID()}`;
11
+ //# sourceMappingURL=messages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/contracts/messages.ts"],"names":[],"mappings":"AAsIA,oEAAoE;AACpE,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,WAAW;IACX,QAAQ;IACR,WAAW;IACX,iBAAiB;IACjB,aAAa;CACL,CAAA;AAgIV,2EAA2E;AAC3E,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,IAAgF,EACxE,EAAE,CAAC,GAAG,IAAI,IAAI,UAAU,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,CAAA"}
@@ -0,0 +1,177 @@
1
+ import type { AssistantOutputPart, ChatMessage, Interaction, MaybePromise, ProviderState, ProviderToolCall, ToolCall, UserMessage } from "./messages.js";
2
+ import type { JsonSchema, ToolDeclaration, ToolSearch } from "./tools.js";
3
+ export declare const ToolChoice: {
4
+ readonly AUTO: "auto";
5
+ readonly NONE: "none";
6
+ readonly REQUIRED: "required";
7
+ };
8
+ export type ToolChoice = (typeof ToolChoice)[keyof typeof ToolChoice];
9
+ export declare const FinishReason: {
10
+ readonly STOP: "stop";
11
+ readonly TOOL_CALLS: "tool_calls";
12
+ readonly LENGTH: "length";
13
+ readonly CONTENT_FILTER: "content_filter";
14
+ };
15
+ export type FinishReason = (typeof FinishReason)[keyof typeof FinishReason];
16
+ export interface Usage {
17
+ readonly prompt_tokens: number;
18
+ readonly completion_tokens: number;
19
+ readonly cache_read_tokens: number;
20
+ readonly cache_write_tokens: number;
21
+ }
22
+ export declare const zeroUsage: () => Usage;
23
+ export declare const usageInputTokens: (usage: Partial<Usage>) => number;
24
+ export declare const addUsage: (left: Usage, right: Partial<Usage>) => Usage;
25
+ export interface TextContentDelta {
26
+ readonly _tag: "TextDelta";
27
+ readonly content: string;
28
+ }
29
+ export interface ReasoningContentDelta {
30
+ readonly _tag: "ReasoningDelta";
31
+ readonly content: string;
32
+ }
33
+ export interface ToolCallStreamDelta {
34
+ readonly _tag: "ToolCallDelta";
35
+ readonly index: number;
36
+ readonly tool_id?: string | null;
37
+ readonly name?: string | null;
38
+ readonly arguments_delta?: string | null;
39
+ readonly done?: boolean;
40
+ }
41
+ /** A complete, immutable assistant output fragment, in response order.
42
+ * The loop can persist it and execute its calls while streaming continues.
43
+ * Adapters emitting fragments must cover the full terminal message, including
44
+ * opaque replay state. Partial arguments remain ToolCallDelta presentation only. */
45
+ export interface OutputItemReady {
46
+ readonly _tag: "OutputItemReady";
47
+ readonly message: ProviderMessage;
48
+ }
49
+ export interface ProviderToolCallDelta {
50
+ readonly _tag: "ProviderToolCall";
51
+ readonly call: ProviderToolCall;
52
+ }
53
+ export interface ProviderStreamRetry {
54
+ readonly _tag: "ProviderStreamRetry";
55
+ /** 1-based transport attempt that just failed. */
56
+ readonly attempt: number;
57
+ /** Total attempts the provider will make before the failure stands. */
58
+ readonly maxAttempts: number;
59
+ /** Backoff the provider will sleep before re-streaming, in milliseconds. */
60
+ readonly delayMs?: number;
61
+ }
62
+ export interface ProviderMessage {
63
+ readonly role: "assistant";
64
+ readonly content: string | null;
65
+ readonly tool_calls: ReadonlyArray<ToolCall> | null;
66
+ readonly reasoning_content: string | null;
67
+ readonly provider_tool_calls?: ReadonlyArray<ProviderToolCall> | null;
68
+ /** Native output order normalized by the provider adapter. */
69
+ readonly output_parts?: ReadonlyArray<AssistantOutputPart> | null;
70
+ readonly provider_state?: ProviderState;
71
+ }
72
+ /** The terminal item of one provider response. */
73
+ export interface CompletionResponse {
74
+ readonly _tag: "Completed";
75
+ /** A provider-owned successor is pending; this response is not a final answer. */
76
+ readonly continuation?: boolean;
77
+ readonly message: ProviderMessage;
78
+ readonly finish_reason: FinishReason | null;
79
+ readonly usage: Partial<Usage> & Pick<Usage, "completion_tokens">;
80
+ readonly model: string;
81
+ }
82
+ export type ModelStreamItem = TextContentDelta | ReasoningContentDelta | ToolCallStreamDelta | OutputItemReady | ProviderToolCallDelta | ProviderStreamRetry | CompletionResponse;
83
+ export type ModelSource<A> = Iterable<A> | AsyncIterable<A> | PromiseLike<Iterable<A> | AsyncIterable<A>>;
84
+ /** JSON-Schema response format for structured output, carried to the provider. */
85
+ export interface ResponseFormat {
86
+ readonly name: string;
87
+ readonly schema: JsonSchema;
88
+ }
89
+ export interface ModelProviderRequest {
90
+ /** Invocation-scoped pending user input. Adapters may poll only while generating. */
91
+ readonly steering?: {
92
+ readonly take: () => Promise<ReadonlyArray<UserMessage>>;
93
+ };
94
+ readonly messages: ReadonlyArray<ChatMessage>;
95
+ /**
96
+ * The loop's text for an interaction a provider carries natively (a user
97
+ * message that kept its `interaction`). Providers place it; they never word it.
98
+ */
99
+ readonly renderInteraction: (interaction: Interaction) => string;
100
+ readonly model: string;
101
+ readonly maxOutputTokens?: number;
102
+ readonly tools: ReadonlyArray<ToolDeclaration>;
103
+ /**
104
+ * The deferred catalog, loaded or not. It stays the same for a whole
105
+ * conversation; loaded tools reach the model inside the conversation.
106
+ */
107
+ readonly deferredTools: ReadonlyArray<ToolDeclaration>;
108
+ /** Present when the route searches on the client and the catalog is not empty. */
109
+ readonly toolSearch?: ToolSearch;
110
+ readonly toolChoice: ToolChoice;
111
+ readonly reasoningEffort?: string;
112
+ /** See `AgentConfigInput.cacheScope`; a provider without prompt caching ignores it. */
113
+ readonly cacheScope?: string;
114
+ readonly responseFormat?: ResponseFormat;
115
+ readonly signal?: AbortSignal;
116
+ }
117
+ export interface ModelProvider {
118
+ readonly protocolVersion: 1;
119
+ /** Allocate connection-local state for one agent invocation. */
120
+ readonly openSession?: () => MaybePromise<ModelProviderSession>;
121
+ /** Optional native features, resolved for the actual model/endpoint route. */
122
+ readonly capabilities?: (model: string) => MaybePromise<ModelCapabilities>;
123
+ readonly stream: (request: ModelProviderRequest) => ModelSource<ModelStreamItem>;
124
+ }
125
+ export interface ModelProviderSession {
126
+ readonly stream: ModelProvider["stream"];
127
+ readonly close: () => MaybePromise<void>;
128
+ }
129
+ export interface ModelCapabilities {
130
+ readonly agentMessages?: "native" | "message";
131
+ readonly asyncTools?: "native" | "message";
132
+ readonly steering?: "native" | "boundary";
133
+ readonly hostedTools: ReadonlyArray<string>;
134
+ /**
135
+ * `native` — the provider constrains the final text to `responseFormat`
136
+ * (the host supplies a schema its dialect accepts); `none` — the route
137
+ * cannot, and a run with `output` fails before inference.
138
+ */
139
+ readonly structuredOutput: "none" | "native";
140
+ /**
141
+ * `client` — the provider declares the request's `toolSearch` and answers
142
+ * the model's search calls with it, loading found tools into the
143
+ * conversation; `none` (the default) — the loop declares every tool.
144
+ */
145
+ readonly toolSearch?: "client" | "none";
146
+ /** The route's image input limits; absent, the host sends images as stored. */
147
+ readonly imageInput?: ImageInputLimits;
148
+ }
149
+ /** How a route measures and bounds an input image, in `patchSize`-pixel square patches. */
150
+ export interface ImageInputLimits {
151
+ readonly patchSize: number;
152
+ /** Images are shrunk (aspect kept) to at most this longest side before sending. */
153
+ readonly fitSide: number;
154
+ /** ...and to at most this many patches. */
155
+ readonly fitPatches: number;
156
+ /** One image over this many patches fails the whole request. */
157
+ readonly maxPatches: number;
158
+ }
159
+ export interface ModelRequest {
160
+ readonly step: number;
161
+ readonly messages: ReadonlyArray<ChatMessage>;
162
+ readonly model: string;
163
+ readonly maxOutputTokens?: number;
164
+ readonly tools: ReadonlyArray<ToolDeclaration>;
165
+ readonly deferredTools: ReadonlyArray<ToolDeclaration>;
166
+ readonly toolChoice: ToolChoice;
167
+ readonly reasoningEffort?: string;
168
+ /** See `AgentConfigInput.cacheScope`; a provider without prompt caching ignores it. */
169
+ readonly cacheScope?: string;
170
+ readonly responseFormat?: ResponseFormat;
171
+ readonly previousResponse: CompletionResponse | null;
172
+ /** The only middleware field allowed to persist a canonical history projection. */
173
+ readonly compactionReplacement?: ReadonlyArray<ChatMessage>;
174
+ }
175
+ export type ModelRequestNext = (request: ModelRequest) => MaybePromise<ModelRequest>;
176
+ export type ModelRequestMiddleware = (request: ModelRequest, next: ModelRequestNext) => MaybePromise<ModelRequest>;
177
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/contracts/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,WAAW,EACX,WAAW,EACX,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,QAAQ,EACR,WAAW,EACZ,MAAM,eAAe,CAAA;AACtB,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAEzE,eAAO,MAAM,UAAU;aACrB,IAAI,EAAE,MAAM;aACZ,IAAI,EAAE,MAAM;aACZ,QAAQ,EAAE,UAAU;CACZ,CAAA;AAEV,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,OAAO,UAAU,CAAC,CAAA;AAErE,eAAO,MAAM,YAAY;aACvB,IAAI,EAAE,MAAM;aACZ,UAAU,EAAE,YAAY;aACxB,MAAM,EAAE,Q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oice = {
2
+ AUTO: "auto",
3
+ NONE: "none",
4
+ REQUIRED: "required"
5
+ };
6
+ export const FinishReason = {
7
+ STOP: "stop",
8
+ TOOL_CALLS: "tool_calls",
9
+ LENGTH: "length",
10
+ CONTENT_FILTER: "content_filter"
11
+ };
12
+ export const zeroUsage = () => ({
13
+ prompt_tokens: 0,
14
+ completion_tokens: 0,
15
+ cache_read_tokens: 0,
16
+ cache_write_tokens: 0
17
+ });
18
+ const count = (value) => value ?? 0;
19
+ export const usageInputTokens = (usage) => count(usage.prompt_tokens) + count(usage.cache_read_tokens) + count(usage.cache_write_tokens);
20
+ export const addUsage = (left, right) => ({
21
+ prompt_tokens: count(left.prompt_tokens) + count(right.prompt_tokens),
22
+ completion_tokens: count(left.completion_tokens) + count(right.completion_tokens),
23
+ cache_read_tokens: count(left.cache_read_tokens) + count(right.cache_read_tokens),
24
+ cache_write_tokens: count(left.cache_write_tokens) + count(right.cache_write_tokens)
25
+ });
26
+ //# sourceMappingURL=provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/contracts/provider.ts"],"names":[],"mappings":"AAYA,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,QAAQ,EAAE,UAAU;CACZ,CAAA;AAIV,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,MAAM;IACZ,UAAU,EAAE,YAAY;IACxB,MAAM,EAAE,QAAQ;IAChB,cAAc,EAAE,gBAAgB;CACxB,CAAA;AAWV,MAAM,CAAC,MAAM,SAAS,GAAG,GAAU,EAAE,CAAC,CAAC;IACrC,aAAa,EAAE,CAAC;IAChB,iBAAiB,EAAE,CAAC;IACpB,iBAAiB,EAAE,CAAC;IACpB,kBAAkB,EAAE,CAAC;CACtB,CAAC,CAAA;AAEF,MAAM,KAAK,GAAG,CAAC,KAAyB,EAAU,EAAE,CAAC,KAAK,IAAI,CAAC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