@colixsystems/widget-sdk 0.305.0 → 0.307.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.305.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.307.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.307.0 (contract 1.251.0)
96
+
97
+ **`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)`.
98
+
99
+ ### What's new in 0.306.0 (contract 1.250.0)
100
+
101
+ **New linter rule `read-error-not-branched` (severity `warning`).** A read that the viewer may not make never succeeds on a retry. A signed-out visitor reading a table only members may read gets a `DatastoreError` with `code: "NOT_FOUND"`; a signed-in user the table's grants leave out gets `FORBIDDEN` or no rows. Both carry `retryable: false`. A widget that shows "could not be loaded" with a Retry for every read error loops that visitor forever. The read hooks' `error` (`useDatastoreQuery`, `usePagedDatastoreQuery`, `useDatastoreRecord`, `useDatastoreAggregate`, `useDatastoreFigure`) has always carried `{ code, message, retryable }`, and the contract now says so. Offer Retry only when `error.retryable` (a dropped connection, a timeout, a rate limit, a 5xx). Otherwise show a calm signed-out state to a visitor with no `useUser().id` ("Sign in to see the recipes"), and `error.message` to a signed-in user, with no Retry. The rule fires when a read hook's `refetch` or `retry` is bound to an `onPress` in the statement that handles its `error`, and that error's `retryable` and `code ===` are never read and the signed-in user's id is never checked. A bare `useUser()` call does not satisfy it.
94
102
 
95
103
  ### What's new in 0.305.0 (contract 1.249.0)
96
104
 
