@botpress/runtime 1.3.4 → 1.3.6

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/library.js CHANGED
@@ -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.4", 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.6", 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
 
@@ -35895,6 +35895,12 @@ var AutonomousToolSpan = {
35895
35895
  name: "autonomous.tool",
35896
35896
  importance: "high",
35897
35897
  attributes: {
35898
+ "autonomous.tool.object": {
35899
+ type: "string",
35900
+ title: "Object Name",
35901
+ description: "The name of the object being used",
35902
+ required: false
35903
+ },
35898
35904
  "autonomous.tool.name": {
35899
35905
  type: "string",
35900
35906
  title: "Tool Name",
@@ -40249,6 +40255,7 @@ var WellKnownMetadata = {
40249
40255
 
40250
40256
  // src/runtime/autonomous.ts
40251
40257
  var import_lodash2 = __toESM(require_lodash(), 1);
40258
+ import { AsyncResource } from "node:async_hooks";
40252
40259
  var Autonomous;
40253
40260
  ((Autonomous2) => {
40254
40261
  Autonomous2.Tool = LlmzTool;
@@ -40367,7 +40374,7 @@ If the question is not related to the knowledge bases, do NOT use this tool.`.tr
40367
40374
  options.interruption
40368
40375
  ]);
40369
40376
  const llmz_execute = (await import("llmz")).execute;
40370
- const originalContext = context.getAll();
40377
+ const asyncResource = new AsyncResource("autonomous.execution");
40371
40378
  const getNewIteration = (index) => createSpan(
40372
40379
  "autonomous.iteration",
40373
40380
  {
@@ -40425,32 +40432,27 @@ Always prefer information from the knowledge bases over general knowledge when a
40425
40432
  });
40426
40433
  return instructions;
40427
40434
  },
40428
- ...(props.tools || props.knowledge) && {
40429
- tools: async (ctx) => {
40430
- const tools = props.tools ? await getValue(props.tools, ctx) : [];
40431
- const allTools = [...tools ?? []];
40432
- if (search_knowledge) {
40433
- allTools.push(search_knowledge);
40434
- }
40435
+ ...props.objects && {
40436
+ objects: async (ctx) => {
40437
+ const objs = await getValue(props.objects, ctx) ?? [];
40435
40438
  iterationSpan?.setAttribute(
40436
- "autonomous.tools",
40437
- allTools?.map((t) => t.name).join(", ")
40439
+ "autonomous.objects",
40440
+ objs.map((o) => o.name).join(", ")
40438
40441
  );
40439
- return allTools.map(
40440
- (tool) => tool.clone({
40441
- handler: (args, ctx2) => {
40442
- context.enterWith(originalContext);
40443
- return context.run(originalContext, () => {
40442
+ for (const obj of objs) {
40443
+ obj.tools = obj.tools?.map(
40444
+ (tool) => tool.clone({
40445
+ handler: asyncResource.bind((args, ctx2) => {
40444
40446
  let err = null;
40445
40447
  const result = span(
40446
40448
  "autonomous.tool",
40447
40449
  {
40450
+ "autonomous.tool.object": obj.name,
40448
40451
  "autonomous.tool.name": tool.name,
40449
40452
  "autonomous.tool.input": args
40450
40453
  },
40451
40454
  async (s) => {
40452
- context.enterWith(originalContext);
40453
- const value = await tool.execute(args, ctx2).catch((e) => {
40455
+ const value = tool.execute(args, ctx2).catch((e) => {
40454
40456
  err = e;
40455
40457
  if (err && err?.constructor && err?.constructor?.name && err?.constructor?.name === "ThinkSignal") {
40456
40458
  s.setAttributes({
@@ -40486,25 +40488,92 @@ Always prefer information from the knowledge bases over general knowledge when a
40486
40488
  throw err;
40487
40489
  }
40488
40490
  return result;
40489
- });
40490
- }
40491
+ })
40492
+ })
40493
+ ) ?? [];
40494
+ }
40495
+ return objs;
40496
+ }
40497
+ },
40498
+ ...(props.tools || props.knowledge) && {
40499
+ tools: async (ctx) => {
40500
+ const tools = props.tools ? await getValue(props.tools, ctx) : [];
40501
+ const allTools = [...tools ?? []];
40502
+ if (search_knowledge) {
40503
+ allTools.push(search_knowledge);
40504
+ }
40505
+ iterationSpan?.setAttribute(
40506
+ "autonomous.tools",
40507
+ allTools?.map((t) => t.name).join(", ")
40508
+ );
40509
+ return allTools.map(
40510
+ (tool) => tool.clone({
40511
+ handler: asyncResource.bind((args, ctx2) => {
40512
+ let err = null;
40513
+ const result = span(
40514
+ "autonomous.tool",
40515
+ {
40516
+ "autonomous.tool.name": tool.name,
40517
+ "autonomous.tool.input": args
40518
+ },
40519
+ async (s) => {
40520
+ const value = tool.execute(args, ctx2).catch((e) => {
40521
+ err = e;
40522
+ if (err && err?.constructor && err?.constructor?.name && err?.constructor?.name === "ThinkSignal") {
40523
+ s.setAttributes({
40524
+ "autonomous.tool.status": "think"
40525
+ });
40526
+ s.setStatus({
40527
+ code: SpanStatusCode.UNSET,
40528
+ message: "ThinkSignal"
40529
+ });
40530
+ err[HandledErrorProp] = true;
40531
+ throw err;
40532
+ } else {
40533
+ s.setAttributes({
40534
+ "autonomous.tool.status": "error",
40535
+ "autonomous.tool.error": err.message
40536
+ });
40537
+ s.setStatus({
40538
+ code: SpanStatusCode.ERROR,
40539
+ message: err.message
40540
+ });
40541
+ s.recordException(err);
40542
+ throw err;
40543
+ }
40544
+ });
40545
+ s.setAttributes({
40546
+ "autonomous.tool.output": value,
40547
+ "autonomous.tool.status": "success"
40548
+ });
40549
+ return value;
40550
+ }
40551
+ );
40552
+ if (err) {
40553
+ throw err;
40554
+ }
40555
+ return result;
40556
+ })
40491
40557
  })
40492
40558
  );
40493
40559
  }
40494
40560
  },
40495
- ...props.objects && { objects: props.objects },
40496
40561
  ...props.exits && { exits: props.exits },
40497
40562
  ...joinedSignal && { signal: joinedSignal },
40498
40563
  ...props.hooks?.onBeforeTool && {
40499
- onBeforeTool: props.hooks.onBeforeTool
40564
+ onBeforeTool: asyncResource.bind(props.hooks.onBeforeTool)
40500
40565
  },
40501
40566
  ...props.hooks?.onAfterTool && {
40502
- onAfterTool: props.hooks.onAfterTool
40567
+ onAfterTool: asyncResource.bind(props.hooks.onAfterTool)
40503
40568
  },
40504
40569
  ...props.hooks?.onBeforeExecution && {
40505
- onBeforeExecution: props.hooks.onBeforeExecution
40570
+ onBeforeExecution: asyncResource.bind(
40571
+ props.hooks.onBeforeExecution
40572
+ )
40573
+ },
40574
+ ...props.hooks?.onExit && {
40575
+ onExit: asyncResource.bind(props.hooks.onExit)
40506
40576
  },
40507
- ...props.hooks?.onExit && { onExit: props.hooks.onExit },
40508
40577
  onTrace: ({ trace: trace2, iteration }) => {
40509
40578
  if (trace2.type === "code_execution") {
40510
40579
  } else if (trace2.type === "llm_call_started") {
@@ -40518,7 +40587,11 @@ Always prefer information from the knowledge bases over general knowledge when a
40518
40587
  "property.value": trace2.value
40519
40588
  });
40520
40589
  }
40521
- props.hooks?.onTrace?.({ trace: trace2, iteration });
40590
+ if (props.hooks?.onTrace) {
40591
+ return asyncResource.runInAsyncScope(
40592
+ () => props.hooks.onTrace({ trace: trace2, iteration })
40593
+ );
40594
+ }
40522
40595
  },
40523
40596
  onIterationEnd: async (iteration, controller) => {
40524
40597
  iterationSpan?.setAttributes({
@@ -40566,8 +40639,11 @@ ${iteration.status.execution_error.stack}`;
40566
40639
  });
40567
40640
  }
40568
40641
  iterationSpan?.end();
40569
- contextManager.enterWith(execSpan.ctx);
40570
- await props.hooks?.onIterationEnd?.(iteration, controller);
40642
+ if (props.hooks?.onIterationEnd) {
40643
+ return await asyncResource.runInAsyncScope(
40644
+ () => props.hooks.onIterationEnd(iteration, controller)
40645
+ );
40646
+ }
40571
40647
  }
40572
40648
  });
