@trigger.dev/sdk 4.7.4 → 4.8.0-webhooks.20261020092920

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.
Files changed (100) hide show
  1. package/dist/commonjs/v3/ai.d.ts +626 -8
  2. package/dist/commonjs/v3/ai.js +2343 -185
  3. package/dist/commonjs/v3/ai.js.map +1 -1
  4. package/dist/commonjs/v3/chat.d.ts +23 -0
  5. package/dist/commonjs/v3/chat.js.map +1 -1
  6. package/dist/commonjs/v3/index.d.ts +2 -0
  7. package/dist/commonjs/v3/index.js +23 -17
  8. package/dist/commonjs/v3/index.js.map +1 -1
  9. package/dist/commonjs/v3/modelFileDownload.d.ts +10 -0
  10. package/dist/commonjs/v3/modelFileDownload.js +164 -0
  11. package/dist/commonjs/v3/modelFileDownload.js.map +1 -0
  12. package/dist/commonjs/v3/query.d.ts +434 -1
  13. package/dist/commonjs/v3/query.js +115 -0
  14. package/dist/commonjs/v3/query.js.map +1 -1
  15. package/dist/commonjs/v3/test/index.d.ts +2 -1
  16. package/dist/commonjs/v3/test/index.js +4 -1
  17. package/dist/commonjs/v3/test/index.js.map +1 -1
  18. package/dist/commonjs/v3/test/mock-channel-connector.d.ts +172 -0
  19. package/dist/commonjs/v3/test/mock-channel-connector.js +173 -0
  20. package/dist/commonjs/v3/test/mock-channel-connector.js.map +1 -0
  21. package/dist/commonjs/v3/test/mock-chat-agent.d.ts +81 -1
  22. package/dist/commonjs/v3/test/mock-chat-agent.js +137 -10
  23. package/dist/commonjs/v3/test/mock-chat-agent.js.map +1 -1
  24. package/dist/commonjs/v3/transcriptStorage.d.ts +44 -1
  25. package/dist/commonjs/v3/transcriptStorage.js +24 -0
  26. package/dist/commonjs/v3/transcriptStorage.js.map +1 -1
  27. package/dist/commonjs/v3/webhookWaiters.d.ts +80 -0
  28. package/dist/commonjs/v3/webhookWaiters.js +156 -0
  29. package/dist/commonjs/v3/webhookWaiters.js.map +1 -0
  30. package/dist/commonjs/v3/webhooks.d.ts +184 -2
  31. package/dist/commonjs/v3/webhooks.js +323 -1
  32. package/dist/commonjs/v3/webhooks.js.map +1 -1
  33. package/dist/commonjs/version.js +1 -1
  34. package/dist/esm/v3/ai.d.ts +626 -8
  35. package/dist/esm/v3/ai.js +2336 -184
  36. package/dist/esm/v3/ai.js.map +1 -1
  37. package/dist/esm/v3/chat.d.ts +23 -0
  38. package/dist/esm/v3/chat.js.map +1 -1
  39. package/dist/esm/v3/index.d.ts +2 -0
  40. package/dist/esm/v3/index.js +1 -0
  41. package/dist/esm/v3/index.js.map +1 -1
  42. package/dist/esm/v3/modelFileDownload.d.ts +10 -0
  43. package/dist/esm/v3/modelFileDownload.js +161 -0
  44. package/dist/esm/v3/modelFileDownload.js.map +1 -0
  45. package/dist/esm/v3/query.d.ts +434 -1
  46. package/dist/esm/v3/query.js +115 -0
  47. package/dist/esm/v3/query.js.map +1 -1
  48. package/dist/esm/v3/test/index.d.ts +2 -1
  49. package/dist/esm/v3/test/index.js +2 -1
  50. package/dist/esm/v3/test/index.js.map +1 -1
  51. package/dist/esm/v3/test/mock-channel-connector.d.ts +172 -0
  52. package/dist/esm/v3/test/mock-channel-connector.js +170 -0
  53. package/dist/esm/v3/test/mock-channel-connector.js.map +1 -0
  54. package/dist/esm/v3/test/mock-chat-agent.d.ts +81 -1
  55. package/dist/esm/v3/test/mock-chat-agent.js +137 -11
  56. package/dist/esm/v3/test/mock-chat-agent.js.map +1 -1
  57. package/dist/esm/v3/transcriptStorage.d.ts +44 -1
  58. package/dist/esm/v3/transcriptStorage.js +24 -0
  59. package/dist/esm/v3/transcriptStorage.js.map +1 -1
  60. package/dist/esm/v3/webhookWaiters.d.ts +80 -0
  61. package/dist/esm/v3/webhookWaiters.js +149 -0
  62. package/dist/esm/v3/webhookWaiters.js.map +1 -0
  63. package/dist/esm/v3/webhooks.d.ts +184 -2
  64. package/dist/esm/v3/webhooks.js +319 -1
  65. package/dist/esm/v3/webhooks.js.map +1 -1
  66. package/dist/esm/version.js +1 -1
  67. package/docs/ai-chat/actions.mdx +6 -1
  68. package/docs/ai-chat/backend.mdx +40 -0
  69. package/docs/ai-chat/patterns/redacting-telemetry.mdx +117 -0
  70. package/docs/ai-chat/pending-messages.mdx +2 -0
  71. package/docs/ai-chat/reference.mdx +53 -2
  72. package/docs/ai-chat/transcript-storage.mdx +1 -1
  73. package/docs/apikeys.mdx +6 -4
  74. package/docs/cli-runs-commands.mdx +2 -2
  75. package/docs/cli-tasks-commands.mdx +95 -0
  76. package/docs/config/config-file.mdx +58 -0
  77. package/docs/config/extensions/prismaExtension.mdx +4 -4
  78. package/docs/deploy-environment-variables.mdx +4 -0
  79. package/docs/deployment/atomic-deployment.mdx +3 -3
  80. package/docs/deployment/overview.mdx +1 -1
  81. package/docs/deployment/preview-branches.mdx +1 -1
  82. package/docs/github-actions.mdx +3 -3
  83. package/docs/limits.mdx +6 -0
  84. package/docs/manual-setup.mdx +1 -1
  85. package/docs/mcp-tools.mdx +99 -3
  86. package/docs/observability/dashboards.mdx +62 -0
  87. package/docs/runs/max-duration.mdx +4 -0
  88. package/docs/self-hosting/env/supervisor.mdx +1 -0
  89. package/docs/webhooks/channels.mdx +132 -0
  90. package/docs/webhooks/connect.mdx +84 -0
  91. package/docs/webhooks/deliveries.mdx +96 -0
  92. package/docs/webhooks/filters.mdx +142 -0
  93. package/docs/webhooks/human-in-the-loop.mdx +155 -0
  94. package/docs/webhooks/linear.mdx +189 -0
  95. package/docs/webhooks/overview.mdx +103 -0
  96. package/docs/webhooks/session-routing.mdx +138 -0
  97. package/docs/webhooks/slack.mdx +368 -0
  98. package/docs/webhooks/sources.mdx +221 -0
  99. package/docs/webhooks/waiters.mdx +194 -0
  100. package/package.json +4 -2
