@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
package/src/core/image.ts DELETED
@@ -1,188 +0,0 @@
1
- import type { ImageSource, ImageBlock } from '../types/content.ts';
2
-
3
- /**
4
- * Image class for handling images in UPP
5
- */
6
- export class Image {
7
- readonly source: ImageSource;
8
- readonly mimeType: string;
9
- readonly width?: number;
10
- readonly height?: number;
11
-
12
- private constructor(
13
- source: ImageSource,
14
- mimeType: string,
15
- width?: number,
16
- height?: number
17
- ) {
18
- this.source = source;
19
- this.mimeType = mimeType;
20
- this.width = width;
21
- this.height = height;
22
- }
23
-
24
- /**
25
- * Check if this image has data loaded (false for URL sources)
26
- */
27
- get hasData(): boolean {
28
- return this.source.type !== 'url';
29
- }
30
-
31
- /**
32
- * Convert to base64 string (throws if source is URL)
33
- */
34
- toBase64(): string {
35
- if (this.source.type === 'base64') {
36
- return this.source.data;
37
- }
38
-
39
- if (this.source.type === 'bytes') {
40
- return btoa(
41
- Array.from(this.source.data)
42
- .map((b) => String.fromCharCode(b))
43
- .join('')
44
- );
45
- }
46
-
47
- throw new Error('Cannot convert URL image to base64. Fetch the image first.');
48
- }
49
-
50
- /**
51
- * Convert to data URL (throws if source is URL)
52
- */
53
- toDataUrl(): string {
54
- const base64 = this.toBase64();
55
- return `data:${this.mimeType};base64,${base64}`;
56
- }
57
-
58
- /**
59
- * Get raw bytes (throws if source is URL)
60
- */
61
- toBytes(): Uint8Array {
62
- if (this.source.type === 'bytes') {
63
- return this.source.data;
64
- }
65
-
66
- if (this.source.type === 'base64') {
67
- const binaryString = atob(this.source.data);
68
- const bytes = new Uint8Array(binaryString.length);
69
- for (let i = 0; i < binaryString.length; i++) {
70
- bytes[i] = binaryString.charCodeAt(i);
71
- }
72
- return bytes;
73
- }
74
-
75
- throw new Error('Cannot get bytes from URL image. Fetch the image first.');
76
- }
77
-
78
- /**
79
- * Get the URL (only for URL sources)
80
- */
81
- toUrl(): string {
82
- if (this.source.type === 'url') {
83
- return this.source.url;
84
- }
85
-
86
- throw new Error('This image does not have a URL source.');
87
- }
88
-
89
- /**
90
- * Convert to ImageBlock for use in messages
91
- */
92
- toBlock(): ImageBlock {
93
- return {
94
- type: 'image',
95
- source: this.source,
96
- mimeType: this.mimeType,
97
- width: this.width,
98
- height: this.height,
99
- };
100
- }
101
-
102
- /**
103
- * Create from file path (reads file into memory)
104
- */
105
- static async fromPath(path: string): Promise<Image> {
106
- const file = Bun.file(path);
107
- const data = await file.arrayBuffer();
108
- const mimeType = file.type || detectMimeType(path);
109
-
110
- return new Image(
111
- { type: 'bytes', data: new Uint8Array(data) },
112
- mimeType
113
- );
114
- }
115
-
116
- /**
117
- * Create from URL reference (does not fetch - providers handle URL conversion)
118
- */
119
- static fromUrl(url: string, mimeType?: string): Image {
120
- const detected = mimeType || detectMimeTypeFromUrl(url);
121
- return new Image({ type: 'url', url }, detected);
122
- }
123
-
124
- /**
125
- * Create from raw bytes
126
- */
127
- static fromBytes(data: Uint8Array, mimeType: string): Image {
128
- return new Image({ type: 'bytes', data }, mimeType);
129
- }
130
-
131
- /**
132
- * Create from base64 string
133
- */
134
- static fromBase64(base64: string, mimeType: string): Image {
135
- return new Image({ type: 'base64', data: base64 }, mimeType);
136
- }
137
-
138
- /**
139
- * Create from an existing ImageBlock
140
- */
141
- static fromBlock(block: ImageBlock): Image {
142
- return new Image(
143
- block.source,
144
- block.mimeType,
145
- block.width,
146
- block.height
147
- );
148
- }
149
- }
150
-
151
- /**
152
- * Detect MIME type from file extension
153
- */
154
- function detectMimeType(path: string): string {
155
- const ext = path.split('.').pop()?.toLowerCase();
156
-
157
- switch (ext) {
158
- case 'jpg':
159
- case 'jpeg':
160
- return 'image/jpeg';
161
- case 'png':
162
- return 'image/png';
163
- case 'gif':
164
- return 'image/gif';
165
- case 'webp':
166
- return 'image/webp';
167
- case 'svg':
168
- return 'image/svg+xml';
169
- case 'bmp':
170
- return 'image/bmp';
171
- case 'ico':
172
- return 'image/x-icon';
173
- default:
174
- return 'application/octet-stream';
175
- }
176
- }
177
-
178
- /**
179
- * Detect MIME type from URL
180
- */
181
- function detectMimeTypeFromUrl(url: string): string {
182
- try {
183
- const pathname = new URL(url).pathname;
184
- return detectMimeType(pathname);
185
- } catch {
186
- return 'application/octet-stream';
187
- }
188
- }