llmz 0.0.2 → 0.0.4
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/{chunk-RB2L33ZR.js → chunk-4EWY34YA.js} +24 -24
- package/dist/{chunk-UG2GCPHF.js → chunk-4KB5WXHR.js} +3 -2
- package/dist/{chunk-YPOOKE3A.cjs → chunk-4QTK5ALH.cjs} +59 -28
- package/dist/{chunk-BKGPO722.cjs → chunk-5NVNEEYW.cjs} +55 -55
- package/dist/{chunk-DFZ6GX5C.js → chunk-5TRUJES5.js} +1 -1
- package/dist/{chunk-C2TSWGYC.cjs → chunk-6YWYCVAB.cjs} +5 -4
- package/dist/{chunk-7S3UY52U.js → chunk-7WRN4E42.js} +36 -8
- package/dist/{chunk-Q4DEJGXD.js → chunk-EFGXTO64.js} +2 -2
- package/dist/{chunk-VP6WWAE2.cjs → chunk-FIVFS4HG.cjs} +2 -2
- package/dist/{chunk-YUDUY7XW.cjs → chunk-HYVKY3W6.cjs} +23 -24
- package/dist/{chunk-PQN6HW7A.cjs → chunk-IKSIOIIP.cjs} +3 -3
- package/dist/{chunk-ZUAFUOUR.cjs → chunk-JDABP4SD.cjs} +3 -3
- package/dist/{chunk-E5W3P7EO.cjs → chunk-JK2LZW2G.cjs} +20 -2
- package/dist/{chunk-RJHDQL4C.js → chunk-JKVVQN2P.js} +1 -1
- package/dist/{chunk-MSTBEKOQ.js → chunk-JQBT7UWN.js} +3 -3
- package/dist/{chunk-BOLDQGES.cjs → chunk-KMZDFWYZ.cjs} +3 -3
- package/dist/{chunk-R2N2UUKC.cjs → chunk-LVKZYKTP.cjs} +14 -8
- package/dist/{chunk-7FIPXMZR.js → chunk-ORQP26SZ.js} +1 -1
- package/dist/{chunk-ENFB45AI.cjs → chunk-P7J2WCBB.cjs} +7 -7
- package/dist/{chunk-DILHJIMP.js → chunk-QBXIE6EY.js} +49 -18
- package/dist/{chunk-UVSOAH2H.js → chunk-QT4QF3YA.js} +1 -1
- package/dist/{chunk-6QDFMQHA.js → chunk-S6WICIDW.js} +8 -2
- package/dist/{chunk-QPSUMPLP.js → chunk-TJQVC4CE.js} +6 -6
- package/dist/{chunk-ZSRC3TN4.js → chunk-UNMKB2DA.js} +9 -10
- package/dist/{chunk-3CGLDS5T.cjs → chunk-UQOBUJIQ.cjs} +38 -10
- package/dist/{chunk-QZGFCB4T.cjs → chunk-VAF2H6UD.cjs} +22 -22
- package/dist/{chunk-E2B5DRIC.cjs → chunk-W6U2VXSF.cjs} +25 -25
- package/dist/{chunk-3T465BEW.js → chunk-ZCPQ3QOW.js} +19 -1
- package/dist/citations.d.ts +63 -0
- package/dist/component-HQ5YQNRX.cjs +14 -0
- package/dist/component-LQDU72LX.js +14 -0
- package/dist/component.d.ts +32 -10
- package/dist/component.default.d.ts +334 -8
- package/dist/context.d.ts +3 -1
- package/dist/dual-modes-QHBOFWHM.js +13 -0
- package/dist/dual-modes-YE4S2AIL.cjs +13 -0
- package/dist/exit-F6ZUL2NV.js +8 -0
- package/dist/exit-IDKGZD7M.cjs +8 -0
- package/dist/exit.d.ts +2 -0
- package/dist/index.cjs +209 -58
- package/dist/index.d.ts +3 -2
- package/dist/index.js +193 -42
- package/dist/{jsx-CJ2RBODH.js → jsx-AEHVFB3L.js} +2 -3
- package/dist/jsx-AJAXBWFE.cjs +13 -0
- package/dist/{llmz-WY74UVE3.js → llmz-AS5TGCQS.js} +98 -39
- package/dist/{llmz-EGTGPSTX.cjs → llmz-R6XZG3JQ.cjs} +129 -70
- package/dist/llmz.d.ts +3 -2
- package/dist/snapshots.d.ts +9 -1
- package/dist/tool-LY77IWV2.js +11 -0
- package/dist/tool-SWJYOR2Z.cjs +11 -0
- package/dist/tool.d.ts +34 -9
- package/dist/truncator-NYN7BGKJ.cjs +10 -0
- package/dist/truncator-WAL2GCUY.js +10 -0
- package/dist/types.d.ts +7 -1
- package/dist/typings-AIV2OASX.js +10 -0
- package/dist/typings-XR6CYHW4.cjs +10 -0
- package/dist/{utils-TS23YJPE.js → utils-L5GLCS3C.js} +2 -3
- package/dist/utils-QC4I2L6R.cjs +37 -0
- package/dist/vm-GJ5R72AP.cjs +12 -0
- package/dist/vm-ZUQOSRRM.js +12 -0
- package/dist/vm.d.ts +1 -1
- package/package.json +8 -6
- package/dist/chunk-A7BDFLAE.cjs +0 -30
- package/dist/chunk-YSQDPG26.js +0 -30
- package/dist/component-DWBRHLEN.cjs +0 -9
- package/dist/component-R3ZAVXUC.js +0 -9
- package/dist/dual-modes-2VDEOJ5D.js +0 -13
- package/dist/dual-modes-3MH5N6RY.cjs +0 -13
- package/dist/exit-GYMXZZ4I.js +0 -9
- package/dist/exit-PQHMJEOG.cjs +0 -9
- package/dist/jsx-PPLE5YTB.cjs +0 -14
- package/dist/tool-AY47ML65.cjs +0 -12
- package/dist/tool-WVIPESKN.js +0 -12
- package/dist/truncator-MTONQESU.js +0 -11
- package/dist/truncator-ZKPOW2I3.cjs +0 -11
- package/dist/typings-HTYLRNIC.js +0 -11
- package/dist/typings-QRJGGNUM.cjs +0 -11
- package/dist/utils-UR4IMUHC.cjs +0 -38
- package/dist/vm-4JFSZAMR.cjs +0 -13
- package/dist/vm-SMMA664M.js +0 -13
- package/patches/source-map-js@1.2.1.patch +0 -16
package/dist/index.js
CHANGED
|
@@ -1,34 +1,38 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Snapshot
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-4KB5WXHR.js";
|
|
4
|
+
import "./chunk-EFGXTO64.js";
|
|
4
5
|
import {
|
|
5
6
|
Tool
|
|
6
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-QBXIE6EY.js";
|
|
7
8
|
import {
|
|
8
9
|
formatTypings,
|
|
9
10
|
getTypings
|
|
10
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-UNMKB2DA.js";
|
|
11
12
|
import {
|
|
12
13
|
CodeFormattingError,
|
|
13
14
|
SnapshotSignal,
|
|
14
15
|
ThinkSignal
|
|
15
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-JKVVQN2P.js";
|
|
17
|
+
import "./chunk-JQBT7UWN.js";
|
|
16
18
|
import {
|
|
17
19
|
Exit
|
|
18
|
-
} from "./chunk-
|
|
19
|
-
import
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
} from "./chunk-S6WICIDW.js";
|
|
21
|
+
import {
|
|
22
|
+
Component,
|
|
23
|
+
assertValidComponent,
|
|
24
|
+
isComponent
|
|
25
|
+
} from "./chunk-ZCPQ3QOW.js";
|
|
26
|
+
import "./chunk-ORQP26SZ.js";
|
|
22
27
|
import {
|
|
23
28
|
escapeString,
|
|
24
29
|
getMultilineComment,
|
|
25
30
|
isValidIdentifier
|
|
26
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-5TRUJES5.js";
|
|
27
32
|
import {
|
|
28
33
|
cloneDeep_default,
|
|
29
34
|
upperFirst_default
|
|
30
|
-
} from "./chunk-
|
|
31
|
-
import "./chunk-YSQDPG26.js";
|
|
35
|
+
} from "./chunk-7WRN4E42.js";
|
|
32
36
|
|
|
33
37
|
// src/objects.ts
|
|
34
38
|
import { z } from "@bpinternal/zui";
|
|
@@ -497,8 +501,142 @@ function embedPropertyValue(property) {
|
|
|
497
501
|
return "unknown";
|
|
498
502
|
}
|
|
499
503
|
|
|
504
|
+
// src/citations.ts
|
|
505
|
+
var RARE_SYMBOLS = {
|
|
506
|
+
ARROW_UP: "\u2191",
|
|
507
|
+
CIRCLE_BULLET: "\u30FB",
|
|
508
|
+
STAR_BULLET_FULL: "\u2605",
|
|
509
|
+
STAR_BULLET_EMPTY: "\u2606",
|
|
510
|
+
ARROW_BULLET: "\u2192",
|
|
511
|
+
SQUARE_BULLET: "\u25A0",
|
|
512
|
+
TRIANGLE_BULLET: "\u25BA",
|
|
513
|
+
OPENING_TAG: "\u3010",
|
|
514
|
+
CLOSING_TAG: "\u3011",
|
|
515
|
+
SS: "\xA7",
|
|
516
|
+
CROSS: "\u2020"
|
|
517
|
+
};
|
|
518
|
+
var CitationsManager = class {
|
|
519
|
+
_citations = /* @__PURE__ */ new Map();
|
|
520
|
+
_nextId = 0;
|
|
521
|
+
/**
|
|
522
|
+
* Registers a new source and returns the created Citation.
|
|
523
|
+
* @param source An object representing the source of the citation.
|
|
524
|
+
* @returns The created Citation.
|
|
525
|
+
*/
|
|
526
|
+
registerSource(source) {
|
|
527
|
+
const id = this._nextId++;
|
|
528
|
+
const tag = `${RARE_SYMBOLS.OPENING_TAG}${id}${RARE_SYMBOLS.CLOSING_TAG}`;
|
|
529
|
+
const citation = {
|
|
530
|
+
id,
|
|
531
|
+
source,
|
|
532
|
+
tag
|
|
533
|
+
};
|
|
534
|
+
this._citations.set(id, citation);
|
|
535
|
+
return citation;
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* Extracts citations from the provided content and cleans the content of citation tags.
|
|
539
|
+
* Non-found citations are replaced with a special "Not Found" citation.
|
|
540
|
+
* @param content The string content containing citation tags.
|
|
541
|
+
* @returns An object containing the cleaned content and an array of found citations.
|
|
542
|
+
*/
|
|
543
|
+
extractCitations(content, replace) {
|
|
544
|
+
const citations = [];
|
|
545
|
+
const notFoundCitation = {
|
|
546
|
+
id: -1,
|
|
547
|
+
source: "Not Found",
|
|
548
|
+
tag: ""
|
|
549
|
+
};
|
|
550
|
+
const regex = new RegExp(`${RARE_SYMBOLS.OPENING_TAG}([\\d|\\w|\\s|,]{0,})${RARE_SYMBOLS.CLOSING_TAG}`, "ig");
|
|
551
|
+
let match;
|
|
552
|
+
const offsets = [];
|
|
553
|
+
while ((match = regex.exec(content)) !== null) {
|
|
554
|
+
const offset = match.index;
|
|
555
|
+
const length = match[0].length;
|
|
556
|
+
offsets.push({ start: offset, length });
|
|
557
|
+
const multi = (match[1] ?? "").split(/\D/g).map((s) => s.trim()).filter(Boolean).map((s) => parseInt(s, 10)).filter((s) => !isNaN(s) && s >= 0);
|
|
558
|
+
for (const citationId of multi) {
|
|
559
|
+
const citation = this._citations.get(citationId);
|
|
560
|
+
if (citation) {
|
|
561
|
+
citations.push({ ...citation, offset });
|
|
562
|
+
} else {
|
|
563
|
+
citations.push({ ...notFoundCitation, offset });
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
const entries = offsets.map((o) => ({
|
|
568
|
+
start: o.start,
|
|
569
|
+
length: o.length,
|
|
570
|
+
citations: citations.filter((x) => x.offset === o.start && x.id !== -1)
|
|
571
|
+
})).sort((a, b) => a.start - b.start);
|
|
572
|
+
let result = "";
|
|
573
|
+
let cursor = 0;
|
|
574
|
+
for (const { start, length, citations: citations2 } of entries) {
|
|
575
|
+
result += content.slice(cursor, start);
|
|
576
|
+
const replacement = citations2.map((citation) => replace ? replace(citation) : "").join("");
|
|
577
|
+
result += replacement;
|
|
578
|
+
cursor = start + length;
|
|
579
|
+
}
|
|
580
|
+
result += content.slice(cursor);
|
|
581
|
+
return { cleaned: result, citations };
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Strips citation tags from the provided content.
|
|
585
|
+
* @param content The string content containing citation tags.
|
|
586
|
+
* @returns The cleaned content without citation tags.
|
|
587
|
+
*/
|
|
588
|
+
static stripCitationTags(content) {
|
|
589
|
+
const regex = new RegExp(`${RARE_SYMBOLS.OPENING_TAG}([\\d|\\w|\\s|,]{0,})${RARE_SYMBOLS.CLOSING_TAG}?`, "g");
|
|
590
|
+
return content.replace(regex, "");
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* Removes citations from a deeply nested plain object and returns a new object with citations removed.
|
|
594
|
+
* @param obj The plain object to process.
|
|
595
|
+
* @returns A tuple containing the new object and an array of extracted citations with paths.
|
|
596
|
+
*/
|
|
597
|
+
removeCitationsFromObject(obj) {
|
|
598
|
+
const result = [];
|
|
599
|
+
const processObject = (current, path) => {
|
|
600
|
+
if (typeof current === "string") {
|
|
601
|
+
const extraction = this.extractCitations(current);
|
|
602
|
+
if (extraction.citations.length > 0) {
|
|
603
|
+
result.push(...extraction.citations.map((citation) => ({ path, citation })));
|
|
604
|
+
}
|
|
605
|
+
return extraction.cleaned;
|
|
606
|
+
} else if (typeof current === "object" && current !== null) {
|
|
607
|
+
const newObject = Array.isArray(current) ? [] : {};
|
|
608
|
+
for (const key of Object.keys(current)) {
|
|
609
|
+
newObject[key] = processObject(current[key], `${path}.${key}`);
|
|
610
|
+
}
|
|
611
|
+
return newObject;
|
|
612
|
+
}
|
|
613
|
+
return current;
|
|
614
|
+
};
|
|
615
|
+
const newObj = processObject(obj, "root");
|
|
616
|
+
return [newObj, result];
|
|
617
|
+
}
|
|
618
|
+
/**
|
|
619
|
+
* Re-adds citations to the cleaned content based on their offsets.
|
|
620
|
+
* @param cleaned The cleaned string without citation tags.
|
|
621
|
+
* @param citations The array of citations with offsets.
|
|
622
|
+
* @returns The string with citation tags re-added.
|
|
623
|
+
*/
|
|
624
|
+
reAddCitations(cleaned, citations) {
|
|
625
|
+
let content = cleaned;
|
|
626
|
+
citations.sort((a, b) => (a.offset ?? 0) - (b.offset ?? 0));
|
|
627
|
+
const adjustment = 0;
|
|
628
|
+
for (const citation of citations) {
|
|
629
|
+
if (citation.offset != null) {
|
|
630
|
+
const position = citation.offset + adjustment;
|
|
631
|
+
content = content.slice(0, position) + citation.tag + content.slice(position);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
return content;
|
|
635
|
+
}
|
|
636
|
+
};
|
|
637
|
+
|
|
500
638
|
// src/component.default.ts
|
|
501
|
-
var Button = {
|
|
639
|
+
var Button = new Component({
|
|
502
640
|
type: "leaf",
|
|
503
641
|
description: "A button component that can perform actions when clicked",
|
|
504
642
|
name: "Button",
|
|
@@ -548,8 +686,8 @@ var Button = {
|
|
|
548
686
|
}
|
|
549
687
|
]
|
|
550
688
|
}
|
|
551
|
-
};
|
|
552
|
-
var Image = {
|
|
689
|
+
});
|
|
690
|
+
var Image = new Component({
|
|
553
691
|
type: "leaf",
|
|
554
692
|
name: "Image",
|
|
555
693
|
description: "Displays an image from a URL.",
|
|
@@ -579,8 +717,8 @@ var Image = {
|
|
|
579
717
|
}
|
|
580
718
|
]
|
|
581
719
|
}
|
|
582
|
-
};
|
|
583
|
-
var File = {
|
|
720
|
+
});
|
|
721
|
+
var File = new Component({
|
|
584
722
|
type: "leaf",
|
|
585
723
|
name: "File",
|
|
586
724
|
description: "Sends a downloadable file to the user.",
|
|
@@ -610,8 +748,8 @@ var File = {
|
|
|
610
748
|
}
|
|
611
749
|
]
|
|
612
750
|
}
|
|
613
|
-
};
|
|
614
|
-
var Video = {
|
|
751
|
+
});
|
|
752
|
+
var Video = new Component({
|
|
615
753
|
type: "leaf",
|
|
616
754
|
name: "Video",
|
|
617
755
|
description: "Embeds a video from a URL.",
|
|
@@ -641,8 +779,8 @@ var Video = {
|
|
|
641
779
|
}
|
|
642
780
|
]
|
|
643
781
|
}
|
|
644
|
-
};
|
|
645
|
-
var Audio = {
|
|
782
|
+
});
|
|
783
|
+
var Audio = new Component({
|
|
646
784
|
type: "leaf",
|
|
647
785
|
name: "Audio",
|
|
648
786
|
description: "Plays an audio clip from a URL.",
|
|
@@ -672,8 +810,8 @@ var Audio = {
|
|
|
672
810
|
}
|
|
673
811
|
]
|
|
674
812
|
}
|
|
675
|
-
};
|
|
676
|
-
var Card = {
|
|
813
|
+
});
|
|
814
|
+
var Card = new Component({
|
|
677
815
|
type: "container",
|
|
678
816
|
name: "Card",
|
|
679
817
|
description: "A visual card component that can include an image and buttons.",
|
|
@@ -709,16 +847,16 @@ var Card = {
|
|
|
709
847
|
children: [
|
|
710
848
|
{
|
|
711
849
|
description: "Image (optional, max 1)",
|
|
712
|
-
component: Image
|
|
850
|
+
component: Image.definition
|
|
713
851
|
},
|
|
714
852
|
{
|
|
715
853
|
description: "Button (optional, up to 5)",
|
|
716
|
-
component: Button
|
|
854
|
+
component: Button.definition
|
|
717
855
|
}
|
|
718
856
|
]
|
|
719
857
|
}
|
|
720
|
-
};
|
|
721
|
-
var Carousel = {
|
|
858
|
+
});
|
|
859
|
+
var Carousel = new Component({
|
|
722
860
|
type: "container",
|
|
723
861
|
name: "Carousel",
|
|
724
862
|
description: "A virtual container for displaying 1 to 10 Card components as a carousel.",
|
|
@@ -746,12 +884,12 @@ var Carousel = {
|
|
|
746
884
|
children: [
|
|
747
885
|
{
|
|
748
886
|
description: "Card component (required, 1\u201310 allowed)",
|
|
749
|
-
component: Card
|
|
887
|
+
component: Card.definition
|
|
750
888
|
}
|
|
751
889
|
]
|
|
752
890
|
}
|
|
753
|
-
};
|
|
754
|
-
var Text = {
|
|
891
|
+
});
|
|
892
|
+
var Text = new Component({
|
|
755
893
|
type: "default",
|
|
756
894
|
name: "Message",
|
|
757
895
|
aliases: ["Text", "Markdown"],
|
|
@@ -769,7 +907,15 @@ var Text = {
|
|
|
769
907
|
props: [],
|
|
770
908
|
children: []
|
|
771
909
|
}
|
|
772
|
-
};
|
|
910
|
+
});
|
|
911
|
+
var messageTool = (handler) => new Tool({
|
|
912
|
+
name: "Message",
|
|
913
|
+
metadata: {
|
|
914
|
+
system: true,
|
|
915
|
+
description: "Sends a message with components like Button, Image, File, Video, Audio, Card, Carousel, and Text."
|
|
916
|
+
},
|
|
917
|
+
handler: async (args) => await handler(args)
|
|
918
|
+
});
|
|
773
919
|
var DefaultComponents = {
|
|
774
920
|
Button,
|
|
775
921
|
Image,
|
|
@@ -783,22 +929,24 @@ var DefaultComponents = {
|
|
|
783
929
|
|
|
784
930
|
// src/index.ts
|
|
785
931
|
var executeContext = async (props) => {
|
|
786
|
-
const { executeContext: executeContext2 } = (await import("./llmz-
|
|
932
|
+
const { executeContext: executeContext2 } = (await import("./llmz-AS5TGCQS.js")).llmz;
|
|
787
933
|
return executeContext2(props);
|
|
788
934
|
};
|
|
789
935
|
var init = async () => {
|
|
790
|
-
await import("./llmz-
|
|
791
|
-
await import("./component-
|
|
792
|
-
await import("./tool-
|
|
793
|
-
await import("./exit-
|
|
794
|
-
await import("./jsx-
|
|
795
|
-
await import("./vm-
|
|
796
|
-
await import("./utils-
|
|
797
|
-
await import("./truncator-
|
|
798
|
-
await import("./typings-
|
|
799
|
-
await import("./dual-modes-
|
|
936
|
+
await import("./llmz-AS5TGCQS.js");
|
|
937
|
+
await import("./component-LQDU72LX.js");
|
|
938
|
+
await import("./tool-LY77IWV2.js");
|
|
939
|
+
await import("./exit-F6ZUL2NV.js");
|
|
940
|
+
await import("./jsx-AEHVFB3L.js");
|
|
941
|
+
await import("./vm-ZUQOSRRM.js");
|
|
942
|
+
await import("./utils-L5GLCS3C.js");
|
|
943
|
+
await import("./truncator-WAL2GCUY.js");
|
|
944
|
+
await import("./typings-AIV2OASX.js");
|
|
945
|
+
await import("./dual-modes-QHBOFWHM.js");
|
|
800
946
|
};
|
|
801
947
|
export {
|
|
948
|
+
CitationsManager,
|
|
949
|
+
Component,
|
|
802
950
|
DefaultComponents,
|
|
803
951
|
Exit,
|
|
804
952
|
ObjectInstance,
|
|
@@ -806,6 +954,9 @@ export {
|
|
|
806
954
|
SnapshotSignal,
|
|
807
955
|
ThinkSignal,
|
|
808
956
|
Tool,
|
|
957
|
+
assertValidComponent,
|
|
809
958
|
executeContext,
|
|
810
|
-
init
|
|
959
|
+
init,
|
|
960
|
+
isComponent,
|
|
961
|
+
messageTool
|
|
811
962
|
};
|
|
@@ -3,9 +3,8 @@ import {
|
|
|
3
3
|
createJsxComponent,
|
|
4
4
|
isAnyJsxComponent,
|
|
5
5
|
isJsxComponent
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
8
|
-
import "./chunk-YSQDPG26.js";
|
|
6
|
+
} from "./chunk-ORQP26SZ.js";
|
|
7
|
+
import "./chunk-7WRN4E42.js";
|
|
9
8
|
export {
|
|
10
9
|
Jsx,
|
|
11
10
|
createJsxComponent,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkKMZDFWYZcjs = require('./chunk-KMZDFWYZ.cjs');
|
|
7
|
+
require('./chunk-UQOBUJIQ.cjs');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
exports.Jsx = _chunkKMZDFWYZcjs.Jsx; exports.createJsxComponent = _chunkKMZDFWYZcjs.createJsxComponent; exports.isAnyJsxComponent = _chunkKMZDFWYZcjs.isAnyJsxComponent; exports.isJsxComponent = _chunkKMZDFWYZcjs.isJsxComponent;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DualModePrompt
|
|
3
|
+
} from "./chunk-TJQVC4CE.js";
|
|
1
4
|
import {
|
|
2
5
|
runAsyncFunction
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-7FIPXMZR.js";
|
|
6
|
+
} from "./chunk-4EWY34YA.js";
|
|
5
7
|
import {
|
|
6
8
|
Snapshot
|
|
7
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-4KB5WXHR.js";
|
|
10
|
+
import "./chunk-EFGXTO64.js";
|
|
8
11
|
import {
|
|
9
12
|
Tool
|
|
10
|
-
} from "./chunk-
|
|
11
|
-
import "./chunk-
|
|
13
|
+
} from "./chunk-QBXIE6EY.js";
|
|
14
|
+
import "./chunk-UNMKB2DA.js";
|
|
12
15
|
import {
|
|
13
16
|
AssignmentError,
|
|
14
17
|
CodeExecutionError,
|
|
@@ -18,41 +21,38 @@ import {
|
|
|
18
21
|
SnapshotSignal,
|
|
19
22
|
ThinkSignal,
|
|
20
23
|
VMSignal
|
|
21
|
-
} from "./chunk-
|
|
22
|
-
import {
|
|
23
|
-
Exit
|
|
24
|
-
} from "./chunk-6QDFMQHA.js";
|
|
25
|
-
import {
|
|
26
|
-
DualModePrompt
|
|
27
|
-
} from "./chunk-QPSUMPLP.js";
|
|
28
|
-
import "./chunk-Q4DEJGXD.js";
|
|
24
|
+
} from "./chunk-JKVVQN2P.js";
|
|
29
25
|
import {
|
|
30
26
|
cleanStackTrace
|
|
31
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-JQBT7UWN.js";
|
|
28
|
+
import {
|
|
29
|
+
Exit
|
|
30
|
+
} from "./chunk-S6WICIDW.js";
|
|
32
31
|
import {
|
|
33
32
|
assertValidComponent
|
|
34
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-ZCPQ3QOW.js";
|
|
34
|
+
import "./chunk-ORQP26SZ.js";
|
|
35
35
|
import {
|
|
36
36
|
truncateWrappedContent,
|
|
37
37
|
wrapContent
|
|
38
|
-
} from "./chunk-
|
|
38
|
+
} from "./chunk-QT4QF3YA.js";
|
|
39
39
|
import {
|
|
40
40
|
init,
|
|
41
41
|
stripInvalidIdentifiers
|
|
42
|
-
} from "./chunk-
|
|
42
|
+
} from "./chunk-5TRUJES5.js";
|
|
43
43
|
import {
|
|
44
44
|
clamp_default,
|
|
45
45
|
cloneDeep_default,
|
|
46
46
|
isEqual_default,
|
|
47
47
|
isPlainObject_default,
|
|
48
48
|
omit_default
|
|
49
|
-
} from "./chunk-
|
|
50
|
-
import "./chunk-YSQDPG26.js";
|
|
49
|
+
} from "./chunk-7WRN4E42.js";
|
|
51
50
|
|
|
52
51
|
// src/llmz.ts
|
|
53
52
|
import { Cognitive } from "@botpress/cognitive";
|
|
54
53
|
import { z } from "@bpinternal/zui";
|
|
55
54
|
import ms from "ms";
|
|
55
|
+
import { ulid as ulid2 } from "ulid";
|
|
56
56
|
|
|
57
57
|
// src/context.ts
|
|
58
58
|
import { ulid } from "ulid";
|
|
@@ -72,15 +72,15 @@ var getValue = async (valueOrGetter, ctx) => {
|
|
|
72
72
|
|
|
73
73
|
// src/handlers.ts
|
|
74
74
|
var Emitter = class {
|
|
75
|
-
|
|
75
|
+
_handlers = [];
|
|
76
76
|
subscribe = (fn) => {
|
|
77
|
-
this.
|
|
77
|
+
this._handlers.push(fn);
|
|
78
78
|
return () => {
|
|
79
|
-
this.
|
|
79
|
+
this._handlers = this._handlers.filter((handler) => handler !== fn);
|
|
80
80
|
};
|
|
81
81
|
};
|
|
82
82
|
emit(event) {
|
|
83
|
-
this.
|
|
83
|
+
this._handlers.forEach((handler) => handler(event));
|
|
84
84
|
}
|
|
85
85
|
};
|
|
86
86
|
var HookedArray = class extends Array {
|
|
@@ -263,6 +263,8 @@ var Context = class {
|
|
|
263
263
|
exits;
|
|
264
264
|
components;
|
|
265
265
|
version = DualModePrompt;
|
|
266
|
+
timeout = 6e4;
|
|
267
|
+
// Default timeout of 60 seconds
|
|
266
268
|
loop;
|
|
267
269
|
temperature;
|
|
268
270
|
model;
|
|
@@ -441,7 +443,7 @@ var Context = class {
|
|
|
441
443
|
throw new Error("Too many tools. Expected at most 100 tools.");
|
|
442
444
|
}
|
|
443
445
|
for (const component of components) {
|
|
444
|
-
assertValidComponent(component);
|
|
446
|
+
assertValidComponent(component.definition);
|
|
445
447
|
}
|
|
446
448
|
const ReservedToolNames = [
|
|
447
449
|
"think",
|
|
@@ -472,7 +474,10 @@ var Context = class {
|
|
|
472
474
|
}
|
|
473
475
|
if (MessageTool && components.length) {
|
|
474
476
|
MessageTool.aliases = Array.from(
|
|
475
|
-
/* @__PURE__ */ new Set([
|
|
477
|
+
/* @__PURE__ */ new Set([
|
|
478
|
+
...MessageTool.aliases,
|
|
479
|
+
...components.flatMap((x) => [x.definition.name, ...x.definition.aliases ?? []])
|
|
480
|
+
])
|
|
476
481
|
);
|
|
477
482
|
}
|
|
478
483
|
const nonMessageTools = tools.filter((x) => {
|
|
@@ -486,10 +491,12 @@ var Context = class {
|
|
|
486
491
|
if (ReservedToolNames.includes(name)) {
|
|
487
492
|
throw new Error(`Tool name "${name}" (${tool.name}) is reserved. Please choose a different name.`);
|
|
488
493
|
}
|
|
489
|
-
if (components.find(
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
494
|
+
if (components.find(
|
|
495
|
+
(x) => {
|
|
496
|
+
var _a2;
|
|
497
|
+
return x.definition.name.toLowerCase() === name || ((_a2 = x.definition.aliases) == null ? void 0 : _a2.map((x2) => x2.toLowerCase()).includes(name));
|
|
498
|
+
}
|
|
499
|
+
)) {
|
|
493
500
|
throw new Error(
|
|
494
501
|
`Tool name "${name}" (${tool.name}) is already used by a component. Please choose a different name.`
|
|
495
502
|
);
|
|
@@ -536,6 +543,7 @@ var Context = class {
|
|
|
536
543
|
this.tools = props.tools;
|
|
537
544
|
this.exits = props.exits;
|
|
538
545
|
this.components = props.components;
|
|
546
|
+
this.timeout = Math.min(999999999, Math.max(0, props.timeout ?? 6e4));
|
|
539
547
|
this.loop = props.loop ?? 3;
|
|
540
548
|
this.temperature = props.temperature ?? 0.7;
|
|
541
549
|
this.model = props.model;
|
|
@@ -565,9 +573,9 @@ var getModelOutputLimit = (inputLength) => clamp_default(
|
|
|
565
573
|
RESPONSE_LENGTH_BUFFER.MAX_TOKENS
|
|
566
574
|
);
|
|
567
575
|
var executeContext = async (props) => {
|
|
568
|
-
var _a, _b, _c;
|
|
576
|
+
var _a, _b, _c, _d;
|
|
569
577
|
await init();
|
|
570
|
-
const { signal, onIterationEnd, onTrace, onExit } = props;
|
|
578
|
+
const { signal, onIterationEnd, onTrace, onExit, onBeforeExecution } = props;
|
|
571
579
|
const cognitive = props.client instanceof Cognitive ? props.client : new Cognitive({ client: props.client });
|
|
572
580
|
const cleanups = [];
|
|
573
581
|
const ctx = new Context({
|
|
@@ -577,6 +585,7 @@ var executeContext = async (props) => {
|
|
|
577
585
|
loop: (_a = props.options) == null ? void 0 : _a.loop,
|
|
578
586
|
temperature: (_b = props.options) == null ? void 0 : _b.temperature,
|
|
579
587
|
model: (_c = props.options) == null ? void 0 : _c.model,
|
|
588
|
+
timeout: (_d = props.options) == null ? void 0 : _d.timeout,
|
|
580
589
|
transcript: props.transcript,
|
|
581
590
|
exits: props.exits,
|
|
582
591
|
components: props.components,
|
|
@@ -593,6 +602,20 @@ var executeContext = async (props) => {
|
|
|
593
602
|
};
|
|
594
603
|
}
|
|
595
604
|
const iteration = await ctx.nextIteration();
|
|
605
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
606
|
+
iteration.end({
|
|
607
|
+
type: "aborted",
|
|
608
|
+
aborted: {
|
|
609
|
+
reason: signal.reason ?? "The operation was aborted"
|
|
610
|
+
}
|
|
611
|
+
});
|
|
612
|
+
return {
|
|
613
|
+
status: "error",
|
|
614
|
+
error: signal.reason ?? "The operation was aborted",
|
|
615
|
+
context: ctx,
|
|
616
|
+
iterations: ctx.iterations
|
|
617
|
+
};
|
|
618
|
+
}
|
|
596
619
|
cleanups.push(
|
|
597
620
|
iteration.traces.onPush((traces) => {
|
|
598
621
|
for (const trace of traces) {
|
|
@@ -606,14 +629,15 @@ var executeContext = async (props) => {
|
|
|
606
629
|
ctx,
|
|
607
630
|
cognitive,
|
|
608
631
|
abortSignal: signal,
|
|
609
|
-
onExit
|
|
632
|
+
onExit,
|
|
633
|
+
onBeforeExecution
|
|
610
634
|
});
|
|
611
635
|
} catch (err) {
|
|
612
636
|
iteration.end({
|
|
613
637
|
type: "execution_error",
|
|
614
638
|
execution_error: {
|
|
615
|
-
|
|
616
|
-
|
|
639
|
+
message: "An unexpected error occurred: " + getErrorMessage(err),
|
|
640
|
+
stack: cleanStackTrace(err.stack ?? "No stack trace available")
|
|
617
641
|
}
|
|
618
642
|
});
|
|
619
643
|
}
|
|
@@ -669,7 +693,8 @@ var executeIteration = async ({
|
|
|
669
693
|
ctx,
|
|
670
694
|
cognitive,
|
|
671
695
|
abortSignal,
|
|
672
|
-
onExit
|
|
696
|
+
onExit,
|
|
697
|
+
onBeforeExecution
|
|
673
698
|
}) => {
|
|
674
699
|
var _a, _b, _c, _d, _e;
|
|
675
700
|
let startedAt = Date.now();
|
|
@@ -687,6 +712,12 @@ var executeIteration = async ({
|
|
|
687
712
|
x.content.trim().length > 0
|
|
688
713
|
)
|
|
689
714
|
);
|
|
715
|
+
traces.push({
|
|
716
|
+
type: "llm_call_started",
|
|
717
|
+
started_at: startedAt,
|
|
718
|
+
ended_at: startedAt,
|
|
719
|
+
model: ctx.model ?? ""
|
|
720
|
+
});
|
|
690
721
|
const output = await cognitive.generateContent({
|
|
691
722
|
signal: abortSignal,
|
|
692
723
|
systemPrompt: (_a = messages.find((x) => x.role === "system")) == null ? void 0 : _a.content,
|
|
@@ -708,6 +739,28 @@ var executeIteration = async ({
|
|
|
708
739
|
}
|
|
709
740
|
const assistantResponse = ctx.version.parseAssistantResponse(out);
|
|
710
741
|
iteration.code = assistantResponse.code.trim();
|
|
742
|
+
if (typeof onBeforeExecution === "function") {
|
|
743
|
+
try {
|
|
744
|
+
await onBeforeExecution(iteration);
|
|
745
|
+
} catch (err) {
|
|
746
|
+
if (err instanceof ThinkSignal) {
|
|
747
|
+
return iteration.end({
|
|
748
|
+
type: "thinking_requested",
|
|
749
|
+
thinking_requested: {
|
|
750
|
+
variables: err.context,
|
|
751
|
+
reason: err.reason
|
|
752
|
+
}
|
|
753
|
+
});
|
|
754
|
+
}
|
|
755
|
+
return iteration.end({
|
|
756
|
+
type: "execution_error",
|
|
757
|
+
execution_error: {
|
|
758
|
+
message: `Error in onBeforeExecution hook: ${getErrorMessage(err)}`,
|
|
759
|
+
stack: cleanStackTrace(err.stack ?? "No stack trace available")
|
|
760
|
+
}
|
|
761
|
+
});
|
|
762
|
+
}
|
|
763
|
+
}
|
|
711
764
|
iteration.llm = {
|
|
712
765
|
cached: output.meta.cached || false,
|
|
713
766
|
ended_at: Date.now(),
|
|
@@ -794,7 +847,7 @@ var executeIteration = async ({
|
|
|
794
847
|
});
|
|
795
848
|
}
|
|
796
849
|
startedAt = Date.now();
|
|
797
|
-
const result = await runAsyncFunction(vmContext,
|
|
850
|
+
const result = await runAsyncFunction(vmContext, iteration.code, traces, abortSignal, ctx.timeout).catch(
|
|
798
851
|
(err) => {
|
|
799
852
|
return {
|
|
800
853
|
success: false,
|
|
@@ -824,7 +877,7 @@ var executeIteration = async ({
|
|
|
824
877
|
type: "execution_error",
|
|
825
878
|
execution_error: {
|
|
826
879
|
message: result.error.message,
|
|
827
|
-
stack: cleanStackTrace(result.error.stack ?? "No stack trace available")
|
|
880
|
+
stack: cleanStackTrace(result.error.stacktrace ?? result.error.stack ?? "No stack trace available")
|
|
828
881
|
}
|
|
829
882
|
});
|
|
830
883
|
}
|
|
@@ -849,7 +902,7 @@ var executeIteration = async ({
|
|
|
849
902
|
return iteration.end({
|
|
850
903
|
type: "thinking_requested",
|
|
851
904
|
thinking_requested: {
|
|
852
|
-
variables: result.signal.
|
|
905
|
+
variables: result.signal.context,
|
|
853
906
|
reason: result.signal.reason
|
|
854
907
|
}
|
|
855
908
|
});
|
|
@@ -942,10 +995,12 @@ var executeIteration = async ({
|
|
|
942
995
|
function wrapTool({ tool, traces, object }) {
|
|
943
996
|
const getToolInput = (input) => tool.zInput.safeParse(input).data ?? input;
|
|
944
997
|
return function(input) {
|
|
998
|
+
const toolCallId = `tcall_${ulid2()}`;
|
|
945
999
|
const alertSlowTool = setTimeout(
|
|
946
1000
|
() => traces.push({
|
|
947
1001
|
type: "tool_slow",
|
|
948
1002
|
tool_name: tool.name,
|
|
1003
|
+
tool_call_id: toolCallId,
|
|
949
1004
|
started_at: Date.now(),
|
|
950
1005
|
input: getToolInput(input),
|
|
951
1006
|
object,
|
|
@@ -985,7 +1040,9 @@ function wrapTool({ tool, traces, object }) {
|
|
|
985
1040
|
return false;
|
|
986
1041
|
};
|
|
987
1042
|
try {
|
|
988
|
-
const result = tool.execute(input
|
|
1043
|
+
const result = tool.execute(input, {
|
|
1044
|
+
callId: toolCallId
|
|
1045
|
+
});
|
|
989
1046
|
if (result instanceof Promise || (result == null ? void 0 : result.then) && (result == null ? void 0 : result.catch)) {
|
|
990
1047
|
return result.then((res) => {
|
|
991
1048
|
output = res;
|
|
@@ -1001,6 +1058,7 @@ function wrapTool({ tool, traces, object }) {
|
|
|
1001
1058
|
cancelSlowTool();
|
|
1002
1059
|
traces.push({
|
|
1003
1060
|
type: "tool_call",
|
|
1061
|
+
tool_call_id: toolCallId,
|
|
1004
1062
|
started_at: toolStart,
|
|
1005
1063
|
ended_at: Date.now(),
|
|
1006
1064
|
tool_name: tool.name,
|
|
@@ -1023,6 +1081,7 @@ function wrapTool({ tool, traces, object }) {
|
|
|
1023
1081
|
cancelSlowTool();
|
|
1024
1082
|
traces.push({
|
|
1025
1083
|
type: "tool_call",
|
|
1084
|
+
tool_call_id: toolCallId,
|
|
1026
1085
|
started_at: toolStart,
|
|
1027
1086
|
ended_at: Date.now(),
|
|
1028
1087
|
tool_name: tool.name,
|