@dosu/cli 0.9.0 → 0.10.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/README.md +0 -3
- package/bin/dosu.js +4036 -439
- package/package.json +6 -2
package/bin/dosu.js
CHANGED
|
@@ -2063,61 +2063,6 @@ var require_commander = __commonJS((exports) => {
|
|
|
2063
2063
|
exports.InvalidOptionArgumentError = InvalidArgumentError;
|
|
2064
2064
|
});
|
|
2065
2065
|
|
|
2066
|
-
// src/config/config.ts
|
|
2067
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2068
|
-
import { join } from "node:path";
|
|
2069
|
-
function getConfigDir() {
|
|
2070
|
-
const xdgConfig = process.env.XDG_CONFIG_HOME;
|
|
2071
|
-
if (xdgConfig)
|
|
2072
|
-
return join(xdgConfig, "dosu-cli");
|
|
2073
|
-
const home = process.env.HOME ?? process.env.USERPROFILE ?? "";
|
|
2074
|
-
return join(home, ".config", "dosu-cli");
|
|
2075
|
-
}
|
|
2076
|
-
function getConfigPath() {
|
|
2077
|
-
const dir = getConfigDir();
|
|
2078
|
-
if (!existsSync(dir)) {
|
|
2079
|
-
mkdirSync(dir, { recursive: true, mode: 448 });
|
|
2080
|
-
}
|
|
2081
|
-
return join(dir, "config.json");
|
|
2082
|
-
}
|
|
2083
|
-
function loadConfig() {
|
|
2084
|
-
const path = getConfigPath();
|
|
2085
|
-
if (!existsSync(path)) {
|
|
2086
|
-
return emptyConfig();
|
|
2087
|
-
}
|
|
2088
|
-
try {
|
|
2089
|
-
const data = readFileSync(path, "utf-8");
|
|
2090
|
-
return JSON.parse(data);
|
|
2091
|
-
} catch {
|
|
2092
|
-
return emptyConfig();
|
|
2093
|
-
}
|
|
2094
|
-
}
|
|
2095
|
-
function saveConfig(cfg) {
|
|
2096
|
-
const path = getConfigPath();
|
|
2097
|
-
const dir = getConfigDir();
|
|
2098
|
-
if (!existsSync(dir)) {
|
|
2099
|
-
mkdirSync(dir, { recursive: true, mode: 448 });
|
|
2100
|
-
}
|
|
2101
|
-
writeFileSync(path, JSON.stringify(cfg, null, 2), { mode: 384 });
|
|
2102
|
-
}
|
|
2103
|
-
function isAuthenticated(cfg) {
|
|
2104
|
-
return cfg.access_token !== "";
|
|
2105
|
-
}
|
|
2106
|
-
function isTokenExpired(cfg) {
|
|
2107
|
-
if (cfg.expires_at === 0)
|
|
2108
|
-
return false;
|
|
2109
|
-
return Math.floor(Date.now() / 1000) > cfg.expires_at - 300;
|
|
2110
|
-
}
|
|
2111
|
-
function emptyConfig() {
|
|
2112
|
-
return {
|
|
2113
|
-
access_token: "",
|
|
2114
|
-
refresh_token: "",
|
|
2115
|
-
expires_at: 0
|
|
2116
|
-
};
|
|
2117
|
-
}
|
|
2118
|
-
var MODE_OSS = "oss";
|
|
2119
|
-
var init_config = () => {};
|
|
2120
|
-
|
|
2121
2066
|
// node_modules/picocolors/picocolors.js
|
|
2122
2067
|
var require_picocolors = __commonJS((exports, module) => {
|
|
2123
2068
|
var p = process || {};
|
|
@@ -2188,11 +2133,80 @@ var require_picocolors = __commonJS((exports, module) => {
|
|
|
2188
2133
|
module.exports.createColors = createColors;
|
|
2189
2134
|
});
|
|
2190
2135
|
|
|
2136
|
+
// src/config/config.ts
|
|
2137
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2138
|
+
import { join } from "node:path";
|
|
2139
|
+
function getConfigDir() {
|
|
2140
|
+
const xdgConfig = process.env.XDG_CONFIG_HOME;
|
|
2141
|
+
if (xdgConfig)
|
|
2142
|
+
return join(xdgConfig, "dosu-cli");
|
|
2143
|
+
const home = process.env.HOME ?? process.env.USERPROFILE ?? "";
|
|
2144
|
+
return join(home, ".config", "dosu-cli");
|
|
2145
|
+
}
|
|
2146
|
+
function getConfigPath() {
|
|
2147
|
+
const dir = getConfigDir();
|
|
2148
|
+
if (!existsSync(dir)) {
|
|
2149
|
+
mkdirSync(dir, { recursive: true, mode: 448 });
|
|
2150
|
+
}
|
|
2151
|
+
return join(dir, "config.json");
|
|
2152
|
+
}
|
|
2153
|
+
function loadConfig() {
|
|
2154
|
+
const path = getConfigPath();
|
|
2155
|
+
if (!existsSync(path)) {
|
|
2156
|
+
return emptyConfig();
|
|
2157
|
+
}
|
|
2158
|
+
try {
|
|
2159
|
+
const data = readFileSync(path, "utf-8");
|
|
2160
|
+
return JSON.parse(data);
|
|
2161
|
+
} catch {
|
|
2162
|
+
return emptyConfig();
|
|
2163
|
+
}
|
|
2164
|
+
}
|
|
2165
|
+
function saveConfig(cfg) {
|
|
2166
|
+
const path = getConfigPath();
|
|
2167
|
+
const dir = getConfigDir();
|
|
2168
|
+
if (!existsSync(dir)) {
|
|
2169
|
+
mkdirSync(dir, { recursive: true, mode: 448 });
|
|
2170
|
+
}
|
|
2171
|
+
writeFileSync(path, JSON.stringify(cfg, null, 2), { mode: 384 });
|
|
2172
|
+
}
|
|
2173
|
+
function isAuthenticated(cfg) {
|
|
2174
|
+
return cfg.access_token !== "";
|
|
2175
|
+
}
|
|
2176
|
+
function isTokenExpired(cfg) {
|
|
2177
|
+
if (cfg.expires_at === 0)
|
|
2178
|
+
return false;
|
|
2179
|
+
return Math.floor(Date.now() / 1000) > cfg.expires_at - 300;
|
|
2180
|
+
}
|
|
2181
|
+
function emptyConfig() {
|
|
2182
|
+
return {
|
|
2183
|
+
access_token: "",
|
|
2184
|
+
refresh_token: "",
|
|
2185
|
+
expires_at: 0
|
|
2186
|
+
};
|
|
2187
|
+
}
|
|
2188
|
+
var MODE_OSS = "oss";
|
|
2189
|
+
var init_config = () => {};
|
|
2190
|
+
|
|
2191
|
+
// src/config/constants.ts
|
|
2192
|
+
function getWebAppURL() {
|
|
2193
|
+
return "https://app.dosu.dev";
|
|
2194
|
+
}
|
|
2195
|
+
function getBackendURL() {
|
|
2196
|
+
return "https://api.dosu.dev";
|
|
2197
|
+
}
|
|
2198
|
+
function getSupabaseURL() {
|
|
2199
|
+
return "https://wldmetsoicvieidlsqrb.supabase.co";
|
|
2200
|
+
}
|
|
2201
|
+
function getSupabaseAnonKey() {
|
|
2202
|
+
return "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6IndsbG1ldHNvaWN2aWVpZGxzcXJiIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MzQ0NjA1NjUsImV4cCI6MjA1MDAzNjU2NX0.15LIxqSMVRnxsvLrk0GPjL1aSYPfOeaeFMdJXqgc5Xs";
|
|
2203
|
+
}
|
|
2204
|
+
|
|
2191
2205
|
// src/version/version.ts
|
|
2192
2206
|
function getVersionString() {
|
|
2193
2207
|
return `v${VERSION}`;
|
|
2194
2208
|
}
|
|
2195
|
-
var VERSION = "0.
|
|
2209
|
+
var VERSION = "0.10.0";
|
|
2196
2210
|
|
|
2197
2211
|
// src/debug/logger.ts
|
|
2198
2212
|
import {
|
|
@@ -2304,103 +2318,239 @@ var init_logger = __esm(() => {
|
|
|
2304
2318
|
};
|
|
2305
2319
|
});
|
|
2306
2320
|
|
|
2307
|
-
// src/
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
function getSupabaseURL() {
|
|
2315
|
-
return "https://wldmetsoicvieidlsqrb.supabase.co";
|
|
2316
|
-
}
|
|
2317
|
-
function getSupabaseAnonKey() {
|
|
2318
|
-
return "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6IndsbG1ldHNvaWN2aWVpZGxzcXJiIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MzQ0NjA1NjUsImV4cCI6MjA1MDAzNjU2NX0.15LIxqSMVRnxsvLrk0GPjL1aSYPfOeaeFMdJXqgc5Xs";
|
|
2319
|
-
}
|
|
2320
|
-
|
|
2321
|
-
// src/mcp/config-helpers.ts
|
|
2322
|
-
import { existsSync as existsSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync3, writeFileSync as writeFileSync3 } from "node:fs";
|
|
2323
|
-
import { dirname } from "node:path";
|
|
2324
|
-
function mcpURL(deploymentID) {
|
|
2325
|
-
return `${getBackendURL()}/v1/mcp/deployments/${deploymentID}`;
|
|
2326
|
-
}
|
|
2327
|
-
function mcpBaseURL() {
|
|
2328
|
-
return `${getBackendURL()}/v1/mcp`;
|
|
2329
|
-
}
|
|
2330
|
-
function mcpHeaders(apiKey) {
|
|
2331
|
-
return { "X-Dosu-API-Key": apiKey };
|
|
2332
|
-
}
|
|
2333
|
-
function loadJSONConfig(path) {
|
|
2334
|
-
if (!existsSync3(path))
|
|
2335
|
-
return {};
|
|
2336
|
-
let data = readFileSync3(path, "utf-8").trim();
|
|
2337
|
-
if (!data)
|
|
2338
|
-
return {};
|
|
2339
|
-
if (path.endsWith(".jsonc")) {
|
|
2340
|
-
data = stripJSONComments(data);
|
|
2341
|
-
}
|
|
2342
|
-
try {
|
|
2343
|
-
return JSON.parse(data);
|
|
2344
|
-
} catch {
|
|
2345
|
-
return {};
|
|
2321
|
+
// src/client/client.ts
|
|
2322
|
+
class Client {
|
|
2323
|
+
baseURL;
|
|
2324
|
+
config;
|
|
2325
|
+
constructor(cfg) {
|
|
2326
|
+
this.baseURL = getBackendURL();
|
|
2327
|
+
this.config = cfg;
|
|
2346
2328
|
}
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
result.push(data[i]);
|
|
2361
|
-
i++;
|
|
2362
|
-
}
|
|
2363
|
-
continue;
|
|
2364
|
-
}
|
|
2365
|
-
result.push(data[i]);
|
|
2366
|
-
i++;
|
|
2367
|
-
}
|
|
2368
|
-
if (i < data.length) {
|
|
2369
|
-
result.push(data[i]);
|
|
2370
|
-
i++;
|
|
2329
|
+
async doRequest(method, path, body) {
|
|
2330
|
+
if (!isAuthenticated(this.config)) {
|
|
2331
|
+
throw new Error("not authenticated - please run setup first");
|
|
2332
|
+
}
|
|
2333
|
+
if (isTokenExpired(this.config)) {
|
|
2334
|
+
await this.refreshToken();
|
|
2335
|
+
}
|
|
2336
|
+
let resp = await this.doRequestOnce(method, path, body);
|
|
2337
|
+
if (resp.status === 401 || resp.status === 403) {
|
|
2338
|
+
try {
|
|
2339
|
+
await this.refreshToken();
|
|
2340
|
+
} catch {
|
|
2341
|
+
throw new SessionExpiredError;
|
|
2371
2342
|
}
|
|
2372
|
-
|
|
2343
|
+
resp = await this.doRequestOnce(method, path, body);
|
|
2373
2344
|
}
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2345
|
+
return resp;
|
|
2346
|
+
}
|
|
2347
|
+
async doRequestRaw(method, path) {
|
|
2348
|
+
return this.doRequestOnce(method, path);
|
|
2349
|
+
}
|
|
2350
|
+
async doRequestOnce(method, path, body) {
|
|
2351
|
+
const url = this.baseURL + path;
|
|
2352
|
+
const headers = {
|
|
2353
|
+
"Content-Type": "application/json",
|
|
2354
|
+
"Supabase-Access-Token": this.config.access_token
|
|
2355
|
+
};
|
|
2356
|
+
const options = { method, headers };
|
|
2357
|
+
if (body !== undefined) {
|
|
2358
|
+
options.body = JSON.stringify(body);
|
|
2380
2359
|
}
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2360
|
+
const controller = new AbortController;
|
|
2361
|
+
const timeout = setTimeout(() => controller.abort(), 1e4);
|
|
2362
|
+
options.signal = controller.signal;
|
|
2363
|
+
try {
|
|
2364
|
+
return await fetch(url, options);
|
|
2365
|
+
} finally {
|
|
2366
|
+
clearTimeout(timeout);
|
|
2388
2367
|
}
|
|
2389
|
-
result.push(data[i]);
|
|
2390
|
-
i++;
|
|
2391
2368
|
}
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
function saveJSONConfig(path, cfg) {
|
|
2395
|
-
const dir = dirname(path);
|
|
2396
|
-
if (!existsSync3(dir)) {
|
|
2397
|
-
mkdirSync3(dir, { recursive: true });
|
|
2369
|
+
async get(path) {
|
|
2370
|
+
return this.doRequest("GET", path);
|
|
2398
2371
|
}
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2372
|
+
async post(path, body) {
|
|
2373
|
+
return this.doRequest("POST", path, body);
|
|
2374
|
+
}
|
|
2375
|
+
async put(path, body) {
|
|
2376
|
+
return this.doRequest("PUT", path, body);
|
|
2377
|
+
}
|
|
2378
|
+
async delete(path) {
|
|
2379
|
+
return this.doRequest("DELETE", path);
|
|
2380
|
+
}
|
|
2381
|
+
async refreshToken() {
|
|
2382
|
+
if (!this.config.refresh_token) {
|
|
2383
|
+
throw new Error("no refresh token available");
|
|
2384
|
+
}
|
|
2385
|
+
const supabaseURL = getSupabaseURL();
|
|
2386
|
+
const endpoint = `${supabaseURL}/auth/v1/token?grant_type=refresh_token`;
|
|
2387
|
+
const resp = await fetch(endpoint, {
|
|
2388
|
+
method: "POST",
|
|
2389
|
+
headers: {
|
|
2390
|
+
"Content-Type": "application/json",
|
|
2391
|
+
apikey: getSupabaseAnonKey()
|
|
2392
|
+
},
|
|
2393
|
+
body: JSON.stringify({ refresh_token: this.config.refresh_token })
|
|
2394
|
+
});
|
|
2395
|
+
if (resp.status !== 200) {
|
|
2396
|
+
throw new Error(`refresh failed with status ${resp.status}`);
|
|
2397
|
+
}
|
|
2398
|
+
const data = await resp.json();
|
|
2399
|
+
this.config.access_token = data.access_token;
|
|
2400
|
+
this.config.refresh_token = data.refresh_token;
|
|
2401
|
+
this.config.expires_at = Math.floor(Date.now() / 1000) + data.expires_in;
|
|
2402
|
+
saveConfig(this.config);
|
|
2403
|
+
}
|
|
2404
|
+
async getDeployments() {
|
|
2405
|
+
const resp = await this.get("/v1/mcp/deployments");
|
|
2406
|
+
if (resp.status !== 200) {
|
|
2407
|
+
let detail = await readErrorBody(resp);
|
|
2408
|
+
if (!detail || detail === "Internal Server Error") {
|
|
2409
|
+
detail = "check backend logs for details";
|
|
2410
|
+
}
|
|
2411
|
+
throw new Error(`failed to fetch deployments (status ${resp.status}): ${detail}`);
|
|
2412
|
+
}
|
|
2413
|
+
return resp.json();
|
|
2414
|
+
}
|
|
2415
|
+
async getOrgs() {
|
|
2416
|
+
const resp = await this.get("/v1/mcp/orgs");
|
|
2417
|
+
if (resp.status !== 200) {
|
|
2418
|
+
const detail = await readErrorBody(resp);
|
|
2419
|
+
throw new Error(`failed to fetch orgs (status ${resp.status}): ${detail}`);
|
|
2420
|
+
}
|
|
2421
|
+
return resp.json();
|
|
2422
|
+
}
|
|
2423
|
+
async validateAPIKey(apiKey, deploymentID) {
|
|
2424
|
+
try {
|
|
2425
|
+
const endpoint = `${this.baseURL}/v1/mcp/deployments/${encodeURIComponent(deploymentID)}`;
|
|
2426
|
+
const controller = new AbortController;
|
|
2427
|
+
const timeout = setTimeout(() => controller.abort(), 5000);
|
|
2428
|
+
try {
|
|
2429
|
+
const resp = await fetch(endpoint, {
|
|
2430
|
+
method: "GET",
|
|
2431
|
+
headers: { "X-Dosu-API-Key": apiKey },
|
|
2432
|
+
signal: controller.signal
|
|
2433
|
+
});
|
|
2434
|
+
return resp.status !== 401 && resp.status !== 403;
|
|
2435
|
+
} finally {
|
|
2436
|
+
clearTimeout(timeout);
|
|
2437
|
+
}
|
|
2438
|
+
} catch {
|
|
2439
|
+
return true;
|
|
2440
|
+
}
|
|
2441
|
+
}
|
|
2442
|
+
async createAPIKey(deploymentID, name) {
|
|
2443
|
+
const path = `/v1/mcp/deployments/${deploymentID}/api-keys`;
|
|
2444
|
+
const resp = await this.post(path, { name });
|
|
2445
|
+
if (resp.status !== 200 && resp.status !== 201) {
|
|
2446
|
+
const detail = await readErrorBody(resp);
|
|
2447
|
+
throw new Error(`failed to create API key (status ${resp.status}): ${detail}`);
|
|
2448
|
+
}
|
|
2449
|
+
return resp.json();
|
|
2450
|
+
}
|
|
2451
|
+
}
|
|
2452
|
+
async function readErrorBody(resp) {
|
|
2453
|
+
try {
|
|
2454
|
+
const text = await resp.text();
|
|
2455
|
+
return text.slice(0, 1024);
|
|
2456
|
+
} catch {
|
|
2457
|
+
return "";
|
|
2458
|
+
}
|
|
2459
|
+
}
|
|
2460
|
+
var SessionExpiredError;
|
|
2461
|
+
var init_client = __esm(() => {
|
|
2462
|
+
init_config();
|
|
2463
|
+
SessionExpiredError = class SessionExpiredError extends Error {
|
|
2464
|
+
constructor() {
|
|
2465
|
+
super("session expired");
|
|
2466
|
+
this.name = "SessionExpiredError";
|
|
2467
|
+
}
|
|
2468
|
+
};
|
|
2469
|
+
});
|
|
2470
|
+
|
|
2471
|
+
// src/mcp/config-helpers.ts
|
|
2472
|
+
import { existsSync as existsSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync4, writeFileSync as writeFileSync3 } from "node:fs";
|
|
2473
|
+
import { dirname } from "node:path";
|
|
2474
|
+
function mcpURL(deploymentID) {
|
|
2475
|
+
return `${getBackendURL()}/v1/mcp/deployments/${deploymentID}`;
|
|
2476
|
+
}
|
|
2477
|
+
function mcpBaseURL() {
|
|
2478
|
+
return `${getBackendURL()}/v1/mcp`;
|
|
2479
|
+
}
|
|
2480
|
+
function mcpHeaders(apiKey) {
|
|
2481
|
+
return { "X-Dosu-API-Key": apiKey };
|
|
2482
|
+
}
|
|
2483
|
+
function loadJSONConfig(path) {
|
|
2484
|
+
if (!existsSync3(path))
|
|
2485
|
+
return {};
|
|
2486
|
+
let data = readFileSync4(path, "utf-8").trim();
|
|
2487
|
+
if (!data)
|
|
2488
|
+
return {};
|
|
2489
|
+
if (path.endsWith(".jsonc")) {
|
|
2490
|
+
data = stripJSONComments(data);
|
|
2491
|
+
}
|
|
2492
|
+
try {
|
|
2493
|
+
return JSON.parse(data);
|
|
2494
|
+
} catch {
|
|
2495
|
+
return {};
|
|
2496
|
+
}
|
|
2497
|
+
}
|
|
2498
|
+
function stripJSONComments(data) {
|
|
2499
|
+
const result = [];
|
|
2500
|
+
let i = 0;
|
|
2501
|
+
while (i < data.length) {
|
|
2502
|
+
if (data[i] === '"') {
|
|
2503
|
+
result.push(data[i]);
|
|
2504
|
+
i++;
|
|
2505
|
+
while (i < data.length && data[i] !== '"') {
|
|
2506
|
+
if (data[i] === "\\") {
|
|
2507
|
+
result.push(data[i]);
|
|
2508
|
+
i++;
|
|
2509
|
+
if (i < data.length) {
|
|
2510
|
+
result.push(data[i]);
|
|
2511
|
+
i++;
|
|
2512
|
+
}
|
|
2513
|
+
continue;
|
|
2514
|
+
}
|
|
2515
|
+
result.push(data[i]);
|
|
2516
|
+
i++;
|
|
2517
|
+
}
|
|
2518
|
+
if (i < data.length) {
|
|
2519
|
+
result.push(data[i]);
|
|
2520
|
+
i++;
|
|
2521
|
+
}
|
|
2522
|
+
continue;
|
|
2523
|
+
}
|
|
2524
|
+
if (i + 1 < data.length && data[i] === "/" && data[i + 1] === "/") {
|
|
2525
|
+
i += 2;
|
|
2526
|
+
while (i < data.length && data[i] !== `
|
|
2527
|
+
`)
|
|
2528
|
+
i++;
|
|
2529
|
+
continue;
|
|
2530
|
+
}
|
|
2531
|
+
if (i + 1 < data.length && data[i] === "/" && data[i + 1] === "*") {
|
|
2532
|
+
i += 2;
|
|
2533
|
+
while (i + 1 < data.length && !(data[i] === "*" && data[i + 1] === "/"))
|
|
2534
|
+
i++;
|
|
2535
|
+
if (i + 1 < data.length)
|
|
2536
|
+
i += 2;
|
|
2537
|
+
continue;
|
|
2538
|
+
}
|
|
2539
|
+
result.push(data[i]);
|
|
2540
|
+
i++;
|
|
2541
|
+
}
|
|
2542
|
+
return result.join("");
|
|
2543
|
+
}
|
|
2544
|
+
function saveJSONConfig(path, cfg) {
|
|
2545
|
+
const dir = dirname(path);
|
|
2546
|
+
if (!existsSync3(dir)) {
|
|
2547
|
+
mkdirSync3(dir, { recursive: true });
|
|
2548
|
+
}
|
|
2549
|
+
writeFileSync3(path, JSON.stringify(cfg, null, 2));
|
|
2550
|
+
}
|
|
2551
|
+
function isJSONKeyConfigured(configPath, topLevelKey) {
|
|
2552
|
+
const cfg = loadJSONConfig(configPath);
|
|
2553
|
+
const section = cfg[topLevelKey];
|
|
2404
2554
|
if (typeof section !== "object" || section === null)
|
|
2405
2555
|
return false;
|
|
2406
2556
|
return "dosu" in section;
|
|
@@ -2622,7 +2772,7 @@ var init_cline_cli = __esm(() => {
|
|
|
2622
2772
|
});
|
|
2623
2773
|
|
|
2624
2774
|
// src/mcp/providers/codex.ts
|
|
2625
|
-
import { existsSync as existsSync5, mkdirSync as mkdirSync4, readFileSync as
|
|
2775
|
+
import { existsSync as existsSync5, mkdirSync as mkdirSync4, readFileSync as readFileSync5, writeFileSync as writeFileSync4 } from "node:fs";
|
|
2626
2776
|
import { dirname as dirname2, join as join8 } from "node:path";
|
|
2627
2777
|
function codexHome() {
|
|
2628
2778
|
return process.env.CODEX_HOME ?? expandHome("~/.codex");
|
|
@@ -2635,7 +2785,7 @@ function getConfigPath2(global) {
|
|
|
2635
2785
|
function readTOML(path) {
|
|
2636
2786
|
if (!existsSync5(path))
|
|
2637
2787
|
return "";
|
|
2638
|
-
return
|
|
2788
|
+
return readFileSync5(path, "utf-8");
|
|
2639
2789
|
}
|
|
2640
2790
|
function writeTOML(path, content) {
|
|
2641
2791
|
const dir = dirname2(path);
|
|
@@ -2643,10 +2793,17 @@ function writeTOML(path, content) {
|
|
|
2643
2793
|
mkdirSync4(dir, { recursive: true });
|
|
2644
2794
|
writeFileSync4(path, content);
|
|
2645
2795
|
}
|
|
2796
|
+
function mcpEndpoint(cfg) {
|
|
2797
|
+
if (cfg.mode === MODE_OSS)
|
|
2798
|
+
return mcpBaseURL();
|
|
2799
|
+
if (!cfg.deployment_id)
|
|
2800
|
+
throw new Error("deployment ID is required");
|
|
2801
|
+
return mcpURL(cfg.deployment_id);
|
|
2802
|
+
}
|
|
2646
2803
|
function installDosuToTOML(path, cfg) {
|
|
2647
2804
|
let content = readTOML(path);
|
|
2648
2805
|
content = removeDosuFromTOML(content);
|
|
2649
|
-
const url =
|
|
2806
|
+
const url = mcpEndpoint(cfg);
|
|
2650
2807
|
const headers = mcpHeaders(cfg.api_key);
|
|
2651
2808
|
const headerEntries = Object.entries(headers).map(([k, v]) => `${k} = "${v}"`).join(`
|
|
2652
2809
|
`);
|
|
@@ -2720,6 +2877,13 @@ function globalPath() {
|
|
|
2720
2877
|
}
|
|
2721
2878
|
return expandHome("~/.copilot/mcp-config.json");
|
|
2722
2879
|
}
|
|
2880
|
+
function mcpEndpoint2(cfg) {
|
|
2881
|
+
if (cfg.mode === MODE_OSS)
|
|
2882
|
+
return mcpBaseURL();
|
|
2883
|
+
if (!cfg.deployment_id)
|
|
2884
|
+
throw new Error("deployment ID is required");
|
|
2885
|
+
return mcpURL(cfg.deployment_id);
|
|
2886
|
+
}
|
|
2723
2887
|
var CopilotProvider = () => ({
|
|
2724
2888
|
name: () => "GitHub Copilot CLI",
|
|
2725
2889
|
id: () => "copilot",
|
|
@@ -2730,9 +2894,7 @@ var CopilotProvider = () => ({
|
|
|
2730
2894
|
globalConfigPath: () => globalPath(),
|
|
2731
2895
|
isConfigured: () => isJSONKeyConfigured(globalPath(), "mcpServers"),
|
|
2732
2896
|
install(cfg, global) {
|
|
2733
|
-
|
|
2734
|
-
throw new Error("deployment ID is required");
|
|
2735
|
-
const url = cfg.mode === MODE_OSS ? mcpBaseURL() : mcpURL(cfg.deployment_id);
|
|
2897
|
+
const url = mcpEndpoint2(cfg);
|
|
2736
2898
|
if (global) {
|
|
2737
2899
|
const server = {
|
|
2738
2900
|
type: "http",
|
|
@@ -2804,12 +2966,19 @@ var init_gemini = __esm(() => {
|
|
|
2804
2966
|
});
|
|
2805
2967
|
|
|
2806
2968
|
// src/mcp/providers/manual.ts
|
|
2969
|
+
function mcpEndpoint3(cfg) {
|
|
2970
|
+
if (cfg.mode === MODE_OSS)
|
|
2971
|
+
return mcpBaseURL();
|
|
2972
|
+
if (!cfg.deployment_id)
|
|
2973
|
+
throw new Error("deployment ID is required");
|
|
2974
|
+
return mcpURL(cfg.deployment_id);
|
|
2975
|
+
}
|
|
2807
2976
|
var ManualProvider = () => ({
|
|
2808
2977
|
name: () => "Manual Configuration",
|
|
2809
2978
|
id: () => "manual",
|
|
2810
2979
|
supportsLocal: () => false,
|
|
2811
2980
|
install(cfg) {
|
|
2812
|
-
const url =
|
|
2981
|
+
const url = mcpEndpoint3(cfg);
|
|
2813
2982
|
console.log("Use these details to configure the Dosu MCP server in your client:");
|
|
2814
2983
|
console.log();
|
|
2815
2984
|
console.log(` Transport: HTTP`);
|
|
@@ -2839,6 +3008,13 @@ function resolveGlobalConfigPath() {
|
|
|
2839
3008
|
return jsoncPath;
|
|
2840
3009
|
return jsonPath;
|
|
2841
3010
|
}
|
|
3011
|
+
function mcpEndpoint4(cfg) {
|
|
3012
|
+
if (cfg.mode === MODE_OSS)
|
|
3013
|
+
return mcpBaseURL();
|
|
3014
|
+
if (!cfg.deployment_id)
|
|
3015
|
+
throw new Error("deployment ID is required");
|
|
3016
|
+
return mcpURL(cfg.deployment_id);
|
|
3017
|
+
}
|
|
2842
3018
|
var MCPorterProvider = () => ({
|
|
2843
3019
|
name: () => "MCPorter",
|
|
2844
3020
|
id: () => "mcporter",
|
|
@@ -2849,12 +3025,10 @@ var MCPorterProvider = () => ({
|
|
|
2849
3025
|
globalConfigPath: () => resolveGlobalConfigPath(),
|
|
2850
3026
|
isConfigured: () => isJSONKeyConfigured(resolveGlobalConfigPath(), "mcpServers"),
|
|
2851
3027
|
install(cfg, global) {
|
|
2852
|
-
if (cfg.mode !== MODE_OSS && !cfg.deployment_id)
|
|
2853
|
-
throw new Error("deployment ID is required");
|
|
2854
3028
|
const configPath = global ? resolveGlobalConfigPath() : join12(process.cwd(), "config", "mcporter.json");
|
|
2855
3029
|
const server = {
|
|
2856
3030
|
type: "http",
|
|
2857
|
-
url:
|
|
3031
|
+
url: mcpEndpoint4(cfg),
|
|
2858
3032
|
headers: mcpHeaders(cfg.api_key)
|
|
2859
3033
|
};
|
|
2860
3034
|
installJSONServer(configPath, "mcpServers", server);
|
|
@@ -3485,17 +3659,17 @@ import y2 from "node:process";
|
|
|
3485
3659
|
function ce() {
|
|
3486
3660
|
return y2.platform !== "win32" ? y2.env.TERM !== "linux" : !!y2.env.CI || !!y2.env.WT_SESSION || !!y2.env.TERMINUS_SUBLIME || y2.env.ConEmuTask === "{cmd::Cmder}" || y2.env.TERM_PROGRAM === "Terminus-Sublime" || y2.env.TERM_PROGRAM === "vscode" || y2.env.TERM === "xterm-256color" || y2.env.TERM === "alacritty" || y2.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
|
|
3487
3661
|
}
|
|
3488
|
-
var
|
|
3662
|
+
var import_picocolors19, import_sisteransi2, V2, u = (t, n) => V2 ? t : n, le, L2, W2, C2, ue, o, d2, k2, P2, A2, T, F, $e, _2, me, de, pe, q, D, U, K2, b2 = (t) => {
|
|
3489
3663
|
switch (t) {
|
|
3490
3664
|
case "initial":
|
|
3491
3665
|
case "active":
|
|
3492
|
-
return
|
|
3666
|
+
return import_picocolors19.default.cyan(le);
|
|
3493
3667
|
case "cancel":
|
|
3494
|
-
return
|
|
3668
|
+
return import_picocolors19.default.red(L2);
|
|
3495
3669
|
case "error":
|
|
3496
|
-
return
|
|
3670
|
+
return import_picocolors19.default.yellow(W2);
|
|
3497
3671
|
case "submit":
|
|
3498
|
-
return
|
|
3672
|
+
return import_picocolors19.default.green(C2);
|
|
3499
3673
|
}
|
|
3500
3674
|
}, G2 = (t) => {
|
|
3501
3675
|
const { cursor: n, options: r, style: i } = t, s = t.maxItems ?? Number.POSITIVE_INFINITY, c = Math.max(process.stdout.rows - 4, 0), a = Math.min(c, Math.max(s, 5));
|
|
@@ -3504,23 +3678,23 @@ var import_picocolors3, import_sisteransi2, V2, u = (t, n) => V2 ? t : n, le, L2
|
|
|
3504
3678
|
const $2 = a < r.length && l2 > 0, g2 = a < r.length && l2 + a < r.length;
|
|
3505
3679
|
return r.slice(l2, l2 + a).map((p2, v, f) => {
|
|
3506
3680
|
const j2 = v === 0 && $2, E = v === f.length - 1 && g2;
|
|
3507
|
-
return j2 || E ?
|
|
3681
|
+
return j2 || E ? import_picocolors19.default.dim("...") : i(p2, v + l2 === n);
|
|
3508
3682
|
});
|
|
3509
3683
|
}, ye = (t) => {
|
|
3510
3684
|
const n = t.active ?? "Yes", r = t.inactive ?? "No";
|
|
3511
3685
|
return new dD({ active: n, inactive: r, initialValue: t.initialValue ?? true, render() {
|
|
3512
|
-
const i = `${
|
|
3686
|
+
const i = `${import_picocolors19.default.gray(o)}
|
|
3513
3687
|
${b2(this.state)} ${t.message}
|
|
3514
3688
|
`, s = this.value ? n : r;
|
|
3515
3689
|
switch (this.state) {
|
|
3516
3690
|
case "submit":
|
|
3517
|
-
return `${i}${
|
|
3691
|
+
return `${i}${import_picocolors19.default.gray(o)} ${import_picocolors19.default.dim(s)}`;
|
|
3518
3692
|
case "cancel":
|
|
3519
|
-
return `${i}${
|
|
3520
|
-
${
|
|
3693
|
+
return `${i}${import_picocolors19.default.gray(o)} ${import_picocolors19.default.strikethrough(import_picocolors19.default.dim(s))}
|
|
3694
|
+
${import_picocolors19.default.gray(o)}`;
|
|
3521
3695
|
default:
|
|
3522
|
-
return `${i}${
|
|
3523
|
-
${
|
|
3696
|
+
return `${i}${import_picocolors19.default.cyan(o)} ${this.value ? `${import_picocolors19.default.green(k2)} ${n}` : `${import_picocolors19.default.dim(P2)} ${import_picocolors19.default.dim(n)}`} ${import_picocolors19.default.dim("/")} ${this.value ? `${import_picocolors19.default.dim(P2)} ${import_picocolors19.default.dim(r)}` : `${import_picocolors19.default.green(k2)} ${r}`}
|
|
3697
|
+
${import_picocolors19.default.cyan(d2)}
|
|
3524
3698
|
`;
|
|
3525
3699
|
}
|
|
3526
3700
|
} }).prompt();
|
|
@@ -3529,43 +3703,43 @@ ${import_picocolors3.default.cyan(d2)}
|
|
|
3529
3703
|
const s = r.label ?? String(r.value);
|
|
3530
3704
|
switch (i) {
|
|
3531
3705
|
case "selected":
|
|
3532
|
-
return `${
|
|
3706
|
+
return `${import_picocolors19.default.dim(s)}`;
|
|
3533
3707
|
case "active":
|
|
3534
|
-
return `${
|
|
3708
|
+
return `${import_picocolors19.default.green(k2)} ${s} ${r.hint ? import_picocolors19.default.dim(`(${r.hint})`) : ""}`;
|
|
3535
3709
|
case "cancelled":
|
|
3536
|
-
return `${
|
|
3710
|
+
return `${import_picocolors19.default.strikethrough(import_picocolors19.default.dim(s))}`;
|
|
3537
3711
|
default:
|
|
3538
|
-
return `${
|
|
3712
|
+
return `${import_picocolors19.default.dim(P2)} ${import_picocolors19.default.dim(s)}`;
|
|
3539
3713
|
}
|
|
3540
3714
|
};
|
|
3541
3715
|
return new LD({ options: t.options, initialValue: t.initialValue, render() {
|
|
3542
|
-
const r = `${
|
|
3716
|
+
const r = `${import_picocolors19.default.gray(o)}
|
|
3543
3717
|
${b2(this.state)} ${t.message}
|
|
3544
3718
|
`;
|
|
3545
3719
|
switch (this.state) {
|
|
3546
3720
|
case "submit":
|
|
3547
|
-
return `${r}${
|
|
3721
|
+
return `${r}${import_picocolors19.default.gray(o)} ${n(this.options[this.cursor], "selected")}`;
|
|
3548
3722
|
case "cancel":
|
|
3549
|
-
return `${r}${
|
|
3550
|
-
${
|
|
3723
|
+
return `${r}${import_picocolors19.default.gray(o)} ${n(this.options[this.cursor], "cancelled")}
|
|
3724
|
+
${import_picocolors19.default.gray(o)}`;
|
|
3551
3725
|
default:
|
|
3552
|
-
return `${r}${
|
|
3553
|
-
${
|
|
3554
|
-
${
|
|
3726
|
+
return `${r}${import_picocolors19.default.cyan(o)} ${G2({ cursor: this.cursor, options: this.options, maxItems: t.maxItems, style: (i, s) => n(i, s ? "active" : "inactive") }).join(`
|
|
3727
|
+
${import_picocolors19.default.cyan(o)} `)}
|
|
3728
|
+
${import_picocolors19.default.cyan(d2)}
|
|
3555
3729
|
`;
|
|
3556
3730
|
}
|
|
3557
3731
|
} }).prompt();
|
|
3558
3732
|
}, fe = (t) => {
|
|
3559
3733
|
const n = (r, i) => {
|
|
3560
3734
|
const s = r.label ?? String(r.value);
|
|
3561
|
-
return i === "active" ? `${
|
|
3735
|
+
return i === "active" ? `${import_picocolors19.default.cyan(A2)} ${s} ${r.hint ? import_picocolors19.default.dim(`(${r.hint})`) : ""}` : i === "selected" ? `${import_picocolors19.default.green(T)} ${import_picocolors19.default.dim(s)} ${r.hint ? import_picocolors19.default.dim(`(${r.hint})`) : ""}` : i === "cancelled" ? `${import_picocolors19.default.strikethrough(import_picocolors19.default.dim(s))}` : i === "active-selected" ? `${import_picocolors19.default.green(T)} ${s} ${r.hint ? import_picocolors19.default.dim(`(${r.hint})`) : ""}` : i === "submitted" ? `${import_picocolors19.default.dim(s)}` : `${import_picocolors19.default.dim(F)} ${import_picocolors19.default.dim(s)}`;
|
|
3562
3736
|
};
|
|
3563
3737
|
return new SD({ options: t.options, initialValues: t.initialValues, required: t.required ?? true, cursorAt: t.cursorAt, validate(r) {
|
|
3564
3738
|
if (this.required && r.length === 0)
|
|
3565
3739
|
return `Please select at least one option.
|
|
3566
|
-
${
|
|
3740
|
+
${import_picocolors19.default.reset(import_picocolors19.default.dim(`Press ${import_picocolors19.default.gray(import_picocolors19.default.bgWhite(import_picocolors19.default.inverse(" space ")))} to select, ${import_picocolors19.default.gray(import_picocolors19.default.bgWhite(import_picocolors19.default.inverse(" enter ")))} to submit`))}`;
|
|
3567
3741
|
}, render() {
|
|
3568
|
-
const r = `${
|
|
3742
|
+
const r = `${import_picocolors19.default.gray(o)}
|
|
3569
3743
|
${b2(this.state)} ${t.message}
|
|
3570
3744
|
`, i = (s, c) => {
|
|
3571
3745
|
const a = this.value.includes(s.value);
|
|
@@ -3573,34 +3747,34 @@ ${b2(this.state)} ${t.message}
|
|
|
3573
3747
|
};
|
|
3574
3748
|
switch (this.state) {
|
|
3575
3749
|
case "submit":
|
|
3576
|
-
return `${r}${
|
|
3750
|
+
return `${r}${import_picocolors19.default.gray(o)} ${this.options.filter(({ value: s }) => this.value.includes(s)).map((s) => n(s, "submitted")).join(import_picocolors19.default.dim(", ")) || import_picocolors19.default.dim("none")}`;
|
|
3577
3751
|
case "cancel": {
|
|
3578
|
-
const s = this.options.filter(({ value: c }) => this.value.includes(c)).map((c) => n(c, "cancelled")).join(
|
|
3579
|
-
return `${r}${
|
|
3580
|
-
${
|
|
3752
|
+
const s = this.options.filter(({ value: c }) => this.value.includes(c)).map((c) => n(c, "cancelled")).join(import_picocolors19.default.dim(", "));
|
|
3753
|
+
return `${r}${import_picocolors19.default.gray(o)} ${s.trim() ? `${s}
|
|
3754
|
+
${import_picocolors19.default.gray(o)}` : ""}`;
|
|
3581
3755
|
}
|
|
3582
3756
|
case "error": {
|
|
3583
3757
|
const s = this.error.split(`
|
|
3584
|
-
`).map((c, a) => a === 0 ? `${
|
|
3758
|
+
`).map((c, a) => a === 0 ? `${import_picocolors19.default.yellow(d2)} ${import_picocolors19.default.yellow(c)}` : ` ${c}`).join(`
|
|
3585
3759
|
`);
|
|
3586
|
-
return `${r +
|
|
3587
|
-
${
|
|
3760
|
+
return `${r + import_picocolors19.default.yellow(o)} ${G2({ options: this.options, cursor: this.cursor, maxItems: t.maxItems, style: i }).join(`
|
|
3761
|
+
${import_picocolors19.default.yellow(o)} `)}
|
|
3588
3762
|
${s}
|
|
3589
3763
|
`;
|
|
3590
3764
|
}
|
|
3591
3765
|
default:
|
|
3592
|
-
return `${r}${
|
|
3593
|
-
${
|
|
3594
|
-
${
|
|
3766
|
+
return `${r}${import_picocolors19.default.cyan(o)} ${G2({ options: this.options, cursor: this.cursor, maxItems: t.maxItems, style: i }).join(`
|
|
3767
|
+
${import_picocolors19.default.cyan(o)} `)}
|
|
3768
|
+
${import_picocolors19.default.cyan(d2)}
|
|
3595
3769
|
`;
|
|
3596
3770
|
}
|
|
3597
3771
|
} }).prompt();
|
|
3598
3772
|
}, Ie = (t = "") => {
|
|
3599
|
-
process.stdout.write(`${
|
|
3773
|
+
process.stdout.write(`${import_picocolors19.default.gray(ue)} ${t}
|
|
3600
3774
|
`);
|
|
3601
3775
|
}, Se = (t = "") => {
|
|
3602
|
-
process.stdout.write(`${
|
|
3603
|
-
${
|
|
3776
|
+
process.stdout.write(`${import_picocolors19.default.gray(o)}
|
|
3777
|
+
${import_picocolors19.default.gray(d2)} ${t}
|
|
3604
3778
|
|
|
3605
3779
|
`);
|
|
3606
3780
|
}, M2, J2, Y2 = ({ indicator: t = "dots" } = {}) => {
|
|
@@ -3625,14 +3799,14 @@ ${import_picocolors3.default.gray(d2)} ${t}
|
|
|
3625
3799
|
const h2 = (performance.now() - m2) / 1000, w2 = Math.floor(h2 / 60), I2 = Math.floor(h2 % 60);
|
|
3626
3800
|
return w2 > 0 ? `[${w2}m ${I2}s]` : `[${I2}s]`;
|
|
3627
3801
|
}, H2 = (m2 = "") => {
|
|
3628
|
-
a = true, s = fD(), l2 = R2(m2), g2 = performance.now(), process.stdout.write(`${
|
|
3802
|
+
a = true, s = fD(), l2 = R2(m2), g2 = performance.now(), process.stdout.write(`${import_picocolors19.default.gray(o)}
|
|
3629
3803
|
`);
|
|
3630
3804
|
let h2 = 0, w2 = 0;
|
|
3631
3805
|
j2(), c = setInterval(() => {
|
|
3632
3806
|
if (i && l2 === $2)
|
|
3633
3807
|
return;
|
|
3634
3808
|
B2(), $2 = l2;
|
|
3635
|
-
const I2 =
|
|
3809
|
+
const I2 = import_picocolors19.default.magenta(n[h2]);
|
|
3636
3810
|
if (i)
|
|
3637
3811
|
process.stdout.write(`${I2} ${l2}...`);
|
|
3638
3812
|
else if (t === "timer")
|
|
@@ -3645,7 +3819,7 @@ ${import_picocolors3.default.gray(d2)} ${t}
|
|
|
3645
3819
|
}, r);
|
|
3646
3820
|
}, N2 = (m2 = "", h2 = 0) => {
|
|
3647
3821
|
a = false, clearInterval(c), B2();
|
|
3648
|
-
const w2 = h2 === 0 ?
|
|
3822
|
+
const w2 = h2 === 0 ? import_picocolors19.default.green(C2) : h2 === 1 ? import_picocolors19.default.red(L2) : import_picocolors19.default.red(W2);
|
|
3649
3823
|
l2 = R2(m2 ?? l2), t === "timer" ? process.stdout.write(`${w2} ${l2} ${O2(g2)}
|
|
3650
3824
|
`) : process.stdout.write(`${w2} ${l2}
|
|
3651
3825
|
`), E(), s();
|
|
@@ -3657,7 +3831,7 @@ ${import_picocolors3.default.gray(d2)} ${t}
|
|
|
3657
3831
|
var init_dist2 = __esm(() => {
|
|
3658
3832
|
init_dist();
|
|
3659
3833
|
init_dist();
|
|
3660
|
-
|
|
3834
|
+
import_picocolors19 = __toESM(require_picocolors(), 1);
|
|
3661
3835
|
import_sisteransi2 = __toESM(require_src(), 1);
|
|
3662
3836
|
V2 = ce();
|
|
3663
3837
|
le = u("◆", "*");
|
|
@@ -3681,192 +3855,42 @@ var init_dist2 = __esm(() => {
|
|
|
3681
3855
|
D = u("◆", "*");
|
|
3682
3856
|
U = u("▲", "!");
|
|
3683
3857
|
K2 = u("■", "x");
|
|
3684
|
-
M2 = { message: (t = "", { symbol: n =
|
|
3685
|
-
const r = [`${
|
|
3858
|
+
M2 = { message: (t = "", { symbol: n = import_picocolors19.default.gray(o) } = {}) => {
|
|
3859
|
+
const r = [`${import_picocolors19.default.gray(o)}`];
|
|
3686
3860
|
if (t) {
|
|
3687
3861
|
const [i, ...s] = t.split(`
|
|
3688
3862
|
`);
|
|
3689
|
-
r.push(`${n} ${i}`, ...s.map((c) => `${
|
|
3863
|
+
r.push(`${n} ${i}`, ...s.map((c) => `${import_picocolors19.default.gray(o)} ${c}`));
|
|
3690
3864
|
}
|
|
3691
3865
|
process.stdout.write(`${r.join(`
|
|
3692
3866
|
`)}
|
|
3693
3867
|
`);
|
|
3694
3868
|
}, info: (t) => {
|
|
3695
|
-
M2.message(t, { symbol:
|
|
3869
|
+
M2.message(t, { symbol: import_picocolors19.default.blue(q) });
|
|
3696
3870
|
}, success: (t) => {
|
|
3697
|
-
M2.message(t, { symbol:
|
|
3871
|
+
M2.message(t, { symbol: import_picocolors19.default.green(D) });
|
|
3698
3872
|
}, step: (t) => {
|
|
3699
|
-
M2.message(t, { symbol:
|
|
3873
|
+
M2.message(t, { symbol: import_picocolors19.default.green(C2) });
|
|
3700
3874
|
}, warn: (t) => {
|
|
3701
|
-
M2.message(t, { symbol:
|
|
3875
|
+
M2.message(t, { symbol: import_picocolors19.default.yellow(U) });
|
|
3702
3876
|
}, warning: (t) => {
|
|
3703
3877
|
M2.warn(t);
|
|
3704
3878
|
}, error: (t) => {
|
|
3705
|
-
M2.message(t, { symbol:
|
|
3879
|
+
M2.message(t, { symbol: import_picocolors19.default.red(K2) });
|
|
3706
3880
|
} };
|
|
3707
|
-
J2 = `${
|
|
3708
|
-
});
|
|
3709
|
-
|
|
3710
|
-
// src/client/client.ts
|
|
3711
|
-
class Client {
|
|
3712
|
-
baseURL;
|
|
3713
|
-
config;
|
|
3714
|
-
constructor(cfg) {
|
|
3715
|
-
this.baseURL = getBackendURL();
|
|
3716
|
-
this.config = cfg;
|
|
3717
|
-
}
|
|
3718
|
-
async doRequest(method, path, body) {
|
|
3719
|
-
if (!isAuthenticated(this.config)) {
|
|
3720
|
-
throw new Error("not authenticated - please run setup first");
|
|
3721
|
-
}
|
|
3722
|
-
if (isTokenExpired(this.config)) {
|
|
3723
|
-
await this.refreshToken();
|
|
3724
|
-
}
|
|
3725
|
-
let resp = await this.doRequestOnce(method, path, body);
|
|
3726
|
-
if (resp.status === 401 || resp.status === 403) {
|
|
3727
|
-
try {
|
|
3728
|
-
await this.refreshToken();
|
|
3729
|
-
} catch {
|
|
3730
|
-
throw new SessionExpiredError;
|
|
3731
|
-
}
|
|
3732
|
-
resp = await this.doRequestOnce(method, path, body);
|
|
3733
|
-
}
|
|
3734
|
-
return resp;
|
|
3735
|
-
}
|
|
3736
|
-
async doRequestRaw(method, path) {
|
|
3737
|
-
return this.doRequestOnce(method, path);
|
|
3738
|
-
}
|
|
3739
|
-
async doRequestOnce(method, path, body) {
|
|
3740
|
-
const url = this.baseURL + path;
|
|
3741
|
-
const headers = {
|
|
3742
|
-
"Content-Type": "application/json",
|
|
3743
|
-
"Supabase-Access-Token": this.config.access_token
|
|
3744
|
-
};
|
|
3745
|
-
const options = { method, headers };
|
|
3746
|
-
if (body !== undefined) {
|
|
3747
|
-
options.body = JSON.stringify(body);
|
|
3748
|
-
}
|
|
3749
|
-
const controller = new AbortController;
|
|
3750
|
-
const timeout = setTimeout(() => controller.abort(), 1e4);
|
|
3751
|
-
options.signal = controller.signal;
|
|
3752
|
-
try {
|
|
3753
|
-
return await fetch(url, options);
|
|
3754
|
-
} finally {
|
|
3755
|
-
clearTimeout(timeout);
|
|
3756
|
-
}
|
|
3757
|
-
}
|
|
3758
|
-
async get(path) {
|
|
3759
|
-
return this.doRequest("GET", path);
|
|
3760
|
-
}
|
|
3761
|
-
async post(path, body) {
|
|
3762
|
-
return this.doRequest("POST", path, body);
|
|
3763
|
-
}
|
|
3764
|
-
async put(path, body) {
|
|
3765
|
-
return this.doRequest("PUT", path, body);
|
|
3766
|
-
}
|
|
3767
|
-
async delete(path) {
|
|
3768
|
-
return this.doRequest("DELETE", path);
|
|
3769
|
-
}
|
|
3770
|
-
async refreshToken() {
|
|
3771
|
-
if (!this.config.refresh_token) {
|
|
3772
|
-
throw new Error("no refresh token available");
|
|
3773
|
-
}
|
|
3774
|
-
const supabaseURL = getSupabaseURL();
|
|
3775
|
-
const endpoint = `${supabaseURL}/auth/v1/token?grant_type=refresh_token`;
|
|
3776
|
-
const resp = await fetch(endpoint, {
|
|
3777
|
-
method: "POST",
|
|
3778
|
-
headers: {
|
|
3779
|
-
"Content-Type": "application/json",
|
|
3780
|
-
apikey: getSupabaseAnonKey()
|
|
3781
|
-
},
|
|
3782
|
-
body: JSON.stringify({ refresh_token: this.config.refresh_token })
|
|
3783
|
-
});
|
|
3784
|
-
if (resp.status !== 200) {
|
|
3785
|
-
throw new Error(`refresh failed with status ${resp.status}`);
|
|
3786
|
-
}
|
|
3787
|
-
const data = await resp.json();
|
|
3788
|
-
this.config.access_token = data.access_token;
|
|
3789
|
-
this.config.refresh_token = data.refresh_token;
|
|
3790
|
-
this.config.expires_at = Math.floor(Date.now() / 1000) + data.expires_in;
|
|
3791
|
-
saveConfig(this.config);
|
|
3792
|
-
}
|
|
3793
|
-
async getDeployments() {
|
|
3794
|
-
const resp = await this.get("/v1/mcp/deployments");
|
|
3795
|
-
if (resp.status !== 200) {
|
|
3796
|
-
let detail = await readErrorBody(resp);
|
|
3797
|
-
if (!detail || detail === "Internal Server Error") {
|
|
3798
|
-
detail = "check backend logs for details";
|
|
3799
|
-
}
|
|
3800
|
-
throw new Error(`failed to fetch deployments (status ${resp.status}): ${detail}`);
|
|
3801
|
-
}
|
|
3802
|
-
return resp.json();
|
|
3803
|
-
}
|
|
3804
|
-
async getOrgs() {
|
|
3805
|
-
const resp = await this.get("/v1/mcp/orgs");
|
|
3806
|
-
if (resp.status !== 200) {
|
|
3807
|
-
const detail = await readErrorBody(resp);
|
|
3808
|
-
throw new Error(`failed to fetch orgs (status ${resp.status}): ${detail}`);
|
|
3809
|
-
}
|
|
3810
|
-
return resp.json();
|
|
3811
|
-
}
|
|
3812
|
-
async validateAPIKey(apiKey, deploymentID) {
|
|
3813
|
-
try {
|
|
3814
|
-
const endpoint = `${this.baseURL}/v1/mcp/deployments/${encodeURIComponent(deploymentID)}`;
|
|
3815
|
-
const controller = new AbortController;
|
|
3816
|
-
const timeout = setTimeout(() => controller.abort(), 5000);
|
|
3817
|
-
try {
|
|
3818
|
-
const resp = await fetch(endpoint, {
|
|
3819
|
-
method: "GET",
|
|
3820
|
-
headers: { "X-Dosu-API-Key": apiKey },
|
|
3821
|
-
signal: controller.signal
|
|
3822
|
-
});
|
|
3823
|
-
return resp.status !== 401 && resp.status !== 403;
|
|
3824
|
-
} finally {
|
|
3825
|
-
clearTimeout(timeout);
|
|
3826
|
-
}
|
|
3827
|
-
} catch {
|
|
3828
|
-
return true;
|
|
3829
|
-
}
|
|
3830
|
-
}
|
|
3831
|
-
async createAPIKey(deploymentID, name) {
|
|
3832
|
-
const path = `/v1/mcp/deployments/${deploymentID}/api-keys`;
|
|
3833
|
-
const resp = await this.post(path, { name });
|
|
3834
|
-
if (resp.status !== 200 && resp.status !== 201) {
|
|
3835
|
-
const detail = await readErrorBody(resp);
|
|
3836
|
-
throw new Error(`failed to create API key (status ${resp.status}): ${detail}`);
|
|
3837
|
-
}
|
|
3838
|
-
return resp.json();
|
|
3839
|
-
}
|
|
3840
|
-
}
|
|
3841
|
-
async function readErrorBody(resp) {
|
|
3842
|
-
try {
|
|
3843
|
-
const text = await resp.text();
|
|
3844
|
-
return text.slice(0, 1024);
|
|
3845
|
-
} catch {
|
|
3846
|
-
return "";
|
|
3847
|
-
}
|
|
3848
|
-
}
|
|
3849
|
-
var SessionExpiredError;
|
|
3850
|
-
var init_client = __esm(() => {
|
|
3851
|
-
init_config();
|
|
3852
|
-
SessionExpiredError = class SessionExpiredError extends Error {
|
|
3853
|
-
constructor() {
|
|
3854
|
-
super("session expired");
|
|
3855
|
-
this.name = "SessionExpiredError";
|
|
3856
|
-
}
|
|
3857
|
-
};
|
|
3881
|
+
J2 = `${import_picocolors19.default.gray(o)} `;
|
|
3858
3882
|
});
|
|
3859
3883
|
|
|
3860
3884
|
// src/setup/styles.ts
|
|
3861
3885
|
function dim(msg) {
|
|
3862
|
-
return
|
|
3886
|
+
return import_picocolors20.default.dim(msg);
|
|
3863
3887
|
}
|
|
3864
3888
|
function info(msg) {
|
|
3865
|
-
return
|
|
3889
|
+
return import_picocolors20.default.cyan(msg);
|
|
3866
3890
|
}
|
|
3867
|
-
var
|
|
3891
|
+
var import_picocolors20;
|
|
3868
3892
|
var init_styles = __esm(() => {
|
|
3869
|
-
|
|
3893
|
+
import_picocolors20 = __toESM(require_picocolors(), 1);
|
|
3870
3894
|
});
|
|
3871
3895
|
|
|
3872
3896
|
// src/auth/server.ts
|
|
@@ -4690,11 +4714,15 @@ async function runSetup(opts = {}) {
|
|
|
4690
4714
|
cfg.mode = undefined;
|
|
4691
4715
|
cfg.deployment_id = d3.deployment_id;
|
|
4692
4716
|
cfg.deployment_name = d3.name;
|
|
4717
|
+
cfg.org_id = d3.org_id;
|
|
4718
|
+
cfg.space_id = d3.space_id;
|
|
4693
4719
|
} else if (cfg.mode === MODE_OSS) {
|
|
4694
4720
|
const deployments = await fetchDeployments(apiClient);
|
|
4695
4721
|
if (deployments.length > 0) {
|
|
4696
4722
|
cfg.deployment_id = deployments[0].deployment_id;
|
|
4697
4723
|
cfg.deployment_name = deployments[0].name;
|
|
4724
|
+
cfg.org_id = deployments[0].org_id;
|
|
4725
|
+
cfg.space_id = deployments[0].space_id;
|
|
4698
4726
|
}
|
|
4699
4727
|
} else {
|
|
4700
4728
|
const org = await stepSelectOrg(apiClient);
|
|
@@ -4706,6 +4734,8 @@ async function runSetup(opts = {}) {
|
|
|
4706
4734
|
cfg.mode = undefined;
|
|
4707
4735
|
cfg.deployment_id = d3.deployment_id;
|
|
4708
4736
|
cfg.deployment_name = d3.name;
|
|
4737
|
+
cfg.org_id = d3.org_id;
|
|
4738
|
+
cfg.space_id = d3.space_id;
|
|
4709
4739
|
}
|
|
4710
4740
|
saveConfig(cfg);
|
|
4711
4741
|
const apiKey = await stepMintAPIKey(apiClient, cfg);
|
|
@@ -5028,7 +5058,7 @@ __export(exports_tui, {
|
|
|
5028
5058
|
handleLogout: () => handleLogout
|
|
5029
5059
|
});
|
|
5030
5060
|
async function runTUI() {
|
|
5031
|
-
console.log(
|
|
5061
|
+
console.log(import_picocolors21.default.magenta(LOGO));
|
|
5032
5062
|
const cfg = loadConfig();
|
|
5033
5063
|
if (!isAuthenticated(cfg)) {
|
|
5034
5064
|
await handleAuthenticate(cfg);
|
|
@@ -5125,7 +5155,7 @@ function handleLogout(cfg) {
|
|
|
5125
5155
|
saveConfig(cfg);
|
|
5126
5156
|
M2.success("Credentials cleared.");
|
|
5127
5157
|
}
|
|
5128
|
-
var
|
|
5158
|
+
var import_picocolors21, LOGO = `
|
|
5129
5159
|
/$$$$$$$
|
|
5130
5160
|
| $$__ $$
|
|
5131
5161
|
| $$ \\ $$ /$$$$$$ /$$$$$$$ /$$ /$$
|
|
@@ -5140,11 +5170,11 @@ var init_tui = __esm(() => {
|
|
|
5140
5170
|
init_client();
|
|
5141
5171
|
init_config();
|
|
5142
5172
|
init_flow2();
|
|
5143
|
-
|
|
5173
|
+
import_picocolors21 = __toESM(require_picocolors(), 1);
|
|
5144
5174
|
});
|
|
5145
5175
|
|
|
5146
5176
|
// src/cli/cli.ts
|
|
5147
|
-
import { readFileSync as
|
|
5177
|
+
import { readFileSync as readFileSync7, unlinkSync } from "node:fs";
|
|
5148
5178
|
|
|
5149
5179
|
// node_modules/commander/esm.mjs
|
|
5150
5180
|
var import__ = __toESM(require_commander(), 1);
|
|
@@ -5162,91 +5192,3642 @@ var {
|
|
|
5162
5192
|
Help
|
|
5163
5193
|
} = import__.default;
|
|
5164
5194
|
|
|
5165
|
-
// src/
|
|
5166
|
-
|
|
5167
|
-
init_logger();
|
|
5168
|
-
init_providers();
|
|
5195
|
+
// src/commands/analytics.ts
|
|
5196
|
+
var import_picocolors4 = __toESM(require_picocolors(), 1);
|
|
5169
5197
|
|
|
5170
|
-
//
|
|
5171
|
-
|
|
5172
|
-
|
|
5173
|
-
var
|
|
5174
|
-
|
|
5175
|
-
|
|
5176
|
-
var
|
|
5177
|
-
var
|
|
5178
|
-
|
|
5179
|
-
|
|
5180
|
-
|
|
5181
|
-
|
|
5182
|
-
|
|
5183
|
-
|
|
5184
|
-
|
|
5185
|
-
|
|
5186
|
-
|
|
5187
|
-
|
|
5188
|
-
|
|
5189
|
-
|
|
5190
|
-
|
|
5198
|
+
// node_modules/@trpc/client/dist/objectSpread2-BvkFp-_Y.mjs
|
|
5199
|
+
var __create2 = Object.create;
|
|
5200
|
+
var __defProp2 = Object.defineProperty;
|
|
5201
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5202
|
+
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
5203
|
+
var __getProtoOf2 = Object.getPrototypeOf;
|
|
5204
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
5205
|
+
var __commonJS2 = (cb, mod) => function() {
|
|
5206
|
+
return mod || (0, cb[__getOwnPropNames2(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
5207
|
+
};
|
|
5208
|
+
var __copyProps = (to, from, except, desc) => {
|
|
5209
|
+
if (from && typeof from === "object" || typeof from === "function")
|
|
5210
|
+
for (var keys = __getOwnPropNames2(from), i = 0, n = keys.length, key;i < n; i++) {
|
|
5211
|
+
key = keys[i];
|
|
5212
|
+
if (!__hasOwnProp2.call(to, key) && key !== except)
|
|
5213
|
+
__defProp2(to, key, {
|
|
5214
|
+
get: ((k) => from[k]).bind(null, key),
|
|
5215
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
5216
|
+
});
|
|
5217
|
+
}
|
|
5218
|
+
return to;
|
|
5219
|
+
};
|
|
5220
|
+
var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", {
|
|
5221
|
+
value: mod,
|
|
5222
|
+
enumerable: true
|
|
5223
|
+
}) : target, mod));
|
|
5224
|
+
var require_typeof = __commonJS2({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/typeof.js"(exports, module) {
|
|
5225
|
+
function _typeof$2(o) {
|
|
5226
|
+
"@babel/helpers - typeof";
|
|
5227
|
+
return module.exports = _typeof$2 = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(o$1) {
|
|
5228
|
+
return typeof o$1;
|
|
5229
|
+
} : function(o$1) {
|
|
5230
|
+
return o$1 && typeof Symbol == "function" && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
5231
|
+
}, module.exports.__esModule = true, module.exports["default"] = module.exports, _typeof$2(o);
|
|
5232
|
+
}
|
|
5233
|
+
module.exports = _typeof$2, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
5234
|
+
} });
|
|
5235
|
+
var require_toPrimitive = __commonJS2({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/toPrimitive.js"(exports, module) {
|
|
5236
|
+
var _typeof$1 = require_typeof()["default"];
|
|
5237
|
+
function toPrimitive$1(t, r) {
|
|
5238
|
+
if (_typeof$1(t) != "object" || !t)
|
|
5239
|
+
return t;
|
|
5240
|
+
var e = t[Symbol.toPrimitive];
|
|
5241
|
+
if (e !== undefined) {
|
|
5242
|
+
var i = e.call(t, r || "default");
|
|
5243
|
+
if (_typeof$1(i) != "object")
|
|
5244
|
+
return i;
|
|
5245
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
5246
|
+
}
|
|
5247
|
+
return (r === "string" ? String : Number)(t);
|
|
5248
|
+
}
|
|
5249
|
+
module.exports = toPrimitive$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
5250
|
+
} });
|
|
5251
|
+
var require_toPropertyKey = __commonJS2({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/toPropertyKey.js"(exports, module) {
|
|
5252
|
+
var _typeof = require_typeof()["default"];
|
|
5253
|
+
var toPrimitive = require_toPrimitive();
|
|
5254
|
+
function toPropertyKey$1(t) {
|
|
5255
|
+
var i = toPrimitive(t, "string");
|
|
5256
|
+
return _typeof(i) == "symbol" ? i : i + "";
|
|
5257
|
+
}
|
|
5258
|
+
module.exports = toPropertyKey$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
5259
|
+
} });
|
|
5260
|
+
var require_defineProperty = __commonJS2({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/defineProperty.js"(exports, module) {
|
|
5261
|
+
var toPropertyKey = require_toPropertyKey();
|
|
5262
|
+
function _defineProperty(e, r, t) {
|
|
5263
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
5264
|
+
value: t,
|
|
5265
|
+
enumerable: true,
|
|
5266
|
+
configurable: true,
|
|
5267
|
+
writable: true
|
|
5268
|
+
}) : e[r] = t, e;
|
|
5269
|
+
}
|
|
5270
|
+
module.exports = _defineProperty, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
5271
|
+
} });
|
|
5272
|
+
var require_objectSpread2 = __commonJS2({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/objectSpread2.js"(exports, module) {
|
|
5273
|
+
var defineProperty = require_defineProperty();
|
|
5274
|
+
function ownKeys(e, r) {
|
|
5275
|
+
var t = Object.keys(e);
|
|
5276
|
+
if (Object.getOwnPropertySymbols) {
|
|
5277
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
5278
|
+
r && (o = o.filter(function(r$1) {
|
|
5279
|
+
return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
|
|
5280
|
+
})), t.push.apply(t, o);
|
|
5281
|
+
}
|
|
5282
|
+
return t;
|
|
5283
|
+
}
|
|
5284
|
+
function _objectSpread2(e) {
|
|
5285
|
+
for (var r = 1;r < arguments.length; r++) {
|
|
5286
|
+
var t = arguments[r] != null ? arguments[r] : {};
|
|
5287
|
+
r % 2 ? ownKeys(Object(t), true).forEach(function(r$1) {
|
|
5288
|
+
defineProperty(e, r$1, t[r$1]);
|
|
5289
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r$1) {
|
|
5290
|
+
Object.defineProperty(e, r$1, Object.getOwnPropertyDescriptor(t, r$1));
|
|
5291
|
+
});
|
|
5292
|
+
}
|
|
5293
|
+
return e;
|
|
5191
5294
|
}
|
|
5192
|
-
|
|
5295
|
+
module.exports = _objectSpread2, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
5296
|
+
} });
|
|
5297
|
+
|
|
5298
|
+
// node_modules/@trpc/server/dist/observable-UMO3vUa_.mjs
|
|
5299
|
+
function observable(subscribe) {
|
|
5300
|
+
const self = {
|
|
5301
|
+
subscribe(observer) {
|
|
5302
|
+
let teardownRef = null;
|
|
5303
|
+
let isDone = false;
|
|
5304
|
+
let unsubscribed = false;
|
|
5305
|
+
let teardownImmediately = false;
|
|
5306
|
+
function unsubscribe() {
|
|
5307
|
+
if (teardownRef === null) {
|
|
5308
|
+
teardownImmediately = true;
|
|
5309
|
+
return;
|
|
5310
|
+
}
|
|
5311
|
+
if (unsubscribed)
|
|
5312
|
+
return;
|
|
5313
|
+
unsubscribed = true;
|
|
5314
|
+
if (typeof teardownRef === "function")
|
|
5315
|
+
teardownRef();
|
|
5316
|
+
else if (teardownRef)
|
|
5317
|
+
teardownRef.unsubscribe();
|
|
5318
|
+
}
|
|
5319
|
+
teardownRef = subscribe({
|
|
5320
|
+
next(value) {
|
|
5321
|
+
var _observer$next;
|
|
5322
|
+
if (isDone)
|
|
5323
|
+
return;
|
|
5324
|
+
(_observer$next = observer.next) === null || _observer$next === undefined || _observer$next.call(observer, value);
|
|
5325
|
+
},
|
|
5326
|
+
error(err) {
|
|
5327
|
+
var _observer$error;
|
|
5328
|
+
if (isDone)
|
|
5329
|
+
return;
|
|
5330
|
+
isDone = true;
|
|
5331
|
+
(_observer$error = observer.error) === null || _observer$error === undefined || _observer$error.call(observer, err);
|
|
5332
|
+
unsubscribe();
|
|
5333
|
+
},
|
|
5334
|
+
complete() {
|
|
5335
|
+
var _observer$complete;
|
|
5336
|
+
if (isDone)
|
|
5337
|
+
return;
|
|
5338
|
+
isDone = true;
|
|
5339
|
+
(_observer$complete = observer.complete) === null || _observer$complete === undefined || _observer$complete.call(observer);
|
|
5340
|
+
unsubscribe();
|
|
5341
|
+
}
|
|
5342
|
+
});
|
|
5343
|
+
if (teardownImmediately)
|
|
5344
|
+
unsubscribe();
|
|
5345
|
+
return { unsubscribe };
|
|
5346
|
+
},
|
|
5347
|
+
pipe(...operations) {
|
|
5348
|
+
return operations.reduce(pipeReducer, self);
|
|
5349
|
+
}
|
|
5350
|
+
};
|
|
5351
|
+
return self;
|
|
5193
5352
|
}
|
|
5194
|
-
function
|
|
5195
|
-
return
|
|
5353
|
+
function pipeReducer(prev, fn) {
|
|
5354
|
+
return fn(prev);
|
|
5196
5355
|
}
|
|
5197
|
-
function
|
|
5198
|
-
|
|
5199
|
-
|
|
5200
|
-
|
|
5201
|
-
|
|
5202
|
-
|
|
5203
|
-
|
|
5204
|
-
|
|
5356
|
+
function observableToPromise(observable$1) {
|
|
5357
|
+
const ac = new AbortController;
|
|
5358
|
+
const promise = new Promise((resolve, reject) => {
|
|
5359
|
+
let isDone = false;
|
|
5360
|
+
function onDone() {
|
|
5361
|
+
if (isDone)
|
|
5362
|
+
return;
|
|
5363
|
+
isDone = true;
|
|
5364
|
+
obs$.unsubscribe();
|
|
5205
5365
|
}
|
|
5206
|
-
|
|
5207
|
-
|
|
5208
|
-
|
|
5366
|
+
ac.signal.addEventListener("abort", () => {
|
|
5367
|
+
reject(ac.signal.reason);
|
|
5368
|
+
});
|
|
5369
|
+
const obs$ = observable$1.subscribe({
|
|
5370
|
+
next(data) {
|
|
5371
|
+
isDone = true;
|
|
5372
|
+
resolve(data);
|
|
5373
|
+
onDone();
|
|
5374
|
+
},
|
|
5375
|
+
error(data) {
|
|
5376
|
+
reject(data);
|
|
5377
|
+
},
|
|
5378
|
+
complete() {
|
|
5379
|
+
ac.abort();
|
|
5380
|
+
onDone();
|
|
5381
|
+
}
|
|
5382
|
+
});
|
|
5383
|
+
});
|
|
5384
|
+
return promise;
|
|
5385
|
+
}
|
|
5386
|
+
|
|
5387
|
+
// node_modules/@trpc/server/dist/observable-CUiPknO-.mjs
|
|
5388
|
+
function share(_opts) {
|
|
5389
|
+
return (source) => {
|
|
5390
|
+
let refCount = 0;
|
|
5391
|
+
let subscription = null;
|
|
5392
|
+
const observers = [];
|
|
5393
|
+
function startIfNeeded() {
|
|
5394
|
+
if (subscription)
|
|
5395
|
+
return;
|
|
5396
|
+
subscription = source.subscribe({
|
|
5397
|
+
next(value) {
|
|
5398
|
+
for (const observer of observers) {
|
|
5399
|
+
var _observer$next;
|
|
5400
|
+
(_observer$next = observer.next) === null || _observer$next === undefined || _observer$next.call(observer, value);
|
|
5401
|
+
}
|
|
5402
|
+
},
|
|
5403
|
+
error(error) {
|
|
5404
|
+
for (const observer of observers) {
|
|
5405
|
+
var _observer$error;
|
|
5406
|
+
(_observer$error = observer.error) === null || _observer$error === undefined || _observer$error.call(observer, error);
|
|
5407
|
+
}
|
|
5408
|
+
},
|
|
5409
|
+
complete() {
|
|
5410
|
+
for (const observer of observers) {
|
|
5411
|
+
var _observer$complete;
|
|
5412
|
+
(_observer$complete = observer.complete) === null || _observer$complete === undefined || _observer$complete.call(observer);
|
|
5413
|
+
}
|
|
5414
|
+
}
|
|
5415
|
+
});
|
|
5416
|
+
}
|
|
5417
|
+
function resetIfNeeded() {
|
|
5418
|
+
if (refCount === 0 && subscription) {
|
|
5419
|
+
const _sub = subscription;
|
|
5420
|
+
subscription = null;
|
|
5421
|
+
_sub.unsubscribe();
|
|
5422
|
+
}
|
|
5423
|
+
}
|
|
5424
|
+
return observable((subscriber) => {
|
|
5425
|
+
refCount++;
|
|
5426
|
+
observers.push(subscriber);
|
|
5427
|
+
startIfNeeded();
|
|
5428
|
+
return { unsubscribe() {
|
|
5429
|
+
refCount--;
|
|
5430
|
+
resetIfNeeded();
|
|
5431
|
+
const index = observers.findIndex((v) => v === subscriber);
|
|
5432
|
+
if (index > -1)
|
|
5433
|
+
observers.splice(index, 1);
|
|
5434
|
+
} };
|
|
5435
|
+
});
|
|
5436
|
+
};
|
|
5437
|
+
}
|
|
5438
|
+
var distinctUnsetMarker = Symbol();
|
|
5439
|
+
function behaviorSubject(initialValue) {
|
|
5440
|
+
let value = initialValue;
|
|
5441
|
+
const observerList = [];
|
|
5442
|
+
const addObserver = (observer) => {
|
|
5443
|
+
if (value !== undefined)
|
|
5444
|
+
observer.next(value);
|
|
5445
|
+
observerList.push(observer);
|
|
5446
|
+
};
|
|
5447
|
+
const removeObserver = (observer) => {
|
|
5448
|
+
observerList.splice(observerList.indexOf(observer), 1);
|
|
5449
|
+
};
|
|
5450
|
+
const obs = observable((observer) => {
|
|
5451
|
+
addObserver(observer);
|
|
5452
|
+
return () => {
|
|
5453
|
+
removeObserver(observer);
|
|
5454
|
+
};
|
|
5455
|
+
});
|
|
5456
|
+
obs.next = (nextValue) => {
|
|
5457
|
+
if (value === nextValue)
|
|
5458
|
+
return;
|
|
5459
|
+
value = nextValue;
|
|
5460
|
+
for (const observer of observerList)
|
|
5461
|
+
observer.next(nextValue);
|
|
5462
|
+
};
|
|
5463
|
+
obs.get = () => value;
|
|
5464
|
+
return obs;
|
|
5465
|
+
}
|
|
5466
|
+
|
|
5467
|
+
// node_modules/@trpc/client/dist/splitLink-B7Cuf2c_.mjs
|
|
5468
|
+
function createChain(opts) {
|
|
5469
|
+
return observable((observer) => {
|
|
5470
|
+
function execute(index = 0, op = opts.op) {
|
|
5471
|
+
const next = opts.links[index];
|
|
5472
|
+
if (!next)
|
|
5473
|
+
throw new Error("No more links to execute - did you forget to add an ending link?");
|
|
5474
|
+
const subscription = next({
|
|
5475
|
+
op,
|
|
5476
|
+
next(nextOp) {
|
|
5477
|
+
const nextObserver = execute(index + 1, nextOp);
|
|
5478
|
+
return nextObserver;
|
|
5479
|
+
}
|
|
5480
|
+
});
|
|
5481
|
+
return subscription;
|
|
5482
|
+
}
|
|
5483
|
+
const obs$ = execute();
|
|
5484
|
+
return obs$.subscribe(observer);
|
|
5485
|
+
});
|
|
5486
|
+
}
|
|
5487
|
+
|
|
5488
|
+
// node_modules/@trpc/server/dist/utils-CLZnJdb_.mjs
|
|
5489
|
+
var TRPC_ERROR_CODES_BY_KEY = {
|
|
5490
|
+
PARSE_ERROR: -32700,
|
|
5491
|
+
BAD_REQUEST: -32600,
|
|
5492
|
+
INTERNAL_SERVER_ERROR: -32603,
|
|
5493
|
+
NOT_IMPLEMENTED: -32603,
|
|
5494
|
+
BAD_GATEWAY: -32603,
|
|
5495
|
+
SERVICE_UNAVAILABLE: -32603,
|
|
5496
|
+
GATEWAY_TIMEOUT: -32603,
|
|
5497
|
+
UNAUTHORIZED: -32001,
|
|
5498
|
+
PAYMENT_REQUIRED: -32002,
|
|
5499
|
+
FORBIDDEN: -32003,
|
|
5500
|
+
NOT_FOUND: -32004,
|
|
5501
|
+
METHOD_NOT_SUPPORTED: -32005,
|
|
5502
|
+
TIMEOUT: -32008,
|
|
5503
|
+
CONFLICT: -32009,
|
|
5504
|
+
PRECONDITION_FAILED: -32012,
|
|
5505
|
+
PAYLOAD_TOO_LARGE: -32013,
|
|
5506
|
+
UNSUPPORTED_MEDIA_TYPE: -32015,
|
|
5507
|
+
UNPROCESSABLE_CONTENT: -32022,
|
|
5508
|
+
PRECONDITION_REQUIRED: -32028,
|
|
5509
|
+
TOO_MANY_REQUESTS: -32029,
|
|
5510
|
+
CLIENT_CLOSED_REQUEST: -32099
|
|
5511
|
+
};
|
|
5512
|
+
var retryableRpcCodes = [
|
|
5513
|
+
TRPC_ERROR_CODES_BY_KEY.BAD_GATEWAY,
|
|
5514
|
+
TRPC_ERROR_CODES_BY_KEY.SERVICE_UNAVAILABLE,
|
|
5515
|
+
TRPC_ERROR_CODES_BY_KEY.GATEWAY_TIMEOUT,
|
|
5516
|
+
TRPC_ERROR_CODES_BY_KEY.INTERNAL_SERVER_ERROR
|
|
5517
|
+
];
|
|
5518
|
+
function isObject(value) {
|
|
5519
|
+
return !!value && !Array.isArray(value) && typeof value === "object";
|
|
5520
|
+
}
|
|
5521
|
+
|
|
5522
|
+
// node_modules/@trpc/server/dist/getErrorShape-BH60iMC2.mjs
|
|
5523
|
+
var __create3 = Object.create;
|
|
5524
|
+
var __defProp3 = Object.defineProperty;
|
|
5525
|
+
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
5526
|
+
var __getOwnPropNames3 = Object.getOwnPropertyNames;
|
|
5527
|
+
var __getProtoOf3 = Object.getPrototypeOf;
|
|
5528
|
+
var __hasOwnProp3 = Object.prototype.hasOwnProperty;
|
|
5529
|
+
var __commonJS3 = (cb, mod) => function() {
|
|
5530
|
+
return mod || (0, cb[__getOwnPropNames3(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
5531
|
+
};
|
|
5532
|
+
var __copyProps2 = (to, from, except, desc) => {
|
|
5533
|
+
if (from && typeof from === "object" || typeof from === "function")
|
|
5534
|
+
for (var keys = __getOwnPropNames3(from), i = 0, n = keys.length, key;i < n; i++) {
|
|
5535
|
+
key = keys[i];
|
|
5536
|
+
if (!__hasOwnProp3.call(to, key) && key !== except)
|
|
5537
|
+
__defProp3(to, key, {
|
|
5538
|
+
get: ((k) => from[k]).bind(null, key),
|
|
5539
|
+
enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable
|
|
5540
|
+
});
|
|
5541
|
+
}
|
|
5542
|
+
return to;
|
|
5543
|
+
};
|
|
5544
|
+
var __toESM3 = (mod, isNodeMode, target) => (target = mod != null ? __create3(__getProtoOf3(mod)) : {}, __copyProps2(isNodeMode || !mod || !mod.__esModule ? __defProp3(target, "default", {
|
|
5545
|
+
value: mod,
|
|
5546
|
+
enumerable: true
|
|
5547
|
+
}) : target, mod));
|
|
5548
|
+
var noop = () => {};
|
|
5549
|
+
var freezeIfAvailable = (obj) => {
|
|
5550
|
+
if (Object.freeze)
|
|
5551
|
+
Object.freeze(obj);
|
|
5552
|
+
};
|
|
5553
|
+
function createInnerProxy(callback, path, memo) {
|
|
5554
|
+
var _memo$cacheKey;
|
|
5555
|
+
const cacheKey = path.join(".");
|
|
5556
|
+
(_memo$cacheKey = memo[cacheKey]) !== null && _memo$cacheKey !== undefined || (memo[cacheKey] = new Proxy(noop, {
|
|
5557
|
+
get(_obj, key) {
|
|
5558
|
+
if (typeof key !== "string" || key === "then")
|
|
5559
|
+
return;
|
|
5560
|
+
return createInnerProxy(callback, [...path, key], memo);
|
|
5561
|
+
},
|
|
5562
|
+
apply(_1, _2, args) {
|
|
5563
|
+
const lastOfPath = path[path.length - 1];
|
|
5564
|
+
let opts = {
|
|
5565
|
+
args,
|
|
5566
|
+
path
|
|
5567
|
+
};
|
|
5568
|
+
if (lastOfPath === "call")
|
|
5569
|
+
opts = {
|
|
5570
|
+
args: args.length >= 2 ? [args[1]] : [],
|
|
5571
|
+
path: path.slice(0, -1)
|
|
5572
|
+
};
|
|
5573
|
+
else if (lastOfPath === "apply")
|
|
5574
|
+
opts = {
|
|
5575
|
+
args: args.length >= 2 ? args[1] : [],
|
|
5576
|
+
path: path.slice(0, -1)
|
|
5577
|
+
};
|
|
5578
|
+
freezeIfAvailable(opts.args);
|
|
5579
|
+
freezeIfAvailable(opts.path);
|
|
5580
|
+
return callback(opts);
|
|
5581
|
+
}
|
|
5582
|
+
}));
|
|
5583
|
+
return memo[cacheKey];
|
|
5584
|
+
}
|
|
5585
|
+
var createRecursiveProxy = (callback) => createInnerProxy(callback, [], Object.create(null));
|
|
5586
|
+
var createFlatProxy = (callback) => {
|
|
5587
|
+
return new Proxy(noop, { get(_obj, name) {
|
|
5588
|
+
if (name === "then")
|
|
5589
|
+
return;
|
|
5590
|
+
return callback(name);
|
|
5591
|
+
} });
|
|
5592
|
+
};
|
|
5593
|
+
var require_typeof2 = __commonJS3({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/typeof.js"(exports, module) {
|
|
5594
|
+
function _typeof$2(o) {
|
|
5595
|
+
"@babel/helpers - typeof";
|
|
5596
|
+
return module.exports = _typeof$2 = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(o$1) {
|
|
5597
|
+
return typeof o$1;
|
|
5598
|
+
} : function(o$1) {
|
|
5599
|
+
return o$1 && typeof Symbol == "function" && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
5600
|
+
}, module.exports.__esModule = true, module.exports["default"] = module.exports, _typeof$2(o);
|
|
5601
|
+
}
|
|
5602
|
+
module.exports = _typeof$2, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
5603
|
+
} });
|
|
5604
|
+
var require_toPrimitive2 = __commonJS3({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/toPrimitive.js"(exports, module) {
|
|
5605
|
+
var _typeof$1 = require_typeof2()["default"];
|
|
5606
|
+
function toPrimitive$1(t, r) {
|
|
5607
|
+
if (_typeof$1(t) != "object" || !t)
|
|
5608
|
+
return t;
|
|
5609
|
+
var e = t[Symbol.toPrimitive];
|
|
5610
|
+
if (e !== undefined) {
|
|
5611
|
+
var i = e.call(t, r || "default");
|
|
5612
|
+
if (_typeof$1(i) != "object")
|
|
5613
|
+
return i;
|
|
5614
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
5615
|
+
}
|
|
5616
|
+
return (r === "string" ? String : Number)(t);
|
|
5617
|
+
}
|
|
5618
|
+
module.exports = toPrimitive$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
5619
|
+
} });
|
|
5620
|
+
var require_toPropertyKey2 = __commonJS3({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/toPropertyKey.js"(exports, module) {
|
|
5621
|
+
var _typeof = require_typeof2()["default"];
|
|
5622
|
+
var toPrimitive = require_toPrimitive2();
|
|
5623
|
+
function toPropertyKey$1(t) {
|
|
5624
|
+
var i = toPrimitive(t, "string");
|
|
5625
|
+
return _typeof(i) == "symbol" ? i : i + "";
|
|
5626
|
+
}
|
|
5627
|
+
module.exports = toPropertyKey$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
5628
|
+
} });
|
|
5629
|
+
var require_defineProperty2 = __commonJS3({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/defineProperty.js"(exports, module) {
|
|
5630
|
+
var toPropertyKey = require_toPropertyKey2();
|
|
5631
|
+
function _defineProperty(e, r, t) {
|
|
5632
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
5633
|
+
value: t,
|
|
5634
|
+
enumerable: true,
|
|
5635
|
+
configurable: true,
|
|
5636
|
+
writable: true
|
|
5637
|
+
}) : e[r] = t, e;
|
|
5638
|
+
}
|
|
5639
|
+
module.exports = _defineProperty, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
5640
|
+
} });
|
|
5641
|
+
var require_objectSpread22 = __commonJS3({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/objectSpread2.js"(exports, module) {
|
|
5642
|
+
var defineProperty = require_defineProperty2();
|
|
5643
|
+
function ownKeys(e, r) {
|
|
5644
|
+
var t = Object.keys(e);
|
|
5645
|
+
if (Object.getOwnPropertySymbols) {
|
|
5646
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
5647
|
+
r && (o = o.filter(function(r$1) {
|
|
5648
|
+
return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
|
|
5649
|
+
})), t.push.apply(t, o);
|
|
5650
|
+
}
|
|
5651
|
+
return t;
|
|
5652
|
+
}
|
|
5653
|
+
function _objectSpread2(e) {
|
|
5654
|
+
for (var r = 1;r < arguments.length; r++) {
|
|
5655
|
+
var t = arguments[r] != null ? arguments[r] : {};
|
|
5656
|
+
r % 2 ? ownKeys(Object(t), true).forEach(function(r$1) {
|
|
5657
|
+
defineProperty(e, r$1, t[r$1]);
|
|
5658
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r$1) {
|
|
5659
|
+
Object.defineProperty(e, r$1, Object.getOwnPropertyDescriptor(t, r$1));
|
|
5660
|
+
});
|
|
5661
|
+
}
|
|
5662
|
+
return e;
|
|
5663
|
+
}
|
|
5664
|
+
module.exports = _objectSpread2, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
5665
|
+
} });
|
|
5666
|
+
var import_objectSpread2 = __toESM3(require_objectSpread22(), 1);
|
|
5667
|
+
|
|
5668
|
+
// node_modules/@trpc/server/dist/tracked-DBSMdVzR.mjs
|
|
5669
|
+
var import_defineProperty = __toESM3(require_defineProperty2(), 1);
|
|
5670
|
+
var import_objectSpread2$1 = __toESM3(require_objectSpread22(), 1);
|
|
5671
|
+
function transformResultInner(response, transformer) {
|
|
5672
|
+
if ("error" in response) {
|
|
5673
|
+
const error = transformer.deserialize(response.error);
|
|
5674
|
+
return {
|
|
5675
|
+
ok: false,
|
|
5676
|
+
error: (0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, response), {}, { error })
|
|
5677
|
+
};
|
|
5209
5678
|
}
|
|
5679
|
+
const result = (0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, response.result), (!response.result.type || response.result.type === "data") && {
|
|
5680
|
+
type: "data",
|
|
5681
|
+
data: transformer.deserialize(response.result.data)
|
|
5682
|
+
});
|
|
5683
|
+
return {
|
|
5684
|
+
ok: true,
|
|
5685
|
+
result
|
|
5686
|
+
};
|
|
5210
5687
|
}
|
|
5211
|
-
|
|
5688
|
+
var TransformResultError = class extends Error {
|
|
5689
|
+
constructor() {
|
|
5690
|
+
super("Unable to transform response from server");
|
|
5691
|
+
}
|
|
5692
|
+
};
|
|
5693
|
+
function transformResult(response, transformer) {
|
|
5694
|
+
let result;
|
|
5212
5695
|
try {
|
|
5213
|
-
|
|
5214
|
-
} catch {
|
|
5696
|
+
result = transformResultInner(response, transformer);
|
|
5697
|
+
} catch (_unused) {
|
|
5698
|
+
throw new TransformResultError;
|
|
5699
|
+
}
|
|
5700
|
+
if (!result.ok && (!isObject(result.error.error) || typeof result.error.error["code"] !== "number"))
|
|
5701
|
+
throw new TransformResultError;
|
|
5702
|
+
if (result.ok && !isObject(result.result))
|
|
5703
|
+
throw new TransformResultError;
|
|
5704
|
+
return result;
|
|
5215
5705
|
}
|
|
5216
|
-
|
|
5217
|
-
|
|
5218
|
-
|
|
5219
|
-
|
|
5220
|
-
|
|
5221
|
-
|
|
5222
|
-
|
|
5223
|
-
|
|
5224
|
-
|
|
5225
|
-
|
|
5226
|
-
|
|
5227
|
-
|
|
5228
|
-
|
|
5229
|
-
|
|
5706
|
+
var import_objectSpread22 = __toESM3(require_objectSpread22(), 1);
|
|
5707
|
+
var trackedSymbol = Symbol();
|
|
5708
|
+
|
|
5709
|
+
// node_modules/@trpc/client/dist/TRPCClientError-CjKyS10w.mjs
|
|
5710
|
+
var import_defineProperty2 = __toESM2(require_defineProperty(), 1);
|
|
5711
|
+
var import_objectSpread23 = __toESM2(require_objectSpread2(), 1);
|
|
5712
|
+
function isTRPCClientError(cause) {
|
|
5713
|
+
return cause instanceof TRPCClientError;
|
|
5714
|
+
}
|
|
5715
|
+
function isTRPCErrorResponse(obj) {
|
|
5716
|
+
return isObject(obj) && isObject(obj["error"]) && typeof obj["error"]["code"] === "number" && typeof obj["error"]["message"] === "string";
|
|
5717
|
+
}
|
|
5718
|
+
function getMessageFromUnknownError(err, fallback) {
|
|
5719
|
+
if (typeof err === "string")
|
|
5720
|
+
return err;
|
|
5721
|
+
if (isObject(err) && typeof err["message"] === "string")
|
|
5722
|
+
return err["message"];
|
|
5723
|
+
return fallback;
|
|
5724
|
+
}
|
|
5725
|
+
var TRPCClientError = class TRPCClientError2 extends Error {
|
|
5726
|
+
constructor(message, opts) {
|
|
5727
|
+
var _opts$result, _opts$result2;
|
|
5728
|
+
const cause = opts === null || opts === undefined ? undefined : opts.cause;
|
|
5729
|
+
super(message, { cause });
|
|
5730
|
+
(0, import_defineProperty2.default)(this, "cause", undefined);
|
|
5731
|
+
(0, import_defineProperty2.default)(this, "shape", undefined);
|
|
5732
|
+
(0, import_defineProperty2.default)(this, "data", undefined);
|
|
5733
|
+
(0, import_defineProperty2.default)(this, "meta", undefined);
|
|
5734
|
+
this.meta = opts === null || opts === undefined ? undefined : opts.meta;
|
|
5735
|
+
this.cause = cause;
|
|
5736
|
+
this.shape = opts === null || opts === undefined || (_opts$result = opts.result) === null || _opts$result === undefined ? undefined : _opts$result.error;
|
|
5737
|
+
this.data = opts === null || opts === undefined || (_opts$result2 = opts.result) === null || _opts$result2 === undefined ? undefined : _opts$result2.error.data;
|
|
5738
|
+
this.name = "TRPCClientError";
|
|
5739
|
+
Object.setPrototypeOf(this, TRPCClientError2.prototype);
|
|
5740
|
+
}
|
|
5741
|
+
static from(_cause, opts = {}) {
|
|
5742
|
+
const cause = _cause;
|
|
5743
|
+
if (isTRPCClientError(cause)) {
|
|
5744
|
+
if (opts.meta)
|
|
5745
|
+
cause.meta = (0, import_objectSpread23.default)((0, import_objectSpread23.default)({}, cause.meta), opts.meta);
|
|
5746
|
+
return cause;
|
|
5747
|
+
}
|
|
5748
|
+
if (isTRPCErrorResponse(cause))
|
|
5749
|
+
return new TRPCClientError2(cause.error.message, (0, import_objectSpread23.default)((0, import_objectSpread23.default)({}, opts), {}, { result: cause }));
|
|
5750
|
+
return new TRPCClientError2(getMessageFromUnknownError(cause, "Unknown error"), (0, import_objectSpread23.default)((0, import_objectSpread23.default)({}, opts), {}, { cause }));
|
|
5230
5751
|
}
|
|
5752
|
+
};
|
|
5753
|
+
|
|
5754
|
+
// node_modules/@trpc/client/dist/unstable-internals-Bg7n9BBj.mjs
|
|
5755
|
+
function getTransformer(transformer) {
|
|
5756
|
+
const _transformer = transformer;
|
|
5757
|
+
if (!_transformer)
|
|
5758
|
+
return {
|
|
5759
|
+
input: {
|
|
5760
|
+
serialize: (data) => data,
|
|
5761
|
+
deserialize: (data) => data
|
|
5762
|
+
},
|
|
5763
|
+
output: {
|
|
5764
|
+
serialize: (data) => data,
|
|
5765
|
+
deserialize: (data) => data
|
|
5766
|
+
}
|
|
5767
|
+
};
|
|
5768
|
+
if ("input" in _transformer)
|
|
5769
|
+
return _transformer;
|
|
5770
|
+
return {
|
|
5771
|
+
input: _transformer,
|
|
5772
|
+
output: _transformer
|
|
5773
|
+
};
|
|
5231
5774
|
}
|
|
5232
|
-
|
|
5233
|
-
|
|
5234
|
-
|
|
5235
|
-
|
|
5236
|
-
|
|
5237
|
-
|
|
5775
|
+
|
|
5776
|
+
// node_modules/@trpc/client/dist/httpUtils-Dv57hbOd.mjs
|
|
5777
|
+
var isFunction2 = (fn) => typeof fn === "function";
|
|
5778
|
+
function getFetch(customFetchImpl) {
|
|
5779
|
+
if (customFetchImpl)
|
|
5780
|
+
return customFetchImpl;
|
|
5781
|
+
if (typeof window !== "undefined" && isFunction2(window.fetch))
|
|
5782
|
+
return window.fetch;
|
|
5783
|
+
if (typeof globalThis !== "undefined" && isFunction2(globalThis.fetch))
|
|
5784
|
+
return globalThis.fetch;
|
|
5785
|
+
throw new Error("No fetch implementation found");
|
|
5238
5786
|
}
|
|
5239
|
-
|
|
5240
|
-
|
|
5241
|
-
|
|
5242
|
-
|
|
5243
|
-
|
|
5244
|
-
|
|
5245
|
-
|
|
5246
|
-
|
|
5247
|
-
|
|
5787
|
+
var import_objectSpread24 = __toESM2(require_objectSpread2(), 1);
|
|
5788
|
+
function resolveHTTPLinkOptions(opts) {
|
|
5789
|
+
return {
|
|
5790
|
+
url: opts.url.toString(),
|
|
5791
|
+
fetch: opts.fetch,
|
|
5792
|
+
transformer: getTransformer(opts.transformer),
|
|
5793
|
+
methodOverride: opts.methodOverride
|
|
5794
|
+
};
|
|
5795
|
+
}
|
|
5796
|
+
function arrayToDict(array) {
|
|
5797
|
+
const dict = {};
|
|
5798
|
+
for (let index = 0;index < array.length; index++) {
|
|
5799
|
+
const element = array[index];
|
|
5800
|
+
dict[index] = element;
|
|
5801
|
+
}
|
|
5802
|
+
return dict;
|
|
5803
|
+
}
|
|
5804
|
+
var METHOD = {
|
|
5805
|
+
query: "GET",
|
|
5806
|
+
mutation: "POST",
|
|
5807
|
+
subscription: "PATCH"
|
|
5808
|
+
};
|
|
5809
|
+
function getInput(opts) {
|
|
5810
|
+
return "input" in opts ? opts.transformer.input.serialize(opts.input) : arrayToDict(opts.inputs.map((_input) => opts.transformer.input.serialize(_input)));
|
|
5811
|
+
}
|
|
5812
|
+
var getUrl = (opts) => {
|
|
5813
|
+
const parts = opts.url.split("?");
|
|
5814
|
+
const base = parts[0].replace(/\/$/, "");
|
|
5815
|
+
let url = base + "/" + opts.path;
|
|
5816
|
+
const queryParts = [];
|
|
5817
|
+
if (parts[1])
|
|
5818
|
+
queryParts.push(parts[1]);
|
|
5819
|
+
if ("inputs" in opts)
|
|
5820
|
+
queryParts.push("batch=1");
|
|
5821
|
+
if (opts.type === "query" || opts.type === "subscription") {
|
|
5822
|
+
const input = getInput(opts);
|
|
5823
|
+
if (input !== undefined && opts.methodOverride !== "POST")
|
|
5824
|
+
queryParts.push(`input=${encodeURIComponent(JSON.stringify(input))}`);
|
|
5825
|
+
}
|
|
5826
|
+
if (queryParts.length)
|
|
5827
|
+
url += "?" + queryParts.join("&");
|
|
5828
|
+
return url;
|
|
5829
|
+
};
|
|
5830
|
+
var getBody = (opts) => {
|
|
5831
|
+
if (opts.type === "query" && opts.methodOverride !== "POST")
|
|
5832
|
+
return;
|
|
5833
|
+
const input = getInput(opts);
|
|
5834
|
+
return input !== undefined ? JSON.stringify(input) : undefined;
|
|
5835
|
+
};
|
|
5836
|
+
var jsonHttpRequester = (opts) => {
|
|
5837
|
+
return httpRequest((0, import_objectSpread24.default)((0, import_objectSpread24.default)({}, opts), {}, {
|
|
5838
|
+
contentTypeHeader: "application/json",
|
|
5839
|
+
getUrl,
|
|
5840
|
+
getBody
|
|
5841
|
+
}));
|
|
5842
|
+
};
|
|
5843
|
+
var AbortError = class extends Error {
|
|
5844
|
+
constructor() {
|
|
5845
|
+
const name = "AbortError";
|
|
5846
|
+
super(name);
|
|
5847
|
+
this.name = name;
|
|
5848
|
+
this.message = name;
|
|
5849
|
+
}
|
|
5850
|
+
};
|
|
5851
|
+
var throwIfAborted = (signal) => {
|
|
5852
|
+
var _signal$throwIfAborte;
|
|
5853
|
+
if (!(signal === null || signal === undefined ? undefined : signal.aborted))
|
|
5854
|
+
return;
|
|
5855
|
+
(_signal$throwIfAborte = signal.throwIfAborted) === null || _signal$throwIfAborte === undefined || _signal$throwIfAborte.call(signal);
|
|
5856
|
+
if (typeof DOMException !== "undefined")
|
|
5857
|
+
throw new DOMException("AbortError", "AbortError");
|
|
5858
|
+
throw new AbortError;
|
|
5859
|
+
};
|
|
5860
|
+
async function fetchHTTPResponse(opts) {
|
|
5861
|
+
var _opts$methodOverride;
|
|
5862
|
+
throwIfAborted(opts.signal);
|
|
5863
|
+
const url = opts.getUrl(opts);
|
|
5864
|
+
const body = opts.getBody(opts);
|
|
5865
|
+
const method = (_opts$methodOverride = opts.methodOverride) !== null && _opts$methodOverride !== undefined ? _opts$methodOverride : METHOD[opts.type];
|
|
5866
|
+
const resolvedHeaders = await (async () => {
|
|
5867
|
+
const heads = await opts.headers();
|
|
5868
|
+
if (Symbol.iterator in heads)
|
|
5869
|
+
return Object.fromEntries(heads);
|
|
5870
|
+
return heads;
|
|
5871
|
+
})();
|
|
5872
|
+
const headers = (0, import_objectSpread24.default)((0, import_objectSpread24.default)((0, import_objectSpread24.default)({}, opts.contentTypeHeader && method !== "GET" ? { "content-type": opts.contentTypeHeader } : {}), opts.trpcAcceptHeader ? { "trpc-accept": opts.trpcAcceptHeader } : undefined), resolvedHeaders);
|
|
5873
|
+
return getFetch(opts.fetch)(url, {
|
|
5874
|
+
method,
|
|
5875
|
+
signal: opts.signal,
|
|
5876
|
+
body,
|
|
5877
|
+
headers
|
|
5878
|
+
});
|
|
5879
|
+
}
|
|
5880
|
+
async function httpRequest(opts) {
|
|
5881
|
+
const meta = {};
|
|
5882
|
+
const res = await fetchHTTPResponse(opts);
|
|
5883
|
+
meta.response = res;
|
|
5884
|
+
const json = await res.json();
|
|
5885
|
+
meta.responseJSON = json;
|
|
5886
|
+
return {
|
|
5887
|
+
json,
|
|
5888
|
+
meta
|
|
5889
|
+
};
|
|
5890
|
+
}
|
|
5891
|
+
|
|
5892
|
+
// node_modules/@trpc/client/dist/httpLink-DCFpUmZF.mjs
|
|
5893
|
+
function isOctetType(input) {
|
|
5894
|
+
return input instanceof Uint8Array || input instanceof Blob;
|
|
5895
|
+
}
|
|
5896
|
+
function isFormData(input) {
|
|
5897
|
+
return input instanceof FormData;
|
|
5898
|
+
}
|
|
5899
|
+
var import_objectSpread25 = __toESM2(require_objectSpread2(), 1);
|
|
5900
|
+
var universalRequester = (opts) => {
|
|
5901
|
+
if ("input" in opts) {
|
|
5902
|
+
const { input } = opts;
|
|
5903
|
+
if (isFormData(input)) {
|
|
5904
|
+
if (opts.type !== "mutation" && opts.methodOverride !== "POST")
|
|
5905
|
+
throw new Error("FormData is only supported for mutations");
|
|
5906
|
+
return httpRequest((0, import_objectSpread25.default)((0, import_objectSpread25.default)({}, opts), {}, {
|
|
5907
|
+
contentTypeHeader: undefined,
|
|
5908
|
+
getUrl,
|
|
5909
|
+
getBody: () => input
|
|
5910
|
+
}));
|
|
5911
|
+
}
|
|
5912
|
+
if (isOctetType(input)) {
|
|
5913
|
+
if (opts.type !== "mutation" && opts.methodOverride !== "POST")
|
|
5914
|
+
throw new Error("Octet type input is only supported for mutations");
|
|
5915
|
+
return httpRequest((0, import_objectSpread25.default)((0, import_objectSpread25.default)({}, opts), {}, {
|
|
5916
|
+
contentTypeHeader: "application/octet-stream",
|
|
5917
|
+
getUrl,
|
|
5918
|
+
getBody: () => input
|
|
5919
|
+
}));
|
|
5920
|
+
}
|
|
5921
|
+
}
|
|
5922
|
+
return jsonHttpRequester(opts);
|
|
5923
|
+
};
|
|
5924
|
+
function httpLink(opts) {
|
|
5925
|
+
const resolvedOpts = resolveHTTPLinkOptions(opts);
|
|
5926
|
+
return () => {
|
|
5927
|
+
return (operationOpts) => {
|
|
5928
|
+
const { op } = operationOpts;
|
|
5929
|
+
return observable((observer) => {
|
|
5930
|
+
const { path, input, type } = op;
|
|
5931
|
+
if (type === "subscription")
|
|
5932
|
+
throw new Error("Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`");
|
|
5933
|
+
const request = universalRequester((0, import_objectSpread25.default)((0, import_objectSpread25.default)({}, resolvedOpts), {}, {
|
|
5934
|
+
type,
|
|
5935
|
+
path,
|
|
5936
|
+
input,
|
|
5937
|
+
signal: op.signal,
|
|
5938
|
+
headers() {
|
|
5939
|
+
if (!opts.headers)
|
|
5940
|
+
return {};
|
|
5941
|
+
if (typeof opts.headers === "function")
|
|
5942
|
+
return opts.headers({ op });
|
|
5943
|
+
return opts.headers;
|
|
5944
|
+
}
|
|
5945
|
+
}));
|
|
5946
|
+
let meta = undefined;
|
|
5947
|
+
request.then((res) => {
|
|
5948
|
+
meta = res.meta;
|
|
5949
|
+
const transformed = transformResult(res.json, resolvedOpts.transformer.output);
|
|
5950
|
+
if (!transformed.ok) {
|
|
5951
|
+
observer.error(TRPCClientError.from(transformed.error, { meta }));
|
|
5952
|
+
return;
|
|
5953
|
+
}
|
|
5954
|
+
observer.next({
|
|
5955
|
+
context: res.meta,
|
|
5956
|
+
result: transformed.result
|
|
5957
|
+
});
|
|
5958
|
+
observer.complete();
|
|
5959
|
+
}).catch((cause) => {
|
|
5960
|
+
observer.error(TRPCClientError.from(cause, { meta }));
|
|
5961
|
+
});
|
|
5962
|
+
return () => {};
|
|
5963
|
+
});
|
|
5964
|
+
};
|
|
5965
|
+
};
|
|
5966
|
+
}
|
|
5967
|
+
|
|
5968
|
+
// node_modules/@trpc/client/dist/httpBatchLink-BOe5aCcR.mjs
|
|
5969
|
+
var import_objectSpread26 = __toESM2(require_objectSpread2(), 1);
|
|
5970
|
+
|
|
5971
|
+
// node_modules/@trpc/client/dist/loggerLink-ineCN1PO.mjs
|
|
5972
|
+
var import_objectSpread27 = __toESM2(require_objectSpread2(), 1);
|
|
5973
|
+
|
|
5974
|
+
// node_modules/@trpc/client/dist/wsLink-CatceK3c.mjs
|
|
5975
|
+
var resultOf = (value, ...args) => {
|
|
5976
|
+
return typeof value === "function" ? value(...args) : value;
|
|
5977
|
+
};
|
|
5978
|
+
var import_defineProperty$3 = __toESM2(require_defineProperty(), 1);
|
|
5979
|
+
function withResolvers() {
|
|
5980
|
+
let resolve;
|
|
5981
|
+
let reject;
|
|
5982
|
+
const promise = new Promise((res, rej) => {
|
|
5983
|
+
resolve = res;
|
|
5984
|
+
reject = rej;
|
|
5985
|
+
});
|
|
5986
|
+
return {
|
|
5987
|
+
promise,
|
|
5988
|
+
resolve,
|
|
5989
|
+
reject
|
|
5990
|
+
};
|
|
5991
|
+
}
|
|
5992
|
+
async function prepareUrl(urlOptions) {
|
|
5993
|
+
const url = await resultOf(urlOptions.url);
|
|
5994
|
+
if (!urlOptions.connectionParams)
|
|
5995
|
+
return url;
|
|
5996
|
+
const prefix = url.includes("?") ? "&" : "?";
|
|
5997
|
+
const connectionParams = `${prefix}connectionParams=1`;
|
|
5998
|
+
return url + connectionParams;
|
|
5999
|
+
}
|
|
6000
|
+
async function buildConnectionMessage(connectionParams) {
|
|
6001
|
+
const message = {
|
|
6002
|
+
method: "connectionParams",
|
|
6003
|
+
data: await resultOf(connectionParams)
|
|
6004
|
+
};
|
|
6005
|
+
return JSON.stringify(message);
|
|
6006
|
+
}
|
|
6007
|
+
var import_defineProperty$2 = __toESM2(require_defineProperty(), 1);
|
|
6008
|
+
var import_defineProperty$1 = __toESM2(require_defineProperty(), 1);
|
|
6009
|
+
function asyncWsOpen(ws) {
|
|
6010
|
+
const { promise, resolve, reject } = withResolvers();
|
|
6011
|
+
ws.addEventListener("open", () => {
|
|
6012
|
+
ws.removeEventListener("error", reject);
|
|
6013
|
+
resolve();
|
|
6014
|
+
});
|
|
6015
|
+
ws.addEventListener("error", reject);
|
|
6016
|
+
return promise;
|
|
6017
|
+
}
|
|
6018
|
+
function setupPingInterval(ws, { intervalMs, pongTimeoutMs }) {
|
|
6019
|
+
let pingTimeout;
|
|
6020
|
+
let pongTimeout;
|
|
6021
|
+
function start() {
|
|
6022
|
+
pingTimeout = setTimeout(() => {
|
|
6023
|
+
ws.send("PING");
|
|
6024
|
+
pongTimeout = setTimeout(() => {
|
|
6025
|
+
ws.close();
|
|
6026
|
+
}, pongTimeoutMs);
|
|
6027
|
+
}, intervalMs);
|
|
6028
|
+
}
|
|
6029
|
+
function reset() {
|
|
6030
|
+
clearTimeout(pingTimeout);
|
|
6031
|
+
start();
|
|
6032
|
+
}
|
|
6033
|
+
function pong() {
|
|
6034
|
+
clearTimeout(pongTimeout);
|
|
6035
|
+
reset();
|
|
6036
|
+
}
|
|
6037
|
+
ws.addEventListener("open", start);
|
|
6038
|
+
ws.addEventListener("message", ({ data }) => {
|
|
6039
|
+
clearTimeout(pingTimeout);
|
|
6040
|
+
start();
|
|
6041
|
+
if (data === "PONG")
|
|
6042
|
+
pong();
|
|
6043
|
+
});
|
|
6044
|
+
ws.addEventListener("close", () => {
|
|
6045
|
+
clearTimeout(pingTimeout);
|
|
6046
|
+
clearTimeout(pongTimeout);
|
|
6047
|
+
});
|
|
6048
|
+
}
|
|
6049
|
+
var WsConnection = class WsConnection2 {
|
|
6050
|
+
constructor(opts) {
|
|
6051
|
+
var _opts$WebSocketPonyfi;
|
|
6052
|
+
(0, import_defineProperty$1.default)(this, "id", ++WsConnection2.connectCount);
|
|
6053
|
+
(0, import_defineProperty$1.default)(this, "WebSocketPonyfill", undefined);
|
|
6054
|
+
(0, import_defineProperty$1.default)(this, "urlOptions", undefined);
|
|
6055
|
+
(0, import_defineProperty$1.default)(this, "keepAliveOpts", undefined);
|
|
6056
|
+
(0, import_defineProperty$1.default)(this, "wsObservable", behaviorSubject(null));
|
|
6057
|
+
(0, import_defineProperty$1.default)(this, "openPromise", null);
|
|
6058
|
+
this.WebSocketPonyfill = (_opts$WebSocketPonyfi = opts.WebSocketPonyfill) !== null && _opts$WebSocketPonyfi !== undefined ? _opts$WebSocketPonyfi : WebSocket;
|
|
6059
|
+
if (!this.WebSocketPonyfill)
|
|
6060
|
+
throw new Error("No WebSocket implementation found - you probably don't want to use this on the server, but if you do you need to pass a `WebSocket`-ponyfill");
|
|
6061
|
+
this.urlOptions = opts.urlOptions;
|
|
6062
|
+
this.keepAliveOpts = opts.keepAlive;
|
|
6063
|
+
}
|
|
6064
|
+
get ws() {
|
|
6065
|
+
return this.wsObservable.get();
|
|
6066
|
+
}
|
|
6067
|
+
set ws(ws) {
|
|
6068
|
+
this.wsObservable.next(ws);
|
|
6069
|
+
}
|
|
6070
|
+
isOpen() {
|
|
6071
|
+
return !!this.ws && this.ws.readyState === this.WebSocketPonyfill.OPEN && !this.openPromise;
|
|
6072
|
+
}
|
|
6073
|
+
isClosed() {
|
|
6074
|
+
return !!this.ws && (this.ws.readyState === this.WebSocketPonyfill.CLOSING || this.ws.readyState === this.WebSocketPonyfill.CLOSED);
|
|
6075
|
+
}
|
|
6076
|
+
async open() {
|
|
6077
|
+
var _this = this;
|
|
6078
|
+
if (_this.openPromise)
|
|
6079
|
+
return _this.openPromise;
|
|
6080
|
+
_this.id = ++WsConnection2.connectCount;
|
|
6081
|
+
const wsPromise = prepareUrl(_this.urlOptions).then((url) => new _this.WebSocketPonyfill(url));
|
|
6082
|
+
_this.openPromise = wsPromise.then(async (ws) => {
|
|
6083
|
+
_this.ws = ws;
|
|
6084
|
+
ws.addEventListener("message", function({ data }) {
|
|
6085
|
+
if (data === "PING")
|
|
6086
|
+
this.send("PONG");
|
|
6087
|
+
});
|
|
6088
|
+
if (_this.keepAliveOpts.enabled)
|
|
6089
|
+
setupPingInterval(ws, _this.keepAliveOpts);
|
|
6090
|
+
ws.addEventListener("close", () => {
|
|
6091
|
+
if (_this.ws === ws)
|
|
6092
|
+
_this.ws = null;
|
|
6093
|
+
});
|
|
6094
|
+
await asyncWsOpen(ws);
|
|
6095
|
+
if (_this.urlOptions.connectionParams)
|
|
6096
|
+
ws.send(await buildConnectionMessage(_this.urlOptions.connectionParams));
|
|
6097
|
+
});
|
|
6098
|
+
try {
|
|
6099
|
+
await _this.openPromise;
|
|
6100
|
+
} finally {
|
|
6101
|
+
_this.openPromise = null;
|
|
6102
|
+
}
|
|
6103
|
+
}
|
|
6104
|
+
async close() {
|
|
6105
|
+
var _this2 = this;
|
|
6106
|
+
try {
|
|
6107
|
+
await _this2.openPromise;
|
|
6108
|
+
} finally {
|
|
6109
|
+
var _this$ws;
|
|
6110
|
+
(_this$ws = _this2.ws) === null || _this$ws === undefined || _this$ws.close();
|
|
6111
|
+
}
|
|
6112
|
+
}
|
|
6113
|
+
};
|
|
6114
|
+
(0, import_defineProperty$1.default)(WsConnection, "connectCount", 0);
|
|
6115
|
+
var import_defineProperty3 = __toESM2(require_defineProperty(), 1);
|
|
6116
|
+
var import_objectSpread28 = __toESM2(require_objectSpread2(), 1);
|
|
6117
|
+
|
|
6118
|
+
// node_modules/@trpc/client/dist/index.mjs
|
|
6119
|
+
var import_defineProperty4 = __toESM2(require_defineProperty(), 1);
|
|
6120
|
+
var import_objectSpread2$4 = __toESM2(require_objectSpread2(), 1);
|
|
6121
|
+
var TRPCUntypedClient = class {
|
|
6122
|
+
constructor(opts) {
|
|
6123
|
+
(0, import_defineProperty4.default)(this, "links", undefined);
|
|
6124
|
+
(0, import_defineProperty4.default)(this, "runtime", undefined);
|
|
6125
|
+
(0, import_defineProperty4.default)(this, "requestId", undefined);
|
|
6126
|
+
this.requestId = 0;
|
|
6127
|
+
this.runtime = {};
|
|
6128
|
+
this.links = opts.links.map((link) => link(this.runtime));
|
|
6129
|
+
}
|
|
6130
|
+
$request(opts) {
|
|
6131
|
+
var _opts$context;
|
|
6132
|
+
const chain$ = createChain({
|
|
6133
|
+
links: this.links,
|
|
6134
|
+
op: (0, import_objectSpread2$4.default)((0, import_objectSpread2$4.default)({}, opts), {}, {
|
|
6135
|
+
context: (_opts$context = opts.context) !== null && _opts$context !== undefined ? _opts$context : {},
|
|
6136
|
+
id: ++this.requestId
|
|
6137
|
+
})
|
|
6138
|
+
});
|
|
6139
|
+
return chain$.pipe(share());
|
|
6140
|
+
}
|
|
6141
|
+
async requestAsPromise(opts) {
|
|
6142
|
+
var _this = this;
|
|
6143
|
+
try {
|
|
6144
|
+
const req$ = _this.$request(opts);
|
|
6145
|
+
const envelope = await observableToPromise(req$);
|
|
6146
|
+
const data = envelope.result.data;
|
|
6147
|
+
return data;
|
|
6148
|
+
} catch (err) {
|
|
6149
|
+
throw TRPCClientError.from(err);
|
|
6150
|
+
}
|
|
6151
|
+
}
|
|
6152
|
+
query(path, input, opts) {
|
|
6153
|
+
return this.requestAsPromise({
|
|
6154
|
+
type: "query",
|
|
6155
|
+
path,
|
|
6156
|
+
input,
|
|
6157
|
+
context: opts === null || opts === undefined ? undefined : opts.context,
|
|
6158
|
+
signal: opts === null || opts === undefined ? undefined : opts.signal
|
|
6159
|
+
});
|
|
6160
|
+
}
|
|
6161
|
+
mutation(path, input, opts) {
|
|
6162
|
+
return this.requestAsPromise({
|
|
6163
|
+
type: "mutation",
|
|
6164
|
+
path,
|
|
6165
|
+
input,
|
|
6166
|
+
context: opts === null || opts === undefined ? undefined : opts.context,
|
|
6167
|
+
signal: opts === null || opts === undefined ? undefined : opts.signal
|
|
6168
|
+
});
|
|
6169
|
+
}
|
|
6170
|
+
subscription(path, input, opts) {
|
|
6171
|
+
const observable$ = this.$request({
|
|
6172
|
+
type: "subscription",
|
|
6173
|
+
path,
|
|
6174
|
+
input,
|
|
6175
|
+
context: opts.context,
|
|
6176
|
+
signal: opts.signal
|
|
6177
|
+
});
|
|
6178
|
+
return observable$.subscribe({
|
|
6179
|
+
next(envelope) {
|
|
6180
|
+
switch (envelope.result.type) {
|
|
6181
|
+
case "state": {
|
|
6182
|
+
var _opts$onConnectionSta;
|
|
6183
|
+
(_opts$onConnectionSta = opts.onConnectionStateChange) === null || _opts$onConnectionSta === undefined || _opts$onConnectionSta.call(opts, envelope.result);
|
|
6184
|
+
break;
|
|
6185
|
+
}
|
|
6186
|
+
case "started": {
|
|
6187
|
+
var _opts$onStarted;
|
|
6188
|
+
(_opts$onStarted = opts.onStarted) === null || _opts$onStarted === undefined || _opts$onStarted.call(opts, { context: envelope.context });
|
|
6189
|
+
break;
|
|
6190
|
+
}
|
|
6191
|
+
case "stopped": {
|
|
6192
|
+
var _opts$onStopped;
|
|
6193
|
+
(_opts$onStopped = opts.onStopped) === null || _opts$onStopped === undefined || _opts$onStopped.call(opts);
|
|
6194
|
+
break;
|
|
6195
|
+
}
|
|
6196
|
+
case "data":
|
|
6197
|
+
case undefined: {
|
|
6198
|
+
var _opts$onData;
|
|
6199
|
+
(_opts$onData = opts.onData) === null || _opts$onData === undefined || _opts$onData.call(opts, envelope.result.data);
|
|
6200
|
+
break;
|
|
6201
|
+
}
|
|
6202
|
+
}
|
|
6203
|
+
},
|
|
6204
|
+
error(err) {
|
|
6205
|
+
var _opts$onError;
|
|
6206
|
+
(_opts$onError = opts.onError) === null || _opts$onError === undefined || _opts$onError.call(opts, err);
|
|
6207
|
+
},
|
|
6208
|
+
complete() {
|
|
6209
|
+
var _opts$onComplete;
|
|
6210
|
+
(_opts$onComplete = opts.onComplete) === null || _opts$onComplete === undefined || _opts$onComplete.call(opts);
|
|
6211
|
+
}
|
|
6212
|
+
});
|
|
6213
|
+
}
|
|
6214
|
+
};
|
|
6215
|
+
var untypedClientSymbol = Symbol.for("trpc_untypedClient");
|
|
6216
|
+
var clientCallTypeMap = {
|
|
6217
|
+
query: "query",
|
|
6218
|
+
mutate: "mutation",
|
|
6219
|
+
subscribe: "subscription"
|
|
6220
|
+
};
|
|
6221
|
+
var clientCallTypeToProcedureType = (clientCallType) => {
|
|
6222
|
+
return clientCallTypeMap[clientCallType];
|
|
6223
|
+
};
|
|
6224
|
+
function createTRPCClientProxy(client) {
|
|
6225
|
+
const proxy = createRecursiveProxy(({ path, args }) => {
|
|
6226
|
+
const pathCopy = [...path];
|
|
6227
|
+
const procedureType = clientCallTypeToProcedureType(pathCopy.pop());
|
|
6228
|
+
const fullPath = pathCopy.join(".");
|
|
6229
|
+
return client[procedureType](fullPath, ...args);
|
|
6230
|
+
});
|
|
6231
|
+
return createFlatProxy((key) => {
|
|
6232
|
+
if (key === untypedClientSymbol)
|
|
6233
|
+
return client;
|
|
6234
|
+
return proxy[key];
|
|
6235
|
+
});
|
|
6236
|
+
}
|
|
6237
|
+
function createTRPCClient(opts) {
|
|
6238
|
+
const client = new TRPCUntypedClient(opts);
|
|
6239
|
+
const proxy = createTRPCClientProxy(client);
|
|
6240
|
+
return proxy;
|
|
6241
|
+
}
|
|
6242
|
+
var import_objectSpread2$3 = __toESM2(require_objectSpread2(), 1);
|
|
6243
|
+
var import_objectSpread2$2 = __toESM2(require_objectSpread2(), 1);
|
|
6244
|
+
var require_asyncIterator = __commonJS2({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/asyncIterator.js"(exports, module) {
|
|
6245
|
+
function _asyncIterator$1(r) {
|
|
6246
|
+
var n, t, o, e = 2;
|
|
6247
|
+
for (typeof Symbol != "undefined" && (t = Symbol.asyncIterator, o = Symbol.iterator);e--; ) {
|
|
6248
|
+
if (t && (n = r[t]) != null)
|
|
6249
|
+
return n.call(r);
|
|
6250
|
+
if (o && (n = r[o]) != null)
|
|
6251
|
+
return new AsyncFromSyncIterator(n.call(r));
|
|
6252
|
+
t = "@@asyncIterator", o = "@@iterator";
|
|
6253
|
+
}
|
|
6254
|
+
throw new TypeError("Object is not async iterable");
|
|
6255
|
+
}
|
|
6256
|
+
function AsyncFromSyncIterator(r) {
|
|
6257
|
+
function AsyncFromSyncIteratorContinuation(r$1) {
|
|
6258
|
+
if (Object(r$1) !== r$1)
|
|
6259
|
+
return Promise.reject(new TypeError(r$1 + " is not an object."));
|
|
6260
|
+
var n = r$1.done;
|
|
6261
|
+
return Promise.resolve(r$1.value).then(function(r$2) {
|
|
6262
|
+
return {
|
|
6263
|
+
value: r$2,
|
|
6264
|
+
done: n
|
|
6265
|
+
};
|
|
6266
|
+
});
|
|
6267
|
+
}
|
|
6268
|
+
return AsyncFromSyncIterator = function AsyncFromSyncIterator$1(r$1) {
|
|
6269
|
+
this.s = r$1, this.n = r$1.next;
|
|
6270
|
+
}, AsyncFromSyncIterator.prototype = {
|
|
6271
|
+
s: null,
|
|
6272
|
+
n: null,
|
|
6273
|
+
next: function next() {
|
|
6274
|
+
return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments));
|
|
6275
|
+
},
|
|
6276
|
+
return: function _return(r$1) {
|
|
6277
|
+
var n = this.s["return"];
|
|
6278
|
+
return n === undefined ? Promise.resolve({
|
|
6279
|
+
value: r$1,
|
|
6280
|
+
done: true
|
|
6281
|
+
}) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments));
|
|
6282
|
+
},
|
|
6283
|
+
throw: function _throw(r$1) {
|
|
6284
|
+
var n = this.s["return"];
|
|
6285
|
+
return n === undefined ? Promise.reject(r$1) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments));
|
|
6286
|
+
}
|
|
6287
|
+
}, new AsyncFromSyncIterator(r);
|
|
6288
|
+
}
|
|
6289
|
+
module.exports = _asyncIterator$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
6290
|
+
} });
|
|
6291
|
+
var import_asyncIterator = __toESM2(require_asyncIterator(), 1);
|
|
6292
|
+
var import_objectSpread2$12 = __toESM2(require_objectSpread2(), 1);
|
|
6293
|
+
var require_usingCtx = __commonJS2({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/usingCtx.js"(exports, module) {
|
|
6294
|
+
function _usingCtx() {
|
|
6295
|
+
var r = typeof SuppressedError == "function" ? SuppressedError : function(r$1, e$1) {
|
|
6296
|
+
var n$1 = Error();
|
|
6297
|
+
return n$1.name = "SuppressedError", n$1.error = r$1, n$1.suppressed = e$1, n$1;
|
|
6298
|
+
}, e = {}, n = [];
|
|
6299
|
+
function using(r$1, e$1) {
|
|
6300
|
+
if (e$1 != null) {
|
|
6301
|
+
if (Object(e$1) !== e$1)
|
|
6302
|
+
throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
|
|
6303
|
+
if (r$1)
|
|
6304
|
+
var o = e$1[Symbol.asyncDispose || Symbol["for"]("Symbol.asyncDispose")];
|
|
6305
|
+
if (o === undefined && (o = e$1[Symbol.dispose || Symbol["for"]("Symbol.dispose")], r$1))
|
|
6306
|
+
var t = o;
|
|
6307
|
+
if (typeof o != "function")
|
|
6308
|
+
throw new TypeError("Object is not disposable.");
|
|
6309
|
+
t && (o = function o$1() {
|
|
6310
|
+
try {
|
|
6311
|
+
t.call(e$1);
|
|
6312
|
+
} catch (r$2) {
|
|
6313
|
+
return Promise.reject(r$2);
|
|
6314
|
+
}
|
|
6315
|
+
}), n.push({
|
|
6316
|
+
v: e$1,
|
|
6317
|
+
d: o,
|
|
6318
|
+
a: r$1
|
|
6319
|
+
});
|
|
6320
|
+
} else
|
|
6321
|
+
r$1 && n.push({
|
|
6322
|
+
d: e$1,
|
|
6323
|
+
a: r$1
|
|
6324
|
+
});
|
|
6325
|
+
return e$1;
|
|
6326
|
+
}
|
|
6327
|
+
return {
|
|
6328
|
+
e,
|
|
6329
|
+
u: using.bind(null, false),
|
|
6330
|
+
a: using.bind(null, true),
|
|
6331
|
+
d: function d() {
|
|
6332
|
+
var o, t = this.e, s = 0;
|
|
6333
|
+
function next() {
|
|
6334
|
+
for (;o = n.pop(); )
|
|
6335
|
+
try {
|
|
6336
|
+
if (!o.a && s === 1)
|
|
6337
|
+
return s = 0, n.push(o), Promise.resolve().then(next);
|
|
6338
|
+
if (o.d) {
|
|
6339
|
+
var r$1 = o.d.call(o.v);
|
|
6340
|
+
if (o.a)
|
|
6341
|
+
return s |= 2, Promise.resolve(r$1).then(next, err);
|
|
6342
|
+
} else
|
|
6343
|
+
s |= 1;
|
|
6344
|
+
} catch (r$2) {
|
|
6345
|
+
return err(r$2);
|
|
6346
|
+
}
|
|
6347
|
+
if (s === 1)
|
|
6348
|
+
return t !== e ? Promise.reject(t) : Promise.resolve();
|
|
6349
|
+
if (t !== e)
|
|
6350
|
+
throw t;
|
|
6351
|
+
}
|
|
6352
|
+
function err(n$1) {
|
|
6353
|
+
return t = t !== e ? new r(n$1, t) : n$1, next();
|
|
6354
|
+
}
|
|
6355
|
+
return next();
|
|
6356
|
+
}
|
|
6357
|
+
};
|
|
6358
|
+
}
|
|
6359
|
+
module.exports = _usingCtx, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
6360
|
+
} });
|
|
6361
|
+
var require_OverloadYield = __commonJS2({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/OverloadYield.js"(exports, module) {
|
|
6362
|
+
function _OverloadYield(e, d) {
|
|
6363
|
+
this.v = e, this.k = d;
|
|
6364
|
+
}
|
|
6365
|
+
module.exports = _OverloadYield, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
6366
|
+
} });
|
|
6367
|
+
var require_awaitAsyncGenerator = __commonJS2({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/awaitAsyncGenerator.js"(exports, module) {
|
|
6368
|
+
var OverloadYield$1 = require_OverloadYield();
|
|
6369
|
+
function _awaitAsyncGenerator$1(e) {
|
|
6370
|
+
return new OverloadYield$1(e, 0);
|
|
6371
|
+
}
|
|
6372
|
+
module.exports = _awaitAsyncGenerator$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
6373
|
+
} });
|
|
6374
|
+
var require_wrapAsyncGenerator = __commonJS2({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/wrapAsyncGenerator.js"(exports, module) {
|
|
6375
|
+
var OverloadYield = require_OverloadYield();
|
|
6376
|
+
function _wrapAsyncGenerator$1(e) {
|
|
6377
|
+
return function() {
|
|
6378
|
+
return new AsyncGenerator(e.apply(this, arguments));
|
|
6379
|
+
};
|
|
6380
|
+
}
|
|
6381
|
+
function AsyncGenerator(e) {
|
|
6382
|
+
var r, t;
|
|
6383
|
+
function resume(r$1, t$1) {
|
|
6384
|
+
try {
|
|
6385
|
+
var n = e[r$1](t$1), o = n.value, u = o instanceof OverloadYield;
|
|
6386
|
+
Promise.resolve(u ? o.v : o).then(function(t$2) {
|
|
6387
|
+
if (u) {
|
|
6388
|
+
var i = r$1 === "return" ? "return" : "next";
|
|
6389
|
+
if (!o.k || t$2.done)
|
|
6390
|
+
return resume(i, t$2);
|
|
6391
|
+
t$2 = e[i](t$2).value;
|
|
6392
|
+
}
|
|
6393
|
+
settle(n.done ? "return" : "normal", t$2);
|
|
6394
|
+
}, function(e$1) {
|
|
6395
|
+
resume("throw", e$1);
|
|
6396
|
+
});
|
|
6397
|
+
} catch (e$1) {
|
|
6398
|
+
settle("throw", e$1);
|
|
6399
|
+
}
|
|
6400
|
+
}
|
|
6401
|
+
function settle(e$1, n) {
|
|
6402
|
+
switch (e$1) {
|
|
6403
|
+
case "return":
|
|
6404
|
+
r.resolve({
|
|
6405
|
+
value: n,
|
|
6406
|
+
done: true
|
|
6407
|
+
});
|
|
6408
|
+
break;
|
|
6409
|
+
case "throw":
|
|
6410
|
+
r.reject(n);
|
|
6411
|
+
break;
|
|
6412
|
+
default:
|
|
6413
|
+
r.resolve({
|
|
6414
|
+
value: n,
|
|
6415
|
+
done: false
|
|
6416
|
+
});
|
|
6417
|
+
}
|
|
6418
|
+
(r = r.next) ? resume(r.key, r.arg) : t = null;
|
|
6419
|
+
}
|
|
6420
|
+
this._invoke = function(e$1, n) {
|
|
6421
|
+
return new Promise(function(o, u) {
|
|
6422
|
+
var i = {
|
|
6423
|
+
key: e$1,
|
|
6424
|
+
arg: n,
|
|
6425
|
+
resolve: o,
|
|
6426
|
+
reject: u,
|
|
6427
|
+
next: null
|
|
6428
|
+
};
|
|
6429
|
+
t ? t = t.next = i : (r = t = i, resume(e$1, n));
|
|
6430
|
+
});
|
|
6431
|
+
}, typeof e["return"] != "function" && (this["return"] = undefined);
|
|
6432
|
+
}
|
|
6433
|
+
AsyncGenerator.prototype[typeof Symbol == "function" && Symbol.asyncIterator || "@@asyncIterator"] = function() {
|
|
6434
|
+
return this;
|
|
6435
|
+
}, AsyncGenerator.prototype.next = function(e) {
|
|
6436
|
+
return this._invoke("next", e);
|
|
6437
|
+
}, AsyncGenerator.prototype["throw"] = function(e) {
|
|
6438
|
+
return this._invoke("throw", e);
|
|
6439
|
+
}, AsyncGenerator.prototype["return"] = function(e) {
|
|
6440
|
+
return this._invoke("return", e);
|
|
6441
|
+
};
|
|
6442
|
+
module.exports = _wrapAsyncGenerator$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
6443
|
+
} });
|
|
6444
|
+
var import_usingCtx = __toESM2(require_usingCtx(), 1);
|
|
6445
|
+
var import_awaitAsyncGenerator = __toESM2(require_awaitAsyncGenerator(), 1);
|
|
6446
|
+
var import_wrapAsyncGenerator = __toESM2(require_wrapAsyncGenerator(), 1);
|
|
6447
|
+
var import_objectSpread29 = __toESM2(require_objectSpread2(), 1);
|
|
6448
|
+
|
|
6449
|
+
// node_modules/superjson/dist/double-indexed-kv.js
|
|
6450
|
+
class DoubleIndexedKV {
|
|
6451
|
+
constructor() {
|
|
6452
|
+
this.keyToValue = new Map;
|
|
6453
|
+
this.valueToKey = new Map;
|
|
6454
|
+
}
|
|
6455
|
+
set(key, value) {
|
|
6456
|
+
this.keyToValue.set(key, value);
|
|
6457
|
+
this.valueToKey.set(value, key);
|
|
6458
|
+
}
|
|
6459
|
+
getByKey(key) {
|
|
6460
|
+
return this.keyToValue.get(key);
|
|
6461
|
+
}
|
|
6462
|
+
getByValue(value) {
|
|
6463
|
+
return this.valueToKey.get(value);
|
|
6464
|
+
}
|
|
6465
|
+
clear() {
|
|
6466
|
+
this.keyToValue.clear();
|
|
6467
|
+
this.valueToKey.clear();
|
|
6468
|
+
}
|
|
6469
|
+
}
|
|
6470
|
+
|
|
6471
|
+
// node_modules/superjson/dist/registry.js
|
|
6472
|
+
class Registry {
|
|
6473
|
+
constructor(generateIdentifier) {
|
|
6474
|
+
this.generateIdentifier = generateIdentifier;
|
|
6475
|
+
this.kv = new DoubleIndexedKV;
|
|
6476
|
+
}
|
|
6477
|
+
register(value, identifier) {
|
|
6478
|
+
if (this.kv.getByValue(value)) {
|
|
6479
|
+
return;
|
|
6480
|
+
}
|
|
6481
|
+
if (!identifier) {
|
|
6482
|
+
identifier = this.generateIdentifier(value);
|
|
6483
|
+
}
|
|
6484
|
+
this.kv.set(identifier, value);
|
|
6485
|
+
}
|
|
6486
|
+
clear() {
|
|
6487
|
+
this.kv.clear();
|
|
6488
|
+
}
|
|
6489
|
+
getIdentifier(value) {
|
|
6490
|
+
return this.kv.getByValue(value);
|
|
6491
|
+
}
|
|
6492
|
+
getValue(identifier) {
|
|
6493
|
+
return this.kv.getByKey(identifier);
|
|
6494
|
+
}
|
|
6495
|
+
}
|
|
6496
|
+
|
|
6497
|
+
// node_modules/superjson/dist/class-registry.js
|
|
6498
|
+
class ClassRegistry extends Registry {
|
|
6499
|
+
constructor() {
|
|
6500
|
+
super((c) => c.name);
|
|
6501
|
+
this.classToAllowedProps = new Map;
|
|
6502
|
+
}
|
|
6503
|
+
register(value, options) {
|
|
6504
|
+
if (typeof options === "object") {
|
|
6505
|
+
if (options.allowProps) {
|
|
6506
|
+
this.classToAllowedProps.set(value, options.allowProps);
|
|
6507
|
+
}
|
|
6508
|
+
super.register(value, options.identifier);
|
|
6509
|
+
} else {
|
|
6510
|
+
super.register(value, options);
|
|
6511
|
+
}
|
|
6512
|
+
}
|
|
6513
|
+
getAllowedProps(value) {
|
|
6514
|
+
return this.classToAllowedProps.get(value);
|
|
6515
|
+
}
|
|
6516
|
+
}
|
|
6517
|
+
|
|
6518
|
+
// node_modules/superjson/dist/util.js
|
|
6519
|
+
function valuesOfObj(record) {
|
|
6520
|
+
if ("values" in Object) {
|
|
6521
|
+
return Object.values(record);
|
|
6522
|
+
}
|
|
6523
|
+
const values = [];
|
|
6524
|
+
for (const key in record) {
|
|
6525
|
+
if (record.hasOwnProperty(key)) {
|
|
6526
|
+
values.push(record[key]);
|
|
6527
|
+
}
|
|
6528
|
+
}
|
|
6529
|
+
return values;
|
|
6530
|
+
}
|
|
6531
|
+
function find(record, predicate) {
|
|
6532
|
+
const values = valuesOfObj(record);
|
|
6533
|
+
if ("find" in values) {
|
|
6534
|
+
return values.find(predicate);
|
|
6535
|
+
}
|
|
6536
|
+
const valuesNotNever = values;
|
|
6537
|
+
for (let i = 0;i < valuesNotNever.length; i++) {
|
|
6538
|
+
const value = valuesNotNever[i];
|
|
6539
|
+
if (predicate(value)) {
|
|
6540
|
+
return value;
|
|
6541
|
+
}
|
|
6542
|
+
}
|
|
6543
|
+
return;
|
|
6544
|
+
}
|
|
6545
|
+
function forEach(record, run2) {
|
|
6546
|
+
Object.entries(record).forEach(([key, value]) => run2(value, key));
|
|
6547
|
+
}
|
|
6548
|
+
function includes(arr, value) {
|
|
6549
|
+
return arr.indexOf(value) !== -1;
|
|
6550
|
+
}
|
|
6551
|
+
function findArr(record, predicate) {
|
|
6552
|
+
for (let i = 0;i < record.length; i++) {
|
|
6553
|
+
const value = record[i];
|
|
6554
|
+
if (predicate(value)) {
|
|
6555
|
+
return value;
|
|
6556
|
+
}
|
|
6557
|
+
}
|
|
6558
|
+
return;
|
|
6559
|
+
}
|
|
6560
|
+
|
|
6561
|
+
// node_modules/superjson/dist/custom-transformer-registry.js
|
|
6562
|
+
class CustomTransformerRegistry {
|
|
6563
|
+
constructor() {
|
|
6564
|
+
this.transfomers = {};
|
|
6565
|
+
}
|
|
6566
|
+
register(transformer) {
|
|
6567
|
+
this.transfomers[transformer.name] = transformer;
|
|
6568
|
+
}
|
|
6569
|
+
findApplicable(v) {
|
|
6570
|
+
return find(this.transfomers, (transformer) => transformer.isApplicable(v));
|
|
6571
|
+
}
|
|
6572
|
+
findByName(name) {
|
|
6573
|
+
return this.transfomers[name];
|
|
6574
|
+
}
|
|
6575
|
+
}
|
|
6576
|
+
|
|
6577
|
+
// node_modules/superjson/dist/is.js
|
|
6578
|
+
var getType = (payload) => Object.prototype.toString.call(payload).slice(8, -1);
|
|
6579
|
+
var isUndefined = (payload) => typeof payload === "undefined";
|
|
6580
|
+
var isNull = (payload) => payload === null;
|
|
6581
|
+
var isPlainObject = (payload) => {
|
|
6582
|
+
if (typeof payload !== "object" || payload === null)
|
|
6583
|
+
return false;
|
|
6584
|
+
if (payload === Object.prototype)
|
|
6585
|
+
return false;
|
|
6586
|
+
if (Object.getPrototypeOf(payload) === null)
|
|
6587
|
+
return true;
|
|
6588
|
+
return Object.getPrototypeOf(payload) === Object.prototype;
|
|
6589
|
+
};
|
|
6590
|
+
var isEmptyObject = (payload) => isPlainObject(payload) && Object.keys(payload).length === 0;
|
|
6591
|
+
var isArray = (payload) => Array.isArray(payload);
|
|
6592
|
+
var isString = (payload) => typeof payload === "string";
|
|
6593
|
+
var isNumber = (payload) => typeof payload === "number" && !isNaN(payload);
|
|
6594
|
+
var isBoolean = (payload) => typeof payload === "boolean";
|
|
6595
|
+
var isRegExp = (payload) => payload instanceof RegExp;
|
|
6596
|
+
var isMap = (payload) => payload instanceof Map;
|
|
6597
|
+
var isSet = (payload) => payload instanceof Set;
|
|
6598
|
+
var isSymbol = (payload) => getType(payload) === "Symbol";
|
|
6599
|
+
var isDate = (payload) => payload instanceof Date && !isNaN(payload.valueOf());
|
|
6600
|
+
var isError = (payload) => payload instanceof Error;
|
|
6601
|
+
var isNaNValue = (payload) => typeof payload === "number" && isNaN(payload);
|
|
6602
|
+
var isPrimitive = (payload) => isBoolean(payload) || isNull(payload) || isUndefined(payload) || isNumber(payload) || isString(payload) || isSymbol(payload);
|
|
6603
|
+
var isBigint = (payload) => typeof payload === "bigint";
|
|
6604
|
+
var isInfinite = (payload) => payload === Infinity || payload === -Infinity;
|
|
6605
|
+
var isTypedArray = (payload) => ArrayBuffer.isView(payload) && !(payload instanceof DataView);
|
|
6606
|
+
var isURL = (payload) => payload instanceof URL;
|
|
6607
|
+
|
|
6608
|
+
// node_modules/superjson/dist/pathstringifier.js
|
|
6609
|
+
var escapeKey = (key) => key.replace(/\\/g, "\\\\").replace(/\./g, "\\.");
|
|
6610
|
+
var stringifyPath = (path) => path.map(String).map(escapeKey).join(".");
|
|
6611
|
+
var parsePath = (string, legacyPaths) => {
|
|
6612
|
+
const result = [];
|
|
6613
|
+
let segment = "";
|
|
6614
|
+
for (let i = 0;i < string.length; i++) {
|
|
6615
|
+
let char = string.charAt(i);
|
|
6616
|
+
if (!legacyPaths && char === "\\") {
|
|
6617
|
+
const escaped = string.charAt(i + 1);
|
|
6618
|
+
if (escaped === "\\") {
|
|
6619
|
+
segment += "\\";
|
|
6620
|
+
i++;
|
|
6621
|
+
continue;
|
|
6622
|
+
} else if (escaped !== ".") {
|
|
6623
|
+
throw Error("invalid path");
|
|
6624
|
+
}
|
|
6625
|
+
}
|
|
6626
|
+
const isEscapedDot = char === "\\" && string.charAt(i + 1) === ".";
|
|
6627
|
+
if (isEscapedDot) {
|
|
6628
|
+
segment += ".";
|
|
6629
|
+
i++;
|
|
6630
|
+
continue;
|
|
6631
|
+
}
|
|
6632
|
+
const isEndOfSegment = char === ".";
|
|
6633
|
+
if (isEndOfSegment) {
|
|
6634
|
+
result.push(segment);
|
|
6635
|
+
segment = "";
|
|
6636
|
+
continue;
|
|
6637
|
+
}
|
|
6638
|
+
segment += char;
|
|
6639
|
+
}
|
|
6640
|
+
const lastSegment = segment;
|
|
6641
|
+
result.push(lastSegment);
|
|
6642
|
+
return result;
|
|
6643
|
+
};
|
|
6644
|
+
|
|
6645
|
+
// node_modules/superjson/dist/transformer.js
|
|
6646
|
+
function simpleTransformation(isApplicable, annotation, transform, untransform) {
|
|
6647
|
+
return {
|
|
6648
|
+
isApplicable,
|
|
6649
|
+
annotation,
|
|
6650
|
+
transform,
|
|
6651
|
+
untransform
|
|
6652
|
+
};
|
|
6653
|
+
}
|
|
6654
|
+
var simpleRules = [
|
|
6655
|
+
simpleTransformation(isUndefined, "undefined", () => null, () => {
|
|
6656
|
+
return;
|
|
6657
|
+
}),
|
|
6658
|
+
simpleTransformation(isBigint, "bigint", (v) => v.toString(), (v) => {
|
|
6659
|
+
if (typeof BigInt !== "undefined") {
|
|
6660
|
+
return BigInt(v);
|
|
6661
|
+
}
|
|
6662
|
+
console.error("Please add a BigInt polyfill.");
|
|
6663
|
+
return v;
|
|
6664
|
+
}),
|
|
6665
|
+
simpleTransformation(isDate, "Date", (v) => v.toISOString(), (v) => new Date(v)),
|
|
6666
|
+
simpleTransformation(isError, "Error", (v, superJson) => {
|
|
6667
|
+
const baseError = {
|
|
6668
|
+
name: v.name,
|
|
6669
|
+
message: v.message
|
|
6670
|
+
};
|
|
6671
|
+
if ("cause" in v) {
|
|
6672
|
+
baseError.cause = v.cause;
|
|
6673
|
+
}
|
|
6674
|
+
superJson.allowedErrorProps.forEach((prop) => {
|
|
6675
|
+
baseError[prop] = v[prop];
|
|
6676
|
+
});
|
|
6677
|
+
return baseError;
|
|
6678
|
+
}, (v, superJson) => {
|
|
6679
|
+
const e = new Error(v.message, { cause: v.cause });
|
|
6680
|
+
e.name = v.name;
|
|
6681
|
+
e.stack = v.stack;
|
|
6682
|
+
superJson.allowedErrorProps.forEach((prop) => {
|
|
6683
|
+
e[prop] = v[prop];
|
|
6684
|
+
});
|
|
6685
|
+
return e;
|
|
6686
|
+
}),
|
|
6687
|
+
simpleTransformation(isRegExp, "regexp", (v) => "" + v, (regex) => {
|
|
6688
|
+
const body = regex.slice(1, regex.lastIndexOf("/"));
|
|
6689
|
+
const flags = regex.slice(regex.lastIndexOf("/") + 1);
|
|
6690
|
+
return new RegExp(body, flags);
|
|
6691
|
+
}),
|
|
6692
|
+
simpleTransformation(isSet, "set", (v) => [...v.values()], (v) => new Set(v)),
|
|
6693
|
+
simpleTransformation(isMap, "map", (v) => [...v.entries()], (v) => new Map(v)),
|
|
6694
|
+
simpleTransformation((v) => isNaNValue(v) || isInfinite(v), "number", (v) => {
|
|
6695
|
+
if (isNaNValue(v)) {
|
|
6696
|
+
return "NaN";
|
|
6697
|
+
}
|
|
6698
|
+
if (v > 0) {
|
|
6699
|
+
return "Infinity";
|
|
6700
|
+
} else {
|
|
6701
|
+
return "-Infinity";
|
|
6702
|
+
}
|
|
6703
|
+
}, Number),
|
|
6704
|
+
simpleTransformation((v) => v === 0 && 1 / v === -Infinity, "number", () => {
|
|
6705
|
+
return "-0";
|
|
6706
|
+
}, Number),
|
|
6707
|
+
simpleTransformation(isURL, "URL", (v) => v.toString(), (v) => new URL(v))
|
|
6708
|
+
];
|
|
6709
|
+
function compositeTransformation(isApplicable, annotation, transform, untransform) {
|
|
6710
|
+
return {
|
|
6711
|
+
isApplicable,
|
|
6712
|
+
annotation,
|
|
6713
|
+
transform,
|
|
6714
|
+
untransform
|
|
6715
|
+
};
|
|
6716
|
+
}
|
|
6717
|
+
var symbolRule = compositeTransformation((s, superJson) => {
|
|
6718
|
+
if (isSymbol(s)) {
|
|
6719
|
+
const isRegistered = !!superJson.symbolRegistry.getIdentifier(s);
|
|
6720
|
+
return isRegistered;
|
|
6721
|
+
}
|
|
6722
|
+
return false;
|
|
6723
|
+
}, (s, superJson) => {
|
|
6724
|
+
const identifier = superJson.symbolRegistry.getIdentifier(s);
|
|
6725
|
+
return ["symbol", identifier];
|
|
6726
|
+
}, (v) => v.description, (_, a, superJson) => {
|
|
6727
|
+
const value = superJson.symbolRegistry.getValue(a[1]);
|
|
6728
|
+
if (!value) {
|
|
6729
|
+
throw new Error("Trying to deserialize unknown symbol");
|
|
6730
|
+
}
|
|
6731
|
+
return value;
|
|
6732
|
+
});
|
|
6733
|
+
var constructorToName = [
|
|
6734
|
+
Int8Array,
|
|
6735
|
+
Uint8Array,
|
|
6736
|
+
Int16Array,
|
|
6737
|
+
Uint16Array,
|
|
6738
|
+
Int32Array,
|
|
6739
|
+
Uint32Array,
|
|
6740
|
+
Float32Array,
|
|
6741
|
+
Float64Array,
|
|
6742
|
+
Uint8ClampedArray
|
|
6743
|
+
].reduce((obj, ctor) => {
|
|
6744
|
+
obj[ctor.name] = ctor;
|
|
6745
|
+
return obj;
|
|
6746
|
+
}, {});
|
|
6747
|
+
var typedArrayRule = compositeTransformation(isTypedArray, (v) => ["typed-array", v.constructor.name], (v) => [...v], (v, a) => {
|
|
6748
|
+
const ctor = constructorToName[a[1]];
|
|
6749
|
+
if (!ctor) {
|
|
6750
|
+
throw new Error("Trying to deserialize unknown typed array");
|
|
6751
|
+
}
|
|
6752
|
+
return new ctor(v);
|
|
6753
|
+
});
|
|
6754
|
+
function isInstanceOfRegisteredClass(potentialClass, superJson) {
|
|
6755
|
+
if (potentialClass?.constructor) {
|
|
6756
|
+
const isRegistered = !!superJson.classRegistry.getIdentifier(potentialClass.constructor);
|
|
6757
|
+
return isRegistered;
|
|
6758
|
+
}
|
|
6759
|
+
return false;
|
|
6760
|
+
}
|
|
6761
|
+
var classRule = compositeTransformation(isInstanceOfRegisteredClass, (clazz, superJson) => {
|
|
6762
|
+
const identifier = superJson.classRegistry.getIdentifier(clazz.constructor);
|
|
6763
|
+
return ["class", identifier];
|
|
6764
|
+
}, (clazz, superJson) => {
|
|
6765
|
+
const allowedProps = superJson.classRegistry.getAllowedProps(clazz.constructor);
|
|
6766
|
+
if (!allowedProps) {
|
|
6767
|
+
return { ...clazz };
|
|
6768
|
+
}
|
|
6769
|
+
const result = {};
|
|
6770
|
+
allowedProps.forEach((prop) => {
|
|
6771
|
+
result[prop] = clazz[prop];
|
|
6772
|
+
});
|
|
6773
|
+
return result;
|
|
6774
|
+
}, (v, a, superJson) => {
|
|
6775
|
+
const clazz = superJson.classRegistry.getValue(a[1]);
|
|
6776
|
+
if (!clazz) {
|
|
6777
|
+
throw new Error(`Trying to deserialize unknown class '${a[1]}' - check https://github.com/blitz-js/superjson/issues/116#issuecomment-773996564`);
|
|
6778
|
+
}
|
|
6779
|
+
return Object.assign(Object.create(clazz.prototype), v);
|
|
6780
|
+
});
|
|
6781
|
+
var customRule = compositeTransformation((value, superJson) => {
|
|
6782
|
+
return !!superJson.customTransformerRegistry.findApplicable(value);
|
|
6783
|
+
}, (value, superJson) => {
|
|
6784
|
+
const transformer = superJson.customTransformerRegistry.findApplicable(value);
|
|
6785
|
+
return ["custom", transformer.name];
|
|
6786
|
+
}, (value, superJson) => {
|
|
6787
|
+
const transformer = superJson.customTransformerRegistry.findApplicable(value);
|
|
6788
|
+
return transformer.serialize(value);
|
|
6789
|
+
}, (v, a, superJson) => {
|
|
6790
|
+
const transformer = superJson.customTransformerRegistry.findByName(a[1]);
|
|
6791
|
+
if (!transformer) {
|
|
6792
|
+
throw new Error("Trying to deserialize unknown custom value");
|
|
6793
|
+
}
|
|
6794
|
+
return transformer.deserialize(v);
|
|
6795
|
+
});
|
|
6796
|
+
var compositeRules = [classRule, symbolRule, customRule, typedArrayRule];
|
|
6797
|
+
var transformValue = (value, superJson) => {
|
|
6798
|
+
const applicableCompositeRule = findArr(compositeRules, (rule) => rule.isApplicable(value, superJson));
|
|
6799
|
+
if (applicableCompositeRule) {
|
|
6800
|
+
return {
|
|
6801
|
+
value: applicableCompositeRule.transform(value, superJson),
|
|
6802
|
+
type: applicableCompositeRule.annotation(value, superJson)
|
|
6803
|
+
};
|
|
6804
|
+
}
|
|
6805
|
+
const applicableSimpleRule = findArr(simpleRules, (rule) => rule.isApplicable(value, superJson));
|
|
6806
|
+
if (applicableSimpleRule) {
|
|
6807
|
+
return {
|
|
6808
|
+
value: applicableSimpleRule.transform(value, superJson),
|
|
6809
|
+
type: applicableSimpleRule.annotation
|
|
6810
|
+
};
|
|
6811
|
+
}
|
|
6812
|
+
return;
|
|
6813
|
+
};
|
|
6814
|
+
var simpleRulesByAnnotation = {};
|
|
6815
|
+
simpleRules.forEach((rule) => {
|
|
6816
|
+
simpleRulesByAnnotation[rule.annotation] = rule;
|
|
6817
|
+
});
|
|
6818
|
+
var untransformValue = (json, type, superJson) => {
|
|
6819
|
+
if (isArray(type)) {
|
|
6820
|
+
switch (type[0]) {
|
|
6821
|
+
case "symbol":
|
|
6822
|
+
return symbolRule.untransform(json, type, superJson);
|
|
6823
|
+
case "class":
|
|
6824
|
+
return classRule.untransform(json, type, superJson);
|
|
6825
|
+
case "custom":
|
|
6826
|
+
return customRule.untransform(json, type, superJson);
|
|
6827
|
+
case "typed-array":
|
|
6828
|
+
return typedArrayRule.untransform(json, type, superJson);
|
|
6829
|
+
default:
|
|
6830
|
+
throw new Error("Unknown transformation: " + type);
|
|
6831
|
+
}
|
|
6832
|
+
} else {
|
|
6833
|
+
const transformation = simpleRulesByAnnotation[type];
|
|
6834
|
+
if (!transformation) {
|
|
6835
|
+
throw new Error("Unknown transformation: " + type);
|
|
6836
|
+
}
|
|
6837
|
+
return transformation.untransform(json, superJson);
|
|
6838
|
+
}
|
|
6839
|
+
};
|
|
6840
|
+
|
|
6841
|
+
// node_modules/superjson/dist/accessDeep.js
|
|
6842
|
+
var getNthKey = (value, n) => {
|
|
6843
|
+
if (n > value.size)
|
|
6844
|
+
throw new Error("index out of bounds");
|
|
6845
|
+
const keys = value.keys();
|
|
6846
|
+
while (n > 0) {
|
|
6847
|
+
keys.next();
|
|
6848
|
+
n--;
|
|
6849
|
+
}
|
|
6850
|
+
return keys.next().value;
|
|
6851
|
+
};
|
|
6852
|
+
function validatePath(path) {
|
|
6853
|
+
if (includes(path, "__proto__")) {
|
|
6854
|
+
throw new Error("__proto__ is not allowed as a property");
|
|
6855
|
+
}
|
|
6856
|
+
if (includes(path, "prototype")) {
|
|
6857
|
+
throw new Error("prototype is not allowed as a property");
|
|
6858
|
+
}
|
|
6859
|
+
if (includes(path, "constructor")) {
|
|
6860
|
+
throw new Error("constructor is not allowed as a property");
|
|
6861
|
+
}
|
|
6862
|
+
}
|
|
6863
|
+
var getDeep = (object, path) => {
|
|
6864
|
+
validatePath(path);
|
|
6865
|
+
for (let i = 0;i < path.length; i++) {
|
|
6866
|
+
const key = path[i];
|
|
6867
|
+
if (isSet(object)) {
|
|
6868
|
+
object = getNthKey(object, +key);
|
|
6869
|
+
} else if (isMap(object)) {
|
|
6870
|
+
const row = +key;
|
|
6871
|
+
const type = +path[++i] === 0 ? "key" : "value";
|
|
6872
|
+
const keyOfRow = getNthKey(object, row);
|
|
6873
|
+
switch (type) {
|
|
6874
|
+
case "key":
|
|
6875
|
+
object = keyOfRow;
|
|
6876
|
+
break;
|
|
6877
|
+
case "value":
|
|
6878
|
+
object = object.get(keyOfRow);
|
|
6879
|
+
break;
|
|
6880
|
+
}
|
|
6881
|
+
} else {
|
|
6882
|
+
object = object[key];
|
|
6883
|
+
}
|
|
6884
|
+
}
|
|
6885
|
+
return object;
|
|
6886
|
+
};
|
|
6887
|
+
var setDeep = (object, path, mapper) => {
|
|
6888
|
+
validatePath(path);
|
|
6889
|
+
if (path.length === 0) {
|
|
6890
|
+
return mapper(object);
|
|
6891
|
+
}
|
|
6892
|
+
let parent = object;
|
|
6893
|
+
for (let i = 0;i < path.length - 1; i++) {
|
|
6894
|
+
const key = path[i];
|
|
6895
|
+
if (isArray(parent)) {
|
|
6896
|
+
const index = +key;
|
|
6897
|
+
parent = parent[index];
|
|
6898
|
+
} else if (isPlainObject(parent)) {
|
|
6899
|
+
parent = parent[key];
|
|
6900
|
+
} else if (isSet(parent)) {
|
|
6901
|
+
const row = +key;
|
|
6902
|
+
parent = getNthKey(parent, row);
|
|
6903
|
+
} else if (isMap(parent)) {
|
|
6904
|
+
const isEnd = i === path.length - 2;
|
|
6905
|
+
if (isEnd) {
|
|
6906
|
+
break;
|
|
6907
|
+
}
|
|
6908
|
+
const row = +key;
|
|
6909
|
+
const type = +path[++i] === 0 ? "key" : "value";
|
|
6910
|
+
const keyOfRow = getNthKey(parent, row);
|
|
6911
|
+
switch (type) {
|
|
6912
|
+
case "key":
|
|
6913
|
+
parent = keyOfRow;
|
|
6914
|
+
break;
|
|
6915
|
+
case "value":
|
|
6916
|
+
parent = parent.get(keyOfRow);
|
|
6917
|
+
break;
|
|
6918
|
+
}
|
|
6919
|
+
}
|
|
6920
|
+
}
|
|
6921
|
+
const lastKey = path[path.length - 1];
|
|
6922
|
+
if (isArray(parent)) {
|
|
6923
|
+
parent[+lastKey] = mapper(parent[+lastKey]);
|
|
6924
|
+
} else if (isPlainObject(parent)) {
|
|
6925
|
+
parent[lastKey] = mapper(parent[lastKey]);
|
|
6926
|
+
}
|
|
6927
|
+
if (isSet(parent)) {
|
|
6928
|
+
const oldValue = getNthKey(parent, +lastKey);
|
|
6929
|
+
const newValue = mapper(oldValue);
|
|
6930
|
+
if (oldValue !== newValue) {
|
|
6931
|
+
parent.delete(oldValue);
|
|
6932
|
+
parent.add(newValue);
|
|
6933
|
+
}
|
|
6934
|
+
}
|
|
6935
|
+
if (isMap(parent)) {
|
|
6936
|
+
const row = +path[path.length - 2];
|
|
6937
|
+
const keyToRow = getNthKey(parent, row);
|
|
6938
|
+
const type = +lastKey === 0 ? "key" : "value";
|
|
6939
|
+
switch (type) {
|
|
6940
|
+
case "key": {
|
|
6941
|
+
const newKey = mapper(keyToRow);
|
|
6942
|
+
parent.set(newKey, parent.get(keyToRow));
|
|
6943
|
+
if (newKey !== keyToRow) {
|
|
6944
|
+
parent.delete(keyToRow);
|
|
6945
|
+
}
|
|
6946
|
+
break;
|
|
6947
|
+
}
|
|
6948
|
+
case "value": {
|
|
6949
|
+
parent.set(keyToRow, mapper(parent.get(keyToRow)));
|
|
6950
|
+
break;
|
|
6951
|
+
}
|
|
6952
|
+
}
|
|
6953
|
+
}
|
|
6954
|
+
return object;
|
|
6955
|
+
};
|
|
6956
|
+
|
|
6957
|
+
// node_modules/superjson/dist/plainer.js
|
|
6958
|
+
var enableLegacyPaths = (version) => version < 1;
|
|
6959
|
+
function traverse(tree, walker, version, origin = []) {
|
|
6960
|
+
if (!tree) {
|
|
6961
|
+
return;
|
|
6962
|
+
}
|
|
6963
|
+
const legacyPaths = enableLegacyPaths(version);
|
|
6964
|
+
if (!isArray(tree)) {
|
|
6965
|
+
forEach(tree, (subtree, key) => traverse(subtree, walker, version, [
|
|
6966
|
+
...origin,
|
|
6967
|
+
...parsePath(key, legacyPaths)
|
|
6968
|
+
]));
|
|
6969
|
+
return;
|
|
6970
|
+
}
|
|
6971
|
+
const [nodeValue, children] = tree;
|
|
6972
|
+
if (children) {
|
|
6973
|
+
forEach(children, (child, key) => {
|
|
6974
|
+
traverse(child, walker, version, [
|
|
6975
|
+
...origin,
|
|
6976
|
+
...parsePath(key, legacyPaths)
|
|
6977
|
+
]);
|
|
6978
|
+
});
|
|
6979
|
+
}
|
|
6980
|
+
walker(nodeValue, origin);
|
|
6981
|
+
}
|
|
6982
|
+
function applyValueAnnotations(plain, annotations, version, superJson) {
|
|
6983
|
+
traverse(annotations, (type, path) => {
|
|
6984
|
+
plain = setDeep(plain, path, (v) => untransformValue(v, type, superJson));
|
|
6985
|
+
}, version);
|
|
6986
|
+
return plain;
|
|
6987
|
+
}
|
|
6988
|
+
function applyReferentialEqualityAnnotations(plain, annotations, version) {
|
|
6989
|
+
const legacyPaths = enableLegacyPaths(version);
|
|
6990
|
+
function apply(identicalPaths, path) {
|
|
6991
|
+
const object = getDeep(plain, parsePath(path, legacyPaths));
|
|
6992
|
+
identicalPaths.map((path2) => parsePath(path2, legacyPaths)).forEach((identicalObjectPath) => {
|
|
6993
|
+
plain = setDeep(plain, identicalObjectPath, () => object);
|
|
6994
|
+
});
|
|
6995
|
+
}
|
|
6996
|
+
if (isArray(annotations)) {
|
|
6997
|
+
const [root, other] = annotations;
|
|
6998
|
+
root.forEach((identicalPath) => {
|
|
6999
|
+
plain = setDeep(plain, parsePath(identicalPath, legacyPaths), () => plain);
|
|
7000
|
+
});
|
|
7001
|
+
if (other) {
|
|
7002
|
+
forEach(other, apply);
|
|
7003
|
+
}
|
|
7004
|
+
} else {
|
|
7005
|
+
forEach(annotations, apply);
|
|
7006
|
+
}
|
|
7007
|
+
return plain;
|
|
7008
|
+
}
|
|
7009
|
+
var isDeep = (object, superJson) => isPlainObject(object) || isArray(object) || isMap(object) || isSet(object) || isError(object) || isInstanceOfRegisteredClass(object, superJson);
|
|
7010
|
+
function addIdentity(object, path, identities) {
|
|
7011
|
+
const existingSet = identities.get(object);
|
|
7012
|
+
if (existingSet) {
|
|
7013
|
+
existingSet.push(path);
|
|
7014
|
+
} else {
|
|
7015
|
+
identities.set(object, [path]);
|
|
7016
|
+
}
|
|
7017
|
+
}
|
|
7018
|
+
function generateReferentialEqualityAnnotations(identitites, dedupe) {
|
|
7019
|
+
const result = {};
|
|
7020
|
+
let rootEqualityPaths = undefined;
|
|
7021
|
+
identitites.forEach((paths) => {
|
|
7022
|
+
if (paths.length <= 1) {
|
|
7023
|
+
return;
|
|
7024
|
+
}
|
|
7025
|
+
if (!dedupe) {
|
|
7026
|
+
paths = paths.map((path) => path.map(String)).sort((a, b) => a.length - b.length);
|
|
7027
|
+
}
|
|
7028
|
+
const [representativePath, ...identicalPaths] = paths;
|
|
7029
|
+
if (representativePath.length === 0) {
|
|
7030
|
+
rootEqualityPaths = identicalPaths.map(stringifyPath);
|
|
7031
|
+
} else {
|
|
7032
|
+
result[stringifyPath(representativePath)] = identicalPaths.map(stringifyPath);
|
|
7033
|
+
}
|
|
7034
|
+
});
|
|
7035
|
+
if (rootEqualityPaths) {
|
|
7036
|
+
if (isEmptyObject(result)) {
|
|
7037
|
+
return [rootEqualityPaths];
|
|
7038
|
+
} else {
|
|
7039
|
+
return [rootEqualityPaths, result];
|
|
7040
|
+
}
|
|
7041
|
+
} else {
|
|
7042
|
+
return isEmptyObject(result) ? undefined : result;
|
|
7043
|
+
}
|
|
7044
|
+
}
|
|
7045
|
+
var walker = (object, identities, superJson, dedupe, path = [], objectsInThisPath = [], seenObjects = new Map) => {
|
|
7046
|
+
const primitive = isPrimitive(object);
|
|
7047
|
+
if (!primitive) {
|
|
7048
|
+
addIdentity(object, path, identities);
|
|
7049
|
+
const seen = seenObjects.get(object);
|
|
7050
|
+
if (seen) {
|
|
7051
|
+
return dedupe ? {
|
|
7052
|
+
transformedValue: null
|
|
7053
|
+
} : seen;
|
|
7054
|
+
}
|
|
7055
|
+
}
|
|
7056
|
+
if (!isDeep(object, superJson)) {
|
|
7057
|
+
const transformed2 = transformValue(object, superJson);
|
|
7058
|
+
const result2 = transformed2 ? {
|
|
7059
|
+
transformedValue: transformed2.value,
|
|
7060
|
+
annotations: [transformed2.type]
|
|
7061
|
+
} : {
|
|
7062
|
+
transformedValue: object
|
|
7063
|
+
};
|
|
7064
|
+
if (!primitive) {
|
|
7065
|
+
seenObjects.set(object, result2);
|
|
7066
|
+
}
|
|
7067
|
+
return result2;
|
|
7068
|
+
}
|
|
7069
|
+
if (includes(objectsInThisPath, object)) {
|
|
7070
|
+
return {
|
|
7071
|
+
transformedValue: null
|
|
7072
|
+
};
|
|
7073
|
+
}
|
|
7074
|
+
const transformationResult = transformValue(object, superJson);
|
|
7075
|
+
const transformed = transformationResult?.value ?? object;
|
|
7076
|
+
const transformedValue = isArray(transformed) ? [] : {};
|
|
7077
|
+
const innerAnnotations = {};
|
|
7078
|
+
forEach(transformed, (value, index) => {
|
|
7079
|
+
if (index === "__proto__" || index === "constructor" || index === "prototype") {
|
|
7080
|
+
throw new Error(`Detected property ${index}. This is a prototype pollution risk, please remove it from your object.`);
|
|
7081
|
+
}
|
|
7082
|
+
const recursiveResult = walker(value, identities, superJson, dedupe, [...path, index], [...objectsInThisPath, object], seenObjects);
|
|
7083
|
+
transformedValue[index] = recursiveResult.transformedValue;
|
|
7084
|
+
if (isArray(recursiveResult.annotations)) {
|
|
7085
|
+
innerAnnotations[escapeKey(index)] = recursiveResult.annotations;
|
|
7086
|
+
} else if (isPlainObject(recursiveResult.annotations)) {
|
|
7087
|
+
forEach(recursiveResult.annotations, (tree, key) => {
|
|
7088
|
+
innerAnnotations[escapeKey(index) + "." + key] = tree;
|
|
7089
|
+
});
|
|
7090
|
+
}
|
|
7091
|
+
});
|
|
7092
|
+
const result = isEmptyObject(innerAnnotations) ? {
|
|
7093
|
+
transformedValue,
|
|
7094
|
+
annotations: transformationResult ? [transformationResult.type] : undefined
|
|
7095
|
+
} : {
|
|
7096
|
+
transformedValue,
|
|
7097
|
+
annotations: transformationResult ? [transformationResult.type, innerAnnotations] : innerAnnotations
|
|
7098
|
+
};
|
|
7099
|
+
if (!primitive) {
|
|
7100
|
+
seenObjects.set(object, result);
|
|
7101
|
+
}
|
|
7102
|
+
return result;
|
|
7103
|
+
};
|
|
7104
|
+
|
|
7105
|
+
// node_modules/is-what/dist/getType.js
|
|
7106
|
+
function getType2(payload) {
|
|
7107
|
+
return Object.prototype.toString.call(payload).slice(8, -1);
|
|
7108
|
+
}
|
|
7109
|
+
|
|
7110
|
+
// node_modules/is-what/dist/isArray.js
|
|
7111
|
+
function isArray2(payload) {
|
|
7112
|
+
return getType2(payload) === "Array";
|
|
7113
|
+
}
|
|
7114
|
+
// node_modules/is-what/dist/isPlainObject.js
|
|
7115
|
+
function isPlainObject2(payload) {
|
|
7116
|
+
if (getType2(payload) !== "Object")
|
|
7117
|
+
return false;
|
|
7118
|
+
const prototype = Object.getPrototypeOf(payload);
|
|
7119
|
+
return !!prototype && prototype.constructor === Object && prototype === Object.prototype;
|
|
7120
|
+
}
|
|
7121
|
+
// node_modules/copy-anything/dist/index.js
|
|
7122
|
+
function assignProp(carry, key, newVal, originalObject, includeNonenumerable) {
|
|
7123
|
+
const propType = {}.propertyIsEnumerable.call(originalObject, key) ? "enumerable" : "nonenumerable";
|
|
7124
|
+
if (propType === "enumerable")
|
|
7125
|
+
carry[key] = newVal;
|
|
7126
|
+
if (includeNonenumerable && propType === "nonenumerable") {
|
|
7127
|
+
Object.defineProperty(carry, key, {
|
|
7128
|
+
value: newVal,
|
|
7129
|
+
enumerable: false,
|
|
7130
|
+
writable: true,
|
|
7131
|
+
configurable: true
|
|
7132
|
+
});
|
|
7133
|
+
}
|
|
7134
|
+
}
|
|
7135
|
+
function copy(target, options = {}) {
|
|
7136
|
+
if (isArray2(target)) {
|
|
7137
|
+
return target.map((item) => copy(item, options));
|
|
7138
|
+
}
|
|
7139
|
+
if (!isPlainObject2(target)) {
|
|
7140
|
+
return target;
|
|
7141
|
+
}
|
|
7142
|
+
const props = Object.getOwnPropertyNames(target);
|
|
7143
|
+
const symbols = Object.getOwnPropertySymbols(target);
|
|
7144
|
+
return [...props, ...symbols].reduce((carry, key) => {
|
|
7145
|
+
if (key === "__proto__")
|
|
7146
|
+
return carry;
|
|
7147
|
+
if (isArray2(options.props) && !options.props.includes(key)) {
|
|
7148
|
+
return carry;
|
|
7149
|
+
}
|
|
7150
|
+
const val = target[key];
|
|
7151
|
+
const newVal = copy(val, options);
|
|
7152
|
+
assignProp(carry, key, newVal, target, options.nonenumerable);
|
|
7153
|
+
return carry;
|
|
7154
|
+
}, {});
|
|
7155
|
+
}
|
|
7156
|
+
|
|
7157
|
+
// node_modules/superjson/dist/index.js
|
|
7158
|
+
class SuperJSON {
|
|
7159
|
+
constructor({ dedupe = false } = {}) {
|
|
7160
|
+
this.classRegistry = new ClassRegistry;
|
|
7161
|
+
this.symbolRegistry = new Registry((s) => s.description ?? "");
|
|
7162
|
+
this.customTransformerRegistry = new CustomTransformerRegistry;
|
|
7163
|
+
this.allowedErrorProps = [];
|
|
7164
|
+
this.dedupe = dedupe;
|
|
7165
|
+
}
|
|
7166
|
+
serialize(object) {
|
|
7167
|
+
const identities = new Map;
|
|
7168
|
+
const output = walker(object, identities, this, this.dedupe);
|
|
7169
|
+
const res = {
|
|
7170
|
+
json: output.transformedValue
|
|
7171
|
+
};
|
|
7172
|
+
if (output.annotations) {
|
|
7173
|
+
res.meta = {
|
|
7174
|
+
...res.meta,
|
|
7175
|
+
values: output.annotations
|
|
7176
|
+
};
|
|
7177
|
+
}
|
|
7178
|
+
const equalityAnnotations = generateReferentialEqualityAnnotations(identities, this.dedupe);
|
|
7179
|
+
if (equalityAnnotations) {
|
|
7180
|
+
res.meta = {
|
|
7181
|
+
...res.meta,
|
|
7182
|
+
referentialEqualities: equalityAnnotations
|
|
7183
|
+
};
|
|
7184
|
+
}
|
|
7185
|
+
if (res.meta)
|
|
7186
|
+
res.meta.v = 1;
|
|
7187
|
+
return res;
|
|
7188
|
+
}
|
|
7189
|
+
deserialize(payload, options) {
|
|
7190
|
+
const { json, meta } = payload;
|
|
7191
|
+
let result = options?.inPlace ? json : copy(json);
|
|
7192
|
+
if (meta?.values) {
|
|
7193
|
+
result = applyValueAnnotations(result, meta.values, meta.v ?? 0, this);
|
|
7194
|
+
}
|
|
7195
|
+
if (meta?.referentialEqualities) {
|
|
7196
|
+
result = applyReferentialEqualityAnnotations(result, meta.referentialEqualities, meta.v ?? 0);
|
|
7197
|
+
}
|
|
7198
|
+
return result;
|
|
7199
|
+
}
|
|
7200
|
+
stringify(object) {
|
|
7201
|
+
return JSON.stringify(this.serialize(object));
|
|
7202
|
+
}
|
|
7203
|
+
parse(string) {
|
|
7204
|
+
return this.deserialize(JSON.parse(string), { inPlace: true });
|
|
7205
|
+
}
|
|
7206
|
+
registerClass(v, options) {
|
|
7207
|
+
this.classRegistry.register(v, options);
|
|
7208
|
+
}
|
|
7209
|
+
registerSymbol(v, identifier) {
|
|
7210
|
+
this.symbolRegistry.register(v, identifier);
|
|
7211
|
+
}
|
|
7212
|
+
registerCustom(transformer, name) {
|
|
7213
|
+
this.customTransformerRegistry.register({
|
|
7214
|
+
name,
|
|
7215
|
+
...transformer
|
|
7216
|
+
});
|
|
7217
|
+
}
|
|
7218
|
+
allowErrorProps(...props) {
|
|
7219
|
+
this.allowedErrorProps.push(...props);
|
|
7220
|
+
}
|
|
7221
|
+
}
|
|
7222
|
+
SuperJSON.defaultInstance = new SuperJSON;
|
|
7223
|
+
SuperJSON.serialize = SuperJSON.defaultInstance.serialize.bind(SuperJSON.defaultInstance);
|
|
7224
|
+
SuperJSON.deserialize = SuperJSON.defaultInstance.deserialize.bind(SuperJSON.defaultInstance);
|
|
7225
|
+
SuperJSON.stringify = SuperJSON.defaultInstance.stringify.bind(SuperJSON.defaultInstance);
|
|
7226
|
+
SuperJSON.parse = SuperJSON.defaultInstance.parse.bind(SuperJSON.defaultInstance);
|
|
7227
|
+
SuperJSON.registerClass = SuperJSON.defaultInstance.registerClass.bind(SuperJSON.defaultInstance);
|
|
7228
|
+
SuperJSON.registerSymbol = SuperJSON.defaultInstance.registerSymbol.bind(SuperJSON.defaultInstance);
|
|
7229
|
+
SuperJSON.registerCustom = SuperJSON.defaultInstance.registerCustom.bind(SuperJSON.defaultInstance);
|
|
7230
|
+
SuperJSON.allowErrorProps = SuperJSON.defaultInstance.allowErrorProps.bind(SuperJSON.defaultInstance);
|
|
7231
|
+
var dist_default = SuperJSON;
|
|
7232
|
+
var serialize = SuperJSON.serialize;
|
|
7233
|
+
var deserialize = SuperJSON.deserialize;
|
|
7234
|
+
var stringify = SuperJSON.stringify;
|
|
7235
|
+
var parse = SuperJSON.parse;
|
|
7236
|
+
var registerClass = SuperJSON.registerClass;
|
|
7237
|
+
var registerCustom = SuperJSON.registerCustom;
|
|
7238
|
+
var registerSymbol = SuperJSON.registerSymbol;
|
|
7239
|
+
var allowErrorProps = SuperJSON.allowErrorProps;
|
|
7240
|
+
|
|
7241
|
+
// src/client/trpc.ts
|
|
7242
|
+
init_config();
|
|
7243
|
+
init_logger();
|
|
7244
|
+
init_client();
|
|
7245
|
+
function createTypedClient(config) {
|
|
7246
|
+
const webAppURL = getWebAppURL();
|
|
7247
|
+
if (!webAppURL) {
|
|
7248
|
+
throw new Error("Web app URL not configured");
|
|
7249
|
+
}
|
|
7250
|
+
if (!config.access_token) {
|
|
7251
|
+
throw new Error("Not authenticated. Run 'dosu login' first.");
|
|
7252
|
+
}
|
|
7253
|
+
const httpClient = new Client(config);
|
|
7254
|
+
return createTRPCClient({
|
|
7255
|
+
links: [
|
|
7256
|
+
httpLink({
|
|
7257
|
+
url: `${webAppURL}/api/trpc`,
|
|
7258
|
+
transformer: dist_default,
|
|
7259
|
+
async headers() {
|
|
7260
|
+
if (isTokenExpired(config)) {
|
|
7261
|
+
logger.debug("trpc", "token expired, refreshing before request");
|
|
7262
|
+
try {
|
|
7263
|
+
await httpClient.refreshToken();
|
|
7264
|
+
} catch {
|
|
7265
|
+
throw new Error("session expired. Run 'dosu login' to re-authenticate");
|
|
7266
|
+
}
|
|
7267
|
+
}
|
|
7268
|
+
return { "Supabase-Access-Token": config.access_token };
|
|
7269
|
+
},
|
|
7270
|
+
async fetch(url, options) {
|
|
7271
|
+
const res = await globalThis.fetch(url, options);
|
|
7272
|
+
if (res.status === 401 || res.status === 403) {
|
|
7273
|
+
logger.debug("trpc", "got 401/403, attempting token refresh and retry");
|
|
7274
|
+
try {
|
|
7275
|
+
await httpClient.refreshToken();
|
|
7276
|
+
} catch {
|
|
7277
|
+
return res;
|
|
7278
|
+
}
|
|
7279
|
+
return globalThis.fetch(url, {
|
|
7280
|
+
...options,
|
|
7281
|
+
headers: {
|
|
7282
|
+
...options?.headers,
|
|
7283
|
+
"Supabase-Access-Token": config.access_token
|
|
7284
|
+
}
|
|
7285
|
+
});
|
|
7286
|
+
}
|
|
7287
|
+
return res;
|
|
7288
|
+
}
|
|
7289
|
+
})
|
|
7290
|
+
]
|
|
7291
|
+
});
|
|
7292
|
+
}
|
|
7293
|
+
|
|
7294
|
+
// src/commands/auth.ts
|
|
7295
|
+
init_config();
|
|
7296
|
+
var import_picocolors2 = __toESM(require_picocolors(), 1);
|
|
7297
|
+
function requireLoginConfig() {
|
|
7298
|
+
const cfg = loadConfig();
|
|
7299
|
+
if (!cfg.access_token) {
|
|
7300
|
+
console.error(import_picocolors2.default.red("Not logged in. Run 'dosu login' first."));
|
|
7301
|
+
process.exit(1);
|
|
7302
|
+
}
|
|
7303
|
+
return cfg;
|
|
7304
|
+
}
|
|
7305
|
+
function requireAPIKey(cfg) {
|
|
7306
|
+
if (!cfg.api_key) {
|
|
7307
|
+
console.error(import_picocolors2.default.red("API key not configured. Run 'dosu setup' first."));
|
|
7308
|
+
process.exit(1);
|
|
7309
|
+
}
|
|
7310
|
+
return cfg.api_key;
|
|
7311
|
+
}
|
|
7312
|
+
|
|
7313
|
+
// src/commands/output.ts
|
|
7314
|
+
var import_picocolors3 = __toESM(require_picocolors(), 1);
|
|
7315
|
+
var stripAnsi = (str) => str.replace(/\x1b\[[0-9;]*m/g, "");
|
|
7316
|
+
function printResult(data, opts) {
|
|
7317
|
+
if (opts.json) {
|
|
7318
|
+
console.log(JSON.stringify(data, null, 2));
|
|
7319
|
+
return;
|
|
7320
|
+
}
|
|
7321
|
+
console.log(JSON.stringify(data, null, 2));
|
|
7322
|
+
}
|
|
7323
|
+
function printTable(headers, rows, opts = {}) {
|
|
7324
|
+
if (opts.json && opts.rawData !== undefined) {
|
|
7325
|
+
console.log(JSON.stringify(opts.rawData, null, 2));
|
|
7326
|
+
return;
|
|
7327
|
+
}
|
|
7328
|
+
if (rows.length === 0) {
|
|
7329
|
+
console.log(import_picocolors3.default.dim("No results found."));
|
|
7330
|
+
return;
|
|
7331
|
+
}
|
|
7332
|
+
const widths = headers.map((h, i) => Math.max(h.length, ...rows.map((r) => stripAnsi(r[i] ?? "").length)));
|
|
7333
|
+
const headerLine = headers.map((h, i) => h.padEnd(widths[i])).join(" ");
|
|
7334
|
+
console.log(import_picocolors3.default.bold(headerLine));
|
|
7335
|
+
console.log(import_picocolors3.default.dim("─".repeat(headerLine.length)));
|
|
7336
|
+
for (const row of rows) {
|
|
7337
|
+
console.log(row.map((cell, i) => {
|
|
7338
|
+
const s = cell ?? "";
|
|
7339
|
+
const pad = Math.max(0, widths[i] - stripAnsi(s).length);
|
|
7340
|
+
return s + " ".repeat(pad);
|
|
7341
|
+
}).join(" "));
|
|
7342
|
+
}
|
|
7343
|
+
}
|
|
7344
|
+
function printInfo(entries, opts = {}) {
|
|
7345
|
+
if (opts.json && opts.rawData !== undefined) {
|
|
7346
|
+
console.log(JSON.stringify(opts.rawData, null, 2));
|
|
7347
|
+
return;
|
|
7348
|
+
}
|
|
7349
|
+
const maxLabel = Math.max(...entries.map(([label]) => label.length));
|
|
7350
|
+
for (const [label, value] of entries) {
|
|
7351
|
+
if (value !== undefined) {
|
|
7352
|
+
console.log(`${import_picocolors3.default.bold(label.padEnd(maxLabel))} ${value}`);
|
|
7353
|
+
}
|
|
7354
|
+
}
|
|
7355
|
+
}
|
|
7356
|
+
function truncate(str, maxLen) {
|
|
7357
|
+
if (str.length <= maxLen)
|
|
7358
|
+
return str;
|
|
7359
|
+
return `${str.slice(0, maxLen - 1)}…`;
|
|
7360
|
+
}
|
|
7361
|
+
function formatDate(dateStr) {
|
|
7362
|
+
if (!dateStr)
|
|
7363
|
+
return "—";
|
|
7364
|
+
const d = new Date(dateStr);
|
|
7365
|
+
return d.toLocaleDateString("en-US", {
|
|
7366
|
+
month: "short",
|
|
7367
|
+
day: "numeric",
|
|
7368
|
+
year: "numeric"
|
|
7369
|
+
});
|
|
7370
|
+
}
|
|
7371
|
+
|
|
7372
|
+
// src/commands/analytics.ts
|
|
7373
|
+
function requireConfig() {
|
|
7374
|
+
const cfg = requireLoginConfig();
|
|
7375
|
+
if (!cfg.space_id) {
|
|
7376
|
+
console.error(import_picocolors4.default.red("Missing space config. Run 'dosu setup' to reconfigure."));
|
|
7377
|
+
process.exit(1);
|
|
7378
|
+
}
|
|
7379
|
+
return cfg;
|
|
7380
|
+
}
|
|
7381
|
+
function analyticsCommand() {
|
|
7382
|
+
const cmd = new Command("analytics").description("View usage statistics").option("--days <n>", "Number of days to analyze (default: 30)", "30").option("--json", "Output as JSON").action(async (opts) => {
|
|
7383
|
+
const cfg = requireConfig();
|
|
7384
|
+
const client = createTypedClient(cfg);
|
|
7385
|
+
const stats = await client.analytics.getUsageStats.query({
|
|
7386
|
+
spaceId: cfg.space_id,
|
|
7387
|
+
days: Number.parseInt(opts.days ?? "30", 10)
|
|
7388
|
+
});
|
|
7389
|
+
if (opts.json) {
|
|
7390
|
+
printResult(stats, opts);
|
|
7391
|
+
return;
|
|
7392
|
+
}
|
|
7393
|
+
const pct = (v) => v !== undefined ? `${(v * 100).toFixed(1)}%` : "—";
|
|
7394
|
+
const answerRate = stats.totalResponses > 0 ? stats.totalWithResponse / stats.totalResponses : undefined;
|
|
7395
|
+
printInfo([
|
|
7396
|
+
["Total Responses", String(stats.totalResponses)],
|
|
7397
|
+
["Answer Rate", pct(answerRate)],
|
|
7398
|
+
["High Confidence", String(stats.byConfidence.high)],
|
|
7399
|
+
["Medium Confidence", String(stats.byConfidence.medium)],
|
|
7400
|
+
["Low Confidence", String(stats.byConfidence.low)],
|
|
7401
|
+
["Positive Reactions", String(stats.reactions.totalPositive)],
|
|
7402
|
+
["Negative Reactions", String(stats.reactions.totalNegative)],
|
|
7403
|
+
["Reaction Rate", pct(stats.reactions.reactionRate)],
|
|
7404
|
+
["Positive Rate", pct(stats.reactions.positiveRate)]
|
|
7405
|
+
], { rawData: stats });
|
|
7406
|
+
});
|
|
7407
|
+
return cmd;
|
|
7408
|
+
}
|
|
7409
|
+
|
|
7410
|
+
// src/commands/ask.ts
|
|
7411
|
+
init_config();
|
|
7412
|
+
init_logger();
|
|
7413
|
+
var import_picocolors5 = __toESM(require_picocolors(), 1);
|
|
7414
|
+
function requireConfig2() {
|
|
7415
|
+
const cfg = loadConfig();
|
|
7416
|
+
if (!cfg.api_key) {
|
|
7417
|
+
console.error(import_picocolors5.default.red("Not configured. Run 'dosu setup' first."));
|
|
7418
|
+
process.exit(1);
|
|
7419
|
+
}
|
|
7420
|
+
if (!cfg.deployment_id || !cfg.space_id) {
|
|
7421
|
+
console.error(import_picocolors5.default.red("Missing deployment config. Run 'dosu setup' to reconfigure."));
|
|
7422
|
+
process.exit(1);
|
|
7423
|
+
}
|
|
7424
|
+
return cfg;
|
|
7425
|
+
}
|
|
7426
|
+
function askCommand() {
|
|
7427
|
+
const cmd = new Command("ask").description("Ask a question and get an AI-generated answer").argument("<question>", "The question to ask").option("--session <id>", "Continue a previous ask session").option("--json", "Output as JSON").action(async (question, opts) => {
|
|
7428
|
+
const cfg = requireConfig2();
|
|
7429
|
+
const backendURL = getBackendURL();
|
|
7430
|
+
if (!backendURL) {
|
|
7431
|
+
console.error(import_picocolors5.default.red("Backend URL not configured."));
|
|
7432
|
+
process.exit(1);
|
|
7433
|
+
}
|
|
7434
|
+
logger.debug("ask", `Asking: ${question}`);
|
|
7435
|
+
const controller = new AbortController;
|
|
7436
|
+
const timeout = setTimeout(() => controller.abort(), 120000);
|
|
7437
|
+
try {
|
|
7438
|
+
const resp = await fetch(`${backendURL}/ask`, {
|
|
7439
|
+
method: "POST",
|
|
7440
|
+
headers: {
|
|
7441
|
+
"Content-Type": "application/json",
|
|
7442
|
+
"X-Dosu-API-Key": cfg.api_key
|
|
7443
|
+
},
|
|
7444
|
+
body: JSON.stringify({
|
|
7445
|
+
deployment_id: cfg.deployment_id,
|
|
7446
|
+
question,
|
|
7447
|
+
session_id: opts.session ?? undefined
|
|
7448
|
+
}),
|
|
7449
|
+
signal: controller.signal
|
|
7450
|
+
});
|
|
7451
|
+
if (!resp.ok) {
|
|
7452
|
+
let detail = `Request failed with status ${resp.status}`;
|
|
7453
|
+
try {
|
|
7454
|
+
const errBody = await resp.json();
|
|
7455
|
+
const raw = errBody.detail ?? detail;
|
|
7456
|
+
detail = typeof raw === "string" ? raw : JSON.stringify(raw, null, 2);
|
|
7457
|
+
} catch {}
|
|
7458
|
+
console.error(import_picocolors5.default.red(`Error: ${detail}`));
|
|
7459
|
+
process.exit(1);
|
|
7460
|
+
}
|
|
7461
|
+
const body = await resp.json();
|
|
7462
|
+
if (opts.json) {
|
|
7463
|
+
printResult(body, opts);
|
|
7464
|
+
return;
|
|
7465
|
+
}
|
|
7466
|
+
if (body.answer) {
|
|
7467
|
+
console.log(body.answer);
|
|
7468
|
+
} else {
|
|
7469
|
+
console.log(JSON.stringify(body, null, 2));
|
|
7470
|
+
}
|
|
7471
|
+
if (body.session_id) {
|
|
7472
|
+
console.log(`
|
|
7473
|
+
${import_picocolors5.default.dim(`Session: ${body.session_id}`)}`);
|
|
7474
|
+
}
|
|
7475
|
+
if (body.observations && body.observations.length > 0) {
|
|
7476
|
+
console.log(`
|
|
7477
|
+
${import_picocolors5.default.bold("Key observations:")}`);
|
|
7478
|
+
for (const obs of body.observations) {
|
|
7479
|
+
console.log(` ${import_picocolors5.default.dim("•")} ${obs}`);
|
|
7480
|
+
}
|
|
7481
|
+
}
|
|
7482
|
+
} catch (err) {
|
|
7483
|
+
if (err instanceof Error && err.name === "AbortError") {
|
|
7484
|
+
console.error(import_picocolors5.default.red("Request timed out."));
|
|
7485
|
+
process.exit(1);
|
|
7486
|
+
}
|
|
7487
|
+
throw err;
|
|
7488
|
+
} finally {
|
|
7489
|
+
clearTimeout(timeout);
|
|
7490
|
+
}
|
|
7491
|
+
});
|
|
7492
|
+
return cmd;
|
|
7493
|
+
}
|
|
7494
|
+
|
|
7495
|
+
// src/commands/deployments.ts
|
|
7496
|
+
var import_picocolors6 = __toESM(require_picocolors(), 1);
|
|
7497
|
+
init_config();
|
|
7498
|
+
function requireConfig3() {
|
|
7499
|
+
return requireLoginConfig();
|
|
7500
|
+
}
|
|
7501
|
+
function deploymentsCommand() {
|
|
7502
|
+
const cmd = new Command("deployments").description("Manage deployments");
|
|
7503
|
+
cmd.command("list").description("List all deployments").option("--json", "Output as JSON").action(async (opts) => {
|
|
7504
|
+
const cfg = requireConfig3();
|
|
7505
|
+
const client = createTypedClient(cfg);
|
|
7506
|
+
const deployments = cfg.org_id ? await client.workspaces.listForOrg.query(cfg.org_id) : await client.workspaces.listAll.query({});
|
|
7507
|
+
if (opts.json) {
|
|
7508
|
+
printResult(deployments, opts);
|
|
7509
|
+
return;
|
|
7510
|
+
}
|
|
7511
|
+
if (!deployments || deployments.length === 0) {
|
|
7512
|
+
console.log(import_picocolors6.default.dim("No deployments found."));
|
|
7513
|
+
return;
|
|
7514
|
+
}
|
|
7515
|
+
printTable(["ID", "Name", "Org", "Status"], deployments.map((d) => [
|
|
7516
|
+
d.deployment_id.slice(0, 8),
|
|
7517
|
+
d.name ?? "(unnamed)",
|
|
7518
|
+
d.org_name ?? "—",
|
|
7519
|
+
d.enabled ? import_picocolors6.default.green("active") : import_picocolors6.default.dim("disabled")
|
|
7520
|
+
]), { rawData: deployments });
|
|
7521
|
+
if (cfg.deployment_id) {
|
|
7522
|
+
console.log(`
|
|
7523
|
+
${import_picocolors6.default.dim(`Current: ${cfg.deployment_name ?? cfg.deployment_id}`)}`);
|
|
7524
|
+
}
|
|
7525
|
+
});
|
|
7526
|
+
cmd.command("info").description("Show current deployment details").option("--json", "Output as JSON").action(async (opts) => {
|
|
7527
|
+
const cfg = requireConfig3();
|
|
7528
|
+
if (!cfg.deployment_id) {
|
|
7529
|
+
console.error(import_picocolors6.default.red("No deployment selected. Run 'dosu setup' or 'dosu deployments switch'."));
|
|
7530
|
+
process.exit(1);
|
|
7531
|
+
}
|
|
7532
|
+
const client = createTypedClient(cfg);
|
|
7533
|
+
const deployment = await client.workspaces.get.query(cfg.deployment_id);
|
|
7534
|
+
if (opts.json) {
|
|
7535
|
+
printResult(deployment, opts);
|
|
7536
|
+
return;
|
|
7537
|
+
}
|
|
7538
|
+
printInfo([
|
|
7539
|
+
["ID", deployment.deployment_id],
|
|
7540
|
+
["Name", deployment.name],
|
|
7541
|
+
["Description", deployment.description],
|
|
7542
|
+
["Organization", deployment.org_name],
|
|
7543
|
+
["Status", deployment.enabled ? "active" : "disabled"],
|
|
7544
|
+
["Space ID", deployment.space_id],
|
|
7545
|
+
["Created", formatDate(deployment.created_at)]
|
|
7546
|
+
], { rawData: deployment });
|
|
7547
|
+
});
|
|
7548
|
+
cmd.command("switch").description("Switch to a different deployment").argument("<id>", "Deployment ID").option("--json", "Output as JSON").action(async (id, opts) => {
|
|
7549
|
+
const cfg = requireConfig3();
|
|
7550
|
+
const client = createTypedClient(cfg);
|
|
7551
|
+
const deployment = await client.workspaces.get.query(id);
|
|
7552
|
+
cfg.deployment_id = deployment.deployment_id;
|
|
7553
|
+
cfg.deployment_name = deployment.name;
|
|
7554
|
+
cfg.org_id = deployment.org_id;
|
|
7555
|
+
cfg.space_id = deployment.space_id;
|
|
7556
|
+
saveConfig(cfg);
|
|
7557
|
+
if (opts.json) {
|
|
7558
|
+
printResult({ success: true, deployment_id: deployment.deployment_id, name: deployment.name }, opts);
|
|
7559
|
+
return;
|
|
7560
|
+
}
|
|
7561
|
+
console.log(import_picocolors6.default.green(`Switched to deployment: ${deployment.name}`));
|
|
7562
|
+
});
|
|
7563
|
+
return cmd;
|
|
7564
|
+
}
|
|
7565
|
+
|
|
7566
|
+
// src/commands/docs.ts
|
|
7567
|
+
import { readFileSync as readFileSync3 } from "node:fs";
|
|
7568
|
+
var import_picocolors7 = __toESM(require_picocolors(), 1);
|
|
7569
|
+
init_logger();
|
|
7570
|
+
function requireConfig4() {
|
|
7571
|
+
const cfg = requireLoginConfig();
|
|
7572
|
+
if (!cfg.space_id) {
|
|
7573
|
+
console.error(import_picocolors7.default.red("Missing space config. Run 'dosu setup' to reconfigure."));
|
|
7574
|
+
process.exit(1);
|
|
7575
|
+
}
|
|
7576
|
+
return cfg;
|
|
7577
|
+
}
|
|
7578
|
+
async function getKnowledgeStoreId(client, spaceId) {
|
|
7579
|
+
const store = await client.knowledgeStore.getBySpaceId.query({
|
|
7580
|
+
space_id: spaceId
|
|
7581
|
+
});
|
|
7582
|
+
if (!store) {
|
|
7583
|
+
console.error(import_picocolors7.default.red("No knowledge store found for this deployment."));
|
|
7584
|
+
process.exit(1);
|
|
7585
|
+
}
|
|
7586
|
+
return store.id;
|
|
7587
|
+
}
|
|
7588
|
+
function readBody(opts) {
|
|
7589
|
+
if (opts.bodyFile)
|
|
7590
|
+
return readFileSync3(opts.bodyFile, "utf-8");
|
|
7591
|
+
return opts.body;
|
|
7592
|
+
}
|
|
7593
|
+
async function backendPost(path, apiKey, body) {
|
|
7594
|
+
const backendURL = getBackendURL();
|
|
7595
|
+
if (!backendURL) {
|
|
7596
|
+
console.error(import_picocolors7.default.red("Backend URL not configured."));
|
|
7597
|
+
process.exit(1);
|
|
7598
|
+
}
|
|
7599
|
+
const resp = await fetch(`${backendURL}${path}`, {
|
|
7600
|
+
method: "POST",
|
|
7601
|
+
headers: { "Content-Type": "application/json", "X-Dosu-API-Key": apiKey },
|
|
7602
|
+
body: JSON.stringify(body)
|
|
7603
|
+
});
|
|
7604
|
+
if (!resp.ok) {
|
|
7605
|
+
let detail = `Request failed with status ${resp.status}`;
|
|
7606
|
+
try {
|
|
7607
|
+
const errBody = await resp.json();
|
|
7608
|
+
detail = errBody.detail ?? detail;
|
|
7609
|
+
} catch {}
|
|
7610
|
+
throw new Error(detail);
|
|
7611
|
+
}
|
|
7612
|
+
return await resp.json();
|
|
7613
|
+
}
|
|
7614
|
+
function docsCommand() {
|
|
7615
|
+
const cmd = new Command("docs").description("Document management");
|
|
7616
|
+
cmd.command("list").description("List documents").option("--search <query>", "Search documents").option("--tag <id>", "Filter by tag ID").option("--limit <n>", "Maximum results", "20").option("--json", "Output as JSON").action(async (opts) => {
|
|
7617
|
+
const cfg = requireConfig4();
|
|
7618
|
+
const client = createTypedClient(cfg);
|
|
7619
|
+
const ksId = await getKnowledgeStoreId(client, cfg.space_id);
|
|
7620
|
+
const result = await client.page.listWithTags.query({
|
|
7621
|
+
knowledge_store_id: ksId,
|
|
7622
|
+
searchTerm: opts.search,
|
|
7623
|
+
tag_id: opts.tag,
|
|
7624
|
+
limit: Number.parseInt(opts.limit ?? "20", 10)
|
|
7625
|
+
});
|
|
7626
|
+
const pages = result.data;
|
|
7627
|
+
if (opts.json) {
|
|
7628
|
+
printResult(pages, opts);
|
|
7629
|
+
return;
|
|
7630
|
+
}
|
|
7631
|
+
if (!pages || pages.length === 0) {
|
|
7632
|
+
console.log(import_picocolors7.default.dim("No documents found."));
|
|
7633
|
+
return;
|
|
7634
|
+
}
|
|
7635
|
+
printTable(["ID", "Title", "Status", "Created"], pages.map((p) => [
|
|
7636
|
+
p.id.slice(0, 8),
|
|
7637
|
+
truncate(p.title ?? "(untitled)", 50),
|
|
7638
|
+
p.published ? "published" : "draft",
|
|
7639
|
+
formatDate(p.created_at)
|
|
7640
|
+
]), { rawData: pages });
|
|
7641
|
+
});
|
|
7642
|
+
cmd.command("get").description("Get a document").argument("<id>", "Page ID").option("--version <v>", "Specific version number").option("--json", "Output as JSON").action(async (id, opts) => {
|
|
7643
|
+
const cfg = requireConfig4();
|
|
7644
|
+
const client = createTypedClient(cfg);
|
|
7645
|
+
const page = await client.page.get.query({
|
|
7646
|
+
page_id: id,
|
|
7647
|
+
version: opts.version ? Number.parseInt(opts.version, 10) : undefined
|
|
7648
|
+
});
|
|
7649
|
+
if (opts.json) {
|
|
7650
|
+
printResult(page, opts);
|
|
7651
|
+
return;
|
|
7652
|
+
}
|
|
7653
|
+
if (!page) {
|
|
7654
|
+
console.log(import_picocolors7.default.dim("Document not found."));
|
|
7655
|
+
return;
|
|
7656
|
+
}
|
|
7657
|
+
console.log(import_picocolors7.default.bold(page.title ?? "(untitled)"));
|
|
7658
|
+
printInfo([
|
|
7659
|
+
["ID", page.id],
|
|
7660
|
+
["Status", page.published ? "published" : "draft"],
|
|
7661
|
+
["Created", formatDate(page.created_at)]
|
|
7662
|
+
]);
|
|
7663
|
+
if (page.body) {
|
|
7664
|
+
console.log(`
|
|
7665
|
+
${page.body}`);
|
|
7666
|
+
}
|
|
7667
|
+
});
|
|
7668
|
+
cmd.command("create").description("Create a new document").requiredOption("--title <title>", "Document title").option("--body <markdown>", "Document body (markdown)").option("--body-file <path>", "Read body from file").option("--json", "Output as JSON").action(async (opts) => {
|
|
7669
|
+
const cfg = requireConfig4();
|
|
7670
|
+
const client = createTypedClient(cfg);
|
|
7671
|
+
const ksId = await getKnowledgeStoreId(client, cfg.space_id);
|
|
7672
|
+
const body = readBody(opts);
|
|
7673
|
+
const result = await client.page.create.mutate({
|
|
7674
|
+
knowledge_store_id: ksId,
|
|
7675
|
+
title: opts.title,
|
|
7676
|
+
body: body ?? ""
|
|
7677
|
+
});
|
|
7678
|
+
if (opts.json) {
|
|
7679
|
+
printResult(result, opts);
|
|
7680
|
+
return;
|
|
7681
|
+
}
|
|
7682
|
+
console.log(import_picocolors7.default.green(`Document "${opts.title}" created.`));
|
|
7683
|
+
});
|
|
7684
|
+
cmd.command("update").description("Update a document").argument("<id>", "Page ID").option("--title <title>", "New title").option("--body <markdown>", "New body (markdown)").option("--body-file <path>", "Read body from file").option("--json", "Output as JSON").action(async (id, opts) => {
|
|
7685
|
+
const cfg = requireConfig4();
|
|
7686
|
+
const client = createTypedClient(cfg);
|
|
7687
|
+
const ksId = await getKnowledgeStoreId(client, cfg.space_id);
|
|
7688
|
+
const body = readBody(opts);
|
|
7689
|
+
const result = await client.page.update.mutate({
|
|
7690
|
+
id,
|
|
7691
|
+
knowledge_store_id: ksId,
|
|
7692
|
+
title: opts.title,
|
|
7693
|
+
body
|
|
7694
|
+
});
|
|
7695
|
+
if (opts.json) {
|
|
7696
|
+
printResult(result, opts);
|
|
7697
|
+
return;
|
|
7698
|
+
}
|
|
7699
|
+
console.log(import_picocolors7.default.green("Document updated."));
|
|
7700
|
+
});
|
|
7701
|
+
for (const archived of [true, false]) {
|
|
7702
|
+
const name = archived ? "archive" : "unarchive";
|
|
7703
|
+
cmd.command(name).description(`${archived ? "Archive" : "Unarchive"} a document`).argument("<id>", "Page ID").option("--json", "Output as JSON").action(async (id, opts) => {
|
|
7704
|
+
const cfg = requireConfig4();
|
|
7705
|
+
const client = createTypedClient(cfg);
|
|
7706
|
+
await client.page.setArchiveState.mutate({ page_id: id, archived });
|
|
7707
|
+
if (opts.json) {
|
|
7708
|
+
printResult({ success: true, id, archived }, opts);
|
|
7709
|
+
return;
|
|
7710
|
+
}
|
|
7711
|
+
console.log(import_picocolors7.default.green(`Document ${name}d.`));
|
|
7712
|
+
});
|
|
7713
|
+
}
|
|
7714
|
+
cmd.command("delete").description("Delete a document").argument("<id>", "Page ID").option("--json", "Output as JSON").action(async (id, opts) => {
|
|
7715
|
+
const cfg = requireConfig4();
|
|
7716
|
+
const client = createTypedClient(cfg);
|
|
7717
|
+
await client.page.delete.mutate({ page_id: id });
|
|
7718
|
+
if (opts.json) {
|
|
7719
|
+
printResult({ success: true, id }, opts);
|
|
7720
|
+
return;
|
|
7721
|
+
}
|
|
7722
|
+
console.log(import_picocolors7.default.green("Document deleted."));
|
|
7723
|
+
});
|
|
7724
|
+
cmd.command("versions").description("List document versions").argument("<id>", "Page ID").option("--json", "Output as JSON").action(async (id, opts) => {
|
|
7725
|
+
const cfg = requireConfig4();
|
|
7726
|
+
const client = createTypedClient(cfg);
|
|
7727
|
+
const versions = await client.page.listVersions.query({ page_id: id });
|
|
7728
|
+
if (opts.json) {
|
|
7729
|
+
printResult(versions, opts);
|
|
7730
|
+
return;
|
|
7731
|
+
}
|
|
7732
|
+
if (!versions || versions.length === 0) {
|
|
7733
|
+
console.log(import_picocolors7.default.dim("No versions found."));
|
|
7734
|
+
return;
|
|
7735
|
+
}
|
|
7736
|
+
printTable(["Version", "Created"], versions.map((v) => [
|
|
7737
|
+
String(v.version),
|
|
7738
|
+
formatDate(v.created_at)
|
|
7739
|
+
]), { rawData: versions });
|
|
7740
|
+
});
|
|
7741
|
+
cmd.command("restore").description("Restore a document version").argument("<id>", "Page ID").requiredOption("--version <n>", "Version number to restore").option("--json", "Output as JSON").action(async (id, opts) => {
|
|
7742
|
+
const cfg = requireConfig4();
|
|
7743
|
+
const client = createTypedClient(cfg);
|
|
7744
|
+
await client.page.restoreVersion.mutate({
|
|
7745
|
+
page_id: id,
|
|
7746
|
+
version_to_restore: Number.parseInt(opts.version, 10)
|
|
7747
|
+
});
|
|
7748
|
+
if (opts.json) {
|
|
7749
|
+
printResult({ success: true, id, version: opts.version }, opts);
|
|
7750
|
+
return;
|
|
7751
|
+
}
|
|
7752
|
+
console.log(import_picocolors7.default.green(`Document restored to version ${opts.version}.`));
|
|
7753
|
+
});
|
|
7754
|
+
cmd.command("generate").description("Generate a document using AI").requiredOption("--title <title>", "Document title").option("--instructions <text>", "Custom generation instructions").option("--json", "Output as JSON").action(async (opts) => {
|
|
7755
|
+
const cfg = requireConfig4();
|
|
7756
|
+
const client = createTypedClient(cfg);
|
|
7757
|
+
const ksId = await getKnowledgeStoreId(client, cfg.space_id);
|
|
7758
|
+
const result = await backendPost("/doc/generate", requireAPIKey(cfg), {
|
|
7759
|
+
knowledge_store_id: ksId,
|
|
7760
|
+
title: opts.title,
|
|
7761
|
+
instructions: opts.instructions
|
|
7762
|
+
});
|
|
7763
|
+
if (opts.json) {
|
|
7764
|
+
printResult(result, opts);
|
|
7765
|
+
return;
|
|
7766
|
+
}
|
|
7767
|
+
console.log(import_picocolors7.default.green("Document generation started."));
|
|
7768
|
+
});
|
|
7769
|
+
cmd.command("auto-tag").description("Auto-tag a document using AI").argument("<id>", "Page ID").option("--json", "Output as JSON").action(async (id, opts) => {
|
|
7770
|
+
const cfg = requireConfig4();
|
|
7771
|
+
const result = await backendPost("/doc/auto-tag", requireAPIKey(cfg), { page_id: id });
|
|
7772
|
+
if (opts.json) {
|
|
7773
|
+
printResult(result, opts);
|
|
7774
|
+
return;
|
|
7775
|
+
}
|
|
7776
|
+
console.log(import_picocolors7.default.green("Auto-tagging started."));
|
|
7777
|
+
});
|
|
7778
|
+
cmd.command("import").description("Import documents from an external platform").argument("<platform>", "Platform: github, gitlab, confluence, notion, coda").requiredOption("--files <ids>", "Comma-separated file/page IDs to import").option("--json", "Output as JSON").action(async (platform, opts) => {
|
|
7779
|
+
const cfg = requireConfig4();
|
|
7780
|
+
const client = createTypedClient(cfg);
|
|
7781
|
+
const ksId = await getKnowledgeStoreId(client, cfg.space_id);
|
|
7782
|
+
const fileIds = opts.files.split(",").map((id) => id.trim());
|
|
7783
|
+
const importFn = {
|
|
7784
|
+
github: (input) => client.docImports.importGithubFiles.mutate(input),
|
|
7785
|
+
gitlab: (input) => client.docImports.importGitlabFiles.mutate(input),
|
|
7786
|
+
confluence: (input) => client.docImports.importConfluencePages.mutate(input),
|
|
7787
|
+
notion: (input) => client.docImports.importNotionPages.mutate(input),
|
|
7788
|
+
coda: (input) => client.docImports.importCodaPages.mutate(input)
|
|
7789
|
+
};
|
|
7790
|
+
const fn = importFn[platform.toLowerCase()];
|
|
7791
|
+
if (!fn) {
|
|
7792
|
+
console.error(import_picocolors7.default.red(`Unknown platform: ${platform}. Use: github, gitlab, confluence, notion, coda`));
|
|
7793
|
+
process.exit(1);
|
|
7794
|
+
}
|
|
7795
|
+
const idField = ["confluence", "notion", "coda"].includes(platform.toLowerCase()) ? "page_ids" : "file_ids";
|
|
7796
|
+
const result = await fn({
|
|
7797
|
+
knowledge_store_id: ksId,
|
|
7798
|
+
space_id: cfg.space_id,
|
|
7799
|
+
[idField]: fileIds
|
|
7800
|
+
});
|
|
7801
|
+
if (opts.json) {
|
|
7802
|
+
printResult(result, opts);
|
|
7803
|
+
return;
|
|
7804
|
+
}
|
|
7805
|
+
console.log(import_picocolors7.default.green(`Import started.${result.task_id ? ` Task ID: ${result.task_id}` : ""}`));
|
|
7806
|
+
});
|
|
7807
|
+
cmd.command("import-status").description("Check import task status").argument("<task-id>", "Import task ID").option("--json", "Output as JSON").action(async (taskId, opts) => {
|
|
7808
|
+
const cfg = requireConfig4();
|
|
7809
|
+
const client = createTypedClient(cfg);
|
|
7810
|
+
const status = await client.docImports.getImportStatus.query(taskId);
|
|
7811
|
+
if (opts.json) {
|
|
7812
|
+
printResult(status, opts);
|
|
7813
|
+
return;
|
|
7814
|
+
}
|
|
7815
|
+
if (!status) {
|
|
7816
|
+
console.log(import_picocolors7.default.dim("Import task not found."));
|
|
7817
|
+
return;
|
|
7818
|
+
}
|
|
7819
|
+
console.log(`Status: ${JSON.stringify(status)}`);
|
|
7820
|
+
});
|
|
7821
|
+
cmd.command("publish").description("Publish a document to an external platform").argument("<id>", "Page ID").requiredOption("--to <platform>", "Target: github, gitlab, confluence, notion, coda").option("--repo-id <id>", "GitHub repository ID").option("--project-id <id>", "GitLab project ID").option("--parent-page-id <id>", "Parent page ID (Confluence/Notion)").option("--doc-id <id>", "Coda doc ID").option("--directory <path>", "Target directory (GitHub/GitLab)").option("--data-source-id <id>", "Data source ID").option("--json", "Output as JSON").action(async (id, opts) => {
|
|
7822
|
+
const cfg = requireConfig4();
|
|
7823
|
+
const platform = opts.to.toLowerCase();
|
|
7824
|
+
const publishMap = {
|
|
7825
|
+
github: {
|
|
7826
|
+
path: `/sync-back/github/${id}/publish`,
|
|
7827
|
+
buildBody: () => ({
|
|
7828
|
+
target_repository_id: Number(opts.repoId),
|
|
7829
|
+
target_directory: opts.directory ?? "/",
|
|
7830
|
+
target_data_source_id: opts.dataSourceId
|
|
7831
|
+
})
|
|
7832
|
+
},
|
|
7833
|
+
gitlab: {
|
|
7834
|
+
path: `/sync-back/gitlab/${id}/publish`,
|
|
7835
|
+
buildBody: () => ({
|
|
7836
|
+
gitlab_project_id: opts.projectId,
|
|
7837
|
+
target_directory: opts.directory ?? "/",
|
|
7838
|
+
target_data_source_id: opts.dataSourceId
|
|
7839
|
+
})
|
|
7840
|
+
},
|
|
7841
|
+
confluence: {
|
|
7842
|
+
path: `/sync-back/confluence/${id}/publish`,
|
|
7843
|
+
buildBody: () => ({
|
|
7844
|
+
parent_page_id: opts.parentPageId,
|
|
7845
|
+
target_data_source_id: opts.dataSourceId
|
|
7846
|
+
})
|
|
7847
|
+
},
|
|
7848
|
+
notion: {
|
|
7849
|
+
path: `/sync-back/notion/${id}/publish`,
|
|
7850
|
+
buildBody: () => ({
|
|
7851
|
+
parent_notion_page_id: opts.parentPageId,
|
|
7852
|
+
target_data_source_id: opts.dataSourceId
|
|
7853
|
+
})
|
|
7854
|
+
},
|
|
7855
|
+
coda: {
|
|
7856
|
+
path: `/sync-back/coda/${id}/publish`,
|
|
7857
|
+
buildBody: () => ({
|
|
7858
|
+
target_doc_id: opts.docId,
|
|
7859
|
+
target_data_source_id: opts.dataSourceId
|
|
7860
|
+
})
|
|
7861
|
+
}
|
|
7862
|
+
};
|
|
7863
|
+
const config = publishMap[platform];
|
|
7864
|
+
if (!config) {
|
|
7865
|
+
console.error(import_picocolors7.default.red(`Unknown platform: ${platform}`));
|
|
7866
|
+
process.exit(1);
|
|
7867
|
+
}
|
|
7868
|
+
logger.debug("docs", `Publishing to ${platform}`);
|
|
7869
|
+
const result = await backendPost(config.path, requireAPIKey(cfg), config.buildBody());
|
|
7870
|
+
if (opts.json) {
|
|
7871
|
+
printResult(result, opts);
|
|
7872
|
+
return;
|
|
7873
|
+
}
|
|
7874
|
+
console.log(import_picocolors7.default.green(`Document published to ${platform}.`));
|
|
7875
|
+
});
|
|
7876
|
+
cmd.command("sync-back").description("Sync document back to its source (Notion/Confluence)").argument("<id>", "Page ID").option("--json", "Output as JSON").action(async (id, opts) => {
|
|
7877
|
+
const cfg = requireConfig4();
|
|
7878
|
+
const client = createTypedClient(cfg);
|
|
7879
|
+
const result = await client.page.syncBack.mutate({ page_id: id });
|
|
7880
|
+
if (opts.json) {
|
|
7881
|
+
printResult(result, opts);
|
|
7882
|
+
return;
|
|
7883
|
+
}
|
|
7884
|
+
console.log(import_picocolors7.default.green("Sync-back initiated."));
|
|
7885
|
+
});
|
|
7886
|
+
return cmd;
|
|
7887
|
+
}
|
|
7888
|
+
|
|
7889
|
+
// src/commands/integrations.ts
|
|
7890
|
+
var import_picocolors8 = __toESM(require_picocolors(), 1);
|
|
7891
|
+
function requireConfig5() {
|
|
7892
|
+
const cfg = requireLoginConfig();
|
|
7893
|
+
if (!cfg.org_id) {
|
|
7894
|
+
console.error(import_picocolors8.default.red("Missing org config. Run 'dosu setup' to reconfigure."));
|
|
7895
|
+
process.exit(1);
|
|
7896
|
+
}
|
|
7897
|
+
return cfg;
|
|
7898
|
+
}
|
|
7899
|
+
var NANGO_PLATFORMS = [
|
|
7900
|
+
"confluence",
|
|
7901
|
+
"notion",
|
|
7902
|
+
"coda",
|
|
7903
|
+
"gitlab",
|
|
7904
|
+
"gitlab-pat",
|
|
7905
|
+
"confluence-basic"
|
|
7906
|
+
];
|
|
7907
|
+
var DISPLAY_PLATFORMS = [
|
|
7908
|
+
"github",
|
|
7909
|
+
"gitlab",
|
|
7910
|
+
"slack",
|
|
7911
|
+
"confluence",
|
|
7912
|
+
"notion",
|
|
7913
|
+
"coda",
|
|
7914
|
+
"teams"
|
|
7915
|
+
];
|
|
7916
|
+
function integrationsCommand() {
|
|
7917
|
+
const cmd = new Command("integrations").description("Manage integrations");
|
|
7918
|
+
cmd.command("list").description("List all integrations and their connection status").option("--json", "Output as JSON").action(async (opts) => {
|
|
7919
|
+
const cfg = requireConfig5();
|
|
7920
|
+
const client = createTypedClient(cfg);
|
|
7921
|
+
const results = [];
|
|
7922
|
+
for (const platform of DISPLAY_PLATFORMS) {
|
|
7923
|
+
const nangoProvider = NANGO_PLATFORMS.find((p) => p === platform);
|
|
7924
|
+
if (nangoProvider) {
|
|
7925
|
+
try {
|
|
7926
|
+
const conn = await client.nango.getConnection.query({
|
|
7927
|
+
provider: nangoProvider,
|
|
7928
|
+
providerConfigKey: nangoProvider,
|
|
7929
|
+
orgId: cfg.org_id
|
|
7930
|
+
});
|
|
7931
|
+
results.push({ platform, connected: conn !== null });
|
|
7932
|
+
} catch {
|
|
7933
|
+
results.push({ platform, connected: false });
|
|
7934
|
+
}
|
|
7935
|
+
} else {
|
|
7936
|
+
results.push({ platform, connected: false });
|
|
7937
|
+
}
|
|
7938
|
+
}
|
|
7939
|
+
if (opts.json) {
|
|
7940
|
+
printResult(results, opts);
|
|
7941
|
+
return;
|
|
7942
|
+
}
|
|
7943
|
+
printTable(["Platform", "Status"], results.map((r) => [
|
|
7944
|
+
r.platform,
|
|
7945
|
+
r.connected ? import_picocolors8.default.green("connected") : import_picocolors8.default.dim("not connected")
|
|
7946
|
+
]), { rawData: results });
|
|
7947
|
+
});
|
|
7948
|
+
cmd.command("status").description("Check connection status of a specific platform").argument("<platform>", `Platform: ${DISPLAY_PLATFORMS.join(", ")}`).option("--json", "Output as JSON").action(async (platform, opts) => {
|
|
7949
|
+
const cfg = requireConfig5();
|
|
7950
|
+
const client = createTypedClient(cfg);
|
|
7951
|
+
const nangoProvider = NANGO_PLATFORMS.find((p) => p === platform);
|
|
7952
|
+
if (!nangoProvider) {
|
|
7953
|
+
if (opts.json) {
|
|
7954
|
+
printResult({ platform, connected: false, note: "not queryable via nango" }, opts);
|
|
7955
|
+
return;
|
|
7956
|
+
}
|
|
7957
|
+
console.log(`${platform}: ${import_picocolors8.default.dim("not connected (not queryable)")}`);
|
|
7958
|
+
return;
|
|
7959
|
+
}
|
|
7960
|
+
try {
|
|
7961
|
+
const conn = await client.nango.getConnection.query({
|
|
7962
|
+
provider: nangoProvider,
|
|
7963
|
+
providerConfigKey: nangoProvider,
|
|
7964
|
+
orgId: cfg.org_id
|
|
7965
|
+
});
|
|
7966
|
+
const connected = conn !== null;
|
|
7967
|
+
if (opts.json) {
|
|
7968
|
+
printResult({ platform, connected, connection: conn }, opts);
|
|
7969
|
+
return;
|
|
7970
|
+
}
|
|
7971
|
+
console.log(`${platform}: ${connected ? import_picocolors8.default.green("connected") : import_picocolors8.default.dim("not connected")}`);
|
|
7972
|
+
} catch {
|
|
7973
|
+
if (opts.json) {
|
|
7974
|
+
printResult({ platform, connected: false }, opts);
|
|
7975
|
+
return;
|
|
7976
|
+
}
|
|
7977
|
+
console.log(`${platform}: ${import_picocolors8.default.dim("not connected")}`);
|
|
7978
|
+
}
|
|
7979
|
+
});
|
|
7980
|
+
cmd.command("slack-channels").description("List Slack channels").option("--json", "Output as JSON").action(async (opts) => {
|
|
7981
|
+
const cfg = requireConfig5();
|
|
7982
|
+
const client = createTypedClient(cfg);
|
|
7983
|
+
const channels = await client.slackChannel.getAll.query(cfg.org_id);
|
|
7984
|
+
if (opts.json) {
|
|
7985
|
+
printResult(channels, opts);
|
|
7986
|
+
return;
|
|
7987
|
+
}
|
|
7988
|
+
if (!channels || channels.length === 0) {
|
|
7989
|
+
console.log(import_picocolors8.default.dim("No Slack channels found."));
|
|
7990
|
+
return;
|
|
7991
|
+
}
|
|
7992
|
+
printTable(["ID", "Name"], channels.map((c) => [c.channel_id, c.name ?? "(unnamed)"]), { rawData: channels });
|
|
7993
|
+
});
|
|
7994
|
+
cmd.command("slack-join").description("Join a Slack channel").argument("<channel-id>", "Slack channel ID").option("--json", "Output as JSON").action(async (channelId, opts) => {
|
|
7995
|
+
const cfg = requireConfig5();
|
|
7996
|
+
const client = createTypedClient(cfg);
|
|
7997
|
+
await client.slackChannel.join.mutate(channelId);
|
|
7998
|
+
if (opts.json) {
|
|
7999
|
+
printResult({ success: true, channelId }, opts);
|
|
8000
|
+
return;
|
|
8001
|
+
}
|
|
8002
|
+
console.log(import_picocolors8.default.green(`Joined Slack channel ${channelId}.`));
|
|
8003
|
+
});
|
|
8004
|
+
cmd.command("github-collaborators").description("List GitHub repository collaborators").option("--json", "Output as JSON").action(async (opts) => {
|
|
8005
|
+
const cfg = requireConfig5();
|
|
8006
|
+
const client = createTypedClient(cfg);
|
|
8007
|
+
const collaborators = await client.githubRepository.getCollaborators.query(0);
|
|
8008
|
+
if (opts.json) {
|
|
8009
|
+
printResult(collaborators, opts);
|
|
8010
|
+
return;
|
|
8011
|
+
}
|
|
8012
|
+
if (!collaborators || collaborators.length === 0) {
|
|
8013
|
+
console.log(import_picocolors8.default.dim("No collaborators found."));
|
|
8014
|
+
return;
|
|
8015
|
+
}
|
|
8016
|
+
printTable(["Username", "Name", "Email"], collaborators.map((c) => [c.user_name ?? "—", c.full_name ?? "—", c.email ?? "—"]), { rawData: collaborators });
|
|
8017
|
+
});
|
|
8018
|
+
return cmd;
|
|
8019
|
+
}
|
|
8020
|
+
|
|
8021
|
+
// src/commands/knowledge.ts
|
|
8022
|
+
var import_picocolors9 = __toESM(require_picocolors(), 1);
|
|
8023
|
+
function requireConfig6() {
|
|
8024
|
+
const cfg = requireLoginConfig();
|
|
8025
|
+
if (!cfg.org_id || !cfg.space_id) {
|
|
8026
|
+
console.error(import_picocolors9.default.red("Missing org/space config. Run 'dosu setup' to reconfigure."));
|
|
8027
|
+
process.exit(1);
|
|
8028
|
+
}
|
|
8029
|
+
return cfg;
|
|
8030
|
+
}
|
|
8031
|
+
function knowledgeCommand() {
|
|
8032
|
+
const cmd = new Command("knowledge").description("Search and browse your knowledge base");
|
|
8033
|
+
cmd.command("search").description("Search the knowledge base").argument("<query>", "Search query").option("--json", "Output as JSON").option("--limit <n>", "Maximum results", "10").action(async (query, opts) => {
|
|
8034
|
+
const cfg = requireConfig6();
|
|
8035
|
+
const client = createTypedClient(cfg);
|
|
8036
|
+
const dataSources = await client.dataSource.list.query({
|
|
8037
|
+
org_id: cfg.org_id,
|
|
8038
|
+
excluded_provider_slugs: []
|
|
8039
|
+
});
|
|
8040
|
+
const dataSourceIds = dataSources.map((ds) => ds.id);
|
|
8041
|
+
if (dataSourceIds.length === 0) {
|
|
8042
|
+
console.log(import_picocolors9.default.dim("No data sources connected. Add data sources in the Dosu dashboard."));
|
|
8043
|
+
return;
|
|
8044
|
+
}
|
|
8045
|
+
const data = await client.search.getMentions.query({
|
|
8046
|
+
query,
|
|
8047
|
+
dataSourceIds,
|
|
8048
|
+
entityTypes: []
|
|
8049
|
+
});
|
|
8050
|
+
const results = data.documents;
|
|
8051
|
+
if (opts.json) {
|
|
8052
|
+
printResult(data, opts);
|
|
8053
|
+
return;
|
|
8054
|
+
}
|
|
8055
|
+
if (!results || results.length === 0) {
|
|
8056
|
+
console.log(import_picocolors9.default.dim("No results found."));
|
|
8057
|
+
return;
|
|
8058
|
+
}
|
|
8059
|
+
const limit = Number.parseInt(opts.limit ?? "10", 10);
|
|
8060
|
+
const limited = results.slice(0, limit);
|
|
8061
|
+
printTable(["Title", "Type"], limited.map((r) => [truncate(r.title ?? "(untitled)", 60), r.entity_type ?? "—"]), { json: false, rawData: limited });
|
|
8062
|
+
if (results.length > limit) {
|
|
8063
|
+
console.log(import_picocolors9.default.dim(`
|
|
8064
|
+
${results.length - limit} more results not shown.`));
|
|
8065
|
+
}
|
|
8066
|
+
});
|
|
8067
|
+
cmd.command("list").description("Show knowledge store information").option("--json", "Output as JSON").action(async (opts) => {
|
|
8068
|
+
const cfg = requireConfig6();
|
|
8069
|
+
const client = createTypedClient(cfg);
|
|
8070
|
+
const store = await client.knowledgeStore.getBySpaceId.query({ space_id: cfg.space_id });
|
|
8071
|
+
if (opts.json) {
|
|
8072
|
+
printResult(store, opts);
|
|
8073
|
+
return;
|
|
8074
|
+
}
|
|
8075
|
+
if (!store) {
|
|
8076
|
+
console.log(import_picocolors9.default.dim("No knowledge store found for this deployment."));
|
|
8077
|
+
return;
|
|
8078
|
+
}
|
|
8079
|
+
console.log(import_picocolors9.default.bold("Knowledge Store"));
|
|
8080
|
+
console.log(` ID: ${store.id}`);
|
|
8081
|
+
console.log(` Space ID: ${store.space_id}`);
|
|
8082
|
+
});
|
|
8083
|
+
return cmd;
|
|
8084
|
+
}
|
|
8085
|
+
|
|
8086
|
+
// src/commands/members.ts
|
|
8087
|
+
var import_picocolors10 = __toESM(require_picocolors(), 1);
|
|
8088
|
+
function requireConfig7() {
|
|
8089
|
+
const cfg = requireLoginConfig();
|
|
8090
|
+
if (!cfg.org_id) {
|
|
8091
|
+
console.error(import_picocolors10.default.red("Missing org config. Run 'dosu setup' to reconfigure."));
|
|
8092
|
+
process.exit(1);
|
|
8093
|
+
}
|
|
8094
|
+
return cfg;
|
|
8095
|
+
}
|
|
8096
|
+
function membersCommand() {
|
|
8097
|
+
const cmd = new Command("members").description("Manage team members");
|
|
8098
|
+
cmd.command("list").description("List team members and invitations").option("--json", "Output as JSON").action(async (opts) => {
|
|
8099
|
+
const cfg = requireConfig7();
|
|
8100
|
+
const client = createTypedClient(cfg);
|
|
8101
|
+
const data = await client.invitations.getInvitations.query();
|
|
8102
|
+
if (opts.json) {
|
|
8103
|
+
printResult(data, opts);
|
|
8104
|
+
return;
|
|
8105
|
+
}
|
|
8106
|
+
if (!data.items || data.items.length === 0) {
|
|
8107
|
+
console.log(import_picocolors10.default.dim("No members or invitations found."));
|
|
8108
|
+
return;
|
|
8109
|
+
}
|
|
8110
|
+
printTable(["Email", "Org"], data.items.map((m) => [m.email ?? "—", m.org?.name ?? "—"]), { rawData: data });
|
|
8111
|
+
});
|
|
8112
|
+
cmd.command("invite").description("Invite a member to the organization").argument("<email>", "Email address to invite").option("--role <role>", "Role: admin or member", "member").option("--json", "Output as JSON").action(async (email, opts) => {
|
|
8113
|
+
const cfg = requireConfig7();
|
|
8114
|
+
const client = createTypedClient(cfg);
|
|
8115
|
+
const role = opts.role.toUpperCase() === "ADMIN" ? "ADMIN" : "MEMBER";
|
|
8116
|
+
await client.invitations.invite.mutate({
|
|
8117
|
+
orgId: cfg.org_id,
|
|
8118
|
+
email,
|
|
8119
|
+
role
|
|
8120
|
+
});
|
|
8121
|
+
if (opts.json) {
|
|
8122
|
+
printResult({ success: true, email, role }, opts);
|
|
8123
|
+
return;
|
|
8124
|
+
}
|
|
8125
|
+
console.log(import_picocolors10.default.green(`Invitation sent to ${email} as ${role}.`));
|
|
8126
|
+
});
|
|
8127
|
+
cmd.command("requests").description("List pending access requests").option("--json", "Output as JSON").action(async (opts) => {
|
|
8128
|
+
const cfg = requireConfig7();
|
|
8129
|
+
const client = createTypedClient(cfg);
|
|
8130
|
+
const data = await client.invitations.getInvitations.query();
|
|
8131
|
+
if (opts.json) {
|
|
8132
|
+
printResult(data, opts);
|
|
8133
|
+
return;
|
|
8134
|
+
}
|
|
8135
|
+
if (!data.items || data.items.length === 0) {
|
|
8136
|
+
console.log(import_picocolors10.default.dim("No pending access requests."));
|
|
8137
|
+
return;
|
|
8138
|
+
}
|
|
8139
|
+
printTable(["Email", "Org"], data.items.map((r) => [r.email ?? "—", r.org?.name ?? "—"]), { rawData: data });
|
|
8140
|
+
});
|
|
8141
|
+
cmd.command("approve").description("Approve an access request").argument("<email>", "Email of requester").option("--json", "Output as JSON").action(async (email, opts) => {
|
|
8142
|
+
const cfg = requireConfig7();
|
|
8143
|
+
const client = createTypedClient(cfg);
|
|
8144
|
+
await client.invitations.acceptInvitation.mutate({
|
|
8145
|
+
orgId: cfg.org_id,
|
|
8146
|
+
email
|
|
8147
|
+
});
|
|
8148
|
+
if (opts.json) {
|
|
8149
|
+
printResult({ success: true, email, action: "approved" }, opts);
|
|
8150
|
+
return;
|
|
8151
|
+
}
|
|
8152
|
+
console.log(import_picocolors10.default.green(`Access request from ${email} approved.`));
|
|
8153
|
+
});
|
|
8154
|
+
cmd.command("deny").description("Deny an access request").argument("<email>", "Email of requester").option("--json", "Output as JSON").action(async (email, opts) => {
|
|
8155
|
+
const cfg = requireConfig7();
|
|
8156
|
+
const client = createTypedClient(cfg);
|
|
8157
|
+
await client.invitations.rejectInvitation.mutate({
|
|
8158
|
+
orgId: cfg.org_id,
|
|
8159
|
+
email
|
|
8160
|
+
});
|
|
8161
|
+
if (opts.json) {
|
|
8162
|
+
printResult({ success: true, email, action: "denied" }, opts);
|
|
8163
|
+
return;
|
|
8164
|
+
}
|
|
8165
|
+
console.log(import_picocolors10.default.green(`Access request from ${email} denied.`));
|
|
8166
|
+
});
|
|
8167
|
+
return cmd;
|
|
8168
|
+
}
|
|
8169
|
+
|
|
8170
|
+
// src/commands/org.ts
|
|
8171
|
+
var import_picocolors11 = __toESM(require_picocolors(), 1);
|
|
8172
|
+
function requireConfig8() {
|
|
8173
|
+
return requireLoginConfig();
|
|
8174
|
+
}
|
|
8175
|
+
function orgCommand() {
|
|
8176
|
+
const cmd = new Command("org").description("Organization information");
|
|
8177
|
+
cmd.command("info").description("Show your organizations").option("--json", "Output as JSON").action(async (opts) => {
|
|
8178
|
+
const cfg = requireConfig8();
|
|
8179
|
+
const client = createTypedClient(cfg);
|
|
8180
|
+
const orgs = await client.organization.getOrganizations.query({});
|
|
8181
|
+
if (opts.json) {
|
|
8182
|
+
printResult(orgs, opts);
|
|
8183
|
+
return;
|
|
8184
|
+
}
|
|
8185
|
+
if (!orgs || orgs.length === 0) {
|
|
8186
|
+
console.log(import_picocolors11.default.dim("No organizations found."));
|
|
8187
|
+
return;
|
|
8188
|
+
}
|
|
8189
|
+
if (orgs.length === 1) {
|
|
8190
|
+
const org = orgs[0];
|
|
8191
|
+
printInfo([
|
|
8192
|
+
["Name", org.name],
|
|
8193
|
+
["ID", org.org_id]
|
|
8194
|
+
], { rawData: org });
|
|
8195
|
+
return;
|
|
8196
|
+
}
|
|
8197
|
+
printTable(["ID", "Name"], orgs.map((o) => [o.org_id.slice(0, 8), o.name]), { rawData: orgs });
|
|
8198
|
+
if (cfg.org_id) {
|
|
8199
|
+
console.log(`
|
|
8200
|
+
${import_picocolors11.default.dim(`Current: ${cfg.org_id}`)}`);
|
|
8201
|
+
}
|
|
8202
|
+
});
|
|
8203
|
+
return cmd;
|
|
8204
|
+
}
|
|
8205
|
+
|
|
8206
|
+
// src/commands/review.ts
|
|
8207
|
+
var import_picocolors12 = __toESM(require_picocolors(), 1);
|
|
8208
|
+
function requireConfig9() {
|
|
8209
|
+
return requireLoginConfig();
|
|
8210
|
+
}
|
|
8211
|
+
function reviewCommand() {
|
|
8212
|
+
const cmd = new Command("review").description("Document review workflow");
|
|
8213
|
+
cmd.command("context").description("Get review context for a thread").argument("<thread-id>", "Thread ID").option("--json", "Output as JSON").action(async (threadId, opts) => {
|
|
8214
|
+
const cfg = requireConfig9();
|
|
8215
|
+
const client = createTypedClient(cfg);
|
|
8216
|
+
const context = await client.review.getThreadContext.query({
|
|
8217
|
+
thread_id: threadId
|
|
8218
|
+
});
|
|
8219
|
+
if (opts.json) {
|
|
8220
|
+
printResult(context, opts);
|
|
8221
|
+
return;
|
|
8222
|
+
}
|
|
8223
|
+
const ctx = context;
|
|
8224
|
+
const reviewPage = ctx.reviewPage;
|
|
8225
|
+
const publishedPage = ctx.publishedPage;
|
|
8226
|
+
printInfo([
|
|
8227
|
+
["Type", context.type],
|
|
8228
|
+
["Page ID", ctx.pageId],
|
|
8229
|
+
["Review Page", reviewPage?.title ?? reviewPage?.id],
|
|
8230
|
+
["Published Page", publishedPage?.title ?? publishedPage?.id],
|
|
8231
|
+
["Sync PR", ctx.syncPrUrl ?? undefined]
|
|
8232
|
+
]);
|
|
8233
|
+
});
|
|
8234
|
+
const actions = [
|
|
8235
|
+
{ name: "approve", action: "accept", description: "Approve a document version" },
|
|
8236
|
+
{ name: "reject", action: "decline", description: "Reject a document version" },
|
|
8237
|
+
{
|
|
8238
|
+
name: "revert",
|
|
8239
|
+
action: "revert_to_pending",
|
|
8240
|
+
description: "Revert to pending review"
|
|
8241
|
+
}
|
|
8242
|
+
];
|
|
8243
|
+
for (const { name, action, description } of actions) {
|
|
8244
|
+
cmd.command(name).description(description).argument("<page-version-id>", "Page version ID").option("--json", "Output as JSON").action(async (pageVersionId, opts) => {
|
|
8245
|
+
const cfg = requireConfig9();
|
|
8246
|
+
const client = createTypedClient(cfg);
|
|
8247
|
+
await client.page.updatePublicationStatus.mutate({
|
|
8248
|
+
page_version_id: pageVersionId,
|
|
8249
|
+
action
|
|
8250
|
+
});
|
|
8251
|
+
if (opts.json) {
|
|
8252
|
+
printResult({ success: true, page_version_id: pageVersionId, action }, opts);
|
|
8253
|
+
return;
|
|
8254
|
+
}
|
|
8255
|
+
console.log(import_picocolors12.default.green(`Review ${name}: ${pageVersionId.slice(0, 8)}`));
|
|
8256
|
+
});
|
|
8257
|
+
}
|
|
8258
|
+
return cmd;
|
|
8259
|
+
}
|
|
8260
|
+
|
|
8261
|
+
// src/commands/skill.ts
|
|
8262
|
+
import { execSync } from "node:child_process";
|
|
8263
|
+
var import_picocolors13 = __toESM(require_picocolors(), 1);
|
|
8264
|
+
var SKILL_REPO = "dosu-ai/dosu-skill";
|
|
8265
|
+
var SKILL_NAME = "dosu";
|
|
8266
|
+
function skillCommand() {
|
|
8267
|
+
const cmd = new Command("skill").description("Manage the Dosu agent skill");
|
|
8268
|
+
cmd.command("install").description("Install the Dosu skill for AI coding agents").action(() => {
|
|
8269
|
+
console.log(`Installing ${SKILL_NAME} skill from ${SKILL_REPO}...`);
|
|
8270
|
+
try {
|
|
8271
|
+
execSync(`npx skills add ${SKILL_REPO} -g -s ${SKILL_NAME} -y`, {
|
|
8272
|
+
stdio: "inherit"
|
|
8273
|
+
});
|
|
8274
|
+
console.log(import_picocolors13.default.green(`
|
|
8275
|
+
✓ Skill "${SKILL_NAME}" installed successfully.`));
|
|
8276
|
+
} catch {
|
|
8277
|
+
console.error(import_picocolors13.default.red(`
|
|
8278
|
+
Failed to install skill. Make sure npx is available.`));
|
|
8279
|
+
process.exit(1);
|
|
8280
|
+
}
|
|
8281
|
+
});
|
|
8282
|
+
cmd.command("remove").description("Remove the Dosu skill").action(() => {
|
|
8283
|
+
console.log(`Removing ${SKILL_NAME} skill...`);
|
|
8284
|
+
try {
|
|
8285
|
+
execSync(`npx skills remove -g -s ${SKILL_NAME} -y`, {
|
|
8286
|
+
stdio: "inherit"
|
|
8287
|
+
});
|
|
8288
|
+
console.log(import_picocolors13.default.green(`
|
|
8289
|
+
✓ Skill "${SKILL_NAME}" removed.`));
|
|
8290
|
+
} catch {
|
|
8291
|
+
console.error(import_picocolors13.default.red(`
|
|
8292
|
+
Failed to remove skill.`));
|
|
8293
|
+
process.exit(1);
|
|
8294
|
+
}
|
|
8295
|
+
});
|
|
8296
|
+
cmd.command("update").description("Update the Dosu skill to the latest version").action(() => {
|
|
8297
|
+
console.log(`Updating ${SKILL_NAME} skill...`);
|
|
8298
|
+
try {
|
|
8299
|
+
execSync(`npx skills update ${SKILL_NAME} -g`, {
|
|
8300
|
+
stdio: "inherit"
|
|
8301
|
+
});
|
|
8302
|
+
console.log(import_picocolors13.default.green(`
|
|
8303
|
+
✓ Skill "${SKILL_NAME}" updated.`));
|
|
8304
|
+
} catch {
|
|
8305
|
+
console.error(import_picocolors13.default.red(`
|
|
8306
|
+
Failed to update skill.`));
|
|
8307
|
+
process.exit(1);
|
|
8308
|
+
}
|
|
8309
|
+
});
|
|
8310
|
+
return cmd;
|
|
8311
|
+
}
|
|
8312
|
+
|
|
8313
|
+
// src/commands/sources.ts
|
|
8314
|
+
var import_picocolors14 = __toESM(require_picocolors(), 1);
|
|
8315
|
+
function requireConfig10() {
|
|
8316
|
+
const cfg = requireLoginConfig();
|
|
8317
|
+
if (!cfg.org_id) {
|
|
8318
|
+
console.error(import_picocolors14.default.red("Missing org config. Run 'dosu setup' to reconfigure."));
|
|
8319
|
+
process.exit(1);
|
|
8320
|
+
}
|
|
8321
|
+
return cfg;
|
|
8322
|
+
}
|
|
8323
|
+
function sourcesCommand() {
|
|
8324
|
+
const cmd = new Command("sources").description("Manage connected data sources");
|
|
8325
|
+
cmd.command("list").description("List all connected data sources").option("--json", "Output as JSON").action(async (opts) => {
|
|
8326
|
+
const cfg = requireConfig10();
|
|
8327
|
+
const client = createTypedClient(cfg);
|
|
8328
|
+
const dataSources = await client.dataSource.list.query({
|
|
8329
|
+
org_id: cfg.org_id,
|
|
8330
|
+
excluded_provider_slugs: []
|
|
8331
|
+
});
|
|
8332
|
+
if (opts.json) {
|
|
8333
|
+
printResult(dataSources, opts);
|
|
8334
|
+
return;
|
|
8335
|
+
}
|
|
8336
|
+
const list = dataSources ?? [];
|
|
8337
|
+
if (list.length === 0) {
|
|
8338
|
+
console.log(import_picocolors14.default.dim("No data sources connected."));
|
|
8339
|
+
return;
|
|
8340
|
+
}
|
|
8341
|
+
printTable(["ID", "Name", "Provider", "Created"], list.map((ds) => [
|
|
8342
|
+
ds.id.slice(0, 8),
|
|
8343
|
+
ds.name ?? "(unnamed)",
|
|
8344
|
+
ds.provider_slug ?? "—",
|
|
8345
|
+
formatDate(ds.created_at)
|
|
8346
|
+
]), { rawData: list });
|
|
8347
|
+
});
|
|
8348
|
+
cmd.command("info").description("Show details of a data source").argument("<id>", "Data source ID").option("--json", "Output as JSON").action(async (id, opts) => {
|
|
8349
|
+
const cfg = requireConfig10();
|
|
8350
|
+
const client = createTypedClient(cfg);
|
|
8351
|
+
const ds = await client.dataSource.get.query(id);
|
|
8352
|
+
if (opts.json) {
|
|
8353
|
+
printResult(ds, opts);
|
|
8354
|
+
return;
|
|
8355
|
+
}
|
|
8356
|
+
if (!ds) {
|
|
8357
|
+
console.log(import_picocolors14.default.dim("Data source not found."));
|
|
8358
|
+
return;
|
|
8359
|
+
}
|
|
8360
|
+
printInfo([
|
|
8361
|
+
["ID", ds.id],
|
|
8362
|
+
["Name", ds.name],
|
|
8363
|
+
["Description", ds.description],
|
|
8364
|
+
["Provider", ds.provider_slug],
|
|
8365
|
+
["Created", formatDate(ds.created_at)]
|
|
8366
|
+
], { rawData: ds });
|
|
8367
|
+
});
|
|
8368
|
+
cmd.command("sync").description("Trigger a data source sync").argument("<id>", "Data source ID").option("--json", "Output as JSON").action(async (id, opts) => {
|
|
8369
|
+
const cfg = requireConfig10();
|
|
8370
|
+
const client = createTypedClient(cfg);
|
|
8371
|
+
await client.dataSource.syncDataSource.mutate(id);
|
|
8372
|
+
if (opts.json) {
|
|
8373
|
+
printResult({ success: true, id }, opts);
|
|
8374
|
+
return;
|
|
8375
|
+
}
|
|
8376
|
+
console.log(import_picocolors14.default.green(`Data source sync triggered for ${id.slice(0, 8)}.`));
|
|
8377
|
+
});
|
|
8378
|
+
cmd.command("update").description("Update a data source").argument("<id>", "Data source ID").option("--name <name>", "New name").option("--description <desc>", "New description").option("--json", "Output as JSON").action(async (id, opts) => {
|
|
8379
|
+
const cfg = requireConfig10();
|
|
8380
|
+
const client = createTypedClient(cfg);
|
|
8381
|
+
const result = await client.dataSource.update.mutate({
|
|
8382
|
+
data_source_id: id,
|
|
8383
|
+
name: opts.name,
|
|
8384
|
+
description: opts.description
|
|
8385
|
+
});
|
|
8386
|
+
if (opts.json) {
|
|
8387
|
+
printResult(result, opts);
|
|
8388
|
+
return;
|
|
8389
|
+
}
|
|
8390
|
+
console.log(import_picocolors14.default.green("Data source updated."));
|
|
8391
|
+
});
|
|
8392
|
+
cmd.command("delete").description("Delete a data source").argument("<id>", "Data source ID").option("--json", "Output as JSON").action(async (id, opts) => {
|
|
8393
|
+
const cfg = requireConfig10();
|
|
8394
|
+
const client = createTypedClient(cfg);
|
|
8395
|
+
await client.dataSource.deleteDataSource.mutate(id);
|
|
8396
|
+
if (opts.json) {
|
|
8397
|
+
printResult({ success: true, id }, opts);
|
|
8398
|
+
return;
|
|
8399
|
+
}
|
|
8400
|
+
console.log(import_picocolors14.default.green("Data source deleted."));
|
|
8401
|
+
});
|
|
8402
|
+
return cmd;
|
|
8403
|
+
}
|
|
8404
|
+
|
|
8405
|
+
// src/commands/suggest.ts
|
|
8406
|
+
var import_picocolors15 = __toESM(require_picocolors(), 1);
|
|
8407
|
+
function requireConfig11() {
|
|
8408
|
+
const cfg = requireLoginConfig();
|
|
8409
|
+
if (!cfg.space_id) {
|
|
8410
|
+
console.error(import_picocolors15.default.red("Missing space config. Run 'dosu setup' to reconfigure."));
|
|
8411
|
+
process.exit(1);
|
|
8412
|
+
}
|
|
8413
|
+
return cfg;
|
|
8414
|
+
}
|
|
8415
|
+
async function getKnowledgeStoreId2(client, spaceId) {
|
|
8416
|
+
const store = await client.knowledgeStore.getBySpaceId.query({
|
|
8417
|
+
space_id: spaceId
|
|
8418
|
+
});
|
|
8419
|
+
if (!store) {
|
|
8420
|
+
console.error(import_picocolors15.default.red("No knowledge store found for this deployment."));
|
|
8421
|
+
process.exit(1);
|
|
8422
|
+
}
|
|
8423
|
+
return store.id;
|
|
8424
|
+
}
|
|
8425
|
+
function suggestCommand() {
|
|
8426
|
+
const cmd = new Command("suggest").description("AI document suggestions");
|
|
8427
|
+
cmd.command("list").description("List pending document suggestions").option("--json", "Output as JSON").action(async (opts) => {
|
|
8428
|
+
const cfg = requireConfig11();
|
|
8429
|
+
const client = createTypedClient(cfg);
|
|
8430
|
+
const ksId = await getKnowledgeStoreId2(client, cfg.space_id);
|
|
8431
|
+
const suggestions = await client.suggestedDoc.listForKnowledgeStore.query({
|
|
8432
|
+
knowledgeStoreId: ksId
|
|
8433
|
+
});
|
|
8434
|
+
if (opts.json) {
|
|
8435
|
+
printResult(suggestions, opts);
|
|
8436
|
+
return;
|
|
8437
|
+
}
|
|
8438
|
+
if (!suggestions || suggestions.length === 0) {
|
|
8439
|
+
console.log(import_picocolors15.default.dim("No pending suggestions."));
|
|
8440
|
+
return;
|
|
8441
|
+
}
|
|
8442
|
+
printTable(["ID", "Title"], suggestions.map((s) => [
|
|
8443
|
+
s.id.slice(0, 8),
|
|
8444
|
+
s.title ?? "(untitled)"
|
|
8445
|
+
]), { rawData: suggestions });
|
|
8446
|
+
});
|
|
8447
|
+
cmd.command("generate").description("Generate new document suggestions from data sources").option("--json", "Output as JSON").action(async (opts) => {
|
|
8448
|
+
const cfg = requireConfig11();
|
|
8449
|
+
const client = createTypedClient(cfg);
|
|
8450
|
+
const ksId = await getKnowledgeStoreId2(client, cfg.space_id);
|
|
8451
|
+
if (!cfg.org_id) {
|
|
8452
|
+
console.error(import_picocolors15.default.red("Missing org config. Run 'dosu setup' to reconfigure."));
|
|
8453
|
+
process.exit(1);
|
|
8454
|
+
}
|
|
8455
|
+
const dataSources = await client.dataSource.list.query({
|
|
8456
|
+
org_id: cfg.org_id,
|
|
8457
|
+
excluded_provider_slugs: []
|
|
8458
|
+
});
|
|
8459
|
+
const dataSourceIds = dataSources.map((ds) => ds.id);
|
|
8460
|
+
const result = await client.suggestedDoc.generate.mutate({
|
|
8461
|
+
knowledgeStoreId: ksId,
|
|
8462
|
+
dataSourceIds
|
|
8463
|
+
});
|
|
8464
|
+
if (opts.json) {
|
|
8465
|
+
printResult(result, opts);
|
|
8466
|
+
return;
|
|
8467
|
+
}
|
|
8468
|
+
console.log(import_picocolors15.default.green("Document suggestions are being generated."));
|
|
8469
|
+
});
|
|
8470
|
+
cmd.command("accept").description("Accept a suggestion and create a document").argument("<id>", "Suggestion ID").option("--title <title>", "Custom title for the document").option("--instructions <text>", "Custom instructions for generation").option("--json", "Output as JSON").action(async (id, opts) => {
|
|
8471
|
+
const cfg = requireConfig11();
|
|
8472
|
+
const client = createTypedClient(cfg);
|
|
8473
|
+
const ksId = await getKnowledgeStoreId2(client, cfg.space_id);
|
|
8474
|
+
const result = await client.suggestedDoc.generateDocBySuggestedDocId.mutate({
|
|
8475
|
+
knowledgeStoreId: ksId,
|
|
8476
|
+
suggestedDocId: id,
|
|
8477
|
+
title: opts.title,
|
|
8478
|
+
instructions: opts.instructions
|
|
8479
|
+
});
|
|
8480
|
+
if (opts.json) {
|
|
8481
|
+
printResult(result, opts);
|
|
8482
|
+
return;
|
|
8483
|
+
}
|
|
8484
|
+
console.log(import_picocolors15.default.green("Document created from suggestion."));
|
|
8485
|
+
});
|
|
8486
|
+
cmd.command("reject").description("Reject a suggestion").argument("<id>", "Suggestion ID").option("--json", "Output as JSON").action(async (id, opts) => {
|
|
8487
|
+
const cfg = requireConfig11();
|
|
8488
|
+
const client = createTypedClient(cfg);
|
|
8489
|
+
await client.suggestedDoc.delete.mutate({ id });
|
|
8490
|
+
if (opts.json) {
|
|
8491
|
+
printResult({ success: true, id }, opts);
|
|
8492
|
+
return;
|
|
8493
|
+
}
|
|
8494
|
+
console.log(import_picocolors15.default.green("Suggestion rejected."));
|
|
8495
|
+
});
|
|
8496
|
+
return cmd;
|
|
8497
|
+
}
|
|
8498
|
+
|
|
8499
|
+
// src/commands/tags.ts
|
|
8500
|
+
var import_picocolors16 = __toESM(require_picocolors(), 1);
|
|
8501
|
+
function requireConfig12() {
|
|
8502
|
+
const cfg = requireLoginConfig();
|
|
8503
|
+
if (!cfg.space_id) {
|
|
8504
|
+
console.error(import_picocolors16.default.red("Missing space config. Run 'dosu setup' to reconfigure."));
|
|
8505
|
+
process.exit(1);
|
|
8506
|
+
}
|
|
8507
|
+
return cfg;
|
|
8508
|
+
}
|
|
8509
|
+
async function getKnowledgeStoreId3(client, spaceId) {
|
|
8510
|
+
const store = await client.knowledgeStore.getBySpaceId.query({
|
|
8511
|
+
space_id: spaceId
|
|
8512
|
+
});
|
|
8513
|
+
if (!store) {
|
|
8514
|
+
console.error(import_picocolors16.default.red("No knowledge store found for this deployment."));
|
|
8515
|
+
process.exit(1);
|
|
8516
|
+
}
|
|
8517
|
+
return store.id;
|
|
8518
|
+
}
|
|
8519
|
+
function tagsCommand() {
|
|
8520
|
+
const cmd = new Command("tags").description("Manage knowledge base tags");
|
|
8521
|
+
cmd.command("list").description("List all tags").option("--search <query>", "Search tags by name").option("--json", "Output as JSON").action(async (opts) => {
|
|
8522
|
+
const cfg = requireConfig12();
|
|
8523
|
+
const client = createTypedClient(cfg);
|
|
8524
|
+
const ksId = await getKnowledgeStoreId3(client, cfg.space_id);
|
|
8525
|
+
let tags;
|
|
8526
|
+
if (opts.search) {
|
|
8527
|
+
const result = await client.tag.listKnowledgeStoreTagsWithPagination.query({
|
|
8528
|
+
knowledge_store_id: ksId,
|
|
8529
|
+
searchTerm: opts.search
|
|
8530
|
+
});
|
|
8531
|
+
tags = result.data;
|
|
8532
|
+
} else {
|
|
8533
|
+
tags = await client.tag.listKnowledgeStoreTags.query({
|
|
8534
|
+
knowledge_store_id: ksId
|
|
8535
|
+
});
|
|
8536
|
+
}
|
|
8537
|
+
if (opts.json) {
|
|
8538
|
+
printResult(tags, opts);
|
|
8539
|
+
return;
|
|
8540
|
+
}
|
|
8541
|
+
if (!tags || tags.length === 0) {
|
|
8542
|
+
console.log(import_picocolors16.default.dim("No tags found."));
|
|
8543
|
+
return;
|
|
8544
|
+
}
|
|
8545
|
+
printTable(["ID", "Name", "Description"], tags.map((t) => [t.id.slice(0, 8), t.name, t.description ?? "—"]), { rawData: tags });
|
|
8546
|
+
});
|
|
8547
|
+
cmd.command("create").description("Create a new tag").requiredOption("--name <name>", "Tag name").option("--description <desc>", "Tag description").option("--json", "Output as JSON").action(async (opts) => {
|
|
8548
|
+
const cfg = requireConfig12();
|
|
8549
|
+
const client = createTypedClient(cfg);
|
|
8550
|
+
const ksId = await getKnowledgeStoreId3(client, cfg.space_id);
|
|
8551
|
+
const result = await client.tag.create.mutate({
|
|
8552
|
+
knowledge_store_id: ksId,
|
|
8553
|
+
name: opts.name,
|
|
8554
|
+
description: opts.description ?? ""
|
|
8555
|
+
});
|
|
8556
|
+
if (opts.json) {
|
|
8557
|
+
printResult(result, opts);
|
|
8558
|
+
return;
|
|
8559
|
+
}
|
|
8560
|
+
console.log(import_picocolors16.default.green(`Tag "${opts.name}" created.`));
|
|
8561
|
+
});
|
|
8562
|
+
cmd.command("update").description("Update a tag").argument("<id>", "Tag ID").requiredOption("--name <name>", "New tag name").option("--description <desc>", "New description").option("--json", "Output as JSON").action(async (id, opts) => {
|
|
8563
|
+
const cfg = requireConfig12();
|
|
8564
|
+
const client = createTypedClient(cfg);
|
|
8565
|
+
const ksId = await getKnowledgeStoreId3(client, cfg.space_id);
|
|
8566
|
+
const result = await client.tag.update.mutate({
|
|
8567
|
+
id,
|
|
8568
|
+
knowledge_store_id: ksId,
|
|
8569
|
+
name: opts.name,
|
|
8570
|
+
description: opts.description
|
|
8571
|
+
});
|
|
8572
|
+
if (opts.json) {
|
|
8573
|
+
printResult(result, opts);
|
|
8574
|
+
return;
|
|
8575
|
+
}
|
|
8576
|
+
console.log(import_picocolors16.default.green(`Tag updated.`));
|
|
8577
|
+
});
|
|
8578
|
+
cmd.command("delete").description("Delete a tag").argument("<id>", "Tag ID").option("--json", "Output as JSON").action(async (id, opts) => {
|
|
8579
|
+
const cfg = requireConfig12();
|
|
8580
|
+
const client = createTypedClient(cfg);
|
|
8581
|
+
await client.tag.delete.mutate(id);
|
|
8582
|
+
if (opts.json) {
|
|
8583
|
+
printResult({ success: true, id }, opts);
|
|
8584
|
+
return;
|
|
8585
|
+
}
|
|
8586
|
+
console.log(import_picocolors16.default.green("Tag deleted."));
|
|
8587
|
+
});
|
|
8588
|
+
cmd.command("add").description("Add a tag to a page").argument("<tag-id>", "Tag ID").argument("<page-id>", "Page ID").option("--json", "Output as JSON").action(async (tagId, pageId, opts) => {
|
|
8589
|
+
const cfg = requireConfig12();
|
|
8590
|
+
const client = createTypedClient(cfg);
|
|
8591
|
+
await client.tag.addToPage.mutate({ tag_id: tagId, page_id: pageId });
|
|
8592
|
+
if (opts.json) {
|
|
8593
|
+
printResult({ success: true, tag_id: tagId, page_id: pageId }, opts);
|
|
8594
|
+
return;
|
|
8595
|
+
}
|
|
8596
|
+
console.log(import_picocolors16.default.green("Tag added to page."));
|
|
8597
|
+
});
|
|
8598
|
+
cmd.command("remove").description("Remove a tag from a page").argument("<tag-id>", "Tag ID").argument("<page-id>", "Page ID").option("--json", "Output as JSON").action(async (tagId, pageId, opts) => {
|
|
8599
|
+
const cfg = requireConfig12();
|
|
8600
|
+
const client = createTypedClient(cfg);
|
|
8601
|
+
await client.tag.removeFromPage.mutate({ tag_id: tagId, page_id: pageId });
|
|
8602
|
+
if (opts.json) {
|
|
8603
|
+
printResult({ success: true, tag_id: tagId, page_id: pageId }, opts);
|
|
8604
|
+
return;
|
|
8605
|
+
}
|
|
8606
|
+
console.log(import_picocolors16.default.green("Tag removed from page."));
|
|
8607
|
+
});
|
|
8608
|
+
cmd.command("pages").description("List pages with a specific tag").argument("<tag-id>", "Tag ID").option("--search <query>", "Search within tagged pages").option("--limit <n>", "Maximum results", "10").option("--json", "Output as JSON").action(async (tagId, opts) => {
|
|
8609
|
+
const cfg = requireConfig12();
|
|
8610
|
+
const client = createTypedClient(cfg);
|
|
8611
|
+
const ksId = await getKnowledgeStoreId3(client, cfg.space_id);
|
|
8612
|
+
const result = await client.tag.getPagesByTagId.query({
|
|
8613
|
+
knowledge_store_id: ksId,
|
|
8614
|
+
tag_id: tagId,
|
|
8615
|
+
searchTerm: opts.search,
|
|
8616
|
+
limit: Number.parseInt(opts.limit ?? "10", 10)
|
|
8617
|
+
});
|
|
8618
|
+
const pages = result.data;
|
|
8619
|
+
if (opts.json) {
|
|
8620
|
+
printResult(pages, opts);
|
|
8621
|
+
return;
|
|
8622
|
+
}
|
|
8623
|
+
if (!pages || pages.length === 0) {
|
|
8624
|
+
console.log(import_picocolors16.default.dim("No pages found with this tag."));
|
|
8625
|
+
return;
|
|
8626
|
+
}
|
|
8627
|
+
printTable(["ID", "Title"], pages.map((p) => [
|
|
8628
|
+
p.id.slice(0, 8),
|
|
8629
|
+
p.title ?? "(untitled)"
|
|
8630
|
+
]), { rawData: pages });
|
|
8631
|
+
});
|
|
8632
|
+
return cmd;
|
|
8633
|
+
}
|
|
8634
|
+
|
|
8635
|
+
// src/commands/threads.ts
|
|
8636
|
+
var import_picocolors17 = __toESM(require_picocolors(), 1);
|
|
8637
|
+
function requireConfig13() {
|
|
8638
|
+
const cfg = requireLoginConfig();
|
|
8639
|
+
if (!cfg.space_id) {
|
|
8640
|
+
console.error(import_picocolors17.default.red("Missing space config. Run 'dosu setup' to reconfigure."));
|
|
8641
|
+
process.exit(1);
|
|
8642
|
+
}
|
|
8643
|
+
return cfg;
|
|
8644
|
+
}
|
|
8645
|
+
function threadsCommand() {
|
|
8646
|
+
const cmd = new Command("threads").description("List and manage conversation threads");
|
|
8647
|
+
cmd.command("list").description("List threads").option("--status <status>", "Filter by status: pending, resolved, archived").option("--search <query>", "Search threads").option("--limit <n>", "Maximum results (default: 20)", "20").option("--json", "Output as JSON").action(async (opts) => {
|
|
8648
|
+
const cfg = requireConfig13();
|
|
8649
|
+
const client = createTypedClient(cfg);
|
|
8650
|
+
const input = {
|
|
8651
|
+
space_id: cfg.space_id,
|
|
8652
|
+
limit: Math.min(Number.parseInt(opts.limit ?? "20", 10), 100)
|
|
8653
|
+
};
|
|
8654
|
+
if (opts.search)
|
|
8655
|
+
input.search = opts.search;
|
|
8656
|
+
if (opts.status === "resolved")
|
|
8657
|
+
input.resolved = true;
|
|
8658
|
+
if (opts.status === "archived")
|
|
8659
|
+
input.archived = true;
|
|
8660
|
+
if (opts.status === "pending") {
|
|
8661
|
+
input.resolved = false;
|
|
8662
|
+
input.archived = false;
|
|
8663
|
+
}
|
|
8664
|
+
const data = await client.thread.list.query(input);
|
|
8665
|
+
const threads = data.list;
|
|
8666
|
+
if (opts.json) {
|
|
8667
|
+
printResult(data, opts);
|
|
8668
|
+
return;
|
|
8669
|
+
}
|
|
8670
|
+
if (!threads || threads.length === 0) {
|
|
8671
|
+
console.log(import_picocolors17.default.dim("No threads found."));
|
|
8672
|
+
return;
|
|
8673
|
+
}
|
|
8674
|
+
printTable(["ID", "Title", "Status", "Created"], threads.map((t) => [
|
|
8675
|
+
t.id.slice(0, 8),
|
|
8676
|
+
truncate(t.generated_title ?? t.initial_message_title ?? "(no title)", 50),
|
|
8677
|
+
t.resolved ? "resolved" : t.inbox_archived_at ? "archived" : "pending",
|
|
8678
|
+
formatDate(t.created_at)
|
|
8679
|
+
]), { rawData: threads });
|
|
8680
|
+
});
|
|
8681
|
+
cmd.command("get").description("View a thread and its messages").argument("<id>", "Thread ID").option("--limit <n>", "Number of messages to show (default: 20)", "20").option("--json", "Output as JSON").action(async (id, opts) => {
|
|
8682
|
+
const cfg = requireConfig13();
|
|
8683
|
+
const client = createTypedClient(cfg);
|
|
8684
|
+
const [thread, messagesData] = await Promise.all([
|
|
8685
|
+
client.thread.get.query(id),
|
|
8686
|
+
client.messages.list.query({
|
|
8687
|
+
thread_id: id,
|
|
8688
|
+
limit: Number.parseInt(opts.limit ?? "20", 10)
|
|
8689
|
+
})
|
|
8690
|
+
]);
|
|
8691
|
+
if (opts.json) {
|
|
8692
|
+
printResult({ thread, messages: messagesData }, opts);
|
|
8693
|
+
return;
|
|
8694
|
+
}
|
|
8695
|
+
if (!thread) {
|
|
8696
|
+
console.log(import_picocolors17.default.dim("Thread not found."));
|
|
8697
|
+
return;
|
|
8698
|
+
}
|
|
8699
|
+
console.log(import_picocolors17.default.bold(thread.generated_title ?? "(untitled thread)"));
|
|
8700
|
+
printInfo([
|
|
8701
|
+
["ID", thread.id],
|
|
8702
|
+
["Created", formatDate(thread.created_at)],
|
|
8703
|
+
["Status", thread.resolved ? "resolved" : "pending"],
|
|
8704
|
+
["Channel", thread.channel]
|
|
8705
|
+
]);
|
|
8706
|
+
const messages = messagesData.list;
|
|
8707
|
+
if (messages && messages.length > 0) {
|
|
8708
|
+
const allMessages = messages.flatMap((group) => group.messages);
|
|
8709
|
+
console.log(`
|
|
8710
|
+
${import_picocolors17.default.bold("Messages")} (${allMessages.length})`);
|
|
8711
|
+
console.log(import_picocolors17.default.dim("─".repeat(60)));
|
|
8712
|
+
for (const msg of allMessages) {
|
|
8713
|
+
const role = msg.author_role ?? "unknown";
|
|
8714
|
+
const date = formatDate(msg.created_at);
|
|
8715
|
+
console.log(`
|
|
8716
|
+
${import_picocolors17.default.bold(role)} ${import_picocolors17.default.dim(date)}`);
|
|
8717
|
+
if (msg.body) {
|
|
8718
|
+
console.log(truncate(msg.body, 500));
|
|
8719
|
+
}
|
|
8720
|
+
}
|
|
8721
|
+
}
|
|
8722
|
+
});
|
|
8723
|
+
cmd.command("archive").description("Archive a thread").argument("<id>", "Thread ID").option("--json", "Output as JSON").action(async (id, opts) => {
|
|
8724
|
+
const cfg = requireConfig13();
|
|
8725
|
+
const client = createTypedClient(cfg);
|
|
8726
|
+
await client.thread.archive.mutate({ threadId: id, archived: true });
|
|
8727
|
+
if (opts.json) {
|
|
8728
|
+
printResult({ success: true, id }, opts);
|
|
8729
|
+
return;
|
|
8730
|
+
}
|
|
8731
|
+
console.log(import_picocolors17.default.green(`Thread ${id.slice(0, 8)} archived.`));
|
|
8732
|
+
});
|
|
8733
|
+
return cmd;
|
|
8734
|
+
}
|
|
8735
|
+
|
|
8736
|
+
// src/cli/cli.ts
|
|
8737
|
+
init_config();
|
|
8738
|
+
init_logger();
|
|
8739
|
+
init_providers();
|
|
8740
|
+
|
|
8741
|
+
// src/version/update-check.ts
|
|
8742
|
+
init_config();
|
|
8743
|
+
init_logger();
|
|
8744
|
+
var import_picocolors18 = __toESM(require_picocolors(), 1);
|
|
8745
|
+
import { existsSync as existsSync7, mkdirSync as mkdirSync5, readFileSync as readFileSync6, writeFileSync as writeFileSync5 } from "node:fs";
|
|
8746
|
+
import { join as join17 } from "node:path";
|
|
8747
|
+
var CACHE_FILENAME = "update-check.json";
|
|
8748
|
+
var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000;
|
|
8749
|
+
var FETCH_TIMEOUT_MS = 5000;
|
|
8750
|
+
var REGISTRY_URL = "https://registry.npmjs.org/-/package/@dosu/cli/dist-tags";
|
|
8751
|
+
function stripPrerelease(version) {
|
|
8752
|
+
return version.replace(/[-+].*$/, "");
|
|
8753
|
+
}
|
|
8754
|
+
function isNewerVersion(latest, current) {
|
|
8755
|
+
const a = stripPrerelease(latest).split(".").map(Number);
|
|
8756
|
+
const b = stripPrerelease(current).split(".").map(Number);
|
|
8757
|
+
const len = Math.max(a.length, b.length);
|
|
8758
|
+
for (let i = 0;i < len; i++) {
|
|
8759
|
+
const av = a[i] ?? 0;
|
|
8760
|
+
const bv = b[i] ?? 0;
|
|
8761
|
+
if (av > bv)
|
|
8762
|
+
return true;
|
|
8763
|
+
if (av < bv)
|
|
8764
|
+
return false;
|
|
8765
|
+
}
|
|
8766
|
+
return false;
|
|
8767
|
+
}
|
|
8768
|
+
function getCachePath() {
|
|
8769
|
+
return join17(getConfigDir(), CACHE_FILENAME);
|
|
8770
|
+
}
|
|
8771
|
+
function readCache() {
|
|
8772
|
+
try {
|
|
8773
|
+
const path = getCachePath();
|
|
8774
|
+
if (!existsSync7(path))
|
|
8775
|
+
return null;
|
|
8776
|
+
const data = JSON.parse(readFileSync6(path, "utf-8"));
|
|
8777
|
+
if (typeof data.lastCheck === "number" && typeof data.latestVersion === "string") {
|
|
8778
|
+
return data;
|
|
8779
|
+
}
|
|
8780
|
+
return null;
|
|
8781
|
+
} catch {
|
|
8782
|
+
return null;
|
|
8783
|
+
}
|
|
8784
|
+
}
|
|
8785
|
+
function writeCache(cache) {
|
|
8786
|
+
try {
|
|
8787
|
+
const dir = getConfigDir();
|
|
8788
|
+
if (!existsSync7(dir)) {
|
|
8789
|
+
mkdirSync5(dir, { recursive: true, mode: 448 });
|
|
8790
|
+
}
|
|
8791
|
+
writeFileSync5(getCachePath(), JSON.stringify(cache), { mode: 384 });
|
|
8792
|
+
} catch {}
|
|
8793
|
+
}
|
|
8794
|
+
async function fetchLatestVersion() {
|
|
8795
|
+
const controller = new AbortController;
|
|
8796
|
+
const timeout = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
8797
|
+
try {
|
|
8798
|
+
const resp = await fetch(REGISTRY_URL, { signal: controller.signal });
|
|
8799
|
+
if (!resp.ok)
|
|
8800
|
+
return null;
|
|
8801
|
+
const data = await resp.json();
|
|
8802
|
+
const latest = data.latest;
|
|
8803
|
+
return typeof latest === "string" ? latest : null;
|
|
8804
|
+
} catch {
|
|
8805
|
+
return null;
|
|
8806
|
+
} finally {
|
|
8807
|
+
clearTimeout(timeout);
|
|
8808
|
+
}
|
|
8809
|
+
}
|
|
8810
|
+
function displayNotice(current, latest) {
|
|
8811
|
+
const msg = `
|
|
8812
|
+
${import_picocolors18.default.yellow(` Update available: ${current} → ${latest}`)}
|
|
8813
|
+
` + `${import_picocolors18.default.dim(' Run "npm update -g @dosu/cli" or visit https://github.com/dosu-ai/dosu-cli/releases')}
|
|
8814
|
+
`;
|
|
8815
|
+
console.error(msg);
|
|
8816
|
+
}
|
|
8817
|
+
function checkForUpdates() {
|
|
8818
|
+
try {
|
|
8819
|
+
const cache = readCache();
|
|
8820
|
+
if (cache && isNewerVersion(cache.latestVersion, VERSION)) {
|
|
8821
|
+
displayNotice(VERSION, cache.latestVersion);
|
|
8822
|
+
}
|
|
8823
|
+
const isStale = !cache || Date.now() - cache.lastCheck > CHECK_INTERVAL_MS;
|
|
8824
|
+
if (isStale) {
|
|
8825
|
+
fetchLatestVersion().then((latest) => {
|
|
8826
|
+
writeCache({
|
|
8827
|
+
lastCheck: Date.now(),
|
|
8828
|
+
latestVersion: latest ?? cache?.latestVersion ?? VERSION
|
|
8829
|
+
});
|
|
5248
8830
|
if (latest) {
|
|
5249
|
-
writeCache({ lastCheck: Date.now(), latestVersion: latest });
|
|
5250
8831
|
logger.debug("update-check", `Cached latest version: ${latest}`);
|
|
5251
8832
|
}
|
|
5252
8833
|
}).catch((err) => {
|
|
@@ -5298,6 +8879,8 @@ function createProgram() {
|
|
|
5298
8879
|
cfg.deployment_id = undefined;
|
|
5299
8880
|
cfg.deployment_name = undefined;
|
|
5300
8881
|
cfg.api_key = undefined;
|
|
8882
|
+
cfg.org_id = undefined;
|
|
8883
|
+
cfg.space_id = undefined;
|
|
5301
8884
|
saveConfig(cfg);
|
|
5302
8885
|
console.log("Successfully logged out.");
|
|
5303
8886
|
});
|
|
@@ -5380,6 +8963,20 @@ Start ${provider.name()} in this project directory to use the Dosu MCP.`);
|
|
|
5380
8963
|
console.log(`
|
|
5381
8964
|
Use 'dosu mcp add <tool>' to add Dosu MCP to a tool.`);
|
|
5382
8965
|
});
|
|
8966
|
+
program2.addCommand(analyticsCommand());
|
|
8967
|
+
program2.addCommand(askCommand());
|
|
8968
|
+
program2.addCommand(deploymentsCommand());
|
|
8969
|
+
program2.addCommand(docsCommand());
|
|
8970
|
+
program2.addCommand(integrationsCommand());
|
|
8971
|
+
program2.addCommand(knowledgeCommand());
|
|
8972
|
+
program2.addCommand(membersCommand());
|
|
8973
|
+
program2.addCommand(orgCommand());
|
|
8974
|
+
program2.addCommand(reviewCommand());
|
|
8975
|
+
program2.addCommand(sourcesCommand());
|
|
8976
|
+
program2.addCommand(suggestCommand());
|
|
8977
|
+
program2.addCommand(tagsCommand());
|
|
8978
|
+
program2.addCommand(threadsCommand());
|
|
8979
|
+
program2.addCommand(skillCommand());
|
|
5383
8980
|
program2.command("setup").description("Set up Dosu MCP for your AI tools").option("--deployment <id>", "Skip to tool configuration for a specific deployment").action(async (opts) => {
|
|
5384
8981
|
const { runSetup: runSetup2 } = await Promise.resolve().then(() => (init_flow2(), exports_flow2));
|
|
5385
8982
|
await runSetup2({ deploymentID: opts.deployment });
|
|
@@ -5398,7 +8995,7 @@ Use 'dosu mcp add <tool>' to add Dosu MCP to a tool.`);
|
|
|
5398
8995
|
if (opts.tail !== undefined) {
|
|
5399
8996
|
const n = typeof opts.tail === "string" ? parseInt(opts.tail, 10) || 50 : 50;
|
|
5400
8997
|
try {
|
|
5401
|
-
const content =
|
|
8998
|
+
const content = readFileSync7(logPath, "utf-8");
|
|
5402
8999
|
const lines = content.split(`
|
|
5403
9000
|
`);
|
|
5404
9001
|
console.log(lines.slice(-n).join(`
|