llmz 0.1.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/README.md +185 -98
  2. package/dist/chat.d.ts +34 -0
  3. package/dist/{chunk-TIZWOIDF.js → chunk-33AB6SVX.js} +134 -76
  4. package/dist/{chunk-EFEF2AL7.js → chunk-DH35WO5G.js} +93 -556
  5. package/dist/chunk-E5NHK3FS.js +1637 -0
  6. package/dist/{chunk-L74UZONX.js → chunk-HM5H556L.js} +3 -1
  7. package/dist/chunk-I56MPOVG.cjs +62 -0
  8. package/dist/{chunk-C7T6OJB4.cjs → chunk-IKLFMVSW.cjs} +144 -86
  9. package/dist/chunk-KWQTYXAT.js +62 -0
  10. package/dist/{chunk-JXD2KJVB.cjs → chunk-WWZ2W4WR.cjs} +103 -566
  11. package/dist/chunk-YGKQEVQQ.cjs +1637 -0
  12. package/dist/{chunk-ZPHRTTQX.cjs → chunk-YQT5G77W.cjs} +3 -1
  13. package/dist/compiler/compiler.d.ts +7 -2
  14. package/dist/compiler/index.d.ts +1 -1
  15. package/dist/compiler/plugins/async-wrapper.d.ts +11 -0
  16. package/dist/component-2NYFY6CW.cjs +14 -0
  17. package/dist/{component-2Z3KLWLX.js → component-ASNZHQUR.js} +3 -7
  18. package/dist/component.d.ts +3 -10
  19. package/dist/context.d.ts +88 -2
  20. package/dist/{dual-modes-HEXPFVUE.js → dual-modes-RMF7V7ZQ.js} +2 -4
  21. package/dist/dual-modes-ZZY6QPYT.cjs +10 -0
  22. package/dist/{execute-22PSGL7P.cjs → execute-BXPFSEVX.cjs} +331 -87
  23. package/dist/{execute-ZENBZBWL.js → execute-HIRXXR6X.js} +321 -77
  24. package/dist/index.cjs +502 -27
  25. package/dist/index.d.ts +8 -5
  26. package/dist/index.js +491 -16
  27. package/dist/message-stream/index.d.ts +9 -0
  28. package/dist/message-stream/instructions.d.ts +22 -0
  29. package/dist/message-stream/normalizer.d.ts +21 -0
  30. package/dist/message-stream/parser.d.ts +81 -0
  31. package/dist/message-stream/registry.d.ts +14 -0
  32. package/dist/message-stream/replayable.d.ts +27 -0
  33. package/dist/message-stream/sanitize.d.ts +10 -0
  34. package/dist/message-stream/stream.d.ts +54 -0
  35. package/dist/message-stream/types.d.ts +96 -0
  36. package/dist/message-stream/validator.d.ts +23 -0
  37. package/dist/message-stream/validator.test.d.ts +1 -0
  38. package/dist/prompts/chat-mode/system.md.d.ts +1 -1
  39. package/dist/prompts/chat-mode/user.md.d.ts +1 -1
  40. package/dist/prompts/common.d.ts +5 -5
  41. package/dist/prompts/prompt.d.ts +43 -6
  42. package/dist/prompts/protocol.d.ts +18 -0
  43. package/dist/prompts/worker-mode/system.md.d.ts +1 -1
  44. package/dist/prompts/worker-mode/user.md.d.ts +1 -1
  45. package/dist/result.d.ts +31 -0
  46. package/dist/runtime/execute.test.d.ts +1 -0
  47. package/dist/runtime/generate.d.ts +24 -1
  48. package/dist/runtime/interpret-result.d.ts +10 -0
  49. package/dist/runtime/types.d.ts +29 -4
  50. package/dist/truncator-7PGEGCHV.cjs +12 -0
  51. package/dist/{truncator-3U2QUUJJ.js → truncator-OZOBNYON.js} +3 -1
  52. package/dist/truncator.d.ts +2 -0
  53. package/dist/types.d.ts +8 -1
  54. package/dist/vm/drivers/quickjs.d.ts +2 -0
  55. package/dist/vm/index.d.ts +7 -0
  56. package/dist/vm/instrument.d.ts +1 -1
  57. package/dist/{vm-PYCKS77H.js → vm-44H4UKI2.js} +5 -4
  58. package/dist/{vm-VHB67FVH.cjs → vm-A3OTQVIR.cjs} +4 -3
  59. package/package.json +6 -6
  60. package/dist/chunk-2O3UTPVH.js +0 -813
  61. package/dist/chunk-3T5IU7OU.js +0 -186
  62. package/dist/chunk-BBX2LDZE.cjs +0 -813
  63. package/dist/chunk-CQ3UJW76.cjs +0 -186
  64. package/dist/compiler/plugins/async-iterator.d.ts +0 -6
  65. package/dist/compiler/plugins/braces-tsx.d.ts +0 -3
  66. package/dist/compiler/plugins/html-to-markdown.d.ts +0 -21
  67. package/dist/compiler/plugins/jsx-preserve-newlines.d.ts +0 -5
  68. package/dist/compiler/plugins/jsx-undefined-vars.d.ts +0 -14
  69. package/dist/component-NNHBHD72.cjs +0 -18
  70. package/dist/dual-modes-LLIWZCHC.cjs +0 -12
  71. package/dist/truncator-3ZN7W6NB.cjs +0 -10
  72. /package/dist/{compiler/plugins/html-to-markdown.test.d.ts → message-stream/instructions.test.d.ts} +0 -0
  73. /package/dist/{compiler/plugins/jsx-undefined-vars.test.d.ts → message-stream/normalizer.test.d.ts} +0 -0
  74. /package/dist/{component.test.d.ts → message-stream/parser.test.d.ts} +0 -0
  75. /package/dist/{vm/vm-jsx.test.d.ts → message-stream/stream.test.d.ts} +0 -0
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _class;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _class; var _class2; var _class3; var _class4;
2
2
 
