llmz 0.7.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/{_baseForOwn-buOZDFbK.cjs → _baseForOwn-BfWDTL8L.cjs} +0 -50
  2. package/dist/common-DdArNQhl.cjs +643 -0
  3. package/dist/common-pgJjFu2Y.js +596 -0
  4. package/dist/compiler-C-OI9sim.cjs +547 -0
  5. package/dist/compiler-CW1VjQsn.js +473 -0
  6. package/dist/{component-BwixNVH8.cjs → component-BXS8vAwO.cjs} +3 -3
  7. package/dist/{component-DGG7d_Mz.js → component-Dq7ZLdvy.js} +1 -1
  8. package/dist/component.d.ts +4 -4
  9. package/dist/component.default.d.ts +60 -87
  10. package/dist/component.default.test.d.ts +1 -0
  11. package/dist/context.d.ts +10 -0
  12. package/dist/{custom-client-CMuy7fXU.js → custom-client-2V9lmzUf.js} +119 -24
  13. package/dist/{custom-client-Bp1TgTKk.cjs → custom-client-HkM1Sdzv.cjs} +124 -29
  14. package/dist/{dual-modes-CfqTk9M8.cjs → dual-modes-Cb7ThvoV.cjs} +1268 -1062
  15. package/dist/{dual-modes-mNyMThtf.js → dual-modes-Cy0_W4O2.js} +1242 -1036
  16. package/dist/example.d.ts +45 -0
  17. package/dist/example.test.d.ts +1 -0
  18. package/dist/{execute-DP_17lYZ.js → execute-Aw4cbIx-.js} +23 -10
  19. package/dist/{execute-msui51b2.cjs → execute-COIHOIKR.cjs} +30 -18
  20. package/dist/{exit-BGi0Kk0y.cjs → exit-DUM96DN1.cjs} +3 -3
  21. package/dist/exit-parser.d.ts +2 -0
  22. package/dist/index.cjs +33 -356
  23. package/dist/index.d.ts +2 -0
  24. package/dist/index.js +13 -337
  25. package/dist/index.workerd.js +9981 -9388
  26. package/dist/{jsx-CIgdGGVs.js → jsx-B0iYyvfr.js} +50 -2
  27. package/dist/{jsx-BWvT6ukg.cjs → jsx-D5Y2cPo-.cjs} +58 -4
  28. package/dist/message-stream/parser.d.ts +3 -0
  29. package/dist/message-stream/types.d.ts +1 -1
  30. package/dist/prompts/chat-mode/system.d.ts +2 -0
  31. package/dist/prompts/chat-mode/user.d.ts +2 -0
  32. package/dist/prompts/execution-history.d.ts +6 -0
  33. package/dist/prompts/execution-state.d.ts +3 -0
  34. package/dist/prompts/prompt.d.ts +26 -0
  35. package/dist/prompts/protocol.test.d.ts +1 -0
  36. package/dist/prompts/worker-mode/system.d.ts +2 -0
  37. package/dist/prompts/worker-mode/user.d.ts +2 -0
  38. package/dist/runtime/types.d.ts +9 -0
  39. package/dist/{tool-ReA9gxMp.cjs → tool-Dy6AJpJH.cjs} +4 -4
  40. package/dist/{truncator-B6aaJaN1.cjs → truncator-CLkouTCO.cjs} +3 -3
  41. package/dist/{typings-BwAz_TM9.cjs → typings-3lsqCbkn.cjs} +3 -3
  42. package/dist/{utils-ZpJm00ed.cjs → utils-3ESwP3yg.cjs} +2 -2
  43. package/dist/{vm-C5vf1LH3.js → vm-BLsHw1da.js} +3 -462
  44. package/dist/{vm-BjkJqSQH.cjs → vm-D6s1zF6M.cjs} +28 -489
  45. package/package.json +1 -1
  46. package/dist/isPlainObject-CSxXVKCk.cjs +0 -56
  47. package/dist/isPlainObject-D39AzPO2.js +0 -51
