@collective-intelligence/external-apps-client-sdk-react 0.6.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.
@@ -10,7 +10,7 @@ The template keeps the families apart. Package code imports only `extensions-sdk
10
10
 
11
11
  ```mermaid
12
12
  flowchart LR
13
- subgraph pkg["Package: apps/extensions and ./ci subpaths"]
13
+ subgraph pkg["Package: apps/extensions and the ci parts"]
14
14
  decl["Declarations<br/>extensions-sdk"]
15
15
  impl["Tool and connector classes<br/>extensions-sdk-backend"]
16
16
  widget["Studio widgets<br/>extensions-sdk-frontend(-react)"]
@@ -32,7 +32,7 @@ flowchart LR
32
32
  server -->|"confidential credentials"| backend
33
33
  ```
34
34
 
35
- In the template, the left side is `apps/extensions` plus the `./ci` subpath of each entity and feature package. The CLI builds that code into a release and installs it into your Organization. After install, CI runs the backend classes and Studio renders the widgets, so this code never runs in your app.
35
+ In the template, the left side is `apps/extensions` plus the `ci` part of each domain. The CLI builds that code into a release and installs it into your Organization. After install, CI runs the backend classes and Studio renders the widgets, so this code never runs in your app.
36
36
 
37
37
  The right side is `apps/web`. Its browser code talks to its own server through a same-origin proxy, and the server calls CI with the application's confidential credentials. A browser can also call CI directly through the client SDK; in that case your app does not need the server SDK.
38
38
 
@@ -122,7 +122,7 @@ import { useQuery } from "@tanstack/react-query"
122
122
 
123
123
  `external-apps-client-sdk-react` adds `CollectiveIntelligenceProvider`, `CollectiveIntelligenceLoginProvider` and the entity hooks on `/resources`: `useEntityList`, `useEntityRecord`, `useEntityCreate`, `useEntityUpdate` and `useEntityDelete`. A write hook reports `conflict`, `rejected` and `uncertain` as well as `idle`, `pending` and `success`, and `resubmit()` repeats the exact same action when the user asks for it. Install its peers in your app: `react`, `react-dom`, `@tanstack/react-query`, `xstate`, `effect` and `@collective-intelligence/ui-react`.
124
124
 
125
- The template's own pages use the template's shadcn/ui package, `@acme/ui`. `ui-react` appears in the Studio widget and in SDK toasts.
125
+ The template's own pages use the template's shadcn/ui package, `@packages/ui-design-system`. `ui-react` appears in the Studio widget and in SDK toasts.
126
126
 
127
127
  ### Server SDK subpaths an external app uses
128
128
 
@@ -129,7 +129,7 @@ The app's server acts only with the grants that an Organization admin gave to it
129
129
 
130
130
  ## Data policies narrow records
131
131
 
132
- A capability opens a feature. A Knowledge Data Policy decides which records of one schema that capability reaches. Each template entity package declares its capabilities and two policies for its schema in its `./ci`: reading needs `read` on the entity's capabilities, and writing needs `manage`. This is the Lead write policy in `@acme/lead/ci`:
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
133
 
134
134
  ```ts
