@windmill-labs/chat-sdk 1.849.0 → 1.851.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 CHANGED
@@ -177,9 +177,9 @@ history, so two agent runnables in one app keep separate conversations. Going th
177
177
  `wmill.ts` is what makes the same code work in a deployed app and under `wmill app dev`.
178
178
 
179
179
  `createChat` and the assistant-ui runtime take the same options; the AI SDK transport
180
- does not. The runnable takes `user_message` and `memory_id`, the conversation id, which
181
- the agent's memory is keyed by, so it remembers earlier turns (called from `wmill.ts`
182
- without `memory_id`, it is a single run with no conversation). The agent needs managed
180
+ does not. The runnable takes `user_message`, and the chat passes the conversation id as
181
+ `backendAsync`'s `memoryId` option, which the agent's memory is keyed by, so it remembers
182
+ earlier turns (called from `wmill.ts` without it, it is a single run with no conversation). The agent needs managed
183
183
  memory: one whose memory is off takes `previous_messages` instead, the history you keep. A signed-in viewer's turns
184
184
  are filed under them, so nobody else can continue their conversations; an anonymous
185
185
  visitor's are kept apart per app. The chat makes no request of its own: history is
@@ -244,6 +244,7 @@ interface ChatState {
244
244
  history: 'server' | 'local' | 'none'
245
245
  loadingMessages: boolean
246
246
  hasMoreMessages: boolean
247
+ runningJobId?: string // the flow job the running turn follows
247
248
  }
248
249
 
