@assistant-ui/react 0.7.61 → 0.7.63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/runtimes/adapters/RuntimeAdapterProvider.d.ts +3 -1
- package/dist/runtimes/adapters/RuntimeAdapterProvider.d.ts.map +1 -1
- package/dist/runtimes/adapters/RuntimeAdapterProvider.js +11 -1
- package/dist/runtimes/adapters/RuntimeAdapterProvider.js.map +1 -1
- package/dist/runtimes/adapters/RuntimeAdapterProvider.mjs +11 -1
- package/dist/runtimes/adapters/RuntimeAdapterProvider.mjs.map +1 -1
- package/dist/runtimes/external-store/useExternalStoreRuntime.d.ts.map +1 -1
- package/dist/runtimes/external-store/useExternalStoreRuntime.js +6 -0
- package/dist/runtimes/external-store/useExternalStoreRuntime.js.map +1 -1
- package/dist/runtimes/external-store/useExternalStoreRuntime.mjs +6 -0
- package/dist/runtimes/external-store/useExternalStoreRuntime.mjs.map +1 -1
- package/dist/runtimes/local/useLocalRuntime.d.ts.map +1 -1
- package/dist/runtimes/local/useLocalRuntime.js +5 -1
- package/dist/runtimes/local/useLocalRuntime.js.map +1 -1
- package/dist/runtimes/local/useLocalRuntime.mjs +5 -1
- package/dist/runtimes/local/useLocalRuntime.mjs.map +1 -1
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.d.ts +3 -1
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.js +21 -18
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.mjs +19 -14
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.js +4 -1
- package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.js.map +1 -1
- package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.mjs +4 -1
- package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.mjs.map +1 -1
- package/dist/utils/smooth/useSmooth.d.ts.map +1 -1
- package/dist/utils/smooth/useSmooth.js +5 -7
- package/dist/utils/smooth/useSmooth.js.map +1 -1
- package/dist/utils/smooth/useSmooth.mjs +5 -7
- package/dist/utils/smooth/useSmooth.mjs.map +1 -1
- package/package.json +1 -1
- package/src/runtimes/adapters/RuntimeAdapterProvider.tsx +10 -2
- package/src/runtimes/external-store/useExternalStoreRuntime.tsx +8 -0
- package/src/runtimes/local/useLocalRuntime.tsx +6 -1
- package/src/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.tsx +15 -4
- package/src/runtimes/remote-thread-list/useRemoteThreadListRuntime.tsx +4 -1
- package/src/utils/smooth/useSmooth.tsx +11 -7
@@ -1,7 +1,9 @@
|
|
1
1
|
import { FC } from "react";
|
2
2
|
import { ThreadHistoryAdapter } from "./thread-history/ThreadHistoryAdapter";
|
3
|
+
import { ModelContextProvider } from "../../model-context";
|
3
4
|
export type RuntimeAdapters = {
|
4
|
-
|
5
|
+
modelContext?: ModelContextProvider;
|
6
|
+
history?: ThreadHistoryAdapter;
|
5
7
|
};
|
6
8
|
declare namespace RuntimeAdapterProvider {
|
7
9
|
type Props = {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"RuntimeAdapterProvider.d.ts","sourceRoot":"","sources":["../../../src/runtimes/adapters/RuntimeAdapterProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiB,EAAE,EAAc,MAAM,OAAO,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;
|
1
|
+
{"version":3,"file":"RuntimeAdapterProvider.d.ts","sourceRoot":"","sources":["../../../src/runtimes/adapters/RuntimeAdapterProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiB,EAAE,EAAc,MAAM,OAAO,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAE3D,MAAM,MAAM,eAAe,GAAG;IAC5B,YAAY,CAAC,EAAE,oBAAoB,CAAC;IACpC,OAAO,CAAC,EAAE,oBAAoB,CAAC;CAChC,CAAC;AAIF,kBAAU,sBAAsB,CAAC;IAC/B,KAAY,KAAK,GAAG;QAClB,QAAQ,EAAE,eAAe,CAAC;QAC1B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;KAC3B,CAAC;CACH;AAED,eAAO,MAAM,sBAAsB,EAAE,EAAE,CAAC,sBAAsB,CAAC,KAAK,CAenE,CAAC;AAEF,eAAO,MAAM,kBAAkB,8BAG9B,CAAC"}
|
@@ -31,7 +31,17 @@ var RuntimeAdapterProvider = ({
|
|
31
31
|
adapters,
|
32
32
|
children
|
33
33
|
}) => {
|
34
|
-
|
34
|
+
const context = (0, import_react.useContext)(RuntimeAdaptersContext);
|
35
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
36
|
+
RuntimeAdaptersContext.Provider,
|
37
|
+
{
|
38
|
+
value: {
|
39
|
+
...context,
|
40
|
+
...adapters
|
41
|
+
},
|
42
|
+
children
|
43
|
+
}
|
44
|
+
);
|
35
45
|
};
|
36
46
|
var useRuntimeAdapters = () => {
|
37
47
|
const adapters = (0, import_react.useContext)(RuntimeAdaptersContext);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/runtimes/adapters/RuntimeAdapterProvider.tsx"],"sourcesContent":["import { createContext, FC, useContext } from \"react\";\nimport { ThreadHistoryAdapter } from \"./thread-history/ThreadHistoryAdapter\";\n\nexport type RuntimeAdapters = {\n history
|
1
|
+
{"version":3,"sources":["../../../src/runtimes/adapters/RuntimeAdapterProvider.tsx"],"sourcesContent":["import { createContext, FC, useContext } from \"react\";\nimport { ThreadHistoryAdapter } from \"./thread-history/ThreadHistoryAdapter\";\nimport { ModelContextProvider } from \"../../model-context\";\n\nexport type RuntimeAdapters = {\n modelContext?: ModelContextProvider;\n history?: ThreadHistoryAdapter;\n};\n\nconst RuntimeAdaptersContext = createContext<RuntimeAdapters | null>(null);\n\nnamespace RuntimeAdapterProvider {\n export type Props = {\n adapters: RuntimeAdapters;\n children: React.ReactNode;\n };\n}\n\nexport const RuntimeAdapterProvider: FC<RuntimeAdapterProvider.Props> = ({\n adapters,\n children,\n}) => {\n const context = useContext(RuntimeAdaptersContext);\n return (\n <RuntimeAdaptersContext.Provider\n value={{\n ...context,\n ...adapters,\n }}\n >\n {children}\n </RuntimeAdaptersContext.Provider>\n );\n};\n\nexport const useRuntimeAdapters = () => {\n const adapters = useContext(RuntimeAdaptersContext);\n return adapters;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA8C;AAwB1C;AAfJ,IAAM,6BAAyB,4BAAsC,IAAI;AASlE,IAAM,yBAA2D,CAAC;AAAA,EACvE;AAAA,EACA;AACF,MAAM;AACJ,QAAM,cAAU,yBAAW,sBAAsB;AACjD,SACE;AAAA,IAAC,uBAAuB;AAAA,IAAvB;AAAA,MACC,OAAO;AAAA,QACL,GAAG;AAAA,QACH,GAAG;AAAA,MACL;AAAA,MAEC;AAAA;AAAA,EACH;AAEJ;AAEO,IAAM,qBAAqB,MAAM;AACtC,QAAM,eAAW,yBAAW,sBAAsB;AAClD,SAAO;AACT;","names":[]}
|
@@ -6,7 +6,17 @@ var RuntimeAdapterProvider = ({
|
|
6
6
|
adapters,
|
7
7
|
children
|
8
8
|
}) => {
|
9
|
-
|
9
|
+
const context = useContext(RuntimeAdaptersContext);
|
10
|
+
return /* @__PURE__ */ jsx(
|
11
|
+
RuntimeAdaptersContext.Provider,
|
12
|
+
{
|
13
|
+
value: {
|
14
|
+
...context,
|
15
|
+
...adapters
|
16
|
+
},
|
17
|
+
children
|
18
|
+
}
|
19
|
+
);
|
10
20
|
};
|
11
21
|
var useRuntimeAdapters = () => {
|
12
22
|
const adapters = useContext(RuntimeAdaptersContext);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/runtimes/adapters/RuntimeAdapterProvider.tsx"],"sourcesContent":["import { createContext, FC, useContext } from \"react\";\nimport { ThreadHistoryAdapter } from \"./thread-history/ThreadHistoryAdapter\";\n\nexport type RuntimeAdapters = {\n history
|
1
|
+
{"version":3,"sources":["../../../src/runtimes/adapters/RuntimeAdapterProvider.tsx"],"sourcesContent":["import { createContext, FC, useContext } from \"react\";\nimport { ThreadHistoryAdapter } from \"./thread-history/ThreadHistoryAdapter\";\nimport { ModelContextProvider } from \"../../model-context\";\n\nexport type RuntimeAdapters = {\n modelContext?: ModelContextProvider;\n history?: ThreadHistoryAdapter;\n};\n\nconst RuntimeAdaptersContext = createContext<RuntimeAdapters | null>(null);\n\nnamespace RuntimeAdapterProvider {\n export type Props = {\n adapters: RuntimeAdapters;\n children: React.ReactNode;\n };\n}\n\nexport const RuntimeAdapterProvider: FC<RuntimeAdapterProvider.Props> = ({\n adapters,\n children,\n}) => {\n const context = useContext(RuntimeAdaptersContext);\n return (\n <RuntimeAdaptersContext.Provider\n value={{\n ...context,\n ...adapters,\n }}\n >\n {children}\n </RuntimeAdaptersContext.Provider>\n );\n};\n\nexport const useRuntimeAdapters = () => {\n const adapters = useContext(RuntimeAdaptersContext);\n return adapters;\n};\n"],"mappings":";AAAA,SAAS,eAAmB,kBAAkB;AAwB1C;AAfJ,IAAM,yBAAyB,cAAsC,IAAI;AASlE,IAAM,yBAA2D,CAAC;AAAA,EACvE;AAAA,EACA;AACF,MAAM;AACJ,QAAM,UAAU,WAAW,sBAAsB;AACjD,SACE;AAAA,IAAC,uBAAuB;AAAA,IAAvB;AAAA,MACC,OAAO;AAAA,QACL,GAAG;AAAA,QACH,GAAG;AAAA,MACL;AAAA,MAEC;AAAA;AAAA,EACH;AAEJ;AAEO,IAAM,qBAAqB,MAAM;AACtC,QAAM,WAAW,WAAW,sBAAsB;AAClD,SAAO;AACT;","names":[]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useExternalStoreRuntime.d.ts","sourceRoot":"","sources":["../../../src/runtimes/external-store/useExternalStoreRuntime.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;
|
1
|
+
{"version":3,"file":"useExternalStoreRuntime.d.ts","sourceRoot":"","sources":["../../../src/runtimes/external-store/useExternalStoreRuntime.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAK9D,eAAO,MAAM,uBAAuB,GAAI,CAAC,SAAU,oBAAoB,CAAC,CAAC,CAAC,qCAkBzE,CAAC"}
|
@@ -28,11 +28,17 @@ var import_react = require("react");
|
|
28
28
|
var import_ExternalStoreRuntimeCore = require("./ExternalStoreRuntimeCore.js");
|
29
29
|
var import_AssistantRuntime = require("../../api/AssistantRuntime.js");
|
30
30
|
var import_ThreadRuntime = require("../../api/ThreadRuntime.js");
|
31
|
+
var import_RuntimeAdapterProvider = require("../adapters/RuntimeAdapterProvider.js");
|
31
32
|
var useExternalStoreRuntime = (store) => {
|
32
33
|
const [runtime] = (0, import_react.useState)(() => new import_ExternalStoreRuntimeCore.ExternalStoreRuntimeCore(store));
|
33
34
|
(0, import_react.useEffect)(() => {
|
34
35
|
runtime.setAdapter(store);
|
35
36
|
});
|
37
|
+
const { modelContext } = (0, import_RuntimeAdapterProvider.useRuntimeAdapters)() ?? {};
|
38
|
+
(0, import_react.useEffect)(() => {
|
39
|
+
if (!modelContext) return void 0;
|
40
|
+
return runtime.registerModelContextProvider(modelContext);
|
41
|
+
}, [modelContext, runtime]);
|
36
42
|
return (0, import_react.useMemo)(
|
37
43
|
() => import_AssistantRuntime.AssistantRuntimeImpl.create(runtime, import_ThreadRuntime.ThreadRuntimeImpl),
|
38
44
|
[runtime]
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/runtimes/external-store/useExternalStoreRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useMemo, useState } from \"react\";\nimport { ExternalStoreRuntimeCore } from \"./ExternalStoreRuntimeCore\";\nimport { ExternalStoreAdapter } from \"./ExternalStoreAdapter\";\nimport { AssistantRuntimeImpl } from \"../../api/AssistantRuntime\";\nimport { ThreadRuntimeImpl } from \"../../api/ThreadRuntime\";\n\nexport const useExternalStoreRuntime = <T,>(store: ExternalStoreAdapter<T>) => {\n const [runtime] = useState(() => new ExternalStoreRuntimeCore(store));\n\n useEffect(() => {\n runtime.setAdapter(store);\n });\n\n return useMemo(\n () => AssistantRuntimeImpl.create(runtime, ThreadRuntimeImpl),\n [runtime],\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA6C;AAC7C,sCAAyC;AAEzC,8BAAqC;AACrC,2BAAkC;
|
1
|
+
{"version":3,"sources":["../../../src/runtimes/external-store/useExternalStoreRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useMemo, useState } from \"react\";\nimport { ExternalStoreRuntimeCore } from \"./ExternalStoreRuntimeCore\";\nimport { ExternalStoreAdapter } from \"./ExternalStoreAdapter\";\nimport { AssistantRuntimeImpl } from \"../../api/AssistantRuntime\";\nimport { ThreadRuntimeImpl } from \"../../api/ThreadRuntime\";\nimport { useRuntimeAdapters } from \"../adapters/RuntimeAdapterProvider\";\n\nexport const useExternalStoreRuntime = <T,>(store: ExternalStoreAdapter<T>) => {\n const [runtime] = useState(() => new ExternalStoreRuntimeCore(store));\n\n useEffect(() => {\n runtime.setAdapter(store);\n });\n\n const { modelContext } = useRuntimeAdapters() ?? {};\n\n useEffect(() => {\n if (!modelContext) return undefined;\n return runtime.registerModelContextProvider(modelContext);\n }, [modelContext, runtime]);\n\n return useMemo(\n () => AssistantRuntimeImpl.create(runtime, ThreadRuntimeImpl),\n [runtime],\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA6C;AAC7C,sCAAyC;AAEzC,8BAAqC;AACrC,2BAAkC;AAClC,oCAAmC;AAE5B,IAAM,0BAA0B,CAAK,UAAmC;AAC7E,QAAM,CAAC,OAAO,QAAI,uBAAS,MAAM,IAAI,yDAAyB,KAAK,CAAC;AAEpE,8BAAU,MAAM;AACd,YAAQ,WAAW,KAAK;AAAA,EAC1B,CAAC;AAED,QAAM,EAAE,aAAa,QAAI,kDAAmB,KAAK,CAAC;AAElD,8BAAU,MAAM;AACd,QAAI,CAAC,aAAc,QAAO;AAC1B,WAAO,QAAQ,6BAA6B,YAAY;AAAA,EAC1D,GAAG,CAAC,cAAc,OAAO,CAAC;AAE1B,aAAO;AAAA,IACL,MAAM,6CAAqB,OAAO,SAAS,sCAAiB;AAAA,IAC5D,CAAC,OAAO;AAAA,EACV;AACF;","names":[]}
|
@@ -5,11 +5,17 @@ import { useEffect, useMemo, useState } from "react";
|
|
5
5
|
import { ExternalStoreRuntimeCore } from "./ExternalStoreRuntimeCore.mjs";
|
6
6
|
import { AssistantRuntimeImpl } from "../../api/AssistantRuntime.mjs";
|
7
7
|
import { ThreadRuntimeImpl } from "../../api/ThreadRuntime.mjs";
|
8
|
+
import { useRuntimeAdapters } from "../adapters/RuntimeAdapterProvider.mjs";
|
8
9
|
var useExternalStoreRuntime = (store) => {
|
9
10
|
const [runtime] = useState(() => new ExternalStoreRuntimeCore(store));
|
10
11
|
useEffect(() => {
|
11
12
|
runtime.setAdapter(store);
|
12
13
|
});
|
14
|
+
const { modelContext } = useRuntimeAdapters() ?? {};
|
15
|
+
useEffect(() => {
|
16
|
+
if (!modelContext) return void 0;
|
17
|
+
return runtime.registerModelContextProvider(modelContext);
|
18
|
+
}, [modelContext, runtime]);
|
13
19
|
return useMemo(
|
14
20
|
() => AssistantRuntimeImpl.create(runtime, ThreadRuntimeImpl),
|
15
21
|
[runtime]
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/runtimes/external-store/useExternalStoreRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useMemo, useState } from \"react\";\nimport { ExternalStoreRuntimeCore } from \"./ExternalStoreRuntimeCore\";\nimport { ExternalStoreAdapter } from \"./ExternalStoreAdapter\";\nimport { AssistantRuntimeImpl } from \"../../api/AssistantRuntime\";\nimport { ThreadRuntimeImpl } from \"../../api/ThreadRuntime\";\n\nexport const useExternalStoreRuntime = <T,>(store: ExternalStoreAdapter<T>) => {\n const [runtime] = useState(() => new ExternalStoreRuntimeCore(store));\n\n useEffect(() => {\n runtime.setAdapter(store);\n });\n\n return useMemo(\n () => AssistantRuntimeImpl.create(runtime, ThreadRuntimeImpl),\n [runtime],\n );\n};\n"],"mappings":";;;AAEA,SAAS,WAAW,SAAS,gBAAgB;AAC7C,SAAS,gCAAgC;AAEzC,SAAS,4BAA4B;AACrC,SAAS,yBAAyB;
|
1
|
+
{"version":3,"sources":["../../../src/runtimes/external-store/useExternalStoreRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useMemo, useState } from \"react\";\nimport { ExternalStoreRuntimeCore } from \"./ExternalStoreRuntimeCore\";\nimport { ExternalStoreAdapter } from \"./ExternalStoreAdapter\";\nimport { AssistantRuntimeImpl } from \"../../api/AssistantRuntime\";\nimport { ThreadRuntimeImpl } from \"../../api/ThreadRuntime\";\nimport { useRuntimeAdapters } from \"../adapters/RuntimeAdapterProvider\";\n\nexport const useExternalStoreRuntime = <T,>(store: ExternalStoreAdapter<T>) => {\n const [runtime] = useState(() => new ExternalStoreRuntimeCore(store));\n\n useEffect(() => {\n runtime.setAdapter(store);\n });\n\n const { modelContext } = useRuntimeAdapters() ?? {};\n\n useEffect(() => {\n if (!modelContext) return undefined;\n return runtime.registerModelContextProvider(modelContext);\n }, [modelContext, runtime]);\n\n return useMemo(\n () => AssistantRuntimeImpl.create(runtime, ThreadRuntimeImpl),\n [runtime],\n );\n};\n"],"mappings":";;;AAEA,SAAS,WAAW,SAAS,gBAAgB;AAC7C,SAAS,gCAAgC;AAEzC,SAAS,4BAA4B;AACrC,SAAS,yBAAyB;AAClC,SAAS,0BAA0B;AAE5B,IAAM,0BAA0B,CAAK,UAAmC;AAC7E,QAAM,CAAC,OAAO,IAAI,SAAS,MAAM,IAAI,yBAAyB,KAAK,CAAC;AAEpE,YAAU,MAAM;AACd,YAAQ,WAAW,KAAK;AAAA,EAC1B,CAAC;AAED,QAAM,EAAE,aAAa,IAAI,mBAAmB,KAAK,CAAC;AAElD,YAAU,MAAM;AACd,QAAI,CAAC,aAAc,QAAO;AAC1B,WAAO,QAAQ,6BAA6B,YAAY;AAAA,EAC1D,GAAG,CAAC,cAAc,OAAO,CAAC;AAE1B,SAAO;AAAA,IACL,MAAM,qBAAqB,OAAO,SAAS,iBAAiB;AAAA,IAC5D,CAAC,OAAO;AAAA,EACV;AACF;","names":[]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useLocalRuntime.d.ts","sourceRoot":"","sources":["../../../src/runtimes/local/useLocalRuntime.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EACL,gBAAgB,EAEjB,MAAM,4BAA4B,CAAC;AAIpC,MAAM,MAAM,YAAY,GAAG,gBAAgB,GAAG;IAC5C,KAAK,EAAE,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;CACrE,CAAC;AAqBF,eAAO,MAAM,eAAe,YACjB,gBAAgB,oCACQ,mBAAmB,
|
1
|
+
{"version":3,"file":"useLocalRuntime.d.ts","sourceRoot":"","sources":["../../../src/runtimes/local/useLocalRuntime.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EACL,gBAAgB,EAEjB,MAAM,4BAA4B,CAAC;AAIpC,MAAM,MAAM,YAAY,GAAG,gBAAgB,GAAG;IAC5C,KAAK,EAAE,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;CACrE,CAAC;AAqBF,eAAO,MAAM,eAAe,YACjB,gBAAgB,oCACQ,mBAAmB,iBA4BrD,CAAC"}
|
@@ -46,7 +46,7 @@ var LocalRuntimeImpl = class _LocalRuntimeImpl extends import_AssistantRuntime.A
|
|
46
46
|
}
|
47
47
|
};
|
48
48
|
var useLocalRuntime = (adapter, { initialMessages, ...options } = {}) => {
|
49
|
-
const threadListAdapters = (0, import_RuntimeAdapterProvider.useRuntimeAdapters)();
|
49
|
+
const { modelContext, ...threadListAdapters } = (0, import_RuntimeAdapterProvider.useRuntimeAdapters)() ?? {};
|
50
50
|
const opt = (0, import_react.useMemo)(
|
51
51
|
() => ({
|
52
52
|
...options,
|
@@ -63,6 +63,10 @@ var useLocalRuntime = (adapter, { initialMessages, ...options } = {}) => {
|
|
63
63
|
runtime.threads.getMainThreadRuntimeCore().__internal_setOptions(opt);
|
64
64
|
runtime.threads.getMainThreadRuntimeCore().__internal_load();
|
65
65
|
}, [runtime, opt]);
|
66
|
+
(0, import_react.useEffect)(() => {
|
67
|
+
if (!modelContext) return void 0;
|
68
|
+
return runtime.registerModelContextProvider(modelContext);
|
69
|
+
}, [modelContext, runtime]);
|
66
70
|
return (0, import_react.useMemo)(() => LocalRuntimeImpl.create(runtime), [runtime]);
|
67
71
|
};
|
68
72
|
// Annotate the CommonJS export names for ESM import in node:
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/runtimes/local/useLocalRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useMemo, useState } from \"react\";\nimport type { ChatModelAdapter } from \"./ChatModelAdapter\";\nimport { LocalRuntimeCore } from \"./LocalRuntimeCore\";\nimport { LocalRuntimeOptions } from \"./LocalRuntimeOptions\";\nimport {\n AssistantRuntime,\n AssistantRuntimeImpl,\n} from \"../../api/AssistantRuntime\";\nimport { ThreadRuntimeImpl } from \"../../internal\";\nimport { useRuntimeAdapters } from \"../adapters/RuntimeAdapterProvider\";\n\nexport type LocalRuntime = AssistantRuntime & {\n reset: (options?: Parameters<LocalRuntimeCore[\"reset\"]>[0]) => void;\n};\n\nclass LocalRuntimeImpl extends AssistantRuntimeImpl implements LocalRuntime {\n private constructor(private core: LocalRuntimeCore) {\n super(core, ThreadRuntimeImpl);\n }\n\n public override __internal_bindMethods() {\n super.__internal_bindMethods();\n this.reset = this.reset.bind(this);\n }\n\n public reset(options?: Parameters<LocalRuntimeCore[\"reset\"]>[0]) {\n this.core.reset(options);\n }\n\n public static override create(_core: LocalRuntimeCore): LocalRuntime {\n return new LocalRuntimeImpl(_core);\n }\n}\n\nexport const useLocalRuntime = (\n adapter: ChatModelAdapter,\n { initialMessages, ...options }: LocalRuntimeOptions = {},\n) => {\n const threadListAdapters = useRuntimeAdapters();\n const opt = useMemo(\n () => ({\n ...options,\n adapters: {\n ...threadListAdapters,\n ...options.adapters,\n chatModel: adapter,\n },\n }),\n [adapter, options, threadListAdapters],\n );\n\n const [runtime] = useState(() => new LocalRuntimeCore(opt, initialMessages));\n\n useEffect(() => {\n runtime.threads.getMainThreadRuntimeCore().__internal_setOptions(opt);\n runtime.threads.getMainThreadRuntimeCore().__internal_load();\n }, [runtime, opt]);\n\n return useMemo(() => LocalRuntimeImpl.create(runtime), [runtime]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA6C;AAE7C,8BAAiC;AAEjC,8BAGO;AACP,sBAAkC;AAClC,oCAAmC;AAMnC,IAAM,mBAAN,MAAM,0BAAyB,6CAA6C;AAAA,EAClE,YAAoB,MAAwB;AAClD,UAAM,MAAM,iCAAiB;AADH;AAAA,EAE5B;AAAA,EAEgB,yBAAyB;AACvC,UAAM,uBAAuB;AAC7B,SAAK,QAAQ,KAAK,MAAM,KAAK,IAAI;AAAA,EACnC;AAAA,EAEO,MAAM,SAAoD;AAC/D,SAAK,KAAK,MAAM,OAAO;AAAA,EACzB;AAAA,EAEA,OAAuB,OAAO,OAAuC;AACnE,WAAO,IAAI,kBAAiB,KAAK;AAAA,EACnC;AACF;AAEO,IAAM,kBAAkB,CAC7B,SACA,EAAE,iBAAiB,GAAG,QAAQ,IAAyB,CAAC,MACrD;AACH,QAAM,
|
1
|
+
{"version":3,"sources":["../../../src/runtimes/local/useLocalRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useMemo, useState } from \"react\";\nimport type { ChatModelAdapter } from \"./ChatModelAdapter\";\nimport { LocalRuntimeCore } from \"./LocalRuntimeCore\";\nimport { LocalRuntimeOptions } from \"./LocalRuntimeOptions\";\nimport {\n AssistantRuntime,\n AssistantRuntimeImpl,\n} from \"../../api/AssistantRuntime\";\nimport { ThreadRuntimeImpl } from \"../../internal\";\nimport { useRuntimeAdapters } from \"../adapters/RuntimeAdapterProvider\";\n\nexport type LocalRuntime = AssistantRuntime & {\n reset: (options?: Parameters<LocalRuntimeCore[\"reset\"]>[0]) => void;\n};\n\nclass LocalRuntimeImpl extends AssistantRuntimeImpl implements LocalRuntime {\n private constructor(private core: LocalRuntimeCore) {\n super(core, ThreadRuntimeImpl);\n }\n\n public override __internal_bindMethods() {\n super.__internal_bindMethods();\n this.reset = this.reset.bind(this);\n }\n\n public reset(options?: Parameters<LocalRuntimeCore[\"reset\"]>[0]) {\n this.core.reset(options);\n }\n\n public static override create(_core: LocalRuntimeCore): LocalRuntime {\n return new LocalRuntimeImpl(_core);\n }\n}\n\nexport const useLocalRuntime = (\n adapter: ChatModelAdapter,\n { initialMessages, ...options }: LocalRuntimeOptions = {},\n) => {\n const { modelContext, ...threadListAdapters } = useRuntimeAdapters() ?? {};\n const opt = useMemo(\n () => ({\n ...options,\n adapters: {\n ...threadListAdapters,\n ...options.adapters,\n chatModel: adapter,\n },\n }),\n [adapter, options, threadListAdapters],\n );\n\n const [runtime] = useState(() => new LocalRuntimeCore(opt, initialMessages));\n\n useEffect(() => {\n runtime.threads.getMainThreadRuntimeCore().__internal_setOptions(opt);\n runtime.threads.getMainThreadRuntimeCore().__internal_load();\n }, [runtime, opt]);\n\n useEffect(() => {\n if (!modelContext) return undefined;\n return runtime.registerModelContextProvider(modelContext);\n }, [modelContext, runtime]);\n\n return useMemo(() => LocalRuntimeImpl.create(runtime), [runtime]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA6C;AAE7C,8BAAiC;AAEjC,8BAGO;AACP,sBAAkC;AAClC,oCAAmC;AAMnC,IAAM,mBAAN,MAAM,0BAAyB,6CAA6C;AAAA,EAClE,YAAoB,MAAwB;AAClD,UAAM,MAAM,iCAAiB;AADH;AAAA,EAE5B;AAAA,EAEgB,yBAAyB;AACvC,UAAM,uBAAuB;AAC7B,SAAK,QAAQ,KAAK,MAAM,KAAK,IAAI;AAAA,EACnC;AAAA,EAEO,MAAM,SAAoD;AAC/D,SAAK,KAAK,MAAM,OAAO;AAAA,EACzB;AAAA,EAEA,OAAuB,OAAO,OAAuC;AACnE,WAAO,IAAI,kBAAiB,KAAK;AAAA,EACnC;AACF;AAEO,IAAM,kBAAkB,CAC7B,SACA,EAAE,iBAAiB,GAAG,QAAQ,IAAyB,CAAC,MACrD;AACH,QAAM,EAAE,cAAc,GAAG,mBAAmB,QAAI,kDAAmB,KAAK,CAAC;AACzE,QAAM,UAAM;AAAA,IACV,OAAO;AAAA,MACL,GAAG;AAAA,MACH,UAAU;AAAA,QACR,GAAG;AAAA,QACH,GAAG,QAAQ;AAAA,QACX,WAAW;AAAA,MACb;AAAA,IACF;AAAA,IACA,CAAC,SAAS,SAAS,kBAAkB;AAAA,EACvC;AAEA,QAAM,CAAC,OAAO,QAAI,uBAAS,MAAM,IAAI,yCAAiB,KAAK,eAAe,CAAC;AAE3E,8BAAU,MAAM;AACd,YAAQ,QAAQ,yBAAyB,EAAE,sBAAsB,GAAG;AACpE,YAAQ,QAAQ,yBAAyB,EAAE,gBAAgB;AAAA,EAC7D,GAAG,CAAC,SAAS,GAAG,CAAC;AAEjB,8BAAU,MAAM;AACd,QAAI,CAAC,aAAc,QAAO;AAC1B,WAAO,QAAQ,6BAA6B,YAAY;AAAA,EAC1D,GAAG,CAAC,cAAc,OAAO,CAAC;AAE1B,aAAO,sBAAQ,MAAM,iBAAiB,OAAO,OAAO,GAAG,CAAC,OAAO,CAAC;AAClE;","names":[]}
|
@@ -25,7 +25,7 @@ var LocalRuntimeImpl = class _LocalRuntimeImpl extends AssistantRuntimeImpl {
|
|
25
25
|
}
|
26
26
|
};
|
27
27
|
var useLocalRuntime = (adapter, { initialMessages, ...options } = {}) => {
|
28
|
-
const threadListAdapters = useRuntimeAdapters();
|
28
|
+
const { modelContext, ...threadListAdapters } = useRuntimeAdapters() ?? {};
|
29
29
|
const opt = useMemo(
|
30
30
|
() => ({
|
31
31
|
...options,
|
@@ -42,6 +42,10 @@ var useLocalRuntime = (adapter, { initialMessages, ...options } = {}) => {
|
|
42
42
|
runtime.threads.getMainThreadRuntimeCore().__internal_setOptions(opt);
|
43
43
|
runtime.threads.getMainThreadRuntimeCore().__internal_load();
|
44
44
|
}, [runtime, opt]);
|
45
|
+
useEffect(() => {
|
46
|
+
if (!modelContext) return void 0;
|
47
|
+
return runtime.registerModelContextProvider(modelContext);
|
48
|
+
}, [modelContext, runtime]);
|
45
49
|
return useMemo(() => LocalRuntimeImpl.create(runtime), [runtime]);
|
46
50
|
};
|
47
51
|
export {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/runtimes/local/useLocalRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useMemo, useState } from \"react\";\nimport type { ChatModelAdapter } from \"./ChatModelAdapter\";\nimport { LocalRuntimeCore } from \"./LocalRuntimeCore\";\nimport { LocalRuntimeOptions } from \"./LocalRuntimeOptions\";\nimport {\n AssistantRuntime,\n AssistantRuntimeImpl,\n} from \"../../api/AssistantRuntime\";\nimport { ThreadRuntimeImpl } from \"../../internal\";\nimport { useRuntimeAdapters } from \"../adapters/RuntimeAdapterProvider\";\n\nexport type LocalRuntime = AssistantRuntime & {\n reset: (options?: Parameters<LocalRuntimeCore[\"reset\"]>[0]) => void;\n};\n\nclass LocalRuntimeImpl extends AssistantRuntimeImpl implements LocalRuntime {\n private constructor(private core: LocalRuntimeCore) {\n super(core, ThreadRuntimeImpl);\n }\n\n public override __internal_bindMethods() {\n super.__internal_bindMethods();\n this.reset = this.reset.bind(this);\n }\n\n public reset(options?: Parameters<LocalRuntimeCore[\"reset\"]>[0]) {\n this.core.reset(options);\n }\n\n public static override create(_core: LocalRuntimeCore): LocalRuntime {\n return new LocalRuntimeImpl(_core);\n }\n}\n\nexport const useLocalRuntime = (\n adapter: ChatModelAdapter,\n { initialMessages, ...options }: LocalRuntimeOptions = {},\n) => {\n const threadListAdapters = useRuntimeAdapters();\n const opt = useMemo(\n () => ({\n ...options,\n adapters: {\n ...threadListAdapters,\n ...options.adapters,\n chatModel: adapter,\n },\n }),\n [adapter, options, threadListAdapters],\n );\n\n const [runtime] = useState(() => new LocalRuntimeCore(opt, initialMessages));\n\n useEffect(() => {\n runtime.threads.getMainThreadRuntimeCore().__internal_setOptions(opt);\n runtime.threads.getMainThreadRuntimeCore().__internal_load();\n }, [runtime, opt]);\n\n return useMemo(() => LocalRuntimeImpl.create(runtime), [runtime]);\n};\n"],"mappings":";;;AAEA,SAAS,WAAW,SAAS,gBAAgB;AAE7C,SAAS,wBAAwB;AAEjC;AAAA,EAEE;AAAA,OACK;AACP,SAAS,yBAAyB;AAClC,SAAS,0BAA0B;AAMnC,IAAM,mBAAN,MAAM,0BAAyB,qBAA6C;AAAA,EAClE,YAAoB,MAAwB;AAClD,UAAM,MAAM,iBAAiB;AADH;AAAA,EAE5B;AAAA,EAEgB,yBAAyB;AACvC,UAAM,uBAAuB;AAC7B,SAAK,QAAQ,KAAK,MAAM,KAAK,IAAI;AAAA,EACnC;AAAA,EAEO,MAAM,SAAoD;AAC/D,SAAK,KAAK,MAAM,OAAO;AAAA,EACzB;AAAA,EAEA,OAAuB,OAAO,OAAuC;AACnE,WAAO,IAAI,kBAAiB,KAAK;AAAA,EACnC;AACF;AAEO,IAAM,kBAAkB,CAC7B,SACA,EAAE,iBAAiB,GAAG,QAAQ,IAAyB,CAAC,MACrD;AACH,QAAM,
|
1
|
+
{"version":3,"sources":["../../../src/runtimes/local/useLocalRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useMemo, useState } from \"react\";\nimport type { ChatModelAdapter } from \"./ChatModelAdapter\";\nimport { LocalRuntimeCore } from \"./LocalRuntimeCore\";\nimport { LocalRuntimeOptions } from \"./LocalRuntimeOptions\";\nimport {\n AssistantRuntime,\n AssistantRuntimeImpl,\n} from \"../../api/AssistantRuntime\";\nimport { ThreadRuntimeImpl } from \"../../internal\";\nimport { useRuntimeAdapters } from \"../adapters/RuntimeAdapterProvider\";\n\nexport type LocalRuntime = AssistantRuntime & {\n reset: (options?: Parameters<LocalRuntimeCore[\"reset\"]>[0]) => void;\n};\n\nclass LocalRuntimeImpl extends AssistantRuntimeImpl implements LocalRuntime {\n private constructor(private core: LocalRuntimeCore) {\n super(core, ThreadRuntimeImpl);\n }\n\n public override __internal_bindMethods() {\n super.__internal_bindMethods();\n this.reset = this.reset.bind(this);\n }\n\n public reset(options?: Parameters<LocalRuntimeCore[\"reset\"]>[0]) {\n this.core.reset(options);\n }\n\n public static override create(_core: LocalRuntimeCore): LocalRuntime {\n return new LocalRuntimeImpl(_core);\n }\n}\n\nexport const useLocalRuntime = (\n adapter: ChatModelAdapter,\n { initialMessages, ...options }: LocalRuntimeOptions = {},\n) => {\n const { modelContext, ...threadListAdapters } = useRuntimeAdapters() ?? {};\n const opt = useMemo(\n () => ({\n ...options,\n adapters: {\n ...threadListAdapters,\n ...options.adapters,\n chatModel: adapter,\n },\n }),\n [adapter, options, threadListAdapters],\n );\n\n const [runtime] = useState(() => new LocalRuntimeCore(opt, initialMessages));\n\n useEffect(() => {\n runtime.threads.getMainThreadRuntimeCore().__internal_setOptions(opt);\n runtime.threads.getMainThreadRuntimeCore().__internal_load();\n }, [runtime, opt]);\n\n useEffect(() => {\n if (!modelContext) return undefined;\n return runtime.registerModelContextProvider(modelContext);\n }, [modelContext, runtime]);\n\n return useMemo(() => LocalRuntimeImpl.create(runtime), [runtime]);\n};\n"],"mappings":";;;AAEA,SAAS,WAAW,SAAS,gBAAgB;AAE7C,SAAS,wBAAwB;AAEjC;AAAA,EAEE;AAAA,OACK;AACP,SAAS,yBAAyB;AAClC,SAAS,0BAA0B;AAMnC,IAAM,mBAAN,MAAM,0BAAyB,qBAA6C;AAAA,EAClE,YAAoB,MAAwB;AAClD,UAAM,MAAM,iBAAiB;AADH;AAAA,EAE5B;AAAA,EAEgB,yBAAyB;AACvC,UAAM,uBAAuB;AAC7B,SAAK,QAAQ,KAAK,MAAM,KAAK,IAAI;AAAA,EACnC;AAAA,EAEO,MAAM,SAAoD;AAC/D,SAAK,KAAK,MAAM,OAAO;AAAA,EACzB;AAAA,EAEA,OAAuB,OAAO,OAAuC;AACnE,WAAO,IAAI,kBAAiB,KAAK;AAAA,EACnC;AACF;AAEO,IAAM,kBAAkB,CAC7B,SACA,EAAE,iBAAiB,GAAG,QAAQ,IAAyB,CAAC,MACrD;AACH,QAAM,EAAE,cAAc,GAAG,mBAAmB,IAAI,mBAAmB,KAAK,CAAC;AACzE,QAAM,MAAM;AAAA,IACV,OAAO;AAAA,MACL,GAAG;AAAA,MACH,UAAU;AAAA,QACR,GAAG;AAAA,QACH,GAAG,QAAQ;AAAA,QACX,WAAW;AAAA,MACb;AAAA,IACF;AAAA,IACA,CAAC,SAAS,SAAS,kBAAkB;AAAA,EACvC;AAEA,QAAM,CAAC,OAAO,IAAI,SAAS,MAAM,IAAI,iBAAiB,KAAK,eAAe,CAAC;AAE3E,YAAU,MAAM;AACd,YAAQ,QAAQ,yBAAyB,EAAE,sBAAsB,GAAG;AACpE,YAAQ,QAAQ,yBAAyB,EAAE,gBAAgB;AAAA,EAC7D,GAAG,CAAC,SAAS,GAAG,CAAC;AAEjB,YAAU,MAAM;AACd,QAAI,CAAC,aAAc,QAAO;AAC1B,WAAO,QAAQ,6BAA6B,YAAY;AAAA,EAC1D,GAAG,CAAC,cAAc,OAAO,CAAC;AAE1B,SAAO,QAAQ,MAAM,iBAAiB,OAAO,OAAO,GAAG,CAAC,OAAO,CAAC;AAClE;","names":[]}
|
@@ -2,6 +2,7 @@ import { ThreadListRuntimeCore } from "../core/ThreadListRuntimeCore";
|
|
2
2
|
import { RemoteThreadInitializeResponse, RemoteThreadListAdapter } from "./types";
|
3
3
|
import { BaseSubscribable } from "./BaseSubscribable";
|
4
4
|
import { FC } from "react";
|
5
|
+
import { ModelContextProvider } from "../../model-context";
|
5
6
|
type RemoteThreadData = {
|
6
7
|
readonly threadId: string;
|
7
8
|
readonly remoteId?: undefined;
|
@@ -24,13 +25,14 @@ type RemoteThreadData = {
|
|
24
25
|
readonly title?: string | undefined;
|
25
26
|
};
|
26
27
|
export declare class RemoteThreadListThreadListRuntimeCore extends BaseSubscribable implements ThreadListRuntimeCore {
|
28
|
+
private readonly contextProvider;
|
27
29
|
private _adapter;
|
28
30
|
private readonly _hookManager;
|
29
31
|
private _loadThreadsPromise;
|
30
32
|
private _mainThreadId;
|
31
33
|
private readonly _state;
|
32
34
|
getLoadThreadsPromise(): Promise<void>;
|
33
|
-
constructor(adapter: RemoteThreadListAdapter);
|
35
|
+
constructor(adapter: RemoteThreadListAdapter, contextProvider: ModelContextProvider);
|
34
36
|
private useProvider;
|
35
37
|
__internal_setAdapter(adapter: RemoteThreadListAdapter): void;
|
36
38
|
__internal_bindAdapter(): import("../..").Unsubscribe | undefined;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"RemoteThreadListThreadListRuntimeCore.d.ts","sourceRoot":"","sources":["../../../src/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAEtE,OAAO,EACL,8BAA8B,EAC9B,uBAAuB,EACxB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAGtD,OAAO,EAAE,EAAE,EAA8B,MAAM,OAAO,CAAC;
|
1
|
+
{"version":3,"file":"RemoteThreadListThreadListRuntimeCore.d.ts","sourceRoot":"","sources":["../../../src/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAEtE,OAAO,EACL,8BAA8B,EAC9B,uBAAuB,EACxB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAGtD,OAAO,EAAE,EAAE,EAA8B,MAAM,OAAO,CAAC;AAGvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAG3D,KAAK,gBAAgB,GACjB;IACE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,CA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S,sBAEnB;IAED,IAAW,iBAAiB,sBAE3B;IAED,IAAW,WAAW,uBAErB;IAED,IAAW,YAAY,IAAI,MAAM,CAEhC;IAEM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAMxB,oBAAoB,CAAC,kBAAkB,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAS/C,WAAW,CAAC,kBAAkB,EAAE,MAAM;IAIhC,cAAc,CAAC,kBAAkB,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBzD,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;IAqCxC,UAAU,aAAoB,MAAM,6CAmDzC;IAEF,OAAO,CAAC,gBAAgB,CA0BtB;IAEK,MAAM,CAAC,kBAAkB,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YA4B5D,sBAAsB;IAOvB,OAAO,CAAC,kBAAkB,EAAE,MAAM;IAkBxC,SAAS,CAAC,kBAAkB,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAqB9C,MAAM,CAAC,kBAAkB,EAAE,MAAM;IAkB9C,OAAO,CAAC,WAAW,CAA8B;IAE1C,0BAA0B,EAAE,EAAE,CA0BnC;CACH"}
|
@@ -32,10 +32,8 @@ var import_OptimisticState = require("./OptimisticState.js");
|
|
32
32
|
var import_react = require("react");
|
33
33
|
var import_zustand = require("zustand");
|
34
34
|
var import_assistant_stream = require("assistant-stream");
|
35
|
-
var
|
36
|
-
|
37
|
-
require("react/jsx-runtime")
|
38
|
-
);
|
35
|
+
var import_RuntimeAdapterProvider = require("../adapters/RuntimeAdapterProvider.js");
|
36
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
39
37
|
function createThreadMappingId(id) {
|
40
38
|
return id;
|
41
39
|
}
|
@@ -101,6 +99,19 @@ var updateStatusReducer = (state, threadIdOrRemoteId, newStatus) => {
|
|
101
99
|
return newState;
|
102
100
|
};
|
103
101
|
var RemoteThreadListThreadListRuntimeCore = class extends import_BaseSubscribable.BaseSubscribable {
|
102
|
+
constructor(adapter, contextProvider) {
|
103
|
+
super();
|
104
|
+
this.contextProvider = contextProvider;
|
105
|
+
this._state.subscribe(() => this._notifySubscribers());
|
106
|
+
this._hookManager = new import_RemoteThreadListHookInstanceManager.RemoteThreadListHookInstanceManager(
|
107
|
+
adapter.runtimeHook
|
108
|
+
);
|
109
|
+
this.useProvider = (0, import_zustand.create)(() => ({
|
110
|
+
Provider: adapter.unstable_Provider ?? import_react.Fragment
|
111
|
+
}));
|
112
|
+
this.__internal_setAdapter(adapter);
|
113
|
+
this.switchToNewThread();
|
114
|
+
}
|
104
115
|
_adapter;
|
105
116
|
_hookManager;
|
106
117
|
_loadThreadsPromise;
|
@@ -174,18 +185,6 @@ var RemoteThreadListThreadListRuntimeCore = class extends import_BaseSubscribabl
|
|
174
185
|
}
|
175
186
|
return this._loadThreadsPromise;
|
176
187
|
}
|
177
|
-
constructor(adapter) {
|
178
|
-
super();
|
179
|
-
this._state.subscribe(() => this._notifySubscribers());
|
180
|
-
this._hookManager = new import_RemoteThreadListHookInstanceManager.RemoteThreadListHookInstanceManager(
|
181
|
-
adapter.runtimeHook
|
182
|
-
);
|
183
|
-
this.useProvider = (0, import_zustand.create)(() => ({
|
184
|
-
Provider: adapter.unstable_Provider ?? import_react.Fragment
|
185
|
-
}));
|
186
|
-
this.__internal_setAdapter(adapter);
|
187
|
-
this.switchToNewThread();
|
188
|
-
}
|
189
188
|
useProvider;
|
190
189
|
__internal_setAdapter(adapter) {
|
191
190
|
if (this._adapter === adapter) return;
|
@@ -435,12 +434,16 @@ var RemoteThreadListThreadListRuntimeCore = class extends import_BaseSubscribabl
|
|
435
434
|
}, []);
|
436
435
|
const boundIds = this.useBoundIds();
|
437
436
|
const { Provider } = this.useProvider();
|
438
|
-
|
437
|
+
const adapters = {
|
438
|
+
modelContext: this.contextProvider
|
439
|
+
};
|
440
|
+
return (boundIds.length === 0 || boundIds[0] === id) && // only render if the component is the first one mounted
|
441
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_RuntimeAdapterProvider.RuntimeAdapterProvider, { adapters, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
439
442
|
this._hookManager.__internal_RenderThreadRuntimes,
|
440
443
|
{
|
441
444
|
provider: Provider
|
442
445
|
}
|
443
|
-
);
|
446
|
+
) });
|
444
447
|
};
|
445
448
|
};
|
446
449
|
// Annotate the CommonJS export names for ESM import in node:
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.tsx"],"sourcesContent":["\"use client\";\n\nimport { ThreadListRuntimeCore } from \"../core/ThreadListRuntimeCore\";\nimport { generateId } from \"../../internal\";\nimport {\n RemoteThreadInitializeResponse,\n RemoteThreadListAdapter,\n} from \"./types\";\nimport { RemoteThreadListHookInstanceManager } from \"./RemoteThreadListHookInstanceManager\";\nimport { BaseSubscribable } from \"./BaseSubscribable\";\nimport { EMPTY_THREAD_CORE } from \"./EMPTY_THREAD_CORE\";\nimport { OptimisticState } from \"./OptimisticState\";\nimport { FC, Fragment, useEffect, useId } from \"react\";\nimport { create } from \"zustand\";\nimport { AssistantStream, AssistantMessageStream } from \"assistant-stream\";\n\ntype RemoteThreadData =\n | {\n readonly threadId: string;\n readonly remoteId?: undefined;\n readonly externalId?: undefined;\n readonly status: \"new\";\n readonly title: undefined;\n }\n | {\n readonly threadId: string;\n readonly initializeTask: Promise<RemoteThreadInitializeResponse>;\n readonly remoteId?: undefined;\n readonly externalId?: undefined;\n readonly status: \"regular\" | \"archived\";\n readonly title?: string | undefined;\n }\n | {\n readonly threadId: string;\n readonly initializeTask: Promise<RemoteThreadInitializeResponse>;\n readonly remoteId: string;\n readonly externalId: string | undefined;\n readonly status: \"regular\" | \"archived\";\n readonly title?: string | undefined;\n };\n\ntype THREAD_MAPPING_ID = string & { __brand: \"THREAD_MAPPING_ID\" };\nfunction createThreadMappingId(id: string): THREAD_MAPPING_ID {\n return id as THREAD_MAPPING_ID;\n}\n\ntype RemoteThreadState = {\n readonly isLoading: boolean;\n readonly newThreadId: string | undefined;\n readonly threadIds: readonly string[];\n readonly archivedThreadIds: readonly string[];\n readonly threadIdMap: Readonly<Record<string, THREAD_MAPPING_ID>>;\n readonly threadData: Readonly<Record<THREAD_MAPPING_ID, RemoteThreadData>>;\n};\n\nconst getThreadData = (\n state: RemoteThreadState,\n threadIdOrRemoteId: string,\n) => {\n const idx = state.threadIdMap[threadIdOrRemoteId];\n if (idx === undefined) return undefined;\n return state.threadData[idx];\n};\n\nconst updateStatusReducer = (\n state: RemoteThreadState,\n threadIdOrRemoteId: string,\n newStatus: \"regular\" | \"archived\" | \"deleted\",\n) => {\n const data = getThreadData(state, threadIdOrRemoteId);\n if (!data) return state;\n\n const { threadId, remoteId, status: lastStatus } = data;\n if (lastStatus === newStatus) return state;\n\n const newState = { ...state };\n\n // lastStatus\n switch (lastStatus) {\n case \"new\":\n newState.newThreadId = undefined;\n break;\n case \"regular\":\n newState.threadIds = newState.threadIds.filter((t) => t !== threadId);\n break;\n case \"archived\":\n newState.archivedThreadIds = newState.archivedThreadIds.filter(\n (t) => t !== threadId,\n );\n break;\n\n default: {\n const _exhaustiveCheck: never = lastStatus;\n throw new Error(`Unsupported state: ${_exhaustiveCheck}`);\n }\n }\n\n // newStatus\n switch (newStatus) {\n case \"regular\":\n newState.threadIds = [threadId, ...newState.threadIds];\n break;\n\n case \"archived\":\n newState.archivedThreadIds = [threadId, ...newState.archivedThreadIds];\n break;\n\n case \"deleted\":\n newState.threadData = Object.fromEntries(\n Object.entries(newState.threadData).filter(([key]) => key !== threadId),\n );\n newState.threadIdMap = Object.fromEntries(\n Object.entries(newState.threadIdMap).filter(\n ([key]) => key !== threadId && key !== remoteId,\n ),\n );\n break;\n\n default: {\n const _exhaustiveCheck: never = newStatus;\n throw new Error(`Unsupported state: ${_exhaustiveCheck}`);\n }\n }\n\n if (newStatus !== \"deleted\") {\n newState.threadData = {\n ...newState.threadData,\n [threadId]: {\n ...data,\n status: newStatus,\n },\n };\n }\n\n return newState;\n};\n\nexport class RemoteThreadListThreadListRuntimeCore\n extends BaseSubscribable\n implements ThreadListRuntimeCore\n{\n private _adapter!: RemoteThreadListAdapter;\n private readonly _hookManager: RemoteThreadListHookInstanceManager;\n\n private _loadThreadsPromise: Promise<void> | undefined;\n\n private _mainThreadId!: string;\n private readonly _state = new OptimisticState<RemoteThreadState>({\n isLoading: false,\n newThreadId: undefined,\n threadIds: [],\n archivedThreadIds: [],\n threadIdMap: {},\n threadData: {},\n });\n\n public getLoadThreadsPromise() {\n // TODO this needs to be cached in case this promise is loaded during suspense\n if (!this._loadThreadsPromise) {\n this._loadThreadsPromise = this._state\n .optimisticUpdate({\n execute: () => this._adapter.list(),\n loading: (state) => {\n return {\n ...state,\n isLoading: true,\n };\n },\n then: (state, l) => {\n const newThreadIds = [];\n const newArchivedThreadIds = [];\n const newThreadIdMap = {} as Record<string, THREAD_MAPPING_ID>;\n const newThreadData = {} as Record<\n THREAD_MAPPING_ID,\n RemoteThreadData\n >;\n\n for (const thread of l.threads) {\n switch (thread.status) {\n case \"regular\":\n newThreadIds.push(thread.remoteId);\n break;\n case \"archived\":\n newArchivedThreadIds.push(thread.remoteId);\n break;\n default: {\n const _exhaustiveCheck: never = thread.status;\n throw new Error(`Unsupported state: ${_exhaustiveCheck}`);\n }\n }\n\n const mappingId = createThreadMappingId(thread.remoteId);\n newThreadIdMap[thread.remoteId] = mappingId;\n newThreadData[mappingId] = {\n threadId: thread.remoteId,\n remoteId: thread.remoteId,\n externalId: thread.externalId,\n status: thread.status,\n title: thread.title,\n initializeTask: Promise.resolve({\n remoteId: thread.remoteId,\n externalId: thread.externalId,\n }),\n };\n }\n\n return {\n ...state,\n threadIds: newThreadIds,\n archivedThreadIds: newArchivedThreadIds,\n threadIdMap: {\n ...state.threadIdMap,\n ...newThreadIdMap,\n },\n threadData: {\n ...state.threadData,\n ...newThreadData,\n },\n };\n },\n })\n .then(() => {});\n }\n\n return this._loadThreadsPromise;\n }\n\n constructor(adapter: RemoteThreadListAdapter) {\n super();\n\n this._state.subscribe(() => this._notifySubscribers());\n this._hookManager = new RemoteThreadListHookInstanceManager(\n adapter.runtimeHook,\n );\n this.useProvider = create(() => ({\n Provider: adapter.unstable_Provider ?? Fragment,\n }));\n this.__internal_setAdapter(adapter);\n\n this.switchToNewThread();\n }\n\n private useProvider;\n\n public __internal_setAdapter(adapter: RemoteThreadListAdapter) {\n if (this._adapter === adapter) return;\n\n this._adapter = adapter;\n\n const Provider = adapter.unstable_Provider ?? Fragment;\n if (Provider !== this.useProvider.getState().Provider) {\n this.useProvider.setState({ Provider }, true);\n }\n\n this._hookManager.setRuntimeHook(adapter.runtimeHook);\n }\n\n public __internal_bindAdapter() {\n this.getLoadThreadsPromise(); // begin loading on initial bind\n return this._adapter.subscribe?.({\n onGenerateTitle: this._onGenerateTitle,\n });\n }\n\n public get threadIds() {\n return this._state.value.threadIds;\n }\n\n public get archivedThreadIds() {\n return this._state.value.archivedThreadIds;\n }\n\n public get newThreadId() {\n return this._state.value.newThreadId;\n }\n\n public get mainThreadId(): string {\n return this._mainThreadId;\n }\n\n public getMainThreadRuntimeCore() {\n const result = this._hookManager.getThreadRuntimeCore(this._mainThreadId);\n if (!result) return EMPTY_THREAD_CORE;\n return result;\n }\n\n public getThreadRuntimeCore(threadIdOrRemoteId: string) {\n const data = this.getItemById(threadIdOrRemoteId);\n if (!data) throw new Error(\"Thread not found\");\n\n const result = this._hookManager.getThreadRuntimeCore(data.threadId);\n if (!result) throw new Error(\"Thread not found\");\n return result;\n }\n\n public getItemById(threadIdOrRemoteId: string) {\n return getThreadData(this._state.value, threadIdOrRemoteId);\n }\n\n public async switchToThread(threadIdOrRemoteId: string): Promise<void> {\n const data = this.getItemById(threadIdOrRemoteId);\n if (!data) throw new Error(\"Thread not found\");\n\n if (this._mainThreadId === data.threadId) return;\n\n const task = this._hookManager.startThreadRuntime(data.threadId);\n if (this.mainThreadId !== undefined) {\n await task;\n } else {\n task.then(() => this._notifySubscribers());\n }\n\n if (data.status === \"archived\") await this.unarchive(data.threadId);\n this._mainThreadId = data.threadId;\n\n this._notifySubscribers();\n }\n\n public async switchToNewThread(): Promise<void> {\n // an initialization transaction is in progress, wait for it to settle\n while (\n this._state.baseValue.newThreadId !== undefined &&\n this._state.value.newThreadId === undefined\n ) {\n await this._state.waitForUpdate();\n }\n\n const state = this._state.value;\n let threadId: string | undefined = this._state.value.newThreadId;\n if (threadId === undefined) {\n do {\n threadId = `__LOCALID_${generateId()}`;\n } while (state.threadIdMap[threadId]);\n\n const mappingId = createThreadMappingId(threadId);\n this._state.update({\n ...state,\n newThreadId: threadId,\n threadIdMap: {\n ...state.threadIdMap,\n [threadId]: mappingId,\n },\n threadData: {\n ...state.threadData,\n [threadId]: {\n status: \"new\",\n threadId,\n },\n },\n });\n }\n\n return this.switchToThread(threadId);\n }\n\n public initialize = async (threadId: string) => {\n if (this._state.value.newThreadId !== threadId) {\n const data = this.getItemById(threadId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status === \"new\") throw new Error(\"Unexpected new state\");\n return data.initializeTask;\n }\n\n return this._state.optimisticUpdate({\n execute: () => {\n return this._adapter.initialize(threadId);\n },\n optimistic: (state) => {\n return updateStatusReducer(state, threadId, \"regular\");\n },\n loading: (state, task) => {\n const mappingId = createThreadMappingId(threadId);\n return {\n ...state,\n threadData: {\n ...state.threadData,\n [mappingId]: {\n ...state.threadData[mappingId],\n initializeTask: task,\n },\n },\n };\n },\n then: (state, { remoteId, externalId }) => {\n const data = getThreadData(state, threadId);\n if (!data) return state;\n\n const mappingId = createThreadMappingId(threadId);\n return {\n ...state,\n threadIdMap: {\n ...state.threadIdMap,\n [remoteId]: mappingId,\n },\n threadData: {\n ...state.threadData,\n [mappingId]: {\n ...data,\n initializeTask: Promise.resolve({ remoteId, externalId }),\n remoteId,\n externalId,\n },\n },\n };\n },\n });\n };\n\n private _onGenerateTitle = async (\n remoteId: string,\n begin: () => Promise<AssistantStream>,\n ) => {\n const data = this.getItemById(remoteId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status === \"new\") throw new Error(\"Thread is not yet initialized\");\n\n const stream = await begin();\n const messageStream = AssistantMessageStream.fromAssistantStream(stream);\n for await (const result of messageStream) {\n const newTitle =\n result.content.filter((c) => c.type === \"text\")[0]?.text ??\n \"New Thread\";\n const state = this._state.baseValue;\n this._state.update({\n ...state,\n threadData: {\n ...state.threadData,\n [data.threadId]: {\n ...data,\n title: newTitle,\n },\n },\n });\n }\n };\n\n public rename(threadIdOrRemoteId: string, newTitle: string): Promise<void> {\n const data = this.getItemById(threadIdOrRemoteId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status === \"new\") throw new Error(\"Thread is not yet initialized\");\n\n return this._state.optimisticUpdate({\n execute: async () => {\n const { remoteId } = await data.initializeTask;\n return this._adapter.rename(remoteId, newTitle);\n },\n optimistic: (state) => {\n const data = getThreadData(state, threadIdOrRemoteId);\n if (!data) return state;\n\n return {\n ...state,\n threadData: {\n ...state.threadData,\n [data.threadId]: {\n ...data,\n title: newTitle,\n },\n },\n };\n },\n });\n }\n\n private async _ensureThreadIsNotMain(threadId: string) {\n // if thread is main thread, switch to another thread\n if (threadId === this._mainThreadId) {\n await this.switchToNewThread();\n }\n }\n\n public async archive(threadIdOrRemoteId: string) {\n const data = this.getItemById(threadIdOrRemoteId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status !== \"regular\")\n throw new Error(\"Thread is not yet initialized or already archived\");\n\n return this._state.optimisticUpdate({\n execute: async () => {\n await this._ensureThreadIsNotMain(data.threadId);\n const { remoteId } = await data.initializeTask;\n return this._adapter.archive(remoteId);\n },\n optimistic: (state) => {\n return updateStatusReducer(state, data.threadId, \"archived\");\n },\n });\n }\n\n public unarchive(threadIdOrRemoteId: string): Promise<void> {\n const data = this.getItemById(threadIdOrRemoteId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status !== \"archived\") throw new Error(\"Thread is not archived\");\n\n return this._state.optimisticUpdate({\n execute: async () => {\n try {\n const { remoteId } = await data.initializeTask;\n return await this._adapter.unarchive(remoteId);\n } catch (error) {\n await this._ensureThreadIsNotMain(data.threadId);\n throw error;\n }\n },\n optimistic: (state) => {\n return updateStatusReducer(state, data.threadId, \"regular\");\n },\n });\n }\n\n public async delete(threadIdOrRemoteId: string) {\n const data = this.getItemById(threadIdOrRemoteId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status !== \"regular\" && data.status !== \"archived\")\n throw new Error(\"Thread is not yet initialized\");\n\n return this._state.optimisticUpdate({\n execute: async () => {\n await this._ensureThreadIsNotMain(data.threadId);\n const { remoteId } = await data.initializeTask;\n return await this._adapter.delete(remoteId);\n },\n optimistic: (state) => {\n return updateStatusReducer(state, data.threadId, \"deleted\");\n },\n });\n }\n\n private useBoundIds = create<string[]>(() => []);\n\n public __internal_RenderComponent: FC = () => {\n const id = useId();\n useEffect(() => {\n this.useBoundIds.setState((s) => [...s, id], true);\n return () => {\n this.useBoundIds.setState((s) => s.filter((i) => i !== id), true);\n };\n }, []);\n\n const boundIds = this.useBoundIds();\n const { Provider } = this.useProvider();\n\n return (\n (boundIds.length === 0 || boundIds[0] === id) && (\n // only render if the component is the first one mounted\n <this._hookManager.__internal_RenderThreadRuntimes\n provider={Provider}\n />\n )\n );\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,sBAA2B;AAK3B,iDAAoD;AACpD,8BAAiC;AACjC,+BAAkC;AAClC,6BAAgC;AAChC,mBAA+C;AAC/C,qBAAuB;AACvB,8BAAwD;AAmhBhD;AAAA;AAAA;AAAA;AAvfR,SAAS,sBAAsB,IAA+B;AAC5D,SAAO;AACT;AAWA,IAAM,gBAAgB,CACpB,OACA,uBACG;AACH,QAAM,MAAM,MAAM,YAAY,kBAAkB;AAChD,MAAI,QAAQ,OAAW,QAAO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K,YAAY,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,MAAM,EAAE,GAAG,IAAI;AAAA,MAClE;AAAA,IACF,GAAG,CAAC,CAAC;AAEL,UAAM,WAAW,KAAK,YAAY;AAClC,UAAM,EAAE,SAAS,IAAI,KAAK,YAAY;AAEtC,YACG,SAAS,WAAW,KAAK,SAAS,CAAC,MAAM,OAExC;AAAA,MAAC,KAAK,aAAa;AAAA,MAAlB;AAAA,QACC,UAAU;AAAA;AAAA,IACZ;AAAA,EAGN;AACF;","names":["data"]}
|
1
|
+
{"version":3,"sources":["../../../src/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.tsx"],"sourcesContent":["\"use client\";\n\nimport { ThreadListRuntimeCore } from \"../core/ThreadListRuntimeCore\";\nimport { generateId } from \"../../internal\";\nimport {\n RemoteThreadInitializeResponse,\n RemoteThreadListAdapter,\n} from \"./types\";\nimport { RemoteThreadListHookInstanceManager } from \"./RemoteThreadListHookInstanceManager\";\nimport { BaseSubscribable } from \"./BaseSubscribable\";\nimport { EMPTY_THREAD_CORE } from \"./EMPTY_THREAD_CORE\";\nimport { OptimisticState } from \"./OptimisticState\";\nimport { FC, Fragment, useEffect, useId } from \"react\";\nimport { create } from \"zustand\";\nimport { AssistantStream, AssistantMessageStream } from \"assistant-stream\";\nimport { ModelContextProvider } from \"../../model-context\";\nimport { RuntimeAdapterProvider } from \"../adapters/RuntimeAdapterProvider\";\n\ntype RemoteThreadData =\n | {\n readonly threadId: string;\n readonly remoteId?: undefined;\n readonly externalId?: undefined;\n readonly status: \"new\";\n readonly title: undefined;\n }\n | {\n readonly threadId: string;\n readonly initializeTask: Promise<RemoteThreadInitializeResponse>;\n readonly remoteId?: undefined;\n readonly externalId?: undefined;\n readonly status: \"regular\" | \"archived\";\n readonly title?: string | undefined;\n }\n | {\n readonly threadId: string;\n readonly initializeTask: Promise<RemoteThreadInitializeResponse>;\n readonly remoteId: string;\n readonly externalId: string | undefined;\n readonly status: \"regular\" | \"archived\";\n readonly title?: string | undefined;\n };\n\ntype THREAD_MAPPING_ID = string & { __brand: \"THREAD_MAPPING_ID\" };\nfunction createThreadMappingId(id: string): THREAD_MAPPING_ID {\n return id as THREAD_MAPPING_ID;\n}\n\ntype RemoteThreadState = {\n readonly isLoading: boolean;\n readonly newThreadId: string | undefined;\n readonly threadIds: readonly string[];\n readonly archivedThreadIds: readonly string[];\n readonly threadIdMap: Readonly<Record<string, THREAD_MAPPING_ID>>;\n readonly threadData: Readonly<Record<THREAD_MAPPING_ID, RemoteThreadData>>;\n};\n\nconst getThreadData = (\n state: RemoteThreadState,\n threadIdOrRemoteId: string,\n) => {\n const idx = state.threadIdMap[threadIdOrRemoteId];\n if (idx === undefined) return undefined;\n return state.threadData[idx];\n};\n\nconst updateStatusReducer = (\n state: RemoteThreadState,\n threadIdOrRemoteId: string,\n newStatus: \"regular\" | \"archived\" | \"deleted\",\n) => {\n const data = getThreadData(state, threadIdOrRemoteId);\n if (!data) return state;\n\n const { threadId, remoteId, status: lastStatus } = data;\n if (lastStatus === newStatus) return state;\n\n const newState = { ...state };\n\n // lastStatus\n switch (lastStatus) {\n case \"new\":\n newState.newThreadId = undefined;\n break;\n case \"regular\":\n newState.threadIds = newState.threadIds.filter((t) => t !== threadId);\n break;\n case \"archived\":\n newState.archivedThreadIds = newState.archivedThreadIds.filter(\n (t) => t !== threadId,\n );\n break;\n\n default: {\n const _exhaustiveCheck: never = lastStatus;\n throw new Error(`Unsupported state: ${_exhaustiveCheck}`);\n }\n }\n\n // newStatus\n switch (newStatus) {\n case \"regular\":\n newState.threadIds = [threadId, ...newState.threadIds];\n break;\n\n case \"archived\":\n newState.archivedThreadIds = [threadId, ...newState.archivedThreadIds];\n break;\n\n case \"deleted\":\n newState.threadData = Object.fromEntries(\n Object.entries(newState.threadData).filter(([key]) => key !== threadId),\n );\n newState.threadIdMap = Object.fromEntries(\n Object.entries(newState.threadIdMap).filter(\n ([key]) => key !== threadId && key !== remoteId,\n ),\n );\n break;\n\n default: {\n const _exhaustiveCheck: never = newStatus;\n throw new Error(`Unsupported state: ${_exhaustiveCheck}`);\n }\n }\n\n if (newStatus !== \"deleted\") {\n newState.threadData = {\n ...newState.threadData,\n [threadId]: {\n ...data,\n status: newStatus,\n },\n };\n }\n\n return newState;\n};\n\nexport class RemoteThreadListThreadListRuntimeCore\n extends BaseSubscribable\n implements ThreadListRuntimeCore\n{\n private _adapter!: RemoteThreadListAdapter;\n private readonly _hookManager: RemoteThreadListHookInstanceManager;\n\n private _loadThreadsPromise: Promise<void> | undefined;\n\n private _mainThreadId!: string;\n private readonly _state = new OptimisticState<RemoteThreadState>({\n isLoading: false,\n newThreadId: undefined,\n threadIds: [],\n archivedThreadIds: [],\n threadIdMap: {},\n threadData: {},\n });\n\n public getLoadThreadsPromise() {\n // TODO this needs to be cached in case this promise is loaded during suspense\n if (!this._loadThreadsPromise) {\n this._loadThreadsPromise = this._state\n .optimisticUpdate({\n execute: () => this._adapter.list(),\n loading: (state) => {\n return {\n ...state,\n isLoading: true,\n };\n },\n then: (state, l) => {\n const newThreadIds = [];\n const newArchivedThreadIds = [];\n const newThreadIdMap = {} as Record<string, THREAD_MAPPING_ID>;\n const newThreadData = {} as Record<\n THREAD_MAPPING_ID,\n RemoteThreadData\n >;\n\n for (const thread of l.threads) {\n switch (thread.status) {\n case \"regular\":\n newThreadIds.push(thread.remoteId);\n break;\n case \"archived\":\n newArchivedThreadIds.push(thread.remoteId);\n break;\n default: {\n const _exhaustiveCheck: never = thread.status;\n throw new Error(`Unsupported state: ${_exhaustiveCheck}`);\n }\n }\n\n const mappingId = createThreadMappingId(thread.remoteId);\n newThreadIdMap[thread.remoteId] = mappingId;\n newThreadData[mappingId] = {\n threadId: thread.remoteId,\n remoteId: thread.remoteId,\n externalId: thread.externalId,\n status: thread.status,\n title: thread.title,\n initializeTask: Promise.resolve({\n remoteId: thread.remoteId,\n externalId: thread.externalId,\n }),\n };\n }\n\n return {\n ...state,\n threadIds: newThreadIds,\n archivedThreadIds: newArchivedThreadIds,\n threadIdMap: {\n ...state.threadIdMap,\n ...newThreadIdMap,\n },\n threadData: {\n ...state.threadData,\n ...newThreadData,\n },\n };\n },\n })\n .then(() => {});\n }\n\n return this._loadThreadsPromise;\n }\n\n constructor(\n adapter: RemoteThreadListAdapter,\n private readonly contextProvider: ModelContextProvider,\n ) {\n super();\n\n this._state.subscribe(() => this._notifySubscribers());\n this._hookManager = new RemoteThreadListHookInstanceManager(\n adapter.runtimeHook,\n );\n this.useProvider = create(() => ({\n Provider: adapter.unstable_Provider ?? Fragment,\n }));\n this.__internal_setAdapter(adapter);\n\n this.switchToNewThread();\n }\n\n private useProvider;\n\n public __internal_setAdapter(adapter: RemoteThreadListAdapter) {\n if (this._adapter === adapter) return;\n\n this._adapter = adapter;\n\n const Provider = adapter.unstable_Provider ?? Fragment;\n if (Provider !== this.useProvider.getState().Provider) {\n this.useProvider.setState({ Provider }, true);\n }\n\n this._hookManager.setRuntimeHook(adapter.runtimeHook);\n }\n\n public __internal_bindAdapter() {\n this.getLoadThreadsPromise(); // begin loading on initial bind\n return this._adapter.subscribe?.({\n onGenerateTitle: this._onGenerateTitle,\n });\n }\n\n public get threadIds() {\n return this._state.value.threadIds;\n }\n\n public get archivedThreadIds() {\n return this._state.value.archivedThreadIds;\n }\n\n public get newThreadId() {\n return this._state.value.newThreadId;\n }\n\n public get mainThreadId(): string {\n return this._mainThreadId;\n }\n\n public getMainThreadRuntimeCore() {\n const result = this._hookManager.getThreadRuntimeCore(this._mainThreadId);\n if (!result) return EMPTY_THREAD_CORE;\n return result;\n }\n\n public getThreadRuntimeCore(threadIdOrRemoteId: string) {\n const data = this.getItemById(threadIdOrRemoteId);\n if (!data) throw new Error(\"Thread not found\");\n\n const result = this._hookManager.getThreadRuntimeCore(data.threadId);\n if (!result) throw new Error(\"Thread not found\");\n return result;\n }\n\n public getItemById(threadIdOrRemoteId: string) {\n return getThreadData(this._state.value, threadIdOrRemoteId);\n }\n\n public async switchToThread(threadIdOrRemoteId: string): Promise<void> {\n const data = this.getItemById(threadIdOrRemoteId);\n if (!data) throw new Error(\"Thread not found\");\n\n if (this._mainThreadId === data.threadId) return;\n\n const task = this._hookManager.startThreadRuntime(data.threadId);\n if (this.mainThreadId !== undefined) {\n await task;\n } else {\n task.then(() => this._notifySubscribers());\n }\n\n if (data.status === \"archived\") await this.unarchive(data.threadId);\n this._mainThreadId = data.threadId;\n\n this._notifySubscribers();\n }\n\n public async switchToNewThread(): Promise<void> {\n // an initialization transaction is in progress, wait for it to settle\n while (\n this._state.baseValue.newThreadId !== undefined &&\n this._state.value.newThreadId === undefined\n ) {\n await this._state.waitForUpdate();\n }\n\n const state = this._state.value;\n let threadId: string | undefined = this._state.value.newThreadId;\n if (threadId === undefined) {\n do {\n threadId = `__LOCALID_${generateId()}`;\n } while (state.threadIdMap[threadId]);\n\n const mappingId = createThreadMappingId(threadId);\n this._state.update({\n ...state,\n newThreadId: threadId,\n threadIdMap: {\n ...state.threadIdMap,\n [threadId]: mappingId,\n },\n threadData: {\n ...state.threadData,\n [threadId]: {\n status: \"new\",\n threadId,\n },\n },\n });\n }\n\n return this.switchToThread(threadId);\n }\n\n public initialize = async (threadId: string) => {\n if (this._state.value.newThreadId !== threadId) {\n const data = this.getItemById(threadId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status === \"new\") throw new Error(\"Unexpected new state\");\n return data.initializeTask;\n }\n\n return this._state.optimisticUpdate({\n execute: () => {\n return this._adapter.initialize(threadId);\n },\n optimistic: (state) => {\n return updateStatusReducer(state, threadId, \"regular\");\n },\n loading: (state, task) => {\n const mappingId = createThreadMappingId(threadId);\n return {\n ...state,\n threadData: {\n ...state.threadData,\n [mappingId]: {\n ...state.threadData[mappingId],\n initializeTask: task,\n },\n },\n };\n },\n then: (state, { remoteId, externalId }) => {\n const data = getThreadData(state, threadId);\n if (!data) return state;\n\n const mappingId = createThreadMappingId(threadId);\n return {\n ...state,\n threadIdMap: {\n ...state.threadIdMap,\n [remoteId]: mappingId,\n },\n threadData: {\n ...state.threadData,\n [mappingId]: {\n ...data,\n initializeTask: Promise.resolve({ remoteId, externalId }),\n remoteId,\n externalId,\n },\n },\n };\n },\n });\n };\n\n private _onGenerateTitle = async (\n remoteId: string,\n begin: () => Promise<AssistantStream>,\n ) => {\n const data = this.getItemById(remoteId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status === \"new\") throw new Error(\"Thread is not yet initialized\");\n\n const stream = await begin();\n const messageStream = AssistantMessageStream.fromAssistantStream(stream);\n for await (const result of messageStream) {\n const newTitle =\n result.content.filter((c) => c.type === \"text\")[0]?.text ??\n \"New Thread\";\n const state = this._state.baseValue;\n this._state.update({\n ...state,\n threadData: {\n ...state.threadData,\n [data.threadId]: {\n ...data,\n title: newTitle,\n },\n },\n });\n }\n };\n\n public rename(threadIdOrRemoteId: string, newTitle: string): Promise<void> {\n const data = this.getItemById(threadIdOrRemoteId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status === \"new\") throw new Error(\"Thread is not yet initialized\");\n\n return this._state.optimisticUpdate({\n execute: async () => {\n const { remoteId } = await data.initializeTask;\n return this._adapter.rename(remoteId, newTitle);\n },\n optimistic: (state) => {\n const data = getThreadData(state, threadIdOrRemoteId);\n if (!data) return state;\n\n return {\n ...state,\n threadData: {\n ...state.threadData,\n [data.threadId]: {\n ...data,\n title: newTitle,\n },\n },\n };\n },\n });\n }\n\n private async _ensureThreadIsNotMain(threadId: string) {\n // if thread is main thread, switch to another thread\n if (threadId === this._mainThreadId) {\n await this.switchToNewThread();\n }\n }\n\n public async archive(threadIdOrRemoteId: string) {\n const data = this.getItemById(threadIdOrRemoteId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status !== \"regular\")\n throw new Error(\"Thread is not yet initialized or already archived\");\n\n return this._state.optimisticUpdate({\n execute: async () => {\n await this._ensureThreadIsNotMain(data.threadId);\n const { remoteId } = await data.initializeTask;\n return this._adapter.archive(remoteId);\n },\n optimistic: (state) => {\n return updateStatusReducer(state, data.threadId, \"archived\");\n },\n });\n }\n\n public unarchive(threadIdOrRemoteId: string): Promise<void> {\n const data = this.getItemById(threadIdOrRemoteId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status !== \"archived\") throw new Error(\"Thread is not archived\");\n\n return this._state.optimisticUpdate({\n execute: async () => {\n try {\n const { remoteId } = await data.initializeTask;\n return await this._adapter.unarchive(remoteId);\n } catch (error) {\n await this._ensureThreadIsNotMain(data.threadId);\n throw error;\n }\n },\n optimistic: (state) => {\n return updateStatusReducer(state, data.threadId, \"regular\");\n },\n });\n }\n\n public async delete(threadIdOrRemoteId: string) {\n const data = this.getItemById(threadIdOrRemoteId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status !== \"regular\" && data.status !== \"archived\")\n throw new Error(\"Thread is not yet initialized\");\n\n return this._state.optimisticUpdate({\n execute: async () => {\n await this._ensureThreadIsNotMain(data.threadId);\n const { remoteId } = await data.initializeTask;\n return await this._adapter.delete(remoteId);\n },\n optimistic: (state) => {\n return updateStatusReducer(state, data.threadId, \"deleted\");\n },\n });\n }\n\n private useBoundIds = create<string[]>(() => []);\n\n public __internal_RenderComponent: FC = () => {\n const id = useId();\n useEffect(() => {\n this.useBoundIds.setState((s) => [...s, id], true);\n return () => {\n this.useBoundIds.setState((s) => s.filter((i) => i !== id), true);\n };\n }, []);\n\n const boundIds = this.useBoundIds();\n const { Provider } = this.useProvider();\n\n const adapters = {\n modelContext: this.contextProvider,\n };\n\n return (\n (boundIds.length === 0 || boundIds[0] === id) && (\n // only render if the component is the first one mounted\n <RuntimeAdapterProvider adapters={adapters}>\n <this._hookManager.__internal_RenderThreadRuntimes\n provider={Provider}\n />\n </RuntimeAdapterProvider>\n )\n );\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,sBAA2B;AAK3B,iDAAoD;AACpD,8BAAiC;AACjC,+BAAkC;AAClC,6BAAgC;AAChC,mBAA+C;AAC/C,qBA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EAEQ,kBAAc,uBAAiB,MAAM,CAAC,CAAC;AAAA,EAExC,6BAAiC,MAAM;AAC5C,UAAM,SAAK,oBAAM;AACjB,gCAAU,MAAM;AACd,WAAK,YAAY,SAAS,CAAC,MAAM,CAAC,GAAG,GAAG,EAAE,GAAG,IAAI;AACjD,aAAO,MAAM;AACX,aAAK,YAAY,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,MAAM,EAAE,GAAG,IAAI;AAAA,MAClE;AAAA,IACF,GAAG,CAAC,CAAC;AAEL,UAAM,WAAW,KAAK,YAAY;AAClC,UAAM,EAAE,SAAS,IAAI,KAAK,YAAY;AAEtC,UAAM,WAAW;AAAA,MACf,cAAc,KAAK;AAAA,IACrB;AAEA,YACG,SAAS,WAAW,KAAK,SAAS,CAAC,MAAM;AAAA,IAExC,4CAAC,wDAAuB,UACtB;AAAA,MAAC,KAAK,aAAa;AAAA,MAAlB;AAAA,QACC,UAAU;AAAA;AAAA,IACZ,GACF;AAAA,EAGN;AACF;","names":["data"]}
|
@@ -9,6 +9,7 @@ import { OptimisticState } from "./OptimisticState.mjs";
|
|
9
9
|
import { Fragment, useEffect, useId } from "react";
|
10
10
|
import { create } from "zustand";
|
11
11
|
import { AssistantMessageStream } from "assistant-stream";
|
12
|
+
import { RuntimeAdapterProvider } from "../adapters/RuntimeAdapterProvider.mjs";
|
12
13
|
import { jsx } from "react/jsx-runtime";
|
13
14
|
function createThreadMappingId(id) {
|
14
15
|
return id;
|
@@ -75,6 +76,19 @@ var updateStatusReducer = (state, threadIdOrRemoteId, newStatus) => {
|
|
75
76
|
return newState;
|
76
77
|
};
|
77
78
|
var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
|
79
|
+
constructor(adapter, contextProvider) {
|
80
|
+
super();
|
81
|
+
this.contextProvider = contextProvider;
|
82
|
+
this._state.subscribe(() => this._notifySubscribers());
|
83
|
+
this._hookManager = new RemoteThreadListHookInstanceManager(
|
84
|
+
adapter.runtimeHook
|
85
|
+
);
|
86
|
+
this.useProvider = create(() => ({
|
87
|
+
Provider: adapter.unstable_Provider ?? Fragment
|
88
|
+
}));
|
89
|
+
this.__internal_setAdapter(adapter);
|
90
|
+
this.switchToNewThread();
|
91
|
+
}
|
78
92
|
_adapter;
|
79
93
|
_hookManager;
|
80
94
|
_loadThreadsPromise;
|
@@ -148,18 +162,6 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
|
|
148
162
|
}
|
149
163
|
return this._loadThreadsPromise;
|
150
164
|
}
|
151
|
-
constructor(adapter) {
|
152
|
-
super();
|
153
|
-
this._state.subscribe(() => this._notifySubscribers());
|
154
|
-
this._hookManager = new RemoteThreadListHookInstanceManager(
|
155
|
-
adapter.runtimeHook
|
156
|
-
);
|
157
|
-
this.useProvider = create(() => ({
|
158
|
-
Provider: adapter.unstable_Provider ?? Fragment
|
159
|
-
}));
|
160
|
-
this.__internal_setAdapter(adapter);
|
161
|
-
this.switchToNewThread();
|
162
|
-
}
|
163
165
|
useProvider;
|
164
166
|
__internal_setAdapter(adapter) {
|
165
167
|
if (this._adapter === adapter) return;
|
@@ -409,13 +411,16 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
|
|
409
411
|
}, []);
|
410
412
|
const boundIds = this.useBoundIds();
|
411
413
|
const { Provider } = this.useProvider();
|
414
|
+
const adapters = {
|
415
|
+
modelContext: this.contextProvider
|
416
|
+
};
|
412
417
|
return (boundIds.length === 0 || boundIds[0] === id) && // only render if the component is the first one mounted
|
413
|
-
/* @__PURE__ */ jsx(
|
418
|
+
/* @__PURE__ */ jsx(RuntimeAdapterProvider, { adapters, children: /* @__PURE__ */ jsx(
|
414
419
|
this._hookManager.__internal_RenderThreadRuntimes,
|
415
420
|
{
|
416
421
|
provider: Provider
|
417
422
|
}
|
418
|
-
);
|
423
|
+
) });
|
419
424
|
};
|
420
425
|
};
|
421
426
|
export {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.tsx"],"sourcesContent":["\"use client\";\n\nimport { ThreadListRuntimeCore } from \"../core/ThreadListRuntimeCore\";\nimport { generateId } from \"../../internal\";\nimport {\n RemoteThreadInitializeResponse,\n RemoteThreadListAdapter,\n} from \"./types\";\nimport { RemoteThreadListHookInstanceManager } from \"./RemoteThreadListHookInstanceManager\";\nimport { BaseSubscribable } from \"./BaseSubscribable\";\nimport { EMPTY_THREAD_CORE } from \"./EMPTY_THREAD_CORE\";\nimport { OptimisticState } from \"./OptimisticState\";\nimport { FC, Fragment, useEffect, useId } from \"react\";\nimport { create } from \"zustand\";\nimport { AssistantStream, AssistantMessageStream } from \"assistant-stream\";\n\ntype RemoteThreadData =\n | {\n readonly threadId: string;\n readonly remoteId?: undefined;\n readonly externalId?: undefined;\n readonly status: \"new\";\n readonly title: undefined;\n }\n | {\n readonly threadId: string;\n readonly initializeTask: Promise<RemoteThreadInitializeResponse>;\n readonly remoteId?: undefined;\n readonly externalId?: undefined;\n readonly status: \"regular\" | \"archived\";\n readonly title?: string | undefined;\n }\n | {\n readonly threadId: string;\n readonly initializeTask: Promise<RemoteThreadInitializeResponse>;\n readonly remoteId: string;\n readonly externalId: string | undefined;\n readonly status: \"regular\" | \"archived\";\n readonly title?: string | undefined;\n };\n\ntype THREAD_MAPPING_ID = string & { __brand: \"THREAD_MAPPING_ID\" };\nfunction createThreadMappingId(id: string): THREAD_MAPPING_ID {\n return id as THREAD_MAPPING_ID;\n}\n\ntype RemoteThreadState = {\n readonly isLoading: boolean;\n readonly newThreadId: string | undefined;\n readonly threadIds: readonly string[];\n readonly archivedThreadIds: readonly string[];\n readonly threadIdMap: Readonly<Record<string, THREAD_MAPPING_ID>>;\n readonly threadData: Readonly<Record<THREAD_MAPPING_ID, RemoteThreadData>>;\n};\n\nconst getThreadData = (\n state: RemoteThreadState,\n threadIdOrRemoteId: string,\n) => {\n const idx = state.threadIdMap[threadIdOrRemoteId];\n if (idx === undefined) return undefined;\n return state.threadData[idx];\n};\n\nconst updateStatusReducer = (\n state: RemoteThreadState,\n threadIdOrRemoteId: string,\n newStatus: \"regular\" | \"archived\" | \"deleted\",\n) => {\n const data = getThreadData(state, threadIdOrRemoteId);\n if (!data) return state;\n\n const { threadId, remoteId, status: lastStatus } = data;\n if (lastStatus === newStatus) return state;\n\n const newState = { ...state };\n\n // lastStatus\n switch (lastStatus) {\n case \"new\":\n newState.newThreadId = undefined;\n break;\n case \"regular\":\n newState.threadIds = newState.threadIds.filter((t) => t !== threadId);\n break;\n case \"archived\":\n newState.archivedThreadIds = newState.archivedThreadIds.filter(\n (t) => t !== threadId,\n );\n break;\n\n default: {\n const _exhaustiveCheck: never = lastStatus;\n throw new Error(`Unsupported state: ${_exhaustiveCheck}`);\n }\n }\n\n // newStatus\n switch (newStatus) {\n case \"regular\":\n newState.threadIds = [threadId, ...newState.threadIds];\n break;\n\n case \"archived\":\n newState.archivedThreadIds = [threadId, ...newState.archivedThreadIds];\n break;\n\n case \"deleted\":\n newState.threadData = Object.fromEntries(\n Object.entries(newState.threadData).filter(([key]) => key !== threadId),\n );\n newState.threadIdMap = Object.fromEntries(\n Object.entries(newState.threadIdMap).filter(\n ([key]) => key !== threadId && key !== remoteId,\n ),\n );\n break;\n\n default: {\n const _exhaustiveCheck: never = newStatus;\n throw new Error(`Unsupported state: ${_exhaustiveCheck}`);\n }\n }\n\n if (newStatus !== \"deleted\") {\n newState.threadData = {\n ...newState.threadData,\n [threadId]: {\n ...data,\n status: newStatus,\n },\n };\n }\n\n return newState;\n};\n\nexport class RemoteThreadListThreadListRuntimeCore\n extends BaseSubscribable\n implements ThreadListRuntimeCore\n{\n private _adapter!: RemoteThreadListAdapter;\n private readonly _hookManager: RemoteThreadListHookInstanceManager;\n\n private _loadThreadsPromise: Promise<void> | undefined;\n\n private _mainThreadId!: string;\n private readonly _state = new OptimisticState<RemoteThreadState>({\n isLoading: false,\n newThreadId: undefined,\n threadIds: [],\n archivedThreadIds: [],\n threadIdMap: {},\n threadData: {},\n });\n\n public getLoadThreadsPromise() {\n // TODO this needs to be cached in case this promise is loaded during suspense\n if (!this._loadThreadsPromise) {\n this._loadThreadsPromise = this._state\n .optimisticUpdate({\n execute: () => this._adapter.list(),\n loading: (state) => {\n return {\n ...state,\n isLoading: true,\n };\n },\n then: (state, l) => {\n const newThreadIds = [];\n const newArchivedThreadIds = [];\n const newThreadIdMap = {} as Record<string, THREAD_MAPPING_ID>;\n const newThreadData = {} as Record<\n THREAD_MAPPING_ID,\n RemoteThreadData\n >;\n\n for (const thread of l.threads) {\n switch (thread.status) {\n case \"regular\":\n newThreadIds.push(thread.remoteId);\n break;\n case \"archived\":\n newArchivedThreadIds.push(thread.remoteId);\n break;\n default: {\n const _exhaustiveCheck: never = thread.status;\n throw new Error(`Unsupported state: ${_exhaustiveCheck}`);\n }\n }\n\n const mappingId = createThreadMappingId(thread.remoteId);\n newThreadIdMap[thread.remoteId] = mappingId;\n newThreadData[mappingId] = {\n threadId: thread.remoteId,\n remoteId: thread.remoteId,\n externalId: thread.externalId,\n status: thread.status,\n title: thread.title,\n initializeTask: Promise.resolve({\n remoteId: thread.remoteId,\n externalId: thread.externalId,\n }),\n };\n }\n\n return {\n ...state,\n threadIds: newThreadIds,\n archivedThreadIds: newArchivedThreadIds,\n threadIdMap: {\n ...state.threadIdMap,\n ...newThreadIdMap,\n },\n threadData: {\n ...state.threadData,\n ...newThreadData,\n },\n };\n },\n })\n .then(() => {});\n }\n\n return this._loadThreadsPromise;\n }\n\n constructor(adapter: RemoteThreadListAdapter) {\n super();\n\n this._state.subscribe(() => this._notifySubscribers());\n this._hookManager = new RemoteThreadListHookInstanceManager(\n adapter.runtimeHook,\n );\n this.useProvider = create(() => ({\n Provider: adapter.unstable_Provider ?? Fragment,\n }));\n this.__internal_setAdapter(adapter);\n\n this.switchToNewThread();\n }\n\n private useProvider;\n\n public __internal_setAdapter(adapter: RemoteThreadListAdapter) {\n if (this._adapter === adapter) return;\n\n this._adapter = adapter;\n\n const Provider = adapter.unstable_Provider ?? Fragment;\n if (Provider !== this.useProvider.getState().Provider) {\n this.useProvider.setState({ Provider }, true);\n }\n\n this._hookManager.setRuntimeHook(adapter.runtimeHook);\n }\n\n public __internal_bindAdapter() {\n this.getLoadThreadsPromise(); // begin loading on initial bind\n return this._adapter.subscribe?.({\n onGenerateTitle: this._onGenerateTitle,\n });\n }\n\n public get threadIds() {\n return this._state.value.threadIds;\n }\n\n public get archivedThreadIds() {\n return this._state.value.archivedThreadIds;\n }\n\n public get newThreadId() {\n return this._state.value.newThreadId;\n }\n\n public get mainThreadId(): string {\n return this._mainThreadId;\n }\n\n public getMainThreadRuntimeCore() {\n const result = this._hookManager.getThreadRuntimeCore(this._mainThreadId);\n if (!result) return EMPTY_THREAD_CORE;\n return result;\n }\n\n public getThreadRuntimeCore(threadIdOrRemoteId: string) {\n const data = this.getItemById(threadIdOrRemoteId);\n if (!data) throw new Error(\"Thread not found\");\n\n const result = this._hookManager.getThreadRuntimeCore(data.threadId);\n if (!result) throw new Error(\"Thread not found\");\n return result;\n }\n\n public getItemById(threadIdOrRemoteId: string) {\n return getThreadData(this._state.value, threadIdOrRemoteId);\n }\n\n public async switchToThread(threadIdOrRemoteId: string): Promise<void> {\n const data = this.getItemById(threadIdOrRemoteId);\n if (!data) throw new Error(\"Thread not found\");\n\n if (this._mainThreadId === data.threadId) return;\n\n const task = this._hookManager.startThreadRuntime(data.threadId);\n if (this.mainThreadId !== undefined) {\n await task;\n } else {\n task.then(() => this._notifySubscribers());\n }\n\n if (data.status === \"archived\") await this.unarchive(data.threadId);\n this._mainThreadId = data.threadId;\n\n this._notifySubscribers();\n }\n\n public async switchToNewThread(): Promise<void> {\n // an initialization transaction is in progress, wait for it to settle\n while (\n this._state.baseValue.newThreadId !== undefined &&\n this._state.value.newThreadId === undefined\n ) {\n await this._state.waitForUpdate();\n }\n\n const state = this._state.value;\n let threadId: string | undefined = this._state.value.newThreadId;\n if (threadId === undefined) {\n do {\n threadId = `__LOCALID_${generateId()}`;\n } while (state.threadIdMap[threadId]);\n\n const mappingId = createThreadMappingId(threadId);\n this._state.update({\n ...state,\n newThreadId: threadId,\n threadIdMap: {\n ...state.threadIdMap,\n [threadId]: mappingId,\n },\n threadData: {\n ...state.threadData,\n [threadId]: {\n status: \"new\",\n threadId,\n },\n },\n });\n }\n\n return this.switchToThread(threadId);\n }\n\n public initialize = async (threadId: string) => {\n if (this._state.value.newThreadId !== threadId) {\n const data = this.getItemById(threadId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status === \"new\") throw new Error(\"Unexpected new state\");\n return data.initializeTask;\n }\n\n return this._state.optimisticUpdate({\n execute: () => {\n return this._adapter.initialize(threadId);\n },\n optimistic: (state) => {\n return updateStatusReducer(state, threadId, \"regular\");\n },\n loading: (state, task) => {\n const mappingId = createThreadMappingId(threadId);\n return {\n ...state,\n threadData: {\n ...state.threadData,\n [mappingId]: {\n ...state.threadData[mappingId],\n initializeTask: task,\n },\n },\n };\n },\n then: (state, { remoteId, externalId }) => {\n const data = getThreadData(state, threadId);\n if (!data) return state;\n\n const mappingId = createThreadMappingId(threadId);\n return {\n ...state,\n threadIdMap: {\n ...state.threadIdMap,\n [remoteId]: mappingId,\n },\n threadData: {\n ...state.threadData,\n [mappingId]: {\n ...data,\n initializeTask: Promise.resolve({ remoteId, externalId }),\n remoteId,\n externalId,\n },\n },\n };\n },\n });\n };\n\n private _onGenerateTitle = async (\n remoteId: string,\n begin: () => Promise<AssistantStream>,\n ) => {\n const data = this.getItemById(remoteId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status === \"new\") throw new Error(\"Thread is not yet initialized\");\n\n const stream = await begin();\n const messageStream = AssistantMessageStream.fromAssistantStream(stream);\n for await (const result of messageStream) {\n const newTitle =\n result.content.filter((c) => c.type === \"text\")[0]?.text ??\n \"New Thread\";\n const state = this._state.baseValue;\n this._state.update({\n ...state,\n threadData: {\n ...state.threadData,\n [data.threadId]: {\n ...data,\n title: newTitle,\n },\n },\n });\n }\n };\n\n public rename(threadIdOrRemoteId: string, newTitle: string): Promise<void> {\n const data = this.getItemById(threadIdOrRemoteId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status === \"new\") throw new Error(\"Thread is not yet initialized\");\n\n return this._state.optimisticUpdate({\n execute: async () => {\n const { remoteId } = await data.initializeTask;\n return this._adapter.rename(remoteId, newTitle);\n },\n optimistic: (state) => {\n const data = getThreadData(state, threadIdOrRemoteId);\n if (!data) return state;\n\n return {\n ...state,\n threadData: {\n ...state.threadData,\n [data.threadId]: {\n ...data,\n title: newTitle,\n },\n },\n };\n },\n });\n }\n\n private async _ensureThreadIsNotMain(threadId: string) {\n // if thread is main thread, switch to another thread\n if (threadId === this._mainThreadId) {\n await this.switchToNewThread();\n }\n }\n\n public async archive(threadIdOrRemoteId: string) {\n const data = this.getItemById(threadIdOrRemoteId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status !== \"regular\")\n throw new Error(\"Thread is not yet initialized or already archived\");\n\n return this._state.optimisticUpdate({\n execute: async () => {\n await this._ensureThreadIsNotMain(data.threadId);\n const { remoteId } = await data.initializeTask;\n return this._adapter.archive(remoteId);\n },\n optimistic: (state) => {\n return updateStatusReducer(state, data.threadId, \"archived\");\n },\n });\n }\n\n public unarchive(threadIdOrRemoteId: string): Promise<void> {\n const data = this.getItemById(threadIdOrRemoteId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status !== \"archived\") throw new Error(\"Thread is not archived\");\n\n return this._state.optimisticUpdate({\n execute: async () => {\n try {\n const { remoteId } = await data.initializeTask;\n return await this._adapter.unarchive(remoteId);\n } catch (error) {\n await this._ensureThreadIsNotMain(data.threadId);\n throw error;\n }\n },\n optimistic: (state) => {\n return updateStatusReducer(state, data.threadId, \"regular\");\n },\n });\n }\n\n public async delete(threadIdOrRemoteId: string) {\n const data = this.getItemById(threadIdOrRemoteId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status !== \"regular\" && data.status !== \"archived\")\n throw new Error(\"Thread is not yet initialized\");\n\n return this._state.optimisticUpdate({\n execute: async () => {\n await this._ensureThreadIsNotMain(data.threadId);\n const { remoteId } = await data.initializeTask;\n return await this._adapter.delete(remoteId);\n },\n optimistic: (state) => {\n return updateStatusReducer(state, data.threadId, \"deleted\");\n },\n });\n }\n\n private useBoundIds = create<string[]>(() => []);\n\n public __internal_RenderComponent: FC = () => {\n const id = useId();\n useEffect(() => {\n this.useBoundIds.setState((s) => [...s, id], true);\n return () => {\n this.useBoundIds.setState((s) => s.filter((i) => i !== id), true);\n };\n }, []);\n\n const boundIds = this.useBoundIds();\n const { Provider } = this.useProvider();\n\n return (\n (boundIds.length === 0 || boundIds[0] === id) && (\n // only render if the component is the first one mounted\n <this._hookManager.__internal_RenderThreadRuntimes\n provider={Provider}\n />\n )\n );\n };\n}\n"],"mappings":";;;AAGA,SAAS,kBAAkB;AAK3B,SAAS,2CAA2C;AACpD,SAAS,wBAAwB;AACjC,SAAS,yBAAyB;AAClC,SAAS,uBAAuB;AAChC,SAAa,UAAU,WAAW,aAAa;AAC/C,SAAS,cAAc;AACvB,SAA0B,8BAA8B;AAmhBhD;AAvfR,SAAS,sBAAsB,IAA+B;AAC5D,SAAO;AACT;AAWA,IAAM,gBAAgB,CACpB,OACA,uBACG;AACH,QAAM,MAAM,MAAM,YAAY,kBAAkB;AAChD,MAAI,QAAQ,OAAW,QAAO;AAC9B,SAAO,MAAM,WAAW,GAAG;AAC7B;AAEA,IAAM,sBAAsB,CAC1B,OACA,oBACA,cACG;AACH,QAAM,OAAO,cAAc,OAAO,kBAAkB;AACpD,MAAI,CAAC,KAAM,QAAO;AAElB,QAAM,EAAE,UAAU,UAAU,QAAQ,WAAW,IAAI;AACnD,MAAI,eAAe,UAAW,QAAO;AAErC,QAAM,WAAW,EAAE,GAAG,MAAM;AAG5B,UAAQ,YAAY;AAAA,IAClB,KAAK;AACH,eAAS,cAAc;AACvB;AAAA,IACF,KAAK;AACH,eAAS,YAAY,SAAS,UAAU,OAAO,CAAC,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oteThreadListThreadListRuntimeCore.tsx"],"sourcesContent":["\"use client\";\n\nimport { ThreadListRuntimeCore } from \"../core/ThreadListRuntimeCore\";\nimport { generateId } from \"../../internal\";\nimport {\n RemoteThreadInitializeResponse,\n RemoteThreadListAdapter,\n} from \"./types\";\nimport { RemoteThreadListHookInstanceManager } from \"./RemoteThreadListHookInstanceManager\";\nimport { BaseSubscribable } from \"./BaseSubscribable\";\nimport { EMPTY_THREAD_CORE } from \"./EMPTY_THREAD_CORE\";\nimport { OptimisticState } from \"./OptimisticState\";\nimport { FC, Fragment, useEffect, useId } from \"react\";\nimport { create } from \"zustand\";\nimport { AssistantStream, AssistantMessageStream } from \"assistant-stream\";\nimport { ModelContextProvider } from \"../../model-context\";\nimport { RuntimeAdapterProvider } from \"../adapters/RuntimeAdapterProvider\";\n\ntype RemoteThreadData =\n | {\n readonly threadId: string;\n readonly remoteId?: undefined;\n readonly externalId?: undefined;\n readonly status: \"new\";\n readonly title: undefined;\n }\n | {\n readonly threadId: string;\n readonly initializeTask: Promise<RemoteThreadInitializeResponse>;\n readonly remoteId?: undefined;\n readonly externalId?: undefined;\n readonly status: \"regular\" | \"archived\";\n readonly title?: string | undefined;\n }\n | {\n readonly threadId: string;\n readonly initializeTask: Promise<RemoteThreadInitializeResponse>;\n readonly remoteId: string;\n readonly externalId: string | undefined;\n readonly status: \"regular\" | \"archived\";\n readonly title?: string | undefined;\n };\n\ntype THREAD_MAPPING_ID = string & { __brand: \"THREAD_MAPPING_ID\" };\nfunction createThreadMappingId(id: string): THREAD_MAPPING_ID {\n return id as THREAD_MAPPING_ID;\n}\n\ntype RemoteThreadState = {\n readonly isLoading: boolean;\n readonly newThreadId: string | undefined;\n readonly threadIds: readonly string[];\n readonly archivedThreadIds: readonly string[];\n readonly threadIdMap: Readonly<Record<string, THREAD_MAPPING_ID>>;\n readonly threadData: Readonly<Record<THREAD_MAPPING_ID, RemoteThreadData>>;\n};\n\nconst getThreadData = (\n state: RemoteThreadState,\n threadIdOrRemoteId: string,\n) => {\n const idx = state.threadIdMap[threadIdOrRemoteId];\n if (idx === undefined) return undefined;\n return state.threadData[idx];\n};\n\nconst updateStatusReducer = (\n state: RemoteThreadState,\n threadIdOrRemoteId: string,\n newStatus: \"regular\" | \"archived\" | \"deleted\",\n) => {\n const data = getThreadData(state, threadIdOrRemoteId);\n if (!data) return state;\n\n const { threadId, remoteId, status: lastStatus } = data;\n if (lastStatus === newStatus) return state;\n\n const newState = { ...state };\n\n // lastStatus\n switch (lastStatus) {\n case \"new\":\n newState.newThreadId = undefined;\n break;\n case \"regular\":\n newState.threadIds = newState.threadIds.filter((t) => t !== threadId);\n break;\n case \"archived\":\n newState.archivedThreadIds = newState.archivedThreadIds.filter(\n (t) => t !== threadId,\n );\n break;\n\n default: {\n const _exhaustiveCheck: never = lastStatus;\n throw new Error(`Unsupported state: ${_exhaustiveCheck}`);\n }\n }\n\n // newStatus\n switch (newStatus) {\n case \"regular\":\n newState.threadIds = [threadId, ...newState.threadIds];\n break;\n\n case \"archived\":\n newState.archivedThreadIds = [threadId, ...newState.archivedThreadIds];\n break;\n\n case \"deleted\":\n newState.threadData = Object.fromEntries(\n Object.entries(newState.threadData).filter(([key]) => key !== threadId),\n );\n newState.threadIdMap = Object.fromEntries(\n Object.entries(newState.threadIdMap).filter(\n ([key]) => key !== threadId && key !== remoteId,\n ),\n );\n break;\n\n default: {\n const _exhaustiveCheck: never = newStatus;\n throw new Error(`Unsupported state: ${_exhaustiveCheck}`);\n }\n }\n\n if (newStatus !== \"deleted\") {\n newState.threadData = {\n ...newState.threadData,\n [threadId]: {\n ...data,\n status: newStatus,\n },\n };\n }\n\n return newState;\n};\n\nexport class RemoteThreadListThreadListRuntimeCore\n extends BaseSubscribable\n implements ThreadListRuntimeCore\n{\n private _adapter!: RemoteThreadListAdapter;\n private readonly _hookManager: RemoteThreadListHookInstanceManager;\n\n private _loadThreadsPromise: Promise<void> | undefined;\n\n private _mainThreadId!: string;\n private readonly _state = new OptimisticState<RemoteThreadState>({\n isLoading: false,\n newThreadId: undefined,\n threadIds: [],\n archivedThreadIds: [],\n threadIdMap: {},\n threadData: {},\n });\n\n public getLoadThreadsPromise() {\n // TODO this needs to be cached in case this promise is loaded during suspense\n if (!this._loadThreadsPromise) {\n this._loadThreadsPromise = this._state\n .optimisticUpdate({\n execute: () => this._adapter.list(),\n loading: (state) => {\n return {\n ...state,\n isLoading: true,\n };\n },\n then: (state, l) => {\n const newThreadIds = [];\n const newArchivedThreadIds = [];\n const newThreadIdMap = {} as Record<string, THREAD_MAPPING_ID>;\n const newThreadData = {} as Record<\n THREAD_MAPPING_ID,\n RemoteThreadData\n >;\n\n for (const thread of l.threads) {\n switch (thread.status) {\n case \"regular\":\n newThreadIds.push(thread.remoteId);\n break;\n case \"archived\":\n newArchivedThreadIds.push(thread.remoteId);\n break;\n default: {\n const _exhaustiveCheck: never = thread.status;\n throw new Error(`Unsupported state: ${_exhaustiveCheck}`);\n }\n }\n\n const mappingId = createThreadMappingId(thread.remoteId);\n newThreadIdMap[thread.remoteId] = mappingId;\n newThreadData[mappingId] = {\n threadId: thread.remoteId,\n remoteId: thread.remoteId,\n externalId: thread.externalId,\n status: thread.status,\n title: thread.title,\n initializeTask: Promise.resolve({\n remoteId: thread.remoteId,\n externalId: thread.externalId,\n }),\n };\n }\n\n return {\n ...state,\n threadIds: newThreadIds,\n archivedThreadIds: newArchivedThreadIds,\n threadIdMap: {\n ...state.threadIdMap,\n ...newThreadIdMap,\n },\n threadData: {\n ...state.threadData,\n ...newThreadData,\n },\n };\n },\n })\n .then(() => {});\n }\n\n return this._loadThreadsPromise;\n }\n\n constructor(\n adapter: RemoteThreadListAdapter,\n private readonly contextProvider: ModelContextProvider,\n ) {\n super();\n\n this._state.subscribe(() => this._notifySubscribers());\n this._hookManager = new RemoteThreadListHookInstanceManager(\n adapter.runtimeHook,\n );\n this.useProvider = create(() => ({\n Provider: adapter.unstable_Provider ?? Fragment,\n }));\n this.__internal_setAdapter(adapter);\n\n this.switchToNewThread();\n }\n\n private useProvider;\n\n public __internal_setAdapter(adapter: RemoteThreadListAdapter) {\n if (this._adapter === adapter) return;\n\n this._adapter = adapter;\n\n const Provider = adapter.unstable_Provider ?? Fragment;\n if (Provider !== this.useProvider.getState().Provider) {\n this.useProvider.setState({ Provider }, true);\n }\n\n this._hookManager.setRuntimeHook(adapter.runtimeHook);\n }\n\n public __internal_bindAdapter() {\n this.getLoadThreadsPromise(); // begin loading on initial bind\n return this._adapter.subscribe?.({\n onGenerateTitle: this._onGenerateTitle,\n });\n }\n\n public get threadIds() {\n return this._state.value.threadIds;\n }\n\n public get archivedThreadIds() {\n return this._state.value.archivedThreadIds;\n }\n\n public get newThreadId() {\n return this._state.value.newThreadId;\n }\n\n public get mainThreadId(): string {\n return this._mainThreadId;\n }\n\n public getMainThreadRuntimeCore() {\n const result = this._hookManager.getThreadRuntimeCore(this._mainThreadId);\n if (!result) return EMPTY_THREAD_CORE;\n return result;\n }\n\n public getThreadRuntimeCore(threadIdOrRemoteId: string) {\n const data = this.getItemById(threadIdOrRemoteId);\n if (!data) throw new Error(\"Thread not found\");\n\n const result = this._hookManager.getThreadRuntimeCore(data.threadId);\n if (!result) throw new Error(\"Thread not found\");\n return result;\n }\n\n public getItemById(threadIdOrRemoteId: string) {\n return getThreadData(this._state.value, threadIdOrRemoteId);\n }\n\n public async switchToThread(threadIdOrRemoteId: string): Promise<void> {\n const data = this.getItemById(threadIdOrRemoteId);\n if (!data) throw new Error(\"Thread not found\");\n\n if (this._mainThreadId === data.threadId) return;\n\n const task = this._hookManager.startThreadRuntime(data.threadId);\n if (this.mainThreadId !== undefined) {\n await task;\n } else {\n task.then(() => this._notifySubscribers());\n }\n\n if (data.status === \"archived\") await this.unarchive(data.threadId);\n this._mainThreadId = data.threadId;\n\n this._notifySubscribers();\n }\n\n public async switchToNewThread(): Promise<void> {\n // an initialization transaction is in progress, wait for it to settle\n while (\n this._state.baseValue.newThreadId !== undefined &&\n this._state.value.newThreadId === undefined\n ) {\n await this._state.waitForUpdate();\n }\n\n const state = this._state.value;\n let threadId: string | undefined = this._state.value.newThreadId;\n if (threadId === undefined) {\n do {\n threadId = `__LOCALID_${generateId()}`;\n } while (state.threadIdMap[threadId]);\n\n const mappingId = createThreadMappingId(threadId);\n this._state.update({\n ...state,\n newThreadId: threadId,\n threadIdMap: {\n ...state.threadIdMap,\n [threadId]: mappingId,\n },\n threadData: {\n ...state.threadData,\n [threadId]: {\n status: \"new\",\n threadId,\n },\n },\n });\n }\n\n return this.switchToThread(threadId);\n }\n\n public initialize = async (threadId: string) => {\n if (this._state.value.newThreadId !== threadId) {\n const data = this.getItemById(threadId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status === \"new\") throw new Error(\"Unexpected new state\");\n return data.initializeTask;\n }\n\n return this._state.optimisticUpdate({\n execute: () => {\n return this._adapter.initialize(threadId);\n },\n optimistic: (state) => {\n return updateStatusReducer(state, threadId, \"regular\");\n },\n loading: (state, task) => {\n const mappingId = createThreadMappingId(threadId);\n return {\n ...state,\n threadData: {\n ...state.threadData,\n [mappingId]: {\n ...state.threadData[mappingId],\n initializeTask: task,\n },\n },\n };\n },\n then: (state, { remoteId, externalId }) => {\n const data = getThreadData(state, threadId);\n if (!data) return state;\n\n const mappingId = createThreadMappingId(threadId);\n return {\n ...state,\n threadIdMap: {\n ...state.threadIdMap,\n [remoteId]: mappingId,\n },\n threadData: {\n ...state.threadData,\n [mappingId]: {\n ...data,\n initializeTask: Promise.resolve({ remoteId, externalId }),\n remoteId,\n externalId,\n },\n },\n };\n },\n });\n };\n\n private _onGenerateTitle = async (\n remoteId: string,\n begin: () => Promise<AssistantStream>,\n ) => {\n const data = this.getItemById(remoteId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status === \"new\") throw new Error(\"Thread is not yet initialized\");\n\n const stream = await begin();\n const messageStream = AssistantMessageStream.fromAssistantStream(stream);\n for await (const result of messageStream) {\n const newTitle =\n result.content.filter((c) => c.type === \"text\")[0]?.text ??\n \"New Thread\";\n const state = this._state.baseValue;\n this._state.update({\n ...state,\n threadData: {\n ...state.threadData,\n [data.threadId]: {\n ...data,\n title: newTitle,\n },\n },\n });\n }\n };\n\n public rename(threadIdOrRemoteId: string, newTitle: string): Promise<void> {\n const data = this.getItemById(threadIdOrRemoteId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status === \"new\") throw new Error(\"Thread is not yet initialized\");\n\n return this._state.optimisticUpdate({\n execute: async () => {\n const { remoteId } = await data.initializeTask;\n return this._adapter.rename(remoteId, newTitle);\n },\n optimistic: (state) => {\n const data = getThreadData(state, threadIdOrRemoteId);\n if (!data) return state;\n\n return {\n ...state,\n threadData: {\n ...state.threadData,\n [data.threadId]: {\n ...data,\n title: newTitle,\n },\n },\n };\n },\n });\n }\n\n private async _ensureThreadIsNotMain(threadId: string) {\n // if thread is main thread, switch to another thread\n if (threadId === this._mainThreadId) {\n await this.switchToNewThread();\n }\n }\n\n public async archive(threadIdOrRemoteId: string) {\n const data = this.getItemById(threadIdOrRemoteId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status !== \"regular\")\n throw new Error(\"Thread is not yet initialized or already archived\");\n\n return this._state.optimisticUpdate({\n execute: async () => {\n await this._ensureThreadIsNotMain(data.threadId);\n const { remoteId } = await data.initializeTask;\n return this._adapter.archive(remoteId);\n },\n optimistic: (state) => {\n return updateStatusReducer(state, data.threadId, \"archived\");\n },\n });\n }\n\n public unarchive(threadIdOrRemoteId: string): Promise<void> {\n const data = this.getItemById(threadIdOrRemoteId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status !== \"archived\") throw new Error(\"Thread is not archived\");\n\n return this._state.optimisticUpdate({\n execute: async () => {\n try {\n const { remoteId } = await data.initializeTask;\n return await this._adapter.unarchive(remoteId);\n } catch (error) {\n await this._ensureThreadIsNotMain(data.threadId);\n throw error;\n }\n },\n optimistic: (state) => {\n return updateStatusReducer(state, data.threadId, \"regular\");\n },\n });\n }\n\n public async delete(threadIdOrRemoteId: string) {\n const data = this.getItemById(threadIdOrRemoteId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status !== \"regular\" && data.status !== \"archived\")\n throw new Error(\"Thread is not yet initialized\");\n\n return this._state.optimisticUpdate({\n execute: async () => {\n await this._ensureThreadIsNotMain(data.threadId);\n const { remoteId } = await data.initializeTask;\n return await this._adapter.delete(remoteId);\n },\n optimistic: (state) => {\n return updateStatusReducer(state, data.threadId, \"deleted\");\n },\n });\n }\n\n private useBoundIds = create<string[]>(() => []);\n\n public __internal_RenderComponent: FC = () => {\n const id = useId();\n useEffect(() => {\n this.useBoundIds.setState((s) => [...s, id], true);\n return () => {\n this.useBoundIds.setState((s) => s.filter((i) => i !== id), true);\n };\n }, []);\n\n const boundIds = this.useBoundIds();\n const { Provider } = this.useProvider();\n\n const adapters = {\n modelContext: this.contextProvider,\n };\n\n return (\n (boundIds.length === 0 || boundIds[0] === id) && (\n // only render if the component is the first one mounted\n <RuntimeAdapterProvider adapters={adapters}>\n <this._hookManager.__internal_RenderThreadRuntimes\n provider={Provider}\n />\n </RuntimeAdapterProvider>\n )\n );\n };\n}\n"],"mappings":";;;AAGA,SAAS,kBAAkB;AAK3B,SAAS,2CAA2C;AACpD,SAAS,wBAAwB;AACjC,SAAS,yBAAyB;AAClC,SAAS,uBAAuB;AAChC,SAAa,UAAU,WAAW,aAAa;AAC/C,SAAS,cAAc;AACvB,SAA0B,8BAA8B;AAExD,SAAS,8BAA8B;AA2hB7B;AA/fV,SAAS,sBAAsB,IAA+B;AAC5D,SAAO;AACT;AAWA,IAAM,gBAAgB,CACpB,OACA,uBACG;AACH,QAAM,MAAM,MAAM,YAAY,kBAAkB;AAChD,MAAI,QAAQ,OAAW,QAAO;AAC9B,SAAO,MAAM,WAAW,GAAG;AAC7B;AAEA,IAAM,sBAAsB,CAC1B,OACA,oBACA,cACG;AACH,QAAM,OAAO,cAAc,OAAO,kBAAkB;AACpD,MAAI,CAAC,KAAM,QAAO;AAElB,QAAM,EAAE,UAAU,UAAU,QA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AAK,YAAY;AAEtC,UAAM,WAAW;AAAA,MACf,cAAc,KAAK;AAAA,IACrB;AAEA,YACG,SAAS,WAAW,KAAK,SAAS,CAAC,MAAM;AAAA,IAExC,oBAAC,0BAAuB,UACtB;AAAA,MAAC,KAAK,aAAa;AAAA,MAAlB;AAAA,QACC,UAAU;AAAA;AAAA,IACZ,GACF;AAAA,EAGN;AACF;","names":["data"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useRemoteThreadListRuntime.d.ts","sourceRoot":"","sources":["../../../src/runtimes/remote-thread-list/useRemoteThreadListRuntime.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;
|
1
|
+
{"version":3,"file":"useRemoteThreadListRuntime.d.ts","sourceRoot":"","sources":["../../../src/runtimes/remote-thread-list/useRemoteThreadListRuntime.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAuBlD,eAAO,MAAM,0BAA0B,YAC5B,uBAAuB,qCAQjC,CAAC"}
|
@@ -32,7 +32,10 @@ var RemoteThreadListRuntimeCore = class extends import_BaseAssistantRuntimeCore.
|
|
32
32
|
threads;
|
33
33
|
constructor(adapter) {
|
34
34
|
super();
|
35
|
-
this.threads = new import_RemoteThreadListThreadListRuntimeCore.RemoteThreadListThreadListRuntimeCore(
|
35
|
+
this.threads = new import_RemoteThreadListThreadListRuntimeCore.RemoteThreadListThreadListRuntimeCore(
|
36
|
+
adapter,
|
37
|
+
this._contextProvider
|
38
|
+
);
|
36
39
|
}
|
37
40
|
get RenderComponent() {
|
38
41
|
return this.threads.__internal_RenderComponent;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/runtimes/remote-thread-list/useRemoteThreadListRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport { useState, useEffect, useMemo } from \"react\";\nimport { BaseAssistantRuntimeCore } from \"../core/BaseAssistantRuntimeCore\";\nimport { RemoteThreadListThreadListRuntimeCore } from \"./RemoteThreadListThreadListRuntimeCore\";\nimport { RemoteThreadListAdapter } from \"./types\";\nimport { AssistantRuntimeImpl } from \"../../internal\";\nimport { AssistantRuntimeCore } from \"../core/AssistantRuntimeCore\";\n\nclass RemoteThreadListRuntimeCore\n extends BaseAssistantRuntimeCore\n implements AssistantRuntimeCore\n{\n public readonly threads;\n\n constructor(adapter: RemoteThreadListAdapter) {\n super();\n this.threads = new RemoteThreadListThreadListRuntimeCore(adapter);\n }\n\n public get RenderComponent() {\n return this.threads.__internal_RenderComponent;\n }\n}\n\nexport const useRemoteThreadListRuntime = (\n adapter: RemoteThreadListAdapter,\n) => {\n const [runtime] = useState(() => new RemoteThreadListRuntimeCore(adapter));\n useEffect(() => {\n runtime.threads.__internal_setAdapter(adapter);\n return runtime.threads.__internal_bindAdapter();\n }, [runtime, adapter]);\n return useMemo(() => AssistantRuntimeImpl.create(runtime), [runtime]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA6C;AAC7C,sCAAyC;AACzC,mDAAsD;AAEtD,sBAAqC;AAGrC,IAAM,8BAAN,cACU,yDAEV;AAAA,EACkB;AAAA,EAEhB,YAAY,SAAkC;AAC5C,UAAM;AACN,SAAK,UAAU,IAAI,
|
1
|
+
{"version":3,"sources":["../../../src/runtimes/remote-thread-list/useRemoteThreadListRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport { useState, useEffect, useMemo } from \"react\";\nimport { BaseAssistantRuntimeCore } from \"../core/BaseAssistantRuntimeCore\";\nimport { RemoteThreadListThreadListRuntimeCore } from \"./RemoteThreadListThreadListRuntimeCore\";\nimport { RemoteThreadListAdapter } from \"./types\";\nimport { AssistantRuntimeImpl } from \"../../internal\";\nimport { AssistantRuntimeCore } from \"../core/AssistantRuntimeCore\";\n\nclass RemoteThreadListRuntimeCore\n extends BaseAssistantRuntimeCore\n implements AssistantRuntimeCore\n{\n public readonly threads;\n\n constructor(adapter: RemoteThreadListAdapter) {\n super();\n this.threads = new RemoteThreadListThreadListRuntimeCore(\n adapter,\n this._contextProvider,\n );\n }\n\n public get RenderComponent() {\n return this.threads.__internal_RenderComponent;\n }\n}\n\nexport const useRemoteThreadListRuntime = (\n adapter: RemoteThreadListAdapter,\n) => {\n const [runtime] = useState(() => new RemoteThreadListRuntimeCore(adapter));\n useEffect(() => {\n runtime.threads.__internal_setAdapter(adapter);\n return runtime.threads.__internal_bindAdapter();\n }, [runtime, adapter]);\n return useMemo(() => AssistantRuntimeImpl.create(runtime), [runtime]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA6C;AAC7C,sCAAyC;AACzC,mDAAsD;AAEtD,sBAAqC;AAGrC,IAAM,8BAAN,cACU,yDAEV;AAAA,EACkB;AAAA,EAEhB,YAAY,SAAkC;AAC5C,UAAM;AACN,SAAK,UAAU,IAAI;AAAA,MACjB;AAAA,MACA,KAAK;AAAA,IACP;AAAA,EACF;AAAA,EAEA,IAAW,kBAAkB;AAC3B,WAAO,KAAK,QAAQ;AAAA,EACtB;AACF;AAEO,IAAM,6BAA6B,CACxC,YACG;AACH,QAAM,CAAC,OAAO,QAAI,uBAAS,MAAM,IAAI,4BAA4B,OAAO,CAAC;AACzE,8BAAU,MAAM;AACd,YAAQ,QAAQ,sBAAsB,OAAO;AAC7C,WAAO,QAAQ,QAAQ,uBAAuB;AAAA,EAChD,GAAG,CAAC,SAAS,OAAO,CAAC;AACrB,aAAO,sBAAQ,MAAM,qCAAqB,OAAO,OAAO,GAAG,CAAC,OAAO,CAAC;AACtE;","names":[]}
|
@@ -9,7 +9,10 @@ var RemoteThreadListRuntimeCore = class extends BaseAssistantRuntimeCore {
|
|
9
9
|
threads;
|
10
10
|
constructor(adapter) {
|
11
11
|
super();
|
12
|
-
this.threads = new RemoteThreadListThreadListRuntimeCore(
|
12
|
+
this.threads = new RemoteThreadListThreadListRuntimeCore(
|
13
|
+
adapter,
|
14
|
+
this._contextProvider
|
15
|
+
);
|
13
16
|
}
|
14
17
|
get RenderComponent() {
|
15
18
|
return this.threads.__internal_RenderComponent;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/runtimes/remote-thread-list/useRemoteThreadListRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport { useState, useEffect, useMemo } from \"react\";\nimport { BaseAssistantRuntimeCore } from \"../core/BaseAssistantRuntimeCore\";\nimport { RemoteThreadListThreadListRuntimeCore } from \"./RemoteThreadListThreadListRuntimeCore\";\nimport { RemoteThreadListAdapter } from \"./types\";\nimport { AssistantRuntimeImpl } from \"../../internal\";\nimport { AssistantRuntimeCore } from \"../core/AssistantRuntimeCore\";\n\nclass RemoteThreadListRuntimeCore\n extends BaseAssistantRuntimeCore\n implements AssistantRuntimeCore\n{\n public readonly threads;\n\n constructor(adapter: RemoteThreadListAdapter) {\n super();\n this.threads = new RemoteThreadListThreadListRuntimeCore(adapter);\n }\n\n public get RenderComponent() {\n return this.threads.__internal_RenderComponent;\n }\n}\n\nexport const useRemoteThreadListRuntime = (\n adapter: RemoteThreadListAdapter,\n) => {\n const [runtime] = useState(() => new RemoteThreadListRuntimeCore(adapter));\n useEffect(() => {\n runtime.threads.__internal_setAdapter(adapter);\n return runtime.threads.__internal_bindAdapter();\n }, [runtime, adapter]);\n return useMemo(() => AssistantRuntimeImpl.create(runtime), [runtime]);\n};\n"],"mappings":";;;AAEA,SAAS,UAAU,WAAW,eAAe;AAC7C,SAAS,gCAAgC;AACzC,SAAS,6CAA6C;AAEtD,SAAS,4BAA4B;AAGrC,IAAM,8BAAN,cACU,yBAEV;AAAA,EACkB;AAAA,EAEhB,YAAY,SAAkC;AAC5C,UAAM;AACN,SAAK,UAAU,IAAI,
|
1
|
+
{"version":3,"sources":["../../../src/runtimes/remote-thread-list/useRemoteThreadListRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport { useState, useEffect, useMemo } from \"react\";\nimport { BaseAssistantRuntimeCore } from \"../core/BaseAssistantRuntimeCore\";\nimport { RemoteThreadListThreadListRuntimeCore } from \"./RemoteThreadListThreadListRuntimeCore\";\nimport { RemoteThreadListAdapter } from \"./types\";\nimport { AssistantRuntimeImpl } from \"../../internal\";\nimport { AssistantRuntimeCore } from \"../core/AssistantRuntimeCore\";\n\nclass RemoteThreadListRuntimeCore\n extends BaseAssistantRuntimeCore\n implements AssistantRuntimeCore\n{\n public readonly threads;\n\n constructor(adapter: RemoteThreadListAdapter) {\n super();\n this.threads = new RemoteThreadListThreadListRuntimeCore(\n adapter,\n this._contextProvider,\n );\n }\n\n public get RenderComponent() {\n return this.threads.__internal_RenderComponent;\n }\n}\n\nexport const useRemoteThreadListRuntime = (\n adapter: RemoteThreadListAdapter,\n) => {\n const [runtime] = useState(() => new RemoteThreadListRuntimeCore(adapter));\n useEffect(() => {\n runtime.threads.__internal_setAdapter(adapter);\n return runtime.threads.__internal_bindAdapter();\n }, [runtime, adapter]);\n return useMemo(() => AssistantRuntimeImpl.create(runtime), [runtime]);\n};\n"],"mappings":";;;AAEA,SAAS,UAAU,WAAW,eAAe;AAC7C,SAAS,gCAAgC;AACzC,SAAS,6CAA6C;AAEtD,SAAS,4BAA4B;AAGrC,IAAM,8BAAN,cACU,yBAEV;AAAA,EACkB;AAAA,EAEhB,YAAY,SAAkC;AAC5C,UAAM;AACN,SAAK,UAAU,IAAI;AAAA,MACjB;AAAA,MACA,KAAK;AAAA,IACP;AAAA,EACF;AAAA,EAEA,IAAW,kBAAkB;AAC3B,WAAO,KAAK,QAAQ;AAAA,EACtB;AACF;AAEO,IAAM,6BAA6B,CACxC,YACG;AACH,QAAM,CAAC,OAAO,IAAI,SAAS,MAAM,IAAI,4BAA4B,OAAO,CAAC;AACzE,YAAU,MAAM;AACd,YAAQ,QAAQ,sBAAsB,OAAO;AAC7C,WAAO,QAAQ,QAAQ,uBAAuB;AAAA,EAChD,GAAG,CAAC,SAAS,OAAO,CAAC;AACrB,SAAO,QAAQ,MAAM,qBAAqB,OAAO,OAAO,GAAG,CAAC,OAAO,CAAC;AACtE;","names":[]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useSmooth.d.ts","sourceRoot":"","sources":["../../../src/utils/smooth/useSmooth.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAqB,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAIhF,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AA4DhE,eAAO,MAAM,SAAS,UACb,gBAAgB,GAAG,eAAe,WACjC,OAAO,KACd,gBAAgB,GAAG,
|
1
|
+
{"version":3,"file":"useSmooth.d.ts","sourceRoot":"","sources":["../../../src/utils/smooth/useSmooth.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAqB,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAIhF,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AA4DhE,eAAO,MAAM,SAAS,UACb,gBAAgB,GAAG,eAAe,WACjC,OAAO,KACd,gBAAgB,GAAG,eA2ErB,CAAC"}
|
@@ -88,18 +88,16 @@ var useSmooth = (state, smooth = false) => {
|
|
88
88
|
const setText = (0, import_react_use_callback_ref.useCallbackRef)((text2) => {
|
89
89
|
setDisplayedText(text2);
|
90
90
|
if (smoothStatusStore) {
|
91
|
-
|
92
|
-
|
93
|
-
);
|
91
|
+
const target = displayedText !== text2 || state.status.type === "running" ? SMOOTH_STATUS : state.status;
|
92
|
+
(0, import_ReadonlyStore.writableStore)(smoothStatusStore).setState(target, true);
|
94
93
|
}
|
95
94
|
});
|
96
95
|
(0, import_react.useEffect)(() => {
|
97
96
|
if (smoothStatusStore) {
|
98
|
-
|
99
|
-
|
100
|
-
);
|
97
|
+
const target = displayedText !== text || state.status.type === "running" ? SMOOTH_STATUS : state.status;
|
98
|
+
(0, import_ReadonlyStore.writableStore)(smoothStatusStore).setState(target, true);
|
101
99
|
}
|
102
|
-
}, [smoothStatusStore, text, displayedText, state.status
|
100
|
+
}, [smoothStatusStore, text, displayedText, state.status]);
|
103
101
|
const [animatorRef] = (0, import_react.useState)(
|
104
102
|
new TextStreamAnimator(text, setText)
|
105
103
|
);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/smooth/useSmooth.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useMemo, useRef, useState } from \"react\";\nimport { useMessage } from \"../../context\";\nimport { ContentPartStatus, TextContentPart } from \"../../types/AssistantTypes\";\nimport { useCallbackRef } from \"@radix-ui/react-use-callback-ref\";\nimport { useSmoothStatusStore } from \"./SmoothContext\";\nimport { writableStore } from \"../../context/ReadonlyStore\";\nimport { ContentPartState } from \"../../api/ContentPartRuntime\";\n\nclass TextStreamAnimator {\n private animationFrameId: number | null = null;\n private lastUpdateTime: number = Date.now();\n\n public targetText: string = \"\";\n\n constructor(\n public currentText: string,\n private setText: (newText: string) => void,\n ) {}\n\n start() {\n if (this.animationFrameId !== null) return;\n this.lastUpdateTime = Date.now();\n this.animate();\n }\n\n stop() {\n if (this.animationFrameId !== null) {\n cancelAnimationFrame(this.animationFrameId);\n this.animationFrameId = null;\n }\n }\n\n private animate = () => {\n const currentTime = Date.now();\n const deltaTime = currentTime - this.lastUpdateTime;\n let timeToConsume = deltaTime;\n\n const remainingChars = this.targetText.length - this.currentText.length;\n const baseTimePerChar = Math.min(5, 250 / remainingChars);\n\n let charsToAdd = 0;\n while (timeToConsume >= baseTimePerChar && charsToAdd < remainingChars) {\n charsToAdd++;\n timeToConsume -= baseTimePerChar;\n }\n\n if (charsToAdd !== remainingChars) {\n this.animationFrameId = requestAnimationFrame(this.animate);\n } else {\n this.animationFrameId = null;\n }\n if (charsToAdd === 0) return;\n\n this.currentText = this.targetText.slice(\n 0,\n this.currentText.length + charsToAdd,\n );\n this.lastUpdateTime = currentTime - timeToConsume;\n this.setText(this.currentText);\n };\n}\n\nconst SMOOTH_STATUS: ContentPartStatus = Object.freeze({\n type: \"running\",\n});\n\nexport const useSmooth = (\n state: ContentPartState & TextContentPart,\n smooth: boolean = false,\n): ContentPartState & TextContentPart => {\n const { text } = state;\n const id = useMessage({\n optional: true,\n selector: (m: { id: string }) => m.id,\n });\n\n const idRef = useRef(id);\n const [displayedText, setDisplayedText] = useState(text);\n\n const smoothStatusStore = useSmoothStatusStore({ optional: true });\n const setText = useCallbackRef((text: string) => {\n setDisplayedText(text);\n if (smoothStatusStore) {\n
|
1
|
+
{"version":3,"sources":["../../../src/utils/smooth/useSmooth.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useMemo, useRef, useState } from \"react\";\nimport { useMessage } from \"../../context\";\nimport { ContentPartStatus, TextContentPart } from \"../../types/AssistantTypes\";\nimport { useCallbackRef } from \"@radix-ui/react-use-callback-ref\";\nimport { useSmoothStatusStore } from \"./SmoothContext\";\nimport { writableStore } from \"../../context/ReadonlyStore\";\nimport { ContentPartState } from \"../../api/ContentPartRuntime\";\n\nclass TextStreamAnimator {\n private animationFrameId: number | null = null;\n private lastUpdateTime: number = Date.now();\n\n public targetText: string = \"\";\n\n constructor(\n public currentText: string,\n private setText: (newText: string) => void,\n ) {}\n\n start() {\n if (this.animationFrameId !== null) return;\n this.lastUpdateTime = Date.now();\n this.animate();\n }\n\n stop() {\n if (this.animationFrameId !== null) {\n cancelAnimationFrame(this.animationFrameId);\n this.animationFrameId = null;\n }\n }\n\n private animate = () => {\n const currentTime = Date.now();\n const deltaTime = currentTime - this.lastUpdateTime;\n let timeToConsume = deltaTime;\n\n const remainingChars = this.targetText.length - this.currentText.length;\n const baseTimePerChar = Math.min(5, 250 / remainingChars);\n\n let charsToAdd = 0;\n while (timeToConsume >= baseTimePerChar && charsToAdd < remainingChars) {\n charsToAdd++;\n timeToConsume -= baseTimePerChar;\n }\n\n if (charsToAdd !== remainingChars) {\n this.animationFrameId = requestAnimationFrame(this.animate);\n } else {\n this.animationFrameId = null;\n }\n if (charsToAdd === 0) return;\n\n this.currentText = this.targetText.slice(\n 0,\n this.currentText.length + charsToAdd,\n );\n this.lastUpdateTime = currentTime - timeToConsume;\n this.setText(this.currentText);\n };\n}\n\nconst SMOOTH_STATUS: ContentPartStatus = Object.freeze({\n type: \"running\",\n});\n\nexport const useSmooth = (\n state: ContentPartState & TextContentPart,\n smooth: boolean = false,\n): ContentPartState & TextContentPart => {\n const { text } = state;\n const id = useMessage({\n optional: true,\n selector: (m: { id: string }) => m.id,\n });\n\n const idRef = useRef(id);\n const [displayedText, setDisplayedText] = useState(text);\n\n const smoothStatusStore = useSmoothStatusStore({ optional: true });\n const setText = useCallbackRef((text: string) => {\n setDisplayedText(text);\n if (smoothStatusStore) {\n const target =\n displayedText !== text || state.status.type === \"running\"\n ? SMOOTH_STATUS\n : state.status;\n writableStore(smoothStatusStore).setState(target, true);\n }\n });\n\n // TODO this is hacky\n useEffect(() => {\n if (smoothStatusStore) {\n const target =\n displayedText !== text || state.status.type === \"running\"\n ? SMOOTH_STATUS\n : state.status;\n writableStore(smoothStatusStore).setState(target, true);\n }\n }, [smoothStatusStore, text, displayedText, state.status]);\n\n const [animatorRef] = useState<TextStreamAnimator>(\n new TextStreamAnimator(text, setText),\n );\n\n useEffect(() => {\n if (!smooth) {\n animatorRef.stop();\n return;\n }\n\n if (idRef.current !== id || !text.startsWith(animatorRef.targetText)) {\n idRef.current = id;\n setText(text);\n\n animatorRef.currentText = text;\n animatorRef.targetText = text;\n animatorRef.stop();\n\n return;\n }\n\n animatorRef.targetText = text;\n animatorRef.start();\n }, [setText, animatorRef, id, smooth, text]);\n\n useEffect(() => {\n return () => {\n animatorRef.stop();\n };\n }, [animatorRef]);\n\n return useMemo(\n () =>\n smooth\n ? {\n type: \"text\",\n text: displayedText,\n status: text === displayedText ? state.status : SMOOTH_STATUS,\n }\n : state,\n [smooth, displayedText, state, text],\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAqD;AACrD,qBAA2B;AAE3B,oC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AM;AAAA,MACN,QAAQ,SAAS,gBAAgB,MAAM,SAAS;AAAA,IAClD,IACA;AAAA,IACN,CAAC,QAAQ,eAAe,OAAO,IAAI;AAAA,EACrC;AACF;","names":["text"]}
|
@@ -65,18 +65,16 @@ var useSmooth = (state, smooth = false) => {
|
|
65
65
|
const setText = useCallbackRef((text2) => {
|
66
66
|
setDisplayedText(text2);
|
67
67
|
if (smoothStatusStore) {
|
68
|
-
|
69
|
-
|
70
|
-
);
|
68
|
+
const target = displayedText !== text2 || state.status.type === "running" ? SMOOTH_STATUS : state.status;
|
69
|
+
writableStore(smoothStatusStore).setState(target, true);
|
71
70
|
}
|
72
71
|
});
|
73
72
|
useEffect(() => {
|
74
73
|
if (smoothStatusStore) {
|
75
|
-
|
76
|
-
|
77
|
-
);
|
74
|
+
const target = displayedText !== text || state.status.type === "running" ? SMOOTH_STATUS : state.status;
|
75
|
+
writableStore(smoothStatusStore).setState(target, true);
|
78
76
|
}
|
79
|
-
}, [smoothStatusStore, text, displayedText, state.status
|
77
|
+
}, [smoothStatusStore, text, displayedText, state.status]);
|
80
78
|
const [animatorRef] = useState(
|
81
79
|
new TextStreamAnimator(text, setText)
|
82
80
|
);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/smooth/useSmooth.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useMemo, useRef, useState } from \"react\";\nimport { useMessage } from \"../../context\";\nimport { ContentPartStatus, TextContentPart } from \"../../types/AssistantTypes\";\nimport { useCallbackRef } from \"@radix-ui/react-use-callback-ref\";\nimport { useSmoothStatusStore } from \"./SmoothContext\";\nimport { writableStore } from \"../../context/ReadonlyStore\";\nimport { ContentPartState } from \"../../api/ContentPartRuntime\";\n\nclass TextStreamAnimator {\n private animationFrameId: number | null = null;\n private lastUpdateTime: number = Date.now();\n\n public targetText: string = \"\";\n\n constructor(\n public currentText: string,\n private setText: (newText: string) => void,\n ) {}\n\n start() {\n if (this.animationFrameId !== null) return;\n this.lastUpdateTime = Date.now();\n this.animate();\n }\n\n stop() {\n if (this.animationFrameId !== null) {\n cancelAnimationFrame(this.animationFrameId);\n this.animationFrameId = null;\n }\n }\n\n private animate = () => {\n const currentTime = Date.now();\n const deltaTime = currentTime - this.lastUpdateTime;\n let timeToConsume = deltaTime;\n\n const remainingChars = this.targetText.length - this.currentText.length;\n const baseTimePerChar = Math.min(5, 250 / remainingChars);\n\n let charsToAdd = 0;\n while (timeToConsume >= baseTimePerChar && charsToAdd < remainingChars) {\n charsToAdd++;\n timeToConsume -= baseTimePerChar;\n }\n\n if (charsToAdd !== remainingChars) {\n this.animationFrameId = requestAnimationFrame(this.animate);\n } else {\n this.animationFrameId = null;\n }\n if (charsToAdd === 0) return;\n\n this.currentText = this.targetText.slice(\n 0,\n this.currentText.length + charsToAdd,\n );\n this.lastUpdateTime = currentTime - timeToConsume;\n this.setText(this.currentText);\n };\n}\n\nconst SMOOTH_STATUS: ContentPartStatus = Object.freeze({\n type: \"running\",\n});\n\nexport const useSmooth = (\n state: ContentPartState & TextContentPart,\n smooth: boolean = false,\n): ContentPartState & TextContentPart => {\n const { text } = state;\n const id = useMessage({\n optional: true,\n selector: (m: { id: string }) => m.id,\n });\n\n const idRef = useRef(id);\n const [displayedText, setDisplayedText] = useState(text);\n\n const smoothStatusStore = useSmoothStatusStore({ optional: true });\n const setText = useCallbackRef((text: string) => {\n setDisplayedText(text);\n if (smoothStatusStore) {\n
|
1
|
+
{"version":3,"sources":["../../../src/utils/smooth/useSmooth.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useMemo, useRef, useState } from \"react\";\nimport { useMessage } from \"../../context\";\nimport { ContentPartStatus, TextContentPart } from \"../../types/AssistantTypes\";\nimport { useCallbackRef } from \"@radix-ui/react-use-callback-ref\";\nimport { useSmoothStatusStore } from \"./SmoothContext\";\nimport { writableStore } from \"../../context/ReadonlyStore\";\nimport { ContentPartState } from \"../../api/ContentPartRuntime\";\n\nclass TextStreamAnimator {\n private animationFrameId: number | null = null;\n private lastUpdateTime: number = Date.now();\n\n public targetText: string = \"\";\n\n constructor(\n public currentText: string,\n private setText: (newText: string) => void,\n ) {}\n\n start() {\n if (this.animationFrameId !== null) return;\n this.lastUpdateTime = Date.now();\n this.animate();\n }\n\n stop() {\n if (this.animationFrameId !== null) {\n cancelAnimationFrame(this.animationFrameId);\n this.animationFrameId = null;\n }\n }\n\n private animate = () => {\n const currentTime = Date.now();\n const deltaTime = currentTime - this.lastUpdateTime;\n let timeToConsume = deltaTime;\n\n const remainingChars = this.targetText.length - this.currentText.length;\n const baseTimePerChar = Math.min(5, 250 / remainingChars);\n\n let charsToAdd = 0;\n while (timeToConsume >= baseTimePerChar && charsToAdd < remainingChars) {\n charsToAdd++;\n timeToConsume -= baseTimePerChar;\n }\n\n if (charsToAdd !== remainingChars) {\n this.animationFrameId = requestAnimationFrame(this.animate);\n } else {\n this.animationFrameId = null;\n }\n if (charsToAdd === 0) return;\n\n this.currentText = this.targetText.slice(\n 0,\n this.currentText.length + charsToAdd,\n );\n this.lastUpdateTime = currentTime - timeToConsume;\n this.setText(this.currentText);\n };\n}\n\nconst SMOOTH_STATUS: ContentPartStatus = Object.freeze({\n type: \"running\",\n});\n\nexport const useSmooth = (\n state: ContentPartState & TextContentPart,\n smooth: boolean = false,\n): ContentPartState & TextContentPart => {\n const { text } = state;\n const id = useMessage({\n optional: true,\n selector: (m: { id: string }) => m.id,\n });\n\n const idRef = useRef(id);\n const [displayedText, setDisplayedText] = useState(text);\n\n const smoothStatusStore = useSmoothStatusStore({ optional: true });\n const setText = useCallbackRef((text: string) => {\n setDisplayedText(text);\n if (smoothStatusStore) {\n const target =\n displayedText !== text || state.status.type === \"running\"\n ? SMOOTH_STATUS\n : state.status;\n writableStore(smoothStatusStore).setState(target, true);\n }\n });\n\n // TODO this is hacky\n useEffect(() => {\n if (smoothStatusStore) {\n const target =\n displayedText !== text || state.status.type === \"running\"\n ? SMOOTH_STATUS\n : state.status;\n writableStore(smoothStatusStore).setState(target, true);\n }\n }, [smoothStatusStore, text, displayedText, state.status]);\n\n const [animatorRef] = useState<TextStreamAnimator>(\n new TextStreamAnimator(text, setText),\n );\n\n useEffect(() => {\n if (!smooth) {\n animatorRef.stop();\n return;\n }\n\n if (idRef.current !== id || !text.startsWith(animatorRef.targetText)) {\n idRef.current = id;\n setText(text);\n\n animatorRef.currentText = text;\n animatorRef.targetText = text;\n animatorRef.stop();\n\n return;\n }\n\n animatorRef.targetText = text;\n animatorRef.start();\n }, [setText, animatorRef, id, smooth, text]);\n\n useEffect(() => {\n return () => {\n animatorRef.stop();\n };\n }, [animatorRef]);\n\n return useMemo(\n () =>\n smooth\n ? {\n type: \"text\",\n text: displayedText,\n status: text === displayedText ? state.status : SMOOTH_STATUS,\n }\n : state,\n [smooth, displayedText, state, text],\n );\n};\n"],"mappings":";;;AAEA,SAAS,WAAW,SAAS,QAAQ,gBAAgB;AACrD,SAAS,kBAAkB;AAE3B,SAAS,sBAAsB;AAC/B,SAAS,4BAA4B;AACrC,SAAS,qBAAqB;AAG9B,IAAM,qBAAN,MAAyB;AAAA,EAMvB,YACS,aACC,SACR;AAFO;AACC;AAAA,EACP;AAAA,EARK,mBAAkC;AAAA,EAClC,iBAAyB,KAAK,IAAI;AAAA,EAEnC,aAAqB;AAAA,EAO5B,QAAQ;AACN,QAAI,KAAK,qBAAqB,KAAM;AACpC,SAAK,iBAAiB,KAAK,IAAI;AAC/B,SAAK,QAAQ;AAAA,EACf;AAAA,EAEA,OAAO;AACL,QAAI,KAAK,qBAAqB,MAAM;AAClC,2BAAqB,KAAK,gBAAgB;AAC1C,WAAK,mBAAmB;AAAA,IAC1B;AAAA,EACF;AAAA,EAEQ,UAAU,MAAM;AACtB,UAAM,cAAc,KAAK,IAAI;AAC7B,UAAM,YAAY,cAAc,KAAK;AACrC,QAAI,gBAAgB;AAEpB,UAAM,iBAAiB,KAAK,WAAW,SAAS,KAAK,YAAY;AACjE,UAAM,kBAAkB,KAAK,IAAI,GAAG,MAA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QAAM,CAAC,WAAW,IAAI;AAAA,IACpB,IAAI,mBAAmB,MAAM,OAAO;AAAA,EACtC;AAEA,YAAU,MAAM;AACd,QAAI,CAAC,QAAQ;AACX,kBAAY,KAAK;AACjB;AAAA,IACF;AAEA,QAAI,MAAM,YAAY,MAAM,CAAC,KAAK,WAAW,YAAY,UAAU,GAAG;AACpE,YAAM,UAAU;AAChB,cAAQ,IAAI;AAEZ,kBAAY,cAAc;AAC1B,kBAAY,aAAa;AACzB,kBAAY,KAAK;AAEjB;AAAA,IACF;AAEA,gBAAY,aAAa;AACzB,gBAAY,MAAM;AAAA,EACpB,GAAG,CAAC,SAAS,aAAa,IAAI,QAAQ,IAAI,CAAC;AAE3C,YAAU,MAAM;AACd,WAAO,MAAM;AACX,kBAAY,KAAK;AAAA,IACnB;AAAA,EACF,GAAG,CAAC,WAAW,CAAC;AAEhB,SAAO;AAAA,IACL,MACE,SACI;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA,MACN,QAAQ,SAAS,gBAAgB,MAAM,SAAS;AAAA,IAClD,IACA;AAAA,IACN,CAAC,QAAQ,eAAe,OAAO,IAAI;AAAA,EACrC;AACF;","names":["text"]}
|
package/package.json
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
import { createContext, FC, useContext } from "react";
|
2
2
|
import { ThreadHistoryAdapter } from "./thread-history/ThreadHistoryAdapter";
|
3
|
+
import { ModelContextProvider } from "../../model-context";
|
3
4
|
|
4
5
|
export type RuntimeAdapters = {
|
5
|
-
|
6
|
+
modelContext?: ModelContextProvider;
|
7
|
+
history?: ThreadHistoryAdapter;
|
6
8
|
};
|
7
9
|
|
8
10
|
const RuntimeAdaptersContext = createContext<RuntimeAdapters | null>(null);
|
@@ -18,8 +20,14 @@ export const RuntimeAdapterProvider: FC<RuntimeAdapterProvider.Props> = ({
|
|
18
20
|
adapters,
|
19
21
|
children,
|
20
22
|
}) => {
|
23
|
+
const context = useContext(RuntimeAdaptersContext);
|
21
24
|
return (
|
22
|
-
<RuntimeAdaptersContext.Provider
|
25
|
+
<RuntimeAdaptersContext.Provider
|
26
|
+
value={{
|
27
|
+
...context,
|
28
|
+
...adapters,
|
29
|
+
}}
|
30
|
+
>
|
23
31
|
{children}
|
24
32
|
</RuntimeAdaptersContext.Provider>
|
25
33
|
);
|
@@ -5,6 +5,7 @@ import { ExternalStoreRuntimeCore } from "./ExternalStoreRuntimeCore";
|
|
5
5
|
import { ExternalStoreAdapter } from "./ExternalStoreAdapter";
|
6
6
|
import { AssistantRuntimeImpl } from "../../api/AssistantRuntime";
|
7
7
|
import { ThreadRuntimeImpl } from "../../api/ThreadRuntime";
|
8
|
+
import { useRuntimeAdapters } from "../adapters/RuntimeAdapterProvider";
|
8
9
|
|
9
10
|
export const useExternalStoreRuntime = <T,>(store: ExternalStoreAdapter<T>) => {
|
10
11
|
const [runtime] = useState(() => new ExternalStoreRuntimeCore(store));
|
@@ -13,6 +14,13 @@ export const useExternalStoreRuntime = <T,>(store: ExternalStoreAdapter<T>) => {
|
|
13
14
|
runtime.setAdapter(store);
|
14
15
|
});
|
15
16
|
|
17
|
+
const { modelContext } = useRuntimeAdapters() ?? {};
|
18
|
+
|
19
|
+
useEffect(() => {
|
20
|
+
if (!modelContext) return undefined;
|
21
|
+
return runtime.registerModelContextProvider(modelContext);
|
22
|
+
}, [modelContext, runtime]);
|
23
|
+
|
16
24
|
return useMemo(
|
17
25
|
() => AssistantRuntimeImpl.create(runtime, ThreadRuntimeImpl),
|
18
26
|
[runtime],
|
@@ -38,7 +38,7 @@ export const useLocalRuntime = (
|
|
38
38
|
adapter: ChatModelAdapter,
|
39
39
|
{ initialMessages, ...options }: LocalRuntimeOptions = {},
|
40
40
|
) => {
|
41
|
-
const threadListAdapters = useRuntimeAdapters();
|
41
|
+
const { modelContext, ...threadListAdapters } = useRuntimeAdapters() ?? {};
|
42
42
|
const opt = useMemo(
|
43
43
|
() => ({
|
44
44
|
...options,
|
@@ -58,5 +58,10 @@ export const useLocalRuntime = (
|
|
58
58
|
runtime.threads.getMainThreadRuntimeCore().__internal_load();
|
59
59
|
}, [runtime, opt]);
|
60
60
|
|
61
|
+
useEffect(() => {
|
62
|
+
if (!modelContext) return undefined;
|
63
|
+
return runtime.registerModelContextProvider(modelContext);
|
64
|
+
}, [modelContext, runtime]);
|
65
|
+
|
61
66
|
return useMemo(() => LocalRuntimeImpl.create(runtime), [runtime]);
|
62
67
|
};
|
@@ -13,6 +13,8 @@ import { OptimisticState } from "./OptimisticState";
|
|
13
13
|
import { FC, Fragment, useEffect, useId } from "react";
|
14
14
|
import { create } from "zustand";
|
15
15
|
import { AssistantStream, AssistantMessageStream } from "assistant-stream";
|
16
|
+
import { ModelContextProvider } from "../../model-context";
|
17
|
+
import { RuntimeAdapterProvider } from "../adapters/RuntimeAdapterProvider";
|
16
18
|
|
17
19
|
type RemoteThreadData =
|
18
20
|
| {
|
@@ -225,7 +227,10 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
225
227
|
return this._loadThreadsPromise;
|
226
228
|
}
|
227
229
|
|
228
|
-
constructor(
|
230
|
+
constructor(
|
231
|
+
adapter: RemoteThreadListAdapter,
|
232
|
+
private readonly contextProvider: ModelContextProvider,
|
233
|
+
) {
|
229
234
|
super();
|
230
235
|
|
231
236
|
this._state.subscribe(() => this._notifySubscribers());
|
@@ -540,12 +545,18 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
540
545
|
const boundIds = this.useBoundIds();
|
541
546
|
const { Provider } = this.useProvider();
|
542
547
|
|
548
|
+
const adapters = {
|
549
|
+
modelContext: this.contextProvider,
|
550
|
+
};
|
551
|
+
|
543
552
|
return (
|
544
553
|
(boundIds.length === 0 || boundIds[0] === id) && (
|
545
554
|
// only render if the component is the first one mounted
|
546
|
-
<
|
547
|
-
|
548
|
-
|
555
|
+
<RuntimeAdapterProvider adapters={adapters}>
|
556
|
+
<this._hookManager.__internal_RenderThreadRuntimes
|
557
|
+
provider={Provider}
|
558
|
+
/>
|
559
|
+
</RuntimeAdapterProvider>
|
549
560
|
)
|
550
561
|
);
|
551
562
|
};
|
@@ -15,7 +15,10 @@ class RemoteThreadListRuntimeCore
|
|
15
15
|
|
16
16
|
constructor(adapter: RemoteThreadListAdapter) {
|
17
17
|
super();
|
18
|
-
this.threads = new RemoteThreadListThreadListRuntimeCore(
|
18
|
+
this.threads = new RemoteThreadListThreadListRuntimeCore(
|
19
|
+
adapter,
|
20
|
+
this._contextProvider,
|
21
|
+
);
|
19
22
|
}
|
20
23
|
|
21
24
|
public get RenderComponent() {
|
@@ -83,20 +83,24 @@ export const useSmooth = (
|
|
83
83
|
const setText = useCallbackRef((text: string) => {
|
84
84
|
setDisplayedText(text);
|
85
85
|
if (smoothStatusStore) {
|
86
|
-
|
87
|
-
|
88
|
-
|
86
|
+
const target =
|
87
|
+
displayedText !== text || state.status.type === "running"
|
88
|
+
? SMOOTH_STATUS
|
89
|
+
: state.status;
|
90
|
+
writableStore(smoothStatusStore).setState(target, true);
|
89
91
|
}
|
90
92
|
});
|
91
93
|
|
92
94
|
// TODO this is hacky
|
93
95
|
useEffect(() => {
|
94
96
|
if (smoothStatusStore) {
|
95
|
-
|
96
|
-
|
97
|
-
|
97
|
+
const target =
|
98
|
+
displayedText !== text || state.status.type === "running"
|
99
|
+
? SMOOTH_STATUS
|
100
|
+
: state.status;
|
101
|
+
writableStore(smoothStatusStore).setState(target, true);
|
98
102
|
}
|
99
|
-
}, [smoothStatusStore, text, displayedText, state.status
|
103
|
+
}, [smoothStatusStore, text, displayedText, state.status]);
|
100
104
|
|
101
105
|
const [animatorRef] = useState<TextStreamAnimator>(
|
102
106
|
new TextStreamAnimator(text, setText),
|