@ottocode/server 0.1.234 → 0.1.236
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 +3 -3
- package/src/openapi/paths/config.ts +94 -0
- package/src/routes/config/debug.ts +39 -0
- package/src/routes/config/index.ts +2 -0
- package/src/routes/config/utils.ts +3 -16
- package/src/routes/git/commit.ts +0 -3
- package/src/routes/terminals.ts +0 -21
- package/src/routes/tunnel.ts +0 -5
- package/src/runtime/agent/mcp-prepare-step.ts +1 -7
- package/src/runtime/agent/registry.ts +1 -8
- package/src/runtime/agent/runner-setup.ts +73 -49
- package/src/runtime/agent/runner.ts +20 -194
- package/src/runtime/debug/index.ts +3 -91
- package/src/runtime/debug/state.ts +5 -61
- package/src/runtime/debug/turn-dump.ts +0 -4
- package/src/runtime/message/compaction-auto.ts +1 -21
- package/src/runtime/message/compaction-mark.ts +75 -27
- package/src/runtime/message/compaction-prune.ts +0 -3
- package/src/runtime/message/history-builder.ts +2 -23
- package/src/runtime/message/service.ts +22 -64
- package/src/runtime/message/tool-history-tracker.ts +0 -3
- package/src/runtime/prompt/builder.ts +0 -2
- package/src/runtime/provider/oauth-adapter.ts +5 -5
- package/src/runtime/stream/error-handler.ts +1 -31
- package/src/runtime/stream/finish-handler.ts +3 -20
- package/src/runtime/stream/step-finish.ts +5 -26
- package/src/runtime/tools/approval.ts +0 -18
- package/src/runtime/utils/token.ts +1 -10
- package/src/tools/adapter.ts +23 -22
|
@@ -6,7 +6,6 @@ import type { RunOpts } from '../session/queue.ts';
|
|
|
6
6
|
import type { ToolAdapterContext } from '../../tools/adapter.ts';
|
|
7
7
|
import type { UsageData, ProviderMetadata } from '../session/db-operations.ts';
|
|
8
8
|
import type { StepFinishEvent } from './types.ts';
|
|
9
|
-
import { debugLog } from '../debug/index.ts';
|
|
10
9
|
|
|
11
10
|
export function createStepFinishHandler(
|
|
12
11
|
opts: RunOpts,
|
|
@@ -45,11 +44,7 @@ export function createStepFinishHandler(
|
|
|
45
44
|
.set({ completedAt: finishedAt })
|
|
46
45
|
.where(eq(messageParts.id, currentPartId));
|
|
47
46
|
}
|
|
48
|
-
} catch
|
|
49
|
-
debugLog(
|
|
50
|
-
`[step-finish] Failed to update part completedAt: ${err instanceof Error ? err.message : String(err)}`,
|
|
51
|
-
);
|
|
52
|
-
}
|
|
47
|
+
} catch {}
|
|
53
48
|
|
|
54
49
|
if (step.usage) {
|
|
55
50
|
try {
|
|
@@ -59,11 +54,7 @@ export function createStepFinishHandler(
|
|
|
59
54
|
opts,
|
|
60
55
|
db,
|
|
61
56
|
);
|
|
62
|
-
} catch
|
|
63
|
-
debugLog(
|
|
64
|
-
`[step-finish] Failed to update session tokens: ${err instanceof Error ? err.message : String(err)}`,
|
|
65
|
-
);
|
|
66
|
-
}
|
|
57
|
+
} catch {}
|
|
67
58
|
|
|
68
59
|
try {
|
|
69
60
|
await updateMessageTokensIncrementalFn(
|
|
@@ -72,11 +63,7 @@ export function createStepFinishHandler(
|
|
|
72
63
|
opts,
|
|
73
64
|
db,
|
|
74
65
|
);
|
|
75
|
-
} catch
|
|
76
|
-
debugLog(
|
|
77
|
-
`[step-finish] Failed to update message tokens: ${err instanceof Error ? err.message : String(err)}`,
|
|
78
|
-
);
|
|
79
|
-
}
|
|
66
|
+
} catch {}
|
|
80
67
|
}
|
|
81
68
|
|
|
82
69
|
try {
|
|
@@ -97,21 +84,13 @@ export function createStepFinishHandler(
|
|
|
97
84
|
payload: { stepIndex, ...step.usage },
|
|
98
85
|
});
|
|
99
86
|
}
|
|
100
|
-
} catch
|
|
101
|
-
debugLog(
|
|
102
|
-
`[step-finish] Failed to publish finish-step: ${err instanceof Error ? err.message : String(err)}`,
|
|
103
|
-
);
|
|
104
|
-
}
|
|
87
|
+
} catch {}
|
|
105
88
|
|
|
106
89
|
try {
|
|
107
90
|
const newStepIndex = incrementStepIndex();
|
|
108
91
|
sharedCtx.stepIndex = newStepIndex;
|
|
109
92
|
updateCurrentPartId(null);
|
|
110
93
|
updateAccumulated('');
|
|
111
|
-
} catch
|
|
112
|
-
debugLog(
|
|
113
|
-
`[step-finish] Failed to increment step: ${err instanceof Error ? err.message : String(err)}`,
|
|
114
|
-
);
|
|
115
|
-
}
|
|
94
|
+
} catch {}
|
|
116
95
|
};
|
|
117
96
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { publish } from '../../events/bus.ts';
|
|
2
|
-
import { debugLog } from '../debug/index.ts';
|
|
3
2
|
|
|
4
3
|
export type ToolApprovalMode = 'auto' | 'dangerous' | 'all';
|
|
5
4
|
|
|
@@ -49,12 +48,6 @@ export async function requestApproval(
|
|
|
49
48
|
args: unknown,
|
|
50
49
|
timeoutMs = 120000,
|
|
51
50
|
): Promise<boolean> {
|
|
52
|
-
debugLog('[approval] requestApproval called', {
|
|
53
|
-
sessionId,
|
|
54
|
-
messageId,
|
|
55
|
-
callId,
|
|
56
|
-
toolName,
|
|
57
|
-
});
|
|
58
51
|
return new Promise((resolve) => {
|
|
59
52
|
const approval: PendingApproval = {
|
|
60
53
|
callId,
|
|
@@ -67,10 +60,6 @@ export async function requestApproval(
|
|
|
67
60
|
};
|
|
68
61
|
|
|
69
62
|
pendingApprovals.set(callId, approval);
|
|
70
|
-
debugLog(
|
|
71
|
-
'[approval] Added to pendingApprovals, count:',
|
|
72
|
-
pendingApprovals.size,
|
|
73
|
-
);
|
|
74
63
|
|
|
75
64
|
publish({
|
|
76
65
|
type: 'tool.approval.required',
|
|
@@ -106,15 +95,8 @@ export function resolveApproval(
|
|
|
106
95
|
callId: string,
|
|
107
96
|
approved: boolean,
|
|
108
97
|
): { ok: boolean; error?: string } {
|
|
109
|
-
debugLog('[approval] resolveApproval called', {
|
|
110
|
-
callId,
|
|
111
|
-
approved,
|
|
112
|
-
pendingCount: pendingApprovals.size,
|
|
113
|
-
pendingIds: [...pendingApprovals.keys()],
|
|
114
|
-
});
|
|
115
98
|
const approval = pendingApprovals.get(callId);
|
|
116
99
|
if (!approval) {
|
|
117
|
-
debugLog('[approval] No pending approval found for callId:', callId);
|
|
118
100
|
return { ok: false, error: 'No pending approval found for this callId' };
|
|
119
101
|
}
|
|
120
102
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { catalog } from '@ottocode/sdk';
|
|
2
|
-
import { debugLog } from '../debug/index.ts';
|
|
3
2
|
import type { ProviderName } from '../provider/index.ts';
|
|
4
3
|
|
|
5
4
|
/**
|
|
@@ -16,23 +15,15 @@ export function getMaxOutputTokens(
|
|
|
16
15
|
try {
|
|
17
16
|
const providerCatalog = catalog[provider];
|
|
18
17
|
if (!providerCatalog) {
|
|
19
|
-
debugLog(`[maxOutputTokens] No catalog found for provider: ${provider}`);
|
|
20
18
|
return undefined;
|
|
21
19
|
}
|
|
22
20
|
const modelInfo = providerCatalog.models.find((m) => m.id === modelId);
|
|
23
21
|
if (!modelInfo) {
|
|
24
|
-
debugLog(
|
|
25
|
-
`[maxOutputTokens] No model info found for: ${modelId} in provider: ${provider}`,
|
|
26
|
-
);
|
|
27
22
|
return undefined;
|
|
28
23
|
}
|
|
29
24
|
const outputLimit = modelInfo.limit?.output;
|
|
30
|
-
debugLog(
|
|
31
|
-
`[maxOutputTokens] Provider: ${provider}, Model: ${modelId}, Limit: ${outputLimit}`,
|
|
32
|
-
);
|
|
33
25
|
return outputLimit;
|
|
34
|
-
} catch
|
|
35
|
-
debugLog(`[maxOutputTokens] Error looking up limit: ${err}`);
|
|
26
|
+
} catch {
|
|
36
27
|
return undefined;
|
|
37
28
|
}
|
|
38
29
|
}
|
package/src/tools/adapter.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { Tool } from 'ai';
|
|
|
2
2
|
import { messageParts, sessions } from '@ottocode/database/schema';
|
|
3
3
|
import { eq } from 'drizzle-orm';
|
|
4
4
|
import { publish } from '../events/bus.ts';
|
|
5
|
-
import type
|
|
5
|
+
import { logger, type DiscoveredTool } from '@ottocode/sdk';
|
|
6
6
|
import { getCwd, setCwd, joinRelative } from '../runtime/utils/cwd.ts';
|
|
7
7
|
import type {
|
|
8
8
|
ToolAdapterContext,
|
|
@@ -18,7 +18,6 @@ import {
|
|
|
18
18
|
requestApproval,
|
|
19
19
|
} from '../runtime/tools/approval.ts';
|
|
20
20
|
import { guardToolCall } from '../runtime/tools/guards.ts';
|
|
21
|
-
import { debugLog } from '../runtime/debug/index.ts';
|
|
22
21
|
|
|
23
22
|
export type { ToolAdapterContext } from '../runtime/tools/context.ts';
|
|
24
23
|
|
|
@@ -63,17 +62,9 @@ function extractToolCallId(options: unknown): string | undefined {
|
|
|
63
62
|
const DEFAULT_TRACED_TOOL_INPUTS = new Set(['write', 'apply_patch']);
|
|
64
63
|
|
|
65
64
|
function shouldTraceToolInput(name: string): boolean {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (['1', 'true', 'yes', 'on', 'all'].includes(normalized)) {
|
|
70
|
-
return DEFAULT_TRACED_TOOL_INPUTS.has(name);
|
|
71
|
-
}
|
|
72
|
-
const tokens = raw
|
|
73
|
-
.split(/[\s,]+/)
|
|
74
|
-
.map((token) => token.trim().toLowerCase())
|
|
75
|
-
.filter(Boolean);
|
|
76
|
-
return tokens.includes('all') || tokens.includes(name.toLowerCase());
|
|
65
|
+
void DEFAULT_TRACED_TOOL_INPUTS;
|
|
66
|
+
void name;
|
|
67
|
+
return false;
|
|
77
68
|
}
|
|
78
69
|
|
|
79
70
|
function summarizeTraceValue(value: unknown, max = 160): string {
|
|
@@ -239,9 +230,7 @@ export function adaptTools(
|
|
|
239
230
|
stepIndex: ctx.stepIndex,
|
|
240
231
|
});
|
|
241
232
|
if (shouldTraceToolInput(name)) {
|
|
242
|
-
|
|
243
|
-
`[TOOL_INPUT_TRACE][adapter] onInputStart tool=${name} callId=${sdkCallId ?? queue[queue.length - 1]?.callId ?? 'unknown'} step=${ctx.stepIndex}`,
|
|
244
|
-
);
|
|
233
|
+
void (sdkCallId ?? queue[queue.length - 1]?.callId ?? 'unknown');
|
|
245
234
|
}
|
|
246
235
|
if (typeof base.onInputStart === 'function')
|
|
247
236
|
// biome-ignore lint/suspicious/noExplicitAny: AI SDK types are complex
|
|
@@ -254,9 +243,8 @@ export function adaptTools(
|
|
|
254
243
|
const queue = pendingCalls.get(name);
|
|
255
244
|
const meta = queue?.length ? queue[queue.length - 1] : undefined;
|
|
256
245
|
if (shouldTraceToolInput(name)) {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
);
|
|
246
|
+
void (sdkCallId ?? meta?.callId ?? 'unknown');
|
|
247
|
+
void summarizeTraceValue(delta ?? '');
|
|
260
248
|
}
|
|
261
249
|
// Stream tool argument deltas as events if needed
|
|
262
250
|
publish({
|
|
@@ -297,9 +285,8 @@ export function adaptTools(
|
|
|
297
285
|
const callPartId = crypto.randomUUID();
|
|
298
286
|
const startTs = meta.startTs;
|
|
299
287
|
if (shouldTraceToolInput(name)) {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
);
|
|
288
|
+
void callId;
|
|
289
|
+
void summarizeTraceValue(args);
|
|
303
290
|
}
|
|
304
291
|
|
|
305
292
|
if (
|
|
@@ -325,6 +312,13 @@ export function adaptTools(
|
|
|
325
312
|
messageId: ctx.messageId,
|
|
326
313
|
},
|
|
327
314
|
});
|
|
315
|
+
logger.debug(`[tools] call ${name}`, {
|
|
316
|
+
sessionId: ctx.sessionId,
|
|
317
|
+
messageId: ctx.messageId,
|
|
318
|
+
toolName: name,
|
|
319
|
+
callId,
|
|
320
|
+
stepIndex: ctx.stepIndex,
|
|
321
|
+
});
|
|
328
322
|
// Persist synchronously to maintain correct ordering
|
|
329
323
|
try {
|
|
330
324
|
const index = await ctx.nextIndex();
|
|
@@ -702,6 +696,13 @@ export function adaptTools(
|
|
|
702
696
|
sessionId: ctx.sessionId,
|
|
703
697
|
payload: { ...contentObj, stepIndex: stepIndexForEvent },
|
|
704
698
|
});
|
|
699
|
+
logger.debug(`[tools] result ${name}`, {
|
|
700
|
+
sessionId: ctx.sessionId,
|
|
701
|
+
messageId: ctx.messageId,
|
|
702
|
+
toolName: name,
|
|
703
|
+
callId,
|
|
704
|
+
stepIndex: stepIndexForEvent,
|
|
705
|
+
});
|
|
705
706
|
if (name === 'update_todos') {
|
|
706
707
|
try {
|
|
707
708
|
const resultValue = (contentObj as { result?: unknown })
|