agents 0.22.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -1
- package/dist/{agent-routing-CnkaHb-v.d.ts → agent-routing-DE5zmCQ8.d.ts} +1038 -394
- package/dist/agent-routing.d.ts +1 -1
- package/dist/agent-tool-types.d.ts +26 -26
- package/dist/{agent-tools-C0XJqWzB.d.ts → agent-tools-DtXMTDGM.d.ts} +7 -7
- package/dist/agent-tools.d.ts +21 -21
- package/dist/browser/ai.js +4 -1
- package/dist/browser/ai.js.map +1 -1
- package/dist/browser/tanstack-ai.js.map +1 -1
- package/dist/callable-decorator-DP__HhBA.d.ts +72 -0
- package/dist/callable-decorator.d.ts +18 -0
- package/dist/callable-decorator.js +71 -0
- package/dist/callable-decorator.js.map +1 -0
- package/dist/capability-BjSKYpzg.js.map +1 -1
- package/dist/capability-runner-Be_-PLR1.d.ts +459 -0
- package/dist/channel-Bnm4S7T2.d.ts +491 -0
- package/dist/channels/ai-sdk.d.ts +46 -0
- package/dist/channels/ai-sdk.js +120 -0
- package/dist/channels/ai-sdk.js.map +1 -0
- package/dist/channels/email.d.ts +95 -0
- package/dist/channels/email.js +323 -0
- package/dist/channels/email.js.map +1 -0
- package/dist/channels/index.d.ts +233 -0
- package/dist/channels/index.js +608 -0
- package/dist/channels/index.js.map +1 -0
- package/dist/channels/slack.d.ts +140 -0
- package/dist/channels/slack.js +614 -0
- package/dist/channels/slack.js.map +1 -0
- package/dist/channels/tanstack-ai.d.ts +39 -0
- package/dist/channels/tanstack-ai.js +17 -0
- package/dist/channels/tanstack-ai.js.map +1 -0
- package/dist/channels/telegram.d.ts +106 -0
- package/dist/channels/telegram.js +427 -0
- package/dist/channels/telegram.js.map +1 -0
- package/dist/channels/voice.d.ts +45 -0
- package/dist/channels/voice.js +122 -0
- package/dist/channels/voice.js.map +1 -0
- package/dist/chat/index.d.ts +2325 -2019
- package/dist/chat/index.js +888 -518
- package/dist/chat/index.js.map +1 -1
- package/dist/chat-sdk/index.d.ts +7 -7
- package/dist/chat-sdk/index.js +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/context/index.d.ts +216 -0
- package/dist/context/index.js +454 -0
- package/dist/context/index.js.map +1 -0
- package/dist/{current-agent-CuMErtly.d.ts → current-agent-Da_C9a3b.d.ts} +90 -107
- package/dist/current-agent-DhoDkSnH.js.map +1 -1
- package/dist/{diagnostics-CaBjfz4J.js → diagnostics-BzvaX2UT.js} +5 -1
- package/dist/diagnostics-BzvaX2UT.js.map +1 -0
- package/dist/diagnostics-C4jcz3VK.js +360 -0
- package/dist/diagnostics-C4jcz3VK.js.map +1 -0
- package/dist/index-BB0kqhIz.d.ts +101 -0
- package/dist/index-BVVgDSdq.d.ts +1 -0
- package/dist/index-XDkuQ7zm.d.ts +89 -0
- package/dist/{index-DcSAZKsB.d.ts → index-YSKgfgg9.d.ts} +3 -1
- package/dist/index.d.ts +91 -82
- package/dist/index.js +3 -2
- package/dist/ingress-BfetZbMO.js +83 -0
- package/dist/ingress-BfetZbMO.js.map +1 -0
- package/dist/internal-CYlgHl1l.js +59 -0
- package/dist/internal-CYlgHl1l.js.map +1 -0
- package/dist/internal_context.d.ts +1 -1
- package/dist/lifecycle/index.d.ts +35 -17
- package/dist/lifecycle/index.js +1 -1
- package/dist/lifecycle-CMRGjZdw.js +1299 -0
- package/dist/lifecycle-CMRGjZdw.js.map +1 -0
- package/dist/mcp/client/index.d.ts +20 -20
- package/dist/mcp/index.d.ts +35 -35
- package/dist/mcp/index.js +1 -1
- package/dist/observability/index.d.ts +1 -1
- package/dist/observability/index.js +1 -1
- package/dist/react.d.ts +4 -4
- package/dist/{retries-CAvxtG9d.d.ts → retries-D9Ds-1lz.d.ts} +17 -6
- package/dist/retries.d.ts +8 -6
- package/dist/retries.js +13 -1
- package/dist/retries.js.map +1 -1
- package/dist/routing/index.d.ts +137 -0
- package/dist/routing/index.js +244 -0
- package/dist/routing/index.js.map +1 -0
- package/dist/sanitize-D9TujEK8.js +79 -0
- package/dist/sanitize-D9TujEK8.js.map +1 -0
- package/dist/scheduler-DD9NdYbF.js +665 -0
- package/dist/scheduler-DD9NdYbF.js.map +1 -0
- package/dist/{scheduler-DQoTGoAW.d.ts → scheduler-Dwh85ZGl.d.ts} +21 -22
- package/dist/schedules/index.d.ts +1 -1
- package/dist/schedules/index.js +1 -1
- package/dist/sentence-chunker-BAidJ4DA.d.ts +68 -0
- package/dist/serializable.d.ts +1 -1
- package/dist/sessions/index.d.ts +441 -0
- package/dist/sessions/index.js +2063 -0
- package/dist/sessions/index.js.map +1 -0
- package/dist/skills/index.d.ts +99 -0
- package/dist/skills/index.js +254 -5
- package/dist/skills/index.js.map +1 -1
- package/dist/{src-5W6JNKVb.js → src-DlSHshb2.js} +1460 -1110
- package/dist/src-DlSHshb2.js.map +1 -0
- package/dist/streams/index.d.ts +120 -0
- package/dist/streams/index.js +107 -0
- package/dist/streams/index.js.map +1 -0
- package/dist/streams-D6tJ0NN9.d.ts +370 -0
- package/dist/streams-DZKgAj9b.js +709 -0
- package/dist/streams-DZKgAj9b.js.map +1 -0
- package/dist/sub-routing.d.ts +12 -12
- package/dist/surface-bZZJqBka.js +17 -0
- package/dist/surface-bZZJqBka.js.map +1 -0
- package/dist/tasks/index.d.ts +64 -0
- package/dist/tasks/index.js +2 -0
- package/dist/tasks-BRJ5zgya.d.ts +517 -0
- package/dist/tasks-ylZgBjhj.js +1656 -0
- package/dist/tasks-ylZgBjhj.js.map +1 -0
- package/dist/text-segment-joiner-BtAFQSA_.js +57 -0
- package/dist/text-segment-joiner-BtAFQSA_.js.map +1 -0
- package/dist/text-stream-CpdiKrJB.js +272 -0
- package/dist/text-stream-CpdiKrJB.js.map +1 -0
- package/dist/tokens-nHAKcN6M.js +52 -0
- package/dist/tokens-nHAKcN6M.js.map +1 -0
- package/dist/tool-schema-CBjGPrsQ.js +31 -0
- package/dist/tool-schema-CBjGPrsQ.js.map +1 -0
- package/dist/types-B7LojTe4.d.ts +202 -0
- package/dist/types-_Faxb570.d.ts +439 -0
- package/dist/voice/client.d.ts +226 -0
- package/dist/voice/client.js +932 -0
- package/dist/voice/client.js.map +1 -0
- package/dist/voice/errors.d.ts +43 -0
- package/dist/voice/errors.js +41 -0
- package/dist/voice/errors.js.map +1 -0
- package/dist/voice/index.d.ts +271 -0
- package/dist/voice/index.js +1812 -0
- package/dist/voice/index.js.map +1 -0
- package/dist/voice/react.d.ts +167 -0
- package/dist/voice/react.js +234 -0
- package/dist/voice/react.js.map +1 -0
- package/dist/voice/sfu.d.ts +71 -0
- package/dist/voice/sfu.js +157 -0
- package/dist/voice/sfu.js.map +1 -0
- package/dist/voice/text.d.ts +6 -0
- package/dist/voice/text.js +2 -0
- package/dist/voice/types.d.ts +58 -0
- package/dist/voice/types.js +18 -0
- package/dist/voice/types.js.map +1 -0
- package/dist/voice/workers-ai.d.ts +136 -0
- package/dist/voice/workers-ai.js +568 -0
- package/dist/voice/workers-ai.js.map +1 -0
- package/dist/websockets/index.d.ts +192 -0
- package/dist/websockets/index.js +2 -0
- package/dist/websockets-DUfRHPRq.js +502 -0
- package/dist/websockets-DUfRHPRq.js.map +1 -0
- package/dist/workflow-types.d.ts +25 -25
- package/dist/workflows.d.ts +21 -21
- package/dist/workflows.js +1 -1
- package/docs/agent-class.md +2 -2
- package/docs/agent-tools.md +2 -1
- package/docs/channels.md +323 -0
- package/docs/chat-agents.md +6 -13
- package/docs/context.md +131 -0
- package/docs/index.md +15 -12
- package/docs/lifecycle.md +102 -55
- package/docs/long-running-agents.md +2 -2
- package/docs/mcp-servers.md +5 -1
- package/docs/resumable-streaming.md +1 -1
- package/docs/routing.md +105 -0
- package/docs/sessions.md +237 -871
- package/docs/streams.md +213 -0
- package/docs/sub-agents.md +184 -124
- package/docs/tasks.md +246 -0
- package/docs/voice.md +745 -0
- package/package.json +115 -13
- package/dist/capability-runner-CvHGZqUu.d.ts +0 -150
- package/dist/compaction-helpers-iiKMr2TQ.js +0 -340
- package/dist/compaction-helpers-iiKMr2TQ.js.map +0 -1
- package/dist/compaction-helpers-wUz6M3us.d.ts +0 -621
- package/dist/diagnostics-CaBjfz4J.js.map +0 -1
- package/dist/durable-object-lifecycle-D6nNQJJd.js +0 -862
- package/dist/durable-object-lifecycle-D6nNQJJd.js.map +0 -1
- package/dist/experimental/memory/session/index.d.ts +0 -671
- package/dist/experimental/memory/session/index.js +0 -2379
- package/dist/experimental/memory/session/index.js.map +0 -1
- package/dist/experimental/memory/utils/index.d.ts +0 -96
- package/dist/experimental/memory/utils/index.js +0 -79
- package/dist/experimental/memory/utils/index.js.map +0 -1
- package/dist/scheduler-CR9RHGos.js +0 -857
- package/dist/scheduler-CR9RHGos.js.map +0 -1
- package/dist/src-5W6JNKVb.js.map +0 -1
- package/dist/tool-output-truncation-CNnnGZQ3.js +0 -98
- package/dist/tool-output-truncation-CNnnGZQ3.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/channels/fallback.ts","../../src/channels/fanout.ts","../../src/channels/host/index.ts","../../src/channels/identity.ts","../../src/channels/routes.ts"],"sourcesContent":["import type {\n Channel,\n ChannelApprovalRequestOptions,\n ChannelChunk,\n ChannelDeliveryOptions,\n ChannelMessage,\n ChannelStreamOptions,\n DeliveryResult,\n OutboundResolver\n} from \"./channel\";\nimport { compositeDestinations, unsupported } from \"./internal\";\nimport type { ChannelMessageSurface } from \"./surface\";\n\nexport type FallbackSurface = ChannelMessageSurface<\n \"fallback\",\n { surfaces: readonly ChannelMessageSurface[] }\n>;\n\n/** A non-empty sequence of destinations ordered from preferred to final. */\nexport type FallbackSurfaceOptions = readonly [\n ChannelMessageSurface,\n ...ChannelMessageSurface[]\n];\n\ntype FallbackOperation = (\n surface: ChannelMessageSurface\n) => Promise<DeliveryResult>;\n\n/**\n * Build an inert fallback destination for a `ChannelHost` to resolve.\n *\n * The Host skips unavailable destinations, advances after confirmed failures,\n * and stops after a delivered or uncertain result to avoid duplicates.\n */\nexport function fallback(surfaces: FallbackSurfaceOptions): FallbackSurface {\n return {\n channelKey: \"fallback\",\n version: 1,\n address: { surfaces },\n label: surfaces.map((surface) => surface.label).join(\", then \")\n };\n}\n\n/**\n * Advance only when a failed destination has not started reading the answer.\n *\n * Replaying an arbitrarily large consumed prefix requires an arbitrarily large\n * buffer. Instead, each attempt gets a cancellation-shielded view of the same\n * source. Once an attempt asks for its first chunk, its result is terminal and\n * the source is never handed to another destination.\n */\nasync function streamWithFallbackBeforeRead(\n resolve: OutboundResolver,\n destinations: readonly ChannelMessageSurface[],\n chunks: ReadableStream<ChannelChunk>,\n options: ChannelStreamOptions\n): Promise<DeliveryResult> {\n const reader = chunks.getReader();\n let drained = false;\n\n function attempt(): {\n chunks: ReadableStream<ChannelChunk>;\n startedReading: () => boolean;\n } {\n let startedReading = false;\n return {\n chunks: new ReadableStream<ChannelChunk>(\n {\n async pull(controller) {\n startedReading = true;\n const result = await reader.read();\n if (result.done) {\n drained = true;\n controller.close();\n return;\n }\n controller.enqueue(result.value);\n },\n // A destination may cancel after an opening failure. Shield the\n // untouched source so the next destination can still try it.\n cancel() {}\n },\n // Do not prefetch: creating an attempt must not consume the source.\n { highWaterMark: 0 }\n ),\n startedReading: () => startedReading\n };\n }\n\n try {\n for (let index = 0; index < destinations.length - 1; index += 1) {\n const destination = destinations[index]!;\n if (!(await resolve.isAvailable(destination))) continue;\n\n const current = attempt();\n const result = await resolve.stream(destination, current.chunks, options);\n if (result.status !== \"failed\" || current.startedReading()) return result;\n }\n const final = attempt();\n // `return await` so the shared reader is released only after the final\n // destination has finished consuming it.\n return await resolve.stream(destinations.at(-1)!, final.chunks, options);\n } finally {\n if (!drained) await reader.cancel().catch(() => {});\n reader.releaseLock();\n }\n}\n\n/** Build the ordinary Channel installed under the reserved fallback key. */\nexport function fallbackChannel(resolve: OutboundResolver): Channel {\n async function run(\n surface: ChannelMessageSurface,\n operation: FallbackOperation\n ): Promise<DeliveryResult> {\n const destinations = compositeDestinations(surface);\n if (!destinations) {\n return unsupported(\n \"FALLBACK_SURFACE_INVALID\",\n \"Fallback surface must contain at least one valid destination\"\n );\n }\n\n for (let index = 0; index < destinations.length - 1; index += 1) {\n const destination = destinations[index]!;\n if (await resolve.isAvailable(destination)) {\n const result = await operation(destination);\n if (result.status !== \"failed\") return result;\n }\n }\n // try the last one if we haven't returned yet\n return operation(destinations.at(-1)!);\n }\n\n return {\n deliver(\n surface: ChannelMessageSurface,\n message: ChannelMessage,\n options?: ChannelDeliveryOptions\n ) {\n return run(surface, (destination) =>\n resolve.deliver(destination, message, options)\n );\n },\n\n async stream(\n surface: ChannelMessageSurface,\n chunks: ReadableStream<ChannelChunk>,\n options: ChannelStreamOptions\n ) {\n const destinations = compositeDestinations(surface);\n if (!destinations) {\n await chunks.cancel().catch(() => {});\n return unsupported(\n \"FALLBACK_SURFACE_INVALID\",\n \"Fallback surface must contain at least one valid destination\"\n );\n }\n return streamWithFallbackBeforeRead(\n resolve,\n destinations,\n chunks,\n options\n );\n },\n\n requestApproval(\n surface: ChannelMessageSurface,\n options: ChannelApprovalRequestOptions\n ) {\n return run(surface, (destination) =>\n resolve.requestApproval(destination, options)\n );\n },\n\n async isAvailable(surface) {\n const destinations = compositeDestinations(surface);\n if (!destinations) return true;\n for (const destination of destinations) {\n if (await resolve.isAvailable(destination)) return true;\n }\n return false;\n }\n };\n}\n","import type {\n Channel,\n ChannelApprovalRequestOptions,\n ChannelChunk,\n ChannelDeliveryOptions,\n ChannelMessage,\n ChannelStreamOptions,\n DeliveryResult,\n OutboundResolver\n} from \"./channel\";\nimport { compositeDestinations, unsupported } from \"./internal\";\nimport type { ChannelMessageSurface } from \"./surface\";\n\nexport type FanoutSurface = ChannelMessageSurface<\n \"fanout\",\n { surfaces: readonly ChannelMessageSurface[] }\n>;\n\n/** A non-empty set of destinations that must all receive each delivery. */\nexport type FanoutSurfaceOptions = readonly [\n ChannelMessageSurface,\n ...ChannelMessageSurface[]\n];\n\ntype FanoutOperation = (\n surface: ChannelMessageSurface\n) => Promise<DeliveryResult>;\n\nfunction teeAll<T>(\n source: ReadableStream<T>,\n count: number\n): ReadableStream<T>[] {\n const branches: ReadableStream<T>[] = [];\n let rest = source;\n for (let index = 0; index < count - 1; index += 1) {\n const [branch, remainder] = rest.tee();\n branches.push(branch);\n rest = remainder;\n }\n branches.push(rest);\n return branches;\n}\n\n/** Build an inert fanout destination for a `ChannelHost` to resolve. */\nexport function fanout(surfaces: FanoutSurfaceOptions): FanoutSurface {\n return {\n channelKey: \"fanout\",\n version: 1,\n address: { surfaces },\n label: surfaces.map((surface) => surface.label).join(\" and \")\n };\n}\n\n/** Build the ordinary Channel installed under the reserved fanout key. */\nexport function fanoutChannel(resolve: OutboundResolver): Channel {\n async function run(\n surface: ChannelMessageSurface,\n operation: FanoutOperation\n ): Promise<DeliveryResult> {\n const destinations = compositeDestinations(surface);\n if (!destinations) {\n return unsupported(\n \"FANOUT_SURFACE_INVALID\",\n \"Fanout surface must contain at least one valid destination\"\n );\n }\n\n return combine(await Promise.all(destinations.map(operation)));\n }\n\n function combine(results: readonly DeliveryResult[]): DeliveryResult {\n if (results.every((result) => result.status === \"delivered\")) {\n return { status: \"delivered\" };\n }\n if (results.every((result) => result.status === \"failed\")) {\n return {\n status: \"failed\",\n retryable: results.every(\n (result) => result.status === \"failed\" && result.retryable\n ),\n error: {\n code: \"FANOUT_DELIVERY_FAILED\",\n message: \"Every fanout destination rejected the delivery\"\n }\n };\n }\n return {\n status: \"uncertain\",\n error: {\n code: \"FANOUT_DELIVERY_UNCERTAIN\",\n message:\n \"Fanout delivery was partial or had an uncertain destination outcome\"\n }\n };\n }\n\n return {\n deliver(\n surface: ChannelMessageSurface,\n message: ChannelMessage,\n options?: ChannelDeliveryOptions\n ) {\n return run(surface, (destination) =>\n resolve.deliver(destination, message, options)\n );\n },\n async stream(\n surface: ChannelMessageSurface,\n chunks: ReadableStream<ChannelChunk>,\n options: ChannelStreamOptions\n ) {\n const destinations = compositeDestinations(surface);\n if (!destinations) {\n await chunks.cancel().catch(() => {});\n return unsupported(\n \"FANOUT_SURFACE_INVALID\",\n \"Fanout surface must contain at least one valid destination\"\n );\n }\n // One branch per destination, so a slow reader cannot pace a fast one.\n const branches = teeAll(chunks, destinations.length);\n return combine(\n await Promise.all(\n destinations.map(async (destination, index) => {\n const branch = branches[index]!;\n try {\n return await resolve.stream(destination, branch, options);\n } finally {\n // A destination may return after an opening failure without\n // reading. Cancel immediately so tee does not retain every chunk\n // consumed by the remaining destinations. Do not await: one tee\n // branch's cancellation settles only after its siblings finish.\n void branch.cancel().catch(() => {});\n }\n })\n )\n );\n },\n requestApproval(\n surface: ChannelMessageSurface,\n options: ChannelApprovalRequestOptions\n ) {\n return run(surface, (destination) =>\n resolve.requestApproval(destination, options)\n );\n },\n async isAvailable(surface) {\n const destinations = compositeDestinations(surface);\n if (!destinations) return true;\n const available = await Promise.all(\n destinations.map((destination) => resolve.isAvailable(destination))\n );\n return available.every(Boolean);\n }\n };\n}\n","import type {\n Channel,\n ChannelApprovalRequestOptions,\n ChannelChunk,\n ChannelChunkSource,\n ChannelDeliveryOptions,\n ChannelMessage,\n ChannelRoute,\n ChannelRouteContext,\n ChannelStreamOptions,\n DeliveryResult\n} from \"../channel\";\nimport { fallbackChannel } from \"../fallback\";\nimport { fanoutChannel } from \"../fanout\";\nimport type {\n ChannelIdentity,\n ChannelIdentityInput,\n UserIdentity\n} from \"../identity\";\nimport { unsupported } from \"../internal\";\nimport { collectText } from \"../stream\";\nimport type {\n ChannelApprovalResponse,\n ChannelEmailInput,\n ChannelInboundMessage,\n ChannelIngressEnvelope,\n ChannelIngressEvent,\n ChannelIngressEventInput\n} from \"../ingress\";\nimport {\n isChannelMessageSurface,\n type ChannelMessageSurface,\n type ChannelMessageSurfaceInput\n} from \"../surface\";\n\nexport type ChannelMessageEvent = {\n channelKey: string;\n route: string;\n /** Stable identity derived only from the configured Channel and eventId. */\n dispatchId: string;\n message: ChannelInboundMessage;\n};\n\nexport type ChannelApprovalResponseEvent = {\n channelKey: string;\n route: string;\n /** Stable identity derived only from the configured Channel and eventId. */\n dispatchId: string;\n response: ChannelApprovalResponse;\n};\n\nexport type ChannelRouteEvent = {\n channelKey: string;\n event: ChannelIngressEvent;\n route: string | null;\n /** Stable identity derived only from the configured Channel and eventId. */\n dispatchId: string;\n};\n\nexport type ChannelHostOptions = {\n channels: Record<string, Channel>;\n /** Used when a Channel does not provide a route. Default: event thread id. */\n defaultRoute?: ChannelRoute;\n /** Resolve an existing, explicitly linked application user. */\n findUser?(identity: ChannelIdentity): Promise<UserIdentity | null>;\n /** Observes every valid route outcome before application dispatch. */\n onRoute?(event: ChannelRouteEvent): void | Promise<void>;\n onMessage?(event: ChannelMessageEvent): void | Promise<void>;\n onApprovalResponse?(\n event: ChannelApprovalResponseEvent\n ): void | Promise<void>;\n};\n\ntype OutboundOperation = (\n channel: Channel,\n surface: ChannelMessageSurface\n) => Promise<DeliveryResult>;\n\nconst POLICY_KEYS = new Set([\"fallback\", \"fanout\"]);\n\n/**\n * Authenticates and normalizes ingress through configured Channel adapters,\n * resolves outbound surfaces, and awaits the application's durable handoff.\n */\nexport class ChannelHost {\n readonly #channels: Record<string, Channel>;\n readonly #defaultRoute: ChannelRoute | undefined;\n readonly #findUser: ChannelHostOptions[\"findUser\"];\n readonly #onRoute: ChannelHostOptions[\"onRoute\"];\n readonly #onMessage: ChannelHostOptions[\"onMessage\"];\n readonly #onApprovalResponse: ChannelHostOptions[\"onApprovalResponse\"];\n\n constructor(options: ChannelHostOptions) {\n for (const channelKey of Object.keys(options.channels)) {\n if (POLICY_KEYS.has(channelKey)) {\n throw new Error(\n `Channel key \"${channelKey}\" is reserved for a delivery policy`\n );\n }\n }\n const channels = { ...options.channels };\n this.#channels = channels;\n channels.fallback = fallbackChannel(this);\n channels.fanout = fanoutChannel(this);\n this.#defaultRoute = options.defaultRoute;\n this.#findUser = options.findUser;\n this.#onRoute = options.onRoute;\n this.#onMessage = options.onMessage;\n this.#onApprovalResponse = options.onApprovalResponse;\n }\n\n async handleRequest(request: Request): Promise<Response | undefined> {\n for (const [channelKey, channel] of Object.entries(this.#channels)) {\n const ingress = channel.ingress;\n if (!ingress) continue;\n\n try {\n const result = await ingress.receive(request);\n if (!result) continue;\n for (const envelope of result.events) {\n await this.#dispatch(channelKey, channel, envelope);\n }\n return result.response;\n } catch {\n return new Response(\"Failed to handle Channel event\", { status: 500 });\n }\n }\n return undefined;\n }\n\n async handleEmail(email: ChannelEmailInput): Promise<boolean> {\n for (const [channelKey, channel] of Object.entries(this.#channels)) {\n const ingress = channel.emailIngress;\n if (!ingress) continue;\n\n const result = await ingress.receive(email);\n if (!result) continue;\n for (const envelope of result.events) {\n await this.#dispatch(channelKey, channel, envelope);\n }\n return true;\n }\n return false;\n }\n\n /** Deliver through the configured Channel or composite named by the surface. */\n deliver(\n surface: ChannelMessageSurface,\n message: ChannelMessage,\n options?: ChannelDeliveryOptions\n ): Promise<DeliveryResult> {\n return this.#outbound(surface, (channel, destination) => {\n if (!channel.deliver) {\n return Promise.resolve(\n unsupported(\n \"CHANNEL_DELIVERY_UNSUPPORTED\",\n `Channel \"${destination.channelKey}\" does not support delivery`\n )\n );\n }\n return channel.deliver(destination, message, options);\n });\n }\n\n /**\n * Deliver a progressively generated answer to the Channel or composite\n * named by the surface.\n *\n * A Channel that can stream consumes the stream itself. A Channel that\n * cannot never learns it was a stream, because the Host collects the answer\n * and calls `deliver` once.\n */\n async stream(\n surface: ChannelMessageSurface,\n chunks: ChannelChunkSource,\n options: ChannelStreamOptions = {}\n ): Promise<DeliveryResult> {\n if (!isChannelMessageSurface(surface)) {\n await chunks.cancel().catch(() => {});\n return invalidSurface();\n }\n\n const channel = this.#configuredChannel(surface.channelKey);\n if (!channel.stream && !channel.deliver) {\n await chunks.cancel().catch(() => {});\n return unsupported(\n \"CHANNEL_DELIVERY_UNSUPPORTED\",\n `Channel \"${surface.channelKey}\" does not support delivery`\n );\n }\n\n if (channel.stream) return channel.stream(surface, chunks, options);\n return collectAndDeliver(channel, surface, chunks, options);\n }\n\n /** Request approval through the Channel or composite named by the surface. */\n requestApproval(\n surface: ChannelMessageSurface,\n options: ChannelApprovalRequestOptions\n ): Promise<DeliveryResult> {\n return this.#outbound(surface, (channel, destination) => {\n if (!channel.requestApproval) {\n return Promise.resolve(\n unsupported(\n \"CHANNEL_APPROVAL_UNSUPPORTED\",\n `Channel \"${destination.channelKey}\" does not support approval requests`\n )\n );\n }\n return channel.requestApproval(destination, options);\n });\n }\n\n /** Return the identity's configured Channel destination, when supported. */\n contactSurface(identity: ChannelIdentity): ChannelMessageSurface | null {\n const channel = Object.prototype.hasOwnProperty.call(\n this.#channels,\n identity.channelKey\n )\n ? this.#channels[identity.channelKey]\n : undefined;\n const surface = channel?.contactSurface?.(identity);\n return surface ? stampSurface(identity.channelKey, surface) : null;\n }\n\n /** Resolve whether a surface can currently be selected without delivery. */\n async isAvailable(surface: ChannelMessageSurface): Promise<boolean> {\n if (!isChannelMessageSurface(surface)) return false;\n const channel = this.#configuredChannel(surface.channelKey);\n return channel.isAvailable?.(surface) ?? true;\n }\n\n async #outbound(\n surface: ChannelMessageSurface,\n operation: OutboundOperation\n ): Promise<DeliveryResult> {\n if (!isChannelMessageSurface(surface)) return invalidSurface();\n const channel = this.#configuredChannel(surface.channelKey);\n return operation(channel, surface);\n }\n\n #configuredChannel(channelKey: string): Channel {\n const channel = Object.prototype.hasOwnProperty.call(\n this.#channels,\n channelKey\n )\n ? this.#channels[channelKey]\n : undefined;\n if (!channel) {\n throw new Error(\n `Channel message surface names unknown configured Channel key \"${channelKey}\"`\n );\n }\n return channel;\n }\n\n async #dispatch(\n channelKey: string,\n channel: Channel,\n envelope: ChannelIngressEnvelope\n ): Promise<void> {\n const rawEvent = envelope.event;\n const event = stampEvent(channelKey, rawEvent);\n const route = await this.#route(channelKey, channel, event, envelope.raw);\n const dispatchId = await createDispatchId(channelKey, event.eventId);\n await this.#onRoute?.({ channelKey, event, route, dispatchId });\n if (route === null) return;\n\n if (event.type === \"message\") {\n if (!this.#onMessage) {\n throw new Error(\n `Channel \"${channelKey}\" received a message without an onMessage callback`\n );\n }\n await this.#onMessage({ channelKey, route, dispatchId, message: event });\n return;\n }\n if (!this.#onApprovalResponse) {\n throw new Error(\n `Channel \"${channelKey}\" received an approval response without an onApprovalResponse callback`\n );\n }\n await this.#onApprovalResponse({\n channelKey,\n route,\n dispatchId,\n response: event\n });\n }\n\n async #route(\n channelKey: string,\n channel: Channel,\n event: ChannelIngressEvent,\n raw: unknown\n ): Promise<string | null> {\n const context = this.#routeContext(event);\n const route = channel.route\n ? await channel.route(event, raw, context)\n : this.#defaultRoute\n ? await this.#defaultRoute(event, raw, context)\n : event.thread.id;\n\n if (route === undefined) {\n throw new Error(\n `Channel route for \"${channelKey}\" returned undefined; return null to ignore an event`\n );\n }\n if (route !== null && typeof route !== \"string\") {\n throw new Error(\n `Channel route for \"${channelKey}\" must return a string or null`\n );\n }\n return route;\n }\n\n #routeContext(event: ChannelIngressEvent): ChannelRouteContext {\n let linkedUser: Promise<UserIdentity | null> | undefined;\n return {\n findUser: () => {\n if (!linkedUser) {\n const identity = event.actor?.identity;\n const findUser = this.#findUser;\n linkedUser =\n identity && findUser\n ? Promise.resolve().then(() => findUser(identity))\n : Promise.resolve(null);\n }\n return linkedUser;\n }\n };\n }\n}\n\n/**\n * Serve a Channel that cannot stream by collecting the answer first.\n *\n * A generation that failed part-way still delivers what it produced, because\n * losing the partial answer helps nobody, but the result is downgraded to\n * `uncertain` since the reader received an incomplete answer.\n */\nfunction invalidSurface(): DeliveryResult {\n return unsupported(\n \"CHANNEL_SURFACE_INVALID\",\n \"Cannot resolve an invalid Channel message surface\"\n );\n}\n\nasync function collectAndDeliver(\n channel: Channel,\n surface: ChannelMessageSurface,\n stream: ReadableStream<ChannelChunk>,\n options: ChannelStreamOptions\n): Promise<DeliveryResult> {\n const collected = await collectText(stream);\n if (collected.interrupted && collected.text.length === 0) {\n return {\n status: \"failed\",\n retryable: false,\n error: {\n code: \"CHANNEL_STREAM_INTERRUPTED\",\n message: \"The stream ended before producing any content to deliver\"\n }\n };\n }\n\n const result = await channel.deliver!(\n surface,\n {\n ...(options.title !== undefined && { title: options.title }),\n markdown: collected.text\n },\n options.delivery ? { delivery: options.delivery } : undefined\n );\n if (!collected.interrupted || result.status !== \"delivered\") return result;\n return {\n status: \"uncertain\",\n ...(result.reference !== undefined && { reference: result.reference }),\n error: {\n code: \"CHANNEL_STREAM_INTERRUPTED\",\n message:\n \"An incomplete answer was delivered because the stream ended early\"\n }\n };\n}\n\nfunction stampSurface<TAddress extends ChannelMessageSurfaceInput[\"address\"]>(\n channelKey: string,\n surface: ChannelMessageSurfaceInput<TAddress>\n): ChannelMessageSurface<string, TAddress> {\n return { ...surface, channelKey };\n}\n\nfunction stampIdentity(\n channelKey: string,\n identity: ChannelIdentityInput\n): ChannelIdentity {\n return { ...identity, channelKey };\n}\n\nfunction stampEvent(\n channelKey: string,\n event: ChannelIngressEventInput\n): ChannelIngressEvent {\n return {\n ...event,\n ...(event.replySurface && {\n replySurface: stampSurface(channelKey, event.replySurface)\n }),\n ...(event.actor && {\n actor: {\n ...event.actor,\n ...(event.actor.identity && {\n identity: stampIdentity(channelKey, event.actor.identity)\n })\n }\n })\n } as ChannelIngressEvent;\n}\n\n/** Hash an unambiguous tuple so dispatch identities remain safe to carry. */\nasync function createDispatchId(\n channelKey: string,\n eventId: string\n): Promise<string> {\n const identity = new TextEncoder().encode(\n JSON.stringify([channelKey, eventId])\n );\n const digest = await crypto.subtle.digest(\"SHA-256\", identity);\n return `sha256:${Array.from(new Uint8Array(digest), (byte) =>\n byte.toString(16).padStart(2, \"0\")\n ).join(\"\")}`;\n}\n","export type ChannelIdentity = Readonly<{\n /** Configured Channel that observed this identity. */\n channelKey: string;\n /** Stable Channel namespace in which `subject` is unique. @default \"default\" */\n scope?: string;\n /** Stable Channel subject within `scope`. */\n subject: string;\n}>;\n\n/** A Channel-produced identity before its Host stamps the configured key. */\nexport type ChannelIdentityInput = Readonly<{\n scope?: string;\n subject: string;\n}>;\n\nconst DEFAULT_IDENTITY_SCOPE = \"default\";\n\ntype NormalizedChannelIdentity = Readonly<{\n channelKey: string;\n scope: string;\n subject: string;\n}>;\n\nfunction normalizeIdentity(\n identity: ChannelIdentity\n): NormalizedChannelIdentity {\n return {\n channelKey: identity.channelKey,\n scope: identity.scope ?? DEFAULT_IDENTITY_SCOPE,\n subject: identity.subject\n };\n}\n\n/** Build a stable key for comparing or indexing a Channel identity. */\nexport function identityKey(identity: ChannelIdentity): string {\n const normalized = normalizeIdentity(identity);\n return JSON.stringify([\n normalized.channelKey,\n normalized.scope,\n normalized.subject\n ]);\n}\n\nexport type UserIdentity = Readonly<{\n /** Opaque identity owned by this store. */\n id: string;\n /** Channel identities explicitly linked to this user. */\n channelIdentities: readonly ChannelIdentity[];\n}>;\n\nexport type UserIdentityConflict = Readonly<{\n channelIdentity: ChannelIdentity;\n userId: string;\n}>;\n\n/** Raised when an operation would join identities already assigned to users. */\nexport class UserIdentityConflictError extends Error {\n readonly code = \"USER_IDENTITY_CONFLICT\";\n\n constructor(\n readonly conflicts: readonly UserIdentityConflict[],\n readonly attemptedUserId?: string\n ) {\n super(\n attemptedUserId\n ? `A channel identity is already linked to a different user than ${attemptedUserId}`\n : \"Both channel identities are already linked to users\"\n );\n this.name = \"UserIdentityConflictError\";\n }\n}\n\n/**\n * Application-owned user identity links.\n *\n * Implementations never infer links from usernames, email-like values, display\n * names, or message surfaces. Every link is an explicit application decision.\n */\nexport interface UserIdentityStore {\n /** Link one Channel identity to a user. Repeating the same link is safe. */\n link(userId: string, identity: ChannelIdentity): Promise<UserIdentity>;\n\n /** Find the user linked to one Channel identity. */\n findUser(identity: ChannelIdentity): Promise<UserIdentity | null>;\n\n /** Get a user and all of its linked Channel identities. */\n getUser(userId: string): Promise<UserIdentity | null>;\n\n /** List every user and its linked Channel identities, ordered by user ID. */\n listUsers(): Promise<UserIdentity[]>;\n\n /**\n * Atomically join two previously unjoined Channel identities.\n *\n * If one is linked, the other joins that user. If neither is linked, a new\n * user is created. If both are linked, this raises\n * `UserIdentityConflictError`, including when both point to the same user.\n */\n linkChannelIdentities(\n first: ChannelIdentity,\n second: ChannelIdentity\n ): Promise<UserIdentity>;\n}\n\nexport type UserIdentitySqlValue = ArrayBuffer | string | number | null;\n\n/** Structural storage seam satisfied by Durable Object SQLite storage. */\nexport interface UserIdentityStorage {\n readonly sql: {\n exec<Row extends Record<string, UserIdentitySqlValue>>(\n query: string,\n ...bindings: UserIdentitySqlValue[]\n ): { toArray(): Row[] };\n };\n transactionSync<Result>(closure: () => Result): Result;\n}\n\nexport type UserIdentityStoreOptions = {\n /** Generate a new opaque user ID. @default crypto.randomUUID */\n createUserId?: () => string;\n};\n\nconst USERS_TABLE = \"cf_channels_users_v1\";\nconst LINKS_TABLE = \"cf_channels_user_identity_links_v1\";\n\nfunction requireNonEmpty(label: string, value: string): void {\n if (value.length === 0) {\n throw new TypeError(`${label} must be a non-empty string`);\n }\n}\n\nfunction validatedIdentity(\n identity: ChannelIdentity\n): NormalizedChannelIdentity {\n const normalized = normalizeIdentity(identity);\n requireNonEmpty(\"identity.channelKey\", normalized.channelKey);\n requireNonEmpty(\"identity.scope\", normalized.scope);\n requireNonEmpty(\"identity.subject\", normalized.subject);\n return normalized;\n}\n\nfunction sameIdentity(\n first: ChannelIdentity,\n second: ChannelIdentity\n): boolean {\n return identityKey(first) === identityKey(second);\n}\n\nfunction compareIdentities(\n first: NormalizedChannelIdentity,\n second: NormalizedChannelIdentity\n): number {\n return (\n first.channelKey.localeCompare(second.channelKey) ||\n first.scope.localeCompare(second.scope) ||\n first.subject.localeCompare(second.subject)\n );\n}\n\n/** Build the off-the-shelf user identity store over application-owned SQLite. */\nexport function createUserIdentityStore(\n storage: UserIdentityStorage,\n options: UserIdentityStoreOptions = {}\n): UserIdentityStore {\n const createUserId = options.createUserId ?? (() => crypto.randomUUID());\n\n storage.sql.exec(`\n CREATE TABLE IF NOT EXISTS ${USERS_TABLE} (\n user_id TEXT PRIMARY KEY\n ) WITHOUT ROWID\n `);\n storage.sql.exec(`\n CREATE TABLE IF NOT EXISTS ${LINKS_TABLE} (\n channel_key TEXT NOT NULL,\n scope TEXT NOT NULL,\n subject TEXT NOT NULL,\n user_id TEXT NOT NULL,\n PRIMARY KEY (channel_key, scope, subject)\n ) WITHOUT ROWID\n `);\n storage.sql.exec(`\n CREATE INDEX IF NOT EXISTS ${LINKS_TABLE}_user\n ON ${LINKS_TABLE} (user_id, channel_key, scope, subject)\n `);\n\n function linkedUserId(identity: NormalizedChannelIdentity): string | null {\n const row = storage.sql\n .exec<{ user_id: string }>(\n `SELECT user_id FROM ${LINKS_TABLE}\n WHERE channel_key = ? AND scope = ? AND subject = ?`,\n identity.channelKey,\n identity.scope,\n identity.subject\n )\n .toArray()[0];\n return row?.user_id ?? null;\n }\n\n function readUser(userId: string): UserIdentity | null {\n const user = storage.sql\n .exec<{ user_id: string }>(\n `SELECT user_id FROM ${USERS_TABLE} WHERE user_id = ?`,\n userId\n )\n .toArray()[0];\n if (!user) return null;\n\n const channelIdentities = storage.sql\n .exec<{ channelKey: string; scope: string; subject: string }>(\n `SELECT channel_key AS channelKey, scope, subject FROM ${LINKS_TABLE}\n WHERE user_id = ?\n ORDER BY channel_key, scope, subject`,\n userId\n )\n .toArray()\n .sort(compareIdentities);\n return { id: user.user_id, channelIdentities };\n }\n\n function insertUser(userId: string): boolean {\n const inserted = storage.sql\n .exec<{ user_id: string }>(\n `INSERT INTO ${USERS_TABLE} (user_id) VALUES (?)\n ON CONFLICT (user_id) DO NOTHING\n RETURNING user_id`,\n userId\n )\n .toArray()[0];\n return inserted !== undefined;\n }\n\n function createUser(): string {\n for (let attempt = 0; attempt < 10; attempt += 1) {\n const userId = createUserId();\n requireNonEmpty(\"createUserId() result\", userId);\n if (insertUser(userId)) return userId;\n }\n throw new Error(\"createUserId() repeatedly returned existing user IDs\");\n }\n\n function insertLink(\n userId: string,\n identity: NormalizedChannelIdentity\n ): void {\n storage.sql.exec(\n `INSERT INTO ${LINKS_TABLE} (channel_key, scope, subject, user_id)\n VALUES (?, ?, ?, ?)`,\n identity.channelKey,\n identity.scope,\n identity.subject,\n userId\n );\n }\n\n const store: UserIdentityStore = {\n async link(userId, identity) {\n requireNonEmpty(\"userId\", userId);\n const normalized = validatedIdentity(identity);\n\n return storage.transactionSync(() => {\n const existingUserId = linkedUserId(normalized);\n if (existingUserId && existingUserId !== userId) {\n throw new UserIdentityConflictError(\n [{ channelIdentity: normalized, userId: existingUserId }],\n userId\n );\n }\n\n insertUser(userId);\n if (!existingUserId) insertLink(userId, normalized);\n const user = readUser(userId);\n if (!user) throw new Error(\"Linked user identity could not be read\");\n return user;\n });\n },\n\n async findUser(identity) {\n const normalized = validatedIdentity(identity);\n const userId = linkedUserId(normalized);\n return userId ? readUser(userId) : null;\n },\n\n async getUser(userId) {\n requireNonEmpty(\"userId\", userId);\n return readUser(userId);\n },\n\n async listUsers() {\n return storage.sql\n .exec<{ user_id: string }>(\n `SELECT user_id FROM ${USERS_TABLE} ORDER BY user_id`\n )\n .toArray()\n .map(({ user_id }) => readUser(user_id))\n .filter((user): user is UserIdentity => user !== null);\n },\n\n async linkChannelIdentities(first, second) {\n const normalizedFirst = validatedIdentity(first);\n const normalizedSecond = validatedIdentity(second);\n if (sameIdentity(normalizedFirst, normalizedSecond)) {\n throw new TypeError(\"Channel identities must be distinct\");\n }\n\n return storage.transactionSync(() => {\n const firstUserId = linkedUserId(normalizedFirst);\n const secondUserId = linkedUserId(normalizedSecond);\n if (firstUserId && secondUserId) {\n throw new UserIdentityConflictError([\n { channelIdentity: normalizedFirst, userId: firstUserId },\n { channelIdentity: normalizedSecond, userId: secondUserId }\n ]);\n }\n\n const userId = firstUserId ?? secondUserId ?? createUser();\n if (!firstUserId) insertLink(userId, normalizedFirst);\n if (!secondUserId) insertLink(userId, normalizedSecond);\n\n const user = readUser(userId);\n if (!user) throw new Error(\"Linked user identity could not be read\");\n return user;\n });\n }\n };\n\n return store;\n}\n\n/** Join two Channel identities through a `UserIdentityStore`. */\nexport function linkChannelIdentities(\n store: UserIdentityStore,\n first: ChannelIdentity,\n second: ChannelIdentity\n): Promise<UserIdentity> {\n return store.linkChannelIdentities(first, second);\n}\n","import type { ChannelRoute } from \"./channel\";\nimport { identityKey } from \"./identity\";\nimport type { ChannelIngressEvent } from \"./ingress\";\n\n/**\n * Common deterministic routing policies for normalized Channel events.\n *\n * Each one maps an event to a namespaced application route. Deciding whether\n * an event is relevant at all is application policy: write that in your own\n * `route` function and return `null` to ignore the event.\n */\nexport const routes = {\n /**\n * Give every event its own application route. Useful to kick off a\n * new conversation for each ingress, and where you don't want subsequent\n * messages routed back to that same conversation.\n **/\n perEvent(event: ChannelIngressEvent): string {\n return `event:${event.eventId}`;\n },\n\n /** Send every event in the same thread to the same conversation */\n perThread(event: ChannelIngressEvent): string {\n return `thread:${event.thread.id}`;\n },\n\n /**\n * Prefer the sender's own channel identity, then delegate to another route\n * policy. Without a fallback, an event carrying no identity is ignored.\n *\n * This groups events that carry the *same* identity. It never infers that\n * two different identities belong to one person: that is an explicit\n * application decision, exposed to routing through `byUser`.\n */\n byIdentity<TRaw>(fallback?: ChannelRoute<TRaw>): ChannelRoute<TRaw> {\n return (event, raw, context) => {\n const identity = event.actor?.identity;\n if (identity) return `identity:${identityKey(identity)}`;\n return fallback ? fallback(event, raw, context) : null;\n };\n },\n\n /** Prefer an explicitly linked user, then delegate to another route policy. */\n byUser<TRaw>(fallback: ChannelRoute<TRaw>): ChannelRoute<TRaw> {\n return async (event, raw, context) => {\n const user = await context.findUser();\n return user ? `user:${user.id}` : fallback(event, raw, context);\n };\n }\n};\n"],"mappings":";;;;;;;;;;;;AAkCA,SAAgB,SAAS,UAAmD;CAC1E,OAAO;EACL,YAAY;EACZ,SAAS;EACT,SAAS,EAAE,SAAS;EACpB,OAAO,SAAS,KAAK,YAAY,QAAQ,KAAK,CAAC,CAAC,KAAK,SA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,gBAAgB;IAEtD,MAAM,OAAO,SAAS,MAAM;IAC5B,IAAI,CAAC,MAAM,MAAM,IAAI,MAAM,wCAAwC;IACnE,OAAO;GACT,CAAC;EACH;CAGS;AACb;;AAGA,SAAgB,sBACd,OACA,OACA,QACuB;CACvB,OAAO,MAAM,sBAAsB,OAAO,MAAM;AAClD;;;;;;;;;;ACpUA,MAAa,SAAS;;;;;;CAMpB,SAAS,OAAoC;EAC3C,OAAO,SAAS,MAAM;CACxB;;CAGA,UAAU,OAAoC;EAC5C,OAAO,UAAU,MAAM,OAAO;CAChC;;;;;;;;;CAUA,WAAiB,UAAmD;EAClE,QAAQ,OAAO,KAAK,YAAY;GAC9B,MAAM,WAAW,MAAM,OAAO;GAC9B,IAAI,UAAU,OAAO,YAAY,YAAY,QAAQ;GACrD,OAAO,WAAW,SAAS,OAAO,KAAK,OAAO,IAAI;EACpD;CACF;;CAGA,OAAa,UAAkD;EAC7D,OAAO,OAAO,OAAO,KAAK,YAAY;GACpC,MAAM,OAAO,MAAM,QAAQ,SAAS;GACpC,OAAO,OAAO,QAAQ,KAAK,OAAO,SAAS,OAAO,KAAK,OAAO;EAChE;CACF;AACF"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import {
|
|
2
|
+
F as ChannelMessageSurface,
|
|
3
|
+
d as ChannelRoute,
|
|
4
|
+
k as ChannelIngress,
|
|
5
|
+
n as Channel,
|
|
6
|
+
u as ChannelMessage
|
|
7
|
+
} from "../channel-Bnm4S7T2.js";
|
|
8
|
+
|
|
9
|
+
//#region src/channels/adapters/slack.d.ts
|
|
10
|
+
/** The subset of a Slack event used by the adapter, with unknown fields retained. */
|
|
11
|
+
type SlackEvent = {
|
|
12
|
+
type?: string;
|
|
13
|
+
user?: string;
|
|
14
|
+
text?: string;
|
|
15
|
+
ts?: string;
|
|
16
|
+
thread_ts?: string;
|
|
17
|
+
channel?: string;
|
|
18
|
+
channel_type?: string;
|
|
19
|
+
subtype?: string;
|
|
20
|
+
bot_id?: string;
|
|
21
|
+
app_id?: string;
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
};
|
|
24
|
+
type SlackAuthorization = {
|
|
25
|
+
team_id?: string;
|
|
26
|
+
user_id?: string;
|
|
27
|
+
is_bot?: boolean;
|
|
28
|
+
[key: string]: unknown;
|
|
29
|
+
};
|
|
30
|
+
/** A typed Slack Events API callback retained in an ingress envelope. */
|
|
31
|
+
type SlackEventCallback = {
|
|
32
|
+
type: "event_callback";
|
|
33
|
+
event_id: string;
|
|
34
|
+
team_id: string;
|
|
35
|
+
event: SlackEvent;
|
|
36
|
+
authorizations?: readonly SlackAuthorization[];
|
|
37
|
+
[key: string]: unknown;
|
|
38
|
+
};
|
|
39
|
+
/** A typed Slack URL verification request. */
|
|
40
|
+
type SlackUrlVerification = {
|
|
41
|
+
type: "url_verification";
|
|
42
|
+
challenge: string;
|
|
43
|
+
[key: string]: unknown;
|
|
44
|
+
};
|
|
45
|
+
type SlackBlockAction = {
|
|
46
|
+
action_id?: string;
|
|
47
|
+
action_ts?: string;
|
|
48
|
+
value?: string;
|
|
49
|
+
[key: string]: unknown;
|
|
50
|
+
};
|
|
51
|
+
/** A typed Slack Block Kit interaction retained in an ingress envelope. */
|
|
52
|
+
type SlackBlockActions = {
|
|
53
|
+
type: "block_actions";
|
|
54
|
+
team?: {
|
|
55
|
+
id?: string;
|
|
56
|
+
[key: string]: unknown;
|
|
57
|
+
};
|
|
58
|
+
user?: {
|
|
59
|
+
id?: string;
|
|
60
|
+
username?: string;
|
|
61
|
+
name?: string;
|
|
62
|
+
[key: string]: unknown;
|
|
63
|
+
};
|
|
64
|
+
channel?: {
|
|
65
|
+
id?: string;
|
|
66
|
+
[key: string]: unknown;
|
|
67
|
+
};
|
|
68
|
+
message?: {
|
|
69
|
+
ts?: string;
|
|
70
|
+
thread_ts?: string;
|
|
71
|
+
[key: string]: unknown;
|
|
72
|
+
};
|
|
73
|
+
container?: {
|
|
74
|
+
channel_id?: string;
|
|
75
|
+
message_ts?: string;
|
|
76
|
+
thread_ts?: string;
|
|
77
|
+
[key: string]: unknown;
|
|
78
|
+
};
|
|
79
|
+
actions?: readonly SlackBlockAction[];
|
|
80
|
+
[key: string]: unknown;
|
|
81
|
+
};
|
|
82
|
+
/** Authenticated Slack payloads which may be passed to a Channel route. */
|
|
83
|
+
type SlackIngressPayload = SlackEventCallback | SlackBlockActions;
|
|
84
|
+
type SlackWebhookOptions = {
|
|
85
|
+
/** Slack app signing secret. */ signingSecret: string /** Exact webhook pathname accepted by this ingress. @default "/webhooks/slack" */;
|
|
86
|
+
path?: string /** Maximum accepted request timestamp skew in seconds. @default 300 */;
|
|
87
|
+
maxSkewSeconds?: number /** Bot user id used to discard events sent by this app. */;
|
|
88
|
+
botUserId?: string;
|
|
89
|
+
};
|
|
90
|
+
type SlackMessageSurface = ChannelMessageSurface<
|
|
91
|
+
string,
|
|
92
|
+
| {
|
|
93
|
+
channelId: string;
|
|
94
|
+
threadTs?: string /** The reader a channel stream is rendered for. Slack requires it. */;
|
|
95
|
+
recipientUserId?: string;
|
|
96
|
+
recipientTeamId?: string;
|
|
97
|
+
}
|
|
98
|
+
| {
|
|
99
|
+
teamId: string;
|
|
100
|
+
userId: string;
|
|
101
|
+
}
|
|
102
|
+
>;
|
|
103
|
+
/** Configuration for a Slack Channel. */
|
|
104
|
+
type SlackChannelOptions = {
|
|
105
|
+
/** Bot token used with chat.postMessage. */ botToken: string /** Slack Web API origin. @default "https://slack.com/api" */;
|
|
106
|
+
apiBaseUrl?: string /** Project canonical Channel Markdown into Slack mrkdwn text. */;
|
|
107
|
+
toText?: (message: ChannelMessage) => string;
|
|
108
|
+
/**
|
|
109
|
+
* Smallest gap between `chat.appendStream` calls. Chunks produced inside
|
|
110
|
+
* one interval are appended together. @default 500
|
|
111
|
+
*/
|
|
112
|
+
streamIntervalMs?: number /** Add signed Slack HTTP ingress to the returned Channel. */;
|
|
113
|
+
webhook?: SlackWebhookOptions /** Select an application route from the event, exact payload, and Host context. */;
|
|
114
|
+
route?: ChannelRoute<SlackIngressPayload> /** Override fetch for testing or custom network routing. */;
|
|
115
|
+
fetch?: typeof globalThis.fetch;
|
|
116
|
+
};
|
|
117
|
+
/** Create dependency-free, request-signed Slack HTTP ingress. */
|
|
118
|
+
declare function slackWebhook(
|
|
119
|
+
options: SlackWebhookOptions
|
|
120
|
+
): ChannelIngress<SlackIngressPayload>;
|
|
121
|
+
/** Create a configured Slack Web API Channel. */
|
|
122
|
+
declare function slack(
|
|
123
|
+
options: SlackChannelOptions
|
|
124
|
+
): Channel<SlackIngressPayload>;
|
|
125
|
+
//#endregion
|
|
126
|
+
export {
|
|
127
|
+
SlackAuthorization,
|
|
128
|
+
SlackBlockAction,
|
|
129
|
+
SlackBlockActions,
|
|
130
|
+
SlackChannelOptions,
|
|
131
|
+
SlackEvent,
|
|
132
|
+
SlackEventCallback,
|
|
133
|
+
SlackIngressPayload,
|
|
134
|
+
SlackMessageSurface,
|
|
135
|
+
SlackUrlVerification,
|
|
136
|
+
SlackWebhookOptions,
|
|
137
|
+
slack,
|
|
138
|
+
slackWebhook
|
|
139
|
+
};
|
|
140
|
+
//# sourceMappingURL=slack.d.ts.map
|