@popcraft/cli 0.41.0 → 0.42.1
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/popcraft.mjs +1746 -854
- package/package.json +2 -2
package/dist/popcraft.mjs
CHANGED
|
@@ -1196,7 +1196,7 @@ function operations(spec = openapi) {
|
|
|
1196
1196
|
}
|
|
1197
1197
|
async function call(target2, method, path, opts = {}) {
|
|
1198
1198
|
const qs = new URLSearchParams(opts.query ?? {}).toString();
|
|
1199
|
-
const headers = { "user-agent": `popcraft-cli/${"0.
|
|
1199
|
+
const headers = { "user-agent": `popcraft-cli/${"0.42.1"}`, ...opts.headers };
|
|
1200
1200
|
if (target2.token) headers.authorization = `Bearer ${target2.token}`;
|
|
1201
1201
|
if (opts.contentType) headers["content-type"] = opts.contentType;
|
|
1202
1202
|
try {
|
|
@@ -1532,7 +1532,8 @@ __export(registry_exports, {
|
|
|
1532
1532
|
isNeverReachable: () => isNeverReachable,
|
|
1533
1533
|
listCommands: () => listCommands,
|
|
1534
1534
|
listCommandsForSurface: () => listCommandsForSurface,
|
|
1535
|
-
registerCommand: () => registerCommand
|
|
1535
|
+
registerCommand: () => registerCommand,
|
|
1536
|
+
unregisterCommand: () => unregisterCommand
|
|
1536
1537
|
});
|
|
1537
1538
|
function unindex(existing) {
|
|
1538
1539
|
if (existing.expose.agent) byAgentName.delete(existing.expose.agent.name);
|
|
@@ -1562,6 +1563,14 @@ function registerCommand(...commands2) {
|
|
|
1562
1563
|
if (method) byPluginMethod.set(method, command);
|
|
1563
1564
|
}
|
|
1564
1565
|
}
|
|
1566
|
+
function unregisterCommand(...ids2) {
|
|
1567
|
+
for (const id3 of ids2) {
|
|
1568
|
+
const existing = byId.get(id3);
|
|
1569
|
+
if (!existing) continue;
|
|
1570
|
+
unindex(existing);
|
|
1571
|
+
byId.delete(id3);
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1565
1574
|
function getCommand(id3) {
|
|
1566
1575
|
return byId.get(id3);
|
|
1567
1576
|
}
|
|
@@ -4770,15 +4779,15 @@ function formatCounter(c2, v) {
|
|
|
4770
4779
|
const fixed = (Number.isFinite(v) ? steppedCounterValue(c2, v) : 0).toFixed(decimals);
|
|
4771
4780
|
const negative = fixed.startsWith("-") && /[1-9]/.test(fixed);
|
|
4772
4781
|
const [int3, frac2] = fixed.replace("-", "").split(".");
|
|
4773
|
-
let
|
|
4782
|
+
let grouped3 = int3;
|
|
4774
4783
|
if (sep2) {
|
|
4775
|
-
|
|
4784
|
+
grouped3 = "";
|
|
4776
4785
|
for (let i2 = 0; i2 < int3.length; i2++) {
|
|
4777
|
-
if (i2 && (int3.length - i2) % 3 === 0)
|
|
4778
|
-
|
|
4786
|
+
if (i2 && (int3.length - i2) % 3 === 0) grouped3 += sep2;
|
|
4787
|
+
grouped3 += int3[i2];
|
|
4779
4788
|
}
|
|
4780
4789
|
}
|
|
4781
|
-
return `${c2.prefix ?? ""}${negative ? "-" : ""}${
|
|
4790
|
+
return `${c2.prefix ?? ""}${negative ? "-" : ""}${grouped3}${frac2 ? `.${frac2}` : ""}${c2.suffix ?? ""}`;
|
|
4782
4791
|
}
|
|
4783
4792
|
function counterFromText(chars) {
|
|
4784
4793
|
const m = /^(\D*?)(-?\d[\d,]*(?:\.\d+)?)(\D*)$/.exec(chars.trim());
|
|
@@ -11362,9 +11371,9 @@ function partPattern(schema) {
|
|
|
11362
11371
|
return own2;
|
|
11363
11372
|
}
|
|
11364
11373
|
if (def.options) {
|
|
11365
|
-
const
|
|
11366
|
-
if (
|
|
11367
|
-
return `^(${
|
|
11374
|
+
const sources3 = def.options.map(partPattern);
|
|
11375
|
+
if (sources3.every(Boolean))
|
|
11376
|
+
return `^(${sources3.map((s) => cleanRegex(s)).join("|")})$`;
|
|
11368
11377
|
}
|
|
11369
11378
|
return leafPattern(schema);
|
|
11370
11379
|
}
|
|
@@ -24183,8 +24192,8 @@ var init_api2 = __esm({
|
|
|
24183
24192
|
});
|
|
24184
24193
|
|
|
24185
24194
|
// node_modules/.pnpm/zod@4.6.5/node_modules/zod/v4/core/to-json-schema.js
|
|
24186
|
-
function assignProps(target2, ...
|
|
24187
|
-
for (const source3 of
|
|
24195
|
+
function assignProps(target2, ...sources3) {
|
|
24196
|
+
for (const source3 of sources3) {
|
|
24188
24197
|
for (const key5 of Reflect.ownKeys(source3)) {
|
|
24189
24198
|
if (Object.prototype.propertyIsEnumerable.call(source3, key5)) {
|
|
24190
24199
|
assignProp(target2, key5, source3[key5]);
|
|
@@ -34410,7 +34419,9 @@ var init_en2 = __esm({
|
|
|
34410
34419
|
"mentionInput.addReaction": "Add reaction",
|
|
34411
34420
|
"mentionInput.someone": "Someone",
|
|
34412
34421
|
"mentionMenu.removeMention": "Remove mention",
|
|
34422
|
+
"messageParts.fromPlugin": "From the {plugin} plugin",
|
|
34413
34423
|
"messageParts.plan": "Plan",
|
|
34424
|
+
"messageParts.pluginTool": "{plugin} \xB7 {tool}",
|
|
34414
34425
|
"messageParts.renderedView": "Rendered view",
|
|
34415
34426
|
"messageParts.thinking": "Thinking",
|
|
34416
34427
|
"minimap.minimapTapOrDragTo": "Minimap \u2014 tap or drag to move the view, double-tap to fit the page",
|
|
@@ -35085,6 +35096,8 @@ var init_en2 = __esm({
|
|
|
35085
35096
|
"pluginImport.noImporterIsInstalledFor": "No importer is installed for \u201C{name}\u201D",
|
|
35086
35097
|
"pluginImport.openAFileToImport": "Open a file to import into",
|
|
35087
35098
|
"pluginImport.producedNoLayers": "\u201C{name}\u201D produced no layers",
|
|
35099
|
+
"pluginOverlays.addAgentTools": "Give the AI agent {count, plural, one {# tool} other {# tools}} that run this plugin",
|
|
35100
|
+
"pluginOverlays.addsAgentTools": "Adds {count, plural, one {# agent tool} other {# agent tools}}",
|
|
35088
35101
|
"pluginOverlays.addsExport": "Adds File \u203A Export \u203A {label}",
|
|
35089
35102
|
"pluginOverlays.allowAndRun": "Allow and run",
|
|
35090
35103
|
"pluginOverlays.allowTo": "Allow \u201C{name}\u201D to:",
|
|
@@ -94349,7 +94362,6 @@ function hasMessage(key5) {
|
|
|
94349
94362
|
var current2, loading, listeners, formats, asts;
|
|
94350
94363
|
var init_runtime = __esm({
|
|
94351
94364
|
"lib/i18n/runtime.ts"() {
|
|
94352
|
-
"use strict";
|
|
94353
94365
|
init_intl_messageformat();
|
|
94354
94366
|
init_icu_messageformat_parser();
|
|
94355
94367
|
init_catalogs();
|
|
@@ -96309,6 +96321,7 @@ async function sha256Prefix(bytes2) {
|
|
|
96309
96321
|
}
|
|
96310
96322
|
var init_media_hash = __esm({
|
|
96311
96323
|
"lib/storage/media-hash.ts"() {
|
|
96324
|
+
"use strict";
|
|
96312
96325
|
}
|
|
96313
96326
|
});
|
|
96314
96327
|
|
|
@@ -96691,6 +96704,7 @@ function releaseMediaMemory(hash3) {
|
|
|
96691
96704
|
var key2, peaksKey, objectUrls, sourceKey, remoteResolver, MEDIA_FETCH_TIMEOUT_MS, SHIPPED_MEDIA_PATH, notShipped, MEDIA_SCHEME, isImageDataUrl, memory, pendingLoads, sourceAliases, PAINT_KEYS, URL_KEYS;
|
|
96692
96705
|
var init_media_store = __esm({
|
|
96693
96706
|
"lib/storage/media-store.ts"() {
|
|
96707
|
+
"use strict";
|
|
96694
96708
|
init_media_types();
|
|
96695
96709
|
init_idb();
|
|
96696
96710
|
init_media_hash();
|
|
@@ -98852,10 +98866,10 @@ function interpolate(a, b, t3) {
|
|
|
98852
98866
|
return out;
|
|
98853
98867
|
}
|
|
98854
98868
|
function staggeredProgress(s, i2, n) {
|
|
98855
|
-
const
|
|
98856
|
-
const span3 = s.duration -
|
|
98869
|
+
const delay3 = Math.max(0, Math.min(s.delay, n > 1 ? s.duration / n : s.delay));
|
|
98870
|
+
const span3 = s.duration - delay3 * Math.max(0, n - 1);
|
|
98857
98871
|
if (span3 <= 0) return s.ease(s.raw >= 1 ? 1 : 0);
|
|
98858
|
-
return s.ease(Math.min(1, Math.max(0, (s.raw * s.duration - i2 *
|
|
98872
|
+
return s.ease(Math.min(1, Math.max(0, (s.raw * s.duration - i2 * delay3) / span3)));
|
|
98859
98873
|
}
|
|
98860
98874
|
function sharedUnder(nodes, rootId) {
|
|
98861
98875
|
const out = /* @__PURE__ */ new Map();
|
|
@@ -247849,6 +247863,7 @@ function resyncText(doc2, ids2) {
|
|
|
247849
247863
|
var isVirtualId;
|
|
247850
247864
|
var init_invariants2 = __esm({
|
|
247851
247865
|
"lib/document/invariants.ts"() {
|
|
247866
|
+
"use strict";
|
|
247852
247867
|
init_auto_layout();
|
|
247853
247868
|
init_scene_graph();
|
|
247854
247869
|
init_text_bounds();
|
|
@@ -252284,6 +252299,7 @@ function resizeWindow(doc2, target2, rect) {
|
|
|
252284
252299
|
}
|
|
252285
252300
|
var init_crop = __esm({
|
|
252286
252301
|
"lib/editor/crop.ts"() {
|
|
252302
|
+
"use strict";
|
|
252287
252303
|
init_dist_node();
|
|
252288
252304
|
init_scene_graph();
|
|
252289
252305
|
init_photo_frames();
|
|
@@ -256772,6 +256788,7 @@ function followPeers(peers) {
|
|
|
256772
256788
|
var PALETTE, usePresence, awareness, CURSOR_SEND_MS, VIEWPORT_SEND_MS, cursorTimer, pendingCursor, sentCursor, EMOTE_MS, lastFollowCamera;
|
|
256773
256789
|
var init_presence = __esm({
|
|
256774
256790
|
"lib/collab/presence.ts"() {
|
|
256791
|
+
"use strict";
|
|
256775
256792
|
init_esm();
|
|
256776
256793
|
init_editor_store();
|
|
256777
256794
|
init_status_announcements();
|
|
@@ -259061,9 +259078,9 @@ function applyPresetToDocument(doc2, ids2, presetId, opts = {}) {
|
|
|
259061
259078
|
const places = opts.stagger && !liveParent ? staggerPlaces(nodes, targets, opts.stagger.order, opts.stagger.seed) : null;
|
|
259062
259079
|
let out = { ...nodes };
|
|
259063
259080
|
if (liveParent && opts.stagger) {
|
|
259064
|
-
const { delay, order: order2 = "index", seed: seed2 } = opts.stagger;
|
|
259081
|
+
const { delay: delay3, order: order2 = "index", seed: seed2 } = opts.stagger;
|
|
259065
259082
|
const parent = out[liveParent];
|
|
259066
|
-
out[liveParent] = { ...parent, motion: { tracks: {}, ...parent.motion, stagger: { delay, order: order2 === "selection" ? { ids: [...targets] } : order2, ...order2 === "random" && seed2 !== void 0 ? { seed: seed2 } : {} } } };
|
|
259083
|
+
out[liveParent] = { ...parent, motion: { tracks: {}, ...parent.motion, stagger: { delay: delay3, order: order2 === "selection" ? { ids: [...targets] } : order2, ...order2 === "random" && seed2 !== void 0 ? { seed: seed2 } : {} } } };
|
|
259067
259084
|
}
|
|
259068
259085
|
for (const id3 of targets) {
|
|
259069
259086
|
const frameId = hosts.get(id3);
|
|
@@ -260200,10 +260217,10 @@ function retargetPath(node2, parent, path) {
|
|
|
260200
260217
|
return propertiesOf(node2, parent).find((p2) => patternOf(p2.path) === pattern)?.path ?? null;
|
|
260201
260218
|
}
|
|
260202
260219
|
function pasteKeys(nodes, frameId, clip, targets, at4) {
|
|
260203
|
-
const
|
|
260204
|
-
for (const tr of clip.tracks) if (!
|
|
260220
|
+
const sources3 = [];
|
|
260221
|
+
for (const tr of clip.tracks) if (!sources3.includes(tr.source)) sources3.push(tr.source);
|
|
260205
260222
|
const onto = targets.filter((id3) => nodes[id3]);
|
|
260206
|
-
const plan2 = !onto.length ?
|
|
260223
|
+
const plan2 = !onto.length ? sources3.filter((id3) => nodes[id3]).map((id3) => [id3, id3]) : sources3.length === 1 ? onto.map((id3) => [sources3[0], id3]) : sources3.slice(0, onto.length).map((s, i2) => [s, onto[i2]]);
|
|
260207
260224
|
const result = { edits: [], keys: [] };
|
|
260208
260225
|
for (const [source3, targetId] of plan2) {
|
|
260209
260226
|
const rest = nodes[targetId];
|
|
@@ -260340,9 +260357,9 @@ function poseAt(doc2, target2, t3) {
|
|
|
260340
260357
|
}
|
|
260341
260358
|
function frameSchedule(stretches, fps, hold) {
|
|
260342
260359
|
const out = [];
|
|
260343
|
-
const
|
|
260360
|
+
const delay3 = Math.round(1e3 / fps);
|
|
260344
260361
|
for (const [from2, to] of stretches) {
|
|
260345
|
-
for (let i2 = 0; frameTime(i2, fps, from2) < to; i2++) out.push({ t: frameTime(i2, fps, from2), delay });
|
|
260362
|
+
for (let i2 = 0; frameTime(i2, fps, from2) < to; i2++) out.push({ t: frameTime(i2, fps, from2), delay: delay3 });
|
|
260346
260363
|
out.push({ t: to, delay: hold });
|
|
260347
260364
|
}
|
|
260348
260365
|
return out;
|
|
@@ -269469,10 +269486,10 @@ var init_yjs = __esm({
|
|
|
269469
269486
|
* @public
|
|
269470
269487
|
*/
|
|
269471
269488
|
toDOM(_document = document, hooks = {}, binding) {
|
|
269472
|
-
const
|
|
269489
|
+
const hook2 = hooks[this.hookName];
|
|
269473
269490
|
let dom;
|
|
269474
|
-
if (
|
|
269475
|
-
dom =
|
|
269491
|
+
if (hook2 !== void 0) {
|
|
269492
|
+
dom = hook2.createDom(this);
|
|
269476
269493
|
} else {
|
|
269477
269494
|
dom = document.createElement(this.hookName);
|
|
269478
269495
|
}
|
|
@@ -272162,11 +272179,11 @@ var init_client = __esm({
|
|
|
272162
272179
|
}
|
|
272163
272180
|
scheduleReconnect(min2 = 0) {
|
|
272164
272181
|
if (this.destroyed || this.reconnectTimer) return;
|
|
272165
|
-
const
|
|
272182
|
+
const delay3 = Math.max(min2, Math.min(3e4, 500 * 2 ** this.attempts++)) * (0.8 + Math.random() * 0.4);
|
|
272166
272183
|
this.reconnectTimer = setTimeout(() => {
|
|
272167
272184
|
this.reconnectTimer = null;
|
|
272168
272185
|
void this.connect();
|
|
272169
|
-
},
|
|
272186
|
+
}, delay3);
|
|
272170
272187
|
}
|
|
272171
272188
|
/**
|
|
272172
272189
|
* Send media to the room now (MSG_MEDIA). Call it BEFORE the document change that references it: the socket keeps
|
|
@@ -273717,7 +273734,7 @@ var require_gifenc = __commonJS({
|
|
|
273717
273734
|
const {
|
|
273718
273735
|
transparent = false,
|
|
273719
273736
|
transparentIndex = 0,
|
|
273720
|
-
delay = 0,
|
|
273737
|
+
delay: delay3 = 0,
|
|
273721
273738
|
palette: palette2 = null,
|
|
273722
273739
|
repeat = 0,
|
|
273723
273740
|
colorDepth = 8,
|
|
@@ -273745,7 +273762,7 @@ var require_gifenc = __commonJS({
|
|
|
273745
273762
|
encodeNetscapeExt(stream, repeat);
|
|
273746
273763
|
}
|
|
273747
273764
|
}
|
|
273748
|
-
const delayTime = Math.round(
|
|
273765
|
+
const delayTime = Math.round(delay3 / 10);
|
|
273749
273766
|
encodeGraphicControlExt(stream, dispose, delayTime, transparent, transparentIndex);
|
|
273750
273767
|
const useLocalColorTable = Boolean(palette2) && !first2;
|
|
273751
273768
|
encodeImageDescriptor(stream, width, height, useLocalColorTable ? palette2 : null);
|
|
@@ -273758,7 +273775,7 @@ var require_gifenc = __commonJS({
|
|
|
273758
273775
|
writeUTFBytes(stream, "GIF89a");
|
|
273759
273776
|
}
|
|
273760
273777
|
}
|
|
273761
|
-
function encodeGraphicControlExt(stream, dispose,
|
|
273778
|
+
function encodeGraphicControlExt(stream, dispose, delay3, transparent, transparentIndex) {
|
|
273762
273779
|
stream.writeByte(33);
|
|
273763
273780
|
stream.writeByte(249);
|
|
273764
273781
|
stream.writeByte(4);
|
|
@@ -273780,7 +273797,7 @@ var require_gifenc = __commonJS({
|
|
|
273780
273797
|
disp <<= 2;
|
|
273781
273798
|
const userInput = 0;
|
|
273782
273799
|
stream.writeByte(0 | disp | userInput | transp);
|
|
273783
|
-
writeUInt16(stream,
|
|
273800
|
+
writeUInt16(stream, delay3);
|
|
273784
273801
|
stream.writeByte(transparentIndex || 0);
|
|
273785
273802
|
stream.writeByte(0);
|
|
273786
273803
|
}
|
|
@@ -273914,7 +273931,7 @@ function createGifEncoder(width, height, opts, shared) {
|
|
|
273914
273931
|
return out;
|
|
273915
273932
|
};
|
|
273916
273933
|
return {
|
|
273917
|
-
frame(rgba,
|
|
273934
|
+
frame(rgba, delay3) {
|
|
273918
273935
|
let palette2 = shared;
|
|
273919
273936
|
if (mode === "per-frame" || !palette2) {
|
|
273920
273937
|
const c2 = new PaletteCounter();
|
|
@@ -273926,7 +273943,7 @@ function createGifEncoder(width, height, opts, shared) {
|
|
|
273926
273943
|
if (incremental && pending8 && canvas) {
|
|
273927
273944
|
const box2 = changedBox(canvas, idx, width);
|
|
273928
273945
|
if (!box2) {
|
|
273929
|
-
pending8.delay +=
|
|
273946
|
+
pending8.delay += delay3;
|
|
273930
273947
|
return new Uint8Array(0);
|
|
273931
273948
|
}
|
|
273932
273949
|
if (solid5 && opaque) {
|
|
@@ -273939,13 +273956,13 @@ function createGifEncoder(width, height, opts, shared) {
|
|
|
273939
273956
|
}
|
|
273940
273957
|
}
|
|
273941
273958
|
const out2 = flush(true);
|
|
273942
|
-
pending8 = { idx: sub2, ...box2, delay, palette: palette2 };
|
|
273959
|
+
pending8 = { idx: sub2, ...box2, delay: delay3, palette: palette2 };
|
|
273943
273960
|
canvas = idx;
|
|
273944
273961
|
return out2;
|
|
273945
273962
|
}
|
|
273946
273963
|
}
|
|
273947
273964
|
const out = flush(false);
|
|
273948
|
-
pending8 = { idx, x: 0, y: 0, w: width, h: height, delay, palette: palette2 };
|
|
273965
|
+
pending8 = { idx, x: 0, y: 0, w: width, h: height, delay: delay3, palette: palette2 };
|
|
273949
273966
|
canvas = incremental ? idx : null;
|
|
273950
273967
|
opaque = solid5;
|
|
273951
273968
|
return out;
|
|
@@ -305367,13 +305384,13 @@ var init_output = __esm({
|
|
|
305367
305384
|
* prefer the `'target'` event for those cases.
|
|
305368
305385
|
*/
|
|
305369
305386
|
get target() {
|
|
305370
|
-
const
|
|
305387
|
+
const errorMessage3 = "Output.target cannot be used when using PathedTarget with an async callback. Use the 'target' event instead.";
|
|
305371
305388
|
if (this._rootTargetPromise) {
|
|
305372
|
-
throw new TypeError(
|
|
305389
|
+
throw new TypeError(errorMessage3);
|
|
305373
305390
|
}
|
|
305374
305391
|
const rootTargetResult = this._getRootTarget();
|
|
305375
305392
|
if (isThenable(rootTargetResult)) {
|
|
305376
|
-
throw new TypeError(
|
|
305393
|
+
throw new TypeError(errorMessage3);
|
|
305377
305394
|
}
|
|
305378
305395
|
return rootTargetResult;
|
|
305379
305396
|
}
|
|
@@ -310337,11 +310354,11 @@ function usePageThumbnail(frame2, doc2) {
|
|
|
310337
310354
|
if (prev && prev !== next2) URL.revokeObjectURL(prev);
|
|
310338
310355
|
setUrl(next2);
|
|
310339
310356
|
};
|
|
310340
|
-
const
|
|
310357
|
+
const delay3 = hit ? SETTLE_MS : 0;
|
|
310341
310358
|
const timer = setTimeout(() => {
|
|
310342
310359
|
if (typeof requestIdleCallback === "function") requestIdleCallback(() => void run4(), { timeout: 3e3 });
|
|
310343
310360
|
else void run4();
|
|
310344
|
-
},
|
|
310361
|
+
}, delay3);
|
|
310345
310362
|
return () => {
|
|
310346
310363
|
cancelled = true;
|
|
310347
310364
|
clearTimeout(timer);
|
|
@@ -310602,6 +310619,7 @@ async function createFreshFileOrExplain(place4 = {}, seed2 = {}) {
|
|
|
310602
310619
|
var online, goesLocal;
|
|
310603
310620
|
var init_new_file = __esm({
|
|
310604
310621
|
"lib/client/cloud/new-file.ts"() {
|
|
310622
|
+
"use strict";
|
|
310605
310623
|
init_scene_graph();
|
|
310606
310624
|
init_print_pages();
|
|
310607
310625
|
init_page_presets();
|
|
@@ -310807,7 +310825,7 @@ async function pushThumbnail(key5, docId) {
|
|
|
310807
310825
|
await putThumbnail(key5, blob);
|
|
310808
310826
|
uploadedThumbs.set(key5, at4);
|
|
310809
310827
|
}
|
|
310810
|
-
function schedulePush(
|
|
310828
|
+
function schedulePush(delay3 = 3e3) {
|
|
310811
310829
|
dirty = true;
|
|
310812
310830
|
if (!activeLink || !canEdit(activeLink.role) || !cloudUser()) return;
|
|
310813
310831
|
if (pushTimer) clearTimeout(pushTimer);
|
|
@@ -310816,7 +310834,7 @@ function schedulePush(delay = 3e3) {
|
|
|
310816
310834
|
pushing = (pushing ?? Promise.resolve()).then(push).finally(() => {
|
|
310817
310835
|
pushing = null;
|
|
310818
310836
|
});
|
|
310819
|
-
},
|
|
310837
|
+
}, delay3);
|
|
310820
310838
|
}
|
|
310821
310839
|
async function openCloudFile(key5, opts = {}) {
|
|
310822
310840
|
const running4 = !opts.replaceLocal && openingFiles.get(key5);
|
|
@@ -311142,7 +311160,6 @@ function startCloudSync() {
|
|
|
311142
311160
|
var status, readOnlyDoc, activeLink, statusListeners, notice, urlArmed, opening, syncStatus, canEdit, uploaded, MEDIA_UPLOAD_PARALLEL, pushTimer, pushing, dirty, pendingMedia, collab, collabSession, collabAnonymous, uploadedThumbs, thumbCheckedAt, THUMB_EVERY_MS, THUMB_MIN_GAP_MS, putThumbnail, openingFiles, mediaHealed, started2;
|
|
311143
311161
|
var init_sync2 = __esm({
|
|
311144
311162
|
"lib/client/cloud/sync.ts"() {
|
|
311145
|
-
"use strict";
|
|
311146
311163
|
init_paint_repair();
|
|
311147
311164
|
init_migrate();
|
|
311148
311165
|
init_view();
|
|
@@ -312527,6 +312544,7 @@ function areaBounds(rings) {
|
|
|
312527
312544
|
}
|
|
312528
312545
|
var init_text_area = __esm({
|
|
312529
312546
|
"lib/engine/text/text-area.ts"() {
|
|
312547
|
+
"use strict";
|
|
312530
312548
|
}
|
|
312531
312549
|
});
|
|
312532
312550
|
|
|
@@ -317316,7 +317334,6 @@ function videoPixelSize(resolution, aspect) {
|
|
|
317316
317334
|
var VIDEO_ASPECTS, VIDEO_RESOLUTIONS, SEEDANCE_ASPECTS, range, VIDEO_MODELS, DEFAULT_VIDEO_MODEL, videoModel, VIDEO_LIMITS;
|
|
317317
317335
|
var init_video_models = __esm({
|
|
317318
317336
|
"lib/ai/video-models.ts"() {
|
|
317319
|
-
"use strict";
|
|
317320
317337
|
VIDEO_ASPECTS = ["16:9", "9:16", "1:1", "4:3", "3:4", "21:9"];
|
|
317321
317338
|
VIDEO_RESOLUTIONS = ["480p", "720p", "1080p"];
|
|
317322
317339
|
SEEDANCE_ASPECTS = ["16:9", "9:16", "1:1", "4:3", "3:4", "21:9"];
|
|
@@ -317805,7 +317822,6 @@ function agentToolList() {
|
|
|
317805
317822
|
var AGENT_CAPABILITIES, legacyCommandId, legacyTools, blobToDataUrl3, provided, legacyTool, legacyToolList;
|
|
317806
317823
|
var init_agent = __esm({
|
|
317807
317824
|
"lib/commands/agent.ts"() {
|
|
317808
|
-
"use strict";
|
|
317809
317825
|
init_types5();
|
|
317810
317826
|
init_registry();
|
|
317811
317827
|
init_errors();
|
|
@@ -327669,7 +327685,7 @@ var init_package = __esm({
|
|
|
327669
327685
|
"packages/runtime/package.json"() {
|
|
327670
327686
|
package_default = {
|
|
327671
327687
|
name: "@popcraft/runtime",
|
|
327672
|
-
version: "0.
|
|
327688
|
+
version: "0.42.1",
|
|
327673
327689
|
description: "What code exported from PopCraft shares: the meaning of expressions (operators and functions) and, as it grows, the parts of a design's behaviour that are common code rather than generated React.",
|
|
327674
327690
|
license: "MIT",
|
|
327675
327691
|
homepage: "https://popcraft.app/docs/exporting/nextjs",
|
|
@@ -342187,7 +342203,7 @@ var require_trace_mapping_umd = __commonJS({
|
|
|
342187
342203
|
return a[COLUMN] - b[COLUMN];
|
|
342188
342204
|
}
|
|
342189
342205
|
function buildBySources(decoded, memos) {
|
|
342190
|
-
const
|
|
342206
|
+
const sources3 = memos.map(() => []);
|
|
342191
342207
|
for (let i2 = 0; i2 < decoded.length; i2++) {
|
|
342192
342208
|
const line = decoded[i2];
|
|
342193
342209
|
for (let j = 0; j < line.length; j++) {
|
|
@@ -342196,19 +342212,19 @@ var require_trace_mapping_umd = __commonJS({
|
|
|
342196
342212
|
const sourceIndex2 = seg[SOURCES_INDEX];
|
|
342197
342213
|
const sourceLine = seg[SOURCE_LINE];
|
|
342198
342214
|
const sourceColumn = seg[SOURCE_COLUMN];
|
|
342199
|
-
const source3 =
|
|
342215
|
+
const source3 = sources3[sourceIndex2];
|
|
342200
342216
|
const segs = source3[sourceLine] || (source3[sourceLine] = []);
|
|
342201
342217
|
segs.push([sourceColumn, i2, seg[COLUMN]]);
|
|
342202
342218
|
}
|
|
342203
342219
|
}
|
|
342204
|
-
for (let i2 = 0; i2 <
|
|
342205
|
-
const source3 =
|
|
342220
|
+
for (let i2 = 0; i2 < sources3.length; i2++) {
|
|
342221
|
+
const source3 = sources3[i2];
|
|
342206
342222
|
for (let j = 0; j < source3.length; j++) {
|
|
342207
342223
|
const line = source3[j];
|
|
342208
342224
|
if (line) line.sort(sortComparator);
|
|
342209
342225
|
}
|
|
342210
342226
|
}
|
|
342211
|
-
return
|
|
342227
|
+
return sources3;
|
|
342212
342228
|
}
|
|
342213
342229
|
var found = false;
|
|
342214
342230
|
function binarySearch(haystack, needle, low, high) {
|
|
@@ -342275,7 +342291,7 @@ var require_trace_mapping_umd = __commonJS({
|
|
|
342275
342291
|
return new TraceMap(parsed2, mapUrl);
|
|
342276
342292
|
}
|
|
342277
342293
|
const mappings = [];
|
|
342278
|
-
const
|
|
342294
|
+
const sources3 = [];
|
|
342279
342295
|
const sourcesContent = [];
|
|
342280
342296
|
const names = [];
|
|
342281
342297
|
const ignoreList = [];
|
|
@@ -342283,7 +342299,7 @@ var require_trace_mapping_umd = __commonJS({
|
|
|
342283
342299
|
parsed2,
|
|
342284
342300
|
mapUrl,
|
|
342285
342301
|
mappings,
|
|
342286
|
-
|
|
342302
|
+
sources3,
|
|
342287
342303
|
sourcesContent,
|
|
342288
342304
|
names,
|
|
342289
342305
|
ignoreList,
|
|
@@ -342296,14 +342312,14 @@ var require_trace_mapping_umd = __commonJS({
|
|
|
342296
342312
|
version: 3,
|
|
342297
342313
|
file: parsed2.file,
|
|
342298
342314
|
names,
|
|
342299
|
-
sources:
|
|
342315
|
+
sources: sources3,
|
|
342300
342316
|
sourcesContent,
|
|
342301
342317
|
mappings,
|
|
342302
342318
|
ignoreList
|
|
342303
342319
|
};
|
|
342304
342320
|
return presortedDecodedMap(joined);
|
|
342305
342321
|
};
|
|
342306
|
-
function recurse(input2, mapUrl, mappings,
|
|
342322
|
+
function recurse(input2, mapUrl, mappings, sources3, sourcesContent, names, ignoreList, lineOffset, columnOffset, stopLine, stopColumn) {
|
|
342307
342323
|
const { sections } = input2;
|
|
342308
342324
|
for (let i2 = 0; i2 < sections.length; i2++) {
|
|
342309
342325
|
const { map: map2, offset } = sections[i2];
|
|
@@ -342322,7 +342338,7 @@ var require_trace_mapping_umd = __commonJS({
|
|
|
342322
342338
|
map2,
|
|
342323
342339
|
mapUrl,
|
|
342324
342340
|
mappings,
|
|
342325
|
-
|
|
342341
|
+
sources3,
|
|
342326
342342
|
sourcesContent,
|
|
342327
342343
|
names,
|
|
342328
342344
|
ignoreList,
|
|
@@ -342333,15 +342349,15 @@ var require_trace_mapping_umd = __commonJS({
|
|
|
342333
342349
|
);
|
|
342334
342350
|
}
|
|
342335
342351
|
}
|
|
342336
|
-
function addSection(input2, mapUrl, mappings,
|
|
342352
|
+
function addSection(input2, mapUrl, mappings, sources3, sourcesContent, names, ignoreList, lineOffset, columnOffset, stopLine, stopColumn) {
|
|
342337
342353
|
const parsed2 = parse7(input2);
|
|
342338
342354
|
if ("sections" in parsed2) return recurse(...arguments);
|
|
342339
342355
|
const map2 = new TraceMap(parsed2, mapUrl);
|
|
342340
|
-
const sourcesOffset =
|
|
342356
|
+
const sourcesOffset = sources3.length;
|
|
342341
342357
|
const namesOffset = names.length;
|
|
342342
342358
|
const decoded = decodedMappings(map2);
|
|
342343
342359
|
const { resolvedSources, sourcesContent: contents, ignoreList: ignores } = map2;
|
|
342344
|
-
append(
|
|
342360
|
+
append(sources3, resolvedSources);
|
|
342345
342361
|
append(names, map2.names);
|
|
342346
342362
|
if (contents) append(sourcesContent, contents);
|
|
342347
342363
|
else for (let i2 = 0; i2 < resolvedSources.length; i2++) sourcesContent.push(null);
|
|
@@ -342385,16 +342401,16 @@ var require_trace_mapping_umd = __commonJS({
|
|
|
342385
342401
|
const isString2 = typeof map2 === "string";
|
|
342386
342402
|
if (!isString2 && map2._decodedMemo) return map2;
|
|
342387
342403
|
const parsed2 = parse7(map2);
|
|
342388
|
-
const { version: version7, file: file2, names, sourceRoot, sources:
|
|
342404
|
+
const { version: version7, file: file2, names, sourceRoot, sources: sources3, sourcesContent } = parsed2;
|
|
342389
342405
|
this.version = version7;
|
|
342390
342406
|
this.file = file2;
|
|
342391
342407
|
this.names = names || [];
|
|
342392
342408
|
this.sourceRoot = sourceRoot;
|
|
342393
|
-
this.sources =
|
|
342409
|
+
this.sources = sources3;
|
|
342394
342410
|
this.sourcesContent = sourcesContent;
|
|
342395
342411
|
this.ignoreList = parsed2.ignoreList || parsed2.x_google_ignoreList || void 0;
|
|
342396
342412
|
const resolve7 = resolver(mapUrl, sourceRoot);
|
|
342397
|
-
this.resolvedSources =
|
|
342413
|
+
this.resolvedSources = sources3.map(resolve7);
|
|
342398
342414
|
const { mappings } = parsed2;
|
|
342399
342415
|
if (typeof mappings === "string") {
|
|
342400
342416
|
this._encoded = mappings;
|
|
@@ -342501,8 +342517,8 @@ var require_trace_mapping_umd = __commonJS({
|
|
|
342501
342517
|
}
|
|
342502
342518
|
}
|
|
342503
342519
|
function sourceIndex(map2, source3) {
|
|
342504
|
-
const { sources:
|
|
342505
|
-
let index2 =
|
|
342520
|
+
const { sources: sources3, resolvedSources } = map2;
|
|
342521
|
+
let index2 = sources3.indexOf(source3);
|
|
342506
342522
|
if (index2 === -1) index2 = resolvedSources.indexOf(source3);
|
|
342507
342523
|
return index2;
|
|
342508
342524
|
}
|
|
@@ -342574,11 +342590,11 @@ var require_trace_mapping_umd = __commonJS({
|
|
|
342574
342590
|
line--;
|
|
342575
342591
|
if (line < 0) throw new Error(LINE_GTR_ZERO);
|
|
342576
342592
|
if (column < 0) throw new Error(COL_GTR_EQ_ZERO);
|
|
342577
|
-
const { sources:
|
|
342578
|
-
let sourceIndex2 =
|
|
342593
|
+
const { sources: sources3, resolvedSources } = map2;
|
|
342594
|
+
let sourceIndex2 = sources3.indexOf(source3);
|
|
342579
342595
|
if (sourceIndex2 === -1) sourceIndex2 = resolvedSources.indexOf(source3);
|
|
342580
342596
|
if (sourceIndex2 === -1) return all4 ? [] : GMapping(null, null);
|
|
342581
|
-
const bySourceMemos = (_a4 = cast(map2))._bySourceMemos || (_a4._bySourceMemos =
|
|
342597
|
+
const bySourceMemos = (_a4 = cast(map2))._bySourceMemos || (_a4._bySourceMemos = sources3.map(memoizedState));
|
|
342582
342598
|
const generated = (_b2 = cast(map2))._bySources || (_b2._bySources = buildBySources(decodedMappings(map2), bySourceMemos));
|
|
342583
342599
|
const segments = generated[sourceIndex2][line];
|
|
342584
342600
|
if (segments == null) return all4 ? [] : GMapping(null, null);
|
|
@@ -342758,21 +342774,21 @@ var require_gen_mapping_umd = __commonJS({
|
|
|
342758
342774
|
};
|
|
342759
342775
|
function setSourceContent(map2, source3, content) {
|
|
342760
342776
|
const {
|
|
342761
|
-
_sources:
|
|
342777
|
+
_sources: sources3,
|
|
342762
342778
|
_sourcesContent: sourcesContent
|
|
342763
342779
|
// _originalScopes: originalScopes,
|
|
342764
342780
|
} = cast2(map2);
|
|
342765
|
-
const index2 = put3(
|
|
342781
|
+
const index2 = put3(sources3, source3);
|
|
342766
342782
|
sourcesContent[index2] = content;
|
|
342767
342783
|
}
|
|
342768
342784
|
function setIgnore(map2, source3, ignore = true) {
|
|
342769
342785
|
const {
|
|
342770
|
-
_sources:
|
|
342786
|
+
_sources: sources3,
|
|
342771
342787
|
_sourcesContent: sourcesContent,
|
|
342772
342788
|
_ignoreList: ignoreList
|
|
342773
342789
|
// _originalScopes: originalScopes,
|
|
342774
342790
|
} = cast2(map2);
|
|
342775
|
-
const index2 = put3(
|
|
342791
|
+
const index2 = put3(sources3, source3);
|
|
342776
342792
|
if (index2 === sourcesContent.length) sourcesContent[index2] = null;
|
|
342777
342793
|
if (ignore) put3(ignoreList, index2);
|
|
342778
342794
|
else remove(ignoreList, index2);
|
|
@@ -342780,7 +342796,7 @@ var require_gen_mapping_umd = __commonJS({
|
|
|
342780
342796
|
function toDecodedMap(map2) {
|
|
342781
342797
|
const {
|
|
342782
342798
|
_mappings: mappings,
|
|
342783
|
-
_sources:
|
|
342799
|
+
_sources: sources3,
|
|
342784
342800
|
_sourcesContent: sourcesContent,
|
|
342785
342801
|
_names: names,
|
|
342786
342802
|
_ignoreList: ignoreList
|
|
@@ -342793,7 +342809,7 @@ var require_gen_mapping_umd = __commonJS({
|
|
|
342793
342809
|
file: map2.file || void 0,
|
|
342794
342810
|
names: names.array,
|
|
342795
342811
|
sourceRoot: map2.sourceRoot || void 0,
|
|
342796
|
-
sources:
|
|
342812
|
+
sources: sources3.array,
|
|
342797
342813
|
sourcesContent,
|
|
342798
342814
|
mappings,
|
|
342799
342815
|
// originalScopes,
|
|
@@ -342821,7 +342837,7 @@ var require_gen_mapping_umd = __commonJS({
|
|
|
342821
342837
|
}
|
|
342822
342838
|
function allMappings(map2) {
|
|
342823
342839
|
const out = [];
|
|
342824
|
-
const { _mappings: mappings, _sources:
|
|
342840
|
+
const { _mappings: mappings, _sources: sources3, _names: names } = cast2(map2);
|
|
342825
342841
|
for (let i2 = 0; i2 < mappings.length; i2++) {
|
|
342826
342842
|
const line = mappings[i2];
|
|
342827
342843
|
for (let j = 0; j < line.length; j++) {
|
|
@@ -342831,7 +342847,7 @@ var require_gen_mapping_umd = __commonJS({
|
|
|
342831
342847
|
let original = void 0;
|
|
342832
342848
|
let name2 = void 0;
|
|
342833
342849
|
if (seg.length !== 1) {
|
|
342834
|
-
source3 =
|
|
342850
|
+
source3 = sources3.array[seg[SOURCES_INDEX]];
|
|
342835
342851
|
original = { line: seg[SOURCE_LINE] + 1, column: seg[SOURCE_COLUMN] };
|
|
342836
342852
|
if (seg.length === 5) name2 = names.array[seg[NAMES_INDEX]];
|
|
342837
342853
|
}
|
|
@@ -342843,7 +342859,7 @@ var require_gen_mapping_umd = __commonJS({
|
|
|
342843
342859
|
function addSegmentInternal(skipable, map2, genLine, genColumn, source3, sourceLine, sourceColumn, name2, content) {
|
|
342844
342860
|
const {
|
|
342845
342861
|
_mappings: mappings,
|
|
342846
|
-
_sources:
|
|
342862
|
+
_sources: sources3,
|
|
342847
342863
|
_sourcesContent: sourcesContent,
|
|
342848
342864
|
_names: names
|
|
342849
342865
|
// _originalScopes: originalScopes,
|
|
@@ -342856,7 +342872,7 @@ var require_gen_mapping_umd = __commonJS({
|
|
|
342856
342872
|
}
|
|
342857
342873
|
assert4(sourceLine);
|
|
342858
342874
|
assert4(sourceColumn);
|
|
342859
|
-
const sourcesIndex = put3(
|
|
342875
|
+
const sourcesIndex = put3(sources3, source3);
|
|
342860
342876
|
const namesIndex = name2 ? put3(names, name2) : NO_NAME;
|
|
342861
342877
|
if (sourcesIndex === sourcesContent.length) sourcesContent[sourcesIndex] = content != null ? content : null;
|
|
342862
342878
|
if (skipable && skipSource(line, index2, sourcesIndex, sourceLine, sourceColumn, namesIndex)) {
|
|
@@ -361417,6 +361433,7 @@ var init_delete_current_file = __esm({
|
|
|
361417
361433
|
var storeOpsSeam;
|
|
361418
361434
|
var init_seams = __esm({
|
|
361419
361435
|
"lib/commands/seams.ts"() {
|
|
361436
|
+
"use strict";
|
|
361420
361437
|
storeOpsSeam = (st) => ({
|
|
361421
361438
|
booleanOperation: (op4) => st().booleanOperation(op4),
|
|
361422
361439
|
flatten: () => st().flattenSelection(),
|
|
@@ -364521,607 +364538,1397 @@ var init_open_intent = __esm({
|
|
|
364521
364538
|
}
|
|
364522
364539
|
});
|
|
364523
364540
|
|
|
364524
|
-
// node_modules/.pnpm/@hyperyai+sdk@1.
|
|
364525
|
-
|
|
364526
|
-
|
|
364541
|
+
// node_modules/.pnpm/@hyperyai+sdk@2.1.0_@types+react-dom@19.3.0_@types+react@19.3.0__@types+react@19.3.0_re_62022f8c0abbfd4c405f5fb20b5aa9ec/node_modules/@hyperyai/sdk/dist/agents/core/hypery-model.js
|
|
364542
|
+
function agentModelError(message, code, status3) {
|
|
364543
|
+
{
|
|
364544
|
+
return { name: "AgentModelError", message, code: code ?? "ai_upstream", status: ((__v) => __v == null ? "null" : typeof __v)(status3) === "number" ? status3 : 502 };
|
|
364545
|
+
}
|
|
364546
|
+
}
|
|
364547
|
+
async function resolve2(v) {
|
|
364548
|
+
{
|
|
364549
|
+
if (((__v) => __v == null ? "null" : typeof __v)(v) === "function") {
|
|
364550
|
+
return await (v() ?? null);
|
|
364551
|
+
}
|
|
364552
|
+
return v ?? null;
|
|
364553
|
+
}
|
|
364554
|
+
}
|
|
364555
|
+
function errorCodeFor(status3, payload) {
|
|
364556
|
+
{
|
|
364557
|
+
if (payload != null && ((__v) => __v == null ? "null" : typeof __v)(payload) === "object" && payload.error != null && ((__v) => __v == null ? "null" : typeof __v)(payload.error) === "object" && ((__v) => __v == null ? "null" : typeof __v)(payload.error.code) === "string") {
|
|
364558
|
+
return payload.error.code;
|
|
364559
|
+
}
|
|
364560
|
+
if (status3 === 401) {
|
|
364561
|
+
return "ai_reauth";
|
|
364562
|
+
}
|
|
364563
|
+
if (status3 === 402) {
|
|
364564
|
+
return "ai_credits";
|
|
364565
|
+
}
|
|
364566
|
+
if (status3 === 403) {
|
|
364567
|
+
return "ai_scope";
|
|
364568
|
+
}
|
|
364569
|
+
if (status3 === 429) {
|
|
364570
|
+
return "ai_rate_limited";
|
|
364571
|
+
}
|
|
364572
|
+
return "ai_upstream";
|
|
364573
|
+
}
|
|
364574
|
+
}
|
|
364575
|
+
function streamErrorMessage(payload, fallback2) {
|
|
364576
|
+
{
|
|
364577
|
+
let otherwise = fallback2 ?? "The AI request failed.";
|
|
364578
|
+
if (payload == null || ((__v) => __v == null ? "null" : typeof __v)(payload) !== "object") {
|
|
364579
|
+
return otherwise;
|
|
364580
|
+
}
|
|
364581
|
+
let err2 = payload.error ?? null;
|
|
364582
|
+
if (((__v) => __v == null ? "null" : typeof __v)(err2) === "string" && (err2.trim() ?? null) !== "") {
|
|
364583
|
+
return err2;
|
|
364584
|
+
}
|
|
364585
|
+
let message = err2 != null && ((__v) => __v == null ? "null" : typeof __v)(err2) === "object" ? err2.message ?? null : null;
|
|
364586
|
+
if (message == null) {
|
|
364587
|
+
message = payload.message ?? null;
|
|
364588
|
+
}
|
|
364589
|
+
return ((__v) => __v == null ? "null" : typeof __v)(message) === "string" && (message.trim() ?? null) !== "" ? message : otherwise;
|
|
364590
|
+
}
|
|
364591
|
+
}
|
|
364592
|
+
function createStreamAccumulator() {
|
|
364593
|
+
{
|
|
364594
|
+
let buffer = "";
|
|
364595
|
+
let text = "";
|
|
364596
|
+
let reasoning = "";
|
|
364597
|
+
let sawDone = false;
|
|
364598
|
+
let calls = /* @__PURE__ */ new Map() ?? null;
|
|
364599
|
+
let order2 = [];
|
|
364600
|
+
return { push: (part) => {
|
|
364601
|
+
{
|
|
364602
|
+
buffer = buffer + part;
|
|
364603
|
+
let out = [];
|
|
364604
|
+
let nl = buffer.indexOf("\n") ?? null;
|
|
364605
|
+
while (nl >= 0) {
|
|
364606
|
+
let line = (buffer.slice(0, nl) ?? null).trim() ?? null;
|
|
364607
|
+
buffer = buffer.slice(nl + 1) ?? null;
|
|
364608
|
+
nl = buffer.indexOf("\n") ?? null;
|
|
364609
|
+
if (!(line.startsWith("data:") ?? null)) {
|
|
364610
|
+
continue;
|
|
364611
|
+
}
|
|
364612
|
+
let data = (line.slice(5) ?? null).trim() ?? null;
|
|
364613
|
+
if (data === "") {
|
|
364614
|
+
continue;
|
|
364615
|
+
}
|
|
364616
|
+
if (data === "[DONE]") {
|
|
364617
|
+
sawDone = true;
|
|
364618
|
+
continue;
|
|
364619
|
+
}
|
|
364620
|
+
let chunk3 = null;
|
|
364621
|
+
try {
|
|
364622
|
+
{
|
|
364623
|
+
chunk3 = JSON.parse(data) ?? null;
|
|
364624
|
+
}
|
|
364625
|
+
} catch (e) {
|
|
364626
|
+
{
|
|
364627
|
+
continue;
|
|
364628
|
+
}
|
|
364629
|
+
}
|
|
364630
|
+
if (chunk3 == null || ((__v) => __v == null ? "null" : typeof __v)(chunk3) !== "object") {
|
|
364631
|
+
continue;
|
|
364632
|
+
}
|
|
364633
|
+
if (chunk3.error) {
|
|
364634
|
+
let code = ((__v) => __v == null ? "null" : typeof __v)(chunk3.error) === "object" && ((__v) => __v == null ? "null" : typeof __v)(chunk3.error.code) === "string" ? chunk3.error.code : "ai_upstream";
|
|
364635
|
+
throw agentModelError(streamErrorMessage(chunk3, null) ?? null, code, 502) ?? null;
|
|
364636
|
+
}
|
|
364637
|
+
let choice = (Array.isArray(chunk3.choices) ?? null) && chunk3.choices.length > 0 ? chunk3.choices[0] ?? null : null;
|
|
364638
|
+
let delta = choice != null ? choice.delta ?? null : null;
|
|
364639
|
+
if (delta == null) {
|
|
364640
|
+
continue;
|
|
364641
|
+
}
|
|
364642
|
+
if (((__v) => __v == null ? "null" : typeof __v)(delta.content) === "string" && delta.content !== "") {
|
|
364643
|
+
text = text + delta.content;
|
|
364644
|
+
out.push({ textDelta: delta.content }) ?? null;
|
|
364645
|
+
}
|
|
364646
|
+
let r = ((__v) => __v == null ? "null" : typeof __v)(delta.reasoning) === "string" ? delta.reasoning : ((__v) => __v == null ? "null" : typeof __v)(delta.reasoning_content) === "string" ? delta.reasoning_content : "";
|
|
364647
|
+
if (r !== "") {
|
|
364648
|
+
reasoning = reasoning + r;
|
|
364649
|
+
out.push({ reasoningDelta: r }) ?? null;
|
|
364650
|
+
}
|
|
364651
|
+
for (const tc of Array.isArray(delta.tool_calls) ?? null ? delta.tool_calls : []) {
|
|
364652
|
+
let i2 = ((__v) => __v == null ? "null" : typeof __v)(tc.index) === "number" ? tc.index : order2.length > 0 ? order2[order2.length - 1] ?? null : 0;
|
|
364653
|
+
if (!(calls.has(i2) ?? null)) {
|
|
364654
|
+
calls.set(i2, { id: null, name: "", arguments: "" }) ?? null;
|
|
364655
|
+
order2.push(i2) ?? null;
|
|
364656
|
+
}
|
|
364657
|
+
let call2 = calls.get(i2) ?? null;
|
|
364658
|
+
if (((__v) => __v == null ? "null" : typeof __v)(tc.id) === "string" && tc.id !== "") {
|
|
364659
|
+
call2.id = tc.id;
|
|
364660
|
+
}
|
|
364661
|
+
let f2 = tc["function"] ?? null ?? null;
|
|
364662
|
+
if (f2 != null && ((__v) => __v == null ? "null" : typeof __v)(f2.name) === "string") {
|
|
364663
|
+
call2.name = call2.name + f2.name;
|
|
364664
|
+
}
|
|
364665
|
+
if (f2 != null && ((__v) => __v == null ? "null" : typeof __v)(f2.arguments) === "string" && f2.arguments !== "") {
|
|
364666
|
+
call2.arguments = call2.arguments + f2.arguments;
|
|
364667
|
+
out.push({ toolProgress: { index: i2, name: call2.name, bytes: call2.arguments.length, arguments: call2.arguments } }) ?? null;
|
|
364668
|
+
}
|
|
364669
|
+
}
|
|
364670
|
+
}
|
|
364671
|
+
return out;
|
|
364672
|
+
}
|
|
364673
|
+
}, result: () => {
|
|
364674
|
+
{
|
|
364675
|
+
let toolCalls = [];
|
|
364676
|
+
let n = 0;
|
|
364677
|
+
for (const i2 of order2) {
|
|
364678
|
+
let c2 = calls.get(i2) ?? null;
|
|
364679
|
+
if (c2.name !== "") {
|
|
364680
|
+
toolCalls.push({ id: c2.id ?? "call_" + (String(n) ?? null), name: c2.name, arguments: c2.arguments }) ?? null;
|
|
364681
|
+
}
|
|
364682
|
+
n = n + 1;
|
|
364683
|
+
}
|
|
364684
|
+
return { text, reasoning, sawDone, toolCalls };
|
|
364685
|
+
}
|
|
364686
|
+
} };
|
|
364687
|
+
}
|
|
364688
|
+
}
|
|
364689
|
+
function appendBytes(pending8, chunk3) {
|
|
364690
|
+
{
|
|
364691
|
+
let out = pending8.slice() ?? null;
|
|
364692
|
+
let i2 = 0;
|
|
364693
|
+
while (i2 < chunk3.length) {
|
|
364694
|
+
out.push(chunk3[i2] ?? null) ?? null;
|
|
364695
|
+
i2 = i2 + 1;
|
|
364696
|
+
}
|
|
364697
|
+
return out;
|
|
364698
|
+
}
|
|
364699
|
+
}
|
|
364700
|
+
function callHook(hooks, name2, value3) {
|
|
364701
|
+
{
|
|
364702
|
+
if (hooks == null || ((__v) => __v == null ? "null" : typeof __v)(hooks) !== "object") {
|
|
364703
|
+
return;
|
|
364704
|
+
}
|
|
364705
|
+
let h = hooks[name2] ?? null;
|
|
364706
|
+
if (((__v) => __v == null ? "null" : typeof __v)(h) === "function") {
|
|
364707
|
+
h(value3) ?? null;
|
|
364708
|
+
}
|
|
364709
|
+
}
|
|
364710
|
+
}
|
|
364711
|
+
function createHyperyModel(opts) {
|
|
364712
|
+
{
|
|
364713
|
+
let idleMs = ((__v) => __v == null ? "null" : typeof __v)(opts.idleTimeoutMs) === "number" ? opts.idleTimeoutMs : DEFAULT_IDLE_TIMEOUT_MS;
|
|
364714
|
+
let limit = ((__v) => __v == null ? "null" : typeof __v)(opts.maxRequestBytes) === "number" ? opts.maxRequestBytes : MAX_REQUEST_BYTES;
|
|
364715
|
+
let base = ((__v) => __v == null ? "null" : typeof __v)(opts.gatewayUrl) === "string" && opts.gatewayUrl !== "" ? opts.gatewayUrl : "https://hypery.ai";
|
|
364716
|
+
if (base.endsWith("/") ?? null) {
|
|
364717
|
+
base = base.slice(0, base.length - 1) ?? null;
|
|
364718
|
+
}
|
|
364719
|
+
return async (messages, tools, hooks, signal, req) => {
|
|
364720
|
+
{
|
|
364721
|
+
let token = await (resolve2(opts.token) ?? null);
|
|
364722
|
+
if (((__v) => __v == null ? "null" : typeof __v)(token) !== "string" || token === "") {
|
|
364723
|
+
throw agentModelError("Sign in to Hypery to use the agent.", "ai_reauth", 401) ?? null;
|
|
364724
|
+
}
|
|
364725
|
+
let model = await (resolve2(opts.model) ?? null);
|
|
364726
|
+
let team = await (resolve2(opts.team) ?? null);
|
|
364727
|
+
let paymentSource = await (resolve2(opts.paymentSource) ?? null);
|
|
364728
|
+
let hasTools = (Array.isArray(tools) ?? null) && tools.length > 0;
|
|
364729
|
+
let request2 = { model, messages, stream: true, max_tokens: ((__v) => __v == null ? "null" : typeof __v)(opts.maxTokens) === "number" ? opts.maxTokens : hasTools ? 16384 : 4096 };
|
|
364730
|
+
if (((__v) => __v == null ? "null" : typeof __v)(opts.temperature) === "number") {
|
|
364731
|
+
request2.temperature = opts.temperature;
|
|
364732
|
+
}
|
|
364733
|
+
if (hasTools) {
|
|
364734
|
+
request2.tools = tools;
|
|
364735
|
+
let choice = req != null && ((__v) => __v == null ? "null" : typeof __v)(req) === "object" ? req.toolChoice ?? null : null;
|
|
364736
|
+
request2.tool_choice = choice != null ? choice : "auto";
|
|
364737
|
+
}
|
|
364738
|
+
let body = JSON.stringify(request2) ?? null;
|
|
364739
|
+
if (body.length > limit) {
|
|
364740
|
+
throw agentModelError("This message is too large to send (" + ((body.length / 1e6).toFixed(1) ?? null) + " MB with its images). Send fewer or smaller images.", "too_large", 413) ?? null;
|
|
364741
|
+
}
|
|
364742
|
+
let headers = { Authorization: "Bearer " + token, "Content-Type": "application/json", Accept: "text/event-stream" };
|
|
364743
|
+
if (((__v) => __v == null ? "null" : typeof __v)(team) === "string" && team !== "") {
|
|
364744
|
+
headers[HYPERY_TEAM_HEADER2] = team;
|
|
364745
|
+
}
|
|
364746
|
+
if (((__v) => __v == null ? "null" : typeof __v)(paymentSource) === "string" && paymentSource !== "") {
|
|
364747
|
+
headers[HYPERY_PAYMENT_SOURCE_HEADER2] = paymentSource;
|
|
364748
|
+
}
|
|
364749
|
+
let init = { method: "POST", headers, body };
|
|
364750
|
+
if (signal != null && ((__v) => __v == null ? "null" : typeof __v)(signal.addEventListener) === "function") {
|
|
364751
|
+
init.signal = signal;
|
|
364752
|
+
}
|
|
364753
|
+
let res = null;
|
|
364754
|
+
try {
|
|
364755
|
+
{
|
|
364756
|
+
res = await (opts.fetch(base + "/api/v1/chat/completions", init) ?? null);
|
|
364757
|
+
}
|
|
364758
|
+
} catch (err2) {
|
|
364759
|
+
{
|
|
364760
|
+
if (err2 != null && ((__v) => __v == null ? "null" : typeof __v)(err2) === "object" && err2.name === "AbortError") {
|
|
364761
|
+
throw err2;
|
|
364762
|
+
}
|
|
364763
|
+
throw agentModelError("Could not reach Hypery. Check your connection.", "network", 0) ?? null;
|
|
364764
|
+
}
|
|
364765
|
+
}
|
|
364766
|
+
if (res.ok !== true || res.body == null) {
|
|
364767
|
+
let text = "";
|
|
364768
|
+
try {
|
|
364769
|
+
{
|
|
364770
|
+
text = await (res.text() ?? null);
|
|
364771
|
+
}
|
|
364772
|
+
} catch (e) {
|
|
364773
|
+
{
|
|
364774
|
+
text = "";
|
|
364775
|
+
}
|
|
364776
|
+
}
|
|
364777
|
+
let payload = text;
|
|
364778
|
+
try {
|
|
364779
|
+
{
|
|
364780
|
+
payload = JSON.parse(text) ?? null;
|
|
364781
|
+
}
|
|
364782
|
+
} catch (e) {
|
|
364783
|
+
{
|
|
364784
|
+
payload = text;
|
|
364785
|
+
}
|
|
364786
|
+
}
|
|
364787
|
+
throw agentModelError(streamErrorMessage(payload, "The AI request failed (" + (String(res.status) ?? null) + ").") ?? null, errorCodeFor(res.status, payload) ?? null, res.status) ?? null;
|
|
364788
|
+
}
|
|
364789
|
+
let acc = createStreamAccumulator() ?? null;
|
|
364790
|
+
let reader = res.body.getReader() ?? null;
|
|
364791
|
+
let pending8 = [];
|
|
364792
|
+
let stopReading = () => {
|
|
364793
|
+
{
|
|
364794
|
+
if (((__v) => __v == null ? "null" : typeof __v)(reader.cancel) === "function") {
|
|
364795
|
+
try {
|
|
364796
|
+
{
|
|
364797
|
+
reader.cancel() ?? null;
|
|
364798
|
+
}
|
|
364799
|
+
} catch (e) {
|
|
364800
|
+
{
|
|
364801
|
+
}
|
|
364802
|
+
}
|
|
364803
|
+
}
|
|
364804
|
+
}
|
|
364805
|
+
};
|
|
364806
|
+
while (true) {
|
|
364807
|
+
if (signal != null && signal.aborted === true) {
|
|
364808
|
+
stopReading() ?? null;
|
|
364809
|
+
throw { name: "AbortError", message: "The request was stopped." };
|
|
364810
|
+
}
|
|
364811
|
+
let next2 = await (Promise.race([reader.read() ?? null, delay(idleMs) ?? null]) ?? null);
|
|
364812
|
+
if (next2 == null) {
|
|
364813
|
+
stopReading() ?? null;
|
|
364814
|
+
throw agentModelError("The model stopped responding.", "ai_timeout", 504) ?? null;
|
|
364815
|
+
}
|
|
364816
|
+
if (next2.done === true) {
|
|
364817
|
+
break;
|
|
364818
|
+
}
|
|
364819
|
+
if (next2.value == null) {
|
|
364820
|
+
continue;
|
|
364821
|
+
}
|
|
364822
|
+
let bytes2 = appendBytes(pending8, next2.value) ?? null;
|
|
364823
|
+
let whole = utf8Complete(bytes2) ?? null;
|
|
364824
|
+
pending8 = bytes2.slice(whole) ?? null;
|
|
364825
|
+
let events = [];
|
|
364826
|
+
try {
|
|
364827
|
+
{
|
|
364828
|
+
events = acc.push(utf8Decode(bytes2.slice(0, whole) ?? null) ?? null) ?? null;
|
|
364829
|
+
}
|
|
364830
|
+
} catch (err2) {
|
|
364831
|
+
{
|
|
364832
|
+
stopReading() ?? null;
|
|
364833
|
+
throw err2;
|
|
364834
|
+
}
|
|
364835
|
+
}
|
|
364836
|
+
for (const e of events) {
|
|
364837
|
+
if (((__v) => __v == null ? "null" : typeof __v)(e.textDelta) === "string") {
|
|
364838
|
+
callHook(hooks, "onTextDelta", e.textDelta) ?? null;
|
|
364839
|
+
}
|
|
364840
|
+
if (((__v) => __v == null ? "null" : typeof __v)(e.reasoningDelta) === "string") {
|
|
364841
|
+
callHook(hooks, "onReasoningDelta", e.reasoningDelta) ?? null;
|
|
364842
|
+
}
|
|
364843
|
+
if (e.toolProgress != null) {
|
|
364844
|
+
callHook(hooks, "onToolProgress", e.toolProgress) ?? null;
|
|
364845
|
+
}
|
|
364846
|
+
}
|
|
364847
|
+
}
|
|
364848
|
+
if (pending8.length > 0) {
|
|
364849
|
+
acc.push(utf8Decode(pending8) ?? null) ?? null;
|
|
364850
|
+
}
|
|
364851
|
+
acc.push("\n") ?? null;
|
|
364852
|
+
let r = acc.result() ?? null;
|
|
364853
|
+
if (!r.sawDone && r.text === "" && r.toolCalls.length === 0) {
|
|
364854
|
+
throw agentModelError("The response was cut off before it started. Try again.", "ai_upstream", 502) ?? null;
|
|
364855
|
+
}
|
|
364856
|
+
return { text: r.text, reasoning: r.reasoning, toolCalls: r.toolCalls };
|
|
364857
|
+
}
|
|
364858
|
+
};
|
|
364859
|
+
}
|
|
364860
|
+
}
|
|
364861
|
+
var delay, utf8Complete, utf8Decode, MAX_REQUEST_BYTES, DEFAULT_IDLE_TIMEOUT_MS, HYPERY_TEAM_HEADER2, HYPERY_PAYMENT_SOURCE_HEADER2;
|
|
364862
|
+
var init_hypery_model = __esm({
|
|
364863
|
+
"node_modules/.pnpm/@hyperyai+sdk@2.1.0_@types+react-dom@19.3.0_@types+react@19.3.0__@types+react@19.3.0_re_62022f8c0abbfd4c405f5fb20b5aa9ec/node_modules/@hyperyai/sdk/dist/agents/core/hypery-model.js"() {
|
|
364864
|
+
delay = ((ms2) => new Promise((settle4) => setTimeout(() => settle4(null), Math.max(0, Number(ms2) || 0))));
|
|
364865
|
+
utf8Complete = ((b) => {
|
|
364866
|
+
if (!Array.isArray(b)) return null;
|
|
364867
|
+
const n = b.length;
|
|
364868
|
+
for (let i2 = n - 1; i2 >= Math.max(0, n - 3); i2--) {
|
|
364869
|
+
const c2 = b[i2];
|
|
364870
|
+
if ((c2 & 192) === 128) continue;
|
|
364871
|
+
const len3 = c2 <= 127 ? 1 : c2 >= 194 && c2 <= 223 ? 2 : c2 >= 224 && c2 <= 239 ? 3 : c2 >= 240 && c2 <= 244 ? 4 : 1;
|
|
364872
|
+
return n - i2 < len3 ? i2 : n;
|
|
364873
|
+
}
|
|
364874
|
+
return n;
|
|
364875
|
+
});
|
|
364876
|
+
utf8Decode = ((b) => typeof b === "string" ? b : Array.isArray(b) ? new TextDecoder().decode(Uint8Array.from(b)) : null);
|
|
364877
|
+
MAX_REQUEST_BYTES = 44e5;
|
|
364878
|
+
DEFAULT_IDLE_TIMEOUT_MS = 18e4;
|
|
364879
|
+
HYPERY_TEAM_HEADER2 = "x-hypery-active-organization-id";
|
|
364880
|
+
HYPERY_PAYMENT_SOURCE_HEADER2 = "x-hypery-payment-source";
|
|
364527
364881
|
}
|
|
364528
364882
|
});
|
|
364529
364883
|
|
|
364530
|
-
// node_modules/.pnpm/@hyperyai+sdk@1.
|
|
364531
|
-
function
|
|
364532
|
-
|
|
364533
|
-
|
|
364534
|
-
|
|
364535
|
-
|
|
364536
|
-
|
|
364537
|
-
|
|
364538
|
-
|
|
364539
|
-
|
|
364540
|
-
|
|
364541
|
-
|
|
364884
|
+
// node_modules/.pnpm/@hyperyai+sdk@2.1.0_@types+react-dom@19.3.0_@types+react@19.3.0__@types+react@19.3.0_re_62022f8c0abbfd4c405f5fb20b5aa9ec/node_modules/@hyperyai/sdk/dist/agents/core/context.js
|
|
364885
|
+
function sizeOf2(messages) {
|
|
364886
|
+
{
|
|
364887
|
+
return (JSON.stringify(messages) ?? null).length;
|
|
364888
|
+
}
|
|
364889
|
+
}
|
|
364890
|
+
function isRenderTurn(m) {
|
|
364891
|
+
{
|
|
364892
|
+
if (m.role !== "user" || !(Array.isArray(m.content) ?? null) || m.content.length === 0) {
|
|
364893
|
+
return false;
|
|
364894
|
+
}
|
|
364895
|
+
let first2 = m.content[0] ?? null;
|
|
364896
|
+
return first2.type === "text" && ((__v) => __v == null ? "null" : typeof __v)(first2.text) === "string" && (first2.text.startsWith(RENDER_TURN_PREFIX) ?? null);
|
|
364897
|
+
}
|
|
364898
|
+
}
|
|
364899
|
+
function countImages(parts) {
|
|
364900
|
+
{
|
|
364901
|
+
return (parts.filter((p2) => {
|
|
364902
|
+
{
|
|
364903
|
+
return p2.type === "image_url";
|
|
364904
|
+
}
|
|
364905
|
+
}) ?? null).length;
|
|
364906
|
+
}
|
|
364907
|
+
}
|
|
364908
|
+
function textOf2(parts) {
|
|
364909
|
+
{
|
|
364910
|
+
return ((parts.filter((p2) => {
|
|
364911
|
+
{
|
|
364912
|
+
return p2.type === "text" && ((__v) => __v == null ? "null" : typeof __v)(p2.text) === "string" && p2.text !== "";
|
|
364913
|
+
}
|
|
364914
|
+
}) ?? null).map((p2) => {
|
|
364915
|
+
{
|
|
364916
|
+
return p2.text;
|
|
364917
|
+
}
|
|
364918
|
+
}) ?? null).join(" ") ?? null;
|
|
364919
|
+
}
|
|
364920
|
+
}
|
|
364921
|
+
function imagesLabel(n) {
|
|
364922
|
+
{
|
|
364923
|
+
return n === 1 ? "image" : (String(n) ?? null) + " images";
|
|
364924
|
+
}
|
|
364925
|
+
}
|
|
364926
|
+
function pruneOldImages(messages, keep) {
|
|
364927
|
+
{
|
|
364928
|
+
let limit = ((__v) => __v == null ? "null" : typeof __v)(keep) === "number" ? keep : KEEP_IMAGE_TURNS;
|
|
364929
|
+
let seen = 0;
|
|
364930
|
+
let i2 = messages.length - 1;
|
|
364931
|
+
while (i2 >= 0) {
|
|
364932
|
+
let m = messages[i2] ?? null;
|
|
364933
|
+
if ((isRenderTurn(m) ?? null) && (countImages(m.content) ?? null) > 0) {
|
|
364934
|
+
seen = seen + 1;
|
|
364935
|
+
if (seen > limit) {
|
|
364936
|
+
let note2 = (textOf2(m.content) ?? null) + " [" + (imagesLabel(countImages(m.content) ?? null) ?? null) + " omitted: superseded by a later view.]";
|
|
364937
|
+
messages[i2] = { ...m, content: note2.trim() ?? null };
|
|
364938
|
+
}
|
|
364939
|
+
}
|
|
364940
|
+
i2 = i2 - 1;
|
|
364941
|
+
}
|
|
364542
364942
|
}
|
|
364543
364943
|
}
|
|
364544
364944
|
function fitImagesToBudget(messages, budget) {
|
|
364545
|
-
|
|
364546
|
-
|
|
364547
|
-
|
|
364548
|
-
const m = messages[i2];
|
|
364549
|
-
if (!isRenderTurn(m) || !Array.isArray(m.content))
|
|
364550
|
-
continue;
|
|
364551
|
-
const parts = [...m.content];
|
|
364552
|
-
let dropped = 0;
|
|
364553
|
-
for (let j = parts.length - 1; j >= 0 && sizeOf2(messages) > budget; j--) {
|
|
364554
|
-
if (parts[j].type !== "image_url")
|
|
364555
|
-
continue;
|
|
364556
|
-
parts.splice(j, 1);
|
|
364557
|
-
dropped++;
|
|
364558
|
-
messages[i2] = { ...m, content: [...parts] };
|
|
364945
|
+
{
|
|
364946
|
+
if ((sizeOf2(messages) ?? null) <= budget) {
|
|
364947
|
+
return;
|
|
364559
364948
|
}
|
|
364560
|
-
|
|
364561
|
-
|
|
364562
|
-
|
|
364949
|
+
let i2 = 0;
|
|
364950
|
+
while (i2 < messages.length && (sizeOf2(messages) ?? null) > budget) {
|
|
364951
|
+
let m = messages[i2] ?? null;
|
|
364952
|
+
if (isRenderTurn(m) ?? null) {
|
|
364953
|
+
let parts = m.content.slice() ?? null;
|
|
364954
|
+
let dropped = 0;
|
|
364955
|
+
let j = parts.length - 1;
|
|
364956
|
+
while (j >= 0 && (sizeOf2(messages) ?? null) > budget) {
|
|
364957
|
+
if ((parts[j] ?? null).type === "image_url") {
|
|
364958
|
+
parts.splice(j, 1) ?? null;
|
|
364959
|
+
dropped = dropped + 1;
|
|
364960
|
+
messages[i2] = { ...m, content: parts.slice() ?? null };
|
|
364961
|
+
}
|
|
364962
|
+
j = j - 1;
|
|
364963
|
+
}
|
|
364964
|
+
if (dropped > 0) {
|
|
364965
|
+
let label3 = dropped === 1 ? "1 image" : (String(dropped) ?? null) + " images";
|
|
364966
|
+
let note2 = (textOf2(parts) ?? null) + " [" + label3 + " omitted to keep the request under the size limit.]";
|
|
364967
|
+
messages[i2] = { ...m, content: note2.trim() ?? null };
|
|
364968
|
+
}
|
|
364969
|
+
}
|
|
364970
|
+
i2 = i2 + 1;
|
|
364563
364971
|
}
|
|
364564
364972
|
}
|
|
364565
364973
|
}
|
|
364566
364974
|
function safeTailStart(messages, want) {
|
|
364567
|
-
|
|
364568
|
-
|
|
364569
|
-
i2
|
|
364570
|
-
|
|
364975
|
+
{
|
|
364976
|
+
let i2 = Math.max(1, messages.length - want) ?? null;
|
|
364977
|
+
while (i2 < messages.length && (messages[i2] ?? null).role === "tool") {
|
|
364978
|
+
i2 = i2 + 1;
|
|
364979
|
+
}
|
|
364980
|
+
return i2;
|
|
364981
|
+
}
|
|
364571
364982
|
}
|
|
364572
364983
|
async function compactTranscript(messages, opts) {
|
|
364573
|
-
|
|
364574
|
-
|
|
364575
|
-
|
|
364576
|
-
|
|
364577
|
-
|
|
364578
|
-
|
|
364579
|
-
|
|
364580
|
-
|
|
364581
|
-
|
|
364582
|
-
|
|
364583
|
-
|
|
364584
|
-
|
|
364585
|
-
|
|
364586
|
-
|
|
364587
|
-
|
|
364588
|
-
|
|
364589
|
-
|
|
364984
|
+
{
|
|
364985
|
+
if ((sizeOf2(messages) ?? null) <= opts.maxChars) {
|
|
364986
|
+
return false;
|
|
364987
|
+
}
|
|
364988
|
+
let head2 = messages.length > 0 && (messages[0] ?? null).role === "system" ? 1 : 0;
|
|
364989
|
+
let firstUser = -1;
|
|
364990
|
+
let k2 = head2;
|
|
364991
|
+
while (k2 < messages.length && firstUser < 0) {
|
|
364992
|
+
if ((messages[k2] ?? null).role === "user") {
|
|
364993
|
+
firstUser = k2;
|
|
364994
|
+
}
|
|
364995
|
+
k2 = k2 + 1;
|
|
364996
|
+
}
|
|
364997
|
+
let keepFrom = firstUser >= 0 ? firstUser + 1 : head2;
|
|
364998
|
+
let tail = safeTailStart(messages, ((__v) => __v == null ? "null" : typeof __v)(opts.keepRecent) === "number" ? opts.keepRecent : 12) ?? null;
|
|
364999
|
+
if (tail <= keepFrom) {
|
|
365000
|
+
return false;
|
|
365001
|
+
}
|
|
365002
|
+
let dropped = messages.slice(keepFrom, tail) ?? null;
|
|
365003
|
+
let summary = "";
|
|
365004
|
+
if (((__v) => __v == null ? "null" : typeof __v)(opts.summarize) === "function") {
|
|
365005
|
+
try {
|
|
365006
|
+
{
|
|
365007
|
+
summary = await (opts.summarize(dropped) ?? null);
|
|
365008
|
+
}
|
|
365009
|
+
} catch (e) {
|
|
365010
|
+
{
|
|
365011
|
+
summary = "";
|
|
365012
|
+
}
|
|
365013
|
+
}
|
|
365014
|
+
}
|
|
365015
|
+
let content = summary !== "" ? "Summary of the earlier work in this session (the details were compacted to save space):\n" + summary : "[" + (String(dropped.length) ?? null) + " earlier messages were compacted to save space. Look again at anything you need from them.]";
|
|
365016
|
+
messages.splice(keepFrom, dropped.length, { role: "user", content }) ?? null;
|
|
365017
|
+
return true;
|
|
365018
|
+
}
|
|
364590
365019
|
}
|
|
364591
|
-
var RENDER_TURN_PREFIX, KEEP_IMAGE_TURNS
|
|
365020
|
+
var RENDER_TURN_PREFIX, KEEP_IMAGE_TURNS;
|
|
364592
365021
|
var init_context2 = __esm({
|
|
364593
|
-
"node_modules/.pnpm/@hyperyai+sdk@1.
|
|
365022
|
+
"node_modules/.pnpm/@hyperyai+sdk@2.1.0_@types+react-dom@19.3.0_@types+react@19.3.0__@types+react@19.3.0_re_62022f8c0abbfd4c405f5fb20b5aa9ec/node_modules/@hyperyai/sdk/dist/agents/core/context.js"() {
|
|
364594
365023
|
RENDER_TURN_PREFIX = "Result of ";
|
|
364595
365024
|
KEEP_IMAGE_TURNS = 2;
|
|
364596
|
-
sizeOf2 = (messages) => JSON.stringify(messages).length;
|
|
364597
|
-
isRenderTurn = (m) => m.role === "user" && Array.isArray(m.content) && m.content[0]?.type === "text" && !!m.content[0].text?.startsWith(RENDER_TURN_PREFIX);
|
|
364598
365025
|
}
|
|
364599
365026
|
});
|
|
364600
365027
|
|
|
364601
|
-
// node_modules/.pnpm/@hyperyai+sdk@1.
|
|
365028
|
+
// node_modules/.pnpm/@hyperyai+sdk@2.1.0_@types+react-dom@19.3.0_@types+react@19.3.0__@types+react@19.3.0_re_62022f8c0abbfd4c405f5fb20b5aa9ec/node_modules/@hyperyai/sdk/dist/agents/core/loop.js
|
|
364602
365029
|
function batchCalls(calls, isParallel, max3) {
|
|
364603
|
-
|
|
364604
|
-
|
|
364605
|
-
const
|
|
364606
|
-
|
|
364607
|
-
|
|
364608
|
-
last3.
|
|
364609
|
-
|
|
364610
|
-
|
|
365030
|
+
{
|
|
365031
|
+
let batches = [];
|
|
365032
|
+
for (const call2 of calls) {
|
|
365033
|
+
let last3 = batches.length > 0 ? batches[batches.length - 1] ?? null : null;
|
|
365034
|
+
let parallel = isParallel(call2.name) ?? null;
|
|
365035
|
+
if (parallel && last3 != null && last3.length < max3 && (isParallel((last3[0] ?? null).name) ?? null)) {
|
|
365036
|
+
last3.push(call2) ?? null;
|
|
365037
|
+
} else {
|
|
365038
|
+
batches.push([call2]) ?? null;
|
|
365039
|
+
}
|
|
365040
|
+
}
|
|
365041
|
+
return batches;
|
|
364611
365042
|
}
|
|
364612
|
-
return batches;
|
|
364613
365043
|
}
|
|
364614
365044
|
function truncateResult(text, max3) {
|
|
364615
|
-
|
|
364616
|
-
|
|
365045
|
+
{
|
|
365046
|
+
if (text.length <= max3) {
|
|
365047
|
+
return text;
|
|
365048
|
+
}
|
|
365049
|
+
return (text.slice(0, max3) ?? null) + "\n\u2026[truncated " + (String(text.length - max3) ?? null) + " characters]";
|
|
365050
|
+
}
|
|
364617
365051
|
}
|
|
364618
365052
|
function defaultIsRecoverable(err2) {
|
|
364619
|
-
|
|
364620
|
-
|
|
364621
|
-
|
|
364622
|
-
|
|
364623
|
-
|
|
364624
|
-
|
|
364625
|
-
|
|
365053
|
+
{
|
|
365054
|
+
if (err2 == null || ((__v) => __v == null ? "null" : typeof __v)(err2) !== "object") {
|
|
365055
|
+
return false;
|
|
365056
|
+
}
|
|
365057
|
+
if (((__v) => __v == null ? "null" : typeof __v)(err2.status) === "number") {
|
|
365058
|
+
return err2.status >= 500 || err2.status === 408 || err2.status === 429;
|
|
365059
|
+
}
|
|
365060
|
+
let text = ((String(err2.name ?? "") ?? null) + " " + (String(err2.code ?? "") ?? null) + " " + (String(err2.message ?? "") ?? null)).toLowerCase() ?? null;
|
|
365061
|
+
return RECOVERABLE_WORDS.some((w) => {
|
|
365062
|
+
{
|
|
365063
|
+
return text.includes(w) ?? null;
|
|
365064
|
+
}
|
|
365065
|
+
}) ?? null;
|
|
365066
|
+
}
|
|
365067
|
+
}
|
|
365068
|
+
function errorMessage(err2) {
|
|
365069
|
+
{
|
|
365070
|
+
if (err2 != null && ((__v) => __v == null ? "null" : typeof __v)(err2) === "object" && ((__v) => __v == null ? "null" : typeof __v)(err2.message) === "string") {
|
|
365071
|
+
return err2.message;
|
|
365072
|
+
}
|
|
365073
|
+
return String(err2) ?? null;
|
|
365074
|
+
}
|
|
365075
|
+
}
|
|
365076
|
+
function repairTranscript(messages) {
|
|
365077
|
+
{
|
|
365078
|
+
let i2 = 0;
|
|
365079
|
+
while (i2 < messages.length) {
|
|
365080
|
+
let m = messages[i2] ?? null;
|
|
365081
|
+
if (m.role === "assistant" && (Array.isArray(m.tool_calls) ?? null) && m.tool_calls.length > 0) {
|
|
365082
|
+
let j = i2 + 1;
|
|
365083
|
+
let answered = /* @__PURE__ */ new Set() ?? null;
|
|
365084
|
+
while (j < messages.length && (messages[j] ?? null).role === "tool") {
|
|
365085
|
+
answered.add((messages[j] ?? null).tool_call_id ?? "") ?? null;
|
|
365086
|
+
j = j + 1;
|
|
365087
|
+
}
|
|
365088
|
+
let missing = m.tool_calls.filter((c2) => {
|
|
365089
|
+
{
|
|
365090
|
+
return !(answered.has(c2.id) ?? null);
|
|
365091
|
+
}
|
|
365092
|
+
}) ?? null;
|
|
365093
|
+
if (missing.length > 0) {
|
|
365094
|
+
let fillers = missing.map((c2) => {
|
|
365095
|
+
{
|
|
365096
|
+
return { role: "tool", tool_call_id: c2.id, name: (c2["function"] ?? null).name, content: JSON.stringify({ error: "interrupted: this call did not finish (the session was interrupted). Check its effect and run it again if needed." }) ?? null };
|
|
365097
|
+
}
|
|
365098
|
+
}) ?? null;
|
|
365099
|
+
messages.splice(j, 0, ...fillers) ?? null;
|
|
365100
|
+
i2 = j + missing.length - 1;
|
|
365101
|
+
}
|
|
365102
|
+
}
|
|
365103
|
+
i2 = i2 + 1;
|
|
365104
|
+
}
|
|
365105
|
+
return messages;
|
|
365106
|
+
}
|
|
365107
|
+
}
|
|
365108
|
+
function hook(hooks, name2) {
|
|
365109
|
+
{
|
|
365110
|
+
if (hooks == null || ((__v) => __v == null ? "null" : typeof __v)(hooks) !== "object") {
|
|
365111
|
+
return null;
|
|
365112
|
+
}
|
|
365113
|
+
let h = hooks[name2] ?? null;
|
|
365114
|
+
return ((__v) => __v == null ? "null" : typeof __v)(h) === "function" ? h : null;
|
|
365115
|
+
}
|
|
364626
365116
|
}
|
|
364627
365117
|
async function runAgentLoop(opts) {
|
|
364628
|
-
|
|
364629
|
-
|
|
364630
|
-
|
|
364631
|
-
|
|
364632
|
-
|
|
364633
|
-
|
|
364634
|
-
|
|
364635
|
-
|
|
364636
|
-
|
|
364637
|
-
|
|
364638
|
-
|
|
364639
|
-
|
|
364640
|
-
|
|
364641
|
-
|
|
364642
|
-
|
|
364643
|
-
|
|
364644
|
-
|
|
364645
|
-
|
|
364646
|
-
|
|
364647
|
-
|
|
364648
|
-
|
|
364649
|
-
|
|
364650
|
-
|
|
364651
|
-
|
|
364652
|
-
|
|
364653
|
-
|
|
364654
|
-
onReasoningDelta: opts.hooks?.onReasoningDelta,
|
|
364655
|
-
onToolProgress: opts.hooks?.onToolProgress
|
|
364656
|
-
}, opts.signal);
|
|
364657
|
-
} catch (err2) {
|
|
364658
|
-
if (isStopped() || attempt >= retries || !recoverable(err2))
|
|
364659
|
-
throw err2;
|
|
365118
|
+
{
|
|
365119
|
+
let maxRounds = ((__v) => __v == null ? "null" : typeof __v)(opts.maxRounds) === "number" ? opts.maxRounds : DEFAULT_MAX_ROUNDS;
|
|
365120
|
+
let maxResultChars = ((__v) => __v == null ? "null" : typeof __v)(opts.maxResultChars) === "number" ? opts.maxResultChars : 8e3;
|
|
365121
|
+
let maxParallel = ((__v) => __v == null ? "null" : typeof __v)(opts.maxParallel) === "number" ? opts.maxParallel : DEFAULT_MAX_PARALLEL;
|
|
365122
|
+
let hooks = opts.hooks ?? null;
|
|
365123
|
+
let specs = opts.tools.map((t3) => {
|
|
365124
|
+
{
|
|
365125
|
+
return t3.spec;
|
|
365126
|
+
}
|
|
365127
|
+
}) ?? null;
|
|
365128
|
+
let parallelNames = new Set((opts.tools.filter((t3) => {
|
|
365129
|
+
{
|
|
365130
|
+
return t3.readOnly === true;
|
|
365131
|
+
}
|
|
365132
|
+
}) ?? null).map((t3) => {
|
|
365133
|
+
{
|
|
365134
|
+
return (t3.spec["function"] ?? null).name;
|
|
365135
|
+
}
|
|
365136
|
+
}) ?? null) ?? null;
|
|
365137
|
+
let actingNames = new Set((opts.tools.filter((t3) => {
|
|
365138
|
+
{
|
|
365139
|
+
return ((__v) => __v == null ? "null" : typeof __v)(t3.acts) === "boolean" ? t3.acts : t3.readOnly !== true;
|
|
365140
|
+
}
|
|
365141
|
+
}) ?? null).map((t3) => {
|
|
365142
|
+
{
|
|
365143
|
+
return (t3.spec["function"] ?? null).name;
|
|
364660
365144
|
}
|
|
365145
|
+
}) ?? null) ?? null;
|
|
365146
|
+
let require3 = null;
|
|
365147
|
+
if (opts.requireAction === true) {
|
|
365148
|
+
require3 = {};
|
|
364661
365149
|
}
|
|
364662
|
-
|
|
364663
|
-
|
|
364664
|
-
|
|
364665
|
-
|
|
364666
|
-
|
|
364667
|
-
|
|
364668
|
-
|
|
364669
|
-
|
|
364670
|
-
|
|
364671
|
-
|
|
364672
|
-
|
|
364673
|
-
|
|
364674
|
-
messages.push({
|
|
364675
|
-
role: "assistant",
|
|
364676
|
-
content: turn.text,
|
|
364677
|
-
...turn.toolCalls.length ? { tool_calls: turn.toolCalls.map((c2) => ({ id: c2.id, type: "function", function: { name: c2.name, arguments: c2.arguments } })) } : {}
|
|
364678
|
-
});
|
|
364679
|
-
if (!turn.toolCalls.length) {
|
|
364680
|
-
opts.hooks?.onRoundEnd?.(round5);
|
|
364681
|
-
const late = opts.drainNotifications?.() ?? [];
|
|
364682
|
-
if (late.length) {
|
|
364683
|
-
for (const note2 of late)
|
|
364684
|
-
messages.push({ role: "user", content: note2 });
|
|
364685
|
-
continue;
|
|
365150
|
+
if (opts.requireAction != null && ((__v) => __v == null ? "null" : typeof __v)(opts.requireAction) === "object") {
|
|
365151
|
+
require3 = opts.requireAction;
|
|
365152
|
+
}
|
|
365153
|
+
let resume = opts.resumeState ?? {};
|
|
365154
|
+
let nudgesLeft = ((__v) => __v == null ? "null" : typeof __v)(resume.nudgesLeft) === "number" ? resume.nudgesLeft : require3 != null ? ((__v) => __v == null ? "null" : typeof __v)(require3.nudges) === "number" ? require3.nudges : 2 : 0;
|
|
365155
|
+
let signal = opts.signal ?? null;
|
|
365156
|
+
let isStopped = () => {
|
|
365157
|
+
{
|
|
365158
|
+
if (signal != null && signal.aborted === true) {
|
|
365159
|
+
return true;
|
|
365160
|
+
}
|
|
365161
|
+
return ((__v) => __v == null ? "null" : typeof __v)(opts.stopped) === "function" && (opts.stopped() ?? null) === true;
|
|
364686
365162
|
}
|
|
364687
|
-
|
|
364688
|
-
|
|
364689
|
-
|
|
364690
|
-
|
|
364691
|
-
|
|
364692
|
-
|
|
364693
|
-
|
|
365163
|
+
};
|
|
365164
|
+
let messages = repairTranscript(opts.messages.slice() ?? null) ?? null;
|
|
365165
|
+
let text = "";
|
|
365166
|
+
let acted = resume.acted === true;
|
|
365167
|
+
let retries = ((__v) => __v == null ? "null" : typeof __v)(opts.modelRetries) === "number" ? opts.modelRetries : 2;
|
|
365168
|
+
let recoverable = ((__v) => __v == null ? "null" : typeof __v)(opts.isRecoverable) === "function" ? opts.isRecoverable : defaultIsRecoverable;
|
|
365169
|
+
let ctx2 = opts.context ?? {};
|
|
365170
|
+
let maxRequestChars = ((__v) => __v == null ? "null" : typeof __v)(ctx2.maxRequestChars) === "number" ? ctx2.maxRequestChars : 43e5;
|
|
365171
|
+
let save = async (round6, done) => {
|
|
365172
|
+
{
|
|
365173
|
+
if (((__v) => __v == null ? "null" : typeof __v)(opts.checkpoint) === "function") {
|
|
365174
|
+
await (opts.checkpoint({ messages: messages.slice() ?? null, round: round6, acted, nudgesLeft, done }) ?? null);
|
|
365175
|
+
}
|
|
364694
365176
|
}
|
|
364695
|
-
|
|
364696
|
-
|
|
364697
|
-
|
|
364698
|
-
|
|
364699
|
-
|
|
364700
|
-
for (const batch of batchCalls(calls, (n) => parallelNames.has(n), opts.maxParallel ?? DEFAULT_MAX_PARALLEL)) {
|
|
364701
|
-
if (isStopped()) {
|
|
364702
|
-
for (const c2 of calls)
|
|
364703
|
-
if (!messages.some((m) => m.role === "tool" && m.tool_call_id === c2.id))
|
|
364704
|
-
messages.push({ role: "tool", tool_call_id: c2.id, name: c2.name, content: JSON.stringify({ error: "stopped" }) });
|
|
364705
|
-
await save(round5 + 1, true);
|
|
364706
|
-
return { messages, text, rounds: round5 + 1, exhausted: false, stopped: true, acted };
|
|
364707
|
-
}
|
|
364708
|
-
for (const info2 of batch)
|
|
364709
|
-
opts.hooks?.onToolStart?.(info2);
|
|
364710
|
-
const runs = await Promise.all(batch.map(async (info2) => {
|
|
364711
|
-
try {
|
|
364712
|
-
return await opts.execTool(info2);
|
|
364713
|
-
} catch (err2) {
|
|
364714
|
-
const message = err2?.message ?? String(err2);
|
|
364715
|
-
return { ...info2, ok: false, summary: message, content: JSON.stringify({ error: message }) };
|
|
365177
|
+
};
|
|
365178
|
+
let drain = () => {
|
|
365179
|
+
{
|
|
365180
|
+
if (((__v) => __v == null ? "null" : typeof __v)(opts.drainNotifications) !== "function") {
|
|
365181
|
+
return [];
|
|
364716
365182
|
}
|
|
364717
|
-
|
|
364718
|
-
|
|
364719
|
-
|
|
364720
|
-
|
|
364721
|
-
|
|
364722
|
-
|
|
364723
|
-
|
|
364724
|
-
|
|
364725
|
-
|
|
364726
|
-
|
|
364727
|
-
{ type: "text", text: `${RENDER_TURN_PREFIX2}${run4.name}: ${run4.images.length === 1 ? "the rendered view" : `${run4.images.length} rendered views`}.` },
|
|
364728
|
-
...run4.images.map((url4) => ({ type: "image_url", image_url: { url: url4 } }))
|
|
364729
|
-
]
|
|
364730
|
-
});
|
|
365183
|
+
let notes = opts.drainNotifications() ?? null;
|
|
365184
|
+
return Array.isArray(notes) ?? null ? notes : [];
|
|
365185
|
+
}
|
|
365186
|
+
};
|
|
365187
|
+
let modelHooks = { onTextDelta: hook(hooks, "onTextDelta") ?? null, onReasoningDelta: hook(hooks, "onReasoningDelta") ?? null, onToolProgress: hook(hooks, "onToolProgress") ?? null };
|
|
365188
|
+
let choiceFor = (round6) => {
|
|
365189
|
+
{
|
|
365190
|
+
let c2 = opts.toolChoice ?? null;
|
|
365191
|
+
if (((__v) => __v == null ? "null" : typeof __v)(c2) === "function") {
|
|
365192
|
+
c2 = c2(round6) ?? null ?? null;
|
|
364731
365193
|
}
|
|
365194
|
+
return c2;
|
|
364732
365195
|
}
|
|
365196
|
+
};
|
|
365197
|
+
let call2 = async (msgs, tools, choice) => {
|
|
365198
|
+
{
|
|
365199
|
+
let attempt = 0;
|
|
365200
|
+
while (true) {
|
|
365201
|
+
try {
|
|
365202
|
+
{
|
|
365203
|
+
if (choice == null || tools.length === 0) {
|
|
365204
|
+
return await (opts.callModel(msgs, tools, modelHooks, signal) ?? null);
|
|
365205
|
+
}
|
|
365206
|
+
return await (opts.callModel(msgs, tools, modelHooks, signal, { toolChoice: choice }) ?? null);
|
|
365207
|
+
}
|
|
365208
|
+
} catch (err2) {
|
|
365209
|
+
{
|
|
365210
|
+
if ((isStopped() ?? null) || attempt >= retries || !(recoverable(err2) ?? null)) {
|
|
365211
|
+
throw err2;
|
|
365212
|
+
}
|
|
365213
|
+
}
|
|
365214
|
+
}
|
|
365215
|
+
attempt = attempt + 1;
|
|
365216
|
+
}
|
|
365217
|
+
}
|
|
365218
|
+
};
|
|
365219
|
+
let round5 = ((__v) => __v == null ? "null" : typeof __v)(resume.round) === "number" ? resume.round : 0;
|
|
365220
|
+
while (maxRounds === 0 || round5 < maxRounds) {
|
|
365221
|
+
if (isStopped() ?? null) {
|
|
365222
|
+
await (save(round5, true) ?? null);
|
|
365223
|
+
return { messages, text, rounds: round5, exhausted: false, stopped: true, acted };
|
|
365224
|
+
}
|
|
365225
|
+
for (const note2 of drain() ?? null) {
|
|
365226
|
+
messages.push({ role: "user", content: note2 }) ?? null;
|
|
365227
|
+
}
|
|
365228
|
+
pruneOldImages(messages, ctx2.keepImageTurns ?? null) ?? null;
|
|
365229
|
+
if (ctx2.compact != null && ((__v) => __v == null ? "null" : typeof __v)(ctx2.compact) === "object") {
|
|
365230
|
+
await (compactTranscript(messages, ctx2.compact) ?? null);
|
|
365231
|
+
}
|
|
365232
|
+
fitImagesToBudget(messages, maxRequestChars - (JSON.stringify(specs) ?? null).length) ?? null;
|
|
365233
|
+
let onStart = hook(hooks, "onAssistantStart") ?? null;
|
|
365234
|
+
if (onStart != null) {
|
|
365235
|
+
onStart(round5) ?? null;
|
|
365236
|
+
}
|
|
365237
|
+
let turn = await (call2(messages, specs, choiceFor(round5) ?? null) ?? null);
|
|
365238
|
+
text = turn.text;
|
|
365239
|
+
let toolCalls = Array.isArray(turn.toolCalls) ?? null ? turn.toolCalls : [];
|
|
365240
|
+
if (toolCalls.length > 0) {
|
|
365241
|
+
messages.push({ role: "assistant", content: turn.text, tool_calls: toolCalls.map((c2) => {
|
|
365242
|
+
{
|
|
365243
|
+
return { id: c2.id, type: "function", function: { name: c2.name, arguments: c2.arguments } };
|
|
365244
|
+
}
|
|
365245
|
+
}) ?? null }) ?? null;
|
|
365246
|
+
} else {
|
|
365247
|
+
messages.push({ role: "assistant", content: turn.text }) ?? null;
|
|
365248
|
+
}
|
|
365249
|
+
if (toolCalls.length === 0) {
|
|
365250
|
+
let onEnd = hook(hooks, "onRoundEnd") ?? null;
|
|
365251
|
+
if (onEnd != null) {
|
|
365252
|
+
onEnd(round5) ?? null;
|
|
365253
|
+
}
|
|
365254
|
+
let late = drain() ?? null;
|
|
365255
|
+
if (late.length > 0) {
|
|
365256
|
+
for (const note2 of late) {
|
|
365257
|
+
messages.push({ role: "user", content: note2 }) ?? null;
|
|
365258
|
+
}
|
|
365259
|
+
round5 = round5 + 1;
|
|
365260
|
+
continue;
|
|
365261
|
+
}
|
|
365262
|
+
if (require3 != null && !acted && nudgesLeft > 0 && actingNames.size > 0) {
|
|
365263
|
+
nudgesLeft = nudgesLeft - 1;
|
|
365264
|
+
let nudge = ((__v) => __v == null ? "null" : typeof __v)(require3.message) === "string" ? require3.message : DEFAULT_ACTION_NUDGE;
|
|
365265
|
+
let onNudge = hook(hooks, "onNudge") ?? null;
|
|
365266
|
+
if (onNudge != null) {
|
|
365267
|
+
onNudge(nudge) ?? null;
|
|
365268
|
+
}
|
|
365269
|
+
messages.push({ role: "user", content: nudge }) ?? null;
|
|
365270
|
+
await (save(round5 + 1, false) ?? null);
|
|
365271
|
+
round5 = round5 + 1;
|
|
365272
|
+
continue;
|
|
365273
|
+
}
|
|
365274
|
+
await (save(round5 + 1, true) ?? null);
|
|
365275
|
+
return { messages, text, rounds: round5 + 1, exhausted: false, stopped: false, acted };
|
|
365276
|
+
}
|
|
365277
|
+
let calls = toolCalls.map((c2) => {
|
|
365278
|
+
{
|
|
365279
|
+
return { id: c2.id, name: c2.name, argsText: c2.arguments };
|
|
365280
|
+
}
|
|
365281
|
+
}) ?? null;
|
|
365282
|
+
let imageTurns = [];
|
|
365283
|
+
for (const batch of batchCalls(calls, (n) => {
|
|
365284
|
+
{
|
|
365285
|
+
return parallelNames.has(n) ?? null;
|
|
365286
|
+
}
|
|
365287
|
+
}, maxParallel) ?? null) {
|
|
365288
|
+
if (isStopped() ?? null) {
|
|
365289
|
+
for (const c2 of calls) {
|
|
365290
|
+
let answered = messages.some((m) => {
|
|
365291
|
+
{
|
|
365292
|
+
return m.role === "tool" && m.tool_call_id === c2.id;
|
|
365293
|
+
}
|
|
365294
|
+
}) ?? null;
|
|
365295
|
+
if (!answered) {
|
|
365296
|
+
messages.push({ role: "tool", tool_call_id: c2.id, name: c2.name, content: JSON.stringify({ error: "stopped" }) ?? null }) ?? null;
|
|
365297
|
+
}
|
|
365298
|
+
}
|
|
365299
|
+
await (save(round5 + 1, true) ?? null);
|
|
365300
|
+
return { messages, text, rounds: round5 + 1, exhausted: false, stopped: true, acted };
|
|
365301
|
+
}
|
|
365302
|
+
let onToolStart = hook(hooks, "onToolStart") ?? null;
|
|
365303
|
+
if (onToolStart != null) {
|
|
365304
|
+
for (const info2 of batch) {
|
|
365305
|
+
onToolStart(info2) ?? null;
|
|
365306
|
+
}
|
|
365307
|
+
}
|
|
365308
|
+
let runs = await (Promise.all(batch.map(async (info2) => {
|
|
365309
|
+
{
|
|
365310
|
+
try {
|
|
365311
|
+
{
|
|
365312
|
+
return await (opts.execTool(info2) ?? null);
|
|
365313
|
+
}
|
|
365314
|
+
} catch (err2) {
|
|
365315
|
+
{
|
|
365316
|
+
let message = errorMessage(err2) ?? null;
|
|
365317
|
+
return { id: info2.id, name: info2.name, argsText: info2.argsText, ok: false, summary: message, content: JSON.stringify({ error: message }) ?? null };
|
|
365318
|
+
}
|
|
365319
|
+
}
|
|
365320
|
+
}
|
|
365321
|
+
}) ?? null) ?? null);
|
|
365322
|
+
let onToolEnd = hook(hooks, "onToolEnd") ?? null;
|
|
365323
|
+
for (const run4 of runs) {
|
|
365324
|
+
let actedHere = ((__v) => __v == null ? "null" : typeof __v)(run4.acted) === "boolean" ? run4.acted : actingNames.has(run4.name) ?? null;
|
|
365325
|
+
if (run4.ok === true && actedHere) {
|
|
365326
|
+
acted = true;
|
|
365327
|
+
}
|
|
365328
|
+
if (onToolEnd != null) {
|
|
365329
|
+
onToolEnd(run4) ?? null;
|
|
365330
|
+
}
|
|
365331
|
+
messages.push({ role: "tool", tool_call_id: run4.id, name: run4.name, content: truncateResult(run4.content, maxResultChars) ?? null }) ?? null;
|
|
365332
|
+
if ((Array.isArray(run4.images) ?? null) && run4.images.length > 0) {
|
|
365333
|
+
let label3 = run4.images.length === 1 ? "the rendered view" : (String(run4.images.length) ?? null) + " rendered views";
|
|
365334
|
+
let parts = [{ type: "text", text: RENDER_TURN_PREFIX2 + run4.name + ": " + label3 + "." }];
|
|
365335
|
+
for (const url4 of run4.images) {
|
|
365336
|
+
parts.push({ type: "image_url", image_url: { url: url4 } }) ?? null;
|
|
365337
|
+
}
|
|
365338
|
+
imageTurns.push({ role: "user", content: parts }) ?? null;
|
|
365339
|
+
}
|
|
365340
|
+
}
|
|
365341
|
+
}
|
|
365342
|
+
for (const m of imageTurns) {
|
|
365343
|
+
messages.push(m) ?? null;
|
|
365344
|
+
}
|
|
365345
|
+
let onRoundEnd = hook(hooks, "onRoundEnd") ?? null;
|
|
365346
|
+
if (onRoundEnd != null) {
|
|
365347
|
+
onRoundEnd(round5) ?? null;
|
|
365348
|
+
}
|
|
365349
|
+
await (save(round5 + 1, false) ?? null);
|
|
365350
|
+
round5 = round5 + 1;
|
|
364733
365351
|
}
|
|
364734
|
-
for
|
|
364735
|
-
|
|
364736
|
-
|
|
364737
|
-
await save(
|
|
365352
|
+
messages.push({ role: "user", content: "You have reached the tool limit for this turn. Summarise what you changed and what is left, without calling more tools." }) ?? null;
|
|
365353
|
+
let final = await (call2(messages, [], null) ?? null);
|
|
365354
|
+
messages.push({ role: "assistant", content: final.text }) ?? null;
|
|
365355
|
+
await (save(maxRounds, true) ?? null);
|
|
365356
|
+
return { messages, text: final.text, rounds: maxRounds, exhausted: true, stopped: false, acted };
|
|
364738
365357
|
}
|
|
364739
|
-
messages.push({ role: "user", content: "You have reached the tool limit for this turn. Summarise what you changed and what is left, without calling more tools." });
|
|
364740
|
-
const final = await call2(messages, []);
|
|
364741
|
-
messages.push({ role: "assistant", content: final.text });
|
|
364742
|
-
await save(maxRounds, true);
|
|
364743
|
-
return { messages, text: final.text, rounds: maxRounds, exhausted: true, stopped: false, acted };
|
|
364744
365358
|
}
|
|
364745
|
-
|
|
364746
|
-
for (let i2 = 0; i2 < messages.length; i2++) {
|
|
364747
|
-
const m = messages[i2];
|
|
364748
|
-
if (m.role !== "assistant" || !m.tool_calls?.length)
|
|
364749
|
-
continue;
|
|
364750
|
-
let j = i2 + 1;
|
|
364751
|
-
const answered = /* @__PURE__ */ new Set();
|
|
364752
|
-
while (j < messages.length && messages[j].role === "tool") {
|
|
364753
|
-
answered.add(messages[j].tool_call_id ?? "");
|
|
364754
|
-
j++;
|
|
364755
|
-
}
|
|
364756
|
-
const missing = m.tool_calls.filter((c2) => !answered.has(c2.id));
|
|
364757
|
-
if (!missing.length)
|
|
364758
|
-
continue;
|
|
364759
|
-
messages.splice(j, 0, ...missing.map((c2) => ({
|
|
364760
|
-
role: "tool",
|
|
364761
|
-
tool_call_id: c2.id,
|
|
364762
|
-
name: c2.function.name,
|
|
364763
|
-
content: JSON.stringify({ error: "interrupted: this call did not finish (the session was interrupted). Check its effect and run it again if needed." })
|
|
364764
|
-
})));
|
|
364765
|
-
i2 = j + missing.length - 1;
|
|
364766
|
-
}
|
|
364767
|
-
return messages;
|
|
364768
|
-
}
|
|
364769
|
-
var DEFAULT_MAX_ROUNDS, DEFAULT_MAX_PARALLEL, DEFAULT_ACTION_NUDGE, RENDER_TURN_PREFIX2;
|
|
365359
|
+
var DEFAULT_MAX_ROUNDS, DEFAULT_MAX_PARALLEL, DEFAULT_ACTION_NUDGE, RENDER_TURN_PREFIX2, RECOVERABLE_WORDS;
|
|
364770
365360
|
var init_loop = __esm({
|
|
364771
|
-
"node_modules/.pnpm/@hyperyai+sdk@1.
|
|
365361
|
+
"node_modules/.pnpm/@hyperyai+sdk@2.1.0_@types+react-dom@19.3.0_@types+react@19.3.0__@types+react@19.3.0_re_62022f8c0abbfd4c405f5fb20b5aa9ec/node_modules/@hyperyai/sdk/dist/agents/core/loop.js"() {
|
|
364772
365362
|
init_context2();
|
|
364773
365363
|
DEFAULT_MAX_ROUNDS = 40;
|
|
364774
365364
|
DEFAULT_MAX_PARALLEL = 4;
|
|
364775
365365
|
DEFAULT_ACTION_NUDGE = "You have not changed anything yet. Stop reading and do what was asked now, with the tools that make changes. If you truly cannot, say exactly what is blocking you.";
|
|
364776
365366
|
RENDER_TURN_PREFIX2 = "Result of ";
|
|
365367
|
+
RECOVERABLE_WORDS = ["timeout", "timed out", "stalled", "network", "fetch failed", "econnreset", "socket", "stream"];
|
|
364777
365368
|
}
|
|
364778
365369
|
});
|
|
364779
365370
|
|
|
364780
|
-
// node_modules/.pnpm/@hyperyai+sdk@1.
|
|
364781
|
-
|
|
364782
|
-
|
|
364783
|
-
|
|
364784
|
-
|
|
364785
|
-
|
|
364786
|
-
|
|
364787
|
-
|
|
364788
|
-
|
|
364789
|
-
|
|
364790
|
-
|
|
364791
|
-
|
|
364792
|
-
name: REPORT_TOOL,
|
|
364793
|
-
description: "Send the main agent a progress update, or a question (set question) when you need a decision you cannot make yourself. It arrives between its steps and it answers with a message you read at your next step \u2014 keep working on what you can meanwhile. Your final answer still goes back by itself when you finish.",
|
|
364794
|
-
parameters: { type: "object", properties: { message: { type: "string", description: "What to tell the main agent." }, question: { type: "boolean", description: "This needs an answer." } }, required: ["message"] }
|
|
364795
|
-
}
|
|
364796
|
-
}
|
|
364797
|
-
};
|
|
364798
|
-
AgentRuntime = class {
|
|
364799
|
-
constructor(host) {
|
|
364800
|
-
this.host = host;
|
|
364801
|
-
this.sessions = /* @__PURE__ */ new Map();
|
|
364802
|
-
this.controllers = /* @__PURE__ */ new Map();
|
|
364803
|
-
this.parentQueue = [];
|
|
364804
|
-
this.loaded = null;
|
|
364805
|
-
this.waiting = [];
|
|
364806
|
-
this.activeBackground = 0;
|
|
364807
|
-
this.listeners = /* @__PURE__ */ new Set();
|
|
364808
|
-
this.pendingSaves = /* @__PURE__ */ new Set();
|
|
364809
|
-
}
|
|
364810
|
-
/** Bring back the store's sessions (any left "running" by a reload are marked stopped: their run is gone). */
|
|
364811
|
-
load() {
|
|
364812
|
-
this.loaded ?? (this.loaded = (async () => {
|
|
364813
|
-
for (const s of await this.host.store?.load() ?? []) {
|
|
364814
|
-
if (s.status === "running")
|
|
364815
|
-
Object.assign(s, { status: "stopped", endedAt: s.endedAt ?? this.now() });
|
|
364816
|
-
this.sessions.set(s.id, s);
|
|
364817
|
-
}
|
|
364818
|
-
this.changed();
|
|
364819
|
-
})());
|
|
364820
|
-
return this.loaded;
|
|
364821
|
-
}
|
|
364822
|
-
/** Wait until every session change has reached the store (before a process exits or a page unloads). */
|
|
364823
|
-
async flush() {
|
|
364824
|
-
while (this.pendingSaves.size)
|
|
364825
|
-
await Promise.all([...this.pendingSaves]);
|
|
364826
|
-
}
|
|
364827
|
-
/** Called whenever sessions change (spawned, queued, finished, messaged, stopped). Returns the unsubscribe. */
|
|
364828
|
-
subscribe(fn) {
|
|
364829
|
-
this.listeners.add(fn);
|
|
364830
|
-
return () => {
|
|
364831
|
-
this.listeners.delete(fn);
|
|
364832
|
-
};
|
|
364833
|
-
}
|
|
364834
|
-
list() {
|
|
364835
|
-
return [...this.sessions.values()].sort((a, b) => a.startedAt - b.startedAt);
|
|
364836
|
-
}
|
|
364837
|
-
get(id3) {
|
|
364838
|
-
return this.sessions.get(id3);
|
|
365371
|
+
// node_modules/.pnpm/@hyperyai+sdk@2.1.0_@types+react-dom@19.3.0_@types+react@19.3.0__@types+react@19.3.0_re_62022f8c0abbfd4c405f5fb20b5aa9ec/node_modules/@hyperyai/sdk/dist/agents/core/runtime.js
|
|
365372
|
+
function isBusy(s) {
|
|
365373
|
+
{
|
|
365374
|
+
return s != null && (s.status === "running" || s.status === "queued");
|
|
365375
|
+
}
|
|
365376
|
+
}
|
|
365377
|
+
function plainStopControl() {
|
|
365378
|
+
{
|
|
365379
|
+
let flag = { aborted: false };
|
|
365380
|
+
return { signal: flag, stop: () => {
|
|
365381
|
+
{
|
|
365382
|
+
flag.aborted = true;
|
|
364839
365383
|
}
|
|
364840
|
-
|
|
364841
|
-
|
|
364842
|
-
|
|
364843
|
-
|
|
364844
|
-
|
|
364845
|
-
|
|
364846
|
-
|
|
364847
|
-
|
|
364848
|
-
|
|
364849
|
-
|
|
364850
|
-
|
|
364851
|
-
|
|
364852
|
-
|
|
364853
|
-
|
|
364854
|
-
|
|
364855
|
-
|
|
364856
|
-
|
|
364857
|
-
|
|
364858
|
-
|
|
364859
|
-
|
|
364860
|
-
|
|
364861
|
-
|
|
365384
|
+
} };
|
|
365385
|
+
}
|
|
365386
|
+
}
|
|
365387
|
+
function allSessions(sessions) {
|
|
365388
|
+
{
|
|
365389
|
+
let out = [];
|
|
365390
|
+
for (const s of sessions.values() ?? null) {
|
|
365391
|
+
out.push(s) ?? null;
|
|
365392
|
+
}
|
|
365393
|
+
return out;
|
|
365394
|
+
}
|
|
365395
|
+
}
|
|
365396
|
+
function errorMessage2(err2) {
|
|
365397
|
+
{
|
|
365398
|
+
if (err2 != null && ((__v) => __v == null ? "null" : typeof __v)(err2) === "object" && ((__v) => __v == null ? "null" : typeof __v)(err2.message) === "string") {
|
|
365399
|
+
return err2.message;
|
|
365400
|
+
}
|
|
365401
|
+
return String(err2) ?? null;
|
|
365402
|
+
}
|
|
365403
|
+
}
|
|
365404
|
+
function createAgentRuntime(host) {
|
|
365405
|
+
{
|
|
365406
|
+
let sessions = /* @__PURE__ */ new Map() ?? null;
|
|
365407
|
+
let controls = /* @__PURE__ */ new Map() ?? null;
|
|
365408
|
+
let parentQueue = [];
|
|
365409
|
+
let loaded2 = false;
|
|
365410
|
+
let loading3 = null;
|
|
365411
|
+
let active3 = 0;
|
|
365412
|
+
let waiting3 = [];
|
|
365413
|
+
let listeners8 = [];
|
|
365414
|
+
let pendingSaves = 0;
|
|
365415
|
+
let maxConcurrent = ((__v) => __v == null ? "null" : typeof __v)(host.maxConcurrent) === "number" ? host.maxConcurrent : 4;
|
|
365416
|
+
let now2 = () => {
|
|
365417
|
+
{
|
|
365418
|
+
return ((__v) => __v == null ? "null" : typeof __v)(host.now) === "function" ? host.now() ?? null : Date.now() ?? null;
|
|
364862
365419
|
}
|
|
364863
|
-
|
|
364864
|
-
|
|
364865
|
-
|
|
364866
|
-
|
|
364867
|
-
|
|
364868
|
-
}
|
|
364869
|
-
/** Everything queued for the parent (reports, finished background children), taken. */
|
|
364870
|
-
drainParentNotifications() {
|
|
364871
|
-
return this.parentQueue.splice(0, this.parentQueue.length);
|
|
364872
|
-
}
|
|
364873
|
-
hasPendingNotifications() {
|
|
364874
|
-
return this.parentQueue.length > 0;
|
|
364875
|
-
}
|
|
364876
|
-
async spawn(req) {
|
|
364877
|
-
const profile = this.host.profiles().find((p2) => p2.id === req.profileId);
|
|
364878
|
-
if (!profile)
|
|
364879
|
-
return { kind: "refused", reason: `No agent type "${req.profileId}". Available: ${this.host.profiles().map((p2) => p2.id).join(", ")}.` };
|
|
364880
|
-
const prompt2 = req.prompt?.trim();
|
|
364881
|
-
if (!prompt2)
|
|
364882
|
-
return { kind: "refused", reason: "A task needs a self-contained prompt \u2014 the agent cannot see this conversation." };
|
|
364883
|
-
const background = req.background ?? profile.background ?? false;
|
|
364884
|
-
const session3 = {
|
|
364885
|
-
id: this.host.newId?.() ?? `agent-${this.now().toString(36)}-${Math.random().toString(36).slice(2, 7)}`,
|
|
364886
|
-
profile: profile.id,
|
|
364887
|
-
description: req.description ?? prompt2.slice(0, 80),
|
|
364888
|
-
status: "running",
|
|
364889
|
-
background,
|
|
364890
|
-
transcript: [],
|
|
364891
|
-
inbox: [],
|
|
364892
|
-
startedAt: this.now(),
|
|
364893
|
-
rounds: 0,
|
|
364894
|
-
readOnly: req.readOnly === true || profile.readOnly === true,
|
|
364895
|
-
...req.parentCallId ? { parentCallId: req.parentCallId } : {}
|
|
364896
|
-
};
|
|
364897
|
-
this.sessions.set(session3.id, session3);
|
|
364898
|
-
this.changed();
|
|
364899
|
-
this.emit({ type: "session", sessionId: session3.id, status: "running", profile: session3.profile, description: session3.description });
|
|
364900
|
-
if (background) {
|
|
364901
|
-
void this.slot(session3).then(async () => {
|
|
364902
|
-
try {
|
|
364903
|
-
if (session3.status !== "stopped")
|
|
364904
|
-
await this.run(session3, profile, prompt2, req.readOnly === true, req.signal, true);
|
|
364905
|
-
} finally {
|
|
364906
|
-
this.release();
|
|
364907
|
-
}
|
|
364908
|
-
}).catch(() => {
|
|
364909
|
-
});
|
|
364910
|
-
return { kind: "started", id: session3.id };
|
|
365420
|
+
};
|
|
365421
|
+
let changed = () => {
|
|
365422
|
+
{
|
|
365423
|
+
if (((__v) => __v == null ? "null" : typeof __v)(host.onChange) === "function") {
|
|
365424
|
+
host.onChange() ?? null;
|
|
364911
365425
|
}
|
|
364912
|
-
const
|
|
364913
|
-
|
|
364914
|
-
return { kind: "done", id: session3.id, ok: out.ok, summary: out.summary, rounds: out.rounds };
|
|
364915
|
-
}
|
|
364916
|
-
/**
|
|
364917
|
-
* Message a child. Running: queued for its next round. Finished: resumed with its whole context and this message —
|
|
364918
|
-
* in the background (its answer reaches the parent as a notification) unless `wait` is set.
|
|
364919
|
-
*/
|
|
364920
|
-
async message(id3, text, opts = {}) {
|
|
364921
|
-
await this.load();
|
|
364922
|
-
const session3 = this.sessions.get(id3);
|
|
364923
|
-
if (!session3)
|
|
364924
|
-
return { kind: "unknown", id: id3 };
|
|
364925
|
-
if (session3.status === "running") {
|
|
364926
|
-
session3.inbox.push(text);
|
|
364927
|
-
this.persist(session3);
|
|
364928
|
-
return { kind: "queued", id: id3 };
|
|
365426
|
+
for (const l of listeners8.slice() ?? null) {
|
|
365427
|
+
l() ?? null;
|
|
364929
365428
|
}
|
|
364930
|
-
|
|
364931
|
-
|
|
364932
|
-
|
|
364933
|
-
|
|
364934
|
-
|
|
364935
|
-
|
|
364936
|
-
void this.slot(session3).then(async () => {
|
|
364937
|
-
try {
|
|
364938
|
-
if (session3.status !== "stopped")
|
|
364939
|
-
await this.run(session3, profile, text, false, opts.signal, false);
|
|
364940
|
-
} finally {
|
|
364941
|
-
this.release();
|
|
364942
|
-
}
|
|
364943
|
-
}).catch(() => {
|
|
364944
|
-
});
|
|
364945
|
-
return { kind: "resumed", id: id3 };
|
|
365429
|
+
}
|
|
365430
|
+
};
|
|
365431
|
+
let emit6 = (e) => {
|
|
365432
|
+
{
|
|
365433
|
+
if (((__v) => __v == null ? "null" : typeof __v)(host.onEvent) === "function") {
|
|
365434
|
+
host.onEvent(e) ?? null;
|
|
364946
365435
|
}
|
|
364947
|
-
const out = await this.run(session3, profile, text, false, opts.signal, false);
|
|
364948
|
-
return { kind: "done", id: id3, ok: out.ok, summary: out.summary };
|
|
364949
365436
|
}
|
|
364950
|
-
|
|
364951
|
-
|
|
364952
|
-
|
|
364953
|
-
|
|
364954
|
-
return false;
|
|
364955
|
-
this.controllers.get(id3)?.abort();
|
|
364956
|
-
Object.assign(session3, { status: "stopped", endedAt: this.now() });
|
|
364957
|
-
this.persist(session3);
|
|
364958
|
-
return true;
|
|
365437
|
+
};
|
|
365438
|
+
let sessionEvent = (s) => {
|
|
365439
|
+
{
|
|
365440
|
+
emit6({ type: "session", sessionId: s.id, status: s.status, profile: s.profile, description: s.description }) ?? null;
|
|
364959
365441
|
}
|
|
364960
|
-
|
|
364961
|
-
|
|
364962
|
-
|
|
364963
|
-
|
|
364964
|
-
|
|
364965
|
-
}
|
|
364966
|
-
/** A child's report to the parent (also what `report_to_parent` does). A question asks for an answer. */
|
|
364967
|
-
report(fromId, text, question = false) {
|
|
364968
|
-
const s = this.sessions.get(fromId);
|
|
364969
|
-
const who = `agent ${fromId}${s ? ` (${s.profile})` : ""}`;
|
|
364970
|
-
this.parentQueue.push(question ? `QUESTION from ${who} \u2014 it needs your answer (send_message ${fromId}):
|
|
364971
|
-
${text}` : `Report from ${who}:
|
|
364972
|
-
${text}`);
|
|
364973
|
-
this.emit({ type: "report", sessionId: fromId, message: text, question });
|
|
364974
|
-
this.changed();
|
|
364975
|
-
}
|
|
364976
|
-
/** Take a background slot (maxConcurrent); the session shows 'queued' while it waits. */
|
|
364977
|
-
async slot(session3) {
|
|
364978
|
-
const max3 = this.host.maxConcurrent ?? 4;
|
|
364979
|
-
if (this.activeBackground < max3) {
|
|
364980
|
-
this.activeBackground++;
|
|
365442
|
+
};
|
|
365443
|
+
let persist3 = (s) => {
|
|
365444
|
+
{
|
|
365445
|
+
changed() ?? null;
|
|
365446
|
+
if (host.store == null || ((__v) => __v == null ? "null" : typeof __v)(host.store) !== "object") {
|
|
364981
365447
|
return;
|
|
364982
365448
|
}
|
|
364983
|
-
|
|
364984
|
-
|
|
364985
|
-
|
|
364986
|
-
|
|
364987
|
-
|
|
364988
|
-
|
|
364989
|
-
|
|
364990
|
-
|
|
364991
|
-
|
|
364992
|
-
|
|
364993
|
-
|
|
364994
|
-
|
|
364995
|
-
|
|
364996
|
-
|
|
365449
|
+
pendingSaves = pendingSaves + 1;
|
|
365450
|
+
let save = async () => {
|
|
365451
|
+
{
|
|
365452
|
+
try {
|
|
365453
|
+
{
|
|
365454
|
+
await (host.store.save(s) ?? null);
|
|
365455
|
+
}
|
|
365456
|
+
} catch (e) {
|
|
365457
|
+
{
|
|
365458
|
+
}
|
|
365459
|
+
}
|
|
365460
|
+
pendingSaves = pendingSaves - 1;
|
|
365461
|
+
}
|
|
365462
|
+
};
|
|
365463
|
+
save() ?? null;
|
|
365464
|
+
}
|
|
365465
|
+
};
|
|
365466
|
+
let profileById = (id3) => {
|
|
365467
|
+
{
|
|
365468
|
+
let found = (host.profiles() ?? null).filter((p2) => {
|
|
365469
|
+
{
|
|
365470
|
+
return p2.id === id3;
|
|
365471
|
+
}
|
|
365472
|
+
}) ?? null;
|
|
365473
|
+
return found.length > 0 ? found[0] ?? null : null;
|
|
364997
365474
|
}
|
|
364998
|
-
|
|
364999
|
-
|
|
365475
|
+
};
|
|
365476
|
+
let report2 = (fromId, text, question) => {
|
|
365477
|
+
{
|
|
365478
|
+
let s = sessions.get(fromId) ?? null ?? null;
|
|
365479
|
+
let who = "agent " + fromId + (s != null ? " (" + s.profile + ")" : "");
|
|
365480
|
+
let asks = question === true;
|
|
365481
|
+
parentQueue.push(asks ? "QUESTION from " + who + " \u2014 it needs your answer (send_message " + fromId + "):\n" + text : "Report from " + who + ":\n" + text) ?? null;
|
|
365482
|
+
emit6({ type: "report", sessionId: fromId, message: text, question: asks }) ?? null;
|
|
365483
|
+
changed() ?? null;
|
|
365000
365484
|
}
|
|
365001
|
-
|
|
365002
|
-
|
|
365003
|
-
|
|
365004
|
-
|
|
365005
|
-
|
|
365006
|
-
|
|
365007
|
-
|
|
365008
|
-
|
|
365009
|
-
|
|
365010
|
-
|
|
365011
|
-
|
|
365012
|
-
|
|
365485
|
+
};
|
|
365486
|
+
let run4 = async (session3, profile, prompt2, forceReadOnly, parentSignal, fresh) => {
|
|
365487
|
+
{
|
|
365488
|
+
let control = ((__v) => __v == null ? "null" : typeof __v)(host.createSignal) === "function" ? host.createSignal() ?? null : plainStopControl() ?? null;
|
|
365489
|
+
controls.set(session3.id, control) ?? null;
|
|
365490
|
+
if (parentSignal != null) {
|
|
365491
|
+
if (parentSignal.aborted === true) {
|
|
365492
|
+
control.stop() ?? null;
|
|
365493
|
+
} else if (((__v) => __v == null ? "null" : typeof __v)(parentSignal.addEventListener) === "function") {
|
|
365494
|
+
parentSignal.addEventListener("abort", () => {
|
|
365495
|
+
{
|
|
365496
|
+
control.stop() ?? null;
|
|
365497
|
+
}
|
|
365498
|
+
}) ?? null;
|
|
365499
|
+
}
|
|
365500
|
+
}
|
|
365501
|
+
let ctx2 = { session: session3, profile, readOnly: forceReadOnly || profile.readOnly === true, signal: control.signal };
|
|
365502
|
+
let tools = (host.childTools(ctx2) ?? null).concat([REPORT_SPEC]) ?? null;
|
|
365503
|
+
let childModel = ((__v) => __v == null ? "null" : typeof __v)(host.childModel) === "function" ? host.childModel(ctx2) ?? null : null;
|
|
365504
|
+
let budget = ((__v) => __v == null ? "null" : typeof __v)(profile.maxRounds) === "number" && profile.maxRounds > 0 ? profile.maxRounds : ((__v) => __v == null ? "null" : typeof __v)(host.maxRounds) === "number" && host.maxRounds > 0 ? host.maxRounds : 30;
|
|
365013
365505
|
let ok2 = true;
|
|
365014
365506
|
let summary = "";
|
|
365015
365507
|
let rounds = 0;
|
|
365508
|
+
let wasStopped = () => {
|
|
365509
|
+
{
|
|
365510
|
+
return control.signal.aborted === true || parentSignal != null && parentSignal.aborted === true;
|
|
365511
|
+
}
|
|
365512
|
+
};
|
|
365016
365513
|
try {
|
|
365017
|
-
|
|
365018
|
-
messages,
|
|
365019
|
-
tools,
|
|
365020
|
-
|
|
365021
|
-
|
|
365022
|
-
|
|
365023
|
-
|
|
365024
|
-
|
|
365025
|
-
|
|
365026
|
-
|
|
365027
|
-
|
|
365028
|
-
|
|
365029
|
-
|
|
365030
|
-
|
|
365514
|
+
{
|
|
365515
|
+
let messages = fresh ? [{ role: "system", content: await (host.childSystemPrompt(ctx2) ?? null) }, { role: "user", content: prompt2 }] : session3.transcript.concat([{ role: "user", content: "Message from the main agent:\n" + prompt2 }]) ?? null;
|
|
365516
|
+
let outcome = await (runAgentLoop({ messages, tools, callModel: ((__v) => __v == null ? "null" : typeof __v)(childModel) === "function" ? childModel : host.callModel, signal: control.signal, stopped: () => {
|
|
365517
|
+
{
|
|
365518
|
+
return parentSignal != null && parentSignal.aborted === true;
|
|
365519
|
+
}
|
|
365520
|
+
}, maxRounds: budget, drainNotifications: () => {
|
|
365521
|
+
{
|
|
365522
|
+
return (session3.inbox.splice(0, session3.inbox.length) ?? null).map((t3) => {
|
|
365523
|
+
{
|
|
365524
|
+
return "Message from the main agent:\n" + t3;
|
|
365525
|
+
}
|
|
365526
|
+
}) ?? null;
|
|
365527
|
+
}
|
|
365528
|
+
}, execTool: async (call2) => {
|
|
365529
|
+
{
|
|
365530
|
+
if (call2.name === REPORT_TOOL) {
|
|
365531
|
+
let args2 = {};
|
|
365532
|
+
try {
|
|
365533
|
+
{
|
|
365534
|
+
args2 = JSON.parse(call2.argsText === "" ? "{}" : call2.argsText) ?? null;
|
|
365535
|
+
}
|
|
365536
|
+
} catch (e) {
|
|
365537
|
+
{
|
|
365538
|
+
args2 = {};
|
|
365539
|
+
}
|
|
365540
|
+
}
|
|
365541
|
+
report2(session3.id, String(args2.message ?? "") ?? null, args2.question === true) ?? null;
|
|
365542
|
+
return { id: call2.id, name: call2.name, argsText: call2.argsText, ok: true, summary: "reported", content: JSON.stringify({ ok: true }) ?? null };
|
|
365031
365543
|
}
|
|
365032
|
-
|
|
365033
|
-
return { ...call2, ok: true, summary: "reported", content: JSON.stringify({ ok: true }) };
|
|
365544
|
+
return await (host.execChildTool(call2, ctx2) ?? null);
|
|
365034
365545
|
}
|
|
365035
|
-
|
|
365036
|
-
|
|
365037
|
-
|
|
365038
|
-
|
|
365039
|
-
|
|
365040
|
-
|
|
365041
|
-
|
|
365042
|
-
|
|
365043
|
-
|
|
365044
|
-
|
|
365045
|
-
|
|
365046
|
-
|
|
365047
|
-
|
|
365048
|
-
|
|
365049
|
-
|
|
365546
|
+
}, requireAction: fresh && !ctx2.readOnly, hooks: { onToolStart: (c2) => {
|
|
365547
|
+
{
|
|
365548
|
+
emit6({ type: "tool-start", sessionId: session3.id, name: c2.name }) ?? null;
|
|
365549
|
+
}
|
|
365550
|
+
}, onToolEnd: (r) => {
|
|
365551
|
+
{
|
|
365552
|
+
emit6({ type: "tool-end", sessionId: session3.id, name: r.name, ok: r.ok, summary: r.summary }) ?? null;
|
|
365553
|
+
}
|
|
365554
|
+
}, onTextDelta: (d) => {
|
|
365555
|
+
{
|
|
365556
|
+
emit6({ type: "text", sessionId: session3.id, delta: d }) ?? null;
|
|
365557
|
+
}
|
|
365558
|
+
}, onNudge: (m) => {
|
|
365559
|
+
{
|
|
365560
|
+
emit6({ type: "nudge", sessionId: session3.id, message: m }) ?? null;
|
|
365561
|
+
}
|
|
365562
|
+
} } }) ?? null);
|
|
365563
|
+
session3.transcript = outcome.messages;
|
|
365564
|
+
rounds = outcome.rounds;
|
|
365565
|
+
let said = outcome.text.trim() ?? null;
|
|
365566
|
+
summary = said !== "" ? said : outcome.stopped ? "(stopped)" : "(finished without a summary)";
|
|
365567
|
+
ok2 = !outcome.stopped;
|
|
365568
|
+
}
|
|
365050
365569
|
} catch (err2) {
|
|
365051
|
-
|
|
365052
|
-
|
|
365053
|
-
|
|
365054
|
-
|
|
365055
|
-
this.controllers.delete(session3.id);
|
|
365570
|
+
{
|
|
365571
|
+
ok2 = false;
|
|
365572
|
+
summary = wasStopped() ?? null ? "(stopped)" : "(agent error: " + (errorMessage2(err2) ?? null) + ")";
|
|
365573
|
+
}
|
|
365056
365574
|
}
|
|
365057
|
-
session3.
|
|
365058
|
-
|
|
365059
|
-
|
|
365060
|
-
|
|
365575
|
+
controls.delete(session3.id) ?? null;
|
|
365576
|
+
session3.rounds = session3.rounds + rounds;
|
|
365577
|
+
if (session3.status === "running") {
|
|
365578
|
+
session3.status = ok2 ? "done" : wasStopped() ?? null ? "stopped" : "error";
|
|
365061
365579
|
session3.summary = summary;
|
|
365580
|
+
session3.endedAt = now2() ?? null;
|
|
365581
|
+
} else {
|
|
365582
|
+
session3.summary = summary;
|
|
365583
|
+
}
|
|
365062
365584
|
if (session3.background && session3.status !== "stopped") {
|
|
365063
|
-
|
|
365064
|
-
${summary}`);
|
|
365585
|
+
parentQueue.push("Agent " + session3.id + " (" + session3.profile + ") " + (ok2 ? "finished" : "failed") + ":\n" + summary) ?? null;
|
|
365065
365586
|
}
|
|
365066
|
-
|
|
365067
|
-
|
|
365587
|
+
sessionEvent(session3) ?? null;
|
|
365588
|
+
persist3(session3) ?? null;
|
|
365068
365589
|
return { ok: ok2, summary, rounds };
|
|
365069
365590
|
}
|
|
365070
|
-
|
|
365071
|
-
|
|
365591
|
+
};
|
|
365592
|
+
let takeNext = () => {
|
|
365593
|
+
{
|
|
365594
|
+
while (waiting3.length > 0) {
|
|
365595
|
+
let next2 = waiting3.shift() ?? null;
|
|
365596
|
+
if (next2.session.status === "queued") {
|
|
365597
|
+
next2.session.status = "running";
|
|
365598
|
+
sessionEvent(next2.session) ?? null;
|
|
365599
|
+
changed() ?? null;
|
|
365600
|
+
return next2;
|
|
365601
|
+
}
|
|
365602
|
+
}
|
|
365603
|
+
return null;
|
|
365072
365604
|
}
|
|
365073
|
-
|
|
365074
|
-
|
|
365075
|
-
|
|
365076
|
-
|
|
365605
|
+
};
|
|
365606
|
+
let runSlot = (first2) => {
|
|
365607
|
+
{
|
|
365608
|
+
((f2) => Promise.resolve().then(() => f2()))(async () => {
|
|
365609
|
+
{
|
|
365610
|
+
let job = first2;
|
|
365611
|
+
while (job != null) {
|
|
365612
|
+
try {
|
|
365613
|
+
{
|
|
365614
|
+
if (job.session.status !== "stopped") {
|
|
365615
|
+
await (job.go() ?? null);
|
|
365616
|
+
}
|
|
365617
|
+
}
|
|
365618
|
+
} catch (e) {
|
|
365619
|
+
{
|
|
365620
|
+
}
|
|
365621
|
+
}
|
|
365622
|
+
job = takeNext() ?? null;
|
|
365623
|
+
if (job == null) {
|
|
365624
|
+
active3 = Math.max(0, active3 - 1) ?? null;
|
|
365625
|
+
if (waiting3.length > 0 && active3 < maxConcurrent) {
|
|
365626
|
+
active3 = active3 + 1;
|
|
365627
|
+
job = takeNext() ?? null;
|
|
365628
|
+
if (job == null) {
|
|
365629
|
+
active3 = Math.max(0, active3 - 1) ?? null;
|
|
365630
|
+
}
|
|
365631
|
+
}
|
|
365632
|
+
}
|
|
365633
|
+
}
|
|
365634
|
+
}
|
|
365635
|
+
}) ?? null;
|
|
365077
365636
|
}
|
|
365078
|
-
|
|
365079
|
-
|
|
365080
|
-
|
|
365637
|
+
};
|
|
365638
|
+
let startBackground = (session3, go) => {
|
|
365639
|
+
{
|
|
365640
|
+
if (active3 < maxConcurrent) {
|
|
365641
|
+
active3 = active3 + 1;
|
|
365642
|
+
runSlot({ session: session3, go }) ?? null;
|
|
365081
365643
|
return;
|
|
365082
|
-
|
|
365083
|
-
|
|
365084
|
-
|
|
365085
|
-
|
|
365644
|
+
}
|
|
365645
|
+
session3.status = "queued";
|
|
365646
|
+
sessionEvent(session3) ?? null;
|
|
365647
|
+
changed() ?? null;
|
|
365648
|
+
waiting3.push({ session: session3, go }) ?? null;
|
|
365086
365649
|
}
|
|
365087
365650
|
};
|
|
365651
|
+
let stop2 = (id3) => {
|
|
365652
|
+
{
|
|
365653
|
+
let s = sessions.get(id3) ?? null ?? null;
|
|
365654
|
+
if (s == null || s.status !== "running" && s.status !== "queued") {
|
|
365655
|
+
return false;
|
|
365656
|
+
}
|
|
365657
|
+
let control = controls.get(id3) ?? null ?? null;
|
|
365658
|
+
if (control != null) {
|
|
365659
|
+
control.stop() ?? null;
|
|
365660
|
+
}
|
|
365661
|
+
s.status = "stopped";
|
|
365662
|
+
s.endedAt = now2() ?? null;
|
|
365663
|
+
persist3(s) ?? null;
|
|
365664
|
+
return true;
|
|
365665
|
+
}
|
|
365666
|
+
};
|
|
365667
|
+
let load2 = async () => {
|
|
365668
|
+
{
|
|
365669
|
+
if (loaded2) {
|
|
365670
|
+
return;
|
|
365671
|
+
}
|
|
365672
|
+
loaded2 = true;
|
|
365673
|
+
if (host.store != null && ((__v) => __v == null ? "null" : typeof __v)(host.store) === "object") {
|
|
365674
|
+
let saved = await (host.store.load() ?? null);
|
|
365675
|
+
for (const s of Array.isArray(saved) ?? null ? saved : []) {
|
|
365676
|
+
if (s.status === "running" || s.status === "queued") {
|
|
365677
|
+
s.status = "stopped";
|
|
365678
|
+
if (((__v) => __v == null ? "null" : typeof __v)(s.endedAt) !== "number") {
|
|
365679
|
+
s.endedAt = now2() ?? null;
|
|
365680
|
+
}
|
|
365681
|
+
}
|
|
365682
|
+
sessions.set(s.id, s) ?? null;
|
|
365683
|
+
}
|
|
365684
|
+
}
|
|
365685
|
+
changed() ?? null;
|
|
365686
|
+
}
|
|
365687
|
+
};
|
|
365688
|
+
let get4 = (id3) => {
|
|
365689
|
+
{
|
|
365690
|
+
return sessions.get(id3) ?? null ?? null;
|
|
365691
|
+
}
|
|
365692
|
+
};
|
|
365693
|
+
return { load: load2, flush: async () => {
|
|
365694
|
+
{
|
|
365695
|
+
while (pendingSaves > 0) {
|
|
365696
|
+
await (delay2(WAIT_STEP_MS) ?? null);
|
|
365697
|
+
}
|
|
365698
|
+
}
|
|
365699
|
+
}, subscribe: (l) => {
|
|
365700
|
+
{
|
|
365701
|
+
listeners8.push(l) ?? null;
|
|
365702
|
+
return () => {
|
|
365703
|
+
{
|
|
365704
|
+
let i2 = listeners8.indexOf(l) ?? null;
|
|
365705
|
+
if (i2 >= 0) {
|
|
365706
|
+
listeners8.splice(i2, 1) ?? null;
|
|
365707
|
+
}
|
|
365708
|
+
}
|
|
365709
|
+
};
|
|
365710
|
+
}
|
|
365711
|
+
}, list: () => {
|
|
365712
|
+
{
|
|
365713
|
+
return (allSessions(sessions) ?? null).sort((a, b) => {
|
|
365714
|
+
{
|
|
365715
|
+
return a.startedAt - b.startedAt;
|
|
365716
|
+
}
|
|
365717
|
+
}) ?? null;
|
|
365718
|
+
}
|
|
365719
|
+
}, get: get4, wait: async (id3, opts) => {
|
|
365720
|
+
{
|
|
365721
|
+
let o = opts ?? {};
|
|
365722
|
+
let deadline = (now2() ?? null) + (((__v) => __v == null ? "null" : typeof __v)(o.timeoutMs) === "number" ? o.timeoutMs : 12e4);
|
|
365723
|
+
let signal = o.signal ?? null;
|
|
365724
|
+
while ((isBusy(get4(id3) ?? null) ?? null) && (now2() ?? null) < deadline && !(signal != null && signal.aborted === true)) {
|
|
365725
|
+
await (delay2(Math.min(WAIT_STEP_MS, Math.max(1, deadline - (now2() ?? null)) ?? null) ?? null) ?? null);
|
|
365726
|
+
}
|
|
365727
|
+
return get4(id3) ?? null;
|
|
365728
|
+
}
|
|
365729
|
+
}, dismissFinished: (id3) => {
|
|
365730
|
+
{
|
|
365731
|
+
let prefix = "Agent " + id3 + " (";
|
|
365732
|
+
let i2 = parentQueue.length - 1;
|
|
365733
|
+
while (i2 >= 0) {
|
|
365734
|
+
if ((parentQueue[i2] ?? null).startsWith(prefix) ?? null) {
|
|
365735
|
+
parentQueue.splice(i2, 1) ?? null;
|
|
365736
|
+
}
|
|
365737
|
+
i2 = i2 - 1;
|
|
365738
|
+
}
|
|
365739
|
+
}
|
|
365740
|
+
}, drainParentNotifications: () => {
|
|
365741
|
+
{
|
|
365742
|
+
return parentQueue.splice(0, parentQueue.length) ?? null;
|
|
365743
|
+
}
|
|
365744
|
+
}, hasPendingNotifications: () => {
|
|
365745
|
+
{
|
|
365746
|
+
return parentQueue.length > 0;
|
|
365747
|
+
}
|
|
365748
|
+
}, spawn: async (req) => {
|
|
365749
|
+
{
|
|
365750
|
+
let profile = profileById(req.profileId) ?? null;
|
|
365751
|
+
if (profile == null) {
|
|
365752
|
+
let ids2 = ((host.profiles() ?? null).map((p2) => {
|
|
365753
|
+
{
|
|
365754
|
+
return p2.id;
|
|
365755
|
+
}
|
|
365756
|
+
}) ?? null).join(", ") ?? null;
|
|
365757
|
+
return { kind: "refused", reason: 'No agent type "' + req.profileId + '". Available: ' + ids2 + "." };
|
|
365758
|
+
}
|
|
365759
|
+
let prompt2 = ((__v) => __v == null ? "null" : typeof __v)(req.prompt) === "string" ? req.prompt.trim() ?? null : "";
|
|
365760
|
+
if (prompt2 === "") {
|
|
365761
|
+
return { kind: "refused", reason: "A task needs a self-contained prompt \u2014 the agent cannot see this conversation." };
|
|
365762
|
+
}
|
|
365763
|
+
let background = ((__v) => __v == null ? "null" : typeof __v)(req.background) === "boolean" ? req.background : profile.background === true;
|
|
365764
|
+
let id3 = ((__v) => __v == null ? "null" : typeof __v)(host.newId) === "function" ? host.newId() ?? null : "agent-" + ((now2() ?? null).toString(36) ?? null) + "-" + (((Math.random() ?? null).toString(36) ?? null).slice(2, 7) ?? null);
|
|
365765
|
+
let session3 = { id: id3, profile: profile.id, description: ((__v) => __v == null ? "null" : typeof __v)(req.description) === "string" && req.description !== "" ? req.description : prompt2.slice(0, 80) ?? null, status: "running", background, transcript: [], inbox: [], startedAt: now2() ?? null, rounds: 0, readOnly: req.readOnly === true || profile.readOnly === true };
|
|
365766
|
+
if (((__v) => __v == null ? "null" : typeof __v)(req.parentCallId) === "string" && req.parentCallId !== "") {
|
|
365767
|
+
session3.parentCallId = req.parentCallId;
|
|
365768
|
+
}
|
|
365769
|
+
sessions.set(session3.id, session3) ?? null;
|
|
365770
|
+
changed() ?? null;
|
|
365771
|
+
sessionEvent(session3) ?? null;
|
|
365772
|
+
let forceReadOnly = req.readOnly === true;
|
|
365773
|
+
let parentSignal = req.signal ?? null;
|
|
365774
|
+
if (background) {
|
|
365775
|
+
startBackground(session3, async () => {
|
|
365776
|
+
{
|
|
365777
|
+
return await (run4(session3, profile, prompt2, forceReadOnly, parentSignal, true) ?? null);
|
|
365778
|
+
}
|
|
365779
|
+
}) ?? null;
|
|
365780
|
+
return { kind: "started", id: session3.id };
|
|
365781
|
+
}
|
|
365782
|
+
let out = await (run4(session3, profile, prompt2, forceReadOnly, parentSignal, true) ?? null);
|
|
365783
|
+
return { kind: "done", id: session3.id, ok: out.ok, summary: out.summary, rounds: out.rounds };
|
|
365784
|
+
}
|
|
365785
|
+
}, message: async (id3, text, opts) => {
|
|
365786
|
+
{
|
|
365787
|
+
await (load2() ?? null);
|
|
365788
|
+
let o = opts ?? {};
|
|
365789
|
+
let session3 = sessions.get(id3) ?? null ?? null;
|
|
365790
|
+
if (session3 == null) {
|
|
365791
|
+
return { kind: "unknown", id: id3 };
|
|
365792
|
+
}
|
|
365793
|
+
if (session3.status === "running" || session3.status === "queued") {
|
|
365794
|
+
session3.inbox.push(text) ?? null;
|
|
365795
|
+
persist3(session3) ?? null;
|
|
365796
|
+
return { kind: "queued", id: id3 };
|
|
365797
|
+
}
|
|
365798
|
+
let profile = profileById(session3.profile) ?? null;
|
|
365799
|
+
if (profile == null) {
|
|
365800
|
+
return { kind: "unknown", id: id3 };
|
|
365801
|
+
}
|
|
365802
|
+
let wait2 = o.wait === true;
|
|
365803
|
+
let parentSignal = o.signal ?? null;
|
|
365804
|
+
session3.status = "running";
|
|
365805
|
+
session3.endedAt = null;
|
|
365806
|
+
session3.background = !wait2;
|
|
365807
|
+
changed() ?? null;
|
|
365808
|
+
if (!wait2) {
|
|
365809
|
+
startBackground(session3, async () => {
|
|
365810
|
+
{
|
|
365811
|
+
return await (run4(session3, profile, text, false, parentSignal, false) ?? null);
|
|
365812
|
+
}
|
|
365813
|
+
}) ?? null;
|
|
365814
|
+
return { kind: "resumed", id: id3 };
|
|
365815
|
+
}
|
|
365816
|
+
let out = await (run4(session3, profile, text, false, parentSignal, false) ?? null);
|
|
365817
|
+
return { kind: "done", id: id3, ok: out.ok, summary: out.summary };
|
|
365818
|
+
}
|
|
365819
|
+
}, stop: stop2, stopAll: () => {
|
|
365820
|
+
{
|
|
365821
|
+
for (const s of allSessions(sessions) ?? null) {
|
|
365822
|
+
stop2(s.id) ?? null;
|
|
365823
|
+
}
|
|
365824
|
+
parentQueue.splice(0, parentQueue.length) ?? null;
|
|
365825
|
+
}
|
|
365826
|
+
}, report: report2 };
|
|
365827
|
+
}
|
|
365828
|
+
}
|
|
365829
|
+
var delay2, REPORT_TOOL, REPORT_SPEC, WAIT_STEP_MS;
|
|
365830
|
+
var init_runtime5 = __esm({
|
|
365831
|
+
"node_modules/.pnpm/@hyperyai+sdk@2.1.0_@types+react-dom@19.3.0_@types+react@19.3.0__@types+react@19.3.0_re_62022f8c0abbfd4c405f5fb20b5aa9ec/node_modules/@hyperyai/sdk/dist/agents/core/runtime.js"() {
|
|
365832
|
+
init_loop();
|
|
365833
|
+
delay2 = ((ms2) => new Promise((settle4) => setTimeout(() => settle4(null), Math.max(0, Number(ms2) || 0))));
|
|
365834
|
+
REPORT_TOOL = "report_to_parent";
|
|
365835
|
+
REPORT_SPEC = { readOnly: true, acts: false, spec: { type: "function", function: { name: REPORT_TOOL, description: "Send the main agent a progress update, or a question (set question) when you need a decision you cannot make yourself. It arrives between its steps and it answers with a message you read at your next step \u2014 keep working on what you can meanwhile. Your final answer still goes back by itself when you finish.", parameters: { type: "object", properties: { message: { type: "string", description: "What to tell the main agent." }, question: { type: "boolean", description: "This needs an answer." } }, required: ["message"] } } } };
|
|
365836
|
+
WAIT_STEP_MS = 25;
|
|
365837
|
+
}
|
|
365838
|
+
});
|
|
365839
|
+
|
|
365840
|
+
// node_modules/.pnpm/@hyperyai+sdk@2.1.0_@types+react-dom@19.3.0_@types+react@19.3.0__@types+react@19.3.0_re_62022f8c0abbfd4c405f5fb20b5aa9ec/node_modules/@hyperyai/sdk/dist/agents/core/types.js
|
|
365841
|
+
var init_types9 = __esm({
|
|
365842
|
+
"node_modules/.pnpm/@hyperyai+sdk@2.1.0_@types+react-dom@19.3.0_@types+react@19.3.0__@types+react@19.3.0_re_62022f8c0abbfd4c405f5fb20b5aa9ec/node_modules/@hyperyai/sdk/dist/agents/core/types.js"() {
|
|
365088
365843
|
}
|
|
365089
365844
|
});
|
|
365090
365845
|
|
|
365091
|
-
// node_modules/.pnpm/@hyperyai+sdk@1.
|
|
365846
|
+
// node_modules/.pnpm/@hyperyai+sdk@2.1.0_@types+react-dom@19.3.0_@types+react@19.3.0__@types+react@19.3.0_re_62022f8c0abbfd4c405f5fb20b5aa9ec/node_modules/@hyperyai/sdk/dist/agents/core/orchestration.js
|
|
365092
365847
|
var init_orchestration = __esm({
|
|
365093
|
-
"node_modules/.pnpm/@hyperyai+sdk@1.
|
|
365848
|
+
"node_modules/.pnpm/@hyperyai+sdk@2.1.0_@types+react-dom@19.3.0_@types+react@19.3.0__@types+react@19.3.0_re_62022f8c0abbfd4c405f5fb20b5aa9ec/node_modules/@hyperyai/sdk/dist/agents/core/orchestration.js"() {
|
|
365094
365849
|
}
|
|
365095
365850
|
});
|
|
365096
365851
|
|
|
365097
|
-
// node_modules/.pnpm/@hyperyai+sdk@1.
|
|
365852
|
+
// node_modules/.pnpm/@hyperyai+sdk@2.1.0_@types+react-dom@19.3.0_@types+react@19.3.0__@types+react@19.3.0_re_62022f8c0abbfd4c405f5fb20b5aa9ec/node_modules/@hyperyai/sdk/dist/agents/core/profiles.js
|
|
365098
365853
|
var ORCHESTRATOR_GUIDANCE;
|
|
365099
365854
|
var init_profiles2 = __esm({
|
|
365100
|
-
"node_modules/.pnpm/@hyperyai+sdk@1.
|
|
365101
|
-
ORCHESTRATOR_GUIDANCE = [
|
|
365102
|
-
"You orchestrate agents. For anything beyond a small edit:",
|
|
365103
|
-
"1. Plan: break the request into steps (a planner agent for big requests).",
|
|
365104
|
-
"2. Do: hand independent steps to agents in parallel (builder for changes, explorer to find things); do small steps yourself.",
|
|
365105
|
-
"3. Check: when the work is done, have a reviewer agent check it against the request.",
|
|
365106
|
-
"4. Repeat: on FAIL, send the fixes to the agent that built it (send_message keeps its context) and review again \u2014 at most three rounds \u2014 then report honestly what is still wrong.",
|
|
365107
|
-
"Steer running agents with send_message, stop ones going wrong with stop_agent, and answer their reports. Finish only when the work is done and checked."
|
|
365108
|
-
].join("\n");
|
|
365855
|
+
"node_modules/.pnpm/@hyperyai+sdk@2.1.0_@types+react-dom@19.3.0_@types+react@19.3.0__@types+react@19.3.0_re_62022f8c0abbfd4c405f5fb20b5aa9ec/node_modules/@hyperyai/sdk/dist/agents/core/profiles.js"() {
|
|
365856
|
+
ORCHESTRATOR_GUIDANCE = ["You orchestrate agents. For anything beyond a small edit:", "1. Plan: break the request into steps (a planner agent for big requests).", "2. Do: hand independent steps to agents in parallel (builder for changes, explorer to find things); do small steps yourself.", "3. Check: when the work is done, have a reviewer agent check it against the request.", "4. Repeat: on FAIL, send the fixes to the agent that built it (send_message keeps its context) and review again \u2014 at most three rounds \u2014 then report honestly what is still wrong.", "Steer running agents with send_message, stop ones going wrong with stop_agent, and answer their reports. Finish only when the work is done and checked."].join("\n") ?? null;
|
|
365109
365857
|
}
|
|
365110
365858
|
});
|
|
365111
365859
|
|
|
365112
|
-
// node_modules/.pnpm/@hyperyai+sdk@1.
|
|
365860
|
+
// node_modules/.pnpm/@hyperyai+sdk@2.1.0_@types+react-dom@19.3.0_@types+react@19.3.0__@types+react@19.3.0_re_62022f8c0abbfd4c405f5fb20b5aa9ec/node_modules/@hyperyai/sdk/dist/agents/core/supervisor.js
|
|
365113
365861
|
var init_supervisor = __esm({
|
|
365114
|
-
"node_modules/.pnpm/@hyperyai+sdk@1.
|
|
365862
|
+
"node_modules/.pnpm/@hyperyai+sdk@2.1.0_@types+react-dom@19.3.0_@types+react@19.3.0__@types+react@19.3.0_re_62022f8c0abbfd4c405f5fb20b5aa9ec/node_modules/@hyperyai/sdk/dist/agents/core/supervisor.js"() {
|
|
365115
365863
|
}
|
|
365116
365864
|
});
|
|
365117
365865
|
|
|
365118
|
-
// node_modules/.pnpm/@hyperyai+sdk@1.
|
|
365866
|
+
// node_modules/.pnpm/@hyperyai+sdk@2.1.0_@types+react-dom@19.3.0_@types+react@19.3.0__@types+react@19.3.0_re_62022f8c0abbfd4c405f5fb20b5aa9ec/node_modules/@hyperyai/sdk/dist/agents/core/todos.js
|
|
365119
365867
|
var init_todos = __esm({
|
|
365120
|
-
"node_modules/.pnpm/@hyperyai+sdk@1.
|
|
365868
|
+
"node_modules/.pnpm/@hyperyai+sdk@2.1.0_@types+react-dom@19.3.0_@types+react@19.3.0__@types+react@19.3.0_re_62022f8c0abbfd4c405f5fb20b5aa9ec/node_modules/@hyperyai/sdk/dist/agents/core/todos.js"() {
|
|
365121
365869
|
}
|
|
365122
365870
|
});
|
|
365123
365871
|
|
|
365124
|
-
// node_modules/.pnpm/@hyperyai+sdk@1.
|
|
365872
|
+
// node_modules/.pnpm/@hyperyai+sdk@2.1.0_@types+react-dom@19.3.0_@types+react@19.3.0__@types+react@19.3.0_re_62022f8c0abbfd4c405f5fb20b5aa9ec/node_modules/@hyperyai/sdk/dist/agents/core/store.js
|
|
365873
|
+
async function loadAll(kv, prefix) {
|
|
365874
|
+
{
|
|
365875
|
+
let out = [];
|
|
365876
|
+
for (const k2 of await (kv.keys(prefix) ?? null)) {
|
|
365877
|
+
let v = await (kv.get(k2) ?? null);
|
|
365878
|
+
if (v != null) {
|
|
365879
|
+
out.push(v) ?? null;
|
|
365880
|
+
}
|
|
365881
|
+
}
|
|
365882
|
+
return out;
|
|
365883
|
+
}
|
|
365884
|
+
}
|
|
365885
|
+
function sessionStore(kv, scope) {
|
|
365886
|
+
{
|
|
365887
|
+
let prefix = (scope ?? "default") + ":session:";
|
|
365888
|
+
return { load: async () => {
|
|
365889
|
+
{
|
|
365890
|
+
return await (loadAll(kv, prefix) ?? null);
|
|
365891
|
+
}
|
|
365892
|
+
}, save: async (s) => {
|
|
365893
|
+
{
|
|
365894
|
+
await (kv.set(prefix + s.id, s) ?? null);
|
|
365895
|
+
}
|
|
365896
|
+
}, remove: async (id3) => {
|
|
365897
|
+
{
|
|
365898
|
+
await ((kv["delete"] ?? null)(prefix + id3) ?? null);
|
|
365899
|
+
}
|
|
365900
|
+
} };
|
|
365901
|
+
}
|
|
365902
|
+
}
|
|
365903
|
+
var init_store = __esm({
|
|
365904
|
+
"node_modules/.pnpm/@hyperyai+sdk@2.1.0_@types+react-dom@19.3.0_@types+react@19.3.0__@types+react@19.3.0_re_62022f8c0abbfd4c405f5fb20b5aa9ec/node_modules/@hyperyai/sdk/dist/agents/core/store.js"() {
|
|
365905
|
+
}
|
|
365906
|
+
});
|
|
365907
|
+
|
|
365908
|
+
// node_modules/.pnpm/@hyperyai+sdk@2.1.0_@types+react-dom@19.3.0_@types+react@19.3.0__@types+react@19.3.0_re_62022f8c0abbfd4c405f5fb20b5aa9ec/node_modules/@hyperyai/sdk/dist/agents/core/run.js
|
|
365909
|
+
var init_run = __esm({
|
|
365910
|
+
"node_modules/.pnpm/@hyperyai+sdk@2.1.0_@types+react-dom@19.3.0_@types+react@19.3.0__@types+react@19.3.0_re_62022f8c0abbfd4c405f5fb20b5aa9ec/node_modules/@hyperyai/sdk/dist/agents/core/run.js"() {
|
|
365911
|
+
}
|
|
365912
|
+
});
|
|
365913
|
+
|
|
365914
|
+
// node_modules/.pnpm/@hyperyai+sdk@2.1.0_@types+react-dom@19.3.0_@types+react@19.3.0__@types+react@19.3.0_re_62022f8c0abbfd4c405f5fb20b5aa9ec/node_modules/@hyperyai/sdk/dist/agents/core/index.js
|
|
365915
|
+
var init_core3 = __esm({
|
|
365916
|
+
"node_modules/.pnpm/@hyperyai+sdk@2.1.0_@types+react-dom@19.3.0_@types+react@19.3.0__@types+react@19.3.0_re_62022f8c0abbfd4c405f5fb20b5aa9ec/node_modules/@hyperyai/sdk/dist/agents/core/index.js"() {
|
|
365917
|
+
init_types9();
|
|
365918
|
+
init_loop();
|
|
365919
|
+
init_context2();
|
|
365920
|
+
init_runtime5();
|
|
365921
|
+
init_orchestration();
|
|
365922
|
+
init_profiles2();
|
|
365923
|
+
init_supervisor();
|
|
365924
|
+
init_todos();
|
|
365925
|
+
init_store();
|
|
365926
|
+
init_run();
|
|
365927
|
+
init_hypery_model();
|
|
365928
|
+
}
|
|
365929
|
+
});
|
|
365930
|
+
|
|
365931
|
+
// node_modules/.pnpm/@hyperyai+sdk@2.1.0_@types+react-dom@19.3.0_@types+react@19.3.0__@types+react@19.3.0_re_62022f8c0abbfd4c405f5fb20b5aa9ec/node_modules/@hyperyai/sdk/dist/agents/indexeddb.js
|
|
365125
365932
|
function indexedDbStore(name2 = "hypery-agents") {
|
|
365126
365933
|
let db3 = null;
|
|
365127
365934
|
const open4 = () => db3 ?? (db3 = new Promise((res, rej) => {
|
|
@@ -365141,7 +365948,8 @@ function indexedDbStore(name2 = "hypery-agents") {
|
|
|
365141
365948
|
});
|
|
365142
365949
|
};
|
|
365143
365950
|
return {
|
|
365144
|
-
|
|
365951
|
+
// A missing key reads as null, as the core's stores do.
|
|
365952
|
+
get: async (k2) => await tx2("readonly", (s) => s.get(k2)) ?? null,
|
|
365145
365953
|
set: async (k2, v) => {
|
|
365146
365954
|
await tx2("readwrite", (s) => s.put(structuredClone(v), k2));
|
|
365147
365955
|
},
|
|
@@ -365151,232 +365959,32 @@ function indexedDbStore(name2 = "hypery-agents") {
|
|
|
365151
365959
|
keys: async (prefix) => (await tx2("readonly", (s) => s.getAllKeys())).map(String).filter((k2) => k2.startsWith(prefix))
|
|
365152
365960
|
};
|
|
365153
365961
|
}
|
|
365154
|
-
|
|
365155
|
-
|
|
365156
|
-
return {
|
|
365157
|
-
load: async () => (await Promise.all((await kv.keys(prefix)).map((k2) => kv.get(k2)))).filter((s) => !!s),
|
|
365158
|
-
save: (s) => kv.set(prefix + s.id, s),
|
|
365159
|
-
remove: (id3) => kv.delete(prefix + id3)
|
|
365160
|
-
};
|
|
365161
|
-
}
|
|
365162
|
-
var init_store = __esm({
|
|
365163
|
-
"node_modules/.pnpm/@hyperyai+sdk@1.6.0_@types+react-dom@19.3.0_@types+react@19.3.0__@types+react@19.3.0_re_7e5d1696c3869532d33b29d7658baea1/node_modules/@hyperyai/sdk/dist/agents/store.js"() {
|
|
365962
|
+
var init_indexeddb2 = __esm({
|
|
365963
|
+
"node_modules/.pnpm/@hyperyai+sdk@2.1.0_@types+react-dom@19.3.0_@types+react@19.3.0__@types+react@19.3.0_re_62022f8c0abbfd4c405f5fb20b5aa9ec/node_modules/@hyperyai/sdk/dist/agents/indexeddb.js"() {
|
|
365164
365964
|
}
|
|
365165
365965
|
});
|
|
365166
365966
|
|
|
365167
|
-
// node_modules/.pnpm/@hyperyai+sdk@1.
|
|
365168
|
-
|
|
365169
|
-
|
|
365170
|
-
}
|
|
365171
|
-
});
|
|
365172
|
-
|
|
365173
|
-
// node_modules/.pnpm/@hyperyai+sdk@1.6.0_@types+react-dom@19.3.0_@types+react@19.3.0__@types+react@19.3.0_re_7e5d1696c3869532d33b29d7658baea1/node_modules/@hyperyai/sdk/dist/agents/hypery-model.js
|
|
365174
|
-
function createHyperyModel(opts) {
|
|
365175
|
-
const doFetch = opts.fetch ?? fetch;
|
|
365176
|
-
return async (messages, tools, hooks, signal) => {
|
|
365177
|
-
const token = await resolve2(opts.token);
|
|
365178
|
-
if (!token)
|
|
365179
|
-
throw new AgentModelError("Sign in to Hypery to use the agent.", "ai_reauth", 401);
|
|
365180
|
-
const [model, team, paymentSource] = await Promise.all([resolve2(opts.model), resolve2(opts.team ?? null), resolve2(opts.paymentSource ?? null)]);
|
|
365181
|
-
const body = JSON.stringify({
|
|
365182
|
-
model,
|
|
365183
|
-
messages,
|
|
365184
|
-
stream: true,
|
|
365185
|
-
max_tokens: opts.maxTokens ?? (tools.length ? 16384 : 4096),
|
|
365186
|
-
...opts.temperature !== void 0 ? { temperature: opts.temperature } : {},
|
|
365187
|
-
...tools.length ? { tools, tool_choice: "auto" } : {}
|
|
365188
|
-
});
|
|
365189
|
-
const limit = opts.maxRequestBytes ?? MAX_REQUEST_BYTES;
|
|
365190
|
-
if (body.length > limit) {
|
|
365191
|
-
throw new AgentModelError(`This message is too large to send (${(body.length / 1e6).toFixed(1)} MB with its images). Send fewer or smaller images.`, "too_large", 413);
|
|
365192
|
-
}
|
|
365193
|
-
const res = await doFetch(`${(opts.gatewayUrl ?? "https://hypery.ai").replace(/\/$/, "")}/api/v1/chat/completions`, {
|
|
365194
|
-
method: "POST",
|
|
365195
|
-
signal,
|
|
365196
|
-
body,
|
|
365197
|
-
headers: {
|
|
365198
|
-
Authorization: `Bearer ${token}`,
|
|
365199
|
-
"Content-Type": "application/json",
|
|
365200
|
-
Accept: "text/event-stream",
|
|
365201
|
-
...team ? { [HYPERY_TEAM_HEADER2]: team } : {},
|
|
365202
|
-
...paymentSource ? { [HYPERY_PAYMENT_SOURCE_HEADER2]: paymentSource } : {}
|
|
365203
|
-
}
|
|
365204
|
-
}).catch((err2) => {
|
|
365205
|
-
if (err2?.name === "AbortError")
|
|
365206
|
-
throw err2;
|
|
365207
|
-
throw new AgentModelError("Could not reach Hypery. Check your connection.", "network", 0);
|
|
365208
|
-
});
|
|
365209
|
-
if (!res.ok || !res.body) {
|
|
365210
|
-
const text = await res.text().catch(() => "");
|
|
365211
|
-
let payload = text;
|
|
365212
|
-
try {
|
|
365213
|
-
payload = JSON.parse(text);
|
|
365214
|
-
} catch {
|
|
365215
|
-
}
|
|
365216
|
-
throw new AgentModelError(streamErrorMessage(payload, `The AI request failed (${res.status}).`), errorCodeFor(res.status, payload), res.status);
|
|
365217
|
-
}
|
|
365218
|
-
const acc = createStreamAccumulator();
|
|
365219
|
-
const reader = res.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
365220
|
-
let idle2;
|
|
365221
|
-
try {
|
|
365222
|
-
await new Promise((done, fail3) => {
|
|
365223
|
-
const arm = () => {
|
|
365224
|
-
clearTimeout(idle2);
|
|
365225
|
-
idle2 = setTimeout(() => fail3(new AgentModelError("The model stopped responding.", "ai_timeout", 504)), opts.idleTimeoutMs ?? DEFAULT_IDLE_TIMEOUT_MS);
|
|
365226
|
-
};
|
|
365227
|
-
arm();
|
|
365228
|
-
const pump = async () => {
|
|
365229
|
-
const { value: value3, done: finished2 } = await reader.read();
|
|
365230
|
-
if (finished2)
|
|
365231
|
-
return done();
|
|
365232
|
-
arm();
|
|
365233
|
-
for (const e of acc.push(value3)) {
|
|
365234
|
-
if (e.textDelta)
|
|
365235
|
-
hooks.onTextDelta?.(e.textDelta);
|
|
365236
|
-
if (e.reasoningDelta)
|
|
365237
|
-
hooks.onReasoningDelta?.(e.reasoningDelta);
|
|
365238
|
-
if (e.toolProgress)
|
|
365239
|
-
hooks.onToolProgress?.(e.toolProgress);
|
|
365240
|
-
}
|
|
365241
|
-
return pump();
|
|
365242
|
-
};
|
|
365243
|
-
pump().catch(fail3);
|
|
365244
|
-
});
|
|
365245
|
-
} finally {
|
|
365246
|
-
clearTimeout(idle2);
|
|
365247
|
-
reader.cancel().catch(() => {
|
|
365248
|
-
});
|
|
365249
|
-
}
|
|
365250
|
-
const r = acc.result();
|
|
365251
|
-
if (!r.sawDone && !r.text && !r.toolCalls.length)
|
|
365252
|
-
throw new AgentModelError("The response was cut off before it started. Try again.", "ai_upstream", 502);
|
|
365253
|
-
return { text: r.text, reasoning: r.reasoning, toolCalls: r.toolCalls };
|
|
365254
|
-
};
|
|
365255
|
-
}
|
|
365256
|
-
function errorCodeFor(status3, payload) {
|
|
365257
|
-
const code = payload?.error?.code;
|
|
365258
|
-
if (typeof code === "string")
|
|
365259
|
-
return code;
|
|
365260
|
-
if (status3 === 401)
|
|
365261
|
-
return "ai_reauth";
|
|
365262
|
-
if (status3 === 402)
|
|
365263
|
-
return "ai_credits";
|
|
365264
|
-
if (status3 === 403)
|
|
365265
|
-
return "ai_scope";
|
|
365266
|
-
if (status3 === 429)
|
|
365267
|
-
return "ai_rate_limited";
|
|
365268
|
-
return "ai_upstream";
|
|
365269
|
-
}
|
|
365270
|
-
function streamErrorMessage(payload, fallback2 = "The AI request failed.") {
|
|
365271
|
-
const err2 = payload?.error;
|
|
365272
|
-
if (typeof err2 === "string" && err2.trim())
|
|
365273
|
-
return err2;
|
|
365274
|
-
const message = err2?.message ?? payload?.message;
|
|
365275
|
-
return typeof message === "string" && message.trim() ? message : fallback2;
|
|
365967
|
+
// node_modules/.pnpm/@hyperyai+sdk@2.1.0_@types+react-dom@19.3.0_@types+react@19.3.0__@types+react@19.3.0_re_62022f8c0abbfd4c405f5fb20b5aa9ec/node_modules/@hyperyai/sdk/dist/agents/index.js
|
|
365968
|
+
function createHyperyModel2(opts) {
|
|
365969
|
+
return createHyperyModel({ ...opts, fetch: opts.fetch ?? ((url4, init) => fetch(url4, init)) });
|
|
365276
365970
|
}
|
|
365277
|
-
function
|
|
365278
|
-
|
|
365279
|
-
|
|
365280
|
-
|
|
365281
|
-
|
|
365282
|
-
|
|
365283
|
-
|
|
365284
|
-
|
|
365285
|
-
|
|
365286
|
-
|
|
365287
|
-
let nl;
|
|
365288
|
-
while ((nl = buffer.indexOf("\n")) >= 0) {
|
|
365289
|
-
const line = buffer.slice(0, nl).trim();
|
|
365290
|
-
buffer = buffer.slice(nl + 1);
|
|
365291
|
-
if (!line.startsWith("data:"))
|
|
365292
|
-
continue;
|
|
365293
|
-
const data = line.slice(5).trim();
|
|
365294
|
-
if (!data)
|
|
365295
|
-
continue;
|
|
365296
|
-
if (data === "[DONE]") {
|
|
365297
|
-
sawDone = true;
|
|
365298
|
-
continue;
|
|
365299
|
-
}
|
|
365300
|
-
let chunk3;
|
|
365301
|
-
try {
|
|
365302
|
-
chunk3 = JSON.parse(data);
|
|
365303
|
-
} catch {
|
|
365304
|
-
continue;
|
|
365305
|
-
}
|
|
365306
|
-
if (chunk3.error) {
|
|
365307
|
-
const code = chunk3.error?.code;
|
|
365308
|
-
throw new AgentModelError(streamErrorMessage(chunk3), typeof code === "string" ? code : "ai_upstream");
|
|
365309
|
-
}
|
|
365310
|
-
const delta = chunk3.choices?.[0]?.delta;
|
|
365311
|
-
if (!delta)
|
|
365312
|
-
continue;
|
|
365313
|
-
if (typeof delta.content === "string" && delta.content) {
|
|
365314
|
-
text += delta.content;
|
|
365315
|
-
out.push({ textDelta: delta.content });
|
|
365316
|
-
}
|
|
365317
|
-
const r = typeof delta.reasoning === "string" ? delta.reasoning : typeof delta.reasoning_content === "string" ? delta.reasoning_content : "";
|
|
365318
|
-
if (r) {
|
|
365319
|
-
reasoning += r;
|
|
365320
|
-
out.push({ reasoningDelta: r });
|
|
365321
|
-
}
|
|
365322
|
-
for (const tc of delta.tool_calls ?? []) {
|
|
365323
|
-
const i2 = typeof tc.index === "number" ? tc.index : Math.max(0, calls.length - 1);
|
|
365324
|
-
const call2 = calls[i2] ?? (calls[i2] = { name: "", arguments: "" });
|
|
365325
|
-
if (tc.id)
|
|
365326
|
-
call2.id = tc.id;
|
|
365327
|
-
if (tc.function?.name)
|
|
365328
|
-
call2.name += tc.function.name;
|
|
365329
|
-
if (tc.function?.arguments) {
|
|
365330
|
-
call2.arguments += tc.function.arguments;
|
|
365331
|
-
out.push({ toolProgress: { index: i2, name: call2.name, bytes: call2.arguments.length, arguments: call2.arguments } });
|
|
365332
|
-
}
|
|
365333
|
-
}
|
|
365334
|
-
}
|
|
365335
|
-
return out;
|
|
365336
|
-
},
|
|
365337
|
-
result() {
|
|
365338
|
-
return {
|
|
365339
|
-
text,
|
|
365340
|
-
reasoning,
|
|
365341
|
-
sawDone,
|
|
365342
|
-
toolCalls: calls.filter((c2) => c2 && c2.name).map((c2, i2) => ({ id: c2.id ?? `call_${i2}`, name: c2.name, arguments: c2.arguments }))
|
|
365343
|
-
};
|
|
365344
|
-
}
|
|
365345
|
-
};
|
|
365971
|
+
function createAgentRuntime2(host) {
|
|
365972
|
+
return createAgentRuntime({
|
|
365973
|
+
...host,
|
|
365974
|
+
createSignal: host.createSignal ?? (() => {
|
|
365975
|
+
const controller = new AbortController();
|
|
365976
|
+
return { signal: controller.signal, stop: () => controller.abort() };
|
|
365977
|
+
})
|
|
365978
|
+
// The core types a child's signal as anything with `aborted`; here every one comes from `createSignal`, whose
|
|
365979
|
+
// signals are AbortSignals — so the host's callbacks may rely on that.
|
|
365980
|
+
});
|
|
365346
365981
|
}
|
|
365347
|
-
var AgentModelError, MAX_REQUEST_BYTES, DEFAULT_IDLE_TIMEOUT_MS, HYPERY_TEAM_HEADER2, HYPERY_PAYMENT_SOURCE_HEADER2, resolve2;
|
|
365348
|
-
var init_hypery_model = __esm({
|
|
365349
|
-
"node_modules/.pnpm/@hyperyai+sdk@1.6.0_@types+react-dom@19.3.0_@types+react@19.3.0__@types+react@19.3.0_re_7e5d1696c3869532d33b29d7658baea1/node_modules/@hyperyai/sdk/dist/agents/hypery-model.js"() {
|
|
365350
|
-
AgentModelError = class extends Error {
|
|
365351
|
-
constructor(message, code = "ai_upstream", status3 = 502) {
|
|
365352
|
-
super(message);
|
|
365353
|
-
this.code = code;
|
|
365354
|
-
this.status = status3;
|
|
365355
|
-
this.name = "AgentModelError";
|
|
365356
|
-
}
|
|
365357
|
-
};
|
|
365358
|
-
MAX_REQUEST_BYTES = 44e5;
|
|
365359
|
-
DEFAULT_IDLE_TIMEOUT_MS = 18e4;
|
|
365360
|
-
HYPERY_TEAM_HEADER2 = "x-hypery-active-organization-id";
|
|
365361
|
-
HYPERY_PAYMENT_SOURCE_HEADER2 = "x-hypery-payment-source";
|
|
365362
|
-
resolve2 = async (v) => typeof v === "function" ? await v() : v;
|
|
365363
|
-
}
|
|
365364
|
-
});
|
|
365365
|
-
|
|
365366
|
-
// node_modules/.pnpm/@hyperyai+sdk@1.6.0_@types+react-dom@19.3.0_@types+react@19.3.0__@types+react@19.3.0_re_7e5d1696c3869532d33b29d7658baea1/node_modules/@hyperyai/sdk/dist/agents/index.js
|
|
365367
365982
|
var init_agents = __esm({
|
|
365368
|
-
"node_modules/.pnpm/@hyperyai+sdk@1.
|
|
365369
|
-
init_types9();
|
|
365370
|
-
init_loop();
|
|
365371
|
-
init_context2();
|
|
365372
|
-
init_runtime5();
|
|
365373
|
-
init_orchestration();
|
|
365374
|
-
init_profiles2();
|
|
365375
|
-
init_supervisor();
|
|
365376
|
-
init_todos();
|
|
365377
|
-
init_store();
|
|
365378
|
-
init_run();
|
|
365983
|
+
"node_modules/.pnpm/@hyperyai+sdk@2.1.0_@types+react-dom@19.3.0_@types+react@19.3.0__@types+react@19.3.0_re_62022f8c0abbfd4c405f5fb20b5aa9ec/node_modules/@hyperyai/sdk/dist/agents/index.js"() {
|
|
365379
365984
|
init_hypery_model();
|
|
365985
|
+
init_runtime5();
|
|
365986
|
+
init_core3();
|
|
365987
|
+
init_indexeddb2();
|
|
365380
365988
|
}
|
|
365381
365989
|
});
|
|
365382
365990
|
|
|
@@ -365390,7 +365998,7 @@ var init_stream_parse = __esm({
|
|
|
365390
365998
|
|
|
365391
365999
|
// lib/agent/gateway.ts
|
|
365392
366000
|
async function streamChat(opts, handlers = {}, signal) {
|
|
365393
|
-
const call2 =
|
|
366001
|
+
const call2 = createHyperyModel2({ ...session2, model: opts.model, maxTokens: opts.maxTokens, temperature: opts.temperature });
|
|
365394
366002
|
const turn = await call2(opts.messages, opts.tools ?? [], handlers, signal);
|
|
365395
366003
|
return { text: turn.text, reasoning: turn.reasoning ?? "", toolCalls: turn.toolCalls };
|
|
365396
366004
|
}
|
|
@@ -365411,11 +366019,11 @@ var init_gateway = __esm({
|
|
|
365411
366019
|
paymentSource: async () => (await paymentSourceHeaders())[HYPERY_PAYMENT_SOURCE_HEADER] === "credits" ? "credits" : null,
|
|
365412
366020
|
gatewayUrl: HYPERY_GATEWAY_URL
|
|
365413
366021
|
};
|
|
365414
|
-
agentModel = (model) =>
|
|
366022
|
+
agentModel = (model) => createHyperyModel2({
|
|
365415
366023
|
...session2,
|
|
365416
366024
|
model: () => {
|
|
365417
366025
|
const id3 = model();
|
|
365418
|
-
if (!id3) throw
|
|
366026
|
+
if (!id3) throw agentModelError("Pick a chat model for the agent first.", "no_model", 400);
|
|
365419
366027
|
return id3;
|
|
365420
366028
|
}
|
|
365421
366029
|
});
|
|
@@ -365607,11 +366215,12 @@ function subagentHost(deps = {}) {
|
|
|
365607
366215
|
}
|
|
365608
366216
|
function recordStep(event) {
|
|
365609
366217
|
if (event.type !== "tool-start" && event.type !== "tool-end") return;
|
|
366218
|
+
const name2 = event.name ?? "";
|
|
365610
366219
|
const steps = [...activity.get(event.sessionId) ?? []];
|
|
365611
|
-
if (event.type === "tool-start") steps.push({ name:
|
|
366220
|
+
if (event.type === "tool-start") steps.push({ name: name2, status: "running" });
|
|
365612
366221
|
else {
|
|
365613
|
-
const i2 = steps.findLastIndex((s) => s.name ===
|
|
365614
|
-
const step3 = { name:
|
|
366222
|
+
const i2 = steps.findLastIndex((s) => s.name === name2 && s.status === "running");
|
|
366223
|
+
const step3 = { name: name2, status: event.ok ? "done" : "error", summary: event.summary ?? void 0 };
|
|
365615
366224
|
if (i2 >= 0) steps[i2] = step3;
|
|
365616
366225
|
else steps.push(step3);
|
|
365617
366226
|
}
|
|
@@ -365626,17 +366235,17 @@ function reportChildTool(runtime, event) {
|
|
|
365626
366235
|
const jobId = session3.background ? session3.id : void 0;
|
|
365627
366236
|
childToolListener({
|
|
365628
366237
|
profile: session3.profile,
|
|
365629
|
-
toolCallId: session3.parentCallId,
|
|
366238
|
+
toolCallId: session3.parentCallId ?? void 0,
|
|
365630
366239
|
jobId,
|
|
365631
366240
|
job: jobId,
|
|
365632
|
-
name: event.name,
|
|
366241
|
+
name: event.name ?? "",
|
|
365633
366242
|
status: event.type === "tool-start" ? "running" : event.ok ? "done" : "error",
|
|
365634
|
-
summary: event.type === "tool-end" ? event.summary : void 0
|
|
366243
|
+
summary: event.type === "tool-end" ? event.summary ?? void 0 : void 0
|
|
365635
366244
|
});
|
|
365636
366245
|
}
|
|
365637
366246
|
function agentRuntime() {
|
|
365638
366247
|
if (!runtimeRef) {
|
|
365639
|
-
runtimeRef =
|
|
366248
|
+
runtimeRef = createAgentRuntime2(subagentHost());
|
|
365640
366249
|
void runtimeRef.load();
|
|
365641
366250
|
}
|
|
365642
366251
|
return runtimeRef;
|
|
@@ -365682,7 +366291,7 @@ function subagentDelegate(deps = {}) {
|
|
|
365682
366291
|
prompt: request2.prompt,
|
|
365683
366292
|
description: request2.description,
|
|
365684
366293
|
readOnly: deps.readOnly === true || request2.readOnly === true,
|
|
365685
|
-
background: request2.background
|
|
366294
|
+
background: request2.background,
|
|
365686
366295
|
signal: deps.signal,
|
|
365687
366296
|
parentCallId: request2.callId
|
|
365688
366297
|
});
|
|
@@ -365709,7 +366318,7 @@ function subagentDelegate(deps = {}) {
|
|
|
365709
366318
|
case "list":
|
|
365710
366319
|
return {
|
|
365711
366320
|
kind: "list",
|
|
365712
|
-
agents: rt.list().map((s) => ({ id: s.id, profile: s.profile, description: s.description, status: s.status, summary: s.summary }))
|
|
366321
|
+
agents: rt.list().map((s) => ({ id: s.id, profile: s.profile, description: s.description, status: s.status, summary: s.summary ?? void 0 }))
|
|
365713
366322
|
};
|
|
365714
366323
|
}
|
|
365715
366324
|
};
|
|
@@ -365767,7 +366376,8 @@ var init_delegate = __esm({
|
|
|
365767
366376
|
prompt: args2.prompt,
|
|
365768
366377
|
description: args2.description,
|
|
365769
366378
|
readOnly: args2.readonly === true,
|
|
365770
|
-
background: args2.run_in_background
|
|
366379
|
+
background: args2.run_in_background,
|
|
366380
|
+
// omitted → the profile's `background` default (the SDK applies it)
|
|
365771
366381
|
callId: ctx2.callId
|
|
365772
366382
|
});
|
|
365773
366383
|
if (reply.kind === "refused") return { summary: "task refused (nested)", data: { error: reply.reason } };
|
|
@@ -367182,6 +367792,11 @@ function validateManifest(raw) {
|
|
|
367182
367792
|
contributes = { ...contributes, exporters };
|
|
367183
367793
|
}
|
|
367184
367794
|
}
|
|
367795
|
+
if (m.contributes !== void 0) {
|
|
367796
|
+
const c2 = m.contributes;
|
|
367797
|
+
if (c2.agentTools !== void 0) contributes = { ...contributes, agentTools: validateAgentTools(c2.agentTools) };
|
|
367798
|
+
}
|
|
367799
|
+
if (contributes?.agentTools?.length && !m.main) throw new PluginPackageError("manifest.main is required for a plugin with agent tools: the tools run in it");
|
|
367185
367800
|
if (contributes?.panels?.length && !m.ui) throw new PluginPackageError("manifest.ui is required for a plugin with panels: the panel shows its UI");
|
|
367186
367801
|
if (contributes?.importers?.length && !m.main) throw new PluginPackageError("manifest.main is required for a plugin with importers");
|
|
367187
367802
|
if (contributes?.exporters?.length && !m.main) throw new PluginPackageError("manifest.main is required for a plugin with exporters");
|
|
@@ -367207,6 +367822,44 @@ function validateManifest(raw) {
|
|
|
367207
367822
|
contributes
|
|
367208
367823
|
};
|
|
367209
367824
|
}
|
|
367825
|
+
function validateAgentTools(raw) {
|
|
367826
|
+
const L = AGENT_TOOL_LIMITS;
|
|
367827
|
+
if (!Array.isArray(raw)) throw new PluginPackageError("manifest.contributes.agentTools must be a list");
|
|
367828
|
+
if (raw.length > L.maxTools) throw new PluginPackageError(`manifest.contributes.agentTools may list at most ${L.maxTools} tools`);
|
|
367829
|
+
const seen = /* @__PURE__ */ new Set();
|
|
367830
|
+
return raw.map((entry, i2) => {
|
|
367831
|
+
const tt = entry;
|
|
367832
|
+
const at4 = `manifest.contributes.agentTools[${i2}]`;
|
|
367833
|
+
if (typeof tt?.name !== "string" || !AGENT_TOOL_NAME_RE.test(tt.name)) throw new PluginPackageError(`${at4}.name must start with a lowercase letter and use only lowercase letters, digits and "_" (at most 40)`);
|
|
367834
|
+
if (seen.has(tt.name)) throw new PluginPackageError(`${at4}.name "${tt.name}" is listed twice`);
|
|
367835
|
+
seen.add(tt.name);
|
|
367836
|
+
if (typeof tt.description !== "string" || !tt.description.trim()) throw new PluginPackageError(`${at4}.description must be a non-empty string`);
|
|
367837
|
+
if (tt.description.length > L.maxDescription) throw new PluginPackageError(`${at4}.description may be at most ${L.maxDescription} characters`);
|
|
367838
|
+
const params2 = tt.parameters ?? { type: "object", properties: {} };
|
|
367839
|
+
if (!params2 || typeof params2 !== "object" || Array.isArray(params2) || params2.type !== "object") {
|
|
367840
|
+
throw new PluginPackageError(`${at4}.parameters must be a JSON Schema with "type": "object"`);
|
|
367841
|
+
}
|
|
367842
|
+
let text;
|
|
367843
|
+
try {
|
|
367844
|
+
text = JSON.stringify(params2);
|
|
367845
|
+
} catch {
|
|
367846
|
+
throw new PluginPackageError(`${at4}.parameters must be plain JSON`);
|
|
367847
|
+
}
|
|
367848
|
+
if (new TextEncoder().encode(text).byteLength > L.maxSchemaBytes) throw new PluginPackageError(`${at4}.parameters may be at most ${L.maxSchemaBytes / 1024} KB as JSON`);
|
|
367849
|
+
try {
|
|
367850
|
+
external_exports.fromJSONSchema(JSON.parse(text));
|
|
367851
|
+
} catch (e) {
|
|
367852
|
+
throw new PluginPackageError(`${at4}.parameters is not a usable JSON Schema: ${e instanceof Error ? e.message : String(e)}`);
|
|
367853
|
+
}
|
|
367854
|
+
if (tt.readOnly !== void 0 && typeof tt.readOnly !== "boolean") throw new PluginPackageError(`${at4}.readOnly must be true or false`);
|
|
367855
|
+
return {
|
|
367856
|
+
name: tt.name,
|
|
367857
|
+
description: tt.description.trim(),
|
|
367858
|
+
parameters: JSON.parse(text),
|
|
367859
|
+
...tt.readOnly === true && { readOnly: true }
|
|
367860
|
+
};
|
|
367861
|
+
});
|
|
367862
|
+
}
|
|
367210
367863
|
function parseContributedTheme(manifest2, index2, text) {
|
|
367211
367864
|
const entry = manifest2.contributes.themes[index2];
|
|
367212
367865
|
let raw = text;
|
|
@@ -367316,12 +367969,14 @@ function parsePluginBundle(text) {
|
|
|
367316
367969
|
return { manifest: manifest2, mainCode: manifest2.main ? raw.main : "", uiHtml: manifest2.ui ? raw.ui : void 0, themes };
|
|
367317
367970
|
}
|
|
367318
367971
|
function pluginContentKey(p2) {
|
|
367319
|
-
|
|
367972
|
+
const tools = p2.manifest?.contributes?.agentTools ?? null;
|
|
367973
|
+
return JSON.stringify({ main: p2.mainCode ?? "", ui: p2.uiHtml ?? null, themes: p2.themes ?? null, ...tools ? { tools } : {} });
|
|
367320
367974
|
}
|
|
367321
|
-
var PluginPackageError, ID_RE2, VERSION_RE, MAX_VERSION_LENGTH, PANEL_ID_RE, MAX_PANELS, DATA_ICON_RE, ICON_PATH_RE, MAX_ICON_BYTES, EXTENSION_RE, ZIP_LIMITS;
|
|
367975
|
+
var PluginPackageError, ID_RE2, VERSION_RE, MAX_VERSION_LENGTH, PANEL_ID_RE, MAX_PANELS, DATA_ICON_RE, ICON_PATH_RE, MAX_ICON_BYTES, EXTENSION_RE, AGENT_TOOL_LIMITS, AGENT_TOOL_NAME_RE, ZIP_LIMITS;
|
|
367322
367976
|
var init_package2 = __esm({
|
|
367323
367977
|
"lib/plugins/package.ts"() {
|
|
367324
367978
|
init_esm2();
|
|
367979
|
+
init_zod();
|
|
367325
367980
|
init_schema();
|
|
367326
367981
|
init_listing();
|
|
367327
367982
|
init_types11();
|
|
@@ -367336,6 +367991,8 @@ var init_package2 = __esm({
|
|
|
367336
367991
|
ICON_PATH_RE = /^(\.\/)?[\w./-]+\.(svg|png|webp)$/i;
|
|
367337
367992
|
MAX_ICON_BYTES = 64 * 1024;
|
|
367338
367993
|
EXTENSION_RE = /^\.[a-z0-9]{1,15}$/i;
|
|
367994
|
+
AGENT_TOOL_LIMITS = { maxTools: 16, maxDescription: 1024, maxSchemaBytes: 8 * 1024 };
|
|
367995
|
+
AGENT_TOOL_NAME_RE = /^[a-z][a-z0-9_]{0,39}$/;
|
|
367339
367996
|
ZIP_LIMITS = { maxEntries: 500, maxEntryBytes: 10 * 1024 * 1024, maxTotalBytes: 25 * 1024 * 1024 };
|
|
367340
367997
|
}
|
|
367341
367998
|
});
|
|
@@ -367414,6 +368071,195 @@ var init_panels = __esm({
|
|
|
367414
368071
|
}
|
|
367415
368072
|
});
|
|
367416
368073
|
|
|
368074
|
+
// lib/plugins/agent-tools.ts
|
|
368075
|
+
function setPluginToolBridge(next2) {
|
|
368076
|
+
bridge2 = next2;
|
|
368077
|
+
}
|
|
368078
|
+
function hash6(s) {
|
|
368079
|
+
let h = 2166136261;
|
|
368080
|
+
for (let i2 = 0; i2 < s.length; i2++) h = Math.imul(h ^ s.charCodeAt(i2), 16777619);
|
|
368081
|
+
return (h >>> 0).toString(36).padStart(6, "0").slice(-6);
|
|
368082
|
+
}
|
|
368083
|
+
function pluginToolName(pluginId, tool2) {
|
|
368084
|
+
const slug4 = pluginId.toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
|
|
368085
|
+
const room = MAX_TOOL_NAME - NAME_PREFIX.length - 2 - tool2.length;
|
|
368086
|
+
const fitted = slug4.length <= room ? slug4 : `${slug4.slice(0, Math.max(1, room - 7))}_${hash6(pluginId)}`;
|
|
368087
|
+
return `${NAME_PREFIX}${fitted}__${tool2}`;
|
|
368088
|
+
}
|
|
368089
|
+
function pluginToolIsReadOnly(plugin, tool2) {
|
|
368090
|
+
return tool2.readOnly === true && !(plugin.granted ?? plugin.manifest.permissions).includes("write");
|
|
368091
|
+
}
|
|
368092
|
+
function toolResultFromReply(plugin, tool2, reply) {
|
|
368093
|
+
const images = (reply.images ?? []).filter(isImageDataUrl2).slice(0, MAX_RESULT_IMAGES);
|
|
368094
|
+
const data = reply.text !== void 0 ? { text: String(reply.text), ...reply.data !== void 0 ? { data: reply.data } : {} } : reply.data;
|
|
368095
|
+
const size6 = new TextEncoder().encode(JSON.stringify(data ?? null)).byteLength + images.reduce((n, s) => n + s.length, 0);
|
|
368096
|
+
if (size6 > PLUGIN_TOOL_MAX_RESULT_BYTES) throw new ToolError(`${plugin.manifest.name}: the result of ${tool2} is too large (${Math.round(size6 / 1024)} KB)`, "failed");
|
|
368097
|
+
const summary = typeof reply.summary === "string" && reply.summary.trim() ? reply.summary.trim().slice(0, 200) : `${plugin.manifest.name}: ${tool2}`;
|
|
368098
|
+
return { summary, ...data !== void 0 ? { data } : {}, ...images.length ? { images } : {} };
|
|
368099
|
+
}
|
|
368100
|
+
function pluginToolCommand(plugin, tool2) {
|
|
368101
|
+
const name2 = pluginToolName(plugin.manifest.id, tool2.name);
|
|
368102
|
+
const readOnly = pluginToolIsReadOnly(plugin, tool2);
|
|
368103
|
+
return defineCommand({
|
|
368104
|
+
id: pluginToolCommandId(plugin.manifest.id, tool2.name),
|
|
368105
|
+
title: `${plugin.manifest.name}: ${tool2.name}`,
|
|
368106
|
+
domain: "plugin",
|
|
368107
|
+
params: external_exports.fromJSONSchema(tool2.parameters),
|
|
368108
|
+
effect: readOnly ? "none" : "document",
|
|
368109
|
+
// The gate is the plugin's own: every call it makes back into the file is checked against its grant by the
|
|
368110
|
+
// plugin surface. The tool itself is consent the user already gave when they granted the plugin.
|
|
368111
|
+
permission: null,
|
|
368112
|
+
expose: { agent: { name: name2, description: `[${plugin.manifest.name} plugin] ${tool2.description}`, readOnly } },
|
|
368113
|
+
run: async (args2, ctx2) => {
|
|
368114
|
+
if (!bridge2) throw new ToolError(`${plugin.manifest.name} cannot run here: plugins need the editor.`, "unsupported");
|
|
368115
|
+
const historyGroup = `plugin-tool:${plugin.manifest.id}:${ctx2.callId ?? ++callSeq}`;
|
|
368116
|
+
const reply = await bridge2.call(plugin, tool2.name, args2, { signal: ctx2.signal, historyGroup });
|
|
368117
|
+
return toolResultFromReply(plugin, name2, reply);
|
|
368118
|
+
}
|
|
368119
|
+
});
|
|
368120
|
+
}
|
|
368121
|
+
function syncPluginAgentTools(installed3) {
|
|
368122
|
+
const want = /* @__PURE__ */ new Map();
|
|
368123
|
+
const nextSources = /* @__PURE__ */ new Map();
|
|
368124
|
+
for (const plugin of installed3) {
|
|
368125
|
+
if (!pluginToolsActive(plugin)) continue;
|
|
368126
|
+
for (const tool2 of plugin.manifest.contributes.agentTools) {
|
|
368127
|
+
try {
|
|
368128
|
+
const command = pluginToolCommand(plugin, tool2);
|
|
368129
|
+
want.set(command.id, command);
|
|
368130
|
+
nextSources.set(command.expose.agent.name, { pluginId: plugin.manifest.id, pluginName: plugin.manifest.name, tool: tool2.name });
|
|
368131
|
+
} catch (err2) {
|
|
368132
|
+
console.warn(`[plugins] ${plugin.manifest.id}: agent tool ${tool2.name} was not registered`, err2);
|
|
368133
|
+
}
|
|
368134
|
+
}
|
|
368135
|
+
}
|
|
368136
|
+
const stale = listCommands().filter((c2) => c2.id.startsWith(COMMAND_PREFIX) && !want.has(c2.id)).map((c2) => c2.id);
|
|
368137
|
+
unregisterCommand(...stale);
|
|
368138
|
+
const names = [];
|
|
368139
|
+
for (const command of want.values()) {
|
|
368140
|
+
try {
|
|
368141
|
+
registerCommand(command);
|
|
368142
|
+
names.push(command.expose.agent.name);
|
|
368143
|
+
} catch (err2) {
|
|
368144
|
+
nextSources.delete(command.expose.agent.name);
|
|
368145
|
+
console.warn(`[plugins] ${command.id} was not registered`, err2);
|
|
368146
|
+
}
|
|
368147
|
+
}
|
|
368148
|
+
sources2.clear();
|
|
368149
|
+
for (const [k2, v] of nextSources) if (names.includes(k2)) sources2.set(k2, v);
|
|
368150
|
+
return names;
|
|
368151
|
+
}
|
|
368152
|
+
function createToolChannel(send, label3) {
|
|
368153
|
+
const pending8 = /* @__PURE__ */ new Map();
|
|
368154
|
+
let seq4 = 0;
|
|
368155
|
+
return {
|
|
368156
|
+
call(tool2, args2, options = {}) {
|
|
368157
|
+
if (options.signal?.aborted) return Promise.reject(new ToolError(`${label3}: ${tool2} was stopped`, "failed"));
|
|
368158
|
+
const callId = `t${++seq4}`;
|
|
368159
|
+
return new Promise((resolve7, reject) => {
|
|
368160
|
+
const done = () => {
|
|
368161
|
+
pending8.delete(callId);
|
|
368162
|
+
clearTimeout(timer);
|
|
368163
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
368164
|
+
};
|
|
368165
|
+
const onAbort = () => {
|
|
368166
|
+
done();
|
|
368167
|
+
send("agenttoolcancel", { callId });
|
|
368168
|
+
reject(new ToolError(`${label3}: ${tool2} was stopped`, "failed"));
|
|
368169
|
+
};
|
|
368170
|
+
const ms2 = options.timeoutMs ?? PLUGIN_TOOL_TIMEOUT_MS;
|
|
368171
|
+
const timer = setTimeout(() => {
|
|
368172
|
+
done();
|
|
368173
|
+
send("agenttoolcancel", { callId });
|
|
368174
|
+
reject(new ToolError(`${label3}: ${tool2} did not answer within ${Math.round(ms2 / 1e3)} s`, "failed"));
|
|
368175
|
+
}, ms2);
|
|
368176
|
+
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
368177
|
+
pending8.set(callId, {
|
|
368178
|
+
resolve: (r) => {
|
|
368179
|
+
done();
|
|
368180
|
+
resolve7(r);
|
|
368181
|
+
},
|
|
368182
|
+
reject: (e) => {
|
|
368183
|
+
done();
|
|
368184
|
+
reject(e);
|
|
368185
|
+
}
|
|
368186
|
+
});
|
|
368187
|
+
send("agenttool", { callId, tool: tool2, args: args2 });
|
|
368188
|
+
});
|
|
368189
|
+
},
|
|
368190
|
+
receive(message) {
|
|
368191
|
+
const p2 = pending8.get(message.callId);
|
|
368192
|
+
if (!p2) return;
|
|
368193
|
+
if (typeof message.error === "string") p2.reject(new ToolError(`${label3}: ${message.error}`, "failed"));
|
|
368194
|
+
else p2.resolve(message.result && typeof message.result === "object" ? message.result : {});
|
|
368195
|
+
},
|
|
368196
|
+
/** The session closed: every outstanding call fails. */
|
|
368197
|
+
close(reason) {
|
|
368198
|
+
for (const p2 of [...pending8.values()]) p2.reject(new ToolError(`${label3}: ${reason}`, "failed"));
|
|
368199
|
+
pending8.clear();
|
|
368200
|
+
},
|
|
368201
|
+
get size() {
|
|
368202
|
+
return pending8.size;
|
|
368203
|
+
}
|
|
368204
|
+
};
|
|
368205
|
+
}
|
|
368206
|
+
function withAgentToolsShim(html) {
|
|
368207
|
+
return html.replace("</head>", () => `<script>${AGENT_TOOLS_SHIM}</script></head>`);
|
|
368208
|
+
}
|
|
368209
|
+
var PLUGIN_TOOL_TIMEOUT_MS, PLUGIN_TOOL_MAX_RESULT_BYTES, MAX_RESULT_IMAGES, COMMAND_PREFIX, NAME_PREFIX, MAX_TOOL_NAME, bridge2, pluginToolCommandId, sources2, isImageDataUrl2, callSeq, pluginToolsActive, AGENT_TOOLS_SHIM;
|
|
368210
|
+
var init_agent_tools = __esm({
|
|
368211
|
+
"lib/plugins/agent-tools.ts"() {
|
|
368212
|
+
"use strict";
|
|
368213
|
+
init_zod();
|
|
368214
|
+
init_types5();
|
|
368215
|
+
init_registry();
|
|
368216
|
+
init_errors();
|
|
368217
|
+
PLUGIN_TOOL_TIMEOUT_MS = 6e4;
|
|
368218
|
+
PLUGIN_TOOL_MAX_RESULT_BYTES = 256 * 1024;
|
|
368219
|
+
MAX_RESULT_IMAGES = 8;
|
|
368220
|
+
COMMAND_PREFIX = "pluginTool.";
|
|
368221
|
+
NAME_PREFIX = "plugin_";
|
|
368222
|
+
MAX_TOOL_NAME = 64;
|
|
368223
|
+
bridge2 = null;
|
|
368224
|
+
pluginToolCommandId = (pluginId, tool2) => `${COMMAND_PREFIX}${pluginId}.${tool2}`;
|
|
368225
|
+
sources2 = /* @__PURE__ */ new Map();
|
|
368226
|
+
isImageDataUrl2 = (v) => typeof v === "string" && /^data:image\/(png|jpe?g|webp|gif);base64,/i.test(v);
|
|
368227
|
+
callSeq = 0;
|
|
368228
|
+
pluginToolsActive = (p2) => p2.enabled && p2.granted !== null && !!p2.manifest.main && !!p2.manifest.contributes?.agentTools?.length;
|
|
368229
|
+
AGENT_TOOLS_SHIM = `(function () {
|
|
368230
|
+
var rpc = window.__popcraftRpc, api = window.popcraft;
|
|
368231
|
+
if (!rpc || !api || api.agent) return;
|
|
368232
|
+
var handlers = {}, queue = [], controllers = {};
|
|
368233
|
+
function run(e) {
|
|
368234
|
+
var ac = typeof AbortController === 'function' ? new AbortController() : null;
|
|
368235
|
+
if (ac) controllers[e.callId] = ac;
|
|
368236
|
+
Promise.resolve().then(function () {
|
|
368237
|
+
var h = handlers[e.tool];
|
|
368238
|
+
if (typeof h !== 'function') throw new Error('No handler for tool "' + e.tool + '"');
|
|
368239
|
+
return h(e.args || {}, { callId: e.callId, tool: e.tool, signal: ac ? ac.signal : undefined });
|
|
368240
|
+
}).then(function (r) {
|
|
368241
|
+
var out = r && r.$popcraftToolResult ? { summary: r.summary, data: r.data, text: r.text, images: r.images } : { data: r };
|
|
368242
|
+
rpc.send({ kind: 'toolResult', callId: e.callId, result: JSON.parse(JSON.stringify(out)) });
|
|
368243
|
+
}, function (err) {
|
|
368244
|
+
rpc.send({ kind: 'toolResult', callId: e.callId, error: String((err && err.message) || err) });
|
|
368245
|
+
}).then(function () { delete controllers[e.callId]; });
|
|
368246
|
+
}
|
|
368247
|
+
rpc.on('agenttool', function (e) { if (handlers[e.tool]) run(e); else queue.push(e); });
|
|
368248
|
+
rpc.on('agenttoolcancel', function (e) { var ac = controllers[e.callId]; if (ac) ac.abort(); });
|
|
368249
|
+
api.agent = {
|
|
368250
|
+
onTool: function (name, handler) {
|
|
368251
|
+
if (typeof name !== 'string' || typeof handler !== 'function') throw new Error('popcraft.agent.onTool needs a tool name and a handler');
|
|
368252
|
+
handlers[name] = handler;
|
|
368253
|
+
var rest = [];
|
|
368254
|
+
queue.splice(0).forEach(function (e) { if (e.tool === name) run(e); else rest.push(e); });
|
|
368255
|
+
queue.push.apply(queue, rest);
|
|
368256
|
+
},
|
|
368257
|
+
result: function (r) { var o = Object.assign({}, r || {}); o.$popcraftToolResult = true; return o; }
|
|
368258
|
+
};
|
|
368259
|
+
})();`;
|
|
368260
|
+
}
|
|
368261
|
+
});
|
|
368262
|
+
|
|
367417
368263
|
// lib/print/print-prefs.ts
|
|
367418
368264
|
var print_prefs_exports = {};
|
|
367419
368265
|
__export(print_prefs_exports, {
|
|
@@ -384264,9 +385110,9 @@ fn fs_main(in : VertexOutput) -> @location(0) vec4<f32> {
|
|
|
384264
385110
|
return;
|
|
384265
385111
|
}
|
|
384266
385112
|
if (reason instanceof RenderingCancelledException) {
|
|
384267
|
-
let
|
|
385113
|
+
let delay3 = RENDERING_CANCELLED_TIMEOUT;
|
|
384268
385114
|
if (reason.extraDelay > 0 && reason.extraDelay < 1e3) {
|
|
384269
|
-
|
|
385115
|
+
delay3 += reason.extraDelay;
|
|
384270
385116
|
}
|
|
384271
385117
|
intentState.streamReaderCancelTimeout = setTimeout(() => {
|
|
384272
385118
|
intentState.streamReaderCancelTimeout = null;
|
|
@@ -384275,7 +385121,7 @@ fn fs_main(in : VertexOutput) -> @location(0) vec4<f32> {
|
|
|
384275
385121
|
reason,
|
|
384276
385122
|
force: true
|
|
384277
385123
|
});
|
|
384278
|
-
},
|
|
385124
|
+
}, delay3);
|
|
384279
385125
|
return;
|
|
384280
385126
|
}
|
|
384281
385127
|
}
|
|
@@ -396847,6 +397693,7 @@ async function refreshInstalledPlugins() {
|
|
|
396847
397693
|
syncPluginTabs(installed3);
|
|
396848
397694
|
usePluginStore.getState().setInstalled(installed3);
|
|
396849
397695
|
syncPluginThemes(installed3);
|
|
397696
|
+
syncPluginAgentTools(installed3);
|
|
396850
397697
|
}
|
|
396851
397698
|
function syncPluginThemes(installed3) {
|
|
396852
397699
|
const themes = useThemeStore.getState();
|
|
@@ -396901,7 +397748,7 @@ async function runPlugin(pluginId, commandId, opts = {}) {
|
|
|
396901
397748
|
iframe.setAttribute("aria-hidden", "true");
|
|
396902
397749
|
iframe.style.display = "none";
|
|
396903
397750
|
iframe.dataset.popcraftPlugin = pluginId;
|
|
396904
|
-
iframe.srcdoc = withWasmEvalCsp(buildMainDocument(plugin.mainCode, granted.includes("network")));
|
|
397751
|
+
iframe.srcdoc = withAgentToolsShim(withWasmEvalCsp(buildMainDocument(plugin.mainCode, granted.includes("network"))));
|
|
396905
397752
|
const channel3 = new MessageChannel();
|
|
396906
397753
|
const session3 = {
|
|
396907
397754
|
sessionId,
|
|
@@ -396916,7 +397763,11 @@ async function runPlugin(pluginId, commandId, opts = {}) {
|
|
|
396916
397763
|
idleTimer: null,
|
|
396917
397764
|
importMode: opts.importMode ?? null,
|
|
396918
397765
|
importFile: opts.importFile ?? null,
|
|
396919
|
-
exportRequest: opts.exportRequest ?? null
|
|
397766
|
+
exportRequest: opts.exportRequest ?? null,
|
|
397767
|
+
env: null,
|
|
397768
|
+
tools: createToolChannel((event, data) => {
|
|
397769
|
+
if (running3.has(sessionId)) channel3.port1.postMessage({ kind: "event", event, data });
|
|
397770
|
+
}, plugin.manifest.name)
|
|
396920
397771
|
};
|
|
396921
397772
|
running3.set(sessionId, session3);
|
|
396922
397773
|
const dockTitle = opts.dock ? plugin.manifest.contributes?.panels?.find((p2) => opts.dock.endsWith(`:${p2.id}`))?.title : void 0;
|
|
@@ -396997,6 +397848,7 @@ async function runPlugin(pluginId, commandId, opts = {}) {
|
|
|
396997
397848
|
}
|
|
396998
397849
|
}
|
|
396999
397850
|
};
|
|
397851
|
+
session3.env = env;
|
|
397000
397852
|
channel3.port1.onmessage = async (ev) => {
|
|
397001
397853
|
const m = ev.data;
|
|
397002
397854
|
if (!running3.has(sessionId)) return;
|
|
@@ -397010,6 +397862,8 @@ async function runPlugin(pluginId, commandId, opts = {}) {
|
|
|
397010
397862
|
} else if (m.kind === "toUI") {
|
|
397011
397863
|
if (session3.uiPort) session3.uiPort.postMessage({ kind: "event", event: "message", data: m.data });
|
|
397012
397864
|
else if (session3.pendingToUI.length < 500) session3.pendingToUI.push(m.data);
|
|
397865
|
+
} else if (m.kind === "toolResult") {
|
|
397866
|
+
session3.tools.receive(m);
|
|
397013
397867
|
} else if (m.kind === "error") {
|
|
397014
397868
|
usePluginStore.getState().toast(`${plugin.manifest.name}: ${m.message}`, { error: true, source: plugin.manifest.name });
|
|
397015
397869
|
}
|
|
@@ -397065,6 +397919,43 @@ function pluginUIDocument(sessionId) {
|
|
|
397065
397919
|
if (!s?.plugin.uiHtml) return null;
|
|
397066
397920
|
return withPluginTheme(withWasmEvalCsp(buildUIDocument(s.plugin.uiHtml, s.granted.includes("network"))));
|
|
397067
397921
|
}
|
|
397922
|
+
async function ensureBackgroundSession(pluginId, command) {
|
|
397923
|
+
let session3 = runningSessionFor(pluginId);
|
|
397924
|
+
if (!session3) {
|
|
397925
|
+
await runPlugin(pluginId, command, { background: true });
|
|
397926
|
+
session3 = runningSessionFor(pluginId);
|
|
397927
|
+
if (!session3) return void 0;
|
|
397928
|
+
}
|
|
397929
|
+
if (session3.background) {
|
|
397930
|
+
if (session3.idleTimer) clearTimeout(session3.idleTimer);
|
|
397931
|
+
const id3 = session3.sessionId;
|
|
397932
|
+
const idle2 = () => {
|
|
397933
|
+
const s = running3.get(id3);
|
|
397934
|
+
if (!s) return;
|
|
397935
|
+
if (s.tools.size) {
|
|
397936
|
+
s.idleTimer = setTimeout(idle2, 6e4);
|
|
397937
|
+
return;
|
|
397938
|
+
}
|
|
397939
|
+
if (!usePluginStore.getState().sessions.find((x2) => x2.sessionId === id3)?.ui) closeSession(id3);
|
|
397940
|
+
};
|
|
397941
|
+
session3.idleTimer = setTimeout(idle2, 6e4);
|
|
397942
|
+
}
|
|
397943
|
+
return session3;
|
|
397944
|
+
}
|
|
397945
|
+
async function callPluginTool(plugin, tool2, args2, options) {
|
|
397946
|
+
const id3 = plugin.manifest.id;
|
|
397947
|
+
const current4 = await getPlugin(id3);
|
|
397948
|
+
if (!current4?.enabled || current4.granted === null) throw new Error(`${plugin.manifest.name} is disabled or has not been allowed to run`);
|
|
397949
|
+
const session3 = await ensureBackgroundSession(id3, "agent");
|
|
397950
|
+
if (!session3?.env) throw new Error(`${plugin.manifest.name} could not start`);
|
|
397951
|
+
const env = session3.env;
|
|
397952
|
+
env.historyGroup = options.historyGroup;
|
|
397953
|
+
try {
|
|
397954
|
+
return await session3.tools.call(tool2, args2, options);
|
|
397955
|
+
} finally {
|
|
397956
|
+
if (env.historyGroup === options.historyGroup) env.historyGroup = null;
|
|
397957
|
+
}
|
|
397958
|
+
}
|
|
397068
397959
|
async function dispatchWidgetClick(nodeId2, handler) {
|
|
397069
397960
|
const store6 = usePluginStore.getState();
|
|
397070
397961
|
const node2 = useEditorStore.getState().document.nodes[nodeId2];
|
|
@@ -397074,31 +397965,20 @@ async function dispatchWidgetClick(nodeId2, handler) {
|
|
|
397074
397965
|
store6.toast(t2("host.youCanViewThisFile"));
|
|
397075
397966
|
return;
|
|
397076
397967
|
}
|
|
397077
|
-
|
|
397078
|
-
if (!
|
|
397079
|
-
|
|
397080
|
-
|
|
397081
|
-
store6.toast(t2("host.installFromThePluginMarketplace", { pluginName: node2.pluginName }));
|
|
397082
|
-
return;
|
|
397083
|
-
}
|
|
397084
|
-
await runPlugin(node2.pluginId, "widget", { background: true });
|
|
397085
|
-
session3 = [...running3.values()].find((s) => s.plugin.manifest.id === node2.pluginId);
|
|
397086
|
-
if (!session3) return;
|
|
397087
|
-
}
|
|
397088
|
-
if (session3.background) {
|
|
397089
|
-
if (session3.idleTimer) clearTimeout(session3.idleTimer);
|
|
397090
|
-
const id3 = session3.sessionId;
|
|
397091
|
-
session3.idleTimer = setTimeout(() => {
|
|
397092
|
-
const s = running3.get(id3);
|
|
397093
|
-
if (s && !usePluginStore.getState().sessions.find((x2) => x2.sessionId === id3)?.ui) closeSession(id3);
|
|
397094
|
-
}, 6e4);
|
|
397968
|
+
const plugin = await getPlugin(node2.pluginId);
|
|
397969
|
+
if (!plugin) {
|
|
397970
|
+
store6.toast(t2("host.installFromThePluginMarketplace", { pluginName: node2.pluginName }));
|
|
397971
|
+
return;
|
|
397095
397972
|
}
|
|
397973
|
+
const session3 = await ensureBackgroundSession(node2.pluginId, "widget");
|
|
397974
|
+
if (!session3) return;
|
|
397096
397975
|
post(session3, "widgetclick", { nodeId: nodeId2, handler, state: node2.widgetState ?? {} });
|
|
397097
397976
|
}
|
|
397098
397977
|
function closeSession(sessionId) {
|
|
397099
397978
|
const s = running3.get(sessionId);
|
|
397100
397979
|
if (!s) return;
|
|
397101
397980
|
running3.delete(sessionId);
|
|
397981
|
+
s.tools.close("the plugin closed before it answered");
|
|
397102
397982
|
if (s.idleTimer) clearTimeout(s.idleTimer);
|
|
397103
397983
|
s.unsubscribers.forEach((u) => u());
|
|
397104
397984
|
s.port.close();
|
|
@@ -397124,7 +398004,9 @@ var init_host3 = __esm({
|
|
|
397124
398004
|
init_theme_store();
|
|
397125
398005
|
init_panels();
|
|
397126
398006
|
init_open_link();
|
|
398007
|
+
init_agent_tools();
|
|
397127
398008
|
running3 = /* @__PURE__ */ new Map();
|
|
398009
|
+
setPluginToolBridge({ call: callPluginTool });
|
|
397128
398010
|
if (typeof window !== "undefined" && false) {
|
|
397129
398011
|
window.__vpPlugins = { installPluginPayload, runPlugin, dispatchWidgetClick, closeSession, removePlugin, setEnabled, running: running3 };
|
|
397130
398012
|
}
|
|
@@ -397208,6 +398090,13 @@ function bytesToDataUrl(bytes2, format) {
|
|
|
397208
398090
|
for (const byte2 of bytes2) binary += String.fromCharCode(byte2);
|
|
397209
398091
|
return `data:${MIME2[format.toUpperCase()] ?? "application/octet-stream"};base64,${btoa(binary)}`;
|
|
397210
398092
|
}
|
|
398093
|
+
function grouped2(env, seam) {
|
|
398094
|
+
const out = {};
|
|
398095
|
+
for (const [k2, v] of Object.entries(seam)) {
|
|
398096
|
+
out[k2] = typeof v === "function" ? (...args2) => withHistoryGroup(env.historyGroup, () => v(...args2)) : v;
|
|
398097
|
+
}
|
|
398098
|
+
return out;
|
|
398099
|
+
}
|
|
397211
398100
|
function pluginContext(env) {
|
|
397212
398101
|
const have = new Set(PLUGIN_CAPABILITIES);
|
|
397213
398102
|
const capabilities = {
|
|
@@ -397233,7 +398122,7 @@ function pluginContext(env) {
|
|
|
397233
398122
|
return {
|
|
397234
398123
|
doc: () => st().document,
|
|
397235
398124
|
commit: (next2, label3) => {
|
|
397236
|
-
st().commitDocument(next2, label3 ?? env.manifest.name);
|
|
398125
|
+
withHistoryGroup(env.historyGroup, () => st().commitDocument(next2, label3 ?? env.manifest.name));
|
|
397237
398126
|
},
|
|
397238
398127
|
pageId: () => st().currentPageId,
|
|
397239
398128
|
selection: () => [...st().selection],
|
|
@@ -397246,16 +398135,17 @@ function pluginContext(env) {
|
|
|
397246
398135
|
actor: { kind: "plugin", id: env.manifest.id, label: env.manifest.name, host: env },
|
|
397247
398136
|
can: (name2) => have.has(name2),
|
|
397248
398137
|
use: (name2) => capabilities[name2],
|
|
397249
|
-
pages: {
|
|
398138
|
+
pages: grouped2(env, {
|
|
397250
398139
|
setCurrent: (id3) => st().setCurrentPage(id3),
|
|
397251
398140
|
create: (name2) => {
|
|
397252
398141
|
st().addPage(name2);
|
|
397253
398142
|
return st().currentPageId;
|
|
397254
398143
|
},
|
|
397255
398144
|
rename: (id3, name2) => st().renamePage(id3, name2)
|
|
397256
|
-
},
|
|
397257
|
-
// Boolean ops, flatten, outline stroke, masks and the shape builder are store actions (they push their own undo
|
|
397258
|
-
|
|
398145
|
+
}),
|
|
398146
|
+
// Boolean ops, flatten, outline stroke, masks and the shape builder are store actions (they push their own undo
|
|
398147
|
+
// step), grouped like `commit` while an agent tool call is running.
|
|
398148
|
+
ops: grouped2(env, storeOpsSeam(st))
|
|
397259
398149
|
};
|
|
397260
398150
|
}
|
|
397261
398151
|
function dispatchPluginCall(env, method, params2 = {}) {
|
|
@@ -397286,6 +398176,7 @@ var init_plugin = __esm({
|
|
|
397286
398176
|
init_plugin_shim();
|
|
397287
398177
|
init_plugin_widget();
|
|
397288
398178
|
init_seams();
|
|
398179
|
+
init_history_group();
|
|
397289
398180
|
PLUGIN_CAPABILITIES = ["render", "storage", "panel"];
|
|
397290
398181
|
pluginCommandId = (method) => `plugin.${method}`;
|
|
397291
398182
|
empty = external_exports.object({});
|
|
@@ -398919,11 +399810,11 @@ function upsertToolPart(parts, part) {
|
|
|
398919
399810
|
next2[i2] = { ...next2[i2], ...part };
|
|
398920
399811
|
return next2;
|
|
398921
399812
|
}
|
|
398922
|
-
var
|
|
399813
|
+
var textOf3;
|
|
398923
399814
|
var init_parts = __esm({
|
|
398924
399815
|
"lib/agent/parts.ts"() {
|
|
398925
399816
|
"use strict";
|
|
398926
|
-
|
|
399817
|
+
textOf3 = (m) => m.parts.filter((p2) => p2.type === "text").map((p2) => p2.text).join("");
|
|
398927
399818
|
}
|
|
398928
399819
|
});
|
|
398929
399820
|
|
|
@@ -399410,6 +400301,7 @@ function designRecorder() {
|
|
|
399410
400301
|
var installed;
|
|
399411
400302
|
var init_recorders = __esm({
|
|
399412
400303
|
"lib/agent/design-script/recorders.ts"() {
|
|
400304
|
+
"use strict";
|
|
399413
400305
|
installed = null;
|
|
399414
400306
|
}
|
|
399415
400307
|
});
|
|
@@ -399635,7 +400527,7 @@ function guardEdit(name2) {
|
|
|
399635
400527
|
if (reason) throw new ToolError(`${name2} cannot run: ${reason}`);
|
|
399636
400528
|
}
|
|
399637
400529
|
function historyMessages() {
|
|
399638
|
-
return activeMessages().slice(-MAX_HISTORY_MESSAGES).map((m) => ({ role: m.role, content:
|
|
400530
|
+
return activeMessages().slice(-MAX_HISTORY_MESSAGES).map((m) => ({ role: m.role, content: textOf3(m).trim() })).filter((m) => !!m.content);
|
|
399639
400531
|
}
|
|
399640
400532
|
function systemMessage(skillId, mentions = []) {
|
|
399641
400533
|
const st = useEditorStore.getState();
|
|
@@ -403349,8 +404241,8 @@ var init_import2 = __esm({
|
|
|
403349
404241
|
run: async (args2, ctx2) => {
|
|
403350
404242
|
const ext = (args2.name.match(/\.[^.]+$/)?.[0] ?? "").toLowerCase();
|
|
403351
404243
|
if (!EXTENSIONS2.includes(ext)) throw new ToolError(`import_file takes ${EXTENSIONS2.join(", ")} files, not "${args2.name}".`);
|
|
403352
|
-
const
|
|
403353
|
-
if (
|
|
404244
|
+
const sources3 = [args2.text, args2.base64, args2.url].filter((v) => v !== void 0).length;
|
|
404245
|
+
if (sources3 !== 1) throw new ToolError("Pass exactly one of text, base64 or url.");
|
|
403354
404246
|
let body;
|
|
403355
404247
|
if (args2.text !== void 0) body = args2.text;
|
|
403356
404248
|
else if (args2.base64 !== void 0) body = Uint8Array.from(atob(args2.base64), (c2) => c2.charCodeAt(0));
|
|
@@ -404035,8 +404927,8 @@ var init_presentation_audio = __esm({
|
|
|
404035
404927
|
},
|
|
404036
404928
|
run: async (args2, ctx2) => {
|
|
404037
404929
|
const page = pageOf3(ctx2, args2.pageId);
|
|
404038
|
-
const
|
|
404039
|
-
if (
|
|
404930
|
+
const sources3 = [args2.mediaHash, args2.url, args2.bytes].filter((v) => v !== void 0).length;
|
|
404931
|
+
if (sources3 !== 1) throw new ToolError("Pass exactly one of mediaHash, url or bytes.");
|
|
404040
404932
|
if (args2.role === "voice" && !args2.frameId) throw new ToolError("Name the slide (frameId) whose narration this is.");
|
|
404041
404933
|
let base = ctx2.doc();
|
|
404042
404934
|
if (!soundtrackOf(base, page)) base = doc(() => configure(base, page, {}));
|
|
@@ -411819,7 +412711,7 @@ init_resources();
|
|
|
411819
412711
|
init_desktop();
|
|
411820
412712
|
init_hypery();
|
|
411821
412713
|
import { createInterface } from "node:readline";
|
|
411822
|
-
var VERSION2 = "0.
|
|
412714
|
+
var VERSION2 = "0.42.1";
|
|
411823
412715
|
var HELP = `popcraft ${VERSION2} \u2014 the PopCraft command line
|
|
411824
412716
|
|
|
411825
412717
|
Files (headless, on .popcraft files):
|