@skilder-ai/runtime 0.7.9 → 0.7.11

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/index.js CHANGED
@@ -143971,6 +143971,21 @@ function loadPrompt(name21) {
143971
143971
  return body;
143972
143972
  }
143973
143973
 
143974
+ // src/constants.ts
143975
+ var MAX_ACTIVATION_RETRIES = 3;
143976
+ var ACTIVATION_COOLDOWN_MS = 6e4;
143977
+ var DEFAULT_IDLE_TIMEOUT_MS = 3e5;
143978
+ var DEFAULT_SCRIPT_TIMEOUT_MS = 3e4;
143979
+ var MAX_INTERACTIVE_SCRIPT_TIMEOUT_MS = 3e5;
143980
+ var MAX_SCRIPT_OUTPUT_SIZE = 10485760;
143981
+ var MAX_DELEGATE_DEPTH = 3;
143982
+ var DELEGATE_MCP_CLIENT_TIMEOUT_MS = 3e4;
143983
+ var DELEGATE_GENERATE_TEXT_TIMEOUT_MS = 12e4;
143984
+ var RECONNECT_INITIAL_WAIT_MS = 5e3;
143985
+ var RECONNECT_MAX_WAIT_MS = 10 * 60 * 1e3;
143986
+ var RECONNECT_BACKOFF_MULTIPLIER = 2;
143987
+ var RECONNECT_JITTER_FACTOR = 0.1;
143988
+
143974
143989
  // src/services/delegate.service.ts
