@collective-intelligence/external-apps-client-sdk 0.0.0-stage → 0.1.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/README.md +123 -2
- package/dist/index.d.ts +892 -0
- package/dist/index.js +725 -0
- package/dist/resources-B9JIzIvl.d.ts +704 -0
- package/dist/resources-BYm1KWAZ.js +8219 -0
- package/dist/resources.d.ts +2 -0
- package/dist/resources.js +2 -0
- package/package.json +53 -4
package/README.md
CHANGED
|
@@ -1,3 +1,124 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@collective-intelligence/external-apps-client-sdk`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Browser-safe, React-free APIs for Collective Intelligence external applications.
|
|
4
|
+
The root entrypoint provides federated login, typed CI operations, and direct or
|
|
5
|
+
same-origin proxy transports. It contains no confidential credentials or
|
|
6
|
+
framework state.
|
|
7
|
+
|
|
8
|
+
`createFederatedAuth` implements the public OAuth authorization-code flow with
|
|
9
|
+
PKCE. It validates same-origin return targets, keeps the login transaction in
|
|
10
|
+
session storage, exchanges the callback code, tracks token expiry, and supports
|
|
11
|
+
logout and reauthorization. A server runtime remains responsible for any
|
|
12
|
+
confidential proxy credentials and durable application sessions.
|
|
13
|
+
|
|
14
|
+
`createClient` binds a typed transport to CI operations for agents, attachments,
|
|
15
|
+
context, Knowledge, runs, skills, and workflows. Call `forOrganization` to bind
|
|
16
|
+
those operations to one organization.
|
|
17
|
+
|
|
18
|
+
For `workflows_invoke`, pass exactly one target: `workflowId` for a workflow
|
|
19
|
+
UUID or `workflowFqn` for its stable fully qualified name. Both forms use the
|
|
20
|
+
same organization-scoped run route and remain subject to the application's
|
|
21
|
+
workflow binding.
|
|
22
|
+
|
|
23
|
+
Skill and workflow runs return a `runId` without waiting for the run to
|
|
24
|
+
finish. `client.forOrganization(id).runs.follow({ runId })` (or the standalone
|
|
25
|
+
`followRun`) polls the run snapshot and its event pages until a terminal event
|
|
26
|
+
or status, then resolves with the last event page it read. It reads the
|
|
27
|
+
snapshot before each page, so once the snapshot is terminal that page holds the
|
|
28
|
+
run's last events. It waits up to
|
|
29
|
+
`DEFAULT_FOLLOW_RUN_DEADLINE_MS` (10 minutes: the 5-minute server AI deadline
|
|
30
|
+
plus slack) before throwing `Run did not finish`; pass `deadlineMs` to change
|
|
31
|
+
it and `signal` to cancel. Polling starts every `idleMs` (50 ms) and backs off
|
|
32
|
+
to at most one second while no new events arrive.
|
|
33
|
+
|
|
34
|
+
The `@collective-intelligence/external-apps-client-sdk/resources` entrypoint
|
|
35
|
+
provides the portable resource contracts and `createResourceClient`. A resource
|
|
36
|
+
client supports filtering, sorting, text search, page or cursor pagination,
|
|
37
|
+
opaque IDs and revisions, optimistic concurrency, idempotency, soft deletion,
|
|
38
|
+
restore, and hard deletion according to the resource's declared capabilities.
|
|
39
|
+
|
|
40
|
+
## Common entity CRUD
|
|
41
|
+
|
|
42
|
+
Use the explicit `protocol: "entity"` option for the common page-based CRUD API.
|
|
43
|
+
Both the root and `/resources` entrypoints export these builders:
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import {
|
|
47
|
+
createEntityHttpTransport,
|
|
48
|
+
createResourceClient
|
|
49
|
+
} from "@collective-intelligence/external-apps-client-sdk"
|
|
50
|
+
|
|
51
|
+
const leads = createResourceClient({
|
|
52
|
+
definition: leadContract,
|
|
53
|
+
protocol: "entity",
|
|
54
|
+
transport: createEntityHttpTransport({
|
|
55
|
+
authentication: { auth, mode: "federated" },
|
|
56
|
+
destination: {
|
|
57
|
+
endpoint: "https://customer.example/api/resources/leads",
|
|
58
|
+
kind: "gateway"
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
const action = {
|
|
64
|
+
expectedRevision: record.revision,
|
|
65
|
+
id: record.id,
|
|
66
|
+
idempotencyKey: crypto.randomUUID(),
|
|
67
|
+
value: { status: "qualified" }
|
|
68
|
+
}
|
|
69
|
+
const result = await leads.update(action)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
`leadContract` supplies portable entity/create/update JSON schemas and capabilities.
|
|
73
|
+
`auth` is the configured federated authentication instance. A customer gateway
|
|
74
|
+
using its own CI-derived browser session can use
|
|
75
|
+
`authentication: { mode: "server_delegated" }` instead.
|
|
76
|
+
For direct CI, configure `destination: { kind: "ci", tenantUrl, schemaFqn,
|
|
77
|
+
organizationId }`; the schema FQN selects the CI resource route. These identifiers
|
|
78
|
+
select the route and organization header; the server still authenticates and
|
|
79
|
+
authorizes access. They are configuration, never mutation-body authority.
|
|
80
|
+
|
|
81
|
+
`createDelegatedApplicationRuntime` owns the sealed-cookie session machine,
|
|
82
|
+
including identity, login, logout, and `runs_follow`. `createFixedWorkflowClient`
|
|
83
|
+
posts a Fixed workflow BFF route and returns `{ runId }`.
|
|
84
|
+
|
|
85
|
+
The common client exposes `list`, `get`, `create`, `update`, and `delete`.
|
|
86
|
+
`delete` calls the explicit soft-delete route. Every mutation requires an operation
|
|
87
|
+
key; update/delete also require the revision originally edited. Reads accept an
|
|
88
|
+
optional `{ signal }`. Mutations are independent of view unmount cancellation.
|
|
89
|
+
Transport calls send once and do not retry. Retain `action` unchanged for an
|
|
90
|
+
explicit same-action resubmission; a different edit requires a new key.
|
|
91
|
+
|
|
92
|
+
Failures preserve safe server errors and correlation IDs. `error.outcome` is
|
|
93
|
+
`not_dispatched` for local input/authentication/cancellation failures, `rejected`
|
|
94
|
+
for an explicit backend rejection, or `uncertain` when a dispatched write has no
|
|
95
|
+
valid response. Uncertainty does not prove rollback. Known response fields are
|
|
96
|
+
validated without coercion; compatible extra entity fields are accepted, while
|
|
97
|
+
an incompatible record fails the whole result, including a page.
|
|
98
|
+
|
|
99
|
+
During migration, omitting `protocol` retains the distinct legacy resource facade,
|
|
100
|
+
including its optional update keys, cursor pagination and explicit lifecycle
|
|
101
|
+
methods. Existing hard-delete behavior is never relabeled as common `delete`.
|
|
102
|
+
|
|
103
|
+
## Workspace development
|
|
104
|
+
|
|
105
|
+
The repository's [Effect demo](../../../demo/external-app-effect/README.md)
|
|
106
|
+
documents local Gateway, proxied CI, and direct CI entity bindings. Its shared
|
|
107
|
+
contract package emits the browser-safe contract consumed by both demo apps.
|
|
108
|
+
|
|
109
|
+
Each package export declares an opt-in `ci-source` condition for workspace
|
|
110
|
+
development. Local TypeScript, Bun, or bundler consumers can enable that
|
|
111
|
+
condition to resolve the matching `src` facade without rebuilding this package.
|
|
112
|
+
Consumers that do not explicitly enable `ci-source`, including packed and
|
|
113
|
+
published npm consumers, continue to resolve the generated `dist` JavaScript
|
|
114
|
+
and declarations.
|
|
115
|
+
|
|
116
|
+
## Enum value compatibility
|
|
117
|
+
|
|
118
|
+
Repository-owned enum values use lower `snake_case`. Update gateway manifests,
|
|
119
|
+
request payloads and saved resource filters together with their consumers. For
|
|
120
|
+
example, resource filters use `starts_with` and `is_null`, lifecycle operation
|
|
121
|
+
values use `soft_delete` and `hard_delete`, and gateway principal kinds use
|
|
122
|
+
`detached_user` and `service_principal`. Public method and capability property
|
|
123
|
+
names such as `softDelete` remain unchanged. External HTTP, OAuth, JSON Schema
|
|
124
|
+
and provider values retain their required spelling at their adapter boundaries.
|