@providerprotocol/ai 0.0.39 → 0.0.40

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 (130) hide show
  1. package/README.md +269 -34
  2. package/dist/anthropic/index.d.ts +3 -3
  3. package/dist/anthropic/index.js +7 -5
  4. package/dist/anthropic/index.js.map +1 -1
  5. package/dist/cerebras/index.d.ts +3 -3
  6. package/dist/cerebras/index.js +7 -5
  7. package/dist/cerebras/index.js.map +1 -1
  8. package/dist/{chunk-WU4U6IHF.js → chunk-6QCV4WXF.js} +4 -13
  9. package/dist/chunk-6QCV4WXF.js.map +1 -0
  10. package/dist/{chunk-5XPRVUOK.js → chunk-AC3VHSZJ.js} +2 -2
  11. package/dist/{chunk-5XPRVUOK.js.map → chunk-AC3VHSZJ.js.map} +1 -1
  12. package/dist/{chunk-ZDYEDI2A.js → chunk-CWGTARDE.js} +2 -2
  13. package/dist/{chunk-KNBODIQU.js → chunk-DI47UY2H.js} +2 -2
  14. package/dist/{chunk-KNBODIQU.js.map → chunk-DI47UY2H.js.map} +1 -1
  15. package/dist/{chunk-IDZR4ROP.js → chunk-EHR3LIPS.js} +2 -2
  16. package/dist/{chunk-IDZR4ROP.js.map → chunk-EHR3LIPS.js.map} +1 -1
  17. package/dist/chunk-EY2LLDGY.js +94 -0
  18. package/dist/chunk-EY2LLDGY.js.map +1 -0
  19. package/dist/{chunk-MJI74VEJ.js → chunk-F5ENANMJ.js} +18 -2
  20. package/dist/chunk-F5ENANMJ.js.map +1 -0
  21. package/dist/chunk-IKJH5ZSJ.js +1 -0
  22. package/dist/chunk-IKJH5ZSJ.js.map +1 -0
  23. package/dist/{chunk-IIMTP3XC.js → chunk-KBI45OXI.js} +2 -2
  24. package/dist/{chunk-SAMIK4WZ.js → chunk-KVUOTFYZ.js} +2 -2
  25. package/dist/{chunk-U6M3MXNI.js → chunk-L6QWKFGE.js} +3 -2
  26. package/dist/chunk-L6QWKFGE.js.map +1 -0
  27. package/dist/{chunk-RDC5GYST.js → chunk-N4LAFGLX.js} +7 -7
  28. package/dist/{chunk-ZKNPQBIE.js → chunk-R3T2IYOU.js} +5 -3
  29. package/dist/{chunk-ZKNPQBIE.js.map → chunk-R3T2IYOU.js.map} +1 -1
  30. package/dist/chunk-U2G5PHHL.js +25 -0
  31. package/dist/chunk-U2G5PHHL.js.map +1 -0
  32. package/dist/{chunk-SBGZJVTJ.js → chunk-VQZPADW6.js} +100 -33
  33. package/dist/chunk-VQZPADW6.js.map +1 -0
  34. package/dist/{chunk-O32SBS6S.js → chunk-XTWBAL42.js} +2 -2
  35. package/dist/{chunk-O32SBS6S.js.map → chunk-XTWBAL42.js.map} +1 -1
  36. package/dist/{chunk-WNB5PSY6.js → chunk-ZMESKGUY.js} +2 -2
  37. package/dist/{chunk-7ULSRWDH.js → chunk-ZSZVWLGE.js} +2 -2
  38. package/dist/{embedding-iNQCeXfk.d.ts → embedding-ts1npsDg.d.ts} +1 -1
  39. package/dist/google/index.d.ts +38 -4
  40. package/dist/google/index.js +5 -4
  41. package/dist/google/index.js.map +1 -1
  42. package/dist/groq/index.d.ts +3 -3
  43. package/dist/groq/index.js +7 -5
  44. package/dist/groq/index.js.map +1 -1
  45. package/dist/http/index.d.ts +5 -5
  46. package/dist/http/index.js +19 -22
  47. package/dist/{image-stream-ARno6XlS.d.ts → image-stream-BPml2YZZ.d.ts} +1 -1
  48. package/dist/index.d.ts +8 -8
  49. package/dist/index.js +306 -112
  50. package/dist/index.js.map +1 -1
  51. package/dist/{llm-CZqlijjK.d.ts → llm-BWLaTzzY.d.ts} +75 -29
  52. package/dist/middleware/logging/index.d.ts +3 -3
  53. package/dist/middleware/logging/index.js +3 -0
  54. package/dist/middleware/logging/index.js.map +1 -1
  55. package/dist/middleware/parsed-object/index.d.ts +3 -3
  56. package/dist/middleware/parsed-object/index.js +5 -1
  57. package/dist/middleware/parsed-object/index.js.map +1 -1
  58. package/dist/middleware/persistence/index.d.ts +3 -3
  59. package/dist/middleware/persistence/index.js +3 -2
  60. package/dist/middleware/persistence/index.js.map +1 -1
  61. package/dist/middleware/pipeline/index.d.ts +195 -0
  62. package/dist/middleware/pipeline/index.js +61 -0
  63. package/dist/middleware/pipeline/index.js.map +1 -0
  64. package/dist/middleware/pubsub/index.d.ts +13 -11
  65. package/dist/middleware/pubsub/index.js +31 -5
  66. package/dist/middleware/pubsub/index.js.map +1 -1
  67. package/dist/middleware/pubsub/server/express/index.d.ts +3 -3
  68. package/dist/middleware/pubsub/server/express/index.js +2 -2
  69. package/dist/middleware/pubsub/server/fastify/index.d.ts +3 -3
  70. package/dist/middleware/pubsub/server/fastify/index.js +2 -2
  71. package/dist/middleware/pubsub/server/h3/index.d.ts +3 -3
  72. package/dist/middleware/pubsub/server/h3/index.js +2 -2
  73. package/dist/middleware/pubsub/server/index.d.ts +50 -9
  74. package/dist/middleware/pubsub/server/index.js +5 -5
  75. package/dist/middleware/pubsub/server/index.js.map +1 -1
  76. package/dist/middleware/pubsub/server/webapi/index.d.ts +3 -3
  77. package/dist/middleware/pubsub/server/webapi/index.js +2 -2
  78. package/dist/moonshot/index.d.ts +3 -3
  79. package/dist/moonshot/index.js +7 -5
  80. package/dist/moonshot/index.js.map +1 -1
  81. package/dist/ollama/index.d.ts +24 -4
  82. package/dist/ollama/index.js +5 -4
  83. package/dist/ollama/index.js.map +1 -1
  84. package/dist/openai/index.d.ts +65 -4
  85. package/dist/openai/index.js +7 -5
  86. package/dist/openai/index.js.map +1 -1
  87. package/dist/openrouter/index.d.ts +4 -4
  88. package/dist/openrouter/index.js +7 -5
  89. package/dist/openrouter/index.js.map +1 -1
  90. package/dist/proxy/index.d.ts +5 -5
  91. package/dist/proxy/index.js +16 -15
  92. package/dist/proxy/index.js.map +1 -1
  93. package/dist/proxy/server/express/index.d.ts +8 -9
  94. package/dist/proxy/server/express/index.js +4 -3
  95. package/dist/proxy/server/fastify/index.d.ts +8 -9
  96. package/dist/proxy/server/fastify/index.js +4 -3
  97. package/dist/proxy/server/h3/index.d.ts +8 -9
  98. package/dist/proxy/server/h3/index.js +4 -3
  99. package/dist/proxy/server/index.d.ts +5 -5
  100. package/dist/proxy/server/index.js +14 -13
  101. package/dist/proxy/server/webapi/index.d.ts +8 -9
  102. package/dist/proxy/server/webapi/index.js +4 -3
  103. package/dist/responses/index.d.ts +3 -3
  104. package/dist/responses/index.js +7 -5
  105. package/dist/responses/index.js.map +1 -1
  106. package/dist/retry-DVfdPLIB.d.ts +322 -0
  107. package/dist/{stream-DVVUIKpz.d.ts → stream-bBd_4Ipu.d.ts} +27 -4
  108. package/dist/{tool-D22EhP5F.d.ts → tool-BmAfKNBq.d.ts} +1 -1
  109. package/dist/{types-CyXF0J7C.d.ts → types-nTwlpyJE.d.ts} +13 -1
  110. package/dist/utils/index.d.ts +66 -2
  111. package/dist/utils/index.js +13 -0
  112. package/dist/xai/index.d.ts +3 -3
  113. package/dist/xai/index.js +7 -5
  114. package/dist/xai/index.js.map +1 -1
  115. package/package.json +6 -1
  116. package/dist/chunk-ARVM24K2.js +0 -128
  117. package/dist/chunk-ARVM24K2.js.map +0 -1
  118. package/dist/chunk-MJI74VEJ.js.map +0 -1
  119. package/dist/chunk-SBGZJVTJ.js.map +0 -1
  120. package/dist/chunk-U6M3MXNI.js.map +0 -1
  121. package/dist/chunk-WU4U6IHF.js.map +0 -1
  122. package/dist/chunk-Y5H7C5J4.js +0 -263
  123. package/dist/chunk-Y5H7C5J4.js.map +0 -1
  124. package/dist/retry-C1eJbEMV.d.ts +0 -531
  125. /package/dist/{chunk-ZDYEDI2A.js.map → chunk-CWGTARDE.js.map} +0 -0
  126. /package/dist/{chunk-IIMTP3XC.js.map → chunk-KBI45OXI.js.map} +0 -0
  127. /package/dist/{chunk-SAMIK4WZ.js.map → chunk-KVUOTFYZ.js.map} +0 -0
  128. /package/dist/{chunk-RDC5GYST.js.map → chunk-N4LAFGLX.js.map} +0 -0
  129. /package/dist/{chunk-WNB5PSY6.js.map → chunk-ZMESKGUY.js.map} +0 -0
  130. /package/dist/{chunk-7ULSRWDH.js.map → chunk-ZSZVWLGE.js.map} +0 -0
