@colixsystems/widget-sdk 0.298.0 → 0.299.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 CHANGED
@@ -58,7 +58,7 @@ The data layer lives in **four separate domain-client packages**, each instantia
58
58
  | **DATASTORE** | `useBoundColumns(tableId, shape, props)` | `{ columns, resolved, missing, loading, error }` | `schema(tableId)` (built on `useDatastoreSchema`) — `datastore.read:<table>`. Resolves author-bound column NAMES from `props` by exact name → case-insensitive name → first unclaimed column matching `shape[key].dataType`, so a column an author renamed after install still resolves instead of `record[props.titleField]` reading `undefined`. `columns` holds the resolved NAME (`record[columns.titleField]`); `resolved` holds the full `Column`; `missing` lists non-`optional` keys that never resolved. Falsy `tableId` collapses to `{ columns: {}, resolved: {}, missing: Object.keys(shape), loading: false, error: null }`. |
59
59
  | **DATASTORE** | `useInterpretDraft(tableId)` | `{ interpret, interpreting, error, result, available }` | `interpret(tableId, body)` — `datastore.read:<table>`. Turns ONE sentence a user typed ("walk at 11 am tomorrow") into DRAFT column values so a form can prefill itself. IMPERATIVE: call `interpret(text, { fields?, timeZone? })` from an event handler, never on mount. It DRAFTS and writes nothing — show the values for review, then submit through `useDatastoreMutation().create`. Resolves to `{ values, unresolved }`; `values` is keyed by column NAME (the shape `create()` takes) and `unresolved` names the fields the sentence did not state. Only text / number / boolean / date / datetime / array columns are drafted — `FILE`, `RELATION`, `USER` and `USER_GROUP` carry ids and are never guessed. Fails closed to an empty draft. **Every call spends the workspace's AI credits** and is rate-limited per actor, so call it once per user action (never on mount or in a render loop); once the workspace runs out the call is refused with a generic 429 — an app user is deliberately **not** told the workspace's billing state, since they have never heard of an AI credit and cannot buy one. Never surface a raw error to the person filling the form: say drafting is unavailable and keep every field editable by hand. `available` is false where the host brokers no interpreter. |
60
60
  | **AGENTS** | `useAgent(agentRef)` | `{ send, cancel, reset, messages, sending, resuming, error, available }` | `ctx.agents` — `ai.invoke:*`. Hold a conversation with one of the WORKSPACE's own AI agents (an author-written name + system prompt). Sending is IMPERATIVE: call `send(text)` from an event handler, never on mount — the first send opens the conversation, so a widget nobody types into costs nothing. On mount the hook DOES reopen the caller's most recent thread with this agent, so a refresh or a navigation keeps the conversation instead of starting a blank one; that resume only READS and spends no credit. `resuming` is true while it runs — render a loading state, not an empty thread. `messages` is the running transcript, oldest first. You **cannot** set or read the system prompt, replay an edited transcript, or pick a model: the server assembles every turn from the stored prompt plus the stored history, and `content` is the only thing that reaches the wire. `reset()` drops the thread (a "new chat" affordance), and the new thread is the one a later mount resumes. **Every send spends the workspace's AI credits** and is rate-limited per caller AND per workspace. Rejects with `AgentError`; branch on `.code` — `AI_QUOTA_EXCEEDED` (429) is the workspace's credit ceiling and will NOT clear on a retry, unlike `RATE_LIMITED`, so never offer "try again" for it, and `AGENT_DISABLED` (409) means the author turned it off, so hide the affordance. Never surface a raw error or the workspace's billing state to an app user. `available` is false when no agent is bound or the host brokers none — render a visible unbound state, never a blank box. An assistant message that used a tool also carries **`activity`** — what the agent DID with the user's data: the table it read (with the `search` text and `filters` it read with), or the table and columns it CHANGED (never the values, and never a row the permissions refused). **Render a write.** A reply saying "done!" is not evidence a row was written, and if the agent got it wrong the user has no other way to notice. A talk-only turn omits the key entirely. |
