@colixsystems/widget-sdk 0.306.0 → 0.308.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
@@ -57,7 +57,7 @@ The data layer lives in **four separate domain-client packages**, each instantia
57
57
  | **DATASTORE** | `useDatastoreSchema(tableId)` | `{ schema, loading, error, refetch }` | `schema(tableId)` — `datastore.read:<table>` |
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
- | **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. |
60
+ | **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
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. |
@@ -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.306.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.308.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.308.0 (contract 1.252.0)
96
+
97
+ **A filter can ask "is any of".** The records filter gains the `in` operator. In the array form, pass the values as an array: `filter: [{ column: "status", operator: "in", value: ["Open", "Waiting"] }]` keeps the rows whose status is either, in one request. On a list column (`STRING_ARRAY`, `INT_ARRAY`) it keeps the rows whose list holds any of the values, so a chip row with several picks needs one read, not one per pick or a fetched batch narrowed in JavaScript. It works on relation columns and `id`; it is refused on `created_at` / `updated_at`, on encrypted columns and with a `currentUser` / `currentUserGroup` value mode. At most 100 values, each valid for the column, or the read fails with `INVALID_FILTER`. An empty array throws a `ValidationError` instead of reading every row: leave the condition out when there is nothing to pick. A `filterList` property's conditions can use it too: the Studio's filter editor offers "is any of" and stores the values as an array. An array `value` with any other operator now throws a `ValidationError` instead of being sent as one joined value. Needs `@colixsystems/datastore-client` 0.27.0 in the host.
98
+
99
+ ### What's new in 0.307.0 (contract 1.251.0)
100
+
101
+ **`useAgent()` can send images and PDFs with a turn.** Call `useAgent(agentRef, { files: true })` and the hook asks the server once, spending no AI credit, whether this agent reads files. `acceptsFiles` and `fileLimits` (`{ types, maxFiles, maxPdfs, maxFileBytes, maxTotalBytes }`) answer it: show an attach control only when `acceptsFiles` is true. Then `send(text, { files })` sends up to `maxFiles` Filestore images (PNG, JPEG, WebP, GIF) or PDFs, each a file id or a `{ id }` row from `useFilestoreUpload`. Each file is read as the signed-in user, so one they may not download is refused before the model is called. Images are downscaled and a PDF reaches the model as its text and page images, so any agent whose provider reads images reads both. The bytes reach the model on that turn only, and a user message that carried files has `attachments` (`{ file_id, name, mime_type, size_bytes }`). An agent whose provider cannot read files reports `acceptsFiles: false`, and a send with files is refused with `AGENT_PROVIDER_CANNOT_READ_FILES`. Without `{ files: true }` nothing extra is requested and `acceptsFiles` stays false. The `agents` host client gains `capabilities(agentId)`.
94
102
 
95
103
  ### What's new in 0.306.0 (contract 1.250.0)
96
104
 
