@colixsystems/widget-sdk 0.306.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 +6 -2
- package/dist/contract.cjs +20 -5
- package/dist/contract.js +20 -5
- package/dist/hooks.js +52 -3
- package/dist/index.d.ts +36 -4
- package/package.json +1 -1
- package/src/contract.js +20 -5
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,11 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
|
|
|
90
90
|
|
|
91
91
|
## Status
|
|
92
92
|
|
|
93
|
-
`v0.
|
|
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)`.
|
|
94
98
|
|
|
95
99
|
### What's new in 0.306.0 (contract 1.250.0)
|
|
96
100
|
|
package/dist/contract.cjs
CHANGED
|
@@ -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. " +
|
|
@@ -6921,7 +6933,10 @@ const CONTRACT = deepFreeze({
|
|
|
6921
6933
|
// of forcing `alignSelf: "flex-start"`; it still hugs its label.
|
|
6922
6934
|
// 1.250.0: documentation (sc-16511) — the read hooks' `error` names the
|
|
6923
6935
|
// `{ code, message, retryable }` it has always carried; Retry only when retryable.
|
|
6924
|
-
|
|
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",
|
|
6925
6940
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
6926
6941
|
hooks: HOOKS,
|
|
6927
6942
|
primitives: PRIMITIVES,
|
package/dist/contract.js
CHANGED
|
@@ -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. " +
|
|
@@ -6916,7 +6928,10 @@ const CONTRACT = deepFreeze({
|
|
|
6916
6928
|
// of forcing `alignSelf: "flex-start"`; it still hugs its label.
|
|
6917
6929
|
// 1.250.0: documentation (sc-16511) — the read hooks' `error` names the
|
|
6918
6930
|
// `{ code, message, retryable }` it has always carried; Retry only when retryable.
|
|
6919
|
-
|
|
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",
|
|
6920
6935
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
6921
6936
|
hooks: HOOKS,
|
|
6922
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
|
-
|
|
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(
|
|
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?: {
|
|
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
|
-
/**
|
|
2095
|
-
|
|
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(
|
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@colixsystems/widget-sdk",
|
|
3
|
-
"version": "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
|
@@ -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. " +
|
|
@@ -6916,7 +6928,10 @@ const CONTRACT = deepFreeze({
|
|
|
6916
6928
|
// of forcing `alignSelf: "flex-start"`; it still hugs its label.
|
|
6917
6929
|
// 1.250.0: documentation (sc-16511) — the read hooks' `error` names the
|
|
6918
6930
|
// `{ code, message, retryable }` it has always carried; Retry only when retryable.
|
|
6919
|
-
|
|
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",
|
|
6920
6935
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
6921
6936
|
hooks: HOOKS,
|
|
6922
6937
|
primitives: PRIMITIVES,
|