@collective-intelligence/ai 0.0.0-placeholder.0 → 0.7.1

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 (172) hide show
  1. package/AGENTS.md +52 -0
  2. package/README.md +463 -1
  3. package/dist/api/access-check.d.ts +18 -0
  4. package/dist/api/answer-sources.d.ts +48 -0
  5. package/dist/api/attachments-api.d.ts +187 -0
  6. package/dist/api/catalog-api.d.ts +408 -0
  7. package/dist/api/chat-api.d.ts +2401 -0
  8. package/dist/api/chat-surface-api.d.ts +4186 -0
  9. package/dist/api/compaction.d.ts +52 -0
  10. package/dist/api/conversations.d.ts +107 -0
  11. package/dist/api/errors.d.ts +117 -0
  12. package/dist/api/feedback-api.d.ts +185 -0
  13. package/dist/api/files.d.ts +22 -0
  14. package/dist/api/ids.d.ts +33 -0
  15. package/dist/api/index.d.ts +21 -0
  16. package/dist/api/intents-api.d.ts +65 -0
  17. package/dist/api/place-context.d.ts +34 -0
  18. package/dist/api/projects-api.d.ts +718 -0
  19. package/dist/api/speech-api.d.ts +345 -0
  20. package/dist/api/transcript.d.ts +260 -0
  21. package/dist/api/turns.d.ts +196 -0
  22. package/dist/api.d.ts +21 -0
  23. package/dist/api.js +1 -0
  24. package/dist/domain/access.d.ts +29 -0
  25. package/dist/domain/context-trail.d.ts +65 -0
  26. package/dist/domain/data-parts.d.ts +247 -0
  27. package/dist/domain/errors.d.ts +28 -0
  28. package/dist/domain/index.d.ts +14 -0
  29. package/dist/domain/intents.d.ts +101 -0
  30. package/dist/domain/message.d.ts +173 -0
  31. package/dist/domain/place.d.ts +17 -0
  32. package/dist/domain/runtime-value.d.ts +16 -0
  33. package/dist/domain-50vzrrp9.js +2 -0
  34. package/dist/domain-5fpd4fte.js +1 -0
  35. package/dist/domain-9wzbv87n.js +2 -0
  36. package/dist/domain-g97xs965.js +2 -0
  37. package/dist/domain-hk3yw2m7.js +1 -0
  38. package/dist/domain-qyts6dgz.js +0 -0
  39. package/dist/domain-s07s1ry1.js +2 -0
  40. package/dist/domain.d.ts +14 -0
  41. package/dist/domain.js +1 -0
  42. package/dist/headless/access/access-store.d.ts +28 -0
  43. package/dist/headless/access/visibility.d.ts +24 -0
  44. package/dist/headless/blocked-state.d.ts +21 -0
  45. package/dist/headless/chat-registry.d.ts +63 -0
  46. package/dist/headless/chat-session-provider.d.ts +109 -0
  47. package/dist/headless/chat-surface.d.ts +4210 -0
  48. package/dist/headless/host-ports.d.ts +146 -0
  49. package/dist/headless/index.d.ts +33 -0
  50. package/dist/headless/intents/card-ends.d.ts +22 -0
  51. package/dist/headless/intents/intent-call.d.ts +28 -0
  52. package/dist/headless/intents/intents-provider.d.ts +108 -0
  53. package/dist/headless/intents/page-registry.d.ts +129 -0
  54. package/dist/headless/intents/use-intent-dispatch.d.ts +60 -0
  55. package/dist/headless/intents/use-intents.d.ts +11 -0
  56. package/dist/headless/intents/use-returned-intent-handle.d.ts +11 -0
  57. package/dist/headless/launch/chat-launch.d.ts +42 -0
  58. package/dist/headless/launch/launch-target.d.ts +25 -0
  59. package/dist/headless/launch/submit.d.ts +29 -0
  60. package/dist/headless/run-state.d.ts +16 -0
  61. package/dist/headless/sent-files.d.ts +20 -0
  62. package/dist/headless/server-started-turn-follow.proof.d.ts +26 -0
  63. package/dist/headless/session-machine.d.ts +745 -0
  64. package/dist/headless/trail/buffer.d.ts +48 -0
  65. package/dist/headless/trail/json-ld.d.ts +10 -0
  66. package/dist/headless/trail/switches.d.ts +10 -0
  67. package/dist/headless/trail/trail-provider.d.ts +53 -0
  68. package/dist/headless/transcript-messages.d.ts +26 -0
  69. package/dist/headless.d.ts +33 -0
  70. package/dist/headless.js +2 -0
  71. package/dist/transport/chat-client.d.ts +25 -0
  72. package/dist/transport/chat-transport.d.ts +57 -0
  73. package/dist/transport/index.d.ts +6 -0
  74. package/dist/transport/simulated-chat-transport.d.ts +39 -0
  75. package/dist/transport.d.ts +6 -0
  76. package/dist/transport.js +1 -0
  77. package/dist/views/assistant-sidebar/assistant-sidebar.d.ts +15 -0
  78. package/dist/views/assistant-sidebar/layout.d.ts +47 -0
  79. package/dist/views/assistant-sidebar/toggle.d.ts +14 -0
  80. package/dist/views/assistant-sidebar/use-shortcut.d.ts +11 -0
  81. package/dist/views/blocked/chat-blocked-state.d.ts +15 -0
  82. package/dist/views/chat-operations.d.ts +46 -0
  83. package/dist/views/chat-root.d.ts +14 -0
  84. package/dist/views/chat.d.ts +51 -0
  85. package/dist/views/composer/capability-picker.d.ts +77 -0
  86. package/dist/views/composer/capability-pickers.d.ts +24 -0
  87. package/dist/views/composer/chat-composer.d.ts +15 -0
  88. package/dist/views/composer/composer-picks.d.ts +31 -0
  89. package/dist/views/composer/composer-trail.d.ts +21 -0
  90. package/dist/views/composer/draft-attachments.d.ts +36 -0
  91. package/dist/views/composer/queued-messages.d.ts +9 -0
  92. package/dist/views/composer/send-menu.d.ts +11 -0
  93. package/dist/views/composer/slash-suggestions.d.ts +37 -0
  94. package/dist/views/composer/trail-chips.d.ts +15 -0
  95. package/dist/views/composer/voice-input/microphone.d.ts +14 -0
  96. package/dist/views/composer/voice-input/remote-transcription.d.ts +12 -0
  97. package/dist/views/composer/voice-input/use-voice-input.d.ts +30 -0
  98. package/dist/views/composer/voice-input/voice-input.d.ts +15 -0
  99. package/dist/views/dock/chat-dock.d.ts +57 -0
  100. package/dist/views/dock/dock-session.d.ts +22 -0
  101. package/dist/views/header/chat-header.d.ts +10 -0
  102. package/dist/views/header/compaction-controls.d.ts +17 -0
  103. package/dist/views/header/memory-switch.d.ts +16 -0
  104. package/dist/views/index.d.ts +58 -0
  105. package/dist/views/intents/form-fields.d.ts +38 -0
  106. package/dist/views/intents/intent-card.d.ts +61 -0
  107. package/dist/views/intents/intent-form.d.ts +23 -0
  108. package/dist/views/intents/intent-notices.d.ts +39 -0
  109. package/dist/views/intents/intent-trigger.d.ts +46 -0
  110. package/dist/views/intents/labels.d.ts +23 -0
  111. package/dist/views/labels/en.d.ts +3 -0
  112. package/dist/views/labels/index.d.ts +13 -0
  113. package/dist/views/labels/it.d.ts +3 -0
  114. package/dist/views/labels/types.d.ts +7 -0
  115. package/dist/views/launch/chat-launch-button.d.ts +21 -0
  116. package/dist/views/parts/answer-feedback.d.ts +26 -0
  117. package/dist/views/parts/evidence-part.d.ts +8 -0
  118. package/dist/views/parts/file-part.d.ts +8 -0
  119. package/dist/views/parts/image-generation-part.d.ts +9 -0
  120. package/dist/views/parts/image-generation.d.ts +84 -0
  121. package/dist/views/parts/intent-card-part.d.ts +8 -0
  122. package/dist/views/parts/memory-evidence-part.d.ts +7 -0
  123. package/dist/views/parts/message-parts.d.ts +21 -0
  124. package/dist/views/parts/question-part.d.ts +8 -0
  125. package/dist/views/parts/read-aloud.d.ts +23 -0
  126. package/dist/views/parts/reasoning-part.d.ts +8 -0
  127. package/dist/views/parts/steering-message-part.d.ts +7 -0
  128. package/dist/views/parts/text-part.d.ts +4 -0
  129. package/dist/views/parts/tool-part.d.ts +11 -0
  130. package/dist/views/parts/types.d.ts +103 -0
  131. package/dist/views/parts/use-read-aloud.d.ts +13 -0
  132. package/dist/views/run-trace/message-run.d.ts +17 -0
  133. package/dist/views/run-trace/run-stream.d.ts +128 -0
  134. package/dist/views/run-trace/run-trace-parts.d.ts +26 -0
  135. package/dist/views/run-trace/run-trace.d.ts +31 -0
  136. package/dist/views/sidebar/conversation-dialogs.d.ts +38 -0
  137. package/dist/views/sidebar/conversation-row.d.ts +23 -0
  138. package/dist/views/sidebar/conversation-sidebar.d.ts +10 -0
  139. package/dist/views/sidebar/date-groups.d.ts +12 -0
  140. package/dist/views/sidebar/history-filter.d.ts +57 -0
  141. package/dist/views/sidebar/projects/project-dialogs.d.ts +40 -0
  142. package/dist/views/sidebar/projects/project-files.d.ts +16 -0
  143. package/dist/views/sidebar/projects/project-groups.d.ts +19 -0
  144. package/dist/views/sidebar/projects/project-view.d.ts +21 -0
  145. package/dist/views/sidebar/projects/projects-section.d.ts +21 -0
  146. package/dist/views/sidebar/projects/use-chat-projects.d.ts +32 -0
  147. package/dist/views/slots.d.ts +148 -0
  148. package/dist/views/transcript/chat-transcript.d.ts +13 -0
  149. package/dist/views/transcript/sent-trail.d.ts +13 -0
  150. package/dist/views/transcript/use-image-reload.d.ts +16 -0
  151. package/dist/views.d.ts +58 -0
  152. package/dist/views.js +3 -0
  153. package/docs/guide/ai/index.md +377 -0
  154. package/docs/guide/ai/studio.md +245 -0
  155. package/docs/guide/data/connectors.md +267 -0
  156. package/docs/guide/data/datasets.md +145 -0
  157. package/docs/guide/data/documents.md +235 -0
  158. package/docs/guide/data/index.md +62 -0
  159. package/docs/guide/data/knowledge.md +214 -0
  160. package/docs/guide/develop/extensions.md +299 -0
  161. package/docs/guide/develop/external-apps.md +279 -0
  162. package/docs/guide/develop/infrastructure.md +135 -0
  163. package/docs/guide/develop/sdks.md +233 -0
  164. package/docs/guide/index.md +83 -0
  165. package/docs/guide/platform/access.md +311 -0
  166. package/docs/guide/platform/architecture.md +166 -0
  167. package/docs/guide/platform/built-ins.md +225 -0
  168. package/docs/guide/platform/entrypoints.md +318 -0
  169. package/docs/guide/scenarios/index.md +130 -0
  170. package/docs/guide/template/index.md +295 -0
  171. package/docs/guide/template/state-machines.md +294 -0
  172. package/package.json +120 -4
