channelstack 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +56 -2
  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 +102 -0
  7. package/dist/integrations/checks/index.js +1034 -0
  8. package/dist/integrations/matchers-core/index.d.ts +217 -0
  9. package/dist/integrations/matchers-core/index.js +799 -0
  10. package/dist/integrations/matchers-core/matchers.test.d.ts +1 -0
  11. package/dist/integrations/matchers-core/matchers.test.js +407 -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 +82 -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 +139 -0
  22. package/dist/sdks/typescript/client.d.ts +14 -0
  23. package/dist/sdks/typescript/client.js +11 -0
  24. package/dist/sdks/typescript/generated/channels.d.ts +32 -0
  25. package/dist/sdks/typescript/generated/channels.js +4 -0
  26. package/dist/sdks/typescript/generated/index.d.ts +4178 -0
  27. package/dist/sdks/typescript/generated/index.js +4608 -0
  28. package/dist/sdks/typescript/generated/normalisation.d.ts +18 -0
  29. package/dist/sdks/typescript/generated/normalisation.js +14 -0
  30. package/dist/sdks/typescript/runtime/client.d.ts +56 -0
  31. package/dist/sdks/typescript/runtime/client.js +74 -0
  32. package/dist/sdks/typescript/runtime/credentials.d.ts +7 -0
  33. package/dist/sdks/typescript/runtime/credentials.js +20 -0
  34. package/dist/sdks/typescript/runtime/duration.d.ts +4 -0
  35. package/dist/sdks/typescript/runtime/duration.js +13 -0
  36. package/dist/sdks/typescript/runtime/files.d.ts +47 -0
  37. package/dist/sdks/typescript/runtime/files.js +53 -0
  38. package/dist/sdks/typescript/runtime/launcher.d.ts +27 -0
  39. package/dist/sdks/typescript/runtime/launcher.js +124 -0
  40. package/dist/sdks/typescript/runtime/responder.d.ts +26 -0
  41. package/dist/sdks/typescript/runtime/responder.js +42 -0
  42. package/dist/sdks/typescript/runtime/transport.d.ts +43 -0
  43. package/dist/sdks/typescript/runtime/transport.js +95 -0
  44. package/dist/sdks/typescript/runtime/wait.d.ts +96 -0
  45. package/dist/sdks/typescript/runtime/wait.js +159 -0
  46. package/dist/sdks/typescript/types.d.ts +82 -0
  47. package/dist/sdks/typescript/types.js +1 -0
  48. package/package.json +82 -4
