@reverbia/sdk 1.0.0-next.20251208112742 → 1.0.0-next.20251209090511
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/dist/expo/index.cjs +1061 -107
- package/dist/expo/index.d.mts +150 -6
- package/dist/expo/index.d.ts +150 -6
- package/dist/expo/index.mjs +1059 -106
- package/dist/react/index.cjs +523 -47635
- package/dist/react/index.d.mts +42 -26
- package/dist/react/index.d.ts +42 -26
- package/dist/react/index.mjs +428 -166
- package/package.json +1 -1
- package/dist/react/chunk-BG7SZT33.mjs +0 -182
- package/dist/react/chunk-FBCDBTKJ.mjs +0 -55
- package/dist/react/chunk-LVWIZZZP.mjs +0 -6
- package/dist/react/chunk-Q6FVPTTV.mjs +0 -28
- package/dist/react/constants-WUGUGYE3.mjs +0 -7
- package/dist/react/generation-NG4QVPCR.mjs +0 -52
- package/dist/react/onnxruntime_binding-5QEF3SUC.node +0 -0
- package/dist/react/onnxruntime_binding-BKPKNEGC.node +0 -0
- package/dist/react/onnxruntime_binding-FMOXGIUT.node +0 -0
- package/dist/react/onnxruntime_binding-OI2KMXC5.node +0 -0
- package/dist/react/onnxruntime_binding-UX44MLAZ.node +0 -0
- package/dist/react/onnxruntime_binding-Y2W7N7WY.node +0 -0
- package/dist/react/selector-XMR5KL3E.mjs +0 -14
- package/dist/react/transformers.node-LUTOZWVQ.mjs +0 -46943
package/package.json
CHANGED
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getTextGenerationPipeline
|
|
3
|
-
} from "./chunk-Q6FVPTTV.mjs";
|
|
4
|
-
|
|
5
|
-
// src/lib/tools/selector.ts
|
|
6
|
-
var DEFAULT_TOOL_SELECTOR_MODEL = "Xenova/LaMini-GPT-124M";
|
|
7
|
-
function buildToolSelectionPrompt(userMessage, tools) {
|
|
8
|
-
const toolList = tools.map((t) => `${t.name} (${t.description})`).join("\n");
|
|
9
|
-
return `Pick the best tool for the task. Reply with ONLY the tool name.
|
|
10
|
-
|
|
11
|
-
Available tools:
|
|
12
|
-
${toolList}
|
|
13
|
-
none (no tool needed)
|
|
14
|
-
|
|
15
|
-
Task: "${userMessage}"
|
|
16
|
-
|
|
17
|
-
Best tool:`;
|
|
18
|
-
}
|
|
19
|
-
function buildParamExtractionPrompt(userMessage, paramName, paramDescription) {
|
|
20
|
-
const desc = paramDescription ? ` (${paramDescription})` : "";
|
|
21
|
-
return `Extract the value for "${paramName}"${desc} from the user message. Reply with ONLY the extracted value, nothing else.
|
|
22
|
-
|
|
23
|
-
User message: "${userMessage}"
|
|
24
|
-
|
|
25
|
-
Value for ${paramName}:`;
|
|
26
|
-
}
|
|
27
|
-
async function extractParams(userMessage, tool, options) {
|
|
28
|
-
const params = {};
|
|
29
|
-
if (!tool.parameters || tool.parameters.length === 0) return params;
|
|
30
|
-
const { model, device } = options;
|
|
31
|
-
try {
|
|
32
|
-
const pipeline = await getTextGenerationPipeline({
|
|
33
|
-
model,
|
|
34
|
-
device,
|
|
35
|
-
dtype: "q4"
|
|
36
|
-
});
|
|
37
|
-
for (const param of tool.parameters) {
|
|
38
|
-
const prompt = buildParamExtractionPrompt(
|
|
39
|
-
userMessage,
|
|
40
|
-
param.name,
|
|
41
|
-
param.description
|
|
42
|
-
);
|
|
43
|
-
const output = await pipeline(prompt, {
|
|
44
|
-
max_new_tokens: 32,
|
|
45
|
-
// Allow reasonable length for parameter values
|
|
46
|
-
temperature: 0,
|
|
47
|
-
do_sample: false,
|
|
48
|
-
return_full_text: false
|
|
49
|
-
});
|
|
50
|
-
const generatedText = output?.[0]?.generated_text || output?.generated_text || "";
|
|
51
|
-
const extractedValue = generatedText.trim().split("\n")[0].trim();
|
|
52
|
-
console.log(
|
|
53
|
-
`[Tool Selector] Extracted param "${param.name}":`,
|
|
54
|
-
extractedValue
|
|
55
|
-
);
|
|
56
|
-
params[param.name] = extractedValue || userMessage;
|
|
57
|
-
}
|
|
58
|
-
} catch (error) {
|
|
59
|
-
console.error("[Tool Selector] Error extracting params:", error);
|
|
60
|
-
for (const param of tool.parameters) {
|
|
61
|
-
params[param.name] = userMessage;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return params;
|
|
65
|
-
}
|
|
66
|
-
async function parseToolSelectionResponse(response, tools, userMessage, options) {
|
|
67
|
-
console.log("[Tool Selector] Raw response:", response);
|
|
68
|
-
const cleaned = response.toLowerCase().trim().split(/[\s\n,.]+/)[0].replace(/[^a-z0-9_-]/g, "");
|
|
69
|
-
console.log("[Tool Selector] Parsed tool name:", cleaned);
|
|
70
|
-
if (cleaned === "none" || cleaned === "null" || cleaned === "") {
|
|
71
|
-
console.log("[Tool Selector] No tool selected");
|
|
72
|
-
return { toolSelected: false };
|
|
73
|
-
}
|
|
74
|
-
const selectedTool = tools.find((t) => t.name.toLowerCase() === cleaned);
|
|
75
|
-
if (!selectedTool) {
|
|
76
|
-
const fuzzyTool = tools.find(
|
|
77
|
-
(t) => t.name.toLowerCase().includes(cleaned) || cleaned.includes(t.name.toLowerCase())
|
|
78
|
-
);
|
|
79
|
-
if (fuzzyTool) {
|
|
80
|
-
console.log(`[Tool Selector] Fuzzy matched tool: ${fuzzyTool.name}`);
|
|
81
|
-
const params2 = await extractParams(userMessage, fuzzyTool, options);
|
|
82
|
-
return {
|
|
83
|
-
toolSelected: true,
|
|
84
|
-
toolName: fuzzyTool.name,
|
|
85
|
-
parameters: params2,
|
|
86
|
-
confidence: 0.6
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
console.warn(`[Tool Selector] Unknown tool: ${cleaned}`);
|
|
90
|
-
return { toolSelected: false };
|
|
91
|
-
}
|
|
92
|
-
const params = await extractParams(userMessage, selectedTool, options);
|
|
93
|
-
console.log(`[Tool Selector] Selected tool: ${selectedTool.name}`, params);
|
|
94
|
-
return {
|
|
95
|
-
toolSelected: true,
|
|
96
|
-
toolName: selectedTool.name,
|
|
97
|
-
parameters: params,
|
|
98
|
-
confidence: 0.9
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
async function selectTool(userMessage, tools, options = {}) {
|
|
102
|
-
const {
|
|
103
|
-
model = DEFAULT_TOOL_SELECTOR_MODEL,
|
|
104
|
-
signal,
|
|
105
|
-
device = "wasm"
|
|
106
|
-
} = options;
|
|
107
|
-
if (!tools.length) {
|
|
108
|
-
return { toolSelected: false };
|
|
109
|
-
}
|
|
110
|
-
console.log(
|
|
111
|
-
`[Tool Selector] analyzing message: "${userMessage}" with model ${model}`
|
|
112
|
-
);
|
|
113
|
-
try {
|
|
114
|
-
const selectorPipeline = await getTextGenerationPipeline({
|
|
115
|
-
model,
|
|
116
|
-
device,
|
|
117
|
-
dtype: "q4"
|
|
118
|
-
// Aggressive quantization for speed
|
|
119
|
-
});
|
|
120
|
-
const prompt = buildToolSelectionPrompt(userMessage, tools);
|
|
121
|
-
const output = await selectorPipeline(prompt, {
|
|
122
|
-
max_new_tokens: 4,
|
|
123
|
-
// Just need the tool name
|
|
124
|
-
temperature: 0,
|
|
125
|
-
// Deterministic
|
|
126
|
-
do_sample: false,
|
|
127
|
-
return_full_text: false
|
|
128
|
-
});
|
|
129
|
-
if (signal?.aborted) {
|
|
130
|
-
return { toolSelected: false };
|
|
131
|
-
}
|
|
132
|
-
const generatedText = output?.[0]?.generated_text || output?.generated_text || "";
|
|
133
|
-
return await parseToolSelectionResponse(generatedText, tools, userMessage, {
|
|
134
|
-
model,
|
|
135
|
-
device
|
|
136
|
-
});
|
|
137
|
-
} catch (error) {
|
|
138
|
-
console.error("[Tool Selector] Error:", error);
|
|
139
|
-
return { toolSelected: false };
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
var preloadPromise = null;
|
|
143
|
-
async function preloadToolSelectorModel(options = {}) {
|
|
144
|
-
if (preloadPromise) {
|
|
145
|
-
return preloadPromise;
|
|
146
|
-
}
|
|
147
|
-
const { model = DEFAULT_TOOL_SELECTOR_MODEL, device = "wasm" } = options;
|
|
148
|
-
console.log(`[Tool Selector] Preloading model: ${model}`);
|
|
149
|
-
preloadPromise = getTextGenerationPipeline({
|
|
150
|
-
model,
|
|
151
|
-
device,
|
|
152
|
-
dtype: "q4"
|
|
153
|
-
}).then(() => {
|
|
154
|
-
console.log(`[Tool Selector] Model preloaded: ${model}`);
|
|
155
|
-
}).catch((error) => {
|
|
156
|
-
console.warn("[Tool Selector] Failed to preload model:", error);
|
|
157
|
-
preloadPromise = null;
|
|
158
|
-
});
|
|
159
|
-
return preloadPromise;
|
|
160
|
-
}
|
|
161
|
-
async function executeTool(tool, params) {
|
|
162
|
-
try {
|
|
163
|
-
console.log(
|
|
164
|
-
`[Tool Selector] Executing tool ${tool.name} with params:`,
|
|
165
|
-
params
|
|
166
|
-
);
|
|
167
|
-
const result = await tool.execute(params);
|
|
168
|
-
console.log(`[Tool Selector] Tool ${tool.name} execution result:`, result);
|
|
169
|
-
return { success: true, result };
|
|
170
|
-
} catch (error) {
|
|
171
|
-
const errorMessage = error instanceof Error ? error.message : "Tool execution failed";
|
|
172
|
-
console.error(`[Tool Selector] Tool ${tool.name} failed:`, errorMessage);
|
|
173
|
-
return { success: false, error: errorMessage };
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export {
|
|
178
|
-
DEFAULT_TOOL_SELECTOR_MODEL,
|
|
179
|
-
selectTool,
|
|
180
|
-
preloadToolSelectorModel,
|
|
181
|
-
executeTool
|
|
182
|
-
};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
9
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
10
|
-
}) : x)(function(x) {
|
|
11
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
12
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
13
|
-
});
|
|
14
|
-
var __glob = (map) => (path) => {
|
|
15
|
-
var fn = map[path];
|
|
16
|
-
if (fn) return fn();
|
|
17
|
-
throw new Error("Module not found in bundle: " + path);
|
|
18
|
-
};
|
|
19
|
-
var __esm = (fn, res) => function __init() {
|
|
20
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
21
|
-
};
|
|
22
|
-
var __commonJS = (cb, mod) => function __require2() {
|
|
23
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
24
|
-
};
|
|
25
|
-
var __export = (target, all) => {
|
|
26
|
-
for (var name in all)
|
|
27
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
28
|
-
};
|
|
29
|
-
var __copyProps = (to, from, except, desc) => {
|
|
30
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
31
|
-
for (let key of __getOwnPropNames(from))
|
|
32
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
33
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
34
|
-
}
|
|
35
|
-
return to;
|
|
36
|
-
};
|
|
37
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
38
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
39
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
40
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
41
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
42
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
43
|
-
mod
|
|
44
|
-
));
|
|
45
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
46
|
-
|
|
47
|
-
export {
|
|
48
|
-
__require,
|
|
49
|
-
__glob,
|
|
50
|
-
__esm,
|
|
51
|
-
__commonJS,
|
|
52
|
-
__export,
|
|
53
|
-
__toESM,
|
|
54
|
-
__publicField
|
|
55
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
// src/lib/chat/pipeline.ts
|
|
2
|
-
var sharedPipeline = null;
|
|
3
|
-
var currentModel = null;
|
|
4
|
-
var currentDevice = null;
|
|
5
|
-
async function getTextGenerationPipeline(options) {
|
|
6
|
-
const { model, device = "wasm", dtype = "q4" } = options;
|
|
7
|
-
if (sharedPipeline && currentModel === model && currentDevice === device) {
|
|
8
|
-
return sharedPipeline;
|
|
9
|
-
}
|
|
10
|
-
const { pipeline, env } = await import("./transformers.node-LUTOZWVQ.mjs");
|
|
11
|
-
env.allowLocalModels = false;
|
|
12
|
-
if (env.backends?.onnx) {
|
|
13
|
-
env.backends.onnx.logLevel = "fatal";
|
|
14
|
-
}
|
|
15
|
-
console.log(`[Pipeline] Loading model: ${model} on ${device}...`);
|
|
16
|
-
sharedPipeline = await pipeline("text-generation", model, {
|
|
17
|
-
dtype,
|
|
18
|
-
device
|
|
19
|
-
});
|
|
20
|
-
currentModel = model;
|
|
21
|
-
currentDevice = device;
|
|
22
|
-
console.log(`[Pipeline] Model loaded: ${model}`);
|
|
23
|
-
return sharedPipeline;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export {
|
|
27
|
-
getTextGenerationPipeline
|
|
28
|
-
};
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DEFAULT_LOCAL_CHAT_MODEL
|
|
3
|
-
} from "./chunk-LVWIZZZP.mjs";
|
|
4
|
-
import {
|
|
5
|
-
getTextGenerationPipeline
|
|
6
|
-
} from "./chunk-Q6FVPTTV.mjs";
|
|
7
|
-
import "./chunk-FBCDBTKJ.mjs";
|
|
8
|
-
|
|
9
|
-
// src/lib/chat/generation.ts
|
|
10
|
-
async function generateLocalChatCompletion(messages, options = {}) {
|
|
11
|
-
const {
|
|
12
|
-
model = DEFAULT_LOCAL_CHAT_MODEL,
|
|
13
|
-
temperature = 0.7,
|
|
14
|
-
max_tokens = 1024,
|
|
15
|
-
top_p = 0.9,
|
|
16
|
-
onToken,
|
|
17
|
-
signal
|
|
18
|
-
} = options;
|
|
19
|
-
const { TextStreamer } = await import("./transformers.node-LUTOZWVQ.mjs");
|
|
20
|
-
const chatPipeline = await getTextGenerationPipeline({
|
|
21
|
-
model,
|
|
22
|
-
device: "wasm",
|
|
23
|
-
dtype: "q4"
|
|
24
|
-
});
|
|
25
|
-
class CallbackStreamer extends TextStreamer {
|
|
26
|
-
constructor(tokenizer, cb) {
|
|
27
|
-
super(tokenizer, {
|
|
28
|
-
skip_prompt: true,
|
|
29
|
-
skip_special_tokens: true
|
|
30
|
-
});
|
|
31
|
-
this.cb = cb;
|
|
32
|
-
}
|
|
33
|
-
on_finalized_text(text) {
|
|
34
|
-
if (signal?.aborted) {
|
|
35
|
-
throw new Error("AbortError");
|
|
36
|
-
}
|
|
37
|
-
this.cb(text);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
const streamer = onToken ? new CallbackStreamer(chatPipeline.tokenizer, onToken) : void 0;
|
|
41
|
-
const output = await chatPipeline(messages, {
|
|
42
|
-
max_new_tokens: max_tokens,
|
|
43
|
-
temperature,
|
|
44
|
-
top_p,
|
|
45
|
-
streamer,
|
|
46
|
-
return_full_text: false
|
|
47
|
-
});
|
|
48
|
-
return output;
|
|
49
|
-
}
|
|
50
|
-
export {
|
|
51
|
-
generateLocalChatCompletion
|
|
52
|
-
};
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DEFAULT_TOOL_SELECTOR_MODEL,
|
|
3
|
-
executeTool,
|
|
4
|
-
preloadToolSelectorModel,
|
|
5
|
-
selectTool
|
|
6
|
-
} from "./chunk-BG7SZT33.mjs";
|
|
7
|
-
import "./chunk-Q6FVPTTV.mjs";
|
|
8
|
-
import "./chunk-FBCDBTKJ.mjs";
|
|
9
|
-
export {
|
|
10
|
-
DEFAULT_TOOL_SELECTOR_MODEL,
|
|
11
|
-
executeTool,
|
|
12
|
-
preloadToolSelectorModel,
|
|
13
|
-
selectTool
|
|
14
|
-
};
|