3
3
 
4
4
 
@@ -10,8 +10,14 @@
10
10
 
11
11
 
12
12
 
13
- var _chunkC7T6OJB4cjs = require('./chunk-C7T6OJB4.cjs');
14
- require('./chunk-BBX2LDZE.cjs');
13
+ var _chunkIKLFMVSWcjs = require('./chunk-IKLFMVSW.cjs');
14
+
15
+
16
+
17
+
18
+
19
+
20
+ var _chunkYGKQEVQQcjs = require('./chunk-YGKQEVQQ.cjs');
15
21
 
16
22
 
17
23
  var _chunkWODK7Y4Jcjs = require('./chunk-WODK7Y4J.cjs');
@@ -34,13 +40,15 @@ var _chunkD6PU5YAScjs = require('./chunk-D6PU5YAS.cjs');
34
40
 
35
41
 
36
42
 
37
-
38
- var _chunkCQ3UJW76cjs = require('./chunk-CQ3UJW76.cjs');
43
+ var _chunkI56MPOVGcjs = require('./chunk-I56MPOVG.cjs');
39
44
  require('./chunk-5ZF6NTYI.cjs');
40
45
 
41
46
 
42
47
 
43
- var _chunkZPHRTTQXcjs = require('./chunk-ZPHRTTQX.cjs');
48
+
49
+ var _chunkYQT5G77Wcjs = require('./chunk-YQT5G77W.cjs');
50
+
51
+
44
52
 
45
53
 
46
54
 
@@ -54,14 +62,14 @@ var _chunkFPLSJF4Scjs = require('./chunk-FPLSJF4S.cjs');
54
62
  var _chunkHC2QZTVTcjs = require('./chunk-HC2QZTVT.cjs');
55
63
 
56
64
  // package.json
57
- var version = "0.1.4";
65
+ var version = "0.2.0";
58
66
 
59
67
  // src/objects.ts
60
68
  var _zui = require('@bpinternal/zui');
61
69
 
62
70
  // src/hoist.ts
63
71
  var _generator = require('@babel/generator');
64
- var _parser = require('@babel/parser');
72
+ var _parser2 = require('@babel/parser');
65
73
  var _traverse = require('@babel/traverse'); var _traverse2 = _interopRequireDefault(_traverse);
66
74
  var _types = require('@babel/types'); var t = _interopRequireWildcard(_types);
67
75
  var traverse = _traverse2.default;
