@agi-cli/server 0.1.78 → 0.1.80
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agi-cli/server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.80",
|
|
4
4
|
"description": "HTTP API server for AGI CLI",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"typecheck": "tsc --noEmit"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@agi-cli/sdk": "0.1.
|
|
33
|
-
"@agi-cli/database": "0.1.
|
|
32
|
+
"@agi-cli/sdk": "0.1.80",
|
|
33
|
+
"@agi-cli/database": "0.1.80",
|
|
34
34
|
"drizzle-orm": "^0.44.5",
|
|
35
35
|
"hono": "^4.9.9",
|
|
36
36
|
"zod": "^4.1.8"
|
|
@@ -109,6 +109,9 @@ export async function buildHistoryMessages(
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
for (const call of toolCalls) {
|
|
112
|
+
// Skip finish tool from history - it's internal loop control
|
|
113
|
+
if (call.name === 'finish') continue;
|
|
114
|
+
|
|
112
115
|
const toolType = `tool-${call.name}` as `tool-${string}`;
|
|
113
116
|
const result = toolResults.find((r) => r.callId === call.callId);
|
|
114
117
|
|
package/src/runtime/runner.ts
CHANGED
|
@@ -76,33 +76,6 @@ async function processQueue(sessionId: string) {
|
|
|
76
76
|
cleanupSession(sessionId);
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
/**
|
|
80
|
-
* Ensures the finish tool is called if not already observed.
|
|
81
|
-
*/
|
|
82
|
-
async function ensureFinishToolCalled(
|
|
83
|
-
finishObserved: boolean,
|
|
84
|
-
toolset: ReturnType<typeof adaptTools>,
|
|
85
|
-
sharedCtx: RunnerToolContext,
|
|
86
|
-
stepIndex: number,
|
|
87
|
-
) {
|
|
88
|
-
if (finishObserved || !toolset?.finish?.execute) return;
|
|
89
|
-
|
|
90
|
-
const finishInput = {} as const;
|
|
91
|
-
const callOptions = { input: finishInput } as const;
|
|
92
|
-
|
|
93
|
-
sharedCtx.stepIndex = stepIndex;
|
|
94
|
-
|
|
95
|
-
try {
|
|
96
|
-
await toolset.finish.onInputStart?.(callOptions as never);
|
|
97
|
-
} catch {}
|
|
98
|
-
|
|
99
|
-
try {
|
|
100
|
-
await toolset.finish.onInputAvailable?.(callOptions as never);
|
|
101
|
-
} catch {}
|
|
102
|
-
|
|
103
|
-
await toolset.finish.execute(finishInput, {} as never);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
79
|
/**
|
|
107
80
|
* Main function to run the assistant for a given request.
|
|
108
81
|
*/
|
|
@@ -290,12 +263,7 @@ async function runAssistant(opts: RunOpts) {
|
|
|
290
263
|
|
|
291
264
|
const onAbort = createAbortHandler(opts, db, getStepIndex, sharedCtx);
|
|
292
265
|
|
|
293
|
-
const onFinish = createFinishHandler(
|
|
294
|
-
opts,
|
|
295
|
-
db,
|
|
296
|
-
() => ensureFinishToolCalled(finishObserved, toolset, sharedCtx, stepIndex),
|
|
297
|
-
completeAssistantMessage,
|
|
298
|
-
);
|
|
266
|
+
const onFinish = createFinishHandler(opts, db, completeAssistantMessage);
|
|
299
267
|
|
|
300
268
|
// Apply optimizations: deduplication, pruning, cache control, and truncation
|
|
301
269
|
const { addCacheControl, truncateHistory } = await import(
|
|
@@ -264,7 +264,6 @@ export function createAbortHandler(
|
|
|
264
264
|
export function createFinishHandler(
|
|
265
265
|
opts: RunOpts,
|
|
266
266
|
db: Awaited<ReturnType<typeof getDb>>,
|
|
267
|
-
ensureFinishToolCalled: () => Promise<void>,
|
|
268
267
|
completeAssistantMessageFn: (
|
|
269
268
|
fin: FinishEvent,
|
|
270
269
|
opts: RunOpts,
|
|
@@ -272,10 +271,6 @@ export function createFinishHandler(
|
|
|
272
271
|
) => Promise<void>,
|
|
273
272
|
) {
|
|
274
273
|
return async (fin: FinishEvent) => {
|
|
275
|
-
try {
|
|
276
|
-
await ensureFinishToolCalled();
|
|
277
|
-
} catch {}
|
|
278
|
-
|
|
279
274
|
// Note: Token updates are handled incrementally in onStepFinish
|
|
280
275
|
// Do NOT add fin.usage here as it would cause double-counting
|
|
281
276
|
|
package/src/tools/adapter.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { publish } from '../events/bus.ts';
|
|
|
5
5
|
import type { DiscoveredTool } from '@agi-cli/sdk';
|
|
6
6
|
import { getCwd, setCwd, joinRelative } from '../runtime/cwd.ts';
|
|
7
7
|
import type { ToolAdapterContext } from '../runtime/tool-context.ts';
|
|
8
|
+
import { isToolError } from '@agi-cli/sdk/tools/error';
|
|
8
9
|
|
|
9
10
|
export type { ToolAdapterContext } from '../runtime/tool-context.ts';
|
|
10
11
|
|
|
@@ -403,7 +404,8 @@ export function adaptTools(
|
|
|
403
404
|
}
|
|
404
405
|
return result;
|
|
405
406
|
} catch (error) {
|
|
406
|
-
// Tool execution failed
|
|
407
|
+
// Tool execution failed
|
|
408
|
+
// Check if the error is already a structured tool error response
|
|
407
409
|
const resultPartId = crypto.randomUUID();
|
|
408
410
|
const callId = callIdFromQueue;
|
|
409
411
|
const startTs = startTsFromQueue;
|
|
@@ -411,15 +413,21 @@ export function adaptTools(
|
|
|
411
413
|
const dur =
|
|
412
414
|
typeof startTs === 'number' ? Math.max(0, endTs - startTs) : null;
|
|
413
415
|
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
416
|
+
// If the tool returned a structured error response, use it directly
|
|
417
|
+
// Otherwise, wrap the thrown error in our standard format
|
|
418
|
+
let errorResult: unknown;
|
|
419
|
+
if (isToolError(error)) {
|
|
420
|
+
errorResult = error;
|
|
421
|
+
} else {
|
|
422
|
+
const errorMessage =
|
|
423
|
+
error instanceof Error ? error.message : String(error);
|
|
424
|
+
const errorStack = error instanceof Error ? error.stack : undefined;
|
|
425
|
+
errorResult = {
|
|
426
|
+
ok: false,
|
|
427
|
+
error: errorMessage,
|
|
428
|
+
stack: errorStack,
|
|
429
|
+
};
|
|
430
|
+
}
|
|
423
431
|
|
|
424
432
|
const contentObj = {
|
|
425
433
|
name,
|