noosphere 0.1.0
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/dist/index.d.ts +257 -0
- package/dist/index.js +1290 -0
- package/dist/index.js.map +1 -0
- package/package.json +38 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
type Modality = 'llm' | 'image' | 'video' | 'tts';
|
|
2
|
+
interface BaseOptions {
|
|
3
|
+
provider?: string;
|
|
4
|
+
model?: string;
|
|
5
|
+
metadata?: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
interface ChatOptions extends BaseOptions {
|
|
8
|
+
messages: Array<{
|
|
9
|
+
role: 'system' | 'user' | 'assistant';
|
|
10
|
+
content: string;
|
|
11
|
+
}>;
|
|
12
|
+
temperature?: number;
|
|
13
|
+
maxTokens?: number;
|
|
14
|
+
jsonMode?: boolean;
|
|
15
|
+
}
|
|
16
|
+
interface ImageOptions extends BaseOptions {
|
|
17
|
+
prompt: string;
|
|
18
|
+
negativePrompt?: string;
|
|
19
|
+
width?: number;
|
|
20
|
+
height?: number;
|
|
21
|
+
seed?: number;
|
|
22
|
+
steps?: number;
|
|
23
|
+
guidanceScale?: number;
|
|
24
|
+
}
|
|
25
|
+
interface VideoOptions extends BaseOptions {
|
|
26
|
+
prompt: string;
|
|
27
|
+
imageUrl?: string;
|
|
28
|
+
duration?: number;
|
|
29
|
+
fps?: number;
|
|
30
|
+
width?: number;
|
|
31
|
+
height?: number;
|
|
32
|
+
}
|
|
33
|
+
interface SpeakOptions extends BaseOptions {
|
|
34
|
+
text: string;
|
|
35
|
+
voice?: string;
|
|
36
|
+
language?: string;
|
|
37
|
+
speed?: number;
|
|
38
|
+
format?: 'mp3' | 'wav' | 'ogg';
|
|
39
|
+
}
|
|
40
|
+
interface NoosphereResult {
|
|
41
|
+
content?: string;
|
|
42
|
+
thinking?: string;
|
|
43
|
+
url?: string;
|
|
44
|
+
buffer?: Buffer;
|
|
45
|
+
provider: string;
|
|
46
|
+
model: string;
|
|
47
|
+
modality: Modality;
|
|
48
|
+
latencyMs: number;
|
|
49
|
+
usage: {
|
|
50
|
+
cost: number;
|
|
51
|
+
input?: number;
|
|
52
|
+
output?: number;
|
|
53
|
+
unit?: string;
|
|
54
|
+
};
|
|
55
|
+
media?: {
|
|
56
|
+
width?: number;
|
|
57
|
+
height?: number;
|
|
58
|
+
duration?: number;
|
|
59
|
+
format?: string;
|
|
60
|
+
fps?: number;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
interface StreamEvent {
|
|
64
|
+
type: 'text_delta' | 'thinking_delta' | 'done' | 'error';
|
|
65
|
+
delta?: string;
|
|
66
|
+
error?: Error;
|
|
67
|
+
result?: NoosphereResult;
|
|
68
|
+
}
|
|
69
|
+
interface NoosphereStream extends AsyncIterable<StreamEvent> {
|
|
70
|
+
result(): Promise<NoosphereResult>;
|
|
71
|
+
abort(): void;
|
|
72
|
+
}
|
|
73
|
+
interface ModelInfo {
|
|
74
|
+
id: string;
|
|
75
|
+
provider: string;
|
|
76
|
+
name: string;
|
|
77
|
+
modality: Modality;
|
|
78
|
+
local: boolean;
|
|
79
|
+
cost: {
|
|
80
|
+
price: number;
|
|
81
|
+
unit: string;
|
|
82
|
+
};
|
|
83
|
+
capabilities?: {
|
|
84
|
+
contextWindow?: number;
|
|
85
|
+
maxTokens?: number;
|
|
86
|
+
supportsVision?: boolean;
|
|
87
|
+
supportsReasoning?: boolean;
|
|
88
|
+
supportsFunctionCalling?: boolean;
|
|
89
|
+
supportsStreaming?: boolean;
|
|
90
|
+
maxWidth?: number;
|
|
91
|
+
maxHeight?: number;
|
|
92
|
+
supportsNegativePrompt?: boolean;
|
|
93
|
+
maxDuration?: number;
|
|
94
|
+
supportsImageToVideo?: boolean;
|
|
95
|
+
voices?: string[];
|
|
96
|
+
languages?: string[];
|
|
97
|
+
supportsVoiceCloning?: boolean;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
interface ProviderInfo {
|
|
101
|
+
id: string;
|
|
102
|
+
name: string;
|
|
103
|
+
modalities: Modality[];
|
|
104
|
+
local: boolean;
|
|
105
|
+
status: 'online' | 'offline' | 'degraded';
|
|
106
|
+
modelCount: number;
|
|
107
|
+
}
|
|
108
|
+
interface UsageEvent {
|
|
109
|
+
modality: Modality;
|
|
110
|
+
provider: string;
|
|
111
|
+
model: string;
|
|
112
|
+
cost: number;
|
|
113
|
+
latencyMs: number;
|
|
114
|
+
input?: number;
|
|
115
|
+
output?: number;
|
|
116
|
+
unit?: string;
|
|
117
|
+
timestamp: string;
|
|
118
|
+
success: boolean;
|
|
119
|
+
error?: string;
|
|
120
|
+
metadata?: Record<string, unknown>;
|
|
121
|
+
}
|
|
122
|
+
interface UsageQueryOptions {
|
|
123
|
+
since?: string | Date;
|
|
124
|
+
until?: string | Date;
|
|
125
|
+
provider?: string;
|
|
126
|
+
modality?: Modality;
|
|
127
|
+
}
|
|
128
|
+
interface UsageSummary {
|
|
129
|
+
totalCost: number;
|
|
130
|
+
totalRequests: number;
|
|
131
|
+
byProvider: Record<string, number>;
|
|
132
|
+
byModality: Record<Modality, number>;
|
|
133
|
+
}
|
|
134
|
+
interface SyncResult {
|
|
135
|
+
synced: number;
|
|
136
|
+
byProvider: Record<string, number>;
|
|
137
|
+
errors: string[];
|
|
138
|
+
}
|
|
139
|
+
type NoosphereErrorCode = 'PROVIDER_UNAVAILABLE' | 'MODEL_NOT_FOUND' | 'AUTH_FAILED' | 'RATE_LIMITED' | 'TIMEOUT' | 'GENERATION_FAILED' | 'INVALID_INPUT' | 'NO_PROVIDER';
|
|
140
|
+
interface LocalServiceConfig {
|
|
141
|
+
enabled?: boolean;
|
|
142
|
+
host?: string;
|
|
143
|
+
port?: number;
|
|
144
|
+
type?: string;
|
|
145
|
+
}
|
|
146
|
+
interface NoosphereConfig {
|
|
147
|
+
keys?: {
|
|
148
|
+
openai?: string;
|
|
149
|
+
anthropic?: string;
|
|
150
|
+
google?: string;
|
|
151
|
+
fal?: string;
|
|
152
|
+
openrouter?: string;
|
|
153
|
+
huggingface?: string;
|
|
154
|
+
groq?: string;
|
|
155
|
+
mistral?: string;
|
|
156
|
+
xai?: string;
|
|
157
|
+
};
|
|
158
|
+
local?: {
|
|
159
|
+
ollama?: LocalServiceConfig;
|
|
160
|
+
comfyui?: LocalServiceConfig;
|
|
161
|
+
piper?: LocalServiceConfig;
|
|
162
|
+
kokoro?: LocalServiceConfig;
|
|
163
|
+
custom?: LocalServiceConfig[];
|
|
164
|
+
};
|
|
165
|
+
defaults?: {
|
|
166
|
+
llm?: {
|
|
167
|
+
provider: string;
|
|
168
|
+
model: string;
|
|
169
|
+
};
|
|
170
|
+
image?: {
|
|
171
|
+
provider: string;
|
|
172
|
+
model: string;
|
|
173
|
+
};
|
|
174
|
+
video?: {
|
|
175
|
+
provider: string;
|
|
176
|
+
model: string;
|
|
177
|
+
};
|
|
178
|
+
tts?: {
|
|
179
|
+
provider: string;
|
|
180
|
+
model: string;
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
autoDetectLocal?: boolean;
|
|
184
|
+
discoveryCacheTTL?: number;
|
|
185
|
+
retry?: {
|
|
186
|
+
maxRetries?: number;
|
|
187
|
+
backoffMs?: number;
|
|
188
|
+
retryableErrors?: NoosphereErrorCode[];
|
|
189
|
+
failover?: boolean;
|
|
190
|
+
};
|
|
191
|
+
timeout?: {
|
|
192
|
+
llm?: number;
|
|
193
|
+
image?: number;
|
|
194
|
+
video?: number;
|
|
195
|
+
tts?: number;
|
|
196
|
+
};
|
|
197
|
+
onUsage?: (usage: UsageEvent) => void | Promise<void>;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
interface NoosphereProvider {
|
|
201
|
+
readonly id: string;
|
|
202
|
+
readonly name: string;
|
|
203
|
+
readonly modalities: Modality[];
|
|
204
|
+
readonly isLocal: boolean;
|
|
205
|
+
ping(): Promise<boolean>;
|
|
206
|
+
listModels(modality?: Modality): Promise<ModelInfo[]>;
|
|
207
|
+
chat?(options: ChatOptions): Promise<NoosphereResult>;
|
|
208
|
+
stream?(options: ChatOptions): NoosphereStream;
|
|
209
|
+
image?(options: ImageOptions): Promise<NoosphereResult>;
|
|
210
|
+
video?(options: VideoOptions): Promise<NoosphereResult>;
|
|
211
|
+
speak?(options: SpeakOptions): Promise<NoosphereResult>;
|
|
212
|
+
dispose?(): Promise<void>;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
declare class Noosphere {
|
|
216
|
+
private config;
|
|
217
|
+
private registry;
|
|
218
|
+
private tracker;
|
|
219
|
+
private initialized;
|
|
220
|
+
constructor(config?: NoosphereConfig);
|
|
221
|
+
/** Register a custom provider adapter */
|
|
222
|
+
registerProvider(provider: NoosphereProvider): void;
|
|
223
|
+
chat(options: ChatOptions): Promise<NoosphereResult>;
|
|
224
|
+
stream(options: ChatOptions): NoosphereStream;
|
|
225
|
+
image(options: ImageOptions): Promise<NoosphereResult>;
|
|
226
|
+
video(options: VideoOptions): Promise<NoosphereResult>;
|
|
227
|
+
speak(options: SpeakOptions): Promise<NoosphereResult>;
|
|
228
|
+
getProviders(modality?: Modality): Promise<ProviderInfo[]>;
|
|
229
|
+
getModels(modality?: Modality): Promise<ModelInfo[]>;
|
|
230
|
+
getModel(provider: string, modelId: string): Promise<ModelInfo | null>;
|
|
231
|
+
syncModels(): Promise<SyncResult>;
|
|
232
|
+
getUsage(options?: UsageQueryOptions): UsageSummary;
|
|
233
|
+
dispose(): Promise<void>;
|
|
234
|
+
private init;
|
|
235
|
+
private resolveProviderForModality;
|
|
236
|
+
private executeWithRetry;
|
|
237
|
+
private trackUsage;
|
|
238
|
+
private trackError;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
declare class NoosphereError extends Error {
|
|
242
|
+
readonly code: NoosphereErrorCode;
|
|
243
|
+
readonly provider: string;
|
|
244
|
+
readonly modality: Modality;
|
|
245
|
+
readonly model?: string;
|
|
246
|
+
readonly cause?: Error;
|
|
247
|
+
constructor(message: string, options: {
|
|
248
|
+
code: NoosphereErrorCode;
|
|
249
|
+
provider: string;
|
|
250
|
+
modality: Modality;
|
|
251
|
+
model?: string;
|
|
252
|
+
cause?: Error;
|
|
253
|
+
});
|
|
254
|
+
isRetryable(): boolean;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export { type BaseOptions, type ChatOptions, type ImageOptions, type LocalServiceConfig, type Modality, type ModelInfo, Noosphere, type NoosphereConfig, NoosphereError, type NoosphereErrorCode, type NoosphereProvider, type NoosphereResult, type NoosphereStream, type ProviderInfo, type SpeakOptions, type StreamEvent, type SyncResult, type UsageEvent, type UsageQueryOptions, type UsageSummary, type VideoOptions };
|