@@ -1,4 +1,4 @@
1
- import { c as ToolCall, d as ToolResult, e as ToolExecution } from './tool-D22EhP5F.js';
1
+ import { T as ToolCall, a as ToolResult, b as ToolExecution } from './tool-BmAfKNBq.js';
2
2
 
3
3
  /**
4
4
  * @fileoverview Content block types for multimodal messages.
@@ -1002,6 +1002,8 @@ declare const StreamEventType: {
1002
1002
  readonly ToolExecutionStart: "tool_execution_start";
1003
1003
  /** Tool execution has completed */
1004
1004
  readonly ToolExecutionEnd: "tool_execution_end";
1005
+ /** Stream is being retried after an error */
1006
+ readonly StreamRetry: "stream_retry";
1005
1007
  /** Beginning of a message */
1006
1008
  readonly MessageStart: "message_start";
1007
1009
  /** End of a message */
@@ -1035,10 +1037,14 @@ type StreamEventType = (typeof StreamEventType)[keyof typeof StreamEventType];
1035
1037
  * | `tool_call_delta` | `toolCallId`, `toolName`, `argumentsJson` |
1036
1038
  * | `tool_execution_start` | `toolCallId`, `toolName`, `timestamp` |
1037
1039
  * | `tool_execution_end` | `toolCallId`, `toolName`, `result`, `isError`, `timestamp` |
