@heyamiko/amiko-cli 0.5.7 → 0.5.8
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/index.js +136 -121
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -74135,6 +74135,117 @@ function registerMarketplaceCommand(program2) {
|
|
|
74135
74135
|
import { createServer } from "node:http";
|
|
74136
74136
|
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
74137
74137
|
import { execFileSync as execFileSync4 } from "node:child_process";
|
|
74138
|
+
|
|
74139
|
+
// src/lib/agent-config.ts
|
|
74140
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2 } from "node:fs";
|
|
74141
|
+
import { join as join3, resolve } from "node:path";
|
|
74142
|
+
function loadAgentConfig() {
|
|
74143
|
+
const knownPaths = [
|
|
74144
|
+
process.env.OPENCLAW_WORKSPACE_DIR ? join3(process.env.OPENCLAW_WORKSPACE_DIR, ".amiko.json") : "",
|
|
74145
|
+
process.env.OPENCLAW_HOME ? join3(process.env.OPENCLAW_HOME, ".openclaw", "workspace", ".amiko.json") : "",
|
|
74146
|
+
"/data/.openclaw/workspace/.amiko.json",
|
|
74147
|
+
"/data/.amiko.json"
|
|
74148
|
+
].filter(Boolean);
|
|
74149
|
+
for (const p13 of knownPaths) {
|
|
74150
|
+
const result = tryLoadConfig(p13);
|
|
74151
|
+
if (result)
|
|
74152
|
+
return result;
|
|
74153
|
+
}
|
|
74154
|
+
let dir = process.cwd();
|
|
74155
|
+
const root2 = resolve("/");
|
|
74156
|
+
while (dir !== root2) {
|
|
74157
|
+
const result = tryLoadConfig(join3(dir, ".amiko.json"));
|
|
74158
|
+
if (result)
|
|
74159
|
+
return result;
|
|
74160
|
+
dir = resolve(dir, "..");
|
|
74161
|
+
}
|
|
74162
|
+
return null;
|
|
74163
|
+
}
|
|
74164
|
+
function tryLoadConfig(filePath) {
|
|
74165
|
+
if (!existsSync3(filePath))
|
|
74166
|
+
return null;
|
|
74167
|
+
try {
|
|
74168
|
+
const raw = readFileSync2(filePath, "utf-8");
|
|
74169
|
+
const parsed = JSON.parse(raw);
|
|
74170
|
+
const config = {};
|
|
74171
|
+
config.twinToken = parsed.amikoTwinToken || parsed.AMIKO_TWIN_TOKEN || parsed.AMIKO_USER_TOKEN;
|
|
74172
|
+
config.twinId = parsed.amikoTwinId || parsed.AMIKO_TWIN_ID;
|
|
74173
|
+
config.userId = parsed.amikoUserId || parsed.AMIKO_USER_ID;
|
|
74174
|
+
config.platformUrl = parsed.amikoPlatformUrl || parsed.AMIKO_PLATFORM_URL;
|
|
74175
|
+
if (parsed.billingBase)
|
|
74176
|
+
config.billingBase = parsed.billingBase;
|
|
74177
|
+
if (parsed.platformKey)
|
|
74178
|
+
config.platformKey = parsed.platformKey;
|
|
74179
|
+
if (Array.isArray(parsed.agentWallets))
|
|
74180
|
+
config.agentWallets = parsed.agentWallets;
|
|
74181
|
+
return Object.keys(config).length > 0 ? config : null;
|
|
74182
|
+
} catch {
|
|
74183
|
+
return null;
|
|
74184
|
+
}
|
|
74185
|
+
}
|
|
74186
|
+
function resolveAuth(cliConfig) {
|
|
74187
|
+
if (cliConfig.agentWallets?.length) {
|
|
74188
|
+
return {
|
|
74189
|
+
mode: "connected",
|
|
74190
|
+
platformUrl: cliConfig.platformUrl,
|
|
74191
|
+
billingBase: cliConfig.billingBase,
|
|
74192
|
+
twinId: cliConfig.twinId,
|
|
74193
|
+
twinToken: cliConfig.twinToken,
|
|
74194
|
+
platformKey: cliConfig.apiKey,
|
|
74195
|
+
privyToken: cliConfig.privyToken,
|
|
74196
|
+
connectedKeyId: cliConfig.connectedKeyId,
|
|
74197
|
+
userId: cliConfig.userId,
|
|
74198
|
+
agentWallets: cliConfig.agentWallets
|
|
74199
|
+
};
|
|
74200
|
+
}
|
|
74201
|
+
if (cliConfig.privyToken && cliConfig.connectedKeyId) {
|
|
74202
|
+
return {
|
|
74203
|
+
mode: "connected",
|
|
74204
|
+
billingBase: cliConfig.billingBase,
|
|
74205
|
+
platformKey: cliConfig.privyToken,
|
|
74206
|
+
privyToken: cliConfig.privyToken,
|
|
74207
|
+
connectedKeyId: cliConfig.connectedKeyId,
|
|
74208
|
+
userId: cliConfig.userId
|
|
74209
|
+
};
|
|
74210
|
+
}
|
|
74211
|
+
if (cliConfig.apiKey) {
|
|
74212
|
+
return {
|
|
74213
|
+
mode: "connected",
|
|
74214
|
+
billingBase: cliConfig.billingBase,
|
|
74215
|
+
platformKey: cliConfig.apiKey,
|
|
74216
|
+
userId: cliConfig.userId,
|
|
74217
|
+
twinId: cliConfig.twinId,
|
|
74218
|
+
twinToken: cliConfig.twinToken
|
|
74219
|
+
};
|
|
74220
|
+
}
|
|
74221
|
+
const envToken = process.env.AMIKO_USER_TOKEN;
|
|
74222
|
+
if (envToken) {
|
|
74223
|
+
return {
|
|
74224
|
+
mode: "agent",
|
|
74225
|
+
twinId: process.env.AMIKO_TWIN_ID,
|
|
74226
|
+
twinToken: envToken,
|
|
74227
|
+
userId: process.env.AMIKO_USER_ID,
|
|
74228
|
+
billingBase: process.env.API_SERVICE_URL || process.env.BILLING_BASE,
|
|
74229
|
+
platformUrl: process.env.AMIKO_PLATFORM_URL
|
|
74230
|
+
};
|
|
74231
|
+
}
|
|
74232
|
+
const agentConfig = loadAgentConfig();
|
|
74233
|
+
if (agentConfig?.twinToken) {
|
|
74234
|
+
return {
|
|
74235
|
+
mode: "agent",
|
|
74236
|
+
platformUrl: agentConfig.platformUrl,
|
|
74237
|
+
billingBase: agentConfig.billingBase,
|
|
74238
|
+
twinId: agentConfig.twinId,
|
|
74239
|
+
twinToken: agentConfig.twinToken,
|
|
74240
|
+
platformKey: agentConfig.platformKey,
|
|
74241
|
+
userId: agentConfig.userId,
|
|
74242
|
+
agentWallets: agentConfig.agentWallets
|
|
74243
|
+
};
|
|
74244
|
+
}
|
|
74245
|
+
return { mode: "none" };
|
|
74246
|
+
}
|
|
74247
|
+
|
|
74248
|
+
// src/commands/login.ts
|
|
74138
74249
|
function buildVerifiedAuthConfig(token, bootstrap) {
|
|
74139
74250
|
return {
|
|
74140
74251
|
privyToken: token,
|
|
@@ -74169,8 +74280,8 @@ function startCallbackServer(expectedState, timeoutMs = 120000, acknowledgementT
|
|
|
74169
74280
|
return new Promise((resolveServer) => {
|
|
74170
74281
|
let resolveToken;
|
|
74171
74282
|
let rejectToken;
|
|
74172
|
-
const tokenPromise = new Promise((
|
|
74173
|
-
resolveToken =
|
|
74283
|
+
const tokenPromise = new Promise((resolve2, reject) => {
|
|
74284
|
+
resolveToken = resolve2;
|
|
74174
74285
|
rejectToken = reject;
|
|
74175
74286
|
});
|
|
74176
74287
|
const server = createServer((req, res) => {
|
|
@@ -74200,8 +74311,8 @@ function startCallbackServer(expectedState, timeoutMs = 120000, acknowledgementT
|
|
|
74200
74311
|
}
|
|
74201
74312
|
let acknowledged = false;
|
|
74202
74313
|
let resolveAcknowledgement;
|
|
74203
|
-
const acknowledgementPromise = new Promise((
|
|
74204
|
-
resolveAcknowledgement =
|
|
74314
|
+
const acknowledgementPromise = new Promise((resolve2) => {
|
|
74315
|
+
resolveAcknowledgement = resolve2;
|
|
74205
74316
|
});
|
|
74206
74317
|
const acknowledgementTimeout = setTimeout(() => {
|
|
74207
74318
|
if (acknowledged)
|
|
@@ -74364,32 +74475,45 @@ Run "amiko login" again to re-authenticate, or "amiko logout" to sign out.
|
|
|
74364
74475
|
});
|
|
74365
74476
|
program2.command("whoami").description("Show current authentication status").action(() => {
|
|
74366
74477
|
const config = loadConfig();
|
|
74367
|
-
const
|
|
74478
|
+
const auth = resolveAuth(config);
|
|
74368
74479
|
console.log(heading(`Amiko Identity
|
|
74369
74480
|
`));
|
|
74370
|
-
if (
|
|
74371
|
-
console.log(label("Auth", source_default.green("
|
|
74481
|
+
if (auth.mode === "agent") {
|
|
74482
|
+
console.log(label("Auth", source_default.green("agent (auto-detected .amiko.json)")));
|
|
74483
|
+
} else if (auth.mode === "connected") {
|
|
74484
|
+
console.log(label("Auth", source_default.green("connected")));
|
|
74372
74485
|
} else {
|
|
74373
74486
|
console.log(label("Auth", dim("not signed in")));
|
|
74374
74487
|
}
|
|
74375
|
-
|
|
74376
|
-
|
|
74488
|
+
const userId = auth.userId || config.userId;
|
|
74489
|
+
if (userId) {
|
|
74490
|
+
console.log(label("User ID", dim(userId)));
|
|
74491
|
+
}
|
|
74492
|
+
if (auth.twinId) {
|
|
74493
|
+
console.log(label("Twin ID", dim(auth.twinId)));
|
|
74377
74494
|
}
|
|
74378
74495
|
if (config.connectedKeyPreview) {
|
|
74379
74496
|
const connectedKeyLabel = config.connectedKeyName ? `${config.connectedKeyName} (${config.connectedKeyPreview})` : config.connectedKeyPreview;
|
|
74380
74497
|
console.log(label("Connected Key", connectedKeyLabel));
|
|
74381
74498
|
}
|
|
74382
|
-
if (
|
|
74499
|
+
if (auth.agentWallets?.length) {
|
|
74500
|
+
console.log(label("Wallets", `${auth.agentWallets.length}`));
|
|
74501
|
+
for (const w5 of auth.agentWallets) {
|
|
74502
|
+
const short = w5.address.length > 14 ? `${w5.address.slice(0, 8)}...${w5.address.slice(-6)}` : w5.address;
|
|
74503
|
+
console.log(dim(` ${w5.chain}: ${short}`));
|
|
74504
|
+
}
|
|
74505
|
+
} else if (config.wallet) {
|
|
74383
74506
|
console.log(label("Wallet", config.wallet));
|
|
74384
74507
|
}
|
|
74385
74508
|
if (config.apiKey) {
|
|
74386
74509
|
const masked = config.apiKey.slice(0, 6) + "..." + config.apiKey.slice(-4);
|
|
74387
74510
|
console.log(label("API Key", masked));
|
|
74388
74511
|
}
|
|
74512
|
+
const billingBase2 = auth.billingBase || config.billingBase;
|
|
74389
74513
|
console.log(label("MPP", config.apiBase));
|
|
74390
|
-
console.log(label("Billing",
|
|
74514
|
+
console.log(label("Billing", billingBase2));
|
|
74391
74515
|
console.log(label("Site", config.siteBase));
|
|
74392
|
-
if (
|
|
74516
|
+
if (auth.mode === "none") {
|
|
74393
74517
|
console.log("");
|
|
74394
74518
|
console.log(dim('Run "amiko login" to authenticate, or'));
|
|
74395
74519
|
console.log(dim(' "amiko config set apiKey <key>" for API key auth.'));
|
|
@@ -75057,115 +75181,6 @@ Tip: you can also generate a connect link from your Amiko settings`));
|
|
|
75057
75181
|
});
|
|
75058
75182
|
}
|
|
75059
75183
|
|
|
75060
|
-
// src/lib/agent-config.ts
|
|
75061
|
-
import { existsSync as existsSync3, readFileSync as readFileSync2 } from "node:fs";
|
|
75062
|
-
import { join as join3, resolve } from "node:path";
|
|
75063
|
-
function loadAgentConfig() {
|
|
75064
|
-
const knownPaths = [
|
|
75065
|
-
process.env.OPENCLAW_WORKSPACE_DIR ? join3(process.env.OPENCLAW_WORKSPACE_DIR, ".amiko.json") : "",
|
|
75066
|
-
process.env.OPENCLAW_HOME ? join3(process.env.OPENCLAW_HOME, ".openclaw", "workspace", ".amiko.json") : "",
|
|
75067
|
-
"/data/.openclaw/workspace/.amiko.json",
|
|
75068
|
-
"/data/.amiko.json"
|
|
75069
|
-
].filter(Boolean);
|
|
75070
|
-
for (const p13 of knownPaths) {
|
|
75071
|
-
const result = tryLoadConfig(p13);
|
|
75072
|
-
if (result)
|
|
75073
|
-
return result;
|
|
75074
|
-
}
|
|
75075
|
-
let dir = process.cwd();
|
|
75076
|
-
const root2 = resolve("/");
|
|
75077
|
-
while (dir !== root2) {
|
|
75078
|
-
const result = tryLoadConfig(join3(dir, ".amiko.json"));
|
|
75079
|
-
if (result)
|
|
75080
|
-
return result;
|
|
75081
|
-
dir = resolve(dir, "..");
|
|
75082
|
-
}
|
|
75083
|
-
return null;
|
|
75084
|
-
}
|
|
75085
|
-
function tryLoadConfig(filePath) {
|
|
75086
|
-
if (!existsSync3(filePath))
|
|
75087
|
-
return null;
|
|
75088
|
-
try {
|
|
75089
|
-
const raw = readFileSync2(filePath, "utf-8");
|
|
75090
|
-
const parsed = JSON.parse(raw);
|
|
75091
|
-
const config = {};
|
|
75092
|
-
config.twinToken = parsed.amikoTwinToken || parsed.AMIKO_TWIN_TOKEN || parsed.AMIKO_USER_TOKEN;
|
|
75093
|
-
config.twinId = parsed.amikoTwinId || parsed.AMIKO_TWIN_ID;
|
|
75094
|
-
config.userId = parsed.amikoUserId || parsed.AMIKO_USER_ID;
|
|
75095
|
-
config.platformUrl = parsed.amikoPlatformUrl || parsed.AMIKO_PLATFORM_URL;
|
|
75096
|
-
if (parsed.billingBase)
|
|
75097
|
-
config.billingBase = parsed.billingBase;
|
|
75098
|
-
if (parsed.platformKey)
|
|
75099
|
-
config.platformKey = parsed.platformKey;
|
|
75100
|
-
if (Array.isArray(parsed.agentWallets))
|
|
75101
|
-
config.agentWallets = parsed.agentWallets;
|
|
75102
|
-
return Object.keys(config).length > 0 ? config : null;
|
|
75103
|
-
} catch {
|
|
75104
|
-
return null;
|
|
75105
|
-
}
|
|
75106
|
-
}
|
|
75107
|
-
function resolveAuth(cliConfig) {
|
|
75108
|
-
if (cliConfig.agentWallets?.length) {
|
|
75109
|
-
return {
|
|
75110
|
-
mode: "connected",
|
|
75111
|
-
platformUrl: cliConfig.platformUrl,
|
|
75112
|
-
billingBase: cliConfig.billingBase,
|
|
75113
|
-
twinId: cliConfig.twinId,
|
|
75114
|
-
twinToken: cliConfig.twinToken,
|
|
75115
|
-
platformKey: cliConfig.apiKey,
|
|
75116
|
-
privyToken: cliConfig.privyToken,
|
|
75117
|
-
connectedKeyId: cliConfig.connectedKeyId,
|
|
75118
|
-
userId: cliConfig.userId,
|
|
75119
|
-
agentWallets: cliConfig.agentWallets
|
|
75120
|
-
};
|
|
75121
|
-
}
|
|
75122
|
-
if (cliConfig.privyToken && cliConfig.connectedKeyId) {
|
|
75123
|
-
return {
|
|
75124
|
-
mode: "connected",
|
|
75125
|
-
billingBase: cliConfig.billingBase,
|
|
75126
|
-
platformKey: cliConfig.privyToken,
|
|
75127
|
-
privyToken: cliConfig.privyToken,
|
|
75128
|
-
connectedKeyId: cliConfig.connectedKeyId,
|
|
75129
|
-
userId: cliConfig.userId
|
|
75130
|
-
};
|
|
75131
|
-
}
|
|
75132
|
-
if (cliConfig.apiKey) {
|
|
75133
|
-
return {
|
|
75134
|
-
mode: "connected",
|
|
75135
|
-
billingBase: cliConfig.billingBase,
|
|
75136
|
-
platformKey: cliConfig.apiKey,
|
|
75137
|
-
userId: cliConfig.userId,
|
|
75138
|
-
twinId: cliConfig.twinId,
|
|
75139
|
-
twinToken: cliConfig.twinToken
|
|
75140
|
-
};
|
|
75141
|
-
}
|
|
75142
|
-
const envToken = process.env.AMIKO_USER_TOKEN;
|
|
75143
|
-
if (envToken) {
|
|
75144
|
-
return {
|
|
75145
|
-
mode: "agent",
|
|
75146
|
-
twinId: process.env.AMIKO_TWIN_ID,
|
|
75147
|
-
twinToken: envToken,
|
|
75148
|
-
userId: process.env.AMIKO_USER_ID,
|
|
75149
|
-
billingBase: process.env.API_SERVICE_URL || process.env.BILLING_BASE,
|
|
75150
|
-
platformUrl: process.env.AMIKO_PLATFORM_URL
|
|
75151
|
-
};
|
|
75152
|
-
}
|
|
75153
|
-
const agentConfig = loadAgentConfig();
|
|
75154
|
-
if (agentConfig?.twinToken) {
|
|
75155
|
-
return {
|
|
75156
|
-
mode: "agent",
|
|
75157
|
-
platformUrl: agentConfig.platformUrl,
|
|
75158
|
-
billingBase: agentConfig.billingBase,
|
|
75159
|
-
twinId: agentConfig.twinId,
|
|
75160
|
-
twinToken: agentConfig.twinToken,
|
|
75161
|
-
platformKey: agentConfig.platformKey,
|
|
75162
|
-
userId: agentConfig.userId,
|
|
75163
|
-
agentWallets: agentConfig.agentWallets
|
|
75164
|
-
};
|
|
75165
|
-
}
|
|
75166
|
-
return { mode: "none" };
|
|
75167
|
-
}
|
|
75168
|
-
|
|
75169
75184
|
// src/lib/mpp-topup.ts
|
|
75170
75185
|
async function mppCreditsTopup(params) {
|
|
75171
75186
|
const config2 = loadConfig();
|