@@ -0,0 +1,172 @@
1
+ import type { ChannelAckCtx, ChannelCancelledToolCall, ChannelDownloadedFile, ChannelConnector, ChannelControl, ChannelInbound, ChannelInteractionCtx, ChannelInteractionResolution, ChannelLifecycleCtx, ChannelLifecycleState, ChannelMessage, ChannelPendingToolCall, ChannelProgressEvent, ChannelReaction, ChannelReactions, ChannelReply, ChannelReplyStreamEnd, ChannelSeedMessage, ChannelSendCtx, ChannelTurnCtx } from "../ai.js";
2
+ /** The default event shape {@link recordingChannelConnector} maps when no `inbound` is given. */
3
+ export type TestChannelEvent = {
4
+ text: string;
5
+ threadId?: string;
6
+ userId?: string;
7
+ };
8
+ /** The posting handle the default `bind` derives: the event's `threadId`. */
9
+ export type TestChannelHandle = {
10
+ threadId: string;
11
+ };
12
+ /** A single `send()` call captured by {@link recordingChannelConnector}. */
13
+ export type RecordedSend<TEvent = unknown> = {
14
+ /** The channel message the connector was asked to post (or edit into place). */
15
+ message: ChannelMessage;
16
+ /** The egress context: `final`, `mode`, `previousRef`, the raw `event`, `deliveryId`. */
17
+ ctx: ChannelSendCtx<TEvent>;
18
+ /** The ref this send resolved to (echoes `previousRef` on an edit, else a fresh id). */
19
+ ref: string;
20
+ };
21
+ /** A reaction applied to the triggering message, captured by {@link recordingChannelConnector}. */
22
+ export type RecordedReaction<TEvent = unknown> = {
23
+ reaction: ChannelReaction;
24
+ event: TEvent;
25
+ };
26
+ /** A `progress()` call, captured by {@link recordingChannelConnector}. */
27
+ type RecordedProgress<TEvent = unknown> = {
28
+ event: ChannelProgressEvent;
29
+ ctx: ChannelTurnCtx<TEvent>;
30
+ };
31
+ /** A `lifecycle()` report, captured by {@link recordingChannelConnector}. */
32
+ export type RecordedLifecycle<TEvent = unknown> = {
33
+ state: ChannelLifecycleState;
34
+ ctx: ChannelLifecycleCtx<TEvent>;
35
+ };
36
+ /** One turn's native reply stream (`stream: true`), captured by {@link recordingChannelConnector}. */
37
+ export type RecordedReplyStream<TEvent = unknown> = {
38
+ ctx: ChannelTurnCtx<TEvent>;
39
+ /** Every text delta, in order. */
40
+ deltas: string[];
41
+ progress: ChannelProgressEvent[];
42
+ /** How the runtime ended the stream; unset while the turn runs. */
43
+ ended?: ChannelReplyStreamEnd;
44
+ /** How many times `end()` was called (the runtime ends each stream once). */
45
+ endCalls: number;
46
+ };
47
+ /** A HITL `cancelInteraction()` call, captured by {@link recordingChannelConnector}. */
48
+ export type RecordedCancel<TEvent = unknown> = {
49
+ cancelled: ChannelCancelledToolCall[];
50
+ ctx: ChannelTurnCtx<TEvent>;
51
+ };
52
+ /** A HITL `finalizeInteraction()` call, captured by {@link recordingChannelConnector}. */
53
+ export type RecordedFinalize<TEvent = unknown> = {
54
+ event: TEvent;
55
+ resolution: ChannelInteractionResolution;
56
+ };
57
+ /**
58
+ * A real {@link ChannelConnector} whose egress hooks record what they were
59
+ * asked to do instead of touching a network, so a test can assert the channel
60
+ * round-trip a `chat.agent` turn produced. Built through the real
61
+ * `chat.channels.custom` factory, so it is a genuinely-shaped connector; only
62
+ * `send` / `ack` / `react` / `finalizeInteraction` are swapped for recorders.
63
+ */
64
+ export type RecordingChannelConnector<TEvent = unknown> = ChannelConnector<TEvent> & {
65
+ /** Every `send()` call in order: the ack, any stream edits, and the final reply. */
66
+ readonly sent: ReadonlyArray<RecordedSend<TEvent>>;
67
+ /** Turn-start placeholder posts ("final" delivery): `final: false`, no `previousRef`. */
68
+ readonly acks: ReadonlyArray<RecordedSend<TEvent>>;
69
+ /** Stream-mode intermediate edits: `mode: "stream"`, `final: false`, with `previousRef`. */
70
+ readonly edits: ReadonlyArray<RecordedSend<TEvent>>;
71
+ /** Every reaction applied to the triggering message (lifecycle + `run().channel`). */
72
+ readonly reactionsApplied: ReadonlyArray<RecordedReaction<TEvent>>;
73
+ /** Every HITL `finalizeInteraction()` call. */
74
+ readonly finalized: ReadonlyArray<RecordedFinalize<TEvent>>;
75
+ /** Every `seed()` call's triggering event, in order. */
76
+ readonly seeded: ReadonlyArray<TEvent>;
77
+ /** Every `progress()` call (tool calls and results the turn streamed), in order. */
78
+ readonly progressed: ReadonlyArray<RecordedProgress<TEvent>>;
79
+ /** Every `lifecycle()` report, in order (`lifecycle: true`). */
80
+ readonly lifecycles: ReadonlyArray<RecordedLifecycle<TEvent>>;
81
+ /** Every native reply stream the runtime opened, one per turn (`stream: true`). */
82
+ readonly streams: ReadonlyArray<RecordedReplyStream<TEvent>>;
83
+ /** Every `cancelInteraction()` call. */
84
+ readonly cancelled: ReadonlyArray<RecordedCancel<TEvent>>;
85
+ /** Every `endInterruptedStream()` call: the ref of a stream a dead worker left open. */
86
+ readonly interrupted: ReadonlyArray<{
87
+ ref: string;
88
+ ctx: ChannelTurnCtx<TEvent>;
89
+ }>;
90
+ /** The ref of the most recent `send()`, i.e. the current edit target. */
91
+ readonly lastRef: string | undefined;
92
+ /** Text of the final reply (`final: true`), or `undefined` if none posted yet. */
93
+ finalText(): string | undefined;
94
+ };
95
+ /** Options for {@link recordingChannelConnector}. */
96
+ export type RecordingChannelConnectorOptions<TEvent = TestChannelEvent> = {
97
+ /** Connector id. Defaults to {@link DEFAULT_TEST_CONNECTOR_ID} so it lines up with `sendChannelEvent`. */
98
+ id?: string;
99
+ /** The endpoint id the connector subscribes to. Server-side routing only; defaults to `"test-channel"`. */
100
+ endpointId?: string;
101
+ /** `"final"` (default: ack then edit-to-answer) or `"stream"` (debounced live edits). */
102
+ delivery?: "final" | "stream";
103
+ /** Session key template. Unused in-run (server-side routing only); defaults to `"{event.threadId}"`. */
104
+ key?: string;
105
+ /** Map the raw event to the turn's message. Defaults to `event.text`, attributed to `event.userId`. */
106
+ inbound?: (event: TEvent) => ChannelInbound;
107
+ /** Map the reply to the posted message. Defaults to `{ text }`; receives the full {@link ChannelReply}. */
108
+ outbound?: (reply: ChannelReply) => ChannelMessage | null;
109
+ /**
110
+ * Derive the session's posting handle from an event, so turns that no channel delivery started
111
+ * (an action turn, a browser message) still egress through this connector with `ctx.handle` and
112
+ * `ctx.bound: true`. Defaults to `{ threadId: event.threadId }`; pass `null` to make the
113
+ * connector unbindable.
114
+ */
115
+ bind?: ((event: TEvent) => unknown | null) | null;
116
+ /** Prior surface messages to seed a new session with (what `seed()` returns). Recorded per call. */
117
+ seed?: (event: TEvent) => Promise<ChannelSeedMessage[]> | ChannelSeedMessage[];
118
+ /**
119
+ * Placeholder posted at turn start ("final" delivery). Defaults to `{ text: "..." }`.
120
+ * Pass `null` (or a function returning `null`) to post no ack, so the final reply
121
+ * arrives as a fresh message instead of an edit.
122
+ */
123
+ ack?: ChannelMessage | null | ((event: TEvent, ctx: ChannelAckCtx) => ChannelMessage | null);
124
+ /** HITL: map a verified callback event to a tool resolution (null => treat as a normal message). */
125
+ onInteraction?: (event: TEvent) => ChannelInteractionResolution | null;
126
+ /** Fetch a file URL the connector owns for the model; null for URLs it does not own. */
127
+ download?: (url: URL, ctx: {
128
+ handle?: unknown;
129
+ }) => Promise<ChannelDownloadedFile | null>;
130
+ /** Map a click on an agent-posted control to an action for `onAction` (null for anything else). */
131
+ toAction?: (event: TEvent) => unknown | null;
132
+ /** Acknowledge a message that arrives while a turn is running. */
133
+ received?: (ctx: ChannelTurnCtx<TEvent>) => Promise<void> | void;
134
+ /** HITL: map the pending tool call(s) to the controls posted in the thread. */
135
+ renderInteraction?: (pending: ChannelPendingToolCall[], ctx: ChannelInteractionCtx<TEvent>) => ChannelMessage | null;
136
+ /** Lifecycle reaction choices (working/done/error). Requires nothing extra; `react` is always recorded. */
137
+ reactions?: ChannelReactions<TEvent>;
138
+ /** Record tool-call progress (`progress()` hook). Off by default so existing turns post nothing extra. */
139
+ progress?: boolean;
140
+ /** Provider helpers merged into `run({ channel })`. */
141
+ surface?: (ctx: ChannelTurnCtx<TEvent>) => Record<string, unknown>;
142
+ /** Map an event to a control (`{ kind: "stop" }`) while a turn runs. */
143
+ onControl?: (event: TEvent) => ChannelControl | null;
144
+ /** Record `lifecycle()` reports. Off by default. */
145
+ lifecycle?: boolean;
146
+ /**
147
+ * Stream replies natively (`delivery: "stream"` with a recording `stream()` hook): each turn's
148
+ * deltas and end outcome land in `streams`, the stream reports `opened("stream_<n>")` on its
149
+ * first delta, and it reports delivered when it saw text. `{ delivered: false }` reports every
150
+ * stream undelivered, like a Slack stream whose fallback post of the rest of the reply failed.
151
+ */
152
+ stream?: boolean | {
153
+ delivered: false;
154
+ };
155
+ };
156
+ /**
157
+ * Create a {@link RecordingChannelConnector} for driving a `chat.agent`
158
+ * channel turn offline. Pair it with `mockChatAgent(...).sendChannelEvent(...)`:
159
+ * list the connector on the agent's `channels`, deliver an event, then assert
160
+ * against `connector.sent` / `.acks` / `.edits` / `.finalText()`.
161
+ *
162
+ * @example
163
+ * ```ts
164
+ * const channel = recordingChannelConnector();
165
+ * const agent = chat.agent({ id: "support", channels: [channel], run: ... });
166
+ * const harness = mockChatAgent(agent);
167
+ * await harness.sendChannelEvent({ event: { text: "hi", threadId: "t1" } });
168
+ * expect(channel.finalText()).toBe("hello");
169
+ * ```
170
+ */
171
+ export declare function recordingChannelConnector<TEvent = TestChannelEvent>(options?: RecordingChannelConnectorOptions<TEvent>): RecordingChannelConnector<TEvent>;
172
+ export {};
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.recordingChannelConnector = recordingChannelConnector;
4
+ const ai_js_1 = require("../ai.js");
5
+ const mock_chat_agent_js_1 = require("./mock-chat-agent.js");
6
+ const DEFAULT_TEST_ENDPOINT_ID = "test-channel";
7
+ /**
8
+ * Create a {@link RecordingChannelConnector} for driving a `chat.agent`
9
+ * channel turn offline. Pair it with `mockChatAgent(...).sendChannelEvent(...)`:
10
+ * list the connector on the agent's `channels`, deliver an event, then assert
11
+ * against `connector.sent` / `.acks` / `.edits` / `.finalText()`.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const channel = recordingChannelConnector();
16
+ * const agent = chat.agent({ id: "support", channels: [channel], run: ... });
17
+ * const harness = mockChatAgent(agent);
18
+ * await harness.sendChannelEvent({ event: { text: "hi", threadId: "t1" } });
19
+ * expect(channel.finalText()).toBe("hello");
20
+ * ```
21
+ */
22
+ function recordingChannelConnector(options = {}) {
23
+ const sent = [];
24
+ const reactionsApplied = [];
25
+ const finalized = [];
26
+ const seeded = [];
27
+ const progressed = [];
28
+ const lifecycles = [];
29
+ const streams = [];
30
+ const cancelled = [];
31
+ const interrupted = [];
32
+ let refCounter = 0;
33
+ let lastRef;
34
+ const inbound = options.inbound ??
35
+ ((event) => {
36
+ const e = event;
37
+ return { message: e?.text ?? "", externalUserId: e?.userId };
38
+ });
39
+ const bind = options.bind === null
40
+ ? undefined
41
+ : (options.bind ??
42
+ ((event) => {
43
+ const threadId = event?.threadId;
44
+ return threadId ? { threadId } : null;
45
+ }));
46
+ const ackFn = options.ack === undefined
47
+ ? () => ({ text: "..." })
48
+ : typeof options.ack === "function"
49
+ ? options.ack
50
+ : () => options.ack;
51
+ const send = async (message, ctx) => {
52
+ const ref = ctx.previousRef ?? `ref_${++refCounter}`;
53
+ sent.push({ message, ctx, ref });
54
+ lastRef = ref;
55
+ return { ref };
56
+ };
57
+ const react = async (reaction, ctx) => {
58
+ reactionsApplied.push({ reaction, event: ctx.event });
59
+ };
60
+ const finalizeInteraction = async (event, resolution) => {
61
+ finalized.push({ event, resolution });
62
+ };
63
+ const connector = ai_js_1.chat.channels.custom({
64
+ id: options.id ?? mock_chat_agent_js_1.DEFAULT_TEST_CONNECTOR_ID,
65
+ endpoint: {
66
+ id: options.endpointId ?? DEFAULT_TEST_ENDPOINT_ID,
67
+ source: "custom",
68
+ },
69
+ key: (options.key ?? "{event.threadId}"),
70
+ inbound: inbound,
71
+ ...(bind ? { bind: bind } : {}),
72
+ ...(options.seed
73
+ ? {
74
+ seed: (async (event) => {
75
+ seeded.push(event);
76
+ return options.seed(event);
77
+ }),
78
+ }
79
+ : {}),
80
+ ack: ackFn,
81
+ ...(options.outbound ? { outbound: options.outbound } : {}),
82
+ send: send,
83
+ react: react,
84
+ finalizeInteraction: finalizeInteraction,
85
+ ...(options.onInteraction ? { onInteraction: options.onInteraction } : {}),
86
+ ...(options.download ? { download: options.download } : {}),
87
+ ...(options.toAction ? { toAction: options.toAction } : {}),
88
+ ...(options.received ? { received: options.received } : {}),
89
+ ...(options.renderInteraction ? { renderInteraction: options.renderInteraction } : {}),
90
+ ...(options.reactions ? { reactions: options.reactions } : {}),
91
+ ...(options.progress
92
+ ? {
93
+ progress: ((event, ctx) => {
94
+ progressed.push({ event, ctx });
95
+ }),
96
+ }
97
+ : {}),
98
+ ...(options.surface ? { surface: options.surface } : {}),
99
+ ...(options.onControl ? { onControl: options.onControl } : {}),
100
+ ...(options.lifecycle
101
+ ? {
102
+ lifecycle: ((state, ctx) => {
103
+ lifecycles.push({ state, ctx });
104
+ }),
105
+ }
106
+ : {}),
107
+ ...(options.stream
108
+ ? {
109
+ stream: ((ctx) => {
110
+ const recorded = {
111
+ ctx,
112
+ deltas: [],
113
+ progress: [],
114
+ endCalls: 0,
115
+ };
116
+ streams.push(recorded);
117
+ return {
118
+ text: (delta) => {
119
+ if (recorded.deltas.length === 0)
120
+ ctx.opened(`stream_${streams.length}`);
121
+ recorded.deltas.push(delta);
122
+ },
123
+ progress: (event) => {
124
+ recorded.progress.push(event);
125
+ },
126
+ end: async (outcome) => {
127
+ recorded.endCalls += 1;
128
+ recorded.ended = outcome;
129
+ const undelivered = typeof options.stream === "object" && options.stream.delivered === false;
130
+ return { delivered: !undelivered && recorded.deltas.join("").length > 0 };
131
+ },
132
+ };
133
+ }),
134
+ }
135
+ : {}),
136
+ endInterruptedStream: ((ref, ctx) => {
137
+ interrupted.push({ ref, ctx });
138
+ }),
139
+ cancelInteraction: ((cancelledCalls, ctx) => {
140
+ cancelled.push({ cancelled: cancelledCalls, ctx });
141
+ }),
142
+ delivery: options.delivery ?? (options.stream ? "stream" : "final"),
143
+ });
144
+ Object.defineProperties(connector, {
145
+ sent: { get: () => sent, enumerable: true },
146
+ reactionsApplied: { get: () => reactionsApplied, enumerable: true },
147
+ finalized: { get: () => finalized, enumerable: true },
148
+ seeded: { get: () => seeded, enumerable: true },
149
+ progressed: { get: () => progressed, enumerable: true },
150
+ lifecycles: { get: () => lifecycles, enumerable: true },
151
+ streams: { get: () => streams, enumerable: true },
152
+ cancelled: { get: () => cancelled, enumerable: true },
153
+ interrupted: { get: () => interrupted, enumerable: true },
154
+ lastRef: { get: () => lastRef, enumerable: true },
155
+ acks: {
156
+ get: () => sent.filter((s) => s.ctx.final === false && s.ctx.previousRef === undefined),
157
+ enumerable: true,
158
+ },
159
+ edits: {
160
+ get: () => sent.filter((s) => s.ctx.mode === "stream" && s.ctx.final === false && s.ctx.previousRef !== undefined),
161
+ enumerable: true,
162
+ },
163
+ });
164
+ connector.finalText = () => {
165
+ for (let i = sent.length - 1; i >= 0; i--) {
166
+ if (sent[i].ctx.final)
167
+ return sent[i].message.text;
168
+ }
169
+ return undefined;
170
+ };
171
+ return connector;
172
+ }
173
+ //# sourceMappingURL=mock-channel-connector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock-channel-connector.js","sourceRoot":"","sources":["../../../../src/v3/test/mock-channel-connector.ts"],"names":[],"mappings":";;;AAAA,oCAAgC;AAyBhC,6DAAiE;AAEjE,MAAM,wBAAwB,GAAG,cAAc,CAAC;AA0JhD;;;;;;;;;;;;;;GAcG;AACH,mCACE,OAAO,GAA6C,EAAE;IAEtD,MAAM,IAAI,GAA2B,EAAE,CAAC;IACxC,MAAM,gBAAgB,GAA+B,EAAE,CAAC;IACxD,MAAM,SAAS,GAA+B,EAAE,CAAC;IACjD,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,UAAU,GAA+B,EAAE,CAAC;IAClD,MAAM,UAAU,GAAgC,EAAE,CAAC;IACnD,MAAM,OAAO,GAAkC,EAAE,CAAC;IAClD,MAAM,SAAS,GAA6B,EAAE,CAAC;IAC/C,MAAM,WAAW,GAAwD,EAAE,CAAC;IAC5E,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,IAAI,OAA2B,CAAC;IAEhC,MAAM,OAAO,GACX,OAAO,CAAC,OAAO;QACf,CAAC,CAAC,KAAa,EAAkB,EAAE;YACjC,MAAM,CAAC,GAAG,KAA0E,CAAC;YACrF,OAAO,EAA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in` tail for the next boot's replay, alongside browser
18
+ * messages, so a test can check that recovery dispatches both kinds in the order they arrived.
19
+ */
20
+ export type SeededChannelDelivery = {
21
+ channelEvent: {
22
+ event: unknown;
23
+ connectorId?: string;
24
+ source?: string;
25
+ headers?: Record<string, string>;
26
+ deliveryId?: string;
27
+ };
28
+ };
16
29
  export type MockChatAgentOptions = {
17
30
  /** The chat session id passed into every wire payload. Defaults to `"test-chat"`. */
18
31
  chatId?: string;
@@ -147,6 +160,20 @@ export type MockChatAgentHarness = {
147
160
  }): Promise<MockChatAgentTurn>;
