@colixsystems/widget-sdk 0.357.0 → 0.358.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** | `useDatastoreSchema(tableId)` | `{ schema, loading, error, refetch }` | `schema(tableId)` — `datastore.read:<table>` |
59
59
  | **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 }`. |
60
60
  | **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. |
61
- | **AGENTS** | `useAgent(agentRef, { files }?)` | `{ send, cancel, reset, messages, sending, resuming, error, available, acceptsFiles, fileLimits }` | `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. **Files:** with `{ files: true }` the hook asks once (no credit) whether the agent reads files — `acceptsFiles`, `fileLimits` — and `send(text, { files })` sends Filestore images or PDFs with the turn. |
61
+ | **AGENTS** | `useAgent(agentRef, { files }?)` | `{ send, cancel, reset, messages, sending, resuming, error, available, acceptsFiles, fileLimits }` | `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), with `count` when a create added many rows in one step. **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. **Files:** with `{ files: true }` the hook asks once (no credit) whether the agent reads files — `acceptsFiles`, `fileLimits` — and `send(text, { files })` sends Filestore images or PDFs with the turn. |
62
62
  | **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`. |
63
63
  | **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. The result has only create, update and delete; the checker refuses a call to any other key (`datastore-method-unknown`). |
64
64
  | **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. |
@@ -91,7 +91,11 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
91
91
 
92
92
  ## Status
93
93
 
94
- `v0.357.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
+ `v0.358.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**.
95
+
96
+ ### What's new in 0.358.0 (contract 1.294.0)
97
+
98
+ **An agent that added many rows says how many.** A `create_record` entry in an assistant `AgentMessage`'s `activity` may carry `count` when one step added many rows, for example an import from a connected tool. Show it ("Added 487 rows"). With `ok: false` the `count` is 0 and nothing was added. Additive: an entry without `count` is one row, as before.
95
99
 
96
100
  ### What's new in 0.357.0 (contract 1.293.0)
97
101
 
@@ -4183,6 +4187,17 @@ export default function ContactList({ tableId, pageSize }) {
4183
4187
  }
