@providerprotocol/ai 0.0.22 → 0.0.23

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 (48) hide show
  1. package/README.md +188 -6
  2. package/dist/anthropic/index.d.ts +1 -1
  3. package/dist/anthropic/index.js +30 -25
  4. package/dist/anthropic/index.js.map +1 -1
  5. package/dist/{chunk-7WYBJPJJ.js → chunk-55X3W2MN.js} +4 -3
  6. package/dist/chunk-55X3W2MN.js.map +1 -0
  7. package/dist/chunk-73IIE3QT.js +120 -0
  8. package/dist/chunk-73IIE3QT.js.map +1 -0
  9. package/dist/{chunk-M4BMM5IB.js → chunk-MF5ETY5O.js} +13 -4
  10. package/dist/chunk-MF5ETY5O.js.map +1 -0
  11. package/dist/{chunk-RFWLEFAB.js → chunk-QNJO7DSD.js} +61 -16
  12. package/dist/chunk-QNJO7DSD.js.map +1 -0
  13. package/dist/{chunk-RS7C25LS.js → chunk-SBCATNHA.js} +9 -5
  14. package/dist/chunk-SBCATNHA.js.map +1 -0
  15. package/dist/{chunk-I2VHCGQE.js → chunk-Z6DKC37J.js} +6 -5
  16. package/dist/chunk-Z6DKC37J.js.map +1 -0
  17. package/dist/google/index.d.ts +3 -2
  18. package/dist/google/index.js +38 -33
  19. package/dist/google/index.js.map +1 -1
  20. package/dist/http/index.d.ts +2 -2
  21. package/dist/http/index.js +3 -3
  22. package/dist/index.d.ts +8 -6
  23. package/dist/index.js +81 -121
  24. package/dist/index.js.map +1 -1
  25. package/dist/ollama/index.d.ts +5 -2
  26. package/dist/ollama/index.js +34 -29
  27. package/dist/ollama/index.js.map +1 -1
  28. package/dist/openai/index.d.ts +1 -1
  29. package/dist/openai/index.js +58 -53
  30. package/dist/openai/index.js.map +1 -1
  31. package/dist/openrouter/index.d.ts +1 -1
  32. package/dist/openrouter/index.js +57 -52
  33. package/dist/openrouter/index.js.map +1 -1
  34. package/dist/{provider-DWEAzeM5.d.ts → provider-DR1yins0.d.ts} +148 -52
  35. package/dist/proxy/index.d.ts +2 -2
  36. package/dist/proxy/index.js +11 -9
  37. package/dist/proxy/index.js.map +1 -1
  38. package/dist/{retry-DmPmqZL6.d.ts → retry-DJiqAslw.d.ts} +1 -1
  39. package/dist/{stream-DbkLOIbJ.d.ts → stream-BuTrqt_j.d.ts} +90 -38
  40. package/dist/xai/index.d.ts +1 -1
  41. package/dist/xai/index.js +71 -66
  42. package/dist/xai/index.js.map +1 -1
  43. package/package.json +1 -1
  44. package/dist/chunk-7WYBJPJJ.js.map +0 -1
  45. package/dist/chunk-I2VHCGQE.js.map +0 -1
  46. package/dist/chunk-M4BMM5IB.js.map +0 -1
  47. package/dist/chunk-RFWLEFAB.js.map +0 -1
  48. package/dist/chunk-RS7C25LS.js.map +0 -1
@@ -3,27 +3,32 @@ import {
3
3
  } from "../chunk-WAKD3OO5.js";
4
4
  import {
5
5
  parseJsonResponse
6
- } from "../chunk-I2VHCGQE.js";
6
+ } from "../chunk-Z6DKC37J.js";
7
+ import {
8
+ StreamEventType
9
+ } from "../chunk-73IIE3QT.js";
7
10
  import {
8
11
  AssistantMessage,
9
12
  createProvider,
10
13
  isAssistantMessage,
11
14
  isToolResultMessage,
12
15
  isUserMessage
13
- } from "../chunk-M4BMM5IB.js";
16
+ } from "../chunk-MF5ETY5O.js";
14
17
  import {
15
18
  parseSSEStream
16
19
  } from "../chunk-NWS5IKNR.js";