148
161
  /** Send a custom action and wait for the next turn-complete. */
149
162
  sendAction(action: unknown): Promise<MockChatAgentTurn>;
163
+ /**
164
+ * Deliver a `chat.event` webhook action: the `{ type, event, source, headers, deliveryId, externalDeliveryId }`
165
+ * envelope the hosted ingress appends to `session.in` with `actionSource: "webhook"`, so it
166
+ * bypasses `actionSchema` and reaches `onAction` typed by the listed events. Waits for the
167
+ * turn-complete the action (or the turn it becomes via `chat.turn()`) writes.
168
+ */
169
+ sendWebhookAction(args: {
170
+ type: string;
171
+ event: unknown;
172
+ source?: string;
173
+ headers?: Record<string, string>;
174
+ deliveryId?: string;
175
+ externalDeliveryId?: string;
176
+ }): Promise<MockChatAgentTurn>;
150
177
  /**
151
178
  * Deliver a message mid-turn without waiting for it, the way the browser's
152
179
  * steering path does. With a `pendingMessages` config the agent routes it into
@@ -157,6 +184,52 @@ export type MockChatAgentHarness = {
157
184
  * call this. Awaiting the turn first leaves nothing to steer.
158
185
  */
159
186
  sendPendingMessage(message: UIMessage): Promise<void>;
