@ebony-vinyl/dsh-our-free-model 2.7.4 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
1
  # Magpie engine notices
2
2
 
3
3
  Upstream: https://github.com/yetone/magpie.git
4
- Pinned revision: c551a229975653b7ae5b6a35e2278c983a272e06
5
- Source build version: ofm-c551a2299756
4
+ Pinned revision: 6a900e0d048e592cbc9120dd2c3f515aab9ef04a
5
+ Source build version: ofm-6a900e0d048e
6
6
 
7
7
  Built without upstream modifications using the nogui tag. This excludes the native
8
8
  desktop shell and retains the complete embedded web UI and built-in plugins.
@@ -11,7 +11,7 @@ The upstream MIT license is reproduced in LICENSE. Go dependency license and
11
11
  notice files below are copied verbatim from the modules linked into this build.
12
12
  The Go runtime license is included as well. Build inputs and hashes are in engine.json.
13
13
 
14
- ## github.com/Calcium-Ion/moejs v0.1.0-alpha.4
14
+ ## github.com/MoeForge/moejs v0.1.0-alpha.11
15
15
 
16
16
  ### LICENSE
17
17
 
@@ -594,6 +594,26 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
594
594
  SOFTWARE.
595
595
  ```
596
596
 
597
+ ## github.com/coder/websocket v1.8.14
598
+
599
+ ### LICENSE.txt
600
+
601
+ ```text
602
+ Copyright (c) 2025 Coder
603
+
604
+ Permission to use, copy, modify, and distribute this software for any
605
+ purpose with or without fee is hereby granted, provided that the above
606
+ copyright notice and this permission notice appear in all copies.
607
+
608
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
609
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
610
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
611
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
612
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
613
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
614
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
615
+ ```
616
+
597
617
  ## github.com/dustin/go-humanize v1.0.1
598
618
 
599
619
  ### LICENSE
@@ -650,6 +670,100 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
650
670
  SOFTWARE.
651
671
  ```
652
672
 
673
+ ## github.com/fsnotify/fsnotify v1.9.0
674
+
675
+ ### LICENSE
676
+
677
+ ```text
678
+ Copyright © 2012 The Go Authors. All rights reserved.
679
+ Copyright © fsnotify Authors. All rights reserved.
680
+
681
+ Redistribution and use in source and binary forms, with or without modification,
682
+ are permitted provided that the following conditions are met:
683
+
684
+ * Redistributions of source code must retain the above copyright notice, this
685
+ list of conditions and the following disclaimer.
686
+ * Redistributions in binary form must reproduce the above copyright notice, this
687
+ list of conditions and the following disclaimer in the documentation and/or
688
+ other materials provided with the distribution.
689
+ * Neither the name of Google Inc. nor the names of its contributors may be used
690
+ to endorse or promote products derived from this software without specific
691
+ prior written permission.
692
+
693
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
694
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
695
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
696
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
697
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
698
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
699
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
700
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
701
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
702
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
703
+ ```
704
+
705
+ ## github.com/go-ole/go-ole v1.3.0
706
+
707
+ ### LICENSE
708
+
709
+ ```text
710
+ The MIT License (MIT)
711
+
712
+ Copyright © 2013-2017 Yasuhiro Matsumoto, <mattn.jp@gmail.com>
713
+
714
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
715
+ this software and associated documentation files (the “Software”), to deal in
716
+ the Software without restriction, including without limitation the rights to
717
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
718
+ of the Software, and to permit persons to whom the Software is furnished to do
719
+ so, subject to the following conditions:
720
+
721
+ The above copyright notice and this permission notice shall be included in all
722
+ copies or substantial portions of the Software.
723
+
724
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
725
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
726
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
727
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
728
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
729
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
730
+ SOFTWARE.
731
+ ```
732
+
733
+ ## github.com/google/uuid v1.6.0
734
+
735
+ ### LICENSE
736
+
737
+ ```text
738
+ Copyright (c) 2009,2014 Google Inc. All rights reserved.
739
+
740
+ Redistribution and use in source and binary forms, with or without
741
+ modification, are permitted provided that the following conditions are
742
+ met:
743
+
744
+ * Redistributions of source code must retain the above copyright
745
+ notice, this list of conditions and the following disclaimer.
746
+ * Redistributions in binary form must reproduce the above
747
+ copyright notice, this list of conditions and the following disclaimer
748
+ in the documentation and/or other materials provided with the
749
+ distribution.
750
+ * Neither the name of Google Inc. nor the names of its
751
+ contributors may be used to endorse or promote products derived from
752
+ this software without specific prior written permission.
753
+
754
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
755
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
756
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
757
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
758
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
759
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
760
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
761
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
762
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
763
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
764
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
765
+ ```
766
+
653
767
  ## github.com/klauspost/compress v1.18.3