@@ -3834,7 +3842,7 @@ export default function ContactList({ tableId, pageSize }) {
3834
3842
  <TextInput value={draft} onChangeText={setDraft} placeholder="Search" />
3835
3843
  <Pressable onPress={() => setStatus(status === "Won" ? "" : "Won")}><Text>Won</Text></Pressable>
3836
3844
  {loading ? <Text>Loading…</Text> : data.map((row) => <Text key={row.id}>{row.name}</Text>)}
3837
- {error ? <Button variant="ghost" title="Retry" onPress={retry} /> : null}
3845
+ {error ? (error.retryable ? <Button variant="ghost" title="Retry" onPress={retry} /> : <Text>{error.message}</Text>) : null}
3838
3846
  <Text>{total ?? 0} contacts</Text>
3839
3847
  {hasMore ? <Button variant="ghost" title="Load more" busy={loadingMore} onPress={loadMore} /> : null}
3840
3848
  </View>
package/dist/contract.cjs CHANGED
@@ -1407,7 +1407,7 @@ const HOOKS = [
1407
1407
  data: "Record | null",
1408
1408
  loading: "boolean",
1409
1409
  fetching: "boolean",
1410
- error: "DatastoreError | null",
1410
+ error: "DatastoreError | null // { code, message, retryable } — offer Retry only when retryable; a signed-out viewer of a table only members read gets NOT_FOUND, retryable false",
1411
1411
  refetch: "() => Promise<void>",
1412
1412
  },
1413
1413
  requiredContextSlice: ["datastore.records"],
@@ -2000,7 +2000,7 @@ const HOOKS = [
2000
2000
  total: "number | null",
2001
2001
  loading: "boolean",
2002
2002
  fetching: "boolean",
2003
- error: "DatastoreError | null",
2003
+ error: "DatastoreError | null // { code, message, retryable } — offer Retry only when retryable; a signed-out viewer of a table only members read gets NOT_FOUND, retryable false",
2004
2004
  refetch: "() => Promise<void>",
2005
2005
  },
2006
2006
  requiredContextSlice: ["datastore.records"],
@@ -2034,7 +2034,7 @@ const HOOKS = [
2034
2034
  loading: "boolean",
2035
2035
  fetching: "boolean",
2036
2036
  loadingMore: "boolean",
2037
- error: "DatastoreError | null",
2037
+ error: "DatastoreError | null // { code, message, retryable } — offer Retry only when retryable; a signed-out viewer of a table only members read gets NOT_FOUND, retryable false",
2038
2038
  loadMore: "() => void",
2039
2039
  retry: "() => void",
2040
2040
  refetch: "() => Promise<void>",
@@ -2068,7 +2068,7 @@ const HOOKS = [
2068
2068
  truncated: "boolean",
2069
2069
  loading: "boolean",
2070
2070
  fetching: "boolean",
2071
- error: "DatastoreError | null",
2071
+ error: "DatastoreError | null // { code, message, retryable } — offer Retry only when retryable; a signed-out viewer of a table only members read gets NOT_FOUND, retryable false",
2072
2072
  refetch: "() => Promise<void>",
2073
2073
  },
2074
2074
  requiredContextSlice: ["datastore.records"],
@@ -2108,7 +2108,7 @@ const HOOKS = [
2108
2108
  "Array<{ group, count, sum }> // by a column; a USER column's group is the user id",
2109
2109
  loading: "boolean",
2110
2110
  fetching: "boolean",
2111
- error: "DatastoreError | null",
2111
+ error: "DatastoreError | null // { code, message, retryable } — offer Retry only when retryable; a signed-out viewer of a table only members read gets NOT_FOUND, retryable false",
2112
2112
  refetch: "() => Promise<void>",
2113
2113
  },
2114
2114
  requiredContextSlice: ["datastore.records"],
@@ -2200,7 +2200,7 @@ const HOOKS = [
2200
2200
  },
2201
2201
  {
2202
2202
  name: "useAgent",
2203
- signature: "useAgent(agentRef)",
2203
+ signature: "useAgent(agentRef, options?)",
2204
2204
  description:
2205
2205
  "sc-7991 — hold a conversation with one of the WORKSPACE's own AI " +
2206
2206
  "agents (an author-written name + system prompt). IMPERATIVE: call " +
@@ -2249,9 +2249,18 @@ const HOOKS = [
2249
2249
  "plain <Text> shows the raw markers to the app user, so a numbered " +
2250
2250
  "how-to arrives as one unreadable line. The USER's own message " +
2251
2251
  "stays <Text>: someone who types *maybe* means asterisks. " +
2252
+ "FILES (sc-16546): call useAgent(agentRef, { files: true }) and the hook " +
2253
+ "asks once, spending no credit, whether this agent reads files; " +
2254
+ "`acceptsFiles` and `fileLimits` ({ types, maxFiles, maxPdfs, maxFileBytes, maxTotalBytes }) " +
2255
+ "answer. Only then offer an attach control, and send with " +
2256
+ "send(text, { files }) where files are Filestore file ids (or { id } rows " +
2257
+ "from useFilestoreUpload) of images or PDFs. Each file is read as the " +
2258
+ "signed-in user, reaches the model on that turn only, and a user message " +
2259
+ "that carried files has `attachments` ({ file_id, name, mime_type, size_bytes }). " +
2260
+ "Without { files: true } `acceptsFiles` stays false and nothing extra is requested. " +
2252
2261
  "Reads ctx.agents.",
2253
2262
  returnShape: {
2254
- send: "(text) => Promise<{ id, role, content, created_at } | null>",
2263
+ send: "(text, { files }?) => Promise<{ id, role, content, created_at } | null>",
2255
2264
  reset: "() => void",
2256
2265
  messages: "Array<{ id, conversation_id, role, content, created_at }>",
2257
2266
  sending: "boolean",
@@ -2259,6 +2268,8 @@ const HOOKS = [
2259
2268
  "boolean // true only while the stored transcript is being reopened on mount; show a loading state, not an empty thread",
2260
2269
  error: "AgentError | null",
2261
2270
  available: "boolean // false when no agent is bound, or the host brokers none",
2271
+ acceptsFiles: "boolean // asked only with { files: true }; false until the server says the agent reads files",
2272
+ fileLimits: "{ types, maxFiles, maxPdfs, maxFileBytes, maxTotalBytes } | null",
2262
2273
  },
2263
2274
  requiredContextSlice: ["agents.conversations"],
2264
2275
  scopes: ["ai.invoke:*"],
@@ -4415,9 +4426,10 @@ const WIDGET_CONTEXT_SHAPE = {
4415
4426
  description:
4416
4427
  "sc-7991 — injected @colixsystems/agents-client instance. " +
4417
4428
  "{ conversations(agentId) -> { create(), list(query), remove(conversationId), " +
4418
- "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 }> }. " +
4419
4431
  "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 — " +
4432
+ "server owns the transcript, so `send` puts ONLY `content` and `file_ids` on the wire — " +
4421
4433
  "a prompt, a history or a model id cannot be smuggled through. " +
4422
4434
  "A conversation belongs to the CALLER (the app user, or the studio user " +
4423
4435
  "previewing on the canvas); another user's id is a 404, never a 403. " +
@@ -6919,7 +6931,12 @@ const CONTRACT = deepFreeze({
6919
6931
  // the web for pointer devices when it overflows; `showsScrollAffordance` turns it off.
6920
6932
  // 1.249.0: a `<Button>` follows its parent's cross-axis alignment instead
6921
6933
  // of forcing `alignSelf: "flex-start"`; it still hugs its label.
6922
- version: "1.249.0",
6934
+ // 1.250.0: documentation (sc-16511) — the read hooks' `error` names the
6935
+ // `{ code, message, retryable }` it has always carried; Retry only when retryable.
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
+ version: "1.251.0",
6923
6940
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
6924
6941
  hooks: HOOKS,
6925
6942
  primitives: PRIMITIVES,
package/dist/contract.js CHANGED
@@ -1402,7 +1402,7 @@ const HOOKS = [
1402
1402
  data: "Record | null",
1403
1403
  loading: "boolean",
1404
1404
  fetching: "boolean",
1405
- error: "DatastoreError | null",
1405
+ error: "DatastoreError | null // { code, message, retryable } — offer Retry only when retryable; a signed-out viewer of a table only members read gets NOT_FOUND, retryable false",
1406
1406
  refetch: "() => Promise<void>",
1407
1407
  },
1408
1408
  requiredContextSlice: ["datastore.records"],
@@ -1995,7 +1995,7 @@ const HOOKS = [
1995
1995
  total: "number | null",
1996
1996
  loading: "boolean",
1997
1997
  fetching: "boolean",
1998
- error: "DatastoreError | null",
1998
+ error: "DatastoreError | null // { code, message, retryable } — offer Retry only when retryable; a signed-out viewer of a table only members read gets NOT_FOUND, retryable false",
1999
1999
  refetch: "() => Promise<void>",
2000
2000
  },
2001
2001
  requiredContextSlice: ["datastore.records"],
@@ -2029,7 +2029,7 @@ const HOOKS = [
2029
2029
  loading: "boolean",
2030
2030
  fetching: "boolean",
2031
2031
  loadingMore: "boolean",
2032
- error: "DatastoreError | null",
2032
+ error: "DatastoreError | null // { code, message, retryable } — offer Retry only when retryable; a signed-out viewer of a table only members read gets NOT_FOUND, retryable false",
2033
2033
  loadMore: "() => void",
2034
2034
  retry: "() => void",
2035
2035
  refetch: "() => Promise<void>",
@@ -2063,7 +2063,7 @@ const HOOKS = [
2063
2063
  truncated: "boolean",
2064
2064
  loading: "boolean",
2065
2065
  fetching: "boolean",
2066
- error: "DatastoreError | null",
2066
+ error: "DatastoreError | null // { code, message, retryable } — offer Retry only when retryable; a signed-out viewer of a table only members read gets NOT_FOUND, retryable false",
2067
2067
  refetch: "() => Promise<void>",
2068
2068
  },
2069
2069
  requiredContextSlice: ["datastore.records"],
@@ -2103,7 +2103,7 @@ const HOOKS = [
2103
2103
  "Array<{ group, count, sum }> // by a column; a USER column's group is the user id",
2104
2104
  loading: "boolean",
2105
2105
  fetching: "boolean",
2106
- error: "DatastoreError | null",
2106
+ error: "DatastoreError | null // { code, message, retryable } — offer Retry only when retryable; a signed-out viewer of a table only members read gets NOT_FOUND, retryable false",
2107
2107
  refetch: "() => Promise<void>",
2108
2108
  },
2109
2109
  requiredContextSlice: ["datastore.records"],
@@ -2195,7 +2195,7 @@ const HOOKS = [
2195
2195
  },
2196
2196
  {
2197
2197
  name: "useAgent",
2198
- signature: "useAgent(agentRef)",
2198
+ signature: "useAgent(agentRef, options?)",
2199
2199
  description:
2200
2200
  "sc-7991 — hold a conversation with one of the WORKSPACE's own AI " +
2201
2201
  "agents (an author-written name + system prompt). IMPERATIVE: call " +
@@ -2244,9 +2244,18 @@ const HOOKS = [
2244
2244
  "plain <Text> shows the raw markers to the app user, so a numbered " +
2245
2245
  "how-to arrives as one unreadable line. The USER's own message " +
2246
2246
  "stays <Text>: someone who types *maybe* means asterisks. " +
2247
+ "FILES (sc-16546): call useAgent(agentRef, { files: true }) and the hook " +
2248
+ "asks once, spending no credit, whether this agent reads files; " +
2249
+ "`acceptsFiles` and `fileLimits` ({ types, maxFiles, maxPdfs, maxFileBytes, maxTotalBytes }) " +
2250
+ "answer. Only then offer an attach control, and send with " +
2251
+ "send(text, { files }) where files are Filestore file ids (or { id } rows " +
2252
+ "from useFilestoreUpload) of images or PDFs. Each file is read as the " +
2253
+ "signed-in user, reaches the model on that turn only, and a user message " +
2254
+ "that carried files has `attachments` ({ file_id, name, mime_type, size_bytes }). " +
2255
+ "Without { files: true } `acceptsFiles` stays false and nothing extra is requested. " +
2247
2256
  "Reads ctx.agents.",
2248
2257
  returnShape: {
2249
- send: "(text) => Promise<{ id, role, content, created_at } | null>",
2258
+ send: "(text, { files }?) => Promise<{ id, role, content, created_at } | null>",
2250
2259
  reset: "() => void",
2251
2260
  messages: "Array<{ id, conversation_id, role, content, created_at }>",
2252
2261
  sending: "boolean",
@@ -2254,6 +2263,8 @@ const HOOKS = [
2254
2263
  "boolean // true only while the stored transcript is being reopened on mount; show a loading state, not an empty thread",
2255
2264
  error: "AgentError | null",
2256
2265
  available: "boolean // false when no agent is bound, or the host brokers none",
2266
+ acceptsFiles: "boolean // asked only with { files: true }; false until the server says the agent reads files",
2267
+ fileLimits: "{ types, maxFiles, maxPdfs, maxFileBytes, maxTotalBytes } | null",
2257
2268
  },
2258
2269
  requiredContextSlice: ["agents.conversations"],
2259
2270
  scopes: ["ai.invoke:*"],
@@ -4410,9 +4421,10 @@ const WIDGET_CONTEXT_SHAPE = {
4410
4421
  description:
4411
4422
  "sc-7991 — injected @colixsystems/agents-client instance. " +
4412
4423
  "{ conversations(agentId) -> { create(), list(query), remove(conversationId), " +
4413
- "messages(conversationId) -> { list(query), send({ content }) } } }. " +
4424
+ "messages(conversationId) -> { list(query), send({ content, file_ids? }) } }, " +
4425
+ "capabilities(agentId) -> Promise<{ accepts_files, accepted_file_types, max_files, max_pdfs, max_file_bytes, max_total_bytes }> }. " +
4414
4426
  "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 — " +
4427
+ "server owns the transcript, so `send` puts ONLY `content` and `file_ids` on the wire — " +
4416
4428
  "a prompt, a history or a model id cannot be smuggled through. " +
4417
4429
  "A conversation belongs to the CALLER (the app user, or the studio user " +
4418
4430
  "previewing on the canvas); another user's id is a 404, never a 403. " +
@@ -6914,7 +6926,12 @@ const CONTRACT = deepFreeze({
6914
6926
  // the web for pointer devices when it overflows; `showsScrollAffordance` turns it off.
6915
6927
  // 1.249.0: a `<Button>` follows its parent's cross-axis alignment instead
6916
6928
  // of forcing `alignSelf: "flex-start"`; it still hugs its label.
6917
- version: "1.249.0",
6929
+ // 1.250.0: documentation (sc-16511) — the read hooks' `error` names the
6930
+ // `{ code, message, retryable }` it has always carried; Retry only when retryable.
6931
+ // 1.251.0: additive (sc-16546) — `useAgent(agentRef, { files: true })`
6932
+ // reports `acceptsFiles` / `fileLimits`, `send(text, { files })` sends
6933
+ // images and PDFs, and the `agents` client gains `capabilities()`.
6934
+ version: "1.251.0",
6918
6935
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
6919
6936
  hooks: HOOKS,
6920
6937
  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
@@ -909,7 +909,11 @@ export interface WidgetContext<TProps = unknown> {
909
909
  /** Injected @colixsystems/identification-client; backs useIdentification. */
910
910
  identification: IdentificationClient;
911
911
  /** sc-7991 — injected @colixsystems/agents-client backing useAgent(). */
912
- agents?: { conversations(agentId: string): unknown };
912
+ agents?: {
913
+ conversations(agentId: string): unknown;
914
+ /** sc-16546 — what the app may send an agent; optional on older hosts. */
915
+ capabilities?(agentId: string): Promise<unknown>;
916
+ };
913
917
  /** sc-13843 — injected @colixsystems/actions-client backing useAction(). */
914
918
  actions?: {
915
919
  run(actionId: string, input?: Record<string, unknown> | null): Promise<{ ok: boolean; result: unknown }>;
@@ -2064,9 +2068,22 @@ export interface AgentMessage {
2064
2068
  * and if the agent got it wrong the user has no other way to notice.
2065
2069
  */
2066
2070
  activity?: AgentActivity[];
2071
+ /** sc-16546 — the files a user message carried, by reference. Absent when none. */
2072
+ attachments?: Array<{ file_id: string; name: string; mime_type: string; size_bytes: number }>;
2067
2073
  created_at: string;
2068
2074
  }
2069
2075
 
2076
+ /** sc-16546 — what an agent reads, when it reads files at all. */
2077
+ export interface AgentFileLimits {
2078
+ /** MIME types a turn may carry, e.g. "image/png", "application/pdf". */
2079
+ types: string[];
2080
+ maxFiles: number;
2081
+ maxPdfs: number;
2082
+ maxFileBytes: number;
2083
+ /** All of a message's files together. */
2084
+ maxTotalBytes: number;
2085
+ }
2086
+
2070
2087
  /**
2071
2088
  * One tool the agent ran. Names the table it touched and, for a write, the
2072
2089
  * columns it set — never the values, and never a row the permissions refused.
@@ -2091,8 +2108,12 @@ export interface AgentActivityFilter {
2091
2108
  }
2092
2109
 
2093
2110
  export interface AgentApi {
2094
- /** Imperative — call from an event handler. The first send opens the thread. */
2095
- send(text: string): Promise<AgentMessage | null>;
2111
+ /**
2112
+ * Imperative — call from an event handler. The first send opens the thread.
2113
+ * sc-16546 — `files` are Filestore file ids (or `{ id }` rows) of images or
2114
+ * PDFs, read as the signed-in user; send them only when `acceptsFiles`.
2115
+ */
2116
+ send(text: string, options?: { files?: Array<string | { id: string }> }): Promise<AgentMessage | null>;
2096
2117
  /**
2097
2118
  * Stop WAITING for the turn in flight. The abort never reaches the server,
2098
2119
  * which finishes and bills it either way — label the control "stop", not
@@ -2117,6 +2138,13 @@ export interface AgentApi {
2117
2138
  error: AgentError | null;
2118
2139
  /** False when no agent is bound, or the host brokers no agents client. */
2119
2140
  available: boolean;
2141
+ /**
2142
+ * sc-16546 — true once the server says this agent reads files. Asked only
2143
+ * when the hook was called with `{ files: true }`; false otherwise.
2144
+ */
2145
+ acceptsFiles: boolean;
2146
+ /** The types and limits when `acceptsFiles`, else null. */
2147
+ fileLimits: AgentFileLimits | null;
2120
2148
  }
2121
2149
 
2122
2150
  /**
@@ -2129,7 +2157,11 @@ export interface AgentApi {
2129
2157
  * agent (two read-only GETs, no credit spent), so a refresh or a navigation
2130
2158
  * keeps the conversation rather than starting a blank one.
2131
2159
  */
2132
- export function useAgent(agentRef: string | null | undefined): AgentApi;
2160
+ export function useAgent(
2161
+ agentRef: string | null | undefined,
2162
+ /** sc-16546 — `files: true` asks once (no credit spent) whether the agent reads files. */
2163
+ options?: { files?: boolean },
2164
+ ): AgentApi;
2133
2165
 
2134
2166
  export interface ActionApi {
2135
2167
  /**
package/dist/linter.cjs CHANGED
@@ -1668,6 +1668,74 @@ function _datastoreErrorHandlingRules(source) {
1668
1668
  ];
1669
1669
  }
1670
1670
 
1671
+ // sc-16511 — soft warning, the read twin of `datastore-error-not-branched`.
1672
+ // A read refused because the viewer may not see the table (a signed-out
1673
+ // visitor gets NOT_FOUND, a signed-in one FORBIDDEN) never clears on a retry,
1674
+ // so a Retry bound to every read error loops the visitor forever. Reading the
1675
+ // read error's `retryable`, branching on its `code ===`, or guarding on the
1676
+ // signed-in user's id satisfies it. A bare `useUser()` call does not: widgets
1677
+ // call it for a greeting, and that is exactly the widget this rule exists for.
1678
+ const READ_HOOK = String.raw`use(?:PagedDatastoreQuery|Datastore(?:Query|Record|Aggregate|Figure)\w*)`;
1679
+ const READ_HOOK_CALL_RE = new RegExp(String.raw`\b${READ_HOOK}\s*\(`);
1680
+ const READ_HOOK_DESTRUCTURE_RE = new RegExp(String.raw`\{([^{}]*)\}\s*=\s*${READ_HOOK}\s*\(`, "g");
1681
+ const RETRY_CONTROL_RE = /\bonPress\s*(?:=\s*\{|:)\s*(?:\(\s*\)\s*=>\s*\{?\s*)?(?:refetch|retry)\b/g;
1682
+ // How far before a retry control, within one statement, its error check may sit.
1683
+ const RETRY_ERROR_WINDOW = 400;
1684
+
1685
+ function _statementBefore(code, index) {
1686
+ const window = code.slice(Math.max(0, index - RETRY_ERROR_WINDOW), index);
1687
+ return window.slice(window.lastIndexOf(";") + 1);
1688
+ }
1689
+
1690
+ /** The names the read hooks' `error` is bound to; `error` when none is destructured. */
1691
+ function _readErrorNames(code) {
1692
+ const names = new Set();
1693
+ for (const m of code.matchAll(READ_HOOK_DESTRUCTURE_RE)) {
1694
+ const bound = /(?:^|,)\s*error\s*(?::\s*([A-Za-z_$][\w$]*))?\s*(?:=[^,]*)?(?:,|$)/.exec(m[1]);
1695
+ if (bound) names.add(bound[1] || "error");
1696
+ }
1697
+ return names.size > 0 ? [...names] : ["error"];
1698
+ }
1699
+
1700
+ function _signedInGuardRes(code) {
1701
+ const res = [/\buseUser\s*\(\s*\)\s*\??\.id\b/];
1702
+ const guardOn = (name) => {
1703
+ const n = name.replace(/\$/g, "\\$");
1704
+ return [new RegExp(`!\\s*${n}\\b(?!\\s*\\.)`), new RegExp(`(?<![\\w$.])${n}\\s*(?:\\?[^.?]|&&|\\|\\|)`)];
1705
+ };
1706
+ const named = /\b(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*useUser\s*\(\s*\)/.exec(code);
1707
+ if (named) res.push(...guardOn(`${named[1]}\\??\\.id`));
1708
+ const destructured = /\b(?:const|let|var)\s*\{([^}]*)\}\s*=\s*useUser\s*\(\s*\)/.exec(code);
1709
+ const idName = destructured && /(?:^|,)\s*id\s*(?::\s*([A-Za-z_$][\w$]*))?\s*(?:,|$)/.exec(destructured[1]);
1710
+ if (idName) res.push(...guardOn(idName[1] || "id"));
1711
+ return res;
1712
+ }
1713
+
1714
+ function _readErrorHandlingRules(source) {
1715
+ const code = _stripNonCode(source);
1716
+ if (!READ_HOOK_CALL_RE.test(code)) return [];
1717
+ const errorNames = _readErrorNames(code).map((n) => n.replace(/\$/g, "\\$"));
1718
+ const nearError = new RegExp(String.raw`(?<![\w$.])(?:${errorNames.join("|")})(?![\w$])`);
1719
+ const retry = [...code.matchAll(RETRY_CONTROL_RE)].find((m) => nearError.test(_statementBefore(code, m.index)));
1720
+ if (!retry) return [];
1721
+ const branched = new RegExp(String.raw`(?<![\w$.])(?:${errorNames.join("|")})\??\.(?:retryable\b|code\s*===)`);
1722
+ if (branched.test(code)) return [];
1723
+ if (_signedInGuardRes(code).some((re) => re.test(code))) return [];
1724
+ const line = code.slice(0, retry.index).split(/\r?\n/).length;
1725
+ return [
1726
+ {
1727
+ rule: "read-error-not-branched",
1728
+ severity: "warning",
1729
+ label:
1730
+ `offers Retry on every read error - a viewer who may not read the ` +
1731
+ `table (signed out: NOT_FOUND) can never succeed. Show Retry only when ` +
1732
+ `error.retryable; otherwise a signed-out state or error.message.`,
1733
+ line,
1734
+ snippet: (source.split(/\r?\n/)[line - 1] || "").trim().slice(0, 200),
1735
+ },
1736
+ ];
1737
+ }
1738
+
1671
1739
  // sc-5206 — soft warning: a `useDatastoreQuery` argument built from a raw
1672
1740
  // `const q = useMemo(() => ({...}), [...])` re-fetches in a loop the moment
1673
1741
  // the deps array is wrong (sc-1579's volatile-query gate exists because of
@@ -3208,6 +3276,7 @@ function lintSource(source, options) {
3208
3276
  findings.push(..._hardcodedCurrencyLabelRules(source));
3209
3277
  findings.push(..._paymentErrorHandlingRules(source));
3210
3278
  findings.push(..._datastoreErrorHandlingRules(source));
3279
+ findings.push(..._readErrorHandlingRules(source));
3211
3280
  // sc-5206 — soft warnings steering a widget toward the two new hooks.
3212
3281
  findings.push(..._rawUseMemoIntoDatastoreQueryRules(source));
3213
3282
  findings.push(..._handRolledWriteGateRules(source));
package/dist/linter.js CHANGED
@@ -1663,6 +1663,74 @@ function _datastoreErrorHandlingRules(source) {
1663
1663
  ];
1664
1664
  }
1665
1665
 
1666
+ // sc-16511 — soft warning, the read twin of `datastore-error-not-branched`.
1667
+ // A read refused because the viewer may not see the table (a signed-out
1668
+ // visitor gets NOT_FOUND, a signed-in one FORBIDDEN) never clears on a retry,
1669
+ // so a Retry bound to every read error loops the visitor forever. Reading the
1670
+ // read error's `retryable`, branching on its `code ===`, or guarding on the
1671
+ // signed-in user's id satisfies it. A bare `useUser()` call does not: widgets
1672
+ // call it for a greeting, and that is exactly the widget this rule exists for.
1673
+ const READ_HOOK = String.raw`use(?:PagedDatastoreQuery|Datastore(?:Query|Record|Aggregate|Figure)\w*)`;
1674
+ const READ_HOOK_CALL_RE = new RegExp(String.raw`\b${READ_HOOK}\s*\(`);
1675
+ const READ_HOOK_DESTRUCTURE_RE = new RegExp(String.raw`\{([^{}]*)\}\s*=\s*${READ_HOOK}\s*\(`, "g");
1676
+ const RETRY_CONTROL_RE = /\bonPress\s*(?:=\s*\{|:)\s*(?:\(\s*\)\s*=>\s*\{?\s*)?(?:refetch|retry)\b/g;
1677
+ // How far before a retry control, within one statement, its error check may sit.
1678
+ const RETRY_ERROR_WINDOW = 400;
1679
+
1680
+ function _statementBefore(code, index) {
1681
+ const window = code.slice(Math.max(0, index - RETRY_ERROR_WINDOW), index);
1682
+ return window.slice(window.lastIndexOf(";") + 1);
1683
+ }
1684
+
1685
+ /** The names the read hooks' `error` is bound to; `error` when none is destructured. */
1686
+ function _readErrorNames(code) {
1687
+ const names = new Set();
1688
+ for (const m of code.matchAll(READ_HOOK_DESTRUCTURE_RE)) {
1689
+ const bound = /(?:^|,)\s*error\s*(?::\s*([A-Za-z_$][\w$]*))?\s*(?:=[^,]*)?(?:,|$)/.exec(m[1]);
1690
+ if (bound) names.add(bound[1] || "error");
1691
+ }
1692
+ return names.size > 0 ? [...names] : ["error"];
1693
+ }
1694
+
1695
+ function _signedInGuardRes(code) {
1696
+ const res = [/\buseUser\s*\(\s*\)\s*\??\.id\b/];
1697
+ const guardOn = (name) => {
1698
+ const n = name.replace(/\$/g, "\\$");
1699
+ return [new RegExp(`!\\s*${n}\\b(?!\\s*\\.)`), new RegExp(`(?<![\\w$.])${n}\\s*(?:\\?[^.?]|&&|\\|\\|)`)];
1700
+ };
1701
+ const named = /\b(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*useUser\s*\(\s*\)/.exec(code);
1702
+ if (named) res.push(...guardOn(`${named[1]}\\??\\.id`));
1703
+ const destructured = /\b(?:const|let|var)\s*\{([^}]*)\}\s*=\s*useUser\s*\(\s*\)/.exec(code);
1704
+ const idName = destructured && /(?:^|,)\s*id\s*(?::\s*([A-Za-z_$][\w$]*))?\s*(?:,|$)/.exec(destructured[1]);
1705
+ if (idName) res.push(...guardOn(idName[1] || "id"));
1706
+ return res;
1707
+ }
1708
+
1709
+ function _readErrorHandlingRules(source) {
1710
+ const code = _stripNonCode(source);
1711
+ if (!READ_HOOK_CALL_RE.test(code)) return [];
1712
+ const errorNames = _readErrorNames(code).map((n) => n.replace(/\$/g, "\\$"));
1713
+ const nearError = new RegExp(String.raw`(?<![\w$.])(?:${errorNames.join("|")})(?![\w$])`);
1714
+ const retry = [...code.matchAll(RETRY_CONTROL_RE)].find((m) => nearError.test(_statementBefore(code, m.index)));
1715
+ if (!retry) return [];
1716
+ const branched = new RegExp(String.raw`(?<![\w$.])(?:${errorNames.join("|")})\??\.(?:retryable\b|code\s*===)`);
1717
+ if (branched.test(code)) return [];
1718
+ if (_signedInGuardRes(code).some((re) => re.test(code))) return [];
1719
+ const line = code.slice(0, retry.index).split(/\r?\n/).length;
1720
+ return [
1721
+ {
1722
+ rule: "read-error-not-branched",
1723
+ severity: "warning",
1724
+ label:
1725
+ `offers Retry on every read error - a viewer who may not read the ` +
1726
+ `table (signed out: NOT_FOUND) can never succeed. Show Retry only when ` +
1727
+ `error.retryable; otherwise a signed-out state or error.message.`,
1728
+ line,
1729
+ snippet: (source.split(/\r?\n/)[line - 1] || "").trim().slice(0, 200),
1730
+ },
1731
+ ];
1732
+ }
1733
+
1666
1734
  // sc-5206 — soft warning: a `useDatastoreQuery` argument built from a raw
1667
1735
  // `const q = useMemo(() => ({...}), [...])` re-fetches in a loop the moment
1668
1736
  // the deps array is wrong (sc-1579's volatile-query gate exists because of
@@ -3203,6 +3271,7 @@ export function lintSource(source, options) {
3203
3271
  findings.push(..._hardcodedCurrencyLabelRules(source));
3204
3272
  findings.push(..._paymentErrorHandlingRules(source));
3205
3273
  findings.push(..._datastoreErrorHandlingRules(source));
3274
+ findings.push(..._readErrorHandlingRules(source));
3206
3275
  // sc-5206 — soft warnings steering a widget toward the two new hooks.
3207
3276
  findings.push(..._rawUseMemoIntoDatastoreQueryRules(source));
3208
3277
  findings.push(..._handRolledWriteGateRules(source));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colixsystems/widget-sdk",
3
- "version": "0.305.0",
3
+ "version": "0.307.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
@@ -1402,7 +1402,7 @@ const HOOKS = [
1402
1402
  data: "Record | null",
1403
1403
  loading: "boolean",
1404
1404
  fetching: "boolean",
1405
- error: "DatastoreError | null",
1405
+ error: "DatastoreError | null // { code, message, retryable } — offer Retry only when retryable; a signed-out viewer of a table only members read gets NOT_FOUND, retryable false",
1406
1406
  refetch: "() => Promise<void>",
1407
1407
  },
1408
1408
  requiredContextSlice: ["datastore.records"],
@@ -1995,7 +1995,7 @@ const HOOKS = [
1995
1995
  total: "number | null",
1996
1996
  loading: "boolean",
1997
1997
  fetching: "boolean",
1998
- error: "DatastoreError | null",
1998
+ error: "DatastoreError | null // { code, message, retryable } — offer Retry only when retryable; a signed-out viewer of a table only members read gets NOT_FOUND, retryable false",
1999
1999
  refetch: "() => Promise<void>",
2000
2000
  },
2001
2001
  requiredContextSlice: ["datastore.records"],
@@ -2029,7 +2029,7 @@ const HOOKS = [
2029
2029
  loading: "boolean",
2030
2030
  fetching: "boolean",
2031
2031
  loadingMore: "boolean",
2032
- error: "DatastoreError | null",
2032
+ error: "DatastoreError | null // { code, message, retryable } — offer Retry only when retryable; a signed-out viewer of a table only members read gets NOT_FOUND, retryable false",
2033
2033
  loadMore: "() => void",
2034
2034
  retry: "() => void",
2035
2035
  refetch: "() => Promise<void>",
@@ -2063,7 +2063,7 @@ const HOOKS = [
2063
2063
  truncated: "boolean",
2064
2064
  loading: "boolean",
2065
2065
  fetching: "boolean",
2066
- error: "DatastoreError | null",
2066
+ error: "DatastoreError | null // { code, message, retryable } — offer Retry only when retryable; a signed-out viewer of a table only members read gets NOT_FOUND, retryable false",
2067
2067
  refetch: "() => Promise<void>",
2068
2068
  },
2069
2069
  requiredContextSlice: ["datastore.records"],
@@ -2103,7 +2103,7 @@ const HOOKS = [
2103
2103
  "Array<{ group, count, sum }> // by a column; a USER column's group is the user id",
2104
2104
  loading: "boolean",
2105
2105
  fetching: "boolean",
2106
- error: "DatastoreError | null",
2106
+ error: "DatastoreError | null // { code, message, retryable } — offer Retry only when retryable; a signed-out viewer of a table only members read gets NOT_FOUND, retryable false",
2107
2107
  refetch: "() => Promise<void>",
2108
2108
  },
2109
2109
  requiredContextSlice: ["datastore.records"],
@@ -2195,7 +2195,7 @@ const HOOKS = [
2195
2195
  },
2196
2196
  {
2197
2197
  name: "useAgent",
2198
- signature: "useAgent(agentRef)",
2198
+ signature: "useAgent(agentRef, options?)",
2199
2199
  description:
2200
2200
  "sc-7991 — hold a conversation with one of the WORKSPACE's own AI " +
2201
2201
  "agents (an author-written name + system prompt). IMPERATIVE: call " +
@@ -2244,9 +2244,18 @@ const HOOKS = [
2244
2244
  "plain <Text> shows the raw markers to the app user, so a numbered " +
2245
2245
  "how-to arrives as one unreadable line. The USER's own message " +
2246
2246
  "stays <Text>: someone who types *maybe* means asterisks. " +
2247
+ "FILES (sc-16546): call useAgent(agentRef, { files: true }) and the hook " +
2248
+ "asks once, spending no credit, whether this agent reads files; " +
2249
+ "`acceptsFiles` and `fileLimits` ({ types, maxFiles, maxPdfs, maxFileBytes, maxTotalBytes }) " +
2250
+ "answer. Only then offer an attach control, and send with " +
2251
+ "send(text, { files }) where files are Filestore file ids (or { id } rows " +
2252
+ "from useFilestoreUpload) of images or PDFs. Each file is read as the " +
2253
+ "signed-in user, reaches the model on that turn only, and a user message " +
2254
+ "that carried files has `attachments` ({ file_id, name, mime_type, size_bytes }). " +
2255
+ "Without { files: true } `acceptsFiles` stays false and nothing extra is requested. " +
2247
2256
  "Reads ctx.agents.",
2248
2257
  returnShape: {
2249
- send: "(text) => Promise<{ id, role, content, created_at } | null>",
2258
+ send: "(text, { files }?) => Promise<{ id, role, content, created_at } | null>",
2250
2259
  reset: "() => void",
2251
2260
  messages: "Array<{ id, conversation_id, role, content, created_at }>",
2252
2261
  sending: "boolean",
@@ -2254,6 +2263,8 @@ const HOOKS = [
2254
2263
  "boolean // true only while the stored transcript is being reopened on mount; show a loading state, not an empty thread",
2255
2264
  error: "AgentError | null",
2256
2265
  available: "boolean // false when no agent is bound, or the host brokers none",
2266
+ acceptsFiles: "boolean // asked only with { files: true }; false until the server says the agent reads files",
2267
+ fileLimits: "{ types, maxFiles, maxPdfs, maxFileBytes, maxTotalBytes } | null",
2257
2268
  },
2258
2269
  requiredContextSlice: ["agents.conversations"],
2259
2270
  scopes: ["ai.invoke:*"],
@@ -4410,9 +4421,10 @@ const WIDGET_CONTEXT_SHAPE = {
4410
4421
  description:
4411
4422
  "sc-7991 — injected @colixsystems/agents-client instance. " +
4412
4423
  "{ conversations(agentId) -> { create(), list(query), remove(conversationId), " +
4413
- "messages(conversationId) -> { list(query), send({ content }) } } }. " +
4424
+ "messages(conversationId) -> { list(query), send({ content, file_ids? }) } }, " +
4425
+ "capabilities(agentId) -> Promise<{ accepts_files, accepted_file_types, max_files, max_pdfs, max_file_bytes, max_total_bytes }> }. " +
4414
4426
  "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 — " +
4427
+ "server owns the transcript, so `send` puts ONLY `content` and `file_ids` on the wire — " +
4416
4428
  "a prompt, a history or a model id cannot be smuggled through. " +
4417
4429
  "A conversation belongs to the CALLER (the app user, or the studio user " +
4418
4430
  "previewing on the canvas); another user's id is a 404, never a 403. " +
@@ -6914,7 +6926,12 @@ const CONTRACT = deepFreeze({
6914
6926
  // the web for pointer devices when it overflows; `showsScrollAffordance` turns it off.
6915
6927
  // 1.249.0: a `<Button>` follows its parent's cross-axis alignment instead
6916
6928
  // of forcing `alignSelf: "flex-start"`; it still hugs its label.
6917
- version: "1.249.0",
6929
+ // 1.250.0: documentation (sc-16511) — the read hooks' `error` names the
6930
+ // `{ code, message, retryable }` it has always carried; Retry only when retryable.
6931
+ // 1.251.0: additive (sc-16546) — `useAgent(agentRef, { files: true })`
6932
+ // reports `acceptsFiles` / `fileLimits`, `send(text, { files })` sends
6933
+ // images and PDFs, and the `agents` client gains `capabilities()`.
6934
+ version: "1.251.0",
6918
6935
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
6919
6936
  hooks: HOOKS,
6920
6937
  primitives: PRIMITIVES,