187
+ /**
188
+ * Deliver a channel event mid-turn without waiting for it, the way a Slack message lands while
189
+ * the agent is answering. With a `pendingMessages` config it can be steered into the running
190
+ * turn; otherwise, or when `shouldInject` declines, it runs as the next turn.
191
+ */
192
+ sendPendingChannelEvent(args: {
193
+ event: unknown;
194
+ connectorId?: string;
195
+ source?: string;
196
+ deliveryId?: string;
197
+ }): Promise<void>;
198
+ /**
199
+ * Deliver a verified channel event (Slack or any `chat.channels.*`
200
+ * connector) and wait for the next turn-complete. Mirrors what the hosted
201
+ * webhook ingress appends to `session.in`: a `submit-message` wire payload
202
+ * carrying `channelEvent` instead of `message`. The run resolves the
203
+ * connector by `connectorId`, maps the event with its `inbound()`, runs the
204
+ * turn, and posts the reply back through the connector's `send()`.
205
+ *
206
+ * `connectorId` defaults to `DEFAULT_TEST_CONNECTOR_ID`, which is also the id
207
+ * `recordingChannelConnector()` uses when you don't set one, so the common
208
+ * single-connector case lines up. Pass it explicitly for a connector with a
209
+ * custom id or for multi-connector agents.
210
+ */
211
+ sendChannelEvent(args: {
212
+ event: unknown;
213
+ connectorId?: string;
214
+ source?: string;
215
+ headers?: Record<string, string>;
216
+ deliveryId?: string;
217
+ externalDeliveryId?: string;
218
+ }): Promise<MockChatAgentTurn>;
219
+ /**
220
+ * Deliver a channel event without waiting for a turn. Mirrors an event that
221
+ * the run may not turn into a turn: a filtered or deduped delivery, or a
222
+ * stale interaction callback that is dropped (matches no pending tool call).
223
+ * Resolves once the run has had a chance to process and possibly drop it.
224
+ */
225
+ deliverChannelEvent(args: {
226
+ event: unknown;
227
+ connectorId?: string;
228
+ source?: string;
229
+ headers?: Record<string, string>;
230
+ deliveryId?: string;
231
+ externalDeliveryId?: string;
232
+ }): Promise<void>;
160
233
  /** Fire a stop signal. Does not wait for the turn — the task keeps running. */