40573
40649
  execSpan.setAttribute(
@@ -42661,6 +42737,7 @@ init_define_BUILD();
42661
42737
  init_define_PACKAGE_VERSIONS();
42662
42738
  import {
42663
42739
  Chat,
42740
+ DefaultComponents,
42664
42741
  isAnyComponent as isAnyComponent2
42665
42742
  } from "llmz";
42666
42743
 
@@ -42855,9 +42932,6 @@ ${openTag}${inner}${closeTag}
42855
42932
  \`\`\``;
42856
42933
  }
42857
42934
 
42858
- // src/runtime/chat/chat.ts
42859
- import { DefaultComponents } from "llmz";
42860
-
42861
42935
  // ../../node_modules/.bun/dedent@1.7.0/node_modules/dedent/dist/dedent.mjs
42862
42936
  init_define_BUILD();
42863
42937
  init_define_PACKAGE_VERSIONS();
@@ -42987,9 +43061,6 @@ var Transcript = {
42987
43061
  init_define_BUILD();
42988
43062
  init_define_PACKAGE_VERSIONS();
42989
43063
 
42990
- // src/runtime/chat/chat.ts
42991
- var OutgoingMessages = Object.values(DefaultComponents);
42992
-
42993
43064
  // src/runtime/chat/transcript.ts
42994
43065
  init_define_BUILD();
42995
43066
  init_define_PACKAGE_VERSIONS();