noosphere 0.9.0 → 0.9.1
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 +98 -0
- package/dist/index.cjs +221 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +57 -1
- package/dist/index.d.ts +57 -1
- package/dist/index.js +199 -15
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { AgentContext, AgentEvent, AgentLoopConfig, AgentTool, ApiOptionsMap, AssistantMessageEvent, AssistantMessageEventStream, KnownProvider, OptionsForApi, Api as PiApi, AssistantMessage as PiAssistantMessage, Context as PiContext, ImageContent as PiImageContent, Message as PiMessage, Model as PiModel, Provider as PiProvider, StreamOptions as PiStreamOptions, ToolResultMessage as PiToolResultMessage, Usage as PiUsage, UserMessage as PiUserMessage, QueuedMessage, ReasoningEffort, SimpleStreamOptions, StopReason, StreamFunction, TextContent, ThinkingContent, ToolCall, agentLoop, calculateCost, getApiKey, getModel as getPiModel, getModels as getPiModels, getProviders as getPiProviders, complete as piComplete, completeSimple as piCompleteSimple, stream as piStream, streamSimple as piStreamSimple, setApiKey } from '@mariozechner/pi-ai';
|
|
2
|
+
|
|
1
3
|
type Modality = 'llm' | 'image' | 'video' | 'tts' | 'stt' | 'music' | 'embedding';
|
|
2
4
|
type ModelStatus = 'installed' | 'available' | 'downloading' | 'running' | 'error';
|
|
3
5
|
interface LocalModelInfo {
|
|
@@ -302,6 +304,59 @@ declare class OllamaProvider implements NoosphereProvider {
|
|
|
302
304
|
getRunningModels(): Promise<OllamaRunningModel[]>;
|
|
303
305
|
}
|
|
304
306
|
|
|
307
|
+
type TokenCountProvider = 'openai' | 'google' | 'anthropic' | 'mistral' | 'groq' | 'xai' | 'cerebras' | 'openrouter' | 'ollama' | 'unknown';
|
|
308
|
+
interface TokenCountResult {
|
|
309
|
+
tokens: number;
|
|
310
|
+
model: string;
|
|
311
|
+
provider: TokenCountProvider;
|
|
312
|
+
method: 'tiktoken' | 'api' | 'estimate';
|
|
313
|
+
}
|
|
314
|
+
interface TokenCountOptions {
|
|
315
|
+
messages: Array<{
|
|
316
|
+
role: string;
|
|
317
|
+
content: string;
|
|
318
|
+
}>;
|
|
319
|
+
model?: string;
|
|
320
|
+
provider?: string;
|
|
321
|
+
}
|
|
322
|
+
declare function countTokensOpenAI(messages: Array<{
|
|
323
|
+
role: string;
|
|
324
|
+
content: string;
|
|
325
|
+
}>, model?: string): number;
|
|
326
|
+
declare function countTokensGoogle(messages: Array<{
|
|
327
|
+
role: string;
|
|
328
|
+
content: string;
|
|
329
|
+
}>, apiKey: string, model?: string): Promise<number>;
|
|
330
|
+
declare function countTokensAnthropic(messages: Array<{
|
|
331
|
+
role: string;
|
|
332
|
+
content: string;
|
|
333
|
+
}>, apiKey: string, model?: string): Promise<number>;
|
|
334
|
+
declare function countTokensGroq(messages: Array<{
|
|
335
|
+
role: string;
|
|
336
|
+
content: string;
|
|
337
|
+
}>, model?: string): number;
|
|
338
|
+
declare function countTokensMistral(messages: Array<{
|
|
339
|
+
role: string;
|
|
340
|
+
content: string;
|
|
341
|
+
}>, model?: string): number;
|
|
342
|
+
declare function countTokensXai(messages: Array<{
|
|
343
|
+
role: string;
|
|
344
|
+
content: string;
|
|
345
|
+
}>, model?: string): number;
|
|
346
|
+
declare function countTokensCerebras(messages: Array<{
|
|
347
|
+
role: string;
|
|
348
|
+
content: string;
|
|
349
|
+
}>, model?: string): number;
|
|
350
|
+
declare function countTokensOpenRouter(messages: Array<{
|
|
351
|
+
role: string;
|
|
352
|
+
content: string;
|
|
353
|
+
}>, model?: string): number;
|
|
354
|
+
declare function countTokensOllama(messages: Array<{
|
|
355
|
+
role: string;
|
|
356
|
+
content: string;
|
|
357
|
+
}>, model?: string): number;
|
|
358
|
+
declare function countTokens(options: TokenCountOptions, apiKeys?: Record<string, string>): Promise<TokenCountResult>;
|
|
359
|
+
|
|
305
360
|
declare class Noosphere {
|
|
306
361
|
private config;
|
|
307
362
|
private registry;
|
|
@@ -320,6 +375,7 @@ declare class Noosphere {
|
|
|
320
375
|
getModel(provider: string, modelId: string): Promise<ModelInfo | null>;
|
|
321
376
|
syncModels(modality?: Modality): Promise<SyncResult>;
|
|
322
377
|
getUsage(options?: UsageQueryOptions): UsageSummary;
|
|
378
|
+
countTokens(options: TokenCountOptions): Promise<TokenCountResult>;
|
|
323
379
|
installModel(name: string): Promise<AsyncGenerator<OllamaPullProgress>>;
|
|
324
380
|
uninstallModel(name: string): Promise<void>;
|
|
325
381
|
getHardware(): Promise<{
|
|
@@ -456,4 +512,4 @@ declare function getProviderLogo(providerId: string | undefined | null): Provide
|
|
|
456
512
|
declare function getAllProviderLogos(): Record<string, ProviderLogo>;
|
|
457
513
|
declare const PROVIDER_LOGOS: Record<string, ProviderLogo>;
|
|
458
514
|
|
|
459
|
-
export { AudioCraftProvider, type BaseOptions, type ChatOptions, GoogleMediaProvider, HfLocalProvider, type ImageOptions, type LocalModelInfo, type LocalServiceConfig, type Modality, type ModelInfo, type ModelStatus, type MusicOptions, Noosphere, type NoosphereConfig, NoosphereError, type NoosphereErrorCode, type NoosphereProvider, type NoosphereResult, type NoosphereStream, type OllamaModelDetail, OllamaProvider, type OllamaPullProgress, type OllamaRunningModel, type OpenAICompatConfig, OpenAICompatProvider, OpenAIMediaProvider, PROVIDER_IDS, PROVIDER_LOGOS, type ProviderInfo, type ProviderLogo$1 as ProviderLogo, type SpeakOptions, type StreamEvent, type SyncResult, type TranscriptionOptions, type TranscriptionResult, type UsageEvent, type UsageQueryOptions, type UsageSummary, type VideoOptions, WhisperLocalProvider, detectOpenAICompatServers, getAllProviderLogos, getProviderLogo };
|
|
515
|
+
export { AudioCraftProvider, type BaseOptions, type ChatOptions, GoogleMediaProvider, HfLocalProvider, type ImageOptions, type LocalModelInfo, type LocalServiceConfig, type Modality, type ModelInfo, type ModelStatus, type MusicOptions, Noosphere, type NoosphereConfig, NoosphereError, type NoosphereErrorCode, type NoosphereProvider, type NoosphereResult, type NoosphereStream, type OllamaModelDetail, OllamaProvider, type OllamaPullProgress, type OllamaRunningModel, type OpenAICompatConfig, OpenAICompatProvider, OpenAIMediaProvider, PROVIDER_IDS, PROVIDER_LOGOS, type ProviderInfo, type ProviderLogo$1 as ProviderLogo, type SpeakOptions, type StreamEvent, type SyncResult, type TokenCountOptions, type TokenCountProvider, type TokenCountResult, type TranscriptionOptions, type TranscriptionResult, type UsageEvent, type UsageQueryOptions, type UsageSummary, type VideoOptions, WhisperLocalProvider, countTokens, countTokensAnthropic, countTokensCerebras, countTokensGoogle, countTokensGroq, countTokensMistral, countTokensOllama, countTokensOpenAI, countTokensOpenRouter, countTokensXai, detectOpenAICompatServers, getAllProviderLogos, getProviderLogo };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { AgentContext, AgentEvent, AgentLoopConfig, AgentTool, ApiOptionsMap, AssistantMessageEvent, AssistantMessageEventStream, KnownProvider, OptionsForApi, Api as PiApi, AssistantMessage as PiAssistantMessage, Context as PiContext, ImageContent as PiImageContent, Message as PiMessage, Model as PiModel, Provider as PiProvider, StreamOptions as PiStreamOptions, ToolResultMessage as PiToolResultMessage, Usage as PiUsage, UserMessage as PiUserMessage, QueuedMessage, ReasoningEffort, SimpleStreamOptions, StopReason, StreamFunction, TextContent, ThinkingContent, ToolCall, agentLoop, calculateCost, getApiKey, getModel as getPiModel, getModels as getPiModels, getProviders as getPiProviders, complete as piComplete, completeSimple as piCompleteSimple, stream as piStream, streamSimple as piStreamSimple, setApiKey } from '@mariozechner/pi-ai';
|
|
2
|
+
|
|
1
3
|
type Modality = 'llm' | 'image' | 'video' | 'tts' | 'stt' | 'music' | 'embedding';
|
|
2
4
|
type ModelStatus = 'installed' | 'available' | 'downloading' | 'running' | 'error';
|
|
3
5
|
interface LocalModelInfo {
|
|
@@ -302,6 +304,59 @@ declare class OllamaProvider implements NoosphereProvider {
|
|
|
302
304
|
getRunningModels(): Promise<OllamaRunningModel[]>;
|
|
303
305
|
}
|
|
304
306
|
|
|
307
|
+
type TokenCountProvider = 'openai' | 'google' | 'anthropic' | 'mistral' | 'groq' | 'xai' | 'cerebras' | 'openrouter' | 'ollama' | 'unknown';
|
|
308
|
+
interface TokenCountResult {
|
|
309
|
+
tokens: number;
|
|
310
|
+
model: string;
|
|
311
|
+
provider: TokenCountProvider;
|
|
312
|
+
method: 'tiktoken' | 'api' | 'estimate';
|
|
313
|
+
}
|
|
314
|
+
interface TokenCountOptions {
|
|
315
|
+
messages: Array<{
|
|
316
|
+
role: string;
|
|
317
|
+
content: string;
|
|
318
|
+
}>;
|
|
319
|
+
model?: string;
|
|
320
|
+
provider?: string;
|
|
321
|
+
}
|
|
322
|
+
declare function countTokensOpenAI(messages: Array<{
|
|
323
|
+
role: string;
|
|
324
|
+
content: string;
|
|
325
|
+
}>, model?: string): number;
|
|
326
|
+
declare function countTokensGoogle(messages: Array<{
|
|
327
|
+
role: string;
|
|
328
|
+
content: string;
|
|
329
|
+
}>, apiKey: string, model?: string): Promise<number>;
|
|
330
|
+
declare function countTokensAnthropic(messages: Array<{
|
|
331
|
+
role: string;
|
|
332
|
+
content: string;
|
|
333
|
+
}>, apiKey: string, model?: string): Promise<number>;
|
|
334
|
+
declare function countTokensGroq(messages: Array<{
|
|
335
|
+
role: string;
|
|
336
|
+
content: string;
|
|
337
|
+
}>, model?: string): number;
|
|
338
|
+
declare function countTokensMistral(messages: Array<{
|
|
339
|
+
role: string;
|
|
340
|
+
content: string;
|
|
341
|
+
}>, model?: string): number;
|
|
342
|
+
declare function countTokensXai(messages: Array<{
|
|
343
|
+
role: string;
|
|
344
|
+
content: string;
|
|
345
|
+
}>, model?: string): number;
|
|
346
|
+
declare function countTokensCerebras(messages: Array<{
|
|
347
|
+
role: string;
|
|
348
|
+
content: string;
|
|
349
|
+
}>, model?: string): number;
|
|
350
|
+
declare function countTokensOpenRouter(messages: Array<{
|
|
351
|
+
role: string;
|
|
352
|
+
content: string;
|
|
353
|
+
}>, model?: string): number;
|
|
354
|
+
declare function countTokensOllama(messages: Array<{
|
|
355
|
+
role: string;
|
|
356
|
+
content: string;
|
|
357
|
+
}>, model?: string): number;
|
|
358
|
+
declare function countTokens(options: TokenCountOptions, apiKeys?: Record<string, string>): Promise<TokenCountResult>;
|
|
359
|
+
|
|
305
360
|
declare class Noosphere {
|
|
306
361
|
private config;
|
|
307
362
|
private registry;
|
|
@@ -320,6 +375,7 @@ declare class Noosphere {
|
|
|
320
375
|
getModel(provider: string, modelId: string): Promise<ModelInfo | null>;
|
|
321
376
|
syncModels(modality?: Modality): Promise<SyncResult>;
|
|
322
377
|
getUsage(options?: UsageQueryOptions): UsageSummary;
|
|
378
|
+
countTokens(options: TokenCountOptions): Promise<TokenCountResult>;
|
|
323
379
|
installModel(name: string): Promise<AsyncGenerator<OllamaPullProgress>>;
|
|
324
380
|
uninstallModel(name: string): Promise<void>;
|
|
325
381
|
getHardware(): Promise<{
|
|
@@ -456,4 +512,4 @@ declare function getProviderLogo(providerId: string | undefined | null): Provide
|
|
|
456
512
|
declare function getAllProviderLogos(): Record<string, ProviderLogo>;
|
|
457
513
|
declare const PROVIDER_LOGOS: Record<string, ProviderLogo>;
|
|
458
514
|
|
|
459
|
-
export { AudioCraftProvider, type BaseOptions, type ChatOptions, GoogleMediaProvider, HfLocalProvider, type ImageOptions, type LocalModelInfo, type LocalServiceConfig, type Modality, type ModelInfo, type ModelStatus, type MusicOptions, Noosphere, type NoosphereConfig, NoosphereError, type NoosphereErrorCode, type NoosphereProvider, type NoosphereResult, type NoosphereStream, type OllamaModelDetail, OllamaProvider, type OllamaPullProgress, type OllamaRunningModel, type OpenAICompatConfig, OpenAICompatProvider, OpenAIMediaProvider, PROVIDER_IDS, PROVIDER_LOGOS, type ProviderInfo, type ProviderLogo$1 as ProviderLogo, type SpeakOptions, type StreamEvent, type SyncResult, type TranscriptionOptions, type TranscriptionResult, type UsageEvent, type UsageQueryOptions, type UsageSummary, type VideoOptions, WhisperLocalProvider, detectOpenAICompatServers, getAllProviderLogos, getProviderLogo };
|
|
515
|
+
export { AudioCraftProvider, type BaseOptions, type ChatOptions, GoogleMediaProvider, HfLocalProvider, type ImageOptions, type LocalModelInfo, type LocalServiceConfig, type Modality, type ModelInfo, type ModelStatus, type MusicOptions, Noosphere, type NoosphereConfig, NoosphereError, type NoosphereErrorCode, type NoosphereProvider, type NoosphereResult, type NoosphereStream, type OllamaModelDetail, OllamaProvider, type OllamaPullProgress, type OllamaRunningModel, type OpenAICompatConfig, OpenAICompatProvider, OpenAIMediaProvider, PROVIDER_IDS, PROVIDER_LOGOS, type ProviderInfo, type ProviderLogo$1 as ProviderLogo, type SpeakOptions, type StreamEvent, type SyncResult, type TokenCountOptions, type TokenCountProvider, type TokenCountResult, type TranscriptionOptions, type TranscriptionResult, type UsageEvent, type UsageQueryOptions, type UsageSummary, type VideoOptions, WhisperLocalProvider, countTokens, countTokensAnthropic, countTokensCerebras, countTokensGoogle, countTokensGroq, countTokensMistral, countTokensOllama, countTokensOpenAI, countTokensOpenRouter, countTokensXai, detectOpenAICompatServers, getAllProviderLogos, getProviderLogo };
|
package/dist/index.js
CHANGED
|
@@ -108,6 +108,136 @@ function resolveConfig(input) {
|
|
|
108
108
|
};
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
+
// src/token-counter.ts
|
|
112
|
+
import { encoding_for_model } from "tiktoken";
|
|
113
|
+
var TIKTOKEN_MODEL_MAP = {
|
|
114
|
+
"gpt-4o": "gpt-4o",
|
|
115
|
+
"gpt-4o-mini": "gpt-4o-mini",
|
|
116
|
+
"gpt-4-turbo": "gpt-4-turbo",
|
|
117
|
+
"gpt-4": "gpt-4",
|
|
118
|
+
"gpt-3.5-turbo": "gpt-3.5-turbo"
|
|
119
|
+
};
|
|
120
|
+
function resolveTiktokenModel(model) {
|
|
121
|
+
if (model in TIKTOKEN_MODEL_MAP) return TIKTOKEN_MODEL_MAP[model];
|
|
122
|
+
for (const [prefix, tikModel] of Object.entries(TIKTOKEN_MODEL_MAP)) {
|
|
123
|
+
if (model.startsWith(prefix)) return tikModel;
|
|
124
|
+
}
|
|
125
|
+
return "gpt-4o";
|
|
126
|
+
}
|
|
127
|
+
function countWithTiktoken(messages, model) {
|
|
128
|
+
const tikModel = resolveTiktokenModel(model);
|
|
129
|
+
const enc = encoding_for_model(tikModel);
|
|
130
|
+
let tokens = 0;
|
|
131
|
+
for (const msg of messages) {
|
|
132
|
+
tokens += 4;
|
|
133
|
+
tokens += enc.encode(msg.role).length;
|
|
134
|
+
tokens += enc.encode(msg.content).length;
|
|
135
|
+
}
|
|
136
|
+
tokens += 2;
|
|
137
|
+
enc.free();
|
|
138
|
+
return tokens;
|
|
139
|
+
}
|
|
140
|
+
function countTokensOpenAI(messages, model = "gpt-4o") {
|
|
141
|
+
return countWithTiktoken(messages, model);
|
|
142
|
+
}
|
|
143
|
+
async function countTokensGoogle(messages, apiKey, model = "gemini-2.5-flash") {
|
|
144
|
+
const contents = messages.map((m) => ({
|
|
145
|
+
role: m.role === "assistant" ? "model" : "user",
|
|
146
|
+
parts: [{ text: m.content }]
|
|
147
|
+
}));
|
|
148
|
+
const res = await fetch(
|
|
149
|
+
`https://generativelanguage.googleapis.com/v1beta/models/${model}:countTokens?key=${apiKey}`,
|
|
150
|
+
{
|
|
151
|
+
method: "POST",
|
|
152
|
+
headers: { "Content-Type": "application/json" },
|
|
153
|
+
body: JSON.stringify({ contents })
|
|
154
|
+
}
|
|
155
|
+
);
|
|
156
|
+
if (!res.ok) {
|
|
157
|
+
throw new Error(`Google countTokens failed (${res.status}): ${await res.text()}`);
|
|
158
|
+
}
|
|
159
|
+
const data = await res.json();
|
|
160
|
+
return data.totalTokens;
|
|
161
|
+
}
|
|
162
|
+
async function countTokensAnthropic(messages, apiKey, model = "claude-sonnet-4-20250514") {
|
|
163
|
+
const anthropicMessages = messages.filter((m) => m.role !== "system").map((m) => ({ role: m.role, content: m.content }));
|
|
164
|
+
const systemPrompt = messages.find((m) => m.role === "system")?.content;
|
|
165
|
+
const body = {
|
|
166
|
+
model,
|
|
167
|
+
messages: anthropicMessages
|
|
168
|
+
};
|
|
169
|
+
if (systemPrompt) body.system = systemPrompt;
|
|
170
|
+
const res = await fetch("https://api.anthropic.com/v1/messages/count_tokens", {
|
|
171
|
+
method: "POST",
|
|
172
|
+
headers: {
|
|
173
|
+
"x-api-key": apiKey,
|
|
174
|
+
"anthropic-version": "2023-06-01",
|
|
175
|
+
"Content-Type": "application/json"
|
|
176
|
+
},
|
|
177
|
+
body: JSON.stringify(body)
|
|
178
|
+
});
|
|
179
|
+
if (!res.ok) {
|
|
180
|
+
throw new Error(`Anthropic countTokens failed (${res.status}): ${await res.text()}`);
|
|
181
|
+
}
|
|
182
|
+
const data = await res.json();
|
|
183
|
+
return data.input_tokens;
|
|
184
|
+
}
|
|
185
|
+
function countTokensGroq(messages, model = "llama-3.3-70b-versatile") {
|
|
186
|
+
return countWithTiktoken(messages, model);
|
|
187
|
+
}
|
|
188
|
+
function countTokensMistral(messages, model = "mistral-large-latest") {
|
|
189
|
+
return countWithTiktoken(messages, model);
|
|
190
|
+
}
|
|
191
|
+
function countTokensXai(messages, model = "grok-3") {
|
|
192
|
+
return countWithTiktoken(messages, model);
|
|
193
|
+
}
|
|
194
|
+
function countTokensCerebras(messages, model = "llama-3.3-70b") {
|
|
195
|
+
return countWithTiktoken(messages, model);
|
|
196
|
+
}
|
|
197
|
+
function countTokensOpenRouter(messages, model = "openai/gpt-4o") {
|
|
198
|
+
return countWithTiktoken(messages, model);
|
|
199
|
+
}
|
|
200
|
+
function countTokensOllama(messages, model = "llama3.2") {
|
|
201
|
+
return countWithTiktoken(messages, model);
|
|
202
|
+
}
|
|
203
|
+
var PROVIDER_MODEL_PREFIXES = [
|
|
204
|
+
{ prefixes: ["gemini", "imagen", "veo"], provider: "google" },
|
|
205
|
+
{ prefixes: ["claude"], provider: "anthropic" },
|
|
206
|
+
{ prefixes: ["gpt-", "o1", "o3", "o4", "chatgpt", "dall-e", "gpt-image", "tts-", "whisper", "sora"], provider: "openai" },
|
|
207
|
+
{ prefixes: ["grok"], provider: "xai" },
|
|
208
|
+
{ prefixes: ["mistral", "mixtral", "codestral", "ministral"], provider: "mistral" },
|
|
209
|
+
{ prefixes: ["llama", "gemma", "qwen", "deepseek", "phi"], provider: "groq" }
|
|
210
|
+
];
|
|
211
|
+
function inferProvider(model) {
|
|
212
|
+
const lower = model.toLowerCase();
|
|
213
|
+
for (const { prefixes, provider } of PROVIDER_MODEL_PREFIXES) {
|
|
214
|
+
for (const prefix of prefixes) {
|
|
215
|
+
if (lower.startsWith(prefix)) return provider;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return "unknown";
|
|
219
|
+
}
|
|
220
|
+
async function countTokens(options, apiKeys) {
|
|
221
|
+
const model = options.model ?? "gpt-4o";
|
|
222
|
+
const provider = options.provider ?? inferProvider(model);
|
|
223
|
+
if (provider === "google" && apiKeys?.google) {
|
|
224
|
+
const tokens2 = await countTokensGoogle(options.messages, apiKeys.google, model);
|
|
225
|
+
return { tokens: tokens2, model, provider: "google", method: "api" };
|
|
226
|
+
}
|
|
227
|
+
if (provider === "anthropic" && apiKeys?.anthropic) {
|
|
228
|
+
const tokens2 = await countTokensAnthropic(options.messages, apiKeys.anthropic, model);
|
|
229
|
+
return { tokens: tokens2, model, provider: "anthropic", method: "api" };
|
|
230
|
+
}
|
|
231
|
+
const tokens = countWithTiktoken(options.messages, model);
|
|
232
|
+
const resolvedProvider = provider === "unknown" ? "openai" : provider;
|
|
233
|
+
return {
|
|
234
|
+
tokens,
|
|
235
|
+
model,
|
|
236
|
+
provider: resolvedProvider,
|
|
237
|
+
method: provider === "openai" ? "tiktoken" : "tiktoken"
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
111
241
|
// src/logos.ts
|
|
112
242
|
var CDN_BASE = "https://blockchainstarter.nyc3.digitaloceanspaces.com/noosphere/logos";
|
|
113
243
|
var PROVIDER_IDS = [
|
|
@@ -2940,7 +3070,7 @@ var GoogleMediaProvider = class {
|
|
|
2940
3070
|
};
|
|
2941
3071
|
}
|
|
2942
3072
|
async video(options) {
|
|
2943
|
-
const model = options.model ?? "veo-
|
|
3073
|
+
const model = options.model ?? "veo-2.0-generate-001";
|
|
2944
3074
|
const start = Date.now();
|
|
2945
3075
|
const body = {
|
|
2946
3076
|
instances: [{ prompt: options.prompt }],
|
|
@@ -2975,10 +3105,15 @@ var GoogleMediaProvider = class {
|
|
|
2975
3105
|
if (!pollRes.ok) continue;
|
|
2976
3106
|
const status = await pollRes.json();
|
|
2977
3107
|
if (status.done) {
|
|
2978
|
-
|
|
2979
|
-
|
|
3108
|
+
if (status.error) {
|
|
3109
|
+
throw new Error(`Google video generation error: ${status.error.message ?? JSON.stringify(status.error)}`);
|
|
3110
|
+
}
|
|
3111
|
+
const resp = status.response ?? {};
|
|
3112
|
+
const samples = resp.generateVideoResponse?.generatedSamples ?? resp.generatedSamples ?? [];
|
|
3113
|
+
const video = samples[0]?.video;
|
|
3114
|
+
if (video?.bytesBase64Encoded) {
|
|
2980
3115
|
return {
|
|
2981
|
-
buffer: Buffer.from(
|
|
3116
|
+
buffer: Buffer.from(video.bytesBase64Encoded, "base64"),
|
|
2982
3117
|
provider: "google-media",
|
|
2983
3118
|
model,
|
|
2984
3119
|
modality: "video",
|
|
@@ -2987,16 +3122,32 @@ var GoogleMediaProvider = class {
|
|
|
2987
3122
|
media: { format: "mp4", duration: options.duration }
|
|
2988
3123
|
};
|
|
2989
3124
|
}
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3125
|
+
if (video?.uri) {
|
|
3126
|
+
const separator = video.uri.includes("?") ? "&" : "?";
|
|
3127
|
+
const videoRes = await fetch(`${video.uri}${separator}key=${this.apiKey}`, { redirect: "follow" });
|
|
3128
|
+
if (videoRes.ok) {
|
|
3129
|
+
const buffer = Buffer.from(await videoRes.arrayBuffer());
|
|
3130
|
+
return {
|
|
3131
|
+
buffer,
|
|
3132
|
+
provider: "google-media",
|
|
3133
|
+
model,
|
|
3134
|
+
modality: "video",
|
|
3135
|
+
latencyMs: Date.now() - start,
|
|
3136
|
+
usage: { cost: 0, unit: "per_video" },
|
|
3137
|
+
media: { format: "mp4", duration: options.duration }
|
|
3138
|
+
};
|
|
3139
|
+
}
|
|
3140
|
+
return {
|
|
3141
|
+
url: video.uri,
|
|
3142
|
+
provider: "google-media",
|
|
3143
|
+
model,
|
|
3144
|
+
modality: "video",
|
|
3145
|
+
latencyMs: Date.now() - start,
|
|
3146
|
+
usage: { cost: 0, unit: "per_video" },
|
|
3147
|
+
media: { format: "mp4", duration: options.duration }
|
|
3148
|
+
};
|
|
3149
|
+
}
|
|
3150
|
+
throw new Error("Google video generation completed but returned no video data");
|
|
3000
3151
|
}
|
|
3001
3152
|
}
|
|
3002
3153
|
throw new Error(`Google video generation timed out after 5 minutes`);
|
|
@@ -3193,6 +3344,12 @@ var Noosphere = class {
|
|
|
3193
3344
|
getUsage(options) {
|
|
3194
3345
|
return this.tracker.getSummary(options);
|
|
3195
3346
|
}
|
|
3347
|
+
async countTokens(options) {
|
|
3348
|
+
const keys = {};
|
|
3349
|
+
if (this.config.keys?.google) keys.google = this.config.keys.google;
|
|
3350
|
+
if (this.config.keys?.anthropic) keys.anthropic = this.config.keys.anthropic;
|
|
3351
|
+
return countTokens(options, keys);
|
|
3352
|
+
}
|
|
3196
3353
|
// --- Local Model Management ---
|
|
3197
3354
|
async installModel(name) {
|
|
3198
3355
|
if (!this.initialized) await this.init();
|
|
@@ -3427,6 +3584,12 @@ var Noosphere = class {
|
|
|
3427
3584
|
await this.tracker.record(event);
|
|
3428
3585
|
}
|
|
3429
3586
|
};
|
|
3587
|
+
|
|
3588
|
+
// src/index.ts
|
|
3589
|
+
import { agentLoop } from "@mariozechner/pi-ai";
|
|
3590
|
+
import { calculateCost, getModel, getModels as getModels2, getProviders as getProviders2 } from "@mariozechner/pi-ai";
|
|
3591
|
+
import { stream as stream2, complete as complete2, streamSimple, completeSimple } from "@mariozechner/pi-ai";
|
|
3592
|
+
import { setApiKey as setApiKey2, getApiKey } from "@mariozechner/pi-ai";
|
|
3430
3593
|
export {
|
|
3431
3594
|
AudioCraftProvider,
|
|
3432
3595
|
GoogleMediaProvider,
|
|
@@ -3439,8 +3602,29 @@ export {
|
|
|
3439
3602
|
PROVIDER_IDS,
|
|
3440
3603
|
PROVIDER_LOGOS,
|
|
3441
3604
|
WhisperLocalProvider,
|
|
3605
|
+
agentLoop,
|
|
3606
|
+
calculateCost,
|
|
3607
|
+
countTokens,
|
|
3608
|
+
countTokensAnthropic,
|
|
3609
|
+
countTokensCerebras,
|
|
3610
|
+
countTokensGoogle,
|
|
3611
|
+
countTokensGroq,
|
|
3612
|
+
countTokensMistral,
|
|
3613
|
+
countTokensOllama,
|
|
3614
|
+
countTokensOpenAI,
|
|
3615
|
+
countTokensOpenRouter,
|
|
3616
|
+
countTokensXai,
|
|
3442
3617
|
detectOpenAICompatServers,
|
|
3443
3618
|
getAllProviderLogos,
|
|
3444
|
-
|
|
3619
|
+
getApiKey,
|
|
3620
|
+
getModel as getPiModel,
|
|
3621
|
+
getModels2 as getPiModels,
|
|
3622
|
+
getProviders2 as getPiProviders,
|
|
3623
|
+
getProviderLogo,
|
|
3624
|
+
complete2 as piComplete,
|
|
3625
|
+
completeSimple as piCompleteSimple,
|
|
3626
|
+
stream2 as piStream,
|
|
3627
|
+
streamSimple as piStreamSimple,
|
|
3628
|
+
setApiKey2 as setApiKey
|
|
3445
3629
|
};
|
|
3446
3630
|
//# sourceMappingURL=index.js.map
|