@dench.com/cli 2.9.5-staging.239 → 2.9.6-staging.240

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.
@@ -0,0 +1,1376 @@
1
+ /**
2
+ * The curated `window.dench` surface — the ONE place that says which
3
+ * methods the App SDK exposes, what each needs, and what it wraps.
4
+ *
5
+ * Three consumers read this file (via `scripts/generate-app-sdk.ts`):
6
+ *
7
+ * • `cli/lib/app-sdk-catalog.generated.ts` — method → permission map
8
+ * shared by the browser host (`src/lib/workspace/app-permissions.ts`)
9
+ * and `dench apps validate`.
10
+ * • `cli/app-sdk.d.ts` — the `Dench` type shipped with `@dench.com/cli`.
11
+ * • `public/references/APPS.md` — the generated method/permission index.
12
+ *
13
+ * Two kinds of method:
14
+ *
15
+ * • `op` — a thin alias over a registry operation (`cli/lib/
16
+ * command-registry.ts`). The host forwards it through
17
+ * `POST /api/apps/sdk` exactly like `dench.api.call(op, args)`;
18
+ * only the argument shape differs (positional sugar). Its
19
+ * permission is derived from the operation unless overridden.
20
+ * • `host` — implemented by the iframe host itself (UI, store, events,
21
+ * clipboard, streaming chat, geo). Never reachable via
22
+ * `dench.api`.
23
+ *
24
+ * The bridge script in `src/lib/workspace/app-bridge.ts` is still written
25
+ * by hand (positional sugar cannot be generated), and
26
+ * `app-bridge-parity.test.ts` asserts it matches this file exactly.
27
+ */
28
+
29
+ export const APP_SDK_VERSION = "2.0.0";
30
+
31
+ export type AppSdkMethodSpec = {
32
+ /** Permission scope, or `null` for none. Omit on `op` methods to derive. */
33
+ permission?: string | null;
34
+ /** Registry operation id this alias wraps. */
35
+ op?: string;
36
+ /** Host-only method (no registry operation behind it). */
37
+ host?: true;
38
+ /**
39
+ * SDK-side sugar that computes the operation id at call time and goes
40
+ * through `api.call` (so the host only ever sees the operation). The
41
+ * permission listed is the family it reaches.
42
+ */
43
+ viaApi?: true;
44
+ /** One-line description (d.ts JSDoc + APPS.md index). */
45
+ doc: string;
46
+ /** TypeScript parameter list for the d.ts. */
47
+ args: string;
48
+ /** TypeScript return type for the d.ts (default `Promise<unknown>`). */
49
+ returns?: string;
50
+ /** Deprecation note; the method still works for one major version. */
51
+ deprecated?: string;
52
+ };
53
+
54
+ export type AppSdkSurface = Record<string, Record<string, AppSdkMethodSpec>>;
55
+
56
+ const R = (op: string) => `Promise<Res<${JSON.stringify(op)}>>`;
57
+ const A = (op: string) => `Req<${JSON.stringify(op)}>`;
58
+ const Rest = (op: string, ...omit: string[]) =>
59
+ `Omit<Req<${JSON.stringify(op)}>, ${omit.map((k) => JSON.stringify(k)).join(" | ")}>`;
60
+
61
+ export const APP_SDK_SURFACE: AppSdkSurface = {
62
+ app: {
63
+ getManifest: {
64
+ host: true,
65
+ permission: null,
66
+ doc: "The parsed .dench.yaml of this app.",
67
+ args: "",
68
+ returns: "Promise<AppManifest>",
69
+ },
70
+ getTheme: {
71
+ host: true,
72
+ permission: null,
73
+ doc: 'Current workspace theme ("light" | "dark").',
74
+ args: "",
75
+ returns: 'Promise<"light" | "dark">',
76
+ },
77
+ },
78
+ context: {
79
+ getWorkspace: {
80
+ host: true,
81
+ permission: null,
82
+ doc: "Workspace name/slug the app is running in.",
83
+ args: "",
84
+ returns: "Promise<{ name: string; slug: string | null }>",
85
+ },
86
+ getAppInfo: {
87
+ host: true,
88
+ permission: null,
89
+ doc: "App path, folder slug, granted permissions and manifest.",
90
+ args: "",
91
+ returns:
92
+ "Promise<{ appPath: string; folderName: string; permissions: string[]; manifest: AppManifest }>",
93
+ },
94
+ },
95
+ api: {
96
+ call: {
97
+ host: true,
98
+ permission: null,
99
+ doc: 'Call ANY public /api/v1 operation by id (e.g. "crm.query"). Permission is the operation\'s own scope.',
100
+ args: "operationId: K, args?: Req<K>",
101
+ returns: "Promise<Res<K>>",
102
+ },
103
+ operations: {
104
+ host: true,
105
+ permission: null,
106
+ doc: "Runtime catalog of every callable operation: id, cli, method, path, permission.",
107
+ args: "opts?: { group?: string }",
108
+ returns: "Promise<ApiOperationInfo[]>",
109
+ },
110
+ },
111
+
112
+ objects: {
113
+ list: {
114
+ host: true,
115
+ permission: "crm:read",
116
+ doc: "Paged rows of an object (flat `id` + field-on-row shape).",
117
+ args: "name: string, opts?: ObjectsListOptions",
118
+ returns: "Promise<ObjectsListResult>",
119
+ },
120
+ query: {
121
+ host: true,
122
+ permission: "crm:read",
123
+ doc: "Filter/sort/select rows with the query DSL (max 1000). Aggregate with analytics.compute instead.",
124
+ args: "dsl: ObjectsQuery",
125
+ returns: "Promise<ObjectsQueryResult>",
126
+ },
127
+ get: {
128
+ host: true,
129
+ permission: "crm:read",
130
+ doc: "One entry by id.",
131
+ args: "name: string, entryId: string",
132
+ returns: "Promise<ObjectEntry>",
133
+ },
134
+ create: {
135
+ host: true,
136
+ permission: "crm:write",
137
+ doc: "Create an entry.",
138
+ args: "name: string, fields: Record<string, unknown>",
139
+ returns: "Promise<ObjectEntry>",
140
+ },
141
+ update: {
142
+ host: true,
143
+ permission: "crm:write",
144
+ doc: "Patch an entry's fields.",
145
+ args: "name: string, entryId: string, fields: Record<string, unknown>",
146
+ returns: "Promise<{ ok: boolean }>",
147
+ },
148
+ delete: {
149
+ host: true,
150
+ permission: "crm:write",
151
+ doc: "Delete one entry.",
152
+ args: "name: string, entryId: string",
153
+ returns: "Promise<{ ok: boolean }>",
154
+ },
155
+ bulkDelete: {
156
+ host: true,
157
+ permission: "crm:write",
158
+ doc: "Delete many entries.",
159
+ args: "name: string, entryIds: string[]",
160
+ returns: "Promise<{ ok: boolean; deleted?: number }>",
161
+ },
162
+ getSchema: {
163
+ host: true,
164
+ permission: "crm:read",
165
+ doc: "Object definition: fields, types, enum options, relations.",
166
+ args: "name: string",
167
+ returns: "Promise<ObjectSchema>",
168
+ },
169
+ getOptions: {
170
+ host: true,
171
+ permission: "crm:read",
172
+ doc: "Relation picker options (id + label) for an object, optionally filtered.",
173
+ args: "name: string, query?: string",
174
+ returns: "Promise<Array<{ id: string; label: string }>>",
175
+ },
176
+ },
177
+
178
+ analytics: {
179
+ get: {
180
+ op: "crm.analytics.get",
181
+ doc: "Stored dashboard: panels, field roles, collapsed flag (+ the view's own dashboard when viewName is set).",
182
+ args: `objectName: string, opts?: ${Rest("crm.analytics.get", "objectName")}`,
183
+ returns: R("crm.analytics.get"),
184
+ },
185
+ compute: {
186
+ op: "crm.analytics.compute",
187
+ doc: "Pre-bucketed KPIs/charts/maps — the strip's own math. Stored dashboard, `panelIds`, or ad-hoc `panels`; `period` and `drillFilters` expand server-side.",
188
+ args: `objectName: string, opts?: ${Rest("crm.analytics.compute", "objectName")}`,
189
+ returns: R("crm.analytics.compute"),
190
+ },
191
+ save: {
192
+ op: "crm.analytics.save",
193
+ doc: "Create or update a stored panel (object dashboard, or the view's when viewName is set — first save forks an inheriting view).",
194
+ args: `objectName: string, panelId: string, panel: Req<"crm.analytics.save">["panel"], opts?: ${Rest("crm.analytics.save", "objectName", "panelId", "panel")}`,
195
+ returns: R("crm.analytics.save"),
196
+ },
197
+ update: {
198
+ op: "crm.analytics.update",
199
+ doc: "Edit part of a stored panel (title, type, metric, groupBy, dateField, filters, derived, span, hidden, sortOrder …); null clears an optional key.",
200
+ args: `objectName: string, panelId: string, patch: Req<"crm.analytics.update">["patch"], opts?: ${Rest("crm.analytics.update", "objectName", "panelId", "patch")}`,
201
+ returns: R("crm.analytics.update"),
202
+ },
203
+ hide: {
204
+ op: "crm.analytics.hide",
205
+ doc: "Take a chart off the strip above the table; it stays in the full analytics view.",
206
+ args: `objectName: string, panelId: string, opts?: ${Rest("crm.analytics.hide", "objectName", "panelId")}`,
207
+ returns: R("crm.analytics.hide"),
208
+ },
209
+ show: {
210
+ op: "crm.analytics.show",
211
+ doc: "Bring a hidden chart back onto the strip.",
212
+ args: `objectName: string, panelId: string, opts?: ${Rest("crm.analytics.show", "objectName", "panelId")}`,
213
+ returns: R("crm.analytics.show"),
214
+ },
215
+ resize: {
216
+ op: "crm.analytics.resize",
217
+ doc: "Set a card's width: span 2 (third) | 3 (half) | 4 (two thirds) | 6 (full) | null (default for the chart kind).",
218
+ args: `objectName: string, panelId: string, span: Req<"crm.analytics.resize">["span"], opts?: ${Rest("crm.analytics.resize", "objectName", "panelId", "span")}`,
219
+ returns: R("crm.analytics.resize"),
220
+ },
221
+ delete: {
222
+ op: "crm.analytics.delete",
223
+ doc: "Delete a stored panel.",
224
+ args: `objectName: string, panelId: string, opts?: ${Rest("crm.analytics.delete", "objectName", "panelId")}`,
225
+ returns: R("crm.analytics.delete"),
226
+ },
227
+ reorder: {
228
+ op: "crm.analytics.reorder",
229
+ doc: "Persist the full panel order.",
230
+ args: `objectName: string, panelIds: string[], opts?: ${Rest("crm.analytics.reorder", "objectName", "panelIds")}`,
231
+ returns: R("crm.analytics.reorder"),
232
+ },
233
+ roles: {
234
+ op: "crm.analytics.roles",
235
+ doc: "Set the object's analytics setup shared by every chart and view: amount / stage / won-lost-converted / stageProbabilities / closeDate / recurrence / owner / location. Pass merge: true to change only the keys given (null clears one).",
236
+ args: `objectName: string, fieldRoles: Req<"crm.analytics.roles">["fieldRoles"], opts?: ${Rest("crm.analytics.roles", "objectName", "fieldRoles")}`,
237
+ returns: R("crm.analytics.roles"),
238
+ },
239
+ collapse: {
240
+ op: "crm.analytics.collapse",
241
+ doc: "Collapse the team-shared strip for this object.",
242
+ args: "objectName: string",
243
+ returns: R("crm.analytics.collapse"),
244
+ },
245
+ expand: {
246
+ op: "crm.analytics.expand",
247
+ doc: "Expand the team-shared strip for this object.",
248
+ args: "objectName: string",
249
+ returns: R("crm.analytics.expand"),
250
+ },
251
+ scope: {
252
+ op: "crm.analytics.scope",
253
+ doc: 'Flip a saved view between its "own" dashboard and the object\'s "shared" one.',
254
+ args: `objectName: string, viewName: string, mode: Req<"crm.analytics.scope">["mode"]`,
255
+ returns: R("crm.analytics.scope"),
256
+ },
257
+ },
258
+
259
+ comments: {
260
+ list: {
261
+ op: "crm.comments.list",
262
+ doc: "Root comments on an entry (with reply previews), paged.",
263
+ args: `objectName: string, entryId: string, opts?: ${Rest("crm.comments.list", "objectName", "entryId")}`,
264
+ returns: R("crm.comments.list"),
265
+ },
266
+ replies: {
267
+ op: "crm.comments.replies",
268
+ doc: "Replies under a root comment.",
269
+ args: `commentId: string, opts?: ${Rest("crm.comments.replies", "commentId")}`,
270
+ returns: R("crm.comments.replies"),
271
+ },
272
+ get: {
273
+ op: "crm.comments.get",
274
+ doc: "One comment.",
275
+ args: "commentId: string",
276
+ returns: R("crm.comments.get"),
277
+ },
278
+ create: {
279
+ op: "crm.comments.create",
280
+ doc: "Post a markdown comment (mention members with [@Name](/?member=<userId>), Dench with [@Dench](/?member=dench)).",
281
+ args: `objectName: string, entryId: string, body: string, opts?: ${Rest("crm.comments.create", "objectName", "entryId", "body")}`,
282
+ returns: R("crm.comments.create"),
283
+ },
284
+ update: {
285
+ op: "crm.comments.update",
286
+ doc: "Edit a comment body.",
287
+ args: "commentId: string, body: string",
288
+ returns: R("crm.comments.update"),
289
+ },
290
+ delete: {
291
+ op: "crm.comments.delete",
292
+ doc: "Delete a comment.",
293
+ args: "commentId: string",
294
+ returns: R("crm.comments.delete"),
295
+ },
296
+ react: {
297
+ op: "crm.comments.react",
298
+ doc: "Toggle an emoji reaction.",
299
+ args: "commentId: string, emoji: string",
300
+ returns: R("crm.comments.react"),
301
+ },
302
+ },
303
+
304
+ watch: {
305
+ get: {
306
+ op: "crm.watch.get",
307
+ doc: "Am I following this entry?",
308
+ args: "objectName: string, entryId: string",
309
+ returns: R("crm.watch.get"),
310
+ },
311
+ set: {
312
+ op: "crm.watch.set",
313
+ doc: "Follow (default) or unfollow an entry.",
314
+ args: "objectName: string, entryId: string, watching?: boolean",
315
+ returns: R("crm.watch.set"),
316
+ },
317
+ },
318
+
319
+ views: {
320
+ list: {
321
+ op: "crm.views.list",
322
+ doc: "Saved views of an object.",
323
+ args: "objectName: string",
324
+ returns: R("crm.views.list"),
325
+ },
326
+ get: {
327
+ op: "crm.views.get",
328
+ doc: "One saved view (filters, sort, columns, analytics).",
329
+ args: "objectName: string, viewName: string",
330
+ returns: R("crm.views.get"),
331
+ },
332
+ entries: {
333
+ op: "crm.views.entries",
334
+ doc: "Rows as the saved view shows them.",
335
+ args: `objectName: string, viewName: string, opts?: ${Rest("crm.views.entries", "objectName", "viewName")}`,
336
+ returns: R("crm.views.entries"),
337
+ },
338
+ create: {
339
+ op: "crm.views.create",
340
+ doc: "Create a saved view.",
341
+ args: `objectName: string, view: ${Rest("crm.views.create", "objectName")}`,
342
+ returns: R("crm.views.create"),
343
+ },
344
+ update: {
345
+ op: "crm.views.update",
346
+ doc: "Update a saved view.",
347
+ args: `objectName: string, viewName: string, patch: ${Rest("crm.views.update", "objectName", "viewName")}`,
348
+ returns: R("crm.views.update"),
349
+ },
350
+ delete: {
351
+ op: "crm.views.delete",
352
+ doc: "Delete a saved view.",
353
+ args: "objectName: string, viewName: string",
354
+ returns: R("crm.views.delete"),
355
+ },
356
+ },
357
+
358
+ tasks: {
359
+ mine: {
360
+ op: "crm.tasks.mine",
361
+ doc: "Open tasks assigned to me.",
362
+ args: `opts?: ${A("crm.tasks.mine")}`,
363
+ returns: R("crm.tasks.mine"),
364
+ },
365
+ forEntry: {
366
+ op: "crm.tasks.forEntry",
367
+ doc: "Tasks linked to an entry.",
368
+ args: "objectName: string, entryId: string",
369
+ returns: R("crm.tasks.forEntry"),
370
+ },
371
+ create: {
372
+ op: "crm.tasks.createForEntry",
373
+ doc: "Create a task on an entry.",
374
+ args: `objectName: string, entryId: string, task: ${Rest("crm.tasks.createForEntry", "objectName", "entryId")}`,
375
+ returns: R("crm.tasks.createForEntry"),
376
+ },
377
+ complete: {
378
+ op: "crm.tasks.complete",
379
+ doc: "Mark a task done.",
380
+ args: "entryId: string",
381
+ returns: R("crm.tasks.complete"),
382
+ },
383
+ reopen: {
384
+ op: "crm.tasks.reopen",
385
+ doc: "Reopen a task.",
386
+ args: "entryId: string",
387
+ returns: R("crm.tasks.reopen"),
388
+ },
389
+ },
390
+
391
+ notifications: {
392
+ list: {
393
+ op: "notifications.list",
394
+ doc: "My notifications (inbox | unread | archived | all | mentions).",
395
+ args: `opts?: ${A("notifications.list")}`,
396
+ returns: R("notifications.list"),
397
+ },
398
+ unreadCount: {
399
+ op: "notifications.unreadCount",
400
+ doc: "Unread badge count.",
401
+ args: "",
402
+ returns: R("notifications.unreadCount"),
403
+ },
404
+ read: {
405
+ op: "notifications.read",
406
+ doc: "Mark one read (or unread).",
407
+ args: "notificationId: string, read?: boolean",
408
+ returns: R("notifications.read"),
409
+ },
410
+ readAll: {
411
+ op: "notifications.readAll",
412
+ doc: "Mark everything read.",
413
+ args: "",
414
+ returns: R("notifications.readAll"),
415
+ },
416
+ archive: {
417
+ op: "notifications.archive",
418
+ doc: "Archive one notification.",
419
+ args: "notificationId: string",
420
+ returns: R("notifications.archive"),
421
+ },
422
+ getPreferences: {
423
+ op: "notifications.preferences.get",
424
+ doc: "My notification preferences.",
425
+ args: "",
426
+ returns: R("notifications.preferences.get"),
427
+ },
428
+ updatePreferences: {
429
+ op: "notifications.preferences.update",
430
+ doc: "Update my notification preferences.",
431
+ args: `patch: ${A("notifications.preferences.update")}`,
432
+ returns: R("notifications.preferences.update"),
433
+ },
434
+ },
435
+
436
+ members: {
437
+ get: {
438
+ op: "members.get",
439
+ doc: "A member's profile.",
440
+ args: "userId: string",
441
+ returns: R("members.get"),
442
+ },
443
+ presence: {
444
+ op: "members.presence",
445
+ doc: "Who is online / away / offline.",
446
+ args: "",
447
+ returns: R("members.presence"),
448
+ },
449
+ activity: {
450
+ op: "members.activity",
451
+ doc: "A member's recent CRM activity.",
452
+ args: `userId: string, opts?: ${Rest("members.activity", "userId")}`,
453
+ returns: R("members.activity"),
454
+ },
455
+ tasks: {
456
+ op: "members.tasks",
457
+ doc: "A member's open tasks.",
458
+ args: `userId: string, opts?: ${Rest("members.tasks", "userId")}`,
459
+ returns: R("members.tasks"),
460
+ },
461
+ me: {
462
+ op: "me.profile.get",
463
+ doc: "My own profile.",
464
+ args: "",
465
+ returns: R("me.profile.get"),
466
+ },
467
+ updateMe: {
468
+ op: "me.profile.update",
469
+ doc: "Update my name / tagline / timezone.",
470
+ args: `patch: ${A("me.profile.update")}`,
471
+ returns: R("me.profile.update"),
472
+ },
473
+ },
474
+
475
+ meetings: {
476
+ list: {
477
+ op: "meetings.list",
478
+ doc: "Meetings (CRM `meeting` rows), newest first.",
479
+ args: `opts?: ${A("meetings.list")}`,
480
+ returns: R("meetings.list"),
481
+ },
482
+ transcript: {
483
+ op: "meetings.transcript.list",
484
+ doc: "Transcript segments of a meeting.",
485
+ args: `meetingEntryId: string, opts?: ${Rest("meetings.transcript.list", "meetingEntryId")}`,
486
+ returns: R("meetings.transcript.list"),
487
+ },
488
+ actionItems: {
489
+ op: "meetings.actionItems.list",
490
+ doc: "Action items of a meeting.",
491
+ args: "meetingEntryId: string",
492
+ returns: R("meetings.actionItems.list"),
493
+ },
494
+ addActionItems: {
495
+ op: "meetings.actionItems.add",
496
+ doc: "Add action items to a meeting.",
497
+ args: `meetingEntryId: string, items: Req<"meetings.actionItems.add">["items"]`,
498
+ returns: R("meetings.actionItems.add"),
499
+ },
500
+ setActionItemDone: {
501
+ op: "meetings.actionItems.setDone",
502
+ doc: "Check or uncheck an action item.",
503
+ args: "itemId: string, done: boolean",
504
+ returns: R("meetings.actionItems.setDone"),
505
+ },
506
+ participants: {
507
+ op: "meetings.participants.list",
508
+ doc: "Participants of a meeting.",
509
+ args: "meetingEntryId: string",
510
+ returns: R("meetings.participants.list"),
511
+ },
512
+ },
513
+
514
+ lists: {
515
+ list: {
516
+ op: "lists.list",
517
+ doc: "Saved lead lists.",
518
+ args: `opts?: ${A("lists.list")}`,
519
+ returns: R("lists.list"),
520
+ },
521
+ get: {
522
+ op: "lists.get",
523
+ doc: "One saved list with its rows.",
524
+ args: "artifactId: string",
525
+ returns: R("lists.get"),
526
+ },
527
+ rename: {
528
+ op: "lists.rename",
529
+ doc: "Rename a list.",
530
+ args: "artifactId: string, title: string",
531
+ returns: R("lists.rename"),
532
+ },
533
+ delete: {
534
+ op: "lists.delete",
535
+ doc: "Delete a list.",
536
+ args: "artifactId: string",
537
+ returns: R("lists.delete"),
538
+ },
539
+ },
540
+
541
+ campaigns: {
542
+ list: {
543
+ op: "campaigns.list",
544
+ doc: "LinkedIn / multi-channel outreach campaigns.",
545
+ args: "",
546
+ returns: R("campaigns.list"),
547
+ },
548
+ get: {
549
+ op: "campaigns.get",
550
+ doc: "One campaign.",
551
+ args: "sequenceId: string",
552
+ returns: R("campaigns.get"),
553
+ },
554
+ analytics: {
555
+ op: "campaigns.analytics",
556
+ doc: "Campaign funnel numbers.",
557
+ args: "sequenceId: string",
558
+ returns: R("campaigns.analytics"),
559
+ },
560
+ events: {
561
+ op: "campaigns.events",
562
+ doc: "Campaign event log.",
563
+ args: `sequenceId: string, opts?: ${Rest("campaigns.events", "sequenceId")}`,
564
+ returns: R("campaigns.events"),
565
+ },
566
+ pause: {
567
+ op: "campaigns.pause",
568
+ doc: "Pause a campaign.",
569
+ args: "sequenceId: string",
570
+ returns: R("campaigns.pause"),
571
+ },
572
+ resume: {
573
+ op: "campaigns.resume",
574
+ doc: "Resume a campaign.",
575
+ args: "sequenceId: string",
576
+ returns: R("campaigns.resume"),
577
+ },
578
+ },
579
+
580
+ email: {
581
+ send: {
582
+ op: "email.send",
583
+ doc: "Send one email from a verified identity.",
584
+ args: `message: ${A("email.send")}`,
585
+ returns: R("email.send"),
586
+ },
587
+ messages: {
588
+ op: "email.message.list",
589
+ doc: "Sent messages.",
590
+ args: `opts?: ${A("email.message.list")}`,
591
+ returns: R("email.message.list"),
592
+ },
593
+ message: {
594
+ op: "email.message.get",
595
+ doc: "One sent message with delivery events.",
596
+ args: "messageId: string",
597
+ returns: R("email.message.get"),
598
+ },
599
+ campaigns: {
600
+ op: "email.campaign.list",
601
+ doc: "Email campaigns.",
602
+ args: `opts?: ${A("email.campaign.list")}`,
603
+ returns: R("email.campaign.list"),
604
+ },
605
+ campaign: {
606
+ op: "email.campaign.get",
607
+ doc: "One email campaign.",
608
+ args: "campaignId: string",
609
+ returns: R("email.campaign.get"),
610
+ },
611
+ identities: {
612
+ op: "email.identity.list",
613
+ doc: "Verified sending identities.",
614
+ args: "",
615
+ returns: R("email.identity.list"),
616
+ },
617
+ },
618
+
619
+ billing: {
620
+ status: {
621
+ op: "billing.status",
622
+ doc: "Plan, AI balance and usage for the workspace.",
623
+ args: "",
624
+ returns: R("billing.status"),
625
+ },
626
+ topup: {
627
+ op: "billing.topup",
628
+ doc: "Start an AI credit top-up (returns a Stripe URL).",
629
+ args: `opts?: ${A("billing.topup")}`,
630
+ returns: R("billing.topup"),
631
+ },
632
+ upgrade: {
633
+ op: "billing.upgrade",
634
+ doc: "Upgrade the plan (returns a Stripe Checkout URL or updates in place).",
635
+ args: `opts?: ${A("billing.upgrade")}`,
636
+ returns: R("billing.upgrade"),
637
+ },
638
+ },
639
+
640
+ approvals: {
641
+ list: {
642
+ op: "workspace.approvals.list",
643
+ doc: "Pending approvals in the workspace.",
644
+ args: "",
645
+ returns: R("workspace.approvals.list"),
646
+ },
647
+ request: {
648
+ op: "approval.request",
649
+ doc: "Ask a human to approve an action.",
650
+ args: `request: ${A("approval.request")}`,
651
+ returns: R("approval.request"),
652
+ },
653
+ decide: {
654
+ op: "approval.decide",
655
+ doc: "Approve or reject a pending approval.",
656
+ args: `approvalId: string, decision: Req<"approval.decide">["decision"], opts?: ${Rest("approval.decide", "approvalId", "decision")}`,
657
+ returns: R("approval.decide"),
658
+ },
659
+ },
660
+
661
+ memory: {
662
+ get: {
663
+ host: true,
664
+ permission: "memory:read",
665
+ doc: "The workspace's saved memories (legacy shape).",
666
+ args: "",
667
+ deprecated: "Use memory.search(query).",
668
+ },
669
+ search: {
670
+ op: "memory.search",
671
+ doc: "Full-text search over saved memories.",
672
+ args: `query: string, opts?: ${Rest("memory.search", "query")}`,
673
+ returns: R("memory.search"),
674
+ },
675
+ save: {
676
+ op: "memory.save",
677
+ doc: "Save a memory under a stable key.",
678
+ args: `memory: ${A("memory.save")}`,
679
+ returns: R("memory.save"),
680
+ },
681
+ },
682
+
683
+ workspace: {
684
+ context: {
685
+ op: "workspace.context",
686
+ doc: "What this workspace has: objects, agents, integrations, next commands.",
687
+ args: "",
688
+ returns: R("workspace.context"),
689
+ },
690
+ status: {
691
+ op: "workspace.status",
692
+ doc: "Workspace status snapshot.",
693
+ args: "",
694
+ returns: R("workspace.status"),
695
+ },
696
+ agents: {
697
+ op: "workspace.agents",
698
+ doc: "Agents in this workspace.",
699
+ args: "",
700
+ returns: R("workspace.agents"),
701
+ },
702
+ artifacts: {
703
+ op: "workspace.artifacts.list",
704
+ doc: "Recent artifacts (reports, docs, lists).",
705
+ args: `opts?: ${A("workspace.artifacts.list")}`,
706
+ returns: R("workspace.artifacts.list"),
707
+ },
708
+ instructions: {
709
+ op: "workspace.instructions",
710
+ doc: "Workspace instructions the agent follows.",
711
+ args: "",
712
+ returns: R("workspace.instructions"),
713
+ },
714
+ },
715
+
716
+ search: {
717
+ web: {
718
+ op: "search.web",
719
+ doc: "Web search (gateway).",
720
+ args: `query: string, opts?: ${Rest("search.web", "query")}`,
721
+ returns: R("search.web"),
722
+ },
723
+ contents: {
724
+ op: "search.contents",
725
+ doc: "Fetch page contents for search results.",
726
+ args: `opts: ${A("search.contents")}`,
727
+ returns: R("search.contents"),
728
+ },
729
+ answer: {
730
+ op: "search.answer",
731
+ doc: "Answer a question from web sources.",
732
+ args: `query: string, opts?: ${Rest("search.answer", "query")}`,
733
+ returns: R("search.answer"),
734
+ },
735
+ },
736
+
737
+ web: {
738
+ scrape: {
739
+ op: "web.scrape",
740
+ doc: "Scrape a URL to Markdown.",
741
+ args: `url: string, opts?: ${Rest("web.scrape", "url")}`,
742
+ returns: R("web.scrape"),
743
+ },
744
+ brand: {
745
+ op: "web.brand",
746
+ doc: "Brand kit (logo, colors, fonts) for a domain.",
747
+ args: `domain: string, opts?: ${Rest("web.brand", "domain")}`,
748
+ returns: R("web.brand"),
749
+ },
750
+ screenshot: {
751
+ op: "web.screenshot",
752
+ doc: "Screenshot a rendered page.",
753
+ args: `url: string, opts?: ${Rest("web.screenshot", "url")}`,
754
+ returns: R("web.screenshot"),
755
+ },
756
+ extract: {
757
+ op: "web.extract",
758
+ doc: "Extract structured data from a page.",
759
+ args: `opts: ${A("web.extract")}`,
760
+ returns: R("web.extract"),
761
+ },
762
+ },
763
+
764
+ images: {
765
+ generate: {
766
+ op: "image.generate",
767
+ doc: "Generate an image from a prompt.",
768
+ args: `opts: ${A("image.generate")}`,
769
+ returns: R("image.generate"),
770
+ },
771
+ edit: {
772
+ op: "image.edit",
773
+ doc: "Edit an image with a prompt.",
774
+ args: `opts: ${A("image.edit")}`,
775
+ returns: R("image.edit"),
776
+ },
777
+ },
778
+
779
+ agentConfig: {
780
+ show: {
781
+ viaApi: true,
782
+ permission: "agent-config:read",
783
+ doc: 'Read one config section: "identity" | "organisation" | "user" | "tools" | "mem" | "bootstrap".',
784
+ args: "section: AgentConfigSection",
785
+ },
786
+ edit: {
787
+ viaApi: true,
788
+ permission: "agent-config:write",
789
+ doc: "Replace one config section's markdown.",
790
+ args: "section: AgentConfigSection, content: string",
791
+ },
792
+ },
793
+
794
+ files: {
795
+ read: {
796
+ op: "files.content",
797
+ doc: "Read a workspace file (text inline; binary → `downloadable: true`).",
798
+ args: "path: string",
799
+ returns: R("files.content"),
800
+ },
801
+ list: {
802
+ op: "files.list",
803
+ doc: "List a directory (default /).",
804
+ args: "dir?: string",
805
+ returns: R("files.list"),
806
+ },
807
+ write: {
808
+ op: "files.write",
809
+ doc: "Write a UTF-8 text file (creates parents).",
810
+ args: `path: string, content: string, opts?: ${Rest("files.write", "path", "content")}`,
811
+ returns: R("files.write"),
812
+ },
813
+ delete: {
814
+ op: "files.delete",
815
+ doc: "Delete a file or directory.",
816
+ args: "path: string",
817
+ returns: R("files.delete"),
818
+ },
819
+ mkdir: {
820
+ op: "files.mkdir",
821
+ doc: "Create a directory (and parents).",
822
+ args: "path: string",
823
+ returns: R("files.mkdir"),
824
+ },
825
+ move: {
826
+ op: "files.move",
827
+ doc: "Move / rename a file or directory.",
828
+ args: "from: string, to: string",
829
+ returns: R("files.move"),
830
+ },
831
+ download: {
832
+ op: "files.downloadUrl",
833
+ doc: "Short-lived signed URL for a file's bytes.",
834
+ args: "path: string",
835
+ returns: R("files.downloadUrl"),
836
+ },
837
+ },
838
+
839
+ chat: {
840
+ createSession: {
841
+ host: true,
842
+ permission: "ai:chat",
843
+ doc: "Create an empty chat thread; returns its id.",
844
+ args: "title?: string",
845
+ returns: "Promise<{ id: string; threadId: string; _id: string }>",
846
+ },
847
+ send: {
848
+ host: true,
849
+ permission: "ai:chat",
850
+ doc: "Send a message to a thread. With `onEvent`, text-delta chunks stream in; resolves with the full reply.",
851
+ args: "sessionId: string, message: string, opts?: { onEvent?: (event: ChatStreamEvent) => void }",
852
+ returns: "Promise<{ text: string; threadId: string }>",
853
+ },
854
+ getHistory: {
855
+ op: "chat.read",
856
+ doc: "Messages in a thread (via chat.read).",
857
+ args: "sessionId: string, opts?: { limit?: number }",
858
+ returns: R("chat.read"),
859
+ },
860
+ getSessions: {
861
+ op: "chat.list",
862
+ doc: "Recent threads.",
863
+ args: `opts?: ${A("chat.list")}`,
864
+ returns: R("chat.list"),
865
+ },
866
+ abort: {
867
+ host: true,
868
+ permission: "ai:chat",
869
+ doc: "Stop the active run on a thread.",
870
+ args: "sessionId: string",
871
+ returns: "Promise<unknown>",
872
+ },
873
+ isActive: {
874
+ host: true,
875
+ permission: "ai:chat",
876
+ doc: "Whether the thread has a running turn.",
877
+ args: "sessionId: string",
878
+ returns: "Promise<boolean>",
879
+ },
880
+ list: {
881
+ op: "chat.list",
882
+ doc: "Recent threads (alias of getSessions).",
883
+ args: `opts?: ${A("chat.list")}`,
884
+ returns: R("chat.list"),
885
+ },
886
+ search: {
887
+ op: "chat.search",
888
+ doc: "Full-text search across past messages.",
889
+ args: `query: string, opts?: ${Rest("chat.search", "query")}`,
890
+ returns: R("chat.search"),
891
+ },
892
+ rename: {
893
+ op: "chat.rename",
894
+ doc: "Rename a thread.",
895
+ args: "threadId: string, title: string",
896
+ returns: R("chat.rename"),
897
+ },
898
+ delete: {
899
+ op: "chat.delete",
900
+ doc: "Delete one or more threads.",
901
+ args: "threadIds: string | string[]",
902
+ returns: R("chat.delete"),
903
+ },
904
+ },
905
+
906
+ agent: {
907
+ send: {
908
+ host: true,
909
+ permission: "agent:invoke",
910
+ doc: "Start a new agent turn in a fresh thread. Resolves once the run is accepted.",
911
+ args: "message: string, opts?: { title?: string; model?: string; yolo?: boolean }",
912
+ returns: "Promise<{ threadId: string; runId: string | null }>",
913
+ },
914
+ },
915
+
916
+ tool: {
917
+ register: {
918
+ host: true,
919
+ permission: "agent:invoke",
920
+ doc: "Expose a function the workspace agent can call while this app is open.",
921
+ args: "name: string, handler: (args: unknown) => unknown | Promise<unknown>, opts?: { description?: string; inputSchema?: unknown }",
922
+ returns: "Promise<{ ok: boolean }>",
923
+ },
924
+ },
925
+
926
+ ui: {
927
+ toast: {
928
+ host: true,
929
+ permission: "ui",
930
+ doc: "Show a toast.",
931
+ args: 'message: string, opts?: { type?: "success" | "error" | "info" }',
932
+ returns: "Promise<{ ok: boolean }>",
933
+ },
934
+ navigate: {
935
+ host: true,
936
+ permission: "ui",
937
+ doc: "Navigate the workspace to a path (e.g. /objects/company).",
938
+ args: "path: string",
939
+ returns: "Promise<{ ok: boolean }>",
940
+ },
941
+ openEntry: {
942
+ host: true,
943
+ permission: "ui",
944
+ doc: "Open a CRM record in the workspace.",
945
+ args: "objectName: string, entryId: string",
946
+ returns: "Promise<{ ok: boolean }>",
947
+ },
948
+ setTitle: {
949
+ host: true,
950
+ permission: "ui",
951
+ doc: "Set the app tab title.",
952
+ args: "title: string",
953
+ returns: "Promise<{ ok: boolean }>",
954
+ },
955
+ confirm: {
956
+ host: true,
957
+ permission: "ui",
958
+ doc: "Native confirm dialog.",
959
+ args: "message: string",
960
+ returns: "Promise<boolean>",
961
+ },
962
+ prompt: {
963
+ host: true,
964
+ permission: "ui",
965
+ doc: "Native prompt dialog.",
966
+ args: "message: string, defaultValue?: string",
967
+ returns: "Promise<string | null>",
968
+ },
969
+ },
970
+
971
+ store: {
972
+ get: {
973
+ host: true,
974
+ permission: "store:read",
975
+ doc: "Read a per-app value.",
976
+ args: "key: string",
977
+ returns: "Promise<unknown>",
978
+ },
979
+ set: {
980
+ host: true,
981
+ permission: "store:write",
982
+ doc: "Write a per-app value (JSON).",
983
+ args: "key: string, value: unknown",
984
+ returns: "Promise<{ ok: boolean }>",
985
+ },
986
+ delete: {
987
+ host: true,
988
+ permission: "store:write",
989
+ doc: "Delete a key.",
990
+ args: "key: string",
991
+ returns: "Promise<{ ok: boolean }>",
992
+ },
993
+ list: {
994
+ host: true,
995
+ permission: "store:read",
996
+ doc: "All keys for this app.",
997
+ args: "",
998
+ returns: "Promise<string[]>",
999
+ },
1000
+ clear: {
1001
+ host: true,
1002
+ permission: "store:write",
1003
+ doc: "Delete every key.",
1004
+ args: "",
1005
+ returns: "Promise<{ ok: boolean }>",
1006
+ },
1007
+ },
1008
+
1009
+ http: {
1010
+ fetch: {
1011
+ host: true,
1012
+ permission: "http:external",
1013
+ doc: "Fetch an external URL through the SSRF-guarded proxy.",
1014
+ args: "url: string, opts?: { method?: string; headers?: Record<string, string>; body?: unknown }",
1015
+ returns:
1016
+ "Promise<{ status: number; headers: Record<string, string>; body: unknown }>",
1017
+ },
1018
+ },
1019
+
1020
+ events: {
1021
+ on: {
1022
+ host: true,
1023
+ permission: null,
1024
+ doc: 'Subscribe to a channel ("object.entry.created" | "object.entry.updated" | "object.entry.deleted" | "theme.changed").',
1025
+ args: "channel: string, callback: (data: unknown) => void",
1026
+ returns: "void",
1027
+ },
1028
+ off: {
1029
+ host: true,
1030
+ permission: null,
1031
+ doc: "Unsubscribe.",
1032
+ args: "channel: string, callback?: (data: unknown) => void",
1033
+ returns: "void",
1034
+ },
1035
+ },
1036
+
1037
+ bus: {
1038
+ send: {
1039
+ host: true,
1040
+ permission: "apps:message",
1041
+ doc: "Send a message to another open app.",
1042
+ args: "targetApp: string, message: unknown",
1043
+ returns: "Promise<{ ok: boolean }>",
1044
+ },
1045
+ on: {
1046
+ host: true,
1047
+ permission: "apps:message",
1048
+ doc: "Receive messages from other apps.",
1049
+ args: "callback: (message: { from: string; message: unknown }) => void",
1050
+ returns: "void",
1051
+ },
1052
+ list: {
1053
+ host: true,
1054
+ permission: "apps:message",
1055
+ doc: "Other apps currently open.",
1056
+ args: "",
1057
+ returns: "Promise<Array<{ appName: string; tools: string[] }>>",
1058
+ },
1059
+ },
1060
+
1061
+ apps: {
1062
+ list: {
1063
+ op: "apps.list",
1064
+ doc: "Installed apps in this workspace.",
1065
+ args: "",
1066
+ returns: R("apps.list"),
1067
+ },
1068
+ gallery: {
1069
+ op: "apps.gallery",
1070
+ doc: "Discover listings (Official + Community).",
1071
+ args: "",
1072
+ returns: R("apps.gallery"),
1073
+ },
1074
+ create: {
1075
+ op: "apps.create",
1076
+ doc: "Scaffold and register a new app.",
1077
+ args: `opts: ${A("apps.create")}`,
1078
+ returns: R("apps.create"),
1079
+ },
1080
+ install: {
1081
+ op: "apps.install",
1082
+ doc: "Install a listing.",
1083
+ args: "listingId: string",
1084
+ returns: R("apps.install"),
1085
+ },
1086
+ publish: {
1087
+ op: "apps.publish",
1088
+ doc: "Publish an app folder as a listing version.",
1089
+ args: `opts: ${A("apps.publish")}`,
1090
+ returns: R("apps.publish"),
1091
+ },
1092
+ uninstall: {
1093
+ op: "apps.uninstall",
1094
+ doc: "Uninstall an app.",
1095
+ args: "slug: string",
1096
+ returns: R("apps.uninstall"),
1097
+ },
1098
+ enable: {
1099
+ op: "apps.setEnabled",
1100
+ doc: "Enable an installed app.",
1101
+ args: "slug: string",
1102
+ returns: R("apps.setEnabled"),
1103
+ },
1104
+ disable: {
1105
+ op: "apps.setEnabled",
1106
+ doc: "Disable an installed app.",
1107
+ args: "slug: string",
1108
+ returns: R("apps.setEnabled"),
1109
+ },
1110
+ pin: {
1111
+ op: "apps.setPinned",
1112
+ doc: "Pin an app in the rail.",
1113
+ args: "slug: string",
1114
+ returns: R("apps.setPinned"),
1115
+ },
1116
+ unpin: {
1117
+ op: "apps.setPinned",
1118
+ doc: "Unpin an app.",
1119
+ args: "slug: string",
1120
+ returns: R("apps.setPinned"),
1121
+ },
1122
+ send: {
1123
+ host: true,
1124
+ permission: "apps:message",
1125
+ doc: "Deprecated alias of bus.send.",
1126
+ args: "targetApp: string, message: unknown",
1127
+ returns: "Promise<{ ok: boolean }>",
1128
+ deprecated: "Use dench.bus.send.",
1129
+ },
1130
+ on: {
1131
+ host: true,
1132
+ permission: "apps:message",
1133
+ doc: "Deprecated alias of bus.on.",
1134
+ args: 'eventType: "message", callback: (message: { from: string; message: unknown }) => void',
1135
+ returns: "void",
1136
+ deprecated: "Use dench.bus.on.",
1137
+ },
1138
+ },
1139
+
1140
+ cron: {
1141
+ schedule: {
1142
+ host: true,
1143
+ permission: "cron:schedule",
1144
+ doc: "Create a scheduled agent (automation).",
1145
+ args: "opts: CronScheduleOptions",
1146
+ returns: "Promise<unknown>",
1147
+ },
1148
+ list: {
1149
+ host: true,
1150
+ permission: "cron:schedule",
1151
+ doc: "Automations in the workspace.",
1152
+ args: "",
1153
+ returns: "Promise<unknown[]>",
1154
+ },
1155
+ update: {
1156
+ host: true,
1157
+ permission: "cron:schedule",
1158
+ doc: "Update an automation.",
1159
+ args: "jobId: string, patch: Partial<CronScheduleOptions>",
1160
+ returns: "Promise<unknown>",
1161
+ },
1162
+ run: {
1163
+ host: true,
1164
+ permission: "cron:schedule",
1165
+ doc: "Run an automation now.",
1166
+ args: "jobId: string",
1167
+ returns: "Promise<unknown>",
1168
+ },
1169
+ cancel: {
1170
+ host: true,
1171
+ permission: "cron:schedule",
1172
+ doc: "Delete an automation.",
1173
+ args: "jobId: string",
1174
+ returns: "Promise<unknown>",
1175
+ },
1176
+ },
1177
+
1178
+ webhooks: {
1179
+ register: {
1180
+ host: true,
1181
+ permission: "webhooks:receive",
1182
+ doc: "Register an inbound webhook for this app. Returns the URL and signing secret ONCE — store the secret with the sender.",
1183
+ args: "hookName: string",
1184
+ returns: R("apps.webhooks.register"),
1185
+ },
1186
+ on: {
1187
+ host: true,
1188
+ permission: "webhooks:receive",
1189
+ doc: "Receive events for a hook while the app is open (polls every 5s).",
1190
+ args: "hookName: string, callback: (event: AppWebhookEvent) => void",
1191
+ returns: "void",
1192
+ },
1193
+ poll: {
1194
+ host: true,
1195
+ permission: "webhooks:receive",
1196
+ doc: "Events received since a timestamp.",
1197
+ args: "hookName: string, opts?: { since?: number; limit?: number }",
1198
+ returns: R("apps.webhooks.poll"),
1199
+ },
1200
+ list: {
1201
+ host: true,
1202
+ permission: "webhooks:receive",
1203
+ doc: "This app's registered hooks (URLs, never secrets).",
1204
+ args: "",
1205
+ returns: R("apps.webhooks.list"),
1206
+ },
1207
+ delete: {
1208
+ host: true,
1209
+ permission: "webhooks:receive",
1210
+ doc: "Remove a hook and its stored events.",
1211
+ args: "hookName: string",
1212
+ returns: R("apps.webhooks.delete"),
1213
+ },
1214
+ },
1215
+
1216
+ clipboard: {
1217
+ read: {
1218
+ host: true,
1219
+ permission: "clipboard:read",
1220
+ doc: "Read clipboard text.",
1221
+ args: "",
1222
+ returns: "Promise<string | null>",
1223
+ },
1224
+ write: {
1225
+ host: true,
1226
+ permission: "clipboard:write",
1227
+ doc: "Write clipboard text.",
1228
+ args: "text: string",
1229
+ returns: "Promise<{ ok: boolean }>",
1230
+ },
1231
+ },
1232
+
1233
+ integrations: {
1234
+ list: {
1235
+ host: true,
1236
+ permission: "integrations:read",
1237
+ doc: "Connected accounts (toolkit, status, connectedAccountId).",
1238
+ args: "",
1239
+ returns: "Promise<IntegrationConnection[]>",
1240
+ },
1241
+ search: {
1242
+ host: true,
1243
+ permission: "integrations:read",
1244
+ doc: "Find tools by natural-language query and/or toolkit.",
1245
+ args: "opts: { query?: string; toolkit?: string; limit?: number }",
1246
+ returns: "Promise<unknown>",
1247
+ },
1248
+ execute: {
1249
+ host: true,
1250
+ permission: "integrations:read",
1251
+ doc: "Run a tool. Write-classified tools additionally need integrations:write.",
1252
+ args: "opts: { tool: string; arguments?: Record<string, unknown>; connectedAccountId?: string }",
1253
+ returns: "Promise<unknown>",
1254
+ },
1255
+ },
1256
+
1257
+ geo: {
1258
+ resolveLocation: {
1259
+ host: true,
1260
+ permission: null,
1261
+ doc: "Free text → country (ISO2 + ISO numeric). Same rules as the analytics map.",
1262
+ args: "text: string",
1263
+ returns: "Promise<{ id: string; iso2: string; name: string } | null>",
1264
+ },
1265
+ resolveRegion: {
1266
+ host: true,
1267
+ permission: null,
1268
+ doc: "Free text → admin-1 region (state/province) within a country. Loads that country's file on first use.",
1269
+ args: "text: string, iso2: string",
1270
+ returns: "Promise<GeoRegionHit | null>",
1271
+ },
1272
+ loadAdmin1: {
1273
+ host: true,
1274
+ permission: null,
1275
+ doc: "First-level divisions of a country as GeoJSON features (what the map draws).",
1276
+ args: "iso2: string",
1277
+ returns: "Promise<GeoRegionFeature[] | null>",
1278
+ },
1279
+ },
1280
+
1281
+ db: {
1282
+ query: {
1283
+ host: true,
1284
+ permission: "crm:read",
1285
+ doc: "Removed. DuckDB SQL is gone — use objects.query / analytics.compute.",
1286
+ args: "sql: string",
1287
+ returns: "Promise<never>",
1288
+ deprecated: "Removed: use objects.query or analytics.compute.",
1289
+ },
1290
+ execute: {
1291
+ host: true,
1292
+ permission: "crm:write",
1293
+ doc: "Removed. Use objects.create / update / delete.",
1294
+ args: "sql: string",
1295
+ returns: "Promise<never>",
1296
+ deprecated: "Removed: use objects.create / update / delete.",
1297
+ },
1298
+ },
1299
+ };
1300
+
1301
+ /**
1302
+ * Registry groups → app permission scope group. Anything not listed maps
1303
+ * to its own group name (`billing` → `billing:read` / `billing:write`).
1304
+ * The `gateway` group is split by operation id prefix (search / web /
1305
+ * image / tool / integrations) so scopes read naturally.
1306
+ */
1307
+ export const GROUP_SCOPE_OVERRIDES: Record<string, string> = {
1308
+ crm: "crm",
1309
+ files: "files",
1310
+ chat: "ai",
1311
+ routines: "cron",
1312
+ meta: "",
1313
+ };
1314
+
1315
+ /** Operations that are reads despite a non-GET method. */
1316
+ export const READ_OPERATION_OVERRIDES = new Set<string>([
1317
+ "crm.query",
1318
+ "crm.sql",
1319
+ "crm.aggregate",
1320
+ "crm.analytics.compute",
1321
+ "crm.people.search",
1322
+ "crm.companies.search",
1323
+ "enrichment.jobs.search",
1324
+ "enrichment.search.preview",
1325
+ "search.web",
1326
+ "search.contents",
1327
+ "search.answer",
1328
+ "web.scrape",
1329
+ "web.brand",
1330
+ "web.sitemap",
1331
+ "web.crawl",
1332
+ "web.screenshot",
1333
+ "web.extract",
1334
+ "web.product",
1335
+ "web.competitors",
1336
+ "web.styleguide",
1337
+ "web.fonts",
1338
+ "web.classify",
1339
+ "web.brandSearch",
1340
+ "tool.search",
1341
+ ]);
1342
+
1343
+ /**
1344
+ * Scope for a registry operation. Pure so the generator, the host and the
1345
+ * CLI validator agree without importing each other.
1346
+ */
1347
+ export function permissionForOperation(operation: {
1348
+ id: string;
1349
+ group: string;
1350
+ method: string;
1351
+ }): string | null {
1352
+ if (operation.group === "meta") return null;
1353
+ if (operation.id.startsWith("apps.webhooks.")) return "webhooks:receive";
1354
+ if (operation.group === "chat") return "ai:chat";
1355
+ if (operation.group === "routines") return "cron:schedule";
1356
+ const isRead =
1357
+ operation.method === "GET" || READ_OPERATION_OVERRIDES.has(operation.id);
1358
+ let scopeGroup: string;
1359
+ if (operation.group === "gateway") {
1360
+ const prefix = operation.id.split(".")[0];
1361
+ scopeGroup = prefix === "tool" ? "integrations" : prefix;
1362
+ } else {
1363
+ scopeGroup = GROUP_SCOPE_OVERRIDES[operation.group] ?? operation.group;
1364
+ }
1365
+ return `${scopeGroup}:${isRead ? "read" : "write"}`;
1366
+ }
1367
+
1368
+ export function listSurfaceMethods(
1369
+ surface: AppSdkSurface = APP_SDK_SURFACE,
1370
+ ): string[] {
1371
+ const out: string[] = [];
1372
+ for (const [ns, methods] of Object.entries(surface)) {
1373
+ for (const name of Object.keys(methods)) out.push(`${ns}.${name}`);
1374
+ }
1375
+ return out;
1376
+ }