@langchain/langgraph-sdk 0.1.9 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/_virtual/rolldown_runtime.cjs +25 -0
- package/dist/auth/error.cjs +76 -86
- package/dist/auth/error.cjs.map +1 -0
- package/dist/auth/error.d.cts +13 -0
- package/dist/auth/error.d.cts.map +1 -0
- package/dist/auth/error.d.ts +12 -8
- package/dist/auth/error.d.ts.map +1 -0
- package/dist/auth/error.js +76 -83
- package/dist/auth/error.js.map +1 -0
- package/dist/auth/index.cjs +36 -44
- package/dist/auth/index.cjs.map +1 -0
- package/dist/auth/index.d.cts +31 -0
- package/dist/auth/index.d.cts.map +1 -0
- package/dist/auth/index.d.ts +20 -15
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +35 -39
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/types.d.cts +294 -0
- package/dist/auth/types.d.cts.map +1 -0
- package/dist/auth/types.d.ts +162 -165
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/client.cjs +1108 -1294
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +688 -0
- package/dist/client.d.cts.map +1 -0
- package/dist/client.d.ts +647 -639
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +1099 -1281
- package/dist/client.js.map +1 -0
- package/dist/index.cjs +6 -8
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -7
- package/dist/index.js +4 -2
- package/dist/logging/index.cjs +30 -31
- package/dist/logging/index.cjs.map +1 -0
- package/dist/logging/index.d.cts +47 -0
- package/dist/logging/index.d.cts.map +1 -0
- package/dist/logging/index.d.ts +20 -16
- package/dist/logging/index.d.ts.map +1 -0
- package/dist/logging/index.js +31 -29
- package/dist/logging/index.js.map +1 -0
- package/dist/react/index.cjs +5 -7
- package/dist/react/index.d.cts +4 -0
- package/dist/react/index.d.ts +4 -3
- package/dist/react/index.js +4 -2
- package/dist/react/stream.cjs +14 -15
- package/dist/react/stream.cjs.map +1 -0
- package/dist/react/stream.custom.cjs +126 -145
- package/dist/react/stream.custom.cjs.map +1 -0
- package/dist/react/stream.custom.d.cts +39 -0
- package/dist/react/stream.custom.d.cts.map +1 -0
- package/dist/react/stream.custom.d.ts +35 -37
- package/dist/react/stream.custom.d.ts.map +1 -0
- package/dist/react/stream.custom.js +122 -137
- package/dist/react/stream.custom.js.map +1 -0
- package/dist/react/stream.d.cts +73 -0
- package/dist/react/stream.d.cts.map +1 -0
- package/dist/react/stream.d.ts +21 -15
- package/dist/react/stream.d.ts.map +1 -0
- package/dist/react/stream.js +12 -11
- package/dist/react/stream.js.map +1 -0
- package/dist/react/stream.lgp.cjs +438 -495
- package/dist/react/stream.lgp.cjs.map +1 -0
- package/dist/react/stream.lgp.js +433 -487
- package/dist/react/stream.lgp.js.map +1 -0
- package/dist/react/thread.cjs +18 -15
- package/dist/react/thread.cjs.map +1 -0
- package/dist/react/thread.js +19 -13
- package/dist/react/thread.js.map +1 -0
- package/dist/react/types.d.cts +355 -0
- package/dist/react/types.d.cts.map +1 -0
- package/dist/react/types.d.ts +333 -329
- package/dist/react/types.d.ts.map +1 -0
- package/dist/react-ui/client.cjs +123 -184
- package/dist/react-ui/client.cjs.map +1 -0
- package/dist/react-ui/client.d.cts +90 -0
- package/dist/react-ui/client.d.cts.map +1 -0
- package/dist/react-ui/client.d.ts +67 -51
- package/dist/react-ui/client.d.ts.map +1 -0
- package/dist/react-ui/client.js +118 -143
- package/dist/react-ui/client.js.map +1 -0
- package/dist/react-ui/index.cjs +14 -13
- package/dist/react-ui/index.cjs.map +1 -0
- package/dist/react-ui/index.d.cts +3 -0
- package/dist/react-ui/index.d.ts +3 -2
- package/dist/react-ui/index.js +8 -3
- package/dist/react-ui/index.js.map +1 -0
- package/dist/react-ui/server/index.cjs +5 -7
- package/dist/react-ui/server/index.d.cts +3 -0
- package/dist/react-ui/server/index.d.ts +3 -2
- package/dist/react-ui/server/index.js +4 -2
- package/dist/react-ui/server/server.cjs +53 -44
- package/dist/react-ui/server/server.cjs.map +1 -0
- package/dist/react-ui/server/server.d.cts +55 -0
- package/dist/react-ui/server/server.d.cts.map +1 -0
- package/dist/react-ui/server/server.d.ts +43 -39
- package/dist/react-ui/server/server.d.ts.map +1 -0
- package/dist/react-ui/server/server.js +54 -42
- package/dist/react-ui/server/server.js.map +1 -0
- package/dist/react-ui/types.cjs +32 -36
- package/dist/react-ui/types.cjs.map +1 -0
- package/dist/react-ui/types.d.cts +25 -0
- package/dist/react-ui/types.d.cts.map +1 -0
- package/dist/react-ui/types.d.ts +23 -19
- package/dist/react-ui/types.d.ts.map +1 -0
- package/dist/react-ui/types.js +32 -34
- package/dist/react-ui/types.js.map +1 -0
- package/dist/schema.d.cts +277 -0
- package/dist/schema.d.cts.map +1 -0
- package/dist/schema.d.ts +249 -242
- package/dist/schema.d.ts.map +1 -0
- package/dist/singletons/fetch.cjs +16 -20
- package/dist/singletons/fetch.cjs.map +1 -0
- package/dist/singletons/fetch.d.cts +14 -0
- package/dist/singletons/fetch.d.cts.map +1 -0
- package/dist/singletons/fetch.d.ts +5 -2
- package/dist/singletons/fetch.d.ts.map +1 -0
- package/dist/singletons/fetch.js +16 -17
- package/dist/singletons/fetch.js.map +1 -0
- package/dist/types.d.cts +187 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.ts +178 -173
- package/dist/types.d.ts.map +1 -0
- package/dist/types.messages.d.cts +91 -0
- package/dist/types.messages.d.cts.map +1 -0
- package/dist/types.messages.d.ts +71 -66
- package/dist/types.messages.d.ts.map +1 -0
- package/dist/types.stream.d.cts +235 -0
- package/dist/types.stream.d.cts.map +1 -0
- package/dist/types.stream.d.ts +149 -142
- package/dist/types.stream.d.ts.map +1 -0
- package/dist/ui/branching.cjs +145 -141
- package/dist/ui/branching.cjs.map +1 -0
- package/dist/ui/branching.d.cts +22 -0
- package/dist/ui/branching.d.cts.map +1 -0
- package/dist/ui/branching.d.ts +17 -30
- package/dist/ui/branching.d.ts.map +1 -0
- package/dist/ui/branching.js +147 -139
- package/dist/ui/branching.js.map +1 -0
- package/dist/ui/errors.cjs +14 -12
- package/dist/ui/errors.cjs.map +1 -0
- package/dist/ui/errors.js +14 -9
- package/dist/ui/errors.js.map +1 -0
- package/dist/ui/manager.cjs +156 -232
- package/dist/ui/manager.cjs.map +1 -0
- package/dist/ui/manager.js +156 -228
- package/dist/ui/manager.js.map +1 -0
- package/dist/ui/messages.cjs +55 -69
- package/dist/ui/messages.cjs.map +1 -0
- package/dist/ui/messages.js +55 -66
- package/dist/ui/messages.js.map +1 -0
- package/dist/ui/utils.cjs +10 -10
- package/dist/ui/utils.cjs.map +1 -0
- package/dist/ui/utils.js +10 -8
- package/dist/ui/utils.js.map +1 -0
- package/dist/utils/async_caller.cjs +103 -185
- package/dist/utils/async_caller.cjs.map +1 -0
- package/dist/utils/async_caller.d.cts +53 -0
- package/dist/utils/async_caller.d.cts.map +1 -0
- package/dist/utils/async_caller.d.ts +36 -31
- package/dist/utils/async_caller.d.ts.map +1 -0
- package/dist/utils/async_caller.js +101 -177
- package/dist/utils/async_caller.js.map +1 -0
- package/dist/utils/env.cjs +11 -13
- package/dist/utils/env.cjs.map +1 -0
- package/dist/utils/env.js +11 -11
- package/dist/utils/env.js.map +1 -0
- package/dist/utils/signals.cjs +18 -19
- package/dist/utils/signals.cjs.map +1 -0
- package/dist/utils/signals.js +18 -17
- package/dist/utils/signals.js.map +1 -0
- package/dist/utils/sse.cjs +110 -140
- package/dist/utils/sse.cjs.map +1 -0
- package/dist/utils/sse.js +110 -138
- package/dist/utils/sse.js.map +1 -0
- package/dist/utils/stream.cjs +90 -114
- package/dist/utils/stream.cjs.map +1 -0
- package/dist/utils/stream.js +90 -111
- package/dist/utils/stream.js.map +1 -0
- package/package.json +72 -80
- package/auth.cjs +0 -1
- package/auth.d.cts +0 -1
- package/auth.d.ts +0 -1
- package/auth.js +0 -1
- package/client.cjs +0 -1
- package/client.d.cts +0 -1
- package/client.d.ts +0 -1
- package/client.js +0 -1
- package/dist/auth/types.cjs +0 -2
- package/dist/auth/types.js +0 -1
- package/dist/react/stream.lgp.d.ts +0 -7
- package/dist/react/thread.d.ts +0 -4
- package/dist/react/types.cjs +0 -2
- package/dist/react/types.js +0 -1
- package/dist/schema.cjs +0 -2
- package/dist/schema.js +0 -1
- package/dist/types.cjs +0 -2
- package/dist/types.js +0 -1
- package/dist/types.messages.cjs +0 -2
- package/dist/types.messages.js +0 -1
- package/dist/types.stream.cjs +0 -2
- package/dist/types.stream.js +0 -1
- package/dist/ui/branching.test.cjs +0 -370
- package/dist/ui/branching.test.d.ts +0 -1
- package/dist/ui/branching.test.js +0 -368
- package/dist/ui/errors.d.ts +0 -12
- package/dist/ui/manager.d.ts +0 -87
- package/dist/ui/messages.d.ts +0 -18
- package/dist/ui/utils.d.ts +0 -2
- package/dist/utils/env.d.ts +0 -1
- package/dist/utils/signals.d.ts +0 -1
- package/dist/utils/sse.d.ts +0 -8
- package/dist/utils/stream.d.ts +0 -13
- package/index.cjs +0 -1
- package/index.d.cts +0 -1
- package/index.d.ts +0 -1
- package/index.js +0 -1
- package/logging.cjs +0 -1
- package/logging.d.cts +0 -1
- package/logging.d.ts +0 -1
- package/logging.js +0 -1
- package/react-ui/server.cjs +0 -1
- package/react-ui/server.d.cts +0 -1
- package/react-ui/server.d.ts +0 -1
- package/react-ui/server.js +0 -1
- package/react-ui.cjs +0 -1
- package/react-ui.d.cts +0 -1
- package/react-ui.d.ts +0 -1
- package/react-ui.js +0 -1
- package/react.cjs +0 -1
- package/react.d.cts +0 -1
- package/react.d.ts +0 -1
- package/react.js +0 -1
|
@@ -1,74 +1,90 @@
|
|
|
1
|
+
import { UIMessage } from "./types.js";
|
|
2
|
+
import { UseStream } from "../react/types.js";
|
|
3
|
+
import { useStream } from "../react/stream.js";
|
|
1
4
|
import * as React from "react";
|
|
2
5
|
import * as JsxRuntime from "react/jsx-runtime";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import type { UseStream } from "../react/types.js";
|
|
6
|
+
|
|
7
|
+
//#region src/react-ui/client.d.ts
|
|
6
8
|
declare const UseStreamContext: React.Context<{
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}>;
|
|
10
|
-
type BagTemplate = {
|
|
11
|
-
ConfigurableType?: Record<string, unknown>;
|
|
9
|
+
stream: UseStream<Record<string, unknown>, {
|
|
10
|
+
ConfigurableType?: Record<string, unknown> | undefined;
|
|
12
11
|
InterruptType?: unknown;
|
|
13
12
|
CustomEventType?: unknown;
|
|
14
13
|
UpdateType?: unknown;
|
|
15
|
-
|
|
14
|
+
}>;
|
|
15
|
+
meta: unknown;
|
|
16
|
+
}>;
|
|
17
|
+
type BagTemplate = {
|
|
18
|
+
ConfigurableType?: Record<string, unknown>;
|
|
19
|
+
InterruptType?: unknown;
|
|
20
|
+
CustomEventType?: unknown;
|
|
21
|
+
UpdateType?: unknown;
|
|
22
|
+
MetaType?: unknown;
|
|
16
23
|
};
|
|
17
24
|
type GetMetaType<Bag extends BagTemplate> = Bag extends {
|
|
18
|
-
|
|
25
|
+
MetaType: unknown;
|
|
19
26
|
} ? Bag["MetaType"] : unknown;
|
|
20
27
|
interface UseStreamContext<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends BagTemplate = BagTemplate> extends UseStream<StateType, Bag> {
|
|
21
|
-
|
|
28
|
+
meta?: GetMetaType<Bag>;
|
|
22
29
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
declare function useStreamContext<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends {
|
|
31
|
+
ConfigurableType?: Record<string, unknown>;
|
|
32
|
+
InterruptType?: unknown;
|
|
33
|
+
CustomEventType?: unknown;
|
|
34
|
+
UpdateType?: unknown;
|
|
35
|
+
MetaType?: unknown;
|
|
29
36
|
} = BagTemplate>(): UseStreamContext<StateType, Bag>;
|
|
30
37
|
interface ComponentTarget {
|
|
31
|
-
|
|
32
|
-
|
|
38
|
+
comp: React.FunctionComponent | React.ComponentClass;
|
|
39
|
+
target: HTMLElement;
|
|
33
40
|
}
|
|
34
41
|
declare class ComponentStore {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
private cache;
|
|
43
|
+
private boundCache;
|
|
44
|
+
private callbacks;
|
|
45
|
+
respond(shadowRootId: string, comp: React.FunctionComponent | React.ComponentClass, targetElement: HTMLElement): void;
|
|
46
|
+
getBoundStore(shadowRootId: string): {
|
|
47
|
+
subscribe: (onStoreChange: () => void) => () => void;
|
|
48
|
+
getSnapshot: () => ComponentTarget | undefined;
|
|
49
|
+
};
|
|
43
50
|
}
|
|
44
51
|
declare const EXT_STORE_SYMBOL: unique symbol;
|
|
45
52
|
declare const REQUIRE_SYMBOL: unique symbol;
|
|
46
53
|
declare const REQUIRE_EXTRA_SYMBOL: unique symbol;
|
|
47
54
|
interface LoadExternalComponentProps extends Pick<React.HTMLAttributes<HTMLDivElement>, "style" | "className"> {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
55
|
+
/** Stream of the assistant */
|
|
56
|
+
stream: ReturnType<typeof useStream>;
|
|
57
|
+
/** Namespace of UI components. Defaults to assistant ID. */
|
|
58
|
+
namespace?: string;
|
|
59
|
+
/** UI message to be rendered */
|
|
60
|
+
message: UIMessage;
|
|
61
|
+
/** Additional context to be passed to the child component */
|
|
62
|
+
meta?: unknown;
|
|
63
|
+
/** Fallback to be rendered when the component is loading */
|
|
64
|
+
fallback?: React.ReactNode | Record<string, React.ReactNode>;
|
|
65
|
+
/**
|
|
66
|
+
* Map of components that can be rendered directly without fetching the UI code
|
|
67
|
+
* from the server.
|
|
68
|
+
*/
|
|
69
|
+
components?: Record<string, React.FunctionComponent | React.ComponentClass>;
|
|
63
70
|
}
|
|
64
|
-
|
|
71
|
+
declare function LoadExternalComponent({
|
|
72
|
+
stream,
|
|
73
|
+
namespace,
|
|
74
|
+
message,
|
|
75
|
+
meta,
|
|
76
|
+
fallback,
|
|
77
|
+
components,
|
|
78
|
+
...props
|
|
79
|
+
}: LoadExternalComponentProps): JsxRuntime.JSX.Element;
|
|
65
80
|
declare global {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
81
|
+
interface Window {
|
|
82
|
+
[EXT_STORE_SYMBOL]: ComponentStore;
|
|
83
|
+
[REQUIRE_SYMBOL]: (name: string) => unknown;
|
|
84
|
+
[REQUIRE_EXTRA_SYMBOL]: Record<string, unknown>;
|
|
85
|
+
}
|
|
71
86
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
export {};
|
|
87
|
+
declare function experimental_loadShare(name: string, module: unknown): void;
|
|
88
|
+
//#endregion
|
|
89
|
+
export { LoadExternalComponent, experimental_loadShare, useStreamContext };
|
|
90
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","names":["React","JsxRuntime","UIMessage","useStream","UseStream","UseStreamContext","Record","Context","BagTemplate","GetMetaType","Bag","StateType","useStreamContext","ComponentTarget","FunctionComponent","ComponentClass","HTMLElement","ComponentStore","EXT_STORE_SYMBOL","REQUIRE_SYMBOL","REQUIRE_EXTRA_SYMBOL","LoadExternalComponentProps","HTMLDivElement","HTMLAttributes","ReturnType","ReactNode","Pick","LoadExternalComponent","stream","namespace","message","meta","fallback","components","JSX","Element","_0","sideEffect","experimental_loadShare","bootstrapUiContext"],"sources":["../../src/react-ui/client.d.ts"],"sourcesContent":["import * as React from \"react\";\nimport * as JsxRuntime from \"react/jsx-runtime\";\nimport type { UIMessage } from \"./types.js\";\nimport { useStream } from \"../react/index.js\";\nimport type { UseStream } from \"../react/types.js\";\ndeclare const UseStreamContext: React.Context<{\n stream: UseStream<Record<string, unknown>, {\n ConfigurableType?: Record<string, unknown> | undefined;\n InterruptType?: unknown;\n CustomEventType?: unknown;\n UpdateType?: unknown;\n }>;\n meta: unknown;\n}>;\ntype BagTemplate = {\n ConfigurableType?: Record<string, unknown>;\n InterruptType?: unknown;\n CustomEventType?: unknown;\n UpdateType?: unknown;\n MetaType?: unknown;\n};\ntype GetMetaType<Bag extends BagTemplate> = Bag extends {\n MetaType: unknown;\n} ? Bag[\"MetaType\"] : unknown;\ninterface UseStreamContext<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends BagTemplate = BagTemplate> extends UseStream<StateType, Bag> {\n meta?: GetMetaType<Bag>;\n}\nexport declare function useStreamContext<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends {\n ConfigurableType?: Record<string, unknown>;\n InterruptType?: unknown;\n CustomEventType?: unknown;\n UpdateType?: unknown;\n MetaType?: unknown;\n} = BagTemplate>(): UseStreamContext<StateType, Bag>;\ninterface ComponentTarget {\n comp: React.FunctionComponent | React.ComponentClass;\n target: HTMLElement;\n}\ndeclare class ComponentStore {\n private cache;\n private boundCache;\n private callbacks;\n respond(shadowRootId: string, comp: React.FunctionComponent | React.ComponentClass, targetElement: HTMLElement): void;\n getBoundStore(shadowRootId: string): {\n subscribe: (onStoreChange: () => void) => () => void;\n getSnapshot: () => ComponentTarget | undefined;\n };\n}\ndeclare const EXT_STORE_SYMBOL: unique symbol;\ndeclare const REQUIRE_SYMBOL: unique symbol;\ndeclare const REQUIRE_EXTRA_SYMBOL: unique symbol;\ninterface LoadExternalComponentProps extends Pick<React.HTMLAttributes<HTMLDivElement>, \"style\" | \"className\"> {\n /** Stream of the assistant */\n stream: ReturnType<typeof useStream>;\n /** Namespace of UI components. Defaults to assistant ID. */\n namespace?: string;\n /** UI message to be rendered */\n message: UIMessage;\n /** Additional context to be passed to the child component */\n meta?: unknown;\n /** Fallback to be rendered when the component is loading */\n fallback?: React.ReactNode | Record<string, React.ReactNode>;\n /**\n * Map of components that can be rendered directly without fetching the UI code\n * from the server.\n */\n components?: Record<string, React.FunctionComponent | React.ComponentClass>;\n}\nexport declare function LoadExternalComponent({ stream, namespace, message, meta, fallback, components, ...props }: LoadExternalComponentProps): JsxRuntime.JSX.Element;\ndeclare global {\n interface Window {\n [EXT_STORE_SYMBOL]: ComponentStore;\n [REQUIRE_SYMBOL]: (name: string) => unknown;\n [REQUIRE_EXTRA_SYMBOL]: Record<string, unknown>;\n }\n}\nexport declare function experimental_loadShare(name: string, module: unknown): void;\nexport declare function bootstrapUiContext(): void;\nexport {};\n"],"mappings":";;;;;;;cAKcK,kBAAkBL,KAAAA,CAAMO;UAC1BH,UAAUE;IADRD,gBAQZ,CAAA,EANyBC,MAMzB,CAAA,MAAA,EAAA,OAAA,CAAA,GAAA,SAAA;IAAA,aAAA,CAAA,EAAA,OAAA;IAPoBA,eAAAA,CAAAA,EAAAA,OAAAA;IACKA,UAAAA,CAAAA,EAAAA,OAAAA;;MAFKN,EAAAA,OAAMO;;AAAO,KASxCC,WAAAA,GAAW;EAOXC,gBAAW,CAAA,EANOH,MAMP,CAAA,MAAA,EAAA,OAAA,CAAA;EAAA,aAAA,CAAA,EAAA,OAAA;iBAAaE,CAAAA,EAAAA,OAAAA;YAAeE,CAAAA,EAAAA,OAAAA;UAExCA,CAAAA,EAAAA,OAAAA;;AAAG,KAFFD,WAGKJ,CAAAA,YAHmBG,WAGH,CAAA,GAHkBE,GAGlB,SAAA;EAAA,QAAA,EAAA,OAAA;IADtBA,GACyCJ,CAAAA,UAAAA,CAAAA,GAAAA,OAAAA;UAAnCD,gBAA6DC,CAAAA,kBAA1BA,MAA0BA,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA,GAAAA,MAAAA,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA,EAAAA,YAAqCE,WAAr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zEb,SAXyEa,CAAAA;;;EAMzFE;EACAC,OAAAA,EAQDjB,SAR8B;EAC7BkB;EACJC,IAAAA,CAAAA,EAAAA,OAAAA;EAA0B;UAAmCC,CAAAA,EAUxDtB,KAAAA,CAAMyB,SAVkDH,GAUtChB,MAVsCgB,CAAAA,MAAAA,EAUvBtB,KAAAA,CAAMyB,SAViBH,CAAAA;;;;;YAUlDG,CAAAA,EAKJnB,MALImB,CAAAA,MAAAA,EAKWzB,KAAAA,CAAMc,iBALjBW,GAKqCzB,KAAAA,CAAMe,cAL3CU,CAAAA;;AAAYnB,iBAOTqB,qBAAAA,CAPSrB;EAAAA,MAAAA;EAAAA,SAAAA;EAAAA,OAAAA;EAAAA,IAAAA;EAAAA,QAAAA;EAAAA,UAAAA;EAAAA,GAAAA;AAAAA,CAAAA,EAOmFe,0BAPnFf,CAAAA,EAOgHL,UAAAA,CAAWiC,GAAAA,CAAIC,OAP/H7B;QAKDN,MAAMc,CAAAA;YAA0BC,MAAAA,CAAAA;IAA/CT,CAKRY,gBAAAA,CALQZ,EAKWW,cALXX;IAf4BoB,CAqBpCP,cAAAA,CArBoCO,EAAAA,CAAAA,IAAAA,EAAAA,MAAAA,EAAAA,GAAAA,OAAAA;KAsBpCN,oBAAAA,GAAuBd;EALRqB;;AAAwBC,iBAQxBU,sBAAAA,CARwBV,IAAAA,EAAAA,MAAAA,EAAAA,MAAAA,EAAAA,OAAAA,CAAAA,EAAAA,IAAAA"}
|
package/dist/react-ui/client.js
CHANGED
|
@@ -1,159 +1,134 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import { useStream } from "../react/stream.js";
|
|
5
|
+
import "../react/index.js";
|
|
3
6
|
import * as React from "react";
|
|
4
7
|
import * as ReactDOM from "react-dom";
|
|
5
8
|
import * as JsxRuntime from "react/jsx-runtime";
|
|
6
|
-
import {
|
|
9
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
|
|
11
|
+
//#region src/react-ui/client.tsx
|
|
7
12
|
const UseStreamContext = React.createContext(null);
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (prop === "meta")
|
|
16
|
-
return target.meta;
|
|
17
|
-
return target.stream[prop];
|
|
18
|
-
},
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
class ComponentStore {
|
|
22
|
-
constructor() {
|
|
23
|
-
Object.defineProperty(this, "cache", {
|
|
24
|
-
enumerable: true,
|
|
25
|
-
configurable: true,
|
|
26
|
-
writable: true,
|
|
27
|
-
value: {}
|
|
28
|
-
});
|
|
29
|
-
Object.defineProperty(this, "boundCache", {
|
|
30
|
-
enumerable: true,
|
|
31
|
-
configurable: true,
|
|
32
|
-
writable: true,
|
|
33
|
-
value: {}
|
|
34
|
-
});
|
|
35
|
-
Object.defineProperty(this, "callbacks", {
|
|
36
|
-
enumerable: true,
|
|
37
|
-
configurable: true,
|
|
38
|
-
writable: true,
|
|
39
|
-
value: {}
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
respond(shadowRootId, comp, targetElement) {
|
|
43
|
-
this.cache[shadowRootId] = { comp, target: targetElement };
|
|
44
|
-
this.callbacks[shadowRootId]?.forEach((c) => c(comp, targetElement));
|
|
45
|
-
}
|
|
46
|
-
getBoundStore(shadowRootId) {
|
|
47
|
-
this.boundCache[shadowRootId] ??= {
|
|
48
|
-
subscribe: (onStoreChange) => {
|
|
49
|
-
this.callbacks[shadowRootId] ??= [];
|
|
50
|
-
this.callbacks[shadowRootId].push(onStoreChange);
|
|
51
|
-
return () => {
|
|
52
|
-
this.callbacks[shadowRootId] = this.callbacks[shadowRootId].filter((c) => c !== onStoreChange);
|
|
53
|
-
};
|
|
54
|
-
},
|
|
55
|
-
getSnapshot: () => this.cache[shadowRootId],
|
|
56
|
-
};
|
|
57
|
-
return this.boundCache[shadowRootId];
|
|
58
|
-
}
|
|
13
|
+
function useStreamContext() {
|
|
14
|
+
const ctx = React.useContext(UseStreamContext);
|
|
15
|
+
if (!ctx) throw new Error("useStreamContext must be used within a LoadExternalComponent");
|
|
16
|
+
return new Proxy(ctx, { get(target, prop) {
|
|
17
|
+
if (prop === "meta") return target.meta;
|
|
18
|
+
return target.stream[prop];
|
|
19
|
+
} });
|
|
59
20
|
}
|
|
21
|
+
var ComponentStore = class {
|
|
22
|
+
cache = {};
|
|
23
|
+
boundCache = {};
|
|
24
|
+
callbacks = {};
|
|
25
|
+
respond(shadowRootId, comp, targetElement) {
|
|
26
|
+
this.cache[shadowRootId] = {
|
|
27
|
+
comp,
|
|
28
|
+
target: targetElement
|
|
29
|
+
};
|
|
30
|
+
this.callbacks[shadowRootId]?.forEach((c) => c(comp, targetElement));
|
|
31
|
+
}
|
|
32
|
+
getBoundStore(shadowRootId) {
|
|
33
|
+
this.boundCache[shadowRootId] ??= {
|
|
34
|
+
subscribe: (onStoreChange) => {
|
|
35
|
+
this.callbacks[shadowRootId] ??= [];
|
|
36
|
+
this.callbacks[shadowRootId].push(onStoreChange);
|
|
37
|
+
return () => {
|
|
38
|
+
this.callbacks[shadowRootId] = this.callbacks[shadowRootId].filter((c) => c !== onStoreChange);
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
getSnapshot: () => this.cache[shadowRootId]
|
|
42
|
+
};
|
|
43
|
+
return this.boundCache[shadowRootId];
|
|
44
|
+
}
|
|
45
|
+
};
|
|
60
46
|
const COMPONENT_STORE = new ComponentStore();
|
|
61
47
|
const EXT_STORE_SYMBOL = Symbol.for("LGUI_EXT_STORE");
|
|
62
48
|
const REQUIRE_SYMBOL = Symbol.for("LGUI_REQUIRE");
|
|
63
49
|
const REQUIRE_EXTRA_SYMBOL = Symbol.for("LGUI_REQUIRE_EXTRA");
|
|
64
50
|
const isIterable = (value) => value != null && typeof value === "object" && Symbol.iterator in value;
|
|
65
|
-
const isPromise = (value) => value != null &&
|
|
66
|
-
typeof value === "object" &&
|
|
67
|
-
"then" in value &&
|
|
68
|
-
typeof value.then === "function";
|
|
51
|
+
const isPromise = (value) => value != null && typeof value === "object" && "then" in value && typeof value.then === "function";
|
|
69
52
|
const isReactNode = (value) => {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
typeof value === "bigint" ||
|
|
77
|
-
typeof value === "boolean") {
|
|
78
|
-
return true;
|
|
79
|
-
}
|
|
80
|
-
if (isIterable(value))
|
|
81
|
-
return true;
|
|
82
|
-
if (isPromise(value))
|
|
83
|
-
return true;
|
|
84
|
-
return false;
|
|
53
|
+
if (React.isValidElement(value)) return true;
|
|
54
|
+
if (value == null) return true;
|
|
55
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "bigint" || typeof value === "boolean") return true;
|
|
56
|
+
if (isIterable(value)) return true;
|
|
57
|
+
if (isPromise(value)) return true;
|
|
58
|
+
return false;
|
|
85
59
|
};
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
60
|
+
function LoadExternalComponent({ stream, namespace, message, meta, fallback, components,...props }) {
|
|
61
|
+
const ref = React.useRef(null);
|
|
62
|
+
const id = React.useId();
|
|
63
|
+
const shadowRootId = `child-shadow-${id}`;
|
|
64
|
+
const store = React.useMemo(() => COMPONENT_STORE.getBoundStore(shadowRootId), [shadowRootId]);
|
|
65
|
+
const state = React.useSyncExternalStore(store.subscribe, store.getSnapshot);
|
|
66
|
+
const clientComponent = components?.[message.name];
|
|
67
|
+
const hasClientComponent = clientComponent != null;
|
|
68
|
+
let fallbackComponent = null;
|
|
69
|
+
if (isReactNode(fallback)) fallbackComponent = fallback;
|
|
70
|
+
else if (typeof fallback === "object" && fallback != null) fallbackComponent = fallback?.[message.name];
|
|
71
|
+
const uiNamespace = namespace ?? stream.assistantId;
|
|
72
|
+
const uiClient = stream.client["~ui"];
|
|
73
|
+
React.useEffect(() => {
|
|
74
|
+
if (hasClientComponent) return;
|
|
75
|
+
uiClient.getComponent(uiNamespace, message.name).then((html) => {
|
|
76
|
+
const dom = ref.current;
|
|
77
|
+
if (!dom) return;
|
|
78
|
+
const root = dom.shadowRoot ?? dom.attachShadow({ mode: "open" });
|
|
79
|
+
const fragment = document.createRange().createContextualFragment(html.replace("{{shadowRootId}}", shadowRootId));
|
|
80
|
+
root.appendChild(fragment);
|
|
81
|
+
});
|
|
82
|
+
}, [
|
|
83
|
+
uiClient,
|
|
84
|
+
uiNamespace,
|
|
85
|
+
message.name,
|
|
86
|
+
shadowRootId,
|
|
87
|
+
hasClientComponent
|
|
88
|
+
]);
|
|
89
|
+
if (hasClientComponent) return /* @__PURE__ */ jsx(UseStreamContext.Provider, {
|
|
90
|
+
value: {
|
|
91
|
+
stream,
|
|
92
|
+
meta
|
|
93
|
+
},
|
|
94
|
+
children: React.createElement(clientComponent, message.props)
|
|
95
|
+
});
|
|
96
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
|
|
97
|
+
id: shadowRootId,
|
|
98
|
+
ref,
|
|
99
|
+
...props
|
|
100
|
+
}), /* @__PURE__ */ jsx(UseStreamContext.Provider, {
|
|
101
|
+
value: {
|
|
102
|
+
stream,
|
|
103
|
+
meta
|
|
104
|
+
},
|
|
105
|
+
children: state?.target != null ? ReactDOM.createPortal(React.createElement(state.comp, message.props), state.target) : fallbackComponent
|
|
106
|
+
})] });
|
|
123
107
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
window[REQUIRE_EXTRA_SYMBOL][name] = module;
|
|
108
|
+
function experimental_loadShare(name, module) {
|
|
109
|
+
if (typeof window === "undefined") return;
|
|
110
|
+
window[REQUIRE_EXTRA_SYMBOL] ??= {};
|
|
111
|
+
window[REQUIRE_EXTRA_SYMBOL][name] = module;
|
|
129
112
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
LoadExternalComponent: () => {
|
|
148
|
-
throw new Error("Nesting LoadExternalComponent is not supported");
|
|
149
|
-
},
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
if (window[REQUIRE_EXTRA_SYMBOL] != null &&
|
|
153
|
-
typeof window[REQUIRE_EXTRA_SYMBOL] === "object" &&
|
|
154
|
-
name in window[REQUIRE_EXTRA_SYMBOL]) {
|
|
155
|
-
return window[REQUIRE_EXTRA_SYMBOL][name];
|
|
156
|
-
}
|
|
157
|
-
throw new Error(`Unknown module...: ${name}`);
|
|
158
|
-
};
|
|
113
|
+
function bootstrapUiContext() {
|
|
114
|
+
if (typeof window === "undefined") return;
|
|
115
|
+
window[EXT_STORE_SYMBOL] = COMPONENT_STORE;
|
|
116
|
+
window[REQUIRE_SYMBOL] = (name) => {
|
|
117
|
+
if (name === "react") return React;
|
|
118
|
+
if (name === "react-dom") return ReactDOM;
|
|
119
|
+
if (name === "react/jsx-runtime") return JsxRuntime;
|
|
120
|
+
if (name === "@langchain/langgraph-sdk/react") return { useStream };
|
|
121
|
+
if (name === "@langchain/langgraph-sdk/react-ui") return {
|
|
122
|
+
useStreamContext,
|
|
123
|
+
LoadExternalComponent: () => {
|
|
124
|
+
throw new Error("Nesting LoadExternalComponent is not supported");
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
if (window[REQUIRE_EXTRA_SYMBOL] != null && typeof window[REQUIRE_EXTRA_SYMBOL] === "object" && name in window[REQUIRE_EXTRA_SYMBOL]) return window[REQUIRE_EXTRA_SYMBOL][name];
|
|
128
|
+
throw new Error(`Unknown module...: ${name}`);
|
|
129
|
+
};
|
|
159
130
|
}
|
|
131
|
+
|
|
132
|
+
//#endregion
|
|
133
|
+
export { LoadExternalComponent, bootstrapUiContext, experimental_loadShare, useStreamContext };
|
|
134
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","names":[],"sources":["../../src/react-ui/client.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport * as ReactDOM from \"react-dom\";\nimport * as JsxRuntime from \"react/jsx-runtime\";\nimport type { UIMessage } from \"./types.js\";\nimport { useStream } from \"../react/index.js\";\nimport type { UseStream } from \"../react/types.js\";\n\nconst UseStreamContext = React.createContext<{\n stream: ReturnType<typeof useStream>;\n meta: unknown;\n}>(null!);\n\ntype BagTemplate = {\n ConfigurableType?: Record<string, unknown>;\n InterruptType?: unknown;\n CustomEventType?: unknown;\n UpdateType?: unknown;\n MetaType?: unknown;\n};\n\ntype GetMetaType<Bag extends BagTemplate> = Bag extends { MetaType: unknown }\n ? Bag[\"MetaType\"]\n : unknown;\n\ninterface UseStreamContext<\n StateType extends Record<string, unknown> = Record<string, unknown>,\n Bag extends BagTemplate = BagTemplate\n> extends UseStream<StateType, Bag> {\n meta?: GetMetaType<Bag>;\n}\n\nexport function useStreamContext<\n StateType extends Record<string, unknown> = Record<string, unknown>,\n Bag extends {\n ConfigurableType?: Record<string, unknown>;\n InterruptType?: unknown;\n CustomEventType?: unknown;\n UpdateType?: unknown;\n MetaType?: unknown;\n } = BagTemplate\n>(): UseStreamContext<StateType, Bag> {\n const ctx = React.useContext(UseStreamContext);\n if (!ctx) {\n throw new Error(\n \"useStreamContext must be used within a LoadExternalComponent\"\n );\n }\n\n return new Proxy(ctx, {\n get(target, prop: keyof UseStreamContext<StateType, Bag>) {\n if (prop === \"meta\") return target.meta;\n return target.stream[prop];\n },\n }) as unknown as UseStreamContext<StateType, Bag>;\n}\n\ninterface ComponentTarget {\n comp: React.FunctionComponent | React.ComponentClass;\n target: HTMLElement;\n}\n\nclass ComponentStore {\n private cache: Record<string, ComponentTarget> = {};\n\n private boundCache: Record<\n string,\n {\n subscribe: (onStoreChange: () => void) => () => void;\n getSnapshot: () => ComponentTarget | undefined;\n }\n > = {};\n\n private callbacks: Record<\n string,\n ((\n comp: React.FunctionComponent | React.ComponentClass,\n el: HTMLElement\n ) => void)[]\n > = {};\n\n respond(\n shadowRootId: string,\n comp: React.FunctionComponent | React.ComponentClass,\n targetElement: HTMLElement\n ) {\n this.cache[shadowRootId] = { comp, target: targetElement };\n this.callbacks[shadowRootId]?.forEach((c) => c(comp, targetElement));\n }\n\n getBoundStore(shadowRootId: string) {\n this.boundCache[shadowRootId] ??= {\n subscribe: (onStoreChange: () => void) => {\n this.callbacks[shadowRootId] ??= [];\n this.callbacks[shadowRootId].push(onStoreChange);\n return () => {\n this.callbacks[shadowRootId] = this.callbacks[shadowRootId].filter(\n (c) => c !== onStoreChange\n );\n };\n },\n getSnapshot: () => this.cache[shadowRootId],\n };\n\n return this.boundCache[shadowRootId];\n }\n}\n\nconst COMPONENT_STORE = new ComponentStore();\nconst EXT_STORE_SYMBOL = Symbol.for(\"LGUI_EXT_STORE\");\nconst REQUIRE_SYMBOL = Symbol.for(\"LGUI_REQUIRE\");\nconst REQUIRE_EXTRA_SYMBOL = Symbol.for(\"LGUI_REQUIRE_EXTRA\");\n\ninterface LoadExternalComponentProps\n extends Pick<React.HTMLAttributes<HTMLDivElement>, \"style\" | \"className\"> {\n /** Stream of the assistant */\n stream: ReturnType<typeof useStream>;\n\n /** Namespace of UI components. Defaults to assistant ID. */\n namespace?: string;\n\n /** UI message to be rendered */\n message: UIMessage;\n\n /** Additional context to be passed to the child component */\n meta?: unknown;\n\n /** Fallback to be rendered when the component is loading */\n fallback?: React.ReactNode | Record<string, React.ReactNode>;\n\n /**\n * Map of components that can be rendered directly without fetching the UI code\n * from the server.\n */\n components?: Record<string, React.FunctionComponent | React.ComponentClass>;\n}\n\nconst isIterable = (value: unknown): value is Iterable<unknown> =>\n value != null && typeof value === \"object\" && Symbol.iterator in value;\n\nconst isPromise = (value: unknown): value is Promise<unknown> =>\n value != null &&\n typeof value === \"object\" &&\n \"then\" in value &&\n typeof value.then === \"function\";\n\nconst isReactNode = (value: unknown): value is React.ReactNode => {\n if (React.isValidElement(value)) return true;\n if (value == null) return true;\n if (\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"bigint\" ||\n typeof value === \"boolean\"\n ) {\n return true;\n }\n\n if (isIterable(value)) return true;\n if (isPromise(value)) return true;\n\n return false;\n};\n\nexport function LoadExternalComponent({\n stream,\n namespace,\n message,\n meta,\n fallback,\n components,\n ...props\n}: LoadExternalComponentProps) {\n const ref = React.useRef<HTMLDivElement>(null);\n const id = React.useId();\n const shadowRootId = `child-shadow-${id}`;\n\n const store = React.useMemo(\n () => COMPONENT_STORE.getBoundStore(shadowRootId),\n [shadowRootId]\n );\n const state = React.useSyncExternalStore(store.subscribe, store.getSnapshot);\n\n const clientComponent = components?.[message.name];\n const hasClientComponent = clientComponent != null;\n\n let fallbackComponent = null;\n if (isReactNode(fallback)) {\n fallbackComponent = fallback;\n } else if (typeof fallback === \"object\" && fallback != null) {\n fallbackComponent = fallback?.[message.name];\n }\n\n const uiNamespace = namespace ?? stream.assistantId;\n const uiClient = stream.client[\"~ui\"];\n React.useEffect(() => {\n if (hasClientComponent) return;\n void uiClient.getComponent(uiNamespace, message.name).then((html) => {\n const dom = ref.current;\n if (!dom) return;\n const root = dom.shadowRoot ?? dom.attachShadow({ mode: \"open\" });\n const fragment = document\n .createRange()\n .createContextualFragment(\n html.replace(\"{{shadowRootId}}\", shadowRootId)\n );\n root.appendChild(fragment);\n });\n }, [uiClient, uiNamespace, message.name, shadowRootId, hasClientComponent]);\n\n if (hasClientComponent) {\n return (\n <UseStreamContext.Provider value={{ stream, meta }}>\n {React.createElement(clientComponent, message.props)}\n </UseStreamContext.Provider>\n );\n }\n\n return (\n <>\n <div id={shadowRootId} ref={ref} {...props} />\n\n <UseStreamContext.Provider value={{ stream, meta }}>\n {state?.target != null\n ? ReactDOM.createPortal(\n React.createElement(state.comp, message.props),\n state.target\n )\n : fallbackComponent}\n </UseStreamContext.Provider>\n </>\n );\n}\n\ndeclare global {\n interface Window {\n [EXT_STORE_SYMBOL]: ComponentStore;\n [REQUIRE_SYMBOL]: (name: string) => unknown;\n [REQUIRE_EXTRA_SYMBOL]: Record<string, unknown>;\n }\n}\n\nexport function experimental_loadShare(name: string, module: unknown) {\n if (typeof window === \"undefined\") return;\n\n window[REQUIRE_EXTRA_SYMBOL] ??= {};\n window[REQUIRE_EXTRA_SYMBOL][name] = module;\n}\n\nexport function bootstrapUiContext() {\n if (typeof window === \"undefined\") {\n return;\n }\n\n window[EXT_STORE_SYMBOL] = COMPONENT_STORE;\n window[REQUIRE_SYMBOL] = (name: string) => {\n if (name === \"react\") return React;\n if (name === \"react-dom\") return ReactDOM;\n if (name === \"react/jsx-runtime\") return JsxRuntime;\n if (name === \"@langchain/langgraph-sdk/react\") return { useStream };\n if (name === \"@langchain/langgraph-sdk/react-ui\") {\n return {\n useStreamContext,\n LoadExternalComponent: () => {\n throw new Error(\"Nesting LoadExternalComponent is not supported\");\n },\n };\n }\n\n if (\n window[REQUIRE_EXTRA_SYMBOL] != null &&\n typeof window[REQUIRE_EXTRA_SYMBOL] === \"object\" &&\n name in window[REQUIRE_EXTRA_SYMBOL]\n ) {\n return window[REQUIRE_EXTRA_SYMBOL][name];\n }\n\n throw new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AAO,WAAW,YAAa;AAEnC,QAAO,0BAA0B;AACjC,QAAO,sBAAsB,QAAQ;;AAGvC,SAAgB,qBAAqB;AACnC,KAAI,OAAO,WAAW,YACpB;AAGF,QAAO,oBAAoB;AAC3B,QAAO,mBAAmB,SAAiB;AACzC,MAAI,SAAS,QAAS,QAAO;AAC7B,MAAI,SAAS,YAAa,QAAO;AACjC,MAAI,SAAS,oBAAqB,QAAO;AACzC,MAAI,SAAS,iCAAkC,QAAO,EAAE;AACxD,MAAI,SAAS,oCACX,QAAO;GACL;GACA,6BAA6B;AAC3B,UAAM,IAAI,MAAM;;;AAKtB,MACE,OAAO,yBAAyB,QAChC,OAAO,OAAO,0BAA0B,YACxC,QAAQ,OAAO,sBAEf,QAAO,OAAO,sBAAsB;AAGtC,QAAM,IAAI,MAAM,sBAAsB"}
|
package/dist/react-ui/index.cjs
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
const require_client = require('./client.cjs');
|
|
2
|
+
const require_types = require('./types.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/react-ui/index.ts
|
|
5
|
+
require_client.bootstrapUiContext();
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
exports.LoadExternalComponent = require_client.LoadExternalComponent;
|
|
9
|
+
exports.experimental_loadShare = require_client.experimental_loadShare;
|
|
10
|
+
exports.isRemoveUIMessage = require_types.isRemoveUIMessage;
|
|
11
|
+
exports.isUIMessage = require_types.isUIMessage;
|
|
12
|
+
exports.uiMessageReducer = require_types.uiMessageReducer;
|
|
13
|
+
exports.useStreamContext = require_client.useStreamContext;
|
|
14
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["bootstrapUiContext"],"sources":["../../src/react-ui/index.ts"],"sourcesContent":["import { bootstrapUiContext } from \"./client.js\";\n\nbootstrapUiContext();\n\nexport {\n useStreamContext,\n LoadExternalComponent,\n experimental_loadShare,\n} from \"./client.js\";\nexport {\n uiMessageReducer,\n isUIMessage,\n isRemoveUIMessage,\n type UIMessage,\n type RemoveUIMessage,\n} from \"./types.js\";\n"],"mappings":";;;;AAEAA"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { RemoveUIMessage, UIMessage, isRemoveUIMessage, isUIMessage, uiMessageReducer } from "./types.cjs";
|
|
2
|
+
import { LoadExternalComponent, experimental_loadShare, useStreamContext } from "./client.cjs";
|
|
3
|
+
export { LoadExternalComponent, type RemoveUIMessage, type UIMessage, experimental_loadShare, isRemoveUIMessage, isUIMessage, uiMessageReducer, useStreamContext };
|
package/dist/react-ui/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { RemoveUIMessage, UIMessage, isRemoveUIMessage, isUIMessage, uiMessageReducer } from "./types.js";
|
|
2
|
+
import { LoadExternalComponent, experimental_loadShare, useStreamContext } from "./client.js";
|
|
3
|
+
export { LoadExternalComponent, type RemoveUIMessage, type UIMessage, experimental_loadShare, isRemoveUIMessage, isUIMessage, uiMessageReducer, useStreamContext };
|
package/dist/react-ui/index.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import { bootstrapUiContext } from "./client.js";
|
|
1
|
+
import { LoadExternalComponent, bootstrapUiContext, experimental_loadShare, useStreamContext } from "./client.js";
|
|
2
|
+
import { isRemoveUIMessage, isUIMessage, uiMessageReducer } from "./types.js";
|
|
3
|
+
|
|
4
|
+
//#region src/react-ui/index.ts
|
|
2
5
|
bootstrapUiContext();
|
|
3
|
-
|
|
4
|
-
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
export { LoadExternalComponent, experimental_loadShare, isRemoveUIMessage, isUIMessage, uiMessageReducer, useStreamContext };
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/react-ui/index.ts"],"sourcesContent":["import { bootstrapUiContext } from \"./client.js\";\n\nbootstrapUiContext();\n\nexport {\n useStreamContext,\n LoadExternalComponent,\n experimental_loadShare,\n} from \"./client.js\";\nexport {\n uiMessageReducer,\n isUIMessage,\n isRemoveUIMessage,\n type UIMessage,\n type RemoveUIMessage,\n} from \"./types.js\";\n"],"mappings":";;;;AAEA"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var types_js_1 = require("../types.cjs");
|
|
7
|
-
Object.defineProperty(exports, "uiMessageReducer", { enumerable: true, get: function () { return types_js_1.uiMessageReducer; } });
|
|
1
|
+
const require_types = require('../types.cjs');
|
|
2
|
+
const require_server = require('./server.cjs');
|
|
3
|
+
|
|
4
|
+
exports.typedUi = require_server.typedUi;
|
|
5
|
+
exports.uiMessageReducer = require_types.uiMessageReducer;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { RemoveUIMessage, UIMessage, uiMessageReducer } from "../types.js";
|
|
2
|
+
import { typedUi } from "./server.js";
|
|
3
|
+
export { type RemoveUIMessage, type UIMessage, typedUi, uiMessageReducer };
|