@simpleplatform/sdk 2.4.2 → 3.0.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
@@ -10,6 +10,49 @@ Install the SDK using [pnpm](https://pnpm.io):
10
10
  pnpm add @simpleplatform/sdk
11
11
  ```
12
12
 
13
+ ## Upgrading from 2.x to 3
14
+
15
+ Version 3 is the first release that carries the Space calls added after 2.5.0.
16
+ One of those changes renamed how a Space connects, which is why this is a major.
17
+
18
+ **A Space changes these names:**
19
+
20
+ | 2.x | 3 |
21
+ | ---------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
22
+ | `import { connectSpace } from '@simpleplatform/sdk/space'` | `import { connect } from '@simpleplatform/sdk/space'` |
23
+ | `await connectSpace({ targetOrigin })` | `await connect({ targetOrigin })` |
24
+ | `connectSpace({ targetOrigin, window: fake })` in a test | `connect({ targetOrigin })`. It reads `globalThis.window`, so a test sets a browser-like global instead. |
25
+ | `ConnectSpaceOptions` | `ConnectOptions` |
26
+ | `SpaceWindowLike`, `SpaceMessageEvent` | No longer exported. A test declares its own. |
27
+
28
+ **Two behaviours change with no change in your code:**
29
+
30
+ - `connect()` sets `overscroll-behavior-y: none` on the Space's root element,
31
+ so the page no longer bounces at its top and bottom edge. A Space that wants
32
+ the bounce sets the style back after it connects.
33
+ - An AI call (`extract`, `summarize`, `transcribePages`) refuses a
34
+ `transcription` option other than `'standard'` or `'precise'`. Version 2
35
+ ignored any value. An Action is otherwise unchanged.
36
+
37
+ **A platform that embeds Spaces** must send a well-formed handshake: a
38
+ `runtime` that is not `{ url, version }` with an `http` or `https` URL is
39
+ ignored and the connection stays pending, and a malformed `form` or `formInfo`
40
+ on a record reply is refused as `invalid_response`. The Simple Platform already
41
+ sends both correctly.
42
+
43
+ **New in 3:**
44
+
45
+ - For a Space: platform tabs (`simple.ui.tabs`, with a count and its tone),
46
+ header actions and a header status, platform toasts, `simple.records.open()`,
47
+ `simple.navigation.open()`, and the bridge the UI Kit's managed `RecordForm`
48
+ and `RecordActivity` use.
49
+ - For an Action: `tasks.create()` from `@simpleplatform/sdk/tasks`, and the
50
+ `transcription` option on the AI calls.
51
+
52
+ Each new Space call needs a platform that supports it. On an older platform
53
+ tabs, the header, toasts and `records.open()` fail as `unavailable`, and
54
+ `navigation.open()` is ignored. The section for each call below says so.
55
+
13
56
  ## Quick Start
14
57
 
15
58
  Create your first Simple Platform action:
@@ -31,28 +74,25 @@ simple.Handle(async (request) => {
31
74
 
32
75
  The TypeScript SDK is organized into focused modules for different capabilities:
33
76
 
34
- | Module | Import | Purpose |
35
- | ------------ | ------------------------------ | ---------------------------------------------- |
36
- | **Core** | `@simpleplatform/sdk` | Request handling and action execution |
37
- | **AI** | `@simpleplatform/sdk/ai` | AI operations (extract, summarize, transcribe) |
38
- | **GraphQL** | `@simpleplatform/sdk/graphql` | Database queries and mutations |
39
- | **HTTP** | `@simpleplatform/sdk/http` | External HTTP requests |
40
- | **Security** | `@simpleplatform/sdk/security` | Security policy authoring |
41
- | **Settings** | `@simpleplatform/sdk/settings` | Application settings retrieval |
42
- | **Storage** | `@simpleplatform/sdk/storage` | File upload, and reading a stored file's bytes |
43
- | **Space** | `@simpleplatform/sdk/space` | Records, data, tasks, and documents in a Space |
77
+ | **Core** | `@simpleplatform/sdk` | Request handling and action execution |
78
+ | **AI** | `@simpleplatform/sdk/ai` | AI operations (extract, summarize, transcribe) |
79
+ | **GraphQL** | `@simpleplatform/sdk/graphql` | Database queries and mutations |
80
+ | **HTTP** | `@simpleplatform/sdk/http` | External HTTP requests |
81
+ | **Security** | `@simpleplatform/sdk/security` | Security policy authoring |
82
+ | **Settings** | `@simpleplatform/sdk/settings` | Application settings retrieval |
83
+ | **Storage** | `@simpleplatform/sdk/storage` | File upload, and reading a stored file's bytes |
84
+ | **Tasks** | `@simpleplatform/sdk/tasks` | Creating tasks from server actions |
85
+ | **Space** | `@simpleplatform/sdk/space` | Record, data, document, task, UI, and action capabilities in a Space |
44
86
 
45
87
  ## Embedded Spaces
46
88
 
47
- Use the explicit Space subpaths inside an embedded browser Space. The package
48
- root remains the Action/WASM API, so Action code never imports browser globals
49
- by accident.
89
+ Use the Space subpath inside a browser Space. The package root remains the
90
+ Action/WASM API, so Action code never imports browser globals by accident.
50
91
 
51
92
  ```typescript
52
- import { connectSpace } from '@simpleplatform/sdk/space'
93
+ import { connect } from '@simpleplatform/sdk/space'
53
94
 
54
- const hostOrigin = new URL(document.referrer).origin
55
- const simple = await connectSpace({ targetOrigin: hostOrigin })
95
+ const simple = await connect({ targetOrigin: new URL(document.referrer).origin })
56
96
  const record = await simple.records.current()
57
97
 
58
98
  await record.update({ first_name: 'Ada' }) // Stages values and runs update Behavior.
@@ -65,11 +105,222 @@ if (!result.ok) {
65
105
  ```
66
106
 
67
107
  Connect once when the Space starts and reuse the returned client. One embedded iframe has one host MessagePort handshake.
108
+ `targetOrigin` is the host's origin, not a full URL. If the embedding setup
109
+ does not provide a referrer, supply the host origin from the Space's trusted
110
+ configuration.
111
+
112
+ `simple.records.current()` returns the platform-owned record for the current
113
+ record page. Its handle exposes immutable snapshots, `update(values)`, and
114
+ `submit()`. The host enforces permissions and runs Record Behaviors; the Space
115
+ only renders the returned state. Snapshots may also include `formInfo` for
116
+ behavior-produced form-level guidance.
117
+
118
+ ### Open another managed record
119
+
120
+ `simple.records.open()` requests an independently managed record by its
121
+ application, table, and record IDs in both Record Space and general Space. The
122
+ host resolves and authorizes the target; the supplied IDs identify a record but
123
+ do not grant access. The target uses the table's standard form.
124
+
125
+ ```ts
126
+ const related = await simple.records.open({
127
+ appId: 'com.example.crm',
128
+ recordId: 'CON000123',
129
+ tableName: 'contacts',
130
+ })
131
+
132
+ if (simple.context.kind === 'record') {
133
+ const current = await simple.records.current()
134
+ // A Space can render <RecordForm record={current} /> and
135
+ // <RecordForm record={related} /> at the same time.
136
+ }
137
+
138
+ await related.update({ status: 'active' })
139
+ const result = await related.submit()
140
+ if (!result.ok)
141
+ console.log(related.snapshot().errors)
142
+ ```
143
+
144
+ Each handle has independent values, validation, behavior, and submit state.
145
+ Each `submit()` saves only that handle; multiple records are not an atomic
146
+ transaction. Opening the same target more than once in one Space connection
147
+ returns the same live handle and session. The host disposes opened sessions
148
+ when the Space connection ends; there is no per-record close method. Opening
149
+ the route-owned record itself rejects with `already_current`; use
150
+ `simple.records.current()` for it.
151
+ `open()` requires a host that negotiated the records capability; when that
152
+ transport is absent, `open()` returns a structured `unavailable` error. In
153
+ general Space context, `records.current()` remains unavailable while `open()`
154
+ succeeds whenever records transport was negotiated. An older host may still
155
+ support `current()` through the existing `record` capability while lacking
156
+ `open()`. Missing and inaccessible records return the same generic
157
+ `target_unavailable` error.
158
+
159
+ To work with another record, use `simple.records.open()` with its exact target:
160
+
161
+ ```ts
162
+ const related = await simple.records.open({
163
+ appId: 'dev.simple.ui_fixtures',
164
+ recordId: 'UIF000002',
165
+ tableName: 'ui_fixture_records',
166
+ })
167
+ await related.update({ status: 'Ready' })
168
+ const saved = await related.submit()
169
+ ```
170
+
171
+ Opened handles have the same behavior-aware update and submit workflow as the
172
+ route record. The host authorizes the target, owns an independent session, and
173
+ reuses it for repeated opens of the same target during one Space connection.
174
+ It disposes opened sessions when that connection closes; there is no public
175
+ `close()` method. `records.open()` is available in Record and standalone Spaces
176
+ when the host negotiates the `records` capability. If that capability is absent,
177
+ the call rejects with `SpaceProtocolError` code `unavailable`. The route record
178
+ cannot be opened again as a secondary session (`already_current`).
179
+
180
+ ### Managed record UI and header actions (pre-release)
68
181
 
69
- `records.current()` returns the platform-owned record for the current record
70
- page. Its handle exposes immutable snapshots, `update(values)`, and `submit()`.
71
- The host enforces permissions and runs Record Behaviors; the Space only renders
72
- the returned state.
182
+ The companion UI Kit currently implements a managed React form for Record
183
+ Spaces:
184
+
185
+ ```tsx
186
+ <RecordForm record={record} />
187
+ ```
188
+
189
+ It renders the complete Simple form without exposing field schemas, editor
190
+ registries, document/reference/secret internals, or Record Behavior timing as
191
+ public APIs. When a Space needs fully custom presentation, keep using the
192
+ record handle's `snapshot()`, `update()`, and `submit()` commands.
193
+
194
+ Record Spaces can replace the platform main actions in the header while
195
+ mounted:
196
+
197
+ ```ts
198
+ simple.ui.header.actions.set([
199
+ {
200
+ id: 'start-call',
201
+ label: 'Start call',
202
+ onClick: async () => startCall(),
203
+ type: 'primary',
204
+ },
205
+ ])
206
+ ```
207
+
208
+ Promise-returning callbacks show button loading automatically. `actions.set([])`
209
+ renders no main actions. While a custom Record Space is active, this replaces
210
+ the platform `Update` button and persisted View Actions; those defaults return
211
+ when the Space unloads or the user selects the standard view. The full
212
+ pre-release interface and examples live in the
213
+ [`@simpleplatform/ui-kit` README](../space-ui/README.md).
214
+
215
+ A header action owns its own save feedback. `record.submit()` returns validation
216
+ state without choosing UI; call `simple.ui.toast.show()` when the Space should
217
+ also show a platform toast. `RecordForm` continues to display detailed field
218
+ and form messages inline.
219
+
220
+ A Record Space can also show one status beside the record title:
221
+
222
+ ```ts
223
+ simple.ui.header.status.set({
224
+ description: 'A reviewer needs to check this record.',
225
+ label: 'Needs review',
226
+ tone: 'warning',
227
+ })
228
+
229
+ simple.ui.header.status.set(null) // Clear the status
230
+ ```
231
+
232
+ The label is non-blank and limited to 80 characters. Tones are `neutral`,
233
+ `info`, `success`, `warning`, and `danger`; the optional description is for
234
+ screen readers. Hosts that do not negotiate `headerStatus` reject this call
235
+ with an `unavailable` error. Header status is negotiated separately, so an
236
+ older host can continue to support header actions without supporting status.
237
+
238
+ ### Show a platform toast
239
+
240
+ Any Space can show feedback with Simple's existing toast presenter and theme:
241
+
242
+ ```ts
243
+ simple.ui.toast.show({
244
+ description: 'Your changes are ready.',
245
+ title: 'Saved',
246
+ })
247
+
248
+ simple.ui.toast.show({
249
+ description: 'The changes could not be saved.',
250
+ variant: 'destructive',
251
+ })
252
+ ```
253
+
254
+ At least one of `title` or `description` is required, and both are plain text.
255
+ Titles are limited to 160 characters and descriptions to 1,000. The supported
256
+ variants are `default` and `destructive`. React content and toast action
257
+ callbacks are not sent across the iframe boundary.
258
+
259
+ ### Record Space tabs
260
+
261
+ Record Spaces can declare tabs in the platform record header:
262
+
263
+ ```ts
264
+ const { selectedTabId } = await simple.ui.tabs.set({
265
+ onChange: (tabId) => {
266
+ console.log(`Active tab changed to ${tabId}`)
267
+ },
268
+ tabs: [
269
+ { icon: 'layout-dashboard', id: 'overview', title: 'Overview' },
270
+ { badge: 3, badgeTone: 'warning', icon: 'message-square', id: 'messages', title: 'Messages' },
271
+ { badge: 'New', icon: 'file-text', id: 'documents', title: 'Documents' },
272
+ ],
273
+ })
274
+
275
+ // Programmatically select a declared tab
276
+ await simple.ui.tabs.select('messages')
277
+ ```
278
+
279
+ Tabs are configured with up to 32 tabs and a required `onChange` callback. An
280
+ empty list clears the current declaration and resolves with
281
+ `{ selectedTabId: null }`.
282
+ Each tab requires an `id` (1–64 characters matching `^[a-z0-9][a-z0-9_-]{0,63}$`)
283
+ and a non-blank `title` (up to 80 characters), with optional `default: true`,
284
+ optional kebab-case Lucide `icon`, and optional `badge` (non-blank text up to 20
285
+ characters or a finite non-negative integer). A count can also set `badgeTone`
286
+ to `neutral`, `info`, `success`, `warning`, or `danger`; without it, the count
287
+ keeps its neutral appearance. At most one tab may set `default: true`; if none
288
+ is specified, the first tab defaults to active.
289
+
290
+ Older hosts that do not recognize `badgeTone` ignore it and display the count
291
+ with the neutral appearance.
292
+
293
+ The host negotiates `protocols.tabs: [1]` and owns selection and URL state.
294
+ Registration uses `ui.tabs.set`, which assigns a `registrationRequestId` and
295
+ acknowledges the initial `selectedTabId` without firing `onChange`. Host-to-Space
296
+ selection changes are delivered via canonical `SPACE_UI_TABS_SELECTION_CHANGED` with
297
+ `{ registrationRequestId, selectedTabId }` and routed to `onChange`. Events for
298
+ superseded registrations are dropped immediately.
299
+
300
+ Programmatic selection uses `ui.tabs.select`, sending `{ registrationRequestId, tabId }`.
301
+ Selecting the already-active tab resolves immediately without wire traffic.
302
+ Selecting an inactive declared tab resolves after host acknowledgement and reaches
303
+ the `onChange` callback once, deduplicating the response and event. Both methods fail
304
+ with structured `SpaceProtocolError` code `'unavailable'` outside a record Space or
305
+ when the tabs capability was not negotiated.
306
+
307
+ ### Open a platform page
308
+
309
+ Ask the host to open a host-relative platform path from any Space:
310
+
311
+ ```ts
312
+ simple.navigation.open({ path: '/om/<application>/<table>/<record>' })
313
+ simple.navigation.open({ path: '/tasks/<task>', target: 'new-tab' })
314
+ ```
315
+
316
+ `'same-tab'` opens the path in the platform tab the Space is shown in (a Space
317
+ cannot navigate its own frame); `'new-tab'` opens it in a new browser tab. The
318
+ target defaults to `'same-tab'`.
319
+ These are the platform's own names, not the browser's `_self` and `_blank`:
320
+ the platform's navigation message already carried them, and they leave room
321
+ for platform targets a browser has no name for.
322
+ `open()` returns `void` as soon as the request is posted. The host gives no
323
+ confirmation, and a host without the navigation handler ignores the message.
73
324
 
74
325
  ### Space context
75
326
 
@@ -93,17 +344,28 @@ switch (simple.context.kind) {
93
344
  The two exact context forms are `{ kind: 'standalone' }` and
94
345
  `{ kind: 'record', applicationId, tableName, recordId }`. There is no
95
346
  `unknown` context variant. A missing or malformed context rejects
96
- `connectSpace()` with `SpaceProtocolError` code `invalid_response`.
347
+ `connect({ targetOrigin })` with `SpaceProtocolError` code `invalid_response`.
348
+
349
+ `connect({ targetOrigin })` works in any embedded Space, including standalone dashboards
350
+ and tools. In a non-record Space, `simple.data` remains available and
351
+ `simple.records.open()` succeeds whenever the records capability was negotiated,
352
+ while `simple.records.current()` rejects with `SpaceProtocolError` code
353
+ `unavailable` and explains that the current record requires a record view.
354
+ In an older host, `records.current()` can remain available through the `record`
355
+ capability while `records.open()` requires the newer `records` capability.
97
356
 
98
- `connectSpace()` works in any embedded Space, including standalone dashboards
99
- and tools. In a non-record Space, `simple.data` remains available while
100
- `simple.records.current()` rejects with `SpaceProtocolError` code `unavailable`
101
- and explains that the Space must be configured as a record view.
357
+ When `connect()` runs in the Space document, it disables vertical root
358
+ overscroll bounce. Normal scrolling inside the Space remains enabled.
102
359
 
103
360
  Each capability beyond `simple.data` is negotiated with the host when the Space
104
361
  connects. A capability the host did not negotiate rejects with
105
362
  `SpaceProtocolError` code `unavailable` when it is called, and sends nothing.
106
363
 
364
+ The same `connect({ targetOrigin })` and `simple.records.current()` vocabulary is
365
+ reserved for future publicly hosted Spaces. That transport and its
366
+ authentication model are not implemented yet; authors should not add
367
+ portal-specific connection code now.
368
+
107
369
  ### Space data access
108
370
 
109
371
  Use `simple.data` for application data that is not the record form currently
@@ -131,9 +393,21 @@ const result = await simple.data.mutate<{ insert_demo__note: { id: string } }>(
131
393
  ```
132
394
 
133
395
  Use `record.update()` and `record.submit()` for writes to the current record.
134
- Those commands preserve Record Behaviors, validation, documents, and the shared
135
- record state used by the platform header. `simple.data.mutate()` is for other
136
- authorized application data; it must not be used to bypass a record workflow.
396
+ Those commands preserve Record Behaviors, validation, permissions, and the
397
+ shared record state used by the platform. The managed `RecordForm` coordinates
398
+ its specialized document-field workflow through Simple's private host adapter.
399
+ For a customer-owned upload workflow, stage a file through the public document
400
+ API:
401
+
402
+ ```ts
403
+ const { handle } = await simple.documents.stage({ file })
404
+ ```
405
+
406
+ The returned handle describes a staged upload; staging does not attach the file
407
+ to a record. The managed `RecordForm` continues to own its specialized
408
+ document-field workflow through Simple's private host adapter.
409
+ `simple.data.mutate()` is for other authorized application data and must not
410
+ bypass the record workflow.
137
411
 
138
412
  ### Space tasks
139
413
 
@@ -281,28 +555,134 @@ refused `reply()` arrives the same way, with the service's own code in
281
555
  `reply()` again with the same arguments resends the kept message rather than
282
556
  posting it twice.
283
557
 
284
- ### Space documents
558
+ #### Starting a task after other tasks
285
559
 
286
- `simple.documents.stage()` stores a file without attaching it to any record and
287
- returns its handle. The host uploads it, so a large file never travels inside
288
- an action request. The file's bytes are transferred to the host, not copied.
560
+ To make a task wait for others, create the others first, then list them under
561
+ `_metadata.start_after` in the new task's `input`:
289
562
 
290
563
  ```typescript
291
- const picker = document.querySelector<HTMLInputElement>('#packet')!
292
- const { handle } = await simple.documents.stage({ file: picker.files![0] })
293
-
294
- // A plain Blob has no name of its own, so it needs one.
295
- await simple.documents.stage({
296
- file: new Blob([csv]),
297
- mimeType: 'text/csv',
298
- name: 'quantities.csv',
564
+ const terms = await simple.tasks.create({ input: { packet: 'DOC000001' }, taskTypeId: 'TTY000003', title: 'Read the terms' })
565
+ const parties = await simple.tasks.create({ input: { packet: 'DOC000001' }, taskTypeId: 'TTY000004', title: 'Read the parties' })
566
+
567
+ const { task: summary } = await simple.tasks.create({
568
+ input: {
569
+ _metadata: {
570
+ start_after: [
571
+ { task_id: terms.task.id }, // Waits until this task has completed.
572
+ { on: ['approved', 'declined'], task_id: parties.task.id }, // Waits until it is in either state.
573
+ ],
574
+ },
575
+ packet: 'DOC000001',
576
+ },
577
+ taskTypeId: 'TTY000009',
578
+ title: 'Summarise the packet',
299
579
  })
300
580
  ```
301
581
 
302
- The handle is `{ file_hash, filename, mime_type, size, storage_path, scope? }`.
303
- `name` defaults to a `File`'s own name, and `mimeType` to the file's type, then
304
- to `application/octet-stream`. A staged document is not attached to anything
305
- yet; attach its handle through the workflow that owns the record.
582
+ - `_metadata` is reserved. The platform owns it, its shape is fixed, and a member
583
+ it does not know is refused. A task type's input schema must not declare it:
584
+ the rest of `input` is checked against that schema as if `_metadata` were not
585
+ there. It counts toward the 32,768-byte limit.
586
+ - `start_after` is a list of entries `{ task_id, on }`. `task_id` names an
587
+ existing task, and each task may be listed once. `on` is optional and names
588
+ states of the listed task's own task type that end it (a state that maps to
589
+ `completed`, `cancelled`, or `failed`). Left out, it means the states that map
590
+ to `completed`.
591
+ - The new task is created `queued`, and nothing runs for it and no model is
592
+ called until every listed task has ended in a state its entry allows. There
593
+ is no time limit. A listed task that has only stopped and is `waiting` keeps
594
+ the new task waiting; reply to that task to carry it on.
595
+ - If a listed task ends in a state its entry does not allow, or no longer
596
+ exists, the platform cancels the new task. Create another one.
597
+ - When the new task runs, its doer, the AI that does the work, is given the
598
+ `read-task-output` tool. The tool reads a listed task's status and output,
599
+ and only for the listed tasks. The platform adds it by itself; the task type
600
+ does not need to declare it.
601
+ - A create the platform refuses rejects as described above, with
602
+ `error.code` `task_rejected` and `details.code` `TASK_INPUT_INVALID`.
603
+ `details.pointers` points at the member: `/input/_metadata/start_after/1/task_id`
604
+ for a task that does not exist, or `/input/_metadata/start_after/1/on/0` for a
605
+ name that is not an end state of that task's type.
606
+ - A platform release that predates this does not know the key: a task type with
607
+ a closed input schema refuses it, and one with an open schema starts the task
608
+ at once.
609
+
610
+ ### Space actions
611
+
612
+ `simple.actions.run()` runs an action of the Space's own app where the app
613
+ declares it runs, as the signed-in user, and returns the action's JSON result:
614
+ a `server` action on the server, a `client` or `both` action in the browser, in
615
+ the platform page's own workers. The host makes the
616
+ call, so the Space makes no network request of its own: it names no domain,
617
+ needs no `network` permission to reach the platform, and handles no sign-in.
618
+ Actions work in standalone and record Spaces alike.
619
+
620
+ ```typescript
621
+ interface AttachResult { data: { document_id: string, status: string } }
622
+
623
+ const result = await simple.actions.run<AttachResult>(
624
+ 'document-attach',
625
+ { document_id: 'DOC000001', job_id: 'JOB000007' },
626
+ { timeoutMs: 120_000 }, // Optional: how long the host waits, in milliseconds.
627
+ )
628
+ ```
629
+
630
+ `action` is the action's name alone, such as `document-attach`: lowercase
631
+ letters, digits, and hyphens, starting with a letter or a digit. The host adds
632
+ the Space's own app, so a Space runs only its own app's actions and never names
633
+ an app. `input` is any JSON value and reaches the action as its payload; pass
634
+ `{}` or `null` when the action takes none. The result is the action's JSON
635
+ result as it returned it, unchecked: `TResult` is the caller's description of
636
+ it.
637
+
638
+ `timeoutMs` defaults to 60,000, and the host accepts 1,000 to 1,200,000. When it
639
+ runs out, the host stops waiting and the call rejects with `timeout`. If the
640
+ host's answer never comes, as when the host has closed its end of the
641
+ connection, the SDK stops waiting 5,000 ms after the timeout and rejects with
642
+ `timeout` itself, so a call always ends. Either way the action may still
643
+ complete, so a caller whose action writes should re-read before
644
+ offering to run it again.
645
+
646
+ A request the SDK can tell is malformed is refused before it is sent, with
647
+ `SpaceProtocolError` code `invalid_request`: a name outside that pattern, an
648
+ input that is not a JSON value, or a `timeoutMs` that is not a number. The host
649
+ checks the range of `timeoutMs`.
650
+
651
+ A call that does not return a result rejects with `SpaceProtocolError`, and its
652
+ `code` says why:
653
+
654
+ | `code` | When | `details` |
655
+ | ---------------------- | ------------------------------------------------------------------------- | ------------------ |
656
+ | `invalid_request` | The name, input, or options are malformed, or `timeoutMs` is out of range | None |
657
+ | `unsupported_protocol` | The host does not support the protocol version | None |
658
+ | `unavailable` | The host did not negotiate actions, or cannot run them | None |
659
+ | `timeout` | The action did not answer within `timeoutMs`, or the host did not answer | None |
660
+ | `action_failed` | The server answered with a status other than 2xx, or with an error result | `{ status, body }` |
661
+ | `network` | The host could not make the request | None |
662
+
663
+ For `action_failed`, `details` is an `ActionFailedDetails`: `status` is the
664
+ HTTP status the server answered with, and `body` is the response body as
665
+ parsed JSON, or `null` when it was not JSON. An action the host ran in the
666
+ browser carries 200 and the same `{ error: [...] }` body shape the server
667
+ gives for the same failure. Neither the host nor the SDK
668
+ changes the body, so an action's own error envelope is read from it:
669
+
670
+ ```typescript
671
+ import type { ActionFailedDetails } from '@simpleplatform/sdk/space'
672
+ import { SpaceProtocolError } from '@simpleplatform/sdk/space'
673
+
674
+ try {
675
+ await simple.actions.run('document-attach', { document_id: 'DOC000001' })
676
+ }
677
+ catch (error) {
678
+ if (!(error instanceof SpaceProtocolError) || error.code !== 'action_failed')
679
+ throw error
680
+
681
+ const { body, status } = error.details as ActionFailedDetails
682
+ // body is the action's own response, such as its error envelope.
683
+ console.warn(status, body)
684
+ }
685
+ ```
306
686
 
307
687
  ---
308
688
 
@@ -369,6 +749,13 @@ an editor with TSDoc support recognizes it instead of flagging it as unknown.
369
749
 
370
750
  The AI module provides powerful capabilities for working with unstructured data.
371
751
 
752
+ The `transcription` option on `extract`, `summarize`, `transcribe`, and `transcribePages` selects the reader for scanned pages; omission or `'standard'` preserves the default behavior.
753
+ `'precise'` costs more and is for pages where exact characters matter (codes, part numbers); text pages are unaffected.
754
+
755
+ ```typescript
756
+ const read = await transcribePages(documentHandle, { transcription: 'precise' }, request.context)
757
+ ```
758
+
372
759
  #### Extract Structured Data
373
760
 
374
761
  Extract structured information from documents, text, or images using AI:
@@ -641,6 +1028,34 @@ console.log(config.api_key) // "sk_live_..."
641
1028
  console.log(config.max_retries) // 3
642
1029
  ```
643
1030
 
1031
+ ### Tasks Module
1032
+
1033
+ Create a task from a server action. It is assigned to the user the action runs
1034
+ as. The platform makes the task and first-message ids. If an action must not
1035
+ start the same work twice, check its own record before creating the task.
1036
+
1037
+ On refusal, the task service's message begins with its code, such as
1038
+ `TASK_INPUT_INVALID: /title`. The SDK surfaces the full host error message.
1039
+ **What is not yet true.** Not every service refusal keeps its internal code.
1040
+ Input/schema (`TASK_INPUT_INVALID`, `TASK_INPUT_TOO_LARGE`), assignee
1041
+ (`TASK_ASSIGNEE_INVALID`), and other public refusals retain their codes.
1042
+ Unlisted internal refusals, including an unknown task type
1043
+ (`TASK_RELATION_NOT_FOUND`), arrive as `TASK_RUNTIME_REMOTE_FAILURE`, just as
1044
+ on the page path. A malformed successful reply throws an ordinary `Error`.
1045
+
1046
+ ```typescript
1047
+ import * as tasks from '@simpleplatform/sdk/tasks'
1048
+
1049
+ const { task } = await tasks.create({
1050
+ input: { invoice_id: 'INV000017' },
1051
+ taskTypeId: 'TTY000003',
1052
+ title: 'Review the invoice'
1053
+ }, request.context)
1054
+ ```
1055
+
1056
+ The result is `{ task: { id: 'TASK000042', revision: 0, status: 'queued' } }`.
1057
+ A new task starts at revision 0, also returned by the page's `tasks.create`.
1058
+
644
1059
  ### Storage Module
645
1060
 
646
1061
  Upload files from external sources to the platform's content-addressable storage:
package/dist/ai.d.ts CHANGED
@@ -159,6 +159,11 @@ export interface AICommonOptions {
159
159
  * If this timeout is exceeded, the promise will reject. Defaults to 30,000ms.
160
160
  */
161
161
  timeout?: number;
162
+ /**
163
+ * Selects the reader for scanned pages; omission or `standard` preserves the default.
164
+ * `precise` costs more and suits exact characters (codes, part numbers); text pages are unaffected.
165
+ */
166
+ transcription?: 'standard' | 'precise';
162
167
  }
163
168
  /**
164
169
  * The configuration options for an AI `extract` operation.
@@ -229,6 +234,11 @@ export interface AITranscribePagesOptions {
229
234
  regenerate?: boolean;
230
235
  /** (Optional) The maximum time in milliseconds to wait for the operation. */
231
236
  timeout?: number;
237
+ /**
238
+ * Selects the reader for scanned pages; omission or `standard` preserves the default.
239
+ * `precise` costs more and suits exact characters (codes, part numbers); text pages are unaffected.
240
+ */
241
+ transcription?: 'standard' | 'precise';
232
242
  }
233
243
  /**
234
244
  * One page's transcription, or why it has none. Pages are numbered in the
package/dist/ai.js CHANGED
@@ -51,10 +51,14 @@ async function _uploadPendingFiles(obj, context) {
51
51
  * @internal
52
52
  */
53
53
  async function _executeAIOperation(operation, input, options, context) {
54
- const { model, prompt, reasoning = true, reasoningBudget, regenerate = false, systemPrompt, temperature, timeout, } = options;
54
+ const { model, prompt, reasoning = true, reasoningBudget, regenerate = false, systemPrompt, temperature, timeout, transcription, } = options;
55
+ if (transcription !== undefined && transcription !== 'standard' && transcription !== 'precise') {
56
+ throw new Error('The `transcription` option must be "standard" or "precise".');
57
+ }
55
58
  const processedInput = await _uploadPendingFiles(input, context);
56
59
  // 1. Construct the universal options payload for caching and execution.
57
60
  const universalOptions = {
61
+ ...(transcription !== undefined && { transcription }),
58
62
  ...(temperature !== undefined && { temperature }),
59
63
  ...(reasoningBudget !== undefined && { reasoningBudget }),
60
64
  ...({ reasoning }),