Repository navigation
Expand file tree
/
Copy pathapi.html
More file actions
649 lines (497 loc) · 61.2 KB
/
Copy pathapi.html
File metadata and controls
649 lines (497 loc) · 61.2 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
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- This file is generated by Nim. -->
<html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en" lang="en" data-theme="auto">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>threecode/api</title>
<!-- Google fonts -->
<link href='https://fonts.googleapis.com/css?family=Lato:400,600,900' rel='stylesheet' type='text/css'/>
<link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
<!-- Favicon -->
<link rel="shortcut icon" href="data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAUAAAAF////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAIAAABbAAAAlQAAAKIAAACbAAAAmwAAAKIAAACVAAAAWwAAAAL///8A////AP///wD///8A////AAAAABQAAADAAAAAYwAAAA3///8A////AP///wD///8AAAAADQAAAGMAAADAAAAAFP///wD///8A////AP///wAAAACdAAAAOv///wD///8A////AP///wD///8A////AP///wD///8AAAAAOgAAAJ3///8A////AP///wAAAAAnAAAAcP///wAAAAAoAAAASv///wD///8A////AP///wAAAABKAAAAKP///wAAAABwAAAAJ////wD///8AAAAAgQAAABwAAACIAAAAkAAAAJMAAACtAAAAFQAAABUAAACtAAAAkwAAAJAAAACIAAAAHAAAAIH///8A////AAAAAKQAAACrAAAAaP///wD///8AAAAARQAAANIAAADSAAAARf///wD///8AAAAAaAAAAKsAAACk////AAAAADMAAACcAAAAnQAAABj///8A////AP///wAAAAAYAAAAGP///wD///8A////AAAAABgAAACdAAAAnAAAADMAAAB1AAAAwwAAAP8AAADpAAAAsQAAAE4AAAAb////AP///wAAAAAbAAAATgAAALEAAADpAAAA/wAAAMMAAAB1AAAAtwAAAOkAAAD/AAAA/wAAAP8AAADvAAAA3gAAAN4AAADeAAAA3gAAAO8AAAD/AAAA/wAAAP8AAADpAAAAtwAAAGUAAAA/AAAA3wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAADfAAAAPwAAAGX///8A////AAAAAEgAAADtAAAAvwAAAL0AAADGAAAA7wAAAO8AAADGAAAAvQAAAL8AAADtAAAASP///wD///8A////AP///wD///8AAAAAO////wD///8A////AAAAAIcAAACH////AP///wD///8AAAAAO////wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A//8AAP//AAD4HwAA7/cAAN/7AAD//wAAoYUAAJ55AACf+QAAh+EAAAAAAADAAwAA4AcAAP5/AAD//wAA//8AAA=="/>
<link rel="icon" type="image/png" sizes="32x32" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4QQQEwksSS9ZWwAAAk1JREFUWMPtll2ITVEUx39nn/O7Y5qR8f05wtCUUr6ZIS++8pEnkZInPImneaCQ5METNdOkeFBKUhMPRIkHKfEuUZSUlGlKPN2TrgfncpvmnntnmlEyq1Z7t89/rf9a6+y99oZxGZf/XeIq61EdtgKXgdXA0xrYAvBjOIF1AI9zvjcC74BSpndrJPkBWDScTF8Aa4E3wDlgHbASaANmVqlcCnwHvgDvgVfAJ+AikAAvgfVZwLnSVZHZaOuKoQi3ZOMi4NkYkpe1p4J7A8BpYAD49hfIy/oqG0+hLomiKP2L5L+1ubn5115S+3OAn4EnwBlgMzCjyt6ZAnQCJ4A7wOs88iRJHvw50HoujuPBoCKwHWiosy8MdfZnAdcHk8dxXFJ3VQbQlCTJvRBCGdRbD4M6uc5glpY3eAihpN5S5w12diSEcCCEcKUO4ljdr15T76ur1FDDLIQQ3qv71EdDOe3Kxj3leRXyk+pxdWnFWod6Wt2bY3de3aSuUHcPBVimHs7mK9WrmeOF6lR1o9qnzskh2ar2qm1qizpfXaPeVGdlmGN5pb09qMxz1Xb1kLqgzn1RyH7JUXW52lr5e/Kqi9qpto7V1atuUzfnARrV7jEib1T76gG2qxdGmXyiekkt1GswPTtek0aBfJp6YySGBfWg2tPQ0FAYgf1stUfdmdcjarbYJEniKIq6gY/Aw+zWHAC+p2labGpqiorFYgGYCEzN7oQdQClN07O1/EfDyGgC0ALMBdYAi4FyK+4H3gLPsxfR1zRNi+NP7nH5J+QntnXe5B5mpfQAAAAASUVORK5CYII=">
<!-- CSS -->
<link rel="stylesheet" type="text/css" href="../nimdoc.out.css?v=2.2.10">
<!-- JS -->
<script type="text/javascript" src="../dochack.js?v=2.2.10"></script>
</head>
<body>
<div class="document" id="documentId">
<input type="checkbox" id="nav-toggle" hidden>
<label for="nav-toggle" id="nav-burger">☰</label>
<label for="nav-toggle" id="nav-overlay"></label>
<div class="container">
<h1 class="title">threecode/api</h1>
<div class="row">
<div class="three columns">
<div class="theme-select-wrapper">
<label for="theme-select">Theme: </label>
<select id="theme-select" onchange="setTheme(this.value)">
<option value="auto">🌗 Match OS</option>
<option value="dark">🌑 Dark</option>
<option value="light">🌕 Light</option>
</select>
</div>
<div id="global-links">
<ul class="simple">
<li><a id="indexLink" href="../theindex.html">Index</a></li>
</ul>
</div>
<div id="searchInputDiv">
Search: <input type="search" id="searchInput" oninput="search()"/>
</div>
<div>
Group by:
<select onchange="groupBy(this.value)">
<option value="section">Section</option>
<option value="type">Type</option>
</select>
</div>
<ul class="simple simple-toc" id="toc-list">
<li>
<a class="reference reference-toplevel" href="#6" id="56">Imports</a>
</li>
<li>
<details open>
<summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
<ul class="simple simple-toc-section">
<li><a class="reference" href="#ApiStreamHooks" title="ApiStreamHooks = object
beforeCall*: proc (lastPromptTokens, window: int): string {.closure.}
afterCall*: proc () {.closure.}
progress*: proc (baseLabel: string; slurped: int) {.closure.}
setStatusLabel*: proc (label: string) {.closure.}
startSpinner*: proc (label: string) {.closure.}
stopSpinner*: proc () {.closure.}
providerActivity*: proc () {.closure.}
reasoningDelta*: proc (reasoning, baseLabel: string; slurped: int;
contentStarted: bool) {.closure.}
contentDelta*: proc (chunk, baseLabel: string; slurped: int): bool {.closure.}
contentFinished*: proc (fullContent, baseLabel: string; slurped: int): bool {.
closure.}
trimTrailingContent*: proc (fullContent, baseLabel: string; slurped: int) {.
closure.}
afterLiveContent*: proc (baseLabel: string; slurped: int) {.closure.}
finalUsage*: proc (usage: Usage; window, elapsed: int;
assistantContent: string; streamedLive: bool) {.closure.}
noUsage*: proc (elapsed: int) {.closure.}">ApiStreamHooks</a></li>
<li><a class="reference" href="#FetchModelsHook" title="FetchModelsHook = proc (url, key: string): (seq[string], string) {.closure.}">FetchModelsHook</a></li>
<li><a class="reference" href="#VerifyProfileHook" title="VerifyProfileHook = proc (p: Profile): (bool, string) {.closure.}">VerifyProfileHook</a></li>
</ul>
</details>
</li>
<li>
<details open>
<summary><a class="reference reference-toplevel" href="#8" id="58">Vars</a></summary>
<ul class="simple simple-toc-section">
<li><a class="reference" href="#apiStreamHooks_2" title="apiStreamHooks: ApiStreamHooks">apiStreamHooks</a></li>
<li><a class="reference" href="#fetchModelsHook_2" title="fetchModelsHook: FetchModelsHook">fetchModelsHook</a></li>
<li><a class="reference" href="#verifyProfileHook_2" title="verifyProfileHook: VerifyProfileHook">verifyProfileHook</a></li>
</ul>
</details>
</li>
<li>
<details open>
<summary><a class="reference reference-toplevel" href="#10" id="60">Consts</a></summary>
<ul class="simple simple-toc-section">
<li><a class="reference" href="#QuietRecvWakeMs" title="QuietRecvWakeMs {.intdefine.} = 500">QuietRecvWakeMs</a></li>
<li><a class="reference" href="#QuietTooLongMs" title="QuietTooLongMs {.intdefine.} = 180000">QuietTooLongMs</a></li>
</ul>
</details>
</li>
<li>
<details open>
<summary><a class="reference reference-toplevel" href="#12" id="62">Procs</a></summary>
<ul class="simple simple-toc-section">
<ul class="simple nested-toc-section">applyGenerationDefaults
<li><a class="reference" href="#applyGenerationDefaults%2CProfile%2CJsonNode" title="applyGenerationDefaults(p: Profile; body: JsonNode)">applyGenerationDefaults(p: Profile; body: JsonNode)</a></li>
</ul>
<ul class="simple nested-toc-section">applyReasoning
<li><a class="reference" href="#applyReasoning%2CProfile%2CJsonNode" title="applyReasoning(p: Profile; body: JsonNode)">applyReasoning(p: Profile; body: JsonNode)</a></li>
</ul>
<ul class="simple nested-toc-section">applyStreamingOptions
<li><a class="reference" href="#applyStreamingOptions%2CProfile%2CJsonNode" title="applyStreamingOptions(p: Profile; body: JsonNode)">applyStreamingOptions(p: Profile; body: JsonNode)</a></li>
</ul>
<ul class="simple nested-toc-section">buildBatchAssistantMsg
<li><a class="reference" href="#buildBatchAssistantMsg%2Cstring%2Cstring%2CJsonNode" title="buildBatchAssistantMsg(message, reasoning: string; toolCalls: JsonNode): JsonNode">buildBatchAssistantMsg(message, reasoning: string; toolCalls: JsonNode): JsonNode</a></li>
</ul>
<ul class="simple nested-toc-section">buildStreamAssistantMsg
<li><a class="reference" href="#buildStreamAssistantMsg%2Cstring%2Cstring%2COrderedTable%5Bint%2CJsonNode%5D%2CUsage" title="buildStreamAssistantMsg(content, reasoning: string;
tools: OrderedTable[int, JsonNode]; usage: Usage;
wasInterrupted = false): JsonNode">buildStreamAssistantMsg(content, reasoning: string;
tools: OrderedTable[int, JsonNode]; usage: Usage;
wasInterrupted = false): JsonNode</a></li>
</ul>
<ul class="simple nested-toc-section">callModel
<li><a class="reference" href="#callModel%2CProfile%2CJsonNode%2CUsage%2Cint" title="callModel(p: Profile; messages: JsonNode; usage: var Usage;
lastPromptTokens: int): JsonNode">callModel(p: Profile; messages: JsonNode; usage: var Usage;
lastPromptTokens: int): JsonNode</a></li>
</ul>
<ul class="simple nested-toc-section">classifyRetry
<li><a class="reference" href="#classifyRetry%2Cref.CatchableError%2Cint" title="classifyRetry(exc: ref CatchableError; code: int): string">classifyRetry(exc: ref CatchableError; code: int): string</a></li>
</ul>
<ul class="simple nested-toc-section">clearInterrupted
<li><a class="reference" href="#clearInterrupted" title="clearInterrupted()">clearInterrupted()</a></li>
</ul>
<ul class="simple nested-toc-section">clearNetworkQuiet
<li><a class="reference" href="#clearNetworkQuiet" title="clearNetworkQuiet()">clearNetworkQuiet()</a></li>
</ul>
<ul class="simple nested-toc-section">closeCachedStreamConn
<li><a class="reference" href="#closeCachedStreamConn" title="closeCachedStreamConn()">closeCachedStreamConn()</a></li>
</ul>
<ul class="simple nested-toc-section">fetchModels
<li><a class="reference" href="#fetchModels%2Cstring%2Cstring" title="fetchModels(url, key: string): (seq[string], string)">fetchModels(url, key: string): (seq[string], string)</a></li>
</ul>
<ul class="simple nested-toc-section">installInterruptHook
<li><a class="reference" href="#installInterruptHook" title="installInterruptHook()">installInterruptHook()</a></li>
</ul>
<ul class="simple nested-toc-section">isInterrupted
<li><a class="reference" href="#isInterrupted" title="isInterrupted(): bool">isInterrupted(): bool</a></li>
</ul>
<ul class="simple nested-toc-section">isNetworkQuiet
<li><a class="reference" href="#isNetworkQuiet" title="isNetworkQuiet(): bool">isNetworkQuiet(): bool</a></li>
</ul>
<ul class="simple nested-toc-section">markNetworkQuiet
<li><a class="reference" href="#markNetworkQuiet" title="markNetworkQuiet()">markNetworkQuiet()</a></li>
</ul>
<ul class="simple nested-toc-section">parseUsage
<li><a class="reference" href="#parseUsage%2CJsonNode" title="parseUsage(u: JsonNode): Usage">parseUsage(u: JsonNode): Usage</a></li>
</ul>
<ul class="simple nested-toc-section">parseXmlToolCalls
<li><a class="reference" href="#parseXmlToolCalls%2Cstring" title="parseXmlToolCalls(content: string): tuple[cleaned: string, calls: seq[JsonNode]]">parseXmlToolCalls(content: string): tuple[cleaned: string, calls: seq[JsonNode]]</a></li>
</ul>
<ul class="simple nested-toc-section">requestTurnInterrupt
<li><a class="reference" href="#requestTurnInterrupt" title="requestTurnInterrupt()">requestTurnInterrupt()</a></li>
</ul>
<ul class="simple nested-toc-section">retryCategory
<li><a class="reference" href="#retryCategory%2Cstring%2CJsonNode%2Cint" title="retryCategory(errMsg: string; assistantMsg: JsonNode; statusCode: int): string">retryCategory(errMsg: string; assistantMsg: JsonNode; statusCode: int): string</a></li>
</ul>
<ul class="simple nested-toc-section">setApiStreamHooks
<li><a class="reference" href="#setApiStreamHooks%2CApiStreamHooks" title="setApiStreamHooks(hooks: ApiStreamHooks)">setApiStreamHooks(hooks: ApiStreamHooks)</a></li>
</ul>
<ul class="simple nested-toc-section">setInterrupted
<li><a class="reference" href="#setInterrupted%2Cbool" title="setInterrupted(value: bool)">setInterrupted(value: bool)</a></li>
</ul>
<ul class="simple nested-toc-section">stripInternalFields
<li><a class="reference" href="#stripInternalFields%2CJsonNode" title="stripInternalFields(messages: JsonNode): JsonNode">stripInternalFields(messages: JsonNode): JsonNode</a></li>
</ul>
<ul class="simple nested-toc-section">verifyBody
<li><a class="reference" href="#verifyBody%2CProfile" title="verifyBody(p: Profile): string">verifyBody(p: Profile): string</a></li>
</ul>
<ul class="simple nested-toc-section">verifyProfile
<li><a class="reference" href="#verifyProfile%2CProfile" title="verifyProfile(p: Profile): (bool, string)">verifyProfile(p: Profile): (bool, string)</a></li>
</ul>
</ul>
</details>
</li>
</ul>
</div>
<div class="nine columns" id="content">
<div id="tocRoot"></div>
<p class="module-desc"><p>HTTP client and SSE parsing.</p>
<p><tt class="docutils literal"><span class="pre"><span class="Identifier">callModel</span></span></tt> is the single outbound call: it sends the messages array as an OpenAI-compatible chat completions request, reads the Server-Sent Events stream chunk by chunk, and returns a completed assistant <tt class="docutils literal"><span class="pre"><span class="Identifier">JsonNode</span></span></tt> plus a <tt class="docutils literal"><span class="pre"><span class="Identifier">Usage</span></span></tt> record.</p>
<p>XML tool call recovery handles a gpt-oss quirk: some nvidia-hosted variants leak the model's native <tt class="docutils literal"><span class="pre"><span class="Operator"><</span><span class="Identifier">tool_call</span><span class="Operator">></span></span></tt> chat template into <tt class="docutils literal"><span class="pre"><span class="Identifier">delta</span><span class="Operator">.</span><span class="Identifier">content</span></span></tt> instead of the OpenAI <tt class="docutils literal"><span class="pre"><span class="Identifier">tool_calls</span></span></tt> field. When <tt class="docutils literal"><span class="pre"><span class="Identifier">xmlToolCalls</span></span></tt> is set for a combo, <tt class="docutils literal"><span class="pre"><span class="Identifier">callModel</span></span></tt> promotes those tags to synthetic tool_calls so the rest of the pipeline sees a uniform shape.</p>
</p>
<div class="section" id="6">
<h1><a class="toc-backref" href="#6">Imports</a></h1>
<dl class="item">
<a class="reference external" href="types.html">types</a>, <a class="reference external" href="util.html">util</a>, <a class="reference external" href="prompts.html">prompts</a>, <a class="reference external" href="compact.html">compact</a>, <a class="reference external" href="streamexec.html">streamexec</a>
</dl>
</div>
<div class="section" id="7">
<h1><a class="toc-backref" href="#7">Types</a></h1>
<dl class="item">
<div id="ApiStreamHooks">
<dt><pre><a href="#ApiStreamHooks"><span class="Identifier">ApiStreamHooks</span></a> <span class="Other">=</span> <span class="Keyword">object</span>
<span class="Identifier">beforeCall</span><span class="Operator">*</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">lastPromptTokens</span><span class="Other">,</span> <span class="Identifier">window</span><span class="Other">:</span> <span class="Identifier">int</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">string</span> {.<span class="Identifier">closure</span>.}
<span class="Identifier">afterCall</span><span class="Operator">*</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Other">)</span> {.<span class="Identifier">closure</span>.}
<span class="Identifier">progress</span><span class="Operator">*</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">baseLabel</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">;</span> <span class="Identifier">slurped</span><span class="Other">:</span> <span class="Identifier">int</span><span class="Other">)</span> {.<span class="Identifier">closure</span>.}
<span class="Identifier">setStatusLabel</span><span class="Operator">*</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">label</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">)</span> {.<span class="Identifier">closure</span>.}
<span class="Identifier">startSpinner</span><span class="Operator">*</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">label</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">)</span> {.<span class="Identifier">closure</span>.}
<span class="Identifier">stopSpinner</span><span class="Operator">*</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Other">)</span> {.<span class="Identifier">closure</span>.}
<span class="Identifier">providerActivity</span><span class="Operator">*</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Other">)</span> {.<span class="Identifier">closure</span>.}
<span class="Identifier">reasoningDelta</span><span class="Operator">*</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">reasoning</span><span class="Other">,</span> <span class="Identifier">baseLabel</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">;</span> <span class="Identifier">slurped</span><span class="Other">:</span> <span class="Identifier">int</span><span class="Other">;</span>
<span class="Identifier">contentStarted</span><span class="Other">:</span> <span class="Identifier">bool</span><span class="Other">)</span> {.<span class="Identifier">closure</span>.}
<span class="Identifier">contentDelta</span><span class="Operator">*</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">chunk</span><span class="Other">,</span> <span class="Identifier">baseLabel</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">;</span> <span class="Identifier">slurped</span><span class="Other">:</span> <span class="Identifier">int</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">bool</span> {.<span class="Identifier">closure</span>.}
<span class="Identifier">contentFinished</span><span class="Operator">*</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">fullContent</span><span class="Other">,</span> <span class="Identifier">baseLabel</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">;</span> <span class="Identifier">slurped</span><span class="Other">:</span> <span class="Identifier">int</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">bool</span> {.
<span class="Identifier">closure</span>.}
<span class="Identifier">trimTrailingContent</span><span class="Operator">*</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">fullContent</span><span class="Other">,</span> <span class="Identifier">baseLabel</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">;</span> <span class="Identifier">slurped</span><span class="Other">:</span> <span class="Identifier">int</span><span class="Other">)</span> {.
<span class="Identifier">closure</span>.}
<span class="Identifier">afterLiveContent</span><span class="Operator">*</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">baseLabel</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">;</span> <span class="Identifier">slurped</span><span class="Other">:</span> <span class="Identifier">int</span><span class="Other">)</span> {.<span class="Identifier">closure</span>.}
<span class="Identifier">finalUsage</span><span class="Operator">*</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">usage</span><span class="Other">:</span> <a href="types.html#Usage"><span class="Identifier">Usage</span></a><span class="Other">;</span> <span class="Identifier">window</span><span class="Other">,</span> <span class="Identifier">elapsed</span><span class="Other">:</span> <span class="Identifier">int</span><span class="Other">;</span>
<span class="Identifier">assistantContent</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">;</span> <span class="Identifier">streamedLive</span><span class="Other">:</span> <span class="Identifier">bool</span><span class="Other">)</span> {.<span class="Identifier">closure</span>.}
<span class="Identifier">noUsage</span><span class="Operator">*</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">elapsed</span><span class="Other">:</span> <span class="Identifier">int</span><span class="Other">)</span> {.<span class="Identifier">closure</span>.}</pre></dt>
<dd>
</dd>
</div>
<div id="FetchModelsHook">
<dt><pre><a href="#FetchModelsHook"><span class="Identifier">FetchModelsHook</span></a> <span class="Other">=</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">url</span><span class="Other">,</span> <span class="Identifier">key</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">)</span><span class="Other">:</span> <span class="Other">(</span><span class="Identifier">seq</span><span class="Other">[</span><span class="Identifier">string</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">string</span><span class="Other">)</span> {.<span class="Identifier">closure</span>.}</pre></dt>
<dd>
</dd>
</div>
<div id="VerifyProfileHook">
<dt><pre><a href="#VerifyProfileHook"><span class="Identifier">VerifyProfileHook</span></a> <span class="Other">=</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="types.html#Profile"><span class="Identifier">Profile</span></a><span class="Other">)</span><span class="Other">:</span> <span class="Other">(</span><span class="Identifier">bool</span><span class="Other">,</span> <span class="Identifier">string</span><span class="Other">)</span> {.<span class="Identifier">closure</span>.}</pre></dt>
<dd>
</dd>
</div>
</dl>
</div>
<div class="section" id="8">
<h1><a class="toc-backref" href="#8">Vars</a></h1>
<dl class="item">
<div id="apiStreamHooks_2">
<dt><pre><a href="#apiStreamHooks"><span class="Identifier">apiStreamHooks</span></a><span class="Other">:</span> <a href="#ApiStreamHooks"><span class="Identifier">ApiStreamHooks</span></a></pre></dt>
<dd>
</dd>
</div>
<div id="fetchModelsHook_2">
<dt><pre><a href="#fetchModelsHook"><span class="Identifier">fetchModelsHook</span></a><span class="Other">:</span> <a href="#FetchModelsHook"><span class="Identifier">FetchModelsHook</span></a></pre></dt>
<dd>
</dd>
</div>
<div id="verifyProfileHook_2">
<dt><pre><a href="#verifyProfileHook"><span class="Identifier">verifyProfileHook</span></a><span class="Other">:</span> <a href="#VerifyProfileHook"><span class="Identifier">VerifyProfileHook</span></a></pre></dt>
<dd>
</dd>
</div>
</dl>
</div>
<div class="section" id="10">
<h1><a class="toc-backref" href="#10">Consts</a></h1>
<dl class="item">
<div id="QuietRecvWakeMs">
<dt><pre><a href="#QuietRecvWakeMs"><span class="Identifier">QuietRecvWakeMs</span></a> {.<span class="Identifier">intdefine</span>.} <span class="Other">=</span> <span class="DecNumber">500</span></pre></dt>
<dd>
How long each blocking <tt class="docutils literal"><span class="pre"><span class="Identifier">recv</span></span></tt> may stall before waking. With streamhttp's <tt class="docutils literal"><span class="pre"><span class="Identifier">readTimeoutMs</span></span></tt> set to this, <tt class="docutils literal"><span class="pre"><span class="Identifier">readLine</span></span></tt> raises <tt class="docutils literal"><span class="pre"><span class="Identifier">StreamTimeoutError</span></span></tt> periodically so the stream loop can re-check the quiet/interrupt flags. Must be well under <tt class="docutils literal"><span class="pre"><span class="Identifier">QuietTooLongMs</span></span></tt>. Kept at 1s so user interrupts (Ctrl-C) are honored within ~1s; the extra poll overhead is negligible for trickle-rate streams.
</dd>
</div>
<div id="QuietTooLongMs">
<dt><pre><a href="#QuietTooLongMs"><span class="Identifier">QuietTooLongMs</span></a> {.<span class="Identifier">intdefine</span>.} <span class="Other">=</span> <span class="DecNumber">180000</span></pre></dt>
<dd>
If a streaming response goes this long with no data from the provider, the turn is aborted. <tt class="docutils literal"><span class="pre"><span class="Identifier">posix</span><span class="Operator">.</span><span class="Identifier">shutdown</span><span class="Punctuation">(</span><span class="Identifier">fd</span><span class="Punctuation">)</span></span></tt> from another thread does not reliably wake a blocked TLS <tt class="docutils literal"><span class="pre"><span class="Identifier">recv</span></span></tt>, so the stream loop instead relies on <tt class="docutils literal"><span class="pre"><span class="Identifier">QuietRecvWakeMs</span></span></tt>-bounded reads to wake up and observe this threshold.
</dd>
</div>
</dl>
</div>
<div class="section" id="12">
<h1><a class="toc-backref" href="#12">Procs</a></h1>
<dl class="item">
<div id="applyGenerationDefaults-procs-all">
<div id="applyGenerationDefaults,Profile,JsonNode">
<dt><pre><span class="Keyword">proc</span> <a href="#applyGenerationDefaults%2CProfile%2CJsonNode"><span class="Identifier">applyGenerationDefaults</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="types.html#Profile"><span class="Identifier">Profile</span></a><span class="Other">;</span> <span class="Identifier">body</span><span class="Other">:</span> <span class="Identifier">JsonNode</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
<span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
Known-good generation policy. Temperature is intentionally hardcoded for now; later a user override can resolve before this writes the field.
</dd>
</div>
</div>
<div id="applyReasoning-procs-all">
<div id="applyReasoning,Profile,JsonNode">
<dt><pre><span class="Keyword">proc</span> <a href="#applyReasoning%2CProfile%2CJsonNode"><span class="Identifier">applyReasoning</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="types.html#Profile"><span class="Identifier">Profile</span></a><span class="Other">;</span> <span class="Identifier">body</span><span class="Other">:</span> <span class="Identifier">JsonNode</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
<span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
Per-family wire mapping for <tt class="docutils literal"><span class="pre"><span class="Identifier">Profile</span><span class="Operator">.</span><span class="Identifier">reasoning</span></span></tt>. Adding a new family means: (1) set <tt class="docutils literal"><span class="pre"><span class="Identifier">reasoning</span></span></tt> in the known-good combo table,<ol class="simple" start="2"><li>write an <tt class="docutils literal"><span class="pre"><span class="Identifier">applyXReasoning</span></span></tt> proc, (3) add a case branch.</li>
</ol>
</dd>
</div>
</div>
<div id="applyStreamingOptions-procs-all">
<div id="applyStreamingOptions,Profile,JsonNode">
<dt><pre><span class="Keyword">proc</span> <a href="#applyStreamingOptions%2CProfile%2CJsonNode"><span class="Identifier">applyStreamingOptions</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="types.html#Profile"><span class="Identifier">Profile</span></a><span class="Other">;</span> <span class="Identifier">body</span><span class="Other">:</span> <span class="Identifier">JsonNode</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
<span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
<p>Provider-specific additions for SSE fidelity.</p>
<p>Z.ai's first-party API (provider names <tt class="docutils literal"><span class="pre"><span class="Identifier">zai</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Identifier">zai</span><span class="Operator">-</span><span class="Identifier">coding</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Identifier">zaicode</span></span></tt>) gets <tt class="docutils literal"><span class="pre"><span class="Identifier">tool_stream</span><span class="Punctuation">:</span> <span class="Identifier">true</span></span></tt>, which streams tool-call arguments as per-token deltas. This was disabled for a long time as a workaround for a streamhttp TLS read bug that truncated the per-token deltas mid-stream; that bug is fixed in streamhttp >= 0.2.0 (the recv loop drains OpenSSL's internal buffer before polling), so streamed tool args now arrive complete. Reasoning/thinking streams live regardless (gated by <tt class="docutils literal"><span class="pre"><span class="Identifier">stream</span><span class="Punctuation">:</span><span class="Identifier">true</span></span></tt> + <tt class="docutils literal"><span class="pre"><span class="Identifier">thinking</span><span class="Punctuation">:</span><span class="Identifier">enabled</span></span></tt>, not <tt class="docutils literal"><span class="pre"><span class="Identifier">tool_stream</span></span></tt>).</p>
</dd>
</div>
</div>
<div id="buildBatchAssistantMsg-procs-all">
<div id="buildBatchAssistantMsg,string,string,JsonNode">
<dt><pre><span class="Keyword">proc</span> <a href="#buildBatchAssistantMsg%2Cstring%2Cstring%2CJsonNode"><span class="Identifier">buildBatchAssistantMsg</span></a><span class="Other">(</span><span class="Identifier">message</span><span class="Other">,</span> <span class="Identifier">reasoning</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">;</span> <span class="Identifier">toolCalls</span><span class="Other">:</span> <span class="Identifier">JsonNode</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">JsonNode</span> {.
<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
Build an assistant message from a non-streaming completion's <tt class="docutils literal"><span class="pre"><span class="Identifier">choices</span><span class="Punctuation">[</span><span class="DecNumber">0</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">message</span></span></tt>. Mirrors <tt class="docutils literal"><span class="pre"><span class="Identifier">buildStreamAssistantMsg</span></span></tt>'s shape so the rest of the pipeline (history replay, tool dispatch) sees a uniform object regardless of transport. Returns nil only when the message is genuinely empty (no content, no tool_calls, no reasoning) — the caller treats that as an error to surface.
</dd>
</div>
</div>
<div id="buildStreamAssistantMsg-procs-all">
<div id="buildStreamAssistantMsg,string,string,OrderedTable[int,JsonNode],Usage">
<dt><pre><span class="Keyword">proc</span> <a href="#buildStreamAssistantMsg%2Cstring%2Cstring%2COrderedTable%5Bint%2CJsonNode%5D%2CUsage"><span class="Identifier">buildStreamAssistantMsg</span></a><span class="Other">(</span><span class="Identifier">content</span><span class="Other">,</span> <span class="Identifier">reasoning</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">;</span>
<span class="Identifier">tools</span><span class="Other">:</span> <span class="Identifier">OrderedTable</span><span class="Other">[</span><span class="Identifier">int</span><span class="Other">,</span> <span class="Identifier">JsonNode</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">usage</span><span class="Other">:</span> <a href="types.html#Usage"><span class="Identifier">Usage</span></a><span class="Other">;</span>
<span class="Identifier">wasInterrupted</span> <span class="Other">=</span> <span class="Identifier">false</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">JsonNode</span> {.
<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">KeyError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
Build the assistant message reconstructed from an SSE stream. Returns nil when the stream produced no assistant data.
</dd>
</div>
</div>
<div id="callModel-procs-all">
<div id="callModel,Profile,JsonNode,Usage,int">
<dt><pre><span class="Keyword">proc</span> <a href="#callModel%2CProfile%2CJsonNode%2CUsage%2Cint"><span class="Identifier">callModel</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="types.html#Profile"><span class="Identifier">Profile</span></a><span class="Other">;</span> <span class="Identifier">messages</span><span class="Other">:</span> <span class="Identifier">JsonNode</span><span class="Other">;</span> <span class="Identifier">usage</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="types.html#Usage"><span class="Identifier">Usage</span></a><span class="Other">;</span>
<span class="Identifier">lastPromptTokens</span><span class="Other">:</span> <span class="Identifier">int</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">JsonNode</span> {.
<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">KeyError</span><span class="Other">,</span> <span class="Identifier">Exception</span><span class="Other">,</span> <span class="Identifier">ValueError</span><span class="Other">,</span> <span class="Identifier">ApiError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span>
<span class="Identifier">TimeEffect</span><span class="Other">,</span> <span class="Identifier">WriteIOEffect</span><span class="Other">,</span> <span class="Identifier">RootEffect</span><span class="Other">,</span> <span class="Identifier">ReadIOEffect</span><span class="Other">,</span> <span class="Identifier">ReadDirEffect</span><span class="Other">,</span>
<span class="Identifier">ReadEnvEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
</dd>
</div>
</div>
<div id="classifyRetry-procs-all">
<div id="classifyRetry,ref.CatchableError,int">
<dt><pre><span class="Keyword">proc</span> <a href="#classifyRetry%2Cref.CatchableError%2Cint"><span class="Identifier">classifyRetry</span></a><span class="Other">(</span><span class="Identifier">exc</span><span class="Other">:</span> <span class="Keyword">ref</span> <span class="Identifier">CatchableError</span><span class="Other">;</span> <span class="Identifier">code</span><span class="Other">:</span> <span class="Identifier">int</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">string</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
<span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
Returns "server" for network errors and 5xx, "rate" for 429, "" for anything else (not retryable). Pure-logic helper for the callModel retry block.
</dd>
</div>
</div>
<div id="clearInterrupted-procs-all">
<div id="clearInterrupted">
<dt><pre><span class="Keyword">proc</span> <a href="#clearInterrupted"><span class="Identifier">clearInterrupted</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
</dd>
</div>
</div>
<div id="clearNetworkQuiet-procs-all">
<div id="clearNetworkQuiet">
<dt><pre><span class="Keyword">proc</span> <a href="#clearNetworkQuiet"><span class="Identifier">clearNetworkQuiet</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
</dd>
</div>
</div>
<div id="closeCachedStreamConn-procs-all">
<div id="closeCachedStreamConn">
<dt><pre><span class="Keyword">proc</span> <a href="#closeCachedStreamConn"><span class="Identifier">closeCachedStreamConn</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">Exception</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span>
<span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
</dd>
</div>
</div>
<div id="fetchModels-procs-all">
<div id="fetchModels,string,string">
<dt><pre><span class="Keyword">proc</span> <a href="#fetchModels%2Cstring%2Cstring"><span class="Identifier">fetchModels</span></a><span class="Other">(</span><span class="Identifier">url</span><span class="Other">,</span> <span class="Identifier">key</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">)</span><span class="Other">:</span> <span class="Other">(</span><span class="Identifier">seq</span><span class="Other">[</span><span class="Identifier">string</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">string</span><span class="Other">)</span> {.
<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">Exception</span><span class="Other">,</span> <span class="Identifier">Exception</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">,</span> <span class="Identifier">ReadDirEffect</span><span class="Other">,</span>
<span class="Identifier">ReadEnvEffect</span><span class="Other">,</span> <span class="Identifier">ReadIOEffect</span><span class="Other">,</span> <span class="Identifier">WriteIOEffect</span><span class="Other">,</span> <span class="Identifier">TimeEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
GET /models on the provider. Returns (models, error) — error is empty on success. Callers are responsible for displaying the error.
</dd>
</div>
</div>
<div id="installInterruptHook-procs-all">
<div id="installInterruptHook">
<dt><pre><span class="Keyword">proc</span> <a href="#installInterruptHook"><span class="Identifier">installInterruptHook</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
</dd>
</div>
</div>
<div id="isInterrupted-procs-all">
<div id="isInterrupted">
<dt><pre><span class="Keyword">proc</span> <a href="#isInterrupted"><span class="Identifier">isInterrupted</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">bool</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
</dd>
</div>
</div>
<div id="isNetworkQuiet-procs-all">
<div id="isNetworkQuiet">
<dt><pre><span class="Keyword">proc</span> <a href="#isNetworkQuiet"><span class="Identifier">isNetworkQuiet</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">bool</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
</dd>
</div>
</div>
<div id="markNetworkQuiet-procs-all">
<div id="markNetworkQuiet">
<dt><pre><span class="Keyword">proc</span> <a href="#markNetworkQuiet"><span class="Identifier">markNetworkQuiet</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
</dd>
</div>
</div>
<div id="parseUsage-procs-all">
<div id="parseUsage,JsonNode">
<dt><pre><span class="Keyword">proc</span> <a href="#parseUsage%2CJsonNode"><span class="Identifier">parseUsage</span></a><span class="Other">(</span><span class="Identifier">u</span><span class="Other">:</span> <span class="Identifier">JsonNode</span><span class="Other">)</span><span class="Other">:</span> <a href="types.html#Usage"><span class="Identifier">Usage</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span>
<span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
Parses an OpenAI-compatible <tt class="docutils literal"><span class="pre"><span class="Identifier">usage</span></span></tt> object. Cached-token accounting differs by provider: OpenAI/DeepInfra/Anthropic report it under <tt class="docutils literal"><span class="pre"><span class="Identifier">prompt_tokens_details</span><span class="Operator">.</span><span class="Identifier">cached_tokens</span></span></tt>; DeepSeek reports it flat as <tt class="docutils literal"><span class="pre"><span class="Identifier">prompt_cache_hit_tokens</span></span></tt>. We accept either.
</dd>
</div>
</div>
<div id="parseXmlToolCalls-procs-all">
<div id="parseXmlToolCalls,string">
<dt><pre><span class="Keyword">proc</span> <a href="#parseXmlToolCalls%2Cstring"><span class="Identifier">parseXmlToolCalls</span></a><span class="Other">(</span><span class="Identifier">content</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">)</span><span class="Other">:</span> <span class="Keyword">tuple</span><span class="Other">[</span><span class="Identifier">cleaned</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">,</span>
<span class="Identifier">calls</span><span class="Other">:</span> <span class="Identifier">seq</span><span class="Other">[</span><span class="Identifier">JsonNode</span><span class="Other">]</span><span class="Other">]</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
<p>Extract GLM/Qwen native <tt class="docutils literal"><span class="pre"><span class="Operator"><</span><span class="Identifier">tool_call</span><span class="Operator">></span><span class="Identifier">NAME</span><span class="Operator"><</span><span class="Identifier">arg_key</span><span class="Operator">></span><span class="Identifier">K</span><span class="Operator"></</span><span class="Identifier">arg_key</span><span class="Operator">></span> <span class="Operator"><</span><span class="Identifier">arg_value</span><span class="Operator">></span><span class="Identifier">V</span><span class="Operator"></</span><span class="Identifier">arg_value</span><span class="Operator">>...</</span><span class="Identifier">tool_call</span><span class="Operator">></span></span></tt> blocks from <tt class="docutils literal"><span class="pre"><span class="Identifier">content</span></span></tt> and promote them to OpenAI-style <tt class="docutils literal"><span class="pre"><span class="Identifier">tool_calls</span></span></tt> entries. Returns the content with those blocks removed and the synthesized calls.</p>
<p>Some endpoints (e.g. nvidia z-ai/glm4.7 mid-turn) leak the model's chat-template tokens into the SSE content stream instead of parsing them into <tt class="docutils literal"><span class="pre"><span class="Identifier">tool_calls</span></span></tt> deltas. This parser is the fallback.</p>
</dd>
</div>
</div>
<div id="requestTurnInterrupt-procs-all">
<div id="requestTurnInterrupt">
<dt><pre><span class="Keyword">proc</span> <a href="#requestTurnInterrupt"><span class="Identifier">requestTurnInterrupt</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
One cancellation path for signal hooks, buffered prompt keys, and stream/tool stdin watchers. Setting the flag alone is not enough: blocking HTTP reads must be woken and active tool subprocesses must be signalled, otherwise Ctrl-C appears to do nothing until the provider or command produces output.
</dd>
</div>
</div>
<div id="retryCategory-procs-all">
<div id="retryCategory,string,JsonNode,int">
<dt><pre><span class="Keyword">proc</span> <a href="#retryCategory%2Cstring%2CJsonNode%2Cint"><span class="Identifier">retryCategory</span></a><span class="Other">(</span><span class="Identifier">errMsg</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">;</span> <span class="Identifier">assistantMsg</span><span class="Other">:</span> <span class="Identifier">JsonNode</span><span class="Other">;</span> <span class="Identifier">statusCode</span><span class="Other">:</span> <span class="Identifier">int</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">string</span> {.
<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
</dd>
</div>
</div>
<div id="setApiStreamHooks-procs-all">
<div id="setApiStreamHooks,ApiStreamHooks">
<dt><pre><span class="Keyword">proc</span> <a href="#setApiStreamHooks%2CApiStreamHooks"><span class="Identifier">setApiStreamHooks</span></a><span class="Other">(</span><span class="Identifier">hooks</span><span class="Other">:</span> <a href="#ApiStreamHooks"><span class="Identifier">ApiStreamHooks</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
<span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
</dd>
</div>
</div>
<div id="setInterrupted-procs-all">
<div id="setInterrupted,bool">
<dt><pre><span class="Keyword">proc</span> <a href="#setInterrupted%2Cbool"><span class="Identifier">setInterrupted</span></a><span class="Other">(</span><span class="Identifier">value</span><span class="Other">:</span> <span class="Identifier">bool</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
</dd>
</div>
</div>
<div id="stripInternalFields-procs-all">
<div id="stripInternalFields,JsonNode">
<dt><pre><span class="Keyword">proc</span> <a href="#stripInternalFields%2CJsonNode"><span class="Identifier">stripInternalFields</span></a><span class="Other">(</span><span class="Identifier">messages</span><span class="Other">:</span> <span class="Identifier">JsonNode</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">JsonNode</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
<span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
Return a wire-safe copy of <tt class="docutils literal"><span class="pre"><span class="Identifier">messages</span></span></tt> with internal bookkeeping fields removed. <tt class="docutils literal"><span class="pre"><span class="Identifier">usage</span></span></tt> is stored on assistant messages for local replay but rejected by strict validators (fireworks, glm-5p1, etc.).
</dd>
</div>
</div>
<div id="verifyBody-procs-all">
<div id="verifyBody,Profile">
<dt><pre><span class="Keyword">proc</span> <a href="#verifyBody%2CProfile"><span class="Identifier">verifyBody</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="types.html#Profile"><span class="Identifier">Profile</span></a><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">string</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
JSON body for the provider-verification ping. Kept as a named proc so the test suite can assert it matches the streaming convention used by <tt class="docutils literal"><span class="pre"><span class="Identifier">callModel</span></span></tt> (both must send <tt class="docutils literal"><span class="pre"><span class="StringLit">"stream"</span><span class="Punctuation">:</span> <span class="Identifier">true</span></span></tt>).
</dd>
</div>
</div>
<div id="verifyProfile-procs-all">
<div id="verifyProfile,Profile">
<dt><pre><span class="Keyword">proc</span> <a href="#verifyProfile%2CProfile"><span class="Identifier">verifyProfile</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="types.html#Profile"><span class="Identifier">Profile</span></a><span class="Other">)</span><span class="Other">:</span> <span class="Other">(</span><span class="Identifier">bool</span><span class="Other">,</span> <span class="Identifier">string</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">Exception</span><span class="Other">,</span> <span class="Identifier">Exception</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span>
<span class="Identifier">RootEffect</span><span class="Other">,</span> <span class="Identifier">ReadDirEffect</span><span class="Other">,</span> <span class="Identifier">ReadEnvEffect</span><span class="Other">,</span> <span class="Identifier">ReadIOEffect</span><span class="Other">,</span> <span class="Identifier">WriteIOEffect</span><span class="Other">,</span>
<span class="Identifier">TimeEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
</dd>
</div>
</div>
</dl>
</div>
</div>
</div>
<div class="twelve-columns footer">
<span class="nim-sprite"></span>
<br>
<small style="color: var(--hint);">Made with Nim. Generated: 2026-06-27 09:42:02 UTC</small>
</div>
</div>
</div>
</body>
</html>