llmz 0.1.0 → 0.1.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.
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } var _class; var _class2;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } var _class; var _class2; var _class3;
2
2
 
3
3
 
4
4
 
@@ -1423,6 +1423,15 @@ var Context = (_class2 = class {
1423
1423
  }
1424
1424
  }, _class2);
1425
1425
 
1426
+ // src/custom-client.ts
1427
+ var _CustomModelClient = (_class3 = class __CustomModelClient {constructor() { _class3.prototype.__init6.call(this); }
1428
+ __init6() {this["$$COGNITIVE"] = "runtime"}
1429
+ static isCustomClient(obj) {
1430
+ return obj instanceof __CustomModelClient || (obj == null ? void 0 : obj["$$COGNITIVE"]) === "runtime";
1431
+ }
1432
+ }, _class3);
1433
+
1434
+
1426
1435
 
1427
1436
 
1428
1437
 
@@ -1435,4 +1444,4 @@ var Context = (_class2 = class {
1435
1444
 
1436
1445
 
1437
1446
 
1438
- exports.parseExit = parseExit; exports.Snapshot = Snapshot; exports.ExecutionResult = ExecutionResult; exports.SuccessExecutionResult = SuccessExecutionResult; exports.ErrorExecutionResult = ErrorExecutionResult; exports.PartialExecutionResult = PartialExecutionResult; exports.getValue = getValue; exports.ThinkExit = ThinkExit; exports.ListenExit = ListenExit; exports.DefaultExit = DefaultExit; exports.Context = Context;
1447
+ exports.parseExit = parseExit; exports.Snapshot = Snapshot; exports.ExecutionResult = ExecutionResult; exports.SuccessExecutionResult = SuccessExecutionResult; exports.ErrorExecutionResult = ErrorExecutionResult; exports.PartialExecutionResult = PartialExecutionResult; exports.getValue = getValue; exports.ThinkExit = ThinkExit; exports.ListenExit = ListenExit; exports.DefaultExit = DefaultExit; exports.Context = Context; exports._CustomModelClient = _CustomModelClient;
@@ -1423,6 +1423,14 @@ var Context = class {
1423
1423
  }
1424
1424
  };
1425
1425
 
1426
+ // src/custom-client.ts
1427
+ var _CustomModelClient = class __CustomModelClient {
1428
+ ["$$COGNITIVE"] = "runtime";
1429
+ static isCustomClient(obj) {
1430
+ return obj instanceof __CustomModelClient || (obj == null ? void 0 : obj["$$COGNITIVE"]) === "runtime";
1431
+ }
1432
+ };
1433
+
1426
1434
  export {
1427
1435
  parseExit,
1428
1436
  Snapshot,
@@ -1434,5 +1442,6 @@ export {
1434
1442
  ThinkExit,
1435
1443
  ListenExit,
1436
1444
  DefaultExit,
1437
- Context
1445
+ Context,
1446
+ _CustomModelClient
1438
1447
  };
@@ -0,0 +1,18 @@
1
+ import { Model } from '@botpress/cognitive';
2
+ import { RuntimeCognitive } from './runtime/types.js';
3
+ export type RuntimeGenerateContentInput = Parameters<RuntimeCognitive['generateContent']>[0];
4
+ export type RuntimeGenerateContentOutput = Awaited<ReturnType<RuntimeCognitive['generateContent']>>;
5
+ /**
6
+ * Internal escape hatch for supplying a custom model client that bypasses Cognitive.
7
+ *
8
+ * Intended for use by the Botpress engineering team only (e.g. running benchmarks
9
+ * against arbitrary models). It is intentionally undocumented and offers no stability
10
+ * guarantees — the API may change or be removed without notice. Avoid it unless you
11
+ * fully understand the implications.
12
+ */
13
+ export declare abstract class _CustomModelClient implements RuntimeCognitive {
14
+ private readonly ['$$COGNITIVE'];
15
+ static isCustomClient(obj: any): obj is _CustomModelClient;
16
+ abstract getModelDetails(model: string): Promise<Model>;
17
+ abstract generateContent(input: RuntimeGenerateContentInput): Promise<RuntimeGenerateContentOutput>;
18
+ }
@@ -8,7 +8,8 @@ var _chunkJXD2KJVBcjs = require('./chunk-JXD2KJVB.cjs');
8
8
 
9
9
 
10
10
 
11
- var _chunkPQGZQQA6cjs = require('./chunk-PQGZQQA6.cjs');
11
+
12
+ var _chunkC7T6OJB4cjs = require('./chunk-C7T6OJB4.cjs');
12
13
  require('./chunk-BBX2LDZE.cjs');
13
14
  require('./chunk-WODK7Y4J.cjs');
14
15
  require('./chunk-7LMIOS6H.cjs');
@@ -243,7 +244,7 @@ var interpretVMResult = async ({
243
244
  });
244
245
  return;
245
246
  }
246
- const parsedExit = _chunkPQGZQQA6cjs.parseExit.call(void 0, returnValue, iteration.exits);
247
+ const parsedExit = _chunkC7T6OJB4cjs.parseExit.call(void 0, returnValue, iteration.exits);
247
248
  if (!parsedExit.success) {
248
249
  iteration.end({
249
250
  type: "exit_error",
@@ -537,8 +538,8 @@ var executeContextInternal = async (props) => {
537
538
  const controller = createJoinedAbortController([props.signal]);
538
539
  const { onIterationStart, onIterationEnd, onTrace, onExit, onBeforeExecution, onAfterTool, onBeforeTool } = props;
539
540
  const client = _nullishCoalesce(props.client, () => ( new (0, _client.Client)()));
540
- const cognitive = _cognitive.Cognitive.isCognitiveClient(client) ? client : _cognitive.CognitiveBeta.isBetaClient(client) ? _cognitive.cognitiveFromBeta.call(void 0, client) : new (0, _cognitive.Cognitive)({ client, __experimental_beta: true });
541
- const ctx = new (0, _chunkPQGZQQA6cjs.Context)({
541
+ const cognitive = _cognitive.Cognitive.isCognitiveClient(client) || _chunkC7T6OJB4cjs._CustomModelClient.isCustomClient(client) ? client : _cognitive.CognitiveBeta.isBetaClient(client) ? _cognitive.cognitiveFromBeta.call(void 0, client) : new (0, _cognitive.Cognitive)({ client, __experimental_beta: true });
542
+ const ctx = new (0, _chunkC7T6OJB4cjs.Context)({
542
543
  chat: props.chat,
543
544
  instructions: props.instructions,
544
545
  objects: props.objects,
@@ -554,7 +555,7 @@ var executeContextInternal = async (props) => {
554
555
  try {
555
556
  while (true) {
556
557
  if (ctx.iterations.length >= ctx.loop) {
557
- return new (0, _chunkPQGZQQA6cjs.ErrorExecutionResult)(ctx, new (0, _chunkPK72FAKDcjs.LoopExceededError)());
558
+ return new (0, _chunkC7T6OJB4cjs.ErrorExecutionResult)(ctx, new (0, _chunkPK72FAKDcjs.LoopExceededError)());
558
559
  }
559
560
  const iteration = await ctx.nextIteration();
560
561
  const unsubscribeTrace = iteration.traces.onPush((traces) => {
@@ -585,7 +586,7 @@ var executeContextInternal = async (props) => {
585
586
  }
586
587
  }
587
588
  });
588
- return new (0, _chunkPQGZQQA6cjs.ErrorExecutionResult)(ctx, _nullishCoalesce(controller.signal.reason, () => ( "The operation was aborted")));
589
+ return new (0, _chunkC7T6OJB4cjs.ErrorExecutionResult)(ctx, _nullishCoalesce(controller.signal.reason, () => ( "The operation was aborted")));
589
590
  }
590
591
  const iterationResult = await executeIterationWithErrorHandling({
591
592
  iteration,
@@ -614,7 +615,7 @@ var executeContextInternal = async (props) => {
614
615
  }
615
616
  }
616
617
  } catch (error) {
617
- return new (0, _chunkPQGZQQA6cjs.ErrorExecutionResult)(ctx, _nullishCoalesce(error, () => ( "Unknown error")));
618
+ return new (0, _chunkC7T6OJB4cjs.ErrorExecutionResult)(ctx, _nullishCoalesce(error, () => ( "Unknown error")));
618
619
  }
619
620
  };
620
621
  var executeIterationStartHook = async ({
@@ -699,7 +700,7 @@ var executeIterationWithErrorHandling = async ({
699
700
  if (!controller.signal.aborted) {
700
701
  return {
701
702
  type: "return",
702
- result: new (0, _chunkPQGZQQA6cjs.ErrorExecutionResult)(ctx, err)
703
+ result: new (0, _chunkC7T6OJB4cjs.ErrorExecutionResult)(ctx, err)
703
704
  };
704
705
  }
705
706
  await finalizeIteration({
@@ -715,7 +716,7 @@ var executeIterationWithErrorHandling = async ({
715
716
  });
716
717
  return {
717
718
  type: "return",
718
- result: new (0, _chunkPQGZQQA6cjs.ErrorExecutionResult)(ctx, _nullishCoalesce(controller.signal.reason, () => ( "The operation was aborted")))
719
+ result: new (0, _chunkC7T6OJB4cjs.ErrorExecutionResult)(ctx, _nullishCoalesce(controller.signal.reason, () => ( "The operation was aborted")))
719
720
  };
720
721
  }
721
722
  };
@@ -727,7 +728,7 @@ var transformIterationResult = ({
727
728
  const exitName = iteration.status.exit_success.exit_name;
728
729
  return {
729
730
  type: "return",
730
- result: new (0, _chunkPQGZQQA6cjs.SuccessExecutionResult)(ctx, {
731
+ result: new (0, _chunkC7T6OJB4cjs.SuccessExecutionResult)(ctx, {
731
732
  exit: iteration.exits.find((x) => x.name === exitName),
732
733
  result: iteration.status.exit_success.return_value
733
734
  })
@@ -736,17 +737,17 @@ var transformIterationResult = ({
736
737
  if (iteration.status.type === "callback_requested") {
737
738
  return {
738
739
  type: "return",
739
- result: new (0, _chunkPQGZQQA6cjs.PartialExecutionResult)(
740
+ result: new (0, _chunkC7T6OJB4cjs.PartialExecutionResult)(
740
741
  ctx,
741
742
  iteration.status.callback_requested.signal,
742
- _chunkPQGZQQA6cjs.Snapshot.fromSignal(iteration.status.callback_requested.signal)
743
+ _chunkC7T6OJB4cjs.Snapshot.fromSignal(iteration.status.callback_requested.signal)
743
744
  )
744
745
  };
745
746
  }
746
747
  if (iteration.status.type === "aborted") {
747
748
  return {
748
749
  type: "return",
749
- result: new (0, _chunkPQGZQQA6cjs.ErrorExecutionResult)(ctx, _nullishCoalesce(iteration.error, () => ( "The operation was aborted")))
750
+ result: new (0, _chunkC7T6OJB4cjs.ErrorExecutionResult)(ctx, _nullishCoalesce(iteration.error, () => ( "The operation was aborted")))
750
751
  };
751
752
  }
752
753
  if (iteration.status.type === "thinking_requested" || iteration.status.type === "exit_error" || iteration.status.type === "execution_error" || iteration.status.type === "invalid_code_error") {
@@ -754,7 +755,7 @@ var transformIterationResult = ({
754
755
  }
755
756
  return {
756
757
  type: "return",
757
- result: new (0, _chunkPQGZQQA6cjs.ErrorExecutionResult)(ctx, _nullishCoalesce(iteration.error, () => ( `Unknown error. Status: ${iteration.status.type}`)))
758
+ result: new (0, _chunkC7T6OJB4cjs.ErrorExecutionResult)(ctx, _nullishCoalesce(iteration.error, () => ( `Unknown error. Status: ${iteration.status.type}`)))
758
759
  };
759
760
  };
760
761
  var executeIteration = async ({
@@ -7,8 +7,9 @@ import {
7
7
  PartialExecutionResult,
8
8
  Snapshot,
9
9
  SuccessExecutionResult,
10
+ _CustomModelClient,
10
11
  parseExit
11
- } from "./chunk-NK2NCYSY.js";
12
+ } from "./chunk-TIZWOIDF.js";
12
13
  import "./chunk-2O3UTPVH.js";
13
14
  import "./chunk-IRCB4FRM.js";
14
15
  import "./chunk-TOGYDN6U.js";
@@ -537,7 +538,7 @@ var executeContextInternal = async (props) => {
537
538
  const controller = createJoinedAbortController([props.signal]);
538
539
  const { onIterationStart, onIterationEnd, onTrace, onExit, onBeforeExecution, onAfterTool, onBeforeTool } = props;
539
540
  const client = props.client ?? new Client();
540
- const cognitive = Cognitive.isCognitiveClient(client) ? client : CognitiveBeta.isBetaClient(client) ? cognitiveFromBeta(client) : new Cognitive({ client, __experimental_beta: true });
541
+ const cognitive = Cognitive.isCognitiveClient(client) || _CustomModelClient.isCustomClient(client) ? client : CognitiveBeta.isBetaClient(client) ? cognitiveFromBeta(client) : new Cognitive({ client, __experimental_beta: true });
541
542
  const ctx = new Context({
542
543
  chat: props.chat,
543
544
  instructions: props.instructions,
package/dist/index.cjs CHANGED
@@ -9,7 +9,8 @@
9
9
 
10
10
 
11
11
 
12
- var _chunkPQGZQQA6cjs = require('./chunk-PQGZQQA6.cjs');
12
+
13
+ var _chunkC7T6OJB4cjs = require('./chunk-C7T6OJB4.cjs');
13
14
  require('./chunk-BBX2LDZE.cjs');
14
15
 
15
16
 
@@ -53,7 +54,7 @@ var _chunkFPLSJF4Scjs = require('./chunk-FPLSJF4S.cjs');
53
54
  var _chunkHC2QZTVTcjs = require('./chunk-HC2QZTVT.cjs');
54
55
 
55
56
  // package.json
56
- var version = "0.1.0";
57
+ var version = "0.1.1";
57
58
 
58
59
  // src/objects.ts
59
60
  var _zui = require('@bpinternal/zui');
@@ -1115,11 +1116,11 @@ var utils = {
1115
1116
  truncateWrappedContent: _chunkZPHRTTQXcjs.truncateWrappedContent
1116
1117
  };
1117
1118
  var execute = async (props) => {
1118
- const { executeContext } = await Promise.resolve().then(() => _interopRequireWildcard(require("./execute-2BVFYTJT.cjs")));
1119
+ const { executeContext } = await Promise.resolve().then(() => _interopRequireWildcard(require("./execute-7MDJHUHO.cjs")));
1119
1120
  return executeContext(props);
1120
1121
  };
1121
1122
  var init = async () => {
1122
- await Promise.resolve().then(() => _interopRequireWildcard(require("./execute-2BVFYTJT.cjs")));
1123
+ await Promise.resolve().then(() => _interopRequireWildcard(require("./execute-7MDJHUHO.cjs")));
1123
1124
  await Promise.resolve().then(() => _interopRequireWildcard(require("./component-NNHBHD72.cjs")));
1124
1125
  await Promise.resolve().then(() => _interopRequireWildcard(require("./tool-GJ6ZXWS2.cjs")));
1125
1126
  await Promise.resolve().then(() => _interopRequireWildcard(require("./exit-LUJY7JIG.cjs")));
@@ -1159,4 +1160,5 @@ var init = async () => {
1159
1160
 
1160
1161
 
1161
1162
 
1162
- exports.Chat = Chat; exports.CitationsManager = CitationsManager; exports.Component = _chunkCQ3UJW76cjs.Component; exports.DefaultComponents = DefaultComponents; exports.DefaultExit = _chunkPQGZQQA6cjs.DefaultExit; exports.ErrorExecutionResult = _chunkPQGZQQA6cjs.ErrorExecutionResult; exports.ExecutionResult = _chunkPQGZQQA6cjs.ExecutionResult; exports.Exit = _chunkD6PU5YAScjs.Exit; exports.ListenExit = _chunkPQGZQQA6cjs.ListenExit; exports.LoopExceededError = _chunkPK72FAKDcjs.LoopExceededError; exports.ObjectInstance = ObjectInstance; exports.PartialExecutionResult = _chunkPQGZQQA6cjs.PartialExecutionResult; exports.Snapshot = _chunkPQGZQQA6cjs.Snapshot; exports.SnapshotSignal = _chunkPK72FAKDcjs.SnapshotSignal; exports.SuccessExecutionResult = _chunkPQGZQQA6cjs.SuccessExecutionResult; exports.ThinkExit = _chunkPQGZQQA6cjs.ThinkExit; exports.ThinkSignal = _chunkPK72FAKDcjs.ThinkSignal; exports.Tool = _chunkWODK7Y4Jcjs.Tool; exports.assertValidComponent = _chunkCQ3UJW76cjs.assertValidComponent; exports.execute = execute; exports.getValue = _chunkPQGZQQA6cjs.getValue; exports.init = init; exports.isAnyComponent = _chunkCQ3UJW76cjs.isAnyComponent; exports.isComponent = _chunkCQ3UJW76cjs.isComponent; exports.parseExit = _chunkPQGZQQA6cjs.parseExit; exports.renderToTsx = _chunkCQ3UJW76cjs.renderToTsx; exports.utils = utils; exports.version = version;
1163
+
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;
package/dist/index.d.ts CHANGED
@@ -19,6 +19,7 @@ export { type Iteration, ListenExit, ThinkExit, DefaultExit, IterationStatuses,
19
19
  export { type Context } from './context.js';
20
20
  export type { LLMzPrompts } from './prompts/prompt.js';
21
21
  export { type ValueOrGetter, getValue } from './getter.js';
22
+ export * from './custom-client.js';
22
23
  export declare const utils: {
23
24
  toValidObjectName: (str: string) => string;
24
25
  toValidFunctionName: (str: string) => string;
package/dist/index.js CHANGED
@@ -7,9 +7,10 @@ import {
7
7
  Snapshot,
8
8
  SuccessExecutionResult,
9
9
  ThinkExit,
10
+ _CustomModelClient,
10
11
  getValue,
11
12
  parseExit
12
- } from "./chunk-NK2NCYSY.js";
13
+ } from "./chunk-TIZWOIDF.js";
13
14
  import "./chunk-2O3UTPVH.js";
14
15
  import {
15
16
  Tool
@@ -53,7 +54,7 @@ import {
53
54
  } from "./chunk-34GJUS6U.js";
54
55
 
55
56
  // package.json
56
- var version = "0.1.0";
57
+ var version = "0.1.1";
57
58
 
58
59
  // src/objects.ts
59
60
  import { z } from "@bpinternal/zui";
@@ -1115,11 +1116,11 @@ var utils = {
1115
1116
  truncateWrappedContent
1116
1117
  };
1117
1118
  var execute = async (props) => {
1118
- const { executeContext } = await import("./execute-EZXXBWB6.js");
1119
+ const { executeContext } = await import("./execute-TPUSOWBP.js");
1119
1120
  return executeContext(props);
1120
1121
  };
1121
1122
  var init = async () => {
1122
- await import("./execute-EZXXBWB6.js");
1123
+ await import("./execute-TPUSOWBP.js");
1123
1124
  await import("./component-2Z3KLWLX.js");
1124
1125
  await import("./tool-DNHVW3KC.js");
1125
1126
  await import("./exit-VJATJTQI.js");
@@ -1149,6 +1150,7 @@ export {
1149
1150
  ThinkExit,
1150
1151
  ThinkSignal,
1151
1152
  Tool,
1153
+ _CustomModelClient,
1152
1154
  assertValidComponent,
1153
1155
  execute,
1154
1156
  getValue,
@@ -1,6 +1,7 @@
1
1
  import { Cognitive, CognitiveBeta, type BotpressClientLike, Models } from '@botpress/cognitive';
2
2
  import { Chat } from '../chat.js';
3
3
  import { Context, Iteration } from '../context.js';
4
+ import { _CustomModelClient } from '../custom-client.js';
4
5
  import { Exit, ExitResult } from '../exit.js';
5
6
  import { ValueOrGetter } from '../getter.js';
6
7
  import { type ObjectInstance } from '../objects.js';
@@ -169,7 +170,7 @@ export type ExecutionProps = {
169
170
  * This is used to generate content using the LLM and to access the Botpress API.
170
171
  * If not provided, a default client will be created using environment variables.
171
172
  */
172
- client?: Cognitive | CognitiveBeta | BotpressClientLike;
173
+ client?: Cognitive | CognitiveBeta | BotpressClientLike | _CustomModelClient;
173
174
  /**
174
175
  * When provided, the execution will immediately stop when the signal is aborted.
175
176
  * This will stop the LLM generation, as well as kill the VM sandbox execution.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "llmz",
3
3
  "type": "module",
4
4
  "description": "LLMz - An LLM-native Typescript VM built on top of Zui",
5
- "version": "0.1.0",
5
+ "version": "0.1.1",
6
6
  "types": "./dist/index.d.ts",
7
7
  "main": "./dist/index.cjs",
8
8
  "module": "./dist/index.js",
@@ -71,7 +71,7 @@
71
71
  "tsx": "^4.19.2"
72
72
  },
73
73
  "peerDependencies": {
74
- "@botpress/client": "1.46.0",
74
+ "@botpress/client": "1.47.0",
75
75
  "@botpress/cognitive": "0.6.1",
76
76
  "@bpinternal/thicktoken": "^2.0.0",
77
77
  "@bpinternal/zui": "^2.3.0"