@agi-cli/server 0.1.97 → 0.1.98

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.97",
3
+ "version": "0.1.98",
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.97",
33
- "@agi-cli/database": "0.1.97",
32
+ "@agi-cli/sdk": "0.1.98",
33
+ "@agi-cli/database": "0.1.98",
34
34
  "drizzle-orm": "^0.44.5",
35
35
  "hono": "^4.9.9",
36
36
  "zod": "^4.1.8"
@@ -275,49 +275,9 @@ async function runAssistant(opts: RunOpts) {
275
275
 
276
276
  const onFinish = createFinishHandler(opts, db, completeAssistantMessage);
277
277
 
278
- // Apply optimizations: deduplication, pruning, cache control, and truncation
279
- const { addCacheControl, truncateHistory } = await import(
280
- './cache-optimizer.ts'
281
- );
282
- const { optimizeContext } = await import('./context-optimizer.ts');
283
-
284
- // 1. Optimize context (deduplicate file reads, prune old tool results)
285
- const contextOptimized = optimizeContext(messagesWithSystemInstructions, {
286
- deduplicateFiles: true,
287
- maxToolResults: 30,
288
- });
289
-
290
- debugLog(
291
- `[RUNNER] After optimizeContext: ${contextOptimized.length} messages`,
292
- );
293
-
294
- // 2. Truncate history
295
- const truncatedMessages = truncateHistory(contextOptimized, 20);
296
-
297
- debugLog(
298
- `[RUNNER] After truncateHistory: ${truncatedMessages.length} messages`,
299
- );
300
- if (truncatedMessages.length > 0 && truncatedMessages[0].role === 'system') {
301
- debugLog('[RUNNER] ✅ First message is system message');
302
- } else if (truncatedMessages.length > 0) {
303
- debugLog(
304
- `[RUNNER] ⚠️ First message is NOT system (it's ${truncatedMessages[0].role})`,
305
- );
306
- }
307
-
308
- // 3. Add cache control
309
- const { system: cachedSystem, messages: optimizedMessages } = addCacheControl(
310
- opts.provider,
311
- system,
312
- truncatedMessages,
313
- );
314
-
315
- debugLog(
316
- `[RUNNER] Final optimizedMessages: ${optimizedMessages.length} messages`,
317
- );
318
- debugLog(
319
- `[RUNNER] cachedSystem (spoof): ${typeof cachedSystem === 'string' ? cachedSystem.substring(0, 100) : JSON.stringify(cachedSystem).substring(0, 100)}`,
320
- );
278
+ // Use messages directly without truncation or optimization
279
+ const optimizedMessages = messagesWithSystemInstructions;
280
+ const cachedSystem = system;
321
281
 
322
282
  // Part tracking - will be created on first text-delta
323
283
  let currentPartId: string | null = null;
@@ -10,13 +10,6 @@ import type {
10
10
  } from '../runtime/tool-context.ts';
11
11
  import { isToolError } from '@agi-cli/sdk/tools/error';
12
12
 
13
- function isSkippedToolCallError(error: unknown): boolean {
14
- if (!isToolError(error)) return false;
15
- const details = (error as { details?: unknown }).details;
16
- if (!details || typeof details !== 'object') return false;
17
- return 'skippedTool' in (details as Record<string, unknown>);
18
- }
19
-
20
13
  export type { ToolAdapterContext } from '../runtime/tool-context.ts';
21
14
 
22
15
  type ToolExecuteSignature = Tool['execute'] extends (
@@ -310,23 +303,6 @@ export function adaptTools(
310
303
 
311
304
  const executeWithGuards = async (): Promise<ToolExecuteReturn> => {
312
305
  try {
313
- if (failureState.active) {
314
- const expectedTool = failureState.toolName;
315
- if (!expectedTool || expectedTool !== name) {
316
- const skipError = {
317
- ok: false,
318
- error: expectedTool
319
- ? `Cannot execute "${name}" because "${expectedTool}" failed earlier in this step. Retry "${expectedTool}" before using other tools.`
320
- : `Cannot execute "${name}" because a previous tool call in this session failed. Retry that tool before continuing with "${name}".`,
321
- details: {
322
- skippedTool: name,
323
- reason: 'previous_tool_failed',
324
- expectedTool,
325
- },
326
- };
327
- throw skipError;
328
- }
329
- }
330
306
  // Handle session-relative paths and cwd tools
331
307
  let res: ToolExecuteReturn | { cwd: string } | null | undefined;
332
308
  const cwd = getCwd(ctx.sessionId);
@@ -396,6 +372,10 @@ export function adaptTools(
396
372
 
397
373
  if (isToolError(result)) {
398
374
  stepState.failed = true;
375
+ stepState.failedToolName = name;
376
+ failureState.active = true;
377
+ failureState.toolName = name;
378
+
399
379
  await persistToolErrorResult(result, {
400
380
  callId: callIdFromQueue,
401
381
  startTs: startTsFromQueue,
@@ -403,7 +383,7 @@ export function adaptTools(
403
383
  args: meta?.args,
404
384
  });
405
385
  processedToolErrors.add(result as object);
406
- throw result;
386
+ return result as ToolExecuteReturn;
407
387
  }
408
388
 
409
389
  const resultPartId = crypto.randomUUID();
@@ -547,10 +527,6 @@ export function adaptTools(
547
527
  }
548
528
  return result as ToolExecuteReturn;
549
529
  } catch (error) {
550
- if (isSkippedToolCallError(error)) {
551
- throw error;
552
- }
553
-
554
530
  stepState.failed = true;
555
531
  stepState.failedToolName = name;
556
532
  failureState.active = true;
@@ -589,8 +565,7 @@ export function adaptTools(
589
565
  processedToolErrors.add(error as object);
590
566
  }
591
567
 
592
- // Re-throw so AI SDK can handle it
593
- throw error;
568
+ return errorResult as ToolExecuteReturn;
594
569
  }
595
570
  };
596
571