@plitzi/sdk-interactions 0.38.14 → 0.38.16

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/CHANGELOG.md CHANGED
@@ -1,5 +1,178 @@
1
1
  # @plitzi/sdk-interactions
2
2
 
3
+ ## 0.38.16
4
+
5
+ ### Patch Changes
6
+
7
+ - 9cfdccb: ## Security
8
+
9
+ - **A site's credential reads nothing of the space over MCP** (`@plitzi/sdk-mcp`): the `render` token every published
10
+ page embeds — and a self-hosting `host` key — resolved to a grant naming the space, and the MCP served every read
11
+ under it: the unpublished draft, the change history with who made each change and every value before and after, the
12
+ functions' source, the space's private data, its action documents and connectors. Only an `agent` grant attaches a
13
+ space now; any other is a connection with no space (`plitzi_render` and the public guides), told so in the words
14
+ `NO_SPACE_ATTACHED` already uses. A deployment whose `getGrant` answered other scopes for reading must issue agent
15
+ grants for them.
16
+
17
+ ## Agents
18
+ - **`plitzi space watch`** (`@plitzi/cli`): the space read again on every save of `src/space/`, `src/plugins/`,
19
+ `src/data/` or `public/data/`, and only what changed said — what the save did to the space element by element, the
20
+ findings and warnings it brought and fixed (one that only moved down its file is the same one), a save that changed
21
+ nothing, or that the space stopped authoring and why. `--json` is one event a line (`ready`, `pass`, `refused`,
22
+ `error`), for an agent to run in the background instead of `author` and `space lint` after every edit. Each pass reads
23
+ the space in a process of its own (`space watch-pass`, hidden). `space lint`'s reading is `spaceFindings`, shared.
24
+ - **A space's activity, followed** (`@plitzi/sdk-shared`, `@plitzi/sdk-mcp`, `@plitzi/cli`): what happened on a space
25
+ after a cursor — its draft changed (a person in the builder, an agent, the autofix), a version went out, a server
26
+ action failed or was refused — and, with nothing yet, waited for, up to 50 s. One vocabulary,
27
+ `@plitzi/sdk-shared/activity` (`SpaceActivity`, `SpaceActivityPage`, `activityLine`, `isSpaceActivityPage`, the
28
+ limits); the reader's own writes left out and counted (`skippedMine`), `mine` keeps them.
29
+ - **`plitzi_activity { after, wait, limit, mine }`** (`@plitzi/sdk-mcp`), on the new `getActivity` adapter
30
+ (`SSRAdapters`). The listing budget is 78k (was 77k) for it.
31
+ - **`plitzi space activity [--follow] [--after <cursor>] [--mine] [--limit <n>] [--json]`** (`@plitzi/cli`), over
32
+ the platform's `GET /spaces/:spaceId/activity`; `--follow` stays, one page a line with `--json`, and asks again
33
+ when the platform does not answer.
34
+ - **The people in the builder see the agent work** (`@plitzi/sdk-server`, `@plitzi/sdk-shared`, `@plitzi/sdk-mcp`,
35
+ `@plitzi/plitzi-builder`): an agent grant carries the application the member connected (`Grant.client`,
36
+ `StoredSpaceToken.client`, `SSRGrant.client`), and every MCP write `SSRWriteContext.client` — the history's
37
+ `client` for an agent, which was never set. A collaborator may be an agent (`SubscriptionCollaborator.agent`): the
38
+ builder draws it as a robot, names it `Claude · for ana` (`collaboratorTitle`) in the header, on the canvas and in
39
+ its notices. The deployment announces it — Plitzi's joins it on a write, selects what it changed, and lets it go
40
+ after a minute of nothing. `activityLine` names it the same way (`Claude for ana over the MCP, …`), so
41
+ `plitzi space activity` says which application wrote.
42
+ - A tool may declare `documents: false` (`ToolSpec`): the host loads none of the space for it, and passes the call's
43
+ abort signal through `ToolContext.activity`.
44
+
45
+ ## Authoring
46
+ - **A file that does not parse is said at its line under any loader** (`@plitzi/sdk-authoring`): `moduleProblem` read
47
+ the first line of the error, and an esbuild transform (tsx, vitest) puts only `Transform failed with 1 error:` there
48
+ — the file, line and what is wrong are on the next. A line of the message that points at a file of the project is
49
+ now the problem (`src/space/hero.ts:139: Expected "}" but found ";"`), the project's root matched as given and as it
50
+ is on disk (`/var/…` and `/private/var/…` on macOS).
51
+
52
+ ## Testing
53
+ - **`unusedPort` is chosen where the system never hands one out** (`@plitzi/sdk-server`): it answered a port the system
54
+ had just handed out (`listen(0)`), from the ephemeral range every outgoing connection takes its local port from — so
55
+ another worker's request could take it before the test listened, and CI failed `runtime.test.ts` with `EADDRINUSE`
56
+ (the page server then ends the process). It is a free port below that range now, at random, checked first.
57
+
58
+ ## Docs
59
+ - **A self-hosted runtime's endpoints go in `data`**, as 0.38.15 moved them: `docs/en/runtimes.md`, the
60
+ `10-runtime` example and the website still put `served.stage` in `preAuth`, before the cross-site guard.
61
+ - New: `docs/en/activity.md`; `space watch` in `docs/en/agent-tooling.md`'s loop; the CLI README, the CLI skill, the
62
+ generated project's `AGENTS.md`, the MCP guide and README.
63
+
64
+ - Updated dependencies [9cfdccb]
65
+ - @plitzi/sdk-auth@0.38.16
66
+ - @plitzi/sdk-event-bridge@0.38.16
67
+ - @plitzi/sdk-shared@0.38.16
68
+
69
+ ## 0.38.15
70
+
71
+ ### Patch Changes
72
+
73
+ - 6cdd5cf: ## Security
74
+
75
+ - **A write another site caused is refused, cookie or none** (`@plitzi/sdk-server`, `@plitzi/sdk-shared`): the page
76
+ server guarded nothing it answers past `/auth` — a server action (`/_action`), a realtime publish, a space's `/fn/`
77
+ route, its runtime's endpoints, the deployment's own `data` stages, the adapter-only `loginPath`, `logoutPath` and
78
+ `exchangePath`. A plain `text/plain` POST from any page open in the same browser ran them, with the visitor's session
79
+ cookie when there was one (`SameSite=None` off this machine) and, in a project nobody signs in to, as whoever holds
80
+ the server's own credentials. Every unsafe request a browser says another site caused (`Sec-Fetch-Site: cross-site`,
81
+ or a foreign `Origin`) is now refused `403 reason: 'foreign'`, saying how to allow it: `crossSiteWrites.origins`
82
+ (with `auth`, `identity.platformOrigins` too) and `crossSiteWrites.paths` for a form other sites post to by design.
83
+ `Authorization`, and callers that are not browsers — webhooks, scripts — pass as before. One rule for this and the
84
+ sign-in check (`crossSiteRequest`, `csrf.ts`). A self-hosted runtime's endpoints now sit where the platform forwards a
85
+ space's — after the auth chain and this guard (`data`, was `preAuth`).
86
+
87
+ ## Testing
88
+ - **`page check` and `page shot` anywhere the project is served** (`@plitzi/cli`): `--url <origin>` for a second server
89
+ of it, staging or a deploy, instead of `npm start`'s port; `page check --space <module>` holds the pages to that space
90
+ instead of the project's — an agent's page — authored with `authorIsolated`.
91
+ - **A route with a query is checked as its page** (`@plitzi/cli`): `page check "/?v=2"` matched the query as part of
92
+ the path, found no page, and checked the space's "not found" page in its place.
93
+
94
+ - **What an element that chooses its children draws is checked** (`@plitzi/sdk-authoring`, `@plitzi/cli`): with
95
+ `choosesChildren`, the page checks owed none of its children — and checked none of them either: a dashboard drawing
96
+ three panels reported `checked: 1`. Each child it may draw, and what is inside one under no condition of its own,
97
+ now carries `shownWith` (the child it comes with) on its handle: once that child is on screen it and everything
98
+ named in it are owed like the rest of the page, and `checked` counts them. `onScreenIfChosen(handles, page)` lists
99
+ them.
100
+ - **A page that met a server error is looked at once more** (`@plitzi/cli`): `page check` and `verify` failed a page
101
+ for a `500` from somebody else's service having a bad second (`/fn/<space>/weather`), and passed on the next run with
102
+ nothing changed. A page whose requests got a `5xx` is checked again once; its report is the second look, and says
103
+ what failed the first time (`retriedAfter`). A `4xx` fails the same way twice, and is never retried.
104
+
105
+ ## Plugins
106
+ - **`useNotify`** (`@plitzi/plitzi-sdk`): a plugin shows the page's notifications — `notify('Deleted 79 recordings', {
107
+ appearance: 'danger' })` — the same toasts an `addNotification` step shows, in the space's theme and `notifications`
108
+ look, with no trigger, flow or `window` event of the space's to wire. The step's vocabulary (`NOTIFICATION_PLACEMENTS`,
109
+ `NOTIFICATION_APPEARANCES`, `NOTIFICATION_DEFAULTS`) is one list in `@plitzi/sdk-shared`, read by both.
110
+ - **`appearance: 'danger'` looks like one** (`@plitzi/plitzi-sdk`): it reached the toast library as a type it does not
111
+ know, so a danger notification showed neither the error icon nor the colour `notifications.danger` sets.
112
+ A value a notification does not take — from a flow, or a plugin in plain JavaScript — is set aside by name and said
113
+ in the console, rather than shown as the default in silence (`readNotificationOptions`, `@plitzi/sdk-shared`).
114
+ - **`useServerAction`** (`@plitzi/plitzi-sdk`, `@plitzi/sdk-authoring`, `@plitzi/sdk-interactions`,
115
+ `@plitzi/sdk-server`): a plugin runs one of the space's server actions, awaited —
116
+ `useServerAction<typeof habitDone>('habits-done')({ id })` answers `{ ok, output }` or `{ ok: false, reason, error }`
117
+ — through the `runServerAction` step itself: the same access, refusals, session handling and dev-tools entry.
118
+ `defineAction` keeps the literal types of its `call` way in, so the input is typed by the fields it declares (the
119
+ required ones required); `taskAction` types both ends from the task's `run`, and `FunctionTask<T, R>` takes what
120
+ `run` answers. `CallInputOf` / `CallOutputOf` read them. One operation is one action, never a `case` in one route.
121
+ What a run answers is typed (`ServerActionStatus`): a status the server never uses reads as a run that did not
122
+ complete, never as one that did.
123
+ The key those types ride under (`CALL_TYPES`) is exported, by `@plitzi/sdk-shared` and `@plitzi/sdk-authoring` with
124
+ `TypedActionEntry`, `CallInputOf` and `CallOutputOf`: a package that emits declarations could not write the type of an
125
+ action it exports (`TS4023` on every `export const actions = [defineAction(…)]`).
126
+ - **A plugin is drawn on the server first** (docs): a preference per device belongs in kept state (`keepState`,
127
+ `paintedState`) as a bound prop, never read from `localStorage` while rendering — React discards the whole tree on the
128
+ mismatch, and only in the browser of whoever saved something. `@plitzi/plitzi-ui` is not the page's: a plugin
129
+ importing it bundles its own copy, with its own contexts and its own look. The authoring skill's `plugin-reach.md`
130
+ says what a plugin says and to whom: a notification, another element (an event and the space's flow), a server
131
+ action, shared state, other pages.
132
+
133
+ ## Realtime
134
+ - **A channel that retains** (`@plitzi/sdk-shared`, `@plitzi/sdk-server`, `@plitzi/sdk-elements`): declared
135
+ `retain: true` (with `publish: 'server'`, which authoring requires), the server keeps the latest message of each type
136
+ on a topic — said by `ctx.publish` or a flow's `realtime.publish` — and hands them to every page that joins, marked
137
+ `retained`. A page reads them as `<channel>.retained.<type>`, a plugin as `useChannel(topic).retained`, the newest of
138
+ a type holding whichever order they arrive in; `null` forgets a type. Kept in the store the actions' `kv` uses (beside
139
+ the grants, by compare-and-swap), so every replica hands out the same; a topic keeps at most 64 types and 512 KB, and
140
+ a publish past that is refused before anything is sent. State every screen shares is one publish and one binding —
141
+ no kv key, initial read or copy in `state` of the project's own. The fleet store `realtime.grants` is now
142
+ `realtime.kv`.
143
+ - **The MCP writes every field a channel takes** (`@plitzi/sdk-mcp`): `patchSettings`'s channel had no `grant` — which
144
+ the guide taught — nor `retain` or the limits, so an agent could not declare a private channel at all. All are there
145
+ now, and the guide says what `retain` is for and that `channel_<id>.retained` holds it.
146
+
147
+ ## Authoring
148
+ - **`plitzi explain` knows every `@plitzi` package installed** (`@plitzi/cli`): a name that was not
149
+ `@plitzi/sdk-authoring`'s (`createServer`, `createJsonAdapters`, `useChannel`) was answered as the project's own code,
150
+ to `grep` in `src/`. It is read from the published types of every one installed, through their re-exports and entry
151
+ points (`@plitzi/sdk-server/handlers`), and a name two packages export — `createServer` is sdk-server's and sdk-mcp's
152
+ — is answered with both.
153
+
154
+ - **A space module somebody else wrote, authored where it reaches nothing** (`@plitzi/sdk-authoring`):
155
+ `authorIsolated(file, { timeoutMs })` of `@plitzi/sdk-authoring/node` runs `authorSpace` on it in a process Node's
156
+ permission model holds to reading the module's folder and its packages — no file written, no process started, no
157
+ variable of the caller's environment — kills one that runs too long, and validates what it answers again, so a forged
158
+ answer gains nothing. A refusal comes back as `authorSpace` says it, with the problems as data.
159
+ - **Pages an agent writes, served** (`@plitzi/sdk-server`): `createAuthoringHost({ dir, frameAncestors })` serves each
160
+ space it is handed at an address of its own (`put(space, { id }) → /?__pt=<id>`) as a draft of its one space, kept in
161
+ `dir` across restarts; `drop(id)` forgets one, and anything else answers `404` saying where the pages are.
162
+ - **A space is chosen by host or credential** (`@plitzi/sdk-server`, docs): `getSpaceDeployment` is asked on every
163
+ request, and what a page fetches after it carries nothing of its address but the host — a space chosen by the page's
164
+ query or path lost everything it asked for, and `/_plitzi/space/<hash>.json` answered a bare `404`. The contract and
165
+ the README say so (the README offered "by path prefix"), and that `404` says why.
166
+
167
+ - **`plitzi explain on` says how to read what a trigger carries** (`@plitzi/sdk-authoring`): its doc sat above a
168
+ helper, so `explain` printed only the signature. It now leads with `[named('picked', on('onPick')), …('{{ picked.seat
169
+ }}')]`, and the CLI skill's plugin section says the same.
170
+
171
+ - Updated dependencies [6cdd5cf]
172
+ - @plitzi/sdk-auth@0.38.15
173
+ - @plitzi/sdk-event-bridge@0.38.15
174
+ - @plitzi/sdk-shared@0.38.15
175
+
3
176
  ## 0.38.14
