@providerprotocol/ai 0.0.11 → 0.0.12

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 (63) hide show
  1. package/dist/index.js +3 -3
  2. package/dist/index.js.map +1 -1
  3. package/package.json +1 -10
  4. package/src/anthropic/index.ts +0 -3
  5. package/src/core/image.ts +0 -188
  6. package/src/core/llm.ts +0 -650
  7. package/src/core/provider.ts +0 -92
  8. package/src/google/index.ts +0 -3
  9. package/src/http/errors.ts +0 -112
  10. package/src/http/fetch.ts +0 -210
  11. package/src/http/index.ts +0 -31
  12. package/src/http/keys.ts +0 -136
  13. package/src/http/retry.ts +0 -205
  14. package/src/http/sse.ts +0 -136
  15. package/src/index.ts +0 -32
  16. package/src/ollama/index.ts +0 -3
  17. package/src/openai/index.ts +0 -39
  18. package/src/openrouter/index.ts +0 -11
  19. package/src/providers/anthropic/index.ts +0 -17
  20. package/src/providers/anthropic/llm.ts +0 -196
  21. package/src/providers/anthropic/transform.ts +0 -434
  22. package/src/providers/anthropic/types.ts +0 -213
  23. package/src/providers/google/index.ts +0 -17
  24. package/src/providers/google/llm.ts +0 -203
  25. package/src/providers/google/transform.ts +0 -447
  26. package/src/providers/google/types.ts +0 -214
  27. package/src/providers/ollama/index.ts +0 -43
  28. package/src/providers/ollama/llm.ts +0 -272
  29. package/src/providers/ollama/transform.ts +0 -434
  30. package/src/providers/ollama/types.ts +0 -260
  31. package/src/providers/openai/index.ts +0 -186
  32. package/src/providers/openai/llm.completions.ts +0 -201
  33. package/src/providers/openai/llm.responses.ts +0 -211
  34. package/src/providers/openai/transform.completions.ts +0 -561
  35. package/src/providers/openai/transform.responses.ts +0 -708
  36. package/src/providers/openai/types.ts +0 -1249
  37. package/src/providers/openrouter/index.ts +0 -177
  38. package/src/providers/openrouter/llm.completions.ts +0 -201
  39. package/src/providers/openrouter/llm.responses.ts +0 -211
  40. package/src/providers/openrouter/transform.completions.ts +0 -538
  41. package/src/providers/openrouter/transform.responses.ts +0 -742
  42. package/src/providers/openrouter/types.ts +0 -717
  43. package/src/providers/xai/index.ts +0 -223
  44. package/src/providers/xai/llm.completions.ts +0 -201
  45. package/src/providers/xai/llm.messages.ts +0 -195
  46. package/src/providers/xai/llm.responses.ts +0 -211
  47. package/src/providers/xai/transform.completions.ts +0 -565
  48. package/src/providers/xai/transform.messages.ts +0 -448
  49. package/src/providers/xai/transform.responses.ts +0 -678
  50. package/src/providers/xai/types.ts +0 -938
  51. package/src/types/content.ts +0 -133
  52. package/src/types/errors.ts +0 -85
  53. package/src/types/index.ts +0 -105
  54. package/src/types/llm.ts +0 -211
  55. package/src/types/messages.ts +0 -205
  56. package/src/types/provider.ts +0 -195
  57. package/src/types/schema.ts +0 -58
  58. package/src/types/stream.ts +0 -188
  59. package/src/types/thread.ts +0 -226
  60. package/src/types/tool.ts +0 -88
  61. package/src/types/turn.ts +0 -118
  62. package/src/utils/id.ts +0 -28
  63. package/src/xai/index.ts +0 -41
