@ottocode/server 0.1.192 → 0.1.193
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": "@ottocode/server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.193",
|
|
4
4
|
"description": "HTTP API server for ottocode",
|
|
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
|
-
"@ottocode/sdk": "0.1.
|
|
33
|
-
"@ottocode/database": "0.1.
|
|
32
|
+
"@ottocode/sdk": "0.1.193",
|
|
33
|
+
"@ottocode/database": "0.1.193",
|
|
34
34
|
"drizzle-orm": "^0.44.5",
|
|
35
35
|
"hono": "^4.9.9",
|
|
36
36
|
"zod": "^4.1.8"
|
package/src/routes/auth.ts
CHANGED
|
@@ -161,6 +161,27 @@ export function registerAuthRoutes(app: Hono) {
|
|
|
161
161
|
}
|
|
162
162
|
});
|
|
163
163
|
|
|
164
|
+
app.get('/v1/auth/setu/export', async (c) => {
|
|
165
|
+
try {
|
|
166
|
+
const projectRoot = process.cwd();
|
|
167
|
+
const wallet = await getSetuWallet(projectRoot);
|
|
168
|
+
|
|
169
|
+
if (!wallet) {
|
|
170
|
+
return c.json({ error: 'Setu wallet not configured' }, 404);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return c.json({
|
|
174
|
+
success: true,
|
|
175
|
+
publicKey: wallet.publicKey,
|
|
176
|
+
privateKey: wallet.privateKey,
|
|
177
|
+
});
|
|
178
|
+
} catch (error) {
|
|
179
|
+
logger.error('Failed to export Setu wallet', error);
|
|
180
|
+
const errorResponse = serializeError(error);
|
|
181
|
+
return c.json(errorResponse, errorResponse.error.status || 500);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
|
|
164
185
|
app.post('/v1/auth/:provider', async (c) => {
|
|
165
186
|
try {
|
|
166
187
|
const provider = c.req.param('provider') as ProviderId;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { hasToolCall, streamText } from 'ai';
|
|
2
|
-
import { messageParts } from '@ottocode/database/schema';
|
|
2
|
+
import { messages, messageParts } from '@ottocode/database/schema';
|
|
3
3
|
import { eq } from 'drizzle-orm';
|
|
4
4
|
import { publish, subscribe } from '../../events/bus.ts';
|
|
5
5
|
import { debugLog, time } from '../debug/index.ts';
|
|
6
6
|
import { toErrorPayload } from '../errors/handling.ts';
|
|
7
7
|
import {
|
|
8
8
|
type RunOpts,
|
|
9
|
+
enqueueAssistantRun,
|
|
9
10
|
setRunning,
|
|
10
11
|
dequeueJob,
|
|
11
12
|
cleanupSession,
|
|
@@ -293,13 +294,71 @@ async function runAssistant(opts: RunOpts) {
|
|
|
293
294
|
await cleanupEmptyTextParts(opts, db);
|
|
294
295
|
firstToolTimer.end({ seen: firstToolSeen() });
|
|
295
296
|
|
|
297
|
+
let streamFinishReason: string | undefined;
|
|
298
|
+
try {
|
|
299
|
+
streamFinishReason = await result.finishReason;
|
|
300
|
+
} catch {
|
|
301
|
+
streamFinishReason = undefined;
|
|
302
|
+
}
|
|
303
|
+
|
|
296
304
|
debugLog(
|
|
297
|
-
`[RUNNER] Stream finished. finishSeen=${_finishObserved}, firstToolSeen=${fs}`,
|
|
305
|
+
`[RUNNER] Stream finished. finishSeen=${_finishObserved}, firstToolSeen=${fs}, finishReason=${streamFinishReason}`,
|
|
298
306
|
);
|
|
299
307
|
|
|
300
|
-
|
|
308
|
+
const wasTruncated = streamFinishReason === 'length';
|
|
309
|
+
|
|
310
|
+
const shouldContinue = !_finishObserved && (wasTruncated || fs);
|
|
311
|
+
|
|
312
|
+
if (shouldContinue) {
|
|
313
|
+
debugLog(
|
|
314
|
+
`[RUNNER] WARNING: Stream ended without finish. finishReason=${streamFinishReason}, firstToolSeen=${fs}. Auto-continuing.`,
|
|
315
|
+
);
|
|
316
|
+
|
|
317
|
+
const MAX_CONTINUATIONS = 10;
|
|
318
|
+
const count = opts.continuationCount ?? 0;
|
|
319
|
+
if (count < MAX_CONTINUATIONS) {
|
|
320
|
+
debugLog(
|
|
321
|
+
`[RUNNER] Auto-continuing (${count + 1}/${MAX_CONTINUATIONS})...`,
|
|
322
|
+
);
|
|
323
|
+
|
|
324
|
+
try {
|
|
325
|
+
await completeAssistantMessage({}, opts, db);
|
|
326
|
+
} catch (err) {
|
|
327
|
+
debugLog(
|
|
328
|
+
`[RUNNER] completeAssistantMessage failed before continuation: ${err instanceof Error ? err.message : String(err)}`,
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const continuationMessageId = crypto.randomUUID();
|
|
333
|
+
await db.insert(messages).values({
|
|
334
|
+
id: continuationMessageId,
|
|
335
|
+
sessionId: opts.sessionId,
|
|
336
|
+
role: 'assistant',
|
|
337
|
+
status: 'pending',
|
|
338
|
+
agent: opts.agent,
|
|
339
|
+
provider: opts.provider,
|
|
340
|
+
model: opts.model,
|
|
341
|
+
createdAt: Date.now(),
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
publish({
|
|
345
|
+
type: 'message.created',
|
|
346
|
+
sessionId: opts.sessionId,
|
|
347
|
+
payload: { id: continuationMessageId, role: 'assistant' },
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
enqueueAssistantRun(
|
|
351
|
+
{
|
|
352
|
+
...opts,
|
|
353
|
+
assistantMessageId: continuationMessageId,
|
|
354
|
+
continuationCount: count + 1,
|
|
355
|
+
},
|
|
356
|
+
runSessionLoop,
|
|
357
|
+
);
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
301
360
|
debugLog(
|
|
302
|
-
`[RUNNER]
|
|
361
|
+
`[RUNNER] Max continuations (${MAX_CONTINUATIONS}) reached, stopping.`,
|
|
303
362
|
);
|
|
304
363
|
}
|
|
305
364
|
} catch (err) {
|