@providerprotocol/ai 0.0.33 → 0.0.35

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 (133) hide show
  1. package/README.md +542 -3
  2. package/dist/anthropic/index.d.ts +2 -1
  3. package/dist/anthropic/index.js +151 -145
  4. package/dist/anthropic/index.js.map +1 -1
  5. package/dist/cerebras/index.d.ts +392 -0
  6. package/dist/cerebras/index.js +648 -0
  7. package/dist/cerebras/index.js.map +1 -0
  8. package/dist/chunk-3GWM5GR3.js +153 -0
  9. package/dist/chunk-3GWM5GR3.js.map +1 -0
  10. package/dist/chunk-4OGB7JZA.js +157 -0
  11. package/dist/chunk-4OGB7JZA.js.map +1 -0
  12. package/dist/chunk-7DXVRILR.js +49 -0
  13. package/dist/chunk-7DXVRILR.js.map +1 -0
  14. package/dist/{chunk-3C7O2RNO.js → chunk-A2IM7PGT.js} +6 -4
  15. package/dist/{chunk-3C7O2RNO.js.map → chunk-A2IM7PGT.js.map} +1 -1
  16. package/dist/{chunk-3D6XGGVG.js → chunk-ARVM24K2.js} +2 -2
  17. package/dist/{chunk-4J6OFUKX.js → chunk-AY55T37A.js} +70 -162
  18. package/dist/chunk-AY55T37A.js.map +1 -0
  19. package/dist/{chunk-ILR2D5PN.js → chunk-BRP5XJ6Q.js} +2 -86
  20. package/dist/chunk-BRP5XJ6Q.js.map +1 -0
  21. package/dist/chunk-C4JP64VW.js +298 -0
  22. package/dist/chunk-C4JP64VW.js.map +1 -0
  23. package/dist/chunk-COS4ON4G.js +111 -0
  24. package/dist/chunk-COS4ON4G.js.map +1 -0
  25. package/dist/chunk-ETBFOLQN.js +34 -0
  26. package/dist/chunk-ETBFOLQN.js.map +1 -0
  27. package/dist/chunk-HB4ZIH3T.js +31 -0
  28. package/dist/chunk-HB4ZIH3T.js.map +1 -0
  29. package/dist/chunk-I53CI6ZZ.js +142 -0
  30. package/dist/chunk-I53CI6ZZ.js.map +1 -0
  31. package/dist/chunk-IDZOVWP3.js +29 -0
  32. package/dist/chunk-IDZOVWP3.js.map +1 -0
  33. package/dist/chunk-JA3UZALR.js +88 -0
  34. package/dist/chunk-JA3UZALR.js.map +1 -0
  35. package/dist/{chunk-WAKD3OO5.js → chunk-N5DX5JW3.js} +31 -31
  36. package/dist/chunk-N5DX5JW3.js.map +1 -0
  37. package/dist/chunk-OIEWDFQU.js +97 -0
  38. package/dist/chunk-OIEWDFQU.js.map +1 -0
  39. package/dist/{chunk-TOJCZMVU.js → chunk-PMK5LZ5Z.js} +40 -40
  40. package/dist/chunk-PMK5LZ5Z.js.map +1 -0
  41. package/dist/chunk-UFFJDYCE.js +94 -0
  42. package/dist/chunk-UFFJDYCE.js.map +1 -0
  43. package/dist/chunk-VGKZIGVI.js +222 -0
  44. package/dist/chunk-VGKZIGVI.js.map +1 -0
  45. package/dist/chunk-VOEWHQUB.js +31 -0
  46. package/dist/chunk-VOEWHQUB.js.map +1 -0
  47. package/dist/{chunk-KUPF5KHT.js → chunk-Y5H7C5J4.js} +2 -2
  48. package/dist/chunk-ZI67WIQS.js +30 -0
  49. package/dist/chunk-ZI67WIQS.js.map +1 -0
  50. package/dist/{embedding-D2BYIehX.d.ts → embedding-CW6SaOOz.d.ts} +1 -1
  51. package/dist/google/index.d.ts +2 -1
  52. package/dist/google/index.js +202 -199
  53. package/dist/google/index.js.map +1 -1
  54. package/dist/groq/index.d.ts +410 -0
  55. package/dist/groq/index.js +649 -0
  56. package/dist/groq/index.js.map +1 -0
  57. package/dist/http/index.d.ts +3 -2
  58. package/dist/http/index.js +5 -4
  59. package/dist/image-stream-C0ciACM2.d.ts +11 -0
  60. package/dist/index.d.ts +8 -118
  61. package/dist/index.js +518 -767
  62. package/dist/index.js.map +1 -1
  63. package/dist/{llm-BQJZj3cD.d.ts → llm-DwbUK7un.d.ts} +12 -1632
  64. package/dist/middleware/logging/index.d.ts +76 -0
  65. package/dist/middleware/logging/index.js +74 -0
  66. package/dist/middleware/logging/index.js.map +1 -0
  67. package/dist/middleware/parsed-object/index.d.ts +45 -0
  68. package/dist/middleware/parsed-object/index.js +73 -0
  69. package/dist/middleware/parsed-object/index.js.map +1 -0
  70. package/dist/middleware/pubsub/index.d.ts +104 -0
  71. package/dist/middleware/pubsub/index.js +230 -0
  72. package/dist/middleware/pubsub/index.js.map +1 -0
  73. package/dist/middleware/pubsub/server/express/index.d.ts +52 -0
  74. package/dist/middleware/pubsub/server/express/index.js +11 -0
  75. package/dist/middleware/pubsub/server/express/index.js.map +1 -0
  76. package/dist/middleware/pubsub/server/fastify/index.d.ts +53 -0
  77. package/dist/middleware/pubsub/server/fastify/index.js +11 -0
  78. package/dist/middleware/pubsub/server/fastify/index.js.map +1 -0
  79. package/dist/middleware/pubsub/server/h3/index.d.ts +56 -0
  80. package/dist/middleware/pubsub/server/h3/index.js +11 -0
  81. package/dist/middleware/pubsub/server/h3/index.js.map +1 -0
  82. package/dist/middleware/pubsub/server/index.d.ts +78 -0
  83. package/dist/middleware/pubsub/server/index.js +34 -0
  84. package/dist/middleware/pubsub/server/index.js.map +1 -0
  85. package/dist/middleware/pubsub/server/webapi/index.d.ts +53 -0
  86. package/dist/middleware/pubsub/server/webapi/index.js +11 -0
  87. package/dist/middleware/pubsub/server/webapi/index.js.map +1 -0
  88. package/dist/ollama/index.d.ts +2 -1
  89. package/dist/ollama/index.js +48 -45
  90. package/dist/ollama/index.js.map +1 -1
  91. package/dist/openai/index.d.ts +2 -1
  92. package/dist/openai/index.js +319 -313
  93. package/dist/openai/index.js.map +1 -1
  94. package/dist/openrouter/index.d.ts +2 -1
  95. package/dist/openrouter/index.js +379 -383
  96. package/dist/openrouter/index.js.map +1 -1
  97. package/dist/proxy/index.d.ts +10 -914
  98. package/dist/proxy/index.js +275 -1007
  99. package/dist/proxy/index.js.map +1 -1
  100. package/dist/proxy/server/express/index.d.ts +161 -0
  101. package/dist/proxy/server/express/index.js +24 -0
  102. package/dist/proxy/server/express/index.js.map +1 -0
  103. package/dist/proxy/server/fastify/index.d.ts +162 -0
  104. package/dist/proxy/server/fastify/index.js +24 -0
  105. package/dist/proxy/server/fastify/index.js.map +1 -0
  106. package/dist/proxy/server/h3/index.d.ts +189 -0
  107. package/dist/proxy/server/h3/index.js +28 -0
  108. package/dist/proxy/server/h3/index.js.map +1 -0
  109. package/dist/proxy/server/index.d.ts +151 -0
  110. package/dist/proxy/server/index.js +48 -0
  111. package/dist/proxy/server/index.js.map +1 -0
  112. package/dist/proxy/server/webapi/index.d.ts +278 -0
  113. package/dist/proxy/server/webapi/index.js +32 -0
  114. package/dist/proxy/server/webapi/index.js.map +1 -0
  115. package/dist/responses/index.d.ts +650 -0
  116. package/dist/responses/index.js +930 -0
  117. package/dist/responses/index.js.map +1 -0
  118. package/dist/{retry-8Ch-WWgX.d.ts → retry-YayV42GV.d.ts} +1 -1
  119. package/dist/stream-CecfVCPO.d.ts +1632 -0
  120. package/dist/types-C8Gciizr.d.ts +168 -0
  121. package/dist/utils/index.d.ts +53 -0
  122. package/dist/utils/index.js +7 -0
  123. package/dist/utils/index.js.map +1 -0
  124. package/dist/xai/index.d.ts +2 -1
  125. package/dist/xai/index.js +310 -310
  126. package/dist/xai/index.js.map +1 -1
  127. package/package.json +94 -4
  128. package/dist/chunk-4J6OFUKX.js.map +0 -1
  129. package/dist/chunk-ILR2D5PN.js.map +0 -1
  130. package/dist/chunk-TOJCZMVU.js.map +0 -1
  131. package/dist/chunk-WAKD3OO5.js.map +0 -1
  132. /package/dist/{chunk-3D6XGGVG.js.map → chunk-ARVM24K2.js.map} +0 -0
  133. /package/dist/{chunk-KUPF5KHT.js.map → chunk-Y5H7C5J4.js.map} +0 -0
