@parall/cli 1.91.0 → 1.93.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/commands/apps-access.d.ts +7 -0
- package/dist/commands/apps-access.d.ts.map +1 -1
- package/dist/commands/apps-access.js +41 -15
- package/dist/commands/clip-connect.d.ts.map +1 -1
- package/dist/commands/clip-connect.js +1 -4
- package/dist/commands/clip.js +4 -0
- package/dist/commands/secrets.d.ts.map +1 -1
- package/dist/commands/secrets.js +61 -8
- package/dist/commands/templates-propose.d.ts +49 -0
- package/dist/commands/templates-propose.d.ts.map +1 -0
- package/dist/commands/templates-propose.js +262 -0
- package/dist/commands/templates.d.ts +11 -0
- package/dist/commands/templates.d.ts.map +1 -0
- package/dist/commands/templates.js +50 -0
- package/dist/index.js +2 -0
- package/dist/lib/output.d.ts +2 -0
- package/dist/lib/output.d.ts.map +1 -1
- package/dist/lib/output.js +4 -0
- package/package.json +4 -4
|
@@ -2,6 +2,13 @@ import type { MiniAppAccessLevel } from '@parall/sdk';
|
|
|
2
2
|
import type { Command } from 'commander';
|
|
3
3
|
/** A member level as given on the command line. */
|
|
4
4
|
export declare function parseMemberLevel(raw: string | undefined, what: string): MiniAppAccessLevel;
|
|
5
|
+
/** Who an access list row is for, as given on the command line: a person or
|
|
6
|
+
* agent (usr_…) or a team (team_…), bare or as a prll:// reference. Anything
|
|
7
|
+
* else stops before a request is made. */
|
|
8
|
+
export declare function parseGrantee(raw: string): {
|
|
9
|
+
kind: 'user' | 'team';
|
|
10
|
+
id: string;
|
|
11
|
+
};
|
|
5
12
|
/** A level on the access list: never below read. */
|
|
6
13
|
export declare function parseGrantLevel(raw: string | undefined): 'read' | 'write';
|
|
7
14
|
export declare function registerAppAccessCommands(app: Command): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apps-access.d.ts","sourceRoot":"","sources":["../../src/commands/apps-access.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"apps-access.d.ts","sourceRoot":"","sources":["../../src/commands/apps-access.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA2DzC,mDAAmD;AACnD,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,kBAAkB,CAI1F;AAED;;0CAE0C;AAC1C,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAO/E;AAED,oDAAoD;AACpD,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,CAIzE;AAED,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,OAAO,QAqHrD"}
|
|
@@ -3,14 +3,17 @@ import { parsePositiveInt, printError, printJson, stripPrllScheme } from '../lib
|
|
|
3
3
|
import { appAndArg, appIdFrom, withApp } from './apps-args.js';
|
|
4
4
|
/** `parall app access list | members | add | remove | log`
|
|
5
5
|
* (docs/engineering-design/mini-app-access-design.md §6.3): how far the rest
|
|
6
|
-
* of the organization reaches into an app, the people given more
|
|
7
|
-
* one, and the record of
|
|
8
|
-
* change
|
|
6
|
+
* of the organization reaches into an app, the people and teams given more
|
|
7
|
+
* one by one (mini-app-access-team-grants-design.md §3), and the record of
|
|
8
|
+
* every change. The server decides who may see and change what; these
|
|
9
|
+
* commands only name the request. */
|
|
9
10
|
/** The levels the help and the local errors name: everyone else in the
|
|
10
|
-
* organization can be held at any of the three, a person
|
|
11
|
-
* at read or write. */
|
|
11
|
+
* organization can be held at any of the three, a person or team added one
|
|
12
|
+
* by one at read or write. */
|
|
12
13
|
const MEMBER_LEVELS = 'none, read or write';
|
|
13
14
|
const LEVELS = 'read or write';
|
|
15
|
+
/** What add and remove name after the app. */
|
|
16
|
+
const GRANTEE = 'user or team ID (usr_… or team_…)';
|
|
14
17
|
const ACCESS_HELP = `
|
|
15
18
|
Levels:
|
|
16
19
|
none not in their app list and does not open; references to it show as
|
|
@@ -23,6 +26,12 @@ People added one by one (add) get the higher of that and their own level:
|
|
|
23
26
|
the list only ever gives more, it never takes anyone below the member
|
|
24
27
|
level. The app's authors and org owners/admins always hold it outright.
|
|
25
28
|
|
|
29
|
+
A team can be added the same way (add <app> <team_…>): its level reaches
|
|
30
|
+
everyone on the team and on every team below it, agents included, and the
|
|
31
|
+
human managers of the teams above it. It follows the teams as they are, so
|
|
32
|
+
people joining or leaving a team need no change here; deleting the team
|
|
33
|
+
takes it off the list. Team IDs: parall teams list.
|
|
34
|
+
|
|
26
35
|
Who can change it: the app's authors (agents too) and org owners/admins.
|
|
27
36
|
Anyone who can open the app sees the member level and their own level
|
|
28
37
|
(list); only those who can change it also see the list and the record of
|
|
@@ -50,6 +59,17 @@ export function parseMemberLevel(raw, what) {
|
|
|
50
59
|
return level;
|
|
51
60
|
throw new Error(`${what} must be ${MEMBER_LEVELS}`);
|
|
52
61
|
}
|
|
62
|
+
/** Who an access list row is for, as given on the command line: a person or
|
|
63
|
+
* agent (usr_…) or a team (team_…), bare or as a prll:// reference. Anything
|
|
64
|
+
* else stops before a request is made. */
|
|
65
|
+
export function parseGrantee(raw) {
|
|
66
|
+
const id = stripPrllScheme(raw.trim());
|
|
67
|
+
if (id.startsWith('usr_'))
|
|
68
|
+
return { kind: 'user', id };
|
|
69
|
+
if (id.startsWith('team_'))
|
|
70
|
+
return { kind: 'team', id };
|
|
71
|
+
throw new Error(`${raw} is not a person or agent (usr_…) or a team (team_…); find team IDs with: parall teams list`);
|
|
72
|
+
}
|
|
53
73
|
/** A level on the access list: never below read. */
|
|
54
74
|
export function parseGrantLevel(raw) {
|
|
55
75
|
const level = raw?.trim();
|
|
@@ -60,11 +80,11 @@ export function parseGrantLevel(raw) {
|
|
|
60
80
|
export function registerAppAccessCommands(app) {
|
|
61
81
|
const access = app
|
|
62
82
|
.command('access')
|
|
63
|
-
.description('Who can use an app: everyone else in the organization (none, read or write), and people added one by one (read or write)')
|
|
83
|
+
.description('Who can use an app: everyone else in the organization (none, read or write), and people or teams added one by one (read or write)')
|
|
64
84
|
.addHelpText('after', ACCESS_HELP);
|
|
65
85
|
withApp(access
|
|
66
86
|
.command('list')
|
|
67
|
-
.description("Show the app's member level and your own level; its authors and org owners/admins also see
|
|
87
|
+
.description("Show the app's member level and your own level; its authors and org owners/admins also see the people and teams added one by one")).action(async (appId, opts) => {
|
|
68
88
|
try {
|
|
69
89
|
const id = appIdFrom(appId, opts.app);
|
|
70
90
|
const { client, orgId } = resolveCredentials();
|
|
@@ -93,17 +113,20 @@ export function registerAppAccessCommands(app) {
|
|
|
93
113
|
});
|
|
94
114
|
access
|
|
95
115
|
.command('add')
|
|
96
|
-
.description("Give a member of the organization (person or agent) read or write on the app, or change
|
|
116
|
+
.description("Give a member of the organization (person or agent) or a team read or write on the app, or change the level (the app's authors or an org owner/admin)")
|
|
97
117
|
.argument('[appId]', 'App ID (app_… or prll://app_…); or pass --app')
|
|
98
|
-
.argument('[
|
|
118
|
+
.argument('[id]', 'User or agent ID (usr_…), or team ID (team_…)')
|
|
99
119
|
.option('--app <appId>', 'App ID, in place of the first argument')
|
|
100
120
|
.requiredOption('--level <level>', LEVELS)
|
|
101
121
|
.action(async (first, second, opts) => {
|
|
102
122
|
try {
|
|
103
|
-
const [id,
|
|
123
|
+
const [id, raw] = appAndArg(first, second, opts.app, GRANTEE);
|
|
124
|
+
const grantee = parseGrantee(raw);
|
|
104
125
|
const level = parseGrantLevel(opts.level);
|
|
105
126
|
const { client, orgId } = resolveCredentials();
|
|
106
|
-
printJson(
|
|
127
|
+
printJson(grantee.kind === 'team'
|
|
128
|
+
? await client.setMiniAppAccessTeamGrant(orgId, id, grantee.id, level)
|
|
129
|
+
: await client.setMiniAppAccessGrant(orgId, id, grantee.id, level));
|
|
107
130
|
}
|
|
108
131
|
catch (err) {
|
|
109
132
|
printError(err);
|
|
@@ -111,15 +134,18 @@ export function registerAppAccessCommands(app) {
|
|
|
111
134
|
});
|
|
112
135
|
access
|
|
113
136
|
.command('remove')
|
|
114
|
-
.description("Take someone off the app's access list; they keep the member level (the app's authors or an org owner/admin)")
|
|
137
|
+
.description("Take someone, or a team, off the app's access list; they keep the member level (the app's authors or an org owner/admin)")
|
|
115
138
|
.argument('[appId]', 'App ID (app_… or prll://app_…); or pass --app')
|
|
116
|
-
.argument('[
|
|
139
|
+
.argument('[id]', 'User or agent ID (usr_…), or team ID (team_…)')
|
|
117
140
|
.option('--app <appId>', 'App ID, in place of the first argument')
|
|
118
141
|
.action(async (first, second, opts) => {
|
|
119
142
|
try {
|
|
120
|
-
const [id,
|
|
143
|
+
const [id, raw] = appAndArg(first, second, opts.app, GRANTEE);
|
|
144
|
+
const grantee = parseGrantee(raw);
|
|
121
145
|
const { client, orgId } = resolveCredentials();
|
|
122
|
-
printJson(
|
|
146
|
+
printJson(grantee.kind === 'team'
|
|
147
|
+
? await client.removeMiniAppAccessTeamGrant(orgId, id, grantee.id)
|
|
148
|
+
: await client.removeMiniAppAccessGrant(orgId, id, grantee.id));
|
|
123
149
|
}
|
|
124
150
|
catch (err) {
|
|
125
151
|
printError(err);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clip-connect.d.ts","sourceRoot":"","sources":["../../src/commands/clip-connect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAU,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"clip-connect.d.ts","sourceRoot":"","sources":["../../src/commands/clip-connect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAU,MAAM,WAAW,CAAC;AA0GjD,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAqH9D"}
|
|
@@ -3,7 +3,7 @@ import { ApiError, CLIP_CONNECTION_CONNECT_ACTION } from '@parall/sdk';
|
|
|
3
3
|
import { printFiledApproval } from '../lib/approvers.js';
|
|
4
4
|
import { resolveCredentials, resolveRuntimeContext } from '../lib/client.js';
|
|
5
5
|
import { CLIP_REF_HELP, clipNotFoundError, connectorRefArg, findConnector, } from '../lib/connector-ref.js';
|
|
6
|
-
import { printError, printJson, printProgress, stripPrllScheme } from '../lib/output.js';
|
|
6
|
+
import { printError, printJson, printProgress, shellQuote, stripPrllScheme, } from '../lib/output.js';
|
|
7
7
|
// `parall connector connect` is how an agent that cannot run a connector yet
|
|
8
8
|
// gets an account for it (agent-connector-connect-design.md §4): it files a
|
|
9
9
|
// `clip.connection.connect` approval, and the person taps Connect on the card
|
|
@@ -13,9 +13,6 @@ Examples:
|
|
|
13
13
|
parall connector connect google-calendar --reason "Check whether you are free tomorrow afternoon"
|
|
14
14
|
parall connector connect jira --reason "File this bug in the team's Jira" --from org`;
|
|
15
15
|
const USAGE_HINT = '(example: parall connector connect google-calendar --reason "Check whether you are free tomorrow afternoon"; add --help for usage)';
|
|
16
|
-
function shellQuote(value) {
|
|
17
|
-
return `'${value.replaceAll("'", `'\\''`)}'`;
|
|
18
|
-
}
|
|
19
16
|
function detailsOf(err) {
|
|
20
17
|
const details = err.extras?.details;
|
|
21
18
|
return details && typeof details === 'object' ? details : {};
|
package/dist/commands/clip.js
CHANGED
|
@@ -114,9 +114,11 @@ function registerClipTree(clip) {
|
|
|
114
114
|
catch (err) {
|
|
115
115
|
connectionsError = err instanceof Error ? err.message : String(err);
|
|
116
116
|
}
|
|
117
|
+
// display_name is what people call it; commands still take `name`.
|
|
117
118
|
const rows = clips.map((c) => ({
|
|
118
119
|
id: c.id,
|
|
119
120
|
name: c.name,
|
|
121
|
+
...(c.display_name ? { display_name: c.display_name } : {}),
|
|
120
122
|
...(c.description ? { description: c.description } : {}),
|
|
121
123
|
version: c.version ?? '-',
|
|
122
124
|
visibility: c.visibility,
|
|
@@ -169,6 +171,7 @@ function registerClipTree(clip) {
|
|
|
169
171
|
printJson(entries.map((c) => ({
|
|
170
172
|
id: c.id,
|
|
171
173
|
name: c.name,
|
|
174
|
+
...(c.display_name ? { display_name: c.display_name } : {}),
|
|
172
175
|
publisher: c.org_id === orgId ? 'your org' : c.org_id,
|
|
173
176
|
...(c.description ? { description: c.description } : {}),
|
|
174
177
|
version: c.version ?? '-',
|
|
@@ -241,6 +244,7 @@ function registerClipTree(clip) {
|
|
|
241
244
|
const info = {
|
|
242
245
|
id: entry.id,
|
|
243
246
|
name: entry.name,
|
|
247
|
+
...(entry.display_name ? { display_name: entry.display_name } : {}),
|
|
244
248
|
version: entry.version,
|
|
245
249
|
description: entry.description,
|
|
246
250
|
visibility: entry.visibility,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secrets.d.ts","sourceRoot":"","sources":["../../src/commands/secrets.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"secrets.d.ts","sourceRoot":"","sources":["../../src/commands/secrets.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA6JpC,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,QAsItD"}
|
package/dist/commands/secrets.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AGENT_SECRET_LAYER_ACTIONS, AGENT_SECRET_REQUEST_ACTION, } from '@parall/sdk';
|
|
2
2
|
import { printFiledApproval } from '../lib/approvers.js';
|
|
3
3
|
import { resolveCredentials } from '../lib/client.js';
|
|
4
|
-
import { printError, printJson, printProgress, stripPrllScheme } from '../lib/output.js';
|
|
4
|
+
import { printError, printJson, printProgress, shellQuote, stripPrllScheme, } from '../lib/output.js';
|
|
5
5
|
// The request action per layer: --from asks to use a key there, --in to have
|
|
6
6
|
// one made.
|
|
7
7
|
const ACTIONS = {
|
|
@@ -9,9 +9,42 @@ const ACTIONS = {
|
|
|
9
9
|
in: AGENT_SECRET_LAYER_ACTIONS.new,
|
|
10
10
|
};
|
|
11
11
|
const WHERE_FORMS = 'org, team:<team_…> or user:<usr_…>';
|
|
12
|
-
|
|
12
|
+
const DISPLAY_NAME_SLOT = '--display-name "<short name people read>"';
|
|
13
|
+
/**
|
|
14
|
+
* The request an agent copies, filling in only its purpose and chat — and,
|
|
15
|
+
* for a key that is made (--in), the name people will read for it.
|
|
16
|
+
*/
|
|
13
17
|
function requestCommand(name, flag, where) {
|
|
14
|
-
|
|
18
|
+
const displayName = flag === '--in' ? ` ${DISPLAY_NAME_SLOT}` : '';
|
|
19
|
+
return `parall secrets request ${name} ${flag} ${where}${displayName} --purpose "<what the key is for>" --chat <chat>`;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The request as it was typed, with the display name still to fill in: what
|
|
23
|
+
* a refusal for a missing one gives the agent to copy.
|
|
24
|
+
*/
|
|
25
|
+
function requestWithDisplayNameSlot(name, opts) {
|
|
26
|
+
return [
|
|
27
|
+
'parall secrets request',
|
|
28
|
+
name,
|
|
29
|
+
...(opts.in !== undefined ? ['--in', shellQuote(opts.in)] : []),
|
|
30
|
+
DISPLAY_NAME_SLOT,
|
|
31
|
+
'--purpose',
|
|
32
|
+
shellQuote(opts.purpose),
|
|
33
|
+
...(opts.reason !== undefined ? ['--reason', shellQuote(opts.reason)] : []),
|
|
34
|
+
...(opts.where !== undefined ? ['--where', shellQuote(opts.where)] : []),
|
|
35
|
+
'--chat',
|
|
36
|
+
shellQuote(opts.chat),
|
|
37
|
+
].join(' ');
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Whether a request for a key of the agent's own would replace one it has:
|
|
41
|
+
* the card then has to say why, which the purpose alone cannot. As the server
|
|
42
|
+
* decides it (the card's "needs a new key"): a key of its own that it has for
|
|
43
|
+
* long. One it was given for this time only is not replaced by asking again.
|
|
44
|
+
*/
|
|
45
|
+
async function replacesOwnKey(client, orgId, name) {
|
|
46
|
+
const catalog = await client.getMyAgentSecretCatalog(orgId, name);
|
|
47
|
+
return (catalog.data ?? []).some((entry) => entry.scope === 'agent' && entry.name === name && entry.grant?.kind !== 'once');
|
|
15
48
|
}
|
|
16
49
|
/** Where a key it may ask to use lives, as --from takes it. */
|
|
17
50
|
function fromOf(entry) {
|
|
@@ -85,7 +118,7 @@ export function registerSecretCommands(program) {
|
|
|
85
118
|
.description('Find the keys you have or may ask for, and ask a person for one');
|
|
86
119
|
secrets
|
|
87
120
|
.command('list')
|
|
88
|
-
.description("List the keys you have and the ones you may ask to use — the organization's, your teams', other people's and agents' (names and purposes, never values) — your requests still waiting, and the teams you may propose a key in")
|
|
121
|
+
.description("List the keys you have and the ones you may ask to use — the organization's, your teams', other people's and agents' (names, display names and purposes, never values) — your requests still waiting, and the teams you may propose a key in")
|
|
89
122
|
.action(async () => {
|
|
90
123
|
try {
|
|
91
124
|
await printCatalog();
|
|
@@ -96,8 +129,8 @@ export function registerSecretCommands(program) {
|
|
|
96
129
|
});
|
|
97
130
|
secrets
|
|
98
131
|
.command('search')
|
|
99
|
-
.description('Like list, but only the keys whose name, purpose or owner contains the word (ignoring case); each one you may ask to use comes with the request to run')
|
|
100
|
-
.argument('<word>', 'A word from the key name, its purpose or its owner, e.g. github')
|
|
132
|
+
.description('Like list, but only the keys whose name, display name, purpose or owner contains the word (ignoring case); each one you may ask to use comes with the request to run')
|
|
133
|
+
.argument('<word>', 'A word from the key name, its display name, its purpose or its owner, e.g. github')
|
|
101
134
|
.action(async (word) => {
|
|
102
135
|
try {
|
|
103
136
|
await printCatalog(word);
|
|
@@ -110,17 +143,25 @@ export function registerSecretCommands(program) {
|
|
|
110
143
|
.command('request')
|
|
111
144
|
.description('Post a request card for a key: to use one that exists (--from), to have a new one made (--in), or, with neither, for a key of your own — the person who manages you, or an org admin, enters it and a key of yours with the same name gets the new value.')
|
|
112
145
|
.argument('<name>', 'The key name your commands will read, e.g. GITHUB_TOKEN')
|
|
113
|
-
.requiredOption('--purpose <text>', '
|
|
146
|
+
.requiredOption('--purpose <text>', 'What the key is FOR, one line for a non-engineer, e.g. "Open pull requests in the website repo"')
|
|
147
|
+
.option('--reason <text>', 'Why you need it NOW, not what it is for (that is --purpose), e.g. "The old token expired"; shown on the card as Markdown. Required when you replace a key of your own you already have')
|
|
114
148
|
.requiredOption('--chat <chatId>', 'Chat to post the card in — the one you are working in (e.g. prll://cht_456)')
|
|
115
149
|
.option('--from <where>', `Ask to use a key that exists, in ${WHERE_FORMS} (a person or another agent); copy it from \`parall secrets search\`. Whoever decides for that key approves; nobody enters a value`)
|
|
116
150
|
.option('--in <where>', `Propose a new key in ${WHERE_FORMS} (a person); the person who approves types it, and the key stays there`)
|
|
151
|
+
.option('--display-name <text>', 'The name people read for the key, on the card and in its notification: say what it is in their language, at most 40 characters, e.g. "GitHub token". Required for a key that is made (every request without --from); a key that exists keeps the name it has')
|
|
117
152
|
.option('--where <text>', 'Where a person can get such a key, if you know (not with --from)')
|
|
118
153
|
.option('--shared', 'Same as --from org')
|
|
119
|
-
.action(async (
|
|
154
|
+
.action(async (rawName, opts) => {
|
|
120
155
|
try {
|
|
156
|
+
// As the server reads it: looked up, compared and filed without the spaces around it.
|
|
157
|
+
const name = rawName.trim();
|
|
121
158
|
if (opts.shared && opts.from !== undefined) {
|
|
122
159
|
throw new Error('--shared is --from org: give one of them');
|
|
123
160
|
}
|
|
161
|
+
const reason = opts.reason === undefined ? undefined : String(opts.reason).trim();
|
|
162
|
+
if (reason === '') {
|
|
163
|
+
throw new Error('--reason is empty: say why you need the key now, e.g. --reason "The old token expired" (what the key is for goes in --purpose), or leave --reason out');
|
|
164
|
+
}
|
|
124
165
|
const fromRaw = opts.shared ? 'org' : opts.from;
|
|
125
166
|
if (fromRaw !== undefined && opts.in !== undefined) {
|
|
126
167
|
throw new Error('Give --from (use a key that exists) or --in (propose a new one), not both');
|
|
@@ -128,19 +169,31 @@ export function registerSecretCommands(program) {
|
|
|
128
169
|
if (fromRaw !== undefined && opts.where !== undefined) {
|
|
129
170
|
throw new Error('--where does not apply with --from or --shared: nobody enters a value for a key that exists');
|
|
130
171
|
}
|
|
172
|
+
const displayName = opts.displayName?.trim();
|
|
173
|
+
if (fromRaw !== undefined && opts.displayName !== undefined) {
|
|
174
|
+
throw new Error('--display-name does not apply with --from or --shared: a key that exists keeps the name its owner gave it. Run the same command without --display-name');
|
|
175
|
+
}
|
|
131
176
|
const { client, orgId } = resolveCredentials();
|
|
132
177
|
const kind = fromRaw !== undefined ? 'from' : 'in';
|
|
133
178
|
const raw = fromRaw ?? opts.in;
|
|
134
179
|
const target = raw !== undefined ? parseWhere(`--${kind}`, raw, orgId) : undefined;
|
|
180
|
+
if (fromRaw === undefined && !displayName) {
|
|
181
|
+
throw new Error(`--display-name is missing: a key that is made needs the name people read on the card instead of ${name} — what the key is, in their language, at most 40 characters (GitHub token, 公司邮箱密码). Run: ${requestWithDisplayNameSlot(name, opts)}`);
|
|
182
|
+
}
|
|
183
|
+
if (!target && reason === undefined && (await replacesOwnKey(client, orgId, name))) {
|
|
184
|
+
throw new Error(`You already have ${name}, so this request replaces it: add --reason saying why it must change, e.g. --reason "The old token expired" (what the key is for goes in --purpose)`);
|
|
185
|
+
}
|
|
135
186
|
const result = await client.requestApproval(orgId, {
|
|
136
187
|
action_type: target ? ACTIONS[kind][target.layer] : AGENT_SECRET_REQUEST_ACTION,
|
|
137
188
|
resource_uri: `prll://${target ? target.id : (await client.getMe()).id}`,
|
|
138
189
|
action_payload: {
|
|
139
190
|
name,
|
|
191
|
+
...(displayName ? { display_name: displayName } : {}),
|
|
140
192
|
purpose: opts.purpose,
|
|
141
193
|
...(opts.where !== undefined ? { source: opts.where } : {}),
|
|
142
194
|
},
|
|
143
195
|
chat_id: stripPrllScheme(opts.chat),
|
|
196
|
+
...(reason !== undefined ? { reason } : {}),
|
|
144
197
|
// The server writes the title; the endpoint still requires one.
|
|
145
198
|
title: name,
|
|
146
199
|
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Command } from 'commander';
|
|
2
|
+
import { type TemplateCatalogItem } from '@parall/sdk';
|
|
3
|
+
/** What the command was asked to propose, as the copyable command repeats it. */
|
|
4
|
+
export interface ProposeInput {
|
|
5
|
+
template: string;
|
|
6
|
+
reason?: string;
|
|
7
|
+
name?: string;
|
|
8
|
+
params: Record<string, string>;
|
|
9
|
+
chat?: string;
|
|
10
|
+
threadRootId?: string;
|
|
11
|
+
}
|
|
12
|
+
/** A parameter still to fill in: its key, and what to ask the person for. */
|
|
13
|
+
export interface ParamPlaceholder {
|
|
14
|
+
key: string;
|
|
15
|
+
label?: string;
|
|
16
|
+
}
|
|
17
|
+
/** A refusal with the step that would work instead. */
|
|
18
|
+
export declare class ProposeRefusal extends Error {
|
|
19
|
+
readonly nextStep?: string | undefined;
|
|
20
|
+
constructor(message: string, nextStep?: string | undefined);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The propose command in its named form: the values given, a placeholder for
|
|
24
|
+
* the reason when there is none, and one `--param key=<…>` per parameter
|
|
25
|
+
* still to fill in.
|
|
26
|
+
*/
|
|
27
|
+
export declare function proposeCommand(input: ProposeInput, missing?: ParamPlaceholder[]): string;
|
|
28
|
+
/** Parses repeatable --param key=value flags; a key given twice is refused. */
|
|
29
|
+
export declare function parseParams(values: string[] | undefined): Record<string, string>;
|
|
30
|
+
/** The template as given: its ID, or a name to look up in the catalog. */
|
|
31
|
+
export declare function templateArg(raw: string): {
|
|
32
|
+
id: string;
|
|
33
|
+
} | {
|
|
34
|
+
name: string;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Resolves a catalog name to its template ID. Anything that is not exactly
|
|
38
|
+
* one catalog entry stops here, before a card is filed.
|
|
39
|
+
*/
|
|
40
|
+
export declare function resolveTemplateName(name: string, catalog: TemplateCatalogItem[], input: Omit<ProposeInput, 'template'>): TemplateCatalogItem;
|
|
41
|
+
/** The next step for each refusal of the card itself. */
|
|
42
|
+
export declare function refusalStep(err: unknown, input: ProposeInput): string | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* A refusal as the agent reads it: what was wrong, then what to run. Plain
|
|
45
|
+
* lines; the server's code stays in brackets for reference.
|
|
46
|
+
*/
|
|
47
|
+
export declare function refusalText(err: unknown, nextStep?: string): string;
|
|
48
|
+
export declare function registerTemplateProposeCommand(templates: Command): void;
|
|
49
|
+
//# sourceMappingURL=templates-propose.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templates-propose.d.ts","sourceRoot":"","sources":["../../src/commands/templates-propose.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAIL,KAAK,mBAAmB,EAEzB,MAAM,aAAa,CAAC;AAqCrB,iFAAiF;AACjF,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,6EAA6E;AAC7E,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,uDAAuD;AACvD,qBAAa,cAAe,SAAQ,KAAK;IAGrC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM;gBAD1B,OAAO,EAAE,MAAM,EACN,QAAQ,CAAC,EAAE,MAAM,YAAA;CAI7B;AAMD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,GAAE,gBAAgB,EAAO,GAAG,MAAM,CAe5F;AAcD,+EAA+E;AAC/E,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAmBhF;AAED,0EAA0E;AAC1E,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAW1E;AAID;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,mBAAmB,EAAE,EAC9B,KAAK,EAAE,IAAI,CAAC,YAAY,EAAE,UAAU,CAAC,GACpC,mBAAmB,CAmBrB;AASD,yDAAyD;AACzD,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,GAAG,MAAM,GAAG,SAAS,CAqBjF;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAInE;AAiED,wBAAgB,8BAA8B,CAAC,SAAS,EAAE,OAAO,GAAG,IAAI,CAkFvE"}
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { ApiError, TEMPLATE_TEAM_HIRE_ACTION, } from '@parall/sdk';
|
|
2
|
+
import { printFiledApproval } from '../lib/approvers.js';
|
|
3
|
+
import { resolveCredentials, resolveRuntimeContext } from '../lib/client.js';
|
|
4
|
+
import { CALLER_SCOPE_NEXT_STEPS, printJson, printProgress, stripPrllScheme, } from '../lib/output.js';
|
|
5
|
+
// `parall templates propose` is how an agent suggests a whole agent team to
|
|
6
|
+
// the person it works with: it files a `template.team.hire` card in the chat
|
|
7
|
+
// it is working in, a person there taps 创建团队 (Create team), and the team is
|
|
8
|
+
// created in the background. The server freezes the template onto the card and
|
|
9
|
+
// checks everything else; this command only shapes the request and turns each
|
|
10
|
+
// refusal into the command that would work.
|
|
11
|
+
const REASON_PLACEHOLDER = '"<why it fits + its first task>"';
|
|
12
|
+
const LIST_STEP = 'Each team you can propose, with its command to copy: parall templates list';
|
|
13
|
+
const EXAMPLES = `
|
|
14
|
+
Example:
|
|
15
|
+
parall templates propose --template tpl_abc123 --reason "Fits your launch; first task: audit the signup funnel" --param company=Acme
|
|
16
|
+
|
|
17
|
+
Each template's ready-to-run line: parall templates list`;
|
|
18
|
+
const USAGE_HINT = `(example: parall templates propose --template <tpl_…> --reason ${REASON_PLACEHOLDER}; each template's line: parall templates list)`;
|
|
19
|
+
/** A refusal with the step that would work instead. */
|
|
20
|
+
export class ProposeRefusal extends Error {
|
|
21
|
+
nextStep;
|
|
22
|
+
constructor(message, nextStep) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.nextStep = nextStep;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function shellArg(value) {
|
|
28
|
+
return /^[A-Za-z0-9_./:=@,+-]+$/.test(value) ? value : `'${value.replaceAll("'", `'\\''`)}'`;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The propose command in its named form: the values given, a placeholder for
|
|
32
|
+
* the reason when there is none, and one `--param key=<…>` per parameter
|
|
33
|
+
* still to fill in.
|
|
34
|
+
*/
|
|
35
|
+
export function proposeCommand(input, missing = []) {
|
|
36
|
+
const parts = ['parall templates propose', '--template', shellArg(input.template)];
|
|
37
|
+
parts.push('--reason', input.reason ? shellArg(input.reason) : REASON_PLACEHOLDER);
|
|
38
|
+
if (input.name)
|
|
39
|
+
parts.push('--name', shellArg(input.name));
|
|
40
|
+
const missingKeys = new Set(missing.map((p) => p.key));
|
|
41
|
+
for (const [key, value] of Object.entries(input.params)) {
|
|
42
|
+
if (!missingKeys.has(key))
|
|
43
|
+
parts.push('--param', shellArg(`${key}=${value}`));
|
|
44
|
+
}
|
|
45
|
+
for (const p of missing) {
|
|
46
|
+
const label = p.label?.trim().replace(/[<>]/g, '');
|
|
47
|
+
parts.push('--param', shellArg(`${p.key}=<${label || 'value'}>`));
|
|
48
|
+
}
|
|
49
|
+
if (input.chat)
|
|
50
|
+
parts.push('--chat', input.chat);
|
|
51
|
+
if (input.threadRootId)
|
|
52
|
+
parts.push('--thread-root-id', input.threadRootId);
|
|
53
|
+
return parts.join(' ');
|
|
54
|
+
}
|
|
55
|
+
/** A value still shaped like the placeholder it was copied from. */
|
|
56
|
+
const isPlaceholder = (value) => /^<[^<>]*>$/.test(value.trim());
|
|
57
|
+
function placeholderRefusal(option, value) {
|
|
58
|
+
return new ProposeRefusal(`${option} is still the placeholder ${value.trim()}: put the real value in its place.`, option === '--param'
|
|
59
|
+
? 'Ask the person for any value you do not know, then run the command again.'
|
|
60
|
+
: undefined);
|
|
61
|
+
}
|
|
62
|
+
/** Parses repeatable --param key=value flags; a key given twice is refused. */
|
|
63
|
+
export function parseParams(values) {
|
|
64
|
+
const out = {};
|
|
65
|
+
for (const raw of values ?? []) {
|
|
66
|
+
const eq = raw.indexOf('=');
|
|
67
|
+
const key = eq > 0 ? raw.slice(0, eq).trim() : '';
|
|
68
|
+
if (!key) {
|
|
69
|
+
throw new ProposeRefusal(`--param takes key=value, not "${raw}".`, 'Give each value as --param key=value, for example --param company=Acme.');
|
|
70
|
+
}
|
|
71
|
+
const value = raw.slice(eq + 1);
|
|
72
|
+
if (isPlaceholder(value))
|
|
73
|
+
throw placeholderRefusal('--param', `${key}=${value}`);
|
|
74
|
+
if (Object.hasOwn(out, key)) {
|
|
75
|
+
throw new ProposeRefusal(`--param ${key} is given twice.`, `Give ${key} once.`);
|
|
76
|
+
}
|
|
77
|
+
out[key] = value;
|
|
78
|
+
}
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
81
|
+
/** The template as given: its ID, or a name to look up in the catalog. */
|
|
82
|
+
export function templateArg(raw) {
|
|
83
|
+
const trimmed = raw.trim();
|
|
84
|
+
if (!trimmed)
|
|
85
|
+
throw new ProposeRefusal('--template is empty.', LIST_STEP);
|
|
86
|
+
if (isPlaceholder(trimmed))
|
|
87
|
+
throw placeholderRefusal('--template', trimmed);
|
|
88
|
+
const bare = stripPrllScheme(trimmed);
|
|
89
|
+
if (bare.startsWith('tpl_'))
|
|
90
|
+
return { id: bare };
|
|
91
|
+
// A prll:// reference is an ID, never a template's name.
|
|
92
|
+
if (trimmed.startsWith('prll://')) {
|
|
93
|
+
throw new ProposeRefusal(`${trimmed} is not a team template.`, LIST_STEP);
|
|
94
|
+
}
|
|
95
|
+
return { name: trimmed };
|
|
96
|
+
}
|
|
97
|
+
const memberNames = (t) => (t.members ?? []).map((m) => m.name).join(', ');
|
|
98
|
+
/**
|
|
99
|
+
* Resolves a catalog name to its template ID. Anything that is not exactly
|
|
100
|
+
* one catalog entry stops here, before a card is filed.
|
|
101
|
+
*/
|
|
102
|
+
export function resolveTemplateName(name, catalog, input) {
|
|
103
|
+
const wanted = name.trim().toLowerCase();
|
|
104
|
+
const matches = catalog.filter((t) => t.name.trim().toLowerCase() === wanted);
|
|
105
|
+
if (matches.length === 1)
|
|
106
|
+
return matches[0];
|
|
107
|
+
if (matches.length > 1) {
|
|
108
|
+
const lines = matches.map((t) => {
|
|
109
|
+
const members = memberNames(t);
|
|
110
|
+
return ` ${proposeCommand({ ...input, template: t.template_id })}${members ? ` # ${members}` : ''}`;
|
|
111
|
+
});
|
|
112
|
+
throw new ProposeRefusal(`More than one team template is named "${name.trim()}".`, `Pick one by its ID:\n${lines.join('\n')}`);
|
|
113
|
+
}
|
|
114
|
+
// Not a catalog name, but shaped like another kind of ID (cht_…, usr_…).
|
|
115
|
+
if (/^[a-z]{2,4}_[A-Za-z0-9]+$/.test(name.trim())) {
|
|
116
|
+
throw new ProposeRefusal(`${name.trim()} is not a team template.`, LIST_STEP);
|
|
117
|
+
}
|
|
118
|
+
throw new ProposeRefusal(`No team template is named "${name.trim()}".`, LIST_STEP);
|
|
119
|
+
}
|
|
120
|
+
function missingKeys(err) {
|
|
121
|
+
const details = err.extras?.details;
|
|
122
|
+
if (!details || typeof details !== 'object')
|
|
123
|
+
return [];
|
|
124
|
+
const missing = details.missing;
|
|
125
|
+
return Array.isArray(missing) ? missing.filter((k) => typeof k === 'string') : [];
|
|
126
|
+
}
|
|
127
|
+
/** The next step for each refusal of the card itself. */
|
|
128
|
+
export function refusalStep(err, input) {
|
|
129
|
+
if (!(err instanceof ApiError))
|
|
130
|
+
return undefined;
|
|
131
|
+
switch (err.code) {
|
|
132
|
+
case 'MISSING_PARAMETER': {
|
|
133
|
+
const keys = missingKeys(err);
|
|
134
|
+
const command = proposeCommand(input, keys.map((key) => ({ key })));
|
|
135
|
+
return `No card posted: the team needs ${keys.length > 0 ? keys.join(', ') : 'more values'} to name its channel or project. Ask the person for what you do not know, then run:\n ${command}`;
|
|
136
|
+
}
|
|
137
|
+
case 'INVALID_RESOURCE_URI':
|
|
138
|
+
case 'TEMPLATE_NOT_FOUND':
|
|
139
|
+
return `No card posted: ${input.template} is not a team template this organization can hire. ${LIST_STEP}`;
|
|
140
|
+
case 'REQUESTER_NOT_ALLOWED':
|
|
141
|
+
return 'No card posted: team cards come from an active agent of this organization. A person asks an agent in the chat to propose the team, or an org admin hires it on the Templates page.';
|
|
142
|
+
case 'INVALID_ACTION_PAYLOAD':
|
|
143
|
+
return 'No card posted. Fix what the error names (--reason, --name or --param) and run the command again; see `parall templates propose --help`.';
|
|
144
|
+
default:
|
|
145
|
+
return err.code ? CALLER_SCOPE_NEXT_STEPS[err.code] : undefined;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* A refusal as the agent reads it: what was wrong, then what to run. Plain
|
|
150
|
+
* lines; the server's code stays in brackets for reference.
|
|
151
|
+
*/
|
|
152
|
+
export function refusalText(err, nextStep) {
|
|
153
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
154
|
+
const code = err instanceof ApiError && err.code ? ` [${err.code}]` : '';
|
|
155
|
+
return `error: ${message}${code}${nextStep ? `\n${nextStep}` : ''}`;
|
|
156
|
+
}
|
|
157
|
+
function refuse(err, nextStep) {
|
|
158
|
+
console.error(refusalText(err, nextStep));
|
|
159
|
+
return process.exit(1);
|
|
160
|
+
}
|
|
161
|
+
/** Checks everything that can be refused before any request. */
|
|
162
|
+
function readInput(opts) {
|
|
163
|
+
const reason = opts.reason.trim();
|
|
164
|
+
if (!reason) {
|
|
165
|
+
throw new ProposeRefusal('--reason needs one line for the person: why this team fits and its first task.');
|
|
166
|
+
}
|
|
167
|
+
if (isPlaceholder(reason))
|
|
168
|
+
throw placeholderRefusal('--reason', reason);
|
|
169
|
+
const name = opts.name?.trim() || undefined;
|
|
170
|
+
if (name && isPlaceholder(name))
|
|
171
|
+
throw placeholderRefusal('--name', name);
|
|
172
|
+
const params = parseParams(opts.param);
|
|
173
|
+
const chat = opts.chat?.trim() || undefined;
|
|
174
|
+
if (chat && !stripPrllScheme(chat).startsWith('cht_')) {
|
|
175
|
+
throw new ProposeRefusal(`--chat takes a chat (cht_…), not ${chat}.`, 'Leave --chat out to post the card in the chat you are working in.');
|
|
176
|
+
}
|
|
177
|
+
const threadRootId = opts.threadRootId !== undefined ? stripPrllScheme(opts.threadRootId.trim()) : undefined;
|
|
178
|
+
if (threadRootId !== undefined && !threadRootId.startsWith('msg_')) {
|
|
179
|
+
throw new ProposeRefusal(`--thread-root-id takes the thread's first message (msg_…), not ${opts.threadRootId}.`);
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
template: opts.template,
|
|
183
|
+
reason,
|
|
184
|
+
name,
|
|
185
|
+
params,
|
|
186
|
+
chat: chat ? stripPrllScheme(chat) : undefined,
|
|
187
|
+
threadRootId,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
function printProposed(result, fallbackTitle) {
|
|
191
|
+
printJson(result);
|
|
192
|
+
const team = result.title || fallbackTitle;
|
|
193
|
+
if (result.deduplicated) {
|
|
194
|
+
printFiledApproval(result, 'Already waiting');
|
|
195
|
+
printProgress(`Nothing new was posted: a card for this team is already waiting. Point the person to it (they tap 创建团队 (Create team)); to change it, withdraw it first with \`parall approvals cancel ${result.id}\` and run this command again.`);
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
printProgress(`Tell the person, in their language: "I proposed ${team} on a card: tap 创建团队 (Create team) to create it, and I'll get the team started."`);
|
|
199
|
+
printFiledApproval(result, 'Created');
|
|
200
|
+
}
|
|
201
|
+
printProgress('End your turn now. You are woken when they decide and again when the team is ready — do not wait with `parall approvals wait`.');
|
|
202
|
+
}
|
|
203
|
+
export function registerTemplateProposeCommand(templates) {
|
|
204
|
+
templates
|
|
205
|
+
.command('propose')
|
|
206
|
+
.description('Propose a team from `parall templates list` to the person you are working with, on a card in the chat. When someone there taps 创建团队 (Create team) the team is created; you are woken when they decide and again when the team is ready, to open its new channel')
|
|
207
|
+
.usage(`--template <tpl_…> --reason ${REASON_PLACEHOLDER} [--name "<team name>"] [--param key=value]… [--chat <cht_…>] [--thread-root-id <msg_…>]`)
|
|
208
|
+
.requiredOption('--template <tpl_…>', 'Template ID from `parall templates list` (prll://tpl_… works too); a name from that list works when it is unique')
|
|
209
|
+
.requiredOption('--reason <text>', 'One line for the person, in their language: why this team fits and its first task (at most 300 characters)')
|
|
210
|
+
.option('--name <name>', "Name for the new team (default: the template's name)")
|
|
211
|
+
.option('--param <key=value>', 'A value for one of the template parameters; repeat for each. `parall templates list` shows the ones a template needs', (value, previous = []) => [...previous, value])
|
|
212
|
+
.option('--chat <cht_…>', 'Chat to post the card in (default: the chat you are working in)')
|
|
213
|
+
.option('--thread-root-id <msg_…>', 'Post the card in this thread of the chat; pass it when you are working in a thread, it is never inferred')
|
|
214
|
+
.showHelpAfterError(USAGE_HINT)
|
|
215
|
+
.addHelpText('after', EXAMPLES)
|
|
216
|
+
.action(async (opts) => {
|
|
217
|
+
let input;
|
|
218
|
+
try {
|
|
219
|
+
// Everything that can be refused locally is refused before any request.
|
|
220
|
+
input = readInput(opts);
|
|
221
|
+
const arg = templateArg(opts.template);
|
|
222
|
+
const chatId = input.chat ?? stripPrllScheme(resolveRuntimeContext().chatId ?? '');
|
|
223
|
+
if (!chatId) {
|
|
224
|
+
throw new ProposeRefusal('No chat to post the card in.', 'Pass --chat <cht_…>, the chat you are working in.');
|
|
225
|
+
}
|
|
226
|
+
const { client, orgId } = resolveCredentials();
|
|
227
|
+
let templateId;
|
|
228
|
+
let fallbackTitle;
|
|
229
|
+
if ('id' in arg) {
|
|
230
|
+
templateId = arg.id;
|
|
231
|
+
fallbackTitle = input.name ?? templateId;
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
const found = resolveTemplateName(arg.name, await client.listTemplateCatalog(orgId), input);
|
|
235
|
+
templateId = found.template_id;
|
|
236
|
+
fallbackTitle = input.name ?? found.name;
|
|
237
|
+
}
|
|
238
|
+
input = { ...input, template: templateId };
|
|
239
|
+
const payload = {
|
|
240
|
+
reason: input.reason,
|
|
241
|
+
...(input.name ? { team_name: input.name } : {}),
|
|
242
|
+
...(Object.keys(input.params).length > 0 ? { parameter_values: input.params } : {}),
|
|
243
|
+
};
|
|
244
|
+
const result = await client.requestApproval(orgId, {
|
|
245
|
+
action_type: TEMPLATE_TEAM_HIRE_ACTION,
|
|
246
|
+
resource_uri: `prll://${templateId}`,
|
|
247
|
+
chat_id: chatId,
|
|
248
|
+
...(input.threadRootId !== undefined ? { thread_root_id: input.threadRootId } : {}),
|
|
249
|
+
// The server titles the card with the team's name; the endpoint
|
|
250
|
+
// still requires one.
|
|
251
|
+
title: fallbackTitle,
|
|
252
|
+
action_payload: { ...payload },
|
|
253
|
+
});
|
|
254
|
+
printProposed(result, fallbackTitle);
|
|
255
|
+
}
|
|
256
|
+
catch (err) {
|
|
257
|
+
if (err instanceof ProposeRefusal)
|
|
258
|
+
refuse(err, err.nextStep);
|
|
259
|
+
refuse(err, input ? refusalStep(err, input) : undefined);
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Command } from 'commander';
|
|
2
|
+
import type { TemplateCatalogItem } from '@parall/sdk';
|
|
3
|
+
/**
|
|
4
|
+
* One block per template: name — mission, its members with their roles, and
|
|
5
|
+
* the propose command to copy, with only the reason and each required
|
|
6
|
+
* parameter left to fill in. Two templates can share a name; the ID in the
|
|
7
|
+
* command tells them apart.
|
|
8
|
+
*/
|
|
9
|
+
export declare function renderTemplateCatalog(templates: TemplateCatalogItem[]): string;
|
|
10
|
+
export declare function registerTemplateCommands(program: Command): void;
|
|
11
|
+
//# sourceMappingURL=templates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../src/commands/templates.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAWvD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,mBAAmB,EAAE,GAAG,MAAM,CAc9E;AAED,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA+B/D"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { resolveCredentials } from '../lib/client.js';
|
|
2
|
+
import { printError, printProgress } from '../lib/output.js';
|
|
3
|
+
import { proposeCommand, registerTemplateProposeCommand } from './templates-propose.js';
|
|
4
|
+
// `parall templates`: the agent teams this organization can hire, and the
|
|
5
|
+
// card that proposes one to a person (`propose`). Distinct from
|
|
6
|
+
// `parall app templates`, the Mini App template library.
|
|
7
|
+
const oneLine = (text) => text.replace(/\s+/g, ' ').trim();
|
|
8
|
+
/**
|
|
9
|
+
* One block per template: name — mission, its members with their roles, and
|
|
10
|
+
* the propose command to copy, with only the reason and each required
|
|
11
|
+
* parameter left to fill in. Two templates can share a name; the ID in the
|
|
12
|
+
* command tells them apart.
|
|
13
|
+
*/
|
|
14
|
+
export function renderTemplateCatalog(templates) {
|
|
15
|
+
return templates
|
|
16
|
+
.map((t) => {
|
|
17
|
+
const lines = [`${oneLine(t.name)} — ${oneLine(t.mission)}`];
|
|
18
|
+
const members = (t.members ?? []).map((m) => m.role?.trim() ? `${oneLine(m.name)} (${oneLine(m.role)})` : oneLine(m.name));
|
|
19
|
+
if (members.length > 0)
|
|
20
|
+
lines.push(` Members: ${members.join(', ')}`);
|
|
21
|
+
lines.push(` ${proposeCommand({ template: t.template_id, params: {} }, t.required_parameters ?? [])}`);
|
|
22
|
+
return lines.join('\n');
|
|
23
|
+
})
|
|
24
|
+
.join('\n\n');
|
|
25
|
+
}
|
|
26
|
+
export function registerTemplateCommands(program) {
|
|
27
|
+
const templates = program
|
|
28
|
+
.command('templates')
|
|
29
|
+
.description('Agent teams this organization can hire: list them, and propose one to the person you are working with on a card');
|
|
30
|
+
templates
|
|
31
|
+
.command('list')
|
|
32
|
+
.description('The team templates this organization can hire, each with the command that proposes it')
|
|
33
|
+
.addHelpText('after', '\nExample:\n parall templates list')
|
|
34
|
+
.action(async () => {
|
|
35
|
+
try {
|
|
36
|
+
const { client, orgId } = resolveCredentials();
|
|
37
|
+
const catalog = await client.listTemplateCatalog(orgId);
|
|
38
|
+
if (catalog.length === 0) {
|
|
39
|
+
printProgress('No team templates can be hired in this organization yet.');
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
console.log(renderTemplateCatalog(catalog));
|
|
43
|
+
printProgress(`${catalog.length} team template${catalog.length === 1 ? '' : 's'}. Pick the one that fits, replace each <…> in its line (ask the person for values you do not know) and run it; the card goes to the chat you are working in.`);
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
printError(err);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
registerTemplateProposeCommand(templates);
|
|
50
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -26,6 +26,7 @@ import { registerSecretCommands } from './commands/secrets.js';
|
|
|
26
26
|
import { registerSlackCommands } from './commands/slack.js';
|
|
27
27
|
import { registerTaskCommands } from './commands/tasks.js';
|
|
28
28
|
import { registerTeamCommands } from './commands/teams.js';
|
|
29
|
+
import { registerTemplateCommands } from './commands/templates.js';
|
|
29
30
|
import { registerTriggerCommands } from './commands/triggers.js';
|
|
30
31
|
import { registerUserCommands } from './commands/users.js';
|
|
31
32
|
import { registerWatchCommands } from './commands/watch.js';
|
|
@@ -67,6 +68,7 @@ registerProjectCommands(program);
|
|
|
67
68
|
registerProfileCommands(program);
|
|
68
69
|
registerSecretCommands(program);
|
|
69
70
|
registerTeamCommands(program);
|
|
71
|
+
registerTemplateCommands(program);
|
|
70
72
|
registerScheduleCommands(program);
|
|
71
73
|
registerTriggerCommands(program);
|
|
72
74
|
registerUserCommands(program);
|
package/dist/lib/output.d.ts
CHANGED
|
@@ -27,6 +27,8 @@ export declare function printRefHint(entityId: string, action?: string): void;
|
|
|
27
27
|
* Strip the `prll://` scheme prefix from an entity ID if present.
|
|
28
28
|
* Allows CLI commands to accept both raw IDs (`tsk_abc`) and URIs (`prll://tsk_abc`).
|
|
29
29
|
*/
|
|
30
|
+
/** One shell word holding `value` exactly, for a command an agent copies. */
|
|
31
|
+
export declare function shellQuote(value: string): string;
|
|
30
32
|
export declare function stripPrllScheme(idOrUri: string): string;
|
|
31
33
|
/**
|
|
32
34
|
* Ensure a value carries the `prll://` scheme — the inverse of stripPrllScheme.
|
package/dist/lib/output.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/lib/output.ts"],"names":[],"mappings":"AAGA,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAE7C;AAID;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAoB3C;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAEhD;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,SAAY,GAAG,IAAI,CAEvE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAExD;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAW5E;AAmBD;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAe1E;AAaD;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAWvE;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,WAAW,EAAE,MAAM,GAAG,SAAS,GAC9B,MAAM,GAAG,SAAS,CAYpB;AASD;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAO1D,CAAC;AAEF;2CAC2C;AAC3C,wBAAgB,UAAU,CACxB,GAAG,EAAE,OAAO,EACZ,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC1C,QAAQ,CAAC,EAAE,MAAM,GAChB,KAAK,CAqEP"}
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/lib/output.ts"],"names":[],"mappings":"AAGA,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAE7C;AAID;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAoB3C;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAEhD;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,SAAY,GAAG,IAAI,CAEvE;AAED;;;GAGG;AACH,6EAA6E;AAC7E,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAExD;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAW5E;AAmBD;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAe1E;AAaD;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAWvE;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,WAAW,EAAE,MAAM,GAAG,SAAS,GAC9B,MAAM,GAAG,SAAS,CAYpB;AASD;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAO1D,CAAC;AAEF;2CAC2C;AAC3C,wBAAgB,UAAU,CACxB,GAAG,EAAE,OAAO,EACZ,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC1C,QAAQ,CAAC,EAAE,MAAM,GAChB,KAAK,CAqEP"}
|
package/dist/lib/output.js
CHANGED
|
@@ -58,6 +58,10 @@ export function printRefHint(entityId, action = 'Created') {
|
|
|
58
58
|
* Strip the `prll://` scheme prefix from an entity ID if present.
|
|
59
59
|
* Allows CLI commands to accept both raw IDs (`tsk_abc`) and URIs (`prll://tsk_abc`).
|
|
60
60
|
*/
|
|
61
|
+
/** One shell word holding `value` exactly, for a command an agent copies. */
|
|
62
|
+
export function shellQuote(value) {
|
|
63
|
+
return `'${value.replaceAll("'", `'\\''`)}'`;
|
|
64
|
+
}
|
|
61
65
|
export function stripPrllScheme(idOrUri) {
|
|
62
66
|
return idOrUri.startsWith('prll://') ? idOrUri.slice(7) : idOrUri;
|
|
63
67
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parall/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.93.0",
|
|
4
4
|
"description": "CLI client for Parall — universal agent & human access to Parall API",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"node-diff3": "3.2.1",
|
|
43
43
|
"tar-stream": "^3.2.1",
|
|
44
44
|
"zod": "^4.3.6",
|
|
45
|
-
"@parall/
|
|
46
|
-
"@parall/
|
|
45
|
+
"@parall/sdk": "1.93.0",
|
|
46
|
+
"@parall/agent-core": "1.93.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@dnd-kit/core": "6.3.1",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"tw-animate-css": "1.4.0",
|
|
72
72
|
"typescript": "^5.7.0",
|
|
73
73
|
"vite": "6.4.1",
|
|
74
|
-
"@parall/agent-core": "1.
|
|
74
|
+
"@parall/agent-core": "1.93.0"
|
|
75
75
|
},
|
|
76
76
|
"scripts": {
|
|
77
77
|
"build": "node scripts/generate-miniapp-sdk.mjs --check && node scripts/generate-local-runner.mjs --check && node scripts/generate-app-templates.mjs --check && tsc",
|