61
- | **ACTIONS** | `useAction(actionRef)` | `{ available, run, running, result, error }` | `ctx.actions` — `actions.run:*`. Run one of the workspace's Actions from an event handler (never on mount) and read the value it passed to `respond()`. The Action needs the app trigger. `available` is false when nothing is bound or the host brokers no client. Errors are `ActionError` with a stable `code`. |
61
+ | **ACTIONS** | `useAction(actionRef)` | `{ available, run, enqueue, running, result, error }` | `ctx.actions` — `actions.run:*`. Run one of the workspace's Actions from an event handler (never on mount) and read the value it passed to `respond()`, or `enqueue` it to run later with its normal limits and no answer. The Action needs the app trigger. `available` is false when nothing is bound or the host brokers no client. Errors are `ActionError` with a stable `code`. |
62
62
  | **DATASTORE** | `useDatastoreMutation(table)` | `{ create, update, delete }` | `records(table).{ create, update (PATCH), delete }` — `datastore.write:*`. A successful write re-reads every query, record, figure and aggregate on that table in every widget on the screen (a run of writes at most once a second, always once more after the last), so never refetch after it, and never write from an effect that re-runs on the data it reads unless a ref or Set marks what it already wrote. **To CLEAR a cell, pass it empty** — `update(id, { when: null })` (also `""` or `[]`) empties that cell and it reads back as `null` (`[]` on an array column). There is no separate clear call, so never write a sentinel such as `0` or a placeholder date to mean "no value". `false` and `0` are values, not clears, and a REQUIRED column cannot be cleared. |
63
63
  | **DATASTORE** | `useDatastoreSubscription(table, handlers, options)` (optional: options) | `{ status }` — `"connecting" \| "live" \| "reconnecting" \| "fallback"` | `records(table).subscribe` — `datastore.read:<table>`. To keep a list, record or figure current, pass `live: true` to its read hook instead (*Live lists*); this hook is for acting on each change. Live `onCreated` / `onUpdated` / `onDeleted` off the realtime socket; never throws, resolving to `{ status: "fallback" }` so the widget polls instead. A whole-table subscribe is gated on read-EVERY-row, because one envelope reaches every subscriber of the table — so for a table governed by per-record grants pass `options.scope`: `{ kind: "record", record_id }` for one row, or `{ kind: "parent", relation_column, record_id }` for the rows whose RELATION column points at that parent (the column must carry `inheritAcl`, else the subscribe reports `"fallback"`). For a live list of the signed-in user's own rows pass `{ kind: "granted" }`: every row they read through a grant to them or one of their groups, plus `onAccessGained(record)` / `onAccessLost({ id })` as rows enter and leave that set. Re-subscribes on the scope's VALUES, so a fresh object literal each render is fine. |
64
64
  | **DATASTORE** | `useTyping(tableId, recordId)` | `{ typingUserIds, setTyping, status }` — status `"connecting" \| "live" \| "unavailable"` | `records(table).typing` — `datastore.read:<table>`. Who else is typing in one record, over the same socket as `useDatastoreSubscription`. Call `setTyping(true)` on every keystroke (throttled to one signal per 3 s; `false` is sent after 5 s idle) and `setTyping(false)` on send, clear or blur. `typingUserIds` lists the OTHER users' ids; each drops out 6 s after their last signal. Needs a signed-in user who can read the record. Never throws: an anonymous visitor, a refused subscription or a host whose client lacks `typing` reads `{ typingUserIds: [], status: "unavailable" }`. Re-subscribes when either id changes. |
@@ -90,7 +90,15 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
90
90
 
91
91
  ## Status
92
92
 
