@eum-agent/llm-provider-chatgpt 1.1.0 → 1.2.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.
- package/dist/index.js +905 -1493
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -2,1250 +2,6 @@ import { z } from "zod";
|
|
|
2
2
|
import { createHash, randomBytes } from "node:crypto";
|
|
3
3
|
import { setImmediate, setTimeout } from "node:timers/promises";
|
|
4
4
|
import { createServer } from "node:http";
|
|
5
|
-
//#endregion
|
|
6
|
-
//#region src/catalog.ts
|
|
7
|
-
/** This extension's endpoint declarations and offline catalogue seed. */
|
|
8
|
-
const catalog = {
|
|
9
|
-
vendors: [{
|
|
10
|
-
kind: "vendor",
|
|
11
|
-
id: "chatgpt",
|
|
12
|
-
logo: "data:image/svg+xml,%3Csvg%20fill%3D%22currentColor%22%20fill-rule%3D%22evenodd%22%20height%3D%2224%22%20style%3D%22flex%3Anone%3Bline-height%3A1%22%20viewBox%3D%220%200%2024%2024%22%20width%3D%2224%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Ctitle%3EOpenAI%3C%2Ftitle%3E%3Cpath%20d%3D%22M9.205%208.658v-2.26c0-.19.072-.333.238-.428l4.543-2.616c.619-.357%201.356-.523%202.117-.523%202.854%200%204.662%202.212%204.662%204.566%200%20.167%200%20.357-.024.547l-4.71-2.759a.797.797%200%2000-.856%200l-5.97%203.473zm10.609%208.8V12.06c0-.333-.143-.57-.429-.737l-5.97-3.473%201.95-1.118a.433.433%200%2001.476%200l4.543%202.617c1.309.76%202.189%202.378%202.189%203.948%200%201.808-1.07%203.473-2.76%204.163zM7.802%2012.703l-1.95-1.142c-.167-.095-.239-.238-.239-.428V5.899c0-2.545%201.95-4.472%204.591-4.472%201%200%201.927.333%202.712.928L8.23%205.067c-.285.166-.428.404-.428.737v6.898zM12%2015.128l-2.795-1.57v-3.33L12%208.658l2.795%201.57v3.33L12%2015.128zm1.796%207.23c-1%200-1.927-.332-2.712-.927l4.686-2.712c.285-.166.428-.404.428-.737v-6.898l1.974%201.142c.167.095.238.238.238.428v5.233c0%202.545-1.974%204.472-4.614%204.472zm-5.637-5.303l-4.544-2.617c-1.308-.761-2.188-2.378-2.188-3.948A4.482%204.482%200%20014.21%206.327v5.423c0%20.333.143.571.428.738l5.947%203.449-1.95%201.118a.432.432%200%2001-.476%200zm-.262%203.9c-2.688%200-4.662-2.021-4.662-4.519%200-.19.024-.38.047-.57l4.686%202.71c.286.167.571.167.856%200l5.97-3.448v2.26c0%20.19-.07.333-.237.428l-4.543%202.616c-.619.357-1.356.523-2.117.523zm5.899%202.83a5.947%205.947%200%20005.827-4.756C22.287%2018.339%2024%2015.84%2024%2013.296c0-1.665-.713-3.282-1.998-4.448.119-.5.19-.999.19-1.498%200-3.401-2.759-5.947-5.946-5.947-.642%200-1.26.095-1.88.31A5.962%205.962%200%200010.205%200a5.947%205.947%200%2000-5.827%204.757C1.713%205.447%200%207.945%200%2010.49c0%201.666.713%203.283%201.998%204.448-.119.5-.19%201-.19%201.499%200%203.401%202.759%205.946%205.946%205.946.642%200%201.26-.095%201.88-.309a5.96%205.96%200%20004.162%201.713z%22%3E%3C%2Fpath%3E%3C%2Fsvg%3E",
|
|
13
|
-
name: "ChatGPT",
|
|
14
|
-
region: null,
|
|
15
|
-
market: "international",
|
|
16
|
-
catalogKey: "openai",
|
|
17
|
-
canListModels: true,
|
|
18
|
-
endpoints: [{
|
|
19
|
-
type: "chatgpt",
|
|
20
|
-
endpointId: "subscription",
|
|
21
|
-
protocolIds: ["chatgpt-subscription"],
|
|
22
|
-
baseUrl: "https://chatgpt.com/backend-api/codex"
|
|
23
|
-
}]
|
|
24
|
-
}],
|
|
25
|
-
snapshot: { "chatgpt": {
|
|
26
|
-
"gpt-5-nano": {
|
|
27
|
-
"id": "gpt-5-nano",
|
|
28
|
-
"name": "GPT-5 Nano",
|
|
29
|
-
"family": "gpt-nano",
|
|
30
|
-
"reasoning": true,
|
|
31
|
-
"reasoning_options": [{
|
|
32
|
-
"type": "effort",
|
|
33
|
-
"values": [
|
|
34
|
-
"minimal",
|
|
35
|
-
"low",
|
|
36
|
-
"medium",
|
|
37
|
-
"high"
|
|
38
|
-
]
|
|
39
|
-
}],
|
|
40
|
-
"temperature": false,
|
|
41
|
-
"tool_call": true,
|
|
42
|
-
"attachment": true,
|
|
43
|
-
"modalities": {
|
|
44
|
-
"input": ["text", "image"],
|
|
45
|
-
"output": ["text"]
|
|
46
|
-
},
|
|
47
|
-
"limit": {
|
|
48
|
-
"context": 4e5,
|
|
49
|
-
"output": 128e3
|
|
50
|
-
},
|
|
51
|
-
"release_date": "2025-08-07"
|
|
52
|
-
},
|
|
53
|
-
"gpt-4.1-nano": {
|
|
54
|
-
"id": "gpt-4.1-nano",
|
|
55
|
-
"name": "GPT-4.1 nano",
|
|
56
|
-
"family": "gpt-nano",
|
|
57
|
-
"reasoning": false,
|
|
58
|
-
"temperature": true,
|
|
59
|
-
"tool_call": true,
|
|
60
|
-
"attachment": true,
|
|
61
|
-
"modalities": {
|
|
62
|
-
"input": ["text", "image"],
|
|
63
|
-
"output": ["text"]
|
|
64
|
-
},
|
|
65
|
-
"limit": {
|
|
66
|
-
"context": 1047576,
|
|
67
|
-
"output": 32768
|
|
68
|
-
},
|
|
69
|
-
"release_date": "2025-04-14"
|
|
70
|
-
},
|
|
71
|
-
"gpt-4o-2024-05-13": {
|
|
72
|
-
"id": "gpt-4o-2024-05-13",
|
|
73
|
-
"name": "GPT-4o (2024-05-13)",
|
|
74
|
-
"family": "gpt",
|
|
75
|
-
"reasoning": false,
|
|
76
|
-
"temperature": true,
|
|
77
|
-
"tool_call": true,
|
|
78
|
-
"attachment": true,
|
|
79
|
-
"modalities": {
|
|
80
|
-
"input": ["text", "image"],
|
|
81
|
-
"output": ["text"]
|
|
82
|
-
},
|
|
83
|
-
"limit": {
|
|
84
|
-
"context": 128e3,
|
|
85
|
-
"output": 4096
|
|
86
|
-
},
|
|
87
|
-
"release_date": "2024-05-13"
|
|
88
|
-
},
|
|
89
|
-
"gpt-5-pro": {
|
|
90
|
-
"id": "gpt-5-pro",
|
|
91
|
-
"name": "GPT-5 Pro",
|
|
92
|
-
"family": "gpt-pro",
|
|
93
|
-
"reasoning": true,
|
|
94
|
-
"reasoning_options": [{
|
|
95
|
-
"type": "effort",
|
|
96
|
-
"values": ["high"]
|
|
97
|
-
}],
|
|
98
|
-
"temperature": false,
|
|
99
|
-
"tool_call": true,
|
|
100
|
-
"attachment": true,
|
|
101
|
-
"modalities": {
|
|
102
|
-
"input": ["text", "image"],
|
|
103
|
-
"output": ["text"]
|
|
104
|
-
},
|
|
105
|
-
"limit": {
|
|
106
|
-
"context": 4e5,
|
|
107
|
-
"output": 272e3
|
|
108
|
-
},
|
|
109
|
-
"release_date": "2025-10-06"
|
|
110
|
-
},
|
|
111
|
-
"chatgpt-image-latest": {
|
|
112
|
-
"id": "chatgpt-image-latest",
|
|
113
|
-
"name": "chatgpt-image-latest",
|
|
114
|
-
"family": "gpt-image",
|
|
115
|
-
"reasoning": false,
|
|
116
|
-
"temperature": false,
|
|
117
|
-
"tool_call": false,
|
|
118
|
-
"attachment": true,
|
|
119
|
-
"modalities": {
|
|
120
|
-
"input": ["text", "image"],
|
|
121
|
-
"output": ["text", "image"]
|
|
122
|
-
},
|
|
123
|
-
"limit": {
|
|
124
|
-
"context": 0,
|
|
125
|
-
"output": 0
|
|
126
|
-
},
|
|
127
|
-
"release_date": "2025-12-16"
|
|
128
|
-
},
|
|
129
|
-
"gpt-5.6-sol": {
|
|
130
|
-
"id": "gpt-5.6-sol",
|
|
131
|
-
"name": "GPT-5.6 Sol",
|
|
132
|
-
"family": "gpt-sol",
|
|
133
|
-
"reasoning": true,
|
|
134
|
-
"reasoning_options": [{
|
|
135
|
-
"type": "effort",
|
|
136
|
-
"values": [
|
|
137
|
-
"none",
|
|
138
|
-
"low",
|
|
139
|
-
"medium",
|
|
140
|
-
"high",
|
|
141
|
-
"xhigh",
|
|
142
|
-
"max"
|
|
143
|
-
]
|
|
144
|
-
}],
|
|
145
|
-
"temperature": false,
|
|
146
|
-
"tool_call": true,
|
|
147
|
-
"attachment": true,
|
|
148
|
-
"modalities": {
|
|
149
|
-
"input": [
|
|
150
|
-
"text",
|
|
151
|
-
"image",
|
|
152
|
-
"pdf"
|
|
153
|
-
],
|
|
154
|
-
"output": ["text"]
|
|
155
|
-
},
|
|
156
|
-
"limit": {
|
|
157
|
-
"context": 105e4,
|
|
158
|
-
"output": 128e3
|
|
159
|
-
},
|
|
160
|
-
"release_date": "2026-07-09"
|
|
161
|
-
},
|
|
162
|
-
"gpt-4o-2024-08-06": {
|
|
163
|
-
"id": "gpt-4o-2024-08-06",
|
|
164
|
-
"name": "GPT-4o (2024-08-06)",
|
|
165
|
-
"family": "gpt",
|
|
166
|
-
"reasoning": false,
|
|
167
|
-
"temperature": true,
|
|
168
|
-
"tool_call": true,
|
|
169
|
-
"attachment": true,
|
|
170
|
-
"modalities": {
|
|
171
|
-
"input": ["text", "image"],
|
|
172
|
-
"output": ["text"]
|
|
173
|
-
},
|
|
174
|
-
"limit": {
|
|
175
|
-
"context": 128e3,
|
|
176
|
-
"output": 16384
|
|
177
|
-
},
|
|
178
|
-
"release_date": "2024-08-06"
|
|
179
|
-
},
|
|
180
|
-
"gpt-6-astra": {
|
|
181
|
-
"id": "gpt-6-astra",
|
|
182
|
-
"name": "GPT-6 Astra",
|
|
183
|
-
"family": "gpt-astra",
|
|
184
|
-
"reasoning": true,
|
|
185
|
-
"reasoning_options": [{
|
|
186
|
-
"type": "effort",
|
|
187
|
-
"values": [
|
|
188
|
-
"low",
|
|
189
|
-
"medium",
|
|
190
|
-
"high",
|
|
191
|
-
"xhigh",
|
|
192
|
-
"max"
|
|
193
|
-
]
|
|
194
|
-
}],
|
|
195
|
-
"temperature": false,
|
|
196
|
-
"tool_call": true,
|
|
197
|
-
"attachment": true,
|
|
198
|
-
"modalities": {
|
|
199
|
-
"input": [
|
|
200
|
-
"text",
|
|
201
|
-
"image",
|
|
202
|
-
"pdf"
|
|
203
|
-
],
|
|
204
|
-
"output": ["text"]
|
|
205
|
-
},
|
|
206
|
-
"limit": {
|
|
207
|
-
"context": 105e4,
|
|
208
|
-
"output": 128e3
|
|
209
|
-
},
|
|
210
|
-
"release_date": "2026-09-04"
|
|
211
|
-
},
|
|
212
|
-
"gpt-5.2-pro": {
|
|
213
|
-
"id": "gpt-5.2-pro",
|
|
214
|
-
"name": "GPT-5.2 Pro",
|
|
215
|
-
"family": "gpt-pro",
|
|
216
|
-
"reasoning": true,
|
|
217
|
-
"reasoning_options": [{
|
|
218
|
-
"type": "effort",
|
|
219
|
-
"values": [
|
|
220
|
-
"medium",
|
|
221
|
-
"high",
|
|
222
|
-
"xhigh"
|
|
223
|
-
]
|
|
224
|
-
}],
|
|
225
|
-
"temperature": false,
|
|
226
|
-
"tool_call": true,
|
|
227
|
-
"attachment": true,
|
|
228
|
-
"modalities": {
|
|
229
|
-
"input": ["text", "image"],
|
|
230
|
-
"output": ["text"]
|
|
231
|
-
},
|
|
232
|
-
"limit": {
|
|
233
|
-
"context": 4e5,
|
|
234
|
-
"output": 128e3
|
|
235
|
-
},
|
|
236
|
-
"release_date": "2025-12-11"
|
|
237
|
-
},
|
|
238
|
-
"gpt-5.3-codex-spark": {
|
|
239
|
-
"id": "gpt-5.3-codex-spark",
|
|
240
|
-
"name": "GPT-5.3 Codex Spark",
|
|
241
|
-
"family": "gpt-codex-spark",
|
|
242
|
-
"reasoning": true,
|
|
243
|
-
"reasoning_options": [{
|
|
244
|
-
"type": "effort",
|
|
245
|
-
"values": [
|
|
246
|
-
"none",
|
|
247
|
-
"low",
|
|
248
|
-
"medium",
|
|
249
|
-
"high",
|
|
250
|
-
"xhigh"
|
|
251
|
-
]
|
|
252
|
-
}],
|
|
253
|
-
"temperature": false,
|
|
254
|
-
"tool_call": true,
|
|
255
|
-
"attachment": true,
|
|
256
|
-
"modalities": {
|
|
257
|
-
"input": [
|
|
258
|
-
"text",
|
|
259
|
-
"image",
|
|
260
|
-
"pdf"
|
|
261
|
-
],
|
|
262
|
-
"output": ["text"]
|
|
263
|
-
},
|
|
264
|
-
"limit": {
|
|
265
|
-
"context": 128e3,
|
|
266
|
-
"output": 32e3
|
|
267
|
-
},
|
|
268
|
-
"release_date": "2026-02-05"
|
|
269
|
-
},
|
|
270
|
-
"gpt-4.1-mini": {
|
|
271
|
-
"id": "gpt-4.1-mini",
|
|
272
|
-
"name": "GPT-4.1 mini",
|
|
273
|
-
"family": "gpt-mini",
|
|
274
|
-
"reasoning": false,
|
|
275
|
-
"temperature": true,
|
|
276
|
-
"tool_call": true,
|
|
277
|
-
"attachment": true,
|
|
278
|
-
"modalities": {
|
|
279
|
-
"input": [
|
|
280
|
-
"text",
|
|
281
|
-
"image",
|
|
282
|
-
"pdf"
|
|
283
|
-
],
|
|
284
|
-
"output": ["text"]
|
|
285
|
-
},
|
|
286
|
-
"limit": {
|
|
287
|
-
"context": 1047576,
|
|
288
|
-
"output": 32768
|
|
289
|
-
},
|
|
290
|
-
"release_date": "2025-04-14"
|
|
291
|
-
},
|
|
292
|
-
"gpt-5.4": {
|
|
293
|
-
"id": "gpt-5.4",
|
|
294
|
-
"name": "GPT-5.4",
|
|
295
|
-
"family": "gpt",
|
|
296
|
-
"reasoning": true,
|
|
297
|
-
"reasoning_options": [{
|
|
298
|
-
"type": "effort",
|
|
299
|
-
"values": [
|
|
300
|
-
"none",
|
|
301
|
-
"low",
|
|
302
|
-
"medium",
|
|
303
|
-
"high",
|
|
304
|
-
"xhigh"
|
|
305
|
-
]
|
|
306
|
-
}],
|
|
307
|
-
"temperature": true,
|
|
308
|
-
"tool_call": true,
|
|
309
|
-
"attachment": true,
|
|
310
|
-
"modalities": {
|
|
311
|
-
"input": [
|
|
312
|
-
"text",
|
|
313
|
-
"image",
|
|
314
|
-
"pdf"
|
|
315
|
-
],
|
|
316
|
-
"output": ["text"]
|
|
317
|
-
},
|
|
318
|
-
"limit": {
|
|
319
|
-
"context": 105e4,
|
|
320
|
-
"output": 128e3
|
|
321
|
-
},
|
|
322
|
-
"release_date": "2026-03-05"
|
|
323
|
-
},
|
|
324
|
-
"gpt-4-turbo": {
|
|
325
|
-
"id": "gpt-4-turbo",
|
|
326
|
-
"name": "GPT-4 Turbo",
|
|
327
|
-
"family": "gpt",
|
|
328
|
-
"reasoning": false,
|
|
329
|
-
"temperature": true,
|
|
330
|
-
"tool_call": true,
|
|
331
|
-
"attachment": true,
|
|
332
|
-
"modalities": {
|
|
333
|
-
"input": ["text", "image"],
|
|
334
|
-
"output": ["text"]
|
|
335
|
-
},
|
|
336
|
-
"limit": {
|
|
337
|
-
"context": 128e3,
|
|
338
|
-
"output": 4096
|
|
339
|
-
},
|
|
340
|
-
"release_date": "2023-11-06"
|
|
341
|
-
},
|
|
342
|
-
"gpt-5.1": {
|
|
343
|
-
"id": "gpt-5.1",
|
|
344
|
-
"name": "GPT-5.1",
|
|
345
|
-
"family": "gpt",
|
|
346
|
-
"reasoning": true,
|
|
347
|
-
"reasoning_options": [{
|
|
348
|
-
"type": "effort",
|
|
349
|
-
"values": [
|
|
350
|
-
"none",
|
|
351
|
-
"low",
|
|
352
|
-
"medium",
|
|
353
|
-
"high"
|
|
354
|
-
]
|
|
355
|
-
}],
|
|
356
|
-
"temperature": true,
|
|
357
|
-
"tool_call": true,
|
|
358
|
-
"attachment": true,
|
|
359
|
-
"modalities": {
|
|
360
|
-
"input": ["text", "image"],
|
|
361
|
-
"output": ["text"]
|
|
362
|
-
},
|
|
363
|
-
"limit": {
|
|
364
|
-
"context": 4e5,
|
|
365
|
-
"output": 128e3
|
|
366
|
-
},
|
|
367
|
-
"release_date": "2025-11-13"
|
|
368
|
-
},
|
|
369
|
-
"o1": {
|
|
370
|
-
"id": "o1",
|
|
371
|
-
"name": "o1",
|
|
372
|
-
"family": "o",
|
|
373
|
-
"reasoning": true,
|
|
374
|
-
"reasoning_options": [{
|
|
375
|
-
"type": "effort",
|
|
376
|
-
"values": [
|
|
377
|
-
"low",
|
|
378
|
-
"medium",
|
|
379
|
-
"high"
|
|
380
|
-
]
|
|
381
|
-
}],
|
|
382
|
-
"temperature": false,
|
|
383
|
-
"tool_call": true,
|
|
384
|
-
"attachment": true,
|
|
385
|
-
"modalities": {
|
|
386
|
-
"input": [
|
|
387
|
-
"text",
|
|
388
|
-
"image",
|
|
389
|
-
"pdf"
|
|
390
|
-
],
|
|
391
|
-
"output": ["text"]
|
|
392
|
-
},
|
|
393
|
-
"limit": {
|
|
394
|
-
"context": 2e5,
|
|
395
|
-
"output": 1e5
|
|
396
|
-
},
|
|
397
|
-
"release_date": "2024-12-05"
|
|
398
|
-
},
|
|
399
|
-
"gpt-4o": {
|
|
400
|
-
"id": "gpt-4o",
|
|
401
|
-
"name": "GPT-4o",
|
|
402
|
-
"family": "gpt",
|
|
403
|
-
"reasoning": false,
|
|
404
|
-
"temperature": true,
|
|
405
|
-
"tool_call": true,
|
|
406
|
-
"attachment": true,
|
|
407
|
-
"modalities": {
|
|
408
|
-
"input": [
|
|
409
|
-
"text",
|
|
410
|
-
"image",
|
|
411
|
-
"pdf"
|
|
412
|
-
],
|
|
413
|
-
"output": ["text"]
|
|
414
|
-
},
|
|
415
|
-
"limit": {
|
|
416
|
-
"context": 128e3,
|
|
417
|
-
"output": 16384
|
|
418
|
-
},
|
|
419
|
-
"release_date": "2024-05-13"
|
|
420
|
-
},
|
|
421
|
-
"gpt-5.6-luna": {
|
|
422
|
-
"id": "gpt-5.6-luna",
|
|
423
|
-
"name": "GPT-5.6 Luna",
|
|
424
|
-
"family": "gpt-luna",
|
|
425
|
-
"reasoning": true,
|
|
426
|
-
"reasoning_options": [{
|
|
427
|
-
"type": "effort",
|
|
428
|
-
"values": [
|
|
429
|
-
"none",
|
|
430
|
-
"low",
|
|
431
|
-
"medium",
|
|
432
|
-
"high",
|
|
433
|
-
"xhigh",
|
|
434
|
-
"max"
|
|
435
|
-
]
|
|
436
|
-
}],
|
|
437
|
-
"temperature": false,
|
|
438
|
-
"tool_call": true,
|
|
439
|
-
"attachment": true,
|
|
440
|
-
"modalities": {
|
|
441
|
-
"input": [
|
|
442
|
-
"text",
|
|
443
|
-
"image",
|
|
444
|
-
"pdf"
|
|
445
|
-
],
|
|
446
|
-
"output": ["text"]
|
|
447
|
-
},
|
|
448
|
-
"limit": {
|
|
449
|
-
"context": 105e4,
|
|
450
|
-
"output": 128e3
|
|
451
|
-
},
|
|
452
|
-
"release_date": "2026-07-09"
|
|
453
|
-
},
|
|
454
|
-
"gpt-5.3-codex": {
|
|
455
|
-
"id": "gpt-5.3-codex",
|
|
456
|
-
"name": "GPT-5.3 Codex",
|
|
457
|
-
"family": "gpt-codex",
|
|
458
|
-
"reasoning": true,
|
|
459
|
-
"reasoning_options": [{
|
|
460
|
-
"type": "effort",
|
|
461
|
-
"values": [
|
|
462
|
-
"none",
|
|
463
|
-
"low",
|
|
464
|
-
"medium",
|
|
465
|
-
"high",
|
|
466
|
-
"xhigh"
|
|
467
|
-
]
|
|
468
|
-
}],
|
|
469
|
-
"temperature": true,
|
|
470
|
-
"tool_call": true,
|
|
471
|
-
"attachment": true,
|
|
472
|
-
"modalities": {
|
|
473
|
-
"input": [
|
|
474
|
-
"text",
|
|
475
|
-
"image",
|
|
476
|
-
"pdf"
|
|
477
|
-
],
|
|
478
|
-
"output": ["text"]
|
|
479
|
-
},
|
|
480
|
-
"limit": {
|
|
481
|
-
"context": 4e5,
|
|
482
|
-
"output": 128e3
|
|
483
|
-
},
|
|
484
|
-
"release_date": "2026-02-05"
|
|
485
|
-
},
|
|
486
|
-
"gpt-4o-mini": {
|
|
487
|
-
"id": "gpt-4o-mini",
|
|
488
|
-
"name": "GPT-4o mini",
|
|
489
|
-
"family": "gpt-mini",
|
|
490
|
-
"reasoning": false,
|
|
491
|
-
"temperature": true,
|
|
492
|
-
"tool_call": true,
|
|
493
|
-
"attachment": true,
|
|
494
|
-
"modalities": {
|
|
495
|
-
"input": [
|
|
496
|
-
"text",
|
|
497
|
-
"image",
|
|
498
|
-
"pdf"
|
|
499
|
-
],
|
|
500
|
-
"output": ["text"]
|
|
501
|
-
},
|
|
502
|
-
"limit": {
|
|
503
|
-
"context": 128e3,
|
|
504
|
-
"output": 16384
|
|
505
|
-
},
|
|
506
|
-
"release_date": "2024-07-18"
|
|
507
|
-
},
|
|
508
|
-
"gpt-image-1.5": {
|
|
509
|
-
"id": "gpt-image-1.5",
|
|
510
|
-
"name": "gpt-image-1.5",
|
|
511
|
-
"family": "gpt-image",
|
|
512
|
-
"reasoning": false,
|
|
513
|
-
"temperature": false,
|
|
514
|
-
"tool_call": false,
|
|
515
|
-
"attachment": true,
|
|
516
|
-
"modalities": {
|
|
517
|
-
"input": ["text", "image"],
|
|
518
|
-
"output": ["text", "image"]
|
|
519
|
-
},
|
|
520
|
-
"limit": {
|
|
521
|
-
"context": 0,
|
|
522
|
-
"output": 0
|
|
523
|
-
},
|
|
524
|
-
"release_date": "2025-11-25"
|
|
525
|
-
},
|
|
526
|
-
"o1-pro": {
|
|
527
|
-
"id": "o1-pro",
|
|
528
|
-
"name": "o1-pro",
|
|
529
|
-
"family": "o-pro",
|
|
530
|
-
"reasoning": true,
|
|
531
|
-
"reasoning_options": [{
|
|
532
|
-
"type": "effort",
|
|
533
|
-
"values": [
|
|
534
|
-
"low",
|
|
535
|
-
"medium",
|
|
536
|
-
"high"
|
|
537
|
-
]
|
|
538
|
-
}],
|
|
539
|
-
"temperature": false,
|
|
540
|
-
"tool_call": true,
|
|
541
|
-
"attachment": true,
|
|
542
|
-
"modalities": {
|
|
543
|
-
"input": ["text", "image"],
|
|
544
|
-
"output": ["text"]
|
|
545
|
-
},
|
|
546
|
-
"limit": {
|
|
547
|
-
"context": 2e5,
|
|
548
|
-
"output": 1e5
|
|
549
|
-
},
|
|
550
|
-
"release_date": "2025-03-19"
|
|
551
|
-
},
|
|
552
|
-
"gpt-4.1": {
|
|
553
|
-
"id": "gpt-4.1",
|
|
554
|
-
"name": "GPT-4.1",
|
|
555
|
-
"family": "gpt",
|
|
556
|
-
"reasoning": false,
|
|
557
|
-
"temperature": true,
|
|
558
|
-
"tool_call": true,
|
|
559
|
-
"attachment": true,
|
|
560
|
-
"modalities": {
|
|
561
|
-
"input": [
|
|
562
|
-
"text",
|
|
563
|
-
"image",
|
|
564
|
-
"pdf"
|
|
565
|
-
],
|
|
566
|
-
"output": ["text"]
|
|
567
|
-
},
|
|
568
|
-
"limit": {
|
|
569
|
-
"context": 1047576,
|
|
570
|
-
"output": 32768
|
|
571
|
-
},
|
|
572
|
-
"release_date": "2025-04-14"
|
|
573
|
-
},
|
|
574
|
-
"text-embedding-ada-002": {
|
|
575
|
-
"id": "text-embedding-ada-002",
|
|
576
|
-
"name": "text-embedding-ada-002",
|
|
577
|
-
"family": "text-embedding",
|
|
578
|
-
"reasoning": false,
|
|
579
|
-
"temperature": false,
|
|
580
|
-
"tool_call": false,
|
|
581
|
-
"attachment": false,
|
|
582
|
-
"modalities": {
|
|
583
|
-
"input": ["text"],
|
|
584
|
-
"output": ["text"]
|
|
585
|
-
},
|
|
586
|
-
"limit": {
|
|
587
|
-
"context": 8192,
|
|
588
|
-
"output": 1536
|
|
589
|
-
},
|
|
590
|
-
"release_date": "2022-12-15"
|
|
591
|
-
},
|
|
592
|
-
"gpt-image-1": {
|
|
593
|
-
"id": "gpt-image-1",
|
|
594
|
-
"name": "gpt-image-1",
|
|
595
|
-
"family": "gpt-image",
|
|
596
|
-
"reasoning": false,
|
|
597
|
-
"temperature": false,
|
|
598
|
-
"tool_call": false,
|
|
599
|
-
"attachment": true,
|
|
600
|
-
"modalities": {
|
|
601
|
-
"input": ["text", "image"],
|
|
602
|
-
"output": ["image"]
|
|
603
|
-
},
|
|
604
|
-
"limit": {
|
|
605
|
-
"context": 0,
|
|
606
|
-
"output": 0
|
|
607
|
-
},
|
|
608
|
-
"release_date": "2025-04-24"
|
|
609
|
-
},
|
|
610
|
-
"gpt-5.4-nano": {
|
|
611
|
-
"id": "gpt-5.4-nano",
|
|
612
|
-
"name": "GPT-5.4 nano",
|
|
613
|
-
"family": "gpt-nano",
|
|
614
|
-
"reasoning": true,
|
|
615
|
-
"reasoning_options": [{
|
|
616
|
-
"type": "effort",
|
|
617
|
-
"values": [
|
|
618
|
-
"none",
|
|
619
|
-
"low",
|
|
620
|
-
"medium",
|
|
621
|
-
"high",
|
|
622
|
-
"xhigh"
|
|
623
|
-
]
|
|
624
|
-
}],
|
|
625
|
-
"temperature": true,
|
|
626
|
-
"tool_call": true,
|
|
627
|
-
"attachment": true,
|
|
628
|
-
"modalities": {
|
|
629
|
-
"input": ["text", "image"],
|
|
630
|
-
"output": ["text"]
|
|
631
|
-
},
|
|
632
|
-
"limit": {
|
|
633
|
-
"context": 4e5,
|
|
634
|
-
"output": 128e3
|
|
635
|
-
},
|
|
636
|
-
"release_date": "2026-03-17"
|
|
637
|
-
},
|
|
638
|
-
"gpt-5.5-pro": {
|
|
639
|
-
"id": "gpt-5.5-pro",
|
|
640
|
-
"name": "GPT-5.5 Pro",
|
|
641
|
-
"family": "gpt-pro",
|
|
642
|
-
"reasoning": true,
|
|
643
|
-
"reasoning_options": [{
|
|
644
|
-
"type": "effort",
|
|
645
|
-
"values": [
|
|
646
|
-
"medium",
|
|
647
|
-
"high",
|
|
648
|
-
"xhigh"
|
|
649
|
-
]
|
|
650
|
-
}],
|
|
651
|
-
"temperature": false,
|
|
652
|
-
"tool_call": true,
|
|
653
|
-
"attachment": true,
|
|
654
|
-
"modalities": {
|
|
655
|
-
"input": [
|
|
656
|
-
"text",
|
|
657
|
-
"image",
|
|
658
|
-
"pdf"
|
|
659
|
-
],
|
|
660
|
-
"output": ["text"]
|
|
661
|
-
},
|
|
662
|
-
"limit": {
|
|
663
|
-
"context": 105e4,
|
|
664
|
-
"output": 128e3
|
|
665
|
-
},
|
|
666
|
-
"release_date": "2026-04-23"
|
|
667
|
-
},
|
|
668
|
-
"gpt-image-1-mini": {
|
|
669
|
-
"id": "gpt-image-1-mini",
|
|
670
|
-
"name": "gpt-image-1-mini",
|
|
671
|
-
"family": "gpt-image",
|
|
672
|
-
"reasoning": false,
|
|
673
|
-
"temperature": false,
|
|
674
|
-
"tool_call": false,
|
|
675
|
-
"attachment": true,
|
|
676
|
-
"modalities": {
|
|
677
|
-
"input": ["text", "image"],
|
|
678
|
-
"output": ["text", "image"]
|
|
679
|
-
},
|
|
680
|
-
"limit": {
|
|
681
|
-
"context": 0,
|
|
682
|
-
"output": 0
|
|
683
|
-
},
|
|
684
|
-
"release_date": "2025-09-26"
|
|
685
|
-
},
|
|
686
|
-
"gpt-5.4-mini": {
|
|
687
|
-
"id": "gpt-5.4-mini",
|
|
688
|
-
"name": "GPT-5.4 mini",
|
|
689
|
-
"family": "gpt-mini",
|
|
690
|
-
"reasoning": true,
|
|
691
|
-
"reasoning_options": [{
|
|
692
|
-
"type": "effort",
|
|
693
|
-
"values": [
|
|
694
|
-
"none",
|
|
695
|
-
"low",
|
|
696
|
-
"medium",
|
|
697
|
-
"high",
|
|
698
|
-
"xhigh"
|
|
699
|
-
]
|
|
700
|
-
}],
|
|
701
|
-
"temperature": true,
|
|
702
|
-
"tool_call": true,
|
|
703
|
-
"attachment": true,
|
|
704
|
-
"modalities": {
|
|
705
|
-
"input": ["text", "image"],
|
|
706
|
-
"output": ["text"]
|
|
707
|
-
},
|
|
708
|
-
"limit": {
|
|
709
|
-
"context": 4e5,
|
|
710
|
-
"output": 128e3
|
|
711
|
-
},
|
|
712
|
-
"release_date": "2026-03-17"
|
|
713
|
-
},
|
|
714
|
-
"gpt-image-2": {
|
|
715
|
-
"id": "gpt-image-2",
|
|
716
|
-
"name": "gpt-image-2",
|
|
717
|
-
"family": "gpt-image",
|
|
718
|
-
"reasoning": false,
|
|
719
|
-
"temperature": false,
|
|
720
|
-
"tool_call": false,
|
|
721
|
-
"attachment": true,
|
|
722
|
-
"modalities": {
|
|
723
|
-
"input": ["text", "image"],
|
|
724
|
-
"output": ["image"]
|
|
725
|
-
},
|
|
726
|
-
"limit": {
|
|
727
|
-
"context": 0,
|
|
728
|
-
"output": 0
|
|
729
|
-
},
|
|
730
|
-
"release_date": "2026-04-21"
|
|
731
|
-
},
|
|
732
|
-
"gpt-3.5-turbo": {
|
|
733
|
-
"id": "gpt-3.5-turbo",
|
|
734
|
-
"name": "GPT-3.5-turbo",
|
|
735
|
-
"family": "gpt",
|
|
736
|
-
"reasoning": false,
|
|
737
|
-
"temperature": true,
|
|
738
|
-
"tool_call": false,
|
|
739
|
-
"attachment": false,
|
|
740
|
-
"modalities": {
|
|
741
|
-
"input": ["text"],
|
|
742
|
-
"output": ["text"]
|
|
743
|
-
},
|
|
744
|
-
"limit": {
|
|
745
|
-
"context": 16385,
|
|
746
|
-
"output": 4096
|
|
747
|
-
},
|
|
748
|
-
"release_date": "2023-03-01"
|
|
749
|
-
},
|
|
750
|
-
"gpt-5.6": {
|
|
751
|
-
"id": "gpt-5.6",
|
|
752
|
-
"name": "GPT-5.6",
|
|
753
|
-
"family": "gpt-sol",
|
|
754
|
-
"reasoning": true,
|
|
755
|
-
"reasoning_options": [{
|
|
756
|
-
"type": "effort",
|
|
757
|
-
"values": [
|
|
758
|
-
"none",
|
|
759
|
-
"low",
|
|
760
|
-
"medium",
|
|
761
|
-
"high",
|
|
762
|
-
"xhigh",
|
|
763
|
-
"max"
|
|
764
|
-
]
|
|
765
|
-
}],
|
|
766
|
-
"temperature": false,
|
|
767
|
-
"tool_call": true,
|
|
768
|
-
"attachment": true,
|
|
769
|
-
"modalities": {
|
|
770
|
-
"input": [
|
|
771
|
-
"text",
|
|
772
|
-
"image",
|
|
773
|
-
"pdf"
|
|
774
|
-
],
|
|
775
|
-
"output": ["text"]
|
|
776
|
-
},
|
|
777
|
-
"limit": {
|
|
778
|
-
"context": 105e4,
|
|
779
|
-
"output": 128e3
|
|
780
|
-
},
|
|
781
|
-
"release_date": "2026-07-09"
|
|
782
|
-
},
|
|
783
|
-
"text-embedding-3-small": {
|
|
784
|
-
"id": "text-embedding-3-small",
|
|
785
|
-
"name": "text-embedding-3-small",
|
|
786
|
-
"family": "text-embedding",
|
|
787
|
-
"reasoning": false,
|
|
788
|
-
"temperature": false,
|
|
789
|
-
"tool_call": false,
|
|
790
|
-
"attachment": false,
|
|
791
|
-
"modalities": {
|
|
792
|
-
"input": ["text"],
|
|
793
|
-
"output": ["text"]
|
|
794
|
-
},
|
|
795
|
-
"limit": {
|
|
796
|
-
"context": 8191,
|
|
797
|
-
"output": 1536
|
|
798
|
-
},
|
|
799
|
-
"release_date": "2024-01-25"
|
|
800
|
-
},
|
|
801
|
-
"gpt-5-mini": {
|
|
802
|
-
"id": "gpt-5-mini",
|
|
803
|
-
"name": "GPT-5 Mini",
|
|
804
|
-
"family": "gpt-mini",
|
|
805
|
-
"reasoning": true,
|
|
806
|
-
"reasoning_options": [{
|
|
807
|
-
"type": "effort",
|
|
808
|
-
"values": [
|
|
809
|
-
"minimal",
|
|
810
|
-
"low",
|
|
811
|
-
"medium",
|
|
812
|
-
"high"
|
|
813
|
-
]
|
|
814
|
-
}],
|
|
815
|
-
"temperature": false,
|
|
816
|
-
"tool_call": true,
|
|
817
|
-
"attachment": true,
|
|
818
|
-
"modalities": {
|
|
819
|
-
"input": ["text", "image"],
|
|
820
|
-
"output": ["text"]
|
|
821
|
-
},
|
|
822
|
-
"limit": {
|
|
823
|
-
"context": 4e5,
|
|
824
|
-
"output": 128e3
|
|
825
|
-
},
|
|
826
|
-
"release_date": "2025-08-07"
|
|
827
|
-
},
|
|
828
|
-
"gpt-5.4-pro": {
|
|
829
|
-
"id": "gpt-5.4-pro",
|
|
830
|
-
"name": "GPT-5.4 Pro",
|
|
831
|
-
"family": "gpt-pro",
|
|
832
|
-
"reasoning": true,
|
|
833
|
-
"reasoning_options": [{
|
|
834
|
-
"type": "effort",
|
|
835
|
-
"values": [
|
|
836
|
-
"medium",
|
|
837
|
-
"high",
|
|
838
|
-
"xhigh"
|
|
839
|
-
]
|
|
840
|
-
}],
|
|
841
|
-
"temperature": false,
|
|
842
|
-
"tool_call": true,
|
|
843
|
-
"attachment": true,
|
|
844
|
-
"modalities": {
|
|
845
|
-
"input": ["text", "image"],
|
|
846
|
-
"output": ["text"]
|
|
847
|
-
},
|
|
848
|
-
"limit": {
|
|
849
|
-
"context": 105e4,
|
|
850
|
-
"output": 128e3
|
|
851
|
-
},
|
|
852
|
-
"release_date": "2026-03-05"
|
|
853
|
-
},
|
|
854
|
-
"text-embedding-3-large": {
|
|
855
|
-
"id": "text-embedding-3-large",
|
|
856
|
-
"name": "text-embedding-3-large",
|
|
857
|
-
"family": "text-embedding",
|
|
858
|
-
"reasoning": false,
|
|
859
|
-
"temperature": false,
|
|
860
|
-
"tool_call": false,
|
|
861
|
-
"attachment": false,
|
|
862
|
-
"modalities": {
|
|
863
|
-
"input": ["text"],
|
|
864
|
-
"output": ["text"]
|
|
865
|
-
},
|
|
866
|
-
"limit": {
|
|
867
|
-
"context": 8191,
|
|
868
|
-
"output": 3072
|
|
869
|
-
},
|
|
870
|
-
"release_date": "2024-01-25"
|
|
871
|
-
},
|
|
872
|
-
"gpt-5.6-terra": {
|
|
873
|
-
"id": "gpt-5.6-terra",
|
|
874
|
-
"name": "GPT-5.6 Terra",
|
|
875
|
-
"family": "gpt-terra",
|
|
876
|
-
"reasoning": true,
|
|
877
|
-
"reasoning_options": [{
|
|
878
|
-
"type": "effort",
|
|
879
|
-
"values": [
|
|
880
|
-
"none",
|
|
881
|
-
"low",
|
|
882
|
-
"medium",
|
|
883
|
-
"high",
|
|
884
|
-
"xhigh",
|
|
885
|
-
"max"
|
|
886
|
-
]
|
|
887
|
-
}],
|
|
888
|
-
"temperature": false,
|
|
889
|
-
"tool_call": true,
|
|
890
|
-
"attachment": true,
|
|
891
|
-
"modalities": {
|
|
892
|
-
"input": [
|
|
893
|
-
"text",
|
|
894
|
-
"image",
|
|
895
|
-
"pdf"
|
|
896
|
-
],
|
|
897
|
-
"output": ["text"]
|
|
898
|
-
},
|
|
899
|
-
"limit": {
|
|
900
|
-
"context": 105e4,
|
|
901
|
-
"output": 128e3
|
|
902
|
-
},
|
|
903
|
-
"release_date": "2026-07-09"
|
|
904
|
-
},
|
|
905
|
-
"gpt-4": {
|
|
906
|
-
"id": "gpt-4",
|
|
907
|
-
"name": "GPT-4",
|
|
908
|
-
"family": "gpt",
|
|
909
|
-
"reasoning": false,
|
|
910
|
-
"temperature": true,
|
|
911
|
-
"tool_call": true,
|
|
912
|
-
"attachment": true,
|
|
913
|
-
"modalities": {
|
|
914
|
-
"input": ["text"],
|
|
915
|
-
"output": ["text"]
|
|
916
|
-
},
|
|
917
|
-
"limit": {
|
|
918
|
-
"context": 8192,
|
|
919
|
-
"output": 8192
|
|
920
|
-
},
|
|
921
|
-
"release_date": "2023-11-06"
|
|
922
|
-
},
|
|
923
|
-
"gpt-5.2": {
|
|
924
|
-
"id": "gpt-5.2",
|
|
925
|
-
"name": "GPT-5.2",
|
|
926
|
-
"family": "gpt",
|
|
927
|
-
"reasoning": true,
|
|
928
|
-
"reasoning_options": [{
|
|
929
|
-
"type": "effort",
|
|
930
|
-
"values": [
|
|
931
|
-
"none",
|
|
932
|
-
"low",
|
|
933
|
-
"medium",
|
|
934
|
-
"high",
|
|
935
|
-
"xhigh"
|
|
936
|
-
]
|
|
937
|
-
}],
|
|
938
|
-
"temperature": true,
|
|
939
|
-
"tool_call": true,
|
|
940
|
-
"attachment": true,
|
|
941
|
-
"modalities": {
|
|
942
|
-
"input": ["text", "image"],
|
|
943
|
-
"output": ["text"]
|
|
944
|
-
},
|
|
945
|
-
"limit": {
|
|
946
|
-
"context": 4e5,
|
|
947
|
-
"output": 128e3
|
|
948
|
-
},
|
|
949
|
-
"release_date": "2025-12-11"
|
|
950
|
-
},
|
|
951
|
-
"gpt-5": {
|
|
952
|
-
"id": "gpt-5",
|
|
953
|
-
"name": "GPT-5",
|
|
954
|
-
"family": "gpt",
|
|
955
|
-
"reasoning": true,
|
|
956
|
-
"reasoning_options": [{
|
|
957
|
-
"type": "effort",
|
|
958
|
-
"values": [
|
|
959
|
-
"minimal",
|
|
960
|
-
"low",
|
|
961
|
-
"medium",
|
|
962
|
-
"high"
|
|
963
|
-
]
|
|
964
|
-
}],
|
|
965
|
-
"temperature": false,
|
|
966
|
-
"tool_call": true,
|
|
967
|
-
"attachment": true,
|
|
968
|
-
"modalities": {
|
|
969
|
-
"input": ["text", "image"],
|
|
970
|
-
"output": ["text"]
|
|
971
|
-
},
|
|
972
|
-
"limit": {
|
|
973
|
-
"context": 4e5,
|
|
974
|
-
"output": 128e3
|
|
975
|
-
},
|
|
976
|
-
"release_date": "2025-08-07"
|
|
977
|
-
},
|
|
978
|
-
"gpt-5.2-chat-latest": {
|
|
979
|
-
"id": "gpt-5.2-chat-latest",
|
|
980
|
-
"name": "GPT-5.2 Chat",
|
|
981
|
-
"family": "gpt-codex",
|
|
982
|
-
"reasoning": true,
|
|
983
|
-
"reasoning_options": [{
|
|
984
|
-
"type": "effort",
|
|
985
|
-
"values": ["medium"]
|
|
986
|
-
}],
|
|
987
|
-
"temperature": false,
|
|
988
|
-
"tool_call": true,
|
|
989
|
-
"attachment": true,
|
|
990
|
-
"modalities": {
|
|
991
|
-
"input": ["text", "image"],
|
|
992
|
-
"output": ["text"]
|
|
993
|
-
},
|
|
994
|
-
"limit": {
|
|
995
|
-
"context": 128e3,
|
|
996
|
-
"output": 16384
|
|
997
|
-
},
|
|
998
|
-
"release_date": "2025-12-11"
|
|
999
|
-
},
|
|
1000
|
-
"o4-mini": {
|
|
1001
|
-
"id": "o4-mini",
|
|
1002
|
-
"name": "o4-mini",
|
|
1003
|
-
"family": "o-mini",
|
|
1004
|
-
"reasoning": true,
|
|
1005
|
-
"reasoning_options": [{
|
|
1006
|
-
"type": "effort",
|
|
1007
|
-
"values": [
|
|
1008
|
-
"low",
|
|
1009
|
-
"medium",
|
|
1010
|
-
"high"
|
|
1011
|
-
]
|
|
1012
|
-
}],
|
|
1013
|
-
"temperature": false,
|
|
1014
|
-
"tool_call": true,
|
|
1015
|
-
"attachment": true,
|
|
1016
|
-
"modalities": {
|
|
1017
|
-
"input": ["text", "image"],
|
|
1018
|
-
"output": ["text"]
|
|
1019
|
-
},
|
|
1020
|
-
"limit": {
|
|
1021
|
-
"context": 2e5,
|
|
1022
|
-
"output": 1e5
|
|
1023
|
-
},
|
|
1024
|
-
"release_date": "2025-04-16"
|
|
1025
|
-
},
|
|
1026
|
-
"gpt-realtime-2.1": {
|
|
1027
|
-
"id": "gpt-realtime-2.1",
|
|
1028
|
-
"name": "GPT-Realtime-2.1",
|
|
1029
|
-
"family": "gpt",
|
|
1030
|
-
"reasoning": true,
|
|
1031
|
-
"reasoning_options": [{
|
|
1032
|
-
"type": "effort",
|
|
1033
|
-
"values": [
|
|
1034
|
-
"minimal",
|
|
1035
|
-
"low",
|
|
1036
|
-
"medium",
|
|
1037
|
-
"high",
|
|
1038
|
-
"xhigh"
|
|
1039
|
-
]
|
|
1040
|
-
}],
|
|
1041
|
-
"temperature": false,
|
|
1042
|
-
"tool_call": true,
|
|
1043
|
-
"attachment": true,
|
|
1044
|
-
"modalities": {
|
|
1045
|
-
"input": [
|
|
1046
|
-
"text",
|
|
1047
|
-
"audio",
|
|
1048
|
-
"image"
|
|
1049
|
-
],
|
|
1050
|
-
"output": ["text", "audio"]
|
|
1051
|
-
},
|
|
1052
|
-
"limit": {
|
|
1053
|
-
"context": 128e3,
|
|
1054
|
-
"output": 32e3
|
|
1055
|
-
},
|
|
1056
|
-
"release_date": "2026-07-06"
|
|
1057
|
-
},
|
|
1058
|
-
"o3-mini": {
|
|
1059
|
-
"id": "o3-mini",
|
|
1060
|
-
"name": "o3-mini",
|
|
1061
|
-
"family": "o-mini",
|
|
1062
|
-
"reasoning": true,
|
|
1063
|
-
"reasoning_options": [{
|
|
1064
|
-
"type": "effort",
|
|
1065
|
-
"values": [
|
|
1066
|
-
"low",
|
|
1067
|
-
"medium",
|
|
1068
|
-
"high"
|
|
1069
|
-
]
|
|
1070
|
-
}],
|
|
1071
|
-
"temperature": false,
|
|
1072
|
-
"tool_call": true,
|
|
1073
|
-
"attachment": false,
|
|
1074
|
-
"modalities": {
|
|
1075
|
-
"input": ["text"],
|
|
1076
|
-
"output": ["text"]
|
|
1077
|
-
},
|
|
1078
|
-
"limit": {
|
|
1079
|
-
"context": 2e5,
|
|
1080
|
-
"output": 1e5
|
|
1081
|
-
},
|
|
1082
|
-
"release_date": "2024-12-20"
|
|
1083
|
-
},
|
|
1084
|
-
"o3": {
|
|
1085
|
-
"id": "o3",
|
|
1086
|
-
"name": "o3",
|
|
1087
|
-
"family": "o",
|
|
1088
|
-
"reasoning": true,
|
|
1089
|
-
"reasoning_options": [{
|
|
1090
|
-
"type": "effort",
|
|
1091
|
-
"values": [
|
|
1092
|
-
"low",
|
|
1093
|
-
"medium",
|
|
1094
|
-
"high"
|
|
1095
|
-
]
|
|
1096
|
-
}],
|
|
1097
|
-
"temperature": false,
|
|
1098
|
-
"tool_call": true,
|
|
1099
|
-
"attachment": true,
|
|
1100
|
-
"modalities": {
|
|
1101
|
-
"input": [
|
|
1102
|
-
"text",
|
|
1103
|
-
"image",
|
|
1104
|
-
"pdf"
|
|
1105
|
-
],
|
|
1106
|
-
"output": ["text"]
|
|
1107
|
-
},
|
|
1108
|
-
"limit": {
|
|
1109
|
-
"context": 2e5,
|
|
1110
|
-
"output": 1e5
|
|
1111
|
-
},
|
|
1112
|
-
"release_date": "2025-04-16"
|
|
1113
|
-
},
|
|
1114
|
-
"o3-pro": {
|
|
1115
|
-
"id": "o3-pro",
|
|
1116
|
-
"name": "o3-pro",
|
|
1117
|
-
"family": "o-pro",
|
|
1118
|
-
"reasoning": true,
|
|
1119
|
-
"reasoning_options": [{
|
|
1120
|
-
"type": "effort",
|
|
1121
|
-
"values": [
|
|
1122
|
-
"low",
|
|
1123
|
-
"medium",
|
|
1124
|
-
"high"
|
|
1125
|
-
]
|
|
1126
|
-
}],
|
|
1127
|
-
"temperature": false,
|
|
1128
|
-
"tool_call": true,
|
|
1129
|
-
"attachment": true,
|
|
1130
|
-
"modalities": {
|
|
1131
|
-
"input": ["text", "image"],
|
|
1132
|
-
"output": ["text"]
|
|
1133
|
-
},
|
|
1134
|
-
"limit": {
|
|
1135
|
-
"context": 2e5,
|
|
1136
|
-
"output": 1e5
|
|
1137
|
-
},
|
|
1138
|
-
"release_date": "2025-06-10"
|
|
1139
|
-
},
|
|
1140
|
-
"gpt-5.3-chat-latest": {
|
|
1141
|
-
"id": "gpt-5.3-chat-latest",
|
|
1142
|
-
"name": "GPT-5.3 Chat (latest)",
|
|
1143
|
-
"family": "gpt",
|
|
1144
|
-
"reasoning": false,
|
|
1145
|
-
"temperature": true,
|
|
1146
|
-
"tool_call": true,
|
|
1147
|
-
"attachment": true,
|
|
1148
|
-
"modalities": {
|
|
1149
|
-
"input": ["text", "image"],
|
|
1150
|
-
"output": ["text"]
|
|
1151
|
-
},
|
|
1152
|
-
"limit": {
|
|
1153
|
-
"context": 128e3,
|
|
1154
|
-
"output": 16384
|
|
1155
|
-
},
|
|
1156
|
-
"release_date": "2026-03-03"
|
|
1157
|
-
},
|
|
1158
|
-
"gpt-5.5": {
|
|
1159
|
-
"id": "gpt-5.5",
|
|
1160
|
-
"name": "GPT-5.5",
|
|
1161
|
-
"family": "gpt",
|
|
1162
|
-
"reasoning": true,
|
|
1163
|
-
"reasoning_options": [{
|
|
1164
|
-
"type": "effort",
|
|
1165
|
-
"values": [
|
|
1166
|
-
"none",
|
|
1167
|
-
"low",
|
|
1168
|
-
"medium",
|
|
1169
|
-
"high",
|
|
1170
|
-
"xhigh"
|
|
1171
|
-
]
|
|
1172
|
-
}],
|
|
1173
|
-
"temperature": false,
|
|
1174
|
-
"tool_call": true,
|
|
1175
|
-
"attachment": true,
|
|
1176
|
-
"modalities": {
|
|
1177
|
-
"input": [
|
|
1178
|
-
"text",
|
|
1179
|
-
"image",
|
|
1180
|
-
"pdf"
|
|
1181
|
-
],
|
|
1182
|
-
"output": ["text"]
|
|
1183
|
-
},
|
|
1184
|
-
"limit": {
|
|
1185
|
-
"context": 105e4,
|
|
1186
|
-
"output": 128e3
|
|
1187
|
-
},
|
|
1188
|
-
"release_date": "2026-04-23"
|
|
1189
|
-
},
|
|
1190
|
-
"gpt-4o-2024-11-20": {
|
|
1191
|
-
"id": "gpt-4o-2024-11-20",
|
|
1192
|
-
"name": "GPT-4o (2024-11-20)",
|
|
1193
|
-
"family": "gpt",
|
|
1194
|
-
"reasoning": false,
|
|
1195
|
-
"temperature": true,
|
|
1196
|
-
"tool_call": true,
|
|
1197
|
-
"attachment": true,
|
|
1198
|
-
"modalities": {
|
|
1199
|
-
"input": ["text", "image"],
|
|
1200
|
-
"output": ["text"]
|
|
1201
|
-
},
|
|
1202
|
-
"limit": {
|
|
1203
|
-
"context": 128e3,
|
|
1204
|
-
"output": 16384
|
|
1205
|
-
},
|
|
1206
|
-
"release_date": "2024-11-20"
|
|
1207
|
-
}
|
|
1208
|
-
} },
|
|
1209
|
-
snapshotAt: Date.parse("2026-09-17")
|
|
1210
|
-
};
|
|
1211
|
-
//#endregion
|
|
1212
|
-
//#region src/facts.ts
|
|
1213
|
-
/** Parameter ranges and request limits for this provider wire. */
|
|
1214
|
-
const facts = {
|
|
1215
|
-
outputLimit: { support: "unsupported" },
|
|
1216
|
-
temperature: null,
|
|
1217
|
-
thinkingSwitch: false,
|
|
1218
|
-
limits: {
|
|
1219
|
-
requestBytes: 50331648,
|
|
1220
|
-
images: 100
|
|
1221
|
-
}
|
|
1222
|
-
};
|
|
1223
|
-
//#endregion
|
|
1224
|
-
//#region src/image-generation/model.ts
|
|
1225
|
-
/** The fixed subscription image model. */
|
|
1226
|
-
const IMAGE_MODEL = "gpt-image-2";
|
|
1227
|
-
/** Strict generation parameters; opaque output is the default. */
|
|
1228
|
-
const IMAGE_PARAMS_SCHEMA = z.object({ transparent_background: z.boolean().default(false) }).strict();
|
|
1229
|
-
/** Declares the image model's executable operations. */
|
|
1230
|
-
const IMAGE_GENERATION_MODEL = {
|
|
1231
|
-
id: IMAGE_MODEL,
|
|
1232
|
-
label: IMAGE_MODEL,
|
|
1233
|
-
outputKinds: ["image"],
|
|
1234
|
-
operations: [{
|
|
1235
|
-
id: "create",
|
|
1236
|
-
inputKinds: [],
|
|
1237
|
-
minInputs: 0,
|
|
1238
|
-
maxInputs: 0,
|
|
1239
|
-
paramsSchema: IMAGE_PARAMS_SCHEMA
|
|
1240
|
-
}, {
|
|
1241
|
-
id: "edit",
|
|
1242
|
-
inputKinds: ["image"],
|
|
1243
|
-
minInputs: 1,
|
|
1244
|
-
maxInputs: 5,
|
|
1245
|
-
paramsSchema: IMAGE_PARAMS_SCHEMA
|
|
1246
|
-
}]
|
|
1247
|
-
};
|
|
1248
|
-
//#endregion
|
|
1249
5
|
//#region src/failure.ts
|
|
1250
6
|
var LoginFailure = class extends Error {
|
|
1251
7
|
name = "LoginFailure";
|
|
@@ -1259,26 +15,10 @@ var LoginFailure = class extends Error {
|
|
|
1259
15
|
};
|
|
1260
16
|
//#endregion
|
|
1261
17
|
//#region src/oauth.ts
|
|
1262
|
-
/**
|
|
1263
|
-
* Signing a ChatGPT account in, and keeping its tokens fresh.
|
|
1264
|
-
*
|
|
1265
|
-
* The client is the Codex CLI's public one: it has no secret, so what stops
|
|
1266
|
-
* an intercepted authorization code from being spent is PKCE alone. The
|
|
1267
|
-
* addresses and the request shapes are the ones the Codex CLI and opencode
|
|
1268
|
-
* use; none of them is a published contract, and each was verified against a
|
|
1269
|
-
* Pro account on 2026-09-24.
|
|
1270
|
-
*
|
|
1271
|
-
* Every function here takes the addresses it reaches as an argument, so a
|
|
1272
|
-
* test points them at a server of its own.
|
|
1273
|
-
*/
|
|
1274
18
|
const CLIENT_ID = "app_EMoamEEZ73f0CkXaXp7hrann";
|
|
1275
|
-
/** Who this client says it is, on the authorization and on every call. */
|
|
1276
19
|
const ORIGINATOR = "yaoguang";
|
|
1277
20
|
const CALLBACK_PATH = "/auth/callback";
|
|
1278
|
-
/** The listing answers only models whose minimal client version this reaches. */
|
|
1279
21
|
const CODEX_CLIENT_VERSION = "1.0.0";
|
|
1280
|
-
/** The reasoning efforts the endpoint accepts. The listing names more
|
|
1281
|
-
* (`ultra`), which the endpoint refuses. */
|
|
1282
22
|
const ACCEPTED_EFFORTS = [
|
|
1283
23
|
"none",
|
|
1284
24
|
"minimal",
|
|
@@ -1290,7 +30,6 @@ const ACCEPTED_EFFORTS = [
|
|
|
1290
30
|
];
|
|
1291
31
|
const SCOPE = "openid profile email offline_access";
|
|
1292
32
|
const REQUEST_TIMEOUT_MS = 3e4;
|
|
1293
|
-
/** How long before expiry a token without `earliest_refresh_at` is refreshed. */
|
|
1294
33
|
const REFRESH_AHEAD_MS = 6e4;
|
|
1295
34
|
const ENDPOINTS = {
|
|
1296
35
|
issuer: "https://auth.openai.com",
|
|
@@ -1337,16 +76,9 @@ function authClaim(claims, key) {
|
|
|
1337
76
|
const value = (typeof nested === "object" && nested !== null ? nested[key] : void 0) ?? claims?.[key];
|
|
1338
77
|
return typeof value === "string" && value !== "" ? value : void 0;
|
|
1339
78
|
}
|
|
1340
|
-
/** Who signed in, as a person reads it: the email, else the account id's
|
|
1341
|
-
* last four characters. */
|
|
1342
79
|
function accountLabel(email, accountId) {
|
|
1343
|
-
return email ??
|
|
80
|
+
return email ?? `\u00b7\u00b7\u00b7\u00b7${accountId.slice(-4)}`;
|
|
1344
81
|
}
|
|
1345
|
-
/**
|
|
1346
|
-
* The tokens an exchange or a refresh answered, as they are stored. `before`
|
|
1347
|
-
* is the credential being refreshed: a refresh that answers no id token keeps
|
|
1348
|
-
* the account it had.
|
|
1349
|
-
*/
|
|
1350
82
|
function storedFrom(body, now, before) {
|
|
1351
83
|
const access = body.access_token;
|
|
1352
84
|
const refresh = body.refresh_token ?? before?.refresh;
|
|
@@ -1378,7 +110,6 @@ function parseStored(credential) {
|
|
|
1378
110
|
return;
|
|
1379
111
|
}
|
|
1380
112
|
}
|
|
1381
|
-
/** UTC milliseconds when the host should refresh this credential. */
|
|
1382
113
|
function refreshAfterOf(tokens) {
|
|
1383
114
|
const expiresAt = Number(tokens.expiresAt) - REFRESH_AHEAD_MS;
|
|
1384
115
|
const earliest = tokens.earliestRefreshAt === void 0 ? expiresAt : Number(tokens.earliestRefreshAt);
|
|
@@ -1392,7 +123,6 @@ async function postForm(fetch, url, form, signal) {
|
|
|
1392
123
|
signal: signal === void 0 ? AbortSignal.timeout(REQUEST_TIMEOUT_MS) : AbortSignal.any([signal, AbortSignal.timeout(REQUEST_TIMEOUT_MS)])
|
|
1393
124
|
});
|
|
1394
125
|
}
|
|
1395
|
-
/** Spends an authorization code. Rejects with `exchange-failed`. */
|
|
1396
126
|
async function exchangeCode(fetch, endpoints, input, now, signal) {
|
|
1397
127
|
let response;
|
|
1398
128
|
try {
|
|
@@ -1441,11 +171,286 @@ async function refreshTokens(fetch, endpoints, before, now, signal) {
|
|
|
1441
171
|
};
|
|
1442
172
|
}
|
|
1443
173
|
//#endregion
|
|
174
|
+
//#region src/subscription-models.json
|
|
175
|
+
var verifiedAt$1 = "2026-10-29";
|
|
176
|
+
var models = [
|
|
177
|
+
{
|
|
178
|
+
"model": "gpt-6-astra",
|
|
179
|
+
"name": "GPT-6-Astra",
|
|
180
|
+
"context": 272e3,
|
|
181
|
+
"inputModalities": ["text", "image"],
|
|
182
|
+
"efforts": [
|
|
183
|
+
"low",
|
|
184
|
+
"medium",
|
|
185
|
+
"high",
|
|
186
|
+
"xhigh",
|
|
187
|
+
"max",
|
|
188
|
+
"ultra"
|
|
189
|
+
],
|
|
190
|
+
"family": "gpt-astra",
|
|
191
|
+
"releaseDate": "2026-09-03",
|
|
192
|
+
"releaseDateSource": "https://developers.openai.com/api/docs/changelog",
|
|
193
|
+
"supportsParallelToolCalls": true
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
"model": "gpt-6.1-sol",
|
|
197
|
+
"name": "GPT-6.1-Sol",
|
|
198
|
+
"context": 5e5,
|
|
199
|
+
"inputModalities": ["text", "image"],
|
|
200
|
+
"efforts": [
|
|
201
|
+
"low",
|
|
202
|
+
"medium",
|
|
203
|
+
"high",
|
|
204
|
+
"xhigh",
|
|
205
|
+
"max",
|
|
206
|
+
"ultra"
|
|
207
|
+
],
|
|
208
|
+
"contextSource": "https://developers.openai.com/api/docs/models/gpt-6.1-sol",
|
|
209
|
+
"bundledContext": 272e3,
|
|
210
|
+
"family": "gpt-sol",
|
|
211
|
+
"releaseDate": "2026-09-29",
|
|
212
|
+
"releaseDateSource": "https://developers.openai.com/api/docs/changelog",
|
|
213
|
+
"supportsParallelToolCalls": true
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
"model": "gpt-6.1-terra",
|
|
217
|
+
"name": "GPT-6.1 Terra",
|
|
218
|
+
"context": 5e5,
|
|
219
|
+
"inputModalities": ["text", "image"],
|
|
220
|
+
"efforts": [
|
|
221
|
+
"low",
|
|
222
|
+
"medium",
|
|
223
|
+
"high",
|
|
224
|
+
"xhigh",
|
|
225
|
+
"max",
|
|
226
|
+
"ultra"
|
|
227
|
+
],
|
|
228
|
+
"family": "gpt-terra",
|
|
229
|
+
"releaseDate": "2026-10-26",
|
|
230
|
+
"releaseDateSource": "https://developers.openai.com/api/docs/changelog",
|
|
231
|
+
"supportsParallelToolCalls": true
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
"model": "gpt-6-sol",
|
|
235
|
+
"name": "GPT-6-Sol",
|
|
236
|
+
"context": 272e3,
|
|
237
|
+
"inputModalities": ["text", "image"],
|
|
238
|
+
"efforts": [
|
|
239
|
+
"low",
|
|
240
|
+
"medium",
|
|
241
|
+
"high",
|
|
242
|
+
"xhigh",
|
|
243
|
+
"max",
|
|
244
|
+
"ultra"
|
|
245
|
+
],
|
|
246
|
+
"family": "gpt-sol",
|
|
247
|
+
"releaseDate": "2026-09-22",
|
|
248
|
+
"releaseDateSource": "https://developers.openai.com/api/docs/changelog",
|
|
249
|
+
"supportsParallelToolCalls": true
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
"model": "gpt-6-luna",
|
|
253
|
+
"name": "GPT-6-Luna",
|
|
254
|
+
"context": 272e3,
|
|
255
|
+
"inputModalities": ["text", "image"],
|
|
256
|
+
"efforts": [
|
|
257
|
+
"low",
|
|
258
|
+
"medium",
|
|
259
|
+
"high",
|
|
260
|
+
"xhigh",
|
|
261
|
+
"max"
|
|
262
|
+
],
|
|
263
|
+
"family": "gpt-luna",
|
|
264
|
+
"releaseDate": "2026-09-22",
|
|
265
|
+
"releaseDateSource": "https://developers.openai.com/api/docs/changelog",
|
|
266
|
+
"supportsParallelToolCalls": true
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
"model": "gpt-5.6-sol",
|
|
270
|
+
"name": "GPT-5.6-Sol",
|
|
271
|
+
"context": 272e3,
|
|
272
|
+
"inputModalities": ["text", "image"],
|
|
273
|
+
"efforts": [
|
|
274
|
+
"low",
|
|
275
|
+
"medium",
|
|
276
|
+
"high",
|
|
277
|
+
"xhigh",
|
|
278
|
+
"max",
|
|
279
|
+
"ultra"
|
|
280
|
+
],
|
|
281
|
+
"family": "gpt-sol",
|
|
282
|
+
"releaseDate": "2026-07-09",
|
|
283
|
+
"releaseDateSource": "https://developers.openai.com/api/docs/changelog",
|
|
284
|
+
"supportsParallelToolCalls": true
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
"model": "gpt-5.6-terra",
|
|
288
|
+
"name": "GPT-5.6-Terra",
|
|
289
|
+
"context": 272e3,
|
|
290
|
+
"inputModalities": ["text", "image"],
|
|
291
|
+
"efforts": [
|
|
292
|
+
"low",
|
|
293
|
+
"medium",
|
|
294
|
+
"high",
|
|
295
|
+
"xhigh",
|
|
296
|
+
"max",
|
|
297
|
+
"ultra"
|
|
298
|
+
],
|
|
299
|
+
"family": "gpt-terra",
|
|
300
|
+
"releaseDate": "2026-07-09",
|
|
301
|
+
"releaseDateSource": "https://developers.openai.com/api/docs/changelog",
|
|
302
|
+
"supportsParallelToolCalls": true
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
"model": "gpt-5.6-luna",
|
|
306
|
+
"name": "GPT-5.6-Luna",
|
|
307
|
+
"context": 272e3,
|
|
308
|
+
"inputModalities": ["text", "image"],
|
|
309
|
+
"efforts": [
|
|
310
|
+
"low",
|
|
311
|
+
"medium",
|
|
312
|
+
"high",
|
|
313
|
+
"xhigh",
|
|
314
|
+
"max"
|
|
315
|
+
],
|
|
316
|
+
"family": "gpt-luna",
|
|
317
|
+
"releaseDate": "2026-07-09",
|
|
318
|
+
"releaseDateSource": "https://developers.openai.com/api/docs/changelog",
|
|
319
|
+
"supportsParallelToolCalls": true
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
"model": "gpt-5.5",
|
|
323
|
+
"name": "GPT-5.5",
|
|
324
|
+
"context": 272e3,
|
|
325
|
+
"inputModalities": ["text", "image"],
|
|
326
|
+
"efforts": [
|
|
327
|
+
"low",
|
|
328
|
+
"medium",
|
|
329
|
+
"high",
|
|
330
|
+
"xhigh"
|
|
331
|
+
],
|
|
332
|
+
"family": "gpt",
|
|
333
|
+
"releaseDate": "2026-04-24",
|
|
334
|
+
"releaseDateSource": "https://developers.openai.com/api/docs/changelog",
|
|
335
|
+
"supportsParallelToolCalls": true
|
|
336
|
+
}
|
|
337
|
+
];
|
|
338
|
+
//#endregion
|
|
339
|
+
//#region src/facts.ts
|
|
340
|
+
const facts = {
|
|
341
|
+
outputLimit: { support: "unsupported" },
|
|
342
|
+
temperature: null,
|
|
343
|
+
thinkingSwitch: false,
|
|
344
|
+
limits: {
|
|
345
|
+
requestBytes: 50331648,
|
|
346
|
+
images: 100
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
const modelFacts = {
|
|
350
|
+
revisions: [],
|
|
351
|
+
presets: models.map((one) => ({
|
|
352
|
+
model: one.model,
|
|
353
|
+
entry: {
|
|
354
|
+
name: one.name,
|
|
355
|
+
family: one.family,
|
|
356
|
+
release_date: one.releaseDate,
|
|
357
|
+
chat: true,
|
|
358
|
+
tool_call: one.supportsParallelToolCalls,
|
|
359
|
+
reasoning: true,
|
|
360
|
+
reasoning_options: [{
|
|
361
|
+
type: "effort",
|
|
362
|
+
values: one.efforts.filter((effort) => ACCEPTED_EFFORTS.includes(effort))
|
|
363
|
+
}],
|
|
364
|
+
modalities: {
|
|
365
|
+
input: one.inputModalities,
|
|
366
|
+
output: ["text"]
|
|
367
|
+
},
|
|
368
|
+
limit: { context: one.context }
|
|
369
|
+
}
|
|
370
|
+
}))
|
|
371
|
+
};
|
|
372
|
+
//#endregion
|
|
373
|
+
//#region src/catalog.ts
|
|
374
|
+
const catalog = {
|
|
375
|
+
vendors: [{
|
|
376
|
+
kind: "vendor",
|
|
377
|
+
id: "chatgpt",
|
|
378
|
+
logo: "data:image/svg+xml,%3Csvg%20fill%3D%22currentColor%22%20fill-rule%3D%22evenodd%22%20height%3D%2224%22%20style%3D%22flex%3Anone%3Bline-height%3A1%22%20viewBox%3D%220%200%2024%2024%22%20width%3D%2224%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Ctitle%3EOpenAI%3C%2Ftitle%3E%3Cpath%20d%3D%22M9.205%208.658v-2.26c0-.19.072-.333.238-.428l4.543-2.616c.619-.357%201.356-.523%202.117-.523%202.854%200%204.662%202.212%204.662%204.566%200%20.167%200%20.357-.024.547l-4.71-2.759a.797.797%200%2000-.856%200l-5.97%203.473zm10.609%208.8V12.06c0-.333-.143-.57-.429-.737l-5.97-3.473%201.95-1.118a.433.433%200%2001.476%200l4.543%202.617c1.309.76%202.189%202.378%202.189%203.948%200%201.808-1.07%203.473-2.76%204.163zM7.802%2012.703l-1.95-1.142c-.167-.095-.239-.238-.239-.428V5.899c0-2.545%201.95-4.472%204.591-4.472%201%200%201.927.333%202.712.928L8.23%205.067c-.285.166-.428.404-.428.737v6.898zM12%2015.128l-2.795-1.57v-3.33L12%208.658l2.795%201.57v3.33L12%2015.128zm1.796%207.23c-1%200-1.927-.332-2.712-.927l4.686-2.712c.285-.166.428-.404.428-.737v-6.898l1.974%201.142c.167.095.238.238.238.428v5.233c0%202.545-1.974%204.472-4.614%204.472zm-5.637-5.303l-4.544-2.617c-1.308-.761-2.188-2.378-2.188-3.948A4.482%204.482%200%20014.21%206.327v5.423c0%20.333.143.571.428.738l5.947%203.449-1.95%201.118a.432.432%200%2001-.476%200zm-.262%203.9c-2.688%200-4.662-2.021-4.662-4.519%200-.19.024-.38.047-.57l4.686%202.71c.286.167.571.167.856%200l5.97-3.448v2.26c0%20.19-.07.333-.237.428l-4.543%202.616c-.619.357-1.356.523-2.117.523zm5.899%202.83a5.947%205.947%200%20005.827-4.756C22.287%2018.339%2024%2015.84%2024%2013.296c0-1.665-.713-3.282-1.998-4.448.119-.5.19-.999.19-1.498%200-3.401-2.759-5.947-5.946-5.947-.642%200-1.26.095-1.88.31A5.962%205.962%200%200010.205%200a5.947%205.947%200%2000-5.827%204.757C1.713%205.447%200%207.945%200%2010.49c0%201.666.713%203.283%201.998%204.448-.119.5-.19%201-.19%201.499%200%203.401%202.759%205.946%205.946%205.946.642%200%201.26-.095%201.88-.309a5.96%205.96%200%20004.162%201.713z%22%3E%3C%2Fpath%3E%3C%2Fsvg%3E",
|
|
379
|
+
name: "ChatGPT",
|
|
380
|
+
region: null,
|
|
381
|
+
market: "international",
|
|
382
|
+
catalogKey: "chatgpt",
|
|
383
|
+
canListModels: true,
|
|
384
|
+
endpoints: [{
|
|
385
|
+
type: "chatgpt",
|
|
386
|
+
endpointId: "subscription",
|
|
387
|
+
protocolIds: ["chatgpt-subscription"],
|
|
388
|
+
baseUrl: "https://chatgpt.com/backend-api/codex"
|
|
389
|
+
}]
|
|
390
|
+
}],
|
|
391
|
+
snapshot: {},
|
|
392
|
+
snapshotAt: Date.parse(verifiedAt$1)
|
|
393
|
+
};
|
|
394
|
+
//#endregion
|
|
395
|
+
//#region src/image-generation/model.ts
|
|
396
|
+
const IMAGE_MODEL = "gpt-image-2";
|
|
397
|
+
const IMAGE_PARAMS_SCHEMA = z.object({ transparent_background: z.boolean().default(false).meta({ presentation: { label: {
|
|
398
|
+
"en-US": "Transparent background",
|
|
399
|
+
"zh-CN": "\u900f\u660e\u80cc\u666f"
|
|
400
|
+
} } }) }).strict();
|
|
401
|
+
function imageModelOf(id) {
|
|
402
|
+
return {
|
|
403
|
+
id,
|
|
404
|
+
label: id,
|
|
405
|
+
outputKinds: ["image"],
|
|
406
|
+
operations: [{
|
|
407
|
+
id: "create",
|
|
408
|
+
inputKinds: [],
|
|
409
|
+
minInputs: 0,
|
|
410
|
+
maxInputs: 0,
|
|
411
|
+
paramsSchema: IMAGE_PARAMS_SCHEMA
|
|
412
|
+
}, {
|
|
413
|
+
id: "edit",
|
|
414
|
+
inputKinds: ["image"],
|
|
415
|
+
minInputs: 1,
|
|
416
|
+
maxInputs: 5,
|
|
417
|
+
paramsSchema: IMAGE_PARAMS_SCHEMA
|
|
418
|
+
}]
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
const IMAGE_GENERATION_MODELS = [
|
|
422
|
+
imageModelOf(IMAGE_MODEL),
|
|
423
|
+
imageModelOf("gpt-image-2.5-sunburst"),
|
|
424
|
+
imageModelOf("gpt-image-2.5-flare")
|
|
425
|
+
];
|
|
426
|
+
//#endregion
|
|
1444
427
|
//#region src/image-generation/client.ts
|
|
1445
428
|
const responseSchema = z.object({
|
|
1446
429
|
data: z.array(z.unknown()).min(1),
|
|
1447
430
|
background: z.enum(["opaque", "transparent"]).optional()
|
|
1448
431
|
});
|
|
432
|
+
const usageSchema = z.object({
|
|
433
|
+
input_tokens: z.number().int().nonnegative().optional(),
|
|
434
|
+
output_tokens: z.number().int().nonnegative().optional(),
|
|
435
|
+
total_tokens: z.number().int().nonnegative().optional()
|
|
436
|
+
});
|
|
437
|
+
function usageOf(text) {
|
|
438
|
+
let raw;
|
|
439
|
+
try {
|
|
440
|
+
raw = JSON.parse(text)?.usage;
|
|
441
|
+
} catch {
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
const parsed = usageSchema.safeParse(raw);
|
|
445
|
+
if (!parsed.success) return void 0;
|
|
446
|
+
const { input_tokens, output_tokens, total_tokens } = parsed.data;
|
|
447
|
+
const usage = {
|
|
448
|
+
...input_tokens === void 0 ? {} : { inputTokens: input_tokens },
|
|
449
|
+
...output_tokens === void 0 ? {} : { outputTokens: output_tokens },
|
|
450
|
+
...total_tokens === void 0 ? {} : { totalTokens: total_tokens }
|
|
451
|
+
};
|
|
452
|
+
return Object.keys(usage).length ? usage : void 0;
|
|
453
|
+
}
|
|
1449
454
|
const itemSchema = z.object({ b64_json: z.string() });
|
|
1450
455
|
const RESPONSE_LIMIT = 41943040;
|
|
1451
456
|
const PNG_SIGNATURE = Buffer.from([
|
|
@@ -1464,21 +469,13 @@ const errorSchema = z.object({ error: z.object({
|
|
|
1464
469
|
limit_id: z.string().optional(),
|
|
1465
470
|
resets_at: z.number().int().optional()
|
|
1466
471
|
}) });
|
|
1467
|
-
/** A body-only provider failure with explicit submission and delivery knowledge. */
|
|
1468
472
|
var ImageGenerationFailure = class extends Error {
|
|
1469
|
-
/** Public failure discriminator. */
|
|
1470
473
|
name = "GenerationFailure";
|
|
1471
|
-
/** Normalized failure category. */
|
|
1472
474
|
code;
|
|
1473
|
-
/** Remote submission and local delivery knowledge. */
|
|
1474
475
|
resultState;
|
|
1475
|
-
/** Provider response status, when available. */
|
|
1476
476
|
status;
|
|
1477
|
-
/** Explicit provider reset time in UTC epoch milliseconds. */
|
|
1478
477
|
retryAt;
|
|
1479
|
-
/** Bounded provider body with known access and refresh tokens removed. */
|
|
1480
478
|
providerText;
|
|
1481
|
-
/** Creates a failure without copying HTTP headers. */
|
|
1482
479
|
constructor(code, message, resultState, metadata = {}) {
|
|
1483
480
|
super(message);
|
|
1484
481
|
this.code = code;
|
|
@@ -1488,7 +485,6 @@ var ImageGenerationFailure = class extends Error {
|
|
|
1488
485
|
this.providerText = metadata.providerText;
|
|
1489
486
|
}
|
|
1490
487
|
};
|
|
1491
|
-
/** Sends exactly one JSON POST and decodes the first inline image. */
|
|
1492
488
|
async function submitImage(options, submission, signal) {
|
|
1493
489
|
if (signal.aborted) await withImageSignal(async () => {}, signal, "not-submitted");
|
|
1494
490
|
let response;
|
|
@@ -1513,6 +509,7 @@ async function submitImage(options, submission, signal) {
|
|
|
1513
509
|
if (error instanceof ImageGenerationFailure) throw error;
|
|
1514
510
|
throw new ImageGenerationFailure("network", "ChatGPT image request failed; its remote result is unknown", "unknown");
|
|
1515
511
|
}
|
|
512
|
+
submission.onSubmitted?.();
|
|
1516
513
|
if (response.status === 401) {
|
|
1517
514
|
response.body?.cancel().catch(() => {});
|
|
1518
515
|
throw new ImageGenerationFailure("expired", "ChatGPT sign-in expired; sign in again in model settings (status 401)", "unknown", { status: 401 });
|
|
@@ -1538,6 +535,8 @@ async function submitImage(options, submission, signal) {
|
|
|
1538
535
|
providerText: providerText.slice(0, 512)
|
|
1539
536
|
});
|
|
1540
537
|
}
|
|
538
|
+
const usage = usageOf(text);
|
|
539
|
+
if (usage) submission.onUsage?.(usage);
|
|
1541
540
|
let parsed;
|
|
1542
541
|
let item;
|
|
1543
542
|
try {
|
|
@@ -1589,7 +588,6 @@ async function readResponse(response, signal) {
|
|
|
1589
588
|
reader.releaseLock();
|
|
1590
589
|
}
|
|
1591
590
|
}
|
|
1592
|
-
/** Ends a provider wait promptly on abort without claiming that its remote work stopped. */
|
|
1593
591
|
async function withImageSignal(work, signal, resultState) {
|
|
1594
592
|
const aborted = () => new ImageGenerationFailure(signal.reason instanceof Error && signal.reason.name === "TimeoutError" ? "timeout" : "cancelled", signal.reason instanceof Error && signal.reason.name === "TimeoutError" ? "Image generation timed out" : "Image generation was cancelled", resultState);
|
|
1595
593
|
if (signal.aborted) throw aborted();
|
|
@@ -1606,7 +604,6 @@ async function withImageSignal(work, signal, resultState) {
|
|
|
1606
604
|
}
|
|
1607
605
|
//#endregion
|
|
1608
606
|
//#region src/image-generation/port.ts
|
|
1609
|
-
/** Creates an image port without network activity or retaining call credentials. */
|
|
1610
607
|
function createImageGenerationPort(options) {
|
|
1611
608
|
return { async generate(request, signal) {
|
|
1612
609
|
await withImageSignal(async () => {}, signal, "not-submitted");
|
|
@@ -1661,7 +658,7 @@ function createImageGenerationPort(options) {
|
|
|
1661
658
|
images.push({ image_url: `data:${input.mediaType};base64,${Buffer.concat(chunks).toString("base64")}` });
|
|
1662
659
|
}
|
|
1663
660
|
const body = JSON.stringify({
|
|
1664
|
-
model:
|
|
661
|
+
model: options.model,
|
|
1665
662
|
prompt,
|
|
1666
663
|
background: params.transparent_background ? "transparent" : "opaque",
|
|
1667
664
|
quality: "auto",
|
|
@@ -1669,60 +666,67 @@ function createImageGenerationPort(options) {
|
|
|
1669
666
|
...request.operation === "edit" ? { images } : {}
|
|
1670
667
|
});
|
|
1671
668
|
if (Buffer.byteLength(body, "utf8") > 50331648) throw new ImageGenerationFailure("too-large", "Encoded image request exceeds 48 MiB", "not-submitted");
|
|
1672
|
-
|
|
669
|
+
const accounting = options.accountingDispatch?.attempt(0);
|
|
670
|
+
let outcome = "failed";
|
|
671
|
+
let submission = "unknown";
|
|
1673
672
|
try {
|
|
1674
|
-
image
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
673
|
+
let image;
|
|
674
|
+
try {
|
|
675
|
+
image = await submitImage(options, {
|
|
676
|
+
operation,
|
|
677
|
+
body,
|
|
678
|
+
callId: request.identity.callId,
|
|
679
|
+
tokens,
|
|
680
|
+
onSubmitted: () => {
|
|
681
|
+
submission = "submitted";
|
|
682
|
+
},
|
|
683
|
+
onUsage: (usage) => accounting?.report({
|
|
684
|
+
sequence: 1,
|
|
685
|
+
...usage
|
|
686
|
+
})
|
|
687
|
+
}, signal);
|
|
688
|
+
} catch (error) {
|
|
689
|
+
if (error instanceof ImageGenerationFailure && error.code === "expired") login.expire(credential.credential);
|
|
690
|
+
throw error;
|
|
691
|
+
}
|
|
692
|
+
const { bytes, background } = image;
|
|
693
|
+
const expectedBackground = params.transparent_background ? "transparent" : "opaque";
|
|
694
|
+
if (background !== void 0 && background !== expectedBackground) throw new ImageGenerationFailure("invalid-output", "ChatGPT did not satisfy the requested background", "not-delivered");
|
|
695
|
+
let info;
|
|
696
|
+
try {
|
|
697
|
+
info = await withImageSignal(() => options.imageInfo(bytes, signal), signal, "unknown");
|
|
698
|
+
} catch (error) {
|
|
699
|
+
if (error instanceof ImageGenerationFailure) throw error;
|
|
700
|
+
throw new ImageGenerationFailure("invalid-output", "ChatGPT returned an undecodable PNG", "not-delivered");
|
|
701
|
+
}
|
|
702
|
+
if (!Number.isSafeInteger(info.width) || !Number.isSafeInteger(info.height) || info.width <= 0 || info.height <= 0 || info.width > 1e4 || info.height > 1e4 || info.mediaType !== "image/png" || info.hasTransparentPixels !== params.transparent_background || params.transparent_background && !info.hasAlpha) throw new ImageGenerationFailure("invalid-output", "ChatGPT did not satisfy the requested background", "not-delivered");
|
|
703
|
+
outcome = "success";
|
|
704
|
+
return { assets: [{
|
|
705
|
+
mediaType: "image/png",
|
|
706
|
+
name: "generated-image.png",
|
|
707
|
+
body: (async function* () {
|
|
708
|
+
yield bytes;
|
|
709
|
+
})()
|
|
710
|
+
}] };
|
|
711
|
+
} finally {
|
|
712
|
+
accounting?.end({
|
|
713
|
+
outcome: signal.aborted ? "cancelled" : outcome,
|
|
714
|
+
submission
|
|
715
|
+
});
|
|
1693
716
|
}
|
|
1694
|
-
if (!Number.isSafeInteger(info.width) || !Number.isSafeInteger(info.height) || info.width <= 0 || info.height <= 0 || info.width > 1e4 || info.height > 1e4 || info.mediaType !== "image/png" || info.hasTransparentPixels !== params.transparent_background || params.transparent_background && !info.hasAlpha) throw new ImageGenerationFailure("invalid-output", "ChatGPT did not satisfy the requested background", "not-delivered");
|
|
1695
|
-
return { assets: [{
|
|
1696
|
-
mediaType: "image/png",
|
|
1697
|
-
name: "generated-image.png",
|
|
1698
|
-
body: (async function* () {
|
|
1699
|
-
yield bytes;
|
|
1700
|
-
})()
|
|
1701
|
-
}] };
|
|
1702
717
|
} };
|
|
1703
718
|
}
|
|
1704
719
|
//#endregion
|
|
1705
720
|
//#region src/errors.ts
|
|
1706
721
|
const failureKindOf = (status) => status === 413 ? "request-too-large" : void 0;
|
|
1707
|
-
/** Same shape as the other adapters' port error, and `authored`: every
|
|
1708
|
-
* message this module builds is written here, from fixed words, a status
|
|
1709
|
-
* and a code matched against a fixed spelling, so the runtime may show it
|
|
1710
|
-
* as it stands. */
|
|
1711
722
|
var ModelCallError = class extends Error {
|
|
1712
|
-
/** Stable fact selected by this local producer, independent of display text. */
|
|
1713
723
|
failureCode;
|
|
1714
724
|
status;
|
|
1715
725
|
retryable;
|
|
1716
726
|
authored = true;
|
|
1717
|
-
/** The endpoint's own error body, unredacted, on a refusal this module did
|
|
1718
|
-
* not recognise. The runtime's guard removes every credential of the
|
|
1719
|
-
* endpoint from it before it reaches a reason. */
|
|
1720
727
|
providerText;
|
|
1721
|
-
/** How long the endpoint asked to wait before trying again, when it said. */
|
|
1722
728
|
retryAfterMs;
|
|
1723
|
-
/** The endpoint's error code, matched against a fixed spelling. */
|
|
1724
729
|
code;
|
|
1725
|
-
/** What the status alone says the refusal is (`failureKindOf`). */
|
|
1726
730
|
kind;
|
|
1727
731
|
constructor(message, options) {
|
|
1728
732
|
super(message);
|
|
@@ -1773,7 +777,6 @@ function resetOf(body) {
|
|
|
1773
777
|
const at = Number(body.error?.resets_at);
|
|
1774
778
|
return Number.isFinite(at) && at > 0 ? `; resets ${(/* @__PURE__ */ new Date(at * 1e3)).toISOString()}` : "";
|
|
1775
779
|
}
|
|
1776
|
-
/** A refused HTTP answer, read into a port error. */
|
|
1777
780
|
function toPortError(status, text) {
|
|
1778
781
|
let body = {};
|
|
1779
782
|
try {
|
|
@@ -1796,7 +799,7 @@ function toPortError(status, text) {
|
|
|
1796
799
|
retryable: false
|
|
1797
800
|
});
|
|
1798
801
|
if (code === "context_length_exceeded") return new ModelCallError(`input exceeds the model's context window ${at}`, {
|
|
1799
|
-
failureCode: "context-
|
|
802
|
+
failureCode: "context-window-exceeded",
|
|
1800
803
|
code,
|
|
1801
804
|
status,
|
|
1802
805
|
retryable: false
|
|
@@ -1814,15 +817,11 @@ function toPortError(status, text) {
|
|
|
1814
817
|
...text.trim() === "" ? {} : { providerText: text }
|
|
1815
818
|
});
|
|
1816
819
|
}
|
|
1817
|
-
/** A failure that is not an HTTP answer: a dropped connection, a body that
|
|
1818
|
-
* could not be read — worth a second attempt. Its message comes from this
|
|
1819
|
-
* side, never the network. */
|
|
1820
820
|
function toCallError(error) {
|
|
1821
821
|
if (error instanceof ModelCallError) return error;
|
|
1822
822
|
const name = error instanceof Error ? error.name : "";
|
|
1823
|
-
return new ModelCallError(`ChatGPT call failed${name === "" ? "" : ` (${name})`}`, { retryable:
|
|
823
|
+
return new ModelCallError(`ChatGPT call failed${name === "" ? "" : ` (${name})`}`, { retryable: false });
|
|
1824
824
|
}
|
|
1825
|
-
/** Codes a `response.failed` carries that a second attempt cannot change. */
|
|
1826
825
|
const FINAL_CODES = /* @__PURE__ */ new Set([
|
|
1827
826
|
"context_length_exceeded",
|
|
1828
827
|
"insufficient_quota",
|
|
@@ -1833,7 +832,6 @@ const FINAL_CODES = /* @__PURE__ */ new Set([
|
|
|
1833
832
|
"bio_policy",
|
|
1834
833
|
"misalignment_policy_violation"
|
|
1835
834
|
]);
|
|
1836
|
-
/** `try again in 1.5s` / `in 250ms`: the wait a rate-limit message names. */
|
|
1837
835
|
function waitIn(message) {
|
|
1838
836
|
if (typeof message !== "string") return void 0;
|
|
1839
837
|
const match = /try again in\s*(\d+(?:\.\d+)?)\s*(s|ms|seconds?)\b/i.exec(message);
|
|
@@ -1842,25 +840,22 @@ function waitIn(message) {
|
|
|
1842
840
|
const milliseconds = match[2]?.toLowerCase() === "ms" ? value : value * 1e3;
|
|
1843
841
|
return Number.isFinite(milliseconds) && milliseconds >= 0 ? milliseconds : void 0;
|
|
1844
842
|
}
|
|
1845
|
-
/**
|
|
1846
|
-
* A `response.failed` event, read into a port error: rate limits, overload
|
|
1847
|
-
* and unclassified server errors are retried — a rate limit after the wait
|
|
1848
|
-
* its message names — while an oversized input, a spent quota and a policy
|
|
1849
|
-
* refusal are final. Only the code travels; the message is read for the wait.
|
|
1850
|
-
*/
|
|
1851
843
|
function toFailedError(failure) {
|
|
1852
844
|
const code = typeof failure.code === "string" && SAFE_CODES.has(failure.code) ? failure.code : void 0;
|
|
1853
845
|
const retryAfterMs = code === "rate_limit_exceeded" ? waitIn(failure.message) : void 0;
|
|
1854
846
|
return new ModelCallError(`ChatGPT response failed${code === void 0 ? "" : ` (code ${code})`}`, {
|
|
1855
|
-
failureCode: code === "context_length_exceeded" ? "context-
|
|
847
|
+
failureCode: code === "context_length_exceeded" ? "context-window-exceeded" : code === "insufficient_quota" || code === "usage_limit_reached" ? "quota-exceeded" : code === "usage_not_included" ? "model-unavailable" : "provider-error",
|
|
1856
848
|
retryable: code === void 0 || !FINAL_CODES.has(code),
|
|
1857
849
|
...code === void 0 ? {} : { code },
|
|
1858
850
|
...retryAfterMs === void 0 ? {} : { retryAfterMs }
|
|
1859
851
|
});
|
|
1860
852
|
}
|
|
1861
|
-
|
|
1862
|
-
function toModelFailure(error, failures) {
|
|
853
|
+
function toModelFailure(error, failures, transportFailure) {
|
|
1863
854
|
if (failures.owns(error)) return error;
|
|
855
|
+
if (!(error instanceof ModelCallError)) {
|
|
856
|
+
const transport = transportFailure?.(error);
|
|
857
|
+
if (transport !== void 0) return transport;
|
|
858
|
+
}
|
|
1864
859
|
const converted = toCallError(error);
|
|
1865
860
|
const known = error instanceof ModelCallError;
|
|
1866
861
|
const code = converted.code;
|
|
@@ -1882,33 +877,18 @@ function toModelFailure(error, failures) {
|
|
|
1882
877
|
const status = Number.isInteger(converted.status) && Number(converted.status) >= 100 && Number(converted.status) <= 599 ? converted.status : void 0;
|
|
1883
878
|
return failures.create({
|
|
1884
879
|
code: diagnosis,
|
|
1885
|
-
stage: diagnosis === "unknown" ? "unknown" : diagnosis.startsWith("authentication") || diagnosis === "request-too-large" ? "request" : status !== void 0 ? "transport" : diagnosis === "response-invalid" ? "response-validation" : "stream",
|
|
1886
|
-
category: diagnosis === "unknown" ? "unknown" : diagnosis === "stream-interrupted" ? "network" : diagnosis === "response-invalid" ? "protocol" : diagnosis === "request-too-large" ? "request-too-large" : "provider",
|
|
880
|
+
stage: diagnosis === "unknown" ? "unknown" : diagnosis.startsWith("authentication") || diagnosis === "request-too-large" || diagnosis === "context-window-exceeded" ? "request" : status !== void 0 ? "transport" : diagnosis === "response-invalid" ? "response-validation" : "stream",
|
|
881
|
+
category: diagnosis === "unknown" ? "unknown" : diagnosis === "stream-interrupted" ? "network" : diagnosis === "response-invalid" ? "protocol" : diagnosis === "request-too-large" || diagnosis === "context-window-exceeded" ? "request-too-large" : "provider",
|
|
1887
882
|
source: known ? "protocol" : "unknown",
|
|
1888
883
|
retryable: converted.retryable,
|
|
1889
884
|
...status === void 0 ? {} : { status },
|
|
1890
885
|
...code !== void 0 && providerCodes.has(code) ? { providerCode: code } : {}
|
|
1891
|
-
});
|
|
886
|
+
}, { cause: error });
|
|
1892
887
|
}
|
|
1893
888
|
//#endregion
|
|
1894
889
|
//#region src/stream.ts
|
|
1895
|
-
/**
|
|
1896
|
-
* A Codex Responses event stream → `ModelChunk`s.
|
|
1897
|
-
*
|
|
1898
|
-
* Deltas are forwarded as they arrive. The final message is assembled from
|
|
1899
|
-
* the `response.output_item.done` events, in order — the `response.completed`
|
|
1900
|
-
* event's own `output` arrives empty from this endpoint — and a reasoning
|
|
1901
|
-
* item becomes a thinking part whose `signature` is its encrypted content,
|
|
1902
|
-
* attributed to the model that produced it so the request side can decide
|
|
1903
|
-
* whether it may go back.
|
|
1904
|
-
*/
|
|
1905
890
|
const EVENT_LIMIT = 8388608;
|
|
1906
891
|
const SLAB_SIZE = 65536;
|
|
1907
|
-
/**
|
|
1908
|
-
* Reads JSON SSE events across fragmented LF, CRLF or CR separators.
|
|
1909
|
-
* Yields after 64 KiB of work, counting each incoming byte and each read, including empty reads.
|
|
1910
|
-
* Rejects bodies above 8 MiB before decoding; ignores non-JSON and unfinished EOF events.
|
|
1911
|
-
*/
|
|
1912
892
|
async function* sseEvents(body) {
|
|
1913
893
|
const decoder = new TextDecoder();
|
|
1914
894
|
let slabs = [];
|
|
@@ -1977,7 +957,23 @@ async function* sseEvents(body) {
|
|
|
1977
957
|
} else if (size > EVENT_LIMIT) throw oversized();
|
|
1978
958
|
}
|
|
1979
959
|
const str = (value) => typeof value === "string" ? value : "";
|
|
1980
|
-
const
|
|
960
|
+
const validCount = (value) => Number.isSafeInteger(value) && Number(value) >= 0;
|
|
961
|
+
const num = (value) => validCount(value) ? value : 0;
|
|
962
|
+
function unparseableCall(item) {
|
|
963
|
+
if (item.type !== "function_call") return void 0;
|
|
964
|
+
const id = str(item.call_id);
|
|
965
|
+
const name = str(item.name);
|
|
966
|
+
if (id.trim() === "" || name.trim() === "") return void 0;
|
|
967
|
+
try {
|
|
968
|
+
JSON.parse(str(item.arguments));
|
|
969
|
+
return;
|
|
970
|
+
} catch {
|
|
971
|
+
return {
|
|
972
|
+
id,
|
|
973
|
+
name
|
|
974
|
+
};
|
|
975
|
+
}
|
|
976
|
+
}
|
|
1981
977
|
function partsOf(item, model) {
|
|
1982
978
|
if (item.type === "reasoning") {
|
|
1983
979
|
const text = (Array.isArray(item.summary) ? item.summary : []).map((one) => str(one.text)).join("\n\n");
|
|
@@ -2020,13 +1016,10 @@ function partsOf(item, model) {
|
|
|
2020
1016
|
}
|
|
2021
1017
|
return [];
|
|
2022
1018
|
}
|
|
2023
|
-
/** UTF-8 bytes over four: rough, and only ever used as a ceiling. */
|
|
2024
1019
|
const tokensOf = (text) => Math.ceil(Buffer.byteLength(text, "utf8") / 4);
|
|
2025
|
-
/**
|
|
2026
|
-
* Forwards deltas immediately and assembles terminal output from completed items.
|
|
2027
|
-
* Completed unusable replies and malformed tool calls fail without retry; refusals remain visible.
|
|
2028
|
-
*/
|
|
2029
1020
|
async function* mapResponsesStream(events, options) {
|
|
1021
|
+
let usageSequence = 0;
|
|
1022
|
+
let reported = {};
|
|
2030
1023
|
const items = [];
|
|
2031
1024
|
const callIds = /* @__PURE__ */ new Map();
|
|
2032
1025
|
const pendingCalls = /* @__PURE__ */ new Map();
|
|
@@ -2036,6 +1029,22 @@ async function* mapResponsesStream(events, options) {
|
|
|
2036
1029
|
let refused = false;
|
|
2037
1030
|
let open = "";
|
|
2038
1031
|
for await (const event of events) {
|
|
1032
|
+
const response = event.response;
|
|
1033
|
+
if (response?.usage && typeof response.usage === "object") {
|
|
1034
|
+
const usage = response.usage;
|
|
1035
|
+
const details = usage.input_tokens_details ?? {};
|
|
1036
|
+
reported = {
|
|
1037
|
+
...reported,
|
|
1038
|
+
...typeof usage.input_tokens === "number" ? { inputTokens: usage.input_tokens } : {},
|
|
1039
|
+
...typeof usage.output_tokens === "number" ? { outputTokens: usage.output_tokens } : {},
|
|
1040
|
+
...typeof usage.total_tokens === "number" ? { totalTokens: usage.total_tokens } : {},
|
|
1041
|
+
...typeof details.cached_tokens === "number" ? { cacheReadTokens: details.cached_tokens } : {}
|
|
1042
|
+
};
|
|
1043
|
+
options.usageReporter?.report({
|
|
1044
|
+
sequence: ++usageSequence,
|
|
1045
|
+
...reported
|
|
1046
|
+
});
|
|
1047
|
+
}
|
|
2039
1048
|
switch (event.type) {
|
|
2040
1049
|
case "response.output_text.delta":
|
|
2041
1050
|
case "response.refusal.delta": {
|
|
@@ -2106,11 +1115,17 @@ async function* mapResponsesStream(events, options) {
|
|
|
2106
1115
|
const response = event.response ?? {};
|
|
2107
1116
|
const usage = response.usage ?? {};
|
|
2108
1117
|
const details = usage.input_tokens_details ?? {};
|
|
2109
|
-
const cache =
|
|
1118
|
+
const cache = validCount(details.cached_tokens) && details.cached_tokens <= num(usage.input_tokens) ? { cacheReadTokens: details.cached_tokens } : {};
|
|
2110
1119
|
const truncated = event.type === "response.incomplete" && response.incomplete_details?.reason === "max_output_tokens";
|
|
2111
1120
|
if (event.type === "response.incomplete" && !truncated && !refused) throw new ModelCallError(`incomplete model reply (${event.type})`, { retryable: false });
|
|
2112
1121
|
const incompleteToolCalls = [...pendingCalls.values()];
|
|
1122
|
+
const droppedToolCalls = [];
|
|
2113
1123
|
const content = items.flatMap((item) => {
|
|
1124
|
+
const unparseable = unparseableCall(item);
|
|
1125
|
+
if (unparseable && !truncated) {
|
|
1126
|
+
droppedToolCalls.push(unparseable);
|
|
1127
|
+
return [];
|
|
1128
|
+
}
|
|
2114
1129
|
try {
|
|
2115
1130
|
return partsOf(item, options.model);
|
|
2116
1131
|
} catch (error) {
|
|
@@ -2130,20 +1145,22 @@ async function* mapResponsesStream(events, options) {
|
|
|
2130
1145
|
type: "thinking",
|
|
2131
1146
|
text: openThinking
|
|
2132
1147
|
});
|
|
2133
|
-
if (!truncated && !refused && !content.some((part) => part.type === "text" || part.type === "tool-use")) throw new ModelCallError(`incomplete model reply (${event.type})`, {
|
|
1148
|
+
if (!truncated && !refused && droppedToolCalls.length === 0 && !content.some((part) => part.type === "text" || part.type === "tool-use")) throw new ModelCallError(`incomplete model reply (${event.type})`, {
|
|
2134
1149
|
retryable: false,
|
|
2135
1150
|
failureCode: "response-empty"
|
|
2136
1151
|
});
|
|
2137
|
-
const finishReason = refused ? "refusal" : truncated ? "max-tokens" : content.some((part) => part.type === "tool-use") ? "tool-calls" : "stop";
|
|
1152
|
+
const finishReason = refused ? "refusal" : truncated ? "max-tokens" : droppedToolCalls.length > 0 || content.some((part) => part.type === "tool-use") ? "tool-calls" : "stop";
|
|
2138
1153
|
yield {
|
|
2139
1154
|
kind: "final",
|
|
2140
1155
|
finishReason,
|
|
1156
|
+
...droppedToolCalls.length > 0 ? { droppedToolCalls } : {},
|
|
2141
1157
|
...finishReason === "max-tokens" ? { outputTruncation: {
|
|
2142
1158
|
incompleteToolCalls,
|
|
2143
1159
|
...openThinking !== "" ? { incompleteThinking: true } : {}
|
|
2144
1160
|
} } : {},
|
|
2145
1161
|
usage: {
|
|
2146
1162
|
inputTokens: num(usage.input_tokens),
|
|
1163
|
+
...validCount(usage.input_tokens) && (details.cached_tokens == null || validCount(details.cached_tokens) && details.cached_tokens <= usage.input_tokens) && (details.cache_write_tokens == null || validCount(details.cache_write_tokens) && details.cache_write_tokens <= usage.input_tokens) ? {} : { inputTokensReported: false },
|
|
2147
1164
|
outputTokens: num(usage.output_tokens),
|
|
2148
1165
|
...cache
|
|
2149
1166
|
},
|
|
@@ -2177,7 +1194,8 @@ async function* mapResponsesStream(events, options) {
|
|
|
2177
1194
|
},
|
|
2178
1195
|
usage: {
|
|
2179
1196
|
inputTokens: 0,
|
|
2180
|
-
outputTokens: written
|
|
1197
|
+
outputTokens: written,
|
|
1198
|
+
inputTokensReported: false
|
|
2181
1199
|
},
|
|
2182
1200
|
message: {
|
|
2183
1201
|
role: "assistant",
|
|
@@ -2194,13 +1212,11 @@ async function* mapResponsesStream(events, options) {
|
|
|
2194
1212
|
}
|
|
2195
1213
|
//#endregion
|
|
2196
1214
|
//#region src/port.ts
|
|
2197
|
-
/** Requires one host-owned transport identity before any network request. */
|
|
2198
1215
|
function transportIdOf(request) {
|
|
2199
1216
|
const identity = request.sessionId ?? request.callId;
|
|
2200
1217
|
if (!identity || request.sessionId !== void 0 && request.callId !== void 0) throw new Error("a model request requires exactly one session or call identity");
|
|
2201
1218
|
return identity;
|
|
2202
1219
|
}
|
|
2203
|
-
/** Builds authenticated headers without exposing the token in request metadata. */
|
|
2204
1220
|
function headersOf(tokens, sessionId, userAgent) {
|
|
2205
1221
|
return {
|
|
2206
1222
|
authorization: `Bearer ${tokens.access}`,
|
|
@@ -2213,9 +1229,8 @@ function headersOf(tokens, sessionId, userAgent) {
|
|
|
2213
1229
|
...tokens.residency === void 0 ? {} : { "x-openai-internal-codex-residency": tokens.residency }
|
|
2214
1230
|
};
|
|
2215
1231
|
}
|
|
2216
|
-
/** Creates a port whose retries preserve the host-selected transport identity. */
|
|
2217
1232
|
function createChatGPTPort(options) {
|
|
2218
|
-
function build(request
|
|
1233
|
+
function build(request) {
|
|
2219
1234
|
const plan = options.params(request.params ?? {});
|
|
2220
1235
|
const media = options.media?.(request.params ?? {}) ?? {
|
|
2221
1236
|
acceptsImages: true,
|
|
@@ -2223,7 +1238,7 @@ function createChatGPTPort(options) {
|
|
|
2223
1238
|
};
|
|
2224
1239
|
const replay = options.support.planEffortCache({
|
|
2225
1240
|
request,
|
|
2226
|
-
inspection,
|
|
1241
|
+
inspection: false,
|
|
2227
1242
|
effort: plan.effort,
|
|
2228
1243
|
capability: plan.thinking === false || plan.effort === "none" ? {
|
|
2229
1244
|
status: "unsupported",
|
|
@@ -2239,78 +1254,157 @@ function createChatGPTPort(options) {
|
|
|
2239
1254
|
thinking: plan.thinking
|
|
2240
1255
|
})
|
|
2241
1256
|
});
|
|
2242
|
-
const
|
|
1257
|
+
const mediaPlan = options.support.planMedia(request, media);
|
|
1258
|
+
const rendered = options.codec.render(request, {
|
|
2243
1259
|
model: options.model,
|
|
2244
1260
|
endpoint: options.providerId,
|
|
2245
1261
|
effort: replay.baseEffort,
|
|
2246
1262
|
effortUpdates: replay.updates,
|
|
2247
1263
|
media
|
|
2248
|
-
},
|
|
1264
|
+
}, mediaPlan);
|
|
1265
|
+
const receipts = new Map(replay.replaySources?.map((source) => [source.messageId, JSON.stringify(source.contribution)]));
|
|
1266
|
+
const replaySelections = options.support.prepareReplaySelections(request, ({ message, part }) => part ? options.codec.replayChoice(message, part, {
|
|
1267
|
+
model: options.model,
|
|
1268
|
+
endpoint: options.providerId
|
|
1269
|
+
}) : {
|
|
1270
|
+
mode: "effort-cache",
|
|
1271
|
+
textIncluded: false,
|
|
1272
|
+
selectedText: receipts.get(message.id),
|
|
1273
|
+
reason: "not-applicable"
|
|
1274
|
+
});
|
|
2249
1275
|
const sessionId = transportIdOf(request);
|
|
1276
|
+
const body = options.support.freezePayload({
|
|
1277
|
+
...rendered,
|
|
1278
|
+
prompt_cache_key: sessionId
|
|
1279
|
+
});
|
|
2250
1280
|
return {
|
|
2251
|
-
body
|
|
2252
|
-
|
|
2253
|
-
prompt_cache_key: sessionId
|
|
2254
|
-
},
|
|
1281
|
+
body,
|
|
1282
|
+
replaySelections,
|
|
2255
1283
|
sessionId,
|
|
2256
|
-
|
|
2257
|
-
|
|
1284
|
+
replay: options.support.freezePayload(replay),
|
|
1285
|
+
fields: options.codec.semanticFields(body, mediaPlan),
|
|
1286
|
+
capacity: options.support.freezePayload(options.catalogue()?.limit ?? {}),
|
|
1287
|
+
request: {
|
|
1288
|
+
...request,
|
|
1289
|
+
params: options.support.freezePayload(request.params ?? {})
|
|
1290
|
+
},
|
|
1291
|
+
mediaPlan,
|
|
1292
|
+
mediaTokens: mediaPlan.tokens,
|
|
1293
|
+
hiddenInputTokens: options.codec.hiddenInputTokens(request, {
|
|
1294
|
+
model: options.model,
|
|
1295
|
+
endpoint: options.providerId
|
|
1296
|
+
}),
|
|
1297
|
+
fingerprint: options.support.freezePayload({
|
|
1298
|
+
rendering: "chatgpt-codex-responses-v2",
|
|
1299
|
+
endpoint: options.providerId,
|
|
1300
|
+
model: options.model,
|
|
1301
|
+
purpose: request.purpose,
|
|
1302
|
+
settings: { effort: body.reasoning?.effort }
|
|
1303
|
+
})
|
|
2258
1304
|
};
|
|
2259
1305
|
}
|
|
2260
|
-
async function send(body, sessionId, signal,
|
|
2261
|
-
const
|
|
2262
|
-
const
|
|
2263
|
-
if (tokens === void 0) throw notSignedIn();
|
|
2264
|
-
const response = await options.fetch(`${options.endpoints.codex}/responses`, {
|
|
1306
|
+
async function send(body, sessionId, signal, prepared, reportProgress, dispatched) {
|
|
1307
|
+
const { tokens } = prepared;
|
|
1308
|
+
const pending = options.fetch(`${options.endpoints.codex}/responses`, {
|
|
2265
1309
|
method: "POST",
|
|
2266
1310
|
headers: headersOf(tokens, sessionId, options.userAgent),
|
|
2267
1311
|
body: JSON.stringify(body),
|
|
2268
1312
|
signal
|
|
2269
1313
|
});
|
|
1314
|
+
dispatched();
|
|
1315
|
+
const response = await pending;
|
|
2270
1316
|
return {
|
|
2271
1317
|
response: options.support.observeResponseProgress(response, reportProgress),
|
|
2272
|
-
credential:
|
|
1318
|
+
credential: prepared.credential
|
|
2273
1319
|
};
|
|
2274
1320
|
}
|
|
2275
|
-
return {
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
1321
|
+
return options.support.createPreparedPort({
|
|
1322
|
+
prepare: build,
|
|
1323
|
+
semantics(payload) {
|
|
1324
|
+
return {
|
|
1325
|
+
replaySelections: payload.replaySelections,
|
|
1326
|
+
mediaSelections: () => options.support.mediaSelections(payload.mediaPlan),
|
|
1327
|
+
format: "request-semantic-v1",
|
|
1328
|
+
protocolId: "chatgpt-subscription",
|
|
1329
|
+
adapterVersion: "1",
|
|
1330
|
+
rendererVersion: "chatgpt-codex-responses-v2",
|
|
1331
|
+
parameters: Object.freeze(Object.fromEntries(Object.entries(payload.body).filter(([key]) => ![
|
|
1332
|
+
"model",
|
|
1333
|
+
"input",
|
|
1334
|
+
"instructions",
|
|
1335
|
+
"tools",
|
|
1336
|
+
"stream",
|
|
1337
|
+
"store",
|
|
1338
|
+
"prompt_cache_key"
|
|
1339
|
+
].includes(key)))),
|
|
1340
|
+
toolDefinitions: payload.body.tools ?? Object.freeze([]),
|
|
1341
|
+
frames: () => options.support.semanticFrames(payload.body, {
|
|
1342
|
+
omitRoot: [
|
|
1343
|
+
"stream",
|
|
1344
|
+
"store",
|
|
1345
|
+
"prompt_cache_key"
|
|
1346
|
+
],
|
|
1347
|
+
fields: payload.fields
|
|
1348
|
+
})
|
|
1349
|
+
};
|
|
1350
|
+
},
|
|
1351
|
+
async inspect(payload, signal) {
|
|
1352
|
+
signal.throwIfAborted();
|
|
1353
|
+
const started = options.support.performance?.now();
|
|
1354
|
+
const { body, request, capacity, hiddenInputTokens, mediaTokens, fingerprint } = payload;
|
|
1355
|
+
options.support.performance?.observe({
|
|
1356
|
+
stage: "model.project",
|
|
1357
|
+
measurementPurpose: "request",
|
|
1358
|
+
durationMs: options.support.performance.now() - started,
|
|
1359
|
+
count: 1
|
|
1360
|
+
});
|
|
1361
|
+
const text = options.support.requestText("responses", body);
|
|
1362
|
+
const inspection = options.support.inspect({
|
|
2280
1363
|
body,
|
|
2281
|
-
textTokens:
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
endpoint: options.providerId
|
|
2286
|
-
}),
|
|
1364
|
+
textTokens: 0,
|
|
1365
|
+
textBytes: Buffer.byteLength(text),
|
|
1366
|
+
tokenizer: "utf8-bytes-quarter-v1",
|
|
1367
|
+
hiddenInputTokens,
|
|
2287
1368
|
request,
|
|
2288
1369
|
capacity,
|
|
2289
1370
|
outputReserve: capacity?.output ?? 0,
|
|
2290
1371
|
outputReserveSource: "capacity",
|
|
2291
|
-
mediaTokens
|
|
2292
|
-
fingerprint
|
|
2293
|
-
rendering: "chatgpt-codex-responses-v2",
|
|
2294
|
-
endpoint: options.providerId,
|
|
2295
|
-
model: options.model,
|
|
2296
|
-
purpose: request.purpose,
|
|
2297
|
-
contextWindow: request.params?.contextWindow,
|
|
2298
|
-
capacity,
|
|
2299
|
-
settings: { effort: body.reasoning?.effort }
|
|
2300
|
-
}
|
|
1372
|
+
mediaTokens,
|
|
1373
|
+
fingerprint
|
|
2301
1374
|
});
|
|
1375
|
+
const textTokens = await options.support.measureText(text, signal);
|
|
1376
|
+
signal.throwIfAborted();
|
|
1377
|
+
return {
|
|
1378
|
+
...inspection,
|
|
1379
|
+
inputTokens: inspection.inputTokens + textTokens
|
|
1380
|
+
};
|
|
2302
1381
|
},
|
|
2303
|
-
stream(
|
|
1382
|
+
stream(payload, signal, observer, scope) {
|
|
2304
1383
|
signal.throwIfAborted();
|
|
2305
1384
|
const login = options.login;
|
|
2306
|
-
const { body, sessionId, replay } =
|
|
1385
|
+
const { body, request, sessionId, replay } = payload;
|
|
1386
|
+
const dispatchEffort = body.reasoning?.effort === "none" ? "none" : replay.effectiveEffort ?? body.reasoning?.effort;
|
|
2307
1387
|
const cap = request.purpose === "summary" && request.summaryMaxTokens !== void 0 ? request.summaryMaxTokens : void 0;
|
|
1388
|
+
let prepared;
|
|
2308
1389
|
return options.support.withChatAttempts({
|
|
1390
|
+
retainCleanup: scope.retainCleanup,
|
|
1391
|
+
accountingDispatch: options.accountingDispatch,
|
|
1392
|
+
beforeAttempt: async (attemptSignal, ordinal) => {
|
|
1393
|
+
await observer?.beforeAttempt?.(ordinal);
|
|
1394
|
+
if (login === void 0) throw notSignedIn();
|
|
1395
|
+
const envelope = await login.get(attemptSignal);
|
|
1396
|
+
const tokens = parseStored(envelope.credential);
|
|
1397
|
+
if (tokens === void 0) throw notSignedIn();
|
|
1398
|
+
prepared = {
|
|
1399
|
+
credential: envelope.credential,
|
|
1400
|
+
tokens
|
|
1401
|
+
};
|
|
1402
|
+
},
|
|
2309
1403
|
signal,
|
|
2310
1404
|
...options.maxRetries === void 0 ? {} : { maxRetries: options.maxRetries },
|
|
2311
1405
|
...options.sleep === void 0 ? {} : { sleep: options.sleep },
|
|
2312
1406
|
...options.idleMs === void 0 ? {} : { idleMs: options.idleMs },
|
|
2313
|
-
async *attempt(attemptSignal, reportProgress, attempt) {
|
|
1407
|
+
async *attempt(attemptSignal, reportProgress, attempt, usageReporter) {
|
|
2314
1408
|
const observe = (event) => {
|
|
2315
1409
|
try {
|
|
2316
1410
|
observer?.observe?.(event);
|
|
@@ -2318,7 +1412,30 @@ function createChatGPTPort(options) {
|
|
|
2318
1412
|
};
|
|
2319
1413
|
const attemptCount = attempt + 1;
|
|
2320
1414
|
let outcome = "unknown";
|
|
1415
|
+
let timeout;
|
|
2321
1416
|
let firstResponseFinished = false;
|
|
1417
|
+
const markDispatched = () => {
|
|
1418
|
+
try {
|
|
1419
|
+
observer?.dispatched({
|
|
1420
|
+
attempt,
|
|
1421
|
+
presentation: {
|
|
1422
|
+
schema: "chat.dispatch-settings.v1",
|
|
1423
|
+
data: {
|
|
1424
|
+
model: {
|
|
1425
|
+
availability: "resolved",
|
|
1426
|
+
value: body.model,
|
|
1427
|
+
origin: "protocol"
|
|
1428
|
+
},
|
|
1429
|
+
effort: dispatchEffort ? {
|
|
1430
|
+
availability: "resolved",
|
|
1431
|
+
value: dispatchEffort,
|
|
1432
|
+
origin: "protocol"
|
|
1433
|
+
} : { availability: "unreported" }
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
});
|
|
1437
|
+
} catch {}
|
|
1438
|
+
};
|
|
2322
1439
|
observe({
|
|
2323
1440
|
stage: "attempt",
|
|
2324
1441
|
phase: "start",
|
|
@@ -2329,10 +1446,12 @@ function createChatGPTPort(options) {
|
|
|
2329
1446
|
phase: "start",
|
|
2330
1447
|
attempt: attemptCount
|
|
2331
1448
|
});
|
|
1449
|
+
let responseBody;
|
|
2332
1450
|
try {
|
|
2333
1451
|
attemptSignal.throwIfAborted();
|
|
2334
1452
|
if (login === void 0) throw notSignedIn();
|
|
2335
|
-
const { response, credential } = await send(body, sessionId, attemptSignal,
|
|
1453
|
+
const { response, credential } = await send(body, sessionId, attemptSignal, prepared, reportProgress, markDispatched);
|
|
1454
|
+
responseBody = response.body;
|
|
2336
1455
|
firstResponseFinished = true;
|
|
2337
1456
|
observe({
|
|
2338
1457
|
stage: "first-response",
|
|
@@ -2341,12 +1460,15 @@ function createChatGPTPort(options) {
|
|
|
2341
1460
|
outcome: "ok"
|
|
2342
1461
|
});
|
|
2343
1462
|
if (response.status === 401) {
|
|
2344
|
-
await response.body?.cancel();
|
|
1463
|
+
await response.body?.cancel().catch(() => {});
|
|
1464
|
+
responseBody = void 0;
|
|
2345
1465
|
login.expire(credential);
|
|
2346
1466
|
throw signInExpired(401);
|
|
2347
1467
|
}
|
|
2348
1468
|
if (!response.ok || response.body === null) {
|
|
2349
|
-
const
|
|
1469
|
+
const refusalText = await response.text().catch(() => "");
|
|
1470
|
+
responseBody = void 0;
|
|
1471
|
+
const refused = toPortError(response.status, refusalText);
|
|
2350
1472
|
const wait = Number(response.headers.get("retry-after"));
|
|
2351
1473
|
throw Number.isFinite(wait * 1e3) && wait > 0 && refused.retryable ? new ModelCallError(refused.message, {
|
|
2352
1474
|
failureCode: refused.failureCode,
|
|
@@ -2358,15 +1480,17 @@ function createChatGPTPort(options) {
|
|
|
2358
1480
|
}) : refused;
|
|
2359
1481
|
}
|
|
2360
1482
|
attemptSignal.throwIfAborted();
|
|
2361
|
-
try {
|
|
2362
|
-
observer?.dispatched({ attempt });
|
|
2363
|
-
} catch {}
|
|
2364
1483
|
attemptSignal.throwIfAborted();
|
|
2365
1484
|
const stream = response.body;
|
|
2366
|
-
|
|
1485
|
+
const events = (async function* () {
|
|
1486
|
+
responseBody = void 0;
|
|
1487
|
+
yield* sseEvents(stream);
|
|
1488
|
+
})();
|
|
1489
|
+
for await (const chunk of mapResponsesStream(events, {
|
|
1490
|
+
usageReporter,
|
|
2367
1491
|
model: options.model,
|
|
2368
1492
|
...cap === void 0 ? {} : { outputCap: cap },
|
|
2369
|
-
stop: () => void
|
|
1493
|
+
stop: () => void events.return(void 0).catch(() => {})
|
|
2370
1494
|
})) {
|
|
2371
1495
|
if (chunk.kind === "final") outcome = "ok";
|
|
2372
1496
|
yield chunk.kind === "final" && replay.replayData ? {
|
|
@@ -2375,37 +1499,52 @@ function createChatGPTPort(options) {
|
|
|
2375
1499
|
} : chunk;
|
|
2376
1500
|
}
|
|
2377
1501
|
} catch (error) {
|
|
2378
|
-
|
|
1502
|
+
const reason = attemptSignal.aborted ? options.support.failures.verified(attemptSignal.reason) : void 0;
|
|
1503
|
+
if (reason?.code === "stream-idle-timeout") {
|
|
1504
|
+
outcome = "timeout";
|
|
1505
|
+
timeout = reason;
|
|
1506
|
+
} else outcome = attemptSignal.aborted ? "cancelled" : "error";
|
|
2379
1507
|
throw error;
|
|
2380
1508
|
} finally {
|
|
2381
|
-
if (
|
|
2382
|
-
|
|
1509
|
+
if (responseBody) {
|
|
1510
|
+
const body = responseBody;
|
|
1511
|
+
scope.retainCleanup(async () => {
|
|
1512
|
+
await body.cancel();
|
|
1513
|
+
}).catch(() => {});
|
|
1514
|
+
}
|
|
1515
|
+
const end = {
|
|
2383
1516
|
phase: "end",
|
|
2384
1517
|
attempt: attemptCount,
|
|
2385
|
-
outcome
|
|
1518
|
+
outcome,
|
|
1519
|
+
...timeout ? { failure: timeout } : {}
|
|
1520
|
+
};
|
|
1521
|
+
if (!firstResponseFinished) observe({
|
|
1522
|
+
stage: "first-response",
|
|
1523
|
+
...end
|
|
2386
1524
|
});
|
|
2387
1525
|
observe({
|
|
2388
1526
|
stage: "attempt",
|
|
2389
|
-
|
|
2390
|
-
attempt: attemptCount,
|
|
2391
|
-
outcome
|
|
1527
|
+
...end
|
|
2392
1528
|
});
|
|
2393
1529
|
}
|
|
2394
1530
|
},
|
|
2395
1531
|
classify(error) {
|
|
2396
|
-
const
|
|
1532
|
+
const failure = toModelFailure(error, options.support.failures, options.support.transportFailure);
|
|
2397
1533
|
return {
|
|
2398
|
-
error:
|
|
2399
|
-
retryable:
|
|
2400
|
-
retryAfterMs:
|
|
1534
|
+
error: failure,
|
|
1535
|
+
retryable: failure.retryable === true,
|
|
1536
|
+
retryAfterMs: toCallError(error).retryAfterMs
|
|
2401
1537
|
};
|
|
2402
1538
|
}
|
|
2403
1539
|
});
|
|
2404
1540
|
}
|
|
2405
|
-
};
|
|
1541
|
+
});
|
|
2406
1542
|
}
|
|
2407
1543
|
//#endregion
|
|
2408
1544
|
//#region src/probe.ts
|
|
1545
|
+
function modalitiesOf(value) {
|
|
1546
|
+
return Array.isArray(value) && value.length > 0 && value.every((one) => typeof one === "string") ? [...value] : void 0;
|
|
1547
|
+
}
|
|
2409
1548
|
function effortsOf(levels) {
|
|
2410
1549
|
if (!Array.isArray(levels)) return void 0;
|
|
2411
1550
|
const named = levels.map((one) => typeof one === "string" ? one : one?.effort).filter((one) => typeof one === "string");
|
|
@@ -2415,19 +1554,20 @@ function effortsOf(levels) {
|
|
|
2415
1554
|
function offerOf(model) {
|
|
2416
1555
|
if (typeof model.slug !== "string" || model.visibility !== "list") return void 0;
|
|
2417
1556
|
const efforts = effortsOf(model.supported_reasoning_levels);
|
|
1557
|
+
const input = modalitiesOf(model.input_modalities);
|
|
1558
|
+
const fallback = model.default_reasoning_level;
|
|
1559
|
+
const defaultEffort = typeof fallback === "string" && efforts?.includes(fallback) ? fallback : void 0;
|
|
2418
1560
|
return {
|
|
2419
1561
|
model: model.slug,
|
|
2420
1562
|
...typeof model.display_name === "string" ? { name: model.display_name } : {},
|
|
2421
1563
|
...Number.isInteger(model.context_window) && Number(model.context_window) > 0 ? { contextWindow: Number(model.context_window) } : {},
|
|
2422
|
-
...
|
|
1564
|
+
...input === void 0 ? {} : { input },
|
|
1565
|
+
output: ["text"],
|
|
1566
|
+
...model.supports_parallel_tool_calls === true ? { toolCall: true } : {},
|
|
1567
|
+
...efforts === void 0 ? {} : { efforts },
|
|
1568
|
+
...defaultEffort === void 0 ? {} : { defaultEffort }
|
|
2423
1569
|
};
|
|
2424
1570
|
}
|
|
2425
|
-
/**
|
|
2426
|
-
* The secret tokens this probe could have carried: the ones it called with
|
|
2427
|
-
* and the ones stored now. A refresh during the probe writes tokens after the
|
|
2428
|
-
* host collected its redaction set, so the probe checks the endpoint's words
|
|
2429
|
-
* against them itself.
|
|
2430
|
-
*/
|
|
2431
1571
|
function heldTokens(used, stored) {
|
|
2432
1572
|
const now = parseStored(stored);
|
|
2433
1573
|
return [
|
|
@@ -2437,6 +1577,34 @@ function heldTokens(used, stored) {
|
|
|
2437
1577
|
now?.refresh
|
|
2438
1578
|
].filter((one) => one !== void 0 && one !== "");
|
|
2439
1579
|
}
|
|
1580
|
+
const DEFAULT_RESPONSE_BYTES = 8388608;
|
|
1581
|
+
async function boundedText(response, maxBytes) {
|
|
1582
|
+
const exceeded = () => /* @__PURE__ */ new Error("the model listing exceeds its response byte ceiling");
|
|
1583
|
+
const declared = response.headers.get("content-length");
|
|
1584
|
+
if (declared !== null && /^\d+$/.test(declared) && Number(declared) > maxBytes) {
|
|
1585
|
+
await response.body?.cancel().catch(() => {});
|
|
1586
|
+
throw exceeded();
|
|
1587
|
+
}
|
|
1588
|
+
if (!response.body) return "";
|
|
1589
|
+
const reader = response.body.getReader();
|
|
1590
|
+
const decoder = new TextDecoder();
|
|
1591
|
+
let bytes = 0;
|
|
1592
|
+
let text = "";
|
|
1593
|
+
try {
|
|
1594
|
+
for (;;) {
|
|
1595
|
+
const next = await reader.read();
|
|
1596
|
+
if (next.done) return text + decoder.decode();
|
|
1597
|
+
bytes += next.value.byteLength;
|
|
1598
|
+
if (bytes > maxBytes) throw exceeded();
|
|
1599
|
+
text += decoder.decode(next.value, { stream: true });
|
|
1600
|
+
}
|
|
1601
|
+
} catch (error) {
|
|
1602
|
+
await reader.cancel().catch(() => {});
|
|
1603
|
+
throw error;
|
|
1604
|
+
} finally {
|
|
1605
|
+
reader.releaseLock();
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
2440
1608
|
function createProbes(deps) {
|
|
2441
1609
|
async function listModels(probe) {
|
|
2442
1610
|
const login = probe.login;
|
|
@@ -2455,12 +1623,13 @@ function createProbes(deps) {
|
|
|
2455
1623
|
},
|
|
2456
1624
|
signal: probe.signal
|
|
2457
1625
|
});
|
|
1626
|
+
const limit = probe.maxResponseBytes ?? DEFAULT_RESPONSE_BYTES;
|
|
2458
1627
|
if (!response.ok) {
|
|
2459
|
-
const body = await response
|
|
1628
|
+
const body = await boundedText(response, limit).catch(() => "");
|
|
2460
1629
|
const echoes = heldTokens(tokens, envelope.credential).some((token) => body.includes(token));
|
|
2461
1630
|
throw Object.assign(new Error(body === "" || echoes ? response.statusText : body), { status: response.status });
|
|
2462
1631
|
}
|
|
2463
|
-
const body = await response
|
|
1632
|
+
const body = JSON.parse(await boundedText(response, limit));
|
|
2464
1633
|
return (Array.isArray(body.models) ? body.models : []).map(offerOf).filter((one) => one !== void 0);
|
|
2465
1634
|
}
|
|
2466
1635
|
return {
|
|
@@ -2472,11 +1641,11 @@ function createProbes(deps) {
|
|
|
2472
1641
|
}
|
|
2473
1642
|
//#endregion
|
|
2474
1643
|
//#region src/support.ts
|
|
2475
|
-
/** Normalizes official facts without requiring an installed Chat capability. */
|
|
2476
1644
|
function normalizeOffers(input) {
|
|
2477
1645
|
return Object.fromEntries(input.offers.map((offer) => [offer.model, {
|
|
2478
1646
|
id: offer.model,
|
|
2479
1647
|
...offer.name === void 0 ? {} : { name: offer.name },
|
|
1648
|
+
...offer.chat === void 0 ? {} : { chat: offer.chat },
|
|
2480
1649
|
...offer.reasoning === void 0 && !offer.efforts?.length ? {} : { reasoning: offer.efforts?.length ? true : offer.reasoning },
|
|
2481
1650
|
...offer.efforts?.length ? { reasoning_options: [{
|
|
2482
1651
|
type: "effort",
|
|
@@ -2496,7 +1665,6 @@ function normalizeOffers(input) {
|
|
|
2496
1665
|
...offer.releaseDate === void 0 ? {} : { release_date: offer.releaseDate }
|
|
2497
1666
|
}]));
|
|
2498
1667
|
}
|
|
2499
|
-
/** The owner-qualified accessor is read per operation; withdrawal never exposes an old service. */
|
|
2500
1668
|
function lazySupport(read) {
|
|
2501
1669
|
return new Proxy({}, { get(_target, key) {
|
|
2502
1670
|
if (key === "normalizeListing") return normalizeOffers;
|
|
@@ -2509,7 +1677,6 @@ function lazySupport(read) {
|
|
|
2509
1677
|
//#endregion
|
|
2510
1678
|
//#region src/protocol.ts
|
|
2511
1679
|
const USER_AGENT = "yaoguang";
|
|
2512
|
-
/** Builds the subscription provider using host-owned planning, routing and login credentials. */
|
|
2513
1680
|
function chatgptProtocolType(support, fetch, codec, options = {}, imageInfo = (bytes, signal) => support.imageInfo(bytes, signal)) {
|
|
2514
1681
|
const endpoints = options.endpoints ?? ENDPOINTS;
|
|
2515
1682
|
const probes = createProbes({
|
|
@@ -2537,6 +1704,7 @@ function chatgptProtocolType(support, fetch, codec, options = {}, imageInfo = (b
|
|
|
2537
1704
|
fileKinds: ["image"],
|
|
2538
1705
|
supportsModel: (model) => !/^gpt-image(?:-|$)/.test(model),
|
|
2539
1706
|
createPort: (call) => createChatGPTPort({
|
|
1707
|
+
accountingDispatch: call.accountingDispatch,
|
|
2540
1708
|
fetch,
|
|
2541
1709
|
codec,
|
|
2542
1710
|
connectionFingerprint: call.connectionFingerprint,
|
|
@@ -2564,44 +1732,39 @@ function chatgptProtocolType(support, fetch, codec, options = {}, imageInfo = (b
|
|
|
2564
1732
|
})
|
|
2565
1733
|
},
|
|
2566
1734
|
image: {
|
|
2567
|
-
models: () => [
|
|
1735
|
+
models: (input) => [...IMAGE_GENERATION_MODELS, ...[...new Set(input.configuredModels.map((row) => row.id))].filter((id) => !IMAGE_GENERATION_MODELS.some((model) => model.id === id)).map(imageModelOf)],
|
|
2568
1736
|
createPort: (call) => createImageGenerationPort({
|
|
1737
|
+
accountingDispatch: call.accountingDispatch,
|
|
2569
1738
|
fetch,
|
|
2570
1739
|
baseUrl: endpoints.codex,
|
|
2571
1740
|
login: call.login,
|
|
2572
1741
|
imageInfo,
|
|
2573
|
-
userAgent: USER_AGENT
|
|
1742
|
+
userAgent: USER_AGENT,
|
|
1743
|
+
model: call.model
|
|
2574
1744
|
})
|
|
2575
1745
|
}
|
|
2576
1746
|
},
|
|
2577
1747
|
normalizeListing: (input) => normalizeOffers(input),
|
|
2578
1748
|
async listModels(probe) {
|
|
2579
|
-
const
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
1749
|
+
const listed = await probes.listModels(probe);
|
|
1750
|
+
const isImage = (id) => IMAGE_GENERATION_MODELS.some((model) => model.id === id);
|
|
1751
|
+
const offers = listed.map(({ output, ...offer }) => isImage(offer.model) ? offer : {
|
|
1752
|
+
...offer,
|
|
1753
|
+
output
|
|
1754
|
+
});
|
|
1755
|
+
const ids = new Set(offers.map((offer) => offer.model));
|
|
1756
|
+
return { offers: [...offers, ...IMAGE_GENERATION_MODELS.filter((model) => !ids.has(model.id)).map((model) => ({
|
|
1757
|
+
model: model.id,
|
|
1758
|
+
name: model.label,
|
|
2584
1759
|
input: ["text", "image"],
|
|
2585
|
-
output: [...
|
|
2586
|
-
}] };
|
|
1760
|
+
output: [...model.outputKinds]
|
|
1761
|
+
}))] };
|
|
2587
1762
|
},
|
|
2588
1763
|
testConnection: (probe) => probes.testConnection(probe)
|
|
2589
1764
|
};
|
|
2590
1765
|
}
|
|
2591
1766
|
//#endregion
|
|
2592
1767
|
//#region src/callback.ts
|
|
2593
|
-
/**
|
|
2594
|
-
* The loopback listener a browser sign-in returns to.
|
|
2595
|
-
*
|
|
2596
|
-
* The redirect address is fixed by the client's registration —
|
|
2597
|
-
* `http://localhost:1455/auth/callback` — and a browser may resolve
|
|
2598
|
-
* `localhost` to either loopback address, while Node's `listen('localhost')`
|
|
2599
|
-
* binds only the first one it resolves. So the same port is opened on both
|
|
2600
|
-
* `127.0.0.1` and `::1`, one flow behind the two; a machine with no IPv6
|
|
2601
|
-
* loopback serves IPv4 alone. Either address being taken refuses the whole
|
|
2602
|
-
* sign-in: a browser landing on the other program would hand it the code.
|
|
2603
|
-
*/
|
|
2604
|
-
/** The listener is in use by something else. */
|
|
2605
1768
|
var CallbackPortInUse = class extends Error {
|
|
2606
1769
|
constructor(port) {
|
|
2607
1770
|
super(`port ${String(port)} is in use`);
|
|
@@ -2623,7 +1786,7 @@ function listen(port, host) {
|
|
|
2623
1786
|
});
|
|
2624
1787
|
}
|
|
2625
1788
|
function page(ok) {
|
|
2626
|
-
return `<!doctype html><html><head><meta charset="utf-8"><title>YaoGuang</title></head><body style="font-family:system-ui;margin:3rem"><p>${ok ? "Sign-in complete. You can close this page.
|
|
1789
|
+
return `<!doctype html><html><head><meta charset="utf-8"><title>YaoGuang</title></head><body style="font-family:system-ui;margin:3rem"><p>${ok ? "Sign-in complete. You can close this page. \u767b\u5f55\u5b8c\u6210\uff0c\u53ef\u4ee5\u5173\u95ed\u6b64\u9875\u3002" : "Sign-in was not completed. You can close this page. \u767b\u5f55\u672a\u5b8c\u6210\uff0c\u53ef\u4ee5\u5173\u95ed\u6b64\u9875\u3002"}</p><script>setTimeout(function(){window.close()},300)<\/script></body></html>`;
|
|
2627
1790
|
}
|
|
2628
1791
|
function respond(res, status, ok) {
|
|
2629
1792
|
res.writeHead(status, {
|
|
@@ -2632,10 +1795,6 @@ function respond(res, status, ok) {
|
|
|
2632
1795
|
});
|
|
2633
1796
|
res.end(page(ok));
|
|
2634
1797
|
}
|
|
2635
|
-
/**
|
|
2636
|
-
* Opens the listener pair for one flow. Rejects with `CallbackPortInUse`
|
|
2637
|
-
* when either address is taken, closing whichever one had opened.
|
|
2638
|
-
*/
|
|
2639
1798
|
async function openCallback(port, state) {
|
|
2640
1799
|
const servers = [];
|
|
2641
1800
|
let bound = port;
|
|
@@ -2705,19 +1864,6 @@ async function openCallback(port, state) {
|
|
|
2705
1864
|
}
|
|
2706
1865
|
//#endregion
|
|
2707
1866
|
//#region src/login.ts
|
|
2708
|
-
/**
|
|
2709
|
-
* The two ways a ChatGPT account signs in.
|
|
2710
|
-
*
|
|
2711
|
-
* Browser: a loopback listener waits for the authorization page to send the
|
|
2712
|
-
* person back with a code. Device code: the person types a code at an
|
|
2713
|
-
* address on any device, and this side polls until the account confirms it.
|
|
2714
|
-
* Both end in the same token exchange and the same stored shape.
|
|
2715
|
-
*
|
|
2716
|
-
* The host owns each flow's life — its deadline, its cancellation, where the
|
|
2717
|
-
* result goes — and hands that over as the `signal`. What this module owns is
|
|
2718
|
-
* the one process-wide listener: its port is fixed, so a second browser
|
|
2719
|
-
* sign-in while one waits is refused rather than queued.
|
|
2720
|
-
*/
|
|
2721
1867
|
function resultOf(tokens) {
|
|
2722
1868
|
return {
|
|
2723
1869
|
credential: JSON.stringify(tokens),
|
|
@@ -2797,7 +1943,7 @@ function createLogin(deps) {
|
|
|
2797
1943
|
const interval = (Number.isFinite(named) && named >= 0 ? named : 5) * 1e3 + deps.pollMarginMs;
|
|
2798
1944
|
const completion = (async () => {
|
|
2799
1945
|
for (;;) {
|
|
2800
|
-
await
|
|
1946
|
+
await setTimeout(interval, void 0, { signal }).catch(() => {
|
|
2801
1947
|
throw new LoginFailure("cancelled");
|
|
2802
1948
|
});
|
|
2803
1949
|
let poll;
|
|
@@ -2859,15 +2005,285 @@ function createLogin(deps) {
|
|
|
2859
2005
|
};
|
|
2860
2006
|
}
|
|
2861
2007
|
//#endregion
|
|
2008
|
+
//#region src/resources.ts
|
|
2009
|
+
function failure(detail) {
|
|
2010
|
+
const code = detail === "Resource request failed" ? "source-failed" : "invalid-response";
|
|
2011
|
+
return Object.assign(new Error(code), {
|
|
2012
|
+
name: "ProviderResourceFailure",
|
|
2013
|
+
code,
|
|
2014
|
+
retryable: false
|
|
2015
|
+
});
|
|
2016
|
+
}
|
|
2017
|
+
const IMAGE_PREFIX = "additional-image_gen";
|
|
2018
|
+
const labels = (en, zh) => ({
|
|
2019
|
+
"en-US": en,
|
|
2020
|
+
"zh-CN": zh
|
|
2021
|
+
});
|
|
2022
|
+
function object(value) {
|
|
2023
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw failure("Invalid resource response");
|
|
2024
|
+
return value;
|
|
2025
|
+
}
|
|
2026
|
+
function decimal(value) {
|
|
2027
|
+
const text = typeof value === "number" && Number.isSafeInteger(value) ? String(value) : value;
|
|
2028
|
+
if (typeof text !== "string" || !/^(0|[1-9]\d*)(\.\d+)?$/.test(text)) throw failure("Invalid resource amount");
|
|
2029
|
+
const normalized = text.includes(".") ? text.replace(/0+$/, "").replace(/\.$/, "") : text;
|
|
2030
|
+
return normalized === "-0" ? "0" : normalized;
|
|
2031
|
+
}
|
|
2032
|
+
function date(value) {
|
|
2033
|
+
const ms = typeof value === "number" ? value * 1e3 : typeof value === "string" ? Date.parse(value) : NaN;
|
|
2034
|
+
return Number.isFinite(ms) ? new Date(ms).toISOString() : void 0;
|
|
2035
|
+
}
|
|
2036
|
+
const resourceCapability = {
|
|
2037
|
+
support: "supported",
|
|
2038
|
+
applicability: { kind: "fixed-endpoint" },
|
|
2039
|
+
sources: [{
|
|
2040
|
+
id: "usage",
|
|
2041
|
+
labels: labels("Usage", "\u7528\u91cf"),
|
|
2042
|
+
optional: false,
|
|
2043
|
+
requests: [{
|
|
2044
|
+
id: "usage",
|
|
2045
|
+
method: "GET",
|
|
2046
|
+
url: "https://chatgpt.com/backend-api/wham/usage"
|
|
2047
|
+
}],
|
|
2048
|
+
allowedHeaderNames: ["Authorization", "ChatGPT-Account-Id"]
|
|
2049
|
+
}, {
|
|
2050
|
+
id: "reset-details",
|
|
2051
|
+
labels: labels("Reset credit details", "\u91cd\u7f6e\u5238\u660e\u7ec6"),
|
|
2052
|
+
optional: true,
|
|
2053
|
+
requests: [{
|
|
2054
|
+
id: "reset-details",
|
|
2055
|
+
method: "GET",
|
|
2056
|
+
url: "https://chatgpt.com/backend-api/wham/rate-limit-reset-credits"
|
|
2057
|
+
}],
|
|
2058
|
+
allowedHeaderNames: ["Authorization", "ChatGPT-Account-Id"]
|
|
2059
|
+
}],
|
|
2060
|
+
presets: [
|
|
2061
|
+
{
|
|
2062
|
+
id: "subscription",
|
|
2063
|
+
labels: labels("Subscription", "\u8ba2\u9605\u989d\u5ea6"),
|
|
2064
|
+
sourceId: "usage",
|
|
2065
|
+
order: 0,
|
|
2066
|
+
recommended: true,
|
|
2067
|
+
format: "quota-windows",
|
|
2068
|
+
match: { group: "subscription-windows" }
|
|
2069
|
+
},
|
|
2070
|
+
{
|
|
2071
|
+
id: "credits",
|
|
2072
|
+
labels: labels("Credits", "\u79ef\u5206"),
|
|
2073
|
+
sourceId: "usage",
|
|
2074
|
+
order: 1,
|
|
2075
|
+
recommended: false,
|
|
2076
|
+
format: "amount",
|
|
2077
|
+
match: { resourceIds: ["credits"] }
|
|
2078
|
+
},
|
|
2079
|
+
{
|
|
2080
|
+
id: "reset-tickets",
|
|
2081
|
+
labels: labels("Reset credits", "\u91cd\u7f6e\u5238"),
|
|
2082
|
+
sourceId: "usage",
|
|
2083
|
+
order: 2,
|
|
2084
|
+
recommended: false,
|
|
2085
|
+
format: "entitlement-count",
|
|
2086
|
+
match: { resourceIds: ["reset-summary"] }
|
|
2087
|
+
}
|
|
2088
|
+
]
|
|
2089
|
+
};
|
|
2090
|
+
async function readResourceSource(input) {
|
|
2091
|
+
if (!["usage", "reset-details"].includes(input.sourceId) || input.endpointId !== "subscription") throw failure("Invalid resource source");
|
|
2092
|
+
if (!input.login) return {
|
|
2093
|
+
kind: "unavailable",
|
|
2094
|
+
reason: "auth-required"
|
|
2095
|
+
};
|
|
2096
|
+
const credential = await input.login.get(input.signal);
|
|
2097
|
+
const tokens = parseStored(credential.credential);
|
|
2098
|
+
if (!tokens) return {
|
|
2099
|
+
kind: "unavailable",
|
|
2100
|
+
reason: "auth-required"
|
|
2101
|
+
};
|
|
2102
|
+
const response = await input.queryJSON({
|
|
2103
|
+
requestId: input.sourceId,
|
|
2104
|
+
headers: {
|
|
2105
|
+
Authorization: `Bearer ${tokens.access}`,
|
|
2106
|
+
"ChatGPT-Account-Id": tokens.accountId
|
|
2107
|
+
}
|
|
2108
|
+
});
|
|
2109
|
+
if (response.status === 401) {
|
|
2110
|
+
input.login.expire(credential.credential);
|
|
2111
|
+
return {
|
|
2112
|
+
kind: "unavailable",
|
|
2113
|
+
reason: "auth-required"
|
|
2114
|
+
};
|
|
2115
|
+
}
|
|
2116
|
+
if (response.status === 403) return {
|
|
2117
|
+
kind: "unavailable",
|
|
2118
|
+
reason: "permission-denied"
|
|
2119
|
+
};
|
|
2120
|
+
if (response.status !== 200) throw failure("Resource request failed");
|
|
2121
|
+
return input.sourceId === "usage" ? usage(object(response.body)) : inventory(object(response.body));
|
|
2122
|
+
}
|
|
2123
|
+
function inventory(body) {
|
|
2124
|
+
if (!Array.isArray(body.credits)) throw failure("Invalid resource inventory");
|
|
2125
|
+
const entries = body.credits.slice(0, 100).map((value) => {
|
|
2126
|
+
const entry = object(value);
|
|
2127
|
+
if (typeof entry.id !== "string" || !/^[a-zA-Z0-9_-]{1,120}$/.test(entry.id)) throw failure("Invalid resource inventory");
|
|
2128
|
+
const expiry = date(entry.expires_at);
|
|
2129
|
+
const issued = date(entry.granted_at);
|
|
2130
|
+
return {
|
|
2131
|
+
id: entry.id,
|
|
2132
|
+
purpose: entry.reset_type === "primary" ? labels("Primary quota reset", "\u4e3b\u989d\u5ea6\u91cd\u7f6e") : labels("Quota reset", "\u989d\u5ea6\u91cd\u7f6e"),
|
|
2133
|
+
state: entry.status === "available" || entry.status === "used" || entry.status === "expired" ? entry.status : "unknown",
|
|
2134
|
+
...issued ? { issuedAt: issued } : {},
|
|
2135
|
+
expiry: expiry ? {
|
|
2136
|
+
kind: "at",
|
|
2137
|
+
at: expiry
|
|
2138
|
+
} : { kind: "unknown" }
|
|
2139
|
+
};
|
|
2140
|
+
});
|
|
2141
|
+
const count = body.available_count === void 0 ? String(body.credits.filter((value) => object(value).status === "available").length) : decimal(body.available_count);
|
|
2142
|
+
return {
|
|
2143
|
+
kind: "ready",
|
|
2144
|
+
resources: [{
|
|
2145
|
+
kind: "entitlement",
|
|
2146
|
+
id: "reset-inventory",
|
|
2147
|
+
group: "reset-tickets",
|
|
2148
|
+
labels: labels("Reset credit details", "\u91cd\u7f6e\u5238\u660e\u7ec6"),
|
|
2149
|
+
valueOrigin: body.available_count === void 0 ? "derived" : "reported",
|
|
2150
|
+
meaning: count === "0" ? "exhausted" : "available",
|
|
2151
|
+
availableCount: count,
|
|
2152
|
+
entries,
|
|
2153
|
+
entriesCompleteness: body.credits.length > 100 ? "limited" : "complete",
|
|
2154
|
+
relationships: [{
|
|
2155
|
+
kind: "details-of",
|
|
2156
|
+
resourceId: "reset-summary",
|
|
2157
|
+
unavailable: true
|
|
2158
|
+
}]
|
|
2159
|
+
}]
|
|
2160
|
+
};
|
|
2161
|
+
}
|
|
2162
|
+
function usage(body) {
|
|
2163
|
+
if (!("rate_limit" in body) && !("credits" in body) && !("rate_limit_reset_credits" in body)) throw failure("Invalid resource response");
|
|
2164
|
+
const resources = [];
|
|
2165
|
+
const rate = body.rate_limit == null ? {} : object(body.rate_limit);
|
|
2166
|
+
const rates = [{
|
|
2167
|
+
prefix: "subscription",
|
|
2168
|
+
group: "subscription-windows",
|
|
2169
|
+
rate
|
|
2170
|
+
}];
|
|
2171
|
+
if (body.code_review_rate_limit != null) rates.push({
|
|
2172
|
+
prefix: "code-review",
|
|
2173
|
+
group: "code-review-windows",
|
|
2174
|
+
rate: object(body.code_review_rate_limit)
|
|
2175
|
+
});
|
|
2176
|
+
if (body.additional_rate_limits != null) {
|
|
2177
|
+
if (!Array.isArray(body.additional_rate_limits)) throw failure("Invalid resource response");
|
|
2178
|
+
for (const value of body.additional_rate_limits) {
|
|
2179
|
+
const extra = object(value);
|
|
2180
|
+
const feature = extra.metered_feature;
|
|
2181
|
+
if (typeof feature !== "string" || !/^[a-zA-Z0-9_-]{1,60}$/.test(feature)) throw failure("Invalid resource scope");
|
|
2182
|
+
rates.push({
|
|
2183
|
+
prefix: `additional-${feature}`,
|
|
2184
|
+
group: "additional-windows",
|
|
2185
|
+
rate: object(extra.rate_limit)
|
|
2186
|
+
});
|
|
2187
|
+
}
|
|
2188
|
+
}
|
|
2189
|
+
for (const item of rates) for (const key of ["primary_window", "secondary_window"]) {
|
|
2190
|
+
if (item.rate[key] == null) continue;
|
|
2191
|
+
const window = object(item.rate[key]);
|
|
2192
|
+
const duration = window.limit_window_seconds;
|
|
2193
|
+
if (duration !== void 0 && (typeof duration !== "number" || !Number.isSafeInteger(duration) || duration <= 0)) throw failure("Invalid resource window");
|
|
2194
|
+
const percent = window.used_percent;
|
|
2195
|
+
if (percent !== void 0 && (typeof percent !== "number" || !Number.isFinite(percent) || percent < 0 || percent > 100)) throw failure("Invalid resource percentage");
|
|
2196
|
+
const reset = date(window.reset_at);
|
|
2197
|
+
resources.push({
|
|
2198
|
+
kind: "quota",
|
|
2199
|
+
id: `${item.prefix}-${duration ?? key}`,
|
|
2200
|
+
group: item.group,
|
|
2201
|
+
labels: item.prefix === "subscription" ? labels("Subscription quota", "\u8ba2\u9605\u989d\u5ea6") : item.prefix === "code-review" ? labels("Code review quota", "\u4ee3\u7801\u5ba1\u67e5\u989d\u5ea6") : item.prefix === IMAGE_PREFIX ? labels("Image generation quota", "\u751f\u56fe\u989d\u5ea6") : labels("Additional quota", "\u9644\u52a0\u989d\u5ea6"),
|
|
2202
|
+
...item.prefix.startsWith("additional-") ? { scope: { product: item.prefix.slice(11) } } : {},
|
|
2203
|
+
valueOrigin: "reported",
|
|
2204
|
+
meaning: percent === void 0 ? "unknown" : percent === 100 ? "exhausted" : "available",
|
|
2205
|
+
window: {
|
|
2206
|
+
...typeof duration === "number" ? { durationSeconds: duration } : {},
|
|
2207
|
+
reset: reset ? {
|
|
2208
|
+
kind: "fixed",
|
|
2209
|
+
at: reset
|
|
2210
|
+
} : { kind: "unknown" }
|
|
2211
|
+
},
|
|
2212
|
+
...typeof percent === "number" ? { usedPercent: percent } : {}
|
|
2213
|
+
});
|
|
2214
|
+
}
|
|
2215
|
+
if (body.credits != null) {
|
|
2216
|
+
const credit = object(body.credits);
|
|
2217
|
+
if (credit.balance != null) resources.push({
|
|
2218
|
+
kind: "balance",
|
|
2219
|
+
id: "credits",
|
|
2220
|
+
group: "credits",
|
|
2221
|
+
labels: labels("Credits", "\u79ef\u5206"),
|
|
2222
|
+
valueOrigin: "reported",
|
|
2223
|
+
meaning: credit.unlimited === true ? "unlimited" : Number(decimal(credit.balance)) === 0 ? "exhausted" : "available",
|
|
2224
|
+
remaining: {
|
|
2225
|
+
value: decimal(credit.balance),
|
|
2226
|
+
unit: {
|
|
2227
|
+
kind: "credit",
|
|
2228
|
+
namespace: "chatgpt",
|
|
2229
|
+
label: "Credits"
|
|
2230
|
+
}
|
|
2231
|
+
}
|
|
2232
|
+
});
|
|
2233
|
+
}
|
|
2234
|
+
if (body.rate_limit_reset_credits != null) {
|
|
2235
|
+
const summary = object(body.rate_limit_reset_credits);
|
|
2236
|
+
if (summary.available_count !== void 0) resources.push({
|
|
2237
|
+
kind: "entitlement",
|
|
2238
|
+
id: "reset-summary",
|
|
2239
|
+
group: "reset-tickets",
|
|
2240
|
+
labels: labels("Reset credits", "\u91cd\u7f6e\u5238"),
|
|
2241
|
+
valueOrigin: "reported",
|
|
2242
|
+
meaning: Number(decimal(summary.available_count)) === 0 ? "exhausted" : "available",
|
|
2243
|
+
availableCount: decimal(summary.available_count),
|
|
2244
|
+
...summary.applicable_available_count !== void 0 ? { applicableCount: decimal(summary.applicable_available_count) } : {}
|
|
2245
|
+
});
|
|
2246
|
+
}
|
|
2247
|
+
const plans = {
|
|
2248
|
+
pro: labels("Pro", "Pro"),
|
|
2249
|
+
plus: labels("Plus", "Plus"),
|
|
2250
|
+
free: labels("Free", "\u514d\u8d39"),
|
|
2251
|
+
team: labels("Team", "\u56e2\u961f"),
|
|
2252
|
+
business: labels("Business", "\u4f01\u4e1a"),
|
|
2253
|
+
enterprise: labels("Enterprise", "\u4f01\u4e1a")
|
|
2254
|
+
};
|
|
2255
|
+
const planId = typeof body.plan_type === "string" ? body.plan_type : "";
|
|
2256
|
+
const planLabels = Object.hasOwn(plans, planId) ? plans[planId] : void 0;
|
|
2257
|
+
const plan = planLabels ? {
|
|
2258
|
+
id: planId,
|
|
2259
|
+
labels: planLabels
|
|
2260
|
+
} : void 0;
|
|
2261
|
+
return {
|
|
2262
|
+
kind: "ready",
|
|
2263
|
+
resources,
|
|
2264
|
+
...plan ? { plan } : {},
|
|
2265
|
+
restrictions: [...typeof rate.allowed === "boolean" ? [{
|
|
2266
|
+
id: "usage-blocked",
|
|
2267
|
+
labels: labels("Usage blocked", "\u7528\u91cf\u53d7\u9650"),
|
|
2268
|
+
active: !rate.allowed && rate.limit_reached !== true
|
|
2269
|
+
}] : [], ...typeof rate.limit_reached === "boolean" ? [{
|
|
2270
|
+
id: "limit-reached",
|
|
2271
|
+
labels: labels("Limit reached", "\u5df2\u8fbe\u4e0a\u9650"),
|
|
2272
|
+
active: rate.limit_reached
|
|
2273
|
+
}] : []]
|
|
2274
|
+
};
|
|
2275
|
+
}
|
|
2276
|
+
//#endregion
|
|
2862
2277
|
//#region src/type.ts
|
|
2863
|
-
/** Stable subscription supplier identity. */
|
|
2864
2278
|
const TYPE = "chatgpt";
|
|
2865
|
-
/** Host-managed sealed login field. */
|
|
2866
2279
|
const LOGIN_FIELD = "account";
|
|
2867
|
-
|
|
2868
|
-
function chatgptProviderType(fetch, options = {}, support) {
|
|
2280
|
+
function chatgptProviderType(fetch, options = {}) {
|
|
2869
2281
|
return {
|
|
2870
2282
|
type: TYPE,
|
|
2283
|
+
listingContractVersion: "subscription-capacity-v1",
|
|
2284
|
+
modelFacts,
|
|
2285
|
+
credentialPrincipal: (credential) => parseStored(credential)?.accountId,
|
|
2286
|
+
readResourceSource,
|
|
2871
2287
|
label: "ChatGPT subscription",
|
|
2872
2288
|
fields: [{
|
|
2873
2289
|
key: LOGIN_FIELD,
|
|
@@ -2877,6 +2293,7 @@ function chatgptProviderType(fetch, options = {}, support) {
|
|
|
2877
2293
|
}],
|
|
2878
2294
|
endpoints: [{
|
|
2879
2295
|
id: "subscription",
|
|
2296
|
+
resourceCapability,
|
|
2880
2297
|
label: "ChatGPT subscription",
|
|
2881
2298
|
capabilities: {
|
|
2882
2299
|
chat: {
|
|
@@ -2897,10 +2314,7 @@ function chatgptProviderType(fetch, options = {}, support) {
|
|
|
2897
2314
|
pollMarginMs: options.pollMarginMs ?? 3e3,
|
|
2898
2315
|
userAgent: "yaoguang"
|
|
2899
2316
|
}),
|
|
2900
|
-
catalog
|
|
2901
|
-
...catalog,
|
|
2902
|
-
source: support.catalogueSource("https://models.dev/api.json", "models")
|
|
2903
|
-
} : catalog
|
|
2317
|
+
catalog
|
|
2904
2318
|
};
|
|
2905
2319
|
}
|
|
2906
2320
|
//#endregion
|
|
@@ -2908,7 +2322,6 @@ function chatgptProviderType(fetch, options = {}, support) {
|
|
|
2908
2322
|
const plugin = {
|
|
2909
2323
|
name: "@eum-agent/llm-provider-chatgpt",
|
|
2910
2324
|
requires: [
|
|
2911
|
-
"model-catalogue-sources",
|
|
2912
2325
|
"network",
|
|
2913
2326
|
"openai-responses-codec",
|
|
2914
2327
|
"file-media"
|
|
@@ -2916,10 +2329,9 @@ const plugin = {
|
|
|
2916
2329
|
optionalServices: ["model-support"],
|
|
2917
2330
|
apply(ctx) {
|
|
2918
2331
|
const support = lazySupport(() => ctx.services.find("model-support"));
|
|
2919
|
-
const catalogue = ctx.services.get("model-catalogue-sources");
|
|
2920
2332
|
const network = ctx.services.get("network");
|
|
2921
2333
|
ctx.modelProtocols.register(chatgptProtocolType(support, network.fetch, ctx.services.get("openai-responses-codec"), {}, ctx.services.get("file-media").imageInfo));
|
|
2922
|
-
ctx.modelProviders.register(chatgptProviderType(network.fetch
|
|
2334
|
+
ctx.modelProviders.register(chatgptProviderType(network.fetch));
|
|
2923
2335
|
}
|
|
2924
2336
|
};
|
|
2925
2337
|
//#endregion
|