@hasna/connectors 1.4.4 → 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 +416 -306
- package/bin/mcp.js +297 -187
- package/bin/serve.js +349 -239
- 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,
|
|
@@ -17199,19 +17309,19 @@ var fallbackAttemptSymbol, __dirname6, localXdgOpenPath, platform, arch, tryEach
|
|
|
17199
17309
|
}
|
|
17200
17310
|
const subprocess = childProcess4.spawn(command, cliArguments, childProcessOptions);
|
|
17201
17311
|
if (options.wait) {
|
|
17202
|
-
return new Promise((
|
|
17312
|
+
return new Promise((resolve2, reject) => {
|
|
17203
17313
|
subprocess.once("error", reject);
|
|
17204
17314
|
subprocess.once("close", (exitCode) => {
|
|
17205
17315
|
if (!options.allowNonzeroExitCode && exitCode !== 0) {
|
|
17206
17316
|
reject(new Error(`Exited with code ${exitCode}`));
|
|
17207
17317
|
return;
|
|
17208
17318
|
}
|
|
17209
|
-
|
|
17319
|
+
resolve2(subprocess);
|
|
17210
17320
|
});
|
|
17211
17321
|
});
|
|
17212
17322
|
}
|
|
17213
17323
|
if (isFallbackAttempt) {
|
|
17214
|
-
return new Promise((
|
|
17324
|
+
return new Promise((resolve2, reject) => {
|
|
17215
17325
|
subprocess.once("error", reject);
|
|
17216
17326
|
subprocess.once("spawn", () => {
|
|
17217
17327
|
subprocess.once("close", (exitCode) => {
|
|
@@ -17221,17 +17331,17 @@ var fallbackAttemptSymbol, __dirname6, localXdgOpenPath, platform, arch, tryEach
|
|
|
17221
17331
|
return;
|
|
17222
17332
|
}
|
|
17223
17333
|
subprocess.unref();
|
|
17224
|
-
|
|
17334
|
+
resolve2(subprocess);
|
|
17225
17335
|
});
|
|
17226
17336
|
});
|
|
17227
17337
|
});
|
|
17228
17338
|
}
|
|
17229
17339
|
subprocess.unref();
|
|
17230
|
-
return new Promise((
|
|
17340
|
+
return new Promise((resolve2, reject) => {
|
|
17231
17341
|
subprocess.once("error", reject);
|
|
17232
17342
|
subprocess.once("spawn", () => {
|
|
17233
17343
|
subprocess.off("error", reject);
|
|
17234
|
-
|
|
17344
|
+
resolve2(subprocess);
|
|
17235
17345
|
});
|
|
17236
17346
|
});
|
|
17237
17347
|
}, open = (target, options) => {
|
|
@@ -17315,7 +17425,7 @@ var init_open_browser = __esm(() => {
|
|
|
17315
17425
|
});
|
|
17316
17426
|
|
|
17317
17427
|
// src/server/serve.ts
|
|
17318
|
-
import { existsSync as
|
|
17428
|
+
import { existsSync as existsSync16, readdirSync as readdirSync9, readFileSync as readFileSync9, writeFileSync as writeFileSync7, mkdirSync as mkdirSync9 } from "fs";
|
|
17319
17429
|
|
|
17320
17430
|
// src/db/agents.ts
|
|
17321
17431
|
init_database();
|
|
@@ -17507,7 +17617,7 @@ init_strip();
|
|
|
17507
17617
|
import { spawn as nodeSpawn } from "child_process";
|
|
17508
17618
|
var spawnImpl = nodeSpawn;
|
|
17509
17619
|
async function runStep(step, previousOutput) {
|
|
17510
|
-
return new Promise((
|
|
17620
|
+
return new Promise((resolve2) => {
|
|
17511
17621
|
const args = [...step.args ?? []];
|
|
17512
17622
|
if (previousOutput && previousOutput.trim()) {
|
|
17513
17623
|
args.push("--input", previousOutput.trim().slice(0, 4096));
|
|
@@ -17521,11 +17631,11 @@ async function runStep(step, previousOutput) {
|
|
|
17521
17631
|
proc.stderr.on("data", (d) => {
|
|
17522
17632
|
output += d.toString();
|
|
17523
17633
|
});
|
|
17524
|
-
proc.on("close", (code) =>
|
|
17525
|
-
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" }));
|
|
17526
17636
|
setTimeout(() => {
|
|
17527
17637
|
proc.kill();
|
|
17528
|
-
|
|
17638
|
+
resolve2({ exitCode: 124, output: output + `
|
|
17529
17639
|
[timeout]` });
|
|
17530
17640
|
}, 60000);
|
|
17531
17641
|
});
|
|
@@ -17556,13 +17666,13 @@ async function runWorkflow(workflow) {
|
|
|
17556
17666
|
|
|
17557
17667
|
// src/server/serve.ts
|
|
17558
17668
|
init_database();
|
|
17559
|
-
import { join as
|
|
17669
|
+
import { join as join16, dirname as dirname7, extname, basename as basename3, relative, resolve as resolve2, sep } from "path";
|
|
17560
17670
|
import { fileURLToPath as fileURLToPath7 } from "url";
|
|
17561
17671
|
|
|
17562
17672
|
// src/lib/registry.ts
|
|
17563
17673
|
init_builtins();
|
|
17564
|
-
import { existsSync as
|
|
17565
|
-
import { join as
|
|
17674
|
+
import { existsSync as existsSync10, readFileSync as readFileSync5 } from "fs";
|
|
17675
|
+
import { join as join11, dirname as dirname4 } from "path";
|
|
17566
17676
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
17567
17677
|
|
|
17568
17678
|
// src/lib/fuzzy.ts
|
|
@@ -25995,16 +26105,16 @@ function loadConnectorVersions() {
|
|
|
25995
26105
|
versionsLoaded = true;
|
|
25996
26106
|
const thisDir = dirname4(fileURLToPath3(import.meta.url));
|
|
25997
26107
|
const candidates = [
|
|
25998
|
-
|
|
25999
|
-
|
|
26108
|
+
join11(thisDir, "..", "connectors"),
|
|
26109
|
+
join11(thisDir, "..", "..", "connectors")
|
|
26000
26110
|
];
|
|
26001
|
-
const connectorsDir = candidates.find((d) =>
|
|
26111
|
+
const connectorsDir = candidates.find((d) => existsSync10(d));
|
|
26002
26112
|
if (!connectorsDir)
|
|
26003
26113
|
return;
|
|
26004
26114
|
for (const connector of CONNECTORS) {
|
|
26005
26115
|
try {
|
|
26006
|
-
const pkgPath =
|
|
26007
|
-
if (
|
|
26116
|
+
const pkgPath = join11(getConnectorPackagePath(connectorsDir, connector.name), "package.json");
|
|
26117
|
+
if (existsSync10(pkgPath)) {
|
|
26008
26118
|
const pkg = JSON.parse(readFileSync5(pkgPath, "utf-8"));
|
|
26009
26119
|
connector.version = pkg.version || "0.0.0";
|
|
26010
26120
|
continue;
|
|
@@ -31835,9 +31945,9 @@ data:
|
|
|
31835
31945
|
const initRequest = messages.find((m) => isInitializeRequest(m));
|
|
31836
31946
|
const clientProtocolVersion = initRequest ? initRequest.params.protocolVersion : req.headers.get("mcp-protocol-version") ?? DEFAULT_NEGOTIATED_PROTOCOL_VERSION;
|
|
31837
31947
|
if (this._enableJsonResponse) {
|
|
31838
|
-
return new Promise((
|
|
31948
|
+
return new Promise((resolve2) => {
|
|
31839
31949
|
this._streamMapping.set(streamId, {
|
|
31840
|
-
resolveJson:
|
|
31950
|
+
resolveJson: resolve2,
|
|
31841
31951
|
cleanup: () => {
|
|
31842
31952
|
this._streamMapping.delete(streamId);
|
|
31843
31953
|
}
|
|
@@ -34040,7 +34150,7 @@ class Protocol {
|
|
|
34040
34150
|
return;
|
|
34041
34151
|
}
|
|
34042
34152
|
const pollInterval = task2.pollInterval ?? this._options?.defaultTaskPollInterval ?? 1000;
|
|
34043
|
-
await new Promise((
|
|
34153
|
+
await new Promise((resolve2) => setTimeout(resolve2, pollInterval));
|
|
34044
34154
|
options?.signal?.throwIfAborted();
|
|
34045
34155
|
}
|
|
34046
34156
|
} catch (error2) {
|
|
@@ -34052,7 +34162,7 @@ class Protocol {
|
|
|
34052
34162
|
}
|
|
34053
34163
|
request(request2, resultSchema, options) {
|
|
34054
34164
|
const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options ?? {};
|
|
34055
|
-
return new Promise((
|
|
34165
|
+
return new Promise((resolve2, reject) => {
|
|
34056
34166
|
const earlyReject = (error2) => {
|
|
34057
34167
|
reject(error2);
|
|
34058
34168
|
};
|
|
@@ -34130,7 +34240,7 @@ class Protocol {
|
|
|
34130
34240
|
if (!parseResult.success) {
|
|
34131
34241
|
reject(parseResult.error);
|
|
34132
34242
|
} else {
|
|
34133
|
-
|
|
34243
|
+
resolve2(parseResult.data);
|
|
34134
34244
|
}
|
|
34135
34245
|
} catch (error2) {
|
|
34136
34246
|
reject(error2);
|
|
@@ -34321,12 +34431,12 @@ class Protocol {
|
|
|
34321
34431
|
interval = task.pollInterval;
|
|
34322
34432
|
}
|
|
34323
34433
|
} catch {}
|
|
34324
|
-
return new Promise((
|
|
34434
|
+
return new Promise((resolve2, reject) => {
|
|
34325
34435
|
if (signal.aborted) {
|
|
34326
34436
|
reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
34327
34437
|
return;
|
|
34328
34438
|
}
|
|
34329
|
-
const timeoutId = setTimeout(
|
|
34439
|
+
const timeoutId = setTimeout(resolve2, interval);
|
|
34330
34440
|
signal.addEventListener("abort", () => {
|
|
34331
34441
|
clearTimeout(timeoutId);
|
|
34332
34442
|
reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
@@ -35173,7 +35283,7 @@ class McpServer {
|
|
|
35173
35283
|
let task = createTaskResult.task;
|
|
35174
35284
|
const pollInterval = task.pollInterval ?? 5000;
|
|
35175
35285
|
while (task.status !== "completed" && task.status !== "failed" && task.status !== "cancelled") {
|
|
35176
|
-
await new Promise((
|
|
35286
|
+
await new Promise((resolve2) => setTimeout(resolve2, pollInterval));
|
|
35177
35287
|
const updatedTask = await extra.taskStore.getTask(taskId);
|
|
35178
35288
|
if (!updatedTask) {
|
|
35179
35289
|
throw new McpError(ErrorCode.InternalError, `Task ${taskId} not found during polling`);
|
|
@@ -36124,8 +36234,8 @@ init_zod();
|
|
|
36124
36234
|
init_auth();
|
|
36125
36235
|
init_database();
|
|
36126
36236
|
init_connector_resolver();
|
|
36127
|
-
import { existsSync as
|
|
36128
|
-
import { join as
|
|
36237
|
+
import { existsSync as existsSync15, readFileSync as readFileSync8 } from "fs";
|
|
36238
|
+
import { join as join15 } from "path";
|
|
36129
36239
|
import { spawn as spawn3 } from "child_process";
|
|
36130
36240
|
function registerAuthTools(server, stripped) {
|
|
36131
36241
|
server.registerTool("connector_auth_status", {
|
|
@@ -36260,8 +36370,8 @@ function registerAuthTools(server, stripped) {
|
|
|
36260
36370
|
const serverPort = port || 9876;
|
|
36261
36371
|
const oauthUrl = `http://localhost:${serverPort}/oauth/${name}/start`;
|
|
36262
36372
|
if (noBrowser) {
|
|
36263
|
-
const
|
|
36264
|
-
const tokenPaths = getConnectorConfigReadDirs(name,
|
|
36373
|
+
const connectorsHome2 = getConnectorsHome();
|
|
36374
|
+
const tokenPaths = getConnectorConfigReadDirs(name, connectorsHome2).map((dir) => join15(dir, "profiles", "default", "tokens.json"));
|
|
36265
36375
|
let serverRunning = false;
|
|
36266
36376
|
try {
|
|
36267
36377
|
await fetch(`http://localhost:${serverPort}/api/connectors`);
|
|
@@ -36274,13 +36384,13 @@ function registerAuthTools(server, stripped) {
|
|
|
36274
36384
|
stdio: "ignore"
|
|
36275
36385
|
});
|
|
36276
36386
|
serverProc.unref();
|
|
36277
|
-
await new Promise((
|
|
36387
|
+
await new Promise((resolve2) => setTimeout(resolve2, 2000));
|
|
36278
36388
|
}
|
|
36279
36389
|
let attempts = 0;
|
|
36280
36390
|
const maxAttempts = 120;
|
|
36281
36391
|
while (attempts < maxAttempts) {
|
|
36282
|
-
await new Promise((
|
|
36283
|
-
if (tokenPaths.some((tokensPath) =>
|
|
36392
|
+
await new Promise((resolve2) => setTimeout(resolve2, 500));
|
|
36393
|
+
if (tokenPaths.some((tokensPath) => existsSync15(tokensPath))) {
|
|
36284
36394
|
break;
|
|
36285
36395
|
}
|
|
36286
36396
|
attempts++;
|
|
@@ -36299,7 +36409,7 @@ function registerAuthTools(server, stripped) {
|
|
|
36299
36409
|
};
|
|
36300
36410
|
}
|
|
36301
36411
|
try {
|
|
36302
|
-
const tokensPath = tokenPaths.find((path) =>
|
|
36412
|
+
const tokensPath = tokenPaths.find((path) => existsSync15(path)) ?? tokenPaths[0];
|
|
36303
36413
|
const tokenData = JSON.parse(readFileSync8(tokensPath, "utf-8"));
|
|
36304
36414
|
return {
|
|
36305
36415
|
content: [{
|
|
@@ -37036,20 +37146,20 @@ function resolveDashboardDir() {
|
|
|
37036
37146
|
const candidates = [];
|
|
37037
37147
|
try {
|
|
37038
37148
|
const scriptDir = dirname7(fileURLToPath7(import.meta.url));
|
|
37039
|
-
candidates.push(
|
|
37040
|
-
candidates.push(
|
|
37149
|
+
candidates.push(join16(scriptDir, "..", "dashboard", "dist"));
|
|
37150
|
+
candidates.push(join16(scriptDir, "..", "..", "dashboard", "dist"));
|
|
37041
37151
|
} catch {}
|
|
37042
37152
|
if (process.argv[1]) {
|
|
37043
37153
|
const mainDir = dirname7(process.argv[1]);
|
|
37044
|
-
candidates.push(
|
|
37045
|
-
candidates.push(
|
|
37154
|
+
candidates.push(join16(mainDir, "..", "dashboard", "dist"));
|
|
37155
|
+
candidates.push(join16(mainDir, "..", "..", "dashboard", "dist"));
|
|
37046
37156
|
}
|
|
37047
|
-
candidates.push(
|
|
37157
|
+
candidates.push(join16(process.cwd(), "dashboard", "dist"));
|
|
37048
37158
|
for (const candidate of candidates) {
|
|
37049
|
-
if (
|
|
37159
|
+
if (existsSync16(candidate))
|
|
37050
37160
|
return candidate;
|
|
37051
37161
|
}
|
|
37052
|
-
return
|
|
37162
|
+
return join16(process.cwd(), "dashboard", "dist");
|
|
37053
37163
|
}
|
|
37054
37164
|
var MIME_TYPES = {
|
|
37055
37165
|
".html": "text/html; charset=utf-8",
|
|
@@ -37148,7 +37258,7 @@ function oauthPage(type, title, message, hint, extra) {
|
|
|
37148
37258
|
</body></html>`;
|
|
37149
37259
|
}
|
|
37150
37260
|
function serveStaticFile(filePath) {
|
|
37151
|
-
if (!
|
|
37261
|
+
if (!existsSync16(filePath))
|
|
37152
37262
|
return null;
|
|
37153
37263
|
const ext = extname(filePath);
|
|
37154
37264
|
const contentType2 = MIME_TYPES[ext] || "application/octet-stream";
|
|
@@ -37185,7 +37295,7 @@ async function startServer(requestedPort, options) {
|
|
|
37185
37295
|
const strict = options?.strict ?? false;
|
|
37186
37296
|
loadConnectorVersions();
|
|
37187
37297
|
const dashboardDir = resolveDashboardDir();
|
|
37188
|
-
const dashboardExists =
|
|
37298
|
+
const dashboardExists = existsSync16(dashboardDir);
|
|
37189
37299
|
if (!dashboardExists) {
|
|
37190
37300
|
console.error(`
|
|
37191
37301
|
Dashboard not found at: ${dashboardDir}`);
|
|
@@ -37616,8 +37726,8 @@ ${result.stderr}`;
|
|
|
37616
37726
|
const profiles = listProfiles4(name);
|
|
37617
37727
|
let current = "default";
|
|
37618
37728
|
for (const configDir of getConnectorConfigReadDirs(name)) {
|
|
37619
|
-
const currentProfileFile =
|
|
37620
|
-
if (
|
|
37729
|
+
const currentProfileFile = join16(configDir, "current_profile");
|
|
37730
|
+
if (existsSync16(currentProfileFile)) {
|
|
37621
37731
|
try {
|
|
37622
37732
|
current = readFileSync9(currentProfileFile, "utf-8").trim() || "default";
|
|
37623
37733
|
} catch {}
|
|
@@ -37670,25 +37780,25 @@ ${result.stderr}`;
|
|
|
37670
37780
|
try {
|
|
37671
37781
|
const connectDir = getConnectorsHome();
|
|
37672
37782
|
const result = {};
|
|
37673
|
-
if (
|
|
37783
|
+
if (existsSync16(connectDir)) {
|
|
37674
37784
|
for (const connectorName of listConfiguredConnectorNames(connectDir)) {
|
|
37675
37785
|
const profiles = {};
|
|
37676
37786
|
for (const configDir of [...getConnectorConfigReadDirs(connectorName, connectDir)].reverse()) {
|
|
37677
|
-
const profilesDir =
|
|
37678
|
-
if (!
|
|
37787
|
+
const profilesDir = join16(configDir, "profiles");
|
|
37788
|
+
if (!existsSync16(profilesDir))
|
|
37679
37789
|
continue;
|
|
37680
37790
|
const profileEntries = readdirSync9(profilesDir, { withFileTypes: true });
|
|
37681
37791
|
for (const pEntry of profileEntries) {
|
|
37682
37792
|
if (pEntry.isFile() && pEntry.name.endsWith(".json")) {
|
|
37683
37793
|
const profileName = basename3(pEntry.name, ".json");
|
|
37684
37794
|
try {
|
|
37685
|
-
const config2 = JSON.parse(readFileSync9(
|
|
37795
|
+
const config2 = JSON.parse(readFileSync9(join16(profilesDir, pEntry.name), "utf-8"));
|
|
37686
37796
|
profiles[profileName] = config2;
|
|
37687
37797
|
} catch {}
|
|
37688
37798
|
}
|
|
37689
37799
|
if (pEntry.isDirectory()) {
|
|
37690
|
-
const configPath =
|
|
37691
|
-
if (
|
|
37800
|
+
const configPath = join16(profilesDir, pEntry.name, "config.json");
|
|
37801
|
+
if (existsSync16(configPath)) {
|
|
37692
37802
|
try {
|
|
37693
37803
|
const config2 = JSON.parse(readFileSync9(configPath, "utf-8"));
|
|
37694
37804
|
profiles[pEntry.name] = config2;
|
|
@@ -37733,12 +37843,12 @@ ${result.stderr}`;
|
|
|
37733
37843
|
if (!data.profiles || typeof data.profiles !== "object")
|
|
37734
37844
|
continue;
|
|
37735
37845
|
const connectorDir = getConnectorConfigDir(connectorName, connectDir);
|
|
37736
|
-
const profilesDir =
|
|
37846
|
+
const profilesDir = join16(connectorDir, "profiles");
|
|
37737
37847
|
for (const [profileName, config2] of Object.entries(data.profiles)) {
|
|
37738
37848
|
if (!config2 || typeof config2 !== "object")
|
|
37739
37849
|
continue;
|
|
37740
37850
|
mkdirSync9(profilesDir, { recursive: true });
|
|
37741
|
-
const profileFile =
|
|
37851
|
+
const profileFile = join16(profilesDir, `${profileName}.json`);
|
|
37742
37852
|
writeFileSync7(profileFile, JSON.stringify(config2, null, 2));
|
|
37743
37853
|
imported++;
|
|
37744
37854
|
}
|
|
@@ -37794,15 +37904,15 @@ ${result.stderr}`;
|
|
|
37794
37904
|
}
|
|
37795
37905
|
if (dashboardExists && (method === "GET" || method === "HEAD")) {
|
|
37796
37906
|
if (path3 !== "/") {
|
|
37797
|
-
const filePath =
|
|
37798
|
-
const rel = relative(dashboardDir,
|
|
37907
|
+
const filePath = join16(dashboardDir, path3);
|
|
37908
|
+
const rel = relative(dashboardDir, resolve2(filePath));
|
|
37799
37909
|
if (!rel.startsWith("..") && !rel.includes(`..${sep}`) && rel !== "") {
|
|
37800
37910
|
const res2 = serveStaticFile(filePath);
|
|
37801
37911
|
if (res2)
|
|
37802
37912
|
return res2;
|
|
37803
37913
|
}
|
|
37804
37914
|
}
|
|
37805
|
-
const indexPath =
|
|
37915
|
+
const indexPath = join16(dashboardDir, "index.html");
|
|
37806
37916
|
const res = serveStaticFile(indexPath);
|
|
37807
37917
|
if (res)
|
|
37808
37918
|
return res;
|