package/dist/index.js CHANGED
@@ -1,16 +1,17 @@
1
- import { a as StreamingMessageParser, c as NAME_REGEX, o as tryParseJson, r as generateInstructions, s as MARKER } from "./dual-modes-mNyMThtf.js";
2
- import { a as ThinkExit, c as ExecutionResult, d as Snapshot, f as parseExit, i as ListenExit, l as PartialExecutionResult, o as getValue, r as DefaultExit, s as ErrorExecutionResult, t as _CustomModelClient, u as SuccessExecutionResult } from "./custom-client-CMuy7fXU.js";
1
+ import { a as StreamingMessageParser, c as NAME_REGEX, o as tryParseJson, s as MARKER } from "./common-pgJjFu2Y.js";
2
+ import { a as Example, h as ComponentRegistry, m as validateProps, o as generateInstructions, p as validateComponent, s as DefaultComponents } from "./dual-modes-Cy0_W4O2.js";
3
+ import { a as ThinkExit, c as ExecutionResult, d as Snapshot, f as parseExit, i as ListenExit, l as PartialExecutionResult, o as getValue, r as DefaultExit, s as ErrorExecutionResult, t as _CustomModelClient, u as SuccessExecutionResult } from "./custom-client-2V9lmzUf.js";
3
4
  import { a as getMultilineComment, c as isJsonSchema, l as isValidIdentifier, m as toValidObjectName, n as escapeString, p as toValidFunctionName, t as configureTokenizer, u as isZuiSchema, v as upperFirst } from "./utils-UBeAFeEI.js";
5
+ import { a as isComponent, i as isAnyComponent, n as assertValidComponent, t as Component } from "./component-Dq7ZLdvy.js";
4
6
  import { t as Tool } from "./tool-Bv8N4IPj.js";
5
7
  import { c as SnapshotSignal, l as ThinkSignal, o as LoopExceededError, r as CodeFormattingError } from "./errors-Cg1G0Awu.js";
6
8
  import { a as isPunct, i as isGroup, o as parse, r as formatTypings, s as tokenize, t as getTypings } from "./typings-CrBa7Tyy.js";
7
9
  import { t as Exit } from "./exit-CDdxDBRT.js";
8
- import { a as isComponent, i as isAnyComponent, n as assertValidComponent, t as Component } from "./component-DGG7d_Mz.js";
9
10
  import { i as wrapContent, n as truncateWrappedContent, t as stripTruncationTags } from "./truncator-DZqEqnpD.js";
10
11
  import { t as configureQuickJS } from "./quickjs-variant-BYhMBpwU.js";
11
12
  import { transforms, z } from "@bpinternal/zui";
12
13
  //#region package.json
13
- var version = "0.7.1";
14
+ var version = "0.8.0";
14
15
  //#endregion
15
16
  //#region src/hoist.ts
