@collective-intelligence/external-apps-client-sdk 0.3.4 → 0.3.7

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/docs/chat.md ADDED
@@ -0,0 +1,49 @@
1
+ # External App chat
2
+
3
+ `client.chat` (and `Chat` at `./effect`) calls the External App chat routes
4
+ (`/application/v1/chat/...`). The package `README.md` lists every group and
5
+ method.
6
+
7
+ ## Rules
8
+
9
+ - Call the chat as a signed-in user of the app. A server credential or a
10
+ visitor gets `forbidden` with `details.reason` `principal_not_allowed`.
11
+ - Give each method the `path`, `query` and `body` of its generated
12
+ operation. Never build a chat URL: the transport maps each method to its
13
+ route, directly or through a proxy or the server SDK BFF.
14
+ - Branch on `error.code` and `error.details.reason`. Show a blocked chat only
15
+ for `principal_not_allowed`, `capability_missing` and `app_disabled`.
16
+ `approval_not_allowed` refuses one approval; the chat stays open.
17
+ `not_available_here` refuses one Conversation or Agent.
18
+ - Read `presentation.stream` with `for await`. One call is one connection: a
19
+ clean end before the `closed` frame is a cut, so open a new connection with
20
+ `query.afterSequence` set to the `id` of the last frame. Do not poll beside
21
+ a live stream.
22
+ - Parse the `data` of each frame as JSON. The SDK drops `: ping` comments.
23
+ - Give named `File` values to `attachments.upload` and
24
+ `projects.uploadFile`. CI reads the file type from the extension of the
25
+ name; a plain `Blob` throws `TypeError`. Wrap it as
26
+ `new File([blob], "notes.txt")`.
27
+
28
+ ## Shared chat UI
29
+
30
+ `createChatTransport` (`/chat`) is the `ChatTransport` of
31
+ `@collective-intelligence/ai-core` over `client.chat`. Give it to
32
+ `<AiProvider transport>` of `@collective-intelligence/ai-react` to show the
33
+ default `<Chat>`.
34
+
35
+ ```ts
36
+ import { createChatTransport } from "@collective-intelligence/external-apps-client-sdk/chat"
37
+
38
+ const transport = createChatTransport(client.forOrganization(organizationId))
39
+ ```
40
+
41
+ - Install `@collective-intelligence/ai-core` with it. It is an optional
42
+ peer: only `/chat` imports it, and `/chat` imports no React.
43
+ - Give an organization client. The transport works directly, through a
44
+ proxy or through the server SDK BFF (`/api/ci`).
45
+ - A refusal answers an `AiError`; `reason` is the `details.reason` of the
46
+ `CiError`. A request that does not reach CI answers `unavailable`
47
+ (retryable). An aborted call rejects with the reason of its signal.
48
+ - `openPresentationStream` opens one connection. Follow a run with
49
+ `followPresentation` of ai-core: it reconnects. Do not reconnect yourself.
@@ -17,6 +17,7 @@ The template's package declares the Lead and Opportunity schemas, the Sales grou
17
17
  | `declareStudioApp` | A Declared Studio App that CI creates and publishes on install |
18
18
  | `declareStudioAppTemplate` | A starting point that a builder copies into a new Studio app |
19
19
  | `declareStudioComponent` | A Studio component, such as a widget of category `widget` |
20
+ | `declarePlaceSettings` | The chat settings of a Studio app or External App (history, Projects, memory, voice) |
20
21
  | `declareConnection`, `declareConnectionInstance` | Connections to outside systems and their configured instances |
21
22
  | `declareKnowledgeConnector`, `declareKnowledgeConnectorInstance` | Knowledge connectors and configured connector instances |
22
23
  | `declareDocumentCollection` | One connected document collection, such as a Microsoft 365 drive folder |
@@ -47,31 +48,63 @@ A package that declares Agents or Skills needs a person to install it; an instal
47
48
 
48
49
  ```mermaid
49
50
  flowchart TD
50
- ext["apps/extensions (@acme/extensions)<br/>index.ts: declarePackage<br/>studio.ts: loadFrontendCatalog"]
51
- org["@acme/organization<br/>package identity, VERSION, domain,<br/>Sales group, external application,<br/>access, Studio app, packageComponents"]
52
- lead["@acme/lead/ci<br/>Lead schema"]
53
- opp["@acme/opportunity/ci<br/>Opportunity schema"]
51
+ ext["apps/extensions (@acme/extensions)<br/>index.ts: declarePackage, deploy order<br/>studio.ts: loadFrontendCatalog"]
52
+ org["@acme/organization<br/>package identity, VERSION, domain,<br/>Sales group, external application,<br/>profiles, grants, Studio app"]
53
+ lead["@acme/lead/ci<br/>Lead schema, capabilities, policies"]
54
+ opp["@acme/opportunity/ci<br/>Opportunity schema, capabilities, policies"]
54
55
  qual["@acme/lead-qualification/ci<br/>tool, Skill, Agent, widget"]
55
56
  conv["@acme/lead-conversion/ci<br/>convert-lead workflow"]
56
57
  ext --> org
58
+ ext --> lead
59
+ ext --> opp
60
+ ext --> qual
61
+ ext --> conv
57
62
  org --> lead
58
63
  org --> opp
59
64
  org --> qual
60
- org --> conv
61
65
  ```
