@lowdefy/ai-utils 6.2.0 → 6.2.2
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/agentErrorForLog.js +6 -34
- package/package.json +4 -4
package/dist/agentErrorForLog.js
CHANGED
|
@@ -12,15 +12,12 @@
|
|
|
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
|
-
*/
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
|
|
21
|
-
// logged by name and code alone, except APICallError, whose message is the provider's reply;
|
|
22
|
-
// any other error keeps its message, cut to 500 characters. Causes are followed the same way.
|
|
23
|
-
const MESSAGE_LIMIT = 500;
|
|
15
|
+
*/ import { errorSummaryForLog } from '@lowdefy/errors';
|
|
16
|
+
// What an agent log may say about an error: the summary every Lowdefy log of an error uses (its
|
|
17
|
+
// name, code, status code and message cut to 500 characters, with an AI SDK error's message left
|
|
18
|
+
// out but for an APICallError's, and the same for three causes). Chat text can hold personal
|
|
19
|
+
// information, so no agent log carries messages, prompts, tool inputs or tool outputs.
|
|
20
|
+
const agentErrorForLog = errorSummaryForLog;
|
|
24
21
|
const CAUSE_DEPTH = 3;
|
|
25
22
|
// AISDKError.isInstance reads this marker; the error classes themselves are not imported so
|
|
26
23
|
// any copy of the AI SDK in the app is recognised.
|
|
@@ -28,31 +25,6 @@ const aiSdkErrorMarker = Symbol.for('vercel.ai.error');
|
|
|
28
25
|
function isAiSdkError(error) {
|
|
29
26
|
return error[aiSdkErrorMarker] === true;
|
|
30
27
|
}
|
|
31
|
-
function truncate(text) {
|
|
32
|
-
if (text.length <= MESSAGE_LIMIT) return text;
|
|
33
|
-
return `${text.slice(0, MESSAGE_LIMIT - 1)}…`;
|
|
34
|
-
}
|
|
35
|
-
function agentErrorForLog(error, depth = 0) {
|
|
36
|
-
if (!(error instanceof Error)) {
|
|
37
|
-
return {
|
|
38
|
-
name: typeof error
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
const summary = {
|
|
42
|
-
name: error.name
|
|
43
|
-
};
|
|
44
|
-
if (!isAiSdkError(error) || error.name === 'AI_APICallError') {
|
|
45
|
-
summary.message = truncate(String(error.message));
|
|
46
|
-
}
|
|
47
|
-
if (error.code !== undefined) summary.code = error.code;
|
|
48
|
-
if (error.statusCode !== undefined) summary.statusCode = error.statusCode;
|
|
49
|
-
// A RetryError holds the attempt that failed last as lastError rather than as its cause.
|
|
50
|
-
const cause = error.lastError ?? error.cause;
|
|
51
|
-
if (cause !== undefined && depth < CAUSE_DEPTH) {
|
|
52
|
-
summary.cause = agentErrorForLog(cause, depth + 1);
|
|
53
|
-
}
|
|
54
|
-
return summary;
|
|
55
|
-
}
|
|
56
28
|
function carriesAiSdkError(error, depth = 0) {
|
|
57
29
|
if (!(error instanceof Error)) return false;
|
|
58
30
|
if (isAiSdkError(error)) return true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/ai-utils",
|
|
3
|
-
"version": "6.2.
|
|
3
|
+
"version": "6.2.2",
|
|
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.2.
|
|
21
|
-
"@lowdefy/helpers": "6.2.
|
|
20
|
+
"@lowdefy/errors": "6.2.2",
|
|
21
|
+
"@lowdefy/helpers": "6.2.2",
|
|
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.2.
|
|
27
|
+
"@lowdefy/ajv": "6.2.2",
|
|
28
28
|
"@swc/cli": "0.8.1",
|
|
29
29
|
"@swc/core": "1.15.32",
|
|
30
30
|
"@swc/jest": "0.2.39",
|