@assistant-ui/react 0.1.4 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,92 @@
1
+ import { ReactNode, ComponentType } from 'react';
2
+ import { z } from 'zod';
3
+
4
+ type TextContentPart = {
5
+ type: "text";
6
+ text: string;
7
+ };
8
+ type ImageContentPart = {
9
+ type: "image";
10
+ image: string;
11
+ };
12
+ type UIContentPart = {
13
+ type: "ui";
14
+ display: ReactNode;
15
+ };
16
+ type ToolCallContentPart<TArgs = unknown, TResult = unknown> = {
17
+ type: "tool-call";
18
+ toolCallId: string;
19
+ toolName: string;
20
+ args: TArgs;
21
+ result?: TResult;
22
+ };
23
+ type UserContentPart = TextContentPart | ImageContentPart | UIContentPart;
24
+ type AssistantContentPart = TextContentPart | ToolCallContentPart | UIContentPart;
25
+ type AppendContentPart = TextContentPart | ImageContentPart;
26
+ type BaseMessage = {
27
+ id: string;
28
+ createdAt: Date;
29
+ };
30
+ type UserMessage = BaseMessage & {
31
+ role: "user";
32
+ content: UserContentPart[];
33
+ };
34
+ type AssistantMessage = BaseMessage & {
35
+ role: "assistant";
36
+ content: AssistantContentPart[];
37
+ status: "in_progress" | "done" | "error";
38
+ };
39
+ type AppendMessage = {
40
+ parentId: string | null;
41
+ content: AppendContentPart[];
42
+ };
43
+ type ThreadMessage = UserMessage | AssistantMessage;
44
+
45
+ type ContentPartStatus = "done" | "in_progress" | "error";
46
+ type TextContentPartProps = {
47
+ part: TextContentPart;
48
+ status: ContentPartStatus;
49
+ };
50
+ type TextContentPartComponent = ComponentType<TextContentPartProps>;
51
+ type ImageContentPartProps = {
52
+ part: ImageContentPart;
53
+ status: ContentPartStatus;
54
+ };
55
+ type ImageContentPartComponent = ComponentType<ImageContentPartProps>;
56
+ type UIContentPartProps = {
57
+ part: UIContentPart;
58
+ status: ContentPartStatus;
59
+ };
60
+ type UIContentPartComponent = ComponentType<UIContentPartProps>;
61
+ type ToolCallContentPartProps<TArgs = any, TResult = any> = {
62
+ part: ToolCallContentPart<TArgs, TResult>;
63
+ status: ContentPartStatus;
64
+ };
65
+ type ToolCallContentPartComponent<TArgs = any, TResult = any> = ComponentType<ToolCallContentPartProps<TArgs, TResult>>;
66
+
67
+ type ToolExecuteFunction<TArgs, TResult> = (args: TArgs) => TResult | Promise<TResult>;
68
+ type Tool<TArgs = unknown, TResult = unknown> = {
69
+ description?: string;
70
+ parameters: z.ZodSchema<TArgs>;
71
+ execute: ToolExecuteFunction<TArgs, TResult>;
72
+ };
73
+ type ModelConfig = {
74
+ priority?: number;
75
+ system?: string;
76
+ tools?: Record<string, Tool<any, any>>;
77
+ };
78
+ type ModelConfigProvider = () => ModelConfig;
79
+
80
+ type Unsubscribe = () => void;
81
+
82
+ type ThreadState = {
83
+ messages: readonly ThreadMessage[];
84
+ isRunning: boolean;
85
+ getBranches: (messageId: string) => readonly string[];
86
+ switchToBranch: (branchId: string) => void;
87
+ append: (message: AppendMessage) => void;
88
+ startRun: (parentId: string | null) => void;
89
+ cancelRun: () => void;
90
+ };
91
+
92
+ export type { AssistantContentPart as A, ImageContentPartComponent as I, ModelConfigProvider as M, TextContentPartComponent as T, UIContentPartComponent as U, ToolCallContentPartComponent as a, ToolCallContentPartProps as b, ThreadState as c, Unsubscribe as d, ThreadMessage as e, ModelConfig as f, AppendMessage as g, AssistantMessage as h, UserMessage as i, UserContentPart as j, AppendContentPart as k, TextContentPart as l, Tool as m, ImageContentPart as n, ToolCallContentPart as o, UIContentPart as p, TextContentPartProps as q, ImageContentPartProps as r, UIContentPartProps as s };
@@ -0,0 +1,92 @@
1
+ import { ReactNode, ComponentType } from 'react';
2
+ import { z } from 'zod';
3
+
4
+ type TextContentPart = {
5
+ type: "text";
6
+ text: string;
7
+ };
8
+ type ImageContentPart = {
9
+ type: "image";
10
+ image: string;
11
+ };
12
+ type UIContentPart = {
13
+ type: "ui";
14
+ display: ReactNode;
15
+ };
16
+ type ToolCallContentPart<TArgs = unknown, TResult = unknown> = {
17
+ type: "tool-call";
18
+ toolCallId: string;
19
+ toolName: string;
20
+ args: TArgs;
21
+ result?: TResult;
22
+ };
23
+ type UserContentPart = TextContentPart | ImageContentPart | UIContentPart;
24
+ type AssistantContentPart = TextContentPart | ToolCallContentPart | UIContentPart;
25
+ type AppendContentPart = TextContentPart | ImageContentPart;
26
+ type BaseMessage = {
27
+ id: string;
28
+ createdAt: Date;
29
+ };
30
+ type UserMessage = BaseMessage & {
31
+ role: "user";
32
+ content: UserContentPart[];
33
+ };
34
+ type AssistantMessage = BaseMessage & {
35
+ role: "assistant";
36
+ content: AssistantContentPart[];
37
+ status: "in_progress" | "done" | "error";
38
+ };
39
+ type AppendMessage = {
40
+ parentId: string | null;
41
+ content: AppendContentPart[];
42
+ };
43
+ type ThreadMessage = UserMessage | AssistantMessage;
44
+
45
+ type ContentPartStatus = "done" | "in_progress" | "error";
46
+ type TextContentPartProps = {
47
+ part: TextContentPart;
48
+ status: ContentPartStatus;
49
+ };
50
+ type TextContentPartComponent = ComponentType<TextContentPartProps>;
51
+ type ImageContentPartProps = {
52
+ part: ImageContentPart;
53
+ status: ContentPartStatus;
54
+ };
55
+ type ImageContentPartComponent = ComponentType<ImageContentPartProps>;
56
+ type UIContentPartProps = {
57
+ part: UIContentPart;
58
+ status: ContentPartStatus;
59
+ };
60
+ type UIContentPartComponent = ComponentType<UIContentPartProps>;
61
+ type ToolCallContentPartProps<TArgs = any, TResult = any> = {
62
+ part: ToolCallContentPart<TArgs, TResult>;
63
+ status: ContentPartStatus;
64
+ };
65
+ type ToolCallContentPartComponent<TArgs = any, TResult = any> = ComponentType<ToolCallContentPartProps<TArgs, TResult>>;
66
+
67
+ type ToolExecuteFunction<TArgs, TResult> = (args: TArgs) => TResult | Promise<TResult>;
68
+ type Tool<TArgs = unknown, TResult = unknown> = {
69
+ description?: string;
70
+ parameters: z.ZodSchema<TArgs>;
71
+ execute: ToolExecuteFunction<TArgs, TResult>;
72
+ };
73
+ type ModelConfig = {
74
+ priority?: number;
75
+ system?: string;
76
+ tools?: Record<string, Tool<any, any>>;
77
+ };
78
+ type ModelConfigProvider = () => ModelConfig;
79
+
80
+ type Unsubscribe = () => void;
81
+
82
+ type ThreadState = {
83
+ messages: readonly ThreadMessage[];
84
+ isRunning: boolean;
85
+ getBranches: (messageId: string) => readonly string[];
86
+ switchToBranch: (branchId: string) => void;
87
+ append: (message: AppendMessage) => void;
88
+ startRun: (parentId: string | null) => void;
89
+ cancelRun: () => void;
90
+ };
91
+
92
+ export type { AssistantContentPart as A, ImageContentPartComponent as I, ModelConfigProvider as M, TextContentPartComponent as T, UIContentPartComponent as U, ToolCallContentPartComponent as a, ToolCallContentPartProps as b, ThreadState as c, Unsubscribe as d, ThreadMessage as e, ModelConfig as f, AppendMessage as g, AssistantMessage as h, UserMessage as i, UserContentPart as j, AppendContentPart as k, TextContentPart as l, Tool as m, ImageContentPart as n, ToolCallContentPart as o, UIContentPart as p, TextContentPartProps as q, ImageContentPartProps as r, UIContentPartProps as s };
@@ -0,0 +1,83 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/context/MessageContext.ts
8
+ import { createContext, useContext } from "react";
9
+ var MessageContext = createContext(null);
10
+ var useMessageContext = () => {
11
+ const context = useContext(MessageContext);
12
+ if (!context)
13
+ throw new Error(
14
+ "This component can only be used inside a component passed to <ThreadPrimitive.Messages components={...} />."
15
+ );
16
+ return context;
17
+ };
18
+
19
+ // src/context/ThreadContext.ts
20
+ import { createContext as createContext2, useContext as useContext2 } from "react";
21
+ var ThreadContext = createContext2(null);
22
+ var useThreadContext = () => {
23
+ const context = useContext2(ThreadContext);
24
+ if (!context)
25
+ throw new Error("This component must be used within an AssistantRuntimeProvider.");
26
+ return context;
27
+ };
28
+
29
+ // src/context/ComposerContext.ts
30
+ import { useContext as useContext3, useMemo } from "react";
31
+ var useComposerContext = () => {
32
+ const { useComposer } = useThreadContext();
33
+ const { useComposer: useEditComposer } = useContext3(MessageContext) ?? {};
34
+ return useMemo(
35
+ () => ({
36
+ useComposer: useEditComposer ?? useComposer,
37
+ type: useEditComposer ? "edit" : "new"
38
+ }),
39
+ [useEditComposer, useComposer]
40
+ );
41
+ };
42
+
43
+ // src/context/AssistantContext.ts
44
+ import { createContext as createContext3, useContext as useContext4 } from "react";
45
+ var AssistantContext = createContext3(
46
+ null
47
+ );
48
+ var useAssistantContext = () => {
49
+ const context = useContext4(AssistantContext);
50
+ if (!context)
51
+ throw new Error(
52
+ "This component must be used within an AssistantRuntimeProvider."
53
+ );
54
+ return context;
55
+ };
56
+
57
+ // src/context/ContentPartContext.ts
58
+ import { createContext as createContext4, useContext as useContext5 } from "react";
59
+ var ContentPartContext = createContext4(
60
+ null
61
+ );
62
+ var useContentPartContext = () => {
63
+ const context = useContext5(ContentPartContext);
64
+ if (!context)
65
+ throw new Error(
66
+ "This component can only be used inside a component passed to <MessagePrimitive.Content components={...} >."
67
+ );
68
+ return context;
69
+ };
70
+
71
+ export {
72
+ __export,
73
+ MessageContext,
74
+ useMessageContext,
75
+ ThreadContext,
76
+ useThreadContext,
77
+ useComposerContext,
78
+ AssistantContext,
79
+ useAssistantContext,
80
+ ContentPartContext,
81
+ useContentPartContext
82
+ };
83
+ //# sourceMappingURL=chunk-KIP3YFVM.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/context/MessageContext.ts","../src/context/ThreadContext.ts","../src/context/ComposerContext.ts","../src/context/AssistantContext.ts","../src/context/ContentPartContext.ts"],"sourcesContent":["import { createContext, useContext } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport type { MessageState } from \"./stores/Message\";\nimport type { EditComposerState } from \"./stores/MessageComposer\";\n\nexport type MessageContextValue = {\n useMessage: UseBoundStore<StoreApi<MessageState>>;\n useComposer: UseBoundStore<StoreApi<EditComposerState>>;\n};\n\nexport const MessageContext = createContext<MessageContextValue | null>(null);\n\nexport const useMessageContext = () => {\n const context = useContext(MessageContext);\n if (!context)\n throw new Error(\n \"This component can only be used inside a component passed to <ThreadPrimitive.Messages components={...} />.\",\n );\n return context;\n};\n","import { createContext, useContext } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport type { ComposerState } from \"./stores/Composer\";\nimport type { ThreadState } from \"./stores/Thread\";\nimport type { ThreadViewportState } from \"./stores/ThreadViewport\";\n\nexport type ThreadContextValue = {\n useThread: UseBoundStore<StoreApi<ThreadState>>;\n useComposer: UseBoundStore<StoreApi<ComposerState>>;\n useViewport: UseBoundStore<StoreApi<ThreadViewportState>>;\n};\n\nexport const ThreadContext = createContext<ThreadContextValue | null>(null);\n\nexport const useThreadContext = (): ThreadContextValue => {\n const context = useContext(ThreadContext);\n if (!context)\n throw new Error(\"This component must be used within an AssistantRuntimeProvider.\");\n return context;\n};\n","import { useContext, useMemo } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport { MessageContext } from \"./MessageContext\";\nimport { useThreadContext } from \"./ThreadContext\";\nimport type { ComposerState } from \"./stores/Composer\";\nimport type { EditComposerState } from \"./stores/MessageComposer\";\n\nexport type ComposerContextValue = {\n useComposer: UseBoundStore<StoreApi<EditComposerState | ComposerState>>;\n type: \"edit\" | \"new\";\n};\n\nexport const useComposerContext = (): ComposerContextValue => {\n const { useComposer } = useThreadContext();\n const { useComposer: useEditComposer } = useContext(MessageContext) ?? {};\n return useMemo(\n () => ({\n useComposer: (useEditComposer ?? useComposer) as UseBoundStore<\n StoreApi<EditComposerState | ComposerState>\n >,\n type: useEditComposer ? (\"edit\" as const) : (\"new\" as const),\n }),\n [useEditComposer, useComposer],\n );\n};\n","import { createContext, useContext } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport type { AssistantModelConfigState } from \"./stores/AssistantModelConfig\";\nimport type { AssistantToolRenderersState } from \"./stores/AssistantToolRenderers\";\n\nexport type AssistantContextValue = {\n useModelConfig: UseBoundStore<StoreApi<AssistantModelConfigState>>;\n useToolRenderers: UseBoundStore<StoreApi<AssistantToolRenderersState>>;\n};\n\nexport const AssistantContext = createContext<AssistantContextValue | null>(\n null,\n);\n\nexport const useAssistantContext = (): AssistantContextValue => {\n const context = useContext(AssistantContext);\n if (!context)\n throw new Error(\n \"This component must be used within an AssistantRuntimeProvider.\",\n );\n return context;\n};\n","import { createContext, useContext } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport type { ContentPartState } from \"./stores/ContentPart\";\n\nexport type ContentPartContextValue = {\n useContentPart: UseBoundStore<StoreApi<ContentPartState>>;\n};\n\nexport const ContentPartContext = createContext<ContentPartContextValue | null>(\n null,\n);\n\nexport const useContentPartContext = (): ContentPartContextValue => {\n const context = useContext(ContentPartContext);\n if (!context)\n throw new Error(\n \"This component can only be used inside a component passed to <MessagePrimitive.Content components={...} >.\",\n );\n return context;\n};\n"],"mappings":";;;;;;;AAAA,SAAS,eAAe,kBAAkB;AAUnC,IAAM,iBAAiB,cAA0C,IAAI;AAErE,IAAM,oBAAoB,MAAM;AACrC,QAAM,UAAU,WAAW,cAAc;AACzC,MAAI,CAAC;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;;;ACnBA,SAAS,iBAAAA,gBAAe,cAAAC,mBAAkB;AAYnC,IAAM,gBAAgBD,eAAyC,IAAI;AAEnE,IAAM,mBAAmB,MAA0B;AACxD,QAAM,UAAUC,YAAW,aAAa;AACxC,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,iEAAiE;AACnF,SAAO;AACT;;;ACnBA,SAAS,cAAAC,aAAY,eAAe;AAY7B,IAAM,qBAAqB,MAA4B;AAC5D,QAAM,EAAE,YAAY,IAAI,iBAAiB;AACzC,QAAM,EAAE,aAAa,gBAAgB,IAAIC,YAAW,cAAc,KAAK,CAAC;AACxE,SAAO;AAAA,IACL,OAAO;AAAA,MACL,aAAc,mBAAmB;AAAA,MAGjC,MAAM,kBAAmB,SAAoB;AAAA,IAC/C;AAAA,IACA,CAAC,iBAAiB,WAAW;AAAA,EAC/B;AACF;;;ACxBA,SAAS,iBAAAC,gBAAe,cAAAC,mBAAkB;AAUnC,IAAM,mBAAmBD;AAAA,EAC9B;AACF;AAEO,IAAM,sBAAsB,MAA6B;AAC9D,QAAM,UAAUC,YAAW,gBAAgB;AAC3C,MAAI,CAAC;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;;;ACrBA,SAAS,iBAAAC,gBAAe,cAAAC,mBAAkB;AAQnC,IAAM,qBAAqBD;AAAA,EAChC;AACF;AAEO,IAAM,wBAAwB,MAA+B;AAClE,QAAM,UAAUC,YAAW,kBAAkB;AAC7C,MAAI,CAAC;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;","names":["createContext","useContext","useContext","useContext","createContext","useContext","createContext","useContext"]}
@@ -0,0 +1,107 @@
1
+ import { M as ModelConfigProvider, e as ThreadMessage, d as Unsubscribe, a as ToolCallContentPartComponent, c as ThreadState, m as Tool } from './Thread-ZUDFhMtm.mjs';
2
+ export { n as ImageContentPart, I as ImageContentPartComponent, r as ImageContentPartProps, f as ModelConfig, T as TextContentPartComponent, q as TextContentPartProps, o as ToolCallContentPart, b as ToolCallContentPartProps, p as UIContentPart, U as UIContentPartComponent, s as UIContentPartProps } from './Thread-ZUDFhMtm.mjs';
3
+ import { ReactNode } from 'react';
4
+ import { UseBoundStore, StoreApi } from 'zustand';
5
+ import 'zod';
6
+
7
+ type AssistantModelConfigState = {
8
+ getModelConfig: ModelConfigProvider;
9
+ registerModelConfigProvider: (provider: ModelConfigProvider) => () => void;
10
+ };
11
+
12
+ type ContentPartState = Readonly<{
13
+ status: "in_progress" | "done" | "error";
14
+ part: ThreadMessage["content"][number];
15
+ }>;
16
+
17
+ type MessageState = Readonly<{
18
+ message: Readonly<ThreadMessage>;
19
+ parentId: string | null;
20
+ branches: readonly string[];
21
+ isLast: boolean;
22
+ inProgressIndicator: ReactNode | null;
23
+ setInProgressIndicator: (value: ReactNode | null) => void;
24
+ isCopied: boolean;
25
+ setIsCopied: (value: boolean) => void;
26
+ isHovering: boolean;
27
+ setIsHovering: (value: boolean) => void;
28
+ }>;
29
+
30
+ type BaseComposerState = Readonly<{
31
+ value: string;
32
+ setValue: (value: string) => void;
33
+ }>;
34
+
35
+ type EditComposerState = BaseComposerState & Readonly<{
36
+ isEditing: boolean;
37
+ edit: () => void;
38
+ send: () => void;
39
+ cancel: () => boolean;
40
+ }>;
41
+
42
+ type ComposerState = BaseComposerState & Readonly<{
43
+ isEditing: true;
44
+ send: () => void;
45
+ cancel: () => boolean;
46
+ }>;
47
+
48
+ type ThreadViewportState = {
49
+ isAtBottom: boolean;
50
+ scrollToBottom: () => void;
51
+ onScrollToBottom: (callback: () => void) => Unsubscribe;
52
+ };
53
+
54
+ type AssistantToolRenderersState = {
55
+ getToolRenderer: (name: string) => ToolCallContentPartComponent | null;
56
+ setToolRenderer: (name: string, render: ToolCallContentPartComponent) => () => void;
57
+ };
58
+
59
+ type AssistantContextValue = {
60
+ useModelConfig: UseBoundStore<StoreApi<AssistantModelConfigState>>;
61
+ useToolRenderers: UseBoundStore<StoreApi<AssistantToolRenderersState>>;
62
+ };
63
+ declare const useAssistantContext: () => AssistantContextValue;
64
+
65
+ type ThreadContextValue = {
66
+ useThread: UseBoundStore<StoreApi<ThreadState>>;
67
+ useComposer: UseBoundStore<StoreApi<ComposerState>>;
68
+ useViewport: UseBoundStore<StoreApi<ThreadViewportState>>;
69
+ };
70
+ declare const useThreadContext: () => ThreadContextValue;
71
+
72
+ type ComposerContextValue = {
73
+ useComposer: UseBoundStore<StoreApi<EditComposerState | ComposerState>>;
74
+ type: "edit" | "new";
75
+ };
76
+ declare const useComposerContext: () => ComposerContextValue;
77
+
78
+ type MessageContextValue = {
79
+ useMessage: UseBoundStore<StoreApi<MessageState>>;
80
+ useComposer: UseBoundStore<StoreApi<EditComposerState>>;
81
+ };
82
+ declare const useMessageContext: () => MessageContextValue;
83
+
84
+ type ContentPartContextValue = {
85
+ useContentPart: UseBoundStore<StoreApi<ContentPartState>>;
86
+ };
87
+ declare const useContentPartContext: () => ContentPartContextValue;
88
+
89
+ declare const useAssistantInstructions: (instruction: string) => void;
90
+
91
+ type AssistantToolProps<TArgs, TResult> = Tool<TArgs, TResult> & {
92
+ name: string;
93
+ render?: ToolCallContentPartComponent<TArgs, TResult>;
94
+ };
95
+ declare const useAssistantTool: <TArgs, TResult>(tool: AssistantToolProps<TArgs, TResult>) => void;
96
+
97
+ type AssistantToolRendererProps<TArgs, TResult> = {
98
+ name: string;
99
+ render: ToolCallContentPartComponent<TArgs, TResult>;
100
+ };
101
+ declare const useAssistantToolRenderer: (tool: AssistantToolRendererProps<any, any> | null) => void;
102
+
103
+ declare const makeTool: <TArgs, TResult>(tool: AssistantToolProps<TArgs, TResult>) => () => null;
104
+
105
+ declare const makeToolRenderer: <TArgs, TResult>(tool: AssistantToolRendererProps<TArgs, TResult>) => () => null;
106
+
107
+ export { type AssistantContextValue, type AssistantModelConfigState, type AssistantToolProps, type AssistantToolRendererProps, type ComposerContextValue, type ComposerState, type ContentPartContextValue, type ContentPartState, type EditComposerState, type MessageContextValue, type MessageState, ModelConfigProvider, type ThreadContextValue, ThreadState, type ThreadViewportState, ToolCallContentPartComponent, makeTool, makeToolRenderer, useAssistantContext, useAssistantInstructions, useAssistantTool, useAssistantToolRenderer, useComposerContext, useContentPartContext, useMessageContext, useThreadContext };
@@ -0,0 +1,107 @@
1
+ import { M as ModelConfigProvider, e as ThreadMessage, d as Unsubscribe, a as ToolCallContentPartComponent, c as ThreadState, m as Tool } from './Thread-ZUDFhMtm.js';
2
+ export { n as ImageContentPart, I as ImageContentPartComponent, r as ImageContentPartProps, f as ModelConfig, T as TextContentPartComponent, q as TextContentPartProps, o as ToolCallContentPart, b as ToolCallContentPartProps, p as UIContentPart, U as UIContentPartComponent, s as UIContentPartProps } from './Thread-ZUDFhMtm.js';
3
+ import { ReactNode } from 'react';
4
+ import { UseBoundStore, StoreApi } from 'zustand';
5
+ import 'zod';
6
+
7
+ type AssistantModelConfigState = {
8
+ getModelConfig: ModelConfigProvider;
9
+ registerModelConfigProvider: (provider: ModelConfigProvider) => () => void;
10
+ };
11
+
12
+ type ContentPartState = Readonly<{
13
+ status: "in_progress" | "done" | "error";
14
+ part: ThreadMessage["content"][number];
15
+ }>;
16
+
17
+ type MessageState = Readonly<{
18
+ message: Readonly<ThreadMessage>;
19
+ parentId: string | null;
20
+ branches: readonly string[];
21
+ isLast: boolean;
22
+ inProgressIndicator: ReactNode | null;
23
+ setInProgressIndicator: (value: ReactNode | null) => void;
24
+ isCopied: boolean;
25
+ setIsCopied: (value: boolean) => void;
26
+ isHovering: boolean;
27
+ setIsHovering: (value: boolean) => void;
28
+ }>;
29
+
30
+ type BaseComposerState = Readonly<{
31
+ value: string;
32
+ setValue: (value: string) => void;
33
+ }>;
34
+
35
+ type EditComposerState = BaseComposerState & Readonly<{
36
+ isEditing: boolean;
37
+ edit: () => void;
38
+ send: () => void;
39
+ cancel: () => boolean;
40
+ }>;
41
+
42
+ type ComposerState = BaseComposerState & Readonly<{
43
+ isEditing: true;
44
+ send: () => void;
45
+ cancel: () => boolean;
46
+ }>;
47
+
48
+ type ThreadViewportState = {
49
+ isAtBottom: boolean;
50
+ scrollToBottom: () => void;
51
+ onScrollToBottom: (callback: () => void) => Unsubscribe;
52
+ };
53
+
54
+ type AssistantToolRenderersState = {
55
+ getToolRenderer: (name: string) => ToolCallContentPartComponent | null;
56
+ setToolRenderer: (name: string, render: ToolCallContentPartComponent) => () => void;
57
+ };
58
+
59
+ type AssistantContextValue = {
60
+ useModelConfig: UseBoundStore<StoreApi<AssistantModelConfigState>>;
61
+ useToolRenderers: UseBoundStore<StoreApi<AssistantToolRenderersState>>;
62
+ };
63
+ declare const useAssistantContext: () => AssistantContextValue;
64
+
65
+ type ThreadContextValue = {
66
+ useThread: UseBoundStore<StoreApi<ThreadState>>;
67
+ useComposer: UseBoundStore<StoreApi<ComposerState>>;
68
+ useViewport: UseBoundStore<StoreApi<ThreadViewportState>>;
69
+ };
70
+ declare const useThreadContext: () => ThreadContextValue;
71
+
72
+ type ComposerContextValue = {
73
+ useComposer: UseBoundStore<StoreApi<EditComposerState | ComposerState>>;
74
+ type: "edit" | "new";
75
+ };
76
+ declare const useComposerContext: () => ComposerContextValue;
77
+
78
+ type MessageContextValue = {
79
+ useMessage: UseBoundStore<StoreApi<MessageState>>;
80
+ useComposer: UseBoundStore<StoreApi<EditComposerState>>;
81
+ };
82
+ declare const useMessageContext: () => MessageContextValue;
83
+
84
+ type ContentPartContextValue = {
85
+ useContentPart: UseBoundStore<StoreApi<ContentPartState>>;
86
+ };
87
+ declare const useContentPartContext: () => ContentPartContextValue;
88
+
89
+ declare const useAssistantInstructions: (instruction: string) => void;
90
+
91
+ type AssistantToolProps<TArgs, TResult> = Tool<TArgs, TResult> & {
92
+ name: string;
93
+ render?: ToolCallContentPartComponent<TArgs, TResult>;
94
+ };
95
+ declare const useAssistantTool: <TArgs, TResult>(tool: AssistantToolProps<TArgs, TResult>) => void;
96
+
97
+ type AssistantToolRendererProps<TArgs, TResult> = {
98
+ name: string;
99
+ render: ToolCallContentPartComponent<TArgs, TResult>;
100
+ };
101
+ declare const useAssistantToolRenderer: (tool: AssistantToolRendererProps<any, any> | null) => void;
102
+
103
+ declare const makeTool: <TArgs, TResult>(tool: AssistantToolProps<TArgs, TResult>) => () => null;
104
+
105
+ declare const makeToolRenderer: <TArgs, TResult>(tool: AssistantToolRendererProps<TArgs, TResult>) => () => null;
106
+
107
+ export { type AssistantContextValue, type AssistantModelConfigState, type AssistantToolProps, type AssistantToolRendererProps, type ComposerContextValue, type ComposerState, type ContentPartContextValue, type ContentPartState, type EditComposerState, type MessageContextValue, type MessageState, ModelConfigProvider, type ThreadContextValue, ThreadState, type ThreadViewportState, ToolCallContentPartComponent, makeTool, makeToolRenderer, useAssistantContext, useAssistantInstructions, useAssistantTool, useAssistantToolRenderer, useComposerContext, useContentPartContext, useMessageContext, useThreadContext };
@@ -0,0 +1,183 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/experimental.ts
21
+ var experimental_exports = {};
22
+ __export(experimental_exports, {
23
+ makeTool: () => makeTool,
24
+ makeToolRenderer: () => makeToolRenderer,
25
+ useAssistantContext: () => useAssistantContext,
26
+ useAssistantInstructions: () => useAssistantInstructions,
27
+ useAssistantTool: () => useAssistantTool,
28
+ useAssistantToolRenderer: () => useAssistantToolRenderer,
29
+ useComposerContext: () => useComposerContext,
30
+ useContentPartContext: () => useContentPartContext,
31
+ useMessageContext: () => useMessageContext,
32
+ useThreadContext: () => useThreadContext
33
+ });
34
+ module.exports = __toCommonJS(experimental_exports);
35
+
36
+ // src/context/AssistantContext.ts
37
+ var import_react = require("react");
38
+ var AssistantContext = (0, import_react.createContext)(
39
+ null
40
+ );
41
+ var useAssistantContext = () => {
42
+ const context = (0, import_react.useContext)(AssistantContext);
43
+ if (!context)
44
+ throw new Error(
45
+ "This component must be used within an AssistantRuntimeProvider."
46
+ );
47
+ return context;
48
+ };
49
+
50
+ // src/context/ThreadContext.ts
51
+ var import_react2 = require("react");
52
+ var ThreadContext = (0, import_react2.createContext)(null);
53
+ var useThreadContext = () => {
54
+ const context = (0, import_react2.useContext)(ThreadContext);
55
+ if (!context)
56
+ throw new Error("This component must be used within an AssistantRuntimeProvider.");
57
+ return context;
58
+ };
59
+
60
+ // src/context/ComposerContext.ts
61
+ var import_react4 = require("react");
62
+
63
+ // src/context/MessageContext.ts
64
+ var import_react3 = require("react");
65
+ var MessageContext = (0, import_react3.createContext)(null);
66
+ var useMessageContext = () => {
67
+ const context = (0, import_react3.useContext)(MessageContext);
68
+ if (!context)
69
+ throw new Error(
70
+ "This component can only be used inside a component passed to <ThreadPrimitive.Messages components={...} />."
71
+ );
72
+ return context;
73
+ };
74
+
75
+ // src/context/ComposerContext.ts
76
+ var useComposerContext = () => {
77
+ const { useComposer } = useThreadContext();
78
+ const { useComposer: useEditComposer } = (0, import_react4.useContext)(MessageContext) ?? {};
79
+ return (0, import_react4.useMemo)(
80
+ () => ({
81
+ useComposer: useEditComposer ?? useComposer,
82
+ type: useEditComposer ? "edit" : "new"
83
+ }),
84
+ [useEditComposer, useComposer]
85
+ );
86
+ };
87
+
88
+ // src/context/ContentPartContext.ts
89
+ var import_react5 = require("react");
90
+ var ContentPartContext = (0, import_react5.createContext)(
91
+ null
92
+ );
93
+ var useContentPartContext = () => {
94
+ const context = (0, import_react5.useContext)(ContentPartContext);
95
+ if (!context)
96
+ throw new Error(
97
+ "This component can only be used inside a component passed to <MessagePrimitive.Content components={...} >."
98
+ );
99
+ return context;
100
+ };
101
+
102
+ // src/model-config/useAssistantInstructions.tsx
103
+ var import_react6 = require("react");
104
+ var useAssistantInstructions = (instruction) => {
105
+ const { useModelConfig } = useAssistantContext();
106
+ const registerModelConfigProvider = useModelConfig(
107
+ (s) => s.registerModelConfigProvider
108
+ );
109
+ (0, import_react6.useEffect)(() => {
110
+ const config = {
111
+ system: instruction
112
+ };
113
+ return registerModelConfigProvider(() => config);
114
+ }, [registerModelConfigProvider, instruction]);
115
+ };
116
+
117
+ // src/model-config/useAssistantTool.tsx
118
+ var import_react7 = require("react");
119
+ var useAssistantTool = (tool) => {
120
+ const { useModelConfig, useToolRenderers } = useAssistantContext();
121
+ const registerModelConfigProvider = useModelConfig(
122
+ (s) => s.registerModelConfigProvider
123
+ );
124
+ const setToolRenderer = useToolRenderers((s) => s.setToolRenderer);
125
+ (0, import_react7.useEffect)(() => {
126
+ const { name, render, ...rest } = tool;
127
+ const config = {
128
+ tools: {
129
+ [tool.name]: rest
130
+ }
131
+ };
132
+ const unsub1 = registerModelConfigProvider(() => config);
133
+ const unsub2 = render ? setToolRenderer(name, render) : void 0;
134
+ return () => {
135
+ unsub1();
136
+ unsub2?.();
137
+ };
138
+ }, [registerModelConfigProvider, setToolRenderer, tool]);
139
+ };
140
+
141
+ // src/model-config/useAssistantToolRenderer.tsx
142
+ var import_react8 = require("react");
143
+ var useAssistantToolRenderer = (tool) => {
144
+ const { useToolRenderers } = useAssistantContext();
145
+ const setToolRenderer = useToolRenderers((s) => s.setToolRenderer);
146
+ (0, import_react8.useEffect)(() => {
147
+ if (!tool) return;
148
+ const { name, render } = tool;
149
+ return setToolRenderer(name, render);
150
+ }, [setToolRenderer, tool]);
151
+ };
152
+
153
+ // src/model-config/makeTool.tsx
154
+ var makeTool = (tool) => {
155
+ const Tool = () => {
156
+ useAssistantTool(tool);
157
+ return null;
158
+ };
159
+ return Tool;
160
+ };
161
+
162
+ // src/model-config/makeToolRenderer.tsx
163
+ var makeToolRenderer = (tool) => {
164
+ const ToolRenderer = () => {
165
+ useAssistantToolRenderer(tool);
166
+ return null;
167
+ };
168
+ return ToolRenderer;
169
+ };
170
+ // Annotate the CommonJS export names for ESM import in node:
171
+ 0 && (module.exports = {
172
+ makeTool,
173
+ makeToolRenderer,
174
+ useAssistantContext,
175
+ useAssistantInstructions,
176
+ useAssistantTool,
177
+ useAssistantToolRenderer,
178
+ useComposerContext,
179
+ useContentPartContext,
180
+ useMessageContext,
181
+ useThreadContext
182
+ });
183
+ //# sourceMappingURL=experimental.js.map