@@ -0,0 +1,168 @@
1
+ import { S as StreamEvent } from './stream-CecfVCPO.js';
2
+
3
+ /**
4
+ * @fileoverview Pub-sub middleware types for stream resumption.
5
+ *
6
+ * Defines interfaces for temporary stream storage, replay, and
7
+ * multi-client broadcast during active generation.
8
+ *
9
+ * @module middleware/pubsub/types
10
+ */
11
+
12
+ /**
13
+ * Stored stream state.
14
+ */
15
+ interface StoredStream {
16
+ readonly streamId: string;
17
+ readonly modelId: string;
18
+ readonly provider: string;
19
+ readonly createdAt: number;
20
+ readonly updatedAt: number;
21
+ readonly completed: boolean;
22
+ readonly events: readonly StreamEvent[];
23
+ }
24
+ /**
25
+ * Subscription callback for live events.
26
+ *
27
+ * @param event - Stream event payload
28
+ * @param cursor - Zero-based event index when adapter supports cursors
29
+ */
30
+ type SubscriptionCallback = (event: StreamEvent, cursor?: number) => void;
31
+ /**
32
+ * Unsubscribe function returned by subscribe.
33
+ */
34
+ type Unsubscribe = () => void;
35
+ /**
36
+ * Storage adapter interface for pub-sub middleware.
37
+ *
38
+ * Implement this interface for custom backends (Redis, etc.).
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * const redisAdapter: PubSubAdapter = {
43
+ * async create(streamId, metadata) {
44
+ * await redis.hset(`stream:${streamId}`, metadata);
45
+ * },
46
+ * // ... other methods
47
+ * };
48
+ * ```
49
+ */
50
+ interface PubSubAdapter {
51
+ /**
52
+ * Checks if a stream exists.
53
+ *
54
+ * @param streamId - Stream identifier to check
55
+ * @returns True if the stream exists
56
+ */
57
+ exists(streamId: string): Promise<boolean>;
58
+ /**
59
+ * Creates a stream entry.
60
+ *
61
+ * @param streamId - Unique stream identifier
62
+ * @param metadata - Stream metadata (modelId, provider)
63
+ */
64
+ create(streamId: string, metadata: {
65
+ modelId: string;
66
+ provider: string;
67
+ }): Promise<void>;
68
+ /**
69
+ * Appends an event to the stream.
70
+ *
71
+ * @param streamId - Stream to append to
72
+ * @param event - Stream event to store
73
+ */
74
+ append(streamId: string, event: StreamEvent): Promise<void>;
75
+ /**
76
+ * Marks stream as completed.
77
+ *
78
+ * @param streamId - Stream to mark complete
79
+ */
80
+ markCompleted(streamId: string): Promise<void>;
81
+ /**
82
+ * Checks if stream is completed.
83
+ *
84
+ * @param streamId - Stream to check
85
+ * @returns True if stream is completed
86
+ */
87
+ isCompleted(streamId: string): Promise<boolean>;
88
+ /**
89
+ * Fetches all events for replay.
90
+ *
91
+ * @param streamId - Stream to fetch events from
92
+ * @returns Array of events or null if stream doesn't exist
93
+ */
94
+ getEvents(streamId: string): Promise<StreamEvent[] | null>;
95
+ /**
96
+ * Gets stream metadata.
97
+ *
98
+ * @param streamId - Stream to get
99
+ * @returns Stream metadata or null if not found
100
+ */
101
+ getStream(streamId: string): Promise<StoredStream | null>;
102
+ /**
103
+ * Subscribes to live events for a stream.
104
+ *
105
+ * @param streamId - Stream to subscribe to
106
+ * @param callback - Function called for each new event
107
+ * @param callback.cursor - Zero-based index of the event when supported
108
+ * @returns Unsubscribe function
109
+ */
110
+ subscribe(streamId: string, callback: SubscriptionCallback): Unsubscribe;
111
+ /**
112
+ * Publishes event to all subscribers.
113
+ *
114
+ * @param streamId - Stream to publish to
115
+ * @param event - Event to broadcast
116
+ */
117
+ publish(streamId: string, event: StreamEvent): void;
118
+ /**
119
+ * Removes a stream (cleanup).
120
+ *
121
+ * @param streamId - Stream to remove
122
+ */
123
+ remove(streamId: string): Promise<void>;
124
+ /**
125
+ * Removes streams older than maxAge.
126
+ *
127
+ * @param maxAge - Maximum age in milliseconds
128
+ */
129
+ cleanup(maxAge: number): Promise<void>;
130
+ }
131
+ /**
132
+ * Options for pub-sub middleware.
133
+ */
134
+ interface PubSubOptions {
135
+ /**
136
+ * Storage adapter instance.
137
+ * @default memoryAdapter()
138
+ */
139
+ adapter?: PubSubAdapter;
140
+ /**
141
+ * Stream identifier for reconnection support.
142
+ *
143
+ * When provided:
144
+ * - If stream exists in adapter → Reconnection, replay buffered events
145
+ * - If stream doesn't exist → New request, create entry and proceed
146
+ *
147
+ * When not provided:
148
+ * - No pub/sub behavior, middleware is effectively disabled
149
+ */
150
+ streamId?: string;
151
+ /**
152
+ * TTL for stored streams in milliseconds.
153
+ * @default 600000 (10 minutes)
154
+ */
155
+ ttl?: number;
156
+ }
157
+ /**
158
+ * Options for memory adapter.
159
+ */
160
+ interface MemoryAdapterOptions {
161
+ /**
162
+ * Max streams to keep (LRU eviction).
163
+ * @default 1000
164
+ */
165
+ maxStreams?: number;
166
+ }
167
+
168
+ export type { MemoryAdapterOptions as M, PubSubAdapter as P, StoredStream as S, Unsubscribe as U, PubSubOptions as a, SubscriptionCallback as b };
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @fileoverview Partial JSON parser for streaming LLM responses.
3
+ *
4
+ * Enables incremental parsing of JSON data as it streams from LLM providers,
5
+ * allowing consumers to access usable partial objects during streaming rather
6
+ * than waiting for complete JSON.
7
+ *
8
+ * @module utils/partial-json
9
+ */
10
+ /**
11
+ * Result of parsing partial JSON.
12
+ *
13
+ * @typeParam T - The expected type of the parsed value
14
+ */
15
+ interface PartialParseResult<T = unknown> {
16
+ /** The parsed value, or undefined if parsing failed */
17
+ value: T | undefined;
18
+ /** Whether the JSON was complete and valid */
19
+ isComplete: boolean;
20
+ }
21
+ /**
22
+ * Parses potentially incomplete JSON, returning as much as can be extracted.
23
+ *
24
+ * Handles common incomplete states during streaming:
25
+ * - Incomplete strings: `{"name":"Jo` → `{name: "Jo"}`
26
+ * - Incomplete objects: `{"a":1,"b":` → `{a: 1}`
27
+ * - Incomplete arrays: `[1,2,` → `[1, 2]`
28
+ * - Incomplete numbers, booleans, null literals
29
+ * - Nested structures with partial completion
30
+ * - Unicode escape sequences
31
+ *
32
+ * @typeParam T - The expected type of the parsed value
33
+ * @param json - The potentially incomplete JSON string
34
+ * @returns A PartialParseResult with the parsed value and completion status
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * // Complete JSON
39
+ * parsePartialJson('{"name":"John"}');
40
+ * // => { value: { name: "John" }, isComplete: true }
41
+ *
42
+ * // Incomplete object
43
+ * parsePartialJson('{"user":{"firstName":"Jo');
44
+ * // => { value: { user: { firstName: "Jo" } }, isComplete: false }
45
+ *
46
+ * // Incomplete array
47
+ * parsePartialJson('[1, 2, 3');
48
+ * // => { value: [1, 2, 3], isComplete: false }
49
+ * ```
50
+ */
51
+ declare function parsePartialJson<T = unknown>(json: string): PartialParseResult<T>;
52
+
53
+ export { type PartialParseResult, parsePartialJson };
@@ -0,0 +1,7 @@
1
+ import {
2
+ parsePartialJson
3
+ } from "../chunk-I53CI6ZZ.js";
4
+ export {
5
+ parsePartialJson
6
+ };
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,4 +1,5 @@
1
- import { P as Provider } from '../llm-BQJZj3cD.js';
1
+ import { d as Provider } from '../llm-DwbUK7un.js';
2
+ import '../stream-CecfVCPO.js';
2
3
 
3
4
  /**
4
5
  * xAI Chat Completions API parameters (OpenAI-compatible).