@iota-uz/sdk 0.4.39 → 0.4.41
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/bichat/index.cjs +104 -17
- package/dist/bichat/index.cjs.map +1 -1
- package/dist/bichat/index.d.cts +1 -0
- package/dist/bichat/index.d.ts +1 -0
- package/dist/bichat/index.mjs +104 -17
- package/dist/bichat/index.mjs.map +1 -1
- package/package.json +1 -1
- package/tailwind/compiled.css +1 -1
- package/tailwind/iota.css +36 -5
- package/tailwind/sdk-theme.cjs +9 -0
package/dist/bichat/index.cjs
CHANGED
|
@@ -1181,6 +1181,15 @@ var RateLimiter = class {
|
|
|
1181
1181
|
}
|
|
1182
1182
|
};
|
|
1183
1183
|
|
|
1184
|
+
// ui/src/bichat/types/index.ts
|
|
1185
|
+
var MessageRole = /* @__PURE__ */ ((MessageRole2) => {
|
|
1186
|
+
MessageRole2["User"] = "user";
|
|
1187
|
+
MessageRole2["Assistant"] = "assistant";
|
|
1188
|
+
MessageRole2["System"] = "system";
|
|
1189
|
+
MessageRole2["Tool"] = "tool";
|
|
1190
|
+
return MessageRole2;
|
|
1191
|
+
})(MessageRole || {});
|
|
1192
|
+
|
|
1184
1193
|
// ui/src/applet-devtools/enabled.ts
|
|
1185
1194
|
function shouldEnableAppletDevtools() {
|
|
1186
1195
|
if (typeof window === "undefined") {
|
|
@@ -1722,15 +1731,6 @@ function getSessionDebugUsage(turns) {
|
|
|
1722
1731
|
};
|
|
1723
1732
|
}
|
|
1724
1733
|
|
|
1725
|
-
// ui/src/bichat/types/index.ts
|
|
1726
|
-
var MessageRole = /* @__PURE__ */ ((MessageRole2) => {
|
|
1727
|
-
MessageRole2["User"] = "user";
|
|
1728
|
-
MessageRole2["Assistant"] = "assistant";
|
|
1729
|
-
MessageRole2["System"] = "system";
|
|
1730
|
-
MessageRole2["Tool"] = "tool";
|
|
1731
|
-
return MessageRole2;
|
|
1732
|
-
})(MessageRole || {});
|
|
1733
|
-
|
|
1734
1734
|
// ui/src/bichat/context/chatHelpers.ts
|
|
1735
1735
|
var ARTIFACT_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
1736
1736
|
"code_interpreter",
|
|
@@ -2541,6 +2541,25 @@ var ChatMachine = class {
|
|
|
2541
2541
|
return;
|
|
2542
2542
|
}
|
|
2543
2543
|
const prev = this.state.messaging.turns;
|
|
2544
|
+
const localPartialTurn = prev.slice().reverse().find((turn) => turn.assistantTurn?.id.startsWith("assistant-partial-"));
|
|
2545
|
+
if (localPartialTurn) {
|
|
2546
|
+
if (fetchedTurns.length === 0) {
|
|
2547
|
+
fetchedTurns = prev;
|
|
2548
|
+
} else {
|
|
2549
|
+
const correspondingIndex = fetchedTurns.findIndex(
|
|
2550
|
+
(turn, index) => turn.userTurn.id === localPartialTurn.userTurn.id || index === fetchedTurns.length - 1 && turn.userTurn.content === localPartialTurn.userTurn.content
|
|
2551
|
+
);
|
|
2552
|
+
if (correspondingIndex >= 0) {
|
|
2553
|
+
if (!fetchedTurns[correspondingIndex].assistantTurn) {
|
|
2554
|
+
fetchedTurns = fetchedTurns.map(
|
|
2555
|
+
(turn, index) => index === correspondingIndex ? { ...turn, assistantTurn: localPartialTurn.assistantTurn } : turn
|
|
2556
|
+
);
|
|
2557
|
+
}
|
|
2558
|
+
} else {
|
|
2559
|
+
fetchedTurns = [...fetchedTurns, localPartialTurn];
|
|
2560
|
+
}
|
|
2561
|
+
}
|
|
2562
|
+
}
|
|
2544
2563
|
const hasPendingUserOnly = prev.length > 0 && !prev[prev.length - 1].assistantTurn;
|
|
2545
2564
|
const patch = {};
|
|
2546
2565
|
const effectivePendingQuestion = pendingQuestion === void 0 ? this.state.messaging.pendingQuestion : pendingQuestion;
|
|
@@ -2646,8 +2665,9 @@ var ChatMachine = class {
|
|
|
2646
2665
|
this.abortController = controller;
|
|
2647
2666
|
const epoch = this.viewEpoch;
|
|
2648
2667
|
this._updateMessaging({ isStreaming: true });
|
|
2668
|
+
let accumulatedContent = "";
|
|
2649
2669
|
try {
|
|
2650
|
-
let
|
|
2670
|
+
let terminalError = null;
|
|
2651
2671
|
await this.dataSource.resumeStream(
|
|
2652
2672
|
sessionId,
|
|
2653
2673
|
runId,
|
|
@@ -2667,13 +2687,27 @@ var ChatMachine = class {
|
|
|
2667
2687
|
this._handleToolStart(chunk.tool);
|
|
2668
2688
|
} else if (chunk.type === "tool_end" && chunk.tool) {
|
|
2669
2689
|
this._handleToolEnd(chunk.tool);
|
|
2670
|
-
} else if (chunk.type === "
|
|
2690
|
+
} else if (chunk.type === "error") {
|
|
2691
|
+
terminalError = new Error(chunk.error || "Stream error");
|
|
2671
2692
|
}
|
|
2672
2693
|
},
|
|
2673
2694
|
controller.signal
|
|
2674
2695
|
);
|
|
2696
|
+
if (terminalError) {
|
|
2697
|
+
throw terminalError;
|
|
2698
|
+
}
|
|
2675
2699
|
clearRunMarker(sessionId);
|
|
2676
2700
|
await this._syncSessionFromServer(sessionId, true, epoch);
|
|
2701
|
+
} catch (err) {
|
|
2702
|
+
if (this._isCurrentEpoch(epoch) && !(err instanceof Error && err.name === "AbortError")) {
|
|
2703
|
+
this._preservePartialAssistant(accumulatedContent);
|
|
2704
|
+
const normalized = normalizeRPCError(err, "Failed to resume stream");
|
|
2705
|
+
this._updateMessaging({
|
|
2706
|
+
streamError: normalized.userMessage,
|
|
2707
|
+
streamErrorRetryable: normalized.retryable
|
|
2708
|
+
});
|
|
2709
|
+
}
|
|
2710
|
+
throw err;
|
|
2677
2711
|
} finally {
|
|
2678
2712
|
if (this.abortController === controller) {
|
|
2679
2713
|
this.abortController = null;
|
|
@@ -2956,7 +2990,8 @@ var ChatMachine = class {
|
|
|
2956
2990
|
model,
|
|
2957
2991
|
tempTurnId,
|
|
2958
2992
|
controller,
|
|
2959
|
-
epoch
|
|
2993
|
+
epoch,
|
|
2994
|
+
onContent
|
|
2960
2995
|
} = params;
|
|
2961
2996
|
let accumulatedContent = "";
|
|
2962
2997
|
let createdSessionId;
|
|
@@ -2986,6 +3021,7 @@ var ChatMachine = class {
|
|
|
2986
3021
|
}
|
|
2987
3022
|
if ((chunk.type === "chunk" || chunk.type === "content") && chunk.content) {
|
|
2988
3023
|
accumulatedContent += chunk.content;
|
|
3024
|
+
onContent(accumulatedContent);
|
|
2989
3025
|
this._updateMessaging({ streamingContent: accumulatedContent });
|
|
2990
3026
|
} else if (chunk.type === "thinking" && chunk.content) {
|
|
2991
3027
|
this._handleThinkingChunk(chunk.content);
|
|
@@ -3071,7 +3107,7 @@ var ChatMachine = class {
|
|
|
3071
3107
|
this._clearStreamError();
|
|
3072
3108
|
this.lastSendAttempt = null;
|
|
3073
3109
|
}
|
|
3074
|
-
_handleSendError(err, content, tempTurn, epoch) {
|
|
3110
|
+
_handleSendError(err, content, tempTurn, epoch, partialAssistantContent) {
|
|
3075
3111
|
if (!this._isCurrentEpoch(epoch)) {
|
|
3076
3112
|
return false;
|
|
3077
3113
|
}
|
|
@@ -3101,13 +3137,52 @@ var ChatMachine = class {
|
|
|
3101
3137
|
};
|
|
3102
3138
|
}
|
|
3103
3139
|
this._updateInput({ message: "", inputError: null });
|
|
3140
|
+
const turns = this._preservePartialAssistant(
|
|
3141
|
+
partialAssistantContent,
|
|
3142
|
+
tempTurn.id
|
|
3143
|
+
);
|
|
3104
3144
|
this._updateMessaging({
|
|
3145
|
+
turns,
|
|
3105
3146
|
streamError: normalized.userMessage,
|
|
3106
3147
|
streamErrorRetryable: normalized.retryable
|
|
3107
3148
|
});
|
|
3108
3149
|
console.error("Send message error:", err);
|
|
3109
3150
|
return false;
|
|
3110
3151
|
}
|
|
3152
|
+
_preservePartialAssistant(content, targetTurnId) {
|
|
3153
|
+
if (content.trim() === "") {
|
|
3154
|
+
return this.state.messaging.turns;
|
|
3155
|
+
}
|
|
3156
|
+
let targetIndex = targetTurnId ? this.state.messaging.turns.findIndex((turn) => turn.id === targetTurnId) : -1;
|
|
3157
|
+
if (!targetTurnId) {
|
|
3158
|
+
for (let i = this.state.messaging.turns.length - 1; i >= 0; i--) {
|
|
3159
|
+
if (!this.state.messaging.turns[i].assistantTurn) {
|
|
3160
|
+
targetIndex = i;
|
|
3161
|
+
break;
|
|
3162
|
+
}
|
|
3163
|
+
}
|
|
3164
|
+
}
|
|
3165
|
+
if (targetIndex < 0) {
|
|
3166
|
+
return this.state.messaging.turns;
|
|
3167
|
+
}
|
|
3168
|
+
const turns = this.state.messaging.turns.map(
|
|
3169
|
+
(turn, index) => index === targetIndex ? {
|
|
3170
|
+
...turn,
|
|
3171
|
+
assistantTurn: {
|
|
3172
|
+
id: generateTempId("assistant-partial"),
|
|
3173
|
+
role: "assistant" /* Assistant */,
|
|
3174
|
+
content,
|
|
3175
|
+
citations: [],
|
|
3176
|
+
artifacts: [],
|
|
3177
|
+
codeOutputs: [],
|
|
3178
|
+
lifecycle: "complete",
|
|
3179
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
3180
|
+
}
|
|
3181
|
+
} : turn
|
|
3182
|
+
);
|
|
3183
|
+
this._updateMessaging({ turns });
|
|
3184
|
+
return turns;
|
|
3185
|
+
}
|
|
3111
3186
|
// ── Send message ────────────────────────────────────────────────────────
|
|
3112
3187
|
/**
|
|
3113
3188
|
* Public entry point (no options). Calls _sendMessageCore internally.
|
|
@@ -3176,6 +3251,7 @@ var ChatMachine = class {
|
|
|
3176
3251
|
const prevTurns = this.state.messaging.turns;
|
|
3177
3252
|
this._insertOptimisticTurn(prevTurns, tempTurn, replaceFromMessageID);
|
|
3178
3253
|
let shouldDrainQueue = true;
|
|
3254
|
+
let partialAssistantContent = "";
|
|
3179
3255
|
try {
|
|
3180
3256
|
const { activeSessionId, shouldNavigateAfter } = await this._resolveSendSession(curSessionId, curDebugMode);
|
|
3181
3257
|
this.sendingSessionId = activeSessionId || null;
|
|
@@ -3191,7 +3267,10 @@ var ChatMachine = class {
|
|
|
3191
3267
|
model: this.state.session.model,
|
|
3192
3268
|
tempTurnId: tempTurn.id,
|
|
3193
3269
|
controller,
|
|
3194
|
-
epoch
|
|
3270
|
+
epoch,
|
|
3271
|
+
onContent: (streamedContent) => {
|
|
3272
|
+
partialAssistantContent = streamedContent;
|
|
3273
|
+
}
|
|
3195
3274
|
});
|
|
3196
3275
|
if (!this._isCurrentEpoch(epoch)) {
|
|
3197
3276
|
} else if (stopped) {
|
|
@@ -3204,8 +3283,10 @@ var ChatMachine = class {
|
|
|
3204
3283
|
this._clearStreamError();
|
|
3205
3284
|
const syncId = createdSessionId || activeSessionId;
|
|
3206
3285
|
if (syncId && syncId !== "new") {
|
|
3207
|
-
await this._syncSessionFromServer(syncId, true, epoch).catch(
|
|
3208
|
-
|
|
3286
|
+
await this._syncSessionFromServer(syncId, true, epoch).catch(
|
|
3287
|
+
() => {
|
|
3288
|
+
}
|
|
3289
|
+
);
|
|
3209
3290
|
}
|
|
3210
3291
|
} else {
|
|
3211
3292
|
await this._ensureSessionSyncAfterStream(
|
|
@@ -3218,7 +3299,13 @@ var ChatMachine = class {
|
|
|
3218
3299
|
this._finalizeSuccessfulSend(targetSessionId, shouldNavigateAfter);
|
|
3219
3300
|
}
|
|
3220
3301
|
} catch (err) {
|
|
3221
|
-
shouldDrainQueue = this._handleSendError(
|
|
3302
|
+
shouldDrainQueue = this._handleSendError(
|
|
3303
|
+
err,
|
|
3304
|
+
content,
|
|
3305
|
+
tempTurn,
|
|
3306
|
+
epoch,
|
|
3307
|
+
partialAssistantContent
|
|
3308
|
+
);
|
|
3222
3309
|
} finally {
|
|
3223
3310
|
if (this._isCurrentEpoch(epoch)) {
|
|
3224
3311
|
this._updateMessaging({
|