@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.
Files changed (67) hide show
  1. package/package.json +4 -3
  2. package/src/index.ts +5 -4
  3. package/src/openapi/register.ts +92 -0
  4. package/src/openapi/route.ts +22 -0
  5. package/src/routes/ask.ts +210 -99
  6. package/src/routes/auth.ts +1701 -626
  7. package/src/routes/branch.ts +281 -90
  8. package/src/routes/config/agents.ts +79 -32
  9. package/src/routes/config/cwd.ts +46 -14
  10. package/src/routes/config/debug.ts +159 -30
  11. package/src/routes/config/defaults.ts +182 -64
  12. package/src/routes/config/main.ts +109 -73
  13. package/src/routes/config/models.ts +304 -137
  14. package/src/routes/config/providers.ts +462 -166
  15. package/src/routes/config/utils.ts +2 -2
  16. package/src/routes/doctor.ts +395 -161
  17. package/src/routes/files.ts +650 -260
  18. package/src/routes/git/branch.ts +143 -52
  19. package/src/routes/git/commit.ts +347 -141
  20. package/src/routes/git/diff.ts +239 -116
  21. package/src/routes/git/init.ts +103 -23
  22. package/src/routes/git/pull.ts +167 -65
  23. package/src/routes/git/push.ts +222 -117
  24. package/src/routes/git/remote.ts +401 -100
  25. package/src/routes/git/staging.ts +502 -141
  26. package/src/routes/git/status.ts +171 -78
  27. package/src/routes/mcp.ts +1129 -404
  28. package/src/routes/openapi.ts +27 -4
  29. package/src/routes/ottorouter.ts +1221 -389
  30. package/src/routes/provider-usage.ts +153 -36
  31. package/src/routes/research.ts +817 -370
  32. package/src/routes/root.ts +50 -6
  33. package/src/routes/session-approval.ts +228 -54
  34. package/src/routes/session-files.ts +265 -134
  35. package/src/routes/session-messages.ts +330 -150
  36. package/src/routes/session-stream.ts +83 -2
  37. package/src/routes/sessions.ts +1830 -780
  38. package/src/routes/skills.ts +849 -161
  39. package/src/routes/terminals.ts +469 -103
  40. package/src/routes/tunnel.ts +394 -118
  41. package/src/runtime/ask/service.ts +1 -0
  42. package/src/runtime/message/compaction-limits.ts +3 -3
  43. package/src/runtime/provider/reasoning.ts +2 -1
  44. package/src/runtime/session/db-operations.ts +4 -3
  45. package/src/runtime/utils/token.ts +7 -2
  46. package/src/tools/adapter.ts +21 -0
  47. package/src/openapi/paths/ask.ts +0 -81
  48. package/src/openapi/paths/auth.ts +0 -687
  49. package/src/openapi/paths/branch.ts +0 -102
  50. package/src/openapi/paths/config.ts +0 -485
  51. package/src/openapi/paths/doctor.ts +0 -165
  52. package/src/openapi/paths/files.ts +0 -236
  53. package/src/openapi/paths/git.ts +0 -690
  54. package/src/openapi/paths/mcp.ts +0 -339
  55. package/src/openapi/paths/messages.ts +0 -103
  56. package/src/openapi/paths/ottorouter.ts +0 -594
  57. package/src/openapi/paths/provider-usage.ts +0 -59
  58. package/src/openapi/paths/research.ts +0 -227
  59. package/src/openapi/paths/session-approval.ts +0 -93
  60. package/src/openapi/paths/session-extras.ts +0 -336
  61. package/src/openapi/paths/session-files.ts +0 -91
  62. package/src/openapi/paths/sessions.ts +0 -210
  63. package/src/openapi/paths/skills.ts +0 -377
  64. package/src/openapi/paths/stream.ts +0 -26
  65. package/src/openapi/paths/terminals.ts +0 -226
  66. package/src/openapi/paths/tunnel.ts +0 -163
  67. 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
- app.get('/v1/provider-usage/:provider', async (c) => {
161
- try {
162
- const provider = c.req.param('provider') as ProviderId;
163
-
164
- if (provider !== 'anthropic' && provider !== 'openai') {
165
- return c.json(
166
- { error: { message: 'Usage not supported for this provider' } },
167
- 400,
168
- );
169
- }
170
-
171
- const tokenResult = await ensureValidOAuth(provider);
172
- if (!tokenResult) {
173
- return c.json(
174
- {
175
- error: {
176
- message: `No OAuth credentials for ${provider}. Usage is only available for OAuth-authenticated providers.`,
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
- 404,
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
- const usage =
184
- provider === 'anthropic'
185
- ? await fetchAnthropicUsage(tokenResult.access)
186
- : await fetchOpenAIUsage(
187
- tokenResult.access,
188
- tokenResult.oauth.accountId,
189
- );
190
-
191
- return c.json(usage);
192
- } catch (error) {
193
- logger.error('Failed to fetch provider usage', error);
194
- const errorResponse = serializeError(error);
195
- const status = (errorResponse.error.status || 500) as 500;
196
- return c.json(errorResponse, status);
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
  }