62
66
 
63
- The template keeps its CI code in three layers. `apps/extensions` is the composition root. It imports `@acme/organization` and one FQN from a `./ci` subpath. `@acme/organization` holds the package identity and everything shared across features, and it lists `packageComponents` in deploy order. Each entity or feature package exports a factory from its `./ci` subpath, for example `leadQualificationComponents({ application, audience, version })`, which takes the organization handles and the package version and returns its components in deploy order. A lower layer never imports `@acme/organization`.
67
+ The template keeps its CI code in three layers. `apps/extensions` is the composition root. It imports the components of `@acme/organization` and the factory of each package `./ci`, and lists every component in deploy order. `@acme/organization` holds the package identity and everything shared across features: the domain, the Sales Group, the external application, the profiles that grant the package capabilities, their grants and the Max Privileges. Each entity or feature package exports a factory from its `./ci` subpath, for example `leadQualificationComponents({ application, audience, version })`, which takes the organization handles and the package version and returns its components in deploy order. A lower layer never imports `@acme/organization`.
64
68
 
65
69
  This is the whole package entry:
66
70
 
67
71
  ```ts
68
- import { leadScoreCardContributionFqn } from "@acme/lead-qualification/ci"
69
- import { packageComponents, packageManifest } from "@acme/organization"
72
+ import { convertLeadComponents } from "@acme/lead-conversion/ci"
73
+ import {
74
+ leadQualificationComponents,
75
+ leadScoreCardContributionFqn
76
+ } from "@acme/lead-qualification/ci"
77
+ import { leadComponents } from "@acme/lead/ci"
78
+ import { opportunityComponents } from "@acme/opportunity/ci"
79
+ import {
80
+ acmeApplication,
81
+ crmDomain,
82
+ organizationComponents,
83
+ packageManifest,
84
+ salesDeskApp,
85
+ salesMembers,
86
+ VERSION
87
+ } from "@acme/organization"
70
88
  import { declarePackage } from "@collective-intelligence/extensions-sdk"
71
89
  import { declareFrontendCatalogContribution } from "@collective-intelligence/extensions-sdk-frontend"
72
90
 
73
91
  export default declarePackage({
74
- components: packageComponents,
92
+ components: [
93
+ crmDomain,
94
+ ...leadComponents({ domain: crmDomain, version: VERSION }),
95
+ ...opportunityComponents({ domain: crmDomain, version: VERSION }),
96
+ ...organizationComponents,
97
+ ...convertLeadComponents({
98
+ application: acmeApplication,
99
+ version: VERSION
100
+ }),
101
+ ...leadQualificationComponents({
102
+ application: acmeApplication,
103
+ audience: salesMembers,
104
+ version: VERSION
105
+ }),
106
+ salesDeskApp
107
+ ],
75
108
  hostedContributions: [
76
109
  declareFrontendCatalogContribution({
77
110
  compatibility: { react: "^19.0.0" },
@@ -84,7 +117,7 @@ export default declarePackage({
84
117
  })
85
118
  ```
86
119
 
87
- `apps/extensions/src/studio.ts` contains one line, `export { loadFrontendCatalog } from "@acme/organization"`. `ci package build` ships every export of that module to the browser, so it exports only the catalog loader.
120
+ `apps/extensions/src/studio.ts` contains one line, `export { loadFrontendCatalog } from "@acme/organization"`. `ci package build` resolves a relative `load` import against the declaration file, so the contribution is the one declaration in `apps/extensions`. The build ships every export of that module to the browser, so it exports only the catalog loader.
88
121
 
89
122
  One entity package such as `@acme/lead` holds the CI schema in `./ci`, the BFF code in `./server` and the React views in `./views`. The lint rule `ci-solution/subpath-imports` keeps React out of the CI release: `domain/` imports no other subpath, `ci/` imports no `headless/` or `views/`, and `headless/` and `views/` import no `server/`.
90
123
 
@@ -95,7 +128,7 @@ A widget needs two declarations. On the backend side, `declareStudioComponent` w
95
128
  To add a component to the template:
96
129
 
97
130
  1. Declare it in the `./ci` subpath of the package that owns it.
