@simpleplatform/sdk 2.5.0 → 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 +382 -44
- package/dist/ai.d.ts +10 -0
- package/dist/ai.js +5 -1
- package/dist/space/actions.d.ts +59 -0
- package/dist/space/actions.js +69 -0
- package/dist/space/browser-transport.d.ts +18 -0
- package/dist/space/browser-transport.js +229 -0
- package/dist/space/core.d.ts +40 -241
- package/dist/space/core.js +69 -499
- package/dist/space/documents.d.ts +25 -0
- package/dist/space/documents.js +72 -0
- package/dist/space/index.d.ts +6 -32
- package/dist/space/index.js +59 -99
- package/dist/space/navigation.d.ts +25 -0
- package/dist/space/navigation.js +32 -0
- package/dist/space/protocol.d.ts +66 -0
- package/dist/space/protocol.js +77 -0
- package/dist/space/record-form.d.ts +94 -0
- package/dist/space/record-form.js +217 -0
- package/dist/space/record.d.ts +137 -0
- package/dist/space/record.js +231 -0
- package/dist/space/status.d.ts +2 -0
- package/dist/space/status.js +7 -0
- package/dist/space/tabs.d.ts +64 -0
- package/dist/space/tabs.js +236 -0
- package/dist/space/tasks.d.ts +84 -0
- package/dist/space/tasks.js +129 -0
- package/dist/space/ui.d.ts +67 -0
- package/dist/space/ui.js +123 -0
- package/dist/tasks.d.ts +18 -0
- package/dist/tasks.js +34 -0
- package/package.json +5 -1
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
|
-
|
|
|
35
|
-
|
|
|
36
|
-
| **
|
|
37
|
-
| **
|
|
38
|
-
| **
|
|
39
|
-
| **
|
|
40
|
-
| **
|
|
41
|
-
| **
|
|
42
|
-
| **
|
|
43
|
-
| **Space** | `@simpleplatform/sdk/space` | Records, data, tasks, documents, and actions 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
|
|
48
|
-
|
|
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 {
|
|
93
|
+
import { connect } from '@simpleplatform/sdk/space'
|
|
53
94
|
|
|
54
|
-
const
|
|
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)
|
|
181
|
+
|
|
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
|
+
```
|
|
68
315
|
|
|
69
|
-
`
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
the
|
|
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
|
-
`
|
|
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
|
-
`
|
|
99
|
-
|
|
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,
|
|
135
|
-
record state used by the platform
|
|
136
|
-
|
|
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,57 @@ 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
|
-
|
|
558
|
+
#### Starting a task after other tasks
|
|
285
559
|
|
|
286
|
-
|
|
287
|
-
|
|
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
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
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.
|
|
306
609
|
|
|
307
610
|
### Space actions
|
|
308
611
|
|
|
@@ -446,6 +749,13 @@ an editor with TSDoc support recognizes it instead of flagging it as unknown.
|
|
|
446
749
|
|
|
447
750
|
The AI module provides powerful capabilities for working with unstructured data.
|
|
448
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
|
+
|
|
449
759
|
#### Extract Structured Data
|
|
450
760
|
|
|
451
761
|
Extract structured information from documents, text, or images using AI:
|
|
@@ -718,6 +1028,34 @@ console.log(config.api_key) // "sk_live_..."
|
|
|
718
1028
|
console.log(config.max_retries) // 3
|
|
719
1029
|
```
|
|
720
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
|
+
|
|
721
1059
|
### Storage Module
|
|
722
1060
|
|
|
723
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 }),
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { ProtocolRequest, SpaceTransport } from './protocol.js';
|
|
2
|
+
import type { JsonValue } from './tasks.js';
|
|
3
|
+
import { requestWithin } from './protocol.js';
|
|
4
|
+
export { requestWithin };
|
|
5
|
+
export interface ActionRunOptions {
|
|
6
|
+
/**
|
|
7
|
+
* How long the host waits for the action before it stops and answers
|
|
8
|
+
* `timeout`, in milliseconds. The host uses 60,000 when it is left out and
|
|
9
|
+
* accepts 1,000 to 1,200,000.
|
|
10
|
+
*/
|
|
11
|
+
timeoutMs?: number;
|
|
12
|
+
}
|
|
13
|
+
/** The `details` of a `SpaceProtocolError` whose code is `action_failed`. */
|
|
14
|
+
export interface ActionFailedDetails {
|
|
15
|
+
/** The action's response body as parsed JSON, or `null` when it was not JSON. */
|
|
16
|
+
body: JsonValue;
|
|
17
|
+
/**
|
|
18
|
+
* The HTTP status the server answered with. An action the host ran in the
|
|
19
|
+
* browser (declared `client` or `both`) carries 200, the status the server
|
|
20
|
+
* gives the same failure, and its `body` has the same `{ error: [...] }` shape.
|
|
21
|
+
*/
|
|
22
|
+
status: number;
|
|
23
|
+
}
|
|
24
|
+
export interface SimpleActionsClient {
|
|
25
|
+
/**
|
|
26
|
+
* Runs an action of this Space's own app where the app declares it runs
|
|
27
|
+
* (on the server, or in the browser for a `client` or `both` action), as
|
|
28
|
+
* the signed-in user, and returns its JSON result as the action returned it. The host
|
|
29
|
+
* adds the app, so `action` is the name alone, such as `document-attach`.
|
|
30
|
+
*/
|
|
31
|
+
run: <TResult = unknown>(action: string, input: unknown, options?: ActionRunOptions) => Promise<TResult>;
|
|
32
|
+
}
|
|
33
|
+
export interface ActionRunRequest extends ProtocolRequest<{
|
|
34
|
+
/** The action's name within the Space's own app; the host adds the app. */
|
|
35
|
+
action: string;
|
|
36
|
+
input: JsonValue;
|
|
37
|
+
timeoutMs?: number;
|
|
38
|
+
}> {
|
|
39
|
+
operation: 'action.run';
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* How long a run waits for the host. The host answers `timeout` itself at the
|
|
43
|
+
* timeout, so this wait only ends a run whose answer never comes, as when the
|
|
44
|
+
* host has closed its port. A timeout the host refuses is answered at once, so
|
|
45
|
+
* it only needs to give a delay a timer can hold.
|
|
46
|
+
*/
|
|
47
|
+
export declare function actionWaitMs(timeoutMs: number | undefined): number;
|
|
48
|
+
/**
|
|
49
|
+
* Checks an action run before it is sent. The timeout's range is the host's to
|
|
50
|
+
* enforce, so only its type is checked here, and it is sent only when given.
|
|
51
|
+
*/
|
|
52
|
+
export declare function readActionRunPayload(action: string, input: unknown, options: ActionRunOptions | undefined): ActionRunRequest['payload'];
|
|
53
|
+
/**
|
|
54
|
+
* The host binds the Space's own app to every action it runs, so a Space names
|
|
55
|
+
* only the action and cannot reach another app's. Actions are not tied to a
|
|
56
|
+
* page record, so they are available in any Space whose host negotiated the
|
|
57
|
+
* action protocol, standalone or record.
|
|
58
|
+
*/
|
|
59
|
+
export declare function createActionsClient(transport: SpaceTransport | undefined, nextRequestId: () => string): SimpleActionsClient;
|