@butlerbot/sdk 0.0.30 → 0.0.31
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.
|
@@ -52,9 +52,16 @@ class SSEConversationTransport {
|
|
|
52
52
|
if (!endpoint)
|
|
53
53
|
return undefined;
|
|
54
54
|
const response = await this.post(endpoint, { chatId: request.chatId, mode: request.mode });
|
|
55
|
+
if (!response)
|
|
56
|
+
return undefined;
|
|
55
57
|
// 404 is "nothing was running", which is the ordinary answer to stopping a moment late.
|
|
56
|
-
|
|
58
|
+
// Anything else is the server refusing or failing, and a stop button that quietly does
|
|
59
|
+
// nothing is the hardest kind of bug to report — so it is said out loud.
|
|
60
|
+
if (!response.ok) {
|
|
61
|
+
if (response.status !== 404)
|
|
62
|
+
console.warn(`[Stop failed: ${response.status}]`, await response.text().catch(() => ""));
|
|
57
63
|
return undefined;
|
|
64
|
+
}
|
|
58
65
|
const body = await response.json().catch(() => undefined);
|
|
59
66
|
return body?.stop;
|
|
60
67
|
}
|
|
@@ -69,7 +76,13 @@ class SSEConversationTransport {
|
|
|
69
76
|
return { ok: true };
|
|
70
77
|
// 409: the turn is no longer accepting messages. The caller still has something the
|
|
71
78
|
// user typed and must send it as an ordinary turn.
|
|
72
|
-
|
|
79
|
+
if (response.status === 409)
|
|
80
|
+
return { ok: false, reason: "too_late" };
|
|
81
|
+
// Anything other than "no turn" means the message did not land for a reason the caller
|
|
82
|
+
// cannot see: it still falls back to sending, but not in silence.
|
|
83
|
+
if (response.status !== 404)
|
|
84
|
+
console.warn(`[Steer failed: ${response.status}]`, await response.text().catch(() => ""));
|
|
85
|
+
return { ok: false, reason: "no_turn" };
|
|
73
86
|
}
|
|
74
87
|
async post(endpoint, body) {
|
|
75
88
|
const url = (0, url_formatter_1.formatURL)(endpoint, undefined, { apiKey: this.config.apiKey, debug: this.config.debug });
|
|
@@ -82,9 +95,10 @@ class SSEConversationTransport {
|
|
|
82
95
|
}
|
|
83
96
|
catch (error) {
|
|
84
97
|
// A stop that cannot reach the server is not worth throwing over: the turn is
|
|
85
|
-
// ending on its own soon enough, and the caller has no better move to make.
|
|
86
|
-
|
|
87
|
-
|
|
98
|
+
// ending on its own soon enough, and the caller has no better move to make. It is
|
|
99
|
+
// still worth saying, and not only in debug — an interruption that vanishes without
|
|
100
|
+
// a trace is indistinguishable from one the UI forgot to wire up.
|
|
101
|
+
console.warn(`[Interrupt failed: ${endpoint}]`, error);
|
|
88
102
|
return undefined;
|
|
89
103
|
}
|
|
90
104
|
}
|
|
@@ -197,6 +197,16 @@ export type ConvoStatusPayload = {
|
|
|
197
197
|
};
|
|
198
198
|
export type ResponseStatusPayload = {
|
|
199
199
|
completed: boolean;
|
|
200
|
+
/** Present when the turn was stopped rather than finished on its own.
|
|
201
|
+
* `mode` is what was applied and `requestedMode` what was asked for: they differ when a
|
|
202
|
+
* hard stop was downgraded because the model's provider ignores a cancelled stream. */
|
|
203
|
+
stop?: {
|
|
204
|
+
mode: "soft" | "hard";
|
|
205
|
+
requestedMode: "soft" | "hard";
|
|
206
|
+
by: "user" | "system";
|
|
207
|
+
/** When the stop was requested. */
|
|
208
|
+
at: number;
|
|
209
|
+
};
|
|
200
210
|
/** Rich response metadata — only present on the final `completed: true` event.
|
|
201
211
|
* Populated by the caller (e.g. gateway) after the response finishes and usage is available. */
|
|
202
212
|
metadata?: ResponseMetadata;
|