@ottocode/server 0.1.173

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 (111) hide show
  1. package/package.json +42 -0
  2. package/src/events/bus.ts +43 -0
  3. package/src/events/types.ts +32 -0
  4. package/src/index.ts +281 -0
  5. package/src/openapi/helpers.ts +64 -0
  6. package/src/openapi/paths/ask.ts +70 -0
  7. package/src/openapi/paths/config.ts +218 -0
  8. package/src/openapi/paths/files.ts +72 -0
  9. package/src/openapi/paths/git.ts +457 -0
  10. package/src/openapi/paths/messages.ts +92 -0
  11. package/src/openapi/paths/sessions.ts +90 -0
  12. package/src/openapi/paths/setu.ts +154 -0
  13. package/src/openapi/paths/stream.ts +26 -0
  14. package/src/openapi/paths/terminals.ts +226 -0
  15. package/src/openapi/schemas.ts +345 -0
  16. package/src/openapi/spec.ts +49 -0
  17. package/src/presets.ts +85 -0
  18. package/src/routes/ask.ts +113 -0
  19. package/src/routes/auth.ts +592 -0
  20. package/src/routes/branch.ts +106 -0
  21. package/src/routes/config/agents.ts +44 -0
  22. package/src/routes/config/cwd.ts +21 -0
  23. package/src/routes/config/defaults.ts +45 -0
  24. package/src/routes/config/index.ts +16 -0
  25. package/src/routes/config/main.ts +73 -0
  26. package/src/routes/config/models.ts +139 -0
  27. package/src/routes/config/providers.ts +46 -0
  28. package/src/routes/config/utils.ts +120 -0
  29. package/src/routes/files.ts +218 -0
  30. package/src/routes/git/branch.ts +75 -0
  31. package/src/routes/git/commit.ts +209 -0
  32. package/src/routes/git/diff.ts +137 -0
  33. package/src/routes/git/index.ts +18 -0
  34. package/src/routes/git/push.ts +160 -0
  35. package/src/routes/git/schemas.ts +48 -0
  36. package/src/routes/git/staging.ts +208 -0
  37. package/src/routes/git/status.ts +83 -0
  38. package/src/routes/git/types.ts +31 -0
  39. package/src/routes/git/utils.ts +249 -0
  40. package/src/routes/openapi.ts +6 -0
  41. package/src/routes/research.ts +392 -0
  42. package/src/routes/root.ts +5 -0
  43. package/src/routes/session-approval.ts +63 -0
  44. package/src/routes/session-files.ts +387 -0
  45. package/src/routes/session-messages.ts +170 -0
  46. package/src/routes/session-stream.ts +61 -0
  47. package/src/routes/sessions.ts +814 -0
  48. package/src/routes/setu.ts +346 -0
  49. package/src/routes/terminals.ts +227 -0
  50. package/src/runtime/agent/registry.ts +351 -0
  51. package/src/runtime/agent/runner-reasoning.ts +108 -0
  52. package/src/runtime/agent/runner-setup.ts +257 -0
  53. package/src/runtime/agent/runner.ts +375 -0
  54. package/src/runtime/agent-registry.ts +6 -0
  55. package/src/runtime/ask/service.ts +369 -0
  56. package/src/runtime/context/environment.ts +202 -0
  57. package/src/runtime/debug/index.ts +117 -0
  58. package/src/runtime/debug/state.ts +140 -0
  59. package/src/runtime/errors/api-error.ts +192 -0
  60. package/src/runtime/errors/handling.ts +199 -0
  61. package/src/runtime/message/compaction-auto.ts +154 -0
  62. package/src/runtime/message/compaction-context.ts +101 -0
  63. package/src/runtime/message/compaction-detect.ts +26 -0
  64. package/src/runtime/message/compaction-limits.ts +37 -0
  65. package/src/runtime/message/compaction-mark.ts +111 -0
  66. package/src/runtime/message/compaction-prune.ts +75 -0
  67. package/src/runtime/message/compaction.ts +21 -0
  68. package/src/runtime/message/history-builder.ts +266 -0
  69. package/src/runtime/message/service.ts +468 -0
  70. package/src/runtime/message/tool-history-tracker.ts +204 -0
  71. package/src/runtime/prompt/builder.ts +167 -0
  72. package/src/runtime/provider/anthropic.ts +50 -0
  73. package/src/runtime/provider/copilot.ts +12 -0
  74. package/src/runtime/provider/google.ts +8 -0
  75. package/src/runtime/provider/index.ts +60 -0
  76. package/src/runtime/provider/moonshot.ts +8 -0
  77. package/src/runtime/provider/oauth-adapter.ts +237 -0
  78. package/src/runtime/provider/openai.ts +18 -0
  79. package/src/runtime/provider/opencode.ts +7 -0
  80. package/src/runtime/provider/openrouter.ts +7 -0
  81. package/src/runtime/provider/selection.ts +118 -0
  82. package/src/runtime/provider/setu.ts +126 -0
  83. package/src/runtime/provider/zai.ts +16 -0
  84. package/src/runtime/session/branch.ts +280 -0
  85. package/src/runtime/session/db-operations.ts +285 -0
  86. package/src/runtime/session/manager.ts +99 -0
  87. package/src/runtime/session/queue.ts +243 -0
  88. package/src/runtime/stream/abort-handler.ts +65 -0
  89. package/src/runtime/stream/error-handler.ts +371 -0
  90. package/src/runtime/stream/finish-handler.ts +101 -0
  91. package/src/runtime/stream/handlers.ts +5 -0
  92. package/src/runtime/stream/step-finish.ts +93 -0
  93. package/src/runtime/stream/types.ts +25 -0
  94. package/src/runtime/tools/approval.ts +180 -0
  95. package/src/runtime/tools/context.ts +83 -0
  96. package/src/runtime/tools/mapping.ts +154 -0
  97. package/src/runtime/tools/setup.ts +44 -0
  98. package/src/runtime/topup/manager.ts +110 -0
  99. package/src/runtime/utils/cwd.ts +69 -0
  100. package/src/runtime/utils/token.ts +35 -0
  101. package/src/tools/adapter.ts +634 -0
  102. package/src/tools/database/get-parent-session.ts +183 -0
  103. package/src/tools/database/get-session-context.ts +161 -0
  104. package/src/tools/database/index.ts +42 -0
  105. package/src/tools/database/present-session-links.ts +47 -0
  106. package/src/tools/database/query-messages.ts +160 -0
  107. package/src/tools/database/query-sessions.ts +126 -0
  108. package/src/tools/database/search-history.ts +135 -0
  109. package/src/types/sql-imports.d.ts +5 -0
  110. package/sst-env.d.ts +8 -0
  111. package/tsconfig.json +7 -0
