@botpress/runtime 1.3.3 → 1.3.5

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.
@@ -48,7 +48,7 @@ var init_define_BUILD = __esm({
48
48
  var define_PACKAGE_VERSIONS_default;
49
49
  var init_define_PACKAGE_VERSIONS = __esm({
50
50
  "<define:__PACKAGE_VERSIONS__>"() {
51
- define_PACKAGE_VERSIONS_default = { runtime: "1.3.3", adk: "not-installed", sdk: "4.17.0", llmz: "0.0.26", zai: "2.1.16", cognitive: "0.1.47" };
51
+ define_PACKAGE_VERSIONS_default = { runtime: "1.3.5", adk: "not-installed", sdk: "4.17.0", llmz: "0.0.26", zai: "2.1.16", cognitive: "0.1.47" };
52
52
  }
53
53
  });
54
54
 
@@ -39770,6 +39770,7 @@ var WellKnownMetadata = {
39770
39770
 
39771
39771
  // src/runtime/autonomous.ts
39772
39772
  var import_lodash2 = __toESM(require_lodash(), 1);
39773
+ import { AsyncResource } from "node:async_hooks";
39773
39774
  var Autonomous;
39774
39775
  ((Autonomous2) => {
39775
39776
  Autonomous2.Tool = LlmzTool;
@@ -39888,7 +39889,7 @@ If the question is not related to the knowledge bases, do NOT use this tool.`.tr
39888
39889
  options.interruption
39889
39890
  ]);
39890
39891
  const llmz_execute = (await import("llmz")).execute;
39891
- const originalContext = context2.getAll();
39892
+ const asyncResource = new AsyncResource("autonomous.execution");
39892
39893
  const getNewIteration = (index) => createSpan(
39893
39894
  "autonomous.iteration",
39894
39895
  {
@@ -39946,32 +39947,27 @@ Always prefer information from the knowledge bases over general knowledge when a
39946
39947
  });
39947
39948
  return instructions;
39948
39949
  },
39949
- ...(props.tools || props.knowledge) && {
39950
- tools: async (ctx) => {
39951
- const tools = props.tools ? await getValue(props.tools, ctx) : [];
39952
- const allTools = [...tools ?? []];
39953
- if (search_knowledge) {
39954
- allTools.push(search_knowledge);
39955
- }
39950
+ ...props.objects && {
39951
+ objects: async (ctx) => {
39952
+ const objs = await getValue(props.objects, ctx) ?? [];
39956
39953
  iterationSpan?.setAttribute(
39957
- "autonomous.tools",
39958
- allTools?.map((t) => t.name).join(", ")
39954
+ "autonomous.objects",
39955
+ objs.map((o) => o.name).join(", ")
39959
39956
  );
39960
- return allTools.map(
39961
- (tool) => tool.clone({
39962
- handler: (args, ctx2) => {
39963
- context2.enterWith(originalContext);
39964
- return context2.run(originalContext, () => {
39957
+ for (const obj of objs) {
39958
+ obj.tools = obj.tools?.map(
39959
+ (tool) => tool.clone({
39960
+ handler: asyncResource.bind((args, ctx2) => {
39965
39961
  let err = null;
39966
39962
  const result = span(
39967
39963
  "autonomous.tool",
39968
39964
  {
39965
+ "autonomous.tool.object": obj.name,
39969
39966
  "autonomous.tool.name": tool.name,
39970
39967
  "autonomous.tool.input": args
39971
39968
  },
39972
39969
  async (s) => {
39973
- context2.enterWith(originalContext);
39974
- const value = await tool.execute(args, ctx2).catch((e) => {
39970
+ const value = tool.execute(args, ctx2).catch((e) => {
39975
39971
  err = e;
39976
39972
  if (err && err?.constructor && err?.constructor?.name && err?.constructor?.name === "ThinkSignal") {
39977
39973
  s.setAttributes({
@@ -40007,25 +40003,92 @@ Always prefer information from the knowledge bases over general knowledge when a
40007
40003
  throw err;
40008
40004
  }
40009
40005
  return result;
40010
- });
40011
- }
40006
+ })
40007
+ })
40008
+ ) ?? [];
40009
+ }
40010
+ return objs;
40011
+ }
40012
+ },
40013
+ ...(props.tools || props.knowledge) && {
40014
+ tools: async (ctx) => {
40015
+ const tools = props.tools ? await getValue(props.tools, ctx) : [];
40016
+ const allTools = [...tools ?? []];
40017
+ if (search_knowledge) {
40018
+ allTools.push(search_knowledge);
40019
+ }
40020
+ iterationSpan?.setAttribute(
40021
+ "autonomous.tools",
40022
+ allTools?.map((t) => t.name).join(", ")
40023
+ );
40024
+ return allTools.map(
40025
+ (tool) => tool.clone({
40026
+ handler: asyncResource.bind((args, ctx2) => {
40027
+ let err = null;
40028
+ const result = span(
40029
+ "autonomous.tool",
40030
+ {
40031
+ "autonomous.tool.name": tool.name,
40032
+ "autonomous.tool.input": args
40033
+ },
40034
+ async (s) => {
40035
+ const value = tool.execute(args, ctx2).catch((e) => {
40036
+ err = e;
40037
+ if (err && err?.constructor && err?.constructor?.name && err?.constructor?.name === "ThinkSignal") {
40038
+ s.setAttributes({
40039
+ "autonomous.tool.status": "think"
40040
+ });
40041
+ s.setStatus({
40042
+ code: SpanStatusCode.UNSET,
40043
+ message: "ThinkSignal"
40044
+ });
40045
+ err[HandledErrorProp] = true;
40046
+ throw err;
40047
+ } else {
40048
+ s.setAttributes({
40049
+ "autonomous.tool.status": "error",
40050
+ "autonomous.tool.error": err.message
40051
+ });
40052
+ s.setStatus({
40053
+ code: SpanStatusCode.ERROR,
40054
+ message: err.message
40055
+ });
40056
+ s.recordException(err);
40057
+ throw err;
40058
+ }
40059
+ });
40060
+ s.setAttributes({
40061
+ "autonomous.tool.output": value,
40062
+ "autonomous.tool.status": "success"
40063
+ });
40064
+ return value;
40065
+ }
40066
+ );
40067
+ if (err) {
40068
+ throw err;
40069
+ }
40070
+ return result;
40071
+ })
40012
40072
  })
40013
40073
  );
40014
40074
  }
40015
40075
  },
40016
- ...props.objects && { objects: props.objects },
40017
40076
  ...props.exits && { exits: props.exits },
40018
40077
  ...joinedSignal && { signal: joinedSignal },
40019
40078
  ...props.hooks?.onBeforeTool && {
40020
- onBeforeTool: props.hooks.onBeforeTool
40079
+ onBeforeTool: asyncResource.bind(props.hooks.onBeforeTool)
40021
40080
  },
40022
40081
  ...props.hooks?.onAfterTool && {
40023
- onAfterTool: props.hooks.onAfterTool
40082
+ onAfterTool: asyncResource.bind(props.hooks.onAfterTool)
40024
40083
  },
40025
40084
  ...props.hooks?.onBeforeExecution && {
40026
- onBeforeExecution: props.hooks.onBeforeExecution
40085
+ onBeforeExecution: asyncResource.bind(
40086
+ props.hooks.onBeforeExecution
40087
+ )
40088
+ },
40089
+ ...props.hooks?.onExit && {
40090
+ onExit: asyncResource.bind(props.hooks.onExit)
40027
40091
  },
40028
- ...props.hooks?.onExit && { onExit: props.hooks.onExit },
40029
40092
  onTrace: ({ trace: trace2, iteration }) => {
40030
40093
  if (trace2.type === "code_execution") {
40031
40094
  } else if (trace2.type === "llm_call_started") {
@@ -40039,7 +40102,11 @@ Always prefer information from the knowledge bases over general knowledge when a
40039
40102
  "property.value": trace2.value
40040
40103
  });
40041
40104
  }
40042
- props.hooks?.onTrace?.({ trace: trace2, iteration });
40105
+ if (props.hooks?.onTrace) {
40106
+ return asyncResource.runInAsyncScope(
40107
+ () => props.hooks.onTrace({ trace: trace2, iteration })
40108
+ );
40109
+ }
40043
40110
  },
40044
40111
  onIterationEnd: async (iteration, controller) => {
40045
40112
  iterationSpan?.setAttributes({
@@ -40087,8 +40154,11 @@ ${iteration.status.execution_error.stack}`;
40087
40154
  });
40088
40155
  }
40089
40156
  iterationSpan?.end();
40090
- contextManager.enterWith(execSpan.ctx);
40091
- await props.hooks?.onIterationEnd?.(iteration, controller);
40157
+ if (props.hooks?.onIterationEnd) {
40158
+ return await asyncResource.runInAsyncScope(
40159
+ () => props.hooks.onIterationEnd(iteration, controller)
40160
+ );
40161
+ }
40092
40162
  }
40093
40163
  });
40094
40164
  execSpan.setAttribute(
@@ -45202,6 +45272,12 @@ var AutonomousToolSpan = {
45202
45272
  name: "autonomous.tool",
45203
45273
  importance: "high",
45204
45274
  attributes: {
45275
+ "autonomous.tool.object": {
45276
+ type: "string",
45277
+ title: "Object Name",
45278
+ description: "The name of the object being used",
45279
+ required: false
45280
+ },
45205
45281
  "autonomous.tool.name": {
45206
45282
  type: "string",
45207
45283
  title: "Tool Name",