@runanywhere/web-llamacpp 0.1.0-beta.10
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 +75 -0
- package/dist/Extensions/DiffusionTypes.d.ts +64 -0
- package/dist/Extensions/DiffusionTypes.d.ts.map +1 -0
- package/dist/Extensions/DiffusionTypes.js +28 -0
- package/dist/Extensions/DiffusionTypes.js.map +1 -0
- package/dist/Extensions/EmbeddingsTypes.d.ts +33 -0
- package/dist/Extensions/EmbeddingsTypes.d.ts.map +1 -0
- package/dist/Extensions/EmbeddingsTypes.js +13 -0
- package/dist/Extensions/EmbeddingsTypes.js.map +1 -0
- package/dist/Extensions/RunAnywhere+Diffusion.d.ts +44 -0
- package/dist/Extensions/RunAnywhere+Diffusion.d.ts.map +1 -0
- package/dist/Extensions/RunAnywhere+Diffusion.js +185 -0
- package/dist/Extensions/RunAnywhere+Diffusion.js.map +1 -0
- package/dist/Extensions/RunAnywhere+Embeddings.d.ts +56 -0
- package/dist/Extensions/RunAnywhere+Embeddings.d.ts.map +1 -0
- package/dist/Extensions/RunAnywhere+Embeddings.js +236 -0
- package/dist/Extensions/RunAnywhere+Embeddings.js.map +1 -0
- package/dist/Extensions/RunAnywhere+StructuredOutput.d.ts +69 -0
- package/dist/Extensions/RunAnywhere+StructuredOutput.d.ts.map +1 -0
- package/dist/Extensions/RunAnywhere+StructuredOutput.js +194 -0
- package/dist/Extensions/RunAnywhere+StructuredOutput.js.map +1 -0
- package/dist/Extensions/RunAnywhere+TextGeneration.d.ts +87 -0
- package/dist/Extensions/RunAnywhere+TextGeneration.d.ts.map +1 -0
- package/dist/Extensions/RunAnywhere+TextGeneration.js +525 -0
- package/dist/Extensions/RunAnywhere+TextGeneration.js.map +1 -0
- package/dist/Extensions/RunAnywhere+ToolCalling.d.ts +82 -0
- package/dist/Extensions/RunAnywhere+ToolCalling.d.ts.map +1 -0
- package/dist/Extensions/RunAnywhere+ToolCalling.js +574 -0
- package/dist/Extensions/RunAnywhere+ToolCalling.js.map +1 -0
- package/dist/Extensions/RunAnywhere+VLM.d.ts +57 -0
- package/dist/Extensions/RunAnywhere+VLM.d.ts.map +1 -0
- package/dist/Extensions/RunAnywhere+VLM.js +258 -0
- package/dist/Extensions/RunAnywhere+VLM.js.map +1 -0
- package/dist/Extensions/ToolCallingTypes.d.ts +78 -0
- package/dist/Extensions/ToolCallingTypes.d.ts.map +1 -0
- package/dist/Extensions/ToolCallingTypes.js +8 -0
- package/dist/Extensions/ToolCallingTypes.js.map +1 -0
- package/dist/Extensions/VLMTypes.d.ts +16 -0
- package/dist/Extensions/VLMTypes.d.ts.map +1 -0
- package/dist/Extensions/VLMTypes.js +18 -0
- package/dist/Extensions/VLMTypes.js.map +1 -0
- package/dist/Foundation/AnalyticsEventsBridge.d.ts +38 -0
- package/dist/Foundation/AnalyticsEventsBridge.d.ts.map +1 -0
- package/dist/Foundation/AnalyticsEventsBridge.js +394 -0
- package/dist/Foundation/AnalyticsEventsBridge.js.map +1 -0
- package/dist/Foundation/LlamaCppBridge.d.ts +182 -0
- package/dist/Foundation/LlamaCppBridge.d.ts.map +1 -0
- package/dist/Foundation/LlamaCppBridge.js +483 -0
- package/dist/Foundation/LlamaCppBridge.js.map +1 -0
- package/dist/Foundation/LlamaCppOffsets.d.ts +32 -0
- package/dist/Foundation/LlamaCppOffsets.d.ts.map +1 -0
- package/dist/Foundation/LlamaCppOffsets.js +191 -0
- package/dist/Foundation/LlamaCppOffsets.js.map +1 -0
- package/dist/Foundation/PlatformAdapter.d.ts +109 -0
- package/dist/Foundation/PlatformAdapter.d.ts.map +1 -0
- package/dist/Foundation/PlatformAdapter.js +417 -0
- package/dist/Foundation/PlatformAdapter.js.map +1 -0
- package/dist/Foundation/TelemetryService.d.ts +96 -0
- package/dist/Foundation/TelemetryService.d.ts.map +1 -0
- package/dist/Foundation/TelemetryService.js +345 -0
- package/dist/Foundation/TelemetryService.js.map +1 -0
- package/dist/Foundation/WASMAnalyticsEmitter.d.ts +29 -0
- package/dist/Foundation/WASMAnalyticsEmitter.d.ts.map +1 -0
- package/dist/Foundation/WASMAnalyticsEmitter.js +70 -0
- package/dist/Foundation/WASMAnalyticsEmitter.js.map +1 -0
- package/dist/Infrastructure/VLMWorkerBridge.d.ts +219 -0
- package/dist/Infrastructure/VLMWorkerBridge.d.ts.map +1 -0
- package/dist/Infrastructure/VLMWorkerBridge.js +288 -0
- package/dist/Infrastructure/VLMWorkerBridge.js.map +1 -0
- package/dist/Infrastructure/VLMWorkerRuntime.d.ts +38 -0
- package/dist/Infrastructure/VLMWorkerRuntime.d.ts.map +1 -0
- package/dist/Infrastructure/VLMWorkerRuntime.js +620 -0
- package/dist/Infrastructure/VLMWorkerRuntime.js.map +1 -0
- package/dist/LlamaCPP.d.ts +49 -0
- package/dist/LlamaCPP.d.ts.map +1 -0
- package/dist/LlamaCPP.js +63 -0
- package/dist/LlamaCPP.js.map +1 -0
- package/dist/LlamaCppProvider.d.ts +32 -0
- package/dist/LlamaCppProvider.d.ts.map +1 -0
- package/dist/LlamaCppProvider.js +106 -0
- package/dist/LlamaCppProvider.js.map +1 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +41 -0
- package/dist/index.js.map +1 -0
- package/dist/workers/vlm-worker.d.ts +9 -0
- package/dist/workers/vlm-worker.d.ts.map +1 -0
- package/dist/workers/vlm-worker.js +10 -0
- package/dist/workers/vlm-worker.js.map +1 -0
- package/package.json +69 -0
- package/wasm/racommons-llamacpp-webgpu.js +159 -0
- package/wasm/racommons-llamacpp-webgpu.wasm +0 -0
- package/wasm/racommons-llamacpp.js +129 -0
- package/wasm/racommons-llamacpp.wasm +0 -0
|
@@ -0,0 +1,574 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RunAnywhere Web SDK - Tool Calling Extension
|
|
3
|
+
*
|
|
4
|
+
* Adds tool calling (function calling) capabilities to LLM generation.
|
|
5
|
+
* The LLM can request external actions (API calls, calculations, etc.)
|
|
6
|
+
* and the SDK orchestrates the generate -> parse -> execute -> loop cycle.
|
|
7
|
+
*
|
|
8
|
+
* Architecture:
|
|
9
|
+
* - C++ (rac_tool_calling.h): ALL parsing, prompt formatting, JSON handling
|
|
10
|
+
* - This file: Tool registry, executor storage, orchestration
|
|
11
|
+
*
|
|
12
|
+
* Mirrors: sdk/runanywhere-swift/Sources/RunAnywhere/Public/Extensions/LLM/
|
|
13
|
+
*
|
|
14
|
+
* Usage:
|
|
15
|
+
* import { ToolCalling } from '@runanywhere/web';
|
|
16
|
+
*
|
|
17
|
+
* ToolCalling.registerTool(
|
|
18
|
+
* { name: 'get_weather', description: 'Gets weather', parameters: [...] },
|
|
19
|
+
* async (args) => ({ temperature: '72F', condition: 'Sunny' })
|
|
20
|
+
* );
|
|
21
|
+
*
|
|
22
|
+
* const result = await ToolCalling.generateWithTools('What is the weather?');
|
|
23
|
+
* console.log(result.text);
|
|
24
|
+
*/
|
|
25
|
+
import { RunAnywhere, SDKError, SDKErrorCode, SDKLogger } from '@runanywhere/web';
|
|
26
|
+
import { LlamaCppBridge } from '../Foundation/LlamaCppBridge';
|
|
27
|
+
import { TextGeneration } from './RunAnywhere+TextGeneration';
|
|
28
|
+
import { ToolCallFormat, } from './ToolCallingTypes';
|
|
29
|
+
export { ToolCallFormat, } from './ToolCallingTypes';
|
|
30
|
+
const logger = new SDKLogger('ToolCalling');
|
|
31
|
+
/**
|
|
32
|
+
* Generate text and return the complete result.
|
|
33
|
+
*
|
|
34
|
+
* Uses the streaming path (`generateStream`) and drains the token stream
|
|
35
|
+
* to collect the full response text. On WebGPU + JSPI builds the
|
|
36
|
+
* non-streaming `generate()` C function triggers "trying to suspend
|
|
37
|
+
* JS frames" because the Emscripten JSPI `Suspending` wrapper cannot
|
|
38
|
+
* unwind through mixed WASM/JS frames in the non-streaming code path.
|
|
39
|
+
* The streaming path works because its token callbacks return to JS
|
|
40
|
+
* cleanly between each suspension point.
|
|
41
|
+
*/
|
|
42
|
+
async function collectGeneration(prompt, opts) {
|
|
43
|
+
const { stream } = await TextGeneration.generateStream(prompt, opts);
|
|
44
|
+
let text = '';
|
|
45
|
+
for await (const token of stream) {
|
|
46
|
+
text += token;
|
|
47
|
+
}
|
|
48
|
+
return { text };
|
|
49
|
+
}
|
|
50
|
+
function requireBridge() {
|
|
51
|
+
if (!RunAnywhere.isInitialized)
|
|
52
|
+
throw SDKError.notInitialized();
|
|
53
|
+
return LlamaCppBridge.shared;
|
|
54
|
+
}
|
|
55
|
+
// ---------------------------------------------------------------------------
|
|
56
|
+
// ToolValue helpers
|
|
57
|
+
// ---------------------------------------------------------------------------
|
|
58
|
+
/** Create a ToolValue from a plain JS value. */
|
|
59
|
+
export function toToolValue(val) {
|
|
60
|
+
if (val === null || val === undefined)
|
|
61
|
+
return { type: 'null' };
|
|
62
|
+
if (typeof val === 'string')
|
|
63
|
+
return { type: 'string', value: val };
|
|
64
|
+
if (typeof val === 'number')
|
|
65
|
+
return { type: 'number', value: val };
|
|
66
|
+
if (typeof val === 'boolean')
|
|
67
|
+
return { type: 'boolean', value: val };
|
|
68
|
+
if (Array.isArray(val))
|
|
69
|
+
return { type: 'array', value: val.map(toToolValue) };
|
|
70
|
+
if (typeof val === 'object') {
|
|
71
|
+
const obj = {};
|
|
72
|
+
for (const [k, v] of Object.entries(val)) {
|
|
73
|
+
obj[k] = toToolValue(v);
|
|
74
|
+
}
|
|
75
|
+
return { type: 'object', value: obj };
|
|
76
|
+
}
|
|
77
|
+
return { type: 'null' };
|
|
78
|
+
}
|
|
79
|
+
/** Convert a ToolValue to a plain JS value. */
|
|
80
|
+
export function fromToolValue(tv) {
|
|
81
|
+
switch (tv.type) {
|
|
82
|
+
case 'string': return tv.value;
|
|
83
|
+
case 'number': return tv.value;
|
|
84
|
+
case 'boolean': return tv.value;
|
|
85
|
+
case 'array': return tv.value.map(fromToolValue);
|
|
86
|
+
case 'object': {
|
|
87
|
+
const obj = {};
|
|
88
|
+
for (const [k, v] of Object.entries(tv.value)) {
|
|
89
|
+
obj[k] = fromToolValue(v);
|
|
90
|
+
}
|
|
91
|
+
return obj;
|
|
92
|
+
}
|
|
93
|
+
case 'null': return null;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/** Get a string argument from tool call args. */
|
|
97
|
+
export function getStringArg(args, key) {
|
|
98
|
+
const v = args[key];
|
|
99
|
+
return v?.type === 'string' ? v.value : undefined;
|
|
100
|
+
}
|
|
101
|
+
/** Get a number argument from tool call args. */
|
|
102
|
+
export function getNumberArg(args, key) {
|
|
103
|
+
const v = args[key];
|
|
104
|
+
return v?.type === 'number' ? v.value : undefined;
|
|
105
|
+
}
|
|
106
|
+
// ---------------------------------------------------------------------------
|
|
107
|
+
// Internal: C++ Bridge helpers
|
|
108
|
+
// ---------------------------------------------------------------------------
|
|
109
|
+
/**
|
|
110
|
+
* Check if C++ tool calling functions are available in the WASM module.
|
|
111
|
+
*
|
|
112
|
+
* On WebGPU builds, all WASM imports are wrapped with WebAssembly.Suspending.
|
|
113
|
+
* Synchronous ccall to C++ tool-calling functions (which are NOT
|
|
114
|
+
* WebAssembly.promising-wrapped) will throw "trying to suspend without
|
|
115
|
+
* WebAssembly.promising" if any import inside the C++ code returns a Promise.
|
|
116
|
+
* To avoid this, we always use the TypeScript fallback on WebGPU builds.
|
|
117
|
+
*/
|
|
118
|
+
function hasNativeToolCalling() {
|
|
119
|
+
try {
|
|
120
|
+
const bridge = requireBridge();
|
|
121
|
+
// WebGPU builds have JSPI Suspending on ALL imports, so synchronous
|
|
122
|
+
// ccall to native tool helpers triggers SuspendError. Use TS fallback.
|
|
123
|
+
if (bridge.accelerationMode === 'webgpu')
|
|
124
|
+
return false;
|
|
125
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
126
|
+
return typeof bridge.module['_rac_tool_call_parse'] === 'function';
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Parse LLM output for tool calls.
|
|
134
|
+
* Uses C++ when available, falls back to TypeScript regex parsing.
|
|
135
|
+
*/
|
|
136
|
+
function parseToolCall(llmOutput) {
|
|
137
|
+
if (hasNativeToolCalling()) {
|
|
138
|
+
return parseToolCallNative(llmOutput);
|
|
139
|
+
}
|
|
140
|
+
return parseToolCallTS(llmOutput);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Parse via C++ rac_tool_call_parse.
|
|
144
|
+
*/
|
|
145
|
+
function parseToolCallNative(llmOutput) {
|
|
146
|
+
const bridge = requireBridge();
|
|
147
|
+
const m = bridge.module;
|
|
148
|
+
// Allocate result struct (rac_tool_call_t)
|
|
149
|
+
// Fields: has_tool_call (i32), tool_name (ptr), arguments_json (ptr),
|
|
150
|
+
// clean_text (ptr), call_id (i64), format (i32)
|
|
151
|
+
const resultSize = 40; // generous
|
|
152
|
+
const resultPtr = m._malloc(resultSize);
|
|
153
|
+
for (let i = 0; i < resultSize; i++)
|
|
154
|
+
m.setValue(resultPtr + i, 0, 'i8');
|
|
155
|
+
const inputPtr = bridge.allocString(llmOutput);
|
|
156
|
+
try {
|
|
157
|
+
const rc = m.ccall('rac_tool_call_parse', 'number', ['number', 'number'], [inputPtr, resultPtr]);
|
|
158
|
+
const hasToolCall = m.getValue(resultPtr, 'i32');
|
|
159
|
+
const toolNamePtr = m.getValue(resultPtr + 4, '*');
|
|
160
|
+
const argsJsonPtr = m.getValue(resultPtr + 8, '*');
|
|
161
|
+
const cleanTextPtr = m.getValue(resultPtr + 12, '*');
|
|
162
|
+
const callId = m.getValue(resultPtr + 16, 'i32');
|
|
163
|
+
const cleanText = cleanTextPtr ? bridge.readString(cleanTextPtr) : llmOutput;
|
|
164
|
+
if (rc !== 0 || hasToolCall !== 1 || !toolNamePtr) {
|
|
165
|
+
// Free the result struct
|
|
166
|
+
m.ccall('rac_tool_call_free', null, ['number'], [resultPtr]);
|
|
167
|
+
return { text: cleanText, toolCall: null };
|
|
168
|
+
}
|
|
169
|
+
const toolName = bridge.readString(toolNamePtr);
|
|
170
|
+
const argsJson = argsJsonPtr ? bridge.readString(argsJsonPtr) : '{}';
|
|
171
|
+
const args = parseJsonToToolValues(argsJson);
|
|
172
|
+
// Free the result struct
|
|
173
|
+
m.ccall('rac_tool_call_free', null, ['number'], [resultPtr]);
|
|
174
|
+
return {
|
|
175
|
+
text: cleanText,
|
|
176
|
+
toolCall: {
|
|
177
|
+
toolName,
|
|
178
|
+
arguments: args,
|
|
179
|
+
callId: `call_${callId}`,
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
finally {
|
|
184
|
+
bridge.free(inputPtr);
|
|
185
|
+
m._free(resultPtr);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* TypeScript fallback parser for when WASM doesn't have tool_calling compiled.
|
|
190
|
+
* Handles both default and LFM2 formats.
|
|
191
|
+
*/
|
|
192
|
+
function parseToolCallTS(llmOutput) {
|
|
193
|
+
// Try default format: <tool_call>{"tool":"name","arguments":{...}}</tool_call>
|
|
194
|
+
const defaultMatch = llmOutput.match(/<tool_call>([\s\S]*?)(?:<\/tool_call>|$)/);
|
|
195
|
+
if (defaultMatch) {
|
|
196
|
+
const jsonStr = defaultMatch[1].trim();
|
|
197
|
+
const cleanText = llmOutput.replace(/<tool_call>[\s\S]*?(?:<\/tool_call>|$)/, '').trim();
|
|
198
|
+
try {
|
|
199
|
+
const parsed = JSON.parse(jsonStr);
|
|
200
|
+
const toolName = parsed.tool || parsed.name || parsed.function || '';
|
|
201
|
+
const rawArgs = parsed.arguments || parsed.args || parsed.parameters || {};
|
|
202
|
+
return {
|
|
203
|
+
text: cleanText,
|
|
204
|
+
toolCall: {
|
|
205
|
+
toolName,
|
|
206
|
+
arguments: jsonToToolValues(rawArgs),
|
|
207
|
+
callId: `call_${Date.now()}`,
|
|
208
|
+
},
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
catch {
|
|
212
|
+
// Try to fix common LLM JSON issues (unquoted keys)
|
|
213
|
+
try {
|
|
214
|
+
const fixed = jsonStr.replace(/([{,]\s*)(\w+)\s*:/g, '$1"$2":');
|
|
215
|
+
const parsed = JSON.parse(fixed);
|
|
216
|
+
const toolName = parsed.tool || parsed.name || parsed.function || '';
|
|
217
|
+
const rawArgs = parsed.arguments || parsed.args || parsed.parameters || {};
|
|
218
|
+
return {
|
|
219
|
+
text: cleanText,
|
|
220
|
+
toolCall: {
|
|
221
|
+
toolName,
|
|
222
|
+
arguments: jsonToToolValues(rawArgs),
|
|
223
|
+
callId: `call_${Date.now()}`,
|
|
224
|
+
},
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
catch {
|
|
228
|
+
return { text: llmOutput, toolCall: null };
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
// Try LFM2 format: <|tool_call_start|>[func_name(arg="val")]<|tool_call_end|>
|
|
233
|
+
const lfm2Match = llmOutput.match(/<\|tool_call_start\|>\s*\[(\w+)\((.*?)\)\]\s*<\|tool_call_end\|>/);
|
|
234
|
+
if (lfm2Match) {
|
|
235
|
+
const funcName = lfm2Match[1];
|
|
236
|
+
const argsStr = lfm2Match[2];
|
|
237
|
+
const cleanText = llmOutput.replace(/<\|tool_call_start\|>[\s\S]*?<\|tool_call_end\|>/, '').trim();
|
|
238
|
+
// Parse LFM2 arguments: arg1="val1", arg2="val2"
|
|
239
|
+
const args = {};
|
|
240
|
+
const argPattern = /(\w+)="([^"]*)"/g;
|
|
241
|
+
let argMatch;
|
|
242
|
+
while ((argMatch = argPattern.exec(argsStr)) !== null) {
|
|
243
|
+
args[argMatch[1]] = { type: 'string', value: argMatch[2] };
|
|
244
|
+
}
|
|
245
|
+
return {
|
|
246
|
+
text: cleanText,
|
|
247
|
+
toolCall: {
|
|
248
|
+
toolName: funcName,
|
|
249
|
+
arguments: args,
|
|
250
|
+
callId: `call_${Date.now()}`,
|
|
251
|
+
},
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
return { text: llmOutput, toolCall: null };
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Format tool definitions into system prompt.
|
|
258
|
+
* Uses C++ when available, falls back to TypeScript.
|
|
259
|
+
*/
|
|
260
|
+
function formatToolsForPrompt(tools, format = ToolCallFormat.Default) {
|
|
261
|
+
if (tools.length === 0)
|
|
262
|
+
return '';
|
|
263
|
+
const toolsJson = serializeToolDefinitions(tools);
|
|
264
|
+
if (hasNativeToolCalling()) {
|
|
265
|
+
const bridge = requireBridge();
|
|
266
|
+
const m = bridge.module;
|
|
267
|
+
const jsonPtr = bridge.allocString(toolsJson);
|
|
268
|
+
const fmtPtr = bridge.allocString(format);
|
|
269
|
+
const outPtrPtr = m._malloc(4);
|
|
270
|
+
m.setValue(outPtrPtr, 0, '*');
|
|
271
|
+
try {
|
|
272
|
+
const rc = m.ccall('rac_tool_call_format_prompt_json_with_format_name', 'number', ['number', 'number', 'number'], [jsonPtr, fmtPtr, outPtrPtr]);
|
|
273
|
+
if (rc === 0) {
|
|
274
|
+
const outPtr = m.getValue(outPtrPtr, '*');
|
|
275
|
+
if (outPtr) {
|
|
276
|
+
const result = bridge.readString(outPtr);
|
|
277
|
+
m.ccall('rac_free', null, ['number'], [outPtr]);
|
|
278
|
+
return result;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
finally {
|
|
283
|
+
bridge.free(jsonPtr);
|
|
284
|
+
bridge.free(fmtPtr);
|
|
285
|
+
m._free(outPtrPtr);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
// Fallback: build prompt in TypeScript
|
|
289
|
+
return formatToolsForPromptTS(tools, format);
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Build follow-up prompt after tool execution.
|
|
293
|
+
* Uses C++ when available, falls back to TypeScript.
|
|
294
|
+
*/
|
|
295
|
+
function buildFollowUpPrompt(originalPrompt, toolsPrompt, toolName, toolResultJson, keepToolsAvailable) {
|
|
296
|
+
if (hasNativeToolCalling()) {
|
|
297
|
+
const bridge = requireBridge();
|
|
298
|
+
const m = bridge.module;
|
|
299
|
+
const promptPtr = bridge.allocString(originalPrompt);
|
|
300
|
+
const toolsPromptPtr = toolsPrompt ? bridge.allocString(toolsPrompt) : 0;
|
|
301
|
+
const namePtr = bridge.allocString(toolName);
|
|
302
|
+
const resultPtr = bridge.allocString(toolResultJson);
|
|
303
|
+
const outPtrPtr = m._malloc(4);
|
|
304
|
+
m.setValue(outPtrPtr, 0, '*');
|
|
305
|
+
try {
|
|
306
|
+
const rc = m.ccall('rac_tool_call_build_followup_prompt', 'number', ['number', 'number', 'number', 'number', 'number', 'number'], [promptPtr, toolsPromptPtr, namePtr, resultPtr, keepToolsAvailable ? 1 : 0, outPtrPtr]);
|
|
307
|
+
if (rc === 0) {
|
|
308
|
+
const outPtr = m.getValue(outPtrPtr, '*');
|
|
309
|
+
if (outPtr) {
|
|
310
|
+
const result = bridge.readString(outPtr);
|
|
311
|
+
m.ccall('rac_free', null, ['number'], [outPtr]);
|
|
312
|
+
return result;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
finally {
|
|
317
|
+
bridge.free(promptPtr);
|
|
318
|
+
if (toolsPromptPtr)
|
|
319
|
+
bridge.free(toolsPromptPtr);
|
|
320
|
+
bridge.free(namePtr);
|
|
321
|
+
bridge.free(resultPtr);
|
|
322
|
+
m._free(outPtrPtr);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
// Fallback: build in TypeScript
|
|
326
|
+
return buildFollowUpPromptTS(originalPrompt, toolName, toolResultJson, keepToolsAvailable);
|
|
327
|
+
}
|
|
328
|
+
// ---------------------------------------------------------------------------
|
|
329
|
+
// TypeScript fallback helpers
|
|
330
|
+
// ---------------------------------------------------------------------------
|
|
331
|
+
function formatToolsForPromptTS(tools, format) {
|
|
332
|
+
const toolDescriptions = tools.map((t) => {
|
|
333
|
+
const params = t.parameters.map((p) => {
|
|
334
|
+
const req = p.required !== false ? ' (required)' : ' (optional)';
|
|
335
|
+
return ` - ${p.name} (${p.type}${req}): ${p.description}`;
|
|
336
|
+
}).join('\n');
|
|
337
|
+
return ` ${t.name}: ${t.description}\n Parameters:\n${params}`;
|
|
338
|
+
}).join('\n\n');
|
|
339
|
+
if (format === ToolCallFormat.LFM2) {
|
|
340
|
+
return `You have access to the following tools:\n\n${toolDescriptions}\n\nTo use a tool, respond with:\n<|tool_call_start|>[tool_name(arg1="value1", arg2="value2")]<|tool_call_end|>\n\nIf no tool is needed, respond normally.`;
|
|
341
|
+
}
|
|
342
|
+
return `You have access to the following tools:\n\n${toolDescriptions}\n\nTo use a tool, respond with:\n<tool_call>{"tool": "tool_name", "arguments": {"arg1": "value1"}}</tool_call>\n\nIf no tool is needed, respond normally.`;
|
|
343
|
+
}
|
|
344
|
+
function buildFollowUpPromptTS(originalPrompt, toolName, toolResultJson, keepToolsAvailable) {
|
|
345
|
+
if (keepToolsAvailable) {
|
|
346
|
+
return `User: ${originalPrompt}\n\nYou previously used the ${toolName} tool and received:\n${toolResultJson}\n\nBased on this tool result, either use another tool if needed, or provide a helpful response.`;
|
|
347
|
+
}
|
|
348
|
+
return `The user asked: "${originalPrompt}"\n\nYou used the ${toolName} tool and received this data:\n${toolResultJson}\n\nNow provide a helpful, natural response to the user based on this information.`;
|
|
349
|
+
}
|
|
350
|
+
// ---------------------------------------------------------------------------
|
|
351
|
+
// JSON <-> ToolValue conversion
|
|
352
|
+
// ---------------------------------------------------------------------------
|
|
353
|
+
function parseJsonToToolValues(json) {
|
|
354
|
+
try {
|
|
355
|
+
const parsed = JSON.parse(json);
|
|
356
|
+
return jsonToToolValues(parsed);
|
|
357
|
+
}
|
|
358
|
+
catch {
|
|
359
|
+
return {};
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
function jsonToToolValues(obj) {
|
|
363
|
+
const result = {};
|
|
364
|
+
for (const [key, val] of Object.entries(obj)) {
|
|
365
|
+
result[key] = toToolValue(val);
|
|
366
|
+
}
|
|
367
|
+
return result;
|
|
368
|
+
}
|
|
369
|
+
function toolValueToJson(val) {
|
|
370
|
+
return fromToolValue(val);
|
|
371
|
+
}
|
|
372
|
+
function toolResultToJsonString(result) {
|
|
373
|
+
const plain = {};
|
|
374
|
+
for (const [k, v] of Object.entries(result)) {
|
|
375
|
+
plain[k] = toolValueToJson(v);
|
|
376
|
+
}
|
|
377
|
+
return JSON.stringify(plain);
|
|
378
|
+
}
|
|
379
|
+
function serializeToolDefinitions(tools) {
|
|
380
|
+
return JSON.stringify(tools.map((t) => ({
|
|
381
|
+
name: t.name,
|
|
382
|
+
description: t.description,
|
|
383
|
+
parameters: t.parameters.map((p) => ({
|
|
384
|
+
name: p.name,
|
|
385
|
+
type: p.type,
|
|
386
|
+
description: p.description,
|
|
387
|
+
required: p.required ?? true,
|
|
388
|
+
...(p.enumValues ? { enumValues: p.enumValues } : {}),
|
|
389
|
+
})),
|
|
390
|
+
})));
|
|
391
|
+
}
|
|
392
|
+
// ---------------------------------------------------------------------------
|
|
393
|
+
// Tool Calling Extension
|
|
394
|
+
// ---------------------------------------------------------------------------
|
|
395
|
+
class ToolCallingImpl {
|
|
396
|
+
extensionName = 'ToolCalling';
|
|
397
|
+
toolRegistry = new Map();
|
|
398
|
+
/**
|
|
399
|
+
* Register a tool that the LLM can use.
|
|
400
|
+
*
|
|
401
|
+
* @param definition - Tool definition (name, description, parameters)
|
|
402
|
+
* @param executor - Async function that executes the tool
|
|
403
|
+
*/
|
|
404
|
+
registerTool(definition, executor) {
|
|
405
|
+
this.toolRegistry.set(definition.name, { definition, executor });
|
|
406
|
+
logger.info(`Tool registered: ${definition.name}`);
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Unregister a tool by name.
|
|
410
|
+
*/
|
|
411
|
+
unregisterTool(name) {
|
|
412
|
+
this.toolRegistry.delete(name);
|
|
413
|
+
logger.info(`Tool unregistered: ${name}`);
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Get all registered tool definitions.
|
|
417
|
+
*/
|
|
418
|
+
getRegisteredTools() {
|
|
419
|
+
return Array.from(this.toolRegistry.values()).map((t) => t.definition);
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Clear all registered tools.
|
|
423
|
+
*/
|
|
424
|
+
clearTools() {
|
|
425
|
+
this.toolRegistry.clear();
|
|
426
|
+
logger.info('All tools cleared');
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Execute a tool call by looking up the registered executor.
|
|
430
|
+
*/
|
|
431
|
+
async executeTool(toolCall) {
|
|
432
|
+
const registered = this.toolRegistry.get(toolCall.toolName);
|
|
433
|
+
if (!registered) {
|
|
434
|
+
return {
|
|
435
|
+
toolName: toolCall.toolName,
|
|
436
|
+
success: false,
|
|
437
|
+
error: `Unknown tool: ${toolCall.toolName}`,
|
|
438
|
+
callId: toolCall.callId,
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
try {
|
|
442
|
+
const result = await registered.executor(toolCall.arguments);
|
|
443
|
+
return {
|
|
444
|
+
toolName: toolCall.toolName,
|
|
445
|
+
success: true,
|
|
446
|
+
result,
|
|
447
|
+
callId: toolCall.callId,
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
catch (err) {
|
|
451
|
+
return {
|
|
452
|
+
toolName: toolCall.toolName,
|
|
453
|
+
success: false,
|
|
454
|
+
error: err instanceof Error ? err.message : String(err),
|
|
455
|
+
callId: toolCall.callId,
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Generate a response with tool calling support.
|
|
461
|
+
*
|
|
462
|
+
* Orchestrates: generate -> parse -> execute -> loop
|
|
463
|
+
*
|
|
464
|
+
* @param prompt - The user's prompt
|
|
465
|
+
* @param options - Tool calling options
|
|
466
|
+
* @returns Result with final text, all tool calls, and their results
|
|
467
|
+
*/
|
|
468
|
+
async generateWithTools(prompt, options = {}) {
|
|
469
|
+
if (!RunAnywhere.isInitialized) {
|
|
470
|
+
throw SDKError.notInitialized();
|
|
471
|
+
}
|
|
472
|
+
if (!TextGeneration.isModelLoaded) {
|
|
473
|
+
throw new SDKError(SDKErrorCode.ModelNotLoaded, 'No LLM model loaded. Call loadModel() first.');
|
|
474
|
+
}
|
|
475
|
+
const maxToolCalls = options.maxToolCalls ?? 5;
|
|
476
|
+
const autoExecute = options.autoExecute ?? true;
|
|
477
|
+
const format = options.format ?? ToolCallFormat.Default;
|
|
478
|
+
const registeredTools = this.getRegisteredTools();
|
|
479
|
+
const tools = options.tools ?? registeredTools;
|
|
480
|
+
// Build tool system prompt
|
|
481
|
+
logger.debug('[generateWithTools] Formatting tools for prompt...');
|
|
482
|
+
let toolsPrompt;
|
|
483
|
+
try {
|
|
484
|
+
toolsPrompt = formatToolsForPrompt(tools, format);
|
|
485
|
+
logger.debug(`[generateWithTools] Tools prompt formatted (${toolsPrompt.length} chars)`);
|
|
486
|
+
}
|
|
487
|
+
catch (fmtErr) {
|
|
488
|
+
logger.error(`[generateWithTools] formatToolsForPrompt failed: ${fmtErr instanceof Error ? fmtErr.message : String(fmtErr)}`);
|
|
489
|
+
throw fmtErr;
|
|
490
|
+
}
|
|
491
|
+
let systemPrompt;
|
|
492
|
+
if (options.replaceSystemPrompt && options.systemPrompt) {
|
|
493
|
+
systemPrompt = options.systemPrompt;
|
|
494
|
+
}
|
|
495
|
+
else if (options.systemPrompt) {
|
|
496
|
+
systemPrompt = `${options.systemPrompt}\n\n${toolsPrompt}`;
|
|
497
|
+
}
|
|
498
|
+
else {
|
|
499
|
+
systemPrompt = toolsPrompt;
|
|
500
|
+
}
|
|
501
|
+
let fullPrompt = systemPrompt ? `${systemPrompt}\n\nUser: ${prompt}` : prompt;
|
|
502
|
+
const allToolCalls = [];
|
|
503
|
+
const allToolResults = [];
|
|
504
|
+
let finalText = '';
|
|
505
|
+
for (let i = 0; i < maxToolCalls; i++) {
|
|
506
|
+
// Generate – non-streaming avoids JSPI callback issues with WebGPU
|
|
507
|
+
logger.debug(`[generateWithTools] Round ${i + 1}/${maxToolCalls}, calling collectGeneration...`);
|
|
508
|
+
let genResult;
|
|
509
|
+
try {
|
|
510
|
+
genResult = await collectGeneration(fullPrompt, {
|
|
511
|
+
maxTokens: options.maxTokens ?? 1024,
|
|
512
|
+
temperature: options.temperature ?? 0.3,
|
|
513
|
+
});
|
|
514
|
+
logger.debug(`[generateWithTools] Generation complete (${genResult.text.length} chars)`);
|
|
515
|
+
}
|
|
516
|
+
catch (genErr) {
|
|
517
|
+
logger.error(`[generateWithTools] collectGeneration failed: ${genErr instanceof Error ? `${genErr.message}\nStack: ${genErr.stack}` : String(genErr)}`);
|
|
518
|
+
throw genErr;
|
|
519
|
+
}
|
|
520
|
+
// Parse for tool calls
|
|
521
|
+
const { text, toolCall } = parseToolCall(genResult.text);
|
|
522
|
+
finalText = text;
|
|
523
|
+
if (!toolCall)
|
|
524
|
+
break;
|
|
525
|
+
allToolCalls.push(toolCall);
|
|
526
|
+
logger.info(`Tool call detected: ${toolCall.toolName}`);
|
|
527
|
+
if (!autoExecute) {
|
|
528
|
+
return {
|
|
529
|
+
text: finalText,
|
|
530
|
+
toolCalls: allToolCalls,
|
|
531
|
+
toolResults: [],
|
|
532
|
+
isComplete: false,
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
// Execute tool
|
|
536
|
+
const result = await this.executeTool(toolCall);
|
|
537
|
+
allToolResults.push(result);
|
|
538
|
+
const resultJson = result.success && result.result
|
|
539
|
+
? toolResultToJsonString(result.result)
|
|
540
|
+
: JSON.stringify({ error: result.error ?? 'Unknown error' });
|
|
541
|
+
logger.info(`Tool ${toolCall.toolName} ${result.success ? 'succeeded' : 'failed'}`);
|
|
542
|
+
// Build follow-up prompt
|
|
543
|
+
fullPrompt = buildFollowUpPrompt(prompt, options.keepToolsAvailable ? toolsPrompt : null, toolCall.toolName, resultJson, options.keepToolsAvailable ?? false);
|
|
544
|
+
}
|
|
545
|
+
return {
|
|
546
|
+
text: finalText,
|
|
547
|
+
toolCalls: allToolCalls,
|
|
548
|
+
toolResults: allToolResults,
|
|
549
|
+
isComplete: true,
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* Clean up the tool calling extension (clears all registered tools).
|
|
554
|
+
*/
|
|
555
|
+
cleanup() {
|
|
556
|
+
this.toolRegistry.clear();
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* Continue generation after manual tool execution.
|
|
560
|
+
* Use when autoExecute is false.
|
|
561
|
+
*/
|
|
562
|
+
async continueWithToolResult(previousPrompt, toolCall, toolResult, options) {
|
|
563
|
+
const resultJson = toolResult.success && toolResult.result
|
|
564
|
+
? toolResultToJsonString(toolResult.result)
|
|
565
|
+
: `Error: ${toolResult.error ?? 'Unknown error'}`;
|
|
566
|
+
const continuedPrompt = `${previousPrompt}\n\nTool Result for ${toolCall.toolName}: ${resultJson}\n\nBased on the tool result, please provide your response:`;
|
|
567
|
+
return this.generateWithTools(continuedPrompt, {
|
|
568
|
+
...options,
|
|
569
|
+
maxToolCalls: (options?.maxToolCalls ?? 5) - 1,
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
export const ToolCalling = new ToolCallingImpl();
|
|
574
|
+
//# sourceMappingURL=RunAnywhere+ToolCalling.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RunAnywhere+ToolCalling.js","sourceRoot":"","sources":["../../src/Extensions/RunAnywhere+ToolCalling.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClF,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;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jB,UAAU,EACV,OAAO,CAAC,kBAAkB,IAAI,KAAK,CACpC,CAAC;QACJ,CAAC;QAED,OAAO;YACL,IAAI,EAAE,SAAS;YACf,SAAS,EAAE,YAAY;YACvB,WAAW,EAAE,cAAc;YAC3B,UAAU,EAAE,IAAI;SACjB,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,OAAO;QACL,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC;IAC5B,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,sBAAsB,CAC1B,cAAsB,EACtB,QAAkB,EAClB,UAAsB,EACtB,OAA4B;QAE5B,MAAM,UAAU,GAAG,UAAU,CAAC,OAAO,IAAI,UAAU,CAAC,MAAM;YACxD,CAAC,CAAC,sBAAsB,CAAC,UAAU,CAAC,MAAM,CAAC;YAC3C,CAAC,CAAC,UAAU,UAAU,CAAC,KAAK,IAAI,eAAe,EAAE,CAAC;QAEpD,MAAM,eAAe,GAAG,GAAG,cAAc,uBAAuB,QAAQ,CAAC,QAAQ,KAAK,UAAU,6DAA6D,CAAC;QAE9J,OAAO,IAAI,CAAC,iBAAiB,CAAC,eAAe,EAAE;YAC7C,GAAG,OAAO;YACV,YAAY,EAAE,CAAC,OAAO,EAAE,YAAY,IAAI,CAAC,CAAC,GAAG,CAAC;SAC/C,CAAC,CAAC;IACL,CAAC;CACF;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,eAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RunAnywhere Web SDK - Vision Language Model Extension
|
|
3
|
+
*
|
|
4
|
+
* Adds VLM capabilities for image understanding + text generation.
|
|
5
|
+
* Uses the RACommons rac_vlm_component_* C API (llama.cpp mtmd backend).
|
|
6
|
+
*
|
|
7
|
+
* Mirrors: sdk/runanywhere-swift/Sources/RunAnywhere/Public/Extensions/VLM/
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* import { VLM } from '@runanywhere/web';
|
|
11
|
+
*
|
|
12
|
+
* await VLM.loadModel('/models/qwen2-vl.gguf', '/models/qwen2-vl-mmproj.gguf', 'qwen2-vl');
|
|
13
|
+
* const result = await VLM.process(imageData, 'Describe this image');
|
|
14
|
+
* console.log(result.text);
|
|
15
|
+
*/
|
|
16
|
+
import type { VLMImage, VLMGenerationOptions, VLMGenerationResult } from './VLMTypes';
|
|
17
|
+
export { VLMModelFamily } from './VLMTypes';
|
|
18
|
+
declare class VLMImpl {
|
|
19
|
+
readonly extensionName = "VLM";
|
|
20
|
+
private _vlmComponentHandle;
|
|
21
|
+
private _vlmBackendRegistered;
|
|
22
|
+
private requireBridge;
|
|
23
|
+
/**
|
|
24
|
+
* Ensure the llama.cpp VLM backend is registered with the service registry.
|
|
25
|
+
* Must be called before creating the VLM component so it can find a provider.
|
|
26
|
+
*/
|
|
27
|
+
private ensureVLMBackendRegistered;
|
|
28
|
+
private ensureVLMComponent;
|
|
29
|
+
/**
|
|
30
|
+
* Load a VLM model (GGUF model + multimodal projector).
|
|
31
|
+
*
|
|
32
|
+
* @param modelPath - Path to the GGUF model file in WASM FS
|
|
33
|
+
* @param mmprojPath - Path to the mmproj file in WASM FS
|
|
34
|
+
* @param modelId - Unique model identifier
|
|
35
|
+
* @param modelName - Display name (optional)
|
|
36
|
+
*/
|
|
37
|
+
loadModel(modelPath: string, mmprojPath: string, modelId: string, modelName?: string): Promise<void>;
|
|
38
|
+
/** Unload the VLM model. */
|
|
39
|
+
unloadModel(): Promise<void>;
|
|
40
|
+
/** Check if a VLM model is loaded. */
|
|
41
|
+
get isModelLoaded(): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Process an image with a text prompt.
|
|
44
|
+
*
|
|
45
|
+
* @param image - Image input (file path, pixel data, or base64)
|
|
46
|
+
* @param prompt - Text prompt describing what to do with the image
|
|
47
|
+
* @param options - Generation options
|
|
48
|
+
* @returns VLM generation result
|
|
49
|
+
*/
|
|
50
|
+
process(image: VLMImage, prompt: string, options?: VLMGenerationOptions): Promise<VLMGenerationResult>;
|
|
51
|
+
/** Cancel in-progress VLM generation. */
|
|
52
|
+
cancel(): void;
|
|
53
|
+
/** Clean up the VLM component and unregister backend. */
|
|
54
|
+
cleanup(): void;
|
|
55
|
+
}
|
|
56
|
+
export declare const VLM: VLMImpl;
|
|
57
|
+
//# sourceMappingURL=RunAnywhere+VLM.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RunAnywhere+VLM.d.ts","sourceRoot":"","sources":["../../src/Extensions/RunAnywhere+VLM.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAMH,OAAO,KAAK,EAAE,QAAQ,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAItF,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAM5C,cAAM,OAAO;IACX,QAAQ,CAAC,aAAa,SAAS;IAC/B,OAAO,CAAC,mBAAmB,CAAK;IAChC,OAAO,CAAC,qBAAqB,CAAS;IAEtC,OAAO,CAAC,aAAa;IAKrB;;;OAGG;IACH,OAAO,CAAC,0BAA0B;IAyBlC,OAAO,CAAC,kBAAkB;IAsB1B;;;;;;;OAOG;IACG,SAAS,CACb,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC;IA8BhB,4BAA4B;IACtB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAUlC,sCAAsC;IACtC,IAAI,aAAa,IAAI,OAAO,CAO3B;IAED;;;;;;;OAOG;IACG,OAAO,CACX,KAAK,EAAE,QAAQ,EACf,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,mBAAmB,CAAC;IA+G/B,yCAAyC;IACzC,MAAM,IAAI,IAAI;IAOd,yDAAyD;IACzD,OAAO,IAAI,IAAI;CAqBhB;AAED,eAAO,MAAM,GAAG,SAAgB,CAAC"}
|