135
135
  declareAccessKnowledgeDataPolicy({
@@ -170,7 +170,7 @@ export const managerProfile = declareAccessProfile({
170
170
  })
171
171
  ```
172
172
 
173
- The organization package grants the entity capabilities by the FQN constants that `@acme/lead/ci` and `@acme/opportunity/ci` 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`.
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
174
 
175
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
176
 
@@ -227,7 +227,7 @@ flowchart LR
227
227
  Route --> CI["CI<br/>grants, Max Privileges, policies<br/>for the run and each record"]
228
228
  ```
229
229
 
230
- An Access Requirement is a serializable guard built from `requires`, `enters`, `allOf` and `anyOf`. A feature package exports the requirement of each operation, 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.
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
231
 
232
232
  ```tsx
233
233
  const CrmLeaf = async () => {
@@ -245,7 +245,7 @@ Dashboard feature flags such as `organization_onboarding`, `knowledge_setup` and
245
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
246
 
247
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 organization package. The app's Max Privileges already allow `platform.workflows`, so they need no change. Bump `VERSION`, then build, publish, promote and install the package.
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
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
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
251
 
@@ -111,7 +111,7 @@ The `next-effect-app` template has two composition roots, one for each side of t
111
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
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
113
 
114
- The package root in `apps/extensions` is short. It lists the organization components and each package's `./ci` components in deploy order, with the Lead score card widget for Studio:
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
115
 
116
116
  ```ts
117
117
  export default declarePackage({
@@ -119,7 +119,7 @@ export default declarePackage({
119
119
  crmDomain,
120
120
  ...leadComponents({ domain: crmDomain, version: VERSION }),
121
121
  ...opportunityComponents({ domain: crmDomain, version: VERSION }),
122
- ...organizationComponents,
122
+ ...identityComponents,
123
123
  ...convertLeadComponents({
124
124
  application: acmeApplication,
125
125
  version: VERSION
@@ -250,7 +250,7 @@ A connection keeps every field that its template marks secret as a secret. A pac
250
250
 
251
251
  ## Code entrypoints
252
252
 
253
- Code in the template imports CI packages and its own workspaces by package name and exported subpath, for example `@acme/lead/views`, and never by relative path. Each subpath has one folder under `src/` with one `index.ts` and one `exports` entry in `package.json`.
253
+ Code in the template imports CI packages and its own workspaces by package name and exported entry, for example `@packages/features-lead-client`, and never by relative path. A CI SDK splits its code by subpath. A template domain splits its code by part: one package for each runtime.
254
254
 
255
255
  ### SDK subpaths
256
256
 
@@ -268,32 +268,30 @@ The SDKs split by where the code runs. [SDKs](../develop/sdks.md) has the full m
268
268
 
269
269
  Every SDK puts its Promise API at the root and its Effect services, Layers, errors and Schemas at `/effect`. `effect` is a required peer of every 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
270
 
271
- ### Template package subpaths
271
+ ### Template domain parts
272
272
 
273
- Each template package exposes up to six subpaths, and each subpath holds one kind of code:
273
+ Each template domain has up to four parts. A part is one package with one runtime:
274
274
 
275
- | Subpath | Holds | Imported by |
276
- | ---------- | ------------------------------------------------------------------------------------------------ | ----------------------------------------- |
277
- | `domain` | Effect Schema models, resource contracts, schema FQNs, pure rules | Every other subpath and other packages |
278
- | `ci` | CI declarations, written as factories over Organization handles | `@acme/organization` |
279
- | `api` | The package `HttpApi` under `/api/app`, its groups and tagged errors | `server`, `headless`, app API composition |
280
- | `server` | The route Layer of the package `HttpApi` and its services | `apps/web/src/server` only |
281
- | `headless` | Typed client, query options, XState machines, entity bindings, Realtime hooks, simulated sources | `views`, the app |
282
- | `views` | Wired React views on `@acme/ui`, with slots for feature parts | The app |
275
+ | Part | Holds | Imported by |
276
+ | -------- | ------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------- |
277
+ | `model` | Effect Schema models, resource contracts, pure rules, the domain `HttpApi` under `/api/app`, and the CI names other parts need | the domain's other parts, other domains, the apps |
278
+ | `server` | The route Layer of the domain `HttpApi` and its services | `apps/web/src/server` only |
279
+ | `client` | Typed client, query options, XState machines, entity bindings, Realtime hooks, simulated sources, wired React views | the app |
280
+ | `ci` | CI declarations, written as factories over Identity Domain handles | `apps/extensions` |
283
281
 
284
- Imports point one way. `domain` imports no other subpath, `ci` imports neither `headless` nor `views`, and `headless` and `views` never import `server`. The `ci-solution/subpath-imports` lint rule enforces these rules.
282
+ In one domain, `server`, `client` and `ci` import their own `model` and never each other. Across domains, a part imports only the other domain's `model` part. `turbo boundaries` enforces these rules with the `tier:*`, `runtime:*` and `part:*` tags of each package.
285
283
 
286
- A package exposes only the subpaths it needs. `@acme/lead` has all six, while `@acme/lead-qualification` has only `./ci`, which holds the lead qualifier agent, its Skill, its tool and its Studio widget. The `ci` subpath is where solution code becomes code that CI installs.
284
+ A domain has only the parts it needs. `features/lead` has all four, while `features/lead-qualification` has only `model` and `ci`. Its `ci` part holds the lead qualifier agent, its Skill, its tool and its Studio widget, and its `model` part holds their FQNs. The `ci` part is where solution code becomes code that CI installs.
287
285
 
288
286
  ### Template routes and widgets
289
287
 
290
- The web app has three route files, and each only re-exports handlers from `server/` and the packages:
288
+ The web app has three route files, and each only re-exports handlers from `server/` and the domain parts:
291
289
 
292
- | Route file | Serves |
293
- | ------------------------------------- | ------------------------------------------------------- |
294
- | `app/api/app/[[...path]]/route.ts` | The app's own API, composed from the package `HttpApi`s |
295
- | `app/api/[...path]/route.ts` | The CI BFF: sign-in, Resources, Realtime ticket |
296
- | `app/api/leads/[id]/convert/route.ts` | The fixed convert-lead workflow |
290
+ | Route file | Serves |
291
+ | ------------------------------------- | ------------------------------------------------------ |
292
+ | `app/api/app/[[...path]]/route.ts` | The app's own API, composed from the domain `HttpApi`s |
293
+ | `app/api/[...path]/route.ts` | The CI BFF: sign-in, Resources, Realtime ticket |
294
+ | `app/api/leads/[id]/convert/route.ts` | The fixed convert-lead workflow |
297
295
 
298
296
  Inside CI, a Studio or Dashboard widget enters through a hosted contribution. You write `declareFrontendCatalogContribution({ fqn, host: "studio", load: () => import("./studio") })` and pass it to `declarePackage({ hostedContributions })`. The `load` function stays out of the serialized package manifest, and the loaded module exports `loadFrontendCatalog` for the host.
299
297
 
@@ -8,100 +8,113 @@ What you get from next-effect-app, where each piece of code goes, and how to tak
8
8
 
9
9
  ```bash
10
10
  apps/
11
- web/ # @acme/web Next app: routes, composition, Data Sources, app API and BFF instances
12
- extensions/ # @acme/extensions Extension Package declaration (composition root)
11
+ web/ # @acme/web Next app: routes, composition, Data Sources, app API and BFF instances
12
+ extensions/ # @acme/extensions Extension Package declaration (composes the ci parts)
13
13
  packages/
14
- organization/acme/ # @acme/organization package identity, access, groups, external application
15
- features/intake/ # @acme/intake lead intake: API, store, XState flow, views
16
- features/lead-conversion/ # @acme/lead-conversion convert-lead workflow and browser flow
17
- features/lead-qualification/ # @acme/lead-qualification lead qualifier agent, Skill, tool, Studio widget
18
- entities/lead/ # @acme/lead Lead contract, CI schema, Lead API, Read Port, Realtime, views
19
- entities/opportunity/ # @acme/opportunity Opportunity contract, CI schema, views
20
- modules/identity/ # @acme/identity CI federated auth, CI runtime, principal, login providers
21
- modules/app-api/ # @acme/app-api typed package API client, QueryClient, ApiPrefetch
22
- modules/ui/ # @acme/ui shadcn/ui primitives, AI Elements, theme, workspace-kit
23
- tooling/config/ # @acme/config shared TypeScript base config
14
+ products/acme/identity/{model,ci} # Identity Domain: package identity and VERSION, access, groups, external application, Sales desk
15
+ features/lead/{model,server,client,ci} # Lead contract and CI names, Lead API and Read Port, Realtime and views, CI schema
16
+ features/opportunity/{model,client,ci} # Opportunity contract and CI names, views, CI schema
17
+ features/intake/{model,server,client} # lead intake: schemas and API, store, XState flow and views
18
+ features/lead-conversion/{client,ci} # convert-lead browser flow and Workflow
19
+ features/lead-qualification/{model,ci} # lead qualifier agent, Skill, tool, Studio widget, and their FQNs
20
+ modules/identity-{api,server,client} # principal and Authentication contract, CI runtime, login providers
21
+ modules/app-api, app-api-server # typed domain API client, QueryClient, simulated network; ApiPrefetch
22
+ ui/design-system/ # shadcn/ui primitives, AI Elements, theme, workspace-kit
23
+ tooling/config/ # shared TypeScript base config and the Layout Guard
24
24
  ```
25
25
 
26
- Intake is a form with an XState flow and an app API that keeps its data in an in-memory store. Lead conversion is a Fixed workflow started by a single-action task. Lead qualification is an agent with a Skill, a tool and a Studio widget. The repository has no docs wiki, no infra folder and no generated client code, because the browser derives each typed client from its package `HttpApi` at runtime. It also ships an agent harness: an `AGENTS.md` per scope, and `.agents/` with skills, rules and lint scripts.
26
+ Intake is a form with an XState flow and an app API that keeps its data in an in-memory store. Lead conversion is a Fixed workflow started by a single-action task. Lead qualification is an agent with a Skill, a tool and a Studio widget. The repository has no docs wiki, no infra folder and no generated client code, because the browser derives each typed client from its domain `HttpApi` at runtime. It also ships an agent harness: an `AGENTS.md` per scope, and `.agents/` with skills, rules and lint scripts.
27
27
 
28
- ## Tiers and the import rule
28
+ ## Domains, parts and the import rules
29
29
 
30
- Every package lives at `packages/<tier>/<name>`, keeps a flat name (`@acme/<name>`) and has exactly one `tier:*` tag in its own `turbo.json`. The six tiers, from top to bottom, are `app` (the composition roots), `organization` (package identity, access, groups, external application and deploy order), `features` (one user-visible capability each), `entities` (one business entity each), `modules` (business-agnostic machinery) and `tooling` (the shared tsconfig base).
30
+ The template groups its code by domain. One domain is one folder, and each runtime of the domain is its own package, a part. The folder directly below `packages/` is the kind:
31
+
32
+ | Kind | Holds |
33
+ | ------------------------------------ | ---------------------------------------------------------- |
34
+ | `features/<domain>/<part>` | a domain that names no product, such as `lead` or `intake` |
35
+ | `products/<product>/<domain>/<part>` | a domain of one product; it may name its product |
36
+ | `ui/<name>` | the design system and page blocks, with no product terms |
37
+ | `modules/<name>` | business-agnostic machinery with one runtime |
38
+ | `tooling/<name>` | TypeScript, lint, build and test configuration |
39
+
40
+ A domain has only the parts it needs, and each part has exactly one runtime:
41
+
42
+ | Part | Runtime | Holds |
43
+ | -------- | ------- | ------------------------------------------------------------------------------------------------------------------------------ |
44
+ | `model` | neutral | Effect Schema models, resource contracts, pure rules, the domain `HttpApi` under `/api/app`, and the CI names other parts need |
45
+ | `server` | server | the route Layer of the domain `HttpApi` and its services; only `apps/web/src/server` imports it |
46
+ | `client` | client | typed client, query options, XState machines, entity bindings, Realtime topics and hooks, simulated sources, wired React views |
47
+ | `ci` | ci | CI declarations (extensions SDK) as factories over Identity Domain handles |
48
+
49
+ A package name is `@packages/` plus its path below `packages/`, with `-` in place of `/`. For example, `packages/features/lead/client` is `@packages/features-lead-client`. The apps keep their own names. Every internal dependency uses `workspace:*`. A part exports `.`, and a `client` part adds `./headless` only when a consumer needs state without components.
31
50
 
32
51
  ```mermaid
33
52
  flowchart TD
34
53
  web["apps/web"]
35
54
  ext["apps/extensions"]
36
- org["organization<br/>@acme/organization"]
37
- subgraph features["features"]
38
- f1["intake"]
39
- f2["lead-conversion"]
40
- f3["lead-qualification"]
55
+ subgraph identity["products/acme/identity"]
56
+ im["model"]
57
+ ic["ci"]
41
58
  end
42
- subgraph entities["entities"]
43
- e1["lead"]
44
- e2["opportunity"]
59
+ subgraph lead["features/lead"]
60
+ lm["model"]
61
+ ls["server"]
62
+ lc["client"]
63
+ lci["ci"]
45
64
  end
46
- subgraph modules["modules"]
47
- m1["identity"]
48
- m2["app-api"]
49
- m3["ui"]
65
+ subgraph conv["features/lead-conversion"]
66
+ cc["client"]
67
+ cci["ci"]
50
68
  end
51
- tooling["tooling<br/>config"]
52
- web --> org
53
- ext -->|"lists CI declarations in deploy order"| org
54
- ext -->|"lists each ./ci"| features
55
- org -->|"grants package capabilities"| features
56
- features --> entities
57
- entities --> modules
58
- modules --> tooling
59
- f1 -.-|"never imports"| f2
60
- e1 -.-|"never imports"| e2
69
+ modules["modules, ui, tooling"]
70
+ web -->|"composes server and client parts"| ls
71
+ web --> lc
72
+ web --> cc
73
+ ext -->|"lists each ci part in deploy order"| lci
74
+ ext --> cci
75
+ ext --> ic
76
+ ic -->|"grants by the names in model parts"| lm
77
+ ls --> lm
78
+ lc --> lm
79
+ lci --> lm
80
+ cc -->|"another domain's model only"| lm
81
+ lc --> modules
82
+ lc -.-|"never imports"| cc
61
83
  ```
62
84
 
63
- Imports point down the tiers and may skip a tier. Inside one tier, only modules and tooling packages import each other. A feature never imports another feature and an entity never imports another entity. When two of them must work together, a page in `apps/web` connects them.
85
+ - In one domain, `server`, `client` and `ci` import their own `model`. They never import each other.
86
+ - Across domains, a part imports only the other domain's `model` part. The `server`, `client` and `ci` parts of different domains meet only in an app: `apps/web` composes the views, and `apps/extensions` composes the `ci` parts.
87
+ - `features`, `ui` and `modules` never import `products`. A product never imports another product.
88
+ - `ui` imports only `ui` and `tooling`. `modules` imports only `modules` and `tooling`.
64
89
 
65
- The arrows are real configuration. The root `turbo.json` lists, for each tag, the tags it may depend on, and `bunx turbo boundaries` fails the build on a wrong import:
90
+ The rules are real configuration. Each workspace `turbo.json` has the Boundary Tags of its place: one `tier:*` tag, one `runtime:*` tag (apps have none), and one `part:*` tag for a part. The root `turbo.json` holds one rule for each tag, and `bunx turbo boundaries` fails the build on a wrong import:
66
91
 
67
92
  ```json
68
- "tier:features": { "dependencies": { "allow": ["tier:entities", "tier:modules", "tier:tooling"] } },
69
- "tier:entities": { "dependencies": { "allow": ["tier:modules", "tier:tooling"] } },
70
- "tier:modules": { "dependencies": { "allow": ["tier:modules", "tier:tooling"] } }
93
+ "tier:features": { "dependencies": { "allow": ["tier:features", "tier:ui", "tier:modules", "tier:tooling"] } },
94
+ "runtime:client": { "dependencies": { "deny": ["runtime:server", "runtime:ci"] } },
95
+ "part:client": { "dependencies": { "deny": ["part:server", "part:client", "part:ci"] } }
71
96
  ```
72
97
 
73
- Workspaces import each other by package name and exported subpath, such as `@acme/lead/views`, and never by relative path.
98
+ The full table is `BOUNDARY_TAGS` from `@collective-intelligence/lint/layout`. The `part:*` rules deny every `server`, `client` and `ci` part, so a part reaches only `model` parts. An app has no `part:*` tag, so the parts of different domains meet there.
74
99
 
75
- ## Package subpaths
100
+ Workspaces import each other by package name and exported entry, such as `@packages/features-lead-client`, and never by relative path.
76
101
 
77
- A feature or entity package exposes only the subpaths it needs. Each subpath is a folder under `src/` with one `index.ts` and one `exports` entry in `package.json`.
102
+ The template has these domains:
78
103
 
79
- | Subpath | Holds | Imported by |
80
- | ---------- | ----------------------------------------------------------------------------------------------------------- | --------------------------------------------- |
81
- | `domain` | Effect Schema models, resource contracts, schema FQNs, pure rules | every other subpath and other packages |
82
- | `ci` | CI declarations (extensions SDK) as factories over organization handles | `apps/extensions`, `@acme/organization` |
83
- | `api` | the package `HttpApi` under `/api/app`, its groups and tagged errors | `server`, `headless`, the app API composition |
84
- | `server` | the route Layer of the package `HttpApi` and its services | `apps/web/src/server` only |
85
- | `headless` | typed client, query options, XState machines, entity bindings, Realtime topics and hooks, simulated sources | `views` and the app |
86
- | `views` | wired React views on `@acme/ui`; feature parts enter through slots | the app |
104
+ | Domain | Parts |
105
+ | ----------------------------- | --------------------------------- |
106
+ | `features/lead` | `model`, `server`, `client`, `ci` |
107
+ | `features/opportunity` | `model`, `client`, `ci` |
108
+ | `features/intake` | `model`, `server`, `client` |
109
+ | `features/lead-conversion` | `client`, `ci` |
110
+ | `features/lead-qualification` | `model`, `ci` |
111
+ | `products/acme/identity` | `model`, `ci` |
87
112
 
88
- Inside a package the subpaths also have a direction. `domain` imports no other subpath, `ci` imports neither `headless` nor `views`, and `headless` and `views` never import `server`. That keeps server code out of the browser bundle and keeps CI declarations free of React.
113
+ `features/lead-qualification` adds an agent, a Skill, a tool and a Studio widget, and all of that is CI-side behavior. Its `model` holds only the FQNs, and its `ci` part holds the declarations. That shows that you can ship an AI capability without writing any web code.
89
114
 
90
- Each template package exposes a different set:
115
+ ## Domains take their audience as a parameter
91
116
 
92
- | Package | Subpaths |
93
- | -------------------------- | ------------------------------------- |
94
- | `@acme/lead` | `domain ci api server headless views` |
95
- | `@acme/opportunity` | `domain ci headless views` |
96
- | `@acme/intake` | `domain api server headless views` |
97
- | `@acme/lead-conversion` | `ci headless views` |
98
- | `@acme/lead-qualification` | `ci` |
99
-
100
- `@acme/lead-qualification` adds an agent, a Skill, a tool and a Studio widget, and all of that is CI-side behavior. Its single `./ci` subpath shows that you can ship an AI capability without writing any web code.
101
-
102
- ## Features take their audience as a parameter
103
-
104
- A feature package must not import `@acme/organization`, because organization sits above it in the tiers. A feature that offers something to a group of users therefore takes that `audience`, and the application handle, as parameters. The organization package owns the groups, the application and the profiles; each entity package declares its own capabilities and Knowledge Data Policies, and the profiles grant them by the FQN constants of `@acme/lead/ci` and `@acme/opportunity/ci`. `apps/extensions/src/index.ts` passes the organization handles in and lists every component in deploy order, where each component follows the components it references:
117
+ `products/acme/identity` is the Identity Domain of the product `acme`. Its `model` part holds the package identity and `VERSION`. Its `ci` part holds the groups, the application, the Access Profiles, their grants and the Max Privileges. A `features` domain never imports a product, so a `ci` part that offers something to a group of users takes that `audience`, and the application handle, as parameters. Each domain declares its own capabilities and Knowledge Data Policies in its `ci` part. The profiles grant them by the FQN constants of `@packages/features-lead-model` and `@packages/features-opportunity-model`. `apps/extensions/src/index.ts` passes the Identity Domain handles in and lists every component in deploy order, where each component follows the components it references:
105
118
 
106
119
  ```ts
107
120
  export default declarePackage({
@@ -109,7 +122,7 @@ export default declarePackage({
109
122
  crmDomain,
110
123
  ...leadComponents({ domain: crmDomain, version: VERSION }),
111
124
  ...opportunityComponents({ domain: crmDomain, version: VERSION }),
112
- ...organizationComponents,
125
+ ...identityComponents,
113
126
  ...convertLeadComponents({
114
127
  application: acmeApplication,
115
128
  version: VERSION
@@ -126,21 +139,21 @@ export default declarePackage({
126
139
  })
127
140
  ```
128
141
 
129
- `organizationComponents` holds the Sales Group, the application, the profiles, their grants and the Max Privileges. The Studio contribution is the one declaration in `apps/extensions`: `ci package build` resolves its relative `load` import against that file.
142
+ `identityComponents` holds the Sales Group, the application, the profiles, their grants and the Max Privileges. The Studio contribution is the one declaration in `apps/extensions`: `ci package build` resolves its relative `load` import against that file.
130
143
 
131
144
  [Extensions](../develop/extensions.md) describes each kind of declaration, and [Access](../platform/access.md) explains the Access Profiles and Access Grants in that list.
132
145
 
133
146
  ## The web app layers
134
147
 
135
- Entity and feature code lives in packages. The web app keeps only routes, Composition, the sign-in gate, Data Sources and server instances, arranged in a fixed set of layers where each layer imports only the layers below it:
148
+ Domain code lives in the domain parts. The web app keeps only routes, Composition, the sign-in gate, Data Sources and server instances, arranged in a fixed set of layers where each layer imports only the layers below it:
136
149
 
137
- | Layer in `apps/web/src` | Holds |
138
- | ----------------------- | --------------------------------------------------------------------------------------------------------------------- |
139
- | `app/` | route files only; each re-exports a Composition export, and `app/api/**` forwards to `server/<domain>/server` |
140
- | `composition/` | `providers/` (global providers, Realtime providers) and `routing/` (access, shells, pages) |
141
- | `features/` | app-local capabilities: their Data Sources (`remote/server.ts`) and `page-link/` |
142
- | `entities/` | app-local entity machinery that several features need (the CI session), Data Sources of entity packages, `page-link/` |
143
- | `server/` | beside the layers: one folder per domain, where `server.ts` (`server-only`) holds the process instance |
150
+ | Layer in `apps/web/src` | Holds |
151
+ | ----------------------- | ------------------------------------------------------------------------------------------------------------------ |
152
+ | `app/` | route files only; each re-exports a Composition export, and `app/api/**` forwards to `server/<domain>/server` |
153
+ | `composition/` | `providers/` (global providers, Realtime providers) and `routing/` (access, shells, pages) |
154
+ | `features/` | app-local capabilities: their Data Sources (`remote/server.ts`) and `page-link/` |
155
+ | `entities/` | app-local entity machinery that several features need (the CI session), Data Sources of domain parts, `page-link/` |
156
+ | `server/` | beside the layers: one folder per domain, where `server.ts` (`server-only`) holds the process instance |
144
157
 
145
158
  Only Composition imports a Data Source, and only Data Sources and `app/api/**` import a `server/<domain>/server.ts`. Peers still meet without importing each other: the CRM page template passes `ConvertLead` into the `selectionActions` slot of `LeadWorkspace` and `LeadAttachment` into its `editorActions` slot. Each page's owner gives its `{ label, path }` in `page-link/`, and shells and links read it, so no route path is written twice.
146
159
 
@@ -148,7 +161,7 @@ One Next app serves two server surfaces:
148
161
 
149
162
  | Path | Handler | What it is |
150
163
  | ------------------------- | ----------------------- | ------------------------------------------------------------------------------------------------------------------------ |
151
- | `/api/app/*` | `server/app-api/server` | the app API: the packages' Effect `HttpApi`s merged, OpenAPI at `/api/app/openapi.json`, Scalar docs at `/api/app/docs` |
164
+ | `/api/app/*` | `server/app-api/server` | the app API: the domains' Effect `HttpApi`s merged , OpenAPI at `/api/app/openapi.json`, Scalar docs at `/api/app/docs` |
152
165
  | `/api/*` | `server/ci/server` | the CI SDK BFF: sign-in with a sealed cookie, Lead and Opportunity resource proxy, Realtime ticket and revalidate routes |
153
166
  | `/api/leads/[id]/convert` | `server/ci/server` | the Fixed convert-lead workflow route |
154
167
 
@@ -157,7 +170,7 @@ The BFF holds the CI session in a sealed cookie and proxies resource calls, so t
157
170
  ## Start a new demo
158
171
 
159
172
  1. Generate a repository with **Use this template** on the template repository. In the new repository, delete the README "Contributing" section and `.github/workflows/close-pull-requests.yml`, which only matter in the template repository itself.
160
- 2. Rename the template for the customer. Replace the `@acme/` package scopes and the `acme.app.` FQNs, replace `https://acme.localhost` in `packages/organization/acme/src/application.ts` and `.env.example`, and replace the theme tokens and the sidebar brand in `apps/web/src/composition/routing/shells/workspace/app-sidebar.tsx`. Theme tokens live once, in `packages/modules/ui/src/styles/globals.css`.
173
+ 2. Rename the template for the customer. Replace the `@acme/` app names, the product folder `packages/products/acme` with its package names `@packages/products-acme-*`, and the `acme.app.` FQNs. Replace `https://acme.localhost` in `packages/products/acme/identity/ci/src/application.ts` and `.env.example`, and replace the theme tokens and the sidebar brand in `apps/web/src/composition/routing/shells/workspace/app-sidebar.tsx`. Theme tokens live once, in `packages/ui/design-system/src/styles/globals.css`.
161
174
  3. Run it locally. The Overview and Lead intake pages work with no configuration, because the intake API keeps requests in memory:
162
175
 
163
176
  ```bash
@@ -226,22 +239,22 @@ The BFF holds the CI session in a sealed cookie and proxies resource calls, so t
226
239
 
227
240
  ## What to change and what to keep
228
241
 
229
- A new demo changes the organization package, the entities, the features, the theme and the origins. It keeps `modules/identity`, `modules/app-api`, the BFF and server wiring, the tier tags, the lint configuration and the harness files, because they hold no business logic. A new environment variable goes into `apps/web/.env.example`, `packages/modules/identity/src/server/env.ts`, `turbo.json` `globalEnv` and the README tenant section together.
242
+ A new demo changes the Identity Domain, the `features` domains, the theme and the origins. It keeps the `modules/identity-*` and `modules/app-api*` packages, the BFF and server wiring, the Boundary Tags, the Layout Guard, the lint configuration and the harness files, because they hold no business logic. A new environment variable goes into `apps/web/.env.example`, `packages/modules/identity-server/src/env.ts`, `turbo.json` `globalEnv` and the README tenant section together.
230
243
 
231
244
  ## Checks that keep the structure honest
232
245
 
246
+ Three checks keep the layout. `turbo boundaries` checks every import against the Boundary Tags. The Layout Guard, the Bun test `packages/tooling/config/src/workspace-layout.test.ts`, checks what the tags cannot express: the root `workspaces` globs, package names, each `turbo.json`, `workspace:*` ranges and product isolation. The `ci-solution/workspace-layout` lint rule reports a package that sits outside the accepted places. All three read one layout definition, `@collective-intelligence/lint/layout`.
247
+
233
248
  `@collective-intelligence/lint` is one Oxlint plugin named `ci-solution`. Extending `recommended` turns every rule on as an error:
234
249
 
235
- | Rule | Checks |
236
- | -------------------------------- | ---------------------------------------------------------------------------------- |
237
- | `ci-solution/package-entrypoint` | an import of another package targets an entrypoint in its `package.json` `exports` |
238
- | `ci-solution/subpath-imports` | imports between subpath folders follow the allowed direction |
239
- | `ci-solution/subpath-entrypoint` | an import of another subpath folder targets its index file |
240
- | `ci-solution/subpath-index` | every subpath folder has `index.ts` or `index.tsx` |
241
- | `ci-solution/effect-subpath` | SDK Effect APIs come from the SDK `/effect` subpath |
242
- | `ci-solution/no-run-in-view` | a view module calls no `fetch` and runs no Effect |
243
- | `ci-solution/effect-actors` | XState side-effect actors are `fromEffect` actors |
244
- | `ci-solution/effect-writes` | no module uses TanStack Query `useMutation`; writes run in `fromEffect` actors |
250
+ | Rule | Checks |
251
+ | -------------------------------- | ---------------------------------------------------------------------------------------------- |
252
+ | `ci-solution/package-entrypoint` | an import of another package targets an entrypoint in its `package.json` `exports` |
253
+ | `ci-solution/workspace-layout` | each workspace sits at `apps/<name>`, a domain part, or `packages/{ui,modules,tooling}/<name>` |
254
+ | `ci-solution/effect-subpath` | SDK Effect APIs come from the SDK `/effect` subpath |
255
+ | `ci-solution/no-run-in-view` | a view module calls no `fetch` and runs no Effect |
256
+ | `ci-solution/effect-actors` | XState side-effect actors are `fromEffect` actors |
257
+ | `ci-solution/effect-writes` | no module uses TanStack Query `useMutation`; writes run in `fromEffect` actors |
245
258
 
246
259
  Each package has an `oxlint.local.ts` that extends the preset:
247
260
 
@@ -264,14 +277,14 @@ The web app also runs a `frontend-layers` lint for layer order, domain entrypoin
264
277
 
265
278
  ```bash
266
279
  bun run check-types
267
- bun run test
280
+ bun run test # includes the Layout Guard
268
281
  bunx turbo boundaries
269
282
  bun run lint
270
283
  bun run format:check
271
284
  bun run build
272
285
  ```
273
286
 
274
- When you change the Lead cache, a Lead write or Lead Realtime, also run `bun run check:models` in `packages/entities/lead`. [State machines](state-machines.md) explains what that command checks.
287
+ When you change the Lead cache, a Lead write or Lead Realtime, also run `bun run check:models` in `packages/features/lead/client`. [State machines](state-machines.md) explains what that command checks.
275
288
 
276
289
  ## Related pages
277
290
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  How next-effect-app models UI flows as XState machines with Effect actors, keeps server data in the QueryCache, resends uncertain writes safely, and checks hard flows with Models.
4
4
 
5
- In `next-effect-app`, a UI flow that carries business logic is an XState machine in the `headless/` folder of its package, at `headless/<flow>-machine.ts`. Flows that belong only to the web app live at `apps/web/src/{features,entities}/<domain>/<flow>-machine.ts`. The machine decides where the flow is: editing, reviewing, submitting, failed. Every side effect is an Effect program that the machine runs as an actor, and TanStack Query owns the remote data that those programs read and write.
5
+ In `next-effect-app`, a UI flow that carries business logic is an XState machine in the `src/headless/` folder of its domain's `client` part, at `src/headless/<flow>-machine.ts`. Flows that belong only to the web app live at `apps/web/src/{features,entities}/<domain>/<flow>-machine.ts`. The machine decides where the flow is: editing, reviewing, submitting, failed. Every side effect is an Effect program that the machine runs as an actor, and TanStack Query owns the remote data that those programs read and write.
6
6
 
7
7
  The machine context holds flow state only and never an API response. Two views that show the same record therefore read one cache entry, and no machine keeps a copy that can go stale. Server Components never run machines or Effects; they await a Promise boundary, and machines exist only in client code.
8
8
 
@@ -72,7 +72,7 @@ submitting: {
72
72
 
73
73
  Leaving the invoking state interrupts the Effect fiber. The machine has no UI of its own: `submitted` is a typed action, and the view provides the toast with `machine.provide({ actions })`. The view runs `useMachine(intakeMachine.provide(...), { input: { runtime } })` and renders by `snapshot.matches("editing")`, `matches("submitting")` and `matches("done")`.
74
74
 
75
- The same `provide` call swaps the data source for a demo without a backend. A simulated source lives in `headless/simulated-*.ts`, built with `simulate("<pace>", effect)` from `@acme/app-api`, and only Composition or a test selects it. Tests use the same mechanism. A test drives the machine on a `ManagedRuntime` of the SDK `makeTestQueryCache` layer, never a hand-made `QueryCache` double, and asserts on cache entries or recorded calls:
75
+ The same `provide` call swaps the data source for a demo without a backend. A simulated source lives in `headless/simulated-*.ts`, built with `simulate("<pace>", effect)` from `@packages/modules-app-api`, and only Composition or a test selects it. Tests use the same mechanism. A test drives the machine on a `ManagedRuntime` of the SDK `makeTestQueryCache` layer, never a hand-made `QueryCache` double, and asserts on cache entries or recorded calls:
76
76
 
77
77
  ```ts
78
78
  const cache = makeTestQueryCache({ seed: [[intakeRequestsQuery.queryKey, []]] })
@@ -160,7 +160,7 @@ stateDiagram-v2
160
160
  done --> running: RUN with a new file
161
161
  ```
162
162
 
163
- The steps inside `running` are steps of the Effect program, and the machine itself sees one `running` state. A resubmit skips the upload and sends only the final write. The size and type checks use `leadAttachmentAccepts` and `leadAttachmentMaxBytes` (5 MiB) from `@acme/lead/domain`. The CI schema declares the same values on the File field, so CI refuses a larger upload too, while a file that fails the local check sends nothing.
163
+ The steps inside `running` are steps of the Effect program, and the machine itself sees one `running` state. A resubmit skips the upload and sends only the final write. The size and type checks use `leadAttachmentAccepts` and `leadAttachmentMaxBytes` (5 MiB) from `@packages/features-lead-model`. The CI schema declares the same values on the File field, so CI refuses a larger upload too, while a file that fails the local check sends nothing.
164
164
 
165
165
  The write that might need a resend is a value the failure carries:
166
166
 
@@ -224,7 +224,7 @@ A Model is a `*.proof.ts` TypeScript module that states the state, actions and i
224
224
  | `/** @constraint */` | a bound, so the search ends |
225
225
  | `ghost` prefix on a `let` | records what a consumer saw, only to state a guarantee |
226
226
 
227
- The Lead Realtime Model in `packages/entities/lead` is trimmed here. The full file also has `writeConfirm`, `otherWrite`, `realtimeChange` and `neverBehindConfirmed`:
227
+ The Lead Realtime Model in `packages/features/lead/client/src/headless/lead-realtime.proof.ts` is trimmed here. The full file also has `writeConfirm`, `otherWrite`, `realtimeChange` and `neverBehindConfirmed`:
228
228
 
229
229
  ```ts
230
230
  let server: Revision = 0
@@ -260,7 +260,7 @@ export const isRefetchDue = () => refetchDue && !isFresh()
260
260
  The checker visits 22 states and proves two things. A Realtime refetch never hides the tab's pending optimistic write (`pendingWriteShown`, `neverBehindConfirmed`), and after a Realtime change the views eventually reach the stored revision (`@leadsTo isFresh`). The package runs it with one script:
261
261
 
262
262
  ```bash
263
- cd packages/entities/lead
263
+ cd packages/features/lead/client
264
264
  bun run check:models
265
265
  ```
266
266
 
package/docs/sign-in.md CHANGED
@@ -42,7 +42,8 @@ For a fully own UI, read `useSignIn()` inside `SignIn.Root`: `state`,
42
42
  `pending`, and the actions `start(email)`, `verify(code)`, `complete(name)`,
43
43
  `sso(provider)` and `password()`. `state.stage` is `email`, `code`, `name`,
44
44
  `sso_required`, `signed_in`, `redirect_to_web` or `no_sign_in_method`;
45
- `state.notice` holds the refusal of the last call, such as `invalid_code`.
45
+ `state.notice` holds the refusal of the last call, such as `invalid_code` or
46
+ `invalid_input`.
46
47
 
47
48
  ## Rules
48
49
 
@@ -50,6 +51,10 @@ For a fully own UI, read `useSignIn()` inside `SignIn.Root`: `state`,
50
51
  mounts; the SSO buttons and the password button follow its answer. Run each
51
52
  later step through the actions of `useSignIn`, not through `auth.signIn`,
52
53
  so the state follows every answer.
54
+ - When the app allows no email code (`methods.emailCode` is `false`), the
55
+ email form stays: CI sends the address to its SSO provider or to the CI
56
+ page. Its button shows `labels.emailContinue` in place of
57
+ `labels.emailSubmit`.
53
58
  - `pending` is true from an action until its call settles, on React 18
54
59
  and 19. An action while a call runs does nothing: show `pending` in an
55
60
  own UI, and do not queue the next step.
@@ -59,6 +64,10 @@ For a fully own UI, read `useSignIn()` inside `SignIn.Root`: `state`,
59
64
  - `onError` gets `CiTransportError` (the call got no step) or
60
65
  `FederatedAuthError` (the SDK could not navigate). The form keeps its
61
66
  values. A refusal such as a wrong code is no error: `SignIn.Notice` shows it.
67
+ - An email, code or name that CI cannot read, such as `bob@example`, is the
68
+ `invalid_input` step, not a fault: the same form stays, `SignIn.Notice`
69
+ asks the person to check the input (`labels.invalidInput`), and `onError`
70
+ does not run.
62
71
  - `labels` replaces any default text; some texts are functions, such as
63
72
  `invalidCode(attemptsLeft)`. `className` goes on the card and on each part.
64
73
  - `components` replaces `EmailField`, `CodeField`, `NameField` or `Button`. A
@@ -66,5 +75,6 @@ For a fully own UI, read `useSignIn()` inside `SignIn.Root`: `state`,
66
75
  render one input with them, because the form reads the value by `name`.
67
76
  - The auth of `createFederatedAuth` has no `signIn`: the sign-in components
68
77
  throw with it. Use `LoginButton` for the CI page instead.
69
- - The components import `@collective-intelligence/ui-react/ui`; install its
70
- required peer `react-hook-form`.
78
+ - The components import `@collective-intelligence/ui-react/ui` and
79
+ `@collective-intelligence/ui-react/ui-extensions/labeled-field`; install the
80
+ `ui-react` peer `react-hook-form`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@collective-intelligence/external-apps-client-sdk-react",
3
- "version": "0.6.0",
3
+ "version": "0.7.1",
4
4
  "description": "React bindings for Collective Intelligence external applications.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -48,11 +48,12 @@
48
48
  "type-check": "bun check --no-script -p tsconfig.json"
49
49
  },
50
50
  "dependencies": {
51
- "@collective-intelligence/external-apps-client-sdk": "0.6.0",
51
+ "@collective-intelligence/effect-xstate": "0.7.1",
52
+ "@collective-intelligence/external-apps-client-sdk": "0.7.1",
52
53
  "nuqs": "2.10.1"
53
54
  },
54
55
  "peerDependencies": {
55
- "@collective-intelligence/ui-react": "0.6.0",
56
+ "@collective-intelligence/ui-react": "0.7.1",
56
57
  "@tanstack/react-query": "^5.101.4",
57
58
  "effect": "^4.1.0",
58
59
  "react": ">=18.2 <20",
@@ -63,7 +64,7 @@
63
64
  "access": "public"
64
65
  },
65
66
  "devDependencies": {
66
- "@collective-intelligence/ui-react": "0.6.0",
67
+ "@collective-intelligence/ui-react": "0.7.1",
67
68
  "@effect/eslint-plugin": "0.3.2",
68
69
  "@oxlint/plugins": "1.94.0",
69
70
  "@punks/lints": "0.2.0",
@@ -92,5 +93,5 @@
92
93
  "vitest": "4.1.10",
93
94
  "xstate": "5.33.3"
94
95
  },
95
- "gitHead": "94535cc59ece904d4a9374a368edb09222688bb6"
96
+ "gitHead": "822e4e2a259aa39e865d40504f6ac1e85d9c182a"
96
97
  }