@providerprotocol/ai 0.0.11 → 0.0.13

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 (104) hide show
  1. package/dist/anthropic/index.d.ts +51 -15
  2. package/dist/anthropic/index.js +54 -19
  3. package/dist/anthropic/index.js.map +1 -1
  4. package/dist/{chunk-SUNYWHTH.js → chunk-MOU4U3PO.js} +55 -3
  5. package/dist/chunk-MOU4U3PO.js.map +1 -0
  6. package/dist/{chunk-Y6Q7JCNP.js → chunk-MSR5P65T.js} +1 -1
  7. package/dist/chunk-MSR5P65T.js.map +1 -0
  8. package/dist/{chunk-W4BB4BG2.js → chunk-SVYROCLD.js} +31 -11
  9. package/dist/chunk-SVYROCLD.js.map +1 -0
  10. package/dist/chunk-U4JJC2YX.js +234 -0
  11. package/dist/chunk-U4JJC2YX.js.map +1 -0
  12. package/dist/{chunk-X5G4EHL7.js → chunk-Z7RBRCRN.js} +1 -1
  13. package/dist/chunk-Z7RBRCRN.js.map +1 -0
  14. package/dist/google/index.d.ts +376 -7
  15. package/dist/google/index.js +127 -15
  16. package/dist/google/index.js.map +1 -1
  17. package/dist/http/index.d.ts +222 -25
  18. package/dist/http/index.js +3 -3
  19. package/dist/index.d.ts +1482 -198
  20. package/dist/index.js +233 -49
  21. package/dist/index.js.map +1 -1
  22. package/dist/ollama/index.d.ts +92 -20
  23. package/dist/ollama/index.js +17 -7
  24. package/dist/ollama/index.js.map +1 -1
  25. package/dist/openai/index.d.ts +340 -61
  26. package/dist/openai/index.js +57 -15
  27. package/dist/openai/index.js.map +1 -1
  28. package/dist/openrouter/index.d.ts +107 -51
  29. package/dist/openrouter/index.js +36 -8
  30. package/dist/openrouter/index.js.map +1 -1
  31. package/dist/provider-mKkz7Q9U.d.ts +488 -0
  32. package/dist/retry-Dh70lgr0.d.ts +508 -0
  33. package/dist/xai/index.d.ts +97 -22
  34. package/dist/xai/index.js +55 -19
  35. package/dist/xai/index.js.map +1 -1
  36. package/package.json +8 -12
  37. package/dist/chunk-CUCRF5W6.js +0 -136
  38. package/dist/chunk-CUCRF5W6.js.map +0 -1
  39. package/dist/chunk-SUNYWHTH.js.map +0 -1
  40. package/dist/chunk-W4BB4BG2.js.map +0 -1
  41. package/dist/chunk-X5G4EHL7.js.map +0 -1
  42. package/dist/chunk-Y6Q7JCNP.js.map +0 -1
  43. package/dist/provider-CUJWjgNl.d.ts +0 -192
  44. package/dist/retry-I2661_rv.d.ts +0 -118
  45. package/src/anthropic/index.ts +0 -3
  46. package/src/core/image.ts +0 -188
  47. package/src/core/llm.ts +0 -650
  48. package/src/core/provider.ts +0 -92
  49. package/src/google/index.ts +0 -3
  50. package/src/http/errors.ts +0 -112
  51. package/src/http/fetch.ts +0 -210
  52. package/src/http/index.ts +0 -31
  53. package/src/http/keys.ts +0 -136
  54. package/src/http/retry.ts +0 -205
  55. package/src/http/sse.ts +0 -136
  56. package/src/index.ts +0 -32
  57. package/src/ollama/index.ts +0 -3
  58. package/src/openai/index.ts +0 -39
  59. package/src/openrouter/index.ts +0 -11
  60. package/src/providers/anthropic/index.ts +0 -17
  61. package/src/providers/anthropic/llm.ts +0 -196
  62. package/src/providers/anthropic/transform.ts +0 -434
  63. package/src/providers/anthropic/types.ts +0 -213
  64. package/src/providers/google/index.ts +0 -17
  65. package/src/providers/google/llm.ts +0 -203
  66. package/src/providers/google/transform.ts +0 -447
  67. package/src/providers/google/types.ts +0 -214
  68. package/src/providers/ollama/index.ts +0 -43
  69. package/src/providers/ollama/llm.ts +0 -272
  70. package/src/providers/ollama/transform.ts +0 -434
  71. package/src/providers/ollama/types.ts +0 -260
  72. package/src/providers/openai/index.ts +0 -186
  73. package/src/providers/openai/llm.completions.ts +0 -201
  74. package/src/providers/openai/llm.responses.ts +0 -211
  75. package/src/providers/openai/transform.completions.ts +0 -561
  76. package/src/providers/openai/transform.responses.ts +0 -708
  77. package/src/providers/openai/types.ts +0 -1249
  78. package/src/providers/openrouter/index.ts +0 -177
  79. package/src/providers/openrouter/llm.completions.ts +0 -201
  80. package/src/providers/openrouter/llm.responses.ts +0 -211
  81. package/src/providers/openrouter/transform.completions.ts +0 -538
  82. package/src/providers/openrouter/transform.responses.ts +0 -742
  83. package/src/providers/openrouter/types.ts +0 -717
  84. package/src/providers/xai/index.ts +0 -223
  85. package/src/providers/xai/llm.completions.ts +0 -201
  86. package/src/providers/xai/llm.messages.ts +0 -195
  87. package/src/providers/xai/llm.responses.ts +0 -211
  88. package/src/providers/xai/transform.completions.ts +0 -565
  89. package/src/providers/xai/transform.messages.ts +0 -448
  90. package/src/providers/xai/transform.responses.ts +0 -678
  91. package/src/providers/xai/types.ts +0 -938
  92. package/src/types/content.ts +0 -133
  93. package/src/types/errors.ts +0 -85
  94. package/src/types/index.ts +0 -105
  95. package/src/types/llm.ts +0 -211
  96. package/src/types/messages.ts +0 -205
  97. package/src/types/provider.ts +0 -195
  98. package/src/types/schema.ts +0 -58
  99. package/src/types/stream.ts +0 -188
  100. package/src/types/thread.ts +0 -226
  101. package/src/types/tool.ts +0 -88
  102. package/src/types/turn.ts +0 -118
  103. package/src/utils/id.ts +0 -28
  104. package/src/xai/index.ts +0 -41
