@columenlabs/lumen-ai 0.1.266 → 0.1.268

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.
@@ -100,14 +100,28 @@ function shownError(err) {
100
100
  }
101
101
  /**
102
102
  * A plain sentence for an error OpenAI sends inside the answer's stream (an `error` event, or a
103
- * failed response): what happened and what to do, by its code. The code is shown when it is not
104
- * one we know; OpenAI's own message is only logged.
103
+ * failed response): what happened and what to do, by its code, with OpenAI's code in brackets so
104
+ * the person and the logs see the real reason. A plan's usage limit and a per-minute rate limit are
105
+ * different things: the first waits for the plan to reset, the second only a minute. OpenAI's own
106
+ * message is logged (one `assistant_upstream_error` line), never shown.
105
107
  */
106
- function openaiStreamError(code, plan) {
107
- if (/usage_limit|usage_unavailable|insufficient_quota|rate_limit/.test(code))
108
+ function openaiStreamError(er, plan) {
109
+ const code = String(er.code || er.type || '');
110
+ console.error(JSON.stringify({
111
+ event: 'assistant_upstream_error',
112
+ provider: 'openai',
113
+ plan,
114
+ code: er.code ?? null,
115
+ type: er.type ?? null,
116
+ message: typeof er.message === 'string' ? er.message.slice(0, 500) : null,
117
+ }));
118
+ const tag = code ? ` (${code})` : '';
119
+ if (/usage_limit|usage_unavailable|insufficient_quota/.test(code))
108
120
  return plan
109
- ? 'Your ChatGPT plan reached its usage limit for now: try again later, or pick another model.'
110
- : 'OpenAI says the key is out of quota or rate limited. Try again shortly.';
121
+ ? `Your ChatGPT plan reached its usage limit for now${tag}: try again later, or pick another model.`
122
+ : `OpenAI says the key is out of quota${tag}. Add credit to the key, or pick another model.`;
123
+ if (/rate_limit/.test(code))
124
+ return `OpenAI is rate limiting these requests${tag}: try again in a minute.`;
111
125
  if (/context_length|too_long|max_tokens/.test(code))
112
126
  return 'This chat is too long for the model. Start a new chat, or type /compact.';
113
127
  if (/model_not_found|model_not_supported|invalid_model|unsupported_model/.test(code))
@@ -115,7 +129,7 @@ function openaiStreamError(code, plan) {
115
129
  ? 'This model is not on your ChatGPT plan. Pick another model for this tier in Settings.'
116
130
  : 'OpenAI does not offer this model to the key. Pick another model for this tier in Settings.';
117
131
  if (/server_error|overloaded|timeout|unavailable/.test(code))
118
- return 'OpenAI is overloaded. Try again shortly.';
132
+ return `OpenAI is overloaded${tag}. Try again shortly.`;
119
133
  if (/content_policy|safety|refus/.test(code))
120
134
  return 'OpenAI declined to answer this message.';
121
135
  return `OpenAI could not answer (${code || 'no reason given'}). It is logged; try again or pick another model.`;
@@ -1073,7 +1087,7 @@ export class Assistant {
1073
1087
  done = e.response;
1074
1088
  else if (e.type === 'error') {
1075
1089
  const er = (e.error ?? e);
1076
- throw new AssistantError(openaiStreamError(er.code || er.type || '', plan), 'upstream');
1090
+ throw new AssistantError(openaiStreamError(er, plan), 'upstream');
1077
1091
  }
1078
1092
  }
1079
1093
  }
@@ -1081,12 +1095,16 @@ export class Assistant {
1081
1095
  // The SDK throws a stream's `error` event as an APIError with no HTTP status.
1082
1096
  if (err instanceof OpenAI.APIError && err.status === undefined) {
1083
1097
  const er = (err.error ?? {});
1084
- throw new AssistantError(openaiStreamError(er.code || er.type || err.code || '', plan), 'upstream');
1098
+ throw new AssistantError(openaiStreamError({
1099
+ ...er,
1100
+ code: er.code || er.type || err.code || '',
1101
+ message: er.message ?? err.message,
1102
+ }, plan), 'upstream');
1085
1103
  }
1086
1104
  throw err;
1087
1105
  }
1088
1106
  if (done?.status === 'failed')
1089
- throw new AssistantError(openaiStreamError(done.error?.code ?? '', plan), 'upstream');
1107
+ throw new AssistantError(openaiStreamError(done.error ?? {}, plan), 'upstream');
1090
1108
  const u = done?.usage;
1091
1109
  if (u) {
1092
1110
  const read = u.input_tokens_details?.cached_tokens ?? 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@columenlabs/lumen-ai",
3
- "version": "0.1.266",
3
+ "version": "0.1.268",
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.266",
60
- "@columenlabs/lumen-ui-types": "0.1.266",
59
+ "@columenlabs/lumen-ops": "0.1.268",
60
+ "@columenlabs/lumen-ui-types": "0.1.268",
61
61
  "agents": "0.32.0",
62
62
  "ai": "7.0.162",
63
63
  "just-bash": "3.6.0",