@jskit-ai/agent-docs 0.1.380 → 0.1.382
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/guide/agent/app-extras/assistant-conversation.md +3 -1
- package/guide/agent/app-extras/assistant.md +143 -20
- package/guide/agent/app-setup/material-3-migration.md +2 -1
- package/guide/agent/framework/material-3.md +79 -1
- package/guide/agent/framework/ui-pass.md +3 -1
- package/package.json +1 -1
- package/patterns/minimal-foundation/example/package.json +1 -1
- package/patterns/shell-foundation/example/package.json +2 -2
- package/reference/autogen/PATTERN_INDEX.md +30 -19
- package/reference/autogen/packages/assistant-core.md +58 -2
- package/reference/autogen/packages/assistant-runtime.md +9 -1
- package/reference/autogen/packages/shell-web.md +13 -0
- package/reference/autogen/tooling/testUtils.md +3 -2
- package/skills/jskit/references/material-3.md +79 -1
- package/skills/jskit/references/pattern-index.md +30 -19
- package/skills/jskit/references/patterns/app/minimal-foundation/example/package.json +1 -1
- package/skills/jskit/references/patterns/app/shell-foundation/example/package.json +2 -2
- package/skills/jskit/references/patterns/assistant/model-sized-results/PATTERN.md +147 -0
- package/skills/jskit/references/patterns/assistant/model-sized-results/example/packages/inbox/src/server/inbox.js +37 -0
- package/skills/jskit/references/patterns/assistant/model-sized-results/example/packages/inbox/src/server/inboxActions.js +90 -0
- package/skills/jskit/references/patterns/assistant/model-sized-results/example/packages/inbox/src/server/types.js +21 -0
- package/skills/jskit/references/patterns/auth/oidc-sign-in/example/package.json +2 -2
- package/skills/jskit/references/patterns/crud/crud-feature-package/example/packages/books/package.json +1 -1
- package/skills/jskit/references/patterns/realtime/realtime-application/example/package.json +2 -2
- package/skills/jskit/references/patterns/users/user-administration-server/example/packages/users/package.json +2 -2
- package/skills/jskit/references/patterns/users/user-administration-server/example/packages/users-workspace/package.json +3 -3
- package/skills/jskit/references/ui-pass.md +3 -1
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: assistant/model-sized-results
|
|
3
|
+
title: Model-sized tool results
|
|
4
|
+
summary: Keep what an action gives the assistant within its result limit with text over markup, the first part of long text and the action that reads the rest, and paged lists, so the catalogue's own cut stays the last resort.
|
|
5
|
+
keywords: ai, assistant, tool, result, size, limit, long text, read on, paging, email, document, maxToolResultBytes
|
|
6
|
+
requires: @jskit-ai/assistant-core
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Model-sized tool results
|
|
10
|
+
|
|
11
|
+
## Use when
|
|
12
|
+
|
|
13
|
+
Use this pattern when an action the assistant calls can answer with more than
|
|
14
|
+
its surface's `maxToolResultBytes` (48 KiB by default, 256 KiB on the MCP
|
|
15
|
+
endpoint): an inbox conversation whose emails quote each other, a document, a
|
|
16
|
+
log, a long settings record, or a list read without a page size.
|
|
17
|
+
|
|
18
|
+
## Do not use when
|
|
19
|
+
|
|
20
|
+
Do not use it for a result that is always small, such as one record by id or
|
|
21
|
+
a count. Do not use it to keep data from the model: what the model may read is
|
|
22
|
+
the action's permission and its assistant output. A screen that needs the whole
|
|
23
|
+
value keeps its route's result; this pattern shapes only what the assistant
|
|
24
|
+
reads.
|
|
25
|
+
|
|
26
|
+
## Product decisions
|
|
27
|
+
|
|
28
|
+
- Which fields the model reads, and which stay on the screen: an email's
|
|
29
|
+
HTML body, its raw source and its attachments' bytes are the screen's.
|
|
30
|
+
- Each long text's first part (`partLength`): enough to answer most questions
|
|
31
|
+
without reading on, and small enough that the largest record's first parts
|
|
32
|
+
fit together. An inbox whose surface allows 128 KiB gives 2,000 characters
|
|
33
|
+
of each email, so a conversation of 35 emails that each quote all the ones
|
|
34
|
+
before, about 900 KB stored, fits whole.
|
|
35
|
+
- How much one read-on part holds (16,000 characters in the example).
|
|
36
|
+
- Each list's page size, and the filters a model narrows it with.
|
|
37
|
+
|
|
38
|
+
## Invariants
|
|
39
|
+
|
|
40
|
+
- The model reads text, not markup. An action's assistant output carries an
|
|
41
|
+
email's or a page's plain text once, never its HTML beside it.
|
|
42
|
+
- A long text field is declared in `extensions.assistant.longText`. The
|
|
43
|
+
catalogue cuts it to its first part and adds `<field>Rest` beside it:
|
|
44
|
+
`{ characters, actionId, input }`, where `input` is the record's own keys
|
|
45
|
+
(`input(record)`) and the `offset` the next part starts at. A record never
|
|
46
|
+
holds a field of that name itself.
|
|
47
|
+
- The read action is a query on the automation channel, with the same
|
|
48
|
+
permission and surfaces as the action whose text it reads on. It reads the
|
|
49
|
+
same stored text the first part came from, from the offset given, with
|
|
50
|
+
`readTextPart`, which the catalogue cuts with too, so the offsets agree.
|
|
51
|
+
- The catalogue cuts the text the model receives: after the action, its
|
|
52
|
+
policy and its `transformResult` have run. A text marked or rewritten
|
|
53
|
+
before then, such as an email's text wrapped in markers that say it is
|
|
54
|
+
untrusted, is cut as marked, and the Rest pointer's offset counts the
|
|
55
|
+
marked text. So either the read action slices that same marked text (it
|
|
56
|
+
marks the stored text exactly as the policy does, then calls
|
|
57
|
+
`readTextPart`), or the marking sits outside the text field (a sibling
|
|
58
|
+
field, or a wrapper around the record), so the text field holds the stored
|
|
59
|
+
text unchanged. A read action that slices the stored text while the first
|
|
60
|
+
part was cut from marked text reads on from the wrong place: a marker
|
|
61
|
+
that adds 20 characters skips or repeats 20 characters at every part's
|
|
62
|
+
edge. A change that keeps the text's length, such as defusing `[` as `(`,
|
|
63
|
+
leaves the offsets aligned; the read action applies it too, so every part
|
|
64
|
+
reaches the model defused alike.
|
|
65
|
+
- Both text fields are `noTrim: true`. json-rest-schema trims strings, so a
|
|
66
|
+
trimmed part loses the spaces at its edges, and a text trimmed at its start
|
|
67
|
+
moves every offset after it.
|
|
68
|
+
- A list is paged in the query: a limit, and the cursor or offset of the next
|
|
69
|
+
page, which the model asks for when it needs more.
|
|
70
|
+
- `maxToolResultBytes` is not raised to fit the largest record. Every byte of
|
|
71
|
+
a result is read by the model on every later step of the turn and, in the
|
|
72
|
+
API engine, in later turns' history, and the largest record keeps growing;
|
|
73
|
+
a raised limit only moves where the result is cut.
|
|
74
|
+
- A result still over the limit is cut by the catalogue, never refused: the
|
|
75
|
+
model reads its first part, with a note saying how much is left out, and
|
|
76
|
+
reads on only if what it needs may be further on.
|
|
77
|
+
|
|
78
|
+
## Framework APIs
|
|
79
|
+
|
|
80
|
+
`extensions.assistant.longText` maps each long text's path in the tool's
|
|
81
|
+
result (the assistant output when the action declares one) to
|
|
82
|
+
`{ partLength, readAction, input }`. A path is field names joined by dots, with
|
|
83
|
+
`[]` after a name for each item of an array (`messages[].bodyText`) or alone
|
|
84
|
+
first when the result is an array (`[].bodyText`). `partLength` is a whole
|
|
85
|
+
number of characters; `readAction` names an automation query; `input(record)`
|
|
86
|
+
returns the read action's input without its `offset`. A wrong declaration stops
|
|
87
|
+
the catalogue with an error naming the action and the path. The tool's
|
|
88
|
+
description tells the model how its long text comes.
|
|
89
|
+
|
|
90
|
+
`readTextPart(text, offset, length)` from `@jskit-ai/assistant-core/server`
|
|
91
|
+
returns `{ text, offset, nextOffset, total }`. Offsets count JavaScript
|
|
92
|
+
characters; a part never splits a character outside the Basic Multilingual
|
|
93
|
+
Plane, so it may end one character early, or take that one character whole
|
|
94
|
+
when it is all the part would hold. `nextOffset` is `null` on the last part;
|
|
95
|
+
an offset at or past the end gives an empty last part at `total`.
|
|
96
|
+
|
|
97
|
+
A result over the limit comes as `{ toolResultPart: { note, resultId, offset,
|
|
98
|
+
nextOffset, total, text } }`, where `text` is the next stretch of the result's
|
|
99
|
+
JSON text, cut between two items or members when one is near, else after a
|
|
100
|
+
space in a long string, and never inside an escape or a character. Direct tool
|
|
101
|
+
sets read on with the `assistant_result_read` tool (`{ resultId, offset }`);
|
|
102
|
+
discovery tool sets with `assistant_action_execute` and
|
|
103
|
+
`actionId: "assistant.result.read"`. The catalogue keeps a cut result in its
|
|
104
|
+
process's memory for 15 minutes, up to 4 Mi characters of all its cut results,
|
|
105
|
+
oldest first, for the same signed-in person, surface and workspace while the
|
|
106
|
+
action is still theirs; a result it no longer keeps answers `assistant_tool_result_unknown`
|
|
107
|
+
(404), and the model calls the tool again. An unsaved action's result and one
|
|
108
|
+
for a caller that resolved its tool set with `offerResultReader: false` are cut
|
|
109
|
+
with nothing kept, and the note says to ask for less.
|
|
110
|
+
|
|
111
|
+
## Example files
|
|
112
|
+
|
|
113
|
+
`example/packages/inbox/src/server/inboxActions.js` declares a conversation
|
|
114
|
+
read whose emails' text is long text, and the read action that reads an
|
|
115
|
+
email's text on from an offset. `example/packages/inbox/src/server/inbox.js`
|
|
116
|
+
is the service: the conversation read gives each email's plain text, and the
|
|
117
|
+
text read answers one part with `readTextPart`. `types.js` names the
|
|
118
|
+
repository the service reads.
|
|
119
|
+
|
|
120
|
+
## Variation points
|
|
121
|
+
|
|
122
|
+
Change the paths, part lengths, read action ids and their input keys. A result
|
|
123
|
+
whose long text sits at its top (`bodyText`) or in an array result
|
|
124
|
+
(`[].bodyText`) declares that path. One read action can serve several fields
|
|
125
|
+
when its input says which. A list action pages instead of declaring long text,
|
|
126
|
+
and one whose items hold long text does both.
|
|
127
|
+
|
|
128
|
+
## Verification
|
|
129
|
+
|
|
130
|
+
- call the action with the largest real record, not a test's small one, and
|
|
131
|
+
see its result within the surface's `maxToolResultBytes`
|
|
132
|
+
- read every long text on from its Rest pointer to `nextOffset: null` and see
|
|
133
|
+
the parts join to the stored text exactly, with a space and a character
|
|
134
|
+
outside the Basic Multilingual Plane at a part's edge
|
|
135
|
+
- see a short text come whole, with no Rest field
|
|
136
|
+
- see the read action refuse a person without the permission
|
|
137
|
+
|
|
138
|
+
## Avoid
|
|
139
|
+
|
|
140
|
+
- raising `maxToolResultBytes` to fit the largest record
|
|
141
|
+
- HTML, raw source or base64 beside the text the model reads
|
|
142
|
+
- a read action that slices the stored text while the first part was cut
|
|
143
|
+
from text the action or its policy marked or rewrote, so its offsets point
|
|
144
|
+
elsewhere
|
|
145
|
+
- trimmed text fields on either side
|
|
146
|
+
- a Rest field the action writes itself
|
|
147
|
+
- a list read without a limit
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { readTextPart } from "@jskit-ai/assistant-core/server";
|
|
2
|
+
|
|
3
|
+
// How much of an email's text one read-on part holds.
|
|
4
|
+
const MESSAGE_TEXT_PART = 16_000;
|
|
5
|
+
|
|
6
|
+
/** @param {{ messages: import("./types.js").InboxMessages }} dependencies */
|
|
7
|
+
function createInbox({ messages }) {
|
|
8
|
+
/**
|
|
9
|
+
* One conversation as its screen and the assistant read it: each email's plain text, never its HTML, which says
|
|
10
|
+
* the same in many times the characters.
|
|
11
|
+
* @param {{ threadId: string }} input
|
|
12
|
+
* @param {{ context: object }} options
|
|
13
|
+
*/
|
|
14
|
+
async function readThread({ threadId }, { context }) {
|
|
15
|
+
const thread = await messages.readThread(threadId, { context });
|
|
16
|
+
return Object.freeze({
|
|
17
|
+
id: thread.id,
|
|
18
|
+
subject: thread.subject,
|
|
19
|
+
messages: thread.messages.map(({ id, fromName, receivedAt, bodyText }) => Object.freeze({ id, fromName, receivedAt, bodyText }))
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* One email's text from `offset`: the same stored text whose first part the conversation read gave, so the
|
|
25
|
+
* offset its Rest pointer names is where this part starts.
|
|
26
|
+
* @param {{ messageId: string, offset: number }} input
|
|
27
|
+
* @param {{ context: object }} options
|
|
28
|
+
*/
|
|
29
|
+
async function readMessageText({ messageId, offset }, { context }) {
|
|
30
|
+
const message = await messages.readMessage(messageId, { context });
|
|
31
|
+
return Object.freeze({ messageId: message.id, ...readTextPart(message.bodyText, offset, MESSAGE_TEXT_PART) });
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return Object.freeze({ readThread, readMessageText });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { createInbox };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { createSchema } from "json-rest-schema";
|
|
2
|
+
|
|
3
|
+
const ACTION_READ_THREAD = "inbox.threads.read";
|
|
4
|
+
const ACTION_READ_MESSAGE_TEXT = "inbox.messages.read_text";
|
|
5
|
+
// How much of each email's text a conversation read gives the model. The rest of a longer email is read on with
|
|
6
|
+
// ACTION_READ_MESSAGE_TEXT, so the longest conversation's first parts fit the assistant's result limit.
|
|
7
|
+
const EMAIL_TEXT_PART = 2000;
|
|
8
|
+
|
|
9
|
+
/** The fields every inbox query shares, spread first into each definition. */
|
|
10
|
+
const INBOX_QUERY = Object.freeze({
|
|
11
|
+
version: 1,
|
|
12
|
+
kind: "query",
|
|
13
|
+
channels: ["api", "automation"],
|
|
14
|
+
surfaces: ["app"]
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const INBOX_READ = Object.freeze({ require: "all", permissions: ["inbox.read"] });
|
|
18
|
+
|
|
19
|
+
// An email's text is never trimmed: a part may start or end with a space, and a trimmed start would move every offset.
|
|
20
|
+
const threadMessage = createSchema({
|
|
21
|
+
id: { type: "string", required: true },
|
|
22
|
+
fromName: { type: "string", required: true },
|
|
23
|
+
receivedAt: { type: "string", required: true },
|
|
24
|
+
bodyText: { type: "string", noTrim: true, required: true }
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const threadInput = Object.freeze({ schema: createSchema({ threadId: { type: "string", required: true } }) });
|
|
28
|
+
const threadOutput = Object.freeze({
|
|
29
|
+
schema: createSchema({
|
|
30
|
+
id: { type: "string", required: true },
|
|
31
|
+
subject: { type: "string", required: true },
|
|
32
|
+
messages: { type: "array", required: true, items: threadMessage }
|
|
33
|
+
}),
|
|
34
|
+
mode: "replace"
|
|
35
|
+
});
|
|
36
|
+
const messageTextInput = Object.freeze({
|
|
37
|
+
schema: createSchema({
|
|
38
|
+
messageId: { type: "string", required: true },
|
|
39
|
+
offset: { type: "integer", min: 0, defaultTo: 0 }
|
|
40
|
+
})
|
|
41
|
+
});
|
|
42
|
+
const messageTextOutput = Object.freeze({
|
|
43
|
+
schema: createSchema({
|
|
44
|
+
messageId: { type: "string", required: true },
|
|
45
|
+
text: { type: "string", noTrim: true, required: true },
|
|
46
|
+
offset: { type: "integer", required: true },
|
|
47
|
+
nextOffset: { type: "integer", nullable: true, required: true },
|
|
48
|
+
total: { type: "integer", required: true }
|
|
49
|
+
}),
|
|
50
|
+
mode: "replace"
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
/** @param {{ inbox: import("./types.js").Inbox }} dependencies */
|
|
54
|
+
function createInboxActions({ inbox }) {
|
|
55
|
+
return Object.freeze([
|
|
56
|
+
Object.freeze({
|
|
57
|
+
...INBOX_QUERY,
|
|
58
|
+
id: ACTION_READ_THREAD,
|
|
59
|
+
input: threadInput,
|
|
60
|
+
output: threadOutput,
|
|
61
|
+
permission: INBOX_READ,
|
|
62
|
+
extensions: {
|
|
63
|
+
assistant: {
|
|
64
|
+
description: "Read one inbox conversation: its subject and each email's sender, date and text.",
|
|
65
|
+
longText: {
|
|
66
|
+
"messages[].bodyText": {
|
|
67
|
+
partLength: EMAIL_TEXT_PART,
|
|
68
|
+
readAction: ACTION_READ_MESSAGE_TEXT,
|
|
69
|
+
input: (message) => ({ messageId: message.id })
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
execute: (input, context) => inbox.readThread(input, { context })
|
|
75
|
+
}),
|
|
76
|
+
Object.freeze({
|
|
77
|
+
...INBOX_QUERY,
|
|
78
|
+
id: ACTION_READ_MESSAGE_TEXT,
|
|
79
|
+
input: messageTextInput,
|
|
80
|
+
output: messageTextOutput,
|
|
81
|
+
permission: INBOX_READ,
|
|
82
|
+
extensions: {
|
|
83
|
+
assistant: { description: "Read one email's text from an offset, such as the rest of an email a conversation read gave in part." }
|
|
84
|
+
},
|
|
85
|
+
execute: (input, context) => inbox.readMessageText(input, { context })
|
|
86
|
+
})
|
|
87
|
+
]);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { ACTION_READ_MESSAGE_TEXT, ACTION_READ_THREAD, createInboxActions };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {object} InboxMessage
|
|
3
|
+
* @property {string} id
|
|
4
|
+
* @property {string} fromName
|
|
5
|
+
* @property {string} receivedAt
|
|
6
|
+
* @property {string} bodyText The email's plain text, as stored.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @typedef {object} InboxMessages
|
|
11
|
+
* @property {(threadId: string, options: { context: object }) => Promise<{ id: string, subject: string, messages: InboxMessage[] }>} readThread
|
|
12
|
+
* @property {(messageId: string, options: { context: object }) => Promise<InboxMessage>} readMessage
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @typedef {object} Inbox
|
|
17
|
+
* @property {(input: { threadId: string }, options: { context: object }) => Promise<object>} readThread
|
|
18
|
+
* @property {(input: { messageId: string, offset: number }, options: { context: object }) => Promise<object>} readMessageText
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
export {};
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
"./shared": "./src/shared/index.js"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@jskit-ai/crud-core": "0.2.
|
|
13
|
+
"@jskit-ai/crud-core": "0.2.67",
|
|
14
14
|
"@jskit-ai/resource-crud-core": "0.1.231",
|
|
15
|
-
"@jskit-ai/users-core": "0.2.
|
|
15
|
+
"@jskit-ai/users-core": "0.2.78"
|
|
16
16
|
},
|
|
17
17
|
"jskit": {
|
|
18
18
|
"kind": "runtime",
|
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
"./shared": "./src/shared/index.js"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@jskit-ai/crud-core": "0.2.
|
|
13
|
+
"@jskit-ai/crud-core": "0.2.67",
|
|
14
14
|
"@jskit-ai/resource-crud-core": "0.1.231",
|
|
15
|
-
"@jskit-ai/users-core": "0.2.
|
|
16
|
-
"@jskit-ai/workspaces-core": "0.2.
|
|
15
|
+
"@jskit-ai/users-core": "0.2.78",
|
|
16
|
+
"@jskit-ai/workspaces-core": "0.2.78"
|
|
17
17
|
},
|
|
18
18
|
"peerDependencies": {
|
|
19
19
|
"@jskit-ai/kernel": "0.2.38",
|
|
@@ -50,7 +50,9 @@ for (const scheme of ["light", "dark"]) {
|
|
|
50
50
|
- **Look at every screenshot** before reporting. They are the only proof of
|
|
51
51
|
what the checks cannot see: layout, spacing, contrast, overflow, clipped
|
|
52
52
|
labels, borders where tones belong, colour that only works in one scheme, an
|
|
53
|
-
Up arrow where it should not be or missing where it should
|
|
53
|
+
Up arrow where it should not be or missing where it should, and a screen that
|
|
54
|
+
is still text on neutral surfaces, with no icons, no colour role carrying
|
|
55
|
+
meaning and no focal point ([A finished screen](material-3.md#a-finished-screen)).
|
|
54
56
|
- **Prove Up** on the screens in scope, with `shellBackButton(page)` and
|
|
55
57
|
`pressShellBack(page)` from `@jskit-ai/shell-web/test/shellNavigation`:
|
|
56
58
|
contact → supplier → Up shows the contact; a supplier opened from a pasted
|