@rowan-agent/models 0.4.4 → 0.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +169 -22
- package/dist/{chunk-J6S6ZJJA.js → chunk-C4RRYNAJ.js} +40 -26
- package/dist/{index-ChnUfIk1.d.cts → index-BGAiAdlQ.d.cts} +36 -33
- package/dist/{index-ChnUfIk1.d.ts → index-BGAiAdlQ.d.ts} +36 -33
- package/dist/index.cjs +67 -53
- package/dist/index.d.cts +10 -10
- package/dist/index.d.ts +10 -10
- package/dist/index.js +28 -28
- package/dist/providers/index.cjs +40 -26
- package/dist/providers/index.d.cts +1 -1
- package/dist/providers/index.d.ts +1 -1
- package/dist/providers/index.js +1 -1
- package/package.json +7 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
type
|
|
2
|
-
type
|
|
1
|
+
type KnownProtocol = "openai-completions" | "openai-responses" | "anthropic-messages";
|
|
2
|
+
type Protocol = KnownProtocol | (string & {});
|
|
3
3
|
type KnownProvider = "openai" | "anthropic" | "deepseek" | "openrouter" | "groq" | "together" | "fireworks" | "xai" | "cerebras";
|
|
4
4
|
type Provider = KnownProvider | string;
|
|
5
5
|
interface ModelCost {
|
|
@@ -10,8 +10,8 @@ interface ModelCost {
|
|
|
10
10
|
}
|
|
11
11
|
interface Model {
|
|
12
12
|
id: string;
|
|
13
|
-
name
|
|
14
|
-
|
|
13
|
+
name?: string;
|
|
14
|
+
protocol: Protocol;
|
|
15
15
|
provider: Provider;
|
|
16
16
|
baseUrl: string;
|
|
17
17
|
reasoning: boolean;
|
|
@@ -20,11 +20,15 @@ interface Model {
|
|
|
20
20
|
contextWindow: number;
|
|
21
21
|
maxTokens: number;
|
|
22
22
|
headers?: Record<string, string>;
|
|
23
|
+
apiKey?: string;
|
|
24
|
+
timeoutMs?: number;
|
|
25
|
+
maxRetries?: number;
|
|
26
|
+
retryDelayMs?: number;
|
|
23
27
|
}
|
|
24
28
|
type ProviderModelConfig = {
|
|
25
29
|
id: string;
|
|
26
|
-
name
|
|
27
|
-
|
|
30
|
+
name?: string;
|
|
31
|
+
protocol: Protocol;
|
|
28
32
|
reasoning: boolean;
|
|
29
33
|
input: ("text" | "image")[];
|
|
30
34
|
cost: ModelCost;
|
|
@@ -32,10 +36,10 @@ type ProviderModelConfig = {
|
|
|
32
36
|
maxTokens: number;
|
|
33
37
|
};
|
|
34
38
|
type ProviderConfig = {
|
|
35
|
-
|
|
39
|
+
id: string;
|
|
36
40
|
baseUrl: string;
|
|
37
|
-
apiKey
|
|
38
|
-
|
|
41
|
+
apiKey: string;
|
|
42
|
+
protocol: Protocol;
|
|
39
43
|
streamSimple?: ApiStreamFn;
|
|
40
44
|
headers?: Record<string, string>;
|
|
41
45
|
authHeader?: string;
|
|
@@ -48,7 +52,7 @@ type ProviderConfig = {
|
|
|
48
52
|
};
|
|
49
53
|
type LlmModelRef = {
|
|
50
54
|
provider: string;
|
|
51
|
-
|
|
55
|
+
id: string;
|
|
52
56
|
};
|
|
53
57
|
type LlmTokenUsage = {
|
|
54
58
|
inputTokens?: number;
|
|
@@ -196,37 +200,39 @@ type LlmStreamOptions = {
|
|
|
196
200
|
type StreamFn = (request: LlmRequest, options: LlmStreamOptions) => AsyncIterable<LlmStreamEvent>;
|
|
197
201
|
/**
|
|
198
202
|
* API-level stream function: receives a resolved Model and yields events.
|
|
199
|
-
* Providers implement this signature. The registry dispatches by model.
|
|
203
|
+
* Providers implement this signature. The registry dispatches by model.protocol.
|
|
200
204
|
*/
|
|
201
205
|
type ApiStreamFn = (model: Model, request: LlmRequest, options: LlmStreamOptions) => AsyncIterable<LlmStreamEvent>;
|
|
202
|
-
type
|
|
206
|
+
type AgentMessage = {
|
|
203
207
|
id: string;
|
|
204
208
|
role: "system" | "user" | "assistant" | "tool";
|
|
205
|
-
content: string;
|
|
209
|
+
content: string | LlmContentPart[];
|
|
206
210
|
createdAt: string;
|
|
207
211
|
metadata?: Record<string, unknown> & {
|
|
208
212
|
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
213
|
};
|
|
218
214
|
};
|
|
219
|
-
type
|
|
215
|
+
type Skill = {
|
|
220
216
|
name: string;
|
|
221
217
|
description: string;
|
|
218
|
+
/** Absolute path to the SKILL.md file */
|
|
222
219
|
filePath: string;
|
|
220
|
+
/** Directory containing the SKILL.md file */
|
|
223
221
|
baseDir: string;
|
|
222
|
+
/** Full body content of the SKILL.md (after frontmatter) */
|
|
223
|
+
content: string;
|
|
224
224
|
disableModelInvocation: boolean;
|
|
225
225
|
};
|
|
226
226
|
type Outcome = {
|
|
227
227
|
id: string;
|
|
228
|
-
taskId?: string;
|
|
229
228
|
message: string;
|
|
229
|
+
toolResults?: Array<{
|
|
230
|
+
toolCallId: string;
|
|
231
|
+
toolName: string;
|
|
232
|
+
ok: boolean;
|
|
233
|
+
content: unknown;
|
|
234
|
+
error?: string;
|
|
235
|
+
}>;
|
|
230
236
|
};
|
|
231
237
|
type ToolCall = {
|
|
232
238
|
id: string;
|
|
@@ -247,15 +253,15 @@ type AgentEvent = {
|
|
|
247
253
|
} | {
|
|
248
254
|
type: "agent_end";
|
|
249
255
|
sessionId: string;
|
|
250
|
-
messages:
|
|
256
|
+
messages: AgentMessage[];
|
|
251
257
|
ts: string;
|
|
252
258
|
} | {
|
|
253
259
|
type: "turn_start";
|
|
254
|
-
content:
|
|
260
|
+
content: AgentMessage[];
|
|
255
261
|
ts: string;
|
|
256
262
|
} | {
|
|
257
263
|
type: "turn_end";
|
|
258
|
-
content:
|
|
264
|
+
content: AgentMessage[];
|
|
259
265
|
outcome?: Outcome;
|
|
260
266
|
ts: string;
|
|
261
267
|
} | {
|
|
@@ -273,16 +279,16 @@ type AgentEvent = {
|
|
|
273
279
|
ts: string;
|
|
274
280
|
} | {
|
|
275
281
|
type: "message_start";
|
|
276
|
-
message:
|
|
282
|
+
message: AgentMessage;
|
|
277
283
|
ts: string;
|
|
278
284
|
} | {
|
|
279
285
|
type: "message_update";
|
|
280
|
-
message:
|
|
286
|
+
message: AgentMessage;
|
|
281
287
|
delta: string;
|
|
282
288
|
ts: string;
|
|
283
289
|
} | {
|
|
284
290
|
type: "message_end";
|
|
285
|
-
message:
|
|
291
|
+
message: AgentMessage;
|
|
286
292
|
ts: string;
|
|
287
293
|
} | {
|
|
288
294
|
type: "tool_execution_start";
|
|
@@ -350,7 +356,6 @@ type ResolveOpenAICompletionsConfigInput = {
|
|
|
350
356
|
retryDelayMs?: number;
|
|
351
357
|
fetch?: ProviderFetch;
|
|
352
358
|
responseFormat?: boolean;
|
|
353
|
-
env?: Record<string, string | undefined>;
|
|
354
359
|
};
|
|
355
360
|
declare function resolveOpenAICompletionsConfig(input?: ResolveOpenAICompletionsConfigInput): OpenAICompletionsConfig;
|
|
356
361
|
declare function createOpenAICompletionsStream(config: OpenAICompletionsConfig): StreamFn;
|
|
@@ -378,7 +383,6 @@ type ResolveOpenAIResponsesConfigInput = {
|
|
|
378
383
|
retryDelayMs?: number;
|
|
379
384
|
fetch?: ProviderFetch;
|
|
380
385
|
reasoningEffort?: "low" | "medium" | "high";
|
|
381
|
-
env?: Record<string, string | undefined>;
|
|
382
386
|
};
|
|
383
387
|
declare function resolveOpenAIResponsesConfig(input?: ResolveOpenAIResponsesConfigInput): OpenAIResponsesConfig;
|
|
384
388
|
declare function createOpenAIResponsesStream(config: OpenAIResponsesConfig): StreamFn;
|
|
@@ -413,7 +417,6 @@ type ResolveAnthropicConfigInput = {
|
|
|
413
417
|
thinking?: {
|
|
414
418
|
budgetTokens: number;
|
|
415
419
|
};
|
|
416
|
-
env?: Record<string, string | undefined>;
|
|
417
420
|
};
|
|
418
421
|
declare function resolveAnthropicConfig(input?: ResolveAnthropicConfigInput): AnthropicConfig;
|
|
419
422
|
declare function createAnthropicStream(config: AnthropicConfig): StreamFn;
|
|
@@ -423,4 +426,4 @@ declare function createAnthropicStream(config: AnthropicConfig): StreamFn;
|
|
|
423
426
|
*/
|
|
424
427
|
declare const streamAnthropic: ApiStreamFn;
|
|
425
428
|
|
|
426
|
-
export { resolveAnthropicConfig as $, type
|
|
429
|
+
export { resolveAnthropicConfig as $, type ApiStreamFn as A, type BaseProviderConfig as B, type ContentBlock as C, type Outcome as D, type ProviderConfig as E, ProviderError as F, type ProviderFetch as G, type ProviderModelConfig as H, type ResolveOpenAICompletionsConfigInput as I, type ResolveOpenAIResponsesConfigInput as J, type KnownProtocol as K, type LlmTokenUsage as L, type Model as M, type Skill 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 Protocol 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 AgentEvent as e, type AgentEventListener as f, type AgentMessage as g, type AnthropicConfig as h, type AssistantMessagePartial as i, type KnownProvider as j, type LlmContentPart as k, type LlmImageContent as l, type LlmMessage as m, type LlmModelRef as n, type LlmModelUsage as o, type LlmResponse as p, type LlmStopReason as q, type LlmTextContent as r, type LlmThinkingContent as s, type LlmToolCall as t, type LlmToolChoice as u, type LlmToolDefinition as v, type LlmToolResultContent as w, type LlmToolUseContent as x, type ModelCost as y, type OpenAIResponsesConfig as z };
|
package/dist/index.cjs
CHANGED
|
@@ -221,7 +221,7 @@ var MODELS = {
|
|
|
221
221
|
"claude-sonnet-4-20250514": {
|
|
222
222
|
id: "claude-sonnet-4-20250514",
|
|
223
223
|
name: "Claude Sonnet 4",
|
|
224
|
-
|
|
224
|
+
protocol: "anthropic-messages",
|
|
225
225
|
provider: "anthropic",
|
|
226
226
|
baseUrl: "https://api.anthropic.com",
|
|
227
227
|
reasoning: true,
|
|
@@ -233,7 +233,7 @@ var MODELS = {
|
|
|
233
233
|
"claude-opus-4-20250514": {
|
|
234
234
|
id: "claude-opus-4-20250514",
|
|
235
235
|
name: "Claude Opus 4",
|
|
236
|
-
|
|
236
|
+
protocol: "anthropic-messages",
|
|
237
237
|
provider: "anthropic",
|
|
238
238
|
baseUrl: "https://api.anthropic.com",
|
|
239
239
|
reasoning: true,
|
|
@@ -245,7 +245,7 @@ var MODELS = {
|
|
|
245
245
|
"claude-haiku-4-20250514": {
|
|
246
246
|
id: "claude-haiku-4-20250514",
|
|
247
247
|
name: "Claude Haiku 4",
|
|
248
|
-
|
|
248
|
+
protocol: "anthropic-messages",
|
|
249
249
|
provider: "anthropic",
|
|
250
250
|
baseUrl: "https://api.anthropic.com",
|
|
251
251
|
reasoning: false,
|
|
@@ -259,7 +259,7 @@ var MODELS = {
|
|
|
259
259
|
"gpt-4o": {
|
|
260
260
|
id: "gpt-4o",
|
|
261
261
|
name: "GPT-4o",
|
|
262
|
-
|
|
262
|
+
protocol: "openai-completions",
|
|
263
263
|
provider: "openai",
|
|
264
264
|
baseUrl: "https://api.openai.com/v1",
|
|
265
265
|
reasoning: false,
|
|
@@ -271,7 +271,7 @@ var MODELS = {
|
|
|
271
271
|
"gpt-4o-mini": {
|
|
272
272
|
id: "gpt-4o-mini",
|
|
273
273
|
name: "GPT-4o Mini",
|
|
274
|
-
|
|
274
|
+
protocol: "openai-completions",
|
|
275
275
|
provider: "openai",
|
|
276
276
|
baseUrl: "https://api.openai.com/v1",
|
|
277
277
|
reasoning: false,
|
|
@@ -283,7 +283,7 @@ var MODELS = {
|
|
|
283
283
|
"o3": {
|
|
284
284
|
id: "o3",
|
|
285
285
|
name: "o3",
|
|
286
|
-
|
|
286
|
+
protocol: "openai-responses",
|
|
287
287
|
provider: "openai",
|
|
288
288
|
baseUrl: "https://api.openai.com/v1",
|
|
289
289
|
reasoning: true,
|
|
@@ -295,7 +295,7 @@ var MODELS = {
|
|
|
295
295
|
"o4-mini": {
|
|
296
296
|
id: "o4-mini",
|
|
297
297
|
name: "o4-mini",
|
|
298
|
-
|
|
298
|
+
protocol: "openai-responses",
|
|
299
299
|
provider: "openai",
|
|
300
300
|
baseUrl: "https://api.openai.com/v1",
|
|
301
301
|
reasoning: true,
|
|
@@ -307,7 +307,7 @@ var MODELS = {
|
|
|
307
307
|
"gpt-4.1": {
|
|
308
308
|
id: "gpt-4.1",
|
|
309
309
|
name: "GPT-4.1",
|
|
310
|
-
|
|
310
|
+
protocol: "openai-completions",
|
|
311
311
|
provider: "openai",
|
|
312
312
|
baseUrl: "https://api.openai.com/v1",
|
|
313
313
|
reasoning: false,
|
|
@@ -319,7 +319,7 @@ var MODELS = {
|
|
|
319
319
|
"gpt-4.1-mini": {
|
|
320
320
|
id: "gpt-4.1-mini",
|
|
321
321
|
name: "GPT-4.1 Mini",
|
|
322
|
-
|
|
322
|
+
protocol: "openai-completions",
|
|
323
323
|
provider: "openai",
|
|
324
324
|
baseUrl: "https://api.openai.com/v1",
|
|
325
325
|
reasoning: false,
|
|
@@ -333,7 +333,7 @@ var MODELS = {
|
|
|
333
333
|
"deepseek-chat": {
|
|
334
334
|
id: "deepseek-chat",
|
|
335
335
|
name: "DeepSeek V3",
|
|
336
|
-
|
|
336
|
+
protocol: "openai-completions",
|
|
337
337
|
provider: "deepseek",
|
|
338
338
|
baseUrl: "https://api.deepseek.com/v1",
|
|
339
339
|
reasoning: false,
|
|
@@ -345,7 +345,7 @@ var MODELS = {
|
|
|
345
345
|
"deepseek-reasoner": {
|
|
346
346
|
id: "deepseek-reasoner",
|
|
347
347
|
name: "DeepSeek R1",
|
|
348
|
-
|
|
348
|
+
protocol: "openai-completions",
|
|
349
349
|
provider: "deepseek",
|
|
350
350
|
baseUrl: "https://api.deepseek.com/v1",
|
|
351
351
|
reasoning: true,
|
|
@@ -359,7 +359,7 @@ var MODELS = {
|
|
|
359
359
|
"anthropic/claude-sonnet-4": {
|
|
360
360
|
id: "anthropic/claude-sonnet-4",
|
|
361
361
|
name: "Claude Sonnet 4 (OpenRouter)",
|
|
362
|
-
|
|
362
|
+
protocol: "openai-completions",
|
|
363
363
|
provider: "openrouter",
|
|
364
364
|
baseUrl: "https://openrouter.ai/api/v1",
|
|
365
365
|
reasoning: true,
|
|
@@ -386,9 +386,6 @@ var ProviderError = class extends Error {
|
|
|
386
386
|
this.details = input.details;
|
|
387
387
|
}
|
|
388
388
|
};
|
|
389
|
-
function defaultEnv() {
|
|
390
|
-
return process.env;
|
|
391
|
-
}
|
|
392
389
|
function normalizeBaseUrl(baseUrl) {
|
|
393
390
|
return baseUrl.replace(/\/+$/, "");
|
|
394
391
|
}
|
|
@@ -525,17 +522,24 @@ function normalizeUsage(usage) {
|
|
|
525
522
|
function summarizeRequestUsage(request) {
|
|
526
523
|
return { inputMessages: request.messages.length + (request.system ? 1 : 0) };
|
|
527
524
|
}
|
|
525
|
+
function sanitizeToolInput(input) {
|
|
526
|
+
if (typeof input !== "string") return input;
|
|
527
|
+
try {
|
|
528
|
+
return JSON.parse(input);
|
|
529
|
+
} catch {
|
|
530
|
+
return input;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
528
533
|
|
|
529
534
|
// src/providers/openai-completions.ts
|
|
530
535
|
function resolveOpenAICompletionsConfig(input = {}) {
|
|
531
|
-
const
|
|
532
|
-
const
|
|
533
|
-
const
|
|
534
|
-
const model = nonEmpty(input.model) ?? nonEmpty(env.ROWAN_MODEL);
|
|
536
|
+
const baseUrl = nonEmpty(input.baseUrl) ?? "https://api.openai.com/v1";
|
|
537
|
+
const apiKey = nonEmpty(input.apiKey);
|
|
538
|
+
const model = nonEmpty(input.model);
|
|
535
539
|
return {
|
|
536
540
|
baseUrl: normalizeBaseUrl(baseUrl),
|
|
537
|
-
apiKey: requireValue("API key", apiKey, "set
|
|
538
|
-
model: requireValue("model", model, "
|
|
541
|
+
apiKey: requireValue("API key", apiKey, "model.apiKey is required (set apiKey in config.yaml or pass --api-key)"),
|
|
542
|
+
model: requireValue("model", model, "model.id is required"),
|
|
539
543
|
...input.temperature !== void 0 ? { temperature: input.temperature } : {},
|
|
540
544
|
...input.maxTokens !== void 0 ? { maxTokens: input.maxTokens } : {},
|
|
541
545
|
...input.timeoutMs !== void 0 ? { timeoutMs: input.timeoutMs } : {},
|
|
@@ -611,7 +615,7 @@ function convertMessages(messages) {
|
|
|
611
615
|
type: "function",
|
|
612
616
|
function: {
|
|
613
617
|
name: p.name,
|
|
614
|
-
arguments:
|
|
618
|
+
arguments: JSON.stringify(sanitizeToolInput(p.input))
|
|
615
619
|
}
|
|
616
620
|
}));
|
|
617
621
|
result.push({ role: "assistant", content: text, tool_calls: toolCalls });
|
|
@@ -863,7 +867,11 @@ function createOpenAICompletionsStream(config) {
|
|
|
863
867
|
var streamOpenAICompletions = (model, request, options) => {
|
|
864
868
|
const config = resolveOpenAICompletionsConfig({
|
|
865
869
|
baseUrl: model.baseUrl,
|
|
866
|
-
model: model.id
|
|
870
|
+
model: model.id,
|
|
871
|
+
apiKey: model.apiKey,
|
|
872
|
+
timeoutMs: model.timeoutMs,
|
|
873
|
+
maxRetries: model.maxRetries,
|
|
874
|
+
retryDelayMs: model.retryDelayMs
|
|
867
875
|
});
|
|
868
876
|
return streamChatCompletions(config, request, options);
|
|
869
877
|
};
|
|
@@ -901,14 +909,13 @@ async function callOpenAICompletions(config, request, options = {}) {
|
|
|
901
909
|
|
|
902
910
|
// src/providers/openai-responses.ts
|
|
903
911
|
function resolveOpenAIResponsesConfig(input = {}) {
|
|
904
|
-
const
|
|
905
|
-
const
|
|
906
|
-
const
|
|
907
|
-
const model = nonEmpty(input.model) ?? nonEmpty(env.ROWAN_MODEL);
|
|
912
|
+
const baseUrl = nonEmpty(input.baseUrl) ?? "https://api.openai.com/v1";
|
|
913
|
+
const apiKey = nonEmpty(input.apiKey);
|
|
914
|
+
const model = nonEmpty(input.model);
|
|
908
915
|
return {
|
|
909
916
|
baseUrl: normalizeBaseUrl(baseUrl),
|
|
910
|
-
apiKey: requireValue("API key", apiKey, "set
|
|
911
|
-
model: requireValue("model", model, "
|
|
917
|
+
apiKey: requireValue("API key", apiKey, "model.apiKey is required (set apiKey in config.yaml or pass --api-key)"),
|
|
918
|
+
model: requireValue("model", model, "model.id is required"),
|
|
912
919
|
...input.temperature !== void 0 ? { temperature: input.temperature } : {},
|
|
913
920
|
...input.maxTokens !== void 0 ? { maxTokens: input.maxTokens } : {},
|
|
914
921
|
...input.timeoutMs !== void 0 ? { timeoutMs: input.timeoutMs } : {},
|
|
@@ -955,7 +962,7 @@ function convertMessages2(messages) {
|
|
|
955
962
|
type: "function_call",
|
|
956
963
|
id: part.id,
|
|
957
964
|
name: part.name,
|
|
958
|
-
arguments:
|
|
965
|
+
arguments: JSON.stringify(sanitizeToolInput(part.input))
|
|
959
966
|
});
|
|
960
967
|
}
|
|
961
968
|
}
|
|
@@ -1186,7 +1193,11 @@ function createOpenAIResponsesStream(config) {
|
|
|
1186
1193
|
var streamOpenAIResponses = (model, request, options) => {
|
|
1187
1194
|
const config = resolveOpenAIResponsesConfig({
|
|
1188
1195
|
baseUrl: model.baseUrl,
|
|
1189
|
-
model: model.id
|
|
1196
|
+
model: model.id,
|
|
1197
|
+
apiKey: model.apiKey,
|
|
1198
|
+
timeoutMs: model.timeoutMs,
|
|
1199
|
+
maxRetries: model.maxRetries,
|
|
1200
|
+
retryDelayMs: model.retryDelayMs
|
|
1190
1201
|
});
|
|
1191
1202
|
return streamResponses(config, request, options);
|
|
1192
1203
|
};
|
|
@@ -1194,14 +1205,13 @@ var streamOpenAIResponses = (model, request, options) => {
|
|
|
1194
1205
|
// src/providers/anthropic.ts
|
|
1195
1206
|
var DEFAULT_MAX_TOKENS = 8192;
|
|
1196
1207
|
function resolveAnthropicConfig(input = {}) {
|
|
1197
|
-
const
|
|
1198
|
-
const
|
|
1199
|
-
const
|
|
1200
|
-
const model = nonEmpty(input.model) ?? nonEmpty(env.ROWAN_MODEL);
|
|
1208
|
+
const baseUrl = nonEmpty(input.baseUrl) ?? "https://api.anthropic.com";
|
|
1209
|
+
const apiKey = nonEmpty(input.apiKey);
|
|
1210
|
+
const model = nonEmpty(input.model);
|
|
1201
1211
|
return {
|
|
1202
1212
|
baseUrl: normalizeBaseUrl(baseUrl),
|
|
1203
|
-
apiKey: requireValue("API key", apiKey, "set
|
|
1204
|
-
model: requireValue("model", model, "
|
|
1213
|
+
apiKey: requireValue("API key", apiKey, "model.apiKey is required (set apiKey in config.yaml or pass --api-key)"),
|
|
1214
|
+
model: requireValue("model", model, "model.id is required"),
|
|
1205
1215
|
...input.maxTokens !== void 0 ? { maxTokens: input.maxTokens } : {},
|
|
1206
1216
|
...input.timeoutMs !== void 0 ? { timeoutMs: input.timeoutMs } : {},
|
|
1207
1217
|
...input.maxRetries !== void 0 ? { maxRetries: input.maxRetries } : {},
|
|
@@ -1487,7 +1497,11 @@ function createAnthropicStream(config) {
|
|
|
1487
1497
|
var streamAnthropic = (model, request, options) => {
|
|
1488
1498
|
const config = resolveAnthropicConfig({
|
|
1489
1499
|
baseUrl: model.baseUrl,
|
|
1490
|
-
model: model.id
|
|
1500
|
+
model: model.id,
|
|
1501
|
+
apiKey: model.apiKey,
|
|
1502
|
+
timeoutMs: model.timeoutMs,
|
|
1503
|
+
maxRetries: model.maxRetries,
|
|
1504
|
+
retryDelayMs: model.retryDelayMs
|
|
1491
1505
|
});
|
|
1492
1506
|
return streamAnthropicMessages(config, request, options);
|
|
1493
1507
|
};
|
|
@@ -1495,10 +1509,10 @@ var streamAnthropic = (model, request, options) => {
|
|
|
1495
1509
|
// src/registry.ts
|
|
1496
1510
|
var apiProviderRegistry = /* @__PURE__ */ new Map();
|
|
1497
1511
|
function registerApiProvider(provider) {
|
|
1498
|
-
apiProviderRegistry.set(provider.
|
|
1512
|
+
apiProviderRegistry.set(provider.protocol, provider);
|
|
1499
1513
|
}
|
|
1500
|
-
function getApiProvider(
|
|
1501
|
-
return apiProviderRegistry.get(
|
|
1514
|
+
function getApiProvider(protocol) {
|
|
1515
|
+
return apiProviderRegistry.get(protocol);
|
|
1502
1516
|
}
|
|
1503
1517
|
function listApiProviders() {
|
|
1504
1518
|
return [...apiProviderRegistry.keys()];
|
|
@@ -1506,30 +1520,30 @@ function listApiProviders() {
|
|
|
1506
1520
|
function clearApiProviders() {
|
|
1507
1521
|
apiProviderRegistry.clear();
|
|
1508
1522
|
}
|
|
1509
|
-
function unregisterApiProvider(
|
|
1510
|
-
return apiProviderRegistry.delete(
|
|
1523
|
+
function unregisterApiProvider(protocol) {
|
|
1524
|
+
return apiProviderRegistry.delete(protocol);
|
|
1511
1525
|
}
|
|
1512
1526
|
function registerBuiltInApiProviders() {
|
|
1513
|
-
registerApiProvider({
|
|
1514
|
-
registerApiProvider({
|
|
1515
|
-
registerApiProvider({
|
|
1527
|
+
registerApiProvider({ protocol: "openai-completions", stream: streamOpenAICompletions });
|
|
1528
|
+
registerApiProvider({ protocol: "openai-responses", stream: streamOpenAIResponses });
|
|
1529
|
+
registerApiProvider({ protocol: "anthropic-messages", stream: streamAnthropic });
|
|
1516
1530
|
}
|
|
1517
1531
|
function stream(model, request, options) {
|
|
1518
|
-
const provider = apiProviderRegistry.get(model.
|
|
1532
|
+
const provider = apiProviderRegistry.get(model.protocol);
|
|
1519
1533
|
if (!provider) {
|
|
1520
1534
|
throw new Error(
|
|
1521
|
-
`No API provider registered for
|
|
1535
|
+
`No API provider registered for protocol "${model.protocol}". Registered: ${[...apiProviderRegistry.keys()].join(", ") || "(none)"}. Call registerBuiltInApiProviders() or registerApiProvider() first.`
|
|
1522
1536
|
);
|
|
1523
1537
|
}
|
|
1524
1538
|
return provider.stream(model, request, options);
|
|
1525
1539
|
}
|
|
1526
1540
|
function streamByRef(ref, request, options = {}) {
|
|
1527
|
-
const model = typeof ref === "string" ? resolveModel(ref) : getModel(ref.provider, ref.
|
|
1541
|
+
const model = typeof ref === "string" ? resolveModel(ref) : getModel(ref.provider, ref.id);
|
|
1528
1542
|
if (!model) {
|
|
1529
|
-
const key = typeof ref === "string" ? ref : `${ref.provider}/${ref.
|
|
1543
|
+
const key = typeof ref === "string" ? ref : `${ref.provider}/${ref.id}`;
|
|
1530
1544
|
throw new Error(`Model not found: "${key}". Register it with registerModel() first.`);
|
|
1531
1545
|
}
|
|
1532
|
-
return stream(model, { ...request, model: { provider: model.provider,
|
|
1546
|
+
return stream(model, { ...request, model: { provider: model.provider, id: model.id } }, options);
|
|
1533
1547
|
}
|
|
1534
1548
|
var legacyProviders = /* @__PURE__ */ new Map();
|
|
1535
1549
|
function registerProvider(name, factory) {
|
|
@@ -1540,7 +1554,7 @@ function createDispatchStream() {
|
|
|
1540
1554
|
registerBuiltInApiProviders();
|
|
1541
1555
|
}
|
|
1542
1556
|
return async function* dispatchStream(request, options) {
|
|
1543
|
-
const model = getModel(request.model.provider, request.model.
|
|
1557
|
+
const model = getModel(request.model.provider, request.model.id) ?? resolveModel(request.model.id);
|
|
1544
1558
|
if (model) {
|
|
1545
1559
|
yield* stream(model, request, options);
|
|
1546
1560
|
return;
|
|
@@ -1552,7 +1566,7 @@ function createDispatchStream() {
|
|
|
1552
1566
|
return;
|
|
1553
1567
|
}
|
|
1554
1568
|
throw new Error(
|
|
1555
|
-
`No provider for "${request.model.provider}/${request.model.
|
|
1569
|
+
`No provider for "${request.model.provider}/${request.model.id}". Register a model with registerModel() or a provider with registerProvider().`
|
|
1556
1570
|
);
|
|
1557
1571
|
};
|
|
1558
1572
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { M as Model, L as LlmTokenUsage, P as Provider,
|
|
2
|
-
export { e as
|
|
1
|
+
import { M as Model, L as LlmTokenUsage, P as Provider, a as Protocol, A as ApiStreamFn, S as StreamFn, b as LlmRequest, c as LlmStreamOptions, d as LlmStreamEvent } from './index-BGAiAdlQ.cjs';
|
|
2
|
+
export { e as AgentEvent, f as AgentEventListener, g as AgentMessage, h as AnthropicConfig, i as AssistantMessagePartial, B as BaseProviderConfig, C as ContentBlock, K as KnownProtocol, j as KnownProvider, k as LlmContentPart, l as LlmImageContent, m as LlmMessage, n as LlmModelRef, o as LlmModelUsage, p as LlmResponse, q as LlmStopReason, r as LlmTextContent, s as LlmThinkingContent, t as LlmToolCall, u as LlmToolChoice, v as LlmToolDefinition, w as LlmToolResultContent, x as LlmToolUseContent, y as ModelCost, O as OpenAICompletionsConfig, z as OpenAIResponsesConfig, D as Outcome, E as ProviderConfig, F as ProviderError, G as ProviderFetch, H as ProviderModelConfig, R as ResolveAnthropicConfigInput, I as ResolveOpenAICompletionsConfigInput, J as ResolveOpenAIResponsesConfigInput, N as Skill, T as TextBlock, Q as ThinkingBlock, U as ToolCall, V as ToolCallBlock, W as ToolResult, X as callOpenAICompletions, Y as createAnthropicStream, Z as createOpenAICompletionsStream, _ as createOpenAIResponsesStream, $ as resolveAnthropicConfig, a0 as resolveOpenAICompletionsConfig, a1 as resolveOpenAIResponsesConfig, a2 as streamAnthropic, a3 as streamOpenAICompletions, a4 as streamOpenAIResponses, a5 as textFromPartial, a6 as toolCallsFromPartial } from './index-BGAiAdlQ.cjs';
|
|
3
3
|
|
|
4
4
|
interface ServerSentEvent {
|
|
5
5
|
event: string | null;
|
|
@@ -56,22 +56,22 @@ declare function calculateCost(model: Model, usage: LlmTokenUsage): {
|
|
|
56
56
|
declare const MODELS: Record<string, Record<string, Model>>;
|
|
57
57
|
|
|
58
58
|
interface ApiProvider {
|
|
59
|
-
|
|
59
|
+
protocol: Protocol;
|
|
60
60
|
stream: ApiStreamFn;
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
63
|
* Register a provider for a given API protocol.
|
|
64
|
-
* When a model with `
|
|
64
|
+
* When a model with `protocol === provider.protocol` is used, this provider handles it.
|
|
65
65
|
*/
|
|
66
66
|
declare function registerApiProvider(provider: ApiProvider): void;
|
|
67
67
|
/**
|
|
68
68
|
* Look up a registered API provider by protocol name.
|
|
69
69
|
*/
|
|
70
|
-
declare function getApiProvider(
|
|
70
|
+
declare function getApiProvider(protocol: Protocol): ApiProvider | undefined;
|
|
71
71
|
/**
|
|
72
72
|
* List all registered API protocol names.
|
|
73
73
|
*/
|
|
74
|
-
declare function listApiProviders():
|
|
74
|
+
declare function listApiProviders(): Protocol[];
|
|
75
75
|
/**
|
|
76
76
|
* Clear all registered API providers.
|
|
77
77
|
*/
|
|
@@ -80,7 +80,7 @@ declare function clearApiProviders(): void;
|
|
|
80
80
|
* Unregister an API provider by protocol name.
|
|
81
81
|
* Returns true if a provider was removed.
|
|
82
82
|
*/
|
|
83
|
-
declare function unregisterApiProvider(
|
|
83
|
+
declare function unregisterApiProvider(protocol: Protocol): boolean;
|
|
84
84
|
/**
|
|
85
85
|
* Register all built-in API providers.
|
|
86
86
|
* Each provider resolves its config from the Model descriptor and environment.
|
|
@@ -97,13 +97,13 @@ declare function stream(model: Model, request: LlmRequest, options: LlmStreamOpt
|
|
|
97
97
|
*/
|
|
98
98
|
declare function streamByRef(ref: string | {
|
|
99
99
|
provider: string;
|
|
100
|
-
|
|
100
|
+
id: string;
|
|
101
101
|
}, request: Omit<LlmRequest, "model">, options?: LlmStreamOptions): AsyncIterable<LlmStreamEvent>;
|
|
102
102
|
type ProviderFactory = (model: {
|
|
103
103
|
provider: string;
|
|
104
|
-
|
|
104
|
+
id: string;
|
|
105
105
|
}) => StreamFn;
|
|
106
106
|
declare function registerProvider(name: string, factory: ProviderFactory): void;
|
|
107
107
|
declare function createDispatchStream(): StreamFn;
|
|
108
108
|
|
|
109
|
-
export {
|
|
109
|
+
export { type ApiProvider, ApiStreamFn, LlmRequest, LlmStreamEvent, LlmStreamOptions, LlmTokenUsage, MODELS, Model, Protocol, Provider, type ProviderFactory, type ServerSentEvent, StreamFn, calculateCost, clearApiProviders, clearModels, createDispatchStream, getAllModels, getApiProvider, getModel, getModels, getProviders, iterateSseMessages, listApiProviders, registerApiProvider, registerBuiltInApiProviders, registerModel, registerProvider, resolveModel, stream, streamByRef, unregisterApiProvider, unregisterProviderModels };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { M as Model, L as LlmTokenUsage, P as Provider,
|
|
2
|
-
export { e as
|
|
1
|
+
import { M as Model, L as LlmTokenUsage, P as Provider, a as Protocol, A as ApiStreamFn, S as StreamFn, b as LlmRequest, c as LlmStreamOptions, d as LlmStreamEvent } from './index-BGAiAdlQ.js';
|
|
2
|
+
export { e as AgentEvent, f as AgentEventListener, g as AgentMessage, h as AnthropicConfig, i as AssistantMessagePartial, B as BaseProviderConfig, C as ContentBlock, K as KnownProtocol, j as KnownProvider, k as LlmContentPart, l as LlmImageContent, m as LlmMessage, n as LlmModelRef, o as LlmModelUsage, p as LlmResponse, q as LlmStopReason, r as LlmTextContent, s as LlmThinkingContent, t as LlmToolCall, u as LlmToolChoice, v as LlmToolDefinition, w as LlmToolResultContent, x as LlmToolUseContent, y as ModelCost, O as OpenAICompletionsConfig, z as OpenAIResponsesConfig, D as Outcome, E as ProviderConfig, F as ProviderError, G as ProviderFetch, H as ProviderModelConfig, R as ResolveAnthropicConfigInput, I as ResolveOpenAICompletionsConfigInput, J as ResolveOpenAIResponsesConfigInput, N as Skill, T as TextBlock, Q as ThinkingBlock, U as ToolCall, V as ToolCallBlock, W as ToolResult, X as callOpenAICompletions, Y as createAnthropicStream, Z as createOpenAICompletionsStream, _ as createOpenAIResponsesStream, $ as resolveAnthropicConfig, a0 as resolveOpenAICompletionsConfig, a1 as resolveOpenAIResponsesConfig, a2 as streamAnthropic, a3 as streamOpenAICompletions, a4 as streamOpenAIResponses, a5 as textFromPartial, a6 as toolCallsFromPartial } from './index-BGAiAdlQ.js';
|
|
3
3
|
|
|
4
4
|
interface ServerSentEvent {
|
|
5
5
|
event: string | null;
|
|
@@ -56,22 +56,22 @@ declare function calculateCost(model: Model, usage: LlmTokenUsage): {
|
|
|
56
56
|
declare const MODELS: Record<string, Record<string, Model>>;
|
|
57
57
|
|
|
58
58
|
interface ApiProvider {
|
|
59
|
-
|
|
59
|
+
protocol: Protocol;
|
|
60
60
|
stream: ApiStreamFn;
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
63
|
* Register a provider for a given API protocol.
|
|
64
|
-
* When a model with `
|
|
64
|
+
* When a model with `protocol === provider.protocol` is used, this provider handles it.
|
|
65
65
|
*/
|
|
66
66
|
declare function registerApiProvider(provider: ApiProvider): void;
|
|
67
67
|
/**
|
|
68
68
|
* Look up a registered API provider by protocol name.
|
|
69
69
|
*/
|
|
70
|
-
declare function getApiProvider(
|
|
70
|
+
declare function getApiProvider(protocol: Protocol): ApiProvider | undefined;
|
|
71
71
|
/**
|
|
72
72
|
* List all registered API protocol names.
|
|
73
73
|
*/
|
|
74
|
-
declare function listApiProviders():
|
|
74
|
+
declare function listApiProviders(): Protocol[];
|
|
75
75
|
/**
|
|
76
76
|
* Clear all registered API providers.
|
|
77
77
|
*/
|
|
@@ -80,7 +80,7 @@ declare function clearApiProviders(): void;
|
|
|
80
80
|
* Unregister an API provider by protocol name.
|
|
81
81
|
* Returns true if a provider was removed.
|
|
82
82
|
*/
|
|
83
|
-
declare function unregisterApiProvider(
|
|
83
|
+
declare function unregisterApiProvider(protocol: Protocol): boolean;
|
|
84
84
|
/**
|
|
85
85
|
* Register all built-in API providers.
|
|
86
86
|
* Each provider resolves its config from the Model descriptor and environment.
|
|
@@ -97,13 +97,13 @@ declare function stream(model: Model, request: LlmRequest, options: LlmStreamOpt
|
|
|
97
97
|
*/
|
|
98
98
|
declare function streamByRef(ref: string | {
|
|
99
99
|
provider: string;
|
|
100
|
-
|
|
100
|
+
id: string;
|
|
101
101
|
}, request: Omit<LlmRequest, "model">, options?: LlmStreamOptions): AsyncIterable<LlmStreamEvent>;
|
|
102
102
|
type ProviderFactory = (model: {
|
|
103
103
|
provider: string;
|
|
104
|
-
|
|
104
|
+
id: string;
|
|
105
105
|
}) => StreamFn;
|
|
106
106
|
declare function registerProvider(name: string, factory: ProviderFactory): void;
|
|
107
107
|
declare function createDispatchStream(): StreamFn;
|
|
108
108
|
|
|
109
|
-
export {
|
|
109
|
+
export { type ApiProvider, ApiStreamFn, LlmRequest, LlmStreamEvent, LlmStreamOptions, LlmTokenUsage, MODELS, Model, Protocol, Provider, type ProviderFactory, type ServerSentEvent, StreamFn, calculateCost, clearApiProviders, clearModels, createDispatchStream, getAllModels, getApiProvider, getModel, getModels, getProviders, iterateSseMessages, listApiProviders, registerApiProvider, registerBuiltInApiProviders, registerModel, registerProvider, resolveModel, stream, streamByRef, unregisterApiProvider, unregisterProviderModels };
|