@tacoreai/web-sdk 1.9.0 → 1.10.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.
@@ -88,6 +88,19 @@ export const appsClientAiMethods = {
88
88
  try {
89
89
  const parsed = JSON.parse(data);
90
90
 
91
+ if (parsed?.error) {
92
+ const streamError = new Error(
93
+ parsed.error?.message ||
94
+ parsed.message ||
95
+ "AI service error"
96
+ );
97
+ if (parsed.error?.code) {
98
+ streamError.code = parsed.error.code;
99
+ }
100
+ options.onError?.(streamError);
101
+ return;
102
+ }
103
+
91
104
  if (parsed.choices && parsed.choices.length > 0) {
92
105
  const choice = parsed.choices[0];
93
106
 
@@ -146,10 +146,17 @@ const getPreviewSessionToken = async function(options = {}) {
146
146
  }
147
147
  };
148
148
 
149
- const isInvalidPreviewTokenError = (error) => {
149
+ const isRefreshablePreviewTokenError = (error) => {
150
150
  const response = error?.response;
151
151
  const responseData = error?.responseData;
152
- return response?.status === 401 && responseData?.code === "INVALID_PREVIEW_TOKEN";
152
+ if (response?.status !== 401) {
153
+ return false;
154
+ }
155
+
156
+ return [
157
+ "INVALID_PREVIEW_TOKEN",
158
+ "MISSING_PREVIEW_TOKEN",
159
+ ].includes(String(responseData?.code || "").trim());
153
160
  };
154
161
 
155
162
  const parseAppServerResponsePayload = async (response) => {
@@ -359,7 +366,7 @@ const invokeByPreviewProxy = async function(appServerAPIName, payload, options =
359
366
  try {
360
367
  return await invokeByPreviewProxyOnce.call(this, appServerAPIName, payload, options, previewToken);
361
368
  } catch (error) {
362
- if (!isInvalidPreviewTokenError(error)) {
369
+ if (!isRefreshablePreviewTokenError(error)) {
363
370
  throw error;
364
371
  }
365
372
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tacoreai/web-sdk",
3
3
  "description": "This file is for app server package, not the real npm package",
4
- "version": "1.9.0",
4
+ "version": "1.10.0",
5
5
  "type": "module",
6
6
  "publishConfig": {
7
7
  "access": "public",