@mariozechner/pi-ai 0.5.27 → 0.5.28

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 (42) hide show
  1. package/README.md +355 -275
  2. package/dist/generate.d.ts +22 -0
  3. package/dist/generate.d.ts.map +1 -0
  4. package/dist/generate.js +204 -0
  5. package/dist/generate.js.map +1 -0
  6. package/dist/index.d.ts +7 -8
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +7 -12
  9. package/dist/index.js.map +1 -1
  10. package/dist/models.d.ts +10 -71
  11. package/dist/models.d.ts.map +1 -1
  12. package/dist/models.generated.d.ts +3056 -2659
  13. package/dist/models.generated.d.ts.map +1 -1
  14. package/dist/models.generated.js +3063 -2663
  15. package/dist/models.generated.js.map +1 -1
  16. package/dist/models.js +17 -59
  17. package/dist/models.js.map +1 -1
  18. package/dist/providers/anthropic.d.ts +5 -18
  19. package/dist/providers/anthropic.d.ts.map +1 -1
  20. package/dist/providers/anthropic.js +249 -227
  21. package/dist/providers/anthropic.js.map +1 -1
  22. package/dist/providers/google.d.ts +3 -14
  23. package/dist/providers/google.d.ts.map +1 -1
  24. package/dist/providers/google.js +215 -220
  25. package/dist/providers/google.js.map +1 -1
  26. package/dist/providers/openai-completions.d.ts +4 -14
  27. package/dist/providers/openai-completions.d.ts.map +1 -1
  28. package/dist/providers/openai-completions.js +247 -215
  29. package/dist/providers/openai-completions.js.map +1 -1
  30. package/dist/providers/openai-responses.d.ts +6 -13
  31. package/dist/providers/openai-responses.d.ts.map +1 -1
  32. package/dist/providers/openai-responses.js +242 -244
  33. package/dist/providers/openai-responses.js.map +1 -1
  34. package/dist/providers/utils.d.ts +2 -14
  35. package/dist/providers/utils.d.ts.map +1 -1
  36. package/dist/providers/utils.js +2 -15
  37. package/dist/providers/utils.js.map +1 -1
  38. package/dist/types.d.ts +39 -16
  39. package/dist/types.d.ts.map +1 -1
  40. package/dist/types.js +1 -0
  41. package/dist/types.js.map +1 -1
  42. package/package.json +1 -1
