@notionhq/apps 0.0.23 → 0.0.25

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.
@@ -72,6 +72,27 @@ export type CustomAgentPropertyUpdatedTrigger = CustomAgentTriggerBase & Propert
72
72
  dataSourceResourceId: ResourceId;
73
73
  };
74
74
  export type CustomAgentTrigger = CustomAgentRecurrenceTrigger | CustomAgentPageAddedTrigger | CustomAgentPropertyUpdatedTrigger;
75
+ /**
76
+ * Defines access levels for resources that a custom agent can use.
77
+ *
78
+ * These values map to Notion module permissions: full access, content editing,
79
+ * commenting, and read-only.
80
+ */
81
+ export type CustomAgentAccessRole = "full_access" | "can_edit_content" | "can_comment" | "can_view";
82
+ /** Grants a custom agent access to a page or database resource. */
83
+ export type CustomAgentAccess = {
84
+ resourceId: ResourceId;
85
+ role: CustomAgentAccessRole;
86
+ };
87
+ /**
88
+ * URL trust settings for a custom agent.
89
+ *
90
+ * URL trust is independent from web access: an agent can trust URLs without
91
+ * being granted web search access.
92
+ */
93
+ export type CustomAgentTrustedUrls = {
94
+ type: "all";
95
+ };
75
96
  export type CustomAgentArgs = {
76
97
  resourceId: ResourceId;
77
98
  name: string;
@@ -80,14 +101,34 @@ export type CustomAgentArgs = {
80
101
  }>;
81
102
  instructions?: string;
82
103
  model?: "ambrosia-tart-high" | "opal-quince-medium" | "almond-croissant-low";
83
- sharedResources?: readonly ResourceId[];
104
+ /**
105
+ * Whether the agent can use web search. Defaults to `false` when omitted for
106
+ * a new agent. When updating an existing agent, omitting this field preserves
107
+ * its current web access and domain restrictions.
108
+ */
109
+ webAccess?: boolean;
110
+ /**
111
+ * URL trust policy for this agent. `{ type: "all" }` allows every HTTP and
112
+ * HTTPS URL. For a new agent, omitting this field leaves URL trust disabled;
113
+ * for an existing agent, omission preserves the current URL trust policy.
114
+ */
115
+ trustedUrls?: CustomAgentTrustedUrls;
116
+ /**
117
+ * Grants the agent access to pages and databases.
118
+ *
119
+ * For an existing custom agent, omit this field or provide an empty list to
120
+ * preserve current page and database grants. Each listed resource adds a
121
+ * grant or replaces its existing grant with the listed role. Grants for
122
+ * unlisted resources remain unchanged.
123
+ */
124
+ access?: readonly CustomAgentAccess[];
84
125
  triggers?: readonly CustomAgentTrigger[];
85
126
  };
86
127
  export type CustomAgentHandle = {
87
128
  readonly resourceType: "customAgent";
88
129
  readonly resourceId: string;
89
130
  };
90
- /** Declare a custom agent and validate every shared resource reference. */
131
+ /** Declare a custom agent and validate every resource reference. */
91
132
  export declare function customAgent(args: CustomAgentArgs): CustomAgentHandle;
92
133
  export {};
93
134
  //# sourceMappingURL=custom-agent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"custom-agent.d.ts","sourceRoot":"","sources":["../../src/notion-as-code/custom-agent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAqB,gBAAgB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAIpF,KAAK,iBAAiB,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAExE,gEAAgE;AAChE,MAAM,MAAM,kBAAkB,GAAG;KAC/B,GAAG,IAAI,iBAAiB,CAAC,CAAC,EAAE,IAAI;CACjC,GAAG;KACF,GAAG,IAAI,iBAAiB,GAAG,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;CAChF,CAAC,iBAAiB,CAAC,CAAC;AAErB,MAAM,MAAM,wBAAwB,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,CAAC;AAE9E,MAAM,MAAM,4BAA4B,GACrC;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GACrC;IACA,IAAI,EAAE,kBAAkB,CAAC;IACzB,OAAO,EAAE,iBAAiB,CAAC;IAC3B,UAAU,EAAE,wBA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MAAM,CAAC;CAC5B,CAAC;AAEF,oEAAoE;AACpE,wBAAgB,WAAW,CAAC,IAAI,EAAE,eAAe,GAAG,iBAAiB,CAoBpE"}
