@providerprotocol/ai 0.0.36 → 0.0.37
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.
- package/README.md +28 -0
- package/dist/anthropic/index.d.ts +2 -2
- package/dist/anthropic/index.js +12 -10
- package/dist/anthropic/index.js.map +1 -1
- package/dist/cerebras/index.d.ts +2 -2
- package/dist/cerebras/index.js +12 -10
- package/dist/cerebras/index.js.map +1 -1
- package/dist/{chunk-UFFJDYCE.js → chunk-7GTWHZY2.js} +2 -2
- package/dist/{chunk-OIEWDFQU.js → chunk-FYSZFIZS.js} +2 -2
- package/dist/chunk-GIDT7C6I.js +37 -0
- package/dist/chunk-GIDT7C6I.js.map +1 -0
- package/dist/{chunk-IDZOVWP3.js → chunk-IK6NRCW5.js} +7 -7
- package/dist/{chunk-VGKZIGVI.js → chunk-LTEMH3CI.js} +2 -2
- package/dist/{chunk-RJGTRQ47.js → chunk-MJI74VEJ.js} +6 -1
- package/dist/chunk-MJI74VEJ.js.map +1 -0
- package/dist/{chunk-AY55T37A.js → chunk-SBGZJVTJ.js} +4 -30
- package/dist/chunk-SBGZJVTJ.js.map +1 -0
- package/dist/{chunk-A2IM7PGT.js → chunk-TUTYMOBL.js} +2 -2
- package/dist/{chunk-BRP5XJ6Q.js → chunk-WU4U6IHF.js} +2 -2
- package/dist/chunk-WU4U6IHF.js.map +1 -0
- package/dist/{chunk-C4JP64VW.js → chunk-YQLR3XOA.js} +2 -2
- package/dist/chunk-ZKNPQBIE.js +265 -0
- package/dist/chunk-ZKNPQBIE.js.map +1 -0
- package/dist/{chunk-4OGB7JZA.js → chunk-ZRVNAET3.js} +2 -2
- package/dist/{embedding-BXA72PlJ.d.ts → embedding-CwZ1ZNWv.d.ts} +1 -1
- package/dist/google/index.d.ts +2 -2
- package/dist/google/index.js +12 -10
- package/dist/google/index.js.map +1 -1
- package/dist/groq/index.d.ts +2 -2
- package/dist/groq/index.js +12 -10
- package/dist/groq/index.js.map +1 -1
- package/dist/http/index.d.ts +3 -3
- package/dist/http/index.js +2 -1
- package/dist/{image-stream-CCgwB7ve.d.ts → image-stream-CeQHtjxS.d.ts} +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.js +86 -283
- package/dist/index.js.map +1 -1
- package/dist/{llm-ByUFPcFH.d.ts → llm-DS_-l71X.d.ts} +11 -3
- package/dist/middleware/logging/index.d.ts +2 -2
- package/dist/middleware/parsed-object/index.d.ts +2 -2
- package/dist/middleware/parsed-object/index.js +1 -1
- package/dist/middleware/persistence/index.d.ts +128 -0
- package/dist/middleware/persistence/index.js +144 -0
- package/dist/middleware/persistence/index.js.map +1 -0
- package/dist/middleware/pubsub/index.d.ts +4 -4
- package/dist/middleware/pubsub/server/express/index.d.ts +2 -2
- package/dist/middleware/pubsub/server/fastify/index.d.ts +2 -2
- package/dist/middleware/pubsub/server/h3/index.d.ts +2 -2
- package/dist/middleware/pubsub/server/index.d.ts +2 -2
- package/dist/middleware/pubsub/server/webapi/index.d.ts +2 -2
- package/dist/ollama/index.d.ts +2 -2
- package/dist/ollama/index.js +12 -10
- package/dist/ollama/index.js.map +1 -1
- package/dist/openai/index.d.ts +2 -2
- package/dist/openai/index.js +12 -10
- package/dist/openai/index.js.map +1 -1
- package/dist/openrouter/index.d.ts +2 -2
- package/dist/openrouter/index.js +12 -10
- package/dist/openrouter/index.js.map +1 -1
- package/dist/proxy/index.d.ts +4 -4
- package/dist/proxy/index.js +20 -18
- package/dist/proxy/index.js.map +1 -1
- package/dist/proxy/server/express/index.d.ts +4 -4
- package/dist/proxy/server/express/index.js +3 -3
- package/dist/proxy/server/fastify/index.d.ts +4 -4
- package/dist/proxy/server/fastify/index.js +3 -3
- package/dist/proxy/server/h3/index.d.ts +4 -4
- package/dist/proxy/server/h3/index.js +3 -3
- package/dist/proxy/server/index.d.ts +4 -4
- package/dist/proxy/server/index.js +9 -9
- package/dist/proxy/server/webapi/index.d.ts +4 -4
- package/dist/proxy/server/webapi/index.js +3 -3
- package/dist/responses/index.d.ts +2 -2
- package/dist/responses/index.js +12 -10
- package/dist/responses/index.js.map +1 -1
- package/dist/{retry-BDMo4AVu.d.ts → retry-CgoBNa51.d.ts} +1 -1
- package/dist/{stream-S7nwQRqM.d.ts → stream-sXhBtWjl.d.ts} +4 -0
- package/dist/{types-CE4B7pno.d.ts → types-Cr4F0tVy.d.ts} +1 -1
- package/dist/xai/index.d.ts +2 -2
- package/dist/xai/index.js +12 -10
- package/dist/xai/index.js.map +1 -1
- package/package.json +6 -1
- package/dist/chunk-AY55T37A.js.map +0 -1
- package/dist/chunk-BRP5XJ6Q.js.map +0 -1
- package/dist/chunk-RJGTRQ47.js.map +0 -1
- /package/dist/{chunk-UFFJDYCE.js.map → chunk-7GTWHZY2.js.map} +0 -0
- /package/dist/{chunk-OIEWDFQU.js.map → chunk-FYSZFIZS.js.map} +0 -0
- /package/dist/{chunk-IDZOVWP3.js.map → chunk-IK6NRCW5.js.map} +0 -0
- /package/dist/{chunk-VGKZIGVI.js.map → chunk-LTEMH3CI.js.map} +0 -0
- /package/dist/{chunk-A2IM7PGT.js.map → chunk-TUTYMOBL.js.map} +0 -0
- /package/dist/{chunk-C4JP64VW.js.map → chunk-YQLR3XOA.js.map} +0 -0
- /package/dist/{chunk-4OGB7JZA.js.map → chunk-ZRVNAET3.js.map} +0 -0
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AssistantMessage,
|
|
3
|
+
ToolResultMessage,
|
|
4
|
+
UserMessage,
|
|
5
|
+
generateId
|
|
6
|
+
} from "./chunk-WU4U6IHF.js";
|
|
7
|
+
|
|
8
|
+
// src/types/thread.ts
|
|
9
|
+
var Thread = class _Thread {
|
|
10
|
+
/** Unique thread identifier */
|
|
11
|
+
id;
|
|
12
|
+
/** Internal message storage */
|
|
13
|
+
_messages;
|
|
14
|
+
/** Creation timestamp */
|
|
15
|
+
_createdAt;
|
|
16
|
+
/** Last update timestamp */
|
|
17
|
+
_updatedAt;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new thread instance.
|
|
20
|
+
*
|
|
21
|
+
* @param messages - Optional initial messages to populate the thread
|
|
22
|
+
*/
|
|
23
|
+
constructor(messages) {
|
|
24
|
+
this.id = generateId();
|
|
25
|
+
this._messages = messages ? [...messages] : [];
|
|
26
|
+
this._createdAt = /* @__PURE__ */ new Date();
|
|
27
|
+
this._updatedAt = /* @__PURE__ */ new Date();
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* All messages in the thread (readonly).
|
|
31
|
+
*/
|
|
32
|
+
get messages() {
|
|
33
|
+
return this._messages;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Number of messages in the thread.
|
|
37
|
+
*/
|
|
38
|
+
get length() {
|
|
39
|
+
return this._messages.length;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Appends all messages from a Turn to the thread.
|
|
43
|
+
*
|
|
44
|
+
* @param turn - The Turn containing messages to append
|
|
45
|
+
* @returns This thread instance for chaining
|
|
46
|
+
*/
|
|
47
|
+
append(turn) {
|
|
48
|
+
this._messages.push(...turn.messages);
|
|
49
|
+
this._updatedAt = /* @__PURE__ */ new Date();
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Adds raw messages to the thread.
|
|
54
|
+
*
|
|
55
|
+
* @param messages - Messages to add
|
|
56
|
+
* @returns This thread instance for chaining
|
|
57
|
+
*/
|
|
58
|
+
push(...messages) {
|
|
59
|
+
this._messages.push(...messages);
|
|
60
|
+
this._updatedAt = /* @__PURE__ */ new Date();
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Adds a user message to the thread.
|
|
65
|
+
*
|
|
66
|
+
* @param content - String or array of content blocks
|
|
67
|
+
* @returns This thread instance for chaining
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* thread.user('Hello, world!');
|
|
72
|
+
* thread.user([
|
|
73
|
+
* { type: 'text', text: 'Describe this image:' },
|
|
74
|
+
* { type: 'image', source: { type: 'url', url: '...' }, mimeType: 'image/png' }
|
|
75
|
+
* ]);
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
user(content) {
|
|
79
|
+
this._messages.push(new UserMessage(content));
|
|
80
|
+
this._updatedAt = /* @__PURE__ */ new Date();
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Adds an assistant message to the thread.
|
|
85
|
+
*
|
|
86
|
+
* @param content - String or array of content blocks
|
|
87
|
+
* @returns This thread instance for chaining
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* thread.assistant('I can help with that!');
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
assistant(content) {
|
|
95
|
+
this._messages.push(new AssistantMessage(content));
|
|
96
|
+
this._updatedAt = /* @__PURE__ */ new Date();
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Filters messages by type.
|
|
101
|
+
*
|
|
102
|
+
* @param type - The message type to filter by
|
|
103
|
+
* @returns Array of messages matching the type
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* const userMessages = thread.filter('user');
|
|
108
|
+
* const assistantMessages = thread.filter('assistant');
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
filter(type) {
|
|
112
|
+
return this._messages.filter((m) => m.type === type);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Returns the last N messages from the thread.
|
|
116
|
+
*
|
|
117
|
+
* @param count - Number of messages to return
|
|
118
|
+
* @returns Array of the last N messages
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* const recent = thread.tail(5);
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
tail(count) {
|
|
126
|
+
return this._messages.slice(-count);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Creates a new thread with a subset of messages.
|
|
130
|
+
*
|
|
131
|
+
* @param start - Start index (inclusive)
|
|
132
|
+
* @param end - End index (exclusive)
|
|
133
|
+
* @returns New Thread containing the sliced messages
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```typescript
|
|
137
|
+
* const subset = thread.slice(0, 10);
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
slice(start, end) {
|
|
141
|
+
return new _Thread(this._messages.slice(start, end));
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Removes all messages from the thread.
|
|
145
|
+
*
|
|
146
|
+
* @returns This thread instance for chaining
|
|
147
|
+
*/
|
|
148
|
+
clear() {
|
|
149
|
+
this._messages = [];
|
|
150
|
+
this._updatedAt = /* @__PURE__ */ new Date();
|
|
151
|
+
return this;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Converts the thread to a plain message array.
|
|
155
|
+
*
|
|
156
|
+
* @returns Copy of the internal message array
|
|
157
|
+
*/
|
|
158
|
+
toMessages() {
|
|
159
|
+
return [...this._messages];
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Serializes the thread to JSON format.
|
|
163
|
+
*
|
|
164
|
+
* @returns JSON-serializable representation of the thread
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```typescript
|
|
168
|
+
* const json = thread.toJSON();
|
|
169
|
+
* localStorage.setItem('thread', JSON.stringify(json));
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
toJSON() {
|
|
173
|
+
return {
|
|
174
|
+
id: this.id,
|
|
175
|
+
messages: this._messages.map((m) => this.messageToJSON(m)),
|
|
176
|
+
createdAt: this._createdAt.toISOString(),
|
|
177
|
+
updatedAt: this._updatedAt.toISOString()
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Deserializes a thread from JSON format.
|
|
182
|
+
*
|
|
183
|
+
* @param json - The JSON representation to deserialize
|
|
184
|
+
* @returns Reconstructed Thread instance
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```typescript
|
|
188
|
+
* const json = JSON.parse(localStorage.getItem('thread'));
|
|
189
|
+
* const thread = Thread.fromJSON(json);
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
static fromJSON(json) {
|
|
193
|
+
const messages = json.messages.map((m) => _Thread.messageFromJSON(m));
|
|
194
|
+
const thread = new _Thread(messages);
|
|
195
|
+
thread.id = json.id;
|
|
196
|
+
thread._createdAt = new Date(json.createdAt);
|
|
197
|
+
thread._updatedAt = new Date(json.updatedAt);
|
|
198
|
+
return thread;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Enables iteration over messages with for...of loops.
|
|
202
|
+
*
|
|
203
|
+
* @returns Iterator over the thread's messages
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```typescript
|
|
207
|
+
* for (const message of thread) {
|
|
208
|
+
* console.log(message.text);
|
|
209
|
+
* }
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
[Symbol.iterator]() {
|
|
213
|
+
return this._messages[Symbol.iterator]();
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Converts a message to JSON format.
|
|
217
|
+
*/
|
|
218
|
+
messageToJSON(m) {
|
|
219
|
+
const base = {
|
|
220
|
+
id: m.id,
|
|
221
|
+
type: m.type,
|
|
222
|
+
content: [],
|
|
223
|
+
metadata: m.metadata,
|
|
224
|
+
timestamp: m.timestamp.toISOString()
|
|
225
|
+
};
|
|
226
|
+
if (m instanceof UserMessage) {
|
|
227
|
+
base.content = m.content;
|
|
228
|
+
} else if (m instanceof AssistantMessage) {
|
|
229
|
+
base.content = m.content;
|
|
230
|
+
base.toolCalls = m.toolCalls;
|
|
231
|
+
} else if (m instanceof ToolResultMessage) {
|
|
232
|
+
base.results = m.results;
|
|
233
|
+
}
|
|
234
|
+
return base;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Reconstructs a message from JSON format.
|
|
238
|
+
*/
|
|
239
|
+
static messageFromJSON(json) {
|
|
240
|
+
const options = {
|
|
241
|
+
id: json.id,
|
|
242
|
+
metadata: json.metadata,
|
|
243
|
+
timestamp: new Date(json.timestamp)
|
|
244
|
+
};
|
|
245
|
+
switch (json.type) {
|
|
246
|
+
case "user":
|
|
247
|
+
return new UserMessage(json.content, options);
|
|
248
|
+
case "assistant":
|
|
249
|
+
return new AssistantMessage(
|
|
250
|
+
json.content,
|
|
251
|
+
json.toolCalls,
|
|
252
|
+
options
|
|
253
|
+
);
|
|
254
|
+
case "tool_result":
|
|
255
|
+
return new ToolResultMessage(json.results ?? [], options);
|
|
256
|
+
default:
|
|
257
|
+
throw new Error(`Unknown message type: ${json.type}`);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
export {
|
|
263
|
+
Thread
|
|
264
|
+
};
|
|
265
|
+
//# sourceMappingURL=chunk-ZKNPQBIE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types/thread.ts"],"sourcesContent":["/**\n * @fileoverview Thread class for managing conversation history.\n *\n * Provides a utility class for building and manipulating conversation\n * message sequences, with support for serialization and deserialization.\n *\n * @module types/thread\n */\n\nimport { generateId } from '../utils/id.ts';\nimport {\n Message,\n UserMessage,\n AssistantMessage,\n ToolResultMessage,\n type MessageJSON,\n type MessageType,\n} from './messages.ts';\nimport type { UserContent, AssistantContent } from './content.ts';\nimport type { Turn } from './turn.ts';\n\n/**\n * Thread serialized to JSON format.\n * Picks id from Thread, converts dates to strings.\n */\nexport type ThreadJSON = Pick<Thread, 'id'> & {\n messages: MessageJSON[];\n createdAt: string;\n updatedAt: string;\n};\n\n/**\n * Thread - A utility class for managing conversation history.\n *\n * Provides methods for building, manipulating, and persisting\n * conversation message sequences. This class is optional; users\n * can also manage their own `Message[]` arrays directly.\n *\n * @example\n * ```typescript\n * // Create a new thread and add messages\n * const thread = new Thread();\n * thread.user('Hello!');\n * thread.assistant('Hi there! How can I help?');\n *\n * // Use with LLM inference\n * const turn = await instance.generate(thread, 'What is 2+2?');\n * thread.append(turn);\n *\n * // Serialize for storage\n * const json = thread.toJSON();\n * localStorage.setItem('chat', JSON.stringify(json));\n *\n * // Restore from storage\n * const restored = Thread.fromJSON(JSON.parse(localStorage.getItem('chat')));\n * ```\n */\nexport class Thread {\n /** Unique thread identifier */\n readonly id: string;\n\n /** Internal message storage */\n private _messages: Message[];\n\n /** Creation timestamp */\n private _createdAt: Date;\n\n /** Last update timestamp */\n private _updatedAt: Date;\n\n /**\n * Creates a new thread instance.\n *\n * @param messages - Optional initial messages to populate the thread\n */\n constructor(messages?: Message[]) {\n this.id = generateId();\n this._messages = messages ? [...messages] : [];\n this._createdAt = new Date();\n this._updatedAt = new Date();\n }\n\n /**\n * All messages in the thread (readonly).\n */\n get messages(): readonly Message[] {\n return this._messages;\n }\n\n /**\n * Number of messages in the thread.\n */\n get length(): number {\n return this._messages.length;\n }\n\n /**\n * Appends all messages from a Turn to the thread.\n *\n * @param turn - The Turn containing messages to append\n * @returns This thread instance for chaining\n */\n append(turn: Turn): this {\n this._messages.push(...turn.messages);\n this._updatedAt = new Date();\n return this;\n }\n\n /**\n * Adds raw messages to the thread.\n *\n * @param messages - Messages to add\n * @returns This thread instance for chaining\n */\n push(...messages: Message[]): this {\n this._messages.push(...messages);\n this._updatedAt = new Date();\n return this;\n }\n\n /**\n * Adds a user message to the thread.\n *\n * @param content - String or array of content blocks\n * @returns This thread instance for chaining\n *\n * @example\n * ```typescript\n * thread.user('Hello, world!');\n * thread.user([\n * { type: 'text', text: 'Describe this image:' },\n * { type: 'image', source: { type: 'url', url: '...' }, mimeType: 'image/png' }\n * ]);\n * ```\n */\n user(content: string | UserContent[]): this {\n this._messages.push(new UserMessage(content));\n this._updatedAt = new Date();\n return this;\n }\n\n /**\n * Adds an assistant message to the thread.\n *\n * @param content - String or array of content blocks\n * @returns This thread instance for chaining\n *\n * @example\n * ```typescript\n * thread.assistant('I can help with that!');\n * ```\n */\n assistant(content: string | AssistantContent[]): this {\n this._messages.push(new AssistantMessage(content));\n this._updatedAt = new Date();\n return this;\n }\n\n /**\n * Filters messages by type.\n *\n * @param type - The message type to filter by\n * @returns Array of messages matching the type\n *\n * @example\n * ```typescript\n * const userMessages = thread.filter('user');\n * const assistantMessages = thread.filter('assistant');\n * ```\n */\n filter(type: MessageType): Message[] {\n return this._messages.filter((m) => m.type === type);\n }\n\n /**\n * Returns the last N messages from the thread.\n *\n * @param count - Number of messages to return\n * @returns Array of the last N messages\n *\n * @example\n * ```typescript\n * const recent = thread.tail(5);\n * ```\n */\n tail(count: number): Message[] {\n return this._messages.slice(-count);\n }\n\n /**\n * Creates a new thread with a subset of messages.\n *\n * @param start - Start index (inclusive)\n * @param end - End index (exclusive)\n * @returns New Thread containing the sliced messages\n *\n * @example\n * ```typescript\n * const subset = thread.slice(0, 10);\n * ```\n */\n slice(start?: number, end?: number): Thread {\n return new Thread(this._messages.slice(start, end));\n }\n\n /**\n * Removes all messages from the thread.\n *\n * @returns This thread instance for chaining\n */\n clear(): this {\n this._messages = [];\n this._updatedAt = new Date();\n return this;\n }\n\n /**\n * Converts the thread to a plain message array.\n *\n * @returns Copy of the internal message array\n */\n toMessages(): Message[] {\n return [...this._messages];\n }\n\n /**\n * Serializes the thread to JSON format.\n *\n * @returns JSON-serializable representation of the thread\n *\n * @example\n * ```typescript\n * const json = thread.toJSON();\n * localStorage.setItem('thread', JSON.stringify(json));\n * ```\n */\n toJSON(): ThreadJSON {\n return {\n id: this.id,\n messages: this._messages.map((m) => this.messageToJSON(m)),\n createdAt: this._createdAt.toISOString(),\n updatedAt: this._updatedAt.toISOString(),\n };\n }\n\n /**\n * Deserializes a thread from JSON format.\n *\n * @param json - The JSON representation to deserialize\n * @returns Reconstructed Thread instance\n *\n * @example\n * ```typescript\n * const json = JSON.parse(localStorage.getItem('thread'));\n * const thread = Thread.fromJSON(json);\n * ```\n */\n static fromJSON(json: ThreadJSON): Thread {\n const messages = json.messages.map((m) => Thread.messageFromJSON(m));\n const thread = new Thread(messages);\n (thread as { id: string }).id = json.id;\n thread._createdAt = new Date(json.createdAt);\n thread._updatedAt = new Date(json.updatedAt);\n return thread;\n }\n\n /**\n * Enables iteration over messages with for...of loops.\n *\n * @returns Iterator over the thread's messages\n *\n * @example\n * ```typescript\n * for (const message of thread) {\n * console.log(message.text);\n * }\n * ```\n */\n [Symbol.iterator](): Iterator<Message> {\n return this._messages[Symbol.iterator]();\n }\n\n /**\n * Converts a message to JSON format.\n */\n private messageToJSON(m: Message): MessageJSON {\n const base: MessageJSON = {\n id: m.id,\n type: m.type,\n content: [],\n metadata: m.metadata,\n timestamp: m.timestamp.toISOString(),\n };\n\n if (m instanceof UserMessage) {\n base.content = m.content;\n } else if (m instanceof AssistantMessage) {\n base.content = m.content;\n base.toolCalls = m.toolCalls;\n } else if (m instanceof ToolResultMessage) {\n base.results = m.results;\n }\n\n return base;\n }\n\n /**\n * Reconstructs a message from JSON format.\n */\n private static messageFromJSON(json: MessageJSON): Message {\n const options = {\n id: json.id,\n metadata: json.metadata,\n timestamp: new Date(json.timestamp),\n };\n\n switch (json.type) {\n case 'user':\n return new UserMessage(json.content as UserContent[], options);\n case 'assistant':\n return new AssistantMessage(\n json.content as AssistantContent[],\n json.toolCalls,\n options\n );\n case 'tool_result':\n return new ToolResultMessage(json.results ?? [], options);\n default:\n throw new Error(`Unknown message type: ${json.type}`);\n }\n }\n}\n"],"mappings":";;;;;;;;AAyDO,IAAM,SAAN,MAAM,QAAO;AAAA;AAAA,EAET;AAAA;AAAA,EAGD;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOR,YAAY,UAAsB;AAChC,SAAK,KAAK,WAAW;AACrB,SAAK,YAAY,WAAW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,IAAuB;AACrC,WAAO,KAAK,UAAU,OAAO,QAAQ,EAAE;AAAA,EACzC;AAAA;AAAA;AAAA;AAAA,EAKQ,cAAc,GAAyB;AAC7C,UAAM,OAAoB;AAAA,MACxB,IAAI,EAAE;AAAA,MACN,MAAM,EAAE;AAAA,MACR,SAAS,CAAC;AAAA,MACV,UAAU,EAAE;AAAA,MACZ,WAAW,EAAE,UAAU,YAAY;AAAA,IACrC;AAEA,QAAI,aAAa,aAAa;AAC5B,WAAK,UAAU,EAAE;AAAA,IACnB,WAAW,aAAa,kBAAkB;AACxC,WAAK,UAAU,EAAE;AACjB,WAAK,YAAY,EAAE;AAAA,IACrB,WAAW,aAAa,mBAAmB;AACzC,WAAK,UAAU,EAAE;AAAA,IACnB;AAEA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,OAAe,gBAAgB,MAA4B;AACzD,UAAM,UAAU;AAAA,MACd,IAAI,KAAK;AAAA,MACT,UAAU,KAAK;AAAA,MACf,WAAW,IAAI,KAAK,KAAK,SAAS;AAAA,IACpC;AAEA,YAAQ,KAAK,MAAM;AAAA,MACjB,KAAK;AACH,eAAO,IAAI,YAAY,KAAK,SAA0B,OAAO;AAAA,MAC/D,KAAK;AACH,eAAO,IAAI;AAAA,UACT,KAAK;AAAA,UACL,KAAK;AAAA,UACL;AAAA,QACF;AAAA,MACF,KAAK;AACH,eAAO,IAAI,kBAAkB,KAAK,WAAW,CAAC,GAAG,OAAO;AAAA,MAC1D;AACE,cAAM,IAAI,MAAM,yBAAyB,KAAK,IAAI,EAAE;AAAA,IACxD;AAAA,EACF;AACF;","names":[]}
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
serializeImageStreamEvent,
|
|
5
5
|
serializeStreamEvent,
|
|
6
6
|
serializeTurn
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-YQLR3XOA.js";
|
|
8
8
|
|
|
9
9
|
// src/providers/proxy/server/h3.ts
|
|
10
10
|
function sendJSON(turn, event) {
|
|
@@ -154,4 +154,4 @@ export {
|
|
|
154
154
|
sendError,
|
|
155
155
|
h3
|
|
156
156
|
};
|
|
157
|
-
//# sourceMappingURL=chunk-
|
|
157
|
+
//# sourceMappingURL=chunk-ZRVNAET3.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { P as ProviderIdentity,
|
|
1
|
+
import { P as ProviderIdentity, c as ProviderConfig, M as Middleware, E as EmbeddingInput, d as EmbeddingUsage, B as BoundEmbeddingModel } from './llm-DS_-l71X.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @fileoverview Embedding types for vector embedding generation.
|
package/dist/google/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '../stream-
|
|
1
|
+
import { c as ProviderConfig, e as Provider } from '../llm-DS_-l71X.js';
|
|
2
|
+
import '../stream-sXhBtWjl.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Provider-specific parameters for Google Gemini API requests.
|
package/dist/google/index.js
CHANGED
|
@@ -6,34 +6,36 @@ import {
|
|
|
6
6
|
} from "../chunk-PMK5LZ5Z.js";
|
|
7
7
|
import {
|
|
8
8
|
parseJsonResponse
|
|
9
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-TUTYMOBL.js";
|
|
10
10
|
import {
|
|
11
11
|
resolveApiKey
|
|
12
12
|
} from "../chunk-ARVM24K2.js";
|
|
13
13
|
import {
|
|
14
14
|
createProvider
|
|
15
15
|
} from "../chunk-JA3UZALR.js";
|
|
16
|
+
import {
|
|
17
|
+
doFetch,
|
|
18
|
+
doStreamFetch,
|
|
19
|
+
normalizeHttpError
|
|
20
|
+
} from "../chunk-SBGZJVTJ.js";
|
|
21
|
+
import {
|
|
22
|
+
StreamEventType,
|
|
23
|
+
objectDelta
|
|
24
|
+
} from "../chunk-MJI74VEJ.js";
|
|
16
25
|
import {
|
|
17
26
|
AssistantMessage,
|
|
18
27
|
isAssistantMessage,
|
|
19
28
|
isToolResultMessage,
|
|
20
29
|
isUserMessage
|
|
21
|
-
} from "../chunk-
|
|
30
|
+
} from "../chunk-WU4U6IHF.js";
|
|
22
31
|
import {
|
|
23
|
-
doFetch,
|
|
24
|
-
doStreamFetch,
|
|
25
|
-
normalizeHttpError,
|
|
26
32
|
toError
|
|
27
|
-
} from "../chunk-
|
|
33
|
+
} from "../chunk-GIDT7C6I.js";
|
|
28
34
|
import {
|
|
29
35
|
ErrorCode,
|
|
30
36
|
ModalityType,
|
|
31
37
|
UPPError
|
|
32
38
|
} from "../chunk-COS4ON4G.js";
|
|
33
|
-
import {
|
|
34
|
-
StreamEventType,
|
|
35
|
-
objectDelta
|
|
36
|
-
} from "../chunk-RJGTRQ47.js";
|
|
37
39
|
|
|
38
40
|
// src/providers/google/transform.ts
|
|
39
41
|
function normalizeSystem(system) {
|