@ulearning/ai-generative-frame 0.0.0-stage → 1.0.0-next.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/LICENSE +21 -0
- package/README.md +233 -2
- package/dist/assistant-ui/entry.d.ts +34 -0
- package/dist/assistant-ui/entry.d.ts.map +1 -0
- package/dist/assistant-ui/entry.js +50 -0
- package/dist/assistant-ui/entry.js.map +1 -0
- package/dist/assistant-ui/extension.d.ts +18 -0
- package/dist/assistant-ui/extension.d.ts.map +1 -0
- package/dist/assistant-ui/extension.js +0 -0
- package/dist/assistant-ui/history.d.ts +15 -0
- package/dist/assistant-ui/history.d.ts.map +1 -0
- package/dist/assistant-ui/history.js +39 -0
- package/dist/assistant-ui/history.js.map +1 -0
- package/dist/assistant-ui/modelContext.d.ts +45 -0
- package/dist/assistant-ui/modelContext.d.ts.map +1 -0
- package/dist/assistant-ui/modelContext.js +88 -0
- package/dist/assistant-ui/modelContext.js.map +1 -0
- package/dist/assistant-ui/snapshotSaver.d.ts +11 -0
- package/dist/assistant-ui/snapshotSaver.d.ts.map +1 -0
- package/dist/assistant-ui/snapshotSaver.js +83 -0
- package/dist/assistant-ui/snapshotSaver.js.map +1 -0
- package/dist/assistant-ui/tool-calls.d.ts +21 -0
- package/dist/assistant-ui/tool-calls.d.ts.map +1 -0
- package/dist/assistant-ui/tool-calls.js +65 -0
- package/dist/assistant-ui/tool-calls.js.map +1 -0
- package/dist/assistant-ui/toolkit.d.ts +96 -0
- package/dist/assistant-ui/toolkit.d.ts.map +1 -0
- package/dist/assistant-ui/toolkit.js +456 -0
- package/dist/assistant-ui/toolkit.js.map +1 -0
- package/dist/assistant-ui/useSharedContext.d.ts +14 -0
- package/dist/assistant-ui/useSharedContext.d.ts.map +1 -0
- package/dist/assistant-ui/useSharedContext.js +27 -0
- package/dist/assistant-ui/useSharedContext.js.map +1 -0
- package/dist/assistant-ui.d.ts +3 -0
- package/dist/assistant-ui.d.ts.map +1 -0
- package/dist/assistant-ui.js +1 -0
- package/dist/bootstrap.d.ts +23 -0
- package/dist/bootstrap.d.ts.map +1 -0
- package/dist/bootstrap.js +78 -0
- package/dist/bootstrap.js.map +1 -0
- package/dist/csp.d.ts +25 -0
- package/dist/csp.d.ts.map +1 -0
- package/dist/csp.js +78 -0
- package/dist/csp.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/json-schema.d.ts +70 -0
- package/dist/json-schema.d.ts.map +1 -0
- package/dist/json-schema.js +163 -0
- package/dist/json-schema.js.map +1 -0
- package/dist/preview.d.ts +30 -0
- package/dist/preview.d.ts.map +1 -0
- package/dist/preview.js +60 -0
- package/dist/preview.js.map +1 -0
- package/dist/prompts/guidance.d.ts +41 -0
- package/dist/prompts/guidance.d.ts.map +1 -0
- package/dist/prompts/guidance.js +268 -0
- package/dist/prompts/guidance.js.map +1 -0
- package/dist/prompts.d.ts +2 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +1 -0
- package/dist/protocol.d.ts +114 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +49 -0
- package/dist/protocol.js.map +1 -0
- package/dist/repair/repair.d.ts +72 -0
- package/dist/repair/repair.d.ts.map +1 -0
- package/dist/repair/repair.js +103 -0
- package/dist/repair/repair.js.map +1 -0
- package/dist/repair.d.ts +2 -0
- package/dist/repair.d.ts.map +1 -0
- package/dist/repair.js +1 -0
- package/dist/rpc.d.ts +60 -0
- package/dist/rpc.d.ts.map +1 -0
- package/dist/rpc.js +127 -0
- package/dist/rpc.js.map +1 -0
- package/dist/runtime/diagnostics.d.ts +17 -0
- package/dist/runtime/diagnostics.d.ts.map +1 -0
- package/dist/runtime/diagnostics.js +128 -0
- package/dist/runtime/diagnostics.js.map +1 -0
- package/dist/runtime/generated.d.ts +2 -0
- package/dist/runtime/generated.d.ts.map +1 -0
- package/dist/runtime/generated.js +5 -0
- package/dist/runtime/generated.js.map +1 -0
- package/dist/runtime/index.d.ts +7 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +264 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/morph.d.ts +51 -0
- package/dist/runtime/morph.d.ts.map +1 -0
- package/dist/runtime/morph.js +251 -0
- package/dist/runtime/morph.js.map +1 -0
- package/dist/runtime/screenshot.d.ts +23 -0
- package/dist/runtime/screenshot.d.ts.map +1 -0
- package/dist/runtime/screenshot.js +188 -0
- package/dist/runtime/screenshot.js.map +1 -0
- package/dist/runtime/size.d.ts +10 -0
- package/dist/runtime/size.d.ts.map +1 -0
- package/dist/runtime/size.js +21 -0
- package/dist/runtime/size.js.map +1 -0
- package/dist/runtime/storage.d.ts +4 -0
- package/dist/runtime/storage.d.ts.map +1 -0
- package/dist/runtime/storage.js +38 -0
- package/dist/runtime/storage.js.map +1 -0
- package/dist/spec/actions.d.ts +40 -0
- package/dist/spec/actions.d.ts.map +1 -0
- package/dist/spec/actions.js +53 -0
- package/dist/spec/actions.js.map +1 -0
- package/dist/spec/assistant-ui/thread.d.ts +66 -0
- package/dist/spec/assistant-ui/thread.d.ts.map +1 -0
- package/dist/spec/assistant-ui/thread.js +252 -0
- package/dist/spec/assistant-ui/thread.js.map +1 -0
- package/dist/spec/assistant-ui/toolkit.d.ts +33 -0
- package/dist/spec/assistant-ui/toolkit.d.ts.map +1 -0
- package/dist/spec/assistant-ui/toolkit.js +142 -0
- package/dist/spec/assistant-ui/toolkit.js.map +1 -0
- package/dist/spec/assistant-ui/web.d.ts +6 -0
- package/dist/spec/assistant-ui/web.d.ts.map +1 -0
- package/dist/spec/assistant-ui/web.js +48 -0
- package/dist/spec/assistant-ui/web.js.map +1 -0
- package/dist/spec/assistant-ui.d.ts +3 -0
- package/dist/spec/assistant-ui.d.ts.map +1 -0
- package/dist/spec/assistant-ui.js +1 -0
- package/dist/spec/calc.d.ts +8 -0
- package/dist/spec/calc.d.ts.map +1 -0
- package/dist/spec/calc.js +498 -0
- package/dist/spec/calc.js.map +1 -0
- package/dist/spec/catalog.d.ts +52 -0
- package/dist/spec/catalog.d.ts.map +1 -0
- package/dist/spec/catalog.js +104 -0
- package/dist/spec/catalog.js.map +1 -0
- package/dist/spec/expressions.d.ts +45 -0
- package/dist/spec/expressions.d.ts.map +1 -0
- package/dist/spec/expressions.js +199 -0
- package/dist/spec/expressions.js.map +1 -0
- package/dist/spec/patch.d.ts +20 -0
- package/dist/spec/patch.d.ts.map +1 -0
- package/dist/spec/patch.js +77 -0
- package/dist/spec/patch.js.map +1 -0
- package/dist/spec/pending.d.ts +15 -0
- package/dist/spec/pending.d.ts.map +1 -0
- package/dist/spec/pending.js +33 -0
- package/dist/spec/pending.js.map +1 -0
- package/dist/spec/pointer.d.ts +17 -0
- package/dist/spec/pointer.d.ts.map +1 -0
- package/dist/spec/pointer.js +88 -0
- package/dist/spec/pointer.js.map +1 -0
- package/dist/spec/prompt.d.ts +29 -0
- package/dist/spec/prompt.d.ts.map +1 -0
- package/dist/spec/prompt.js +145 -0
- package/dist/spec/prompt.js.map +1 -0
- package/dist/spec/render-spec.d.ts +50 -0
- package/dist/spec/render-spec.d.ts.map +1 -0
- package/dist/spec/render-spec.js +104 -0
- package/dist/spec/render-spec.js.map +1 -0
- package/dist/spec/resolve.d.ts +39 -0
- package/dist/spec/resolve.d.ts.map +1 -0
- package/dist/spec/resolve.js +51 -0
- package/dist/spec/resolve.js.map +1 -0
- package/dist/spec/resolved.d.ts +3 -0
- package/dist/spec/resolved.d.ts.map +1 -0
- package/dist/spec/resolved.js +36 -0
- package/dist/spec/resolved.js.map +1 -0
- package/dist/spec/state.d.ts +34 -0
- package/dist/spec/state.d.ts.map +1 -0
- package/dist/spec/state.js +111 -0
- package/dist/spec/state.js.map +1 -0
- package/dist/spec/stream.d.ts +50 -0
- package/dist/spec/stream.d.ts.map +1 -0
- package/dist/spec/stream.js +168 -0
- package/dist/spec/stream.js.map +1 -0
- package/dist/spec/tools.d.ts +3 -0
- package/dist/spec/tools.d.ts.map +1 -0
- package/dist/spec/tools.js +3 -0
- package/dist/spec/tree.d.ts +21 -0
- package/dist/spec/tree.d.ts.map +1 -0
- package/dist/spec/tree.js +27 -0
- package/dist/spec/tree.js.map +1 -0
- package/dist/spec/types.d.ts +66 -0
- package/dist/spec/types.d.ts.map +1 -0
- package/dist/spec/types.js +9 -0
- package/dist/spec/types.js.map +1 -0
- package/dist/spec/validate.d.ts +32 -0
- package/dist/spec/validate.d.ts.map +1 -0
- package/dist/spec/validate.js +264 -0
- package/dist/spec/validate.js.map +1 -0
- package/dist/spec/vue/SpecRenderer.d.ts +43 -0
- package/dist/spec/vue/SpecRenderer.d.ts.map +1 -0
- package/dist/spec/vue/SpecRenderer.js +357 -0
- package/dist/spec/vue/SpecRenderer.js.map +1 -0
- package/dist/spec/vue/useSpecStream.d.ts +19 -0
- package/dist/spec/vue/useSpecStream.d.ts.map +1 -0
- package/dist/spec/vue/useSpecStream.js +115 -0
- package/dist/spec/vue/useSpecStream.js.map +1 -0
- package/dist/spec/vue.d.ts +3 -0
- package/dist/spec/vue.d.ts.map +1 -0
- package/dist/spec/vue.js +3 -0
- package/dist/spec.d.ts +12 -0
- package/dist/spec.d.ts.map +1 -0
- package/dist/spec.js +8 -0
- package/dist/theme.d.ts +38 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +370 -0
- package/dist/theme.js.map +1 -0
- package/dist/tools/define.d.ts +43 -0
- package/dist/tools/define.d.ts.map +1 -0
- package/dist/tools/define.js +31 -0
- package/dist/tools/define.js.map +1 -0
- package/dist/tools/edits.d.ts +19 -0
- package/dist/tools/edits.d.ts.map +1 -0
- package/dist/tools/edits.js +55 -0
- package/dist/tools/edits.js.map +1 -0
- package/dist/tools/registry.d.ts +19 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +33 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/tools/tools.d.ts +88 -0
- package/dist/tools/tools.d.ts.map +1 -0
- package/dist/tools/tools.js +235 -0
- package/dist/tools/tools.js.map +1 -0
- package/dist/tools.d.ts +5 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +5 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +5 -0
- package/dist/version.js.map +1 -0
- package/dist/vue/Widget.d.ts +16 -0
- package/dist/vue/Widget.d.ts.map +1 -0
- package/dist/vue/Widget.js +58 -0
- package/dist/vue/Widget.js.map +1 -0
- package/dist/vue/sync.d.ts +19 -0
- package/dist/vue/sync.d.ts.map +1 -0
- package/dist/vue/sync.js +31 -0
- package/dist/vue/sync.js.map +1 -0
- package/dist/vue/themeStore.d.ts +23 -0
- package/dist/vue/themeStore.d.ts.map +1 -0
- package/dist/vue/themeStore.js +115 -0
- package/dist/vue/themeStore.js.map +1 -0
- package/dist/vue/useThemeTokens.d.ts +6 -0
- package/dist/vue/useThemeTokens.d.ts.map +1 -0
- package/dist/vue/useThemeTokens.js +49 -0
- package/dist/vue/useThemeTokens.js.map +1 -0
- package/dist/vue/useWidget.d.ts +10 -0
- package/dist/vue/useWidget.d.ts.map +1 -0
- package/dist/vue/useWidget.js +81 -0
- package/dist/vue/useWidget.js.map +1 -0
- package/dist/vue.d.ts +5 -0
- package/dist/vue.d.ts.map +1 -0
- package/dist/vue.js +4 -0
- package/dist/widget.d.ts +129 -0
- package/dist/widget.d.ts.map +1 -0
- package/dist/widget.js +655 -0
- package/dist/widget.js.map +1 -0
- package/package.json +125 -3
- package/src/assistant-ui/entry.ts +124 -0
- package/src/assistant-ui/extension.ts +19 -0
- package/src/assistant-ui/history.ts +63 -0
- package/src/assistant-ui/modelContext.ts +162 -0
- package/src/assistant-ui/snapshotSaver.ts +116 -0
- package/src/assistant-ui/tool-calls.ts +115 -0
- package/src/assistant-ui/toolkit.tsx +747 -0
- package/src/assistant-ui/useSharedContext.ts +40 -0
- package/src/assistant-ui.ts +14 -0
- package/src/bootstrap.ts +112 -0
- package/src/csp.ts +96 -0
- package/src/index.ts +44 -0
- package/src/json-schema.ts +353 -0
- package/src/preview.ts +120 -0
- package/src/prompts/guidance.ts +369 -0
- package/src/prompts.ts +8 -0
- package/src/protocol.ts +141 -0
- package/src/repair/repair.ts +202 -0
- package/src/repair.ts +11 -0
- package/src/rpc.ts +228 -0
- package/src/runtime/diagnostics.ts +165 -0
- package/src/runtime/generated.ts +2 -0
- package/src/runtime/index.ts +343 -0
- package/src/runtime/morph.ts +352 -0
- package/src/runtime/screenshot.ts +288 -0
- package/src/runtime/size.ts +17 -0
- package/src/runtime/storage.ts +49 -0
- package/src/spec/actions.ts +111 -0
- package/src/spec/assistant-ui/thread.ts +381 -0
- package/src/spec/assistant-ui/toolkit.tsx +295 -0
- package/src/spec/assistant-ui/web.tsx +63 -0
- package/src/spec/assistant-ui.ts +2 -0
- package/src/spec/calc.ts +598 -0
- package/src/spec/catalog.ts +196 -0
- package/src/spec/expressions.ts +301 -0
- package/src/spec/patch.ts +112 -0
- package/src/spec/pending.ts +36 -0
- package/src/spec/pointer.ts +170 -0
- package/src/spec/prompt.ts +243 -0
- package/src/spec/render-spec.ts +144 -0
- package/src/spec/resolve.ts +123 -0
- package/src/spec/resolved.ts +53 -0
- package/src/spec/state.ts +193 -0
- package/src/spec/stream.ts +230 -0
- package/src/spec/tools.ts +17 -0
- package/src/spec/tree.ts +37 -0
- package/src/spec/types.ts +51 -0
- package/src/spec/validate.ts +429 -0
- package/src/spec/vue/SpecRenderer.tsx +544 -0
- package/src/spec/vue/__tests__/harness.ts +50 -0
- package/src/spec/vue/useSpecStream.ts +162 -0
- package/src/spec/vue.ts +13 -0
- package/src/spec.ts +55 -0
- package/src/theme.ts +423 -0
- package/src/tools/define.ts +65 -0
- package/src/tools/edits.ts +73 -0
- package/src/tools/registry.ts +44 -0
- package/src/tools/tools.ts +361 -0
- package/src/tools.ts +32 -0
- package/src/version.ts +4 -0
- package/src/vue/Widget.tsx +74 -0
- package/src/vue/sync.ts +36 -0
- package/src/vue/themeStore.ts +157 -0
- package/src/vue/useThemeTokens.ts +71 -0
- package/src/vue/useWidget.ts +117 -0
- package/src/vue.ts +8 -0
- package/src/widget.ts +1080 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type SnapshotSaver<T> = {
|
|
2
|
+
/** Saves `read()` once changes settle, if it differs from the newest entry recorded. */
|
|
3
|
+
schedule(read: () => T): void;
|
|
4
|
+
/** Saves a change that is still waiting now rather than after the delay. */
|
|
5
|
+
flush(): void;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Saves snapshots of a tool call's UI state through `record`, 500 ms after the last change and when flushed, whenever the snapshot differs from the newest entry recorded; `initial` is that entry when saving starts. One record is in flight at a time, so entries land in the order they are sent, and a change made meanwhile is saved once it settles. When the current snapshot cannot be recorded, `record(null)` marks it, so the call starts fresh on its next mount rather than from an older snapshot; a marker that fails is sent again only after a newer snapshot is tried.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createSnapshotSaver<T>(initial: T, record: (snapshot: T | null) => unknown): SnapshotSaver<T>;
|
|
11
|
+
//# sourceMappingURL=snapshotSaver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshotSaver.d.ts","mappings":"AAoCA,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI;IAC7B;IACA,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,IAAI;IAC7B;IACA,KAAK,IAAI,IAAI;CACd;AAED;;;AAGA,wBAAgB,mBAAmB,CAAC,CAAC,EACnC,OAAO,EAAE,CAAC,EACV,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,GAAG,IAAI,KAAK,OAAO,GACtC,aAAa,CAAC,CAAC,CAAC","names":[],"ignoreList":[],"sources":["../../src/assistant-ui/snapshotSaver.ts"],"sourcesContent":[null]}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// src/assistant-ui/snapshotSaver.ts
|
|
2
|
+
const SAVE_DELAY_MS = 500;
|
|
3
|
+
/** The snapshot as JSON only when it is plain JSON throughout, since `JSON.stringify` quietly turns `NaN`, `undefined`, and class instances into other values, which would compare equal to a different snapshot and restore something else. */
|
|
4
|
+
const serialize = (snapshot) => {
|
|
5
|
+
try {
|
|
6
|
+
return JSON.stringify(snapshot, function(key, value) {
|
|
7
|
+
const raw = this[key];
|
|
8
|
+
if (raw === null || typeof raw === "string" || typeof raw === "boolean" || typeof raw === "number" && Number.isFinite(raw)) return value;
|
|
9
|
+
if (typeof raw === "object" && typeof raw.toJSON !== "function") {
|
|
10
|
+
const prototype = Object.getPrototypeOf(raw);
|
|
11
|
+
if (Array.isArray(raw) ? prototype === Array.prototype : prototype === Object.prototype || prototype === null) return value;
|
|
12
|
+
}
|
|
13
|
+
throw new TypeError("Not plain JSON");
|
|
14
|
+
});
|
|
15
|
+
} catch {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Saves snapshots of a tool call's UI state through `record`, 500 ms after the last change and when flushed, whenever the snapshot differs from the newest entry recorded; `initial` is that entry when saving starts. One record is in flight at a time, so entries land in the order they are sent, and a change made meanwhile is saved once it settles. When the current snapshot cannot be recorded, `record(null)` marks it, so the call starts fresh on its next mount rather than from an older snapshot; a marker that fails is sent again only after a newer snapshot is tried.
|
|
21
|
+
*/
|
|
22
|
+
function createSnapshotSaver(initial, record) {
|
|
23
|
+
let recorded = JSON.stringify(initial);
|
|
24
|
+
let failed;
|
|
25
|
+
let markerFailed = false;
|
|
26
|
+
let busy = false;
|
|
27
|
+
let timer;
|
|
28
|
+
let read;
|
|
29
|
+
const send = (snapshot, json, marker) => {
|
|
30
|
+
busy = true;
|
|
31
|
+
let result;
|
|
32
|
+
try {
|
|
33
|
+
result = Promise.resolve(record(snapshot));
|
|
34
|
+
} catch (error) {
|
|
35
|
+
result = Promise.reject(error);
|
|
36
|
+
}
|
|
37
|
+
result.then(() => {
|
|
38
|
+
recorded = json;
|
|
39
|
+
if (!marker) failed = void 0;
|
|
40
|
+
}, () => {
|
|
41
|
+
if (marker) markerFailed = true;
|
|
42
|
+
else failed = json;
|
|
43
|
+
}).finally(() => {
|
|
44
|
+
busy = false;
|
|
45
|
+
if (timer === void 0) save();
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
const save = () => {
|
|
49
|
+
if (busy || !read) return;
|
|
50
|
+
let snapshot;
|
|
51
|
+
let json;
|
|
52
|
+
try {
|
|
53
|
+
snapshot = read();
|
|
54
|
+
json = serialize(snapshot);
|
|
55
|
+
} catch {}
|
|
56
|
+
if (json === recorded) return;
|
|
57
|
+
if (json !== void 0 && json !== failed) {
|
|
58
|
+
markerFailed = false;
|
|
59
|
+
send(snapshot, json, false);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (recorded !== "null" && !markerFailed) send(null, "null", true);
|
|
63
|
+
};
|
|
64
|
+
return {
|
|
65
|
+
schedule(next) {
|
|
66
|
+
read = next;
|
|
67
|
+
clearTimeout(timer);
|
|
68
|
+
timer = setTimeout(() => {
|
|
69
|
+
timer = void 0;
|
|
70
|
+
save();
|
|
71
|
+
}, SAVE_DELAY_MS);
|
|
72
|
+
},
|
|
73
|
+
flush() {
|
|
74
|
+
if (timer === void 0) return;
|
|
75
|
+
clearTimeout(timer);
|
|
76
|
+
timer = void 0;
|
|
77
|
+
save();
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
export { createSnapshotSaver };
|
|
82
|
+
|
|
83
|
+
//# sourceMappingURL=snapshotSaver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshotSaver.js","names":[],"sources":["../../src/assistant-ui/snapshotSaver.ts"],"sourcesContent":["const SAVE_DELAY_MS = 500;\n\n/** The snapshot as JSON only when it is plain JSON throughout, since `JSON.stringify` quietly turns `NaN`, `undefined`, and class instances into other values, which would compare equal to a different snapshot and restore something else. */\nconst serialize = (snapshot: unknown): string | undefined => {\n try {\n return JSON.stringify(\n snapshot,\n function (this: Record<string, unknown>, key: string, value: unknown) {\n const raw = this[key];\n if (\n raw === null ||\n typeof raw === \"string\" ||\n typeof raw === \"boolean\" ||\n (typeof raw === \"number\" && Number.isFinite(raw))\n )\n return value;\n if (\n typeof raw === \"object\" &&\n typeof (raw as { toJSON?: unknown }).toJSON !== \"function\"\n ) {\n const prototype = Object.getPrototypeOf(raw);\n if (\n Array.isArray(raw)\n ? prototype === Array.prototype\n : prototype === Object.prototype || prototype === null\n )\n return value;\n }\n throw new TypeError(\"Not plain JSON\");\n },\n );\n } catch {\n return undefined;\n }\n};\n\nexport type SnapshotSaver<T> = {\n /** Saves `read()` once changes settle, if it differs from the newest entry recorded. */\n schedule(read: () => T): void;\n /** Saves a change that is still waiting now rather than after the delay. */\n flush(): void;\n};\n\n/**\n * Saves snapshots of a tool call's UI state through `record`, 500 ms after the last change and when flushed, whenever the snapshot differs from the newest entry recorded; `initial` is that entry when saving starts. One record is in flight at a time, so entries land in the order they are sent, and a change made meanwhile is saved once it settles. When the current snapshot cannot be recorded, `record(null)` marks it, so the call starts fresh on its next mount rather than from an older snapshot; a marker that fails is sent again only after a newer snapshot is tried.\n */\nexport function createSnapshotSaver<T>(\n initial: T,\n record: (snapshot: T | null) => unknown,\n): SnapshotSaver<T> {\n let recorded = JSON.stringify(initial);\n let failed: string | undefined;\n let markerFailed = false;\n let busy = false;\n let timer: ReturnType<typeof setTimeout> | undefined;\n let read: (() => T) | undefined;\n\n const send = (snapshot: T | null, json: string, marker: boolean) => {\n busy = true;\n let result: Promise<unknown>;\n try {\n result = Promise.resolve(record(snapshot));\n } catch (error) {\n result = Promise.reject(error);\n }\n void result\n .then(\n () => {\n recorded = json;\n if (!marker) failed = undefined;\n },\n () => {\n if (marker) markerFailed = true;\n else failed = json;\n },\n )\n .finally(() => {\n busy = false;\n if (timer === undefined) save();\n });\n };\n\n const save = () => {\n if (busy || !read) return;\n let snapshot: T | undefined;\n let json: string | undefined;\n try {\n snapshot = read();\n json = serialize(snapshot);\n } catch {}\n if (json === recorded) return;\n if (json !== undefined && json !== failed) {\n markerFailed = false;\n send(snapshot as T, json, false);\n return;\n }\n if (recorded !== \"null\" && !markerFailed) send(null, \"null\", true);\n };\n\n return {\n schedule(next) {\n read = next;\n clearTimeout(timer);\n timer = setTimeout(() => {\n timer = undefined;\n save();\n }, SAVE_DELAY_MS);\n },\n flush() {\n if (timer === undefined) return;\n clearTimeout(timer);\n timer = undefined;\n save();\n },\n };\n}\n"],"mappings":";AAAA,MAAM,gBAAgB;;AAGtB,MAAM,aAAa,aAA0C;CAC3D,IAAI;EACF,OAAO,KAAK,UACV,UACA,SAAyC,KAAa,OAAgB;GACpE,MAAM,MAAM,KAAK;GACjB,IACE,QAAQ,QACR,OAAO,QAAQ,YACf,OAAO,QAAQ,aACd,OAAO,QAAQ,YAAY,OAAO,SAAS,GAAG,GAE/C,OAAO;GACT,IACE,OAAO,QAAQ,YACf,OAAQ,IAA6B,WAAW,YAChD;IACA,MAAM,YAAY,OAAO,eAAe,GAAG;IAC3C,IACE,MAAM,QAAQ,GAAG,IACb,cAAc,MAAM,YACpB,cAAc,OAAO,aAAa,cAAc,MAEpD,OAAO;GACX;GACA,MAAM,IAAI,UAAU,gBAAgB;EACtC,CACF;CACF,QAAQ;EACN;CACF;AACF;;;;AAYA,SAAgB,oBACd,SACA,QACkB;CAClB,IAAI,WAAW,KAAK,UAAU,OAAO;CACrC,IAAI;CACJ,IAAI,eAAe;CACnB,IAAI,OAAO;CACX,IAAI;CACJ,IAAI;CAEJ,MAAM,QAAQ,UAAoB,MAAc,WAAoB;EAClE,OAAO;EACP,IAAI;EACJ,IAAI;GACF,SAAS,QAAQ,QAAQ,OAAO,QAAQ,CAAC;EAC3C,SAAS,OAAO;GACd,SAAS,QAAQ,OAAO,KAAK;EAC/B;EACA,OACG,WACO;GACJ,WAAW;GACX,IAAI,CAAC,QAAQ,SAAS,KAAA;EACxB,SACM;GACJ,IAAI,QAAQ,eAAe;QACtB,SAAS;EAChB,CACF,CAAC,CACA,cAAc;GACb,OAAO;GACP,IAAI,UAAU,KAAA,GAAW,KAAK;EAChC,CAAC;CACL;CAEA,MAAM,aAAa;EACjB,IAAI,QAAQ,CAAC,MAAM;EACnB,IAAI;EACJ,IAAI;EACJ,IAAI;GACF,WAAW,KAAK;GAChB,OAAO,UAAU,QAAQ;EAC3B,QAAQ,CAAC;EACT,IAAI,SAAS,UAAU;EACvB,IAAI,SAAS,KAAA,KAAa,SAAS,QAAQ;GACzC,eAAe;GACf,KAAK,UAAe,MAAM,KAAK;GAC/B;EACF;EACA,IAAI,aAAa,UAAU,CAAC,cAAc,KAAK,MAAM,QAAQ,IAAI;CACnE;CAEA,OAAO;EACL,SAAS,MAAM;GACb,OAAO;GACP,aAAa,KAAK;GAClB,QAAQ,iBAAiB;IACvB,QAAQ,KAAA;IACR,KAAK;GACP,GAAG,aAAa;EAClB;EACA,QAAQ;GACN,IAAI,UAAU,KAAA,GAAW;GACzB,aAAa,KAAK;GAClB,QAAQ,KAAA;GACR,KAAK;EACP;CACF;AACF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** The part of a thread message the history readers need. */
|
|
2
|
+
export type MessageLike = {
|
|
3
|
+
readonly content: string | readonly unknown[];
|
|
4
|
+
readonly status?: {
|
|
5
|
+
readonly type: string;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
/** A tool call as the history readers see it. */
|
|
9
|
+
export type ToolCall = {
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
args: Record<string, unknown>;
|
|
13
|
+
argsText: string | undefined;
|
|
14
|
+
result: unknown;
|
|
15
|
+
/** Whether the arguments can no longer change, read as core reads a tool call's status: it has a final result, or its message is no longer running. */
|
|
16
|
+
settled: boolean;
|
|
17
|
+
};
|
|
18
|
+
export declare function toolCalls(messages: readonly MessageLike[]): Generator<ToolCall>;
|
|
19
|
+
/** Whether a later call in the same message, with this call's whole title, takes over what this call shows, as `takesOver` decides. A call in a later message never does, since earlier messages are the conversation's history. */
|
|
20
|
+
export declare function hasLaterToolCallInMessage(messages: readonly MessageLike[], toolCallId: string, title: string, takesOver: (call: ToolCall) => boolean): boolean;
|
|
21
|
+
//# sourceMappingURL=tool-calls.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-calls.d.ts","mappings":"AAUA;AACA,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,OAAO,EAAE;IAC7C,QAAQ,CAAC,MAAM,CAAC,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM;KAAE;CAC5C;AAED;AACA,MAAM,MAAM,QAAQ,GAAG;IACrB,EAAE,EAAE,MAAM;IACV,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC7B,QAAQ,EAAE,MAAM,GAAG,SAAS;IAC5B,MAAM,EAAE,OAAO;IACf;IACA,OAAO,EAAE,OAAO;CACjB;AAED,wBAAiB,SAAS,CACxB,QAAQ,EAAE,SAAS,WAAW,EAAE,GAC/B,SAAS,CAAC,QAAQ,CAAC;AA8DtB;AACA,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,SAAS,WAAW,EAAE,EAChC,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,OAAO,GACrC,OAAO","names":[],"ignoreList":[],"sources":["../../src/assistant-ui/tool-calls.ts"],"sourcesContent":[null]}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// src/assistant-ui/tool-calls.ts
|
|
2
|
+
function* toolCalls(messages) {
|
|
3
|
+
for (const message of messages) {
|
|
4
|
+
if (typeof message.content === "string") continue;
|
|
5
|
+
const running = message.status?.type === "running";
|
|
6
|
+
for (const part of message.content) {
|
|
7
|
+
const call = part;
|
|
8
|
+
if (call?.type === "tool-call" && call.toolCallId && call.toolName) yield {
|
|
9
|
+
id: call.toolCallId,
|
|
10
|
+
name: call.toolName,
|
|
11
|
+
args: call.args ?? {},
|
|
12
|
+
argsText: typeof call.argsText === "string" ? call.argsText : void 0,
|
|
13
|
+
result: call.result,
|
|
14
|
+
settled: call.result !== void 0 && call.isPreliminary !== true || !running
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const STRING_TOKEN = /"(?:[^"\\]|\\.)*"/y;
|
|
20
|
+
const decode = (token) => {
|
|
21
|
+
try {
|
|
22
|
+
return JSON.parse(token);
|
|
23
|
+
} catch {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
/** The top-level `title` of streamed arguments once its string has closed, whatever escaping it was written with. */
|
|
28
|
+
const streamedTitle = (argsText) => {
|
|
29
|
+
let depth = 0;
|
|
30
|
+
let key;
|
|
31
|
+
let inValue = false;
|
|
32
|
+
for (let i = 0; i < argsText.length; i++) {
|
|
33
|
+
const char = argsText[i];
|
|
34
|
+
if (char === "\"") {
|
|
35
|
+
STRING_TOKEN.lastIndex = i;
|
|
36
|
+
const token = STRING_TOKEN.exec(argsText)?.[0];
|
|
37
|
+
if (token === void 0) return void 0;
|
|
38
|
+
if (depth === 1) {
|
|
39
|
+
if (!inValue) key = decode(token);
|
|
40
|
+
else if (key === "title") return decode(token);
|
|
41
|
+
else inValue = false;
|
|
42
|
+
}
|
|
43
|
+
i += token.length - 1;
|
|
44
|
+
} else if (char === "{" || char === "[") depth++;
|
|
45
|
+
else if (char === "}" || char === "]") depth--;
|
|
46
|
+
else if (depth === 1 && char === ":") inValue = true;
|
|
47
|
+
else if (depth === 1 && char === ",") inValue = false;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
/** Whether streamed arguments hold this whole title, not a prefix of a longer one that is still arriving. */
|
|
51
|
+
const holdsTitle = (argsText, title) => argsText === void 0 || streamedTitle(argsText) === title;
|
|
52
|
+
/** Whether a later call in the same message, with this call's whole title, takes over what this call shows, as `takesOver` decides. A call in a later message never does, since earlier messages are the conversation's history. */
|
|
53
|
+
function hasLaterToolCallInMessage(messages, toolCallId, title, takesOver) {
|
|
54
|
+
if (!title) return false;
|
|
55
|
+
for (const message of messages) {
|
|
56
|
+
let seen = false;
|
|
57
|
+
for (const call of toolCalls([message])) if (call.id === toolCallId) seen = true;
|
|
58
|
+
else if (seen && call.args["title"] === title && holdsTitle(call.argsText, title) && takesOver(call)) return true;
|
|
59
|
+
if (seen) return false;
|
|
60
|
+
}
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
export { hasLaterToolCallInMessage, toolCalls };
|
|
64
|
+
|
|
65
|
+
//# sourceMappingURL=tool-calls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-calls.js","names":[],"sources":["../../src/assistant-ui/tool-calls.ts"],"sourcesContent":["type ToolCallLike = {\n type: string;\n toolName?: string;\n toolCallId?: string;\n args?: unknown;\n argsText?: unknown;\n result?: unknown;\n isPreliminary?: unknown;\n};\n\n/** The part of a thread message the history readers need. */\nexport type MessageLike = {\n readonly content: string | readonly unknown[];\n readonly status?: { readonly type: string };\n};\n\n/** A tool call as the history readers see it. */\nexport type ToolCall = {\n id: string;\n name: string;\n args: Record<string, unknown>;\n argsText: string | undefined;\n result: unknown;\n /** Whether the arguments can no longer change, read as core reads a tool call's status: it has a final result, or its message is no longer running. */\n settled: boolean;\n};\n\nexport function* toolCalls(\n messages: readonly MessageLike[],\n): Generator<ToolCall> {\n for (const message of messages) {\n if (typeof message.content === \"string\") continue;\n const running = message.status?.type === \"running\";\n for (const part of message.content) {\n const call = part as ToolCallLike;\n if (call?.type === \"tool-call\" && call.toolCallId && call.toolName) {\n yield {\n id: call.toolCallId,\n name: call.toolName,\n args: (call.args ?? {}) as Record<string, unknown>,\n argsText:\n typeof call.argsText === \"string\" ? call.argsText : undefined,\n result: call.result,\n settled:\n (call.result !== undefined && call.isPreliminary !== true) ||\n !running,\n };\n }\n }\n }\n}\n\nconst STRING_TOKEN = /\"(?:[^\"\\\\]|\\\\.)*\"/y;\n\nconst decode = (token: string): unknown => {\n try {\n return JSON.parse(token);\n } catch {\n return undefined;\n }\n};\n\n/** The top-level `title` of streamed arguments once its string has closed, whatever escaping it was written with. */\nconst streamedTitle = (argsText: string): unknown => {\n let depth = 0;\n let key: unknown;\n let inValue = false;\n for (let i = 0; i < argsText.length; i++) {\n const char = argsText[i];\n if (char === '\"') {\n STRING_TOKEN.lastIndex = i;\n const token = STRING_TOKEN.exec(argsText)?.[0];\n if (token === undefined) return undefined;\n if (depth === 1) {\n if (!inValue) key = decode(token);\n else if (key === \"title\") return decode(token);\n else inValue = false;\n }\n i += token.length - 1;\n } else if (char === \"{\" || char === \"[\") depth++;\n else if (char === \"}\" || char === \"]\") depth--;\n else if (depth === 1 && char === \":\") inValue = true;\n else if (depth === 1 && char === \",\") inValue = false;\n }\n return undefined;\n};\n\n/** Whether streamed arguments hold this whole title, not a prefix of a longer one that is still arriving. */\nconst holdsTitle = (argsText: string | undefined, title: string) =>\n argsText === undefined || streamedTitle(argsText) === title;\n\n/** Whether a later call in the same message, with this call's whole title, takes over what this call shows, as `takesOver` decides. A call in a later message never does, since earlier messages are the conversation's history. */\nexport function hasLaterToolCallInMessage(\n messages: readonly MessageLike[],\n toolCallId: string,\n title: string,\n takesOver: (call: ToolCall) => boolean,\n): boolean {\n if (!title) return false;\n for (const message of messages) {\n let seen = false;\n for (const call of toolCalls([message])) {\n if (call.id === toolCallId) seen = true;\n else if (\n seen &&\n call.args[\"title\"] === title &&\n holdsTitle(call.argsText, title) &&\n takesOver(call)\n )\n return true;\n }\n if (seen) return false;\n }\n return false;\n}\n"],"mappings":";AA2BA,UAAiB,UACf,UACqB;CACrB,KAAK,MAAM,WAAW,UAAU;EAC9B,IAAI,OAAO,QAAQ,YAAY,UAAU;EACzC,MAAM,UAAU,QAAQ,QAAQ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AW,UAAU;EAC9B,IAAI,OAAO;EACX,KAAK,MAAM,QAAQ,UAAU,CAAC,OAAO,CAAC,GACpC,IAAI,KAAK,OAAO,YAAY,OAAO;OAC9B,IACH,QACA,KAAK,KAAK,aAAa,SACvB,WAAW,KAAK,UAAU,KAAK,KAC/B,UAAU,IAAI,GAEd,OAAO;EAEX,IAAI,MAAM,OAAO;CACnB;CACA,OAAO;AACT"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { type Toolkit } from "@ulearning/ai-sdk";
|
|
2
|
+
import { type MaybeRefOrGetter } from "vue";
|
|
3
|
+
import type { ConsoleEntry, WidgetError } from "../protocol.js";
|
|
4
|
+
import { type UseWidgetOptions } from "../vue/useWidget.js";
|
|
5
|
+
import type { ThemeTokenSources } from "../theme.js";
|
|
6
|
+
import { type WidgetRegistry } from "../tools/registry.js";
|
|
7
|
+
import { type CreateWidgetToolsOptions, type WidgetInstructionsOptions, type WidgetTools } from "../tools/tools.js";
|
|
8
|
+
import type { AnyTool } from "../tools/define.js";
|
|
9
|
+
import type { ToolkitDisplay, WidgetToolkitExtension } from "./extension.js";
|
|
10
|
+
/**
|
|
11
|
+
* Where theme tokens come from in an assistant-ui app: shadcn/ui variables
|
|
12
|
+
* first, because Tailwind v4 aliases `--color-accent` to shadcn's muted
|
|
13
|
+
* `--accent` rather than the primary color.
|
|
14
|
+
*/
|
|
15
|
+
export declare const ASSISTANT_UI_TOKEN_SOURCES: ThemeTokenSources;
|
|
16
|
+
/** The app's assistant-ui (shadcn/ui) theme as widget tokens, kept in sync. */
|
|
17
|
+
export declare function useAssistantUiThemeTokens(element?: Element | null): Readonly<import("vue").ShallowRef<import("../index.js").ThemeTokens>>;
|
|
18
|
+
export type WidgetToolkitOptions = Omit<CreateWidgetToolsOptions, "registry"> & {
|
|
19
|
+
registry?: WidgetRegistry;
|
|
20
|
+
/**
|
|
21
|
+
* `frontend` (default): the tools execute in the browser and the server
|
|
22
|
+
* forwards their schemas (`frontendTools` from `@ulearning/ai-sdk-adapter`).
|
|
23
|
+
* `backend`: the server executes `createWidgetTools()` and the toolkit
|
|
24
|
+
* only renders.
|
|
25
|
+
*/
|
|
26
|
+
execution?: "frontend" | "backend";
|
|
27
|
+
/** Options for every widget frame (csp, product, maxHeight, handlers, …). */
|
|
28
|
+
widget?: Omit<UseWidgetOptions, "tokens" | "initialState">;
|
|
29
|
+
/** Spec mode: `createSpecToolkit(catalog, { components })` from `generative-frame/spec/assistant-ui`. */
|
|
30
|
+
spec?: WidgetToolkitExtension;
|
|
31
|
+
/** More tools for the model, such as data lookups. They execute like the widget tools and render nothing in the thread. */
|
|
32
|
+
extraTools?: Record<string, AnyTool>;
|
|
33
|
+
/** Where the theme is read from. Defaults to the document root. */
|
|
34
|
+
themeElement?: Element | null;
|
|
35
|
+
/** How the widget tools are presented relative to the reasoning trace. Defaults to `standalone`. */
|
|
36
|
+
display?: ToolkitDisplay;
|
|
37
|
+
/**
|
|
38
|
+
* With frontend execution, `show_widget` and `edit_widget` wait for the
|
|
39
|
+
* frame to finish rendering and return its errors as `render`. `false`
|
|
40
|
+
* returns as soon as the code is stored.
|
|
41
|
+
*/
|
|
42
|
+
renderReport?: RenderReportOptions | false;
|
|
43
|
+
/** Keep the PNG in `preview_widget` results. Defaults to false. */
|
|
44
|
+
previewScreenshot?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* The storage id of a widget's frame, from the thread's persisted id and
|
|
47
|
+
* the `toolCallId` of the `show_widget` call that created it, so a widget
|
|
48
|
+
* keeps its localStorage across reloads and edits. Defaults to
|
|
49
|
+
* `<remoteId>:<toolCallId>`, or `aui:<toolCallId>` while the thread has no
|
|
50
|
+
* remote id; `false` gives every frame a fresh origin. Derive it from host
|
|
51
|
+
* data only, never from tool arguments the model wrote.
|
|
52
|
+
*/
|
|
53
|
+
widgetId?: false | ((call: {
|
|
54
|
+
toolCallId: string;
|
|
55
|
+
threadId: string | undefined;
|
|
56
|
+
}) => string);
|
|
57
|
+
};
|
|
58
|
+
export type RenderReportOptions = {
|
|
59
|
+
/** How long a tool result waits for the frame. Defaults to 10000 ms. */
|
|
60
|
+
timeoutMs?: number;
|
|
61
|
+
/** Wait after the code ends so late script errors are caught. Defaults to 300 ms. */
|
|
62
|
+
settleMs?: number;
|
|
63
|
+
};
|
|
64
|
+
/** How a widget rendered in the thread, attached to tool results as `render`. */
|
|
65
|
+
export type WidgetRenderReport = {
|
|
66
|
+
status: "rendered";
|
|
67
|
+
ok: boolean;
|
|
68
|
+
blank: boolean;
|
|
69
|
+
height: number;
|
|
70
|
+
errors: WidgetError[];
|
|
71
|
+
/** Console warnings and errors, most recent last. */
|
|
72
|
+
console: ConsoleEntry[];
|
|
73
|
+
feedback: string;
|
|
74
|
+
} | {
|
|
75
|
+
status: "timeout";
|
|
76
|
+
feedback: string;
|
|
77
|
+
};
|
|
78
|
+
export type WidgetToolkit = {
|
|
79
|
+
/** Pass to `Tools({ toolkit })`, or spread into your own toolkit. */
|
|
80
|
+
toolkit: Toolkit;
|
|
81
|
+
/** The tool definitions behind the toolkit, for instructions or the server. */
|
|
82
|
+
tools: WidgetTools & Record<string, AnyTool>;
|
|
83
|
+
/** Latest code per widget title. */
|
|
84
|
+
registry: WidgetRegistry;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Renders `show_widget`, `edit_widget`, and `render_spec` tool calls in an
|
|
88
|
+
* assistant-ui thread: widget code streams into a frame from the partial
|
|
89
|
+
* tool arguments, `sendPrompt` adds its text to the thread composer, and the
|
|
90
|
+
* frame follows the app's theme. With `execution: "frontend"` the tools run
|
|
91
|
+
* in the browser too, so the server only forwards their schemas.
|
|
92
|
+
*/
|
|
93
|
+
export declare function createWidgetToolkit(options?: WidgetToolkitOptions): WidgetToolkit;
|
|
94
|
+
/** Adds the widget guidance to the model while this Vue scope is active. */
|
|
95
|
+
export declare function useWidgetInstructions(tools: MaybeRefOrGetter<WidgetTools & Record<string, AnyTool>>, options?: MaybeRefOrGetter<WidgetInstructionsOptions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