@@ -2,8 +2,8 @@ import { recordIntent } from "./recorder.js";
2
2
  import { assertUserResourceId } from "./resource.js";
3
3
  function customAgent(args) {
4
4
  assertUserResourceId(args.resourceId);
5
- for (const resourceId of args.sharedResources ?? []) {
6
- assertUserResourceId(resourceId);
5
+ for (const grant of args.access ?? []) {
6
+ assertUserResourceId(grant.resourceId);
7
7
  }
8
8
  for (const trigger of args.triggers ?? []) {
9
9
  assertUserResourceId(trigger.resourceId);
@@ -1,6 +1,6 @@
1
1
  export { APPS_RESERVED_RESOURCE_ID_PREFIX, APPS_WORKSPACE_RESOURCE_ID } from "./intents.js";
2
2
  export type { ContentPageLayoutTab, DatabasePageLayout, DatabasePageLayoutTab, DatabaseIntent, DataSourceDefinition, NotionAsCodeIcon, NotionAsCodeProperty, NotionAsCodePropertyConfig, NotionAsCodeSchema, NotionAsCodeSelectOption, NotionAsCodeStatusOption, PageCoverReference, PageLayoutMainModule, PageLayoutNumberAndFormulaStyle, PageLayoutPersonStyle, PageLayoutPropertiesModule, PageLayoutPropertyConfig, PageLayoutPropertyModule, PageLayoutPropertySection, PageLayoutRelationConfig, PageLayoutRelationsGroupModule, PageLayoutSidebarModule, Parent, ResourceId, RollupBaseAggregationType, RollupDateAggregationType, RollupNumberAggregationType, RollupTargetPropertyType, ViewPageLayoutTab, } from "./intents.js";
3
- export type { CustomAgentArgs, CustomAgentHandle, CustomAgentPageAddedTrigger, CustomAgentPropertyUpdatedTrigger, CustomAgentRecurrenceSchedule, CustomAgentRecurrenceTrigger, CustomAgentTrigger, CustomAgentTriggerBase, DailyRecurrenceSchedule, HourlyRecurrenceSchedule, MonthlyRecurrenceRestriction, MonthlyRecurrenceSchedule, MonthlyWeekdayOccurrence, PropertyTriggerCondition, RecurrenceScheduleEnd, RecurrenceWeekdays, WeeklyRecurrenceSchedule, YearlyRecurrenceSchedule, } from "./custom-agent.js";
3
+ export type { CustomAgentAccess, CustomAgentAccessRole, CustomAgentArgs, CustomAgentHandle, CustomAgentPageAddedTrigger, CustomAgentPropertyUpdatedTrigger, CustomAgentRecurrenceSchedule, CustomAgentRecurrenceTrigger, CustomAgentTrustedUrls, CustomAgentTrigger, CustomAgentTriggerBase, DailyRecurrenceSchedule, HourlyRecurrenceSchedule, MonthlyRecurrenceRestriction, MonthlyRecurrenceSchedule, MonthlyWeekdayOccurrence, PropertyTriggerCondition, RecurrenceScheduleEnd, RecurrenceWeekdays, WeeklyRecurrenceSchedule, YearlyRecurrenceSchedule, } from "./custom-agent.js";
4
4
  export type { ChildDatabaseArgs, ChildDatabaseFactory, ChildMultiSourceDatabaseArgs, ChildSingleSourceDatabaseArgs, DataSourceArgs, DataSourceHandle, DataSourceMap, DatabaseArgs, DatabaseHandle, MultiSourceDatabaseArgs, SingleSourceDatabaseArgs, SingleSourceDatabaseHandle, } from "./database.js";
5
5
  export { toCustomBlockDefaultBinding, toCustomBlockDataSource } from "../translate.js";
6
6
  export type { ChildPageArgs, PageArgs, PageHandle, PropertyValue, SimpleTextToken, TextValue, VerificationInput, VerificationPropertyValue, } from "./page.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/notion-as-code/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gCAAgC,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAC5F,YAAY,EACX,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,EACrB,cAAc,EACd,oBAAoB,EACpB,gBAAgB,EAChB,oBAAoB,EACpB,0BAA0B,EAC1B,kBAAkB,EAClB,wBAAwB,EACxB,wBAAwB,EACxB,kBAAkB,EAClB,oBAAoB,EACpB,+BAA+B,EAC/B,qBAAqB,EACrB,0BAA0B,EAC1B,wBAAwB,EACxB,wBAAwB,EACxB,yBAAyB,EACzB,wBAAwB,EACxB,8BAA8B,EAC9B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BAAoB,EACpB,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,cAAc,EACd,qBAAqB,EACrB,yBAAyB,EACzB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,cAAc,EACd,sBAAsB,EACtB,kBAAkB,EAClB,qBAAqB,EACrB,sBAAsB,EACtB,kBAAkB,EAClB,+BAA+B,EAC/B,qBAAqB,EACrB,sCAAsC,EACtC,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,UAAU,EACV,QAAQ,GACR,MAAM,YAAY,CAAC;AAEpB,wEAAwE;AACxE,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;CAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/notion-as-code/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gCAAgC,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAC5F,YAAY,EACX,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,EACrB,cAAc,EACd,oBAAoB,EACpB,gBAAgB,EAChB,oBAAoB,EACpB,0BAA0B,EAC1B,kBAAkB,EAClB,wBAAwB,EACxB,wBAAwB,EACxB,kBAAkB,EAClB,oBAAoB,EACpB,+BAA+B,EAC/B,qBAAqB,EACrB,0BAA0B,EAC1B,wBAAwB,EACxB,wBAAwB,EACxB,yBAAyB,EACzB,wBAAwB,EACxB,8BAA8B,EAC9B,uBAAuB,EACvB,MAAM,EACN,UAAU,EACV,yBAAyB,EACzB,yBAAyB,EACzB,2BAA2B,EAC3B,wBAAwB,EACxB,iBAAiB,GACjB,MAAM,cAAc,CAAC;AACtB,YAAY,EACX,iBAAiB,EACjB,qBAAqB,EACrB,eAAe,EACf,iBAAiB,EACjB,2BAA2B,EAC3B,iCAAiC,EACjC,6BAA6B,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EACtB,kBAAkB,EAClB,qBAAqB,EACrB,sBAAsB,EACtB,kBAAkB,EAClB,+BAA+B,EAC/B,qBAAqB,EACrB,sCAAsC,EACtC,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,UAAU,EACV,QAAQ,GACR,MAAM,YAAY,CAAC;AAEpB,wEAAwE;AACxE,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;CAAiB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@notionhq/apps",
3
- "version": "0.0.23",
3
+ "version": "0.0.25",
4
4
  "description": "An SDK for building workflow apps for Notion",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -86,9 +86,9 @@ root exports support:
86
86
  `database(resourceId, { datasources: { Key: { resourceId, schema } }, views?, parent? })`,
87
87
  returning sources as `handle.datasources.Key`. A source's `addPage` declares a row;
88
88
  the database handle also exposes `addView`.
89
- - `customAgent({ resourceId, name, instructions?, sharedResources? })`.
90
- Shared resources are declared resource IDs; inspect the installed types
91
- before specifying models or triggers.
89
+ - `customAgent({ resourceId, name, ... })`; only `resourceId` and `name` are
90
+ required. Choose optional fields individually as described below, and inspect
91
+ the installed types before using them.
92
92
  - `view({ databaseResourceId, resourceId, type, dataSourceResourceId, ... })`,
93
93
  returning a handle with `resourceId`. This is also available as `notion.view`.
94
94
  Use property resource IDs in view filters, sorts, and layout options; calendar
@@ -127,11 +127,72 @@ use `{ type: "resourceId", resourceId: parent.resourceId }`; child helpers set
127
127
  this reference for you. Pages and databases without a parent default to private
128
128
  top-level resources in the Apps workspace.
129
129
 
130
- Page and database covers accept `{ type: "url", url, position? }`. Custom-agent
131
- triggers are discriminated unions for recurrence, page-added, and
132
- property-updated triggers. Weekly recurrences require at least one weekday, and
133
- property-updated triggers require property conditions or
134
- `triggerWhenPageContentEdited: true`.
130
+ Page and database covers accept `{ type: "url", url, position? }`.
131
+
132
+ ## Configure a custom agent
133
+
134
+ Start with the smallest declaration that describes the requested agent:
135
+
136
+ ```ts
137
+ import { customAgent } from "@notionhq/apps";
138
+
139
+ const analyst = customAgent({
140
+ resourceId: "project-analyst",
141
+ name: "Project analyst",
142
+ instructions: "Summarize project status and identify blocked work.",
143
+ });
144
+ ```
145
+
146
+ Do not add every optional field by default. Decide on each field separately:
147
+
148
+ - `instructions`: set when the App should define the agent's purpose or
149
+ behavior. Omit rather than inventing placeholder instructions.
150
+ - `icon`: set only when the agent needs a specified visual identity. Custom
151
+ agents accept an emoji or Notion icon, but not a file-backed icon.
152
+ - `model`: set only when the user or product requirement calls for one of the
153
+ exact model values in the installed declarations. Otherwise omit it and let
154
+ Notion choose the model.
155
+ - `access`: set only for declared pages or databases the agent must use. Grant
156
+ the least-capable suitable role: `can_view` for reading, `can_comment` for
157
+ comments, `can_edit_content` for editing content, or `full_access` only when
158
+ broader access is required. Use the target handle's `resourceId`; this is
159
+ separate from a workflow's `access.call(agent)` binding.
160
+ - `webAccess`: set `true` only when the agent must search the web. Set `false`
161
+ when the declaration must explicitly disable web search. For a new agent,
162
+ omission defaults to `false`; for an existing agent, omission preserves its
163
+ current web access and domain restrictions.
164
+ - `trustedUrls`: set `{ type: "all" }` only when the agent must trust every HTTP
165
+ and HTTPS URL. URL trust is independent of web search, so do not add it merely
166
+ because `webAccess` is enabled. Omission disables URL trust for a new agent
167
+ and preserves the current policy for an existing agent. The current type has
168
+ no value that clears an existing trust policy.
169
+ - `triggers`: set only when the agent should run automatically. Use
170
+ `recurrence` for a schedule, `page_added` for new rows in a data source, and
171
+ `property_updated` for selected property edits and/or page-content edits.
172
+ Do not add a trigger merely because its data source also appears in `access`.
173
+
174
+ For an existing agent, `access` is additive: each entry adds a grant or updates
175
+ that resource's role, while unlisted grants remain unchanged. Omitting `access`
176
+ and passing `access: []` both preserve existing grants. Reuse declared resource
177
+ IDs and choose roles deliberately:
178
+
179
+ ```ts
180
+ customAgent({
181
+ resourceId: "project-analyst",
182
+ name: "Project analyst",
183
+ instructions: "Summarize project status and identify blocked work.",
184
+ access: [{ resourceId: projects.resourceId, role: "can_view" }],
185
+ webAccess: true,
186
+ });
187
+ ```
188
+
189
+ For a recurrence trigger, always set `interval`, `start`, and `timeZone`; add
190
+ `end` only for a finite schedule. Weekly triggers also require a nonempty
191
+ `weekdays` object, and monthly triggers require `monthlyRestriction`. Page-added
192
+ and property-updated triggers reference a declared data source by
193
+ `dataSourceResourceId`. Property-updated triggers require property conditions
194
+ or `triggerWhenPageContentEdited: true`. Give every trigger its own stable
195
+ `resourceId`.
135
196
 
136
197
  Database page layouts are typed against their keyed data-source schema. Reference
137
198
  property resource IDs, not schema keys. The SDK restricts relation groups to
@@ -4,12 +4,15 @@ import { notion } from "./index.js";
4
4
  import { finishMetadataRecording, startMetadataRecording } from "./recorder.js";
5
5
 
6
6
  describe("Notion-as-Code custom agent declarations", () => {
7
- it("records typed recurrence and database triggers", () => {
7
+ it("records access, web, URL trust, and triggers", () => {
8
8
  const recorder = startMetadataRecording();
9
9
 
10
10
  notion.customAgent({
11
11
  resourceId: "triage-agent",
12
12
  name: "Triage agent",
13
+ webAccess: true,
14
+ trustedUrls: { type: "all" },
15
+ access: [{ resourceId: "tasks", role: "can_edit_content" }],
13
16
  triggers: [
14
17
  {
15
18
  type: "recurrence",
@@ -37,6 +40,9 @@ describe("Notion-as-Code custom agent declarations", () => {
37
40
  type: "custom_agent",
38
41
  resourceId: "triage-agent",
39
42
  name: "Triage agent",
43
+ webAccess: true,
44
+ trustedUrls: { type: "all" },
45
+ access: [{ resourceId: "tasks", role: "can_edit_content" }],
40
46
  triggers: [
41
47
  {
42
48
  type: "recurrence",
@@ -76,4 +82,14 @@ describe("Notion-as-Code custom agent declarations", () => {
76
82
  }),
77
83
  ).toThrow("reserved");
78
84
  });
85
+
86
+ it("rejects reserved resource IDs inside access grants", () => {
87
+ expect(() =>
88
+ notion.customAgent({
89
+ resourceId: "triage-agent",
90
+ name: "Triage agent",
91
+ access: [{ resourceId: "__notion_apps_tasks", role: "can_view" }],
92
+ }),
93
+ ).toThrow("reserved");
94
+ });
79
95
  });
@@ -101,13 +101,57 @@ export type CustomAgentTrigger =
101
101
  | CustomAgentPageAddedTrigger
102
102
  | CustomAgentPropertyUpdatedTrigger;
103
103
 
104
+ /**
105
+ * Defines access levels for resources that a custom agent can use.
106
+ *
107
+ * These values map to Notion module permissions: full access, content editing,
108
+ * commenting, and read-only.
109
+ */
110
+ export type CustomAgentAccessRole = "full_access" | "can_edit_content" | "can_comment" | "can_view";
111
+
112
+ /** Grants a custom agent access to a page or database resource. */
113
+ export type CustomAgentAccess = {
114
+ resourceId: ResourceId;
115
+ role: CustomAgentAccessRole;
116
+ };
117
+
118
+ /**
119
+ * URL trust settings for a custom agent.
120
+ *
121
+ * URL trust is independent from web access: an agent can trust URLs without
122
+ * being granted web search access.
123
+ */
124
+ export type CustomAgentTrustedUrls = {
125
+ type: "all";
126
+ };
127
+
104
128
  export type CustomAgentArgs = {
105
129
  resourceId: ResourceId;
106
130
  name: string;
107
131
  icon?: Exclude<NotionAsCodeIcon, { type: "file" }>;
108
132
  instructions?: string;
109
133
  model?: "ambrosia-tart-high" | "opal-quince-medium" | "almond-croissant-low";
110
- sharedResources?: readonly ResourceId[];
134
+ /**
135
+ * Whether the agent can use web search. Defaults to `false` when omitted for
136
+ * a new agent. When updating an existing agent, omitting this field preserves
137
+ * its current web access and domain restrictions.
138
+ */
139
+ webAccess?: boolean;
140
+ /**
141
+ * URL trust policy for this agent. `{ type: "all" }` allows every HTTP and
142
+ * HTTPS URL. For a new agent, omitting this field leaves URL trust disabled;
143
+ * for an existing agent, omission preserves the current URL trust policy.
144
+ */
145
+ trustedUrls?: CustomAgentTrustedUrls;
146
+ /**
147
+ * Grants the agent access to pages and databases.
148
+ *
149
+ * For an existing custom agent, omit this field or provide an empty list to
150
+ * preserve current page and database grants. Each listed resource adds a
151
+ * grant or replaces its existing grant with the listed role. Grants for
152
+ * unlisted resources remain unchanged.
153
+ */
154
+ access?: readonly CustomAgentAccess[];
111
155
  triggers?: readonly CustomAgentTrigger[];
112
156
  };
113
157
 
@@ -116,11 +160,11 @@ export type CustomAgentHandle = {
116
160
  readonly resourceId: string;
117
161
  };
118
162
 
119
- /** Declare a custom agent and validate every shared resource reference. */
163
+ /** Declare a custom agent and validate every resource reference. */
120
164
  export function customAgent(args: CustomAgentArgs): CustomAgentHandle {
121
165
  assertUserResourceId(args.resourceId);
122
- for (const resourceId of args.sharedResources ?? []) {
123
- assertUserResourceId(resourceId);
166
+ for (const grant of args.access ?? []) {
167
+ assertUserResourceId(grant.resourceId);
124
168
  }
125
169
  for (const trigger of args.triggers ?? []) {
126
170
  assertUserResourceId(trigger.resourceId);
@@ -33,12 +33,15 @@ export type {
33
33
  ViewPageLayoutTab,
34
34
  } from "./intents.js";
35
35
  export type {
36
+ CustomAgentAccess,
37
+ CustomAgentAccessRole,
36
38
  CustomAgentArgs,
37
39
  CustomAgentHandle,
38
40
  CustomAgentPageAddedTrigger,
39
41
  CustomAgentPropertyUpdatedTrigger,
40
42
  CustomAgentRecurrenceSchedule,
41
43
  CustomAgentRecurrenceTrigger,
44
+ CustomAgentTrustedUrls,
42
45
  CustomAgentTrigger,
43
46
  CustomAgentTriggerBase,
44
47
  DailyRecurrenceSchedule,
@@ -1,8 +1,11 @@
1
1
  import { expectTypeOf, it } from "vitest";
2
2
 
3
3
  import type {
4
+ CustomAgentAccess,
5
+ CustomAgentAccessRole,
4
6
  CustomAgentArgs,
5
7
  CustomAgentPropertyUpdatedTrigger,
8
+ CustomAgentTrustedUrls,
6
9
  CustomAgentTrigger,
7
10
  DatabasePageLayout,
8
11
  NotionAsCodePropertyConfig,
@@ -12,6 +15,28 @@ import type {
12
15
  SingleSourceDatabaseArgs,
13
16
  } from "./index.js";
14
17
 
18
+ it("types custom agent resource access and URL trust", () => {
19
+ expectTypeOf<
20
+ "full_access" | "can_edit_content" | "can_comment" | "can_view"
21
+ >().toEqualTypeOf<CustomAgentAccessRole>();
22
+ expectTypeOf<{
23
+ resourceId: "tasks";
24
+ role: "can_view";
25
+ }>().toExtend<CustomAgentAccess>();
26
+ expectTypeOf<{
27
+ resourceId: "tasks";
28
+ role: "read_and_write";
29
+ }>().not.toExtend<CustomAgentAccess>();
30
+ expectTypeOf<{ type: "all" }>().toEqualTypeOf<CustomAgentTrustedUrls>();
31
+ expectTypeOf<CustomAgentArgs["webAccess"]>().toEqualTypeOf<boolean | undefined>();
32
+ expectTypeOf<CustomAgentArgs["trustedUrls"]>().toEqualTypeOf<
33
+ CustomAgentTrustedUrls | undefined
34
+ >();
35
+ expectTypeOf<CustomAgentArgs["access"]>().toEqualTypeOf<
36
+ readonly CustomAgentAccess[] | undefined
37
+ >();
38
+ });
39
+
15
40
  it("types page and database covers as URL references", () => {
16
41
  expectTypeOf<{
17
42
  type: "url";