@plotday/twister 0.63.0 → 0.65.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/bin/commands/deploy.js +6 -0
- package/bin/commands/deploy.js.map +1 -1
- package/dist/connector.d.ts +45 -0
- package/dist/connector.d.ts.map +1 -1
- package/dist/connector.js +16 -0
- package/dist/connector.js.map +1 -1
- package/dist/docs/assets/hierarchy.js +1 -1
- package/dist/docs/assets/navigation.js +1 -1
- package/dist/docs/assets/search.js +1 -1
- package/dist/docs/classes/index.Connector.html +44 -32
- package/dist/docs/classes/index.FileNotFoundError.html +1 -1
- package/dist/docs/classes/index.Files.html +1 -1
- package/dist/docs/classes/index.Imap.html +1 -1
- package/dist/docs/classes/index.Options.html +1 -1
- package/dist/docs/classes/index.Smtp.html +1 -1
- package/dist/docs/classes/tools_integrations.Integrations.html +15 -15
- package/dist/docs/classes/tools_network.Network.html +1 -1
- package/dist/docs/classes/tools_plot.Plot.html +1 -1
- package/dist/docs/classes/tools_store.Store.html +1 -1
- package/dist/docs/classes/tools_tasks.Tasks.html +1 -1
- package/dist/docs/enums/tools_integrations.AuthProvider.html +13 -13
- package/dist/docs/hierarchy.html +1 -1
- package/dist/docs/modules/index.html +1 -1
- package/dist/docs/types/index.ProductInfo.html +24 -0
- package/dist/docs/types/tools_integrations.ArchiveLinkFilter.html +5 -5
- package/dist/docs/types/tools_integrations.ArchiveNotesFilter.html +2 -2
- package/dist/docs/types/tools_integrations.AuthToken.html +4 -4
- package/dist/docs/types/tools_integrations.Authorization.html +4 -4
- package/dist/docs/types/tools_integrations.ComposeConfig.html +4 -4
- package/dist/docs/types/tools_integrations.ContactRoleConfig.html +5 -5
- package/dist/docs/types/tools_integrations.LinkTypeConfig.html +31 -20
- package/dist/docs/types/tools_integrations.NewCustomEmoji.html +8 -8
- package/dist/docs/types/tools_integrations.SyncContext.html +4 -4
- package/dist/llm-docs/connector.d.ts +1 -1
- package/dist/llm-docs/connector.d.ts.map +1 -1
- package/dist/llm-docs/connector.js +1 -1
- package/dist/llm-docs/connector.js.map +1 -1
- package/dist/llm-docs/tools/integrations.d.ts +1 -1
- package/dist/llm-docs/tools/integrations.d.ts.map +1 -1
- package/dist/llm-docs/tools/integrations.js +1 -1
- package/dist/llm-docs/tools/integrations.js.map +1 -1
- package/dist/tools/integrations.d.ts +13 -0
- package/dist/tools/integrations.d.ts.map +1 -1
- package/dist/tools/integrations.js.map +1 -1
- package/package.json +1 -1
- package/src/connector.ts +47 -0
- package/src/llm-docs/connector.ts +1 -1
- package/src/llm-docs/tools/integrations.ts +1 -1
- package/src/tools/integrations.ts +13 -0
package/src/connector.ts
CHANGED
|
@@ -220,6 +220,36 @@ export type ScopeConfig = {
|
|
|
220
220
|
optional?: OptionalScopeGroup[];
|
|
221
221
|
};
|
|
222
222
|
|
|
223
|
+
/**
|
|
224
|
+
* Per-instance product metadata for combined (multi-product) connectors — one
|
|
225
|
+
* ordinary `Connector` that bundles several user-facing products (e.g. the
|
|
226
|
+
* combined Google connector covering Mail, Calendar, Tasks, and Contacts) under
|
|
227
|
+
* a single OAuth grant and one charge.
|
|
228
|
+
*
|
|
229
|
+
* The app's combined-connection setup/status UX renders one row per entry. Each
|
|
230
|
+
* product maps to exactly one optional scope group: `scopeGroupId` MUST equal an
|
|
231
|
+
* {@link OptionalScopeGroup.id} declared in the connector's {@link ScopeConfig}
|
|
232
|
+
* `optional` groups, so the API can derive per-product enablement
|
|
233
|
+
* (`granted | scope-missing | no-channels | locally-off`) from the connection's
|
|
234
|
+
* granted scopes plus its enabled channels.
|
|
235
|
+
*
|
|
236
|
+
* Plain (single-product) connectors leave {@link Connector.products} undefined;
|
|
237
|
+
* the API then omits the `products`/`productStatus` fields and the app falls
|
|
238
|
+
* back to the standard per-connector flow.
|
|
239
|
+
*/
|
|
240
|
+
export type ProductInfo = {
|
|
241
|
+
/** Stable product id. Also the channel-id namespace prefix (`"<key>:<rawId>"`). */
|
|
242
|
+
key: string;
|
|
243
|
+
/** Setup/status row title (e.g. "Gmail"). */
|
|
244
|
+
label: string;
|
|
245
|
+
/** Short summary shown under the label on the setup/status row. */
|
|
246
|
+
description: string;
|
|
247
|
+
/** Icon URL rendered on the row. */
|
|
248
|
+
icon: string;
|
|
249
|
+
/** Matches an {@link OptionalScopeGroup.id} in this connector's scopes. */
|
|
250
|
+
scopeGroupId: string;
|
|
251
|
+
};
|
|
252
|
+
|
|
223
253
|
/**
|
|
224
254
|
* Base class for connectors — twists that sync data from external services.
|
|
225
255
|
*
|
|
@@ -412,6 +442,23 @@ export abstract class Connector<TSelf> extends Twist<TSelf> {
|
|
|
412
442
|
*/
|
|
413
443
|
readonly dynamicLinkTypes?: boolean;
|
|
414
444
|
|
|
445
|
+
/**
|
|
446
|
+
* Per-instance product metadata for combined (multi-product) connectors —
|
|
447
|
+
* one connection bundling several user-facing products under a single OAuth
|
|
448
|
+
* grant (e.g. the combined Google connector: Mail, Calendar, Tasks,
|
|
449
|
+
* Contacts).
|
|
450
|
+
*
|
|
451
|
+
* Each {@link ProductInfo.scopeGroupId} must match an
|
|
452
|
+
* {@link OptionalScopeGroup.id} declared in this connector's {@link scopes}
|
|
453
|
+
* so the API can derive per-product enablement from granted scopes + enabled
|
|
454
|
+
* channels.
|
|
455
|
+
*
|
|
456
|
+
* Leave undefined for plain (single-product) connectors — the API then omits
|
|
457
|
+
* the `products`/`productStatus` response fields and the app uses the
|
|
458
|
+
* standard per-connector flow.
|
|
459
|
+
*/
|
|
460
|
+
readonly products?: ProductInfo[];
|
|
461
|
+
|
|
415
462
|
/**
|
|
416
463
|
* When true, this connector is mentioned by default on replies to threads it created.
|
|
417
464
|
* When false (default), this connector cannot be mentioned at all.
|
|
@@ -5,4 +5,4 @@
|
|
|
5
5
|
* Generated from: prebuild.ts
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
export default "import { type Actor, type ActorId, type Contact, type DeliveryError, type Link, type NewLinkWithNotes, type Note, type Thread, type Uuid } from \"./plot\";\nimport type { ScheduleContactStatus } from \"./schedule\";\nimport {\n type AuthProvider,\n type AuthToken,\n type Authorization,\n type Channel,\n type LinkTypeConfig,\n type SyncContext,\n} from \"./tools/integrations\";\nimport { Twist } from \"./twist\";\n\n/**\n * Declares how a connector's platform handles emoji reactions.\n *\n * Drives Plot UI behavior (e.g. the picker filters the available\n * reactions on notes whose primary connector declares `fixed`) and\n * outbound dispatch (Plot won't try to push an emoji the platform\n * can't accept).\n *\n * Variants:\n * - `open-unicode`: Platform accepts any Unicode emoji. `customEmoji`\n * indicates whether the platform additionally supports workspace\n * custom emoji (Slack, Google Chat).\n * - `unicode-subset`: Platform accepts Unicode but only a finite set.\n * `subset` lists the allowed emoji (omit for \"currently full Unicode\n * per docs, future-proofed for shrinkage\").\n * - `fixed`: Platform only accepts a fixed set (e.g. LinkedIn\n * Messaging's 7-reaction set). `allowed` lists every supported emoji.\n */\nexport type ReactionCapabilities =\n | { mode: \"open-unicode\"; customEmoji?: \"workspace\" | \"none\" }\n | { mode: \"unicode-subset\"; subset?: readonly string[] }\n | { mode: \"fixed\"; allowed: readonly string[] };\n\n/**\n * Result returned from {@link Connector.onNoteCreated} and\n * {@link Connector.onNoteUpdated} to report what the external system now\n * has stored for the note.\n *\n * The runtime hashes `externalContent` and stores it as the note's sync\n * baseline. On the next sync-in, if the incoming content hashes to the\n * same value, the runtime knows the external side hasn't changed and\n * preserves Plot's (possibly formatted) content. When the external side\n * is edited, the hash diverges and the runtime overwrites Plot's content\n * with the new external version.\n *\n * Omitting `externalContent` skips baseline tracking — the next sync-in\n * will overwrite Plot's content (previous behavior). Always provide it\n * when the write-back's return value reflects what the external system\n * actually stored (often lossy plain-text), so the round-trip does not\n * clobber the original Plot markdown.\n *\n * The hash covers only the content string — the runtime intentionally\n * does not include a content-type in the hash, so write-back and sync-in\n * do not have to agree on a content-type label for the same underlying\n * bytes. Return exactly the string your connector's sync-in path will\n * emit as `NewNote.content` for this note on the next re-ingest.\n *\n * For back-compat, `onNoteCreated` may also return a plain string, which\n * is treated as `{ key }` with no baseline.\n */\nexport type NoteWriteBackResult = {\n /**\n * External system identifier assigned to this note. Set as the note's\n * `key` for future upsert matching. Required when the runtime does not\n * already know the key (i.e., from `onNoteCreated`); ignored from\n * `onNoteUpdated` when the key was already established on create.\n */\n key?: string;\n /**\n * The content string as the external system now stores it, post-write.\n * For systems whose write-back returns a representation of what was\n * actually stored (e.g. Google Drive comment `content` after a create),\n * pass that verbatim. For systems that only accept plain text, this\n * will often be a lossy plain-text version of the Plot markdown — that\n * is exactly the point: storing the lossy form as baseline lets the\n * next sync-in recognize it and skip overwriting the richer Plot\n * version.\n *\n * Must exactly match the string your connector's sync-in path emits as\n * `NewNote.content` for this note on re-ingest.\n */\n externalContent?: string;\n /**\n * Reports that the outbound send / write-back for this note FAILED and\n * could not be recovered (after the connector's own retries). The runtime\n * records it on the note — surfacing a \"Failed to send\" affordance (Retry /\n * Discard) to the user — and marks the thread unread.\n *\n * - object → record the failure.\n * - `null` → clear a previously-recorded failure (e.g. a successful retry).\n * - omitted (`undefined`) → leave any existing delivery state untouched.\n *\n * A successful write-back (any result without a `deliveryError`) also clears\n * a previously-recorded failure, so connectors usually only need to SET this\n * on failure.\n *\n * Prefer RETURNING this over throwing for expected, user-visible failures\n * (rejected recipient, message too large, quota exhausted): a thrown error\n * pages error tracking, whereas a returned `deliveryError` does not. Reserve\n * throwing for genuinely unexpected errors. Connectors that simply throw on a\n * failed write-back still get a generic \"Failed to send\" surfaced by the\n * runtime, just without a specific reason.\n */\n deliveryError?: DeliveryError | null;\n};\n\n/**\n * A Plot contact pre-resolved to its platform account ID, ready for use\n * in a messaging dispatch.\n *\n * Populated by the runtime for link types with `compose.targets: \"contacts\"` before\n * `onCreateLink` is called. The connector should use `externalAccountId`\n * directly to address the recipient on the platform (e.g. Slack user ID,\n * LinkedIn URN, Gmail address) without performing its own contact lookup.\n */\nexport type ResolvedRecipient = {\n /** Plot contact UUID */\n id: Uuid;\n /** Display name, or null if not set */\n name: string | null;\n /** Platform-specific account identifier pre-resolved at dispatch time (e.g. Slack `U…`, LinkedIn URN, Gmail email address) */\n externalAccountId: string;\n /**\n * The contact's role on the originating thread, resolved from\n * `thread.contact_meta` against the link type's `contactRoles` (e.g.\n * `\"to\"` / `\"cc\"` / `\"bcc\"` for Gmail). `null` when the contact had no\n * explicit role entry — connectors should treat `null` as the link\n * type's default role (the `contactRoles` entry marked `default: true`).\n *\n * Connectors that distinguish roles MUST honor this when addressing the\n * recipient — e.g. Gmail must place `\"cc\"`/`\"bcc\"` recipients in the\n * Cc/Bcc headers, never the To header, so BCC recipients are not\n * exposed to the other recipients. Connectors that don't distinguish\n * roles (Slack, Linear) can ignore it.\n */\n role: string | null;\n};\n\n/**\n * Fields captured in Plot when a user initiates creation of a new external\n * item via a connector's `onCreateLink` hook.\n *\n * Thread-agnostic on purpose — connectors do not receive the Plot thread.\n * The platform attaches the returned `NewLinkWithNotes` to the originating\n * thread once `onCreateLink` resolves.\n */\nexport type CreateLinkDraft = {\n /** The channel (account + resource) the new item belongs to. */\n channelId: string;\n /** Link type identifier, matches a `LinkTypeConfig.type`. */\n type: string;\n /**\n * Status the user selected. Matches a `statuses[].status` for `type`,\n * or null for status-less link types (the parent linkType declares no\n * `statuses` and no `compose.status`).\n */\n status: string | null;\n /** Title of the originating Plot thread (post AI title generation). */\n title: string;\n /** Markdown content of the thread's first note, or null if none. */\n noteContent: string | null;\n /**\n * Contacts attached to the originating Plot thread, excluding the\n * creating user. Use these as recipients (email, chat DM members, etc.)\n * when the external item is a message or invite. An empty list means\n * the user did not add anyone to the thread.\n *\n * For link types with `compose.targets: \"contacts\"`, prefer `recipients` over\n * re-resolving contacts yourself: the runtime pre-resolves each contact\n * to its platform account ID (`externalAccountId`) and populates\n * `recipients` before `onCreateLink` is called.\n */\n contacts: Actor[];\n /**\n * Pre-resolved recipients for link types whose `compose.targets` is\n * `\"contacts\"` or `\"addresses\"`.\n *\n * Only populated for those link types; otherwise undefined. Each entry contains the Plot\n * contact UUID, the platform-specific account ID\n * (`externalAccountId`) the connector should use to address the\n * recipient without performing its own lookup, and the contact's\n * `role` on the thread (e.g. `\"to\"` / `\"cc\"` / `\"bcc\"`) resolved from\n * `thread.contact_meta`. For `\"addresses\"` link types, contacts without\n * a connection-scoped row fall back to `contact.email`.\n */\n recipients?: ResolvedRecipient[];\n /**\n * Free-form addresses the user typed into the picker (no Plot contact\n * row). Only populated for link types with `compose.targets: \"addresses\"`; otherwise\n * undefined. Connectors should append these alongside `recipients`\n * when constructing the recipient list (e.g. `To:` header for Gmail).\n */\n inviteEmails?: string[];\n};\n\n/** An optional OAuth scope group the user can toggle at connect time. */\nexport type OptionalScopeGroup = {\n /** Stable id used to track the user's selection. */\n id: string;\n /** Value-forward switch label, e.g. \"Add names to events using contacts\". */\n label: string;\n /** Optional secondary line shown under the label. */\n description?: string;\n /** The OAuth scope strings this group grants. */\n scopes: string[];\n /** Whether the group is requested by default (switch on). */\n default: boolean;\n};\n\n/**\n * Structured scope declaration. `required` scopes must be granted — auth fails\n * and re-prompts if any is declined. `optional` groups are requested by default\n * but auth still succeeds if the user declines them; the connector should detect\n * the absence via the granted `token.scopes` and degrade gracefully.\n */\nexport type ScopeConfig = {\n required: string[];\n optional?: OptionalScopeGroup[];\n};\n\n/**\n * Base class for connectors — twists that sync data from external services.\n *\n * Connectors declare a single OAuth provider and scopes, and implement channel\n * lifecycle methods for discovering and syncing external resources. They save\n * data directly via `integrations.saveLink()` instead of using the Plot tool.\n *\n * @example\n * ```typescript\n * class LinearConnector extends Connector<LinearConnector> {\n * readonly provider = AuthProvider.Linear;\n * readonly scopes = [\"read\", \"write\"];\n * readonly linkTypes = [{\n * type: \"issue\",\n * label: \"Issue\",\n * statuses: [\n * { status: \"open\", label: \"Open\", icon: \"todo\" },\n * { status: \"done\", label: \"Done\", icon: \"done\", done: true },\n * ],\n * }];\n *\n * build(build: ToolBuilder) {\n * return {\n * integrations: build(Integrations),\n * };\n * }\n *\n * async getChannels(auth: Authorization, token: AuthToken): Promise<Channel[]> {\n * const teams = await this.listTeams(token);\n * return teams.map(t => ({ id: t.id, title: t.name }));\n * }\n *\n * async onChannelEnabled(channel: Channel) {\n * const issues = await this.fetchIssues(channel.id);\n * for (const issue of issues) {\n * await this.tools.integrations.saveLink(issue);\n * }\n * }\n *\n * async onChannelDisabled(channel: Channel) {\n * // Clean up webhooks, sync state, etc.\n * }\n * }\n * ```\n */\nexport abstract class Connector<TSelf> extends Twist<TSelf> {\n /**\n * Static marker to identify Connector subclasses without instanceof checks\n * across worker boundaries.\n */\n static readonly isConnector = true;\n\n // ---- Identity (abstract — every connector must declare) ----\n\n /** The OAuth provider this connector authenticates with. */\n readonly provider?: AuthProvider;\n\n /** OAuth scopes to request for this connector — a flat list (all required), or\n * a {@link ScopeConfig} declaring required + optional scope groups. */\n readonly scopes?: string[] | ScopeConfig;\n\n /**\n * Plain-language bullets describing what access connecting this service\n * grants the user — shown on the connect screen regardless of auth mechanism\n * (OAuth, API key, or hosted). For OAuth connectors it also previews what the\n * provider's consent screen will request. These are justifications for what\n * Plot accesses, not a one-to-one mapping of scope strings.\n */\n readonly access?: string[];\n\n // ---- Auth model ----\n\n /**\n * When true, one credential is shared across all users in the workspace,\n * entered once by the installer. When false (default), each user provides\n * their own credential.\n *\n * Applies to both OAuth and key-based connectors:\n * - Shared OAuth: e.g. Slack bot token (workspace-level)\n * - Shared key: e.g. Attio workspace API key\n * - Individual OAuth: e.g. Google Calendar (per-user)\n * - Individual key: e.g. Fellow (per-user API key)\n */\n readonly shared?: boolean;\n\n /**\n * The Options field name that contains the authentication key (e.g. \"apiKey\").\n * Must reference a `secure: true` field in the Options schema.\n *\n * When set, this connector uses key-based auth instead of OAuth.\n * For individual connectors (`shared` is false), this field is stored\n * per-user rather than in shared config.\n */\n readonly keyOption?: string;\n\n // ---- Optional metadata ----\n\n /**\n * When true, this connector has a single implicit channel.\n * `getChannels()` must return exactly one Channel.\n * The UI will show channel config inline instead of a channel list.\n */\n readonly singleChannel?: boolean;\n\n /**\n * The user-facing noun for this connector's channels — what each\n * {@link Channel} returned by {@link getChannels} actually represents in the\n * external service. Many connectors map \"channels\" onto a domain concept\n * (folders, projects, calendars, labels, spaces, repositories, …), so the\n * generic word \"channel\" reads as jargon. Set this and the UI substitutes it\n * everywhere it would otherwise say \"channel(s)\" — e.g. the per-connection\n * toggle becomes \"Sync new folders\" / \"When a new folder is added, …\".\n *\n * Provide lowercase nouns (the UI capitalizes where needed):\n * `{ singular: \"folder\", plural: \"folders\" }`. Defaults to\n * `{ singular: \"channel\", plural: \"channels\" }` when omitted.\n */\n readonly channelNoun?: { singular: string; plural: string };\n\n /**\n * Whether the per-connection \"Sync new channels\" preference starts ON for\n * newly added connections of this connector. Defaults to `false` (opt-in).\n *\n * Set `true` for connectors that select **all** of their channels by default\n * (i.e. {@link getChannels} returns no channels marked\n * `enabledByDefault: false`). If syncing every channel is the intended\n * default, then channels discovered later should also sync automatically.\n * Leave `false`/omitted for selective connectors that exclude some channels\n * by default (e.g. Gmail syncs only Inbox/Sent, Google Calendar only\n * owner calendars) — for those, a newly discovered channel is just as\n * uncertain and should wait for the user to opt in.\n *\n * Only affects the **default** for new connections; the user's explicit\n * toggle always wins, and existing connections keep their stored preference.\n */\n readonly autoEnableNewChannelsByDefault?: boolean;\n\n /**\n * Whether this connector supports the platform's sequential auto-threading —\n * folding a conversation that arrives as a run of separate top-level messages\n * into a single thread. Set `true` for conversational connectors (chat,\n * messaging) that mark eligible links with {@link NewLink.autoThread}. The UI\n * shows a per-connection \"Group related messages into conversations\" toggle\n * only for connectors that declare this.\n *\n * Leave undefined/false for connectors whose items are not conversational\n * (calendars, issue trackers, file storage) — marking a link does nothing\n * unless the connection both declares support and the user opted in.\n */\n readonly autoThreading?: boolean;\n\n /**\n * Whether the per-connection auto-threading preference starts ON for newly\n * added connections of this connector. Defaults to `false` (opt-in) — the\n * least-surprise default, since a wrong fold is irreversible. Only meaningful\n * when {@link autoThreading} is `true`. The user's explicit toggle always\n * wins, and existing connections keep their stored preference.\n */\n readonly autoThreadingByDefault?: boolean;\n\n /**\n * Registry of link types this connector creates (e.g., issue, event, message).\n * Used for display in the UI (icons, labels, statuses).\n */\n readonly linkTypes?: LinkTypeConfig[];\n\n /**\n * Declares how this connector's platform handles emoji reactions.\n * Used to filter the reaction picker for notes whose primary connector\n * is this one, and to guard outbound dispatch from sending emoji the\n * platform can't accept.\n *\n * Leave undefined for connectors whose platform has no concept of\n * reactions (calendar, file storage, issue trackers without reactions).\n */\n readonly reactionCapabilities?: ReactionCapabilities;\n\n /**\n * When true, this connector's effective link types are computed dynamically\n * from its enabled channels' per-channel link types (each channel carries the\n * link types for whatever product/resource it represents), rather than the\n * static union of all declared providers' link types. Lets one connection\n * surface different link types depending on what the user has enabled — e.g.\n * a combined Google connection shows calendar/event link types (and thus the\n * agenda) only when a calendar channel is enabled.\n *\n * Defaults to false (static link types — the behavior for every connector\n * that doesn't set this). Requires the connector to attach per-channel\n * `linkTypes` on the channels returned by `getChannels`.\n */\n readonly dynamicLinkTypes?: boolean;\n\n /**\n * When true, this connector is mentioned by default on replies to threads it created.\n * When false (default), this connector cannot be mentioned at all.\n *\n * Set this to true for connectors with bidirectional sync (e.g., issue trackers,\n * messaging) where user replies should be written back to the external service.\n */\n static readonly handleReplies?: boolean;\n\n // ---- Account identity (abstract — every connector must implement) ----\n\n /**\n * Returns a human-readable name for the connected account.\n * Shown in the connections list and edit modal to identify this connection.\n *\n * For OAuth connectors, this is typically the workspace or organization name\n * (e.g., \"Acme Corp\" for a Linear workspace). For API key connectors, this\n * could be the workspace name from the external service.\n *\n * Override this in your connector to return a meaningful account name.\n *\n * @param auth - The authorization (null for no-provider connectors)\n * @param token - The access token (null for no-provider connectors)\n * @returns Promise resolving to the account display name\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n getAccountName(\n auth: Authorization | null,\n token: AuthToken | null\n ): Promise<string | null> {\n return Promise.resolve(null);\n }\n\n // ---- Channel lifecycle (abstract — every connector must implement) ----\n\n /**\n * Returns available channels for the authorized actor.\n * Called after OAuth is complete, during the setup/edit modal.\n *\n * @param auth - The completed authorization with provider and actor info\n * @param token - The access token for making API calls\n * @returns Promise resolving to available channels for the user to select\n */\n abstract getChannels(\n auth: Authorization | null,\n token: AuthToken | null\n ): Promise<Channel[]>;\n\n /**\n * Called when a channel resource is enabled for syncing.\n *\n * The framework dispatches this in three cases:\n * 1. **Initial enable** — user toggled the channel on for the first time.\n * 2. **Auto-enable** — `setChannels` discovered a new channel on a\n * connection with `auto_enable_new_channels` set.\n * 3. **Recovery after re-auth** — the user re-authorized a previously-\n * broken connection. The framework calls `onChannelEnabled` for every\n * channel that was already enabled at the time of re-auth, with\n * `context.recovering = true`. See {@link SyncContext.recovering}.\n *\n * Implementations should be **idempotent and overwrite stored state**:\n * the same channel may receive multiple `onChannelEnabled` calls across\n * its lifetime. Use unconditional `this.set()` writes rather than\n * coalesce/skip-if-present logic so a recovery dispatch wipes stale\n * cursors and state from the prior session.\n *\n * **Sync state tracking is automatic.** The framework stamps the\n * connection as \"syncing\" when it dispatches this method and clears\n * that state when:\n * - the connector calls `tools.integrations.channelSyncCompleted(id)`\n * once the initial backfill is done, OR\n * - this method throws an unhandled exception (auto-cleared so the UI\n * doesn't get stuck in \"syncing\" forever).\n *\n * **IMPORTANT: This method runs inline in the HTTP request handler.**\n * Any long-running work (webhook setup, API calls, sync) MUST be queued\n * as a separate task via `this.runTask()`, not executed inline. Blocking\n * here causes the client to spin waiting for the response.\n *\n * Only lightweight operations should appear directly in this method:\n * `this.set()`, `this.get()`, `this.callback()`, and `this.runTask()`.\n *\n * @example\n * ```typescript\n * async onChannelEnabled(channel: Channel, context?: SyncContext): Promise<void> {\n * // Recovery: drop stale cursors so the next sync re-walks history.\n * if (context?.recovering) {\n * await this.clear(`last_sync_token_${channel.id}`);\n * }\n *\n * await this.set(`sync_state_${channel.id}`, { channelId: channel.id });\n *\n * // Queue sync as a task — do NOT use this.run() or call sync methods inline\n * const syncCallback = await this.callback(this.syncBatch, 1, \"full\", channel.id, true);\n * await this.runTask(syncCallback);\n *\n * // Queue webhook setup as a task — do NOT call setupWebhook() inline\n * const webhookCallback = await this.callback(this.setupWebhook, channel.id);\n * await this.runTask(webhookCallback);\n * }\n * ```\n *\n * @param channel - The channel that was enabled\n * @param context - Optional sync context (plan-based hints, recovery flag)\n */\n abstract onChannelEnabled(channel: Channel, context?: SyncContext): Promise<void>;\n\n /**\n * Called when a channel resource is disabled.\n * Should stop sync, clean up webhooks, and remove state.\n *\n * @param channel - The channel that was disabled\n */\n abstract onChannelDisabled(channel: Channel): Promise<void>;\n\n // ---- Write-back hooks (optional, default no-ops) ----\n\n /**\n * Called when a link created by this connector is updated by the user.\n * Override to write back changes to the external service\n * (e.g., changing issue status in Linear when marked done in Plot).\n *\n * @param link - The updated link\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onLinkUpdated(link: Link): Promise<void> {\n return Promise.resolve();\n }\n\n /**\n * Called when a user creates a thread in Plot that should create a new\n * item in this connector's external system.\n *\n * A connector opts in to Plot-initiated creation by declaring a\n * `compose` block on the relevant `LinkTypeConfig` (see\n * {@link ComposeConfig}). When a user picks \"Create new <type>\" from the\n * Add link modal and the thread is synced, the runtime calls this method\n * with the draft fields.\n *\n * Implementations should create the item in the external service and\n * return a `NewLinkWithNotes` describing the created item. The platform\n * attaches the returned link to the originating thread — do not call\n * `integrations.saveLink` yourself.\n *\n * Returning `null` aborts creation silently (the thread is still saved\n * without a link).\n *\n * @param draft - The fields captured in Plot for the new item.\n * @returns The link to attach, or null to abort creation.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onCreateLink(draft: CreateLinkDraft): Promise<NewLinkWithNotes | null> {\n return Promise.resolve(null);\n }\n\n /**\n * Called when a note is created on a thread owned by this connector.\n * Override to write back comments to the external service\n * (e.g., adding a comment to a Linear issue).\n *\n * Returning a string or {@link NoteWriteBackResult} links the Plot note\n * to its external counterpart. A plain string sets the note's `key`.\n * A `NoteWriteBackResult` additionally sets a sync baseline (via\n * `externalContent`) so the next sync-in can recognize the round-tripped\n * content and preserve Plot's formatted version. See\n * {@link NoteWriteBackResult} for details.\n *\n * @param note - The created note\n * @param thread - The thread the note belongs to (includes thread.meta with connector-specific data)\n * @returns Optional note key or NoteWriteBackResult for external dedup + baseline tracking\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onNoteCreated(note: Note, thread: Thread): Promise<string | NoteWriteBackResult | void> {\n return Promise.resolve();\n }\n\n /**\n * Resolve a `fileRef` action's bytes for download. Called when a user opens\n * an attachment in Plot. Return either a redirect URL (preferred for sources\n * that issue signed URLs, like Linear S3 or Slack permalink_public) or a\n * streamed body (required when bytes are only reachable through an\n * authenticated API call, like Gmail attachments.get).\n *\n * @param ref Opaque value the connector previously emitted on a fileRef action.\n * @returns Either `{ redirectUrl }` or `{ body, mimeType, fileName? }`.\n * @throws If the source is unavailable, the connection is broken, or `ref` is invalid.\n *\n * If not overridden, fileRef actions on this connector's notes will return 410 Gone.\n */\n async downloadAttachment(\n ref: string,\n ): Promise<\n | { redirectUrl: string }\n | { body: ReadableStream | Uint8Array; mimeType: string; fileName?: string }\n > {\n throw new Error(\n `downloadAttachment not implemented for ${this.constructor.name} (ref=${ref})`,\n );\n }\n\n /**\n * Called when a note on a thread owned by this connector is updated.\n * Override to write back changes to the external service\n * (e.g., syncing reaction tags as emoji reactions, or editing a comment\n * whose content changed in Plot).\n *\n * Return a {@link NoteWriteBackResult} with `externalContent` to update\n * the sync baseline after a successful write-back, so the next sync-in\n * recognizes the external version as already-seen and preserves Plot's\n * content.\n *\n * @param note - The updated note (includes current tags)\n * @param thread - The thread the note belongs to (includes thread.meta with connector-specific data)\n * @returns Optional NoteWriteBackResult for baseline tracking\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onNoteUpdated(note: Note, thread: Thread): Promise<NoteWriteBackResult | void> {\n return Promise.resolve();\n }\n\n /**\n * Called when a user reads or unreads a thread owned by this connector.\n * Override to write back read status to the external service\n * (e.g., marking an email as read in Gmail).\n *\n * @param thread - The thread that was read/unread (includes thread.meta with connector-specific data)\n * @param actor - The user who performed the action\n * @param unread - false when marked as read, true when marked as unread\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onThreadRead(thread: Thread, actor: Actor, unread: boolean): Promise<void> {\n return Promise.resolve();\n }\n\n /**\n * Called when a user changes the **thread-level sharing** of a thread owned\n * by this connector — adding or removing a contact, or (for connectors with\n * roles) changing a contact's role. Override on connectors whose external\n * source can reflect that membership change, e.g. a group DM / multi-party\n * chat (`LinkTypeConfig.sharingModel: \"thread\"`) or an email's To/Cc/Bcc\n * recipients (`sharingModel: \"message\"`). Connectors backed by an immutable\n * roster (most group DMs today) or by channel-level membership\n * (`sharingModel: \"channel\"`) leave this as the default no-op.\n *\n * `role`/`from`/`to` are **null** for connectors without roles (group DMs\n * have no roles); they carry a `contactRoles` id only for connectors that\n * declare roles (e.g. email `to`/`cc`/`bcc`).\n *\n * The dispatch fires after Plot has persisted the change. A connector may\n * reflect it actively (e.g. add/remove a participant on the external chat)\n * or passively on the next outbound note (e.g. building To/Cc/Bcc headers\n * from the current `thread.contacts` × `thread.contactMeta`) — this callback\n * is not the right place to send a standalone notification.\n *\n * @param thread - The thread whose contacts changed\n * @param changes - The added/removed contacts and any role transitions on existing contacts\n */\n /* eslint-disable @typescript-eslint/no-unused-vars */\n onContactsChanged(\n thread: Thread,\n changes: {\n added: Array<{ contact: Contact; role: string | null }>;\n removed: Array<{ contact: Contact; role: string | null }>;\n changed: Array<{ contact: Contact; from: string | null; to: string | null }>;\n },\n ): Promise<void> {\n return Promise.resolve();\n }\n /* eslint-enable @typescript-eslint/no-unused-vars */\n\n /**\n * Called when a user marks or unmarks a thread as todo.\n * Override to sync todo status to the external service\n * (e.g., starring an email in Gmail when marked as todo).\n *\n * @param thread - The thread (includes thread.meta with connector-specific data)\n * @param actor - The user who changed the todo status\n * @param todo - true when marked as todo, false when done or removed\n * @param options - Additional context\n * @param options.date - The todo date (when todo=true)\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onThreadToDo(thread: Thread, actor: Actor, todo: boolean, options: { date?: Date }): Promise<void> {\n return Promise.resolve();\n }\n\n /**\n * Called when a schedule contact's RSVP status changes on a thread owned by this connector.\n * Override to sync RSVP changes back to the external calendar.\n *\n * @param thread - The thread (includes thread.meta with connector-specific data)\n * @param scheduleId - The schedule ID\n * @param contactId - The contact whose status changed\n * @param status - The new RSVP status ('attend', 'skip', or null)\n * @param actor - The user who changed the status\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onScheduleContactUpdated(thread: Thread, scheduleId: string, contactId: ActorId, status: ScheduleContactStatus | null, actor: Actor): Promise<void> {\n return Promise.resolve();\n }\n\n /**\n * Called when a user adds or removes a single emoji reaction on a note\n * (one event per `(note, actor, emoji)` state transition).\n *\n * Dispatch is routed to the reacting user's own connector instance via\n * `twist_instance_for_actor` on `note_reaction.actor_id`, so this method\n * already runs under the reactor's auth. Fetch the API client with the\n * connector's normal token-fetch path (`this.tools.integrations.get(...)`)\n * and the external write — e.g. Slack `reactions.add` — will be attributed\n * to the correct user. No `actAs` step required.\n *\n * If the reacting user has no connection of this type, no dispatch fires\n * for that reaction (it stays in Plot only).\n *\n * Override to sync per-actor reactions back to the external system.\n *\n * @param note - The note that was reacted on (partial; `id`, `key`, `content` populated)\n * @param thread - The thread the note belongs to (partial; `id`, `title`, `archived`, `meta` populated)\n * @param actor - The contact who added/removed the reaction\n * @param emoji - The emoji (Unicode grapheme or `provider:workspace/name` custom-emoji ref)\n * @param added - `true` if the reaction is now present, `false` if it was removed\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onNoteReactionChanged(note: Note, thread: Thread, actor: Actor, emoji: string, added: boolean): Promise<void> {\n return Promise.resolve();\n }\n\n // ---- Activation ----\n\n /**\n * Called when the connector is activated after OAuth is complete.\n *\n * Connectors receive the authorization in addition to the activating actor.\n * When this runs, `this.userId` is already populated with the installing\n * user's ID.\n *\n * Default implementation does nothing. Override for custom setup.\n *\n * @param context - The activation context\n * @param context.auth - The completed OAuth authorization\n * @param context.actor - The actor who activated the connector\n */\n // @ts-ignore - Connector.activate() has a Connector-specific context type.\n activate(context: { auth?: Authorization; actor?: Actor }): Promise<void> {\n return Promise.resolve();\n }\n}\n\n/** @deprecated Use `Connector` instead. */\nexport { Connector as Source };\n";
|
|
8
|
+
export default "import { type Actor, type ActorId, type Contact, type DeliveryError, type Link, type NewLinkWithNotes, type Note, type Thread, type Uuid } from \"./plot\";\nimport type { ScheduleContactStatus } from \"./schedule\";\nimport {\n type AuthProvider,\n type AuthToken,\n type Authorization,\n type Channel,\n type LinkTypeConfig,\n type SyncContext,\n} from \"./tools/integrations\";\nimport { Twist } from \"./twist\";\n\n/**\n * Declares how a connector's platform handles emoji reactions.\n *\n * Drives Plot UI behavior (e.g. the picker filters the available\n * reactions on notes whose primary connector declares `fixed`) and\n * outbound dispatch (Plot won't try to push an emoji the platform\n * can't accept).\n *\n * Variants:\n * - `open-unicode`: Platform accepts any Unicode emoji. `customEmoji`\n * indicates whether the platform additionally supports workspace\n * custom emoji (Slack, Google Chat).\n * - `unicode-subset`: Platform accepts Unicode but only a finite set.\n * `subset` lists the allowed emoji (omit for \"currently full Unicode\n * per docs, future-proofed for shrinkage\").\n * - `fixed`: Platform only accepts a fixed set (e.g. LinkedIn\n * Messaging's 7-reaction set). `allowed` lists every supported emoji.\n */\nexport type ReactionCapabilities =\n | { mode: \"open-unicode\"; customEmoji?: \"workspace\" | \"none\" }\n | { mode: \"unicode-subset\"; subset?: readonly string[] }\n | { mode: \"fixed\"; allowed: readonly string[] };\n\n/**\n * Result returned from {@link Connector.onNoteCreated} and\n * {@link Connector.onNoteUpdated} to report what the external system now\n * has stored for the note.\n *\n * The runtime hashes `externalContent` and stores it as the note's sync\n * baseline. On the next sync-in, if the incoming content hashes to the\n * same value, the runtime knows the external side hasn't changed and\n * preserves Plot's (possibly formatted) content. When the external side\n * is edited, the hash diverges and the runtime overwrites Plot's content\n * with the new external version.\n *\n * Omitting `externalContent` skips baseline tracking — the next sync-in\n * will overwrite Plot's content (previous behavior). Always provide it\n * when the write-back's return value reflects what the external system\n * actually stored (often lossy plain-text), so the round-trip does not\n * clobber the original Plot markdown.\n *\n * The hash covers only the content string — the runtime intentionally\n * does not include a content-type in the hash, so write-back and sync-in\n * do not have to agree on a content-type label for the same underlying\n * bytes. Return exactly the string your connector's sync-in path will\n * emit as `NewNote.content` for this note on the next re-ingest.\n *\n * For back-compat, `onNoteCreated` may also return a plain string, which\n * is treated as `{ key }` with no baseline.\n */\nexport type NoteWriteBackResult = {\n /**\n * External system identifier assigned to this note. Set as the note's\n * `key` for future upsert matching. Required when the runtime does not\n * already know the key (i.e., from `onNoteCreated`); ignored from\n * `onNoteUpdated` when the key was already established on create.\n */\n key?: string;\n /**\n * The content string as the external system now stores it, post-write.\n * For systems whose write-back returns a representation of what was\n * actually stored (e.g. Google Drive comment `content` after a create),\n * pass that verbatim. For systems that only accept plain text, this\n * will often be a lossy plain-text version of the Plot markdown — that\n * is exactly the point: storing the lossy form as baseline lets the\n * next sync-in recognize it and skip overwriting the richer Plot\n * version.\n *\n * Must exactly match the string your connector's sync-in path emits as\n * `NewNote.content` for this note on re-ingest.\n */\n externalContent?: string;\n /**\n * Reports that the outbound send / write-back for this note FAILED and\n * could not be recovered (after the connector's own retries). The runtime\n * records it on the note — surfacing a \"Failed to send\" affordance (Retry /\n * Discard) to the user — and marks the thread unread.\n *\n * - object → record the failure.\n * - `null` → clear a previously-recorded failure (e.g. a successful retry).\n * - omitted (`undefined`) → leave any existing delivery state untouched.\n *\n * A successful write-back (any result without a `deliveryError`) also clears\n * a previously-recorded failure, so connectors usually only need to SET this\n * on failure.\n *\n * Prefer RETURNING this over throwing for expected, user-visible failures\n * (rejected recipient, message too large, quota exhausted): a thrown error\n * pages error tracking, whereas a returned `deliveryError` does not. Reserve\n * throwing for genuinely unexpected errors. Connectors that simply throw on a\n * failed write-back still get a generic \"Failed to send\" surfaced by the\n * runtime, just without a specific reason.\n */\n deliveryError?: DeliveryError | null;\n};\n\n/**\n * A Plot contact pre-resolved to its platform account ID, ready for use\n * in a messaging dispatch.\n *\n * Populated by the runtime for link types with `compose.targets: \"contacts\"` before\n * `onCreateLink` is called. The connector should use `externalAccountId`\n * directly to address the recipient on the platform (e.g. Slack user ID,\n * LinkedIn URN, Gmail address) without performing its own contact lookup.\n */\nexport type ResolvedRecipient = {\n /** Plot contact UUID */\n id: Uuid;\n /** Display name, or null if not set */\n name: string | null;\n /** Platform-specific account identifier pre-resolved at dispatch time (e.g. Slack `U…`, LinkedIn URN, Gmail email address) */\n externalAccountId: string;\n /**\n * The contact's role on the originating thread, resolved from\n * `thread.contact_meta` against the link type's `contactRoles` (e.g.\n * `\"to\"` / `\"cc\"` / `\"bcc\"` for Gmail). `null` when the contact had no\n * explicit role entry — connectors should treat `null` as the link\n * type's default role (the `contactRoles` entry marked `default: true`).\n *\n * Connectors that distinguish roles MUST honor this when addressing the\n * recipient — e.g. Gmail must place `\"cc\"`/`\"bcc\"` recipients in the\n * Cc/Bcc headers, never the To header, so BCC recipients are not\n * exposed to the other recipients. Connectors that don't distinguish\n * roles (Slack, Linear) can ignore it.\n */\n role: string | null;\n};\n\n/**\n * Fields captured in Plot when a user initiates creation of a new external\n * item via a connector's `onCreateLink` hook.\n *\n * Thread-agnostic on purpose — connectors do not receive the Plot thread.\n * The platform attaches the returned `NewLinkWithNotes` to the originating\n * thread once `onCreateLink` resolves.\n */\nexport type CreateLinkDraft = {\n /** The channel (account + resource) the new item belongs to. */\n channelId: string;\n /** Link type identifier, matches a `LinkTypeConfig.type`. */\n type: string;\n /**\n * Status the user selected. Matches a `statuses[].status` for `type`,\n * or null for status-less link types (the parent linkType declares no\n * `statuses` and no `compose.status`).\n */\n status: string | null;\n /** Title of the originating Plot thread (post AI title generation). */\n title: string;\n /** Markdown content of the thread's first note, or null if none. */\n noteContent: string | null;\n /**\n * Contacts attached to the originating Plot thread, excluding the\n * creating user. Use these as recipients (email, chat DM members, etc.)\n * when the external item is a message or invite. An empty list means\n * the user did not add anyone to the thread.\n *\n * For link types with `compose.targets: \"contacts\"`, prefer `recipients` over\n * re-resolving contacts yourself: the runtime pre-resolves each contact\n * to its platform account ID (`externalAccountId`) and populates\n * `recipients` before `onCreateLink` is called.\n */\n contacts: Actor[];\n /**\n * Pre-resolved recipients for link types whose `compose.targets` is\n * `\"contacts\"` or `\"addresses\"`.\n *\n * Only populated for those link types; otherwise undefined. Each entry contains the Plot\n * contact UUID, the platform-specific account ID\n * (`externalAccountId`) the connector should use to address the\n * recipient without performing its own lookup, and the contact's\n * `role` on the thread (e.g. `\"to\"` / `\"cc\"` / `\"bcc\"`) resolved from\n * `thread.contact_meta`. For `\"addresses\"` link types, contacts without\n * a connection-scoped row fall back to `contact.email`.\n */\n recipients?: ResolvedRecipient[];\n /**\n * Free-form addresses the user typed into the picker (no Plot contact\n * row). Only populated for link types with `compose.targets: \"addresses\"`; otherwise\n * undefined. Connectors should append these alongside `recipients`\n * when constructing the recipient list (e.g. `To:` header for Gmail).\n */\n inviteEmails?: string[];\n};\n\n/** An optional OAuth scope group the user can toggle at connect time. */\nexport type OptionalScopeGroup = {\n /** Stable id used to track the user's selection. */\n id: string;\n /** Value-forward switch label, e.g. \"Add names to events using contacts\". */\n label: string;\n /** Optional secondary line shown under the label. */\n description?: string;\n /** The OAuth scope strings this group grants. */\n scopes: string[];\n /** Whether the group is requested by default (switch on). */\n default: boolean;\n};\n\n/**\n * Structured scope declaration. `required` scopes must be granted — auth fails\n * and re-prompts if any is declined. `optional` groups are requested by default\n * but auth still succeeds if the user declines them; the connector should detect\n * the absence via the granted `token.scopes` and degrade gracefully.\n */\nexport type ScopeConfig = {\n required: string[];\n optional?: OptionalScopeGroup[];\n};\n\n/**\n * Per-instance product metadata for combined (multi-product) connectors — one\n * ordinary `Connector` that bundles several user-facing products (e.g. the\n * combined Google connector covering Mail, Calendar, Tasks, and Contacts) under\n * a single OAuth grant and one charge.\n *\n * The app's combined-connection setup/status UX renders one row per entry. Each\n * product maps to exactly one optional scope group: `scopeGroupId` MUST equal an\n * {@link OptionalScopeGroup.id} declared in the connector's {@link ScopeConfig}\n * `optional` groups, so the API can derive per-product enablement\n * (`granted | scope-missing | no-channels | locally-off`) from the connection's\n * granted scopes plus its enabled channels.\n *\n * Plain (single-product) connectors leave {@link Connector.products} undefined;\n * the API then omits the `products`/`productStatus` fields and the app falls\n * back to the standard per-connector flow.\n */\nexport type ProductInfo = {\n /** Stable product id. Also the channel-id namespace prefix (`\"<key>:<rawId>\"`). */\n key: string;\n /** Setup/status row title (e.g. \"Gmail\"). */\n label: string;\n /** Short summary shown under the label on the setup/status row. */\n description: string;\n /** Icon URL rendered on the row. */\n icon: string;\n /** Matches an {@link OptionalScopeGroup.id} in this connector's scopes. */\n scopeGroupId: string;\n};\n\n/**\n * Base class for connectors — twists that sync data from external services.\n *\n * Connectors declare a single OAuth provider and scopes, and implement channel\n * lifecycle methods for discovering and syncing external resources. They save\n * data directly via `integrations.saveLink()` instead of using the Plot tool.\n *\n * @example\n * ```typescript\n * class LinearConnector extends Connector<LinearConnector> {\n * readonly provider = AuthProvider.Linear;\n * readonly scopes = [\"read\", \"write\"];\n * readonly linkTypes = [{\n * type: \"issue\",\n * label: \"Issue\",\n * statuses: [\n * { status: \"open\", label: \"Open\", icon: \"todo\" },\n * { status: \"done\", label: \"Done\", icon: \"done\", done: true },\n * ],\n * }];\n *\n * build(build: ToolBuilder) {\n * return {\n * integrations: build(Integrations),\n * };\n * }\n *\n * async getChannels(auth: Authorization, token: AuthToken): Promise<Channel[]> {\n * const teams = await this.listTeams(token);\n * return teams.map(t => ({ id: t.id, title: t.name }));\n * }\n *\n * async onChannelEnabled(channel: Channel) {\n * const issues = await this.fetchIssues(channel.id);\n * for (const issue of issues) {\n * await this.tools.integrations.saveLink(issue);\n * }\n * }\n *\n * async onChannelDisabled(channel: Channel) {\n * // Clean up webhooks, sync state, etc.\n * }\n * }\n * ```\n */\nexport abstract class Connector<TSelf> extends Twist<TSelf> {\n /**\n * Static marker to identify Connector subclasses without instanceof checks\n * across worker boundaries.\n */\n static readonly isConnector = true;\n\n // ---- Identity (abstract — every connector must declare) ----\n\n /** The OAuth provider this connector authenticates with. */\n readonly provider?: AuthProvider;\n\n /** OAuth scopes to request for this connector — a flat list (all required), or\n * a {@link ScopeConfig} declaring required + optional scope groups. */\n readonly scopes?: string[] | ScopeConfig;\n\n /**\n * Plain-language bullets describing what access connecting this service\n * grants the user — shown on the connect screen regardless of auth mechanism\n * (OAuth, API key, or hosted). For OAuth connectors it also previews what the\n * provider's consent screen will request. These are justifications for what\n * Plot accesses, not a one-to-one mapping of scope strings.\n */\n readonly access?: string[];\n\n // ---- Auth model ----\n\n /**\n * When true, one credential is shared across all users in the workspace,\n * entered once by the installer. When false (default), each user provides\n * their own credential.\n *\n * Applies to both OAuth and key-based connectors:\n * - Shared OAuth: e.g. Slack bot token (workspace-level)\n * - Shared key: e.g. Attio workspace API key\n * - Individual OAuth: e.g. Google Calendar (per-user)\n * - Individual key: e.g. Fellow (per-user API key)\n */\n readonly shared?: boolean;\n\n /**\n * The Options field name that contains the authentication key (e.g. \"apiKey\").\n * Must reference a `secure: true` field in the Options schema.\n *\n * When set, this connector uses key-based auth instead of OAuth.\n * For individual connectors (`shared` is false), this field is stored\n * per-user rather than in shared config.\n */\n readonly keyOption?: string;\n\n // ---- Optional metadata ----\n\n /**\n * When true, this connector has a single implicit channel.\n * `getChannels()` must return exactly one Channel.\n * The UI will show channel config inline instead of a channel list.\n */\n readonly singleChannel?: boolean;\n\n /**\n * The user-facing noun for this connector's channels — what each\n * {@link Channel} returned by {@link getChannels} actually represents in the\n * external service. Many connectors map \"channels\" onto a domain concept\n * (folders, projects, calendars, labels, spaces, repositories, …), so the\n * generic word \"channel\" reads as jargon. Set this and the UI substitutes it\n * everywhere it would otherwise say \"channel(s)\" — e.g. the per-connection\n * toggle becomes \"Sync new folders\" / \"When a new folder is added, …\".\n *\n * Provide lowercase nouns (the UI capitalizes where needed):\n * `{ singular: \"folder\", plural: \"folders\" }`. Defaults to\n * `{ singular: \"channel\", plural: \"channels\" }` when omitted.\n */\n readonly channelNoun?: { singular: string; plural: string };\n\n /**\n * Whether the per-connection \"Sync new channels\" preference starts ON for\n * newly added connections of this connector. Defaults to `false` (opt-in).\n *\n * Set `true` for connectors that select **all** of their channels by default\n * (i.e. {@link getChannels} returns no channels marked\n * `enabledByDefault: false`). If syncing every channel is the intended\n * default, then channels discovered later should also sync automatically.\n * Leave `false`/omitted for selective connectors that exclude some channels\n * by default (e.g. Gmail syncs only Inbox/Sent, Google Calendar only\n * owner calendars) — for those, a newly discovered channel is just as\n * uncertain and should wait for the user to opt in.\n *\n * Only affects the **default** for new connections; the user's explicit\n * toggle always wins, and existing connections keep their stored preference.\n */\n readonly autoEnableNewChannelsByDefault?: boolean;\n\n /**\n * Whether this connector supports the platform's sequential auto-threading —\n * folding a conversation that arrives as a run of separate top-level messages\n * into a single thread. Set `true` for conversational connectors (chat,\n * messaging) that mark eligible links with {@link NewLink.autoThread}. The UI\n * shows a per-connection \"Group related messages into conversations\" toggle\n * only for connectors that declare this.\n *\n * Leave undefined/false for connectors whose items are not conversational\n * (calendars, issue trackers, file storage) — marking a link does nothing\n * unless the connection both declares support and the user opted in.\n */\n readonly autoThreading?: boolean;\n\n /**\n * Whether the per-connection auto-threading preference starts ON for newly\n * added connections of this connector. Defaults to `false` (opt-in) — the\n * least-surprise default, since a wrong fold is irreversible. Only meaningful\n * when {@link autoThreading} is `true`. The user's explicit toggle always\n * wins, and existing connections keep their stored preference.\n */\n readonly autoThreadingByDefault?: boolean;\n\n /**\n * Registry of link types this connector creates (e.g., issue, event, message).\n * Used for display in the UI (icons, labels, statuses).\n */\n readonly linkTypes?: LinkTypeConfig[];\n\n /**\n * Declares how this connector's platform handles emoji reactions.\n * Used to filter the reaction picker for notes whose primary connector\n * is this one, and to guard outbound dispatch from sending emoji the\n * platform can't accept.\n *\n * Leave undefined for connectors whose platform has no concept of\n * reactions (calendar, file storage, issue trackers without reactions).\n */\n readonly reactionCapabilities?: ReactionCapabilities;\n\n /**\n * When true, this connector's effective link types are computed dynamically\n * from its enabled channels' per-channel link types (each channel carries the\n * link types for whatever product/resource it represents), rather than the\n * static union of all declared providers' link types. Lets one connection\n * surface different link types depending on what the user has enabled — e.g.\n * a combined Google connection shows calendar/event link types (and thus the\n * agenda) only when a calendar channel is enabled.\n *\n * Defaults to false (static link types — the behavior for every connector\n * that doesn't set this). Requires the connector to attach per-channel\n * `linkTypes` on the channels returned by `getChannels`.\n */\n readonly dynamicLinkTypes?: boolean;\n\n /**\n * Per-instance product metadata for combined (multi-product) connectors —\n * one connection bundling several user-facing products under a single OAuth\n * grant (e.g. the combined Google connector: Mail, Calendar, Tasks,\n * Contacts).\n *\n * Each {@link ProductInfo.scopeGroupId} must match an\n * {@link OptionalScopeGroup.id} declared in this connector's {@link scopes}\n * so the API can derive per-product enablement from granted scopes + enabled\n * channels.\n *\n * Leave undefined for plain (single-product) connectors — the API then omits\n * the `products`/`productStatus` response fields and the app uses the\n * standard per-connector flow.\n */\n readonly products?: ProductInfo[];\n\n /**\n * When true, this connector is mentioned by default on replies to threads it created.\n * When false (default), this connector cannot be mentioned at all.\n *\n * Set this to true for connectors with bidirectional sync (e.g., issue trackers,\n * messaging) where user replies should be written back to the external service.\n */\n static readonly handleReplies?: boolean;\n\n // ---- Account identity (abstract — every connector must implement) ----\n\n /**\n * Returns a human-readable name for the connected account.\n * Shown in the connections list and edit modal to identify this connection.\n *\n * For OAuth connectors, this is typically the workspace or organization name\n * (e.g., \"Acme Corp\" for a Linear workspace). For API key connectors, this\n * could be the workspace name from the external service.\n *\n * Override this in your connector to return a meaningful account name.\n *\n * @param auth - The authorization (null for no-provider connectors)\n * @param token - The access token (null for no-provider connectors)\n * @returns Promise resolving to the account display name\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n getAccountName(\n auth: Authorization | null,\n token: AuthToken | null\n ): Promise<string | null> {\n return Promise.resolve(null);\n }\n\n // ---- Channel lifecycle (abstract — every connector must implement) ----\n\n /**\n * Returns available channels for the authorized actor.\n * Called after OAuth is complete, during the setup/edit modal.\n *\n * @param auth - The completed authorization with provider and actor info\n * @param token - The access token for making API calls\n * @returns Promise resolving to available channels for the user to select\n */\n abstract getChannels(\n auth: Authorization | null,\n token: AuthToken | null\n ): Promise<Channel[]>;\n\n /**\n * Called when a channel resource is enabled for syncing.\n *\n * The framework dispatches this in three cases:\n * 1. **Initial enable** — user toggled the channel on for the first time.\n * 2. **Auto-enable** — `setChannels` discovered a new channel on a\n * connection with `auto_enable_new_channels` set.\n * 3. **Recovery after re-auth** — the user re-authorized a previously-\n * broken connection. The framework calls `onChannelEnabled` for every\n * channel that was already enabled at the time of re-auth, with\n * `context.recovering = true`. See {@link SyncContext.recovering}.\n *\n * Implementations should be **idempotent and overwrite stored state**:\n * the same channel may receive multiple `onChannelEnabled` calls across\n * its lifetime. Use unconditional `this.set()` writes rather than\n * coalesce/skip-if-present logic so a recovery dispatch wipes stale\n * cursors and state from the prior session.\n *\n * **Sync state tracking is automatic.** The framework stamps the\n * connection as \"syncing\" when it dispatches this method and clears\n * that state when:\n * - the connector calls `tools.integrations.channelSyncCompleted(id)`\n * once the initial backfill is done, OR\n * - this method throws an unhandled exception (auto-cleared so the UI\n * doesn't get stuck in \"syncing\" forever).\n *\n * **IMPORTANT: This method runs inline in the HTTP request handler.**\n * Any long-running work (webhook setup, API calls, sync) MUST be queued\n * as a separate task via `this.runTask()`, not executed inline. Blocking\n * here causes the client to spin waiting for the response.\n *\n * Only lightweight operations should appear directly in this method:\n * `this.set()`, `this.get()`, `this.callback()`, and `this.runTask()`.\n *\n * @example\n * ```typescript\n * async onChannelEnabled(channel: Channel, context?: SyncContext): Promise<void> {\n * // Recovery: drop stale cursors so the next sync re-walks history.\n * if (context?.recovering) {\n * await this.clear(`last_sync_token_${channel.id}`);\n * }\n *\n * await this.set(`sync_state_${channel.id}`, { channelId: channel.id });\n *\n * // Queue sync as a task — do NOT use this.run() or call sync methods inline\n * const syncCallback = await this.callback(this.syncBatch, 1, \"full\", channel.id, true);\n * await this.runTask(syncCallback);\n *\n * // Queue webhook setup as a task — do NOT call setupWebhook() inline\n * const webhookCallback = await this.callback(this.setupWebhook, channel.id);\n * await this.runTask(webhookCallback);\n * }\n * ```\n *\n * @param channel - The channel that was enabled\n * @param context - Optional sync context (plan-based hints, recovery flag)\n */\n abstract onChannelEnabled(channel: Channel, context?: SyncContext): Promise<void>;\n\n /**\n * Called when a channel resource is disabled.\n * Should stop sync, clean up webhooks, and remove state.\n *\n * @param channel - The channel that was disabled\n */\n abstract onChannelDisabled(channel: Channel): Promise<void>;\n\n // ---- Write-back hooks (optional, default no-ops) ----\n\n /**\n * Called when a link created by this connector is updated by the user.\n * Override to write back changes to the external service\n * (e.g., changing issue status in Linear when marked done in Plot).\n *\n * @param link - The updated link\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onLinkUpdated(link: Link): Promise<void> {\n return Promise.resolve();\n }\n\n /**\n * Called when a user creates a thread in Plot that should create a new\n * item in this connector's external system.\n *\n * A connector opts in to Plot-initiated creation by declaring a\n * `compose` block on the relevant `LinkTypeConfig` (see\n * {@link ComposeConfig}). When a user picks \"Create new <type>\" from the\n * Add link modal and the thread is synced, the runtime calls this method\n * with the draft fields.\n *\n * Implementations should create the item in the external service and\n * return a `NewLinkWithNotes` describing the created item. The platform\n * attaches the returned link to the originating thread — do not call\n * `integrations.saveLink` yourself.\n *\n * Returning `null` aborts creation silently (the thread is still saved\n * without a link).\n *\n * @param draft - The fields captured in Plot for the new item.\n * @returns The link to attach, or null to abort creation.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onCreateLink(draft: CreateLinkDraft): Promise<NewLinkWithNotes | null> {\n return Promise.resolve(null);\n }\n\n /**\n * Called when a note is created on a thread owned by this connector.\n * Override to write back comments to the external service\n * (e.g., adding a comment to a Linear issue).\n *\n * Returning a string or {@link NoteWriteBackResult} links the Plot note\n * to its external counterpart. A plain string sets the note's `key`.\n * A `NoteWriteBackResult` additionally sets a sync baseline (via\n * `externalContent`) so the next sync-in can recognize the round-tripped\n * content and preserve Plot's formatted version. See\n * {@link NoteWriteBackResult} for details.\n *\n * @param note - The created note\n * @param thread - The thread the note belongs to (includes thread.meta with connector-specific data)\n * @returns Optional note key or NoteWriteBackResult for external dedup + baseline tracking\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onNoteCreated(note: Note, thread: Thread): Promise<string | NoteWriteBackResult | void> {\n return Promise.resolve();\n }\n\n /**\n * Resolve a `fileRef` action's bytes for download. Called when a user opens\n * an attachment in Plot. Return either a redirect URL (preferred for sources\n * that issue signed URLs, like Linear S3 or Slack permalink_public) or a\n * streamed body (required when bytes are only reachable through an\n * authenticated API call, like Gmail attachments.get).\n *\n * @param ref Opaque value the connector previously emitted on a fileRef action.\n * @returns Either `{ redirectUrl }` or `{ body, mimeType, fileName? }`.\n * @throws If the source is unavailable, the connection is broken, or `ref` is invalid.\n *\n * If not overridden, fileRef actions on this connector's notes will return 410 Gone.\n */\n async downloadAttachment(\n ref: string,\n ): Promise<\n | { redirectUrl: string }\n | { body: ReadableStream | Uint8Array; mimeType: string; fileName?: string }\n > {\n throw new Error(\n `downloadAttachment not implemented for ${this.constructor.name} (ref=${ref})`,\n );\n }\n\n /**\n * Called when a note on a thread owned by this connector is updated.\n * Override to write back changes to the external service\n * (e.g., syncing reaction tags as emoji reactions, or editing a comment\n * whose content changed in Plot).\n *\n * Return a {@link NoteWriteBackResult} with `externalContent` to update\n * the sync baseline after a successful write-back, so the next sync-in\n * recognizes the external version as already-seen and preserves Plot's\n * content.\n *\n * @param note - The updated note (includes current tags)\n * @param thread - The thread the note belongs to (includes thread.meta with connector-specific data)\n * @returns Optional NoteWriteBackResult for baseline tracking\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onNoteUpdated(note: Note, thread: Thread): Promise<NoteWriteBackResult | void> {\n return Promise.resolve();\n }\n\n /**\n * Called when a user reads or unreads a thread owned by this connector.\n * Override to write back read status to the external service\n * (e.g., marking an email as read in Gmail).\n *\n * @param thread - The thread that was read/unread (includes thread.meta with connector-specific data)\n * @param actor - The user who performed the action\n * @param unread - false when marked as read, true when marked as unread\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onThreadRead(thread: Thread, actor: Actor, unread: boolean): Promise<void> {\n return Promise.resolve();\n }\n\n /**\n * Called when a user changes the **thread-level sharing** of a thread owned\n * by this connector — adding or removing a contact, or (for connectors with\n * roles) changing a contact's role. Override on connectors whose external\n * source can reflect that membership change, e.g. a group DM / multi-party\n * chat (`LinkTypeConfig.sharingModel: \"thread\"`) or an email's To/Cc/Bcc\n * recipients (`sharingModel: \"message\"`). Connectors backed by an immutable\n * roster (most group DMs today) or by channel-level membership\n * (`sharingModel: \"channel\"`) leave this as the default no-op.\n *\n * `role`/`from`/`to` are **null** for connectors without roles (group DMs\n * have no roles); they carry a `contactRoles` id only for connectors that\n * declare roles (e.g. email `to`/`cc`/`bcc`).\n *\n * The dispatch fires after Plot has persisted the change. A connector may\n * reflect it actively (e.g. add/remove a participant on the external chat)\n * or passively on the next outbound note (e.g. building To/Cc/Bcc headers\n * from the current `thread.contacts` × `thread.contactMeta`) — this callback\n * is not the right place to send a standalone notification.\n *\n * @param thread - The thread whose contacts changed\n * @param changes - The added/removed contacts and any role transitions on existing contacts\n */\n /* eslint-disable @typescript-eslint/no-unused-vars */\n onContactsChanged(\n thread: Thread,\n changes: {\n added: Array<{ contact: Contact; role: string | null }>;\n removed: Array<{ contact: Contact; role: string | null }>;\n changed: Array<{ contact: Contact; from: string | null; to: string | null }>;\n },\n ): Promise<void> {\n return Promise.resolve();\n }\n /* eslint-enable @typescript-eslint/no-unused-vars */\n\n /**\n * Called when a user marks or unmarks a thread as todo.\n * Override to sync todo status to the external service\n * (e.g., starring an email in Gmail when marked as todo).\n *\n * @param thread - The thread (includes thread.meta with connector-specific data)\n * @param actor - The user who changed the todo status\n * @param todo - true when marked as todo, false when done or removed\n * @param options - Additional context\n * @param options.date - The todo date (when todo=true)\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onThreadToDo(thread: Thread, actor: Actor, todo: boolean, options: { date?: Date }): Promise<void> {\n return Promise.resolve();\n }\n\n /**\n * Called when a schedule contact's RSVP status changes on a thread owned by this connector.\n * Override to sync RSVP changes back to the external calendar.\n *\n * @param thread - The thread (includes thread.meta with connector-specific data)\n * @param scheduleId - The schedule ID\n * @param contactId - The contact whose status changed\n * @param status - The new RSVP status ('attend', 'skip', or null)\n * @param actor - The user who changed the status\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onScheduleContactUpdated(thread: Thread, scheduleId: string, contactId: ActorId, status: ScheduleContactStatus | null, actor: Actor): Promise<void> {\n return Promise.resolve();\n }\n\n /**\n * Called when a user adds or removes a single emoji reaction on a note\n * (one event per `(note, actor, emoji)` state transition).\n *\n * Dispatch is routed to the reacting user's own connector instance via\n * `twist_instance_for_actor` on `note_reaction.actor_id`, so this method\n * already runs under the reactor's auth. Fetch the API client with the\n * connector's normal token-fetch path (`this.tools.integrations.get(...)`)\n * and the external write — e.g. Slack `reactions.add` — will be attributed\n * to the correct user. No `actAs` step required.\n *\n * If the reacting user has no connection of this type, no dispatch fires\n * for that reaction (it stays in Plot only).\n *\n * Override to sync per-actor reactions back to the external system.\n *\n * @param note - The note that was reacted on (partial; `id`, `key`, `content` populated)\n * @param thread - The thread the note belongs to (partial; `id`, `title`, `archived`, `meta` populated)\n * @param actor - The contact who added/removed the reaction\n * @param emoji - The emoji (Unicode grapheme or `provider:workspace/name` custom-emoji ref)\n * @param added - `true` if the reaction is now present, `false` if it was removed\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onNoteReactionChanged(note: Note, thread: Thread, actor: Actor, emoji: string, added: boolean): Promise<void> {\n return Promise.resolve();\n }\n\n // ---- Activation ----\n\n /**\n * Called when the connector is activated after OAuth is complete.\n *\n * Connectors receive the authorization in addition to the activating actor.\n * When this runs, `this.userId` is already populated with the installing\n * user's ID.\n *\n * Default implementation does nothing. Override for custom setup.\n *\n * @param context - The activation context\n * @param context.auth - The completed OAuth authorization\n * @param context.actor - The actor who activated the connector\n */\n // @ts-ignore - Connector.activate() has a Connector-specific context type.\n activate(context: { auth?: Authorization; actor?: Actor }): Promise<void> {\n return Promise.resolve();\n }\n}\n\n/** @deprecated Use `Connector` instead. */\nexport { Connector as Source };\n";
|
|
@@ -5,4 +5,4 @@
|
|
|
5
5
|
* Generated from: prebuild.ts
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
export default "import {\n type Actor,\n type ActorId,\n type NewContact,\n type NewLinkWithNotes,\n type NewNote,\n ITool,\n} from \"..\";\nimport type { JSONValue } from \"../utils/types\";\nimport type { Uuid } from \"../utils/uuid\";\n\n/**\n * A resource that can be synced (e.g., a calendar, project, channel).\n * Returned by getChannels() and managed by users in the twist setup/edit modal.\n */\nexport type Channel = {\n /** External ID shared across users (e.g., Google calendar ID) */\n id: string;\n /** Display name shown in the UI */\n title: string;\n /**\n * Whether this channel should be selected by default when the user first\n * adds the connection. Tri-state:\n * - `true` — pre-select it (e.g. the user's own/primary calendar).\n * - `false` — exclude it from the default selection (low-value or\n * irrelevant resources that would crowd the user's view, or containers\n * whose contents are too broad to sync wholesale — e.g. a holiday or\n * someone-else's shared calendar, a GitHub org that cascades to every\n * repo, a Microsoft Teams team container). The user can still enable it\n * manually.\n * - `undefined` — no opinion; the client decides. The client defaults to\n * enabling the channel unless its title looks low-value (holidays,\n * birthdays, spam/sent/draft, …).\n *\n * The guiding principle is \"sync everything the user would reasonably want\n * by default\" — for most connectors that's all channels, so only set this\n * where the connector can distinguish the user's own/relevant channels from\n * low-value ones (e.g. Google Calendar via `accessRole === \"owner\"`).\n */\n enabledByDefault?: boolean;\n /** Optional nested channel resources (e.g., subfolders) */\n children?: Channel[];\n /** Per-channel link type configs. Overrides twist-level linkTypes when present. */\n linkTypes?: LinkTypeConfig[];\n};\n\n/**\n * Curated status-icon vocabulary. Connectors map each declared status to the\n * closest icon; clients render a single glyph per value. Required on every\n * status so the UI always has something to show.\n */\nexport type StatusIcon =\n | \"backlog\"\n | \"todo\"\n | \"inProgress\"\n | \"blocked\"\n | \"done\"\n | \"cancelled\"\n | \"confirmed\"\n | \"tentative\";\n\n/**\n * Describes a link type that a connector creates.\n * Used for display in the UI (icons, labels).\n */\nexport type LinkTypeConfig = {\n /** Machine-readable type identifier (e.g., \"issue\", \"pull_request\") */\n type: string;\n /** Human-readable label (e.g., \"Issue\", \"Pull Request\") */\n label: string;\n /**\n * Connector's word for a note on a linked item of this type — used by the\n * Flutter app to adapt note/composer copy (\"Add a comment\" on Linear,\n * \"Add a message\" on Slack, \"Add a reply\" on Gmail). Defaults to \"note\"\n * when omitted. Use the singular noun in title case (e.g. \"Comment\").\n */\n noteLabel?: string;\n /**\n * Placeholder shown in the editor when this link type is the target of a\n * new thread (NewThreadPage). Example: \"Send a Gmail email\".\n * If unset, Plot derives \"Create a new {connector} {label.toLowerCase()}\".\n */\n composePlaceholder?: string;\n /**\n * Label for the Send button on NewThreadPage when this link type is the\n * target. Example: \"Send\". If unset, defaults to \"Create\".\n */\n composeVerb?: string;\n /**\n * Placeholder shown in the in-thread editor for the default reply mode.\n * Example: \"Reply\" (Gmail), \"Add a comment\" (Linear). If unset, Plot derives\n * \"Add a {noteLabel.toLowerCase()}\" or \"Add a note\".\n */\n replyPlaceholder?: string;\n /**\n * Label for the Send button in the in-thread editor. Example: \"Send\"\n * (Gmail), \"Comment\" (Linear). If unset, defaults to \"Send\".\n */\n replyVerb?: string;\n /** URL to an icon for this link type (light mode). Prefer Iconify `logos/*` URLs. */\n logo?: string;\n /** URL to an icon for dark mode. Use when the default logo is invisible on dark backgrounds (e.g., Iconify `simple-icons/*` with `?color=`). */\n logoDark?: string;\n /** URL to a monochrome icon (uses `currentColor`). Prefer Iconify `simple-icons/*` URLs without a `?color=` param. */\n logoMono?: string;\n /** Possible status values for this type */\n statuses?: Array<{\n /** Machine-readable status (e.g., \"open\", \"done\") */\n status: string;\n /** Human-readable label (e.g., \"Open\", \"Done\") */\n label: string;\n /** Curated icon for this status (required so the UI always has a glyph). */\n icon: StatusIcon;\n /**\n * Suppress this status's icon on the feed row (ThreadWidget) while still\n * showing it in the ThreadPage header. Use for a \"resting\" default state\n * that would otherwise clutter the feed (e.g. calendar \"Confirmed\").\n */\n hiddenDefault?: boolean;\n /** Whether this status represents completion (done, closed, merged, cancelled, etc.) */\n done?: boolean;\n /**\n * Mark the thread `active=true` in Plot when a link enters this status.\n * Use for messaging-style flags where the user has indicated they want\n * to act on the thread now — Gmail's \"starred\", Slack's \"later\", etc.\n * The Plot user can later un-flag the thread without breaking the\n * connector relationship.\n */\n active?: boolean;\n /**\n * Marks this status as the connector's \"to-do\" / active state. When a\n * user brings a done thread back into Plot's agenda, done-status links\n * are flipped to the status marked `todo: true` (e.g. Gmail's \"starred\",\n * Linear's \"unstarted\"); connectors that don't mark one fall back to the\n * first non-done status.\n */\n todo?: boolean;\n }>;\n /** Whether this link type supports displaying and changing the assignee */\n supportsAssignee?: boolean;\n /**\n * Whether this link type produces time-anchored schedule/agenda items\n * (i.e. calendar events). The Plot app shows the agenda (the bottom-nav\n * tab on mobile and the left-sidebar agenda on desktop) only when the\n * user has at least one active connection whose link types include one\n * with `includesSchedules: true`. Calendar connectors (Google / Apple /\n * Outlook Calendar) set this on their `event` link type. Defaults to\n * false — non-calendar link types (messages, issues, tasks, docs) omit it.\n */\n includesSchedules?: boolean;\n /** Default thread creation mode for this link type: 'all' | 'actionable' | 'manual' */\n defaultCreateThreads?: string;\n /**\n * Opt-in: declares this link type is composable from Plot via\n * `Connector.onCreateLink`. Omit to make the link type sync-only (no\n * \"Create new …\" picker entry).\n *\n * Connectors that need multiple compose modes for what users perceive as\n * the same kind of thing (e.g. Slack channel post vs DM) should declare\n * **separate linkTypes**, one per user-facing thread type. That keeps\n * each linkType isomorphic to one filter chip.\n */\n compose?: ComposeConfig;\n /**\n * Per-connector contact roles. Examples:\n * email → [{id:\"to\",label:\"To\",default:true},{id:\"cc\",label:\"CC\"},{id:\"bcc\",label:\"BCC\",hidden:true}]\n * calendar → [{id:\"required\",label:\"Required\",default:true},{id:\"optional\",label:\"Optional\"}]\n *\n * Plot uses this list to render a role picker on each contact chip in the\n * composer and to label non-default roles on existing threads. Exactly one\n * role should be marked `default: true`. Connectors that don't distinguish\n * roles (Slack, Linear) omit this field entirely.\n */\n contactRoles?: ContactRoleConfig[];\n /**\n * Whether contacts on an existing thread can be added, removed, or have\n * their role changed (email-style mid-thread recipient changes). When\n * false, the thread's contact list is fixed after creation. Defaults to\n * false when omitted.\n */\n supportsContactChanges?: boolean;\n /**\n * Whether a note/reply on this link type can carry a link (a pasted URL or\n * connector-created item) that Plot forwards to the source. When false (the\n * default), the \"Add link\" button is hidden for threads of this link type.\n * Only set true if the connector's reply path actually forwards the link\n * action to the source. Private Plot notes (no link type) always allow links.\n */\n supportsLinks?: boolean;\n /**\n * Whether a note/reply on this link type can carry an uploaded file that Plot\n * forwards to the source as an attachment. When false (the default), the\n * \"Attach file\" button is hidden for threads of this link type. Only set true\n * if the connector's reply path actually uploads file actions to the source.\n * Private Plot notes (no link type) always allow attachments.\n */\n supportsFileAttachments?: boolean;\n /**\n * Declares how sharing on threads of this link type is scoped:\n *\n * - `\"thread\"` (default): one roster shared across all notes in the\n * thread. Native Plot threads, Slack DMs, calendar events.\n * - `\"channel\"`: visibility is the external channel's membership;\n * the per-thread `contacts` array is ignored for sharing UI.\n * Slack channels, Linear projects.\n * - `\"message\"`: each note carries its own recipient set via\n * `note.access_contacts`; the thread roster is the union across\n * all messages. Email.\n * - `\"none\"`: the link type has no recipient roster at all. No\n * contacts/sharing UI is shown for these threads. Use for purely\n * personal destinations with no sharing concept (e.g. Google\n * Tasks). The per-thread `contacts` array is ignored for sharing UI.\n *\n * Omit to default to `\"thread\"`. When set to `\"message\"`, every\n * note this connector ingests must populate `access_contacts`\n * explicitly (never NULL).\n */\n sharingModel?: \"thread\" | \"channel\" | \"message\" | \"none\";\n};\n\n/**\n * Declares how a link type is composable from Plot via\n * `Connector.onCreateLink`. Attached to {@link LinkTypeConfig.compose}.\n */\nexport type ComposeConfig = {\n /**\n * Selects the destination model for the \"Create new …\" picker.\n *\n * - `\"channels\"` (default): one chip per enabled channel (e.g. a Linear\n * team, a Slack channel). Existing behaviour for task-tracker / calendar\n * connectors.\n * - `\"contacts\"`: one chip per connection (account); the user picks\n * recipients from their contacts. The runtime pre-resolves the chosen\n * Plot contacts to platform account IDs via the per-connection\n * `contact_external_account` rows and delivers them as\n * `CreateLinkDraft.recipients`. Contacts without a row for this specific\n * connection are filtered out of the picker — used by closed-roster\n * messaging platforms (Slack DM, Teams DM, Google Chat DM, LinkedIn DM).\n * - `\"addresses\"`: one chip per connection; the picker accepts any\n * contact with an addressable identifier (e.g. an email) or a free-form\n * typed address. The runtime fills `recipients` for contacts with a\n * connection-scoped row and falls back to the contact's primary address\n * (e.g. `contact.email`) when no row exists. Free-form addresses arrive\n * via the thread's `inviteEmails`. Used by open address spaces like\n * Gmail.\n */\n targets?: \"channels\" | \"contacts\" | \"addresses\";\n /**\n * Status to assign newly-created links. Should match an entry in the\n * parent linkType's `statuses[]`, OR a symbolic id that the connector's\n * `onCreateLink` resolves itself (e.g. Linear's `\"unstarted\"` category is\n * resolved per-team to a state UUID inside the connector — see\n * `connectors/linear/src/linear.ts`).\n *\n * Omit for status-less link types (e.g. messaging connectors that don't\n * model a status): composed links are created with no status.\n */\n status?: string;\n /**\n * Optional override for the picker chip / \"Create new …\" copy. Defaults\n * to the parent linkType's `label`. Use to disambiguate compose entries\n * when the parent label alone isn't specific enough (e.g. \"Direct\n * messages\" for a DM-mode compose on a chat connector).\n */\n label?: string;\n};\n\n/**\n * Declares one contact role for a connector's link type. See\n * `LinkTypeConfig.contactRoles`.\n */\nexport type ContactRoleConfig = {\n /** Stable machine id, e.g. \"to\" / \"cc\" / \"bcc\" / \"required\" / \"optional\". */\n id: string;\n /** Display label shown next to a contact chip, e.g. \"To\", \"CC\", \"Required\". */\n label: string;\n /** Exactly one role per linkType should be marked default. */\n default?: boolean;\n /**\n * Hidden roles are visible only to (a) the contact themselves and\n * (b) the user who added them. The API filters them out of every other\n * viewer's `thread.contacts` and `thread.contactMeta`. Use for BCC-style\n * semantics where other recipients must not see the hidden contact.\n */\n hidden?: boolean;\n};\n\n/**\n * Context passed to onChannelEnabled with plan-based sync hints.\n * Connectors can use these hints to limit initial sync scope.\n */\nexport type SyncContext = {\n /**\n * Earliest date to include in initial sync, based on the user's plan.\n *\n * Non-calendar connectors should use this as their date filter (timeMin,\n * created.gte, etc.) during initial sync. Calendar connectors should\n * ignore this for API queries (to avoid missing recurring events) — the\n * API layer filters non-recurring items automatically.\n *\n * Undefined when no limit applies.\n */\n syncHistoryMin?: Date;\n\n /**\n * True when this is a recovery dispatch after the connection's auth was\n * restored (the user re-authorized a previously-broken connection).\n *\n * The framework calls `onChannelEnabled` again for every channel that was\n * already enabled at the time of re-auth so the connector can recover from\n * the auth gap. Connectors should:\n *\n * 1. Drop any persisted incremental sync cursors / sync tokens so the\n * next sync re-walks history (the cursor may be stale or invalid —\n * Google Calendar invalidates syncTokens after ~7 days).\n * 2. Re-register webhooks (any prior subscription may have been\n * invalidated during the auth outage).\n * 3. Treat this as a backfill that walks history but does NOT spam\n * notifications — set `unread: false` and `archived: false` on\n * items as you would during initial sync.\n *\n * Most connectors can take the same code path as a fresh\n * `onChannelEnabled` for `recovering: true` as long as that path\n * overwrites stored state rather than appending to it.\n */\n recovering?: boolean;\n\n /**\n * True when the channel is being observed because the user composed a Plot\n * thread INTO it (via `onCreateLink`), not because they explicitly enabled\n * it. The connector should register webhooks / mark the channel observed so\n * inbound events (replies, reactions) on the composed thread sync back —\n * but must NOT backfill history. Only go-forward events matter; pulling the\n * channel's existing content would be surprising for a channel the user\n * only posted one thread into.\n *\n * Connectors whose `onChannelEnabled` already skips historical backfill can\n * ignore this flag. Connectors that initial-sync on enable MUST short-\n * circuit that backfill when `observeOnly` is true (still set up webhooks\n * and any go-forward state).\n */\n observeOnly?: boolean;\n};\n\n/**\n * Built-in tool for managing OAuth authentication and channel resources.\n *\n * The Integrations tool:\n * 1. Manages channel resources (calendars, projects, etc.) per actor\n * 2. Returns tokens for the user who enabled sync on a channel\n * 3. Supports per-actor auth via actAs() for write-back operations\n * 4. Provides saveLink/saveContacts for Connectors to save data directly\n *\n * Connectors declare their provider, scopes, and channel lifecycle methods as\n * class properties and methods. The Integrations tool reads these automatically.\n * Auth and channel management is handled in the twist edit modal in Flutter.\n *\n * @example\n * ```typescript\n * class CalendarConnector extends Connector<CalendarConnector> {\n * readonly provider = AuthProvider.Google;\n * readonly scopes = [\"https://www.googleapis.com/auth/calendar\"];\n *\n * build(build: ToolBuilder) {\n * return {\n * integrations: build(Integrations),\n * };\n * }\n *\n * async getChannels(auth: Authorization, token: AuthToken): Promise<Channel[]> {\n * const calendars = await this.listCalendars(token);\n * return calendars.map(c => ({ id: c.id, title: c.name }));\n * }\n *\n * async onChannelEnabled(channel: Channel) {\n * // Start syncing\n * }\n *\n * async onChannelDisabled(channel: Channel) {\n * // Stop syncing\n * }\n * }\n * ```\n */\nexport abstract class Integrations extends ITool {\n /**\n * Merge scopes from multiple tools, deduplicating.\n *\n * @param scopeArrays - Arrays of scopes to merge\n * @returns Deduplicated array of scopes\n */\n static MergeScopes(...scopeArrays: string[][]): string[] {\n return Array.from(new Set(scopeArrays.flat()));\n }\n\n /**\n * Retrieves an access token for a channel resource.\n *\n * Returns the token of the user who enabled sync on the given channel.\n * If the channel is not enabled or the token is expired/invalid, returns null.\n *\n * @param channelId - The channel resource ID (e.g., calendar ID)\n * @returns Promise resolving to the access token or null\n */\n abstract get(channelId: string): Promise<AuthToken | null>;\n /**\n * Retrieves an access token for a channel resource.\n *\n * @param provider - The OAuth provider (deprecated, ignored for single-provider connectors)\n * @param channelId - The channel resource ID (e.g., calendar ID)\n * @returns Promise resolving to the access token or null\n * @deprecated Use get(channelId) instead. The provider is implicit from the connector.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n abstract get(provider: AuthProvider, channelId: string): Promise<AuthToken | null>;\n\n /**\n * Saves a link with notes to the connector's focus.\n *\n * Creates a thread+link pair. The thread is a lightweight container;\n * the link holds the external entity data (source, meta, type, status, etc.).\n *\n * This method is available only to Connectors (not regular Twists).\n *\n * @param link - The link with notes to save\n * @returns Promise resolving to the saved thread's UUID, or null if the\n * link was filtered out (e.g. older than the plan's sync history limit)\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n abstract saveLink(link: NewLinkWithNotes): Promise<Uuid | null>;\n\n /**\n * Batch version of {@link saveLink} — saves many links in one call.\n *\n * Connectors syncing many items per page (e.g. calendar events, issues,\n * messages) should prefer this over looping `saveLink`. Each `saveLink`\n * crosses the runtime boundary and counts against the per-execution\n * request budget; `saveLinks` collapses N saves into a single crossing.\n *\n * Failures on individual links DO NOT abort the batch. A bad item lands\n * as `null` in its slot and the rest still save. This prevents one\n * malformed record from losing an entire page of sync progress.\n *\n * This method is available only to Connectors (not regular Twists).\n *\n * @param links - Array of links with notes to save\n * @returns Array of the same length and order as `links`. Each entry is\n * the saved thread's UUID, or `null` if the link was filtered out\n * (e.g. older than the plan's sync history limit) OR failed to save.\n * The two null causes are not distinguished; the save failure is\n * logged server-side.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n abstract saveLinks(links: NewLinkWithNotes[]): Promise<(Uuid | null)[]>;\n\n /**\n * Save one or more notes. Unlike saveLink (which creates a thread-level\n * canonical link), these notes attach to an EXISTING thread — addressed by\n * `note.thread: { id }` or `{ source }` — and may carry their own\n * note-attached link via `note.link` (a note-scoped link, NOT a thread-level\n * canonical link). When `{ source }` resolves to no thread yet, the runtime\n * find-or-creates the thread by that source. Use for augmenter content\n * (e.g. meeting notes attached to a calendar event).\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n abstract saveNotes(notes: NewNote[]): Promise<(Uuid | null)[]>;\n /** Save a single note. See {@link saveNotes}. */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n abstract saveNote(note: NewNote): Promise<Uuid | null>;\n /**\n * Archive every note this connector created (optionally scoped to a channel),\n * plus their note-attached links. Mirror of {@link archiveLinks} for the\n * note-attached content model. Use in `onChannelDisabled`.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n abstract archiveNotes(filter: ArchiveNotesFilter): Promise<void>;\n\n /**\n * Upserts contacts into the connector's focus without requiring a Link.\n *\n * Use this for messaging connectors to bulk-sync workspace members so the\n * recipient picker can filter contacts by reachable platform account. Populate\n * `NewContact.source` to persist `contact_external_account` rows (the platform\n * identity used to address the contact). Returns one `Actor` per input, in order.\n *\n * @param contacts - Contacts to upsert, keyed by `source`/`key`\n * @returns Promise resolving to the saved actors, 1:1 with input order\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n abstract saveContacts(contacts: NewContact[]): Promise<Actor[]>;\n\n /**\n * Archives links matching the given filter that were created by this connector.\n *\n * For each archived link's thread, if no other non-archived links remain,\n * the thread is also archived.\n *\n * @param filter - Filter criteria for which links to archive\n * @returns Promise that resolves when archiving is complete\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n abstract archiveLinks(filter: ArchiveLinkFilter): Promise<void>;\n\n /**\n * Sets or clears todo status on a thread owned by this connector.\n *\n * @param source - The link source URL identifying the thread\n * @param actorId - The user to set the todo for\n * @param todo - true to mark as todo, false to clear/complete\n * @param options - Additional options\n * @param options.date - The todo date (when todo=true). Defaults to today.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n abstract setThreadToDo(\n source: string,\n actorId: ActorId,\n todo: boolean,\n options?: { date?: Date | string }\n ): Promise<void>;\n\n /**\n * Signal that initial bulk-sync (or recovery sync) for a channel is fully\n * complete. The Flutter app uses this to clear the \"syncing…\" indicator\n * on the connection.\n *\n * The framework automatically marks a channel as syncing when it dispatches\n * `onChannelEnabled` (whether initial-enable, auto-enable from\n * `setChannels`, or recovery after re-auth). Connectors do NOT need to\n * call anything to start tracking — only to signal completion.\n *\n * Call this exactly once when the initial backfill has finished (no more\n * pages, all phases exhausted). Do NOT call it on every incremental sync.\n *\n * If `onChannelEnabled` throws an unhandled exception, the framework\n * automatically clears the syncing state — connectors don't need a\n * `try/catch` to clear state on failure.\n *\n * No-op when no auth/user mapping exists for the channel (e.g. key-based\n * connectors that don't have a per-user OAuth association).\n *\n * @param channelId - The channel resource ID whose initial sync just finished\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n abstract channelSyncCompleted(channelId: string): Promise<void>;\n\n /**\n * Flag a connection as needing re-authentication so the Flutter app\n * surfaces a re-auth prompt on the next sync.\n *\n * Call this when a connector's API call returns a permanent auth-style\n * error that the runtime can't observe through token refresh — e.g.\n * Slack `invalid_auth` / `token_revoked` / `not_authed`, or a 401 on a\n * provider that doesn't refresh. The runtime already flags reauth\n * automatically when an OAuth refresh permanently fails or when the\n * stored token is missing on a get(); only call this for cases the\n * runtime can't see.\n *\n * Idempotent: safe to call repeatedly; existing reauth flags are not\n * overwritten. No-op when the channel has no `enabledBy` actor (e.g.\n * key-based connectors).\n *\n * @param channelId - The channel resource ID whose token is bad\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n abstract markNeedsReauth(channelId: string): Promise<void>;\n\n /**\n * Upsert workspace custom emoji into Plot's shared cache so reactions using\n * `provider:workspace/name` refs render as images and round-trip. Idempotent;\n * keyed on `id`. Pass `archived: true` to mark an emoji removed. Workspace-\n * scoped (shared across all users of that workspace).\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n abstract saveCustomEmoji(emoji: NewCustomEmoji[]): Promise<void>;\n\n}\n\n/**\n * Filter criteria for archiving links.\n * All fields are optional; only provided fields are used for matching.\n */\nexport type ArchiveLinkFilter = {\n /** Filter by channel ID */\n channelId?: string;\n /** Filter by link type (e.g., \"issue\", \"pull_request\") */\n type?: string;\n /** Filter by link status (e.g., \"open\", \"closed\") */\n status?: string;\n /** Filter by metadata fields (uses containment matching) */\n meta?: Record<string, JSONValue>;\n};\n\n/**\n * Filter criteria for archiving notes (and their note-attached links).\n * All fields are optional; only provided fields are used for matching.\n */\nexport type ArchiveNotesFilter = {\n /** Restrict to notes whose note-attached link is on this channel. */\n channelId?: string;\n};\n\n/**\n * A workspace custom emoji to cache so Plot can render and round-trip it as a\n * reaction. `id` is the provider-scoped ref stored on reactions, of the form\n * `<provider>:<workspace>/<name>` (e.g. `slack:T0123ABC/party_parrot`).\n */\nexport type NewCustomEmoji = {\n /** Provider-scoped ref: `<provider>:<workspace>/<name>`. The reaction value. */\n id: string;\n /** e.g. \"slack\". */\n provider: string;\n /** Provider workspace/team id (e.g. Slack team id `T0123ABC`). */\n workspace: string;\n /** Bare emoji name without colons (e.g. \"party_parrot\"). */\n name: string;\n /** Image URL to render, or null for an alias (see `aliasOf`). */\n imageUrl: string | null;\n /** When this emoji aliases another, the target ref (`id` of the canonical emoji); else null. */\n aliasOf: string | null;\n /** True to mark the emoji removed (archive it) rather than upsert it. */\n archived: boolean;\n};\n\n/**\n * Enumeration of supported OAuth providers.\n *\n * Each provider has different OAuth endpoints, scopes, and token formats.\n * The Integrations tool handles the provider-specific implementation details.\n */\nexport enum AuthProvider {\n /** Google OAuth provider for Google Workspace services */\n Google = \"google\",\n /** Microsoft OAuth provider for Microsoft 365 services */\n Microsoft = \"microsoft\",\n /** Notion OAuth provider for Notion workspaces */\n Notion = \"notion\",\n /** Slack OAuth provider for Slack workspaces */\n Slack = \"slack\",\n /** Atlassian OAuth provider for Jira and Confluence */\n Atlassian = \"atlassian\",\n /** Linear OAuth provider for Linear workspaces */\n Linear = \"linear\",\n /** Monday.com OAuth provider */\n Monday = \"monday\",\n /** GitHub OAuth provider for GitHub repositories and organizations */\n GitHub = \"github\",\n /** Asana OAuth provider for Asana workspaces */\n Asana = \"asana\",\n /** HubSpot OAuth provider for HubSpot CRM */\n HubSpot = \"hubspot\",\n /** Todoist OAuth provider for Todoist task management */\n Todoist = \"todoist\",\n /** Airtable OAuth provider for Airtable bases */\n Airtable = \"airtable\",\n}\n\n/**\n * Represents a completed authorization from an OAuth flow.\n *\n * Contains the provider, granted scopes, and the actor (contact) that was authorized.\n * Tokens are looked up by (provider, actorId) rather than a random ID.\n */\nexport type Authorization = {\n /** The OAuth provider this authorization is for */\n provider: AuthProvider;\n /** Array of OAuth scopes this authorization covers */\n scopes: string[];\n /** The external account that was authorized (e.g., the Google account) */\n actor: Actor;\n};\n\n/**\n * Represents a stored OAuth authentication token.\n *\n * Contains the actual access token and the scopes it was granted,\n * which may be a subset of the originally requested scopes.\n */\nexport type AuthToken = {\n /** The OAuth access token */\n token: string;\n /** Array of granted OAuth scopes */\n scopes: string[];\n /**\n * Provider-specific metadata as key-value pairs.\n *\n * For Slack (AuthProvider.Slack):\n * - authed_user_id: The authenticated user's Slack ID\n * - team_id: The Slack workspace/team ID\n * - team_name: The Slack workspace/team name\n * - enterprise_id: The Enterprise Grid org ID (when applicable)\n */\n provider?: Record<string, string>;\n};\n";
|
|
8
|
+
export default "import {\n type Actor,\n type ActorId,\n type NewContact,\n type NewLinkWithNotes,\n type NewNote,\n ITool,\n} from \"..\";\nimport type { JSONValue } from \"../utils/types\";\nimport type { Uuid } from \"../utils/uuid\";\n\n/**\n * A resource that can be synced (e.g., a calendar, project, channel).\n * Returned by getChannels() and managed by users in the twist setup/edit modal.\n */\nexport type Channel = {\n /** External ID shared across users (e.g., Google calendar ID) */\n id: string;\n /** Display name shown in the UI */\n title: string;\n /**\n * Whether this channel should be selected by default when the user first\n * adds the connection. Tri-state:\n * - `true` — pre-select it (e.g. the user's own/primary calendar).\n * - `false` — exclude it from the default selection (low-value or\n * irrelevant resources that would crowd the user's view, or containers\n * whose contents are too broad to sync wholesale — e.g. a holiday or\n * someone-else's shared calendar, a GitHub org that cascades to every\n * repo, a Microsoft Teams team container). The user can still enable it\n * manually.\n * - `undefined` — no opinion; the client decides. The client defaults to\n * enabling the channel unless its title looks low-value (holidays,\n * birthdays, spam/sent/draft, …).\n *\n * The guiding principle is \"sync everything the user would reasonably want\n * by default\" — for most connectors that's all channels, so only set this\n * where the connector can distinguish the user's own/relevant channels from\n * low-value ones (e.g. Google Calendar via `accessRole === \"owner\"`).\n */\n enabledByDefault?: boolean;\n /** Optional nested channel resources (e.g., subfolders) */\n children?: Channel[];\n /** Per-channel link type configs. Overrides twist-level linkTypes when present. */\n linkTypes?: LinkTypeConfig[];\n};\n\n/**\n * Curated status-icon vocabulary. Connectors map each declared status to the\n * closest icon; clients render a single glyph per value. Required on every\n * status so the UI always has something to show.\n */\nexport type StatusIcon =\n | \"backlog\"\n | \"todo\"\n | \"inProgress\"\n | \"blocked\"\n | \"done\"\n | \"cancelled\"\n | \"confirmed\"\n | \"tentative\";\n\n/**\n * Describes a link type that a connector creates.\n * Used for display in the UI (icons, labels).\n */\nexport type LinkTypeConfig = {\n /** Machine-readable type identifier (e.g., \"issue\", \"pull_request\") */\n type: string;\n /** Human-readable label (e.g., \"Issue\", \"Pull Request\") */\n label: string;\n /**\n * Display name of the specific product/source this link type belongs to.\n * Used in place of the connector's display name when building\n * \"{source} {label}\" copy (the thread type name, the \"Create new …\" picker\n * entry, compose chips). Only needed for **aggregate** connectors that bundle\n * several products under one display name: the Google connector's display\n * name is \"Gmail & Calendar\", but its `event` link type should read\n * \"Google Calendar event\", its `email` link type \"Gmail thread\", and its\n * `task` link type \"Google Tasks task\". Set it to the standalone product\n * name (e.g. \"Gmail\", \"Google Calendar\", \"Google Tasks\"). Single-product\n * connectors can omit it — Plot falls back to the connector display name.\n */\n sourceName?: string;\n /**\n * Connector's word for a note on a linked item of this type — used by the\n * Flutter app to adapt note/composer copy (\"Add a comment\" on Linear,\n * \"Add a message\" on Slack, \"Add a reply\" on Gmail). Defaults to \"note\"\n * when omitted. Use the singular noun in title case (e.g. \"Comment\").\n */\n noteLabel?: string;\n /**\n * Placeholder shown in the editor when this link type is the target of a\n * new thread (NewThreadPage). Example: \"Send a Gmail email\".\n * If unset, Plot derives \"Create a new {connector} {label.toLowerCase()}\".\n */\n composePlaceholder?: string;\n /**\n * Label for the Send button on NewThreadPage when this link type is the\n * target. Example: \"Send\". If unset, defaults to \"Create\".\n */\n composeVerb?: string;\n /**\n * Placeholder shown in the in-thread editor for the default reply mode.\n * Example: \"Reply\" (Gmail), \"Add a comment\" (Linear). If unset, Plot derives\n * \"Add a {noteLabel.toLowerCase()}\" or \"Add a note\".\n */\n replyPlaceholder?: string;\n /**\n * Label for the Send button in the in-thread editor. Example: \"Send\"\n * (Gmail), \"Comment\" (Linear). If unset, defaults to \"Send\".\n */\n replyVerb?: string;\n /** URL to an icon for this link type (light mode). Prefer Iconify `logos/*` URLs. */\n logo?: string;\n /** URL to an icon for dark mode. Use when the default logo is invisible on dark backgrounds (e.g., Iconify `simple-icons/*` with `?color=`). */\n logoDark?: string;\n /** URL to a monochrome icon (uses `currentColor`). Prefer Iconify `simple-icons/*` URLs without a `?color=` param. */\n logoMono?: string;\n /** Possible status values for this type */\n statuses?: Array<{\n /** Machine-readable status (e.g., \"open\", \"done\") */\n status: string;\n /** Human-readable label (e.g., \"Open\", \"Done\") */\n label: string;\n /** Curated icon for this status (required so the UI always has a glyph). */\n icon: StatusIcon;\n /**\n * Suppress this status's icon on the feed row (ThreadWidget) while still\n * showing it in the ThreadPage header. Use for a \"resting\" default state\n * that would otherwise clutter the feed (e.g. calendar \"Confirmed\").\n */\n hiddenDefault?: boolean;\n /** Whether this status represents completion (done, closed, merged, cancelled, etc.) */\n done?: boolean;\n /**\n * Mark the thread `active=true` in Plot when a link enters this status.\n * Use for messaging-style flags where the user has indicated they want\n * to act on the thread now — Gmail's \"starred\", Slack's \"later\", etc.\n * The Plot user can later un-flag the thread without breaking the\n * connector relationship.\n */\n active?: boolean;\n /**\n * Marks this status as the connector's \"to-do\" / active state. When a\n * user brings a done thread back into Plot's agenda, done-status links\n * are flipped to the status marked `todo: true` (e.g. Gmail's \"starred\",\n * Linear's \"unstarted\"); connectors that don't mark one fall back to the\n * first non-done status.\n */\n todo?: boolean;\n }>;\n /** Whether this link type supports displaying and changing the assignee */\n supportsAssignee?: boolean;\n /**\n * Whether this link type produces time-anchored schedule/agenda items\n * (i.e. calendar events). The Plot app shows the agenda (the bottom-nav\n * tab on mobile and the left-sidebar agenda on desktop) only when the\n * user has at least one active connection whose link types include one\n * with `includesSchedules: true`. Calendar connectors (Google / Apple /\n * Outlook Calendar) set this on their `event` link type. Defaults to\n * false — non-calendar link types (messages, issues, tasks, docs) omit it.\n */\n includesSchedules?: boolean;\n /** Default thread creation mode for this link type: 'all' | 'actionable' | 'manual' */\n defaultCreateThreads?: string;\n /**\n * Opt-in: declares this link type is composable from Plot via\n * `Connector.onCreateLink`. Omit to make the link type sync-only (no\n * \"Create new …\" picker entry).\n *\n * Connectors that need multiple compose modes for what users perceive as\n * the same kind of thing (e.g. Slack channel post vs DM) should declare\n * **separate linkTypes**, one per user-facing thread type. That keeps\n * each linkType isomorphic to one filter chip.\n */\n compose?: ComposeConfig;\n /**\n * Per-connector contact roles. Examples:\n * email → [{id:\"to\",label:\"To\",default:true},{id:\"cc\",label:\"CC\"},{id:\"bcc\",label:\"BCC\",hidden:true}]\n * calendar → [{id:\"required\",label:\"Required\",default:true},{id:\"optional\",label:\"Optional\"}]\n *\n * Plot uses this list to render a role picker on each contact chip in the\n * composer and to label non-default roles on existing threads. Exactly one\n * role should be marked `default: true`. Connectors that don't distinguish\n * roles (Slack, Linear) omit this field entirely.\n */\n contactRoles?: ContactRoleConfig[];\n /**\n * Whether contacts on an existing thread can be added, removed, or have\n * their role changed (email-style mid-thread recipient changes). When\n * false, the thread's contact list is fixed after creation. Defaults to\n * false when omitted.\n */\n supportsContactChanges?: boolean;\n /**\n * Whether a note/reply on this link type can carry a link (a pasted URL or\n * connector-created item) that Plot forwards to the source. When false (the\n * default), the \"Add link\" button is hidden for threads of this link type.\n * Only set true if the connector's reply path actually forwards the link\n * action to the source. Private Plot notes (no link type) always allow links.\n */\n supportsLinks?: boolean;\n /**\n * Whether a note/reply on this link type can carry an uploaded file that Plot\n * forwards to the source as an attachment. When false (the default), the\n * \"Attach file\" button is hidden for threads of this link type. Only set true\n * if the connector's reply path actually uploads file actions to the source.\n * Private Plot notes (no link type) always allow attachments.\n */\n supportsFileAttachments?: boolean;\n /**\n * Declares how sharing on threads of this link type is scoped:\n *\n * - `\"thread\"` (default): one roster shared across all notes in the\n * thread. Native Plot threads, Slack DMs, calendar events.\n * - `\"channel\"`: visibility is the external channel's membership;\n * the per-thread `contacts` array is ignored for sharing UI.\n * Slack channels, Linear projects.\n * - `\"message\"`: each note carries its own recipient set via\n * `note.access_contacts`; the thread roster is the union across\n * all messages. Email.\n * - `\"none\"`: the link type has no recipient roster at all. No\n * contacts/sharing UI is shown for these threads. Use for purely\n * personal destinations with no sharing concept (e.g. Google\n * Tasks). The per-thread `contacts` array is ignored for sharing UI.\n *\n * Omit to default to `\"thread\"`. When set to `\"message\"`, every\n * note this connector ingests must populate `access_contacts`\n * explicitly (never NULL).\n */\n sharingModel?: \"thread\" | \"channel\" | \"message\" | \"none\";\n};\n\n/**\n * Declares how a link type is composable from Plot via\n * `Connector.onCreateLink`. Attached to {@link LinkTypeConfig.compose}.\n */\nexport type ComposeConfig = {\n /**\n * Selects the destination model for the \"Create new …\" picker.\n *\n * - `\"channels\"` (default): one chip per enabled channel (e.g. a Linear\n * team, a Slack channel). Existing behaviour for task-tracker / calendar\n * connectors.\n * - `\"contacts\"`: one chip per connection (account); the user picks\n * recipients from their contacts. The runtime pre-resolves the chosen\n * Plot contacts to platform account IDs via the per-connection\n * `contact_external_account` rows and delivers them as\n * `CreateLinkDraft.recipients`. Contacts without a row for this specific\n * connection are filtered out of the picker — used by closed-roster\n * messaging platforms (Slack DM, Teams DM, Google Chat DM, LinkedIn DM).\n * - `\"addresses\"`: one chip per connection; the picker accepts any\n * contact with an addressable identifier (e.g. an email) or a free-form\n * typed address. The runtime fills `recipients` for contacts with a\n * connection-scoped row and falls back to the contact's primary address\n * (e.g. `contact.email`) when no row exists. Free-form addresses arrive\n * via the thread's `inviteEmails`. Used by open address spaces like\n * Gmail.\n */\n targets?: \"channels\" | \"contacts\" | \"addresses\";\n /**\n * Status to assign newly-created links. Should match an entry in the\n * parent linkType's `statuses[]`, OR a symbolic id that the connector's\n * `onCreateLink` resolves itself (e.g. Linear's `\"unstarted\"` category is\n * resolved per-team to a state UUID inside the connector — see\n * `connectors/linear/src/linear.ts`).\n *\n * Omit for status-less link types (e.g. messaging connectors that don't\n * model a status): composed links are created with no status.\n */\n status?: string;\n /**\n * Optional override for the picker chip / \"Create new …\" copy. Defaults\n * to the parent linkType's `label`. Use to disambiguate compose entries\n * when the parent label alone isn't specific enough (e.g. \"Direct\n * messages\" for a DM-mode compose on a chat connector).\n */\n label?: string;\n};\n\n/**\n * Declares one contact role for a connector's link type. See\n * `LinkTypeConfig.contactRoles`.\n */\nexport type ContactRoleConfig = {\n /** Stable machine id, e.g. \"to\" / \"cc\" / \"bcc\" / \"required\" / \"optional\". */\n id: string;\n /** Display label shown next to a contact chip, e.g. \"To\", \"CC\", \"Required\". */\n label: string;\n /** Exactly one role per linkType should be marked default. */\n default?: boolean;\n /**\n * Hidden roles are visible only to (a) the contact themselves and\n * (b) the user who added them. The API filters them out of every other\n * viewer's `thread.contacts` and `thread.contactMeta`. Use for BCC-style\n * semantics where other recipients must not see the hidden contact.\n */\n hidden?: boolean;\n};\n\n/**\n * Context passed to onChannelEnabled with plan-based sync hints.\n * Connectors can use these hints to limit initial sync scope.\n */\nexport type SyncContext = {\n /**\n * Earliest date to include in initial sync, based on the user's plan.\n *\n * Non-calendar connectors should use this as their date filter (timeMin,\n * created.gte, etc.) during initial sync. Calendar connectors should\n * ignore this for API queries (to avoid missing recurring events) — the\n * API layer filters non-recurring items automatically.\n *\n * Undefined when no limit applies.\n */\n syncHistoryMin?: Date;\n\n /**\n * True when this is a recovery dispatch after the connection's auth was\n * restored (the user re-authorized a previously-broken connection).\n *\n * The framework calls `onChannelEnabled` again for every channel that was\n * already enabled at the time of re-auth so the connector can recover from\n * the auth gap. Connectors should:\n *\n * 1. Drop any persisted incremental sync cursors / sync tokens so the\n * next sync re-walks history (the cursor may be stale or invalid —\n * Google Calendar invalidates syncTokens after ~7 days).\n * 2. Re-register webhooks (any prior subscription may have been\n * invalidated during the auth outage).\n * 3. Treat this as a backfill that walks history but does NOT spam\n * notifications — set `unread: false` and `archived: false` on\n * items as you would during initial sync.\n *\n * Most connectors can take the same code path as a fresh\n * `onChannelEnabled` for `recovering: true` as long as that path\n * overwrites stored state rather than appending to it.\n */\n recovering?: boolean;\n\n /**\n * True when the channel is being observed because the user composed a Plot\n * thread INTO it (via `onCreateLink`), not because they explicitly enabled\n * it. The connector should register webhooks / mark the channel observed so\n * inbound events (replies, reactions) on the composed thread sync back —\n * but must NOT backfill history. Only go-forward events matter; pulling the\n * channel's existing content would be surprising for a channel the user\n * only posted one thread into.\n *\n * Connectors whose `onChannelEnabled` already skips historical backfill can\n * ignore this flag. Connectors that initial-sync on enable MUST short-\n * circuit that backfill when `observeOnly` is true (still set up webhooks\n * and any go-forward state).\n */\n observeOnly?: boolean;\n};\n\n/**\n * Built-in tool for managing OAuth authentication and channel resources.\n *\n * The Integrations tool:\n * 1. Manages channel resources (calendars, projects, etc.) per actor\n * 2. Returns tokens for the user who enabled sync on a channel\n * 3. Supports per-actor auth via actAs() for write-back operations\n * 4. Provides saveLink/saveContacts for Connectors to save data directly\n *\n * Connectors declare their provider, scopes, and channel lifecycle methods as\n * class properties and methods. The Integrations tool reads these automatically.\n * Auth and channel management is handled in the twist edit modal in Flutter.\n *\n * @example\n * ```typescript\n * class CalendarConnector extends Connector<CalendarConnector> {\n * readonly provider = AuthProvider.Google;\n * readonly scopes = [\"https://www.googleapis.com/auth/calendar\"];\n *\n * build(build: ToolBuilder) {\n * return {\n * integrations: build(Integrations),\n * };\n * }\n *\n * async getChannels(auth: Authorization, token: AuthToken): Promise<Channel[]> {\n * const calendars = await this.listCalendars(token);\n * return calendars.map(c => ({ id: c.id, title: c.name }));\n * }\n *\n * async onChannelEnabled(channel: Channel) {\n * // Start syncing\n * }\n *\n * async onChannelDisabled(channel: Channel) {\n * // Stop syncing\n * }\n * }\n * ```\n */\nexport abstract class Integrations extends ITool {\n /**\n * Merge scopes from multiple tools, deduplicating.\n *\n * @param scopeArrays - Arrays of scopes to merge\n * @returns Deduplicated array of scopes\n */\n static MergeScopes(...scopeArrays: string[][]): string[] {\n return Array.from(new Set(scopeArrays.flat()));\n }\n\n /**\n * Retrieves an access token for a channel resource.\n *\n * Returns the token of the user who enabled sync on the given channel.\n * If the channel is not enabled or the token is expired/invalid, returns null.\n *\n * @param channelId - The channel resource ID (e.g., calendar ID)\n * @returns Promise resolving to the access token or null\n */\n abstract get(channelId: string): Promise<AuthToken | null>;\n /**\n * Retrieves an access token for a channel resource.\n *\n * @param provider - The OAuth provider (deprecated, ignored for single-provider connectors)\n * @param channelId - The channel resource ID (e.g., calendar ID)\n * @returns Promise resolving to the access token or null\n * @deprecated Use get(channelId) instead. The provider is implicit from the connector.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n abstract get(provider: AuthProvider, channelId: string): Promise<AuthToken | null>;\n\n /**\n * Saves a link with notes to the connector's focus.\n *\n * Creates a thread+link pair. The thread is a lightweight container;\n * the link holds the external entity data (source, meta, type, status, etc.).\n *\n * This method is available only to Connectors (not regular Twists).\n *\n * @param link - The link with notes to save\n * @returns Promise resolving to the saved thread's UUID, or null if the\n * link was filtered out (e.g. older than the plan's sync history limit)\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n abstract saveLink(link: NewLinkWithNotes): Promise<Uuid | null>;\n\n /**\n * Batch version of {@link saveLink} — saves many links in one call.\n *\n * Connectors syncing many items per page (e.g. calendar events, issues,\n * messages) should prefer this over looping `saveLink`. Each `saveLink`\n * crosses the runtime boundary and counts against the per-execution\n * request budget; `saveLinks` collapses N saves into a single crossing.\n *\n * Failures on individual links DO NOT abort the batch. A bad item lands\n * as `null` in its slot and the rest still save. This prevents one\n * malformed record from losing an entire page of sync progress.\n *\n * This method is available only to Connectors (not regular Twists).\n *\n * @param links - Array of links with notes to save\n * @returns Array of the same length and order as `links`. Each entry is\n * the saved thread's UUID, or `null` if the link was filtered out\n * (e.g. older than the plan's sync history limit) OR failed to save.\n * The two null causes are not distinguished; the save failure is\n * logged server-side.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n abstract saveLinks(links: NewLinkWithNotes[]): Promise<(Uuid | null)[]>;\n\n /**\n * Save one or more notes. Unlike saveLink (which creates a thread-level\n * canonical link), these notes attach to an EXISTING thread — addressed by\n * `note.thread: { id }` or `{ source }` — and may carry their own\n * note-attached link via `note.link` (a note-scoped link, NOT a thread-level\n * canonical link). When `{ source }` resolves to no thread yet, the runtime\n * find-or-creates the thread by that source. Use for augmenter content\n * (e.g. meeting notes attached to a calendar event).\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n abstract saveNotes(notes: NewNote[]): Promise<(Uuid | null)[]>;\n /** Save a single note. See {@link saveNotes}. */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n abstract saveNote(note: NewNote): Promise<Uuid | null>;\n /**\n * Archive every note this connector created (optionally scoped to a channel),\n * plus their note-attached links. Mirror of {@link archiveLinks} for the\n * note-attached content model. Use in `onChannelDisabled`.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n abstract archiveNotes(filter: ArchiveNotesFilter): Promise<void>;\n\n /**\n * Upserts contacts into the connector's focus without requiring a Link.\n *\n * Use this for messaging connectors to bulk-sync workspace members so the\n * recipient picker can filter contacts by reachable platform account. Populate\n * `NewContact.source` to persist `contact_external_account` rows (the platform\n * identity used to address the contact). Returns one `Actor` per input, in order.\n *\n * @param contacts - Contacts to upsert, keyed by `source`/`key`\n * @returns Promise resolving to the saved actors, 1:1 with input order\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n abstract saveContacts(contacts: NewContact[]): Promise<Actor[]>;\n\n /**\n * Archives links matching the given filter that were created by this connector.\n *\n * For each archived link's thread, if no other non-archived links remain,\n * the thread is also archived.\n *\n * @param filter - Filter criteria for which links to archive\n * @returns Promise that resolves when archiving is complete\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n abstract archiveLinks(filter: ArchiveLinkFilter): Promise<void>;\n\n /**\n * Sets or clears todo status on a thread owned by this connector.\n *\n * @param source - The link source URL identifying the thread\n * @param actorId - The user to set the todo for\n * @param todo - true to mark as todo, false to clear/complete\n * @param options - Additional options\n * @param options.date - The todo date (when todo=true). Defaults to today.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n abstract setThreadToDo(\n source: string,\n actorId: ActorId,\n todo: boolean,\n options?: { date?: Date | string }\n ): Promise<void>;\n\n /**\n * Signal that initial bulk-sync (or recovery sync) for a channel is fully\n * complete. The Flutter app uses this to clear the \"syncing…\" indicator\n * on the connection.\n *\n * The framework automatically marks a channel as syncing when it dispatches\n * `onChannelEnabled` (whether initial-enable, auto-enable from\n * `setChannels`, or recovery after re-auth). Connectors do NOT need to\n * call anything to start tracking — only to signal completion.\n *\n * Call this exactly once when the initial backfill has finished (no more\n * pages, all phases exhausted). Do NOT call it on every incremental sync.\n *\n * If `onChannelEnabled` throws an unhandled exception, the framework\n * automatically clears the syncing state — connectors don't need a\n * `try/catch` to clear state on failure.\n *\n * No-op when no auth/user mapping exists for the channel (e.g. key-based\n * connectors that don't have a per-user OAuth association).\n *\n * @param channelId - The channel resource ID whose initial sync just finished\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n abstract channelSyncCompleted(channelId: string): Promise<void>;\n\n /**\n * Flag a connection as needing re-authentication so the Flutter app\n * surfaces a re-auth prompt on the next sync.\n *\n * Call this when a connector's API call returns a permanent auth-style\n * error that the runtime can't observe through token refresh — e.g.\n * Slack `invalid_auth` / `token_revoked` / `not_authed`, or a 401 on a\n * provider that doesn't refresh. The runtime already flags reauth\n * automatically when an OAuth refresh permanently fails or when the\n * stored token is missing on a get(); only call this for cases the\n * runtime can't see.\n *\n * Idempotent: safe to call repeatedly; existing reauth flags are not\n * overwritten. No-op when the channel has no `enabledBy` actor (e.g.\n * key-based connectors).\n *\n * @param channelId - The channel resource ID whose token is bad\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n abstract markNeedsReauth(channelId: string): Promise<void>;\n\n /**\n * Upsert workspace custom emoji into Plot's shared cache so reactions using\n * `provider:workspace/name` refs render as images and round-trip. Idempotent;\n * keyed on `id`. Pass `archived: true` to mark an emoji removed. Workspace-\n * scoped (shared across all users of that workspace).\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n abstract saveCustomEmoji(emoji: NewCustomEmoji[]): Promise<void>;\n\n}\n\n/**\n * Filter criteria for archiving links.\n * All fields are optional; only provided fields are used for matching.\n */\nexport type ArchiveLinkFilter = {\n /** Filter by channel ID */\n channelId?: string;\n /** Filter by link type (e.g., \"issue\", \"pull_request\") */\n type?: string;\n /** Filter by link status (e.g., \"open\", \"closed\") */\n status?: string;\n /** Filter by metadata fields (uses containment matching) */\n meta?: Record<string, JSONValue>;\n};\n\n/**\n * Filter criteria for archiving notes (and their note-attached links).\n * All fields are optional; only provided fields are used for matching.\n */\nexport type ArchiveNotesFilter = {\n /** Restrict to notes whose note-attached link is on this channel. */\n channelId?: string;\n};\n\n/**\n * A workspace custom emoji to cache so Plot can render and round-trip it as a\n * reaction. `id` is the provider-scoped ref stored on reactions, of the form\n * `<provider>:<workspace>/<name>` (e.g. `slack:T0123ABC/party_parrot`).\n */\nexport type NewCustomEmoji = {\n /** Provider-scoped ref: `<provider>:<workspace>/<name>`. The reaction value. */\n id: string;\n /** e.g. \"slack\". */\n provider: string;\n /** Provider workspace/team id (e.g. Slack team id `T0123ABC`). */\n workspace: string;\n /** Bare emoji name without colons (e.g. \"party_parrot\"). */\n name: string;\n /** Image URL to render, or null for an alias (see `aliasOf`). */\n imageUrl: string | null;\n /** When this emoji aliases another, the target ref (`id` of the canonical emoji); else null. */\n aliasOf: string | null;\n /** True to mark the emoji removed (archive it) rather than upsert it. */\n archived: boolean;\n};\n\n/**\n * Enumeration of supported OAuth providers.\n *\n * Each provider has different OAuth endpoints, scopes, and token formats.\n * The Integrations tool handles the provider-specific implementation details.\n */\nexport enum AuthProvider {\n /** Google OAuth provider for Google Workspace services */\n Google = \"google\",\n /** Microsoft OAuth provider for Microsoft 365 services */\n Microsoft = \"microsoft\",\n /** Notion OAuth provider for Notion workspaces */\n Notion = \"notion\",\n /** Slack OAuth provider for Slack workspaces */\n Slack = \"slack\",\n /** Atlassian OAuth provider for Jira and Confluence */\n Atlassian = \"atlassian\",\n /** Linear OAuth provider for Linear workspaces */\n Linear = \"linear\",\n /** Monday.com OAuth provider */\n Monday = \"monday\",\n /** GitHub OAuth provider for GitHub repositories and organizations */\n GitHub = \"github\",\n /** Asana OAuth provider for Asana workspaces */\n Asana = \"asana\",\n /** HubSpot OAuth provider for HubSpot CRM */\n HubSpot = \"hubspot\",\n /** Todoist OAuth provider for Todoist task management */\n Todoist = \"todoist\",\n /** Airtable OAuth provider for Airtable bases */\n Airtable = \"airtable\",\n}\n\n/**\n * Represents a completed authorization from an OAuth flow.\n *\n * Contains the provider, granted scopes, and the actor (contact) that was authorized.\n * Tokens are looked up by (provider, actorId) rather than a random ID.\n */\nexport type Authorization = {\n /** The OAuth provider this authorization is for */\n provider: AuthProvider;\n /** Array of OAuth scopes this authorization covers */\n scopes: string[];\n /** The external account that was authorized (e.g., the Google account) */\n actor: Actor;\n};\n\n/**\n * Represents a stored OAuth authentication token.\n *\n * Contains the actual access token and the scopes it was granted,\n * which may be a subset of the originally requested scopes.\n */\nexport type AuthToken = {\n /** The OAuth access token */\n token: string;\n /** Array of granted OAuth scopes */\n scopes: string[];\n /**\n * Provider-specific metadata as key-value pairs.\n *\n * For Slack (AuthProvider.Slack):\n * - authed_user_id: The authenticated user's Slack ID\n * - team_id: The Slack workspace/team ID\n * - team_name: The Slack workspace/team name\n * - enterprise_id: The Enterprise Grid org ID (when applicable)\n */\n provider?: Record<string, string>;\n};\n";
|
|
@@ -68,6 +68,19 @@ export type LinkTypeConfig = {
|
|
|
68
68
|
type: string;
|
|
69
69
|
/** Human-readable label (e.g., "Issue", "Pull Request") */
|
|
70
70
|
label: string;
|
|
71
|
+
/**
|
|
72
|
+
* Display name of the specific product/source this link type belongs to.
|
|
73
|
+
* Used in place of the connector's display name when building
|
|
74
|
+
* "{source} {label}" copy (the thread type name, the "Create new …" picker
|
|
75
|
+
* entry, compose chips). Only needed for **aggregate** connectors that bundle
|
|
76
|
+
* several products under one display name: the Google connector's display
|
|
77
|
+
* name is "Gmail & Calendar", but its `event` link type should read
|
|
78
|
+
* "Google Calendar event", its `email` link type "Gmail thread", and its
|
|
79
|
+
* `task` link type "Google Tasks task". Set it to the standalone product
|
|
80
|
+
* name (e.g. "Gmail", "Google Calendar", "Google Tasks"). Single-product
|
|
81
|
+
* connectors can omit it — Plot falls back to the connector display name.
|
|
82
|
+
*/
|
|
83
|
+
sourceName?: string;
|
|
71
84
|
/**
|
|
72
85
|
* Connector's word for a note on a linked item of this type — used by the
|
|
73
86
|
* Flutter app to adapt note/composer copy ("Add a comment" on Linear,
|