161
234
  sendStop(message?: string): Promise<void>;
162
235
  /**
@@ -219,7 +292,7 @@ export type MockChatAgentHarness = {
219
292
  *
220
293
  * Effective on the next run boot only.
221
294
  */
222
- seedSessionInTail(messages: UIMessage[]): void;
295
+ seedSessionInTail(entries: Array<UIMessage | SeededChannelDelivery>): void;
223
296
  /**
224
297
  * Append a `trigger: "close"` record to `session.in` — what the server does
225
298
  * when a session is closed from outside (dashboard, `sessions.close()`, MCP).
@@ -270,6 +343,13 @@ export type MockChatAgentHarness = {
270
343
  /** Every raw chunk (including control chunks) emitted since the harness was created. */
271
344
  readonly allRawChunks: unknown[];
272
345
  };
346
+ /**
347
+ * Default `connectorId` used by {@link MockChatAgentHarness.sendChannelEvent}
348
+ * when the caller omits it. Matches the default `id` of
349
+ * {@link recordingChannelConnector}, so a single-connector agent needs no
350
+ * explicit id on either side.
351
+ */
352
+ export declare const DEFAULT_TEST_CONNECTOR_ID = "test-channel";
273
353
  /**
274
354
  * Create an offline test harness for a `chat.agent` task.
275
355
  *