@schuttdev/gigai 0.2.5 → 0.2.7
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/{dist-G2KJBUZX.js → dist-MGLETZTT.js} +283 -30
- package/dist/index.js +155 -963
- package/package.json +3 -4
- package/dist/chunk-7C3UYEKE.js +0 -281
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@schuttdev/gigai",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"gigai": "dist/index.js"
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"citty": "^0.1.6",
|
|
25
|
+
"zod": "^3.22.0",
|
|
25
26
|
"fastify": "^4.25.0",
|
|
26
27
|
"@fastify/cors": "^9.0.0",
|
|
27
28
|
"@fastify/rate-limit": "^9.0.0",
|
|
@@ -29,9 +30,7 @@
|
|
|
29
30
|
"fastify-plugin": "^4.5.0",
|
|
30
31
|
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
31
32
|
"@inquirer/prompts": "^7.0.0",
|
|
32
|
-
"nanoid": "^5.0.0"
|
|
33
|
-
"zod": "^3.22.0",
|
|
34
|
-
"undici": "^6.0.0"
|
|
33
|
+
"nanoid": "^5.0.0"
|
|
35
34
|
},
|
|
36
35
|
"devDependencies": {
|
|
37
36
|
"@gigai/shared": "*",
|
package/dist/chunk-7C3UYEKE.js
DELETED
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// ../shared/dist/index.mjs
|
|
4
|
-
import { randomBytes, createCipheriv, createDecipheriv } from "crypto";
|
|
5
|
-
import { z } from "zod";
|
|
6
|
-
var ALGORITHM = "aes-256-gcm";
|
|
7
|
-
var IV_LENGTH = 12;
|
|
8
|
-
var TAG_LENGTH = 16;
|
|
9
|
-
function encrypt(payload, key) {
|
|
10
|
-
const keyBuffer = Buffer.from(key, "hex");
|
|
11
|
-
if (keyBuffer.length !== 32) {
|
|
12
|
-
throw new Error("Encryption key must be 32 bytes (64 hex chars)");
|
|
13
|
-
}
|
|
14
|
-
const iv = randomBytes(IV_LENGTH);
|
|
15
|
-
const cipher = createCipheriv(ALGORITHM, keyBuffer, iv, {
|
|
16
|
-
authTagLength: TAG_LENGTH
|
|
17
|
-
});
|
|
18
|
-
const plaintext = JSON.stringify(payload);
|
|
19
|
-
const encrypted = Buffer.concat([
|
|
20
|
-
cipher.update(plaintext, "utf8"),
|
|
21
|
-
cipher.final()
|
|
22
|
-
]);
|
|
23
|
-
const tag = cipher.getAuthTag();
|
|
24
|
-
return {
|
|
25
|
-
iv: iv.toString("base64"),
|
|
26
|
-
ciphertext: encrypted.toString("base64"),
|
|
27
|
-
tag: tag.toString("base64")
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
function decrypt(encrypted, key) {
|
|
31
|
-
const keyBuffer = Buffer.from(key, "hex");
|
|
32
|
-
if (keyBuffer.length !== 32) {
|
|
33
|
-
throw new Error("Encryption key must be 32 bytes (64 hex chars)");
|
|
34
|
-
}
|
|
35
|
-
const iv = Buffer.from(encrypted.iv, "base64");
|
|
36
|
-
const ciphertext = Buffer.from(encrypted.ciphertext, "base64");
|
|
37
|
-
const tag = Buffer.from(encrypted.tag, "base64");
|
|
38
|
-
const decipher = createDecipheriv(ALGORITHM, keyBuffer, iv, {
|
|
39
|
-
authTagLength: TAG_LENGTH
|
|
40
|
-
});
|
|
41
|
-
decipher.setAuthTag(tag);
|
|
42
|
-
const decrypted = Buffer.concat([
|
|
43
|
-
decipher.update(ciphertext),
|
|
44
|
-
decipher.final()
|
|
45
|
-
]);
|
|
46
|
-
return JSON.parse(decrypted.toString("utf8"));
|
|
47
|
-
}
|
|
48
|
-
function generateEncryptionKey() {
|
|
49
|
-
return randomBytes(32).toString("hex");
|
|
50
|
-
}
|
|
51
|
-
var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
|
|
52
|
-
ErrorCode2["PAIRING_EXPIRED"] = "PAIRING_EXPIRED";
|
|
53
|
-
ErrorCode2["PAIRING_INVALID"] = "PAIRING_INVALID";
|
|
54
|
-
ErrorCode2["PAIRING_USED"] = "PAIRING_USED";
|
|
55
|
-
ErrorCode2["TOKEN_INVALID"] = "TOKEN_INVALID";
|
|
56
|
-
ErrorCode2["TOKEN_DECRYPT_FAILED"] = "TOKEN_DECRYPT_FAILED";
|
|
57
|
-
ErrorCode2["ORG_MISMATCH"] = "ORG_MISMATCH";
|
|
58
|
-
ErrorCode2["SESSION_EXPIRED"] = "SESSION_EXPIRED";
|
|
59
|
-
ErrorCode2["SESSION_INVALID"] = "SESSION_INVALID";
|
|
60
|
-
ErrorCode2["AUTH_REQUIRED"] = "AUTH_REQUIRED";
|
|
61
|
-
ErrorCode2["TOOL_NOT_FOUND"] = "TOOL_NOT_FOUND";
|
|
62
|
-
ErrorCode2["EXEC_TIMEOUT"] = "EXEC_TIMEOUT";
|
|
63
|
-
ErrorCode2["EXEC_FAILED"] = "EXEC_FAILED";
|
|
64
|
-
ErrorCode2["HTTPS_REQUIRED"] = "HTTPS_REQUIRED";
|
|
65
|
-
ErrorCode2["RATE_LIMITED"] = "RATE_LIMITED";
|
|
66
|
-
ErrorCode2["VALIDATION_ERROR"] = "VALIDATION_ERROR";
|
|
67
|
-
ErrorCode2["INTERNAL_ERROR"] = "INTERNAL_ERROR";
|
|
68
|
-
ErrorCode2["MCP_ERROR"] = "MCP_ERROR";
|
|
69
|
-
ErrorCode2["MCP_NOT_CONNECTED"] = "MCP_NOT_CONNECTED";
|
|
70
|
-
ErrorCode2["TRANSFER_NOT_FOUND"] = "TRANSFER_NOT_FOUND";
|
|
71
|
-
ErrorCode2["TRANSFER_EXPIRED"] = "TRANSFER_EXPIRED";
|
|
72
|
-
ErrorCode2["PATH_NOT_ALLOWED"] = "PATH_NOT_ALLOWED";
|
|
73
|
-
ErrorCode2["COMMAND_NOT_ALLOWED"] = "COMMAND_NOT_ALLOWED";
|
|
74
|
-
return ErrorCode2;
|
|
75
|
-
})(ErrorCode || {});
|
|
76
|
-
var STATUS_CODES = {
|
|
77
|
-
[
|
|
78
|
-
"PAIRING_EXPIRED"
|
|
79
|
-
/* PAIRING_EXPIRED */
|
|
80
|
-
]: 410,
|
|
81
|
-
[
|
|
82
|
-
"PAIRING_INVALID"
|
|
83
|
-
/* PAIRING_INVALID */
|
|
84
|
-
]: 400,
|
|
85
|
-
[
|
|
86
|
-
"PAIRING_USED"
|
|
87
|
-
/* PAIRING_USED */
|
|
88
|
-
]: 409,
|
|
89
|
-
[
|
|
90
|
-
"TOKEN_INVALID"
|
|
91
|
-
/* TOKEN_INVALID */
|
|
92
|
-
]: 401,
|
|
93
|
-
[
|
|
94
|
-
"TOKEN_DECRYPT_FAILED"
|
|
95
|
-
/* TOKEN_DECRYPT_FAILED */
|
|
96
|
-
]: 401,
|
|
97
|
-
[
|
|
98
|
-
"ORG_MISMATCH"
|
|
99
|
-
/* ORG_MISMATCH */
|
|
100
|
-
]: 403,
|
|
101
|
-
[
|
|
102
|
-
"SESSION_EXPIRED"
|
|
103
|
-
/* SESSION_EXPIRED */
|
|
104
|
-
]: 401,
|
|
105
|
-
[
|
|
106
|
-
"SESSION_INVALID"
|
|
107
|
-
/* SESSION_INVALID */
|
|
108
|
-
]: 401,
|
|
109
|
-
[
|
|
110
|
-
"AUTH_REQUIRED"
|
|
111
|
-
/* AUTH_REQUIRED */
|
|
112
|
-
]: 401,
|
|
113
|
-
[
|
|
114
|
-
"TOOL_NOT_FOUND"
|
|
115
|
-
/* TOOL_NOT_FOUND */
|
|
116
|
-
]: 404,
|
|
117
|
-
[
|
|
118
|
-
"EXEC_TIMEOUT"
|
|
119
|
-
/* EXEC_TIMEOUT */
|
|
120
|
-
]: 408,
|
|
121
|
-
[
|
|
122
|
-
"EXEC_FAILED"
|
|
123
|
-
/* EXEC_FAILED */
|
|
124
|
-
]: 500,
|
|
125
|
-
[
|
|
126
|
-
"HTTPS_REQUIRED"
|
|
127
|
-
/* HTTPS_REQUIRED */
|
|
128
|
-
]: 403,
|
|
129
|
-
[
|
|
130
|
-
"RATE_LIMITED"
|
|
131
|
-
/* RATE_LIMITED */
|
|
132
|
-
]: 429,
|
|
133
|
-
[
|
|
134
|
-
"VALIDATION_ERROR"
|
|
135
|
-
/* VALIDATION_ERROR */
|
|
136
|
-
]: 400,
|
|
137
|
-
[
|
|
138
|
-
"INTERNAL_ERROR"
|
|
139
|
-
/* INTERNAL_ERROR */
|
|
140
|
-
]: 500,
|
|
141
|
-
[
|
|
142
|
-
"MCP_ERROR"
|
|
143
|
-
/* MCP_ERROR */
|
|
144
|
-
]: 502,
|
|
145
|
-
[
|
|
146
|
-
"MCP_NOT_CONNECTED"
|
|
147
|
-
/* MCP_NOT_CONNECTED */
|
|
148
|
-
]: 503,
|
|
149
|
-
[
|
|
150
|
-
"TRANSFER_NOT_FOUND"
|
|
151
|
-
/* TRANSFER_NOT_FOUND */
|
|
152
|
-
]: 404,
|
|
153
|
-
[
|
|
154
|
-
"TRANSFER_EXPIRED"
|
|
155
|
-
/* TRANSFER_EXPIRED */
|
|
156
|
-
]: 410,
|
|
157
|
-
[
|
|
158
|
-
"PATH_NOT_ALLOWED"
|
|
159
|
-
/* PATH_NOT_ALLOWED */
|
|
160
|
-
]: 403,
|
|
161
|
-
[
|
|
162
|
-
"COMMAND_NOT_ALLOWED"
|
|
163
|
-
/* COMMAND_NOT_ALLOWED */
|
|
164
|
-
]: 403
|
|
165
|
-
};
|
|
166
|
-
var GigaiError = class extends Error {
|
|
167
|
-
code;
|
|
168
|
-
statusCode;
|
|
169
|
-
details;
|
|
170
|
-
constructor(code, message, details) {
|
|
171
|
-
super(message);
|
|
172
|
-
this.name = "GigaiError";
|
|
173
|
-
this.code = code;
|
|
174
|
-
this.statusCode = STATUS_CODES[code];
|
|
175
|
-
this.details = details;
|
|
176
|
-
}
|
|
177
|
-
toJSON() {
|
|
178
|
-
return {
|
|
179
|
-
error: {
|
|
180
|
-
code: this.code,
|
|
181
|
-
message: this.message,
|
|
182
|
-
...this.details !== void 0 && { details: this.details }
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
var TailscaleHttpsConfigSchema = z.object({
|
|
188
|
-
provider: z.literal("tailscale"),
|
|
189
|
-
funnelPort: z.number().optional()
|
|
190
|
-
});
|
|
191
|
-
var CloudflareHttpsConfigSchema = z.object({
|
|
192
|
-
provider: z.literal("cloudflare"),
|
|
193
|
-
tunnelName: z.string(),
|
|
194
|
-
domain: z.string().optional()
|
|
195
|
-
});
|
|
196
|
-
var ManualHttpsConfigSchema = z.object({
|
|
197
|
-
provider: z.literal("manual"),
|
|
198
|
-
certPath: z.string(),
|
|
199
|
-
keyPath: z.string()
|
|
200
|
-
});
|
|
201
|
-
var HttpsConfigSchema = z.discriminatedUnion("provider", [
|
|
202
|
-
TailscaleHttpsConfigSchema,
|
|
203
|
-
CloudflareHttpsConfigSchema,
|
|
204
|
-
ManualHttpsConfigSchema
|
|
205
|
-
]);
|
|
206
|
-
var CliToolConfigSchema = z.object({
|
|
207
|
-
type: z.literal("cli"),
|
|
208
|
-
name: z.string(),
|
|
209
|
-
command: z.string(),
|
|
210
|
-
args: z.array(z.string()).optional(),
|
|
211
|
-
description: z.string(),
|
|
212
|
-
timeout: z.number().optional(),
|
|
213
|
-
cwd: z.string().optional(),
|
|
214
|
-
env: z.record(z.string()).optional()
|
|
215
|
-
});
|
|
216
|
-
var McpToolConfigSchema = z.object({
|
|
217
|
-
type: z.literal("mcp"),
|
|
218
|
-
name: z.string(),
|
|
219
|
-
command: z.string(),
|
|
220
|
-
args: z.array(z.string()).optional(),
|
|
221
|
-
description: z.string(),
|
|
222
|
-
env: z.record(z.string()).optional()
|
|
223
|
-
});
|
|
224
|
-
var ScriptToolConfigSchema = z.object({
|
|
225
|
-
type: z.literal("script"),
|
|
226
|
-
name: z.string(),
|
|
227
|
-
path: z.string(),
|
|
228
|
-
description: z.string(),
|
|
229
|
-
timeout: z.number().optional(),
|
|
230
|
-
interpreter: z.string().optional()
|
|
231
|
-
});
|
|
232
|
-
var BuiltinToolConfigSchema = z.object({
|
|
233
|
-
type: z.literal("builtin"),
|
|
234
|
-
name: z.string(),
|
|
235
|
-
builtin: z.enum(["filesystem", "shell"]),
|
|
236
|
-
description: z.string(),
|
|
237
|
-
config: z.record(z.unknown()).optional()
|
|
238
|
-
});
|
|
239
|
-
var ToolConfigSchema = z.discriminatedUnion("type", [
|
|
240
|
-
CliToolConfigSchema,
|
|
241
|
-
McpToolConfigSchema,
|
|
242
|
-
ScriptToolConfigSchema,
|
|
243
|
-
BuiltinToolConfigSchema
|
|
244
|
-
]);
|
|
245
|
-
var AuthConfigSchema = z.object({
|
|
246
|
-
encryptionKey: z.string().length(64),
|
|
247
|
-
pairingTtlSeconds: z.number().default(300),
|
|
248
|
-
sessionTtlSeconds: z.number().default(14400)
|
|
249
|
-
});
|
|
250
|
-
var ServerConfigSchema = z.object({
|
|
251
|
-
port: z.number().default(7443),
|
|
252
|
-
host: z.string().default("0.0.0.0"),
|
|
253
|
-
https: HttpsConfigSchema.optional()
|
|
254
|
-
});
|
|
255
|
-
var GigaiConfigSchema = z.object({
|
|
256
|
-
serverName: z.string().optional(),
|
|
257
|
-
server: ServerConfigSchema,
|
|
258
|
-
auth: AuthConfigSchema,
|
|
259
|
-
tools: z.array(ToolConfigSchema).default([])
|
|
260
|
-
});
|
|
261
|
-
function decodeJWTPayload(token) {
|
|
262
|
-
const parts = token.split(".");
|
|
263
|
-
if (parts.length !== 3) {
|
|
264
|
-
throw new Error("Invalid JWT format: expected 3 segments");
|
|
265
|
-
}
|
|
266
|
-
const payload = parts[1];
|
|
267
|
-
const base64 = payload.replace(/-/g, "+").replace(/_/g, "/");
|
|
268
|
-
const padded = base64 + "=".repeat((4 - base64.length % 4) % 4);
|
|
269
|
-
const decoded = Buffer.from(padded, "base64").toString("utf8");
|
|
270
|
-
return JSON.parse(decoded);
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
export {
|
|
274
|
-
encrypt,
|
|
275
|
-
decrypt,
|
|
276
|
-
generateEncryptionKey,
|
|
277
|
-
ErrorCode,
|
|
278
|
-
GigaiError,
|
|
279
|
-
GigaiConfigSchema,
|
|
280
|
-
decodeJWTPayload
|
|
281
|
-
};
|