17
20
  import {
18
21
  resolveApiKey
19
- } from "../chunk-7WYBJPJJ.js";
22
+ } from "../chunk-55X3W2MN.js";
20
23
  import {
24
+ ErrorCode,
25
+ ModalityType,
21
26
  UPPError,
22
27
  doFetch,
23
28
  doStreamFetch,
24
29
  normalizeHttpError,
25
30
  toError
26
- } from "../chunk-RFWLEFAB.js";
31
+ } from "../chunk-QNJO7DSD.js";
27
32
 
28
33
  // src/providers/google/transform.ts
29
34
  function transformRequest(request, modelId) {
@@ -80,9 +85,9 @@ function normalizeSystem(system) {
80
85
  if (!Array.isArray(system)) {
81
86
  throw new UPPError(
82
87
  "System prompt must be a string or an array of text parts",
83
- "INVALID_REQUEST",
88
+ ErrorCode.InvalidRequest,
84
89
  "google",
85
- "llm"
90
+ ModalityType.LLM
86
91
  );
87
92
  }
88
93
  const parts = [];
@@ -90,18 +95,18 @@ function normalizeSystem(system) {
90
95
  if (!part || typeof part !== "object" || !("text" in part)) {
91
96
  throw new UPPError(
92
97
  "Google system prompt array must contain text parts",
93
- "INVALID_REQUEST",
98
+ ErrorCode.InvalidRequest,
94
99
  "google",
95
- "llm"
100
+ ModalityType.LLM
96
101
  );
97
102
  }
98
103
  const textValue = part.text;
99
104
  if (typeof textValue !== "string") {
100
105
  throw new UPPError(
101
106
  "Google system prompt text must be a string",
102
- "INVALID_REQUEST",
107
+ ErrorCode.InvalidRequest,
103
108
  "google",
104
- "llm"
109
+ ModalityType.LLM
105
110
  );
106
111
  }
107
112
  parts.push(part);
@@ -308,7 +313,7 @@ function createStreamState() {
308
313
  function transformStreamChunk(chunk, state) {
309
314
  const events = [];
310
315
  if (state.isFirstChunk) {
311
- events.push({ type: "message_start", index: 0, delta: {} });
316
+ events.push({ type: StreamEventType.MessageStart, index: 0, delta: {} });
312
317
  state.isFirstChunk = false;
313
318
  }
314
319
  if (chunk.usageMetadata) {
@@ -324,7 +329,7 @@ function transformStreamChunk(chunk, state) {
324
329
  if ("text" in part) {
325
330
  state.content += part.text;
326
331
  events.push({
327
- type: "text_delta",
332
+ type: StreamEventType.TextDelta,
328
333
  index: 0,
329
334
  delta: { text: part.text }
330
335
  });
@@ -338,7 +343,7 @@ function transformStreamChunk(chunk, state) {
338
343
  thoughtSignature: fc.thoughtSignature
339
344
  });
340
345
  events.push({
341
- type: "tool_call_delta",
346
+ type: StreamEventType.ToolCallDelta,
342
347
  index: state.toolCalls.length - 1,
343
348
  delta: {
344
349
  toolCallId,
@@ -355,7 +360,7 @@ ${codeResult.codeExecutionResult.output}\`\`\`
355
360
  `;
356
361
  state.content += outputText;
357
362
  events.push({
358
- type: "text_delta",
363
+ type: StreamEventType.TextDelta,
359
364
  index: 0,
360
365
  delta: { text: outputText }
361
366
  });
@@ -364,7 +369,7 @@ ${codeResult.codeExecutionResult.output}\`\`\`
364
369
  }
365
370
  if (candidate.finishReason) {
366
371
  state.finishReason = candidate.finishReason;
367
- events.push({ type: "message_stop", index: 0, delta: {} });
372
+ events.push({ type: StreamEventType.MessageStop, index: 0, delta: {} });
368
373
  }
369
374
  return events;
370
375
  }
@@ -458,9 +463,9 @@ function createLLMHandler() {
458
463
  if (!providerRef) {
459
464
  throw new UPPError(
460
465
  "Provider reference not set. Handler must be used with createProvider().",
461
- "INVALID_REQUEST",
466
+ ErrorCode.InvalidRequest,
462
467
  "google",
463
- "llm"
468
+ ModalityType.LLM
464
469
  );
465
470
  }
466
471
  const model = {
@@ -554,9 +559,9 @@ function createLLMHandler() {
554
559
  if (!response.body) {
555
560
  const error = new UPPError(
556
561
  "No response body for streaming request",
557
- "PROVIDER_ERROR",
562
+ ErrorCode.ProviderError,
558
563
  "google",
559
- "llm"
564
+ ModalityType.LLM
560
565
  );
561
566
  responseReject(error);
562
567
  throw error;
@@ -567,9 +572,9 @@ function createLLMHandler() {
567
572
  if (chunk.error) {
568
573
  const error = new UPPError(
569
574
  chunk.error.message,
570
- "PROVIDER_ERROR",
575
+ ErrorCode.ProviderError,
571
576
  "google",
572
- "llm"
577
+ ModalityType.LLM
573
578
  );
574
579
  responseReject(error);
575
580
  throw error;
@@ -613,9 +618,9 @@ function createEmbeddingHandler() {
613
618
  if (!providerRef) {
614
619
  throw new UPPError(
615
620
  "Provider reference not set. Handler must be used with createProvider().",
616
- "INVALID_REQUEST",
621
+ ErrorCode.InvalidRequest,
617
622
  "google",
618
- "embedding"
623
+ ModalityType.Embedding
619
624
  );
620
625
  }
621
626
  const model = {
@@ -639,9 +644,9 @@ function createEmbeddingHandler() {
639
644
  if (!text) {
640
645
  throw new UPPError(
641
646
  "Google embeddings only support text input",
642
- "INVALID_REQUEST",
647
+ ErrorCode.InvalidRequest,
643
648
  "google",
644
- "embedding"
649
+ ModalityType.Embedding
645
650
  );
646
651
  }
647
652
  const embedRequest = {
@@ -713,9 +718,9 @@ function createImageHandler() {
713
718
  if (!providerRef) {
714
719
  throw new UPPError(
715
720
  "Provider reference not set. Handler must be used with createProvider().",
716
- "INVALID_REQUEST",
721
+ ErrorCode.InvalidRequest,
717
722
  "google",
718
- "image"
723
+ ModalityType.Image
719
724
  );
720
725
  }
721
726
  const capabilities = getCapabilities();
@@ -775,9 +780,9 @@ function transformResponse2(data) {
775
780
  if (!data.predictions || data.predictions.length === 0) {
776
781
  throw new UPPError(
777
782
  "No images in response",
778
- "PROVIDER_ERROR",
783
+ ErrorCode.ProviderError,
779
784
  "google",
780
- "image"
785
+ ModalityType.Image
781
786
  );
782
787
  }
783
788
  const images = data.predictions.map((prediction) => {
@@ -922,9 +927,9 @@ async function update(name, updateRequest, apiKey, config, signal) {
922
927
  if (updateRequest.expireTime && updateRequest.ttl) {
923
928
  throw new UPPError(
924
929
  "Provide either expireTime or ttl (not both)",
925
- "INVALID_REQUEST",
930
+ ErrorCode.InvalidRequest,
926
931
  "google",
927
- "llm"
932
+ ModalityType.LLM
928
933
  );
929
934
  }
930
935
  const updateMaskParts = [];
@@ -937,9 +942,9 @@ async function update(name, updateRequest, apiKey, config, signal) {
937
942
  if (updateMaskParts.length === 0) {
938
943
  throw new UPPError(
939
944
  "Update request must include expireTime or ttl",
940
- "INVALID_REQUEST",
945
+ ErrorCode.InvalidRequest,
941
946
  "google",
942
- "llm"
947
+ ModalityType.LLM
943
948
  );
944
949
  }
945
950
  const cacheName = name.startsWith("cachedContents/") ? name : `cachedContents/${name}`;