@@ -1,133 +0,0 @@
1
- /**
2
- * Content block types for messages
3
- */
4
-
5
- /**
6
- * Image source types
7
- */
8
- export type ImageSource =
9
- | { type: 'base64'; data: string }
10
- | { type: 'url'; url: string }
11
- | { type: 'bytes'; data: Uint8Array };
12
-
13
- /**
14
- * Text content block
15
- */
16
- export interface TextBlock {
17
- type: 'text';
18
- text: string;
19
- }
20
-
21
- /**
22
- * Image content block
23
- */
24
- export interface ImageBlock {
25
- type: 'image';
26
- source: ImageSource;
27
- mimeType: string;
28
- width?: number;
29
- height?: number;
30
- }
31
-
32
- /**
33
- * Audio content block
34
- */
35
- export interface AudioBlock {
36
- type: 'audio';
37
- data: Uint8Array;
38
- mimeType: string;
39
- duration?: number;
40
- }
41
-
42
- /**
43
- * Video content block
44
- */
45
- export interface VideoBlock {
46
- type: 'video';
47
- data: Uint8Array;
48
- mimeType: string;
49
- duration?: number;
50
- width?: number;
51
- height?: number;
52
- }
53
-
54
- /**
55
- * Binary content block for arbitrary data
56
- */
57
- export interface BinaryBlock {
58
- type: 'binary';
59
- data: Uint8Array;
60
- mimeType: string;
61
- metadata?: Record<string, unknown>;
62
- }
63
-
64
- /**
65
- * All content block types
66
- */
67
- export type ContentBlock =
68
- | TextBlock
69
- | ImageBlock
70
- | AudioBlock
71
- | VideoBlock
72
- | BinaryBlock;
73
-
74
- /**
75
- * Content types allowed in user messages
76
- */
77
- export type UserContent =
78
- | TextBlock
79
- | ImageBlock
80
- | AudioBlock
81
- | VideoBlock
82
- | BinaryBlock;
83
-
84
- /**
85
- * Content types allowed in assistant messages
86
- */
87
- export type AssistantContent =
88
- | TextBlock
89
- | ImageBlock
90
- | AudioBlock
91
- | VideoBlock;
92
-
93
- /**
94
- * Helper to create a text block
95
- */
96
- export function text(content: string): TextBlock {
97
- return { type: 'text', text: content };
98
- }
99
-
100
- /**
101
- * Type guard for TextBlock
102
- */
103
- export function isTextBlock(block: ContentBlock): block is TextBlock {
104
- return block.type === 'text';
105
- }
106
-
107
- /**
108
- * Type guard for ImageBlock
109
- */
110
- export function isImageBlock(block: ContentBlock): block is ImageBlock {
111
- return block.type === 'image';
112
- }
113
-
114
- /**
115
- * Type guard for AudioBlock
116
- */
117
- export function isAudioBlock(block: ContentBlock): block is AudioBlock {
118
- return block.type === 'audio';
119
- }
120
-
121
- /**
122
- * Type guard for VideoBlock
123
- */
124
- export function isVideoBlock(block: ContentBlock): block is VideoBlock {
125
- return block.type === 'video';
126
- }
127
-
128
- /**
129
- * Type guard for BinaryBlock
130
- */
131
- export function isBinaryBlock(block: ContentBlock): block is BinaryBlock {
132
- return block.type === 'binary';
133
- }
@@ -1,85 +0,0 @@
1
- /**
2
- * UPP Error Codes
3
- * Normalized error codes for cross-provider error handling
4
- */
5
- export type ErrorCode =
6
- | 'AUTHENTICATION_FAILED'
7
- | 'RATE_LIMITED'
8
- | 'CONTEXT_LENGTH_EXCEEDED'
9
- | 'MODEL_NOT_FOUND'
10
- | 'INVALID_REQUEST'
11
- | 'INVALID_RESPONSE'
12
- | 'CONTENT_FILTERED'
13
- | 'QUOTA_EXCEEDED'
14
- | 'PROVIDER_ERROR'
15
- | 'NETWORK_ERROR'
16
- | 'TIMEOUT'
17
- | 'CANCELLED';
18
-
19
- /**
20
- * Modality types supported by UPP
21
- */
22
- export type Modality = 'llm' | 'embedding' | 'image' | 'audio' | 'video';
23
-
24
- /**
25
- * Unified Provider Protocol Error
26
- * All provider errors are normalized to this type
27
- */
28
- export class UPPError extends Error {
29
- readonly code: ErrorCode;
30
- readonly provider: string;
31
- readonly modality: Modality;
32
- readonly statusCode?: number;
33
- override readonly cause?: Error;
34
-
35
- override readonly name = 'UPPError';
36
-
37
- constructor(
38
- message: string,
39
- code: ErrorCode,
40
- provider: string,
41
- modality: Modality,
42
- statusCode?: number,
43
- cause?: Error
44
- ) {
45
- super(message);
46
- this.code = code;
47
- this.provider = provider;
48
- this.modality = modality;
49
- this.statusCode = statusCode;
50
- this.cause = cause;
51
-
52
- // Maintain proper stack trace in V8 environments
53
- if (Error.captureStackTrace) {
54
- Error.captureStackTrace(this, UPPError);
55
- }
56
- }
57
-
58
- /**
59
- * Create a string representation of the error
60
- */
61
- override toString(): string {
62
- let str = `UPPError [${this.code}]: ${this.message}`;
63
- str += ` (provider: ${this.provider}, modality: ${this.modality}`;
64
- if (this.statusCode) {
65
- str += `, status: ${this.statusCode}`;
66
- }
67
- str += ')';
68
- return str;
69
- }
70
-
71
- /**
72
- * Convert to JSON for serialization
73
- */
74
- toJSON(): Record<string, unknown> {
75
- return {
76
- name: this.name,
77
- message: this.message,
78
- code: this.code,
79
- provider: this.provider,
80
- modality: this.modality,
81
- statusCode: this.statusCode,
82
- cause: this.cause?.message,
83
- };
84
- }
85
- }
@@ -1,105 +0,0 @@
1
- // Error types
2
- export { UPPError, type ErrorCode, type Modality } from './errors.ts';
3
-
4
- // Schema types
5
- export type {
6
- JSONSchema,
7
- JSONSchemaProperty,
8
- JSONSchemaPropertyType,
9
- } from './schema.ts';
10
-
11
- // Content block types
12
- export type {
13
- ContentBlock,
14
- TextBlock,
15
- ImageBlock,
16
- AudioBlock,
17
- VideoBlock,
18
- BinaryBlock,
19
- ImageSource,
20
- UserContent,
21
- AssistantContent,
22
- } from './content.ts';
23
- export {
24
- text,
25
- isTextBlock,
26
- isImageBlock,
27
- isAudioBlock,
28
- isVideoBlock,
29
- isBinaryBlock,
30
- } from './content.ts';
31
-
32
- // Tool types
33
- export type {
34
- Tool,
35
- ToolCall,
36
- ToolResult,
37
- ToolUseStrategy,
38
- ToolExecution,
39
- } from './tool.ts';
40
-
41
- // Message types
42
- export {
43
- Message,
44
- UserMessage,
45
- AssistantMessage,
46
- ToolResultMessage,
47
- isUserMessage,
48
- isAssistantMessage,
49
- isToolResultMessage,
50
- } from './messages.ts';
51
- export type { MessageType, MessageMetadata, MessageOptions } from './messages.ts';
52
-
53
- // Turn types
54
- export type { Turn, TokenUsage } from './turn.ts';
55
- export { createTurn, emptyUsage, aggregateUsage } from './turn.ts';
56
-
57
- // Thread types
58
- export { Thread } from './thread.ts';
59
- export type { ThreadJSON, MessageJSON } from './thread.ts';
60
-
61
- // Stream types
62
- export type {
63
- StreamEvent,
64
- StreamEventType,
65
- EventDelta,
66
- StreamResult,
67
- } from './stream.ts';
68
- export {
69
- createStreamResult,
70
- textDelta,
71
- toolCallDelta,
72
- messageStart,
73
- messageStop,
74
- contentBlockStart,
75
- contentBlockStop,
76
- } from './stream.ts';
77
-
78
- // Provider types
79
- export type {
80
- Provider,
81
- ModelReference,
82
- ProviderConfig,
83
- KeyStrategy,
84
- RetryStrategy,
85
- LLMProvider,
86
- EmbeddingProvider,
87
- ImageProvider,
88
- EmbeddingHandler,
89
- ImageHandler,
90
- BoundEmbeddingModel,
91
- BoundImageModel,
92
- } from './provider.ts';
93
-
94
- // LLM types
95
- export type {
96
- LLMOptions,
97
- LLMInstance,
98
- LLMCapabilities,
99
- LLMRequest,
100
- LLMResponse,
101
- LLMStreamResult,
102
- BoundLLMModel,
103
- LLMHandler,
104
- InferenceInput,
105
- } from './llm.ts';
package/src/types/llm.ts DELETED
@@ -1,211 +0,0 @@
1
- import type { Message, AssistantMessage } from './messages.ts';
2
- import type { ContentBlock } from './content.ts';
3
- import type { Tool, ToolUseStrategy } from './tool.ts';
4
- import type { JSONSchema } from './schema.ts';
5
- import type { Turn, TokenUsage } from './turn.ts';
6
- import type { StreamEvent, StreamResult } from './stream.ts';
7
- import type {
8
- ModelReference,
9
- ProviderConfig,
10
- LLMProvider,
11
- } from './provider.ts';
12
- import type { Thread } from './thread.ts';
13
-
14
- /**
15
- * LLMCapabilities declares what the provider's API supports, not individual model capabilities.
16
- * If a user attempts to use a feature with a model that doesn't support it,
17
- * the provider's API will return an error—this is expected behavior.
18
- *
19
- * Capabilities are static - they are constant for the lifetime of the provider instance
20
- * and do not vary per-request or per-model.
21
- */
22
- export interface LLMCapabilities {
23
- /** Provider API supports streaming responses */
24
- streaming: boolean;
25
-
26
- /** Provider API supports tool/function calling */
27
- tools: boolean;
28
-
29
- /** Provider API supports native structured output (JSON schema) */
30
- structuredOutput: boolean;
31
-
32
- /** Provider API supports image input */
33
- imageInput: boolean;
34
-
35
- /** Provider API supports video input */
36
- videoInput: boolean;
37
-
38
- /** Provider API supports audio input */
39
- audioInput: boolean;
40
- }
41
-
42
- /**
43
- * Input types for inference
44
- */
45
- export type InferenceInput = string | Message | ContentBlock;
46
-
47
- /**
48
- * Options for llm() function
49
- */
50
- export interface LLMOptions<TParams = unknown> {
51
- /** A model reference from a provider factory */
52
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
53
- model: ModelReference<any>;
54
-
55
- /** Provider infrastructure configuration (optional - uses env vars if omitted) */
56
- config?: ProviderConfig;
57
-
58
- /** Model-specific parameters (temperature, max_tokens, etc.) */
59
- params?: TParams;
60
-
61
- /** System prompt for all inferences */
62
- system?: string;
63
-
64
- /** Tools available to the model */
65
- tools?: Tool[];
66
-
67
- /** Tool execution strategy */
68
- toolStrategy?: ToolUseStrategy;
69
-
70
- /** Structured output schema (JSON Schema) */
71
- structure?: JSONSchema;
72
- }
73
-
74
- /**
75
- * LLM instance returned by llm()
76
- */
77
- export interface LLMInstance<TParams = unknown> {
78
- /**
79
- * Execute inference and return complete Turn
80
- *
81
- * @overload No history - single input
82
- * generate(input: InferenceInput): Promise<Turn>
83
- *
84
- * @overload No history - multiple inputs
85
- * generate(...inputs: InferenceInput[]): Promise<Turn>
86
- *
87
- * @overload With history
88
- * generate(history: Message[] | Thread, ...inputs: InferenceInput[]): Promise<Turn>
89
- */
90
- generate(
91
- historyOrInput: Message[] | Thread | InferenceInput,
92
- ...input: InferenceInput[]
93
- ): Promise<Turn>;
94
-
95
- /**
96
- * Execute streaming inference
97
- *
98
- * @overload No history - single input
99
- * stream(input: InferenceInput): StreamResult
100
- *
101
- * @overload No history - multiple inputs
102
- * stream(...inputs: InferenceInput[]): StreamResult
103
- *
104
- * @overload With history
105
- * stream(history: Message[] | Thread, ...inputs: InferenceInput[]): StreamResult
106
- */
107
- stream(
108
- historyOrInput: Message[] | Thread | InferenceInput,
109
- ...input: InferenceInput[]
110
- ): StreamResult;
111
-
112
- /** The bound model */
113
- readonly model: BoundLLMModel<TParams>;
114
-
115
- /** Current system prompt */
116
- readonly system: string | undefined;
117
-
118
- /** Current parameters */
119
- readonly params: TParams | undefined;
120
-
121
- /** Provider API capabilities */
122
- readonly capabilities: LLMCapabilities;
123
- }
124
-
125
- /**
126
- * Request passed from llm() core to providers
127
- * Note: config is required here because llm() core resolves defaults
128
- * before passing to providers
129
- */
130
- export interface LLMRequest<TParams = unknown> {
131
- /** All messages for this request (history + new input) */
132
- messages: Message[];
133
-
134
- /** System prompt */
135
- system?: string;
136
-
137
- /** Model-specific parameters (passed through unchanged) */
138
- params?: TParams;
139
-
140
- /** Tools available for this request */
141
- tools?: Tool[];
142
-
143
- /** Structured output schema (if requested) */
144
- structure?: JSONSchema;
145
-
146
- /** Provider infrastructure config (resolved by llm() core) */
147
- config: ProviderConfig;
148
-
149
- /** Abort signal for cancellation */
150
- signal?: AbortSignal;
151
- }
152
-
153
- /**
154
- * Raw provider response (single cycle, no tool loop)
155
- */
156
- export interface LLMResponse {
157
- message: AssistantMessage;
158
- usage: TokenUsage;
159
- stopReason: string;
160
-
161
- /**
162
- * Structured output data extracted by the provider.
163
- * Present when a structure schema was requested and the provider
164
- * successfully extracted the data (via tool call or native JSON mode).
165
- * Providers handle their own extraction logic - core just uses this value.
166
- */
167
- data?: unknown;
168
- }
169
-
170
- /**
171
- * Raw provider stream result
172
- */
173
- export interface LLMStreamResult extends AsyncIterable<StreamEvent> {
174
- readonly response: Promise<LLMResponse>;
175
- }
176
-
177
- /**
178
- * Bound LLM model - full definition
179
- */
180
- export interface BoundLLMModel<TParams = unknown> {
181
- /** The model identifier */
182
- readonly modelId: string;
183
-
184
- /** Reference to the parent provider */
185
- readonly provider: LLMProvider<TParams>;
186
-
187
- /** Provider API capabilities */
188
- readonly capabilities: LLMCapabilities;
189
-
190
- /** Execute a single non-streaming inference request */
191
- complete(request: LLMRequest<TParams>): Promise<LLMResponse>;
192
-
193
- /** Execute a single streaming inference request */
194
- stream(request: LLMRequest<TParams>): LLMStreamResult;
195
- }
196
-
197
- /**
198
- * LLM Handler for providers
199
- */
200
- export interface LLMHandler<TParams = unknown> {
201
- /** Bind model ID to create executable model */
202
- bind(modelId: string): BoundLLMModel<TParams>;
203
-
204
- /**
205
- * Internal: Set the parent provider reference.
206
- * Called by createProvider() after the provider is constructed.
207
- * This allows bind() to return models with the correct provider reference.
208
- * @internal
209
- */
210
- _setProvider?(provider: LLMProvider<TParams>): void;
211
- }