654
768
 
655
769
  ### LICENSE
@@ -1784,6 +1898,40 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1784
1898
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1785
1899
  ```
1786
1900
 
1901
+ ## golang.org/x/image v0.43.0
1902
+
1903
+ ### LICENSE
1904
+
1905
+ ```text
1906
+ Copyright 2009 The Go Authors.
1907
+
1908
+ Redistribution and use in source and binary forms, with or without
1909
+ modification, are permitted provided that the following conditions are
1910
+ met:
1911
+
1912
+ * Redistributions of source code must retain the above copyright
1913
+ notice, this list of conditions and the following disclaimer.
1914
+ * Redistributions in binary form must reproduce the above
1915
+ copyright notice, this list of conditions and the following disclaimer
1916
+ in the documentation and/or other materials provided with the
1917
+ distribution.
1918
+ * Neither the name of Google LLC nor the names of its
1919
+ contributors may be used to endorse or promote products derived from
1920
+ this software without specific prior written permission.
1921
+
1922
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1923
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1924
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1925
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1926
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1927
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1928
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1929
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1930
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1931
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1932
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1933
+ ```
1934
+
1787
1935
  ## golang.org/x/net v0.56.0
1788
1936
 
1789
1937
  ### LICENSE
@@ -2,8 +2,8 @@
2
2
  "schemaVersion": 1,
3
3
  "name": "magpie",
4
4
  "upstream": "https://github.com/yetone/magpie.git",
5
- "revision": "c551a229975653b7ae5b6a35e2278c983a272e06",
6
- "version": "ofm-c551a2299756",
5
+ "revision": "6a900e0d048e592cbc9120dd2c3f515aab9ef04a",
6
+ "version": "ofm-6a900e0d048e",
7
7
  "license": "MIT",
8
8
  "build": {
9
9
  "command": [
@@ -14,7 +14,7 @@
14
14
  "-trimpath",
15
15
  "-buildvcs=true",
16
16
  "-ldflags",
17
- "-X main.version=ofm-c551a2299756",
17
+ "-s -w -X main.version=ofm-6a900e0d048e",
18
18
  "."
19
19
  ],
20
20
  "go": "go version go1.27.1 windows/amd64"
@@ -22,57 +22,47 @@
22
22
  "binaries": {
23
23
  "win32-x64": {
24
24
  "path": "bin/magpie-win32-x64.exe",
25
- "sha256": "6490f7ed2c5f001adc97284276af453f2a2b1711712e175e6fc780e09046fa3b",
25
+ "sha256": "1f4b2f350fe09f42c0ac8a859c2ccb5f03dcd0c13d4e066cd689a1acda23e604",
26
26
  "compressed": {
27
27
  "algorithm": "gzip",
28
- "size": 35128000,
29
- "sha256": "5964bf859e7de297bdc755d9fb4d540b816df87efd6fd28bbf9e1103c326730e",
30
- "outputSize": 68578304,
28
+ "size": 27223733,
29
+ "sha256": "4f3afd03b709cda47b3b4ad4723cdbf12a74a027b321da4f1a6c0a5983e7ff56",
30
+ "outputSize": 64811008,
31
31
  "parts": [
32
32
  {
33
33
  "path": "src/engine-parts/win32-x64.000.part",
34
34
  "size": 4194304,
35
- "sha256": "ee492eaa5d992b8703ede29821e07b4bd46a9ff0395faba2128211e1363fa4b9"
35
+ "sha256": "f8dea6313012982c0b3cde2badda9733a7baee19d90c5dd73abe66d7bdc58de4"
36
36
  },
37
37
  {
38
38
  "path": "src/engine-parts/win32-x64.001.part",
39
39
  "size": 4194304,
40
- "sha256": "141c520cf249a6930618c198c6072ccf04fab7edee93ab4f28da41c4619e61aa"
40
+ "sha256": "8b790e0dc8debc3d1c1817d2874afe2b6935909efcfba5eca239106e0572d499"
41
41
  },
42
42
  {
43
43
  "path": "src/engine-parts/win32-x64.002.part",
44
44
  "size": 4194304,
45
- "sha256": "854178a956532bdfc7b6eee89d179c6a5ea5a29fef9a0a2d19f396938ca93fe7"
45
+ "sha256": "131e57f9211b71a81868e361873ce1bdc87ff026bd2cf8723779b73c68ed1380"
46
46
  },
47
47
  {
48
48
  "path": "src/engine-parts/win32-x64.003.part",
49
49
  "size": 4194304,
50
- "sha256": "37740d6058361640c8a46cbcb26576ed88ba41f99c6162a495475828d5c7bff1"
50
+ "sha256": "e4c553e91328c9e95d701e8bb3d800dc155ed4c6003b9b5b31597a29f76d2fea"
51
51
  },
52
52
  {
53
53
  "path": "src/engine-parts/win32-x64.004.part",
54
54
  "size": 4194304,
55
- "sha256": "228b98336fef117087c55d5ab85cc972cc42f61ea1d4b19ced145ac408723525"
55
+ "sha256": "20b5ffa9453af953ffd771513d858cf0ab4e22ba863d86b4edf2d5e1c33c4a19"
56
56
  },
57
57
  {
58
58
  "path": "src/engine-parts/win32-x64.005.part",
59
59
  "size": 4194304,
60
- "sha256": "4c723b29f4d69861fd29751951e7c480ae35ad981489b406cb0765b78cc5a26f"
60
+ "sha256": "f2902a4a09f9f55fc3b0d7f5922e61cac58dd58942733e70b5fb212c8f788eb1"
61
61
  },
62
62
  {
63
63
  "path": "src/engine-parts/win32-x64.006.part",
64
- "size": 4194304,
65
- "sha256": "397e3c199a0ed6ef6ffdf7a9de62cc7467f5583a2a5ecef3d5867cde9d14ce86"
66
- },
67
- {
68
- "path": "src/engine-parts/win32-x64.007.part",
69
- "size": 4194304,
70
- "sha256": "18cb47f20ab54d013aaf9f7471695bb5a6e7ef5b8ed39a088c61a63a8ce73132"
71
- },
72
- {
73
- "path": "src/engine-parts/win32-x64.008.part",
74
- "size": 1573568,
75
- "sha256": "4a0877e8067b71b5968304008afeb8b96fd578ac581a52e2281df45b95e0d3ce"
64
+ "size": 2057909,
65
+ "sha256": "c399bbd95b0101b571674f96a0efc255517b677c0b9ced203851c263b3e734bb"
76
66
  }
77
67
  ]
78
68
  }
@@ -80,8 +70,8 @@
80
70
  },
81
71
  "modules": [
82
72
  {
83
- "path": "github.com/Calcium-Ion/moejs",
84
- "version": "v0.1.0-alpha.4",
73
+ "path": "github.com/MoeForge/moejs",
74
+ "version": "v0.1.0-alpha.11",
85
75
  "licenses": [
86
76
  "LICENSE"
87
77
  ]
@@ -171,6 +161,13 @@
171
161
  "LICENSE"
172
162
  ]
173
163
  },
164
+ {
165
+ "path": "github.com/coder/websocket",
166
+ "version": "v1.8.14",
167
+ "licenses": [
168
+ "LICENSE.txt"
169
+ ]
170
+ },
174
171
  {
175
172
  "path": "github.com/dustin/go-humanize",
176
173
  "version": "v1.0.1",
@@ -185,6 +182,27 @@
185
182
  "LICENSE"
186
183
  ]
187
184
  },
185
+ {
186
+ "path": "github.com/fsnotify/fsnotify",
187
+ "version": "v1.9.0",
188
+ "licenses": [
189
+ "LICENSE"
190
+ ]
191
+ },
192
+ {
193
+ "path": "github.com/go-ole/go-ole",
194
+ "version": "v1.3.0",
195
+ "licenses": [
196
+ "LICENSE"
197
+ ]
198
+ },
199
+ {
200
+ "path": "github.com/google/uuid",
201
+ "version": "v1.6.0",
202
+ "licenses": [
203
+ "LICENSE"
204
+ ]
205
+ },
188
206
  {
189
207
  "path": "github.com/klauspost/compress",
190
208
  "version": "v1.18.3",
@@ -317,6 +335,13 @@
317
335
  "LICENSE"
318
336
  ]
319
337
  },
338
+ {
339
+ "path": "golang.org/x/image",
340
+ "version": "v0.43.0",
341
+ "licenses": [
342
+ "LICENSE"
343
+ ]
344
+ },
320
345
  {
321
346
  "path": "golang.org/x/net",
322
347
  "version": "v0.56.0",
@@ -1,196 +0,0 @@
1
- import { ROUTE_MAIN, ROUTE_REGION } from '../adapter.js'
2
- import { toOpenAiUsage } from '../forward.js'
3
- import { carryFailure } from '../failure.js'
4
- import { effortsFor, defaultEffortFor } from '../effort.js'
5
-
6
- export function routableModelIds(snapshot) {
7
- const membership = new Set(snapshot.membership[ROUTE_MAIN] ?? [])
8
- if (snapshot.settings.exposeRegionModels !== false) {
9
- for (const id of snapshot.membership[ROUTE_REGION] ?? []) membership.add(id)
10
- }
11
- return membership
12
- }
13
-
14
- export function publicModelRows(snapshot) {
15
- const membership = routableModelIds(snapshot)
16
- return snapshot.catalog
17
- .filter(entry => membership.has(entry.id))
18
- .map(entry => {
19
- const efforts = effortsFor(entry, undefined, snapshot.settings.defaultMaxTokens)
20
- return {
21
- id: entry.id, object: 'model',
22
- created: Math.floor(Date.now() / 1000), owned_by: 'our-free-model',
23
- ...entry.contextWindow === undefined ? {} : { context_window: entry.contextWindow },
24
- ...efforts === undefined ? {} : {
25
- x_ofm_efforts: efforts.map(effort => effort.id),
26
- x_ofm_effort_default: defaultEffortFor(entry),
27
- },
28
- }
29
- })
30
- }
31
-
32
- /** 固定本次请求的模型和配置快照,两个入口使用同一条推理链路。 */
33
- export function createForwardCompletion({ adapter, state, signal }) {
34
- return async (request, onChunk) => {
35
- if (signal?.aborted) throw Object.assign(new Error('model runtime is stopped'), { statusCode: 503 })
36
- const snapshot = state()
37
- const entry = snapshot.catalog.find(candidate => candidate.id === request.model)
38
- if (entry === undefined || !routableModelIds(snapshot).has(entry.id)) {
39
- throw Object.assign(new Error(`model "${request.model}" not found`), { statusCode: 404 })
40
- }
41
- const openAi = request.openAi ?? {}
42
- // Two callers converge here. The OpenAI/Responses listener hands over a raw
43
- // body; the Anthropic listener hands over harness messages it already
44
- // projected through `fromAnthropicRequest`, because re-spelling them as
45
- // OpenAI blocks and back would lose thinking blocks and block ordering. Both
46
- // shapes end at the same adapter call, so there is exactly one place that
47
- // decides which model runs.
48
- const messages = Array.isArray(request.messages)
49
- ? request.messages
50
- : fromOpenAiMessages(openAi, request.responses === true, entry.id)
51
- const tools = Array.isArray(request.tools)
52
- ? request.tools
53
- : (openAi.tools ?? []).map(normalizeTool).filter(Boolean)
54
- const handler = typeof onChunk === 'function' ? onChunk : () => {}
55
- const outcome = { text: '', toolCalls: [], usage: undefined, truncated: false, error: undefined }
56
- const maxTokens = Number.isFinite(request.maxTokens) ? request.maxTokens
57
- : Number.isFinite(openAi.max_tokens) ? openAi.max_tokens : undefined
58
- const temperature = Number.isFinite(request.temperature) ? request.temperature
59
- : Number.isFinite(openAi.temperature) ? openAi.temperature : undefined
60
- const reasoningEffort = typeof request.reasoningEffort === 'string' ? request.reasoningEffort
61
- : typeof openAi.reasoning_effort === 'string' ? openAi.reasoning_effort : undefined
62
- const toolChoice = request.toolChoice === undefined ? openAi.tool_choice : request.toolChoice
63
- const options = {
64
- provider: ROUTE_MAIN, model: entry.id,
65
- messages,
66
- tools: tools.length > 0 ? tools : undefined,
67
- ...temperature === undefined ? {} : { temperature },
68
- ...maxTokens === undefined ? {} : { maxTokens },
69
- ...reasoningEffort === undefined ? {} : { reasoningEffort },
70
- ...toolChoice === undefined ? {} : { toolChoice },
71
- sessionId: `forward:${String(openAi.user ?? openAi.conversation ?? request.sessionId ?? 'shared')}`,
72
- signal: request.signal && signal ? AbortSignal.any([request.signal, signal]) : request.signal ?? signal,
73
- }
74
- for await (const chunk of adapter.stream(options, entry, snapshot)) {
75
- handler(chunk)
76
- foldForwardOutcome(outcome, chunk)
77
- }
78
- if (outcome.truncated === true) {
79
- outcome.toolCalls = outcome.toolCalls.filter(call => {
80
- try { JSON.parse(call.arguments === '' ? '{}' : call.arguments); return true } catch { return false }
81
- })
82
- }
83
- return outcome
84
- }
85
- }
86
-
87
- export function fromOpenAiMessages(body, isResponses, modelId) {
88
- const out = []
89
- const rows = isResponses
90
- ? normaliseResponsesInput(body.input)
91
- : (Array.isArray(body.messages) ? body.messages : [])
92
- for (const row of rows) {
93
- const role = row.role ?? 'user'
94
- const content = []
95
- if (typeof row.content === 'string') {
96
- if (row.content !== '') content.push({ type: 'text', text: row.content })
97
- } else if (Array.isArray(row.content)) {
98
- for (const part of row.content) {
99
- if (typeof part === 'string') { if (part !== '') content.push({ type: 'text', text: part }); continue }
100
- const text = part?.text ?? part?.input_text ?? part?.output_text
101
- if (typeof text === 'string' && text !== '') content.push({ type: 'text', text })
102
- const image = part?.image_url?.url ?? part?.image_url
103
- if (typeof image === 'string' && image !== '') {
104
- content.push({ type: 'image', attachment: { attachmentId: `url:${image.slice(0, 64)}`, mediaType: 'image/png', bytes: 0, width: 0, height: 0, url: image } })
105
- }
106
- }
107
- }
108
- if (role === 'tool') {
109
- out.push({ role: 'tool', content: [{ type: 'text', text: typeof row.content === 'string' ? row.content : JSON.stringify(row.content ?? '') }], toolCallId: row.tool_call_id ?? '', source: { kind: 'tool', callId: row.tool_call_id ?? '' } })
110
- continue
111
- }
112
- if (role === 'assistant' && Array.isArray(row.tool_calls)) {
113
- for (const call of row.tool_calls) {
114
- content.push({ type: 'tool-call', id: call.id ?? '', name: call.function?.name ?? '', arguments: call.function?.arguments ?? '{}' })
115
- }
116
- }
117
- if (content.length === 0) continue
118
- out.push({
119
- role: role === 'developer' ? 'developer' : role === 'system' ? 'system' : role === 'assistant' ? 'assistant' : 'user',
120
- content,
121
- ...(role === 'assistant' && typeof row.reasoning_content === 'string'
122
- ? { reasoning_content: row.reasoning_content }
123
- : {}),
124
- ...role === 'assistant' ? { source: { kind: 'model', provider: ROUTE_MAIN, model: String(modelId ?? '') } } : {},
125
- })
126
- }
127
- return out
128
- }
129
-
130
- function normaliseResponsesInput(input) {
131
- if (typeof input === 'string') return [{ role: 'user', content: input }]
132
- if (!Array.isArray(input)) return []
133
- return input.map(row => {
134
- if (typeof row === 'string') return { role: 'user', content: row }
135
- if (row.type === 'function_call') return { role: 'assistant', content: [], tool_calls: [{ id: row.call_id, function: { name: row.name, arguments: row.arguments } }] }
136
- if (row.type === 'function_call_output') return { role: 'tool', content: String(row.output ?? ''), tool_call_id: row.call_id }
137
- return row
138
- })
139
- }
140
-
141
- function normalizeTool(tool) {
142
- const name = tool?.name ?? tool?.function?.name
143
- if (typeof name !== 'string' || name.trim() === '') return null
144
- const parameters = tool?.parameters ?? tool?.function?.parameters ?? { type: 'object', properties: {} }
145
- return { name, description: String(tool?.description ?? tool?.function?.description ?? ''), parameters }
146
- }
147
-
148
- export function foldForwardOutcome(outcome, chunk) {
149
- switch (chunk.type) {
150
- case 'text-delta': outcome.text += chunk.text; break
151
- case 'tool-call-delta': {
152
- let call = outcome.toolCalls.find(candidate => candidate.slot === chunk.index)
153
- if (call === undefined) { call = { slot: chunk.index, id: chunk.id ?? '', name: chunk.name ?? '', arguments: chunk.argumentsDelta ?? '' }; outcome.toolCalls.push(call) }
154
- else call.arguments += chunk.argumentsDelta ?? ''
155
- if (chunk.name) call.name = chunk.name
156
- if (chunk.id) call.id = chunk.id
157
- break
158
- }
159
- case 'block-end':
160
- if (chunk.block?.type === 'tool-call') {
161
- // Match by slot first: the call's deltas were folded under this same
162
- // block index, and a relayed stream can carry its id late — matching
163
- // by id alone would miss the slot's entry and fold one call into two.
164
- // The block-end carries the assembled arguments, so a slot match
165
- // adopts them; an id match only fills identity fields.
166
- const bySlot = outcome.toolCalls.find(candidate => candidate.slot === chunk.index)
167
- if (bySlot !== undefined) {
168
- if (typeof chunk.block.id === 'string' && chunk.block.id !== '') bySlot.id = chunk.block.id
169
- if (typeof chunk.block.name === 'string' && chunk.block.name !== '') bySlot.name = chunk.block.name
170
- if (typeof chunk.block.arguments === 'string') bySlot.arguments = chunk.block.arguments
171
- break
172
- }
173
- const byId = outcome.toolCalls.find(candidate => typeof candidate.id === 'string' && candidate.id !== ''
174
- && candidate.id === chunk.block.id)
175
- if (byId === undefined) {
176
- outcome.toolCalls.push({
177
- slot: chunk.index,
178
- id: typeof chunk.block.id === 'string' ? chunk.block.id : '',
179
- name: typeof chunk.block.name === 'string' ? chunk.block.name : '',
180
- arguments: typeof chunk.block.arguments === 'string' ? chunk.block.arguments : '',
181
- })
182
- }
183
- }
184
- break
185
- case 'usage': outcome.usage = toOpenAiUsage(chunk.usage); break
186
- case 'finish':
187
- if (chunk.reason?.kind === 'max-tokens') outcome.truncated = true
188
- if (chunk.reason?.kind === 'error' || chunk.reason?.kind === 'aborted') {
189
- outcome.failure = carryFailure(chunk.reason.failure, chunk.reason.kind)
190
- outcome.error = outcome.failure.message
191
- }
192
- break
193
- default: break
194
- }
195
- return outcome
196
- }