249
250
  interface ChatMessage {
@@ -1,18 +1,15 @@
1
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-DXfmfPfr.js";
2
2
  //#region src/runnable.ts
3
3
  /**
4
- * `run` and `follow` over a raw app's agent runnable (a path runnable of type `agent`, naming
5
- * a saved AI agent), behind the `runnable` option. `memory_id` is the conversation id, the
6
- * agent's memory key.
4
+ * `run` and `follow` over a raw app's chat runnable (a saved AI agent, or a flow in chat mode),
5
+ * behind the `runnable` option. The conversation id goes as `memoryId`, the run's `memory_id`
6
+ * query parameter, which keys the conversation and its memory.
7
7
  */
8
8
  function rawAppRunnable(start, streamJob) {
9
9
  return {
10
10
  run: async (args, { conversationId }) => {
11
11
  try {
12
- return String(await start({
13
- ...args,
14
- memory_id: conversationId
15
- }));
12
+ return String(await start(args, { memoryId: conversationId }));
16
13
  } catch (e) {
17
14
  const text = e instanceof Error ? e.message : String(e);
18
15
  throw turnRunningError(text.slice(text.indexOf("{"), text.lastIndexOf("}") + 1)) ?? e;
@@ -610,6 +607,7 @@ var ChatImpl = class {
610
607
  };
611
608
  async function _followTurn(turn, isNew) {
612
609
  let nextTurn;
610
+ _assertClassBrand(_ChatImpl_brand, this, _set).call(this, { runningJobId: turn.jobId });
613
611
  try {
614
612
  const stopPolling = _classPrivateFieldGet2(_state, this).history === "server" ? _assertClassBrand(_ChatImpl_brand, this, _startPolling).call(this, turn) : () => {};
615
613
  let result;
@@ -629,6 +627,7 @@ async function _followTurn(turn, isNew) {
629
627
  _assertClassBrand(_ChatImpl_brand, this, _failTurn).call(this, turn, e);
630
628
  } finally {
631
629
  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, { runningJobId: void 0 });
632
631
  }
633
632
  if (nextTurn) await this.resumeTurn(nextTurn);
634
633
  }
@@ -1,18 +1,15 @@
1
1
  const require_follow = require("./follow-Dug-Afeu.cjs");
2
2
  //#region src/runnable.ts
3
3
  /**
4
- * `run` and `follow` over a raw app's agent runnable (a path runnable of type `agent`, naming
5
- * a saved AI agent), behind the `runnable` option. `memory_id` is the conversation id, the
6
- * agent's memory key.
4
+ * `run` and `follow` over a raw app's chat runnable (a saved AI agent, or a flow in chat mode),
5
+ * behind the `runnable` option. The conversation id goes as `memoryId`, the run's `memory_id`
6
+ * query parameter, which keys the conversation and its memory.
7
7
  */
8
8
  function rawAppRunnable(start, streamJob) {
9
9
  return {
10
10
  run: async (args, { conversationId }) => {
11
11
  try {
12
- return String(await start({
13
- ...args,
14
- memory_id: conversationId
15
- }));
12
+ return String(await start(args, { memoryId: conversationId }));
16
13
  } catch (e) {
17
14
  const text = e instanceof Error ? e.message : String(e);
18
15
  throw require_follow.turnRunningError(text.slice(text.indexOf("{"), text.lastIndexOf("}") + 1)) ?? e;
@@ -610,6 +607,7 @@ var ChatImpl = class {
610
607
  };
611
608
  async function _followTurn(turn, isNew) {
612
609
  let nextTurn;
610
+ require_follow._assertClassBrand(_ChatImpl_brand, this, _set).call(this, { runningJobId: turn.jobId });
613
611
  try {
614
612
  const stopPolling = require_follow._classPrivateFieldGet2(_state, this).history === "server" ? require_follow._assertClassBrand(_ChatImpl_brand, this, _startPolling).call(this, turn) : () => {};
615
613
  let result;
@@ -629,6 +627,7 @@ async function _followTurn(turn, isNew) {
629
627
  require_follow._assertClassBrand(_ChatImpl_brand, this, _failTurn).call(this, turn, e);
630
628
  } finally {
631
629
  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, { runningJobId: void 0 });
632
631
  }
633
632
  if (nextTurn) await this.resumeTurn(nextTurn);
634
633
  }
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_follow = require("./follow-Dug-Afeu.cjs");
3
- const require_chat = require("./chat-C0iOSX6H.cjs");
3
+ const require_chat = require("./chat-pUgtVqWV.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
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-DXfmfPfr.js";
2
- import { a as detectRawApp, i as uploadAttachments, n as CHAT_UPLOADS_PREFIX, r as storedAttachmentName, t as createChat } from "./chat-DjonfE4j.js";
2
+ import { a as detectRawApp, i as uploadAttachments, n as CHAT_UPLOADS_PREFIX, r as storedAttachmentName, t as createChat } from "./chat-D5SvCHXU.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
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_chat = require("./chat-C0iOSX6H.cjs");
2
+ const require_chat = require("./chat-pUgtVqWV.cjs");
3
3
  let react = require("react");
4
4
  //#region src/react.ts
5
5
  /**
package/dist/react.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as createChat } from "./chat-DjonfE4j.js";
1
+ import { t as createChat } from "./chat-D5SvCHXU.js";
2
2
  import { useEffect, useMemo, useRef, useSyncExternalStore } from "react";
3
3
  //#region src/react.ts
4
4
  /**
@@ -1,9 +1,11 @@
1
1
  import type { ChatOptions } from './types';
2
2
  /**
3
- * `run` and `follow` over a raw app's agent runnable (a path runnable of type `agent`, naming
4
- * a saved AI agent), behind the `runnable` option. `memory_id` is the conversation id, the
5
- * agent's memory key.
3
+ * `run` and `follow` over a raw app's chat runnable (a saved AI agent, or a flow in chat mode),
4
+ * behind the `runnable` option. The conversation id goes as `memoryId`, the run's `memory_id`
5
+ * query parameter, which keys the conversation and its memory.
6
6
  */
7
- export declare function rawAppRunnable(start: (args: any) => Promise<string>, streamJob: (jobId: string, onUpdate?: (update: {
7
+ export declare function rawAppRunnable(start: (args: any, opts: {
8
+ memoryId: string;
9
+ }) => Promise<string>, streamJob: (jobId: string, onUpdate?: (update: {
8
10
  new_result_stream?: string;
9
11
  }) => void) => Promise<unknown>): Required<Pick<ChatOptions, 'run' | 'follow'>>;
package/dist/types.d.ts CHANGED
@@ -77,6 +77,8 @@ export interface ChatState {
77
77
  history: HistoryMode;
78
78
  loadingMessages: boolean;
79
79
  hasMoreMessages: boolean;
80
+ /** The flow job the running turn follows, once it is known. */
81
+ runningJobId?: string;
80
82
  }
81
83
  export type TokenSource = string | (() => string | Promise<string>);
82
84
  export type StorageLike = Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>;
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.849.0",
4
+ "version": "1.851.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",