@schuttdev/gigai 0.1.0-beta.15 → 0.1.0-beta.17
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 +56 -17
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -51,8 +51,8 @@ function getOrgUUID() {
|
|
|
51
51
|
if (process.env.GIGAI_ORG_UUID) {
|
|
52
52
|
return process.env.GIGAI_ORG_UUID;
|
|
53
53
|
}
|
|
54
|
-
const proxyUrl = process.env.
|
|
55
|
-
const jwtMatch = proxyUrl.match(
|
|
54
|
+
const proxyUrl = process.env.HTTPS_PROXY || process.env.HTTP_PROXY || "";
|
|
55
|
+
const jwtMatch = proxyUrl.match(/jwt_([^@]+)/);
|
|
56
56
|
if (jwtMatch) {
|
|
57
57
|
try {
|
|
58
58
|
const payload = decodeJWTPayload(jwtMatch[1]);
|
|
@@ -62,18 +62,25 @@ function getOrgUUID() {
|
|
|
62
62
|
} catch {
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
|
+
const anthropicProxy = process.env.ANTHROPIC_PROXY_URL ?? "";
|
|
66
|
+
const anthropicJwtMatch = anthropicProxy.match(/([A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+)/);
|
|
67
|
+
if (anthropicJwtMatch) {
|
|
68
|
+
try {
|
|
69
|
+
const payload = decodeJWTPayload(anthropicJwtMatch[1]);
|
|
70
|
+
if (payload.organization_uuid) {
|
|
71
|
+
return payload.organization_uuid;
|
|
72
|
+
}
|
|
73
|
+
} catch {
|
|
74
|
+
}
|
|
75
|
+
}
|
|
65
76
|
const apiKey = process.env.ANTHROPIC_API_KEY ?? "";
|
|
66
|
-
if (apiKey.includes("
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const payload = decodeJWTPayload(jwtPart);
|
|
72
|
-
if (payload.organization_uuid) {
|
|
73
|
-
return payload.organization_uuid;
|
|
74
|
-
}
|
|
75
|
-
} catch {
|
|
77
|
+
if (apiKey.includes(".")) {
|
|
78
|
+
try {
|
|
79
|
+
const payload = decodeJWTPayload(apiKey);
|
|
80
|
+
if (payload.organization_uuid) {
|
|
81
|
+
return payload.organization_uuid;
|
|
76
82
|
}
|
|
83
|
+
} catch {
|
|
77
84
|
}
|
|
78
85
|
}
|
|
79
86
|
throw new Error(
|
|
@@ -82,6 +89,23 @@ function getOrgUUID() {
|
|
|
82
89
|
}
|
|
83
90
|
|
|
84
91
|
// src/http.ts
|
|
92
|
+
async function getProxyDispatcher() {
|
|
93
|
+
const proxyUrl = process.env.HTTPS_PROXY || process.env.HTTP_PROXY;
|
|
94
|
+
if (!proxyUrl) return void 0;
|
|
95
|
+
try {
|
|
96
|
+
const undici = await import("undici");
|
|
97
|
+
return new undici.ProxyAgent(proxyUrl);
|
|
98
|
+
} catch {
|
|
99
|
+
return void 0;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
var _dispatcher = null;
|
|
103
|
+
async function ensureDispatcher() {
|
|
104
|
+
if (_dispatcher === null) {
|
|
105
|
+
_dispatcher = await getProxyDispatcher();
|
|
106
|
+
}
|
|
107
|
+
return _dispatcher;
|
|
108
|
+
}
|
|
85
109
|
function createHttpClient(serverUrl, sessionToken) {
|
|
86
110
|
const baseUrl = serverUrl.replace(/\/$/, "");
|
|
87
111
|
async function request(path, init = {}) {
|
|
@@ -94,10 +118,15 @@ function createHttpClient(serverUrl, sessionToken) {
|
|
|
94
118
|
if (!headers["Content-Type"] && init.body && typeof init.body === "string") {
|
|
95
119
|
headers["Content-Type"] = "application/json";
|
|
96
120
|
}
|
|
97
|
-
const
|
|
121
|
+
const dispatcher = await ensureDispatcher();
|
|
122
|
+
const fetchOpts = {
|
|
98
123
|
...init,
|
|
99
124
|
headers
|
|
100
|
-
}
|
|
125
|
+
};
|
|
126
|
+
if (dispatcher) {
|
|
127
|
+
fetchOpts.dispatcher = dispatcher;
|
|
128
|
+
}
|
|
129
|
+
const res = await fetch(`${baseUrl}${path}`, fetchOpts);
|
|
101
130
|
if (!res.ok) {
|
|
102
131
|
let errorBody;
|
|
103
132
|
try {
|
|
@@ -124,11 +153,16 @@ function createHttpClient(serverUrl, sessionToken) {
|
|
|
124
153
|
if (sessionToken) {
|
|
125
154
|
headers["Authorization"] = `Bearer ${sessionToken}`;
|
|
126
155
|
}
|
|
127
|
-
const
|
|
156
|
+
const dispatcher = await ensureDispatcher();
|
|
157
|
+
const fetchOpts = {
|
|
128
158
|
method: "POST",
|
|
129
159
|
headers,
|
|
130
160
|
body: formData
|
|
131
|
-
}
|
|
161
|
+
};
|
|
162
|
+
if (dispatcher) {
|
|
163
|
+
fetchOpts.dispatcher = dispatcher;
|
|
164
|
+
}
|
|
165
|
+
const res = await fetch(`${baseUrl}${path}`, fetchOpts);
|
|
132
166
|
if (!res.ok) {
|
|
133
167
|
let errorBody;
|
|
134
168
|
try {
|
|
@@ -144,7 +178,12 @@ function createHttpClient(serverUrl, sessionToken) {
|
|
|
144
178
|
if (sessionToken) {
|
|
145
179
|
headers["Authorization"] = `Bearer ${sessionToken}`;
|
|
146
180
|
}
|
|
147
|
-
const
|
|
181
|
+
const dispatcher = await ensureDispatcher();
|
|
182
|
+
const fetchOpts = { headers };
|
|
183
|
+
if (dispatcher) {
|
|
184
|
+
fetchOpts.dispatcher = dispatcher;
|
|
185
|
+
}
|
|
186
|
+
const res = await fetch(`${baseUrl}${path}`, fetchOpts);
|
|
148
187
|
if (!res.ok) {
|
|
149
188
|
throw new Error(`HTTP ${res.status}: ${res.statusText}`);
|
|
150
189
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@schuttdev/gigai",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.17",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"gigai": "dist/index.js"
|
|
@@ -30,7 +30,8 @@
|
|
|
30
30
|
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
31
31
|
"@inquirer/prompts": "^7.0.0",
|
|
32
32
|
"nanoid": "^5.0.0",
|
|
33
|
-
"zod": "^3.22.0"
|
|
33
|
+
"zod": "^3.22.0",
|
|
34
|
+
"undici": "^6.0.0"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
37
|
"@gigai/shared": "*",
|