93
- `v0.298.0` — pre-publish. The package surface (types, function names, export paths) is the v1 contract; runtime behaviour for some hooks is stubbed (each hook documents what's wired and what isn't). It is **not yet published to npm**.
93
+ `v0.299.0` — pre-publish. The package surface (types, function names, export paths) is the v1 contract; runtime behaviour for some hooks is stubbed (each hook documents what's wired and what isn't). It is **not yet published to npm**.
94
+
95
+ ### What's new in 0.299.0 (contract 1.246.0)
96
+
97
+ **`useAction()` can queue a run instead of waiting for it.** The hook now returns `enqueue(input)` beside `run(input)`. `run` still waits for the Action and hands back its `respond()` value, and must finish within 500 ms of the press. `enqueue` resolves as soon as the server has queued the run, with the same refusals as `run` (`ACTION_NOT_APP_INVOKABLE`, `ACTION_NOT_FOUND`, `INVALID_ACTION_INPUT`, `RATE_LIMITED`, a signed-out caller). The Action then runs away from the request with its normal time limits, the way a scheduled run does, and a pod restart does not lose it. Nothing comes back: `running`, `result` and `error` stay as they were. Use it to start work the widget needs no answer from (a batch, a sync, a long send), and tell the user it has started, not that it is done. It is also refused, rather than queued, when the Action is switched off (`ACTION_DISABLED`) or paused (`ACTION_PAUSED`), and with `RATE_LIMITED` when the workspace already has 10 queued runs waiting or running. It can run twice: a scheduler restarted mid-run starts it again, so write the Action to be safe to repeat. On a host whose actions client cannot queue, `enqueue` rejects `UNAVAILABLE`. The injected client is `@colixsystems/actions-client` 0.4.0.
98
+
99
+ ```jsx
100
+ const { available, enqueue } = useAction(props.actionId);
101
+ const start = () => enqueue({ batch_id: batch.id }).then(() => toast.show("Started"), () => toast.show("Could not start"));
94
102
 
95
103
  ### What's new in 0.298.0 (contract 1.245.0)
96
104
 
@@ -119,7 +127,7 @@ const dx = (pressed.has("ArrowRight") ? 1 : 0) - (pressed.has("ArrowLeft") ? 1 :
119
127
 
120
128
  ### What's new in 0.292.0 (contract 1.239.0)
121
129
 
122
- **An Action a widget runs must be done 250 ms after the press.** The time counts from when the press reaches the server, so waiting for a free sandbox and setting the run up spend from it too. A run started by `useAction()` (or a Button's Run action) that is still going then is stopped, and `run()` rejects with `ACTION_TIMEOUT` (504). Its outcome is unknown: open requests and connector calls are cut and no new work starts, but a write that had already finished stays, and a notification already sent can't be recalled. So an Action the app waits on must do its writes as one call (a bulk write) or be safe to repeat, and never tell the user it did nothing. Move slow or multi-step work to an Action triggered by a record the widget writes. Scheduled, record-triggered and Run now runs keep their own limits.
130
+ **An Action a widget runs must be done 500 ms after the press.** The time counts from when the press reaches the server, so waiting for a free sandbox and setting the run up spend from it too. A run started by `useAction()` (or a Button's Run action) that is still going then is stopped, and `run()` rejects with `ACTION_TIMEOUT` (504). Its outcome is unknown: open requests and connector calls are cut and no new work starts, but a write that had already finished stays, and a notification already sent can't be recalled. So an Action the app waits on must do its writes as one call (a bulk write) or be safe to repeat, and never tell the user it did nothing. Move slow or multi-step work to an Action triggered by a record the widget writes. Scheduled, record-triggered and Run now runs keep their own limits.
123
131
 
124
132
  ### What's new in 0.291.0 (contract 1.238.0)
125
133
 
@@ -127,7 +135,7 @@ const dx = (pressed.has("ArrowRight") ? 1 : 0) - (pressed.has("ArrowLeft") ? 1 :
127
135
 
128
136
  ### What's new in 0.290.0 (contract 1.238.0)
129
137
 
130
- **New `useConnector(connectorRef)` hook — a widget can call one of the workspace's REST connectors and use the answer itself.** Bind a connector with a `{ type: "connectorRef" }` property and declare `connectors.call:*` in `requestedScopes`. `call(operation, { params, query, body })` names an operation the workspace listed for apps on that connector — never a method or a path — and resolves `{ status, content_type, body }` with the outside API's status and parsed body. The whole call has 250 ms, token exchange included: a slower outside API is cut off and the call rejects with `UPSTREAM_TIMEOUT`. The credential is added on the server and never reaches the app. A new `connectors` host client (`createConnectorsClient` in `@colixsystems/actions-client`), the `connectorRef` property type, the `connectors.call:*` scope and a `ConnectorError`. Everything is additive.
138
+ **New `useConnector(connectorRef)` hook — a widget can call one of the workspace's REST connectors and use the answer itself.** Bind a connector with a `{ type: "connectorRef" }` property and declare `connectors.call:*` in `requestedScopes`. `call(operation, { params, query, body })` names an operation the workspace listed for apps on that connector — never a method or a path — and resolves `{ status, content_type, body }` with the outside API's status and parsed body. The whole call has 500 ms, token exchange included: a slower outside API is cut off and the call rejects with `UPSTREAM_TIMEOUT`. The credential is added on the server and never reaches the app. A new `connectors` host client (`createConnectorsClient` in `@colixsystems/actions-client`), the `connectorRef` property type, the `connectors.call:*` scope and a `ConnectorError`. Everything is additive.
131
139
 
132
140
  ### What's new in 0.289.0 (contract 1.237.0)
133
141
 
@@ -328,7 +336,7 @@ const { available, run, running, result, error } = useAction(props.actionId);
328
336
 
329
337
  **Bind it with an `actionRef` property.** Declare `{ type: "actionRef" }` in your `propertySchema` and the Studio renders an Action picker that warns when the chosen Action lacks the app trigger. The value is a bare Action id, so Copy Workspace remaps it like `pageRef`.
330
338
 
331
- When nothing is bound, or the host brokers no actions client, `available` is `false` and `run()` rejects `UNAVAILABLE`: render a visible "pick an action" state, never a blank box. A changed binding clears `result` and `error`, and a run that settles after the binding changed or the widget unmounted writes nothing. When runs overlap, `result` and `error` follow the newest one. Branch on `error.code`: `ACTION_NOT_APP_INVOKABLE` and `ACTION_NOT_FOUND` will not clear on a retry, `RATE_LIMITED` will, `INVALID_ACTION_INPUT` means the input was refused, `AUTH_REQUIRED`, `TOKEN_EXPIRED` and `TOKEN_INVALID` mean the app user must sign in, `ACTION_FAILED` means the Action ran and failed, and `ACTION_TIMEOUT` means it was still running 250 ms after the press and was stopped, so its outcome is unknown: some of its writes may have happened. Never show an app user the raw message. A text answer from a bot is often markdown, so render it with `<RichText>`.
339
+ When nothing is bound, or the host brokers no actions client, `available` is `false` and `run()` rejects `UNAVAILABLE`: render a visible "pick an action" state, never a blank box. A changed binding clears `result` and `error`, and a run that settles after the binding changed or the widget unmounted writes nothing. When runs overlap, `result` and `error` follow the newest one. Branch on `error.code`: `ACTION_NOT_APP_INVOKABLE` and `ACTION_NOT_FOUND` will not clear on a retry, `RATE_LIMITED` will, `INVALID_ACTION_INPUT` means the input was refused, `AUTH_REQUIRED`, `TOKEN_EXPIRED` and `TOKEN_INVALID` mean the app user must sign in, `ACTION_FAILED` means the Action ran and failed, and `ACTION_TIMEOUT` means it was still running 500 ms after the press and was stopped, so its outcome is unknown: some of its writes may have happened. Never show an app user the raw message. A text answer from a bot is often markdown, so render it with `<RichText>`.
332
340
 
333
341
  The linter rejects `useAction()` unless your manifest declares `actions.run:*` in `requestedScopes`.
334
342
 
package/dist/contract.cjs CHANGED
@@ -2291,7 +2291,7 @@ const HOOKS = [
2291
2291
  "INVALID_ACTION_INPUT (400) — the input was refused; " +
2292
2292
  "ACTION_NOT_APP_INVOKABLE (403) and ACTION_NOT_FOUND (404) will NOT " +
2293
2293
  "clear on a retry, so hide the affordance; RATE_LIMITED (429) will; " +
2294
- "ACTION_TIMEOUT (504) — the run was still going 250 ms after the press " +
2294
+ "ACTION_TIMEOUT (504) — the run was still going 500 ms after the press " +
2295
2295
  "and was stopped, so its OUTCOME IS UNKNOWN: some of its writes may " +
2296
2296
  "have happened. Never retry it blindly and never tell the user it did " +
2297
2297
  "nothing; an Action a widget runs must do its writes as one call or be " +
@@ -2300,10 +2300,22 @@ const HOOKS = [
2300
2300
  "ACTION_FAILED — the Action ran and failed, or no answer arrived. NEVER " +
2301
2301
  "show an app user a raw error. A text answer from a bot is often " +
2302
2302
  "MARKDOWN, so render it with <RichText value={result} />, not <Text>. " +
2303
+ "enqueue(input) QUEUES the run instead: it resolves as soon " +
2304
+ "as the server accepted it (the same refusals as run), and the script " +
2305
+ "runs later, away from the request, with the Action's normal limits " +
2306
+ "rather than the 500 ms an app run gets. Nothing comes back — no " +
2307
+ "respond() value, and running/result/error are untouched — so use it to " +
2308
+ "start work the widget needs no answer from (a batch, a sync, a long " +
2309
+ "send) and tell the user it has started, never that it is done. " +
2310
+ "It is also refused when the Action is switched off (ACTION_DISABLED) " +
2311
+ "or paused (ACTION_PAUSED), and with RATE_LIMITED when the workspace " +
2312
+ "already has 10 queued runs waiting. A queued run can run twice (a " +
2313
+ "restart mid-run starts it again), so its Action must be safe to repeat. " +
2303
2314
  "Reads ctx.actions.",
2304
2315
  returnShape: {
2305
2316
  available: "boolean // false when no Action is bound, the host brokers none, or the server says a run would not reach the script",
2306
2317
  run: "(input) => Promise<unknown> // input is optional; resolves with the Action's respond() value, or null; rejects with ActionError",
2318
+ enqueue: "(input) => Promise<void> // input is optional; resolves once the run is queued, returns nothing; rejects with ActionError (run's codes plus ACTION_DISABLED, ACTION_PAUSED)",
2307
2319
  running: "boolean // true while any run is in flight",
2308
2320
  result: "unknown // the last successful run's result; null before the first run",
2309
2321
  error: "ActionError | null",
@@ -2326,7 +2338,7 @@ const HOOKS = [
2326
2338
  "only where the operation takes one. call resolves with { status, " +
2327
2339
  "content_type, body } — the outside API's status (a non-2xx answer " +
2328
2340
  "still resolves: branch on status) and its parsed JSON or text body. " +
2329
- "The whole call must finish within 250 ms, token exchange included: a " +
2341
+ "The whole call must finish within 500 ms, token exchange included: a " +
2330
2342
  "slower outside API is cut off and the call rejects with UPSTREAM_TIMEOUT. " +
2331
2343
  "May run on mount for a read operation; an operation that changes data " +
2332
2344
  "belongs in an event handler. `connectorRef` is a connector id an " +
@@ -4419,14 +4431,15 @@ const WIDGET_CONTEXT_SHAPE = {
4419
4431
  actions: {
4420
4432
  description:
4421
4433
  "sc-13843 — injected @colixsystems/actions-client instance. " +
4422
- "{ run(actionId, input?) -> Promise<{ ok, result }>, status(actionId) -> " +
4434
+ "{ run(actionId, input?) -> Promise<{ ok, result }>, enqueue(actionId, " +
4435
+ "input?) -> Promise<{ queued: true }>, status(actionId) -> " +
4423
4436
  "Promise<{ available, reason }> }. Backs useAction(). " +
4424
4437
  "Runs one Action as the signed-in caller; the server refuses an Action " +
4425
4438
  "without the app trigger. Errors carry the server's `code` and `status`. " +
4426
4439
  "Absent on a host that brokers no actions client, where useAction() " +
4427
4440
  "degrades to available: false rather than throwing.",
4428
4441
  required: false,
4429
- fields: { run: "function", status: "function" },
4442
+ fields: { run: "function", enqueue: "function", status: "function" },
4430
4443
  },
4431
4444
  connectors: {
4432
4445
  description:
@@ -6898,7 +6911,10 @@ const CONTRACT = deepFreeze({
6898
6911
  // 1.245.0: additive (sc-15920) — a Tabs item with `value` and no `key` is
6899
6912
  // keyed by its `value`; a host may set `ctx.strictProps` so a component
6900
6913
  // throws on a prop it cannot render without (the widget check's render).
6901
- version: "1.245.0",
6914
+ // 1.246.0: additive (sc-15876) — `useAction()` gains `enqueue(input)`, which
6915
+ // queues the run and resolves at once; the script runs with the Action's
6916
+ // normal limits and returns nothing to the widget.
6917
+ version: "1.246.0",
6902
6918
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
6903
6919
  hooks: HOOKS,
6904
6920
  primitives: PRIMITIVES,
package/dist/contract.js CHANGED
@@ -2286,7 +2286,7 @@ const HOOKS = [
2286
2286
  "INVALID_ACTION_INPUT (400) — the input was refused; " +
2287
2287
  "ACTION_NOT_APP_INVOKABLE (403) and ACTION_NOT_FOUND (404) will NOT " +
2288
2288
  "clear on a retry, so hide the affordance; RATE_LIMITED (429) will; " +
2289
- "ACTION_TIMEOUT (504) — the run was still going 250 ms after the press " +
2289
+ "ACTION_TIMEOUT (504) — the run was still going 500 ms after the press " +
2290
2290
  "and was stopped, so its OUTCOME IS UNKNOWN: some of its writes may " +
2291
2291
  "have happened. Never retry it blindly and never tell the user it did " +
2292
2292
  "nothing; an Action a widget runs must do its writes as one call or be " +
@@ -2295,10 +2295,22 @@ const HOOKS = [
2295
2295
  "ACTION_FAILED — the Action ran and failed, or no answer arrived. NEVER " +
2296
2296
  "show an app user a raw error. A text answer from a bot is often " +
2297
2297
  "MARKDOWN, so render it with <RichText value={result} />, not <Text>. " +
2298
+ "enqueue(input) QUEUES the run instead: it resolves as soon " +
2299
+ "as the server accepted it (the same refusals as run), and the script " +
2300
+ "runs later, away from the request, with the Action's normal limits " +
2301
+ "rather than the 500 ms an app run gets. Nothing comes back — no " +
2302
+ "respond() value, and running/result/error are untouched — so use it to " +
2303
+ "start work the widget needs no answer from (a batch, a sync, a long " +
2304
+ "send) and tell the user it has started, never that it is done. " +
2305
+ "It is also refused when the Action is switched off (ACTION_DISABLED) " +
2306
+ "or paused (ACTION_PAUSED), and with RATE_LIMITED when the workspace " +
2307
+ "already has 10 queued runs waiting. A queued run can run twice (a " +
2308
+ "restart mid-run starts it again), so its Action must be safe to repeat. " +
2298
2309
  "Reads ctx.actions.",
2299
2310
  returnShape: {
2300
2311
  available: "boolean // false when no Action is bound, the host brokers none, or the server says a run would not reach the script",
2301
2312
  run: "(input) => Promise<unknown> // input is optional; resolves with the Action's respond() value, or null; rejects with ActionError",
2313
+ enqueue: "(input) => Promise<void> // input is optional; resolves once the run is queued, returns nothing; rejects with ActionError (run's codes plus ACTION_DISABLED, ACTION_PAUSED)",
2302
2314
  running: "boolean // true while any run is in flight",
2303
2315
  result: "unknown // the last successful run's result; null before the first run",
2304
2316
  error: "ActionError | null",
@@ -2321,7 +2333,7 @@ const HOOKS = [
2321
2333
  "only where the operation takes one. call resolves with { status, " +
2322
2334
  "content_type, body } — the outside API's status (a non-2xx answer " +
2323
2335
  "still resolves: branch on status) and its parsed JSON or text body. " +
2324
- "The whole call must finish within 250 ms, token exchange included: a " +
2336
+ "The whole call must finish within 500 ms, token exchange included: a " +
2325
2337
  "slower outside API is cut off and the call rejects with UPSTREAM_TIMEOUT. " +
2326
2338
  "May run on mount for a read operation; an operation that changes data " +
2327
2339
  "belongs in an event handler. `connectorRef` is a connector id an " +
@@ -4414,14 +4426,15 @@ const WIDGET_CONTEXT_SHAPE = {
4414
4426
  actions: {
4415
4427
  description:
4416
4428
  "sc-13843 — injected @colixsystems/actions-client instance. " +
4417
- "{ run(actionId, input?) -> Promise<{ ok, result }>, status(actionId) -> " +
4429
+ "{ run(actionId, input?) -> Promise<{ ok, result }>, enqueue(actionId, " +
4430
+ "input?) -> Promise<{ queued: true }>, status(actionId) -> " +
4418
4431
  "Promise<{ available, reason }> }. Backs useAction(). " +
4419
4432
  "Runs one Action as the signed-in caller; the server refuses an Action " +
4420
4433
  "without the app trigger. Errors carry the server's `code` and `status`. " +
4421
4434
  "Absent on a host that brokers no actions client, where useAction() " +
4422
4435
  "degrades to available: false rather than throwing.",
4423
4436
  required: false,
4424
- fields: { run: "function", status: "function" },
4437
+ fields: { run: "function", enqueue: "function", status: "function" },
4425
4438
  },
4426
4439
  connectors: {
4427
4440
  description:
@@ -6893,7 +6906,10 @@ const CONTRACT = deepFreeze({
6893
6906
  // 1.245.0: additive (sc-15920) — a Tabs item with `value` and no `key` is
6894
6907
  // keyed by its `value`; a host may set `ctx.strictProps` so a component
6895
6908
  // throws on a prop it cannot render without (the widget check's render).
6896
- version: "1.245.0",
6909
+ // 1.246.0: additive (sc-15876) — `useAction()` gains `enqueue(input)`, which
6910
+ // queues the run and resolves at once; the script runs with the Action's
6911
+ // normal limits and returns nothing to the widget.
6912
+ version: "1.246.0",
6897
6913
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
6898
6914
  hooks: HOOKS,
6899
6915
  primitives: PRIMITIVES,
package/dist/hooks.js CHANGED
@@ -4008,9 +4008,16 @@ function toActionError(err) {
4008
4008
 
4009
4009
  /**
4010
4010
  * sc-13843 — run one of the workspace's Actions and read what it returned.
4011
- * Returns `{ available, run, running, result, error }`.
4011
+ * Returns `{ available, run, enqueue, running, result, error }`.
4012
4012
  *
4013
4013
  * run(input?) → Promise<result> the Action's `respond()` value, or null
4014
+ * enqueue(input?) → Promise<void> resolves once the run is queued
4015
+ *
4016
+ * sc-15876 — `enqueue` starts the run away from the request: the server
4017
+ * answers as soon as it accepted it and the script runs later with the
4018
+ * Action's normal limits, not the app-run deadline. Nothing comes back, so
4019
+ * `running`, `result` and `error` are untouched. A host whose client has no
4020
+ * `enqueue` rejects UNAVAILABLE.
4014
4021
  *
4015
4022
  * IMPERATIVE — it never runs on mount or render; call `run` from an event
4016
4023
  * handler. An Action can write data and send messages, so running it because
@@ -4123,10 +4130,25 @@ export function useAction(actionRef) {
4123
4130
  }
4124
4131
  }, []);
4125
4132
 
4133
+ // sc-15876: queues the run; no answer comes back, so no state changes.
4134
+ const enqueue = useCallback(async (input) => {
4135
+ const client = clientRef.current;
4136
+ const actionId = actionIdRef.current;
4137
+ if (!client || !actionId || typeof client.enqueue !== "function") {
4138
+ throw new ActionError("UNAVAILABLE", "No action is available for this host");
4139
+ }
4140
+ try {
4141
+ await client.enqueue(actionId, input);
4142
+ } catch (err) {
4143
+ throw toActionError(err);
4144
+ }
4145
+ }, []);
4146
+
4126
4147
  const current = outcome.generation === generationRef.current;
4127
4148
  return {
4128
4149
  available,
4129
4150
  run,
4151
+ enqueue,
4130
4152
  running: current && outcome.pending > 0,
4131
4153
  result: current ? outcome.result : null,
4132
4154
  error: current ? outcome.error : null,
package/dist/index.d.ts CHANGED
@@ -915,6 +915,8 @@ export interface WidgetContext<TProps = unknown> {
915
915
  run(actionId: string, input?: Record<string, unknown> | null): Promise<{ ok: boolean; result: unknown }>;
916
916
  /** sc-14224 — whether a run would reach the script; optional on older hosts. */
917
917
  status?(actionId: string): Promise<{ available: boolean; reason: string | null }>;
918
+ /** sc-15876 — queues a run; optional on older hosts. */
919
+ enqueue?(actionId: string, input?: Record<string, unknown> | null): Promise<{ queued: true }>;
918
920
  };
919
921
  /** sc-15659 — injected @colixsystems/actions-client backing useConnector(). */
920
922
  connectors?: {
@@ -2141,6 +2143,12 @@ export interface ActionApi {
2141
2143
  * value the Action passed to `respond()`, or null; rejects with ActionError.
2142
2144
  */
2143
2145
  run(input?: Record<string, unknown> | null): Promise<unknown>;
2146
+ /**
2147
+ * Imperative — queues the run and resolves once the server accepted it. The
2148
+ * script runs later with the Action's normal limits and returns nothing;
2149
+ * `running`, `result` and `error` are untouched. Rejects with ActionError.
2150
+ */
2151
+ enqueue(input?: Record<string, unknown> | null): Promise<void>;
2144
2152
  /** True while any run is in flight. */
2145
2153
  running: boolean;
2146
2154
  /** The last successful run's result; cleared when the binding changes. */
@@ -3556,7 +3564,7 @@ export class AgentError extends Error {
3556
3564
  }
3557
3565
 
3558
3566
  /**
3559
- * sc-13843 — structured error thrown by `useAction().run`. Branch on `code`:
3567
+ * sc-13843 — structured error thrown by `useAction().run` and `.enqueue`. Branch on `code`:
3560
3568
  * `ACTION_NOT_APP_INVOKABLE` and `ACTION_NOT_FOUND` will not clear on a retry,
3561
3569
  * `RATE_LIMITED` will. `AUTH_REQUIRED`, `TOKEN_EXPIRED` and `TOKEN_INVALID`
3562
3570
  * mean the app user must sign in. Never show an app user the raw message.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colixsystems/widget-sdk",
3
- "version": "0.298.0",
3
+ "version": "0.299.0",
4
4
  "description": "Common widget interface for AppStudio. Implements WidgetManifest, WidgetContext, property schema, and helper hooks.",
5
5
  "homepage": "https://github.com/Colix-AB/AppStudio",
6
6
  "type": "module",
package/src/contract.js CHANGED
@@ -2286,7 +2286,7 @@ const HOOKS = [
2286
2286
  "INVALID_ACTION_INPUT (400) — the input was refused; " +
2287
2287
  "ACTION_NOT_APP_INVOKABLE (403) and ACTION_NOT_FOUND (404) will NOT " +
2288
2288
  "clear on a retry, so hide the affordance; RATE_LIMITED (429) will; " +
2289
- "ACTION_TIMEOUT (504) — the run was still going 250 ms after the press " +
2289
+ "ACTION_TIMEOUT (504) — the run was still going 500 ms after the press " +
2290
2290
  "and was stopped, so its OUTCOME IS UNKNOWN: some of its writes may " +
2291
2291
  "have happened. Never retry it blindly and never tell the user it did " +
2292
2292
  "nothing; an Action a widget runs must do its writes as one call or be " +
@@ -2295,10 +2295,22 @@ const HOOKS = [
2295
2295
  "ACTION_FAILED — the Action ran and failed, or no answer arrived. NEVER " +
2296
2296
  "show an app user a raw error. A text answer from a bot is often " +
2297
2297
  "MARKDOWN, so render it with <RichText value={result} />, not <Text>. " +
2298
+ "enqueue(input) QUEUES the run instead: it resolves as soon " +
2299
+ "as the server accepted it (the same refusals as run), and the script " +
2300
+ "runs later, away from the request, with the Action's normal limits " +
2301
+ "rather than the 500 ms an app run gets. Nothing comes back — no " +
2302
+ "respond() value, and running/result/error are untouched — so use it to " +
2303
+ "start work the widget needs no answer from (a batch, a sync, a long " +
2304
+ "send) and tell the user it has started, never that it is done. " +
2305
+ "It is also refused when the Action is switched off (ACTION_DISABLED) " +
2306
+ "or paused (ACTION_PAUSED), and with RATE_LIMITED when the workspace " +
2307
+ "already has 10 queued runs waiting. A queued run can run twice (a " +
2308
+ "restart mid-run starts it again), so its Action must be safe to repeat. " +
2298
2309
  "Reads ctx.actions.",
2299
2310
  returnShape: {
2300
2311
  available: "boolean // false when no Action is bound, the host brokers none, or the server says a run would not reach the script",
2301
2312
  run: "(input) => Promise<unknown> // input is optional; resolves with the Action's respond() value, or null; rejects with ActionError",
2313
+ enqueue: "(input) => Promise<void> // input is optional; resolves once the run is queued, returns nothing; rejects with ActionError (run's codes plus ACTION_DISABLED, ACTION_PAUSED)",
2302
2314
  running: "boolean // true while any run is in flight",
2303
2315
  result: "unknown // the last successful run's result; null before the first run",
2304
2316
  error: "ActionError | null",
@@ -2321,7 +2333,7 @@ const HOOKS = [
2321
2333
  "only where the operation takes one. call resolves with { status, " +
2322
2334
  "content_type, body } — the outside API's status (a non-2xx answer " +
2323
2335
  "still resolves: branch on status) and its parsed JSON or text body. " +
2324
- "The whole call must finish within 250 ms, token exchange included: a " +
2336
+ "The whole call must finish within 500 ms, token exchange included: a " +
2325
2337
  "slower outside API is cut off and the call rejects with UPSTREAM_TIMEOUT. " +
2326
2338
  "May run on mount for a read operation; an operation that changes data " +
2327
2339
  "belongs in an event handler. `connectorRef` is a connector id an " +
@@ -4414,14 +4426,15 @@ const WIDGET_CONTEXT_SHAPE = {
4414
4426
  actions: {
4415
4427
  description:
4416
4428
  "sc-13843 — injected @colixsystems/actions-client instance. " +
4417
- "{ run(actionId, input?) -> Promise<{ ok, result }>, status(actionId) -> " +
4429
+ "{ run(actionId, input?) -> Promise<{ ok, result }>, enqueue(actionId, " +
4430
+ "input?) -> Promise<{ queued: true }>, status(actionId) -> " +
4418
4431
  "Promise<{ available, reason }> }. Backs useAction(). " +
4419
4432
  "Runs one Action as the signed-in caller; the server refuses an Action " +
4420
4433
  "without the app trigger. Errors carry the server's `code` and `status`. " +
4421
4434
  "Absent on a host that brokers no actions client, where useAction() " +
4422
4435
  "degrades to available: false rather than throwing.",
4423
4436
  required: false,
4424
- fields: { run: "function", status: "function" },
4437
+ fields: { run: "function", enqueue: "function", status: "function" },
4425
4438
  },
4426
4439
  connectors: {
4427
4440
  description:
@@ -6893,7 +6906,10 @@ const CONTRACT = deepFreeze({
6893
6906
  // 1.245.0: additive (sc-15920) — a Tabs item with `value` and no `key` is
6894
6907
  // keyed by its `value`; a host may set `ctx.strictProps` so a component
6895
6908
  // throws on a prop it cannot render without (the widget check's render).
6896
- version: "1.245.0",
6909
+ // 1.246.0: additive (sc-15876) — `useAction()` gains `enqueue(input)`, which
6910
+ // queues the run and resolves at once; the script runs with the Action's
6911
+ // normal limits and returns nothing to the widget.
6912
+ version: "1.246.0",
6897
6913
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
6898
6914
  hooks: HOOKS,
6899
6915
  primitives: PRIMITIVES,