@@ -0,0 +1,457 @@
1
+ import { gitErrorResponse, projectQueryParam } from '../helpers';
2
+
3
+ export const gitPaths = {
4
+ '/v1/git/status': {
5
+ get: {
6
+ tags: ['git'],
7
+ operationId: 'getGitStatus',
8
+ summary: 'Get git status',
9
+ description:
10
+ 'Returns current git status including staged, unstaged, and untracked files',
11
+ parameters: [projectQueryParam()],
12
+ responses: {
13
+ 200: {
14
+ description: 'OK',
15
+ content: {
16
+ 'application/json': {
17
+ schema: {
18
+ type: 'object',
19
+ properties: {
20
+ status: { type: 'string', enum: ['ok'] },
21
+ data: { $ref: '#/components/schemas/GitStatus' },
22
+ },
23
+ required: ['status', 'data'],
24
+ },
25
+ },
26
+ },
27
+ },
28
+ 400: gitErrorResponse(),
29
+ 500: gitErrorResponse(),
30
+ },
31
+ },
32
+ },
33
+ '/v1/git/diff': {
34
+ get: {
35
+ tags: ['git'],
36
+ operationId: 'getGitDiff',
37
+ summary: 'Get git diff for a file',
38
+ parameters: [
39
+ projectQueryParam(),
40
+ {
41
+ in: 'query',
42
+ name: 'file',
43
+ required: true,
44
+ schema: { type: 'string' },
45
+ description: 'File path to get diff for',
46
+ },
47
+ {
48
+ in: 'query',
49
+ name: 'staged',
50
+ required: false,
51
+ schema: { type: 'string', enum: ['true', 'false'] },
52
+ description: 'Show staged diff (default: unstaged)',
53
+ },
54
+ ],
55
+ responses: {
56
+ 200: {
57
+ description: 'OK',
58
+ content: {
59
+ 'application/json': {
60
+ schema: {
61
+ type: 'object',
62
+ properties: {
63
+ status: { type: 'string', enum: ['ok'] },
64
+ data: { $ref: '#/components/schemas/GitDiff' },
65
+ },
66
+ required: ['status', 'data'],
67
+ },
68
+ },
69
+ },
70
+ },
71
+ 400: gitErrorResponse(),
72
+ 500: gitErrorResponse(),
73
+ },
74
+ },
75
+ },
76
+ '/v1/git/branch': {
77
+ get: {
78
+ tags: ['git'],
79
+ operationId: 'getGitBranch',
80
+ summary: 'Get git branch information',
81
+ parameters: [projectQueryParam()],
82
+ responses: {
83
+ 200: {
84
+ description: 'OK',
85
+ content: {
86
+ 'application/json': {
87
+ schema: {
88
+ type: 'object',
89
+ properties: {
90
+ status: { type: 'string', enum: ['ok'] },
91
+ data: { $ref: '#/components/schemas/GitBranch' },
92
+ },
93
+ required: ['status', 'data'],
94
+ },
95
+ },
96
+ },
97
+ },
98
+ 400: gitErrorResponse(),
99
+ 500: gitErrorResponse(),
100
+ },
101
+ },
102
+ },
103
+ '/v1/git/stage': {
104
+ post: {
105
+ tags: ['git'],
106
+ operationId: 'stageFiles',
107
+ summary: 'Stage files',
108
+ requestBody: {
109
+ required: true,
110
+ content: {
111
+ 'application/json': {
112
+ schema: {
113
+ type: 'object',
114
+ properties: {
115
+ project: { type: 'string' },
116
+ files: {
117
+ type: 'array',
118
+ items: { type: 'string' },
119
+ },
120
+ },
121
+ required: ['files'],
122
+ },
123
+ },
124
+ },
125
+ },
126
+ responses: {
127
+ 200: {
128
+ description: 'OK',
129
+ content: {
130
+ 'application/json': {
131
+ schema: {
132
+ type: 'object',
133
+ properties: {
134
+ status: { type: 'string', enum: ['ok'] },
135
+ data: {
136
+ type: 'object',
137
+ properties: {
138
+ staged: {
139
+ type: 'array',
140
+ items: { type: 'string' },
141
+ },
142
+ failed: {
143
+ type: 'array',
144
+ items: { type: 'string' },
145
+ },
146
+ },
147
+ required: ['staged', 'failed'],
148
+ },
149
+ },
150
+ required: ['status', 'data'],
151
+ },
152
+ },
153
+ },
154
+ },
155
+ 500: gitErrorResponse(),
156
+ },
157
+ },
158
+ },
159
+ '/v1/git/unstage': {
160
+ post: {
161
+ tags: ['git'],
162
+ operationId: 'unstageFiles',
163
+ summary: 'Unstage files',
164
+ requestBody: {
165
+ required: true,
166
+ content: {
167
+ 'application/json': {
168
+ schema: {
169
+ type: 'object',
170
+ properties: {
171
+ project: { type: 'string' },
172
+ files: {
173
+ type: 'array',
174
+ items: { type: 'string' },
175
+ },
176
+ },
177
+ required: ['files'],
178
+ },
179
+ },
180
+ },
181
+ },
182
+ responses: {
183
+ 200: {
184
+ description: 'OK',
185
+ content: {
186
+ 'application/json': {
187
+ schema: {
188
+ type: 'object',
189
+ properties: {
190
+ status: { type: 'string', enum: ['ok'] },
191
+ data: {
192
+ type: 'object',
193
+ properties: {
194
+ unstaged: {
195
+ type: 'array',
196
+ items: { type: 'string' },
197
+ },
198
+ failed: {
199
+ type: 'array',
200
+ items: { type: 'string' },
201
+ },
202
+ },
203
+ required: ['unstaged', 'failed'],
204
+ },
205
+ },
206
+ required: ['status', 'data'],
207
+ },
208
+ },
209
+ },
210
+ },
211
+ 500: gitErrorResponse(),
212
+ },
213
+ },
214
+ },
215
+ '/v1/git/commit': {
216
+ post: {
217
+ tags: ['git'],
218
+ operationId: 'commitChanges',
219
+ summary: 'Commit staged changes',
220
+ requestBody: {
221
+ required: true,
222
+ content: {
223
+ 'application/json': {
224
+ schema: {
225
+ type: 'object',
226
+ properties: {
227
+ project: { type: 'string' },
228
+ message: { type: 'string', minLength: 1 },
229
+ },
230
+ required: ['message'],
231
+ },
232
+ },
233
+ },
234
+ },
235
+ responses: {
236
+ 200: {
237
+ description: 'OK',
238
+ content: {
239
+ 'application/json': {
240
+ schema: {
241
+ type: 'object',
242
+ properties: {
243
+ status: { type: 'string', enum: ['ok'] },
244
+ data: { $ref: '#/components/schemas/GitCommit' },
245
+ },
246
+ required: ['status', 'data'],
247
+ },
248
+ },
249
+ },
250
+ },
251
+ 400: gitErrorResponse(),
252
+ 500: gitErrorResponse(),
253
+ },
254
+ },
255
+ },
256
+ '/v1/git/generate-commit-message': {
257
+ post: {
258
+ tags: ['git'],
259
+ operationId: 'generateCommitMessage',
260
+ summary: 'Generate AI-powered commit message',
261
+ description:
262
+ 'Uses AI to generate a commit message based on staged changes',
263
+ requestBody: {
264
+ required: false,
265
+ content: {
266
+ 'application/json': {
267
+ schema: {
268
+ type: 'object',
269
+ properties: {
270
+ project: { type: 'string' },
271
+ sessionId: {
272
+ type: 'string',
273
+ description: 'Session ID to use session provider',
274
+ },
275
+ },
276
+ },
277
+ },
278
+ },
279
+ },
280
+ responses: {
281
+ 200: {
282
+ description: 'OK',
283
+ content: {
284
+ 'application/json': {
285
+ schema: {
286
+ type: 'object',
287
+ properties: {
288
+ status: { type: 'string', enum: ['ok'] },
289
+ data: {
290
+ type: 'object',
291
+ properties: {
292
+ message: { type: 'string' },
293
+ },
294
+ required: ['message'],
295
+ },
296
+ },
297
+ required: ['status', 'data'],
298
+ },
299
+ },
300
+ },
301
+ },
302
+ 400: gitErrorResponse(),
303
+ 500: gitErrorResponse(),
304
+ },
305
+ },
306
+ },
307
+ '/v1/git/push': {
308
+ post: {
309
+ tags: ['git'],
310
+ operationId: 'pushCommits',
311
+ summary: 'Push commits to remote',
312
+ description: 'Pushes local commits to the configured remote repository',
313
+ requestBody: {
314
+ required: false,
315
+ content: {
316
+ 'application/json': {
317
+ schema: {
318
+ type: 'object',
319
+ properties: {
320
+ project: { type: 'string' },
321
+ },
322
+ },
323
+ },
324
+ },
325
+ },
326
+ responses: {
327
+ 200: {
328
+ description: 'OK',
329
+ content: {
330
+ 'application/json': {
331
+ schema: {
332
+ type: 'object',
333
+ properties: {
334
+ status: { type: 'string', enum: ['ok'] },
335
+ data: {
336
+ type: 'object',
337
+ properties: {
338
+ output: { type: 'string' },
339
+ },
340
+ required: ['output'],
341
+ },
342
+ },
343
+ required: ['status', 'data'],
344
+ },
345
+ },
346
+ },
347
+ },
348
+ 400: gitErrorResponse(),
349
+ 500: gitErrorResponse(),
350
+ },
351
+ },
352
+ },
353
+ '/v1/git/restore': {
354
+ post: {
355
+ tags: ['git'],
356
+ operationId: 'restoreFiles',
357
+ summary: 'Restore files to HEAD',
358
+ requestBody: {
359
+ required: true,
360
+ content: {
361
+ 'application/json': {
362
+ schema: {
363
+ type: 'object',
364
+ properties: {
365
+ project: { type: 'string' },
366
+ files: {
367
+ type: 'array',
368
+ items: { type: 'string' },
369
+ },
370
+ },
371
+ required: ['files'],
372
+ },
373
+ },
374
+ },
375
+ },
376
+ responses: {
377
+ 200: {
378
+ description: 'OK',
379
+ content: {
380
+ 'application/json': {
381
+ schema: {
382
+ type: 'object',
383
+ properties: {
384
+ status: { type: 'string', enum: ['ok'] },
385
+ data: {
386
+ type: 'object',
387
+ properties: {
388
+ restored: {
389
+ type: 'array',
390
+ items: { type: 'string' },
391
+ },
392
+ },
393
+ required: ['restored'],
394
+ },
395
+ },
396
+ required: ['status', 'data'],
397
+ },
398
+ },
399
+ },
400
+ },
401
+ 500: gitErrorResponse(),
402
+ },
403
+ },
404
+ },
405
+ '/v1/git/delete': {
406
+ post: {
407
+ tags: ['git'],
408
+ operationId: 'deleteFiles',
409
+ summary: 'Delete untracked files',
410
+ requestBody: {
411
+ required: true,
412
+ content: {
413
+ 'application/json': {
414
+ schema: {
415
+ type: 'object',
416
+ properties: {
417
+ project: { type: 'string' },
418
+ files: {
419
+ type: 'array',
420
+ items: { type: 'string' },
421
+ },
422
+ },
423
+ required: ['files'],
424
+ },
425
+ },
426
+ },
427
+ },
428
+ responses: {
429
+ 200: {
430
+ description: 'OK',
431
+ content: {
432
+ 'application/json': {
433
+ schema: {
434
+ type: 'object',
435
+ properties: {
436
+ status: { type: 'string', enum: ['ok'] },
437
+ data: {
438
+ type: 'object',
439
+ properties: {
440
+ deleted: {
441
+ type: 'array',
442
+ items: { type: 'string' },
443
+ },
444
+ },
445
+ required: ['deleted'],
446
+ },
447
+ },
448
+ required: ['status', 'data'],
449
+ },
450
+ },
451
+ },
452
+ },
453
+ 500: gitErrorResponse(),
454
+ },
455
+ },
456
+ },
457
+ } as const;
@@ -0,0 +1,92 @@
1
+ import {
2
+ errorResponse,
3
+ projectQueryParam,
4
+ sessionIdParam,
5
+ withoutParam,
6
+ } from '../helpers';
7
+
8
+ export const messagesPaths = {
9
+ '/v1/sessions/{id}/messages': {
10
+ get: {
11
+ tags: ['messages'],
12
+ operationId: 'listMessages',
13
+ summary: 'List messages for a session',
14
+ parameters: [projectQueryParam(), sessionIdParam(), withoutParam()],
15
+ responses: {
16
+ 200: {
17
+ description: 'OK',
18
+ content: {
19
+ 'application/json': {
20
+ schema: {
21
+ type: 'array',
22
+ items: {
23
+ allOf: [
24
+ { $ref: '#/components/schemas/Message' },
25
+ {
26
+ type: 'object',
27
+ properties: {
28
+ parts: {
29
+ type: 'array',
30
+ items: {
31
+ $ref: '#/components/schemas/MessagePart',
32
+ },
33
+ },
34
+ },
35
+ required: [],
36
+ },
37
+ ],
38
+ },
39
+ },
40
+ },
41
+ },
42
+ },
43
+ },
44
+ },
45
+ post: {
46
+ tags: ['messages'],
47
+ operationId: 'createMessage',
48
+ summary: 'Send a user message and enqueue assistant run',
49
+ parameters: [projectQueryParam(), sessionIdParam()],
50
+ requestBody: {
51
+ required: true,
52
+ content: {
53
+ 'application/json': {
54
+ schema: {
55
+ type: 'object',
56
+ required: ['content'],
57
+ properties: {
58
+ content: { type: 'string' },
59
+ agent: {
60
+ type: 'string',
61
+ description: 'Agent name. Defaults to config if omitted.',
62
+ },
63
+ provider: { $ref: '#/components/schemas/Provider' },
64
+ model: { type: 'string' },
65
+ userContext: {
66
+ type: 'string',
67
+ description:
68
+ 'Optional user-provided context to include in the system prompt.',
69
+ },
70
+ },
71
+ },
72
+ },
73
+ },
74
+ },
75
+ responses: {
76
+ 202: {
77
+ description: 'Accepted',
78
+ content: {
79
+ 'application/json': {
80
+ schema: {
81
+ type: 'object',
82
+ properties: { messageId: { type: 'string' } },
83
+ required: ['messageId'],
84
+ },
85
+ },
86
+ },
87
+ },
88
+ 400: errorResponse(),
89
+ },
90
+ },
91
+ },
92
+ } as const;
@@ -0,0 +1,90 @@
1
+ import { errorResponse, projectQueryParam } from '../helpers';
2
+
3
+ export const sessionsPaths = {
4
+ '/v1/sessions': {
5
+ get: {
6
+ tags: ['sessions'],
7
+ operationId: 'listSessions',
8
+ summary: 'List sessions',
9
+ parameters: [projectQueryParam()],
10
+ responses: {
11
+ 200: {
12
+ description: 'OK',
13
+ content: {
14
+ 'application/json': {
15
+ schema: {
16
+ type: 'array',
17
+ items: { $ref: '#/components/schemas/Session' },
18
+ },
19
+ },
20
+ },
21
+ },
22
+ },
23
+ },
24
+ post: {
25
+ tags: ['sessions'],
26
+ operationId: 'createSession',
27
+ summary: 'Create a new session',
28
+ parameters: [projectQueryParam()],
29
+ requestBody: {
30
+ required: false,
31
+ content: {
32
+ 'application/json': {
33
+ schema: {
34
+ type: 'object',
35
+ properties: {
36
+ title: { type: 'string', nullable: true },
37
+ agent: { type: 'string' },
38
+ provider: { $ref: '#/components/schemas/Provider' },
39
+ model: { type: 'string' },
40
+ },
41
+ },
42
+ },
43
+ },
44
+ },
45
+ responses: {
46
+ 201: {
47
+ description: 'Created',
48
+ content: {
49
+ 'application/json': {
50
+ schema: { $ref: '#/components/schemas/Session' },
51
+ },
52
+ },
53
+ },
54
+ 400: errorResponse(),
55
+ },
56
+ },
57
+ },
58
+ '/v1/sessions/{sessionId}/abort': {
59
+ delete: {
60
+ tags: ['sessions'],
61
+ operationId: 'abortSession',
62
+ summary: 'Abort a running session',
63
+ description:
64
+ 'Aborts any currently running assistant generation for the session',
65
+ parameters: [
66
+ {
67
+ in: 'path',
68
+ name: 'sessionId',
69
+ required: true,
70
+ schema: { type: 'string' },
71
+ description: 'Session ID to abort',
72
+ },
73
+ ],
74
+ responses: {
75
+ 200: {
76
+ description: 'OK',
77
+ content: {
78
+ 'application/json': {
79
+ schema: {
80
+ type: 'object',
81
+ properties: { success: { type: 'boolean' } },
82
+ required: ['success'],
83
+ },
84
+ },
85
+ },
86
+ },
87
+ },
88
+ },
89
+ },
90
+ } as const;