indusagi 0.13.8 → 0.13.10
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/CHANGELOG.md +6 -0
- package/dist/agent.js +153 -5
- package/dist/ai.js +223 -51
- package/dist/capabilities.js +60 -19
- package/dist/cli.js +60 -19
- package/dist/connectors-saas.js +60 -19
- package/dist/index.js +60 -19
- package/dist/interop.js +60 -19
- package/dist/shell-app.js +60 -19
- package/dist/smithy.js +60 -19
- package/dist/swarm.js +60 -19
- package/dist/types/facade/ml/kit/auth/openai-codex.d.ts +1 -0
- package/dist/types/facade/ml/kit/auth/openai-codex.test.d.ts +1 -0
- package/dist/types/facade/ml/models.generated.d.ts +136 -0
- package/dist/types/facade/ml/models.test.d.ts +1 -0
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
- **OpenAI browser redirect**: retries the registered `localhost:1457` callback when port `1455` is unavailable, and uses the selected redirect URI for both authorization and token exchange.
|
|
7
|
+
- **Framework build dependency**: declares the `proxy-agent` package already used by the Bedrock adapter.
|
|
8
|
+
|
|
3
9
|
## [0.13.3]
|
|
4
10
|
|
|
5
11
|
### Changed
|
package/dist/agent.js
CHANGED
|
@@ -5,8 +5,13 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
5
5
|
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
6
6
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
7
|
});
|
|
8
|
-
var __esm = (fn, res) => function __init() {
|
|
9
|
-
|
|
8
|
+
var __esm = (fn, res, err) => function __init() {
|
|
9
|
+
if (err) throw err[0];
|
|
10
|
+
try {
|
|
11
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
12
|
+
} catch (e) {
|
|
13
|
+
throw err = [e], e;
|
|
14
|
+
}
|
|
10
15
|
};
|
|
11
16
|
|
|
12
17
|
// src/facade/ml/kit/streaming-state-manager.ts
|
|
@@ -4689,6 +4694,75 @@ var MODELS = {
|
|
|
4689
4694
|
contextWindow: 1e6,
|
|
4690
4695
|
maxTokens: 128e3
|
|
4691
4696
|
},
|
|
4697
|
+
"gpt-5.6-sol": {
|
|
4698
|
+
id: "gpt-5.6-sol",
|
|
4699
|
+
name: "GPT-5.6 Sol",
|
|
4700
|
+
api: "openai-responses",
|
|
4701
|
+
provider: "openai",
|
|
4702
|
+
baseUrl: "https://api.openai.com/v1",
|
|
4703
|
+
reasoning: true,
|
|
4704
|
+
input: ["text", "image"],
|
|
4705
|
+
cost: {
|
|
4706
|
+
input: 5,
|
|
4707
|
+
output: 30,
|
|
4708
|
+
cacheRead: 0.5,
|
|
4709
|
+
cacheWrite: 0
|
|
4710
|
+
},
|
|
4711
|
+
contextWindow: 105e4,
|
|
4712
|
+
maxTokens: 128e3
|
|
4713
|
+
},
|
|
4714
|
+
"gpt-5.6-terra": {
|
|
4715
|
+
id: "gpt-5.6-terra",
|
|
4716
|
+
name: "GPT-5.6 Terra",
|
|
4717
|
+
api: "openai-responses",
|
|
4718
|
+
provider: "openai",
|
|
4719
|
+
baseUrl: "https://api.openai.com/v1",
|
|
4720
|
+
reasoning: true,
|
|
4721
|
+
input: ["text", "image"],
|
|
4722
|
+
cost: {
|
|
4723
|
+
input: 2,
|
|
4724
|
+
output: 12,
|
|
4725
|
+
// ponytail: 0 means unavailable cached-input pricing; allow null if the catalog must distinguish it from free.
|
|
4726
|
+
cacheRead: 0,
|
|
4727
|
+
cacheWrite: 0
|
|
4728
|
+
},
|
|
4729
|
+
contextWindow: 105e4,
|
|
4730
|
+
maxTokens: 128e3
|
|
4731
|
+
},
|
|
4732
|
+
"gpt-5.6-luna": {
|
|
4733
|
+
id: "gpt-5.6-luna",
|
|
4734
|
+
name: "GPT-5.6 Luna",
|
|
4735
|
+
api: "openai-responses",
|
|
4736
|
+
provider: "openai",
|
|
4737
|
+
baseUrl: "https://api.openai.com/v1",
|
|
4738
|
+
reasoning: true,
|
|
4739
|
+
input: ["text", "image"],
|
|
4740
|
+
cost: {
|
|
4741
|
+
input: 0.2,
|
|
4742
|
+
output: 1.2,
|
|
4743
|
+
cacheRead: 0,
|
|
4744
|
+
cacheWrite: 0
|
|
4745
|
+
},
|
|
4746
|
+
contextWindow: 105e4,
|
|
4747
|
+
maxTokens: 128e3
|
|
4748
|
+
},
|
|
4749
|
+
"gpt-5.6": {
|
|
4750
|
+
id: "gpt-5.6",
|
|
4751
|
+
name: "GPT-5.6",
|
|
4752
|
+
api: "openai-responses",
|
|
4753
|
+
provider: "openai",
|
|
4754
|
+
baseUrl: "https://api.openai.com/v1",
|
|
4755
|
+
reasoning: true,
|
|
4756
|
+
input: ["text", "image"],
|
|
4757
|
+
cost: {
|
|
4758
|
+
input: 5,
|
|
4759
|
+
output: 30,
|
|
4760
|
+
cacheRead: 0.5,
|
|
4761
|
+
cacheWrite: 0
|
|
4762
|
+
},
|
|
4763
|
+
contextWindow: 105e4,
|
|
4764
|
+
maxTokens: 128e3
|
|
4765
|
+
},
|
|
4692
4766
|
"o1": {
|
|
4693
4767
|
id: "o1",
|
|
4694
4768
|
name: "o1",
|
|
@@ -5013,6 +5087,75 @@ var MODELS = {
|
|
|
5013
5087
|
},
|
|
5014
5088
|
contextWindow: 1e6,
|
|
5015
5089
|
maxTokens: 128e3
|
|
5090
|
+
},
|
|
5091
|
+
"gpt-5.6-sol": {
|
|
5092
|
+
id: "gpt-5.6-sol",
|
|
5093
|
+
name: "GPT-5.6 Sol",
|
|
5094
|
+
api: "openai-codex-responses",
|
|
5095
|
+
provider: "openai-codex",
|
|
5096
|
+
baseUrl: "https://chatgpt.com/backend-api",
|
|
5097
|
+
reasoning: true,
|
|
5098
|
+
input: ["text", "image"],
|
|
5099
|
+
cost: {
|
|
5100
|
+
input: 5,
|
|
5101
|
+
output: 30,
|
|
5102
|
+
cacheRead: 0.5,
|
|
5103
|
+
cacheWrite: 0
|
|
5104
|
+
},
|
|
5105
|
+
contextWindow: 105e4,
|
|
5106
|
+
maxTokens: 128e3
|
|
5107
|
+
},
|
|
5108
|
+
"gpt-5.6-terra": {
|
|
5109
|
+
id: "gpt-5.6-terra",
|
|
5110
|
+
name: "GPT-5.6 Terra",
|
|
5111
|
+
api: "openai-codex-responses",
|
|
5112
|
+
provider: "openai-codex",
|
|
5113
|
+
baseUrl: "https://chatgpt.com/backend-api",
|
|
5114
|
+
reasoning: true,
|
|
5115
|
+
input: ["text", "image"],
|
|
5116
|
+
cost: {
|
|
5117
|
+
input: 2,
|
|
5118
|
+
output: 12,
|
|
5119
|
+
// ponytail: 0 means unavailable cached-input pricing; allow null if the catalog must distinguish it from free.
|
|
5120
|
+
cacheRead: 0,
|
|
5121
|
+
cacheWrite: 0
|
|
5122
|
+
},
|
|
5123
|
+
contextWindow: 105e4,
|
|
5124
|
+
maxTokens: 128e3
|
|
5125
|
+
},
|
|
5126
|
+
"gpt-5.6-luna": {
|
|
5127
|
+
id: "gpt-5.6-luna",
|
|
5128
|
+
name: "GPT-5.6 Luna",
|
|
5129
|
+
api: "openai-codex-responses",
|
|
5130
|
+
provider: "openai-codex",
|
|
5131
|
+
baseUrl: "https://chatgpt.com/backend-api",
|
|
5132
|
+
reasoning: true,
|
|
5133
|
+
input: ["text", "image"],
|
|
5134
|
+
cost: {
|
|
5135
|
+
input: 0.2,
|
|
5136
|
+
output: 1.2,
|
|
5137
|
+
cacheRead: 0,
|
|
5138
|
+
cacheWrite: 0
|
|
5139
|
+
},
|
|
5140
|
+
contextWindow: 105e4,
|
|
5141
|
+
maxTokens: 128e3
|
|
5142
|
+
},
|
|
5143
|
+
"gpt-5.6": {
|
|
5144
|
+
id: "gpt-5.6",
|
|
5145
|
+
name: "GPT-5.6",
|
|
5146
|
+
api: "openai-codex-responses",
|
|
5147
|
+
provider: "openai-codex",
|
|
5148
|
+
baseUrl: "https://chatgpt.com/backend-api",
|
|
5149
|
+
reasoning: true,
|
|
5150
|
+
input: ["text", "image"],
|
|
5151
|
+
cost: {
|
|
5152
|
+
input: 5,
|
|
5153
|
+
output: 30,
|
|
5154
|
+
cacheRead: 0.5,
|
|
5155
|
+
cacheWrite: 0
|
|
5156
|
+
},
|
|
5157
|
+
contextWindow: 105e4,
|
|
5158
|
+
maxTokens: 128e3
|
|
5016
5159
|
}
|
|
5017
5160
|
},
|
|
5018
5161
|
"opencode": {
|
|
@@ -16864,8 +17007,8 @@ function buildHeaders(initHeaders, additionalHeaders, accountId, token, sessionI
|
|
|
16864
17007
|
headers.set("Authorization", `Bearer ${token}`);
|
|
16865
17008
|
headers.set("chatgpt-account-id", accountId);
|
|
16866
17009
|
headers.set("OpenAI-Beta", "responses=experimental");
|
|
16867
|
-
headers.set("originator", "
|
|
16868
|
-
const userAgent = _os ? `
|
|
17010
|
+
headers.set("originator", "pi");
|
|
17011
|
+
const userAgent = _os ? `pi (${_os.platform()} ${_os.release()}; ${_os.arch()})` : "pi (browser)";
|
|
16869
17012
|
headers.set("User-Agent", userAgent);
|
|
16870
17013
|
headers.set("accept", "text/event-stream");
|
|
16871
17014
|
headers.set("content-type", "application/json");
|
|
@@ -18394,7 +18537,12 @@ function ensureNodeBuiltins() {
|
|
|
18394
18537
|
});
|
|
18395
18538
|
}
|
|
18396
18539
|
ensureNodeBuiltins();
|
|
18397
|
-
var
|
|
18540
|
+
var DEFAULT_CLIENT_ID = "app_EMoamEEZ73f0CkXaXp7hrann";
|
|
18541
|
+
var UNREGISTERED_CLIENT_ID = "<UNREGISTERED-OPENAI-CODEX-APP>";
|
|
18542
|
+
function resolveOpenAICodexClientId(configured = process.env.INDUSAGI_OPENAI_CODEX_CLIENT_ID) {
|
|
18543
|
+
return configured && configured !== UNREGISTERED_CLIENT_ID ? configured : DEFAULT_CLIENT_ID;
|
|
18544
|
+
}
|
|
18545
|
+
var CLIENT_ID2 = resolveOpenAICodexClientId();
|
|
18398
18546
|
|
|
18399
18547
|
// src/facade/ml/kit/overflow.ts
|
|
18400
18548
|
var OVERFLOW_PATTERN_CONFIG = [
|
package/dist/ai.js
CHANGED
|
@@ -8,8 +8,13 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
8
8
|
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
9
9
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
10
10
|
});
|
|
11
|
-
var __esm = (fn, res) => function __init() {
|
|
12
|
-
|
|
11
|
+
var __esm = (fn, res, err) => function __init() {
|
|
12
|
+
if (err) throw err[0];
|
|
13
|
+
try {
|
|
14
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
15
|
+
} catch (e) {
|
|
16
|
+
throw err = [e], e;
|
|
17
|
+
}
|
|
13
18
|
};
|
|
14
19
|
var __export = (target, all) => {
|
|
15
20
|
for (var name in all)
|
|
@@ -4813,6 +4818,75 @@ var MODELS = {
|
|
|
4813
4818
|
contextWindow: 1e6,
|
|
4814
4819
|
maxTokens: 128e3
|
|
4815
4820
|
},
|
|
4821
|
+
"gpt-5.6-sol": {
|
|
4822
|
+
id: "gpt-5.6-sol",
|
|
4823
|
+
name: "GPT-5.6 Sol",
|
|
4824
|
+
api: "openai-responses",
|
|
4825
|
+
provider: "openai",
|
|
4826
|
+
baseUrl: "https://api.openai.com/v1",
|
|
4827
|
+
reasoning: true,
|
|
4828
|
+
input: ["text", "image"],
|
|
4829
|
+
cost: {
|
|
4830
|
+
input: 5,
|
|
4831
|
+
output: 30,
|
|
4832
|
+
cacheRead: 0.5,
|
|
4833
|
+
cacheWrite: 0
|
|
4834
|
+
},
|
|
4835
|
+
contextWindow: 105e4,
|
|
4836
|
+
maxTokens: 128e3
|
|
4837
|
+
},
|
|
4838
|
+
"gpt-5.6-terra": {
|
|
4839
|
+
id: "gpt-5.6-terra",
|
|
4840
|
+
name: "GPT-5.6 Terra",
|
|
4841
|
+
api: "openai-responses",
|
|
4842
|
+
provider: "openai",
|
|
4843
|
+
baseUrl: "https://api.openai.com/v1",
|
|
4844
|
+
reasoning: true,
|
|
4845
|
+
input: ["text", "image"],
|
|
4846
|
+
cost: {
|
|
4847
|
+
input: 2,
|
|
4848
|
+
output: 12,
|
|
4849
|
+
// ponytail: 0 means unavailable cached-input pricing; allow null if the catalog must distinguish it from free.
|
|
4850
|
+
cacheRead: 0,
|
|
4851
|
+
cacheWrite: 0
|
|
4852
|
+
},
|
|
4853
|
+
contextWindow: 105e4,
|
|
4854
|
+
maxTokens: 128e3
|
|
4855
|
+
},
|
|
4856
|
+
"gpt-5.6-luna": {
|
|
4857
|
+
id: "gpt-5.6-luna",
|
|
4858
|
+
name: "GPT-5.6 Luna",
|
|
4859
|
+
api: "openai-responses",
|
|
4860
|
+
provider: "openai",
|
|
4861
|
+
baseUrl: "https://api.openai.com/v1",
|
|
4862
|
+
reasoning: true,
|
|
4863
|
+
input: ["text", "image"],
|
|
4864
|
+
cost: {
|
|
4865
|
+
input: 0.2,
|
|
4866
|
+
output: 1.2,
|
|
4867
|
+
cacheRead: 0,
|
|
4868
|
+
cacheWrite: 0
|
|
4869
|
+
},
|
|
4870
|
+
contextWindow: 105e4,
|
|
4871
|
+
maxTokens: 128e3
|
|
4872
|
+
},
|
|
4873
|
+
"gpt-5.6": {
|
|
4874
|
+
id: "gpt-5.6",
|
|
4875
|
+
name: "GPT-5.6",
|
|
4876
|
+
api: "openai-responses",
|
|
4877
|
+
provider: "openai",
|
|
4878
|
+
baseUrl: "https://api.openai.com/v1",
|
|
4879
|
+
reasoning: true,
|
|
4880
|
+
input: ["text", "image"],
|
|
4881
|
+
cost: {
|
|
4882
|
+
input: 5,
|
|
4883
|
+
output: 30,
|
|
4884
|
+
cacheRead: 0.5,
|
|
4885
|
+
cacheWrite: 0
|
|
4886
|
+
},
|
|
4887
|
+
contextWindow: 105e4,
|
|
4888
|
+
maxTokens: 128e3
|
|
4889
|
+
},
|
|
4816
4890
|
"o1": {
|
|
4817
4891
|
id: "o1",
|
|
4818
4892
|
name: "o1",
|
|
@@ -5137,6 +5211,75 @@ var MODELS = {
|
|
|
5137
5211
|
},
|
|
5138
5212
|
contextWindow: 1e6,
|
|
5139
5213
|
maxTokens: 128e3
|
|
5214
|
+
},
|
|
5215
|
+
"gpt-5.6-sol": {
|
|
5216
|
+
id: "gpt-5.6-sol",
|
|
5217
|
+
name: "GPT-5.6 Sol",
|
|
5218
|
+
api: "openai-codex-responses",
|
|
5219
|
+
provider: "openai-codex",
|
|
5220
|
+
baseUrl: "https://chatgpt.com/backend-api",
|
|
5221
|
+
reasoning: true,
|
|
5222
|
+
input: ["text", "image"],
|
|
5223
|
+
cost: {
|
|
5224
|
+
input: 5,
|
|
5225
|
+
output: 30,
|
|
5226
|
+
cacheRead: 0.5,
|
|
5227
|
+
cacheWrite: 0
|
|
5228
|
+
},
|
|
5229
|
+
contextWindow: 105e4,
|
|
5230
|
+
maxTokens: 128e3
|
|
5231
|
+
},
|
|
5232
|
+
"gpt-5.6-terra": {
|
|
5233
|
+
id: "gpt-5.6-terra",
|
|
5234
|
+
name: "GPT-5.6 Terra",
|
|
5235
|
+
api: "openai-codex-responses",
|
|
5236
|
+
provider: "openai-codex",
|
|
5237
|
+
baseUrl: "https://chatgpt.com/backend-api",
|
|
5238
|
+
reasoning: true,
|
|
5239
|
+
input: ["text", "image"],
|
|
5240
|
+
cost: {
|
|
5241
|
+
input: 2,
|
|
5242
|
+
output: 12,
|
|
5243
|
+
// ponytail: 0 means unavailable cached-input pricing; allow null if the catalog must distinguish it from free.
|
|
5244
|
+
cacheRead: 0,
|
|
5245
|
+
cacheWrite: 0
|
|
5246
|
+
},
|
|
5247
|
+
contextWindow: 105e4,
|
|
5248
|
+
maxTokens: 128e3
|
|
5249
|
+
},
|
|
5250
|
+
"gpt-5.6-luna": {
|
|
5251
|
+
id: "gpt-5.6-luna",
|
|
5252
|
+
name: "GPT-5.6 Luna",
|
|
5253
|
+
api: "openai-codex-responses",
|
|
5254
|
+
provider: "openai-codex",
|
|
5255
|
+
baseUrl: "https://chatgpt.com/backend-api",
|
|
5256
|
+
reasoning: true,
|
|
5257
|
+
input: ["text", "image"],
|
|
5258
|
+
cost: {
|
|
5259
|
+
input: 0.2,
|
|
5260
|
+
output: 1.2,
|
|
5261
|
+
cacheRead: 0,
|
|
5262
|
+
cacheWrite: 0
|
|
5263
|
+
},
|
|
5264
|
+
contextWindow: 105e4,
|
|
5265
|
+
maxTokens: 128e3
|
|
5266
|
+
},
|
|
5267
|
+
"gpt-5.6": {
|
|
5268
|
+
id: "gpt-5.6",
|
|
5269
|
+
name: "GPT-5.6",
|
|
5270
|
+
api: "openai-codex-responses",
|
|
5271
|
+
provider: "openai-codex",
|
|
5272
|
+
baseUrl: "https://chatgpt.com/backend-api",
|
|
5273
|
+
reasoning: true,
|
|
5274
|
+
input: ["text", "image"],
|
|
5275
|
+
cost: {
|
|
5276
|
+
input: 5,
|
|
5277
|
+
output: 30,
|
|
5278
|
+
cacheRead: 0.5,
|
|
5279
|
+
cacheWrite: 0
|
|
5280
|
+
},
|
|
5281
|
+
contextWindow: 105e4,
|
|
5282
|
+
maxTokens: 128e3
|
|
5140
5283
|
}
|
|
5141
5284
|
},
|
|
5142
5285
|
"opencode": {
|
|
@@ -17077,8 +17220,8 @@ function buildHeaders(initHeaders, additionalHeaders, accountId, token, sessionI
|
|
|
17077
17220
|
headers.set("Authorization", `Bearer ${token}`);
|
|
17078
17221
|
headers.set("chatgpt-account-id", accountId);
|
|
17079
17222
|
headers.set("OpenAI-Beta", "responses=experimental");
|
|
17080
|
-
headers.set("originator", "
|
|
17081
|
-
const userAgent = _os ? `
|
|
17223
|
+
headers.set("originator", "pi");
|
|
17224
|
+
const userAgent = _os ? `pi (${_os.platform()} ${_os.release()}; ${_os.arch()})` : "pi (browser)";
|
|
17082
17225
|
headers.set("User-Agent", userAgent);
|
|
17083
17226
|
headers.set("accept", "text/event-stream");
|
|
17084
17227
|
headers.set("content-type", "application/json");
|
|
@@ -19132,18 +19275,24 @@ function ensureNodeBuiltins() {
|
|
|
19132
19275
|
});
|
|
19133
19276
|
}
|
|
19134
19277
|
ensureNodeBuiltins();
|
|
19135
|
-
var
|
|
19278
|
+
var DEFAULT_CLIENT_ID = "app_EMoamEEZ73f0CkXaXp7hrann";
|
|
19279
|
+
var UNREGISTERED_CLIENT_ID = "<UNREGISTERED-OPENAI-CODEX-APP>";
|
|
19280
|
+
function resolveOpenAICodexClientId(configured = process.env.INDUSAGI_OPENAI_CODEX_CLIENT_ID) {
|
|
19281
|
+
return configured && configured !== UNREGISTERED_CLIENT_ID ? configured : DEFAULT_CLIENT_ID;
|
|
19282
|
+
}
|
|
19283
|
+
var CLIENT_ID2 = resolveOpenAICodexClientId();
|
|
19136
19284
|
var AUTHORIZE_URL2 = "https://auth.openai.com/oauth/authorize";
|
|
19137
19285
|
var TOKEN_URL2 = "https://auth.openai.com/oauth/token";
|
|
19138
19286
|
var REDIRECT_URI2 = "http://localhost:1455/auth/callback";
|
|
19139
|
-
var
|
|
19287
|
+
var FALLBACK_REDIRECT_URI = "http://localhost:1457/auth/callback";
|
|
19288
|
+
var SCOPE = "openid profile email offline_access api.connectors.read api.connectors.invoke";
|
|
19140
19289
|
var JWT_CLAIM_PATH2 = "https://api.openai.com/auth";
|
|
19141
19290
|
function createState() {
|
|
19142
19291
|
const { randomBytes } = nodeBuiltins;
|
|
19143
19292
|
if (!randomBytes) {
|
|
19144
19293
|
throw new Error("Codex sign-in needs a Node or Bun runtime and cannot run inside a browser.");
|
|
19145
19294
|
}
|
|
19146
|
-
return randomBytes(
|
|
19295
|
+
return randomBytes(32).toString("hex");
|
|
19147
19296
|
}
|
|
19148
19297
|
function readCodeAndState(params) {
|
|
19149
19298
|
return {
|
|
@@ -19204,13 +19353,12 @@ async function exchangeAuthorizationCode(code, verifier, redirectUri = REDIRECT_
|
|
|
19204
19353
|
})
|
|
19205
19354
|
});
|
|
19206
19355
|
if (!response.ok) {
|
|
19207
|
-
|
|
19208
|
-
console.error("[openai-codex] exchanging the code for a token failed:", response.status, text);
|
|
19356
|
+
console.error("[openai-codex] exchanging the code for a token failed:", response.status);
|
|
19209
19357
|
return { type: "failed" };
|
|
19210
19358
|
}
|
|
19211
19359
|
const json = await response.json();
|
|
19212
19360
|
if (!json.access_token || !json.refresh_token || typeof json.expires_in !== "number") {
|
|
19213
|
-
console.error("[openai-codex] token response was missing required fields
|
|
19361
|
+
console.error("[openai-codex] token response was missing required fields");
|
|
19214
19362
|
return { type: "failed" };
|
|
19215
19363
|
}
|
|
19216
19364
|
return {
|
|
@@ -19232,13 +19380,12 @@ async function refreshAccessToken(refreshToken) {
|
|
|
19232
19380
|
})
|
|
19233
19381
|
});
|
|
19234
19382
|
if (!response.ok) {
|
|
19235
|
-
|
|
19236
|
-
console.error("[openai-codex] refreshing the token failed:", response.status, text);
|
|
19383
|
+
console.error("[openai-codex] refreshing the token failed:", response.status);
|
|
19237
19384
|
return { type: "failed" };
|
|
19238
19385
|
}
|
|
19239
19386
|
const json = await response.json();
|
|
19240
19387
|
if (!json.access_token || !json.refresh_token || typeof json.expires_in !== "number") {
|
|
19241
|
-
console.error("[openai-codex] refresh response was missing required fields
|
|
19388
|
+
console.error("[openai-codex] refresh response was missing required fields");
|
|
19242
19389
|
return { type: "failed" };
|
|
19243
19390
|
}
|
|
19244
19391
|
return {
|
|
@@ -19247,27 +19394,27 @@ async function refreshAccessToken(refreshToken) {
|
|
|
19247
19394
|
refresh: json.refresh_token,
|
|
19248
19395
|
expires: Date.now() + json.expires_in * 1e3
|
|
19249
19396
|
};
|
|
19250
|
-
} catch
|
|
19251
|
-
console.error("[openai-codex] token refresh
|
|
19397
|
+
} catch {
|
|
19398
|
+
console.error("[openai-codex] token refresh failed");
|
|
19252
19399
|
return { type: "failed" };
|
|
19253
19400
|
}
|
|
19254
19401
|
}
|
|
19255
|
-
async function createAuthorizationFlow(originator = process.env.INDUSAGI_OPENAI_CODEX_ORIGINATOR ?? "
|
|
19402
|
+
async function createAuthorizationFlow(originator = process.env.INDUSAGI_OPENAI_CODEX_ORIGINATOR ?? "codex_cli_rs") {
|
|
19256
19403
|
const { verifier, challenge } = await generatePKCE();
|
|
19257
19404
|
const state = createState();
|
|
19258
|
-
const query = new URLSearchParams(
|
|
19259
|
-
|
|
19260
|
-
|
|
19261
|
-
redirect_uri
|
|
19262
|
-
scope
|
|
19263
|
-
|
|
19264
|
-
|
|
19265
|
-
|
|
19266
|
-
|
|
19267
|
-
|
|
19268
|
-
originator
|
|
19269
|
-
|
|
19270
|
-
const url = `${AUTHORIZE_URL2}?${query
|
|
19405
|
+
const query = new URLSearchParams([
|
|
19406
|
+
["response_type", "code"],
|
|
19407
|
+
["client_id", CLIENT_ID2],
|
|
19408
|
+
["redirect_uri", REDIRECT_URI2],
|
|
19409
|
+
["scope", SCOPE],
|
|
19410
|
+
["code_challenge", challenge],
|
|
19411
|
+
["code_challenge_method", "S256"],
|
|
19412
|
+
["id_token_add_organizations", "true"],
|
|
19413
|
+
["codex_cli_simplified_flow", "true"],
|
|
19414
|
+
["state", state],
|
|
19415
|
+
["originator", originator]
|
|
19416
|
+
]);
|
|
19417
|
+
const url = `${AUTHORIZE_URL2}?${query}`;
|
|
19271
19418
|
return { verifier, state, url };
|
|
19272
19419
|
}
|
|
19273
19420
|
function createSingleShotGate() {
|
|
@@ -19322,27 +19469,47 @@ function startLocalOAuthServer(state) {
|
|
|
19322
19469
|
} catch {
|
|
19323
19470
|
}
|
|
19324
19471
|
};
|
|
19325
|
-
|
|
19326
|
-
|
|
19327
|
-
|
|
19328
|
-
|
|
19329
|
-
|
|
19330
|
-
|
|
19331
|
-
|
|
19332
|
-
|
|
19333
|
-
|
|
19334
|
-
|
|
19335
|
-
|
|
19336
|
-
);
|
|
19337
|
-
|
|
19338
|
-
|
|
19339
|
-
|
|
19340
|
-
|
|
19341
|
-
},
|
|
19342
|
-
waitForCode: async () => null
|
|
19343
|
-
});
|
|
19344
|
-
});
|
|
19472
|
+
const listen = (port) => new Promise((resolve) => {
|
|
19473
|
+
const cleanup = () => {
|
|
19474
|
+
server.off("error", onError);
|
|
19475
|
+
server.off("listening", onListening);
|
|
19476
|
+
};
|
|
19477
|
+
const onError = () => {
|
|
19478
|
+
cleanup();
|
|
19479
|
+
resolve(false);
|
|
19480
|
+
};
|
|
19481
|
+
const onListening = () => {
|
|
19482
|
+
cleanup();
|
|
19483
|
+
resolve(true);
|
|
19484
|
+
};
|
|
19485
|
+
server.once("error", onError);
|
|
19486
|
+
server.once("listening", onListening);
|
|
19487
|
+
server.listen(port, "127.0.0.1");
|
|
19345
19488
|
});
|
|
19489
|
+
return (async () => {
|
|
19490
|
+
for (const [port, redirectUri] of [
|
|
19491
|
+
[1455, REDIRECT_URI2],
|
|
19492
|
+
[1457, FALLBACK_REDIRECT_URI]
|
|
19493
|
+
]) {
|
|
19494
|
+
if (await listen(port)) {
|
|
19495
|
+
return {
|
|
19496
|
+
close: closeQuietly,
|
|
19497
|
+
cancelWait: () => gate.resolve(null),
|
|
19498
|
+
redirectUri,
|
|
19499
|
+
waitForCode: () => gate.promise
|
|
19500
|
+
};
|
|
19501
|
+
}
|
|
19502
|
+
}
|
|
19503
|
+
console.error("[openai-codex] callback ports 1455 and 1457 are unavailable; using manual code entry.");
|
|
19504
|
+
gate.resolve(null);
|
|
19505
|
+
return {
|
|
19506
|
+
close: closeQuietly,
|
|
19507
|
+
cancelWait: () => {
|
|
19508
|
+
},
|
|
19509
|
+
redirectUri: REDIRECT_URI2,
|
|
19510
|
+
waitForCode: async () => null
|
|
19511
|
+
};
|
|
19512
|
+
})();
|
|
19346
19513
|
}
|
|
19347
19514
|
function getAccountId(accessToken) {
|
|
19348
19515
|
const payload = decodeJwt(accessToken);
|
|
@@ -19353,7 +19520,12 @@ function getAccountId(accessToken) {
|
|
|
19353
19520
|
async function loginOpenAICodex(options) {
|
|
19354
19521
|
const { verifier, state, url } = await createAuthorizationFlow(options.originator);
|
|
19355
19522
|
const server = await startLocalOAuthServer(state);
|
|
19356
|
-
|
|
19523
|
+
const authorizationUrl = new URL(url);
|
|
19524
|
+
authorizationUrl.searchParams.set("redirect_uri", server.redirectUri);
|
|
19525
|
+
options.onAuth({
|
|
19526
|
+
url: authorizationUrl.toString(),
|
|
19527
|
+
instructions: "Opening your browser \u2014 finish signing in there to continue."
|
|
19528
|
+
});
|
|
19357
19529
|
const codeFromPastedInput = (pasted) => {
|
|
19358
19530
|
const parsed = parseAuthorizationInput(pasted);
|
|
19359
19531
|
if (parsed.state && parsed.state !== state) {
|
|
@@ -19406,7 +19578,7 @@ async function loginOpenAICodex(options) {
|
|
|
19406
19578
|
if (!code) {
|
|
19407
19579
|
throw new Error("No authorization code was provided to complete sign-in.");
|
|
19408
19580
|
}
|
|
19409
|
-
const tokenResult = await exchangeAuthorizationCode(code, verifier);
|
|
19581
|
+
const tokenResult = await exchangeAuthorizationCode(code, verifier, server.redirectUri);
|
|
19410
19582
|
if (tokenResult.type !== "success") {
|
|
19411
19583
|
throw new Error("Could not trade the authorization code for an access token");
|
|
19412
19584
|
}
|