@lowdefy/ai-utils 6.0.0 → 6.1.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/dist/handleAgentChat.js +17 -12
- package/package.json +4 -4
package/dist/handleAgentChat.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
|
-
*/ import { convertToModelMessages, createAgentUIStream, createUIMessageStream, createUIMessageStreamResponse, generateId, generateText, pruneMessages,
|
|
15
|
+
*/ import { convertToModelMessages, createAgentUIStream, createUIMessageStream, createUIMessageStreamResponse, generateId, generateText, pruneMessages, validateUIMessages } from 'ai';
|
|
16
16
|
import { serializer } from '@lowdefy/helpers';
|
|
17
17
|
import createToolLoopAgent from './createToolLoopAgent.js';
|
|
18
18
|
import createUsageAccumulator from './createUsageAccumulator.js';
|
|
@@ -51,15 +51,15 @@ function convertDataUrlsToBase64(messages) {
|
|
|
51
51
|
function dropEmptyMessages(messages) {
|
|
52
52
|
return messages.filter((msg)=>Array.isArray(msg.parts) && msg.parts.length > 0);
|
|
53
53
|
}
|
|
54
|
-
// What the client is told when a turn fails.
|
|
55
|
-
//
|
|
56
|
-
//
|
|
57
|
-
//
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
54
|
+
// What the client is told when a turn fails or a tool throws. The text reaches the end
|
|
55
|
+
// user and AgentChat config (`_event: message`), so it takes the wire policy: the
|
|
56
|
+
// author's message for a UserError or an auth refusal, the generic message otherwise. A
|
|
57
|
+
// library's message can embed anything it saw - a TypeValidationError's embeds the whole
|
|
58
|
+
// conversation. The full error is logged server-side.
|
|
59
|
+
function createClientErrorText(context) {
|
|
60
|
+
return function clientErrorText(error) {
|
|
61
|
+
return context.wireErrorMessage(error);
|
|
62
|
+
};
|
|
63
63
|
}
|
|
64
64
|
// Concatenate the text parts of the first user message — used as the source
|
|
65
65
|
// for generateTitle.
|
|
@@ -90,6 +90,9 @@ async function handleAgentChat({ connection, properties, context }) {
|
|
|
90
90
|
const hasMcpClients = mcpClients.length > 0;
|
|
91
91
|
const pruneConfig = agent.properties.prune;
|
|
92
92
|
const titleEnabled = agent.properties.generateTitle === true;
|
|
93
|
+
const clientErrorText = createClientErrorText(context);
|
|
94
|
+
// Every stream gets clientErrorText: the AI SDK's default onError writes a tool error or
|
|
95
|
+
// an in-stream error to the client raw.
|
|
93
96
|
const stream = createUIMessageStream({
|
|
94
97
|
onError: clientErrorText,
|
|
95
98
|
execute: async ({ writer })=>{
|
|
@@ -170,7 +173,8 @@ async function handleAgentChat({ connection, properties, context }) {
|
|
|
170
173
|
// Without a generator the assistant message reaches onFinish with
|
|
171
174
|
// id: '' — see the createAgentUIStream call below.
|
|
172
175
|
generateMessageId: generateId,
|
|
173
|
-
onFinish: captureMessages
|
|
176
|
+
onFinish: captureMessages,
|
|
177
|
+
onError: clientErrorText
|
|
174
178
|
});
|
|
175
179
|
} else {
|
|
176
180
|
// createAgentUIStream validates UIMessages, converts to ModelMessages,
|
|
@@ -193,7 +197,8 @@ async function handleAgentChat({ connection, properties, context }) {
|
|
|
193
197
|
// after a reload.
|
|
194
198
|
generateMessageId: generateId,
|
|
195
199
|
onStepFinish: collectStep,
|
|
196
|
-
onFinish: captureMessages
|
|
200
|
+
onFinish: captureMessages,
|
|
201
|
+
onError: clientErrorText
|
|
197
202
|
});
|
|
198
203
|
}
|
|
199
204
|
// Read the agent stream to completion before running onFinish hooks.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/ai-utils",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.1.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -17,14 +17,14 @@
|
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@ai-sdk/mcp": "1.0.41",
|
|
20
|
-
"@lowdefy/errors": "6.
|
|
21
|
-
"@lowdefy/helpers": "6.
|
|
20
|
+
"@lowdefy/errors": "6.1.0",
|
|
21
|
+
"@lowdefy/helpers": "6.1.0",
|
|
22
22
|
"ai": "6.0.176",
|
|
23
23
|
"glob": "13.0.6"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@jest/globals": "28.1.3",
|
|
27
|
-
"@lowdefy/ajv": "6.
|
|
27
|
+
"@lowdefy/ajv": "6.1.0",
|
|
28
28
|
"@swc/cli": "0.8.1",
|
|
29
29
|
"@swc/core": "1.15.32",
|
|
30
30
|
"@swc/jest": "0.2.39",
|