@@ -0,0 +1,22 @@
1
+ import type { Api, AssistantMessage, AssistantMessageEvent, Context, GenerateStream, KnownProvider, Model, OptionsForApi, SimpleGenerateOptions } from "./types.js";
2
+ export declare class QueuedGenerateStream implements GenerateStream {
3
+ private queue;
4
+ private waiting;
5
+ private done;
6
+ private finalMessagePromise;
7
+ private resolveFinalMessage;
8
+ constructor();
9
+ push(event: AssistantMessageEvent): void;
10
+ end(): void;
11
+ [Symbol.asyncIterator](): AsyncIterator<AssistantMessageEvent>;
12
+ finalMessage(): Promise<AssistantMessage>;
13
+ }
14
+ export declare function setApiKey(provider: KnownProvider, key: string): void;
15
+ export declare function setApiKey(provider: string, key: string): void;
16
+ export declare function getApiKey(provider: KnownProvider): string | undefined;
17
+ export declare function getApiKey(provider: string): string | undefined;
18
+ export declare function stream<TApi extends Api>(model: Model<TApi>, context: Context, options?: OptionsForApi<TApi>): GenerateStream;
19
+ export declare function complete<TApi extends Api>(model: Model<TApi>, context: Context, options?: OptionsForApi<TApi>): Promise<AssistantMessage>;
20
+ export declare function streamSimple<TApi extends Api>(model: Model<TApi>, context: Context, options?: SimpleGenerateOptions): GenerateStream;
21
+ export declare function completeSimple<TApi extends Api>(model: Model<TApi>, context: Context, options?: SimpleGenerateOptions): Promise<AssistantMessage>;
22
+ //# sourceMappingURL=generate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACX,GAAG,EACH,gBAAgB,EAChB,qBAAqB,EACrB,OAAO,EACP,cAAc,EACd,aAAa,EACb,KAAK,EACL,aAAa,EAEb,qBAAqB,EACrB,MAAM,YAAY,CAAC;AAEpB,qBAAa,oBAAqB,YAAW,cAAc;IAC1D,OAAO,CAAC,KAAK,CAA+B;IAC5C,OAAO,CAAC,OAAO,CAAkE;IACjF,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,mBAAmB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B,OAAO,CAAC,EAAE,qBAAqB,GAC7B,OAAO,CAAC,gBAAgB,CAAC,CAG3B"}
@@ -0,0 +1,204 @@
1
+ import { streamAnthropic } from "./providers/anthropic.js";
2
+ import { streamGoogle } from "./providers/google.js";
3
+ import { streamOpenAICompletions } from "./providers/openai-completions.js";
4
+ import { streamOpenAIResponses } from "./providers/openai-responses.js";
5
+ export class QueuedGenerateStream {
6
+ queue = [];
7
+ waiting = [];
8
+ done = false;
9
+ finalMessagePromise;
10
+ resolveFinalMessage;
11
+ constructor() {
12
+ this.finalMessagePromise = new Promise((resolve) => {
13
+ this.resolveFinalMessage = resolve;
14
+ });
15
+ }
16
+ push(event) {
17
+ if (this.done)
18
+ return;
19
+ if (event.type === "done") {
20
+ this.done = true;
21
+ this.resolveFinalMessage(event.message);
22
+ }
23
+ if (event.type === "error") {
24
+ this.done = true;
25
+ this.resolveFinalMessage(event.partial);
26
+ }
27
+ // Deliver to waiting consumer or queue it
28
+ const waiter = this.waiting.shift();
29
+ if (waiter) {
30
+ waiter({ value: event, done: false });
31
+ }
32
+ else {
33
+ this.queue.push(event);
34
+ }
35
+ }
36
+ end() {
37
+ this.done = true;
38
+ // Notify all waiting consumers that we're done
39
+ while (this.waiting.length > 0) {
40
+ const waiter = this.waiting.shift();
41
+ waiter({ value: undefined, done: true });
42
+ }
43
+ }
44
+ async *[Symbol.asyncIterator]() {
45
+ while (true) {
46
+ // If we have queued events, yield them
47
+ if (this.queue.length > 0) {
48
+ yield this.queue.shift();
49
+ }
50
+ else if (this.done) {
51
+ // No more events and we're done
52
+ return;
53
+ }
54
+ else {
55
+ // Wait for next event
56
+ const result = await new Promise((resolve) => this.waiting.push(resolve));
57
+ if (result.done)
58
+ return;
59
+ yield result.value;
60
+ }
61
+ }
62
+ }
63
+ finalMessage() {
64
+ return this.finalMessagePromise;
65
+ }
66
+ }
67
+ const apiKeys = new Map();
68
+ export function setApiKey(provider, key) {
69
+ apiKeys.set(provider, key);
70
+ }
71
+ export function getApiKey(provider) {
72
+ // Check explicit keys first
73
+ const key = apiKeys.get(provider);
74
+ if (key)
75
+ return key;
76
+ // Fall back to environment variables
77
+ const envMap = {
78
+ openai: "OPENAI_API_KEY",
79
+ anthropic: "ANTHROPIC_API_KEY",
80
+ google: "GEMINI_API_KEY",
81
+ groq: "GROQ_API_KEY",
82
+ cerebras: "CEREBRAS_API_KEY",
83
+ xai: "XAI_API_KEY",
84
+ openrouter: "OPENROUTER_API_KEY",
85
+ };
86
+ const envVar = envMap[provider];
87
+ return envVar ? process.env[envVar] : undefined;
88
+ }
89
+ export function stream(model, context, options) {
90
+ const apiKey = options?.apiKey || getApiKey(model.provider);
91
+ if (!apiKey) {
92
+ throw new Error(`No API key for provider: ${model.provider}`);
93
+ }
94
+ const providerOptions = { ...options, apiKey };
95
+ const api = model.api;
96
+ switch (api) {
97
+ case "anthropic-messages":
98
+ return streamAnthropic(model, context, providerOptions);
99
+ case "openai-completions":
100
+ return streamOpenAICompletions(model, context, providerOptions);
101
+ case "openai-responses":
102
+ return streamOpenAIResponses(model, context, providerOptions);
103
+ case "google-generative-ai":
104
+ return streamGoogle(model, context, providerOptions);
105
+ default: {
106
+ // This should never be reached if all Api cases are handled
107
+ const _exhaustive = api;
108
+ throw new Error(`Unhandled API: ${_exhaustive}`);
109
+ }
110
+ }
111
+ }
112
+ export async function complete(model, context, options) {
113
+ const s = stream(model, context, options);
114
+ return s.finalMessage();
115
+ }
116
+ export function streamSimple(model, context, options) {
117
+ const apiKey = options?.apiKey || getApiKey(model.provider);
118
+ if (!apiKey) {
119
+ throw new Error(`No API key for provider: ${model.provider}`);
120
+ }
121
+ const providerOptions = mapOptionsForApi(model, options, apiKey);
122
+ return stream(model, context, providerOptions);
123
+ }
124
+ export async function completeSimple(model, context, options) {
125
+ const s = streamSimple(model, context, options);
126
+ return s.finalMessage();
127
+ }
128
+ function mapOptionsForApi(model, options, apiKey) {
129
+ const base = {
130
+ temperature: options?.temperature,
131
+ maxTokens: options?.maxTokens,
132
+ signal: options?.signal,
133
+ apiKey: apiKey || options?.apiKey,
134
+ };
135
+ switch (model.api) {
136
+ case "anthropic-messages": {
137
+ if (!options?.reasoning)
138
+ return base;
139
+ const anthropicBudgets = {
140
+ minimal: 1024,
141
+ low: 2048,
142
+ medium: 8192,
143
+ high: Math.min(25000, model.maxTokens - 1000),
144
+ };
145
+ return {
146
+ ...base,
147
+ thinkingEnabled: true,
148
+ thinkingBudgetTokens: anthropicBudgets[options.reasoning],
149
+ };
150
+ }
151
+ case "openai-completions":
152
+ return {
153
+ ...base,
154
+ reasoningEffort: options?.reasoning,
155
+ };
156
+ case "openai-responses":
157
+ return {
158
+ ...base,
159
+ reasoningEffort: options?.reasoning,
160
+ };
161
+ case "google-generative-ai": {
162
+ if (!options?.reasoning)
163
+ return base;
164
+ const googleBudget = getGoogleBudget(model, options.reasoning);
165
+ return {
166
+ ...base,
167
+ thinking: {
168
+ enabled: true,
169
+ budgetTokens: googleBudget,
170
+ },
171
+ };
172
+ }
173
+ default: {
174
+ // Exhaustiveness check
175
+ const _exhaustive = model.api;
176
+ throw new Error(`Unhandled API in mapOptionsForApi: ${_exhaustive}`);
177
+ }
178
+ }
179
+ }
180
+ function getGoogleBudget(model, effort) {
181
+ // See https://ai.google.dev/gemini-api/docs/thinking#set-budget
182
+ if (model.id.includes("2.5-pro")) {
183
+ const budgets = {
184
+ minimal: 128,
185
+ low: 2048,
186
+ medium: 8192,
187
+ high: 32768,
188
+ };
189
+ return budgets[effort];
190
+ }
191
+ if (model.id.includes("2.5-flash")) {
192
+ // Covers 2.5-flash-lite as well
193
+ const budgets = {
194
+ minimal: 128,
195
+ low: 2048,
196
+ medium: 8192,
197
+ high: 24576,
198
+ };
199
+ return budgets[effort];
200
+ }
201
+ // Unknown model - use dynamic
202
+ return -1;
203
+ }
204
+ //# sourceMappingURL=generate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.js","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":"AAAA,OA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,WAAW,EAAE,CAAC,CAAC;QACtE,CAAC;IACF,CAAC;AACF,CAAC;AAED,SAAS,eAAe,CAAC,KAAoC,EAAE,MAAuB;IACrF,gEAAgE;IAChE,IAAI,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;QAClC,MAAM,OAAO,GAAG;YACf,OAAO,EAAE,GAAG;YACZ,GAAG,EAAE,IAAI;YACT,MAAM,EAAE,IAAI;YACZ,IAAI,EAAE,KAAK;SACX,CAAC;QACF,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;IACxB,CAAC;IAED,IAAI,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;QACpC,gCAAgC;QAChC,MAAM,OAAO,GAAG;YACf,OAAO,EAAE,GAAG;YACZ,GAAG,EAAE,IAAI;YACT,MAAM,EAAE,IAAI;YACZ,IAAI,EAAE,KAAK;SACX,CAAC;QACF,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;IACxB,CAAC;IAED,8BAA8B;IAC9B,OAAO,CAAC,CAAC,CAAC;AACX,CAAC","sourcesContent":["import { type AnthropicOptions, streamAnthropic } from \"./providers/anthropic.js\";\nimport { type GoogleOptions, streamGoogle } from \"./providers/google.js\";\nimport { type OpenAICompletionsOptions, streamOpenAICompletions } from \"./providers/openai-completions.js\";\nimport { type OpenAIResponsesOptions, streamOpenAIResponses } from \"./providers/openai-responses.js\";\nimport type {\n\tApi,\n\tAssistantMessage,\n\tAssistantMessageEvent,\n\tContext,\n\tGenerateStream,\n\tKnownProvider,\n\tModel,\n\tOptionsForApi,\n\tReasoningEffort,\n\tSimpleGenerateOptions,\n} from \"./types.js\";\n\nexport class QueuedGenerateStream implements GenerateStream {\n\tprivate queue: AssistantMessageEvent[] = [];\n\tprivate waiting: ((value: IteratorResult<AssistantMessageEvent>) => void)[] = [];\n\tprivate done = false;\n\tprivate finalMessagePromise: Promise<AssistantMessage>;\n\tprivate resolveFinalMessage!: (message: AssistantMessage) => void;\n\n\tconstructor() {\n\t\tthis.finalMessagePromise = new Promise((resolve) => {\n\t\t\tthis.resolveFinalMessage = resolve;\n\t\t});\n\t}\n\n\tpush(event: AssistantMessageEvent): void {\n\t\tif (this.done) return;\n\n\t\tif (event.type === \"done\") {\n\t\t\tthis.done = true;\n\t\t\tthis.resolveFinalMessage(event.message);\n\t\t}\n\t\tif (event.type === \"error\") {\n\t\t\tthis.done = true;\n\t\t\tthis.resolveFinalMessage(event.partial);\n\t\t}\n\n\t\t// Deliver to waiting consumer or queue it\n\t\tconst waiter = this.waiting.shift();\n\t\tif (waiter) {\n\t\t\twaiter({ value: event, done: false });\n\t\t} else {\n\t\t\tthis.queue.push(event);\n\t\t}\n\t}\n\n\tend(): void {\n\t\tthis.done = true;\n\t\t// Notify all waiting consumers that we're done\n\t\twhile (this.waiting.length > 0) {\n\t\t\tconst waiter = this.waiting.shift()!;\n\t\t\twaiter({ value: undefined as any, done: true });\n\t\t}\n\t}\n\n\tasync *[Symbol.asyncIterator](): AsyncIterator<AssistantMessageEvent> {\n\t\twhile (true) {\n\t\t\t// If we have queued events, yield them\n\t\t\tif (this.queue.length > 0) {\n\t\t\t\tyield this.queue.shift()!;\n\t\t\t} else if (this.done) {\n\t\t\t\t// No more events and we're done\n\t\t\t\treturn;\n\t\t\t} else {\n\t\t\t\t// Wait for next event\n\t\t\t\tconst result = await new Promise<IteratorResult<AssistantMessageEvent>>((resolve) =>\n\t\t\t\t\tthis.waiting.push(resolve),\n\t\t\t\t);\n\t\t\t\tif (result.done) return;\n\t\t\t\tyield result.value;\n\t\t\t}\n\t\t}\n\t}\n\n\tfinalMessage(): Promise<AssistantMessage> {\n\t\treturn this.finalMessagePromise;\n\t}\n}\n\nconst apiKeys: Map<string, string> = new Map();\n\nexport function setApiKey(provider: KnownProvider, key: string): void;\nexport function setApiKey(provider: string, key: string): void;\nexport function setApiKey(provider: any, key: string): void {\n\tapiKeys.set(provider, key);\n}\n\nexport function getApiKey(provider: KnownProvider): string | undefined;\nexport function getApiKey(provider: string): string | undefined;\nexport function getApiKey(provider: any): string | undefined {\n\t// Check explicit keys first\n\tconst key = apiKeys.get(provider);\n\tif (key) return key;\n\n\t// Fall back to environment variables\n\tconst envMap: Record<string, string> = {\n\t\topenai: \"OPENAI_API_KEY\",\n\t\tanthropic: \"ANTHROPIC_API_KEY\",\n\t\tgoogle: \"GEMINI_API_KEY\",\n\t\tgroq: \"GROQ_API_KEY\",\n\t\tcerebras: \"CEREBRAS_API_KEY\",\n\t\txai: \"XAI_API_KEY\",\n\t\topenrouter: \"OPENROUTER_API_KEY\",\n\t};\n\n\tconst envVar = envMap[provider];\n\treturn envVar ? process.env[envVar] : undefined;\n}\n\nexport function stream<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontext: Context,\n\toptions?: OptionsForApi<TApi>,\n): GenerateStream {\n\tconst apiKey = options?.apiKey || getApiKey(model.provider);\n\tif (!apiKey) {\n\t\tthrow new Error(`No API key for provider: ${model.provider}`);\n\t}\n\tconst providerOptions = { ...options, apiKey };\n\n\tconst api: Api = model.api;\n\tswitch (api) {\n\t\tcase \"anthropic-messages\":\n\t\t\treturn streamAnthropic(model as Model<\"anthropic-messages\">, context, providerOptions);\n\n\t\tcase \"openai-completions\":\n\t\t\treturn streamOpenAICompletions(model as Model<\"openai-completions\">, context, providerOptions as any);\n\n\t\tcase \"openai-responses\":\n\t\t\treturn streamOpenAIResponses(model as Model<\"openai-responses\">, context, providerOptions as any);\n\n\t\tcase \"google-generative-ai\":\n\t\t\treturn streamGoogle(model as Model<\"google-generative-ai\">, context, providerOptions);\n\n\t\tdefault: {\n\t\t\t// This should never be reached if all Api cases are handled\n\t\t\tconst _exhaustive: never = api;\n\t\t\tthrow new Error(`Unhandled API: ${_exhaustive}`);\n\t\t}\n\t}\n}\n\nexport async function complete<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontext: Context,\n\toptions?: OptionsForApi<TApi>,\n): Promise<AssistantMessage> {\n\tconst s = stream(model, context, options);\n\treturn s.finalMessage();\n}\n\nexport function streamSimple<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontext: Context,\n\toptions?: SimpleGenerateOptions,\n): GenerateStream {\n\tconst apiKey = options?.apiKey || getApiKey(model.provider);\n\tif (!apiKey) {\n\t\tthrow new Error(`No API key for provider: ${model.provider}`);\n\t}\n\n\tconst providerOptions = mapOptionsForApi(model, options, apiKey);\n\treturn stream(model, context, providerOptions);\n}\n\nexport async function completeSimple<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontext: Context,\n\toptions?: SimpleGenerateOptions,\n): Promise<AssistantMessage> {\n\tconst s = streamSimple(model, context, options);\n\treturn s.finalMessage();\n}\n\nfunction mapOptionsForApi<TApi extends Api>(\n\tmodel: Model<TApi>,\n\toptions?: SimpleGenerateOptions,\n\tapiKey?: string,\n): OptionsForApi<TApi> {\n\tconst base = {\n\t\ttemperature: options?.temperature,\n\t\tmaxTokens: options?.maxTokens,\n\t\tsignal: options?.signal,\n\t\tapiKey: apiKey || options?.apiKey,\n\t};\n\n\tswitch (model.api) {\n\t\tcase \"anthropic-messages\": {\n\t\t\tif (!options?.reasoning) return base satisfies AnthropicOptions;\n\n\t\t\tconst anthropicBudgets = {\n\t\t\t\tminimal: 1024,\n\t\t\t\tlow: 2048,\n\t\t\t\tmedium: 8192,\n\t\t\t\thigh: Math.min(25000, model.maxTokens - 1000),\n\t\t\t};\n\n\t\t\treturn {\n\t\t\t\t...base,\n\t\t\t\tthinkingEnabled: true,\n\t\t\t\tthinkingBudgetTokens: anthropicBudgets[options.reasoning],\n\t\t\t} satisfies AnthropicOptions;\n\t\t}\n\n\t\tcase \"openai-completions\":\n\t\t\treturn {\n\t\t\t\t...base,\n\t\t\t\treasoningEffort: options?.reasoning,\n\t\t\t} satisfies OpenAICompletionsOptions;\n\n\t\tcase \"openai-responses\":\n\t\t\treturn {\n\t\t\t\t...base,\n\t\t\t\treasoningEffort: options?.reasoning,\n\t\t\t} satisfies OpenAIResponsesOptions;\n\n\t\tcase \"google-generative-ai\": {\n\t\t\tif (!options?.reasoning) return base as any;\n\n\t\t\tconst googleBudget = getGoogleBudget(model as Model<\"google-generative-ai\">, options.reasoning);\n\t\t\treturn {\n\t\t\t\t...base,\n\t\t\t\tthinking: {\n\t\t\t\t\tenabled: true,\n\t\t\t\t\tbudgetTokens: googleBudget,\n\t\t\t\t},\n\t\t\t} satisfies GoogleOptions;\n\t\t}\n\n\t\tdefault: {\n\t\t\t// Exhaustiveness check\n\t\t\tconst _exhaustive: never = model.api;\n\t\t\tthrow new Error(`Unhandled API in mapOptionsForApi: ${_exhaustive}`);\n\t\t}\n\t}\n}\n\nfunction getGoogleBudget(model: Model<\"google-generative-ai\">, effort: ReasoningEffort): number {\n\t// See https://ai.google.dev/gemini-api/docs/thinking#set-budget\n\tif (model.id.includes(\"2.5-pro\")) {\n\t\tconst budgets = {\n\t\t\tminimal: 128,\n\t\t\tlow: 2048,\n\t\t\tmedium: 8192,\n\t\t\thigh: 32768,\n\t\t};\n\t\treturn budgets[effort];\n\t}\n\n\tif (model.id.includes(\"2.5-flash\")) {\n\t\t// Covers 2.5-flash-lite as well\n\t\tconst budgets = {\n\t\t\tminimal: 128,\n\t\t\tlow: 2048,\n\t\t\tmedium: 8192,\n\t\t\thigh: 24576,\n\t\t};\n\t\treturn budgets[effort];\n\t}\n\n\t// Unknown model - use dynamic\n\treturn -1;\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -1,9 +1,8 @@
1
- export declare const version = "0.5.8";
2
- export { PROVIDERS } from "./models.generated.js";
3
- export { type AnthropicModel, type CerebrasModel, createLLM, type GoogleModel, type GroqModel, type Model, type OpenAIModel, type OpenRouterModel, PROVIDER_CONFIG, type ProviderModels, type ProviderToLLM, type XAIModel, } from "./models.js";
4
- export { AnthropicLLM } from "./providers/anthropic.js";
5
- export { GoogleLLM } from "./providers/google.js";
6
- export { OpenAICompletionsLLM } from "./providers/openai-completions.js";
7
- export { OpenAIResponsesLLM } from "./providers/openai-responses.js";
8
- export type * from "./types.js";
1
+ export * from "./generate.js";
2
+ export * from "./models.js";
3
+ export * from "./providers/anthropic.js";
4
+ export * from "./providers/google.js";
5
+ export * from "./providers/openai-completions.js";
6
+ export * from "./providers/openai-responses.js";
7
+ export * from "./types.js";
9
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,OAAO,UAAU,CAAC;AAG/B,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAGlD,OAAO,EACN,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,SAAS,EACT,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,KAAK,EACV,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,eAAe,EACf,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,QAAQ,GACb,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAGrE,mBAAmB,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mCAAmC,CAAC;AAClD,cAAc,iCAAiC,CAAC;AAChD,cAAc,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -1,13 +1,8 @@
1
- // @mariozechner/pi-ai - Unified LLM API with automatic model discovery
2
- // This package provides a common interface for working with multiple LLM providers
3
- export const version = "0.5.8";
4
- // Export generated models data
5
- export { PROVIDERS } from "./models.generated.js";
6
- // Export models utilities and types
7
- export { createLLM, PROVIDER_CONFIG, } from "./models.js";
8
- // Export providers
9
- export { AnthropicLLM } from "./providers/anthropic.js";
10
- export { GoogleLLM } from "./providers/google.js";
11
- export { OpenAICompletionsLLM } from "./providers/openai-completions.js";
12
- export { OpenAIResponsesLLM } from "./providers/openai-responses.js";
1
+ export * from "./generate.js";
2
+ export * from "./models.js";
3
+ export * from "./providers/anthropic.js";
4
+ export * from "./providers/google.js";
5
+ export * from "./providers/openai-completions.js";
6
+ export * from "./providers/openai-responses.js";
7
+ export * from "./types.js";
13
8
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,mFAAmF;AAEnF,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC;AAE/B,+BAA+B;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElD,oCAAoC;AACpC,OAAO,EAGN,SAAS,EAMT,eAAe,GAIf,MAAM,aAAa,CAAC;AAErB,mBAAmB;AACnB,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC","sourcesContent":["// @mariozechner/pi-ai - Unified LLM API with automatic model discovery\n// This package provides a common interface for working with multiple LLM providers\n\nexport const version = \"0.5.8\";\n\n// Export generated models data\nexport { PROVIDERS } from \"./models.generated.js\";\n\n// Export models utilities and types\nexport {\n\ttype AnthropicModel,\n\ttype CerebrasModel,\n\tcreateLLM,\n\ttype GoogleModel,\n\ttype GroqModel,\n\ttype Model,\n\ttype OpenAIModel,\n\ttype OpenRouterModel,\n\tPROVIDER_CONFIG,\n\ttype ProviderModels,\n\ttype ProviderToLLM,\n\ttype XAIModel,\n} from \"./models.js\";\n\n// Export providers\nexport { AnthropicLLM } from \"./providers/anthropic.js\";\nexport { GoogleLLM } from \"./providers/google.js\";\nexport { OpenAICompletionsLLM } from \"./providers/openai-completions.js\";\nexport { OpenAIResponsesLLM } from \"./providers/openai-responses.js\";\n\n// Export types\nexport type * from \"./types.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mCAAmC,CAAC;AAClD,cAAc,iCAAiC,CAAC;AAChD,cAAc,YAAY,CAAC","sourcesContent":["export * from \"./generate.js\";\nexport * from \"./models.js\";\nexport * from \"./providers/anthropic.js\";\nexport * from \"./providers/google.js\";\nexport * from \"./providers/openai-completions.js\";\nexport * from \"./providers/openai-responses.js\";\nexport * from \"./types.js\";\n"]}
package/dist/models.d.ts CHANGED
@@ -1,72 +1,11 @@
1
- import { PROVIDERS } from "./models.generated.js";
2
- import { AnthropicLLM } from "./providers/anthropic.js";
3
- import { GoogleLLM } from "./providers/google.js";
4
- import { OpenAICompletionsLLM } from "./providers/openai-completions.js";
5
- import { OpenAIResponsesLLM } from "./providers/openai-responses.js";
6
- import type { Model, Usage } from "./types.js";
7
- export declare const PROVIDER_CONFIG: {
8
- readonly google: {
9
- readonly envKey: "GEMINI_API_KEY";
10
- readonly create: (model: Model, apiKey: string) => GoogleLLM;
11
- };
12
- readonly openai: {
13
- readonly envKey: "OPENAI_API_KEY";
14
- readonly create: (model: Model, apiKey: string) => OpenAIResponsesLLM;
15
- };
16
- readonly anthropic: {
17
- readonly envKey: "ANTHROPIC_API_KEY";
18
- readonly create: (model: Model, apiKey: string) => AnthropicLLM;
19
- };
20
- readonly xai: {
21
- readonly envKey: "XAI_API_KEY";
22
- readonly create: (model: Model, apiKey: string) => OpenAICompletionsLLM;
23
- };
24
- readonly groq: {
25
- readonly envKey: "GROQ_API_KEY";
26
- readonly create: (model: Model, apiKey: string) => OpenAICompletionsLLM;
27
- };
28
- readonly cerebras: {
29
- readonly envKey: "CEREBRAS_API_KEY";
30
- readonly create: (model: Model, apiKey: string) => OpenAICompletionsLLM;
31
- };
32
- readonly openrouter: {
33
- readonly envKey: "OPENROUTER_API_KEY";
34
- readonly create: (model: Model, apiKey: string) => OpenAICompletionsLLM;
35
- };
36
- };
37
- export type ProviderToLLM = {
38
- google: GoogleLLM;
39
- openai: OpenAIResponsesLLM;
40
- anthropic: AnthropicLLM;
41
- xai: OpenAICompletionsLLM;
42
- groq: OpenAICompletionsLLM;
43
- cerebras: OpenAICompletionsLLM;
44
- openrouter: OpenAICompletionsLLM;
45
- };
46
- export type GoogleModel = keyof typeof PROVIDERS.google.models;
47
- export type OpenAIModel = keyof typeof PROVIDERS.openai.models;
48
- export type AnthropicModel = keyof typeof PROVIDERS.anthropic.models;
49
- export type XAIModel = keyof typeof PROVIDERS.xai.models;
50
- export type GroqModel = keyof typeof PROVIDERS.groq.models;
51
- export type CerebrasModel = keyof typeof PROVIDERS.cerebras.models;
52
- export type OpenRouterModel = keyof typeof PROVIDERS.openrouter.models;
53
- export type ProviderModels = {
54
- google: GoogleModel;
55
- openai: OpenAIModel;
56
- anthropic: AnthropicModel;
57
- xai: XAIModel;
58
- groq: GroqModel;
59
- cerebras: CerebrasModel;
60
- openrouter: OpenRouterModel;
61
- };
62
- export declare function createLLM<P extends keyof typeof PROVIDERS, M extends keyof (typeof PROVIDERS)[P]["models"]>(provider: P, model: M, apiKey?: string): ProviderToLLM[P];
63
- export declare function getModel<P extends keyof typeof PROVIDERS>(provider: P, modelId: keyof (typeof PROVIDERS)[P]["models"]): Model | undefined;
64
- export declare function calculateCost(model: Model, usage: Usage): {
65
- input: number;
66
- output: number;
67
- cacheRead: number;
68
- cacheWrite: number;
69
- total: number;
70
- };
71
- export type { Model };
1
+ import { MODELS } from "./models.generated.js";
2
+ import type { Api, KnownProvider, Model, Usage } from "./types.js";
3
+ type ModelApi<TProvider extends KnownProvider, TModelId extends keyof (typeof MODELS)[TProvider]> = (typeof MODELS)[TProvider][TModelId] extends {
4
+ api: infer TApi;
5
+ } ? (TApi extends Api ? TApi : never) : never;
6
+ export declare function getModel<TProvider extends KnownProvider, TModelId extends keyof (typeof MODELS)[TProvider]>(provider: TProvider, modelId: TModelId): Model<ModelApi<TProvider, TModelId>>;
7
+ export declare function getProviders(): KnownProvider[];
8
+ export declare function getModels<TProvider extends KnownProvider>(provider: TProvider): Model<ModelApi<TProvider, keyof (typeof MODELS)[TProvider]>>[];
9
+ export declare function calculateCost<TApi extends Api>(model: Model<TApi>, usage: Usage): Usage["cost"];
10
+ export {};
72
11
  //# sourceMappingURL=models.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAG/C,eAAO,MAAM,eAAe;;;iCAGV,KAAK,UAAU,MAAM;;;;iCAIrB,KAAK,UAAU,MAAM;;;;iCAIrB,KAAK,UAAU,MAAM;;;;iCAIrB,KAAK,UAAU,MAAM;;;;iCAIrB,KAAK,UAAU,MAAM;;;;iCAIrB,KAAK,UAAU,MAAM;;;;iCAIrB,KAAK,UAAU,MAAM;;CAE7B,CAAC;AAGX,MAAM,MAAM,aAAa,G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