@twin3-ai/agent-id 0.1.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.
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ const { createSiteAgentClient } = require("../site-agent.js");
5
+ const { createSiteAgentSyncService } = require("../sync-service.js");
6
+
7
+ function valueAfter(args, name, fallback = "") {
8
+ const index = args.indexOf(name);
9
+ return index >= 0 && args[index + 1] ? args[index + 1] : fallback;
10
+ }
11
+
12
+ function help() {
13
+ console.log(`agent-id-sync
14
+
15
+ Usage:
16
+ agent-id-sync --url https://example.com --once
17
+ agent-id-sync --url https://example.com --status
18
+ agent-id-sync --url https://example.com --pause [--reason maintenance]
19
+ agent-id-sync --url https://example.com --resume [--reason resumed]
20
+ agent-id-sync --url https://example.com --disconnect [--reason owner_requested]
21
+ agent-id-sync --url https://example.com --revoke [--reason key_revoked]
22
+ agent-id-sync --url https://example.com [--interval-ms 900000]
23
+
24
+ Environment:
25
+ SITE_AGENT_KEY Required for sync calls; never stored in sync state
26
+ SITE_URL Website URL when --url is omitted
27
+ AGENT_ID_ENDPOINT Parent Agent service origin
28
+ AGENT_ID_SYNC_STATE Cursor, queue, and dead-letter state path
29
+ AGENT_ID_SYNC_INTERVAL_MS Service polling interval
30
+ `);
31
+ }
32
+
33
+ async function main() {
34
+ const args = process.argv.slice(2);
35
+ if (args.includes("--help") || args.includes("-h")) return help();
36
+ const siteUrl = valueAfter(args, "--url", process.env.SITE_URL || "");
37
+ const endpoint = valueAfter(args, "--endpoint", process.env.AGENT_ID_ENDPOINT || "");
38
+ const statePath = valueAfter(args, "--state", process.env.AGENT_ID_SYNC_STATE || "");
39
+ const intervalMs = Number(valueAfter(args, "--interval-ms", process.env.AGENT_ID_SYNC_INTERVAL_MS || "900000"));
40
+ if (!siteUrl) throw new Error("--url or SITE_URL is required");
41
+ const client = createSiteAgentClient({ endpoint, agentKey: process.env.SITE_AGENT_KEY });
42
+ const service = createSiteAgentSyncService({ client, siteUrl, statePath: statePath || undefined, intervalMs });
43
+ if (args.includes("--status")) {
44
+ console.log(JSON.stringify(await service.status(), null, 2));
45
+ return;
46
+ }
47
+ const reason = valueAfter(args, "--reason", "operator_requested");
48
+ if (args.includes("--pause")) {
49
+ console.log(JSON.stringify(await service.pause(reason), null, 2));
50
+ return;
51
+ }
52
+ if (args.includes("--resume")) {
53
+ console.log(JSON.stringify(await service.resume(reason), null, 2));
54
+ return;
55
+ }
56
+ if (args.includes("--disconnect")) {
57
+ console.log(JSON.stringify(await service.disconnect(reason), null, 2));
58
+ return;
59
+ }
60
+ if (args.includes("--revoke")) {
61
+ console.log(JSON.stringify(await service.revoke(reason), null, 2));
62
+ return;
63
+ }
64
+ if (args.includes("--once")) {
65
+ console.log(JSON.stringify(await service.runOnce(), null, 2));
66
+ return;
67
+ }
68
+ const controller = new AbortController();
69
+ process.once("SIGINT", () => controller.abort());
70
+ process.once("SIGTERM", () => controller.abort());
71
+ await service.run({
72
+ signal: controller.signal,
73
+ onCycle: async (result) => console.log(JSON.stringify({ at: new Date().toISOString(), ...result }))
74
+ });
75
+ }
76
+
77
+ main().catch((err) => {
78
+ console.error(err.message || String(err));
79
+ process.exit(1);
80
+ });