16
17
  /**
@@ -790,173 +791,6 @@ var CitationsManager = class {
790
791
  }
791
792
  };
792
793
  //#endregion
793
- //#region src/component.default.ts
794
- const Button = new Component({
795
- type: "leaf",
796
- description: "A button component that can perform actions when clicked",
797
- name: "Button",
798
- aliases: ["btn"],
799
- generation: {
800
- usage: "Attach quick actions to a message, e.g. postback choices or a URL to open.",
801
- examples: [{ props: {
802
- action: "postback",
803
- label: "Buy",
804
- value: "buy_product"
805
- } }]
806
- },
807
- leaf: { props: z.object({
808
- action: z.enum([
809
- "say",
810
- "url",
811
- "postback"
812
- ]).default("say").describe("The action to perform when the button is clicked. Can be \"say\", \"url\", or \"postback\""),
813
- label: z.string().describe("The text displayed on the button (min 1 character, max 250 characters)"),
814
- value: z.string().optional().describe("The postback value to send when the button is clicked. Required if action is \"postback\""),
815
- url: z.string().optional().describe("The URL to open when the button is clicked. Required if action is \"url\"")
816
- }) }
817
- });
818
- const Image = new Component({
819
- type: "leaf",
820
- name: "Image",
821
- description: "Displays an image from a URL.",
822
- aliases: [],
823
- generation: { examples: [{ props: {
824
- url: "https://example.com/photo.jpg",
825
- alt: "Example image"
826
- } }] },
827
- leaf: { props: z.object({
828
- url: z.string().describe("The URL of the image (must be valid)"),
829
- alt: z.string().optional().describe("Alternative text describing the image")
830
- }) }
831
- });
832
- const File = new Component({
833
- type: "leaf",
834
- name: "File",
835
- description: "Sends a downloadable file to the user.",
836
- aliases: [],
837
- generation: { examples: [{ props: {
838
- url: "https://example.com/report.pdf",
839
- name: "Report.pdf"
840
- } }] },
841
- leaf: { props: z.object({
842
- url: z.string().describe("The URL of the file (must be valid)"),
843
- name: z.string().optional().describe("The display name of the file")
844
- }) }
845
- });
846
- const Video = new Component({
847
- type: "leaf",
848
- name: "Video",
849
- description: "Embeds a video from a URL.",
850
- aliases: [],
851
- generation: { examples: [{ props: {
852
- url: "https://example.com/intro.mp4",
853
- title: "Welcome"
854
- } }] },
855
- leaf: { props: z.object({
856
- url: z.string().describe("The URL of the video (must be valid)"),
857
- title: z.string().optional().describe("Title for the video")
858
- }) }
859
- });
860
- const Audio = new Component({
861
- type: "leaf",
862
- name: "Audio",
863
- description: "Plays an audio clip from a URL.",
864
- aliases: [],
865
- generation: { examples: [{ props: {
866
- url: "https://example.com/audio.mp3",
867
- title: "Sample"
868
- } }] },
869
- leaf: { props: z.object({
870
- url: z.string().describe("The URL of the audio clip (must be valid)"),
871
- title: z.string().optional().describe("Title for the audio clip")
872
- }) }
873
- });
874
- const Card = new Component({
875
- type: "container",
876
- name: "Card",
877
- description: "A visual card component that can include an image and buttons.",
878
- aliases: [],
879
- generation: { examples: [{
880
- props: {
881
- title: "Product Name",
882
- subtitle: "Limited offer"
883
- },
884
- body: "Featured product of the week."
885
- }] },
886
- container: {
887
- props: z.object({
888
- title: z.string().min(1).max(250).describe("Title text (1–250 characters)"),
889
- subtitle: z.string().optional().describe("Optional subtitle for the card")
890
- }),
891
- children: [{
892
- description: "Image (optional, max 1)",
893
- component: Image.definition
894
- }, {
895
- description: "Button (optional, up to 5)",
896
- component: Button.definition
897
- }]
898
- }
899
- });
900
- const DefaultComponents = {
901
- Button,
902
- Image,
903
- File,
904
- Video,
905
- Audio,
906
- Card,
907
- Carousel: new Component({
908
- type: "container",
909
- name: "Carousel",
910
- description: "A virtual container for displaying 1 to 10 Card components as a carousel.",
911
- aliases: [],
912
- container: {
913
- props: z.object({}),
914
- children: [{
915
- description: "Card component (required, 1–10 allowed)",
916
- component: Card.definition
917
- }]
918
- }
919
- }),
920
- Text: new Component({
921
- type: "default",
922
- name: "Message",
923
- aliases: ["Text", "Markdown"],
924
- description: "A Markdown-formatted text message. Long answers are written the same way: plain Markdown prose.",
925
- generation: { examples: [{ body: `Great question! Deploying happens in three steps.
926
-
927
- First, connect your repository from the dashboard — we support GitHub and GitLab. Once connected, every push to your main branch triggers a build automatically.
928
-
929
- Then configure your build settings:
930
-
931
- - **Build command** — usually \`npm run build\`
932
- - **Output directory** — where the compiled assets end up
933
-
934
- Finally, hit **Deploy**. The first build takes a couple of minutes; subsequent ones are incremental and much faster. Want me to walk you through connecting your repository?` }, { body: "**Hello**, welcome to our service!" }] },
935
- default: {
936
- props: z.object({}),
937
- children: []
938
- }
939
- }),
940
- Speech: new Component({
941
- type: "default",
942
- name: "Speech",
943
- aliases: ["speak", "spoken"],
944
- description: "A message spoken aloud to the user via text-to-speech.",
945
- body: {
946
- format: "text",
947
- description: "Plain conversational prose only, written to be read aloud: no Markdown, no links or URLs, no emojis, no code, no bullet points, tables or headings. Write everything the way it should be pronounced — spell out numbers, dates, units and abbreviations (e.g. \"June third at three thirty PM\", not \"06/03 @ 3:30pm\")."
948
- },
949
- generation: {
950
- usage: "Use when the reply will be played back as audio (voice conversations).",
951
- examples: [{ body: "Sure! Your order shipped this morning and should arrive on Tuesday, June third, around noon." }]
952
- },
953
- default: {
954
- props: z.object({}),
955
- children: []
956
- }
957
- })
958
- };
959
- //#endregion
960
794
  //#region src/chat.ts
961
795
  /**
962
796
  * Base class for implementing chat interfaces in LLMz agents.
@@ -1497,34 +1331,6 @@ async function* bodyStream(pump, itemId) {
1497
1331
  }
1498
1332
  }
1499
1333
  //#endregion
1500
- //#region src/message-stream/registry.ts
1501
- /**
1502
- * Stores normalized component definitions. The registry (not the parser) is the
1503
- * single source of truth for which components exist and how they are validated.
1504
- */
1505
- var ComponentRegistry = class {
1506
- _definitions = /* @__PURE__ */ new Map();
1507
- constructor(definitions = []) {
1508
- for (const definition of definitions) this.register(definition);
1509
- }
1510
- register(definition) {
1511
- if (!NAME_REGEX.test(definition.name)) throw new Error(`Invalid component name "${definition.name}". Component names must be lowercase ([a-z][a-z0-9_-]*).`);
1512
- this._definitions.set(definition.name, definition);
1513
- }
1514
- unregister(name) {
1515
- this._definitions.delete(name);
1516
- }
1517
- has(name) {
1518
- return this._definitions.has(name);
1519
- }
1520
- get(name) {
1521
- return this._definitions.get(name);
1522
- }
1523
- list() {
1524
- return [...this._definitions.values()];
1525
- }
1526
- };
1527
- //#endregion
1528
1334
  //#region src/message-stream/normalizer.ts
