@hasna/connectors 1.4.3 → 1.4.5
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 +3 -3
- package/bin/index.js +558 -397
- package/bin/mcp.js +297 -187
- package/bin/serve.js +491 -330
- package/connectors/aws/package.json +1 -1
- package/connectors/clickbank/package.json +1 -1
- package/dist/db/database.d.ts +5 -2
- package/dist/index.js +243 -138
- package/dist/lib/paths.d.ts +28 -0
- package/dist/lib/paths.test.d.ts +1 -0
- package/package.json +2 -1
package/bin/serve.js
CHANGED
|
@@ -105,6 +105,115 @@ class SqliteAdapter {
|
|
|
105
105
|
}
|
|
106
106
|
var init_sqlite_adapter = () => {};
|
|
107
107
|
|
|
108
|
+
// ../../node_modules/.bun/@hasna+paths@0.1.0/node_modules/@hasna/paths/dist/index.js
|
|
109
|
+
import { homedir } from "os";
|
|
110
|
+
import { join } from "path";
|
|
111
|
+
function assertApp(app) {
|
|
112
|
+
if (typeof app !== "string" || app.length === 0) {
|
|
113
|
+
throw new TypeError("paths: app must be a non-empty string");
|
|
114
|
+
}
|
|
115
|
+
if (!APP_SLUG_RE.test(app)) {
|
|
116
|
+
throw new TypeError(`paths: invalid app slug "${app}" \u2014 expected lowercase kebab-case ([a-z0-9]+(-[a-z0-9]+)*)`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function envOf(options) {
|
|
120
|
+
return options.env ?? process.env;
|
|
121
|
+
}
|
|
122
|
+
function envValue(options, kind) {
|
|
123
|
+
const value = envOf(options)[KIND_ENV[kind]];
|
|
124
|
+
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
125
|
+
}
|
|
126
|
+
function isMacOS(platform) {
|
|
127
|
+
return platform === "darwin";
|
|
128
|
+
}
|
|
129
|
+
function baseDir(kind, options) {
|
|
130
|
+
const override = envValue(options, kind);
|
|
131
|
+
if (override)
|
|
132
|
+
return override;
|
|
133
|
+
const home = options.home ?? homedir();
|
|
134
|
+
const platform = options.platform ?? process.platform;
|
|
135
|
+
if (isMacOS(platform)) {
|
|
136
|
+
switch (kind) {
|
|
137
|
+
case "config":
|
|
138
|
+
case "data":
|
|
139
|
+
return join(home, "Library", "Application Support", "Hasna");
|
|
140
|
+
case "cache":
|
|
141
|
+
return join(home, "Library", "Caches", "Hasna");
|
|
142
|
+
case "state":
|
|
143
|
+
return join(home, "Library", "Logs", "Hasna");
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
switch (kind) {
|
|
147
|
+
case "config":
|
|
148
|
+
return join(home, ".config", "hasna");
|
|
149
|
+
case "data":
|
|
150
|
+
return join(home, ".local", "share", "hasna");
|
|
151
|
+
case "state":
|
|
152
|
+
return join(home, ".local", "state", "hasna");
|
|
153
|
+
case "cache":
|
|
154
|
+
return join(home, ".cache", "hasna");
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function resolvePath(kind, options) {
|
|
158
|
+
assertApp(options.app);
|
|
159
|
+
const appSegment = options.internal === true ? join("internal", options.app) : options.app;
|
|
160
|
+
return join(baseDir(kind, options), appSegment);
|
|
161
|
+
}
|
|
162
|
+
function dataDir(options) {
|
|
163
|
+
return resolvePath("data", options);
|
|
164
|
+
}
|
|
165
|
+
var KIND_ENV, APP_SLUG_RE;
|
|
166
|
+
var init_dist = __esm(() => {
|
|
167
|
+
KIND_ENV = {
|
|
168
|
+
config: "HASNA_CONFIG_HOME",
|
|
169
|
+
data: "HASNA_DATA_HOME",
|
|
170
|
+
state: "HASNA_STATE_HOME",
|
|
171
|
+
cache: "HASNA_CACHE_HOME"
|
|
172
|
+
};
|
|
173
|
+
APP_SLUG_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
// src/lib/paths.ts
|
|
177
|
+
import { existsSync } from "fs";
|
|
178
|
+
import { homedir as homedir2 } from "os";
|
|
179
|
+
import { join as join2, resolve } from "path";
|
|
180
|
+
function envOr(name, fallback) {
|
|
181
|
+
const value = process.env[name]?.trim();
|
|
182
|
+
return value ? value : fallback;
|
|
183
|
+
}
|
|
184
|
+
function effectiveHome() {
|
|
185
|
+
return process.env["HOME"] || process.env["USERPROFILE"] || homedir2();
|
|
186
|
+
}
|
|
187
|
+
function legacyHomeDir() {
|
|
188
|
+
return join2(effectiveHome(), ".hasna", "connectors");
|
|
189
|
+
}
|
|
190
|
+
function resolverHome() {
|
|
191
|
+
return dataDir({
|
|
192
|
+
app: "connectors",
|
|
193
|
+
home: process.env["HOME"] || process.env["USERPROFILE"] || undefined
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
function adoptResolverHome(resolved, env = process.env) {
|
|
197
|
+
const dataOverride = env.HASNA_DATA_HOME;
|
|
198
|
+
if (typeof dataOverride === "string" && dataOverride.trim().length > 0)
|
|
199
|
+
return true;
|
|
200
|
+
return existsSync(join2(resolved, "connectors.db"));
|
|
201
|
+
}
|
|
202
|
+
function exactConnectorsHome() {
|
|
203
|
+
const home = envOr("HASNA_CONNECTORS_DIR", "");
|
|
204
|
+
return home ? home : undefined;
|
|
205
|
+
}
|
|
206
|
+
function connectorsHome() {
|
|
207
|
+
const exact = exactConnectorsHome();
|
|
208
|
+
if (exact)
|
|
209
|
+
return resolve(exact);
|
|
210
|
+
const resolved = resolverHome();
|
|
211
|
+
return adoptResolverHome(resolved) ? resolve(resolved) : resolve(legacyHomeDir());
|
|
212
|
+
}
|
|
213
|
+
var init_paths = __esm(() => {
|
|
214
|
+
init_dist();
|
|
215
|
+
});
|
|
216
|
+
|
|
108
217
|
// src/db/database.ts
|
|
109
218
|
var exports_database = {};
|
|
110
219
|
__export(exports_database, {
|
|
@@ -115,33 +224,32 @@ __export(exports_database, {
|
|
|
115
224
|
closeDatabase: () => closeDatabase,
|
|
116
225
|
SqliteAdapter: () => SqliteAdapter
|
|
117
226
|
});
|
|
118
|
-
import { dirname, join } from "path";
|
|
119
|
-
import {
|
|
120
|
-
import { mkdirSync, existsSync, readdirSync, copyFileSync, statSync } from "fs";
|
|
227
|
+
import { dirname, join as join3 } from "path";
|
|
228
|
+
import { mkdirSync, existsSync as existsSync2, readdirSync, copyFileSync, statSync } from "fs";
|
|
121
229
|
function mergeDirectoryContents(sourceDir, targetDir) {
|
|
122
|
-
if (!
|
|
230
|
+
if (!existsSync2(sourceDir)) {
|
|
123
231
|
return;
|
|
124
232
|
}
|
|
125
233
|
mkdirSync(targetDir, { recursive: true });
|
|
126
234
|
for (const entry of readdirSync(sourceDir)) {
|
|
127
|
-
const sourcePath =
|
|
128
|
-
const targetPath =
|
|
235
|
+
const sourcePath = join3(sourceDir, entry);
|
|
236
|
+
const targetPath = join3(targetDir, entry);
|
|
129
237
|
try {
|
|
130
238
|
const sourceStat = statSync(sourcePath);
|
|
131
239
|
if (sourceStat.isDirectory()) {
|
|
132
240
|
mergeDirectoryContents(sourcePath, targetPath);
|
|
133
241
|
continue;
|
|
134
242
|
}
|
|
135
|
-
if (!
|
|
243
|
+
if (!existsSync2(targetPath)) {
|
|
136
244
|
copyFileSync(sourcePath, targetPath);
|
|
137
245
|
}
|
|
138
246
|
} catch {}
|
|
139
247
|
}
|
|
140
248
|
}
|
|
141
249
|
function getConnectorsHome() {
|
|
142
|
-
const
|
|
143
|
-
const
|
|
144
|
-
const legacyDirs = [
|
|
250
|
+
const newDir = connectorsHome();
|
|
251
|
+
const home = effectiveHome();
|
|
252
|
+
const legacyDirs = [join3(home, ".connectors"), join3(home, ".connect")];
|
|
145
253
|
mkdirSync(newDir, { recursive: true });
|
|
146
254
|
for (const legacyDir of legacyDirs) {
|
|
147
255
|
try {
|
|
@@ -289,8 +397,9 @@ var DB_DIR, DB_PATH, _db = null, _dbPath = null;
|
|
|
289
397
|
var init_database = __esm(() => {
|
|
290
398
|
init_sqlite_adapter();
|
|
291
399
|
init_sqlite_adapter();
|
|
400
|
+
init_paths();
|
|
292
401
|
DB_DIR = getConnectorsHome();
|
|
293
|
-
DB_PATH =
|
|
402
|
+
DB_PATH = join3(DB_DIR, "connectors.db");
|
|
294
403
|
});
|
|
295
404
|
|
|
296
405
|
// src/lib/llm.ts
|
|
@@ -304,14 +413,14 @@ __export(exports_llm, {
|
|
|
304
413
|
PROVIDER_DEFAULTS: () => PROVIDER_DEFAULTS,
|
|
305
414
|
LLMClient: () => LLMClient
|
|
306
415
|
});
|
|
307
|
-
import { existsSync as
|
|
308
|
-
import { join as
|
|
416
|
+
import { existsSync as existsSync3, readFileSync, writeFileSync, mkdirSync as mkdirSync2 } from "fs";
|
|
417
|
+
import { join as join4 } from "path";
|
|
309
418
|
function getLlmConfigPath() {
|
|
310
|
-
return
|
|
419
|
+
return join4(getConnectorsHome(), "llm.json");
|
|
311
420
|
}
|
|
312
421
|
function getLlmConfig() {
|
|
313
422
|
const path = getLlmConfigPath();
|
|
314
|
-
if (!
|
|
423
|
+
if (!existsSync3(path))
|
|
315
424
|
return null;
|
|
316
425
|
try {
|
|
317
426
|
return JSON.parse(readFileSync(path, "utf-8"));
|
|
@@ -596,7 +705,7 @@ function cronMatches(cron, d) {
|
|
|
596
705
|
return matches(min, d.getMinutes(), 0, 59) && matches(hour, d.getHours(), 0, 23) && matches(dom, d.getDate(), 1, 31) && matches(mon, d.getMonth() + 1, 1, 12) && matches(dow, d.getDay(), 0, 6);
|
|
597
706
|
}
|
|
598
707
|
async function runConnectorCommand(connector, command, args) {
|
|
599
|
-
return new Promise((
|
|
708
|
+
return new Promise((resolve2) => {
|
|
600
709
|
const cmdArgs = [connector, command, ...args, "--format", "json"];
|
|
601
710
|
const proc = spawn("connectors", ["run", ...cmdArgs], { shell: false });
|
|
602
711
|
let output = "";
|
|
@@ -606,11 +715,11 @@ async function runConnectorCommand(connector, command, args) {
|
|
|
606
715
|
proc.stderr.on("data", (d) => {
|
|
607
716
|
output += d.toString();
|
|
608
717
|
});
|
|
609
|
-
proc.on("close", (code) =>
|
|
610
|
-
proc.on("error", () =>
|
|
718
|
+
proc.on("close", (code) => resolve2({ exitCode: code ?? 1, output }));
|
|
719
|
+
proc.on("error", () => resolve2({ exitCode: 1, output: `Failed to spawn connectors run` }));
|
|
611
720
|
setTimeout(() => {
|
|
612
721
|
proc.kill();
|
|
613
|
-
|
|
722
|
+
resolve2({ exitCode: 124, output: output + `
|
|
614
723
|
[timeout]` });
|
|
615
724
|
}, 60000);
|
|
616
725
|
});
|
|
@@ -4764,28 +4873,28 @@ var init_zod = __esm(() => {
|
|
|
4764
4873
|
|
|
4765
4874
|
// src/core/connectors/github.ts
|
|
4766
4875
|
import { Buffer as Buffer2 } from "buffer";
|
|
4767
|
-
import { existsSync as
|
|
4768
|
-
import { dirname as dirname2, join as
|
|
4876
|
+
import { existsSync as existsSync4 } from "fs";
|
|
4877
|
+
import { dirname as dirname2, join as join5 } from "path";
|
|
4769
4878
|
import { fileURLToPath, pathToFileURL } from "url";
|
|
4770
4879
|
function resolveGithubConnectorDir() {
|
|
4771
4880
|
const candidates = [
|
|
4772
|
-
|
|
4773
|
-
|
|
4774
|
-
|
|
4775
|
-
|
|
4881
|
+
join5(__dirname2, "..", "..", "..", "connectors", "github"),
|
|
4882
|
+
join5(__dirname2, "..", "..", "connectors", "github"),
|
|
4883
|
+
join5(__dirname2, "..", "connectors", "github"),
|
|
4884
|
+
join5(process.cwd(), "connectors", "github")
|
|
4776
4885
|
];
|
|
4777
4886
|
for (const candidate of candidates) {
|
|
4778
|
-
if (
|
|
4887
|
+
if (existsSync4(candidate)) {
|
|
4779
4888
|
return candidate;
|
|
4780
4889
|
}
|
|
4781
4890
|
}
|
|
4782
4891
|
return candidates[0];
|
|
4783
4892
|
}
|
|
4784
4893
|
async function loadGitHubApiModule() {
|
|
4785
|
-
return await import(pathToFileURL(
|
|
4894
|
+
return await import(pathToFileURL(join5(CONNECTOR_DIR, "src", "api", "index.ts")).href);
|
|
4786
4895
|
}
|
|
4787
4896
|
async function loadGitHubConfigModule() {
|
|
4788
|
-
return await import(pathToFileURL(
|
|
4897
|
+
return await import(pathToFileURL(join5(CONNECTOR_DIR, "src", "utils", "config.ts")).href);
|
|
4789
4898
|
}
|
|
4790
4899
|
function extractGlobalArgs(args) {
|
|
4791
4900
|
const remaining = [];
|
|
@@ -5629,9 +5738,8 @@ Commands:
|
|
|
5629
5738
|
});
|
|
5630
5739
|
|
|
5631
5740
|
// src/core/connectors/gmail.ts
|
|
5632
|
-
import { existsSync as
|
|
5633
|
-
import {
|
|
5634
|
-
import { basename, join as join4 } from "path";
|
|
5741
|
+
import { existsSync as existsSync5, mkdirSync as mkdirSync3, readFileSync as readFileSync2, readdirSync as readdirSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
5742
|
+
import { basename, join as join6 } from "path";
|
|
5635
5743
|
async function modifyMessage(profile, messageId, addLabelIds, removeLabelIds) {
|
|
5636
5744
|
return requestJson(profile, `/users/me/messages/${encodeURIComponent(messageId)}/modify`, {}, {
|
|
5637
5745
|
method: "POST",
|
|
@@ -5668,7 +5776,7 @@ async function replyToMessage(profile, messageId, input) {
|
|
|
5668
5776
|
}
|
|
5669
5777
|
async function downloadAttachments(profile, input) {
|
|
5670
5778
|
const messageId = getMessageId(input);
|
|
5671
|
-
const outputDir = input.dir ?? input.outputDir ??
|
|
5779
|
+
const outputDir = input.dir ?? input.outputDir ?? join6(configDirs()[0], "attachments", messageId);
|
|
5672
5780
|
mkdirSync3(outputDir, { recursive: true });
|
|
5673
5781
|
const attachments = input.attachmentId && input.filename ? [{
|
|
5674
5782
|
attachmentId: input.attachmentId,
|
|
@@ -5680,7 +5788,7 @@ async function downloadAttachments(profile, input) {
|
|
|
5680
5788
|
for (const attachment of attachments) {
|
|
5681
5789
|
const data = await requestJson(profile, `/users/me/messages/${encodeURIComponent(messageId)}/attachments/${encodeURIComponent(attachment.attachmentId)}`, {});
|
|
5682
5790
|
const filename = safeFilename(attachment.filename);
|
|
5683
|
-
const path =
|
|
5791
|
+
const path = join6(outputDir, filename);
|
|
5684
5792
|
const buffer = Buffer.from(data.data, "base64url");
|
|
5685
5793
|
writeFileSync2(path, buffer);
|
|
5686
5794
|
downloaded.push({
|
|
@@ -5750,7 +5858,7 @@ function gmailBackoffDelayMs(attempt, retryAfter = null) {
|
|
|
5750
5858
|
return Math.min(2 ** attempt * baseMs + jitterMs, 64000);
|
|
5751
5859
|
}
|
|
5752
5860
|
function sleep(ms) {
|
|
5753
|
-
return new Promise((
|
|
5861
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
5754
5862
|
}
|
|
5755
5863
|
async function getValidAccessToken(profile) {
|
|
5756
5864
|
if (process.env.GMAIL_ACCESS_TOKEN)
|
|
@@ -5796,9 +5904,9 @@ async function refreshAccessToken(profile, currentTokens) {
|
|
|
5796
5904
|
}
|
|
5797
5905
|
function listProfiles() {
|
|
5798
5906
|
const profiles = new Set;
|
|
5799
|
-
for (const
|
|
5800
|
-
const profilesDir =
|
|
5801
|
-
if (!
|
|
5907
|
+
for (const baseDir2 of configDirs()) {
|
|
5908
|
+
const profilesDir = join6(baseDir2, "profiles");
|
|
5909
|
+
if (!existsSync5(profilesDir))
|
|
5802
5910
|
continue;
|
|
5803
5911
|
for (const entry of readdirSync2(profilesDir, { withFileTypes: true })) {
|
|
5804
5912
|
if (entry.isDirectory())
|
|
@@ -5814,10 +5922,10 @@ function loadCredentials(profile) {
|
|
|
5814
5922
|
const envClientSecret = process.env.GMAIL_CLIENT_SECRET ?? process.env.GOOGLE_CLIENT_SECRET;
|
|
5815
5923
|
if (envClientId && envClientSecret)
|
|
5816
5924
|
return { clientId: envClientId, clientSecret: envClientSecret };
|
|
5817
|
-
for (const
|
|
5925
|
+
for (const baseDir2 of configDirs()) {
|
|
5818
5926
|
const credentials = {
|
|
5819
|
-
...readJson(
|
|
5820
|
-
...readJson(
|
|
5927
|
+
...readJson(join6(baseDir2, "credentials.json")),
|
|
5928
|
+
...readJson(join6(baseDir2, "profiles", profile, "config.json"))
|
|
5821
5929
|
};
|
|
5822
5930
|
if (credentials.clientId || credentials.clientSecret)
|
|
5823
5931
|
return credentials;
|
|
@@ -5825,31 +5933,31 @@ function loadCredentials(profile) {
|
|
|
5825
5933
|
return {};
|
|
5826
5934
|
}
|
|
5827
5935
|
function loadTokens(profile) {
|
|
5828
|
-
for (const
|
|
5829
|
-
const fromProfile = readJson(
|
|
5936
|
+
for (const baseDir2 of configDirs()) {
|
|
5937
|
+
const fromProfile = readJson(join6(baseDir2, "profiles", profile, "tokens.json"));
|
|
5830
5938
|
if (fromProfile)
|
|
5831
5939
|
return fromProfile;
|
|
5832
|
-
const flat = readJson(
|
|
5940
|
+
const flat = readJson(join6(baseDir2, "profiles", `${profile}.json`));
|
|
5833
5941
|
if (flat)
|
|
5834
5942
|
return flat.tokens ?? (flat.accessToken || flat.refreshToken ? flat : null);
|
|
5835
5943
|
}
|
|
5836
5944
|
return null;
|
|
5837
5945
|
}
|
|
5838
5946
|
function saveTokens(profile, tokens) {
|
|
5839
|
-
const
|
|
5840
|
-
const profileDir =
|
|
5947
|
+
const baseDir2 = configDirs().find((dir) => existsSync5(dir)) ?? configDirs()[0];
|
|
5948
|
+
const profileDir = join6(baseDir2, "profiles", profile);
|
|
5841
5949
|
mkdirSync3(profileDir, { recursive: true });
|
|
5842
|
-
writeFileSync2(
|
|
5950
|
+
writeFileSync2(join6(profileDir, "tokens.json"), JSON.stringify(tokens, null, 2), { mode: 384 });
|
|
5843
5951
|
}
|
|
5844
5952
|
function configDirs() {
|
|
5845
5953
|
const explicit = process.env.HASNA_GMAIL_CONNECTOR_DIR ?? process.env.GMAIL_CONNECTOR_DIR;
|
|
5846
5954
|
if (explicit)
|
|
5847
5955
|
return [explicit];
|
|
5848
|
-
const
|
|
5849
|
-
return [
|
|
5956
|
+
const baseDir2 = connectorsHome();
|
|
5957
|
+
return [join6(baseDir2, "gmail"), join6(baseDir2, "connect-gmail")];
|
|
5850
5958
|
}
|
|
5851
5959
|
function readJson(path) {
|
|
5852
|
-
if (!
|
|
5960
|
+
if (!existsSync5(path))
|
|
5853
5961
|
return null;
|
|
5854
5962
|
try {
|
|
5855
5963
|
return JSON.parse(readFileSync2(path, "utf8"));
|
|
@@ -5930,6 +6038,7 @@ function safeFilename(filename) {
|
|
|
5930
6038
|
}
|
|
5931
6039
|
var GMAIL_API_BASE = "https://gmail.googleapis.com/gmail/v1", TOKEN_URL = "https://oauth2.googleapis.com/token", REFRESH_BUFFER_MS, MAX_GMAIL_RETRIES = 5, listMessagesSchema, messageIdSchema, readMessageSchema, attachmentListSchema, attachmentDownloadSchema, historyListSchema, replySchema, gmailConnector;
|
|
5932
6040
|
var init_gmail = __esm(() => {
|
|
6041
|
+
init_paths();
|
|
5933
6042
|
init_zod();
|
|
5934
6043
|
init_connector();
|
|
5935
6044
|
REFRESH_BUFFER_MS = 5 * 60 * 1000;
|
|
@@ -6099,9 +6208,8 @@ var init_gmail = __esm(() => {
|
|
|
6099
6208
|
});
|
|
6100
6209
|
|
|
6101
6210
|
// src/core/connectors/googledrive.ts
|
|
6102
|
-
import { existsSync as
|
|
6103
|
-
import {
|
|
6104
|
-
import { basename as basename2, join as join5 } from "path";
|
|
6211
|
+
import { existsSync as existsSync6, mkdirSync as mkdirSync4, readFileSync as readFileSync3, readdirSync as readdirSync3, writeFileSync as writeFileSync3 } from "fs";
|
|
6212
|
+
import { basename as basename2, join as join7 } from "path";
|
|
6105
6213
|
async function requestJson2(profile, path, params) {
|
|
6106
6214
|
const response = await request(profile, path, params);
|
|
6107
6215
|
const text = await response.text();
|
|
@@ -6168,9 +6276,9 @@ async function refreshAccessToken2(profile, currentTokens) {
|
|
|
6168
6276
|
}
|
|
6169
6277
|
function listProfiles2() {
|
|
6170
6278
|
const profiles = new Set;
|
|
6171
|
-
for (const
|
|
6172
|
-
const profilesDir =
|
|
6173
|
-
if (!
|
|
6279
|
+
for (const baseDir2 of configDirs2()) {
|
|
6280
|
+
const profilesDir = join7(baseDir2, "profiles");
|
|
6281
|
+
if (!existsSync6(profilesDir))
|
|
6174
6282
|
continue;
|
|
6175
6283
|
for (const entry of readdirSync3(profilesDir, { withFileTypes: true })) {
|
|
6176
6284
|
if (entry.isDirectory())
|
|
@@ -6215,10 +6323,10 @@ function loadCredentials2(profile) {
|
|
|
6215
6323
|
const envClientSecret = process.env.GOOGLE_CLIENT_SECRET;
|
|
6216
6324
|
if (envClientId && envClientSecret)
|
|
6217
6325
|
return { clientId: envClientId, clientSecret: envClientSecret };
|
|
6218
|
-
for (const
|
|
6326
|
+
for (const baseDir2 of configDirs2()) {
|
|
6219
6327
|
const credentials = {
|
|
6220
|
-
...readJson2(
|
|
6221
|
-
...readJson2(
|
|
6328
|
+
...readJson2(join7(baseDir2, "credentials.json")),
|
|
6329
|
+
...readJson2(join7(baseDir2, "profiles", profile, "config.json"))
|
|
6222
6330
|
};
|
|
6223
6331
|
if (credentials.clientId || credentials.clientSecret)
|
|
6224
6332
|
return credentials;
|
|
@@ -6226,31 +6334,31 @@ function loadCredentials2(profile) {
|
|
|
6226
6334
|
return {};
|
|
6227
6335
|
}
|
|
6228
6336
|
function loadTokens2(profile) {
|
|
6229
|
-
for (const
|
|
6230
|
-
const fromProfile = readJson2(
|
|
6337
|
+
for (const baseDir2 of configDirs2()) {
|
|
6338
|
+
const fromProfile = readJson2(join7(baseDir2, "profiles", profile, "tokens.json"));
|
|
6231
6339
|
if (fromProfile)
|
|
6232
6340
|
return fromProfile;
|
|
6233
|
-
const flat = readJson2(
|
|
6341
|
+
const flat = readJson2(join7(baseDir2, "profiles", `${profile}.json`));
|
|
6234
6342
|
if (flat)
|
|
6235
6343
|
return flat.tokens ?? (flat.accessToken || flat.refreshToken ? flat : null);
|
|
6236
6344
|
}
|
|
6237
6345
|
return null;
|
|
6238
6346
|
}
|
|
6239
6347
|
function saveTokens2(profile, tokens) {
|
|
6240
|
-
const
|
|
6241
|
-
const profileDir =
|
|
6348
|
+
const baseDir2 = configDirs2().find((dir) => existsSync6(dir)) ?? configDirs2()[0];
|
|
6349
|
+
const profileDir = join7(baseDir2, "profiles", profile);
|
|
6242
6350
|
mkdirSync4(profileDir, { recursive: true });
|
|
6243
|
-
writeFileSync3(
|
|
6351
|
+
writeFileSync3(join7(profileDir, "tokens.json"), JSON.stringify(tokens, null, 2), { mode: 384 });
|
|
6244
6352
|
}
|
|
6245
6353
|
function configDirs2() {
|
|
6246
6354
|
const explicit = process.env.HASNA_GOOGLE_DRIVE_CONNECTOR_DIR ?? process.env.GOOGLE_DRIVE_CONNECTOR_DIR;
|
|
6247
6355
|
if (explicit)
|
|
6248
6356
|
return [explicit];
|
|
6249
|
-
const
|
|
6250
|
-
return [
|
|
6357
|
+
const baseDir2 = connectorsHome();
|
|
6358
|
+
return [join7(baseDir2, "googledrive"), join7(baseDir2, "connect-googledrive")];
|
|
6251
6359
|
}
|
|
6252
6360
|
function readJson2(path) {
|
|
6253
|
-
if (!
|
|
6361
|
+
if (!existsSync6(path))
|
|
6254
6362
|
return null;
|
|
6255
6363
|
try {
|
|
6256
6364
|
return JSON.parse(readFileSync3(path, "utf8"));
|
|
@@ -6284,6 +6392,7 @@ function extractGoogleError(body) {
|
|
|
6284
6392
|
}
|
|
6285
6393
|
var DRIVE_API_BASE = "https://www.googleapis.com/drive/v3", TOKEN_URL2 = "https://oauth2.googleapis.com/token", REFRESH_BUFFER_MS2, DEFAULT_FILE_FIELDS, DEFAULT_EXPORT_FORMATS, EXPORT_EXTENSIONS, listFilesSchema, listDrivesSchema, fileIdSchema, downloadSchema, profilesStatusSchema, googleDriveConnector;
|
|
6286
6394
|
var init_googledrive = __esm(() => {
|
|
6395
|
+
init_paths();
|
|
6287
6396
|
init_zod();
|
|
6288
6397
|
init_connector();
|
|
6289
6398
|
REFRESH_BUFFER_MS2 = 5 * 60 * 1000;
|
|
@@ -6433,7 +6542,7 @@ var package_default;
|
|
|
6433
6542
|
var init_package = __esm(() => {
|
|
6434
6543
|
package_default = {
|
|
6435
6544
|
name: "@hasna/connectors",
|
|
6436
|
-
version: "1.4.
|
|
6545
|
+
version: "1.4.5",
|
|
6437
6546
|
description: "Open source connector library - Install API connectors with a single command",
|
|
6438
6547
|
type: "module",
|
|
6439
6548
|
bin: {
|
|
@@ -6505,6 +6614,7 @@ var init_package = __esm(() => {
|
|
|
6505
6614
|
},
|
|
6506
6615
|
dependencies: {
|
|
6507
6616
|
"@hasna/events": "0.1.8",
|
|
6617
|
+
"@hasna/paths": "0.1.0",
|
|
6508
6618
|
"@modelcontextprotocol/sdk": "^1.26.0",
|
|
6509
6619
|
chalk: "^5.3.0",
|
|
6510
6620
|
commander: "^12.1.0",
|
|
@@ -6537,8 +6647,8 @@ var init_package = __esm(() => {
|
|
|
6537
6647
|
});
|
|
6538
6648
|
|
|
6539
6649
|
// src/lib/connector-resolver.ts
|
|
6540
|
-
import { existsSync as
|
|
6541
|
-
import { join as
|
|
6650
|
+
import { existsSync as existsSync7, readdirSync as readdirSync4, statSync as statSync2 } from "fs";
|
|
6651
|
+
import { join as join8 } from "path";
|
|
6542
6652
|
function stripLegacyPrefix(name) {
|
|
6543
6653
|
return name.startsWith(LEGACY_CONNECTOR_PREFIX) ? name.slice(LEGACY_CONNECTOR_PREFIX.length) : name;
|
|
6544
6654
|
}
|
|
@@ -6581,8 +6691,8 @@ function connectorPackageDirNames(name) {
|
|
|
6581
6691
|
function resolveConnectorPackagePath(connectorsDir, name) {
|
|
6582
6692
|
const resolution = resolveConnectorName(name);
|
|
6583
6693
|
const dirNames = connectorPackageDirNames(name);
|
|
6584
|
-
const checkedPaths = dirNames.map((dirName) =>
|
|
6585
|
-
const existingPath = checkedPaths.find((path) =>
|
|
6694
|
+
const checkedPaths = dirNames.map((dirName) => join8(connectorsDir, dirName));
|
|
6695
|
+
const existingPath = checkedPaths.find((path) => existsSync7(path)) ?? null;
|
|
6586
6696
|
const existingDirName = existingPath ? dirNames[checkedPaths.indexOf(existingPath)] : null;
|
|
6587
6697
|
return {
|
|
6588
6698
|
...resolution,
|
|
@@ -6598,16 +6708,16 @@ function getConnectorPackagePath(connectorsDir, name) {
|
|
|
6598
6708
|
const resolved = resolveConnectorPackagePath(connectorsDir, name);
|
|
6599
6709
|
return resolved.existingPath ?? resolved.preferredPath;
|
|
6600
6710
|
}
|
|
6601
|
-
function resolveConnectorConfigPaths(name,
|
|
6711
|
+
function resolveConnectorConfigPaths(name, connectorsHome2 = getConnectorsHome()) {
|
|
6602
6712
|
const resolution = resolveConnectorName(name);
|
|
6603
6713
|
const preferredDirName = resolution.canonicalName || resolution.legacyName;
|
|
6604
|
-
const preferredPath =
|
|
6605
|
-
const legacyPath =
|
|
6714
|
+
const preferredPath = join8(connectorsHome2, preferredDirName);
|
|
6715
|
+
const legacyPath = join8(connectorsHome2, resolution.legacyName);
|
|
6606
6716
|
const paths = preferredPath === legacyPath ? [preferredPath] : [preferredPath, legacyPath];
|
|
6607
|
-
const existingPaths = paths.filter((path) =>
|
|
6717
|
+
const existingPaths = paths.filter((path) => existsSync7(path));
|
|
6608
6718
|
return {
|
|
6609
6719
|
...resolution,
|
|
6610
|
-
connectorsHome,
|
|
6720
|
+
connectorsHome: connectorsHome2,
|
|
6611
6721
|
preferredDirName,
|
|
6612
6722
|
preferredPath,
|
|
6613
6723
|
legacyPath,
|
|
@@ -6615,18 +6725,18 @@ function resolveConnectorConfigPaths(name, connectorsHome = getConnectorsHome())
|
|
|
6615
6725
|
readPaths: paths
|
|
6616
6726
|
};
|
|
6617
6727
|
}
|
|
6618
|
-
function getConnectorConfigDir(name,
|
|
6619
|
-
return resolveConnectorConfigPaths(name,
|
|
6728
|
+
function getConnectorConfigDir(name, connectorsHome2 = getConnectorsHome()) {
|
|
6729
|
+
return resolveConnectorConfigPaths(name, connectorsHome2).preferredPath;
|
|
6620
6730
|
}
|
|
6621
|
-
function getConnectorConfigReadDirs(name,
|
|
6622
|
-
return resolveConnectorConfigPaths(name,
|
|
6731
|
+
function getConnectorConfigReadDirs(name, connectorsHome2 = getConnectorsHome()) {
|
|
6732
|
+
return resolveConnectorConfigPaths(name, connectorsHome2).readPaths;
|
|
6623
6733
|
}
|
|
6624
|
-
function listConfiguredConnectorNames(
|
|
6625
|
-
if (!
|
|
6734
|
+
function listConfiguredConnectorNames(connectorsHome2 = getConnectorsHome()) {
|
|
6735
|
+
if (!existsSync7(connectorsHome2))
|
|
6626
6736
|
return [];
|
|
6627
6737
|
const names = new Set;
|
|
6628
|
-
for (const entry of readdirSync4(
|
|
6629
|
-
const fullPath =
|
|
6738
|
+
for (const entry of readdirSync4(connectorsHome2)) {
|
|
6739
|
+
const fullPath = join8(connectorsHome2, entry);
|
|
6630
6740
|
try {
|
|
6631
6741
|
if (!statSync2(fullPath).isDirectory())
|
|
6632
6742
|
continue;
|
|
@@ -6649,7 +6759,7 @@ var init_connector_resolver = __esm(() => {
|
|
|
6649
6759
|
|
|
6650
6760
|
// src/core/connectors/imessage.ts
|
|
6651
6761
|
import {
|
|
6652
|
-
existsSync as
|
|
6762
|
+
existsSync as existsSync8,
|
|
6653
6763
|
mkdirSync as mkdirSync5,
|
|
6654
6764
|
readFileSync as readFileSync4,
|
|
6655
6765
|
readdirSync as readdirSync5,
|
|
@@ -6657,7 +6767,7 @@ import {
|
|
|
6657
6767
|
statSync as statSync3,
|
|
6658
6768
|
writeFileSync as writeFileSync4
|
|
6659
6769
|
} from "fs";
|
|
6660
|
-
import { join as
|
|
6770
|
+
import { join as join9 } from "path";
|
|
6661
6771
|
function buildRootHelp(specs) {
|
|
6662
6772
|
const lines = [
|
|
6663
6773
|
"Usage: connect-imessage [options] [command]",
|
|
@@ -6708,12 +6818,12 @@ function getConfigReadDirs() {
|
|
|
6708
6818
|
return getConnectorConfigReadDirs(CONNECTOR_NAME);
|
|
6709
6819
|
}
|
|
6710
6820
|
function getProfilesDir() {
|
|
6711
|
-
return
|
|
6821
|
+
return join9(getConfigDir(), "profiles");
|
|
6712
6822
|
}
|
|
6713
6823
|
function getCurrentProfile() {
|
|
6714
6824
|
for (const configDir of getConfigReadDirs()) {
|
|
6715
|
-
const currentProfileFile =
|
|
6716
|
-
if (!
|
|
6825
|
+
const currentProfileFile = join9(configDir, "current_profile");
|
|
6826
|
+
if (!existsSync8(currentProfileFile))
|
|
6717
6827
|
continue;
|
|
6718
6828
|
try {
|
|
6719
6829
|
return readFileSync4(currentProfileFile, "utf-8").trim() || "default";
|
|
@@ -6726,16 +6836,16 @@ function getCurrentProfile() {
|
|
|
6726
6836
|
function setCurrentProfile(profile) {
|
|
6727
6837
|
const configDir = getConfigDir();
|
|
6728
6838
|
mkdirSync5(configDir, { recursive: true });
|
|
6729
|
-
writeFileSync4(
|
|
6839
|
+
writeFileSync4(join9(configDir, "current_profile"), profile);
|
|
6730
6840
|
}
|
|
6731
6841
|
function getFlatProfilePath(profile) {
|
|
6732
|
-
return
|
|
6842
|
+
return join9(getProfilesDir(), `${profile}.json`);
|
|
6733
6843
|
}
|
|
6734
6844
|
function getFlatProfileReadPaths(profile) {
|
|
6735
|
-
return getConfigReadDirs().map((dir) =>
|
|
6845
|
+
return getConfigReadDirs().map((dir) => join9(dir, "profiles", `${profile}.json`));
|
|
6736
6846
|
}
|
|
6737
6847
|
function getDirectoryProfileReadPaths(profile) {
|
|
6738
|
-
return getConfigReadDirs().map((dir) =>
|
|
6848
|
+
return getConfigReadDirs().map((dir) => join9(dir, "profiles", profile, "config.json"));
|
|
6739
6849
|
}
|
|
6740
6850
|
function loadJsonFile(path) {
|
|
6741
6851
|
try {
|
|
@@ -6755,8 +6865,8 @@ function sanitizeProfileConfig(config) {
|
|
|
6755
6865
|
};
|
|
6756
6866
|
}
|
|
6757
6867
|
function loadProfile(profile = getCurrentProfile()) {
|
|
6758
|
-
const flatConfig = getFlatProfileReadPaths(profile).reverse().reduce((config, path) => ({ ...config, ...
|
|
6759
|
-
const directoryConfig = getDirectoryProfileReadPaths(profile).reverse().reduce((config, path) => ({ ...config, ...
|
|
6868
|
+
const flatConfig = getFlatProfileReadPaths(profile).reverse().reduce((config, path) => ({ ...config, ...existsSync8(path) ? loadJsonFile(path) : {} }), {});
|
|
6869
|
+
const directoryConfig = getDirectoryProfileReadPaths(profile).reverse().reduce((config, path) => ({ ...config, ...existsSync8(path) ? loadJsonFile(path) : {} }), {});
|
|
6760
6870
|
return sanitizeProfileConfig({
|
|
6761
6871
|
...flatConfig,
|
|
6762
6872
|
...directoryConfig
|
|
@@ -6772,17 +6882,17 @@ function profileExists(profile) {
|
|
|
6772
6882
|
if (profile === "default") {
|
|
6773
6883
|
return true;
|
|
6774
6884
|
}
|
|
6775
|
-
return getFlatProfileReadPaths(profile).some((path) =>
|
|
6885
|
+
return getFlatProfileReadPaths(profile).some((path) => existsSync8(path)) || getConfigReadDirs().some((dir) => existsSync8(join9(dir, "profiles", profile)));
|
|
6776
6886
|
}
|
|
6777
6887
|
function listProfiles3() {
|
|
6778
6888
|
const seen = new Set(["default"]);
|
|
6779
6889
|
for (const configDir of getConfigReadDirs()) {
|
|
6780
|
-
const profilesDir =
|
|
6781
|
-
if (!
|
|
6890
|
+
const profilesDir = join9(configDir, "profiles");
|
|
6891
|
+
if (!existsSync8(profilesDir))
|
|
6782
6892
|
continue;
|
|
6783
6893
|
try {
|
|
6784
6894
|
for (const entry of readdirSync5(profilesDir)) {
|
|
6785
|
-
const fullPath =
|
|
6895
|
+
const fullPath = join9(profilesDir, entry);
|
|
6786
6896
|
const stat = statSync3(fullPath);
|
|
6787
6897
|
if (stat.isDirectory()) {
|
|
6788
6898
|
seen.add(entry);
|
|
@@ -6804,11 +6914,11 @@ function createProfile(profile, config = {}) {
|
|
|
6804
6914
|
}
|
|
6805
6915
|
function clearProfile(profile = getCurrentProfile()) {
|
|
6806
6916
|
const flatPath = getFlatProfilePath(profile);
|
|
6807
|
-
const directoryPath =
|
|
6808
|
-
if (
|
|
6917
|
+
const directoryPath = join9(getProfilesDir(), profile);
|
|
6918
|
+
if (existsSync8(flatPath)) {
|
|
6809
6919
|
rmSync(flatPath);
|
|
6810
6920
|
}
|
|
6811
|
-
if (
|
|
6921
|
+
if (existsSync8(directoryPath)) {
|
|
6812
6922
|
rmSync(directoryPath, { recursive: true, force: true });
|
|
6813
6923
|
}
|
|
6814
6924
|
}
|
|
@@ -7734,18 +7844,18 @@ var init_imessage = __esm(() => {
|
|
|
7734
7844
|
});
|
|
7735
7845
|
|
|
7736
7846
|
// src/core/connectors/stripe.ts
|
|
7737
|
-
import { existsSync as
|
|
7738
|
-
import { dirname as dirname3, join as
|
|
7847
|
+
import { existsSync as existsSync9 } from "fs";
|
|
7848
|
+
import { dirname as dirname3, join as join10 } from "path";
|
|
7739
7849
|
import { fileURLToPath as fileURLToPath2, pathToFileURL as pathToFileURL2 } from "url";
|
|
7740
7850
|
function resolveStripeConnectorDir() {
|
|
7741
7851
|
const candidates = [
|
|
7742
|
-
|
|
7743
|
-
|
|
7744
|
-
|
|
7745
|
-
|
|
7852
|
+
join10(__dirname3, "..", "..", "..", "connectors", "stripe"),
|
|
7853
|
+
join10(__dirname3, "..", "..", "connectors", "stripe"),
|
|
7854
|
+
join10(__dirname3, "..", "connectors", "stripe"),
|
|
7855
|
+
join10(process.cwd(), "connectors", "stripe")
|
|
7746
7856
|
];
|
|
7747
7857
|
for (const candidate of candidates) {
|
|
7748
|
-
if (
|
|
7858
|
+
if (existsSync9(candidate)) {
|
|
7749
7859
|
return candidate;
|
|
7750
7860
|
}
|
|
7751
7861
|
}
|
|
@@ -7793,10 +7903,10 @@ function buildCommandHelp2(spec) {
|
|
|
7793
7903
|
`);
|
|
7794
7904
|
}
|
|
7795
7905
|
async function loadStripeApiModule() {
|
|
7796
|
-
return await import(pathToFileURL2(
|
|
7906
|
+
return await import(pathToFileURL2(join10(CONNECTOR_DIR2, "src", "api", "index.ts")).href);
|
|
7797
7907
|
}
|
|
7798
7908
|
async function loadStripeConfigModule() {
|
|
7799
|
-
return await import(pathToFileURL2(
|
|
7909
|
+
return await import(pathToFileURL2(join10(CONNECTOR_DIR2, "src", "utils", "config.ts")).href);
|
|
7800
7910
|
}
|
|
7801
7911
|
function extractGlobalArgs3(args) {
|
|
7802
7912
|
const remaining = [];
|
|
@@ -8642,30 +8752,30 @@ __export(exports_installer, {
|
|
|
8642
8752
|
getConnectorDocs: () => getConnectorDocs,
|
|
8643
8753
|
connectorExists: () => connectorExists
|
|
8644
8754
|
});
|
|
8645
|
-
import { existsSync as
|
|
8646
|
-
import { join as
|
|
8755
|
+
import { existsSync as existsSync11, mkdirSync as mkdirSync6, readFileSync as readFileSync6, writeFileSync as writeFileSync5, readdirSync as readdirSync6, statSync as statSync4, rmSync as rmSync2 } from "fs";
|
|
8756
|
+
import { join as join12, dirname as dirname5 } from "path";
|
|
8647
8757
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
8648
8758
|
function resolveConnectorsDir() {
|
|
8649
|
-
const fromBin =
|
|
8650
|
-
if (
|
|
8759
|
+
const fromBin = join12(__dirname4, "..", "connectors");
|
|
8760
|
+
if (existsSync11(fromBin))
|
|
8651
8761
|
return fromBin;
|
|
8652
|
-
const fromSrc =
|
|
8653
|
-
if (
|
|
8762
|
+
const fromSrc = join12(__dirname4, "..", "..", "connectors");
|
|
8763
|
+
if (existsSync11(fromSrc))
|
|
8654
8764
|
return fromSrc;
|
|
8655
8765
|
return fromBin;
|
|
8656
8766
|
}
|
|
8657
8767
|
function getProjectConnectorsDir(targetDir) {
|
|
8658
|
-
return
|
|
8768
|
+
return join12(targetDir, PROJECT_CONNECTORS_DIRNAME);
|
|
8659
8769
|
}
|
|
8660
8770
|
function getEnablementManifestPath(targetDir) {
|
|
8661
|
-
return
|
|
8771
|
+
return join12(getProjectConnectorsDir(targetDir), ENABLEMENT_MANIFEST_FILENAME);
|
|
8662
8772
|
}
|
|
8663
8773
|
function getLegacyInstallPath(targetDir, name) {
|
|
8664
|
-
return
|
|
8774
|
+
return join12(getProjectConnectorsDir(targetDir), legacyConnectorName(name));
|
|
8665
8775
|
}
|
|
8666
8776
|
function loadEnablementManifest(targetDir) {
|
|
8667
8777
|
const manifestPath = getEnablementManifestPath(targetDir);
|
|
8668
|
-
if (!
|
|
8778
|
+
if (!existsSync11(manifestPath)) {
|
|
8669
8779
|
return null;
|
|
8670
8780
|
}
|
|
8671
8781
|
try {
|
|
@@ -8685,11 +8795,11 @@ function loadEnablementManifest(targetDir) {
|
|
|
8685
8795
|
}
|
|
8686
8796
|
function getLegacyInstalledConnectors(targetDir) {
|
|
8687
8797
|
const connectorsDir = getProjectConnectorsDir(targetDir);
|
|
8688
|
-
if (!
|
|
8798
|
+
if (!existsSync11(connectorsDir)) {
|
|
8689
8799
|
return [];
|
|
8690
8800
|
}
|
|
8691
8801
|
return readdirSync6(connectorsDir).filter((entry) => {
|
|
8692
|
-
const fullPath =
|
|
8802
|
+
const fullPath = join12(connectorsDir, entry);
|
|
8693
8803
|
return entry.startsWith("connect-") && statSync4(fullPath).isDirectory();
|
|
8694
8804
|
}).map((entry) => entry.replace("connect-", "")).sort();
|
|
8695
8805
|
}
|
|
@@ -8698,7 +8808,7 @@ function getEnabledConnectors(targetDir) {
|
|
|
8698
8808
|
return [...new Set([...manifestConnectors, ...getLegacyInstalledConnectors(targetDir)])].sort();
|
|
8699
8809
|
}
|
|
8700
8810
|
function updateConnectorsIndex(connectorsDir, connectors18) {
|
|
8701
|
-
const indexPath =
|
|
8811
|
+
const indexPath = join12(connectorsDir, ENABLEMENT_INDEX_FILENAME);
|
|
8702
8812
|
const connectorList = connectors18.map((connector) => ` "${connector}",`).join(`
|
|
8703
8813
|
`);
|
|
8704
8814
|
const content = `/**
|
|
@@ -8734,7 +8844,7 @@ function getConnectorPath(name) {
|
|
|
8734
8844
|
}
|
|
8735
8845
|
function connectorExists(name) {
|
|
8736
8846
|
const normalizedName = normalizeConnectorName(name);
|
|
8737
|
-
return hasInternalConnectorDefinition(normalizedName) ||
|
|
8847
|
+
return hasInternalConnectorDefinition(normalizedName) || existsSync11(getConnectorPath(normalizedName));
|
|
8738
8848
|
}
|
|
8739
8849
|
function installConnector(name, options = {}) {
|
|
8740
8850
|
const { targetDir = process.cwd(), overwrite = false } = options;
|
|
@@ -8767,7 +8877,7 @@ function installConnector(name, options = {}) {
|
|
|
8767
8877
|
try {
|
|
8768
8878
|
const nextEnabled = [...new Set([...installed, normalizedName])].sort();
|
|
8769
8879
|
writeEnablementManifest(targetDir, nextEnabled);
|
|
8770
|
-
if (overwrite &&
|
|
8880
|
+
if (overwrite && existsSync11(legacyInstallPath)) {
|
|
8771
8881
|
rmSync2(legacyInstallPath, { recursive: true });
|
|
8772
8882
|
}
|
|
8773
8883
|
return {
|
|
@@ -8802,8 +8912,8 @@ function parseConnectorDocs(raw) {
|
|
|
8802
8912
|
function getConnectorDocs(name) {
|
|
8803
8913
|
const normalizedName = normalizeConnectorName(name);
|
|
8804
8914
|
const connectorPath = getConnectorPath(normalizedName);
|
|
8805
|
-
const claudeMdPath =
|
|
8806
|
-
if (
|
|
8915
|
+
const claudeMdPath = join12(connectorPath, "CLAUDE.md");
|
|
8916
|
+
if (existsSync11(claudeMdPath)) {
|
|
8807
8917
|
return parseConnectorDocs(readFileSync6(claudeMdPath, "utf-8"));
|
|
8808
8918
|
}
|
|
8809
8919
|
const internalDocs = getInternalConnectorDefinition(normalizedName)?.docsMarkdown;
|
|
@@ -8848,7 +8958,7 @@ function removeConnector(name, targetDir = process.cwd()) {
|
|
|
8848
8958
|
const nextEnabled = installed.filter((connector) => connector !== normalizedName);
|
|
8849
8959
|
writeEnablementManifest(targetDir, nextEnabled);
|
|
8850
8960
|
const legacyInstallPath = getLegacyInstallPath(targetDir, normalizedName);
|
|
8851
|
-
if (
|
|
8961
|
+
if (existsSync11(legacyInstallPath)) {
|
|
8852
8962
|
rmSync2(legacyInstallPath, { recursive: true });
|
|
8853
8963
|
}
|
|
8854
8964
|
return true;
|
|
@@ -8862,7 +8972,7 @@ var init_installer = __esm(() => {
|
|
|
8862
8972
|
});
|
|
8863
8973
|
|
|
8864
8974
|
// src/lib/lock.ts
|
|
8865
|
-
import { openSync, closeSync, unlinkSync, existsSync as
|
|
8975
|
+
import { openSync, closeSync, unlinkSync, existsSync as existsSync12, statSync as statSync5 } from "fs";
|
|
8866
8976
|
import { mkdirSync as mkdirSync7 } from "fs";
|
|
8867
8977
|
function lockPath(connector) {
|
|
8868
8978
|
const dir = getConnectorConfigDir(connector);
|
|
@@ -8878,7 +8988,7 @@ function isStale(path) {
|
|
|
8878
8988
|
}
|
|
8879
8989
|
}
|
|
8880
8990
|
function tryAcquire(path) {
|
|
8881
|
-
if (
|
|
8991
|
+
if (existsSync12(path) && isStale(path)) {
|
|
8882
8992
|
try {
|
|
8883
8993
|
unlinkSync(path);
|
|
8884
8994
|
} catch {}
|
|
@@ -8910,7 +9020,7 @@ async function withWriteLock(connector, fn) {
|
|
|
8910
9020
|
release(path);
|
|
8911
9021
|
}
|
|
8912
9022
|
}
|
|
8913
|
-
await new Promise((
|
|
9023
|
+
await new Promise((resolve2) => setTimeout(resolve2, LOCK_RETRY_MS));
|
|
8914
9024
|
}
|
|
8915
9025
|
throw new LockTimeoutError(connector);
|
|
8916
9026
|
}
|
|
@@ -8928,9 +9038,9 @@ var init_lock = __esm(() => {
|
|
|
8928
9038
|
});
|
|
8929
9039
|
|
|
8930
9040
|
// src/server/auth.ts
|
|
8931
|
-
import { chmodSync, existsSync as
|
|
9041
|
+
import { chmodSync, existsSync as existsSync13, readFileSync as readFileSync7, writeFileSync as writeFileSync6, mkdirSync as mkdirSync8, readdirSync as readdirSync7, rmSync as rmSync3, statSync as statSync6 } from "fs";
|
|
8932
9042
|
import { randomBytes } from "crypto";
|
|
8933
|
-
import { join as
|
|
9043
|
+
import { join as join13 } from "path";
|
|
8934
9044
|
function getAuthType(name) {
|
|
8935
9045
|
name = normalizeConnectorName(name);
|
|
8936
9046
|
const docs = getConnectorDocs(name);
|
|
@@ -8971,8 +9081,8 @@ function writePrivateText(path, data) {
|
|
|
8971
9081
|
function getCurrentProfile2(name) {
|
|
8972
9082
|
name = normalizeConnectorName(name);
|
|
8973
9083
|
for (const configDir of getConnectorConfigReadDirs2(name)) {
|
|
8974
|
-
const currentProfileFile =
|
|
8975
|
-
if (
|
|
9084
|
+
const currentProfileFile = join13(configDir, "current_profile");
|
|
9085
|
+
if (existsSync13(currentProfileFile)) {
|
|
8976
9086
|
try {
|
|
8977
9087
|
return readFileSync7(currentProfileFile, "utf-8").trim() || "default";
|
|
8978
9088
|
} catch {
|
|
@@ -8985,14 +9095,14 @@ function getCurrentProfile2(name) {
|
|
|
8985
9095
|
function loadProfileConfigFromDir(configDir, profile) {
|
|
8986
9096
|
let flatConfig = {};
|
|
8987
9097
|
let dirConfig = {};
|
|
8988
|
-
const profileFile =
|
|
8989
|
-
if (
|
|
9098
|
+
const profileFile = join13(configDir, "profiles", `${profile}.json`);
|
|
9099
|
+
if (existsSync13(profileFile)) {
|
|
8990
9100
|
try {
|
|
8991
9101
|
flatConfig = JSON.parse(readFileSync7(profileFile, "utf-8"));
|
|
8992
9102
|
} catch {}
|
|
8993
9103
|
}
|
|
8994
|
-
const profileDirConfig =
|
|
8995
|
-
if (
|
|
9104
|
+
const profileDirConfig = join13(configDir, "profiles", profile, "config.json");
|
|
9105
|
+
if (existsSync13(profileDirConfig)) {
|
|
8996
9106
|
try {
|
|
8997
9107
|
dirConfig = JSON.parse(readFileSync7(profileDirConfig, "utf-8"));
|
|
8998
9108
|
} catch {}
|
|
@@ -9012,8 +9122,8 @@ function loadTokens3(name) {
|
|
|
9012
9122
|
name = normalizeConnectorName(name);
|
|
9013
9123
|
const profile = getCurrentProfile2(name);
|
|
9014
9124
|
for (const configDir of getConnectorConfigReadDirs2(name)) {
|
|
9015
|
-
const tokensFile =
|
|
9016
|
-
if (
|
|
9125
|
+
const tokensFile = join13(configDir, "profiles", profile, "tokens.json");
|
|
9126
|
+
if (existsSync13(tokensFile)) {
|
|
9017
9127
|
try {
|
|
9018
9128
|
return JSON.parse(readFileSync7(tokensFile, "utf-8"));
|
|
9019
9129
|
} catch {
|
|
@@ -9146,10 +9256,10 @@ function _saveApiKey(name, key, field) {
|
|
|
9146
9256
|
const profile = getCurrentProfile2(name);
|
|
9147
9257
|
const keyField = field || guessKeyField(name);
|
|
9148
9258
|
if (keyField === "clientId" || keyField === "clientSecret") {
|
|
9149
|
-
const credentialsFile =
|
|
9259
|
+
const credentialsFile = join13(configDir, "credentials.json");
|
|
9150
9260
|
ensurePrivateDir(configDir);
|
|
9151
9261
|
let creds = {};
|
|
9152
|
-
if (
|
|
9262
|
+
if (existsSync13(credentialsFile)) {
|
|
9153
9263
|
try {
|
|
9154
9264
|
creds = JSON.parse(readFileSync7(credentialsFile, "utf-8"));
|
|
9155
9265
|
} catch {}
|
|
@@ -9158,10 +9268,10 @@ function _saveApiKey(name, key, field) {
|
|
|
9158
9268
|
writePrivateJson(credentialsFile, creds);
|
|
9159
9269
|
return;
|
|
9160
9270
|
}
|
|
9161
|
-
const profilesDir =
|
|
9162
|
-
const profileFile =
|
|
9163
|
-
const profileDir =
|
|
9164
|
-
if (
|
|
9271
|
+
const profilesDir = join13(configDir, "profiles");
|
|
9272
|
+
const profileFile = join13(profilesDir, `${profile}.json`);
|
|
9273
|
+
const profileDir = join13(profilesDir, profile);
|
|
9274
|
+
if (existsSync13(profileFile)) {
|
|
9165
9275
|
let config = {};
|
|
9166
9276
|
try {
|
|
9167
9277
|
config = JSON.parse(readFileSync7(profileFile, "utf-8"));
|
|
@@ -9172,10 +9282,10 @@ function _saveApiKey(name, key, field) {
|
|
|
9172
9282
|
writePrivateJson(profileFile, config);
|
|
9173
9283
|
return;
|
|
9174
9284
|
}
|
|
9175
|
-
if (
|
|
9176
|
-
const configFile =
|
|
9285
|
+
if (existsSync13(profileDir)) {
|
|
9286
|
+
const configFile = join13(profileDir, "config.json");
|
|
9177
9287
|
let config = {};
|
|
9178
|
-
if (
|
|
9288
|
+
if (existsSync13(configFile)) {
|
|
9179
9289
|
try {
|
|
9180
9290
|
config = JSON.parse(readFileSync7(configFile, "utf-8"));
|
|
9181
9291
|
} catch {}
|
|
@@ -9190,7 +9300,7 @@ function _saveApiKey(name, key, field) {
|
|
|
9190
9300
|
ensurePrivateDir(configDir);
|
|
9191
9301
|
ensurePrivateDir(profilesDir);
|
|
9192
9302
|
ensurePrivateDir(profileDir);
|
|
9193
|
-
writePrivateJson(
|
|
9303
|
+
writePrivateJson(join13(profileDir, "config.json"), { [keyField]: key });
|
|
9194
9304
|
}
|
|
9195
9305
|
function guessKeyField(name) {
|
|
9196
9306
|
name = normalizeConnectorName(name);
|
|
@@ -9212,8 +9322,8 @@ function guessKeyField(name) {
|
|
|
9212
9322
|
function getOAuthConfig(name) {
|
|
9213
9323
|
name = normalizeConnectorName(name);
|
|
9214
9324
|
for (const configDir of getConnectorConfigReadDirs2(name)) {
|
|
9215
|
-
const credentialsFile =
|
|
9216
|
-
if (
|
|
9325
|
+
const credentialsFile = join13(configDir, "credentials.json");
|
|
9326
|
+
if (existsSync13(credentialsFile)) {
|
|
9217
9327
|
try {
|
|
9218
9328
|
const creds = JSON.parse(readFileSync7(credentialsFile, "utf-8"));
|
|
9219
9329
|
return { clientId: creds.clientId, clientSecret: creds.clientSecret };
|
|
@@ -9299,12 +9409,12 @@ function saveOAuthTokens(name, tokens) {
|
|
|
9299
9409
|
name = normalizeConnectorName(name);
|
|
9300
9410
|
const configDir = getConnectorConfigDir2(name);
|
|
9301
9411
|
const profile = getCurrentProfile2(name);
|
|
9302
|
-
const profilesDir =
|
|
9303
|
-
const profileDir =
|
|
9412
|
+
const profilesDir = join13(configDir, "profiles");
|
|
9413
|
+
const profileDir = join13(profilesDir, profile);
|
|
9304
9414
|
ensurePrivateDir(configDir);
|
|
9305
9415
|
ensurePrivateDir(profilesDir);
|
|
9306
9416
|
ensurePrivateDir(profileDir);
|
|
9307
|
-
const tokensFile =
|
|
9417
|
+
const tokensFile = join13(profileDir, "tokens.json");
|
|
9308
9418
|
writePrivateJson(tokensFile, tokens);
|
|
9309
9419
|
}
|
|
9310
9420
|
async function refreshOAuthToken(name) {
|
|
@@ -9351,13 +9461,13 @@ function listProfiles4(name) {
|
|
|
9351
9461
|
name = normalizeConnectorName(name);
|
|
9352
9462
|
const seen = new Set;
|
|
9353
9463
|
for (const configDir of getConnectorConfigReadDirs2(name)) {
|
|
9354
|
-
const profilesDir =
|
|
9355
|
-
if (!
|
|
9464
|
+
const profilesDir = join13(configDir, "profiles");
|
|
9465
|
+
if (!existsSync13(profilesDir))
|
|
9356
9466
|
continue;
|
|
9357
9467
|
try {
|
|
9358
9468
|
const entries = readdirSync7(profilesDir);
|
|
9359
9469
|
for (const entry of entries) {
|
|
9360
|
-
const fullPath =
|
|
9470
|
+
const fullPath = join13(profilesDir, entry);
|
|
9361
9471
|
const stat = statSync6(fullPath);
|
|
9362
9472
|
if (stat.isDirectory()) {
|
|
9363
9473
|
seen.add(entry);
|
|
@@ -9374,24 +9484,24 @@ function switchProfile(name, profile) {
|
|
|
9374
9484
|
name = normalizeConnectorName(name);
|
|
9375
9485
|
const configDir = getConnectorConfigDir2(name);
|
|
9376
9486
|
ensurePrivateDir(configDir);
|
|
9377
|
-
writePrivateText(
|
|
9487
|
+
writePrivateText(join13(configDir, "current_profile"), profile);
|
|
9378
9488
|
}
|
|
9379
9489
|
function deleteProfile2(name, profile) {
|
|
9380
9490
|
name = normalizeConnectorName(name);
|
|
9381
9491
|
if (profile === "default")
|
|
9382
9492
|
return false;
|
|
9383
9493
|
const configDir = getConnectorConfigDir2(name);
|
|
9384
|
-
const profilesDir =
|
|
9385
|
-
const profileFile =
|
|
9386
|
-
if (
|
|
9494
|
+
const profilesDir = join13(configDir, "profiles");
|
|
9495
|
+
const profileFile = join13(profilesDir, `${profile}.json`);
|
|
9496
|
+
if (existsSync13(profileFile)) {
|
|
9387
9497
|
rmSync3(profileFile);
|
|
9388
9498
|
if (getCurrentProfile2(name) === profile) {
|
|
9389
9499
|
switchProfile(name, "default");
|
|
9390
9500
|
}
|
|
9391
9501
|
return true;
|
|
9392
9502
|
}
|
|
9393
|
-
const profileDir =
|
|
9394
|
-
if (
|
|
9503
|
+
const profileDir = join13(profilesDir, profile);
|
|
9504
|
+
if (existsSync13(profileDir)) {
|
|
9395
9505
|
rmSync3(profileDir, { recursive: true });
|
|
9396
9506
|
if (getCurrentProfile2(name) === profile) {
|
|
9397
9507
|
switchProfile(name, "default");
|
|
@@ -9465,16 +9575,16 @@ __export(exports_runner, {
|
|
|
9465
9575
|
buildEnvWithCredentials: () => buildEnvWithCredentials,
|
|
9466
9576
|
buildConnectorOperationArgs: () => buildConnectorOperationArgs
|
|
9467
9577
|
});
|
|
9468
|
-
import { existsSync as
|
|
9469
|
-
import { join as
|
|
9578
|
+
import { existsSync as existsSync14, readdirSync as readdirSync8 } from "fs";
|
|
9579
|
+
import { join as join14, dirname as dirname6 } from "path";
|
|
9470
9580
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
9471
9581
|
import { spawn as spawn2 } from "child_process";
|
|
9472
9582
|
function resolveConnectorsDir2() {
|
|
9473
|
-
const fromBin =
|
|
9474
|
-
if (
|
|
9583
|
+
const fromBin = join14(__dirname5, "..", "connectors");
|
|
9584
|
+
if (existsSync14(fromBin))
|
|
9475
9585
|
return fromBin;
|
|
9476
|
-
const fromSrc =
|
|
9477
|
-
if (
|
|
9586
|
+
const fromSrc = join14(__dirname5, "..", "..", "connectors");
|
|
9587
|
+
if (existsSync14(fromSrc))
|
|
9478
9588
|
return fromSrc;
|
|
9479
9589
|
return fromBin;
|
|
9480
9590
|
}
|
|
@@ -9542,8 +9652,8 @@ function buildEnvWithCredentials(connectorName, baseEnv) {
|
|
|
9542
9652
|
function getConnectorCliPath(name) {
|
|
9543
9653
|
const safeName = normalizeConnectorName(name).replace(/[^a-z0-9-]/g, "");
|
|
9544
9654
|
const connectorDir = getConnectorPackagePath(CONNECTORS_DIR2, safeName);
|
|
9545
|
-
const cliPath =
|
|
9546
|
-
if (
|
|
9655
|
+
const cliPath = join14(connectorDir, "src", "cli", "index.ts");
|
|
9656
|
+
if (existsSync14(cliPath))
|
|
9547
9657
|
return cliPath;
|
|
9548
9658
|
return null;
|
|
9549
9659
|
}
|
|
@@ -9737,7 +9847,7 @@ function runLegacyConnectorCommand(name, args, timeoutMs = 30000) {
|
|
|
9737
9847
|
success: false
|
|
9738
9848
|
});
|
|
9739
9849
|
}
|
|
9740
|
-
return new Promise((
|
|
9850
|
+
return new Promise((resolve2) => {
|
|
9741
9851
|
const proc = spawn2("bun", ["run", cliPath, ...args], {
|
|
9742
9852
|
timeout: timeoutMs,
|
|
9743
9853
|
env: buildEnvWithCredentials(connectorName, process.env),
|
|
@@ -9752,7 +9862,7 @@ function runLegacyConnectorCommand(name, args, timeoutMs = 30000) {
|
|
|
9752
9862
|
stderr += data.toString();
|
|
9753
9863
|
});
|
|
9754
9864
|
proc.on("close", (code) => {
|
|
9755
|
-
|
|
9865
|
+
resolve2({
|
|
9756
9866
|
stdout: stdout.trim(),
|
|
9757
9867
|
stderr: stderr.trim(),
|
|
9758
9868
|
exitCode: code ?? 1,
|
|
@@ -9760,7 +9870,7 @@ function runLegacyConnectorCommand(name, args, timeoutMs = 30000) {
|
|
|
9760
9870
|
});
|
|
9761
9871
|
});
|
|
9762
9872
|
proc.on("error", (err) => {
|
|
9763
|
-
|
|
9873
|
+
resolve2({
|
|
9764
9874
|
stdout: "",
|
|
9765
9875
|
stderr: err.message,
|
|
9766
9876
|
exitCode: 1,
|
|
@@ -12845,7 +12955,7 @@ var require_compile = __commonJS((exports) => {
|
|
|
12845
12955
|
const schOrFunc = root.refs[ref];
|
|
12846
12956
|
if (schOrFunc)
|
|
12847
12957
|
return schOrFunc;
|
|
12848
|
-
let _sch =
|
|
12958
|
+
let _sch = resolve2.call(this, root, ref);
|
|
12849
12959
|
if (_sch === undefined) {
|
|
12850
12960
|
const schema = (_a = root.localRefs) === null || _a === undefined ? undefined : _a[ref];
|
|
12851
12961
|
const { schemaId } = this.opts;
|
|
@@ -12872,7 +12982,7 @@ var require_compile = __commonJS((exports) => {
|
|
|
12872
12982
|
function sameSchemaEnv(s1, s2) {
|
|
12873
12983
|
return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
|
|
12874
12984
|
}
|
|
12875
|
-
function
|
|
12985
|
+
function resolve2(root, ref) {
|
|
12876
12986
|
let sch;
|
|
12877
12987
|
while (typeof (sch = this.refs[ref]) == "string")
|
|
12878
12988
|
ref = sch;
|
|
@@ -13458,7 +13568,7 @@ var require_fast_uri = __commonJS((exports, module) => {
|
|
|
13458
13568
|
}
|
|
13459
13569
|
return uri;
|
|
13460
13570
|
}
|
|
13461
|
-
function
|
|
13571
|
+
function resolve2(baseURI, relativeURI, options) {
|
|
13462
13572
|
const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
|
|
13463
13573
|
const { parsed: baseParsed, malformedAuthorityOrPort: baseMalformed } = parseWithStatus(baseURI, schemelessOptions);
|
|
13464
13574
|
const { parsed: relativeParsed, malformedAuthorityOrPort: relativeMalformed } = parseWithStatus(relativeURI, schemelessOptions);
|
|
@@ -13743,7 +13853,7 @@ var require_fast_uri = __commonJS((exports, module) => {
|
|
|
13743
13853
|
var fastUri = {
|
|
13744
13854
|
SCHEMES,
|
|
13745
13855
|
normalize,
|
|
13746
|
-
resolve,
|
|
13856
|
+
resolve: resolve2,
|
|
13747
13857
|
resolveComponent,
|
|
13748
13858
|
equal,
|
|
13749
13859
|
serialize,
|
|
@@ -16720,7 +16830,7 @@ var init_powershell_utils = __esm(() => {
|
|
|
16720
16830
|
executePowerShell.escapeArgument = (value) => `'${String(value).replaceAll("'", "''")}'`;
|
|
16721
16831
|
});
|
|
16722
16832
|
|
|
16723
|
-
// ../../node_modules/.bun/wsl-utils@0.
|
|
16833
|
+
// ../../node_modules/.bun/wsl-utils@1.0.0/node_modules/wsl-utils/utilities.js
|
|
16724
16834
|
function parseMountPointFromConfig(content) {
|
|
16725
16835
|
for (const line of content.split(`
|
|
16726
16836
|
`)) {
|
|
@@ -16735,7 +16845,8 @@ function parseMountPointFromConfig(content) {
|
|
|
16735
16845
|
}
|
|
16736
16846
|
}
|
|
16737
16847
|
|
|
16738
|
-
// ../../node_modules/.bun/wsl-utils@0.
|
|
16848
|
+
// ../../node_modules/.bun/wsl-utils@1.0.0/node_modules/wsl-utils/index.js
|
|
16849
|
+
import path from "path";
|
|
16739
16850
|
import { promisify as promisify2 } from "util";
|
|
16740
16851
|
import childProcess2 from "child_process";
|
|
16741
16852
|
import fs4, { constants as fsConstants } from "fs/promises";
|
|
@@ -16756,18 +16867,33 @@ var execFile2, wslDrivesMountPoint, powerShellPathFromWsl = async () => {
|
|
|
16756
16867
|
}, wslDefaultBrowser = async () => {
|
|
16757
16868
|
const psPath = await powerShellPath2();
|
|
16758
16869
|
const command = String.raw`(Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice").ProgId`;
|
|
16759
|
-
const { stdout } = await executePowerShell(command, {
|
|
16870
|
+
const { stdout } = await executePowerShell(command, {
|
|
16871
|
+
powerShellPath: psPath,
|
|
16872
|
+
cwd: path.dirname(psPath)
|
|
16873
|
+
});
|
|
16760
16874
|
return stdout.trim();
|
|
16761
|
-
}, convertWslPathToWindows = async (
|
|
16762
|
-
|
|
16763
|
-
|
|
16764
|
-
|
|
16765
|
-
|
|
16766
|
-
|
|
16767
|
-
|
|
16768
|
-
|
|
16769
|
-
|
|
16875
|
+
}, isUrl = (path2) => /^[a-z]+:\/\//i.test(path2), convertWslPathToWindows = async (paths) => {
|
|
16876
|
+
const isBatch = Array.isArray(paths);
|
|
16877
|
+
const pathArray = isBatch ? paths : [paths];
|
|
16878
|
+
const indicesToConvert = [];
|
|
16879
|
+
const pathsToConvert = [];
|
|
16880
|
+
for (const [index, path2] of pathArray.entries()) {
|
|
16881
|
+
if (!isUrl(path2)) {
|
|
16882
|
+
indicesToConvert.push(index);
|
|
16883
|
+
pathsToConvert.push(path2);
|
|
16884
|
+
}
|
|
16885
|
+
}
|
|
16886
|
+
const results = [...pathArray];
|
|
16887
|
+
if (pathsToConvert.length > 0) {
|
|
16888
|
+
try {
|
|
16889
|
+
const { stdout } = await execFile2("wslpath", ["-aw", ...pathsToConvert], { encoding: "utf8" });
|
|
16890
|
+
const convertedPaths = stdout.split(/\r?\n/).filter(Boolean);
|
|
16891
|
+
for (const [index, originalIndex] of indicesToConvert.entries()) {
|
|
16892
|
+
results[originalIndex] = convertedPaths[index] ?? pathArray[originalIndex];
|
|
16893
|
+
}
|
|
16894
|
+
} catch {}
|
|
16770
16895
|
}
|
|
16896
|
+
return isBatch ? results : results[0];
|
|
16771
16897
|
};
|
|
16772
16898
|
var init_wsl_utils = __esm(() => {
|
|
16773
16899
|
init_is_wsl();
|
|
@@ -16803,6 +16929,36 @@ var init_wsl_utils = __esm(() => {
|
|
|
16803
16929
|
powerShellPath2 = is_wsl_default ? powerShellPathFromWsl : powerShellPath;
|
|
16804
16930
|
});
|
|
16805
16931
|
|
|
16932
|
+
// ../../node_modules/.bun/powershell-utils@0.2.0/node_modules/powershell-utils/index.js
|
|
16933
|
+
import process4 from "process";
|
|
16934
|
+
import { Buffer as Buffer4 } from "buffer";
|
|
16935
|
+
import { promisify as promisify3 } from "util";
|
|
16936
|
+
import childProcess3 from "child_process";
|
|
16937
|
+
var execFile3, powerShellPath3 = () => `${process4.env.SYSTEMROOT || process4.env.windir || String.raw`C:\Windows`}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`, argumentsPrefix, encodeCommand = (command) => Buffer4.from(command, "utf16le").toString("base64"), escapeArgument = (value) => `'${String(value).replaceAll("'", "''")}'`, createArguments = (command) => [...argumentsPrefix, encodeCommand(command)], executePowerShell2 = async (command, options = {}) => {
|
|
16938
|
+
const {
|
|
16939
|
+
powerShellPath: psPath,
|
|
16940
|
+
...execFileOptions
|
|
16941
|
+
} = options;
|
|
16942
|
+
return execFile3(psPath ?? powerShellPath3(), createArguments(command), {
|
|
16943
|
+
encoding: "utf8",
|
|
16944
|
+
...execFileOptions
|
|
16945
|
+
});
|
|
16946
|
+
};
|
|
16947
|
+
var init_powershell_utils2 = __esm(() => {
|
|
16948
|
+
execFile3 = promisify3(childProcess3.execFile);
|
|
16949
|
+
argumentsPrefix = [
|
|
16950
|
+
"-NoProfile",
|
|
16951
|
+
"-NonInteractive",
|
|
16952
|
+
"-ExecutionPolicy",
|
|
16953
|
+
"Bypass",
|
|
16954
|
+
"-EncodedCommand"
|
|
16955
|
+
];
|
|
16956
|
+
executePowerShell2.argumentsPrefix = argumentsPrefix;
|
|
16957
|
+
executePowerShell2.encodeCommand = encodeCommand;
|
|
16958
|
+
executePowerShell2.escapeArgument = escapeArgument;
|
|
16959
|
+
executePowerShell2.createArguments = createArguments;
|
|
16960
|
+
});
|
|
16961
|
+
|
|
16806
16962
|
// ../../node_modules/.bun/define-lazy-prop@3.0.0/node_modules/define-lazy-prop/index.js
|
|
16807
16963
|
function defineLazyProperty(object4, propertyName, valueGetter) {
|
|
16808
16964
|
const define = (value) => Object.defineProperty(object4, propertyName, { value, enumerable: true, writable: true });
|
|
@@ -16822,11 +16978,11 @@ function defineLazyProperty(object4, propertyName, valueGetter) {
|
|
|
16822
16978
|
}
|
|
16823
16979
|
|
|
16824
16980
|
// ../../node_modules/.bun/default-browser-id@5.0.1/node_modules/default-browser-id/index.js
|
|
16825
|
-
import { promisify as
|
|
16826
|
-
import
|
|
16827
|
-
import { execFile as
|
|
16981
|
+
import { promisify as promisify4 } from "util";
|
|
16982
|
+
import process5 from "process";
|
|
16983
|
+
import { execFile as execFile4 } from "child_process";
|
|
16828
16984
|
async function defaultBrowserId() {
|
|
16829
|
-
if (
|
|
16985
|
+
if (process5.platform !== "darwin") {
|
|
16830
16986
|
throw new Error("macOS only");
|
|
16831
16987
|
}
|
|
16832
16988
|
const { stdout } = await execFileAsync("defaults", ["read", "com.apple.LaunchServices/com.apple.launchservices.secure", "LSHandlers"]);
|
|
@@ -16839,15 +16995,15 @@ async function defaultBrowserId() {
|
|
|
16839
16995
|
}
|
|
16840
16996
|
var execFileAsync;
|
|
16841
16997
|
var init_default_browser_id = __esm(() => {
|
|
16842
|
-
execFileAsync =
|
|
16998
|
+
execFileAsync = promisify4(execFile4);
|
|
16843
16999
|
});
|
|
16844
17000
|
|
|
16845
17001
|
// ../../node_modules/.bun/run-applescript@7.1.0/node_modules/run-applescript/index.js
|
|
16846
|
-
import
|
|
16847
|
-
import { promisify as
|
|
16848
|
-
import { execFile as
|
|
17002
|
+
import process6 from "process";
|
|
17003
|
+
import { promisify as promisify5 } from "util";
|
|
17004
|
+
import { execFile as execFile5, execFileSync } from "child_process";
|
|
16849
17005
|
async function runAppleScript(script, { humanReadableOutput = true, signal } = {}) {
|
|
16850
|
-
if (
|
|
17006
|
+
if (process6.platform !== "darwin") {
|
|
16851
17007
|
throw new Error("macOS only");
|
|
16852
17008
|
}
|
|
16853
17009
|
const outputArguments = humanReadableOutput ? [] : ["-ss"];
|
|
@@ -16860,7 +17016,7 @@ async function runAppleScript(script, { humanReadableOutput = true, signal } = {
|
|
|
16860
17016
|
}
|
|
16861
17017
|
var execFileAsync2;
|
|
16862
17018
|
var init_run_applescript = __esm(() => {
|
|
16863
|
-
execFileAsync2 =
|
|
17019
|
+
execFileAsync2 = promisify5(execFile5);
|
|
16864
17020
|
});
|
|
16865
17021
|
|
|
16866
17022
|
// ../../node_modules/.bun/bundle-name@4.1.0/node_modules/bundle-name/index.js
|
|
@@ -16872,11 +17028,13 @@ var init_bundle_name = __esm(() => {
|
|
|
16872
17028
|
init_run_applescript();
|
|
16873
17029
|
});
|
|
16874
17030
|
|
|
16875
|
-
// ../../node_modules/.bun/default-browser@5.5.
|
|
16876
|
-
import
|
|
16877
|
-
import {
|
|
17031
|
+
// ../../node_modules/.bun/default-browser@5.5.1/node_modules/default-browser/windows.js
|
|
17032
|
+
import process7 from "process";
|
|
17033
|
+
import { promisify as promisify6 } from "util";
|
|
17034
|
+
import { execFile as execFile6 } from "child_process";
|
|
16878
17035
|
async function defaultBrowser(_execFileAsync = execFileAsync3) {
|
|
16879
|
-
const {
|
|
17036
|
+
const regPath = `${process7.env.SYSTEMROOT ?? process7.env.windir ?? "C:\\Windows"}\\System32\\reg.exe`;
|
|
17037
|
+
const { stdout } = await _execFileAsync(regPath, [
|
|
16880
17038
|
"QUERY",
|
|
16881
17039
|
" HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice",
|
|
16882
17040
|
"/v",
|
|
@@ -16895,7 +17053,7 @@ async function defaultBrowser(_execFileAsync = execFileAsync3) {
|
|
|
16895
17053
|
}
|
|
16896
17054
|
var execFileAsync3, windowsBrowserProgIds, _windowsBrowserProgIdMap, UnknownBrowserError;
|
|
16897
17055
|
var init_windows = __esm(() => {
|
|
16898
|
-
execFileAsync3 =
|
|
17056
|
+
execFileAsync3 = promisify6(execFile6);
|
|
16899
17057
|
windowsBrowserProgIds = {
|
|
16900
17058
|
MSEdgeHTM: { name: "Edge", id: "com.microsoft.edge" },
|
|
16901
17059
|
MSEdgeBHTML: { name: "Edge Beta", id: "com.microsoft.edge.beta" },
|
|
@@ -16919,23 +17077,23 @@ var init_windows = __esm(() => {
|
|
|
16919
17077
|
};
|
|
16920
17078
|
});
|
|
16921
17079
|
|
|
16922
|
-
// ../../node_modules/.bun/default-browser@5.5.
|
|
16923
|
-
import { promisify as
|
|
16924
|
-
import
|
|
16925
|
-
import { execFile as
|
|
17080
|
+
// ../../node_modules/.bun/default-browser@5.5.1/node_modules/default-browser/index.js
|
|
17081
|
+
import { promisify as promisify7 } from "util";
|
|
17082
|
+
import process8 from "process";
|
|
17083
|
+
import { execFile as execFile7 } from "child_process";
|
|
16926
17084
|
async function defaultBrowser2() {
|
|
16927
|
-
if (
|
|
17085
|
+
if (process8.platform === "darwin") {
|
|
16928
17086
|
const id = await defaultBrowserId();
|
|
16929
17087
|
const name = await bundleName(id);
|
|
16930
17088
|
return { name, id };
|
|
16931
17089
|
}
|
|
16932
|
-
if (
|
|
17090
|
+
if (process8.platform === "linux") {
|
|
16933
17091
|
const { stdout } = await execFileAsync4("xdg-mime", ["query", "default", "x-scheme-handler/http"]);
|
|
16934
17092
|
const id = stdout.trim();
|
|
16935
17093
|
const name = titleize(id.replace(/.desktop$/, "").replace("-", " "));
|
|
16936
17094
|
return { name, id };
|
|
16937
17095
|
}
|
|
16938
|
-
if (
|
|
17096
|
+
if (process8.platform === "win32") {
|
|
16939
17097
|
return defaultBrowser();
|
|
16940
17098
|
}
|
|
16941
17099
|
throw new Error("Only macOS, Linux, and Windows are supported");
|
|
@@ -16946,22 +17104,22 @@ var init_default_browser = __esm(() => {
|
|
|
16946
17104
|
init_bundle_name();
|
|
16947
17105
|
init_windows();
|
|
16948
17106
|
init_windows();
|
|
16949
|
-
execFileAsync4 =
|
|
17107
|
+
execFileAsync4 = promisify7(execFile7);
|
|
16950
17108
|
});
|
|
16951
17109
|
|
|
16952
17110
|
// ../../node_modules/.bun/is-in-ssh@1.0.0/node_modules/is-in-ssh/index.js
|
|
16953
|
-
import
|
|
17111
|
+
import process9 from "process";
|
|
16954
17112
|
var isInSsh, is_in_ssh_default;
|
|
16955
17113
|
var init_is_in_ssh = __esm(() => {
|
|
16956
|
-
isInSsh = Boolean(
|
|
17114
|
+
isInSsh = Boolean(process9.env.SSH_CONNECTION || process9.env.SSH_CLIENT || process9.env.SSH_TTY);
|
|
16957
17115
|
is_in_ssh_default = isInSsh;
|
|
16958
17116
|
});
|
|
16959
17117
|
|
|
16960
|
-
// ../../node_modules/.bun/open@11.0.
|
|
16961
|
-
import
|
|
16962
|
-
import
|
|
17118
|
+
// ../../node_modules/.bun/open@11.0.1/node_modules/open/index.js
|
|
17119
|
+
import process10 from "process";
|
|
17120
|
+
import path2 from "path";
|
|
16963
17121
|
import { fileURLToPath as fileURLToPath6 } from "url";
|
|
16964
|
-
import
|
|
17122
|
+
import childProcess4 from "child_process";
|
|
16965
17123
|
import fs5, { constants as fsConstants2 } from "fs/promises";
|
|
16966
17124
|
function detectArchBinary(binary) {
|
|
16967
17125
|
if (typeof binary === "string" || Array.isArray(binary)) {
|
|
@@ -17092,7 +17250,7 @@ var fallbackAttemptSymbol, __dirname6, localXdgOpenPath, platform, arch, tryEach
|
|
|
17092
17250
|
}
|
|
17093
17251
|
} else if (platform === "win32" || shouldUseWindowsInWsl) {
|
|
17094
17252
|
command = await powerShellPath2();
|
|
17095
|
-
cliArguments.push(...
|
|
17253
|
+
cliArguments.push(...executePowerShell2.argumentsPrefix);
|
|
17096
17254
|
if (!is_wsl_default) {
|
|
17097
17255
|
childProcessOptions.windowsVerbatimArguments = true;
|
|
17098
17256
|
}
|
|
@@ -17104,21 +17262,24 @@ var fallbackAttemptSymbol, __dirname6, localXdgOpenPath, platform, arch, tryEach
|
|
|
17104
17262
|
encodedArguments.push("-Wait");
|
|
17105
17263
|
}
|
|
17106
17264
|
if (app) {
|
|
17107
|
-
encodedArguments.push(
|
|
17265
|
+
encodedArguments.push(executePowerShell2.escapeArgument(app));
|
|
17108
17266
|
if (options.target) {
|
|
17109
17267
|
appArguments.push(options.target);
|
|
17110
17268
|
}
|
|
17111
17269
|
} else if (options.target) {
|
|
17112
|
-
encodedArguments.push(
|
|
17270
|
+
encodedArguments.push(executePowerShell2.escapeArgument(options.target));
|
|
17113
17271
|
}
|
|
17114
17272
|
if (appArguments.length > 0) {
|
|
17115
|
-
appArguments = appArguments.map((argument) =>
|
|
17273
|
+
appArguments = appArguments.map((argument) => executePowerShell2.escapeArgument(argument));
|
|
17116
17274
|
encodedArguments.push("-ArgumentList", appArguments.join(","));
|
|
17117
17275
|
}
|
|
17118
|
-
options.target =
|
|
17276
|
+
options.target = executePowerShell2.encodeCommand(encodedArguments.join(" "));
|
|
17119
17277
|
if (!options.wait) {
|
|
17120
17278
|
childProcessOptions.stdio = "ignore";
|
|
17121
17279
|
}
|
|
17280
|
+
if (is_wsl_default) {
|
|
17281
|
+
childProcessOptions.cwd = path2.dirname(command);
|
|
17282
|
+
}
|
|
17122
17283
|
} else {
|
|
17123
17284
|
if (app) {
|
|
17124
17285
|
command = app;
|
|
@@ -17129,7 +17290,7 @@ var fallbackAttemptSymbol, __dirname6, localXdgOpenPath, platform, arch, tryEach
|
|
|
17129
17290
|
await fs5.access(localXdgOpenPath, fsConstants2.X_OK);
|
|
17130
17291
|
exeLocalXdgOpen = true;
|
|
17131
17292
|
} catch {}
|
|
17132
|
-
const useSystemXdgOpen =
|
|
17293
|
+
const useSystemXdgOpen = process10.versions.electron ?? (platform === "android" || isBundled || !exeLocalXdgOpen);
|
|
17133
17294
|
command = useSystemXdgOpen ? "xdg-open" : localXdgOpenPath;
|
|
17134
17295
|
}
|
|
17135
17296
|
if (appArguments.length > 0) {
|
|
@@ -17146,21 +17307,21 @@ var fallbackAttemptSymbol, __dirname6, localXdgOpenPath, platform, arch, tryEach
|
|
|
17146
17307
|
if (options.target) {
|
|
17147
17308
|
cliArguments.push(options.target);
|
|
17148
17309
|
}
|
|
17149
|
-
const subprocess =
|
|
17310
|
+
const subprocess = childProcess4.spawn(command, cliArguments, childProcessOptions);
|
|
17150
17311
|
if (options.wait) {
|
|
17151
|
-
return new Promise((
|
|
17312
|
+
return new Promise((resolve2, reject) => {
|
|
17152
17313
|
subprocess.once("error", reject);
|
|
17153
17314
|
subprocess.once("close", (exitCode) => {
|
|
17154
17315
|
if (!options.allowNonzeroExitCode && exitCode !== 0) {
|
|
17155
17316
|
reject(new Error(`Exited with code ${exitCode}`));
|
|
17156
17317
|
return;
|
|
17157
17318
|
}
|
|
17158
|
-
|
|
17319
|
+
resolve2(subprocess);
|
|
17159
17320
|
});
|
|
17160
17321
|
});
|
|
17161
17322
|
}
|
|
17162
17323
|
if (isFallbackAttempt) {
|
|
17163
|
-
return new Promise((
|
|
17324
|
+
return new Promise((resolve2, reject) => {
|
|
17164
17325
|
subprocess.once("error", reject);
|
|
17165
17326
|
subprocess.once("spawn", () => {
|
|
17166
17327
|
subprocess.once("close", (exitCode) => {
|
|
@@ -17170,17 +17331,17 @@ var fallbackAttemptSymbol, __dirname6, localXdgOpenPath, platform, arch, tryEach
|
|
|
17170
17331
|
return;
|
|
17171
17332
|
}
|
|
17172
17333
|
subprocess.unref();
|
|
17173
|
-
|
|
17334
|
+
resolve2(subprocess);
|
|
17174
17335
|
});
|
|
17175
17336
|
});
|
|
17176
17337
|
});
|
|
17177
17338
|
}
|
|
17178
17339
|
subprocess.unref();
|
|
17179
|
-
return new Promise((
|
|
17340
|
+
return new Promise((resolve2, reject) => {
|
|
17180
17341
|
subprocess.once("error", reject);
|
|
17181
17342
|
subprocess.once("spawn", () => {
|
|
17182
17343
|
subprocess.off("error", reject);
|
|
17183
|
-
|
|
17344
|
+
resolve2(subprocess);
|
|
17184
17345
|
});
|
|
17185
17346
|
});
|
|
17186
17347
|
}, open = (target, options) => {
|
|
@@ -17194,14 +17355,14 @@ var fallbackAttemptSymbol, __dirname6, localXdgOpenPath, platform, arch, tryEach
|
|
|
17194
17355
|
}, apps, open_default;
|
|
17195
17356
|
var init_open = __esm(() => {
|
|
17196
17357
|
init_wsl_utils();
|
|
17197
|
-
|
|
17358
|
+
init_powershell_utils2();
|
|
17198
17359
|
init_default_browser();
|
|
17199
17360
|
init_is_inside_container();
|
|
17200
17361
|
init_is_in_ssh();
|
|
17201
17362
|
fallbackAttemptSymbol = Symbol("fallbackAttempt");
|
|
17202
|
-
__dirname6 = import.meta.url ?
|
|
17203
|
-
localXdgOpenPath =
|
|
17204
|
-
({ platform, arch } =
|
|
17363
|
+
__dirname6 = import.meta.url ? path2.dirname(fileURLToPath6(import.meta.url)) : "";
|
|
17364
|
+
localXdgOpenPath = path2.join(__dirname6, "xdg-open");
|
|
17365
|
+
({ platform, arch } = process10);
|
|
17205
17366
|
apps = {
|
|
17206
17367
|
browser: "browser",
|
|
17207
17368
|
browserPrivate: "browserPrivate"
|
|
@@ -17264,7 +17425,7 @@ var init_open_browser = __esm(() => {
|
|
|
17264
17425
|
});
|
|
17265
17426
|
|
|
17266
17427
|
// src/server/serve.ts
|
|
17267
|
-
import { existsSync as
|
|
17428
|
+
import { existsSync as existsSync16, readdirSync as readdirSync9, readFileSync as readFileSync9, writeFileSync as writeFileSync7, mkdirSync as mkdirSync9 } from "fs";
|
|
17268
17429
|
|
|
17269
17430
|
// src/db/agents.ts
|
|
17270
17431
|
init_database();
|
|
@@ -17456,7 +17617,7 @@ init_strip();
|
|
|
17456
17617
|
import { spawn as nodeSpawn } from "child_process";
|
|
17457
17618
|
var spawnImpl = nodeSpawn;
|
|
17458
17619
|
async function runStep(step, previousOutput) {
|
|
17459
|
-
return new Promise((
|
|
17620
|
+
return new Promise((resolve2) => {
|
|
17460
17621
|
const args = [...step.args ?? []];
|
|
17461
17622
|
if (previousOutput && previousOutput.trim()) {
|
|
17462
17623
|
args.push("--input", previousOutput.trim().slice(0, 4096));
|
|
@@ -17470,11 +17631,11 @@ async function runStep(step, previousOutput) {
|
|
|
17470
17631
|
proc.stderr.on("data", (d) => {
|
|
17471
17632
|
output += d.toString();
|
|
17472
17633
|
});
|
|
17473
|
-
proc.on("close", (code) =>
|
|
17474
|
-
proc.on("error", () =>
|
|
17634
|
+
proc.on("close", (code) => resolve2({ exitCode: code ?? 1, output }));
|
|
17635
|
+
proc.on("error", () => resolve2({ exitCode: 1, output: "Failed to spawn connectors" }));
|
|
17475
17636
|
setTimeout(() => {
|
|
17476
17637
|
proc.kill();
|
|
17477
|
-
|
|
17638
|
+
resolve2({ exitCode: 124, output: output + `
|
|
17478
17639
|
[timeout]` });
|
|
17479
17640
|
}, 60000);
|
|
17480
17641
|
});
|
|
@@ -17505,13 +17666,13 @@ async function runWorkflow(workflow) {
|
|
|
17505
17666
|
|
|
17506
17667
|
// src/server/serve.ts
|
|
17507
17668
|
init_database();
|
|
17508
|
-
import { join as
|
|
17669
|
+
import { join as join16, dirname as dirname7, extname, basename as basename3, relative, resolve as resolve2, sep } from "path";
|
|
17509
17670
|
import { fileURLToPath as fileURLToPath7 } from "url";
|
|
17510
17671
|
|
|
17511
17672
|
// src/lib/registry.ts
|
|
17512
17673
|
init_builtins();
|
|
17513
|
-
import { existsSync as
|
|
17514
|
-
import { join as
|
|
17674
|
+
import { existsSync as existsSync10, readFileSync as readFileSync5 } from "fs";
|
|
17675
|
+
import { join as join11, dirname as dirname4 } from "path";
|
|
17515
17676
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
17516
17677
|
|
|
17517
17678
|
// src/lib/fuzzy.ts
|
|
@@ -25944,16 +26105,16 @@ function loadConnectorVersions() {
|
|
|
25944
26105
|
versionsLoaded = true;
|
|
25945
26106
|
const thisDir = dirname4(fileURLToPath3(import.meta.url));
|
|
25946
26107
|
const candidates = [
|
|
25947
|
-
|
|
25948
|
-
|
|
26108
|
+
join11(thisDir, "..", "connectors"),
|
|
26109
|
+
join11(thisDir, "..", "..", "connectors")
|
|
25949
26110
|
];
|
|
25950
|
-
const connectorsDir = candidates.find((d) =>
|
|
26111
|
+
const connectorsDir = candidates.find((d) => existsSync10(d));
|
|
25951
26112
|
if (!connectorsDir)
|
|
25952
26113
|
return;
|
|
25953
26114
|
for (const connector of CONNECTORS) {
|
|
25954
26115
|
try {
|
|
25955
|
-
const pkgPath =
|
|
25956
|
-
if (
|
|
26116
|
+
const pkgPath = join11(getConnectorPackagePath(connectorsDir, connector.name), "package.json");
|
|
26117
|
+
if (existsSync10(pkgPath)) {
|
|
25957
26118
|
const pkg = JSON.parse(readFileSync5(pkgPath, "utf-8"));
|
|
25958
26119
|
connector.version = pkg.version || "0.0.0";
|
|
25959
26120
|
continue;
|
|
@@ -31784,9 +31945,9 @@ data:
|
|
|
31784
31945
|
const initRequest = messages.find((m) => isInitializeRequest(m));
|
|
31785
31946
|
const clientProtocolVersion = initRequest ? initRequest.params.protocolVersion : req.headers.get("mcp-protocol-version") ?? DEFAULT_NEGOTIATED_PROTOCOL_VERSION;
|
|
31786
31947
|
if (this._enableJsonResponse) {
|
|
31787
|
-
return new Promise((
|
|
31948
|
+
return new Promise((resolve2) => {
|
|
31788
31949
|
this._streamMapping.set(streamId, {
|
|
31789
|
-
resolveJson:
|
|
31950
|
+
resolveJson: resolve2,
|
|
31790
31951
|
cleanup: () => {
|
|
31791
31952
|
this._streamMapping.delete(streamId);
|
|
31792
31953
|
}
|
|
@@ -33989,7 +34150,7 @@ class Protocol {
|
|
|
33989
34150
|
return;
|
|
33990
34151
|
}
|
|
33991
34152
|
const pollInterval = task2.pollInterval ?? this._options?.defaultTaskPollInterval ?? 1000;
|
|
33992
|
-
await new Promise((
|
|
34153
|
+
await new Promise((resolve2) => setTimeout(resolve2, pollInterval));
|
|
33993
34154
|
options?.signal?.throwIfAborted();
|
|
33994
34155
|
}
|
|
33995
34156
|
} catch (error2) {
|
|
@@ -34001,7 +34162,7 @@ class Protocol {
|
|
|
34001
34162
|
}
|
|
34002
34163
|
request(request2, resultSchema, options) {
|
|
34003
34164
|
const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options ?? {};
|
|
34004
|
-
return new Promise((
|
|
34165
|
+
return new Promise((resolve2, reject) => {
|
|
34005
34166
|
const earlyReject = (error2) => {
|
|
34006
34167
|
reject(error2);
|
|
34007
34168
|
};
|
|
@@ -34079,7 +34240,7 @@ class Protocol {
|
|
|
34079
34240
|
if (!parseResult.success) {
|
|
34080
34241
|
reject(parseResult.error);
|
|
34081
34242
|
} else {
|
|
34082
|
-
|
|
34243
|
+
resolve2(parseResult.data);
|
|
34083
34244
|
}
|
|
34084
34245
|
} catch (error2) {
|
|
34085
34246
|
reject(error2);
|
|
@@ -34270,12 +34431,12 @@ class Protocol {
|
|
|
34270
34431
|
interval = task.pollInterval;
|
|
34271
34432
|
}
|
|
34272
34433
|
} catch {}
|
|
34273
|
-
return new Promise((
|
|
34434
|
+
return new Promise((resolve2, reject) => {
|
|
34274
34435
|
if (signal.aborted) {
|
|
34275
34436
|
reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
34276
34437
|
return;
|
|
34277
34438
|
}
|
|
34278
|
-
const timeoutId = setTimeout(
|
|
34439
|
+
const timeoutId = setTimeout(resolve2, interval);
|
|
34279
34440
|
signal.addEventListener("abort", () => {
|
|
34280
34441
|
clearTimeout(timeoutId);
|
|
34281
34442
|
reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
@@ -35122,7 +35283,7 @@ class McpServer {
|
|
|
35122
35283
|
let task = createTaskResult.task;
|
|
35123
35284
|
const pollInterval = task.pollInterval ?? 5000;
|
|
35124
35285
|
while (task.status !== "completed" && task.status !== "failed" && task.status !== "cancelled") {
|
|
35125
|
-
await new Promise((
|
|
35286
|
+
await new Promise((resolve2) => setTimeout(resolve2, pollInterval));
|
|
35126
35287
|
const updatedTask = await extra.taskStore.getTask(taskId);
|
|
35127
35288
|
if (!updatedTask) {
|
|
35128
35289
|
throw new McpError(ErrorCode.InternalError, `Task ${taskId} not found during polling`);
|
|
@@ -36073,8 +36234,8 @@ init_zod();
|
|
|
36073
36234
|
init_auth();
|
|
36074
36235
|
init_database();
|
|
36075
36236
|
init_connector_resolver();
|
|
36076
|
-
import { existsSync as
|
|
36077
|
-
import { join as
|
|
36237
|
+
import { existsSync as existsSync15, readFileSync as readFileSync8 } from "fs";
|
|
36238
|
+
import { join as join15 } from "path";
|
|
36078
36239
|
import { spawn as spawn3 } from "child_process";
|
|
36079
36240
|
function registerAuthTools(server, stripped) {
|
|
36080
36241
|
server.registerTool("connector_auth_status", {
|
|
@@ -36209,8 +36370,8 @@ function registerAuthTools(server, stripped) {
|
|
|
36209
36370
|
const serverPort = port || 9876;
|
|
36210
36371
|
const oauthUrl = `http://localhost:${serverPort}/oauth/${name}/start`;
|
|
36211
36372
|
if (noBrowser) {
|
|
36212
|
-
const
|
|
36213
|
-
const tokenPaths = getConnectorConfigReadDirs(name,
|
|
36373
|
+
const connectorsHome2 = getConnectorsHome();
|
|
36374
|
+
const tokenPaths = getConnectorConfigReadDirs(name, connectorsHome2).map((dir) => join15(dir, "profiles", "default", "tokens.json"));
|
|
36214
36375
|
let serverRunning = false;
|
|
36215
36376
|
try {
|
|
36216
36377
|
await fetch(`http://localhost:${serverPort}/api/connectors`);
|
|
@@ -36223,13 +36384,13 @@ function registerAuthTools(server, stripped) {
|
|
|
36223
36384
|
stdio: "ignore"
|
|
36224
36385
|
});
|
|
36225
36386
|
serverProc.unref();
|
|
36226
|
-
await new Promise((
|
|
36387
|
+
await new Promise((resolve2) => setTimeout(resolve2, 2000));
|
|
36227
36388
|
}
|
|
36228
36389
|
let attempts = 0;
|
|
36229
36390
|
const maxAttempts = 120;
|
|
36230
36391
|
while (attempts < maxAttempts) {
|
|
36231
|
-
await new Promise((
|
|
36232
|
-
if (tokenPaths.some((tokensPath) =>
|
|
36392
|
+
await new Promise((resolve2) => setTimeout(resolve2, 500));
|
|
36393
|
+
if (tokenPaths.some((tokensPath) => existsSync15(tokensPath))) {
|
|
36233
36394
|
break;
|
|
36234
36395
|
}
|
|
36235
36396
|
attempts++;
|
|
@@ -36248,7 +36409,7 @@ function registerAuthTools(server, stripped) {
|
|
|
36248
36409
|
};
|
|
36249
36410
|
}
|
|
36250
36411
|
try {
|
|
36251
|
-
const tokensPath = tokenPaths.find((path) =>
|
|
36412
|
+
const tokensPath = tokenPaths.find((path) => existsSync15(path)) ?? tokenPaths[0];
|
|
36252
36413
|
const tokenData = JSON.parse(readFileSync8(tokensPath, "utf-8"));
|
|
36253
36414
|
return {
|
|
36254
36415
|
content: [{
|
|
@@ -36985,20 +37146,20 @@ function resolveDashboardDir() {
|
|
|
36985
37146
|
const candidates = [];
|
|
36986
37147
|
try {
|
|
36987
37148
|
const scriptDir = dirname7(fileURLToPath7(import.meta.url));
|
|
36988
|
-
candidates.push(
|
|
36989
|
-
candidates.push(
|
|
37149
|
+
candidates.push(join16(scriptDir, "..", "dashboard", "dist"));
|
|
37150
|
+
candidates.push(join16(scriptDir, "..", "..", "dashboard", "dist"));
|
|
36990
37151
|
} catch {}
|
|
36991
37152
|
if (process.argv[1]) {
|
|
36992
37153
|
const mainDir = dirname7(process.argv[1]);
|
|
36993
|
-
candidates.push(
|
|
36994
|
-
candidates.push(
|
|
37154
|
+
candidates.push(join16(mainDir, "..", "dashboard", "dist"));
|
|
37155
|
+
candidates.push(join16(mainDir, "..", "..", "dashboard", "dist"));
|
|
36995
37156
|
}
|
|
36996
|
-
candidates.push(
|
|
37157
|
+
candidates.push(join16(process.cwd(), "dashboard", "dist"));
|
|
36997
37158
|
for (const candidate of candidates) {
|
|
36998
|
-
if (
|
|
37159
|
+
if (existsSync16(candidate))
|
|
36999
37160
|
return candidate;
|
|
37000
37161
|
}
|
|
37001
|
-
return
|
|
37162
|
+
return join16(process.cwd(), "dashboard", "dist");
|
|
37002
37163
|
}
|
|
37003
37164
|
var MIME_TYPES = {
|
|
37004
37165
|
".html": "text/html; charset=utf-8",
|
|
@@ -37097,7 +37258,7 @@ function oauthPage(type, title, message, hint, extra) {
|
|
|
37097
37258
|
</body></html>`;
|
|
37098
37259
|
}
|
|
37099
37260
|
function serveStaticFile(filePath) {
|
|
37100
|
-
if (!
|
|
37261
|
+
if (!existsSync16(filePath))
|
|
37101
37262
|
return null;
|
|
37102
37263
|
const ext = extname(filePath);
|
|
37103
37264
|
const contentType2 = MIME_TYPES[ext] || "application/octet-stream";
|
|
@@ -37134,7 +37295,7 @@ async function startServer(requestedPort, options) {
|
|
|
37134
37295
|
const strict = options?.strict ?? false;
|
|
37135
37296
|
loadConnectorVersions();
|
|
37136
37297
|
const dashboardDir = resolveDashboardDir();
|
|
37137
|
-
const dashboardExists =
|
|
37298
|
+
const dashboardExists = existsSync16(dashboardDir);
|
|
37138
37299
|
if (!dashboardExists) {
|
|
37139
37300
|
console.error(`
|
|
37140
37301
|
Dashboard not found at: ${dashboardDir}`);
|
|
@@ -37155,12 +37316,12 @@ Dashboard not found at: ${dashboardDir}`);
|
|
|
37155
37316
|
port,
|
|
37156
37317
|
async fetch(req) {
|
|
37157
37318
|
const url2 = new URL(req.url);
|
|
37158
|
-
const
|
|
37319
|
+
const path3 = url2.pathname;
|
|
37159
37320
|
const method = req.method;
|
|
37160
37321
|
const mcpResponse = await handleMcpHttpRequest(req);
|
|
37161
37322
|
if (mcpResponse)
|
|
37162
37323
|
return mcpResponse;
|
|
37163
|
-
if (
|
|
37324
|
+
if (path3 === "/api/connectors" && method === "GET") {
|
|
37164
37325
|
const compact = url2.searchParams.get("compact") === "true";
|
|
37165
37326
|
const fieldsParam = url2.searchParams.get("fields");
|
|
37166
37327
|
const fields = fieldsParam ? new Set(fieldsParam.split(",").map((f) => f.trim())) : null;
|
|
@@ -37180,7 +37341,7 @@ Dashboard not found at: ${dashboardDir}`);
|
|
|
37180
37341
|
}
|
|
37181
37342
|
return jsonStripped(data, 200, port);
|
|
37182
37343
|
}
|
|
37183
|
-
if (
|
|
37344
|
+
if (path3 === "/api/connectors/manifest" && method === "GET") {
|
|
37184
37345
|
const connectorNames = url2.searchParams.get("connectors")?.split(",").map((name) => name.trim()).filter(Boolean);
|
|
37185
37346
|
const includeOperations = url2.searchParams.get("includeOperations") === "true";
|
|
37186
37347
|
const manifest = await getConnectorCapabilityManifest({
|
|
@@ -37189,7 +37350,7 @@ Dashboard not found at: ${dashboardDir}`);
|
|
|
37189
37350
|
});
|
|
37190
37351
|
return json(manifest, 200, port);
|
|
37191
37352
|
}
|
|
37192
|
-
const singleMatch =
|
|
37353
|
+
const singleMatch = path3.match(/^\/api\/connectors\/([^/]+)$/);
|
|
37193
37354
|
if (singleMatch && method === "GET") {
|
|
37194
37355
|
const name = singleMatch[1];
|
|
37195
37356
|
if (!isValidConnectorName(name))
|
|
@@ -37209,7 +37370,7 @@ Dashboard not found at: ${dashboardDir}`);
|
|
|
37209
37370
|
overview: docs?.overview || null
|
|
37210
37371
|
}, 200, port);
|
|
37211
37372
|
}
|
|
37212
|
-
const operationsMatch =
|
|
37373
|
+
const operationsMatch = path3.match(/^\/api\/connectors\/([^/]+)\/operations$/);
|
|
37213
37374
|
if (operationsMatch && method === "GET") {
|
|
37214
37375
|
const name = operationsMatch[1];
|
|
37215
37376
|
if (!isValidConnectorName(name))
|
|
@@ -37230,7 +37391,7 @@ Dashboard not found at: ${dashboardDir}`);
|
|
|
37230
37391
|
helpText: ops.helpText
|
|
37231
37392
|
}, 200, port);
|
|
37232
37393
|
}
|
|
37233
|
-
const operationHelpMatch =
|
|
37394
|
+
const operationHelpMatch = path3.match(/^\/api\/connectors\/([^/]+)\/operations\/([^/]+)$/);
|
|
37234
37395
|
if (operationHelpMatch && method === "GET") {
|
|
37235
37396
|
const name = operationHelpMatch[1];
|
|
37236
37397
|
const command = decodeURIComponent(operationHelpMatch[2]);
|
|
@@ -37245,7 +37406,7 @@ Dashboard not found at: ${dashboardDir}`);
|
|
|
37245
37406
|
const help = await getConnectorCommandHelp(name, command);
|
|
37246
37407
|
return json({ connector: name, displayName: meta.displayName, command, help }, 200, port);
|
|
37247
37408
|
}
|
|
37248
|
-
const operationRunMatch =
|
|
37409
|
+
const operationRunMatch = path3.match(/^\/api\/connectors\/([^/]+)\/operations\/run$/);
|
|
37249
37410
|
if (operationRunMatch && method === "POST") {
|
|
37250
37411
|
const name = operationRunMatch[1];
|
|
37251
37412
|
if (!isValidConnectorName(name))
|
|
@@ -37309,7 +37470,7 @@ ${result.stderr}`;
|
|
|
37309
37470
|
}, 500, port);
|
|
37310
37471
|
}
|
|
37311
37472
|
}
|
|
37312
|
-
const keyMatch =
|
|
37473
|
+
const keyMatch = path3.match(/^\/api\/connectors\/([^/]+)\/key$/);
|
|
37313
37474
|
if (keyMatch && method === "POST") {
|
|
37314
37475
|
const name = keyMatch[1];
|
|
37315
37476
|
if (!isValidConnectorName(name))
|
|
@@ -37328,7 +37489,7 @@ ${result.stderr}`;
|
|
|
37328
37489
|
return json({ error: e instanceof Error ? e.message : "Failed to save key" }, 500, port);
|
|
37329
37490
|
}
|
|
37330
37491
|
}
|
|
37331
|
-
const refreshMatch =
|
|
37492
|
+
const refreshMatch = path3.match(/^\/api\/connectors\/([^/]+)\/refresh$/);
|
|
37332
37493
|
if (refreshMatch && method === "POST") {
|
|
37333
37494
|
const name = refreshMatch[1];
|
|
37334
37495
|
if (!isValidConnectorName(name))
|
|
@@ -37341,7 +37502,7 @@ ${result.stderr}`;
|
|
|
37341
37502
|
return json({ success: false, error: e instanceof Error ? e.message : "Failed to refresh" }, 500, port);
|
|
37342
37503
|
}
|
|
37343
37504
|
}
|
|
37344
|
-
const installMatch =
|
|
37505
|
+
const installMatch = path3.match(/^\/api\/connectors\/([^/]+)\/install$/);
|
|
37345
37506
|
if (installMatch && method === "POST") {
|
|
37346
37507
|
const name = installMatch[1];
|
|
37347
37508
|
if (!isValidConnectorName(name))
|
|
@@ -37360,7 +37521,7 @@ ${result.stderr}`;
|
|
|
37360
37521
|
return json({ error: e instanceof Error ? e.message : "Failed to install connector" }, 500, port);
|
|
37361
37522
|
}
|
|
37362
37523
|
}
|
|
37363
|
-
const uninstallMatch =
|
|
37524
|
+
const uninstallMatch = path3.match(/^\/api\/connectors\/([^/]+)\/uninstall$/);
|
|
37364
37525
|
if (uninstallMatch && method === "POST") {
|
|
37365
37526
|
const name = uninstallMatch[1];
|
|
37366
37527
|
if (!isValidConnectorName(name))
|
|
@@ -37376,7 +37537,7 @@ ${result.stderr}`;
|
|
|
37376
37537
|
return json({ error: e instanceof Error ? e.message : "Failed to uninstall connector" }, 500, port);
|
|
37377
37538
|
}
|
|
37378
37539
|
}
|
|
37379
|
-
if (
|
|
37540
|
+
if (path3 === "/api/update" && method === "POST") {
|
|
37380
37541
|
try {
|
|
37381
37542
|
const installed = getInstalledConnectors();
|
|
37382
37543
|
if (installed.length === 0) {
|
|
@@ -37392,10 +37553,10 @@ ${result.stderr}`;
|
|
|
37392
37553
|
return json({ error: e instanceof Error ? e.message : "Failed to update" }, 500, port);
|
|
37393
37554
|
}
|
|
37394
37555
|
}
|
|
37395
|
-
if (
|
|
37556
|
+
if (path3 === "/api/activity" && method === "GET") {
|
|
37396
37557
|
return json(activityLog, 200, port);
|
|
37397
37558
|
}
|
|
37398
|
-
if (
|
|
37559
|
+
if (path3 === "/api/hot" && method === "GET") {
|
|
37399
37560
|
const { getTopConnectors: getTopConnectors2 } = await Promise.resolve().then(() => (init_usage(), exports_usage));
|
|
37400
37561
|
const { getPromotedConnectors: getPromotedConnectors2 } = await Promise.resolve().then(() => (init_promotions(), exports_promotions));
|
|
37401
37562
|
const limit = parseInt(url2.searchParams.get("limit") || "10", 10);
|
|
@@ -37405,7 +37566,7 @@ ${result.stderr}`;
|
|
|
37405
37566
|
const promoted = new Set(getPromotedConnectors2(db));
|
|
37406
37567
|
return json(top.map((t) => ({ ...t, promoted: promoted.has(t.connector) })), 200, port);
|
|
37407
37568
|
}
|
|
37408
|
-
const promoteMatch =
|
|
37569
|
+
const promoteMatch = path3.match(/^\/api\/connectors\/([^/]+)\/promote$/);
|
|
37409
37570
|
if (promoteMatch && method === "POST") {
|
|
37410
37571
|
const name = promoteMatch[1];
|
|
37411
37572
|
if (!getConnector(name))
|
|
@@ -37419,13 +37580,13 @@ ${result.stderr}`;
|
|
|
37419
37580
|
const removed = demoteConnector2(promoteMatch[1], getDatabase3());
|
|
37420
37581
|
return json({ success: removed, connector: promoteMatch[1] }, 200, port);
|
|
37421
37582
|
}
|
|
37422
|
-
if (
|
|
37583
|
+
if (path3 === "/api/llm" && method === "GET") {
|
|
37423
37584
|
const config2 = getLlmConfig();
|
|
37424
37585
|
if (!config2)
|
|
37425
37586
|
return json({ configured: false }, 200, port);
|
|
37426
37587
|
return json({ configured: true, provider: config2.provider, model: config2.model, key: maskKey(config2.api_key), strip: config2.strip }, 200, port);
|
|
37427
37588
|
}
|
|
37428
|
-
if (
|
|
37589
|
+
if (path3 === "/api/llm" && method === "POST") {
|
|
37429
37590
|
const body = await req.json().catch(() => ({}));
|
|
37430
37591
|
const validProviders = ["cerebras", "groq", "openai", "anthropic"];
|
|
37431
37592
|
const provider = body.provider;
|
|
@@ -37439,7 +37600,7 @@ ${result.stderr}`;
|
|
|
37439
37600
|
saveLlmConfig({ provider, model, api_key, strip });
|
|
37440
37601
|
return json({ success: true, provider, model, strip }, 200, port);
|
|
37441
37602
|
}
|
|
37442
|
-
if (
|
|
37603
|
+
if (path3 === "/api/llm/test" && method === "POST") {
|
|
37443
37604
|
const config2 = getLlmConfig();
|
|
37444
37605
|
if (!config2)
|
|
37445
37606
|
return json({ error: "No LLM configured" }, 400, port);
|
|
@@ -37451,17 +37612,17 @@ ${result.stderr}`;
|
|
|
37451
37612
|
return json({ success: false, error: e instanceof Error ? e.message : String(e) }, 500, port);
|
|
37452
37613
|
}
|
|
37453
37614
|
}
|
|
37454
|
-
if (
|
|
37615
|
+
if (path3 === "/api/jobs" && method === "GET") {
|
|
37455
37616
|
return json(listJobs(getDatabase3()), 200, port);
|
|
37456
37617
|
}
|
|
37457
|
-
if (
|
|
37618
|
+
if (path3 === "/api/jobs" && method === "POST") {
|
|
37458
37619
|
const body = await req.json().catch(() => ({}));
|
|
37459
37620
|
if (!body.name || !body.connector || !body.command || !body.cron)
|
|
37460
37621
|
return json({ error: "name, connector, command, cron required" }, 400, port);
|
|
37461
37622
|
const job = createJob({ name: body.name, connector: body.connector, command: body.command, args: body.args ?? [], cron: body.cron, strip: !!body.strip }, getDatabase3());
|
|
37462
37623
|
return json(job, 201, port);
|
|
37463
37624
|
}
|
|
37464
|
-
const jobMatch =
|
|
37625
|
+
const jobMatch = path3.match(/^\/api\/jobs\/([^/]+)$/);
|
|
37465
37626
|
if (jobMatch) {
|
|
37466
37627
|
const db = getDatabase3();
|
|
37467
37628
|
const job = getJobByName(jobMatch[1]) ?? getDatabase3().query("SELECT * FROM connector_jobs WHERE id = ?").get(jobMatch[1]);
|
|
@@ -37483,7 +37644,7 @@ ${result.stderr}`;
|
|
|
37483
37644
|
return json(updated, 200, port);
|
|
37484
37645
|
}
|
|
37485
37646
|
}
|
|
37486
|
-
const jobRunMatch =
|
|
37647
|
+
const jobRunMatch = path3.match(/^\/api\/jobs\/([^/]+)\/run$/);
|
|
37487
37648
|
if (jobRunMatch && method === "POST") {
|
|
37488
37649
|
const db = getDatabase3();
|
|
37489
37650
|
const job = getJobByName(jobRunMatch[1], db);
|
|
@@ -37492,17 +37653,17 @@ ${result.stderr}`;
|
|
|
37492
37653
|
const result = await triggerJob(job, db);
|
|
37493
37654
|
return json(result, 200, port);
|
|
37494
37655
|
}
|
|
37495
|
-
if (
|
|
37656
|
+
if (path3 === "/api/workflows" && method === "GET") {
|
|
37496
37657
|
return json(listWorkflows(getDatabase3()), 200, port);
|
|
37497
37658
|
}
|
|
37498
|
-
if (
|
|
37659
|
+
if (path3 === "/api/workflows" && method === "POST") {
|
|
37499
37660
|
const body = await req.json().catch(() => ({}));
|
|
37500
37661
|
if (!body.name || !body.steps)
|
|
37501
37662
|
return json({ error: "name and steps required" }, 400, port);
|
|
37502
37663
|
const wf = createWorkflow({ name: body.name, steps: body.steps }, getDatabase3());
|
|
37503
37664
|
return json(wf, 201, port);
|
|
37504
37665
|
}
|
|
37505
|
-
const wfMatch =
|
|
37666
|
+
const wfMatch = path3.match(/^\/api\/workflows\/([^/]+)$/);
|
|
37506
37667
|
if (wfMatch) {
|
|
37507
37668
|
const db = getDatabase3();
|
|
37508
37669
|
const wf = getWorkflowByName(wfMatch[1], db);
|
|
@@ -37515,7 +37676,7 @@ ${result.stderr}`;
|
|
|
37515
37676
|
return json({ success: true }, 200, port);
|
|
37516
37677
|
}
|
|
37517
37678
|
}
|
|
37518
|
-
const wfRunMatch =
|
|
37679
|
+
const wfRunMatch = path3.match(/^\/api\/workflows\/([^/]+)\/run$/);
|
|
37519
37680
|
if (wfRunMatch && method === "POST") {
|
|
37520
37681
|
const wf = getWorkflowByName(wfRunMatch[1], getDatabase3());
|
|
37521
37682
|
if (!wf)
|
|
@@ -37523,10 +37684,10 @@ ${result.stderr}`;
|
|
|
37523
37684
|
const result = await runWorkflow(wf);
|
|
37524
37685
|
return json(result, 200, port);
|
|
37525
37686
|
}
|
|
37526
|
-
if (
|
|
37687
|
+
if (path3 === "/api/agents" && method === "GET") {
|
|
37527
37688
|
return json(listAgents(), 200, port);
|
|
37528
37689
|
}
|
|
37529
|
-
if (
|
|
37690
|
+
if (path3 === "/api/agents/register" && method === "POST") {
|
|
37530
37691
|
const body = await req.json().catch(() => ({}));
|
|
37531
37692
|
const name = typeof body.name === "string" ? body.name : null;
|
|
37532
37693
|
if (!name)
|
|
@@ -37540,15 +37701,15 @@ ${result.stderr}`;
|
|
|
37540
37701
|
return json(result, 409, port);
|
|
37541
37702
|
return json(result, 200, port);
|
|
37542
37703
|
}
|
|
37543
|
-
if (
|
|
37544
|
-
const agentName =
|
|
37704
|
+
if (path3.startsWith("/api/agents/") && method === "DELETE") {
|
|
37705
|
+
const agentName = path3.slice("/api/agents/".length);
|
|
37545
37706
|
const agent = getAgentByName(agentName);
|
|
37546
37707
|
if (!agent)
|
|
37547
37708
|
return json({ error: "Agent not found" }, 404, port);
|
|
37548
37709
|
deleteAgent(agent.id);
|
|
37549
37710
|
return json({ success: true }, 200, port);
|
|
37550
37711
|
}
|
|
37551
|
-
const rateMatch =
|
|
37712
|
+
const rateMatch = path3.match(/^\/api\/rate\/([^/]+)\/([^/]+)$/);
|
|
37552
37713
|
if (rateMatch && method === "GET") {
|
|
37553
37714
|
const [, agentId, connector] = rateMatch;
|
|
37554
37715
|
const limit = parseInt(url2.searchParams.get("limit") || "60", 10);
|
|
@@ -37556,7 +37717,7 @@ ${result.stderr}`;
|
|
|
37556
37717
|
const result = consume ? checkRateBudget(agentId, connector, limit) : getRateBudget(agentId, connector, limit);
|
|
37557
37718
|
return json(result, 200, port);
|
|
37558
37719
|
}
|
|
37559
|
-
const profilesMatch =
|
|
37720
|
+
const profilesMatch = path3.match(/^\/api\/connectors\/([^/]+)\/profiles$/);
|
|
37560
37721
|
if (profilesMatch && method === "GET") {
|
|
37561
37722
|
const name = profilesMatch[1];
|
|
37562
37723
|
if (!isValidConnectorName(name))
|
|
@@ -37565,8 +37726,8 @@ ${result.stderr}`;
|
|
|
37565
37726
|
const profiles = listProfiles4(name);
|
|
37566
37727
|
let current = "default";
|
|
37567
37728
|
for (const configDir of getConnectorConfigReadDirs(name)) {
|
|
37568
|
-
const currentProfileFile =
|
|
37569
|
-
if (
|
|
37729
|
+
const currentProfileFile = join16(configDir, "current_profile");
|
|
37730
|
+
if (existsSync16(currentProfileFile)) {
|
|
37570
37731
|
try {
|
|
37571
37732
|
current = readFileSync9(currentProfileFile, "utf-8").trim() || "default";
|
|
37572
37733
|
} catch {}
|
|
@@ -37578,7 +37739,7 @@ ${result.stderr}`;
|
|
|
37578
37739
|
return json({ error: e instanceof Error ? e.message : "Failed to list profiles" }, 500, port);
|
|
37579
37740
|
}
|
|
37580
37741
|
}
|
|
37581
|
-
const profileSwitchMatch =
|
|
37742
|
+
const profileSwitchMatch = path3.match(/^\/api\/connectors\/([^/]+)\/profiles\/switch$/);
|
|
37582
37743
|
if (profileSwitchMatch && method === "POST") {
|
|
37583
37744
|
const name = profileSwitchMatch[1];
|
|
37584
37745
|
if (!isValidConnectorName(name))
|
|
@@ -37597,7 +37758,7 @@ ${result.stderr}`;
|
|
|
37597
37758
|
return json({ error: e instanceof Error ? e.message : "Failed to switch profile" }, 500, port);
|
|
37598
37759
|
}
|
|
37599
37760
|
}
|
|
37600
|
-
const profileDeleteMatch =
|
|
37761
|
+
const profileDeleteMatch = path3.match(/^\/api\/connectors\/([^/]+)\/profiles\/([^/]+)$/);
|
|
37601
37762
|
if (profileDeleteMatch && method === "DELETE") {
|
|
37602
37763
|
const name = profileDeleteMatch[1];
|
|
37603
37764
|
const profile = profileDeleteMatch[2];
|
|
@@ -37615,29 +37776,29 @@ ${result.stderr}`;
|
|
|
37615
37776
|
return json({ error: e instanceof Error ? e.message : "Failed to delete profile" }, 500, port);
|
|
37616
37777
|
}
|
|
37617
37778
|
}
|
|
37618
|
-
if (
|
|
37779
|
+
if (path3 === "/api/export" && method === "GET") {
|
|
37619
37780
|
try {
|
|
37620
37781
|
const connectDir = getConnectorsHome();
|
|
37621
37782
|
const result = {};
|
|
37622
|
-
if (
|
|
37783
|
+
if (existsSync16(connectDir)) {
|
|
37623
37784
|
for (const connectorName of listConfiguredConnectorNames(connectDir)) {
|
|
37624
37785
|
const profiles = {};
|
|
37625
37786
|
for (const configDir of [...getConnectorConfigReadDirs(connectorName, connectDir)].reverse()) {
|
|
37626
|
-
const profilesDir =
|
|
37627
|
-
if (!
|
|
37787
|
+
const profilesDir = join16(configDir, "profiles");
|
|
37788
|
+
if (!existsSync16(profilesDir))
|
|
37628
37789
|
continue;
|
|
37629
37790
|
const profileEntries = readdirSync9(profilesDir, { withFileTypes: true });
|
|
37630
37791
|
for (const pEntry of profileEntries) {
|
|
37631
37792
|
if (pEntry.isFile() && pEntry.name.endsWith(".json")) {
|
|
37632
37793
|
const profileName = basename3(pEntry.name, ".json");
|
|
37633
37794
|
try {
|
|
37634
|
-
const config2 = JSON.parse(readFileSync9(
|
|
37795
|
+
const config2 = JSON.parse(readFileSync9(join16(profilesDir, pEntry.name), "utf-8"));
|
|
37635
37796
|
profiles[profileName] = config2;
|
|
37636
37797
|
} catch {}
|
|
37637
37798
|
}
|
|
37638
37799
|
if (pEntry.isDirectory()) {
|
|
37639
|
-
const configPath =
|
|
37640
|
-
if (
|
|
37800
|
+
const configPath = join16(profilesDir, pEntry.name, "config.json");
|
|
37801
|
+
if (existsSync16(configPath)) {
|
|
37641
37802
|
try {
|
|
37642
37803
|
const config2 = JSON.parse(readFileSync9(configPath, "utf-8"));
|
|
37643
37804
|
profiles[pEntry.name] = config2;
|
|
@@ -37665,7 +37826,7 @@ ${result.stderr}`;
|
|
|
37665
37826
|
return json({ error: e instanceof Error ? e.message : "Failed to export credentials" }, 500, port);
|
|
37666
37827
|
}
|
|
37667
37828
|
}
|
|
37668
|
-
if (
|
|
37829
|
+
if (path3 === "/api/import" && method === "POST") {
|
|
37669
37830
|
try {
|
|
37670
37831
|
const contentLength = parseInt(req.headers.get("content-length") || "0", 10);
|
|
37671
37832
|
if (contentLength > MAX_BODY_SIZE)
|
|
@@ -37682,12 +37843,12 @@ ${result.stderr}`;
|
|
|
37682
37843
|
if (!data.profiles || typeof data.profiles !== "object")
|
|
37683
37844
|
continue;
|
|
37684
37845
|
const connectorDir = getConnectorConfigDir(connectorName, connectDir);
|
|
37685
|
-
const profilesDir =
|
|
37846
|
+
const profilesDir = join16(connectorDir, "profiles");
|
|
37686
37847
|
for (const [profileName, config2] of Object.entries(data.profiles)) {
|
|
37687
37848
|
if (!config2 || typeof config2 !== "object")
|
|
37688
37849
|
continue;
|
|
37689
37850
|
mkdirSync9(profilesDir, { recursive: true });
|
|
37690
|
-
const profileFile =
|
|
37851
|
+
const profileFile = join16(profilesDir, `${profileName}.json`);
|
|
37691
37852
|
writeFileSync7(profileFile, JSON.stringify(config2, null, 2));
|
|
37692
37853
|
imported++;
|
|
37693
37854
|
}
|
|
@@ -37698,7 +37859,7 @@ ${result.stderr}`;
|
|
|
37698
37859
|
return json({ error: e instanceof Error ? e.message : "Failed to import credentials" }, 500, port);
|
|
37699
37860
|
}
|
|
37700
37861
|
}
|
|
37701
|
-
const oauthStartMatch =
|
|
37862
|
+
const oauthStartMatch = path3.match(/^\/oauth\/([^/]+)\/start$/);
|
|
37702
37863
|
if (oauthStartMatch && method === "GET") {
|
|
37703
37864
|
const name = oauthStartMatch[1];
|
|
37704
37865
|
const redirectUri = `http://localhost:${port}/oauth/${name}/callback`;
|
|
@@ -37708,7 +37869,7 @@ ${result.stderr}`;
|
|
|
37708
37869
|
}
|
|
37709
37870
|
return Response.redirect(authUrl, 302);
|
|
37710
37871
|
}
|
|
37711
|
-
const oauthCallbackMatch =
|
|
37872
|
+
const oauthCallbackMatch = path3.match(/^\/oauth\/([^/]+)\/callback$/);
|
|
37712
37873
|
if (oauthCallbackMatch && method === "GET") {
|
|
37713
37874
|
const name = oauthCallbackMatch[1];
|
|
37714
37875
|
const code = url2.searchParams.get("code");
|
|
@@ -37742,16 +37903,16 @@ ${result.stderr}`;
|
|
|
37742
37903
|
});
|
|
37743
37904
|
}
|
|
37744
37905
|
if (dashboardExists && (method === "GET" || method === "HEAD")) {
|
|
37745
|
-
if (
|
|
37746
|
-
const filePath =
|
|
37747
|
-
const rel = relative(dashboardDir,
|
|
37906
|
+
if (path3 !== "/") {
|
|
37907
|
+
const filePath = join16(dashboardDir, path3);
|
|
37908
|
+
const rel = relative(dashboardDir, resolve2(filePath));
|
|
37748
37909
|
if (!rel.startsWith("..") && !rel.includes(`..${sep}`) && rel !== "") {
|
|
37749
37910
|
const res2 = serveStaticFile(filePath);
|
|
37750
37911
|
if (res2)
|
|
37751
37912
|
return res2;
|
|
37752
37913
|
}
|
|
37753
37914
|
}
|
|
37754
|
-
const indexPath =
|
|
37915
|
+
const indexPath = join16(dashboardDir, "index.html");
|
|
37755
37916
|
const res = serveStaticFile(indexPath);
|
|
37756
37917
|
if (res)
|
|
37757
37918
|
return res;
|