@fased/fased 0.1.36 → 0.1.38
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/config/capability-catalog.json +241 -0
- package/config/dependency-ownership.json +130 -0
- package/config/official-channel-catalog.json +39 -0
- package/dist/agents/tools/web-fetch-utils.js +2 -1
- package/dist/agents/tools/web-fetch-visibility.js +3 -1
- package/dist/brand.js +1 -1
- package/dist/browser/pw-session.js +2 -1
- package/dist/browser/pw-tools-core.state.js +3 -2
- package/dist/browser/runtime-dependency.js +27 -0
- package/dist/build-info.json +3 -3
- package/dist/canvas-host/a2ui/.bundle.hash +1 -1
- package/dist/capabilities/catalog.js +228 -0
- package/dist/cli/components-cli.js +105 -0
- package/dist/cli/hooks-cli.js +1 -1
- package/dist/cli/plugins-cli.js +3 -3
- package/dist/cli/program/register.subclis.js +9 -0
- package/dist/cli/update-cli/update-command.js +1 -1
- package/dist/commands/doctor-capabilities.js +26 -0
- package/dist/commands/doctor.js +2 -0
- package/dist/control-ui/assets/{app-DXYMrRJ9.js → app-JBrTSsNu.js} +1480 -1465
- package/dist/control-ui/assets/{index-iGQkJE0l.js → index-H-2DWAnH.js} +3 -3
- package/dist/control-ui/index.html +1 -1
- package/dist/gateway/method-scopes.js +1 -0
- package/dist/gateway/server-methods/plugins-marketplace.js +1 -1
- package/dist/gateway/server-methods/services.js +8 -0
- package/dist/gateway/server-methods-list.js +1 -0
- package/dist/infra/optional-runtime-dependency.js +46 -0
- package/dist/media/image-ops.js +6 -1
- package/dist/media/input-files.js +11 -2
- package/dist/media/mime.js +6 -1
- package/dist/memory/sqlite-vec.js +7 -1
- package/dist/plugin-sdk/{accounts-VqAX3HJ0.js → accounts-BwkH5bTD.js} +1 -1
- package/dist/plugin-sdk/{accounts-Zgt0NP54.js → accounts-RT6y7n3H.js} +1 -1
- package/dist/plugin-sdk/{actions-lB3PCwsz.js → actions-BrU_JMqM.js} +2 -2
- package/dist/plugin-sdk/{actions-BI5QViLk.js → actions-CUdVHzeJ.js} +2 -2
- package/dist/plugin-sdk/{active-listener-DKZiSaRA.js → active-listener-CE8t5g6l.js} +1 -1
- package/dist/plugin-sdk/{active-listener-D6_pdTMC.js → active-listener-Dx1SEGDn.js} +1 -1
- package/dist/plugin-sdk/{audio-preflight-Dx8J7XhV.js → audio-preflight-BPK8t0tI.js} +22 -22
- package/dist/plugin-sdk/{audio-preflight-CeRstduc.js → audio-preflight-kCa_KGRH.js} +22 -22
- package/dist/plugin-sdk/{audit-BImNOQvk.js → audit-DxB2Kml5.js} +11 -11
- package/dist/plugin-sdk/{audit-CKWkq0Un.js → audit-sSeRDwJb.js} +11 -11
- package/dist/plugin-sdk/channel-plugin-common.js +3 -2
- package/dist/plugin-sdk/{chunk-skAJZWCT.js → chunk-KCxbJLsV.js} +1 -1
- package/dist/plugin-sdk/{chunk-Cjw4712g.js → chunk-M2d7r-Zt.js} +1 -1
- package/dist/plugin-sdk/{chunk-items-Df5811D0.js → chunk-items-DGHUeFuI.js} +1 -1
- package/dist/plugin-sdk/command-status.js +22 -22
- package/dist/plugin-sdk/{commands-registry-5J619bQ2.js → commands-registry-CdT-nl7v.js} +2 -2
- package/dist/plugin-sdk/{commands-registry-CoLAT03J.js → commands-registry-DoWdYAJd.js} +2 -2
- package/dist/plugin-sdk/{common-CSTxewqY.js → common-Cpw-vuuM.js} +1 -1
- package/dist/plugin-sdk/{common-BiF0sTnY.js → common-DJWrErdE.js} +1 -1
- package/dist/plugin-sdk/{config-BxVjLTIv.js → config-C0qggNKQ.js} +7 -7
- package/dist/plugin-sdk/{config-TFokWwvO.js → config-CgwTaper.js} +45 -2
- package/dist/plugin-sdk/{config-DXlISPlx.js → config-DtqAN2L3.js} +45 -2
- package/dist/plugin-sdk/discord.js +2 -1
- package/dist/plugin-sdk/{fetch-guard-DPMynms8.js → fetch-guard-BLdujDnt.js} +1 -1
- package/dist/plugin-sdk/{fetch-guard-COLmW2TM.js → fetch-guard-DTKgMN9f.js} +1 -1
- package/dist/plugin-sdk/{handle-action-C-UndB8E.js → handle-action-B61D85yo.js} +12 -12
- package/dist/plugin-sdk/{handle-action-hhufKxmU.js → handle-action-CjcxGzQD.js} +12 -12
- package/dist/plugin-sdk/index.js +22 -22
- package/dist/plugin-sdk/{login-DL1oBBfL.js → login-CB_nCjX3.js} +3 -3
- package/dist/plugin-sdk/{login-Dnxas1dI.js → login-CzUuDd1v.js} +3 -3
- package/dist/plugin-sdk/{login-qr-CVQsGWKq.js → login-qr-D7MEpFza.js} +3 -3
- package/dist/plugin-sdk/{login-qr-B343JNXJ.js → login-qr-DgxfBFVN.js} +3 -3
- package/dist/plugin-sdk/{manager-BytwRIfK.js → manager-9see0IX5.js} +8 -3
- package/dist/plugin-sdk/{manager-BZjd_PCt.js → manager-D2kZ0Cps.js} +8 -3
- package/dist/plugin-sdk/{markdown-tables-krKiU4cT.js → markdown-tables-CCSD52rA.js} +1 -1
- package/dist/plugin-sdk/{markdown-tables-9rJDQ1X-.js → markdown-tables-DWUNvLrc.js} +1 -1
- package/dist/plugin-sdk/{media-D7ZkWU-A.js → media-C7YT4DeU.js} +13 -4
- package/dist/plugin-sdk/{media-C6C2c9a4.js → media-Cxw-xLGU.js} +13 -4
- package/dist/plugin-sdk/{monitor-BsLMfn3U.js → monitor-6lkdOqhQ.js} +26 -26
- package/dist/plugin-sdk/{monitor-BCxkQBoh.js → monitor-C6Ohw9BA.js} +26 -26
- package/dist/plugin-sdk/{monitor-BzDW50H6.js → monitor-o20KTHIi.js} +29 -29
- package/dist/plugin-sdk/{monitor-CVQNDfhs.js → monitor-rOs3mUol.js} +27 -27
- package/dist/plugin-sdk/{openresponses-http-BB67Z4QM.js → openresponses-http-BJONnUdy.js} +22 -22
- package/dist/plugin-sdk/{openresponses-http-NE76GGhj.js → openresponses-http-DkWqYznu.js} +22 -22
- package/dist/plugin-sdk/{ssrf-u0Ul7okY.js → optional-runtime-dependency-szS49voX.js} +46 -2
- package/dist/plugin-sdk/{outbound-PGNWU6T-.js → outbound-BCxOxdi-.js} +6 -6
- package/dist/plugin-sdk/{outbound-BHWJD9q0.js → outbound-JIwQbpRY.js} +6 -6
- package/dist/plugin-sdk/{outbound-attachment-BVzfhqnk.js → outbound-attachment-C-jSFaEB.js} +1 -1
- package/dist/plugin-sdk/{outbound-attachment-ClMvNW17.js → outbound-attachment-D6tj5Y5H.js} +1 -1
- package/dist/plugin-sdk/{pi-embedded-runner-DQ6UPx6-.js → pi-embedded-runner-DqDy0MWN.js} +72 -60
- package/dist/plugin-sdk/{pi-model-discovery-D51L5E9I.js → pi-model-discovery-DadlvsZW.js} +1 -1
- package/dist/plugin-sdk/{pi-model-discovery-runtime-DxoFm4Vd.js → pi-model-discovery-runtime-C5ssE6EW.js} +1 -1
- package/dist/plugin-sdk/{pi-model-discovery-runtime-DRuh4PNV.js → pi-model-discovery-runtime-DAaOPt64.js} +2 -2
- package/dist/plugin-sdk/{pi-model-discovery-runtime-BTWgkx4x.js → pi-model-discovery-runtime-gd77b0UF.js} +2 -2
- package/dist/plugin-sdk/{pi-model-discovery-CkH5l9X5.js → pi-model-discovery-yifTIDIn.js} +1 -1
- package/dist/plugin-sdk/{pw-ai-DZs6uYRd.js → pw-ai-Boor5vYw.js} +6 -5
- package/dist/plugin-sdk/{pw-ai-Cn-EUPZK.js → pw-ai-sH1Pi-Fh.js} +6 -5
- package/dist/plugin-sdk/{registry-B4HvWzob.js → registry-DNkJsNsz.js} +4 -3
- package/dist/plugin-sdk/{replies-jDMUBsNO.js → replies-fvzN5wnU.js} +2 -2
- package/dist/plugin-sdk/{replies-B_LW9c9f.js → replies-zebgZCHX.js} +2 -2
- package/dist/plugin-sdk/{resolve-route-_YZHbS-z.js → resolve-route-CNhTJG_2.js} +1 -1
- package/dist/plugin-sdk/{resolve-route-DlHzggnG.js → resolve-route-DO0WR4nB.js} +1 -1
- package/dist/plugin-sdk/{resolve-utils-zBhVX3Vx.js → resolve-utils-bixHYDBj.js} +1 -1
- package/dist/plugin-sdk/{retry-policy-DGLs5ebP.js → retry-policy-BLYEgIwP.js} +1 -1
- package/dist/plugin-sdk/{retry-policy-DaodShGa.js → retry-policy-sM01QZT2.js} +1 -1
- package/dist/plugin-sdk/{runtime-Dd0sswuW.js → runtime-BPyuAmka.js} +4 -3
- package/dist/plugin-sdk/{paths-CBCpJ5bu.js → runtime-dependency-Csswyv5r.js} +27 -3
- package/dist/plugin-sdk/{paths-DW-U2r7Y.js → runtime-dependency-Deg_sw2k.js} +36 -12
- package/dist/plugin-sdk/sat-runtime.js +1 -0
- package/dist/plugin-sdk/{send-8remZhsH.js → send-B09HRfHN.js} +6 -6
- package/dist/plugin-sdk/{send-DaaAscWj.js → send-BBYcgXA4.js} +5 -5
- package/dist/plugin-sdk/{send-DFTB0cnx.js → send-BQXQA81e.js} +6 -6
- package/dist/plugin-sdk/{send-CtMVvMJs.js → send-BzFdvD_i.js} +6 -6
- package/dist/plugin-sdk/{send-Di9irjS-.js → send-C3u-F_8s.js} +6 -6
- package/dist/plugin-sdk/{send-Dl88ZKq2.js → send-D3836_UN.js} +6 -6
- package/dist/plugin-sdk/{send-ifgZCHVB.js → send-D7tr-EsH.js} +5 -5
- package/dist/plugin-sdk/{send-DvUpYh0d.js → send-DRGzRdI3.js} +6 -6
- package/dist/plugin-sdk/{send-D2jlPeKH.js → send-DfkPKz_0.js} +4 -4
- package/dist/plugin-sdk/{send-QSt6nbny.js → send-DsxFXrCO.js} +4 -4
- package/dist/plugin-sdk/{session-CknrceVU.js → session-DG_bYisw.js} +2 -2
- package/dist/plugin-sdk/{session-CyRTcJ8N.js → session-EIStzK0E.js} +2 -2
- package/dist/plugin-sdk/{skill-commands-DHxkTA0s.js → skill-commands-CkgGmWBS.js} +2 -2
- package/dist/plugin-sdk/{skill-commands-CLXAG5sU.js → skill-commands-hyZA0LE3.js} +2 -2
- package/dist/plugin-sdk/{slack-Br9c6Yzs.js → slack-BErIh0uj.js} +34 -34
- package/dist/plugin-sdk/{slack-BpJXkwxF.js → slack-CGTAN4UD.js} +34 -34
- package/dist/plugin-sdk/{slack-actions-8tLGt1Ht.js → slack-actions-BQawWGTJ.js} +11 -11
- package/dist/plugin-sdk/{slack-actions-CDSSRo8Y.js → slack-actions-DDMszx56.js} +11 -11
- package/dist/plugin-sdk/slack.js +2 -1
- package/dist/plugin-sdk/src/brand.d.ts +2 -2
- package/dist/plugin-sdk/src/browser/runtime-dependency.d.ts +3 -0
- package/dist/plugin-sdk/src/infra/optional-runtime-dependency.d.ts +6 -0
- package/dist/plugin-sdk/{ssrf-fG4UHKBw.js → ssrf-Cce6LubA.js} +41 -7
- package/dist/plugin-sdk/{status-DoxnzyMC.js → status-CCGFb0f2.js} +76 -64
- package/dist/plugin-sdk/{sticker-cache-zmJ39ByC.js → sticker-cache-CKAkkCoU.js} +3 -3
- package/dist/plugin-sdk/{sticker-cache-D7WcMYsF.js → sticker-cache-wxl1Me2i.js} +3 -3
- package/dist/plugin-sdk/{tables-CkxblF0u.js → tables-BD7H5ug-.js} +1 -1
- package/dist/plugin-sdk/{tables-RBtf8G4P.js → tables-CJE8kB35.js} +1 -1
- package/dist/plugin-sdk/{telegram-actions-DAeYXSLk.js → telegram-actions-BRUNEXMr.js} +25 -25
- package/dist/plugin-sdk/{telegram-actions-BDeS3ocd.js → telegram-actions-r86ntIKR.js} +25 -25
- package/dist/plugin-sdk/telegram.js +2 -1
- package/dist/plugin-sdk/{thread-bindings.lifecycle-DsB94WbE.js → thread-bindings.lifecycle-Djem8FWF.js} +2 -2
- package/dist/plugin-sdk/{thread-bindings.lifecycle-DMhV3TsR.js → thread-bindings.lifecycle-gmHv3hc7.js} +2 -2
- package/dist/plugin-sdk/{thread-bindings.state-DYWpy7hJ.js → thread-bindings.state-CNT2vxm3.js} +2 -2
- package/dist/plugin-sdk/{thread-bindings.state-DG5cBaRn.js → thread-bindings.state-D8kN2X6H.js} +2 -2
- package/dist/plugin-sdk/{web-DJwacWQo.js → web-02I0vmdu.js} +26 -26
- package/dist/plugin-sdk/{web-IJ4NoGPJ.js → web-CXz56wyu.js} +26 -26
- package/dist/plugin-sdk/{whatsapp-actions-DAY8hWpD.js → whatsapp-actions-68Mfs2dJ.js} +12 -12
- package/dist/plugin-sdk/{whatsapp-actions-6opfo-oB.js → whatsapp-actions-DRqtzvTO.js} +12 -12
- package/dist/plugin-sdk/whatsapp.js +2 -1
- package/dist/plugin-sdk/{wsl-B2euLEc2.js → wsl-DcM2PgSS.js} +3 -3
- package/dist/plugin-sdk/{wsl-B8eyviuv.js → wsl-PXrdWitE.js} +3 -3
- package/dist/plugins/update.js +1 -1
- package/dist/tts/tts-core.js +6 -1
- package/dist/wizard/onboarding.finalize.js +9 -0
- package/extensions/acpx/package.json +1 -1
- package/extensions/bluebubbles/package.json +1 -1
- package/extensions/copilot-proxy/package.json +1 -1
- package/extensions/diagnostics-otel/package.json +1 -1
- package/extensions/fased-federation/package.json +1 -1
- package/extensions/google-gemini-cli-auth/package.json +1 -1
- package/extensions/imessage/package.json +1 -1
- package/extensions/irc/package.json +1 -1
- package/extensions/line/package.json +1 -1
- package/extensions/llm-task/package.json +1 -1
- package/extensions/lobster/package.json +1 -1
- package/extensions/matrix/CHANGELOG.md +12 -0
- package/extensions/matrix/package.json +1 -1
- package/extensions/mattermost/package.json +1 -1
- package/extensions/memory-core/package.json +2 -2
- package/extensions/memory-lancedb/package.json +1 -1
- package/extensions/minimax-portal-auth/package.json +1 -1
- package/extensions/msteams/CHANGELOG.md +12 -0
- package/extensions/msteams/package.json +1 -1
- package/extensions/nextcloud-talk/package.json +1 -1
- package/extensions/nostr/CHANGELOG.md +12 -0
- package/extensions/nostr/package.json +1 -1
- package/extensions/open-prose/package.json +1 -1
- package/extensions/sat-mining/package.json +1 -1
- package/extensions/signal/package.json +1 -1
- package/extensions/synology-chat/package.json +1 -1
- package/extensions/tlon/package.json +1 -1
- package/extensions/twitch/CHANGELOG.md +12 -0
- package/extensions/twitch/package.json +1 -1
- package/extensions/voice-call/CHANGELOG.md +12 -0
- package/extensions/voice-call/package.json +1 -1
- package/extensions/zalo/CHANGELOG.md +12 -0
- package/extensions/zalo/package.json +1 -1
- package/extensions/zalouser/CHANGELOG.md +12 -0
- package/extensions/zalouser/package.json +1 -1
- package/package.json +22 -15
- package/extensions/feishu/fased.plugin.json +0 -10
- package/extensions/feishu/index.ts +0 -63
- package/extensions/feishu/package.json +0 -33
- package/extensions/feishu/skills/feishu-doc/SKILL.md +0 -211
- package/extensions/feishu/skills/feishu-doc/references/block-types.md +0 -103
- package/extensions/feishu/skills/feishu-drive/SKILL.md +0 -97
- package/extensions/feishu/skills/feishu-perm/SKILL.md +0 -119
- package/extensions/feishu/skills/feishu-wiki/SKILL.md +0 -111
- package/extensions/feishu/src/accounts.ts +0 -159
- package/extensions/feishu/src/bitable.ts +0 -713
- package/extensions/feishu/src/bot.ts +0 -979
- package/extensions/feishu/src/channel.ts +0 -359
- package/extensions/feishu/src/client.ts +0 -118
- package/extensions/feishu/src/config-schema.ts +0 -226
- package/extensions/feishu/src/dedup.ts +0 -54
- package/extensions/feishu/src/directory.ts +0 -177
- package/extensions/feishu/src/doc-schema.ts +0 -122
- package/extensions/feishu/src/docx.ts +0 -998
- package/extensions/feishu/src/drive-schema.ts +0 -46
- package/extensions/feishu/src/drive.ts +0 -232
- package/extensions/feishu/src/dynamic-agent.ts +0 -131
- package/extensions/feishu/src/external-keys.ts +0 -19
- package/extensions/feishu/src/media.ts +0 -447
- package/extensions/feishu/src/mention.ts +0 -133
- package/extensions/feishu/src/monitor.ts +0 -434
- package/extensions/feishu/src/onboarding.ts +0 -430
- package/extensions/feishu/src/outbound.ts +0 -56
- package/extensions/feishu/src/perm-schema.ts +0 -52
- package/extensions/feishu/src/perm.ts +0 -180
- package/extensions/feishu/src/policy.ts +0 -116
- package/extensions/feishu/src/probe.ts +0 -44
- package/extensions/feishu/src/reactions.ts +0 -160
- package/extensions/feishu/src/reply-dispatcher.ts +0 -239
- package/extensions/feishu/src/runtime.ts +0 -14
- package/extensions/feishu/src/send-result.ts +0 -29
- package/extensions/feishu/src/send-target.ts +0 -25
- package/extensions/feishu/src/send.ts +0 -313
- package/extensions/feishu/src/streaming-card.ts +0 -218
- package/extensions/feishu/src/targets.ts +0 -78
- package/extensions/feishu/src/tool-account.ts +0 -58
- package/extensions/feishu/src/tools-config.ts +0 -21
- package/extensions/feishu/src/types.ts +0 -81
- package/extensions/feishu/src/typing.ts +0 -80
- package/extensions/feishu/src/wiki-schema.ts +0 -55
- package/extensions/feishu/src/wiki.ts +0 -237
- package/extensions/googlechat/fased.plugin.json +0 -9
- package/extensions/googlechat/index.ts +0 -19
- package/extensions/googlechat/package.json +0 -37
- package/extensions/googlechat/src/accounts.ts +0 -147
- package/extensions/googlechat/src/actions.ts +0 -176
- package/extensions/googlechat/src/api.ts +0 -282
- package/extensions/googlechat/src/auth.ts +0 -137
- package/extensions/googlechat/src/channel.ts +0 -591
- package/extensions/googlechat/src/monitor.ts +0 -996
- package/extensions/googlechat/src/onboarding.ts +0 -344
- package/extensions/googlechat/src/runtime.ts +0 -14
- package/extensions/googlechat/src/targets.ts +0 -65
- package/extensions/googlechat/src/types.config.ts +0 -3
- package/extensions/googlechat/src/types.ts +0 -73
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
import crypto from "node:crypto";
|
|
2
|
-
import type { ResolvedGoogleChatAccount } from "./accounts.js";
|
|
3
|
-
import { getGoogleChatAccessToken } from "./auth.js";
|
|
4
|
-
import type { GoogleChatReaction } from "./types.js";
|
|
5
|
-
|
|
6
|
-
const CHAT_API_BASE = "https://chat.googleapis.com/v1";
|
|
7
|
-
const CHAT_UPLOAD_BASE = "https://chat.googleapis.com/upload/v1";
|
|
8
|
-
|
|
9
|
-
const headersToObject = (headers?: HeadersInit): Record<string, string> =>
|
|
10
|
-
headers instanceof Headers
|
|
11
|
-
? Object.fromEntries(headers.entries())
|
|
12
|
-
: Array.isArray(headers)
|
|
13
|
-
? Object.fromEntries(headers)
|
|
14
|
-
: headers || {};
|
|
15
|
-
|
|
16
|
-
async function fetchJson<T>(
|
|
17
|
-
account: ResolvedGoogleChatAccount,
|
|
18
|
-
url: string,
|
|
19
|
-
init: RequestInit,
|
|
20
|
-
): Promise<T> {
|
|
21
|
-
const token = await getGoogleChatAccessToken(account);
|
|
22
|
-
const res = await fetch(url, {
|
|
23
|
-
...init,
|
|
24
|
-
headers: {
|
|
25
|
-
...headersToObject(init.headers),
|
|
26
|
-
Authorization: `Bearer ${token}`,
|
|
27
|
-
"Content-Type": "application/json",
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
if (!res.ok) {
|
|
31
|
-
const text = await res.text().catch(() => "");
|
|
32
|
-
throw new Error(`Google Chat API ${res.status}: ${text || res.statusText}`);
|
|
33
|
-
}
|
|
34
|
-
return (await res.json()) as T;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async function fetchOk(
|
|
38
|
-
account: ResolvedGoogleChatAccount,
|
|
39
|
-
url: string,
|
|
40
|
-
init: RequestInit,
|
|
41
|
-
): Promise<void> {
|
|
42
|
-
const token = await getGoogleChatAccessToken(account);
|
|
43
|
-
const res = await fetch(url, {
|
|
44
|
-
...init,
|
|
45
|
-
headers: {
|
|
46
|
-
...headersToObject(init.headers),
|
|
47
|
-
Authorization: `Bearer ${token}`,
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
if (!res.ok) {
|
|
51
|
-
const text = await res.text().catch(() => "");
|
|
52
|
-
throw new Error(`Google Chat API ${res.status}: ${text || res.statusText}`);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async function fetchBuffer(
|
|
57
|
-
account: ResolvedGoogleChatAccount,
|
|
58
|
-
url: string,
|
|
59
|
-
init?: RequestInit,
|
|
60
|
-
options?: { maxBytes?: number },
|
|
61
|
-
): Promise<{ buffer: Buffer; contentType?: string }> {
|
|
62
|
-
const token = await getGoogleChatAccessToken(account);
|
|
63
|
-
const res = await fetch(url, {
|
|
64
|
-
...init,
|
|
65
|
-
headers: {
|
|
66
|
-
...headersToObject(init?.headers),
|
|
67
|
-
Authorization: `Bearer ${token}`,
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
if (!res.ok) {
|
|
71
|
-
const text = await res.text().catch(() => "");
|
|
72
|
-
throw new Error(`Google Chat API ${res.status}: ${text || res.statusText}`);
|
|
73
|
-
}
|
|
74
|
-
const maxBytes = options?.maxBytes;
|
|
75
|
-
const lengthHeader = res.headers.get("content-length");
|
|
76
|
-
if (maxBytes && lengthHeader) {
|
|
77
|
-
const length = Number(lengthHeader);
|
|
78
|
-
if (Number.isFinite(length) && length > maxBytes) {
|
|
79
|
-
throw new Error(`Google Chat media exceeds max bytes (${maxBytes})`);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
if (!maxBytes || !res.body) {
|
|
83
|
-
const buffer = Buffer.from(await res.arrayBuffer());
|
|
84
|
-
const contentType = res.headers.get("content-type") ?? undefined;
|
|
85
|
-
return { buffer, contentType };
|
|
86
|
-
}
|
|
87
|
-
const reader = res.body.getReader();
|
|
88
|
-
const chunks: Buffer[] = [];
|
|
89
|
-
let total = 0;
|
|
90
|
-
while (true) {
|
|
91
|
-
const { done, value } = await reader.read();
|
|
92
|
-
if (done) {
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
if (!value) {
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
98
|
-
total += value.length;
|
|
99
|
-
if (total > maxBytes) {
|
|
100
|
-
await reader.cancel();
|
|
101
|
-
throw new Error(`Google Chat media exceeds max bytes (${maxBytes})`);
|
|
102
|
-
}
|
|
103
|
-
chunks.push(Buffer.from(value));
|
|
104
|
-
}
|
|
105
|
-
const buffer = Buffer.concat(chunks, total);
|
|
106
|
-
const contentType = res.headers.get("content-type") ?? undefined;
|
|
107
|
-
return { buffer, contentType };
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export async function sendGoogleChatMessage(params: {
|
|
111
|
-
account: ResolvedGoogleChatAccount;
|
|
112
|
-
space: string;
|
|
113
|
-
text?: string;
|
|
114
|
-
thread?: string;
|
|
115
|
-
attachments?: Array<{ attachmentUploadToken: string; contentName?: string }>;
|
|
116
|
-
}): Promise<{ messageName?: string } | null> {
|
|
117
|
-
const { account, space, text, thread, attachments } = params;
|
|
118
|
-
const body: Record<string, unknown> = {};
|
|
119
|
-
if (text) {
|
|
120
|
-
body.text = text;
|
|
121
|
-
}
|
|
122
|
-
if (thread) {
|
|
123
|
-
body.thread = { name: thread };
|
|
124
|
-
}
|
|
125
|
-
if (attachments && attachments.length > 0) {
|
|
126
|
-
body.attachment = attachments.map((item) => ({
|
|
127
|
-
attachmentDataRef: { attachmentUploadToken: item.attachmentUploadToken },
|
|
128
|
-
...(item.contentName ? { contentName: item.contentName } : {}),
|
|
129
|
-
}));
|
|
130
|
-
}
|
|
131
|
-
const url = `${CHAT_API_BASE}/${space}/messages`;
|
|
132
|
-
const result = await fetchJson<{ name?: string }>(account, url, {
|
|
133
|
-
method: "POST",
|
|
134
|
-
body: JSON.stringify(body),
|
|
135
|
-
});
|
|
136
|
-
return result ? { messageName: result.name } : null;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export async function updateGoogleChatMessage(params: {
|
|
140
|
-
account: ResolvedGoogleChatAccount;
|
|
141
|
-
messageName: string;
|
|
142
|
-
text: string;
|
|
143
|
-
}): Promise<{ messageName?: string }> {
|
|
144
|
-
const { account, messageName, text } = params;
|
|
145
|
-
const url = `${CHAT_API_BASE}/${messageName}?updateMask=text`;
|
|
146
|
-
const result = await fetchJson<{ name?: string }>(account, url, {
|
|
147
|
-
method: "PATCH",
|
|
148
|
-
body: JSON.stringify({ text }),
|
|
149
|
-
});
|
|
150
|
-
return { messageName: result.name };
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
export async function deleteGoogleChatMessage(params: {
|
|
154
|
-
account: ResolvedGoogleChatAccount;
|
|
155
|
-
messageName: string;
|
|
156
|
-
}): Promise<void> {
|
|
157
|
-
const { account, messageName } = params;
|
|
158
|
-
const url = `${CHAT_API_BASE}/${messageName}`;
|
|
159
|
-
await fetchOk(account, url, { method: "DELETE" });
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export async function uploadGoogleChatAttachment(params: {
|
|
163
|
-
account: ResolvedGoogleChatAccount;
|
|
164
|
-
space: string;
|
|
165
|
-
filename: string;
|
|
166
|
-
buffer: Buffer;
|
|
167
|
-
contentType?: string;
|
|
168
|
-
}): Promise<{ attachmentUploadToken?: string }> {
|
|
169
|
-
const { account, space, filename, buffer, contentType } = params;
|
|
170
|
-
const boundary = `fased-${crypto.randomUUID()}`;
|
|
171
|
-
const metadata = JSON.stringify({ filename });
|
|
172
|
-
const header = `--${boundary}\r\nContent-Type: application/json; charset=UTF-8\r\n\r\n${metadata}\r\n`;
|
|
173
|
-
const mediaHeader = `--${boundary}\r\nContent-Type: ${contentType ?? "application/octet-stream"}\r\n\r\n`;
|
|
174
|
-
const footer = `\r\n--${boundary}--\r\n`;
|
|
175
|
-
const body = Buffer.concat([
|
|
176
|
-
Buffer.from(header, "utf8"),
|
|
177
|
-
Buffer.from(mediaHeader, "utf8"),
|
|
178
|
-
buffer,
|
|
179
|
-
Buffer.from(footer, "utf8"),
|
|
180
|
-
]);
|
|
181
|
-
|
|
182
|
-
const token = await getGoogleChatAccessToken(account);
|
|
183
|
-
const url = `${CHAT_UPLOAD_BASE}/${space}/attachments:upload?uploadType=multipart`;
|
|
184
|
-
const res = await fetch(url, {
|
|
185
|
-
method: "POST",
|
|
186
|
-
headers: {
|
|
187
|
-
Authorization: `Bearer ${token}`,
|
|
188
|
-
"Content-Type": `multipart/related; boundary=${boundary}`,
|
|
189
|
-
},
|
|
190
|
-
body,
|
|
191
|
-
});
|
|
192
|
-
if (!res.ok) {
|
|
193
|
-
const text = await res.text().catch(() => "");
|
|
194
|
-
throw new Error(`Google Chat upload ${res.status}: ${text || res.statusText}`);
|
|
195
|
-
}
|
|
196
|
-
const payload = (await res.json()) as {
|
|
197
|
-
attachmentDataRef?: { attachmentUploadToken?: string };
|
|
198
|
-
};
|
|
199
|
-
return {
|
|
200
|
-
attachmentUploadToken: payload.attachmentDataRef?.attachmentUploadToken,
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
export async function downloadGoogleChatMedia(params: {
|
|
205
|
-
account: ResolvedGoogleChatAccount;
|
|
206
|
-
resourceName: string;
|
|
207
|
-
maxBytes?: number;
|
|
208
|
-
}): Promise<{ buffer: Buffer; contentType?: string }> {
|
|
209
|
-
const { account, resourceName, maxBytes } = params;
|
|
210
|
-
const url = `${CHAT_API_BASE}/media/${resourceName}?alt=media`;
|
|
211
|
-
return await fetchBuffer(account, url, undefined, { maxBytes });
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
export async function createGoogleChatReaction(params: {
|
|
215
|
-
account: ResolvedGoogleChatAccount;
|
|
216
|
-
messageName: string;
|
|
217
|
-
emoji: string;
|
|
218
|
-
}): Promise<GoogleChatReaction> {
|
|
219
|
-
const { account, messageName, emoji } = params;
|
|
220
|
-
const url = `${CHAT_API_BASE}/${messageName}/reactions`;
|
|
221
|
-
return await fetchJson<GoogleChatReaction>(account, url, {
|
|
222
|
-
method: "POST",
|
|
223
|
-
body: JSON.stringify({ emoji: { unicode: emoji } }),
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
export async function listGoogleChatReactions(params: {
|
|
228
|
-
account: ResolvedGoogleChatAccount;
|
|
229
|
-
messageName: string;
|
|
230
|
-
limit?: number;
|
|
231
|
-
}): Promise<GoogleChatReaction[]> {
|
|
232
|
-
const { account, messageName, limit } = params;
|
|
233
|
-
const url = new URL(`${CHAT_API_BASE}/${messageName}/reactions`);
|
|
234
|
-
if (limit && limit > 0) {
|
|
235
|
-
url.searchParams.set("pageSize", String(limit));
|
|
236
|
-
}
|
|
237
|
-
const result = await fetchJson<{ reactions?: GoogleChatReaction[] }>(account, url.toString(), {
|
|
238
|
-
method: "GET",
|
|
239
|
-
});
|
|
240
|
-
return result.reactions ?? [];
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
export async function deleteGoogleChatReaction(params: {
|
|
244
|
-
account: ResolvedGoogleChatAccount;
|
|
245
|
-
reactionName: string;
|
|
246
|
-
}): Promise<void> {
|
|
247
|
-
const { account, reactionName } = params;
|
|
248
|
-
const url = `${CHAT_API_BASE}/${reactionName}`;
|
|
249
|
-
await fetchOk(account, url, { method: "DELETE" });
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
export async function findGoogleChatDirectMessage(params: {
|
|
253
|
-
account: ResolvedGoogleChatAccount;
|
|
254
|
-
userName: string;
|
|
255
|
-
}): Promise<{ name?: string; displayName?: string } | null> {
|
|
256
|
-
const { account, userName } = params;
|
|
257
|
-
const url = new URL(`${CHAT_API_BASE}/spaces:findDirectMessage`);
|
|
258
|
-
url.searchParams.set("name", userName);
|
|
259
|
-
return await fetchJson<{ name?: string; displayName?: string }>(account, url.toString(), {
|
|
260
|
-
method: "GET",
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
export async function probeGoogleChat(account: ResolvedGoogleChatAccount): Promise<{
|
|
265
|
-
ok: boolean;
|
|
266
|
-
status?: number;
|
|
267
|
-
error?: string;
|
|
268
|
-
}> {
|
|
269
|
-
try {
|
|
270
|
-
const url = new URL(`${CHAT_API_BASE}/spaces`);
|
|
271
|
-
url.searchParams.set("pageSize", "1");
|
|
272
|
-
await fetchJson<Record<string, unknown>>(account, url.toString(), {
|
|
273
|
-
method: "GET",
|
|
274
|
-
});
|
|
275
|
-
return { ok: true };
|
|
276
|
-
} catch (err) {
|
|
277
|
-
return {
|
|
278
|
-
ok: false,
|
|
279
|
-
error: err instanceof Error ? err.message : String(err),
|
|
280
|
-
};
|
|
281
|
-
}
|
|
282
|
-
}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { GoogleAuth, OAuth2Client } from "google-auth-library";
|
|
2
|
-
import type { ResolvedGoogleChatAccount } from "./accounts.js";
|
|
3
|
-
|
|
4
|
-
const CHAT_SCOPE = "https://www.googleapis.com/auth/chat.bot";
|
|
5
|
-
const CHAT_ISSUER = "chat@system.gserviceaccount.com";
|
|
6
|
-
// Google Workspace Add-ons use a different service account pattern
|
|
7
|
-
const ADDON_ISSUER_PATTERN = /^service-\d+@gcp-sa-gsuiteaddons\.iam\.gserviceaccount\.com$/;
|
|
8
|
-
const CHAT_CERTS_URL =
|
|
9
|
-
"https://www.googleapis.com/service_accounts/v1/metadata/x509/chat@system.gserviceaccount.com";
|
|
10
|
-
|
|
11
|
-
// Size-capped to prevent unbounded growth in long-running deployments (#4948)
|
|
12
|
-
const MAX_AUTH_CACHE_SIZE = 32;
|
|
13
|
-
const authCache = new Map<string, { key: string; auth: GoogleAuth }>();
|
|
14
|
-
const verifyClient = new OAuth2Client();
|
|
15
|
-
|
|
16
|
-
let cachedCerts: { fetchedAt: number; certs: Record<string, string> } | null = null;
|
|
17
|
-
|
|
18
|
-
function buildAuthKey(account: ResolvedGoogleChatAccount): string {
|
|
19
|
-
if (account.credentialsFile) {
|
|
20
|
-
return `file:${account.credentialsFile}`;
|
|
21
|
-
}
|
|
22
|
-
if (account.credentials) {
|
|
23
|
-
return `inline:${JSON.stringify(account.credentials)}`;
|
|
24
|
-
}
|
|
25
|
-
return "none";
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function getAuthInstance(account: ResolvedGoogleChatAccount): GoogleAuth {
|
|
29
|
-
const key = buildAuthKey(account);
|
|
30
|
-
const cached = authCache.get(account.accountId);
|
|
31
|
-
if (cached && cached.key === key) {
|
|
32
|
-
return cached.auth;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const evictOldest = () => {
|
|
36
|
-
if (authCache.size > MAX_AUTH_CACHE_SIZE) {
|
|
37
|
-
const oldest = authCache.keys().next().value;
|
|
38
|
-
if (oldest !== undefined) {
|
|
39
|
-
authCache.delete(oldest);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
if (account.credentialsFile) {
|
|
45
|
-
const auth = new GoogleAuth({ keyFile: account.credentialsFile, scopes: [CHAT_SCOPE] });
|
|
46
|
-
authCache.set(account.accountId, { key, auth });
|
|
47
|
-
evictOldest();
|
|
48
|
-
return auth;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (account.credentials) {
|
|
52
|
-
const auth = new GoogleAuth({ credentials: account.credentials, scopes: [CHAT_SCOPE] });
|
|
53
|
-
authCache.set(account.accountId, { key, auth });
|
|
54
|
-
evictOldest();
|
|
55
|
-
return auth;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const auth = new GoogleAuth({ scopes: [CHAT_SCOPE] });
|
|
59
|
-
authCache.set(account.accountId, { key, auth });
|
|
60
|
-
evictOldest();
|
|
61
|
-
return auth;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export async function getGoogleChatAccessToken(
|
|
65
|
-
account: ResolvedGoogleChatAccount,
|
|
66
|
-
): Promise<string> {
|
|
67
|
-
const auth = getAuthInstance(account);
|
|
68
|
-
const client = await auth.getClient();
|
|
69
|
-
const access = await client.getAccessToken();
|
|
70
|
-
const token = typeof access === "string" ? access : access?.token;
|
|
71
|
-
if (!token) {
|
|
72
|
-
throw new Error("Missing Google Chat access token");
|
|
73
|
-
}
|
|
74
|
-
return token;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
async function fetchChatCerts(): Promise<Record<string, string>> {
|
|
78
|
-
const now = Date.now();
|
|
79
|
-
if (cachedCerts && now - cachedCerts.fetchedAt < 10 * 60 * 1000) {
|
|
80
|
-
return cachedCerts.certs;
|
|
81
|
-
}
|
|
82
|
-
const res = await fetch(CHAT_CERTS_URL);
|
|
83
|
-
if (!res.ok) {
|
|
84
|
-
throw new Error(`Failed to fetch Chat certs (${res.status})`);
|
|
85
|
-
}
|
|
86
|
-
const certs = (await res.json()) as Record<string, string>;
|
|
87
|
-
cachedCerts = { fetchedAt: now, certs };
|
|
88
|
-
return certs;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export type GoogleChatAudienceType = "app-url" | "project-number";
|
|
92
|
-
|
|
93
|
-
export async function verifyGoogleChatRequest(params: {
|
|
94
|
-
bearer?: string | null;
|
|
95
|
-
audienceType?: GoogleChatAudienceType | null;
|
|
96
|
-
audience?: string | null;
|
|
97
|
-
}): Promise<{ ok: boolean; reason?: string }> {
|
|
98
|
-
const bearer = params.bearer?.trim();
|
|
99
|
-
if (!bearer) {
|
|
100
|
-
return { ok: false, reason: "missing token" };
|
|
101
|
-
}
|
|
102
|
-
const audience = params.audience?.trim();
|
|
103
|
-
if (!audience) {
|
|
104
|
-
return { ok: false, reason: "missing audience" };
|
|
105
|
-
}
|
|
106
|
-
const audienceType = params.audienceType ?? null;
|
|
107
|
-
|
|
108
|
-
if (audienceType === "app-url") {
|
|
109
|
-
try {
|
|
110
|
-
const ticket = await verifyClient.verifyIdToken({
|
|
111
|
-
idToken: bearer,
|
|
112
|
-
audience,
|
|
113
|
-
});
|
|
114
|
-
const payload = ticket.getPayload();
|
|
115
|
-
const email = payload?.email ?? "";
|
|
116
|
-
const ok =
|
|
117
|
-
payload?.email_verified && (email === CHAT_ISSUER || ADDON_ISSUER_PATTERN.test(email));
|
|
118
|
-
return ok ? { ok: true } : { ok: false, reason: `invalid issuer: ${email}` };
|
|
119
|
-
} catch (err) {
|
|
120
|
-
return { ok: false, reason: err instanceof Error ? err.message : "invalid token" };
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (audienceType === "project-number") {
|
|
125
|
-
try {
|
|
126
|
-
const certs = await fetchChatCerts();
|
|
127
|
-
await verifyClient.verifySignedJwtWithCertsAsync(bearer, certs, audience, [CHAT_ISSUER]);
|
|
128
|
-
return { ok: true };
|
|
129
|
-
} catch (err) {
|
|
130
|
-
return { ok: false, reason: err instanceof Error ? err.message : "invalid token" };
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return { ok: false, reason: "unsupported audience type" };
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export const GOOGLE_CHAT_SCOPE = CHAT_SCOPE;
|