@wirecat/slack-cli 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +104 -0
- package/LICENSE +204 -0
- package/README.md +131 -2
- package/contracts/wirecat.json +5526 -0
- package/dist/bin/slack.d.ts +3 -0
- package/dist/bin/slack.d.ts.map +1 -0
- package/dist/bin/slack.js +40 -0
- package/dist/bin/slack.js.map +1 -0
- package/dist/bundle/agent-GOFXFUQP.js +37 -0
- package/dist/bundle/all-profiles-4C7VOT2D.js +320 -0
- package/dist/bundle/anthropic-ZD66TC5S.js +91 -0
- package/dist/bundle/app-server-QNCVEDMY.js +249 -0
- package/dist/bundle/bun-2FULBYXS.js +169 -0
- package/dist/bundle/bun-sqlite-PMS26ZUT.js +76 -0
- package/dist/bundle/chunk-2LB5BWC4.js +362 -0
- package/dist/bundle/chunk-2ZEYRHZV.js +18 -0
- package/dist/bundle/chunk-3IJ3THPV.js +7 -0
- package/dist/bundle/chunk-4HSVEQ3R.js +29 -0
- package/dist/bundle/chunk-4QPMHVM5.js +1007 -0
- package/dist/bundle/chunk-53LIHHXC.js +16 -0
- package/dist/bundle/chunk-5F36CXDM.js +794 -0
- package/dist/bundle/chunk-5LPREGD3.js +12636 -0
- package/dist/bundle/chunk-5R5YRYIP.js +1148 -0
- package/dist/bundle/chunk-5RSQTG7L.js +388 -0
- package/dist/bundle/chunk-5SXZETJF.js +170 -0
- package/dist/bundle/chunk-6PDQP5RM.js +50 -0
- package/dist/bundle/chunk-75BLNPN3.js +1197 -0
- package/dist/bundle/chunk-7BEO72EN.js +131 -0
- package/dist/bundle/chunk-7F6RNAIM.js +230 -0
- package/dist/bundle/chunk-AG7FP64Z.js +77 -0
- package/dist/bundle/chunk-B7ZM3FCB.js +61 -0
- package/dist/bundle/chunk-BRXTN5LJ.js +338 -0
- package/dist/bundle/chunk-CABZAU37.js +319 -0
- package/dist/bundle/chunk-CCOSG3F2.js +24616 -0
- package/dist/bundle/chunk-CDTZSFTN.js +58 -0
- package/dist/bundle/chunk-CMZBCWND.js +1246 -0
- package/dist/bundle/chunk-CRQEEJNF.js +185 -0
- package/dist/bundle/chunk-CWYU4R65.js +358 -0
- package/dist/bundle/chunk-CZFR6JQX.js +52 -0
- package/dist/bundle/chunk-D72URWJE.js +532 -0
- package/dist/bundle/chunk-DFDN6AUB.js +21 -0
- package/dist/bundle/chunk-DVHX7R54.js +4072 -0
- package/dist/bundle/chunk-DYKOG7QR.js +9596 -0
- package/dist/bundle/chunk-ECDI42G6.js +100 -0
- package/dist/bundle/chunk-EH6ZEJGT.js +932 -0
- package/dist/bundle/chunk-ELY2TLCY.js +259 -0
- package/dist/bundle/chunk-ERRVUVKR.js +156 -0
- package/dist/bundle/chunk-FBWR4E5D.js +353 -0
- package/dist/bundle/chunk-GKS6KL57.js +6848 -0
- package/dist/bundle/chunk-H2COZZ55.js +2787 -0
- package/dist/bundle/chunk-HGXTEK7R.js +82 -0
- package/dist/bundle/chunk-HXLXM7HV.js +726 -0
- package/dist/bundle/chunk-IPP4N6HD.js +24 -0
- package/dist/bundle/chunk-IWTVR7S7.js +53 -0
- package/dist/bundle/chunk-IYJH75D4.js +63 -0
- package/dist/bundle/chunk-JCZLRT4Z.js +39 -0
- package/dist/bundle/chunk-JGRWMR5H.js +123 -0
- package/dist/bundle/chunk-JYRYQJBN.js +633 -0
- package/dist/bundle/chunk-KIKLDI74.js +161 -0
- package/dist/bundle/chunk-L4WO3XH6.js +2020 -0
- package/dist/bundle/chunk-LQDNUAK3.js +274 -0
- package/dist/bundle/chunk-LV5ONLQH.js +38 -0
- package/dist/bundle/chunk-M27Z23OZ.js +23 -0
- package/dist/bundle/chunk-M5XTZHXM.js +142 -0
- package/dist/bundle/chunk-MJBEGUIZ.js +76 -0
- package/dist/bundle/chunk-N4WOLGIV.js +2333 -0
- package/dist/bundle/chunk-N5K4OHPT.js +206 -0
- package/dist/bundle/chunk-NYAPUET7.js +108 -0
- package/dist/bundle/chunk-P4IFLOIK.js +218 -0
- package/dist/bundle/chunk-P6G2QTCD.js +288 -0
- package/dist/bundle/chunk-PL5P7UKW.js +25216 -0
- package/dist/bundle/chunk-PU7R6XNV.js +80 -0
- package/dist/bundle/chunk-QLLBACDR.js +72 -0
- package/dist/bundle/chunk-QP7XN5KX.js +407 -0
- package/dist/bundle/chunk-QY2F6A3D.js +557 -0
- package/dist/bundle/chunk-RLIT7VAZ.js +66 -0
- package/dist/bundle/chunk-S4UUN6LD.js +1410 -0
- package/dist/bundle/chunk-SKGAKI62.js +86 -0
- package/dist/bundle/chunk-SQMZP5MA.js +66653 -0
- package/dist/bundle/chunk-UB6NTICY.js +95 -0
- package/dist/bundle/chunk-UBHQO5HV.js +778 -0
- package/dist/bundle/chunk-UM4RKO24.js +106 -0
- package/dist/bundle/chunk-VAHFY732.js +1068 -0
- package/dist/bundle/chunk-VGDM4C3F.js +188 -0
- package/dist/bundle/chunk-VOUAKCPM.js +41181 -0
- package/dist/bundle/chunk-WCCFJ4Q6.js +3736 -0
- package/dist/bundle/chunk-WV6EXRDV.js +46 -0
- package/dist/bundle/chunk-WVAT5TGY.js +334 -0
- package/dist/bundle/chunk-WW76JMKE.js +1243 -0
- package/dist/bundle/chunk-XXOMUKC6.js +54 -0
- package/dist/bundle/chunk-Y5E2WNWB.js +35 -0
- package/dist/bundle/chunk-YDO6RJ2P.js +1337 -0
- package/dist/bundle/chunk-ZBCFZCJW.js +388 -0
- package/dist/bundle/chunk-ZVVMGPBJ.js +50 -0
- package/dist/bundle/command-contract-BWGRUY6L.js +37 -0
- package/dist/bundle/command-server-entry-BATOWE3Y.js +166 -0
- package/dist/bundle/decode-MZQGYXJH.js +297 -0
- package/dist/bundle/definitions-3EONB23J.js +8600 -0
- package/dist/bundle/dispatch-NYC4ARWX.js +411 -0
- package/dist/bundle/dist-PAKDDIBT.js +191 -0
- package/dist/bundle/dist-XZ65GRQ6.js +7577 -0
- package/dist/bundle/echarts-7OYGL2GW.js +42501 -0
- package/dist/bundle/embed-4I25DVKZ.js +38 -0
- package/dist/bundle/embedder-YXKQHAZO.js +111 -0
- package/dist/bundle/emoji-4LYX3GOS.js +4271 -0
- package/dist/bundle/failure-3YOVYZTX.js +25 -0
- package/dist/bundle/first-run-2VL2BOV7.js +29 -0
- package/dist/bundle/first-screen-C7FIWZL2.js +37 -0
- package/dist/bundle/instructions-UMNDHXG2.js +11 -0
- package/dist/bundle/mcp-V27RHILF.js +167 -0
- package/dist/bundle/meeting-combined-LS6XO4JH.js +24 -0
- package/dist/bundle/meeting-model-VIR465CY.js +25 -0
- package/dist/bundle/meeting-semantic-H5J3OOF2.js +22 -0
- package/dist/bundle/node-JJ3WDCNJ.js +2340 -0
- package/dist/bundle/node-PYFPGL4E.js +176 -0
- package/dist/bundle/node-TLZSIHIJ.js +21 -0
- package/dist/bundle/node-sqlite-LFWPGDVP.js +74 -0
- package/dist/bundle/oauth-42VCSIVL.js +20 -0
- package/dist/bundle/open-XJ5R5LHC.js +23 -0
- package/dist/bundle/openai-RZBLV4HG.js +238 -0
- package/dist/bundle/process-DD6H3K7L.js +91 -0
- package/dist/bundle/program-33RT6DER.js +35421 -0
- package/dist/bundle/prompt-NQRDM5LY.js +17 -0
- package/dist/bundle/recognize-EM7H2IZS.js +26 -0
- package/dist/bundle/remote-Z6NU6QQA.js +31 -0
- package/dist/bundle/rerank-PNPCSPNF.js +52 -0
- package/dist/bundle/schemas-JMKNP4U3.js +2765 -0
- package/dist/bundle/serve-SQVGX76J.js +199 -0
- package/dist/bundle/server-NPJH45FZ.js +212 -0
- package/dist/bundle/server-Z4ZMGRAH.js +79 -0
- package/dist/bundle/slack.js +184 -0
- package/dist/bundle/sqlite-runtime-F3AJGAPN.js +20 -0
- package/dist/bundle/state-JT7ZFSXN.js +36 -0
- package/dist/bundle/store-FXGMHRF3.js +181 -0
- package/dist/bundle/store-J5ZL2USR.js +295 -0
- package/dist/bundle/store-maintenance-command-TIHOIKLZ.js +66 -0
- package/dist/bundle/surface-NW6T5OR6.js +65 -0
- package/dist/commands/api.d.ts +7 -0
- package/dist/commands/api.d.ts.map +1 -0
- package/dist/commands/api.js +49 -0
- package/dist/commands/api.js.map +1 -0
- package/dist/commands/comments.d.ts +3 -0
- package/dist/commands/comments.d.ts.map +1 -0
- package/dist/commands/comments.js +114 -0
- package/dist/commands/comments.js.map +1 -0
- package/dist/commands/doctor.d.ts +7 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +53 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/session.d.ts +7 -0
- package/dist/commands/session.d.ts.map +1 -0
- package/dist/commands/session.js +26 -0
- package/dist/commands/session.js.map +1 -0
- package/dist/config.d.ts +24 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +75 -0
- package/dist/config.js.map +1 -0
- package/dist/context.d.ts +59 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +75 -0
- package/dist/context.js.map +1 -0
- package/dist/generated/definitions.d.ts +3 -0
- package/dist/generated/definitions.d.ts.map +1 -0
- package/dist/generated/definitions.js +8596 -0
- package/dist/generated/definitions.js.map +1 -0
- package/dist/generated/emoji.d.ts +2 -0
- package/dist/generated/emoji.d.ts.map +1 -0
- package/dist/generated/emoji.js +4265 -0
- package/dist/generated/emoji.js.map +1 -0
- package/dist/generated/manifest.d.ts +6 -0
- package/dist/generated/manifest.d.ts.map +1 -0
- package/dist/generated/manifest.js +6139 -0
- package/dist/generated/manifest.js.map +1 -0
- package/dist/generated/schemas.d.ts +631 -0
- package/dist/generated/schemas.d.ts.map +1 -0
- package/dist/generated/schemas.js +2426 -0
- package/dist/generated/schemas.js.map +1 -0
- package/dist/generated/types.d.ts +3220 -0
- package/dist/generated/types.d.ts.map +1 -0
- package/dist/generated/types.js +5 -0
- package/dist/generated/types.js.map +1 -0
- package/dist/identity.d.ts +29 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +32 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/messenger.d.ts +12 -0
- package/dist/messenger.d.ts.map +1 -0
- package/dist/messenger.js +184 -0
- package/dist/messenger.js.map +1 -0
- package/dist/program.d.ts +6 -0
- package/dist/program.d.ts.map +1 -0
- package/dist/program.js +116 -0
- package/dist/program.js.map +1 -0
- package/dist/reasons.d.ts +7 -0
- package/dist/reasons.d.ts.map +1 -0
- package/dist/reasons.js +20 -0
- package/dist/reasons.js.map +1 -0
- package/dist/sample/comments.d.ts +61 -0
- package/dist/sample/comments.d.ts.map +1 -0
- package/dist/sample/comments.js +39 -0
- package/dist/sample/comments.js.map +1 -0
- package/dist/sample/records.d.ts +16 -0
- package/dist/sample/records.d.ts.map +1 -0
- package/dist/sample/records.js +22 -0
- package/dist/sample/records.js.map +1 -0
- package/dist/sample/transport.d.ts +42 -0
- package/dist/sample/transport.d.ts.map +1 -0
- package/dist/sample/transport.js +153 -0
- package/dist/sample/transport.js.map +1 -0
- package/dist/setup/flow.d.ts +2 -0
- package/dist/setup/flow.d.ts.map +1 -0
- package/dist/setup/flow.js +83 -0
- package/dist/setup/flow.js.map +1 -0
- package/dist/setup/guide.d.ts +6 -0
- package/dist/setup/guide.d.ts.map +1 -0
- package/dist/setup/guide.js +13 -0
- package/dist/setup/guide.js.map +1 -0
- package/dist/setup/texts.d.ts +24 -0
- package/dist/setup/texts.d.ts.map +1 -0
- package/dist/setup/texts.js +24 -0
- package/dist/setup/texts.js.map +1 -0
- package/dist/slack/adapter.d.ts +36 -0
- package/dist/slack/adapter.d.ts.map +1 -0
- package/dist/slack/adapter.js +551 -0
- package/dist/slack/adapter.js.map +1 -0
- package/dist/slack/app-manifest.d.ts +25 -0
- package/dist/slack/app-manifest.d.ts.map +1 -0
- package/dist/slack/app-manifest.js +51 -0
- package/dist/slack/app-manifest.js.map +1 -0
- package/dist/slack/client.d.ts +45 -0
- package/dist/slack/client.d.ts.map +1 -0
- package/dist/slack/client.js +236 -0
- package/dist/slack/client.js.map +1 -0
- package/dist/slack/map.d.ts +429 -0
- package/dist/slack/map.d.ts.map +1 -0
- package/dist/slack/map.js +406 -0
- package/dist/slack/map.js.map +1 -0
- package/dist/slack/mrkdwn.d.ts +9 -0
- package/dist/slack/mrkdwn.d.ts.map +1 -0
- package/dist/slack/mrkdwn.js +56 -0
- package/dist/slack/mrkdwn.js.map +1 -0
- package/dist/slack/search.d.ts +24 -0
- package/dist/slack/search.d.ts.map +1 -0
- package/dist/slack/search.js +99 -0
- package/dist/slack/search.js.map +1 -0
- package/dist/slack/threads.d.ts +28 -0
- package/dist/slack/threads.d.ts.map +1 -0
- package/dist/slack/threads.js +56 -0
- package/dist/slack/threads.js.map +1 -0
- package/dist/slack/tokens.d.ts +17 -0
- package/dist/slack/tokens.d.ts.map +1 -0
- package/dist/slack/tokens.js +27 -0
- package/dist/slack/tokens.js.map +1 -0
- package/dist/slack/writes.d.ts +43 -0
- package/dist/slack/writes.d.ts.map +1 -0
- package/dist/slack/writes.js +277 -0
- package/dist/slack/writes.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +2 -0
- package/dist/version.js.map +1 -0
- package/dist/wcat.d.ts +3 -0
- package/dist/wcat.d.ts.map +1 -0
- package/dist/wcat.js +4 -0
- package/dist/wcat.js.map +1 -0
- package/package.json +89 -4
- package/skills/slack-cli/SKILL.md +117 -0
- package/skills/slack-cli/references/api/api-admin.md +541 -0
- package/skills/slack-cli/references/api/api-api.md +13 -0
- package/skills/slack-cli/references/api/api-apps.md +78 -0
- package/skills/slack-cli/references/api/api-auth.md +18 -0
- package/skills/slack-cli/references/api/api-bots.md +12 -0
- package/skills/slack-cli/references/api/api-calls.md +68 -0
- package/skills/slack-cli/references/api/api-chat.md +123 -0
- package/skills/slack-cli/references/api/api-conversations.md +230 -0
- package/skills/slack-cli/references/api/api-dialog.md +13 -0
- package/skills/slack-cli/references/api/api-dnd.md +31 -0
- package/skills/slack-cli/references/api/api-emoji.md +8 -0
- package/skills/slack-cli/references/api/api-files.md +120 -0
- package/skills/slack-cli/references/api/api-migration.md +14 -0
- package/skills/slack-cli/references/api/api-pins.md +37 -0
- package/skills/slack-cli/references/api/api-reactions.md +58 -0
- package/skills/slack-cli/references/api/api-reminders.md +51 -0
- package/skills/slack-cli/references/api/api-search.md +18 -0
- package/skills/slack-cli/references/api/api-stars.md +42 -0
- package/skills/slack-cli/references/api/api-team.md +55 -0
- package/skills/slack-cli/references/api/api-usergroups.md +80 -0
- package/skills/slack-cli/references/api/api-users.md +101 -0
- package/skills/slack-cli/references/api/api-views.md +46 -0
- package/skills/slack-cli/references/api/api-workflows.md +36 -0
- package/skills/slack-cli/references/api.md +35 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { apiCommandPath } from "@wirecat/cli-base/codegen";
|
|
3
|
+
import { retrying } from "@wirecat/cli-base/http";
|
|
4
|
+
import { environmentOf, hostsFetch, serviceApiCommand } from "@wirecat/cli-core/cli";
|
|
5
|
+
import { API, configuration } from "../config.js";
|
|
6
|
+
import { contextOf, pacerFor, tokenOf } from "../context.js";
|
|
7
|
+
import { DESKTOP, IDENTITY } from "../identity.js";
|
|
8
|
+
import { refusalOf } from "../slack/client.js";
|
|
9
|
+
// Slack is RPC: a GET can send or publish (`views.publish`), so only an operation the manifest calls a read may be sent
|
|
10
|
+
// again after a 5xx or a lost answer; a write is sent once (WC-OUT-20).
|
|
11
|
+
const READS = new Set(API.manifest.operations.flatMap(({ effect, binding }) => effect === "read" && binding.kind === "http" ? [`${binding.method} ${binding.path}`] : []));
|
|
12
|
+
export const isRead = (method, url) => READS.has(`${method} ${url.pathname.slice(url.pathname.lastIndexOf("/"))}`);
|
|
13
|
+
/** The service's hosts and nothing else (WC-CMD-32), over the test's fake when it gives one. */
|
|
14
|
+
export const serviceFetch = (environment) => hostsFetch(DESKTOP.hosts, environment.fetch);
|
|
15
|
+
/**
|
|
16
|
+
* The service's raw API from its spec, `api list`, `api show` and one command per operation, through cli-core's shared
|
|
17
|
+
* group. The manifest gives the server, the sign-in header, the paging of `--all` and the keys: each write asks or
|
|
18
|
+
* refuses by `api.<operation>`, a delete or a share also by its key. The requests keep the profile's pace.
|
|
19
|
+
* The token is the profile's own, read by `tokenOf` like every other command's.
|
|
20
|
+
*/
|
|
21
|
+
const DESTRUCTIVE = new Set(API.manifest.operations.flatMap((operation) => operation.effect === "destructive" ? [apiCommandPath(operation).join(" ")] : []));
|
|
22
|
+
const pathUnder = (group, action) => {
|
|
23
|
+
const words = [];
|
|
24
|
+
for (let at = action; at && at !== group; at = at.parent)
|
|
25
|
+
words.unshift(at.name());
|
|
26
|
+
return words.join(" ");
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* An agent never runs a raw delete: `chat delete` removes a message for everyone, and the rest cannot be undone
|
|
30
|
+
* either (WC-PERM-11). The owner still can, on the command line.
|
|
31
|
+
*/
|
|
32
|
+
const ownerDeletesOnly = (group) => group.hook("preAction", (_, action) => {
|
|
33
|
+
const path = pathUnder(group, action);
|
|
34
|
+
if (environmentOf(action).agent && DESTRUCTIVE.has(path))
|
|
35
|
+
throw new CliError("permission_error", `an agent never runs \`api ${path}\`; the owner can, on the command line`, {
|
|
36
|
+
sent: false,
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
export const apiCommand = () => ownerDeletesOnly(serviceApiCommand({
|
|
40
|
+
...API,
|
|
41
|
+
app: IDENTITY,
|
|
42
|
+
configuration,
|
|
43
|
+
fetch: (command) => retrying(serviceFetch(contextOf(command).environment), { reads: isRead, pacer: pacerFor(command) }),
|
|
44
|
+
token: tokenOf,
|
|
45
|
+
failedAnswer: (answer, operation) => refusalOf(answer, operation.effect !== "read"),
|
|
46
|
+
schemas: () => import("../generated/schemas.js").then((module) => module.schemas),
|
|
47
|
+
definitions: () => import("../generated/definitions.js").then((module) => module.definitions),
|
|
48
|
+
}));
|
|
49
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/commands/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AACjD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AAEpF,OAAO,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AACjD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAA2B,OAAO,EAAE,MAAM,eAAe,CAAA;AACrF,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAE9C,wHAAwH;AACxH,wEAAwE;AACxE,MAAM,KAAK,GAAG,IAAI,GAAG,CACnB,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,CACtD,MAAM,KAAK,MAAM,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAC1F,CACF,CAAA;AACD,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,MAAc,EAAE,GAAQ,EAAE,EAAE,CACjD,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM,IAAI,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CA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,MAAM,CAAC,MAAM,UAAU,GAAG,GAAY,EAAE,CACtC,gBAAgB,CACd,iBAAiB,CAAC;IAChB,GAAG,GAAG;IACN,GAAG,EAAE,QAAQ;IACb,aAAa;IACb,KAAK,EAAE,CAAC,OAAO,EAAE,EAAE,CACjB,QAAQ,CAAC,YAAY,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;IACrG,KAAK,EAAE,OAAO;IACd,YAAY,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,KAAK,MAAM,CAAC;IACnF,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,yBAAyB,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC;IACjF,WAAW,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,6BAA6B,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC;CAC9F,CAAC,CACH,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comments.d.ts","sourceRoot":"","sources":["../../src/commands/comments.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AA6InC,eAAO,MAAM,eAAe,QAAO,OAMH,CAAA"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { annotate } from "@wirecat/cli-base/commands";
|
|
3
|
+
import { answerEntity, commandPath, itemOf, outputFor, pagedList, pageOf, queryTerms, REMOTE_READ, REMOTE_WRITE, renderAnswer, termField, terminalAsker, withPaging, withQuery, } from "@wirecat/cli-core/cli";
|
|
4
|
+
import { guardedWrite, guardFor, keyedGuard, levelFor, newOperationId } from "@wirecat/cli-core/sends";
|
|
5
|
+
import { Command } from "commander";
|
|
6
|
+
import { permissions } from "../config.js";
|
|
7
|
+
import { contextOf, withService } from "../context.js";
|
|
8
|
+
import { IDENTITY } from "../identity.js";
|
|
9
|
+
import { commentSchema } from "../sample/comments.js";
|
|
10
|
+
import { SERVICE } from "../sample/transport.js";
|
|
11
|
+
// SAMPLE: `comments` is the reference command group. Keep its shape; replace the noun and the calls with your
|
|
12
|
+
// service's. Every command path is its own permission key (`comments.create`), from `commandPermissions()`.
|
|
13
|
+
const CLI = IDENTITY.command;
|
|
14
|
+
/** The list's query: one field the service filters itself (WC-CMD-20). Nothing is filtered in memory. */
|
|
15
|
+
const COMMENTS_QUERY = {
|
|
16
|
+
entity: "comment",
|
|
17
|
+
backend: "native",
|
|
18
|
+
fields: [termField("author", "kw", "author:u2")],
|
|
19
|
+
};
|
|
20
|
+
/** --all walks pages until the service has no more, at most this many, so a huge account cannot hold the run open. */
|
|
21
|
+
const ALL_PAGES = 20;
|
|
22
|
+
const ALL_PAGE_SIZE = 100;
|
|
23
|
+
const listAll = async (service, author) => {
|
|
24
|
+
const items = [];
|
|
25
|
+
for (let page = 0; page < ALL_PAGES; page++) {
|
|
26
|
+
const found = await service.list({ limit: ALL_PAGE_SIZE, offset: page * ALL_PAGE_SIZE, author });
|
|
27
|
+
for (const item of found.items)
|
|
28
|
+
items.push(item);
|
|
29
|
+
if (!found.hasMore)
|
|
30
|
+
return { items, hasMore: false };
|
|
31
|
+
}
|
|
32
|
+
return { items, hasMore: true };
|
|
33
|
+
};
|
|
34
|
+
const listCommand = () => withPaging(withQuery(answerEntity(annotate(new Command("list"), {
|
|
35
|
+
effects: REMOTE_READ,
|
|
36
|
+
offline: false,
|
|
37
|
+
examples: [`${CLI} personal comments list`, `${CLI} personal comments list author:u2 --json=id,text`],
|
|
38
|
+
}), "comment", commentSchema), COMMENTS_QUERY))
|
|
39
|
+
.description(`list the comments in ${SERVICE}, newest first`)
|
|
40
|
+
.action(async function (words) {
|
|
41
|
+
const path = commandPath(this);
|
|
42
|
+
const author = queryTerms(words, COMMENTS_QUERY, path).get("author");
|
|
43
|
+
const { settings } = contextOf(this);
|
|
44
|
+
const found = await withService(this, (service) => settings.all ? listAll(service, author) : service.list({ ...pageOf(settings), author }));
|
|
45
|
+
renderAnswer(this, outputFor(this), pagedList(path, settings, found));
|
|
46
|
+
});
|
|
47
|
+
const showCommand = () => answerEntity(annotate(new Command("show"), {
|
|
48
|
+
effects: REMOTE_READ,
|
|
49
|
+
offline: false,
|
|
50
|
+
examples: [`${CLI} personal comments show c1`, `${CLI} personal comments show c1 --json`],
|
|
51
|
+
}), "comment", commentSchema)
|
|
52
|
+
.description(`show one comment in ${SERVICE}`)
|
|
53
|
+
.argument("<id>", "the comment's id, as list prints it")
|
|
54
|
+
.action(async function (id) {
|
|
55
|
+
renderAnswer(this, outputFor(this), itemOf(await withService(this, (service) => service.show(id))));
|
|
56
|
+
});
|
|
57
|
+
/**
|
|
58
|
+
* Every write's one path (WC-PERM-13). The profile's level for the command's key refuses, or asks once; the send
|
|
59
|
+
* journal records the attempt and its outcome, never its content (WC-PERM-17); the answer carries the `operation_id`
|
|
60
|
+
* (WC-OUT-10). cli-core's `run` has already answered `--dry-run` and refused under `<PREFIX>_READ_ONLY` before this
|
|
61
|
+
* runs. Never retried: a write that got no answer is `outcome_unknown`, with the id to look it up by (WC-LIFE-9).
|
|
62
|
+
*/
|
|
63
|
+
const write = async (command, act) => {
|
|
64
|
+
const { settings, env, renderer } = contextOf(command);
|
|
65
|
+
const key = commandPath(command).replaceAll(" ", ".");
|
|
66
|
+
const operationId = newOperationId();
|
|
67
|
+
const levelOf = (one) => levelFor(settings.permissions, one, permissions.defaults).level;
|
|
68
|
+
const guard = keyedGuard((ask) => guardFor(IDENTITY,
|
|
69
|
+
// SAMPLE: the service limits its own rate, so this guard keeps the levels and the journal, not a send cap.
|
|
70
|
+
{ ...settings, sendsPerHour: Number.MAX_SAFE_INTEGER, permissionDefaults: permissions.defaults }, renderer.warn, env, ask), terminalAsker(command), levelOf, []);
|
|
71
|
+
const request = { chatId: null, kind: "edit", key, operationId };
|
|
72
|
+
guard.refuse(request);
|
|
73
|
+
let comment;
|
|
74
|
+
try {
|
|
75
|
+
comment = await guardedWrite(guard, request, () => withService(command, act));
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
if (error instanceof CliError && error.code === "outcome_unknown")
|
|
79
|
+
throw new CliError("outcome_unknown", error.message, { ...error.details, operation_id: operationId });
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
renderAnswer(command, outputFor(command), itemOf({ operation_id: operationId, comment }));
|
|
83
|
+
};
|
|
84
|
+
const createCommand = () => annotate(new Command("create"), {
|
|
85
|
+
effects: REMOTE_WRITE,
|
|
86
|
+
offline: false,
|
|
87
|
+
examples: [
|
|
88
|
+
`${CLI} personal comments create --text "Looks good to me"`,
|
|
89
|
+
`${CLI} personal comments create --text "Looks good to me" --dry-run`,
|
|
90
|
+
],
|
|
91
|
+
})
|
|
92
|
+
.description(`post a comment in ${SERVICE}`)
|
|
93
|
+
.requiredOption("--text <text>", "the comment's text")
|
|
94
|
+
.action(async function (args) {
|
|
95
|
+
await write(this, (service) => service.create(args.text));
|
|
96
|
+
});
|
|
97
|
+
const updateCommand = () => annotate(new Command("update"), {
|
|
98
|
+
effects: REMOTE_WRITE,
|
|
99
|
+
offline: false,
|
|
100
|
+
examples: [`${CLI} personal comments update c1 --text "Looks good now"`],
|
|
101
|
+
})
|
|
102
|
+
.description(`change the text of your comment in ${SERVICE}`)
|
|
103
|
+
.argument("<id>", "the comment's id, as list prints it")
|
|
104
|
+
.requiredOption("--text <text>", "the new text")
|
|
105
|
+
.action(async function (id, args) {
|
|
106
|
+
await write(this, (service) => service.update(id, args.text));
|
|
107
|
+
});
|
|
108
|
+
export const commentsCommand = () => annotate(new Command("comments"), { effects: REMOTE_READ })
|
|
109
|
+
.description(`read and write comments in ${SERVICE}, the sample service`)
|
|
110
|
+
.addCommand(listCommand())
|
|
111
|
+
.addCommand(showCommand())
|
|
112
|
+
.addCommand(createCommand())
|
|
113
|
+
.addCommand(updateCommand());
|
|
114
|
+
//# sourceMappingURL=comments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comments.js","sourceRoot":"","sources":["../../src/commands/comments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AACrD,OAAO,EACL,YAAY,EACZ,WAAW,EACX,MAAM,EACN,SAAS,EACT,SAAS,EACT,MAAM,EACN,UAAU,EACV,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,aAAa,EACb,UAAU,EACV,SAAS,GACV,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACtG,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAsC,aAAa,EAAE,MAAM,uBAAuB,CAAA;AACzF,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAEhD,8GAA8G;AAC9G,4GAA4G;AAE5G,MAAM,GAAG,GAAG,QAAQ,CAAC,OAAO,CAAA;AAE5B,yGAAyG;AACzG,MAAM,cAAc,GAAG;IACrB,MAAM,EAAE,SAAS;IACjB,OAAO,EAAE,QAAQ;IACjB,MAAM,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;CACx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IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;AAC/D,CAAC,CAAC,CAAA;AAEN,MAAM,CAAC,MAAM,eAAe,GAAG,GAAY,EAAE,CAC3C,QAAQ,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;KACxD,WAAW,CAAC,8BAA8B,OAAO,sBAAsB,CAAC;KACxE,UAAU,CAAC,WAAW,EAAE,CAAC;KACzB,UAAU,CAAC,WAAW,EAAE,CAAC;KACzB,UAAU,CAAC,aAAa,EAAE,CAAC;KAC3B,UAAU,CAAC,aAAa,EAAE,CAAC,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Command } from "commander";
|
|
2
|
+
/**
|
|
3
|
+
* cli-core's doctor; `--online` also asks Slack whose each saved token is. Its `online` hook gets no command, so the
|
|
4
|
+
* one being run is kept for it, with the test's keyring and fake in its environment.
|
|
5
|
+
*/
|
|
6
|
+
export declare const doctorCommand: () => Command;
|
|
7
|
+
//# sourceMappingURL=doctor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doctor.d.ts","sourceRoot":"","sources":["../../src/commands/doctor.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAwCxC;;;GAGG;AACH,eAAO,MAAM,aAAa,QAAO,OAQhC,CAAA"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { isCliError } from "@wirecat/cli-base";
|
|
2
|
+
import { appDoctorCommand, environmentOf, ProfileTokenStore, profilesHere, } from "@wirecat/cli-core/cli";
|
|
3
|
+
import { Pacer, pacePathFor } from "@wirecat/cli-core/sends";
|
|
4
|
+
import { configuration } from "../config.js";
|
|
5
|
+
import { PACE } from "../context.js";
|
|
6
|
+
import { IDENTITY, PACKAGE } from "../identity.js";
|
|
7
|
+
import { slackClient } from "../slack/client.js";
|
|
8
|
+
import { whoAmI } from "./session.js";
|
|
9
|
+
/** `auth.test` for every profile signed in here, each under its own name; doctor picks no profile. */
|
|
10
|
+
const checkProfiles = async (command) => {
|
|
11
|
+
const environment = environmentOf(command);
|
|
12
|
+
const env = environment.env ?? process.env;
|
|
13
|
+
// biome-ignore lint/plugin/no-own-settings: doctor names no profile, so there is no baseContext to ask
|
|
14
|
+
const { configuredProfiles } = configuration.resolveSettings({}, { env, needsProfile: false });
|
|
15
|
+
const tokens = new ProfileTokenStore({
|
|
16
|
+
app: IDENTITY,
|
|
17
|
+
env,
|
|
18
|
+
...(environment.keyring ? { keyring: environment.keyring } : {}),
|
|
19
|
+
});
|
|
20
|
+
const signedIn = profilesHere(IDENTITY, configuredProfiles, env).flatMap((profile) => {
|
|
21
|
+
const saved = tokens.read(profile);
|
|
22
|
+
return saved ? [{ profile, token: saved.secret }] : [];
|
|
23
|
+
});
|
|
24
|
+
const profiles = await Promise.all(signedIn.map(async ({ profile, token }) => {
|
|
25
|
+
const slack = slackClient({
|
|
26
|
+
token,
|
|
27
|
+
fetch: environment.fetch,
|
|
28
|
+
signal: environment.signal,
|
|
29
|
+
pacer: new Pacer(pacePathFor(IDENTITY, profile, env), PACE),
|
|
30
|
+
});
|
|
31
|
+
try {
|
|
32
|
+
return { profile, ok: true, ...(await whoAmI(slack)).account };
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
return { profile, ok: false, error_code: isCliError(error) ? error.code : "provider_error" };
|
|
36
|
+
}
|
|
37
|
+
}));
|
|
38
|
+
return { ok: profiles.every((one) => one.ok), profiles };
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* cli-core's doctor; `--online` also asks Slack whose each saved token is. Its `online` hook gets no command, so the
|
|
42
|
+
* one being run is kept for it, with the test's keyring and fake in its environment.
|
|
43
|
+
*/
|
|
44
|
+
export const doctorCommand = () => {
|
|
45
|
+
let running;
|
|
46
|
+
return appDoctorCommand(IDENTITY, configuration, {
|
|
47
|
+
packageName: PACKAGE,
|
|
48
|
+
online: () => checkProfiles(running),
|
|
49
|
+
}).hook("preAction", (_, action) => {
|
|
50
|
+
running = action;
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=doctor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doctor.js","sourceRoot":"","sources":["../../src/commands/doctor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,iBAAiB,EACjB,YAAY,GAEb,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAE5D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,EAAE,IAAI,EAA2B,MAAM,eAAe,CAAA;AAC7D,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAErC,sGAAsG;AACtG,MAAM,aAAa,GAAG,KAAK,EAAE,OAAgB,EAAE,EAAE;IAC/C,MAAM,WAAW,GAAG,aAAa,CAAkC,OAAO,CAAC,CAAA;IAC3E,MAAM,GAAG,GAAG,WAAW,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAA;IAC1C,uGAAuG;IACvG,MAAM,EAAE,kBAAkB,EAAE,GAAG,aAAa,CAAC,eAAe,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,CAAA;IAC9F,MAAM,MAAM,GAAG,IAAI,iBAAiB,CAAC;QACnC,GAAG,EAAE,QAAQ;QACb,GAAG;QACH,GAAG,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,OAAO,EAAE,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CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAA;AAC1D,CAAC,CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,GAAY,EAAE;IACzC,IAAI,OAAgB,CAAA;IACpB,OAAO,gBAAgB,CAAC,QAAQ,EAAE,aAAa,EAAE;QAC/C,WAAW,EAAE,OAAO;QACpB,MAAM,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC;KACrC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE;QACjC,OAAO,GAAG,MAAM,CAAA;IAClB,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `session start | status | end | list` (WC-ACCT-12) through cli-core's token session: the token is read hidden or
|
|
3
|
+
* from stdin, never as an argument, checked with `auth.test`, and only then kept in the keyring through
|
|
4
|
+
* `ProfileTokenStore`.
|
|
5
|
+
*/
|
|
6
|
+
export declare const sessionCommand: () => import("commander").Command;
|
|
7
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/commands/session.ts"],"names":[],"mappings":"AAOA;;;;GAIG;AACH,eAAO,MAAM,cAAc,mCAevB,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { tokenSessionCommand } from "@wirecat/cli-core/cli";
|
|
2
|
+
import { configuration } from "../config.js";
|
|
3
|
+
import { slackFor } from "../context.js";
|
|
4
|
+
import { IDENTITY, SERVICE } from "../identity.js";
|
|
5
|
+
import { TOKEN_GUIDE } from "../setup/guide.js";
|
|
6
|
+
import { refuseOtherTokens, whoAmI } from "../slack/tokens.js";
|
|
7
|
+
/**
|
|
8
|
+
* `session start | status | end | list` (WC-ACCT-12) through cli-core's token session: the token is read hidden or
|
|
9
|
+
* from stdin, never as an argument, checked with `auth.test`, and only then kept in the keyring through
|
|
10
|
+
* `ProfileTokenStore`.
|
|
11
|
+
*/
|
|
12
|
+
export const sessionCommand = () => tokenSessionCommand({
|
|
13
|
+
app: IDENTITY,
|
|
14
|
+
service: SERVICE,
|
|
15
|
+
resolveSettings: configuration.resolveSettings,
|
|
16
|
+
token: "User OAuth Token (xoxp-…)",
|
|
17
|
+
about: "Paste the User OAuth Token (xoxp-…) of your own Slack app, made from docs/slack-app-manifest.json; " +
|
|
18
|
+
"a bot token is refused",
|
|
19
|
+
guide: TOKEN_GUIDE,
|
|
20
|
+
endNote: "The app stays installed in the workspace; remove it there to revoke the token",
|
|
21
|
+
verify: async (command, token, events) => {
|
|
22
|
+
refuseOtherTokens(token);
|
|
23
|
+
return whoAmI(slackFor(command, token, events));
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/commands/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAE9D;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,EAAE,CACjC,mBAAmB,CAAC;IAClB,GAAG,EAAE,QAAQ;IACb,OAAO,EAAE,OAAO;IAChB,eAAe,EAAE,aAAa,CAAC,eAAe;IAC9C,KAAK,EAAE,2BAA2B;IAClC,KAAK,EACH,qGAAqG;QACrG,wBAAwB;IAC1B,KAAK,EAAE,WAAW;IAClB,OAAO,EAAE,+EAA+E;IACxF,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;QACvC,iBAAiB,CAAC,KAAK,CAAC,CAAA;QACxB,OAAO,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAA;IACjD,CAAC;CACF,CAAC,CAAA"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type Configuration } from "@wirecat/cli-core/cli";
|
|
2
|
+
export declare const API: {
|
|
3
|
+
manifest: {
|
|
4
|
+
servers: readonly import("@wirecat/cli-base/codegen").ApiServer[];
|
|
5
|
+
securitySchemes: Readonly<Record<string, import("@wirecat/cli-base/codegen").SecurityScheme>>;
|
|
6
|
+
security: readonly import("@wirecat/cli-base/codegen").SecurityRequirement[];
|
|
7
|
+
operations: readonly import("@wirecat/cli-base/codegen").ManifestOperation[];
|
|
8
|
+
};
|
|
9
|
+
service: string;
|
|
10
|
+
excluded: readonly {
|
|
11
|
+
id: string;
|
|
12
|
+
reason: string;
|
|
13
|
+
}[];
|
|
14
|
+
};
|
|
15
|
+
export declare const permissions: import("@wirecat/cli-core/cli").CommandPermissions;
|
|
16
|
+
/** How many days back `messages sync` looks for threads with new replies (plan.md, "Sync and threads"). */
|
|
17
|
+
export declare const THREAD_WINDOW_DAYS = 14;
|
|
18
|
+
export interface SlackSettings {
|
|
19
|
+
threadWindowDays: number;
|
|
20
|
+
inboxChannels: string[];
|
|
21
|
+
inboxAllChannels: boolean;
|
|
22
|
+
}
|
|
23
|
+
export declare const configuration: Configuration;
|
|
24
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAKnB,MAAM,uBAAuB,CAAA;AAW9B,eAAO,MAAM,GAAG;;;;;;;;;;;;CAIf,CAAA;AAMD,eAAO,MAAM,WAAW,oDAGtB,CAAA;AAEF,2GAA2G;AAC3G,eAAO,MAAM,kBAAkB,KAAK,CAAA;AAEpC,MAAM,WAAW,aAAa;IAC5B,gBAAgB,EAAE,MAAM,CAAA;IACxB,aAAa,EAAE,MAAM,EAAE,CAAA;IACvB,gBAAgB,EAAE,OAAO,CAAA;CAC1B;AASD,eAAO,MAAM,aAAa,EAAE,aAgD1B,CAAA"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { commandPermissions, serviceApiOperations, serviceApiPermissions, settingsFor, } from "@wirecat/cli-core/cli";
|
|
2
|
+
import { levelFor } from "@wirecat/cli-core/sends";
|
|
3
|
+
import * as v from "valibot";
|
|
4
|
+
import * as manifest from "./generated/manifest.js";
|
|
5
|
+
import { IDENTITY, SERVICE } from "./identity.js";
|
|
6
|
+
/** Each command is checked against its own path (`notes.list`); add the keys a command checks inside itself. */
|
|
7
|
+
// The keys a delete or a share checks come from `permissions` in scripts/generate.ts. Left out: an operation that
|
|
8
|
+
// answers with a credential (the CLI signs in through `session`) and a body cli-core cannot send (a form).
|
|
9
|
+
const { offered, left } = serviceApiOperations(manifest);
|
|
10
|
+
export const API = {
|
|
11
|
+
manifest: { ...manifest, operations: offered },
|
|
12
|
+
service: SERVICE,
|
|
13
|
+
excluded: left,
|
|
14
|
+
};
|
|
15
|
+
const apiPermissions = serviceApiPermissions(API);
|
|
16
|
+
// cli-core asks for every key an api operation names; a read of what people wrote is checked as `messages.list` and is
|
|
17
|
+
// no stricter than `messages list` (WC-PERM-4). A write keeps the ask: the api group has no recipient list or pace.
|
|
18
|
+
export const permissions = commandPermissions({
|
|
19
|
+
...apiPermissions,
|
|
20
|
+
defaults: { ...apiPermissions.defaults, "messages.list": levelFor({}, "messages.list").level },
|
|
21
|
+
});
|
|
22
|
+
/** How many days back `messages sync` looks for threads with new replies (plan.md, "Sync and threads"). */
|
|
23
|
+
export const THREAD_WINDOW_DAYS = 14;
|
|
24
|
+
const threadWindowDays = v.optional(v.pipe(v.number("has to be a number of days"), v.integer(), v.minValue(1), v.maxValue(365)));
|
|
25
|
+
const inboxChannels = v.optional(v.string("has to be channel names or ids, comma-separated: #general, #dev"));
|
|
26
|
+
const inboxAllChannels = v.optional(v.boolean("has to be true or false"));
|
|
27
|
+
export const configuration = settingsFor(IDENTITY, {
|
|
28
|
+
permissions,
|
|
29
|
+
personal: {
|
|
30
|
+
thread_window_days: threadWindowDays,
|
|
31
|
+
inbox_channels: inboxChannels,
|
|
32
|
+
inbox_all_channels: inboxAllChannels,
|
|
33
|
+
},
|
|
34
|
+
// The channels are a workspace's, so they are set per profile only.
|
|
35
|
+
defaults: { thread_window_days: threadWindowDays },
|
|
36
|
+
settings: [
|
|
37
|
+
{
|
|
38
|
+
key: "thread_window_days",
|
|
39
|
+
default: THREAD_WINDOW_DAYS,
|
|
40
|
+
description: "how many days back messages sync looks for threads with new replies",
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
key: "inbox_channels",
|
|
44
|
+
default: "",
|
|
45
|
+
description: "the channels inbox counts every unread message of, comma-separated names or ids (#general, #dev); DMs are " +
|
|
46
|
+
"always counted",
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
key: "inbox_all_channels",
|
|
50
|
+
default: false,
|
|
51
|
+
description: "inbox counts every channel you are in, two calls each, so it may stop before the last ones",
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
resolve: ({ fromLayers }) => {
|
|
55
|
+
const days = fromLayers("thread_window_days", THREAD_WINDOW_DAYS);
|
|
56
|
+
const channels = fromLayers("inbox_channels", "");
|
|
57
|
+
const allChannels = fromLayers("inbox_all_channels", false);
|
|
58
|
+
return {
|
|
59
|
+
values: {
|
|
60
|
+
threadWindowDays: days.value,
|
|
61
|
+
inboxChannels: channels.value
|
|
62
|
+
.split(",")
|
|
63
|
+
.map((one) => one.trim())
|
|
64
|
+
.filter(Boolean),
|
|
65
|
+
inboxAllChannels: allChannels.value,
|
|
66
|
+
},
|
|
67
|
+
sources: {
|
|
68
|
+
thread_window_days: days.from,
|
|
69
|
+
inbox_channels: channels.from,
|
|
70
|
+
inbox_all_channels: allChannels.from,
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,EACrB,WAAW,GACZ,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAClD,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAC5B,OAAO,KAAK,QAAQ,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAEjD,gHAAgH;AAChH,kHAAkH;AAClH,2GAA2G;AAC3G,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,oBAAoB,CAAC,QAAQ,CAAC,CAAA;AAExD,MAAM,CAAC,MAAM,GAAG,GAAG;IACjB,QAAQ,EAAE,EAAE,GAAG,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE;IAC9C,OAAO,EAAE,OAAO;IAChB,QAAQ,EAAE,IAAI;CACf,CAAA;AAED,MAAM,cAAc,GAAG,qBAAqB,CAAC,GAAG,CAAC,CAAA;AAEjD,uHAAuH;AACvH,oHAAoH;AACpH,MAAM,CAAC,MAAM,WAAW,GAAG,kBAAkB,CAAC;IAC5C,GAAG,cAAc;IACjB,QAAQ,EAAE,EAAE,GAAG,cAAc,CAAC,QAAQ,EAAE,eAAe,EAAE,QAAQ,CAAC,EAAE,EAAE,eAAe,CAAC,CAAC,KAA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MAAM,QAAQ,GAAG,UAAU,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAA;QACjD,MAAM,WAAW,GAAG,UAAU,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAAA;QAC3D,OAAO;YACL,MAAM,EAAE;gBACN,gBAAgB,EAAE,IAAI,CAAC,KAAK;gBAC5B,aAAa,EAAE,QAAQ,CAAC,KAAK;qBAC1B,KAAK,CAAC,GAAG,CAAC;qBACV,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;qBACxB,MAAM,CAAC,OAAO,CAAC;gBAClB,gBAAgB,EAAE,WAAW,CAAC,KAAK;aACpC;YACD,OAAO,EAAE;gBACP,kBAAkB,EAAE,IAAI,CAAC,IAAI;gBAC7B,cAAc,EAAE,QAAQ,CAAC,IAAI;gBAC7B,kBAAkB,EAAE,WAAW,CAAC,IAAI;aACrC;SACF,CAAA;IACH,CAAC;CACF,CAAC,CAAA"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type BaseEnvironment, type EventSink, type GlobalFlags, ProfileTokenStore } from "@wirecat/cli-core/cli";
|
|
2
|
+
import { Pacer } from "@wirecat/cli-core/sends";
|
|
3
|
+
import type { Command } from "commander";
|
|
4
|
+
/** What a test hands `run()` beside cli-core's own: the fake service in place of the network (WC-ARCH-10). */
|
|
5
|
+
export interface ServiceEnvironment extends BaseEnvironment {
|
|
6
|
+
fetch?: typeof fetch;
|
|
7
|
+
}
|
|
8
|
+
export declare const PACE: {
|
|
9
|
+
perMinute: number;
|
|
10
|
+
burst: number;
|
|
11
|
+
};
|
|
12
|
+
export declare const TIER_3_PACE: {
|
|
13
|
+
perMinute: number;
|
|
14
|
+
burst: number;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Settings, keyring and the run come from cli-core's `baseContext` and nowhere else: a command that resolves settings
|
|
18
|
+
* on its own skips `--timeout`, the run record and the profile's permissions (WC-LIFE-5, WC-LIFE-15).
|
|
19
|
+
*/
|
|
20
|
+
export declare const contextOf: (command: Command) => {
|
|
21
|
+
settings: import("@wirecat/cli-core/cli").Settings;
|
|
22
|
+
renderer: import("@wirecat/cli-base").Renderer;
|
|
23
|
+
format: import("@wirecat/cli-base").RenderFormat;
|
|
24
|
+
color: boolean;
|
|
25
|
+
streams: import("@wirecat/cli-base").Streams;
|
|
26
|
+
compact?: boolean;
|
|
27
|
+
full?: boolean;
|
|
28
|
+
env: NodeJS.ProcessEnv;
|
|
29
|
+
keyring?: import("@wirecat/cli-base").KeyringStore;
|
|
30
|
+
run: <T>(body: (events: EventSink) => Promise<T>, options?: {
|
|
31
|
+
unbounded?: boolean;
|
|
32
|
+
name?: string;
|
|
33
|
+
}) => Promise<T>;
|
|
34
|
+
track: (closeable: import("@wirecat/cli-core/cli").Closeable) => void;
|
|
35
|
+
environment: ServiceEnvironment;
|
|
36
|
+
flags: GlobalFlags;
|
|
37
|
+
profile: string;
|
|
38
|
+
tokens: ProfileTokenStore;
|
|
39
|
+
};
|
|
40
|
+
/** The profile's pace: Slack's Tier 2, or `requests_per_minute` when set; 0 turns it off for tests. */
|
|
41
|
+
export declare const pacerFor: (command: Command, rate?: {
|
|
42
|
+
perMinute: number;
|
|
43
|
+
burst: number;
|
|
44
|
+
}, suffix?: string) => Pacer;
|
|
45
|
+
/** Slack for one run, with the token it was given and the profile's pace; each call lands in the run's `events`. */
|
|
46
|
+
export declare const slackFor: (command: Command, token: string, events?: EventSink) => (<T>(method: string, args: import("./slack/client.js").SlackArgs, answer: import("valibot").GenericSchema<unknown, T>, { writes, signal: stop }?: {
|
|
47
|
+
writes?: boolean;
|
|
48
|
+
signal?: AbortSignal | undefined;
|
|
49
|
+
}) => Promise<T>) & {
|
|
50
|
+
upload: (address: string, bytes: Uint8Array) => Promise<void>;
|
|
51
|
+
};
|
|
52
|
+
/** Whether the profile's token comes from SLACK_TOKEN, which never went through `session start`. */
|
|
53
|
+
export declare const tokenFromEnvironment: (command: Command) => boolean;
|
|
54
|
+
/**
|
|
55
|
+
* The profile's saved token, or an authentication error that says how to sign in. Read before any request; one from
|
|
56
|
+
* `SLACK_TOKEN` skips `session start`, so it is refused here as there.
|
|
57
|
+
*/
|
|
58
|
+
export declare const tokenOf: (command: Command) => string;
|
|
59
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,eAAe,EAEpB,KAAK,SAAS,EAEd,KAAK,WAAW,EAChB,iBAAiB,EAGlB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,KAAK,EAAe,MAAM,yBAAyB,CAAA;AAC5D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAMxC,8GAA8G;AAC9G,MAAM,WAAW,kBAAmB,SAAQ,eAAe;IACzD,KAAK,CAAC,EAAE,OAAO,KAAK,CAAA;CACrB;AAMD,eAAO,MAAM,IAAI;IAAK,SAAS;IAAM,KAAK;CAAM,CAAA;AAChD,eAAO,MAAM,WAAW;IAAK,SAAS;IAAM,KAAK;CAAM,CAAA;AAEvD;;;GAGG;AACH,eAAO,MAAM,SAAS,YAAa,OAAO;;;;;;;;;;;;;;;;;;;CAczC,CAAA;AAED,uGAAuG;AACvG,eAAO,MAAM,QAAQ,YAAa,OAAO;;;4BAOxC,CAAA;AAED,oHAAoH;AACpH,eAAO,MAAM,QAAQ,YAAa,OAAO,SAAS,MAAM,WAAW,SAAS;;;;;CAU3E,CAAA;AAED,oGAAoG;AACpG,eAAO,MAAM,oBAAoB,YAAa,OAAO,YAGpD,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,OAAO,YAAa,OAAO,KAAG,MAiB1C,CAAA"}
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { CliError, isCliError } from "@wirecat/cli-base";
|
|
2
|
+
import { baseContext, environmentOf, ProfileTokenStore, recalledAccount, refuseOffline, } from "@wirecat/cli-core/cli";
|
|
3
|
+
import { Pacer, pacePathFor } from "@wirecat/cli-core/sends";
|
|
4
|
+
import { configuration } from "./config.js";
|
|
5
|
+
import { IDENTITY, PROVIDER, SERVICE } from "./identity.js";
|
|
6
|
+
import { slackClient } from "./slack/client.js";
|
|
7
|
+
import { refuseOtherTokens } from "./slack/tokens.js";
|
|
8
|
+
// Slack limits each method per workspace by tier (https://docs.slack.dev/apis/web-api/rate-limits/). The paging reads
|
|
9
|
+
// mix Tier 2 (users.list, reactions.list, search.messages: 20 a minute) and Tier 3 (conversations.history, .info,
|
|
10
|
+
// .replies, users.conversations: 50). cli-core's Pacer keeps one pace per file, so the profile has two: Tier 2 for
|
|
11
|
+
// every method, and Tier 3 for those in TIER_3. A 429 holds every process of the profile on that pace.
|
|
12
|
+
export const PACE = { perMinute: 20, burst: 10 };
|
|
13
|
+
export const TIER_3_PACE = { perMinute: 50, burst: 10 };
|
|
14
|
+
/**
|
|
15
|
+
* Settings, keyring and the run come from cli-core's `baseContext` and nowhere else: a command that resolves settings
|
|
16
|
+
* on its own skips `--timeout`, the run record and the profile's permissions (WC-LIFE-5, WC-LIFE-15).
|
|
17
|
+
*/
|
|
18
|
+
export const contextOf = (command) => {
|
|
19
|
+
const base = baseContext(command, configuration.resolveSettings);
|
|
20
|
+
return {
|
|
21
|
+
...base,
|
|
22
|
+
environment: environmentOf(command),
|
|
23
|
+
flags: command.optsWithGlobals(),
|
|
24
|
+
profile: base.settings.profile,
|
|
25
|
+
tokens: new ProfileTokenStore({
|
|
26
|
+
app: IDENTITY,
|
|
27
|
+
env: base.env,
|
|
28
|
+
keyring: base.keyring,
|
|
29
|
+
warn: base.renderer.warn,
|
|
30
|
+
}),
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
/** The profile's pace: Slack's Tier 2, or `requests_per_minute` when set; 0 turns it off for tests. */
|
|
34
|
+
export const pacerFor = (command, rate = PACE, suffix = "") => {
|
|
35
|
+
const { env, profile, settings } = contextOf(command);
|
|
36
|
+
const { requestsPerMinute } = settings;
|
|
37
|
+
return new Pacer(`${pacePathFor(IDENTITY, profile, env)}${suffix}`, requestsPerMinute === undefined ? rate : { ...rate, perMinute: requestsPerMinute });
|
|
38
|
+
};
|
|
39
|
+
/** Slack for one run, with the token it was given and the profile's pace; each call lands in the run's `events`. */
|
|
40
|
+
export const slackFor = (command, token, events) => {
|
|
41
|
+
const { environment } = contextOf(command);
|
|
42
|
+
return slackClient({
|
|
43
|
+
token,
|
|
44
|
+
events,
|
|
45
|
+
signal: environment.signal,
|
|
46
|
+
fetch: environment.fetch,
|
|
47
|
+
pacer: pacerFor(command),
|
|
48
|
+
tier3Pacer: pacerFor(command, TIER_3_PACE, ".tier3"),
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
/** Whether the profile's token comes from SLACK_TOKEN, which never went through `session start`. */
|
|
52
|
+
export const tokenFromEnvironment = (command) => {
|
|
53
|
+
const { profile, tokens } = contextOf(command);
|
|
54
|
+
return tokens.read(profile)?.source === "environment";
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* The profile's saved token, or an authentication error that says how to sign in. Read before any request; one from
|
|
58
|
+
* `SLACK_TOKEN` skips `session start`, so it is refused here as there.
|
|
59
|
+
*/
|
|
60
|
+
export const tokenOf = (command) => {
|
|
61
|
+
const { profile, tokens, env, settings } = contextOf(command);
|
|
62
|
+
refuseOffline(command, SERVICE);
|
|
63
|
+
try {
|
|
64
|
+
return refuseOtherTokens(tokens.need(profile));
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
// A keyring that cannot be read hides whether a profile this computer has never seen is a typo; as not signed in,
|
|
68
|
+
// cli-core names the profiles here (WC-ACCT-3). A known profile keeps the keyring's own error.
|
|
69
|
+
const unseen = !settings.profilesHere.includes(profile) && !recalledAccount(IDENTITY, PROVIDER, profile, env);
|
|
70
|
+
if (isCliError(error) && error.code === "configuration_error" && unseen)
|
|
71
|
+
throw new CliError("authentication_error", `profile ${profile} is not signed in — run \`${IDENTITY.command} ${profile} session start\``, { reason: "session.missing" });
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,EAEL,WAAW,EAEX,aAAa,EAEb,iBAAiB,EACjB,eAAe,EACf,aAAa,GACd,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAE5D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAOrD,sHAAsH;AACtH,kHAAkH;AAClH,mHAAmH;AACnH,uGAAuG;AACvG,MAAM,CAAC,MAAM,IAAI,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CAAA;AAChD,MAAM,CAAC,MAAM,WAAW,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CAAA;AAEvD;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,OAAgB,EAAE,EAAE;IAC5C,MAAM,IAAI,GAAG,WAAW,CAAC,OAAO,EAAE,aAAa,CAAC,eAAe,CAAC,CAAA;IAChE,OAAO;QACL,GAAG,IAAI;QACP,WAAW,EAAE,aAAa,CAAqB,OAAO,CAAC;QACvD,KAAK,EAAE,OAAO,CAAC,eAA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