@stamn/agent 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-DJ3HR5OC.js → chunk-J723GUNU.js} +2 -2
- package/dist/commands/spend.js +1 -1
- package/dist/commands/start.js +3 -3
- package/dist/commands/start.js.map +1 -1
- package/dist/commands/uninstall.d.ts +8 -0
- package/dist/commands/uninstall.js +33 -0
- package/dist/commands/uninstall.js.map +1 -0
- package/dist/commands/update.js +2 -2
- package/dist/ui/setup.js +11 -10
- package/dist/ui/setup.js.map +1 -1
- package/package.json +1 -1
- /package/dist/{chunk-DJ3HR5OC.js.map → chunk-J723GUNU.js.map} +0 -0
|
@@ -266,7 +266,7 @@ var WSClient = class {
|
|
|
266
266
|
const payload = {
|
|
267
267
|
agentId: this.options.config.agentId,
|
|
268
268
|
status,
|
|
269
|
-
version: "0.
|
|
269
|
+
version: "0.7.0",
|
|
270
270
|
platform: `${process.platform}-${process.arch}`,
|
|
271
271
|
nodeVersion: process.versions.node
|
|
272
272
|
};
|
|
@@ -373,4 +373,4 @@ export {
|
|
|
373
373
|
WSClient,
|
|
374
374
|
SpendClient
|
|
375
375
|
};
|
|
376
|
-
//# sourceMappingURL=chunk-
|
|
376
|
+
//# sourceMappingURL=chunk-J723GUNU.js.map
|
package/dist/commands/spend.js
CHANGED
package/dist/commands/start.js
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
SpendClient,
|
|
7
7
|
WSClient,
|
|
8
8
|
createLogger
|
|
9
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-J723GUNU.js";
|
|
10
10
|
import {
|
|
11
11
|
ConfigStore
|
|
12
12
|
} from "../chunk-KQC5O25P.js";
|
|
@@ -49,8 +49,8 @@ var Start = class _Start extends Command {
|
|
|
49
49
|
configStore.set("agentName", result.agentName);
|
|
50
50
|
config.apiKey = result.apiKey;
|
|
51
51
|
config.agentId = result.agentId;
|
|
52
|
-
} catch {
|
|
53
|
-
this.error("Setup cancelled.");
|
|
52
|
+
} catch (err) {
|
|
53
|
+
this.error(err.message || "Setup cancelled.");
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
const dm = new DaemonManager();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/commands/start.ts"],"sourcesContent":["import { Command, Flags } from '@oclif/core';\nimport { ConfigStore } from '../config/config-store.js';\nimport { SERVER_URL, type AgentConfig } from '../config/config-schema.js';\nimport { createLogger } from '../logging/logger.js';\nimport { WSClient } from '../ws/ws-client.js';\nimport { SpendClient } from '../spend/spend-client.js';\nimport { DaemonManager } from '../daemon/daemon-manager.js';\n\nexport default class Start extends Command {\n static override description = 'Start the Stamn agent daemon';\n\n static override flags = {\n daemon: Flags.boolean({\n char: 'd',\n description: 'Run as background daemon',\n default: false,\n }),\n 'log-level': Flags.string({\n description: 'Override log level',\n options: ['trace', 'debug', 'info', 'warn', 'error', 'fatal'],\n }),\n };\n\n async run(): Promise<void> {\n const { flags } = await this.parse(Start);\n const configStore = new ConfigStore();\n const config = { ...configStore.getAll() };\n\n // Apply flag overrides\n if (flags['log-level'])\n config.logLevel = flags['log-level'] as AgentConfig['logLevel'];\n\n // Interactive setup when not registered\n if (!config.apiKey || !config.agentId) {\n if (flags.daemon || !process.stdout.isTTY) {\n this.error(\n 'Not registered. Run `stamn start` interactively first.',\n );\n }\n\n const { runSetup } = await import('../ui/setup.js');\n try {\n const result = await runSetup();\n configStore.set('apiKey', result.apiKey);\n configStore.set('agentId', result.agentId);\n configStore.set('agentName', result.agentName);\n config.apiKey = result.apiKey;\n config.agentId = result.agentId;\n } catch {\n this.error('Setup cancelled.');\n }\n }\n\n // Check for existing daemon\n const dm = new DaemonManager();\n const { running, pid } = dm.isRunning();\n if (running) {\n this.error(`Daemon already running (PID ${pid})`);\n }\n\n // Daemonize if requested\n if (flags.daemon) {\n const { daemonizeProcess } = await import('../daemon/process.js');\n await daemonizeProcess();\n }\n\n // Write PID\n dm.writePid(process.pid);\n\n const logger = createLogger(config);\n logger.info(\n { agentId: config.agentId, server: SERVER_URL },\n 'Starting Stamn agent',\n );\n\n // Create WebSocket client\n const client = new WSClient({\n config,\n logger,\n onCommand: (command, params) => {\n logger.info({ command, params }, 'Received command');\n if (command === 'shutdown') {\n shutdown();\n }\n },\n onDisconnect: () => {\n logger.warn('Disconnected from server');\n },\n onConnected: () => {\n logger.info('Agent is online and ready — spend capability active');\n },\n });\n\n // Create spend client — available for plugin/task integration\n const spendClient = new SpendClient(client, logger);\n\n // Expose on process for external plugin access\n (globalThis as Record<string, unknown>).__stamnSpendClient = spendClient;\n\n // Graceful shutdown\n const shutdown = () => {\n logger.info('Shutting down...');\n client.disconnect();\n dm.removePid();\n process.exit(0);\n };\n\n process.on('SIGTERM', shutdown);\n process.on('SIGINT', shutdown);\n\n // Connect\n client.connect();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA,SAAS,SAAS,aAAa;AAQ/B,IAAqB,QAArB,MAAqB,eAAc,QAAQ;AAAA,EACzC,OAAgB,cAAc;AAAA,EAE9B,OAAgB,QAAQ;AAAA,IACtB,QAAQ,MAAM,QAAQ;AAAA,MACpB,MAAM;AAAA,MACN,aAAa;AAAA,MACb,SAAS;AAAA,IACX,CAAC;AAAA,IACD,aAAa,MAAM,OAAO;AAAA,MACxB,aAAa;AAAA,MACb,SAAS,CAAC,SAAS,SAAS,QAAQ,QAAQ,SAAS,OAAO;AAAA,IAC9D,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,MAAqB;AACzB,UAAM,EAAE,MAAM,IAAI,MAAM,KAAK,MAAM,MAAK;AACxC,UAAM,cAAc,IAAI,YAAY;AACpC,UAAM,SAAS,EAAE,GAAG,YAAY,OAAO,EAAE;AAGzC,QAAI,MAAM,WAAW;AACnB,aAAO,WAAW,MAAM,WAAW;AAGrC,QAAI,CAAC,OAAO,UAAU,CAAC,OAAO,SAAS;AACrC,UAAI,MAAM,UAAU,CAAC,QAAQ,OAAO,OAAO;AACzC,aAAK;AAAA,UACH;AAAA,QACF;AAAA,MACF;AAEA,YAAM,EAAE,SAAS,IAAI,MAAM,OAAO,gBAAgB;AAClD,UAAI;AACF,cAAM,SAAS,MAAM,SAAS;AAC9B,oBAAY,IAAI,UAAU,OAAO,MAAM;AACvC,oBAAY,IAAI,WAAW,OAAO,OAAO;AACzC,oBAAY,IAAI,aAAa,OAAO,SAAS;AAC7C,eAAO,SAAS,OAAO;AACvB,eAAO,UAAU,OAAO;AAAA,MAC1B,
|
|
1
|
+
{"version":3,"sources":["../../src/commands/start.ts"],"sourcesContent":["import { Command, Flags } from '@oclif/core';\nimport { ConfigStore } from '../config/config-store.js';\nimport { SERVER_URL, type AgentConfig } from '../config/config-schema.js';\nimport { createLogger } from '../logging/logger.js';\nimport { WSClient } from '../ws/ws-client.js';\nimport { SpendClient } from '../spend/spend-client.js';\nimport { DaemonManager } from '../daemon/daemon-manager.js';\n\nexport default class Start extends Command {\n static override description = 'Start the Stamn agent daemon';\n\n static override flags = {\n daemon: Flags.boolean({\n char: 'd',\n description: 'Run as background daemon',\n default: false,\n }),\n 'log-level': Flags.string({\n description: 'Override log level',\n options: ['trace', 'debug', 'info', 'warn', 'error', 'fatal'],\n }),\n };\n\n async run(): Promise<void> {\n const { flags } = await this.parse(Start);\n const configStore = new ConfigStore();\n const config = { ...configStore.getAll() };\n\n // Apply flag overrides\n if (flags['log-level'])\n config.logLevel = flags['log-level'] as AgentConfig['logLevel'];\n\n // Interactive setup when not registered\n if (!config.apiKey || !config.agentId) {\n if (flags.daemon || !process.stdout.isTTY) {\n this.error(\n 'Not registered. Run `stamn start` interactively first.',\n );\n }\n\n const { runSetup } = await import('../ui/setup.js');\n try {\n const result = await runSetup();\n configStore.set('apiKey', result.apiKey);\n configStore.set('agentId', result.agentId);\n configStore.set('agentName', result.agentName);\n config.apiKey = result.apiKey;\n config.agentId = result.agentId;\n } catch (err) {\n this.error((err as Error).message || 'Setup cancelled.');\n }\n }\n\n // Check for existing daemon\n const dm = new DaemonManager();\n const { running, pid } = dm.isRunning();\n if (running) {\n this.error(`Daemon already running (PID ${pid})`);\n }\n\n // Daemonize if requested\n if (flags.daemon) {\n const { daemonizeProcess } = await import('../daemon/process.js');\n await daemonizeProcess();\n }\n\n // Write PID\n dm.writePid(process.pid);\n\n const logger = createLogger(config);\n logger.info(\n { agentId: config.agentId, server: SERVER_URL },\n 'Starting Stamn agent',\n );\n\n // Create WebSocket client\n const client = new WSClient({\n config,\n logger,\n onCommand: (command, params) => {\n logger.info({ command, params }, 'Received command');\n if (command === 'shutdown') {\n shutdown();\n }\n },\n onDisconnect: () => {\n logger.warn('Disconnected from server');\n },\n onConnected: () => {\n logger.info('Agent is online and ready — spend capability active');\n },\n });\n\n // Create spend client — available for plugin/task integration\n const spendClient = new SpendClient(client, logger);\n\n // Expose on process for external plugin access\n (globalThis as Record<string, unknown>).__stamnSpendClient = spendClient;\n\n // Graceful shutdown\n const shutdown = () => {\n logger.info('Shutting down...');\n client.disconnect();\n dm.removePid();\n process.exit(0);\n };\n\n process.on('SIGTERM', shutdown);\n process.on('SIGINT', shutdown);\n\n // Connect\n client.connect();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA,SAAS,SAAS,aAAa;AAQ/B,IAAqB,QAArB,MAAqB,eAAc,QAAQ;AAAA,EACzC,OAAgB,cAAc;AAAA,EAE9B,OAAgB,QAAQ;AAAA,IACtB,QAAQ,MAAM,QAAQ;AAAA,MACpB,MAAM;AAAA,MACN,aAAa;AAAA,MACb,SAAS;AAAA,IACX,CAAC;AAAA,IACD,aAAa,MAAM,OAAO;AAAA,MACxB,aAAa;AAAA,MACb,SAAS,CAAC,SAAS,SAAS,QAAQ,QAAQ,SAAS,OAAO;AAAA,IAC9D,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,MAAqB;AACzB,UAAM,EAAE,MAAM,IAAI,MAAM,KAAK,MAAM,MAAK;AACxC,UAAM,cAAc,IAAI,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,KAAK,0BAA0B;AAAA,MACxC;AAAA,MACA,aAAa,MAAM;AACjB,eAAO,KAAK,0DAAqD;AAAA,MACnE;AAAA,IACF,CAAC;AAGD,UAAM,cAAc,IAAI,YAAY,QAAQ,MAAM;AAGlD,IAAC,WAAuC,qBAAqB;AAG7D,UAAM,WAAW,MAAM;AACrB,aAAO,KAAK,kBAAkB;AAC9B,aAAO,WAAW;AAClB,SAAG,UAAU;AACb,cAAQ,KAAK,CAAC;AAAA,IAChB;AAEA,YAAQ,GAAG,WAAW,QAAQ;AAC9B,YAAQ,GAAG,UAAU,QAAQ;AAG7B,WAAO,QAAQ;AAAA,EACjB;AACF;","names":[]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createRequire } from "module"; const require = createRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
DaemonManager
|
|
4
|
+
} from "../chunk-DCE6ICKM.js";
|
|
5
|
+
import {
|
|
6
|
+
ConfigStore
|
|
7
|
+
} from "../chunk-KQC5O25P.js";
|
|
8
|
+
import "../chunk-JVIBUEVN.js";
|
|
9
|
+
|
|
10
|
+
// src/commands/uninstall.ts
|
|
11
|
+
import { Command } from "@oclif/core";
|
|
12
|
+
import { execSync } from "child_process";
|
|
13
|
+
var Uninstall = class extends Command {
|
|
14
|
+
static description = "Uninstall the Stamn agent";
|
|
15
|
+
async run() {
|
|
16
|
+
const dm = new DaemonManager();
|
|
17
|
+
const { running } = dm.isRunning();
|
|
18
|
+
if (running) {
|
|
19
|
+
this.log("Stopping daemon...");
|
|
20
|
+
dm.stop();
|
|
21
|
+
}
|
|
22
|
+
this.log("Removing config...");
|
|
23
|
+
const store = new ConfigStore();
|
|
24
|
+
store.clear();
|
|
25
|
+
this.log("Uninstalling...");
|
|
26
|
+
execSync("npm rm -g @stamn/agent", { stdio: "inherit" });
|
|
27
|
+
this.log("Done.");
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
export {
|
|
31
|
+
Uninstall as default
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=uninstall.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/commands/uninstall.ts"],"sourcesContent":["import { Command } from '@oclif/core';\nimport { execSync } from 'child_process';\nimport { ConfigStore } from '../config/config-store.js';\nimport { DaemonManager } from '../daemon/daemon-manager.js';\n\nexport default class Uninstall extends Command {\n static override description = 'Uninstall the Stamn agent';\n\n async run(): Promise<void> {\n const dm = new DaemonManager();\n const { running } = dm.isRunning();\n\n if (running) {\n this.log('Stopping daemon...');\n dm.stop();\n }\n\n this.log('Removing config...');\n const store = new ConfigStore();\n store.clear();\n\n this.log('Uninstalling...');\n execSync('npm rm -g @stamn/agent', { stdio: 'inherit' });\n\n this.log('Done.');\n }\n}\n"],"mappings":";;;;;;;;;;AAAA,SAAS,eAAe;AACxB,SAAS,gBAAgB;AAIzB,IAAqB,YAArB,cAAuC,QAAQ;AAAA,EAC7C,OAAgB,cAAc;AAAA,EAE9B,MAAM,MAAqB;AACzB,UAAM,KAAK,IAAI,cAAc;AAC7B,UAAM,EAAE,QAAQ,IAAI,GAAG,UAAU;AAEjC,QAAI,SAAS;AACX,WAAK,IAAI,oBAAoB;AAC7B,SAAG,KAAK;AAAA,IACV;AAEA,SAAK,IAAI,oBAAoB;AAC7B,UAAM,QAAQ,IAAI,YAAY;AAC9B,UAAM,MAAM;AAEZ,SAAK,IAAI,iBAAiB;AAC1B,aAAS,0BAA0B,EAAE,OAAO,UAAU,CAAC;AAEvD,SAAK,IAAI,OAAO;AAAA,EAClB;AACF;","names":[]}
|
package/dist/commands/update.js
CHANGED
|
@@ -6,13 +6,13 @@ import { execSync } from "child_process";
|
|
|
6
6
|
var Update = class extends Command {
|
|
7
7
|
static description = "Update the Stamn agent to the latest version";
|
|
8
8
|
async run() {
|
|
9
|
-
this.log(`Current version: ${"0.
|
|
9
|
+
this.log(`Current version: ${"0.7.0"}`);
|
|
10
10
|
this.log("Checking for updates...");
|
|
11
11
|
try {
|
|
12
12
|
const latest = execSync("npm view @stamn/agent version", {
|
|
13
13
|
encoding: "utf-8"
|
|
14
14
|
}).trim();
|
|
15
|
-
if (latest === "0.
|
|
15
|
+
if (latest === "0.7.0") {
|
|
16
16
|
this.log("Already on the latest version.");
|
|
17
17
|
return;
|
|
18
18
|
}
|
package/dist/ui/setup.js
CHANGED
|
@@ -8,7 +8,7 @@ import { useState } from "react";
|
|
|
8
8
|
import { Box, Text } from "ink";
|
|
9
9
|
import { TextInput, Spinner, StatusMessage } from "@inkjs/ui";
|
|
10
10
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
-
function SetupWizard({ onComplete }) {
|
|
11
|
+
function SetupWizard({ onComplete, onError }) {
|
|
12
12
|
const [step, setStep] = useState("api-key");
|
|
13
13
|
const [error, setError] = useState("");
|
|
14
14
|
const register = async (apiKey) => {
|
|
@@ -37,8 +37,12 @@ function SetupWizard({ onComplete }) {
|
|
|
37
37
|
agentName: json.data.name
|
|
38
38
|
});
|
|
39
39
|
} catch (err) {
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
const msg = err.message;
|
|
41
|
+
if (msg === "fetch failed" || msg.includes("ECONNREFUSED") || msg.includes("ENOTFOUND")) {
|
|
42
|
+
onError("Could not connect to Stamn. Is the server running?");
|
|
43
|
+
} else {
|
|
44
|
+
onError(msg);
|
|
45
|
+
}
|
|
42
46
|
}
|
|
43
47
|
};
|
|
44
48
|
return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", padding: 1, children: [
|
|
@@ -69,13 +73,6 @@ function SetupWizard({ onComplete }) {
|
|
|
69
73
|
] }),
|
|
70
74
|
step === "registering" && /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Spinner, { label: "Registering agent..." }) }),
|
|
71
75
|
step === "done" && /* @__PURE__ */ jsx(StatusMessage, { variant: "success", children: "Agent registered. Starting..." }),
|
|
72
|
-
step === "error" && /* @__PURE__ */ jsxs(Box, { flexDirection: "column", children: [
|
|
73
|
-
/* @__PURE__ */ jsxs(StatusMessage, { variant: "error", children: [
|
|
74
|
-
"Registration failed: ",
|
|
75
|
-
error
|
|
76
|
-
] }),
|
|
77
|
-
/* @__PURE__ */ jsx(Text, { dimColor: true, children: "Check your API key and try again." })
|
|
78
|
-
] }),
|
|
79
76
|
step === "api-key" && /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsx(Text, { dimColor: true, children: "Press Ctrl+C to cancel" }) })
|
|
80
77
|
] });
|
|
81
78
|
}
|
|
@@ -91,6 +88,10 @@ function runSetup() {
|
|
|
91
88
|
onComplete: (result) => {
|
|
92
89
|
unmount();
|
|
93
90
|
resolve(result);
|
|
91
|
+
},
|
|
92
|
+
onError: (message) => {
|
|
93
|
+
unmount();
|
|
94
|
+
reject(new Error(message));
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
97
|
)
|
package/dist/ui/setup.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ui/setup.tsx","../../src/ui/components/setup-wizard.tsx"],"sourcesContent":["import { render } from 'ink';\nimport { SetupWizard } from './components/setup-wizard.js';\n\nexport interface SetupResult {\n agentId: string;\n apiKey: string;\n agentName: string;\n}\n\nexport function runSetup(): Promise<SetupResult> {\n return new Promise((resolve, reject) => {\n const { unmount, waitUntilExit } = render(\n <SetupWizard\n onComplete={(result) => {\n unmount();\n resolve(result);\n }}\n />,\n );\n\n waitUntilExit().catch(reject);\n });\n}\n","import { useState } from 'react';\nimport { Box, Text } from 'ink';\nimport { TextInput, Spinner, StatusMessage } from '@inkjs/ui';\n\ntype Step = 'api-key' | 'registering' | 'done'
|
|
1
|
+
{"version":3,"sources":["../../src/ui/setup.tsx","../../src/ui/components/setup-wizard.tsx"],"sourcesContent":["import { render } from 'ink';\nimport { SetupWizard } from './components/setup-wizard.js';\n\nexport interface SetupResult {\n agentId: string;\n apiKey: string;\n agentName: string;\n}\n\nexport function runSetup(): Promise<SetupResult> {\n return new Promise((resolve, reject) => {\n const { unmount, waitUntilExit } = render(\n <SetupWizard\n onComplete={(result) => {\n unmount();\n resolve(result);\n }}\n onError={(message) => {\n unmount();\n reject(new Error(message));\n }}\n />,\n );\n\n waitUntilExit().catch(reject);\n });\n}\n","import { useState } from 'react';\nimport { Box, Text } from 'ink';\nimport { TextInput, Spinner, StatusMessage } from '@inkjs/ui';\n\ntype Step = 'api-key' | 'registering' | 'done';\n\ninterface Props {\n onComplete: (result: { agentId: string; apiKey: string; agentName: string }) => void;\n onError: (message: string) => void;\n}\n\ndeclare const AGENT_VERSION: string;\n\nexport function SetupWizard({ onComplete, onError }: Props) {\n const [step, setStep] = useState<Step>('api-key');\n const [error, setError] = useState('');\n\n const register = async (apiKey: string) => {\n setStep('registering');\n\n try {\n const { SERVER_URL } = await import('../../config/config-schema.js');\n const res = await fetch(`${SERVER_URL}/v1/agents/register`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${apiKey}`,\n },\n body: JSON.stringify({\n platform: `${process.platform}-${process.arch}`,\n }),\n });\n\n if (!res.ok) {\n const body = await res.text();\n throw new Error(body || `HTTP ${res.status}`);\n }\n\n const json = (await res.json()) as {\n data: { id: string; name: string };\n };\n setStep('done');\n onComplete({\n agentId: json.data.id,\n apiKey,\n agentName: json.data.name,\n });\n } catch (err) {\n const msg = (err as Error).message;\n if (msg === 'fetch failed' || msg.includes('ECONNREFUSED') || msg.includes('ENOTFOUND')) {\n onError('Could not connect to Stamn. Is the server running?');\n } else {\n onError(msg);\n }\n }\n };\n\n return (\n <Box flexDirection=\"column\" padding={1}>\n <Box marginBottom={1}>\n <Text bold color=\"cyan\">\n stamn\n </Text>\n <Text dimColor> setup</Text>\n </Box>\n\n {step === 'api-key' && (\n <Box flexDirection=\"column\">\n <Text>Enter your API key from the Stamn dashboard.</Text>\n <Box marginTop={1}>\n <Text color=\"cyan\">{\"> \"}</Text>\n <TextInput\n placeholder=\"sk-...\"\n onSubmit={(value: string) => {\n if (!value.trim()) {\n setError('API key cannot be empty');\n return;\n }\n setError('');\n register(value.trim());\n }}\n />\n </Box>\n {error && step === 'api-key' && (\n <StatusMessage variant=\"error\">{error}</StatusMessage>\n )}\n </Box>\n )}\n\n {step === 'registering' && (\n <Box>\n <Spinner label=\"Registering agent...\" />\n </Box>\n )}\n\n {step === 'done' && (\n <StatusMessage variant=\"success\">\n Agent registered. Starting...\n </StatusMessage>\n )}\n\n {step === 'api-key' && (\n <Box marginTop={1}>\n <Text dimColor>Press Ctrl+C to cancel</Text>\n </Box>\n )}\n </Box>\n );\n}\n"],"mappings":";;;AAAA,SAAS,cAAc;;;ACAvB,SAAS,gBAAgB;AACzB,SAAS,KAAK,YAAY;AAC1B,SAAS,WAAW,SAAS,qBAAqB;AAyD5C,SACE,KADF;AA9CC,SAAS,YAAY,EAAE,YAAY,QAAQ,GAAU;AAC1D,QAAM,CAAC,MAAM,OAAO,IAAI,SAAe,SAAS;AAChD,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAS,EAAE;AAErC,QAAM,WAAW,OAAO,WAAmB;AACzC,YAAQ,aAAa;AAErB,QAAI;AACF,YAAM,EAAE,WAAW,IAAI,MAAM,OAAO,8BAA+B;AACnE,YAAM,MAAM,MAAM,MAAM,GAAG,UAAU,uBAAuB;AAAA,QAC1D,QAAQ;AAAA,QACR,SAAS;AAAA,UACP,gBAAgB;AAAA,UAChB,eAAe,UAAU,MAAM;AAAA,QACjC;AAAA,QACA,MAAM,KAAK,UAAU;AAAA,UACnB,UAAU,GAAG,QAAQ,QAAQ,IAAI,QAAQ,IAAI;AAAA,QAC/C,CAAC;AAAA,MACH,CAAC;AAED,UAAI,CAAC,IAAI,IAAI;AACX,cAAM,OAAO,MAAM,IAAI,KAAK;AAC5B,cAAM,IAAI,MAAM,QAAQ,QAAQ,IAAI,MAAM,EAAE;AAAA,MAC9C;AAEA,YAAM,OAAQ,MAAM,IAAI,KAAK;AAG7B,cAAQ,MAAM;AACd,iBAAW;AAAA,QACT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