@collective-intelligence/external-apps-server-sdk-payload 0.0.0-placeholder.0 → 0.13.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 (61) hide show
  1. package/AGENTS.md +49 -0
  2. package/README.md +122 -0
  3. package/dist/ci-generate/declarations/ci-generate/generate.d.ts +10 -0
  4. package/dist/ci-generate/declarations/entrypoints/ci-generate.d.ts +6 -0
  5. package/dist/ci-generate/declarations/knowledge/body.d.ts +32 -0
  6. package/dist/ci-generate/declarations/knowledge/files.d.ts +42 -0
  7. package/dist/ci-generate/declarations/knowledge/manifest.d.ts +19 -0
  8. package/dist/ci-generate/declarations/package/builder.d.ts +63 -0
  9. package/dist/ci-generate/declarations/package/contract.d.ts +16 -0
  10. package/dist/ci-generate/declarations/package/stamped-fields.d.ts +7 -0
  11. package/dist/ci-generate/declarations/plugin/editor-field.d.ts +20 -0
  12. package/dist/ci-generate/declarations/plugin/integration-user.d.ts +11 -0
  13. package/dist/ci-generate/declarations/plugin/parts.d.ts +81 -0
  14. package/dist/ci-generate.d.ts +1 -0
  15. package/dist/ci-generate.js +2 -0
  16. package/dist/index/declarations/ci-generate/generate.d.ts +10 -0
  17. package/dist/index/declarations/entrypoints/index.d.ts +6 -0
  18. package/dist/index/declarations/knowledge/body.d.ts +32 -0
  19. package/dist/index/declarations/knowledge/files.d.ts +42 -0
  20. package/dist/index/declarations/knowledge/identity.d.ts +27 -0
  21. package/dist/index/declarations/knowledge/manifest.d.ts +19 -0
  22. package/dist/index/declarations/knowledge/push-job.d.ts +8 -0
  23. package/dist/index/declarations/knowledge/source.d.ts +24 -0
  24. package/dist/index/declarations/operations/conflict.d.ts +22 -0
  25. package/dist/index/declarations/operations/markdown.d.ts +25 -0
  26. package/dist/index/declarations/operations/operations.d.ts +30 -0
  27. package/dist/index/declarations/operations/write-back.d.ts +8 -0
  28. package/dist/index/declarations/package/builder.d.ts +63 -0
  29. package/dist/index/declarations/package/contract.d.ts +16 -0
  30. package/dist/index/declarations/package/stamped-fields.d.ts +7 -0
  31. package/dist/index/declarations/plugin/editor-field.d.ts +20 -0
  32. package/dist/index/declarations/plugin/grant-store.d.ts +21 -0
  33. package/dist/index/declarations/plugin/integration-user.d.ts +11 -0
  34. package/dist/index/declarations/plugin/parts.d.ts +81 -0
  35. package/dist/index/declarations/plugin/plugin.d.ts +10 -0
  36. package/dist/index.d.ts +1 -0
  37. package/dist/index.js +7 -0
  38. package/dist/package.d.ts +134 -0
  39. package/dist/package.js +24 -0
  40. package/docs/guide/ai/index.md +379 -0
  41. package/docs/guide/ai/studio.md +245 -0
  42. package/docs/guide/data/connectors.md +267 -0
  43. package/docs/guide/data/datasets.md +145 -0
  44. package/docs/guide/data/documents.md +235 -0
  45. package/docs/guide/data/index.md +62 -0
  46. package/docs/guide/data/knowledge.md +214 -0
  47. package/docs/guide/develop/extensions.md +299 -0
  48. package/docs/guide/develop/external-apps.md +289 -0
  49. package/docs/guide/develop/infrastructure.md +135 -0
  50. package/docs/guide/develop/sdks.md +252 -0
  51. package/docs/guide/index.md +83 -0
  52. package/docs/guide/platform/access.md +311 -0
  53. package/docs/guide/platform/architecture.md +166 -0
  54. package/docs/guide/platform/built-ins.md +225 -0
  55. package/docs/guide/platform/entrypoints.md +320 -0
  56. package/docs/guide/scenarios/index.md +130 -0
  57. package/docs/guide/template/index.md +295 -0
  58. package/docs/guide/template/state-machines.md +294 -0
  59. package/docs/payload-connector.md +890 -0
  60. package/docs/payload-page-editor-skill.md +284 -0
  61. package/package.json +76 -8
