@alfe.ai/gateway 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/gateway.js +1 -1
- package/dist/health.js +237 -47
- package/dist/src/index.d.ts +10 -1
- package/dist/src/index.js +2 -2
- package/package.json +2 -2
package/dist/bin/gateway.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { a as installService,
|
|
2
|
+
import { a as installService, c as uninstallService, f as SOCKET_PATH, g as LOG_FILE, i as checkExistingDaemon, n as queryDaemonHealth, r as startDaemon, s as stopExistingDaemon, t as formatHealthReport } from "../health.js";
|
|
3
3
|
import { spawn } from "node:child_process";
|
|
4
4
|
//#region bin/gateway.ts
|
|
5
5
|
/**
|
package/dist/health.js
CHANGED
|
@@ -104,6 +104,15 @@ const ID_PREFIXES = {
|
|
|
104
104
|
transaction: "txn",
|
|
105
105
|
subscription: "sub",
|
|
106
106
|
conversation: "conv",
|
|
107
|
+
referral: "ref",
|
|
108
|
+
promoCode: "prc",
|
|
109
|
+
promoRedemption: "prr",
|
|
110
|
+
pendingPromo: "pdp",
|
|
111
|
+
webhook: "whk",
|
|
112
|
+
webhookDelivery: "wdl",
|
|
113
|
+
onboardingSession: "obs",
|
|
114
|
+
inviteToken: "inv",
|
|
115
|
+
claimToken: "clm",
|
|
107
116
|
run: "run",
|
|
108
117
|
request: "req",
|
|
109
118
|
connection: "conn",
|
|
@@ -381,6 +390,21 @@ var AuthService = class {
|
|
|
381
390
|
deleteToken(tokenId) {
|
|
382
391
|
return this.client.request(`${this.prefix}/tokens/${tokenId}`, { method: "DELETE" });
|
|
383
392
|
}
|
|
393
|
+
getReferralCode() {
|
|
394
|
+
return this.client.request(`${this.prefix}/referral/code`);
|
|
395
|
+
}
|
|
396
|
+
redeemCode(code) {
|
|
397
|
+
return this.client.request(`${this.prefix}/referral/redeem`, {
|
|
398
|
+
method: "POST",
|
|
399
|
+
body: JSON.stringify({ code })
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
getReferralStatus() {
|
|
403
|
+
return this.client.request(`${this.prefix}/referral/status`);
|
|
404
|
+
}
|
|
405
|
+
getReferralHistory() {
|
|
406
|
+
return this.client.request(`${this.prefix}/referral/history`);
|
|
407
|
+
}
|
|
384
408
|
};
|
|
385
409
|
//#endregion
|
|
386
410
|
//#region ../../packages-internal/types/dist/lib/enum-values.js
|
|
@@ -3069,7 +3093,8 @@ enumValues({
|
|
|
3069
3093
|
});
|
|
3070
3094
|
enumValues({
|
|
3071
3095
|
Anthropic: "anthropic",
|
|
3072
|
-
OpenAI: "openai"
|
|
3096
|
+
OpenAI: "openai",
|
|
3097
|
+
ElevenLabs: "elevenlabs"
|
|
3073
3098
|
});
|
|
3074
3099
|
enumValues({
|
|
3075
3100
|
Month: "month",
|
|
@@ -3095,6 +3120,7 @@ enumValues({
|
|
|
3095
3120
|
Provisioning: "provisioning",
|
|
3096
3121
|
Running: "running",
|
|
3097
3122
|
Stopped: "stopped",
|
|
3123
|
+
Failing: "failing",
|
|
3098
3124
|
Failed: "failed",
|
|
3099
3125
|
BillingSuspended: "billing_suspended"
|
|
3100
3126
|
});
|
|
@@ -3121,6 +3147,8 @@ enumValues({
|
|
|
3121
3147
|
SubscriptionCredit: "subscription_credit",
|
|
3122
3148
|
AutoRecharge: "auto_recharge",
|
|
3123
3149
|
AdminGift: "admin_gift",
|
|
3150
|
+
ReferralCredit: "referral_credit",
|
|
3151
|
+
PromoCredit: "promo_credit",
|
|
3124
3152
|
Refund: "refund"
|
|
3125
3153
|
});
|
|
3126
3154
|
enumValues({
|
|
@@ -3134,6 +3162,36 @@ enumValues({
|
|
|
3134
3162
|
Week: "week",
|
|
3135
3163
|
Month: "month"
|
|
3136
3164
|
});
|
|
3165
|
+
enumValues({
|
|
3166
|
+
Active: "active",
|
|
3167
|
+
Paused: "paused",
|
|
3168
|
+
Revoked: "revoked"
|
|
3169
|
+
});
|
|
3170
|
+
enumValues({
|
|
3171
|
+
Pending: "pending",
|
|
3172
|
+
Completed: "completed",
|
|
3173
|
+
Failed: "failed"
|
|
3174
|
+
});
|
|
3175
|
+
enumValues({
|
|
3176
|
+
BalanceCredit: "balance_credit",
|
|
3177
|
+
SubscriptionDiscount: "subscription_discount",
|
|
3178
|
+
FreeTrial: "free_trial"
|
|
3179
|
+
});
|
|
3180
|
+
enumValues({
|
|
3181
|
+
Active: "active",
|
|
3182
|
+
Paused: "paused",
|
|
3183
|
+
Revoked: "revoked"
|
|
3184
|
+
});
|
|
3185
|
+
enumValues({
|
|
3186
|
+
Pending: "pending",
|
|
3187
|
+
Completed: "completed",
|
|
3188
|
+
Failed: "failed"
|
|
3189
|
+
});
|
|
3190
|
+
enumValues({
|
|
3191
|
+
Pending: "pending",
|
|
3192
|
+
Consumed: "consumed",
|
|
3193
|
+
Expired: "expired"
|
|
3194
|
+
});
|
|
3137
3195
|
enumValues({
|
|
3138
3196
|
Synced: "synced",
|
|
3139
3197
|
Stale: "stale",
|
|
@@ -3183,6 +3241,31 @@ _enum(OPENAI_MODELS);
|
|
|
3183
3241
|
_enum([...ANTHROPIC_MODELS, ...OPENAI_MODELS]);
|
|
3184
3242
|
AnthropicModel.Opus, AnthropicModel.Sonnet, AnthropicModel.Haiku, OpenAIModel.GPT4o, OpenAIModel.GPT4oMini, OpenAIModel.O3;
|
|
3185
3243
|
AnthropicModel.Opus, AnthropicModel.Sonnet, AnthropicModel.Haiku, OpenAIModel.GPT4o, OpenAIModel.GPT4oMini, OpenAIModel.O3;
|
|
3244
|
+
enumValues({
|
|
3245
|
+
PendingChallenge: "pending_challenge",
|
|
3246
|
+
Creating: "creating",
|
|
3247
|
+
Complete: "complete",
|
|
3248
|
+
Failed: "failed",
|
|
3249
|
+
Expired: "expired"
|
|
3250
|
+
});
|
|
3251
|
+
enumValues({
|
|
3252
|
+
Active: "active",
|
|
3253
|
+
Used: "used",
|
|
3254
|
+
Expired: "expired",
|
|
3255
|
+
Revoked: "revoked"
|
|
3256
|
+
});
|
|
3257
|
+
enumValues({
|
|
3258
|
+
Pending: "pending",
|
|
3259
|
+
Claimed: "claimed",
|
|
3260
|
+
Expired: "expired"
|
|
3261
|
+
});
|
|
3262
|
+
enumValues({
|
|
3263
|
+
Mcp: "mcp",
|
|
3264
|
+
Api: "api",
|
|
3265
|
+
Cli: "cli",
|
|
3266
|
+
Dashboard: "dashboard",
|
|
3267
|
+
Agent: "agent"
|
|
3268
|
+
});
|
|
3186
3269
|
//#endregion
|
|
3187
3270
|
//#region src/config.ts
|
|
3188
3271
|
/**
|
|
@@ -3337,7 +3420,8 @@ async function loadManagedConfig() {
|
|
|
3337
3420
|
agentId: identity.agentId,
|
|
3338
3421
|
orgId: identity.orgId,
|
|
3339
3422
|
runtime: identity.runtime,
|
|
3340
|
-
runtimes: identity.runtime === "openclaw" ? { openclaw: { workspace: join(homedir(), ".openclaw") } } : {}
|
|
3423
|
+
runtimes: identity.runtime === "openclaw" ? { openclaw: { workspace: join(homedir(), ".openclaw") } } : {},
|
|
3424
|
+
autoStartRuntime: true
|
|
3341
3425
|
};
|
|
3342
3426
|
}
|
|
3343
3427
|
/**
|
|
@@ -3368,7 +3452,8 @@ async function loadDaemonConfig() {
|
|
|
3368
3452
|
agentId: identity.agentId,
|
|
3369
3453
|
orgId: identity.orgId,
|
|
3370
3454
|
runtime: identity.runtime,
|
|
3371
|
-
runtimes
|
|
3455
|
+
runtimes,
|
|
3456
|
+
autoStartRuntime: alfeConfig.auto_start_runtime ?? false
|
|
3372
3457
|
};
|
|
3373
3458
|
}
|
|
3374
3459
|
/**
|
|
@@ -4441,6 +4526,12 @@ var CommandQueue = class {
|
|
|
4441
4526
|
*/
|
|
4442
4527
|
const LAUNCHD_LABEL = "ai.alfe.gateway";
|
|
4443
4528
|
const SYSTEMD_SERVICE = "alfe-gateway";
|
|
4529
|
+
function isRootUser() {
|
|
4530
|
+
return process.getuid?.() === 0;
|
|
4531
|
+
}
|
|
4532
|
+
function getSystemdSystemServicePath() {
|
|
4533
|
+
return `/etc/systemd/system/${SYSTEMD_SERVICE}.service`;
|
|
4534
|
+
}
|
|
4444
4535
|
function getLaunchdPlistPath() {
|
|
4445
4536
|
return join(homedir(), "Library", "LaunchAgents", `${LAUNCHD_LABEL}.plist`);
|
|
4446
4537
|
}
|
|
@@ -4501,9 +4592,13 @@ function generateLaunchdPlist() {
|
|
|
4501
4592
|
</plist>`;
|
|
4502
4593
|
}
|
|
4503
4594
|
/**
|
|
4504
|
-
* Generate a systemd
|
|
4595
|
+
* Generate a systemd unit for Linux.
|
|
4596
|
+
* Root users get a system-level unit; non-root get a user-level unit.
|
|
4505
4597
|
*/
|
|
4506
4598
|
function generateSystemdUnit() {
|
|
4599
|
+
const nodePath = getNodePath();
|
|
4600
|
+
const gatewayBin = getGatewayBinPath();
|
|
4601
|
+
const root = isRootUser();
|
|
4507
4602
|
return `[Unit]
|
|
4508
4603
|
Description=Alfe Gateway Daemon
|
|
4509
4604
|
After=network-online.target
|
|
@@ -4511,13 +4606,13 @@ Wants=network-online.target
|
|
|
4511
4606
|
|
|
4512
4607
|
[Service]
|
|
4513
4608
|
Type=simple
|
|
4514
|
-
ExecStart=${
|
|
4609
|
+
ExecStart=${nodePath} ${gatewayBin} daemon
|
|
4515
4610
|
Restart=always
|
|
4516
4611
|
RestartSec=10
|
|
4517
|
-
Environment=NODE_ENV=production
|
|
4612
|
+
Environment=NODE_ENV=production${root ? "\nEnvironment=HOME=/root\nWorkingDirectory=/root" : ""}
|
|
4518
4613
|
|
|
4519
4614
|
[Install]
|
|
4520
|
-
WantedBy
|
|
4615
|
+
WantedBy=${root ? "multi-user.target" : "default.target"}`;
|
|
4521
4616
|
}
|
|
4522
4617
|
/**
|
|
4523
4618
|
* Install the service unit for the current platform.
|
|
@@ -4558,31 +4653,57 @@ async function uninstallLaunchd() {
|
|
|
4558
4653
|
return `Uninstalled: ${plistPath}`;
|
|
4559
4654
|
}
|
|
4560
4655
|
async function installSystemd() {
|
|
4561
|
-
const
|
|
4562
|
-
|
|
4656
|
+
const root = isRootUser();
|
|
4657
|
+
const unitPath = root ? getSystemdSystemServicePath() : getSystemdServicePath();
|
|
4658
|
+
const dir = root ? "/etc/systemd/system" : join(homedir(), ".config", "systemd", "user");
|
|
4659
|
+
const ctl = root ? "systemctl" : "systemctl --user";
|
|
4660
|
+
if (!root) await mkdir(dir, { recursive: true });
|
|
4563
4661
|
await writeFile(unitPath, generateSystemdUnit(), "utf-8");
|
|
4564
|
-
logger$1.info({
|
|
4662
|
+
logger$1.info({
|
|
4663
|
+
path: unitPath,
|
|
4664
|
+
root
|
|
4665
|
+
}, "Wrote systemd unit");
|
|
4565
4666
|
try {
|
|
4566
|
-
execSync(
|
|
4567
|
-
execSync(
|
|
4667
|
+
execSync(`${ctl} daemon-reload`, { stdio: "pipe" });
|
|
4668
|
+
execSync(`${ctl} enable ${SYSTEMD_SERVICE}`, { stdio: "pipe" });
|
|
4568
4669
|
} catch {}
|
|
4569
|
-
return `Installed: ${unitPath}\nService enabled for user session.`;
|
|
4670
|
+
return `Installed: ${unitPath}\nService enabled${root ? " (system-level)" : " for user session"}.`;
|
|
4570
4671
|
}
|
|
4571
4672
|
async function uninstallSystemd() {
|
|
4572
|
-
const
|
|
4673
|
+
const root = isRootUser();
|
|
4674
|
+
const unitPath = root ? getSystemdSystemServicePath() : getSystemdServicePath();
|
|
4675
|
+
const ctl = root ? "systemctl" : "systemctl --user";
|
|
4573
4676
|
try {
|
|
4574
|
-
execSync(
|
|
4575
|
-
execSync(
|
|
4677
|
+
execSync(`${ctl} disable ${SYSTEMD_SERVICE}`, { stdio: "pipe" });
|
|
4678
|
+
execSync(`${ctl} stop ${SYSTEMD_SERVICE}`, { stdio: "pipe" });
|
|
4576
4679
|
} catch {}
|
|
4577
4680
|
try {
|
|
4578
4681
|
await unlink(unitPath);
|
|
4579
4682
|
} catch {}
|
|
4580
4683
|
try {
|
|
4581
|
-
execSync(
|
|
4684
|
+
execSync(`${ctl} daemon-reload`, { stdio: "pipe" });
|
|
4582
4685
|
} catch {}
|
|
4583
4686
|
return `Uninstalled: ${unitPath}`;
|
|
4584
4687
|
}
|
|
4585
4688
|
/**
|
|
4689
|
+
* Start the installed service via systemctl/launchctl.
|
|
4690
|
+
*/
|
|
4691
|
+
function startService() {
|
|
4692
|
+
const platform = process.platform;
|
|
4693
|
+
if (platform === "darwin") {
|
|
4694
|
+
const plistPath = getLaunchdPlistPath();
|
|
4695
|
+
execSync(`launchctl start ${LAUNCHD_LABEL}`, { stdio: "pipe" });
|
|
4696
|
+
logger$1.info({ path: plistPath }, "Started launchd service");
|
|
4697
|
+
return;
|
|
4698
|
+
}
|
|
4699
|
+
if (platform === "linux") {
|
|
4700
|
+
execSync(`${isRootUser() ? "systemctl" : "systemctl --user"} start ${SYSTEMD_SERVICE}`, { stdio: "pipe" });
|
|
4701
|
+
logger$1.info("Started systemd service");
|
|
4702
|
+
return;
|
|
4703
|
+
}
|
|
4704
|
+
throw new Error(`Unsupported platform: ${platform}`);
|
|
4705
|
+
}
|
|
4706
|
+
/**
|
|
4586
4707
|
* Write the current process PID to the PID file.
|
|
4587
4708
|
*/
|
|
4588
4709
|
async function writePidFile() {
|
|
@@ -19918,6 +20039,8 @@ let integrationManager;
|
|
|
19918
20039
|
let aiProxyServer = null;
|
|
19919
20040
|
let runtimeProcess = null;
|
|
19920
20041
|
let localRelay = null;
|
|
20042
|
+
let aiProxyUrl = null;
|
|
20043
|
+
let aiProxyRunning = false;
|
|
19921
20044
|
let cloudConnected = false;
|
|
19922
20045
|
let shuttingDown = false;
|
|
19923
20046
|
/**
|
|
@@ -19968,20 +20091,21 @@ async function startDaemon() {
|
|
|
19968
20091
|
commandQueue.startGC();
|
|
19969
20092
|
logger$1.debug("Starting AI proxy...");
|
|
19970
20093
|
try {
|
|
19971
|
-
const { createProxyServer } = await import("@alfe.ai/ai-proxy-local");
|
|
20094
|
+
const { createProxyServer, DEFAULT_AI_PROXY_PORT } = await import("@alfe.ai/ai-proxy-local");
|
|
19972
20095
|
const { getAiServiceUrlFromToken } = await import("@alfe.ai/config");
|
|
19973
20096
|
const proxyUrl = getAiServiceUrlFromToken(config.apiKey);
|
|
19974
|
-
const AI_PROXY_PORT = 18193;
|
|
19975
20097
|
aiProxyServer = createProxyServer({
|
|
19976
|
-
port:
|
|
20098
|
+
port: DEFAULT_AI_PROXY_PORT,
|
|
19977
20099
|
apiKey: config.apiKey,
|
|
19978
20100
|
proxyUrl
|
|
19979
20101
|
});
|
|
19980
20102
|
const server = aiProxyServer;
|
|
19981
20103
|
await new Promise((resolve, reject) => {
|
|
19982
|
-
server.listen(
|
|
20104
|
+
server.listen(DEFAULT_AI_PROXY_PORT, "127.0.0.1", () => {
|
|
20105
|
+
aiProxyRunning = true;
|
|
20106
|
+
aiProxyUrl = `http://127.0.0.1:${String(DEFAULT_AI_PROXY_PORT)}`;
|
|
19983
20107
|
logger$1.info({
|
|
19984
|
-
port:
|
|
20108
|
+
port: DEFAULT_AI_PROXY_PORT,
|
|
19985
20109
|
upstream: proxyUrl
|
|
19986
20110
|
}, "AI proxy started");
|
|
19987
20111
|
resolve();
|
|
@@ -20042,8 +20166,8 @@ async function startDaemon() {
|
|
|
20042
20166
|
cloudClient.setIntegrationManager(integrationAdapter);
|
|
20043
20167
|
cloudClient.start();
|
|
20044
20168
|
logger$1.debug("Cloud client started");
|
|
20045
|
-
if (
|
|
20046
|
-
logger$1.debug({ runtime: config.runtime }, "Starting agent runtime
|
|
20169
|
+
if (config.autoStartRuntime && config.runtime) {
|
|
20170
|
+
logger$1.debug({ runtime: config.runtime }, "Starting agent runtime...");
|
|
20047
20171
|
const runtimeCfg = config.runtimes[config.runtime];
|
|
20048
20172
|
if (runtimeCfg) {
|
|
20049
20173
|
const runtimeToken = randomUUID();
|
|
@@ -20059,8 +20183,8 @@ async function startDaemon() {
|
|
|
20059
20183
|
ALFE_API_KEY: config.apiKey,
|
|
20060
20184
|
ALFE_API_URL: config.apiEndpoint,
|
|
20061
20185
|
ALFE_AGENT_ID: config.agentId,
|
|
20062
|
-
ANTHROPIC_BASE_URL: "http://127.0.0.1:18193",
|
|
20063
|
-
OPENAI_BASE_URL: "http://127.0.0.1:18193",
|
|
20186
|
+
ANTHROPIC_BASE_URL: aiProxyUrl ?? "http://127.0.0.1:18193",
|
|
20187
|
+
OPENAI_BASE_URL: aiProxyUrl ?? "http://127.0.0.1:18193",
|
|
20064
20188
|
OPENCLAW_GATEWAY_TOKEN: runtimeToken
|
|
20065
20189
|
}
|
|
20066
20190
|
});
|
|
@@ -20113,6 +20237,7 @@ async function startDaemon() {
|
|
|
20113
20237
|
resolve();
|
|
20114
20238
|
});
|
|
20115
20239
|
});
|
|
20240
|
+
aiProxyRunning = false;
|
|
20116
20241
|
logger$1.debug("AI proxy stopped");
|
|
20117
20242
|
}
|
|
20118
20243
|
logger$1.debug("Stopping cloud client...");
|
|
@@ -20137,33 +20262,94 @@ async function startDaemon() {
|
|
|
20137
20262
|
}, "Alfe Gateway Daemon started ✅");
|
|
20138
20263
|
}
|
|
20139
20264
|
async function handleCloudCommand(command) {
|
|
20140
|
-
if (command.command === "support.diagnostic")
|
|
20141
|
-
const { runDiagnostic } = await import("@alfe.ai/doctor");
|
|
20265
|
+
if (command.command === "support.diagnostic") {
|
|
20142
20266
|
const payload = command.payload;
|
|
20143
|
-
|
|
20144
|
-
const report = await runDiagnostic({
|
|
20145
|
-
task: payload.task,
|
|
20146
|
-
workspacePath,
|
|
20147
|
-
timeoutSeconds: 300
|
|
20148
|
-
});
|
|
20149
|
-
return {
|
|
20150
|
-
type: "COMMAND_ACK",
|
|
20151
|
-
commandId: command.commandId,
|
|
20152
|
-
status: report.success ? "ok" : "error",
|
|
20153
|
-
result: report
|
|
20154
|
-
};
|
|
20155
|
-
} catch (err) {
|
|
20156
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
20157
|
-
logger$1.error({ err: message }, "Diagnostic failed");
|
|
20158
|
-
return {
|
|
20267
|
+
if (!payload.apiKey && !aiProxyRunning) return {
|
|
20159
20268
|
type: "COMMAND_ACK",
|
|
20160
20269
|
commandId: command.commandId,
|
|
20161
20270
|
status: "error",
|
|
20162
20271
|
result: {
|
|
20163
|
-
code: "
|
|
20164
|
-
message
|
|
20272
|
+
code: "PROXY_NOT_RUNNING",
|
|
20273
|
+
message: "AI proxy is not running — diagnostic requires LLM access"
|
|
20165
20274
|
}
|
|
20166
20275
|
};
|
|
20276
|
+
let proxyUrl;
|
|
20277
|
+
if (aiProxyRunning) proxyUrl = aiProxyUrl ?? void 0;
|
|
20278
|
+
else {
|
|
20279
|
+
const { getAiServiceUrlFromToken } = await import("@alfe.ai/config");
|
|
20280
|
+
proxyUrl = getAiServiceUrlFromToken(config.apiKey);
|
|
20281
|
+
}
|
|
20282
|
+
try {
|
|
20283
|
+
const { runDiagnostic } = await import("@alfe.ai/doctor");
|
|
20284
|
+
const workspacePath = Object.values(config.runtimes)[0]?.workspace ?? "~/.openclaw";
|
|
20285
|
+
const report = await runDiagnostic({
|
|
20286
|
+
task: payload.task,
|
|
20287
|
+
workspacePath,
|
|
20288
|
+
timeoutSeconds: 300,
|
|
20289
|
+
proxyUrl,
|
|
20290
|
+
apiKey: payload.apiKey
|
|
20291
|
+
});
|
|
20292
|
+
return {
|
|
20293
|
+
type: "COMMAND_ACK",
|
|
20294
|
+
commandId: command.commandId,
|
|
20295
|
+
status: report.success ? "ok" : "error",
|
|
20296
|
+
result: report
|
|
20297
|
+
};
|
|
20298
|
+
} catch (err) {
|
|
20299
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
20300
|
+
logger$1.error({ err: message }, "Diagnostic failed");
|
|
20301
|
+
return {
|
|
20302
|
+
type: "COMMAND_ACK",
|
|
20303
|
+
commandId: command.commandId,
|
|
20304
|
+
status: "error",
|
|
20305
|
+
result: {
|
|
20306
|
+
code: "DIAGNOSTIC_FAILED",
|
|
20307
|
+
message
|
|
20308
|
+
}
|
|
20309
|
+
};
|
|
20310
|
+
}
|
|
20311
|
+
}
|
|
20312
|
+
if (command.command === "integration.status") {
|
|
20313
|
+
const payload = command.payload;
|
|
20314
|
+
try {
|
|
20315
|
+
if (payload?.integrationId) {
|
|
20316
|
+
const info = integrationManager.get(payload.integrationId);
|
|
20317
|
+
if (!info) return {
|
|
20318
|
+
type: "COMMAND_ACK",
|
|
20319
|
+
commandId: command.commandId,
|
|
20320
|
+
status: "error",
|
|
20321
|
+
result: {
|
|
20322
|
+
code: "NOT_FOUND",
|
|
20323
|
+
message: `Integration "${payload.integrationId}" not found`
|
|
20324
|
+
}
|
|
20325
|
+
};
|
|
20326
|
+
return {
|
|
20327
|
+
type: "COMMAND_ACK",
|
|
20328
|
+
commandId: command.commandId,
|
|
20329
|
+
status: "ok",
|
|
20330
|
+
result: { integrations: [info] }
|
|
20331
|
+
};
|
|
20332
|
+
}
|
|
20333
|
+
const integrations = integrationManager.list();
|
|
20334
|
+
return {
|
|
20335
|
+
type: "COMMAND_ACK",
|
|
20336
|
+
commandId: command.commandId,
|
|
20337
|
+
status: "ok",
|
|
20338
|
+
result: { integrations }
|
|
20339
|
+
};
|
|
20340
|
+
} catch (err) {
|
|
20341
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
20342
|
+
logger$1.error({ err: message }, "Integration status failed");
|
|
20343
|
+
return {
|
|
20344
|
+
type: "COMMAND_ACK",
|
|
20345
|
+
commandId: command.commandId,
|
|
20346
|
+
status: "error",
|
|
20347
|
+
result: {
|
|
20348
|
+
code: "STATUS_FAILED",
|
|
20349
|
+
message
|
|
20350
|
+
}
|
|
20351
|
+
};
|
|
20352
|
+
}
|
|
20167
20353
|
}
|
|
20168
20354
|
const ipcRequest = cloudCommandToIPCRequest(command);
|
|
20169
20355
|
if (!ipcRequest) {
|
|
@@ -20249,6 +20435,7 @@ function handleStatus() {
|
|
|
20249
20435
|
status: cloudConnected ? "connected" : "disconnected",
|
|
20250
20436
|
latencyMs: cloudClient.getLatencyMs()
|
|
20251
20437
|
},
|
|
20438
|
+
aiProxy: { status: aiProxyRunning ? "running" : "stopped" },
|
|
20252
20439
|
plugins: (ipcServer?.getRegisteredPlugins() ?? []).map(([, info]) => ({
|
|
20253
20440
|
name: info.name,
|
|
20254
20441
|
version: info.version,
|
|
@@ -20336,6 +20523,7 @@ async function queryDaemonHealth(socketPath, timeoutMs = 5e3) {
|
|
|
20336
20523
|
if (err.code === "ECONNREFUSED" || err.code === "ENOENT") resolve({
|
|
20337
20524
|
daemon: { status: "stopped" },
|
|
20338
20525
|
cloud: { status: "unknown" },
|
|
20526
|
+
aiProxy: { status: "stopped" },
|
|
20339
20527
|
plugins: [],
|
|
20340
20528
|
commandQueue: { totalPending: 0 }
|
|
20341
20529
|
});
|
|
@@ -20352,6 +20540,8 @@ function formatHealthReport(health) {
|
|
|
20352
20540
|
lines.push(` Gateway daemon ${daemonIcon} ${health.daemon.status}` + (health.daemon.uptime ? ` (uptime: ${formatUptime(health.daemon.uptime)})` : "") + (health.daemon.version ? ` v${health.daemon.version}` : ""));
|
|
20353
20541
|
const cloudIcon = health.cloud.status === "connected" ? "✓" : "✗";
|
|
20354
20542
|
lines.push(` Cloud connection ${cloudIcon} ${health.cloud.status}` + (health.cloud.latencyMs !== void 0 ? ` (latency: ${String(health.cloud.latencyMs)}ms)` : ""));
|
|
20543
|
+
const proxyIcon = health.aiProxy.status === "running" ? "✓" : "✗";
|
|
20544
|
+
lines.push(` AI proxy ${proxyIcon} ${health.aiProxy.status}`);
|
|
20355
20545
|
if (health.plugins.length === 0) lines.push(" Plugins – none connected");
|
|
20356
20546
|
else for (const plugin of health.plugins) {
|
|
20357
20547
|
const lastSeenAgo = Date.now() - plugin.lastSeen;
|
|
@@ -20373,4 +20563,4 @@ function formatDuration(ms) {
|
|
|
20373
20563
|
return `${String(Math.round(seconds / 3600))}h`;
|
|
20374
20564
|
}
|
|
20375
20565
|
//#endregion
|
|
20376
|
-
export { installService as a,
|
|
20566
|
+
export { logger$1 as _, installService as a, uninstallService as c, PID_PATH as d, SOCKET_PATH as f, LOG_FILE as g, resolveAgentIdentity as h, checkExistingDaemon as i, PROTOCOL_VERSION as l, loadDaemonConfig as m, queryDaemonHealth as n, startService as o, fetchAgentConfig as p, startDaemon as r, stopExistingDaemon as s, formatHealthReport as t, ALFE_DIR as u };
|
package/dist/src/index.d.ts
CHANGED
|
@@ -60,6 +60,8 @@ interface DaemonConfig {
|
|
|
60
60
|
runtime: string;
|
|
61
61
|
/** Runtime configurations keyed by runtime name (e.g. 'openclaw') */
|
|
62
62
|
runtimes: Record<string, RuntimeConfig>;
|
|
63
|
+
/** Whether to auto-start the agent runtime process (e.g. openclaw) */
|
|
64
|
+
autoStartRuntime: boolean;
|
|
63
65
|
}
|
|
64
66
|
interface AgentIdentity {
|
|
65
67
|
agentId: string;
|
|
@@ -113,6 +115,9 @@ interface DaemonHealth {
|
|
|
113
115
|
status: 'connected' | 'disconnected' | 'unknown';
|
|
114
116
|
latencyMs?: number;
|
|
115
117
|
};
|
|
118
|
+
aiProxy: {
|
|
119
|
+
status: 'running' | 'stopped';
|
|
120
|
+
};
|
|
116
121
|
plugins: {
|
|
117
122
|
name: string;
|
|
118
123
|
version: string;
|
|
@@ -152,6 +157,10 @@ declare function installService(): Promise<string>;
|
|
|
152
157
|
* Uninstall the service unit for the current platform.
|
|
153
158
|
*/
|
|
154
159
|
declare function uninstallService(): Promise<string>;
|
|
160
|
+
/**
|
|
161
|
+
* Start the installed service via systemctl/launchctl.
|
|
162
|
+
*/
|
|
163
|
+
declare function startService(): void;
|
|
155
164
|
/**
|
|
156
165
|
* Write the current process PID to the PID file.
|
|
157
166
|
*/
|
|
@@ -166,4 +175,4 @@ declare function checkExistingDaemon(): Promise<number | null>;
|
|
|
166
175
|
*/
|
|
167
176
|
declare function stopExistingDaemon(): Promise<boolean>;
|
|
168
177
|
//#endregion
|
|
169
|
-
export { ALFE_DIR, type AgentIdentity, type AgentWorkspaceConfig, type DaemonConfig, type DaemonHealth, type IPCEvent, type IPCRequest, type IPCResponse, PID_PATH, PROTOCOL_VERSION, SOCKET_PATH, checkExistingDaemon, fetchAgentConfig, formatHealthReport, installService, loadDaemonConfig, logger, queryDaemonHealth, resolveAgentIdentity, startDaemon, stopExistingDaemon, uninstallService };
|
|
178
|
+
export { ALFE_DIR, type AgentIdentity, type AgentWorkspaceConfig, type DaemonConfig, type DaemonHealth, type IPCEvent, type IPCRequest, type IPCResponse, PID_PATH, PROTOCOL_VERSION, SOCKET_PATH, checkExistingDaemon, fetchAgentConfig, formatHealthReport, installService, loadDaemonConfig, logger, queryDaemonHealth, resolveAgentIdentity, startDaemon, startService, stopExistingDaemon, uninstallService };
|
package/dist/src/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as installService, c as
|
|
2
|
-
export { ALFE_DIR, PID_PATH, PROTOCOL_VERSION, SOCKET_PATH, checkExistingDaemon, fetchAgentConfig, formatHealthReport, installService, loadDaemonConfig, logger, queryDaemonHealth, resolveAgentIdentity, startDaemon, stopExistingDaemon, uninstallService };
|
|
1
|
+
import { _ as logger, a as installService, c as uninstallService, d as PID_PATH, f as SOCKET_PATH, h as resolveAgentIdentity, i as checkExistingDaemon, l as PROTOCOL_VERSION, m as loadDaemonConfig, n as queryDaemonHealth, o as startService, p as fetchAgentConfig, r as startDaemon, s as stopExistingDaemon, t as formatHealthReport, u as ALFE_DIR } from "../health.js";
|
|
2
|
+
export { ALFE_DIR, PID_PATH, PROTOCOL_VERSION, SOCKET_PATH, checkExistingDaemon, fetchAgentConfig, formatHealthReport, installService, loadDaemonConfig, logger, queryDaemonHealth, resolveAgentIdentity, startDaemon, startService, stopExistingDaemon, uninstallService };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alfe.ai/gateway",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "Alfe local gateway daemon — persistent control plane for agent integrations",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"pino": "^9.6.0",
|
|
22
|
-
"smol-toml": "^1.3.0",
|
|
23
22
|
"pino-roll": "^1.2.0",
|
|
23
|
+
"smol-toml": ">=1.6.1",
|
|
24
24
|
"ws": "^8.18.0",
|
|
25
25
|
"@alfe.ai/ai-proxy-local": "^0.0.2",
|
|
26
26
|
"@alfe.ai/config": "^0.0.2",
|