@@ -1,211 +0,0 @@
1
- import type { LLMHandler, BoundLLMModel, LLMRequest, LLMResponse, LLMStreamResult, LLMCapabilities } from '../../types/llm.ts';
2
- import type { StreamEvent } from '../../types/stream.ts';
3
- import type { LLMProvider } from '../../types/provider.ts';
4
- import { UPPError } from '../../types/errors.ts';
5
- import { resolveApiKey } from '../../http/keys.ts';
6
- import { doFetch, doStreamFetch } from '../../http/fetch.ts';
7
- import { parseSSEStream } from '../../http/sse.ts';
8
- import { normalizeHttpError } from '../../http/errors.ts';
9
- import type { XAIResponsesParams, XAIResponsesResponse, XAIResponsesStreamEvent, XAIResponseErrorEvent } from './types.ts';
10
- import {
11
- transformRequest,
12
- transformResponse,
13
- transformStreamEvent,
14
- createStreamState,
15
- buildResponseFromState,
16
- } from './transform.responses.ts';
17
-
18
- const XAI_RESPONSES_API_URL = 'https://api.x.ai/v1/responses';
19
-
20
- /**
21
- * xAI Responses API capabilities
22
- */
23
- const XAI_RESPONSES_CAPABILITIES: LLMCapabilities = {
24
- streaming: true,
25
- tools: true,
26
- structuredOutput: true,
27
- imageInput: true,
28
- videoInput: false,
29
- audioInput: false,
30
- };
31
-
32
- /**
33
- * Create xAI Responses API LLM handler
34
- */
35
- export function createResponsesLLMHandler(): LLMHandler<XAIResponsesParams> {
36
- // Provider reference injected by createProvider() or xAI's custom factory
37
- let providerRef: LLMProvider<XAIResponsesParams> | null = null;
38
-
39
- return {
40
- _setProvider(provider: LLMProvider<XAIResponsesParams>) {
41
- providerRef = provider;
42
- },
43
-
44
- bind(modelId: string): BoundLLMModel<XAIResponsesParams> {
45
- // Use the injected provider reference
46
- if (!providerRef) {
47
- throw new UPPError(
48
- 'Provider reference not set. Handler must be used with createProvider() or have _setProvider called.',
49
- 'INVALID_REQUEST',
50
- 'xai',
51
- 'llm'
52
- );
53
- }
54
-
55
- const model: BoundLLMModel<XAIResponsesParams> = {
56
- modelId,
57
- capabilities: XAI_RESPONSES_CAPABILITIES,
58
-
59
- get provider(): LLMProvider<XAIResponsesParams> {
60
- return providerRef!;
61
- },
62
-
63
- async complete(request: LLMRequest<XAIResponsesParams>): Promise<LLMResponse> {
64
- const apiKey = await resolveApiKey(
65
- request.config,
66
- 'XAI_API_KEY',
67
- 'xai',
68
- 'llm'
69
- );
70
-
71
- const baseUrl = request.config.baseUrl ?? XAI_RESPONSES_API_URL;
72
- const body = transformRequest(request, modelId);
73
-
74
- const response = await doFetch(
75
- baseUrl,
76
- {
77
- method: 'POST',
78
- headers: {
79
- 'Content-Type': 'application/json',
80
- Authorization: `Bearer ${apiKey}`,
81
- },
82
- body: JSON.stringify(body),
83
- signal: request.signal,
84
- },
85
- request.config,
86
- 'xai',
87
- 'llm'
88
- );
89
-
90
- const data = (await response.json()) as XAIResponsesResponse;
91
-
92
- // Check for error in response
93
- if (data.status === 'failed' && data.error) {
94
- throw new UPPError(
95
- data.error.message,
96
- 'PROVIDER_ERROR',
97
- 'xai',
98
- 'llm'
99
- );
100
- }
101
-
102
- return transformResponse(data);
103
- },
104
-
105
- stream(request: LLMRequest<XAIResponsesParams>): LLMStreamResult {
106
- const state = createStreamState();
107
- let responseResolve: (value: LLMResponse) => void;
108
- let responseReject: (error: Error) => void;
109
-
110
- const responsePromise = new Promise<LLMResponse>((resolve, reject) => {
111
- responseResolve = resolve;
112
- responseReject = reject;
113
- });
114
-
115
- async function* generateEvents(): AsyncGenerator<StreamEvent, void, unknown> {
116
- try {
117
- const apiKey = await resolveApiKey(
118
- request.config,
119
- 'XAI_API_KEY',
120
- 'xai',
121
- 'llm'
122
- );
123
-
124
- const baseUrl = request.config.baseUrl ?? XAI_RESPONSES_API_URL;
125
- const body = transformRequest(request, modelId);
126
- body.stream = true;
127
-
128
- const response = await doStreamFetch(
129
- baseUrl,
130
- {
131
- method: 'POST',
132
- headers: {
133
- 'Content-Type': 'application/json',
134
- Authorization: `Bearer ${apiKey}`,
135
- },
136
- body: JSON.stringify(body),
137
- signal: request.signal,
138
- },
139
- request.config,
140
- 'xai',
141
- 'llm'
142
- );
143
-
144
- if (!response.ok) {
145
- const error = await normalizeHttpError(response, 'xai', 'llm');
146
- responseReject(error);
147
- throw error;
148
- }
149
-
150
- if (!response.body) {
151
- const error = new UPPError(
152
- 'No response body for streaming request',
153
- 'PROVIDER_ERROR',
154
- 'xai',
155
- 'llm'
156
- );
157
- responseReject(error);
158
- throw error;
159
- }
160
-
161
- for await (const data of parseSSEStream(response.body)) {
162
- // Skip [DONE] marker
163
- if (data === '[DONE]') {
164
- continue;
165
- }
166
-
167
- // Check for xAI error event
168
- if (typeof data === 'object' && data !== null) {
169
- const event = data as XAIResponsesStreamEvent;
170
-
171
- // Check for error event
172
- if (event.type === 'error') {
173
- const errorEvent = event as XAIResponseErrorEvent;
174
- const error = new UPPError(
175
- errorEvent.error.message,
176
- 'PROVIDER_ERROR',
177
- 'xai',
178
- 'llm'
179
- );
180
- responseReject(error);
181
- throw error;
182
- }
183
-
184
- const uppEvents = transformStreamEvent(event, state);
185
- for (const uppEvent of uppEvents) {
186
- yield uppEvent;
187
- }
188
- }
189
- }
190
-
191
- // Build final response
192
- responseResolve(buildResponseFromState(state));
193
- } catch (error) {
194
- responseReject(error as Error);
195
- throw error;
196
- }
197
- }
198
-
199
- return {
200
- [Symbol.asyncIterator]() {
201
- return generateEvents();
202
- },
203
- response: responsePromise,
204
- };
205
- },
206
- };
207
-
208
- return model;
209
- },
210
- };
211
- }