@absolutejs/ai 0.0.1
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 +6 -0
- package/dist/ai/client/index.js +682 -0
- package/dist/ai/client/index.js.map +15 -0
- package/dist/ai/index.js +3317 -0
- package/dist/ai/index.js.map +28 -0
- package/dist/ai/providers/anthropic.js +371 -0
- package/dist/ai/providers/anthropic.js.map +10 -0
- package/dist/ai/providers/gemini.js +260 -0
- package/dist/ai/providers/gemini.js.map +10 -0
- package/dist/ai/providers/ollama.js +221 -0
- package/dist/ai/providers/ollama.js.map +10 -0
- package/dist/ai/providers/openai.js +322 -0
- package/dist/ai/providers/openai.js.map +10 -0
- package/dist/ai/providers/openaiCompatible.js +360 -0
- package/dist/ai/providers/openaiCompatible.js.map +11 -0
- package/dist/ai/providers/openaiResponses.js +381 -0
- package/dist/ai/providers/openaiResponses.js.map +10 -0
- package/dist/src/ai/client/actions.d.ts +186 -0
- package/dist/src/ai/client/connection.d.ts +9 -0
- package/dist/src/ai/client/createAIStream.d.ts +12 -0
- package/dist/src/ai/client/index.d.ts +4 -0
- package/dist/src/ai/client/messageStore.d.ts +12 -0
- package/dist/src/ai/conversationManager.d.ts +19 -0
- package/dist/src/ai/htmxRenderers.d.ts +3 -0
- package/dist/src/ai/index.d.ts +19 -0
- package/dist/src/ai/memoryStore.d.ts +2 -0
- package/dist/src/ai/protocol.d.ts +4 -0
- package/dist/src/ai/providers/anthropic.d.ts +3 -0
- package/dist/src/ai/providers/gemini.d.ts +8 -0
- package/dist/src/ai/providers/ollama.d.ts +6 -0
- package/dist/src/ai/providers/openai.d.ts +7 -0
- package/dist/src/ai/providers/openaiCompatible.d.ts +30 -0
- package/dist/src/ai/providers/openaiResponses.d.ts +33 -0
- package/dist/src/ai/streamAI.d.ts +2 -0
- package/dist/src/ai/streamAIToSSE.d.ts +6 -0
- package/dist/src/constants.d.ts +60 -0
- package/dist/src/plugins/aiChat.d.ts +239 -0
- package/dist/types/ai.d.ts +4773 -0
- package/dist/types/anthropic.d.ts +20 -0
- package/dist/types/session.d.ts +16 -0
- package/dist/types/typeGuards.d.ts +3 -0
- package/package.json +59 -0
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/ai/providers/openaiResponses.ts
|
|
3
|
+
var DEFAULT_BASE_URL = "https://api.openai.com";
|
|
4
|
+
var EVENT_PREFIX_LENGTH = 7;
|
|
5
|
+
var DATA_PREFIX_LENGTH = 6;
|
|
6
|
+
var isRecord = (value) => typeof value === "object" && value !== null;
|
|
7
|
+
var isRecordArray = (value) => Array.isArray(value) && value.length > 0 && isRecord(value[0]);
|
|
8
|
+
var mapBlockToResponsesFormat = (block) => {
|
|
9
|
+
if (block.type === "text") {
|
|
10
|
+
return { text: block.content, type: "input_text" };
|
|
11
|
+
}
|
|
12
|
+
if (block.type === "image") {
|
|
13
|
+
return {
|
|
14
|
+
image_url: {
|
|
15
|
+
url: `data:${block.source.media_type};base64,${block.source.data}`
|
|
16
|
+
},
|
|
17
|
+
type: "input_image"
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
if (block.type === "document") {
|
|
21
|
+
return {
|
|
22
|
+
file: {
|
|
23
|
+
file_data: `data:${block.source.media_type};base64,${block.source.data}`,
|
|
24
|
+
filename: block.name ?? "document.pdf"
|
|
25
|
+
},
|
|
26
|
+
type: "input_file"
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
};
|
|
31
|
+
var mapContentToResponsesFormat = (content) => {
|
|
32
|
+
if (typeof content === "string") {
|
|
33
|
+
return content;
|
|
34
|
+
}
|
|
35
|
+
const parts = content.map(mapBlockToResponsesFormat).filter((mapped) => mapped !== null);
|
|
36
|
+
return parts.length > 0 ? parts : "";
|
|
37
|
+
};
|
|
38
|
+
var hasToolBlocks = (content) => content.some((block) => block.type === "tool_use" || block.type === "tool_result");
|
|
39
|
+
var convertToolBlock = (block) => {
|
|
40
|
+
if (block.type === "tool_use") {
|
|
41
|
+
return {
|
|
42
|
+
arguments: typeof block.input === "string" ? block.input : JSON.stringify(block.input),
|
|
43
|
+
call_id: block.id,
|
|
44
|
+
name: block.name,
|
|
45
|
+
type: "function_call"
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
if (block.type === "tool_result") {
|
|
49
|
+
return {
|
|
50
|
+
call_id: block.tool_use_id,
|
|
51
|
+
output: typeof block.content === "string" ? block.content : "",
|
|
52
|
+
type: "function_call_output"
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
};
|
|
57
|
+
var convertToolBlocks = (content) => content.map(convertToolBlock).filter((converted) => converted !== null);
|
|
58
|
+
var convertMessage = (msg) => {
|
|
59
|
+
if (typeof msg.content !== "string" && Array.isArray(msg.content) && hasToolBlocks(msg.content)) {
|
|
60
|
+
return convertToolBlocks(msg.content);
|
|
61
|
+
}
|
|
62
|
+
const content = mapContentToResponsesFormat(msg.content);
|
|
63
|
+
return [
|
|
64
|
+
{
|
|
65
|
+
content,
|
|
66
|
+
role: msg.role === "system" ? "developer" : msg.role,
|
|
67
|
+
type: "message"
|
|
68
|
+
}
|
|
69
|
+
];
|
|
70
|
+
};
|
|
71
|
+
var buildInput = (messages) => {
|
|
72
|
+
const input = [];
|
|
73
|
+
for (const msg of messages) {
|
|
74
|
+
input.push(...convertMessage(msg));
|
|
75
|
+
}
|
|
76
|
+
return input;
|
|
77
|
+
};
|
|
78
|
+
var mapToolDefinition = (tool) => ({
|
|
79
|
+
description: tool.description,
|
|
80
|
+
name: tool.name,
|
|
81
|
+
parameters: tool.input_schema,
|
|
82
|
+
type: "function"
|
|
83
|
+
});
|
|
84
|
+
var buildTools = (tools, isImageModel) => {
|
|
85
|
+
const mapped = tools ? tools.map(mapToolDefinition) : [];
|
|
86
|
+
const result = [...mapped];
|
|
87
|
+
if (isImageModel) {
|
|
88
|
+
result.push({ type: "image_generation" });
|
|
89
|
+
}
|
|
90
|
+
return result.length > 0 ? result : undefined;
|
|
91
|
+
};
|
|
92
|
+
var buildRequestBody = (params, isImageModel) => {
|
|
93
|
+
const body = {
|
|
94
|
+
input: buildInput(params.messages),
|
|
95
|
+
model: params.model,
|
|
96
|
+
stream: true
|
|
97
|
+
};
|
|
98
|
+
if (params.systemPrompt) {
|
|
99
|
+
body.instructions = params.systemPrompt;
|
|
100
|
+
}
|
|
101
|
+
const tools = buildTools(params.tools, isImageModel);
|
|
102
|
+
if (tools) {
|
|
103
|
+
body.tools = tools;
|
|
104
|
+
}
|
|
105
|
+
if (params.thinking) {
|
|
106
|
+
body.reasoning = {
|
|
107
|
+
effort: "high",
|
|
108
|
+
summary: "auto"
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
return body;
|
|
112
|
+
};
|
|
113
|
+
var parseJSON = (data) => {
|
|
114
|
+
try {
|
|
115
|
+
return JSON.parse(data);
|
|
116
|
+
} catch {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
var parseToolInput = (rawArguments) => {
|
|
121
|
+
try {
|
|
122
|
+
return JSON.parse(rawArguments);
|
|
123
|
+
} catch {
|
|
124
|
+
return rawArguments;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
var extractUsage = (response) => {
|
|
128
|
+
if (!isRecord(response.usage)) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const { usage } = response;
|
|
132
|
+
return {
|
|
133
|
+
inputTokens: typeof usage.input_tokens === "number" ? usage.input_tokens : 0,
|
|
134
|
+
outputTokens: typeof usage.output_tokens === "number" ? usage.output_tokens : 0
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
var extractMimeFormat = (mimeType) => {
|
|
138
|
+
if (typeof mimeType !== "string") {
|
|
139
|
+
return "png";
|
|
140
|
+
}
|
|
141
|
+
if (mimeType.includes("jpeg"))
|
|
142
|
+
return "jpeg";
|
|
143
|
+
if (mimeType.includes("webp"))
|
|
144
|
+
return "webp";
|
|
145
|
+
return "png";
|
|
146
|
+
};
|
|
147
|
+
var processTextDelta = function* (parsed) {
|
|
148
|
+
if (typeof parsed.delta === "string") {
|
|
149
|
+
yield { content: parsed.delta, type: "text" };
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
var processPartialImage = function* (parsed) {
|
|
153
|
+
const itemId = typeof parsed.item_id === "string" ? parsed.item_id : undefined;
|
|
154
|
+
const b64 = typeof parsed.partial_image_b64 === "string" ? parsed.partial_image_b64 : undefined;
|
|
155
|
+
if (b64) {
|
|
156
|
+
yield {
|
|
157
|
+
data: b64,
|
|
158
|
+
format: "png",
|
|
159
|
+
imageId: itemId,
|
|
160
|
+
isPartial: true,
|
|
161
|
+
type: "image"
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
var processFunctionCallArgumentsDelta = (parsed, pendingCalls) => {
|
|
166
|
+
const itemId = typeof parsed.item_id === "string" ? parsed.item_id : "";
|
|
167
|
+
const callId = typeof parsed.call_id === "string" ? parsed.call_id : "";
|
|
168
|
+
const delta = typeof parsed.arguments_delta === "string" ? parsed.arguments_delta : "";
|
|
169
|
+
const existing = pendingCalls.get(itemId);
|
|
170
|
+
if (existing) {
|
|
171
|
+
existing.arguments += delta;
|
|
172
|
+
} else {
|
|
173
|
+
pendingCalls.set(itemId, {
|
|
174
|
+
arguments: delta,
|
|
175
|
+
callId,
|
|
176
|
+
name: ""
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
var processFunctionCallArgumentsDone = function* (parsed, pendingCalls) {
|
|
181
|
+
const itemId = typeof parsed.item_id === "string" ? parsed.item_id : "";
|
|
182
|
+
const callId = typeof parsed.call_id === "string" ? parsed.call_id : "";
|
|
183
|
+
const fullArgs = typeof parsed.arguments === "string" ? parsed.arguments : "";
|
|
184
|
+
const pending = pendingCalls.get(itemId);
|
|
185
|
+
const name = pending?.name ?? "";
|
|
186
|
+
const args = fullArgs || pending?.arguments || "";
|
|
187
|
+
pendingCalls.delete(itemId);
|
|
188
|
+
yield {
|
|
189
|
+
id: callId || pending?.callId || itemId,
|
|
190
|
+
input: parseToolInput(args),
|
|
191
|
+
name,
|
|
192
|
+
type: "tool_use"
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
var processOutputItemAdded = (parsed, pendingCalls) => {
|
|
196
|
+
if (!isRecord(parsed.item)) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const { item } = parsed;
|
|
200
|
+
const itemId = typeof item.id === "string" ? item.id : "";
|
|
201
|
+
const itemType = typeof item.type === "string" ? item.type : "";
|
|
202
|
+
if (itemType !== "function_call") {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const callId = typeof item.call_id === "string" ? item.call_id : "";
|
|
206
|
+
const name = typeof item.name === "string" ? item.name : "";
|
|
207
|
+
pendingCalls.set(itemId, {
|
|
208
|
+
arguments: "",
|
|
209
|
+
callId,
|
|
210
|
+
name
|
|
211
|
+
});
|
|
212
|
+
};
|
|
213
|
+
var isCompletedImageGeneration = (item) => item.type === "image_generation_call" && item.status === "completed" && typeof item.result === "string" && item.result !== "";
|
|
214
|
+
var buildImageChunk = (item) => ({
|
|
215
|
+
data: typeof item.result === "string" ? item.result : "",
|
|
216
|
+
format: extractMimeFormat(item.output_format),
|
|
217
|
+
imageId: typeof item.id === "string" ? item.id : undefined,
|
|
218
|
+
isPartial: false,
|
|
219
|
+
revisedPrompt: typeof item.revised_prompt === "string" ? item.revised_prompt : undefined,
|
|
220
|
+
type: "image"
|
|
221
|
+
});
|
|
222
|
+
var extractImageFromOutput = function* (output) {
|
|
223
|
+
const completedImages = output.filter(isCompletedImageGeneration);
|
|
224
|
+
for (const item of completedImages) {
|
|
225
|
+
yield buildImageChunk(item);
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
var processCompleted = function* (parsed) {
|
|
229
|
+
if (!isRecord(parsed.response)) {
|
|
230
|
+
yield { type: "done", usage: undefined };
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
const { response } = parsed;
|
|
234
|
+
const usage = extractUsage(response);
|
|
235
|
+
if (isRecordArray(response.output)) {
|
|
236
|
+
yield* extractImageFromOutput(response.output);
|
|
237
|
+
}
|
|
238
|
+
yield { type: "done", usage };
|
|
239
|
+
};
|
|
240
|
+
var processSSEEvent = function* (eventType, parsed, pendingCalls) {
|
|
241
|
+
switch (eventType) {
|
|
242
|
+
case "response.reasoning_summary_text.delta": {
|
|
243
|
+
const delta = typeof parsed.delta === "string" ? parsed.delta : "";
|
|
244
|
+
if (!delta)
|
|
245
|
+
break;
|
|
246
|
+
yield {
|
|
247
|
+
content: delta,
|
|
248
|
+
type: "thinking"
|
|
249
|
+
};
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
case "response.output_text.delta":
|
|
253
|
+
yield* processTextDelta(parsed);
|
|
254
|
+
break;
|
|
255
|
+
case "response.image_generation_call.partial_image":
|
|
256
|
+
yield* processPartialImage(parsed);
|
|
257
|
+
break;
|
|
258
|
+
case "response.output_item.added":
|
|
259
|
+
processOutputItemAdded(parsed, pendingCalls);
|
|
260
|
+
break;
|
|
261
|
+
case "response.function_call_arguments.delta":
|
|
262
|
+
processFunctionCallArgumentsDelta(parsed, pendingCalls);
|
|
263
|
+
break;
|
|
264
|
+
case "response.function_call_arguments.done":
|
|
265
|
+
yield* processFunctionCallArgumentsDone(parsed, pendingCalls);
|
|
266
|
+
break;
|
|
267
|
+
case "response.completed":
|
|
268
|
+
yield* processCompleted(parsed);
|
|
269
|
+
break;
|
|
270
|
+
case "response.failed":
|
|
271
|
+
case "response.incomplete": {
|
|
272
|
+
const respObj = isRecord(parsed.response) ? parsed.response : parsed;
|
|
273
|
+
const errMsg = isRecord(respObj.error) && typeof respObj.error.message === "string" ? respObj.error.message : `OpenAI Responses API: ${eventType}`;
|
|
274
|
+
throw new Error(errMsg);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
var flushSSEBuffer = function* (state) {
|
|
279
|
+
if (!state.currentEvent || !state.buffer) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
const parsed = parseJSON(state.buffer);
|
|
283
|
+
if (parsed) {
|
|
284
|
+
yield* processSSEEvent(state.currentEvent, parsed, state.pendingCalls);
|
|
285
|
+
}
|
|
286
|
+
state.currentEvent = "";
|
|
287
|
+
state.buffer = "";
|
|
288
|
+
};
|
|
289
|
+
var parseSSELine = (trimmed, state) => {
|
|
290
|
+
if (trimmed.startsWith("event: ")) {
|
|
291
|
+
state.currentEvent = trimmed.slice(EVENT_PREFIX_LENGTH);
|
|
292
|
+
} else if (trimmed.startsWith("data: ")) {
|
|
293
|
+
state.buffer = trimmed.slice(DATA_PREFIX_LENGTH);
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
var processSSELine = function* (line, state) {
|
|
297
|
+
const trimmed = line.trim();
|
|
298
|
+
if (trimmed) {
|
|
299
|
+
parseSSELine(trimmed, state);
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
yield* flushSSEBuffer(state);
|
|
303
|
+
};
|
|
304
|
+
var processSSELines = function* (lines, state) {
|
|
305
|
+
for (const line of lines) {
|
|
306
|
+
yield* processSSELine(line, state);
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
var drainReader = async function* (reader, decoder, state, signal) {
|
|
310
|
+
let textBuffer = "";
|
|
311
|
+
for (let result = await reader.read();!result.done && !signal?.aborted; result = await reader.read()) {
|
|
312
|
+
textBuffer += decoder.decode(result.value, { stream: true });
|
|
313
|
+
const lines = textBuffer.split(`
|
|
314
|
+
`);
|
|
315
|
+
textBuffer = lines.pop() ?? "";
|
|
316
|
+
yield* processSSELines(lines, state);
|
|
317
|
+
}
|
|
318
|
+
if (textBuffer.trim()) {
|
|
319
|
+
yield* processSSELines([textBuffer, ""], state);
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
var parseSSEStream = async function* (body, signal) {
|
|
323
|
+
const reader = body.getReader();
|
|
324
|
+
const decoder = new TextDecoder;
|
|
325
|
+
const state = {
|
|
326
|
+
buffer: "",
|
|
327
|
+
currentEvent: "",
|
|
328
|
+
pendingCalls: new Map,
|
|
329
|
+
usage: undefined
|
|
330
|
+
};
|
|
331
|
+
try {
|
|
332
|
+
yield* drainReader(reader, decoder, state, signal);
|
|
333
|
+
} finally {
|
|
334
|
+
reader.releaseLock();
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
var fetchResponsesStream = async function* (baseUrl, apiKey, body, signal) {
|
|
338
|
+
const response = await fetch(`${baseUrl}/v1/responses`, {
|
|
339
|
+
body: JSON.stringify(body),
|
|
340
|
+
headers: {
|
|
341
|
+
Authorization: `Bearer ${apiKey}`,
|
|
342
|
+
"Content-Type": "application/json"
|
|
343
|
+
},
|
|
344
|
+
method: "POST",
|
|
345
|
+
signal
|
|
346
|
+
});
|
|
347
|
+
if (!response.ok) {
|
|
348
|
+
const errorText = await response.text();
|
|
349
|
+
throw new Error(`OpenAI Responses API error ${response.status}: ${errorText}`);
|
|
350
|
+
}
|
|
351
|
+
if (!response.body) {
|
|
352
|
+
throw new Error("OpenAI Responses API returned no response body");
|
|
353
|
+
}
|
|
354
|
+
yield* parseSSEStream(response.body, signal);
|
|
355
|
+
};
|
|
356
|
+
var resolveImageModels = (imageModels) => {
|
|
357
|
+
if (!imageModels) {
|
|
358
|
+
return new Set;
|
|
359
|
+
}
|
|
360
|
+
if (imageModels instanceof Set) {
|
|
361
|
+
return imageModels;
|
|
362
|
+
}
|
|
363
|
+
return new Set(imageModels);
|
|
364
|
+
};
|
|
365
|
+
var openaiResponses = (config) => {
|
|
366
|
+
const baseUrl = config.baseUrl ?? DEFAULT_BASE_URL;
|
|
367
|
+
const imageModels = resolveImageModels(config.imageModels);
|
|
368
|
+
return {
|
|
369
|
+
stream: (params) => {
|
|
370
|
+
const isImageModel = imageModels.has(params.model);
|
|
371
|
+
const body = buildRequestBody(params, isImageModel);
|
|
372
|
+
return fetchResponsesStream(baseUrl, config.apiKey, body, params.signal);
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
};
|
|
376
|
+
export {
|
|
377
|
+
openaiResponses
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
//# debugId=04A5D56F49D65F2E64756E2164756E21
|
|
381
|
+
//# sourceMappingURL=openaiResponses.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/ai/providers/openaiResponses.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import type {\n\tAIProviderConfig,\n\tAIProviderContentBlock,\n\tAIProviderMessage,\n\tAIProviderStreamParams,\n\tAIProviderToolDefinition,\n\tAIUsage\n} from '../../../types/ai';\n\ntype OpenAIResponsesConfig = {\n\tapiKey: string;\n\tbaseUrl?: string;\n\timageModels?: Set<string> | string[];\n};\n\ntype PendingFunctionCall = {\n\tcallId: string;\n\tname: string;\n\targuments: string;\n};\n\ntype StreamState = {\n\tbuffer: string;\n\tcurrentEvent: string;\n\tpendingCalls: Map<string, PendingFunctionCall>;\n\tusage: AIUsage | undefined;\n};\n\nconst DEFAULT_BASE_URL = 'https://api.openai.com';\nconst EVENT_PREFIX_LENGTH = 7;\nconst DATA_PREFIX_LENGTH = 6;\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n\ttypeof value === 'object' && value !== null;\n\nconst isRecordArray = (\n\tvalue: unknown\n): value is Array<Record<string, unknown>> =>\n\tArray.isArray(value) && value.length > 0 && isRecord(value[0]);\n\n/* ─── Message conversion ─── */\n\nconst mapBlockToResponsesFormat = (block: AIProviderContentBlock) => {\n\tif (block.type === 'text') {\n\t\treturn { text: block.content, type: 'input_text' };\n\t}\n\n\tif (block.type === 'image') {\n\t\treturn {\n\t\t\timage_url: {\n\t\t\t\turl: `data:${block.source.media_type};base64,${block.source.data}`\n\t\t\t},\n\t\t\ttype: 'input_image'\n\t\t};\n\t}\n\n\tif (block.type === 'document') {\n\t\treturn {\n\t\t\tfile: {\n\t\t\t\tfile_data: `data:${block.source.media_type};base64,${block.source.data}`,\n\t\t\t\tfilename: block.name ?? 'document.pdf'\n\t\t\t},\n\t\t\ttype: 'input_file'\n\t\t};\n\t}\n\n\treturn null;\n};\n\nconst mapContentToResponsesFormat = (\n\tcontent: string | AIProviderContentBlock[]\n) => {\n\tif (typeof content === 'string') {\n\t\treturn content;\n\t}\n\n\tconst parts = content\n\t\t.map(mapBlockToResponsesFormat)\n\t\t.filter((mapped) => mapped !== null);\n\n\treturn parts.length > 0 ? parts : '';\n};\n\nconst hasToolBlocks = (content: AIProviderContentBlock[]) =>\n\tcontent.some(\n\t\t(block) => block.type === 'tool_use' || block.type === 'tool_result'\n\t);\n\nconst convertToolBlock = (block: AIProviderContentBlock) => {\n\tif (block.type === 'tool_use') {\n\t\treturn {\n\t\t\targuments:\n\t\t\t\ttypeof block.input === 'string'\n\t\t\t\t\t? block.input\n\t\t\t\t\t: JSON.stringify(block.input),\n\t\t\tcall_id: block.id,\n\t\t\tname: block.name,\n\t\t\ttype: 'function_call'\n\t\t};\n\t}\n\n\tif (block.type === 'tool_result') {\n\t\treturn {\n\t\t\tcall_id: block.tool_use_id,\n\t\t\toutput: typeof block.content === 'string' ? block.content : '',\n\t\t\ttype: 'function_call_output'\n\t\t};\n\t}\n\n\treturn null;\n};\n\nconst convertToolBlocks = (content: AIProviderContentBlock[]) =>\n\tcontent.map(convertToolBlock).filter((converted) => converted !== null);\n\nconst convertMessage = (msg: AIProviderMessage) => {\n\tif (\n\t\ttypeof msg.content !== 'string' &&\n\t\tArray.isArray(msg.content) &&\n\t\thasToolBlocks(msg.content)\n\t) {\n\t\treturn convertToolBlocks(msg.content);\n\t}\n\n\tconst content = mapContentToResponsesFormat(msg.content);\n\n\treturn [\n\t\t{\n\t\t\tcontent,\n\t\t\trole: msg.role === 'system' ? 'developer' : msg.role,\n\t\t\ttype: 'message'\n\t\t}\n\t];\n};\n\nconst buildInput = (messages: AIProviderMessage[]) => {\n\tconst input: Array<Record<string, unknown>> = [];\n\n\tfor (const msg of messages) {\n\t\tinput.push(...convertMessage(msg));\n\t}\n\n\treturn input;\n};\n\nconst mapToolDefinition = (tool: AIProviderToolDefinition) => ({\n\tdescription: tool.description,\n\tname: tool.name,\n\tparameters: tool.input_schema,\n\ttype: 'function'\n});\n\nconst buildTools = (\n\ttools: AIProviderToolDefinition[] | undefined,\n\tisImageModel: boolean\n) => {\n\tconst mapped = tools ? tools.map(mapToolDefinition) : [];\n\tconst result: Array<Record<string, unknown>> = [...mapped];\n\n\tif (isImageModel) {\n\t\tresult.push({ type: 'image_generation' });\n\t}\n\n\treturn result.length > 0 ? result : undefined;\n};\n\nconst buildRequestBody = (\n\tparams: AIProviderStreamParams,\n\tisImageModel: boolean\n) => {\n\tconst body: Record<string, unknown> = {\n\t\tinput: buildInput(params.messages),\n\t\tmodel: params.model,\n\t\tstream: true\n\t};\n\n\tif (params.systemPrompt) {\n\t\tbody.instructions = params.systemPrompt;\n\t}\n\n\tconst tools = buildTools(params.tools, isImageModel);\n\n\tif (tools) {\n\t\tbody.tools = tools;\n\t}\n\n\t// Enable reasoning summary for models that support thinking/reasoning\n\tif (params.thinking) {\n\t\tbody.reasoning = {\n\t\t\teffort: 'high',\n\t\t\tsummary: 'auto'\n\t\t};\n\t}\n\n\treturn body;\n};\n\n/* ─── SSE parsing ─── */\n\nconst parseJSON = (data: string) => {\n\ttry {\n\t\treturn JSON.parse(data);\n\t} catch {\n\t\treturn null;\n\t}\n};\n\nconst parseToolInput = (rawArguments: string) => {\n\ttry {\n\t\treturn JSON.parse(rawArguments);\n\t} catch {\n\t\treturn rawArguments;\n\t}\n};\n\nconst extractUsage = (response: Record<string, unknown>) => {\n\tif (!isRecord(response.usage)) {\n\t\treturn undefined;\n\t}\n\n\tconst { usage } = response;\n\n\treturn {\n\t\tinputTokens:\n\t\t\ttypeof usage.input_tokens === 'number' ? usage.input_tokens : 0,\n\t\toutputTokens:\n\t\t\ttypeof usage.output_tokens === 'number' ? usage.output_tokens : 0\n\t};\n};\n\nconst extractMimeFormat = (mimeType: unknown) => {\n\tif (typeof mimeType !== 'string') {\n\t\treturn 'png';\n\t}\n\n\tif (mimeType.includes('jpeg')) return 'jpeg';\n\tif (mimeType.includes('webp')) return 'webp';\n\n\treturn 'png';\n};\n\nconst processTextDelta = function* (parsed: Record<string, unknown>) {\n\tif (typeof parsed.delta === 'string') {\n\t\tyield { content: parsed.delta, type: 'text' as const };\n\t}\n};\n\nconst processPartialImage = function* (parsed: Record<string, unknown>) {\n\tconst itemId =\n\t\ttypeof parsed.item_id === 'string' ? parsed.item_id : undefined;\n\tconst b64 =\n\t\ttypeof parsed.partial_image_b64 === 'string'\n\t\t\t? parsed.partial_image_b64\n\t\t\t: undefined;\n\n\tif (b64) {\n\t\tyield {\n\t\t\tdata: b64,\n\t\t\tformat: 'png',\n\t\t\timageId: itemId,\n\t\t\tisPartial: true,\n\t\t\ttype: 'image' as const\n\t\t};\n\t}\n};\n\nconst processFunctionCallArgumentsDelta = (\n\tparsed: Record<string, unknown>,\n\tpendingCalls: Map<string, PendingFunctionCall>\n) => {\n\tconst itemId = typeof parsed.item_id === 'string' ? parsed.item_id : '';\n\tconst callId = typeof parsed.call_id === 'string' ? parsed.call_id : '';\n\tconst delta =\n\t\ttypeof parsed.arguments_delta === 'string'\n\t\t\t? parsed.arguments_delta\n\t\t\t: '';\n\n\tconst existing = pendingCalls.get(itemId);\n\n\tif (existing) {\n\t\texisting.arguments += delta;\n\t} else {\n\t\tpendingCalls.set(itemId, {\n\t\t\targuments: delta,\n\t\t\tcallId,\n\t\t\tname: ''\n\t\t});\n\t}\n};\n\nconst processFunctionCallArgumentsDone = function* (\n\tparsed: Record<string, unknown>,\n\tpendingCalls: Map<string, PendingFunctionCall>\n) {\n\tconst itemId = typeof parsed.item_id === 'string' ? parsed.item_id : '';\n\tconst callId = typeof parsed.call_id === 'string' ? parsed.call_id : '';\n\tconst fullArgs =\n\t\ttypeof parsed.arguments === 'string' ? parsed.arguments : '';\n\n\tconst pending = pendingCalls.get(itemId);\n\tconst name = pending?.name ?? '';\n\tconst args = fullArgs || pending?.arguments || '';\n\n\tpendingCalls.delete(itemId);\n\n\tyield {\n\t\tid: callId || pending?.callId || itemId,\n\t\tinput: parseToolInput(args),\n\t\tname,\n\t\ttype: 'tool_use' as const\n\t};\n};\n\nconst processOutputItemAdded = (\n\tparsed: Record<string, unknown>,\n\tpendingCalls: Map<string, PendingFunctionCall>\n) => {\n\tif (!isRecord(parsed.item)) {\n\t\treturn;\n\t}\n\n\tconst { item } = parsed;\n\tconst itemId = typeof item.id === 'string' ? item.id : '';\n\tconst itemType = typeof item.type === 'string' ? item.type : '';\n\n\tif (itemType !== 'function_call') {\n\t\treturn;\n\t}\n\n\tconst callId = typeof item.call_id === 'string' ? item.call_id : '';\n\tconst name = typeof item.name === 'string' ? item.name : '';\n\n\tpendingCalls.set(itemId, {\n\t\targuments: '',\n\t\tcallId,\n\t\tname\n\t});\n};\n\nconst isCompletedImageGeneration = (item: Record<string, unknown>) =>\n\titem.type === 'image_generation_call' &&\n\titem.status === 'completed' &&\n\ttypeof item.result === 'string' &&\n\titem.result !== '';\n\nconst buildImageChunk = (item: Record<string, unknown>) => ({\n\tdata: typeof item.result === 'string' ? item.result : '',\n\tformat: extractMimeFormat(item.output_format),\n\timageId: typeof item.id === 'string' ? item.id : undefined,\n\tisPartial: false,\n\trevisedPrompt:\n\t\ttypeof item.revised_prompt === 'string'\n\t\t\t? item.revised_prompt\n\t\t\t: undefined,\n\ttype: 'image' as const\n});\n\nconst extractImageFromOutput = function* (\n\toutput: Array<Record<string, unknown>>\n) {\n\tconst completedImages = output.filter(isCompletedImageGeneration);\n\n\tfor (const item of completedImages) {\n\t\tyield buildImageChunk(item);\n\t}\n};\n\nconst processCompleted = function* (parsed: Record<string, unknown>) {\n\tif (!isRecord(parsed.response)) {\n\t\tyield { type: 'done' as const, usage: undefined };\n\n\t\treturn;\n\t}\n\n\tconst { response } = parsed;\n\tconst usage = extractUsage(response);\n\n\tif (isRecordArray(response.output)) {\n\t\tyield* extractImageFromOutput(response.output);\n\t}\n\n\tyield { type: 'done' as const, usage };\n};\n\nconst processSSEEvent = function* (\n\teventType: string,\n\tparsed: Record<string, unknown>,\n\tpendingCalls: Map<string, PendingFunctionCall>\n) {\n\tswitch (eventType) {\n\t\tcase 'response.reasoning_summary_text.delta': {\n\t\t\tconst delta = typeof parsed.delta === 'string' ? parsed.delta : '';\n\t\t\tif (!delta) break;\n\n\t\t\tyield {\n\t\t\t\tcontent: delta,\n\t\t\t\ttype: 'thinking' as const\n\t\t\t};\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase 'response.output_text.delta':\n\t\t\tyield* processTextDelta(parsed);\n\t\t\tbreak;\n\n\t\tcase 'response.image_generation_call.partial_image':\n\t\t\tyield* processPartialImage(parsed);\n\t\t\tbreak;\n\n\t\tcase 'response.output_item.added':\n\t\t\tprocessOutputItemAdded(parsed, pendingCalls);\n\t\t\tbreak;\n\n\t\tcase 'response.function_call_arguments.delta':\n\t\t\tprocessFunctionCallArgumentsDelta(parsed, pendingCalls);\n\t\t\tbreak;\n\n\t\tcase 'response.function_call_arguments.done':\n\t\t\tyield* processFunctionCallArgumentsDone(parsed, pendingCalls);\n\t\t\tbreak;\n\n\t\tcase 'response.completed':\n\t\t\tyield* processCompleted(parsed);\n\t\t\tbreak;\n\n\t\tcase 'response.failed':\n\t\tcase 'response.incomplete': {\n\t\t\tconst respObj = isRecord(parsed.response)\n\t\t\t\t? parsed.response\n\t\t\t\t: parsed;\n\t\t\tconst errMsg =\n\t\t\t\tisRecord(respObj.error) &&\n\t\t\t\ttypeof respObj.error.message === 'string'\n\t\t\t\t\t? respObj.error.message\n\t\t\t\t\t: `OpenAI Responses API: ${eventType}`;\n\t\t\tthrow new Error(errMsg);\n\t\t}\n\t}\n};\n\nconst flushSSEBuffer = function* (state: StreamState) {\n\tif (!state.currentEvent || !state.buffer) {\n\t\treturn;\n\t}\n\n\tconst parsed = parseJSON(state.buffer);\n\n\tif (parsed) {\n\t\tyield* processSSEEvent(state.currentEvent, parsed, state.pendingCalls);\n\t}\n\n\tstate.currentEvent = '';\n\tstate.buffer = '';\n};\n\nconst parseSSELine = (trimmed: string, state: StreamState) => {\n\tif (trimmed.startsWith('event: ')) {\n\t\tstate.currentEvent = trimmed.slice(EVENT_PREFIX_LENGTH);\n\t} else if (trimmed.startsWith('data: ')) {\n\t\tstate.buffer = trimmed.slice(DATA_PREFIX_LENGTH);\n\t}\n};\n\nconst processSSELine = function* (line: string, state: StreamState) {\n\tconst trimmed = line.trim();\n\n\tif (trimmed) {\n\t\tparseSSELine(trimmed, state);\n\n\t\treturn;\n\t}\n\n\tyield* flushSSEBuffer(state);\n};\n\nconst processSSELines = function* (lines: string[], state: StreamState) {\n\tfor (const line of lines) {\n\t\tyield* processSSELine(line, state);\n\t}\n};\n\nconst drainReader = async function* (\n\treader: ReadableStreamDefaultReader<Uint8Array>,\n\tdecoder: TextDecoder,\n\tstate: StreamState,\n\tsignal?: AbortSignal\n) {\n\tlet textBuffer = '';\n\n\tfor (\n\t\tlet result = await reader.read();\n\t\t!result.done && !signal?.aborted;\n\t\t// eslint-disable-next-line no-await-in-loop\n\t\tresult = await reader.read()\n\t) {\n\t\ttextBuffer += decoder.decode(result.value, { stream: true });\n\t\tconst lines = textBuffer.split('\\n');\n\t\ttextBuffer = lines.pop() ?? '';\n\n\t\tyield* processSSELines(lines, state);\n\t}\n\n\tif (textBuffer.trim()) {\n\t\tyield* processSSELines([textBuffer, ''], state);\n\t}\n};\n\nconst parseSSEStream = async function* (\n\tbody: ReadableStream<Uint8Array>,\n\tsignal?: AbortSignal\n) {\n\tconst reader = body.getReader();\n\tconst decoder = new TextDecoder();\n\tconst state: StreamState = {\n\t\tbuffer: '',\n\t\tcurrentEvent: '',\n\t\tpendingCalls: new Map(),\n\t\tusage: undefined\n\t};\n\n\ttry {\n\t\tyield* drainReader(reader, decoder, state, signal);\n\t} finally {\n\t\treader.releaseLock();\n\t}\n};\n\nconst fetchResponsesStream = async function* (\n\tbaseUrl: string,\n\tapiKey: string,\n\tbody: Record<string, unknown>,\n\tsignal?: AbortSignal\n) {\n\tconst response = await fetch(`${baseUrl}/v1/responses`, {\n\t\tbody: JSON.stringify(body),\n\t\theaders: {\n\t\t\tAuthorization: `Bearer ${apiKey}`,\n\t\t\t'Content-Type': 'application/json'\n\t\t},\n\t\tmethod: 'POST',\n\t\tsignal\n\t});\n\n\tif (!response.ok) {\n\t\tconst errorText = await response.text();\n\t\tthrow new Error(\n\t\t\t`OpenAI Responses API error ${response.status}: ${errorText}`\n\t\t);\n\t}\n\n\tif (!response.body) {\n\t\tthrow new Error('OpenAI Responses API returned no response body');\n\t}\n\n\tyield* parseSSEStream(response.body, signal);\n};\n\nconst resolveImageModels = (\n\timageModels: Set<string> | string[] | undefined\n) => {\n\tif (!imageModels) {\n\t\treturn new Set<string>();\n\t}\n\n\tif (imageModels instanceof Set) {\n\t\treturn imageModels;\n\t}\n\n\treturn new Set(imageModels);\n};\n\nexport const openaiResponses = (config: OpenAIResponsesConfig) => {\n\tconst baseUrl = config.baseUrl ?? DEFAULT_BASE_URL;\n\tconst imageModels = resolveImageModels(config.imageModels);\n\n\treturn {\n\t\tstream: (params: AIProviderStreamParams) => {\n\t\t\tconst isImageModel = imageModels.has(params.model);\n\t\t\tconst body = buildRequestBody(params, isImageModel);\n\n\t\t\treturn fetchResponsesStream(\n\t\t\t\tbaseUrl,\n\t\t\t\tconfig.apiKey,\n\t\t\t\tbody,\n\t\t\t\tparams.signal\n\t\t\t);\n\t\t}\n\t} satisfies AIProviderConfig;\n};\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;AA4BA,IAAM,mBAAmB;AACzB,IAAM,sBAAsB;AAC5B,IAAM,qBAAqB;AAE3B,IAAM,WAAW,CAAC,UACjB,OAAO,UAAU,YAAY,UAAU;AAExC,IAAM,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AAA,IAC/B,OAAO;AAAA,EACR;AAAA,EAEA,OAAO,IAAI,IAAI,WAAW;AAAA;AAGpB,IAAM,kBAAkB,CAAC,WAAkC;AAAA,EACjE,MAAM,UAAU,OAAO,WAAW;AAAA,EAClC,MAAM,cAAc,mBAAmB,OAAO,WAAW;AAAA,EAEzD,OAAO;AAAA,IACN,QAAQ,CAAC,WAAmC;AAAA,MAC3C,MAAM,eAAe,YAAY,IAAI,OAAO,KAAK;AAAA,MACjD,MAAM,OAAO,iBAAiB,QAAQ,YAAY;AAAA,MAElD,OAAO,qBACN,SACA,OAAO,QACP,MACA,OAAO,MACR;AAAA;AAAA,EAEF;AAAA;",
|
|
8
|
+
"debugId": "04A5D56F49D65F2E64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import type { AIServerMessage } from '../../../types/ai';
|
|
2
|
+
export declare const serverMessageToAction: (message: AIServerMessage) => {
|
|
3
|
+
content: string;
|
|
4
|
+
conversationId: string;
|
|
5
|
+
messageId: string;
|
|
6
|
+
type: "chunk";
|
|
7
|
+
input?: undefined;
|
|
8
|
+
name?: undefined;
|
|
9
|
+
result?: undefined;
|
|
10
|
+
status?: undefined;
|
|
11
|
+
data?: undefined;
|
|
12
|
+
format?: undefined;
|
|
13
|
+
imageId?: undefined;
|
|
14
|
+
isPartial?: undefined;
|
|
15
|
+
revisedPrompt?: undefined;
|
|
16
|
+
durationMs?: undefined;
|
|
17
|
+
model?: undefined;
|
|
18
|
+
sources?: undefined;
|
|
19
|
+
usage?: undefined;
|
|
20
|
+
retrievalStartedAt?: undefined;
|
|
21
|
+
retrievalDurationMs?: undefined;
|
|
22
|
+
retrievedAt?: undefined;
|
|
23
|
+
trace?: undefined;
|
|
24
|
+
message?: undefined;
|
|
25
|
+
} | {
|
|
26
|
+
content: string;
|
|
27
|
+
conversationId: string;
|
|
28
|
+
messageId: string;
|
|
29
|
+
type: "thinking";
|
|
30
|
+
input?: undefined;
|
|
31
|
+
name?: undefined;
|
|
32
|
+
result?: undefined;
|
|
33
|
+
status?: undefined;
|
|
34
|
+
data?: undefined;
|
|
35
|
+
format?: undefined;
|
|
36
|
+
imageId?: undefined;
|
|
37
|
+
isPartial?: undefined;
|
|
38
|
+
revisedPrompt?: undefined;
|
|
39
|
+
durationMs?: undefined;
|
|
40
|
+
model?: undefined;
|
|
41
|
+
sources?: undefined;
|
|
42
|
+
usage?: undefined;
|
|
43
|
+
retrievalStartedAt?: undefined;
|
|
44
|
+
retrievalDurationMs?: undefined;
|
|
45
|
+
retrievedAt?: undefined;
|
|
46
|
+
trace?: undefined;
|
|
47
|
+
message?: undefined;
|
|
48
|
+
} | {
|
|
49
|
+
conversationId: string;
|
|
50
|
+
input: unknown;
|
|
51
|
+
messageId: string;
|
|
52
|
+
name: string;
|
|
53
|
+
result: string | undefined;
|
|
54
|
+
status: "complete" | "running";
|
|
55
|
+
type: "tool_status";
|
|
56
|
+
content?: undefined;
|
|
57
|
+
data?: undefined;
|
|
58
|
+
format?: undefined;
|
|
59
|
+
imageId?: undefined;
|
|
60
|
+
isPartial?: undefined;
|
|
61
|
+
revisedPrompt?: undefined;
|
|
62
|
+
durationMs?: undefined;
|
|
63
|
+
model?: undefined;
|
|
64
|
+
sources?: undefined;
|
|
65
|
+
usage?: undefined;
|
|
66
|
+
retrievalStartedAt?: undefined;
|
|
67
|
+
retrievalDurationMs?: undefined;
|
|
68
|
+
retrievedAt?: undefined;
|
|
69
|
+
trace?: undefined;
|
|
70
|
+
message?: undefined;
|
|
71
|
+
} | {
|
|
72
|
+
conversationId: string;
|
|
73
|
+
data: string;
|
|
74
|
+
format: string;
|
|
75
|
+
imageId: string | undefined;
|
|
76
|
+
isPartial: boolean;
|
|
77
|
+
messageId: string;
|
|
78
|
+
revisedPrompt: string | undefined;
|
|
79
|
+
type: "image";
|
|
80
|
+
content?: undefined;
|
|
81
|
+
input?: undefined;
|
|
82
|
+
name?: undefined;
|
|
83
|
+
result?: undefined;
|
|
84
|
+
status?: undefined;
|
|
85
|
+
durationMs?: undefined;
|
|
86
|
+
model?: undefined;
|
|
87
|
+
sources?: undefined;
|
|
88
|
+
usage?: undefined;
|
|
89
|
+
retrievalStartedAt?: undefined;
|
|
90
|
+
retrievalDurationMs?: undefined;
|
|
91
|
+
retrievedAt?: undefined;
|
|
92
|
+
trace?: undefined;
|
|
93
|
+
message?: undefined;
|
|
94
|
+
} | {
|
|
95
|
+
conversationId: string;
|
|
96
|
+
durationMs: number | undefined;
|
|
97
|
+
messageId: string;
|
|
98
|
+
model: string | undefined;
|
|
99
|
+
sources: import("..").RAGSource[] | undefined;
|
|
100
|
+
type: "complete";
|
|
101
|
+
usage: import("..").AIUsage | undefined;
|
|
102
|
+
content?: undefined;
|
|
103
|
+
input?: undefined;
|
|
104
|
+
name?: undefined;
|
|
105
|
+
result?: undefined;
|
|
106
|
+
status?: undefined;
|
|
107
|
+
data?: undefined;
|
|
108
|
+
format?: undefined;
|
|
109
|
+
imageId?: undefined;
|
|
110
|
+
isPartial?: undefined;
|
|
111
|
+
revisedPrompt?: undefined;
|
|
112
|
+
retrievalStartedAt?: undefined;
|
|
113
|
+
retrievalDurationMs?: undefined;
|
|
114
|
+
retrievedAt?: undefined;
|
|
115
|
+
trace?: undefined;
|
|
116
|
+
message?: undefined;
|
|
117
|
+
} | {
|
|
118
|
+
conversationId: string;
|
|
119
|
+
messageId: string;
|
|
120
|
+
retrievalStartedAt: number;
|
|
121
|
+
type: "rag_retrieving";
|
|
122
|
+
content?: undefined;
|
|
123
|
+
input?: undefined;
|
|
124
|
+
name?: undefined;
|
|
125
|
+
result?: undefined;
|
|
126
|
+
status?: undefined;
|
|
127
|
+
data?: undefined;
|
|
128
|
+
format?: undefined;
|
|
129
|
+
imageId?: undefined;
|
|
130
|
+
isPartial?: undefined;
|
|
131
|
+
revisedPrompt?: undefined;
|
|
132
|
+
durationMs?: undefined;
|
|
133
|
+
model?: undefined;
|
|
134
|
+
sources?: undefined;
|
|
135
|
+
usage?: undefined;
|
|
136
|
+
retrievalDurationMs?: undefined;
|
|
137
|
+
retrievedAt?: undefined;
|
|
138
|
+
trace?: undefined;
|
|
139
|
+
message?: undefined;
|
|
140
|
+
} | {
|
|
141
|
+
conversationId: string;
|
|
142
|
+
messageId: string;
|
|
143
|
+
retrievalDurationMs: number | undefined;
|
|
144
|
+
retrievalStartedAt: number | undefined;
|
|
145
|
+
retrievedAt: number;
|
|
146
|
+
sources: import("..").RAGSource[];
|
|
147
|
+
trace: import("..").RAGRetrievalTrace | undefined;
|
|
148
|
+
type: "rag_retrieved";
|
|
149
|
+
content?: undefined;
|
|
150
|
+
input?: undefined;
|
|
151
|
+
name?: undefined;
|
|
152
|
+
result?: undefined;
|
|
153
|
+
status?: undefined;
|
|
154
|
+
data?: undefined;
|
|
155
|
+
format?: undefined;
|
|
156
|
+
imageId?: undefined;
|
|
157
|
+
isPartial?: undefined;
|
|
158
|
+
revisedPrompt?: undefined;
|
|
159
|
+
durationMs?: undefined;
|
|
160
|
+
model?: undefined;
|
|
161
|
+
usage?: undefined;
|
|
162
|
+
message?: undefined;
|
|
163
|
+
} | {
|
|
164
|
+
message: string;
|
|
165
|
+
type: "error";
|
|
166
|
+
content?: undefined;
|
|
167
|
+
conversationId?: undefined;
|
|
168
|
+
messageId?: undefined;
|
|
169
|
+
input?: undefined;
|
|
170
|
+
name?: undefined;
|
|
171
|
+
result?: undefined;
|
|
172
|
+
status?: undefined;
|
|
173
|
+
data?: undefined;
|
|
174
|
+
format?: undefined;
|
|
175
|
+
imageId?: undefined;
|
|
176
|
+
isPartial?: undefined;
|
|
177
|
+
revisedPrompt?: undefined;
|
|
178
|
+
durationMs?: undefined;
|
|
179
|
+
model?: undefined;
|
|
180
|
+
sources?: undefined;
|
|
181
|
+
usage?: undefined;
|
|
182
|
+
retrievalStartedAt?: undefined;
|
|
183
|
+
retrievalDurationMs?: undefined;
|
|
184
|
+
retrievedAt?: undefined;
|
|
185
|
+
trace?: undefined;
|
|
186
|
+
} | null;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AIClientMessage, AIConnectionOptions, AIServerMessage } from '../../../types/ai';
|
|
2
|
+
type AIConnectionHandle = {
|
|
3
|
+
close: () => void;
|
|
4
|
+
getReadyState: () => number;
|
|
5
|
+
send: (msg: AIClientMessage) => void;
|
|
6
|
+
subscribe: (callback: (msg: AIServerMessage) => void) => () => void;
|
|
7
|
+
};
|
|
8
|
+
export declare const createAIConnection: (path: string, options?: AIConnectionOptions) => AIConnectionHandle;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AIAttachment, AIMessage } from '../../../types/ai';
|
|
2
|
+
export declare const createAIStream: (path: string, conversationId?: string) => {
|
|
3
|
+
branch: (messageId: string, content: string) => void;
|
|
4
|
+
cancel: () => void;
|
|
5
|
+
destroy: () => void;
|
|
6
|
+
send: (content: string, attachments?: AIAttachment[]) => void;
|
|
7
|
+
subscribe: (callback: () => void) => () => void;
|
|
8
|
+
readonly error: string | null;
|
|
9
|
+
readonly isStreaming: boolean;
|
|
10
|
+
readonly messages: AIMessage[];
|
|
11
|
+
};
|
|
12
|
+
export type CreateAIStream = typeof createAIStream;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AIConversation, AIStreamState, AIStoreAction } from '../../../types/ai';
|
|
2
|
+
export declare const createAIMessageStore: () => {
|
|
3
|
+
dispatch: (action: AIStoreAction) => void;
|
|
4
|
+
getServerSnapshot: () => AIStreamState;
|
|
5
|
+
getSnapshot: () => {
|
|
6
|
+
activeConversationId: null;
|
|
7
|
+
conversations: Map<string, AIConversation>;
|
|
8
|
+
error: null;
|
|
9
|
+
isStreaming: boolean;
|
|
10
|
+
};
|
|
11
|
+
subscribe: (callback: () => void) => () => void;
|
|
12
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AIConversation, AIMessage, AIProviderMessage } from '../../types/ai';
|
|
2
|
+
export declare const createConversationManager: () => {
|
|
3
|
+
abort: (conversationId: string) => void;
|
|
4
|
+
appendMessage: (conversationId: string, message: AIMessage) => void;
|
|
5
|
+
branch: (fromMessageId: string, sourceConversationId: string) => `${string}-${string}-${string}-${string}-${string}` | null;
|
|
6
|
+
get: (conversationId: string) => AIConversation | undefined;
|
|
7
|
+
getAbortController: (conversationId: string) => AbortController;
|
|
8
|
+
getHistory: (conversationId: string) => AIProviderMessage[];
|
|
9
|
+
getMessages: (conversationId: string) => AIMessage[];
|
|
10
|
+
getOrCreate: (conversationId?: string) => AIConversation;
|
|
11
|
+
list: () => {
|
|
12
|
+
createdAt: number;
|
|
13
|
+
id: string;
|
|
14
|
+
lastMessageAt: number | undefined;
|
|
15
|
+
messageCount: number;
|
|
16
|
+
title: string;
|
|
17
|
+
}[];
|
|
18
|
+
remove: (conversationId: string) => boolean;
|
|
19
|
+
};
|