@project-ajax/create 0.0.15 → 0.0.17

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.
@@ -1,6 +1,8 @@
1
- # README
1
+ # Notion Workers
2
2
 
3
- Use this repo to write extensions to enhance Notion. With Notion extensions, you can write JavaScript that syncs data into Notion collections, adds new slash-commands, or provides new actions to Custom Agents.
3
+ Use this repo to write workers to enhance Notion. With Notion Workers, you can
4
+ write JavaScript that syncs data into Notion collections, provides tools to
5
+ Custom Agents, or runs automation tasks.
4
6
 
5
7
  ## Prerequisites
6
8
 
@@ -8,80 +10,56 @@ Use this repo to write extensions to enhance Notion. With Notion extensions, you
8
10
 
9
11
  You need Node >= 22, npm >= 10 installed. (The repo will warn you if you don't.)
10
12
 
11
- ### Access to the feature
12
-
13
- This feature is behind a feature flag (i.e. Statsig gate) in Notion.
14
-
15
- See a `#proj-ajax` team member to gain access.
16
-
17
13
  ## Quickstart
18
14
 
19
15
  In this Quickstart, you’ll:
20
16
 
21
- - Clone this extensions template
22
- - Publish example extensions to your Notion workspace
17
+ - Create a new project using this template
18
+ - Publish the example worker to your Notion workspace
23
19
 
24
20
  ### 1. Create worker project from template
25
21
 
26
22
  Use `npm init` to setup a project template:
27
23
 
28
- ```
24
+ ```shell
29
25
  npm init @project-ajax
30
26
  ```
31
27
 
32
- When prompted, enter a path to the new project, e.g. `my-extensions`.
28
+ When prompted, enter a path to the new project, e.g. `my-worker`.
33
29
 
34
30
  ### 2. Install packages and connect the repo to Notion
35
31
 
36
32
  Install packages:
37
33
 
38
- ```
34
+ ```shell
39
35
  # or whatever you chose for the pathname
40
- cd my-extensions && npm i
36
+ cd my-worker && npm i
41
37
  ```
42
38
 
43
- Now, run `npx workers` to verify the tool has installed:
44
-
45
- ```
46
- npx workers
39
+ Now, connect the repo to Notion to publish the example worker to your Notion
40
+ workspace:
47
41
 
48
- USAGE
49
- workers auth login|show|logout ...
50
- workers deploy [--config value] [--debug]
51
- workers secrets set|list|rm ...
52
- workers --help
53
- workers --version
54
-
55
- A CLI for the Project Ajax platform
56
-
57
- [ ... ]
58
- ```
59
-
60
- Then, connect the repo to Notion to publish the example extensions to your Notion workspace:
61
-
62
- ```
42
+ ```shell
63
43
  # Connect to Notion Prod
64
44
  npx workers auth login
65
45
  # Connect to Notion Dev
66
46
  npx workers auth login --env=dev
67
47
  ```
68
48
 
69
- This command will open a new page with a command that includes a token. Run that command locally. It will look like this:
49
+ This command will open a new page with a command that includes a token. Run that
50
+ command locally. It will look like this:
70
51
 
71
- ```
52
+ ```shell
72
53
  # example
73
54
  npx workers auth login v1.user.wAFygwEZ-[...] --env=dev
74
55
  ```
75
56
 
76
- > **Note**
77
- >
78
- > If the command opens a page that 404s, you likely do not have Statsig access to extensions. See a #proj-virtual-databases team member for access.
79
-
80
57
  ### 3. Deploy
81
58
 
82
- Run the following command to deploy this repo's example extensions to your Notion workspace:
59
+ Run the following command to deploy this repo's example workers to your Notion
60
+ workspace:
83
61
 
84
- ```
62
+ ```shell
85
63
  npx workers deploy
86
64
 
87
65
  Deploying worker...
@@ -98,15 +76,15 @@ The sample worker installs three capabilities:
98
76
 
99
77
  - [Synced database](#try-the-synced-database)
100
78
  - [Agent tool](#try-the-agent-tool)
101
- - [Slash command](#try-the-slash-command)
102
79
 
103
80
  #### Try the synced database
104
81
 
105
- After deploying, the sync runs automatically and creates a database in your private pages - you can find it in your sidebar or by searching "Sample Tasks".
82
+ After deploying, the sync runs automatically and creates a database in your
83
+ private pages - you can find it in your sidebar or by searching "Sample Tasks".
106
84
 
107
85
  Alternatively, run the sync via the CLI to get the URL:
108
86
 
109
- ```
87
+ ```shell
110
88
  npx workers exec tasksSync
111
89
  ```
112
90
 
@@ -114,275 +92,63 @@ When the command completes you will see the URL for the `Sample Tasks` database.
114
92
 
115
93
  #### Try the agent tool
116
94
 
117
- To exercise the sample agent tool, first navigate to a new or existing custom agent in Notion.
95
+ To exercise the sample agent tool, first navigate to a new or existing custom
96
+ agent in Notion.
118
97
 
119
98
  On the settings tab, choose Add connection:
120
99
 
121
100
  <img src="./docs/custom-agent-add-connection.png" style="width:400px">
122
101
 
123
- Scroll down to find the installed worker which has the name used when you deployed the worker. Click Add.
102
+ Scroll down to find the installed worker which has the name used when you
103
+ deployed the worker. Click Add.
124
104
 
125
105
  <img src="./docs/custom-agent-select-worker.png" style="width:400px">
126
106
 
127
- Save settings, then navigate to the **chat** tab. Our sample tool call allows for searching tasks by id or keyword - try asking Agent to find tasks related to "Ajax" or "worker".
128
-
129
- #### Try the slash command
130
-
131
- In your Notion workspace, **first refresh**. Then, type forward-slash (`/insert`) and select the "Insert Sample Task" capability:
132
-
133
- <img src="./docs/insert-sample-task.png" style="width:300px" />
134
-
135
- In the search field that appears, type `ajax` to preview matching sample tasks:
136
-
137
- <img src="./docs/select-ajax.png" style="width:400px" />
138
-
139
- After execution, the function will insert blocks into the page:
140
-
141
- <img src="./docs/inserted-blocks.png" style="width:400px" />
107
+ Save settings, then navigate to the **chat** tab. Our sample tool call allows
108
+ for searching tasks by id or keyword - try asking Agent to find tasks related to
109
+ "Ajax" or "worker".
142
110
 
143
111
  ## How-to build your own
144
112
 
145
- ### 1. Create repo from template
113
+ Begin by using `npm init @project-ajax`, and then customize `index.ts` with
114
+ capabilities you'd like to include in your worker.
146
115
 
147
- If you haven't already, use the GitHub CLI to create a new repo from this template:
116
+ ### Writing a sync function
148
117
 
149
- ```
150
- gh repo create notion-extensions -p makenotion/project-ajax-template --private
151
- git clone git@github.com:[YOUR-USER]/notion-extensions my-extensions
152
- ```
153
-
154
- Alternatively, you can click "Create from template" on the repo's page [on GitHub](https://github.com/makenotion/project-ajax-template).
155
-
156
- ### 2. Install packages and connect the repo to Notion
157
-
158
- Install packages:
159
-
160
- ```
161
- cd my-extensions && npm i
162
- ```
163
-
164
- Then, connect the repo to Notion to publish the example extensions to your Notion workspace:
165
-
166
- ```
167
- # Connect to Notion Prod
168
- npx workers auth login
169
- # Connect to Notion Dev
170
- npx workers auth login --env=dev
171
- ```
172
-
173
- This command will open a new page with a command that includes a token. Run that command locally.
118
+ [Sync functions](#sync) populate Notion collections with data from external
119
+ sources.
174
120
 
175
- ### 3. Write your extension(s)
121
+ See the [sync example](./.examples/sync-example.ts) for a complete example.
176
122
 
177
- You can write three types of extensions: **slash commands**, **syncs**, and **tools**.
123
+ ### Writing a tool for custom agents
178
124
 
179
- #### Writing a slash command function
125
+ [Tools](#tools) provide custom actions that can be invoked by custom agents in
126
+ your Notion workspace.
180
127
 
181
- [Slash commands](#slash-commands) add custom `/` commands to your Notion workspace.
128
+ See the [tool example](./.examples/tool-example.ts) for a complete example.
182
129
 
183
- Basic structure:
184
-
185
- ```typescript
186
- import { slashCommand } from "@project-ajax/sdk/slashCommand";
187
-
188
- export const myCommand = slashCommand({
189
- // Title in slash command menu
190
- menuTitle: "My Command",
191
- // Description in slash command menu
192
- menuDescription: "Description shown in menu",
193
- search: {
194
- // Placeholder shown in search bar
195
- placeholder: "Search...",
196
- // Debounce when user types into the search bar, in milliseconds
197
- debounce: 300,
198
- },
199
- // Called when the user enters a search query. Return results to show to user in search menu.
200
- executeSearch: async (query: string) => {
201
- // Return search results
202
- return { items: [{ id: "1", title: "Result", description: "..." }] };
203
- },
204
- // Called when the user has selected a search item from the search menu.
205
- executeSelect: async (id: string) => {
206
- // Return Notion blocks to insert
207
- return [
208
- /* array of blocks */
209
- ];
210
- },
211
- });
212
- ```
130
+ ## Secrets
213
131
 
214
- #### Writing a sync function
215
-
216
- [Sync functions](#sync) populate Notion collections with data from external sources.
217
-
218
- Basic structure:
219
-
220
- ```typescript
221
- import { sync } from "@project-ajax/sdk/sync";
222
- import * as Schema from "@project-ajax/sdk/schema";
223
- import * as Builder from "@project-ajax/sdk/builder";
224
-
225
- export const mySync = sync({
226
- // Which field to use in each object as the primary key. Must be unique.
227
- primaryKeyProperty: "ID",
228
- // The schema of the collection to create in Notion.
229
- schema: {
230
- // Name of the collection to create in Notion.
231
- dataSourceTitle: "My Data",
232
- properties: {
233
- // See `Schema` for the full list of possible column types.
234
- Title: Schema.title(),
235
- ID: Schema.richText(),
236
- },
237
- },
238
- execute: async () => {
239
- // Fetch and return data
240
- return [
241
- // Each object must match the shape of `properties` above.
242
- {
243
- key: "1",
244
- properties: {
245
- Title: Builder.title("Item 1"),
246
- ID: Builder.richText("1"),
247
- },
248
- },
249
- ];
250
- },
251
- });
252
- ```
253
-
254
- #### Writing a tool for custom agents
255
-
256
- [Tools](#tools) provide custom actions that can be invoked by custom agents in your Notion workspace.
257
-
258
- Basic structure:
259
-
260
- ```typescript
261
- import { tool } from "@project-ajax/sdk";
262
-
263
- export const myTool = tool({
264
- // Description of what this tool does - shown to the AI agent
265
- description: "Search for items by keyword or ID",
266
- // JSON Schema for the input the tool accepts
267
- schema: {
268
- type: "object",
269
- properties: {
270
- query: {
271
- type: "string",
272
- nullable: true,
273
- description: "The search query"
274
- },
275
- limit: {
276
- type: "number",
277
- nullable: true,
278
- description: "Maximum number of results"
279
- },
280
- },
281
- required: [],
282
- additionalProperties: false,
283
- },
284
- // Optional: JSON Schema for the output the tool returns
285
- outputSchema: {
286
- type: "object",
287
- properties: {
288
- results: {
289
- type: "array",
290
- items: { type: "string" },
291
- },
292
- },
293
- required: ["results"],
294
- additionalProperties: false,
295
- },
296
- // The function that executes when the tool is called
297
- execute: async (input: { query?: string | null; limit?: number | null }) => {
298
- // Destructure input with default values
299
- const { query, limit = 10 } = input;
300
-
301
- // Perform your logic here
302
- const results = await searchItems(query, limit);
303
-
304
- // Return data matching your outputSchema (if provided)
305
- return { results };
306
- },
307
- });
308
- ```
309
-
310
- ### 4. Deploy your function
311
-
312
- Deploy your functions to your Notion workspace with [**deploy**](#npx-workers-deploy):
313
-
314
- ```bash
315
- npx workers deploy
316
- ```
317
-
318
- This will build your worker bundle, upload it to Notion, and make your functions available in your workspace.
319
-
320
- ### 5. Add secrets
321
-
322
- Your function might require sensitive values, like API tokens, to run. You can add [**secrets**](#npx-workers-secrets) to your function's run context. Secrets are exposed to your function as environment variables.
132
+ Your function might require sensitive values, like API tokens, to run. You can
133
+ add [**secrets**](#npx-workers-secrets) to your function's run context. Secrets
134
+ are exposed to your function as environment variables.
323
135
 
324
136
  Run the following to add secrets:
325
137
 
326
- ```
138
+ ```shell
327
139
  npx workers secrets set MY_SECRET_1=my-secret-value MY_SECRET_2=my-secret-value2
328
140
  ```
329
141
 
330
- Then, you can reference these secret values in your function code using `process.env`, e.g. `process.env.MY_SECRET_1`.
331
-
332
- ### 6. Run your function
333
-
334
- For slash commands, you can test your function in the Notion workspace you deployed to.
335
-
336
- For sync commands, your function is run automatically in the background. You can also run it via the CLI with [`exec`](#npx-workers-exec):
337
-
338
- ```
339
- npx workers exec nameOfSyncCapability
340
- ```
341
-
342
- When the command has finished executing, you should see a collection in your Notion sidebar that contains the synced data.
343
-
344
- You can also test slash commands using [`exec`](#npx-workers-exec). Specify which function inside the slash command you want to run (i.e. `executeSearch` or `executeSelect`). Pass in arguments using `arg=value` syntax:
345
-
346
- ```
347
- npx workers exec mySlashCommand executeSearch query="myquery"
348
- ```
349
-
350
- ## Extensions reference
351
-
352
- ### Slash commands
353
-
354
- You can write an extension that adds a new **slash command** to a Notion workspace. The slash command currently supported is a "search-then-execute" flow.
355
-
356
- For example, you can write a slash command to insert a Linear ticket:
357
-
358
- 1. First, after selecting your slash command, the user enters a search query for a particular Linear ticket:
359
-
360
- <img src="./docs/select-ajax.png" style="width:400px" />
142
+ Then, you can reference these secret values in your function code using
143
+ `process.env`, e.g. `process.env.MY_SECRET_1`.
361
144
 
362
- 2. After they select a ticket from the list, your extension will insert blocks into the page.
363
-
364
- The search query is powered by `executeSearch` and the select action triggers `executeSelect`.
365
-
366
- #### Properties
367
-
368
- - **`menuTitle`** (string, required): The title that appears in the slash command menu when users type `/`.
369
- - **`menuDescription`** (string, required): A description of what the slash command does, shown in the menu.
370
- - **`search`** (object, required): Configuration for the search interface.
371
- - **`placeholder`** (string, required): Placeholder text shown in the search field.
372
- - **`debounce`** (number, required): Milliseconds to wait before executing search after user stops typing.
373
- - **`executeSearch`** (function, required): Async function that handles search queries.
374
- - **Parameters**: `query` (string) - The user's search input.
375
- - **Returns**: Promise resolving to an object with `items` array, where each item has:
376
- - `id` (string): Unique identifier for the item.
377
- - `title` (string): Title displayed in search results.
378
- - `description` (string, optional): Additional description text.
379
- - **`executeSelect`** (function, required): Async function that handles when a user selects an item.
380
- - **Parameters**: `id` (string) - The id of the selected item.
381
- - **Returns**: Promise resolving to an array of Notion blocks to insert into the page.
145
+ ## Workers capabilities reference
382
146
 
383
147
  ### Sync
384
148
 
385
- The **sync** extension allows you to sync any data to a Notion collection. Every time a sync is run, data is upserted or deleted from the target Notion collection so that the collection matches the source.
149
+ The **sync** capabilityh allows you to sync any data to a Notion collection. Every
150
+ time a sync is run, data is upserted or deleted from the target Notion
151
+ collection so that the collection matches the source.
386
152
 
387
153
  At the moment, syncs do not run automatically. Use **`exec`** to run a sync.
388
154
 
@@ -400,9 +166,12 @@ At the moment, syncs do not run automatically. Use **`exec`** to run a sync.
400
166
 
401
167
  ### Tools
402
168
 
403
- The **tool** extension allows custom agents in your Notion workspace to perform actions. When you connect a worker to a custom agent, the agent can invoke your tools based on their descriptions and schemas.
169
+ The **tool** capability allows custom agents in your Notion workspace to perform
170
+ actions. When you connect a worker to a custom agent, the agent can invoke your
171
+ tools based on their descriptions and schemas.
404
172
 
405
- Tools use JSON Schema to define their input and output structures, and the SDK validates data automatically.
173
+ Tools use JSON Schema to define their input and output structures, and the SDK
174
+ validates data automatically.
406
175
 
407
176
  #### Properties
408
177
 
@@ -462,7 +231,7 @@ Your schemas should use standard JSON Schema format. Common patterns:
462
231
 
463
232
  You can test tools using [`exec`](#npx-workers-exec):
464
233
 
465
- ```bash
234
+ ```shell
466
235
  # Execute a tool without arguments
467
236
  npx workers exec myTool
468
237
 
@@ -472,7 +241,9 @@ npx workers exec myTool
472
241
 
473
242
  ## CLI reference
474
243
 
475
- The `workers` CLI provides commands to authenticate, deploy, execute, and manage your Notion functions. All commands support global flags for configuration and debugging.
244
+ The `workers` CLI provides commands to authenticate, deploy, execute, and manage
245
+ your Notion functions. All commands support global flags for configuration and
246
+ debugging.
476
247
 
477
248
  ### Global flags
478
249
 
@@ -499,7 +270,7 @@ Login to the Project Ajax platform using a Workers API token.
499
270
 
500
271
  **Examples:**
501
272
 
502
- ```bash
273
+ ```shell
503
274
  # Open browser to create a token
504
275
  npx workers auth login
505
276
 
@@ -516,7 +287,7 @@ Display the currently configured authentication token.
516
287
 
517
288
  **Example:**
518
289
 
519
- ```bash
290
+ ```shell
520
291
  npx workers auth show
521
292
  ```
522
293
 
@@ -526,17 +297,18 @@ Remove the currently configured authentication token.
526
297
 
527
298
  **Example:**
528
299
 
529
- ```bash
300
+ ```shell
530
301
  npx workers auth logout
531
302
  ```
532
303
 
533
304
  ### `npx workers deploy`
534
305
 
535
- Deploy your worker to the Project Ajax platform. This command builds your worker bundle, uploads it to Notion, and saves the worker configuration.
306
+ Deploy your worker to the Project Ajax platform. This command builds your worker
307
+ bundle, uploads it to Notion, and saves the worker configuration.
536
308
 
537
309
  **Example:**
538
310
 
539
- ```bash
311
+ ```shell
540
312
  npx workers deploy
541
313
  ```
542
314
 
@@ -553,14 +325,13 @@ Execute a worker capability with optional function and arguments.
553
325
 
554
326
  **Usage:**
555
327
 
556
- ```bash
328
+ ```shell
557
329
  npx workers exec <capabilityName> [functionName] [arg1=value1 arg2=value2...]
558
330
  ```
559
331
 
560
332
  **Arguments:**
561
333
 
562
334
  - `capabilityName` (required): Name of the capability to execute
563
- - `functionName` (optional): For slash commands, specify which function to run (`executeSearch` or `executeSelect`)
564
335
  - `arguments` (optional): Key-value pairs as arguments. Supports both `key=value` and `key value` formats.
565
336
 
566
337
  **Flags:**
@@ -572,15 +343,9 @@ npx workers exec <capabilityName> [functionName] [arg1=value1 arg2=value2...]
572
343
 
573
344
  **Examples:**
574
345
 
575
- ```bash
346
+ ```shell
576
347
  # Execute a sync capability
577
348
  npx workers exec tasksSync
578
-
579
- # Execute a slash command's search function
580
- npx workers exec taskSearch executeSearch query="ajax"
581
-
582
- # Execute with specific output mode
583
- npx workers exec taskSearch executeSearch query="test" --output=full
584
349
  ```
585
350
 
586
351
  ### `npx workers capabilities`
@@ -593,15 +358,17 @@ List all capabilities for the deployed worker.
593
358
 
594
359
  **Example:**
595
360
 
596
- ```bash
361
+ ```shell
597
362
  npx workers capabilities list
598
363
  ```
599
364
 
600
- This will display all capabilities with their names and types (e.g., `sync`, `slashCommand`).
365
+ This will display all capabilities with their names and types (e.g., `sync`,
366
+ `tool`).
601
367
 
602
368
  ### `npx workers secrets`
603
369
 
604
- Commands for managing worker secrets. Secrets are exposed to your functions as environment variables via `process.env`.
370
+ Commands for managing worker secrets. Secrets are exposed to your functions as
371
+ environment variables via `process.env`.
605
372
 
606
373
  #### `npx workers secrets set <key> <value> [<key2> <value2>...]`
607
374
 
@@ -615,7 +382,7 @@ Set one or more secrets for your worker. Supports multiple formats:
615
382
 
616
383
  **Examples:**
617
384
 
618
- ```bash
385
+ ```shell
619
386
  # Set a single secret
620
387
  npx workers secrets set API_KEY my-secret-value
621
388
 
@@ -631,11 +398,12 @@ npx workers secrets set API_KEY=my-key DATABASE_URL my-db-url
631
398
 
632
399
  #### `npx workers secrets list`
633
400
 
634
- List all secret keys for your worker. Note: Secret values are not displayed, only keys and creation timestamps.
401
+ List all secret keys for your worker. Note: Secret values are not displayed,
402
+ only keys and creation timestamps.
635
403
 
636
404
  **Example:**
637
405
 
638
- ```bash
406
+ ```shell
639
407
  npx workers secrets list
640
408
  ```
641
409
 
@@ -649,35 +417,40 @@ Remove a secret from your worker.
649
417
 
650
418
  **Example:**
651
419
 
652
- ```bash
420
+ ```shell
653
421
  npx workers secrets rm API_KEY
654
422
  ```
655
423
 
656
424
  ### `npx workers connect`
657
425
 
658
- Commands for managing OAuth connections that store provider tokens as worker secrets. Connections appear in your runtime as environment variables (e.g., `process.env.NOTION_OAUTH_GOOGLE`).
426
+ Commands for managing OAuth connections that store provider tokens as worker
427
+ secrets. Connections appear in your runtime as environment variables (e.g.,
428
+ `process.env.NOTION_OAUTH_GOOGLE`).
659
429
 
660
430
  #### `npx workers connect providers`
661
431
 
662
432
  List the OAuth providers that are currently available for your workspace.
663
433
 
664
- ```bash
434
+ ```shell
665
435
  npx workers connect providers
666
436
  ```
667
437
 
668
438
  #### `npx workers connect add <provider>`
669
439
 
670
- Start the OAuth flow in your browser for the specified provider. The command opens your default browser and also prints a fallback link.
440
+ Start the OAuth flow in your browser for the specified provider. The command
441
+ opens your default browser and also prints a fallback link.
671
442
 
672
- ```bash
443
+ ```shell
673
444
  npx workers connect add google
674
445
  ```
675
446
 
676
447
  #### `npx workers connect list`
677
448
 
678
- Display all active OAuth connections for the deployed worker. The output includes the provider name, the environment variable exposed to your code, and when the connection was created.
449
+ Display all active OAuth connections for the deployed worker. The output
450
+ includes the provider name, the environment variable exposed to your code, and
451
+ when the connection was created.
679
452
 
680
- ```bash
453
+ ```shell
681
454
  npx workers connect list
682
455
  ```
683
456
 
@@ -685,13 +458,14 @@ npx workers connect list
685
458
 
686
459
  Remove an OAuth connection (and the stored tokens) for the specified provider.
687
460
 
688
- ```bash
461
+ ```shell
689
462
  npx workers connect rm google
690
463
  ```
691
464
 
692
465
  ### Configuration file
693
466
 
694
- The CLI stores configuration in a `workers.json` file in your project directory. This file is automatically created and updated by the CLI commands. It contains:
467
+ The CLI stores configuration in a `workers.json` file in your project directory.
468
+ This file is automatically created and updated by the CLI commands. It contains:
695
469
 
696
470
  - **`environment`**: The current environment (`local`, `staging`, `dev`, or `prod`)
697
471
  - **`token`**: Your authentication token