@limo-labs/deity 0.2.0 → 0.2.2

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.cjs CHANGED
@@ -510,15 +510,13 @@ function Tool(props) {
510
510
  throw new Error("Tool: input schema is required");
511
511
  }
512
512
  let executeFn;
513
- if (children) {
513
+ const hasChildren = children && Array.isArray(children) && children.length > 0;
514
+ if (hasChildren) {
514
515
  if (execute) {
515
516
  throw new Error("Tool: cannot use both children and execute prop");
516
517
  }
517
518
  let actualChild = children;
518
519
  if (Array.isArray(children)) {
519
- if (children.length === 0) {
520
- throw new Error("Tool: children array is empty");
521
- }
522
520
  if (children.length > 1) {
523
521
  throw new Error("Tool: can only have one child (the execute function)");
524
522
  }
@@ -2878,6 +2876,7 @@ var DEFAULT_LLM_LOOP_CONFIG = {
2878
2876
  // 2 minutes
2879
2877
  verbose: false
2880
2878
  };
2879
+ var DEADLINE_PROMPT = `\u26A0\uFE0F DEADLINE REACHED: You have reached the maximum allowed rounds or time limit. You MUST immediately provide your final answer based on the information gathered so far. Do NOT call any more tools. Respond with your best final output NOW.`;
2881
2880
  async function executeLLMLoop(adapter, initialMessages, tools, config, ctx, loopConfig = {}, validator) {
2882
2881
  const cfg = { ...DEFAULT_LLM_LOOP_CONFIG, ...loopConfig };
2883
2882
  const messagesWithMemory = await injectRelevantMemories(
@@ -2891,6 +2890,7 @@ async function executeLLMLoop(adapter, initialMessages, tools, config, ctx, loop
2891
2890
  let toolCallsExecuted = 0;
2892
2891
  let response;
2893
2892
  let toolCallsThisRound = [];
2893
+ const startTime = Date.now();
2894
2894
  while (rounds < cfg.maxToolRounds) {
2895
2895
  rounds++;
2896
2896
  toolCallsThisRound = [];
@@ -2938,10 +2938,6 @@ async function executeLLMLoop(adapter, initialMessages, tools, config, ctx, loop
2938
2938
  }
2939
2939
  break;
2940
2940
  }
2941
- if (rounds >= cfg.maxToolRounds) {
2942
- errors.push(`Maximum tool rounds (${cfg.maxToolRounds}) exceeded`);
2943
- break;
2944
- }
2945
2941
  for (const toolCall of response.toolCalls) {
2946
2942
  const alreadyExecuted = toolCall._alreadyExecuted;
2947
2943
  if (alreadyExecuted) {
@@ -3009,6 +3005,23 @@ async function executeLLMLoop(adapter, initialMessages, tools, config, ctx, loop
3009
3005
  if (allPreExecuted) {
3010
3006
  break;
3011
3007
  }
3008
+ const isTimeout = cfg.timeout > 0 && Date.now() - startTime >= cfg.timeout;
3009
+ const isLastRound = rounds >= cfg.maxToolRounds;
3010
+ if (isTimeout || isLastRound) {
3011
+ messages.push({
3012
+ role: "user",
3013
+ content: DEADLINE_PROMPT
3014
+ });
3015
+ try {
3016
+ response = await adapter.generate(messages, void 0, config, ctx);
3017
+ messages.push({ role: "assistant", content: response.content });
3018
+ } catch (_error) {
3019
+ }
3020
+ errors.push(
3021
+ isTimeout ? `Timeout reached (${cfg.timeout}ms)` : `Maximum tool rounds (${cfg.maxToolRounds}) reached`
3022
+ );
3023
+ break;
3024
+ }
3012
3025
  }
3013
3026
  return {
3014
3027
  response,
@@ -3248,6 +3261,17 @@ async function executeWithRetry(component, ctx, executeFn) {
3248
3261
  }
3249
3262
  const shouldRetry = retryConfig.shouldRetry ? retryConfig.shouldRetry(attempts, output, ctx) : attempts < retryConfig.maxAttempts;
3250
3263
  if (!shouldRetry) {
3264
+ const lastOutput = outputHistory[outputHistory.length - 1];
3265
+ if (lastOutput !== void 0) {
3266
+ return {
3267
+ output: lastOutput,
3268
+ success: true,
3269
+ attempts,
3270
+ errors: validation.errors ?? ["Validation failed (used best-effort output)"],
3271
+ validationHistory,
3272
+ outputHistory
3273
+ };
3274
+ }
3251
3275
  return {
3252
3276
  success: false,
3253
3277
  attempts,
@@ -4346,7 +4370,7 @@ zod.z.object({
4346
4370
  sessionId: zod.z.string().min(1, "Session ID cannot be empty"),
4347
4371
  workflowName: zod.z.string().min(1, "Workflow name cannot be empty"),
4348
4372
  pausedAt: zod.z.string().datetime("Must be ISO 8601 datetime"),
4349
- version: zod.z.string().regex(/^\d+\.\d+\.\d+$/, "Must be semver format (e.g., 4.0.0)"),
4373
+ version: zod.z.string().regex(/^\d+\.\d+\.\d+$/, "Must be semver format (e.g., 1.0.0)"),
4350
4374
  state: PausedSessionStateSchema,
4351
4375
  metadata: PausedSessionMetadataSchema
4352
4376
  });
@@ -4362,7 +4386,7 @@ var SessionSerializer = class {
4362
4386
  metadata;
4363
4387
  constructor() {
4364
4388
  this.metadata = {
4365
- version: "4.0.0",
4389
+ version: "1.0.0",
4366
4390
  timestamp: /* @__PURE__ */ new Date(),
4367
4391
  specialFields: []
4368
4392
  };
@@ -5254,6 +5278,7 @@ function createLoopNode(child, maxIterations) {
5254
5278
 
5255
5279
  exports.Agent = Agent;
5256
5280
  exports.Conditional = Conditional;
5281
+ exports.DEADLINE_PROMPT = DEADLINE_PROMPT;
5257
5282
  exports.DEBUG_ENABLED = DEBUG_ENABLED;
5258
5283
  exports.DebugLogger = DebugLogger;
5259
5284
  exports.ForEach = ForEach;