@@ -0,0 +1,284 @@
1
+ # Payload page editor Skill
2
+
3
+ An Agent writes the pages of a Payload Site with the six operations of the
4
+ Payload Operation Contract: `read`, `create`, `update`, `publish`,
5
+ `unpublish` and `delete`. A page editor Skill tells the Agent how to use
6
+ them, and each of its tool bindings sets the approval of one operation.
7
+
8
+ Call `payloadPageEditor` from the Payload SDK `/package` in your extension
9
+ package. It declares the page editor Skill and the Agent that holds it, under
10
+ the FQNs that you give, and returns them as finished components. Change the
11
+ instruction text and the approvals with its inputs.
12
+
13
+ ## Before you start
14
+
15
+ - Set up the site and the package: [Payload connector](payload-connector.md).
16
+ - Mark each collection that the Agent writes with `writable: true` in
17
+ `ciPayloadPlugin`, then make a site migration (see
18
+ [Make the site migration](payload-connector.md#2-make-the-site-migration)).
19
+ An operation on a collection that is not writable fails with
20
+ `invalid_request`.
21
+ - Declare the Gateway with `payloadGateway`. Install makes one tool for each
22
+ operation on the package's own Gateway Connection, and binds the Skill to
23
+ these tools.
24
+
25
+ ## Call the helper
26
+
27
+ Add the `components` of `payloadPageEditor` to `declarePackage`, with the
28
+ package's own Gateway. In the test site's package:
29
+
30
+ ```ts
31
+ import { declarePackage } from "@collective-intelligence/extensions-sdk"
32
+ import {
33
+ payloadGateway,
34
+ payloadPageEditor
35
+ } from "@collective-intelligence/external-apps-server-sdk-payload/package"
36
+
37
+ const gateway = payloadGateway({
38
+ displayName: "Museum site",
39
+ fqn: names.gateway,
40
+ version
41
+ })
42
+ const pageEditor = payloadPageEditor({
43
+ agentFqn: `${input.fqn}.agents.page-editor`,
44
+ gateway,
45
+ skillFqn: `${input.fqn}.skills.page-editor`,
46
+ version
47
+ })
48
+
49
+ return declarePackage({
50
+ components: [
51
+ gateway,
52
+ // The schemas, the connector instance, the policies and the other parts.
53
+ ...pageEditor.components
54
+ ],
55
+ manifest
56
+ })
57
+ ```
58
+
59
+ The inputs:
60
+
61
+ | Input | Value |
62
+ | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
63
+ | `gateway` | The Gateway that `payloadGateway` returns. The Skill binds its six operations. |
64
+ | `skillFqn` | The FQN of the Skill |
65
+ | `agentFqn` | The FQN of the Agent |
66
+ | `version` | The version of both components |
67
+ | `instructions` | Optional. The instruction text of the Skill, in place of the [default text](#instruction-text) |
68
+ | `approvals` | Optional. The approval of an operation, by operation id, in place of its [default approval](#approvals), for example `{ create: "always" }` |
69
+
70
+ The result has `skill`, `agent`, and `components` (the Skill, then the
71
+ Agent). The bindings take the operation ids of the Payload Operation
72
+ Contract: an unknown id fails the type check.
73
+
74
+ ## What the helper declares
75
+
76
+ The Skill, **Page editor**:
77
+
78
+ - binds the six operations of the Gateway, each with its approval. The
79
+ manifest stores the Gateway FQN and the operation's contract reference,
80
+ for example `payload/documents/publish@1.0.0`.
81
+ - has `audience: { organization: true }`. A Skill without an `audience` is
82
+ offered to nobody, also inside an Agent that holds it.
83
+
84
+ The Agent, `<Gateway display name> page editor` (in the test site,
85
+ **Museum site page editor**):
86
+
87
+ - takes its display name from the Gateway. The backend refuses a second
88
+ Organization Agent with the same display name, so give the Gateway of each
89
+ Payload Site in an Organization its own display name. The Skill name
90
+ **Page editor** can repeat: install knows a package Skill by its FQN.
91
+ - holds the Skill, and offers it to the Organization members.
92
+ - binds the `read` operation itself under the name `read-page`, with the
93
+ `read` approval of the Skill (default: no approval). Install refuses an
94
+ Agent whose held Skill uses a tool that
95
+ the Agent does not allow; this binding allows the operation tools of the
96
+ Skill:
97
+
98
+ ```text
99
+ Agent '<agent fqn>' holds Skill '<skill fqn>', which uses tools the Agent does not allow: <tool fqns>. Add them to the Agent's tools.
100
+ ```
101
+
102
+ - publishes, unpublishes or deletes a page only when the user asks for it
103
+ (its behavioral boundary).
104
+
105
+ All operation tools share one tool template, and an administrator
106
+ restriction on an Agent's binding names the template and the binding `name`.
107
+ The `read-page` name keeps a restriction on that binding off the other
108
+ operation bindings of the Agent. Two bindings that the model would know by
109
+ one name are refused at declaration and at install, for example:
110
+
111
+ ```text
112
+ skill:<skill fqn>: two tool bindings have the name 'publish'; give one of them its own name
113
+ ```
114
+
115
+ The Skill and the Agent declare no `dataAccess`, so they read in their own
116
+ mode. Install then needs an installer who holds `admin.unrestrictedRuns`, as
117
+ Organization admins do by default. Without it, install refuses the Skill and
118
+ the Agent, for example:
119
+
120
+ ```text
121
+ This Agent reads all Organization data in its own mode; saving it needs admin.unrestrictedRuns. Set every source to "user" or ask an Organization admin.
122
+ ```
123
+
124
+ ## Instruction text
125
+
126
+ This is the default instruction text of the Skill, with the
127
+ [default approvals](#approvals). To change it, give your full text in
128
+ `instructions`, with the steps and the rules of your site.
129
+
130
+ When you give `approvals` and no `instructions`, steps 5 and 6 name a
131
+ person's approval only for the operations whose approval is `always`. For
132
+ example, with `approvals: { publish: "never" }`, step 5 ends with "A person
133
+ approves each unpublish." A rule approval decides per call, so the text does
134
+ not name it.
135
+
136
+ ```md
137
+ # Page editor
138
+
139
+ Write the pages of the Payload site. Visitors see only published pages. A draft stays on the site until a person publishes it.
140
+
141
+ ## Steps
142
+
143
+ 1. Read the site without an id to get its collections. Write only to a collection with `writable: true`. The list also tells if a collection has drafts and trash.
144
+ 2. Before you change a document, read it with its id. Keep its `revision`.
145
+ 3. To add a page, create it. In a collection with drafts, a new page is a draft.
146
+ 4. To change a page, update it with the `revision` of step 2. In a collection with drafts, the change is a new draft.
147
+ 5. Publish or unpublish a page only when the user asks for it. A person approves each publish and unpublish.
148
+ 6. Delete a page only when the user asks for it. Set `mode` to `trash` for a collection with trash, and to `permanent` for a collection without trash. A person approves each delete.
149
+
150
+ ## Field values
151
+
152
+ - Write rich text as Markdown: headings, bullet and numbered lists, quotes, rules (`---`), paragraphs, bold, italic, strikethrough, inline code and links. The site keeps as text the Markdown that its editor does not support. Blocks inside rich text, tables and uploads stay text.
153
+ - Write other fields and blocks as JSON.
154
+ - On a site with more than one language, give `locale` to read, create, update, publish and unpublish. Without `locale`, the site uses its default language. A delete removes the document in all languages.
155
+
156
+ ## Errors
157
+
158
+ - `conflict`: the document changed after your read, or an editor has it open. Read it again, make your change on the new version, and try one more time. If it fails again, tell the user.
159
+ - `invalid_request`: the message names the collection or the field. Correct that input before you call again.
160
+ ```
161
+
162
+ ## Approvals
163
+
164
+ The default approval of each Skill binding:
165
+
166
+ | Binding | Approval | Reason |
167
+ | ----------- | -------- | ---------------------------------------------------------------------- |
168
+ | `read` | `never` | It reads only. |
169
+ | `create` | `never` | In a collection with drafts, it saves a draft. Visitors do not see it. |
170
+ | `update` | `never` | In a collection with drafts, it saves a draft. Visitors do not see it. |
171
+ | `publish` | `always` | Visitors see the change. |
172
+ | `unpublish` | `always` | The page goes off the site. |
173
+ | `delete` | `always` | The document goes to trash, or is deleted for ever. |
174
+
175
+ These defaults are the helper's, not CI rules. CI uses only its standard
176
+ tool binding approval, and each binding keeps its own approval.
177
+
178
+ `never` on `create` and `update` fits a collection with drafts. In a
179
+ collection without drafts, a create or an update changes the live page at
180
+ once: give `approvals: { create: "always", update: "always" }` when a person
181
+ must check each change.
182
+
183
+ ### Knowledge Mutate on Payload schemas
184
+
185
+ The page editor Skill does not use Knowledge Mutate. An administrator or
186
+ another package can bind Knowledge Mutate on a Payload schema to an Agent or
187
+ a Skill. Through the Remote-first write, an edit of a published item then
188
+ publishes it on the site. Set `always` on each Knowledge Mutate binding that
189
+ reaches a Payload schema. With `never`, an Agent can publish a Knowledge
190
+ edit with no person. The Knowledge write-back rules are in
191
+ [The Knowledge of the chosen collections](payload-connector.md#the-knowledge-of-the-chosen-collections).
192
+
193
+ Knowledge Mutate ships disabled: each Organization has its tool instance,
194
+ but CI does not turn it on. An administrator enables it before a package
195
+ Skill or Agent binds it:
196
+
197
+ ```http
198
+ PUT /admin/ai/tool-instances/<Knowledge Mutate tool instance id>
199
+ x-organization-id: <organization id>
200
+
201
+ { "enabled": true }
202
+ ```
203
+
204
+ Otherwise install refuses the binding:
205
+
206
+ ```text
207
+ Skill '<skill fqn>' references unavailable tool 'builtin.core.knowledge.tools.mutate'
208
+ Agent '<agent fqn>' references unavailable tools: builtin.core.knowledge.tools.mutate
209
+ ```
210
+
211
+ To limit a binding to the site's schemas, set
212
+ `settings.allowedEntitySchemaIds` to their FQNs. Install changes each FQN
213
+ into the id of the Organization's schema.
214
+
215
+ ### Approve a call
216
+
217
+ An `always` call waits until a person approves it. The approval request
218
+ shows the tool input: in the chat, in the Studio **Approvals** sheet
219
+ (**Tool input**) and in the approval card of Notifications. For a delete,
220
+ read the `mode` there: `trash` or `permanent`. The admin approval routes and
221
+ the Dashboard approvals page do not show CI tool approvals.
222
+
223
+ A person approves only where a person is: in a chat, or in an Agent run that
224
+ a person starts. An Agent run that no person starts, for example from a
225
+ schedule, approves each `always` call at once. The **Gateway Operation**
226
+ workflow node calls an operation with no approval. Keep the page editor away
227
+ from these paths when a person must check each publish, unpublish and
228
+ delete.
229
+
230
+ ## What the operations do
231
+
232
+ - **Collections.** `read` without `id` lists the exposed collections, with
233
+ `drafts`, `trash` and `writable` for each one. The other operations write
234
+ only a writable collection. `publish` and `unpublish` need a collection
235
+ with drafts.
236
+ - **Revision.** `read` with `id` gives the newest draft, the published
237
+ version and the `revision`. `update` sends that `revision`. When the
238
+ document changed after the read, or an editor holds its lock, the write
239
+ fails with `conflict`.
240
+ - **Rich text.** `data` takes rich text as Markdown text or as a Lexical
241
+ editor state. The plugin converts headings, bullet and numbered lists,
242
+ quotes, rules, paragraphs, bold, italic, strikethrough, inline code and
243
+ links, each only when the field's Lexical editor has that feature. Other
244
+ Markdown stays text. Custom Lexical features, such as blocks inside rich
245
+ text, tables and uploads, are not converted. A rich-text field with another
246
+ editor refuses Markdown. Other fields and blocks take JSON.
247
+ - **Language.** `read`, `create`, `update`, `publish` and `unpublish` take
248
+ an optional `locale`. Without it, the operation uses the site's default
249
+ locale. A locale that the site does not have fails with `invalid_request`.
250
+ `read` gives no fallback text from another locale. `delete` acts on the
251
+ whole document.
252
+ - **Delete mode.** `delete` needs `mode`: `trash` for a collection with
253
+ trash, `permanent` for a collection without trash. Another mode fails with
254
+ `invalid_request`.
255
+ - **Retries.** CI keys each Gateway call of an Agent with
256
+ `<harnessInvocationId>.<toolCallId>`. A `create` keeps the key in the
257
+ hidden, unique `ciCreateKey` field. A retry of the same tool call gives
258
+ the document that the first call made, not a second page, also while the
259
+ first call still runs. An `update` keeps the key in the hidden
260
+ `ciUpdateKey` field until the next save: when CI sends the call again
261
+ because its answer was lost, the retry gives the version that the first
262
+ call saved, not a `conflict`. After a later save, the retry gets the
263
+ revision check again.
264
+ - **CI Editor field.** Each CI write sets the hidden `ciEditor` field to the
265
+ CI user (`Name <email>`) of the Write Actor (`context.actor`). Each other
266
+ save, also a CI write without a Write Actor, clears it. The version
267
+ history of the document shows it to the site's admin users only, and
268
+ `read` leaves it out.
269
+ - **Fields of Payload and the plugin.** `create` and `update` refuse with
270
+ `invalid_request` a `data` field that only Payload and the plugin write:
271
+ `id`, `_status`, `createdAt`, `updatedAt`, `deletedAt`, `ciCreateKey`,
272
+ `ciUpdateKey` and `ciEditor`. Publish, unpublish and delete have their own
273
+ operations.
274
+ - **Integration User.** The operations read and write as the Integration
275
+ User, with the site's access rules on. The site refuses what that user may
276
+ not do (`authorization_denied`).
277
+
278
+ ## Create the Skill in the Dashboard
279
+
280
+ On the Dashboard path, no package calls the helper. An administrator
281
+ creates the Skill on the Dashboard **Skills** page: the
282
+ [instruction text](#instruction-text) goes in **Instructions**, and the six
283
+ operation tools of the site's Gateway Connection go in **Tools**. Use the
284
+ [default approvals](#approvals) for these tools too.
package/package.json CHANGED
@@ -1,13 +1,81 @@
1
1
  {
2
2
  "name": "@collective-intelligence/external-apps-server-sdk-payload",
3
- "version": "0.0.0-placeholder.0",
4
- "description": "",
5
- "main": "index.js",
3
+ "version": "0.13.0",
4
+ "description": "The Payload SDK: the CMS SDK that connects a Payload Site to Collective Intelligence through a Gateway, with the Payload Plugin, the Payload Package Helpers and the payload ci-generate command.",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "files": [
8
+ "dist",
9
+ "README.md",
10
+ "AGENTS.md",
11
+ "docs"
12
+ ],
13
+ "main": "./dist/index.js",
14
+ "types": "./dist/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "ci-source": "./src/entrypoints/index.ts",
18
+ "types": "./dist/index.d.ts",
19
+ "import": "./dist/index.js",
20
+ "default": "./dist/index.js"
21
+ },
22
+ "./package": {
23
+ "ci-source": "./src/entrypoints/package.ts",
24
+ "types": "./dist/package.d.ts",
25
+ "import": "./dist/package.js",
26
+ "default": "./dist/package.js"
27
+ },
28
+ "./ci-generate": {
29
+ "ci-source": "./src/entrypoints/ci-generate.ts",
30
+ "types": "./dist/ci-generate.d.ts",
31
+ "import": "./dist/ci-generate.js",
32
+ "default": "./dist/ci-generate.js"
33
+ }
34
+ },
6
35
  "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
36
+ "build": "bun tools/build.ts",
37
+ "check:models": "tsprover",
38
+ "test": "bun run test:unit && bun run test:pack",
39
+ "test:pack": "bun tools/test-pack.ts",
40
+ "test:unit": "bun --conditions=ci-source test src test/imports.test.ts test/manifest.test.ts",
41
+ "format": "oxfmt --write .",
42
+ "format:check": "oxfmt --check .",
43
+ "format:check:staged": "oxfmt --check",
44
+ "lint": "node \"../../../.agents/scripts/managed-lint-runner.mjs\" --scope \"packages/public/external-apps-server-sdk-payload\"",
45
+ "lint:staged": "oxlint --no-error-on-unmatched-pattern",
46
+ "prepack": "bun run build",
47
+ "type-check": "bun check --no-script -p tsconfig.json && bun check --no-script -p tsconfig.type-tests.json && bun check --no-script -p tsconfig.type-tests-inexact-optional.json"
48
+ },
49
+ "dependencies": {
50
+ "@collective-intelligence/external-apps-server-sdk": "0.13.0"
51
+ },
52
+ "peerDependencies": {
53
+ "@collective-intelligence/extensions-sdk": "0.13.0",
54
+ "effect": "^4.1.0",
55
+ "payload": ">=3 <4"
56
+ },
57
+ "publishConfig": {
58
+ "access": "public"
59
+ },
60
+ "devDependencies": {
61
+ "@collective-intelligence/extensions-sdk": "0.13.0",
62
+ "@effect/eslint-plugin": "0.3.2",
63
+ "@oxlint/plugins": "1.94.0",
64
+ "@punks/lints": "0.2.0",
65
+ "@types/bun": "1.4.2",
66
+ "@types/node": "25.9.7",
67
+ "@typescript-eslint/utils": "8.22.0",
68
+ "ajv": "8.20.0",
69
+ "dts-bundle-generator": "9.5.1",
70
+ "effect": "4.1.4",
71
+ "eslint": "9.39.5",
72
+ "jose": "6.2.9",
73
+ "oxfmt": "0.66.0",
74
+ "oxlint": "1.94.0",
75
+ "payload": "3.94.1",
76
+ "tsprover": "0.0.2",
77
+ "typescript": "5.9.3",
78
+ "ultracite": "7.10.7"
8
79
  },
9
- "keywords": [],
10
- "author": "",
11
- "license": "ISC",
12
- "type": "commonjs"
80
+ "gitHead": "d3e93c4287307c474b0bf32c386a1471fe67ce2c"
13
81
  }