98
- 2. Add it to `packageComponents` after every component it references.
131
+ 2. Add it to `components` in `apps/extensions/src/index.ts` after every component it references.
99
132
  3. Bump `VERSION` in `packages/organization/acme/src/package.ts`. The package and every component share this one version.
100
133
 
101
134
  ## Lifecycle
@@ -129,17 +129,17 @@ 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. The template generates two policies for each of its schemas: reading needs CRM `read`, and writing needs CRM `manage`.
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`:
133
133
 
134
134
  ```ts
135
135
  declareAccessKnowledgeDataPolicy({
136
136
  definition: {
137
- capability: requires(capability, "manage"),
137
+ capability: access.requires(capabilities, "manage"),
138
138
  lifecycle: readonly,
139
139
  operation: "write",
140
- target,
140
+ target: leadSchemaFqn,
141
141
  },
142
- manifest: { fqn: `acme.app.policies.${name}-write`, version: VERSION },
142
+ manifest: { fqn: "acme.app.policies.leads-write", version },
143
143
  }),
144
144
  ```
145
145
 
@@ -160,7 +160,8 @@ export const managerProfile = declareAccessProfile({
160
160
  allow(core.platform.knowledge),
161
161
  allow(core.platform.agents),
162
162
  allow(core.platform.workflows),
163
- allow(crmCapabilities, "manage")
163
+ allow(leadCapabilitiesFqn, "manage"),
164
+ allow(opportunityCapabilitiesFqn, "manage")
164
165
  ],
165
166
  lifecycle: readonly
166
167
  },
@@ -169,7 +170,7 @@ export const managerProfile = declareAccessProfile({
169
170
  })
170
171
  ```
171
172
 
172
- The Sales rep profile holds the same gate with `platform.knowledge`, `platform.agents` and CRM `read`. It leaves out `platform.workflows` and CRM `manage`.
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
174
 
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:
175
176
 
@@ -181,7 +182,8 @@ export const applicationTokens = declareAccessMaxPrivileges({
181
182
  allow(core.platform.knowledge),
182
183
  allow(core.platform.agents),
183
184
  allow(core.platform.workflows),
184
- allow(crmCapabilities, "manage")
185
+ allow(leadCapabilitiesFqn, "manage"),
186
+ allow(opportunityCapabilitiesFqn, "manage")
185
187
  ],
186
188
  lifecycle: readonly
187
189
  },
@@ -111,11 +111,26 @@ 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 combines the declared components with the Lead score card widget for Studio:
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:
115
115
 
116
116
  ```ts
117
117
  export default declarePackage({
118
- components: packageComponents,
118
+ components: [
119
+ crmDomain,
120
+ ...leadComponents({ domain: crmDomain, version: VERSION }),
121
+ ...opportunityComponents({ domain: crmDomain, version: VERSION }),
122
+ ...organizationComponents,
123
+ ...convertLeadComponents({
124
+ application: acmeApplication,
125
+ version: VERSION
126
+ }),
127
+ ...leadQualificationComponents({
128
+ application: acmeApplication,
129
+ audience: salesMembers,
130
+ version: VERSION
131
+ }),
132
+ salesDeskApp
133
+ ],
119
134
  hostedContributions: [
120
135
  declareFrontendCatalogContribution({
121
136
  compatibility: { react: "^19.0.0" },
@@ -50,8 +50,9 @@ flowchart TD
50
50
  end
51
51
  tooling["tooling<br/>config"]
52
52
  web --> org
53
- ext -->|"passes packageComponents to declarePackage"| org
54
- org -->|"composes CI declarations in deploy order"| features
53
+ ext -->|"lists CI declarations in deploy order"| org
54
+ ext -->|"lists each ./ci"| features
55
+ org -->|"grants package capabilities"| features
55
56
  features --> entities
56
57
  entities --> modules
57
58
  modules --> tooling
@@ -78,7 +79,7 @@ A feature or entity package exposes only the subpaths it needs. Each subpath is
78
79
  | Subpath | Holds | Imported by |
79
80
  | ---------- | ----------------------------------------------------------------------------------------------------------- | --------------------------------------------- |
80
81
  | `domain` | Effect Schema models, resource contracts, schema FQNs, pure rules | every other subpath and other packages |
81
- | `ci` | CI declarations (extensions SDK) as factories over organization handles | `@acme/organization` |
82
+ | `ci` | CI declarations (extensions SDK) as factories over organization handles | `apps/extensions`, `@acme/organization` |
82
83
  | `api` | the package `HttpApi` under `/api/app`, its groups and tagged errors | `server`, `headless`, the app API composition |
83
84
  | `server` | the route Layer of the package `HttpApi` and its services | `apps/web/src/server` only |
84
85
  | `headless` | typed client, query options, XState machines, entity bindings, Realtime topics and hooks, simulated sources | `views` and the app |
@@ -100,41 +101,33 @@ Each template package exposes a different set:
100
101
 
101
102
  ## Features take their audience as a parameter
102
103
 
103
- 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 and passes them in, then lists every component in deploy order, where each component follows the components it references:
104
-
105
- ```ts
106
- export const packageComponents = [
107
- crmDomain,
108
- ...leadComponents({ domain: crmDomain, version: VERSION }),
109
- ...opportunityComponents({ domain: crmDomain, version: VERSION }),
110
- salesGroup,
111
- acmeApplication,
112
- crmCapabilities,
113
- ...crmPolicies,
114
- repProfile,
115
- managerProfile,
116
- ...salesGrants,
117
- applicationTokens,
118
- ...convertLeadComponents({ application: acmeApplication, version: VERSION }),
119
- ...leadQualificationComponents({
120
- application: acmeApplication,
121
- audience: salesMembers,
122
- version: VERSION
123
- }),
124
- salesDeskApp
125
- ]
126
- ```
127
-
128
- Because the organization package owns the content, `apps/extensions/src/index.ts` only declares the package:
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:
129
105
 
130
106
  ```ts