@@ -0,0 +1,4608 @@
1
+ // Generated by codegen from spec/ir.json. Do not edit: change the routes and run `pnpm sdk`.
2
+ import { ClientBase, connectWith, CONTEXT, 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, readMedia, readTree } from "../runtime/files.js";
6
+ import { respondWith } from "../runtime/responder.js";
7
+ import { ChannelstackError, segment } from "../runtime/transport.js";
8
+ import { describeWait, fromMatches, textMatches, latestOnceQuiet, waitFor, waitForNext, retryWhile, untilQuiet, patternOnWire } from "../runtime/wait.js";
9
+ /** The server version this SDK was generated for. */
10
+ export const VERSION = "0.2.0";
11
+ export class AccountInactiveError extends ChannelstackError {
12
+ }
13
+ export class ActionRequiresError extends ChannelstackError {
14
+ }
15
+ export class AlreadyInChannelError extends ChannelstackError {
16
+ }
17
+ export class AlreadyReactedError extends ChannelstackError {
18
+ }
19
+ export class CannotDmBotError extends ChannelstackError {
20
+ }
21
+ export class CannotEditOthersMessageError extends ChannelstackError {
22
+ }
23
+ export class CannotMessageUserError extends ChannelstackError {
24
+ }
25
+ export class CantDeleteMessageError extends ChannelstackError {
26
+ }
27
+ export class CantUpdateMessageError extends ChannelstackError {
28
+ }
29
+ export class CrossWorkspaceCredentialError extends ChannelstackError {
30
+ }
31
+ export class DispatchFailedError extends ChannelstackError {
32
+ }
33
+ export class EmptyMessageError extends ChannelstackError {
34
+ }
35
+ export class FakeActorInLiveWorldError extends ChannelstackError {
36
+ }
37
+ export class ForbiddenError extends ChannelstackError {
38
+ }
39
+ export class InternalError extends ChannelstackError {
40
+ }
41
+ export class InvalidArgumentError extends ChannelstackError {
42
+ }
43
+ export class InvalidAuthError extends ChannelstackError {
44
+ }
45
+ export class InvalidFormBodyError extends ChannelstackError {
46
+ }
47
+ export class LiveMisconfiguredError extends ChannelstackError {
48
+ }
49
+ export class LiveNotAllowlistedError extends ChannelstackError {
50
+ }
51
+ export class MethodNotSupportedForChannelTypeError extends ChannelstackError {
52
+ }
53
+ export class MissingAccessError extends ChannelstackError {
54
+ }
55
+ export class MissingPermissionsError extends ChannelstackError {
56
+ }
57
+ export class MsgTooLongError extends ChannelstackError {
58
+ }
59
+ export class NameTakenError extends ChannelstackError {
60
+ }
61
+ export class NoReactionError extends ChannelstackError {
62
+ }
63
+ export class NoTextError extends ChannelstackError {
64
+ }
65
+ export class NotAllowedError extends ChannelstackError {
66
+ }
67
+ export class NotFoundError extends ChannelstackError {
68
+ }
69
+ export class NotInChannelError extends ChannelstackError {
70
+ }
71
+ export class NotInRoomError extends ChannelstackError {
72
+ }
73
+ export class ObjectNotFoundError extends ChannelstackError {
74
+ }
75
+ export class RestrictedResourceError extends ChannelstackError {
76
+ }
77
+ export class SessionNotFoundError extends ChannelstackError {
78
+ }
79
+ export class SplitViewUnavailableError extends ChannelstackError {
80
+ }
81
+ export class StopUnavailableError extends ChannelstackError {
82
+ }
83
+ export class ThreadAlreadyCreatedError extends ChannelstackError {
84
+ }
85
+ export class UnauthorizedError extends ChannelstackError {
86
+ }
87
+ export class UnsupportedInFakeError extends ChannelstackError {
88
+ }
89
+ export class UnsupportedInLiveError extends ChannelstackError {
90
+ }
91
+ export class ValidationErrorError extends ChannelstackError {
92
+ }
93
+ export class ValidationFailedError extends ChannelstackError {
94
+ }
95
+ const ERRORS = {
96
+ account_inactive: AccountInactiveError,
97
+ action_requires: ActionRequiresError,
98
+ already_in_channel: AlreadyInChannelError,
99
+ already_reacted: AlreadyReactedError,
100
+ cannot_dm_bot: CannotDmBotError,
101
+ cannot_edit_others_message: CannotEditOthersMessageError,
102
+ cannot_message_user: CannotMessageUserError,
103
+ cant_delete_message: CantDeleteMessageError,
104
+ cant_update_message: CantUpdateMessageError,
105
+ cross_workspace_credential: CrossWorkspaceCredentialError,
106
+ dispatch_failed: DispatchFailedError,
107
+ empty_message: EmptyMessageError,
108
+ fake_actor_in_live_world: FakeActorInLiveWorldError,
109
+ forbidden: ForbiddenError,
110
+ internal: InternalError,
111
+ invalid_argument: InvalidArgumentError,
112
+ invalid_auth: InvalidAuthError,
113
+ invalid_form_body: InvalidFormBodyError,
114
+ live_misconfigured: LiveMisconfiguredError,
115
+ live_not_allowlisted: LiveNotAllowlistedError,
116
+ method_not_supported_for_channel_type: MethodNotSupportedForChannelTypeError,
117
+ missing_access: MissingAccessError,
118
+ missing_permissions: MissingPermissionsError,
119
+ msg_too_long: MsgTooLongError,
120
+ name_taken: NameTakenError,
121
+ no_reaction: NoReactionError,
122
+ no_text: NoTextError,
123
+ not_allowed: NotAllowedError,
124
+ not_found: NotFoundError,
125
+ not_in_channel: NotInChannelError,
126
+ not_in_room: NotInRoomError,
127
+ object_not_found: ObjectNotFoundError,
128
+ restricted_resource: RestrictedResourceError,
129
+ session_not_found: SessionNotFoundError,
130
+ split_view_unavailable: SplitViewUnavailableError,
131
+ stop_unavailable: StopUnavailableError,
132
+ thread_already_created: ThreadAlreadyCreatedError,
133
+ unauthorized: UnauthorizedError,
134
+ unsupported_in_fake: UnsupportedInFakeError,
135
+ unsupported_in_live: UnsupportedInLiveError,
136
+ validation_error: ValidationErrorError,
137
+ validation_failed: ValidationFailedError,
138
+ };
139
+ function decodeEchoApps(ctx, data) {
140
+ return data.map((item) => new EchoApp(ctx, item));
141
+ }
142
+ function decodeSlackApps(ctx, data) {
143
+ return data.map((item) => new SlackApp(ctx, item));
144
+ }
145
+ function decodeSlackUsers(ctx, data) {
146
+ return data.map((item) => new SlackUser(ctx, item));
147
+ }
148
+ function decodeSlackConversations(ctx, data) {
149
+ return data.map((item) => new SlackConversation(ctx, item));
150
+ }
151
+ function decodeSlackModals(ctx, data) {
152
+ return data.map((item) => new SlackModal(ctx, item));
153
+ }
154
+ function decodeSlackModalValues(ctx, data) {
155
+ return Object.fromEntries(Object.entries(data).map(([key, value]) => [key, (value === null ? undefined : value)]));
156
+ }
157
+ function decodeSlackMessages(ctx, data) {
158
+ return data.map((item) => new SlackMessage(ctx, item));
159
+ }
160
+ function decodeSlackMembers(ctx, data) {
161
+ return data.map((item) => item.kind === "user" ? new SlackUser(ctx, item) : new SlackApp(ctx, item));
162
+ }
163
+ function decodeSlackReplies(ctx, data) {
164
+ return data.map((item) => new SlackMessage(ctx, item));
165
+ }
166
+ function decodeSlackReactions(ctx, data) {
167
+ return data.map((item) => decodeSlackReaction(ctx, item));
168
+ }
169
+ function decodeSlackReaction(ctx, data) {
170
+ return { ...data, by: data.by.map((item) => item.kind === "user" ? new SlackUser(ctx, item) : new SlackApp(ctx, item)) };
171
+ }
172
+ function decodeSlackTranscript(_ctx, data) {
173
+ return printsAs({ ...data }, data.text);
174
+ }
175
+ function decodeSlackEphemeralMessages(ctx, data) {
176
+ return data.map((item) => new SlackMessage(ctx, item));
177
+ }
178
+ function decodeSlackMessageDeliveries(ctx, data) {
179
+ return data.map((item) => new SlackDelivery(ctx, item));
180
+ }
181
+ function decodeSlackDeliveries(ctx, data) {
182
+ return data.map((item) => new SlackDelivery(ctx, item));
183
+ }
184
+ function decodeSlackUninstallDeliveries(ctx, data) {
185
+ return data.map((item) => new SlackDelivery(ctx, item));
186
+ }
187
+ function decodeGitHubUsers(ctx, data) {
188
+ return data.map((item) => new GitHubUser(ctx, item));
189
+ }
190
+ function decodeGitHubRepos(ctx, data) {
191
+ return data.map((item) => new GitHubRepo(ctx, item));
192
+ }
193
+ function decodeGitHubIssues(ctx, data) {
194
+ return data.map((item) => decodeGitHubIssueListing(ctx, item));
195
+ }
196
+ function decodeGitHubIssueListing(ctx, data) {
197
+ return { ...data, issue: new GitHubIssue(ctx, data.issue) };
198
+ }
199
+ function decodeGitHubApps(ctx, data) {
200
+ return data.map((item) => new GitHubApp(ctx, item));
201
+ }
202
+ function decodeGitHubCommits(ctx, data) {
203
+ return data.map((item) => new GitHubCommit(ctx, item));
204
+ }
205
+ function decodeGitHubCheckRuns(ctx, data) {
206
+ return data.map((item) => new GitHubCheckRun(ctx, item));
207
+ }
208
+ function decodeGitHubStatuses(ctx, data) {
209
+ return data.map((item) => ({ ...item, author: item.author.kind === "user" ? new GitHubUser(ctx, item.author) : new GitHubApp(ctx, item.author) }));
210
+ }
211
+ function decodeGitHubLabelDeliveries(ctx, data) {
212
+ return data.map((item) => new GitHubDelivery(ctx, item));
213
+ }
214
+ function decodeGitHubUnlabelDeliveries(ctx, data) {
215
+ return data.map((item) => new GitHubDelivery(ctx, item));
216
+ }
217
+ function decodeGitHubAssignDeliveries(ctx, data) {
218
+ return data.map((item) => new GitHubDelivery(ctx, item));
219
+ }
220
+ function decodeGitHubReview(ctx, data) {
221
+ 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);
222
+ }
223
+ function decodeGitHubComments(ctx, data) {
224
+ return data.map((item) => new GitHubComment(ctx, item));
225
+ }
226
+ function decodeGitHubTranscript(_ctx, data) {
227
+ return printsAs({ ...data }, data.text);
228
+ }
229
+ function decodeGitHubReviews(ctx, data) {
230
+ return data.map((item) => decodeGitHubReview(ctx, item));
231
+ }
232
+ function decodeGitHubReviewComments(ctx, data) {
233
+ return data.map((item) => new GitHubReviewComment(ctx, item));
234
+ }
235
+ function decodeGitHubPullCheckRuns(ctx, data) {
236
+ return data.map((item) => new GitHubCheckRun(ctx, item));
237
+ }
238
+ function decodeGitHubReactions(ctx, data) {
239
+ return data.map((item) => decodeGitHubReaction(ctx, item));
240
+ }
241
+ function decodeGitHubReaction(ctx, data) {
242
+ return { ...data, by: data.by.map((item) => item.kind === "user" ? new GitHubUser(ctx, item) : new GitHubApp(ctx, item)) };
243
+ }
244
+ function decodeGitHubReviewCommentReplies(ctx, data) {
245
+ return data.map((item) => new GitHubReviewComment(ctx, item));
246
+ }
247
+ function decodeGitHubDeliveries(ctx, data) {
248
+ return data.map((item) => new GitHubDelivery(ctx, item));
249
+ }
250
+ function decodeLinearApps(ctx, data) {
251
+ return data.map((item) => new LinearApp(ctx, item));
252
+ }
253
+ function decodeLinearUsers(ctx, data) {
254
+ return data.map((item) => new LinearUser(ctx, item));
255
+ }
256
+ function decodeLinearTeams(ctx, data) {
257
+ return data.map((item) => new LinearTeam(ctx, item));
258
+ }
259
+ function decodeLinearIssues(ctx, data) {
260
+ return data.map((item) => decodeLinearIssueListing(ctx, item));
261
+ }
262
+ function decodeLinearIssueListing(ctx, data) {
263
+ return { ...data, issue: new LinearIssue(ctx, data.issue) };
264
+ }
265
+ function decodeLinearComments(ctx, data) {
266
+ return data.map((item) => new LinearComment(ctx, item));
267
+ }
268
+ function decodeLinearAgentSessions(ctx, data) {
269
+ return data.map((item) => new LinearAgentSession(ctx, item));
270
+ }
271
+ function decodeLinearTranscript(_ctx, data) {
272
+ return printsAs({ ...data }, data.text);
273
+ }
274
+ function decodeLinearCommentReplies(ctx, data) {
275
+ return data.map((item) => new LinearComment(ctx, item));
276
+ }
277
+ function decodeLinearAgentActivities(ctx, data) {
278
+ return data.map((item) => new LinearAgentActivity(ctx, item));
279
+ }
280
+ function decodeLinearDeliveries(ctx, data) {
281
+ return data.map((item) => new LinearDelivery(ctx, item));
282
+ }
283
+ function decodeNotionIntegrations(ctx, data) {
284
+ return data.map((item) => new NotionIntegration(ctx, item));
285
+ }
286
+ function decodeNotionUsers(ctx, data) {
287
+ return data.map((item) => new NotionUser(ctx, item));
288
+ }
289
+ function decodeNotionPages(ctx, data) {
290
+ return data.map((item) => new NotionPage(ctx, item));
291
+ }
292
+ function decodeNotionPropertyValue(ctx, data) {
293
+ return (data === null ? undefined : data);
294
+ }
295
+ function decodeNotionDiscussions(ctx, data) {
296
+ return data.map((item) => new NotionDiscussion(ctx, item));
297
+ }
298
+ function decodeNotionChildPages(ctx, data) {
299
+ return data.map((item) => new NotionPage(ctx, item));
300
+ }
301
+ function decodeNotionConnections(ctx, data) {
302
+ return data.map((item) => new NotionIntegration(ctx, item));
303
+ }
304
+ function decodeNotionTranscript(_ctx, data) {
305
+ return printsAs({ ...data }, data.text);
306
+ }
307
+ function decodeNotionRows(ctx, data) {
308
+ return data.map((item) => new NotionPage(ctx, item));
309
+ }
310
+ function decodeNotionComments(ctx, data) {
311
+ return data.map((item) => new NotionComment(ctx, item));
312
+ }
313
+ function decodeNotionDeliveries(ctx, data) {
314
+ return data.map((item) => new NotionDelivery(ctx, item));
315
+ }
316
+ function decodeResendApps(ctx, data) {
317
+ return data.map((item) => new ResendApp(ctx, item));
318
+ }
319
+ function decodeResendUsers(ctx, data) {
320
+ return data.map((item) => new ResendUser(ctx, item));
321
+ }
322
+ function decodeResendThreads(ctx, data) {
323
+ return data.map((item) => new ResendThread(ctx, item));
324
+ }
325
+ function decodeResendInbox(ctx, data) {
326
+ return data.map((item) => new ResendEmail(ctx, item));
327
+ }
328
+ function decodeResendMessages(ctx, data) {
329
+ return data.map((item) => new ResendEmail(ctx, item));
330
+ }
331
+ function decodeResendReplies(ctx, data) {
332
+ return data.map((item) => new ResendEmail(ctx, item));
333
+ }
334
+ function decodeResendTranscript(_ctx, data) {
335
+ return printsAs({ ...data }, data.text);
336
+ }
337
+ function decodeResendDeliveries(ctx, data) {
338
+ return data.map((item) => new ResendDelivery(ctx, item));
339
+ }
340
+ function decodeGoogleApps(ctx, data) {
341
+ return data.map((item) => new GoogleApp(ctx, item));
342
+ }
343
+ function decodeGoogleUsers(ctx, data) {
344
+ return data.map((item) => new GoogleUser(ctx, item));
345
+ }
346
+ function decodeGoogleThreads(ctx, data) {
347
+ return data.map((item) => new GoogleThread(ctx, item));
348
+ }
349
+ function decodeGoogleInbox(ctx, data) {
350
+ return data.map((item) => new GoogleEmail(ctx, item));
351
+ }
352
+ function decodeGoogleMessages(ctx, data) {
353
+ return data.map((item) => new GoogleEmail(ctx, item));
354
+ }
355
+ function decodeGoogleReplies(ctx, data) {
356
+ return data.map((item) => new GoogleEmail(ctx, item));
357
+ }
358
+ function decodeGoogleTranscript(_ctx, data) {
359
+ return printsAs({ ...data }, data.text);
360
+ }
361
+ function decodeGoogleDeliveries(ctx, data) {
362
+ return data.map((item) => new GoogleDelivery(ctx, item));
363
+ }
364
+ function decodeDiscordApps(ctx, data) {
365
+ return data.map((item) => new DiscordApp(ctx, item));
366
+ }
367
+ function decodeDiscordUsers(ctx, data) {
368
+ return data.map((item) => new DiscordUser(ctx, item));
369
+ }
370
+ function decodeDiscordChannels(ctx, data) {
371
+ return data.map((item) => new DiscordChannel(ctx, item));
372
+ }
373
+ function decodeDiscordEphemeralMessages(ctx, data) {
374
+ return data.map((item) => new DiscordMessage(ctx, item));
375
+ }
376
+ function decodeDiscordMessages(ctx, data) {
377
+ return data.map((item) => new DiscordMessage(ctx, item));
378
+ }
379
+ function decodeDiscordMembers(ctx, data) {
380
+ return data.map((item) => item.kind === "user" ? new DiscordUser(ctx, item) : new DiscordApp(ctx, item));
381
+ }
382
+ function decodeDiscordThreads(ctx, data) {
383
+ return data.map((item) => new DiscordChannel(ctx, item));
384
+ }
385
+ function decodeDiscordTranscript(_ctx, data) {
386
+ return printsAs({ ...data }, data.text);
387
+ }
388
+ function decodeDiscordReplies(ctx, data) {
389
+ return data.map((item) => new DiscordMessage(ctx, item));
390
+ }
391
+ function decodeDiscordReactions(ctx, data) {
392
+ return data.map((item) => decodeDiscordReaction(ctx, item));
393
+ }
394
+ function decodeDiscordReaction(ctx, data) {
395
+ return { ...data, by: data.by.map((item) => item.kind === "user" ? new DiscordUser(ctx, item) : new DiscordApp(ctx, item)) };
396
+ }
397
+ function decodeDiscordMessageDeliveries(ctx, data) {
398
+ return data.map((item) => new DiscordDelivery(ctx, item));
399
+ }
400
+ function decodeDiscordDeliveries(ctx, data) {
401
+ return data.map((item) => new DiscordDelivery(ctx, item));
402
+ }
403
+ function decodeOpenAICalls(ctx, data) {
404
+ return data.map((item) => new OpenAICall(ctx, item));
405
+ }
406
+ function decodeOpenAIPausedCalls(ctx, data) {
407
+ return data.map((item) => new OpenAICall(ctx, item));
408
+ }
409
+ function decodeOpenAISessionCalls(ctx, data) {
410
+ return data.map((item) => new OpenAICall(ctx, item));
411
+ }
412
+ function decodePlaces(ctx, data) {
413
+ return data.map((item) => new Place(ctx, item));
414
+ }
415
+ function decodePlaceTranscript(_ctx, data) {
416
+ return printsAs({ ...data }, data.text);
417
+ }
418
+ export class Channelstack extends ClientBase {
419
+ #ctx;
420
+ /** @internal Handles come from the SDK, never from `new`. */
421
+ constructor(transport, stop) {
422
+ super(stop);
423
+ this.#ctx = { transport, session: undefined };
424
+ }
425
+ /** Server health, version and loaded drivers. */
426
+ async status() {
427
+ const ctx = this.#ctx;
428
+ const data = (await ctx.transport.request("GET", `/status`));
429
+ return data;
430
+ }
431
+ /** Open a session: a scope in the shared world that owns what it creates. */
432
+ async openSession(options = {}) {
433
+ const ctx = this.#ctx;
434
+ const data = (await ctx.transport.request("POST", `/sessions`, { body: { name: options.name } }));
435
+ return new Session({ transport: ctx.transport, session: data.sessionId }, data);
436
+ }
437
+ /** Drop the whole world. Avoid in parallel suites. */
438
+ async reset() {
439
+ const ctx = this.#ctx;
440
+ await ctx.transport.request("POST", `/reset`);
441
+ }
442
+ /** 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. */
443
+ async env(options = {}) {
444
+ const ctx = this.#ctx;
445
+ const data = (await ctx.transport.request("GET", `/env`, { query: { proxy: options.proxy, app: options.app, channel: options.channel } }));
446
+ return data;
447
+ }
448
+ /** A new one-time link that opens the UI in a browser (what `channelstack ui` prints). Experimental. */
449
+ async uiLoginLink() {
450
+ const ctx = this.#ctx;
451
+ const data = (await ctx.transport.request("POST", `/ui/login-links`));
452
+ return data;
453
+ }
454
+ }
455
+ export class Session {
456
+ sessionId;
457
+ drivers;
458
+ #ctx;
459
+ /** @internal Handles come from the SDK, never from `new`. */
460
+ constructor(ctx, data) {
461
+ this.#ctx = ctx;
462
+ this.sessionId = data.sessionId;
463
+ this.drivers = data.drivers;
464
+ }
465
+ /** Close a session and remove everything it created. */
466
+ async close() {
467
+ const ctx = this.#ctx;
468
+ await ctx.transport.request("DELETE", `/sessions/${segment(sessionOf(ctx))}`);
469
+ }
470
+ async [Symbol.asyncDispose]() {
471
+ await disposeQuietly(() => this.close());
472
+ }
473
+ /** The session's event log: actions, deliveries with every attempt, and the agent's API calls. */
474
+ async events(options = {}) {
475
+ const ctx = this.#ctx;
476
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/events`, { query: { since: options.since } }));
477
+ return data;
478
+ }
479
+ /** Is the agent idle in this session, and for how long? Negative and exact-count matchers wait for this. */
480
+ async quiet() {
481
+ const ctx = this.#ctx;
482
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/quiet`));
483
+ return data;
484
+ }
485
+ /** The echo fixture: the agent's app and where it reaches the fake. Experimental. */
486
+ async echo() {
487
+ const ctx = this.#ctx;
488
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/echo`));
489
+ return new EchoFixture(ctx, data);
490
+ }
491
+ /** The Slack fixture: the agent's app, the workspace, and where the agent reaches the fake. Experimental. */
492
+ async slack() {
493
+ const ctx = this.#ctx;
494
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack`));
495
+ return new SlackFixture(ctx, data);
496
+ }
497
+ /** The GitHub fixture: the agent's App, the org, and where the agent reaches the fake. Experimental. */
498
+ async github() {
499
+ const ctx = this.#ctx;
500
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github`));
501
+ return new GitHubFixture(ctx, data);
502
+ }
503
+ /** The Linear fixture: the agent's app, and where the agent reaches the fake. Experimental. */
504
+ async linear() {
505
+ const ctx = this.#ctx;
506
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear`));
507
+ return new LinearFixture(ctx, data);
508
+ }
509
+ /** The Notion fixture: the agent's integration, and where the agent reaches the fake. Experimental. */
510
+ async notion() {
511
+ const ctx = this.#ctx;
512
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/notion`));
513
+ return new NotionFixture(ctx, data);
514
+ }
515
+ /** The Resend fixture: the agent's team, and where the agent reaches the fake. Experimental. */
516
+ async resend() {
517
+ const ctx = this.#ctx;
518
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/resend`));
519
+ return new ResendFixture(ctx, data);
520
+ }
521
+ /** The Google fixture: the agent's mailbox, and where the agent reaches the fake. Experimental. */
522
+ async google() {
523
+ const ctx = this.#ctx;
524
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/google`));
525
+ return new GoogleFixture(ctx, data);
526
+ }
527
+ /** The Discord fixture: the agent's app, the guild, and where the agent reaches the fake. Experimental. */
528
+ async discord() {
529
+ const ctx = this.#ctx;
530
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/discord`));
531
+ return new DiscordFixture(ctx, data);
532
+ }
533
+ /** The OpenAI fixture: where the agent reaches the fake model. Experimental. */
534
+ async openai() {
535
+ const ctx = this.#ctx;
536
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/openai`));
537
+ return new OpenAIFixture(ctx, data);
538
+ }
539
+ /** Every channel's places in the session, as the dev tools name them (a Slack channel, a GitHub issue, a Notion page, an email thread, a Discord channel), the most recently active last. Experimental. */
540
+ async places() {
541
+ const ctx = this.#ctx;
542
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/places`));
543
+ return decodePlaces(ctx, data);
544
+ }
545
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
546
+ [QUIET]() {
547
+ return quietOf(this.#ctx);
548
+ }
549
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
550
+ [CONTEXT]() {
551
+ return this.#ctx;
552
+ }
553
+ }
554
+ export class EchoFixture {
555
+ app;
556
+ apiUrl;
557
+ #ctx;
558
+ /** @internal Handles come from the SDK, never from `new`. */
559
+ constructor(ctx, data) {
560
+ this.#ctx = ctx;
561
+ this.app = new EchoApp(ctx, data.app);
562
+ this.apiUrl = data.apiUrl;
563
+ }
564
+ /** Create a person. Experimental. */
565
+ async createUser(options) {
566
+ const ctx = this.#ctx;
567
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/echo/users`, { body: { name: options.name } }));
568
+ return new EchoUser(ctx, data);
569
+ }
570
+ /** Make another app (decision 0027), or return the one with this name. Its events go to CHANNELSTACK_ECHO_APP_<NAME>_WEBHOOK_URL. Experimental. */
571
+ async createApp(options) {
572
+ const ctx = this.#ctx;
573
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/echo/apps`, { body: { name: options.name } }));
574
+ return new EchoApp(ctx, data);
575
+ }
576
+ /** The apps this session used: the built-in one first, then each it got from `createApp`, in the order it first did. Another session's are `not_found` here. Experimental. */
577
+ async apps() {
578
+ const ctx = this.#ctx;
579
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/echo/apps`));
580
+ return decodeEchoApps(ctx, data);
581
+ }
582
+ /** Create a room. Only the listed participants are members; include the app for it to receive events. Experimental. */
583
+ async createRoom(options = {}) {
584
+ const ctx = this.#ctx;
585
+ 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) } }));
586
+ return new EchoRoom(ctx, data);
587
+ }
588
+ /** Per action: works in the fake, works live, and what live needs. Experimental. */
589
+ async capabilities() {
590
+ const ctx = this.#ctx;
591
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/echo/capabilities`));
592
+ return data;
593
+ }
594
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
595
+ [QUIET]() {
596
+ return quietOf(this.#ctx);
597
+ }
598
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
599
+ [CONTEXT]() {
600
+ return this.#ctx;
601
+ }
602
+ }
603
+ export class EchoApp {
604
+ id;
605
+ name;
606
+ kind;
607
+ #ctx;
608
+ /** @internal Handles come from the SDK, never from `new`. */
609
+ constructor(ctx, data) {
610
+ this.#ctx = ctx;
611
+ this.id = data.id;
612
+ this.name = data.name;
613
+ this.kind = data.kind;
614
+ }
615
+ /** An app a test made posts in a room it is a member of, as its own call would. Experimental. */
616
+ async say(text, options) {
617
+ const ctx = this.#ctx;
618
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/echo/apps/${segment(this.id)}/say`, { body: { text, room: options.room.id } }));
619
+ return data;
620
+ }
621
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
622
+ [QUIET]() {
623
+ return quietOf(this.#ctx);
624
+ }
625
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
626
+ [CONTEXT]() {
627
+ return this.#ctx;
628
+ }
629
+ }
630
+ export class EchoUser {
631
+ id;
632
+ name;
633
+ kind;
634
+ #ctx;
635
+ /** @internal Handles come from the SDK, never from `new`. */
636
+ constructor(ctx, data) {
637
+ this.#ctx = ctx;
638
+ this.id = data.id;
639
+ this.name = data.name;
640
+ this.kind = data.kind;
641
+ }
642
+ /** Post a message in a room as this person. Experimental. */
643
+ async say(text, options) {
644
+ const ctx = this.#ctx;
645
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/echo/users/${segment(this.id)}/say`, { body: { text, room: options.room.id } }));
646
+ return data;
647
+ }
648
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
649
+ [QUIET]() {
650
+ return quietOf(this.#ctx);
651
+ }
652
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
653
+ [CONTEXT]() {
654
+ return this.#ctx;
655
+ }
656
+ }
657
+ export class EchoRoom {
658
+ id;
659
+ name;
660
+ members;
661
+ #ctx;
662
+ /** @internal Handles come from the SDK, never from `new`. */
663
+ constructor(ctx, data) {
664
+ this.#ctx = ctx;
665
+ this.id = data.id;
666
+ this.name = data.name;
667
+ this.members = data.members;
668
+ }
669
+ /** The room's messages, oldest first, with a cursor for the next read. Experimental. */
670
+ async messages(options = {}) {
671
+ const ctx = this.#ctx;
672
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/echo/rooms/${segment(this.id)}/messages`, { query: { since: options.since } }));
673
+ return data;
674
+ }
675
+ /** The room as a person would read it. Experimental. */
676
+ async transcript() {
677
+ const ctx = this.#ctx;
678
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/echo/rooms/${segment(this.id)}/transcript`));
679
+ return data;
680
+ }
681
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
682
+ [QUIET]() {
683
+ return quietOf(this.#ctx);
684
+ }
685
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
686
+ [CONTEXT]() {
687
+ return this.#ctx;
688
+ }
689
+ }
690
+ export class SlackFixture {
691
+ app;
692
+ apiUrl;
693
+ team;
694
+ socketConnections;
695
+ #ctx;
696
+ #seen = new Map();
697
+ /** @internal Handles come from the SDK, never from `new`. */
698
+ constructor(ctx, data) {
699
+ this.#ctx = ctx;
700
+ this.app = new SlackApp(ctx, data.app);
701
+ this.apiUrl = data.apiUrl;
702
+ this.team = data.team;
703
+ this.socketConnections = data.socketConnections;
704
+ }
705
+ /** Create a person in the workspace. Experimental. */
706
+ async createUser(options) {
707
+ const ctx = this.#ctx;
708
+ 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 } }));
709
+ return new SlackUser(ctx, data);
710
+ }
711
+ /** The people this session created. Experimental. */
712
+ async users() {
713
+ const ctx = this.#ctx;
714
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/users`));
715
+ return decodeSlackUsers(ctx, data);
716
+ }
717
+ /** Make another app in the workspace, with its own bot user, tokens and signing secret (decision 0027), or return the one made with this name and settings. Its events go to CHANNELSTACK_SLACK_APP_<NAME>_WEBHOOK_URL, or over its own Socket Mode connection. Experimental. */
718
+ async createApp(options) {
719
+ const ctx = this.#ctx;
720
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/apps`, { body: { name: options.name, scopes: options.scopes, botEvents: options.botEvents } }));
721
+ return new SlackApp(ctx, data);
722
+ }
723
+ /** The apps this session used: the built-in one first, then each it got from `createApp`, in the order it first did. Another session's are `not_found` here. Experimental. */
724
+ async apps() {
725
+ const ctx = this.#ctx;
726
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/apps`));
727
+ return decodeSlackApps(ctx, data);
728
+ }
729
+ /** The session's conversations, the one with the newest message last. Experimental. */
730
+ async conversations() {
731
+ const ctx = this.#ctx;
732
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/conversations`));
733
+ return decodeSlackConversations(ctx, data);
734
+ }
735
+ /** Create a channel. Only the listed participants are members; include the app for it to receive events. Experimental. */
736
+ async createChannel(options = {}) {
737
+ const ctx = this.#ctx;
738
+ 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 } }));
739
+ return new SlackConversation(ctx, data);
740
+ }
741
+ /** Every event channelstack sent the agent for this session, with every attempt. Experimental. */
742
+ async deliveries(options = {}) {
743
+ const ctx = this.#ctx;
744
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/deliveries`, { query: { app: options.app === undefined ? undefined : options.app.id } }));
745
+ return decodeSlackDeliveries(ctx, data);
746
+ }
747
+ /** 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. */
748
+ async calls(options = {}) {
749
+ const ctx = this.#ctx;
750
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/calls`, { query: { operation: options.operation, error: options.error } }));
751
+ return data;
752
+ }
753
+ /** The workspace uninstalls an app: the built-in one, or the one given. Undone when this session closes; run such tests on their own. Experimental. */
754
+ async uninstallApp(options = {}) {
755
+ const ctx = this.#ctx;
756
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/uninstall`, { body: { app: options.app === undefined ? undefined : options.app.id } }));
757
+ return decodeSlackUninstallDeliveries(ctx, data);
758
+ }
759
+ /** Inject a fault: into the agent's Web API calls (removed when this session closes), or drop its Socket Mode connection once. Experimental. */
760
+ async fault(options) {
761
+ const ctx = this.#ctx;
762
+ 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, app: options.app === undefined ? undefined : options.app.id } }));
763
+ return new SlackFault(ctx, data);
764
+ }
765
+ /** Wait for the next new API call from the agent, after the last one this handle saw. */
766
+ async waitForCall(filter = {}, options = {}) {
767
+ return waitForNext(this.#seen, `waitForCall:${JSON.stringify(filter)}`, () => this.calls(filter), () => true, "an API call from the agent", options);
768
+ }
769
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
770
+ [QUIET]() {
771
+ return quietOf(this.#ctx);
772
+ }
773
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
774
+ [CONTEXT]() {
775
+ return this.#ctx;
776
+ }
777
+ }
778
+ export class SlackApp {
779
+ id;
780
+ name;
781
+ kind;
782
+ botUserId;
783
+ botId;
784
+ botToken;
785
+ appToken;
786
+ signingSecret;
787
+ scopes;
788
+ #ctx;
789
+ /** @internal Handles come from the SDK, never from `new`. */
790
+ constructor(ctx, data) {
791
+ this.#ctx = ctx;
792
+ this.id = data.id;
793
+ this.name = data.name;
794
+ this.kind = data.kind;
795
+ this.botUserId = data.botUserId;
796
+ this.botId = data.botId;
797
+ this.botToken = data.botToken;
798
+ this.appToken = data.appToken;
799
+ this.signingSecret = data.signingSecret;
800
+ this.scopes = data.scopes;
801
+ }
802
+ /** An app a test made writes a top-level message, as its own chat.postMessage would: in a conversation it is a member of, or in a DM with the people in `to`. Experimental. */
803
+ async say(message, options = {}) {
804
+ const ctx = this.#ctx;
805
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/apps/${segment(this.id)}/say`, { body: { message: typeof message === "string" ? { text: 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) } }));
806
+ return new SlackMessage(ctx, data);
807
+ }
808
+ /** An app a test made replies in a thread: pass the message that starts it, or any reply in it. Experimental. */
809
+ async reply(message, options) {
810
+ const ctx = this.#ctx;
811
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/apps/${segment(this.id)}/reply`, { body: { message: typeof message === "string" ? { text: message } : (typeof message === "string" ? { text: message } : message), thread: { channel: options.thread.channel, ts: options.thread.ts } } }));
812
+ return new SlackMessage(ctx, data);
813
+ }
814
+ /** An app a test made reacts to a message. Experimental. */
815
+ async react(emoji, options) {
816
+ const ctx = this.#ctx;
817
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/apps/${segment(this.id)}/react`, { body: { emoji, message: { channel: options.message.channel, ts: options.message.ts } } }));
818
+ return (data === null ? undefined : new SlackDelivery(ctx, data));
819
+ }
820
+ /** An app a test made takes its reaction back. Experimental. */
821
+ async unreact(emoji, options) {
822
+ const ctx = this.#ctx;
823
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/apps/${segment(this.id)}/unreact`, { body: { emoji, message: { channel: options.message.channel, ts: options.message.ts } } }));
824
+ return (data === null ? undefined : new SlackDelivery(ctx, data));
825
+ }
826
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
827
+ [QUIET]() {
828
+ return quietOf(this.#ctx);
829
+ }
830
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
831
+ [CONTEXT]() {
832
+ return this.#ctx;
833
+ }
834
+ }
835
+ export class SlackUser {
836
+ id;
837
+ name;
838
+ kind;
839
+ displayName;
840
+ realName;
841
+ email;
842
+ isAdmin;
843
+ isBot;
844
+ #ctx;
845
+ #seen = new Map();
846
+ /** @internal Handles come from the SDK, never from `new`. */
847
+ constructor(ctx, data) {
848
+ this.#ctx = ctx;
849
+ this.id = data.id;
850
+ this.name = data.name;
851
+ this.kind = data.kind;
852
+ this.displayName = data.displayName;
853
+ this.realName = data.realName;
854
+ this.email = data.email;
855
+ this.isAdmin = data.isAdmin;
856
+ this.isBot = data.isBot;
857
+ }
858
+ /** Post a top-level message in a conversation, or in a DM with the people in `to`. Experimental. */
859
+ async say(message, options = {}) {
860
+ const ctx = this.#ctx;
861
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/users/${segment(this.id)}/say`, { body: { message: typeof message === "string" ? { text: 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) } }));
862
+ return new SlackMessage(ctx, data);
863
+ }
864
+ /** Reply in a thread: pass the message that starts it, or any reply in it. Experimental. */
865
+ async reply(message, options) {
866
+ const ctx = this.#ctx;
867
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/users/${segment(this.id)}/reply`, { body: { message: typeof message === "string" ? { text: 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) } }));
868
+ return new SlackMessage(ctx, data);
869
+ }
870
+ /** Edit one of this person's own messages. Experimental. */
871
+ async edit(text, options) {
872
+ const ctx = this.#ctx;
873
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/users/${segment(this.id)}/edit`, { body: { text: typeof text === "string" ? { text: text } : (typeof text === "string" ? { text: text } : text), message: { channel: options.message.channel, ts: options.message.ts } } }));
874
+ return new SlackMessage(ctx, data);
875
+ }
876
+ /** Delete a message: this person's own, or anyone's for an admin. Experimental. */
877
+ async delete(options) {
878
+ const ctx = this.#ctx;
879
+ 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 } } });
880
+ }
881
+ /** 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. */
882
+ async click(button, options = {}) {
883
+ const ctx = this.#ctx;
884
+ 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 } : (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 } })));
885
+ return (data === null ? undefined : new SlackDelivery(ctx, data));
886
+ }
887
+ /** Choose from a select menu on a message: options by their text or value, the menu by its placeholder or action_id. Experimental. */
888
+ async select(option, options) {
889
+ const ctx = this.#ctx;
890
+ 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 } : (typeof options.menu === "string" ? { label: options.menu } : options.menu), message: { channel: options.message.channel, ts: options.message.ts } } })));
891
+ return new SlackDelivery(ctx, data);
892
+ }
893
+ /** Run an app's message shortcut on a message: it goes to that app alone. Experimental. */
894
+ async shortcut(callbackId, options) {
895
+ const ctx = this.#ctx;
896
+ 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 }, app: options.app === undefined ? undefined : options.app.id } }));
897
+ return new SlackDelivery(ctx, data);
898
+ }
899
+ /** Run an app's slash command in a conversation, e.g. `/deploy web staging`: it goes to that app alone. Experimental. */
900
+ async runCommand(command, options) {
901
+ const ctx = this.#ctx;
902
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/users/${segment(this.id)}/commands`, { body: { command, channel: options.channel.id, app: options.app === undefined ? undefined : options.app.id } }));
903
+ return new SlackDelivery(ctx, data);
904
+ }
905
+ /** Press Stop on the app's work in a thread: what is streaming there ends, and the app is told. Experimental. */
906
+ async stop(options) {
907
+ const ctx = this.#ctx;
908
+ 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 } } }));
909
+ return new SlackDelivery(ctx, data);
910
+ }
911
+ /** Open an app's split view: a new thread in this person's DM with that app, started from the channel they are looking at. Experimental. */
912
+ async openAgentThread(options = {}) {
913
+ const ctx = this.#ctx;
914
+ 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, app: options.app === undefined ? undefined : options.app.id } }));
915
+ return new SlackThread(ctx, data);
916
+ }
917
+ /** Pick one of the prompts the app suggested in a thread: this person says its message there. Experimental. */
918
+ async pickPrompt(title, options) {
919
+ const ctx = this.#ctx;
920
+ 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 } } })));
921
+ return new SlackMessage(ctx, data);
922
+ }
923
+ /** Look at another channel while the split view stays open: the app is told the new context. Experimental. */
924
+ async switchContext(channel, options) {
925
+ const ctx = this.#ctx;
926
+ 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 } } }));
927
+ return new SlackDelivery(ctx, data);
928
+ }
929
+ /** The modals the app opened for this person, in the order it opened them; `open` says which are still up. Experimental. */
930
+ async modals() {
931
+ const ctx = this.#ctx;
932
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/users/${segment(this.id)}/modals`));
933
+ return decodeSlackModals(ctx, data);
934
+ }
935
+ /** Add an emoji reaction to a message. Experimental. */
936
+ async react(emoji, options) {
937
+ const ctx = this.#ctx;
938
+ 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 } } }));
939
+ return (data === null ? undefined : new SlackDelivery(ctx, data));
940
+ }
941
+ /** Remove this person's emoji reaction from a message. Experimental. */
942
+ async unreact(emoji, options) {
943
+ const ctx = this.#ctx;
944
+ 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 } } }));
945
+ return (data === null ? undefined : new SlackDelivery(ctx, data));
946
+ }
947
+ /** Open (or reuse) a DM with the app, another person, or several. Experimental. */
948
+ async openDM(participants) {
949
+ const ctx = this.#ctx;
950
+ 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) } }));
951
+ return new SlackConversation(ctx, data);
952
+ }
953
+ /** Invite people or the app to a channel. Experimental. */
954
+ async invite(participants, options) {
955
+ const ctx = this.#ctx;
956
+ 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 } });
957
+ }
958
+ /** Remove someone from a channel. Experimental. */
959
+ async kick(participant, options) {
960
+ const ctx = this.#ctx;
961
+ await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/users/${segment(this.id)}/kick`, { body: { participant: participant.id, channel: options.channel.id } });
962
+ }
963
+ /** Messages only this person can see. Experimental. */
964
+ async ephemeral() {
965
+ const ctx = this.#ctx;
966
+ await untilQuiet(() => quietOf(ctx));
967
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/users/${segment(this.id)}/ephemeral`));
968
+ return decodeSlackEphemeralMessages(ctx, data);
969
+ }
970
+ /** Wait for the next new open modal from the agent, after the last one this handle saw. */
971
+ async waitForModal(options = {}) {
972
+ return waitForNext(this.#seen, "waitForModal", () => this.modals(), (item) => textMatches(item.title, options.title) && item.open === true, "an open modal from the agent", options);
973
+ }
974
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
975
+ [QUIET]() {
976
+ return quietOf(this.#ctx);
977
+ }
978
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
979
+ [CONTEXT]() {
980
+ return this.#ctx;
981
+ }
982
+ }
983
+ export class SlackMessage {
984
+ channel;
985
+ ts;
986
+ conversation;
987
+ author;
988
+ text;
989
+ blocks;
990
+ files;
991
+ postedAt;
992
+ threadTs;
993
+ edited;
994
+ visibleTo;
995
+ thread;
996
+ delivery;
997
+ stream;
998
+ #ctx;
999
+ /** @internal Handles come from the SDK, never from `new`. */
1000
+ constructor(ctx, data) {
1001
+ this.#ctx = ctx;
1002
+ this.channel = data.channel;
1003
+ this.ts = data.ts;
1004
+ this.conversation = new SlackConversation(ctx, data.conversation);
1005
+ this.author = data.author.kind === "user" ? new SlackUser(ctx, data.author) : new SlackApp(ctx, data.author);
1006
+ this.text = data.text;
1007
+ this.blocks = data.blocks;
1008
+ this.files = data.files;
1009
+ this.postedAt = data.postedAt;
1010
+ this.threadTs = data.threadTs;
1011
+ this.edited = data.edited;
1012
+ this.visibleTo = data.visibleTo === undefined ? undefined : new SlackUser(ctx, data.visibleTo);
1013
+ this.thread = new SlackThread(ctx, data.thread);
1014
+ this.delivery = data.delivery === undefined ? undefined : new SlackDelivery(ctx, data.delivery);
1015
+ this.stream = data.stream === undefined ? undefined : new SlackStream(ctx, data.stream);
1016
+ }
1017
+ /** Re-read a message: its latest text, edits and deliveries. Experimental. */
1018
+ async refresh() {
1019
+ const ctx = this.#ctx;
1020
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/conversations/${segment(this.channel)}/messages/${segment(this.ts)}`));
1021
+ return new SlackMessage(ctx, data);
1022
+ }
1023
+ /** The reactions on a message, and who added each. Experimental. */
1024
+ async reactions() {
1025
+ const ctx = this.#ctx;
1026
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/conversations/${segment(this.channel)}/messages/${segment(this.ts)}/reactions`));
1027
+ return decodeSlackReactions(ctx, data);
1028
+ }
1029
+ /** A message and the replies under it as a person would read them. Experimental. */
1030
+ async transcript(options = {}) {
1031
+ const ctx = this.#ctx;
1032
+ 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 } }));
1033
+ return decodeSlackTranscript(ctx, data);
1034
+ }
1035
+ /** The first delivery this message caused to this app (decision 0027), or nothing when it wasn't told. Experimental. */
1036
+ async deliveryFor(app) {
1037
+ const ctx = this.#ctx;
1038
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/conversations/${segment(this.channel)}/messages/${segment(this.ts)}/delivery-for`, { query: { app: app.id } }));
1039
+ return (data === null ? undefined : new SlackDelivery(ctx, data));
1040
+ }
1041
+ /** Every delivery this message caused to the agent. Experimental. */
1042
+ async deliveries() {
1043
+ const ctx = this.#ctx;
1044
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/conversations/${segment(this.channel)}/messages/${segment(this.ts)}/deliveries`));
1045
+ return decodeSlackMessageDeliveries(ctx, data);
1046
+ }
1047
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
1048
+ [QUIET]() {
1049
+ return quietOf(this.#ctx);
1050
+ }
1051
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
1052
+ [CONTEXT]() {
1053
+ return this.#ctx;
1054
+ }
1055
+ }
1056
+ export class SlackConversation {
1057
+ id;
1058
+ kind;
1059
+ name;
1060
+ #ctx;
1061
+ #seen = new Map();
1062
+ /** @internal Handles come from the SDK, never from `new`. */
1063
+ constructor(ctx, data) {
1064
+ this.#ctx = ctx;
1065
+ this.id = data.id;
1066
+ this.kind = data.kind;
1067
+ this.name = data.name;
1068
+ }
1069
+ /** The newest message of a conversation, replies included. Experimental. */
1070
+ async latestMessage() {
1071
+ const ctx = this.#ctx;
1072
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/conversations/${segment(this.id)}/latest`));
1073
+ return new SlackMessage(ctx, data);
1074
+ }
1075
+ /** Top-level messages of a conversation, oldest first. Experimental. */
1076
+ async messages() {
1077
+ const ctx = this.#ctx;
1078
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/conversations/${segment(this.id)}/messages`));
1079
+ return decodeSlackMessages(ctx, data);
1080
+ }
1081
+ /** The people and apps in a conversation. Experimental. */
1082
+ async members() {
1083
+ const ctx = this.#ctx;
1084
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/conversations/${segment(this.id)}/members`));
1085
+ return decodeSlackMembers(ctx, data);
1086
+ }
1087
+ /** The conversation as a person would read it, threads included. Experimental. */
1088
+ async transcript(options = {}) {
1089
+ const ctx = this.#ctx;
1090
+ 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 } }));
1091
+ return decodeSlackTranscript(ctx, data);
1092
+ }
1093
+ /** Wait for the next new message matching `from` (anyone if omitted), after the last one this handle saw. */
1094
+ async waitForMessage(options = {}) {
1095
+ return waitForNext(this.#seen, "waitForMessage", () => this.messages(), (item) => fromMatches(item.author, options.from), describeWait("a message", options.from), options);
1096
+ }
1097
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
1098
+ [QUIET]() {
1099
+ return quietOf(this.#ctx);
1100
+ }
1101
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
1102
+ [CONTEXT]() {
1103
+ return this.#ctx;
1104
+ }
1105
+ }
1106
+ export class SlackThread {
1107
+ channel;
1108
+ ts;
1109
+ conversation;
1110
+ #ctx;
1111
+ #seen = new Map();
1112
+ /** @internal Handles come from the SDK, never from `new`. */
1113
+ constructor(ctx, data) {
1114
+ this.#ctx = ctx;
1115
+ this.channel = data.channel;
1116
+ this.ts = data.ts;
1117
+ this.conversation = new SlackConversation(ctx, data.conversation);
1118
+ }
1119
+ /** The prompts the app suggested in a thread. Experimental. */
1120
+ async suggestedPrompts() {
1121
+ const ctx = this.#ctx;
1122
+ await untilQuiet(() => quietOf(ctx));
1123
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/conversations/${segment(this.channel)}/threads/${segment(this.ts)}/suggested-prompts`));
1124
+ return data;
1125
+ }
1126
+ /** The message that starts a thread, as it is now. Experimental. */
1127
+ async root() {
1128
+ const ctx = this.#ctx;
1129
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/conversations/${segment(this.channel)}/threads/${segment(this.ts)}`));
1130
+ return new SlackMessage(ctx, data);
1131
+ }
1132
+ /** Replies in a thread, oldest first, without the message that starts it. Experimental. */
1133
+ async replies() {
1134
+ const ctx = this.#ctx;
1135
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/conversations/${segment(this.channel)}/threads/${segment(this.ts)}/replies`));
1136
+ return decodeSlackReplies(ctx, data);
1137
+ }
1138
+ /** What the agent is doing in a thread: its status line, an open stream, or idle. Experimental. */
1139
+ async status() {
1140
+ const ctx = this.#ctx;
1141
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/conversations/${segment(this.channel)}/threads/${segment(this.ts)}/state`));
1142
+ return data;
1143
+ }
1144
+ /** A thread as a person would read it. Experimental. */
1145
+ async transcript(options = {}) {
1146
+ const ctx = this.#ctx;
1147
+ 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 } }));
1148
+ return decodeSlackTranscript(ctx, data);
1149
+ }
1150
+ /** Wait for the next new reply matching `from` (anyone if omitted), after the last one this handle saw. */
1151
+ async waitForReply(options = {}) {
1152
+ return waitForNext(this.#seen, "waitForReply", () => this.replies(), (item) => fromMatches(item.author, options.from), describeWait("a reply", options.from), options);
1153
+ }
1154
+ /** The latest reply matching `from`, once the agent is quiet. Waits for at least one. */
1155
+ async latestReply(options = {}) {
1156
+ return latestOnceQuiet(() => this.replies(), (item) => fromMatches(item.author, options.from), () => quietOf(this.#ctx), describeWait("a reply", options.from), options);
1157
+ }
1158
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
1159
+ [QUIET]() {
1160
+ return quietOf(this.#ctx);
1161
+ }
1162
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
1163
+ [CONTEXT]() {
1164
+ return this.#ctx;
1165
+ }
1166
+ }
1167
+ export class SlackDelivery {
1168
+ id;
1169
+ channel;
1170
+ app;
1171
+ type;
1172
+ eventType;
1173
+ eventId;
1174
+ payload;
1175
+ attempts;
1176
+ status;
1177
+ #ctx;
1178
+ /** @internal Handles come from the SDK, never from `new`. */
1179
+ constructor(ctx, data) {
1180
+ this.#ctx = ctx;
1181
+ this.id = data.id;
1182
+ this.channel = data.channel;
1183
+ this.app = data.app;
1184
+ this.type = data.type;
1185
+ this.eventType = data.eventType;
1186
+ this.eventId = data.eventId;
1187
+ this.payload = data.payload;
1188
+ this.attempts = data.attempts;
1189
+ this.status = data.status;
1190
+ }
1191
+ /** Re-read a delivery: its attempts and status. Experimental. */
1192
+ async refresh() {
1193
+ const ctx = this.#ctx;
1194
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/deliveries/${segment(this.id)}`));
1195
+ return new SlackDelivery(ctx, data);
1196
+ }
1197
+ /** Send the delivery again, unchanged or forged: a wrong signature, or a timestamp outside the replay window. Experimental. */
1198
+ async resend(options = {}) {
1199
+ const ctx = this.#ctx;
1200
+ 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 } }));
1201
+ return data;
1202
+ }
1203
+ /** Retry the way Slack does: the same payload, with X-Slack-Retry-Num and X-Slack-Retry-Reason. Experimental. */
1204
+ async retry(options = {}) {
1205
+ const ctx = this.#ctx;
1206
+ 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 } }));
1207
+ return data;
1208
+ }
1209
+ /** Wait for the delivery to settle, and resolve with the value as it is then. */
1210
+ async settled(options = {}) {
1211
+ return waitFor("the delivery to settle", async () => {
1212
+ const value = await this.refresh();
1213
+ return value.status === "pending" ? undefined : value;
1214
+ }, options);
1215
+ }
1216
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
1217
+ [QUIET]() {
1218
+ return quietOf(this.#ctx);
1219
+ }
1220
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
1221
+ [CONTEXT]() {
1222
+ return this.#ctx;
1223
+ }
1224
+ }
1225
+ export class SlackStream {
1226
+ channel;
1227
+ ts;
1228
+ state;
1229
+ chunks;
1230
+ startedAt;
1231
+ endedAt;
1232
+ #ctx;
1233
+ /** @internal Handles come from the SDK, never from `new`. */
1234
+ constructor(ctx, data) {
1235
+ this.#ctx = ctx;
1236
+ this.channel = data.channel;
1237
+ this.ts = data.ts;
1238
+ this.state = data.state;
1239
+ this.chunks = data.chunks;
1240
+ this.startedAt = data.startedAt;
1241
+ this.endedAt = data.endedAt;
1242
+ }
1243
+ /** Re-read a streamed message's stream: its state and what was streamed so far. Experimental. */
1244
+ async refresh() {
1245
+ const ctx = this.#ctx;
1246
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/conversations/${segment(this.channel)}/messages/${segment(this.ts)}/stream`));
1247
+ return new SlackStream(ctx, data);
1248
+ }
1249
+ /** Wait for the stream to end, and resolve with the value as it is then. */
1250
+ async ended(options = {}) {
1251
+ return waitFor("the stream to end", async () => {
1252
+ const value = await this.refresh();
1253
+ return value.state === "open" ? undefined : value;
1254
+ }, options);
1255
+ }
1256
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
1257
+ [QUIET]() {
1258
+ return quietOf(this.#ctx);
1259
+ }
1260
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
1261
+ [CONTEXT]() {
1262
+ return this.#ctx;
1263
+ }
1264
+ }
1265
+ export class SlackModal {
1266
+ viewId;
1267
+ user;
1268
+ title;
1269
+ blocks;
1270
+ open;
1271
+ errors;
1272
+ #ctx;
1273
+ /** @internal Handles come from the SDK, never from `new`. */
1274
+ constructor(ctx, data) {
1275
+ this.#ctx = ctx;
1276
+ this.viewId = data.viewId;
1277
+ this.user = new SlackUser(ctx, data.user);
1278
+ this.title = data.title;
1279
+ this.blocks = data.blocks;
1280
+ this.open = data.open;
1281
+ this.errors = data.errors;
1282
+ }
1283
+ /** What is filled in: each input by its label (or action_id), with the text a person sees in it. Experimental. */
1284
+ async values() {
1285
+ const ctx = this.#ctx;
1286
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/slack/modals/${segment(this.viewId)}/values`));
1287
+ return decodeSlackModalValues(ctx, data);
1288
+ }
1289
+ /** Fill in inputs, by label or `block_id.action_id`, and submit the modal. Experimental. */
1290
+ async submit(values) {
1291
+ const ctx = this.#ctx;
1292
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/modals/${segment(this.viewId)}/submit`, { body: { values } }));
1293
+ return new SlackDelivery(ctx, data);
1294
+ }
1295
+ /** Close the modal. The app is told only if it asked to be (`notify_on_close`). Experimental. */
1296
+ async close() {
1297
+ const ctx = this.#ctx;
1298
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/slack/modals/${segment(this.viewId)}/close`));
1299
+ return (data === null ? undefined : new SlackDelivery(ctx, data));
1300
+ }
1301
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
1302
+ [QUIET]() {
1303
+ return quietOf(this.#ctx);
1304
+ }
1305
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
1306
+ [CONTEXT]() {
1307
+ return this.#ctx;
1308
+ }
1309
+ }
1310
+ export class SlackFault {
1311
+ id;
1312
+ #ctx;
1313
+ /** @internal Handles come from the SDK, never from `new`. */
1314
+ constructor(ctx, data) {
1315
+ this.#ctx = ctx;
1316
+ this.id = data.id;
1317
+ }
1318
+ /** Remove a fault. Experimental. */
1319
+ async undo() {
1320
+ const ctx = this.#ctx;
1321
+ await ctx.transport.request("DELETE", `/sessions/${segment(sessionOf(ctx))}/slack/faults/${segment(this.id)}`);
1322
+ }
1323
+ async [Symbol.asyncDispose]() {
1324
+ await disposeQuietly(() => this.undo());
1325
+ }
1326
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
1327
+ [QUIET]() {
1328
+ return quietOf(this.#ctx);
1329
+ }
1330
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
1331
+ [CONTEXT]() {
1332
+ return this.#ctx;
1333
+ }
1334
+ }
1335
+ export class GitHubFixture {
1336
+ app;
1337
+ apiUrl;
1338
+ org;
1339
+ #ctx;
1340
+ #seen = new Map();
1341
+ /** @internal Handles come from the SDK, never from `new`. */
1342
+ constructor(ctx, data) {
1343
+ this.#ctx = ctx;
1344
+ this.app = new GitHubApp(ctx, data.app);
1345
+ this.apiUrl = data.apiUrl;
1346
+ this.org = data.org;
1347
+ }
1348
+ /** Create a person in the org. Experimental. */
1349
+ async createUser(options) {
1350
+ const ctx = this.#ctx;
1351
+ 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 }) } }));
1352
+ return new GitHubUser(ctx, data);
1353
+ }
1354
+ /** The people this session created. Experimental. */
1355
+ async users() {
1356
+ const ctx = this.#ctx;
1357
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/users`));
1358
+ return decodeGitHubUsers(ctx, data);
1359
+ }
1360
+ /** 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. */
1361
+ async createRepo(options = {}) {
1362
+ const ctx = this.#ctx;
1363
+ 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)) } }));
1364
+ return new GitHubRepo(ctx, data);
1365
+ }
1366
+ /** The repositories this session created. Experimental. */
1367
+ async repos() {
1368
+ const ctx = this.#ctx;
1369
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos`));
1370
+ return decodeGitHubRepos(ctx, data);
1371
+ }
1372
+ /** The issues and pull requests in this session's repositories, read again from GitHub live, the most recently updated last. Experimental. */
1373
+ async issues() {
1374
+ const ctx = this.#ctx;
1375
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/issues`));
1376
+ return decodeGitHubIssues(ctx, data);
1377
+ }
1378
+ /** The id of the built-in App's installation, for a repository it is installed on. The same as `github.app.installationId(repo)`. Experimental. */
1379
+ async installationId(repo) {
1380
+ const ctx = this.#ctx;
1381
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/installation-id`, { body: { repo: repo.id } }));
1382
+ return data;
1383
+ }
1384
+ /** Make another GitHub App on the org, with its own App id, bot user, installation, private key and webhook secret (decision 0027), or return the one made with this name and settings. It reaches no repository until it is installed on one; its webhooks go to CHANNELSTACK_GITHUB_APP_<NAME>_WEBHOOK_URL. Experimental. */
1385
+ async createApp(options) {
1386
+ const ctx = this.#ctx;
1387
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/apps`, { body: { name: options.name, permissions: options.permissions, events: options.events } }));
1388
+ return new GitHubApp(ctx, data);
1389
+ }
1390
+ /** The Apps this session used: the built-in one first, then each it got from `createApp`, in the order it first did. Another session's are `not_found` here. Experimental. */
1391
+ async apps() {
1392
+ const ctx = this.#ctx;
1393
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/apps`));
1394
+ return decodeGitHubApps(ctx, data);
1395
+ }
1396
+ /** Every webhook channelstack sent the agent for this session, with every attempt. Experimental. */
1397
+ async deliveries(options = {}) {
1398
+ const ctx = this.#ctx;
1399
+ 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, app: options.app === undefined ? undefined : options.app.id } }));
1400
+ return decodeGitHubDeliveries(ctx, data);
1401
+ }
1402
+ /** The REST calls the agent made about this session's repositories. Calls about no repository (`GET /app`) are in no session. Experimental. */
1403
+ async calls(options = {}) {
1404
+ const ctx = this.#ctx;
1405
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/calls`, { query: { operation: options.operation, error: options.error } }));
1406
+ return data;
1407
+ }
1408
+ /** 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. */
1409
+ async appCalls(options = {}) {
1410
+ const ctx = this.#ctx;
1411
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/app-calls`, { query: { operation: options.operation, error: options.error } }));
1412
+ return data;
1413
+ }
1414
+ /** Wait for the next new API call from the agent, after the last one this handle saw. */
1415
+ async waitForCall(filter = {}, options = {}) {
1416
+ return waitForNext(this.#seen, `waitForCall:${JSON.stringify(filter)}`, () => this.calls(filter), () => true, "an API call from the agent", options);
1417
+ }
1418
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
1419
+ [QUIET]() {
1420
+ return quietOf(this.#ctx);
1421
+ }
1422
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
1423
+ [CONTEXT]() {
1424
+ return this.#ctx;
1425
+ }
1426
+ }
1427
+ export class GitHubApp {
1428
+ id;
1429
+ name;
1430
+ kind;
1431
+ slug;
1432
+ botLogin;
1433
+ botUserId;
1434
+ appId;
1435
+ privateKey;
1436
+ webhookSecret;
1437
+ #ctx;
1438
+ /** @internal Handles come from the SDK, never from `new`. */
1439
+ constructor(ctx, data) {
1440
+ this.#ctx = ctx;
1441
+ this.id = data.id;
1442
+ this.name = data.name;
1443
+ this.kind = data.kind;
1444
+ this.slug = data.slug;
1445
+ this.botLogin = data.botLogin;
1446
+ this.botUserId = data.botUserId;
1447
+ this.appId = data.appId;
1448
+ this.privateKey = data.privateKey;
1449
+ this.webhookSecret = data.webhookSecret;
1450
+ }
1451
+ /** The id of this App's installation, for a repository it is installed on. Experimental. */
1452
+ async installationId(repo) {
1453
+ const ctx = this.#ctx;
1454
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/apps/${segment(this.id)}/installation-id`, { body: { repo: repo.id } }));
1455
+ return data;
1456
+ }
1457
+ /** 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. */
1458
+ async push(changes, options) {
1459
+ const ctx = this.#ctx;
1460
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/apps/${segment(this.id)}/push`, { body: { changes: readChanges(changes), repo: options.repo.id, branch: options.branch, message: options.message } }));
1461
+ return new GitHubCommit(ctx, data);
1462
+ }
1463
+ /** Open an issue. Sends `issues` (action `opened`). Experimental. */
1464
+ async openIssue(issue, options) {
1465
+ const ctx = this.#ctx;
1466
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/apps/${segment(this.id)}/issues`, { body: { issue: { ...issue, assignees: issue.assignees === undefined ? undefined : issue.assignees.map((item) => item.id) }, repo: options.repo.id } }));
1467
+ return new GitHubIssue(ctx, data);
1468
+ }
1469
+ /** Open a pull request. With `changes`, they are pushed to `from` first; without, `from` is an existing branch. Sends `pull_request` (action `opened`). Experimental. */
1470
+ async openPullRequest(pr, options) {
1471
+ const ctx = this.#ctx;
1472
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/apps/${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 } }));
1473
+ return new GitHubPullRequest(ctx, data);
1474
+ }
1475
+ /** Edit the title or the body of an issue or a pull request. Sends `issues` or `pull_request` (action `edited`). Experimental. */
1476
+ async editIssue(changes, options) {
1477
+ const ctx = this.#ctx;
1478
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/apps/${segment(this.id)}/edit-issue`, { body: { changes, issue: { repoId: options.issue.repoId, number: options.issue.number } } }));
1479
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1480
+ }
1481
+ /** Close an issue or a pull request. Sends `issues` or `pull_request` (action `closed`). Experimental. */
1482
+ async close(options) {
1483
+ const ctx = this.#ctx;
1484
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/apps/${segment(this.id)}/close`, { body: { issue: { repoId: options.issue.repoId, number: options.issue.number } } }));
1485
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1486
+ }
1487
+ /** Reopen an issue or a pull request. Sends `issues` or `pull_request` (action `reopened`). Experimental. */
1488
+ async reopen(options) {
1489
+ const ctx = this.#ctx;
1490
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/apps/${segment(this.id)}/reopen`, { body: { issue: { repoId: options.issue.repoId, number: options.issue.number } } }));
1491
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1492
+ }
1493
+ /** Put labels on an issue or a pull request. Sends one `labeled` event per label. Experimental. */
1494
+ async label(labels, options) {
1495
+ const ctx = this.#ctx;
1496
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/apps/${segment(this.id)}/label`, { body: { labels: [labels].flat(), issue: { repoId: options.issue.repoId, number: options.issue.number } } }));
1497
+ return decodeGitHubLabelDeliveries(ctx, data);
1498
+ }
1499
+ /** Take labels off an issue or a pull request. Sends one `unlabeled` event per label. Experimental. */
1500
+ async unlabel(labels, options) {
1501
+ const ctx = this.#ctx;
1502
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/apps/${segment(this.id)}/unlabel`, { body: { labels: [labels].flat(), issue: { repoId: options.issue.repoId, number: options.issue.number } } }));
1503
+ return decodeGitHubUnlabelDeliveries(ctx, data);
1504
+ }
1505
+ /** Assign people or the App's bot. Sends one `assigned` event per assignee. Experimental. */
1506
+ async assign(assignees, options) {
1507
+ const ctx = this.#ctx;
1508
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/apps/${segment(this.id)}/assign`, { body: { assignees: [assignees].flat().map((item) => item.id), issue: { repoId: options.issue.repoId, number: options.issue.number } } }));
1509
+ return decodeGitHubAssignDeliveries(ctx, data);
1510
+ }
1511
+ /** Comment on an issue or a pull request's conversation. Sends `issue_comment` (action `created`). Experimental. */
1512
+ async comment(body, options) {
1513
+ const ctx = this.#ctx;
1514
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/apps/${segment(this.id)}/comment`, { body: { body, issue: { repoId: options.issue.repoId, number: options.issue.number } } }));
1515
+ return new GitHubComment(ctx, data);
1516
+ }
1517
+ /** Edit a conversation comment or a comment on the diff. Sends the comment's event with action `edited`. Experimental. */
1518
+ async edit(body, options) {
1519
+ const ctx = this.#ctx;
1520
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/apps/${segment(this.id)}/edit`, { body: { body, comment: options.comment.id } }));
1521
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1522
+ }
1523
+ /** Delete a conversation comment or a comment on the diff. Sends the comment's event with action `deleted`. Experimental. */
1524
+ async delete(options) {
1525
+ const ctx = this.#ctx;
1526
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/apps/${segment(this.id)}/delete`, { body: { comment: options.comment.id } }));
1527
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1528
+ }
1529
+ /** React to an issue, a pull request or a comment. GitHub sends no webhook for a reaction. Experimental. */
1530
+ async react(content, options = {}) {
1531
+ const ctx = this.#ctx;
1532
+ await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/apps/${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 } });
1533
+ }
1534
+ /** Hide a comment as outdated, spam, off-topic or resolved. GitHub sends no webhook for it. Experimental. */
1535
+ async minimize(options) {
1536
+ const ctx = this.#ctx;
1537
+ await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/apps/${segment(this.id)}/minimize`, { body: { comment: options.comment.id, reason: options.reason } });
1538
+ }
1539
+ /** Submit a review, with comments on the diff if any. Sends `pull_request_review`, and one `pull_request_review_comment` per comment. Experimental. */
1540
+ async review(review) {
1541
+ const ctx = this.#ctx;
1542
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/apps/${segment(this.id)}/review`, { body: { review: { ...review, pr: { repoId: review.pr.repoId, number: review.pr.number } } } }));
1543
+ return decodeGitHubReview(ctx, data);
1544
+ }
1545
+ /** One comment on the diff, outside a review. Sends `pull_request_review_comment`. Experimental. */
1546
+ async reviewComment(body, options) {
1547
+ const ctx = this.#ctx;
1548
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/apps/${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 } }));
1549
+ return new GitHubReviewComment(ctx, data);
1550
+ }
1551
+ /** Reply in a thread on the diff. Sends `pull_request_review_comment`. Experimental. */
1552
+ async reply(body, options) {
1553
+ const ctx = this.#ctx;
1554
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/apps/${segment(this.id)}/reply`, { body: { body, comment: options.comment.id } }));
1555
+ return new GitHubReviewComment(ctx, data);
1556
+ }
1557
+ /** Resolve a thread on the diff. Sends `pull_request_review_thread`. Experimental. */
1558
+ async resolve(options) {
1559
+ const ctx = this.#ctx;
1560
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/apps/${segment(this.id)}/resolve`, { body: { comment: options.comment.id } }));
1561
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1562
+ }
1563
+ /** Reopen a thread on the diff. Sends `pull_request_review_thread`. Experimental. */
1564
+ async unresolve(options) {
1565
+ const ctx = this.#ctx;
1566
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/apps/${segment(this.id)}/unresolve`, { body: { comment: options.comment.id } }));
1567
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1568
+ }
1569
+ /** Request a review from people or the App's bot. Sends `pull_request` (action `review_requested`) per reviewer. Experimental. */
1570
+ async requestReview(reviewers, options) {
1571
+ const ctx = this.#ctx;
1572
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/apps/${segment(this.id)}/request-review`, { body: { reviewers: [reviewers].flat().map((item) => item.id), pr: { repoId: options.pr.repoId, number: options.pr.number } } }));
1573
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1574
+ }
1575
+ /** Mark a draft pull request as ready for review. Sends `pull_request` (action `ready_for_review`). Experimental. */
1576
+ async markReady(options) {
1577
+ const ctx = this.#ctx;
1578
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/apps/${segment(this.id)}/mark-ready`, { body: { pr: { repoId: options.pr.repoId, number: options.pr.number } } }));
1579
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1580
+ }
1581
+ /** Merge a pull request. Sends `push` for the base branch, then `pull_request` (action `closed`, merged). Experimental. */
1582
+ async merge(options) {
1583
+ const ctx = this.#ctx;
1584
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/apps/${segment(this.id)}/merge`, { body: { pr: { repoId: options.pr.repoId, number: options.pr.number }, method: options.method } }));
1585
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1586
+ }
1587
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
1588
+ [QUIET]() {
1589
+ return quietOf(this.#ctx);
1590
+ }
1591
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
1592
+ [CONTEXT]() {
1593
+ return this.#ctx;
1594
+ }
1595
+ }
1596
+ export class GitHubUser {
1597
+ id;
1598
+ name;
1599
+ kind;
1600
+ login;
1601
+ numericId;
1602
+ displayName;
1603
+ email;
1604
+ role;
1605
+ #ctx;
1606
+ /** @internal Handles come from the SDK, never from `new`. */
1607
+ constructor(ctx, data) {
1608
+ this.#ctx = ctx;
1609
+ this.id = data.id;
1610
+ this.name = data.name;
1611
+ this.kind = data.kind;
1612
+ this.login = data.login;
1613
+ this.numericId = data.numericId;
1614
+ this.displayName = data.displayName;
1615
+ this.email = data.email;
1616
+ this.role = data.role;
1617
+ }
1618
+ /** 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. */
1619
+ async push(changes, options) {
1620
+ const ctx = this.#ctx;
1621
+ 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 } }));
1622
+ return new GitHubCommit(ctx, data);
1623
+ }
1624
+ /** Open an issue. Sends `issues` (action `opened`). Experimental. */
1625
+ async openIssue(issue, options) {
1626
+ const ctx = this.#ctx;
1627
+ 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 } }));
1628
+ return new GitHubIssue(ctx, data);
1629
+ }
1630
+ /** Open a pull request. With `changes`, they are pushed to `from` first; without, `from` is an existing branch. Sends `pull_request` (action `opened`). Experimental. */
1631
+ async openPullRequest(pr, options) {
1632
+ const ctx = this.#ctx;
1633
+ 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 } }));
1634
+ return new GitHubPullRequest(ctx, data);
1635
+ }
1636
+ /** Edit the title or the body of an issue or a pull request. Sends `issues` or `pull_request` (action `edited`). Experimental. */
1637
+ async editIssue(changes, options) {
1638
+ const ctx = this.#ctx;
1639
+ 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 } } }));
1640
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1641
+ }
1642
+ /** Close an issue or a pull request. Sends `issues` or `pull_request` (action `closed`). Experimental. */
1643
+ async close(options) {
1644
+ const ctx = this.#ctx;
1645
+ 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 } } }));
1646
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1647
+ }
1648
+ /** Reopen an issue or a pull request. Sends `issues` or `pull_request` (action `reopened`). Experimental. */
1649
+ async reopen(options) {
1650
+ const ctx = this.#ctx;
1651
+ 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 } } }));
1652
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1653
+ }
1654
+ /** Put labels on an issue or a pull request. Sends one `labeled` event per label. Experimental. */
1655
+ async label(labels, options) {
1656
+ const ctx = this.#ctx;
1657
+ 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 } } }));
1658
+ return decodeGitHubLabelDeliveries(ctx, data);
1659
+ }
1660
+ /** Take labels off an issue or a pull request. Sends one `unlabeled` event per label. Experimental. */
1661
+ async unlabel(labels, options) {
1662
+ const ctx = this.#ctx;
1663
+ 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 } } }));
1664
+ return decodeGitHubUnlabelDeliveries(ctx, data);
1665
+ }
1666
+ /** Assign people or the App's bot. Sends one `assigned` event per assignee. Experimental. */
1667
+ async assign(assignees, options) {
1668
+ const ctx = this.#ctx;
1669
+ 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 } } }));
1670
+ return decodeGitHubAssignDeliveries(ctx, data);
1671
+ }
1672
+ /** Comment on an issue or a pull request's conversation. Sends `issue_comment` (action `created`). Experimental. */
1673
+ async comment(body, options) {
1674
+ const ctx = this.#ctx;
1675
+ 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 } } }));
1676
+ return new GitHubComment(ctx, data);
1677
+ }
1678
+ /** Edit a conversation comment or a comment on the diff. Sends the comment's event with action `edited`. Experimental. */
1679
+ async edit(body, options) {
1680
+ const ctx = this.#ctx;
1681
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/users/${segment(this.id)}/edit`, { body: { body, comment: options.comment.id } }));
1682
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1683
+ }
1684
+ /** Delete a conversation comment or a comment on the diff. Sends the comment's event with action `deleted`. Experimental. */
1685
+ async delete(options) {
1686
+ const ctx = this.#ctx;
1687
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/users/${segment(this.id)}/delete`, { body: { comment: options.comment.id } }));
1688
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1689
+ }
1690
+ /** React to an issue, a pull request or a comment. GitHub sends no webhook for a reaction. Experimental. */
1691
+ async react(content, options = {}) {
1692
+ const ctx = this.#ctx;
1693
+ 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 } });
1694
+ }
1695
+ /** Hide a comment as outdated, spam, off-topic or resolved. GitHub sends no webhook for it. Experimental. */
1696
+ async minimize(options) {
1697
+ const ctx = this.#ctx;
1698
+ await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/users/${segment(this.id)}/minimize`, { body: { comment: options.comment.id, reason: options.reason } });
1699
+ }
1700
+ /** Submit a review, with comments on the diff if any. Sends `pull_request_review`, and one `pull_request_review_comment` per comment. Experimental. */
1701
+ async review(review) {
1702
+ const ctx = this.#ctx;
1703
+ 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 } } } }));
1704
+ return decodeGitHubReview(ctx, data);
1705
+ }
1706
+ /** One comment on the diff, outside a review. Sends `pull_request_review_comment`. Experimental. */
1707
+ async reviewComment(body, options) {
1708
+ const ctx = this.#ctx;
1709
+ 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 } }));
1710
+ return new GitHubReviewComment(ctx, data);
1711
+ }
1712
+ /** Reply in a thread on the diff. Sends `pull_request_review_comment`. Experimental. */
1713
+ async reply(body, options) {
1714
+ const ctx = this.#ctx;
1715
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/users/${segment(this.id)}/reply`, { body: { body, comment: options.comment.id } }));
1716
+ return new GitHubReviewComment(ctx, data);
1717
+ }
1718
+ /** Resolve a thread on the diff. Sends `pull_request_review_thread`. Experimental. */
1719
+ async resolve(options) {
1720
+ const ctx = this.#ctx;
1721
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/users/${segment(this.id)}/resolve`, { body: { comment: options.comment.id } }));
1722
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1723
+ }
1724
+ /** Reopen a thread on the diff. Sends `pull_request_review_thread`. Experimental. */
1725
+ async unresolve(options) {
1726
+ const ctx = this.#ctx;
1727
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/users/${segment(this.id)}/unresolve`, { body: { comment: options.comment.id } }));
1728
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1729
+ }
1730
+ /** Request a review from people or the App's bot. Sends `pull_request` (action `review_requested`) per reviewer. Experimental. */
1731
+ async requestReview(reviewers, options) {
1732
+ const ctx = this.#ctx;
1733
+ 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 } } }));
1734
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1735
+ }
1736
+ /** Mark a draft pull request as ready for review. Sends `pull_request` (action `ready_for_review`). Experimental. */
1737
+ async markReady(options) {
1738
+ const ctx = this.#ctx;
1739
+ 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 } } }));
1740
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1741
+ }
1742
+ /** Merge a pull request. Sends `push` for the base branch, then `pull_request` (action `closed`, merged). Experimental. */
1743
+ async merge(options) {
1744
+ const ctx = this.#ctx;
1745
+ 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 } }));
1746
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1747
+ }
1748
+ /** Click "Re-run" on a check run. Sends `check_run` (action `rerequested`). Experimental. */
1749
+ async rerun(options) {
1750
+ const ctx = this.#ctx;
1751
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/users/${segment(this.id)}/rerun`, { body: { checkRun: options.checkRun.id } }));
1752
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1753
+ }
1754
+ /** Click one of the buttons the App put on a check run. Sends `check_run` (action `requested_action`). Experimental. */
1755
+ async requestAction(identifier, options) {
1756
+ const ctx = this.#ctx;
1757
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/users/${segment(this.id)}/request-action`, { body: { identifier, checkRun: options.checkRun.id } }));
1758
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1759
+ }
1760
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
1761
+ [QUIET]() {
1762
+ return quietOf(this.#ctx);
1763
+ }
1764
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
1765
+ [CONTEXT]() {
1766
+ return this.#ctx;
1767
+ }
1768
+ }
1769
+ export class GitHubRepo {
1770
+ id;
1771
+ owner;
1772
+ name;
1773
+ fullName;
1774
+ defaultBranch;
1775
+ private;
1776
+ #ctx;
1777
+ /** @internal Handles come from the SDK, never from `new`. */
1778
+ constructor(ctx, data) {
1779
+ this.#ctx = ctx;
1780
+ this.id = data.id;
1781
+ this.owner = data.owner;
1782
+ this.name = data.name;
1783
+ this.fullName = data.fullName;
1784
+ this.defaultBranch = data.defaultBranch;
1785
+ this.private = data.private;
1786
+ }
1787
+ /** Install an App on this repository. Sends that App `installation_repositories`. Experimental. */
1788
+ async installApp(app) {
1789
+ const ctx = this.#ctx;
1790
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.id)}/install`, { body: { app: app.id } }));
1791
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1792
+ }
1793
+ /** Take an App off this repository. Sends that App `installation_repositories`. Experimental. */
1794
+ async uninstallApp(app) {
1795
+ const ctx = this.#ctx;
1796
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.id)}/uninstall`, { body: { app: app.id } }));
1797
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
1798
+ }
1799
+ /** An issue of this repository by its number. Experimental. */
1800
+ async issue(number) {
1801
+ const ctx = this.#ctx;
1802
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.id)}/issue`, { query: { number } }));
1803
+ return new GitHubIssue(ctx, data);
1804
+ }
1805
+ /** A pull request of this repository by its number. Experimental. */
1806
+ async pullRequest(number) {
1807
+ const ctx = this.#ctx;
1808
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.id)}/pull`, { query: { number } }));
1809
+ return new GitHubPullRequest(ctx, data);
1810
+ }
1811
+ /** A file's text as it is on a branch (the default branch without `ref`), or nothing when it isn't there. Experimental. */
1812
+ async readFile(path, options = {}) {
1813
+ const ctx = this.#ctx;
1814
+ await untilQuiet(() => quietOf(ctx));
1815
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.id)}/file`, { query: { path, ref: options.ref } }));
1816
+ return (data === null ? undefined : data);
1817
+ }
1818
+ /** The commits of a branch (the default branch without `branch`), newest first. Experimental. */
1819
+ async commits(options = {}) {
1820
+ const ctx = this.#ctx;
1821
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.id)}/commits`, { query: { branch: options.branch } }));
1822
+ return decodeGitHubCommits(ctx, data);
1823
+ }
1824
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
1825
+ [QUIET]() {
1826
+ return quietOf(this.#ctx);
1827
+ }
1828
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
1829
+ [CONTEXT]() {
1830
+ return this.#ctx;
1831
+ }
1832
+ }
1833
+ export class GitHubIssue {
1834
+ repoId;
1835
+ number;
1836
+ repo;
1837
+ url;
1838
+ author;
1839
+ #ctx;
1840
+ #seen = new Map();
1841
+ /** @internal Handles come from the SDK, never from `new`. */
1842
+ constructor(ctx, data) {
1843
+ this.#ctx = ctx;
1844
+ this.repoId = data.repoId;
1845
+ this.number = data.number;
1846
+ this.repo = new GitHubRepo(ctx, data.repo);
1847
+ this.url = data.url;
1848
+ this.author = data.author.kind === "user" ? new GitHubUser(ctx, data.author) : new GitHubApp(ctx, data.author);
1849
+ }
1850
+ /** Read the issue again. Experimental. */
1851
+ async refresh() {
1852
+ const ctx = this.#ctx;
1853
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.repoId)}/issues/${segment(this.number)}`));
1854
+ return new GitHubIssue(ctx, data);
1855
+ }
1856
+ /** The issue's title as it is now. Experimental. */
1857
+ async title() {
1858
+ const ctx = this.#ctx;
1859
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.repoId)}/issues/${segment(this.number)}/title`));
1860
+ return data;
1861
+ }
1862
+ /** Open or closed, once the agent is quiet. Experimental. */
1863
+ async state() {
1864
+ const ctx = this.#ctx;
1865
+ await untilQuiet(() => quietOf(ctx));
1866
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.repoId)}/issues/${segment(this.number)}/state`));
1867
+ return data;
1868
+ }
1869
+ /** The names of the labels on it. Experimental. */
1870
+ async labels() {
1871
+ const ctx = this.#ctx;
1872
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.repoId)}/issues/${segment(this.number)}/labels`));
1873
+ return data;
1874
+ }
1875
+ /** Who it is assigned to. Experimental. */
1876
+ async assignees() {
1877
+ const ctx = this.#ctx;
1878
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.repoId)}/issues/${segment(this.number)}/assignees`));
1879
+ return data.map((item) => item.kind === "user" ? new GitHubUser(ctx, item) : new GitHubApp(ctx, item));
1880
+ }
1881
+ /** The comments of the conversation, oldest first. Experimental. */
1882
+ async comments() {
1883
+ const ctx = this.#ctx;
1884
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.repoId)}/issues/${segment(this.number)}/comments`));
1885
+ return decodeGitHubComments(ctx, data);
1886
+ }
1887
+ /** The issue or pull request as a person reads it: description, comments, reviews and threads. Experimental. */
1888
+ async transcript() {
1889
+ const ctx = this.#ctx;
1890
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.repoId)}/issues/${segment(this.number)}/transcript`));
1891
+ return decodeGitHubTranscript(ctx, data);
1892
+ }
1893
+ /** Wait for the next new comment matching `from` (anyone if omitted), after the last one this handle saw. */
1894
+ async waitForComment(options = {}) {
1895
+ return waitForNext(this.#seen, "waitForComment", () => this.comments(), (item) => fromMatches(item.author, options.from) && textMatches(item.body, options.body), describeWait("a comment", options.from), options);
1896
+ }
1897
+ /** The latest comment matching `from`, once the agent is quiet. Waits for at least one. */
1898
+ async latestComment(options = {}) {
1899
+ return latestOnceQuiet(() => this.comments(), (item) => fromMatches(item.author, options.from), () => quietOf(this.#ctx), describeWait("a comment", options.from), options);
1900
+ }
1901
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
1902
+ [QUIET]() {
1903
+ return quietOf(this.#ctx);
1904
+ }
1905
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
1906
+ [CONTEXT]() {
1907
+ return this.#ctx;
1908
+ }
1909
+ }
1910
+ export class GitHubDelivery {
1911
+ id;
1912
+ channel;
1913
+ app;
1914
+ type;
1915
+ action;
1916
+ guid;
1917
+ payload;
1918
+ attempts;
1919
+ status;
1920
+ #ctx;
1921
+ /** @internal Handles come from the SDK, never from `new`. */
1922
+ constructor(ctx, data) {
1923
+ this.#ctx = ctx;
1924
+ this.id = data.id;
1925
+ this.channel = data.channel;
1926
+ this.app = data.app;
1927
+ this.type = data.type;
1928
+ this.action = data.action;
1929
+ this.guid = data.guid;
1930
+ this.payload = data.payload;
1931
+ this.attempts = data.attempts;
1932
+ this.status = data.status;
1933
+ }
1934
+ /** Re-read a delivery: its attempts and status. Experimental. */
1935
+ async refresh() {
1936
+ const ctx = this.#ctx;
1937
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/deliveries/${segment(this.id)}`));
1938
+ return new GitHubDelivery(ctx, data);
1939
+ }
1940
+ /** Redeliver from the App's delivery log, as GitHub's UI and API do: the same GUID, a new attempt. Experimental. */
1941
+ async redeliver() {
1942
+ const ctx = this.#ctx;
1943
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/deliveries/${segment(this.id)}/redeliver`));
1944
+ return data;
1945
+ }
1946
+ /** Send the delivery again, unchanged or signed with a secret that isn't the App's. Experimental. */
1947
+ async resend(options = {}) {
1948
+ const ctx = this.#ctx;
1949
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/github/deliveries/${segment(this.id)}/resend`, { body: { badSignature: options.badSignature } }));
1950
+ return data;
1951
+ }
1952
+ /** Wait for the delivery to settle, and resolve with the value as it is then. */
1953
+ async settled(options = {}) {
1954
+ return waitFor("the delivery to settle", async () => {
1955
+ const value = await this.refresh();
1956
+ return value.status === "pending" ? undefined : value;
1957
+ }, options);
1958
+ }
1959
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
1960
+ [QUIET]() {
1961
+ return quietOf(this.#ctx);
1962
+ }
1963
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
1964
+ [CONTEXT]() {
1965
+ return this.#ctx;
1966
+ }
1967
+ }
1968
+ export class GitHubCommit {
1969
+ repoId;
1970
+ sha;
1971
+ message;
1972
+ author;
1973
+ branch;
1974
+ committedAt;
1975
+ #ctx;
1976
+ /** @internal Handles come from the SDK, never from `new`. */
1977
+ constructor(ctx, data) {
1978
+ this.#ctx = ctx;
1979
+ this.repoId = data.repoId;
1980
+ this.sha = data.sha;
1981
+ this.message = data.message;
1982
+ this.author = data.author === undefined ? undefined : data.author.kind === "user" ? new GitHubUser(ctx, data.author) : new GitHubApp(ctx, data.author);
1983
+ this.branch = data.branch;
1984
+ this.committedAt = data.committedAt;
1985
+ }
1986
+ /** The check runs on this commit: the newest of each name. Experimental. */
1987
+ async checkRuns() {
1988
+ const ctx = this.#ctx;
1989
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.repoId)}/commits/${segment(this.sha)}/check-runs`));
1990
+ return decodeGitHubCheckRuns(ctx, data);
1991
+ }
1992
+ /** The commit statuses on this commit: the newest of each context. Experimental. */
1993
+ async statuses() {
1994
+ const ctx = this.#ctx;
1995
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.repoId)}/commits/${segment(this.sha)}/statuses`));
1996
+ return decodeGitHubStatuses(ctx, data);
1997
+ }
1998
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
1999
+ [QUIET]() {
2000
+ return quietOf(this.#ctx);
2001
+ }
2002
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
2003
+ [CONTEXT]() {
2004
+ return this.#ctx;
2005
+ }
2006
+ }
2007
+ export class GitHubCheckRun {
2008
+ id;
2009
+ name;
2010
+ app;
2011
+ headSha;
2012
+ status;
2013
+ conclusion;
2014
+ title;
2015
+ summary;
2016
+ annotations;
2017
+ actions;
2018
+ #ctx;
2019
+ /** @internal Handles come from the SDK, never from `new`. */
2020
+ constructor(ctx, data) {
2021
+ this.#ctx = ctx;
2022
+ this.id = data.id;
2023
+ this.name = data.name;
2024
+ this.app = data.app;
2025
+ this.headSha = data.headSha;
2026
+ this.status = data.status;
2027
+ this.conclusion = data.conclusion;
2028
+ this.title = data.title;
2029
+ this.summary = data.summary;
2030
+ this.annotations = data.annotations;
2031
+ this.actions = data.actions;
2032
+ }
2033
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2034
+ [QUIET]() {
2035
+ return quietOf(this.#ctx);
2036
+ }
2037
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
2038
+ [CONTEXT]() {
2039
+ return this.#ctx;
2040
+ }
2041
+ }
2042
+ export class GitHubComment {
2043
+ id;
2044
+ url;
2045
+ issue;
2046
+ author;
2047
+ body;
2048
+ createdAt;
2049
+ delivery;
2050
+ #ctx;
2051
+ /** @internal Handles come from the SDK, never from `new`. */
2052
+ constructor(ctx, data) {
2053
+ this.#ctx = ctx;
2054
+ this.id = data.id;
2055
+ this.url = data.url;
2056
+ this.issue = new GitHubIssue(ctx, data.issue);
2057
+ this.author = data.author.kind === "user" ? new GitHubUser(ctx, data.author) : new GitHubApp(ctx, data.author);
2058
+ this.body = data.body;
2059
+ this.createdAt = data.createdAt;
2060
+ this.delivery = data.delivery === undefined ? undefined : new GitHubDelivery(ctx, data.delivery);
2061
+ }
2062
+ /** Read a conversation comment again. Experimental. */
2063
+ async refresh() {
2064
+ const ctx = this.#ctx;
2065
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/comments/${segment(this.id)}`));
2066
+ return new GitHubComment(ctx, data);
2067
+ }
2068
+ /** The reactions on a conversation comment, by content. Experimental. */
2069
+ async reactions() {
2070
+ const ctx = this.#ctx;
2071
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/comments/${segment(this.id)}/reactions`));
2072
+ return decodeGitHubReactions(ctx, data);
2073
+ }
2074
+ /** The `issue_comment` (`created`) delivery this comment caused to this App (decision 0027), or nothing when it wasn't told. The comment's `delivery` is the built-in App's. Experimental. */
2075
+ async deliveryFor(app) {
2076
+ const ctx = this.#ctx;
2077
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/comments/${segment(this.id)}/delivery-for`, { query: { app: app.id } }));
2078
+ return (data === null ? undefined : new GitHubDelivery(ctx, data));
2079
+ }
2080
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2081
+ [QUIET]() {
2082
+ return quietOf(this.#ctx);
2083
+ }
2084
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
2085
+ [CONTEXT]() {
2086
+ return this.#ctx;
2087
+ }
2088
+ }
2089
+ export class GitHubReviewComment {
2090
+ id;
2091
+ pr;
2092
+ author;
2093
+ path;
2094
+ line;
2095
+ side;
2096
+ body;
2097
+ delivery;
2098
+ #ctx;
2099
+ /** @internal Handles come from the SDK, never from `new`. */
2100
+ constructor(ctx, data) {
2101
+ this.#ctx = ctx;
2102
+ this.id = data.id;
2103
+ this.pr = new GitHubPullRequest(ctx, data.pr);
2104
+ this.author = data.author.kind === "user" ? new GitHubUser(ctx, data.author) : new GitHubApp(ctx, data.author);
2105
+ this.path = data.path;
2106
+ this.line = data.line;
2107
+ this.side = data.side;
2108
+ this.body = data.body;
2109
+ this.delivery = data.delivery === undefined ? undefined : new GitHubDelivery(ctx, data.delivery);
2110
+ }
2111
+ /** The replies in this comment's thread, once the agent is quiet. Experimental. */
2112
+ async replies() {
2113
+ const ctx = this.#ctx;
2114
+ await untilQuiet(() => quietOf(ctx));
2115
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/review-comments/${segment(this.id)}/replies`));
2116
+ return decodeGitHubReviewCommentReplies(ctx, data);
2117
+ }
2118
+ /** Is this comment's thread resolved?. Experimental. */
2119
+ async resolved() {
2120
+ const ctx = this.#ctx;
2121
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/review-comments/${segment(this.id)}/resolved`));
2122
+ return data;
2123
+ }
2124
+ /** This comment's thread as a person reads it. Experimental. */
2125
+ async transcript() {
2126
+ const ctx = this.#ctx;
2127
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/review-comments/${segment(this.id)}/transcript`));
2128
+ return decodeGitHubTranscript(ctx, data);
2129
+ }
2130
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2131
+ [QUIET]() {
2132
+ return quietOf(this.#ctx);
2133
+ }
2134
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
2135
+ [CONTEXT]() {
2136
+ return this.#ctx;
2137
+ }
2138
+ }
2139
+ export class LinearFixture {
2140
+ app;
2141
+ apiUrl;
2142
+ #ctx;
2143
+ #seen = new Map();
2144
+ /** @internal Handles come from the SDK, never from `new`. */
2145
+ constructor(ctx, data) {
2146
+ this.#ctx = ctx;
2147
+ this.app = new LinearApp(ctx, data.app);
2148
+ this.apiUrl = data.apiUrl;
2149
+ }
2150
+ /** Create a person in the workspace. Experimental. */
2151
+ async createUser(options) {
2152
+ const ctx = this.#ctx;
2153
+ 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 }) } }));
2154
+ return new LinearUser(ctx, data);
2155
+ }
2156
+ /** The people this session created. Experimental. */
2157
+ async users() {
2158
+ const ctx = this.#ctx;
2159
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/users`));
2160
+ return decodeLinearUsers(ctx, data);
2161
+ }
2162
+ /** Make another OAuth app in the workspace, installed with `actor=app`: its own app user (mentionable and assignable), access token, client and webhook secret. Or return the one made with this name and settings. Its webhooks go to CHANNELSTACK_LINEAR_APP_<NAME>_WEBHOOK_URL. Experimental. */
2163
+ async createApp(options) {
2164
+ const ctx = this.#ctx;
2165
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/linear/apps`, { body: { name: options.name, events: options.events } }));
2166
+ return new LinearApp(ctx, data);
2167
+ }
2168
+ /** The apps this session used: the built-in one first, then each it got from `createApp`, in the order it first did. Another session's are `not_found` here. Experimental. */
2169
+ async apps() {
2170
+ const ctx = this.#ctx;
2171
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/apps`));
2172
+ return decodeLinearApps(ctx, data);
2173
+ }
2174
+ /** The teams this session created. Experimental. */
2175
+ async teams() {
2176
+ const ctx = this.#ctx;
2177
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/teams`));
2178
+ return decodeLinearTeams(ctx, data);
2179
+ }
2180
+ /** Create a team: its members, workflow states and labels. Without a key one is made up, so parallel tests never share one. Experimental. */
2181
+ async createTeam(options = {}) {
2182
+ const ctx = this.#ctx;
2183
+ 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 } }));
2184
+ return new LinearTeam(ctx, data);
2185
+ }
2186
+ /** The issues in this session's teams, read again from Linear live, oldest first. Experimental. */
2187
+ async issues() {
2188
+ const ctx = this.#ctx;
2189
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/issues`));
2190
+ return decodeLinearIssues(ctx, data);
2191
+ }
2192
+ /** Every webhook channelstack sent the agent for this session, with every attempt. Experimental. */
2193
+ async deliveries(options = {}) {
2194
+ const ctx = this.#ctx;
2195
+ 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, app: options.app === undefined ? undefined : options.app.id } }));
2196
+ return decodeLinearDeliveries(ctx, data);
2197
+ }
2198
+ /** The GraphQL operations the agent sent about this session's issues and sessions, by root field (`agentActivityCreate`). Experimental. */
2199
+ async calls(options = {}) {
2200
+ const ctx = this.#ctx;
2201
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/calls`, { query: { operation: options.operation, error: options.error } }));
2202
+ return data;
2203
+ }
2204
+ /** Wait for the next new API call from the agent, after the last one this handle saw. */
2205
+ async waitForCall(filter = {}, options = {}) {
2206
+ return waitForNext(this.#seen, `waitForCall:${JSON.stringify(filter)}`, () => this.calls(filter), () => true, "an API call from the agent", options);
2207
+ }
2208
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2209
+ [QUIET]() {
2210
+ return quietOf(this.#ctx);
2211
+ }
2212
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
2213
+ [CONTEXT]() {
2214
+ return this.#ctx;
2215
+ }
2216
+ }
2217
+ export class LinearApp {
2218
+ id;
2219
+ name;
2220
+ kind;
2221
+ botUserId;
2222
+ accessToken;
2223
+ webhookSecret;
2224
+ clientId;
2225
+ clientSecret;
2226
+ #ctx;
2227
+ /** @internal Handles come from the SDK, never from `new`. */
2228
+ constructor(ctx, data) {
2229
+ this.#ctx = ctx;
2230
+ this.id = data.id;
2231
+ this.name = data.name;
2232
+ this.kind = data.kind;
2233
+ this.botUserId = data.botUserId;
2234
+ this.accessToken = data.accessToken;
2235
+ this.webhookSecret = data.webhookSecret;
2236
+ this.clientId = data.clientId;
2237
+ this.clientSecret = data.clientSecret;
2238
+ }
2239
+ /** An app a test made comments on an issue, as its own `commentCreate` would. Its mention of another app is refused (to confirm, B6). Experimental. */
2240
+ async comment(body, options) {
2241
+ const ctx = this.#ctx;
2242
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/linear/apps/${segment(this.id)}/comment`, { body: { body, issue: options.issue.id } }));
2243
+ return new LinearComment(ctx, data);
2244
+ }
2245
+ /** An app a test made replies in a comment's thread, as its own `commentCreate` with a `parentId` would. Experimental. */
2246
+ async reply(body, options) {
2247
+ const ctx = this.#ctx;
2248
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/linear/apps/${segment(this.id)}/reply`, { body: { body, comment: options.comment.id } }));
2249
+ return new LinearComment(ctx, data);
2250
+ }
2251
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2252
+ [QUIET]() {
2253
+ return quietOf(this.#ctx);
2254
+ }
2255
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
2256
+ [CONTEXT]() {
2257
+ return this.#ctx;
2258
+ }
2259
+ }
2260
+ export class LinearUser {
2261
+ id;
2262
+ name;
2263
+ kind;
2264
+ displayName;
2265
+ email;
2266
+ admin;
2267
+ guest;
2268
+ #ctx;
2269
+ /** @internal Handles come from the SDK, never from `new`. */
2270
+ constructor(ctx, data) {
2271
+ this.#ctx = ctx;
2272
+ this.id = data.id;
2273
+ this.name = data.name;
2274
+ this.kind = data.kind;
2275
+ this.displayName = data.displayName;
2276
+ this.email = data.email;
2277
+ this.admin = data.admin;
2278
+ this.guest = data.guest;
2279
+ }
2280
+ /** Create an issue. Sends `Issue` (`create`); with `delegate`, it opens an agent session and sends `AgentSessionEvent` (`created`). Experimental. */
2281
+ async createIssue(issue, options) {
2282
+ const ctx = this.#ctx;
2283
+ 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 } }));
2284
+ return new LinearIssue(ctx, data);
2285
+ }
2286
+ /** Edit an issue's title, description or priority. Sends `Issue` (`update`). Experimental. */
2287
+ async editIssue(changes, options) {
2288
+ const ctx = this.#ctx;
2289
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/linear/users/${segment(this.id)}/edit-issue`, { body: { changes, issue: options.issue.id } }));
2290
+ return (data === null ? undefined : new LinearDelivery(ctx, data));
2291
+ }
2292
+ /** Take an issue back from the app. Sends `Issue` (`update`). Experimental. */
2293
+ async undelegate(options) {
2294
+ const ctx = this.#ctx;
2295
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/linear/users/${segment(this.id)}/undelegate`, { body: { issue: options.issue.id } }));
2296
+ return (data === null ? undefined : new LinearDelivery(ctx, data));
2297
+ }
2298
+ /** Assign an issue to a person, or (with no one) unassign it. Sends `Issue` (`update`). Experimental. */
2299
+ async assign(assignee, options) {
2300
+ const ctx = this.#ctx;
2301
+ 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 } }));
2302
+ return (data === null ? undefined : new LinearDelivery(ctx, data));
2303
+ }
2304
+ /** Move an issue to a workflow state, by name. Sends `Issue` (`update`). Experimental. */
2305
+ async setState(state, options) {
2306
+ const ctx = this.#ctx;
2307
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/linear/users/${segment(this.id)}/set-state`, { body: { state, issue: options.issue.id } }));
2308
+ return (data === null ? undefined : new LinearDelivery(ctx, data));
2309
+ }
2310
+ /** Put labels on an issue, by name. Sends `Issue` (`update`). Experimental. */
2311
+ async label(labels, options) {
2312
+ const ctx = this.#ctx;
2313
+ 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 } }));
2314
+ return (data === null ? undefined : new LinearDelivery(ctx, data));
2315
+ }
2316
+ /** Delegate an issue to an app. Opens that app's agent session and sends it `AgentSessionEvent` (`created`); an issue delegated to another app moves. Experimental. */
2317
+ async delegate(app, options) {
2318
+ const ctx = this.#ctx;
2319
+ 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 } }));
2320
+ return new LinearAgentSession(ctx, data);
2321
+ }
2322
+ /** Comment on an issue. A mention of the app opens an agent session and sends `AgentSessionEvent` (`created`). Experimental. */
2323
+ async comment(body, options) {
2324
+ const ctx = this.#ctx;
2325
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/linear/users/${segment(this.id)}/comment`, { body: { body, issue: options.issue.id } }));
2326
+ return new LinearComment(ctx, data);
2327
+ }
2328
+ /** Reply in a comment's thread. In an agent session's thread, it prompts the session (`AgentSessionEvent` `prompted`). Experimental. */
2329
+ async reply(body, options) {
2330
+ const ctx = this.#ctx;
2331
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/linear/users/${segment(this.id)}/reply`, { body: { body, comment: options.comment.id } }));
2332
+ return new LinearComment(ctx, data);
2333
+ }
2334
+ /** Edit a comment. Sends `Comment` (`update`). Experimental. */
2335
+ async edit(body, options) {
2336
+ const ctx = this.#ctx;
2337
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/linear/users/${segment(this.id)}/edit`, { body: { body, comment: options.comment.id } }));
2338
+ return (data === null ? undefined : new LinearDelivery(ctx, data));
2339
+ }
2340
+ /** Delete a comment. Sends `Comment` (`remove`). Experimental. */
2341
+ async delete(options) {
2342
+ const ctx = this.#ctx;
2343
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/linear/users/${segment(this.id)}/delete`, { body: { comment: options.comment.id } }));
2344
+ return (data === null ? undefined : new LinearDelivery(ctx, data));
2345
+ }
2346
+ /** React to a comment with an emoji. Linear sends no webhook for it. Experimental. */
2347
+ async react(emoji, options) {
2348
+ const ctx = this.#ctx;
2349
+ await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/linear/users/${segment(this.id)}/react`, { body: { emoji, comment: options.comment.id } });
2350
+ }
2351
+ /** Send a follow-up in an agent session. Sends `AgentSessionEvent` (`prompted`). Experimental. */
2352
+ async prompt(body, options) {
2353
+ const ctx = this.#ctx;
2354
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/linear/users/${segment(this.id)}/prompt`, { body: { body, session: options.session.id } }));
2355
+ return (data === null ? undefined : new LinearDelivery(ctx, data));
2356
+ }
2357
+ /** Answer a question the agent asked (an `elicitation` activity). Sends `AgentSessionEvent` (`prompted`). Experimental. */
2358
+ async answer(body, options) {
2359
+ const ctx = this.#ctx;
2360
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/linear/users/${segment(this.id)}/answer`, { body: { body, elicitation: options.elicitation.id } }));
2361
+ return (data === null ? undefined : new LinearDelivery(ctx, data));
2362
+ }
2363
+ /** Press Stop on an agent session. Sends `AgentSessionEvent` (`prompted`) with the `stop` signal. Experimental. */
2364
+ async stop(options) {
2365
+ const ctx = this.#ctx;
2366
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/linear/users/${segment(this.id)}/stop`, { body: { session: options.session.id } }));
2367
+ return new LinearDelivery(ctx, data);
2368
+ }
2369
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2370
+ [QUIET]() {
2371
+ return quietOf(this.#ctx);
2372
+ }
2373
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
2374
+ [CONTEXT]() {
2375
+ return this.#ctx;
2376
+ }
2377
+ }
2378
+ export class LinearComment {
2379
+ id;
2380
+ issue;
2381
+ author;
2382
+ body;
2383
+ createdAt;
2384
+ url;
2385
+ session;
2386
+ delivery;
2387
+ #ctx;
2388
+ /** @internal Handles come from the SDK, never from `new`. */
2389
+ constructor(ctx, data) {
2390
+ this.#ctx = ctx;
2391
+ this.id = data.id;
2392
+ this.issue = new LinearIssue(ctx, data.issue);
2393
+ this.author = data.author.kind === "user" ? new LinearUser(ctx, data.author) : new LinearApp(ctx, data.author);
2394
+ this.body = data.body;
2395
+ this.createdAt = data.createdAt;
2396
+ this.url = data.url;
2397
+ this.session = data.session === undefined ? undefined : new LinearAgentSession(ctx, data.session);
2398
+ this.delivery = data.delivery === undefined ? undefined : new LinearDelivery(ctx, data.delivery);
2399
+ }
2400
+ /** The replies in a comment's thread, once the agent is quiet. Experimental. */
2401
+ async replies() {
2402
+ const ctx = this.#ctx;
2403
+ await untilQuiet(() => quietOf(ctx));
2404
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/comments/${segment(this.id)}/replies`));
2405
+ return decodeLinearCommentReplies(ctx, data);
2406
+ }
2407
+ /** The `Comment` (`create`) delivery this comment caused to this app (decision 0027), or nothing when it wasn't told. The comment's `delivery` is the built-in app's. Experimental. */
2408
+ async deliveryFor(app) {
2409
+ const ctx = this.#ctx;
2410
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/comments/${segment(this.id)}/delivery-for`, { query: { app: app.id } }));
2411
+ return (data === null ? undefined : new LinearDelivery(ctx, data));
2412
+ }
2413
+ /** A comment's thread as a person reads it. Experimental. */
2414
+ async transcript() {
2415
+ const ctx = this.#ctx;
2416
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/comments/${segment(this.id)}/transcript`));
2417
+ return decodeLinearTranscript(ctx, data);
2418
+ }
2419
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2420
+ [QUIET]() {
2421
+ return quietOf(this.#ctx);
2422
+ }
2423
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
2424
+ [CONTEXT]() {
2425
+ return this.#ctx;
2426
+ }
2427
+ }
2428
+ export class LinearIssue {
2429
+ id;
2430
+ identifier;
2431
+ url;
2432
+ team;
2433
+ creator;
2434
+ #ctx;
2435
+ #seen = new Map();
2436
+ /** @internal Handles come from the SDK, never from `new`. */
2437
+ constructor(ctx, data) {
2438
+ this.#ctx = ctx;
2439
+ this.id = data.id;
2440
+ this.identifier = data.identifier;
2441
+ this.url = data.url;
2442
+ this.team = new LinearTeam(ctx, data.team);
2443
+ this.creator = data.creator.kind === "user" ? new LinearUser(ctx, data.creator) : new LinearApp(ctx, data.creator);
2444
+ }
2445
+ /** Read the issue again. Experimental. */
2446
+ async refresh() {
2447
+ const ctx = this.#ctx;
2448
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/issues/${segment(this.id)}`));
2449
+ return new LinearIssue(ctx, data);
2450
+ }
2451
+ /** The issue's title as it is now. Experimental. */
2452
+ async title() {
2453
+ const ctx = this.#ctx;
2454
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/issues/${segment(this.id)}/title`));
2455
+ return data;
2456
+ }
2457
+ /** The issue's workflow state. Experimental. */
2458
+ async state() {
2459
+ const ctx = this.#ctx;
2460
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/issues/${segment(this.id)}/state`));
2461
+ return data;
2462
+ }
2463
+ /** Who the issue is assigned to, if anyone. Experimental. */
2464
+ async assignee() {
2465
+ const ctx = this.#ctx;
2466
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/issues/${segment(this.id)}/assignee`));
2467
+ return (data === null ? undefined : new LinearUser(ctx, data));
2468
+ }
2469
+ /** The app the issue is delegated to, if any. Experimental. */
2470
+ async delegatedTo() {
2471
+ const ctx = this.#ctx;
2472
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/issues/${segment(this.id)}/delegate`));
2473
+ return (data === null ? undefined : new LinearApp(ctx, data));
2474
+ }
2475
+ /** The names of the labels on the issue. Experimental. */
2476
+ async labels() {
2477
+ const ctx = this.#ctx;
2478
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/issues/${segment(this.id)}/labels`));
2479
+ return data;
2480
+ }
2481
+ /** The comments on the issue, oldest first, without the one Linear writes to open a delegated session's thread. Experimental. */
2482
+ async comments() {
2483
+ const ctx = this.#ctx;
2484
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/issues/${segment(this.id)}/comments`));
2485
+ return decodeLinearComments(ctx, data);
2486
+ }
2487
+ /** The agent sessions on the issue, oldest first. Experimental. */
2488
+ async sessions() {
2489
+ const ctx = this.#ctx;
2490
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/issues/${segment(this.id)}/sessions`));
2491
+ return decodeLinearAgentSessions(ctx, data);
2492
+ }
2493
+ /** The issue's latest agent session, waiting for one to be opened. Experimental. */
2494
+ async session() {
2495
+ const ctx = this.#ctx;
2496
+ const data = (await retryWhile(["not_found"], () => ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/issues/${segment(this.id)}/session`)));
2497
+ return new LinearAgentSession(ctx, data);
2498
+ }
2499
+ /** The issue as a person reads it: description, comments and the agent's sessions. Experimental. */
2500
+ async transcript() {
2501
+ const ctx = this.#ctx;
2502
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/issues/${segment(this.id)}/transcript`));
2503
+ return decodeLinearTranscript(ctx, data);
2504
+ }
2505
+ /** Wait for the next new comment matching `from` (anyone if omitted), after the last one this handle saw. */
2506
+ async waitForComment(options = {}) {
2507
+ return waitForNext(this.#seen, "waitForComment", () => this.comments(), (item) => fromMatches(item.author, options.from) && textMatches(item.body, options.body), describeWait("a comment", options.from), options);
2508
+ }
2509
+ /** The latest comment matching `from`, once the agent is quiet. Waits for at least one. */
2510
+ async latestComment(options = {}) {
2511
+ return latestOnceQuiet(() => this.comments(), (item) => fromMatches(item.author, options.from), () => quietOf(this.#ctx), describeWait("a comment", options.from), options);
2512
+ }
2513
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2514
+ [QUIET]() {
2515
+ return quietOf(this.#ctx);
2516
+ }
2517
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
2518
+ [CONTEXT]() {
2519
+ return this.#ctx;
2520
+ }
2521
+ }
2522
+ export class LinearTeam {
2523
+ id;
2524
+ key;
2525
+ name;
2526
+ #ctx;
2527
+ /** @internal Handles come from the SDK, never from `new`. */
2528
+ constructor(ctx, data) {
2529
+ this.#ctx = ctx;
2530
+ this.id = data.id;
2531
+ this.key = data.key;
2532
+ this.name = data.name;
2533
+ }
2534
+ /** An issue of this team by its identifier (`ENG-12`). Experimental. */
2535
+ async issue(identifier) {
2536
+ const ctx = this.#ctx;
2537
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/teams/${segment(this.id)}/issue`, { query: { identifier } }));
2538
+ return new LinearIssue(ctx, data);
2539
+ }
2540
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2541
+ [QUIET]() {
2542
+ return quietOf(this.#ctx);
2543
+ }
2544
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
2545
+ [CONTEXT]() {
2546
+ return this.#ctx;
2547
+ }
2548
+ }
2549
+ export class LinearAgentSession {
2550
+ id;
2551
+ issue;
2552
+ app;
2553
+ startedBy;
2554
+ delivery;
2555
+ #ctx;
2556
+ #seen = new Map();
2557
+ /** @internal Handles come from the SDK, never from `new`. */
2558
+ constructor(ctx, data) {
2559
+ this.#ctx = ctx;
2560
+ this.id = data.id;
2561
+ this.issue = new LinearIssue(ctx, data.issue);
2562
+ this.app = new LinearApp(ctx, data.app);
2563
+ this.startedBy = new LinearUser(ctx, data.startedBy);
2564
+ this.delivery = data.delivery === undefined ? undefined : new LinearDelivery(ctx, data.delivery);
2565
+ }
2566
+ /** The session's status. Experimental. */
2567
+ async state() {
2568
+ const ctx = this.#ctx;
2569
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/agent-sessions/${segment(this.id)}/state`));
2570
+ return data;
2571
+ }
2572
+ /** The session's activities, oldest first: the agent's, and the prompts of people. Experimental. */
2573
+ async activities() {
2574
+ const ctx = this.#ctx;
2575
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/agent-sessions/${segment(this.id)}/activities`));
2576
+ return decodeLinearAgentActivities(ctx, data);
2577
+ }
2578
+ /** The links the agent attached to the session. Experimental. */
2579
+ async externalUrls() {
2580
+ const ctx = this.#ctx;
2581
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/agent-sessions/${segment(this.id)}/external-urls`));
2582
+ return data;
2583
+ }
2584
+ /** The agent's plan: each step and its status. Experimental. */
2585
+ async plan() {
2586
+ const ctx = this.#ctx;
2587
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/agent-sessions/${segment(this.id)}/plan`));
2588
+ return data;
2589
+ }
2590
+ /** The session as a person reads it. Experimental. */
2591
+ async transcript() {
2592
+ const ctx = this.#ctx;
2593
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/agent-sessions/${segment(this.id)}/transcript`));
2594
+ return decodeLinearTranscript(ctx, data);
2595
+ }
2596
+ /** Wait for the agent session to reach that state: one of the values given. Resolves with the value as it is then. */
2597
+ async waitForState(wanted, options = {}) {
2598
+ const values = [wanted].flat();
2599
+ return waitFor("the agent session to reach that state", async () => {
2600
+ const value = await this.state();
2601
+ return values.includes(value) ? value : undefined;
2602
+ }, options);
2603
+ }
2604
+ /** Wait for the next new activity, after the last one this handle saw. */
2605
+ async waitForActivity(options = {}) {
2606
+ return waitForNext(this.#seen, "waitForActivity", () => this.activities(), (item) => textMatches(item.type, options.type), "an activity", options, (item) => item.type === "prompt");
2607
+ }
2608
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2609
+ [QUIET]() {
2610
+ return quietOf(this.#ctx);
2611
+ }
2612
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
2613
+ [CONTEXT]() {
2614
+ return this.#ctx;
2615
+ }
2616
+ }
2617
+ export class LinearDelivery {
2618
+ id;
2619
+ channel;
2620
+ app;
2621
+ type;
2622
+ action;
2623
+ webhookId;
2624
+ payload;
2625
+ attempts;
2626
+ status;
2627
+ #ctx;
2628
+ /** @internal Handles come from the SDK, never from `new`. */
2629
+ constructor(ctx, data) {
2630
+ this.#ctx = ctx;
2631
+ this.id = data.id;
2632
+ this.channel = data.channel;
2633
+ this.app = data.app;
2634
+ this.type = data.type;
2635
+ this.action = data.action;
2636
+ this.webhookId = data.webhookId;
2637
+ this.payload = data.payload;
2638
+ this.attempts = data.attempts;
2639
+ this.status = data.status;
2640
+ }
2641
+ /** Re-read a delivery: its attempts and status. Experimental. */
2642
+ async refresh() {
2643
+ const ctx = this.#ctx;
2644
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/linear/deliveries/${segment(this.id)}`));
2645
+ return new LinearDelivery(ctx, data);
2646
+ }
2647
+ /** Redeliver, as Linear retries: the same delivery, with a new `webhookTimestamp` and a new signature. Experimental. */
2648
+ async redeliver() {
2649
+ const ctx = this.#ctx;
2650
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/linear/deliveries/${segment(this.id)}/redeliver`));
2651
+ return data;
2652
+ }
2653
+ /** Send the delivery again: stale (its `webhookTimestamp` two minutes old), or signed with a secret that isn't the app's. Experimental. */
2654
+ async resend(options = {}) {
2655
+ const ctx = this.#ctx;
2656
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/linear/deliveries/${segment(this.id)}/resend`, { body: { badSignature: options.badSignature, stale: options.stale } }));
2657
+ return data;
2658
+ }
2659
+ /** Wait for the delivery to settle, and resolve with the value as it is then. */
2660
+ async settled(options = {}) {
2661
+ return waitFor("the delivery to settle", async () => {
2662
+ const value = await this.refresh();
2663
+ return value.status === "pending" ? undefined : value;
2664
+ }, options);
2665
+ }
2666
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2667
+ [QUIET]() {
2668
+ return quietOf(this.#ctx);
2669
+ }
2670
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
2671
+ [CONTEXT]() {
2672
+ return this.#ctx;
2673
+ }
2674
+ }
2675
+ export class LinearAgentActivity {
2676
+ id;
2677
+ session;
2678
+ type;
2679
+ author;
2680
+ body;
2681
+ action;
2682
+ ephemeral;
2683
+ createdAt;
2684
+ #ctx;
2685
+ /** @internal Handles come from the SDK, never from `new`. */
2686
+ constructor(ctx, data) {
2687
+ this.#ctx = ctx;
2688
+ this.id = data.id;
2689
+ this.session = new LinearAgentSession(ctx, data.session);
2690
+ this.type = data.type;
2691
+ this.author = data.author.kind === "user" ? new LinearUser(ctx, data.author) : new LinearApp(ctx, data.author);
2692
+ this.body = data.body;
2693
+ this.action = data.action;
2694
+ this.ephemeral = data.ephemeral;
2695
+ this.createdAt = data.createdAt;
2696
+ }
2697
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2698
+ [QUIET]() {
2699
+ return quietOf(this.#ctx);
2700
+ }
2701
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
2702
+ [CONTEXT]() {
2703
+ return this.#ctx;
2704
+ }
2705
+ }
2706
+ export class NotionFixture {
2707
+ app;
2708
+ apiUrl;
2709
+ #ctx;
2710
+ #seen = new Map();
2711
+ /** @internal Handles come from the SDK, never from `new`. */
2712
+ constructor(ctx, data) {
2713
+ this.#ctx = ctx;
2714
+ this.app = new NotionIntegration(ctx, data.app);
2715
+ this.apiUrl = data.apiUrl;
2716
+ }
2717
+ /** Create a person in the workspace. Experimental. */
2718
+ async createUser(options) {
2719
+ const ctx = this.#ctx;
2720
+ 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 }) } }));
2721
+ return new NotionUser(ctx, data);
2722
+ }
2723
+ /** The people this session created. Experimental. */
2724
+ async users() {
2725
+ const ctx = this.#ctx;
2726
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/notion/users`));
2727
+ return decodeNotionUsers(ctx, data);
2728
+ }
2729
+ /** Make another internal integration in the workspace, with its own bot user, token and webhook subscription (decision 0027), or return the one made with this name and settings. Its events go to CHANNELSTACK_NOTION_APP_<NAME>_WEBHOOK_URL, and it sees only the pages connected to it. Experimental. */
2730
+ async createApp(options) {
2731
+ const ctx = this.#ctx;
2732
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/apps`, { body: { name: options.name, capabilities: options.capabilities, events: options.events } }));
2733
+ return new NotionIntegration(ctx, data);
2734
+ }
2735
+ /** The integrations this session used: the built-in one first, then each it got from `createApp`, in the order it first did. Another session's are `not_found` here. Experimental. */
2736
+ async apps() {
2737
+ const ctx = this.#ctx;
2738
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/notion/apps`));
2739
+ return decodeNotionIntegrations(ctx, data);
2740
+ }
2741
+ /** The pages this session created, a database's rows included, read again from Notion live, oldest first. Not those in the trash. Experimental. */
2742
+ async pages() {
2743
+ const ctx = this.#ctx;
2744
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/notion/pages`));
2745
+ return decodeNotionPages(ctx, data);
2746
+ }
2747
+ /** 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. */
2748
+ async createPage(options) {
2749
+ const ctx = this.#ctx;
2750
+ 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 } }));
2751
+ return new NotionPage(ctx, data);
2752
+ }
2753
+ /** Create a database with its property schema and rows, as seed data. Experimental. */
2754
+ async createDatabase(options) {
2755
+ const ctx = this.#ctx;
2756
+ 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) } }));
2757
+ return new NotionDatabase(ctx, data);
2758
+ }
2759
+ /** How long Notion holds `page.content_updated` to batch edits, for this session (fake only). Default one second. Experimental. */
2760
+ async setContentUpdateDelay(delay) {
2761
+ const ctx = this.#ctx;
2762
+ await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/content-delay`, { body: { delay: parseDuration(delay) } });
2763
+ }
2764
+ /** Send a subscription's verification request (`{ verification_token }`), as Notion does once when a subscription is created: the built-in integration's, or the one given's. Experimental. */
2765
+ async sendVerification(options = {}) {
2766
+ const ctx = this.#ctx;
2767
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/verification`, { body: { app: options.app === undefined ? undefined : options.app.id } }));
2768
+ return (data === null ? undefined : new NotionDelivery(ctx, data));
2769
+ }
2770
+ /** Every webhook channelstack sent the agent for this session, with every attempt. Experimental. */
2771
+ async deliveries(options = {}) {
2772
+ const ctx = this.#ctx;
2773
+ 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, app: options.app === undefined ? undefined : options.app.id } }));
2774
+ return decodeNotionDeliveries(ctx, data);
2775
+ }
2776
+ /** The REST calls the agent made about this session's pages, by the client's method name (`comments.create`). Experimental. */
2777
+ async calls(options = {}) {
2778
+ const ctx = this.#ctx;
2779
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/notion/calls`, { query: { operation: options.operation, error: options.error } }));
2780
+ return data;
2781
+ }
2782
+ /** Wait for the next new API call from the agent, after the last one this handle saw. */
2783
+ async waitForCall(filter = {}, options = {}) {
2784
+ return waitForNext(this.#seen, `waitForCall:${JSON.stringify(filter)}`, () => this.calls(filter), () => true, "an API call from the agent", options);
2785
+ }
2786
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2787
+ [QUIET]() {
2788
+ return quietOf(this.#ctx);
2789
+ }
2790
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
2791
+ [CONTEXT]() {
2792
+ return this.#ctx;
2793
+ }
2794
+ }
2795
+ export class NotionIntegration {
2796
+ id;
2797
+ name;
2798
+ kind;
2799
+ channel;
2800
+ botUserId;
2801
+ token;
2802
+ webhookSecret;
2803
+ #ctx;
2804
+ /** @internal Handles come from the SDK, never from `new`. */
2805
+ constructor(ctx, data) {
2806
+ this.#ctx = ctx;
2807
+ this.id = data.id;
2808
+ this.name = data.name;
2809
+ this.kind = data.kind;
2810
+ this.channel = data.channel;
2811
+ this.botUserId = data.botUserId;
2812
+ this.token = data.token;
2813
+ this.webhookSecret = data.webhookSecret;
2814
+ }
2815
+ /** An integration a test made starts a discussion on a page, or anchored to the block with `anchor` in its text, as its own `comments.create` would: on a page connected to it, mentioning people only. Sends `comment.created` to every integration that sees the page. Experimental. */
2816
+ async comment(text, options) {
2817
+ const ctx = this.#ctx;
2818
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/apps/${segment(this.id)}/comment`, { body: { text, page: options.page.id, anchor: options.anchor === undefined ? undefined : patternOnWire(options.anchor) } }));
2819
+ return new NotionComment(ctx, data);
2820
+ }
2821
+ /** An integration a test made replies in a discussion, as `comments.create` with `discussion_id` would. Sends `comment.created`. Experimental. */
2822
+ async reply(text, options) {
2823
+ const ctx = this.#ctx;
2824
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/apps/${segment(this.id)}/reply`, { body: { text, discussion: options.discussion.id } }));
2825
+ return new NotionComment(ctx, data);
2826
+ }
2827
+ /** An integration a test made edits a page's body, as its own block calls would: append, or replace it. Sends one `page.content_updated` once Notion's batching delay is over. Experimental. */
2828
+ async edit(change, options) {
2829
+ const ctx = this.#ctx;
2830
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/apps/${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 } }));
2831
+ return (data === null ? undefined : new NotionDelivery(ctx, data));
2832
+ }
2833
+ /** An integration a test made changes a page's title, as its own `pages.update` would. Sends `page.properties_updated`. Experimental. */
2834
+ async rename(title, options) {
2835
+ const ctx = this.#ctx;
2836
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/apps/${segment(this.id)}/rename`, { body: { title, page: options.page.id } }));
2837
+ return (data === null ? undefined : new NotionDelivery(ctx, data));
2838
+ }
2839
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2840
+ [QUIET]() {
2841
+ return quietOf(this.#ctx);
2842
+ }
2843
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
2844
+ [CONTEXT]() {
2845
+ return this.#ctx;
2846
+ }
2847
+ }
2848
+ export class NotionUser {
2849
+ id;
2850
+ name;
2851
+ kind;
2852
+ channel;
2853
+ email;
2854
+ #ctx;
2855
+ /** @internal Handles come from the SDK, never from `new`. */
2856
+ constructor(ctx, data) {
2857
+ this.#ctx = ctx;
2858
+ this.id = data.id;
2859
+ this.name = data.name;
2860
+ this.kind = data.kind;
2861
+ this.channel = data.channel;
2862
+ this.email = data.email;
2863
+ }
2864
+ /** 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. */
2865
+ async comment(text, options) {
2866
+ const ctx = this.#ctx;
2867
+ 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) } }));
2868
+ return new NotionComment(ctx, data);
2869
+ }
2870
+ /** Reply in a discussion. Sends `comment.created`. Experimental. */
2871
+ async reply(text, options) {
2872
+ const ctx = this.#ctx;
2873
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/users/${segment(this.id)}/reply`, { body: { text, discussion: options.discussion.id } }));
2874
+ return new NotionComment(ctx, data);
2875
+ }
2876
+ /** Edit one of this person's comments. Sends `comment.updated`. Experimental. */
2877
+ async editComment(text, options) {
2878
+ const ctx = this.#ctx;
2879
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/users/${segment(this.id)}/edit-comment`, { body: { text, comment: options.comment.id } }));
2880
+ return (data === null ? undefined : new NotionDelivery(ctx, data));
2881
+ }
2882
+ /** Delete one of this person's comments. Sends `comment.deleted`. Experimental. */
2883
+ async deleteComment(options) {
2884
+ const ctx = this.#ctx;
2885
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/users/${segment(this.id)}/delete-comment`, { body: { comment: options.comment.id } }));
2886
+ return (data === null ? undefined : new NotionDelivery(ctx, data));
2887
+ }
2888
+ /** Resolve a discussion. Notion sends no event for it, and the API no longer lists its comments. Experimental. */
2889
+ async resolve(options) {
2890
+ const ctx = this.#ctx;
2891
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/users/${segment(this.id)}/resolve`, { body: { discussion: options.discussion.id } }));
2892
+ return (data === null ? undefined : new NotionDelivery(ctx, data));
2893
+ }
2894
+ /** Reopen a resolved discussion. Experimental. */
2895
+ async reopen(options) {
2896
+ const ctx = this.#ctx;
2897
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/users/${segment(this.id)}/reopen`, { body: { discussion: options.discussion.id } }));
2898
+ return (data === null ? undefined : new NotionDelivery(ctx, data));
2899
+ }
2900
+ /** Create a page as this person. Sends `page.created` if the integration can see it. Experimental. */
2901
+ async createPage(page) {
2902
+ const ctx = this.#ctx;
2903
+ 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) } } }));
2904
+ return new NotionPage(ctx, data);
2905
+ }
2906
+ /** Edit a page's body: append, or replace it. Sends one `page.content_updated` once Notion's batching delay is over. Experimental. */
2907
+ async edit(change, options) {
2908
+ const ctx = this.#ctx;
2909
+ 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 } }));
2910
+ return (data === null ? undefined : new NotionDelivery(ctx, data));
2911
+ }
2912
+ /** Change a page's title. Sends `page.properties_updated`. Experimental. */
2913
+ async rename(title, options) {
2914
+ const ctx = this.#ctx;
2915
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/users/${segment(this.id)}/rename`, { body: { title, page: options.page.id } }));
2916
+ return (data === null ? undefined : new NotionDelivery(ctx, data));
2917
+ }
2918
+ /** 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. */
2919
+ async mention(integration, options) {
2920
+ const ctx = this.#ctx;
2921
+ 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) } }));
2922
+ return (data === null ? undefined : new NotionDelivery(ctx, data));
2923
+ }
2924
+ /** Set a property of a database row. Sends `page.properties_updated`. Experimental. */
2925
+ async setProperty(name, value, options) {
2926
+ const ctx = this.#ctx;
2927
+ 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 } }));
2928
+ return (data === null ? undefined : new NotionDelivery(ctx, data));
2929
+ }
2930
+ /** Add a row to a database. Sends `page.created` if the integration can see the database. Experimental. */
2931
+ async addRow(values, options) {
2932
+ const ctx = this.#ctx;
2933
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/users/${segment(this.id)}/rows`, { body: { values, database: options.database.id } }));
2934
+ return new NotionPage(ctx, data);
2935
+ }
2936
+ /** Connect the integration to a page (Share → Connections): it sees the page and everything under it. Experimental. */
2937
+ async connect(integration, options) {
2938
+ const ctx = this.#ctx;
2939
+ await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/users/${segment(this.id)}/connect`, { body: { integration: integration.id, page: options.page.id } });
2940
+ }
2941
+ /** Remove the integration's connection from a page. Experimental. */
2942
+ async disconnect(integration, options) {
2943
+ const ctx = this.#ctx;
2944
+ await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/users/${segment(this.id)}/disconnect`, { body: { integration: integration.id, page: options.page.id } });
2945
+ }
2946
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2947
+ [QUIET]() {
2948
+ return quietOf(this.#ctx);
2949
+ }
2950
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
2951
+ [CONTEXT]() {
2952
+ return this.#ctx;
2953
+ }
2954
+ }
2955
+ export class NotionComment {
2956
+ id;
2957
+ discussion;
2958
+ author;
2959
+ text;
2960
+ createdAt;
2961
+ delivery;
2962
+ #ctx;
2963
+ /** @internal Handles come from the SDK, never from `new`. */
2964
+ constructor(ctx, data) {
2965
+ this.#ctx = ctx;
2966
+ this.id = data.id;
2967
+ this.discussion = new NotionDiscussion(ctx, data.discussion);
2968
+ this.author = data.author.kind === "user" ? new NotionUser(ctx, data.author) : new NotionIntegration(ctx, data.author);
2969
+ this.text = data.text;
2970
+ this.createdAt = data.createdAt;
2971
+ this.delivery = data.delivery === undefined ? undefined : new NotionDelivery(ctx, data.delivery);
2972
+ }
2973
+ /** The `comment.created` delivery this comment caused to this integration (decision 0027), or nothing when it wasn't told. The comment's `delivery` is the built-in integration's. Experimental. */
2974
+ async deliveryFor(app) {
2975
+ const ctx = this.#ctx;
2976
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/notion/comments/${segment(this.id)}/delivery-for`, { query: { app: app.id } }));
2977
+ return (data === null ? undefined : new NotionDelivery(ctx, data));
2978
+ }
2979
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
2980
+ [QUIET]() {
2981
+ return quietOf(this.#ctx);
2982
+ }
2983
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
2984
+ [CONTEXT]() {
2985
+ return this.#ctx;
2986
+ }
2987
+ }
2988
+ export class NotionDiscussion {
2989
+ id;
2990
+ page;
2991
+ anchor;
2992
+ #ctx;
2993
+ #seen = new Map();
2994
+ /** @internal Handles come from the SDK, never from `new`. */
2995
+ constructor(ctx, data) {
2996
+ this.#ctx = ctx;
2997
+ this.id = data.id;
2998
+ this.page = new NotionPage(ctx, data.page);
2999
+ this.anchor = data.anchor;
3000
+ }
3001
+ /** The discussion's comments, oldest first. Experimental. */
3002
+ async comments() {
3003
+ const ctx = this.#ctx;
3004
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/notion/discussions/${segment(this.id)}/comments`));
3005
+ return decodeNotionComments(ctx, data);
3006
+ }
3007
+ /** Whether the discussion is resolved. Experimental. */
3008
+ async resolved() {
3009
+ const ctx = this.#ctx;
3010
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/notion/discussions/${segment(this.id)}/resolved`));
3011
+ return data;
3012
+ }
3013
+ /** The discussion as a person reads it. Experimental. */
3014
+ async transcript() {
3015
+ const ctx = this.#ctx;
3016
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/notion/discussions/${segment(this.id)}/transcript`));
3017
+ return decodeNotionTranscript(ctx, data);
3018
+ }
3019
+ /** Wait for the next new comment matching `from` (anyone if omitted), after the last one this handle saw. */
3020
+ async waitForComment(options = {}) {
3021
+ return waitForNext(this.#seen, "waitForComment", () => this.comments(), (item) => fromMatches(item.author, options.from), describeWait("a comment", options.from), options);
3022
+ }
3023
+ /** The latest comment matching `from`, once the agent is quiet. Waits for at least one. */
3024
+ async latestComment(options = {}) {
3025
+ return latestOnceQuiet(() => this.comments(), (item) => fromMatches(item.author, options.from), () => quietOf(this.#ctx), describeWait("a comment", options.from), options);
3026
+ }
3027
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
3028
+ [QUIET]() {
3029
+ return quietOf(this.#ctx);
3030
+ }
3031
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
3032
+ [CONTEXT]() {
3033
+ return this.#ctx;
3034
+ }
3035
+ }
3036
+ export class NotionPage {
3037
+ id;
3038
+ channel;
3039
+ title;
3040
+ url;
3041
+ #ctx;
3042
+ /** @internal Handles come from the SDK, never from `new`. */
3043
+ constructor(ctx, data) {
3044
+ this.#ctx = ctx;
3045
+ this.id = data.id;
3046
+ this.channel = data.channel;
3047
+ this.title = data.title;
3048
+ this.url = data.url;
3049
+ }
3050
+ /** The page's discussions: on the page itself, and on its blocks. Experimental. */
3051
+ async discussions() {
3052
+ const ctx = this.#ctx;
3053
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/notion/pages/${segment(this.id)}/discussions`));
3054
+ return decodeNotionDiscussions(ctx, data);
3055
+ }
3056
+ /** The page body as Markdown, once the agent is quiet. Experimental. */
3057
+ async markdown() {
3058
+ const ctx = this.#ctx;
3059
+ await untilQuiet(() => quietOf(ctx));
3060
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/notion/pages/${segment(this.id)}/markdown`));
3061
+ return data;
3062
+ }
3063
+ /** The page's blocks as the API has them, with nested blocks under `children`. Experimental. */
3064
+ async blocks() {
3065
+ const ctx = this.#ctx;
3066
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/notion/pages/${segment(this.id)}/blocks`));
3067
+ return data;
3068
+ }
3069
+ /** A property's value as a person reads it: text, a number, option names, ids. Experimental. */
3070
+ async property(name) {
3071
+ const ctx = this.#ctx;
3072
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/notion/pages/${segment(this.id)}/property`, { query: { name } }));
3073
+ return decodeNotionPropertyValue(ctx, data);
3074
+ }
3075
+ /** The pages directly under this page. Experimental. */
3076
+ async children() {
3077
+ const ctx = this.#ctx;
3078
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/notion/pages/${segment(this.id)}/children`));
3079
+ return decodeNotionChildPages(ctx, data);
3080
+ }
3081
+ /** The integrations that can see the page: connected to it or to a page above it. Experimental. */
3082
+ async connections() {
3083
+ const ctx = this.#ctx;
3084
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/notion/pages/${segment(this.id)}/connections`));
3085
+ return decodeNotionConnections(ctx, data);
3086
+ }
3087
+ /** The page and its discussions as a person reads them. Experimental. */
3088
+ async transcript() {
3089
+ const ctx = this.#ctx;
3090
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/notion/pages/${segment(this.id)}/transcript`));
3091
+ return decodeNotionTranscript(ctx, data);
3092
+ }
3093
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
3094
+ [QUIET]() {
3095
+ return quietOf(this.#ctx);
3096
+ }
3097
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
3098
+ [CONTEXT]() {
3099
+ return this.#ctx;
3100
+ }
3101
+ }
3102
+ export class NotionDelivery {
3103
+ id;
3104
+ channel;
3105
+ app;
3106
+ type;
3107
+ entity;
3108
+ payload;
3109
+ attempts;
3110
+ status;
3111
+ #ctx;
3112
+ /** @internal Handles come from the SDK, never from `new`. */
3113
+ constructor(ctx, data) {
3114
+ this.#ctx = ctx;
3115
+ this.id = data.id;
3116
+ this.channel = data.channel;
3117
+ this.app = data.app;
3118
+ this.type = data.type;
3119
+ this.entity = data.entity;
3120
+ this.payload = data.payload;
3121
+ this.attempts = data.attempts;
3122
+ this.status = data.status;
3123
+ }
3124
+ /** Re-read a delivery: its attempts and status. Experimental. */
3125
+ async refresh() {
3126
+ const ctx = this.#ctx;
3127
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/notion/deliveries/${segment(this.id)}`));
3128
+ return new NotionDelivery(ctx, data);
3129
+ }
3130
+ /** Send the same event again, as a retry does: the same body, the next `attempt_number`, signed again. Experimental. */
3131
+ async redeliver() {
3132
+ const ctx = this.#ctx;
3133
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/deliveries/${segment(this.id)}/redeliver`));
3134
+ return data;
3135
+ }
3136
+ /** Send the delivery again, signed with a token that isn't the subscription's. Experimental. */
3137
+ async resend(options = {}) {
3138
+ const ctx = this.#ctx;
3139
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/deliveries/${segment(this.id)}/resend`, { body: { badSignature: options.badSignature } }));
3140
+ return data;
3141
+ }
3142
+ /** Wait for the delivery to settle, and resolve with the value as it is then. */
3143
+ async settled(options = {}) {
3144
+ return waitFor("the delivery to settle", async () => {
3145
+ const value = await this.refresh();
3146
+ return value.status === "pending" ? undefined : value;
3147
+ }, options);
3148
+ }
3149
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
3150
+ [QUIET]() {
3151
+ return quietOf(this.#ctx);
3152
+ }
3153
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
3154
+ [CONTEXT]() {
3155
+ return this.#ctx;
3156
+ }
3157
+ }
3158
+ export class NotionDatabase {
3159
+ id;
3160
+ channel;
3161
+ title;
3162
+ url;
3163
+ #ctx;
3164
+ /** @internal Handles come from the SDK, never from `new`. */
3165
+ constructor(ctx, data) {
3166
+ this.#ctx = ctx;
3167
+ this.id = data.id;
3168
+ this.channel = data.channel;
3169
+ this.title = data.title;
3170
+ this.url = data.url;
3171
+ }
3172
+ /** The rows of a database, optionally only those whose properties have these values. Experimental. */
3173
+ async rows(filter) {
3174
+ const ctx = this.#ctx;
3175
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/notion/databases/${segment(this.id)}/rows`, { body: { filter } }));
3176
+ return decodeNotionRows(ctx, data);
3177
+ }
3178
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
3179
+ [QUIET]() {
3180
+ return quietOf(this.#ctx);
3181
+ }
3182
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
3183
+ [CONTEXT]() {
3184
+ return this.#ctx;
3185
+ }
3186
+ }
3187
+ export class ResendFixture {
3188
+ app;
3189
+ apiUrl;
3190
+ #ctx;
3191
+ #seen = new Map();
3192
+ /** @internal Handles come from the SDK, never from `new`. */
3193
+ constructor(ctx, data) {
3194
+ this.#ctx = ctx;
3195
+ this.app = new ResendApp(ctx, data.app);
3196
+ this.apiUrl = data.apiUrl;
3197
+ }
3198
+ /** Make another app: a team of its own, with its own address and credentials (decision 0027), or return the one made with this name and settings. Its events go to CHANNELSTACK_RESEND_APP_<NAME>_WEBHOOK_URL. Experimental. */
3199
+ async createApp(options) {
3200
+ const ctx = this.#ctx;
3201
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/resend/apps`, { body: { name: options.name, domain: options.domain } }));
3202
+ return new ResendApp(ctx, data);
3203
+ }
3204
+ /** The teams this session used: the agent's first, then each it got from `createApp`, in the order it first did. Another session's are `not_found` here. Experimental. */
3205
+ async apps() {
3206
+ const ctx = this.#ctx;
3207
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/resend/apps`));
3208
+ return decodeResendApps(ctx, data);
3209
+ }
3210
+ /** Create a person: a mailbox, at `<name>@example.com` unless a test gives the address. Experimental. */
3211
+ async createUser(options) {
3212
+ const ctx = this.#ctx;
3213
+ 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 }) } }));
3214
+ return new ResendUser(ctx, data);
3215
+ }
3216
+ /** The people this session created. Experimental. */
3217
+ async users() {
3218
+ const ctx = this.#ctx;
3219
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/resend/users`));
3220
+ return decodeResendUsers(ctx, data);
3221
+ }
3222
+ /** The threads this session's people started, oldest first. Experimental. */
3223
+ async threads() {
3224
+ const ctx = this.#ctx;
3225
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/resend/threads`));
3226
+ return decodeResendThreads(ctx, data);
3227
+ }
3228
+ /** Every webhook channelstack sent the agent for this session, with every attempt. Experimental. */
3229
+ async deliveries(options = {}) {
3230
+ const ctx = this.#ctx;
3231
+ 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, app: options.app === undefined ? undefined : options.app.id } }));
3232
+ return decodeResendDeliveries(ctx, data);
3233
+ }
3234
+ /** The REST calls the agent made about this session's emails, by the SDK's method name (`emails.send`). Experimental. */
3235
+ async calls(options = {}) {
3236
+ const ctx = this.#ctx;
3237
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/resend/calls`, { query: { operation: options.operation, error: options.error } }));
3238
+ return data;
3239
+ }
3240
+ /** Wait for the next new API call from the agent, after the last one this handle saw. */
3241
+ async waitForCall(filter = {}, options = {}) {
3242
+ return waitForNext(this.#seen, `waitForCall:${JSON.stringify(filter)}`, () => this.calls(filter), () => true, "an API call from the agent", options);
3243
+ }
3244
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
3245
+ [QUIET]() {
3246
+ return quietOf(this.#ctx);
3247
+ }
3248
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
3249
+ [CONTEXT]() {
3250
+ return this.#ctx;
3251
+ }
3252
+ }
3253
+ export class ResendApp {
3254
+ id;
3255
+ channel;
3256
+ kind;
3257
+ name;
3258
+ botUserId;
3259
+ address;
3260
+ domain;
3261
+ apiKey;
3262
+ webhookSecret;
3263
+ #ctx;
3264
+ /** @internal Handles come from the SDK, never from `new`. */
3265
+ constructor(ctx, data) {
3266
+ this.#ctx = ctx;
3267
+ this.id = data.id;
3268
+ this.channel = data.channel;
3269
+ this.kind = data.kind;
3270
+ this.name = data.name;
3271
+ this.botUserId = data.botUserId;
3272
+ this.address = data.address;
3273
+ this.domain = data.domain;
3274
+ this.apiKey = data.apiKey;
3275
+ this.webhookSecret = data.webhookSecret;
3276
+ }
3277
+ /** An app a test made sends an email, through its own team's API, as its own call would. Experimental. */
3278
+ async send(options) {
3279
+ const ctx = this.#ctx;
3280
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/resend/apps/${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, headers: options.headers } }));
3281
+ return new ResendEmail(ctx, data);
3282
+ }
3283
+ /** An app a test made replies to an email, in its thread, as its own call would. Experimental. */
3284
+ async reply(email, options = {}) {
3285
+ const ctx = this.#ctx;
3286
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/resend/apps/${segment(this.id)}/reply`, { body: { email: email.id, text: options.text, html: options.html, all: options.all, headers: options.headers } }));
3287
+ return new ResendEmail(ctx, data);
3288
+ }
3289
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
3290
+ [QUIET]() {
3291
+ return quietOf(this.#ctx);
3292
+ }
3293
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
3294
+ [CONTEXT]() {
3295
+ return this.#ctx;
3296
+ }
3297
+ }
3298
+ export class ResendEmail {
3299
+ id;
3300
+ channel;
3301
+ thread;
3302
+ author;
3303
+ from;
3304
+ to;
3305
+ cc;
3306
+ subject;
3307
+ text;
3308
+ at;
3309
+ messageId;
3310
+ headers;
3311
+ delivery;
3312
+ #ctx;
3313
+ /** @internal Handles come from the SDK, never from `new`. */
3314
+ constructor(ctx, data) {
3315
+ this.#ctx = ctx;
3316
+ this.id = data.id;
3317
+ this.channel = data.channel;
3318
+ this.thread = new ResendThread(ctx, data.thread);
3319
+ this.author = data.author;
3320
+ this.from = data.from;
3321
+ this.to = data.to;
3322
+ this.cc = data.cc;
3323
+ this.subject = data.subject;
3324
+ this.text = data.text;
3325
+ this.at = data.at;
3326
+ this.messageId = data.messageId;
3327
+ this.headers = data.headers;
3328
+ this.delivery = data.delivery === undefined ? undefined : new ResendDelivery(ctx, data.delivery);
3329
+ }
3330
+ /** Re-read an email. Experimental. */
3331
+ async refresh() {
3332
+ const ctx = this.#ctx;
3333
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/resend/emails/${segment(this.id)}`));
3334
+ return new ResendEmail(ctx, data);
3335
+ }
3336
+ /** The delivery that told this app of the email (decision 0027), or nothing when it wasn't told. Experimental. */
3337
+ async deliveryFor(app) {
3338
+ const ctx = this.#ctx;
3339
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/resend/emails/${segment(this.id)}/delivery-for`, { query: { app: app.id } }));
3340
+ return (data === null ? undefined : new ResendDelivery(ctx, data));
3341
+ }
3342
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
3343
+ [QUIET]() {
3344
+ return quietOf(this.#ctx);
3345
+ }
3346
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
3347
+ [CONTEXT]() {
3348
+ return this.#ctx;
3349
+ }
3350
+ }
3351
+ export class ResendThread {
3352
+ id;
3353
+ channel;
3354
+ subject;
3355
+ #ctx;
3356
+ #seen = new Map();
3357
+ /** @internal Handles come from the SDK, never from `new`. */
3358
+ constructor(ctx, data) {
3359
+ this.#ctx = ctx;
3360
+ this.id = data.id;
3361
+ this.channel = data.channel;
3362
+ this.subject = data.subject;
3363
+ }
3364
+ /** Every email in the thread, oldest first. Experimental. */
3365
+ async messages() {
3366
+ const ctx = this.#ctx;
3367
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/resend/threads/${segment(this.id)}/messages`));
3368
+ return decodeResendMessages(ctx, data);
3369
+ }
3370
+ /** The thread's answers: every email after the first, oldest first. Experimental. */
3371
+ async replies() {
3372
+ const ctx = this.#ctx;
3373
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/resend/threads/${segment(this.id)}/replies`));
3374
+ return decodeResendReplies(ctx, data);
3375
+ }
3376
+ /** The thread as a person reads it: each email's own words, without the quoted history. Experimental. */
3377
+ async transcript() {
3378
+ const ctx = this.#ctx;
3379
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/resend/threads/${segment(this.id)}/transcript`));
3380
+ return decodeResendTranscript(ctx, data);
3381
+ }
3382
+ /** Wait for the next new reply matching `from` (anyone if omitted), after the last one this handle saw. */
3383
+ async waitForReply(options = {}) {
3384
+ return waitForNext(this.#seen, "waitForReply", () => this.replies(), (item) => fromMatches(item.author, options.from), describeWait("a reply", options.from), options);
3385
+ }
3386
+ /** The latest reply matching `from`, once the agent is quiet. Waits for at least one. */
3387
+ async latestReply(options = {}) {
3388
+ return latestOnceQuiet(() => this.replies(), (item) => fromMatches(item.author, options.from), () => quietOf(this.#ctx), describeWait("a reply", options.from), options);
3389
+ }
3390
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
3391
+ [QUIET]() {
3392
+ return quietOf(this.#ctx);
3393
+ }
3394
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
3395
+ [CONTEXT]() {
3396
+ return this.#ctx;
3397
+ }
3398
+ }
3399
+ export class ResendDelivery {
3400
+ id;
3401
+ channel;
3402
+ app;
3403
+ type;
3404
+ email;
3405
+ payload;
3406
+ attempts;
3407
+ status;
3408
+ #ctx;
3409
+ /** @internal Handles come from the SDK, never from `new`. */
3410
+ constructor(ctx, data) {
3411
+ this.#ctx = ctx;
3412
+ this.id = data.id;
3413
+ this.channel = data.channel;
3414
+ this.app = data.app;
3415
+ this.type = data.type;
3416
+ this.email = data.email;
3417
+ this.payload = data.payload;
3418
+ this.attempts = data.attempts;
3419
+ this.status = data.status;
3420
+ }
3421
+ /** Re-read a delivery: its attempts and status. Experimental. */
3422
+ async refresh() {
3423
+ const ctx = this.#ctx;
3424
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/resend/deliveries/${segment(this.id)}`));
3425
+ return new ResendDelivery(ctx, data);
3426
+ }
3427
+ /** Send the same webhook again, as Resend retries: the same `svix-id`, signed again. Experimental. */
3428
+ async redeliver() {
3429
+ const ctx = this.#ctx;
3430
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/resend/deliveries/${segment(this.id)}/redeliver`));
3431
+ return data;
3432
+ }
3433
+ /** 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. */
3434
+ async resend(options = {}) {
3435
+ const ctx = this.#ctx;
3436
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/resend/deliveries/${segment(this.id)}/resend`, { body: { badSignature: options.badSignature, stale: options.stale } }));
3437
+ return data;
3438
+ }
3439
+ /** Wait for the delivery to settle, and resolve with the value as it is then. */
3440
+ async settled(options = {}) {
3441
+ return waitFor("the delivery to settle", async () => {
3442
+ const value = await this.refresh();
3443
+ return value.status === "pending" ? undefined : value;
3444
+ }, options);
3445
+ }
3446
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
3447
+ [QUIET]() {
3448
+ return quietOf(this.#ctx);
3449
+ }
3450
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
3451
+ [CONTEXT]() {
3452
+ return this.#ctx;
3453
+ }
3454
+ }
3455
+ export class ResendUser {
3456
+ id;
3457
+ channel;
3458
+ kind;
3459
+ name;
3460
+ address;
3461
+ #ctx;
3462
+ #seen = new Map();
3463
+ /** @internal Handles come from the SDK, never from `new`. */
3464
+ constructor(ctx, data) {
3465
+ this.#ctx = ctx;
3466
+ this.id = data.id;
3467
+ this.channel = data.channel;
3468
+ this.kind = data.kind;
3469
+ this.name = data.name;
3470
+ this.address = data.address;
3471
+ }
3472
+ /** The person emails someone: the agent (`resend.app`), another app, or another person. Experimental. */
3473
+ async send(options) {
3474
+ const ctx = this.#ctx;
3475
+ 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 } }));
3476
+ return new ResendEmail(ctx, data);
3477
+ }
3478
+ /** The person replies to an email, in its thread: `Re:` its subject, with `In-Reply-To` and `References`. Experimental. */
3479
+ async reply(email, options = {}) {
3480
+ const ctx = this.#ctx;
3481
+ 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 } }));
3482
+ return new ResendEmail(ctx, data);
3483
+ }
3484
+ /** What reached the person's mailbox, oldest first. Experimental. */
3485
+ async inbox() {
3486
+ const ctx = this.#ctx;
3487
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/resend/users/${segment(this.id)}/inbox`));
3488
+ return decodeResendInbox(ctx, data);
3489
+ }
3490
+ /** Wait for the next new email matching `from` (anyone if omitted), after the last one this handle saw. */
3491
+ async waitForEmail(options = {}) {
3492
+ return waitForNext(this.#seen, "waitForEmail", () => this.inbox(), (item) => fromMatches(item.author, options.from), describeWait("an email", options.from), options);
3493
+ }
3494
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
3495
+ [QUIET]() {
3496
+ return quietOf(this.#ctx);
3497
+ }
3498
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
3499
+ [CONTEXT]() {
3500
+ return this.#ctx;
3501
+ }
3502
+ }
3503
+ export class GoogleFixture {
3504
+ app;
3505
+ apiUrl;
3506
+ #ctx;
3507
+ #seen = new Map();
3508
+ /** @internal Handles come from the SDK, never from `new`. */
3509
+ constructor(ctx, data) {
3510
+ this.#ctx = ctx;
3511
+ this.app = new GoogleApp(ctx, data.app);
3512
+ this.apiUrl = data.apiUrl;
3513
+ }
3514
+ /** Make another app: a mailbox of its own, with its own address and credentials (decision 0027), or return the one made with this name and settings. Its events go to CHANNELSTACK_GOOGLE_APP_<NAME>_WEBHOOK_URL. Experimental. */
3515
+ async createApp(options) {
3516
+ const ctx = this.#ctx;
3517
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/google/apps`, { body: { name: options.name } }));
3518
+ return new GoogleApp(ctx, data);
3519
+ }
3520
+ /** The mailboxs this session used: the agent's first, then each it got from `createApp`, in the order it first did. Another session's are `not_found` here. Experimental. */
3521
+ async apps() {
3522
+ const ctx = this.#ctx;
3523
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/google/apps`));
3524
+ return decodeGoogleApps(ctx, data);
3525
+ }
3526
+ /** Create a person: a mailbox, at `<name>@example.com` unless a test gives the address. Experimental. */
3527
+ async createUser(options) {
3528
+ const ctx = this.#ctx;
3529
+ 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 }) } }));
3530
+ return new GoogleUser(ctx, data);
3531
+ }
3532
+ /** The people this session created. Experimental. */
3533
+ async users() {
3534
+ const ctx = this.#ctx;
3535
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/google/users`));
3536
+ return decodeGoogleUsers(ctx, data);
3537
+ }
3538
+ /** The threads this session's people started, oldest first. Experimental. */
3539
+ async threads() {
3540
+ const ctx = this.#ctx;
3541
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/google/threads`));
3542
+ return decodeGoogleThreads(ctx, data);
3543
+ }
3544
+ /** Every push channelstack sent the agent for this session, with every attempt. Experimental. */
3545
+ async deliveries(options = {}) {
3546
+ const ctx = this.#ctx;
3547
+ 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, app: options.app === undefined ? undefined : options.app.id } }));
3548
+ return decodeGoogleDeliveries(ctx, data);
3549
+ }
3550
+ /** The Gmail calls the agent made about this session's mail, by the SDK's method name (`users.messages.send`). Experimental. */
3551
+ async calls(options = {}) {
3552
+ const ctx = this.#ctx;
3553
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/google/calls`, { query: { operation: options.operation, error: options.error } }));
3554
+ return data;
3555
+ }
3556
+ /** Wait for the next new API call from the agent, after the last one this handle saw. */
3557
+ async waitForCall(filter = {}, options = {}) {
3558
+ return waitForNext(this.#seen, `waitForCall:${JSON.stringify(filter)}`, () => this.calls(filter), () => true, "an API call from the agent", options);
3559
+ }
3560
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
3561
+ [QUIET]() {
3562
+ return quietOf(this.#ctx);
3563
+ }
3564
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
3565
+ [CONTEXT]() {
3566
+ return this.#ctx;
3567
+ }
3568
+ }
3569
+ export class GoogleApp {
3570
+ id;
3571
+ channel;
3572
+ kind;
3573
+ name;
3574
+ botUserId;
3575
+ address;
3576
+ clientId;
3577
+ clientSecret;
3578
+ refreshToken;
3579
+ #ctx;
3580
+ /** @internal Handles come from the SDK, never from `new`. */
3581
+ constructor(ctx, data) {
3582
+ this.#ctx = ctx;
3583
+ this.id = data.id;
3584
+ this.channel = data.channel;
3585
+ this.kind = data.kind;
3586
+ this.name = data.name;
3587
+ this.botUserId = data.botUserId;
3588
+ this.address = data.address;
3589
+ this.clientId = data.clientId;
3590
+ this.clientSecret = data.clientSecret;
3591
+ this.refreshToken = data.refreshToken;
3592
+ }
3593
+ /** An app a test made sends an email, through its own mailbox's API, as its own call would. Experimental. */
3594
+ async send(options) {
3595
+ const ctx = this.#ctx;
3596
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/google/apps/${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, headers: options.headers } }));
3597
+ return new GoogleEmail(ctx, data);
3598
+ }
3599
+ /** An app a test made replies to an email, in its thread, as its own call would. Experimental. */
3600
+ async reply(email, options = {}) {
3601
+ const ctx = this.#ctx;
3602
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/google/apps/${segment(this.id)}/reply`, { body: { email: email.id, text: options.text, html: options.html, all: options.all, headers: options.headers } }));
3603
+ return new GoogleEmail(ctx, data);
3604
+ }
3605
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
3606
+ [QUIET]() {
3607
+ return quietOf(this.#ctx);
3608
+ }
3609
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
3610
+ [CONTEXT]() {
3611
+ return this.#ctx;
3612
+ }
3613
+ }
3614
+ export class GoogleEmail {
3615
+ id;
3616
+ channel;
3617
+ thread;
3618
+ author;
3619
+ from;
3620
+ to;
3621
+ cc;
3622
+ subject;
3623
+ text;
3624
+ at;
3625
+ messageId;
3626
+ headers;
3627
+ labels;
3628
+ delivery;
3629
+ #ctx;
3630
+ /** @internal Handles come from the SDK, never from `new`. */
3631
+ constructor(ctx, data) {
3632
+ this.#ctx = ctx;
3633
+ this.id = data.id;
3634
+ this.channel = data.channel;
3635
+ this.thread = new GoogleThread(ctx, data.thread);
3636
+ this.author = data.author;
3637
+ this.from = data.from;
3638
+ this.to = data.to;
3639
+ this.cc = data.cc;
3640
+ this.subject = data.subject;
3641
+ this.text = data.text;
3642
+ this.at = data.at;
3643
+ this.messageId = data.messageId;
3644
+ this.headers = data.headers;
3645
+ this.labels = data.labels;
3646
+ this.delivery = data.delivery === undefined ? undefined : new GoogleDelivery(ctx, data.delivery);
3647
+ }
3648
+ /** Re-read an email. Experimental. */
3649
+ async refresh() {
3650
+ const ctx = this.#ctx;
3651
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/google/emails/${segment(this.id)}`));
3652
+ return new GoogleEmail(ctx, data);
3653
+ }
3654
+ /** The delivery that told this app of the email (decision 0027), or nothing when it wasn't told. Experimental. */
3655
+ async deliveryFor(app) {
3656
+ const ctx = this.#ctx;
3657
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/google/emails/${segment(this.id)}/delivery-for`, { query: { app: app.id } }));
3658
+ return (data === null ? undefined : new GoogleDelivery(ctx, data));
3659
+ }
3660
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
3661
+ [QUIET]() {
3662
+ return quietOf(this.#ctx);
3663
+ }
3664
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
3665
+ [CONTEXT]() {
3666
+ return this.#ctx;
3667
+ }
3668
+ }
3669
+ export class GoogleThread {
3670
+ id;
3671
+ channel;
3672
+ subject;
3673
+ #ctx;
3674
+ #seen = new Map();
3675
+ /** @internal Handles come from the SDK, never from `new`. */
3676
+ constructor(ctx, data) {
3677
+ this.#ctx = ctx;
3678
+ this.id = data.id;
3679
+ this.channel = data.channel;
3680
+ this.subject = data.subject;
3681
+ }
3682
+ /** Every email in the thread, oldest first. Experimental. */
3683
+ async messages() {
3684
+ const ctx = this.#ctx;
3685
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/google/threads/${segment(this.id)}/messages`));
3686
+ return decodeGoogleMessages(ctx, data);
3687
+ }
3688
+ /** The thread's answers: every email after the first, oldest first. Experimental. */
3689
+ async replies() {
3690
+ const ctx = this.#ctx;
3691
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/google/threads/${segment(this.id)}/replies`));
3692
+ return decodeGoogleReplies(ctx, data);
3693
+ }
3694
+ /** The thread as a person reads it: each email's own words, without the quoted history. Experimental. */
3695
+ async transcript() {
3696
+ const ctx = this.#ctx;
3697
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/google/threads/${segment(this.id)}/transcript`));
3698
+ return decodeGoogleTranscript(ctx, data);
3699
+ }
3700
+ /** Wait for the next new reply matching `from` (anyone if omitted), after the last one this handle saw. */
3701
+ async waitForReply(options = {}) {
3702
+ return waitForNext(this.#seen, "waitForReply", () => this.replies(), (item) => fromMatches(item.author, options.from), describeWait("a reply", options.from), options);
3703
+ }
3704
+ /** The latest reply matching `from`, once the agent is quiet. Waits for at least one. */
3705
+ async latestReply(options = {}) {
3706
+ return latestOnceQuiet(() => this.replies(), (item) => fromMatches(item.author, options.from), () => quietOf(this.#ctx), describeWait("a reply", options.from), options);
3707
+ }
3708
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
3709
+ [QUIET]() {
3710
+ return quietOf(this.#ctx);
3711
+ }
3712
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
3713
+ [CONTEXT]() {
3714
+ return this.#ctx;
3715
+ }
3716
+ }
3717
+ export class GoogleDelivery {
3718
+ id;
3719
+ channel;
3720
+ app;
3721
+ type;
3722
+ emailAddress;
3723
+ historyId;
3724
+ payload;
3725
+ attempts;
3726
+ status;
3727
+ #ctx;
3728
+ /** @internal Handles come from the SDK, never from `new`. */
3729
+ constructor(ctx, data) {
3730
+ this.#ctx = ctx;
3731
+ this.id = data.id;
3732
+ this.channel = data.channel;
3733
+ this.app = data.app;
3734
+ this.type = data.type;
3735
+ this.emailAddress = data.emailAddress;
3736
+ this.historyId = data.historyId;
3737
+ this.payload = data.payload;
3738
+ this.attempts = data.attempts;
3739
+ this.status = data.status;
3740
+ }
3741
+ /** Re-read a delivery: its attempts and status. Experimental. */
3742
+ async refresh() {
3743
+ const ctx = this.#ctx;
3744
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/google/deliveries/${segment(this.id)}`));
3745
+ return new GoogleDelivery(ctx, data);
3746
+ }
3747
+ /** Push the same message again, as Pub/Sub does when a push isn't acknowledged: the same message id. Experimental. */
3748
+ async redeliver() {
3749
+ const ctx = this.#ctx;
3750
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/google/deliveries/${segment(this.id)}/redeliver`));
3751
+ return data;
3752
+ }
3753
+ /** 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. */
3754
+ async resend(options = {}) {
3755
+ const ctx = this.#ctx;
3756
+ 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 } }));
3757
+ return data;
3758
+ }
3759
+ /** Wait for the delivery to settle, and resolve with the value as it is then. */
3760
+ async settled(options = {}) {
3761
+ return waitFor("the delivery to settle", async () => {
3762
+ const value = await this.refresh();
3763
+ return value.status === "pending" ? undefined : value;
3764
+ }, options);
3765
+ }
3766
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
3767
+ [QUIET]() {
3768
+ return quietOf(this.#ctx);
3769
+ }
3770
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
3771
+ [CONTEXT]() {
3772
+ return this.#ctx;
3773
+ }
3774
+ }
3775
+ export class GoogleUser {
3776
+ id;
3777
+ channel;
3778
+ kind;
3779
+ name;
3780
+ address;
3781
+ #ctx;
3782
+ #seen = new Map();
3783
+ /** @internal Handles come from the SDK, never from `new`. */
3784
+ constructor(ctx, data) {
3785
+ this.#ctx = ctx;
3786
+ this.id = data.id;
3787
+ this.channel = data.channel;
3788
+ this.kind = data.kind;
3789
+ this.name = data.name;
3790
+ this.address = data.address;
3791
+ }
3792
+ /** The person emails someone: the agent (`google.app`), another app, or another person. Experimental. */
3793
+ async send(options) {
3794
+ const ctx = this.#ctx;
3795
+ 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 } }));
3796
+ return new GoogleEmail(ctx, data);
3797
+ }
3798
+ /** The person replies to an email, in its thread: `Re:` its subject, with `In-Reply-To` and `References`. Experimental. */
3799
+ async reply(email, options = {}) {
3800
+ const ctx = this.#ctx;
3801
+ 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 } }));
3802
+ return new GoogleEmail(ctx, data);
3803
+ }
3804
+ /** What reached the person's mailbox, oldest first. Experimental. */
3805
+ async inbox() {
3806
+ const ctx = this.#ctx;
3807
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/google/users/${segment(this.id)}/inbox`));
3808
+ return decodeGoogleInbox(ctx, data);
3809
+ }
3810
+ /** Wait for the next new email matching `from` (anyone if omitted), after the last one this handle saw. */
3811
+ async waitForEmail(options = {}) {
3812
+ return waitForNext(this.#seen, "waitForEmail", () => this.inbox(), (item) => fromMatches(item.author, options.from), describeWait("an email", options.from), options);
3813
+ }
3814
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
3815
+ [QUIET]() {
3816
+ return quietOf(this.#ctx);
3817
+ }
3818
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
3819
+ [CONTEXT]() {
3820
+ return this.#ctx;
3821
+ }
3822
+ }
3823
+ export class DiscordFixture {
3824
+ app;
3825
+ apiUrl;
3826
+ guild;
3827
+ gatewayConnections;
3828
+ #ctx;
3829
+ #seen = new Map();
3830
+ /** @internal Handles come from the SDK, never from `new`. */
3831
+ constructor(ctx, data) {
3832
+ this.#ctx = ctx;
3833
+ this.app = new DiscordApp(ctx, data.app);
3834
+ this.apiUrl = data.apiUrl;
3835
+ this.guild = data.guild;
3836
+ this.gatewayConnections = data.gatewayConnections;
3837
+ }
3838
+ /** Create a person in the guild. Experimental. */
3839
+ async createUser(options) {
3840
+ const ctx = this.#ctx;
3841
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/discord/users`, { body: { name: options.name, id: options.id, admin: options.admin, bot: options.bot, token: options.token ?? credential("CHANNELSTACK_DISCORD_USER_{name}_TOKEN", { name: options.name }) } }));
3842
+ return new DiscordUser(ctx, data);
3843
+ }
3844
+ /** The people this session created. Experimental. */
3845
+ async users() {
3846
+ const ctx = this.#ctx;
3847
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/discord/users`));
3848
+ return decodeDiscordUsers(ctx, data);
3849
+ }
3850
+ /** Make another app in the guild, with its own application, bot user, token and Ed25519 key (decision 0027), or return the one made with this name and settings. Its bot connects to the Gateway with its own token; its interactions go to CHANNELSTACK_DISCORD_APP_<NAME>_WEBHOOK_URL, or over its Gateway connection. Experimental. */
3851
+ async createApp(options) {
3852
+ const ctx = this.#ctx;
3853
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/discord/apps`, { body: { name: options.name, privilegedIntents: options.privilegedIntents } }));
3854
+ return new DiscordApp(ctx, data);
3855
+ }
3856
+ /** The apps this session used: the built-in one first, then each it got from `createApp`, in the order it first did. Another session's are `not_found` here. Experimental. */
3857
+ async apps() {
3858
+ const ctx = this.#ctx;
3859
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/discord/apps`));
3860
+ return decodeDiscordApps(ctx, data);
3861
+ }
3862
+ /** Create a text channel. Only the listed participants see it (a private channel); include the app for the bot to hear it. Experimental. */
3863
+ async createChannel(options = {}) {
3864
+ const ctx = this.#ctx;
3865
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/discord/channels`, { body: { name: options.name, participants: options.participants === undefined ? undefined : options.participants.map((item) => item.id), readOnly: options.readOnly, topic: options.topic } }));
3866
+ return new DiscordChannel(ctx, data);
3867
+ }
3868
+ /** The session's channels, threads and DMs. Experimental. */
3869
+ async channels() {
3870
+ const ctx = this.#ctx;
3871
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/discord/channels`));
3872
+ return decodeDiscordChannels(ctx, data);
3873
+ }
3874
+ /** Discord's check of the app's interactions endpoint, as when it is saved in the developer portal: a PING it must answer with a PONG, and one with a bad signature it must refuse with 401. Experimental. */
3875
+ async verifyEndpoint() {
3876
+ const ctx = this.#ctx;
3877
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/discord/verify-endpoint`));
3878
+ return data;
3879
+ }
3880
+ /** Every Gateway dispatch and interaction channelstack sent the bot for this session, with every attempt. Experimental. */
3881
+ async deliveries(options = {}) {
3882
+ const ctx = this.#ctx;
3883
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/discord/deliveries`, { query: { type: options.type, resource: options.resource === undefined ? undefined : options.resource.id, app: options.app === undefined ? undefined : options.app.id } }));
3884
+ return decodeDiscordDeliveries(ctx, data);
3885
+ }
3886
+ /** The REST calls the bot made about this session's channels, messages and interactions, by route (`POST /channels/{channel.id}/messages`). Calls about nothing a session owns (`GET /gateway/bot`) are in no session. Experimental. */
3887
+ async calls(options = {}) {
3888
+ const ctx = this.#ctx;
3889
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/discord/calls`, { query: { operation: options.operation, error: options.error } }));
3890
+ return data;
3891
+ }
3892
+ /** Inject a fault: rate-limit the bot's calls of a route (removed when this session closes), or drop its Gateway connection just before the next dispatch. Experimental. */
3893
+ async fault(options) {
3894
+ const ctx = this.#ctx;
3895
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/discord/faults`, { body: { type: options.type, route: options.route, retryAfter: options.retryAfter === undefined ? undefined : parseDuration(options.retryAfter), times: options.times, app: options.app === undefined ? undefined : options.app.id } }));
3896
+ return new DiscordFault(ctx, data);
3897
+ }
3898
+ /** Wait for the next new API call from the agent, after the last one this handle saw. */
3899
+ async waitForCall(filter = {}, options = {}) {
3900
+ return waitForNext(this.#seen, `waitForCall:${JSON.stringify(filter)}`, () => this.calls(filter), () => true, "an API call from the agent", options);
3901
+ }
3902
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
3903
+ [QUIET]() {
3904
+ return quietOf(this.#ctx);
3905
+ }
3906
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
3907
+ [CONTEXT]() {
3908
+ return this.#ctx;
3909
+ }
3910
+ }
3911
+ export class DiscordApp {
3912
+ id;
3913
+ name;
3914
+ kind;
3915
+ channel;
3916
+ botUserId;
3917
+ botToken;
3918
+ publicKey;
3919
+ guildId;
3920
+ #ctx;
3921
+ /** @internal Handles come from the SDK, never from `new`. */
3922
+ constructor(ctx, data) {
3923
+ this.#ctx = ctx;
3924
+ this.id = data.id;
3925
+ this.name = data.name;
3926
+ this.kind = data.kind;
3927
+ this.channel = data.channel;
3928
+ this.botUserId = data.botUserId;
3929
+ this.botToken = data.botToken;
3930
+ this.publicKey = data.publicKey;
3931
+ this.guildId = data.guildId;
3932
+ }
3933
+ /** An app a test made writes, as its own `POST /channels/{id}/messages` would: in a channel or thread its bot sees, or in a DM with the person in `to`. No bot writes to another bot in a DM (50007). Experimental. */
3934
+ async say(text, options = {}) {
3935
+ const ctx = this.#ctx;
3936
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/discord/apps/${segment(this.id)}/say`, { body: { text: typeof text === "string" ? { content: text } : (typeof text === "string" ? { content: text } : text), channel: options.channel === undefined ? undefined : options.channel.id, to: options.to === undefined ? undefined : [options.to].flat().map((item) => item.id) } }));
3937
+ return new DiscordMessage(ctx, data);
3938
+ }
3939
+ /** An app a test made replies to a message: Discord's reply, in the message's channel, which quotes it. Experimental. */
3940
+ async reply(text, options) {
3941
+ const ctx = this.#ctx;
3942
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/discord/apps/${segment(this.id)}/reply`, { body: { text: typeof text === "string" ? { content: text } : (typeof text === "string" ? { content: text } : text), message: { channelId: options.message.channelId, id: options.message.id } } }));
3943
+ return new DiscordMessage(ctx, data);
3944
+ }
3945
+ /** An app a test made reacts to a message. Experimental. */
3946
+ async react(emoji, options) {
3947
+ const ctx = this.#ctx;
3948
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/discord/apps/${segment(this.id)}/react`, { body: { emoji, message: { channelId: options.message.channelId, id: options.message.id } } }));
3949
+ return (data === null ? undefined : new DiscordDelivery(ctx, data));
3950
+ }
3951
+ /** An app a test made takes its reaction back. Experimental. */
3952
+ async unreact(emoji, options) {
3953
+ const ctx = this.#ctx;
3954
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/discord/apps/${segment(this.id)}/unreact`, { body: { emoji, message: { channelId: options.message.channelId, id: options.message.id } } }));
3955
+ return (data === null ? undefined : new DiscordDelivery(ctx, data));
3956
+ }
3957
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
3958
+ [QUIET]() {
3959
+ return quietOf(this.#ctx);
3960
+ }
3961
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
3962
+ [CONTEXT]() {
3963
+ return this.#ctx;
3964
+ }
3965
+ }
3966
+ export class DiscordUser {
3967
+ id;
3968
+ name;
3969
+ kind;
3970
+ channel;
3971
+ username;
3972
+ isAdmin;
3973
+ isBot;
3974
+ #ctx;
3975
+ /** @internal Handles come from the SDK, never from `new`. */
3976
+ constructor(ctx, data) {
3977
+ this.#ctx = ctx;
3978
+ this.id = data.id;
3979
+ this.name = data.name;
3980
+ this.kind = data.kind;
3981
+ this.channel = data.channel;
3982
+ this.username = data.username;
3983
+ this.isAdmin = data.isAdmin;
3984
+ this.isBot = data.isBot;
3985
+ }
3986
+ /** Write a message in a channel or thread, or in a DM with the person or app in `to`. Experimental. */
3987
+ async say(text, options = {}) {
3988
+ const ctx = this.#ctx;
3989
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/discord/users/${segment(this.id)}/say`, { body: { text: typeof text === "string" ? { content: text } : (typeof text === "string" ? { content: text } : text), channel: options.channel === undefined ? undefined : options.channel.id, to: options.to === undefined ? undefined : [options.to].flat().map((item) => item.id) } }));
3990
+ return new DiscordMessage(ctx, data);
3991
+ }
3992
+ /** Reply to a message: Discord's reply, in the message's channel, which quotes it. Experimental. */
3993
+ async reply(text, options) {
3994
+ const ctx = this.#ctx;
3995
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/discord/users/${segment(this.id)}/reply`, { body: { text: typeof text === "string" ? { content: text } : (typeof text === "string" ? { content: text } : text), message: { channelId: options.message.channelId, id: options.message.id } } }));
3996
+ return new DiscordMessage(ctx, data);
3997
+ }
3998
+ /** Edit one of this person's own messages. Experimental. */
3999
+ async edit(text, options) {
4000
+ const ctx = this.#ctx;
4001
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/discord/users/${segment(this.id)}/edit`, { body: { text: typeof text === "string" ? { content: text } : (typeof text === "string" ? { content: text } : text), message: { channelId: options.message.channelId, id: options.message.id } } }));
4002
+ return new DiscordMessage(ctx, data);
4003
+ }
4004
+ /** Delete a message: this person's own, or anyone's for an admin. Experimental. */
4005
+ async delete(options) {
4006
+ const ctx = this.#ctx;
4007
+ await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/discord/users/${segment(this.id)}/delete`, { body: { message: { channelId: options.message.channelId, id: options.message.id } } });
4008
+ }
4009
+ /** React to a message with an emoji. Experimental. */
4010
+ async react(emoji, options) {
4011
+ const ctx = this.#ctx;
4012
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/discord/users/${segment(this.id)}/react`, { body: { emoji, message: { channelId: options.message.channelId, id: options.message.id } } }));
4013
+ return (data === null ? undefined : new DiscordDelivery(ctx, data));
4014
+ }
4015
+ /** Take this person's reaction off a message. Experimental. */
4016
+ async unreact(emoji, options) {
4017
+ const ctx = this.#ctx;
4018
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/discord/users/${segment(this.id)}/unreact`, { body: { emoji, message: { channelId: options.message.channelId, id: options.message.id } } }));
4019
+ return (data === null ? undefined : new DiscordDelivery(ctx, data));
4020
+ }
4021
+ /** Start a thread: from a message, or in a channel. Experimental. */
4022
+ async startThread(name, options = {}) {
4023
+ const ctx = this.#ctx;
4024
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/discord/users/${segment(this.id)}/threads`, { body: { name, message: options.message === undefined ? undefined : { channelId: options.message.channelId, id: options.message.id }, channel: options.channel === undefined ? undefined : options.channel.id } }));
4025
+ return new DiscordChannel(ctx, data);
4026
+ }
4027
+ /** Open (or reuse) a DM with the app or another person. Experimental. */
4028
+ async openDM(participant) {
4029
+ const ctx = this.#ctx;
4030
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/discord/users/${segment(this.id)}/open-dm`, { body: { participant: participant.id } }));
4031
+ return new DiscordChannel(ctx, data);
4032
+ }
4033
+ /** Let people or the app see a channel. The person must be an admin. Experimental. */
4034
+ async invite(participants, options) {
4035
+ const ctx = this.#ctx;
4036
+ await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/discord/users/${segment(this.id)}/invite`, { body: { participants: [participants].flat().map((item) => item.id), channel: options.channel.id } });
4037
+ }
4038
+ /** Run one of an app's slash commands in a channel, e.g. `/deploy web staging` or `/deploy service:web`: the built-in app's, or `app`'s, as a person picks one app's command when several have it. Experimental. */
4039
+ async runCommand(command, options) {
4040
+ const ctx = this.#ctx;
4041
+ const data = (await retryWhile(["not_found"], () => ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/discord/users/${segment(this.id)}/commands`, { body: { command, channel: options.channel.id, app: options.app === undefined ? undefined : options.app.id } })));
4042
+ return (data === null ? undefined : new DiscordDelivery(ctx, data));
4043
+ }
4044
+ /** Press a button, found by its label or custom_id: on a message, or on the app's newest message in a channel or thread that has it. Experimental. */
4045
+ async click(button, options = {}) {
4046
+ const ctx = this.#ctx;
4047
+ const data = (await retryWhile(["not_found"], () => ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/discord/users/${segment(this.id)}/click`, { body: { button: typeof button === "string" ? { label: button } : (typeof button === "string" ? { label: button } : button), message: options.message === undefined ? undefined : { channelId: options.message.channelId, id: options.message.id }, channel: options.channel === undefined ? undefined : options.channel.id } })));
4048
+ return (data === null ? undefined : new DiscordDelivery(ctx, data));
4049
+ }
4050
+ /** Messages only this person sees: the app's ephemeral responses, and "This interaction failed". Experimental. */
4051
+ async ephemeral() {
4052
+ const ctx = this.#ctx;
4053
+ await untilQuiet(() => quietOf(ctx));
4054
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/discord/users/${segment(this.id)}/ephemeral`));
4055
+ return decodeDiscordEphemeralMessages(ctx, data);
4056
+ }
4057
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
4058
+ [QUIET]() {
4059
+ return quietOf(this.#ctx);
4060
+ }
4061
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
4062
+ [CONTEXT]() {
4063
+ return this.#ctx;
4064
+ }
4065
+ }
4066
+ export class DiscordMessage {
4067
+ id;
4068
+ channelId;
4069
+ channel;
4070
+ author;
4071
+ text;
4072
+ content;
4073
+ embeds;
4074
+ components;
4075
+ postedAt;
4076
+ edited;
4077
+ replyTo;
4078
+ thread;
4079
+ visibleTo;
4080
+ delivery;
4081
+ #ctx;
4082
+ #seen = new Map();
4083
+ /** @internal Handles come from the SDK, never from `new`. */
4084
+ constructor(ctx, data) {
4085
+ this.#ctx = ctx;
4086
+ this.id = data.id;
4087
+ this.channelId = data.channelId;
4088
+ this.channel = new DiscordChannel(ctx, data.channel);
4089
+ this.author = data.author.kind === "user" ? new DiscordUser(ctx, data.author) : new DiscordApp(ctx, data.author);
4090
+ this.text = data.text;
4091
+ this.content = data.content;
4092
+ this.embeds = data.embeds;
4093
+ this.components = data.components;
4094
+ this.postedAt = data.postedAt;
4095
+ this.edited = data.edited;
4096
+ this.replyTo = data.replyTo;
4097
+ this.thread = data.thread === undefined ? undefined : new DiscordChannel(ctx, data.thread);
4098
+ this.visibleTo = data.visibleTo === undefined ? undefined : new DiscordUser(ctx, data.visibleTo);
4099
+ this.delivery = data.delivery === undefined ? undefined : new DiscordDelivery(ctx, data.delivery);
4100
+ }
4101
+ /** Re-read a message: its latest text, edits and thread. Experimental. */
4102
+ async refresh() {
4103
+ const ctx = this.#ctx;
4104
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/discord/channels/${segment(this.channelId)}/messages/${segment(this.id)}`));
4105
+ return new DiscordMessage(ctx, data);
4106
+ }
4107
+ /** What answers a message, oldest first: Discord's replies to it, and the messages of the thread started from it. Experimental. */
4108
+ async replies() {
4109
+ const ctx = this.#ctx;
4110
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/discord/channels/${segment(this.channelId)}/messages/${segment(this.id)}/replies`));
4111
+ return decodeDiscordReplies(ctx, data);
4112
+ }
4113
+ /** A message and what answers it, as a person reads them. Experimental. */
4114
+ async transcript(options = {}) {
4115
+ const ctx = this.#ctx;
4116
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/discord/channels/${segment(this.channelId)}/messages/${segment(this.id)}/transcript`, { query: { as: options.as === undefined ? undefined : options.as.id } }));
4117
+ return decodeDiscordTranscript(ctx, data);
4118
+ }
4119
+ /** The reactions on a message, and who added each. Experimental. */
4120
+ async reactions() {
4121
+ const ctx = this.#ctx;
4122
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/discord/channels/${segment(this.channelId)}/messages/${segment(this.id)}/reactions`));
4123
+ return decodeDiscordReactions(ctx, data);
4124
+ }
4125
+ /** The first Gateway dispatch this message caused to this app's bot (decision 0027), or nothing when it wasn't told. Experimental. */
4126
+ async deliveryFor(app) {
4127
+ const ctx = this.#ctx;
4128
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/discord/channels/${segment(this.channelId)}/messages/${segment(this.id)}/delivery-for`, { query: { app: app.id } }));
4129
+ return (data === null ? undefined : new DiscordDelivery(ctx, data));
4130
+ }
4131
+ /** Every Gateway dispatch this message caused to the apps' bots. Experimental. */
4132
+ async deliveries() {
4133
+ const ctx = this.#ctx;
4134
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/discord/channels/${segment(this.channelId)}/messages/${segment(this.id)}/deliveries`));
4135
+ return decodeDiscordMessageDeliveries(ctx, data);
4136
+ }
4137
+ /** Wait for the next new reply matching `from` (anyone if omitted), after the last one this handle saw. */
4138
+ async waitForReply(options = {}) {
4139
+ return waitForNext(this.#seen, "waitForReply", () => this.replies(), (item) => fromMatches(item.author, options.from), describeWait("a reply", options.from), options);
4140
+ }
4141
+ /** The latest reply matching `from`, once the agent is quiet. Waits for at least one. */
4142
+ async latestReply(options = {}) {
4143
+ return latestOnceQuiet(() => this.replies(), (item) => fromMatches(item.author, options.from), () => quietOf(this.#ctx), describeWait("a reply", options.from), options);
4144
+ }
4145
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
4146
+ [QUIET]() {
4147
+ return quietOf(this.#ctx);
4148
+ }
4149
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
4150
+ [CONTEXT]() {
4151
+ return this.#ctx;
4152
+ }
4153
+ }
4154
+ export class DiscordChannel {
4155
+ id;
4156
+ kind;
4157
+ channel;
4158
+ name;
4159
+ parentId;
4160
+ starterId;
4161
+ #ctx;
4162
+ #seen = new Map();
4163
+ /** @internal Handles come from the SDK, never from `new`. */
4164
+ constructor(ctx, data) {
4165
+ this.#ctx = ctx;
4166
+ this.id = data.id;
4167
+ this.kind = data.kind;
4168
+ this.channel = data.channel;
4169
+ this.name = data.name;
4170
+ this.parentId = data.parentId;
4171
+ this.starterId = data.starterId;
4172
+ }
4173
+ /** A channel's or thread's messages, oldest first. Experimental. */
4174
+ async messages() {
4175
+ const ctx = this.#ctx;
4176
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/discord/channels/${segment(this.id)}/messages`));
4177
+ return decodeDiscordMessages(ctx, data);
4178
+ }
4179
+ /** Who sees a channel: a text channel's participants, a DM's two ends; a thread's are its channel's. Admins see every channel without being listed. Experimental. */
4180
+ async members() {
4181
+ const ctx = this.#ctx;
4182
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/discord/channels/${segment(this.id)}/members`));
4183
+ return decodeDiscordMembers(ctx, data);
4184
+ }
4185
+ /** The threads in a channel. Experimental. */
4186
+ async threads() {
4187
+ const ctx = this.#ctx;
4188
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/discord/channels/${segment(this.id)}/threads`));
4189
+ return decodeDiscordThreads(ctx, data);
4190
+ }
4191
+ /** A channel or thread as a person reads it, each thread under the message that starts it. Experimental. */
4192
+ async transcript(options = {}) {
4193
+ const ctx = this.#ctx;
4194
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/discord/channels/${segment(this.id)}/transcript`, { query: { as: options.as === undefined ? undefined : options.as.id } }));
4195
+ return decodeDiscordTranscript(ctx, data);
4196
+ }
4197
+ /** Wait for the next new message matching `from` (anyone if omitted), after the last one this handle saw. */
4198
+ async waitForMessage(options = {}) {
4199
+ return waitForNext(this.#seen, "waitForMessage", () => this.messages(), (item) => fromMatches(item.author, options.from), describeWait("a message", options.from), options);
4200
+ }
4201
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
4202
+ [QUIET]() {
4203
+ return quietOf(this.#ctx);
4204
+ }
4205
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
4206
+ [CONTEXT]() {
4207
+ return this.#ctx;
4208
+ }
4209
+ }
4210
+ export class DiscordDelivery {
4211
+ id;
4212
+ channel;
4213
+ app;
4214
+ type;
4215
+ payload;
4216
+ attempts;
4217
+ status;
4218
+ #ctx;
4219
+ /** @internal Handles come from the SDK, never from `new`. */
4220
+ constructor(ctx, data) {
4221
+ this.#ctx = ctx;
4222
+ this.id = data.id;
4223
+ this.channel = data.channel;
4224
+ this.app = data.app;
4225
+ this.type = data.type;
4226
+ this.payload = data.payload;
4227
+ this.attempts = data.attempts;
4228
+ this.status = data.status;
4229
+ }
4230
+ /** Re-read a delivery: its attempts and status. Experimental. */
4231
+ async refresh() {
4232
+ const ctx = this.#ctx;
4233
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/discord/deliveries/${segment(this.id)}`));
4234
+ return new DiscordDelivery(ctx, data);
4235
+ }
4236
+ /** Dispatch the same event to the bot again, as a replay after a RESUME would. Experimental. */
4237
+ async redeliver() {
4238
+ const ctx = this.#ctx;
4239
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/discord/deliveries/${segment(this.id)}/redeliver`));
4240
+ return data;
4241
+ }
4242
+ /** Send an interaction again, forged: signed with a key that isn't the app's, which its endpoint must refuse with 401. Experimental. */
4243
+ async resend(options = {}) {
4244
+ const ctx = this.#ctx;
4245
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/discord/deliveries/${segment(this.id)}/resend`, { body: { badSignature: options.badSignature } }));
4246
+ return data;
4247
+ }
4248
+ /** Wait for the delivery to settle, and resolve with the value as it is then. */
4249
+ async settled(options = {}) {
4250
+ return waitFor("the delivery to settle", async () => {
4251
+ const value = await this.refresh();
4252
+ return value.status === "pending" ? undefined : value;
4253
+ }, options);
4254
+ }
4255
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
4256
+ [QUIET]() {
4257
+ return quietOf(this.#ctx);
4258
+ }
4259
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
4260
+ [CONTEXT]() {
4261
+ return this.#ctx;
4262
+ }
4263
+ }
4264
+ export class DiscordFault {
4265
+ id;
4266
+ #ctx;
4267
+ /** @internal Handles come from the SDK, never from `new`. */
4268
+ constructor(ctx, data) {
4269
+ this.#ctx = ctx;
4270
+ this.id = data.id;
4271
+ }
4272
+ /** Remove a fault. Experimental. */
4273
+ async undo() {
4274
+ const ctx = this.#ctx;
4275
+ await ctx.transport.request("DELETE", `/sessions/${segment(sessionOf(ctx))}/discord/faults/${segment(this.id)}`);
4276
+ }
4277
+ async [Symbol.asyncDispose]() {
4278
+ await disposeQuietly(() => this.undo());
4279
+ }
4280
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
4281
+ [QUIET]() {
4282
+ return quietOf(this.#ctx);
4283
+ }
4284
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
4285
+ [CONTEXT]() {
4286
+ return this.#ctx;
4287
+ }
4288
+ }
4289
+ export class OpenAIFixture {
4290
+ baseUrl;
4291
+ #ctx;
4292
+ #seen = new Map();
4293
+ /** @internal Handles come from the SDK, never from `new`. */
4294
+ constructor(ctx, data) {
4295
+ this.#ctx = ctx;
4296
+ this.baseUrl = data.baseUrl;
4297
+ }
4298
+ /** Script what the model answers: turns used in order, one per matching call, or a responder the test answers. Scripts are tried in the order they were added. Experimental. */
4299
+ async respond(turns, options = {}) {
4300
+ const ctx = this.#ctx;
4301
+ const answer = typeof turns === "function" ? turns : undefined;
4302
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/openai/scripts`, { body: { turns: (answer === undefined ? turns : undefined) === undefined ? undefined : [(answer === undefined ? turns : undefined)].flat().map((item) => (typeof item === "object" && item !== null && !Array.isArray(item) ? { ...item, toolCalls: item.toolCalls === undefined ? undefined : item.toolCalls.map((item) => ({ ...item, codeInterpreter: item.codeInterpreter === undefined ? undefined : { ...item.codeInterpreter, files: item.codeInterpreter.files === undefined ? undefined : item.codeInterpreter.files.map((item) => readMedia(item)) }, imageGeneration: item.imageGeneration === undefined ? undefined : { ...item.imageGeneration, image: readMedia(item.imageGeneration.image) } })), image: item.image === undefined ? undefined : [item.image].flat().map((item) => readMedia(item)), audio: item.audio === undefined ? undefined : readMedia(item.audio) } : item)), when: options.when === undefined ? undefined : { ...options.when, text: options.when.text === undefined ? undefined : patternOnWire(options.when.text), prompt: options.when.prompt === undefined ? undefined : patternOnWire(options.when.prompt), model: options.when.model === undefined ? undefined : patternOnWire(options.when.model), from: options.when.from === undefined ? undefined : options.when.from.id, in: options.when.in === undefined ? undefined : options.when.in.id }, times: options.times, timing: options.timing, responder: answer !== undefined } }));
4303
+ const handle = new OpenAIScript(ctx, data);
4304
+ if (answer !== undefined)
4305
+ respondWith({ held: (o) => handle.heldCalls(o), answer: (id, o) => handle.answerHeld(id, o) }, answer);
4306
+ return handle;
4307
+ }
4308
+ /** Every model call attributed to this session, oldest first. Experimental. */
4309
+ async calls(options = {}) {
4310
+ const ctx = this.#ctx;
4311
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/openai/calls`, { query: { endpoint: options.endpoint, error: options.error } }));
4312
+ return decodeOpenAISessionCalls(ctx, data);
4313
+ }
4314
+ /** Every tool call the model made in this session, each with the result the agent sent back. Experimental. */
4315
+ async toolCalls(options = {}) {
4316
+ const ctx = this.#ctx;
4317
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/openai/tool-calls`, { query: { name: options.name } }));
4318
+ return data;
4319
+ }
4320
+ /** What went wrong with the model in this session: a call no script answered, a script that ran out or did what the real API can't, a responder that threw. Matchers fail at once on these. Experimental. */
4321
+ async problems() {
4322
+ const ctx = this.#ctx;
4323
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/openai/problems`));
4324
+ return data;
4325
+ }
4326
+ /** The calls that sent a secret channelstack knows to the model, and the kinds they sent (`slack.botToken`): never the values. Experimental. */
4327
+ async sentSecrets() {
4328
+ const ctx = this.#ctx;
4329
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/openai/sent-secrets`));
4330
+ return data;
4331
+ }
4332
+ /** Model calls no session could be given (the agent calling the model at startup, for example), oldest first: what a failing matcher names. Experimental. */
4333
+ async unattributed(options = {}) {
4334
+ const ctx = this.#ctx;
4335
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/openai/unattributed`, { query: { withinMs: options.withinMs } }));
4336
+ return data;
4337
+ }
4338
+ /** Limit this session's model calls: requests and tokens per window, with truthful x-ratelimit-* headers. Experimental. */
4339
+ async rateLimit(options = {}) {
4340
+ const ctx = this.#ctx;
4341
+ const data = (await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/openai/rate-limits`, { body: { requests: options.requests === undefined ? undefined : { ...options.requests, per: options.requests.per === undefined ? undefined : parseDuration(options.requests.per) }, tokens: options.tokens === undefined ? undefined : { ...options.tokens, per: options.tokens.per === undefined ? undefined : parseDuration(options.tokens.per) }, error: options.error } }));
4342
+ return new OpenAIRateLimit(ctx, data);
4343
+ }
4344
+ /** Wait for the next new model call from the agent, after the last one this handle saw. */
4345
+ async waitForCall(filter = {}, options = {}) {
4346
+ return waitForNext(this.#seen, `waitForCall:${JSON.stringify(filter)}`, () => this.calls(filter), () => true, "a model call from the agent", options);
4347
+ }
4348
+ /** The latest model call from the agent, once the agent is quiet. Waits for at least one. */
4349
+ async latestCall(filter = {}, options = {}) {
4350
+ return latestOnceQuiet(() => this.calls(filter), () => true, () => quietOf(this.#ctx), "a model call from the agent", options);
4351
+ }
4352
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
4353
+ [QUIET]() {
4354
+ return quietOf(this.#ctx);
4355
+ }
4356
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
4357
+ [CONTEXT]() {
4358
+ return this.#ctx;
4359
+ }
4360
+ }
4361
+ export class OpenAIScript {
4362
+ id;
4363
+ responder;
4364
+ times;
4365
+ used;
4366
+ problems;
4367
+ #ctx;
4368
+ #seen = new Map();
4369
+ /** @internal Handles come from the SDK, never from `new`. */
4370
+ constructor(ctx, data) {
4371
+ this.#ctx = ctx;
4372
+ this.id = data.id;
4373
+ this.responder = data.responder;
4374
+ this.times = data.times;
4375
+ this.used = data.used;
4376
+ this.problems = data.problems;
4377
+ }
4378
+ /** Re-read a script: how many calls it answered, and its problems. Experimental. */
4379
+ async refresh() {
4380
+ const ctx = this.#ctx;
4381
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/openai/scripts/${segment(this.id)}`));
4382
+ return new OpenAIScript(ctx, data);
4383
+ }
4384
+ /** Remove a script. Closing the session does it too. Experimental. */
4385
+ async undo() {
4386
+ const ctx = this.#ctx;
4387
+ await ctx.transport.request("DELETE", `/sessions/${segment(sessionOf(ctx))}/openai/scripts/${segment(this.id)}`);
4388
+ }
4389
+ async [Symbol.asyncDispose]() {
4390
+ await disposeQuietly(() => this.undo());
4391
+ }
4392
+ /** Let the streams this script holds at `pauseAfter` go on. Experimental. */
4393
+ async resume() {
4394
+ const ctx = this.#ctx;
4395
+ await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/openai/scripts/${segment(this.id)}/resume`);
4396
+ }
4397
+ /** The calls this script answered. Experimental. */
4398
+ async calls() {
4399
+ const ctx = this.#ctx;
4400
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/openai/scripts/${segment(this.id)}/calls`));
4401
+ return decodeOpenAICalls(ctx, data);
4402
+ }
4403
+ /** The calls whose streams this script holds at `pauseAfter`. Experimental. */
4404
+ async pausedCalls() {
4405
+ const ctx = this.#ctx;
4406
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/openai/scripts/${segment(this.id)}/paused`));
4407
+ return decodeOpenAIPausedCalls(ctx, data);
4408
+ }
4409
+ /** The tool calls this script made, each with the result the agent sent back. Experimental. */
4410
+ async toolCalls(options = {}) {
4411
+ const ctx = this.#ctx;
4412
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/openai/scripts/${segment(this.id)}/tool-calls`, { query: { name: options.name } }));
4413
+ return data;
4414
+ }
4415
+ /** For a responder's SDK: the calls held for it since `since`, waiting up to `waitMs` for one. Experimental. */
4416
+ async heldCalls(options = {}) {
4417
+ const ctx = this.#ctx;
4418
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/openai/scripts/${segment(this.id)}/requests`, { query: { since: options.since, waitMs: options.waitMs } }));
4419
+ return data;
4420
+ }
4421
+ /** For a responder's SDK: answer a held call with a turn, or report that the test's function threw. Experimental. */
4422
+ async answerHeld(held, options = {}) {
4423
+ const ctx = this.#ctx;
4424
+ await ctx.transport.request("POST", `/sessions/${segment(sessionOf(ctx))}/openai/scripts/${segment(this.id)}/answers`, { body: { held, turn: options.turn === undefined ? undefined : (typeof options.turn === "object" && options.turn !== null && !Array.isArray(options.turn) ? { ...options.turn, toolCalls: options.turn.toolCalls === undefined ? undefined : options.turn.toolCalls.map((item) => ({ ...item, codeInterpreter: item.codeInterpreter === undefined ? undefined : { ...item.codeInterpreter, files: item.codeInterpreter.files === undefined ? undefined : item.codeInterpreter.files.map((item) => readMedia(item)) }, imageGeneration: item.imageGeneration === undefined ? undefined : { ...item.imageGeneration, image: readMedia(item.imageGeneration.image) } })), image: options.turn.image === undefined ? undefined : [options.turn.image].flat().map((item) => readMedia(item)), audio: options.turn.audio === undefined ? undefined : readMedia(options.turn.audio) } : options.turn), error: options.error } });
4425
+ }
4426
+ /** Wait for the next new model call this script answers, after the last one this handle saw. */
4427
+ async waitForCall(options = {}) {
4428
+ return waitForNext(this.#seen, "waitForCall", () => this.calls(), () => true, "a model call this script answers", options);
4429
+ }
4430
+ /** Wait for the next new stream held at pauseAfter, after the last one this handle saw. */
4431
+ async waitForPause(options = {}) {
4432
+ return waitForNext(this.#seen, "waitForPause", () => this.pausedCalls(), () => true, "a stream held at pauseAfter", options);
4433
+ }
4434
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
4435
+ [QUIET]() {
4436
+ return quietOf(this.#ctx);
4437
+ }
4438
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
4439
+ [CONTEXT]() {
4440
+ return this.#ctx;
4441
+ }
4442
+ }
4443
+ export class OpenAICall {
4444
+ id;
4445
+ endpoint;
4446
+ model;
4447
+ stream;
4448
+ at;
4449
+ durationMs;
4450
+ attempt;
4451
+ done;
4452
+ request;
4453
+ response;
4454
+ toolCalls;
4455
+ script;
4456
+ #ctx;
4457
+ /** @internal Handles come from the SDK, never from `new`. */
4458
+ constructor(ctx, data) {
4459
+ this.#ctx = ctx;
4460
+ this.id = data.id;
4461
+ this.endpoint = data.endpoint;
4462
+ this.model = data.model;
4463
+ this.stream = data.stream;
4464
+ this.at = data.at;
4465
+ this.durationMs = data.durationMs;
4466
+ this.attempt = data.attempt;
4467
+ this.done = data.done;
4468
+ this.request = data.request;
4469
+ this.response = data.response;
4470
+ this.toolCalls = data.toolCalls;
4471
+ this.script = data.script;
4472
+ }
4473
+ /** Re-read a model call: whether it is done, how it ended. Experimental. */
4474
+ async refresh() {
4475
+ const ctx = this.#ctx;
4476
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/openai/calls/${segment(this.id)}`));
4477
+ return new OpenAICall(ctx, data);
4478
+ }
4479
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
4480
+ [QUIET]() {
4481
+ return quietOf(this.#ctx);
4482
+ }
4483
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
4484
+ [CONTEXT]() {
4485
+ return this.#ctx;
4486
+ }
4487
+ }
4488
+ export class OpenAIRateLimit {
4489
+ id;
4490
+ requests;
4491
+ tokens;
4492
+ resetsInMs;
4493
+ #ctx;
4494
+ /** @internal Handles come from the SDK, never from `new`. */
4495
+ constructor(ctx, data) {
4496
+ this.#ctx = ctx;
4497
+ this.id = data.id;
4498
+ this.requests = data.requests;
4499
+ this.tokens = data.tokens;
4500
+ this.resetsInMs = data.resetsInMs;
4501
+ }
4502
+ /** What the rate limit's headers would say now. Experimental. */
4503
+ async remaining() {
4504
+ const ctx = this.#ctx;
4505
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/openai/rate-limits/${segment(this.id)}`));
4506
+ return new OpenAIRateLimit(ctx, data);
4507
+ }
4508
+ /** Remove the rate limit. Experimental. */
4509
+ async undo() {
4510
+ const ctx = this.#ctx;
4511
+ await ctx.transport.request("DELETE", `/sessions/${segment(sessionOf(ctx))}/openai/rate-limits/${segment(this.id)}`);
4512
+ }
4513
+ async [Symbol.asyncDispose]() {
4514
+ await disposeQuietly(() => this.undo());
4515
+ }
4516
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
4517
+ [QUIET]() {
4518
+ return quietOf(this.#ctx);
4519
+ }
4520
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
4521
+ [CONTEXT]() {
4522
+ return this.#ctx;
4523
+ }
4524
+ }
4525
+ export class Place {
4526
+ channel;
4527
+ title;
4528
+ id;
4529
+ name;
4530
+ active;
4531
+ #ctx;
4532
+ /** @internal Handles come from the SDK, never from `new`. */
4533
+ constructor(ctx, data) {
4534
+ this.#ctx = ctx;
4535
+ this.channel = data.channel;
4536
+ this.title = data.title;
4537
+ this.id = data.id;
4538
+ this.name = data.name;
4539
+ this.active = data.active;
4540
+ }
4541
+ /** A place as a person reads it: the transcript its channel's own transcript route has. Experimental. */
4542
+ async transcript() {
4543
+ const ctx = this.#ctx;
4544
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/places/${segment(this.channel)}/${segment(this.id)}/transcript`));
4545
+ return decodePlaceTranscript(ctx, data);
4546
+ }
4547
+ /** @internal Is the agent quiet in this handle's session? Matchers ask this. */
4548
+ [QUIET]() {
4549
+ return quietOf(this.#ctx);
4550
+ }
4551
+ /** @internal The server and session this handle lives in: what a failing matcher reads the session's model calls with. */
4552
+ [CONTEXT]() {
4553
+ return this.#ctx;
4554
+ }
4555
+ }
4556
+ export class GitHubPullRequest extends GitHubIssue {
4557
+ head;
4558
+ base;
4559
+ #ctx;
4560
+ /** @internal Handles come from the SDK, never from `new`. */
4561
+ constructor(ctx, data) {
4562
+ super(ctx, data);
4563
+ this.#ctx = ctx;
4564
+ this.head = data.head;
4565
+ this.base = data.base;
4566
+ }
4567
+ /** Read the pull request again. Experimental. */
4568
+ async refresh() {
4569
+ const ctx = this.#ctx;
4570
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.repoId)}/pulls/${segment(this.number)}`));
4571
+ return new GitHubPullRequest(ctx, data);
4572
+ }
4573
+ /** The newest commit of the pull request's branch, once the agent is quiet. Experimental. */
4574
+ async headCommit() {
4575
+ const ctx = this.#ctx;
4576
+ await untilQuiet(() => quietOf(ctx));
4577
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.repoId)}/pulls/${segment(this.number)}/head-commit`));
4578
+ return new GitHubCommit(ctx, data);
4579
+ }
4580
+ /** The submitted reviews, oldest first. Experimental. */
4581
+ async reviews() {
4582
+ const ctx = this.#ctx;
4583
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.repoId)}/pulls/${segment(this.number)}/reviews`));
4584
+ return decodeGitHubReviews(ctx, data);
4585
+ }
4586
+ /** The comments on the diff, oldest first. Experimental. */
4587
+ async reviewComments() {
4588
+ const ctx = this.#ctx;
4589
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.repoId)}/pulls/${segment(this.number)}/review-comments`));
4590
+ return decodeGitHubReviewComments(ctx, data);
4591
+ }
4592
+ /** The check runs on the pull request's newest commit: the newest of each name. Experimental. */
4593
+ async checkRuns() {
4594
+ const ctx = this.#ctx;
4595
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.repoId)}/pulls/${segment(this.number)}/check-runs`));
4596
+ return decodeGitHubPullCheckRuns(ctx, data);
4597
+ }
4598
+ /** Has the pull request been merged?. Experimental. */
4599
+ async merged() {
4600
+ const ctx = this.#ctx;
4601
+ const data = (await ctx.transport.request("GET", `/sessions/${segment(sessionOf(ctx))}/github/repos/${segment(this.repoId)}/pulls/${segment(this.number)}/merged`));
4602
+ return data;
4603
+ }
4604
+ }
4605
+ /** Attach to a running channelstack server, or start one, and return the client. */
4606
+ export function connect(options = {}) {
4607
+ return connectWith((transport, stop) => new Channelstack(transport, stop), { basePath: "/_channelstack", errors: ERRORS, version: VERSION }, options);
4608
+ }