@assistant-ui/react 0.5.96 → 0.5.97

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,14 +4,33 @@ import { ThreadRuntime, ThreadRuntimeCoreBinding } from "./ThreadRuntime";
4
4
  import { Unsubscribe } from "../types";
5
5
  import { ThreadManagerRuntime, ThreadManagerRuntimeImpl } from "./ThreadManagerRuntime";
6
6
  export type AssistantRuntime = {
7
+ /**
8
+ * The currently selected main thread.
9
+ */
7
10
  thread: ThreadRuntime;
11
+ /**
12
+ * The thread manager, to rename, archive and delete threads.
13
+ */
8
14
  threadManager: ThreadManagerRuntime;
15
+ /**
16
+ * Switch to a new thread.
17
+ */
9
18
  switchToNewThread(): void;
19
+ /**
20
+ * Switch to a thread.
21
+ *
22
+ * @param threadId The thread ID to switch to.
23
+ */
10
24
  switchToThread(threadId: string): void;
11
25
  /**
12
26
  * @deprecated Use `switchToNewThread` instead. This will be removed in 0.6.0.
13
27
  */
14
28
  switchToThread(threadId: string | null): void;
29
+ /**
30
+ * Register a model config provider. Model config providers are configuration such as system message, temperature, etc. that are set in the frontend.
31
+ *
32
+ * @param provider The model config provider to register.
33
+ */
15
34
  registerModelConfigProvider(provider: ModelConfigProvider): Unsubscribe;
16
35
  /**
17
36
  * @deprecated Thread is now static and never gets updated. This will be removed in 0.6.0.
@@ -1 +1 @@
1
- {"version":3,"file":"AssistantRuntime.d.ts","sourceRoot":"","sources":["../../src/api/AssistantRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAE7E,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EACL,aAAa,EACb,wBAAwB,EAEzB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACzB,MAAM,wBAAwB,CAAC;AAEhC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,aA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AE,MAAM,GAAG,IAAI,GAAG,IAAI;IAM7C,2BAA2B,CAAC,QAAQ,EAAE,mBAAmB;IAIhE;;OAEG;IACI,SAAS;IAIhB,SAAS,CAAC,MAAM,CAAC,uBAAuB,CACtC,KAAK,EAAE,oBAAoB,EAC3B,mBAAmB,GAAE,KACnB,OAAO,EAAE,wBAAwB,KAC9B,aAAiC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WAc1B,MAAM,CAClB,KAAK,EAAE,oBAAoB,EAC3B,mBAAmB,GAAE,KACnB,OAAO,EAAE,wBAAwB,KAC9B,aAAiC,GAKjC,gBAAgB;CAExB"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/api/AssistantRuntime.ts"],"sourcesContent":["import { AssistantRuntimeCore } from \"../runtimes/core/AssistantRuntimeCore\";\nimport { NestedSubscriptionSubject } from \"./subscribable/NestedSubscriptionSubject\";\nimport { ModelConfigProvider } from \"../types/ModelConfigTypes\";\nimport {\n ThreadRuntime,\n ThreadRuntimeCoreBinding,\n ThreadRuntimeImpl,\n} from \"./ThreadRuntime\";\nimport { Unsubscribe } from \"../types\";\nimport {\n ThreadManagerRuntime,\n ThreadManagerRuntimeImpl,\n} from \"./ThreadManagerRuntime\";\n\nexport type AssistantRuntime = {\n thread: ThreadRuntime;\n threadManager: ThreadManagerRuntime;\n\n switchToNewThread(): void;\n\n switchToThread(threadId: string): void;\n /**\n * @deprecated Use `switchToNewThread` instead. This will be removed in 0.6.0.\n */\n switchToThread(threadId: string | null): void;\n\n registerModelConfigProvider(provider: ModelConfigProvider): Unsubscribe;\n\n /**\n * @deprecated Thread is now static and never gets updated. This will be removed in 0.6.0.\n */\n subscribe(callback: () => void): Unsubscribe;\n};\n\nexport class AssistantRuntimeImpl\n implements\n Omit<AssistantRuntimeCore, \"thread\" | \"threadManager\">,\n AssistantRuntime\n{\n public readonly threadManager;\n\n protected constructor(\n private readonly _core: AssistantRuntimeCore,\n private readonly _thread: ThreadRuntime,\n ) {\n this.threadManager = new ThreadManagerRuntimeImpl(_core.threadManager);\n }\n\n public get thread() {\n return this._thread;\n }\n\n public switchToNewThread() {\n return this._core.threadManager.switchToNewThread();\n }\n\n public switchToThread(threadId: string): void;\n /**\n * @deprecated Use `switchToNewThread` instead. This will be removed in 0.6.0.\n */\n public switchToThread(threadId: string | null): void;\n public switchToThread(threadId: string | null) {\n if (threadId === null) return this.switchToNewThread();\n return this._core.threadManager.switchToThread(threadId);\n }\n\n public registerModelConfigProvider(provider: ModelConfigProvider) {\n return this._core.registerModelConfigProvider(provider);\n }\n\n /**\n * @deprecated Thread is now static and never gets updated. This will be removed in 0.6.0.\n */\n public subscribe() {\n return () => {};\n }\n\n protected static createMainThreadRuntime(\n _core: AssistantRuntimeCore,\n CustomThreadRuntime: new (\n binding: ThreadRuntimeCoreBinding,\n ) => ThreadRuntime = ThreadRuntimeImpl,\n ) {\n return new CustomThreadRuntime(\n new NestedSubscriptionSubject({\n path: {\n ref: \"threads.main\",\n threadSelector: { type: \"main\" },\n },\n getState: () => _core.threadManager.mainThread,\n subscribe: (callback) => _core.threadManager.subscribe(callback),\n }),\n );\n }\n\n public static create(\n _core: AssistantRuntimeCore,\n CustomThreadRuntime: new (\n binding: ThreadRuntimeCoreBinding,\n ) => ThreadRuntime = ThreadRuntimeImpl,\n ) {\n return new AssistantRuntimeImpl(\n _core,\n AssistantRuntimeImpl.createMainThreadRuntime(_core, CustomThreadRuntime),\n ) as AssistantRuntime;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uCAA0C;AAE1C,2BAIO;AAEP,kCAGO;AAsBA,MAAM,qBAIb;AAAA,EAGY,YACS,OACA,SACjB;AAFiB;AACA;AAEjB,SAAK,gBAAgB,IAAI,qDAAyB,MAAM,aAAa;AAAA,EACvE;AAAA,EAPgB;AAAA,EAShB,IAAW,SAAS;AAClB,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,oBAAoB;AACzB,WAAO,KAAK,MAAM,cAAc,kBAAkB;AAAA,EACpD;AAAA,EAOO,eAAe,UAAyB;AAC7C,QAAI,aAAa,KAAM,QAAO,KAAK,kBAAkB;AACrD,WAAO,KAAK,MAAM,cAAc,eAAe,QAAQ;AAAA,EACzD;AAAA,EAEO,4BAA4B,UAA+B;AAChE,WAAO,KAAK,MAAM,4BAA4B,QAAQ;AAAA,EACxD;AAAA;AAAA;AAAA;AAAA,EAKO,YAAY;AACjB,WAAO,MAAM;AAAA,IAAC;AAAA,EAChB;AAAA,EAEA,OAAiB,wBACf,OACA,sBAEqB,wCACrB;AACA,WAAO,IAAI;AAAA,MACT,IAAI,2DAA0B;AAAA,QAC5B,MAAM;AAAA,UACJ,KAAK;AAAA,UACL,gBAAgB,EAAE,MAAM,OAAO;AAAA,QACjC;AAAA,QACA,UAAU,MAAM,MAAM,cAAc;AAAA,QACpC,WAAW,CAAC,aAAa,MAAM,cAAc,UAAU,QAAQ;AAAA,MACjE,CAAC;AAAA,IACH;AAAA,EACF;AAAA,EAEA,OAAc,OACZ,OACA,sBAEqB,wCACrB;AACA,WAAO,IAAI;AAAA,MACT;AAAA,MACA,qBAAqB,wBAAwB,OAAO,mBAAmB;AAAA,IACzE;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/api/AssistantRuntime.ts"],"sourcesContent":["import { AssistantRuntimeCore } from \"../runtimes/core/AssistantRuntimeCore\";\nimport { NestedSubscriptionSubject } from \"./subscribable/NestedSubscriptionSubject\";\nimport { ModelConfigProvider } from \"../types/ModelConfigTypes\";\nimport {\n ThreadRuntime,\n ThreadRuntimeCoreBinding,\n ThreadRuntimeImpl,\n} from \"./ThreadRuntime\";\nimport { Unsubscribe } from \"../types\";\nimport {\n ThreadManagerRuntime,\n ThreadManagerRuntimeImpl,\n} from \"./ThreadManagerRuntime\";\n\nexport type AssistantRuntime = {\n /**\n * The currently selected main thread.\n */\n thread: ThreadRuntime;\n\n /**\n * The thread manager, to rename, archive and delete threads.\n */\n threadManager: ThreadManagerRuntime;\n\n /**\n * Switch to a new thread.\n */\n switchToNewThread(): void;\n\n /**\n * Switch to a thread.\n *\n * @param threadId The thread ID to switch to.\n */\n switchToThread(threadId: string): void;\n /**\n * @deprecated Use `switchToNewThread` instead. This will be removed in 0.6.0.\n */\n switchToThread(threadId: string | null): void;\n\n /**\n * Register a model config provider. Model config providers are configuration such as system message, temperature, etc. that are set in the frontend.\n *\n * @param provider The model config provider to register.\n */\n registerModelConfigProvider(provider: ModelConfigProvider): Unsubscribe;\n\n /**\n * @deprecated Thread is now static and never gets updated. This will be removed in 0.6.0.\n */\n subscribe(callback: () => void): Unsubscribe;\n};\n\nexport class AssistantRuntimeImpl\n implements\n Omit<AssistantRuntimeCore, \"thread\" | \"threadManager\">,\n AssistantRuntime\n{\n public readonly threadManager;\n\n protected constructor(\n private readonly _core: AssistantRuntimeCore,\n private readonly _thread: ThreadRuntime,\n ) {\n this.threadManager = new ThreadManagerRuntimeImpl(_core.threadManager);\n }\n\n public get thread() {\n return this._thread;\n }\n\n public switchToNewThread() {\n return this._core.threadManager.switchToNewThread();\n }\n\n public switchToThread(threadId: string): void;\n /**\n * @deprecated Use `switchToNewThread` instead. This will be removed in 0.6.0.\n */\n public switchToThread(threadId: string | null): void;\n public switchToThread(threadId: string | null) {\n if (threadId === null) return this.switchToNewThread();\n return this._core.threadManager.switchToThread(threadId);\n }\n\n public registerModelConfigProvider(provider: ModelConfigProvider) {\n return this._core.registerModelConfigProvider(provider);\n }\n\n /**\n * @deprecated Thread is now static and never gets updated. This will be removed in 0.6.0.\n */\n public subscribe() {\n return () => {};\n }\n\n protected static createMainThreadRuntime(\n _core: AssistantRuntimeCore,\n CustomThreadRuntime: new (\n binding: ThreadRuntimeCoreBinding,\n ) => ThreadRuntime = ThreadRuntimeImpl,\n ) {\n return new CustomThreadRuntime(\n new NestedSubscriptionSubject({\n path: {\n ref: \"threads.main\",\n threadSelector: { type: \"main\" },\n },\n getState: () => _core.threadManager.mainThread,\n subscribe: (callback) => _core.threadManager.subscribe(callback),\n }),\n );\n }\n\n public static create(\n _core: AssistantRuntimeCore,\n CustomThreadRuntime: new (\n binding: ThreadRuntimeCoreBinding,\n ) => ThreadRuntime = ThreadRuntimeImpl,\n ) {\n return new AssistantRuntimeImpl(\n _core,\n AssistantRuntimeImpl.createMainThreadRuntime(_core, CustomThreadRuntime),\n ) as AssistantRuntime;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uCAA0C;AAE1C,2BAIO;AAEP,kCAGO;AA0CA,MAAM,qBAIb;AAAA,EAGY,YACS,OACA,SACjB;AAFiB;AACA;AAEjB,SAAK,gBAAgB,IAAI,qDAAyB,MAAM,aAAa;AAAA,EACvE;AAAA,EAPgB;AAAA,EAShB,IAAW,SAAS;AAClB,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,oBAAoB;AACzB,WAAO,KAAK,MAAM,cAAc,kBAAkB;AAAA,EACpD;AAAA,EAOO,eAAe,UAAyB;AAC7C,QAAI,aAAa,KAAM,QAAO,KAAK,kBAAkB;AACrD,WAAO,KAAK,MAAM,cAAc,eAAe,QAAQ;AAAA,EACzD;AAAA,EAEO,4BAA4B,UAA+B;AAChE,WAAO,KAAK,MAAM,4BAA4B,QAAQ;AAAA,EACxD;AAAA;AAAA;AAAA;AAAA,EAKO,YAAY;AACjB,WAAO,MAAM;AAAA,IAAC;AAAA,EAChB;AAAA,EAEA,OAAiB,wBACf,OACA,sBAEqB,wCACrB;AACA,WAAO,IAAI;AAAA,MACT,IAAI,2DAA0B;AAAA,QAC5B,MAAM;AAAA,UACJ,KAAK;AAAA,UACL,gBAAgB,EAAE,MAAM,OAAO;AAAA,QACjC;AAAA,QACA,UAAU,MAAM,MAAM,cAAc;AAAA,QACpC,WAAW,CAAC,aAAa,MAAM,cAAc,UAAU,QAAQ;AAAA,MACjE,CAAC;AAAA,IACH;AAAA,EACF;AAAA,EAEA,OAAc,OACZ,OACA,sBAEqB,wCACrB;AACA,WAAO,IAAI;AAAA,MACT;AAAA,MACA,qBAAqB,wBAAwB,OAAO,mBAAmB;AAAA,IACzE;AAAA,EACF;AACF;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/api/AssistantRuntime.ts"],"sourcesContent":["import { AssistantRuntimeCore } from \"../runtimes/core/AssistantRuntimeCore\";\nimport { NestedSubscriptionSubject } from \"./subscribable/NestedSubscriptionSubject\";\nimport { ModelConfigProvider } from \"../types/ModelConfigTypes\";\nimport {\n ThreadRuntime,\n ThreadRuntimeCoreBinding,\n ThreadRuntimeImpl,\n} from \"./ThreadRuntime\";\nimport { Unsubscribe } from \"../types\";\nimport {\n ThreadManagerRuntime,\n ThreadManagerRuntimeImpl,\n} from \"./ThreadManagerRuntime\";\n\nexport type AssistantRuntime = {\n thread: ThreadRuntime;\n threadManager: ThreadManagerRuntime;\n\n switchToNewThread(): void;\n\n switchToThread(threadId: string): void;\n /**\n * @deprecated Use `switchToNewThread` instead. This will be removed in 0.6.0.\n */\n switchToThread(threadId: string | null): void;\n\n registerModelConfigProvider(provider: ModelConfigProvider): Unsubscribe;\n\n /**\n * @deprecated Thread is now static and never gets updated. This will be removed in 0.6.0.\n */\n subscribe(callback: () => void): Unsubscribe;\n};\n\nexport class AssistantRuntimeImpl\n implements\n Omit<AssistantRuntimeCore, \"thread\" | \"threadManager\">,\n AssistantRuntime\n{\n public readonly threadManager;\n\n protected constructor(\n private readonly _core: AssistantRuntimeCore,\n private readonly _thread: ThreadRuntime,\n ) {\n this.threadManager = new ThreadManagerRuntimeImpl(_core.threadManager);\n }\n\n public get thread() {\n return this._thread;\n }\n\n public switchToNewThread() {\n return this._core.threadManager.switchToNewThread();\n }\n\n public switchToThread(threadId: string): void;\n /**\n * @deprecated Use `switchToNewThread` instead. This will be removed in 0.6.0.\n */\n public switchToThread(threadId: string | null): void;\n public switchToThread(threadId: string | null) {\n if (threadId === null) return this.switchToNewThread();\n return this._core.threadManager.switchToThread(threadId);\n }\n\n public registerModelConfigProvider(provider: ModelConfigProvider) {\n return this._core.registerModelConfigProvider(provider);\n }\n\n /**\n * @deprecated Thread is now static and never gets updated. This will be removed in 0.6.0.\n */\n public subscribe() {\n return () => {};\n }\n\n protected static createMainThreadRuntime(\n _core: AssistantRuntimeCore,\n CustomThreadRuntime: new (\n binding: ThreadRuntimeCoreBinding,\n ) => ThreadRuntime = ThreadRuntimeImpl,\n ) {\n return new CustomThreadRuntime(\n new NestedSubscriptionSubject({\n path: {\n ref: \"threads.main\",\n threadSelector: { type: \"main\" },\n },\n getState: () => _core.threadManager.mainThread,\n subscribe: (callback) => _core.threadManager.subscribe(callback),\n }),\n );\n }\n\n public static create(\n _core: AssistantRuntimeCore,\n CustomThreadRuntime: new (\n binding: ThreadRuntimeCoreBinding,\n ) => ThreadRuntime = ThreadRuntimeImpl,\n ) {\n return new AssistantRuntimeImpl(\n _core,\n AssistantRuntimeImpl.createMainThreadRuntime(_core, CustomThreadRuntime),\n ) as AssistantRuntime;\n }\n}\n"],"mappings":"AACA,SAAS,iCAAiC;AAE1C;AAAA,EAGE;AAAA,OACK;AAEP;AAAA,EAEE;AAAA,OACK;AAsBA,MAAM,qBAIb;AAAA,EAGY,YACS,OACA,SACjB;AAFiB;AACA;AAEjB,SAAK,gBAAgB,IAAI,yBAAyB,MAAM,aAAa;AAAA,EACvE;AAAA,EAPgB;AAAA,EAShB,IAAW,SAAS;AAClB,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,oBAAoB;AACzB,WAAO,KAAK,MAAM,cAAc,kBAAkB;AAAA,EACpD;AAAA,EAOO,eAAe,UAAyB;AAC7C,QAAI,aAAa,KAAM,QAAO,KAAK,kBAAkB;AACrD,WAAO,KAAK,MAAM,cAAc,eAAe,QAAQ;AAAA,EACzD;AAAA,EAEO,4BAA4B,UAA+B;AAChE,WAAO,KAAK,MAAM,4BAA4B,QAAQ;AAAA,EACxD;AAAA;AAAA;AAAA;AAAA,EAKO,YAAY;AACjB,WAAO,MAAM;AAAA,IAAC;AAAA,EAChB;AAAA,EAEA,OAAiB,wBACf,OACA,sBAEqB,mBACrB;AACA,WAAO,IAAI;AAAA,MACT,IAAI,0BAA0B;AAAA,QAC5B,MAAM;AAAA,UACJ,KAAK;AAAA,UACL,gBAAgB,EAAE,MAAM,OAAO;AAAA,QACjC;AAAA,QACA,UAAU,MAAM,MAAM,cAAc;AAAA,QACpC,WAAW,CAAC,aAAa,MAAM,cAAc,UAAU,QAAQ;AAAA,MACjE,CAAC;AAAA,IACH;AAAA,EACF;AAAA,EAEA,OAAc,OACZ,OACA,sBAEqB,mBACrB;AACA,WAAO,IAAI;AAAA,MACT;AAAA,MACA,qBAAqB,wBAAwB,OAAO,mBAAmB;AAAA,IACzE;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/api/AssistantRuntime.ts"],"sourcesContent":["import { AssistantRuntimeCore } from \"../runtimes/core/AssistantRuntimeCore\";\nimport { NestedSubscriptionSubject } from \"./subscribable/NestedSubscriptionSubject\";\nimport { ModelConfigProvider } from \"../types/ModelConfigTypes\";\nimport {\n ThreadRuntime,\n ThreadRuntimeCoreBinding,\n ThreadRuntimeImpl,\n} from \"./ThreadRuntime\";\nimport { Unsubscribe } from \"../types\";\nimport {\n ThreadManagerRuntime,\n ThreadManagerRuntimeImpl,\n} from \"./ThreadManagerRuntime\";\n\nexport type AssistantRuntime = {\n /**\n * The currently selected main thread.\n */\n thread: ThreadRuntime;\n\n /**\n * The thread manager, to rename, archive and delete threads.\n */\n threadManager: ThreadManagerRuntime;\n\n /**\n * Switch to a new thread.\n */\n switchToNewThread(): void;\n\n /**\n * Switch to a thread.\n *\n * @param threadId The thread ID to switch to.\n */\n switchToThread(threadId: string): void;\n /**\n * @deprecated Use `switchToNewThread` instead. This will be removed in 0.6.0.\n */\n switchToThread(threadId: string | null): void;\n\n /**\n * Register a model config provider. Model config providers are configuration such as system message, temperature, etc. that are set in the frontend.\n *\n * @param provider The model config provider to register.\n */\n registerModelConfigProvider(provider: ModelConfigProvider): Unsubscribe;\n\n /**\n * @deprecated Thread is now static and never gets updated. This will be removed in 0.6.0.\n */\n subscribe(callback: () => void): Unsubscribe;\n};\n\nexport class AssistantRuntimeImpl\n implements\n Omit<AssistantRuntimeCore, \"thread\" | \"threadManager\">,\n AssistantRuntime\n{\n public readonly threadManager;\n\n protected constructor(\n private readonly _core: AssistantRuntimeCore,\n private readonly _thread: ThreadRuntime,\n ) {\n this.threadManager = new ThreadManagerRuntimeImpl(_core.threadManager);\n }\n\n public get thread() {\n return this._thread;\n }\n\n public switchToNewThread() {\n return this._core.threadManager.switchToNewThread();\n }\n\n public switchToThread(threadId: string): void;\n /**\n * @deprecated Use `switchToNewThread` instead. This will be removed in 0.6.0.\n */\n public switchToThread(threadId: string | null): void;\n public switchToThread(threadId: string | null) {\n if (threadId === null) return this.switchToNewThread();\n return this._core.threadManager.switchToThread(threadId);\n }\n\n public registerModelConfigProvider(provider: ModelConfigProvider) {\n return this._core.registerModelConfigProvider(provider);\n }\n\n /**\n * @deprecated Thread is now static and never gets updated. This will be removed in 0.6.0.\n */\n public subscribe() {\n return () => {};\n }\n\n protected static createMainThreadRuntime(\n _core: AssistantRuntimeCore,\n CustomThreadRuntime: new (\n binding: ThreadRuntimeCoreBinding,\n ) => ThreadRuntime = ThreadRuntimeImpl,\n ) {\n return new CustomThreadRuntime(\n new NestedSubscriptionSubject({\n path: {\n ref: \"threads.main\",\n threadSelector: { type: \"main\" },\n },\n getState: () => _core.threadManager.mainThread,\n subscribe: (callback) => _core.threadManager.subscribe(callback),\n }),\n );\n }\n\n public static create(\n _core: AssistantRuntimeCore,\n CustomThreadRuntime: new (\n binding: ThreadRuntimeCoreBinding,\n ) => ThreadRuntime = ThreadRuntimeImpl,\n ) {\n return new AssistantRuntimeImpl(\n _core,\n AssistantRuntimeImpl.createMainThreadRuntime(_core, CustomThreadRuntime),\n ) as AssistantRuntime;\n }\n}\n"],"mappings":"AACA,SAAS,iCAAiC;AAE1C;AAAA,EAGE;AAAA,OACK;AAEP;AAAA,EAEE;AAAA,OACK;AA0CA,MAAM,qBAIb;AAAA,EAGY,YACS,OACA,SACjB;AAFiB;AACA;AAEjB,SAAK,gBAAgB,IAAI,yBAAyB,MAAM,aAAa;AAAA,EACvE;AAAA,EAPgB;AAAA,EAShB,IAAW,SAAS;AAClB,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,oBAAoB;AACzB,WAAO,KAAK,MAAM,cAAc,kBAAkB;AAAA,EACpD;AAAA,EAOO,eAAe,UAAyB;AAC7C,QAAI,aAAa,KAAM,QAAO,KAAK,kBAAkB;AACrD,WAAO,KAAK,MAAM,cAAc,eAAe,QAAQ;AAAA,EACzD;AAAA,EAEO,4BAA4B,UAA+B;AAChE,WAAO,KAAK,MAAM,4BAA4B,QAAQ;AAAA,EACxD;AAAA;AAAA;AAAA;AAAA,EAKO,YAAY;AACjB,WAAO,MAAM;AAAA,IAAC;AAAA,EAChB;AAAA,EAEA,OAAiB,wBACf,OACA,sBAEqB,mBACrB;AACA,WAAO,IAAI;AAAA,MACT,IAAI,0BAA0B;AAAA,QAC5B,MAAM;AAAA,UACJ,KAAK;AAAA,UACL,gBAAgB,EAAE,MAAM,OAAO;AAAA,QACjC;AAAA,QACA,UAAU,MAAM,MAAM,cAAc;AAAA,QACpC,WAAW,CAAC,aAAa,MAAM,cAAc,UAAU,QAAQ;AAAA,MACjE,CAAC;AAAA,IACH;AAAA,EACF;AAAA,EAEA,OAAc,OACZ,OACA,sBAEqB,mBACrB;AACA,WAAO,IAAI;AAAA,MACT;AAAA,MACA,qBAAqB,wBAAwB,OAAO,mBAAmB;AAAA,IACzE;AAAA,EACF;AACF;","names":[]}
@@ -16,12 +16,33 @@ export type ThreadRuntimeCoreBinding = SubscribableWithState<ThreadRuntimeCore,
16
16
  outerSubscribe(callback: () => void): Unsubscribe;
