@ottocode/server 0.1.260 → 0.1.261
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 +4 -3
- package/src/index.ts +5 -4
- package/src/openapi/register.ts +92 -0
- package/src/openapi/route.ts +22 -0
- package/src/routes/ask.ts +210 -99
- package/src/routes/auth.ts +1701 -626
- package/src/routes/branch.ts +281 -90
- package/src/routes/config/agents.ts +79 -32
- package/src/routes/config/cwd.ts +46 -14
- package/src/routes/config/debug.ts +159 -30
- package/src/routes/config/defaults.ts +182 -64
- package/src/routes/config/main.ts +109 -73
- package/src/routes/config/models.ts +304 -137
- package/src/routes/config/providers.ts +462 -166
- package/src/routes/config/utils.ts +2 -2
- package/src/routes/doctor.ts +395 -161
- package/src/routes/files.ts +650 -260
- package/src/routes/git/branch.ts +143 -52
- package/src/routes/git/commit.ts +347 -141
- package/src/routes/git/diff.ts +239 -116
- package/src/routes/git/init.ts +103 -23
- package/src/routes/git/pull.ts +167 -65
- package/src/routes/git/push.ts +222 -117
- package/src/routes/git/remote.ts +401 -100
- package/src/routes/git/staging.ts +502 -141
- package/src/routes/git/status.ts +171 -78
- package/src/routes/mcp.ts +1129 -404
- package/src/routes/openapi.ts +27 -4
- package/src/routes/ottorouter.ts +1221 -389
- package/src/routes/provider-usage.ts +153 -36
- package/src/routes/research.ts +817 -370
- package/src/routes/root.ts +50 -6
- package/src/routes/session-approval.ts +228 -54
- package/src/routes/session-files.ts +265 -134
- package/src/routes/session-messages.ts +330 -150
- package/src/routes/session-stream.ts +83 -2
- package/src/routes/sessions.ts +1830 -780
- package/src/routes/skills.ts +849 -161
- package/src/routes/terminals.ts +469 -103
- package/src/routes/tunnel.ts +394 -118
- package/src/runtime/ask/service.ts +1 -0
- package/src/runtime/message/compaction-limits.ts +3 -3
- package/src/runtime/provider/reasoning.ts +2 -1
- package/src/runtime/session/db-operations.ts +4 -3
- package/src/runtime/utils/token.ts +7 -2
- package/src/tools/adapter.ts +21 -0
- package/src/openapi/paths/ask.ts +0 -81
- package/src/openapi/paths/auth.ts +0 -687
- package/src/openapi/paths/branch.ts +0 -102
- package/src/openapi/paths/config.ts +0 -485
- package/src/openapi/paths/doctor.ts +0 -165
- package/src/openapi/paths/files.ts +0 -236
- package/src/openapi/paths/git.ts +0 -690
- package/src/openapi/paths/mcp.ts +0 -339
- package/src/openapi/paths/messages.ts +0 -103
- package/src/openapi/paths/ottorouter.ts +0 -594
- package/src/openapi/paths/provider-usage.ts +0 -59
- package/src/openapi/paths/research.ts +0 -227
- package/src/openapi/paths/session-approval.ts +0 -93
- package/src/openapi/paths/session-extras.ts +0 -336
- package/src/openapi/paths/session-files.ts +0 -91
- package/src/openapi/paths/sessions.ts +0 -210
- package/src/openapi/paths/skills.ts +0 -377
- package/src/openapi/paths/stream.ts +0 -26
- package/src/openapi/paths/terminals.ts +0 -226
- package/src/openapi/paths/tunnel.ts +0 -163
- package/src/openapi/spec.ts +0 -73
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ottocode/server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.261",
|
|
4
4
|
"description": "HTTP API server for ottocode",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -61,8 +61,9 @@
|
|
|
61
61
|
"typecheck": "tsc --noEmit"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@ottocode/database": "0.1.
|
|
65
|
-
"@ottocode/sdk": "0.1.
|
|
64
|
+
"@ottocode/database": "0.1.261",
|
|
65
|
+
"@ottocode/sdk": "0.1.261",
|
|
66
|
+
"@hono/zod-openapi": "^1.1.5",
|
|
66
67
|
"ai-sdk-ollama": "^3.8.3",
|
|
67
68
|
"drizzle-orm": "^0.44.5",
|
|
68
69
|
"hono": "^4.9.9",
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OpenAPIHono } from '@hono/zod-openapi';
|
|
2
|
+
import type { BlankEnv } from 'hono/types';
|
|
2
3
|
import { cors } from 'hono/cors';
|
|
3
4
|
import type { ProviderId, AuthInfo } from '@ottocode/sdk';
|
|
4
5
|
import { TerminalManager } from '@ottocode/sdk';
|
|
@@ -34,7 +35,7 @@ setTerminalManager(globalTerminalManager);
|
|
|
34
35
|
installAiSdkWarningHandler();
|
|
35
36
|
|
|
36
37
|
function initApp() {
|
|
37
|
-
const app = new
|
|
38
|
+
const app = new OpenAPIHono<BlankEnv>();
|
|
38
39
|
|
|
39
40
|
// Enable CORS for localhost and local network access
|
|
40
41
|
app.use(
|
|
@@ -110,7 +111,7 @@ export type StandaloneAppConfig = {
|
|
|
110
111
|
};
|
|
111
112
|
|
|
112
113
|
export function createStandaloneApp(_config?: StandaloneAppConfig) {
|
|
113
|
-
const honoApp = new
|
|
114
|
+
const honoApp = new OpenAPIHono<BlankEnv>();
|
|
114
115
|
|
|
115
116
|
honoApp.use(
|
|
116
117
|
'*',
|
|
@@ -203,7 +204,7 @@ export type EmbeddedAppConfig = {
|
|
|
203
204
|
};
|
|
204
205
|
|
|
205
206
|
export function createEmbeddedApp(config: EmbeddedAppConfig = {}) {
|
|
206
|
-
const honoApp = new
|
|
207
|
+
const honoApp = new OpenAPIHono<BlankEnv>();
|
|
207
208
|
|
|
208
209
|
// Store injected config in Hono context for routes to access
|
|
209
210
|
// Config can be empty - routes will fall back to files/env
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { OpenAPIHono, RouteConfig } from '@hono/zod-openapi';
|
|
2
|
+
import { z } from '@hono/zod-openapi';
|
|
3
|
+
import type {
|
|
4
|
+
MediaTypeObject,
|
|
5
|
+
OperationObject,
|
|
6
|
+
ReferenceObject,
|
|
7
|
+
RequestBodyObject,
|
|
8
|
+
ResponseObject,
|
|
9
|
+
} from 'openapi3-ts/oas30';
|
|
10
|
+
import { schemas } from './schemas';
|
|
11
|
+
|
|
12
|
+
export type HttpMethod = RouteConfig['method'];
|
|
13
|
+
|
|
14
|
+
function isReferenceObject(value: unknown): value is ReferenceObject {
|
|
15
|
+
return Boolean(
|
|
16
|
+
value &&
|
|
17
|
+
typeof value === 'object' &&
|
|
18
|
+
'$ref' in value &&
|
|
19
|
+
typeof (value as { $ref?: unknown }).$ref === 'string',
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function schemaToZod(schema: unknown) {
|
|
24
|
+
if (!schema || isReferenceObject(schema)) {
|
|
25
|
+
return z.any().openapi(schema as Record<string, unknown>);
|
|
26
|
+
}
|
|
27
|
+
return z.any().openapi(schema as Record<string, unknown>);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function convertContent(content: ResponseObject['content']) {
|
|
31
|
+
if (!content) return undefined;
|
|
32
|
+
return Object.fromEntries(
|
|
33
|
+
Object.entries(content).map(([contentType, mediaType]) => [
|
|
34
|
+
contentType,
|
|
35
|
+
{
|
|
36
|
+
...(mediaType as MediaTypeObject),
|
|
37
|
+
schema: schemaToZod((mediaType as MediaTypeObject).schema),
|
|
38
|
+
},
|
|
39
|
+
]),
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function convertRequestBody(
|
|
44
|
+
requestBody: OperationObject['requestBody'],
|
|
45
|
+
): RouteConfig['request'] extends { body?: infer Body } ? Body : never {
|
|
46
|
+
if (!requestBody || isReferenceObject(requestBody))
|
|
47
|
+
return requestBody as never;
|
|
48
|
+
const body = requestBody as RequestBodyObject;
|
|
49
|
+
return {
|
|
50
|
+
...body,
|
|
51
|
+
content: convertContent(body.content) ?? {},
|
|
52
|
+
} as never;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function convertResponses(
|
|
56
|
+
operation: OperationObject,
|
|
57
|
+
): RouteConfig['responses'] {
|
|
58
|
+
return Object.fromEntries(
|
|
59
|
+
Object.entries(operation.responses ?? {}).map(([status, response]) => {
|
|
60
|
+
if (isReferenceObject(response)) return [status, response];
|
|
61
|
+
return [
|
|
62
|
+
status,
|
|
63
|
+
{
|
|
64
|
+
...(response as ResponseObject),
|
|
65
|
+
content: convertContent((response as ResponseObject).content),
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
|
+
}),
|
|
69
|
+
) as RouteConfig['responses'];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function buildRouteConfig(
|
|
73
|
+
method: HttpMethod,
|
|
74
|
+
path: string,
|
|
75
|
+
operation: OperationObject,
|
|
76
|
+
): RouteConfig {
|
|
77
|
+
return {
|
|
78
|
+
...operation,
|
|
79
|
+
method,
|
|
80
|
+
path,
|
|
81
|
+
request: {
|
|
82
|
+
body: convertRequestBody(operation.requestBody),
|
|
83
|
+
},
|
|
84
|
+
responses: convertResponses(operation),
|
|
85
|
+
} as RouteConfig;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function registerOpenApiComponents(app: OpenAPIHono) {
|
|
89
|
+
for (const [name, schema] of Object.entries(schemas)) {
|
|
90
|
+
app.openAPIRegistry.registerComponent('schemas', name, schema as never);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createRoute, type OpenAPIHono } from '@hono/zod-openapi';
|
|
2
|
+
import type { Handler, Hono } from 'hono';
|
|
3
|
+
import type { OperationObject } from 'openapi3-ts/oas30';
|
|
4
|
+
import { buildRouteConfig, type HttpMethod } from './register.ts';
|
|
5
|
+
|
|
6
|
+
type InlineRouteConfig = OperationObject & {
|
|
7
|
+
method: HttpMethod;
|
|
8
|
+
path: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export function openApiRoute(
|
|
12
|
+
app: Hono,
|
|
13
|
+
route: InlineRouteConfig,
|
|
14
|
+
handler: Handler,
|
|
15
|
+
) {
|
|
16
|
+
const openApiApp = app as OpenAPIHono;
|
|
17
|
+
const { method, path, ...operation } = route;
|
|
18
|
+
return openApiApp.openapi(
|
|
19
|
+
createRoute(buildRouteConfig(method, path, operation)),
|
|
20
|
+
handler as never,
|
|
21
|
+
);
|
|
22
|
+
}
|
package/src/routes/ask.ts
CHANGED
|
@@ -8,116 +8,227 @@ import { handleAskRequest } from '../runtime/ask/service.ts';
|
|
|
8
8
|
import { serializeError } from '../runtime/errors/api-error.ts';
|
|
9
9
|
import { logger } from '@ottocode/sdk';
|
|
10
10
|
import type { EmbeddedAppConfig } from '../index.ts';
|
|
11
|
+
import { openApiRoute } from '../openapi/route.ts';
|
|
11
12
|
|
|
12
13
|
export function registerAskRoutes(app: Hono) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
14
|
+
openApiRoute(
|
|
15
|
+
app,
|
|
16
|
+
{
|
|
17
|
+
method: 'post',
|
|
18
|
+
path: '/v1/ask',
|
|
19
|
+
tags: ['ask'],
|
|
20
|
+
operationId: 'ask',
|
|
21
|
+
summary: 'Send a prompt using the ask service',
|
|
22
|
+
description:
|
|
23
|
+
'Streamlined endpoint used by the CLI to send prompts and receive assistant responses. Creates sessions as needed and reuses the last session when requested.',
|
|
24
|
+
parameters: [
|
|
25
|
+
{
|
|
26
|
+
in: 'query',
|
|
27
|
+
name: 'project',
|
|
28
|
+
required: false,
|
|
29
|
+
schema: {
|
|
30
|
+
type: 'string',
|
|
31
|
+
},
|
|
32
|
+
description:
|
|
33
|
+
'Project root override (defaults to current working directory).',
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
requestBody: {
|
|
37
|
+
required: true,
|
|
38
|
+
content: {
|
|
39
|
+
'application/json': {
|
|
40
|
+
schema: {
|
|
41
|
+
type: 'object',
|
|
42
|
+
required: ['prompt'],
|
|
43
|
+
properties: {
|
|
44
|
+
prompt: {
|
|
45
|
+
type: 'string',
|
|
46
|
+
description: 'User prompt to send to the assistant.',
|
|
47
|
+
},
|
|
48
|
+
agent: {
|
|
49
|
+
type: 'string',
|
|
50
|
+
description: 'Optional agent name to use for this request.',
|
|
51
|
+
},
|
|
52
|
+
provider: {
|
|
53
|
+
$ref: '#/components/schemas/Provider',
|
|
54
|
+
description:
|
|
55
|
+
'Optional provider override. When omitted the agent and config defaults apply.',
|
|
56
|
+
},
|
|
57
|
+
model: {
|
|
58
|
+
type: 'string',
|
|
59
|
+
description:
|
|
60
|
+
'Optional model override for the selected provider.',
|
|
61
|
+
},
|
|
62
|
+
reasoningText: {
|
|
63
|
+
type: 'boolean',
|
|
64
|
+
description:
|
|
65
|
+
'Enable extended thinking / reasoning for models that support it.',
|
|
66
|
+
},
|
|
67
|
+
reasoningLevel: {
|
|
68
|
+
type: 'string',
|
|
69
|
+
enum: ['minimal', 'low', 'medium', 'high', 'max', 'xhigh'],
|
|
70
|
+
description:
|
|
71
|
+
'Optional reasoning intensity override for supported providers/models.',
|
|
72
|
+
},
|
|
73
|
+
sessionId: {
|
|
74
|
+
type: 'string',
|
|
75
|
+
description: 'Send the prompt to a specific session.',
|
|
76
|
+
},
|
|
77
|
+
last: {
|
|
78
|
+
type: 'boolean',
|
|
79
|
+
description:
|
|
80
|
+
'If true, reuse the most recent session for the project.',
|
|
81
|
+
},
|
|
82
|
+
jsonMode: {
|
|
83
|
+
type: 'boolean',
|
|
84
|
+
description:
|
|
85
|
+
'Request structured JSON output when supported by the agent.',
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
responses: {
|
|
93
|
+
'202': {
|
|
94
|
+
description: 'Accepted',
|
|
95
|
+
content: {
|
|
96
|
+
'application/json': {
|
|
97
|
+
schema: {
|
|
98
|
+
$ref: '#/components/schemas/AskResponse',
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
'400': {
|
|
104
|
+
description: 'Bad Request',
|
|
105
|
+
content: {
|
|
106
|
+
'application/json': {
|
|
107
|
+
schema: {
|
|
108
|
+
type: 'object',
|
|
109
|
+
properties: {
|
|
110
|
+
error: {
|
|
111
|
+
type: 'string',
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
required: ['error'],
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
async (c) => {
|
|
122
|
+
const projectRoot = c.req.query('project') || process.cwd();
|
|
123
|
+
const body = (await c.req.json().catch(() => ({}))) as Record<
|
|
124
|
+
string,
|
|
125
|
+
unknown
|
|
126
|
+
>;
|
|
127
|
+
const prompt = typeof body.prompt === 'string' ? body.prompt : '';
|
|
128
|
+
if (!prompt.trim().length) {
|
|
129
|
+
return c.json({ error: 'Prompt is required.' }, 400);
|
|
27
130
|
}
|
|
28
|
-
).get('embeddedConfig');
|
|
29
131
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
132
|
+
const embeddedConfig = (
|
|
133
|
+
c as unknown as {
|
|
134
|
+
get: (key: 'embeddedConfig') => EmbeddedAppConfig | undefined;
|
|
135
|
+
}
|
|
136
|
+
).get('embeddedConfig');
|
|
34
137
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
defaults ||
|
|
40
|
-
embeddedConfig.provider ||
|
|
41
|
-
embeddedConfig.model ||
|
|
42
|
-
embeddedConfig.agent;
|
|
138
|
+
// Hybrid fallback: Use embedded config if provided, otherwise fall back to files/env
|
|
139
|
+
let injectableConfig: InjectableConfig | undefined;
|
|
140
|
+
let injectableCredentials: InjectableCredentials | undefined;
|
|
141
|
+
let skipFileConfig = false;
|
|
43
142
|
|
|
44
|
-
if (
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
143
|
+
if (embeddedConfig && Object.keys(embeddedConfig).length > 0) {
|
|
144
|
+
// Has embedded config - build injectable config from it
|
|
145
|
+
const defaults = embeddedConfig.defaults;
|
|
146
|
+
const hasDefaults =
|
|
147
|
+
defaults ||
|
|
148
|
+
embeddedConfig.provider ||
|
|
149
|
+
embeddedConfig.model ||
|
|
150
|
+
embeddedConfig.agent;
|
|
51
151
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
for (const [provider, auth] of Object.entries(embeddedConfig.auth)) {
|
|
58
|
-
if ('apiKey' in auth) {
|
|
59
|
-
(injectableCredentials as Record<string, { apiKey: string }>)[
|
|
60
|
-
provider
|
|
61
|
-
] = { apiKey: auth.apiKey };
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
} else if (embeddedConfig.apiKey && embeddedConfig.provider) {
|
|
65
|
-
injectableCredentials = {
|
|
66
|
-
[embeddedConfig.provider]: { apiKey: embeddedConfig.apiKey },
|
|
152
|
+
if (hasDefaults) {
|
|
153
|
+
injectableConfig = {
|
|
154
|
+
provider: defaults?.provider ?? embeddedConfig.provider,
|
|
155
|
+
model: defaults?.model ?? embeddedConfig.model,
|
|
156
|
+
agent: defaults?.agent ?? embeddedConfig.agent,
|
|
67
157
|
};
|
|
68
158
|
}
|
|
69
159
|
|
|
70
|
-
//
|
|
71
|
-
|
|
160
|
+
// Convert embedded auth to injectable credentials
|
|
161
|
+
const hasAuth = embeddedConfig.auth || embeddedConfig.apiKey;
|
|
162
|
+
if (hasAuth) {
|
|
163
|
+
if (embeddedConfig.auth) {
|
|
164
|
+
injectableCredentials = {} as InjectableCredentials;
|
|
165
|
+
for (const [provider, auth] of Object.entries(
|
|
166
|
+
embeddedConfig.auth,
|
|
167
|
+
)) {
|
|
168
|
+
if ('apiKey' in auth) {
|
|
169
|
+
(injectableCredentials as Record<string, { apiKey: string }>)[
|
|
170
|
+
provider
|
|
171
|
+
] = { apiKey: auth.apiKey };
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
} else if (embeddedConfig.apiKey && embeddedConfig.provider) {
|
|
175
|
+
injectableCredentials = {
|
|
176
|
+
[embeddedConfig.provider]: { apiKey: embeddedConfig.apiKey },
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Only skip file config if we have credentials injected
|
|
181
|
+
skipFileConfig = true;
|
|
182
|
+
}
|
|
183
|
+
// If no auth provided, skipFileConfig stays false -> will use ensureProviderEnv -> auth.json fallback
|
|
72
184
|
}
|
|
73
|
-
// If no auth provided, skipFileConfig stays false -> will use ensureProviderEnv -> auth.json fallback
|
|
74
|
-
}
|
|
75
185
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
186
|
+
const request: AskServerRequest = {
|
|
187
|
+
projectRoot,
|
|
188
|
+
prompt,
|
|
189
|
+
agent: typeof body.agent === 'string' ? body.agent : undefined,
|
|
190
|
+
provider: typeof body.provider === 'string' ? body.provider : undefined,
|
|
191
|
+
model: typeof body.model === 'string' ? body.model : undefined,
|
|
192
|
+
reasoningText:
|
|
193
|
+
typeof body.reasoningText === 'boolean'
|
|
194
|
+
? body.reasoningText
|
|
195
|
+
: undefined,
|
|
196
|
+
reasoningLevel:
|
|
197
|
+
typeof body.reasoningLevel === 'string'
|
|
198
|
+
? (body.reasoningLevel as AskServerRequest['reasoningLevel'])
|
|
199
|
+
: undefined,
|
|
200
|
+
sessionId:
|
|
201
|
+
typeof body.sessionId === 'string' ? body.sessionId : undefined,
|
|
202
|
+
last: Boolean(body.last),
|
|
203
|
+
jsonMode: Boolean(body.jsonMode),
|
|
204
|
+
skipFileConfig:
|
|
205
|
+
skipFileConfig ||
|
|
206
|
+
(typeof body.skipFileConfig === 'boolean'
|
|
207
|
+
? body.skipFileConfig
|
|
208
|
+
: false),
|
|
209
|
+
config:
|
|
210
|
+
injectableConfig ||
|
|
211
|
+
(body.config && typeof body.config === 'object'
|
|
212
|
+
? (body.config as InjectableConfig)
|
|
213
|
+
: undefined),
|
|
214
|
+
credentials:
|
|
215
|
+
injectableCredentials ||
|
|
216
|
+
(body.credentials && typeof body.credentials === 'object'
|
|
217
|
+
? (body.credentials as InjectableCredentials)
|
|
218
|
+
: undefined),
|
|
219
|
+
agentPrompt:
|
|
220
|
+
typeof body.agentPrompt === 'string' ? body.agentPrompt : undefined,
|
|
221
|
+
tools: Array.isArray(body.tools) ? body.tools : undefined,
|
|
222
|
+
};
|
|
113
223
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
224
|
+
try {
|
|
225
|
+
const response = await handleAskRequest(request);
|
|
226
|
+
return c.json(response, 202);
|
|
227
|
+
} catch (err) {
|
|
228
|
+
logger.error('Ask request failed', err);
|
|
229
|
+
const errorResponse = serializeError(err);
|
|
230
|
+
return c.json(errorResponse, errorResponse.error.status || 400);
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
);
|
|
123
234
|
}
|