@absolutejs/absolute 0.19.0-beta.242 → 0.19.0-beta.244
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/.absolutejs/vue-tsc.tsbuildinfo +1 -1
- package/.claude/settings.local.json +2 -1
- package/dist/ai/index.js +350 -4
- package/dist/ai/index.js.map +7 -5
- package/dist/ai/providers/openaiCompatible.js +392 -0
- package/dist/ai/providers/openaiCompatible.js.map +11 -0
- package/dist/ai-client/angular/ai/index.js +2 -1
- package/dist/ai-client/react/ai/index.js +2 -1
- package/dist/ai-client/vue/ai/index.js +2 -1
- package/dist/angular/ai/index.js +3 -2
- package/dist/angular/ai/index.js.map +3 -3
- package/dist/react/ai/index.js +3 -2
- package/dist/react/ai/index.js.map +3 -3
- package/dist/src/ai/conversationManager.d.ts +3 -1
- package/dist/src/ai/index.d.ts +1 -0
- package/dist/src/ai/providers/openaiCompatible.d.ts +25 -0
- package/dist/src/plugins/aiChat.d.ts +74 -0
- package/dist/svelte/ai/index.js +3 -2
- package/dist/svelte/ai/index.js.map +3 -3
- package/dist/types/ai.d.ts +10 -0
- package/dist/vue/ai/index.js +3 -2
- package/dist/vue/ai/index.js.map +3 -3
- package/package.json +11 -7
- package/scripts/build.ts +1 -0
- package/types/ai.ts +11 -0
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
function __accessProp(key) {
|
|
9
|
+
return this[key];
|
|
10
|
+
}
|
|
11
|
+
var __toESMCache_node;
|
|
12
|
+
var __toESMCache_esm;
|
|
13
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
14
|
+
var canCache = mod != null && typeof mod === "object";
|
|
15
|
+
if (canCache) {
|
|
16
|
+
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
17
|
+
var cached = cache.get(mod);
|
|
18
|
+
if (cached)
|
|
19
|
+
return cached;
|
|
20
|
+
}
|
|
21
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
22
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
23
|
+
for (let key of __getOwnPropNames(mod))
|
|
24
|
+
if (!__hasOwnProp.call(to, key))
|
|
25
|
+
__defProp(to, key, {
|
|
26
|
+
get: __accessProp.bind(mod, key),
|
|
27
|
+
enumerable: true
|
|
28
|
+
});
|
|
29
|
+
if (canCache)
|
|
30
|
+
cache.set(mod, to);
|
|
31
|
+
return to;
|
|
32
|
+
};
|
|
33
|
+
var __toCommonJS = (from) => {
|
|
34
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
35
|
+
if (entry)
|
|
36
|
+
return entry;
|
|
37
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
38
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
39
|
+
for (var key of __getOwnPropNames(from))
|
|
40
|
+
if (!__hasOwnProp.call(entry, key))
|
|
41
|
+
__defProp(entry, key, {
|
|
42
|
+
get: __accessProp.bind(from, key),
|
|
43
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
__moduleCache.set(from, entry);
|
|
47
|
+
return entry;
|
|
48
|
+
};
|
|
49
|
+
var __moduleCache;
|
|
50
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
51
|
+
var __returnValue = (v) => v;
|
|
52
|
+
function __exportSetter(name, newValue) {
|
|
53
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
54
|
+
}
|
|
55
|
+
var __export = (target, all) => {
|
|
56
|
+
for (var name in all)
|
|
57
|
+
__defProp(target, name, {
|
|
58
|
+
get: all[name],
|
|
59
|
+
enumerable: true,
|
|
60
|
+
configurable: true,
|
|
61
|
+
set: __exportSetter.bind(all, name)
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
65
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
66
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
67
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
68
|
+
else
|
|
69
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
70
|
+
if (d = decorators[i])
|
|
71
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
72
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
73
|
+
};
|
|
74
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
75
|
+
var __require = import.meta.require;
|
|
76
|
+
|
|
77
|
+
// src/ai/providers/openai.ts
|
|
78
|
+
var DEFAULT_BASE_URL = "https://api.openai.com";
|
|
79
|
+
var SSE_DATA_PREFIX_LENGTH = 6;
|
|
80
|
+
var DONE_SENTINEL = "[DONE]";
|
|
81
|
+
var NOT_FOUND = -1;
|
|
82
|
+
var isRecord = (value) => typeof value === "object" && value !== null;
|
|
83
|
+
var isRecordArray = (value) => Array.isArray(value) && value.length > 0 && isRecord(value[0]);
|
|
84
|
+
var hasArrayContent = (msg) => typeof msg.content !== "string" && Array.isArray(msg.content);
|
|
85
|
+
var buildToolMessages = (blocks) => {
|
|
86
|
+
const toolUseBlocks = blocks.filter((block) => block.type === "tool_use");
|
|
87
|
+
const toolResultBlocks = blocks.filter((block) => block.type === "tool_result");
|
|
88
|
+
const messages = [];
|
|
89
|
+
if (toolUseBlocks.length > 0) {
|
|
90
|
+
messages.push({
|
|
91
|
+
content: null,
|
|
92
|
+
role: "assistant",
|
|
93
|
+
tool_calls: toolUseBlocks.map((block) => ({
|
|
94
|
+
function: {
|
|
95
|
+
arguments: typeof block.input === "string" ? block.input : JSON.stringify(block.input),
|
|
96
|
+
name: block.name
|
|
97
|
+
},
|
|
98
|
+
id: block.id,
|
|
99
|
+
type: "function"
|
|
100
|
+
}))
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
for (const result of toolResultBlocks) {
|
|
104
|
+
messages.push({
|
|
105
|
+
content: typeof result.content === "string" ? result.content : "",
|
|
106
|
+
role: "tool",
|
|
107
|
+
tool_call_id: result.tool_use_id
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
return messages;
|
|
111
|
+
};
|
|
112
|
+
var processMessageAtIndex = (result, msg, idx) => {
|
|
113
|
+
if (!hasArrayContent(msg)) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const hasToolBlocks = msg.content.some((block) => block.type === "tool_use" || block.type === "tool_result");
|
|
117
|
+
if (!hasToolBlocks) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const toolMessages = buildToolMessages(msg.content);
|
|
121
|
+
result.splice(idx, 1, ...toolMessages);
|
|
122
|
+
};
|
|
123
|
+
var convertSingleMessage = (result, msg, idx) => {
|
|
124
|
+
if (!msg) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
processMessageAtIndex(result, msg, idx);
|
|
128
|
+
};
|
|
129
|
+
var convertToolResultMessages = (messages, params) => {
|
|
130
|
+
const result = [...messages];
|
|
131
|
+
for (let idx = 0;idx < params.messages.length; idx++) {
|
|
132
|
+
convertSingleMessage(result, params.messages[idx], idx);
|
|
133
|
+
}
|
|
134
|
+
return result;
|
|
135
|
+
};
|
|
136
|
+
var mapToolDefinitions = (tools) => tools.map((tool) => ({
|
|
137
|
+
function: {
|
|
138
|
+
description: tool.description,
|
|
139
|
+
name: tool.name,
|
|
140
|
+
parameters: tool.input_schema
|
|
141
|
+
},
|
|
142
|
+
type: "function"
|
|
143
|
+
}));
|
|
144
|
+
var buildRequestBody = (params) => {
|
|
145
|
+
const messages = convertToolResultMessages(params.messages.map((msg) => ({
|
|
146
|
+
content: typeof msg.content === "string" ? msg.content : null,
|
|
147
|
+
role: msg.role
|
|
148
|
+
})), params);
|
|
149
|
+
const body = {
|
|
150
|
+
messages,
|
|
151
|
+
model: params.model,
|
|
152
|
+
stream: true,
|
|
153
|
+
stream_options: { include_usage: true }
|
|
154
|
+
};
|
|
155
|
+
if (params.tools && params.tools.length > 0) {
|
|
156
|
+
body.tools = mapToolDefinitions(params.tools);
|
|
157
|
+
}
|
|
158
|
+
return body;
|
|
159
|
+
};
|
|
160
|
+
var parseToolInput = (rawArguments) => {
|
|
161
|
+
try {
|
|
162
|
+
return JSON.parse(rawArguments);
|
|
163
|
+
} catch {
|
|
164
|
+
return rawArguments;
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
var flushPendingToolCalls = function* (pendingToolCalls) {
|
|
168
|
+
for (const [, tool] of pendingToolCalls) {
|
|
169
|
+
const input = parseToolInput(tool.arguments);
|
|
170
|
+
yield {
|
|
171
|
+
id: tool.id,
|
|
172
|
+
input,
|
|
173
|
+
name: tool.name,
|
|
174
|
+
type: "tool_use"
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
pendingToolCalls.clear();
|
|
178
|
+
};
|
|
179
|
+
var extractUsage = (parsedUsage) => ({
|
|
180
|
+
inputTokens: parsedUsage.prompt_tokens ?? 0,
|
|
181
|
+
outputTokens: parsedUsage.completion_tokens ?? 0
|
|
182
|
+
});
|
|
183
|
+
var resolveToolCallIndex = (toolCall) => {
|
|
184
|
+
const raw = typeof toolCall.index === "number" ? toolCall.index : NOT_FOUND;
|
|
185
|
+
return raw < 0 ? undefined : raw;
|
|
186
|
+
};
|
|
187
|
+
var initPendingToolCall = (toolCall, func, index, pendingToolCalls) => {
|
|
188
|
+
if (pendingToolCalls.has(index)) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
const toolId = typeof toolCall.id === "string" ? toolCall.id : "";
|
|
192
|
+
const toolName = func && typeof func.name === "string" ? func.name : "";
|
|
193
|
+
pendingToolCalls.set(index, {
|
|
194
|
+
arguments: "",
|
|
195
|
+
id: toolId,
|
|
196
|
+
name: toolName
|
|
197
|
+
});
|
|
198
|
+
};
|
|
199
|
+
var updatePendingToolCall = (toolCall, func, pending) => {
|
|
200
|
+
if (typeof toolCall.id === "string") {
|
|
201
|
+
pending.id = toolCall.id;
|
|
202
|
+
}
|
|
203
|
+
if (func && typeof func.name === "string") {
|
|
204
|
+
pending.name = func.name;
|
|
205
|
+
}
|
|
206
|
+
if (func && typeof func.arguments === "string") {
|
|
207
|
+
pending.arguments += func.arguments;
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
var processToolCallDelta = (toolCall, pendingToolCalls) => {
|
|
211
|
+
const index = resolveToolCallIndex(toolCall);
|
|
212
|
+
if (index === undefined) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
const func = isRecord(toolCall.function) ? toolCall.function : null;
|
|
216
|
+
initPendingToolCall(toolCall, func, index, pendingToolCalls);
|
|
217
|
+
const pending = pendingToolCalls.get(index);
|
|
218
|
+
if (!pending) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
updatePendingToolCall(toolCall, func, pending);
|
|
222
|
+
};
|
|
223
|
+
var processToolCallDeltas = (toolCalls, pendingToolCalls) => {
|
|
224
|
+
for (const toolCall of toolCalls) {
|
|
225
|
+
processToolCallDelta(toolCall, pendingToolCalls);
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
var processDelta = function* (delta, pendingToolCalls) {
|
|
229
|
+
if (typeof delta.content === "string") {
|
|
230
|
+
yield { content: delta.content, type: "text" };
|
|
231
|
+
}
|
|
232
|
+
if (isRecordArray(delta.tool_calls)) {
|
|
233
|
+
processToolCallDeltas(delta.tool_calls, pendingToolCalls);
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
var processChoice = function* (choice, pendingToolCalls) {
|
|
237
|
+
const delta = isRecord(choice.delta) ? choice.delta : null;
|
|
238
|
+
if (delta) {
|
|
239
|
+
yield* processDelta(delta, pendingToolCalls);
|
|
240
|
+
}
|
|
241
|
+
if (choice.finish_reason === "tool_calls") {
|
|
242
|
+
yield* flushPendingToolCalls(pendingToolCalls);
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
var narrowUsageRecord = (parsed) => {
|
|
246
|
+
if (!isRecord(parsed.usage)) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
const { usage } = parsed;
|
|
250
|
+
const promptTokens = typeof usage.prompt_tokens === "number" ? usage.prompt_tokens : 0;
|
|
251
|
+
const completionTokens = typeof usage.completion_tokens === "number" ? usage.completion_tokens : 0;
|
|
252
|
+
return extractUsage({
|
|
253
|
+
completion_tokens: completionTokens,
|
|
254
|
+
prompt_tokens: promptTokens
|
|
255
|
+
});
|
|
256
|
+
};
|
|
257
|
+
var processSSELine = function* (line, pendingToolCalls, currentUsage) {
|
|
258
|
+
const trimmed = line.trim();
|
|
259
|
+
if (!trimmed || !trimmed.startsWith("data: ")) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
const data = trimmed.slice(SSE_DATA_PREFIX_LENGTH);
|
|
263
|
+
if (data === DONE_SENTINEL) {
|
|
264
|
+
yield* flushPendingToolCalls(pendingToolCalls);
|
|
265
|
+
yield { type: "done", usage: currentUsage };
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
let parsed;
|
|
269
|
+
try {
|
|
270
|
+
parsed = JSON.parse(data);
|
|
271
|
+
} catch {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
const usageUpdate = narrowUsageRecord(parsed);
|
|
275
|
+
if (usageUpdate) {
|
|
276
|
+
yield { type: "usage_update", usage: usageUpdate };
|
|
277
|
+
}
|
|
278
|
+
const { choices } = parsed;
|
|
279
|
+
if (!isRecordArray(choices)) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
const [firstChoice] = choices;
|
|
283
|
+
if (!firstChoice) {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
yield* processChoice(firstChoice, pendingToolCalls);
|
|
287
|
+
};
|
|
288
|
+
var isUsageUpdate = (chunk) => chunk.type === "usage_update";
|
|
289
|
+
var collectYieldableChunks = (line, pendingToolCalls, usageRef) => {
|
|
290
|
+
const allChunks = Array.from(processSSELine(line, pendingToolCalls, usageRef.current));
|
|
291
|
+
const usageChunks = allChunks.filter(isUsageUpdate);
|
|
292
|
+
const lastUsage = usageChunks.at(NOT_FOUND);
|
|
293
|
+
if (lastUsage) {
|
|
294
|
+
usageRef.current = lastUsage.usage;
|
|
295
|
+
}
|
|
296
|
+
return allChunks.filter((chunk) => !isUsageUpdate(chunk));
|
|
297
|
+
};
|
|
298
|
+
var processSSELines = function* (lines, pendingToolCalls, usageRef) {
|
|
299
|
+
for (const line of lines) {
|
|
300
|
+
yield* collectYieldableChunks(line, pendingToolCalls, usageRef);
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
var processStreamValue = (value, decoder, state) => {
|
|
304
|
+
state.buffer += decoder.decode(value, { stream: true });
|
|
305
|
+
const lines = state.buffer.split(`
|
|
306
|
+
`);
|
|
307
|
+
state.buffer = lines.pop() ?? "";
|
|
308
|
+
return lines;
|
|
309
|
+
};
|
|
310
|
+
var drainReader = async function* (reader, decoder, state, signal) {
|
|
311
|
+
for (let result = await reader.read();!result.done && !signal?.aborted; result = await reader.read()) {
|
|
312
|
+
const lines = processStreamValue(result.value, decoder, state);
|
|
313
|
+
yield* processSSELines(lines, state.pendingToolCalls, state.usageRef);
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
var parseSSEStream = async function* (body, signal) {
|
|
317
|
+
const reader = body.getReader();
|
|
318
|
+
const decoder = new TextDecoder;
|
|
319
|
+
const state = {
|
|
320
|
+
buffer: "",
|
|
321
|
+
pendingToolCalls: new Map,
|
|
322
|
+
usageRef: { current: undefined }
|
|
323
|
+
};
|
|
324
|
+
try {
|
|
325
|
+
yield* drainReader(reader, decoder, state, signal);
|
|
326
|
+
yield { type: "done", usage: state.usageRef.current };
|
|
327
|
+
} finally {
|
|
328
|
+
reader.releaseLock();
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
var fetchOpenAIStream = async function* (baseUrl, apiKey, body, signal) {
|
|
332
|
+
const response = await fetch(`${baseUrl}/v1/chat/completions`, {
|
|
333
|
+
body: JSON.stringify(body),
|
|
334
|
+
headers: {
|
|
335
|
+
Authorization: `Bearer ${apiKey}`,
|
|
336
|
+
"Content-Type": "application/json"
|
|
337
|
+
},
|
|
338
|
+
method: "POST",
|
|
339
|
+
signal
|
|
340
|
+
});
|
|
341
|
+
if (!response.ok) {
|
|
342
|
+
const errorText = await response.text();
|
|
343
|
+
throw new Error(`OpenAI API error ${response.status}: ${errorText}`);
|
|
344
|
+
}
|
|
345
|
+
if (!response.body) {
|
|
346
|
+
throw new Error("OpenAI API returned no response body");
|
|
347
|
+
}
|
|
348
|
+
yield* parseSSEStream(response.body, signal);
|
|
349
|
+
};
|
|
350
|
+
var openai = (config) => {
|
|
351
|
+
const baseUrl = config.baseUrl ?? DEFAULT_BASE_URL;
|
|
352
|
+
return {
|
|
353
|
+
stream: (params) => {
|
|
354
|
+
const body = buildRequestBody(params);
|
|
355
|
+
return fetchOpenAIStream(baseUrl, config.apiKey, body, params.signal);
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
// src/ai/providers/openaiCompatible.ts
|
|
361
|
+
var openaiCompatible = (config) => openai({ apiKey: config.apiKey, baseUrl: config.baseUrl });
|
|
362
|
+
var google = (config) => openaiCompatible({
|
|
363
|
+
apiKey: config.apiKey,
|
|
364
|
+
baseUrl: "https://generativelanguage.googleapis.com/v1beta/openai"
|
|
365
|
+
});
|
|
366
|
+
var xai = (config) => openaiCompatible({
|
|
367
|
+
apiKey: config.apiKey,
|
|
368
|
+
baseUrl: "https://api.x.ai"
|
|
369
|
+
});
|
|
370
|
+
var deepseek = (config) => openaiCompatible({
|
|
371
|
+
apiKey: config.apiKey,
|
|
372
|
+
baseUrl: "https://api.deepseek.com"
|
|
373
|
+
});
|
|
374
|
+
var mistralai = (config) => openaiCompatible({
|
|
375
|
+
apiKey: config.apiKey,
|
|
376
|
+
baseUrl: "https://api.mistral.ai"
|
|
377
|
+
});
|
|
378
|
+
var alibaba = (config) => openaiCompatible({
|
|
379
|
+
apiKey: config.apiKey,
|
|
380
|
+
baseUrl: "https://dashscope-intl.aliyuncs.com/compatible-mode"
|
|
381
|
+
});
|
|
382
|
+
export {
|
|
383
|
+
xai,
|
|
384
|
+
openaiCompatible,
|
|
385
|
+
mistralai,
|
|
386
|
+
google,
|
|
387
|
+
deepseek,
|
|
388
|
+
alibaba
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
//# debugId=C81C1E9A39CC1F9D64756E2164756E21
|
|
392
|
+
//# sourceMappingURL=openaiCompatible.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/ai/providers/openai.ts", "../src/ai/providers/openaiCompatible.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import type {\n\tAIProviderConfig,\n\tAIProviderContentBlock,\n\tAIProviderMessage,\n\tAIProviderStreamParams,\n\tAIProviderToolDefinition,\n\tAIUsage\n} from '../../../types/ai';\n\ntype OpenAIConfig = {\n\tapiKey: string;\n\tbaseUrl?: string;\n};\n\ntype OpenAIMessage = {\n\tcontent: string | null;\n\trole: 'user' | 'assistant' | 'system' | 'tool';\n\ttool_call_id?: string;\n\ttool_calls?: Array<{\n\t\tfunction: { arguments: string; name: string };\n\t\tid: string;\n\t\ttype: 'function';\n\t}>;\n};\n\ntype PendingToolCall = {\n\targuments: string;\n\tid: string;\n\tname: string;\n};\n\ntype UsageRef = {\n\tcurrent: AIUsage | undefined;\n};\n\ntype StreamState = {\n\tbuffer: string;\n\tpendingToolCalls: Map<number, PendingToolCall>;\n\tusageRef: UsageRef;\n};\n\nconst DEFAULT_BASE_URL = 'https://api.openai.com';\nconst SSE_DATA_PREFIX_LENGTH = 6;\nconst DONE_SENTINEL = '[DONE]';\nconst NOT_FOUND = -1;\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\nconst isToolResultBlock = (\n\tblock: AIProviderContentBlock\n): block is AIProviderContentBlock & {\n\tcontent: string;\n\ttool_use_id: string;\n\ttype: 'tool_result';\n} => block.type === 'tool_result';\n\nconst hasArrayContent = (\n\tmsg: AIProviderMessage\n): msg is AIProviderMessage & { content: AIProviderContentBlock[] } =>\n\ttypeof msg.content !== 'string' && Array.isArray(msg.content);\n\nconst buildToolMessages = (\n\tblocks: AIProviderContentBlock[]\n) => {\n\tconst toolUseBlocks = blocks.filter((block) => block.type === 'tool_use');\n\tconst toolResultBlocks = blocks.filter((block) => block.type === 'tool_result');\n\tconst messages: OpenAIMessage[] = [];\n\n\tif (toolUseBlocks.length > 0) {\n\t\tmessages.push({\n\t\t\tcontent: null,\n\t\t\trole: 'assistant',\n\t\t\ttool_calls: toolUseBlocks.map((block) => ({\n\t\t\t\tfunction: {\n\t\t\t\t\targuments: typeof block.input === 'string'\n\t\t\t\t\t\t? block.input\n\t\t\t\t\t\t: JSON.stringify(block.input),\n\t\t\t\t\tname: block.name\n\t\t\t\t},\n\t\t\t\tid: block.id,\n\t\t\t\ttype: 'function' as const\n\t\t\t}))\n\t\t});\n\t}\n\n\tfor (const result of toolResultBlocks) {\n\t\tmessages.push({\n\t\t\tcontent: typeof result.content === 'string' ? result.content : '',\n\t\t\trole: 'tool',\n\t\t\ttool_call_id: result.tool_use_id\n\t\t});\n\t}\n\n\treturn messages;\n};\n\nconst processMessageAtIndex = (\n\tresult: OpenAIMessage[],\n\tmsg: AIProviderMessage,\n\tidx: number\n) => {\n\tif (!hasArrayContent(msg)) {\n\t\treturn;\n\t}\n\n\tconst hasToolBlocks = msg.content.some(\n\t\t(block) => block.type === 'tool_use' || block.type === 'tool_result'\n\t);\n\n\tif (!hasToolBlocks) {\n\t\treturn;\n\t}\n\n\tconst toolMessages = buildToolMessages(msg.content);\n\tresult.splice(idx, 1, ...toolMessages);\n};\n\nconst convertSingleMessage = (\n\tresult: OpenAIMessage[],\n\tmsg: AIProviderMessage | undefined,\n\tidx: number\n) => {\n\tif (!msg) {\n\t\treturn;\n\t}\n\n\tprocessMessageAtIndex(result, msg, idx);\n};\n\nconst convertToolResultMessages = (\n\tmessages: OpenAIMessage[],\n\tparams: AIProviderStreamParams\n) => {\n\tconst result = [...messages];\n\n\tfor (let idx = 0; idx < params.messages.length; idx++) {\n\t\tconvertSingleMessage(result, params.messages[idx], idx);\n\t}\n\n\treturn result;\n};\n\nconst mapToolDefinitions = (tools: AIProviderToolDefinition[]) =>\n\ttools.map((tool) => ({\n\t\tfunction: {\n\t\t\tdescription: tool.description,\n\t\t\tname: tool.name,\n\t\t\tparameters: tool.input_schema\n\t\t},\n\t\ttype: 'function'\n\t}));\n\nconst buildRequestBody = (params: AIProviderStreamParams) => {\n\tconst messages = convertToolResultMessages(\n\t\tparams.messages.map((msg) => ({\n\t\t\tcontent: typeof msg.content === 'string' ? msg.content : null,\n\t\t\trole: msg.role\n\t\t})),\n\t\tparams\n\t);\n\n\tconst body: Record<string, unknown> = {\n\t\tmessages,\n\t\tmodel: params.model,\n\t\tstream: true,\n\t\tstream_options: { include_usage: true }\n\t};\n\n\tif (params.tools && params.tools.length > 0) {\n\t\tbody.tools = mapToolDefinitions(params.tools);\n\t}\n\n\treturn body;\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 flushPendingToolCalls = function* (\n\tpendingToolCalls: Map<number, PendingToolCall>\n) {\n\tfor (const [, tool] of pendingToolCalls) {\n\t\tconst input = parseToolInput(tool.arguments);\n\t\tyield {\n\t\t\tid: tool.id,\n\t\t\tinput,\n\t\t\tname: tool.name,\n\t\t\ttype: 'tool_use' as const\n\t\t};\n\t}\n\n\tpendingToolCalls.clear();\n};\n\nconst extractUsage = (parsedUsage: Record<string, number>) => ({\n\tinputTokens: parsedUsage.prompt_tokens ?? 0,\n\toutputTokens: parsedUsage.completion_tokens ?? 0\n});\n\nconst resolveToolCallIndex = (toolCall: Record<string, unknown>) => {\n\tconst raw = typeof toolCall.index === 'number' ? toolCall.index : NOT_FOUND;\n\n\treturn raw < 0 ? undefined : raw;\n};\n\nconst initPendingToolCall = (\n\ttoolCall: Record<string, unknown>,\n\tfunc: Record<string, unknown> | null,\n\tindex: number,\n\tpendingToolCalls: Map<number, PendingToolCall>\n) => {\n\tif (pendingToolCalls.has(index)) {\n\t\treturn;\n\t}\n\n\tconst toolId = typeof toolCall.id === 'string' ? toolCall.id : '';\n\tconst toolName = func && typeof func.name === 'string' ? func.name : '';\n\n\tpendingToolCalls.set(index, {\n\t\targuments: '',\n\t\tid: toolId,\n\t\tname: toolName\n\t});\n};\n\nconst updatePendingToolCall = (\n\ttoolCall: Record<string, unknown>,\n\tfunc: Record<string, unknown> | null,\n\tpending: PendingToolCall\n) => {\n\tif (typeof toolCall.id === 'string') {\n\t\tpending.id = toolCall.id;\n\t}\n\n\tif (func && typeof func.name === 'string') {\n\t\tpending.name = func.name;\n\t}\n\n\tif (func && typeof func.arguments === 'string') {\n\t\tpending.arguments += func.arguments;\n\t}\n};\n\nconst processToolCallDelta = (\n\ttoolCall: Record<string, unknown>,\n\tpendingToolCalls: Map<number, PendingToolCall>\n) => {\n\tconst index = resolveToolCallIndex(toolCall);\n\tif (index === undefined) {\n\t\treturn;\n\t}\n\n\tconst func = isRecord(toolCall.function) ? toolCall.function : null;\n\tinitPendingToolCall(toolCall, func, index, pendingToolCalls);\n\n\tconst pending = pendingToolCalls.get(index);\n\tif (!pending) {\n\t\treturn;\n\t}\n\n\tupdatePendingToolCall(toolCall, func, pending);\n};\n\nconst processToolCallDeltas = (\n\ttoolCalls: Array<Record<string, unknown>>,\n\tpendingToolCalls: Map<number, PendingToolCall>\n) => {\n\tfor (const toolCall of toolCalls) {\n\t\tprocessToolCallDelta(toolCall, pendingToolCalls);\n\t}\n};\n\nconst processDelta = function* (\n\tdelta: Record<string, unknown>,\n\tpendingToolCalls: Map<number, PendingToolCall>\n) {\n\tif (typeof delta.content === 'string') {\n\t\tyield { content: delta.content, type: 'text' as const };\n\t}\n\n\tif (isRecordArray(delta.tool_calls)) {\n\t\tprocessToolCallDeltas(delta.tool_calls, pendingToolCalls);\n\t}\n};\n\nconst processChoice = function* (\n\tchoice: Record<string, unknown>,\n\tpendingToolCalls: Map<number, PendingToolCall>\n) {\n\tconst delta = isRecord(choice.delta) ? choice.delta : null;\n\tif (delta) {\n\t\tyield* processDelta(delta, pendingToolCalls);\n\t}\n\n\tif (choice.finish_reason === 'tool_calls') {\n\t\tyield* flushPendingToolCalls(pendingToolCalls);\n\t}\n};\n\nconst narrowUsageRecord = (parsed: Record<string, unknown>) => {\n\tif (!isRecord(parsed.usage)) {\n\t\treturn undefined;\n\t}\n\n\tconst { usage } = parsed;\n\tconst promptTokens =\n\t\ttypeof usage.prompt_tokens === 'number' ? usage.prompt_tokens : 0;\n\tconst completionTokens =\n\t\ttypeof usage.completion_tokens === 'number'\n\t\t\t? usage.completion_tokens\n\t\t\t: 0;\n\n\treturn extractUsage({\n\t\tcompletion_tokens: completionTokens,\n\t\tprompt_tokens: promptTokens\n\t});\n};\n\nconst processSSELine = function* (\n\tline: string,\n\tpendingToolCalls: Map<number, PendingToolCall>,\n\tcurrentUsage: AIUsage | undefined\n) {\n\tconst trimmed = line.trim();\n\tif (!trimmed || !trimmed.startsWith('data: ')) {\n\t\treturn;\n\t}\n\n\tconst data = trimmed.slice(SSE_DATA_PREFIX_LENGTH);\n\tif (data === DONE_SENTINEL) {\n\t\tyield* flushPendingToolCalls(pendingToolCalls);\n\t\tyield { type: 'done' as const, usage: currentUsage };\n\n\t\treturn;\n\t}\n\n\tlet parsed: Record<string, unknown>;\n\ttry {\n\t\tparsed = JSON.parse(data);\n\t} catch {\n\t\treturn;\n\t}\n\n\tconst usageUpdate = narrowUsageRecord(parsed);\n\tif (usageUpdate) {\n\t\tyield { type: 'usage_update' as const, usage: usageUpdate };\n\t}\n\n\tconst { choices } = parsed;\n\tif (!isRecordArray(choices)) {\n\t\treturn;\n\t}\n\n\tconst [firstChoice] = choices;\n\tif (!firstChoice) {\n\t\treturn;\n\t}\n\n\tyield* processChoice(firstChoice, pendingToolCalls);\n};\n\nconst isUsageUpdate = (chunk: {\n\ttype: string;\n\tusage?: AIUsage;\n}): chunk is { type: 'usage_update'; usage: AIUsage } =>\n\tchunk.type === 'usage_update';\n\nconst collectYieldableChunks = (\n\tline: string,\n\tpendingToolCalls: Map<number, PendingToolCall>,\n\tusageRef: UsageRef\n) => {\n\tconst allChunks = Array.from(\n\t\tprocessSSELine(line, pendingToolCalls, usageRef.current)\n\t);\n\tconst usageChunks = allChunks.filter(isUsageUpdate);\n\tconst lastUsage = usageChunks.at(NOT_FOUND);\n\n\tif (lastUsage) {\n\t\tusageRef.current = lastUsage.usage;\n\t}\n\n\treturn allChunks.filter((chunk) => !isUsageUpdate(chunk));\n};\n\nconst processSSELines = function* (\n\tlines: string[],\n\tpendingToolCalls: Map<number, PendingToolCall>,\n\tusageRef: UsageRef\n) {\n\tfor (const line of lines) {\n\t\tyield* collectYieldableChunks(line, pendingToolCalls, usageRef);\n\t}\n};\n\nconst processStreamValue = (\n\tvalue: Uint8Array,\n\tdecoder: TextDecoder,\n\tstate: StreamState\n) => {\n\tstate.buffer += decoder.decode(value, { stream: true });\n\tconst lines = state.buffer.split('\\n');\n\tstate.buffer = lines.pop() ?? '';\n\n\treturn lines;\n};\n\nconst drainReader = async function* (\n\treader: ReadableStreamDefaultReader<Uint8Array>,\n\tdecoder: TextDecoder,\n\tstate: StreamState,\n\tsignal?: AbortSignal\n) {\n\t/* eslint-disable no-await-in-loop */\n\tfor (\n\t\tlet result = await reader.read();\n\t\t!result.done && !signal?.aborted;\n\t\tresult = await reader.read()\n\t) {\n\t\t/* eslint-enable no-await-in-loop */\n\t\tconst lines = processStreamValue(result.value, decoder, state);\n\t\tyield* processSSELines(lines, state.pendingToolCalls, state.usageRef);\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\tpendingToolCalls: new Map<number, PendingToolCall>(),\n\t\tusageRef: { current: undefined }\n\t};\n\n\ttry {\n\t\tyield* drainReader(reader, decoder, state, signal);\n\t\tyield { type: 'done' as const, usage: state.usageRef.current };\n\t} finally {\n\t\treader.releaseLock();\n\t}\n};\n\nconst fetchOpenAIStream = async function* (\n\tbaseUrl: string,\n\tapiKey: string,\n\tbody: Record<string, unknown>,\n\tsignal?: AbortSignal\n) {\n\tconst response = await fetch(`${baseUrl}/v1/chat/completions`, {\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(`OpenAI API error ${response.status}: ${errorText}`);\n\t}\n\n\tif (!response.body) {\n\t\tthrow new Error('OpenAI API returned no response body');\n\t}\n\n\tyield* parseSSEStream(response.body, signal);\n};\n\nexport const openai = (config: OpenAIConfig): AIProviderConfig => {\n\tconst baseUrl = config.baseUrl ?? DEFAULT_BASE_URL;\n\n\treturn {\n\t\tstream: (params: AIProviderStreamParams) => {\n\t\t\tconst body = buildRequestBody(params);\n\n\t\t\treturn fetchOpenAIStream(\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};\n};\n",
|
|
6
|
+
"import type { AIProviderConfig } from '../../../types/ai';\nimport { openai } from './openai';\n\n/**\n * Creates a provider for any OpenAI-compatible API.\n * Many providers (Google, xAI, DeepSeek, Mistral, etc.)\n * expose OpenAI-compatible chat completion endpoints.\n */\nexport const openaiCompatible = (config: {\n\tapiKey: string;\n\tbaseUrl: string;\n}): AIProviderConfig => openai({ apiKey: config.apiKey, baseUrl: config.baseUrl });\n\nexport const google = (config: { apiKey: string }) =>\n\topenaiCompatible({\n\t\tapiKey: config.apiKey,\n\t\tbaseUrl: 'https://generativelanguage.googleapis.com/v1beta/openai'\n\t});\n\nexport const xai = (config: { apiKey: string }) =>\n\topenaiCompatible({\n\t\tapiKey: config.apiKey,\n\t\tbaseUrl: 'https://api.x.ai'\n\t});\n\nexport const deepseek = (config: { apiKey: string }) =>\n\topenaiCompatible({\n\t\tapiKey: config.apiKey,\n\t\tbaseUrl: 'https://api.deepseek.com'\n\t});\n\nexport const mistralai = (config: { apiKey: string }) =>\n\topenaiCompatible({\n\t\tapiKey: config.apiKey,\n\t\tbaseUrl: 'https://api.mistral.ai'\n\t});\n\nexport const alibaba = (config: { apiKey: string }) =>\n\topenaiCompatible({\n\t\tapiKey: config.apiKey,\n\t\tbaseUrl: 'https://dashscope-intl.aliyuncs.com/compatible-mode'\n\t});\n"
|
|
7
|
+
],
|
|
8
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,IAAM,mBAAmB;AACzB,IAAM,yBAAyB;AAC/B,IAAM,gB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AAM,UAAU,CAAC,WACvB,iBAAiB;AAAA,EAChB,QAAQ,OAAO;AAAA,EACf,SAAS;AACV,CAAC;",
|
|
9
|
+
"debugId": "C81C1E9A39CC1F9D64756E2164756E21",
|
|
10
|
+
"names": []
|
|
11
|
+
}
|
|
@@ -216,7 +216,7 @@ var findAssistantMessage = (conversation, messageId) => conversation.messages.fi
|
|
|
216
216
|
var getOrCreate = (state, conversationId) => {
|
|
217
217
|
let conversation = state.conversations.get(conversationId);
|
|
218
218
|
if (!conversation) {
|
|
219
|
-
conversation = { id: conversationId, messages: [] };
|
|
219
|
+
conversation = { createdAt: Date.now(), id: conversationId, messages: [] };
|
|
220
220
|
state.conversations.set(conversationId, conversation);
|
|
221
221
|
}
|
|
222
222
|
return conversation;
|
|
@@ -329,6 +329,7 @@ var handleBranch = (state, action) => {
|
|
|
329
329
|
}
|
|
330
330
|
const branchedMessages = source.messages.slice(0, cutoffIndex + 1).map((msg) => ({ ...msg, conversationId: action.newConversationId }));
|
|
331
331
|
const newConversation = {
|
|
332
|
+
createdAt: Date.now(),
|
|
332
333
|
id: action.newConversationId,
|
|
333
334
|
messages: branchedMessages
|
|
334
335
|
};
|
|
@@ -185,7 +185,7 @@ var findAssistantMessage = (conversation, messageId) => conversation.messages.fi
|
|
|
185
185
|
var getOrCreate = (state, conversationId) => {
|
|
186
186
|
let conversation = state.conversations.get(conversationId);
|
|
187
187
|
if (!conversation) {
|
|
188
|
-
conversation = { id: conversationId, messages: [] };
|
|
188
|
+
conversation = { createdAt: Date.now(), id: conversationId, messages: [] };
|
|
189
189
|
state.conversations.set(conversationId, conversation);
|
|
190
190
|
}
|
|
191
191
|
return conversation;
|
|
@@ -298,6 +298,7 @@ var handleBranch = (state, action) => {
|
|
|
298
298
|
}
|
|
299
299
|
const branchedMessages = source.messages.slice(0, cutoffIndex + 1).map((msg) => ({ ...msg, conversationId: action.newConversationId }));
|
|
300
300
|
const newConversation = {
|
|
301
|
+
createdAt: Date.now(),
|
|
301
302
|
id: action.newConversationId,
|
|
302
303
|
messages: branchedMessages
|
|
303
304
|
};
|
|
@@ -216,7 +216,7 @@ var findAssistantMessage = (conversation, messageId) => conversation.messages.fi
|
|
|
216
216
|
var getOrCreate = (state, conversationId) => {
|
|
217
217
|
let conversation = state.conversations.get(conversationId);
|
|
218
218
|
if (!conversation) {
|
|
219
|
-
conversation = { id: conversationId, messages: [] };
|
|
219
|
+
conversation = { createdAt: Date.now(), id: conversationId, messages: [] };
|
|
220
220
|
state.conversations.set(conversationId, conversation);
|
|
221
221
|
}
|
|
222
222
|
return conversation;
|
|
@@ -329,6 +329,7 @@ var handleBranch = (state, action) => {
|
|
|
329
329
|
}
|
|
330
330
|
const branchedMessages = source.messages.slice(0, cutoffIndex + 1).map((msg) => ({ ...msg, conversationId: action.newConversationId }));
|
|
331
331
|
const newConversation = {
|
|
332
|
+
createdAt: Date.now(),
|
|
332
333
|
id: action.newConversationId,
|
|
333
334
|
messages: branchedMessages
|
|
334
335
|
};
|
package/dist/angular/ai/index.js
CHANGED
|
@@ -319,7 +319,7 @@ var findAssistantMessage = (conversation, messageId) => conversation.messages.fi
|
|
|
319
319
|
var getOrCreate = (state, conversationId) => {
|
|
320
320
|
let conversation = state.conversations.get(conversationId);
|
|
321
321
|
if (!conversation) {
|
|
322
|
-
conversation = { id: conversationId, messages: [] };
|
|
322
|
+
conversation = { createdAt: Date.now(), id: conversationId, messages: [] };
|
|
323
323
|
state.conversations.set(conversationId, conversation);
|
|
324
324
|
}
|
|
325
325
|
return conversation;
|
|
@@ -432,6 +432,7 @@ var handleBranch = (state, action) => {
|
|
|
432
432
|
}
|
|
433
433
|
const branchedMessages = source.messages.slice(0, cutoffIndex + 1).map((msg) => ({ ...msg, conversationId: action.newConversationId }));
|
|
434
434
|
const newConversation = {
|
|
435
|
+
createdAt: Date.now(),
|
|
435
436
|
id: action.newConversationId,
|
|
436
437
|
messages: branchedMessages
|
|
437
438
|
};
|
|
@@ -677,5 +678,5 @@ export {
|
|
|
677
678
|
AIStreamService
|
|
678
679
|
};
|
|
679
680
|
|
|
680
|
-
//# debugId=
|
|
681
|
+
//# debugId=C542E7509B2612D464756E2164756E21
|
|
681
682
|
//# sourceMappingURL=index.js.map
|