@oneie/cli 0.3.4 → 0.3.5
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/src/staff.js +46 -5
- package/package.json +1 -1
package/dist/src/staff.js
CHANGED
|
@@ -27,8 +27,8 @@ function out(data) {
|
|
|
27
27
|
export function staffCmd() {
|
|
28
28
|
const cmd = new Command('staff').description('Workspace staff management');
|
|
29
29
|
cmd
|
|
30
|
-
.command('invite
|
|
31
|
-
.description('Invite a human to your workspace
|
|
30
|
+
.command('invite [email]')
|
|
31
|
+
.description('Invite a human to your workspace; omit email to get an invite URL without sending mail')
|
|
32
32
|
.option('--role <role>', `Role to assign: ${VALID_ROLES.join('|')}`, 'admin')
|
|
33
33
|
.option('--workspace <slug>', 'Workspace slug (defaults to authenticated workspace)')
|
|
34
34
|
.option('--dry-run', 'Print plan without sending invite')
|
|
@@ -40,7 +40,7 @@ export function staffCmd() {
|
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
42
42
|
if (opts.dryRun) {
|
|
43
|
-
out({ ok: true, dry_run: true, email, role, workspace: opts.workspace ?? '(authenticated)' });
|
|
43
|
+
out({ ok: true, dry_run: true, email: email ?? '(url-only)', role, workspace: opts.workspace ?? '(authenticated)' });
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
46
46
|
const key = readApiKey();
|
|
@@ -49,7 +49,9 @@ export function staffCmd() {
|
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
51
|
const base = opts.api.replace(/\/$/, '');
|
|
52
|
-
const body = {
|
|
52
|
+
const body = { role };
|
|
53
|
+
if (email)
|
|
54
|
+
body.email = email;
|
|
53
55
|
if (opts.workspace)
|
|
54
56
|
body.workspace = opts.workspace;
|
|
55
57
|
const res = await fetch(`${base}/api/ask/world:invite-member`, {
|
|
@@ -68,7 +70,46 @@ export function staffCmd() {
|
|
|
68
70
|
return;
|
|
69
71
|
}
|
|
70
72
|
const inviteUrl = json.inviteUrl ?? (json.token ? `${base}/join?token=${encodeURIComponent(json.token)}` : undefined);
|
|
71
|
-
out({ ok: true, email, role, invite_url: inviteUrl ?? '(sent)' });
|
|
73
|
+
out({ ok: true, email: email ?? '(url-only)', role, invite_url: inviteUrl ?? '(sent)' });
|
|
74
|
+
});
|
|
75
|
+
cmd
|
|
76
|
+
.command('add-agent <name>')
|
|
77
|
+
.description('Create an agent in your workspace and print its key once')
|
|
78
|
+
.option('--role <role>', `Role to assign: ${VALID_ROLES.join('|')}`, 'member')
|
|
79
|
+
.option('--workspace <slug>', 'Workspace slug (defaults to authenticated workspace)')
|
|
80
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
81
|
+
.action(async (name, opts) => {
|
|
82
|
+
const role = opts.role;
|
|
83
|
+
if (!VALID_ROLES.includes(role)) {
|
|
84
|
+
out({ ok: false, error: `--role must be one of: ${VALID_ROLES.join(', ')}` });
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const key = readApiKey();
|
|
88
|
+
if (!key) {
|
|
89
|
+
out({ ok: false, error: 'no API key — set ONEIE_API_KEY or run: oneie auth login' });
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const base = opts.api.replace(/\/$/, '');
|
|
93
|
+
const body = { name, role };
|
|
94
|
+
if (opts.workspace)
|
|
95
|
+
body.workspace = opts.workspace;
|
|
96
|
+
const res = await fetch(`${base}/api/ask/world:invite-agent`, {
|
|
97
|
+
method: 'POST',
|
|
98
|
+
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${key}` },
|
|
99
|
+
body: JSON.stringify({ data: body }),
|
|
100
|
+
});
|
|
101
|
+
if (!res.ok) {
|
|
102
|
+
const text = await res.text().catch(() => '');
|
|
103
|
+
out({ ok: false, error: `${res.status}: ${text}` });
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const json = (await res.json());
|
|
107
|
+
if (json.error) {
|
|
108
|
+
out({ ok: false, error: json.error });
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const result = json.result ?? json;
|
|
112
|
+
out({ ok: true, name, role, aid: result.aid, key: result.key });
|
|
72
113
|
});
|
|
73
114
|
return cmd;
|
|
74
115
|
}
|