oneie 3.8.3 → 4.0.1
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/LICENSE +86 -0
- package/README.md +63 -952
- package/dist/package.json +38 -0
- package/dist/src/agent.d.ts +2 -0
- package/dist/src/agent.js +888 -0
- package/dist/src/args.d.ts +9 -0
- package/dist/src/args.js +61 -0
- package/dist/src/auth.d.ts +6 -0
- package/dist/src/auth.js +122 -0
- package/dist/{banner.d.ts → src/banner.d.ts} +0 -1
- package/dist/src/banner.js +16 -0
- package/dist/src/broadcast.d.ts +6 -0
- package/dist/src/broadcast.js +150 -0
- package/dist/src/catalog.d.ts +2 -0
- package/dist/src/catalog.js +78 -0
- package/dist/src/chat.d.ts +2 -0
- package/dist/src/chat.js +92 -0
- package/dist/src/client.d.ts +5 -0
- package/dist/src/client.js +151 -0
- package/dist/src/compiler.d.ts +36 -0
- package/dist/src/compiler.js +314 -0
- package/dist/src/config.d.ts +24 -0
- package/dist/src/config.js +70 -0
- package/dist/src/connect.d.ts +2 -0
- package/dist/src/connect.js +64 -0
- package/dist/src/coordinate.d.ts +3 -0
- package/dist/src/coordinate.js +58 -0
- package/dist/src/create.d.ts +2 -0
- package/dist/src/create.js +113 -0
- package/dist/src/deploy.d.ts +2 -0
- package/dist/src/deploy.js +19 -0
- package/dist/src/dev.d.ts +2 -0
- package/dist/src/dev.js +75 -0
- package/dist/src/device-flow.d.ts +57 -0
- package/dist/src/device-flow.js +173 -0
- package/dist/src/doctor.d.ts +26 -0
- package/dist/src/doctor.js +91 -0
- package/dist/src/env.d.ts +3 -0
- package/dist/src/env.js +37 -0
- package/dist/src/eval.d.ts +2 -0
- package/dist/src/eval.js +42 -0
- package/dist/src/fn.d.ts +2 -0
- package/dist/src/fn.js +73 -0
- package/dist/src/group.d.ts +2 -0
- package/dist/src/group.js +115 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +102 -0
- package/dist/src/init.d.ts +11 -0
- package/dist/src/init.js +121 -0
- package/dist/src/lib/agent-env.d.ts +5 -0
- package/dist/src/lib/agent-env.js +25 -0
- package/dist/src/lib/api-path.d.ts +1 -0
- package/dist/src/lib/api-path.js +9 -0
- package/dist/src/lib/client.d.ts +16 -0
- package/dist/src/lib/client.js +57 -0
- package/dist/src/lib/launch-claude.d.ts +5 -0
- package/dist/src/lib/launch-claude.js +45 -0
- package/dist/src/links.d.ts +5 -0
- package/dist/src/links.js +44 -0
- package/dist/src/onboard.d.ts +16 -0
- package/dist/src/onboard.js +146 -0
- package/dist/src/plugin.d.ts +2 -0
- package/dist/src/plugin.js +184 -0
- package/dist/src/push.d.ts +2 -0
- package/dist/src/push.js +114 -0
- package/dist/src/render.d.ts +21 -0
- package/dist/src/render.js +32 -0
- package/dist/src/setup.d.ts +6 -0
- package/dist/src/setup.js +126 -0
- package/dist/src/ship.d.ts +2 -0
- package/dist/src/ship.js +18 -0
- package/dist/src/skill-parser.d.ts +14 -0
- package/dist/src/skill-parser.js +113 -0
- package/dist/src/skill.d.ts +2 -0
- package/dist/src/skill.js +377 -0
- package/dist/src/slug.d.ts +2 -0
- package/dist/src/slug.js +6 -0
- package/dist/src/social.d.ts +2 -0
- package/dist/src/social.js +87 -0
- package/dist/src/staff.d.ts +2 -0
- package/dist/src/staff.js +93 -0
- package/dist/src/status.d.ts +2 -0
- package/dist/src/status.js +46 -0
- package/dist/src/substrate.d.ts +2 -0
- package/dist/src/substrate.js +243 -0
- package/dist/src/templates/_node/site/one.config.d.ts +2 -0
- package/dist/src/templates/_node/site/one.config.js +22 -0
- package/dist/src/templates.d.ts +1 -0
- package/dist/src/templates.js +205 -0
- package/dist/src/trade.d.ts +2 -0
- package/dist/src/trade.js +95 -0
- package/dist/src/trail.d.ts +2 -0
- package/dist/src/trail.js +41 -0
- package/dist/src/validate.d.ts +13 -0
- package/dist/src/validate.js +35 -0
- package/dist/src/wallet.d.ts +9 -0
- package/dist/src/wallet.js +209 -0
- package/package.json +26 -54
- package/LICENSE.md +0 -89
- package/dist/admin/build.d.ts +0 -15
- package/dist/admin/build.d.ts.map +0 -1
- package/dist/admin/build.js +0 -295
- package/dist/admin/build.js.map +0 -1
- package/dist/admin/index.d.ts +0 -24
- package/dist/admin/index.d.ts.map +0 -1
- package/dist/admin/index.js +0 -98
- package/dist/admin/index.js.map +0 -1
- package/dist/admin/list.d.ts +0 -14
- package/dist/admin/list.d.ts.map +0 -1
- package/dist/admin/list.js +0 -90
- package/dist/admin/list.js.map +0 -1
- package/dist/admin/manifest.d.ts +0 -86
- package/dist/admin/manifest.d.ts.map +0 -1
- package/dist/admin/manifest.js +0 -183
- package/dist/admin/manifest.js.map +0 -1
- package/dist/admin/monorepo.d.ts +0 -25
- package/dist/admin/monorepo.d.ts.map +0 -1
- package/dist/admin/monorepo.js +0 -59
- package/dist/admin/monorepo.js.map +0 -1
- package/dist/admin/release.d.ts +0 -17
- package/dist/admin/release.d.ts.map +0 -1
- package/dist/admin/release.js +0 -144
- package/dist/admin/release.js.map +0 -1
- package/dist/admin/sync.d.ts +0 -14
- package/dist/admin/sync.d.ts.map +0 -1
- package/dist/admin/sync.js +0 -104
- package/dist/admin/sync.js.map +0 -1
- package/dist/admin/validate.d.ts +0 -15
- package/dist/admin/validate.d.ts.map +0 -1
- package/dist/admin/validate.js +0 -169
- package/dist/admin/validate.js.map +0 -1
- package/dist/banner.d.ts.map +0 -1
- package/dist/banner.js +0 -15
- package/dist/banner.js.map +0 -1
- package/dist/clone-docs.d.ts +0 -17
- package/dist/clone-docs.d.ts.map +0 -1
- package/dist/clone-docs.js +0 -62
- package/dist/clone-docs.js.map +0 -1
- package/dist/clone-web.d.ts +0 -12
- package/dist/clone-web.d.ts.map +0 -1
- package/dist/clone-web.js +0 -50
- package/dist/clone-web.js.map +0 -1
- package/dist/commands/agent.d.ts +0 -20
- package/dist/commands/agent.d.ts.map +0 -1
- package/dist/commands/agent.js +0 -315
- package/dist/commands/agent.js.map +0 -1
- package/dist/commands/ask.d.ts +0 -4
- package/dist/commands/ask.d.ts.map +0 -1
- package/dist/commands/ask.js +0 -8
- package/dist/commands/ask.js.map +0 -1
- package/dist/commands/bounty.d.ts +0 -4
- package/dist/commands/bounty.d.ts.map +0 -1
- package/dist/commands/bounty.js +0 -24
- package/dist/commands/bounty.js.map +0 -1
- package/dist/commands/buy.d.ts +0 -19
- package/dist/commands/buy.d.ts.map +0 -1
- package/dist/commands/buy.js +0 -63
- package/dist/commands/buy.js.map +0 -1
- package/dist/commands/capabilities.d.ts +0 -4
- package/dist/commands/capabilities.d.ts.map +0 -1
- package/dist/commands/capabilities.js +0 -18
- package/dist/commands/capabilities.js.map +0 -1
- package/dist/commands/claw.d.ts +0 -4
- package/dist/commands/claw.d.ts.map +0 -1
- package/dist/commands/claw.js +0 -14
- package/dist/commands/claw.js.map +0 -1
- package/dist/commands/commend.d.ts +0 -4
- package/dist/commands/commend.d.ts.map +0 -1
- package/dist/commands/commend.js +0 -13
- package/dist/commands/commend.js.map +0 -1
- package/dist/commands/completion.d.ts +0 -4
- package/dist/commands/completion.d.ts.map +0 -1
- package/dist/commands/completion.js +0 -49
- package/dist/commands/completion.js.map +0 -1
- package/dist/commands/config.d.ts +0 -4
- package/dist/commands/config.d.ts.map +0 -1
- package/dist/commands/config.js +0 -78
- package/dist/commands/config.js.map +0 -1
- package/dist/commands/deploy.d.ts +0 -4
- package/dist/commands/deploy.d.ts.map +0 -1
- package/dist/commands/deploy.js +0 -45
- package/dist/commands/deploy.js.map +0 -1
- package/dist/commands/doctor.d.ts +0 -4
- package/dist/commands/doctor.d.ts.map +0 -1
- package/dist/commands/doctor.js +0 -72
- package/dist/commands/doctor.js.map +0 -1
- package/dist/commands/domain.d.ts +0 -4
- package/dist/commands/domain.d.ts.map +0 -1
- package/dist/commands/domain.js +0 -19
- package/dist/commands/domain.js.map +0 -1
- package/dist/commands/export.d.ts +0 -4
- package/dist/commands/export.d.ts.map +0 -1
- package/dist/commands/export.js +0 -15
- package/dist/commands/export.js.map +0 -1
- package/dist/commands/fade.d.ts +0 -4
- package/dist/commands/fade.d.ts.map +0 -1
- package/dist/commands/fade.js +0 -15
- package/dist/commands/fade.js.map +0 -1
- package/dist/commands/flag.d.ts +0 -4
- package/dist/commands/flag.d.ts.map +0 -1
- package/dist/commands/flag.js +0 -13
- package/dist/commands/flag.js.map +0 -1
- package/dist/commands/forget.d.ts +0 -4
- package/dist/commands/forget.d.ts.map +0 -1
- package/dist/commands/forget.js +0 -16
- package/dist/commands/forget.js.map +0 -1
- package/dist/commands/frontier.d.ts +0 -4
- package/dist/commands/frontier.d.ts.map +0 -1
- package/dist/commands/frontier.js +0 -11
- package/dist/commands/frontier.js.map +0 -1
- package/dist/commands/group.d.ts +0 -3
- package/dist/commands/group.d.ts.map +0 -1
- package/dist/commands/group.js +0 -123
- package/dist/commands/group.js.map +0 -1
- package/dist/commands/health.d.ts +0 -4
- package/dist/commands/health.d.ts.map +0 -1
- package/dist/commands/health.js +0 -11
- package/dist/commands/health.js.map +0 -1
- package/dist/commands/highways.d.ts +0 -4
- package/dist/commands/highways.d.ts.map +0 -1
- package/dist/commands/highways.js +0 -14
- package/dist/commands/highways.js.map +0 -1
- package/dist/commands/hire.d.ts +0 -4
- package/dist/commands/hire.d.ts.map +0 -1
- package/dist/commands/hire.js +0 -16
- package/dist/commands/hire.js.map +0 -1
- package/dist/commands/init.d.ts +0 -17
- package/dist/commands/init.d.ts.map +0 -1
- package/dist/commands/init.js +0 -308
- package/dist/commands/init.js.map +0 -1
- package/dist/commands/invite.d.ts +0 -4
- package/dist/commands/invite.d.ts.map +0 -1
- package/dist/commands/invite.js +0 -37
- package/dist/commands/invite.js.map +0 -1
- package/dist/commands/know.d.ts +0 -4
- package/dist/commands/know.d.ts.map +0 -1
- package/dist/commands/know.js +0 -8
- package/dist/commands/know.js.map +0 -1
- package/dist/commands/launch.d.ts +0 -4
- package/dist/commands/launch.d.ts.map +0 -1
- package/dist/commands/launch.js +0 -16
- package/dist/commands/launch.js.map +0 -1
- package/dist/commands/mark.d.ts +0 -4
- package/dist/commands/mark.d.ts.map +0 -1
- package/dist/commands/mark.js +0 -15
- package/dist/commands/mark.js.map +0 -1
- package/dist/commands/pay.d.ts +0 -4
- package/dist/commands/pay.d.ts.map +0 -1
- package/dist/commands/pay.js +0 -21
- package/dist/commands/pay.js.map +0 -1
- package/dist/commands/pipe.d.ts +0 -4
- package/dist/commands/pipe.d.ts.map +0 -1
- package/dist/commands/pipe.js +0 -35
- package/dist/commands/pipe.js.map +0 -1
- package/dist/commands/publish.d.ts +0 -4
- package/dist/commands/publish.d.ts.map +0 -1
- package/dist/commands/publish.js +0 -23
- package/dist/commands/publish.js.map +0 -1
- package/dist/commands/recall.d.ts +0 -4
- package/dist/commands/recall.d.ts.map +0 -1
- package/dist/commands/recall.js +0 -12
- package/dist/commands/recall.js.map +0 -1
- package/dist/commands/repl.d.ts +0 -4
- package/dist/commands/repl.d.ts.map +0 -1
- package/dist/commands/repl.js +0 -56
- package/dist/commands/repl.js.map +0 -1
- package/dist/commands/reveal.d.ts +0 -4
- package/dist/commands/reveal.d.ts.map +0 -1
- package/dist/commands/reveal.js +0 -11
- package/dist/commands/reveal.js.map +0 -1
- package/dist/commands/revenue.d.ts +0 -4
- package/dist/commands/revenue.d.ts.map +0 -1
- package/dist/commands/revenue.js +0 -11
- package/dist/commands/revenue.js.map +0 -1
- package/dist/commands/select.d.ts +0 -4
- package/dist/commands/select.d.ts.map +0 -1
- package/dist/commands/select.js +0 -19
- package/dist/commands/select.js.map +0 -1
- package/dist/commands/sell.d.ts +0 -15
- package/dist/commands/sell.d.ts.map +0 -1
- package/dist/commands/sell.js +0 -49
- package/dist/commands/sell.js.map +0 -1
- package/dist/commands/signal.d.ts +0 -4
- package/dist/commands/signal.d.ts.map +0 -1
- package/dist/commands/signal.js +0 -8
- package/dist/commands/signal.js.map +0 -1
- package/dist/commands/stats.d.ts +0 -4
- package/dist/commands/stats.d.ts.map +0 -1
- package/dist/commands/stats.js +0 -11
- package/dist/commands/stats.js.map +0 -1
- package/dist/commands/status.d.ts +0 -4
- package/dist/commands/status.d.ts.map +0 -1
- package/dist/commands/status.js +0 -18
- package/dist/commands/status.js.map +0 -1
- package/dist/commands/subscribe.d.ts +0 -14
- package/dist/commands/subscribe.d.ts.map +0 -1
- package/dist/commands/subscribe.js +0 -33
- package/dist/commands/subscribe.js.map +0 -1
- package/dist/commands/sync.d.ts +0 -4
- package/dist/commands/sync.d.ts.map +0 -1
- package/dist/commands/sync.js +0 -20
- package/dist/commands/sync.js.map +0 -1
- package/dist/commands/tail.d.ts +0 -4
- package/dist/commands/tail.d.ts.map +0 -1
- package/dist/commands/tail.js +0 -51
- package/dist/commands/tail.js.map +0 -1
- package/dist/commands/warn.d.ts +0 -4
- package/dist/commands/warn.d.ts.map +0 -1
- package/dist/commands/warn.js +0 -15
- package/dist/commands/warn.js.map +0 -1
- package/dist/copy-claude-config.d.ts +0 -2
- package/dist/copy-claude-config.d.ts.map +0 -1
- package/dist/copy-claude-config.js +0 -32
- package/dist/copy-claude-config.js.map +0 -1
- package/dist/create-org-profile.d.ts +0 -10
- package/dist/create-org-profile.d.ts.map +0 -1
- package/dist/create-org-profile.js +0 -136
- package/dist/create-org-profile.js.map +0 -1
- package/dist/create-user-profile.d.ts +0 -9
- package/dist/create-user-profile.d.ts.map +0 -1
- package/dist/create-user-profile.js +0 -115
- package/dist/create-user-profile.js.map +0 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -375
- package/dist/index.js.map +0 -1
- package/dist/lib/agent-detection.d.ts +0 -19
- package/dist/lib/agent-detection.d.ts.map +0 -1
- package/dist/lib/agent-detection.js +0 -87
- package/dist/lib/agent-detection.js.map +0 -1
- package/dist/lib/args.d.ts +0 -11
- package/dist/lib/args.d.ts.map +0 -1
- package/dist/lib/args.js +0 -57
- package/dist/lib/args.js.map +0 -1
- package/dist/lib/config.d.ts +0 -12
- package/dist/lib/config.d.ts.map +0 -1
- package/dist/lib/config.js +0 -38
- package/dist/lib/config.js.map +0 -1
- package/dist/lib/detect.d.ts +0 -45
- package/dist/lib/detect.d.ts.map +0 -1
- package/dist/lib/detect.js +0 -221
- package/dist/lib/detect.js.map +0 -1
- package/dist/lib/http.d.ts +0 -9
- package/dist/lib/http.d.ts.map +0 -1
- package/dist/lib/http.js +0 -25
- package/dist/lib/http.js.map +0 -1
- package/dist/lib/output.d.ts +0 -5
- package/dist/lib/output.d.ts.map +0 -1
- package/dist/lib/output.js +0 -32
- package/dist/lib/output.js.map +0 -1
- package/dist/lib/sdk.d.ts +0 -10
- package/dist/lib/sdk.d.ts.map +0 -1
- package/dist/lib/sdk.js +0 -22
- package/dist/lib/sdk.js.map +0 -1
- package/dist/lib/telemetry.d.ts +0 -4
- package/dist/lib/telemetry.d.ts.map +0 -1
- package/dist/lib/telemetry.js +0 -61
- package/dist/lib/telemetry.js.map +0 -1
- package/dist/sync-agents.d.ts +0 -5
- package/dist/sync-agents.d.ts.map +0 -1
- package/dist/sync-agents.js +0 -28
- package/dist/sync-agents.js.map +0 -1
- package/dist/sync-ontology.d.ts +0 -4
- package/dist/sync-ontology.d.ts.map +0 -1
- package/dist/sync-ontology.js +0 -40
- package/dist/sync-ontology.js.map +0 -1
- package/dist/utils/file-resolver.d.ts +0 -83
- package/dist/utils/file-resolver.d.ts.map +0 -1
- package/dist/utils/file-resolver.js +0 -194
- package/dist/utils/file-resolver.js.map +0 -1
- package/dist/utils/installation-setup.d.ts +0 -88
- package/dist/utils/installation-setup.d.ts.map +0 -1
- package/dist/utils/installation-setup.js +0 -409
- package/dist/utils/installation-setup.js.map +0 -1
- package/dist/utils/launch-claude.d.ts +0 -7
- package/dist/utils/launch-claude.d.ts.map +0 -1
- package/dist/utils/launch-claude.js +0 -86
- package/dist/utils/launch-claude.js.map +0 -1
- package/dist/utils/validation.d.ts +0 -48
- package/dist/utils/validation.d.ts.map +0 -1
- package/dist/utils/validation.js +0 -73
- package/dist/utils/validation.js.map +0 -1
package/dist/src/args.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
function coerce(v) {
|
|
2
|
+
if (v === 'true')
|
|
3
|
+
return true;
|
|
4
|
+
if (v === 'false')
|
|
5
|
+
return false;
|
|
6
|
+
if (v !== '' && !Number.isNaN(Number(v)))
|
|
7
|
+
return Number(v);
|
|
8
|
+
return v;
|
|
9
|
+
}
|
|
10
|
+
export function parseArgs(rest) {
|
|
11
|
+
const positional = [];
|
|
12
|
+
const flags = {};
|
|
13
|
+
const fromFlags = {};
|
|
14
|
+
let body = {};
|
|
15
|
+
let dryRun = false;
|
|
16
|
+
let simulate = false;
|
|
17
|
+
for (let i = 0; i < rest.length; i++) {
|
|
18
|
+
const tok = rest[i];
|
|
19
|
+
if (tok.startsWith('--')) {
|
|
20
|
+
const eq = tok.indexOf('=');
|
|
21
|
+
const key = (eq === -1 ? tok.slice(2) : tok.slice(2, eq));
|
|
22
|
+
if (key === 'dry-run') {
|
|
23
|
+
dryRun = true;
|
|
24
|
+
flags[key] = true;
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (key === 'simulate') {
|
|
28
|
+
simulate = true;
|
|
29
|
+
flags[key] = true;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
let val;
|
|
33
|
+
if (eq !== -1)
|
|
34
|
+
val = tok.slice(eq + 1);
|
|
35
|
+
else if (i + 1 < rest.length && !rest[i + 1].startsWith('--'))
|
|
36
|
+
val = rest[++i];
|
|
37
|
+
else
|
|
38
|
+
val = true;
|
|
39
|
+
flags[key] = val;
|
|
40
|
+
fromFlags[key] = typeof val === 'string' ? coerce(val) : val;
|
|
41
|
+
}
|
|
42
|
+
else if (tok.trimStart().startsWith('{')) {
|
|
43
|
+
try {
|
|
44
|
+
const parsed = JSON.parse(tok);
|
|
45
|
+
if (parsed && typeof parsed === 'object')
|
|
46
|
+
body = { ...body, ...parsed };
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
throw new Error(`invalid JSON payload: ${tok}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
positional.push(tok);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
body = { ...body, ...fromFlags };
|
|
57
|
+
simulate = simulate || dryRun;
|
|
58
|
+
if (simulate)
|
|
59
|
+
body.simulate = true;
|
|
60
|
+
return { receiver: positional[0], positional, body, dryRun, simulate, flags };
|
|
61
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
/** Shared by `auth login` (nested) and the top-level `login` alias — same
|
|
3
|
+
* Command shape, same action, registered under two parents (contract #11). */
|
|
4
|
+
export declare function buildLoginCommand(): Command;
|
|
5
|
+
export declare function authCmd(): Command;
|
|
6
|
+
export declare function loadKey(): string | null;
|
package/dist/src/auth.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { writeFileSync, readFileSync, existsSync, mkdirSync, chmodSync, unlinkSync, renameSync, } from 'node:fs';
|
|
3
|
+
import { resolve, join } from 'node:path';
|
|
4
|
+
import { homedir } from 'node:os';
|
|
5
|
+
import { requestDeviceCode, openBrowser, pollForToken } from './device-flow.js';
|
|
6
|
+
const CONFIG_DIR = resolve(homedir(), '.config', 'oneie');
|
|
7
|
+
const KEY_FILE = resolve(CONFIG_DIR, 'key');
|
|
8
|
+
const DEFAULT_API = process.env.ONEIE_BASE_URL ?? 'https://one.ie';
|
|
9
|
+
const CLI_CLIENT_ID = 'oneie-cli';
|
|
10
|
+
const CLI_SCOPE = 'read write';
|
|
11
|
+
/** Shared by `auth login` (nested) and the top-level `login` alias — same
|
|
12
|
+
* Command shape, same action, registered under two parents (contract #11). */
|
|
13
|
+
export function buildLoginCommand() {
|
|
14
|
+
const cmd = new Command('login')
|
|
15
|
+
.description('Sign in via browser and persist token to ~/.config/oneie/key')
|
|
16
|
+
.option('--key <key>', 'Skip browser flow — store API key directly (or set ONEIE_API_KEY)')
|
|
17
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
18
|
+
.action(async (opts) => {
|
|
19
|
+
// Fast path: explicit --key or ONEIE_API_KEY env var (legacy / CI)
|
|
20
|
+
const envKey = opts.key ?? process.env.ONEIE_API_KEY;
|
|
21
|
+
if (envKey) {
|
|
22
|
+
writeKey(envKey);
|
|
23
|
+
out(cmd, { ok: true, stored: KEY_FILE, permissions: '0600', method: 'key' });
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
// Device-flow path
|
|
27
|
+
const base = opts.api.replace(/\/$/, '');
|
|
28
|
+
try {
|
|
29
|
+
// (a) Request device code
|
|
30
|
+
process.stderr.write('Requesting device authorization…\n');
|
|
31
|
+
const dc = await requestDeviceCode(base, CLI_CLIENT_ID, CLI_SCOPE);
|
|
32
|
+
// (b) Open browser — include user_code as a hint in the verification URL
|
|
33
|
+
const sep = dc.verification_uri.includes('?') ? '&' : '?';
|
|
34
|
+
const verifyUrl = `${dc.verification_uri}${sep}user_code=${encodeURIComponent(dc.user_code)}`;
|
|
35
|
+
process.stderr.write(`\nOpen this URL in your browser to sign in:\n ${verifyUrl}\n`);
|
|
36
|
+
process.stderr.write(`\nYour one-time code: ${dc.user_code}\n`);
|
|
37
|
+
process.stderr.write('(The browser should open automatically)\n\n');
|
|
38
|
+
await openBrowser(verifyUrl);
|
|
39
|
+
// (c) Poll until token or expiry
|
|
40
|
+
process.stderr.write(`Waiting for sign-in (expires in ${dc.expires_in}s)…\n`);
|
|
41
|
+
const token = await pollForToken(base, CLI_CLIENT_ID, dc.device_code, dc.interval, dc.expires_in);
|
|
42
|
+
// (d) Write token to ~/.config/oneie/key mode 0600
|
|
43
|
+
writeKey(token.access_token);
|
|
44
|
+
// (e) Print success — emit userId if server returned it
|
|
45
|
+
const userId = token.userId ?? 'unknown';
|
|
46
|
+
out(cmd, {
|
|
47
|
+
ok: true,
|
|
48
|
+
stored: KEY_FILE,
|
|
49
|
+
permissions: '0600',
|
|
50
|
+
method: 'device-flow',
|
|
51
|
+
userId,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
const msg = err.message;
|
|
56
|
+
if (process.env.DEBUG) {
|
|
57
|
+
process.stderr.write(`${err.stack ?? msg}\n`);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
process.stderr.write(`Login failed: ${msg}\n`);
|
|
61
|
+
}
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
return cmd;
|
|
66
|
+
}
|
|
67
|
+
export function authCmd() {
|
|
68
|
+
const cmd = new Command('auth').description('Authentication');
|
|
69
|
+
cmd.addCommand(buildLoginCommand());
|
|
70
|
+
cmd.command('logout')
|
|
71
|
+
.description('Remove stored API key')
|
|
72
|
+
.action(() => {
|
|
73
|
+
if (existsSync(KEY_FILE)) {
|
|
74
|
+
unlinkSync(KEY_FILE);
|
|
75
|
+
out(cmd, { ok: true, cleared: KEY_FILE });
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
out(cmd, { ok: true, cleared: null, note: 'no key was stored' });
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
return cmd;
|
|
82
|
+
}
|
|
83
|
+
export function loadKey() {
|
|
84
|
+
if (process.env.ONEIE_API_KEY)
|
|
85
|
+
return process.env.ONEIE_API_KEY;
|
|
86
|
+
if (existsSync(KEY_FILE)) {
|
|
87
|
+
const val = readFileSync(KEY_FILE, 'utf8').trim();
|
|
88
|
+
return val || null;
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
// ---------------------------------------------------------------------------
|
|
93
|
+
// Internal helpers
|
|
94
|
+
// ---------------------------------------------------------------------------
|
|
95
|
+
/**
|
|
96
|
+
* Atomically write `value` to KEY_FILE with mode 0600.
|
|
97
|
+
* Write to a temp file first, then rename — avoids a race where a concurrent
|
|
98
|
+
* reader sees a half-written key file.
|
|
99
|
+
*/
|
|
100
|
+
function writeKey(value) {
|
|
101
|
+
mkdirSync(CONFIG_DIR, { recursive: true });
|
|
102
|
+
const tmp = join(CONFIG_DIR, '.key.tmp');
|
|
103
|
+
writeFileSync(tmp, value, { mode: 0o600 });
|
|
104
|
+
chmodSync(tmp, 0o600);
|
|
105
|
+
renameSync(tmp, KEY_FILE);
|
|
106
|
+
}
|
|
107
|
+
function out(cmd, data) {
|
|
108
|
+
const isJson = cmd.parent?.opts().json;
|
|
109
|
+
if (isJson) {
|
|
110
|
+
process.stdout.write(JSON.stringify(data) + '\n');
|
|
111
|
+
}
|
|
112
|
+
else if (data.ok) {
|
|
113
|
+
const pairs = Object.entries(data)
|
|
114
|
+
.filter(([k]) => k !== 'ok')
|
|
115
|
+
.map(([k, v]) => `${k}=${JSON.stringify(v)}`)
|
|
116
|
+
.join(' ');
|
|
117
|
+
console.log('✓', pairs);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
console.error('✗', String(data.error));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// The ONE wordmark — ported from legacy 3.8.3's banner.js, plain stdout
|
|
2
|
+
// (no chalk: the current CLI stays dependency-lean). Shown only on the
|
|
3
|
+
// human-TTY paths (bare invocation, `create`) — never for an agent shell,
|
|
4
|
+
// which wants signal, not decoration.
|
|
5
|
+
export function displayBanner() {
|
|
6
|
+
process.stdout.write(`
|
|
7
|
+
██████╗ ███╗ ██╗███████╗
|
|
8
|
+
██╔═══██╗████╗ ██║██╔════╝
|
|
9
|
+
██║ ██║██╔██╗ ██║█████╗
|
|
10
|
+
██║ ██║██║╚██╗██║██╔══╝
|
|
11
|
+
╚██████╔╝██║ ╚████║███████╗
|
|
12
|
+
╚═════╝ ╚═╝ ╚═══╝╚══════╝
|
|
13
|
+
Turn ideas into reality — https://one.ie
|
|
14
|
+
|
|
15
|
+
`);
|
|
16
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
/** `one broadcast` — operate newsletters from the terminal.
|
|
3
|
+
* Two verbs: list + send. Both hit broadcast:* receivers via ask(); no new route. */
|
|
4
|
+
export declare function broadcastCmd(): Command;
|
|
5
|
+
/** `one newsletter` — pull/push newsletter block trees from the terminal. */
|
|
6
|
+
export declare function newsletterCmd(): Command;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { authHeaders, resolveBase } from './lib/client.js';
|
|
3
|
+
const DEFAULT_API = resolveBase({}, 'https://api.one.ie');
|
|
4
|
+
async function ask(api, receiver, data) {
|
|
5
|
+
const res = await fetch(`${api.replace(/\/$/, '')}/api/ask/${encodeURIComponent(receiver)}`, {
|
|
6
|
+
method: 'POST',
|
|
7
|
+
headers: authHeaders(),
|
|
8
|
+
body: JSON.stringify({ data }),
|
|
9
|
+
});
|
|
10
|
+
if (!res.ok) {
|
|
11
|
+
process.stderr.write(`POST /api/ask/${receiver} → ${res.status}\n`);
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
|
14
|
+
return res.json();
|
|
15
|
+
}
|
|
16
|
+
function out(data) {
|
|
17
|
+
process.stdout.write(JSON.stringify(data, null, 2) + '\n');
|
|
18
|
+
}
|
|
19
|
+
/** `one broadcast` — operate newsletters from the terminal.
|
|
20
|
+
* Two verbs: list + send. Both hit broadcast:* receivers via ask(); no new route. */
|
|
21
|
+
export function broadcastCmd() {
|
|
22
|
+
const cmd = new Command('broadcast').description('Operate email broadcasts (newsletters)');
|
|
23
|
+
cmd
|
|
24
|
+
.command('list')
|
|
25
|
+
.description('List broadcasts for the workspace')
|
|
26
|
+
.option('--limit <n>', 'Max results', '20')
|
|
27
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
28
|
+
.action(async (opts) => {
|
|
29
|
+
out(await ask(opts.api, 'broadcast:list', { limit: Number(opts.limit) }));
|
|
30
|
+
});
|
|
31
|
+
cmd
|
|
32
|
+
.command('send <id>')
|
|
33
|
+
.description('Send a broadcast now (inline drain, suppression-checked)')
|
|
34
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
35
|
+
.action(async (id, opts) => {
|
|
36
|
+
out(await ask(opts.api, 'broadcast:send', { broadcastId: id }));
|
|
37
|
+
});
|
|
38
|
+
return cmd;
|
|
39
|
+
}
|
|
40
|
+
// ---------------------------------------------------------------------------
|
|
41
|
+
// Inline block serialization — mirrors serialize.ts; no Zod dep (CLI rule)
|
|
42
|
+
// ---------------------------------------------------------------------------
|
|
43
|
+
function serializeBlocksMd(blocks) {
|
|
44
|
+
return blocks.map(({ kind, ...rest }) => '```block ' + kind + '\n' + JSON.stringify(rest) + '\n```').join('\n\n');
|
|
45
|
+
}
|
|
46
|
+
function parseBlocksMd(md) {
|
|
47
|
+
const blocks = [];
|
|
48
|
+
const fence = /^```block ([a-z]+)\n([\s\S]*?)\n```$/gm;
|
|
49
|
+
let m;
|
|
50
|
+
while ((m = fence.exec(md)) !== null) {
|
|
51
|
+
const lineNo = md.slice(0, m.index).split('\n').length;
|
|
52
|
+
try {
|
|
53
|
+
const body = JSON.parse(m[2]);
|
|
54
|
+
blocks.push({ kind: m[1], ...body });
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
throw new Error(`parseBlocks: invalid JSON at line ${lineNo}: ${e instanceof Error ? e.message : e}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return blocks;
|
|
61
|
+
}
|
|
62
|
+
function diffBlocks(before, after) {
|
|
63
|
+
const diffs = [];
|
|
64
|
+
const beforeById = new Map(before.map(b => [b.id, b]));
|
|
65
|
+
const afterById = new Map(after.map(b => [b.id, b]));
|
|
66
|
+
for (const [id, b] of beforeById) {
|
|
67
|
+
if (!afterById.has(id)) {
|
|
68
|
+
diffs.push({ op: '-', kind: b.kind, id });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
for (const [id, a] of afterById) {
|
|
72
|
+
if (!beforeById.has(id)) {
|
|
73
|
+
diffs.push({ op: '+', kind: a.kind, id });
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
const b = beforeById.get(id);
|
|
77
|
+
if (JSON.stringify(b) !== JSON.stringify(a)) {
|
|
78
|
+
diffs.push({ op: '~', kind: a.kind, id });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return diffs;
|
|
83
|
+
}
|
|
84
|
+
/** `one newsletter` — pull/push newsletter block trees from the terminal. */
|
|
85
|
+
export function newsletterCmd() {
|
|
86
|
+
const cmd = new Command('newsletter').description('Pull and push newsletter component trees');
|
|
87
|
+
cmd
|
|
88
|
+
.command('pull <broadcastId>')
|
|
89
|
+
.description('Fetch a broadcast and print its blocks as markdown')
|
|
90
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
91
|
+
.action(async (broadcastId, opts) => {
|
|
92
|
+
const res = await ask(opts.api, 'broadcast:get', { broadcastId });
|
|
93
|
+
const b = res.broadcast;
|
|
94
|
+
if (!b) {
|
|
95
|
+
process.stderr.write(`broadcast:get returned no broadcast\n`);
|
|
96
|
+
process.exit(1);
|
|
97
|
+
}
|
|
98
|
+
if (b.components && Array.isArray(b.components) && b.components.length > 0) {
|
|
99
|
+
process.stdout.write(serializeBlocksMd(b.components) + '\n');
|
|
100
|
+
}
|
|
101
|
+
else if (b.body_md) {
|
|
102
|
+
process.stdout.write(b.body_md + '\n');
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
process.stdout.write('');
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
cmd
|
|
109
|
+
.command('push <broadcastId> <file>')
|
|
110
|
+
.description('Parse a markdown file and update broadcast components')
|
|
111
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
112
|
+
.option('--test', 'Dry-run: mark update as test_send')
|
|
113
|
+
.action(async (broadcastId, file, opts) => {
|
|
114
|
+
const { readFileSync } = await import('node:fs');
|
|
115
|
+
let md;
|
|
116
|
+
try {
|
|
117
|
+
md = readFileSync(file, 'utf8');
|
|
118
|
+
}
|
|
119
|
+
catch (e) {
|
|
120
|
+
process.stderr.write(`Cannot read ${file}: ${e instanceof Error ? e.message : e}\n`);
|
|
121
|
+
process.exit(1);
|
|
122
|
+
}
|
|
123
|
+
let components;
|
|
124
|
+
try {
|
|
125
|
+
components = parseBlocksMd(md);
|
|
126
|
+
}
|
|
127
|
+
catch (e) {
|
|
128
|
+
process.stderr.write(`${e instanceof Error ? e.message : e}\n`);
|
|
129
|
+
process.exit(1);
|
|
130
|
+
}
|
|
131
|
+
// Fetch current state for diff display
|
|
132
|
+
const current = await ask(opts.api, 'broadcast:get', { broadcastId });
|
|
133
|
+
const prev = (current.broadcast?.components ?? []);
|
|
134
|
+
const version = current.broadcast?.version;
|
|
135
|
+
const diffs = diffBlocks(prev, components);
|
|
136
|
+
for (const d of diffs) {
|
|
137
|
+
process.stdout.write(`${d.op} ${d.kind} (${d.id})\n`);
|
|
138
|
+
}
|
|
139
|
+
if (diffs.length === 0) {
|
|
140
|
+
process.stdout.write('(no changes)\n');
|
|
141
|
+
}
|
|
142
|
+
const payload = { broadcastId, components };
|
|
143
|
+
if (version !== undefined)
|
|
144
|
+
payload['version'] = version;
|
|
145
|
+
if (opts.test)
|
|
146
|
+
payload['test_send'] = true;
|
|
147
|
+
out(await ask(opts.api, 'broadcast:update', payload));
|
|
148
|
+
});
|
|
149
|
+
return cmd;
|
|
150
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { askPath } from './lib/api-path.js';
|
|
2
|
+
const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'https://api.one.ie';
|
|
3
|
+
function apiKey() {
|
|
4
|
+
return process.env.ONEIE_API_KEY ?? process.env.ONE_API_KEY ?? '';
|
|
5
|
+
}
|
|
6
|
+
function base(opts) {
|
|
7
|
+
return (opts.api ?? DEFAULT_API).replace(/\/$/, '');
|
|
8
|
+
}
|
|
9
|
+
function authHeaders() {
|
|
10
|
+
const h = { 'Content-Type': 'application/json' };
|
|
11
|
+
const k = apiKey();
|
|
12
|
+
if (k)
|
|
13
|
+
h['Authorization'] = `Bearer ${k}`;
|
|
14
|
+
return h;
|
|
15
|
+
}
|
|
16
|
+
const RECIPE_BLURB = {
|
|
17
|
+
spine: 'onboard — become an actor, mint a key, declare capability',
|
|
18
|
+
build: 'build a world — workspace, group, actor, thing',
|
|
19
|
+
trade: 'discover peers, hire, get paid',
|
|
20
|
+
transact: 'post a bounty, settle onchain',
|
|
21
|
+
};
|
|
22
|
+
function formatItem(it) {
|
|
23
|
+
const meta = [];
|
|
24
|
+
if (it.cost != null)
|
|
25
|
+
meta.push(`cost: ${typeof it.cost === 'object' ? JSON.stringify(it.cost) : it.cost}`);
|
|
26
|
+
if (it.settles && it.settles !== 'none')
|
|
27
|
+
meta.push(`settles: ${it.settles}`);
|
|
28
|
+
if (it.reversible === false)
|
|
29
|
+
meta.push('reversible: false');
|
|
30
|
+
const tail = meta.length ? ` · ${meta.join(' · ')}` : '';
|
|
31
|
+
return ` ${it.receiver.padEnd(28)}${it.summary ?? ''}${tail}`;
|
|
32
|
+
}
|
|
33
|
+
function formatCatalog(items, goal) {
|
|
34
|
+
if (goal) {
|
|
35
|
+
const match = items.filter((it) => it.receiver.toLowerCase().includes(goal.toLowerCase()));
|
|
36
|
+
if (!match.length)
|
|
37
|
+
return ` (no receivers matching "${goal}")`;
|
|
38
|
+
return `GOAL: ${goal}\n\n` + match.map(formatItem).join('\n');
|
|
39
|
+
}
|
|
40
|
+
const grouped = {};
|
|
41
|
+
for (const it of items) {
|
|
42
|
+
const group = it.receiver.split(':')[0] ?? 'other';
|
|
43
|
+
(grouped[group] ??= []).push(it);
|
|
44
|
+
}
|
|
45
|
+
const out = [];
|
|
46
|
+
for (const [group, groupItems] of Object.entries(grouped)) {
|
|
47
|
+
out.push(`${group.toUpperCase()} — ${RECIPE_BLURB[group] ?? ''}`);
|
|
48
|
+
groupItems.forEach((it) => out.push(formatItem(it)));
|
|
49
|
+
out.push('');
|
|
50
|
+
}
|
|
51
|
+
return out.join('\n');
|
|
52
|
+
}
|
|
53
|
+
export function catalogCommands(program) {
|
|
54
|
+
program
|
|
55
|
+
.command('catalog')
|
|
56
|
+
.description('Browse receiver surface by recipe')
|
|
57
|
+
.option('--goal <text>', 'Filter by receiver group or keyword')
|
|
58
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
59
|
+
.option('--json', 'Output raw JSON')
|
|
60
|
+
.action(async (opts) => {
|
|
61
|
+
const res = await fetch(askPath(base(opts), 'meta:catalog'), {
|
|
62
|
+
method: 'POST',
|
|
63
|
+
headers: authHeaders(),
|
|
64
|
+
body: JSON.stringify({ data: opts.goal ? { goal: opts.goal } : {} }),
|
|
65
|
+
});
|
|
66
|
+
if (!res.ok) {
|
|
67
|
+
process.stderr.write(`meta:catalog → ${res.status}\n`);
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
const data = await res.json();
|
|
71
|
+
if (opts.json) {
|
|
72
|
+
process.stdout.write(JSON.stringify(data, null, 2) + '\n');
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const items = (data.items ?? data.receivers ?? []);
|
|
76
|
+
process.stdout.write(formatCatalog(items, opts.goal) + '\n');
|
|
77
|
+
});
|
|
78
|
+
}
|
package/dist/src/chat.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { authHeaders, resolveBase, resolveKey } from './lib/client.js';
|
|
3
|
+
const DEFAULT_API = resolveBase({}, 'https://one.ie');
|
|
4
|
+
const DEFAULT_CHANNELS = process.env.CHANNELS_URL ?? 'https://channels.one.ie';
|
|
5
|
+
const DEFAULT_SPACES = ['vespio', 'elitemoversca', 'world'];
|
|
6
|
+
async function spacePost(api, space, content) {
|
|
7
|
+
const res = await fetch(`${api.replace(/\/$/, '')}/api/ask/space:post`, {
|
|
8
|
+
method: 'POST',
|
|
9
|
+
headers: authHeaders(),
|
|
10
|
+
body: JSON.stringify({ data: { space, content } }),
|
|
11
|
+
});
|
|
12
|
+
if (!res.ok)
|
|
13
|
+
return { ok: false, error: `HTTP ${res.status}` };
|
|
14
|
+
const j = await res.json();
|
|
15
|
+
return j.result ?? { ok: j.outcome === 'result', error: j.error };
|
|
16
|
+
}
|
|
17
|
+
export function chatCmd() {
|
|
18
|
+
const cmd = new Command('chat')
|
|
19
|
+
.description('Send messages to Spaces (fan-out) or listen for incoming messages (fan-in)');
|
|
20
|
+
// one chat "text" [--to space] [--broadcast]
|
|
21
|
+
cmd
|
|
22
|
+
.command('send <text>', { isDefault: true })
|
|
23
|
+
.description('Send a message to a Space (default: broadcast to all)')
|
|
24
|
+
.option('--to <space>', 'Target space slug (default: broadcast to vespio + elitemoversca + world)')
|
|
25
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
26
|
+
.action(async (text, opts) => {
|
|
27
|
+
if (opts.to) {
|
|
28
|
+
const r = await spacePost(opts.api, opts.to, text);
|
|
29
|
+
process.stdout.write(JSON.stringify(r, null, 2) + '\n');
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
const results = await Promise.all(DEFAULT_SPACES.map(s => spacePost(opts.api, s, text)));
|
|
33
|
+
results.forEach((r, i) => process.stdout.write(`→ space:${DEFAULT_SPACES[i]} ${r.ok ? r.id : r.error}\n`));
|
|
34
|
+
process.stdout.write(`ok broadcast to ${DEFAULT_SPACES.length} spaces\n`);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
// one chat broadcast "text"
|
|
38
|
+
cmd
|
|
39
|
+
.command('broadcast <text>')
|
|
40
|
+
.description('Fan-out to all default spaces (vespio + elitemoversca + world)')
|
|
41
|
+
.option('--spaces <list>', 'Comma-separated space slugs', DEFAULT_SPACES.join(','))
|
|
42
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
43
|
+
.action(async (text, opts) => {
|
|
44
|
+
const spaces = opts.spaces.split(',').map(s => s.trim()).filter(Boolean);
|
|
45
|
+
const results = await Promise.all(spaces.map(s => spacePost(opts.api, s, text)));
|
|
46
|
+
results.forEach((r, i) => process.stdout.write(`→ space:${spaces[i]} ${r.ok ? r.id : r.error}\n`));
|
|
47
|
+
process.stdout.write(`ok broadcast to ${spaces.length} spaces\n`);
|
|
48
|
+
});
|
|
49
|
+
// one chat listen <space>
|
|
50
|
+
cmd
|
|
51
|
+
.command('listen <space>')
|
|
52
|
+
.description('Stream incoming messages from a Space via SSE (Ctrl+C to stop)')
|
|
53
|
+
.option('--channels <url>', 'Channels base URL', DEFAULT_CHANNELS)
|
|
54
|
+
.action(async (space, opts) => {
|
|
55
|
+
const group = space.startsWith('space:') ? space : `space:${space}`;
|
|
56
|
+
const url = `${opts.channels.replace(/\/$/, '')}/stream/${encodeURIComponent(group)}`;
|
|
57
|
+
process.stderr.write(`Listening on ${group} — Ctrl+C to stop\n`);
|
|
58
|
+
const key = resolveKey();
|
|
59
|
+
const h = { Accept: 'text/event-stream' };
|
|
60
|
+
if (key)
|
|
61
|
+
h['Authorization'] = `Bearer ${key}`;
|
|
62
|
+
const res = await fetch(url, { headers: h });
|
|
63
|
+
if (!res.ok || !res.body) {
|
|
64
|
+
process.stderr.write(`stream error: ${res.status}\n`);
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
const reader = res.body.getReader();
|
|
68
|
+
const dec = new TextDecoder();
|
|
69
|
+
while (true) {
|
|
70
|
+
const { done, value } = await reader.read();
|
|
71
|
+
if (done)
|
|
72
|
+
break;
|
|
73
|
+
const chunk = dec.decode(value);
|
|
74
|
+
for (const line of chunk.split('\n')) {
|
|
75
|
+
if (!line.startsWith('data:'))
|
|
76
|
+
continue;
|
|
77
|
+
const raw = line.slice(5).trim();
|
|
78
|
+
if (!raw || raw === '[DONE]')
|
|
79
|
+
continue;
|
|
80
|
+
try {
|
|
81
|
+
const msg = JSON.parse(raw);
|
|
82
|
+
const t = msg.ts ? new Date(msg.ts).toISOString().slice(11, 19) : '';
|
|
83
|
+
process.stdout.write(`[${t}] ${msg.sender ?? '?'}: ${msg.content ?? raw}\n`);
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
process.stdout.write(raw + '\n');
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
return cmd;
|
|
92
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
/** `clients/<slug>.toml` — the scaffold `client add` reads. Optional keys are
|
|
3
|
+
* commented so `readClient()`'s defaults apply until the operator opts in. */
|
|
4
|
+
export declare function clientToml(name: string, slug: string): string;
|
|
5
|
+
export declare function clientCmd(): Command;
|