17
17
  };
18
18
  export type ThreadState = Readonly<{
19
+ /**
20
+ * The thread ID.
21
+ */
19
22
  threadId: string;
23
+ /**
24
+ * Whether the thread is disabled. Disabled threads cannot receive new messages.
25
+ */
20
26
  isDisabled: boolean;
27
+ /**
28
+ * Whether the thread is running. A thread is considered running when there is an active stream connection to the backend.
29
+ */
21
30
  isRunning: boolean;
31
+ /**
32
+ * The capabilities of the thread, such as whether the thread supports editing, branch switching, etc.
33
+ */
22
34
  capabilities: RuntimeCapabilities;
35
+ /**
36
+ * The messages in the currently selected branch of the thread.
37
+ */
23
38
  messages: readonly ThreadMessage[];
39
+ /**
40
+ * Follow up message suggestions to show the user.
41
+ */
24
42
  suggestions: readonly ThreadSuggestion[];
43
+ /**
44
+ * Custom extra information provided by the runtime.
45
+ */
25
46
  extras: unknown;
26
47
  /**
27
48
  * @deprecated This API is still under active development and might change without notice.
@@ -197,12 +218,33 @@ export declare class ThreadRuntimeImpl implements Omit<ThreadRuntimeCore, "getMe
197
218
  constructor(threadBinding: ThreadRuntimeCoreBinding);
198
219
  readonly composer: ThreadComposerRuntimeImpl;
199
220
  getState(): Readonly<{
221
+ /**
222
+ * The thread ID.
223
+ */
200
224
  threadId: string;
225
+ /**
226
+ * Whether the thread is disabled. Disabled threads cannot receive new messages.
227
+ */
201
228
  isDisabled: boolean;
229
+ /**
230
+ * Whether the thread is running. A thread is considered running when there is an active stream connection to the backend.
231
+ */
202
232
  isRunning: boolean;
233
+ /**
234
+ * The capabilities of the thread, such as whether the thread supports editing, branch switching, etc.
235
+ */
203
236
  capabilities: RuntimeCapabilities;
237
+ /**
238
+ * The messages in the currently selected branch of the thread.
239
+ */
204
240
  messages: readonly ThreadMessage[];
241
+ /**
242
+ * Follow up message suggestions to show the user.
243
+ */
205
244
  suggestions: readonly ThreadSuggestion[];
245
+ /**
246
+ * Custom extra information provided by the runtime.
247
+ */
206
248
  extras: unknown;
207
249
  /**
208
250
  * @deprecated This API is still under active development and might change without notice.
@@ -1 +1 @@
1
- {"version":3,"file":"ThreadRuntime.d.ts","sourceRoot":"","sources":["../../src/api/ThreadRuntime.ts"],"names":[],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ItC,kBAAkB,CAAC,GAAG,EAAE,MAAM;IAqB9B,eAAe,CAAC,SAAS,EAAE,MAAM;IAaxC,OAAO,CAAC,kBAAkB;IA6C1B,OAAO,CAAC,iCAAiC,CAGrC;IAEG,WAAW,CAChB,KAAK,EAAE,sBAAsB,EAC7B,QAAQ,EAAE,MAAM,IAAI,GACnB,WAAW;CAef"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/api/ThreadRuntime.ts"],"sourcesContent":["import {\n AddToolResultOptions,\n ThreadSuggestion,\n RuntimeCapabilities,\n SubmitFeedbackOptions,\n ThreadRuntimeCore,\n SpeechState,\n SubmittedFeedback,\n ThreadRuntimeEventType,\n} from \"../runtimes/core/ThreadRuntimeCore\";\nimport { ExportedMessageRepository } from \"../runtimes/utils/MessageRepository\";\nimport {\n AppendMessage,\n ModelConfig,\n ThreadMessage,\n Unsubscribe,\n} from \"../types\";\nimport {\n MessageRuntime,\n MessageRuntimeImpl,\n MessageState,\n} from \"./MessageRuntime\";\nimport { NestedSubscriptionSubject } from \"./subscribable/NestedSubscriptionSubject\";\nimport { ShallowMemoizeSubject } from \"./subscribable/ShallowMemoizeSubject\";\nimport {\n Subscribable,\n SubscribableWithState,\n} from \"./subscribable/Subscribable\";\nimport {\n ThreadComposerRuntime,\n ThreadComposerRuntimeImpl,\n} from \"./ComposerRuntime\";\nimport { LazyMemoizeSubject } from \"./subscribable/LazyMemoizeSubject\";\nimport { SKIP_UPDATE } from \"./subscribable/SKIP_UPDATE\";\nimport { ComposerRuntimeCore } from \"../runtimes/core/ComposerRuntimeCore\";\nimport { MessageRuntimePath, ThreadRuntimePath } from \"./RuntimePathTypes\";\n\nexport type CreateAppendMessage =\n | string\n | {\n parentId?: string | null | undefined;\n role?: AppendMessage[\"role\"] | undefined;\n content: AppendMessage[\"content\"];\n attachments?: AppendMessage[\"attachments\"] | undefined;\n };\n\nconst toAppendMessage = (\n messages: readonly ThreadMessage[],\n message: CreateAppendMessage,\n): AppendMessage => {\n if (typeof message === \"string\") {\n return {\n parentId: messages.at(-1)?.id ?? null,\n role: \"user\",\n content: [{ type: \"text\", text: message }],\n attachments: [],\n };\n }\n\n if (message.role && message.parentId && message.attachments) {\n return message as AppendMessage;\n }\n\n return {\n parentId: message.parentId ?? messages.at(-1)?.id ?? null,\n role: message.role ?? \"user\",\n content: message.content,\n attachments: message.attachments ?? [],\n } as AppendMessage;\n};\n\nexport type ThreadRuntimeCoreBinding = SubscribableWithState<\n ThreadRuntimeCore,\n ThreadRuntimePath\n> & {\n outerSubscribe(callback: () => void): Unsubscribe;\n};\n\nexport type ThreadState = Readonly<{\n threadId: string;\n isDisabled: boolean;\n isRunning: boolean;\n capabilities: RuntimeCapabilities;\n messages: readonly ThreadMessage[];\n suggestions: readonly ThreadSuggestion[];\n extras: unknown;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n speech: SpeechState | undefined;\n}>;\n\nexport const getThreadState = (runtime: ThreadRuntimeCore): ThreadState => {\n const lastMessage = runtime.messages.at(-1);\n return Object.freeze({\n threadId: runtime.threadId,\n capabilities: runtime.capabilities,\n isDisabled: runtime.isDisabled,\n isRunning:\n lastMessage?.role !== \"assistant\"\n ? false\n : lastMessage.status.type === \"running\",\n messages: runtime.messages,\n suggestions: runtime.suggestions,\n extras: runtime.extras,\n speech: runtime.speech,\n });\n};\n\nexport type ThreadRuntime = Readonly<{\n readonly path: ThreadRuntimePath;\n\n readonly composer: ThreadComposerRuntime;\n getState(): ThreadState;\n\n /**\n * @deprecated This method will be removed in 0.6.0. Submit feedback if you need this functionality.\n */\n unstable_getCore(): ThreadRuntimeCore;\n\n append(message: CreateAppendMessage): void;\n startRun(parentId: string | null): void;\n subscribe(callback: () => void): Unsubscribe;\n cancelRun(): void;\n getModelConfig(): ModelConfig;\n export(): ExportedMessageRepository;\n import(repository: ExportedMessageRepository): void;\n getMesssageByIndex(idx: number): MessageRuntime;\n getMesssageById(messageId: string): MessageRuntime;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n stopSpeaking: () => void;\n\n unstable_on(event: ThreadRuntimeEventType, callback: () => void): Unsubscribe;\n\n // Legacy methods with deprecations\n\n /**\n * @deprecated Use `getState().capabilities` instead. This will be removed in 0.6.0.\n */\n capabilities: Readonly<RuntimeCapabilities>;\n\n /**\n * @deprecated Use `getState().threadId` instead. This will be removed in 0.6.0.\n */\n threadId: string;\n\n /**\n * @deprecated Use `getState().isDisabled` instead. This will be removed in 0.6.0.\n */\n isDisabled: boolean;\n\n /**\n * @deprecated Use `getState().isRunning` instead. This will be removed in 0.6.0.\n */\n isRunning: boolean;\n\n /**\n * @deprecated Use `getState().messages` instead. This will be removed in 0.6.0.\n */\n messages: readonly ThreadMessage[];\n\n /**\n * @deprecated Use `getState().followupSuggestions` instead. This will be removed in 0.6.0.\n */\n suggestions: readonly ThreadSuggestion[];\n\n /**\n * @deprecated Use `getState().speechState` instead. This will be removed in 0.6.0.\n */\n speech: SpeechState | undefined;\n\n /**\n * @deprecated Use `getState().extras` instead. This will be removed in 0.6.0.\n */\n extras: unknown;\n\n /**\n * @deprecated Use `getMesssageById(id).getState().branchNumber` / `getMesssageById(id).getState().branchCount` instead. This will be removed in 0.6.0.\n */\n getBranches: (messageId: string) => readonly string[];\n\n /**\n * @deprecated Use `getMesssageById(id).switchToBranch({ options })` instead. This will be removed in 0.6.0.\n */\n switchToBranch: (branchId: string) => void;\n\n /**\n * @deprecated Use `getMesssageById(id).getContentPartByToolCallId(toolCallId).addToolResult({ result })` instead. This will be removed in 0.6.0.\n */\n addToolResult: (options: AddToolResultOptions) => void;\n\n /**\n * @deprecated Use `getMesssageById(id).speak()` instead. This will be removed in 0.6.0.\n */\n speak: (messageId: string) => void;\n\n /**\n * @deprecated Use `getMesssageById(id).getState().submittedFeedback` instead. This will be removed in 0.6.0.\n */\n getSubmittedFeedback: (messageId: string) => SubmittedFeedback | undefined;\n\n /**\n * @deprecated Use `getMesssageById(id).submitFeedback({ type })` instead. This will be removed in 0.6.0.\n */\n submitFeedback: (feedback: SubmitFeedbackOptions) => void;\n\n /**\n * @deprecated Use `getMesssageById(id).composer` instead. This will be removed in 0.6.0.\n */\n getEditComposer: (messageId: string) => ComposerRuntimeCore | undefined;\n\n /**\n * @deprecated Use `getMesssageById(id).composer.beginEdit()` instead. This will be removed in 0.6.0.\n */\n beginEdit: (messageId: string) => void;\n}>;\n\nexport class ThreadRuntimeImpl\n implements Omit<ThreadRuntimeCore, \"getMessageById\">, ThreadRuntime\n{\n public get path() {\n return this._threadBinding.path;\n }\n\n /**\n * @deprecated Use `getState().threadId` instead. This will be removed in 0.6.0.\n */\n public get threadId() {\n return this.getState().threadId;\n }\n\n /**\n * @deprecated Use `getState().isDisabled` instead. This will be removed in 0.6.0.\n */\n public get isDisabled() {\n return this.getState().isDisabled;\n }\n\n /**\n * @deprecated Use `getState().isRunning` instead. This will be removed in 0.6.0.\n */\n public get isRunning() {\n return this.getState().isRunning;\n }\n\n /**\n * @deprecated Use `getState().capabilities` instead. This will be removed in 0.6.0.\n */\n public get capabilities() {\n return this.getState().capabilities;\n }\n\n /**\n * @deprecated Use `getState().extras` instead. This will be removed in 0.6.0.\n */\n public get extras() {\n return this._threadBinding.getState().extras;\n }\n\n /**\n * @deprecated Use `getState().followupSuggestions` instead. This will be removed in 0.6.0.\n */\n public get suggestions() {\n return this._threadBinding.getState().suggestions;\n }\n\n /**\n * @deprecated Use `getState().messages` instead. This will be removed in 0.6.0.\n */\n public get messages() {\n return this._threadBinding.getState().messages;\n }\n\n /**\n * @deprecated Use `getState().speechState` instead. This will be removed in 0.6.0.\n */\n public get speech() {\n return this._threadBinding.getState().speech;\n }\n\n public unstable_getCore() {\n return this._threadBinding.getState();\n }\n\n private _threadBinding: ThreadRuntimeCoreBinding & {\n getStateState(): ThreadState;\n };\n\n constructor(threadBinding: ThreadRuntimeCoreBinding) {\n const stateBinding = new LazyMemoizeSubject({\n path: threadBinding.path,\n getState: () => getThreadState(threadBinding.getState()),\n subscribe: (callback) => threadBinding.subscribe(callback),\n });\n\n this._threadBinding = {\n path: threadBinding.path,\n getState: () => threadBinding.getState(),\n getStateState: () => stateBinding.getState(),\n outerSubscribe: (callback) => threadBinding.outerSubscribe(callback),\n subscribe: (callback) => threadBinding.subscribe(callback),\n };\n\n this.composer = new ThreadComposerRuntimeImpl(\n new NestedSubscriptionSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.composer`,\n composerSource: \"thread\",\n },\n getState: () => this._threadBinding.getState().composer,\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n );\n }\n\n public readonly composer;\n\n public getState() {\n return this._threadBinding.getStateState();\n }\n\n public append(message: CreateAppendMessage) {\n this._threadBinding\n .getState()\n .append(\n toAppendMessage(this._threadBinding.getState().messages, message),\n );\n }\n\n public subscribe(callback: () => void) {\n return this._threadBinding.subscribe(callback);\n }\n\n /**\n * @derprecated Use `getMesssageById(id).getState().branchNumber` / `getMesssageById(id).getState().branchCount` instead. This will be removed in 0.6.0.\n */\n public getBranches(messageId: string) {\n return this._threadBinding.getState().getBranches(messageId);\n }\n\n public getModelConfig() {\n return this._threadBinding.getState().getModelConfig();\n }\n\n // TODO sometimes you want to continue when there is no child message\n public startRun(parentId: string | null) {\n return this._threadBinding.getState().startRun(parentId);\n }\n\n public cancelRun() {\n this._threadBinding.getState().cancelRun();\n }\n\n /**\n * @deprecated Use `getMesssageById(id).getContentPartByToolCallId(toolCallId).addToolResult({ result })` instead. This will be removed in 0.6.0.\n */\n public addToolResult(options: AddToolResultOptions) {\n this._threadBinding.getState().addToolResult(options);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).switchToBranch({ options })` instead. This will be removed in 0.6.0.\n */\n public switchToBranch(branchId: string) {\n return this._threadBinding.getState().switchToBranch(branchId);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).speak()` instead. This will be removed in 0.6.0.\n */\n public speak(messageId: string) {\n return this._threadBinding.getState().speak(messageId);\n }\n\n public stopSpeaking() {\n return this._threadBinding.getState().stopSpeaking();\n }\n\n public getSubmittedFeedback(messageId: string) {\n return this._threadBinding.getState().getSubmittedFeedback(messageId);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).submitFeedback({ type })` instead. This will be removed in 0.6.0.\n */\n public submitFeedback(options: SubmitFeedbackOptions) {\n return this._threadBinding.getState().submitFeedback(options);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).getMessageByIndex(idx).composer` instead. This will be removed in 0.6.0.\n */\n public getEditComposer(messageId: string) {\n return this._threadBinding.getState().getEditComposer(messageId);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).getMessageByIndex(idx).composer.beginEdit()` instead. This will be removed in 0.6.0.\n */\n public beginEdit(messageId: string) {\n return this._threadBinding.getState().beginEdit(messageId);\n }\n\n public export() {\n return this._threadBinding.getState().export();\n }\n\n public import(data: ExportedMessageRepository) {\n this._threadBinding.getState().import(data);\n }\n\n public getMesssageByIndex(idx: number) {\n if (idx < 0) throw new Error(\"Message index must be >= 0\");\n\n return this._getMessageRuntime(\n {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.messages[${idx}]`,\n messageSelector: { type: \"index\", index: idx },\n },\n () => {\n const messages = this._threadBinding.getState().messages;\n const message = messages[idx];\n if (!message) return undefined;\n return {\n message,\n parentId: messages[idx - 1]?.id ?? null,\n };\n },\n );\n }\n\n public getMesssageById(messageId: string) {\n return this._getMessageRuntime(\n {\n ...this.path,\n ref:\n this.path.ref +\n `${this.path.ref}.messages[messageId=${JSON.stringify(messageId)}]`,\n messageSelector: { type: \"messageId\", messageId: messageId },\n },\n () => this._threadBinding.getState().getMessageById(messageId),\n );\n }\n\n private _getMessageRuntime(\n path: MessageRuntimePath,\n callback: () =>\n | { parentId: string | null; message: ThreadMessage }\n | undefined,\n ) {\n return new MessageRuntimeImpl(\n new ShallowMemoizeSubject({\n path,\n getState: () => {\n const { message, parentId } = callback() ?? {};\n\n const { messages, speech: speechState } =\n this._threadBinding.getState();\n\n if (!message || parentId === undefined) return SKIP_UPDATE;\n\n const thread = this._threadBinding.getState();\n\n const branches = thread.getBranches(message.id);\n const submittedFeedback = thread.getSubmittedFeedback(message.id);\n\n return {\n ...message,\n\n message,\n isLast: messages.at(-1)?.id === message.id,\n parentId,\n\n branches,\n branchNumber: branches.indexOf(message.id) + 1,\n branchCount: branches.length,\n\n speech:\n speechState?.messageId === message.id ? speechState : undefined,\n\n submittedFeedback,\n } satisfies MessageState;\n },\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n this._threadBinding,\n );\n }\n\n private _eventListenerNestedSubscriptions = new Map<\n string,\n NestedSubscriptionSubject<Subscribable, ThreadRuntimePath>\n >();\n\n public unstable_on(\n event: ThreadRuntimeEventType,\n callback: () => void,\n ): Unsubscribe {\n let subject = this._eventListenerNestedSubscriptions.get(event);\n if (!subject) {\n subject = new NestedSubscriptionSubject({\n path: this.path,\n getState: () => ({\n subscribe: (callback) =>\n this._threadBinding.getState().unstable_on(event, callback),\n }),\n subscribe: (callback) => this._threadBinding.outerSubscribe(callback),\n });\n this._eventListenerNestedSubscriptions.set(event, subject);\n }\n return subject.subscribe(callback);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBA,4BAIO;AACP,uCAA0C;AAC1C,mCAAsC;AAKtC,6BAGO;AACP,gCAAmC;AACnC,yBAA4B;AAa5B,MAAM,kBAAkB,CACtB,UACA,YACkB;AAClB,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO;AAAA,MACL,UAAU,SAAS,GAAG,EAAE,GAAG,MAAM;AAAA,MACjC,MAAM;AAAA,MACN,SAAS,CAAC,EAAE,MAAM,QAAQ,MAAM,QAAQ,CAAC;AAAA,MACzC,aAAa,CAAC;AAAA,IAChB;AAAA,EACF;AAEA,MAAI,QAAQ,QAAQ,QAAQ,YAAY,QAAQ,aAAa;AAC3D,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL,UAAU,QAAQ,YAAY,SAAS,GAAG,EAAE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QAAQ,SAAS,GAAG,EAAE,GAAG,OAAO,QAAQ;AAAA,YACxC;AAAA,YAEA;AAAA,YACA,cAAc,SAAS,QAAQ,QAAQ,EAAE,IAAI;AAAA,YAC7C,aAAa,SAAS;AAAA,YAEtB,QACE,aAAa,cAAc,QAAQ,KAAK,cAAc;AAAA,YAExD;AAAA,UACF;AAAA,QACF;AAAA,QACA,WAAW,CAACA,cAAa,KAAK,eAAe,UAAUA,SAAQ;AAAA,MACjE,CAAC;AAAA,MACD,KAAK;AAAA,IACP;AAAA,EACF;AAAA,EAEQ,oCAAoC,oBAAI,IAG9C;AAAA,EAEK,YACL,OACA,UACa;AACb,QAAI,UAAU,KAAK,kCAAkC,IAAI,KAAK;AAC9D,QAAI,CAAC,SAAS;AACZ,gBAAU,IAAI,2DAA0B;AAAA,QACtC,MAAM,KAAK;AAAA,QACX,UAAU,OAAO;AAAA,UACf,WAAW,CAACA,cACV,KAAK,eAAe,SAAS,EAAE,YAAY,OAAOA,SAAQ;AAAA,QAC9D;AAAA,QACA,WAAW,CAACA,cAAa,KAAK,eAAe,eAAeA,SAAQ;AAAA,MACtE,CAAC;AACD,WAAK,kCAAkC,IAAI,OAAO,OAAO;AAAA,IAC3D;AACA,WAAO,QAAQ,UAAU,QAAQ;AAAA,EACnC;AACF;","names":["callback"]}
1
+ {"version":3,"sources":["../../src/api/ThreadRuntime.ts"],"sourcesContent":["import {\n AddToolResultOptions,\n ThreadSuggestion,\n RuntimeCapabilities,\n SubmitFeedbackOptions,\n ThreadRuntimeCore,\n SpeechState,\n SubmittedFeedback,\n ThreadRuntimeEventType,\n} from \"../runtimes/core/ThreadRuntimeCore\";\nimport { ExportedMessageRepository } from \"../runtimes/utils/MessageRepository\";\nimport {\n AppendMessage,\n ModelConfig,\n ThreadMessage,\n Unsubscribe,\n} from \"../types\";\nimport {\n MessageRuntime,\n MessageRuntimeImpl,\n MessageState,\n} from \"./MessageRuntime\";\nimport { NestedSubscriptionSubject } from \"./subscribable/NestedSubscriptionSubject\";\nimport { ShallowMemoizeSubject } from \"./subscribable/ShallowMemoizeSubject\";\nimport {\n Subscribable,\n SubscribableWithState,\n} from \"./subscribable/Subscribable\";\nimport {\n ThreadComposerRuntime,\n ThreadComposerRuntimeImpl,\n} from \"./ComposerRuntime\";\nimport { LazyMemoizeSubject } from \"./subscribable/LazyMemoizeSubject\";\nimport { SKIP_UPDATE } from \"./subscribable/SKIP_UPDATE\";\nimport { ComposerRuntimeCore } from \"../runtimes/core/ComposerRuntimeCore\";\nimport { MessageRuntimePath, ThreadRuntimePath } from \"./RuntimePathTypes\";\n\nexport type CreateAppendMessage =\n | string\n | {\n parentId?: string | null | undefined;\n role?: AppendMessage[\"role\"] | undefined;\n content: AppendMessage[\"content\"];\n attachments?: AppendMessage[\"attachments\"] | undefined;\n };\n\nconst toAppendMessage = (\n messages: readonly ThreadMessage[],\n message: CreateAppendMessage,\n): AppendMessage => {\n if (typeof message === \"string\") {\n return {\n parentId: messages.at(-1)?.id ?? null,\n role: \"user\",\n content: [{ type: \"text\", text: message }],\n attachments: [],\n };\n }\n\n if (message.role && message.parentId && message.attachments) {\n return message as AppendMessage;\n }\n\n return {\n parentId: message.parentId ?? messages.at(-1)?.id ?? null,\n role: message.role ?? \"user\",\n content: message.content,\n attachments: message.attachments ?? [],\n } as AppendMessage;\n};\n\nexport type ThreadRuntimeCoreBinding = SubscribableWithState<\n ThreadRuntimeCore,\n ThreadRuntimePath\n> & {\n outerSubscribe(callback: () => void): Unsubscribe;\n};\n\nexport type ThreadState = Readonly<{\n /**\n * The thread ID.\n */\n threadId: string;\n /**\n * Whether the thread is disabled. Disabled threads cannot receive new messages.\n */\n isDisabled: boolean;\n\n /**\n * Whether the thread is running. A thread is considered running when there is an active stream connection to the backend.\n */\n isRunning: boolean;\n\n /**\n * The capabilities of the thread, such as whether the thread supports editing, branch switching, etc.\n */\n capabilities: RuntimeCapabilities;\n\n /**\n * The messages in the currently selected branch of the thread.\n */\n messages: readonly ThreadMessage[];\n\n /**\n * Follow up message suggestions to show the user.\n */\n suggestions: readonly ThreadSuggestion[];\n\n /**\n * Custom extra information provided by the runtime.\n */\n extras: unknown;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n speech: SpeechState | undefined;\n}>;\n\nexport const getThreadState = (runtime: ThreadRuntimeCore): ThreadState => {\n const lastMessage = runtime.messages.at(-1);\n return Object.freeze({\n threadId: runtime.threadId,\n capabilities: runtime.capabilities,\n isDisabled: runtime.isDisabled,\n isRunning:\n lastMessage?.role !== \"assistant\"\n ? false\n : lastMessage.status.type === \"running\",\n messages: runtime.messages,\n suggestions: runtime.suggestions,\n extras: runtime.extras,\n speech: runtime.speech,\n });\n};\n\nexport type ThreadRuntime = Readonly<{\n readonly path: ThreadRuntimePath;\n\n readonly composer: ThreadComposerRuntime;\n getState(): ThreadState;\n\n /**\n * @deprecated This method will be removed in 0.6.0. Submit feedback if you need this functionality.\n */\n unstable_getCore(): ThreadRuntimeCore;\n\n append(message: CreateAppendMessage): void;\n startRun(parentId: string | null): void;\n subscribe(callback: () => void): Unsubscribe;\n cancelRun(): void;\n getModelConfig(): ModelConfig;\n export(): ExportedMessageRepository;\n import(repository: ExportedMessageRepository): void;\n getMesssageByIndex(idx: number): MessageRuntime;\n getMesssageById(messageId: string): MessageRuntime;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n stopSpeaking: () => void;\n\n unstable_on(event: ThreadRuntimeEventType, callback: () => void): Unsubscribe;\n\n // Legacy methods with deprecations\n\n /**\n * @deprecated Use `getState().capabilities` instead. This will be removed in 0.6.0.\n */\n capabilities: Readonly<RuntimeCapabilities>;\n\n /**\n * @deprecated Use `getState().threadId` instead. This will be removed in 0.6.0.\n */\n threadId: string;\n\n /**\n * @deprecated Use `getState().isDisabled` instead. This will be removed in 0.6.0.\n */\n isDisabled: boolean;\n\n /**\n * @deprecated Use `getState().isRunning` instead. This will be removed in 0.6.0.\n */\n isRunning: boolean;\n\n /**\n * @deprecated Use `getState().messages` instead. This will be removed in 0.6.0.\n */\n messages: readonly ThreadMessage[];\n\n /**\n * @deprecated Use `getState().followupSuggestions` instead. This will be removed in 0.6.0.\n */\n suggestions: readonly ThreadSuggestion[];\n\n /**\n * @deprecated Use `getState().speechState` instead. This will be removed in 0.6.0.\n */\n speech: SpeechState | undefined;\n\n /**\n * @deprecated Use `getState().extras` instead. This will be removed in 0.6.0.\n */\n extras: unknown;\n\n /**\n * @deprecated Use `getMesssageById(id).getState().branchNumber` / `getMesssageById(id).getState().branchCount` instead. This will be removed in 0.6.0.\n */\n getBranches: (messageId: string) => readonly string[];\n\n /**\n * @deprecated Use `getMesssageById(id).switchToBranch({ options })` instead. This will be removed in 0.6.0.\n */\n switchToBranch: (branchId: string) => void;\n\n /**\n * @deprecated Use `getMesssageById(id).getContentPartByToolCallId(toolCallId).addToolResult({ result })` instead. This will be removed in 0.6.0.\n */\n addToolResult: (options: AddToolResultOptions) => void;\n\n /**\n * @deprecated Use `getMesssageById(id).speak()` instead. This will be removed in 0.6.0.\n */\n speak: (messageId: string) => void;\n\n /**\n * @deprecated Use `getMesssageById(id).getState().submittedFeedback` instead. This will be removed in 0.6.0.\n */\n getSubmittedFeedback: (messageId: string) => SubmittedFeedback | undefined;\n\n /**\n * @deprecated Use `getMesssageById(id).submitFeedback({ type })` instead. This will be removed in 0.6.0.\n */\n submitFeedback: (feedback: SubmitFeedbackOptions) => void;\n\n /**\n * @deprecated Use `getMesssageById(id).composer` instead. This will be removed in 0.6.0.\n */\n getEditComposer: (messageId: string) => ComposerRuntimeCore | undefined;\n\n /**\n * @deprecated Use `getMesssageById(id).composer.beginEdit()` instead. This will be removed in 0.6.0.\n */\n beginEdit: (messageId: string) => void;\n}>;\n\nexport class ThreadRuntimeImpl\n implements Omit<ThreadRuntimeCore, \"getMessageById\">, ThreadRuntime\n{\n public get path() {\n return this._threadBinding.path;\n }\n\n /**\n * @deprecated Use `getState().threadId` instead. This will be removed in 0.6.0.\n */\n public get threadId() {\n return this.getState().threadId;\n }\n\n /**\n * @deprecated Use `getState().isDisabled` instead. This will be removed in 0.6.0.\n */\n public get isDisabled() {\n return this.getState().isDisabled;\n }\n\n /**\n * @deprecated Use `getState().isRunning` instead. This will be removed in 0.6.0.\n */\n public get isRunning() {\n return this.getState().isRunning;\n }\n\n /**\n * @deprecated Use `getState().capabilities` instead. This will be removed in 0.6.0.\n */\n public get capabilities() {\n return this.getState().capabilities;\n }\n\n /**\n * @deprecated Use `getState().extras` instead. This will be removed in 0.6.0.\n */\n public get extras() {\n return this._threadBinding.getState().extras;\n }\n\n /**\n * @deprecated Use `getState().followupSuggestions` instead. This will be removed in 0.6.0.\n */\n public get suggestions() {\n return this._threadBinding.getState().suggestions;\n }\n\n /**\n * @deprecated Use `getState().messages` instead. This will be removed in 0.6.0.\n */\n public get messages() {\n return this._threadBinding.getState().messages;\n }\n\n /**\n * @deprecated Use `getState().speechState` instead. This will be removed in 0.6.0.\n */\n public get speech() {\n return this._threadBinding.getState().speech;\n }\n\n public unstable_getCore() {\n return this._threadBinding.getState();\n }\n\n private _threadBinding: ThreadRuntimeCoreBinding & {\n getStateState(): ThreadState;\n };\n\n constructor(threadBinding: ThreadRuntimeCoreBinding) {\n const stateBinding = new LazyMemoizeSubject({\n path: threadBinding.path,\n getState: () => getThreadState(threadBinding.getState()),\n subscribe: (callback) => threadBinding.subscribe(callback),\n });\n\n this._threadBinding = {\n path: threadBinding.path,\n getState: () => threadBinding.getState(),\n getStateState: () => stateBinding.getState(),\n outerSubscribe: (callback) => threadBinding.outerSubscribe(callback),\n subscribe: (callback) => threadBinding.subscribe(callback),\n };\n\n this.composer = new ThreadComposerRuntimeImpl(\n new NestedSubscriptionSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.composer`,\n composerSource: \"thread\",\n },\n getState: () => this._threadBinding.getState().composer,\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n );\n }\n\n public readonly composer;\n\n public getState() {\n return this._threadBinding.getStateState();\n }\n\n public append(message: CreateAppendMessage) {\n this._threadBinding\n .getState()\n .append(\n toAppendMessage(this._threadBinding.getState().messages, message),\n );\n }\n\n public subscribe(callback: () => void) {\n return this._threadBinding.subscribe(callback);\n }\n\n /**\n * @derprecated Use `getMesssageById(id).getState().branchNumber` / `getMesssageById(id).getState().branchCount` instead. This will be removed in 0.6.0.\n */\n public getBranches(messageId: string) {\n return this._threadBinding.getState().getBranches(messageId);\n }\n\n public getModelConfig() {\n return this._threadBinding.getState().getModelConfig();\n }\n\n // TODO sometimes you want to continue when there is no child message\n public startRun(parentId: string | null) {\n return this._threadBinding.getState().startRun(parentId);\n }\n\n public cancelRun() {\n this._threadBinding.getState().cancelRun();\n }\n\n /**\n * @deprecated Use `getMesssageById(id).getContentPartByToolCallId(toolCallId).addToolResult({ result })` instead. This will be removed in 0.6.0.\n */\n public addToolResult(options: AddToolResultOptions) {\n this._threadBinding.getState().addToolResult(options);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).switchToBranch({ options })` instead. This will be removed in 0.6.0.\n */\n public switchToBranch(branchId: string) {\n return this._threadBinding.getState().switchToBranch(branchId);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).speak()` instead. This will be removed in 0.6.0.\n */\n public speak(messageId: string) {\n return this._threadBinding.getState().speak(messageId);\n }\n\n public stopSpeaking() {\n return this._threadBinding.getState().stopSpeaking();\n }\n\n public getSubmittedFeedback(messageId: string) {\n return this._threadBinding.getState().getSubmittedFeedback(messageId);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).submitFeedback({ type })` instead. This will be removed in 0.6.0.\n */\n public submitFeedback(options: SubmitFeedbackOptions) {\n return this._threadBinding.getState().submitFeedback(options);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).getMessageByIndex(idx).composer` instead. This will be removed in 0.6.0.\n */\n public getEditComposer(messageId: string) {\n return this._threadBinding.getState().getEditComposer(messageId);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).getMessageByIndex(idx).composer.beginEdit()` instead. This will be removed in 0.6.0.\n */\n public beginEdit(messageId: string) {\n return this._threadBinding.getState().beginEdit(messageId);\n }\n\n public export() {\n return this._threadBinding.getState().export();\n }\n\n public import(data: ExportedMessageRepository) {\n this._threadBinding.getState().import(data);\n }\n\n public getMesssageByIndex(idx: number) {\n if (idx < 0) throw new Error(\"Message index must be >= 0\");\n\n return this._getMessageRuntime(\n {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.messages[${idx}]`,\n messageSelector: { type: \"index\", index: idx },\n },\n () => {\n const messages = this._threadBinding.getState().messages;\n const message = messages[idx];\n if (!message) return undefined;\n return {\n message,\n parentId: messages[idx - 1]?.id ?? null,\n };\n },\n );\n }\n\n public getMesssageById(messageId: string) {\n return this._getMessageRuntime(\n {\n ...this.path,\n ref:\n this.path.ref +\n `${this.path.ref}.messages[messageId=${JSON.stringify(messageId)}]`,\n messageSelector: { type: \"messageId\", messageId: messageId },\n },\n () => this._threadBinding.getState().getMessageById(messageId),\n );\n }\n\n private _getMessageRuntime(\n path: MessageRuntimePath,\n callback: () =>\n | { parentId: string | null; message: ThreadMessage }\n | undefined,\n ) {\n return new MessageRuntimeImpl(\n new ShallowMemoizeSubject({\n path,\n getState: () => {\n const { message, parentId } = callback() ?? {};\n\n const { messages, speech: speechState } =\n this._threadBinding.getState();\n\n if (!message || parentId === undefined) return SKIP_UPDATE;\n\n const thread = this._threadBinding.getState();\n\n const branches = thread.getBranches(message.id);\n const submittedFeedback = thread.getSubmittedFeedback(message.id);\n\n return {\n ...message,\n\n message,\n isLast: messages.at(-1)?.id === message.id,\n parentId,\n\n branches,\n branchNumber: branches.indexOf(message.id) + 1,\n branchCount: branches.length,\n\n speech:\n speechState?.messageId === message.id ? speechState : undefined,\n\n submittedFeedback,\n } satisfies MessageState;\n },\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n this._threadBinding,\n );\n }\n\n private _eventListenerNestedSubscriptions = new Map<\n string,\n NestedSubscriptionSubject<Subscribable, ThreadRuntimePath>\n >();\n\n public unstable_on(\n event: ThreadRuntimeEventType,\n callback: () => void,\n ): Unsubscribe {\n let subject = this._eventListenerNestedSubscriptions.get(event);\n if (!subject) {\n subject = new NestedSubscriptionSubject({\n path: this.path,\n getState: () => ({\n subscribe: (callback) =>\n this._threadBinding.getState().unstable_on(event, callback),\n }),\n subscribe: (callback) => this._threadBinding.outerSubscribe(callback),\n });\n this._eventListenerNestedSubscriptions.set(event, subject);\n }\n return subject.subscribe(callback);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBA,4BAIO;AACP,uCAA0C;AAC1C,mCAAsC;AAKtC,6BAGO;AACP,gCAAmC;AACnC,yBAA4B;AAa5B,MAAM,kBAAkB,CACtB,UACA,YACkB;AAClB,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO;AAAA,MACL,UAAU,SAAS,GAAG,EAAE,GAAG,MAAM;AAAA,MACjC,MAAM;AAAA,MACN,SAAS,CAAC,EAAE,MAAM,QAAQ,MAAM,QAAQ,CAAC;AAAA,MACzC,aAAa,CAAC;AAAA,IAChB;AAAA,EACF;AAEA,MAAI,QAAQ,QAAQ,QAAQ,YAAY,QAAQ,aAAa;AAC3D,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL,UAAU,QAAQ,YAAY,SAAS,GAAG,EAAE,GAAG,MAAM;AAAA,IACrD,MAAM,QAAQ,QAAQ;AAAA,IACtB,SAAS,QAAQ;AAAA,IACjB,aAAa,QAAQ,eAAe,CAAC;AAAA,EACvC;AACF;AAkDO,MAAM,iBAAiB,CAAC,YAA4C;AACzE,QAAM,cAAc,QAAQ,SAAS,GAAG,EAAE;AAC1C,SAAO,OAAO,OAAO;AAAA,IACnB,UAAU,QAAQ;AAAA,IAClB,cAAc,QAAQ;AAAA,IACtB,YAAY,QAAQ;AAAA,IACpB,WACE,aAAa,SAAS,cAClB,QACA,YAAY,OAAO,SAAS;AAAA,IAClC,UAAU,QAAQ;AAAA,IAClB,a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AACb,QAAI,UAAU,KAAK,kCAAkC,IAAI,KAAK;AAC9D,QAAI,CAAC,SAAS;AACZ,gBAAU,IAAI,2DAA0B;AAAA,QACtC,MAAM,KAAK;AAAA,QACX,UAAU,OAAO;AAAA,UACf,WAAW,CAACA,cACV,KAAK,eAAe,SAAS,EAAE,YAAY,OAAOA,SAAQ;AAAA,QAC9D;AAAA,QACA,WAAW,CAACA,cAAa,KAAK,eAAe,eAAeA,SAAQ;AAAA,MACtE,CAAC;AACD,WAAK,kCAAkC,IAAI,OAAO,OAAO;AAAA,IAC3D;AACA,WAAO,QAAQ,UAAU,QAAQ;AAAA,EACnC;AACF;","names":["callback"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/api/ThreadRuntime.ts"],"sourcesContent":["import {\n AddToolResultOptions,\n ThreadSuggestion,\n RuntimeCapabilities,\n SubmitFeedbackOptions,\n ThreadRuntimeCore,\n SpeechState,\n SubmittedFeedback,\n ThreadRuntimeEventType,\n} from \"../runtimes/core/ThreadRuntimeCore\";\nimport { ExportedMessageRepository } from \"../runtimes/utils/MessageRepository\";\nimport {\n AppendMessage,\n ModelConfig,\n ThreadMessage,\n Unsubscribe,\n} from \"../types\";\nimport {\n MessageRuntime,\n MessageRuntimeImpl,\n MessageState,\n} from \"./MessageRuntime\";\nimport { NestedSubscriptionSubject } from \"./subscribable/NestedSubscriptionSubject\";\nimport { ShallowMemoizeSubject } from \"./subscribable/ShallowMemoizeSubject\";\nimport {\n Subscribable,\n SubscribableWithState,\n} from \"./subscribable/Subscribable\";\nimport {\n ThreadComposerRuntime,\n ThreadComposerRuntimeImpl,\n} from \"./ComposerRuntime\";\nimport { LazyMemoizeSubject } from \"./subscribable/LazyMemoizeSubject\";\nimport { SKIP_UPDATE } from \"./subscribable/SKIP_UPDATE\";\nimport { ComposerRuntimeCore } from \"../runtimes/core/ComposerRuntimeCore\";\nimport { MessageRuntimePath, ThreadRuntimePath } from \"./RuntimePathTypes\";\n\nexport type CreateAppendMessage =\n | string\n | {\n parentId?: string | null | undefined;\n role?: AppendMessage[\"role\"] | undefined;\n content: AppendMessage[\"content\"];\n attachments?: AppendMessage[\"attachments\"] | undefined;\n };\n\nconst toAppendMessage = (\n messages: readonly ThreadMessage[],\n message: CreateAppendMessage,\n): AppendMessage => {\n if (typeof message === \"string\") {\n return {\n parentId: messages.at(-1)?.id ?? null,\n role: \"user\",\n content: [{ type: \"text\", text: message }],\n attachments: [],\n };\n }\n\n if (message.role && message.parentId && message.attachments) {\n return message as AppendMessage;\n }\n\n return {\n parentId: message.parentId ?? messages.at(-1)?.id ?? null,\n role: message.role ?? \"user\",\n content: message.content,\n attachments: message.attachments ?? [],\n } as AppendMessage;\n};\n\nexport type ThreadRuntimeCoreBinding = SubscribableWithState<\n ThreadRuntimeCore,\n ThreadRuntimePath\n> & {\n outerSubscribe(callback: () => void): Unsubscribe;\n};\n\nexport type ThreadState = Readonly<{\n threadId: string;\n isDisabled: boolean;\n isRunning: boolean;\n capabilities: RuntimeCapabilities;\n messages: readonly ThreadMessage[];\n suggestions: readonly ThreadSuggestion[];\n extras: unknown;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n speech: SpeechState | undefined;\n}>;\n\nexport const getThreadState = (runtime: ThreadRuntimeCore): ThreadState => {\n const lastMessage = runtime.messages.at(-1);\n return Object.freeze({\n threadId: runtime.threadId,\n capabilities: runtime.capabilities,\n isDisabled: runtime.isDisabled,\n isRunning:\n lastMessage?.role !== \"assistant\"\n ? false\n : lastMessage.status.type === \"running\",\n messages: runtime.messages,\n suggestions: runtime.suggestions,\n extras: runtime.extras,\n speech: runtime.speech,\n });\n};\n\nexport type ThreadRuntime = Readonly<{\n readonly path: ThreadRuntimePath;\n\n readonly composer: ThreadComposerRuntime;\n getState(): ThreadState;\n\n /**\n * @deprecated This method will be removed in 0.6.0. Submit feedback if you need this functionality.\n */\n unstable_getCore(): ThreadRuntimeCore;\n\n append(message: CreateAppendMessage): void;\n startRun(parentId: string | null): void;\n subscribe(callback: () => void): Unsubscribe;\n cancelRun(): void;\n getModelConfig(): ModelConfig;\n export(): ExportedMessageRepository;\n import(repository: ExportedMessageRepository): void;\n getMesssageByIndex(idx: number): MessageRuntime;\n getMesssageById(messageId: string): MessageRuntime;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n stopSpeaking: () => void;\n\n unstable_on(event: ThreadRuntimeEventType, callback: () => void): Unsubscribe;\n\n // Legacy methods with deprecations\n\n /**\n * @deprecated Use `getState().capabilities` instead. This will be removed in 0.6.0.\n */\n capabilities: Readonly<RuntimeCapabilities>;\n\n /**\n * @deprecated Use `getState().threadId` instead. This will be removed in 0.6.0.\n */\n threadId: string;\n\n /**\n * @deprecated Use `getState().isDisabled` instead. This will be removed in 0.6.0.\n */\n isDisabled: boolean;\n\n /**\n * @deprecated Use `getState().isRunning` instead. This will be removed in 0.6.0.\n */\n isRunning: boolean;\n\n /**\n * @deprecated Use `getState().messages` instead. This will be removed in 0.6.0.\n */\n messages: readonly ThreadMessage[];\n\n /**\n * @deprecated Use `getState().followupSuggestions` instead. This will be removed in 0.6.0.\n */\n suggestions: readonly ThreadSuggestion[];\n\n /**\n * @deprecated Use `getState().speechState` instead. This will be removed in 0.6.0.\n */\n speech: SpeechState | undefined;\n\n /**\n * @deprecated Use `getState().extras` instead. This will be removed in 0.6.0.\n */\n extras: unknown;\n\n /**\n * @deprecated Use `getMesssageById(id).getState().branchNumber` / `getMesssageById(id).getState().branchCount` instead. This will be removed in 0.6.0.\n */\n getBranches: (messageId: string) => readonly string[];\n\n /**\n * @deprecated Use `getMesssageById(id).switchToBranch({ options })` instead. This will be removed in 0.6.0.\n */\n switchToBranch: (branchId: string) => void;\n\n /**\n * @deprecated Use `getMesssageById(id).getContentPartByToolCallId(toolCallId).addToolResult({ result })` instead. This will be removed in 0.6.0.\n */\n addToolResult: (options: AddToolResultOptions) => void;\n\n /**\n * @deprecated Use `getMesssageById(id).speak()` instead. This will be removed in 0.6.0.\n */\n speak: (messageId: string) => void;\n\n /**\n * @deprecated Use `getMesssageById(id).getState().submittedFeedback` instead. This will be removed in 0.6.0.\n */\n getSubmittedFeedback: (messageId: string) => SubmittedFeedback | undefined;\n\n /**\n * @deprecated Use `getMesssageById(id).submitFeedback({ type })` instead. This will be removed in 0.6.0.\n */\n submitFeedback: (feedback: SubmitFeedbackOptions) => void;\n\n /**\n * @deprecated Use `getMesssageById(id).composer` instead. This will be removed in 0.6.0.\n */\n getEditComposer: (messageId: string) => ComposerRuntimeCore | undefined;\n\n /**\n * @deprecated Use `getMesssageById(id).composer.beginEdit()` instead. This will be removed in 0.6.0.\n */\n beginEdit: (messageId: string) => void;\n}>;\n\nexport class ThreadRuntimeImpl\n implements Omit<ThreadRuntimeCore, \"getMessageById\">, ThreadRuntime\n{\n public get path() {\n return this._threadBinding.path;\n }\n\n /**\n * @deprecated Use `getState().threadId` instead. This will be removed in 0.6.0.\n */\n public get threadId() {\n return this.getState().threadId;\n }\n\n /**\n * @deprecated Use `getState().isDisabled` instead. This will be removed in 0.6.0.\n */\n public get isDisabled() {\n return this.getState().isDisabled;\n }\n\n /**\n * @deprecated Use `getState().isRunning` instead. This will be removed in 0.6.0.\n */\n public get isRunning() {\n return this.getState().isRunning;\n }\n\n /**\n * @deprecated Use `getState().capabilities` instead. This will be removed in 0.6.0.\n */\n public get capabilities() {\n return this.getState().capabilities;\n }\n\n /**\n * @deprecated Use `getState().extras` instead. This will be removed in 0.6.0.\n */\n public get extras() {\n return this._threadBinding.getState().extras;\n }\n\n /**\n * @deprecated Use `getState().followupSuggestions` instead. This will be removed in 0.6.0.\n */\n public get suggestions() {\n return this._threadBinding.getState().suggestions;\n }\n\n /**\n * @deprecated Use `getState().messages` instead. This will be removed in 0.6.0.\n */\n public get messages() {\n return this._threadBinding.getState().messages;\n }\n\n /**\n * @deprecated Use `getState().speechState` instead. This will be removed in 0.6.0.\n */\n public get speech() {\n return this._threadBinding.getState().speech;\n }\n\n public unstable_getCore() {\n return this._threadBinding.getState();\n }\n\n private _threadBinding: ThreadRuntimeCoreBinding & {\n getStateState(): ThreadState;\n };\n\n constructor(threadBinding: ThreadRuntimeCoreBinding) {\n const stateBinding = new LazyMemoizeSubject({\n path: threadBinding.path,\n getState: () => getThreadState(threadBinding.getState()),\n subscribe: (callback) => threadBinding.subscribe(callback),\n });\n\n this._threadBinding = {\n path: threadBinding.path,\n getState: () => threadBinding.getState(),\n getStateState: () => stateBinding.getState(),\n outerSubscribe: (callback) => threadBinding.outerSubscribe(callback),\n subscribe: (callback) => threadBinding.subscribe(callback),\n };\n\n this.composer = new ThreadComposerRuntimeImpl(\n new NestedSubscriptionSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.composer`,\n composerSource: \"thread\",\n },\n getState: () => this._threadBinding.getState().composer,\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n );\n }\n\n public readonly composer;\n\n public getState() {\n return this._threadBinding.getStateState();\n }\n\n public append(message: CreateAppendMessage) {\n this._threadBinding\n .getState()\n .append(\n toAppendMessage(this._threadBinding.getState().messages, message),\n );\n }\n\n public subscribe(callback: () => void) {\n return this._threadBinding.subscribe(callback);\n }\n\n /**\n * @derprecated Use `getMesssageById(id).getState().branchNumber` / `getMesssageById(id).getState().branchCount` instead. This will be removed in 0.6.0.\n */\n public getBranches(messageId: string) {\n return this._threadBinding.getState().getBranches(messageId);\n }\n\n public getModelConfig() {\n return this._threadBinding.getState().getModelConfig();\n }\n\n // TODO sometimes you want to continue when there is no child message\n public startRun(parentId: string | null) {\n return this._threadBinding.getState().startRun(parentId);\n }\n\n public cancelRun() {\n this._threadBinding.getState().cancelRun();\n }\n\n /**\n * @deprecated Use `getMesssageById(id).getContentPartByToolCallId(toolCallId).addToolResult({ result })` instead. This will be removed in 0.6.0.\n */\n public addToolResult(options: AddToolResultOptions) {\n this._threadBinding.getState().addToolResult(options);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).switchToBranch({ options })` instead. This will be removed in 0.6.0.\n */\n public switchToBranch(branchId: string) {\n return this._threadBinding.getState().switchToBranch(branchId);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).speak()` instead. This will be removed in 0.6.0.\n */\n public speak(messageId: string) {\n return this._threadBinding.getState().speak(messageId);\n }\n\n public stopSpeaking() {\n return this._threadBinding.getState().stopSpeaking();\n }\n\n public getSubmittedFeedback(messageId: string) {\n return this._threadBinding.getState().getSubmittedFeedback(messageId);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).submitFeedback({ type })` instead. This will be removed in 0.6.0.\n */\n public submitFeedback(options: SubmitFeedbackOptions) {\n return this._threadBinding.getState().submitFeedback(options);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).getMessageByIndex(idx).composer` instead. This will be removed in 0.6.0.\n */\n public getEditComposer(messageId: string) {\n return this._threadBinding.getState().getEditComposer(messageId);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).getMessageByIndex(idx).composer.beginEdit()` instead. This will be removed in 0.6.0.\n */\n public beginEdit(messageId: string) {\n return this._threadBinding.getState().beginEdit(messageId);\n }\n\n public export() {\n return this._threadBinding.getState().export();\n }\n\n public import(data: ExportedMessageRepository) {\n this._threadBinding.getState().import(data);\n }\n\n public getMesssageByIndex(idx: number) {\n if (idx < 0) throw new Error(\"Message index must be >= 0\");\n\n return this._getMessageRuntime(\n {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.messages[${idx}]`,\n messageSelector: { type: \"index\", index: idx },\n },\n () => {\n const messages = this._threadBinding.getState().messages;\n const message = messages[idx];\n if (!message) return undefined;\n return {\n message,\n parentId: messages[idx - 1]?.id ?? null,\n };\n },\n );\n }\n\n public getMesssageById(messageId: string) {\n return this._getMessageRuntime(\n {\n ...this.path,\n ref:\n this.path.ref +\n `${this.path.ref}.messages[messageId=${JSON.stringify(messageId)}]`,\n messageSelector: { type: \"messageId\", messageId: messageId },\n },\n () => this._threadBinding.getState().getMessageById(messageId),\n );\n }\n\n private _getMessageRuntime(\n path: MessageRuntimePath,\n callback: () =>\n | { parentId: string | null; message: ThreadMessage }\n | undefined,\n ) {\n return new MessageRuntimeImpl(\n new ShallowMemoizeSubject({\n path,\n getState: () => {\n const { message, parentId } = callback() ?? {};\n\n const { messages, speech: speechState } =\n this._threadBinding.getState();\n\n if (!message || parentId === undefined) return SKIP_UPDATE;\n\n const thread = this._threadBinding.getState();\n\n const branches = thread.getBranches(message.id);\n const submittedFeedback = thread.getSubmittedFeedback(message.id);\n\n return {\n ...message,\n\n message,\n isLast: messages.at(-1)?.id === message.id,\n parentId,\n\n branches,\n branchNumber: branches.indexOf(message.id) + 1,\n branchCount: branches.length,\n\n speech:\n speechState?.messageId === message.id ? speechState : undefined,\n\n submittedFeedback,\n } satisfies MessageState;\n },\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n this._threadBinding,\n );\n }\n\n private _eventListenerNestedSubscriptions = new Map<\n string,\n NestedSubscriptionSubject<Subscribable, ThreadRuntimePath>\n >();\n\n public unstable_on(\n event: ThreadRuntimeEventType,\n callback: () => void,\n ): Unsubscribe {\n let subject = this._eventListenerNestedSubscriptions.get(event);\n if (!subject) {\n subject = new NestedSubscriptionSubject({\n path: this.path,\n getState: () => ({\n subscribe: (callback) =>\n this._threadBinding.getState().unstable_on(event, callback),\n }),\n subscribe: (callback) => this._threadBinding.outerSubscribe(callback),\n });\n this._eventListenerNestedSubscriptions.set(event, subject);\n }\n return subject.subscribe(callback);\n }\n}\n"],"mappings":"AAiBA;AAAA,EAEE;AAAA,OAEK;AACP,SAAS,iCAAiC;AAC1C,SAAS,6BAA6B;AAKtC;AAAA,EAEE;AAAA,OACK;AACP,SAAS,0BAA0B;AACnC,SAAS,mBAAmB;AAa5B,MAAM,kBAAkB,CACtB,UACA,YACkB;AAClB,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO;AAAA,MACL,UAAU,SAAS,GAAG,EAAE,GAAG,MAAM;AAAA,MACjC,MAAM;AAAA,MACN,SAAS,CAAC,EAAE,MAAM,QAAQ,MAAM,QAAQ,CAAC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C,gBAAM,SAAS,KAAK,eAAe,SAAS;AAE5C,gBAAM,WAAW,OAAO,YAAY,QAAQ,EAAE;AAC9C,gBAAM,oBAAoB,OAAO,qBAAqB,QAAQ,EAAE;AAEhE,iBAAO;AAAA,YACL,GAAG;AAAA,YAEH;AAAA,YACA,QAAQ,SAAS,GAAG,EAAE,GAAG,OAAO,QAAQ;AAAA,YACxC;AAAA,YAEA;AAAA,YACA,cAAc,SAAS,QAAQ,QAAQ,EAAE,IAAI;AAAA,YAC7C,aAAa,SAAS;AAAA,YAEtB,QACE,aAAa,cAAc,QAAQ,KAAK,cAAc;AAAA,YAExD;AAAA,UACF;AAAA,QACF;AAAA,QACA,WAAW,CAACA,cAAa,KAAK,eAAe,UAAUA,SAAQ;AAAA,MACjE,CAAC;AAAA,MACD,KAAK;AAAA,IACP;AAAA,EACF;AAAA,EAEQ,oCAAoC,oBAAI,IAG9C;AAAA,EAEK,YACL,OACA,UACa;AACb,QAAI,UAAU,KAAK,kCAAkC,IAAI,KAAK;AAC9D,QAAI,CAAC,SAAS;AACZ,gBAAU,IAAI,0BAA0B;AAAA,QACtC,MAAM,KAAK;AAAA,QACX,UAAU,OAAO;AAAA,UACf,WAAW,CAACA,cACV,KAAK,eAAe,SAAS,EAAE,YAAY,OAAOA,SAAQ;AAAA,QAC9D;AAAA,QACA,WAAW,CAACA,cAAa,KAAK,eAAe,eAAeA,SAAQ;AAAA,MACtE,CAAC;AACD,WAAK,kCAAkC,IAAI,OAAO,OAAO;AAAA,IAC3D;AACA,WAAO,QAAQ,UAAU,QAAQ;AAAA,EACnC;AACF;","names":["callback"]}
1
+ {"version":3,"sources":["../../src/api/ThreadRuntime.ts"],"sourcesContent":["import {\n AddToolResultOptions,\n ThreadSuggestion,\n RuntimeCapabilities,\n SubmitFeedbackOptions,\n ThreadRuntimeCore,\n SpeechState,\n SubmittedFeedback,\n ThreadRuntimeEventType,\n} from \"../runtimes/core/ThreadRuntimeCore\";\nimport { ExportedMessageRepository } from \"../runtimes/utils/MessageRepository\";\nimport {\n AppendMessage,\n ModelConfig,\n ThreadMessage,\n Unsubscribe,\n} from \"../types\";\nimport {\n MessageRuntime,\n MessageRuntimeImpl,\n MessageState,\n} from \"./MessageRuntime\";\nimport { NestedSubscriptionSubject } from \"./subscribable/NestedSubscriptionSubject\";\nimport { ShallowMemoizeSubject } from \"./subscribable/ShallowMemoizeSubject\";\nimport {\n Subscribable,\n SubscribableWithState,\n} from \"./subscribable/Subscribable\";\nimport {\n ThreadComposerRuntime,\n ThreadComposerRuntimeImpl,\n} from \"./ComposerRuntime\";\nimport { LazyMemoizeSubject } from \"./subscribable/LazyMemoizeSubject\";\nimport { SKIP_UPDATE } from \"./subscribable/SKIP_UPDATE\";\nimport { ComposerRuntimeCore } from \"../runtimes/core/ComposerRuntimeCore\";\nimport { MessageRuntimePath, ThreadRuntimePath } from \"./RuntimePathTypes\";\n\nexport type CreateAppendMessage =\n | string\n | {\n parentId?: string | null | undefined;\n role?: AppendMessage[\"role\"] | undefined;\n content: AppendMessage[\"content\"];\n attachments?: AppendMessage[\"attachments\"] | undefined;\n };\n\nconst toAppendMessage = (\n messages: readonly ThreadMessage[],\n message: CreateAppendMessage,\n): AppendMessage => {\n if (typeof message === \"string\") {\n return {\n parentId: messages.at(-1)?.id ?? null,\n role: \"user\",\n content: [{ type: \"text\", text: message }],\n attachments: [],\n };\n }\n\n if (message.role && message.parentId && message.attachments) {\n return message as AppendMessage;\n }\n\n return {\n parentId: message.parentId ?? messages.at(-1)?.id ?? null,\n role: message.role ?? \"user\",\n content: message.content,\n attachments: message.attachments ?? [],\n } as AppendMessage;\n};\n\nexport type ThreadRuntimeCoreBinding = SubscribableWithState<\n ThreadRuntimeCore,\n ThreadRuntimePath\n> & {\n outerSubscribe(callback: () => void): Unsubscribe;\n};\n\nexport type ThreadState = Readonly<{\n /**\n * The thread ID.\n */\n threadId: string;\n /**\n * Whether the thread is disabled. Disabled threads cannot receive new messages.\n */\n isDisabled: boolean;\n\n /**\n * Whether the thread is running. A thread is considered running when there is an active stream connection to the backend.\n */\n isRunning: boolean;\n\n /**\n * The capabilities of the thread, such as whether the thread supports editing, branch switching, etc.\n */\n capabilities: RuntimeCapabilities;\n\n /**\n * The messages in the currently selected branch of the thread.\n */\n messages: readonly ThreadMessage[];\n\n /**\n * Follow up message suggestions to show the user.\n */\n suggestions: readonly ThreadSuggestion[];\n\n /**\n * Custom extra information provided by the runtime.\n */\n extras: unknown;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n speech: SpeechState | undefined;\n}>;\n\nexport const getThreadState = (runtime: ThreadRuntimeCore): ThreadState => {\n const lastMessage = runtime.messages.at(-1);\n return Object.freeze({\n threadId: runtime.threadId,\n capabilities: runtime.capabilities,\n isDisabled: runtime.isDisabled,\n isRunning:\n lastMessage?.role !== \"assistant\"\n ? false\n : lastMessage.status.type === \"running\",\n messages: runtime.messages,\n suggestions: runtime.suggestions,\n extras: runtime.extras,\n speech: runtime.speech,\n });\n};\n\nexport type ThreadRuntime = Readonly<{\n readonly path: ThreadRuntimePath;\n\n readonly composer: ThreadComposerRuntime;\n getState(): ThreadState;\n\n /**\n * @deprecated This method will be removed in 0.6.0. Submit feedback if you need this functionality.\n */\n unstable_getCore(): ThreadRuntimeCore;\n\n append(message: CreateAppendMessage): void;\n startRun(parentId: string | null): void;\n subscribe(callback: () => void): Unsubscribe;\n cancelRun(): void;\n getModelConfig(): ModelConfig;\n export(): ExportedMessageRepository;\n import(repository: ExportedMessageRepository): void;\n getMesssageByIndex(idx: number): MessageRuntime;\n getMesssageById(messageId: string): MessageRuntime;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n stopSpeaking: () => void;\n\n unstable_on(event: ThreadRuntimeEventType, callback: () => void): Unsubscribe;\n\n // Legacy methods with deprecations\n\n /**\n * @deprecated Use `getState().capabilities` instead. This will be removed in 0.6.0.\n */\n capabilities: Readonly<RuntimeCapabilities>;\n\n /**\n * @deprecated Use `getState().threadId` instead. This will be removed in 0.6.0.\n */\n threadId: string;\n\n /**\n * @deprecated Use `getState().isDisabled` instead. This will be removed in 0.6.0.\n */\n isDisabled: boolean;\n\n /**\n * @deprecated Use `getState().isRunning` instead. This will be removed in 0.6.0.\n */\n isRunning: boolean;\n\n /**\n * @deprecated Use `getState().messages` instead. This will be removed in 0.6.0.\n */\n messages: readonly ThreadMessage[];\n\n /**\n * @deprecated Use `getState().followupSuggestions` instead. This will be removed in 0.6.0.\n */\n suggestions: readonly ThreadSuggestion[];\n\n /**\n * @deprecated Use `getState().speechState` instead. This will be removed in 0.6.0.\n */\n speech: SpeechState | undefined;\n\n /**\n * @deprecated Use `getState().extras` instead. This will be removed in 0.6.0.\n */\n extras: unknown;\n\n /**\n * @deprecated Use `getMesssageById(id).getState().branchNumber` / `getMesssageById(id).getState().branchCount` instead. This will be removed in 0.6.0.\n */\n getBranches: (messageId: string) => readonly string[];\n\n /**\n * @deprecated Use `getMesssageById(id).switchToBranch({ options })` instead. This will be removed in 0.6.0.\n */\n switchToBranch: (branchId: string) => void;\n\n /**\n * @deprecated Use `getMesssageById(id).getContentPartByToolCallId(toolCallId).addToolResult({ result })` instead. This will be removed in 0.6.0.\n */\n addToolResult: (options: AddToolResultOptions) => void;\n\n /**\n * @deprecated Use `getMesssageById(id).speak()` instead. This will be removed in 0.6.0.\n */\n speak: (messageId: string) => void;\n\n /**\n * @deprecated Use `getMesssageById(id).getState().submittedFeedback` instead. This will be removed in 0.6.0.\n */\n getSubmittedFeedback: (messageId: string) => SubmittedFeedback | undefined;\n\n /**\n * @deprecated Use `getMesssageById(id).submitFeedback({ type })` instead. This will be removed in 0.6.0.\n */\n submitFeedback: (feedback: SubmitFeedbackOptions) => void;\n\n /**\n * @deprecated Use `getMesssageById(id).composer` instead. This will be removed in 0.6.0.\n */\n getEditComposer: (messageId: string) => ComposerRuntimeCore | undefined;\n\n /**\n * @deprecated Use `getMesssageById(id).composer.beginEdit()` instead. This will be removed in 0.6.0.\n */\n beginEdit: (messageId: string) => void;\n}>;\n\nexport class ThreadRuntimeImpl\n implements Omit<ThreadRuntimeCore, \"getMessageById\">, ThreadRuntime\n{\n public get path() {\n return this._threadBinding.path;\n }\n\n /**\n * @deprecated Use `getState().threadId` instead. This will be removed in 0.6.0.\n */\n public get threadId() {\n return this.getState().threadId;\n }\n\n /**\n * @deprecated Use `getState().isDisabled` instead. This will be removed in 0.6.0.\n */\n public get isDisabled() {\n return this.getState().isDisabled;\n }\n\n /**\n * @deprecated Use `getState().isRunning` instead. This will be removed in 0.6.0.\n */\n public get isRunning() {\n return this.getState().isRunning;\n }\n\n /**\n * @deprecated Use `getState().capabilities` instead. This will be removed in 0.6.0.\n */\n public get capabilities() {\n return this.getState().capabilities;\n }\n\n /**\n * @deprecated Use `getState().extras` instead. This will be removed in 0.6.0.\n */\n public get extras() {\n return this._threadBinding.getState().extras;\n }\n\n /**\n * @deprecated Use `getState().followupSuggestions` instead. This will be removed in 0.6.0.\n */\n public get suggestions() {\n return this._threadBinding.getState().suggestions;\n }\n\n /**\n * @deprecated Use `getState().messages` instead. This will be removed in 0.6.0.\n */\n public get messages() {\n return this._threadBinding.getState().messages;\n }\n\n /**\n * @deprecated Use `getState().speechState` instead. This will be removed in 0.6.0.\n */\n public get speech() {\n return this._threadBinding.getState().speech;\n }\n\n public unstable_getCore() {\n return this._threadBinding.getState();\n }\n\n private _threadBinding: ThreadRuntimeCoreBinding & {\n getStateState(): ThreadState;\n };\n\n constructor(threadBinding: ThreadRuntimeCoreBinding) {\n const stateBinding = new LazyMemoizeSubject({\n path: threadBinding.path,\n getState: () => getThreadState(threadBinding.getState()),\n subscribe: (callback) => threadBinding.subscribe(callback),\n });\n\n this._threadBinding = {\n path: threadBinding.path,\n getState: () => threadBinding.getState(),\n getStateState: () => stateBinding.getState(),\n outerSubscribe: (callback) => threadBinding.outerSubscribe(callback),\n subscribe: (callback) => threadBinding.subscribe(callback),\n };\n\n this.composer = new ThreadComposerRuntimeImpl(\n new NestedSubscriptionSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.composer`,\n composerSource: \"thread\",\n },\n getState: () => this._threadBinding.getState().composer,\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n );\n }\n\n public readonly composer;\n\n public getState() {\n return this._threadBinding.getStateState();\n }\n\n public append(message: CreateAppendMessage) {\n this._threadBinding\n .getState()\n .append(\n toAppendMessage(this._threadBinding.getState().messages, message),\n );\n }\n\n public subscribe(callback: () => void) {\n return this._threadBinding.subscribe(callback);\n }\n\n /**\n * @derprecated Use `getMesssageById(id).getState().branchNumber` / `getMesssageById(id).getState().branchCount` instead. This will be removed in 0.6.0.\n */\n public getBranches(messageId: string) {\n return this._threadBinding.getState().getBranches(messageId);\n }\n\n public getModelConfig() {\n return this._threadBinding.getState().getModelConfig();\n }\n\n // TODO sometimes you want to continue when there is no child message\n public startRun(parentId: string | null) {\n return this._threadBinding.getState().startRun(parentId);\n }\n\n public cancelRun() {\n this._threadBinding.getState().cancelRun();\n }\n\n /**\n * @deprecated Use `getMesssageById(id).getContentPartByToolCallId(toolCallId).addToolResult({ result })` instead. This will be removed in 0.6.0.\n */\n public addToolResult(options: AddToolResultOptions) {\n this._threadBinding.getState().addToolResult(options);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).switchToBranch({ options })` instead. This will be removed in 0.6.0.\n */\n public switchToBranch(branchId: string) {\n return this._threadBinding.getState().switchToBranch(branchId);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).speak()` instead. This will be removed in 0.6.0.\n */\n public speak(messageId: string) {\n return this._threadBinding.getState().speak(messageId);\n }\n\n public stopSpeaking() {\n return this._threadBinding.getState().stopSpeaking();\n }\n\n public getSubmittedFeedback(messageId: string) {\n return this._threadBinding.getState().getSubmittedFeedback(messageId);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).submitFeedback({ type })` instead. This will be removed in 0.6.0.\n */\n public submitFeedback(options: SubmitFeedbackOptions) {\n return this._threadBinding.getState().submitFeedback(options);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).getMessageByIndex(idx).composer` instead. This will be removed in 0.6.0.\n */\n public getEditComposer(messageId: string) {\n return this._threadBinding.getState().getEditComposer(messageId);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).getMessageByIndex(idx).composer.beginEdit()` instead. This will be removed in 0.6.0.\n */\n public beginEdit(messageId: string) {\n return this._threadBinding.getState().beginEdit(messageId);\n }\n\n public export() {\n return this._threadBinding.getState().export();\n }\n\n public import(data: ExportedMessageRepository) {\n this._threadBinding.getState().import(data);\n }\n\n public getMesssageByIndex(idx: number) {\n if (idx < 0) throw new Error(\"Message index must be >= 0\");\n\n return this._getMessageRuntime(\n {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.messages[${idx}]`,\n messageSelector: { type: \"index\", index: idx },\n },\n () => {\n const messages = this._threadBinding.getState().messages;\n const message = messages[idx];\n if (!message) return undefined;\n return {\n message,\n parentId: messages[idx - 1]?.id ?? null,\n };\n },\n );\n }\n\n public getMesssageById(messageId: string) {\n return this._getMessageRuntime(\n {\n ...this.path,\n ref:\n this.path.ref +\n `${this.path.ref}.messages[messageId=${JSON.stringify(messageId)}]`,\n messageSelector: { type: \"messageId\", messageId: messageId },\n },\n () => this._threadBinding.getState().getMessageById(messageId),\n );\n }\n\n private _getMessageRuntime(\n path: MessageRuntimePath,\n callback: () =>\n | { parentId: string | null; message: ThreadMessage }\n | undefined,\n ) {\n return new MessageRuntimeImpl(\n new ShallowMemoizeSubject({\n path,\n getState: () => {\n const { message, parentId } = callback() ?? {};\n\n const { messages, speech: speechState } =\n this._threadBinding.getState();\n\n if (!message || parentId === undefined) return SKIP_UPDATE;\n\n const thread = this._threadBinding.getState();\n\n const branches = thread.getBranches(message.id);\n const submittedFeedback = thread.getSubmittedFeedback(message.id);\n\n return {\n ...message,\n\n message,\n isLast: messages.at(-1)?.id === message.id,\n parentId,\n\n branches,\n branchNumber: branches.indexOf(message.id) + 1,\n branchCount: branches.length,\n\n speech:\n speechState?.messageId === message.id ? speechState : undefined,\n\n submittedFeedback,\n } satisfies MessageState;\n },\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n this._threadBinding,\n );\n }\n\n private _eventListenerNestedSubscriptions = new Map<\n string,\n NestedSubscriptionSubject<Subscribable, ThreadRuntimePath>\n >();\n\n public unstable_on(\n event: ThreadRuntimeEventType,\n callback: () => void,\n ): Unsubscribe {\n let subject = this._eventListenerNestedSubscriptions.get(event);\n if (!subject) {\n subject = new NestedSubscriptionSubject({\n path: this.path,\n getState: () => ({\n subscribe: (callback) =>\n this._threadBinding.getState().unstable_on(event, callback),\n }),\n subscribe: (callback) => this._threadBinding.outerSubscribe(callback),\n });\n this._eventListenerNestedSubscriptions.set(event, subject);\n }\n return subject.subscribe(callback);\n }\n}\n"],"mappings":"AAiBA;AAAA,EAEE;AAAA,OAEK;AACP,SAAS,iCAAiC;AAC1C,SAAS,6BAA6B;AAKtC;AAAA,EAEE;AAAA,OACK;AACP,SAAS,0BAA0B;AACnC,SAAS,mBAAmB;AAa5B,MAAM,kBAAkB,CACtB,UACA,YACkB;AAClB,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO;AAAA,MACL,UAAU,SAAS,GAAG,EAAE,GAAG,MAAM;AAAA,MACjC,MAAM;AAAA,MACN,SAAS,CAAC,EAAE,MAAM,QAAQ,MAAM,QAAQ,CAAC;AAAA,MACzC,aAAa,CAAC;AAAA,IAChB;AAAA,EACF;AAEA,MAAI,QAAQ,QAAQ,QAAQ,YAAY,QAAQ,aAAa;AAC3D,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL,UAAU,QAAQ,YAAY,SAAS,GAAG,EAAE,GAAG,MAAM;AAAA,IACrD,MAAM,QAAQ,QAAQ;AAAA,IACtB,SAAS,QAAQ;AAAA,IACjB,aAAa,QAAQ,eAAe,CAAC;AAAA,EACvC;AACF;AAkDO,MAAM,iBAAiB,CAAC,YAA4C;AACzE,QAAM,cAAc,QAAQ,SAAS,GAAG,EAAE;AAC1C,SAAO,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AAA,QACF;AAAA,QACA,WAAW,CAACA,cAAa,KAAK,eAAe,UAAUA,SAAQ;AAAA,MACjE,CAAC;AAAA,MACD,KAAK;AAAA,IACP;AAAA,EACF;AAAA,EAEQ,oCAAoC,oBAAI,IAG9C;AAAA,EAEK,YACL,OACA,UACa;AACb,QAAI,UAAU,KAAK,kCAAkC,IAAI,KAAK;AAC9D,QAAI,CAAC,SAAS;AACZ,gBAAU,IAAI,0BAA0B;AAAA,QACtC,MAAM,KAAK;AAAA,QACX,UAAU,OAAO;AAAA,UACf,WAAW,CAACA,cACV,KAAK,eAAe,SAAS,EAAE,YAAY,OAAOA,SAAQ;AAAA,QAC9D;AAAA,QACA,WAAW,CAACA,cAAa,KAAK,eAAe,eAAeA,SAAQ;AAAA,MACtE,CAAC;AACD,WAAK,kCAAkC,IAAI,OAAO,OAAO;AAAA,IAC3D;AACA,WAAO,QAAQ,UAAU,QAAQ;AAAA,EACnC;AACF;","names":["callback"]}
@@ -10,6 +10,11 @@ export type EdgeChatAdapterOptions = {
10
10
  * When enabled, the adapter will not strip `id` from messages in the messages array.
11
11
  */
12
12
  unstable_sendMessageIds?: boolean;
13
+ /**
14
+ * When enabled, the adapter will send messages in the format expected by the Vercel AI SDK Core.
15
+ * This feature will be removed in the future in favor of a better solution.
16
+ */
17
+ unstable_AISDKInterop?: boolean | undefined;
13
18
  };
14
19
  export declare class EdgeChatAdapter implements ChatModelAdapter {
15
20
  private options;
@@ -1 +1 @@
1
- {"version":3,"file":"EdgeChatAdapter.d.ts","sourceRoot":"","sources":["../../../src/runtimes/edge/EdgeChatAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACpB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAS/D,wBAAgB,eAAe,CAAC,CAAC,EAC/B,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,GACxB,aAAa,CAAC,CAAC,CAAC,C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;IAE5C,GAAG,CAAC,EACT,QAAQ,EACR,WAAW,EACX,MAAM,EACN,2BAA2B,GAC5B,EAAE,mBAAmB;CA6CvB"}
@@ -28,6 +28,7 @@ var import_assistantDecoderStream = require("./streams/assistantDecoderStream");
28
28
  var import_streamPartDecoderStream = require("./streams/utils/streamPartDecoderStream");
29
29
  var import_runResultStream = require("./streams/runResultStream");
30
30
  var import_toolResultStream = require("./streams/toolResultStream");
31
+ var import_converters = require("./converters");
31
32
  function asAsyncIterable(source) {
32
33
  return {
33
34
  [Symbol.asyncIterator]: () => {
@@ -59,7 +60,9 @@ class EdgeChatAdapter {
59
60
  credentials: this.options.credentials ?? "same-origin",
60
61
  body: JSON.stringify({
61
62
  system: config.system,
62
- messages: (0, import_toCoreMessages.toCoreMessages)(messages, {
63
+ messages: this.options.unstable_AISDKInterop ? (0, import_converters.toLanguageModelMessages)(
64
+ messages
65
+ ) : (0, import_toCoreMessages.toCoreMessages)(messages, {
63
66
  unstable_includeId: this.options.unstable_sendMessageIds
64
67
  }),
65
68
  tools: config.tools ? (0, import_toLanguageModelTools.toLanguageModelTools)(config.tools) : [],
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/runtimes/edge/EdgeChatAdapter.ts"],"sourcesContent":["import {\n ChatModelAdapter,\n ChatModelRunOptions,\n} from \"../local/ChatModelAdapter\";\nimport { ChatModelRunResult } from \"../local/ChatModelAdapter\";\nimport { toCoreMessages } from \"./converters/toCoreMessages\";\nimport { toLanguageModelTools } from \"./converters/toLanguageModelTools\";\nimport { EdgeRuntimeRequestOptions } from \"./EdgeRuntimeRequestOptions\";\nimport { assistantDecoderStream } from \"./streams/assistantDecoderStream\";\nimport { streamPartDecoderStream } from \"./streams/utils/streamPartDecoderStream\";\nimport { runResultStream } from \"./streams/runResultStream\";\nimport { toolResultStream } from \"./streams/toolResultStream\";\n\nexport function asAsyncIterable<T>(\n source: ReadableStream<T>,\n): AsyncIterable<T> {\n return {\n [Symbol.asyncIterator]: () => {\n const reader = source.getReader();\n return {\n async next(): Promise<IteratorResult<T, undefined>> {\n const { done, value } = await reader.read();\n return done\n ? { done: true, value: undefined }\n : { done: false, value };\n },\n };\n },\n };\n}\nexport type EdgeChatAdapterOptions = {\n api: string;\n\n credentials?: RequestCredentials;\n headers?: Record<string, string> | Headers;\n body?: object;\n\n /**\n * When enabled, the adapter will not strip `id` from messages in the messages array.\n */\n unstable_sendMessageIds?: boolean;\n};\n\nexport class EdgeChatAdapter implements ChatModelAdapter {\n constructor(private options: EdgeChatAdapterOptions) {}\n\n async *run({\n messages,\n abortSignal,\n config,\n unstable_assistantMessageId,\n }: ChatModelRunOptions) {\n const headers = new Headers(this.options.headers);\n headers.set(\"Content-Type\", \"application/json\");\n\n const result = await fetch(this.options.api, {\n method: \"POST\",\n headers,\n credentials: this.options.credentials ?? \"same-origin\",\n body: JSON.stringify({\n system: config.system,\n messages: toCoreMessages(messages, {\n unstable_includeId: this.options.unstable_sendMessageIds,\n }),\n tools: config.tools ? toLanguageModelTools(config.tools) : [],\n unstable_assistantMessageId,\n ...config.callSettings,\n ...config.config,\n\n ...this.options.body,\n } satisfies EdgeRuntimeRequestOptions),\n signal: abortSignal,\n });\n\n if (!result.ok) {\n throw new Error(`Status ${result.status}: ${await result.text()}`);\n }\n\n const stream = result\n .body!.pipeThrough(streamPartDecoderStream())\n .pipeThrough(assistantDecoderStream())\n .pipeThrough(toolResultStream(config.tools, abortSignal))\n .pipeThrough(runResultStream());\n\n let update: ChatModelRunResult | undefined;\n for await (update of asAsyncIterable(stream)) {\n yield update;\n }\n\n if (update === undefined)\n throw new Error(\"No data received from Edge Runtime\");\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,4BAA+B;AAC/B,kCAAqC;AAErC,oCAAuC;AACvC,qCAAwC;AACxC,6BAAgC;AAChC,8BAAiC;AAE1B,SAAS,gBACd,QACkB;AAClB,SAAO;AAAA,IACL,CAAC,OAAO,aAA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AAgB,CAAC;AAEhC,QAAI;AACJ,eAAW,UAAU,gBAAgB,MAAM,GAAG;AAC5C,YAAM;AAAA,IACR;AAEA,QAAI,WAAW;AACb,YAAM,IAAI,MAAM,oCAAoC;AAAA,EACxD;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/runtimes/edge/EdgeChatAdapter.ts"],"sourcesContent":["import {\n ChatModelAdapter,\n ChatModelRunOptions,\n} from \"../local/ChatModelAdapter\";\nimport { ChatModelRunResult } from \"../local/ChatModelAdapter\";\nimport { toCoreMessages } from \"./converters/toCoreMessages\";\nimport { toLanguageModelTools } from \"./converters/toLanguageModelTools\";\nimport { EdgeRuntimeRequestOptions } from \"./EdgeRuntimeRequestOptions\";\nimport { assistantDecoderStream } from \"./streams/assistantDecoderStream\";\nimport { streamPartDecoderStream } from \"./streams/utils/streamPartDecoderStream\";\nimport { runResultStream } from \"./streams/runResultStream\";\nimport { toolResultStream } from \"./streams/toolResultStream\";\nimport { toLanguageModelMessages } from \"./converters\";\n\nexport function asAsyncIterable<T>(\n source: ReadableStream<T>,\n): AsyncIterable<T> {\n return {\n [Symbol.asyncIterator]: () => {\n const reader = source.getReader();\n return {\n async next(): Promise<IteratorResult<T, undefined>> {\n const { done, value } = await reader.read();\n return done\n ? { done: true, value: undefined }\n : { done: false, value };\n },\n };\n },\n };\n}\nexport type EdgeChatAdapterOptions = {\n api: string;\n\n credentials?: RequestCredentials;\n headers?: Record<string, string> | Headers;\n body?: object;\n\n /**\n * When enabled, the adapter will not strip `id` from messages in the messages array.\n */\n unstable_sendMessageIds?: boolean;\n\n /**\n * When enabled, the adapter will send messages in the format expected by the Vercel AI SDK Core.\n * This feature will be removed in the future in favor of a better solution.\n */\n unstable_AISDKInterop?: boolean | undefined;\n};\n\nexport class EdgeChatAdapter implements ChatModelAdapter {\n constructor(private options: EdgeChatAdapterOptions) {}\n\n async *run({\n messages,\n abortSignal,\n config,\n unstable_assistantMessageId,\n }: ChatModelRunOptions) {\n const headers = new Headers(this.options.headers);\n headers.set(\"Content-Type\", \"application/json\");\n\n const result = await fetch(this.options.api, {\n method: \"POST\",\n headers,\n credentials: this.options.credentials ?? \"same-origin\",\n body: JSON.stringify({\n system: config.system,\n messages: this.options.unstable_AISDKInterop\n ? (toLanguageModelMessages(\n messages,\n ) as EdgeRuntimeRequestOptions[\"messages\"]) // TODO figure out a better way to do this\n : toCoreMessages(messages, {\n unstable_includeId: this.options.unstable_sendMessageIds,\n }),\n tools: config.tools ? toLanguageModelTools(config.tools) : [],\n unstable_assistantMessageId,\n ...config.callSettings,\n ...config.config,\n\n ...this.options.body,\n } satisfies EdgeRuntimeRequestOptions),\n signal: abortSignal,\n });\n\n if (!result.ok) {\n throw new Error(`Status ${result.status}: ${await result.text()}`);\n }\n\n const stream = result\n .body!.pipeThrough(streamPartDecoderStream())\n .pipeThrough(assistantDecoderStream())\n .pipeThrough(toolResultStream(config.tools, abortSignal))\n .pipeThrough(runResultStream());\n\n let update: ChatModelRunResult | undefined;\n for await (update of asAsyncIterable(stream)) {\n yield update;\n }\n\n if (update === undefined)\n throw new Error(\"No data received from Edge Runtime\");\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,4BAA+B;AAC/B,kCAAqC;AAErC,oCAAuC;AACvC,qCAAwC;AACxC,6BAAgC;AAChC,8BAAiC;AACjC,wBAAwC;AAEjC,SAAS,gBACd,QACkB;AAClB,SAAO;AAAA,IACL,CAAC,OAAO,aAAa,GAAG,MAAM;AAC5B,YAAM,SAAS,OAAO,UAAU;AAChC,aAAO;AAAA,QACL,MAAM,OAA8C;AAClD,gBAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,iBAAO,OACH,EAAE,MAAM,MAAM,OAAO,OAAU,IAC/B,EAAE,MAAM,OAAO,MAAM;AAAA,QAC3B;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAoBO,MAAM,gBAA4C;AAAA,EACvD,YAAoB,SAAiC;AAAjC;AAAA,EAAkC;AAAA,EAEtD,OAAO,IAAI;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAAwB;AACtB,UAAM,UAAU,IAAI,QAAQ,KAAK,QAAQ,OAAO;AAChD,YAAQ,IAAI,gBAAgB,kBAAkB;AAE9C,UAAM,SAAS,MAAM,MAAM,KAAK,QAAQ,KAAK;AAAA,MAC3C,QAAQ;AAAA,MACR;AAAA,MACA,aAAa,KAAK,QAAQ,eAAe;AAAA,MACzC,MAAM,KAAK,UAAU;AAAA,QACnB,QAAQ,OAAO;AAAA,QACf,UAAU,KAAK,QAAQ,4BAClB;AAAA,UACC;AAAA,QACF,QACA,sCAAe,UAAU;AAAA,UACvB,oBAAoB,KAAK,QAAQ;AAAA,QACnC,CAAC;AAAA,QACL,OAAO,OAAO,YAAQ,kDAAqB,OAAO,KAAK,IAAI,CAAC;AAAA,QAC5D;AAAA,QACA,GAAG,OAAO;AAAA,QACV,GAAG,OAAO;AAAA,QAEV,GAAG,KAAK,QAAQ;AAAA,MAClB,CAAqC;AAAA,MACrC,QAAQ;AAAA,IACV,CAAC;AAED,QAAI,CAAC,OAAO,IAAI;AACd,YAAM,IAAI,MAAM,UAAU,OAAO,MAAM,KAAK,MAAM,OAAO,KAAK,CAAC,EAAE;AAAA,IACnE;AAEA,UAAM,SAAS,OACZ,KAAM,gBAAY,wDAAwB,CAAC,EAC3C,gBAAY,sDAAuB,CAAC,EACpC,gBAAY,0CAAiB,OAAO,OAAO,WAAW,CAAC,EACvD,gBAAY,wCAAgB,CAAC;AAEhC,QAAI;AACJ,eAAW,UAAU,gBAAgB,MAAM,GAAG;AAC5C,YAAM;AAAA,IACR;AAEA,QAAI,WAAW;AACb,YAAM,IAAI,MAAM,oCAAoC;AAAA,EACxD;AACF;","names":[]}
@@ -4,6 +4,7 @@ import { assistantDecoderStream } from "./streams/assistantDecoderStream";
4
4
  import { streamPartDecoderStream } from "./streams/utils/streamPartDecoderStream";
5
5
  import { runResultStream } from "./streams/runResultStream";
6
6
  import { toolResultStream } from "./streams/toolResultStream";
7
+ import { toLanguageModelMessages } from "./converters";
7
8
  function asAsyncIterable(source) {
8
9
  return {
9
10
  [Symbol.asyncIterator]: () => {
@@ -35,7 +36,9 @@ class EdgeChatAdapter {
35
36
  credentials: this.options.credentials ?? "same-origin",
36
37
  body: JSON.stringify({
37
38
  system: config.system,
38
- messages: toCoreMessages(messages, {
39
+ messages: this.options.unstable_AISDKInterop ? toLanguageModelMessages(
40
+ messages
41
+ ) : toCoreMessages(messages, {
39
42
  unstable_includeId: this.options.unstable_sendMessageIds
40
43
  }),
41
44
  tools: config.tools ? toLanguageModelTools(config.tools) : [],
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/runtimes/edge/EdgeChatAdapter.ts"],"sourcesContent":["import {\n ChatModelAdapter,\n ChatModelRunOptions,\n} from \"../local/ChatModelAdapter\";\nimport { ChatModelRunResult } from \"../local/ChatModelAdapter\";\nimport { toCoreMessages } from \"./converters/toCoreMessages\";\nimport { toLanguageModelTools } from \"./converters/toLanguageModelTools\";\nimport { EdgeRuntimeRequestOptions } from \"./EdgeRuntimeRequestOptions\";\nimport { assistantDecoderStream } from \"./streams/assistantDecoderStream\";\nimport { streamPartDecoderStream } from \"./streams/utils/streamPartDecoderStream\";\nimport { runResultStream } from \"./streams/runResultStream\";\nimport { toolResultStream } from \"./streams/toolResultStream\";\n\nexport function asAsyncIterable<T>(\n source: ReadableStream<T>,\n): AsyncIterable<T> {\n return {\n [Symbol.asyncIterator]: () => {\n const reader = source.getReader();\n return {\n async next(): Promise<IteratorResult<T, undefined>> {\n const { done, value } = await reader.read();\n return done\n ? { done: true, value: undefined }\n : { done: false, value };\n },\n };\n },\n };\n}\nexport type EdgeChatAdapterOptions = {\n api: string;\n\n credentials?: RequestCredentials;\n headers?: Record<string, string> | Headers;\n body?: object;\n\n /**\n * When enabled, the adapter will not strip `id` from messages in the messages array.\n */\n unstable_sendMessageIds?: boolean;\n};\n\nexport class EdgeChatAdapter implements ChatModelAdapter {\n constructor(private options: EdgeChatAdapterOptions) {}\n\n async *run({\n messages,\n abortSignal,\n config,\n unstable_assistantMessageId,\n }: ChatModelRunOptions) {\n const headers = new Headers(this.options.headers);\n headers.set(\"Content-Type\", \"application/json\");\n\n const result = await fetch(this.options.api, {\n method: \"POST\",\n headers,\n credentials: this.options.credentials ?? \"same-origin\",\n body: JSON.stringify({\n system: config.system,\n messages: toCoreMessages(messages, {\n unstable_includeId: this.options.unstable_sendMessageIds,\n }),\n tools: config.tools ? toLanguageModelTools(config.tools) : [],\n unstable_assistantMessageId,\n ...config.callSettings,\n ...config.config,\n\n ...this.options.body,\n } satisfies EdgeRuntimeRequestOptions),\n signal: abortSignal,\n });\n\n if (!result.ok) {\n throw new Error(`Status ${result.status}: ${await result.text()}`);\n }\n\n const stream = result\n .body!.pipeThrough(streamPartDecoderStream())\n .pipeThrough(assistantDecoderStream())\n .pipeThrough(toolResultStream(config.tools, abortSignal))\n .pipeThrough(runResultStream());\n\n let update: ChatModelRunResult | undefined;\n for await (update of asAsyncIterable(stream)) {\n yield update;\n }\n\n if (update === undefined)\n throw new Error(\"No data received from Edge Runtime\");\n }\n}\n"],"mappings":"AAKA,SAAS,sBAAsB;AAC/B,SAAS,4BAA4B;AAErC,SAAS,8BAA8B;AACvC,SAAS,+BAA+B;AACxC,SAAS,uBAAuB;AAChC,SAAS,wBAAwB;AAE1B,SAAS,gBACd,QACkB;AAClB,SAAO;AAAA,IACL,CAAC,OAAO,aAAa,GAAG,MAAM;AAC5B,YAAM,SAAS,OAAO,UAAU;AAChC,aAAO;AAAA,QACL,MAAM,OAA8C;AAClD,gBAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,iBAAO,OACH,EAAE,MAAM,MAAM,OAAO,OAAU,IAC/B,EAAE,MAAM,OAAO,MAAM;AAAA,QAC3B;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAcO,MAAM,gBAA4C;AAAA,EACvD,YAAoB,SAAiC;AAAjC;AAAA,EAAkC;AAAA,EAEtD,OAAO,IAAI;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAAwB;AACtB,UAAM,UAAU,IAAI,QAAQ,KAAK,QAAQ,OAAO;AAChD,YAAQ,IAAI,gBAAgB,kBAAkB;AAE9C,UAAM,SAAS,MAAM,MAAM,KAAK,QAAQ,KAAK;AAAA,MAC3C,QAAQ;AAAA,MACR;AAAA,MACA,aAAa,KAAK,QAAQ,eAAe;AAAA,MACzC,MAAM,KAAK,UAAU;AAAA,QACnB,QAAQ,OAAO;AAAA,QACf,UAAU,eAAe,UAAU;AAAA,UACjC,oBAAoB,KAAK,QAAQ;AAAA,QACnC,CAAC;AAAA,QACD,OAAO,OAAO,QAAQ,qBAAqB,OAAO,KAAK,IAAI,CAAC;AAAA,QAC5D;AAAA,QACA,GAAG,OAAO;AAAA,QACV,GAAG,OAAO;AAAA,QAEV,GAAG,KAAK,QAAQ;AAAA,MAClB,CAAqC;AAAA,MACrC,QAAQ;AAAA,IACV,CAAC;AAED,QAAI,CAAC,OAAO,IAAI;AACd,YAAM,IAAI,MAAM,UAAU,OAAO,MAAM,KAAK,MAAM,OAAO,KAAK,CAAC,EAAE;AAAA,IACnE;AAEA,UAAM,SAAS,OACZ,KAAM,YAAY,wBAAwB,CAAC,EAC3C,YAAY,uBAAuB,CAAC,EACpC,YAAY,iBAAiB,OAAO,OAAO,WAAW,CAAC,EACvD,YAAY,gBAAgB,CAAC;AAEhC,QAAI;AACJ,eAAW,UAAU,gBAAgB,MAAM,GAAG;AAC5C,YAAM;AAAA,IACR;AAEA,QAAI,WAAW;AACb,YAAM,IAAI,MAAM,oCAAoC;AAAA,EACxD;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/runtimes/edge/EdgeChatAdapter.ts"],"sourcesContent":["import {\n ChatModelAdapter,\n ChatModelRunOptions,\n} from \"../local/ChatModelAdapter\";\nimport { ChatModelRunResult } from \"../local/ChatModelAdapter\";\nimport { toCoreMessages } from \"./converters/toCoreMessages\";\nimport { toLanguageModelTools } from \"./converters/toLanguageModelTools\";\nimport { EdgeRuntimeRequestOptions } from \"./EdgeRuntimeRequestOptions\";\nimport { assistantDecoderStream } from \"./streams/assistantDecoderStream\";\nimport { streamPartDecoderStream } from \"./streams/utils/streamPartDecoderStream\";\nimport { runResultStream } from \"./streams/runResultStream\";\nimport { toolResultStream } from \"./streams/toolResultStream\";\nimport { toLanguageModelMessages } from \"./converters\";\n\nexport function asAsyncIterable<T>(\n source: ReadableStream<T>,\n): AsyncIterable<T> {\n return {\n [Symbol.asyncIterator]: () => {\n const reader = source.getReader();\n return {\n async next(): Promise<IteratorResult<T, undefined>> {\n const { done, value } = await reader.read();\n return done\n ? { done: true, value: undefined }\n : { done: false, value };\n },\n };\n },\n };\n}\nexport type EdgeChatAdapterOptions = {\n api: string;\n\n credentials?: RequestCredentials;\n headers?: Record<string, string> | Headers;\n body?: object;\n\n /**\n * When enabled, the adapter will not strip `id` from messages in the messages array.\n */\n unstable_sendMessageIds?: boolean;\n\n /**\n * When enabled, the adapter will send messages in the format expected by the Vercel AI SDK Core.\n * This feature will be removed in the future in favor of a better solution.\n */\n unstable_AISDKInterop?: boolean | undefined;\n};\n\nexport class EdgeChatAdapter implements ChatModelAdapter {\n constructor(private options: EdgeChatAdapterOptions) {}\n\n async *run({\n messages,\n abortSignal,\n config,\n unstable_assistantMessageId,\n }: ChatModelRunOptions) {\n const headers = new Headers(this.options.headers);\n headers.set(\"Content-Type\", \"application/json\");\n\n const result = await fetch(this.options.api, {\n method: \"POST\",\n headers,\n credentials: this.options.credentials ?? \"same-origin\",\n body: JSON.stringify({\n system: config.system,\n messages: this.options.unstable_AISDKInterop\n ? (toLanguageModelMessages(\n messages,\n ) as EdgeRuntimeRequestOptions[\"messages\"]) // TODO figure out a better way to do this\n : toCoreMessages(messages, {\n unstable_includeId: this.options.unstable_sendMessageIds,\n }),\n tools: config.tools ? toLanguageModelTools(config.tools) : [],\n unstable_assistantMessageId,\n ...config.callSettings,\n ...config.config,\n\n ...this.options.body,\n } satisfies EdgeRuntimeRequestOptions),\n signal: abortSignal,\n });\n\n if (!result.ok) {\n throw new Error(`Status ${result.status}: ${await result.text()}`);\n }\n\n const stream = result\n .body!.pipeThrough(streamPartDecoderStream())\n .pipeThrough(assistantDecoderStream())\n .pipeThrough(toolResultStream(config.tools, abortSignal))\n .pipeThrough(runResultStream());\n\n let update: ChatModelRunResult | undefined;\n for await (update of asAsyncIterable(stream)) {\n yield update;\n }\n\n if (update === undefined)\n throw new Error(\"No data received from Edge Runtime\");\n }\n}\n"],"mappings":"AAKA,SAAS,sBAAsB;AAC/B,SAAS,4BAA4B;AAErC,SAAS,8BAA8B;AACvC,SAAS,+BAA+B;AACxC,SAAS,uBAAuB;AAChC,SAAS,wBAAwB;AACjC,SAAS,+BAA+B;AAEjC,SAAS,gBACd,QACkB;AAClB,SAAO;AAAA,IACL,CAAC,OAAO,aAAa,GAAG,MAAM;AAC5B,YAAM,SAAS,OAAO,UAAU;AAChC,aAAO;AAAA,QACL,MAAM,OAA8C;AAClD,gBAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,iBAAO,OACH,EAAE,MAAM,MAAM,OAAO,OAAU,IAC/B,EAAE,MAAM,OAAO,MAAM;AAAA,QAC3B;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAoBO,MAAM,gBAA4C;AAAA,EACvD,YAAoB,SAAiC;AAAjC;AAAA,EAAkC;AAAA,EAEtD,OAAO,IAAI;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAAwB;AACtB,UAAM,UAAU,IAAI,QAAQ,KAAK,QAAQ,OAAO;AAChD,YAAQ,IAAI,gBAAgB,kBAAkB;AAE9C,UAAM,SAAS,MAAM,MAAM,KAAK,QAAQ,KAAK;AAAA,MAC3C,QAAQ;AAAA,MACR;AAAA,MACA,aAAa,KAAK,QAAQ,eAAe;AAAA,MACzC,MAAM,KAAK,UAAU;AAAA,QACnB,QAAQ,OAAO;AAAA,QACf,UAAU,KAAK,QAAQ,wBAClB;AAAA,UACC;AAAA,QACF,IACA,eAAe,UAAU;AAAA,UACvB,oBAAoB,KAAK,QAAQ;AAAA,QACnC,CAAC;AAAA,QACL,OAAO,OAAO,QAAQ,qBAAqB,OAAO,KAAK,IAAI,CAAC;AAAA,QAC5D;AAAA,QACA,GAAG,OAAO;AAAA,QACV,GAAG,OAAO;AAAA,QAEV,GAAG,KAAK,QAAQ;AAAA,MAClB,CAAqC;AAAA,MACrC,QAAQ;AAAA,IACV,CAAC;AAED,QAAI,CAAC,OAAO,IAAI;AACd,YAAM,IAAI,MAAM,UAAU,OAAO,MAAM,KAAK,MAAM,OAAO,KAAK,CAAC,EAAE;AAAA,IACnE;AAEA,UAAM,SAAS,OACZ,KAAM,YAAY,wBAAwB,CAAC,EAC3C,YAAY,uBAAuB,CAAC,EACpC,YAAY,iBAAiB,OAAO,OAAO,WAAW,CAAC,EACvD,YAAY,gBAAgB,CAAC;AAEhC,QAAI;AACJ,eAAW,UAAU,gBAAgB,MAAM,GAAG;AAC5C,YAAM;AAAA,IACR;AAEA,QAAI,WAAW;AACb,YAAM,IAAI,MAAM,oCAAoC;AAAA,EACxD;AACF;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/ui/base/dialog.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport * as DialogPrimitive from \"@radix-ui/react-dialog\";\n\nimport classNames from \"classnames\";\n\nconst Dialog = DialogPrimitive.Root;\n\nconst DialogTrigger = DialogPrimitive.Trigger;\n\nconst DialogPortal = DialogPrimitive.Portal;\n\nconst DialogClose = DialogPrimitive.Close;\n\nconst DialogOverlay = React.forwardRef<\n React.ElementRef<typeof DialogPrimitive.Overlay>,\n React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>\n>(({ className, ...props }, ref) => (\n <DialogPrimitive.Overlay\n ref={ref}\n className={classNames(\"aui-dialog-overlay\", className)}\n {...props}\n />\n));\nDialogOverlay.displayName = DialogPrimitive.Overlay.displayName;\n\nconst DialogContent = React.forwardRef<\n React.ElementRef<typeof DialogPrimitive.Content>,\n React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>\n>(({ className, children, ...props }, ref) => (\n <DialogPortal>\n <DialogOverlay />\n <DialogPrimitive.Content\n ref={ref}\n className={classNames(\"aui-dialog-content\", className)}\n {...props}\n >\n {children}\n {/* <DialogPrimitive.Close className=\"ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute right-4 top-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-offset-2 disabled:pointer-events-none\">\n <XIcon className=\"h-4 w-4\" />\n <span className=\"sr-only\">Close</span>\n </DialogPrimitive.Close> */}\n </DialogPrimitive.Content>\n </DialogPortal>\n));\nDialogContent.displayName = DialogPrimitive.Content.displayName;\n\n// const DialogHeader = ({\n// className,\n// ...props\n// }: React.HTMLAttributes<HTMLDivElement>) => (\n// <div\n// className={classNames(\n// \"flex flex-col space-y-1.5 text-center sm:text-left\",\n// className,\n// )}\n// {...props}\n// />\n// );\n// DialogHeader.displayName = \"DialogHeader\";\n\n// const DialogFooter = ({\n// className,\n// ...props\n// }: React.HTMLAttributes<HTMLDivElement>) => (\n// <div\n// className={classNames(\n// \"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2\",\n// className,\n// )}\n// {...props}\n// />\n// );\n// DialogFooter.displayName = \"DialogFooter\";\n\n// const DialogTitle = React.forwardRef<\n// React.ElementRef<typeof DialogPrimitive.Title>,\n// React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>\n// >(({ className, ...props }, ref) => (\n// <DialogPrimitive.Title\n// ref={ref}\n// className={classNames(\n// \"text-lg font-semibold leading-none tracking-tight\",\n// className,\n// )}\n// {...props}\n// />\n// ));\n// DialogTitle.displayName = DialogPrimitive.Title.displayName;\n\n// const DialogDescription = React.forwardRef<\n// React.ElementRef<typeof DialogPrimitive.Description>,\n// React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>\n// >(({ className, ...props }, ref) => (\n// <DialogPrimitive.Description\n// ref={ref}\n// className={classNames(\"text-muted-foreground text-sm\", className)}\n// {...props}\n// />\n// ));\n// DialogDescription.displayName = DialogPrimitive.Description.displayName;\n\nexport {\n Dialog,\n DialogPortal,\n DialogOverlay,\n DialogTrigger,\n DialogClose,\n DialogContent,\n // DialogHeader,\n // DialogFooter,\n // DialogTitle,\n // DialogDescription,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmBE;AAjBF,YAAuB;AACvB,sBAAiC;AAEjC,wBAAuB;AAEvB,MAAM,SAAS,gBAAgB;AAE/B,MAAM,gBAAgB,gBAAgB;AAEtC,MAAM,eAAe,gBAAgB;AAErC,MAAM,cAAc,gBAAgB;AAEpC,MAAM,gBAAgB,MAAM,WAG1B,CAAC,EAAE,WAAW,GAAG,MAAM,GAAG,QAC1B;AAAA,EAAC,gBAAgB;AAAA,EAAhB;AAAA,IACC;AAAA,IACA,eAAW,kBAAAA,SAAW,sBAAsB,SAAS;AAAA,IACpD,GAAG;AAAA;AACN,CACD;AACD,cAAc,cAAc,gBAAgB,QAAQ;AAEpD,MAAM,gBAAgB,MAAM,WAG1B,CAAC,EAAE,WAAW,UAAU,GAAG,MAAM,GAAG,QACpC,6CAAC,gBACC;AAAA,8CAAC,iBAAc;AAAA,EACf;AAAA,IAAC,gBAAgB;AAAA,IAAhB;AAAA,MACC;AAAA,MACA,eAAW,kBAAAA,SAAW,sBAAsB,SAAS;AAAA,MACpD,GAAG;AAAA,MAEH;AAAA;AAAA,EAKH;AAAA,GACF,CACD;AACD,cAAc,cAAc,gBAAgB,QAAQ;","names":["classNames"]}
1
+ {"version":3,"sources":["../../../src/ui/base/dialog.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport * as DialogPrimitive from \"@radix-ui/react-dialog\";\n\nimport classNames from \"classnames\";\n\nconst Dialog = DialogPrimitive.Root;\n\nconst DialogTrigger = DialogPrimitive.Trigger;\n\nconst DialogPortal = DialogPrimitive.Portal;\n\nconst DialogClose = DialogPrimitive.Close;\n\nconst DialogOverlay = React.forwardRef<\n React.ElementRef<typeof DialogPrimitive.Overlay>,\n React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>\n>(({ className, ...props }, ref) => (\n <DialogPrimitive.Overlay\n ref={ref}\n className={classNames(\"aui-dialog-overlay\", className)}\n {...props}\n />\n));\nDialogOverlay.displayName = DialogPrimitive.Overlay.displayName;\n\nconst DialogContent = React.forwardRef<\n React.ElementRef<typeof DialogPrimitive.Content>,\n React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>\n>(({ className, children, ...props }, ref) => (\n <DialogPortal>\n <DialogOverlay />\n <DialogPrimitive.Content\n ref={ref}\n className={classNames(\"aui-dialog-content\", className)}\n {...props}\n >\n {children}\n {/* <DialogPrimitive.Close className=\"ring-offset-aui-background focus:ring-aui-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute right-4 top-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-offset-2 disabled:pointer-events-none\">\n <XIcon className=\"h-4 w-4\" />\n <span className=\"sr-only\">Close</span>\n </DialogPrimitive.Close> */}\n </DialogPrimitive.Content>\n </DialogPortal>\n));\nDialogContent.displayName = DialogPrimitive.Content.displayName;\n\n// const DialogHeader = ({\n// className,\n// ...props\n// }: React.HTMLAttributes<HTMLDivElement>) => (\n// <div\n// className={classNames(\n// \"flex flex-col space-y-1.5 text-center sm:text-left\",\n// className,\n// )}\n// {...props}\n// />\n// );\n// DialogHeader.displayName = \"DialogHeader\";\n\n// const DialogFooter = ({\n// className,\n// ...props\n// }: React.HTMLAttributes<HTMLDivElement>) => (\n// <div\n// className={classNames(\n// \"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2\",\n// className,\n// )}\n// {...props}\n// />\n// );\n// DialogFooter.displayName = \"DialogFooter\";\n\n// const DialogTitle = React.forwardRef<\n// React.ElementRef<typeof DialogPrimitive.Title>,\n// React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>\n// >(({ className, ...props }, ref) => (\n// <DialogPrimitive.Title\n// ref={ref}\n// className={classNames(\n// \"text-lg font-semibold leading-none tracking-tight\",\n// className,\n// )}\n// {...props}\n// />\n// ));\n// DialogTitle.displayName = DialogPrimitive.Title.displayName;\n\n// const DialogDescription = React.forwardRef<\n// React.ElementRef<typeof DialogPrimitive.Description>,\n// React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>\n// >(({ className, ...props }, ref) => (\n// <DialogPrimitive.Description\n// ref={ref}\n// className={classNames(\"text-muted-foreground text-sm\", className)}\n// {...props}\n// />\n// ));\n// DialogDescription.displayName = DialogPrimitive.Description.displayName;\n\nexport {\n Dialog,\n DialogPortal,\n DialogOverlay,\n DialogTrigger,\n DialogClose,\n DialogContent,\n // DialogHeader,\n // DialogFooter,\n // DialogTitle,\n // DialogDescription,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmBE;AAjBF,YAAuB;AACvB,sBAAiC;AAEjC,wBAAuB;AAEvB,MAAM,SAAS,gBAAgB;AAE/B,MAAM,gBAAgB,gBAAgB;AAEtC,MAAM,eAAe,gBAAgB;AAErC,MAAM,cAAc,gBAAgB;AAEpC,MAAM,gBAAgB,MAAM,WAG1B,CAAC,EAAE,WAAW,GAAG,MAAM,GAAG,QAC1B;AAAA,EAAC,gBAAgB;AAAA,EAAhB;AAAA,IACC;AAAA,IACA,eAAW,kBAAAA,SAAW,sBAAsB,SAAS;AAAA,IACpD,GAAG;AAAA;AACN,CACD;AACD,cAAc,cAAc,gBAAgB,QAAQ;AAEpD,MAAM,gBAAgB,MAAM,WAG1B,CAAC,EAAE,WAAW,UAAU,GAAG,MAAM,GAAG,QACpC,6CAAC,gBACC;AAAA,8CAAC,iBAAc;AAAA,EACf;AAAA,IAAC,gBAAgB;AAAA,IAAhB;AAAA,MACC;AAAA,MACA,eAAW,kBAAAA,SAAW,sBAAsB,SAAS;AAAA,MACpD,GAAG;AAAA,MAEH;AAAA;AAAA,EAKH;AAAA,GACF,CACD;AACD,cAAc,cAAc,gBAAgB,QAAQ;","names":["classNames"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/ui/base/dialog.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport * as DialogPrimitive from \"@radix-ui/react-dialog\";\n\nimport classNames from \"classnames\";\n\nconst Dialog = DialogPrimitive.Root;\n\nconst DialogTrigger = DialogPrimitive.Trigger;\n\nconst DialogPortal = DialogPrimitive.Portal;\n\nconst DialogClose = DialogPrimitive.Close;\n\nconst DialogOverlay = React.forwardRef<\n React.ElementRef<typeof DialogPrimitive.Overlay>,\n React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>\n>(({ className, ...props }, ref) => (\n <DialogPrimitive.Overlay\n ref={ref}\n className={classNames(\"aui-dialog-overlay\", className)}\n {...props}\n />\n));\nDialogOverlay.displayName = DialogPrimitive.Overlay.displayName;\n\nconst DialogContent = React.forwardRef<\n React.ElementRef<typeof DialogPrimitive.Content>,\n React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>\n>(({ className, children, ...props }, ref) => (\n <DialogPortal>\n <DialogOverlay />\n <DialogPrimitive.Content\n ref={ref}\n className={classNames(\"aui-dialog-content\", className)}\n {...props}\n >\n {children}\n {/* <DialogPrimitive.Close className=\"ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute right-4 top-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-offset-2 disabled:pointer-events-none\">\n <XIcon className=\"h-4 w-4\" />\n <span className=\"sr-only\">Close</span>\n </DialogPrimitive.Close> */}\n </DialogPrimitive.Content>\n </DialogPortal>\n));\nDialogContent.displayName = DialogPrimitive.Content.displayName;\n\n// const DialogHeader = ({\n// className,\n// ...props\n// }: React.HTMLAttributes<HTMLDivElement>) => (\n// <div\n// className={classNames(\n// \"flex flex-col space-y-1.5 text-center sm:text-left\",\n// className,\n// )}\n// {...props}\n// />\n// );\n// DialogHeader.displayName = \"DialogHeader\";\n\n// const DialogFooter = ({\n// className,\n// ...props\n// }: React.HTMLAttributes<HTMLDivElement>) => (\n// <div\n// className={classNames(\n// \"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2\",\n// className,\n// )}\n// {...props}\n// />\n// );\n// DialogFooter.displayName = \"DialogFooter\";\n\n// const DialogTitle = React.forwardRef<\n// React.ElementRef<typeof DialogPrimitive.Title>,\n// React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>\n// >(({ className, ...props }, ref) => (\n// <DialogPrimitive.Title\n// ref={ref}\n// className={classNames(\n// \"text-lg font-semibold leading-none tracking-tight\",\n// className,\n// )}\n// {...props}\n// />\n// ));\n// DialogTitle.displayName = DialogPrimitive.Title.displayName;\n\n// const DialogDescription = React.forwardRef<\n// React.ElementRef<typeof DialogPrimitive.Description>,\n// React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>\n// >(({ className, ...props }, ref) => (\n// <DialogPrimitive.Description\n// ref={ref}\n// className={classNames(\"text-muted-foreground text-sm\", className)}\n// {...props}\n// />\n// ));\n// DialogDescription.displayName = DialogPrimitive.Description.displayName;\n\nexport {\n Dialog,\n DialogPortal,\n DialogOverlay,\n DialogTrigger,\n DialogClose,\n DialogContent,\n // DialogHeader,\n // DialogFooter,\n // DialogTitle,\n // DialogDescription,\n};\n"],"mappings":";AAmBE,cAYA,YAZA;AAjBF,YAAY,WAAW;AACvB,YAAY,qBAAqB;AAEjC,OAAO,gBAAgB;AAEvB,MAAM,SAAS,gBAAgB;AAE/B,MAAM,gBAAgB,gBAAgB;AAEtC,MAAM,eAAe,gBAAgB;AAErC,MAAM,cAAc,gBAAgB;AAEpC,MAAM,gBAAgB,MAAM,WAG1B,CAAC,EAAE,WAAW,GAAG,MAAM,GAAG,QAC1B;AAAA,EAAC,gBAAgB;AAAA,EAAhB;AAAA,IACC;AAAA,IACA,WAAW,WAAW,sBAAsB,SAAS;AAAA,IACpD,GAAG;AAAA;AACN,CACD;AACD,cAAc,cAAc,gBAAgB,QAAQ;AAEpD,MAAM,gBAAgB,MAAM,WAG1B,CAAC,EAAE,WAAW,UAAU,GAAG,MAAM,GAAG,QACpC,qBAAC,gBACC;AAAA,sBAAC,iBAAc;AAAA,EACf;AAAA,IAAC,gBAAgB;AAAA,IAAhB;AAAA,MACC;AAAA,MACA,WAAW,WAAW,sBAAsB,SAAS;AAAA,MACpD,GAAG;AAAA,MAEH;AAAA;AAAA,EAKH;AAAA,GACF,CACD;AACD,cAAc,cAAc,gBAAgB,QAAQ;","names":[]}
1
+ {"version":3,"sources":["../../../src/ui/base/dialog.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport * as DialogPrimitive from \"@radix-ui/react-dialog\";\n\nimport classNames from \"classnames\";\n\nconst Dialog = DialogPrimitive.Root;\n\nconst DialogTrigger = DialogPrimitive.Trigger;\n\nconst DialogPortal = DialogPrimitive.Portal;\n\nconst DialogClose = DialogPrimitive.Close;\n\nconst DialogOverlay = React.forwardRef<\n React.ElementRef<typeof DialogPrimitive.Overlay>,\n React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>\n>(({ className, ...props }, ref) => (\n <DialogPrimitive.Overlay\n ref={ref}\n className={classNames(\"aui-dialog-overlay\", className)}\n {...props}\n />\n));\nDialogOverlay.displayName = DialogPrimitive.Overlay.displayName;\n\nconst DialogContent = React.forwardRef<\n React.ElementRef<typeof DialogPrimitive.Content>,\n React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>\n>(({ className, children, ...props }, ref) => (\n <DialogPortal>\n <DialogOverlay />\n <DialogPrimitive.Content\n ref={ref}\n className={classNames(\"aui-dialog-content\", className)}\n {...props}\n >\n {children}\n {/* <DialogPrimitive.Close className=\"ring-offset-aui-background focus:ring-aui-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute right-4 top-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-offset-2 disabled:pointer-events-none\">\n <XIcon className=\"h-4 w-4\" />\n <span className=\"sr-only\">Close</span>\n </DialogPrimitive.Close> */}\n </DialogPrimitive.Content>\n </DialogPortal>\n));\nDialogContent.displayName = DialogPrimitive.Content.displayName;\n\n// const DialogHeader = ({\n// className,\n// ...props\n// }: React.HTMLAttributes<HTMLDivElement>) => (\n// <div\n// className={classNames(\n// \"flex flex-col space-y-1.5 text-center sm:text-left\",\n// className,\n// )}\n// {...props}\n// />\n// );\n// DialogHeader.displayName = \"DialogHeader\";\n\n// const DialogFooter = ({\n// className,\n// ...props\n// }: React.HTMLAttributes<HTMLDivElement>) => (\n// <div\n// className={classNames(\n// \"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2\",\n// className,\n// )}\n// {...props}\n// />\n// );\n// DialogFooter.displayName = \"DialogFooter\";\n\n// const DialogTitle = React.forwardRef<\n// React.ElementRef<typeof DialogPrimitive.Title>,\n// React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>\n// >(({ className, ...props }, ref) => (\n// <DialogPrimitive.Title\n// ref={ref}\n// className={classNames(\n// \"text-lg font-semibold leading-none tracking-tight\",\n// className,\n// )}\n// {...props}\n// />\n// ));\n// DialogTitle.displayName = DialogPrimitive.Title.displayName;\n\n// const DialogDescription = React.forwardRef<\n// React.ElementRef<typeof DialogPrimitive.Description>,\n// React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>\n// >(({ className, ...props }, ref) => (\n// <DialogPrimitive.Description\n// ref={ref}\n// className={classNames(\"text-muted-foreground text-sm\", className)}\n// {...props}\n// />\n// ));\n// DialogDescription.displayName = DialogPrimitive.Description.displayName;\n\nexport {\n Dialog,\n DialogPortal,\n DialogOverlay,\n DialogTrigger,\n DialogClose,\n DialogContent,\n // DialogHeader,\n // DialogFooter,\n // DialogTitle,\n // DialogDescription,\n};\n"],"mappings":";AAmBE,cAYA,YAZA;AAjBF,YAAY,WAAW;AACvB,YAAY,qBAAqB;AAEjC,OAAO,gBAAgB;AAEvB,MAAM,SAAS,gBAAgB;AAE/B,MAAM,gBAAgB,gBAAgB;AAEtC,MAAM,eAAe,gBAAgB;AAErC,MAAM,cAAc,gBAAgB;AAEpC,MAAM,gBAAgB,MAAM,WAG1B,CAAC,EAAE,WAAW,GAAG,MAAM,GAAG,QAC1B;AAAA,EAAC,gBAAgB;AAAA,EAAhB;AAAA,IACC;AAAA,IACA,WAAW,WAAW,sBAAsB,SAAS;AAAA,IACpD,GAAG;AAAA;AACN,CACD;AACD,cAAc,cAAc,gBAAgB,QAAQ;AAEpD,MAAM,gBAAgB,MAAM,WAG1B,CAAC,EAAE,WAAW,UAAU,GAAG,MAAM,GAAG,QACpC,qBAAC,gBACC;AAAA,sBAAC,iBAAc;AAAA,EACf;AAAA,IAAC,gBAAgB;AAAA,IAAhB;AAAA,MACC;AAAA,MACA,WAAW,WAAW,sBAAsB,SAAS;AAAA,MACpD,GAAG;AAAA,MAEH;AAAA;AAAA,EAKH;AAAA,GACF,CACD;AACD,cAAc,cAAc,gBAAgB,QAAQ;","names":[]}
package/package.json CHANGED
@@ -29,7 +29,7 @@
29
29
  "conversational-ui",
30
30
  "conversational-ai"
31
31
  ],
32
- "version": "0.5.96",
32
+ "version": "0.5.97",
33
33
  "license": "MIT",
34
34
  "exports": {
35
35
  ".": {
@@ -13,17 +13,37 @@ import {
13
13
  } from "./ThreadManagerRuntime";
14
14
 
15
15
  export type AssistantRuntime = {
16
+ /**
17
+ * The currently selected main thread.
18
+ */
16
19
  thread: ThreadRuntime;
20
+
21
+ /**
22
+ * The thread manager, to rename, archive and delete threads.
23
+ */
17
24
  threadManager: ThreadManagerRuntime;
18
25
 
26
+ /**
27
+ * Switch to a new thread.
28
+ */
19
29
  switchToNewThread(): void;
20
30
 
31
+ /**
32
+ * Switch to a thread.
33
+ *
34
+ * @param threadId The thread ID to switch to.
35
+ */
21
36
  switchToThread(threadId: string): void;
22
37
  /**
23
38
  * @deprecated Use `switchToNewThread` instead. This will be removed in 0.6.0.
24
39
  */
25
40
  switchToThread(threadId: string | null): void;
26
41
 
42
+ /**
43
+ * Register a model config provider. Model config providers are configuration such as system message, temperature, etc. that are set in the frontend.
44
+ *
45
+ * @param provider The model config provider to register.
46
+ */
27
47
  registerModelConfigProvider(provider: ModelConfigProvider): Unsubscribe;
28
48
 
29
49
  /**
@@ -77,12 +77,38 @@ export type ThreadRuntimeCoreBinding = SubscribableWithState<
77
77
  };
78
78
 
79
79
  export type ThreadState = Readonly<{
80
+ /**
81
+ * The thread ID.
82
+ */
80
83
  threadId: string;
84
+ /**
85
+ * Whether the thread is disabled. Disabled threads cannot receive new messages.
86
+ */
81
87
  isDisabled: boolean;
88
+
89
+ /**
90
+ * Whether the thread is running. A thread is considered running when there is an active stream connection to the backend.
91
+ */
82
92
  isRunning: boolean;
93
+
94
+ /**
95
+ * The capabilities of the thread, such as whether the thread supports editing, branch switching, etc.
96
+ */
83
97
  capabilities: RuntimeCapabilities;
98
+
99
+ /**
100
+ * The messages in the currently selected branch of the thread.
101
+ */
84
102
  messages: readonly ThreadMessage[];
103
+
104
+ /**
105
+ * Follow up message suggestions to show the user.
106
+ */
85
107
  suggestions: readonly ThreadSuggestion[];
108
+
109
+ /**
110
+ * Custom extra information provided by the runtime.
111
+ */
86
112
  extras: unknown;
87
113
 
88
114
  /**
@@ -10,6 +10,7 @@ import { assistantDecoderStream } from "./streams/assistantDecoderStream";
10
10
  import { streamPartDecoderStream } from "./streams/utils/streamPartDecoderStream";
11
11
  import { runResultStream } from "./streams/runResultStream";
12
12
  import { toolResultStream } from "./streams/toolResultStream";
13
+ import { toLanguageModelMessages } from "./converters";
13
14
 
14
15
  export function asAsyncIterable<T>(
15
16
  source: ReadableStream<T>,
@@ -39,6 +40,12 @@ export type EdgeChatAdapterOptions = {
39
40
  * When enabled, the adapter will not strip `id` from messages in the messages array.
40
41
  */
41
42
  unstable_sendMessageIds?: boolean;
43
+
44
+ /**
45
+ * When enabled, the adapter will send messages in the format expected by the Vercel AI SDK Core.
46
+ * This feature will be removed in the future in favor of a better solution.
47
+ */
48
+ unstable_AISDKInterop?: boolean | undefined;
42
49
  };
43
50
 
44
51
  export class EdgeChatAdapter implements ChatModelAdapter {
@@ -59,9 +66,13 @@ export class EdgeChatAdapter implements ChatModelAdapter {
59
66
  credentials: this.options.credentials ?? "same-origin",
60
67
  body: JSON.stringify({
61
68
  system: config.system,
62
- messages: toCoreMessages(messages, {
63
- unstable_includeId: this.options.unstable_sendMessageIds,
64
- }),
69
+ messages: this.options.unstable_AISDKInterop
70
+ ? (toLanguageModelMessages(
71
+ messages,
72
+ ) as EdgeRuntimeRequestOptions["messages"]) // TODO figure out a better way to do this
73
+ : toCoreMessages(messages, {
74
+ unstable_includeId: this.options.unstable_sendMessageIds,
75
+ }),
65
76
  tools: config.tools ? toLanguageModelTools(config.tools) : [],
66
77
  unstable_assistantMessageId,
67
78
  ...config.callSettings,
@@ -37,7 +37,7 @@ const DialogContent = React.forwardRef<
37
37
  {...props}
38
38
  >
39
39
  {children}
40
- {/* <DialogPrimitive.Close className="ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute right-4 top-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-offset-2 disabled:pointer-events-none">
40
+ {/* <DialogPrimitive.Close className="ring-offset-aui-background focus:ring-aui-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute right-4 top-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-offset-2 disabled:pointer-events-none">
41
41
  <XIcon className="h-4 w-4" />
42
42
  <span className="sr-only">Close</span>
43
43
  </DialogPrimitive.Close> */}