4184
4188
  ```
4185
4189
 
4190
+ ## Shop bag (cart)
4191
+
4192
+ A shop's bag holds what the buyer means to buy until they pay. Build it the same way in every shop.
4193
+
4194
+ - **The bag is its own widget or page, never a placeholder.** It lists each item with its name, options, quantity and price, lets the buyer change the quantity and remove the item, shows a total that updates at once, and links to Checkout. An empty bag says so and links back to the shop. Every widget that adds to the bag or counts it (a header count) reads the same store, so they stay in step.
4195
+ - **A signed-in buyer's bag is a table.** One row per item: the product (a relation to the products table), its options, its quantity, and a buyer USER column that defaults to the signed-in user (`@currentUser`). Give the table creator-only access, so only that buyer can read or change their rows, and query it with the condition `{ column: "buyer", operator: "eq", valueMode: "currentUser" }` so a staff member's view never holds another buyer's rows. Adding a product creates a row, or raises the quantity of the row with the same product and options; changing the quantity updates the row, and Remove deletes it. A refresh, the menu and another device all show the same bag.
4196
+ - **A guest's bag exists only in a shop that takes guest payments.** There a visitor who is not signed in keeps the bag with `useDeviceStorage("bag", [])` as `[{ productId, options, qty }]`: product ids, options and quantities, never a price. Every widget uses that one key. When the guest signs in, the bag widget alone moves it: it copies the device bag, calls `remove()`, then adds each item to the buyer's bag table the way Add does. Other widgets, such as a header count, only read the bag. In a shop where only signed-in buyers pay there is no guest bag: Add shown to a signed-out visitor asks them to sign in with `useNavigation().signIn()`.
4197
+ - **Keep the bag out of the page address.** Never carry it in `useRouteParams()`, a navigation param, `useWidgetRoute` or a wire: the menu link and a refresh lose it, and Back after paying brings it back. Hand a product to the bag by its id.
4198
+ - **Prices come from the products table.** Show each price and the total from the products table, never from the bag. An option that changes the price (a larger size) is its own product row; an option is only a choice that keeps the price. Checkout refuses to start while an item's product is no longer sold, so no order is created for it. It creates the order and one line per bag item with its product, quantity and options (a write-once options column on the lines), then calls `requestPayment({ description, kind, order })` (a guest: `requestGuestPayment({ description, order })`) with no `amount_cents`: the server prices the order from its lines. Pay stays disabled while a payment runs.
4199
+ - **Empty the bag only after a successful payment.** At checkout, tag each bag row with its order (a relation column on the bag table). Whenever the bag loads, delete the rows whose order reads paid, so Back, a refresh, another device and an old success address all show an empty bag. A guest's device bag is cleared with `remove()` once the payment reads `PAID`. A cancelled or failed payment leaves the bag as it was.
4200
+
4186
4201
  ## Cross-platform widgets (single-file vs split)
4187
4202
 
4188
4203
  Every widget runs in **both** the web Player and the exported native (Expo) app.
package/dist/contract.cjs CHANGED
@@ -2240,7 +2240,8 @@ const HOOKS = [
2240
2240
  "{ id, role, content, created_at } with role 'user' | 'assistant'. " +
2241
2241
  "An assistant message that used a tool also carries `activity`: what " +
2242
2242
  "the agent DID — the table it read and the search text and filters it " +
2243
- "read with, or the table and columns it CHANGED. Render a write: a reply saying 'done!' is not evidence a " +
2243
+ "read with, or the table and columns it CHANGED. A create that added many rows " +
2244
+ "in one step carries `count` (absent means one row): say the number. Render a write: a reply saying 'done!' is not evidence a " +
2244
2245
  "row was written, and the user has no other way to notice a mistake. " +
2245
2246
  "A talk-only turn omits the key entirely. " +
2246
2247
  "You CANNOT set the system prompt, replay an edited transcript, " +
@@ -7208,7 +7209,9 @@ const CONTRACT = deepFreeze({
7208
7209
  // 1.293.0: additive (sc-16652) — the `payment-price-from-page` lint warning
7209
7210
  // flags an order charge whose amount comes from the page address, a
7210
7211
  // wire input or the bag.
7211
- version: "1.293.0",
7212
+ // 1.294.0 (sc-18646): additive — a `create_record` activity entry may carry
7213
+ // `count`, how many rows one step added.
7214
+ version: "1.294.0",
7212
7215
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
7213
7216
  hooks: HOOKS,
7214
7217
  primitives: PRIMITIVES,
package/dist/contract.js CHANGED
@@ -2235,7 +2235,8 @@ const HOOKS = [
2235
2235
  "{ id, role, content, created_at } with role 'user' | 'assistant'. " +
2236
2236
  "An assistant message that used a tool also carries `activity`: what " +
2237
2237
  "the agent DID — the table it read and the search text and filters it " +
2238
- "read with, or the table and columns it CHANGED. Render a write: a reply saying 'done!' is not evidence a " +
2238
+ "read with, or the table and columns it CHANGED. A create that added many rows " +
2239
+ "in one step carries `count` (absent means one row): say the number. Render a write: a reply saying 'done!' is not evidence a " +
2239
2240
  "row was written, and the user has no other way to notice a mistake. " +
2240
2241
  "A talk-only turn omits the key entirely. " +
2241
2242
  "You CANNOT set the system prompt, replay an edited transcript, " +
@@ -7203,7 +7204,9 @@ const CONTRACT = deepFreeze({
7203
7204
  // 1.293.0: additive (sc-16652) — the `payment-price-from-page` lint warning
7204
7205
  // flags an order charge whose amount comes from the page address, a
7205
7206
  // wire input or the bag.
7206
- version: "1.293.0",
7207
+ // 1.294.0 (sc-18646): additive — a `create_record` activity entry may carry
7208
+ // `count`, how many rows one step added.
7209
+ version: "1.294.0",
7207
7210
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
7208
7211
  hooks: HOOKS,
7209
7212
  primitives: PRIMITIVES,
package/dist/index.d.ts CHANGED
@@ -2249,6 +2249,8 @@ export interface AgentActivity {
2249
2249
  table?: string;
2250
2250
  record_id?: string;
2251
2251
  fields?: string[];
2252
+ /** On a `create_record` that added many rows in one step: how many it added. */
2253
+ count?: number;
2252
2254
  /** A read's own search text: what the agent looked FOR, never what it found. */
2253
2255
  search?: string;
2254
2256
  /** A read's own filter conditions, as the agent asked for them. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colixsystems/widget-sdk",
3
- "version": "0.357.0",
3
+ "version": "0.358.0",
4
4
  "description": "Common widget interface for AppStudio. Implements WidgetManifest, WidgetContext, property schema, and helper hooks.",
5
5
  "repository": {
6
6
  "type": "git",
package/src/contract.js CHANGED
@@ -2235,7 +2235,8 @@ const HOOKS = [
2235
2235
  "{ id, role, content, created_at } with role 'user' | 'assistant'. " +
2236
2236
  "An assistant message that used a tool also carries `activity`: what " +
2237
2237
  "the agent DID — the table it read and the search text and filters it " +
2238
- "read with, or the table and columns it CHANGED. Render a write: a reply saying 'done!' is not evidence a " +
2238
+ "read with, or the table and columns it CHANGED. A create that added many rows " +
2239
+ "in one step carries `count` (absent means one row): say the number. Render a write: a reply saying 'done!' is not evidence a " +
2239
2240
  "row was written, and the user has no other way to notice a mistake. " +
2240
2241
  "A talk-only turn omits the key entirely. " +
2241
2242
  "You CANNOT set the system prompt, replay an edited transcript, " +
@@ -7203,7 +7204,9 @@ const CONTRACT = deepFreeze({
7203
7204
  // 1.293.0: additive (sc-16652) — the `payment-price-from-page` lint warning
7204
7205
  // flags an order charge whose amount comes from the page address, a
7205
7206
  // wire input or the bag.
7206
- version: "1.293.0",
7207
+ // 1.294.0 (sc-18646): additive — a `create_record` activity entry may carry
7208
+ // `count`, how many rows one step added.
7209
+ version: "1.294.0",
7207
7210
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
7208
7211
  hooks: HOOKS,
7209
7212
  primitives: PRIMITIVES,