@@ -286,7 +294,7 @@ async function hoistTypings(code, formatOptions) {
286
294
  for (let i = 1; i <= 5; i++) {
287
295
  try {
288
296
  const initialCode = code;
289
- const ast = _parser.parse.call(void 0, code, {
297
+ const ast = _parser2.parse.call(void 0, code, {
290
298
  sourceType: "module",
291
299
  plugins: ["typescript"]
292
300
  });
@@ -770,7 +778,7 @@ var CitationsManager = (_class = class {constructor() { _class.prototype.__init.
770
778
 
771
779
  // src/component.default.ts
772
780
 
773
- var Button = new (0, _chunkCQ3UJW76cjs.Component)({
781
+ var Button = new (0, _chunkI56MPOVGcjs.Component)({
774
782
  type: "leaf",
775
783
  description: "A button component that can perform actions when clicked",
776
784
  name: "Button",
@@ -802,7 +810,7 @@ var Button = new (0, _chunkCQ3UJW76cjs.Component)({
802
810
  })
803
811
  }
804
812
  });
805
- var Image = new (0, _chunkCQ3UJW76cjs.Component)({
813
+ var Image = new (0, _chunkI56MPOVGcjs.Component)({
806
814
  type: "leaf",
807
815
  name: "Image",
808
816
  description: "Displays an image from a URL.",
@@ -824,7 +832,7 @@ var Image = new (0, _chunkCQ3UJW76cjs.Component)({
824
832
  })
825
833
  }
826
834
  });
827
- var File = new (0, _chunkCQ3UJW76cjs.Component)({
835
+ var File = new (0, _chunkI56MPOVGcjs.Component)({
828
836
  type: "leaf",
829
837
  name: "File",
830
838
  description: "Sends a downloadable file to the user.",
@@ -846,7 +854,7 @@ var File = new (0, _chunkCQ3UJW76cjs.Component)({
846
854
  })
847
855
  }
848
856
  });
849
- var Video = new (0, _chunkCQ3UJW76cjs.Component)({
857
+ var Video = new (0, _chunkI56MPOVGcjs.Component)({
850
858
  type: "leaf",
851
859
  name: "Video",
852
860
  description: "Embeds a video from a URL.",
@@ -868,7 +876,7 @@ var Video = new (0, _chunkCQ3UJW76cjs.Component)({
868
876
  })
869
877
  }
870
878
  });
871
- var Audio = new (0, _chunkCQ3UJW76cjs.Component)({
879
+ var Audio = new (0, _chunkI56MPOVGcjs.Component)({
872
880
  type: "leaf",
873
881
  name: "Audio",
874
882
  description: "Plays an audio clip from a URL.",
@@ -890,7 +898,7 @@ var Audio = new (0, _chunkCQ3UJW76cjs.Component)({
890
898
  })
891
899
  }
892
900
  });
893
- var Card = new (0, _chunkCQ3UJW76cjs.Component)({
901
+ var Card = new (0, _chunkI56MPOVGcjs.Component)({
894
902
  type: "container",
895
903
  name: "Card",
896
904
  description: "A visual card component that can include an image and buttons.",
@@ -926,7 +934,7 @@ var Card = new (0, _chunkCQ3UJW76cjs.Component)({
926
934
  ]
927
935
  }
928
936
  });
929
- var Carousel = new (0, _chunkCQ3UJW76cjs.Component)({
937
+ var Carousel = new (0, _chunkI56MPOVGcjs.Component)({
930
938
  type: "container",
931
939
  name: "Carousel",
932
940
  description: "A virtual container for displaying 1 to 10 Card components as a carousel.",
@@ -960,11 +968,11 @@ var Carousel = new (0, _chunkCQ3UJW76cjs.Component)({
960
968
  ]
961
969
  }
962
970
  });
963
- var Text = new (0, _chunkCQ3UJW76cjs.Component)({
971
+ var Text = new (0, _chunkI56MPOVGcjs.Component)({
964
972
  type: "default",
965
973
  name: "Message",
966
974
  aliases: ["Text", "Markdown"],
967
- description: "Markdown-formatted text that appears directly inside components like <Message>.",
975
+ description: "A Markdown-formatted text message.",
968
976
  examples: [
969
977
  {
970
978
  name: "Basic Markdown",
@@ -995,6 +1003,7 @@ var Chat = class {
995
1003
 
996
1004
 
997
1005
 
1006
+
998
1007
  /**
999
1008
  * Creates a new Chat instance.
1000
1009
  *
@@ -1045,6 +1054,7 @@ var Chat = class {
1045
1054
  */
1046
1055
  constructor(props) {
1047
1056
  this.handler = props.handler;
1057
+ this.onMessageDelta = props.onMessageDelta;
1048
1058
  this.components = props.components;
1049
1059
  this.transcript = props.transcript || [];
1050
1060
  }
@@ -1108,28 +1118,474 @@ var Chat = class {
1108
1118
  }
1109
1119
  };
1110
1120
 
1121
+ // src/message-stream/replayable.ts
1122
+ var ReplayableAsyncIterable = (_class2 = class {
1123
+
1124
+ __init3() {this._chunks = []}
1125
+ __init4() {this._done = false}
1126
+ __init5() {this._failed = false}
1127
+
1128
+ __init6() {this._lock = Promise.resolve()}
1129
+ constructor(source) {;_class2.prototype.__init3.call(this);_class2.prototype.__init4.call(this);_class2.prototype.__init5.call(this);_class2.prototype.__init6.call(this);
1130
+ this._source = source[Symbol.asyncIterator]();
1131
+ }
1132
+ /** True once the underlying source has been fully consumed (or has failed). */
1133
+ get done() {
1134
+ return this._done;
1135
+ }
1136
+ /** The chunks pulled from the source so far. */
1137
+ get chunks() {
1138
+ return [...this._chunks];
1139
+ }
1140
+ async *[Symbol.asyncIterator]() {
1141
+ let index = 0;
1142
+ while (true) {
1143
+ if (index < this._chunks.length) {
1144
+ yield this._chunks[index++];
1145
+ } else if (this._failed) {
1146
+ throw this._error;
1147
+ } else if (this._done) {
1148
+ return;
1149
+ } else {
1150
+ await this._pull();
1151
+ }
1152
+ }
1153
+ }
1154
+ /** Consumes the entire source and returns all chunks. */
1155
+ async collect() {
1156
+ for await (const _ of this) {
1157
+ }
1158
+ return this.chunks;
1159
+ }
1160
+ _pull() {
1161
+ const next = this._lock.then(async () => {
1162
+ if (this._done) {
1163
+ return;
1164
+ }
1165
+ let result;
1166
+ try {
1167
+ result = await this._source.next();
1168
+ } catch (thrown) {
1169
+ this._done = true;
1170
+ this._failed = true;
1171
+ this._error = thrown;
1172
+ throw thrown;
1173
+ }
1174
+ if (result.done) {
1175
+ this._done = true;
1176
+ } else {
1177
+ this._chunks.push(result.value);
1178
+ }
1179
+ });
1180
+ this._lock = next.catch(() => {
1181
+ });
1182
+ return next;
1183
+ }
1184
+ }, _class2);
1185
+ var collectText = async (iterable) => {
1186
+ let text = "";
1187
+ for await (const chunk of iterable) {
1188
+ text += chunk;
1189
+ }
1190
+ return text;
1191
+ };
1192
+
1193
+ // src/message-stream/stream.ts
1194
+ var BaseResponse = class {
1195
+ constructor(action, item) {
1196
+ this.action = action;
1197
+ this.item = item;
1198
+ }
1199
+ get diagnostics() {
1200
+ return this.item.diagnostics;
1201
+ }
1202
+ };
1203
+ var SendResponse = class extends BaseResponse {
1204
+ constructor(item, content) {
1205
+ super("send", item);
1206
+ this.content = content;
1207
+ }
1208
+ get component() {
1209
+ return this.item.name;
1210
+ }
1211
+ get props() {
1212
+ return this.item.props;
1213
+ }
1214
+ static formatToText(component, props, body) {
1215
+ const header = `${_chunkYGKQEVQQcjs.MARKER}send=${component}${props && Object.keys(props).length ? ` ${JSON.stringify(props)}` : ""}`;
1216
+ return body ? `${header}
1217
+ ${body}` : header;
1218
+ }
1219
+ };
1220
+ var RunResponse = class extends BaseResponse {
1221
+ constructor(item, code) {
1222
+ super("run", item);
1223
+ this.code = code;
1224
+ }
1225
+ static formatToText(code) {
1226
+ return `${_chunkYGKQEVQQcjs.MARKER}run
1227
+ ${code}`;
1228
+ }
1229
+ };
1230
+ var NextResponse = class extends BaseResponse {
1231
+ constructor(item) {
1232
+ super("next", item);
1233
+ }
1234
+ get name() {
1235
+ return this.item.name;
1236
+ }
1237
+ get props() {
1238
+ return this.item.props;
1239
+ }
1240
+ static formatToText(name, props) {
1241
+ return `${_chunkYGKQEVQQcjs.MARKER}next=${name}${props && Object.keys(props).length ? ` ${JSON.stringify(props)}` : ""}`;
1242
+ }
1243
+ };
1244
+ var EventPump = (_class3 = class {
1245
+
1246
+
1247
+ __init7() {this._queue = []}
1248
+ __init8() {this._sourceDone = false}
1249
+ __init9() {this._lock = Promise.resolve()}
1250
+ constructor(stream, parser) {;_class3.prototype.__init7.call(this);_class3.prototype.__init8.call(this);_class3.prototype.__init9.call(this);
1251
+ this._iterator = stream[Symbol.asyncIterator]();
1252
+ this._parser = parser;
1253
+ }
1254
+ next() {
1255
+ const next = this._lock.then(() => this._next());
1256
+ this._lock = next.catch(() => {
1257
+ });
1258
+ return next;
1259
+ }
1260
+ unshift(event) {
1261
+ this._queue.unshift(event);
1262
+ }
1263
+ async _next() {
1264
+ while (this._queue.length === 0) {
1265
+ if (this._sourceDone) {
1266
+ return void 0;
1267
+ }
1268
+ let result;
1269
+ try {
1270
+ result = await this._iterator.next();
1271
+ } catch (e) {
1272
+ this._sourceDone = true;
1273
+ this._queue.push(...this._parser.finish("interrupted"));
1274
+ continue;
1275
+ }
1276
+ if (result.done) {
1277
+ this._sourceDone = true;
1278
+ this._queue.push(...this._parser.finish());
1279
+ } else {
1280
+ this._queue.push(...this._parser.push(result.value));
1281
+ }
1282
+ }
1283
+ return this._queue.shift();
1284
+ }
1285
+ }, _class3);
1286
+ function parseStream(stream, options) {
1287
+ return parseResponses(stream, options);
1288
+ }
1289
+ function parseText(text, options) {
1290
+ return parseResponses(
1291
+ async function* () {
1292
+ yield text;
1293
+ }(),
1294
+ options
1295
+ );
1296
+ }
1297
+ async function* parseResponses(stream, options) {
1298
+ const parser = new (0, _chunkYGKQEVQQcjs.StreamingMessageParser)(options);
1299
+ const pump = new EventPump(stream, parser);
1300
+ let activeBody;
1301
+ while (true) {
1302
+ if (activeBody) {
1303
+ await activeBody.collect();
1304
+ activeBody = void 0;
1305
+ }
1306
+ const event = await pump.next();
1307
+ if (!event) {
1308
+ return;
1309
+ }
1310
+ if (event.type === "item-ready" && (event.item.kind === "send" || event.item.kind === "run")) {
1311
+ const body = new ReplayableAsyncIterable(bodyStream(pump, event.item.id));
1312
+ activeBody = body;
1313
+ yield event.item.kind === "send" ? new SendResponse(event.item, body) : new RunResponse(event.item, body);
1314
+ continue;
1315
+ }
1316
+ if (event.type === "item-complete" && event.item.kind === "next") {
1317
+ yield new NextResponse(event.item);
1318
+ continue;
1319
+ }
1320
+ }
1321
+ }
1322
+ async function* bodyStream(pump, itemId) {
1323
+ while (true) {
1324
+ const event = await pump.next();
1325
+ if (!event) {
1326
+ return;
1327
+ }
1328
+ if (event.type === "body-delta" && event.itemId === itemId) {
1329
+ yield event.delta;
1330
+ continue;
1331
+ }
1332
+ if (event.type === "body-start" && event.itemId === itemId) {
1333
+ continue;
1334
+ }
1335
+ if (event.type === "diagnostic") {
1336
+ continue;
1337
+ }
1338
+ if (event.type === "item-complete" && event.item.id === itemId) {
1339
+ return;
1340
+ }
1341
+ pump.unshift(event);
1342
+ return;
1343
+ }
1344
+ }
1345
+
1346
+ // src/message-stream/registry.ts
1347
+ var ComponentRegistry = (_class4 = class {
1348
+ __init10() {this._definitions = /* @__PURE__ */ new Map()}
1349
+ constructor(definitions = []) {;_class4.prototype.__init10.call(this);
1350
+ for (const definition of definitions) {
1351
+ this.register(definition);
1352
+ }
1353
+ }
1354
+ register(definition) {
1355
+ if (!_chunkYGKQEVQQcjs.NAME_REGEX.test(definition.name)) {
1356
+ throw new Error(
1357
+ `Invalid component name "${definition.name}". Component names must be lowercase ([a-z][a-z0-9_-]*).`
1358
+ );
1359
+ }
1360
+ this._definitions.set(definition.name, definition);
1361
+ }
1362
+ unregister(name) {
1363
+ this._definitions.delete(name);
1364
+ }
1365
+ has(name) {
1366
+ return this._definitions.has(name);
1367
+ }
1368
+ get(name) {
1369
+ return this._definitions.get(name);
1370
+ }
1371
+ list() {
1372
+ return [...this._definitions.values()];
1373
+ }
1374
+ }, _class4);
1375
+
1376
+ // src/message-stream/normalizer.ts
1377
+
1378
+ var EMPTY_PROPS_SCHEMA = { type: "object", properties: {}, additionalProperties: false };
1379
+ var normalizeComponentName = (name) => name.trim().toLowerCase();
1380
+ function normalizeComponentDefinition(definition) {
1381
+ const name = normalizeComponentName(_nullishCoalesce(definition.name, () => ( "")));
1382
+ if (!_chunkYGKQEVQQcjs.NAME_REGEX.test(name)) {
1383
+ throw new Error(
1384
+ `Invalid component name "${definition.name}". Component names must be lowercase ([a-z][a-z0-9_-]*).`
1385
+ );
1386
+ }
1387
+ return {
1388
+ name,
1389
+ description: definition.description,
1390
+ propsJsonSchema: normalizePropsSchema(definition.props, name),
1391
+ body: definition.body ? {
1392
+ format: definition.body.type,
1393
+ description: definition.body.description,
1394
+ required: _nullishCoalesce(definition.body.required, () => ( false))
1395
+ } : void 0,
1396
+ generation: definition.generation
1397
+ };
1398
+ }
1399
+ function normalizePropsSchema(props, name) {
1400
+ if (props === void 0) {
1401
+ return EMPTY_PROPS_SCHEMA;
1402
+ }
1403
+ if (_chunkFPLSJF4Scjs.isZuiSchema.call(void 0, props)) {
1404
+ try {
1405
+ return _zui.transforms.toJSONSchema(props);
1406
+ } catch (e2) {
1407
+ return _zui.transforms.toJSONSchemaLegacy(props);
1408
+ }
1409
+ }
1410
+ if (_chunkFPLSJF4Scjs.isJsonSchema.call(void 0, props)) {
1411
+ return props;
1412
+ }
1413
+ throw new Error(
1414
+ `Invalid props schema for "${name}". Expected a ZUI/Zod object schema or a JSON schema, but got type "${typeof props}".`
1415
+ );
1416
+ }
1417
+
1418
+ // src/message-stream/validator.ts
1419
+ function validateComponent(item, registry) {
1420
+ const definition = registry.get(item.name);
1421
+ if (!definition) {
1422
+ const registered = registry.list().map((d) => d.name).join(", ") || "(none)";
1423
+ return {
1424
+ valid: false,
1425
+ props: item.props,
1426
+ errors: [
1427
+ {
1428
+ code: "unknown-component",
1429
+ message: `Unknown component "${item.name}". Registered components: ${registered}`
1430
+ }
1431
+ ]
1432
+ };
1433
+ }
1434
+ const errors = [
1435
+ ..._validateProps(item.props, definition),
1436
+ ..._validateBody(item, definition)
1437
+ ];
1438
+ return { valid: errors.length === 0, props: item.props, errors };
1439
+ }
1440
+ function validateProps(props, schema) {
1441
+ const errors = [];
1442
+ _checkValue(props, schema, "", errors);
1443
+ return errors;
1444
+ }
1445
+ var _validateProps = (props, definition) => validateProps(props, definition.propsJsonSchema);
1446
+ var _validateBody = (item, definition) => {
1447
+ var _a;
1448
+ const hasBody = typeof item.body === "string" && item.body.length > 0;
1449
+ if (hasBody && !definition.body) {
1450
+ return [
1451
+ {
1452
+ code: "body-not-allowed",
1453
+ message: `Component "${definition.name}" does not support a body`
1454
+ }
1455
+ ];
1456
+ }
1457
+ if (!hasBody && ((_a = definition.body) == null ? void 0 : _a.required)) {
1458
+ return [
1459
+ {
1460
+ code: "missing-required-body",
1461
+ message: `Component "${definition.name}" requires a body`
1462
+ }
1463
+ ];
1464
+ }
1465
+ return [];
1466
+ };
1467
+ var _typeOf = (value) => {
1468
+ if (value === null)
1469
+ return "null";
1470
+ if (Array.isArray(value))
1471
+ return "array";
1472
+ return typeof value;
1473
+ };
1474
+ var _matchesType = (value, type) => {
1475
+ switch (type) {
1476
+ case "string":
1477
+ return typeof value === "string";
1478
+ case "number":
1479
+ return typeof value === "number";
1480
+ case "integer":
1481
+ return typeof value === "number" && Number.isInteger(value);
1482
+ case "boolean":
1483
+ return typeof value === "boolean";
1484
+ case "null":
1485
+ return value === null;
1486
+ case "array":
1487
+ return Array.isArray(value);
1488
+ case "object":
1489
+ return !!value && typeof value === "object" && !Array.isArray(value);
1490
+ default:
1491
+ return true;
1492
+ }
1493
+ };
1494
+ var _isEqual = (a, b) => JSON.stringify(a) === JSON.stringify(b);
1495
+ var _checkValue = (value, schema, path, errors) => {
1496
+ if (schema === void 0 || typeof schema === "boolean" || typeof schema !== "object") {
1497
+ return;
1498
+ }
1499
+ const label = path || "props";
1500
+ const propError = (message) => {
1501
+ errors.push({ code: "invalid-prop-value", message, path: path || void 0 });
1502
+ };
1503
+ if (schema.const !== void 0 && !_isEqual(value, schema.const)) {
1504
+ propError(`Expected "${label}" to equal ${JSON.stringify(schema.const)}`);
1505
+ return;
1506
+ }
1507
+ if (schema.enum && !schema.enum.some((allowed) => _isEqual(value, allowed))) {
1508
+ propError(`Expected "${label}" to be one of: ${schema.enum.map((v) => JSON.stringify(v)).join(", ")}`);
1509
+ return;
1510
+ }
1511
+ const variants = _nullishCoalesce(schema.anyOf, () => ( schema.oneOf));
1512
+ if (variants == null ? void 0 : variants.length) {
1513
+ const matchesAny = variants.some((variant) => {
1514
+ const variantErrors = [];
1515
+ _checkValue(value, variant, path, variantErrors);
1516
+ return variantErrors.length === 0;
1517
+ });
1518
+ if (!matchesAny) {
1519
+ propError(`Value of "${label}" does not match any of the allowed types`);
1520
+ return;
1521
+ }
1522
+ }
1523
+ if (schema.type) {
1524
+ const types = Array.isArray(schema.type) ? schema.type : [schema.type];
1525
+ if (!types.some((type) => _matchesType(value, type))) {
1526
+ propError(`Expected "${label}" to be of type ${types.join(" | ")}, but got ${_typeOf(value)}`);
1527
+ return;
1528
+ }
1529
+ }
1530
+ if (Array.isArray(value) && schema.items && !Array.isArray(schema.items)) {
1531
+ value.forEach((item, index) => _checkValue(item, schema.items, `${label}[${index}]`, errors));
1532
+ }
1533
+ if (value && typeof value === "object" && !Array.isArray(value)) {
1534
+ const record = value;
1535
+ const properties = _nullishCoalesce(schema.properties, () => ( {}));
1536
+ for (const requiredKey of _nullishCoalesce(schema.required, () => ( []))) {
1537
+ if (record[requiredKey] === void 0) {
1538
+ errors.push({
1539
+ code: "missing-required-prop",
1540
+ message: `Missing required prop "${path ? `${path}.` : ""}${requiredKey}"`,
1541
+ path: path ? `${path}.${requiredKey}` : requiredKey
1542
+ });
1543
+ }
1544
+ }
1545
+ for (const [key, propValue] of Object.entries(record)) {
1546
+ const propSchema = properties[key];
1547
+ const propPath = path ? `${path}.${key}` : key;
1548
+ if (propSchema === void 0) {
1549
+ if (schema.additionalProperties === false) {
1550
+ errors.push({
1551
+ code: "unexpected-prop",
1552
+ message: `Unexpected prop "${propPath}"`,
1553
+ path: propPath
1554
+ });
1555
+ }
1556
+ continue;
1557
+ }
1558
+ _checkValue(propValue, propSchema, propPath, errors);
1559
+ }
1560
+ }
1561
+ };
1562
+
1563
+ // src/message-stream/sanitize.ts
1564
+ var sanitizeMessageText = (value, options = {}) => value.replaceAll(_chunkYGKQEVQQcjs.MARKER, _nullishCoalesce(options.markerReplacement, () => ( "\u25AA")));
1565
+
1111
1566
  // src/index.ts
1112
1567
  var utils = {
1113
1568
  toValidObjectName: _chunkFPLSJF4Scjs.toValidObjectName,
1114
1569
  toValidFunctionName: _chunkFPLSJF4Scjs.toValidFunctionName,
1115
- wrapContent: _chunkZPHRTTQXcjs.wrapContent,
1116
- truncateWrappedContent: _chunkZPHRTTQXcjs.truncateWrappedContent
1570
+ wrapContent: _chunkYQT5G77Wcjs.wrapContent,
1571
+ truncateWrappedContent: _chunkYQT5G77Wcjs.truncateWrappedContent,
1572
+ stripTruncationTags: _chunkYQT5G77Wcjs.stripTruncationTags
1117
1573
  };
1118
1574
  var execute = async (props) => {
1119
- const { executeContext } = await Promise.resolve().then(() => _interopRequireWildcard(require("./execute-22PSGL7P.cjs")));
1575
+ const { executeContext } = await Promise.resolve().then(() => _interopRequireWildcard(require("./execute-BXPFSEVX.cjs")));
1120
1576
  return executeContext(props);
1121
1577
  };
1122
1578
  var init = async () => {
1123
- await Promise.resolve().then(() => _interopRequireWildcard(require("./execute-22PSGL7P.cjs")));
1124
- await Promise.resolve().then(() => _interopRequireWildcard(require("./component-NNHBHD72.cjs")));
1579
+ await Promise.resolve().then(() => _interopRequireWildcard(require("./execute-BXPFSEVX.cjs")));
1580
+ await Promise.resolve().then(() => _interopRequireWildcard(require("./component-2NYFY6CW.cjs")));
1125
1581
  await Promise.resolve().then(() => _interopRequireWildcard(require("./tool-GJ6ZXWS2.cjs")));
1126
1582
  await Promise.resolve().then(() => _interopRequireWildcard(require("./exit-LUJY7JIG.cjs")));
1127
1583
  await Promise.resolve().then(() => _interopRequireWildcard(require("./jsx-ULPWX5TW.cjs")));
1128
- await Promise.resolve().then(() => _interopRequireWildcard(require("./vm-VHB67FVH.cjs")));
1584
+ await Promise.resolve().then(() => _interopRequireWildcard(require("./vm-A3OTQVIR.cjs")));
1129
1585
  await Promise.resolve().then(() => _interopRequireWildcard(require("./utils-GLZVMRWO.cjs")));
1130
- await Promise.resolve().then(() => _interopRequireWildcard(require("./truncator-3ZN7W6NB.cjs")));
1586
+ await Promise.resolve().then(() => _interopRequireWildcard(require("./truncator-7PGEGCHV.cjs")));
1131
1587
  await Promise.resolve().then(() => _interopRequireWildcard(require("./typings-ZTFPPA5W.cjs")));
1132
- await Promise.resolve().then(() => _interopRequireWildcard(require("./dual-modes-LLIWZCHC.cjs")));
1588
+ await Promise.resolve().then(() => _interopRequireWildcard(require("./dual-modes-ZZY6QPYT.cjs")));
1133
1589
  };
1134
1590
 
1135
1591
 
@@ -1161,4 +1617,23 @@ var init = async () => {
1161
1617
 
1162
1618
 
1163
1619
 
1164
- exports.Chat = Chat; exports.CitationsManager = CitationsManager; exports.Component = _chunkCQ3UJW76cjs.Component; exports.DefaultComponents = DefaultComponents; exports.DefaultExit = _chunkC7T6OJB4cjs.DefaultExit; exports.ErrorExecutionResult = _chunkC7T6OJB4cjs.ErrorExecutionResult; exports.ExecutionResult = _chunkC7T6OJB4cjs.ExecutionResult; exports.Exit = _chunkD6PU5YAScjs.Exit; exports.ListenExit = _chunkC7T6OJB4cjs.ListenExit; exports.LoopExceededError = _chunkPK72FAKDcjs.LoopExceededError; exports.ObjectInstance = ObjectInstance; exports.PartialExecutionResult = _chunkC7T6OJB4cjs.PartialExecutionResult; exports.Snapshot = _chunkC7T6OJB4cjs.Snapshot; exports.SnapshotSignal = _chunkPK72FAKDcjs.SnapshotSignal; exports.SuccessExecutionResult = _chunkC7T6OJB4cjs.SuccessExecutionResult; exports.ThinkExit = _chunkC7T6OJB4cjs.ThinkExit; exports.ThinkSignal = _chunkPK72FAKDcjs.ThinkSignal; exports.Tool = _chunkWODK7Y4Jcjs.Tool; exports._CustomModelClient = _chunkC7T6OJB4cjs._CustomModelClient; exports.assertValidComponent = _chunkCQ3UJW76cjs.assertValidComponent; exports.execute = execute; exports.getValue = _chunkC7T6OJB4cjs.getValue; exports.init = init; exports.isAnyComponent = _chunkCQ3UJW76cjs.isAnyComponent; exports.isComponent = _chunkCQ3UJW76cjs.isComponent; exports.parseExit = _chunkC7T6OJB4cjs.parseExit; exports.renderToTsx = _chunkCQ3UJW76cjs.renderToTsx; exports.utils = utils; exports.version = version;
1620
+
1621
+
1622
+
1623
+
1624
+
1625
+
1626
+
1627
+
1628
+
1629
+
1630
+
1631
+
1632
+
1633
+
1634
+
1635
+
1636
+
1637
+
1638
+
1639
+ exports.BaseResponse = BaseResponse; exports.Chat = Chat; exports.CitationsManager = CitationsManager; exports.Component = _chunkI56MPOVGcjs.Component; exports.ComponentRegistry = ComponentRegistry; exports.DefaultComponents = DefaultComponents; exports.DefaultExit = _chunkIKLFMVSWcjs.DefaultExit; exports.ErrorExecutionResult = _chunkIKLFMVSWcjs.ErrorExecutionResult; exports.ExecutionResult = _chunkIKLFMVSWcjs.ExecutionResult; exports.Exit = _chunkD6PU5YAScjs.Exit; exports.ListenExit = _chunkIKLFMVSWcjs.ListenExit; exports.LoopExceededError = _chunkPK72FAKDcjs.LoopExceededError; exports.MARKER = _chunkYGKQEVQQcjs.MARKER; exports.NAME_REGEX = _chunkYGKQEVQQcjs.NAME_REGEX; exports.NextResponse = NextResponse; exports.ObjectInstance = ObjectInstance; exports.PartialExecutionResult = _chunkIKLFMVSWcjs.PartialExecutionResult; exports.ReplayableAsyncIterable = ReplayableAsyncIterable; exports.RunResponse = RunResponse; exports.SendResponse = SendResponse; exports.Snapshot = _chunkIKLFMVSWcjs.Snapshot; exports.SnapshotSignal = _chunkPK72FAKDcjs.SnapshotSignal; exports.StreamingMessageParser = _chunkYGKQEVQQcjs.StreamingMessageParser; exports.SuccessExecutionResult = _chunkIKLFMVSWcjs.SuccessExecutionResult; exports.ThinkExit = _chunkIKLFMVSWcjs.ThinkExit; exports.ThinkSignal = _chunkPK72FAKDcjs.ThinkSignal; exports.Tool = _chunkWODK7Y4Jcjs.Tool; exports._CustomModelClient = _chunkIKLFMVSWcjs._CustomModelClient; exports.assertValidComponent = _chunkI56MPOVGcjs.assertValidComponent; exports.collectText = collectText; exports.execute = execute; exports.generateInstructions = _chunkYGKQEVQQcjs.generateInstructions; exports.getValue = _chunkIKLFMVSWcjs.getValue; exports.init = init; exports.isAnyComponent = _chunkI56MPOVGcjs.isAnyComponent; exports.isComponent = _chunkI56MPOVGcjs.isComponent; exports.normalizeComponentDefinition = normalizeComponentDefinition; exports.normalizeComponentName = normalizeComponentName; exports.normalizePropsSchema = normalizePropsSchema; exports.parseExit = _chunkIKLFMVSWcjs.parseExit; exports.parseStream = parseStream; exports.parseText = parseText; exports.sanitizeMessageText = sanitizeMessageText; exports.tryParseJson = _chunkYGKQEVQQcjs.tryParseJson; exports.utils = utils; exports.validateComponent = validateComponent; exports.validateProps = validateProps; exports.version = version;