@ekanos/cli 0.12.0 → 0.14.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/README.md +25 -8
- package/dist/agents-api.d.ts +11 -2
- package/dist/agents-api.js +39 -3
- package/dist/agents-api.js.map +1 -1
- package/dist/apps-api.d.ts +3 -2
- package/dist/apps-api.js +3 -7
- package/dist/apps-api.js.map +1 -1
- package/dist/auth/ekanos-api.d.ts +16 -2
- package/dist/auth/ekanos-api.js +101 -15
- package/dist/auth/ekanos-api.js.map +1 -1
- package/dist/auth/host-trust.d.ts +46 -0
- package/dist/auth/host-trust.js +79 -0
- package/dist/auth/host-trust.js.map +1 -0
- package/dist/auth/session.d.ts +10 -1
- package/dist/auth/session.js +28 -28
- package/dist/auth/session.js.map +1 -1
- package/dist/commands/agents-edit.d.ts +6 -2
- package/dist/commands/agents-edit.js +57 -26
- package/dist/commands/agents-edit.js.map +1 -1
- package/dist/commands/agents.d.ts +13 -2
- package/dist/commands/agents.js +148 -36
- package/dist/commands/agents.js.map +1 -1
- package/dist/commands/apps.d.ts +15 -4
- package/dist/commands/apps.js +133 -51
- package/dist/commands/apps.js.map +1 -1
- package/dist/commands/catalog.js +7 -6
- package/dist/commands/catalog.js.map +1 -1
- package/dist/commands/knowledge.d.ts +56 -0
- package/dist/commands/knowledge.js +456 -0
- package/dist/commands/knowledge.js.map +1 -0
- package/dist/commands/login.d.ts +4 -0
- package/dist/commands/login.js +30 -2
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/logout.d.ts +9 -1
- package/dist/commands/logout.js +56 -7
- package/dist/commands/logout.js.map +1 -1
- package/dist/commands/publish.js +3 -3
- package/dist/commands/publish.js.map +1 -1
- package/dist/commands/reviewers.d.ts +2 -0
- package/dist/commands/reviewers.js +7 -3
- package/dist/commands/reviewers.js.map +1 -1
- package/dist/commands/routes.d.ts +2 -0
- package/dist/commands/routes.js +42 -9
- package/dist/commands/routes.js.map +1 -1
- package/dist/commands/runs.d.ts +13 -2
- package/dist/commands/runs.js +96 -15
- package/dist/commands/runs.js.map +1 -1
- package/dist/commands/scope-notice.d.ts +21 -0
- package/dist/commands/scope-notice.js +35 -0
- package/dist/commands/scope-notice.js.map +1 -0
- package/dist/commands/skills.d.ts +7 -1
- package/dist/commands/skills.js +80 -24
- package/dist/commands/skills.js.map +1 -1
- package/dist/commands/sources.d.ts +4 -0
- package/dist/commands/sources.js +233 -5
- package/dist/commands/sources.js.map +1 -1
- package/dist/commands/status.js +5 -4
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/team-agent-readiness.d.ts +59 -0
- package/dist/commands/team-agent-readiness.js +341 -0
- package/dist/commands/team-agent-readiness.js.map +1 -0
- package/dist/commands/team-agents-agents.d.ts +24 -3
- package/dist/commands/team-agents-agents.js +336 -35
- package/dist/commands/team-agents-agents.js.map +1 -1
- package/dist/commands/team-agents-mcp.js +32 -3
- package/dist/commands/team-agents-mcp.js.map +1 -1
- package/dist/commands/team-agents-triggers.js +230 -54
- package/dist/commands/team-agents-triggers.js.map +1 -1
- package/dist/commands/team-agents.d.ts +3 -1
- package/dist/commands/team-agents.js +27 -7
- package/dist/commands/team-agents.js.map +1 -1
- package/dist/commands/teams-channel-install.d.ts +24 -0
- package/dist/commands/teams-channel-install.js +94 -0
- package/dist/commands/teams-channel-install.js.map +1 -0
- package/dist/commands/teams-connect.d.ts +66 -0
- package/dist/commands/teams-connect.js +397 -0
- package/dist/commands/teams-connect.js.map +1 -0
- package/dist/commands/teams-events.d.ts +12 -0
- package/dist/commands/teams-events.js +138 -0
- package/dist/commands/teams-events.js.map +1 -0
- package/dist/commands/teams-onboard.d.ts +16 -5
- package/dist/commands/teams-onboard.js +61 -36
- package/dist/commands/teams-onboard.js.map +1 -1
- package/dist/commands/teams-overview.d.ts +11 -0
- package/dist/commands/teams-overview.js +160 -0
- package/dist/commands/teams-overview.js.map +1 -0
- package/dist/commands/teams-scope.d.ts +10 -0
- package/dist/commands/teams-scope.js +109 -0
- package/dist/commands/teams-scope.js.map +1 -0
- package/dist/commands/teams.d.ts +64 -7
- package/dist/commands/teams.js +254 -60
- package/dist/commands/teams.js.map +1 -1
- package/dist/commands/upgrade.js +12 -2
- package/dist/commands/upgrade.js.map +1 -1
- package/dist/commands/use.js +2 -2
- package/dist/commands/use.js.map +1 -1
- package/dist/commands/whoami.js +1 -1
- package/dist/commands/whoami.js.map +1 -1
- package/dist/connections-api.js +1 -1
- package/dist/connections-api.js.map +1 -1
- package/dist/delegate.js +11 -4
- package/dist/delegate.js.map +1 -1
- package/dist/harness-scaffold.js +12 -0
- package/dist/harness-scaffold.js.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.js +724 -152
- package/dist/index.js.map +1 -1
- package/dist/knowledge-api.d.ts +175 -0
- package/dist/knowledge-api.js +169 -0
- package/dist/knowledge-api.js.map +1 -0
- package/dist/open-url.d.ts +16 -0
- package/dist/open-url.js +73 -0
- package/dist/open-url.js.map +1 -0
- package/dist/parse-argv.d.ts +2 -0
- package/dist/parse-argv.js.map +1 -1
- package/dist/publish-api.d.ts +2 -1
- package/dist/publish-api.js +4 -3
- package/dist/publish-api.js.map +1 -1
- package/dist/pull-write.d.ts +27 -0
- package/dist/pull-write.js +60 -0
- package/dist/pull-write.js.map +1 -0
- package/dist/routes-api.d.ts +3 -0
- package/dist/routes-api.js +9 -4
- package/dist/routes-api.js.map +1 -1
- package/dist/runs-api.d.ts +7 -1
- package/dist/runs-api.js +21 -6
- package/dist/runs-api.js.map +1 -1
- package/dist/safe-fs.d.ts +2 -0
- package/dist/safe-fs.js +12 -6
- package/dist/safe-fs.js.map +1 -1
- package/dist/secret-file.d.ts +17 -0
- package/dist/secret-file.js +69 -0
- package/dist/secret-file.js.map +1 -0
- package/dist/skills-api.d.ts +10 -2
- package/dist/skills-api.js +37 -2
- package/dist/skills-api.js.map +1 -1
- package/dist/source-products-api.d.ts +63 -0
- package/dist/source-products-api.js +123 -0
- package/dist/source-products-api.js.map +1 -0
- package/dist/source-target.js +2 -1
- package/dist/source-target.js.map +1 -1
- package/dist/sources-api.d.ts +2 -1
- package/dist/sources-api.js +3 -2
- package/dist/sources-api.js.map +1 -1
- package/dist/team-connect-api.d.ts +286 -0
- package/dist/team-connect-api.js +107 -0
- package/dist/team-connect-api.js.map +1 -0
- package/dist/teams-api.d.ts +42 -1
- package/dist/teams-api.js +98 -20
- package/dist/teams-api.js.map +1 -1
- package/dist/toolchain-api.d.ts +9 -0
- package/dist/toolchain-api.js +17 -2
- package/dist/toolchain-api.js.map +1 -1
- package/dist/toolchain-resolve.d.ts +3 -0
- package/dist/toolchain-resolve.js +15 -1
- package/dist/toolchain-resolve.js.map +1 -1
- package/dist/toolchain.d.ts +6 -0
- package/dist/toolchain.js +19 -0
- package/dist/toolchain.js.map +1 -1
- package/dist/update-notice.js +2 -1
- package/dist/update-notice.js.map +1 -1
- package/package.json +2 -2
- package/templates/AGENTS.md.tmpl +6 -1
- package/templates/claude-skill.md.tmpl +5 -0
- package/templates/package.json.tmpl +4 -4
- package/templates/skills/build-agent/SKILL.md +115 -16
- package/templates/skills/build-agent/references/agent-json.md +26 -8
- package/templates/skills/build-agent/references/app-setup.md +2 -1
- package/templates/skills/build-agent/references/rollout.md +27 -4
- package/templates/skills/build-agent/references/set-up-an-integration.md +74 -15
- package/templates/skills/build-agent/references/skills.md +20 -1
- package/templates/skills/build-agent/references/triggers.md +84 -20
- package/templates/skills/build-integration/references/widget-design.md +3 -3
- package/templates/skills/ekanos-platform/SKILL.md +70 -17
- package/templates/skills/polish-widgets/references/patterns.md +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"team-agents.js","sourceRoot":"","sources":["../../src/commands/team-agents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAEzE,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,kB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b,CAAC;QAChc,KAAK,UAAU;YACb,OAAO,oNAAoN,CAAC;QAC9N,KAAK,OAAO;YACV,OAAO,gPAAgP,CAAC;QAC1P,KAAK,KAAK;YACR,OAAO,sSAAsS,CAAC;IAClT,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,SAAS,YAAY,CACnB,QAA2B,EAC3B,IAA6C;;IAE7C,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,QAAQ,CAAC;IACxC,MAAM,IAAI,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACvE,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,UAAU,CAAC,2BAA2B,EAAE,oBAAoB,CAAC,CAAC;IACtE,CAAC;IACD,OAAO,CAAA,MAAA,QAAQ,CAAC,CAAC,CAAC,0CAAE,IAAI,GAAG,WAAW,EAAE,MAAK,IAAI;QAC/C,CAAC,CAAC,QAAQ;QACV,CAAC,CAAC,CAAC,IAAI,EAAE,GAAG,QAAQ,CAAC,CAAC;AAC1B,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,cAAc,CAC5B,KAAyB,EACzB,IAAY,EACZ,IAAmB;IAEnB,MAAM,IAAI,GAAG,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,GAAG,WAAW,EAAE,CAAC;IACzC,IAAI,IAAI,IAAI,sBAAsB,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAC3D,MAAM,UAAU,CACd,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,cAAc,IAAI,GAAG,CAAC,CAAC,CAAC,YAAY,IAAI,GAAG,EAC5D,QAAQ,CAAC,IAAI,CAAC,CACf,CAAC;AACJ,CAAC","sourcesContent":["import { requireSession, resolveAuthEnvironment } from '../auth/session';\nimport type { CliContext } from '../context';\nimport { usageError } from '../errors';\nimport type { ExitCode } from '../exit-codes';\nimport { resolveSourceTarget } from '../source-target';\nimport { runTeamAgentsArea } from './team-agents-agents';\nimport { runTeamMcp } from './team-agents-mcp';\nimport { runTeamLinks, runTeamTriggers } from './team-agents-triggers';\nimport { TeamsClient, type TeamsArgs } from './teams';\n\n/**\n * `ekanos teams agents|triggers|links|mcp …` — a Source admin setting up a\n * team's agents from the terminal, acting on that team through the partner\n * API (`/api/partner/teams/<team>/agents/*`, `/mcp/*`). Every write goes\n * through the same checks the app's agent pages make and leaves an Admin\n * Audit row naming the person.\n *\n * The shape is always `teams <area> <verb> <team> [<agent-key> …]`; the\n * team may also be named with `--team <slug>`, as `runs`, `approvals`,\n * `skills` and `knowledge` name it.\n */\n\nexport const TEAM_AGENT_AREAS = ['agents', 'triggers', 'links', 'mcp'] as const;\nexport type TeamAgentArea = (typeof TEAM_AGENT_AREAS)[number];\n\nexport function isTeamAgentArea(\n value: string | undefined,\n): value is TeamAgentArea {\n return TEAM_AGENT_AREAS.some((area) => area === value);\n}\n\n/** What every area handler gets: an authorized client and its operands. */\nexport interface TeamAgentRun {\n args: TeamsArgs;\n client: TeamsClient;\n host: string;\n /** The Source slug, for `?source=`. */\n source: string;\n /** The verb. */\n verb: string;\n /** Everything after the verb: `<team> [<key> …]`. */\n operands: readonly string[];\n}\n\nexport async function runTeamAgentCommands(\n ctx: CliContext,\n args: TeamsArgs,\n): Promise<ExitCode> {\n const [area, verb, ...positional] = args.positionals;\n if (!isTeamAgentArea(area)) {\n throw usageError(\n `Unknown teams area \"${area ?? ''}\".`,\n 'See \"ekanos teams --help\".',\n );\n }\n if (!verb) {\n throw usageError(`teams ${area} needs a subcommand.`, usageFor(area));\n }\n const operands = withTeamFlag(positional, args.flags?.team);\n\n const env = resolveAuthEnvironment(ctx, args.host, args.env, {\n projectDir: args.dir,\n });\n const resolved = await resolveSourceTarget(env, requireSession(env), args);\n const run: TeamAgentRun = {\n args,\n client: new TeamsClient(env, resolved.session),\n host: env.host,\n source: resolved.source,\n verb,\n operands,\n };\n\n switch (area) {\n case 'agents':\n return runTeamAgentsArea(ctx, run);\n case 'triggers':\n return runTeamTriggers(ctx, run);\n case 'links':\n return runTeamLinks(ctx, run);\n case 'mcp':\n return runTeamMcp(ctx, run);\n }\n}\n\nexport function usageFor(area: TeamAgentArea): string {\n switch (area) {\n case 'agents':\n return 'Run one of: ekanos teams agents list <team> | show <team> <key> | enable <team> <key> [--as <member-email>] [--draft] [--confirm-access] | confirm <team> <key> | disable <team> <key> --yes | pin <team> <key> <version> | pin <team> <key> --draft | unpin <team> <key> | policy <team> <key> [set <tool> auto|approve | unset <tool> | --reads auto|approve --writes auto|approve] [--confirm-access] | skills <team> <key> [add|remove <skill>].';\n case 'triggers':\n return 'Run one of: ekanos teams triggers list <team> <key> | add <team> <key> <manual|schedule|webhook|event|slack|linear> … | remove <team> <key> <trigger-id|key> --yes | rotate <team> <key> <trigger-key|id> [--yes].';\n case 'links':\n return 'Run one of: ekanos teams links list <team> <key> | add <team> <from-key> <to-key> --kind talk|delegate [--mode await|handoff] | remove <team> <from-key> <link-id|to-key> [--kind talk|delegate] --yes. The team may be --team <slug> instead.';\n case 'mcp':\n return 'Run one of: ekanos teams mcp list <team> | add <team> <server-key> --url <url> [--auth none|token|oauth] [--name <name>] | status <team> <server-key> | token <team> <server-key> (hidden input at your terminal) | effect <team> <server-key> <tool> read|write | remove <team> <server-key> --yes.';\n }\n}\n\n/**\n * `--team <slug>` in place of the leading team operand. Given both, they\n * must agree; given only the flag, it becomes the first operand.\n */\nfunction withTeamFlag(\n operands: readonly string[],\n flag: string | boolean | string[] | undefined,\n): readonly string[] {\n if (flag === undefined) return operands;\n const team = typeof flag === 'string' ? flag.trim().toLowerCase() : '';\n if (!team) {\n throw usageError('--team needs a team slug.', 'e.g. --team bank-a');\n }\n return operands[0]?.trim().toLowerCase() === team\n ? operands\n : [team, ...operands];\n}\n\n/** A slug operand (team, agent key, server key), or a usage error naming it. */\nexport function requireOperand(\n value: string | undefined,\n what: string,\n area: TeamAgentArea,\n): string {\n const slug = value?.trim().toLowerCase();\n if (slug && /^[a-z0-9][a-z0-9-]*$/.test(slug)) return slug;\n throw usageError(\n value ? `\"${value}\" is not a ${what}.` : `Name the ${what}.`,\n usageFor(area),\n );\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type TeamChannel } from '@ekanos/integration-schema';
|
|
2
|
+
import type { CliContext } from '../context.js';
|
|
3
|
+
import type { ExitCode } from '../exit-codes.js';
|
|
4
|
+
import type { TeamsArgs, TeamsClient } from './teams.js';
|
|
5
|
+
/**
|
|
6
|
+
* `teams connect <team> slack|linear-app` — install, for one team, the
|
|
7
|
+
* channel a `slack` or `linear` agent trigger answers through: Slack, or
|
|
8
|
+
* Ekanos's own Linear Agents app (not the team's own Linear app, which is
|
|
9
|
+
* `teams connect <team> linear --connection agent`).
|
|
10
|
+
*
|
|
11
|
+
* The same open-the-link-and-wait as `teams connect`'s sign-in: the host
|
|
12
|
+
* mints a one-time link for the team member who installs it (the caller when
|
|
13
|
+
* a member, else `--as`), the CLI opens it for the caller, prints it always,
|
|
14
|
+
* and polls until it is installed. Only that member, signed in to the app,
|
|
15
|
+
* can finish it.
|
|
16
|
+
*/
|
|
17
|
+
export declare function isTeamChannel(value: string): value is TeamChannel;
|
|
18
|
+
export declare function runTeamChannelInstall(ctx: CliContext, args: TeamsArgs, client: TeamsClient, host: string, source: string, input: {
|
|
19
|
+
team: string;
|
|
20
|
+
channel: TeamChannel;
|
|
21
|
+
as?: string;
|
|
22
|
+
/** Opens the link in the caller's browser (`teams connect`'s opener). */
|
|
23
|
+
open: (url: string) => void;
|
|
24
|
+
}): Promise<ExitCode>;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { TeamChannelInstallStartSchema, TeamChannelInstallStatusSchema, TeamChannelSchema, } from '@ekanos/integration-schema';
|
|
2
|
+
import { invalidStateError, validationError } from '../errors.js';
|
|
3
|
+
import { assertBrowserSafeUrl } from '../open-url.js';
|
|
4
|
+
import { call } from '../teams-api.js';
|
|
5
|
+
/**
|
|
6
|
+
* `teams connect <team> slack|linear-app` — install, for one team, the
|
|
7
|
+
* channel a `slack` or `linear` agent trigger answers through: Slack, or
|
|
8
|
+
* Ekanos's own Linear Agents app (not the team's own Linear app, which is
|
|
9
|
+
* `teams connect <team> linear --connection agent`).
|
|
10
|
+
*
|
|
11
|
+
* The same open-the-link-and-wait as `teams connect`'s sign-in: the host
|
|
12
|
+
* mints a one-time link for the team member who installs it (the caller when
|
|
13
|
+
* a member, else `--as`), the CLI opens it for the caller, prints it always,
|
|
14
|
+
* and polls until it is installed. Only that member, signed in to the app,
|
|
15
|
+
* can finish it.
|
|
16
|
+
*/
|
|
17
|
+
export function isTeamChannel(value) {
|
|
18
|
+
return TeamChannelSchema.safeParse(value).success;
|
|
19
|
+
}
|
|
20
|
+
export async function runTeamChannelInstall(ctx, args, client, host, source, input) {
|
|
21
|
+
var _a, _b, _c, _d;
|
|
22
|
+
const path = `/api/partner/teams/${encodeURIComponent(input.team)}/channels/${input.channel}`;
|
|
23
|
+
const read = () => client.call((token) => call(host, token, TeamChannelInstallStatusSchema, {
|
|
24
|
+
method: 'GET',
|
|
25
|
+
path,
|
|
26
|
+
source,
|
|
27
|
+
}));
|
|
28
|
+
const status = await read();
|
|
29
|
+
if (status.installed) {
|
|
30
|
+
return ctx.succeed(Object.assign({ host }, status), ctx.ui.result({
|
|
31
|
+
title: `${status.team.slug} has installed ${status.name}`,
|
|
32
|
+
rows: [['Workspace', (_a = status.workspace) !== null && _a !== void 0 ? _a : 'installed']],
|
|
33
|
+
notes: [triggerHint(status.team.slug, input.channel)],
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
if (status.problem) {
|
|
37
|
+
throw invalidStateError(`${status.problem}.`, input.channel === 'slack'
|
|
38
|
+
? `"ekanos sources products --source ${source}" shows whether Slack is enabled; a super-admin enables it.`
|
|
39
|
+
: 'Ekanos sets the Linear Agents app up for a host; ask Ekanos.');
|
|
40
|
+
}
|
|
41
|
+
const started = await client.call((token) => call(host, token, TeamChannelInstallStartSchema, {
|
|
42
|
+
method: 'POST',
|
|
43
|
+
path: `${path}/install`,
|
|
44
|
+
source,
|
|
45
|
+
body: input.as ? { as: input.as } : {},
|
|
46
|
+
}));
|
|
47
|
+
assertBrowserSafeUrl(started.authorizeUrl, 'install link');
|
|
48
|
+
const { member } = started;
|
|
49
|
+
const expires = started.expiresAt.replace('T', ' ').slice(0, 16);
|
|
50
|
+
const consent = input.channel === 'slack'
|
|
51
|
+
? 'pick the Slack workspace and approve'
|
|
52
|
+
: 'approve it as an admin of the Linear workspace it goes into';
|
|
53
|
+
ctx.log(member.isCaller
|
|
54
|
+
? [
|
|
55
|
+
`Install ${status.name} for ${status.team.slug} — sign in to the app as yourself if asked, then ${consent}:`,
|
|
56
|
+
` ${started.authorizeUrl}`,
|
|
57
|
+
` (one-time link, valid until ${expires} UTC)`,
|
|
58
|
+
].join('\n')
|
|
59
|
+
: [
|
|
60
|
+
`Send this link to ${(_b = member.email) !== null && _b !== void 0 ? _b : 'the member'} — they install ${status.name} for ${status.team.slug}, signed in to the app as themselves (${consent}):`,
|
|
61
|
+
` ${started.authorizeUrl}`,
|
|
62
|
+
` (one-time, for them only, valid until ${expires} UTC)`,
|
|
63
|
+
].join('\n'));
|
|
64
|
+
// Only ever the caller's own browser: the link is bound to its member.
|
|
65
|
+
if (member.isCaller && !args.noOpen && !ctx.jsonMode) {
|
|
66
|
+
input.open(started.authorizeUrl);
|
|
67
|
+
}
|
|
68
|
+
if (args.noWait || ctx.jsonMode) {
|
|
69
|
+
return ctx.succeed(Object.assign(Object.assign({ host }, started.status), { authorizeUrl: started.authorizeUrl, expiresAt: started.expiresAt, member }), ctx.ui.hint(`Then check with "ekanos teams connect ${input.team} ${input.channel}".`));
|
|
70
|
+
}
|
|
71
|
+
ctx.log('Waiting for the install to finish (Ctrl-C stops waiting; the link stays valid)…');
|
|
72
|
+
const deadline = Date.parse(started.expiresAt) || Date.now() + 10 * 60 * 1000;
|
|
73
|
+
while (Date.now() < deadline) {
|
|
74
|
+
await new Promise((resolve) => { var _a; return setTimeout(resolve, (_a = args.pollDelayMs) !== null && _a !== void 0 ? _a : 3000); });
|
|
75
|
+
const polled = await read();
|
|
76
|
+
if (polled.installed) {
|
|
77
|
+
return ctx.succeed(Object.assign({ host }, polled), ctx.ui.result({
|
|
78
|
+
title: `Installed ${polled.name} for ${polled.team.slug}`,
|
|
79
|
+
rows: [
|
|
80
|
+
['Workspace', (_c = polled.workspace) !== null && _c !== void 0 ? _c : 'installed'],
|
|
81
|
+
['Installed by', (_d = member.email) !== null && _d !== void 0 ? _d : 'the member'],
|
|
82
|
+
],
|
|
83
|
+
notes: [triggerHint(polled.team.slug, input.channel)],
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
throw validationError('The install did not finish before the link expired.', `Run "ekanos teams connect ${input.team} ${input.channel}${input.as ? ` --as ${input.as}` : ''}" again for a fresh link.`);
|
|
88
|
+
}
|
|
89
|
+
function triggerHint(team, channel) {
|
|
90
|
+
return channel === 'slack'
|
|
91
|
+
? `Next: an agent answers there once it has a slack trigger — "ekanos teams triggers add ${team} <agent-key> slack --channel '#<channel>' --yes" (invite the bot to the channel first).`
|
|
92
|
+
: `Next: an agent answers @mentions there once it has a linear trigger — "ekanos teams triggers add ${team} <agent-key> linear".`;
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=teams-channel-install.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"teams-channel-install.js","sourceRoot":"","sources":["../../src/commands/teams-channel-install.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,6BAA6B,EAC7B,8BAA8B,EAC9B,iBAAiB,GAClB,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;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KAAK,EAAE,aAAa,MAAM,CAAC,IAAI,QAAQ,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE;gBACzD,IAAI,EAAE;oBACJ,CAAC,WAAW,QAAE,MAAM,CAAC,SAAS,mCAAI,WAAW,CAAC;oBAC9C,CAAC,cAAc,QAAE,MAAM,CAAC,KAAK,mCAAI,YAAY,CAAC;iBAC/C;gBACD,KAAK,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;aACtD,CAAC,CACH,CAAC;QACJ,CAAC;IACH,CAAC;IACD,MAAM,eAAe,CACnB,qDAAqD,EACrD,6BAA6B,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,OAAO,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,2BAA2B,CAC1H,CAAC;AACJ,CAAC;AAED,SAAS,WAAW,CAAC,IAAY,EAAE,OAAoB;IACrD,OAAO,OAAO,KAAK,OAAO;QACxB,CAAC,CAAC,yFAAyF,IAAI,yFAAyF;QACxL,CAAC,CAAC,oGAAoG,IAAI,uBAAuB,CAAC;AACtI,CAAC","sourcesContent":["import {\n type TeamChannel,\n TeamChannelInstallStartSchema,\n TeamChannelInstallStatusSchema,\n TeamChannelSchema,\n} from '@ekanos/integration-schema';\n\nimport type { CliContext } from '../context';\nimport { invalidStateError, validationError } from '../errors';\nimport type { ExitCode } from '../exit-codes';\nimport { assertBrowserSafeUrl } from '../open-url';\nimport { call } from '../teams-api';\nimport type { TeamsArgs, TeamsClient } from './teams';\n\n/**\n * `teams connect <team> slack|linear-app` — install, for one team, the\n * channel a `slack` or `linear` agent trigger answers through: Slack, or\n * Ekanos's own Linear Agents app (not the team's own Linear app, which is\n * `teams connect <team> linear --connection agent`).\n *\n * The same open-the-link-and-wait as `teams connect`'s sign-in: the host\n * mints a one-time link for the team member who installs it (the caller when\n * a member, else `--as`), the CLI opens it for the caller, prints it always,\n * and polls until it is installed. Only that member, signed in to the app,\n * can finish it.\n */\n\nexport function isTeamChannel(value: string): value is TeamChannel {\n return TeamChannelSchema.safeParse(value).success;\n}\n\nexport async function runTeamChannelInstall(\n ctx: CliContext,\n args: TeamsArgs,\n client: TeamsClient,\n host: string,\n source: string,\n input: {\n team: string;\n channel: TeamChannel;\n as?: string;\n /** Opens the link in the caller's browser (`teams connect`'s opener). */\n open: (url: string) => void;\n },\n): Promise<ExitCode> {\n const path = `/api/partner/teams/${encodeURIComponent(input.team)}/channels/${input.channel}`;\n const read = () =>\n client.call((token) =>\n call(host, token, TeamChannelInstallStatusSchema, {\n method: 'GET',\n path,\n source,\n }),\n );\n\n const status = await read();\n if (status.installed) {\n return ctx.succeed(\n { host, ...status },\n ctx.ui.result({\n title: `${status.team.slug} has installed ${status.name}`,\n rows: [['Workspace', status.workspace ?? 'installed']],\n notes: [triggerHint(status.team.slug, input.channel)],\n }),\n );\n }\n if (status.problem) {\n throw invalidStateError(\n `${status.problem}.`,\n input.channel === 'slack'\n ? `\"ekanos sources products --source ${source}\" shows whether Slack is enabled; a super-admin enables it.`\n : 'Ekanos sets the Linear Agents app up for a host; ask Ekanos.',\n );\n }\n\n const started = await client.call((token) =>\n call(host, token, TeamChannelInstallStartSchema, {\n method: 'POST',\n path: `${path}/install`,\n source,\n body: input.as ? { as: input.as } : {},\n }),\n );\n assertBrowserSafeUrl(started.authorizeUrl, 'install link');\n const { member } = started;\n const expires = started.expiresAt.replace('T', ' ').slice(0, 16);\n const consent =\n input.channel === 'slack'\n ? 'pick the Slack workspace and approve'\n : 'approve it as an admin of the Linear workspace it goes into';\n ctx.log(\n member.isCaller\n ? [\n `Install ${status.name} for ${status.team.slug} — sign in to the app as yourself if asked, then ${consent}:`,\n ` ${started.authorizeUrl}`,\n ` (one-time link, valid until ${expires} UTC)`,\n ].join('\\n')\n : [\n `Send this link to ${member.email ?? 'the member'} — they install ${status.name} for ${status.team.slug}, signed in to the app as themselves (${consent}):`,\n ` ${started.authorizeUrl}`,\n ` (one-time, for them only, valid until ${expires} UTC)`,\n ].join('\\n'),\n );\n\n // Only ever the caller's own browser: the link is bound to its member.\n if (member.isCaller && !args.noOpen && !ctx.jsonMode) {\n input.open(started.authorizeUrl);\n }\n\n if (args.noWait || ctx.jsonMode) {\n return ctx.succeed(\n {\n host,\n ...started.status,\n authorizeUrl: started.authorizeUrl,\n expiresAt: started.expiresAt,\n member,\n },\n ctx.ui.hint(\n `Then check with \"ekanos teams connect ${input.team} ${input.channel}\".`,\n ),\n );\n }\n\n ctx.log(\n 'Waiting for the install to finish (Ctrl-C stops waiting; the link stays valid)…',\n );\n const deadline = Date.parse(started.expiresAt) || Date.now() + 10 * 60 * 1000;\n while (Date.now() < deadline) {\n await new Promise((resolve) =>\n setTimeout(resolve, args.pollDelayMs ?? 3000),\n );\n const polled = await read();\n if (polled.installed) {\n return ctx.succeed(\n { host, ...polled },\n ctx.ui.result({\n title: `Installed ${polled.name} for ${polled.team.slug}`,\n rows: [\n ['Workspace', polled.workspace ?? 'installed'],\n ['Installed by', member.email ?? 'the member'],\n ],\n notes: [triggerHint(polled.team.slug, input.channel)],\n }),\n );\n }\n }\n throw validationError(\n 'The install did not finish before the link expired.',\n `Run \"ekanos teams connect ${input.team} ${input.channel}${input.as ? ` --as ${input.as}` : ''}\" again for a fresh link.`,\n );\n}\n\nfunction triggerHint(team: string, channel: TeamChannel): string {\n return channel === 'slack'\n ? `Next: an agent answers there once it has a slack trigger — \"ekanos teams triggers add ${team} <agent-key> slack --channel '#<channel>' --yes\" (invite the bot to the channel first).`\n : `Next: an agent answers @mentions there once it has a linear trigger — \"ekanos teams triggers add ${team} <agent-key> linear\".`;\n}\n"]}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { type TeamIntegrationStatus } from '@ekanos/integration-schema';
|
|
2
|
+
import type { CliContext } from '../context.js';
|
|
3
|
+
import type { ExitCode } from '../exit-codes.js';
|
|
4
|
+
import { type TeamsArgs, type TeamsClient } from './teams.js';
|
|
5
|
+
/**
|
|
6
|
+
* `teams connect <team> <product>` — connect a product for one team, doing
|
|
7
|
+
* whichever the integration needs (the host's plan decides, never the CLI):
|
|
8
|
+
*
|
|
9
|
+
* - works as shipped → says so; not self-serve or not enabled → refuses
|
|
10
|
+
* with the reason (and points at `sources products` for the latter);
|
|
11
|
+
* - form fields → asks them here (secrets hidden, never as arguments) and
|
|
12
|
+
* activates exactly as the app's form does;
|
|
13
|
+
* - OAuth → runs `teams app set` inline when the team's own app is needed
|
|
14
|
+
* first (Zendesk), then a one-time sign-in link for the member who
|
|
15
|
+
* consents: the caller when a member, else `--as <email>`. Opens it for
|
|
16
|
+
* the caller (unless `--no-open`), always prints it, and waits until the
|
|
17
|
+
* team is connected (unless `--no-wait`);
|
|
18
|
+
* - a form only the browser can fill → prints the team's page.
|
|
19
|
+
*
|
|
20
|
+
* `--connection <id>` connects one of the integration's named connections
|
|
21
|
+
* instead of the main one — Linear's `agent`, the team's own Linear app
|
|
22
|
+
* installed as a workspace member, which is what makes Linear send the
|
|
23
|
+
* @mention and assignment webhooks an agent's triggers listen for. It runs
|
|
24
|
+
* the same way: the team app's fields when missing, then the sign-in, then
|
|
25
|
+
* the wait until it is installed.
|
|
26
|
+
*
|
|
27
|
+
* Without `--connection`, once the main connection is made (or already
|
|
28
|
+
* was), a named connection the team's agents' triggers wait on is offered
|
|
29
|
+
* next — at a terminal it asks and installs it, otherwise it names the
|
|
30
|
+
* command. "Connected" is not the goal; an agent that can be reached is.
|
|
31
|
+
*
|
|
32
|
+
* `--reconnect` connects it again even though it reads as connected — for
|
|
33
|
+
* a revoked or expired sign-in, or new form values. An OAuth reconnect
|
|
34
|
+
* prints the link and returns: the team already reads as connected, so
|
|
35
|
+
* there is nothing to wait for.
|
|
36
|
+
*
|
|
37
|
+
* `--link-only` keeps the old behaviour: the team's page and its status.
|
|
38
|
+
*
|
|
39
|
+
* `slack` and `linear-app` install the channels agent triggers answer
|
|
40
|
+
* through — Slack, and Ekanos's own Linear Agents app — by the same
|
|
41
|
+
* link-and-wait (`teams-channel-install.ts`).
|
|
42
|
+
*/
|
|
43
|
+
export declare function runTeamConnect(ctx: CliContext, args: TeamsArgs, client: TeamsClient, host: string, source: string, input: {
|
|
44
|
+
team: string;
|
|
45
|
+
product: string;
|
|
46
|
+
as?: string;
|
|
47
|
+
connection?: string;
|
|
48
|
+
}): Promise<ExitCode>;
|
|
49
|
+
/** Named connections the team's agents wait on and the team has not installed. */
|
|
50
|
+
export declare function channelsToInstall(status: TeamIntegrationStatus): {
|
|
51
|
+
connectionId: string;
|
|
52
|
+
label: string;
|
|
53
|
+
teamApp: boolean;
|
|
54
|
+
credentialsSaved: boolean | null;
|
|
55
|
+
connected: boolean;
|
|
56
|
+
connectedAt: string | null;
|
|
57
|
+
connectedBy: {
|
|
58
|
+
userId: string;
|
|
59
|
+
name: string | null;
|
|
60
|
+
email: string | null;
|
|
61
|
+
} | null;
|
|
62
|
+
neededBy: {
|
|
63
|
+
agent: string;
|
|
64
|
+
triggers: string[];
|
|
65
|
+
}[];
|
|
66
|
+
}[];
|
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
import { TeamAgentListSchema, } from '@ekanos/integration-schema';
|
|
2
|
+
import { invalidStateError, usageError, validationError } from '../errors.js';
|
|
3
|
+
import { assertBrowserSafeUrl, openInBrowser } from '../open-url.js';
|
|
4
|
+
import { showTeamConnect, startTeamConnect, } from '../team-connect-api.js';
|
|
5
|
+
import { call, showTeamIntegration } from '../teams-api.js';
|
|
6
|
+
import { promptHidden, promptLine } from './apps.js';
|
|
7
|
+
import { scopeHiddenLines } from './scope-notice.js';
|
|
8
|
+
import { canPrompt, checklist, promptAndSaveTeamApp, } from './teams.js';
|
|
9
|
+
import { isTeamChannel, runTeamChannelInstall } from './teams-channel-install.js';
|
|
10
|
+
/**
|
|
11
|
+
* `teams connect <team> <product>` — connect a product for one team, doing
|
|
12
|
+
* whichever the integration needs (the host's plan decides, never the CLI):
|
|
13
|
+
*
|
|
14
|
+
* - works as shipped → says so; not self-serve or not enabled → refuses
|
|
15
|
+
* with the reason (and points at `sources products` for the latter);
|
|
16
|
+
* - form fields → asks them here (secrets hidden, never as arguments) and
|
|
17
|
+
* activates exactly as the app's form does;
|
|
18
|
+
* - OAuth → runs `teams app set` inline when the team's own app is needed
|
|
19
|
+
* first (Zendesk), then a one-time sign-in link for the member who
|
|
20
|
+
* consents: the caller when a member, else `--as <email>`. Opens it for
|
|
21
|
+
* the caller (unless `--no-open`), always prints it, and waits until the
|
|
22
|
+
* team is connected (unless `--no-wait`);
|
|
23
|
+
* - a form only the browser can fill → prints the team's page.
|
|
24
|
+
*
|
|
25
|
+
* `--connection <id>` connects one of the integration's named connections
|
|
26
|
+
* instead of the main one — Linear's `agent`, the team's own Linear app
|
|
27
|
+
* installed as a workspace member, which is what makes Linear send the
|
|
28
|
+
* @mention and assignment webhooks an agent's triggers listen for. It runs
|
|
29
|
+
* the same way: the team app's fields when missing, then the sign-in, then
|
|
30
|
+
* the wait until it is installed.
|
|
31
|
+
*
|
|
32
|
+
* Without `--connection`, once the main connection is made (or already
|
|
33
|
+
* was), a named connection the team's agents' triggers wait on is offered
|
|
34
|
+
* next — at a terminal it asks and installs it, otherwise it names the
|
|
35
|
+
* command. "Connected" is not the goal; an agent that can be reached is.
|
|
36
|
+
*
|
|
37
|
+
* `--reconnect` connects it again even though it reads as connected — for
|
|
38
|
+
* a revoked or expired sign-in, or new form values. An OAuth reconnect
|
|
39
|
+
* prints the link and returns: the team already reads as connected, so
|
|
40
|
+
* there is nothing to wait for.
|
|
41
|
+
*
|
|
42
|
+
* `--link-only` keeps the old behaviour: the team's page and its status.
|
|
43
|
+
*
|
|
44
|
+
* `slack` and `linear-app` install the channels agent triggers answer
|
|
45
|
+
* through — Slack, and Ekanos's own Linear Agents app — by the same
|
|
46
|
+
* link-and-wait (`teams-channel-install.ts`).
|
|
47
|
+
*/
|
|
48
|
+
export async function runTeamConnect(ctx, args, client, host, source, input) {
|
|
49
|
+
var _a, _b, _c, _d, _e;
|
|
50
|
+
const target = Object.assign({ source, team: input.team, product: input.product }, (input.connection ? { connection: input.connection } : {}));
|
|
51
|
+
// Slack and Ekanos's Linear Agents app: the channels a `slack` or `linear`
|
|
52
|
+
// agent trigger answers through, installed by their own flows.
|
|
53
|
+
if (!input.connection && !args.linkOnly && isTeamChannel(input.product)) {
|
|
54
|
+
return runTeamChannelInstall(ctx, args, client, host, source, Object.assign(Object.assign({ team: input.team, channel: input.product }, (input.as ? { as: input.as } : {})), { open: (_a = args.openUrl) !== null && _a !== void 0 ? _a : openInBrowser }));
|
|
55
|
+
}
|
|
56
|
+
if (args.linkOnly)
|
|
57
|
+
return printLink(ctx, client, host, target);
|
|
58
|
+
const { plan } = await client.call((token) => showTeamConnect(host, token, target, input.as));
|
|
59
|
+
const named = isNamed(plan);
|
|
60
|
+
const name = named
|
|
61
|
+
? await connectionLabel(client, host, target, plan)
|
|
62
|
+
: plan.product.name;
|
|
63
|
+
await warnOtherRunsAs(ctx, client, host, source, plan);
|
|
64
|
+
for (const line of scopeHiddenLines(plan.productScope, {
|
|
65
|
+
team: plan.team.slug,
|
|
66
|
+
product: plan.product.slug,
|
|
67
|
+
source: plan.source.slug,
|
|
68
|
+
})) {
|
|
69
|
+
ctx.warn(line);
|
|
70
|
+
}
|
|
71
|
+
switch (plan.mode) {
|
|
72
|
+
case 'not-entitled':
|
|
73
|
+
throw invalidStateError((_b = plan.reason) !== null && _b !== void 0 ? _b : `"${input.product}" is not enabled on ${plan.source.slug}.`, `Enable it for the Source first: "ekanos sources products enable ${input.product}" as a Source admin if ${plan.source.slug} built it, otherwise a super-admin (/admin in the browser). "ekanos sources products" shows what ${plan.source.slug} has.`);
|
|
74
|
+
case 'not-self-serve':
|
|
75
|
+
throw invalidStateError((_c = plan.reason) !== null && _c !== void 0 ? _c : `${name} is not connected by a team.`, plan.product.kind === 'experience'
|
|
76
|
+
? `"ekanos sources products --source ${plan.source.slug}" shows whether it is on for the Source.`
|
|
77
|
+
: 'It is turned on for the Source by Ekanos; there is nothing for the team to do.');
|
|
78
|
+
case 'unsupported':
|
|
79
|
+
throw invalidStateError((_d = plan.reason) !== null && _d !== void 0 ? _d : `${name} cannot be connected from here.`, `Open the team's page instead: ${plan.connectUrl}`);
|
|
80
|
+
case 'works-as-shipped':
|
|
81
|
+
return ctx.succeed({ host, plan, connected: true }, ctx.ui.result({
|
|
82
|
+
title: `${name} works as shipped for ${plan.team.slug}`,
|
|
83
|
+
rows: [['Status', 'nothing to connect']],
|
|
84
|
+
}));
|
|
85
|
+
case 'browser':
|
|
86
|
+
return ctx.succeed({ host, plan, connected: plan.connected }, ctx.ui.result({
|
|
87
|
+
title: plan.connected
|
|
88
|
+
? `${plan.team.slug} has connected ${name}`
|
|
89
|
+
: `${name} connects in the app for ${plan.team.slug}`,
|
|
90
|
+
tone: plan.connected ? 'ok' : 'warn',
|
|
91
|
+
rows: [
|
|
92
|
+
['Open', plan.connectUrl],
|
|
93
|
+
['Status', statusOf(plan)],
|
|
94
|
+
],
|
|
95
|
+
notes: plan.connected
|
|
96
|
+
? []
|
|
97
|
+
: [
|
|
98
|
+
(_e = plan.reason) !== null && _e !== void 0 ? _e : `${name} connects through its own form in the app.`,
|
|
99
|
+
'A team admin signs in there and clicks Connect.',
|
|
100
|
+
],
|
|
101
|
+
}));
|
|
102
|
+
default:
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
if (plan.connected && !args.reconnect) {
|
|
106
|
+
const summary = ctx.ui.result({
|
|
107
|
+
title: `${plan.team.slug} has already ${named ? 'installed' : 'connected'} ${name}`,
|
|
108
|
+
rows: [
|
|
109
|
+
['Status', statusOf(plan, named)],
|
|
110
|
+
['Team page', plan.connectUrl],
|
|
111
|
+
],
|
|
112
|
+
notes: [
|
|
113
|
+
`"ekanos teams show ${plan.team.slug} ${plan.product.slug}" shows the full setup.`,
|
|
114
|
+
`Broken (revoked or expired)? Connect it again: ekanos teams connect ${plan.team.slug} ${plan.product.slug}${named ? ` --connection ${plan.connectionId}` : ''} --reconnect`,
|
|
115
|
+
],
|
|
116
|
+
});
|
|
117
|
+
return named
|
|
118
|
+
? ctx.succeed({ host, plan, connected: true }, summary)
|
|
119
|
+
: offerChannels(ctx, args, client, host, source, input, {
|
|
120
|
+
data: { host, plan, connected: true },
|
|
121
|
+
summary,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
if (plan.mode === 'fields' || plan.mode === 'no-fields') {
|
|
125
|
+
return activate(ctx, args, client, host, target, plan);
|
|
126
|
+
}
|
|
127
|
+
return connectOAuth(ctx, args, client, host, target, plan, input.as, {
|
|
128
|
+
name,
|
|
129
|
+
then: named
|
|
130
|
+
? undefined
|
|
131
|
+
: (done) => offerChannels(ctx, args, client, host, source, input, done),
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* A personal connection belongs to whoever makes it, but a provided agent
|
|
136
|
+
* uses the personal connection of the person it runs as — so connecting
|
|
137
|
+
* your own leaves the agent missing it (CLI audit P0-5). Name each agent
|
|
138
|
+
* that runs as someone else and the command that connects it for them.
|
|
139
|
+
*/
|
|
140
|
+
async function warnOtherRunsAs(ctx, client, host, source, plan) {
|
|
141
|
+
var _a, _b, _c, _d;
|
|
142
|
+
const email = (_b = (_a = plan.member) === null || _a === void 0 ? void 0 : _a.email) === null || _b === void 0 ? void 0 : _b.toLowerCase();
|
|
143
|
+
if (plan.scope !== 'user' || !email)
|
|
144
|
+
return;
|
|
145
|
+
let list;
|
|
146
|
+
try {
|
|
147
|
+
list = await client.call((token) => call(host, token, TeamAgentListSchema, {
|
|
148
|
+
method: 'GET',
|
|
149
|
+
path: `/api/partner/teams/${encodeURIComponent(plan.team.slug)}/agents`,
|
|
150
|
+
source,
|
|
151
|
+
}));
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
ctx.log(`Could not check who ${plan.team.slug}'s agents run as: ${error instanceof Error ? error.message : String(error)}`);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
for (const entry of list.agents) {
|
|
158
|
+
const runsAs = (_d = (_c = entry.agent) === null || _c === void 0 ? void 0 : _c.requirements.find((item) => item.key === plan.product.slug &&
|
|
159
|
+
item.via === 'person' &&
|
|
160
|
+
item.viaDetail &&
|
|
161
|
+
item.viaDetail.toLowerCase() !== email)) === null || _d === void 0 ? void 0 : _d.viaDetail;
|
|
162
|
+
if (!runsAs)
|
|
163
|
+
continue;
|
|
164
|
+
ctx.warn(`Note: ${entry.key} runs as ${runsAs} and uses ${runsAs}'s ${plan.product.name} connection, not ${email}'s. For the agent, run: npx @ekanos/cli teams connect ${plan.team.slug} ${plan.product.slug} --as ${runsAs} --source ${source}`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* After the main connection: the named connections the team's agents'
|
|
169
|
+
* triggers wait on and the team has not installed (Linear's agent). At a
|
|
170
|
+
* terminal, ask and install each; otherwise name the command, in the
|
|
171
|
+
* result and its JSON (`channelsToInstall`).
|
|
172
|
+
*/
|
|
173
|
+
async function offerChannels(ctx, args, client, host, source, input, done) {
|
|
174
|
+
var _a;
|
|
175
|
+
const status = await client.call((token) => showTeamIntegration(host, token, {
|
|
176
|
+
source,
|
|
177
|
+
team: input.team,
|
|
178
|
+
product: input.product,
|
|
179
|
+
}));
|
|
180
|
+
const waiting = channelsToInstall(status);
|
|
181
|
+
if (waiting.length === 0)
|
|
182
|
+
return ctx.succeed(done.data, done.summary);
|
|
183
|
+
const command = (connectionId) => `ekanos teams connect ${input.team} ${input.product} --connection ${connectionId} --source ${status.source.slug}`;
|
|
184
|
+
const why = (entry) => `${entry.label} is not installed for ${input.team}, and ${entry.neededBy.map((need) => `${need.agent} (${need.triggers.join(', ')})`).join(', ')} only start${entry.neededBy.length === 1 ? 's' : ''} through it.`;
|
|
185
|
+
if (!canPrompt(ctx, args)) {
|
|
186
|
+
return ctx.succeed(Object.assign(Object.assign({}, done.data), { channelsToInstall: waiting.map((entry) => ({
|
|
187
|
+
connectionId: entry.connectionId,
|
|
188
|
+
label: entry.label,
|
|
189
|
+
neededBy: entry.neededBy,
|
|
190
|
+
command: command(entry.connectionId),
|
|
191
|
+
})) }), [
|
|
192
|
+
done.summary,
|
|
193
|
+
...waiting.flatMap((entry) => [
|
|
194
|
+
`Next: ${why(entry)}`,
|
|
195
|
+
` Install it in your terminal: npx @ekanos/cli ${command(entry.connectionId)}`,
|
|
196
|
+
]),
|
|
197
|
+
].join('\n'));
|
|
198
|
+
}
|
|
199
|
+
ctx.log(done.summary);
|
|
200
|
+
let code = 0;
|
|
201
|
+
for (const entry of waiting) {
|
|
202
|
+
ctx.log(why(entry));
|
|
203
|
+
const answer = (await ((_a = args.ask) !== null && _a !== void 0 ? _a : promptLine)(`Install ${entry.label} now? [Y/n] `))
|
|
204
|
+
.trim()
|
|
205
|
+
.toLowerCase();
|
|
206
|
+
if (answer !== '' && answer !== 'y' && answer !== 'yes') {
|
|
207
|
+
ctx.log(`Skipped. Later: ${command(entry.connectionId)}`);
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
code = await runTeamConnect(ctx, args, client, host, source, Object.assign(Object.assign({}, input), { connection: entry.connectionId }));
|
|
211
|
+
}
|
|
212
|
+
return code;
|
|
213
|
+
}
|
|
214
|
+
/** Named connections the team's agents wait on and the team has not installed. */
|
|
215
|
+
export function channelsToInstall(status) {
|
|
216
|
+
var _a;
|
|
217
|
+
return ((_a = status.connections) !== null && _a !== void 0 ? _a : []).filter((entry) => entry.connectionId !== 'default' &&
|
|
218
|
+
!entry.connected &&
|
|
219
|
+
entry.neededBy.length > 0);
|
|
220
|
+
}
|
|
221
|
+
function isNamed(plan) {
|
|
222
|
+
return Boolean(plan.connectionId && plan.connectionId !== 'default');
|
|
223
|
+
}
|
|
224
|
+
async function connectionLabel(client, host, target, plan) {
|
|
225
|
+
var _a, _b, _c;
|
|
226
|
+
var _d, _e;
|
|
227
|
+
const status = await client.call((token) => showTeamIntegration(host, token, target));
|
|
228
|
+
return ((_e = (_d = (_b = (_a = status.connections) === null || _a === void 0 ? void 0 : _a.find((entry) => entry.connectionId === plan.connectionId)) === null || _b === void 0 ? void 0 : _b.label) !== null && _d !== void 0 ? _d : (_c = status.teamApps.find((entry) => entry.connectionId === plan.connectionId)) === null || _c === void 0 ? void 0 : _c.label) !== null && _e !== void 0 ? _e : `${plan.product.name} (${plan.connectionId})`);
|
|
229
|
+
}
|
|
230
|
+
async function activate(ctx, args, client, host, target, plan) {
|
|
231
|
+
var _a;
|
|
232
|
+
var _b, _c, _d, _e;
|
|
233
|
+
if (plan.scope === 'user' && !plan.member) {
|
|
234
|
+
throw invalidStateError((_b = plan.memberProblem) !== null && _b !== void 0 ? _b : `${plan.product.name} is a personal connection: each member connects their own.`, `A member connects it for themselves on the team's page: ${plan.connectUrl}`);
|
|
235
|
+
}
|
|
236
|
+
const fields = {};
|
|
237
|
+
if (plan.mode === 'fields') {
|
|
238
|
+
if (!canPrompt(ctx, args)) {
|
|
239
|
+
throw usageError(`${plan.product.name} needs its fields typed at a terminal (${plan.fields.map((field) => field.label).join(', ')}), never in a script or an agent run.`, `Run it yourself in your terminal: npx @ekanos/cli teams connect ${target.team} ${target.product} --source ${plan.source.slug}`);
|
|
240
|
+
}
|
|
241
|
+
ctx.log(`${plan.product.name} for ${plan.scope === 'user' ? 'you, in' : 'team'} ${plan.team.slug}: enter what the app's form asks. Secrets are hidden and never shown again.`);
|
|
242
|
+
for (const field of plan.fields) {
|
|
243
|
+
if (field.description)
|
|
244
|
+
ctx.log(` ${field.description}`);
|
|
245
|
+
const suffix = `${field.required ? '' : ' (optional — Enter skips)'}${field.sensitive ? ' (hidden)' : ''}: `;
|
|
246
|
+
const value = (await (field.sensitive
|
|
247
|
+
? ((_c = args.askSecret) !== null && _c !== void 0 ? _c : promptHidden)
|
|
248
|
+
: ((_d = args.ask) !== null && _d !== void 0 ? _d : promptLine))(`${field.label}${suffix}`)).trim();
|
|
249
|
+
if (value)
|
|
250
|
+
fields[field.name] = value;
|
|
251
|
+
else if (field.required) {
|
|
252
|
+
throw validationError(`${field.label} is needed.`, `Run "ekanos teams connect ${target.team} ${target.product}" again.`);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
const started = await client.call((token) => startTeamConnect(host, token, target, { fields }));
|
|
257
|
+
return ctx.succeed(Object.assign(Object.assign({ host }, started), { connected: started.plan.connected }), ctx.ui.result({
|
|
258
|
+
title: `Connected ${started.plan.product.name} for ${started.plan.team.slug}`,
|
|
259
|
+
rows: [
|
|
260
|
+
['Status', statusOf(started.plan)],
|
|
261
|
+
[
|
|
262
|
+
'For',
|
|
263
|
+
started.plan.scope === 'user'
|
|
264
|
+
? `you (${(_e = (_a = started.plan.member) === null || _a === void 0 ? void 0 : _a.email) !== null && _e !== void 0 ? _e : 'your account'}) — a personal connection`
|
|
265
|
+
: 'the whole team',
|
|
266
|
+
],
|
|
267
|
+
['Team page', started.plan.connectUrl],
|
|
268
|
+
],
|
|
269
|
+
}));
|
|
270
|
+
}
|
|
271
|
+
async function connectOAuth(ctx, args, client, host, target, plan, asEmail, options) {
|
|
272
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
273
|
+
const named = isNamed(plan);
|
|
274
|
+
const name = options.name;
|
|
275
|
+
const again = `ekanos teams connect ${target.team} ${target.product}${named ? ` --connection ${plan.connectionId}` : ''}`;
|
|
276
|
+
if (!plan.member) {
|
|
277
|
+
throw invalidStateError((_a = plan.memberProblem) !== null && _a !== void 0 ? _a : 'No member of the team can sign in yet.', `Name a member of ${plan.team.slug} who signs in: ${again} --as <email>`);
|
|
278
|
+
}
|
|
279
|
+
if (plan.teamApp) {
|
|
280
|
+
const status = await client.call((token) => showTeamIntegration(host, token, target));
|
|
281
|
+
const connectionId = (_b = plan.connectionId) !== null && _b !== void 0 ? _b : 'default';
|
|
282
|
+
const app = (_c = status.teamApps.find((entry) => entry.connectionId === connectionId)) !== null && _c !== void 0 ? _c : (named ? undefined : status.teamApps[0]);
|
|
283
|
+
if (app && app.fields.some((field) => !field.set)) {
|
|
284
|
+
if (!canPrompt(ctx, args)) {
|
|
285
|
+
throw usageError(`${name} needs ${plan.team.slug}'s own app first, entered at a terminal.`, `Run it yourself in your terminal: npx @ekanos/cli ${again} --source ${plan.source.slug}`);
|
|
286
|
+
}
|
|
287
|
+
ctx.log(`${name} signs ${plan.team.slug} in through the team's own app. Set it up first:`);
|
|
288
|
+
await promptAndSaveTeamApp(ctx, args, client, host, target, status, app);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
const started = await client.call((token) => startTeamConnect(host, token, target, asEmail ? { as: asEmail } : {}));
|
|
292
|
+
if (started.result !== 'consent') {
|
|
293
|
+
throw invalidStateError(`The host answered "${started.result}" where a sign-in link was expected.`, 'Run "ekanos upgrade" — the CLI and the host disagree on the connect contract.');
|
|
294
|
+
}
|
|
295
|
+
assertBrowserSafeUrl(started.authorizeUrl, 'sign-in link');
|
|
296
|
+
const member = (_d = started.plan.member) !== null && _d !== void 0 ? _d : plan.member;
|
|
297
|
+
const forCaller = member.isCaller;
|
|
298
|
+
const expires = started.expiresAt.replace('T', ' ').slice(0, 16);
|
|
299
|
+
ctx.log(forCaller
|
|
300
|
+
? [
|
|
301
|
+
named
|
|
302
|
+
? `Install ${name} for ${plan.team.slug} — sign in as an admin of the workspace it goes into, and approve it:`
|
|
303
|
+
: `Sign in to ${plan.product.name} as the account ${plan.team.slug} should use${plan.scope === 'user' ? ' (a personal connection: yours)' : ''}:`,
|
|
304
|
+
` ${started.authorizeUrl}`,
|
|
305
|
+
` (one-time link, valid until ${expires} UTC)`,
|
|
306
|
+
].join('\n')
|
|
307
|
+
: [
|
|
308
|
+
`Send this link to ${(_e = member.email) !== null && _e !== void 0 ? _e : 'the member'} — they ${named ? `install ${name}` : `sign in to ${plan.product.name}`} for ${plan.team.slug}${plan.scope === 'user' ? ' (a personal connection: theirs)' : ''}:`,
|
|
309
|
+
` ${started.authorizeUrl}`,
|
|
310
|
+
` (one-time, for them only, valid until ${expires} UTC)`,
|
|
311
|
+
].join('\n'));
|
|
312
|
+
// Only ever the caller's own browser: opening a link meant for another
|
|
313
|
+
// member would sign the caller's provider account in for them.
|
|
314
|
+
if (forCaller && !args.noOpen && !ctx.jsonMode) {
|
|
315
|
+
((_f = args.openUrl) !== null && _f !== void 0 ? _f : openInBrowser)(started.authorizeUrl);
|
|
316
|
+
}
|
|
317
|
+
// A reconnect can't be waited on: the team already reads as connected, so
|
|
318
|
+
// nothing the host reports changes when the new sign-in lands.
|
|
319
|
+
const reconnecting = args.reconnect === true && plan.connected;
|
|
320
|
+
if (args.noWait || ctx.jsonMode || reconnecting) {
|
|
321
|
+
return ctx.succeed({
|
|
322
|
+
host,
|
|
323
|
+
plan: started.plan,
|
|
324
|
+
authorizeUrl: started.authorizeUrl,
|
|
325
|
+
expiresAt: started.expiresAt,
|
|
326
|
+
connected: false,
|
|
327
|
+
}, ctx.ui.hint(reconnecting
|
|
328
|
+
? `The current connection keeps working until the sign-in finishes; then its tokens are replaced. Check with "ekanos teams show ${target.team} ${target.product}".`
|
|
329
|
+
: `Then check with "ekanos teams show ${target.team} ${target.product}".`));
|
|
330
|
+
}
|
|
331
|
+
ctx.log('Waiting for the sign-in to finish (Ctrl-C stops waiting; the link stays valid)…');
|
|
332
|
+
const deadline = Date.parse(started.expiresAt) || Date.now() + 10 * 60 * 1000;
|
|
333
|
+
while (Date.now() < deadline) {
|
|
334
|
+
await new Promise((resolve) => { var _a; return setTimeout(resolve, (_a = args.pollDelayMs) !== null && _a !== void 0 ? _a : 3000); });
|
|
335
|
+
const polled = await client.call((token) => showTeamConnect(host, token, target, asEmail));
|
|
336
|
+
if (polled.plan.connected) {
|
|
337
|
+
const status = await client.call((token) => showTeamIntegration(host, token, target));
|
|
338
|
+
const done = {
|
|
339
|
+
data: { host, plan: polled.plan, status, connected: true },
|
|
340
|
+
summary: [
|
|
341
|
+
ctx.ui.result({
|
|
342
|
+
title: `${named ? 'Installed' : 'Connected'} ${name} for ${plan.team.slug}`,
|
|
343
|
+
rows: [
|
|
344
|
+
['Signed in by', (_g = member.email) !== null && _g !== void 0 ? _g : member.userId],
|
|
345
|
+
['Status', statusOf(polled.plan, named)],
|
|
346
|
+
],
|
|
347
|
+
notes: named
|
|
348
|
+
? [
|
|
349
|
+
`Prove it end to end: @mention the agent in ${plan.product.name}, then "ekanos runs list --team ${plan.team.slug}" shows the run it started.`,
|
|
350
|
+
]
|
|
351
|
+
: [],
|
|
352
|
+
}),
|
|
353
|
+
checklist(status).join('\n'),
|
|
354
|
+
].join('\n'),
|
|
355
|
+
};
|
|
356
|
+
return options.then
|
|
357
|
+
? options.then(done)
|
|
358
|
+
: ctx.succeed(done.data, done.summary);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
throw validationError('The sign-in did not finish before the link expired.', `Run "${again}${asEmail ? ` --as ${asEmail}` : ''}" again for a fresh link.`);
|
|
362
|
+
}
|
|
363
|
+
/** `--link-only`: the team's page and whether it is connected. */
|
|
364
|
+
async function printLink(ctx, client, host, target) {
|
|
365
|
+
var _a;
|
|
366
|
+
const status = await client.call((token) => showTeamIntegration(host, token, target));
|
|
367
|
+
if (!status.enabled) {
|
|
368
|
+
throw invalidStateError(`"${target.product}" is not enabled on ${status.source.slug}.`, `"ekanos sources products --source ${status.source.slug}" shows what this Source has; a super-admin enables a product for a Source.`);
|
|
369
|
+
}
|
|
370
|
+
const connected = status.activation !== null;
|
|
371
|
+
const rows = [
|
|
372
|
+
['Open', status.connectUrl],
|
|
373
|
+
[
|
|
374
|
+
'Status',
|
|
375
|
+
connected
|
|
376
|
+
? `connected${((_a = status.activation) === null || _a === void 0 ? void 0 : _a.activatedAt) ? ` ${status.activation.activatedAt.slice(0, 10)}` : ''}`
|
|
377
|
+
: 'not connected',
|
|
378
|
+
],
|
|
379
|
+
];
|
|
380
|
+
return ctx.succeed(Object.assign({ host }, status), ctx.ui.result({
|
|
381
|
+
title: connected
|
|
382
|
+
? `${status.team.slug} has connected ${status.product.name}`
|
|
383
|
+
: `Connect link for ${status.team.slug} · ${status.product.name}`,
|
|
384
|
+
tone: connected ? 'ok' : 'warn',
|
|
385
|
+
rows,
|
|
386
|
+
notes: [
|
|
387
|
+
'A team member signs in there and clicks Connect.',
|
|
388
|
+
`"ekanos teams connect ${status.team.slug} ${status.product.slug}" (without --link-only) connects it from here.`,
|
|
389
|
+
],
|
|
390
|
+
}));
|
|
391
|
+
}
|
|
392
|
+
function statusOf(plan, named = false) {
|
|
393
|
+
if (!plan.connected)
|
|
394
|
+
return named ? 'not installed' : 'not connected';
|
|
395
|
+
return `${named ? 'installed' : 'connected'}${plan.connectedAt ? ` ${plan.connectedAt.slice(0, 10)}` : ''}`;
|
|
396
|
+
}
|
|
397
|
+
//# sourceMappingURL=teams-connect.js.map
|