@@ -0,0 +1,311 @@
1
+ # Grants and permissions
2
+
3
+ How CI decides what a user, a Group, an app or an API key may do, and how to change it in the template.
4
+
5
+ CI uses one access model for people, Groups, apps, service principals and API keys. Capabilities name the operations, Access Profiles bundle capabilities, Access Grants give a profile to someone, and Knowledge Data Policies decide which records a capability opens. This model replaced the older organization roles, app roles, API key scopes and OAuth scopes. The Dashboard still labels an Access Profile as "Role", so read that word as "profile" wherever you meet it.
6
+
7
+ ## The model in one diagram
8
+
9
+ ```mermaid
10
+ flowchart LR
11
+ P["Principal<br/>user, Group, service principal,<br/>app server, app visitors"] --> G[Access Grant]
12
+ G --> AP[Access Profile]
13
+ AP --> C[Capabilities]
14
+ MP[Max Privileges] -. caps app tokens and API keys .-> C
15
+ C --> DP[Knowledge Data Policy]
16
+ DP --> R[Records the caller may read or write]
17
+ ```
18
+
19
+ A grant gives exactly one profile to exactly one recipient. The profile holds capabilities, and a Knowledge Data Policy turns a capability into rows of one schema. Max Privileges never give anything: they cut what an app's user tokens or an API key may use, whatever the grants say.
20
+
21
+ | Term | What it is | Who declares it |
22
+ | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
23
+ | Capability | An operation CI authorizes, with a stable `code`. A Switch is off or on. A Read/Manage capability is off, `read` or `manage`, and `manage` includes `read`. Capabilities form a tree, and holding a node gives every node below it, including nodes a later release adds. | The core and packages |
24
+ | Access Profile | A set of capabilities for one audience: `user`, `server` or `anonymous`. | The core (six built-in, read-only profiles) and packages |
25
+ | Access Grant | One profile given to one recipient. | Packages, or at runtime through the Dashboard, invitations, SSO and the server SDK |
26
+ | Max Privileges | The most an app's user tokens or an API key may use. | Packages |
27
+ | Knowledge Data Policy | A rule on one schema and one operation (`read` or `write`): a required capability, an optional `where`, and the fields it lets the caller read or write. | The core and packages only. Nobody edits a policy at runtime. |
28
+ | Resource Audience | Who an agent, Skill, tool, workflow or Studio app is offered to. Entries name users, Groups, profile holders, apps, the whole Organization or anonymous visitors. | Packages |
29
+
30
+ ## How CI decides
31
+
32
+ Every grant only allows. No grant and no audience entry can deny, so a policy that must hide some records does it with a `where` clause. CI also checks each grant alone, for reads, updates and read masks. If one grant holds the capability and a second grant holds the right perimeter, the two halves never combine into one permission.
33
+
34
+ Through an app, the user's effective access is the union of their grants, each checked alone, cut down to the app's Max Privileges. A Sales manager who is also an Organization admin still cannot do through the app what the Max Privileges leave out. Dashboard, Studio and MCP sessions are not cut this way.
35
+
36
+ A grant change takes effect within 60 seconds. Every Organization-scoped response carries an `x-access-version` header, and a client that sees the value change refetches its access snapshot from `GET /me/access`.
37
+
38
+ > **Note:** A Studio user reads no Knowledge record until something opens it: a package
39
+ > policy, the built-in knowledge reader profile or a custom profile. A schema
40
+ > without a policy shows its members nothing. In the same way, a resource with
41
+ > an empty audience is offered to nobody.
42
+
43
+ ## Memberships carry no role
44
+
45
+ An Organization membership links one user to one Organization and has one kind, `member` or `guest`. An external app usually creates guests. The membership itself gives no access, because access comes only from grants. Every former role is now a grant of the matching built-in profile, such as `core.profiles.organization-admin` or `core.profiles.knowledge-reader`.
46
+
47
+ ## Groups
48
+
49
+ Groups are the usual way to hand out grants. A Group is a named set of accounts in one Organization: users, and service principals that a package places in its own Groups. Groups form a tree in which each Group has at most one parent, and an Organization allows at most five levels.
50
+
51
+ A grant to a Group has one recipient, the Group, and CI applies it to every account that it reaches. The grant's `coverage` decides which accounts these are:
52
+
53
+ - With `coverage: "direct"`, the grant reaches the members of that Group only.
54
+ - With `coverage: "inherited"`, it also reaches the members of every Group below it, at any depth.
55
+
56
+ Inheritance goes down the tree only. A grant to a parent Group can reach the members of its subgroups, and a grant to a subgroup never reaches the members of its parent. Every grant must state its `coverage`. In a Resource Audience, a Group entry without `coverage` counts as `inherited`.
57
+
58
+ The template shows both directions. It grants the Sales rep profile to Sales and the Sales manager profile to Sales managers, both with `inherited` coverage:
59
+
60
+ ```mermaid
61
+ flowchart TD
62
+ S["Sales<br/>grant: Sales rep, inherited"] --> M["Sales managers<br/>grant: Sales manager, inherited"]
63
+ ```
64
+
65
+ A member of Sales managers holds both profiles, because Sales is an ancestor of their Group. A member who is only in Sales holds Sales rep and nothing from the managers grant.
66
+
67
+ CI stores the grants that reach each account and recalculates them in the same write that adds or removes a Group member, moves a Group or changes a grant. A request reads that stored result and does not walk the tree. A workflow also reads the current Groups of its run identity at every tool call, so a person you remove from a Group loses that access at the next call. Clients see the change within 60 seconds.
68
+
69
+ ### Declared Groups and Dashboard Groups
70
+
71
+ A package declares a Group tree with `declareOrganizationGroup`, and every Group in the tree has an FQN. A subgroup has no handle of its own, so a grant names it by its FQN, which is the parent FQN, a dot and the subgroup key:
72
+
73
+ ```ts
74
+ export const salesGroupFqn = "acme.app.groups.sales"
75
+ const managersKey = "managers"
76
+ /** A subgroup has no handle: a grant names it by FQN. */
77
+ export const salesManagersGroupFqn = `${salesGroupFqn}.${managersKey}`
78
+
79
+ export const salesGroup = declareOrganizationGroup({
80
+ definition: {
81
+ lifecycle: { deployMode: "upsert", readonly: true },
82
+ subgroups: [
83
+ {
84
+ description: "Sales managers of the Acme CRM.",
85
+ displayName: "Sales managers",
86
+ key: managersKey
87
+ }
88
+ ]
89
+ },
90
+ manifest: { fqn: salesGroupFqn, version: VERSION },
91
+ presentation: {
92
+ description: "Sales team of the Acme CRM.",
93
+ displayName: "Sales"
94
+ }
95
+ })
96
+ ```
97
+
98
+ A Group that someone creates in the Dashboard, or with `ci.access.groups.create` from a server, has no FQN. Package grants and the server SDK name a Group only by its FQN, so a Group without one can get grants only in the Dashboard.
99
+
100
+ Declared Groups follow these rules:
101
+
102
+ - Only the package that first declared a Group FQN can declare it again. FQNs that start with `core.groups.` belong to the platform, and a package install that uses one fails.
103
+ - With `upsert`, each deploy writes the declared name, description and parent again. With `init_only`, CI keeps a Group that already exists as it is.
104
+ - The package never fills its Groups. After install, an Organization admin adds people to Sales or Sales managers. The one exception is a service principal that the same package declares with `groups`, which the install places in those Groups.
105
+ - When a release drops a Group, CI deletes it only when nothing uses it, and keeps it otherwise. A Group that holds an Access Grant cannot be deleted.
106
+
107
+ ## Declared and runtime grants
108
+
109
+ A package can declare capabilities, profiles, policies, Max Privileges and grants, and the install creates them in the Organization. The lifecycle of each grant decides who owns it after install. The template's Sales grant uses `deployMode: "init_only"` with `readonly: false`, so an Organization admin can revoke it and a package update does not write it again. The managers grant uses `upsert` with `readonly: true`, so the package keeps it in place.
110
+
111
+ Runtime grants come from the Dashboard, invitations, SSO defaults and the provisioning API. An app's server manages them through `ci.access` in the server SDK. `sync` makes the runtime grants under one namespace match the list exactly:
112
+
113
+ ```ts
114
+ await ci.access.grants.sync({
115
+ grants: [
116
+ {
117
+ fqn: "clinic.patients.p-1001",
118
+ grantee: { user: { email: "patient@example.test" } },
119
+ profile: "clinic.profiles.patient"
120
+ }
121
+ ],
122
+ namespace: "clinic.patients",
123
+ organizationId
124
+ })
125
+ // result = { created, updated, deleted, unchanged }: Access Grant FQNs.
126
+ ```
127
+
128
+ The app's server acts only with the grants that an Organization admin gave to it as `{ applicationServer }`. It creates and changes only its own guests, reads Groups without writing them, sends no invitations, and never touches a package-declared grant.
129
+
130
+ ## Data policies narrow records
131
+
132
+ A capability opens a feature. A Knowledge Data Policy decides which records of one schema that capability reaches. Each template entity domain declares its capabilities and two policies for its schema in its `ci` part: reading needs `read` on the entity's capabilities, and writing needs `manage`. This is the Lead write policy in `@packages/features-lead-ci`:
133
+
134
+ ```ts
135
+ declareAccessKnowledgeDataPolicy({
136
+ definition: {
137
+ capability: access.requires(capabilities, "manage"),
138
+ lifecycle: readonly,
139
+ operation: "write",
140
+ target: leadSchemaFqn,
141
+ },
142
+ manifest: { fqn: "acme.app.policies.leads-write", version },
143
+ }),
144
+ ```
145
+
146
+ Several policies on the same schema and operation combine with OR. A `where` clause limits the rows, and `readableFields: { except: ["salary"] }` removes a field from the result. Read masks do not apply to search, embeddings or filters yet, so a masked value can still match a search. Each record the caller reads also carries `access.write`, which tells the UI whether this caller may change that record and lets a page hide the edit button row by row.
147
+
148
+ A profile can also declare Grant Axes, such as Company or Country, so that one grant reads "this profile, but only for Italy". The template uses no axes. See [Knowledge](../data/knowledge.md) for schemas, conditions and axes in policies.
149
+
150
+ ## The app gate
151
+
152
+ Every external app has an app gate: a Switch capability at the root of the app's capability tree, with the app FQN as its code. CI accepts a user's token for the app only when one of the user's grants holds the gate, so a user with no such grant cannot sign in. Both template profiles hold it:
153
+
154
+ ```ts
155
+ export const managerProfile = declareAccessProfile({
156
+ definition: {
157
+ audience: "user",
158
+ capabilities: [
159
+ allow(accessGate(acmeApplication)),
160
+ allow(core.platform.knowledge),
161
+ allow(core.platform.agents),
162
+ allow(core.platform.workflows),
163
+ allow(leadCapabilitiesFqn, "manage"),
164
+ allow(opportunityCapabilitiesFqn, "manage")
165
+ ],
166
+ lifecycle: readonly
167
+ },
168
+ manifest: { fqn: "acme.app.profiles.manager", version: VERSION },
169
+ presentation: { displayName: "Sales manager" }
170
+ })
171
+ ```
172
+
173
+ The Identity Domain grants the entity capabilities by the FQN constants that `@packages/features-lead-model` and `@packages/features-opportunity-model` export. The Sales rep profile holds the same gate with `platform.knowledge`, `platform.agents` and `read` on Leads and Opportunities. It leaves out `platform.workflows` and `manage`.
174
+
175
+ The gate lets a user in. Max Privileges then limit what the app's user tokens may use, for every caller including tenant users:
176
+
177
+ ```ts
178
+ export const applicationTokens = declareAccessMaxPrivileges({
179
+ definition: {
180
+ appliesTo: { applicationTokens: acmeApplication },
181
+ capabilities: [
182
+ allow(core.platform.knowledge),
183
+ allow(core.platform.agents),
184
+ allow(core.platform.workflows),
185
+ allow(leadCapabilitiesFqn, "manage"),
186
+ allow(opportunityCapabilitiesFqn, "manage")
187
+ ],
188
+ lifecycle: readonly
189
+ },
190
+ manifest: { fqn: "acme.app.max-privileges.user-tokens", version: VERSION }
191
+ })
192
+ ```
193
+
194
+ > **Warning:** An app registered from the Dashboard or the CLI has no Max Privileges, so its
195
+ > user tokens can sign in and read no data at all. Declare the app in a package
196
+ > together with its Max Privileges when its tokens must read data.
197
+
198
+ Consent is a separate setting. `applicationConsent` (`inherit`, `ask` or `skip`) only decides whether the user sees an Allow and Deny panel. A user without a grant that holds the gate is refused under `skip` exactly as under `ask`. The [External apps](../develop/external-apps.md) page covers sign-in and consent in full.
199
+
200
+ ## API keys and service principals
201
+
202
+ A service principal is a non-human identity, declared with `servicePrincipal({ fqn, groups, name, version })`. It holds only the grants that name it with `grantee: { servicePrincipal }`. The template's `convertLeadRunner` is a service principal with no Groups. The convert-lead workflow selects it with `runIdentity: { mode: "service_principal", servicePrincipal: convertLeadRunnerFqn }`. In this mode, a production run that a person starts from Studio or the Dashboard, and a run that no person starts, act as `convertLeadRunner`. A call from the web app with a user's delegated token still acts as that user, so when a signed-in user clicks Convert, the run acts as that user. [AI primitives](../ai/index.md) lists every case.
203
+
204
+ An API key belongs to a service principal and is created with a Max Privileges template:
205
+
206
+ ```bash
207
+ ci api-keys upsert --principal <fqn> --name <name> --max-privileges <template-fqn>
208
+ ```
209
+
210
+ The template sets the ceiling, and the principal's grants decide what the key may do below it. A key without a template uses no capability, and no API key can manage API keys. CI shows the secret once.
211
+
212
+ > **Warning:** A run as a service principal asks no questions and decides no approvals. In an
213
+ > Agent run, tool approval gates do not stop it: CI approves the unattended call
214
+ > by default and records it without an actor. A workflow Approval node still
215
+ > pauses the run until a person decides, and that reviewer never becomes the
216
+ > run's identity. Plan for this before a demo drives an agent with an API key.
217
+
218
+ The template's server also reads Leads with the app's own Server Credential (the Read Port on the [External apps](../develop/external-apps.md) page). The package declares no `{ applicationServer }` grant for it, so an Organization admin must give the app server read access to Leads after install.
219
+
220
+ ## Hide in the UI, check on the server
221
+
222
+ The template checks every protected action three times, and no layer trusts the one above it:
223
+
224
+ ```mermaid
225
+ flowchart LR
226
+ Page["Page<br/>holds hides the button"] --> Route["BFF route<br/>403 without the requirement"]
227
+ Route --> CI["CI<br/>grants, Max Privileges, policies<br/>for the run and each record"]
228
+ ```
229
+
230
+ An Access Requirement is a serializable guard built from `requires`, `enters`, `allOf` and `anyOf`. A domain exports the requirement of each operation from its `ci` part, so the page and the route check the same value. On the server, `CiRuntime.access(cookie)` returns the app's slice of the user's capabilities, and `holds(slice, requirement)` checks one requirement against it. The browser SDK session holds no access data.
231
+
232
+ ```tsx
233
+ const CrmLeaf = async () => {
234
+ const access = await readSessionAccess()
235
+ return <CrmWorkspace canConvert={holds(access, convertLeadRequirement)} />
236
+ }
237
+ ```
238
+
239
+ The leaf reads request cookies, so it sits inside `<Suspense>`. Without a session, or when CI is down, the access slice is `null` and no gated control appears. When the user's access changes during a session, CI reports it on the realtime stream and `RealtimeProviders` refreshes the route, so the button appears or disappears without a reload.
240
+
241
+ Dashboard feature flags such as `organization_onboarding`, `knowledge_setup` and `apps_setup` belong to the hiding layer only. They remove Dashboard entry points and leave capabilities and server checks unchanged.
242
+
243
+ ## Worked example: Sales members can convert leads
244
+
245
+ The template's CRM page has a Convert action that starts the convert-lead workflow. Here is how to give it to every Sales member.
246
+
247
+ 1. Check what the template does today. `convertLeadRequirement` is `{ mode: "on", requires: "platform.workflows" }`. Only the Sales manager profile allows `core.platform.workflows`, so today only members of Sales managers see Convert and can run it. A member who is only in Sales gets no button, and the BFF route answers 403.
248
+ 2. Add `allow(core.platform.workflows)` to `repProfile` in the Identity Domain (`packages/products/acme/identity/ci`). The app's Max Privileges already allow `platform.workflows`, so they need no change. Bump `VERSION`, then build, publish, promote and install the package.
249
+ 3. Know who the run acts as. The BFF route starts the workflow with the signed-in user's delegated token, so the run acts as that user, with the user's current grants, and not as `convertLeadRunner`. The workflow's only node sets a run variable (`converted: true`) and writes no Lead record, so no Knowledge write policy takes part. Confirm it with one trial run as a rep before the demo.
250
+ 4. Sign in as a user who is only in Sales. The CRM page now shows Convert, and `POST /api/leads/:id/convert` answers `{ runId }`. In the Dashboard Check access tab, choose that user and `platform.workflows` to see which grant gives it. Allow up to 60 seconds after a grant change, or wait for the realtime access event to refresh the page.
251
+
252
+ For a one-off demo you can skip the package change. An Organization admin grants the Sales manager profile to a single user in the Dashboard, which creates a runtime grant. The package stays the source of truth for the Sales tree, so remove the runtime grant when the demo ends.
253
+
254
+ ## Debug and test access
255
+
256
+ To answer "why can or can't this user do this?", use the access check. It lists the principal's grants and how each one reaches it: directly, through a Group, or through an ancestor Group. For a capability, it names the grants that hold it. For one Knowledge record, it lists each policy of the schema and why the policy admits the record or not. You can reach the same check in three ways, and each one needs `admin.grants` at read. The built-in Organization admin and Organization operator profiles hold it, and the Studio user profile does not.
257
+
258
+ The short path for a person is the Dashboard. Open the Organization admin Access page and its Check access tab, then choose who and a capability or a Knowledge record. On a member's page, the Effective access tab lists every capability with a Why? or Why not? button that opens Check access with the member and the capability filled in.
259
+
260
+ From an MCP client, call the `explain_access` tool. Its `request` takes the principal, the target and, optionally, the credential whose Max Privileges CI must apply. On `/mcp`, name the Organization with `organization_id`; on `/mcp/o/<organizationId>` you can leave it out.
261
+
262
+ ```json
263
+ {
264
+ "name": "explain_access",
265
+ "arguments": {
266
+ "organization_id": "<organization id>",
267
+ "request": {
268
+ "principal": { "kind": "user", "userId": "<user id>" },
269
+ "target": {
270
+ "kind": "capability",
271
+ "code": "platform.workflows",
272
+ "mode": "on"
273
+ }
274
+ }
275
+ }
276
+ }
277
+ ```
278
+
279
+ From server code, call `ci.access.explain` in the server SDK with the same request. Add a `credential` of kind `application_token` to see the access through the app, after the Max Privileges cut:
280
+
281
+ ```ts
282
+ const why = await ci.access.explain({
283
+ organizationId,
284
+ principal: { kind: "user", userId },
285
+ target: { kind: "capability", code: "platform.workflows", mode: "on" },
286
+ credential: { kind: "application_token", applicationId }
287
+ })
288
+ // why.target.allowed and why.target.holders, why.grants with their path, why.cut
289
+ ```
290
+
291
+ The template's app server holds no grant with `admin.grants`, so this call answers 403 from the template's server as installed. Use the Dashboard or the MCP tool there.
292
+
293
+ When a user installed the package and still cannot sign in to the app, check three things in order. The user must be in Sales or Sales managers, the grant for that Group must hold the app gate, and the app's client secret must have been rotated with `ci apps rotate-secret <application-id>`. Install adds no members to the Groups and does not rotate the secret. A package that declares grants also needs an install with a user's management token, because a system install fails with `installer_required`.
294
+
295
+ You can test policies and profiles without a running CI. `accessTest` from `@collective-intelligence/extensions-sdk-backend` loads your packages and answers questions as a given user:
296
+
297
+ ```ts
298
+ const check = accessTest([orgPackage, hrPackage], { corePolicies, entities })
299
+
300
+ check.as({ user, grants }).canRead(schema, record)
301
+ check.as({ user, grants }).holds(requirement)
302
+ ```
303
+
304
+ The same object offers `.read(...)` for the masked record, `.canUpdate(...)` and `check.conditionTests()` for the built-in condition tests.
305
+
306
+ ## Related pages
307
+
308
+ - [External apps](../develop/external-apps.md)
309
+ - [Knowledge](../data/knowledge.md)
310
+ - [Extensions](../develop/extensions.md)
311
+ - [The template](../template/index.md)
@@ -0,0 +1,166 @@
1
+ # Platform architecture
2
+
3
+ The parts of Collective Intelligence, the three integration models, and how a package moves from build to install.
4
+
5
+ A customer solution built on Collective Intelligence (CI) usually produces two artifacts and points both at a CI deployment that already runs. The first is an extension package that CI installs into an Organization. The second is a web app that runs on your own host and calls CI. Your team does not run the backend, its workers, Compute, Media, the Dashboard or Studio; the CI deployment provides all of them.
6
+
7
+ ## Tenant and Organization
8
+
9
+ A tenant is one CI deployment and its top-level security boundary, so each CI deployment has exactly one tenant. An Organization is a data and access partition inside a tenant, and each Organization belongs to one tenant. The customer is almost always an Organization inside an existing tenant. Do not use "tenant" as another word for the customer.
10
+
11
+ Platform-wide choices live at tenant scope: tenant users, oversight of Organizations, feature flags, AI model availability and defaults, maintenance and monitoring. Most of what a customer solution touches lives at Organization scope: users and Groups, installed packages, connector instances, Knowledge, tools, Skills, workflows and Studio apps.
12
+
13
+ The Organizations of one tenant share the CI deployment: its processes, its core database, its queues and, by default, its file storage. CI keeps their data apart by Organization. Every record, file and job of an Organization carries its Organization, and the backend checks that Organization on each operation. Some stores also give each Organization its own storage area. Managed Datasets live in a separate database with one schema per Organization, and the vectors that search uses sit in one partition per Organization. Files get one storage prefix per Organization, and a Tenant admin can point an Organization at its own bucket or container.
14
+
15
+ Each scope has its own admin. A Tenant admin runs the CI deployment: the Tenant admin creates Organizations, manages tenant users, AI models and the file storage of each Organization, and turns feature flags on per Organization. CI gives a Tenant admin the tenant profile in every Organization, so a Tenant admin can also configure any Organization. An Organization admin runs one Organization: the Organization admin installs packages, invites users, adds them to Groups and grants them any Access Profile except the tenant profiles. An account with a tenant role is never a member of an Organization, and a member of an Organization never holds a tenant role. [Access](access.md) explains Access Profiles and Access Grants.
16
+
17
+ CI never infers either scope. Code installed inside CI receives the tenant and Organization from CI on each call. An external application names the tenant URL in its configuration and the Organization in each data operation.
18
+
19
+ ## Surfaces
20
+
21
+ | Surface | Who uses it | What it does |
22
+ | ------------------------- | ---------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
23
+ | Dashboard | Organization admins, and Tenant admins for the tenant area | Configures the Organization: users, Groups, access, packages, connectors, Knowledge schemas, agents, Skills, tools, workflows, external applications and MCP. Its tenant area configures the CI deployment: tenant users, Organizations, AI models, Studio releases, maintenance and monitoring. |
24
+ | [Studio](../ai/studio.md) | End users | Desktop app where people chat with agents, open Studio apps, fill agent forms and read Documents. Each Organization has an install page with a Connect Studio button, so nobody types a backend URL. |
25
+ | Backend API | Dashboard, Studio, CLI, your app | Serves every HTTP route. Its OpenAPI document is the authority that the SDKs and the CLI are generated from. |
26
+ | Workers | The backend | Background workers run long jobs, and interactive workers run the agent and tool work that users wait for. |
27
+ | Compute | The backend | Runs transcription, transcoding and conversion from a queue. Each capability has its own slots, so a long transcode does not block transcription. |
28
+ | Media | Browsers | Serves file bytes and image transforms from URLs that the backend signs. No file byte passes through a backend endpoint. |
29
+
30
+ Your code never calls Compute. For files, the backend decides who can see each one and signs its URL, and Media only checks the signature. A principal can fetch a file if, and only if, it can see the item the file is attached to. [Infrastructure](../develop/infrastructure.md) lists the runtime resources behind these surfaces and the deployment blueprints.
31
+
32
+ > **Note:** Some Dashboard areas, such as Organization onboarding, Knowledge setup and
33
+ > apps setup, start disabled. A Tenant admin turns them on per Organization with
34
+ > feature flags. If an Organization lacks a menu item, check the tenant feature
35
+ > flags first.
36
+
37
+ ## Three ways to integrate
38
+
39
+ CI supports three integration models, and none of them depends on another.
40
+
41
+ ```mermaid
42
+ flowchart LR
43
+ subgraph tenant["CI tenant (one deployment)"]
44
+ dashboard["Dashboard"]
45
+ studio["Studio"]
46
+ api["Backend API"]
47
+ workers["Workers"]
48
+ compute["Compute"]
49
+ media["Media"]
50
+ subgraph org["Organization"]
51
+ pkg["Installed extension package"]
52
+ end
53
+ dashboard --> api
54
+ studio --> api
55
+ api --> workers
56
+ api --> compute
57
+ api --- pkg
58
+ end
59
+ webapp["Your web app (BFF)"] -->|"Application API"| api
60
+ api -->|"signed calls"| gateway["Your Gateway"]
61
+ browser["Browser"] -->|"signed URLs"| media
62
+ ```
63
+
64
+ The first model installs code inside CI. An extension package declares schemas, Groups, access, agents, Skills, tools, workflows and Studio apps, and it can add React widgets to Studio and the Dashboard. CI runs this code in its own hosts and gives it the current tenant and Organization on each call. See [Extensions](../develop/extensions.md).
65
+
66
+ The second model is an external application: software your team hosts that calls CI over HTTP. The template's web app is one. A server-side BFF holds the app's confidential credentials, signs users in with their CI identity and calls the Application API. See [External apps](../develop/external-apps.md).
67
+
68
+ In the third model, CI calls your server. A Gateway, installed in your server with the server SDK, exposes your own resources, datasets and business operations to CI. Your application keeps its database, its business rules and its user sessions, and CI can import your resources into Knowledge, query your datasets and call your operations as tools.
69
+
70
+ Choose the direction by asking who owns the records. When CI owns them, as with the template's Leads that people edit from Studio and from the web app, call CI from your app. When your app's database stays the source of truth and CI must read or act on it, expose the data through a Gateway. The template uses only the outbound direction and needs no Gateway connection to run.
71
+
72
+ ## Packages
73
+
74
+ A package in CI distributes platform capabilities, and code is only one part of it. One package can carry Knowledge domains and schemas, connectors, tools, Skills, agents, workflows, Studio apps and widgets, Groups, Access Profiles and external application registrations. A customer solution package usually holds the shared pieces for one Organization's initiative. One package per Organization is a convention, and CI does not enforce it.
75
+
76
+ CI's own built-in features ship as packages with the same manifest, bundle and runtime contracts, so a customer solution package uses the same mechanism as the platform's core packages.
77
+
78
+ Items that a package declares belong to the package installation. A Declared Studio App, for example, is read-only in the Studio builder and changes only when you deploy a new release of its package. Ordinary saves in the Dashboard never install or change packages.
79
+
80
+ Each declared item sets a lifecycle with two fields. With `deployMode: "upsert"`, every deploy writes the declared state again, so a Dashboard edit returns to the declared value on the next deploy. With `deployMode: "init_only"`, CI creates the item when it is absent and keeps later edits. With `readonly: true`, the Dashboard shows the item and refuses edits, and it tells the user to update the package instead. Where possible, declare items with `{ deployMode: "upsert", readonly: true }` and use the Dashboard only to view them. The package then stays the one source of the Organization's setup, and a deploy to a new Organization creates the same setup. CI declares its own built-in Access Profiles this way. Use `init_only` with `readonly: false` only for an item that an Organization admin must change after install. The template does this for the grant to its Sales reps and for its convert-lead workflow.
81
+
82
+ Some setup stays outside a package. A package declares Groups but never their members, and it creates no Organization memberships, so an Organization admin adds users after install. A Tenant admin creates the Organization itself. If you need to configure something that a package cannot declare yet, ask the Collective team to add the declaration, and avoid configuring it by hand in the Dashboard.
83
+
84
+ ### Package lifecycle
85
+
86
+ ```mermaid
87
+ flowchart LR
88
+ declare["Declarations in TypeScript"] --> build["ci package build"]
89
+ build --> archive["Immutable archive and release manifest"]
90
+ archive --> validate["Validate"]
91
+ validate --> publish["Publish"]
92
+ publish --> promote["Promote"]
93
+ promote --> install["Install or update in one Organization"]
94
+ install --> desired["Desired release"]
95
+ desired -->|"prepared on every host"| serving["Serving release"]
96
+ desired -.->|"preparation fails"| previous["Previous release keeps serving"]
97
+ ```
98
+
99
+ Each published version is an immutable release. Installing or updating a package in an Organization selects a desired release, and CI then prepares it on every host that needs it: the backend, the Dashboard and Studio. The serving release changes only when every host is ready. If preparation fails, the previous compatible release continues to serve. Backend code and React widgets from one release always move together and cannot drift to different versions.
100
+
101
+ Rollback selects an earlier release through the same lifecycle checks. It does not restore records, and it does not write inverse changes to definitions.
102
+
103
+ The CLI and the Dashboard reach the same backend operation for each package action. The CLI also has `ci deploy`, which publishes the release only when it is absent, promotes it only when needed, and then installs or updates it. Copying a package archive somewhere gives it no authority; only an installation makes a package active in an Organization.
104
+
105
+ ## How the template maps onto CI
106
+
107
+ The `next-effect-app` template has two composition roots, one for each side of the boundary.
108
+
109
+ | Folder | Runs where | SDKs | Reaches CI by |
110
+ | ----------------- | ---------------------------------------- | ----------------------------------------------------------------------------------------- | ------------------------------------------------ |
111
+ | `apps/extensions` | Inside CI, installed in the Organization | `extensions-sdk`, `extensions-sdk-backend`, `extensions-sdk-frontend-react`, `ui-react` | `ci package build`, publish, promote and install |
112
+ | `apps/web` | Your host, as a Next.js app | `external-apps-server-sdk` on the server, `external-apps-client-sdk-react` in the browser | The BFF calls the Application API |
113
+
114
+ The package root in `apps/extensions` is short. It lists the Identity Domain components and the components of each domain's `ci` part in deploy order, with the Lead score card widget for Studio:
115
+
116
+ ```ts
117
+ export default declarePackage({
118
+ components: [
119
+ crmDomain,
120
+ ...leadComponents({ domain: crmDomain, version: VERSION }),
121
+ ...opportunityComponents({ domain: crmDomain, version: VERSION }),
122
+ ...identityComponents,
123
+ ...convertLeadComponents({
124
+ application: acmeApplication,
125
+ version: VERSION
126
+ }),
127
+ ...leadQualificationComponents({
128
+ application: acmeApplication,
129
+ audience: salesMembers,
130
+ version: VERSION
131
+ }),
132
+ salesDeskApp
133
+ ],
134
+ hostedContributions: [
135
+ declareFrontendCatalogContribution({
136
+ compatibility: { react: "^19.0.0" },
137
+ fqn: leadScoreCardContributionFqn,
138
+ host: "studio",
139
+ load: async () => await import("./studio")
140
+ })
141
+ ],
142
+ manifest: packageManifest
143
+ })
144
+ ```
145
+
146
+ When installed, that package creates the CRM domain with the Lead and Opportunity schemas, the Sales Groups and their access, the app registration, the convert-lead workflow, the lead qualifier agent, the Sales desk Studio app and the widget. The web app has no database of its own. Users sign in with their CI identity, Leads and Opportunities live in CI Knowledge, and lead conversion runs as a CI workflow.
147
+
148
+ > **Warning:** The web app serves two route families that start with `/api`. The `/api/app/*`
149
+ > routes are the app's own HTTP API, merged from its packages. The `/api/*`
150
+ > routes are the BFF that forwards to CI. The browser calls only these
151
+ > same-origin routes and never holds the client secret.
152
+
153
+ The Overview and Lead intake pages of the template work with no CI at all, because intake data stays in memory. Only the CRM pages need a connected tenant.
154
+
155
+ ## Where data lives
156
+
157
+ CI has three kinds of Data resources: Knowledge holds durable business records that follow declared schemas, Datasets hold typed, high-volume records, and Documents holds files in Document Collections. The [Data resources overview](../data/index.md) compares them, and [Knowledge](../data/knowledge.md), [Datasets](../data/datasets.md), [Documents](../data/documents.md) and [Connectors](../data/connectors.md) give the details.
158
+
159
+ ## Next pages
160
+
161
+ - [Entrypoints](entrypoints.md): How people, apps and agents reach CI, and what your code imports.
162
+ - [Access](access.md): Access Profiles, Access Grants and Max Privileges.
163
+ - [Extensions](../develop/extensions.md): Write the package that CI installs.
164
+ - [External apps](../develop/external-apps.md): Build the web app that calls CI.
165
+ - [Infrastructure](../develop/infrastructure.md): The runtime resources of a CI deployment and its deployment blueprints.
166
+ - [Template](../template/index.md): Start from the `next-effect-app` template.