-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenapi.yaml
More file actions
1807 lines (1802 loc) · 70.6 KB
/
Copy pathopenapi.yaml
File metadata and controls
1807 lines (1802 loc) · 70.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
openapi: 3.0.3
info:
title: claude-code-java Gateway Web API
version: 1.0.0-draft
description: |
The in-process HTTP+SSE gateway serving web clients of the same instance
(TUI keeps its own session; the gateway routes parallel headless sessions
and mirrors every followed session).
This contract is the authoritative alignment standard for the gateway's
web rendering API, keeping official Claude Code stream-json wire naming
first priority. It is the single source of truth: the SSE mirror-frame
catalog lives in the MirrorFrame schema, not in a side document.
Alignment strategy (two steps): this document is the standard first; code
implementation then aligns to it.
servers:
- url: http://127.0.0.1:{port}
description: Loopback gateway launched by the /web command (token required)
variables:
port:
default: '0'
security:
- bearerToken: []
- queryToken: []
tags:
- name: Protocol
description: The three streaming turn-submission wire formats (Anthropic/OpenAI-compatible)
- name: Sessions
description: Session catalog, headless open/close, message snapshots, and the SSE mirror stream
- name: Permissions
description: Answering pending permission asks and user questions
- name: Settings
description: Effective settings snapshot and per-tier settings mutations
- name: Schedule
description: Cron-style scheduled task management
- name: Models
description: The custom model catalogue shared with the /model command
paths:
/v1/messages:
post:
tags: [Protocol]
summary: Anthropic Messages protocol face (streaming SSE)
description: |
Submits one turn. The session is routed by metadata.session_id:
absent → the active session (409 when none); a headless session id;
or the active TUI session's own id. Responses follow the Anthropic
streaming wire format (message_start / content_block_* / message_stop).
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [model, messages]
properties:
model:
type: string
stream:
type: boolean
default: true
metadata:
type: object
properties:
session_id:
type: string
description: Session routing key (headless id, active TUI id, or absent)
user_id:
type: string
description: Idempotency key; a repeated value does not resubmit
messages:
type: array
items:
$ref: '#/components/schemas/ProtocolMessage'
responses:
'200':
description: SSE stream of the turn (Anthropic streaming events)
'400': { $ref: '#/components/responses/InvalidRequest' }
'401': { $ref: '#/components/responses/Unauthorized' }
'404': { $ref: '#/components/responses/UnknownSession' }
'409': { $ref: '#/components/responses/NoActiveSession' }
'429': { $ref: '#/components/responses/SessionBusy' }
/v1/chat/completions:
post:
tags: [Protocol]
summary: OpenAI Chat Completions protocol face (streaming SSE)
description: Same routing and turn semantics as /v1/messages over the OpenAI wire format.
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [model, messages]
properties:
model: { type: string }
stream: { type: boolean, default: true }
metadata:
type: object
properties:
session_id: { type: string }
user_id: { type: string }
messages:
type: array
items: { $ref: '#/components/schemas/ProtocolMessage' }
responses:
'200': { description: SSE stream of the turn (OpenAI wire events) }
'400': { $ref: '#/components/responses/InvalidRequest' }
'401': { $ref: '#/components/responses/Unauthorized' }
'404': { $ref: '#/components/responses/UnknownSession' }
'409': { $ref: '#/components/responses/NoActiveSession' }
'429': { $ref: '#/components/responses/SessionBusy' }
/v1/responses:
post:
tags: [Protocol]
summary: OpenAI Responses protocol face (streaming SSE)
description: Same routing and turn semantics as /v1/messages over the Responses wire format.
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [model, input]
properties:
model: { type: string }
stream: { type: boolean, default: true }
metadata:
type: object
properties:
session_id: { type: string }
user_id: { type: string }
input: { $ref: '#/components/schemas/ProtocolMessage' }
responses:
'200': { description: SSE stream of the turn (Responses wire events) }
'400': { $ref: '#/components/responses/InvalidRequest' }
'401': { $ref: '#/components/responses/Unauthorized' }
'404': { $ref: '#/components/responses/UnknownSession' }
'409': { $ref: '#/components/responses/NoActiveSession' }
'429': { $ref: '#/components/responses/SessionBusy' }
/api/sessions:
get:
tags: [Sessions]
summary: Full two-level session catalog (aligned with the TUI /resume picker)
description: |
Every project and every session on disk, not only open ones. Rows carry
active:true for the current TUI session and headless_open:true for
sessions routable right now without an open round-trip. Each project's
sessions are paged to its most recent per_project rows (session_count
keeps the total); grow the page with a larger per_project.
parameters:
- name: per_project
in: query
required: false
schema: { type: string }
description: Rows per project (1..1000); "all" serves every row. Defaults to 5.
responses:
'200':
description: Two-level project→session listing (flat fallback when no catalog is wired)
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/SessionCatalog'
- $ref: '#/components/schemas/FlatSessionList'
'401': { $ref: '#/components/responses/Unauthorized' }
/api/sessions/open:
post:
tags: [Sessions]
summary: Open (or resume) one parallel headless session
description: |
Mints a session when session_id is absent; reuses an open one; resumes
message-level from the on-disk transcript when the id exists on disk.
project_path defaults to the process project (cross-project support).
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
session_id:
type: string
maxLength: 256
project_path:
type: string
description: Defaults to the process project; any existing directory for a cross-project session
responses:
'200':
description: The opened session
content:
application/json:
schema: { $ref: '#/components/schemas/OpenedSession' }
'400': { $ref: '#/components/responses/InvalidRequest' }
'401': { $ref: '#/components/responses/Unauthorized' }
'429': { $ref: '#/components/responses/SessionBusy' }
/api/sessions/close:
post:
tags: [Sessions]
summary: Close one headless session
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [session_id]
properties:
session_id: { type: string }
responses:
'200':
description: Closure result
content:
application/json:
schema:
type: object
properties:
closed: { type: boolean }
'400': { $ref: '#/components/responses/InvalidRequest' }
'401': { $ref: '#/components/responses/Unauthorized' }
'404': { $ref: '#/components/responses/UnknownSession' }
/api/sessions/{sessionId}/messages:
get:
tags: [Sessions]
summary: Message snapshot for one session
description: |
Snapshot-first: the authoritative current message list. A reconnecting
client pulls this once and then follows SSE increments — snapshot
replay over HTTP. The assistant-message shape uses content[] with
typed tool_call entries; a tool_use block pairs with its later
tool_result block by tool use id into the entry's status/result/ready
fields (pending when the result has not arrived). Open headless
sessions serve live in-memory messages; other known session ids
serve their on-disk transcript.
parameters:
- name: sessionId
in: path
required: true
schema: { type: string }
responses:
'200':
description: Message snapshot
content:
application/json:
schema: { $ref: '#/components/schemas/MessageSnapshot' }
'401': { $ref: '#/components/responses/Unauthorized' }
'404': { $ref: '#/components/responses/UnknownSession' }
/api/sessions/{sessionId}/rename:
post:
tags: [Sessions]
summary: Rename a session in place
description: |
Appends a custom-title JSONL event; confirming an unchanged title is
deliberately allowed. Mirrors the upstream row menu's Rename action.
parameters:
- name: sessionId
in: path
required: true
schema: { type: string }
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [title]
properties:
title: { type: string }
responses:
'200':
description: Rename result
content:
application/json:
schema:
type: object
properties:
session_id: { type: string }
custom_title: { type: string }
'400': { $ref: '#/components/responses/InvalidRequest' }
'401': { $ref: '#/components/responses/Unauthorized' }
'404': { $ref: '#/components/responses/UnknownSession' }
'500': { $ref: '#/components/responses/SessionOperationFailed' }
/api/sessions/{sessionId}/fork:
post:
tags: [Sessions]
summary: Fork a session at its last completed turn
description: |
Copies the source transcript up to its last completed turn into a new
session id. Mirrors the upstream row menu's Fork session action.
parameters:
- name: sessionId
in: path
required: true
schema: { type: string }
requestBody:
required: false
content:
application/json:
schema:
type: object
properties:
title: { type: string }
responses:
'200':
description: The forked session's id
content:
application/json:
schema:
type: object
properties:
session_id: { type: string }
'400': { $ref: '#/components/responses/InvalidRequest' }
'401': { $ref: '#/components/responses/Unauthorized' }
'404': { $ref: '#/components/responses/UnknownSession' }
'500': { $ref: '#/components/responses/SessionOperationFailed' }
/api/sessions/{sessionId}/archive:
post:
tags: [Sessions]
summary: Hide a session from the default catalog listing
description: |
Appends a one-way archived JSONL event; the transcript itself is
untouched. Archived sessions are filtered out of every grouping
surface (webui and the TUI /resume picker share the same catalog).
No unarchive endpoint exists in this pass.
parameters:
- name: sessionId
in: path
required: true
schema: { type: string }
responses:
'200':
description: Archive result
content:
application/json:
schema:
type: object
properties:
session_id: { type: string }
archived: { type: boolean }
'400': { $ref: '#/components/responses/InvalidRequest' }
'401': { $ref: '#/components/responses/Unauthorized' }
'404': { $ref: '#/components/responses/UnknownSession' }
'500': { $ref: '#/components/responses/SessionOperationFailed' }
/api/sessions/{sessionId}:
delete:
tags: [Sessions]
summary: Permanently delete a session
description: |
Deletes the session's transcript and sidecar directory from disk.
Product-scope extension with no upstream counterpart — reuses the
Java /resume picker's permanent-deletion capability.
An id no session answers to is 404, not an error: two clients on the
same catalog listing race, and the loser deleting an already-deleted
row got the outcome it asked for. 500 is reserved for a session that
resolved and could not be deleted.
parameters:
- name: sessionId
in: path
required: true
schema: { type: string }
responses:
'200':
description: Delete result
content:
application/json:
schema:
type: object
properties:
session_id: { type: string }
deleted: { type: boolean }
'400': { $ref: '#/components/responses/InvalidRequest' }
'401': { $ref: '#/components/responses/Unauthorized' }
'404': { $ref: '#/components/responses/UnknownSession' }
'500': { $ref: '#/components/responses/SessionOperationFailed' }
/api/events:
get:
tags: [Sessions]
summary: SSE mirror stream of every followed session
description: |
Server-sent events for the active TUI session plus every open headless
session. Every frame's data JSON carries session_id. Reconnect with
Last-Event-ID to replay the bounded ring; ?session_id= narrows to one
conversation view. The turn.completed frame's data carries elapsed_ms
(turn wall time), ttft_ms (time to first stream output; absent when
the turn produced none), time (epoch ms), and turn + turn_usage (the
durable-fold delta; the usage body's model is the turn's last-reported
model id).
parameters:
- name: session_id
in: query
required: false
schema: { type: string }
description: Only frames whose session_id matches
- name: Last-Event-ID
in: header
required: false
schema: { type: string }
description: Replay every journaled frame after this id
- name: token
in: query
required: false
schema: { type: string }
description: Alternative to the Authorization header
responses:
'200':
description: text/event-stream of mirror frames
content:
text/event-stream:
schema: { $ref: '#/components/schemas/MirrorFrame' }
'401': { $ref: '#/components/responses/Unauthorized' }
/api/permissions/respond:
post:
tags: [Permissions]
summary: Answer one pending permission ask or user question
description: |
A tool waiting at ASK blocks inside the shared interaction
coordinator; the TUI dialog and a web client are two observers of the
same ask — first answer wins. The request_id comes from the matching
permission.asked frame. For AskUserQuestion asks, the chosen answers
go back through updated_input (the rewritten tool input); feedback
carries an optional deny reason or allow instruction.
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [request_id, session_id, allowed]
properties:
request_id:
type: string
description: The id from the matching permission.asked frame
session_id: { type: string }
allowed:
type: boolean
description: true = execute, false = cancel
feedback:
type: string
description: Optional deny reason or allow instruction
updated_input:
type: object
description: AskUserQuestion answers as the rewritten tool input
skip:
type: boolean
description: Skip this tool call (denies with a skip-marked message)
responses:
'200':
description: The ask was answered by this request
content:
application/json:
schema:
type: object
properties:
responded: { type: boolean }
'400': { $ref: '#/components/responses/InvalidRequest' }
'401': { $ref: '#/components/responses/Unauthorized' }
'409':
description: The ask was already answered by another observer
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
/api/settings:
get:
tags: [Settings]
summary: Effective settings snapshot with per-tier source attribution
description: |
Merges every settings tier (user -> project -> local -> flag -> policy,
later tiers overriding earlier) into one effective object, alongside
the raw per-tier settings for whichever tiers are actually present on
disk right now.
responses:
'200':
description: The effective snapshot
content:
application/json:
schema: { $ref: '#/components/schemas/SettingsSnapshot' }
'401': { $ref: '#/components/responses/Unauthorized' }
post:
tags: [Settings]
summary: Apply one settings mutation, dispatched by the op field
description: |
Every successful mutation responds with the refreshed effective
snapshot (same shape as GET), so the web client never has to
re-fetch. tier is one of user|project|local; behavior is one of
allow|deny|ask.
requestBody:
required: true
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/UserValueOp'
- $ref: '#/components/schemas/PermissionModeOp'
- $ref: '#/components/schemas/PermissionRulesOp'
- $ref: '#/components/schemas/DirectoriesOp'
responses:
'200':
description: The refreshed effective snapshot
content:
application/json:
schema: { $ref: '#/components/schemas/SettingsSnapshot' }
'400': { $ref: '#/components/responses/InvalidRequest' }
'401': { $ref: '#/components/responses/Unauthorized' }
/api/schedule:
get:
tags: [Schedule]
summary: List every scheduled (cron) task known to this process
responses:
'200':
description: The task list
content:
application/json:
schema: { $ref: '#/components/schemas/ScheduleList' }
'401': { $ref: '#/components/responses/Unauthorized' }
post:
tags: [Schedule]
summary: Create one scheduled task
requestBody:
required: true
content:
application/json:
schema: { $ref: '#/components/schemas/ScheduleCreateRequest' }
responses:
'200':
description: The generated task id
content:
application/json:
schema:
type: object
properties:
id: { type: string }
'400': { $ref: '#/components/responses/InvalidRequest' }
'401': { $ref: '#/components/responses/Unauthorized' }
/api/schedule/{id}:
delete:
tags: [Schedule]
summary: Remove one scheduled task
parameters:
- name: id
in: path
required: true
schema: { type: string }
responses:
'200':
description: Removed
content:
application/json:
schema:
type: object
properties:
removed: { type: boolean }
'400': { $ref: '#/components/responses/InvalidRequest' }
'401': { $ref: '#/components/responses/Unauthorized' }
'404': { $ref: '#/components/responses/NotFound' }
/api/models:
get:
tags: [Models]
summary: List the custom model catalogue (shared with the /model command)
responses:
'200':
description: The model list
content:
application/json:
schema: { $ref: '#/components/schemas/ModelList' }
'401': { $ref: '#/components/responses/Unauthorized' }
post:
tags: [Models]
summary: Save (add or update) one custom model entry
description: |
api_key is a tri-state field: absent keeps the existing key, null
clears it, a string sets it. api_key is never echoed back by GET.
requestBody:
required: true
content:
application/json:
schema: { $ref: '#/components/schemas/ModelSaveRequest' }
responses:
'200':
description: The refreshed model list
content:
application/json:
schema: { $ref: '#/components/schemas/ModelList' }
'400': { $ref: '#/components/responses/InvalidRequest' }
'401': { $ref: '#/components/responses/Unauthorized' }
/api/commands:
get:
tags: [Commands]
summary: List the composer menu catalogue (slash commands and skills)
description: |
One row per non-hidden interactive command; skills appear here too
because they register as commands. Feeds the webui composer's "+"
menu, mirroring dsh's host command catalog listing.
responses:
'200':
description: The command list
content:
application/json:
schema: { $ref: '#/components/schemas/CommandList' }
'401': { $ref: '#/components/responses/Unauthorized' }
/api/session/context:
get:
tags: [Sessions]
summary: One session's model selection, context usage, and session metrics
description: |
Feeds the webui composer's model seat, context meter, and stats
pills (mirroring dsh's remote session model/context surface). The
selection half lists the same /model catalogue the TUI serves
(built-in families, custom models, allowlist-filtered); the context
half reuses the claude-hud status-line token accounting — the
finalized usage anchor's input-token sum over the model-resolved
context window — so the meter and the status line show one number.
The metrics half projects the engine's durable whole-session fold
(the same SessionMetricsTracker fold the TUI status line renders);
raw integers cross the wire and the client owns display formatting.
The addressed session follows the protocol turn runner's routing:
an open headless session id, the active TUI session's own id, or
blank for the active TUI session. Any other known id serves its
on-disk transcript as a read-only target (usage measured, no live
selection — both halves render null without one).
parameters:
- name: session_id
in: query
required: false
schema: { type: string }
description: The session to address; absent means the active TUI session
responses:
'200':
description: Selection, usage, and metrics; each half is null without a live target
content:
application/json:
schema: { $ref: '#/components/schemas/SessionContext' }
'401': { $ref: '#/components/responses/Unauthorized' }
post:
tags: [Sessions]
summary: Change one session's model or reasoning effort
description: |
One selection per request. Both go through the addressed session's
live controllers — the same control path the TUI /model picker and
Session Link endpoints drive for the TUI session, or the open
headless session's own engine — so a web selection and a TUI
selection of the same session stay in lockstep while sibling
sessions keep their own choices. A running turn keeps the model it
started with; the new choice applies to the next prompt assembly.
The refreshed answer carries the session's metrics alongside the
selection and usage, so a selection change never blanks the
stats pills.
requestBody:
required: true
content:
application/json:
schema: { $ref: '#/components/schemas/SessionContextSelectRequest' }
responses:
'200':
description: The refreshed selection, usage, and metrics
content:
application/json:
schema: { $ref: '#/components/schemas/SessionContext' }
'400': { $ref: '#/components/responses/InvalidRequest' }
'401': { $ref: '#/components/responses/Unauthorized' }
/api/session/permission-mode:
get:
tags: [Sessions]
summary: One session's live permission-mode selection
description: |
Feeds the webui composer's permission-mode chip — the remote
counterpart of the TUI Shift+Tab cycle. The addressed session
follows the same routing as /api/session/context: an open headless
session id, the active TUI session's own id, or blank for the
active TUI session. Any other id has no live PermissionGate to
report and renders null.
parameters:
- name: session_id
in: query
required: false
schema: { type: string }
description: The session to address; absent means the active TUI session
responses:
'200':
description: The current mode and selectable modes; null without a live target
content:
application/json:
schema: { $ref: '#/components/schemas/SessionPermissionModeResponse' }
'401': { $ref: '#/components/responses/Unauthorized' }
post:
tags: [Sessions]
summary: Change one session's permission mode
description: |
Applies through the addressed session's live PermissionGate — the
same control path the TUI Shift+Tab cycle and the SDK
set_permission_mode control request drive. bypassPermissions is
rejected (400) when the session was not launched with
--dangerously-skip-permissions or policy disables it.
requestBody:
required: true
content:
application/json:
schema: { $ref: '#/components/schemas/SessionPermissionModeSelectRequest' }
responses:
'200':
description: The refreshed permission-mode state
content:
application/json:
schema: { $ref: '#/components/schemas/SessionPermissionModeResponse' }
'400': { $ref: '#/components/responses/InvalidRequest' }
'401': { $ref: '#/components/responses/Unauthorized' }
/api/session/context/timeline:
get:
tags: [Sessions]
summary: One live session's context-timeline head (dsh-context wire shape)
description: |
The slim head of the gateway's per-session context ledger — the
current heuristic composition, the retained-window counts, the
newest request's billing anchor, cost/timing totals, and the
`detailRev` cursor an open Context tab refetches the detail on.
Emits the camelCase `ContextTimeline` structure of dsh-context's
`shared/types.ts` (an intentional exception to this API's
snake_case convention, so the vendored webui helpers consume it
unchanged; see webui/UPSTREAM.md). Only live sessions (the active
TUI session and open headless sessions) own a ledger — any other id
answers `timeline: null`.
parameters:
- $ref: '#/components/parameters/ContextSessionId'
responses:
'200':
description: The head, or null for a cold session
content:
application/json:
schema:
type: object
properties:
timeline:
allOf: [ { $ref: '#/components/schemas/ContextTimelineHead' } ]
nullable: true
'401': { $ref: '#/components/responses/Unauthorized' }
/api/session/context/detail:
get:
tags: [Sessions]
summary: One live session's context-timeline detail collections
description: |
The heavy collections behind the head: per-request records, context
events, the served surface window, the removed-node archive with
`gone` stamps, the file-operation log, the request-header epoch
metadata, and this product's `agents[]` extension (the session's
Task/Agent tool calls). `rev` mirrors the head's `detailRev` at the
same fold cut (latest-wins cursor). Shape: dsh-context
`ContextTimelineDetail` plus `headers` (`ContextHeaders`) and
`agents`.
parameters:
- $ref: '#/components/parameters/ContextSessionId'
responses:
'200':
description: The detail payload, or null for a cold session
content:
application/json:
schema:
type: object
properties:
detail:
allOf: [ { $ref: '#/components/schemas/ContextTimelineDetail' } ]
nullable: true
'401': { $ref: '#/components/responses/Unauthorized' }
/api/session/context/content:
get:
tags: [Sessions]
summary: One surface node's stored content, the system prompt, or one tool definition
description: |
On-demand content the timeline wire deliberately omits: a node's
bounded text by `seq`, the live system prompt (`kind=system`, joined
and as assembler parts), one tool's description and JSON schema
(`kind=tool&name=`), or every tool definition at once (`kind=tools`,
the browser's header epoch). Bounded like the mirror's result excerpts
(20k chars, truncation marker).
parameters:
- $ref: '#/components/parameters/ContextSessionId'
- name: seq
in: query
required: false
schema: { type: integer }
description: The surface node's fold sequence number
- name: kind
in: query
required: false
schema: { type: string, enum: [system, tool, tools] }
description: Header content instead of a node
- name: name
in: query
required: false
schema: { type: string }
description: The tool name for kind=tool
responses:
'200':
description: The content
content:
application/json:
schema:
type: object
properties:
content: { type: object, additionalProperties: true }
'400': { $ref: '#/components/responses/InvalidRequest' }
'401': { $ref: '#/components/responses/Unauthorized' }
'404': { $ref: '#/components/responses/NotFound' }
/api/session/context/overview:
get:
tags: [Sessions]
summary: Every live session's context head and daily activity ledger
description: |
The Context Dashboard's aggregate: one row per live session (the
active TUI session and every open headless session) with its
timeline head, per-local-day activity ledger (dsh-context
`ContextActivity`), run state, and title/cwd. Transcript-only
sessions are never listed.
responses:
'200':
description: The live sessions' heads and activity
content:
application/json:
schema: { $ref: '#/components/schemas/ContextOverview' }
'401': { $ref: '#/components/responses/Unauthorized' }
/api/models/{name}:
delete:
tags: [Models]
summary: Remove one custom model entry
parameters:
- name: name
in: path
required: true
schema: { type: string }
responses:
'200':
description: Removed
content:
application/json:
schema:
type: object
properties:
removed: { type: boolean }
'400': { $ref: '#/components/responses/InvalidRequest' }
'401': { $ref: '#/components/responses/Unauthorized' }
'404': { $ref: '#/components/responses/NotFound' }
components:
securitySchemes:
bearerToken:
type: http
scheme: bearer
description: The launch token printed by the /web command
queryToken:
type: apiKey
in: query
name: token
schemas:
Error:
type: object
required: [error]
properties:
error:
type: object
required: [type, message]
properties:
type:
type: string
description: |
invalid_request (400: malformed JSON, missing session_id, over
length), authentication_required (401), not_found (404: unknown
route or session), already_responded (409: an ask another
observer settled, or a submission with no session_id and no
active session), api_error (429: a turn already in flight on
this session, or the headless session limit).
message: { type: string }
ProtocolMessage:
type: object
required: [role, content]
properties:
role: { type: string, enum: [user, assistant] }
content:
oneOf:
- type: string
- type: array
items:
type: object
properties:
type: { type: string, enum: [text, image, document] }
text: { type: string }
title:
type: string
description: Document display name; becomes the persisted file name
source:
type: object
required: [type, media_type, data]
properties:
type: { type: string, enum: [base64] }
media_type: { type: string }
data:
type: string
description: base64 payload; images become inline picture blocks, documents are persisted under the project and referenced by path
SessionCatalog:
type: object
properties:
projects:
type: array
items:
type: object
properties:
project_path: { type: string }
project_name: { type: string }
session_count: { type: integer, description: Total sessions in the project (sessions may be a paged subset) }
sessions:
type: array
items: { $ref: '#/components/schemas/SessionRow' }
FlatSessionList:
type: object
properties:
sessions:
type: array
items: { $ref: '#/components/schemas/SessionRow' }
SessionRow:
type: object
properties:
id: { type: string }
summary: { type: string }
message_count: { type: integer }
modified_at: { type: string, format: date-time }
git_branch: { type: string }
cwd: { type: string }
custom_title: { type: string }
first_prompt: { type: string }
active:
type: boolean
description: True for the current TUI session
headless_open:
type: boolean
description: True when routable right now via metadata.session_id without an open round-trip
OpenedSession:
type: object
properties:
session_id: { type: string }
project_path: { type: string }
resumed:
type: boolean
description: True when the session was restored from the on-disk transcript
headless:
type: boolean
description: Always true for gateway-opened sessions
MessageSnapshot:
type: object
description: The authoritative current message list of one session (snapshot-first)
properties:
session_id: { type: string }
messages:
type: array
description: User text rows and assistant content[] rows, transcript order; both kinds stamp `time` (epoch ms) for their clock labels
items: { $ref: '#/components/schemas/AssistantMessageSnapshot' }
AssistantMessageSnapshot:
type: object
description: Assistant-message snapshot shape
properties:
id: { type: string }
request_id: { type: string }
conversation_id: { type: string }
complete: { type: boolean }
time:
type: integer
description: Durable transcript timestamp as epoch ms — the turn-tail clock label fact; absent on synthetic rows
turn:
type: integer
description: |
1-based turn number this assistant row answers (a human prompt
opens a turn). Absent on rows predating the turn annotation.
turn_usage:
allOf: [ { $ref: '#/components/schemas/TurnUsage' } ]
description: This row's provider-reported token buckets; absent when the row carries no usage
content:
type: array
items: { $ref: '#/components/schemas/MessageContentBlock' }
text:
type: string
description: A user row's text, when it carries any (this schema also serves the user-row shape)
images:
type: array
items: { $ref: '#/components/schemas/MessageImageAttachment' }
description: Inline image attachments on a user row; absent when none
MessageImageAttachment:
type: object
required: [media_type, data]
description: One inline image, the same shape the client submits attachments in
properties:
media_type: { type: string, description: 'e.g. image/png, image/jpeg' }
data: { type: string, description: Base64-encoded image bytes }
TurnUsage:
type: object
description: |
Per-turn provider token buckets, raw integers. On the snapshot path
the row's own usage buckets; on the live turn.completed frame the
durable-fold delta between the turn's start baseline and the fold
after endTurn (so every step of the turn is counted exactly once).
Display formatting is client-side.
required:
- uncached_input_tokens
- output_tokens