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
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
swagger: '2.0'
info:
  title: InfoRadar API
  version: "0.1"
consumes:
  - application/json
produces:
  - application/json

basePath: /api

paths:

  /analyze:
    post:
      tags:
        - all
      summary: analyze text
      operationId: server.analyze
      parameters:
        - in: body
          name: analyze_request
          description: request analyze
          schema:
            $ref: "#/definitions/AnalyzeRequest"

      responses:
        200:
          description: |
            成功时为信息密度分析结果。`stream=false`(默认)时响应体即本 schema;
            `stream=true` 时为 `text/event-stream`,最后一条 `data` 事件内为同形 JSON。
            业务错误(4xx/5xx)时响应体含 `success`/`message` 等,见各状态码说明,非本 schema。
          schema:
            $ref: "#/definitions/AnalyzeResponse"
        400:
          description: invalid request payload (missing text or model)
        404:
          description: requested model is not registered
        500:
          description: model inference failed
        503:
          description: requested model could not be loaded

  /list_demos:
    get:
      tags:
        - all
      summary: list all available demo files and folders
      operationId: server.list_demos
      parameters:
        - in: query
          name: path
          type: string
          required: false
          description: path to list (empty string for root)
      responses:
        200:
          description: return list of demo files and folders
          schema:
            type: object
            properties:
              path:
                type: string
                description: current path
              items:
                type: array
                items:
                  type: object
                  properties:
                    type:
                      type: string
                      enum: [folder, file]
                      description: item type
                    name:
                      type: string
                      description: item name
                    path:
                      type: string
                      description: full path
                    file:
                      type: string
                      description: relative file path (only for files)

  /save_demo:
    post:
      tags:
        - all
      summary: save demo file
      operationId: server.save_demo
      parameters:
        - in: body
          name: save_request
          description: request to save demo
          schema:
            type: object
            properties:
              name:
                type: string
                description: demo name (will be used as filename)
              data:
                type: object
                description: AnalyzeResponse data to save
              path:
                type: string
                description: "target folder path (default: \"/\" for root directory)"
                default: "/"
            required:
              - name
              - data
      responses:
        200:
          description: return save result
          schema:
            type: object
            properties:
              success:
                type: boolean
              message:
                type: string
              file:
                type: string
                description: saved filename

  /delete_demo:
    post:
      tags:
        - all
      summary: delete demo file
      operationId: server.delete_demo
      parameters:
        - in: body
          name: delete_request
          description: request to delete demo
          schema:
            type: object
            properties:
              file:
                type: string
                description: demo filename (with .json extension)
            required:
              - file
      responses:
        200:
          description: return delete result
          schema:
            type: object
            properties:
              success:
                type: boolean
              message:
                type: string

  /move_demo:
    post:
      tags:
        - all
      summary: move demo file or folder
      operationId: server.move_demo
      parameters:
        - in: body
          name: move_request
          description: request to move demo or folder
          schema:
            type: object
            properties:
              file:
                type: string
                description: file path (for moving files)
              path:
                type: string
                description: folder path (for moving folders)
              target_path:
                type: string
                description: target folder path (empty string for root)
            required:
              - target_path
      responses:
        200:
          description: return move result
          schema:
            type: object
            properties:
              success:
                type: boolean
              message:
                type: string

  /rename_demo:
    post:
      tags:
        - all
      summary: rename demo file
      operationId: server.rename_demo
      parameters:
        - in: body
          name: rename_request
          description: request to rename demo file
          schema:
            type: object
            properties:
              file:
                type: string
                description: file path
              new_name:
                type: string
                description: new name (without extension)
            required:
              - file
              - new_name
      responses:
        200:
          description: return rename result
          schema:
            type: object
            properties:
              success:
                type: boolean
              message:
                type: string

  /rename_folder:
    post:
      tags:
        - all
      summary: rename folder
      operationId: server.rename_folder
      parameters:
        - in: body
          name: rename_request
          description: request to rename folder
          schema:
            type: object
            properties:
              path:
                type: string
                description: folder path
              new_name:
                type: string
                description: new folder name
            required:
              - path
              - new_name
      responses:
        200:
          description: return rename result
          schema:
            type: object
            properties:
              success:
                type: boolean
              message:
                type: string

  /delete_folder:
    post:
      tags:
        - all
      summary: delete folder
      operationId: server.delete_folder
      parameters:
        - in: body
          name: delete_request
          description: request to delete folder
          schema:
            type: object
            properties:
              path:
                type: string
                description: folder path
            required:
              - path
      responses:
        200:
          description: return delete result
          schema:
            type: object
            properties:
              success:
                type: boolean
              message:
                type: string

  /list_all_folders:
    get:
      tags:
        - all
      summary: list all folders for move operation
      operationId: server.list_all_folders
      responses:
        200:
          description: return list of all folders
          schema:
            type: object
            properties:
              folders:
                type: array
                items:
                  type: string
                description: list of folder paths

  /create_folder:
    post:
      tags:
        - all
      summary: create a new folder
      operationId: server.create_folder_api
      parameters:
        - in: body
          name: create_request
          description: request to create folder
          schema:
            type: object
            properties:
              parent_path:
                type: string
                description: 'parent folder path (default: "/" for root directory)'
                default: "/"
              folder_name:
                type: string
                description: new folder name
            required:
              - folder_name
      responses:
        200:
          description: return create result
          schema:
            type: object
            properties:
              success:
                type: boolean
              message:
                type: string

  /fetch_url:
    post:
      tags:
        - all
      summary: fetch text content from URL
      operationId: server.fetch_url
      parameters:
        - in: body
          name: fetch_request
          description: request to fetch text from URL
          schema:
            type: object
            properties:
              url:
                type: string
                description: URL to fetch text from
            required:
              - url
      responses:
        200:
          description: return fetched text content
          schema:
            type: object
            properties:
              success:
                type: boolean
              text:
                type: string
                description: extracted text content
              url:
                type: string
                description: original URL
              char_count:
                type: integer
                description: character count of extracted text
              message:
                type: string
                description: error message if success is false
        400:
          description: invalid request (missing url or invalid URL format)
        500:
          description: failed to fetch or extract text from URL

  /client-activity:
    post:
      tags:
        - all
      summary: anonymous client activity heartbeat
      operationId: server.client_activity_report
      parameters:
        - in: body
          name: activity_body
          required: false
          schema:
            type: object
            properties:
              page_path:
                type: string
                description: pathname+search;汇总按去掉 ?/# 的路径末段,逐条日志里 path 仍带 query(unquote)
              total_active_sec:
                type: integer
              delta_active_sec:
                type: integer
              client_os:
                type: string
                description: 首轮心跳附带;ios / android / windows / macos / linux / unknown
      responses:
        200:
          description: acknowledged
          schema:
            type: object
            properties:
              ok:
                type: boolean

  /check_admin:
    post:
      tags:
        - all
      summary: check admin token
      operationId: server.check_admin
      parameters:
        - in: body
          name: check_request
          description: request to check admin token
          schema:
            type: object
            properties:
              token:
                type: string
                description: admin token to check
            required:
              - token
      responses:
        200:
          description: return check result
          schema:
            type: object
            properties:
              success:
                type: boolean
              message:
                type: string

  /available_models:
    get:
      tags:
        - all
      summary: get available models
      operationId: server.get_available_models
      responses:
        200:
          description: return list of available models
          schema:
            type: object
            properties:
              success:
                type: boolean
              models:
                type: array
                items:
                  type: string

  /current_model:
    get:
      tags:
        - all
      summary: get current model
      operationId: server.get_current_model
      responses:
        200:
          description: return current model name and quantization config
          schema:
            type: object
            properties:
              success:
                type: boolean
              model:
                type: string
              switching:
                type: boolean
              device_type:
                type: string
                enum: [cpu, cuda, mps]
                description: current device type
              use_int8:
                type: boolean
                description: whether INT8 quantization is enabled
              use_bfloat16:
                type: boolean
                description: whether bfloat16 is enabled (CPU only)

  /prediction-attribute:
    post:
      tags:
        - all
      summary: prediction attribute
      operationId: server.prediction_attribute
      parameters:
        - in: body
          name: attribution_request
          schema:
            type: object
            properties:
              context:
                type: string
                description: 输入上下文文本(不做 trim;token 数不得超过 2000,否则 400
              target_prediction:
                type: string
                description: 目标预测文本,取首个 token 作为归因目标(不做 trim)。省略时自动使用 top-1(贪心解码)。
              model:
                type: string
                enum: [base, instruct]
                description: base 使用主槽位(--model),instruct 使用语义槽位(--semantic_model)
              source_page:
                type: string
                description: 发起页面名(analysis.html / chat.html / attribution.html / gen_attribute.html)
              flow_id:
                type: string
                description: 连续生成归因会话 ID;仅 source_page=gen_attribute.html 时允许
              flow_step:
                type: integer
                description: 连续生成归因步骤(从 0 开始);仅 source_page=gen_attribute.html 时允许
            required:
              - context
              - model
              - source_page
      responses:
        200:
          description: 返回各输入 token 对目标预测的归因分
          schema:
            type: object
            properties:
              success:
                type: boolean
              model:
                type: string
              target_token:
                type: string
                description: 归因目标 token 的字符串
              target_prob:
                type: number
                description:  token  next-token 分布中的预测概率
              token_attribution:
                type: array
                items:
                  type: object
                  properties:
                    offset:
                      type: array
                      items:
                        type: integer
                      description: 字符偏移 [start, end]
                    raw:
                      type: string
                      description: token 原文
                    score:
                      type: number
                      description: 梯度 L2 范数归因分
              debug_info:
                type: object
                description: 下一 token  top10 与概率(与语义分析 debug_info 同形,无 abbrev)
                properties:
                  topk_tokens:
                    type: array
                    items:
                      type: string
                  topk_probs:
                    type: array
                    items:
                      type: number
              is_eos:
                type: boolean
                description: target_token 是否为模型的 EOS token(top-1 模式下尤为重要,客户端据此判断是否终止生成循环)
        400:
          description: 缺少必要字段、model 非法、context 超长、或 target 无法 tokenize
        500:
          description: 推理失败
        503:
          description: 服务繁忙

  /tokenize:
    post:
      tags:
        - all
      summary: tokenize text
      description: |
        对 context 用指定 model 的 tokenizer 分词,返回各 token 的字符 offset 与原文。
        不持有推理锁,不做前向 / 梯度计算,响应极快。
      operationId: server.tokenize
      parameters:
        - in: body
          name: tokenize_request
          required: true
          schema:
            type: object
            required:
              - context
              - model
            properties:
              context:
                type: string
                description: 待分词文本
              model:
                type: string
                enum: [base, instruct]
                description: base 使用主槽位 tokenizer,instruct 使用语义槽位 tokenizer
      responses:
        200:
          description: 分词结果
          schema:
            type: object
            properties:
              success:
                type: boolean
              spans:
                type: array
                items:
                  type: object
                  properties:
                    offset:
                      type: array
                      items:
                        type: integer
                      description: 字符偏移 [start, end]
                    raw:
                      type: string
                      description: token 原文
        400:
          description: 缺少必要字段或 model 非法

  /analyze-semantic:
    post:
      tags:
        - all
      summary: analyze semantic (token-level relevance to query)
      operationId: server.analyze_semantic
      parameters:
        - in: body
          name: semantic_request
          schema:
            type: object
            properties:
              query:
                type: string
                description: 查询主题
              text:
                type: string
                description: 原文
              stream:
                type: boolean
                description: 是否使用 SSE 流式响应(带阶段级进度)
              submode:
                type: string
                enum: [count, match_score, fill_blank]
                description: 可选子模式,不传则用服务端默认。match_score 已废弃
              debug_info:
                type: boolean
                description:  true 时响应包含 debug_info(abbrev、topk_tokens、topk_probs),默认关,不传则不返回
            required:
              - query
              - text
      responses:
        200:
          description: 返回 model  token_attention
          schema:
            type: object
            properties:
              success:
                type: boolean
              model:
                type: string
                description: 使用的 semantic 模型名
              token_attention:
                type: array
                items:
                  type: object
                  properties:
                    offset:
                      type: array
                      items:
                        type: integer
                      description: 原文中的字符偏移 [start, end]
                    raw:
                      type: string
                      description: token 原文
                    score:
                      type: number
                      description:  prompt 区域的平均关注度
              debug_info:
                type: object
                description: 请求中 debug_info=true 时返回
                properties:
                  abbrev:
                    type: string
                    description: 推理原文缩写
                  topk_tokens:
                    type: array
                    items:
                      type: string
                    description: top10 预测 token 列表
                  topk_probs:
                    type: array
                    items:
                      type: number
                    description: top10 对应的概率
              message:
                type: string
        400:
          description: 缺少 query  text 参数
        500:
          description: 分析失败

  /switch_model:
    post:
      tags:
        - all
      summary: switch model (admin only)
      operationId: server.switch_model
      parameters:
        - in: body
          name: switch_request
          description: request to switch model with quantization options
          schema:
            type: object
            properties:
              model:
                type: string
                description: target model name
              use_int8:
                type: boolean
                description: enable INT8 quantization (not supported on MPS)
                default: false
              use_bfloat16:
                type: boolean
                description: enable bfloat16 (CPU only)
                default: false
            required:
              - model
      responses:
        200:
          description: return switch result
          schema:
            type: object
            properties:
              success:
                type: boolean
              message:
                type: string
              model:
                type: string
        400:
          description: invalid request or incompatible quantization settings
        404:
          description: model not found
        500:
          description: model switch failed
        503:
          description: model switching in progress

  /v1/completions/prompt:
    post:
      tags:
        - openai
      summary: Apply chat template to user text (completion prompt assembly)
      description: |
        将 prompt 作为单条 user 经 tokenizer.apply_chat_template 封装,返回实际送入 POST /v1/completions 的完整字符串(JSON 字段 prompt_used)。
        可选 system 字段:省略时仅拼装 user;传入时原样作为 system 段(含空字符串)。
        与续写共用 semantic 模型/tokenizer;过长时返回 400。
      operationId: server.completions_prompt
      parameters:
        - in: body
          name: completions_prompt_request
          required: true
          schema:
            $ref: "server_openai_definitions.yaml#/definitions/OpenAICompletionsPromptRequest"
      responses:
        200:
          description: ok
          schema:
            $ref: "server_openai_definitions.yaml#/definitions/OpenAICompletionsPromptResponse"
        400:
          description: invalid body or prompt too long

  /v1/completions:
    post:
      tags:
        - openai
      summary: OpenAI-compatible text completion (minimal v1)
      description: |
        与 OpenAI POST /v1/completions 对齐(见 platform.openai.com Completions)。
        必填 model、prompt;prompt 须为已确定的完整模型输入(需 chat template 时请先 POST /v1/completions/prompt)。
        本接口响应恒为 text/event-stream(忽略 body 中的 stream 字段):type=delta…,末条 type=result,其 data 与 OpenAICompletionsResponse 同形(含 choices[0].text、info_radar.bpe_strings);若需「非流式」语义,由客户端消费 SSE 末条 result 即可。
      operationId: server.completions
      parameters:
        - in: body
          name: completions_request
          required: true
          schema:
            $ref: "server_openai_definitions.yaml#/definitions/OpenAICompletionsRequest"
      responses:
        200:
          description: |
            text/event-stream(SSE);末条事件的 data 与 OpenAICompletionsResponse 同形。
          schema:
            $ref: "server_openai_definitions.yaml#/definitions/OpenAICompletionsResponse"
        400:
          description: invalid request body

  /v1/completions/stop:
    post:
      tags:
        - openai
      summary: Global completions stop (single-user serial)
      description: |
        置位全局停止标志,使当前正在进行的续写尽快结束(与单次 SSE 断开/GeneratorExit 叠加)。
        单用户串行场景下无需 request_id;新一次 POST /v1/completions 开始时清除该标志。
      operationId: server.completions_stop
      responses:
        200:
          description: ok
          schema:
            type: object
            properties:
              ok:
                type: boolean


  /visit_stats:
    get:
      tags:
        - all
      summary: get visit statistics (admin only)
      operationId: server.get_visit_stats
      responses:
        200:
          description: |
            返回当前累计快照(_base + 本进程内存增量)。
            窗口内未提交的增量仅以与 stats_total.json 相同字段结构的记录写入 Dataset 的 stats_delta/*.json。
          schema:
            type: object
            properties:
              success:
                type: boolean
              totals:
                type: object
                description: |
                  page_loads(GET /client/*.html,一次实际 HTML 响应计一次,与访问日志「📄 页面访问」一致);active_visits(至少有一次有效活跃心跳的页面访问数,每页以 delta_active_sec == total_active_sec 的首轮上报计一次)。
              os:
                type: object
              page_sec:
                type: object
              api:
                type: object
              saved_at:
                type: string
              startup_base:
                type: object
                description: |
                  进程启动时(_load_base 完成后)_base 的深拷贝;前端用 totals − startup_base 计算自启动以来的增量。
              process_start_at:
                type: string
                description: |
                  统计线程完成 _load_base 并拍下 startup_base 时的 UTC 时间(与 saved_at 相同格式)。

definitions:
  # 与 client generatedSchemas TokenWithOffset 一致;信息密度 analyze 与 completions info_radar 共用
  TokenWithOffset:
    type: object
    properties:
      offset:
        type: array
        description: |
          字符下标 [start, end):信息密度分析相对 request.text;
          completions 的 info_radar 相对续写全文 choices[0].text。
        items:
          type: integer
        minItems: 2
        maxItems: 2
      raw:
        type: string
      real_topk:
        type: array
        description: "[模型排序名次, 该 token 的 softmax 概率]"
        items:
          type: number
        minItems: 2
        maxItems: 2
      pred_topk:
        type: array
        description: 该位置 logits softmax 后的 top-N 候选 [token 文本, 概率](N 由服务端 DEFAULT_TOPK 决定)

  # 与 client generatedSchemas AnalyzeResult 一致;成功路径下 backend.api.analyze._build_response
  AnalyzeResult:
    type: object
    required:
      - bpe_strings
    properties:
      model:
        type: string
      bpe_strings:
        type: array
        items:
          $ref: "#/definitions/TokenWithOffset"
      error:
        type: string
        x-nullable: true

  AnalyzeResponse:
    type: object
    required:
      - request
      - result
    properties:
      request:
        type: object
        required:
          - text
        properties:
          text:
            type: string
            description: 与请求中分析的原文一致(响应中仅回显 text)
      result:
        $ref: "#/definitions/AnalyzeResult"

  AnalyzeRequest:
    type: object
    required:
      - model
      - text
    properties:
      model:
        type: string
      text:
        type: string
      stream:
        type: boolean
        description: 是否使用 SSE 流式响应