1529
1335
  const EMPTY_PROPS_SCHEMA = {
1530
1336
  type: "object",
@@ -1558,137 +1364,6 @@ function normalizePropsSchema(props, name) {
1558
1364
  throw new Error(`Invalid props schema for "${name}". Expected a ZUI/Zod object schema or a JSON schema, but got type "${typeof props}".`);
1559
1365
  }
1560
1366
  //#endregion
1561
- //#region src/message-stream/validator.ts
1562
- /**
1563
- * Validates a syntactically parsed `■send` item against the registered
1564
- * component definitions. Validation is intentionally separate from parsing: a
1565
- * validation failure never stops the stream, it only produces errors the caller
1566
- * can turn into diagnostics or fallback rendering.
1567
- */
1568
- function validateComponent(item, registry) {
1569
- const definition = registry.get(item.name);
1570
- if (!definition) {
1571
- const registered = registry.list().map((d) => d.name).join(", ") || "(none)";
1572
- return {
1573
- valid: false,
1574
- props: item.props,
1575
- errors: [{
1576
- code: "unknown-component",
1577
- message: `Unknown component "${item.name}". Registered components: ${registered}`
1578
- }]
1579
- };
1580
- }
1581
- const errors = [..._validateProps(item.props, definition), ..._validateBody(item, definition)];
1582
- return {
1583
- valid: errors.length === 0,
1584
- props: item.props,
1585
- errors
1586
- };
1587
- }
1588
- /** Validates a props object against a JSON schema (also used for `■next` exit props). */
1589
- function validateProps(props, schema) {
1590
- const errors = [];
1591
- _checkValue(props, schema, "", errors);
1592
- return errors;
1593
- }
1594
- const _validateProps = (props, definition) => validateProps(props, definition.propsJsonSchema);
1595
- const _validateBody = (item, definition) => {
1596
- var _definition$body;
1597
- const hasBody = typeof item.body === "string" && item.body.length > 0;
1598
- if (hasBody && !definition.body) return [{
1599
- code: "body-not-allowed",
1600
- message: `Component "${definition.name}" does not support a body`
1601
- }];
1602
- if (!hasBody && ((_definition$body = definition.body) === null || _definition$body === void 0 ? void 0 : _definition$body.required)) return [{
1603
- code: "missing-required-body",
1604
- message: `Component "${definition.name}" requires a body`
1605
- }];
1606
- return [];
1607
- };
1608
- const _typeOf = (value) => {
1609
- if (value === null) return "null";
1610
- if (Array.isArray(value)) return "array";
1611
- return typeof value;
1612
- };
1613
- const _matchesType = (value, type) => {
1614
- switch (type) {
1615
- case "string": return typeof value === "string";
1616
- case "number": return typeof value === "number";
1617
- case "integer": return typeof value === "number" && Number.isInteger(value);
1618
- case "boolean": return typeof value === "boolean";
1619
- case "null": return value === null;
1620
- case "array": return Array.isArray(value);
1621
- case "object": return !!value && typeof value === "object" && !Array.isArray(value);
1622
- default: return true;
1623
- }
1624
- };
1625
- const _isEqual = (a, b) => JSON.stringify(a) === JSON.stringify(b);
1626
- /**
1627
- * Minimal JSON-schema subset checker covering what component schemas need:
1628
- * type, enum, const, required, properties, additionalProperties, items, anyOf/oneOf.
1629
- * Unknown keywords are ignored (lenient by design).
1630
- */
1631
- const _checkValue = (value, schema, path, errors) => {
1632
- if (schema === void 0 || typeof schema === "boolean" || typeof schema !== "object") return;
1633
- const label = path || "props";
1634
- const propError = (message) => {
1635
- errors.push({
1636
- code: "invalid-prop-value",
1637
- message,
1638
- path: path || void 0
1639
- });
1640
- };
1641
- if (schema.const !== void 0 && !_isEqual(value, schema.const)) {
1642
- propError(`Expected "${label}" to equal ${JSON.stringify(schema.const)}`);
1643
- return;
1644
- }
1645
- if (schema.enum && !schema.enum.some((allowed) => _isEqual(value, allowed))) {
1646
- propError(`Expected "${label}" to be one of: ${schema.enum.map((v) => JSON.stringify(v)).join(", ")}`);
1647
- return;
1648
- }
1649
- const variants = schema.anyOf ?? schema.oneOf;
1650
- if (variants === null || variants === void 0 ? void 0 : variants.length) {
1651
- if (!variants.some((variant) => {
1652
- const variantErrors = [];
1653
- _checkValue(value, variant, path, variantErrors);
1654
- return variantErrors.length === 0;
1655
- })) {
1656
- propError(`Value of "${label}" does not match any of the allowed types`);
1657
- return;
1658
- }
1659
- }
1660
- if (schema.type) {
1661
- const types = Array.isArray(schema.type) ? schema.type : [schema.type];
1662
- if (!types.some((type) => _matchesType(value, type))) {
1663
- propError(`Expected "${label}" to be of type ${types.join(" | ")}, but got ${_typeOf(value)}`);
1664
- return;
1665
- }
1666
- }
1667
- if (Array.isArray(value) && schema.items && !Array.isArray(schema.items)) value.forEach((item, index) => _checkValue(item, schema.items, `${label}[${index}]`, errors));
1668
- if (value && typeof value === "object" && !Array.isArray(value)) {
1669
- const record = value;
1670
- const properties = schema.properties ?? {};
1671
- for (const requiredKey of schema.required ?? []) if (record[requiredKey] === void 0) errors.push({
1672
- code: "missing-required-prop",
1673
- message: `Missing required prop "${path ? `${path}.` : ""}${requiredKey}"`,
1674
- path: path ? `${path}.${requiredKey}` : requiredKey
1675
- });
1676
- for (const [key, propValue] of Object.entries(record)) {
1677
- const propSchema = properties[key];
1678
- const propPath = path ? `${path}.${key}` : key;
1679
- if (propSchema === void 0) {
1680
- if (schema.additionalProperties === false) errors.push({
1681
- code: "unexpected-prop",
1682
- message: `Unexpected prop "${propPath}"`,
1683
- path: propPath
1684
- });
1685
- continue;
1686
- }
1687
- _checkValue(propValue, propSchema, propPath, errors);
1688
- }
1689
- }
1690
- };
1691
- //#endregion
1692
1367
  //#region src/message-stream/sanitize.ts
1693
1368
  /**
1694
1369
  * The protocol has no escaping mechanism by design. Any untrusted text that is
@@ -1715,6 +1390,7 @@ const utils = {
1715
1390
  * @param props - Configuration object for the execution
1716
1391
  * @param props.client - Botpress Client or Cognitive Client instance for LLM generation
1717
1392
  * @param props.instructions - System prompt/instructions for the LLM (static string or dynamic function)
1393
+ * @param props.examples - Optional labeled few-shot examples (static array or dynamic function)
1718
1394
  * @param props.chat - Optional Chat instance to enable Chat Mode with user interaction
1719
1395
  * @param props.tools - Array of Tool instances available to the agent (static or dynamic)
1720
1396
  * @param props.objects - Array of ObjectInstance for namespaced tools and variables (static or dynamic)
@@ -1773,7 +1449,7 @@ const utils = {
1773
1449
  * })
1774
1450
  */
1775
1451
  const execute = async (props) => {
1776
- const { executeContext } = await import("./execute-DP_17lYZ.js");
1452
+ const { executeContext } = await import("./execute-Aw4cbIx-.js");
1777
1453
  return executeContext(props);
1778
1454
  };
1779
1455
  /**
@@ -1782,16 +1458,16 @@ const execute = async (props) => {
1782
1458
  * It's recommended to call this function at the beginning of your application without awaiting it (void init())
1783
1459
  */
1784
1460
  const init = async () => {
1785
- await import("./execute-DP_17lYZ.js");
1786
- await import("./component-DGG7d_Mz.js").then((n) => n.r);
1461
+ await import("./execute-Aw4cbIx-.js");
1462
+ await import("./component-Dq7ZLdvy.js").then((n) => n.r);
1787
1463
  await import("./tool-Bv8N4IPj.js").then((n) => n.n);
1788
1464
  await import("./exit-CDdxDBRT.js").then((n) => n.n);
1789
- await import("./jsx-CIgdGGVs.js").then((n) => n.i);
1790
- await import("./vm-C5vf1LH3.js");
1465
+ await import("./jsx-B0iYyvfr.js").then((n) => n.i);
1466
+ await import("./vm-BLsHw1da.js");
1791
1467
  await import("./utils-UBeAFeEI.js").then((n) => n.h);
1792
1468
  await import("./truncator-DZqEqnpD.js").then((n) => n.r);
1793
1469
  await import("./typings-CrBa7Tyy.js").then((n) => n.n);
1794
- await import("./dual-modes-mNyMThtf.js").then((n) => n.n);
1470
+ await import("./dual-modes-Cy0_W4O2.js").then((n) => n.n);
1795
1471
  };
1796
1472
  //#endregion
1797
- export { BaseResponse, Chat, CitationsManager, Component, ComponentRegistry, DefaultComponents, DefaultExit, ErrorExecutionResult, ExecutionResult, Exit, ListenExit, LoopExceededError, MARKER, NAME_REGEX, NextResponse, ObjectInstance, PartialExecutionResult, ReplayableAsyncIterable, RunResponse, SendResponse, Snapshot, SnapshotSignal, StreamingMessageParser, SuccessExecutionResult, ThinkExit, ThinkSignal, Tool, _CustomModelClient, assertValidComponent, collectText, configureQuickJS, configureTokenizer, execute, generateInstructions, getValue, init, isAnyComponent, isComponent, normalizeComponentDefinition, normalizeComponentName, normalizePropsSchema, parseExit, parseStream, parseText, sanitizeMessageText, tryParseJson, utils, validateComponent, validateProps, version };
1473
+ export { BaseResponse, Chat, CitationsManager, Component, ComponentRegistry, DefaultComponents, DefaultExit, ErrorExecutionResult, Example, ExecutionResult, Exit, ListenExit, LoopExceededError, MARKER, NAME_REGEX, NextResponse, ObjectInstance, PartialExecutionResult, ReplayableAsyncIterable, RunResponse, SendResponse, Snapshot, SnapshotSignal, StreamingMessageParser, SuccessExecutionResult, ThinkExit, ThinkSignal, Tool, _CustomModelClient, assertValidComponent, collectText, configureQuickJS, configureTokenizer, execute, generateInstructions, getValue, init, isAnyComponent, isComponent, normalizeComponentDefinition, normalizeComponentName, normalizePropsSchema, parseExit, parseStream, parseText, sanitizeMessageText, tryParseJson, utils, validateComponent, validateProps, version };