@rowan-agent/models 0.4.4

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.
@@ -0,0 +1,426 @@
1
+ type KnownApi = "openai-completions" | "openai-responses" | "anthropic-messages";
2
+ type Api = KnownApi | (string & {});
3
+ type KnownProvider = "openai" | "anthropic" | "deepseek" | "openrouter" | "groq" | "together" | "fireworks" | "xai" | "cerebras";
4
+ type Provider = KnownProvider | string;
5
+ interface ModelCost {
6
+ input: number;
7
+ output: number;
8
+ cacheRead: number;
9
+ cacheWrite: number;
10
+ }
11
+ interface Model {
12
+ id: string;
13
+ name: string;
14
+ api: Api;
15
+ provider: Provider;
16
+ baseUrl: string;
17
+ reasoning: boolean;
18
+ input: ("text" | "image")[];
19
+ cost: ModelCost;
20
+ contextWindow: number;
21
+ maxTokens: number;
22
+ headers?: Record<string, string>;
23
+ }
24
+ type ProviderModelConfig = {
25
+ id: string;
26
+ name: string;
27
+ api: Api;
28
+ reasoning: boolean;
29
+ input: ("text" | "image")[];
30
+ cost: ModelCost;
31
+ contextWindow: number;
32
+ maxTokens: number;
33
+ };
34
+ type ProviderConfig = {
35
+ name: string;
36
+ baseUrl: string;
37
+ apiKey?: string;
38
+ api: Api;
39
+ streamSimple?: ApiStreamFn;
40
+ headers?: Record<string, string>;
41
+ authHeader?: string;
42
+ models: ProviderModelConfig[];
43
+ oauth?: {
44
+ clientId: string;
45
+ scopes?: string[];
46
+ tokenEndpoint?: string;
47
+ };
48
+ };
49
+ type LlmModelRef = {
50
+ provider: string;
51
+ name: string;
52
+ };
53
+ type LlmTokenUsage = {
54
+ inputTokens?: number;
55
+ outputTokens?: number;
56
+ totalTokens?: number;
57
+ cacheReadTokens?: number;
58
+ cacheWriteTokens?: number;
59
+ };
60
+ type LlmModelUsage = LlmTokenUsage & {
61
+ inputMessages: number;
62
+ };
63
+ type LlmTextContent = {
64
+ type: "text";
65
+ text: string;
66
+ };
67
+ type LlmImageContent = {
68
+ type: "image";
69
+ data: string;
70
+ mimeType: string;
71
+ };
72
+ type LlmThinkingContent = {
73
+ type: "thinking";
74
+ thinking: string;
75
+ signature?: string;
76
+ };
77
+ type LlmToolUseContent = {
78
+ type: "tool_use";
79
+ id: string;
80
+ name: string;
81
+ input: unknown;
82
+ };
83
+ type LlmToolResultContent = {
84
+ type: "tool_result";
85
+ toolUseId: string;
86
+ content: string;
87
+ isError?: boolean;
88
+ };
89
+ type LlmContentPart = LlmTextContent | LlmImageContent | LlmThinkingContent | LlmToolUseContent | LlmToolResultContent;
90
+ type LlmMessage = {
91
+ role: "user" | "assistant" | "tool";
92
+ content: string | LlmContentPart[];
93
+ };
94
+ type LlmToolDefinition = {
95
+ name: string;
96
+ description: string;
97
+ parameters: unknown;
98
+ };
99
+ type LlmToolCall = {
100
+ id: string;
101
+ name: string;
102
+ arguments: unknown;
103
+ };
104
+ type LlmToolChoice = "auto" | "required" | "none" | {
105
+ type: "tool";
106
+ name: string;
107
+ };
108
+ type LlmRequest = {
109
+ model: LlmModelRef;
110
+ system?: string;
111
+ messages: LlmMessage[];
112
+ tools?: LlmToolDefinition[];
113
+ toolChoice?: LlmToolChoice;
114
+ maxTokens?: number;
115
+ temperature?: number;
116
+ };
117
+ type LlmStopReason = "end_turn" | "tool_use" | "max_tokens" | "stop" | "error" | "unknown";
118
+ type LlmResponse = {
119
+ content: string;
120
+ thinking?: string;
121
+ toolCalls?: LlmToolCall[];
122
+ stopReason?: LlmStopReason;
123
+ usage?: LlmTokenUsage;
124
+ };
125
+ type TextBlock = {
126
+ type: "text";
127
+ text: string;
128
+ };
129
+ type ThinkingBlock = {
130
+ type: "thinking";
131
+ thinking: string;
132
+ };
133
+ type ToolCallBlock = {
134
+ type: "tool_call";
135
+ id: string;
136
+ name: string;
137
+ args: string;
138
+ };
139
+ type ContentBlock = TextBlock | ThinkingBlock | ToolCallBlock;
140
+ /**
141
+ * Accumulated assistant message partial, carried by each streaming event.
142
+ * The provider builds this incrementally; the consumer reads it directly.
143
+ */
144
+ type AssistantMessagePartial = {
145
+ role: "assistant";
146
+ contentBlocks: ContentBlock[];
147
+ stopReason?: LlmStopReason;
148
+ };
149
+ type LlmStreamEvent = {
150
+ type: "start";
151
+ partial: AssistantMessagePartial;
152
+ } | {
153
+ type: "text_delta";
154
+ text: string;
155
+ partial: AssistantMessagePartial;
156
+ } | {
157
+ type: "thinking_delta";
158
+ thinking: string;
159
+ partial: AssistantMessagePartial;
160
+ } | {
161
+ type: "tool_call_start";
162
+ id: string;
163
+ name: string;
164
+ partial: AssistantMessagePartial;
165
+ } | {
166
+ type: "tool_call_delta";
167
+ id: string;
168
+ arguments: string;
169
+ partial: AssistantMessagePartial;
170
+ } | {
171
+ type: "tool_call_end";
172
+ id: string;
173
+ name: string;
174
+ arguments: string;
175
+ partial: AssistantMessagePartial;
176
+ } | {
177
+ type: "model_requested";
178
+ model: LlmModelRef;
179
+ usage: LlmModelUsage;
180
+ } | {
181
+ type: "error";
182
+ error: Error;
183
+ } | {
184
+ type: "done";
185
+ response?: LlmResponse;
186
+ };
187
+ declare function textFromPartial(partial: AssistantMessagePartial): string;
188
+ declare function toolCallsFromPartial(partial: AssistantMessagePartial): ToolCallBlock[];
189
+ type LlmStreamOptions = {
190
+ signal?: AbortSignal;
191
+ };
192
+ /**
193
+ * Low-level stream function: receives a full LlmRequest and yields events.
194
+ * This is the function the agent loop consumes.
195
+ */
196
+ type StreamFn = (request: LlmRequest, options: LlmStreamOptions) => AsyncIterable<LlmStreamEvent>;
197
+ /**
198
+ * API-level stream function: receives a resolved Model and yields events.
199
+ * Providers implement this signature. The registry dispatches by model.api.
200
+ */
201
+ type ApiStreamFn = (model: Model, request: LlmRequest, options: LlmStreamOptions) => AsyncIterable<LlmStreamEvent>;
202
+ type AgentContextMessage = {
203
+ id: string;
204
+ role: "system" | "user" | "assistant" | "tool";
205
+ content: string;
206
+ createdAt: string;
207
+ metadata?: Record<string, unknown> & {
208
+ phase?: string;
209
+ toolCalls?: Array<{
210
+ id: string;
211
+ name: string;
212
+ args: unknown;
213
+ }>;
214
+ toolCallId?: string;
215
+ toolName?: string;
216
+ isError?: boolean;
217
+ };
218
+ };
219
+ type AgentContextSkill = {
220
+ name: string;
221
+ description: string;
222
+ filePath: string;
223
+ baseDir: string;
224
+ disableModelInvocation: boolean;
225
+ };
226
+ type Outcome = {
227
+ id: string;
228
+ taskId?: string;
229
+ message: string;
230
+ };
231
+ type ToolCall = {
232
+ id: string;
233
+ name: string;
234
+ args: unknown;
235
+ };
236
+ type ToolResult = {
237
+ toolCallId: string;
238
+ toolName: string;
239
+ ok: boolean;
240
+ content: unknown;
241
+ error?: string;
242
+ };
243
+ type AgentEvent = {
244
+ type: "agent_start";
245
+ sessionId: string;
246
+ ts: string;
247
+ } | {
248
+ type: "agent_end";
249
+ sessionId: string;
250
+ messages: AgentContextMessage[];
251
+ ts: string;
252
+ } | {
253
+ type: "turn_start";
254
+ content: AgentContextMessage[];
255
+ ts: string;
256
+ } | {
257
+ type: "turn_end";
258
+ content: AgentContextMessage[];
259
+ outcome?: Outcome;
260
+ ts: string;
261
+ } | {
262
+ type: "model_requested";
263
+ model: LlmModelRef;
264
+ usage: LlmModelUsage;
265
+ ts: string;
266
+ } | {
267
+ type: "phase_start";
268
+ phase: string;
269
+ ts: string;
270
+ } | {
271
+ type: "phase_end";
272
+ phase: string;
273
+ ts: string;
274
+ } | {
275
+ type: "message_start";
276
+ message: AgentContextMessage;
277
+ ts: string;
278
+ } | {
279
+ type: "message_update";
280
+ message: AgentContextMessage;
281
+ delta: string;
282
+ ts: string;
283
+ } | {
284
+ type: "message_end";
285
+ message: AgentContextMessage;
286
+ ts: string;
287
+ } | {
288
+ type: "tool_execution_start";
289
+ toolCallId: string;
290
+ toolName: string;
291
+ args: unknown;
292
+ ts: string;
293
+ } | {
294
+ type: "tool_execution_update";
295
+ toolCallId: string;
296
+ toolName: string;
297
+ args: unknown;
298
+ partialResult: unknown;
299
+ ts: string;
300
+ } | {
301
+ type: "tool_execution_end";
302
+ toolCallId: string;
303
+ toolName: string;
304
+ result: ToolResult;
305
+ isError: boolean;
306
+ ts: string;
307
+ };
308
+ type AgentEventListener = ((event: AgentEvent) => void | Promise<void>) & {
309
+ flush?: () => void | Promise<void>;
310
+ };
311
+
312
+ declare class ProviderError extends Error {
313
+ readonly code: string;
314
+ readonly status?: number;
315
+ readonly retryable: boolean;
316
+ readonly details?: Record<string, unknown>;
317
+ constructor(input: {
318
+ code: string;
319
+ message: string;
320
+ status?: number;
321
+ retryable?: boolean;
322
+ details?: Record<string, unknown>;
323
+ });
324
+ }
325
+
326
+ type ProviderFetch = (input: Parameters<typeof fetch>[0], init?: Parameters<typeof fetch>[1]) => ReturnType<typeof fetch>;
327
+ type BaseProviderConfig = {
328
+ baseUrl: string;
329
+ apiKey: string;
330
+ model: string;
331
+ temperature?: number;
332
+ maxTokens?: number;
333
+ timeoutMs?: number;
334
+ maxRetries?: number;
335
+ retryDelayMs?: number;
336
+ fetch?: ProviderFetch;
337
+ };
338
+
339
+ type OpenAICompletionsConfig = BaseProviderConfig & {
340
+ responseFormat?: boolean;
341
+ };
342
+ type ResolveOpenAICompletionsConfigInput = {
343
+ baseUrl?: string;
344
+ apiKey?: string;
345
+ model?: string;
346
+ temperature?: number;
347
+ maxTokens?: number;
348
+ timeoutMs?: number;
349
+ maxRetries?: number;
350
+ retryDelayMs?: number;
351
+ fetch?: ProviderFetch;
352
+ responseFormat?: boolean;
353
+ env?: Record<string, string | undefined>;
354
+ };
355
+ declare function resolveOpenAICompletionsConfig(input?: ResolveOpenAICompletionsConfigInput): OpenAICompletionsConfig;
356
+ declare function createOpenAICompletionsStream(config: OpenAICompletionsConfig): StreamFn;
357
+ /**
358
+ * ApiStreamFn-compatible stream function for OpenAI Chat Completions API.
359
+ * Resolves config from the Model descriptor and environment.
360
+ */
361
+ declare const streamOpenAICompletions: ApiStreamFn;
362
+ declare function callOpenAICompletions(config: OpenAICompletionsConfig, request: LlmRequest, options?: LlmStreamOptions): Promise<{
363
+ content: string;
364
+ usage?: LlmTokenUsage;
365
+ }>;
366
+
367
+ type OpenAIResponsesConfig = BaseProviderConfig & {
368
+ reasoningEffort?: "low" | "medium" | "high";
369
+ };
370
+ type ResolveOpenAIResponsesConfigInput = {
371
+ baseUrl?: string;
372
+ apiKey?: string;
373
+ model?: string;
374
+ temperature?: number;
375
+ maxTokens?: number;
376
+ timeoutMs?: number;
377
+ maxRetries?: number;
378
+ retryDelayMs?: number;
379
+ fetch?: ProviderFetch;
380
+ reasoningEffort?: "low" | "medium" | "high";
381
+ env?: Record<string, string | undefined>;
382
+ };
383
+ declare function resolveOpenAIResponsesConfig(input?: ResolveOpenAIResponsesConfigInput): OpenAIResponsesConfig;
384
+ declare function createOpenAIResponsesStream(config: OpenAIResponsesConfig): StreamFn;
385
+ /**
386
+ * ApiStreamFn-compatible stream function for OpenAI Responses API.
387
+ * Resolves config from the Model descriptor and environment.
388
+ */
389
+ declare const streamOpenAIResponses: ApiStreamFn;
390
+
391
+ type AnthropicConfig = {
392
+ baseUrl: string;
393
+ apiKey: string;
394
+ model: string;
395
+ maxTokens?: number;
396
+ timeoutMs?: number;
397
+ maxRetries?: number;
398
+ retryDelayMs?: number;
399
+ fetch?: ProviderFetch;
400
+ thinking?: {
401
+ budgetTokens: number;
402
+ };
403
+ };
404
+ type ResolveAnthropicConfigInput = {
405
+ baseUrl?: string;
406
+ apiKey?: string;
407
+ model?: string;
408
+ maxTokens?: number;
409
+ timeoutMs?: number;
410
+ maxRetries?: number;
411
+ retryDelayMs?: number;
412
+ fetch?: ProviderFetch;
413
+ thinking?: {
414
+ budgetTokens: number;
415
+ };
416
+ env?: Record<string, string | undefined>;
417
+ };
418
+ declare function resolveAnthropicConfig(input?: ResolveAnthropicConfigInput): AnthropicConfig;
419
+ declare function createAnthropicStream(config: AnthropicConfig): StreamFn;
420
+ /**
421
+ * ApiStreamFn-compatible stream function for Anthropic Messages API.
422
+ * Resolves config from the Model descriptor and environment.
423
+ */
424
+ declare const streamAnthropic: ApiStreamFn;
425
+
426
+ export { resolveAnthropicConfig as $, type Api as A, type BaseProviderConfig as B, type ContentBlock as C, type OpenAIResponsesConfig as D, type Outcome as E, type ProviderConfig as F, ProviderError as G, type ProviderFetch as H, type ProviderModelConfig as I, type ResolveOpenAICompletionsConfigInput as J, type KnownApi as K, type LlmTokenUsage as L, type Model as M, type ResolveOpenAIResponsesConfigInput as N, type OpenAICompletionsConfig as O, type Provider as P, type ThinkingBlock as Q, type ResolveAnthropicConfigInput as R, type StreamFn as S, type TextBlock as T, type ToolCall as U, type ToolCallBlock as V, type ToolResult as W, callOpenAICompletions as X, createAnthropicStream as Y, createOpenAICompletionsStream as Z, createOpenAIResponsesStream as _, type ApiStreamFn as a, resolveOpenAICompletionsConfig as a0, resolveOpenAIResponsesConfig as a1, streamAnthropic as a2, streamOpenAICompletions as a3, streamOpenAIResponses as a4, textFromPartial as a5, toolCallsFromPartial as a6, type LlmRequest as b, type LlmStreamOptions as c, type LlmStreamEvent as d, type AgentContextMessage as e, type AgentContextSkill as f, type AgentEvent as g, type AgentEventListener as h, type AnthropicConfig as i, type AssistantMessagePartial as j, type KnownProvider as k, type LlmContentPart as l, type LlmImageContent as m, type LlmMessage as n, type LlmModelRef as o, type LlmModelUsage as p, type LlmResponse as q, type LlmStopReason as r, type LlmTextContent as s, type LlmThinkingContent as t, type LlmToolCall as u, type LlmToolChoice as v, type LlmToolDefinition as w, type LlmToolResultContent as x, type LlmToolUseContent as y, type ModelCost as z };