@collective-intelligence/external-apps-client-sdk-react 0.11.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.
- package/AGENTS.md +42 -20
- package/README.md +77 -72
- package/dist/effect.d.ts +1 -67
- package/dist/effect.js +1 -1
- package/dist/index-0k92txne.js +2 -0
- package/dist/index-7r4n344n.js +2 -0
- package/dist/index-h4fpzytm.js +2 -0
- package/dist/index-v7pbmwry.js +2 -0
- package/dist/index-ycckwta5.js +2 -0
- package/dist/index.d.ts +18 -8
- package/dist/index.js +1 -1
- package/dist/realtime.d.ts +11 -8
- package/dist/realtime.js +1 -1
- package/dist/records.d.ts +322 -0
- package/dist/records.js +2 -0
- package/dist/records.server.d.ts +155 -0
- package/dist/records.server.js +1 -0
- package/dist/resources.d.ts +13 -10
- package/dist/resources.js +1 -1
- package/docs/effect.md +6 -96
- package/docs/errors.md +14 -14
- package/docs/guide/ai/index.md +1 -1
- package/docs/guide/develop/sdks.md +34 -16
- package/docs/guide/platform/entrypoints.md +13 -11
- package/docs/realtime.md +14 -10
- package/docs/record-collections.md +277 -0
- package/docs/tanstack-skills.md +73 -0
- package/package.json +28 -8
- package/skills/client-sdk-react-move-to-record-collections/SKILL.md +62 -0
- package/skills/client-sdk-react-record-collections/SKILL.md +49 -0
- package/skills/client-sdk-react-tanstack-db-ssr/SKILL.md +52 -0
- package/dist/index-5t792h25.js +0 -2
- package/dist/index-ktw8msmm.js +0 -2
package/docs/effect.md
CHANGED
|
@@ -108,105 +108,15 @@ const LeadEditor = ({ id }: { id: string }) => {
|
|
|
108
108
|
|
|
109
109
|
### Optimistic write
|
|
110
110
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
call order at once, so a second quick write shows while CI has not
|
|
118
|
-
answered the first. An entry without a value shows no edit until a fetch
|
|
119
|
-
gives it one.
|
|
120
|
-
- **Order.** The writes to one key go to CI one at a time, in call order.
|
|
121
|
-
When CI gets a write, the running fetch of the key is cancelled.
|
|
122
|
-
- **Fetches.** A fetch that ends while writes are pending, for example after
|
|
123
|
-
a realtime change or a window focus, updates the confirmed value, and the
|
|
124
|
-
layers show over it again. Thus an edit must give the same value for a
|
|
125
|
-
value that already holds it: set fields, or replace or remove a row by its
|
|
126
|
-
id. To add a row, skip the add when the row is there.
|
|
127
|
-
- **Send-time payload.** Give `write` as a function to build the payload when
|
|
128
|
-
CI gets the write. It gets `{ confirmed, optimistic }`: the confirmed value
|
|
129
|
-
with the answers of the writes before it, and that value with this edit
|
|
130
|
-
only. A refused write before it is not in either value.
|
|
131
|
-
- **Answer.** When CI confirms the write, its layer goes, and the confirmed
|
|
132
|
-
value becomes `options.confirm(result, confirmed)`, for example CI's row
|
|
133
|
-
with its new revision. Without `confirm`, or when it gives `undefined`, the
|
|
134
|
-
confirmed value gets the edit. When `write` fails, is interrupted or dies,
|
|
135
|
-
only its own layer goes; the other layers show over the confirmed value.
|
|
136
|
-
When `confirm` throws, the write dies with its error, the confirmed value
|
|
137
|
-
stays, and its layer still goes. When the write ends, the key is
|
|
138
|
-
invalidated, so views read CI's value.
|
|
139
|
-
- **Other members.** A value that `setData`, `update` or `remove` puts while
|
|
140
|
-
writes are pending stays. The edits before it no longer show or roll back,
|
|
141
|
-
and their `confirm` does not run, so an older answer of CI never replaces
|
|
142
|
-
the newer value.
|
|
143
|
-
- **Runs.** Each run of the effect that `optimisticUpdate` returns is one
|
|
144
|
-
write with its own layer, so an actor can run one save effect twice.
|
|
145
|
-
- **Pending.** `pending(queryKey)` gives the number of optimistic writes of
|
|
146
|
-
the key that wait for CI or run, for example to show "Saving…".
|
|
147
|
-
|
|
148
|
-
The writes of one key share their layers across every `QueryCache` over the
|
|
149
|
-
same QueryClient. The QueryClient holds them, so two bundled copies of the
|
|
150
|
-
SDK over it, such as the app's and a library's, also share them. Copies of
|
|
151
|
-
releases with another layout of these writes keep their own. A write that changes several keys does the steps itself:
|
|
111
|
+
`QueryCache` has no optimistic write. An optimistic write of a CI record is
|
|
112
|
+
a Record Collection transaction: write it with the entity hooks
|
|
113
|
+
([record-collections.md](record-collections.md)). TanStack DB shows the write
|
|
114
|
+
at once, writes to one record go to CI one at a time, and a refused write
|
|
115
|
+
rolls back only its own change. A write that changes other keys of
|
|
116
|
+
`QueryCache` does the steps itself:
|
|
152
117
|
`cancel` the keys, `update` them, run the write, and `invalidate` the keys
|
|
153
118
|
when the actor ends.
|
|
154
119
|
|
|
155
|
-
```ts
|
|
156
|
-
type Task = Readonly<{
|
|
157
|
-
done: boolean
|
|
158
|
-
id: string
|
|
159
|
-
revision: string
|
|
160
|
-
title: string
|
|
161
|
-
}>
|
|
162
|
-
const tasksKey = ["portal", "tasks"]
|
|
163
|
-
|
|
164
|
-
const saveTask = fromEffect(
|
|
165
|
-
(
|
|
166
|
-
input: Readonly<{
|
|
167
|
-
patch: Partial<Pick<Task, "done" | "title">>
|
|
168
|
-
id: string
|
|
169
|
-
runtime: EffectRunner<QueryCache>
|
|
170
|
-
}>
|
|
171
|
-
) =>
|
|
172
|
-
QueryCache.use((cache) =>
|
|
173
|
-
cache.optimisticUpdate(
|
|
174
|
-
tasksKey,
|
|
175
|
-
// Replaces the row by its id, so a fetch under the layer keeps it.
|
|
176
|
-
(tasks: readonly Task[]) =>
|
|
177
|
-
tasks.map((task) =>
|
|
178
|
-
task.id === input.id ? { ...task, ...input.patch } : task
|
|
179
|
-
),
|
|
180
|
-
// Built when CI gets the save: the revision of the save before it,
|
|
181
|
-
// and no change of a refused save.
|
|
182
|
-
({ optimistic }) => {
|
|
183
|
-
const task = optimistic?.find(({ id }) => id === input.id)
|
|
184
|
-
return task === undefined
|
|
185
|
-
? Effect.die("no task")
|
|
186
|
-
: writeTask(input.id, {
|
|
187
|
-
done: task.done,
|
|
188
|
-
revision: task.revision,
|
|
189
|
-
title: task.title
|
|
190
|
-
})
|
|
191
|
-
},
|
|
192
|
-
// `writeTask` answers CI's row with its new revision.
|
|
193
|
-
{
|
|
194
|
-
confirm: (row: Task, confirmed) =>
|
|
195
|
-
confirmed?.map((task) => (task.id === row.id ? row : task))
|
|
196
|
-
}
|
|
197
|
-
)
|
|
198
|
-
)
|
|
199
|
-
)
|
|
200
|
-
|
|
201
|
-
const savingTasks = fromEffect(
|
|
202
|
-
(input: Readonly<{ runtime: EffectRunner<QueryCache> }>) =>
|
|
203
|
-
QueryCache.use((cache) => cache.pending(tasksKey))
|
|
204
|
-
)
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
A `write` given as an Effect works as before: it is the same for each
|
|
208
|
-
confirmed value.
|
|
209
|
-
|
|
210
120
|
## Rules
|
|
211
121
|
|
|
212
122
|
- Make each side-effect actor with `fromEffect`. The
|
package/docs/errors.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Errors and
|
|
1
|
+
# Errors and rolled-back writes
|
|
2
2
|
|
|
3
3
|
Entity reads and writes run on the Effect Core of the client SDK. Their
|
|
4
4
|
errors stay values; other client SDK calls follow the client SDK error model
|
|
@@ -11,29 +11,29 @@ error. Reads never retry by themselves; call `refresh` on a user request.
|
|
|
11
11
|
|
|
12
12
|
## Entity writes
|
|
13
13
|
|
|
14
|
-
Entity writes are
|
|
15
|
-
|
|
14
|
+
Entity writes are Record Collection transactions
|
|
15
|
+
([record-collections.md](record-collections.md)).
|
|
16
16
|
|
|
17
|
-
| Outcome
|
|
18
|
-
|
|
|
19
|
-
| Pending
|
|
20
|
-
|
|
|
21
|
-
|
|
|
22
|
-
| Failure or interruption | The value from before the write, when the view still shows the write's value |
|
|
17
|
+
| Outcome | Record Collection of the record | Entity reads |
|
|
18
|
+
| ----------------------- | ---------------------------------------- | --------------------------------------------------------- |
|
|
19
|
+
| Pending | The new value; a delete hides the row | CI's record |
|
|
20
|
+
| Success | CI's confirmed row, with no flicker back | CI's record; each read of the resource reads CI once more |
|
|
21
|
+
| Failure or interruption | Only this write's change rolls back | CI's record |
|
|
23
22
|
|
|
24
23
|
- `status` of a write is `idle`, `pending`, `success`, `conflict`, `rejected`
|
|
25
|
-
or `uncertain`. A write
|
|
24
|
+
or `uncertain`. A write whose answer is lost is sent again with its key for
|
|
25
|
+
up to 60 seconds; it is `uncertain` only after that.
|
|
26
26
|
- `submit` makes a new action; `resubmit` sends the same action again, with
|
|
27
27
|
its key, values and revision. Call `resubmit` only on a user request.
|
|
28
|
-
-
|
|
29
|
-
|
|
28
|
+
- `optimistic: false` in the target has no effect: every write shows at once
|
|
29
|
+
in its Record Collection.
|
|
30
30
|
- Writes to one record run one at a time, in call order.
|
|
31
31
|
|
|
32
32
|
## `onWriteFailed`
|
|
33
33
|
|
|
34
34
|
`onWriteFailed` on `CollectiveIntelligenceProvider` gets a `WriteFailed` for
|
|
35
|
-
each entity write that CI refuses or that does not reach CI, after the
|
|
36
|
-
|
|
35
|
+
each entity write that CI refuses or that does not reach CI, after the
|
|
36
|
+
Record Collection rolled the write back. It is not called for an interruption, or when the entity source
|
|
37
37
|
changed during the write.
|
|
38
38
|
|
|
39
39
|
- `error` is a `CiError` (CI refused) or a `CiTransportError` (the request did
|
package/docs/guide/ai/index.md
CHANGED
|
@@ -226,7 +226,7 @@ Your server invokes an Agent with `agents.invoke({ agentId, input })`, which ret
|
|
|
226
226
|
|
|
227
227
|
For a multi-turn chat, use the shared chat. Start a Conversation with the Agent with `ci.chat.createConversation({ organizationId, payload: { agentId } })`, send each message with `createChatClient(ci, { organizationId }).send({ conversationId, message })` from `@collective-intelligence/external-apps-server-sdk/chat`, and read earlier turns with `ci.chat.getTranscript`. Each turn is an ordinary Agent run, and the earlier successful turns, with their saved Agent Output, become the model's conversation history. A message sent while a turn still runs steers that turn and starts no second turn, and a resend with the same message `id` adds nothing.
|
|
228
228
|
|
|
229
|
-
`send` resolves `{ ok: true, value, runId }`: `runId` is the id of the turn's run, which the answer message also carries as `metadata.invocationId`, and `turnRunId(message)` reads it from any answer message. `runs.get`, `runs.sources` and `runs.feedback` accept that id like the `runId` of `agents.invoke`. They answer only the caller that owns the Conversation (the member, the app server or the visitor) through the application where the Conversation started, and answer `not_found` to every other caller. As for any run, only a signed-in member reads `runs.sources` and gives `runs.feedback`. `runs.get` gives the status and `result: { message, output? }`, where `output` is the Agent Output that the turn saved. `runs.feedback` also rates a succeeded turn whose answer is only its Agent Output, with the Output's JSON text as the rated answer; a turn with neither text nor Output has no answer to rate and gets `not_found`. The member can also rate and clear the answer with `ci.chat.putAnswerFeedback` and `ci.chat.clearAnswerFeedback` (`params: { invocationId: runId }`); it is the same rating. Each completed Agent turn with an answer to rate (its text or its Agent Output) of `ci.chat.getTranscript` gives that member `feedbackTargetId` (the turn's run id) and `currentUserFeedback`, so the app shows a saved rating again after a reload. `runs.sources` gives the searched Document Versions with their pages and a download link. `runs.stream`
|
|
229
|
+
`send` resolves `{ ok: true, value, runId }`: `runId` is the id of the turn's run, which the answer message also carries as `metadata.invocationId`, and `turnRunId(message)` reads it from any answer message. `runs.get`, `runs.stream`, `runs.cancel`, `runs.sources` and `runs.feedback` accept that id like the `runId` of `agents.invoke`. They answer only the caller that owns the Conversation (the member, the app server or the visitor) through the application where the Conversation started, and answer `not_found` to every other caller. As for any run, only a signed-in member reads `runs.sources` and gives `runs.feedback`. `runs.get` gives the status and `result: { message, output? }`, where `output` is the Agent Output that the turn saved. `runs.feedback` also rates a succeeded turn whose answer is only its Agent Output, with the Output's JSON text as the rated answer; a turn with neither text nor Output has no answer to rate and gets `not_found`. The member can also rate and clear the answer with `ci.chat.putAnswerFeedback` and `ci.chat.clearAnswerFeedback` (`params: { invocationId: runId }`); it is the same rating. Each completed Agent turn with an answer to rate (its text or its Agent Output) of `ci.chat.getTranscript` gives that member `feedbackTargetId` (the turn's run id) and `currentUserFeedback`, so the app shows a saved rating again after a reload. `runs.sources` gives the searched Document Versions with their pages and a download link. `runs.stream` pages the turn's events as for `agents.invoke`: `accepted`, the `agent.*` events and the application events that its tools publish, then one terminal event with the `runs.get` result. `runs.cancel` stops the turn. The answer itself streams from `GET /runs/:runId/stream` of the chat mount.
|
|
230
230
|
|
|
231
231
|
Anonymous visitors can chat with an Agent only when its audience has `anonymous: [app]` for that application and the call passes `caller: { kind: "anonymous_visitor", visitor: { issuer, subjectId } }`. Their turns run with the Agent's own bindings, never with the application's grants, and visitors never see each other's conversations.
|
|
232
232
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Which @collective-intelligence package to import, from which subpath, with which Effect setup and which versions.
|
|
4
4
|
|
|
5
|
-
The SDK family splits by where your code runs. Code that you install into CI as part of a package uses the `@collective-intelligence/extensions-sdk*` packages. Code that you host yourself, such as a Next.js web app and its BFF, uses the `@collective-intelligence/external-apps-*` packages.
|
|
5
|
+
The SDK family splits by where your code runs. Code that you install into CI as part of a package uses the `@collective-intelligence/extensions-sdk*` packages. Code that you host yourself, such as a Next.js web app and its BFF, uses the `@collective-intelligence/external-apps-*` packages. A self-hosted content system, such as a Payload Site, uses a CMS SDK of that family.
|
|
6
6
|
|
|
7
7
|
The template keeps the families apart. Package code imports only `extensions-sdk*` and `ui-react`, browser code imports the client SDK, and confidential server code imports the server SDK.
|
|
8
8
|
|
|
@@ -38,19 +38,21 @@ The right side is `apps/web`. Its browser code talks to its own server through a
|
|
|
38
38
|
|
|
39
39
|
## The packages
|
|
40
40
|
|
|
41
|
-
| Package
|
|
42
|
-
|
|
|
43
|
-
| `@collective-intelligence/extensions-sdk`
|
|
44
|
-
| `@collective-intelligence/extensions-sdk-backend`
|
|
45
|
-
| `@collective-intelligence/extensions-sdk-frontend`
|
|
46
|
-
| `@collective-intelligence/extensions-sdk-frontend-react`
|
|
47
|
-
| `@collective-intelligence/external-apps-client-sdk`
|
|
48
|
-
| `@collective-intelligence/external-apps-client-sdk-react`
|
|
49
|
-
| `@collective-intelligence/external-apps-server-sdk`
|
|
50
|
-
| `@collective-intelligence/
|
|
51
|
-
| `@collective-intelligence/
|
|
52
|
-
| `@collective-intelligence/
|
|
53
|
-
| `@collective-intelligence/
|
|
41
|
+
| Package | Runs where | Main subpaths | Use it for |
|
|
42
|
+
| ----------------------------------------------------------- | ------------------------------- | --------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
|
|
43
|
+
| `@collective-intelligence/extensions-sdk` | Package build | `.`, `/effect` (empty) | Declare the package and its components with `declarePackage` and the other `declare*` functions |
|
|
44
|
+
| `@collective-intelligence/extensions-sdk-backend` | Inside CI, backend | `.`, `/effect` | Implement the code that tools, connectors and dataset providers run |
|
|
45
|
+
| `@collective-intelligence/extensions-sdk-frontend` | Inside CI, Studio and Dashboard | `.`, `/effect` (empty) | Declare the frontend catalog that a Host loads through `loadFrontendCatalog` |
|
|
46
|
+
| `@collective-intelligence/extensions-sdk-frontend-react` | Inside CI, Studio and Dashboard | `/studio`, `/studio-api`, `/dashboard`, `/workflow`, `/ui-react`, `/effect` | Write the React code of a Studio widget or Dashboard contribution |
|
|
47
|
+
| `@collective-intelligence/external-apps-client-sdk` | Your app, browser | `.`, `/resources`, `/effect` | Sign users in with CI and call CI operations without React |
|
|
48
|
+
| `@collective-intelligence/external-apps-client-sdk-react` | Your app, browser | `.`, `/resources`, `/effect` | Providers and entity hooks that read and write CI records |
|
|
49
|
+
| `@collective-intelligence/external-apps-server-sdk` | Your app, server only | `.`, `/auth/federated`, `/effect`, `/next`, `/admin` | BFF routes, sign-in and confidential calls to CI |
|
|
50
|
+
| `@collective-intelligence/external-apps-server-sdk-payload` | Your Payload Site, server only | `.`, `/package`, `/ci-generate` | Connect a Payload Site to CI: the Payload Plugin, and helpers for the site's CI package |
|
|
51
|
+
| `@collective-intelligence/external-apps-server-sdk-strapi` | Your Strapi 5 site, server only | `.` | Serve the documents of a Strapi 5 site to CI through a Gateway |
|
|
52
|
+
| `@collective-intelligence/ui-react` | Both sides | `/ui`, `/resources`, `/icons`, `/hooks`, `/tokens/theme` | CI design-system components that take display-ready props |
|
|
53
|
+
| `@collective-intelligence/cli` | Your machine or pipeline | `ci` binary | Sign in, build and deploy packages, enroll an app |
|
|
54
|
+
| `@collective-intelligence/lint` | Development | `recommended` | Oxlint rules that keep the solution layout and Effect imports correct |
|
|
55
|
+
| `@collective-intelligence/schema-codegen` | Development | `.` | Generate TypeScript, Zod or Effect Schema source from package schemas |
|
|
54
56
|
|
|
55
57
|
You rarely import `schema-codegen` yourself, because `ci package codegen --target zod|effect|types` calls it for you. Generated schemas describe the wire shape only, and the CI backend still validates every payload.
|
|
56
58
|
|
|
@@ -154,9 +156,22 @@ handlers: createExternalApplicationBffNextHandlers({
|
|
|
154
156
|
|
|
155
157
|
[External apps](external-apps.md) covers sign-in, the BFF and fixed workflow routes in detail.
|
|
156
158
|
|
|
159
|
+
### CMS SDKs for a self-hosted content system
|
|
160
|
+
|
|
161
|
+
A CMS SDK connects a self-hosted content system to CI. It serves the site's content through a Gateway, and CI reads it with its one built-in Knowledge Gateway connector, so CI needs no code for your content system. A CMS SDK depends on `external-apps-server-sdk` at the exact same version: install no other server SDK version next to it.
|
|
162
|
+
|
|
163
|
+
| Package | Subpath | What you get |
|
|
164
|
+
| ---------------------------------- | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
165
|
+
| `external-apps-server-sdk-payload` | `.` | `ciPayloadPlugin`, the Payload Plugin that serves the chosen collections and pushes each change |
|
|
166
|
+
| `external-apps-server-sdk-payload` | `/package` | The Payload Package Helpers `payloadGateway`, `payloadKnowledge`, `payloadGatewayPushGrant`, `payloadPageEditor`, `payloadPackageDependencies` and `payloadOperationContract`, for the site's CI package; it loads no Payload module |
|
|
167
|
+
| `external-apps-server-sdk-payload` | `/ci-generate` | The `payload ci-generate` command that the plugin adds; Payload loads it, so you do not import it |
|
|
168
|
+
| `external-apps-server-sdk-strapi` | `.` | `defineStrapiSource` and `defineStrapiGatewayPlugin`, which turn a Strapi Document Service into a Gateway resource |
|
|
169
|
+
|
|
170
|
+
The Payload SDK takes `extensions-sdk` as a peer at the exact version, so the helpers and your CI package share one copy. A hosted service, such as Notion, needs no CMS SDK: CI connects it with a built-in integration package.
|
|
171
|
+
|
|
157
172
|
## Effect
|
|
158
173
|
|
|
159
|
-
`effect` `^4.1.0` is a required peer of `extensions-sdk`, `extensions-sdk-backend`, both frontend extension packages and the
|
|
174
|
+
`effect` `^4.1.0` is a required peer of `extensions-sdk`, `extensions-sdk-backend`, both frontend extension packages, the client SDK, the client React SDK, the server SDK and the Payload SDK. The Strapi SDK needs it through the server SDK. The SDKs do not bundle it, so install it in your app and keep one version across the workspace.
|
|
160
175
|
|
|
161
176
|
Effect APIs always come from a `/effect` subpath, and the lint rule `effect-subpath` reports an Effect import from anywhere else.
|
|
162
177
|
|
|
@@ -206,7 +221,8 @@ Some names from older examples no longer exist. An old server SDK subpath fails
|
|
|
206
221
|
| `external-apps-server-sdk/runtime/effect` | `external-apps-server-sdk/effect` |
|
|
207
222
|
| `external-apps-server-sdk/persistence/drizzle/effect` | `external-apps-server-sdk/effect` plus `/effect/node-postgres` |
|
|
208
223
|
| `external-apps-server-sdk/runtime/next` | `external-apps-server-sdk/next` |
|
|
209
|
-
| `external-apps-server-sdk/knowledge-sources/payload` | `ciPayloadPlugin` from `external-apps-server-sdk
|
|
224
|
+
| `external-apps-server-sdk/knowledge-sources/payload` | `ciPayloadPlugin` from `external-apps-server-sdk-payload`, which serves the site's collections as a Gateway |
|
|
225
|
+
| `external-apps-server-sdk/knowledge-sources/strapi` | `external-apps-server-sdk-strapi`; take the resource types from `external-apps-server-sdk/resources` |
|
|
210
226
|
|
|
211
227
|
The two removed packages stopped at version 0.2.0, and npm marks them deprecated.
|
|
212
228
|
|
|
@@ -219,6 +235,8 @@ The two removed packages stopped at version 0.2.0, and npm marks them deprecated
|
|
|
219
235
|
| Render a custom widget in Studio | `extensions-sdk-frontend` for the catalog and `extensions-sdk-frontend-react` (`/studio`, `/studio-api`) |
|
|
220
236
|
| Sign users in with CI and proxy record reads and writes from a Next.js server | `external-apps-server-sdk` (`/auth/federated`, `/next`) |
|
|
221
237
|
| Call CI from server code with the application's credentials | `external-apps-server-sdk` root or `/effect` |
|
|
238
|
+
| Connect a Payload Site to CI | `external-apps-server-sdk-payload`, with `/package` in the site's CI package |
|
|
239
|
+
| Connect a Strapi 5 site to CI | `external-apps-server-sdk-strapi` |
|
|
222
240
|
| Show and edit CI records on a browser page | `external-apps-client-sdk-react` (`/resources`) |
|
|
223
241
|
| Call CI from a browser without React | `external-apps-client-sdk` |
|
|
224
242
|
| Reuse CI design-system components | `ui-react` |
|
|
@@ -256,17 +256,19 @@ Code in the template imports CI packages and its own workspaces by package name
|
|
|
256
256
|
|
|
257
257
|
The SDKs split by where the code runs. [SDKs](../develop/sdks.md) has the full map; these are the subpaths you meet most.
|
|
258
258
|
|
|
259
|
-
| Package
|
|
260
|
-
|
|
|
261
|
-
| `@collective-intelligence/extensions-sdk`
|
|
262
|
-
| `@collective-intelligence/extensions-sdk-backend`
|
|
263
|
-
| `@collective-intelligence/extensions-sdk-frontend`
|
|
264
|
-
| `@collective-intelligence/extensions-sdk-frontend-react`
|
|
265
|
-
| `@collective-intelligence/external-apps-server-sdk`
|
|
266
|
-
| `@collective-intelligence/external-apps-
|
|
267
|
-
| `@collective-intelligence/external-apps-
|
|
268
|
-
|
|
269
|
-
|
|
259
|
+
| Package | Runs | Holds | Main subpaths |
|
|
260
|
+
| ----------------------------------------------------------- | ------------------ | ------------------------------------------------------------------------ | ---------------------------------------------------------- |
|
|
261
|
+
| `@collective-intelligence/extensions-sdk` | Inside CI | Declarations such as `declarePackage`, `declareAgent`, `declareWorkflow` | `.`, `./effect` |
|
|
262
|
+
| `@collective-intelligence/extensions-sdk-backend` | Inside CI | Contracts for backend tools and connectors | `.`, `./effect` |
|
|
263
|
+
| `@collective-intelligence/extensions-sdk-frontend` | Inside CI | Framework-neutral frontend catalog | `.`, `./effect` |
|
|
264
|
+
| `@collective-intelligence/extensions-sdk-frontend-react` | Inside CI | React bindings for Studio and Dashboard contributions | `./studio`, `./dashboard`, `./studio-api`, `./effect` |
|
|
265
|
+
| `@collective-intelligence/external-apps-server-sdk` | Your server | Server client, BFF, authentication, Gateway | `.`, `./auth/federated`, `./effect`, `./next`, `./gateway` |
|
|
266
|
+
| `@collective-intelligence/external-apps-server-sdk-payload` | Your Payload Site | Payload Plugin, Payload Package Helpers, `payload ci-generate` | `.`, `./package`, `./ci-generate` |
|
|
267
|
+
| `@collective-intelligence/external-apps-server-sdk-strapi` | Your Strapi 5 site | Strapi 5 adapter that serves documents through a Gateway | `.` |
|
|
268
|
+
| `@collective-intelligence/external-apps-client-sdk` | Your browser | React-free client and Realtime | `.`, `./resources`, `./effect` |
|
|
269
|
+
| `@collective-intelligence/external-apps-client-sdk-react` | Your browser | React hooks, including the entity hooks in `./resources` | `.`, `./resources`, `./effect` |
|
|
270
|
+
|
|
271
|
+
Every SDK puts its Promise API at the root and its Effect services, Layers, errors and Schemas at `/effect`; the two CMS SDKs, the Payload SDK and the Strapi SDK, have no `/effect`. `effect` is a required peer of every SDK (the Strapi SDK gets it through the server SDK), so install it next to the SDK and keep one `effect` version in the app. Optional peers such as Next.js, Express, Drizzle, Better Auth and the AI SDK sit behind their own subpaths, so importing the server SDK root never loads them. In the template, `/next` is imported only inside `apps/web/src/server`, because `/next` loads Next.js and `/effect` does not.
|
|
270
272
|
|
|
271
273
|
### Template domain parts
|
|
272
274
|
|
package/docs/realtime.md
CHANGED
|
@@ -12,8 +12,7 @@ const AppRealtime = ({ children }: { children: ReactNode }) => {
|
|
|
12
12
|
const queryClient = useQueryClient()
|
|
13
13
|
return (
|
|
14
14
|
<RealtimeProvider
|
|
15
|
-
|
|
16
|
-
onReset={() => queryClient.invalidateQueries()}
|
|
15
|
+
onResync={() => queryClient.invalidateQueries()}
|
|
17
16
|
revalidateUrl="/api/realtime/revalidate"
|
|
18
17
|
ticketUrl="/api/realtime/ticket"
|
|
19
18
|
>
|
|
@@ -34,11 +33,12 @@ const LeadBoard = () => {
|
|
|
34
33
|
|
|
35
34
|
## Rules
|
|
36
35
|
|
|
37
|
-
- Pass `
|
|
38
|
-
|
|
39
|
-
`
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
- Pass `onResync` and reload every realtime-driven query in it. It runs once
|
|
37
|
+
per delivery that holds a Resync. Its `reasons` (`"gap"`, `"access"`,
|
|
38
|
+
`"server"`, `"first-open"`) and `generation` are for logs and metrics;
|
|
39
|
+
every call means reload, also for a generation seen before. With
|
|
40
|
+
`accessChanged` true, check the session too. Without `onResync` the client
|
|
41
|
+
cannot recover from a gap, and a change can be lost.
|
|
42
42
|
- `startedAt` (default `performance.timeOrigin`) is when the page started to
|
|
43
43
|
read its data. A page that shows cached data read before its navigation
|
|
44
44
|
passes `performance.timeOrigin - ageMs`; never a server timestamp.
|
|
@@ -48,9 +48,13 @@ const LeadBoard = () => {
|
|
|
48
48
|
- Changes come in batches, one delivery per tab, with the latest change of
|
|
49
49
|
each record. Invalidate once per batch.
|
|
50
50
|
- The provider reads `ticketUrl`, `fetch` and the other client props once. To
|
|
51
|
-
use new values, remount it, for example with a React `key`.
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
use new values, remount it, for example with a React `key`. It calls the
|
|
52
|
+
`onResync` and `onRefused` of the latest render; a render that adds or
|
|
53
|
+
removes `onResync` opens a new stream.
|
|
54
|
+
- A Realtime Record Collection follows its topic with no `useRealtimeTopic`:
|
|
55
|
+
inside `CollectiveIntelligenceProvider`, `RealtimeProvider` feeds it the
|
|
56
|
+
Change Hints and Resyncs of its connection
|
|
57
|
+
([record-collections.md](record-collections.md)).
|
|
54
58
|
- With `revalidateUrl`, the server expires its Next.js cache tags of the
|
|
55
59
|
changes before `onChanges` runs, so `router.refresh()` in `onChanges` reads
|
|
56
60
|
fresh server data.
|