@soverius-ai/browser-models 0.1.0 → 0.2.0
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 +16 -8
- package/chunk-4RAISIWO.js +1 -0
- package/chunk-6TJV26R3.js +1 -0
- package/chunk-EFSLG2O3.js +1 -0
- package/chunk-MPBLCIMW.js +1 -0
- package/chunk-T3BB5C4O.js +1 -0
- package/chunk-T5TQFW45.js +1 -0
- package/chunk-UZW7NPZG.js +1 -0
- package/engines/prompt-api.d.ts +41 -0
- package/{src/engines → engines}/transformers.d.ts +22 -9
- package/engines/web-llm-default.worker.d.ts +1 -0
- package/engines/web-llm.d.ts +48 -0
- package/engines.d.ts +44 -0
- package/engines.js +1 -0
- package/index.d.ts +11 -0
- package/index.js +1 -0
- package/{src/lib → lib}/async-queue.d.ts +4 -0
- package/lib/engine.d.ts +107 -0
- package/{src/lib/parser.d.ts → lib/output-parser.d.ts} +4 -0
- package/{src/model-store.d.ts → model-store.d.ts} +3 -0
- package/models.d.ts +26 -0
- package/package.json +28 -47
- package/prompt-api.d.ts +6 -0
- package/prompt-api.js +1 -0
- package/transformers.d.ts +6 -0
- package/transformers.js +1 -0
- package/web-llm-default.worker.js +1 -0
- package/web-llm-worker.d.ts +6 -0
- package/web-llm-worker.js +1 -0
- package/web-llm.d.ts +6 -0
- package/web-llm.js +1 -0
- package/src/agent.d.ts +0 -52
- package/src/agent.js +0 -128
- package/src/agent.js.map +0 -1
- package/src/copilotkit.d.ts +0 -20
- package/src/copilotkit.js +0 -163
- package/src/copilotkit.js.map +0 -1
- package/src/engines/opfs-cache.js +0 -43
- package/src/engines/opfs-cache.js.map +0 -1
- package/src/engines/prompt-api.d.ts +0 -50
- package/src/engines/prompt-api.js +0 -124
- package/src/engines/prompt-api.js.map +0 -1
- package/src/engines/shared-load.js +0 -67
- package/src/engines/shared-load.js.map +0 -1
- package/src/engines/transformers.js +0 -209
- package/src/engines/transformers.js.map +0 -1
- package/src/engines/web-llm-worker.js +0 -15
- package/src/engines/web-llm-worker.js.map +0 -1
- package/src/engines/web-llm.d.ts +0 -41
- package/src/engines/web-llm.js +0 -135
- package/src/engines/web-llm.js.map +0 -1
- package/src/index.d.ts +0 -7
- package/src/index.js +0 -6
- package/src/index.js.map +0 -1
- package/src/lib/abort.js +0 -24
- package/src/lib/abort.js.map +0 -1
- package/src/lib/async-queue.js +0 -35
- package/src/lib/async-queue.js.map +0 -1
- package/src/lib/engine.d.ts +0 -45
- package/src/lib/engine.js +0 -2
- package/src/lib/engine.js.map +0 -1
- package/src/lib/parser.js +0 -124
- package/src/lib/parser.js.map +0 -1
- package/src/lib/partial-json.d.ts +0 -21
- package/src/lib/partial-json.js +0 -88
- package/src/lib/partial-json.js.map +0 -1
- package/src/lib/prompt.d.ts +0 -9
- package/src/lib/prompt.js +0 -82
- package/src/lib/prompt.js.map +0 -1
- package/src/lib/repair.d.ts +0 -47
- package/src/lib/repair.js +0 -217
- package/src/lib/repair.js.map +0 -1
- package/src/lib/run.d.ts +0 -40
- package/src/lib/run.js +0 -434
- package/src/lib/run.js.map +0 -1
- package/src/lib/schema.d.ts +0 -21
- package/src/lib/schema.js +0 -128
- package/src/lib/schema.js.map +0 -1
- package/src/lib/tools.d.ts +0 -33
- package/src/lib/tools.js +0 -20
- package/src/lib/tools.js.map +0 -1
- package/src/mcp.d.ts +0 -54
- package/src/mcp.js +0 -204
- package/src/mcp.js.map +0 -1
- package/src/model-store.js +0 -139
- package/src/model-store.js.map +0 -1
- package/src/prompt-api.d.ts +0 -1
- package/src/prompt-api.js +0 -3
- package/src/prompt-api.js.map +0 -1
- package/src/transformers.d.ts +0 -1
- package/src/transformers.js +0 -3
- package/src/transformers.js.map +0 -1
- package/src/web-llm-worker.d.ts +0 -1
- package/src/web-llm-worker.js +0 -3
- package/src/web-llm-worker.js.map +0 -1
- package/src/web-llm.d.ts +0 -1
- package/src/web-llm.js +0 -3
- package/src/web-llm.js.map +0 -1
- package/src/webmcp.d.ts +0 -43
- package/src/webmcp.js +0 -58
- package/src/webmcp.js.map +0 -1
- /package/{src/engines → engines}/opfs-cache.d.ts +0 -0
- /package/{src/engines → engines}/shared-load.d.ts +0 -0
- /package/{src/engines → engines}/web-llm-worker.d.ts +0 -0
- /package/{src/lib → lib}/abort.d.ts +0 -0
package/src/lib/parser.js
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Formats small models use. Tool calls: a ```tool_call fence or Qwen/Hermes <tool_call>
|
|
3
|
-
* tags. Thinking: Qwen3/DeepSeek <think> tags. A ```tool_result fence is dropped.
|
|
4
|
-
*/
|
|
5
|
-
const BLOCKS = [
|
|
6
|
-
{ kind: 'tool-call', open: '```tool_call', close: '```' },
|
|
7
|
-
// Tool results are written by the agent. A model that writes one is echoing: never shown.
|
|
8
|
-
{ kind: 'tool-result', open: '```tool_result', close: '```' },
|
|
9
|
-
{ kind: 'tool-call', open: '<tool_call>', close: '</tool_call>' },
|
|
10
|
-
{ kind: 'reasoning', open: '<think>', close: '</think>' },
|
|
11
|
-
];
|
|
12
|
-
/**
|
|
13
|
-
* Splits streamed model output into text, thinking and tool calls. Text is passed on as
|
|
14
|
-
* soon as it cannot be the start of a block, so block syntax never shows up in the chat.
|
|
15
|
-
*/
|
|
16
|
-
export class OutputParser {
|
|
17
|
-
#buffer = '';
|
|
18
|
-
#inside;
|
|
19
|
-
/** Feeds the next text fragment and returns the parts that are complete. */
|
|
20
|
-
push(fragment) {
|
|
21
|
-
this.#buffer += fragment;
|
|
22
|
-
const parts = [];
|
|
23
|
-
for (;;) {
|
|
24
|
-
const block = this.#inside;
|
|
25
|
-
if (block) {
|
|
26
|
-
const end = this.#buffer.indexOf(block.close);
|
|
27
|
-
if (block.kind === 'tool-call') {
|
|
28
|
-
if (end === -1) {
|
|
29
|
-
// Report the body so far, without a possible start of the closing tag.
|
|
30
|
-
const upTo = this.#buffer.length - partialEnd(this.#buffer, [block.close]);
|
|
31
|
-
const raw = this.#buffer.slice(0, upTo).trim();
|
|
32
|
-
if (raw)
|
|
33
|
-
parts.push({ kind: 'tool-call-partial', raw });
|
|
34
|
-
return parts;
|
|
35
|
-
}
|
|
36
|
-
parts.push({
|
|
37
|
-
kind: 'tool-call',
|
|
38
|
-
raw: this.#buffer.slice(0, end).trim(),
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
else if (block.kind === 'tool-result') {
|
|
42
|
-
if (end === -1) {
|
|
43
|
-
// Drop what arrived, keeping only a possible start of the closing fence.
|
|
44
|
-
this.#buffer = this.#buffer.slice(this.#buffer.length - partialEnd(this.#buffer, [block.close]));
|
|
45
|
-
return parts;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
// Stream thinking right away, holding back only a possible start of </think>.
|
|
50
|
-
const upTo = end === -1
|
|
51
|
-
? this.#buffer.length - partialEnd(this.#buffer, [block.close])
|
|
52
|
-
: end;
|
|
53
|
-
add(parts, 'reasoning', this.#buffer.slice(0, upTo));
|
|
54
|
-
if (end === -1) {
|
|
55
|
-
this.#buffer = this.#buffer.slice(upTo);
|
|
56
|
-
return parts;
|
|
57
|
-
}
|
|
58
|
-
parts.push({ kind: 'reasoning-end' });
|
|
59
|
-
}
|
|
60
|
-
this.#buffer = this.#buffer.slice(end + block.close.length);
|
|
61
|
-
this.#inside = undefined;
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
const start = this.#findOpening();
|
|
65
|
-
if (start) {
|
|
66
|
-
add(parts, 'text', this.#buffer.slice(0, start.index));
|
|
67
|
-
this.#buffer = this.#buffer.slice(start.index + start.block.open.length);
|
|
68
|
-
this.#inside = start.block;
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
const keep = partialEnd(this.#buffer, BLOCKS.map((b) => b.open));
|
|
72
|
-
add(parts, 'text', this.#buffer.slice(0, this.#buffer.length - keep));
|
|
73
|
-
this.#buffer = this.#buffer.slice(this.#buffer.length - keep);
|
|
74
|
-
return parts;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
/** Call when the stream ends. An unclosed tool call is returned as `tool-call-cut`. */
|
|
78
|
-
end() {
|
|
79
|
-
const parts = [];
|
|
80
|
-
if (this.#inside?.kind === 'tool-call') {
|
|
81
|
-
parts.push({ kind: 'tool-call-cut', raw: this.#buffer.trim() });
|
|
82
|
-
}
|
|
83
|
-
else if (this.#inside?.kind === 'reasoning') {
|
|
84
|
-
add(parts, 'reasoning', this.#buffer);
|
|
85
|
-
parts.push({ kind: 'reasoning-end' });
|
|
86
|
-
}
|
|
87
|
-
else if (this.#inside?.kind === 'tool-result') {
|
|
88
|
-
// An echoed tool result that was never closed: dropped like a closed one.
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
add(parts, 'text', this.#buffer);
|
|
92
|
-
}
|
|
93
|
-
this.#buffer = '';
|
|
94
|
-
this.#inside = undefined;
|
|
95
|
-
return parts;
|
|
96
|
-
}
|
|
97
|
-
#findOpening() {
|
|
98
|
-
let found;
|
|
99
|
-
for (const block of BLOCKS) {
|
|
100
|
-
const index = this.#buffer.indexOf(block.open);
|
|
101
|
-
if (index !== -1 && (!found || index < found.index))
|
|
102
|
-
found = { index, block };
|
|
103
|
-
}
|
|
104
|
-
return found;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
function add(parts, kind, text) {
|
|
108
|
-
if (text)
|
|
109
|
-
parts.push({ kind, text });
|
|
110
|
-
}
|
|
111
|
-
/** Length of the longest ending of `text` that is the start of one of the `tags`. */
|
|
112
|
-
function partialEnd(text, tags) {
|
|
113
|
-
let longest = 0;
|
|
114
|
-
for (const tag of tags) {
|
|
115
|
-
for (let length = Math.min(tag.length - 1, text.length); length > longest; length--) {
|
|
116
|
-
if (text.endsWith(tag.slice(0, length))) {
|
|
117
|
-
longest = length;
|
|
118
|
-
break;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return longest;
|
|
123
|
-
}
|
|
124
|
-
//# sourceMappingURL=parser.js.map
|
package/src/lib/parser.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../../../../../../libs/agent/browser-models/src/lib/parser.ts"],"names":[],"mappings":"AAcA;;;GAGG;AACH,MAAM,MAAM,GAAG;IACb,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,KAAK,EAAE;IACzD,0FAA0F;IAC1F,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAE,KAAK,EAAE;IAC7D,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,cAAc,EAAE;IACjE,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,UAAU,EAAE;CACjD,CAAC;AAIX;;;GAGG;AACH,MAAM,OAAO,YAAY;IACvB,OAAO,GAAG,EAAE,CAAC;IACb,OAAO,CAAoB;IAE3B,4EAA4E;IAC5E,IAAI,CAAC,QAAgB;QACnB,IAAI,CAAC,OAAO,IAAI,QAAQ,CAAC;QACzB,MAAM,KAAK,GAAiB,EAAE,CAAC;QAE/B,SAAS,CAAC;YACR,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC;YAC3B,IAAI,KAAK,EAAE,CAAC;gBACV,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBAC9C,IAAI,KAAK,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;oBAC/B,IAAI,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC;wBACf,uEAAuE;wBACvE,MAAM,IAAI,GACR,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;wB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AAmB,EACnB,IAA0B,EAC1B,IAAY;IAEZ,IAAI,IAAI;QAAE,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;AACvC,CAAC;AAED,qFAAqF;AACrF,SAAS,UAAU,CAAC,IAAY,EAAE,IAAuB;IACvD,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,KACE,IAAI,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,EAClD,MAAM,GAAG,OAAO,EAChB,MAAM,EAAE,EACR,CAAC;YACD,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC;gBACxC,OAAO,GAAG,MAAM,CAAC;gBACjB,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/** JSON that was cut off somewhere, closed so it can be parsed. */
|
|
2
|
-
export interface ClosedJson {
|
|
3
|
-
/** Valid JSON, or `''` when nothing complete has arrived yet. */
|
|
4
|
-
readonly json: string;
|
|
5
|
-
/** True when the cut is inside a string value: that string may still grow. */
|
|
6
|
-
readonly inString: boolean;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Closes JSON that a model is still writing, keeping only what is certain.
|
|
10
|
-
*
|
|
11
|
-
* A string value that is cut off is kept as far as it goes. Anything else that is unfinished is
|
|
12
|
-
* left out: half a key, a key without its value, a number or literal that may still grow.
|
|
13
|
-
* Brackets and braces inside strings are text, not structure, so code in a string is safe.
|
|
14
|
-
*
|
|
15
|
-
* ```ts
|
|
16
|
-
* closeJson('{"city": "Vie'); // {"city": "Vie"}
|
|
17
|
-
* closeJson('{"city": "Vienna", "da'); // {"city": "Vienna"}
|
|
18
|
-
* closeJson('{"days": 1'); // {} (could become 12)
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
export declare function closeJson(text: string): ClosedJson;
|
package/src/lib/partial-json.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Closes JSON that a model is still writing, keeping only what is certain.
|
|
3
|
-
*
|
|
4
|
-
* A string value that is cut off is kept as far as it goes. Anything else that is unfinished is
|
|
5
|
-
* left out: half a key, a key without its value, a number or literal that may still grow.
|
|
6
|
-
* Brackets and braces inside strings are text, not structure, so code in a string is safe.
|
|
7
|
-
*
|
|
8
|
-
* ```ts
|
|
9
|
-
* closeJson('{"city": "Vie'); // {"city": "Vie"}
|
|
10
|
-
* closeJson('{"city": "Vienna", "da'); // {"city": "Vienna"}
|
|
11
|
-
* closeJson('{"days": 1'); // {} (could become 12)
|
|
12
|
-
* ```
|
|
13
|
-
*/
|
|
14
|
-
export function closeJson(text) {
|
|
15
|
-
/** The closing characters still owed, innermost last. */
|
|
16
|
-
const open = [];
|
|
17
|
-
/** How far the text is complete, and what closes it there. */
|
|
18
|
-
let complete = { end: 0, closers: '' };
|
|
19
|
-
let inString = false;
|
|
20
|
-
let isKey = false;
|
|
21
|
-
/** Where an escape sequence that is not finished yet starts. */
|
|
22
|
-
let escapeStart = -1;
|
|
23
|
-
let hexDigits = 0;
|
|
24
|
-
/** In an object: the next string is a key. */
|
|
25
|
-
let expectKey = false;
|
|
26
|
-
const closers = () => [...open].reverse().join('');
|
|
27
|
-
const valueEnds = (end) => {
|
|
28
|
-
complete = { end, closers: closers() };
|
|
29
|
-
};
|
|
30
|
-
for (let i = 0; i < text.length; i++) {
|
|
31
|
-
const char = text.charAt(i);
|
|
32
|
-
if (inString) {
|
|
33
|
-
if (hexDigits > 0) {
|
|
34
|
-
if (--hexDigits === 0)
|
|
35
|
-
escapeStart = -1;
|
|
36
|
-
}
|
|
37
|
-
else if (escapeStart >= 0) {
|
|
38
|
-
if (char === 'u')
|
|
39
|
-
hexDigits = 4;
|
|
40
|
-
else
|
|
41
|
-
escapeStart = -1;
|
|
42
|
-
}
|
|
43
|
-
else if (char === '\\') {
|
|
44
|
-
escapeStart = i;
|
|
45
|
-
}
|
|
46
|
-
else if (char === '"') {
|
|
47
|
-
inString = false;
|
|
48
|
-
if (!isKey)
|
|
49
|
-
valueEnds(i + 1);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
else if (char === '"') {
|
|
53
|
-
inString = true;
|
|
54
|
-
isKey = expectKey;
|
|
55
|
-
expectKey = false;
|
|
56
|
-
}
|
|
57
|
-
else if (char === '{' || char === '[') {
|
|
58
|
-
open.push(char === '{' ? '}' : ']');
|
|
59
|
-
expectKey = char === '{';
|
|
60
|
-
// An empty object or array is complete as it is.
|
|
61
|
-
valueEnds(i + 1);
|
|
62
|
-
}
|
|
63
|
-
else if (char === '}' || char === ']') {
|
|
64
|
-
open.pop();
|
|
65
|
-
expectKey = false;
|
|
66
|
-
valueEnds(i + 1);
|
|
67
|
-
}
|
|
68
|
-
else if (char === ',') {
|
|
69
|
-
expectKey = open.at(-1) === '}';
|
|
70
|
-
}
|
|
71
|
-
else if (/[-\w.+]/.test(char)) {
|
|
72
|
-
// A number or literal is complete only when something follows it.
|
|
73
|
-
const end = i + (/^[-\w.+]+/.exec(text.slice(i))?.[0].length ?? 1);
|
|
74
|
-
if (end < text.length)
|
|
75
|
-
valueEnds(end);
|
|
76
|
-
i = end - 1;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
if (inString && !isKey) {
|
|
80
|
-
const end = escapeStart >= 0 ? escapeStart : text.length;
|
|
81
|
-
return { json: text.slice(0, end) + '"' + closers(), inString: true };
|
|
82
|
-
}
|
|
83
|
-
return {
|
|
84
|
-
json: text.slice(0, complete.end) + complete.closers,
|
|
85
|
-
inString: false,
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
//# sourceMappingURL=partial-json.js.map
|
|
@@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CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC;YACnE,IAAI,GAAG,GAAG,IAAI,CAAC,MAAM;gBAAE,SAAS,CAAC,GAAG,CAAC,CAAC;YACtC,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC;QACd,CAAC;IACH,CAAC;IAED,IAAI,QAAQ,IAAI,CAAC,KAAK,EAAE,CAAC;QACvB,MAAM,GAAG,GAAG,WAAW,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;QACzD,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,GAAG,GAAG,OAAO,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IACxE,CAAC;IACD,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,OAAO;QACpD,QAAQ,EAAE,KAAK;KAChB,CAAC;AACJ,CAAC"}
|
package/src/lib/prompt.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { Context, Message } from '@ag-ui/core';
|
|
2
|
-
import type { ChatMessage } from './engine.ts';
|
|
3
|
-
import type { ToolSpec } from './tools.ts';
|
|
4
|
-
/** Turns the AG-UI conversation into plain chat messages, with tool instructions in the system prompt. */
|
|
5
|
-
export declare function buildChatMessages(messages: readonly Message[], context: readonly Context[], tools: readonly ToolSpec[]): ChatMessage[];
|
|
6
|
-
/** How a tool call looks in the conversation the model sees. */
|
|
7
|
-
export declare function toolCallBlock(name: string, argumentsJson: string): string;
|
|
8
|
-
/** How a tool result looks in the conversation the model sees. */
|
|
9
|
-
export declare function toolResultBlock(name: string, result: string): string;
|
package/src/lib/prompt.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
/** Turns the AG-UI conversation into plain chat messages, with tool instructions in the system prompt. */
|
|
2
|
-
export function buildChatMessages(messages, context, tools) {
|
|
3
|
-
const system = [];
|
|
4
|
-
const chat = [];
|
|
5
|
-
const toolNames = new Map();
|
|
6
|
-
for (const message of messages) {
|
|
7
|
-
switch (message.role) {
|
|
8
|
-
case 'system':
|
|
9
|
-
case 'developer':
|
|
10
|
-
system.push(message.content);
|
|
11
|
-
break;
|
|
12
|
-
case 'user':
|
|
13
|
-
chat.push({ role: 'user', content: textOf(message.content) });
|
|
14
|
-
break;
|
|
15
|
-
case 'assistant': {
|
|
16
|
-
const calls = (message.toolCalls ?? []).map((call) => {
|
|
17
|
-
toolNames.set(call.id, call.function.name);
|
|
18
|
-
return toolCallBlock(call.function.name, call.function.arguments);
|
|
19
|
-
});
|
|
20
|
-
const content = [message.content ?? '', ...calls]
|
|
21
|
-
.filter(Boolean)
|
|
22
|
-
.join('\n');
|
|
23
|
-
if (content)
|
|
24
|
-
chat.push({ role: 'assistant', content });
|
|
25
|
-
break;
|
|
26
|
-
}
|
|
27
|
-
case 'tool':
|
|
28
|
-
chat.push({
|
|
29
|
-
role: 'user',
|
|
30
|
-
content: toolResultBlock(toolNames.get(message.toolCallId) ?? 'unknown', message.error ?? (textOf(message.content) || EMPTY_RESULT)),
|
|
31
|
-
});
|
|
32
|
-
break;
|
|
33
|
-
default:
|
|
34
|
-
// Activity and reasoning messages are UI-only and not sent to the model.
|
|
35
|
-
break;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
for (const item of context)
|
|
39
|
-
system.push(`${item.description}:\n${item.value}`);
|
|
40
|
-
if (tools.length > 0)
|
|
41
|
-
system.push(toolInstructions(tools));
|
|
42
|
-
return system.length > 0
|
|
43
|
-
? [{ role: 'system', content: system.join('\n\n') }, ...chat]
|
|
44
|
-
: chat;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Said to the model when a tool returns nothing, for example a CopilotKit `registerComponent`
|
|
48
|
-
* tool that only shows a component. An empty result reads like a failure to small models.
|
|
49
|
-
*/
|
|
50
|
-
const EMPTY_RESULT = 'Done. The tool ran and returned no data.';
|
|
51
|
-
/** How a tool call looks in the conversation the model sees. */
|
|
52
|
-
export function toolCallBlock(name, argumentsJson) {
|
|
53
|
-
return ('```tool_call\n' +
|
|
54
|
-
`{"name": ${JSON.stringify(name)}, "arguments": ${argumentsJson || '{}'}}` +
|
|
55
|
-
'\n```');
|
|
56
|
-
}
|
|
57
|
-
/** How a tool result looks in the conversation the model sees. */
|
|
58
|
-
export function toolResultBlock(name, result) {
|
|
59
|
-
return '```tool_result\n' + JSON.stringify({ name, result }) + '\n```';
|
|
60
|
-
}
|
|
61
|
-
function toolInstructions(tools) {
|
|
62
|
-
const list = tools
|
|
63
|
-
.map((tool) => `- ${tool.name}: ${tool.description}\n arguments (JSON Schema): ${JSON.stringify(tool.parameters ?? { type: 'object' })}`)
|
|
64
|
-
.join('\n');
|
|
65
|
-
return [
|
|
66
|
-
'You can call tools. To call one, reply with a block like this and nothing after it:',
|
|
67
|
-
'```tool_call\n{"name": "<tool name>", "arguments": { ... }}\n```',
|
|
68
|
-
'Tool results come back in a ```tool_result block. Only call a tool when you need it.',
|
|
69
|
-
'After a tool result, answer the user in plain words. Never write a tool_result block yourself.',
|
|
70
|
-
'If a tool result is an error, do not give up: fix the arguments or call the tool that provides what is missing, then try again.',
|
|
71
|
-
'Available tools:',
|
|
72
|
-
list,
|
|
73
|
-
].join('\n');
|
|
74
|
-
}
|
|
75
|
-
function textOf(content) {
|
|
76
|
-
if (typeof content === 'string')
|
|
77
|
-
return content;
|
|
78
|
-
return content
|
|
79
|
-
.map((part) => (part.type === 'text' ? (part.text ?? '') : ''))
|
|
80
|
-
.join('');
|
|
81
|
-
}
|
|
82
|
-
//# sourceMappingURL=prompt.js.map
|
package/src/lib/prompt.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../../../../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IAAI,EAAE,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC;AACzE,CAAC;AAED,SAAS,gBAAgB,CAAC,KAA0B;IAClD,MAAM,IAAI,GAAG,KAAK;SACf,GAAG,CACF,CAAC,IAAI,EAAE,EAAE,CACP,KAAK,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,WAAW,gCAAgC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,EAAE,CAC7H;SACA,IAAI,CAAC,IAAI,CAAC,CAAC;IACd,OAAO;QACL,qFAAqF;QACrF,kEAAkE;QAClE,sFAAsF;QACtF,gGAAgG;QAChG,iIAAiI;QACjI,kBAAkB;QAClB,IAAI;KACL,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC;AAED,SAAS,MAAM,CACb,OAA4D;IAE5D,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,OAAO,CAAC;IAChD,OAAO,OAAO;SACX,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;SAC9D,IAAI,CAAC,EAAE,CAAC,CAAC;AACd,CAAC"}
|
package/src/lib/repair.d.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type { ToolCall, ToolSpec } from './tools.ts';
|
|
2
|
-
/** How a broken tool call was fixed, in the order the steps ran. */
|
|
3
|
-
export type RepairStep = 'json' | 'name' | 'coerce' | 'reask' | 'hook';
|
|
4
|
-
export type RepairResult = {
|
|
5
|
-
readonly ok: true;
|
|
6
|
-
readonly call: ToolCall;
|
|
7
|
-
readonly steps: readonly RepairStep[];
|
|
8
|
-
} | {
|
|
9
|
-
readonly ok: false;
|
|
10
|
-
readonly error: string;
|
|
11
|
-
};
|
|
12
|
-
export interface RepairOptions {
|
|
13
|
-
/**
|
|
14
|
-
* Asks the model once more for valid arguments. Returns the new raw arguments
|
|
15
|
-
* text (or a whole call), or undefined when the engine cannot be asked again.
|
|
16
|
-
*/
|
|
17
|
-
readonly reask?: (tool: ToolSpec, error: string,
|
|
18
|
-
/** The raw call that had the error. */
|
|
19
|
-
raw: string) => Promise<string | undefined>;
|
|
20
|
-
/** Your own last-chance fix. Return a call to use it, or undefined to give up. */
|
|
21
|
-
readonly hook?: (input: {
|
|
22
|
-
readonly raw: string;
|
|
23
|
-
readonly error: string;
|
|
24
|
-
readonly tools: readonly ToolSpec[];
|
|
25
|
-
}) => Promise<ToolCall | undefined> | ToolCall | undefined;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Turns the raw text of a tool call into a valid call for one of `tools`. Steps, stopping at
|
|
29
|
-
* the first success: JSON repair (jsonrepair) → tool name repair → schema coercion → re-ask
|
|
30
|
-
* the model → user hook.
|
|
31
|
-
*/
|
|
32
|
-
export declare class ToolCallRepair {
|
|
33
|
-
#private;
|
|
34
|
-
constructor(tools: readonly ToolSpec[], options?: RepairOptions);
|
|
35
|
-
/** Repairs one complete call. */
|
|
36
|
-
repair(raw: string): Promise<RepairResult>;
|
|
37
|
-
/**
|
|
38
|
-
* Reads a call the model is still writing, so it can be shown while it streams. Returns
|
|
39
|
-
* nothing until the name is complete and (after name repair) a known tool. `argumentsJson`
|
|
40
|
-
* is the start of the arguments JSON that is already certain. It is a preview only: the
|
|
41
|
-
* complete call still goes through `repair`.
|
|
42
|
-
*/
|
|
43
|
-
readPartial(raw: string): {
|
|
44
|
-
readonly name: string;
|
|
45
|
-
readonly argumentsJson: string;
|
|
46
|
-
} | undefined;
|
|
47
|
-
}
|
package/src/lib/repair.js
DELETED
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
import { jsonrepair } from 'jsonrepair';
|
|
2
|
-
import { closeJson } from "./partial-json.js";
|
|
3
|
-
import { z } from 'zod';
|
|
4
|
-
import { ArgumentsSchema } from "./schema.js";
|
|
5
|
-
const jsonObject = z.record(z.string(), z.unknown());
|
|
6
|
-
/** A tool call as models write it. Some say `parameters` for `arguments`. */
|
|
7
|
-
const callEnvelope = z.looseObject({
|
|
8
|
-
name: z.string(),
|
|
9
|
-
arguments: z.unknown().optional(),
|
|
10
|
-
parameters: z.unknown().optional(),
|
|
11
|
-
});
|
|
12
|
-
/** For tools without parameters. One object, so its compiled schema is reused. */
|
|
13
|
-
const anyObject = { type: 'object' };
|
|
14
|
-
/**
|
|
15
|
-
* Turns the raw text of a tool call into a valid call for one of `tools`. Steps, stopping at
|
|
16
|
-
* the first success: JSON repair (jsonrepair) → tool name repair → schema coercion → re-ask
|
|
17
|
-
* the model → user hook.
|
|
18
|
-
*/
|
|
19
|
-
export class ToolCallRepair {
|
|
20
|
-
#tools;
|
|
21
|
-
#options;
|
|
22
|
-
constructor(tools, options = {}) {
|
|
23
|
-
this.#tools = tools;
|
|
24
|
-
this.#options = options;
|
|
25
|
-
}
|
|
26
|
-
/** Repairs one complete call. */
|
|
27
|
-
async repair(raw) {
|
|
28
|
-
const result = await this.#tryRepair(raw);
|
|
29
|
-
const hook = this.#options.hook;
|
|
30
|
-
if (result.ok || !hook)
|
|
31
|
-
return result;
|
|
32
|
-
// A failing hook must not end the run: the model is told the error instead.
|
|
33
|
-
let fixed;
|
|
34
|
-
try {
|
|
35
|
-
fixed = await hook({ raw, error: result.error, tools: this.#tools });
|
|
36
|
-
}
|
|
37
|
-
catch {
|
|
38
|
-
return result;
|
|
39
|
-
}
|
|
40
|
-
// Earlier steps did not lead to this call, so only the hook is reported.
|
|
41
|
-
return fixed ? { ok: true, call: fixed, steps: ['hook'] } : result;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Reads a call the model is still writing, so it can be shown while it streams. Returns
|
|
45
|
-
* nothing until the name is complete and (after name repair) a known tool. `argumentsJson`
|
|
46
|
-
* is the start of the arguments JSON that is already certain. It is a preview only: the
|
|
47
|
-
* complete call still goes through `repair`.
|
|
48
|
-
*/
|
|
49
|
-
readPartial(raw) {
|
|
50
|
-
// Well-formed JSON is closed exactly. JSON that needs repair (single quotes, bare keys) is
|
|
51
|
-
// read with jsonrepair, which has to guess: the arguments are then only a likely preview.
|
|
52
|
-
const closed = closeJson(raw);
|
|
53
|
-
const exact = parse(closed.json);
|
|
54
|
-
const parsed = exact ?? parse(() => jsonrepair(raw));
|
|
55
|
-
const call = callEnvelope.safeParse(parsed).data;
|
|
56
|
-
if (!call)
|
|
57
|
-
return undefined;
|
|
58
|
-
// The model is still writing the name itself.
|
|
59
|
-
const lastKey = Object.keys(jsonObject.safeParse(parsed).data ?? {}).at(-1);
|
|
60
|
-
if (lastKey === 'name' && (exact === undefined || closed.inString))
|
|
61
|
-
return undefined;
|
|
62
|
-
const tool = findTool(call.name, this.#tools);
|
|
63
|
-
if (!tool)
|
|
64
|
-
return undefined;
|
|
65
|
-
const args = jsonObject.safeParse(call.arguments ?? call.parameters);
|
|
66
|
-
if (!args.success)
|
|
67
|
-
return { name: tool.name, argumentsJson: '' };
|
|
68
|
-
const json = JSON.stringify(args.data);
|
|
69
|
-
if (exact === undefined)
|
|
70
|
-
return { name: tool.name, argumentsJson: certainStart(json, raw) };
|
|
71
|
-
// What is still open gets closed later: leave the closing characters out.
|
|
72
|
-
const start = json.replace(/[\]}]+$/, '');
|
|
73
|
-
return {
|
|
74
|
-
name: tool.name,
|
|
75
|
-
argumentsJson: closed.inString ? start.slice(0, -1) : start,
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
async #tryRepair(raw) {
|
|
79
|
-
const steps = [];
|
|
80
|
-
const call = callEnvelope.safeParse(parseJson(raw, steps)).data;
|
|
81
|
-
if (!call) {
|
|
82
|
-
return {
|
|
83
|
-
ok: false,
|
|
84
|
-
error: 'The tool call must be a JSON object with a "name".',
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
const tool = findTool(call.name, this.#tools);
|
|
88
|
-
if (!tool) {
|
|
89
|
-
const names = this.#tools.map((t) => t.name).join(', ');
|
|
90
|
-
return {
|
|
91
|
-
ok: false,
|
|
92
|
-
error: `Unknown tool "${call.name}". Available tools: ${names}.`,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
if (tool.name !== call.name)
|
|
96
|
-
steps.push('name');
|
|
97
|
-
let args = parseArguments(call.arguments ?? call.parameters ?? {}, steps);
|
|
98
|
-
let check = checkArguments(args, tool);
|
|
99
|
-
if (check.errors.length > 0 && this.#options.reask) {
|
|
100
|
-
// A failing re-ask (for example an engine that rejects the schema as a constraint)
|
|
101
|
-
// must not end the run: the model is told the error instead.
|
|
102
|
-
let answer;
|
|
103
|
-
try {
|
|
104
|
-
answer = await this.#options.reask(tool, check.errors.join('; '), raw);
|
|
105
|
-
}
|
|
106
|
-
catch {
|
|
107
|
-
answer = undefined;
|
|
108
|
-
}
|
|
109
|
-
if (answer !== undefined) {
|
|
110
|
-
args = unwrapCall(parseArguments(answer, steps));
|
|
111
|
-
check = checkArguments(args, tool);
|
|
112
|
-
steps.push('reask');
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
if (check.errors.length > 0) {
|
|
116
|
-
return {
|
|
117
|
-
ok: false,
|
|
118
|
-
error: `Invalid arguments for "${tool.name}": ${check.errors.join('; ')}.`,
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
if (check.coerced)
|
|
122
|
-
steps.push('coerce');
|
|
123
|
-
return {
|
|
124
|
-
ok: true,
|
|
125
|
-
call: { name: tool.name, arguments: check.value },
|
|
126
|
-
steps,
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* The start of `json` (the arguments jsonrepair made of the unfinished `raw`) that stays the
|
|
132
|
-
* same when the rest of the call arrives. jsonrepair closes what is open and guesses the
|
|
133
|
-
* unfinished end: half a key becomes `"key":null`, half a `true` becomes the string "tr".
|
|
134
|
-
*/
|
|
135
|
-
function certainStart(json, raw) {
|
|
136
|
-
const open = json.replace(/[\]}]+$/, '');
|
|
137
|
-
const quotes = raw.replace(/\\./g, '').split('"').length - 1;
|
|
138
|
-
if (open.endsWith('"')) {
|
|
139
|
-
// Inside a string value: all of it but the closing quote is certain.
|
|
140
|
-
if (quotes % 2 === 1)
|
|
141
|
-
return open.slice(0, -1);
|
|
142
|
-
// A finished string, unless the raw text ends in a bare word such as `tr`.
|
|
143
|
-
if (!/\w$/.test(raw))
|
|
144
|
-
return open;
|
|
145
|
-
}
|
|
146
|
-
// A number, literal or key that may still grow: drop the whole last entry.
|
|
147
|
-
return open.slice(0, Math.max(open.lastIndexOf(','), open.lastIndexOf('{') + 1, open.lastIndexOf('[') + 1));
|
|
148
|
-
}
|
|
149
|
-
/** The parsed JSON, or undefined when it is not valid JSON. */
|
|
150
|
-
function parse(json) {
|
|
151
|
-
try {
|
|
152
|
-
return JSON.parse(typeof json === 'string' ? json : json());
|
|
153
|
-
}
|
|
154
|
-
catch {
|
|
155
|
-
return undefined;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
function checkArguments(args, tool) {
|
|
159
|
-
const check = ArgumentsSchema.of(tool.parameters ?? anyObject).check(args);
|
|
160
|
-
return { ...check, value: jsonObject.safeParse(check.value).data ?? {} };
|
|
161
|
-
}
|
|
162
|
-
function parseJson(text, steps) {
|
|
163
|
-
try {
|
|
164
|
-
return JSON.parse(text);
|
|
165
|
-
}
|
|
166
|
-
catch {
|
|
167
|
-
try {
|
|
168
|
-
const value = JSON.parse(jsonrepair(text));
|
|
169
|
-
steps.push('json');
|
|
170
|
-
return value;
|
|
171
|
-
}
|
|
172
|
-
catch {
|
|
173
|
-
return undefined;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
/** A re-ask may be answered with a whole call (`{name, arguments}`) instead of the arguments. */
|
|
178
|
-
function unwrapCall(value) {
|
|
179
|
-
const call = callEnvelope.safeParse(value).data;
|
|
180
|
-
return call ? (call.arguments ?? call.parameters ?? value) : value;
|
|
181
|
-
}
|
|
182
|
-
function parseArguments(value, steps) {
|
|
183
|
-
// Some models send the arguments object as a JSON string.
|
|
184
|
-
return typeof value === 'string' ? parseJson(value, steps) : value;
|
|
185
|
-
}
|
|
186
|
-
/** Exact name first, then the same name in other spelling, then one unambiguous typo. */
|
|
187
|
-
function findTool(name, tools) {
|
|
188
|
-
const exact = tools.find((tool) => tool.name === name);
|
|
189
|
-
if (exact)
|
|
190
|
-
return exact;
|
|
191
|
-
const wanted = normalize(name);
|
|
192
|
-
const sameName = tools.filter((tool) => normalize(tool.name) === wanted);
|
|
193
|
-
if (sameName.length === 1)
|
|
194
|
-
return sameName[0];
|
|
195
|
-
const close = tools.filter((tool) => editDistance(normalize(tool.name), wanted) <= 2);
|
|
196
|
-
return close.length === 1 ? close[0] : undefined;
|
|
197
|
-
}
|
|
198
|
-
/** "functions.getWeather", "get-weather" and "GET_WEATHER" all become "getweather". */
|
|
199
|
-
function normalize(name) {
|
|
200
|
-
return name
|
|
201
|
-
.replace(/^functions\./, '')
|
|
202
|
-
.toLowerCase()
|
|
203
|
-
.replace(/[^a-z0-9]/g, '');
|
|
204
|
-
}
|
|
205
|
-
function editDistance(a, b) {
|
|
206
|
-
let previous = Array.from({ length: b.length + 1 }, (_, index) => index);
|
|
207
|
-
for (let i = 1; i <= a.length; i++) {
|
|
208
|
-
const current = [i];
|
|
209
|
-
for (let j = 1; j <= b.length; j++) {
|
|
210
|
-
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
211
|
-
current[j] = Math.min((previous[j] ?? 0) + 1, (current[j - 1] ?? 0) + 1, (previous[j - 1] ?? 0) + cost);
|
|
212
|
-
}
|
|
213
|
-
previous = current;
|
|
214
|
-
}
|
|
215
|
-
return previous[b.length] ?? 0;
|
|
216
|
-
}
|
|
217
|
-
//# sourceMappingURL=repair.js.map
|
package/src/lib/repair.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file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