@providerprotocol/ai 0.0.37 → 0.0.38

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.
@@ -1,3 +1,6 @@
1
+ import {
2
+ express
3
+ } from "./chunk-FYSZFIZS.js";
1
4
  import {
2
5
  h3
3
6
  } from "./chunk-ZRVNAET3.js";
@@ -7,9 +10,6 @@ import {
7
10
  import {
8
11
  webapi
9
12
  } from "./chunk-LTEMH3CI.js";
10
- import {
11
- express
12
- } from "./chunk-FYSZFIZS.js";
13
13
 
14
14
  // src/providers/proxy/server/index.ts
15
15
  var server = {
@@ -26,4 +26,4 @@ var server = {
26
26
  export {
27
27
  server
28
28
  };
29
- //# sourceMappingURL=chunk-IK6NRCW5.js.map
29
+ //# sourceMappingURL=chunk-BDXH6NQS.js.map
@@ -0,0 +1,510 @@
1
+ import { e as Provider } from '../llm-DS_-l71X.js';
2
+ import '../stream-sXhBtWjl.js';
3
+
4
+ /**
5
+ * @fileoverview Moonshot AI Provider Type Definitions
6
+ *
7
+ * This module contains all TypeScript type definitions for the Moonshot provider,
8
+ * including types for the Chat Completions API (OpenAI-compatible).
9
+ *
10
+ * @module providers/moonshot/types
11
+ */
12
+ /**
13
+ * Thinking mode configuration for Moonshot models.
14
+ *
15
+ * By default, kimi-k2.5 has thinking mode enabled and returns reasoning traces.
16
+ * Use `{ type: 'disabled' }` to switch to instant mode for faster responses.
17
+ */
18
+ interface MoonshotThinkingConfig {
19
+ /** Thinking mode type: 'enabled' (default) or 'disabled' for instant mode */
20
+ type: 'enabled' | 'disabled';
21
+ }
22
+ /**
23
+ * Parameters for the Moonshot Chat Completions API.
24
+ *
25
+ * These parameters are passed directly to the `/v1/chat/completions` endpoint.
26
+ * Moonshot's API is OpenAI-compatible with additional thinking mode support.
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * const params: MoonshotLLMParams = {
31
+ * temperature: 1.0,
32
+ * max_tokens: 1000,
33
+ * thinking: { type: 'enabled' } // Default for kimi-k2.5
34
+ * };
35
+ * ```
36
+ */
37
+ interface MoonshotLLMParams {
38
+ /** Maximum number of tokens to generate */
39
+ max_tokens?: number;
40
+ /** Maximum completion tokens (alias for max_tokens) */
41
+ max_completion_tokens?: number;
42
+ /** Temperature for randomness (0.0 to 2.0). Default: 1.0 (thinking) or 0.6 (instant) */
43
+ temperature?: number;
44
+ /** Top-p (nucleus) sampling (0.0 - 1.0), default 0.95 */
45
+ top_p?: number;
46
+ /** Custom stop sequences */
47
+ stop?: string | string[];
48
+ /** Frequency penalty (-2.0 - 2.0) */
49
+ frequency_penalty?: number;
50
+ /** Presence penalty (-2.0 - 2.0) */
51
+ presence_penalty?: number;
52
+ /** Seed for deterministic sampling */
53
+ seed?: number;
54
+ /** User identifier for rate limit tracking */
55
+ user?: string;
56
+ /** Response format for structured output */
57
+ response_format?: MoonshotResponseFormat;
58
+ /** Thinking mode configuration (kimi-k2.5 specific) */
59
+ thinking?: MoonshotThinkingConfig;
60
+ /**
61
+ * Builtin tools to enable for this request.
62
+ * Use the `tools` helper object to create these.
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * import { moonshot, tools } from '@providerprotocol/ai/moonshot';
67
+ *
68
+ * const model = llm({
69
+ * model: moonshot('kimi-k2.5'),
70
+ * params: {
71
+ * tools: [tools.webSearch(), tools.codeRunner()],
72
+ * },
73
+ * });
74
+ * ```
75
+ */
76
+ tools?: MoonshotTool[];
77
+ }
78
+ /**
79
+ * Response format options for structured output.
80
+ */
81
+ type MoonshotResponseFormat = {
82
+ type: 'text';
83
+ } | {
84
+ type: 'json_object';
85
+ } | {
86
+ type: 'json_schema';
87
+ json_schema: {
88
+ name: string;
89
+ description?: string;
90
+ schema: Record<string, unknown>;
91
+ strict?: boolean;
92
+ };
93
+ };
94
+ /**
95
+ * Request body for the Moonshot Chat Completions API.
96
+ */
97
+ interface MoonshotRequest {
98
+ model: string;
99
+ messages: MoonshotMessage[];
100
+ temperature?: number;
101
+ top_p?: number;
102
+ stream?: boolean;
103
+ stream_options?: {
104
+ include_usage?: boolean;
105
+ };
106
+ stop?: string | string[];
107
+ max_tokens?: number;
108
+ max_completion_tokens?: number;
109
+ presence_penalty?: number;
110
+ frequency_penalty?: number;
111
+ user?: string;
112
+ seed?: number;
113
+ tools?: MoonshotTool[];
114
+ tool_choice?: MoonshotToolChoice;
115
+ response_format?: MoonshotResponseFormat;
116
+ thinking?: MoonshotThinkingConfig;
117
+ }
118
+ /**
119
+ * Union type for all message types in the Moonshot API.
120
+ */
121
+ type MoonshotMessage = MoonshotSystemMessage | MoonshotUserMessage | MoonshotAssistantMessage | MoonshotToolMessage;
122
+ /** System message for setting context and instructions */
123
+ interface MoonshotSystemMessage {
124
+ role: 'system';
125
+ content: string;
126
+ }
127
+ /** User message with text or multimodal content */
128
+ interface MoonshotUserMessage {
129
+ role: 'user';
130
+ content: string | MoonshotUserContent[];
131
+ }
132
+ /** Assistant message containing the model's response */
133
+ interface MoonshotAssistantMessage {
134
+ role: 'assistant';
135
+ content?: string | null;
136
+ /** Reasoning traces from thinking mode */
137
+ reasoning_content?: string | null;
138
+ tool_calls?: MoonshotToolCall[];
139
+ }
140
+ /** Tool result message providing output from a function call */
141
+ interface MoonshotToolMessage {
142
+ role: 'tool';
143
+ content: string;
144
+ tool_call_id: string;
145
+ }
146
+ /**
147
+ * Union type for user content parts (text, image, or video).
148
+ */
149
+ type MoonshotUserContent = MoonshotTextContent | MoonshotImageContent | MoonshotVideoContent;
150
+ /** Text content part */
151
+ interface MoonshotTextContent {
152
+ type: 'text';
153
+ text: string;
154
+ }
155
+ /** Image content part with URL reference (for vision models) */
156
+ interface MoonshotImageContent {
157
+ type: 'image_url';
158
+ image_url: {
159
+ url: string;
160
+ };
161
+ }
162
+ /** Video content part with URL reference (experimental) */
163
+ interface MoonshotVideoContent {
164
+ type: 'video_url';
165
+ video_url: {
166
+ url: string;
167
+ };
168
+ }
169
+ /**
170
+ * Tool call structure in assistant messages.
171
+ */
172
+ interface MoonshotToolCall {
173
+ id: string;
174
+ type: 'function';
175
+ function: {
176
+ name: string;
177
+ arguments: string;
178
+ };
179
+ }
180
+ /**
181
+ * Tool definition for the Moonshot API.
182
+ * Used for both custom function tools and server-side builtin tools.
183
+ */
184
+ interface MoonshotTool {
185
+ type: 'function';
186
+ function: {
187
+ name: string;
188
+ description: string;
189
+ parameters: {
190
+ type?: 'object';
191
+ description?: string;
192
+ properties: Record<string, unknown>;
193
+ required?: string[];
194
+ additionalProperties?: boolean;
195
+ };
196
+ strict?: boolean;
197
+ };
198
+ }
199
+ /**
200
+ * Tool choice options for controlling function calling behavior.
201
+ * Moonshot models support full tool_choice including 'required'.
202
+ */
203
+ type MoonshotToolChoice = 'none' | 'auto' | 'required' | {
204
+ type: 'function';
205
+ function: {
206
+ name: string;
207
+ };
208
+ };
209
+ /**
210
+ * Creates a web search tool (server-side execution).
211
+ * Enables real-time internet search capabilities.
212
+ *
213
+ * Note: Web search is charged separately from regular API usage.
214
+ *
215
+ * @example
216
+ * ```typescript
217
+ * import { moonshot, tools } from '@providerprotocol/ai/moonshot';
218
+ *
219
+ * const model = llm({
220
+ * model: moonshot('kimi-k2.5'),
221
+ * params: {
222
+ * tools: [tools.webSearch()],
223
+ * },
224
+ * });
225
+ * ```
226
+ */
227
+ declare function webSearch(): MoonshotTool;
228
+ /**
229
+ * Creates a Python code runner tool (server-side execution).
230
+ * Allows execution of Python code for calculations and data processing.
231
+ * Supports print output, matplotlib plots, pandas, and file reading via ctx.read_object().
232
+ */
233
+ declare function codeRunner(): MoonshotTool;
234
+ /**
235
+ * Creates a QuickJS JavaScript execution tool (server-side execution).
236
+ * Enables secure JavaScript code execution via the QuickJS engine.
237
+ */
238
+ declare function quickjs(): MoonshotTool;
239
+ /**
240
+ * Creates a URL fetch tool (server-side execution).
241
+ * Extracts content from URLs and formats it as Markdown.
242
+ */
243
+ declare function fetch(): MoonshotTool;
244
+ /**
245
+ * Creates a unit conversion tool (server-side execution).
246
+ * Supports length, mass, volume, temperature, area, time, energy,
247
+ * pressure, speed, and currency conversions.
248
+ */
249
+ declare function convert(): MoonshotTool;
250
+ /**
251
+ * Creates a date/time processing tool (server-side execution).
252
+ * Handles date and time calculations, timezone conversion, and formatting.
253
+ */
254
+ declare function date(): MoonshotTool;
255
+ /**
256
+ * Creates a Base64 encoding tool (server-side execution).
257
+ */
258
+ declare function base64Encode(): MoonshotTool;
259
+ /**
260
+ * Creates a Base64 decoding tool (server-side execution).
261
+ */
262
+ declare function base64Decode(): MoonshotTool;
263
+ /**
264
+ * Creates a memory storage tool (server-side execution).
265
+ * Supports persistent storage of conversation history and user preferences.
266
+ */
267
+ declare function memory(): MoonshotTool;
268
+ /**
269
+ * Creates an intelligent reasoning tool (server-side execution).
270
+ * Allows the model to organize thoughts and plan before responding.
271
+ */
272
+ declare function rethink(): MoonshotTool;
273
+ /**
274
+ * Creates a random choice tool (server-side execution).
275
+ * Enables random selection from options with optional weights.
276
+ */
277
+ declare function randomChoice(): MoonshotTool;
278
+ /**
279
+ * Creates a cat meowing/blessing tool (server-side execution).
280
+ * Returns random cat meowing sounds and blessings based on mood.
281
+ */
282
+ declare function mew(): MoonshotTool;
283
+ /**
284
+ * Moonshot builtin tools factory object.
285
+ * Provides convenient access to all builtin tool creators.
286
+ *
287
+ * Note: The `excel` plugin tool uses a different format and is not included here.
288
+ * It requires file IDs from the Moonshot file upload API.
289
+ *
290
+ * @example
291
+ * ```typescript
292
+ * import { moonshot, tools } from '@providerprotocol/ai/moonshot';
293
+ *
294
+ * const model = llm({
295
+ * model: moonshot('kimi-k2.5'),
296
+ * params: {
297
+ * tools: [
298
+ * tools.webSearch(),
299
+ * tools.codeRunner(),
300
+ * tools.fetch(),
301
+ * ],
302
+ * },
303
+ * });
304
+ * ```
305
+ */
306
+ declare const tools: {
307
+ /** Web search for real-time internet information */
308
+ webSearch: typeof webSearch;
309
+ /** Python code execution with matplotlib, pandas support */
310
+ codeRunner: typeof codeRunner;
311
+ /** JavaScript execution via QuickJS engine */
312
+ quickjs: typeof quickjs;
313
+ /** URL content fetching with markdown extraction */
314
+ fetch: typeof fetch;
315
+ /** Unit conversion (length, mass, temperature, currency, etc.) */
316
+ convert: typeof convert;
317
+ /** Date/time processing and timezone conversion */
318
+ date: typeof date;
319
+ /** Base64 encoding */
320
+ base64Encode: typeof base64Encode;
321
+ /** Base64 decoding */
322
+ base64Decode: typeof base64Decode;
323
+ /** Alias for base64Encode */
324
+ base64: typeof base64Encode;
325
+ /** Memory storage and retrieval system */
326
+ memory: typeof memory;
327
+ /** Intelligent reasoning/reflection tool */
328
+ rethink: typeof rethink;
329
+ /** Random selection with optional weights */
330
+ randomChoice: typeof randomChoice;
331
+ /** Cat meowing and blessings generator */
332
+ mew: typeof mew;
333
+ };
334
+ /**
335
+ * Response structure from the Moonshot Chat Completions API.
336
+ */
337
+ interface MoonshotResponse {
338
+ id: string;
339
+ object: 'chat.completion';
340
+ created: number;
341
+ model: string;
342
+ choices: MoonshotChoice[];
343
+ usage: MoonshotUsage;
344
+ system_fingerprint?: string;
345
+ }
346
+ /** A single choice from a completion response */
347
+ interface MoonshotChoice {
348
+ index: number;
349
+ message: MoonshotAssistantMessage;
350
+ finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | null;
351
+ }
352
+ /** Token usage statistics from the API response */
353
+ interface MoonshotUsage {
354
+ prompt_tokens: number;
355
+ completion_tokens: number;
356
+ total_tokens: number;
357
+ prompt_tokens_details?: {
358
+ cached_tokens?: number;
359
+ };
360
+ }
361
+ /**
362
+ * Streaming chunk structure from the Moonshot API.
363
+ */
364
+ interface MoonshotStreamChunk {
365
+ id: string;
366
+ object: 'chat.completion.chunk';
367
+ created: number;
368
+ model: string;
369
+ choices: MoonshotStreamChoice[];
370
+ usage?: MoonshotUsage | null;
371
+ system_fingerprint?: string;
372
+ }
373
+ /** A streaming choice containing incremental content */
374
+ interface MoonshotStreamChoice {
375
+ index: number;
376
+ delta: MoonshotStreamDelta;
377
+ finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | null;
378
+ }
379
+ /** Incremental content delta in a streaming chunk */
380
+ interface MoonshotStreamDelta {
381
+ role?: 'assistant';
382
+ content?: string | null;
383
+ reasoning_content?: string | null;
384
+ tool_calls?: MoonshotStreamToolCall[];
385
+ }
386
+ /** Incremental tool call data in a streaming chunk */
387
+ interface MoonshotStreamToolCall {
388
+ index: number;
389
+ id?: string;
390
+ type?: 'function';
391
+ function?: {
392
+ name?: string;
393
+ arguments?: string;
394
+ };
395
+ }
396
+ /**
397
+ * Moonshot-specific HTTP headers for API requests.
398
+ *
399
+ * @example
400
+ * ```typescript
401
+ * const headers: MoonshotHeaders = {
402
+ * 'X-Request-Id': 'my-request-id',
403
+ * };
404
+ * ```
405
+ */
406
+ interface MoonshotHeaders {
407
+ /** Client-generated request ID for tracing */
408
+ 'X-Request-Id'?: string;
409
+ [key: string]: string | undefined;
410
+ }
411
+
412
+ /**
413
+ * @fileoverview Moonshot Provider Factory
414
+ *
415
+ * This module provides the main Moonshot provider implementation for the
416
+ * OpenAI-compatible Chat Completions API.
417
+ *
418
+ * @module providers/moonshot
419
+ */
420
+ /**
421
+ * Configuration options for the Moonshot provider.
422
+ *
423
+ * Currently Moonshot only supports one API endpoint (Chat Completions),
424
+ * so no additional options are needed.
425
+ */
426
+ interface MoonshotProviderOptions {
427
+ }
428
+ /**
429
+ * The Moonshot provider instance.
430
+ *
431
+ * Use this provider to create model references for Moonshot models like
432
+ * Kimi K2.5 and other models available on the Moonshot AI platform.
433
+ *
434
+ * @example Basic usage
435
+ * ```typescript
436
+ * import { moonshot } from './providers/moonshot';
437
+ * import { llm } from './core/llm';
438
+ *
439
+ * const model = llm({
440
+ * model: moonshot('kimi-k2.5'),
441
+ * params: { max_tokens: 1000 }
442
+ * });
443
+ *
444
+ * const turn = await model.generate('Hello!');
445
+ * console.log(turn.response.text);
446
+ * ```
447
+ *
448
+ * @example With streaming
449
+ * ```typescript
450
+ * const stream = model.stream('Tell me a story');
451
+ *
452
+ * for await (const event of stream) {
453
+ * if (event.type === StreamEventType.TextDelta) {
454
+ * process.stdout.write(event.delta.text ?? '');
455
+ * }
456
+ * }
457
+ *
458
+ * const turn = await stream.turn;
459
+ * console.log('Tokens used:', turn.usage.totalTokens);
460
+ * ```
461
+ *
462
+ * @example With thinking mode (default for K2.5)
463
+ * ```typescript
464
+ * const model = llm({
465
+ * model: moonshot('kimi-k2.5'),
466
+ * params: {
467
+ * max_tokens: 2000,
468
+ * temperature: 1.0, // Recommended for thinking mode
469
+ * thinking: { type: 'enabled' } // Default
470
+ * }
471
+ * });
472
+ *
473
+ * // Response includes reasoning_content in metadata
474
+ * const turn = await model.generate('Solve this step by step: 2x + 5 = 13');
475
+ * ```
476
+ *
477
+ * @example With instant mode (disabled thinking)
478
+ * ```typescript
479
+ * const model = llm({
480
+ * model: moonshot('kimi-k2.5'),
481
+ * params: {
482
+ * max_tokens: 1000,
483
+ * temperature: 0.6, // Recommended for instant mode
484
+ * thinking: { type: 'disabled' }
485
+ * }
486
+ * });
487
+ * ```
488
+ *
489
+ * @example With vision (image input)
490
+ * ```typescript
491
+ * import { Image } from './core/media/Image';
492
+ *
493
+ * const image = await Image.fromPath('./photo.png');
494
+ * const turn = await model.generate([
495
+ * image.toBlock(),
496
+ * { type: 'text', text: 'Describe this image' }
497
+ * ]);
498
+ * ```
499
+ *
500
+ * @example Available models
501
+ * Production models:
502
+ * - `kimi-k2.5` - Latest K2.5 with 256K context, vision, thinking mode
503
+ *
504
+ * Environment variables:
505
+ * - `MOONSHOT_API_KEY` - Primary API key
506
+ * - `KIMI_API_KEY` - Fallback API key
507
+ */
508
+ declare const moonshot: Provider<MoonshotProviderOptions>;
509
+
510
+ export { type MoonshotHeaders, type MoonshotLLMParams, type MoonshotMessage, type MoonshotProviderOptions, type MoonshotRequest, type MoonshotResponse, type MoonshotResponseFormat, type MoonshotStreamChunk, type MoonshotThinkingConfig, type MoonshotTool, type MoonshotToolCall, type MoonshotToolChoice, type MoonshotUsage, moonshot, tools };