@colixsystems/widget-sdk 0.360.0 → 0.361.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 +6 -2
- package/dist/contract.cjs +8 -4
- package/dist/contract.js +8 -4
- package/dist/hooks.js +11 -31
- package/dist/index.d.ts +5 -5
- package/package.json +1 -1
- package/src/contract.js +8 -4
package/README.md
CHANGED
|
@@ -56,7 +56,7 @@ The data layer lives in **four separate domain-client packages**, each instantia
|
|
|
56
56
|
| **DATASTORE** | `useDatastoreFigure(table, { aggregate, column, filter })` (optional: options) | `{ value, text, truncated, loading, fetching, error, refetch }` | `records(table).list` (a count reads the envelope total; a sum or average up to 1000 rows) — `datastore.read:*`. One count / sum / average for a `<Stat>`, computed exactly as the built-in Stat widget does. |
|
|
57
57
|
| **DATASTORE** | `useDatastoreRecord(table, id, options)` (optional: options) | `{ data, loading, fetching, error, refetch }` — a refetch of the same record keeps `data` while `fetching`; `{ includeCapabilities: true }` adds `data._capabilities` | `records(table).get` — `datastore.read:<table>` |
|
|
58
58
|
| **DATASTORE** | `useDatastoreSchema(tableId)` | `{ schema, loading, error, refetch }` | `schema(tableId)` — `datastore.read:<table>` |
|
|
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
|
|
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. A `dataType` match alone never binds: a name that matches no column is listed in `missing` instead of showing another column. `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
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`. |
|
|
@@ -93,7 +93,11 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
|
|
|
93
93
|
|
|
94
94
|
## Status
|
|
95
95
|
|
|
96
|
-
`v0.
|
|
96
|
+
`v0.361.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**.
|
|
97
|
+
|
|
98
|
+
### What's new in 0.361.0 (contract 1.297.0)
|
|
99
|
+
|
|
100
|
+
**`useBoundColumns` no longer guesses a column by type.** A key whose bound name matches no column, exactly or case-insensitively, now reads `undefined` and is listed in `missing` (unless `optional: true`). It used to take the first free column of the key's `dataType`, so a widget could show the wrong column with no warning, while the Studio's Properties panel and the preview showed the prop unbound. Pick the column in the Properties panel, or declare `ui.autoFill: { names, types }` on the `columnRef` so the Studio picks one by type when the table is chosen and stores it. `dataType` stays in the shape as the column type the key expects. Behaviour change; minor bump.
|
|
97
101
|
|
|
98
102
|
### What's new in 0.360.0 (contract 1.296.0)
|
|
99
103
|
|
package/dist/contract.cjs
CHANGED
|
@@ -2169,9 +2169,10 @@ const HOOKS = [
|
|
|
2169
2169
|
description:
|
|
2170
2170
|
"sc-5206 — resolve author-bound column NAMES from a widget's own props, built on useDatastoreSchema. shape is " +
|
|
2171
2171
|
"{ [propKey]: { dataType?, optional? } }; props is the widget's own props carrying author-bound column names (e.g. props.titleField === " +
|
|
2172
|
-
"'Title'). Resolution order per key: (1) an exact name match on props[key], (2) a case-insensitive name match,
|
|
2173
|
-
"
|
|
2174
|
-
"
|
|
2172
|
+
"'Title'). Resolution order per key: (1) an exact name match on props[key], (2) a case-insensitive name match, each skipping a column an " +
|
|
2173
|
+
"EARLIER key in this call already claimed, (3) unresolved. A dataType match alone never binds: dataType states the column type the key " +
|
|
2174
|
+
"expects. Unresolved NEVER throws — the key reads undefined and is named in missing, so a stale or unset binding degrades visibly instead " +
|
|
2175
|
+
"of crashing the widget or showing another column. Returns { columns, resolved, " +
|
|
2175
2176
|
"missing, loading, error }: columns holds the resolved column NAME — a drop-in replacement for record[props.titleField] -> " +
|
|
2176
2177
|
"record[columns.titleField]; resolved holds the full Column object (snake_case verbatim, as useDatastoreSchema returns it) so a caller can " +
|
|
2177
2178
|
"inspect resolved.<key>.data_type; missing lists every key whose spec is not optional:true and did not resolve. Falsy tableId collapses to " +
|
|
@@ -7276,7 +7277,10 @@ const CONTRACT = deepFreeze({
|
|
|
7276
7277
|
// 1.296.0: additive (sc-18707) — a template column may declare
|
|
7277
7278
|
// `rentalStart` / `rentalEnd` (and `rentalByNight` on the end); the
|
|
7278
7279
|
// server prices a rental by its days or nights.
|
|
7279
|
-
|
|
7280
|
+
// 1.297.0: behaviour (sc-16663) — `useBoundColumns` no longer binds a key
|
|
7281
|
+
// to the first free column of its `dataType`; a name that matches no
|
|
7282
|
+
// column is `missing`, as the Studio and preview binders already showed.
|
|
7283
|
+
version: "1.297.0",
|
|
7280
7284
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
7281
7285
|
hooks: HOOKS,
|
|
7282
7286
|
primitives: PRIMITIVES,
|
package/dist/contract.js
CHANGED
|
@@ -2164,9 +2164,10 @@ const HOOKS = [
|
|
|
2164
2164
|
description:
|
|
2165
2165
|
"sc-5206 — resolve author-bound column NAMES from a widget's own props, built on useDatastoreSchema. shape is " +
|
|
2166
2166
|
"{ [propKey]: { dataType?, optional? } }; props is the widget's own props carrying author-bound column names (e.g. props.titleField === " +
|
|
2167
|
-
"'Title'). Resolution order per key: (1) an exact name match on props[key], (2) a case-insensitive name match,
|
|
2168
|
-
"
|
|
2169
|
-
"
|
|
2167
|
+
"'Title'). Resolution order per key: (1) an exact name match on props[key], (2) a case-insensitive name match, each skipping a column an " +
|
|
2168
|
+
"EARLIER key in this call already claimed, (3) unresolved. A dataType match alone never binds: dataType states the column type the key " +
|
|
2169
|
+
"expects. Unresolved NEVER throws — the key reads undefined and is named in missing, so a stale or unset binding degrades visibly instead " +
|
|
2170
|
+
"of crashing the widget or showing another column. Returns { columns, resolved, " +
|
|
2170
2171
|
"missing, loading, error }: columns holds the resolved column NAME — a drop-in replacement for record[props.titleField] -> " +
|
|
2171
2172
|
"record[columns.titleField]; resolved holds the full Column object (snake_case verbatim, as useDatastoreSchema returns it) so a caller can " +
|
|
2172
2173
|
"inspect resolved.<key>.data_type; missing lists every key whose spec is not optional:true and did not resolve. Falsy tableId collapses to " +
|
|
@@ -7271,7 +7272,10 @@ const CONTRACT = deepFreeze({
|
|
|
7271
7272
|
// 1.296.0: additive (sc-18707) — a template column may declare
|
|
7272
7273
|
// `rentalStart` / `rentalEnd` (and `rentalByNight` on the end); the
|
|
7273
7274
|
// server prices a rental by its days or nights.
|
|
7274
|
-
|
|
7275
|
+
// 1.297.0: behaviour (sc-16663) — `useBoundColumns` no longer binds a key
|
|
7276
|
+
// to the first free column of its `dataType`; a name that matches no
|
|
7277
|
+
// column is `missing`, as the Studio and preview binders already showed.
|
|
7278
|
+
version: "1.297.0",
|
|
7275
7279
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
7276
7280
|
hooks: HOOKS,
|
|
7277
7281
|
primitives: PRIMITIVES,
|
package/dist/hooks.js
CHANGED
|
@@ -3393,13 +3393,6 @@ export function useDatastoreSchema(tableId) {
|
|
|
3393
3393
|
return { schema, loading, error, refetch };
|
|
3394
3394
|
}
|
|
3395
3395
|
|
|
3396
|
-
// Columns reach widgets as wire `data_type`; manifest-derived ones carry
|
|
3397
|
-
// `dataType`. The shipped widgets already read both — keep one reading here.
|
|
3398
|
-
function columnType(column) {
|
|
3399
|
-
if (!column) return undefined;
|
|
3400
|
-
return column.data_type ?? column.dataType;
|
|
3401
|
-
}
|
|
3402
|
-
|
|
3403
3396
|
// Identity for the claimed-set. Falls back to the name so an id-less column
|
|
3404
3397
|
// can't claim `undefined` and starve every later key.
|
|
3405
3398
|
function columnKey(column) {
|
|
@@ -3415,12 +3408,14 @@ function columnKey(column) {
|
|
|
3415
3408
|
* (e.g. `props.titleField === "Title"`).
|
|
3416
3409
|
*
|
|
3417
3410
|
* Resolution order per key: (1) an exact `name` match on `props[key]`,
|
|
3418
|
-
* (2) a case-insensitive name match,
|
|
3419
|
-
*
|
|
3420
|
-
*
|
|
3421
|
-
*
|
|
3422
|
-
*
|
|
3423
|
-
*
|
|
3411
|
+
* (2) a case-insensitive name match, each skipping a column an EARLIER key in
|
|
3412
|
+
* this same call already claimed, (3) unresolved. A `dataType` match alone
|
|
3413
|
+
* never binds (sc-16663): it showed the wrong column with no warning, and the
|
|
3414
|
+
* Studio and preview binders never guess without a `ui.autoFill` hint.
|
|
3415
|
+
* `dataType` states the column type the key expects. Unresolved never
|
|
3416
|
+
* throws — the key reads `undefined` and is named in `missing` — so a
|
|
3417
|
+
* column an author renamed after install, or never bound, degrades visibly
|
|
3418
|
+
* instead of crashing.
|
|
3424
3419
|
*
|
|
3425
3420
|
* Returns `{ columns, resolved, missing, loading, error }`. `columns` holds
|
|
3426
3421
|
* the resolved column NAME — a drop-in replacement for
|
|
@@ -3523,24 +3518,9 @@ export function useBoundColumns(tableId, shape, props) {
|
|
|
3523
3518
|
});
|
|
3524
3519
|
|
|
3525
3520
|
for (const key of stillUnresolved) {
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
const types = spec.dataType
|
|
3530
|
-
? Array.isArray(spec.dataType)
|
|
3531
|
-
? spec.dataType
|
|
3532
|
-
: [spec.dataType]
|
|
3533
|
-
: null;
|
|
3534
|
-
const match =
|
|
3535
|
-
types &&
|
|
3536
|
-
schemaColumns.find((c) => free(c) && types.includes(columnType(c)));
|
|
3537
|
-
if (match) {
|
|
3538
|
-
take(key, match);
|
|
3539
|
-
} else {
|
|
3540
|
-
columns[key] = undefined;
|
|
3541
|
-
resolved[key] = undefined;
|
|
3542
|
-
if (spec.optional !== true) missing.push(key);
|
|
3543
|
-
}
|
|
3521
|
+
columns[key] = undefined;
|
|
3522
|
+
resolved[key] = undefined;
|
|
3523
|
+
if ((shape[key] || {}).optional !== true) missing.push(key);
|
|
3544
3524
|
}
|
|
3545
3525
|
return { columns, resolved, missing, loading, error };
|
|
3546
3526
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
package/dist/index.d.ts
CHANGED
|
@@ -2134,6 +2134,7 @@ export function useDatastoreSchema(
|
|
|
2134
2134
|
|
|
2135
2135
|
/** sc-5206 — one prop key `useBoundColumns` resolves to a schema column. */
|
|
2136
2136
|
export interface BoundColumnSpec {
|
|
2137
|
+
/** The column type the key expects. Never picks a column on its own. */
|
|
2137
2138
|
dataType?: string | string[];
|
|
2138
2139
|
/** When true, an unresolved key is omitted from `missing`. */
|
|
2139
2140
|
optional?: boolean;
|
|
@@ -2154,11 +2155,10 @@ export interface BoundColumnsResult {
|
|
|
2154
2155
|
|
|
2155
2156
|
/**
|
|
2156
2157
|
* sc-5206 — resolve author-bound column NAMES from a widget's own props,
|
|
2157
|
-
* built on `useDatastoreSchema`.
|
|
2158
|
-
*
|
|
2159
|
-
*
|
|
2160
|
-
*
|
|
2161
|
-
* in `missing`. Falsy `tableId` collapses to `{ columns: {}, resolved: {},
|
|
2158
|
+
* built on `useDatastoreSchema`. Matches the bound name exactly, then
|
|
2159
|
+
* case-insensitively; a `dataType` match alone never binds. Never throws for a
|
|
2160
|
+
* missing column — an unresolved key reads `undefined` and, when not
|
|
2161
|
+
* `optional: true`, is named in `missing`. Falsy `tableId` collapses to `{ columns: {}, resolved: {},
|
|
2162
2162
|
* missing: Object.keys(shape), loading: false, error: null }`.
|
|
2163
2163
|
*/
|
|
2164
2164
|
export function useBoundColumns<TProps = Record<string, unknown>>(
|
package/package.json
CHANGED
package/src/contract.js
CHANGED
|
@@ -2164,9 +2164,10 @@ const HOOKS = [
|
|
|
2164
2164
|
description:
|
|
2165
2165
|
"sc-5206 — resolve author-bound column NAMES from a widget's own props, built on useDatastoreSchema. shape is " +
|
|
2166
2166
|
"{ [propKey]: { dataType?, optional? } }; props is the widget's own props carrying author-bound column names (e.g. props.titleField === " +
|
|
2167
|
-
"'Title'). Resolution order per key: (1) an exact name match on props[key], (2) a case-insensitive name match,
|
|
2168
|
-
"
|
|
2169
|
-
"
|
|
2167
|
+
"'Title'). Resolution order per key: (1) an exact name match on props[key], (2) a case-insensitive name match, each skipping a column an " +
|
|
2168
|
+
"EARLIER key in this call already claimed, (3) unresolved. A dataType match alone never binds: dataType states the column type the key " +
|
|
2169
|
+
"expects. Unresolved NEVER throws — the key reads undefined and is named in missing, so a stale or unset binding degrades visibly instead " +
|
|
2170
|
+
"of crashing the widget or showing another column. Returns { columns, resolved, " +
|
|
2170
2171
|
"missing, loading, error }: columns holds the resolved column NAME — a drop-in replacement for record[props.titleField] -> " +
|
|
2171
2172
|
"record[columns.titleField]; resolved holds the full Column object (snake_case verbatim, as useDatastoreSchema returns it) so a caller can " +
|
|
2172
2173
|
"inspect resolved.<key>.data_type; missing lists every key whose spec is not optional:true and did not resolve. Falsy tableId collapses to " +
|
|
@@ -7271,7 +7272,10 @@ const CONTRACT = deepFreeze({
|
|
|
7271
7272
|
// 1.296.0: additive (sc-18707) — a template column may declare
|
|
7272
7273
|
// `rentalStart` / `rentalEnd` (and `rentalByNight` on the end); the
|
|
7273
7274
|
// server prices a rental by its days or nights.
|
|
7274
|
-
|
|
7275
|
+
// 1.297.0: behaviour (sc-16663) — `useBoundColumns` no longer binds a key
|
|
7276
|
+
// to the first free column of its `dataType`; a name that matches no
|
|
7277
|
+
// column is `missing`, as the Studio and preview binders already showed.
|
|
7278
|
+
version: "1.297.0",
|
|
7275
7279
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
7276
7280
|
hooks: HOOKS,
|
|
7277
7281
|
primitives: PRIMITIVES,
|