critiqs-react 0.0.0-stage → 0.3.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/AGENT_SETUP.md +190 -0
- package/LICENSE +21 -0
- package/README.md +341 -2
- package/bin/cli.d.mts +21 -0
- package/bin/cli.mjs +293 -0
- package/bin/critiqs.mjs +4 -0
- package/bin/env.d.mts +41 -0
- package/bin/env.mjs +384 -0
- package/bin/init.d.mts +126 -0
- package/bin/init.mjs +965 -0
- package/bin/mcp.d.mts +20 -0
- package/bin/mcp.mjs +314 -0
- package/bin/setup.d.mts +183 -0
- package/bin/setup.mjs +1054 -0
- package/dist/Critiqs.d.ts +9 -0
- package/dist/backend/convex/_generated/api.d.ts +95 -0
- package/dist/backend/convex/_generated/api.js +23 -0
- package/dist/backend/convex/_generated/dataModel.d.ts +60 -0
- package/dist/backend/convex/_generated/server.d.ts +162 -0
- package/dist/backend/convex/_generated/server.js +101 -0
- package/dist/backend/convex/ai.ts +93 -0
- package/dist/backend/convex/aiSettings.ts +43 -0
- package/dist/backend/convex/auth.config.ts +18 -0
- package/dist/backend/convex/captureHttp.ts +96 -0
- package/dist/backend/convex/captures.ts +167 -0
- package/dist/backend/convex/crons.ts +14 -0
- package/dist/backend/convex/deviceSignIn.ts +151 -0
- package/dist/backend/convex/grouping.ts +41 -0
- package/dist/backend/convex/http.ts +724 -0
- package/dist/backend/convex/lib/ai.ts +6 -0
- package/dist/backend/convex/lib/links.ts +12 -0
- package/dist/backend/convex/lib/pages.ts +207 -0
- package/dist/backend/convex/lib/r2.ts +75 -0
- package/dist/backend/convex/lib/store.ts +509 -0
- package/dist/backend/convex/lib/tokens.ts +101 -0
- package/dist/backend/convex/lib/validators.ts +73 -0
- package/dist/backend/convex/lib/vendor/aws4fetch.js +289 -0
- package/dist/backend/convex/lib/vendor/critiqs_ai.js +49081 -0
- package/dist/backend/convex/lib/vendor/critiqs_core.js +385 -0
- package/dist/backend/convex/lib/vendor/critiqs_server.js +3108 -0
- package/dist/backend/convex/notificationEmails.ts +61 -0
- package/dist/backend/convex/notifications.ts +182 -0
- package/dist/backend/convex/plans.ts +67 -0
- package/dist/backend/convex/projects.ts +46 -0
- package/dist/backend/convex/schema.ts +343 -0
- package/dist/backend/convex/search.ts +26 -0
- package/dist/backend/convex/signIn.ts +368 -0
- package/dist/backend/convex/tags.ts +68 -0
- package/dist/backend/convex/threads.ts +146 -0
- package/dist/backend/convex/users.ts +13 -0
- package/dist/constants.d.ts +4 -0
- package/dist/core/types.d.ts +72 -0
- package/dist/host.d.ts +66 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +8076 -0
- package/dist/server/chunks/driver-n9zpr0k3.js +21 -0
- package/dist/server/chunks/index-9bg7tmnq.js +522 -0
- package/dist/server/chunks/index-askcfn7t.js +148 -0
- package/dist/server/chunks/providers-rv184xvj.js +48444 -0
- package/dist/server/chunks/token-kzddms7r.js +63 -0
- package/dist/server/chunks/token-util-k8bee1wc.js +4 -0
- package/dist/server/index.d.ts +87 -0
- package/dist/server/index.js +4889 -0
- package/package.json +77 -4
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// ../server/src/sqlite/driver.ts
|
|
2
|
+
function bunDriver(db) {
|
|
3
|
+
return {
|
|
4
|
+
exec: (sql) => void db.exec(sql),
|
|
5
|
+
run: (sql, params = []) => void db.query(sql).run(...params),
|
|
6
|
+
get: (sql, params = []) => db.query(sql).get(...params) ?? undefined,
|
|
7
|
+
all: (sql, params = []) => db.query(sql).all(...params)
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function preparedDriver(db) {
|
|
11
|
+
return {
|
|
12
|
+
exec: (sql) => void db.exec(sql),
|
|
13
|
+
run: (sql, params = []) => void db.prepare(sql).run(...params),
|
|
14
|
+
get: (sql, params = []) => db.prepare(sql).get(...params) ?? undefined,
|
|
15
|
+
all: (sql, params = []) => db.prepare(sql).all(...params)
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
bunDriver,
|
|
20
|
+
preparedDriver
|
|
21
|
+
};
|
|
@@ -0,0 +1,522 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
function __accessProp(key) {
|
|
8
|
+
return this[key];
|
|
9
|
+
}
|
|
10
|
+
var __toESMCache_node;
|
|
11
|
+
var __toESMCache_esm;
|
|
12
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
13
|
+
var canCache = mod != null && typeof mod === "object";
|
|
14
|
+
if (canCache) {
|
|
15
|
+
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
16
|
+
var cached = cache.get(mod);
|
|
17
|
+
if (cached)
|
|
18
|
+
return cached;
|
|
19
|
+
}
|
|
20
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
21
|
+
const to = isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
22
|
+
if (mod && typeof mod === "object" || typeof mod === "function") {
|
|
23
|
+
for (let key of __getOwnPropNames(mod))
|
|
24
|
+
if (!__hasOwnProp.call(to, key))
|
|
25
|
+
__defProp(to, key, {
|
|
26
|
+
get: __accessProp.bind(mod, key),
|
|
27
|
+
enumerable: true
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (canCache)
|
|
31
|
+
cache.set(mod, to);
|
|
32
|
+
return to;
|
|
33
|
+
};
|
|
34
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
35
|
+
var __returnValue = (v) => v;
|
|
36
|
+
function __exportSetter(name, newValue) {
|
|
37
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
38
|
+
}
|
|
39
|
+
var __export = (target, all) => {
|
|
40
|
+
for (var name in all)
|
|
41
|
+
__defProp(target, name, {
|
|
42
|
+
get: all[name],
|
|
43
|
+
enumerable: true,
|
|
44
|
+
configurable: true,
|
|
45
|
+
set: __exportSetter.bind(all, name)
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
49
|
+
|
|
50
|
+
// ../../node_modules/.bun/@vercel+oidc@3.2.0/node_modules/@vercel/oidc/dist/token-error.js
|
|
51
|
+
var require_token_error = __commonJS(function(exports, module) {
|
|
52
|
+
var __defProp = Object.defineProperty;
|
|
53
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
54
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
55
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
56
|
+
var __export = (target, all) => {
|
|
57
|
+
for (var name in all)
|
|
58
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
59
|
+
};
|
|
60
|
+
var __copyProps = (to, from, except, desc) => {
|
|
61
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
62
|
+
for (let key of __getOwnPropNames(from))
|
|
63
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
64
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
65
|
+
}
|
|
66
|
+
return to;
|
|
67
|
+
};
|
|
68
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
69
|
+
var token_error_exports = {};
|
|
70
|
+
__export(token_error_exports, {
|
|
71
|
+
VercelOidcTokenError: () => VercelOidcTokenError
|
|
72
|
+
});
|
|
73
|
+
module.exports = __toCommonJS(token_error_exports);
|
|
74
|
+
|
|
75
|
+
class VercelOidcTokenError extends Error {
|
|
76
|
+
constructor(message, cause) {
|
|
77
|
+
super(message);
|
|
78
|
+
this.name = "VercelOidcTokenError";
|
|
79
|
+
this.cause = cause;
|
|
80
|
+
}
|
|
81
|
+
toString() {
|
|
82
|
+
if (this.cause) {
|
|
83
|
+
return `${this.name}: ${this.message}: ${this.cause}`;
|
|
84
|
+
}
|
|
85
|
+
return `${this.name}: ${this.message}`;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// ../../node_modules/.bun/@vercel+oidc@3.2.0/node_modules/@vercel/oidc/dist/token-io.js
|
|
91
|
+
var require_token_io = __commonJS(function(exports, module) {
|
|
92
|
+
var __create = Object.create;
|
|
93
|
+
var __defProp = Object.defineProperty;
|
|
94
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
95
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
96
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
97
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
98
|
+
var __export = (target, all) => {
|
|
99
|
+
for (var name in all)
|
|
100
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
101
|
+
};
|
|
102
|
+
var __copyProps = (to, from, except, desc) => {
|
|
103
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
104
|
+
for (let key of __getOwnPropNames(from))
|
|
105
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
106
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
107
|
+
}
|
|
108
|
+
return to;
|
|
109
|
+
};
|
|
110
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
111
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
112
|
+
var token_io_exports = {};
|
|
113
|
+
__export(token_io_exports, {
|
|
114
|
+
findRootDir: () => findRootDir,
|
|
115
|
+
getUserDataDir: () => getUserDataDir
|
|
116
|
+
});
|
|
117
|
+
module.exports = __toCommonJS(token_io_exports);
|
|
118
|
+
var import_path = __toESM(__require("path"));
|
|
119
|
+
var import_fs = __toESM(__require("fs"));
|
|
120
|
+
var import_os = __toESM(__require("os"));
|
|
121
|
+
var import_token_error = require_token_error();
|
|
122
|
+
function findRootDir() {
|
|
123
|
+
try {
|
|
124
|
+
let dir = process.cwd();
|
|
125
|
+
while (dir !== import_path.default.dirname(dir)) {
|
|
126
|
+
const pkgPath = import_path.default.join(dir, ".vercel");
|
|
127
|
+
if (import_fs.default.existsSync(pkgPath)) {
|
|
128
|
+
return dir;
|
|
129
|
+
}
|
|
130
|
+
dir = import_path.default.dirname(dir);
|
|
131
|
+
}
|
|
132
|
+
} catch (e) {
|
|
133
|
+
throw new import_token_error.VercelOidcTokenError("Token refresh only supported in node server environments");
|
|
134
|
+
}
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
function getUserDataDir() {
|
|
138
|
+
if (process.env.XDG_DATA_HOME) {
|
|
139
|
+
return process.env.XDG_DATA_HOME;
|
|
140
|
+
}
|
|
141
|
+
switch (import_os.default.platform()) {
|
|
142
|
+
case "darwin":
|
|
143
|
+
return import_path.default.join(import_os.default.homedir(), "Library/Application Support");
|
|
144
|
+
case "linux":
|
|
145
|
+
return import_path.default.join(import_os.default.homedir(), ".local/share");
|
|
146
|
+
case "win32":
|
|
147
|
+
if (process.env.LOCALAPPDATA) {
|
|
148
|
+
return process.env.LOCALAPPDATA;
|
|
149
|
+
}
|
|
150
|
+
return null;
|
|
151
|
+
default:
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
// ../../node_modules/.bun/@vercel+oidc@3.2.0/node_modules/@vercel/oidc/dist/auth-config.js
|
|
158
|
+
var require_auth_config = __commonJS(function(exports, module) {
|
|
159
|
+
var __create = Object.create;
|
|
160
|
+
var __defProp = Object.defineProperty;
|
|
161
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
162
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
163
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
164
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
165
|
+
var __export = (target, all) => {
|
|
166
|
+
for (var name in all)
|
|
167
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
168
|
+
};
|
|
169
|
+
var __copyProps = (to, from, except, desc) => {
|
|
170
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
171
|
+
for (let key of __getOwnPropNames(from))
|
|
172
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
173
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
174
|
+
}
|
|
175
|
+
return to;
|
|
176
|
+
};
|
|
177
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
178
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
179
|
+
var auth_config_exports = {};
|
|
180
|
+
__export(auth_config_exports, {
|
|
181
|
+
isValidAccessToken: () => isValidAccessToken,
|
|
182
|
+
readAuthConfig: () => readAuthConfig,
|
|
183
|
+
writeAuthConfig: () => writeAuthConfig
|
|
184
|
+
});
|
|
185
|
+
module.exports = __toCommonJS(auth_config_exports);
|
|
186
|
+
var fs = __toESM(__require("fs"));
|
|
187
|
+
var path = __toESM(__require("path"));
|
|
188
|
+
var import_token_util = require_token_util();
|
|
189
|
+
function getAuthConfigPath() {
|
|
190
|
+
const dataDir = (0, import_token_util.getVercelDataDir)();
|
|
191
|
+
if (!dataDir) {
|
|
192
|
+
throw new Error(`Unable to find Vercel CLI data directory. Your platform: ${process.platform}. Supported: darwin, linux, win32.`);
|
|
193
|
+
}
|
|
194
|
+
return path.join(dataDir, "auth.json");
|
|
195
|
+
}
|
|
196
|
+
function readAuthConfig() {
|
|
197
|
+
try {
|
|
198
|
+
const authPath = getAuthConfigPath();
|
|
199
|
+
if (!fs.existsSync(authPath)) {
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
const content = fs.readFileSync(authPath, "utf8");
|
|
203
|
+
if (!content) {
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
return JSON.parse(content);
|
|
207
|
+
} catch (error) {
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
function writeAuthConfig(config) {
|
|
212
|
+
const authPath = getAuthConfigPath();
|
|
213
|
+
const authDir = path.dirname(authPath);
|
|
214
|
+
if (!fs.existsSync(authDir)) {
|
|
215
|
+
fs.mkdirSync(authDir, { mode: 504, recursive: true });
|
|
216
|
+
}
|
|
217
|
+
fs.writeFileSync(authPath, JSON.stringify(config, null, 2), { mode: 384 });
|
|
218
|
+
}
|
|
219
|
+
function isValidAccessToken(authConfig, expirationBufferMs = 0) {
|
|
220
|
+
if (!authConfig.token)
|
|
221
|
+
return false;
|
|
222
|
+
if (typeof authConfig.expiresAt !== "number")
|
|
223
|
+
return true;
|
|
224
|
+
const nowInSeconds = Math.floor(Date.now() / 1000);
|
|
225
|
+
const bufferInSeconds = expirationBufferMs / 1000;
|
|
226
|
+
return authConfig.expiresAt >= nowInSeconds + bufferInSeconds;
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
// ../../node_modules/.bun/@vercel+oidc@3.2.0/node_modules/@vercel/oidc/dist/oauth.js
|
|
231
|
+
var require_oauth = __commonJS(function(exports, module) {
|
|
232
|
+
var __defProp = Object.defineProperty;
|
|
233
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
234
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
235
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
236
|
+
var __export = (target, all) => {
|
|
237
|
+
for (var name in all)
|
|
238
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
239
|
+
};
|
|
240
|
+
var __copyProps = (to, from, except, desc) => {
|
|
241
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
242
|
+
for (let key of __getOwnPropNames(from))
|
|
243
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
244
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
245
|
+
}
|
|
246
|
+
return to;
|
|
247
|
+
};
|
|
248
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
249
|
+
var oauth_exports = {};
|
|
250
|
+
__export(oauth_exports, {
|
|
251
|
+
processTokenResponse: () => processTokenResponse,
|
|
252
|
+
refreshTokenRequest: () => refreshTokenRequest
|
|
253
|
+
});
|
|
254
|
+
module.exports = __toCommonJS(oauth_exports);
|
|
255
|
+
var import_os = __require("os");
|
|
256
|
+
var VERCEL_ISSUER = "https://vercel.com";
|
|
257
|
+
var VERCEL_CLI_CLIENT_ID = "cl_HYyOPBNtFMfHhaUn9L4QPfTZz6TP47bp";
|
|
258
|
+
var userAgent = `@vercel/oidc node-${process.version} ${(0, import_os.platform)()} (${(0, import_os.arch)()}) ${(0, import_os.hostname)()}`;
|
|
259
|
+
var _tokenEndpoint = null;
|
|
260
|
+
async function getTokenEndpoint() {
|
|
261
|
+
if (_tokenEndpoint) {
|
|
262
|
+
return _tokenEndpoint;
|
|
263
|
+
}
|
|
264
|
+
const discoveryUrl = `${VERCEL_ISSUER}/.well-known/openid-configuration`;
|
|
265
|
+
const response = await fetch(discoveryUrl, {
|
|
266
|
+
headers: { "user-agent": userAgent }
|
|
267
|
+
});
|
|
268
|
+
if (!response.ok) {
|
|
269
|
+
throw new Error("Failed to discover OAuth endpoints");
|
|
270
|
+
}
|
|
271
|
+
const metadata = await response.json();
|
|
272
|
+
if (!metadata || typeof metadata.token_endpoint !== "string") {
|
|
273
|
+
throw new Error("Invalid OAuth discovery response");
|
|
274
|
+
}
|
|
275
|
+
const endpoint = metadata.token_endpoint;
|
|
276
|
+
_tokenEndpoint = endpoint;
|
|
277
|
+
return endpoint;
|
|
278
|
+
}
|
|
279
|
+
async function refreshTokenRequest(options) {
|
|
280
|
+
const tokenEndpoint = await getTokenEndpoint();
|
|
281
|
+
return await fetch(tokenEndpoint, {
|
|
282
|
+
method: "POST",
|
|
283
|
+
headers: {
|
|
284
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
285
|
+
"user-agent": userAgent
|
|
286
|
+
},
|
|
287
|
+
body: new URLSearchParams({
|
|
288
|
+
client_id: VERCEL_CLI_CLIENT_ID,
|
|
289
|
+
grant_type: "refresh_token",
|
|
290
|
+
...options
|
|
291
|
+
})
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
async function processTokenResponse(response) {
|
|
295
|
+
const json = await response.json();
|
|
296
|
+
if (!response.ok) {
|
|
297
|
+
const errorMsg = typeof json === "object" && json && "error" in json ? String(json.error) : "Token refresh failed";
|
|
298
|
+
return [new Error(errorMsg)];
|
|
299
|
+
}
|
|
300
|
+
if (typeof json !== "object" || json === null) {
|
|
301
|
+
return [new Error("Invalid token response")];
|
|
302
|
+
}
|
|
303
|
+
if (typeof json.access_token !== "string") {
|
|
304
|
+
return [new Error("Missing access_token in response")];
|
|
305
|
+
}
|
|
306
|
+
if (json.token_type !== "Bearer") {
|
|
307
|
+
return [new Error("Invalid token_type in response")];
|
|
308
|
+
}
|
|
309
|
+
if (typeof json.expires_in !== "number") {
|
|
310
|
+
return [new Error("Missing expires_in in response")];
|
|
311
|
+
}
|
|
312
|
+
return [null, json];
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
// ../../node_modules/.bun/@vercel+oidc@3.2.0/node_modules/@vercel/oidc/dist/auth-errors.js
|
|
317
|
+
var require_auth_errors = __commonJS(function(exports, module) {
|
|
318
|
+
var __defProp = Object.defineProperty;
|
|
319
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
320
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
321
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
322
|
+
var __export = (target, all) => {
|
|
323
|
+
for (var name in all)
|
|
324
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
325
|
+
};
|
|
326
|
+
var __copyProps = (to, from, except, desc) => {
|
|
327
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
328
|
+
for (let key of __getOwnPropNames(from))
|
|
329
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
330
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
331
|
+
}
|
|
332
|
+
return to;
|
|
333
|
+
};
|
|
334
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
335
|
+
var auth_errors_exports = {};
|
|
336
|
+
__export(auth_errors_exports, {
|
|
337
|
+
AccessTokenMissingError: () => AccessTokenMissingError,
|
|
338
|
+
RefreshAccessTokenFailedError: () => RefreshAccessTokenFailedError
|
|
339
|
+
});
|
|
340
|
+
module.exports = __toCommonJS(auth_errors_exports);
|
|
341
|
+
|
|
342
|
+
class AccessTokenMissingError extends Error {
|
|
343
|
+
constructor() {
|
|
344
|
+
super("No authentication found. Please log in with the Vercel CLI (vercel login).");
|
|
345
|
+
this.name = "AccessTokenMissingError";
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
class RefreshAccessTokenFailedError extends Error {
|
|
350
|
+
constructor(cause) {
|
|
351
|
+
super("Failed to refresh authentication token.", { cause });
|
|
352
|
+
this.name = "RefreshAccessTokenFailedError";
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
// ../../node_modules/.bun/@vercel+oidc@3.2.0/node_modules/@vercel/oidc/dist/token-util.js
|
|
358
|
+
var require_token_util = __commonJS(function(exports, module) {
|
|
359
|
+
var __create = Object.create;
|
|
360
|
+
var __defProp = Object.defineProperty;
|
|
361
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
362
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
363
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
364
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
365
|
+
var __export = (target, all) => {
|
|
366
|
+
for (var name in all)
|
|
367
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
368
|
+
};
|
|
369
|
+
var __copyProps = (to, from, except, desc) => {
|
|
370
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
371
|
+
for (let key of __getOwnPropNames(from))
|
|
372
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
373
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
374
|
+
}
|
|
375
|
+
return to;
|
|
376
|
+
};
|
|
377
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
378
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
379
|
+
var token_util_exports = {};
|
|
380
|
+
__export(token_util_exports, {
|
|
381
|
+
assertVercelOidcTokenResponse: () => assertVercelOidcTokenResponse,
|
|
382
|
+
findProjectInfo: () => findProjectInfo,
|
|
383
|
+
getTokenPayload: () => getTokenPayload,
|
|
384
|
+
getVercelDataDir: () => getVercelDataDir,
|
|
385
|
+
getVercelOidcToken: () => getVercelOidcToken,
|
|
386
|
+
getVercelToken: () => getVercelToken,
|
|
387
|
+
isExpired: () => isExpired,
|
|
388
|
+
loadToken: () => loadToken,
|
|
389
|
+
saveToken: () => saveToken
|
|
390
|
+
});
|
|
391
|
+
module.exports = __toCommonJS(token_util_exports);
|
|
392
|
+
var path = __toESM(__require("path"));
|
|
393
|
+
var fs = __toESM(__require("fs"));
|
|
394
|
+
var import_token_error = require_token_error();
|
|
395
|
+
var import_token_io = require_token_io();
|
|
396
|
+
var import_auth_config = require_auth_config();
|
|
397
|
+
var import_oauth = require_oauth();
|
|
398
|
+
var import_auth_errors = require_auth_errors();
|
|
399
|
+
function getVercelDataDir() {
|
|
400
|
+
const vercelFolder = "com.vercel.cli";
|
|
401
|
+
const dataDir = (0, import_token_io.getUserDataDir)();
|
|
402
|
+
if (!dataDir) {
|
|
403
|
+
return null;
|
|
404
|
+
}
|
|
405
|
+
return path.join(dataDir, vercelFolder);
|
|
406
|
+
}
|
|
407
|
+
async function getVercelToken(options) {
|
|
408
|
+
const authConfig = (0, import_auth_config.readAuthConfig)();
|
|
409
|
+
if (!authConfig?.token) {
|
|
410
|
+
throw new import_auth_errors.AccessTokenMissingError;
|
|
411
|
+
}
|
|
412
|
+
if ((0, import_auth_config.isValidAccessToken)(authConfig, options?.expirationBufferMs)) {
|
|
413
|
+
return authConfig.token;
|
|
414
|
+
}
|
|
415
|
+
if (!authConfig.refreshToken) {
|
|
416
|
+
(0, import_auth_config.writeAuthConfig)({});
|
|
417
|
+
throw new import_auth_errors.RefreshAccessTokenFailedError("No refresh token available");
|
|
418
|
+
}
|
|
419
|
+
try {
|
|
420
|
+
const tokenResponse = await (0, import_oauth.refreshTokenRequest)({
|
|
421
|
+
refresh_token: authConfig.refreshToken
|
|
422
|
+
});
|
|
423
|
+
const [tokensError, tokens] = await (0, import_oauth.processTokenResponse)(tokenResponse);
|
|
424
|
+
if (tokensError || !tokens) {
|
|
425
|
+
(0, import_auth_config.writeAuthConfig)({});
|
|
426
|
+
throw new import_auth_errors.RefreshAccessTokenFailedError(tokensError);
|
|
427
|
+
}
|
|
428
|
+
const updatedConfig = {
|
|
429
|
+
token: tokens.access_token,
|
|
430
|
+
expiresAt: Math.floor(Date.now() / 1000) + tokens.expires_in
|
|
431
|
+
};
|
|
432
|
+
if (tokens.refresh_token) {
|
|
433
|
+
updatedConfig.refreshToken = tokens.refresh_token;
|
|
434
|
+
}
|
|
435
|
+
(0, import_auth_config.writeAuthConfig)(updatedConfig);
|
|
436
|
+
return updatedConfig.token;
|
|
437
|
+
} catch (error) {
|
|
438
|
+
(0, import_auth_config.writeAuthConfig)({});
|
|
439
|
+
if (error instanceof import_auth_errors.AccessTokenMissingError || error instanceof import_auth_errors.RefreshAccessTokenFailedError) {
|
|
440
|
+
throw error;
|
|
441
|
+
}
|
|
442
|
+
throw new import_auth_errors.RefreshAccessTokenFailedError(error);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
async function getVercelOidcToken(authToken, projectId, teamId) {
|
|
446
|
+
const url = `https://api.vercel.com/v1/projects/${projectId}/token?source=vercel-oidc-refresh${teamId ? `&teamId=${teamId}` : ""}`;
|
|
447
|
+
const res = await fetch(url, {
|
|
448
|
+
method: "POST",
|
|
449
|
+
headers: {
|
|
450
|
+
Authorization: `Bearer ${authToken}`
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
if (!res.ok) {
|
|
454
|
+
throw new import_token_error.VercelOidcTokenError(`Failed to refresh OIDC token: ${res.statusText}`);
|
|
455
|
+
}
|
|
456
|
+
const tokenRes = await res.json();
|
|
457
|
+
assertVercelOidcTokenResponse(tokenRes);
|
|
458
|
+
return tokenRes;
|
|
459
|
+
}
|
|
460
|
+
function assertVercelOidcTokenResponse(res) {
|
|
461
|
+
if (!res || typeof res !== "object") {
|
|
462
|
+
throw new TypeError("Vercel OIDC token is malformed. Expected an object. Please run `vc env pull` and try again");
|
|
463
|
+
}
|
|
464
|
+
if (!("token" in res) || typeof res.token !== "string") {
|
|
465
|
+
throw new TypeError("Vercel OIDC token is malformed. Expected a string-valued token property. Please run `vc env pull` and try again");
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
function findProjectInfo() {
|
|
469
|
+
const dir = (0, import_token_io.findRootDir)();
|
|
470
|
+
if (!dir) {
|
|
471
|
+
throw new import_token_error.VercelOidcTokenError("Unable to find project root directory. Have you linked your project with `vc link?`");
|
|
472
|
+
}
|
|
473
|
+
const prjPath = path.join(dir, ".vercel", "project.json");
|
|
474
|
+
if (!fs.existsSync(prjPath)) {
|
|
475
|
+
throw new import_token_error.VercelOidcTokenError("project.json not found, have you linked your project with `vc link?`");
|
|
476
|
+
}
|
|
477
|
+
const prj = JSON.parse(fs.readFileSync(prjPath, "utf8"));
|
|
478
|
+
if (typeof prj.projectId !== "string" && typeof prj.orgId !== "string") {
|
|
479
|
+
throw new TypeError("Expected a string-valued projectId property. Try running `vc link` to re-link your project.");
|
|
480
|
+
}
|
|
481
|
+
return { projectId: prj.projectId, teamId: prj.orgId };
|
|
482
|
+
}
|
|
483
|
+
function saveToken(token, projectId) {
|
|
484
|
+
const dir = (0, import_token_io.getUserDataDir)();
|
|
485
|
+
if (!dir) {
|
|
486
|
+
throw new import_token_error.VercelOidcTokenError("Unable to find user data directory. Please reach out to Vercel support.");
|
|
487
|
+
}
|
|
488
|
+
const tokenPath = path.join(dir, "com.vercel.token", `${projectId}.json`);
|
|
489
|
+
const tokenJson = JSON.stringify(token);
|
|
490
|
+
fs.mkdirSync(path.dirname(tokenPath), { mode: 504, recursive: true });
|
|
491
|
+
fs.writeFileSync(tokenPath, tokenJson);
|
|
492
|
+
fs.chmodSync(tokenPath, 432);
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
function loadToken(projectId) {
|
|
496
|
+
const dir = (0, import_token_io.getUserDataDir)();
|
|
497
|
+
if (!dir) {
|
|
498
|
+
throw new import_token_error.VercelOidcTokenError("Unable to find user data directory. Please reach out to Vercel support.");
|
|
499
|
+
}
|
|
500
|
+
const tokenPath = path.join(dir, "com.vercel.token", `${projectId}.json`);
|
|
501
|
+
if (!fs.existsSync(tokenPath)) {
|
|
502
|
+
return null;
|
|
503
|
+
}
|
|
504
|
+
const token = JSON.parse(fs.readFileSync(tokenPath, "utf8"));
|
|
505
|
+
assertVercelOidcTokenResponse(token);
|
|
506
|
+
return token;
|
|
507
|
+
}
|
|
508
|
+
function getTokenPayload(token) {
|
|
509
|
+
const tokenParts = token.split(".");
|
|
510
|
+
if (tokenParts.length !== 3) {
|
|
511
|
+
throw new import_token_error.VercelOidcTokenError("Invalid token. Please run `vc env pull` and try again");
|
|
512
|
+
}
|
|
513
|
+
const base64 = tokenParts[1].replace(/-/g, "+").replace(/_/g, "/");
|
|
514
|
+
const padded = base64.padEnd(base64.length + (4 - base64.length % 4) % 4, "=");
|
|
515
|
+
return JSON.parse(Buffer.from(padded, "base64").toString("utf8"));
|
|
516
|
+
}
|
|
517
|
+
function isExpired(token, bufferMs = 0) {
|
|
518
|
+
return token.exp * 1000 < Date.now() + bufferMs;
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
|
|
522
|
+
export { __toESM, __commonJS, __export, require_token_error, require_auth_errors, require_token_util };
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// ../server/src/ai/model.ts
|
|
2
|
+
class AiError extends Error {
|
|
3
|
+
code;
|
|
4
|
+
constructor(code, message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.code = code;
|
|
7
|
+
this.name = "AiError";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
var MESSAGES = {
|
|
11
|
+
auth: "The provider refused the key. Check that it is correct and active.",
|
|
12
|
+
model: "The provider doesn't offer this model to this key. Check the model name.",
|
|
13
|
+
capability: "The model didn't return the structured answer Critiqs asked for. Choose a model that supports structured output.",
|
|
14
|
+
network: "Critiqs couldn't reach the provider, or it didn't answer in time.",
|
|
15
|
+
"rate-limit": "The provider is limiting requests right now. Try again later.",
|
|
16
|
+
config: "The AI connection isn't set up completely.",
|
|
17
|
+
unknown: "The provider couldn't answer."
|
|
18
|
+
};
|
|
19
|
+
function aiErrorMessage(code) {
|
|
20
|
+
return MESSAGES[code];
|
|
21
|
+
}
|
|
22
|
+
function isAiError(value) {
|
|
23
|
+
return value instanceof AiError || value?.name === "AiError" && typeof value.code === "string";
|
|
24
|
+
}
|
|
25
|
+
function toAiError(error) {
|
|
26
|
+
if (error instanceof AiError)
|
|
27
|
+
return error;
|
|
28
|
+
if (isAiError(error)) {
|
|
29
|
+
const copy = error;
|
|
30
|
+
return new AiError(copy.code, copy.message);
|
|
31
|
+
}
|
|
32
|
+
const last = error?.lastError;
|
|
33
|
+
if (last !== undefined && last !== error)
|
|
34
|
+
return toAiError(last);
|
|
35
|
+
const cause = error?.cause;
|
|
36
|
+
if (isAiError(cause))
|
|
37
|
+
return toAiError(cause);
|
|
38
|
+
const value = error;
|
|
39
|
+
const status = typeof value?.statusCode === "number" ? value.statusCode : null;
|
|
40
|
+
const name = typeof value?.name === "string" ? value.name : "";
|
|
41
|
+
const code = status === 401 || status === 403 ? "auth" : status === 404 ? "model" : status === 429 ? "rate-limit" : status !== null && status >= 500 ? "network" : status === 400 && /model/i.test(String(value?.message ?? "")) ? "model" : /NoObjectGenerated|TypeValidation|JSONParse|NoContentGenerated|UnsupportedFunctionality/.test(name) ? "capability" : /Abort|Timeout/.test(name) || name === "TypeError" || /fetch failed|ECONN|ENOTFOUND|network/i.test(String(value?.message ?? "")) ? "network" : /LoadAPIKey/.test(name) ? "config" : "unknown";
|
|
42
|
+
return new AiError(code, MESSAGES[code]);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// ../server/src/ai/endpoints.ts
|
|
46
|
+
function normalize(url) {
|
|
47
|
+
return `${url.protocol}//${url.host}${url.pathname.replace(/\/+$/, "")}`;
|
|
48
|
+
}
|
|
49
|
+
function isPrivateIpv4(host) {
|
|
50
|
+
const parts = host.split(".").map(Number);
|
|
51
|
+
if (parts.length !== 4 || parts.some((part) => !Number.isInteger(part) || part < 0 || part > 255))
|
|
52
|
+
return false;
|
|
53
|
+
const [a, b] = parts;
|
|
54
|
+
return a === 0 || a === 10 || a === 127 || a === 100 && b >= 64 && b <= 127 || a === 169 && b === 254 || a === 172 && b >= 16 && b <= 31 || a === 192 && b === 168 || a === 198 && (b === 18 || b === 19) || a >= 224;
|
|
55
|
+
}
|
|
56
|
+
function isPrivateIpv6(host) {
|
|
57
|
+
const address = host.replace(/^\[|\]$/g, "").toLowerCase();
|
|
58
|
+
if (!address.includes(":"))
|
|
59
|
+
return false;
|
|
60
|
+
if (address === "::" || address === "::1")
|
|
61
|
+
return true;
|
|
62
|
+
const mapped = address.match(/^::ffff:(\d+\.\d+\.\d+\.\d+)$/);
|
|
63
|
+
if (mapped)
|
|
64
|
+
return isPrivateIpv4(mapped[1]);
|
|
65
|
+
if (address.startsWith("::ffff:"))
|
|
66
|
+
return true;
|
|
67
|
+
return /^(fc|fd|fe8|fe9|fea|feb|ff)/.test(address);
|
|
68
|
+
}
|
|
69
|
+
function isLocalHost(hostname) {
|
|
70
|
+
const host = hostname.toLowerCase().replace(/\.$/, "");
|
|
71
|
+
return host === "localhost" || host.endsWith(".localhost") || host.endsWith(".local") || host.endsWith(".internal") || isPrivateIpv4(host) || isPrivateIpv6(host);
|
|
72
|
+
}
|
|
73
|
+
function isLocalReviewAddress(address) {
|
|
74
|
+
if (address === undefined || address === null)
|
|
75
|
+
return false;
|
|
76
|
+
try {
|
|
77
|
+
return isLocalHost(new URL(address).hostname.replace(/^\[|\]$/g, ""));
|
|
78
|
+
} catch {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function isUnder(url, base) {
|
|
83
|
+
const prefix = new URL(base);
|
|
84
|
+
if (url.protocol !== prefix.protocol || url.host !== prefix.host)
|
|
85
|
+
return false;
|
|
86
|
+
const path = prefix.pathname.replace(/\/+$/, "");
|
|
87
|
+
return url.pathname === path || url.pathname.startsWith(`${path}/`) || path === "";
|
|
88
|
+
}
|
|
89
|
+
function checkEndpoint(raw, policy, trusted = false) {
|
|
90
|
+
let url;
|
|
91
|
+
try {
|
|
92
|
+
url = new URL(raw.trim());
|
|
93
|
+
} catch {
|
|
94
|
+
return { ok: false, reason: "Enter the endpoint's full address, starting with https://." };
|
|
95
|
+
}
|
|
96
|
+
if (url.username !== "" || url.password !== "")
|
|
97
|
+
return { ok: false, reason: "Endpoint addresses can't contain a username or password; enter the key separately." };
|
|
98
|
+
if (url.search !== "" || url.hash !== "")
|
|
99
|
+
return { ok: false, reason: "Endpoint addresses can't contain a query or fragment." };
|
|
100
|
+
const local = isLocalHost(url.hostname);
|
|
101
|
+
if (url.protocol === "http:") {
|
|
102
|
+
if (!(policy.allowLocal && (trusted || local)))
|
|
103
|
+
return { ok: false, reason: "Endpoints must use HTTPS." };
|
|
104
|
+
} else if (url.protocol !== "https:") {
|
|
105
|
+
return { ok: false, reason: "Endpoints must use HTTPS." };
|
|
106
|
+
}
|
|
107
|
+
if (local && !policy.allowLocal)
|
|
108
|
+
return { ok: false, reason: "This deployment doesn't allow private or local network addresses." };
|
|
109
|
+
const normalized = normalize(url);
|
|
110
|
+
if (trusted)
|
|
111
|
+
return { ok: true, url: normalized };
|
|
112
|
+
const allowed = policy.allowed.some((entry) => {
|
|
113
|
+
try {
|
|
114
|
+
const prefix = new URL(entry.trim());
|
|
115
|
+
if (prefix.protocol === "http:" && !policy.allowLocal)
|
|
116
|
+
return false;
|
|
117
|
+
return isUnder(url, normalize(prefix));
|
|
118
|
+
} catch {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
if (!allowed)
|
|
123
|
+
return { ok: false, reason: "This endpoint isn't on this deployment's list of allowed AI endpoints. Ask its operator to add it." };
|
|
124
|
+
return { ok: true, url: normalized };
|
|
125
|
+
}
|
|
126
|
+
function guardedFetch(base, timeoutMs, allowHttp = false) {
|
|
127
|
+
const guarded = async (input, init) => {
|
|
128
|
+
const url = new URL(typeof input === "string" ? input : input instanceof URL ? input.href : input.url);
|
|
129
|
+
if (base !== null ? !isUnder(url, base) : url.protocol !== "https:") {
|
|
130
|
+
throw new AiError("config", "The provider tried to reach an address outside its configured endpoint.");
|
|
131
|
+
}
|
|
132
|
+
if (url.protocol !== "https:" && !(allowHttp && base !== null))
|
|
133
|
+
throw new AiError("config", "Endpoints must use HTTPS.");
|
|
134
|
+
const timeout = AbortSignal.timeout(timeoutMs);
|
|
135
|
+
const signal = init?.signal ? AbortSignal.any([init.signal, timeout]) : timeout;
|
|
136
|
+
const response = await fetch(input, { ...init, redirect: "manual", signal });
|
|
137
|
+
if (response.status >= 300 && response.status < 400) {
|
|
138
|
+
await response.body?.cancel().catch(() => {
|
|
139
|
+
return;
|
|
140
|
+
});
|
|
141
|
+
throw new AiError("network", "The provider answered with a redirect, which Critiqs doesn't follow.");
|
|
142
|
+
}
|
|
143
|
+
return response;
|
|
144
|
+
};
|
|
145
|
+
return guarded;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export { AiError, aiErrorMessage, toAiError, isLocalReviewAddress, checkEndpoint, guardedFetch };
|