@collective-intelligence/extensions-sdk-frontend-react 0.2.0 → 0.2.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.
package/AGENTS.md ADDED
@@ -0,0 +1,26 @@
1
+ # `@collective-intelligence/extensions-sdk-frontend-react`: agent guide
2
+
3
+ Host-neutral React contracts of Collective Intelligence (CI) Studio and
4
+ Dashboard contributions, and the Studio API. The package `README.md` holds
5
+ the full API.
6
+
7
+ ## Rules
8
+
9
+ - Import each contribution kind from its subpath (`/studio`, `/dashboard`,
10
+ `/workflow`, `/ui-react`, `/frontend`), and the `StudioApi` service from
11
+ `/effect`.
12
+ - Keep one `effect` (`^4.1.0`) in the extension package. It is a required
13
+ peer. `react` and `react-dom` come from the host.
14
+ - Call the Studio API from Effect code through `StudioApi`. A Studio Widget
15
+ gives `layerStudioApi()` no base URL: the Studio Host binds the client.
16
+ - Decode `StudioApiError.body` with a Schema before use; it is `unknown`.
17
+
18
+ ## Index
19
+
20
+ - [docs/effect.md](docs/effect.md): read when a widget or view calls the
21
+ Studio API from Effect, or you give the base URL of a test host.
22
+ - [docs/errors.md](docs/errors.md): read when you handle a failed Studio API
23
+ call.
24
+ - [skills/extensions-sdk-frontend-react-move-to-effect/SKILL.md](skills/extensions-sdk-frontend-react-move-to-effect/SKILL.md):
25
+ run when Effect code calls the `/studio-api` client through
26
+ `Effect.tryPromise`, or lint reports `ci-solution/effect-subpath`.
package/docs/effect.md ADDED
@@ -0,0 +1,48 @@
1
+ # Studio API on Effect
2
+
3
+ `/effect` exports the `StudioApi` service. It has one method per operation of
4
+ the `/studio-api` client, with the same name, request options and success
5
+ type. It calls the shared client of `/studio-api`, so a Studio Widget calls
6
+ the client that the Studio Host binds.
7
+
8
+ ```ts
9
+ import type { StudioViewContext } from "@collective-intelligence/extensions-sdk-frontend-react/studio"
10
+
11
+ import {
12
+ layerStudioApi,
13
+ StudioApi
14
+ } from "@collective-intelligence/extensions-sdk-frontend-react/effect"
15
+ import { studioPublishedViewScope } from "@collective-intelligence/extensions-sdk-frontend-react/studio"
16
+ import * as Effect from "effect/Effect"
17
+
18
+ const runCount = (context: StudioViewContext) =>
19
+ Effect.gen(function* () {
20
+ const api = yield* StudioApi
21
+ const page = yield* api.studioWorkflowRunsList(
22
+ studioPublishedViewScope(context)
23
+ )
24
+ return page.data.length
25
+ }).pipe(
26
+ Effect.catchTag("StudioApiError", (error) => Effect.fail(error.status)),
27
+ Effect.provide(layerStudioApi())
28
+ )
29
+ ```
30
+
31
+ ## Rules
32
+
33
+ - A Studio Widget calls `layerStudioApi()` with no base URL; the Host binds
34
+ the client to its Backend and refuses other URLs.
35
+ - A host that binds no client, such as a test or a preview, gives the URL of
36
+ its Backend: `layerStudioApiConfig({ baseUrl: Config.String("STUDIO_API_BASE_URL") })`.
37
+ - The service sets `client`, `fetch`, `baseUrl`, `signal`, `responseStyle` and
38
+ `throwOnError`. Set headers and the other request options per call.
39
+ - An interruption of the fiber aborts the request.
40
+ - A Studio Extension release bundles `/effect` and keeps `/studio-api`
41
+ external; the release build needs a `ci` CLI that bundles an SDK `/effect`
42
+ entry.
43
+ - `/effect` imports each `/studio-api` operation by name, so it loads only
44
+ with a Studio Host that ships this SDK version or a later one.
45
+ - A Dashboard release bundles its own copy of the client, and no Host binds
46
+ it.
47
+
48
+ Errors: [errors.md](errors.md).
package/docs/errors.md ADDED
@@ -0,0 +1,17 @@
1
+ # Errors
2
+
3
+ `StudioApi` fails with tagged errors of `/effect`:
4
+
5
+ | Failure | Result |
6
+ | ----------------------------------------------------------------------- | ----------------------------------------------------------- |
7
+ | The Backend answers an error | `StudioApiError` with `status` and `body` (JSON, else text) |
8
+ | The request does not reach the Backend, or an OK answer is not readable | `StudioApiTransportError` with `cause` |
9
+ | Bad input, such as a body that JSON cannot write | `TypeError` defect; the request does not leave |
10
+ | The fiber is interrupted | The request is aborted |
11
+
12
+ ## Rules
13
+
14
+ - `body` is `unknown`: a status outside the generated error map, such as a
15
+ 502 of a proxy, holds any body. Decode it with a Schema before use.
16
+ - Branch with `Effect.catchTag("StudioApiError", ...)` and on `status`.
17
+ - Show the user your own text for `StudioApiTransportError`.
package/package.json CHANGED
@@ -1,12 +1,15 @@
1
1
  {
2
2
  "name": "@collective-intelligence/extensions-sdk-frontend-react",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Public hosted React contribution contracts for Collective Intelligence extensions.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "files": [
8
8
  "dist",
9
- "README.md"
9
+ "README.md",
10
+ "AGENTS.md",
11
+ "docs",
12
+ "skills"
10
13
  ],
11
14
  "main": "./dist/index.js",
12
15
  "types": "./dist/index.d.ts",
@@ -77,8 +80,8 @@
77
80
  "type-check": "bun check && bun check -p tsconfig.type-tests.json"
78
81
  },
