@ottocode/server 0.1.259 → 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/agent/runner-reasoning.ts +38 -3
- package/src/runtime/agent/runner.ts +1 -0
- package/src/runtime/ask/service.ts +1 -0
- package/src/runtime/message/compaction-limits.ts +3 -3
- package/src/runtime/provider/reasoning.ts +18 -7
- 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
|
@@ -9,6 +9,7 @@ import { logger } from '@ottocode/sdk';
|
|
|
9
9
|
import { setAuth } from '@ottocode/sdk';
|
|
10
10
|
import { serializeError } from '../runtime/errors/api-error.ts';
|
|
11
11
|
import type { OAuth } from '@ottocode/sdk';
|
|
12
|
+
import { openApiRoute } from '../openapi/route.ts';
|
|
12
13
|
|
|
13
14
|
async function ensureValidOAuth(
|
|
14
15
|
provider: ProviderId,
|
|
@@ -157,43 +158,159 @@ async function fetchOpenAIUsage(access: string, accountId?: string) {
|
|
|
157
158
|
}
|
|
158
159
|
|
|
159
160
|
export function registerProviderUsageRoutes(app: Hono) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
161
|
+
openApiRoute(
|
|
162
|
+
app,
|
|
163
|
+
{
|
|
164
|
+
method: 'get',
|
|
165
|
+
path: '/v1/provider-usage/{provider}',
|
|
166
|
+
tags: ['config'],
|
|
167
|
+
operationId: 'getProviderUsage',
|
|
168
|
+
summary: 'Get usage information for an OAuth provider',
|
|
169
|
+
parameters: [
|
|
170
|
+
{
|
|
171
|
+
in: 'path',
|
|
172
|
+
name: 'provider',
|
|
173
|
+
required: true,
|
|
174
|
+
schema: {
|
|
175
|
+
type: 'string',
|
|
176
|
+
enum: ['anthropic', 'openai'],
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
],
|
|
180
|
+
responses: {
|
|
181
|
+
'200': {
|
|
182
|
+
description: 'OK',
|
|
183
|
+
content: {
|
|
184
|
+
'application/json': {
|
|
185
|
+
schema: {
|
|
186
|
+
type: 'object',
|
|
187
|
+
properties: {
|
|
188
|
+
provider: {
|
|
189
|
+
type: 'string',
|
|
190
|
+
},
|
|
191
|
+
primaryWindow: {
|
|
192
|
+
type: 'object',
|
|
193
|
+
nullable: true,
|
|
194
|
+
properties: {
|
|
195
|
+
usedPercent: {
|
|
196
|
+
type: 'number',
|
|
197
|
+
},
|
|
198
|
+
windowSeconds: {
|
|
199
|
+
type: 'integer',
|
|
200
|
+
},
|
|
201
|
+
resetsAt: {
|
|
202
|
+
type: 'string',
|
|
203
|
+
nullable: true,
|
|
204
|
+
},
|
|
205
|
+
resetAfterSeconds: {
|
|
206
|
+
type: 'integer',
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
secondaryWindow: {
|
|
211
|
+
type: 'object',
|
|
212
|
+
nullable: true,
|
|
213
|
+
properties: {
|
|
214
|
+
usedPercent: {
|
|
215
|
+
type: 'number',
|
|
216
|
+
},
|
|
217
|
+
windowSeconds: {
|
|
218
|
+
type: 'integer',
|
|
219
|
+
},
|
|
220
|
+
resetsAt: {
|
|
221
|
+
type: 'string',
|
|
222
|
+
nullable: true,
|
|
223
|
+
},
|
|
224
|
+
resetAfterSeconds: {
|
|
225
|
+
type: 'integer',
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
limitReached: {
|
|
230
|
+
type: 'boolean',
|
|
231
|
+
},
|
|
232
|
+
planType: {
|
|
233
|
+
type: 'string',
|
|
234
|
+
nullable: true,
|
|
235
|
+
},
|
|
236
|
+
},
|
|
237
|
+
required: ['provider', 'limitReached'],
|
|
238
|
+
},
|
|
177
239
|
},
|
|
178
240
|
},
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
241
|
+
},
|
|
242
|
+
'400': {
|
|
243
|
+
description: 'Bad Request',
|
|
244
|
+
content: {
|
|
245
|
+
'application/json': {
|
|
246
|
+
schema: {
|
|
247
|
+
type: 'object',
|
|
248
|
+
properties: {
|
|
249
|
+
error: {
|
|
250
|
+
type: 'string',
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
required: ['error'],
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
},
|
|
258
|
+
'404': {
|
|
259
|
+
description: 'Bad Request',
|
|
260
|
+
content: {
|
|
261
|
+
'application/json': {
|
|
262
|
+
schema: {
|
|
263
|
+
type: 'object',
|
|
264
|
+
properties: {
|
|
265
|
+
error: {
|
|
266
|
+
type: 'string',
|
|
267
|
+
},
|
|
268
|
+
},
|
|
269
|
+
required: ['error'],
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
},
|
|
274
|
+
},
|
|
275
|
+
},
|
|
276
|
+
async (c) => {
|
|
277
|
+
try {
|
|
278
|
+
const provider = c.req.param('provider') as ProviderId;
|
|
182
279
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
280
|
+
if (provider !== 'anthropic' && provider !== 'openai') {
|
|
281
|
+
return c.json(
|
|
282
|
+
{ error: { message: 'Usage not supported for this provider' } },
|
|
283
|
+
400,
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const tokenResult = await ensureValidOAuth(provider);
|
|
288
|
+
if (!tokenResult) {
|
|
289
|
+
return c.json(
|
|
290
|
+
{
|
|
291
|
+
error: {
|
|
292
|
+
message: `No OAuth credentials for ${provider}. Usage is only available for OAuth-authenticated providers.`,
|
|
293
|
+
},
|
|
294
|
+
},
|
|
295
|
+
404,
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const usage =
|
|
300
|
+
provider === 'anthropic'
|
|
301
|
+
? await fetchAnthropicUsage(tokenResult.access)
|
|
302
|
+
: await fetchOpenAIUsage(
|
|
303
|
+
tokenResult.access,
|
|
304
|
+
tokenResult.oauth.accountId,
|
|
305
|
+
);
|
|
306
|
+
|
|
307
|
+
return c.json(usage);
|
|
308
|
+
} catch (error) {
|
|
309
|
+
logger.error('Failed to fetch provider usage', error);
|
|
310
|
+
const errorResponse = serializeError(error);
|
|
311
|
+
const status = (errorResponse.error.status || 500) as 500;
|
|
312
|
+
return c.json(errorResponse, status);
|
|
313
|
+
}
|
|
314
|
+
},
|
|
315
|
+
);
|
|
199
316
|
}
|