1040
+ * | `stream_retry` | `attempt`, `maxAttempts`, `error`, `timestamp` |
1038
1041
  * | `message_start` | (none) |
1039
1042
  * | `message_stop` | (none) |
1040
1043
  * | `content_block_start` | (none) |
1041
1044
  * | `content_block_stop` | (none) |
1045
+ *
1046
+ * Custom event types (via middleware) may extend EventDelta with additional fields.
1047
+ * See {@link @providerprotocol/ai/middleware/flow!FlowStageDelta} for an example.
1042
1048
  */
1043
1049
  interface EventDelta {
1044
1050
  /** Incremental text content (text_delta, reasoning_delta, object_delta) */
@@ -1055,8 +1061,17 @@ interface EventDelta {
1055
1061
  result?: unknown;
1056
1062
  /** Whether tool execution resulted in an error (tool_execution_end) */
1057
1063
  isError?: boolean;
1058
- /** Timestamp in milliseconds (tool_execution_start/end) */
1064
+ /** Timestamp in milliseconds (tool_execution_start/end, stream_retry) */
1059
1065
  timestamp?: number;
1066
+ /** Current retry attempt number (stream_retry, 1-indexed) */
1067
+ attempt?: number;
1068
+ /** Maximum number of retry attempts configured (stream_retry) */
1069
+ maxAttempts?: number;
1070
+ /** Error that triggered the retry (stream_retry) - serialized for JSON transport */
1071
+ error?: {
1072
+ message: string;
1073
+ code?: string;
1074
+ };
1060
1075
  }
1061
1076
  /**
1062
1077
  * A single streaming event from the LLM.
@@ -1078,8 +1093,16 @@ interface EventDelta {
1078
1093
  * ```
1079
1094
  */
1080
1095
  interface StreamEvent {
1081
- /** Event type discriminator */
1082
- type: StreamEventType;
1096
+ /**
1097
+ * Event type discriminator.
1098
+ *
1099
+ * Uses `StreamEventType | (string & Record<never, never>)` to allow custom
1100
+ * event types (like 'flow_stage') while preserving autocomplete for known types.
1101
+ * The `(string & Record<never, never>)` pattern is a TypeScript idiom that
1102
+ * widens the type to accept any string without losing the literal type union
1103
+ * in IDE autocomplete suggestions.
1104
+ */
1105
+ type: StreamEventType | (string & Record<never, never>);
1083
1106
  /** Index of the content block this event belongs to */
1084
1107
  index: number;
1085
1108
  /** Event-specific data payload */
@@ -504,4 +504,4 @@ interface ToolExecution {
504
504
  approved?: boolean;
505
505
  }
506
506
 
507
- export type { AfterCallResult as A, BeforeCallResult as B, JSONSchema as J, Structure as S, ToolInput as T, ZodLike as Z, ZodV4Like as a, Tool as b, ToolCall as c, ToolResult as d, ToolExecution as e, ToolUseStrategy as f, JSONSchemaProperty as g, JSONSchemaPropertyType as h, ZodV3Like as i, ToolMetadata as j };
507
+ export type { AfterCallResult as A, BeforeCallResult as B, JSONSchema as J, Structure as S, ToolCall as T, ZodLike as Z, ToolResult as a, ToolExecution as b, ZodV4Like as c, ToolInput as d, Tool as e, ToolUseStrategy as f, JSONSchemaProperty as g, JSONSchemaPropertyType as h, ZodV3Like as i, ToolMetadata as j };
@@ -1,4 +1,4 @@
1
- import { S as StreamEvent } from './stream-DVVUIKpz.js';
1
+ import { S as StreamEvent } from './stream-bBd_4Ipu.js';
2
2
 
3
3
  /**
4
4
  * @fileoverview Pub-sub middleware types for stream resumption.
@@ -80,6 +80,18 @@ interface PubSubAdapter {
80
80
  * Notifies subscribers and removes stream from storage.
81
81
  */
82
82
  remove(streamId: string): Promise<void>;
83
+ /**
84
+ * Clears all events for a stream without removing it.
85
+ * Used during retry to reset accumulated state.
86
+ */
87
+ clear(streamId: string): Promise<void>;
88
+ /**
89
+ * Gets the current cursor base for a stream.
90
+ * After a clear, cursor base increases so new events have higher cursors
91
+ * than any events sent before the clear.
92
+ * @returns Cursor base, or 0 if stream doesn't exist or hasn't been cleared
93
+ */
94
+ getCursorBase(streamId: string): number;
83
95
  }
84
96
  /**
85
97
  * Options for pub-sub middleware.
@@ -1,4 +1,4 @@
1
- import { Z as ZodLike, a as ZodV4Like, J as JSONSchema, T as ToolInput, b as Tool } from '../tool-D22EhP5F.js';
1
+ import { Z as ZodLike, c as ZodV4Like, J as JSONSchema, d as ToolInput, e as Tool } from '../tool-BmAfKNBq.js';
2
2
 
3
3
  /**
4
4
  * @fileoverview Partial JSON parser for streaming LLM responses.
@@ -114,4 +114,68 @@ declare function resolveStructure(structure: JSONSchema | ZodLike): JSONSchema;
114
114
  */
115
115
  declare function resolveTools(tools: ToolInput[]): Tool[];
116
116
 
117
- export { type PartialParseResult, isZodSchema, isZodV4, parsePartialJson, resolveStructure, resolveTools, zodToJSONSchema, zodToJSONSchemaSync };
117
+ /**
118
+ * @fileoverview Error normalization utilities.
119
+ *
120
+ * @module utils/error
121
+ */
122
+ /**
123
+ * Converts an unknown thrown value into an Error instance.
124
+ *
125
+ * @param value - Unknown error value
126
+ * @returns An Error instance
127
+ */
128
+ declare function toError(value: unknown): Error;
129
+ /**
130
+ * Checks whether an error represents a cancellation.
131
+ *
132
+ * @param value - Unknown error value
133
+ * @returns True if the error indicates cancellation
134
+ */
135
+ declare function isCancelledError(value: unknown): boolean;
136
+
137
+ /**
138
+ * @fileoverview ID generation utilities for the Universal Provider Protocol.
139
+ *
140
+ * Provides functions for generating unique identifiers used throughout UPP,
141
+ * including message IDs, tool call IDs, and other internal references.
142
+ *
143
+ * @module utils/id
144
+ */
145
+ /**
146
+ * Generates a unique UUID v4 identifier.
147
+ *
148
+ * Uses the native `crypto.randomUUID()` when available for cryptographically
149
+ * secure randomness. Falls back to a Math.random-based implementation for
150
+ * environments without Web Crypto API support.
151
+ *
152
+ * @returns A UUID v4 string in the format `xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`
153
+ *
154
+ * @example
155
+ * ```typescript
156
+ * const messageId = generateId();
157
+ * // => "f47ac10b-58cc-4372-a567-0e02b2c3d479"
158
+ * ```
159
+ */
160
+ declare function generateId(): string;
161
+ /**
162
+ * Generates a short alphanumeric identifier.
163
+ *
164
+ * Creates a 12-character random string using alphanumeric characters (a-z, A-Z, 0-9).
165
+ * Useful for tool call IDs and other cases where a full UUID is not required.
166
+ *
167
+ * @param prefix - Optional prefix to prepend to the generated ID
168
+ * @returns A string containing the prefix followed by 12 random alphanumeric characters
169
+ *
170
+ * @example
171
+ * ```typescript
172
+ * const toolCallId = generateShortId('call_');
173
+ * // => "call_aB3xY9mK2pQr"
174
+ *
175
+ * const simpleId = generateShortId();
176
+ * // => "Tz4wN8vL1sHj"
177
+ * ```
178
+ */
179
+ declare function generateShortId(prefix?: string): string;
180
+
181
+ export { type PartialParseResult, generateId, generateShortId, isCancelledError, isZodSchema, isZodV4, parsePartialJson, resolveStructure, resolveTools, toError, zodToJSONSchema, zodToJSONSchemaSync };
@@ -9,12 +9,25 @@ import {
9
9
  zodToJSONSchema,
10
10
  zodToJSONSchemaSync
11
11
  } from "../chunk-3Q5VELKG.js";
12
+ import {
13
+ generateId,
14
+ generateShortId
15
+ } from "../chunk-U2G5PHHL.js";
16
+ import {
17
+ isCancelledError,
18
+ toError
19
+ } from "../chunk-GIDT7C6I.js";
20
+ import "../chunk-COS4ON4G.js";
12
21
  export {
22
+ generateId,
23
+ generateShortId,
24
+ isCancelledError,
13
25
  isZodSchema,
14
26
  isZodV4,
15
27
  parsePartialJson,
16
28
  resolveStructure,
17
29
  resolveTools,
30
+ toError,
18
31
  zodToJSONSchema,
19
32
  zodToJSONSchemaSync
20
33
  };
@@ -1,6 +1,6 @@
1
- import { e as Provider } from '../llm-CZqlijjK.js';
2
- import '../stream-DVVUIKpz.js';
3
- import '../tool-D22EhP5F.js';
1
+ import { e as Provider } from '../llm-BWLaTzzY.js';
2
+ import '../stream-bBd_4Ipu.js';
3
+ import '../tool-BmAfKNBq.js';
4
4
 
5
5
  /**
6
6
  * xAI Chat Completions API parameters (OpenAI-compatible).
package/dist/xai/index.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  } from "../chunk-TUTYMOBL.js";
10
10
  import {
11
11
  resolveApiKey
12
- } from "../chunk-ARVM24K2.js";
12
+ } from "../chunk-EY2LLDGY.js";
13
13
  import {
14
14
  createProvider
15
15
  } from "../chunk-JA3UZALR.js";
@@ -17,18 +17,20 @@ import {
17
17
  doFetch,
18
18
  doStreamFetch,
19
19
  normalizeHttpError
20
- } from "../chunk-SBGZJVTJ.js";
20
+ } from "../chunk-VQZPADW6.js";
21
21
  import {
22
22
  StreamEventType,
23
23
  objectDelta
24
- } from "../chunk-MJI74VEJ.js";
24
+ } from "../chunk-F5ENANMJ.js";
25
25
  import {
26
26
  AssistantMessage,
27
- generateId,
28
27
  isAssistantMessage,
29
28
  isToolResultMessage,
30
29
  isUserMessage
31
- } from "../chunk-WU4U6IHF.js";
30
+ } from "../chunk-6QCV4WXF.js";
31
+ import {
32
+ generateId
33
+ } from "../chunk-U2G5PHHL.js";
32
34
  import {
33
35
  toError
34
36
  } from "../chunk-GIDT7C6I.js";