@windmill-labs/chat-sdk 1.871.1 → 1.873.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.
- package/README.md +10 -2
- package/dist/ai-sdk.cjs +1 -1
- package/dist/ai-sdk.js +1 -1
- package/dist/assistant-ui.cjs +1 -1
- package/dist/assistant-ui.js +1 -1
- package/dist/{chat-pUgtVqWV.cjs → chat-BB4qQwLO.cjs} +113 -43
- package/dist/{chat-D5SvCHXU.js → chat-BD65QCxW.js} +113 -43
- package/dist/{follow-Dug-Afeu.cjs → follow-4zitFXAj.cjs} +1 -0
- package/dist/{follow-DXfmfPfr.js → follow-BiGZzxuz.js} +1 -0
- package/dist/index.cjs +2 -2
- package/dist/index.js +2 -2
- package/dist/react.cjs +1 -1
- package/dist/react.js +1 -1
- package/dist/stream.d.ts +4 -0
- package/dist/types.d.ts +15 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -245,6 +245,7 @@ interface ChatState {
|
|
|
245
245
|
loadingMessages: boolean
|
|
246
246
|
hasMoreMessages: boolean
|
|
247
247
|
runningJobId?: string // the flow job the running turn follows
|
|
248
|
+
waitingOnBackground?: boolean // the agent answered and waits on tools running in the background
|
|
248
249
|
}
|
|
249
250
|
|
|
250
251
|
interface ChatMessage {
|
|
@@ -267,8 +268,11 @@ A turn goes `submitted` (the flow is queued) → `streaming` (the answer is arri
|
|
|
267
268
|
`success` or `error`. A flow that fails still completes the turn: its error is the
|
|
268
269
|
answer, an `assistant` message with `success: false`. `status: 'error'` (with `error`
|
|
269
270
|
set) means the turn could not run or be followed at all, such as a refused request.
|
|
271
|
+
An agent that answered while some of its tools still run in the background keeps its turn
|
|
272
|
+
`streaming` with `waitingOnBackground` set until one of them finishes and wakes it: its answer
|
|
273
|
+
is given, and those tools' messages stay `running` until their results arrive.
|
|
270
274
|
|
|
271
|
-
Methods: `sendMessage(text, { inputs?, attachments?, attachmentsInput? })`, `stop()`,
|
|
275
|
+
Methods: `sendMessage(text, { inputs?, attachments?, attachmentsInput?, overRunningTurn? })`, `stop()`,
|
|
272
276
|
`newConversation()`, `selectConversation(id)`, `loadConversations({ page?, perPage?, kind? })`,
|
|
273
277
|
`deleteConversation(id)`, `renameConversation(id, title)`, `loadOlderMessages()`,
|
|
274
278
|
`resumeTurn(turn)`, `refreshMessages()` (reads what another tab added to the open
|
|
@@ -276,7 +280,11 @@ conversation), `destroy()`. `kind` lists the flow editor's test chats (`'test'`)
|
|
|
276
280
|
own (`'deployed'`, the server's default) or both (`'all'`); each `Conversation` carries
|
|
277
281
|
`isTest`. A rename keeps the conversation's place in the list. Switching conversations
|
|
278
282
|
stops following the current answer; the flow keeps running and, with server history,
|
|
279
|
-
its answer is there when you come back.
|
|
283
|
+
its answer is there when you come back. `overRunningTurn` sends while a turn is still
|
|
284
|
+
followed: the server takes the message when that turn's AI agent is parked (it answered while
|
|
285
|
+
background jobs run, or waits on an approval or a question), ending that turn and carrying its
|
|
286
|
+
background jobs over, and the chat follows the new one; while the turn works it is refused with a
|
|
287
|
+
`TurnRunningError` and the chat keeps following it.
|
|
280
288
|
|
|
281
289
|
## Attachments
|
|
282
290
|
|
package/dist/ai-sdk.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_follow = require("./follow-
|
|
2
|
+
const require_follow = require("./follow-4zitFXAj.cjs");
|
|
3
3
|
//#region src/ai-sdk.ts
|
|
4
4
|
/**
|
|
5
5
|
* A Vercel AI SDK `ChatTransport` over a chat-mode flow: `useChat({ transport })`
|
package/dist/ai-sdk.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as _assertClassBrand, S as _classPrivateFieldSet2, T as _classPrivateMethodInitSpec, _ as WindmillApiError, a as errorResultMessage, c as isErrorResult, d as randomId, o as extractChatAnswer, r as conversationIdFor, s as isAbortError, t as followJob, u as parseJsonOr, v as WindmillChatApi, w as _classPrivateFieldInitSpec, x as _classPrivateFieldGet2 } from "./follow-
|
|
1
|
+
import { C as _assertClassBrand, S as _classPrivateFieldSet2, T as _classPrivateMethodInitSpec, _ as WindmillApiError, a as errorResultMessage, c as isErrorResult, d as randomId, o as extractChatAnswer, r as conversationIdFor, s as isAbortError, t as followJob, u as parseJsonOr, v as WindmillChatApi, w as _classPrivateFieldInitSpec, x as _classPrivateFieldGet2 } from "./follow-BiGZzxuz.js";
|
|
2
2
|
//#region src/ai-sdk.ts
|
|
3
3
|
/**
|
|
4
4
|
* A Vercel AI SDK `ChatTransport` over a chat-mode flow: `useChat({ transport })`
|
package/dist/assistant-ui.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_follow = require("./follow-
|
|
2
|
+
const require_follow = require("./follow-4zitFXAj.cjs");
|
|
3
3
|
const require_react = require("./react.cjs");
|
|
4
4
|
let _assistant_ui_react = require("@assistant-ui/react");
|
|
5
5
|
let react = require("react");
|
package/dist/assistant-ui.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { u as parseJsonOr } from "./follow-
|
|
1
|
+
import { u as parseJsonOr } from "./follow-BiGZzxuz.js";
|
|
2
2
|
import { useWindmillChat } from "./react.js";
|
|
3
3
|
import { useExternalStoreRuntime } from "@assistant-ui/react";
|
|
4
4
|
import { useEffect, useMemo } from "react";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_follow = require("./follow-
|
|
1
|
+
const require_follow = require("./follow-4zitFXAj.cjs");
|
|
2
2
|
//#region src/runnable.ts
|
|
3
3
|
/**
|
|
4
4
|
* `run` and `follow` over a raw app's chat runnable (a saved AI agent, or a flow in chat mode),
|
|
@@ -265,6 +265,7 @@ var _local = /* @__PURE__ */ new WeakMap();
|
|
|
265
265
|
var _listeners = /* @__PURE__ */ new WeakMap();
|
|
266
266
|
var _state = /* @__PURE__ */ new WeakMap();
|
|
267
267
|
var _turn = /* @__PURE__ */ new WeakMap();
|
|
268
|
+
var _sentOver = /* @__PURE__ */ new WeakMap();
|
|
268
269
|
var _page = /* @__PURE__ */ new WeakMap();
|
|
269
270
|
var _conversationKind = /* @__PURE__ */ new WeakMap();
|
|
270
271
|
var _persistTimer = /* @__PURE__ */ new WeakMap();
|
|
@@ -280,6 +281,7 @@ var ChatImpl = class {
|
|
|
280
281
|
require_follow._classPrivateFieldInitSpec(this, _listeners, /* @__PURE__ */ new Set());
|
|
281
282
|
require_follow._classPrivateFieldInitSpec(this, _state, void 0);
|
|
282
283
|
require_follow._classPrivateFieldInitSpec(this, _turn, void 0);
|
|
284
|
+
require_follow._classPrivateFieldInitSpec(this, _sentOver, void 0);
|
|
283
285
|
require_follow._classPrivateFieldInitSpec(this, _page, 1);
|
|
284
286
|
require_follow._classPrivateFieldInitSpec(this, _conversationKind, void 0);
|
|
285
287
|
require_follow._classPrivateFieldInitSpec(this, _persistTimer, void 0);
|
|
@@ -294,13 +296,15 @@ var ChatImpl = class {
|
|
|
294
296
|
};
|
|
295
297
|
};
|
|
296
298
|
this.sendMessage = async (text, options = {}) => {
|
|
297
|
-
var _this$epoch;
|
|
298
299
|
const content = text.trim();
|
|
299
300
|
if (!content) {
|
|
300
301
|
if (options.attachments?.length) throw new Error("windmill-chat: attachments need a message to go with them");
|
|
301
302
|
return;
|
|
302
303
|
}
|
|
303
|
-
|
|
304
|
+
const running = require_follow._classPrivateFieldGet2(_turn, this);
|
|
305
|
+
if (running && !options.overRunningTurn) throw new Error("windmill-chat: a message is already being answered; call stop() first");
|
|
306
|
+
if (running && options.attachments?.length) throw new Error("windmill-chat: attachments cannot be sent over a running turn");
|
|
307
|
+
if (require_follow._classPrivateFieldGet2(_sentOver, this)) throw new Error("windmill-chat: a message sent over the running turn is still waiting for the server");
|
|
304
308
|
const attachments = options.attachments ?? [];
|
|
305
309
|
const attachmentsInput = options.attachmentsInput;
|
|
306
310
|
if (attachments.length > 0 && !attachmentsInput) throw new Error("windmill-chat: attachments need `attachmentsInput`, the flow input that takes them");
|
|
@@ -317,8 +321,11 @@ var ChatImpl = class {
|
|
|
317
321
|
withdrawn: false,
|
|
318
322
|
streamedText: false
|
|
319
323
|
};
|
|
320
|
-
|
|
321
|
-
|
|
324
|
+
if (!running) {
|
|
325
|
+
var _this$epoch;
|
|
326
|
+
require_follow._classPrivateFieldSet2(_turn, this, turn);
|
|
327
|
+
require_follow._classPrivateFieldSet2(_epoch, this, (_this$epoch = require_follow._classPrivateFieldGet2(_epoch, this), _this$epoch++, _this$epoch));
|
|
328
|
+
}
|
|
322
329
|
const timestamp = require_follow.now();
|
|
323
330
|
const touched = {
|
|
324
331
|
...require_follow._classPrivateFieldGet2(_state, this).conversations.find((c) => c.id === conversationId) ?? {
|
|
@@ -339,8 +346,10 @@ var ChatImpl = class {
|
|
|
339
346
|
createdAt: timestamp,
|
|
340
347
|
pending: true
|
|
341
348
|
}],
|
|
342
|
-
|
|
343
|
-
|
|
349
|
+
...running ? {} : {
|
|
350
|
+
status: "submitted",
|
|
351
|
+
error: void 0
|
|
352
|
+
}
|
|
344
353
|
});
|
|
345
354
|
try {
|
|
346
355
|
const args = {
|
|
@@ -370,10 +379,15 @@ var ChatImpl = class {
|
|
|
370
379
|
conversationId,
|
|
371
380
|
signal: turn.controller.signal
|
|
372
381
|
};
|
|
382
|
+
if (running) require_follow._classPrivateFieldSet2(_sentOver, this, turn);
|
|
373
383
|
turn.jobId = require_follow._classPrivateFieldGet2(_config, this).run ? await require_follow._classPrivateFieldGet2(_config, this).run(args, context) : await require_follow._classPrivateFieldGet2(_api, this).runFlow(require_follow._classPrivateFieldGet2(_config, this).flowPath, args, context);
|
|
384
|
+
if (running && turn.controller.signal.aborted) {
|
|
385
|
+
if (turn.stopped && !require_follow._classPrivateFieldGet2(_config, this).follow) await require_follow._classPrivateFieldGet2(_api, this).cancelJob(turn.jobId).catch(() => {});
|
|
386
|
+
throw require_follow.abortError();
|
|
387
|
+
}
|
|
374
388
|
} catch (e) {
|
|
375
389
|
try {
|
|
376
|
-
if (e instanceof require_follow.TurnRunningError || !turn.started) {
|
|
390
|
+
if (e instanceof require_follow.TurnRunningError || !turn.started || running) {
|
|
377
391
|
require_follow._assertClassBrand(_ChatImpl_brand, this, _withdrawTurn).call(this, turn);
|
|
378
392
|
throw e;
|
|
379
393
|
}
|
|
@@ -383,11 +397,35 @@ var ChatImpl = class {
|
|
|
383
397
|
} finally {
|
|
384
398
|
if (require_follow._classPrivateFieldGet2(_turn, this) === turn) require_follow._classPrivateFieldSet2(_turn, this, void 0);
|
|
385
399
|
}
|
|
400
|
+
} finally {
|
|
401
|
+
if (require_follow._classPrivateFieldGet2(_sentOver, this) === turn) require_follow._classPrivateFieldSet2(_sentOver, this, void 0);
|
|
402
|
+
}
|
|
403
|
+
if (running) {
|
|
404
|
+
var _this$epoch3;
|
|
405
|
+
if (require_follow._classPrivateFieldGet2(_state, this).conversationId !== conversationId) return;
|
|
406
|
+
if (require_follow._classPrivateFieldGet2(_turn, this)) require_follow._assertClassBrand(_ChatImpl_brand, this, _detachTurn).call(this);
|
|
407
|
+
require_follow._classPrivateFieldSet2(_turn, this, turn);
|
|
408
|
+
require_follow._classPrivateFieldSet2(_epoch, this, (_this$epoch3 = require_follow._classPrivateFieldGet2(_epoch, this), _this$epoch3++, _this$epoch3));
|
|
409
|
+
const oldTurnStart = lastUserBefore(require_follow._classPrivateFieldGet2(_state, this).messages, turn.userMessageId);
|
|
410
|
+
require_follow._assertClassBrand(_ChatImpl_brand, this, _set).call(this, {
|
|
411
|
+
messages: require_follow._classPrivateFieldGet2(_state, this).messages.map((m, j) => {
|
|
412
|
+
if (m.role === "tool" && m.tool?.status === "running") return j > oldTurnStart ? {
|
|
413
|
+
...m,
|
|
414
|
+
pending: true
|
|
415
|
+
} : m;
|
|
416
|
+
return m.pending && m.id !== turn.userMessageId ? {
|
|
417
|
+
...m,
|
|
418
|
+
pending: false
|
|
419
|
+
} : m;
|
|
420
|
+
}),
|
|
421
|
+
status: "submitted",
|
|
422
|
+
error: void 0
|
|
423
|
+
});
|
|
386
424
|
}
|
|
387
425
|
await require_follow._assertClassBrand(_ChatImpl_brand, this, _followTurn).call(this, turn, isNew);
|
|
388
426
|
};
|
|
389
427
|
this.resumeTurn = async ({ jobId, userSeq }) => {
|
|
390
|
-
var _this$
|
|
428
|
+
var _this$epoch5;
|
|
391
429
|
const conversationId = require_follow._classPrivateFieldGet2(_state, this).conversationId;
|
|
392
430
|
if (!conversationId || require_follow._classPrivateFieldGet2(_turn, this)) return;
|
|
393
431
|
if (require_follow._classPrivateFieldGet2(_state, this).history !== "server") {
|
|
@@ -405,7 +443,7 @@ var ChatImpl = class {
|
|
|
405
443
|
streamedText: false
|
|
406
444
|
};
|
|
407
445
|
require_follow._classPrivateFieldSet2(_turn, this, turn);
|
|
408
|
-
require_follow._classPrivateFieldSet2(_epoch, this, (_this$
|
|
446
|
+
require_follow._classPrivateFieldSet2(_epoch, this, (_this$epoch5 = require_follow._classPrivateFieldGet2(_epoch, this), _this$epoch5++, _this$epoch5));
|
|
409
447
|
require_follow._assertClassBrand(_ChatImpl_brand, this, _set).call(this, {
|
|
410
448
|
status: "submitted",
|
|
411
449
|
error: void 0
|
|
@@ -453,6 +491,11 @@ var ChatImpl = class {
|
|
|
453
491
|
await require_follow._assertClassBrand(_ChatImpl_brand, this, _followTurn).call(this, turn, false);
|
|
454
492
|
};
|
|
455
493
|
this.stop = async () => {
|
|
494
|
+
const sentOver = require_follow._classPrivateFieldGet2(_sentOver, this);
|
|
495
|
+
if (sentOver) {
|
|
496
|
+
sentOver.stopped = true;
|
|
497
|
+
sentOver.controller.abort();
|
|
498
|
+
}
|
|
456
499
|
const turn = require_follow._classPrivateFieldGet2(_turn, this);
|
|
457
500
|
if (!turn) return;
|
|
458
501
|
require_follow._assertClassBrand(_ChatImpl_brand, this, _detachTurn).call(this);
|
|
@@ -627,7 +670,10 @@ async function _followTurn(turn, isNew) {
|
|
|
627
670
|
require_follow._assertClassBrand(_ChatImpl_brand, this, _failTurn).call(this, turn, e);
|
|
628
671
|
} finally {
|
|
629
672
|
if (require_follow._classPrivateFieldGet2(_turn, this) === turn) require_follow._classPrivateFieldSet2(_turn, this, void 0);
|
|
630
|
-
if (require_follow._classPrivateFieldGet2(_state, this).runningJobId === turn.jobId) require_follow._assertClassBrand(_ChatImpl_brand, this, _set).call(this, {
|
|
673
|
+
if (require_follow._classPrivateFieldGet2(_state, this).runningJobId === turn.jobId) require_follow._assertClassBrand(_ChatImpl_brand, this, _set).call(this, {
|
|
674
|
+
runningJobId: void 0,
|
|
675
|
+
waitingOnBackground: void 0
|
|
676
|
+
});
|
|
631
677
|
}
|
|
632
678
|
if (nextTurn) await this.resumeTurn(nextTurn);
|
|
633
679
|
}
|
|
@@ -725,12 +771,14 @@ function _applyEvents(turn, events) {
|
|
|
725
771
|
let messages = [...require_follow._classPrivateFieldGet2(_state, this).messages];
|
|
726
772
|
const upsertTool = (callId, name, patch) => {
|
|
727
773
|
const { content, success, ...toolPatch } = patch;
|
|
728
|
-
|
|
774
|
+
let asked = messages.length - 1;
|
|
775
|
+
while (asked >= 0 && messages[asked].role !== "user") asked--;
|
|
776
|
+
const i = messages.findIndex((m, j) => (m.pending || j > asked) && m.role === "tool" && m.tool?.callId === callId);
|
|
729
777
|
if (i >= 0) {
|
|
730
778
|
const existing = messages[i];
|
|
731
779
|
messages[i] = {
|
|
732
780
|
...existing,
|
|
733
|
-
content: content ?? existing.content,
|
|
781
|
+
content: existing.seq === void 0 ? content ?? existing.content : existing.content,
|
|
734
782
|
success: success ?? existing.success,
|
|
735
783
|
tool: {
|
|
736
784
|
...existing.tool,
|
|
@@ -780,34 +828,43 @@ function _applyEvents(turn, events) {
|
|
|
780
828
|
});
|
|
781
829
|
}
|
|
782
830
|
};
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
831
|
+
let waitingOnBackground = false;
|
|
832
|
+
for (const event of events) {
|
|
833
|
+
waitingOnBackground = event.type === "background_wait";
|
|
834
|
+
switch (event.type) {
|
|
835
|
+
case "token_delta":
|
|
836
|
+
turn.streamedText = true;
|
|
837
|
+
appendAssistant(event.content, "");
|
|
838
|
+
break;
|
|
839
|
+
case "reasoning_token_delta":
|
|
840
|
+
appendAssistant("", event.content);
|
|
841
|
+
break;
|
|
842
|
+
case "tool_call":
|
|
843
|
+
upsertTool(event.call_id, event.function_name, { status: "running" });
|
|
844
|
+
break;
|
|
845
|
+
case "tool_call_arguments":
|
|
846
|
+
upsertTool(event.call_id, event.function_name, { arguments: event.arguments });
|
|
847
|
+
break;
|
|
848
|
+
case "tool_execution":
|
|
849
|
+
upsertTool(event.call_id, event.function_name, { status: "running" });
|
|
850
|
+
break;
|
|
851
|
+
case "tool_result": upsertTool(event.call_id, event.function_name, {
|
|
852
|
+
status: event.success ? "success" : "error",
|
|
853
|
+
result: event.result,
|
|
854
|
+
success: event.success,
|
|
855
|
+
content: event.success ? `Used ${event.function_name} tool` : `Error executing ${event.function_name}`
|
|
856
|
+
});
|
|
857
|
+
}
|
|
806
858
|
}
|
|
859
|
+
const startsWaiting = waitingOnBackground && !require_follow._classPrivateFieldGet2(_state, this).waitingOnBackground;
|
|
807
860
|
require_follow._assertClassBrand(_ChatImpl_brand, this, _set).call(this, {
|
|
808
861
|
messages,
|
|
809
|
-
status: "streaming"
|
|
862
|
+
status: "streaming",
|
|
863
|
+
waitingOnBackground
|
|
810
864
|
});
|
|
865
|
+
if (startsWaiting && require_follow._classPrivateFieldGet2(_state, this).history === "server") require_follow._assertClassBrand(_ChatImpl_brand, this, _rowsAfterLastSeq).call(this, turn.conversationId, turn.controller.signal).then((rows) => {
|
|
866
|
+
if (require_follow._assertClassBrand(_ChatImpl_brand, this, _turnActive).call(this, turn)) require_follow._assertClassBrand(_ChatImpl_brand, this, _mergeRows).call(this, rows);
|
|
867
|
+
}).catch(() => {});
|
|
811
868
|
}
|
|
812
869
|
async function _finishTurn(turn, result, isNew) {
|
|
813
870
|
if (!require_follow._assertClassBrand(_ChatImpl_brand, this, _turnActive).call(this, turn)) return;
|
|
@@ -1051,7 +1108,8 @@ function _mergeRows(rows) {
|
|
|
1051
1108
|
for (const row of rows.map(fromRow)) {
|
|
1052
1109
|
if (known.has(row.id)) continue;
|
|
1053
1110
|
known.add(row.id);
|
|
1054
|
-
|
|
1111
|
+
const backgroundResult = row.role === "tool" && row.jobId !== void 0 && messages.some((m) => m.seq !== void 0 && m.jobId === row.jobId && BACKGROUND_START.test(m.content));
|
|
1112
|
+
let i = messages.findIndex((m) => !backgroundResult && m.seq === void 0 && m.role === row.role && (m.content === row.content || row.tool !== void 0 && m.tool?.name === row.tool.name));
|
|
1055
1113
|
if (i < 0 && row.role === "assistant") {
|
|
1056
1114
|
let j = messages.length - 1;
|
|
1057
1115
|
while (j >= 0 && messages[j].role !== "user") {
|
|
@@ -1062,15 +1120,17 @@ function _mergeRows(rows) {
|
|
|
1062
1120
|
}
|
|
1063
1121
|
if (i >= 0) {
|
|
1064
1122
|
const m = messages[i];
|
|
1123
|
+
const outrun = row.tool?.status === "running" && !!m.tool && m.tool.status !== "running";
|
|
1065
1124
|
messages[i] = {
|
|
1066
1125
|
...row,
|
|
1067
1126
|
id: m.id,
|
|
1127
|
+
success: outrun ? m.success : row.success,
|
|
1068
1128
|
reasoning: m.reasoning ?? row.reasoning,
|
|
1069
1129
|
tool: row.role === "tool" && m.tool ? {
|
|
1070
1130
|
...m.tool,
|
|
1071
1131
|
arguments: m.tool.arguments ?? row.tool?.arguments,
|
|
1072
1132
|
result: m.tool.result ?? row.tool?.result,
|
|
1073
|
-
status: row.tool?.status ?? m.tool.status
|
|
1133
|
+
status: outrun ? m.tool.status : row.tool?.status ?? m.tool.status
|
|
1074
1134
|
} : row.tool
|
|
1075
1135
|
};
|
|
1076
1136
|
} else {
|
|
@@ -1148,8 +1208,9 @@ function _detachTurn() {
|
|
|
1148
1208
|
* written out now rather than on the debounce that may never fire.
|
|
1149
1209
|
*/
|
|
1150
1210
|
function _leaveConversation() {
|
|
1151
|
-
var _this$
|
|
1152
|
-
require_follow._classPrivateFieldSet2(_epoch, this, (_this$
|
|
1211
|
+
var _this$epoch7;
|
|
1212
|
+
require_follow._classPrivateFieldSet2(_epoch, this, (_this$epoch7 = require_follow._classPrivateFieldGet2(_epoch, this), _this$epoch7++, _this$epoch7));
|
|
1213
|
+
require_follow._classPrivateFieldGet2(_sentOver, this)?.controller.abort();
|
|
1153
1214
|
if (require_follow._classPrivateFieldGet2(_turn, this)) {
|
|
1154
1215
|
require_follow._assertClassBrand(_ChatImpl_brand, this, _detachTurn).call(this);
|
|
1155
1216
|
require_follow._assertClassBrand(_ChatImpl_brand, this, _set).call(this, {
|
|
@@ -1181,8 +1242,10 @@ function lastFailureShown(messages) {
|
|
|
1181
1242
|
function latestSeq(messages) {
|
|
1182
1243
|
return messages.reduce((newest, m) => m.seq !== void 0 && m.seq > newest ? m.seq : newest, 0);
|
|
1183
1244
|
}
|
|
1245
|
+
const BACKGROUND_START = /^(?:Started (.+) in the background|Moved (.+) to the background(?: after \d+s)?)$/;
|
|
1184
1246
|
function fromRow(row) {
|
|
1185
|
-
const
|
|
1247
|
+
const background = row.message_type === "tool" ? BACKGROUND_START.exec(row.content)?.slice(1).find((name) => name !== void 0) : void 0;
|
|
1248
|
+
const toolName = row.message_type === "tool" ? /^Used (.+) tool$/.exec(row.content)?.[1] ?? /^Error executing (.+)$/.exec(row.content)?.[1] ?? background : void 0;
|
|
1186
1249
|
const success = row.success ?? true;
|
|
1187
1250
|
return {
|
|
1188
1251
|
id: row.id,
|
|
@@ -1199,7 +1262,7 @@ function fromRow(row) {
|
|
|
1199
1262
|
attachments: row.attachments ?? void 0,
|
|
1200
1263
|
tool: toolName ? {
|
|
1201
1264
|
name: toolName,
|
|
1202
|
-
status: success ? "success" : "error",
|
|
1265
|
+
status: background ? "running" : success ? "success" : "error",
|
|
1203
1266
|
arguments: row.tool_arguments ?? void 0,
|
|
1204
1267
|
result: row.tool_result ?? void 0
|
|
1205
1268
|
} : void 0
|
|
@@ -1229,6 +1292,13 @@ function assistantMessage(content, success, jobId) {
|
|
|
1229
1292
|
pending: false
|
|
1230
1293
|
};
|
|
1231
1294
|
}
|
|
1295
|
+
/** Index of the latest user message before the one with `id`, the start of the turn it ends. */
|
|
1296
|
+
function lastUserBefore(messages, id) {
|
|
1297
|
+
let j = messages.findIndex((m) => m.id === id);
|
|
1298
|
+
if (j < 0) j = messages.length;
|
|
1299
|
+
while (--j >= 0 && messages[j].role !== "user");
|
|
1300
|
+
return j;
|
|
1301
|
+
}
|
|
1232
1302
|
function finalized(messages) {
|
|
1233
1303
|
return messages.some((m) => m.pending) ? messages.map((m) => m.pending ? {
|
|
1234
1304
|
...m,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as _assertClassBrand, S as _classPrivateFieldSet2, T as _classPrivateMethodInitSpec, _ as WindmillApiError, a as errorResultMessage, b as turnRunningError, c as isErrorResult, d as randomId, f as sleep, g as TurnRunningError, i as conversationTitle, l as now, m as createStreamEventParser, n as abortError, o as extractChatAnswer, p as truncateTitle, s as isAbortError, t as followJob, v as WindmillChatApi, w as _classPrivateFieldInitSpec, x as _classPrivateFieldGet2 } from "./follow-
|
|
1
|
+
import { C as _assertClassBrand, S as _classPrivateFieldSet2, T as _classPrivateMethodInitSpec, _ as WindmillApiError, a as errorResultMessage, b as turnRunningError, c as isErrorResult, d as randomId, f as sleep, g as TurnRunningError, i as conversationTitle, l as now, m as createStreamEventParser, n as abortError, o as extractChatAnswer, p as truncateTitle, s as isAbortError, t as followJob, v as WindmillChatApi, w as _classPrivateFieldInitSpec, x as _classPrivateFieldGet2 } from "./follow-BiGZzxuz.js";
|
|
2
2
|
//#region src/runnable.ts
|
|
3
3
|
/**
|
|
4
4
|
* `run` and `follow` over a raw app's chat runnable (a saved AI agent, or a flow in chat mode),
|
|
@@ -265,6 +265,7 @@ var _local = /* @__PURE__ */ new WeakMap();
|
|
|
265
265
|
var _listeners = /* @__PURE__ */ new WeakMap();
|
|
266
266
|
var _state = /* @__PURE__ */ new WeakMap();
|
|
267
267
|
var _turn = /* @__PURE__ */ new WeakMap();
|
|
268
|
+
var _sentOver = /* @__PURE__ */ new WeakMap();
|
|
268
269
|
var _page = /* @__PURE__ */ new WeakMap();
|
|
269
270
|
var _conversationKind = /* @__PURE__ */ new WeakMap();
|
|
270
271
|
var _persistTimer = /* @__PURE__ */ new WeakMap();
|
|
@@ -280,6 +281,7 @@ var ChatImpl = class {
|
|
|
280
281
|
_classPrivateFieldInitSpec(this, _listeners, /* @__PURE__ */ new Set());
|
|
281
282
|
_classPrivateFieldInitSpec(this, _state, void 0);
|
|
282
283
|
_classPrivateFieldInitSpec(this, _turn, void 0);
|
|
284
|
+
_classPrivateFieldInitSpec(this, _sentOver, void 0);
|
|
283
285
|
_classPrivateFieldInitSpec(this, _page, 1);
|
|
284
286
|
_classPrivateFieldInitSpec(this, _conversationKind, void 0);
|
|
285
287
|
_classPrivateFieldInitSpec(this, _persistTimer, void 0);
|
|
@@ -294,13 +296,15 @@ var ChatImpl = class {
|
|
|
294
296
|
};
|
|
295
297
|
};
|
|
296
298
|
this.sendMessage = async (text, options = {}) => {
|
|
297
|
-
var _this$epoch;
|
|
298
299
|
const content = text.trim();
|
|
299
300
|
if (!content) {
|
|
300
301
|
if (options.attachments?.length) throw new Error("windmill-chat: attachments need a message to go with them");
|
|
301
302
|
return;
|
|
302
303
|
}
|
|
303
|
-
|
|
304
|
+
const running = _classPrivateFieldGet2(_turn, this);
|
|
305
|
+
if (running && !options.overRunningTurn) throw new Error("windmill-chat: a message is already being answered; call stop() first");
|
|
306
|
+
if (running && options.attachments?.length) throw new Error("windmill-chat: attachments cannot be sent over a running turn");
|
|
307
|
+
if (_classPrivateFieldGet2(_sentOver, this)) throw new Error("windmill-chat: a message sent over the running turn is still waiting for the server");
|
|
304
308
|
const attachments = options.attachments ?? [];
|
|
305
309
|
const attachmentsInput = options.attachmentsInput;
|
|
306
310
|
if (attachments.length > 0 && !attachmentsInput) throw new Error("windmill-chat: attachments need `attachmentsInput`, the flow input that takes them");
|
|
@@ -317,8 +321,11 @@ var ChatImpl = class {
|
|
|
317
321
|
withdrawn: false,
|
|
318
322
|
streamedText: false
|
|
319
323
|
};
|
|
320
|
-
|
|
321
|
-
|
|
324
|
+
if (!running) {
|
|
325
|
+
var _this$epoch;
|
|
326
|
+
_classPrivateFieldSet2(_turn, this, turn);
|
|
327
|
+
_classPrivateFieldSet2(_epoch, this, (_this$epoch = _classPrivateFieldGet2(_epoch, this), _this$epoch++, _this$epoch));
|
|
328
|
+
}
|
|
322
329
|
const timestamp = now();
|
|
323
330
|
const touched = {
|
|
324
331
|
..._classPrivateFieldGet2(_state, this).conversations.find((c) => c.id === conversationId) ?? {
|
|
@@ -339,8 +346,10 @@ var ChatImpl = class {
|
|
|
339
346
|
createdAt: timestamp,
|
|
340
347
|
pending: true
|
|
341
348
|
}],
|
|
342
|
-
|
|
343
|
-
|
|
349
|
+
...running ? {} : {
|
|
350
|
+
status: "submitted",
|
|
351
|
+
error: void 0
|
|
352
|
+
}
|
|
344
353
|
});
|
|
345
354
|
try {
|
|
346
355
|
const args = {
|
|
@@ -370,10 +379,15 @@ var ChatImpl = class {
|
|
|
370
379
|
conversationId,
|
|
371
380
|
signal: turn.controller.signal
|
|
372
381
|
};
|
|
382
|
+
if (running) _classPrivateFieldSet2(_sentOver, this, turn);
|
|
373
383
|
turn.jobId = _classPrivateFieldGet2(_config, this).run ? await _classPrivateFieldGet2(_config, this).run(args, context) : await _classPrivateFieldGet2(_api, this).runFlow(_classPrivateFieldGet2(_config, this).flowPath, args, context);
|
|
384
|
+
if (running && turn.controller.signal.aborted) {
|
|
385
|
+
if (turn.stopped && !_classPrivateFieldGet2(_config, this).follow) await _classPrivateFieldGet2(_api, this).cancelJob(turn.jobId).catch(() => {});
|
|
386
|
+
throw abortError();
|
|
387
|
+
}
|
|
374
388
|
} catch (e) {
|
|
375
389
|
try {
|
|
376
|
-
if (e instanceof TurnRunningError || !turn.started) {
|
|
390
|
+
if (e instanceof TurnRunningError || !turn.started || running) {
|
|
377
391
|
_assertClassBrand(_ChatImpl_brand, this, _withdrawTurn).call(this, turn);
|
|
378
392
|
throw e;
|
|
379
393
|
}
|
|
@@ -383,11 +397,35 @@ var ChatImpl = class {
|
|
|
383
397
|
} finally {
|
|
384
398
|
if (_classPrivateFieldGet2(_turn, this) === turn) _classPrivateFieldSet2(_turn, this, void 0);
|
|
385
399
|
}
|
|
400
|
+
} finally {
|
|
401
|
+
if (_classPrivateFieldGet2(_sentOver, this) === turn) _classPrivateFieldSet2(_sentOver, this, void 0);
|
|
402
|
+
}
|
|
403
|
+
if (running) {
|
|
404
|
+
var _this$epoch3;
|
|
405
|
+
if (_classPrivateFieldGet2(_state, this).conversationId !== conversationId) return;
|
|
406
|
+
if (_classPrivateFieldGet2(_turn, this)) _assertClassBrand(_ChatImpl_brand, this, _detachTurn).call(this);
|
|
407
|
+
_classPrivateFieldSet2(_turn, this, turn);
|
|
408
|
+
_classPrivateFieldSet2(_epoch, this, (_this$epoch3 = _classPrivateFieldGet2(_epoch, this), _this$epoch3++, _this$epoch3));
|
|
409
|
+
const oldTurnStart = lastUserBefore(_classPrivateFieldGet2(_state, this).messages, turn.userMessageId);
|
|
410
|
+
_assertClassBrand(_ChatImpl_brand, this, _set).call(this, {
|
|
411
|
+
messages: _classPrivateFieldGet2(_state, this).messages.map((m, j) => {
|
|
412
|
+
if (m.role === "tool" && m.tool?.status === "running") return j > oldTurnStart ? {
|
|
413
|
+
...m,
|
|
414
|
+
pending: true
|
|
415
|
+
} : m;
|
|
416
|
+
return m.pending && m.id !== turn.userMessageId ? {
|
|
417
|
+
...m,
|
|
418
|
+
pending: false
|
|
419
|
+
} : m;
|
|
420
|
+
}),
|
|
421
|
+
status: "submitted",
|
|
422
|
+
error: void 0
|
|
423
|
+
});
|
|
386
424
|
}
|
|
387
425
|
await _assertClassBrand(_ChatImpl_brand, this, _followTurn).call(this, turn, isNew);
|
|
388
426
|
};
|
|
389
427
|
this.resumeTurn = async ({ jobId, userSeq }) => {
|
|
390
|
-
var _this$
|
|
428
|
+
var _this$epoch5;
|
|
391
429
|
const conversationId = _classPrivateFieldGet2(_state, this).conversationId;
|
|
392
430
|
if (!conversationId || _classPrivateFieldGet2(_turn, this)) return;
|
|
393
431
|
if (_classPrivateFieldGet2(_state, this).history !== "server") {
|
|
@@ -405,7 +443,7 @@ var ChatImpl = class {
|
|
|
405
443
|
streamedText: false
|
|
406
444
|
};
|
|
407
445
|
_classPrivateFieldSet2(_turn, this, turn);
|
|
408
|
-
_classPrivateFieldSet2(_epoch, this, (_this$
|
|
446
|
+
_classPrivateFieldSet2(_epoch, this, (_this$epoch5 = _classPrivateFieldGet2(_epoch, this), _this$epoch5++, _this$epoch5));
|
|
409
447
|
_assertClassBrand(_ChatImpl_brand, this, _set).call(this, {
|
|
410
448
|
status: "submitted",
|
|
411
449
|
error: void 0
|
|
@@ -453,6 +491,11 @@ var ChatImpl = class {
|
|
|
453
491
|
await _assertClassBrand(_ChatImpl_brand, this, _followTurn).call(this, turn, false);
|
|
454
492
|
};
|
|
455
493
|
this.stop = async () => {
|
|
494
|
+
const sentOver = _classPrivateFieldGet2(_sentOver, this);
|
|
495
|
+
if (sentOver) {
|
|
496
|
+
sentOver.stopped = true;
|
|
497
|
+
sentOver.controller.abort();
|
|
498
|
+
}
|
|
456
499
|
const turn = _classPrivateFieldGet2(_turn, this);
|
|
457
500
|
if (!turn) return;
|
|
458
501
|
_assertClassBrand(_ChatImpl_brand, this, _detachTurn).call(this);
|
|
@@ -627,7 +670,10 @@ async function _followTurn(turn, isNew) {
|
|
|
627
670
|
_assertClassBrand(_ChatImpl_brand, this, _failTurn).call(this, turn, e);
|
|
628
671
|
} finally {
|
|
629
672
|
if (_classPrivateFieldGet2(_turn, this) === turn) _classPrivateFieldSet2(_turn, this, void 0);
|
|
630
|
-
if (_classPrivateFieldGet2(_state, this).runningJobId === turn.jobId) _assertClassBrand(_ChatImpl_brand, this, _set).call(this, {
|
|
673
|
+
if (_classPrivateFieldGet2(_state, this).runningJobId === turn.jobId) _assertClassBrand(_ChatImpl_brand, this, _set).call(this, {
|
|
674
|
+
runningJobId: void 0,
|
|
675
|
+
waitingOnBackground: void 0
|
|
676
|
+
});
|
|
631
677
|
}
|
|
632
678
|
if (nextTurn) await this.resumeTurn(nextTurn);
|
|
633
679
|
}
|
|
@@ -725,12 +771,14 @@ function _applyEvents(turn, events) {
|
|
|
725
771
|
let messages = [..._classPrivateFieldGet2(_state, this).messages];
|
|
726
772
|
const upsertTool = (callId, name, patch) => {
|
|
727
773
|
const { content, success, ...toolPatch } = patch;
|
|
728
|
-
|
|
774
|
+
let asked = messages.length - 1;
|
|
775
|
+
while (asked >= 0 && messages[asked].role !== "user") asked--;
|
|
776
|
+
const i = messages.findIndex((m, j) => (m.pending || j > asked) && m.role === "tool" && m.tool?.callId === callId);
|
|
729
777
|
if (i >= 0) {
|
|
730
778
|
const existing = messages[i];
|
|
731
779
|
messages[i] = {
|
|
732
780
|
...existing,
|
|
733
|
-
content: content ?? existing.content,
|
|
781
|
+
content: existing.seq === void 0 ? content ?? existing.content : existing.content,
|
|
734
782
|
success: success ?? existing.success,
|
|
735
783
|
tool: {
|
|
736
784
|
...existing.tool,
|
|
@@ -780,34 +828,43 @@ function _applyEvents(turn, events) {
|
|
|
780
828
|
});
|
|
781
829
|
}
|
|
782
830
|
};
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
831
|
+
let waitingOnBackground = false;
|
|
832
|
+
for (const event of events) {
|
|
833
|
+
waitingOnBackground = event.type === "background_wait";
|
|
834
|
+
switch (event.type) {
|
|
835
|
+
case "token_delta":
|
|
836
|
+
turn.streamedText = true;
|
|
837
|
+
appendAssistant(event.content, "");
|
|
838
|
+
break;
|
|
839
|
+
case "reasoning_token_delta":
|
|
840
|
+
appendAssistant("", event.content);
|
|
841
|
+
break;
|
|
842
|
+
case "tool_call":
|
|
843
|
+
upsertTool(event.call_id, event.function_name, { status: "running" });
|
|
844
|
+
break;
|
|
845
|
+
case "tool_call_arguments":
|
|
846
|
+
upsertTool(event.call_id, event.function_name, { arguments: event.arguments });
|
|
847
|
+
break;
|
|
848
|
+
case "tool_execution":
|
|
849
|
+
upsertTool(event.call_id, event.function_name, { status: "running" });
|
|
850
|
+
break;
|
|
851
|
+
case "tool_result": upsertTool(event.call_id, event.function_name, {
|
|
852
|
+
status: event.success ? "success" : "error",
|
|
853
|
+
result: event.result,
|
|
854
|
+
success: event.success,
|
|
855
|
+
content: event.success ? `Used ${event.function_name} tool` : `Error executing ${event.function_name}`
|
|
856
|
+
});
|
|
857
|
+
}
|
|
806
858
|
}
|
|
859
|
+
const startsWaiting = waitingOnBackground && !_classPrivateFieldGet2(_state, this).waitingOnBackground;
|
|
807
860
|
_assertClassBrand(_ChatImpl_brand, this, _set).call(this, {
|
|
808
861
|
messages,
|
|
809
|
-
status: "streaming"
|
|
862
|
+
status: "streaming",
|
|
863
|
+
waitingOnBackground
|
|
810
864
|
});
|
|
865
|
+
if (startsWaiting && _classPrivateFieldGet2(_state, this).history === "server") _assertClassBrand(_ChatImpl_brand, this, _rowsAfterLastSeq).call(this, turn.conversationId, turn.controller.signal).then((rows) => {
|
|
866
|
+
if (_assertClassBrand(_ChatImpl_brand, this, _turnActive).call(this, turn)) _assertClassBrand(_ChatImpl_brand, this, _mergeRows).call(this, rows);
|
|
867
|
+
}).catch(() => {});
|
|
811
868
|
}
|
|
812
869
|
async function _finishTurn(turn, result, isNew) {
|
|
813
870
|
if (!_assertClassBrand(_ChatImpl_brand, this, _turnActive).call(this, turn)) return;
|
|
@@ -1051,7 +1108,8 @@ function _mergeRows(rows) {
|
|
|
1051
1108
|
for (const row of rows.map(fromRow)) {
|
|
1052
1109
|
if (known.has(row.id)) continue;
|
|
1053
1110
|
known.add(row.id);
|
|
1054
|
-
|
|
1111
|
+
const backgroundResult = row.role === "tool" && row.jobId !== void 0 && messages.some((m) => m.seq !== void 0 && m.jobId === row.jobId && BACKGROUND_START.test(m.content));
|
|
1112
|
+
let i = messages.findIndex((m) => !backgroundResult && m.seq === void 0 && m.role === row.role && (m.content === row.content || row.tool !== void 0 && m.tool?.name === row.tool.name));
|
|
1055
1113
|
if (i < 0 && row.role === "assistant") {
|
|
1056
1114
|
let j = messages.length - 1;
|
|
1057
1115
|
while (j >= 0 && messages[j].role !== "user") {
|
|
@@ -1062,15 +1120,17 @@ function _mergeRows(rows) {
|
|
|
1062
1120
|
}
|
|
1063
1121
|
if (i >= 0) {
|
|
1064
1122
|
const m = messages[i];
|
|
1123
|
+
const outrun = row.tool?.status === "running" && !!m.tool && m.tool.status !== "running";
|
|
1065
1124
|
messages[i] = {
|
|
1066
1125
|
...row,
|
|
1067
1126
|
id: m.id,
|
|
1127
|
+
success: outrun ? m.success : row.success,
|
|
1068
1128
|
reasoning: m.reasoning ?? row.reasoning,
|
|
1069
1129
|
tool: row.role === "tool" && m.tool ? {
|
|
1070
1130
|
...m.tool,
|
|
1071
1131
|
arguments: m.tool.arguments ?? row.tool?.arguments,
|
|
1072
1132
|
result: m.tool.result ?? row.tool?.result,
|
|
1073
|
-
status: row.tool?.status ?? m.tool.status
|
|
1133
|
+
status: outrun ? m.tool.status : row.tool?.status ?? m.tool.status
|
|
1074
1134
|
} : row.tool
|
|
1075
1135
|
};
|
|
1076
1136
|
} else {
|
|
@@ -1148,8 +1208,9 @@ function _detachTurn() {
|
|
|
1148
1208
|
* written out now rather than on the debounce that may never fire.
|
|
1149
1209
|
*/
|
|
1150
1210
|
function _leaveConversation() {
|
|
1151
|
-
var _this$
|
|
1152
|
-
_classPrivateFieldSet2(_epoch, this, (_this$
|
|
1211
|
+
var _this$epoch7;
|
|
1212
|
+
_classPrivateFieldSet2(_epoch, this, (_this$epoch7 = _classPrivateFieldGet2(_epoch, this), _this$epoch7++, _this$epoch7));
|
|
1213
|
+
_classPrivateFieldGet2(_sentOver, this)?.controller.abort();
|
|
1153
1214
|
if (_classPrivateFieldGet2(_turn, this)) {
|
|
1154
1215
|
_assertClassBrand(_ChatImpl_brand, this, _detachTurn).call(this);
|
|
1155
1216
|
_assertClassBrand(_ChatImpl_brand, this, _set).call(this, {
|
|
@@ -1181,8 +1242,10 @@ function lastFailureShown(messages) {
|
|
|
1181
1242
|
function latestSeq(messages) {
|
|
1182
1243
|
return messages.reduce((newest, m) => m.seq !== void 0 && m.seq > newest ? m.seq : newest, 0);
|
|
1183
1244
|
}
|
|
1245
|
+
const BACKGROUND_START = /^(?:Started (.+) in the background|Moved (.+) to the background(?: after \d+s)?)$/;
|
|
1184
1246
|
function fromRow(row) {
|
|
1185
|
-
const
|
|
1247
|
+
const background = row.message_type === "tool" ? BACKGROUND_START.exec(row.content)?.slice(1).find((name) => name !== void 0) : void 0;
|
|
1248
|
+
const toolName = row.message_type === "tool" ? /^Used (.+) tool$/.exec(row.content)?.[1] ?? /^Error executing (.+)$/.exec(row.content)?.[1] ?? background : void 0;
|
|
1186
1249
|
const success = row.success ?? true;
|
|
1187
1250
|
return {
|
|
1188
1251
|
id: row.id,
|
|
@@ -1199,7 +1262,7 @@ function fromRow(row) {
|
|
|
1199
1262
|
attachments: row.attachments ?? void 0,
|
|
1200
1263
|
tool: toolName ? {
|
|
1201
1264
|
name: toolName,
|
|
1202
|
-
status: success ? "success" : "error",
|
|
1265
|
+
status: background ? "running" : success ? "success" : "error",
|
|
1203
1266
|
arguments: row.tool_arguments ?? void 0,
|
|
1204
1267
|
result: row.tool_result ?? void 0
|
|
1205
1268
|
} : void 0
|
|
@@ -1229,6 +1292,13 @@ function assistantMessage(content, success, jobId) {
|
|
|
1229
1292
|
pending: false
|
|
1230
1293
|
};
|
|
1231
1294
|
}
|
|
1295
|
+
/** Index of the latest user message before the one with `id`, the start of the turn it ends. */
|
|
1296
|
+
function lastUserBefore(messages, id) {
|
|
1297
|
+
let j = messages.findIndex((m) => m.id === id);
|
|
1298
|
+
if (j < 0) j = messages.length;
|
|
1299
|
+
while (--j >= 0 && messages[j].role !== "user");
|
|
1300
|
+
return j;
|
|
1301
|
+
}
|
|
1232
1302
|
function finalized(messages) {
|
|
1233
1303
|
return messages.some((m) => m.pending) ? messages.map((m) => m.pending ? {
|
|
1234
1304
|
...m,
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_follow = require("./follow-
|
|
3
|
-
const require_chat = require("./chat-
|
|
2
|
+
const require_follow = require("./follow-4zitFXAj.cjs");
|
|
3
|
+
const require_chat = require("./chat-BB4qQwLO.cjs");
|
|
4
4
|
exports.CHAT_UPLOADS_PREFIX = require_chat.CHAT_UPLOADS_PREFIX;
|
|
5
5
|
exports.TurnRunningError = require_follow.TurnRunningError;
|
|
6
6
|
exports.WindmillApiError = require_follow.WindmillApiError;
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { _ as WindmillApiError, b as turnRunningError, g as TurnRunningError, h as parseStreamEvents, m as createStreamEventParser, o as extractChatAnswer, r as conversationIdFor, t as followJob, v as WindmillChatApi, y as readServerSentEvents } from "./follow-
|
|
2
|
-
import { a as detectRawApp, i as uploadAttachments, n as CHAT_UPLOADS_PREFIX, r as storedAttachmentName, t as createChat } from "./chat-
|
|
1
|
+
import { _ as WindmillApiError, b as turnRunningError, g as TurnRunningError, h as parseStreamEvents, m as createStreamEventParser, o as extractChatAnswer, r as conversationIdFor, t as followJob, v as WindmillChatApi, y as readServerSentEvents } from "./follow-BiGZzxuz.js";
|
|
2
|
+
import { a as detectRawApp, i as uploadAttachments, n as CHAT_UPLOADS_PREFIX, r as storedAttachmentName, t as createChat } from "./chat-BD65QCxW.js";
|
|
3
3
|
export { CHAT_UPLOADS_PREFIX, TurnRunningError, WindmillApiError, WindmillChatApi, conversationIdFor, createChat, createStreamEventParser, detectRawApp, extractChatAnswer, followJob, parseStreamEvents, readServerSentEvents, storedAttachmentName, turnRunningError, uploadAttachments };
|
package/dist/react.cjs
CHANGED
package/dist/react.js
CHANGED
package/dist/stream.d.ts
CHANGED
|
@@ -24,6 +24,10 @@ export type AgentStreamEvent = {
|
|
|
24
24
|
function_name: string;
|
|
25
25
|
result: string;
|
|
26
26
|
success: boolean;
|
|
27
|
+
}
|
|
28
|
+
/** The agent answered and waits on tools still running in the background. */
|
|
29
|
+
| {
|
|
30
|
+
type: 'background_wait';
|
|
27
31
|
};
|
|
28
32
|
/**
|
|
29
33
|
* Incremental parser for the `new_result_stream` chunks of a job update. A chunk is
|
package/dist/types.d.ts
CHANGED
|
@@ -79,6 +79,12 @@ export interface ChatState {
|
|
|
79
79
|
hasMoreMessages: boolean;
|
|
80
80
|
/** The flow job the running turn follows, once it is known. */
|
|
81
81
|
runningJobId?: string;
|
|
82
|
+
/**
|
|
83
|
+
* The running turn's AI agent has answered and waits, without a worker, on tools still running
|
|
84
|
+
* in the background: nothing streams until one finishes. Set by its `background_wait` event,
|
|
85
|
+
* cleared by the next event and when the turn ends.
|
|
86
|
+
*/
|
|
87
|
+
waitingOnBackground?: boolean;
|
|
82
88
|
}
|
|
83
89
|
export type TokenSource = string | (() => string | Promise<string>);
|
|
84
90
|
export type StorageLike = Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>;
|
|
@@ -200,6 +206,15 @@ export interface SendMessageOptions {
|
|
|
200
206
|
attachments?: AttachmentUpload[];
|
|
201
207
|
/** Required with `attachments`, which also need message text. With `multiple: false`, more than one attachment is refused before anything uploads. */
|
|
202
208
|
attachmentsInput?: AttachmentsInput;
|
|
209
|
+
/**
|
|
210
|
+
* Send although the chat is still following a turn. The server takes the message when that
|
|
211
|
+
* turn's AI agent is parked (it answered while background jobs run, or waits on an approval or
|
|
212
|
+
* a question): it ends that turn, dropping its open request, and carries its background jobs
|
|
213
|
+
* over to this one, which the chat then follows. While the turn works it is refused with a
|
|
214
|
+
* `TurnRunningError` and the chat keeps following it. Not with `attachments`, and one at a time:
|
|
215
|
+
* a second one is refused while the first waits for the server.
|
|
216
|
+
*/
|
|
217
|
+
overRunningTurn?: boolean;
|
|
203
218
|
}
|
|
204
219
|
export interface Chat {
|
|
205
220
|
getState(): ChatState;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@windmill-labs/chat-sdk",
|
|
3
3
|
"description": "Build chat interfaces on Windmill flows deployed in chat mode, from any frontend or raw app",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.873.0",
|
|
5
5
|
"author": "Ruben Fiszel",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"homepage": "https://github.com/windmill-labs/windmill/tree/main/chat-sdk#readme",
|