143975
143990
  var __decorate9 = function(decorators, target, key, desc) {
143976
143991
  var c3 = arguments.length, r2 = c3 < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d2;
@@ -143989,9 +144004,6 @@ var __param8 = function(paramIndex, decorator) {
143989
144004
  var _a30;
143990
144005
  var _b24;
143991
144006
  var _c2;
143992
- var MAX_DELEGATE_DEPTH = 3;
143993
- var DELEGATE_MCP_CLIENT_TIMEOUT_MS = 3e4;
143994
- var DELEGATE_GENERATE_TEXT_TIMEOUT_MS = 12e4;
143995
144007
  var DelegateService = class DelegateService2 {
143996
144008
  constructor(loggerService, natsService, aiProviderService) {
143997
144009
  this.natsService = natsService;
@@ -144495,7 +144507,7 @@ var SkillService = class SkillService2 extends Service {
144495
144507
  if (this.fileService) {
144496
144508
  tools.push(this.prepareDownloadAssetTool());
144497
144509
  }
144498
- if ((this.identity.delegateDepth ?? 0) < MAX_DELEGATE_DEPTH) {
144510
+ if (process.env.SKILDER_ENABLE_AGENT_DELEGATE === "true" && (this.identity.delegateDepth ?? 0) < MAX_DELEGATE_DEPTH) {
144499
144511
  tools.push(this.prepareDelegateTool());
144500
144512
  }
144501
144513
  return tools;
@@ -144794,7 +144806,12 @@ The path must point to a downloadable (binary) resource in a skill's related ite
144794
144806
  return {
144795
144807
  response: {
144796
144808
  isError: true,
144797
- content: [{ type: "text", text: `Error: Delegate failed unexpectedly: ${error48 instanceof Error ? error48.message : String(error48)}` }]
144809
+ content: [
144810
+ {
144811
+ type: "text",
144812
+ text: `Error: Delegate failed unexpectedly: ${error48 instanceof Error ? error48.message : String(error48)}`
144813
+ }
144814
+ ]
144798
144815
  }
144799
144816
  };
144800
144817
  }
@@ -149489,15 +149506,12 @@ var __param14 = function(paramIndex, decorator) {
149489
149506
  };
149490
149507
  var _a39;
149491
149508
  var ScriptType2 = dgraph_resolvers_types_exports.ScriptType;
149492
- var DEFAULT_TIMEOUT_MS = 3e4;
149493
- var MAX_INTERACTIVE_TIMEOUT_MS = 3e5;
149494
- var MAX_OUTPUT_SIZE = 10485760;
149495
149509
  var ScriptExecutorService = class ScriptExecutorService2 {
149496
149510
  constructor(loggerService) {
149497
149511
  this.logger = loggerService.getLogger("script-executor");
149498
149512
  }
149499
149513
  async execute(options) {
149500
- const { code, scriptType, args = [], timeout = DEFAULT_TIMEOUT_MS } = options;
149514
+ const { code, scriptType, args = [], timeout = DEFAULT_SCRIPT_TIMEOUT_MS } = options;
149501
149515
  this.logger.debug({ scriptType, argsCount: args.length, timeout }, "Executing script");
149502
149516
  let tempDir;
149503
149517
  let tempFile;
@@ -149570,10 +149584,10 @@ var ScriptExecutorService = class ScriptExecutorService2 {
149570
149584
  if (outputTruncated)
149571
149585
  return;
149572
149586
  const dataSize = Buffer.byteLength(data);
149573
- if (totalOutputSize + dataSize > MAX_OUTPUT_SIZE) {
149587
+ if (totalOutputSize + dataSize > MAX_SCRIPT_OUTPUT_SIZE) {
149574
149588
  outputTruncated = true;
149575
149589
  child.kill("SIGKILL");
149576
- this.logger.warn({ totalOutputSize, MAX_OUTPUT_SIZE }, "Script output exceeded maximum size");
149590
+ this.logger.warn({ totalOutputSize, MAX_SCRIPT_OUTPUT_SIZE }, "Script output exceeded maximum size");
149577
149591
  return;
149578
149592
  }
149579
149593
  totalOutputSize += dataSize;
@@ -149583,10 +149597,10 @@ var ScriptExecutorService = class ScriptExecutorService2 {
149583
149597
  if (outputTruncated)
149584
149598
  return;
149585
149599
  const dataSize = Buffer.byteLength(data);
149586
- if (totalOutputSize + dataSize > MAX_OUTPUT_SIZE) {
149600
+ if (totalOutputSize + dataSize > MAX_SCRIPT_OUTPUT_SIZE) {
149587
149601
  outputTruncated = true;
149588
149602
  child.kill("SIGKILL");
149589
- this.logger.warn({ totalOutputSize, MAX_OUTPUT_SIZE }, "Script output exceeded maximum size");
149603
+ this.logger.warn({ totalOutputSize, MAX_SCRIPT_OUTPUT_SIZE }, "Script output exceeded maximum size");
149590
149604
  return;
149591
149605
  }
149592
149606
  totalOutputSize += dataSize;
@@ -149645,7 +149659,7 @@ var ScriptExecutorService = class ScriptExecutorService2 {
149645
149659
  * The script can call MCP tools via the injected SDK.
149646
149660
  */
149647
149661
  async executeInteractive(options) {
149648
- const { code, scriptType, args = [], timeout = DEFAULT_TIMEOUT_MS, onRequest, sdkBundleContent, toolCallTimeout = 1e4 } = options;
149662
+ const { code, scriptType, args = [], timeout = DEFAULT_SCRIPT_TIMEOUT_MS, onRequest, sdkBundleContent, toolCallTimeout = 1e4 } = options;
149649
149663
  this.logger.debug({ scriptType, argsCount: args.length }, "Executing interactive script");
149650
149664
  let tempDir;
149651
149665
  try {
@@ -149702,7 +149716,7 @@ var ScriptExecutorService = class ScriptExecutorService2 {
149702
149716
  const resetTimeout = (extraMs) => {
149703
149717
  clearTimeout(timeoutId);
149704
149718
  const elapsed = Date.now() - totalStartTime;
149705
- const remaining = Math.min(extraMs, MAX_INTERACTIVE_TIMEOUT_MS - elapsed);
149719
+ const remaining = Math.min(extraMs, MAX_INTERACTIVE_SCRIPT_TIMEOUT_MS - elapsed);
149706
149720
  if (remaining <= 0) {
149707
149721
  killed = true;
149708
149722
  child.kill("SIGKILL");
@@ -149736,7 +149750,7 @@ var ScriptExecutorService = class ScriptExecutorService2 {
149736
149750
  if (outputTruncated)
149737
149751
  return;
149738
149752
  const dataSize = Buffer.byteLength(line);
149739
- if (totalOutputSize + dataSize > MAX_OUTPUT_SIZE) {
149753
+ if (totalOutputSize + dataSize > MAX_SCRIPT_OUTPUT_SIZE) {
149740
149754
  outputTruncated = true;
149741
149755
  child.kill("SIGKILL");
149742
149756
  return;
@@ -149781,7 +149795,7 @@ var ScriptExecutorService = class ScriptExecutorService2 {
149781
149795
  if (outputTruncated)
149782
149796
  return;
149783
149797
  const dataSize = Buffer.byteLength(data);
149784
- if (totalOutputSize + dataSize > MAX_OUTPUT_SIZE) {
149798
+ if (totalOutputSize + dataSize > MAX_SCRIPT_OUTPUT_SIZE) {
149785
149799
  outputTruncated = true;
149786
149800
  child.kill("SIGKILL");
149787
149801
  return;
@@ -152915,10 +152929,10 @@ var ToolService = class ToolService2 extends Service {
152915
152929
  this.startingServers = /* @__PURE__ */ new Map();
152916
152930
  this.stoppingServers = /* @__PURE__ */ new Map();
152917
152931
  this.activationFailures = /* @__PURE__ */ new Map();
152918
- this.maxActivationRetries = 3;
152919
- this.activationCooldownMs = 6e4;
152932
+ this.maxActivationRetries = MAX_ACTIVATION_RETRIES;
152933
+ this.activationCooldownMs = ACTIVATION_COOLDOWN_MS;
152920
152934
  this.lazyStartEnabled = true;
152921
- this.idleTimeoutMs = 3e5;
152935
+ this.idleTimeoutMs = DEFAULT_IDLE_TIMEOUT_MS;
152922
152936
  this.logger = this.loggerService.getLogger(this.name);
152923
152937
  }
152924
152938
  async initialize() {
@@ -152928,7 +152942,7 @@ var ToolService = class ToolService2 extends Service {
152928
152942
  const parsedTimeout = parseInt(process.env.MCP_IDLE_TIMEOUT_MS ?? "300000", 10);
152929
152943
  if (Number.isNaN(parsedTimeout) || parsedTimeout <= 0) {
152930
152944
  this.logger.warn({ rawValue: process.env.MCP_IDLE_TIMEOUT_MS }, "Invalid MCP_IDLE_TIMEOUT_MS value, falling back to default 300000ms");
152931
- this.idleTimeoutMs = 3e5;
152945
+ this.idleTimeoutMs = DEFAULT_IDLE_TIMEOUT_MS;
152932
152946
  } else {
152933
152947
  this.idleTimeoutMs = parsedTimeout;
152934
152948
  }
@@ -154357,13 +154371,9 @@ var MainService = class MainService2 extends Service {
154357
154371
  await this.up();
154358
154372
  }
154359
154373
  calculateReconnectWaitTime() {
154360
- const INITIAL_WAIT_TIME = 5e3;
154361
- const MAX_WAIT_TIME = 10 * 60 * 1e3;
154362
- const BACKOFF_MULTIPLIER = 2;
154363
- const JITTER_FACTOR = 0.1;
154364
- const baseWaitTime = INITIAL_WAIT_TIME * Math.pow(BACKOFF_MULTIPLIER, this.failedConnectionCounter - 1);
154365
- const cappedWaitTime = Math.min(baseWaitTime, MAX_WAIT_TIME);
154366
- const jitter = cappedWaitTime * JITTER_FACTOR * Math.random();
154374
+ const baseWaitTime = RECONNECT_INITIAL_WAIT_MS * Math.pow(RECONNECT_BACKOFF_MULTIPLIER, this.failedConnectionCounter - 1);
154375
+ const cappedWaitTime = Math.min(baseWaitTime, RECONNECT_MAX_WAIT_MS);
154376
+ const jitter = cappedWaitTime * RECONNECT_JITTER_FACTOR * Math.random();
154367
154377
  const finalWaitTime = cappedWaitTime + jitter;
154368
154378
  return Math.floor(finalWaitTime);
154369
154379
  }