@columenlabs/lumen-ai 0.1.268 → 0.1.269

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.
@@ -96,8 +96,50 @@ function shownError(err) {
96
96
  return { message: `${who} is overloaded. Try again shortly.`, code: 'overloaded' };
97
97
  return { message: `${who} refused the request (${status ?? 'error'}).`, code: 'model_error' };
98
98
  }
99
+ // The AI SDK's errors (APICallError, and RetryError around its last one) carry the HTTP status as
100
+ // statusCode: say what that status means, never the body; the body goes to the log only.
101
+ const call = sdkCall(err);
102
+ if (call) {
103
+ console.error(JSON.stringify({
104
+ event: 'assistant_upstream_error',
105
+ provider: 'ai-sdk',
106
+ status: call.status ?? null,
107
+ message: call.message.slice(0, 500),
108
+ }));
109
+ if (call.status === 401 || call.status === 403)
110
+ return { message: `The model key was refused (${call.status}).`, code: 'key_refused' };
111
+ if (call.status === 429)
112
+ return {
113
+ message: 'The model is busy or hit a rate limit (429). Try again shortly.',
114
+ code: 'rate_limited',
115
+ };
116
+ if ((call.status ?? 0) >= 500)
117
+ return {
118
+ message: `The model is overloaded (${call.status}). Try again shortly.`,
119
+ code: 'overloaded',
120
+ };
121
+ return {
122
+ message: `The model refused the request (${call.status ?? 'error'}).`,
123
+ code: 'model_error',
124
+ };
125
+ }
99
126
  return { message: 'Something went wrong while answering.', code: 'internal' };
100
127
  }
128
+ /** An AI SDK call error's status and message, through RetryError's lastError and `cause`. */
129
+ function sdkCall(err, depth = 0) {
130
+ if (!err || typeof err !== 'object' || depth > 3)
131
+ return null;
132
+ const e = err;
133
+ const name = typeof e.name === 'string' ? e.name : '';
134
+ if (name === 'AI_RetryError' || name === 'RetryError')
135
+ return sdkCall(e.lastError, depth + 1);
136
+ if (name === 'AI_APICallError' || name === 'APICallError' || typeof e.statusCode === 'number')
137
+ return {
138
+ ...(typeof e.statusCode === 'number' && { status: e.statusCode }),
139
+ message: typeof e.message === 'string' ? e.message : '',
140
+ };
141
+ return e.cause ? sdkCall(e.cause, depth + 1) : null;
142
+ }
101
143
  /**
102
144
  * A plain sentence for an error OpenAI sends inside the answer's stream (an `error` event, or a
103
145
  * failed response): what happened and what to do, by its code, with OpenAI's code in brackets so
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@columenlabs/lumen-ai",
3
- "version": "0.1.268",
3
+ "version": "0.1.269",
4
4
  "description": "Lumen's assistant and agent parts: a chat assistant's server (Claude tiers, tools over MCP, the web, hand off, spend caps), serving an MCP server from a Worker, read-only tool sets and metered tool calls.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -56,8 +56,8 @@
56
56
  "@ai-sdk/openai": "4.0.108",
57
57
  "@anthropic-ai/sdk": "0.133.0",
58
58
  "@cloudflare/think": "0.23.0",
59
- "@columenlabs/lumen-ops": "0.1.268",
60
- "@columenlabs/lumen-ui-types": "0.1.268",
59
+ "@columenlabs/lumen-ops": "0.1.269",
60
+ "@columenlabs/lumen-ui-types": "0.1.269",
61
61
  "agents": "0.32.0",
62
62
  "ai": "7.0.162",
63
63
  "just-bash": "3.6.0",