131
107
  export default declarePackage({
132
- components: packageComponents,
108
+ components: [
109
+ crmDomain,
110
+ ...leadComponents({ domain: crmDomain, version: VERSION }),
111
+ ...opportunityComponents({ domain: crmDomain, version: VERSION }),
112
+ ...organizationComponents,
113
+ ...convertLeadComponents({
114
+ application: acmeApplication,
115
+ version: VERSION
116
+ }),
117
+ ...leadQualificationComponents({
118
+ application: acmeApplication,
119
+ audience: salesMembers,
120
+ version: VERSION
121
+ }),
122
+ salesDeskApp
123
+ ],
133
124
  hostedContributions: [/* the Lead score card Studio widget */],
134
125
  manifest: packageManifest
135
126
  })
136
127
  ```
137
128
 
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.
130
+
138
131
  [Extensions](../develop/extensions.md) describes each kind of declaration, and [Access](../platform/access.md) explains the Access Profiles and Access Grants in that list.
139
132
 
140
133
  ## The web app layers
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@collective-intelligence/external-apps-client-sdk",
3
- "version": "0.3.4",
3
+ "version": "0.3.7",
4
4
  "description": "Framework-neutral client for Collective Intelligence external applications.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -26,6 +26,12 @@
26
26
  "import": "./dist/resources.js",
27
27
  "default": "./dist/resources.js"
28
28
  },
29
+ "./chat": {
30
+ "ci-source": "./src/chat.ts",
31
+ "types": "./dist/chat.d.ts",
32
+ "import": "./dist/chat.js",
33
+ "default": "./dist/chat.js"
34
+ },
29
35
  "./effect": {
30
36
  "ci-source": "./src/effect.ts",
31
37
  "types": "./dist/effect.d.ts",
@@ -56,24 +62,31 @@
56
62
  "ajv-formats": "3.0.1"
57
63
  },
58
64
  "peerDependencies": {
65
+ "@collective-intelligence/ai-core": "0.3.7",
59
66
  "effect": "^4.1.0"
60
67
  },
68
+ "peerDependenciesMeta": {
69
+ "@collective-intelligence/ai-core": {
70
+ "optional": true
71
+ }
72
+ },
61
73
  "devDependencies": {
74
+ "@collective-intelligence/ai-core": "0.3.7",
62
75
  "@effect/eslint-plugin": "0.3.2",
63
- "@effect/vitest": "4.1.2",
64
- "@oxlint/plugins": "1.90.0",
76
+ "@effect/vitest": "4.1.4",
77
+ "@oxlint/plugins": "1.94.0",
65
78
  "@punks/lints": "0.2.0",
66
79
  "@types/bun": "1.4.2",
67
80
  "@typescript-eslint/utils": "8.22.0",
68
- "effect": "4.1.2",
81
+ "effect": "4.1.4",
69
82
  "eslint": "9.39.5",
70
83
  "oxfmt": "0.66.0",
71
- "oxlint": "1.90.0",
84
+ "oxlint": "1.94.0",
72
85
  "tsdown": "0.22.14",
73
86
  "tsprover": "0.0.2",
74
87
  "typescript": "5.9.3",
75
88
  "ultracite": "7.10.7",
76
89
  "vitest": "5.0.2"
77
90
  },
78
- "gitHead": "dc0b867b4eb6fef705bc55ed670db4ac7deeaf4a"
91
+ "gitHead": "fd4f8fcacdfa0fd7e127b9d75bf3a00e7283829f"
79
92
  }