channelstack 0.0.0-placeholder.0 → 0.1.1

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 (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +55 -1
  3. package/bin/channelstack.mjs +31 -0
  4. package/dist/integrations/checks/checks.test.d.ts +1 -0
  5. package/dist/integrations/checks/checks.test.js +31 -0
  6. package/dist/integrations/checks/index.d.ts +69 -0
  7. package/dist/integrations/checks/index.js +578 -0
  8. package/dist/integrations/matchers-core/index.d.ts +138 -0
  9. package/dist/integrations/matchers-core/index.js +458 -0
  10. package/dist/integrations/matchers-core/matchers.test.d.ts +1 -0
  11. package/dist/integrations/matchers-core/matchers.test.js +159 -0
  12. package/dist/integrations/vitest/global-setup.d.ts +3 -0
  13. package/dist/integrations/vitest/global-setup.js +19 -0
  14. package/dist/integrations/vitest/index.d.ts +80 -0
  15. package/dist/integrations/vitest/index.js +42 -0
  16. package/dist/integrations/vitest/plugin.test.d.ts +1 -0
  17. package/dist/integrations/vitest/plugin.test.js +19 -0
  18. package/dist/integrations/vitest/refused.d.ts +22 -0
  19. package/dist/integrations/vitest/refused.js +49 -0
  20. package/dist/integrations/vitest/setup.d.ts +1 -0
  21. package/dist/integrations/vitest/setup.js +109 -0
  22. package/dist/sdks/typescript/client.d.ts +13 -0
  23. package/dist/sdks/typescript/client.js +11 -0
  24. package/dist/sdks/typescript/generated/channels.d.ts +24 -0
  25. package/dist/sdks/typescript/generated/channels.js +2 -0
  26. package/dist/sdks/typescript/generated/index.d.ts +2747 -0
  27. package/dist/sdks/typescript/generated/index.js +3039 -0
  28. package/dist/sdks/typescript/runtime/client.d.ts +47 -0
  29. package/dist/sdks/typescript/runtime/client.js +69 -0
  30. package/dist/sdks/typescript/runtime/credentials.d.ts +7 -0
  31. package/dist/sdks/typescript/runtime/credentials.js +20 -0
  32. package/dist/sdks/typescript/runtime/duration.d.ts +4 -0
  33. package/dist/sdks/typescript/runtime/duration.js +13 -0
  34. package/dist/sdks/typescript/runtime/files.d.ts +32 -0
  35. package/dist/sdks/typescript/runtime/files.js +45 -0
  36. package/dist/sdks/typescript/runtime/launcher.d.ts +24 -0
  37. package/dist/sdks/typescript/runtime/launcher.js +121 -0
  38. package/dist/sdks/typescript/runtime/transport.d.ts +43 -0
  39. package/dist/sdks/typescript/runtime/transport.js +95 -0
  40. package/dist/sdks/typescript/runtime/wait.d.ts +82 -0
  41. package/dist/sdks/typescript/runtime/wait.js +136 -0
  42. package/dist/sdks/typescript/types.d.ts +72 -0
  43. package/dist/sdks/typescript/types.js +1 -0
  44. package/package.json +78 -4
  45. package/index.js +0 -1
@@ -0,0 +1,3039 @@
1
+ // Generated by codegen from spec/ir.json. Do not edit: change the routes and run `pnpm sdk`.
2
+ import { ClientBase, connectWith, disposeQuietly, printsAs, QUIET, quietOf, sessionOf } from "../runtime/client.js";
3
+ import { credential } from "../runtime/credentials.js";
4
+ import { parseDuration } from "../runtime/duration.js";
5
+ import { readChanges, readDocument, readTree } from "../runtime/files.js";
6
+ import { ChannelstackError, segment } from "../runtime/transport.js";
7
+ import { describeWait, fromMatches, textMatches, latestOnceQuiet, waitFor, waitForNext, retryWhile, untilQuiet, patternOnWire } from "../runtime/wait.js";
8
+ /** The server version this SDK was generated for. */
9
+ export const VERSION = "0.1.1";
10
+ export class AccountInactiveError extends ChannelstackError {
11
+ }
12
+ export class ActionRequiresError extends ChannelstackError {
13
+ }
14
+ export class AlreadyInChannelError extends ChannelstackError {
15
+ }
16
+ export class AlreadyReactedError extends ChannelstackError {
17
+ }
18
+ export class CantDeleteMessageError extends ChannelstackError {
19
+ }
20
+ export class CantUpdateMessageError extends ChannelstackError {
21
+ }
22
+ export class CrossWorkspaceCredentialError extends ChannelstackError {
23
+ }
24
+ export class DispatchFailedError extends ChannelstackError {
25
+ }
26
+ export class FakeActorInLiveWorldError extends ChannelstackError {
27
+ }
28
+ export class ForbiddenError extends ChannelstackError {
29
+ }
30
+ export class InternalError extends ChannelstackError {
31
+ }
32
+ export class InvalidArgumentError extends ChannelstackError {
33
+ }
34
+ export class InvalidAuthError extends ChannelstackError {
35
+ }
36
+ export class LiveMisconfiguredError extends ChannelstackError {
37
+ }
38
+ export class LiveNotAllowlistedError extends ChannelstackError {
39
+ }
40
+ export class MsgTooLongError extends ChannelstackError {
41
+ }
42
+ export class NameTakenError extends ChannelstackError {
43
+ }
44
+ export class NoReactionError extends ChannelstackError {
45
+ }
46
+ export class NoTextError extends ChannelstackError {
47
+ }
48
+ export class NotAllowedError extends ChannelstackError {
49
+ }
50
+ export class NotFoundError extends ChannelstackError {
51
+ }
52
+ export class NotInChannelError extends ChannelstackError {
53
+ }
54
+ export class NotInRoomError extends ChannelstackError {
55
+ }
56
+ export class SessionNotFoundError extends ChannelstackError {
57
+ }
58
+ export class SplitViewUnavailableError extends ChannelstackError {
59
+ }
60
+ export class StopUnavailableError extends ChannelstackError {
61
+ }
62
+ export class UnauthorizedError extends ChannelstackError {
63
+ }
64
+ export class UnsupportedInFakeError extends ChannelstackError {
65
+ }
66
+ export class UnsupportedInLiveError extends ChannelstackError {
67
+ }
68
+ export class ValidationFailedError extends ChannelstackError {
69
+ }
70
+ const ERRORS = {
71
+ account_inactive: AccountInactiveError,
72
+ action_requires: ActionRequiresError,
73
+ already_in_channel: AlreadyInChannelError,
74
+ already_reacted: AlreadyReactedError,
75
+ cant_delete_message: CantDeleteMessageError,
76
+ cant_update_message: CantUpdateMessageError,
77
+ cross_workspace_credential: CrossWorkspaceCredentialError,
78
+ dispatch_failed: DispatchFailedError,
79
+ fake_actor_in_live_world: FakeActorInLiveWorldError,
80
+ forbidden: ForbiddenError,
81
+ internal: InternalError,
82
+ invalid_argument: InvalidArgumentError,
83
+ invalid_auth: InvalidAuthError,
84
+ live_misconfigured: LiveMisconfiguredError,
85
+ live_not_allowlisted: LiveNotAllowlistedError,
86
+ msg_too_long: MsgTooLongError,
87
+ name_taken: NameTakenError,
88
+ no_reaction: NoReactionError,
89
+ no_text: NoTextError,
90
+ not_allowed: NotAllowedError,
91
+ not_found: NotFoundError,
92
+ not_in_channel: NotInChannelError,
93
+ not_in_room: NotInRoomError,
94
+ session_not_found: SessionNotFoundError,
95
+ split_view_unavailable: SplitViewUnavailableError,
96
+ stop_unavailable: StopUnavailableError,
97
+ unauthorized: UnauthorizedError,
98
+ unsupported_in_fake: UnsupportedInFakeError,
99
+ unsupported_in_live: UnsupportedInLiveError,
100
+ validation_failed: ValidationFailedError,
101
+ };
102
+ function decodeSlackUsers(ctx, data) {
103
+ return data.map((item) => new SlackUser(ctx, item));
104
+ }
105
+ function decodeSlackConversations(ctx, data) {
106
+ return data.map((item) => new SlackConversation(ctx, item));
107
+ }
108
+ function decodeSlackModals(ctx, data) {
109
+ return data.map((item) => new SlackModal(ctx, item));
110
+ }
111
+ function decodeSlackModalValues(ctx, data) {
112
+ return Object.fromEntries(Object.entries(data).map(([key, value]) => [key, (value === null ? undefined : value)]));
113
+ }
114
+ function decodeSlackMessages(ctx, data) {
115
+ return data.map((item) => new SlackMessage(ctx, item));
116
+ }
117
+ function decodeSlackMembers(ctx, data) {
118
+ return data.map((item) => item.kind === "user" ? new SlackUser(ctx, item) : new SlackApp(ctx, item));
119
+ }
120
+ function decodeSlackReplies(ctx, data) {
121
+ return data.map((item) => new SlackMessage(ctx, item));
122
+ }
123
+ function decodeSlackReactions(ctx, data) {
124
+ return data.map((item) => decodeSlackReaction(ctx, item));
125
+ }
126
+ function decodeSlackReaction(ctx, data) {
127
+ return { ...data, by: data.by.map((item) => item.kind === "user" ? new SlackUser(ctx, item) : new SlackApp(ctx, item)) };
128
+ }
129
+ function decodeSlackTranscript(_ctx, data) {
130
+ return printsAs({ ...data }, data.text);
131
+ }
132
+ function decodeSlackEphemeralMessages(ctx, data) {
133
+ return data.map((item) => new SlackMessage(ctx, item));
134
+ }
135
+ function decodeSlackMessageDeliveries(ctx, data) {
136
+ return data.map((item) => new SlackDelivery(ctx, item));
137
+ }
138
+ function decodeSlackDeliveries(ctx, data) {
139
+ return data.map((item) => new SlackDelivery(ctx, item));
140
+ }
141
+ function decodeSlackUninstallDeliveries(ctx, data) {
142
+ return data.map((item) => new SlackDelivery(ctx, item));
143
+ }
144
+ function decodeGitHubCommits(ctx, data) {
145
+ return data.map((item) => new GitHubCommit(ctx, item));
146
+ }
147
+ function decodeGitHubCheckRuns(ctx, data) {
148
+ return data.map((item) => new GitHubCheckRun(ctx, item));
149
+ }
150
+ function decodeGitHubStatuses(ctx, data) {
151
+ return data.map((item) => ({ ...item, author: item.author.kind === "user" ? new GitHubUser(ctx, item.author) : new GitHubApp(ctx, item.author) }));
152
+ }
153
+ function decodeGitHubLabelDeliveries(ctx, data) {
154
+ return data.map((item) => new GitHubDelivery(ctx, item));
155
+ }
156
+ function decodeGitHubUnlabelDeliveries(ctx, data) {
157
+ return data.map((item) => new GitHubDelivery(ctx, item));
158
+ }
159
+ function decodeGitHubAssignDeliveries(ctx, data) {
160
+ return data.map((item) => new GitHubDelivery(ctx, item));
161
+ }
162
+ function decodeGitHubReview(ctx, data) {
163
+ return (({ delivery, ...rest }) => ({ ...rest, author: rest.author.kind === "user" ? new GitHubUser(ctx, rest.author) : new GitHubApp(ctx, rest.author), comments: rest.comments.map((item) => new GitHubReviewComment(ctx, item)), ...(delivery === undefined ? {} : { delivery: new GitHubDelivery(ctx, delivery) }) }))(data);
164
+ }
165
+ function decodeGitHubComments(ctx, data) {
166
+ return data.map((item) => new GitHubComment(ctx, item));
167
+ }
168
+ function decodeGitHubTranscript(_ctx, data) {
169
+ return printsAs({ ...data }, data.text);
170
+ }
171
+ function decodeGitHubReviews(ctx, data) {
172
+ return data.map((item) => decodeGitHubReview(ctx, item));
173
+ }
174
+ function decodeGitHubReviewComments(ctx, data) {
175
+ return data.map((item) => new GitHubReviewComment(ctx, item));
176
+ }
177
+ function decodeGitHubPullCheckRuns(ctx, data) {
178
+ return data.map((item) => new GitHubCheckRun(ctx, item));
179
+ }
180
+ function decodeGitHubReactions(ctx, data) {
181
+ return data.map((item) => decodeGitHubReaction(ctx, item));
182
+ }
183
+ function decodeGitHubReaction(ctx, data) {
184
+ return { ...data, by: data.by.map((item) => item.kind === "user" ? new GitHubUser(ctx, item) : new GitHubApp(ctx, item)) };
185
+ }
186
+ function decodeGitHubReviewCommentReplies(ctx, data) {
187
+ return data.map((item) => new GitHubReviewComment(ctx, item));
188
+ }
189
+ function decodeGitHubDeliveries(ctx, data) {
190
+ return data.map((item) => new GitHubDelivery(ctx, item));
191
+ }
192
+ function decodeLinearComments(ctx, data) {
193
+ return data.map((item) => new LinearComment(ctx, item));
194
+ }
195
+ function decodeLinearAgentSessions(ctx, data) {
196
+ return data.map((item) => new LinearAgentSession(ctx, item));
197
+ }
198
+ function decodeLinearTranscript(_ctx, data) {
199
+ return printsAs({ ...data }, data.text);
200
+ }
201
+ function decodeLinearCommentReplies(ctx, data) {
202
+ return data.map((item) => new LinearComment(ctx, item));
203
+ }
204
+ function decodeLinearAgentActivities(ctx, data) {
205
+ return data.map((item) => new LinearAgentActivity(ctx, item));
206
+ }
207
+ function decodeLinearDeliveries(ctx, data) {
208
+ return data.map((item) => new LinearDelivery(ctx, item));
209
+ }
210
+ function decodeNotionPropertyValue(ctx, data) {
211
+ return (data === null ? undefined : data);
212
+ }
213
+ function decodeNotionDiscussions(ctx, data) {
214
+ return data.map((item) => new NotionDiscussion(ctx, item));
215
+ }
216
+ function decodeNotionChildPages(ctx, data) {
217
+ return data.map((item) => new NotionPage(ctx, item));
218
+ }
219
+ function decodeNotionConnections(ctx, data) {
220
+ return data.map((item) => new NotionIntegration(ctx, item));
221
+ }
222
+ function decodeNotionTranscript(_ctx, data) {
223
+ return printsAs({ ...data }, data.text);
224
+ }
225
+ function decodeNotionRows(ctx, data) {
226
+ return data.map((item) => new NotionPage(ctx, item));
227
+ }
228
+ function decodeNotionComments(ctx, data) {
229
+ return data.map((item) => new NotionComment(ctx, item));
230
+ }
231
+ function decodeNotionDeliveries(ctx, data) {
232
+ return data.map((item) => new NotionDelivery(ctx, item));
233
+ }
234
+ function decodeResendInbox(ctx, data) {
235
+ return data.map((item) => new ResendEmail(ctx, item));
236
+ }
237
+ function decodeResendMessages(ctx, data) {
238
+ return data.map((item) => new ResendEmail(ctx, item));
239
+ }
240
+ function decodeResendReplies(ctx, data) {
241
+ return data.map((item) => new ResendEmail(ctx, item));
242
+ }
243
+ function decodeResendTranscript(_ctx, data) {
244
+ return printsAs({ ...data }, data.text);
245
+ }
246
+ function decodeResendDeliveries(ctx, data) {
247
+ return data.map((item) => new ResendDelivery(ctx, item));
248
+ }
249
+ function decodeGoogleInbox(ctx, data) {
250
+ return data.map((item) => new GoogleEmail(ctx, item));
251
+ }
252
+ function decodeGoogleMessages(ctx, data) {
253
+ return data.map((item) => new GoogleEmail(ctx, item));
254
+ }
255
+ function decodeGoogleReplies(ctx, data) {
256
+ return data.map((item) => new GoogleEmail(ctx, item));
257
+ }
258
+ function decodeGoogleTranscript(_ctx, data) {
259
+ return printsAs({ ...data }, data.text);
260
+ }
261
+ function decodeGoogleDeliveries(ctx, data) {
262
+ return data.map((item) => new GoogleDelivery(ctx, item));
263
+ }
264
+ export class Channelstack extends ClientBase {
265
+ #ctx;
266
+ /** @internal Handles come from the SDK, never from `new`. */
267
+ constructor(transport, stop) {
268
+ super(stop);
269
+ this.#ctx = { transport, session: undefined };
270
+ }
271
+ /** Server health, version and loaded drivers. */
272
+ async status() {
273
+ const ctx = this.#ctx;
274
+ const data = (await ctx.transport.request("GET", `/status`));
275
+ return data;
276
+ }
277
+ /** Open a session: a scope in the shared world that owns what it creates. */
278
+ async openSession(options = {}) {
279
+ const ctx = this.#ctx;
280
+ const data = (await ctx.transport.request("POST", `/sessions`, { body: { name: options.name } }));
281
+ return new Session({ transport: ctx.transport, session: data.sessionId }, data);
282
+ }
283
+ /** Drop the whole world. Avoid in parallel suites. */
284
+ async reset() {
285
+ const ctx = this.#ctx;
286
+ await ctx.transport.request("POST", `/reset`);
287
+ }
288
+ /** Env vars for the agent: fake tokens, signing secrets and API URLs (what `channelstack env` prints). With `proxy`, the proxy and the CA instead of the API URLs. */
289
+ async env(options = {}) {
290
+ const ctx = this.#ctx;
291
+ const data = (await ctx.transport.request("GET", `/env`, { query: { proxy: options.proxy } }));
292
+ return data;
293
+ }
294
+ /** A new one-time link that opens the UI in a browser (what `channelstack ui` prints). Experimental. */
295
+ async uiLoginLink() {
296
+ const ctx = this.#ctx;
297
+ const data = (await ctx.transport.request("POST", `/ui/login-links`));
298
+ return data;
299
+ }
300
+ }
301
+ export class Session {
302
+ sessionId;
303
+ drivers;
304
+ #ctx;
305
+ /** @internal Handles come from the SDK, never from `new`. */
306
+ constructor(ctx, data) {
307
+ this.#ctx = ctx;
308
+ this.sessionId = data.sessionId;
309
+ this.drivers = data.drivers;
310
+ }
311
+ /** Close a session and remove everything it created. */
312
+ async close() {
313
+ const ctx = this.#ctx;
314
+ await ctx.transport.request("DELETE", `/sessions/${segment(sessionOf(ctx))}`);
315
+ }
316
+ async [Symbol.asyncDispose]() {
317
+ await disposeQuietly(() => this.close());
318
+ }
319
+ /** The session's event log: actions, deliveries with every attempt, and the agent's API calls. */
320
+ async events(options = {}) {
321
+ const ctx = this.#ctx;
322
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/events`, { query: { since: options.since } }));
323
+ return data;
324
+ }
325
+ /** Is the agent idle in this session, and for how long? Negative and exact-count matchers wait for this. */
326
+ async quiet() {
327
+ const ctx = this.#ctx;
328
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/quiet`));
329
+ return data;
330
+ }
331
+ /** The echo fixture: the agent's app and where it reaches the fake. Experimental. */
332
+ async echo() {
333
+ const ctx = this.#ctx;
334
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/echo`));
335
+ return new EchoFixture(ctx, data);
336
+ }
337
+ /** The Slack fixture: the agent's app, the workspace, and where the agent reaches the fake. Experimental. */
338
+ async slack() {
339
+ const ctx = this.#ctx;
340
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack`));
341
+ return new SlackFixture(ctx, data);
342
+ }
343
+ /** The GitHub fixture: the agent's App, the org, and where the agent reaches the fake. Experimental. */
344
+ async github() {
345
+ const ctx = this.#ctx;
346
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github`));
347
+ return new GitHubFixture(ctx, data);
348
+ }
349
+ /** The Linear fixture: the agent's app, and where the agent reaches the fake. Experimental. */
350
+ async linear() {
351
+ const ctx = this.#ctx;
352
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear`));
353
+ return new LinearFixture(ctx, data);
354
+ }
355
+ /** The Notion fixture: the agent's integration, and where the agent reaches the fake. Experimental. */
356
+ async notion() {
357
+ const ctx = this.#ctx;
358
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/notion`));
359
+ return new NotionFixture(ctx, data);
360
+ }
361
+ /** The Resend fixture: the agent's team, and where the agent reaches the fake. Experimental. */
362
+ async resend() {
363
+ const ctx = this.#ctx;
364
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/resend`));
365
+ return new ResendFixture(ctx, data);
366
+ }
367
+ /** The Google fixture: the agent's mailbox, and where the agent reaches the fake. Experimental. */
368
+ async google() {
369
+ const ctx = this.#ctx;
370
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/google`));
371
+ return new GoogleFixture(ctx, data);
372
+ }
373
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
374
+ [QUIET]() {
375
+ return quietOf(this.#ctx);
376
+ }
377
+ }
378
+ export class EchoFixture {
379
+ app;
380
+ apiUrl;
381
+ #ctx;
382
+ /** @internal Handles come from the SDK, never from `new`. */
383
+ constructor(ctx, data) {
384
+ this.#ctx = ctx;
385
+ this.app = new EchoApp(ctx, data.app);
386
+ this.apiUrl = data.apiUrl;
387
+ }
388
+ /** Create a person. Experimental. */
389
+ async createUser(options) {
390
+ const ctx = this.#ctx;
391
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/echo/users`, { body: { name: options.name } }));
392
+ return new EchoUser(ctx, data);
393
+ }
394
+ /** Create a room. Only the listed participants are members; include the app for it to receive events. Experimental. */
395
+ async createRoom(options = {}) {
396
+ const ctx = this.#ctx;
397
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/echo/rooms`, { body: { name: options.name, participants: options.participants === undefined ? undefined : options.participants.map((item) => item.id) } }));
398
+ return new EchoRoom(ctx, data);
399
+ }
400
+ /** Per action: works in the fake, works live, and what live needs. Experimental. */
401
+ async capabilities() {
402
+ const ctx = this.#ctx;
403
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/echo/capabilities`));
404
+ return data;
405
+ }
406
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
407
+ [QUIET]() {
408
+ return quietOf(this.#ctx);
409
+ }
410
+ }
411
+ export class EchoApp {
412
+ id;
413
+ name;
414
+ kind;
415
+ #ctx;
416
+ /** @internal Handles come from the SDK, never from `new`. */
417
+ constructor(ctx, data) {
418
+ this.#ctx = ctx;
419
+ this.id = data.id;
420
+ this.name = data.name;
421
+ this.kind = data.kind;
422
+ }
423
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
424
+ [QUIET]() {
425
+ return quietOf(this.#ctx);
426
+ }
427
+ }
428
+ export class EchoUser {
429
+ id;
430
+ name;
431
+ kind;
432
+ #ctx;
433
+ /** @internal Handles come from the SDK, never from `new`. */
434
+ constructor(ctx, data) {
435
+ this.#ctx = ctx;
436
+ this.id = data.id;
437
+ this.name = data.name;
438
+ this.kind = data.kind;
439
+ }
440
+ /** Post a message in a room as this person. Experimental. */
441
+ async say(text, options) {
442
+ const ctx = this.#ctx;
443
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/echo/users/${segment(this.id)}/say`, { body: { text, room: options.room.id } }));
444
+ return data;
445
+ }
446
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
447
+ [QUIET]() {
448
+ return quietOf(this.#ctx);
449
+ }
450
+ }
451
+ export class EchoRoom {
452
+ id;
453
+ name;
454
+ members;
455
+ #ctx;
456
+ /** @internal Handles come from the SDK, never from `new`. */
457
+ constructor(ctx, data) {
458
+ this.#ctx = ctx;
459
+ this.id = data.id;
460
+ this.name = data.name;
461
+ this.members = data.members;
462
+ }
463
+ /** The room's messages, oldest first, with a cursor for the next read. Experimental. */
464
+ async messages(options = {}) {
465
+ const ctx = this.#ctx;
466
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/echo/rooms/${segment(this.id)}/messages`, { query: { since: options.since } }));
467
+ return data;
468
+ }
469
+ /** The room as a person would read it. Experimental. */
470
+ async transcript() {
471
+ const ctx = this.#ctx;
472
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/echo/rooms/${segment(this.id)}/transcript`));
473
+ return data;
474
+ }
475
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
476
+ [QUIET]() {
477
+ return quietOf(this.#ctx);
478
+ }
479
+ }
480
+ export class SlackFixture {
481
+ app;
482
+ apiUrl;
483
+ team;
484
+ socketConnections;
485
+ #ctx;
486
+ #seen = new Map();
487
+ /** @internal Handles come from the SDK, never from `new`. */
488
+ constructor(ctx, data) {
489
+ this.#ctx = ctx;
490
+ this.app = new SlackApp(ctx, data.app);
491
+ this.apiUrl = data.apiUrl;
492
+ this.team = data.team;
493
+ this.socketConnections = data.socketConnections;
494
+ }
495
+ /** Create a person in the workspace. Experimental. */
496
+ async createUser(options) {
497
+ const ctx = this.#ctx;
498
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/users`, { body: { name: options.name, id: options.id, displayName: options.displayName, realName: options.realName, email: options.email, timezone: options.timezone, admin: options.admin, owner: options.owner, guest: options.guest, bot: options.bot, token: options.token ?? credential("CHANNELSTACK_SLACK_USER_{name}_TOKEN", { name: options.name }), browser: options.browser } }));
499
+ return new SlackUser(ctx, data);
500
+ }
501
+ /** The people this session created. Experimental. */
502
+ async users() {
503
+ const ctx = this.#ctx;
504
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/users`));
505
+ return decodeSlackUsers(ctx, data);
506
+ }
507
+ /** The session's conversations, the one with the newest message last. Experimental. */
508
+ async conversations() {
509
+ const ctx = this.#ctx;
510
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/conversations`));
511
+ return decodeSlackConversations(ctx, data);
512
+ }
513
+ /** Create a channel. Only the listed participants are members; include the app for it to receive events. Experimental. */
514
+ async createChannel(options = {}) {
515
+ const ctx = this.#ctx;
516
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/channels`, { body: { name: options.name, private: options.private, participants: options.participants === undefined ? undefined : options.participants.map((item) => item.id), topic: options.topic, purpose: options.purpose, shared: options.shared } }));
517
+ return new SlackConversation(ctx, data);
518
+ }
519
+ /** Every event channelstack sent the agent for this session, with every attempt. Experimental. */
520
+ async deliveries() {
521
+ const ctx = this.#ctx;
522
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/deliveries`));
523
+ return decodeSlackDeliveries(ctx, data);
524
+ }
525
+ /** The Web API calls the agent made about this session's conversations, people and files. Calls about nothing a session owns (auth.test, users.list) are in no session. Experimental. */
526
+ async calls(options = {}) {
527
+ const ctx = this.#ctx;
528
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/calls`, { query: { operation: options.operation, error: options.error } }));
529
+ return data;
530
+ }
531
+ /** The workspace uninstalls the app. Undone when this session closes; run such tests on their own. Experimental. */
532
+ async uninstallApp() {
533
+ const ctx = this.#ctx;
534
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/uninstall`));
535
+ return decodeSlackUninstallDeliveries(ctx, data);
536
+ }
537
+ /** Inject a fault: into the agent's Web API calls (removed when this session closes), or drop its Socket Mode connection once. Experimental. */
538
+ async fault(options) {
539
+ const ctx = this.#ctx;
540
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/faults`, { body: { type: options.type, operation: options.operation, retryAfter: options.retryAfter === undefined ? undefined : parseDuration(options.retryAfter), delay: options.delay === undefined ? undefined : parseDuration(options.delay), after: options.after === undefined ? undefined : parseDuration(options.after), error: options.error, times: options.times } }));
541
+ return new SlackFault(ctx, data);
542
+ }
543
+ /** Wait for the next new API call from the agent, after the last one this handle saw. */
544
+ async waitForCall(filter, options = {}) {
545
+ return waitForNext(this.#seen, `waitForCall:${JSON.stringify(filter)}`, () => this.calls(filter), () => true, "an API call from the agent", options);
546
+ }
547
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
548
+ [QUIET]() {
549
+ return quietOf(this.#ctx);
550
+ }
551
+ }
552
+ export class SlackApp {
553
+ id;
554
+ name;
555
+ kind;
556
+ botUserId;
557
+ botId;
558
+ botToken;
559
+ appToken;
560
+ signingSecret;
561
+ scopes;
562
+ #ctx;
563
+ /** @internal Handles come from the SDK, never from `new`. */
564
+ constructor(ctx, data) {
565
+ this.#ctx = ctx;
566
+ this.id = data.id;
567
+ this.name = data.name;
568
+ this.kind = data.kind;
569
+ this.botUserId = data.botUserId;
570
+ this.botId = data.botId;
571
+ this.botToken = data.botToken;
572
+ this.appToken = data.appToken;
573
+ this.signingSecret = data.signingSecret;
574
+ this.scopes = data.scopes;
575
+ }
576
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
577
+ [QUIET]() {
578
+ return quietOf(this.#ctx);
579
+ }
580
+ }
581
+ export class SlackUser {
582
+ id;
583
+ name;
584
+ kind;
585
+ displayName;
586
+ realName;
587
+ email;
588
+ isAdmin;
589
+ isBot;
590
+ #ctx;
591
+ #seen = new Map();
592
+ /** @internal Handles come from the SDK, never from `new`. */
593
+ constructor(ctx, data) {
594
+ this.#ctx = ctx;
595
+ this.id = data.id;
596
+ this.name = data.name;
597
+ this.kind = data.kind;
598
+ this.displayName = data.displayName;
599
+ this.realName = data.realName;
600
+ this.email = data.email;
601
+ this.isAdmin = data.isAdmin;
602
+ this.isBot = data.isBot;
603
+ }
604
+ /** Post a top-level message in a conversation, or in a DM with the people in `to`. Experimental. */
605
+ async say(message, options = {}) {
606
+ const ctx = this.#ctx;
607
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/users/${segment(this.id)}/say`, { body: { message: typeof message === "string" ? { text: message } : message, channel: options.channel === undefined ? undefined : options.channel.id, to: options.to === undefined ? undefined : [options.to].flat().map((item) => item.id), files: options.files === undefined ? undefined : readTree(options.files) } }));
608
+ return new SlackMessage(ctx, data);
609
+ }
610
+ /** Reply in a thread: pass the message that starts it, or any reply in it. Experimental. */
611
+ async reply(message, options) {
612
+ const ctx = this.#ctx;
613
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/users/${segment(this.id)}/reply`, { body: { message: typeof message === "string" ? { text: message } : message, thread: { channel: options.thread.channel, ts: options.thread.ts }, alsoSendToChannel: options.alsoSendToChannel, files: options.files === undefined ? undefined : readTree(options.files) } }));
614
+ return new SlackMessage(ctx, data);
615
+ }
616
+ /** Edit one of this person's own messages. Experimental. */
617
+ async edit(text, options) {
618
+ const ctx = this.#ctx;
619
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/users/${segment(this.id)}/edit`, { body: { text: typeof text === "string" ? { text: text } : text, message: { channel: options.message.channel, ts: options.message.ts } } }));
620
+ return new SlackMessage(ctx, data);
621
+ }
622
+ /** Delete a message: this person's own, or anyone's for an admin. Experimental. */
623
+ async delete(options) {
624
+ const ctx = this.#ctx;
625
+ await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/users/${segment(this.id)}/delete`, { body: { message: { channel: options.message.channel, ts: options.message.ts } } });
626
+ }
627
+ /** Click a button, found by its label or action_id: on a message, or on the app's latest message that has it in a thread or a conversation. Experimental. */
628
+ async click(button, options = {}) {
629
+ const ctx = this.#ctx;
630
+ const data = (await retryWhile(["not_found"], () => ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/users/${segment(this.id)}/click`, { body: { button: typeof button === "string" ? { label: button } : button, message: options.message === undefined ? undefined : { channel: options.message.channel, ts: options.message.ts }, thread: options.thread === undefined ? undefined : { channel: options.thread.channel, ts: options.thread.ts }, channel: options.channel === undefined ? undefined : options.channel.id } })));
631
+ return (data === null ? undefined : new SlackDelivery(ctx, data));
632
+ }
633
+ /** Choose from a select menu on a message: options by their text or value, the menu by its placeholder or action_id. Experimental. */
634
+ async select(option, options) {
635
+ const ctx = this.#ctx;
636
+ const data = (await retryWhile(["not_found"], () => ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/users/${segment(this.id)}/select`, { body: { option: [option].flat(), menu: typeof options.menu === "string" ? { label: options.menu } : options.menu, message: { channel: options.message.channel, ts: options.message.ts } } })));
637
+ return new SlackDelivery(ctx, data);
638
+ }
639
+ /** Run a message shortcut on a message. Experimental. */
640
+ async shortcut(callbackId, options) {
641
+ const ctx = this.#ctx;
642
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/users/${segment(this.id)}/shortcut`, { body: { callbackId, message: { channel: options.message.channel, ts: options.message.ts } } }));
643
+ return new SlackDelivery(ctx, data);
644
+ }
645
+ /** Run a slash command in a conversation, e.g. `/deploy web staging`. Experimental. */
646
+ async runCommand(command, options) {
647
+ const ctx = this.#ctx;
648
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/users/${segment(this.id)}/commands`, { body: { command, channel: options.channel.id } }));
649
+ return new SlackDelivery(ctx, data);
650
+ }
651
+ /** Press Stop on the app's work in a thread: what is streaming there ends, and the app is told. Experimental. */
652
+ async stop(options) {
653
+ const ctx = this.#ctx;
654
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/users/${segment(this.id)}/stop`, { body: { thread: { channel: options.thread.channel, ts: options.thread.ts } } }));
655
+ return new SlackDelivery(ctx, data);
656
+ }
657
+ /** Open the app's split view: a new thread in this person's DM with the app, started from the channel they are looking at. Experimental. */
658
+ async openAgentThread(options = {}) {
659
+ const ctx = this.#ctx;
660
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/users/${segment(this.id)}/agent-threads`, { body: { from: options.from === undefined ? undefined : options.from.id } }));
661
+ return new SlackThread(ctx, data);
662
+ }
663
+ /** Pick one of the prompts the app suggested in a thread: this person says its message there. Experimental. */
664
+ async pickPrompt(title, options) {
665
+ const ctx = this.#ctx;
666
+ const data = (await retryWhile(["not_found"], () => ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/users/${segment(this.id)}/pick-prompt`, { body: { title, thread: { channel: options.thread.channel, ts: options.thread.ts } } })));
667
+ return new SlackMessage(ctx, data);
668
+ }
669
+ /** Look at another channel while the split view stays open: the app is told the new context. Experimental. */
670
+ async switchContext(channel, options) {
671
+ const ctx = this.#ctx;
672
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/users/${segment(this.id)}/switch-context`, { body: { channel: channel.id, thread: { channel: options.thread.channel, ts: options.thread.ts } } }));
673
+ return new SlackDelivery(ctx, data);
674
+ }
675
+ /** The modals the app opened for this person, in the order it opened them; `open` says which are still up. Experimental. */
676
+ async modals() {
677
+ const ctx = this.#ctx;
678
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/users/${segment(this.id)}/modals`));
679
+ return decodeSlackModals(ctx, data);
680
+ }
681
+ /** Add an emoji reaction to a message. Experimental. */
682
+ async react(emoji, options) {
683
+ const ctx = this.#ctx;
684
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/users/${segment(this.id)}/react`, { body: { emoji, message: { channel: options.message.channel, ts: options.message.ts } } }));
685
+ return (data === null ? undefined : new SlackDelivery(ctx, data));
686
+ }
687
+ /** Remove this person's emoji reaction from a message. Experimental. */
688
+ async unreact(emoji, options) {
689
+ const ctx = this.#ctx;
690
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/users/${segment(this.id)}/unreact`, { body: { emoji, message: { channel: options.message.channel, ts: options.message.ts } } }));
691
+ return (data === null ? undefined : new SlackDelivery(ctx, data));
692
+ }
693
+ /** Open (or reuse) a DM with the app, another person, or several. Experimental. */
694
+ async openDM(participants) {
695
+ const ctx = this.#ctx;
696
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/users/${segment(this.id)}/open-dm`, { body: { participants: [participants].flat().map((item) => item.id) } }));
697
+ return new SlackConversation(ctx, data);
698
+ }
699
+ /** Invite people or the app to a channel. Experimental. */
700
+ async invite(participants, options) {
701
+ const ctx = this.#ctx;
702
+ await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/users/${segment(this.id)}/invite`, { body: { participants: [participants].flat().map((item) => item.id), channel: options.channel.id } });
703
+ }
704
+ /** Remove someone from a channel. Experimental. */
705
+ async kick(participant, options) {
706
+ const ctx = this.#ctx;
707
+ await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/users/${segment(this.id)}/kick`, { body: { participant: participant.id, channel: options.channel.id } });
708
+ }
709
+ /** Messages only this person can see. Experimental. */
710
+ async ephemeral() {
711
+ const ctx = this.#ctx;
712
+ await untilQuiet(() => quietOf(ctx));
713
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/users/${segment(this.id)}/ephemeral`));
714
+ return decodeSlackEphemeralMessages(ctx, data);
715
+ }
716
+ /** Wait for the next new open modal from the agent, after the last one this handle saw. */
717
+ async waitForModal(options = {}) {
718
+ return waitForNext(this.#seen, "waitForModal", () => this.modals(), (item) => textMatches(item.title, options.title) && item.open === true, "an open modal from the agent", options);
719
+ }
720
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
721
+ [QUIET]() {
722
+ return quietOf(this.#ctx);
723
+ }
724
+ }
725
+ export class SlackConversation {
726
+ id;
727
+ kind;
728
+ name;
729
+ #ctx;
730
+ #seen = new Map();
731
+ /** @internal Handles come from the SDK, never from `new`. */
732
+ constructor(ctx, data) {
733
+ this.#ctx = ctx;
734
+ this.id = data.id;
735
+ this.kind = data.kind;
736
+ this.name = data.name;
737
+ }
738
+ /** The newest message of a conversation, replies included. Experimental. */
739
+ async latestMessage() {
740
+ const ctx = this.#ctx;
741
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/conversations/${segment(this.id)}/latest`));
742
+ return new SlackMessage(ctx, data);
743
+ }
744
+ /** Top-level messages of a conversation, oldest first. Experimental. */
745
+ async messages() {
746
+ const ctx = this.#ctx;
747
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/conversations/${segment(this.id)}/messages`));
748
+ return decodeSlackMessages(ctx, data);
749
+ }
750
+ /** The people and apps in a conversation. Experimental. */
751
+ async members() {
752
+ const ctx = this.#ctx;
753
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/conversations/${segment(this.id)}/members`));
754
+ return decodeSlackMembers(ctx, data);
755
+ }
756
+ /** The conversation as a person would read it, threads included. Experimental. */
757
+ async transcript(options = {}) {
758
+ const ctx = this.#ctx;
759
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/conversations/${segment(this.id)}/transcript`, { query: { as: options.as === undefined ? undefined : options.as.id } }));
760
+ return decodeSlackTranscript(ctx, data);
761
+ }
762
+ /** Wait for the next new message matching `from` (anyone if omitted), after the last one this handle saw. */
763
+ async waitForMessage(options = {}) {
764
+ return waitForNext(this.#seen, "waitForMessage", () => this.messages(), (item) => fromMatches(item.author, options.from), describeWait("a message", options.from), options);
765
+ }
766
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
767
+ [QUIET]() {
768
+ return quietOf(this.#ctx);
769
+ }
770
+ }
771
+ export class SlackMessage {
772
+ channel;
773
+ ts;
774
+ conversation;
775
+ author;
776
+ text;
777
+ blocks;
778
+ postedAt;
779
+ threadTs;
780
+ edited;
781
+ visibleTo;
782
+ thread;
783
+ delivery;
784
+ stream;
785
+ #ctx;
786
+ /** @internal Handles come from the SDK, never from `new`. */
787
+ constructor(ctx, data) {
788
+ this.#ctx = ctx;
789
+ this.channel = data.channel;
790
+ this.ts = data.ts;
791
+ this.conversation = new SlackConversation(ctx, data.conversation);
792
+ this.author = data.author.kind === "user" ? new SlackUser(ctx, data.author) : new SlackApp(ctx, data.author);
793
+ this.text = data.text;
794
+ this.blocks = data.blocks;
795
+ this.postedAt = data.postedAt;
796
+ this.threadTs = data.threadTs;
797
+ this.edited = data.edited;
798
+ this.visibleTo = data.visibleTo === undefined ? undefined : new SlackUser(ctx, data.visibleTo);
799
+ this.thread = new SlackThread(ctx, data.thread);
800
+ this.delivery = data.delivery === undefined ? undefined : new SlackDelivery(ctx, data.delivery);
801
+ this.stream = data.stream === undefined ? undefined : new SlackStream(ctx, data.stream);
802
+ }
803
+ /** Re-read a message: its latest text, edits and deliveries. Experimental. */
804
+ async refresh() {
805
+ const ctx = this.#ctx;
806
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/conversations/${segment(this.channel)}/messages/${segment(this.ts)}`));
807
+ return new SlackMessage(ctx, data);
808
+ }
809
+ /** The reactions on a message, and who added each. Experimental. */
810
+ async reactions() {
811
+ const ctx = this.#ctx;
812
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/conversations/${segment(this.channel)}/messages/${segment(this.ts)}/reactions`));
813
+ return decodeSlackReactions(ctx, data);
814
+ }
815
+ /** A message and the replies under it as a person would read them. Experimental. */
816
+ async transcript(options = {}) {
817
+ const ctx = this.#ctx;
818
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/conversations/${segment(this.channel)}/messages/${segment(this.ts)}/transcript`, { query: { as: options.as === undefined ? undefined : options.as.id } }));
819
+ return decodeSlackTranscript(ctx, data);
820
+ }
821
+ /** Every delivery this message caused to the agent. Experimental. */
822
+ async deliveries() {
823
+ const ctx = this.#ctx;
824
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/conversations/${segment(this.channel)}/messages/${segment(this.ts)}/deliveries`));
825
+ return decodeSlackMessageDeliveries(ctx, data);
826
+ }
827
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
828
+ [QUIET]() {
829
+ return quietOf(this.#ctx);
830
+ }
831
+ }
832
+ export class SlackThread {
833
+ channel;
834
+ ts;
835
+ conversation;
836
+ #ctx;
837
+ #seen = new Map();
838
+ /** @internal Handles come from the SDK, never from `new`. */
839
+ constructor(ctx, data) {
840
+ this.#ctx = ctx;
841
+ this.channel = data.channel;
842
+ this.ts = data.ts;
843
+ this.conversation = new SlackConversation(ctx, data.conversation);
844
+ }
845
+ /** The prompts the app suggested in a thread. Experimental. */
846
+ async suggestedPrompts() {
847
+ const ctx = this.#ctx;
848
+ await untilQuiet(() => quietOf(ctx));
849
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/conversations/${segment(this.channel)}/threads/${segment(this.ts)}/suggested-prompts`));
850
+ return data;
851
+ }
852
+ /** The message that starts a thread, as it is now. Experimental. */
853
+ async root() {
854
+ const ctx = this.#ctx;
855
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/conversations/${segment(this.channel)}/threads/${segment(this.ts)}`));
856
+ return new SlackMessage(ctx, data);
857
+ }
858
+ /** Replies in a thread, oldest first, without the message that starts it. Experimental. */
859
+ async replies() {
860
+ const ctx = this.#ctx;
861
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/conversations/${segment(this.channel)}/threads/${segment(this.ts)}/replies`));
862
+ return decodeSlackReplies(ctx, data);
863
+ }
864
+ /** What the agent is doing in a thread: its status line, an open stream, or idle. Experimental. */
865
+ async status() {
866
+ const ctx = this.#ctx;
867
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/conversations/${segment(this.channel)}/threads/${segment(this.ts)}/state`));
868
+ return data;
869
+ }
870
+ /** A thread as a person would read it. Experimental. */
871
+ async transcript(options = {}) {
872
+ const ctx = this.#ctx;
873
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/conversations/${segment(this.channel)}/threads/${segment(this.ts)}/transcript`, { query: { as: options.as === undefined ? undefined : options.as.id } }));
874
+ return decodeSlackTranscript(ctx, data);
875
+ }
876
+ /** Wait for the next new reply matching `from` (anyone if omitted), after the last one this handle saw. */
877
+ async waitForReply(options = {}) {
878
+ return waitForNext(this.#seen, "waitForReply", () => this.replies(), (item) => fromMatches(item.author, options.from), describeWait("a reply", options.from), options);
879
+ }
880
+ /** The latest reply matching `from`, once the agent is quiet. Waits for at least one. */
881
+ async latestReply(options = {}) {
882
+ return latestOnceQuiet(() => this.replies(), (item) => fromMatches(item.author, options.from), () => quietOf(this.#ctx), describeWait("a reply", options.from), options);
883
+ }
884
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
885
+ [QUIET]() {
886
+ return quietOf(this.#ctx);
887
+ }
888
+ }
889
+ export class SlackDelivery {
890
+ id;
891
+ channel;
892
+ type;
893
+ eventType;
894
+ eventId;
895
+ payload;
896
+ attempts;
897
+ status;
898
+ #ctx;
899
+ /** @internal Handles come from the SDK, never from `new`. */
900
+ constructor(ctx, data) {
901
+ this.#ctx = ctx;
902
+ this.id = data.id;
903
+ this.channel = data.channel;
904
+ this.type = data.type;
905
+ this.eventType = data.eventType;
906
+ this.eventId = data.eventId;
907
+ this.payload = data.payload;
908
+ this.attempts = data.attempts;
909
+ this.status = data.status;
910
+ }
911
+ /** Re-read a delivery: its attempts and status. Experimental. */
912
+ async refresh() {
913
+ const ctx = this.#ctx;
914
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/deliveries/${segment(this.id)}`));
915
+ return new SlackDelivery(ctx, data);
916
+ }
917
+ /** Send the delivery again, unchanged or forged: a wrong signature, or a timestamp outside the replay window. Experimental. */
918
+ async resend(options = {}) {
919
+ const ctx = this.#ctx;
920
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/deliveries/${segment(this.id)}/resend`, { body: { badSignature: options.badSignature, stale: options.stale, headers: options.headers } }));
921
+ return data;
922
+ }
923
+ /** Retry the way Slack does: the same payload, with X-Slack-Retry-Num and X-Slack-Retry-Reason. Experimental. */
924
+ async retry(options = {}) {
925
+ const ctx = this.#ctx;
926
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/deliveries/${segment(this.id)}/retry`, { body: { after: options.after === undefined ? undefined : parseDuration(options.after), reason: options.reason } }));
927
+ return data;
928
+ }
929
+ /** Wait for the delivery to settle, and resolve with the value as it is then. */
930
+ async settled(options = {}) {
931
+ return waitFor("the delivery to settle", async () => {
932
+ const value = await this.refresh();
933
+ return value.status === "pending" ? undefined : value;
934
+ }, options);
935
+ }
936
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
937
+ [QUIET]() {
938
+ return quietOf(this.#ctx);
939
+ }
940
+ }
941
+ export class SlackStream {
942
+ channel;
943
+ ts;
944
+ state;
945
+ chunks;
946
+ startedAt;
947
+ endedAt;
948
+ #ctx;
949
+ /** @internal Handles come from the SDK, never from `new`. */
950
+ constructor(ctx, data) {
951
+ this.#ctx = ctx;
952
+ this.channel = data.channel;
953
+ this.ts = data.ts;
954
+ this.state = data.state;
955
+ this.chunks = data.chunks;
956
+ this.startedAt = data.startedAt;
957
+ this.endedAt = data.endedAt;
958
+ }
959
+ /** Re-read a streamed message's stream: its state and what was streamed so far. Experimental. */
960
+ async refresh() {
961
+ const ctx = this.#ctx;
962
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/conversations/${segment(this.channel)}/messages/${segment(this.ts)}/stream`));
963
+ return new SlackStream(ctx, data);
964
+ }
965
+ /** Wait for the stream to end, and resolve with the value as it is then. */
966
+ async ended(options = {}) {
967
+ return waitFor("the stream to end", async () => {
968
+ const value = await this.refresh();
969
+ return value.state === "open" ? undefined : value;
970
+ }, options);
971
+ }
972
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
973
+ [QUIET]() {
974
+ return quietOf(this.#ctx);
975
+ }
976
+ }
977
+ export class SlackModal {
978
+ viewId;
979
+ user;
980
+ title;
981
+ blocks;
982
+ open;
983
+ errors;
984
+ #ctx;
985
+ /** @internal Handles come from the SDK, never from `new`. */
986
+ constructor(ctx, data) {
987
+ this.#ctx = ctx;
988
+ this.viewId = data.viewId;
989
+ this.user = new SlackUser(ctx, data.user);
990
+ this.title = data.title;
991
+ this.blocks = data.blocks;
992
+ this.open = data.open;
993
+ this.errors = data.errors;
994
+ }
995
+ /** What is filled in: each input by its label (or action_id), with the text a person sees in it. Experimental. */
996
+ async values() {
997
+ const ctx = this.#ctx;
998
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/modals/${segment(this.viewId)}/values`));
999
+ return decodeSlackModalValues(ctx, data);
1000
+ }
1001
+ /** Fill in inputs, by label or `block_id.action_id`, and submit the modal. Experimental. */
1002
+ async submit(values) {
1003
+ const ctx = this.#ctx;
1004
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/modals/${segment(this.viewId)}/submit`, { body: { values } }));
1005
+ return new SlackDelivery(ctx, data);
1006
+ }
1007
+ /** Close the modal. The app is told only if it asked to be (`notify_on_close`). Experimental. */
1008
+ async close() {
1009
+ const ctx = this.#ctx;
1010
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/modals/${segment(this.viewId)}/close`));
1011
+ return (data === null ? undefined : new SlackDelivery(ctx, data));
1012
+ }
1013
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
1014
+ [QUIET]() {
1015
+ return quietOf(this.#ctx);
1016
+ }
1017
+ }
1018
+ export class SlackFault {
1019
+ id;
1020
+ #ctx;
1021
+ /** @internal Handles come from the SDK, never from `new`. */
1022
+ constructor(ctx, data) {
1023
+ this.#ctx = ctx;
1024
+ this.id = data.id;
1025
+ }
1026
+ /** Remove a fault. Experimental. */
1027
+ async undo() {
1028
+ const ctx = this.#ctx;
1029
+ await ctx.transport.request("DELETE", `/sessions/${segment(sessionOf(ctx))}/slack/faults/${segment(this.id)}`);
1030
+ }
1031
+ async [Symbol.asyncDispose]() {
1032
+ await disposeQuietly(() => this.undo());
1033
+ }
1034
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
1035
+ [QUIET]() {
1036
+ return quietOf(this.#ctx);
1037
+ }
1038
+ }
1039
+ export class GitHubFixture {
1040
+ app;
1041
+ apiUrl;
1042
+ org;
1043
+ #ctx;
1044
+ #seen = new Map();
1045
+ /** @internal Handles come from the SDK, never from `new`. */
1046
+ constructor(ctx, data) {
1047
+ this.#ctx = ctx;
1048
+ this.app = new GitHubApp(ctx, data.app);
1049
+ this.apiUrl = data.apiUrl;
1050
+ this.org = data.org;
1051
+ }
1052
+ /** Create a person in the org. Experimental. */
1053
+ async createUser(options) {
1054
+ const ctx = this.#ctx;
1055
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/users`, { body: { login: options.login, id: options.id, name: options.name, email: options.email, role: options.role, token: options.token ?? credential("CHANNELSTACK_GITHUB_USER_{login}_TOKEN", { login: options.login }) } }));
1056
+ return new GitHubUser(ctx, data);
1057
+ }
1058
+ /** Create a repository in the org. The App hears about it only when it is listed in `apps`: an App must be installed on a repository. Experimental. */
1059
+ async createRepo(options = {}) {
1060
+ const ctx = this.#ctx;
1061
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/repos`, { body: { name: options.name, private: options.private, defaultBranch: options.defaultBranch, files: options.files === undefined ? undefined : readTree(options.files), collaborators: options.collaborators === undefined ? undefined : options.collaborators.map((item) => (item instanceof GitHubUser ? { user: item.id } : { ...item, user: item.user.id })), apps: options.apps === undefined ? undefined : options.apps.map((item) => item.id), labels: options.labels === undefined ? undefined : options.labels.map((item) => (typeof item === "string" ? { name: item } : item)) } }));
1062
+ return new GitHubRepo(ctx, data);
1063
+ }
1064
+ /** Every webhook channelstack sent the agent for this session, with every attempt. Experimental. */
1065
+ async deliveries(options = {}) {
1066
+ const ctx = this.#ctx;
1067
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/deliveries`, { query: { type: options.type, resource: options.resource === undefined ? undefined : options.resource.id } }));
1068
+ return decodeGitHubDeliveries(ctx, data);
1069
+ }
1070
+ /** The REST calls the agent made about this session's repositories. Calls about no repository (`GET /app`) are in no session. Experimental. */
1071
+ async calls(options = {}) {
1072
+ const ctx = this.#ctx;
1073
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/calls`, { query: { operation: options.operation, error: options.error } }));
1074
+ return data;
1075
+ }
1076
+ /** The App's REST calls that are about no repository of any session: its own endpoints and the token exchange. They belong to no session, so every session reads the same list. Only calls that authenticated as the App or its installation are on it. Experimental. */
1077
+ async appCalls(options = {}) {
1078
+ const ctx = this.#ctx;
1079
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/app-calls`, { query: { operation: options.operation, error: options.error } }));
1080
+ return data;
1081
+ }
1082
+ /** Wait for the next new API call from the agent, after the last one this handle saw. */
1083
+ async waitForCall(filter, options = {}) {
1084
+ return waitForNext(this.#seen, `waitForCall:${JSON.stringify(filter)}`, () => this.calls(filter), () => true, "an API call from the agent", options);
1085
+ }
1086
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
1087
+ [QUIET]() {
1088
+ return quietOf(this.#ctx);
1089
+ }
1090
+ }
1091
+ export class GitHubApp {
1092
+ id;
1093
+ name;
1094
+ kind;
1095
+ slug;
1096
+ botLogin;
1097
+ botUserId;
1098
+ appId;
1099
+ privateKey;
1100
+ webhookSecret;
1101
+ #ctx;
1102
+ /** @internal Handles come from the SDK, never from `new`. */
1103
+ constructor(ctx, data) {
1104
+ this.#ctx = ctx;
1105
+ this.id = data.id;
1106
+ this.name = data.name;
1107
+ this.kind = data.kind;
1108
+ this.slug = data.slug;
1109
+ this.botLogin = data.botLogin;
1110
+ this.botUserId = data.botUserId;
1111
+ this.appId = data.appId;
1112
+ this.privateKey = data.privateKey;
1113
+ this.webhookSecret = data.webhookSecret;
1114
+ }
1115
+ /** The id of the App's installation, for a repository it is installed on. Experimental. */
1116
+ async installationId(repo) {
1117
+ const ctx = this.#ctx;
1118
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/installation-id`, { body: { repo: repo.id } }));
1119
+ return data;
1120
+ }
1121
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
1122
+ [QUIET]() {
1123
+ return quietOf(this.#ctx);
1124
+ }
1125
+ }
1126
+ export class GitHubUser {
1127
+ id;
1128
+ name;
1129
+ kind;
1130
+ login;
1131
+ numericId;
1132
+ displayName;
1133
+ email;
1134
+ role;
1135
+ #ctx;
1136
+ /** @internal Handles come from the SDK, never from `new`. */
1137
+ constructor(ctx, data) {
1138
+ this.#ctx = ctx;
1139
+ this.id = data.id;
1140
+ this.name = data.name;
1141
+ this.kind = data.kind;
1142
+ this.login = data.login;
1143
+ this.numericId = data.numericId;
1144
+ this.displayName = data.displayName;
1145
+ this.email = data.email;
1146
+ this.role = data.role;
1147
+ }
1148
+ /** Push a commit to a branch (created from the default branch if it isn't there). Sends `push`, and `pull_request` `synchronize` for open pull requests from it. Experimental. */
1149
+ async push(changes, options) {
1150
+ const ctx = this.#ctx;
1151
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/users/${segment(this.id)}/push`, { body: { changes: readChanges(changes), repo: options.repo.id, branch: options.branch, message: options.message } }));
1152
+ return new GitHubCommit(ctx, data);
1153
+ }
1154
+ /** Open an issue. Sends `issues` (action `opened`). Experimental. */
1155
+ async openIssue(issue, options) {
1156
+ const ctx = this.#ctx;
1157
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/users/${segment(this.id)}/issues`, { body: { issue: { ...issue, assignees: issue.assignees === undefined ? undefined : issue.assignees.map((item) => item.id) }, repo: options.repo.id } }));
1158
+ return new GitHubIssue(ctx, data);
1159
+ }
1160
+ /** Open a pull request. With `changes`, they are pushed to `from` first; without, `from` is an existing branch. Sends `pull_request` (action `opened`). Experimental. */
1161
+ async openPullRequest(pr, options) {
1162
+ const ctx = this.#ctx;
1163
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/users/${segment(this.id)}/pulls`, { body: { pr: { ...pr, changes: pr.changes === undefined ? undefined : readChanges(pr.changes), reviewers: pr.reviewers === undefined ? undefined : pr.reviewers.map((item) => item.id) }, repo: options.repo.id } }));
1164
+ return new GitHubPullRequest(ctx, data);
1165
+ }
1166
+ /** Edit the title or the body of an issue or a pull request. Sends `issues` or `pull_request` (action `edited`). Experimental. */
1167
+ async editIssue(changes, options) {
1168
+ const ctx = this.#ctx;
1169
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/users/${segment(this.id)}/edit-issue`, { body: { changes, issue: { repoId: options.issue.repoId, number: options.issue.number } } }));
1170
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1171
+ }
1172
+ /** Close an issue or a pull request. Sends `issues` or `pull_request` (action `closed`). Experimental. */
1173
+ async close(options) {
1174
+ const ctx = this.#ctx;
1175
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/users/${segment(this.id)}/close`, { body: { issue: { repoId: options.issue.repoId, number: options.issue.number } } }));
1176
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1177
+ }
1178
+ /** Reopen an issue or a pull request. Sends `issues` or `pull_request` (action `reopened`). Experimental. */
1179
+ async reopen(options) {
1180
+ const ctx = this.#ctx;
1181
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/users/${segment(this.id)}/reopen`, { body: { issue: { repoId: options.issue.repoId, number: options.issue.number } } }));
1182
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1183
+ }
1184
+ /** Put labels on an issue or a pull request. Sends one `labeled` event per label. Experimental. */
1185
+ async label(labels, options) {
1186
+ const ctx = this.#ctx;
1187
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/users/${segment(this.id)}/label`, { body: { labels: [labels].flat(), issue: { repoId: options.issue.repoId, number: options.issue.number } } }));
1188
+ return decodeGitHubLabelDeliveries(ctx, data);
1189
+ }
1190
+ /** Take labels off an issue or a pull request. Sends one `unlabeled` event per label. Experimental. */
1191
+ async unlabel(labels, options) {
1192
+ const ctx = this.#ctx;
1193
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/users/${segment(this.id)}/unlabel`, { body: { labels: [labels].flat(), issue: { repoId: options.issue.repoId, number: options.issue.number } } }));
1194
+ return decodeGitHubUnlabelDeliveries(ctx, data);
1195
+ }
1196
+ /** Assign people or the App's bot. Sends one `assigned` event per assignee. Experimental. */
1197
+ async assign(assignees, options) {
1198
+ const ctx = this.#ctx;
1199
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/users/${segment(this.id)}/assign`, { body: { assignees: [assignees].flat().map((item) => item.id), issue: { repoId: options.issue.repoId, number: options.issue.number } } }));
1200
+ return decodeGitHubAssignDeliveries(ctx, data);
1201
+ }
1202
+ /** Comment on an issue or a pull request's conversation. Sends `issue_comment` (action `created`). Experimental. */
1203
+ async comment(body, options) {
1204
+ const ctx = this.#ctx;
1205
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/users/${segment(this.id)}/comment`, { body: { body, issue: { repoId: options.issue.repoId, number: options.issue.number } } }));
1206
+ return new GitHubComment(ctx, data);
1207
+ }
1208
+ /** Edit a conversation comment or a comment on the diff. Sends the comment's event with action `edited`. Experimental. */
1209
+ async edit(body, options) {
1210
+ const ctx = this.#ctx;
1211
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/users/${segment(this.id)}/edit`, { body: { body, comment: options.comment.id } }));
1212
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1213
+ }
1214
+ /** Delete a conversation comment or a comment on the diff. Sends the comment's event with action `deleted`. Experimental. */
1215
+ async delete(options) {
1216
+ const ctx = this.#ctx;
1217
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/users/${segment(this.id)}/delete`, { body: { comment: options.comment.id } }));
1218
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1219
+ }
1220
+ /** React to an issue, a pull request or a comment. GitHub sends no webhook for a reaction. Experimental. */
1221
+ async react(content, options = {}) {
1222
+ const ctx = this.#ctx;
1223
+ await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/users/${segment(this.id)}/react`, { body: { content, issue: options.issue === undefined ? undefined : { repoId: options.issue.repoId, number: options.issue.number }, comment: options.comment === undefined ? undefined : options.comment.id } });
1224
+ }
1225
+ /** Hide a comment as outdated, spam, off-topic or resolved. GitHub sends no webhook for it. Experimental. */
1226
+ async minimize(options) {
1227
+ const ctx = this.#ctx;
1228
+ await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/users/${segment(this.id)}/minimize`, { body: { comment: options.comment.id, reason: options.reason } });
1229
+ }
1230
+ /** Submit a review, with comments on the diff if any. Sends `pull_request_review`, and one `pull_request_review_comment` per comment. Experimental. */
1231
+ async review(review) {
1232
+ const ctx = this.#ctx;
1233
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/users/${segment(this.id)}/review`, { body: { review: { ...review, pr: { repoId: review.pr.repoId, number: review.pr.number } } } }));
1234
+ return decodeGitHubReview(ctx, data);
1235
+ }
1236
+ /** One comment on the diff, outside a review. Sends `pull_request_review_comment`. Experimental. */
1237
+ async reviewComment(body, options) {
1238
+ const ctx = this.#ctx;
1239
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/users/${segment(this.id)}/review-comment`, { body: { body, pr: { repoId: options.pr.repoId, number: options.pr.number }, path: options.path, line: options.line, side: options.side } }));
1240
+ return new GitHubReviewComment(ctx, data);
1241
+ }
1242
+ /** Reply in a thread on the diff. Sends `pull_request_review_comment`. Experimental. */
1243
+ async reply(body, options) {
1244
+ const ctx = this.#ctx;
1245
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/users/${segment(this.id)}/reply`, { body: { body, comment: options.comment.id } }));
1246
+ return new GitHubReviewComment(ctx, data);
1247
+ }
1248
+ /** Resolve a thread on the diff. Sends `pull_request_review_thread`. Experimental. */
1249
+ async resolve(options) {
1250
+ const ctx = this.#ctx;
1251
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/users/${segment(this.id)}/resolve`, { body: { comment: options.comment.id } }));
1252
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1253
+ }
1254
+ /** Reopen a thread on the diff. Sends `pull_request_review_thread`. Experimental. */
1255
+ async unresolve(options) {
1256
+ const ctx = this.#ctx;
1257
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/users/${segment(this.id)}/unresolve`, { body: { comment: options.comment.id } }));
1258
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1259
+ }
1260
+ /** Request a review from people or the App's bot. Sends `pull_request` (action `review_requested`) per reviewer. Experimental. */
1261
+ async requestReview(reviewers, options) {
1262
+ const ctx = this.#ctx;
1263
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/users/${segment(this.id)}/request-review`, { body: { reviewers: [reviewers].flat().map((item) => item.id), pr: { repoId: options.pr.repoId, number: options.pr.number } } }));
1264
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1265
+ }
1266
+ /** Mark a draft pull request as ready for review. Sends `pull_request` (action `ready_for_review`). Experimental. */
1267
+ async markReady(options) {
1268
+ const ctx = this.#ctx;
1269
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/users/${segment(this.id)}/mark-ready`, { body: { pr: { repoId: options.pr.repoId, number: options.pr.number } } }));
1270
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1271
+ }
1272
+ /** Merge a pull request. Sends `push` for the base branch, then `pull_request` (action `closed`, merged). Experimental. */
1273
+ async merge(options) {
1274
+ const ctx = this.#ctx;
1275
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/users/${segment(this.id)}/merge`, { body: { pr: { repoId: options.pr.repoId, number: options.pr.number }, method: options.method } }));
1276
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1277
+ }
1278
+ /** Click "Re-run" on a check run. Sends `check_run` (action `rerequested`). Experimental. */
1279
+ async rerun(options) {
1280
+ const ctx = this.#ctx;
1281
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/users/${segment(this.id)}/rerun`, { body: { checkRun: options.checkRun.id } }));
1282
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1283
+ }
1284
+ /** Click one of the buttons the App put on a check run. Sends `check_run` (action `requested_action`). Experimental. */
1285
+ async requestAction(identifier, options) {
1286
+ const ctx = this.#ctx;
1287
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/users/${segment(this.id)}/request-action`, { body: { identifier, checkRun: options.checkRun.id } }));
1288
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1289
+ }
1290
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
1291
+ [QUIET]() {
1292
+ return quietOf(this.#ctx);
1293
+ }
1294
+ }
1295
+ export class GitHubRepo {
1296
+ id;
1297
+ owner;
1298
+ name;
1299
+ fullName;
1300
+ defaultBranch;
1301
+ private;
1302
+ #ctx;
1303
+ /** @internal Handles come from the SDK, never from `new`. */
1304
+ constructor(ctx, data) {
1305
+ this.#ctx = ctx;
1306
+ this.id = data.id;
1307
+ this.owner = data.owner;
1308
+ this.name = data.name;
1309
+ this.fullName = data.fullName;
1310
+ this.defaultBranch = data.defaultBranch;
1311
+ this.private = data.private;
1312
+ }
1313
+ /** Install the App on this repository. Sends `installation_repositories`. Experimental. */
1314
+ async installApp(app) {
1315
+ const ctx = this.#ctx;
1316
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.id)}/install`, { body: { app: app.id } }));
1317
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1318
+ }
1319
+ /** Take the App off this repository. Sends `installation_repositories`. Experimental. */
1320
+ async uninstallApp(app) {
1321
+ const ctx = this.#ctx;
1322
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.id)}/uninstall`, { body: { app: app.id } }));
1323
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1324
+ }
1325
+ /** An issue of this repository by its number. Experimental. */
1326
+ async issue(number) {
1327
+ const ctx = this.#ctx;
1328
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.id)}/issue`, { query: { number } }));
1329
+ return new GitHubIssue(ctx, data);
1330
+ }
1331
+ /** A pull request of this repository by its number. Experimental. */
1332
+ async pullRequest(number) {
1333
+ const ctx = this.#ctx;
1334
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.id)}/pull`, { query: { number } }));
1335
+ return new GitHubPullRequest(ctx, data);
1336
+ }
1337
+ /** A file's text as it is on a branch (the default branch without `ref`), or nothing when it isn't there. Experimental. */
1338
+ async readFile(path, options = {}) {
1339
+ const ctx = this.#ctx;
1340
+ await untilQuiet(() => quietOf(ctx));
1341
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.id)}/file`, { query: { path, ref: options.ref } }));
1342
+ return (data === null ? undefined : data);
1343
+ }
1344
+ /** The commits of a branch (the default branch without `branch`), newest first. Experimental. */
1345
+ async commits(options = {}) {
1346
+ const ctx = this.#ctx;
1347
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.id)}/commits`, { query: { branch: options.branch } }));
1348
+ return decodeGitHubCommits(ctx, data);
1349
+ }
1350
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
1351
+ [QUIET]() {
1352
+ return quietOf(this.#ctx);
1353
+ }
1354
+ }
1355
+ export class GitHubDelivery {
1356
+ id;
1357
+ channel;
1358
+ type;
1359
+ action;
1360
+ guid;
1361
+ payload;
1362
+ attempts;
1363
+ status;
1364
+ #ctx;
1365
+ /** @internal Handles come from the SDK, never from `new`. */
1366
+ constructor(ctx, data) {
1367
+ this.#ctx = ctx;
1368
+ this.id = data.id;
1369
+ this.channel = data.channel;
1370
+ this.type = data.type;
1371
+ this.action = data.action;
1372
+ this.guid = data.guid;
1373
+ this.payload = data.payload;
1374
+ this.attempts = data.attempts;
1375
+ this.status = data.status;
1376
+ }
1377
+ /** Re-read a delivery: its attempts and status. Experimental. */
1378
+ async refresh() {
1379
+ const ctx = this.#ctx;
1380
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/deliveries/${segment(this.id)}`));
1381
+ return new GitHubDelivery(ctx, data);
1382
+ }
1383
+ /** Redeliver from the App's delivery log, as GitHub's UI and API do: the same GUID, a new attempt. Experimental. */
1384
+ async redeliver() {
1385
+ const ctx = this.#ctx;
1386
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/deliveries/${segment(this.id)}/redeliver`));
1387
+ return data;
1388
+ }
1389
+ /** Send the delivery again, unchanged or signed with a secret that isn't the App's. Experimental. */
1390
+ async resend(options = {}) {
1391
+ const ctx = this.#ctx;
1392
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/deliveries/${segment(this.id)}/resend`, { body: { badSignature: options.badSignature } }));
1393
+ return data;
1394
+ }
1395
+ /** Wait for the delivery to settle, and resolve with the value as it is then. */
1396
+ async settled(options = {}) {
1397
+ return waitFor("the delivery to settle", async () => {
1398
+ const value = await this.refresh();
1399
+ return value.status === "pending" ? undefined : value;
1400
+ }, options);
1401
+ }
1402
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
1403
+ [QUIET]() {
1404
+ return quietOf(this.#ctx);
1405
+ }
1406
+ }
1407
+ export class GitHubIssue {
1408
+ repoId;
1409
+ number;
1410
+ repo;
1411
+ url;
1412
+ author;
1413
+ #ctx;
1414
+ #seen = new Map();
1415
+ /** @internal Handles come from the SDK, never from `new`. */
1416
+ constructor(ctx, data) {
1417
+ this.#ctx = ctx;
1418
+ this.repoId = data.repoId;
1419
+ this.number = data.number;
1420
+ this.repo = new GitHubRepo(ctx, data.repo);
1421
+ this.url = data.url;
1422
+ this.author = data.author.kind === "user" ? new GitHubUser(ctx, data.author) : new GitHubApp(ctx, data.author);
1423
+ }
1424
+ /** Read the issue again. Experimental. */
1425
+ async refresh() {
1426
+ const ctx = this.#ctx;
1427
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.repoId)}/issues/${segment(this.number)}`));
1428
+ return new GitHubIssue(ctx, data);
1429
+ }
1430
+ /** The issue's title as it is now. Experimental. */
1431
+ async title() {
1432
+ const ctx = this.#ctx;
1433
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.repoId)}/issues/${segment(this.number)}/title`));
1434
+ return data;
1435
+ }
1436
+ /** Open or closed, once the agent is quiet. Experimental. */
1437
+ async state() {
1438
+ const ctx = this.#ctx;
1439
+ await untilQuiet(() => quietOf(ctx));
1440
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.repoId)}/issues/${segment(this.number)}/state`));
1441
+ return data;
1442
+ }
1443
+ /** The names of the labels on it. Experimental. */
1444
+ async labels() {
1445
+ const ctx = this.#ctx;
1446
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.repoId)}/issues/${segment(this.number)}/labels`));
1447
+ return data;
1448
+ }
1449
+ /** Who it is assigned to. Experimental. */
1450
+ async assignees() {
1451
+ const ctx = this.#ctx;
1452
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.repoId)}/issues/${segment(this.number)}/assignees`));
1453
+ return data.map((item) => item.kind === "user" ? new GitHubUser(ctx, item) : new GitHubApp(ctx, item));
1454
+ }
1455
+ /** The comments of the conversation, oldest first. Experimental. */
1456
+ async comments() {
1457
+ const ctx = this.#ctx;
1458
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.repoId)}/issues/${segment(this.number)}/comments`));
1459
+ return decodeGitHubComments(ctx, data);
1460
+ }
1461
+ /** The issue or pull request as a person reads it: description, comments, reviews and threads. Experimental. */
1462
+ async transcript() {
1463
+ const ctx = this.#ctx;
1464
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.repoId)}/issues/${segment(this.number)}/transcript`));
1465
+ return decodeGitHubTranscript(ctx, data);
1466
+ }
1467
+ /** Wait for the next new comment matching `from` (anyone if omitted), after the last one this handle saw. */
1468
+ async waitForComment(options = {}) {
1469
+ return waitForNext(this.#seen, "waitForComment", () => this.comments(), (item) => fromMatches(item.author, options.from) && textMatches(item.body, options.body), describeWait("a comment", options.from), options);
1470
+ }
1471
+ /** The latest comment matching `from`, once the agent is quiet. Waits for at least one. */
1472
+ async latestComment(options = {}) {
1473
+ return latestOnceQuiet(() => this.comments(), (item) => fromMatches(item.author, options.from), () => quietOf(this.#ctx), describeWait("a comment", options.from), options);
1474
+ }
1475
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
1476
+ [QUIET]() {
1477
+ return quietOf(this.#ctx);
1478
+ }
1479
+ }
1480
+ export class GitHubCommit {
1481
+ repoId;
1482
+ sha;
1483
+ message;
1484
+ author;
1485
+ branch;
1486
+ committedAt;
1487
+ #ctx;
1488
+ /** @internal Handles come from the SDK, never from `new`. */
1489
+ constructor(ctx, data) {
1490
+ this.#ctx = ctx;
1491
+ this.repoId = data.repoId;
1492
+ this.sha = data.sha;
1493
+ this.message = data.message;
1494
+ this.author = data.author === undefined ? undefined : data.author.kind === "user" ? new GitHubUser(ctx, data.author) : new GitHubApp(ctx, data.author);
1495
+ this.branch = data.branch;
1496
+ this.committedAt = data.committedAt;
1497
+ }
1498
+ /** The check runs on this commit: the newest of each name. Experimental. */
1499
+ async checkRuns() {
1500
+ const ctx = this.#ctx;
1501
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.repoId)}/commits/${segment(this.sha)}/check-runs`));
1502
+ return decodeGitHubCheckRuns(ctx, data);
1503
+ }
1504
+ /** The commit statuses on this commit: the newest of each context. Experimental. */
1505
+ async statuses() {
1506
+ const ctx = this.#ctx;
1507
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.repoId)}/commits/${segment(this.sha)}/statuses`));
1508
+ return decodeGitHubStatuses(ctx, data);
1509
+ }
1510
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
1511
+ [QUIET]() {
1512
+ return quietOf(this.#ctx);
1513
+ }
1514
+ }
1515
+ export class GitHubCheckRun {
1516
+ id;
1517
+ name;
1518
+ app;
1519
+ headSha;
1520
+ status;
1521
+ conclusion;
1522
+ title;
1523
+ summary;
1524
+ annotations;
1525
+ actions;
1526
+ #ctx;
1527
+ /** @internal Handles come from the SDK, never from `new`. */
1528
+ constructor(ctx, data) {
1529
+ this.#ctx = ctx;
1530
+ this.id = data.id;
1531
+ this.name = data.name;
1532
+ this.app = data.app;
1533
+ this.headSha = data.headSha;
1534
+ this.status = data.status;
1535
+ this.conclusion = data.conclusion;
1536
+ this.title = data.title;
1537
+ this.summary = data.summary;
1538
+ this.annotations = data.annotations;
1539
+ this.actions = data.actions;
1540
+ }
1541
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
1542
+ [QUIET]() {
1543
+ return quietOf(this.#ctx);
1544
+ }
1545
+ }
1546
+ export class GitHubComment {
1547
+ id;
1548
+ url;
1549
+ issue;
1550
+ author;
1551
+ body;
1552
+ createdAt;
1553
+ delivery;
1554
+ #ctx;
1555
+ /** @internal Handles come from the SDK, never from `new`. */
1556
+ constructor(ctx, data) {
1557
+ this.#ctx = ctx;
1558
+ this.id = data.id;
1559
+ this.url = data.url;
1560
+ this.issue = new GitHubIssue(ctx, data.issue);
1561
+ this.author = data.author.kind === "user" ? new GitHubUser(ctx, data.author) : new GitHubApp(ctx, data.author);
1562
+ this.body = data.body;
1563
+ this.createdAt = data.createdAt;
1564
+ this.delivery = data.delivery === undefined ? undefined : new GitHubDelivery(ctx, data.delivery);
1565
+ }
1566
+ /** Read a conversation comment again. Experimental. */
1567
+ async refresh() {
1568
+ const ctx = this.#ctx;
1569
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/comments/${segment(this.id)}`));
1570
+ return new GitHubComment(ctx, data);
1571
+ }
1572
+ /** The reactions on a conversation comment, by content. Experimental. */
1573
+ async reactions() {
1574
+ const ctx = this.#ctx;
1575
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/comments/${segment(this.id)}/reactions`));
1576
+ return decodeGitHubReactions(ctx, data);
1577
+ }
1578
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
1579
+ [QUIET]() {
1580
+ return quietOf(this.#ctx);
1581
+ }
1582
+ }
1583
+ export class GitHubReviewComment {
1584
+ id;
1585
+ pr;
1586
+ author;
1587
+ path;
1588
+ line;
1589
+ side;
1590
+ body;
1591
+ delivery;
1592
+ #ctx;
1593
+ /** @internal Handles come from the SDK, never from `new`. */
1594
+ constructor(ctx, data) {
1595
+ this.#ctx = ctx;
1596
+ this.id = data.id;
1597
+ this.pr = new GitHubPullRequest(ctx, data.pr);
1598
+ this.author = data.author.kind === "user" ? new GitHubUser(ctx, data.author) : new GitHubApp(ctx, data.author);
1599
+ this.path = data.path;
1600
+ this.line = data.line;
1601
+ this.side = data.side;
1602
+ this.body = data.body;
1603
+ this.delivery = data.delivery === undefined ? undefined : new GitHubDelivery(ctx, data.delivery);
1604
+ }
1605
+ /** The replies in this comment's thread, once the agent is quiet. Experimental. */
1606
+ async replies() {
1607
+ const ctx = this.#ctx;
1608
+ await untilQuiet(() => quietOf(ctx));
1609
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/review-comments/${segment(this.id)}/replies`));
1610
+ return decodeGitHubReviewCommentReplies(ctx, data);
1611
+ }
1612
+ /** Is this comment's thread resolved?. Experimental. */
1613
+ async resolved() {
1614
+ const ctx = this.#ctx;
1615
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/review-comments/${segment(this.id)}/resolved`));
1616
+ return data;
1617
+ }
1618
+ /** This comment's thread as a person reads it. Experimental. */
1619
+ async transcript() {
1620
+ const ctx = this.#ctx;
1621
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/review-comments/${segment(this.id)}/transcript`));
1622
+ return decodeGitHubTranscript(ctx, data);
1623
+ }
1624
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
1625
+ [QUIET]() {
1626
+ return quietOf(this.#ctx);
1627
+ }
1628
+ }
1629
+ export class LinearFixture {
1630
+ app;
1631
+ apiUrl;
1632
+ #ctx;
1633
+ #seen = new Map();
1634
+ /** @internal Handles come from the SDK, never from `new`. */
1635
+ constructor(ctx, data) {
1636
+ this.#ctx = ctx;
1637
+ this.app = new LinearApp(ctx, data.app);
1638
+ this.apiUrl = data.apiUrl;
1639
+ }
1640
+ /** Create a person in the workspace. Experimental. */
1641
+ async createUser(options) {
1642
+ const ctx = this.#ctx;
1643
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/linear/users`, { body: { name: options.name, id: options.id, displayName: options.displayName, email: options.email, admin: options.admin, guest: options.guest, token: options.token ?? credential("CHANNELSTACK_LINEAR_USER_{name}_TOKEN", { name: options.name }) } }));
1644
+ return new LinearUser(ctx, data);
1645
+ }
1646
+ /** Create a team: its members, workflow states and labels. Without a key one is made up, so parallel tests never share one. Experimental. */
1647
+ async createTeam(options = {}) {
1648
+ const ctx = this.#ctx;
1649
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/linear/teams`, { body: { key: options.key, name: options.name, members: options.members === undefined ? undefined : options.members.map((item) => item.id), states: options.states, labels: options.labels } }));
1650
+ return new LinearTeam(ctx, data);
1651
+ }
1652
+ /** Every webhook channelstack sent the agent for this session, with every attempt. Experimental. */
1653
+ async deliveries(options = {}) {
1654
+ const ctx = this.#ctx;
1655
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/deliveries`, { query: { type: options.type, resource: options.resource === undefined ? undefined : options.resource.id } }));
1656
+ return decodeLinearDeliveries(ctx, data);
1657
+ }
1658
+ /** The GraphQL operations the agent sent about this session's issues and sessions, by root field (`agentActivityCreate`). Experimental. */
1659
+ async calls(options = {}) {
1660
+ const ctx = this.#ctx;
1661
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/calls`, { query: { operation: options.operation, error: options.error } }));
1662
+ return data;
1663
+ }
1664
+ /** Wait for the next new API call from the agent, after the last one this handle saw. */
1665
+ async waitForCall(filter, options = {}) {
1666
+ return waitForNext(this.#seen, `waitForCall:${JSON.stringify(filter)}`, () => this.calls(filter), () => true, "an API call from the agent", options);
1667
+ }
1668
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
1669
+ [QUIET]() {
1670
+ return quietOf(this.#ctx);
1671
+ }
1672
+ }
1673
+ export class LinearApp {
1674
+ id;
1675
+ name;
1676
+ kind;
1677
+ botUserId;
1678
+ accessToken;
1679
+ webhookSecret;
1680
+ clientId;
1681
+ clientSecret;
1682
+ #ctx;
1683
+ /** @internal Handles come from the SDK, never from `new`. */
1684
+ constructor(ctx, data) {
1685
+ this.#ctx = ctx;
1686
+ this.id = data.id;
1687
+ this.name = data.name;
1688
+ this.kind = data.kind;
1689
+ this.botUserId = data.botUserId;
1690
+ this.accessToken = data.accessToken;
1691
+ this.webhookSecret = data.webhookSecret;
1692
+ this.clientId = data.clientId;
1693
+ this.clientSecret = data.clientSecret;
1694
+ }
1695
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
1696
+ [QUIET]() {
1697
+ return quietOf(this.#ctx);
1698
+ }
1699
+ }
1700
+ export class LinearUser {
1701
+ id;
1702
+ name;
1703
+ kind;
1704
+ displayName;
1705
+ email;
1706
+ admin;
1707
+ guest;
1708
+ #ctx;
1709
+ /** @internal Handles come from the SDK, never from `new`. */
1710
+ constructor(ctx, data) {
1711
+ this.#ctx = ctx;
1712
+ this.id = data.id;
1713
+ this.name = data.name;
1714
+ this.kind = data.kind;
1715
+ this.displayName = data.displayName;
1716
+ this.email = data.email;
1717
+ this.admin = data.admin;
1718
+ this.guest = data.guest;
1719
+ }
1720
+ /** Create an issue. Sends `Issue` (`create`); with `delegate`, it opens an agent session and sends `AgentSessionEvent` (`created`). Experimental. */
1721
+ async createIssue(issue, options) {
1722
+ const ctx = this.#ctx;
1723
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/linear/users/${segment(this.id)}/issues`, { body: { issue: { ...issue, assignee: issue.assignee === undefined ? undefined : issue.assignee.id, delegate: issue.delegate === undefined ? undefined : issue.delegate.id, parent: issue.parent === undefined ? undefined : issue.parent.id }, team: options.team.id } }));
1724
+ return new LinearIssue(ctx, data);
1725
+ }
1726
+ /** Edit an issue's title, description or priority. Sends `Issue` (`update`). Experimental. */
1727
+ async editIssue(changes, options) {
1728
+ const ctx = this.#ctx;
1729
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/linear/users/${segment(this.id)}/edit-issue`, { body: { changes, issue: options.issue.id } }));
1730
+ return (data === null ? undefined : new LinearDelivery(ctx, data));
1731
+ }
1732
+ /** Take an issue back from the app. Sends `Issue` (`update`). Experimental. */
1733
+ async undelegate(options) {
1734
+ const ctx = this.#ctx;
1735
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/linear/users/${segment(this.id)}/undelegate`, { body: { issue: options.issue.id } }));
1736
+ return (data === null ? undefined : new LinearDelivery(ctx, data));
1737
+ }
1738
+ /** Assign an issue to a person, or (with no one) unassign it. Sends `Issue` (`update`). Experimental. */
1739
+ async assign(assignee, options) {
1740
+ const ctx = this.#ctx;
1741
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/linear/users/${segment(this.id)}/assign`, { body: { assignee: assignee === undefined ? undefined : assignee.id, issue: options.issue.id } }));
1742
+ return (data === null ? undefined : new LinearDelivery(ctx, data));
1743
+ }
1744
+ /** Move an issue to a workflow state, by name. Sends `Issue` (`update`). Experimental. */
1745
+ async setState(state, options) {
1746
+ const ctx = this.#ctx;
1747
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/linear/users/${segment(this.id)}/set-state`, { body: { state, issue: options.issue.id } }));
1748
+ return (data === null ? undefined : new LinearDelivery(ctx, data));
1749
+ }
1750
+ /** Put labels on an issue, by name. Sends `Issue` (`update`). Experimental. */
1751
+ async label(labels, options) {
1752
+ const ctx = this.#ctx;
1753
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/linear/users/${segment(this.id)}/label`, { body: { labels: [labels].flat(), issue: options.issue.id } }));
1754
+ return (data === null ? undefined : new LinearDelivery(ctx, data));
1755
+ }
1756
+ /** Delegate an issue to the app. Opens an agent session and sends `AgentSessionEvent` (`created`). Experimental. */
1757
+ async delegate(app, options) {
1758
+ const ctx = this.#ctx;
1759
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/linear/users/${segment(this.id)}/delegate`, { body: { app: app.id, issue: options.issue.id } }));
1760
+ return new LinearAgentSession(ctx, data);
1761
+ }
1762
+ /** Comment on an issue. A mention of the app opens an agent session and sends `AgentSessionEvent` (`created`). Experimental. */
1763
+ async comment(body, options) {
1764
+ const ctx = this.#ctx;
1765
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/linear/users/${segment(this.id)}/comment`, { body: { body, issue: options.issue.id } }));
1766
+ return new LinearComment(ctx, data);
1767
+ }
1768
+ /** Reply in a comment's thread. In an agent session's thread, it prompts the session (`AgentSessionEvent` `prompted`). Experimental. */
1769
+ async reply(body, options) {
1770
+ const ctx = this.#ctx;
1771
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/linear/users/${segment(this.id)}/reply`, { body: { body, comment: options.comment.id } }));
1772
+ return new LinearComment(ctx, data);
1773
+ }
1774
+ /** Edit a comment. Sends `Comment` (`update`). Experimental. */
1775
+ async edit(body, options) {
1776
+ const ctx = this.#ctx;
1777
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/linear/users/${segment(this.id)}/edit`, { body: { body, comment: options.comment.id } }));
1778
+ return (data === null ? undefined : new LinearDelivery(ctx, data));
1779
+ }
1780
+ /** Delete a comment. Sends `Comment` (`remove`). Experimental. */
1781
+ async delete(options) {
1782
+ const ctx = this.#ctx;
1783
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/linear/users/${segment(this.id)}/delete`, { body: { comment: options.comment.id } }));
1784
+ return (data === null ? undefined : new LinearDelivery(ctx, data));
1785
+ }
1786
+ /** React to a comment with an emoji. Linear sends no webhook for it. Experimental. */
1787
+ async react(emoji, options) {
1788
+ const ctx = this.#ctx;
1789
+ await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/linear/users/${segment(this.id)}/react`, { body: { emoji, comment: options.comment.id } });
1790
+ }
1791
+ /** Send a follow-up in an agent session. Sends `AgentSessionEvent` (`prompted`). Experimental. */
1792
+ async prompt(body, options) {
1793
+ const ctx = this.#ctx;
1794
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/linear/users/${segment(this.id)}/prompt`, { body: { body, session: options.session.id } }));
1795
+ return (data === null ? undefined : new LinearDelivery(ctx, data));
1796
+ }
1797
+ /** Answer a question the agent asked (an `elicitation` activity). Sends `AgentSessionEvent` (`prompted`). Experimental. */
1798
+ async answer(body, options) {
1799
+ const ctx = this.#ctx;
1800
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/linear/users/${segment(this.id)}/answer`, { body: { body, elicitation: options.elicitation.id } }));
1801
+ return (data === null ? undefined : new LinearDelivery(ctx, data));
1802
+ }
1803
+ /** Press Stop on an agent session. Sends `AgentSessionEvent` (`prompted`) with the `stop` signal. Experimental. */
1804
+ async stop(options) {
1805
+ const ctx = this.#ctx;
1806
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/linear/users/${segment(this.id)}/stop`, { body: { session: options.session.id } }));
1807
+ return new LinearDelivery(ctx, data);
1808
+ }
1809
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
1810
+ [QUIET]() {
1811
+ return quietOf(this.#ctx);
1812
+ }
1813
+ }
1814
+ export class LinearTeam {
1815
+ id;
1816
+ key;
1817
+ name;
1818
+ #ctx;
1819
+ /** @internal Handles come from the SDK, never from `new`. */
1820
+ constructor(ctx, data) {
1821
+ this.#ctx = ctx;
1822
+ this.id = data.id;
1823
+ this.key = data.key;
1824
+ this.name = data.name;
1825
+ }
1826
+ /** An issue of this team by its identifier (`ENG-12`). Experimental. */
1827
+ async issue(identifier) {
1828
+ const ctx = this.#ctx;
1829
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/teams/${segment(this.id)}/issue`, { query: { identifier } }));
1830
+ return new LinearIssue(ctx, data);
1831
+ }
1832
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
1833
+ [QUIET]() {
1834
+ return quietOf(this.#ctx);
1835
+ }
1836
+ }
1837
+ export class LinearIssue {
1838
+ id;
1839
+ identifier;
1840
+ url;
1841
+ team;
1842
+ creator;
1843
+ #ctx;
1844
+ #seen = new Map();
1845
+ /** @internal Handles come from the SDK, never from `new`. */
1846
+ constructor(ctx, data) {
1847
+ this.#ctx = ctx;
1848
+ this.id = data.id;
1849
+ this.identifier = data.identifier;
1850
+ this.url = data.url;
1851
+ this.team = new LinearTeam(ctx, data.team);
1852
+ this.creator = data.creator.kind === "user" ? new LinearUser(ctx, data.creator) : new LinearApp(ctx, data.creator);
1853
+ }
1854
+ /** Read the issue again. Experimental. */
1855
+ async refresh() {
1856
+ const ctx = this.#ctx;
1857
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/issues/${segment(this.id)}`));
1858
+ return new LinearIssue(ctx, data);
1859
+ }
1860
+ /** The issue's title as it is now. Experimental. */
1861
+ async title() {
1862
+ const ctx = this.#ctx;
1863
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/issues/${segment(this.id)}/title`));
1864
+ return data;
1865
+ }
1866
+ /** The issue's workflow state. Experimental. */
1867
+ async state() {
1868
+ const ctx = this.#ctx;
1869
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/issues/${segment(this.id)}/state`));
1870
+ return data;
1871
+ }
1872
+ /** Who the issue is assigned to, if anyone. Experimental. */
1873
+ async assignee() {
1874
+ const ctx = this.#ctx;
1875
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/issues/${segment(this.id)}/assignee`));
1876
+ return (data === null ? undefined : new LinearUser(ctx, data));
1877
+ }
1878
+ /** The app the issue is delegated to, if any. Experimental. */
1879
+ async delegatedTo() {
1880
+ const ctx = this.#ctx;
1881
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/issues/${segment(this.id)}/delegate`));
1882
+ return (data === null ? undefined : new LinearApp(ctx, data));
1883
+ }
1884
+ /** The names of the labels on the issue. Experimental. */
1885
+ async labels() {
1886
+ const ctx = this.#ctx;
1887
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/issues/${segment(this.id)}/labels`));
1888
+ return data;
1889
+ }
1890
+ /** The comments on the issue, oldest first, without the one Linear writes to open a delegated session's thread. Experimental. */
1891
+ async comments() {
1892
+ const ctx = this.#ctx;
1893
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/issues/${segment(this.id)}/comments`));
1894
+ return decodeLinearComments(ctx, data);
1895
+ }
1896
+ /** The agent sessions on the issue, oldest first. Experimental. */
1897
+ async sessions() {
1898
+ const ctx = this.#ctx;
1899
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/issues/${segment(this.id)}/sessions`));
1900
+ return decodeLinearAgentSessions(ctx, data);
1901
+ }
1902
+ /** The issue's latest agent session, waiting for one to be opened. Experimental. */
1903
+ async session() {
1904
+ const ctx = this.#ctx;
1905
+ const data = (await retryWhile(["not_found"], () => ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/issues/${segment(this.id)}/session`)));
1906
+ return new LinearAgentSession(ctx, data);
1907
+ }
1908
+ /** The issue as a person reads it: description, comments and the agent's sessions. Experimental. */
1909
+ async transcript() {
1910
+ const ctx = this.#ctx;
1911
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/issues/${segment(this.id)}/transcript`));
1912
+ return decodeLinearTranscript(ctx, data);
1913
+ }
1914
+ /** Wait for the next new comment matching `from` (anyone if omitted), after the last one this handle saw. */
1915
+ async waitForComment(options = {}) {
1916
+ return waitForNext(this.#seen, "waitForComment", () => this.comments(), (item) => fromMatches(item.author, options.from) && textMatches(item.body, options.body), describeWait("a comment", options.from), options);
1917
+ }
1918
+ /** The latest comment matching `from`, once the agent is quiet. Waits for at least one. */
1919
+ async latestComment(options = {}) {
1920
+ return latestOnceQuiet(() => this.comments(), (item) => fromMatches(item.author, options.from), () => quietOf(this.#ctx), describeWait("a comment", options.from), options);
1921
+ }
1922
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
1923
+ [QUIET]() {
1924
+ return quietOf(this.#ctx);
1925
+ }
1926
+ }
1927
+ export class LinearDelivery {
1928
+ id;
1929
+ channel;
1930
+ type;
1931
+ action;
1932
+ webhookId;
1933
+ payload;
1934
+ attempts;
1935
+ status;
1936
+ #ctx;
1937
+ /** @internal Handles come from the SDK, never from `new`. */
1938
+ constructor(ctx, data) {
1939
+ this.#ctx = ctx;
1940
+ this.id = data.id;
1941
+ this.channel = data.channel;
1942
+ this.type = data.type;
1943
+ this.action = data.action;
1944
+ this.webhookId = data.webhookId;
1945
+ this.payload = data.payload;
1946
+ this.attempts = data.attempts;
1947
+ this.status = data.status;
1948
+ }
1949
+ /** Re-read a delivery: its attempts and status. Experimental. */
1950
+ async refresh() {
1951
+ const ctx = this.#ctx;
1952
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/deliveries/${segment(this.id)}`));
1953
+ return new LinearDelivery(ctx, data);
1954
+ }
1955
+ /** Redeliver, as Linear retries: the same delivery, with a new `webhookTimestamp` and a new signature. Experimental. */
1956
+ async redeliver() {
1957
+ const ctx = this.#ctx;
1958
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/linear/deliveries/${segment(this.id)}/redeliver`));
1959
+ return data;
1960
+ }
1961
+ /** Send the delivery again: stale (its `webhookTimestamp` two minutes old), or signed with a secret that isn't the app's. Experimental. */
1962
+ async resend(options = {}) {
1963
+ const ctx = this.#ctx;
1964
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/linear/deliveries/${segment(this.id)}/resend`, { body: { badSignature: options.badSignature, stale: options.stale } }));
1965
+ return data;
1966
+ }
1967
+ /** Wait for the delivery to settle, and resolve with the value as it is then. */
1968
+ async settled(options = {}) {
1969
+ return waitFor("the delivery to settle", async () => {
1970
+ const value = await this.refresh();
1971
+ return value.status === "pending" ? undefined : value;
1972
+ }, options);
1973
+ }
1974
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
1975
+ [QUIET]() {
1976
+ return quietOf(this.#ctx);
1977
+ }
1978
+ }
1979
+ export class LinearAgentSession {
1980
+ id;
1981
+ issue;
1982
+ app;
1983
+ startedBy;
1984
+ delivery;
1985
+ #ctx;
1986
+ #seen = new Map();
1987
+ /** @internal Handles come from the SDK, never from `new`. */
1988
+ constructor(ctx, data) {
1989
+ this.#ctx = ctx;
1990
+ this.id = data.id;
1991
+ this.issue = new LinearIssue(ctx, data.issue);
1992
+ this.app = new LinearApp(ctx, data.app);
1993
+ this.startedBy = new LinearUser(ctx, data.startedBy);
1994
+ this.delivery = data.delivery === undefined ? undefined : new LinearDelivery(ctx, data.delivery);
1995
+ }
1996
+ /** The session's status. Experimental. */
1997
+ async state() {
1998
+ const ctx = this.#ctx;
1999
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/agent-sessions/${segment(this.id)}/state`));
2000
+ return data;
2001
+ }
2002
+ /** The session's activities, oldest first: the agent's, and the prompts of people. Experimental. */
2003
+ async activities() {
2004
+ const ctx = this.#ctx;
2005
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/agent-sessions/${segment(this.id)}/activities`));
2006
+ return decodeLinearAgentActivities(ctx, data);
2007
+ }
2008
+ /** The links the agent attached to the session. Experimental. */
2009
+ async externalUrls() {
2010
+ const ctx = this.#ctx;
2011
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/agent-sessions/${segment(this.id)}/external-urls`));
2012
+ return data;
2013
+ }
2014
+ /** The agent's plan: each step and its status. Experimental. */
2015
+ async plan() {
2016
+ const ctx = this.#ctx;
2017
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/agent-sessions/${segment(this.id)}/plan`));
2018
+ return data;
2019
+ }
2020
+ /** The session as a person reads it. Experimental. */
2021
+ async transcript() {
2022
+ const ctx = this.#ctx;
2023
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/agent-sessions/${segment(this.id)}/transcript`));
2024
+ return decodeLinearTranscript(ctx, data);
2025
+ }
2026
+ /** Wait for the agent session to reach that state: one of the values given. Resolves with the value as it is then. */
2027
+ async waitForState(wanted, options = {}) {
2028
+ const values = [wanted].flat();
2029
+ return waitFor("the agent session to reach that state", async () => {
2030
+ const value = await this.state();
2031
+ return values.includes(value) ? value : undefined;
2032
+ }, options);
2033
+ }
2034
+ /** Wait for the next new activity, after the last one this handle saw. */
2035
+ async waitForActivity(options = {}) {
2036
+ return waitForNext(this.#seen, "waitForActivity", () => this.activities(), (item) => textMatches(item.type, options.type), "an activity", options, (item) => item.type === "prompt");
2037
+ }
2038
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2039
+ [QUIET]() {
2040
+ return quietOf(this.#ctx);
2041
+ }
2042
+ }
2043
+ export class LinearComment {
2044
+ id;
2045
+ issue;
2046
+ author;
2047
+ body;
2048
+ createdAt;
2049
+ url;
2050
+ session;
2051
+ delivery;
2052
+ #ctx;
2053
+ /** @internal Handles come from the SDK, never from `new`. */
2054
+ constructor(ctx, data) {
2055
+ this.#ctx = ctx;
2056
+ this.id = data.id;
2057
+ this.issue = new LinearIssue(ctx, data.issue);
2058
+ this.author = data.author.kind === "user" ? new LinearUser(ctx, data.author) : new LinearApp(ctx, data.author);
2059
+ this.body = data.body;
2060
+ this.createdAt = data.createdAt;
2061
+ this.url = data.url;
2062
+ this.session = data.session === undefined ? undefined : new LinearAgentSession(ctx, data.session);
2063
+ this.delivery = data.delivery === undefined ? undefined : new LinearDelivery(ctx, data.delivery);
2064
+ }
2065
+ /** The replies in a comment's thread, once the agent is quiet. Experimental. */
2066
+ async replies() {
2067
+ const ctx = this.#ctx;
2068
+ await untilQuiet(() => quietOf(ctx));
2069
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/comments/${segment(this.id)}/replies`));
2070
+ return decodeLinearCommentReplies(ctx, data);
2071
+ }
2072
+ /** A comment's thread as a person reads it. Experimental. */
2073
+ async transcript() {
2074
+ const ctx = this.#ctx;
2075
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/comments/${segment(this.id)}/transcript`));
2076
+ return decodeLinearTranscript(ctx, data);
2077
+ }
2078
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2079
+ [QUIET]() {
2080
+ return quietOf(this.#ctx);
2081
+ }
2082
+ }
2083
+ export class LinearAgentActivity {
2084
+ id;
2085
+ session;
2086
+ type;
2087
+ author;
2088
+ body;
2089
+ action;
2090
+ ephemeral;
2091
+ createdAt;
2092
+ #ctx;
2093
+ /** @internal Handles come from the SDK, never from `new`. */
2094
+ constructor(ctx, data) {
2095
+ this.#ctx = ctx;
2096
+ this.id = data.id;
2097
+ this.session = new LinearAgentSession(ctx, data.session);
2098
+ this.type = data.type;
2099
+ this.author = data.author.kind === "user" ? new LinearUser(ctx, data.author) : new LinearApp(ctx, data.author);
2100
+ this.body = data.body;
2101
+ this.action = data.action;
2102
+ this.ephemeral = data.ephemeral;
2103
+ this.createdAt = data.createdAt;
2104
+ }
2105
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2106
+ [QUIET]() {
2107
+ return quietOf(this.#ctx);
2108
+ }
2109
+ }
2110
+ export class NotionFixture {
2111
+ app;
2112
+ apiUrl;
2113
+ #ctx;
2114
+ #seen = new Map();
2115
+ /** @internal Handles come from the SDK, never from `new`. */
2116
+ constructor(ctx, data) {
2117
+ this.#ctx = ctx;
2118
+ this.app = new NotionIntegration(ctx, data.app);
2119
+ this.apiUrl = data.apiUrl;
2120
+ }
2121
+ /** Create a person in the workspace. Experimental. */
2122
+ async createUser(options) {
2123
+ const ctx = this.#ctx;
2124
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/users`, { body: { name: options.name, id: options.id, email: options.email, avatarUrl: options.avatarUrl, token: options.token ?? credential("CHANNELSTACK_NOTION_USER_{name}_TOKEN", { name: options.name }) } }));
2125
+ return new NotionUser(ctx, data);
2126
+ }
2127
+ /** Create a page as seed data. The integration sees it only through `connections`, its own or a parent's. In the fake it sends no event; live, a real person makes it, so Notion sends `page.created` to a connected integration. A person creating the page sends the event in both worlds. Experimental. */
2128
+ async createPage(options) {
2129
+ const ctx = this.#ctx;
2130
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/pages`, { body: { title: options.title, parent: options.parent === undefined ? undefined : options.parent.id, content: options.content === undefined ? undefined : readDocument(options.content), icon: options.icon, connections: options.connections === undefined ? undefined : options.connections.map((item) => item.id), createdBy: options.createdBy === undefined ? undefined : options.createdBy.id } }));
2131
+ return new NotionPage(ctx, data);
2132
+ }
2133
+ /** Create a database with its property schema and rows, as seed data. Experimental. */
2134
+ async createDatabase(options) {
2135
+ const ctx = this.#ctx;
2136
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/databases`, { body: { title: options.title, parent: options.parent === undefined ? undefined : options.parent.id, properties: options.properties, rows: options.rows, connections: options.connections === undefined ? undefined : options.connections.map((item) => item.id) } }));
2137
+ return new NotionDatabase(ctx, data);
2138
+ }
2139
+ /** How long Notion holds `page.content_updated` to batch edits, for this session (fake only). Default one second. Experimental. */
2140
+ async setContentUpdateDelay(delay) {
2141
+ const ctx = this.#ctx;
2142
+ await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/content-delay`, { body: { delay: parseDuration(delay) } });
2143
+ }
2144
+ /** Send the subscription's verification request (`{ verification_token }`), as Notion does once when a subscription is created. Experimental. */
2145
+ async sendVerification() {
2146
+ const ctx = this.#ctx;
2147
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/verification`));
2148
+ return (data === null ? undefined : new NotionDelivery(ctx, data));
2149
+ }
2150
+ /** Every webhook channelstack sent the agent for this session, with every attempt. Experimental. */
2151
+ async deliveries(options = {}) {
2152
+ const ctx = this.#ctx;
2153
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/notion/deliveries`, { query: { type: options.type, resource: options.resource === undefined ? undefined : options.resource.id } }));
2154
+ return decodeNotionDeliveries(ctx, data);
2155
+ }
2156
+ /** The REST calls the agent made about this session's pages, by the client's method name (`comments.create`). Experimental. */
2157
+ async calls(options = {}) {
2158
+ const ctx = this.#ctx;
2159
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/notion/calls`, { query: { operation: options.operation, error: options.error } }));
2160
+ return data;
2161
+ }
2162
+ /** Wait for the next new API call from the agent, after the last one this handle saw. */
2163
+ async waitForCall(filter, options = {}) {
2164
+ return waitForNext(this.#seen, `waitForCall:${JSON.stringify(filter)}`, () => this.calls(filter), () => true, "an API call from the agent", options);
2165
+ }
2166
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2167
+ [QUIET]() {
2168
+ return quietOf(this.#ctx);
2169
+ }
2170
+ }
2171
+ export class NotionIntegration {
2172
+ id;
2173
+ name;
2174
+ kind;
2175
+ channel;
2176
+ botUserId;
2177
+ token;
2178
+ webhookSecret;
2179
+ #ctx;
2180
+ /** @internal Handles come from the SDK, never from `new`. */
2181
+ constructor(ctx, data) {
2182
+ this.#ctx = ctx;
2183
+ this.id = data.id;
2184
+ this.name = data.name;
2185
+ this.kind = data.kind;
2186
+ this.channel = data.channel;
2187
+ this.botUserId = data.botUserId;
2188
+ this.token = data.token;
2189
+ this.webhookSecret = data.webhookSecret;
2190
+ }
2191
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2192
+ [QUIET]() {
2193
+ return quietOf(this.#ctx);
2194
+ }
2195
+ }
2196
+ export class NotionUser {
2197
+ id;
2198
+ name;
2199
+ kind;
2200
+ channel;
2201
+ email;
2202
+ #ctx;
2203
+ /** @internal Handles come from the SDK, never from `new`. */
2204
+ constructor(ctx, data) {
2205
+ this.#ctx = ctx;
2206
+ this.id = data.id;
2207
+ this.name = data.name;
2208
+ this.kind = data.kind;
2209
+ this.channel = data.channel;
2210
+ this.email = data.email;
2211
+ }
2212
+ /** Start a discussion on a page, or anchored to the block with `anchor` in its text. Sends `comment.created` if the integration can see the page. Experimental. */
2213
+ async comment(text, options) {
2214
+ const ctx = this.#ctx;
2215
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/users/${segment(this.id)}/comment`, { body: { text, page: options.page.id, anchor: options.anchor === undefined ? undefined : patternOnWire(options.anchor) } }));
2216
+ return new NotionComment(ctx, data);
2217
+ }
2218
+ /** Reply in a discussion. Sends `comment.created`. Experimental. */
2219
+ async reply(text, options) {
2220
+ const ctx = this.#ctx;
2221
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/users/${segment(this.id)}/reply`, { body: { text, discussion: options.discussion.id } }));
2222
+ return new NotionComment(ctx, data);
2223
+ }
2224
+ /** Edit one of this person's comments. Sends `comment.updated`. Experimental. */
2225
+ async editComment(text, options) {
2226
+ const ctx = this.#ctx;
2227
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/users/${segment(this.id)}/edit-comment`, { body: { text, comment: options.comment.id } }));
2228
+ return (data === null ? undefined : new NotionDelivery(ctx, data));
2229
+ }
2230
+ /** Delete one of this person's comments. Sends `comment.deleted`. Experimental. */
2231
+ async deleteComment(options) {
2232
+ const ctx = this.#ctx;
2233
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/users/${segment(this.id)}/delete-comment`, { body: { comment: options.comment.id } }));
2234
+ return (data === null ? undefined : new NotionDelivery(ctx, data));
2235
+ }
2236
+ /** Resolve a discussion. Notion sends no event for it, and the API no longer lists its comments. Experimental. */
2237
+ async resolve(options) {
2238
+ const ctx = this.#ctx;
2239
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/users/${segment(this.id)}/resolve`, { body: { discussion: options.discussion.id } }));
2240
+ return (data === null ? undefined : new NotionDelivery(ctx, data));
2241
+ }
2242
+ /** Reopen a resolved discussion. Experimental. */
2243
+ async reopen(options) {
2244
+ const ctx = this.#ctx;
2245
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/users/${segment(this.id)}/reopen`, { body: { discussion: options.discussion.id } }));
2246
+ return (data === null ? undefined : new NotionDelivery(ctx, data));
2247
+ }
2248
+ /** Create a page as this person. Sends `page.created` if the integration can see it. Experimental. */
2249
+ async createPage(page) {
2250
+ const ctx = this.#ctx;
2251
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/users/${segment(this.id)}/pages`, { body: { page: { ...page, parent: page.parent === undefined ? undefined : page.parent.id, content: page.content === undefined ? undefined : readDocument(page.content), connections: page.connections === undefined ? undefined : page.connections.map((item) => item.id) } } }));
2252
+ return new NotionPage(ctx, data);
2253
+ }
2254
+ /** Edit a page's body: append, or replace it. Sends one `page.content_updated` once Notion's batching delay is over. Experimental. */
2255
+ async edit(change, options) {
2256
+ const ctx = this.#ctx;
2257
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/users/${segment(this.id)}/edit`, { body: { change: { ...change, append: change.append === undefined ? undefined : readDocument(change.append), replace: change.replace === undefined ? undefined : readDocument(change.replace) }, page: options.page.id } }));
2258
+ return (data === null ? undefined : new NotionDelivery(ctx, data));
2259
+ }
2260
+ /** Change a page's title. Sends `page.properties_updated`. Experimental. */
2261
+ async rename(title, options) {
2262
+ const ctx = this.#ctx;
2263
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/users/${segment(this.id)}/rename`, { body: { title, page: options.page.id } }));
2264
+ return (data === null ? undefined : new NotionDelivery(ctx, data));
2265
+ }
2266
+ /** Mention the integration in the page body: in the block with `inBlock` in its text, or in a new paragraph. Sends `page.content_updated` after the batching delay. Experimental. */
2267
+ async mention(integration, options) {
2268
+ const ctx = this.#ctx;
2269
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/users/${segment(this.id)}/mention`, { body: { integration: integration.id, page: options.page.id, inBlock: options.inBlock === undefined ? undefined : patternOnWire(options.inBlock) } }));
2270
+ return (data === null ? undefined : new NotionDelivery(ctx, data));
2271
+ }
2272
+ /** Set a property of a database row. Sends `page.properties_updated`. Experimental. */
2273
+ async setProperty(name, value, options) {
2274
+ const ctx = this.#ctx;
2275
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/users/${segment(this.id)}/set-property`, { body: { name, value, page: options.page.id } }));
2276
+ return (data === null ? undefined : new NotionDelivery(ctx, data));
2277
+ }
2278
+ /** Add a row to a database. Sends `page.created` if the integration can see the database. Experimental. */
2279
+ async addRow(values, options) {
2280
+ const ctx = this.#ctx;
2281
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/users/${segment(this.id)}/rows`, { body: { values, database: options.database.id } }));
2282
+ return new NotionPage(ctx, data);
2283
+ }
2284
+ /** Connect the integration to a page (Share → Connections): it sees the page and everything under it. Experimental. */
2285
+ async connect(integration, options) {
2286
+ const ctx = this.#ctx;
2287
+ await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/users/${segment(this.id)}/connect`, { body: { integration: integration.id, page: options.page.id } });
2288
+ }
2289
+ /** Remove the integration's connection from a page. Experimental. */
2290
+ async disconnect(integration, options) {
2291
+ const ctx = this.#ctx;
2292
+ await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/users/${segment(this.id)}/disconnect`, { body: { integration: integration.id, page: options.page.id } });
2293
+ }
2294
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2295
+ [QUIET]() {
2296
+ return quietOf(this.#ctx);
2297
+ }
2298
+ }
2299
+ export class NotionPage {
2300
+ id;
2301
+ channel;
2302
+ title;
2303
+ url;
2304
+ #ctx;
2305
+ /** @internal Handles come from the SDK, never from `new`. */
2306
+ constructor(ctx, data) {
2307
+ this.#ctx = ctx;
2308
+ this.id = data.id;
2309
+ this.channel = data.channel;
2310
+ this.title = data.title;
2311
+ this.url = data.url;
2312
+ }
2313
+ /** The page's discussions: on the page itself, and on its blocks. Experimental. */
2314
+ async discussions() {
2315
+ const ctx = this.#ctx;
2316
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/notion/pages/${segment(this.id)}/discussions`));
2317
+ return decodeNotionDiscussions(ctx, data);
2318
+ }
2319
+ /** The page body as Markdown, once the agent is quiet. Experimental. */
2320
+ async markdown() {
2321
+ const ctx = this.#ctx;
2322
+ await untilQuiet(() => quietOf(ctx));
2323
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/notion/pages/${segment(this.id)}/markdown`));
2324
+ return data;
2325
+ }
2326
+ /** The page's blocks as the API has them, with nested blocks under `children`. Experimental. */
2327
+ async blocks() {
2328
+ const ctx = this.#ctx;
2329
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/notion/pages/${segment(this.id)}/blocks`));
2330
+ return data;
2331
+ }
2332
+ /** A property's value as a person reads it: text, a number, option names, ids. Experimental. */
2333
+ async property(name) {
2334
+ const ctx = this.#ctx;
2335
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/notion/pages/${segment(this.id)}/property`, { query: { name } }));
2336
+ return decodeNotionPropertyValue(ctx, data);
2337
+ }
2338
+ /** The pages directly under this page. Experimental. */
2339
+ async children() {
2340
+ const ctx = this.#ctx;
2341
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/notion/pages/${segment(this.id)}/children`));
2342
+ return decodeNotionChildPages(ctx, data);
2343
+ }
2344
+ /** The integrations that can see the page: connected to it or to a page above it. Experimental. */
2345
+ async connections() {
2346
+ const ctx = this.#ctx;
2347
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/notion/pages/${segment(this.id)}/connections`));
2348
+ return decodeNotionConnections(ctx, data);
2349
+ }
2350
+ /** The page and its discussions as a person reads them. Experimental. */
2351
+ async transcript() {
2352
+ const ctx = this.#ctx;
2353
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/notion/pages/${segment(this.id)}/transcript`));
2354
+ return decodeNotionTranscript(ctx, data);
2355
+ }
2356
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2357
+ [QUIET]() {
2358
+ return quietOf(this.#ctx);
2359
+ }
2360
+ }
2361
+ export class NotionDatabase {
2362
+ id;
2363
+ channel;
2364
+ title;
2365
+ url;
2366
+ #ctx;
2367
+ /** @internal Handles come from the SDK, never from `new`. */
2368
+ constructor(ctx, data) {
2369
+ this.#ctx = ctx;
2370
+ this.id = data.id;
2371
+ this.channel = data.channel;
2372
+ this.title = data.title;
2373
+ this.url = data.url;
2374
+ }
2375
+ /** The rows of a database, optionally only those whose properties have these values. Experimental. */
2376
+ async rows(filter) {
2377
+ const ctx = this.#ctx;
2378
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/databases/${segment(this.id)}/rows`, { body: { filter } }));
2379
+ return decodeNotionRows(ctx, data);
2380
+ }
2381
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2382
+ [QUIET]() {
2383
+ return quietOf(this.#ctx);
2384
+ }
2385
+ }
2386
+ export class NotionDelivery {
2387
+ id;
2388
+ channel;
2389
+ type;
2390
+ entity;
2391
+ payload;
2392
+ attempts;
2393
+ status;
2394
+ #ctx;
2395
+ /** @internal Handles come from the SDK, never from `new`. */
2396
+ constructor(ctx, data) {
2397
+ this.#ctx = ctx;
2398
+ this.id = data.id;
2399
+ this.channel = data.channel;
2400
+ this.type = data.type;
2401
+ this.entity = data.entity;
2402
+ this.payload = data.payload;
2403
+ this.attempts = data.attempts;
2404
+ this.status = data.status;
2405
+ }
2406
+ /** Re-read a delivery: its attempts and status. Experimental. */
2407
+ async refresh() {
2408
+ const ctx = this.#ctx;
2409
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/notion/deliveries/${segment(this.id)}`));
2410
+ return new NotionDelivery(ctx, data);
2411
+ }
2412
+ /** Send the same event again, as a retry does: the same body, the next `attempt_number`, signed again. Experimental. */
2413
+ async redeliver() {
2414
+ const ctx = this.#ctx;
2415
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/deliveries/${segment(this.id)}/redeliver`));
2416
+ return data;
2417
+ }
2418
+ /** Send the delivery again, signed with a token that isn't the subscription's. Experimental. */
2419
+ async resend(options = {}) {
2420
+ const ctx = this.#ctx;
2421
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/deliveries/${segment(this.id)}/resend`, { body: { badSignature: options.badSignature } }));
2422
+ return data;
2423
+ }
2424
+ /** Wait for the delivery to settle, and resolve with the value as it is then. */
2425
+ async settled(options = {}) {
2426
+ return waitFor("the delivery to settle", async () => {
2427
+ const value = await this.refresh();
2428
+ return value.status === "pending" ? undefined : value;
2429
+ }, options);
2430
+ }
2431
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2432
+ [QUIET]() {
2433
+ return quietOf(this.#ctx);
2434
+ }
2435
+ }
2436
+ export class NotionComment {
2437
+ id;
2438
+ discussion;
2439
+ author;
2440
+ text;
2441
+ createdAt;
2442
+ delivery;
2443
+ #ctx;
2444
+ /** @internal Handles come from the SDK, never from `new`. */
2445
+ constructor(ctx, data) {
2446
+ this.#ctx = ctx;
2447
+ this.id = data.id;
2448
+ this.discussion = new NotionDiscussion(ctx, data.discussion);
2449
+ this.author = data.author.kind === "user" ? new NotionUser(ctx, data.author) : new NotionIntegration(ctx, data.author);
2450
+ this.text = data.text;
2451
+ this.createdAt = data.createdAt;
2452
+ this.delivery = data.delivery === undefined ? undefined : new NotionDelivery(ctx, data.delivery);
2453
+ }
2454
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2455
+ [QUIET]() {
2456
+ return quietOf(this.#ctx);
2457
+ }
2458
+ }
2459
+ export class NotionDiscussion {
2460
+ id;
2461
+ page;
2462
+ anchor;
2463
+ #ctx;
2464
+ #seen = new Map();
2465
+ /** @internal Handles come from the SDK, never from `new`. */
2466
+ constructor(ctx, data) {
2467
+ this.#ctx = ctx;
2468
+ this.id = data.id;
2469
+ this.page = new NotionPage(ctx, data.page);
2470
+ this.anchor = data.anchor;
2471
+ }
2472
+ /** The discussion's comments, oldest first. Experimental. */
2473
+ async comments() {
2474
+ const ctx = this.#ctx;
2475
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/notion/discussions/${segment(this.id)}/comments`));
2476
+ return decodeNotionComments(ctx, data);
2477
+ }
2478
+ /** Whether the discussion is resolved. Experimental. */
2479
+ async resolved() {
2480
+ const ctx = this.#ctx;
2481
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/notion/discussions/${segment(this.id)}/resolved`));
2482
+ return data;
2483
+ }
2484
+ /** The discussion as a person reads it. Experimental. */
2485
+ async transcript() {
2486
+ const ctx = this.#ctx;
2487
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/notion/discussions/${segment(this.id)}/transcript`));
2488
+ return decodeNotionTranscript(ctx, data);
2489
+ }
2490
+ /** Wait for the next new comment matching `from` (anyone if omitted), after the last one this handle saw. */
2491
+ async waitForComment(options = {}) {
2492
+ return waitForNext(this.#seen, "waitForComment", () => this.comments(), (item) => fromMatches(item.author, options.from), describeWait("a comment", options.from), options);
2493
+ }
2494
+ /** The latest comment matching `from`, once the agent is quiet. Waits for at least one. */
2495
+ async latestComment(options = {}) {
2496
+ return latestOnceQuiet(() => this.comments(), (item) => fromMatches(item.author, options.from), () => quietOf(this.#ctx), describeWait("a comment", options.from), options);
2497
+ }
2498
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2499
+ [QUIET]() {
2500
+ return quietOf(this.#ctx);
2501
+ }
2502
+ }
2503
+ export class ResendFixture {
2504
+ app;
2505
+ apiUrl;
2506
+ #ctx;
2507
+ #seen = new Map();
2508
+ /** @internal Handles come from the SDK, never from `new`. */
2509
+ constructor(ctx, data) {
2510
+ this.#ctx = ctx;
2511
+ this.app = new ResendApp(ctx, data.app);
2512
+ this.apiUrl = data.apiUrl;
2513
+ }
2514
+ /** Create a person: a mailbox, at `<name>@example.com` unless a test gives the address. Experimental. */
2515
+ async createUser(options) {
2516
+ const ctx = this.#ctx;
2517
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/resend/users`, { body: { name: options.name, address: options.address, token: options.token ?? credential("CHANNELSTACK_RESEND_USER_{name}_TOKEN", { name: options.name }) } }));
2518
+ return new ResendUser(ctx, data);
2519
+ }
2520
+ /** Every webhook channelstack sent the agent for this session, with every attempt. Experimental. */
2521
+ async deliveries(options = {}) {
2522
+ const ctx = this.#ctx;
2523
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/resend/deliveries`, { query: { type: options.type, resource: options.resource === undefined ? undefined : options.resource.id } }));
2524
+ return decodeResendDeliveries(ctx, data);
2525
+ }
2526
+ /** The REST calls the agent made about this session's emails, by the SDK's method name (`emails.send`). Experimental. */
2527
+ async calls(options = {}) {
2528
+ const ctx = this.#ctx;
2529
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/resend/calls`, { query: { operation: options.operation, error: options.error } }));
2530
+ return data;
2531
+ }
2532
+ /** Wait for the next new API call from the agent, after the last one this handle saw. */
2533
+ async waitForCall(filter, options = {}) {
2534
+ return waitForNext(this.#seen, `waitForCall:${JSON.stringify(filter)}`, () => this.calls(filter), () => true, "an API call from the agent", options);
2535
+ }
2536
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2537
+ [QUIET]() {
2538
+ return quietOf(this.#ctx);
2539
+ }
2540
+ }
2541
+ export class ResendApp {
2542
+ id;
2543
+ channel;
2544
+ kind;
2545
+ name;
2546
+ botUserId;
2547
+ address;
2548
+ #ctx;
2549
+ /** @internal Handles come from the SDK, never from `new`. */
2550
+ constructor(ctx, data) {
2551
+ this.#ctx = ctx;
2552
+ this.id = data.id;
2553
+ this.channel = data.channel;
2554
+ this.kind = data.kind;
2555
+ this.name = data.name;
2556
+ this.botUserId = data.botUserId;
2557
+ this.address = data.address;
2558
+ }
2559
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2560
+ [QUIET]() {
2561
+ return quietOf(this.#ctx);
2562
+ }
2563
+ }
2564
+ export class ResendUser {
2565
+ id;
2566
+ channel;
2567
+ kind;
2568
+ name;
2569
+ address;
2570
+ #ctx;
2571
+ #seen = new Map();
2572
+ /** @internal Handles come from the SDK, never from `new`. */
2573
+ constructor(ctx, data) {
2574
+ this.#ctx = ctx;
2575
+ this.id = data.id;
2576
+ this.channel = data.channel;
2577
+ this.kind = data.kind;
2578
+ this.name = data.name;
2579
+ this.address = data.address;
2580
+ }
2581
+ /** The person emails someone: the agent (`resend.app`), or another person. Experimental. */
2582
+ async send(options) {
2583
+ const ctx = this.#ctx;
2584
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/resend/users/${segment(this.id)}/send`, { body: { to: options.to.map((item) => item.id), cc: options.cc === undefined ? undefined : options.cc.map((item) => item.id), subject: options.subject, text: options.text, html: options.html } }));
2585
+ return new ResendEmail(ctx, data);
2586
+ }
2587
+ /** The person replies to an email, in its thread: `Re:` its subject, with `In-Reply-To` and `References`. Experimental. */
2588
+ async reply(email, options = {}) {
2589
+ const ctx = this.#ctx;
2590
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/resend/users/${segment(this.id)}/reply`, { body: { email: email.id, text: options.text, html: options.html, all: options.all } }));
2591
+ return new ResendEmail(ctx, data);
2592
+ }
2593
+ /** What reached the person's mailbox, oldest first. Experimental. */
2594
+ async inbox() {
2595
+ const ctx = this.#ctx;
2596
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/resend/users/${segment(this.id)}/inbox`));
2597
+ return decodeResendInbox(ctx, data);
2598
+ }
2599
+ /** Wait for the next new email matching `from` (anyone if omitted), after the last one this handle saw. */
2600
+ async waitForEmail(options = {}) {
2601
+ return waitForNext(this.#seen, "waitForEmail", () => this.inbox(), (item) => fromMatches(item.author, options.from), describeWait("an email", options.from), options);
2602
+ }
2603
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2604
+ [QUIET]() {
2605
+ return quietOf(this.#ctx);
2606
+ }
2607
+ }
2608
+ export class ResendEmail {
2609
+ id;
2610
+ channel;
2611
+ thread;
2612
+ author;
2613
+ from;
2614
+ to;
2615
+ cc;
2616
+ subject;
2617
+ text;
2618
+ at;
2619
+ messageId;
2620
+ delivery;
2621
+ #ctx;
2622
+ /** @internal Handles come from the SDK, never from `new`. */
2623
+ constructor(ctx, data) {
2624
+ this.#ctx = ctx;
2625
+ this.id = data.id;
2626
+ this.channel = data.channel;
2627
+ this.thread = new ResendThread(ctx, data.thread);
2628
+ this.author = data.author;
2629
+ this.from = data.from;
2630
+ this.to = data.to;
2631
+ this.cc = data.cc;
2632
+ this.subject = data.subject;
2633
+ this.text = data.text;
2634
+ this.at = data.at;
2635
+ this.messageId = data.messageId;
2636
+ this.delivery = data.delivery === undefined ? undefined : new ResendDelivery(ctx, data.delivery);
2637
+ }
2638
+ /** Re-read an email. Experimental. */
2639
+ async refresh() {
2640
+ const ctx = this.#ctx;
2641
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/resend/emails/${segment(this.id)}`));
2642
+ return new ResendEmail(ctx, data);
2643
+ }
2644
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2645
+ [QUIET]() {
2646
+ return quietOf(this.#ctx);
2647
+ }
2648
+ }
2649
+ export class ResendThread {
2650
+ id;
2651
+ channel;
2652
+ subject;
2653
+ #ctx;
2654
+ #seen = new Map();
2655
+ /** @internal Handles come from the SDK, never from `new`. */
2656
+ constructor(ctx, data) {
2657
+ this.#ctx = ctx;
2658
+ this.id = data.id;
2659
+ this.channel = data.channel;
2660
+ this.subject = data.subject;
2661
+ }
2662
+ /** Every email in the thread, oldest first. Experimental. */
2663
+ async messages() {
2664
+ const ctx = this.#ctx;
2665
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/resend/threads/${segment(this.id)}/messages`));
2666
+ return decodeResendMessages(ctx, data);
2667
+ }
2668
+ /** The thread's answers: every email after the first, oldest first. Experimental. */
2669
+ async replies() {
2670
+ const ctx = this.#ctx;
2671
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/resend/threads/${segment(this.id)}/replies`));
2672
+ return decodeResendReplies(ctx, data);
2673
+ }
2674
+ /** The thread as a person reads it: each email's own words, without the quoted history. Experimental. */
2675
+ async transcript() {
2676
+ const ctx = this.#ctx;
2677
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/resend/threads/${segment(this.id)}/transcript`));
2678
+ return decodeResendTranscript(ctx, data);
2679
+ }
2680
+ /** Wait for the next new reply matching `from` (anyone if omitted), after the last one this handle saw. */
2681
+ async waitForReply(options = {}) {
2682
+ return waitForNext(this.#seen, "waitForReply", () => this.replies(), (item) => fromMatches(item.author, options.from), describeWait("a reply", options.from), options);
2683
+ }
2684
+ /** The latest reply matching `from`, once the agent is quiet. Waits for at least one. */
2685
+ async latestReply(options = {}) {
2686
+ return latestOnceQuiet(() => this.replies(), (item) => fromMatches(item.author, options.from), () => quietOf(this.#ctx), describeWait("a reply", options.from), options);
2687
+ }
2688
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2689
+ [QUIET]() {
2690
+ return quietOf(this.#ctx);
2691
+ }
2692
+ }
2693
+ export class ResendDelivery {
2694
+ id;
2695
+ channel;
2696
+ type;
2697
+ email;
2698
+ payload;
2699
+ attempts;
2700
+ status;
2701
+ #ctx;
2702
+ /** @internal Handles come from the SDK, never from `new`. */
2703
+ constructor(ctx, data) {
2704
+ this.#ctx = ctx;
2705
+ this.id = data.id;
2706
+ this.channel = data.channel;
2707
+ this.type = data.type;
2708
+ this.email = data.email;
2709
+ this.payload = data.payload;
2710
+ this.attempts = data.attempts;
2711
+ this.status = data.status;
2712
+ }
2713
+ /** Re-read a delivery: its attempts and status. Experimental. */
2714
+ async refresh() {
2715
+ const ctx = this.#ctx;
2716
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/resend/deliveries/${segment(this.id)}`));
2717
+ return new ResendDelivery(ctx, data);
2718
+ }
2719
+ /** Send the same webhook again, as Resend retries: the same `svix-id`, signed again. Experimental. */
2720
+ async redeliver() {
2721
+ const ctx = this.#ctx;
2722
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/resend/deliveries/${segment(this.id)}/redeliver`));
2723
+ return data;
2724
+ }
2725
+ /** Send the webhook again, forged: signed with a secret that isn't the webhook's, or with a timestamp past the five minutes receivers accept. Experimental. */
2726
+ async resend(options = {}) {
2727
+ const ctx = this.#ctx;
2728
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/resend/deliveries/${segment(this.id)}/resend`, { body: { badSignature: options.badSignature, stale: options.stale } }));
2729
+ return data;
2730
+ }
2731
+ /** Wait for the delivery to settle, and resolve with the value as it is then. */
2732
+ async settled(options = {}) {
2733
+ return waitFor("the delivery to settle", async () => {
2734
+ const value = await this.refresh();
2735
+ return value.status === "pending" ? undefined : value;
2736
+ }, options);
2737
+ }
2738
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2739
+ [QUIET]() {
2740
+ return quietOf(this.#ctx);
2741
+ }
2742
+ }
2743
+ export class GoogleFixture {
2744
+ app;
2745
+ apiUrl;
2746
+ #ctx;
2747
+ #seen = new Map();
2748
+ /** @internal Handles come from the SDK, never from `new`. */
2749
+ constructor(ctx, data) {
2750
+ this.#ctx = ctx;
2751
+ this.app = new GoogleApp(ctx, data.app);
2752
+ this.apiUrl = data.apiUrl;
2753
+ }
2754
+ /** Create a person: a mailbox, at `<name>@example.com` unless a test gives the address. Experimental. */
2755
+ async createUser(options) {
2756
+ const ctx = this.#ctx;
2757
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/google/users`, { body: { name: options.name, address: options.address, token: options.token ?? credential("CHANNELSTACK_GOOGLE_USER_{name}_TOKEN", { name: options.name }) } }));
2758
+ return new GoogleUser(ctx, data);
2759
+ }
2760
+ /** Every push channelstack sent the agent for this session, with every attempt. Experimental. */
2761
+ async deliveries(options = {}) {
2762
+ const ctx = this.#ctx;
2763
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/google/deliveries`, { query: { type: options.type, resource: options.resource === undefined ? undefined : options.resource.id } }));
2764
+ return decodeGoogleDeliveries(ctx, data);
2765
+ }
2766
+ /** The Gmail calls the agent made about this session's mail, by the SDK's method name (`users.messages.send`). Experimental. */
2767
+ async calls(options = {}) {
2768
+ const ctx = this.#ctx;
2769
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/google/calls`, { query: { operation: options.operation, error: options.error } }));
2770
+ return data;
2771
+ }
2772
+ /** Wait for the next new API call from the agent, after the last one this handle saw. */
2773
+ async waitForCall(filter, options = {}) {
2774
+ return waitForNext(this.#seen, `waitForCall:${JSON.stringify(filter)}`, () => this.calls(filter), () => true, "an API call from the agent", options);
2775
+ }
2776
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2777
+ [QUIET]() {
2778
+ return quietOf(this.#ctx);
2779
+ }
2780
+ }
2781
+ export class GoogleApp {
2782
+ id;
2783
+ channel;
2784
+ kind;
2785
+ name;
2786
+ botUserId;
2787
+ address;
2788
+ #ctx;
2789
+ /** @internal Handles come from the SDK, never from `new`. */
2790
+ constructor(ctx, data) {
2791
+ this.#ctx = ctx;
2792
+ this.id = data.id;
2793
+ this.channel = data.channel;
2794
+ this.kind = data.kind;
2795
+ this.name = data.name;
2796
+ this.botUserId = data.botUserId;
2797
+ this.address = data.address;
2798
+ }
2799
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2800
+ [QUIET]() {
2801
+ return quietOf(this.#ctx);
2802
+ }
2803
+ }
2804
+ export class GoogleUser {
2805
+ id;
2806
+ channel;
2807
+ kind;
2808
+ name;
2809
+ address;
2810
+ #ctx;
2811
+ #seen = new Map();
2812
+ /** @internal Handles come from the SDK, never from `new`. */
2813
+ constructor(ctx, data) {
2814
+ this.#ctx = ctx;
2815
+ this.id = data.id;
2816
+ this.channel = data.channel;
2817
+ this.kind = data.kind;
2818
+ this.name = data.name;
2819
+ this.address = data.address;
2820
+ }
2821
+ /** The person emails someone: the agent (`google.app`), or another person. Experimental. */
2822
+ async send(options) {
2823
+ const ctx = this.#ctx;
2824
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/google/users/${segment(this.id)}/send`, { body: { to: options.to.map((item) => item.id), cc: options.cc === undefined ? undefined : options.cc.map((item) => item.id), subject: options.subject, text: options.text, html: options.html } }));
2825
+ return new GoogleEmail(ctx, data);
2826
+ }
2827
+ /** The person replies to an email, in its thread: `Re:` its subject, with `In-Reply-To` and `References`. Experimental. */
2828
+ async reply(email, options = {}) {
2829
+ const ctx = this.#ctx;
2830
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/google/users/${segment(this.id)}/reply`, { body: { email: email.id, text: options.text, html: options.html, all: options.all } }));
2831
+ return new GoogleEmail(ctx, data);
2832
+ }
2833
+ /** What reached the person's mailbox, oldest first. Experimental. */
2834
+ async inbox() {
2835
+ const ctx = this.#ctx;
2836
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/google/users/${segment(this.id)}/inbox`));
2837
+ return decodeGoogleInbox(ctx, data);
2838
+ }
2839
+ /** Wait for the next new email matching `from` (anyone if omitted), after the last one this handle saw. */
2840
+ async waitForEmail(options = {}) {
2841
+ return waitForNext(this.#seen, "waitForEmail", () => this.inbox(), (item) => fromMatches(item.author, options.from), describeWait("an email", options.from), options);
2842
+ }
2843
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2844
+ [QUIET]() {
2845
+ return quietOf(this.#ctx);
2846
+ }
2847
+ }
2848
+ export class GoogleEmail {
2849
+ id;
2850
+ channel;
2851
+ thread;
2852
+ author;
2853
+ from;
2854
+ to;
2855
+ cc;
2856
+ subject;
2857
+ text;
2858
+ at;
2859
+ messageId;
2860
+ labels;
2861
+ delivery;
2862
+ #ctx;
2863
+ /** @internal Handles come from the SDK, never from `new`. */
2864
+ constructor(ctx, data) {
2865
+ this.#ctx = ctx;
2866
+ this.id = data.id;
2867
+ this.channel = data.channel;
2868
+ this.thread = new GoogleThread(ctx, data.thread);
2869
+ this.author = data.author;
2870
+ this.from = data.from;
2871
+ this.to = data.to;
2872
+ this.cc = data.cc;
2873
+ this.subject = data.subject;
2874
+ this.text = data.text;
2875
+ this.at = data.at;
2876
+ this.messageId = data.messageId;
2877
+ this.labels = data.labels;
2878
+ this.delivery = data.delivery === undefined ? undefined : new GoogleDelivery(ctx, data.delivery);
2879
+ }
2880
+ /** Re-read an email. Experimental. */
2881
+ async refresh() {
2882
+ const ctx = this.#ctx;
2883
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/google/emails/${segment(this.id)}`));
2884
+ return new GoogleEmail(ctx, data);
2885
+ }
2886
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2887
+ [QUIET]() {
2888
+ return quietOf(this.#ctx);
2889
+ }
2890
+ }
2891
+ export class GoogleThread {
2892
+ id;
2893
+ channel;
2894
+ subject;
2895
+ #ctx;
2896
+ #seen = new Map();
2897
+ /** @internal Handles come from the SDK, never from `new`. */
2898
+ constructor(ctx, data) {
2899
+ this.#ctx = ctx;
2900
+ this.id = data.id;
2901
+ this.channel = data.channel;
2902
+ this.subject = data.subject;
2903
+ }
2904
+ /** Every email in the thread, oldest first. Experimental. */
2905
+ async messages() {
2906
+ const ctx = this.#ctx;
2907
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/google/threads/${segment(this.id)}/messages`));
2908
+ return decodeGoogleMessages(ctx, data);
2909
+ }
2910
+ /** The thread's answers: every email after the first, oldest first. Experimental. */
2911
+ async replies() {
2912
+ const ctx = this.#ctx;
2913
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/google/threads/${segment(this.id)}/replies`));
2914
+ return decodeGoogleReplies(ctx, data);
2915
+ }
2916
+ /** The thread as a person reads it: each email's own words, without the quoted history. Experimental. */
2917
+ async transcript() {
2918
+ const ctx = this.#ctx;
2919
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/google/threads/${segment(this.id)}/transcript`));
2920
+ return decodeGoogleTranscript(ctx, data);
2921
+ }
2922
+ /** Wait for the next new reply matching `from` (anyone if omitted), after the last one this handle saw. */
2923
+ async waitForReply(options = {}) {
2924
+ return waitForNext(this.#seen, "waitForReply", () => this.replies(), (item) => fromMatches(item.author, options.from), describeWait("a reply", options.from), options);
2925
+ }
2926
+ /** The latest reply matching `from`, once the agent is quiet. Waits for at least one. */
2927
+ async latestReply(options = {}) {
2928
+ return latestOnceQuiet(() => this.replies(), (item) => fromMatches(item.author, options.from), () => quietOf(this.#ctx), describeWait("a reply", options.from), options);
2929
+ }
2930
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2931
+ [QUIET]() {
2932
+ return quietOf(this.#ctx);
2933
+ }
2934
+ }
2935
+ export class GoogleDelivery {
2936
+ id;
2937
+ channel;
2938
+ type;
2939
+ emailAddress;
2940
+ historyId;
2941
+ payload;
2942
+ attempts;
2943
+ status;
2944
+ #ctx;
2945
+ /** @internal Handles come from the SDK, never from `new`. */
2946
+ constructor(ctx, data) {
2947
+ this.#ctx = ctx;
2948
+ this.id = data.id;
2949
+ this.channel = data.channel;
2950
+ this.type = data.type;
2951
+ this.emailAddress = data.emailAddress;
2952
+ this.historyId = data.historyId;
2953
+ this.payload = data.payload;
2954
+ this.attempts = data.attempts;
2955
+ this.status = data.status;
2956
+ }
2957
+ /** Re-read a delivery: its attempts and status. Experimental. */
2958
+ async refresh() {
2959
+ const ctx = this.#ctx;
2960
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/google/deliveries/${segment(this.id)}`));
2961
+ return new GoogleDelivery(ctx, data);
2962
+ }
2963
+ /** Push the same message again, as Pub/Sub does when a push isn't acknowledged: the same message id. Experimental. */
2964
+ async redeliver() {
2965
+ const ctx = this.#ctx;
2966
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/google/deliveries/${segment(this.id)}/redeliver`));
2967
+ return data;
2968
+ }
2969
+ /** Push it again, forged: with a token signed by another key, one that has expired, or one for another audience than the push endpoint. Experimental. */
2970
+ async resend(options = {}) {
2971
+ const ctx = this.#ctx;
2972
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/google/deliveries/${segment(this.id)}/resend`, { body: { badSignature: options.badSignature, stale: options.stale, wrongAudience: options.wrongAudience } }));
2973
+ return data;
2974
+ }
2975
+ /** Wait for the delivery to settle, and resolve with the value as it is then. */
2976
+ async settled(options = {}) {
2977
+ return waitFor("the delivery to settle", async () => {
2978
+ const value = await this.refresh();
2979
+ return value.status === "pending" ? undefined : value;
2980
+ }, options);
2981
+ }
2982
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2983
+ [QUIET]() {
2984
+ return quietOf(this.#ctx);
2985
+ }
2986
+ }
2987
+ export class GitHubPullRequest extends GitHubIssue {
2988
+ head;
2989
+ base;
2990
+ #ctx;
2991
+ /** @internal Handles come from the SDK, never from `new`. */
2992
+ constructor(ctx, data) {
2993
+ super(ctx, data);
2994
+ this.#ctx = ctx;
2995
+ this.head = data.head;
2996
+ this.base = data.base;
2997
+ }
2998
+ /** Read the pull request again. Experimental. */
2999
+ async refresh() {
3000
+ const ctx = this.#ctx;
3001
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.repoId)}/pulls/${segment(this.number)}`));
3002
+ return new GitHubPullRequest(ctx, data);
3003
+ }
3004
+ /** The newest commit of the pull request's branch, once the agent is quiet. Experimental. */
3005
+ async headCommit() {
3006
+ const ctx = this.#ctx;
3007
+ await untilQuiet(() => quietOf(ctx));
3008
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.repoId)}/pulls/${segment(this.number)}/head-commit`));
3009
+ return new GitHubCommit(ctx, data);
3010
+ }
3011
+ /** The submitted reviews, oldest first. Experimental. */
3012
+ async reviews() {
3013
+ const ctx = this.#ctx;
3014
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.repoId)}/pulls/${segment(this.number)}/reviews`));
3015
+ return decodeGitHubReviews(ctx, data);
3016
+ }
3017
+ /** The comments on the diff, oldest first. Experimental. */
3018
+ async reviewComments() {
3019
+ const ctx = this.#ctx;
3020
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.repoId)}/pulls/${segment(this.number)}/review-comments`));
3021
+ return decodeGitHubReviewComments(ctx, data);
3022
+ }
3023
+ /** The check runs on the pull request's newest commit: the newest of each name. Experimental. */
3024
+ async checkRuns() {
3025
+ const ctx = this.#ctx;
3026
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.repoId)}/pulls/${segment(this.number)}/check-runs`));
3027
+ return decodeGitHubPullCheckRuns(ctx, data);
3028
+ }
3029
+ /** Has the pull request been merged?. Experimental. */
3030
+ async merged() {
3031
+ const ctx = this.#ctx;
3032
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.repoId)}/pulls/${segment(this.number)}/merged`));
3033
+ return data;
3034
+ }
3035
+ }
3036
+ /** Attach to a running channelstack server, or start one, and return the client. */
3037
+ export function connect(options = {}) {
3038
+ return connectWith((transport, stop) => new Channelstack(transport, stop), { basePath: "/_channelstack", errors: ERRORS, version: VERSION }, options);
3039
+ }