79
82
  "dependencies": {
80
- "@collective-intelligence/extensions-sdk": "0.2.0",
81
- "@collective-intelligence/extensions-sdk-frontend": "0.2.0"
83
+ "@collective-intelligence/extensions-sdk": "0.2.1",
84
+ "@collective-intelligence/extensions-sdk-frontend": "0.2.1"
82
85
  },
83
86
  "peerDependencies": {
84
87
  "@collective-intelligence/ui-react": "0.2.0",
@@ -119,5 +122,5 @@
119
122
  "vitest": "5.0.2",
120
123
  "es-module-lexer": "2.3.2"
121
124
  },
122
- "gitHead": "399369a97e85b54b43aeac887e7ba9c960cb7505"
125
+ "gitHead": "7b3d604c39db3969749b14174d660a814a1f3a72"
123
126
  }
@@ -0,0 +1,27 @@
1
+ ---
2
+ name: extensions-sdk-frontend-react-move-to-effect
3
+ description: Move Studio API calls in Effect code to the `StudioApi` service of `@collective-intelligence/extensions-sdk-frontend-react/effect`. Use when Effect code calls the `/studio-api` client through `Effect.tryPromise` or `Effect.promise`, maps its errors by hand, or lint reports `ci-solution/effect-subpath`.
4
+ ---
5
+
6
+ # Move Studio API calls to `StudioApi`
7
+
8
+ Reference: [effect.md](../../docs/effect.md), [errors.md](../../docs/errors.md).
9
+
10
+ ## Steps
11
+
12
+ 1. **Find the wrapped calls.** Search Effect modules for imports of
13
+ `extensions-sdk-frontend-react/studio-api` and for `Effect.tryPromise` or
14
+ `Effect.promise` around its operations. Done when you have each call site.
15
+ 2. **Rewrite each call** as `yield* StudioApi` and the method of the same
16
+ name, with the same request options. Done when no Effect module imports
17
+ `/studio-api`.
18
+ 3. **Map the errors.** Replace hand-written mapping with
19
+ `Effect.catchTag("StudioApiError", ...)` and
20
+ `Effect.catchTag("StudioApiTransportError", ...)`; decode `body` with a
21
+ Schema. Done when no code reads `body` without a decode.
22
+ 4. **Provide the layer once.** In a Studio Widget, `layerStudioApi()` with no
23
+ base URL; in a test or preview host, `layerStudioApiConfig` with the
24
+ Backend URL. Done when each program has the layer at its root.
25
+ 5. **Verify.** Run the type-check, the tests and oxlint with the
26
+ `recommended` config of `@collective-intelligence/lint`. Build the release
27
+ with a `ci` CLI that bundles `/effect`. Done when all pass.