@@ -3806,7 +3814,7 @@ export default function OpenTasks({ tableId, titleField, statusField }) {
3806
3814
  | `offset` | Rows to skip, for the next page. |
3807
3815
  | `includeCapabilities` | `true` stamps each row with `_capabilities`, what the signed-in user may do to it. |
3808
3816
 
3809
- The filter operators are `eq`, `neq`, `gt`, `gte`, `lt`, `lte`, `contains` (a case-insensitive substring), `empty` and `nempty` (no value). On a list column (`STRING_ARRAY`, `INT_ARRAY`), `eq` keeps the rows whose list holds the value exactly, `empty` / `nempty` test whether it holds any, and every other operator is refused. In the array form a condition may carry `valueMode`: `"currentUser"` or `"currentUserGroup"` with `eq` or `neq` matches the signed-in user (or their groups) on a USER or USER_GROUP column, and `"relativeDate"` with an ordering operator reads `value` as "that many days ago".
3817
+ The filter operators are `eq`, `neq`, `gt`, `gte`, `lt`, `lte`, `contains` (a case-insensitive substring), `in` (is any of), `empty` and `nempty` (no value). `in` takes an array `value` in the array form (`{ column, operator: "in", value: ["Open", "Waiting"] }`), at most 100 values; an empty array is refused (leave the condition out instead). On a list column (`STRING_ARRAY`, `INT_ARRAY`), `eq` keeps the rows whose list holds the value exactly, `in` the rows whose list holds any of the values, `empty` / `nempty` test whether it holds any, and every other operator is refused. In the array form a condition may carry `valueMode`: `"currentUser"` or `"currentUserGroup"` with `eq` or `neq` matches the signed-in user (or their groups) on a USER or USER_GROUP column, and `"relativeDate"` with an ordering operator reads `value` as "that many days ago".
3810
3818
 
3811
3819
  The result's `total` is how many rows match in all, not just this page. **A list that grows reads its rows with `usePagedDatastoreQuery(tableId, { pageSize, ...query })`**, which takes the same options bar `limit` / `offset`, sets those itself, and appends the next page on `loadMore()`. Declare `pageSize: PAGE_SIZE_PROPERTY` in the `propertySchema` so the maker sets the rows per page. For a count, a sum or an average, use `useDatastoreFigure(tableId, { aggregate, column, filter })` instead of reading rows.
3812
3820
 
package/dist/contract.cjs CHANGED
@@ -1994,7 +1994,9 @@ const HOOKS = [
1994
1994
  "a write; the re-read is the same permission-checked read, and keeps the " +
1995
1995
  "rows on screen with loading false). Use it for lists other people " +
1996
1996
  "change: queues, bookings, chat, dashboards. Never poll with setInterval " +
1997
- "or wire useDatastoreSubscription for that.",
1997
+ "or wire useDatastoreSubscription for that. A `filter` condition " +
1998
+ "`{ column, operator: \"in\", value: [a, b] }` keeps rows whose value " +
1999
+ "is any of the list (a list column: holding any of it), at most 100 values.",
1998
2000
  returnShape: {
1999
2001
  data: "Record[]",
2000
2002
  total: "number | null",
@@ -2200,7 +2202,8 @@ const HOOKS = [
2200
2202
  },
2201
2203
  {
2202
2204
  name: "useAgent",
2203
- signature: "useAgent(agentRef)",
2205
+ signature: "useAgent(agentRef, options)",
2206
+ optionalArgs: ["options"],
2204
2207
  description:
2205
2208
  "sc-7991 — hold a conversation with one of the WORKSPACE's own AI " +
2206
2209
  "agents (an author-written name + system prompt). IMPERATIVE: call " +
@@ -2249,9 +2252,18 @@ const HOOKS = [
2249
2252
  "plain <Text> shows the raw markers to the app user, so a numbered " +
2250
2253
  "how-to arrives as one unreadable line. The USER's own message " +
2251
2254
  "stays <Text>: someone who types *maybe* means asterisks. " +
2255
+ "FILES (sc-16546): call useAgent(agentRef, { files: true }) and the hook " +
2256
+ "asks once, spending no credit, whether this agent reads files; " +
2257
+ "`acceptsFiles` and `fileLimits` ({ types, maxFiles, maxPdfs, maxFileBytes, maxTotalBytes }) " +
2258
+ "answer. Only then offer an attach control, and send with " +
2259
+ "send(text, { files }) where files are Filestore file ids (or { id } rows " +
2260
+ "from useFilestoreUpload) of images or PDFs. Each file is read as the " +
2261
+ "signed-in user, reaches the model on that turn only, and a user message " +
2262
+ "that carried files has `attachments` ({ file_id, name, mime_type, size_bytes }). " +
2263
+ "Without { files: true } `acceptsFiles` stays false and nothing extra is requested. " +
2252
2264
  "Reads ctx.agents.",
2253
2265
  returnShape: {
2254
- send: "(text) => Promise<{ id, role, content, created_at } | null>",
2266
+ send: "(text, { files }?) => Promise<{ id, role, content, created_at } | null>",
2255
2267
  reset: "() => void",
2256
2268
  messages: "Array<{ id, conversation_id, role, content, created_at }>",
2257
2269
  sending: "boolean",
@@ -2259,6 +2271,8 @@ const HOOKS = [
2259
2271
  "boolean // true only while the stored transcript is being reopened on mount; show a loading state, not an empty thread",
2260
2272
  error: "AgentError | null",
2261
2273
  available: "boolean // false when no agent is bound, or the host brokers none",
2274
+ acceptsFiles: "boolean // asked only with { files: true }; false until the server says the agent reads files",
2275
+ fileLimits: "{ types, maxFiles, maxPdfs, maxFileBytes, maxTotalBytes } | null",
2262
2276
  },
2263
2277
  requiredContextSlice: ["agents.conversations"],
2264
2278
  scopes: ["ai.invoke:*"],
@@ -4072,6 +4086,8 @@ const ACTION_SCRIPT_GLOBALS = [
4072
4086
  "input",
4073
4087
  // sc-13843 — hands the app run its one JSON result.
4074
4088
  "respond",
4089
+ // sc-16548 — one turn of a workspace AI agent.
4090
+ "agents",
4075
4091
  ];
4076
4092
  // Mirrors action.service.js SCRIPT_MAX_BYTES.
4077
4093
  const ACTION_SCRIPT_MAX_BYTES = 200 * 1024;
@@ -4415,9 +4431,10 @@ const WIDGET_CONTEXT_SHAPE = {
4415
4431
  description:
4416
4432
  "sc-7991 — injected @colixsystems/agents-client instance. " +
4417
4433
  "{ conversations(agentId) -> { create(), list(query), remove(conversationId), " +
4418
- "messages(conversationId) -> { list(query), send({ content }) } } }. " +
4434
+ "messages(conversationId) -> { list(query), send({ content, file_ids? }) } }, " +
4435
+ "capabilities(agentId) -> Promise<{ accepts_files, accepted_file_types, max_files, max_pdfs, max_file_bytes, max_total_bytes }> }. " +
4419
4436
  "Backs useAgent(). The workspace's agent owns the system prompt and the " +
4420
- "server owns the transcript, so `send` puts ONLY `content` on the wire — " +
4437
+ "server owns the transcript, so `send` puts ONLY `content` and `file_ids` on the wire — " +
4421
4438
  "a prompt, a history or a model id cannot be smuggled through. " +
4422
4439
  "A conversation belongs to the CALLER (the app user, or the studio user " +
4423
4440
  "previewing on the canvas); another user's id is a 404, never a 403. " +
@@ -6921,7 +6938,14 @@ const CONTRACT = deepFreeze({
6921
6938
  // of forcing `alignSelf: "flex-start"`; it still hugs its label.
6922
6939
  // 1.250.0: documentation (sc-16511) — the read hooks' `error` names the
6923
6940
  // `{ code, message, retryable }` it has always carried; Retry only when retryable.
6924
- version: "1.250.0",
6941
+ // 1.251.0: additive (sc-16546) — `useAgent(agentRef, { files: true })`
6942
+ // reports `acceptsFiles` / `fileLimits`, `send(text, { files })` sends
6943
+ // images and PDFs, and the `agents` client gains `capabilities()`.
6944
+ // 1.252.0: additive — the records filter gains `in` ("is any of"). A
6945
+ // `filterList` condition and a query's array-form `filter` take
6946
+ // `{ operator: "in", value: [a, b] }`; on a list column it matches a row
6947
+ // holding any of the values. At most 100; no `valueMode` applies.
6948
+ version: "1.252.0",
6925
6949
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
6926
6950
  hooks: HOOKS,
6927
6951
  primitives: PRIMITIVES,
package/dist/contract.js CHANGED
@@ -1989,7 +1989,9 @@ const HOOKS = [
1989
1989
  "a write; the re-read is the same permission-checked read, and keeps the " +
1990
1990
  "rows on screen with loading false). Use it for lists other people " +
1991
1991
  "change: queues, bookings, chat, dashboards. Never poll with setInterval " +
1992
- "or wire useDatastoreSubscription for that.",
1992
+ "or wire useDatastoreSubscription for that. A `filter` condition " +
1993
+ "`{ column, operator: \"in\", value: [a, b] }` keeps rows whose value " +
1994
+ "is any of the list (a list column: holding any of it), at most 100 values.",
1993
1995
  returnShape: {
1994
1996
  data: "Record[]",
1995
1997
  total: "number | null",
@@ -2195,7 +2197,8 @@ const HOOKS = [
2195
2197
  },
2196
2198
  {
2197
2199
  name: "useAgent",
2198
- signature: "useAgent(agentRef)",
2200
+ signature: "useAgent(agentRef, options)",
2201
+ optionalArgs: ["options"],
2199
2202
  description:
2200
2203
  "sc-7991 — hold a conversation with one of the WORKSPACE's own AI " +
2201
2204
  "agents (an author-written name + system prompt). IMPERATIVE: call " +
@@ -2244,9 +2247,18 @@ const HOOKS = [
2244
2247
  "plain <Text> shows the raw markers to the app user, so a numbered " +
2245
2248
  "how-to arrives as one unreadable line. The USER's own message " +
2246
2249
  "stays <Text>: someone who types *maybe* means asterisks. " +
2250
+ "FILES (sc-16546): call useAgent(agentRef, { files: true }) and the hook " +
2251
+ "asks once, spending no credit, whether this agent reads files; " +
2252
+ "`acceptsFiles` and `fileLimits` ({ types, maxFiles, maxPdfs, maxFileBytes, maxTotalBytes }) " +
2253
+ "answer. Only then offer an attach control, and send with " +
2254
+ "send(text, { files }) where files are Filestore file ids (or { id } rows " +
2255
+ "from useFilestoreUpload) of images or PDFs. Each file is read as the " +
2256
+ "signed-in user, reaches the model on that turn only, and a user message " +
2257
+ "that carried files has `attachments` ({ file_id, name, mime_type, size_bytes }). " +
2258
+ "Without { files: true } `acceptsFiles` stays false and nothing extra is requested. " +
2247
2259
  "Reads ctx.agents.",
2248
2260
  returnShape: {
2249
- send: "(text) => Promise<{ id, role, content, created_at } | null>",
2261
+ send: "(text, { files }?) => Promise<{ id, role, content, created_at } | null>",
2250
2262
  reset: "() => void",
2251
2263
  messages: "Array<{ id, conversation_id, role, content, created_at }>",
2252
2264
  sending: "boolean",
@@ -2254,6 +2266,8 @@ const HOOKS = [
2254
2266
  "boolean // true only while the stored transcript is being reopened on mount; show a loading state, not an empty thread",
2255
2267
  error: "AgentError | null",
2256
2268
  available: "boolean // false when no agent is bound, or the host brokers none",
2269
+ acceptsFiles: "boolean // asked only with { files: true }; false until the server says the agent reads files",
2270
+ fileLimits: "{ types, maxFiles, maxPdfs, maxFileBytes, maxTotalBytes } | null",
2257
2271
  },
2258
2272
  requiredContextSlice: ["agents.conversations"],
2259
2273
  scopes: ["ai.invoke:*"],
@@ -4067,6 +4081,8 @@ const ACTION_SCRIPT_GLOBALS = [
4067
4081
  "input",
4068
4082
  // sc-13843 — hands the app run its one JSON result.
4069
4083
  "respond",
4084
+ // sc-16548 — one turn of a workspace AI agent.
4085
+ "agents",
4070
4086
  ];
4071
4087
  // Mirrors action.service.js SCRIPT_MAX_BYTES.
4072
4088
  const ACTION_SCRIPT_MAX_BYTES = 200 * 1024;
@@ -4410,9 +4426,10 @@ const WIDGET_CONTEXT_SHAPE = {
4410
4426
  description:
4411
4427
  "sc-7991 — injected @colixsystems/agents-client instance. " +
4412
4428
  "{ conversations(agentId) -> { create(), list(query), remove(conversationId), " +
4413
- "messages(conversationId) -> { list(query), send({ content }) } } }. " +
4429
+ "messages(conversationId) -> { list(query), send({ content, file_ids? }) } }, " +
4430
+ "capabilities(agentId) -> Promise<{ accepts_files, accepted_file_types, max_files, max_pdfs, max_file_bytes, max_total_bytes }> }. " +
4414
4431
  "Backs useAgent(). The workspace's agent owns the system prompt and the " +
4415
- "server owns the transcript, so `send` puts ONLY `content` on the wire — " +
4432
+ "server owns the transcript, so `send` puts ONLY `content` and `file_ids` on the wire — " +
4416
4433
  "a prompt, a history or a model id cannot be smuggled through. " +
4417
4434
  "A conversation belongs to the CALLER (the app user, or the studio user " +
4418
4435
  "previewing on the canvas); another user's id is a 404, never a 403. " +
@@ -6916,7 +6933,14 @@ const CONTRACT = deepFreeze({
6916
6933
  // of forcing `alignSelf: "flex-start"`; it still hugs its label.
6917
6934
  // 1.250.0: documentation (sc-16511) — the read hooks' `error` names the
6918
6935
  // `{ code, message, retryable }` it has always carried; Retry only when retryable.
6919
- version: "1.250.0",
6936
+ // 1.251.0: additive (sc-16546) — `useAgent(agentRef, { files: true })`
6937
+ // reports `acceptsFiles` / `fileLimits`, `send(text, { files })` sends
6938
+ // images and PDFs, and the `agents` client gains `capabilities()`.
6939
+ // 1.252.0: additive — the records filter gains `in` ("is any of"). A
6940
+ // `filterList` condition and a query's array-form `filter` take
6941
+ // `{ operator: "in", value: [a, b] }`; on a list column it matches a row
6942
+ // holding any of the values. At most 100; no `valueMode` applies.
6943
+ version: "1.252.0",
6920
6944
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
6921
6945
  hooks: HOOKS,
6922
6946
  primitives: PRIMITIVES,
package/dist/hooks.js CHANGED
@@ -3610,6 +3610,14 @@ export function useInterpretDraft(tableId) {
3610
3610
  * - "AGENT_DISABLED" — 409 (the author turned it off; it still exists)
3611
3611
  * - "CONVERSATION_NOT_FOUND"— 404 (a stale thread; `reset()` starts a new one)
3612
3612
  * - "INVALID_MESSAGE" — 400 (empty, or past the length cap)
3613
+ * - "FILE_NOT_FOUND" / "FILE_DOWNLOAD_NOT_PERMITTED" / "FILE_TOO_LARGE" /
3614
+ * "TOO_MANY_FILES" / "UNSUPPORTED_FILE_TYPE" — a file sent with the turn
3615
+ * was refused (sc-16546); nothing was billed
3616
+ * - "AGENT_FILES_NOT_ACCEPTED" / "AGENT_PROVIDER_CANNOT_READ_FILES" — 422
3617
+ * (this agent reads no files; hide the attach
3618
+ * control rather than retrying)
3619
+ * - "AGENT_FILES_BUSY" — 503 (the server could not take the files on
3620
+ * right now; retry shortly)
3613
3621
  * - "AI_QUOTA_EXCEEDED" — 429 (the WORKSPACE is out of AI credit; this
3614
3622
  * does NOT clear by retrying — say so)
3615
3623
  * - "RATE_LIMITED" — 429 (too many turns — retry shortly)
@@ -3691,10 +3699,16 @@ function toAgentError(err) {
3691
3699
  * throwing at render — the widget must render a visible unbound state, never a
3692
3700
  * blank box (CLAUDE.md §8).
3693
3701
  *
3702
+ * sc-16546 — `send(text, { files })` sends Filestore images or PDFs with the
3703
+ * turn (each a file id or a `{ id }` row). Pass `{ files: true }` as the second
3704
+ * argument and the hook asks the server, once and without spending credit,
3705
+ * whether this agent reads files: `acceptsFiles` and `fileLimits` answer it.
3706
+ * Without the option nothing extra is requested and `acceptsFiles` is false.
3707
+ *
3694
3708
  * Routes through the injected `@colixsystems/agents-client` at `ctx.agents`,
3695
3709
  * so the Player and the Expo export resolve against the identical client.
3696
3710
  */
3697
- export function useAgent(agentRef) {
3711
+ export function useAgent(agentRef, options) {
3698
3712
  const ctx = useWidgetContextOrThrow("useAgent");
3699
3713
  const available =
3700
3714
  Boolean(agentRef) &&
@@ -3870,7 +3884,34 @@ export function useAgent(agentRef) {
3870
3884
  };
3871
3885
  }, [available, agentRef]);
3872
3886
 
3873
- const send = useCallback(async (text) => {
3887
+ // sc-16546 — what this agent reads; null until known, or when it reads none.
3888
+ const wantsFiles = Boolean(options && options.files === true);
3889
+ const [fileLimits, setFileLimits] = useState(null);
3890
+ useEffect(() => {
3891
+ const client = clientRef.current;
3892
+ setFileLimits(null);
3893
+ if (!wantsFiles || !client || typeof client.capabilities !== "function") return undefined;
3894
+ let live = true;
3895
+ client.capabilities(agentRef).then(
3896
+ (caps) => {
3897
+ if (!live || !caps || caps.accepts_files !== true) return;
3898
+ setFileLimits({
3899
+ types: Array.isArray(caps.accepted_file_types) ? caps.accepted_file_types : [],
3900
+ maxFiles: caps.max_files,
3901
+ maxPdfs: caps.max_pdfs,
3902
+ maxFileBytes: caps.max_file_bytes,
3903
+ maxTotalBytes: caps.max_total_bytes,
3904
+ });
3905
+ },
3906
+ // No answer is not an offer: keep the attach control hidden.
3907
+ () => {},
3908
+ );
3909
+ return () => {
3910
+ live = false;
3911
+ };
3912
+ }, [available, agentRef, wantsFiles]);
3913
+
3914
+ const send = useCallback(async (text, sendOptions) => {
3874
3915
  const client = clientRef.current;
3875
3916
  const agentId = agentIdRef.current;
3876
3917
  if (!client || !agentId) {
@@ -3880,6 +3921,9 @@ export function useAgent(agentRef) {
3880
3921
  if (!content) {
3881
3922
  throw new AgentError("INVALID_MESSAGE", "A message is required");
3882
3923
  }
3924
+ const fileIds = (sendOptions && Array.isArray(sendOptions.files) ? sendOptions.files : [])
3925
+ .map((file) => (typeof file === "string" ? file : file && file.id))
3926
+ .filter((id) => typeof id === "string" && id.length > 0);
3883
3927
 
3884
3928
  setSending(true);
3885
3929
  setError(null);
@@ -3908,7 +3952,10 @@ export function useAgent(agentRef) {
3908
3952
  abortRef.current = controller;
3909
3953
  const turn = await thread
3910
3954
  .messages(conversationId)
3911
- .send({ content }, controller ? { signal: controller.signal } : undefined);
3955
+ .send(
3956
+ fileIds.length > 0 ? { content, file_ids: fileIds } : { content },
3957
+ controller ? { signal: controller.signal } : undefined,
3958
+ );
3912
3959
  abortRef.current = null;
3913
3960
  // A rebind during the round trip makes this the PREVIOUS agent's reply;
3914
3961
  // writing it now would render it under the new one.
@@ -3968,6 +4015,8 @@ export function useAgent(agentRef) {
3968
4015
  resuming: visibleResuming,
3969
4016
  error: visibleError,
3970
4017
  available,
4018
+ acceptsFiles: available && fileLimits !== null,
4019
+ fileLimits: available ? fileLimits : null,
3971
4020
  };
3972
4021
  }
3973
4022
 
package/dist/index.d.ts CHANGED
@@ -72,7 +72,8 @@ export type WidgetPropertyType =
72
72
  // (ordering operators on a DATE column — `value` is "N days ago"), or the
73
73
  // sc-6282 actor-scoped pair `currentUser` (USER column) / `currentUserGroup`
74
74
  // (USER_GROUP column), which drop `value` and let the SERVER scope the
75
- // condition to the signed-in app-user.
75
+ // condition to the signed-in app-user. The `in` operator ("is any of") takes
76
+ // an array `value` of at most 100 members and no `valueMode`.
76
77
  | "filterList";
77
78
 
78
79
  export interface WidgetPropertyDef {
@@ -909,7 +910,11 @@ export interface WidgetContext<TProps = unknown> {
909
910
  /** Injected @colixsystems/identification-client; backs useIdentification. */
910
911
  identification: IdentificationClient;
911
912
  /** sc-7991 — injected @colixsystems/agents-client backing useAgent(). */
912
- agents?: { conversations(agentId: string): unknown };
913
+ agents?: {
914
+ conversations(agentId: string): unknown;
915
+ /** sc-16546 — what the app may send an agent; optional on older hosts. */
916
+ capabilities?(agentId: string): Promise<unknown>;
917
+ };
913
918
  /** sc-13843 — injected @colixsystems/actions-client backing useAction(). */
914
919
  actions?: {
915
920
  run(actionId: string, input?: Record<string, unknown> | null): Promise<{ ok: boolean; result: unknown }>;
@@ -1125,7 +1130,11 @@ export function hasCornerRadius(
1125
1130
 
1126
1131
  /** A record query the datastore applies on the server; see the README's "Querying records". */
1127
1132
  export interface Query {
1128
- /** `{ column: "op:value" }` (an array of expressions for a range), or `[{ column, operator, value, valueMode }]`. */
1133
+ /**
1134
+ * `{ column: "op:value" }` (an array of expressions for a range), or
1135
+ * `[{ column, operator, value, valueMode }]`. Operator `"in"` takes an array
1136
+ * `value` (at most 100) and keeps rows whose value is any of it.
1137
+ */
1129
1138
  filter?:
1130
1139
  | Record<string, string | string[]>
1131
1140
  | Array<{ column: string; operator?: string; value?: unknown; valueMode?: string }>;
@@ -2064,9 +2073,22 @@ export interface AgentMessage {
2064
2073
  * and if the agent got it wrong the user has no other way to notice.
2065
2074
  */
2066
2075
  activity?: AgentActivity[];
2076
+ /** sc-16546 — the files a user message carried, by reference. Absent when none. */
2077
+ attachments?: Array<{ file_id: string; name: string; mime_type: string; size_bytes: number }>;
2067
2078
  created_at: string;
2068
2079
  }
2069
2080
 
2081
+ /** sc-16546 — what an agent reads, when it reads files at all. */
2082
+ export interface AgentFileLimits {
2083
+ /** MIME types a turn may carry, e.g. "image/png", "application/pdf". */
2084
+ types: string[];
2085
+ maxFiles: number;
2086
+ maxPdfs: number;
2087
+ maxFileBytes: number;
2088
+ /** All of a message's files together. */
2089
+ maxTotalBytes: number;
2090
+ }
2091
+
2070
2092
  /**
2071
2093
  * One tool the agent ran. Names the table it touched and, for a write, the
2072
2094
  * columns it set — never the values, and never a row the permissions refused.
@@ -2091,8 +2113,12 @@ export interface AgentActivityFilter {
2091
2113
  }
2092
2114
 
2093
2115
  export interface AgentApi {
2094
- /** Imperative — call from an event handler. The first send opens the thread. */
2095
- send(text: string): Promise<AgentMessage | null>;
2116
+ /**
2117
+ * Imperative — call from an event handler. The first send opens the thread.
2118
+ * sc-16546 — `files` are Filestore file ids (or `{ id }` rows) of images or
2119
+ * PDFs, read as the signed-in user; send them only when `acceptsFiles`.
2120
+ */
2121
+ send(text: string, options?: { files?: Array<string | { id: string }> }): Promise<AgentMessage | null>;
2096
2122
  /**
2097
2123
  * Stop WAITING for the turn in flight. The abort never reaches the server,
2098
2124
  * which finishes and bills it either way — label the control "stop", not
@@ -2117,6 +2143,13 @@ export interface AgentApi {
2117
2143
  error: AgentError | null;
2118
2144
  /** False when no agent is bound, or the host brokers no agents client. */
2119
2145
  available: boolean;
2146
+ /**
2147
+ * sc-16546 — true once the server says this agent reads files. Asked only
2148
+ * when the hook was called with `{ files: true }`; false otherwise.
2149
+ */
2150
+ acceptsFiles: boolean;
2151
+ /** The types and limits when `acceptsFiles`, else null. */
2152
+ fileLimits: AgentFileLimits | null;
2120
2153
  }
2121
2154
 
2122
2155
  /**
@@ -2129,7 +2162,11 @@ export interface AgentApi {
2129
2162
  * agent (two read-only GETs, no credit spent), so a refresh or a navigation
2130
2163
  * keeps the conversation rather than starting a blank one.
2131
2164
  */
2132
- export function useAgent(agentRef: string | null | undefined): AgentApi;
2165
+ export function useAgent(
2166
+ agentRef: string | null | undefined,
2167
+ /** sc-16546 — `files: true` asks once (no credit spent) whether the agent reads files. */
2168
+ options?: { files?: boolean },
2169
+ ): AgentApi;
2133
2170
 
2134
2171
  export interface ActionApi {
2135
2172
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colixsystems/widget-sdk",
3
- "version": "0.306.0",
3
+ "version": "0.308.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
@@ -1989,7 +1989,9 @@ const HOOKS = [
1989
1989
  "a write; the re-read is the same permission-checked read, and keeps the " +
1990
1990
  "rows on screen with loading false). Use it for lists other people " +
1991
1991
  "change: queues, bookings, chat, dashboards. Never poll with setInterval " +
1992
- "or wire useDatastoreSubscription for that.",
1992
+ "or wire useDatastoreSubscription for that. A `filter` condition " +
1993
+ "`{ column, operator: \"in\", value: [a, b] }` keeps rows whose value " +
1994
+ "is any of the list (a list column: holding any of it), at most 100 values.",
1993
1995
  returnShape: {
1994
1996
  data: "Record[]",
1995
1997
  total: "number | null",
@@ -2195,7 +2197,8 @@ const HOOKS = [
2195
2197
  },
2196
2198
  {
2197
2199
  name: "useAgent",
2198
- signature: "useAgent(agentRef)",
2200
+ signature: "useAgent(agentRef, options)",
2201
+ optionalArgs: ["options"],
2199
2202
  description:
2200
2203
  "sc-7991 — hold a conversation with one of the WORKSPACE's own AI " +
2201
2204
  "agents (an author-written name + system prompt). IMPERATIVE: call " +
@@ -2244,9 +2247,18 @@ const HOOKS = [
2244
2247
  "plain <Text> shows the raw markers to the app user, so a numbered " +
2245
2248
  "how-to arrives as one unreadable line. The USER's own message " +
2246
2249
  "stays <Text>: someone who types *maybe* means asterisks. " +
2250
+ "FILES (sc-16546): call useAgent(agentRef, { files: true }) and the hook " +
2251
+ "asks once, spending no credit, whether this agent reads files; " +
2252
+ "`acceptsFiles` and `fileLimits` ({ types, maxFiles, maxPdfs, maxFileBytes, maxTotalBytes }) " +
2253
+ "answer. Only then offer an attach control, and send with " +
2254
+ "send(text, { files }) where files are Filestore file ids (or { id } rows " +
2255
+ "from useFilestoreUpload) of images or PDFs. Each file is read as the " +
2256
+ "signed-in user, reaches the model on that turn only, and a user message " +
2257
+ "that carried files has `attachments` ({ file_id, name, mime_type, size_bytes }). " +
2258
+ "Without { files: true } `acceptsFiles` stays false and nothing extra is requested. " +
2247
2259
  "Reads ctx.agents.",
2248
2260
  returnShape: {
2249
- send: "(text) => Promise<{ id, role, content, created_at } | null>",
2261
+ send: "(text, { files }?) => Promise<{ id, role, content, created_at } | null>",
2250
2262
  reset: "() => void",
2251
2263
  messages: "Array<{ id, conversation_id, role, content, created_at }>",
2252
2264
  sending: "boolean",
@@ -2254,6 +2266,8 @@ const HOOKS = [
2254
2266
  "boolean // true only while the stored transcript is being reopened on mount; show a loading state, not an empty thread",
2255
2267
  error: "AgentError | null",
2256
2268
  available: "boolean // false when no agent is bound, or the host brokers none",
2269
+ acceptsFiles: "boolean // asked only with { files: true }; false until the server says the agent reads files",
2270
+ fileLimits: "{ types, maxFiles, maxPdfs, maxFileBytes, maxTotalBytes } | null",
2257
2271
  },
2258
2272
  requiredContextSlice: ["agents.conversations"],
2259
2273
  scopes: ["ai.invoke:*"],
@@ -4067,6 +4081,8 @@ const ACTION_SCRIPT_GLOBALS = [
4067
4081
  "input",
4068
4082
  // sc-13843 — hands the app run its one JSON result.
4069
4083
  "respond",
4084
+ // sc-16548 — one turn of a workspace AI agent.
4085
+ "agents",
4070
4086
  ];
4071
4087
  // Mirrors action.service.js SCRIPT_MAX_BYTES.
4072
4088
  const ACTION_SCRIPT_MAX_BYTES = 200 * 1024;
@@ -4410,9 +4426,10 @@ const WIDGET_CONTEXT_SHAPE = {
4410
4426
  description:
4411
4427
  "sc-7991 — injected @colixsystems/agents-client instance. " +
4412
4428
  "{ conversations(agentId) -> { create(), list(query), remove(conversationId), " +
4413
- "messages(conversationId) -> { list(query), send({ content }) } } }. " +
4429
+ "messages(conversationId) -> { list(query), send({ content, file_ids? }) } }, " +
4430
+ "capabilities(agentId) -> Promise<{ accepts_files, accepted_file_types, max_files, max_pdfs, max_file_bytes, max_total_bytes }> }. " +
4414
4431
  "Backs useAgent(). The workspace's agent owns the system prompt and the " +
4415
- "server owns the transcript, so `send` puts ONLY `content` on the wire — " +
4432
+ "server owns the transcript, so `send` puts ONLY `content` and `file_ids` on the wire — " +
4416
4433
  "a prompt, a history or a model id cannot be smuggled through. " +
4417
4434
  "A conversation belongs to the CALLER (the app user, or the studio user " +
4418
4435
  "previewing on the canvas); another user's id is a 404, never a 403. " +
@@ -6916,7 +6933,14 @@ const CONTRACT = deepFreeze({
6916
6933
  // of forcing `alignSelf: "flex-start"`; it still hugs its label.
6917
6934
  // 1.250.0: documentation (sc-16511) — the read hooks' `error` names the
6918
6935
  // `{ code, message, retryable }` it has always carried; Retry only when retryable.
6919
- version: "1.250.0",
6936
+ // 1.251.0: additive (sc-16546) — `useAgent(agentRef, { files: true })`
6937
+ // reports `acceptsFiles` / `fileLimits`, `send(text, { files })` sends
6938
+ // images and PDFs, and the `agents` client gains `capabilities()`.
6939
+ // 1.252.0: additive — the records filter gains `in` ("is any of"). A
6940
+ // `filterList` condition and a query's array-form `filter` take
6941
+ // `{ operator: "in", value: [a, b] }`; on a list column it matches a row
6942
+ // holding any of the values. At most 100; no `valueMode` applies.
6943
+ version: "1.252.0",
6920
6944
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
6921
6945
  hooks: HOOKS,
6922
6946
  primitives: PRIMITIVES,