4
177
 
5
178
  ### Patch Changes
@@ -9,5 +9,5 @@ export type ActionInteractionsProps = {
9
9
  * is the server's to decide from the space's own documents, so a page can only ever run what that space already
10
10
  * declared.
11
11
  */
12
- declare const ActionInteractions: ({ children }: ActionInteractionsProps) => ReactNode;
12
+ declare const ActionInteractions: ({ children }: ActionInteractionsProps) => import('react').JSX.Element;
13
13
  export default ActionInteractions;
@@ -1,14 +1,15 @@
1
1
  import e from "../../InteractionsContext.mjs";
2
2
  import { actionsCallbacks as t } from "./callbacks.mjs";
3
- import { use as n, useCallback as r, useMemo as i } from "react";
4
- import { pConsole as a } from "@plitzi/sdk-shared/devTools/utils/PlitziConsole";
5
- import { toBuilderParams as o, toInteractionCallbacks as s } from "@plitzi/sdk-shared/authoring/builder";
6
- import { invalidateAfterWrite as c } from "@plitzi/sdk-shared/queries";
7
- import { jsx as l, jsxs as u } from "react/jsx-runtime";
8
- import { recordActionProgress as d, recordActionRun as f, registerActionCanceller as p, releaseActionCanceller as m, updateActionRun as h, useCommonStore as g } from "@plitzi/sdk-shared/store";
9
- import { authFailureFromResponse as _, reportAuthFailure as v } from "@plitzi/sdk-shared/auth";
3
+ import { ServerActionContext as n, endedStatusOf as r } from "./ServerActionContext.mjs";
4
+ import { use as i, useCallback as a, useMemo as o } from "react";
5
+ import { pConsole as s } from "@plitzi/sdk-shared/devTools/utils/PlitziConsole";
6
+ import { toBuilderParams as c, toInteractionCallbacks as l } from "@plitzi/sdk-shared/authoring/builder";
7
+ import { invalidateAfterWrite as u } from "@plitzi/sdk-shared/queries";
8
+ import { jsx as d, jsxs as f } from "react/jsx-runtime";
9
+ import { recordActionProgress as p, recordActionRun as m, registerActionCanceller as h, releaseActionCanceller as g, updateActionRun as _, useCommonStore as v } from "@plitzi/sdk-shared/store";
10
+ import { authFailureFromResponse as y, reportAuthFailure as b } from "@plitzi/sdk-shared/auth";
10
11
  //#region src/sources/ActionsSource/ActionInteractions.tsx
11
- var y = (e) => Array.isArray(e) ? e : void 0, b = async (e, t) => {
12
+ var x = (e) => Array.isArray(e) ? e : void 0, S = async (e, t) => {
12
13
  let n = e.getReader(), r = new TextDecoder(), i = "";
13
14
  for (;;) {
14
15
  let { done: e, value: a } = await n.read();
@@ -28,7 +29,7 @@ var y = (e) => Array.isArray(e) ? e : void 0, b = async (e, t) => {
28
29
  } catch {}
29
30
  }
30
31
  }
31
- }, x = (e) => {
32
+ }, C = (e) => {
32
33
  if (!e) return {};
33
34
  if (typeof e == "object") return e;
34
35
  try {
@@ -37,44 +38,44 @@ var y = (e) => Array.isArray(e) ? e : void 0, b = async (e, t) => {
37
38
  } catch {
38
39
  return {};
39
40
  }
40
- }, S = {
41
+ }, w = {
41
42
  status: "failed",
42
43
  reason: "failed",
43
44
  runId: "",
44
45
  output: {}
45
- }, C = (e, t) => e.signal.aborted ? {
46
+ }, T = (e, t) => e.signal.aborted ? {
46
47
  status: "aborted",
47
48
  error: "Cancelled"
48
49
  } : {
49
50
  status: "failed",
50
51
  error: t instanceof Error ? t.message : String(t)
51
- }, w = (e, t, n) => {
52
+ }, E = (e, t, n) => {
52
53
  if (e !== 401) return;
53
- let r = _(e, t);
54
- r && v({
54
+ let r = y(e, t);
55
+ r && b({
55
56
  reason: r,
56
57
  url: n
57
58
  });
58
- }, T = (e) => ({
59
+ }, D = (e) => ({
59
60
  status: "failed",
60
61
  ...e.runId ? { runId: e.runId } : {},
61
62
  ...e.reason ? { reason: e.reason } : {},
62
63
  ...e.error ? { error: e.error } : {},
63
64
  ...e.steps ? { steps: e.steps } : {},
64
65
  ...e.trace ? { trace: e.trace } : {}
65
- }), E = (e, t) => ({
66
+ }), O = (e, t) => ({
66
67
  actionId: e,
67
68
  runId: t.runId ?? "",
68
69
  error: t.error ?? "",
69
70
  reason: t.reason ?? "failed"
70
- }), D = ({ children: _ }) => {
71
- let { useInteractions: v, interactionsManager: D } = n(e), [O] = g("actions.endpoint"), [[k, A]] = g(["actions.catalog", "actions.available"]), j = r((e, t, n) => {
72
- e && D.interactionTrigger(e, t, n);
73
- }, [D]), M = r(async (e, t) => {
74
- let { actionId: n, mode: r = "await", idempotencyKey: i } = e;
75
- if (!O) return a.warning("actions", /* @__PURE__ */ u("span", { children: [
71
+ }), k = ({ children: y }) => {
72
+ let { useInteractions: b, interactionsManager: k } = i(e), [A] = v("actions.endpoint"), [[j, M]] = v(["actions.catalog", "actions.available"]), N = a((e, t, n) => {
73
+ e && k.interactionTrigger(e, t, n);
74
+ }, [k]), P = a(async (e, t) => {
75
+ let { actionId: n, mode: i = "await", idempotencyKey: a } = e;
76
+ if (!A) return s.warning("actions", /* @__PURE__ */ f("span", { children: [
76
77
  "Server action ",
77
- /* @__PURE__ */ l("b", { children: n }),
78
+ /* @__PURE__ */ d("b", { children: n }),
78
79
  " was skipped: this page is served without a Plitzi server"
79
80
  ] }), {
80
81
  actionId: n,
@@ -89,105 +90,105 @@ var y = (e) => Array.isArray(e) ? e : void 0, b = async (e, t) => {
89
90
  runId: "",
90
91
  output: {}
91
92
  };
92
- let o = x(e.input), s = JSON.stringify({
93
+ let o = C(e.input), c = JSON.stringify({
93
94
  actionId: n,
94
95
  input: o,
95
- ...i ? { idempotencyKey: i } : {}
96
- }), g = f({
96
+ ...a ? { idempotencyKey: a } : {}
97
+ }), l = m({
97
98
  actionId: n,
98
- mode: r,
99
+ mode: i,
99
100
  input: o
100
- }), _ = new AbortController(), v = "", D = () => {
101
- _.abort(), h(g, {
101
+ }), v = new AbortController(), y = "", b = () => {
102
+ v.abort(), _(l, {
102
103
  status: "aborted",
103
104
  endedAt: Date.now(),
104
105
  cancellable: !1
105
- }), v && fetch(`${O}/run/${v}`, {
106
+ }), y && fetch(`${A}/run/${y}`, {
106
107
  method: "DELETE",
107
108
  credentials: "same-origin"
108
109
  }).catch(() => void 0);
109
110
  };
110
- p(g, D);
111
+ h(l, b);
111
112
  let k = t?.signal;
112
- k?.addEventListener("abort", D, { once: !0 });
113
- let A = (t) => {
114
- k?.removeEventListener("abort", D), m(g), h(g, {
113
+ k?.addEventListener("abort", b, { once: !0 });
114
+ let j = (t) => {
115
+ k?.removeEventListener("abort", b), g(l), _(l, {
115
116
  endedAt: Date.now(),
116
117
  cancellable: !1,
117
118
  ...t
118
- }), t.status === "completed" && c({
119
+ }), t.status === "completed" && u({
119
120
  mode: e.invalidateQueries,
120
121
  fallback: "all",
121
122
  elements: e.invalidateElements
122
123
  });
123
124
  };
124
- if (r === "detached") return a.info("actions", /* @__PURE__ */ u("span", { children: [
125
+ if (i === "detached") return s.info("actions", /* @__PURE__ */ f("span", { children: [
125
126
  "Server action ",
126
- /* @__PURE__ */ l("b", { children: n }),
127
+ /* @__PURE__ */ d("b", { children: n }),
127
128
  " sent"
128
129
  ] }), {
129
130
  actionId: n,
130
- mode: r,
131
+ mode: i,
131
132
  status: "accepted"
132
- }), fetch(O, {
133
+ }), fetch(A, {
133
134
  method: "POST",
134
135
  headers: { "Content-Type": "application/json" },
135
136
  credentials: "same-origin",
136
137
  keepalive: !0,
137
- signal: _.signal,
138
- body: s
138
+ signal: v.signal,
139
+ body: c
139
140
  }).then(async (e) => {
140
- let i = await e.json().catch(() => ({}));
141
+ let r = await e.json().catch(() => ({}));
141
142
  if (!e.ok) {
142
- w(e.status, i, O), A(T(i)), j(t?.hostElementId, "onFlowError", E(n, i));
143
+ E(e.status, r, A), j(D(r)), N(t?.hostElementId, "onFlowError", O(n, r));
143
144
  return;
144
145
  }
145
- if (i.status === "failed") {
146
- A(T(i)), a.warning("actions", /* @__PURE__ */ u("span", { children: [
146
+ if (r.status === "failed") {
147
+ j(D(r)), s.warning("actions", /* @__PURE__ */ f("span", { children: [
147
148
  "Server action ",
148
- /* @__PURE__ */ l("b", { children: n }),
149
+ /* @__PURE__ */ d("b", { children: n }),
149
150
  " failed"
150
151
  ] }), {
151
152
  actionId: n,
152
- mode: r,
153
- runId: i.runId,
154
- reason: i.reason,
155
- error: i.error
156
- }), j(t?.hostElementId, "onFlowError", E(n, i));
153
+ mode: i,
154
+ runId: r.runId,
155
+ reason: r.reason,
156
+ error: r.error
157
+ }), N(t?.hostElementId, "onFlowError", O(n, r));
157
158
  return;
158
159
  }
159
- A({
160
- status: i.status === "completed" ? "completed" : "accepted",
161
- ...i.runId ? { runId: i.runId } : {},
162
- ...i.output ? { output: i.output } : {},
163
- ...i.steps ? { steps: i.steps } : {},
164
- ...i.trace ? { trace: i.trace } : {}
165
- }), a.success("actions", /* @__PURE__ */ u("span", { children: [
160
+ j({
161
+ status: r.status === "completed" ? "completed" : "accepted",
162
+ ...r.runId ? { runId: r.runId } : {},
163
+ ...r.output ? { output: r.output } : {},
164
+ ...r.steps ? { steps: r.steps } : {},
165
+ ...r.trace ? { trace: r.trace } : {}
166
+ }), s.success("actions", /* @__PURE__ */ f("span", { children: [
166
167
  "Server action ",
167
- /* @__PURE__ */ l("b", { children: n }),
168
+ /* @__PURE__ */ d("b", { children: n }),
168
169
  " finished"
169
170
  ] }), {
170
171
  actionId: n,
171
- mode: r,
172
- runId: i.runId,
173
- status: i.status,
174
- output: i.output
175
- }), j(t?.hostElementId, "onFlowEnd", {
172
+ mode: i,
173
+ runId: r.runId,
174
+ status: r.status,
175
+ output: r.output
176
+ }), N(t?.hostElementId, "onFlowEnd", {
176
177
  actionId: n,
177
- runId: i.runId ?? "",
178
- status: i.status ?? "completed",
179
- output: i.output ?? {}
178
+ runId: r.runId ?? "",
179
+ status: r.status ?? "completed",
180
+ output: r.output ?? {}
180
181
  });
181
182
  }).catch((e) => {
182
- A(C(_, e)), a.warning("actions", /* @__PURE__ */ u("span", { children: [
183
+ j(T(v, e)), s.warning("actions", /* @__PURE__ */ f("span", { children: [
183
184
  "Server action ",
184
- /* @__PURE__ */ l("b", { children: n }),
185
+ /* @__PURE__ */ d("b", { children: n }),
185
186
  " could not be sent"
186
187
  ] }), {
187
188
  actionId: n,
188
- mode: r,
189
+ mode: i,
189
190
  error: e instanceof Error ? e.message : String(e)
190
- }), j(t?.hostElementId, "onFlowError", {
191
+ }), N(t?.hostElementId, "onFlowError", {
191
192
  actionId: n,
192
193
  runId: "",
193
194
  error: "",
@@ -199,47 +200,47 @@ var y = (e) => Array.isArray(e) ? e : void 0, b = async (e, t) => {
199
200
  runId: "",
200
201
  output: {}
201
202
  };
202
- if (r === "stream") {
203
- a.info("actions", /* @__PURE__ */ u("span", { children: [
203
+ if (i === "stream") {
204
+ s.info("actions", /* @__PURE__ */ f("span", { children: [
204
205
  "Server action ",
205
- /* @__PURE__ */ l("b", { children: n }),
206
+ /* @__PURE__ */ d("b", { children: n }),
206
207
  " streaming"
207
208
  ] }), {
208
209
  actionId: n,
209
- mode: r,
210
+ mode: i,
210
211
  status: "streaming"
211
212
  });
212
213
  let e;
213
214
  try {
214
- e = await fetch(O, {
215
+ e = await fetch(A, {
215
216
  method: "POST",
216
217
  headers: {
217
218
  "Content-Type": "application/json",
218
219
  Accept: "text/event-stream"
219
220
  },
220
221
  credentials: "same-origin",
221
- signal: _.signal,
222
- body: s
222
+ signal: v.signal,
223
+ body: c
223
224
  });
224
225
  } catch (e) {
225
- return A(C(_, e)), a.warning("actions", /* @__PURE__ */ u("span", { children: [
226
+ return j(T(v, e)), s.warning("actions", /* @__PURE__ */ f("span", { children: [
226
227
  "Server action ",
227
- /* @__PURE__ */ l("b", { children: n }),
228
+ /* @__PURE__ */ d("b", { children: n }),
228
229
  " could not be reached"
229
230
  ] }), {
230
231
  actionId: n,
231
- mode: r,
232
+ mode: i,
232
233
  error: e instanceof Error ? e.message : String(e)
233
- }), j(t?.hostElementId, "onFlowError", {
234
+ }), N(t?.hostElementId, "onFlowError", {
234
235
  actionId: n,
235
236
  runId: "",
236
237
  error: "",
237
238
  reason: "failed"
238
- }), S;
239
+ }), w;
239
240
  }
240
241
  if (!e.ok || !e.body) {
241
242
  let r = await e.json().catch(() => ({}));
242
- return w(e.status, r, O), A(T(r)), j(t?.hostElementId, "onFlowError", E(n, r)), {
243
+ return E(e.status, r, A), j(D(r)), N(t?.hostElementId, "onFlowError", O(n, r)), {
243
244
  status: "failed",
244
245
  reason: r.reason ?? "failed",
245
246
  runId: "",
@@ -247,139 +248,139 @@ var y = (e) => Array.isArray(e) ? e : void 0, b = async (e, t) => {
247
248
  ...r.error ? { error: r.error } : {}
248
249
  };
249
250
  }
250
- let i = e.headers.get("X-Plitzi-Run-Id") ?? "";
251
- return v = i, h(g, {
251
+ let r = e.headers.get("X-Plitzi-Run-Id") ?? "";
252
+ return y = r, _(l, {
252
253
  status: "streaming",
253
- ...i ? { runId: i } : {}
254
- }), b(e.body, (e) => {
254
+ ...r ? { runId: r } : {}
255
+ }), S(e.body, (e) => {
255
256
  if (e.event === "data") {
256
- d(g, e.data.chunk ?? e.data), j(t?.hostElementId, "onFlowProgress", {
257
+ p(l, e.data.chunk ?? e.data), N(t?.hostElementId, "onFlowProgress", {
257
258
  actionId: n,
258
- runId: i,
259
+ runId: r,
259
260
  ...e.data
260
261
  });
261
262
  return;
262
263
  }
263
264
  if (e.event === "error") {
264
- let r = y(e.data.steps);
265
- A({
265
+ let i = x(e.data.steps);
266
+ j({
266
267
  status: "failed",
267
268
  ...typeof e.data.reason == "string" ? { reason: e.data.reason } : {},
268
269
  ...typeof e.data.error == "string" ? { error: e.data.error } : {},
269
- ...r ? { steps: r } : {}
270
- }), j(t?.hostElementId, "onFlowError", {
270
+ ...i ? { steps: i } : {}
271
+ }), N(t?.hostElementId, "onFlowError", {
271
272
  actionId: n,
272
- runId: i,
273
+ runId: r,
273
274
  ...e.data
274
275
  });
275
276
  return;
276
277
  }
277
278
  if (e.event === "done") {
278
- let r = y(e.data.steps);
279
- A({
279
+ let i = x(e.data.steps);
280
+ j({
280
281
  status: e.data.status === "completed" ? "completed" : "failed",
281
282
  ...e.data.output ? { output: e.data.output } : {},
282
283
  ...typeof e.data.error == "string" ? { error: e.data.error } : {},
283
- ...r ? { steps: r } : {}
284
- }), j(t?.hostElementId, "onFlowEnd", {
284
+ ...i ? { steps: i } : {}
285
+ }), N(t?.hostElementId, "onFlowEnd", {
285
286
  actionId: n,
286
- runId: i,
287
+ runId: r,
287
288
  ...e.data
288
289
  });
289
290
  }
290
291
  }).catch((e) => {
291
- if (_.signal.aborted) return;
292
- let o = e instanceof Error ? e.message : String(e);
293
- A({
292
+ if (v.signal.aborted) return;
293
+ let a = e instanceof Error ? e.message : String(e);
294
+ j({
294
295
  status: "failed",
295
- error: o
296
- }), a.warning("actions", /* @__PURE__ */ u("span", { children: [
296
+ error: a
297
+ }), s.warning("actions", /* @__PURE__ */ f("span", { children: [
297
298
  "Server action ",
298
- /* @__PURE__ */ l("b", { children: n }),
299
+ /* @__PURE__ */ d("b", { children: n }),
299
300
  " stopped mid-stream"
300
301
  ] }), {
301
302
  actionId: n,
302
- mode: r,
303
- runId: i,
304
- error: o
305
- }), j(t?.hostElementId, "onFlowError", {
303
+ mode: i,
304
+ runId: r,
305
+ error: a
306
+ }), N(t?.hostElementId, "onFlowError", {
306
307
  actionId: n,
307
- runId: i,
308
- error: o,
308
+ runId: r,
309
+ error: a,
309
310
  reason: "failed"
310
311
  });
311
312
  }), {
312
313
  accepted: !0,
313
314
  status: "streaming",
314
- runId: i,
315
+ runId: r,
315
316
  output: {}
316
317
  };
317
318
  }
318
319
  let M;
319
320
  try {
320
- M = await fetch(O, {
321
+ M = await fetch(A, {
321
322
  method: "POST",
322
323
  headers: { "Content-Type": "application/json" },
323
324
  credentials: "same-origin",
324
- signal: _.signal,
325
- body: s
325
+ signal: v.signal,
326
+ body: c
326
327
  });
327
328
  } catch (e) {
328
- return A(C(_, e)), a.warning("interactions", /* @__PURE__ */ u("span", { children: [
329
+ return j(T(v, e)), s.warning("interactions", /* @__PURE__ */ f("span", { children: [
329
330
  "Server action ",
330
- /* @__PURE__ */ l("b", { children: n }),
331
+ /* @__PURE__ */ d("b", { children: n }),
331
332
  " could not be reached"
332
333
  ] }), {
333
334
  actionId: n,
334
335
  error: e instanceof Error ? e.message : String(e)
335
- }), j(t?.hostElementId, "onFlowError", {
336
+ }), N(t?.hostElementId, "onFlowError", {
336
337
  actionId: n,
337
338
  runId: "",
338
339
  error: "",
339
340
  reason: "failed"
340
- }), S;
341
+ }), w;
341
342
  }
342
- let N = await M.json().catch(() => ({}));
343
- return M.ok ? (A({
344
- status: N.status === "completed" ? "completed" : "failed",
345
- ...N.runId ? { runId: N.runId } : {},
346
- ...N.output ? { output: N.output } : {},
347
- ...N.error ? { error: N.error } : {},
348
- ...N.steps ? { steps: N.steps } : {},
349
- ...N.trace ? { trace: N.trace } : {}
350
- }), N.status === "failed" && j(t?.hostElementId, "onFlowError", E(n, N)), {
351
- status: N.status ?? "completed",
352
- runId: N.runId ?? "",
353
- output: N.output ?? {},
354
- ...N.error ? { error: N.error } : {}
355
- }) : (w(M.status, N, O), A(T(N)), j(t?.hostElementId, "onFlowError", E(n, N)), a.warning("actions", /* @__PURE__ */ u("span", { children: [
343
+ let P = await M.json().catch(() => ({}));
344
+ return M.ok ? (j({
345
+ status: P.status === "completed" ? "completed" : "failed",
346
+ ...P.runId ? { runId: P.runId } : {},
347
+ ...P.output ? { output: P.output } : {},
348
+ ...P.error ? { error: P.error } : {},
349
+ ...P.steps ? { steps: P.steps } : {},
350
+ ...P.trace ? { trace: P.trace } : {}
351
+ }), P.status === "failed" && N(t?.hostElementId, "onFlowError", O(n, P)), {
352
+ status: r(P.status),
353
+ runId: P.runId ?? "",
354
+ output: P.output ?? {},
355
+ ...P.error ? { error: P.error } : {}
356
+ }) : (E(M.status, P, A), j(D(P)), N(t?.hostElementId, "onFlowError", O(n, P)), s.warning("actions", /* @__PURE__ */ f("span", { children: [
356
357
  "Server action ",
357
- /* @__PURE__ */ l("b", { children: n }),
358
+ /* @__PURE__ */ d("b", { children: n }),
358
359
  " was refused"
359
360
  ] }), {
360
361
  actionId: n,
361
- mode: r,
362
- runId: N.runId,
363
- reason: N.reason,
364
- error: N.error,
362
+ mode: i,
363
+ runId: P.runId,
364
+ reason: P.reason,
365
+ error: P.error,
365
366
  status: String(M.status)
366
367
  }), {
367
368
  status: "failed",
368
- reason: N.reason ?? "failed",
369
- runId: N.runId ?? "",
369
+ reason: P.reason ?? "failed",
370
+ runId: P.runId ?? "",
370
371
  output: {},
371
- ...N.error ? { error: N.error } : {}
372
+ ...P.error ? { error: P.error } : {}
372
373
  });
373
- }, [O, j]), N = r(async (e) => {
374
- if (!O || !e.runId) return { cancelled: !1 };
374
+ }, [A, N]), F = a(async (e) => {
375
+ if (!A || !e.runId) return { cancelled: !1 };
375
376
  try {
376
- let t = (await fetch(`${O}/run/${e.runId}`, {
377
+ let t = (await fetch(`${A}/run/${e.runId}`, {
377
378
  method: "DELETE",
378
379
  credentials: "same-origin"
379
380
  })).status === 204;
380
- return a.info("actions", /* @__PURE__ */ u("span", { children: [
381
+ return s.info("actions", /* @__PURE__ */ f("span", { children: [
381
382
  "Server action run ",
382
- /* @__PURE__ */ l("b", { children: e.runId }),
383
+ /* @__PURE__ */ d("b", { children: e.runId }),
383
384
  " ",
384
385
  t ? "cancelled" : "was not cancelled"
385
386
  ] }), {
@@ -391,25 +392,25 @@ var y = (e) => Array.isArray(e) ? e : void 0, b = async (e, t) => {
391
392
  } catch {
392
393
  return { cancelled: !1 };
393
394
  }
394
- }, [O]), P = i(() => (k ?? []).map((e) => ({
395
+ }, [A]), I = o(() => (j ?? []).map((e) => ({
395
396
  label: `${e.name} (${e.identifier})`,
396
397
  value: e.identifier
397
- })), [k]);
398
- return v({
398
+ })), [j]);
399
+ b({
399
400
  id: "actions",
400
- callbacks: i(() => s(t, {
401
- cancelServerAction: N,
402
- runServerAction: M
401
+ callbacks: o(() => l(t, {
402
+ cancelServerAction: F,
403
+ runServerAction: P
403
404
  }, { runServerAction: { params: (e) => {
404
- let n = o(t.runServerAction.params), r = (k ?? []).find((t) => t.identifier === e.actionId), i = Object.entries(r?.input ?? {});
405
+ let n = c(t.runServerAction.params), r = (j ?? []).find((t) => t.identifier === e.actionId), i = Object.entries(r?.input ?? {});
405
406
  return {
406
407
  ...n,
407
408
  actionId: {
408
409
  ...n.actionId,
409
- type: () => P.length > 0 ? "select" : "text",
410
+ type: () => I.length > 0 ? "select" : "text",
410
411
  canBind: !0,
411
- label: A === !1 ? "Action — this space has no server to run it" : "Action",
412
- options: P
412
+ label: M === !1 ? "Action — this space has no server to run it" : "Action",
413
+ options: I
413
414
  },
414
415
  input: {
415
416
  ...n.input,
@@ -418,13 +419,24 @@ var y = (e) => Array.isArray(e) ? e : void 0, b = async (e, t) => {
418
419
  }
419
420
  };
420
421
  } } }), [
421
- M,
422
- N,
423
422
  P,
424
- k,
425
- A
423
+ F,
424
+ I,
425
+ j,
426
+ M
426
427
  ])
427
- }), _;
428
+ });
429
+ let L = a(({ actionId: e, input: t, idempotencyKey: n = "", invalidateQueries: r }) => P({
430
+ actionId: e,
431
+ input: t,
432
+ mode: "await",
433
+ idempotencyKey: n,
434
+ invalidateQueries: r
435
+ }), [P]);
436
+ return /* @__PURE__ */ d(n, {
437
+ value: L,
438
+ children: y
439
+ });
428
440
  };
429
441
  //#endregion
430
- export { D as default };
442
+ export { k as default };
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Where a run stands as its caller hears it: how an awaited one ended (`completed`, `failed`, `aborted`, or `skipped`
3
+ * where no server runs actions), or that a detached one was `accepted` and a streamed one is `streaming`.
4
+ */
5
+ export type ServerActionStatus = 'completed' | 'failed' | 'skipped' | 'aborted' | 'accepted' | 'streaming';
6
+ /**
7
+ * How the server said an awaited run ended — read from its JSON, so a word it never uses is a run that did not
8
+ * complete, never one that did.
9
+ */
10
+ export declare const endedStatusOf: (status: string | undefined) => ServerActionStatus;
11
+ /** What a run of a server action answers whoever started it — a flow's `runServerAction` step, or a plugin's `useServerAction`. */
12
+ export type ServerActionAnswer = {
13
+ status: ServerActionStatus;
14
+ runId: string;
15
+ output: Record<string, unknown>;
16
+ /** The server's word for a run it refused or that failed: `forbidden`, `invalid_input`, `duplicate`… */
17
+ reason?: string;
18
+ /** Said for the caller, by a step that refused with a reason written for them. */
19
+ error?: string;
20
+ accepted?: boolean;
21
+ };
22
+ /** One awaited run of an action, as the `runServerAction` step makes it. */
23
+ export type RunServerAction = (request: {
24
+ actionId: string;
25
+ input: Record<string, unknown>;
26
+ idempotencyKey?: string;
27
+ /**
28
+ * Whether a completed run refreshes the page's cached requests — `all`, the default, since what it wrote is the
29
+ * server's to know — or none, for an action that only reads.
30
+ */
31
+ invalidateQueries?: 'all' | 'none';
32
+ }) => Promise<ServerActionAnswer>;
33
+ /** Present wherever the page runs actions; absent, nothing on this page can (the builder's canvas, an offline render). */
34
+ export declare const ServerActionContext: import('react').Context<RunServerAction | undefined>;
@@ -0,0 +1,10 @@
1
+ import { sharedContext as e } from "@plitzi/sdk-shared/helpers/sharedContext";
2
+ //#region src/sources/ActionsSource/ServerActionContext.ts
3
+ var t = [
4
+ "completed",
5
+ "failed",
6
+ "skipped",
7
+ "aborted"
8
+ ], n = (e) => e === void 0 ? "completed" : t.find((t) => t === e) ?? "failed", r = e("ServerActionContext", void 0);
9
+ //#endregion
10
+ export { r as ServerActionContext, n as endedStatusOf };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plitzi/sdk-interactions",
3
- "version": "0.38.14",
3
+ "version": "0.38.16",
4
4
  "license": "AGPL-3.0",
5
5
  "files": [
6
6
  "dist"
@@ -54,6 +54,10 @@
54
54
  "types": "./dist/sources/ActionsSource/ActionInteractions.d.ts",
55
55
  "import": "./dist/sources/ActionsSource/ActionInteractions.mjs"
56
56
  },
57
+ "./sources/ActionsSource/ServerActionContext": {
58
+ "types": "./dist/sources/ActionsSource/ServerActionContext.d.ts",
59
+ "import": "./dist/sources/ActionsSource/ServerActionContext.mjs"
60
+ },
57
61
  "./sources/ActionsSource/callbacks": {
58
62
  "types": "./dist/sources/ActionsSource/callbacks.d.ts",
59
63
  "import": "./dist/sources/ActionsSource/callbacks.mjs"
@@ -203,9 +207,9 @@
203
207
  },
204
208
  "dependencies": {
205
209
  "@plitzi/plitzi-ui": "^1.6.33",
206
- "@plitzi/sdk-auth": "0.38.14",
207
- "@plitzi/sdk-event-bridge": "0.38.14",
208
- "@plitzi/sdk-shared": "0.38.14"
210
+ "@plitzi/sdk-auth": "0.38.16",
211
+ "@plitzi/sdk-event-bridge": "0.38.16",
212
+ "@plitzi/sdk-shared": "0.38.16"
209
213
  },
210
214
  "peerDependencies": {
211
215
  "react": "^19"