@lowire/loop 0.0.21 → 0.0.22

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/lib/loop.d.ts CHANGED
@@ -61,7 +61,8 @@ export declare class Loop {
61
61
  abortController?: AbortController;
62
62
  }): Promise<{
63
63
  result?: types.ToolResult;
64
- status: 'ok' | 'break';
64
+ status: 'ok' | 'break' | 'error';
65
+ error?: string;
65
66
  usage: types.Usage;
66
67
  turns: number;
67
68
  }>;
package/lib/loop.js CHANGED
@@ -49,7 +49,7 @@ class Loop {
49
49
  const maxTurns = options.maxTurns || 100;
50
50
  for (let turns = 0; turns < maxTurns; ++turns) {
51
51
  if (options.maxTokens && budget.tokens !== undefined && budget.tokens <= 0)
52
- throw new Error(`Budget tokens ${options.maxTokens} exhausted`);
52
+ return { status: 'error', error: `Budget tokens ${options.maxTokens} exhausted`, usage: totalUsage, turns };
53
53
  debug?.('lowire:loop')(`Turn ${turns + 1} of (max ${maxTurns})`);
54
54
  const caches = options.cache ? {
55
55
  input: options.cache,
@@ -83,7 +83,7 @@ class Loop {
83
83
  }
84
84
  for (const toolCall of toolCalls) {
85
85
  if (budget.toolCalls !== undefined && --budget.toolCalls < 0)
86
- throw new Error(`Failed to perform step, max tool calls (${options.maxToolCalls}) reached`);
86
+ return { status: 'error', error: `Failed to perform step, max tool calls (${options.maxToolCalls}) reached`, usage: totalUsage, turns };
87
87
  const { name, arguments: args } = toolCall;
88
88
  debug?.('lowire:loop')('Call tool', name, JSON.stringify(args, null, 2));
89
89
  const status = await options.onBeforeToolCall?.({ assistantMessage, toolCall });
@@ -139,9 +139,9 @@ class Loop {
139
139
  if (!hasErrors)
140
140
  budget.toolCallRetries = options.maxToolCallRetries;
141
141
  if (hasErrors && budget.toolCallRetries !== undefined && --budget.toolCallRetries < 0)
142
- throw new Error(`Failed to perform action after ${options.maxToolCallRetries} tool call retries`);
142
+ return { status: 'error', error: `Failed to perform action after ${options.maxToolCallRetries} tool call retries`, usage: totalUsage, turns };
143
143
  }
144
- throw new Error('Failed to perform step, max attempts reached');
144
+ return { status: 'error', error: `Failed to perform step, max attempts reached`, usage: totalUsage, turns: maxTurns };
145
145
  }
146
146
  _summarizeConversation(task, conversation, options) {
147
147
  const { summary, lastMessage } = (0, summary_1.summarizeConversation)(task, conversation, options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowire/loop",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "description": "Small agentic loop",
5
5
  "repository": {
6
6
  "type": "git",
package/githubAuth.js DELETED
@@ -1,17 +0,0 @@
1
- /**
2
- * Copyright (c) Microsoft Corporation.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
-
17
- require('./lib/auth/githubAuth');