@assistant-ui/react 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -29,7 +29,7 @@
29
29
  "conversational-ui",
30
30
  "conversational-ai"
31
31
  ],
32
- "version": "0.1.2",
32
+ "version": "0.1.3",
33
33
  "license": "MIT",
34
34
  "exports": {
35
35
  ".": {
@@ -89,7 +89,8 @@
89
89
  "@assistant-ui/tsconfig": "0.0.0"
90
90
  },
91
91
  "publishConfig": {
92
- "access": "public"
92
+ "access": "public",
93
+ "provenance": true
93
94
  },
94
95
  "homepage": "https://assistant-ui.com/",
95
96
  "repository": {
@@ -1,67 +0,0 @@
1
- import { z } from 'zod';
2
- import { ReactNode } from 'react';
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 = {
17
- type: "tool-call";
18
- name: string;
19
- args: object;
20
- result?: object;
21
- };
22
- type UserContentPart = TextContentPart | ImageContentPart | UIContentPart;
23
- type AssistantContentPart = TextContentPart | UIContentPart | ToolCallContentPart;
24
- type AppendContentPart = TextContentPart | ImageContentPart;
25
- type BaseMessage = {
26
- id: string;
27
- createdAt: Date;
28
- };
29
- type UserMessage = BaseMessage & {
30
- role: "user";
31
- content: UserContentPart[];
32
- };
33
- type AssistantMessage = BaseMessage & {
34
- role: "assistant";
35
- content: AssistantContentPart[];
36
- status: "in_progress" | "done" | "error";
37
- };
38
- type AppendMessage = {
39
- parentId: string | null;
40
- content: AppendContentPart[];
41
- };
42
- type ThreadMessage = UserMessage | AssistantMessage;
43
-
44
- type Tool<TArgs> = {
45
- description: string;
46
- parameters: z.ZodSchema<TArgs>;
47
- execute: (args: TArgs) => unknown;
48
- };
49
- type ModelConfig = {
50
- system?: string;
51
- tools?: Record<string, Tool<any>>;
52
- };
53
- type ModelConfigProvider = () => ModelConfig;
54
-
55
- type Unsubscribe = () => void;
56
-
57
- type ThreadState = {
58
- messages: readonly ThreadMessage[];
59
- isRunning: boolean;
60
- getBranches: (messageId: string) => readonly string[];
61
- switchToBranch: (branchId: string) => void;
62
- append: (message: AppendMessage) => void;
63
- startRun: (parentId: string | null) => void;
64
- cancelRun: () => void;
65
- };
66
-
67
- export type { AssistantContentPart as A, ImageContentPart as I, ModelConfigProvider as M, TextContentPart as T, UIContentPart as U, ToolCallContentPart as a, ThreadState as b, Unsubscribe as c, ThreadMessage as d, ModelConfig as e, AppendMessage as f, AssistantMessage as g, UserMessage as h, UserContentPart as i, AppendContentPart as j };
@@ -1,67 +0,0 @@
1
- import { z } from 'zod';
2
- import { ReactNode } from 'react';
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 = {
17
- type: "tool-call";
18
- name: string;
19
- args: object;
20
- result?: object;
21
- };
22
- type UserContentPart = TextContentPart | ImageContentPart | UIContentPart;
23
- type AssistantContentPart = TextContentPart | UIContentPart | ToolCallContentPart;
24
- type AppendContentPart = TextContentPart | ImageContentPart;
25
- type BaseMessage = {
26
- id: string;
27
- createdAt: Date;
28
- };
29
- type UserMessage = BaseMessage & {
30
- role: "user";
31
- content: UserContentPart[];
32
- };
33
- type AssistantMessage = BaseMessage & {
34
- role: "assistant";
35
- content: AssistantContentPart[];
36
- status: "in_progress" | "done" | "error";
37
- };
38
- type AppendMessage = {
39
- parentId: string | null;
40
- content: AppendContentPart[];
41
- };
42
- type ThreadMessage = UserMessage | AssistantMessage;
43
-
44
- type Tool<TArgs> = {
45
- description: string;
46
- parameters: z.ZodSchema<TArgs>;
47
- execute: (args: TArgs) => unknown;
48
- };
49
- type ModelConfig = {
50
- system?: string;
51
- tools?: Record<string, Tool<any>>;
52
- };
53
- type ModelConfigProvider = () => ModelConfig;
54
-
55
- type Unsubscribe = () => void;
56
-
57
- type ThreadState = {
58
- messages: readonly ThreadMessage[];
59
- isRunning: boolean;
60
- getBranches: (messageId: string) => readonly string[];
61
- switchToBranch: (branchId: string) => void;
62
- append: (message: AppendMessage) => void;
63
- startRun: (parentId: string | null) => void;
64
- cancelRun: () => void;
65
- };
66
-
67
- export type { AssistantContentPart as A, ImageContentPart as I, ModelConfigProvider as M, TextContentPart as T, UIContentPart as U, ToolCallContentPart as a, ThreadState as b, Unsubscribe as c, ThreadMessage as d, ModelConfig as e, AppendMessage as f, AssistantMessage as g, UserMessage as h, UserContentPart as i, AppendContentPart as j };
@@ -1,83 +0,0 @@
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/ContentPartContext.ts
44
- import { createContext as createContext3, useContext as useContext4 } from "react";
45
- var ContentPartContext = createContext3(
46
- null
47
- );
48
- var useContentPartContext = () => {
49
- const context = useContext4(ContentPartContext);
50
- if (!context)
51
- throw new Error(
52
- "This component can only be used inside a component passed to <MessagePrimitive.Content components={...} >."
53
- );
54
- return context;
55
- };
56
-
57
- // src/context/AssistantContext.ts
58
- import { createContext as createContext4, useContext as useContext5 } from "react";
59
- var AssistantContext = createContext4(
60
- null
61
- );
62
- var useAssistantContext = () => {
63
- const context = useContext5(AssistantContext);
64
- if (!context)
65
- throw new Error(
66
- "This component must be used within an AssistantRuntimeProvider."
67
- );
68
- return context;
69
- };
70
-
71
- export {
72
- __export,
73
- MessageContext,
74
- useMessageContext,
75
- ThreadContext,
76
- useThreadContext,
77
- useComposerContext,
78
- ContentPartContext,
79
- useContentPartContext,
80
- AssistantContext,
81
- useAssistantContext
82
- };
83
- //# sourceMappingURL=chunk-SCWPIDP6.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/context/MessageContext.ts","../src/context/ThreadContext.ts","../src/context/ComposerContext.ts","../src/context/ContentPartContext.ts","../src/context/AssistantContext.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 { 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","import { createContext, useContext } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport type { AssistantModelConfigState } from \"./stores/AssistantModelConfig\";\n\nexport type AssistantContextValue = {\n useModelConfig: UseBoundStore<StoreApi<AssistantModelConfigState>>;\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"],"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;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;;;ACnBA,SAAS,iBAAAC,gBAAe,cAAAC,mBAAkB;AAQnC,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;","names":["createContext","useContext","useContext","useContext","createContext","useContext","createContext","useContext"]}
@@ -1,85 +0,0 @@
1
- import { M as ModelConfigProvider, d as ThreadMessage, c as Unsubscribe, b as ThreadState } from './Thread-By2aBNAG.mjs';
2
- export { I as ImageContentPart, a as ToolCallContentPart, U as UIContentPart } from './Thread-By2aBNAG.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 AssistantContextValue = {
55
- useModelConfig: UseBoundStore<StoreApi<AssistantModelConfigState>>;
56
- };
57
- declare const useAssistantContext: () => AssistantContextValue;
58
-
59
- type ThreadContextValue = {
60
- useThread: UseBoundStore<StoreApi<ThreadState>>;
61
- useComposer: UseBoundStore<StoreApi<ComposerState>>;
62
- useViewport: UseBoundStore<StoreApi<ThreadViewportState>>;
63
- };
64
- declare const useThreadContext: () => ThreadContextValue;
65
-
66
- type ComposerContextValue = {
67
- useComposer: UseBoundStore<StoreApi<EditComposerState | ComposerState>>;
68
- type: "edit" | "new";
69
- };
70
- declare const useComposerContext: () => ComposerContextValue;
71
-
72
- type MessageContextValue = {
73
- useMessage: UseBoundStore<StoreApi<MessageState>>;
74
- useComposer: UseBoundStore<StoreApi<EditComposerState>>;
75
- };
76
- declare const useMessageContext: () => MessageContextValue;
77
-
78
- type ContentPartContextValue = {
79
- useContentPart: UseBoundStore<StoreApi<ContentPartState>>;
80
- };
81
- declare const useContentPartContext: () => ContentPartContextValue;
82
-
83
- declare const useAssistantInstructions: (instruction: string) => void;
84
-
85
- export { type AssistantContextValue, type AssistantModelConfigState, type ComposerContextValue, type ComposerState, type ContentPartContextValue, type ContentPartState, type EditComposerState, type MessageContextValue, type MessageState, ModelConfigProvider, type ThreadContextValue, ThreadState, type ThreadViewportState, useAssistantContext, useAssistantInstructions, useComposerContext, useContentPartContext, useMessageContext, useThreadContext };
@@ -1,85 +0,0 @@
1
- import { M as ModelConfigProvider, d as ThreadMessage, c as Unsubscribe, b as ThreadState } from './Thread-By2aBNAG.js';
2
- export { I as ImageContentPart, a as ToolCallContentPart, U as UIContentPart } from './Thread-By2aBNAG.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 AssistantContextValue = {
55
- useModelConfig: UseBoundStore<StoreApi<AssistantModelConfigState>>;
56
- };
57
- declare const useAssistantContext: () => AssistantContextValue;
58
-
59
- type ThreadContextValue = {
60
- useThread: UseBoundStore<StoreApi<ThreadState>>;
61
- useComposer: UseBoundStore<StoreApi<ComposerState>>;
62
- useViewport: UseBoundStore<StoreApi<ThreadViewportState>>;
63
- };
64
- declare const useThreadContext: () => ThreadContextValue;
65
-
66
- type ComposerContextValue = {
67
- useComposer: UseBoundStore<StoreApi<EditComposerState | ComposerState>>;
68
- type: "edit" | "new";
69
- };
70
- declare const useComposerContext: () => ComposerContextValue;
71
-
72
- type MessageContextValue = {
73
- useMessage: UseBoundStore<StoreApi<MessageState>>;
74
- useComposer: UseBoundStore<StoreApi<EditComposerState>>;
75
- };
76
- declare const useMessageContext: () => MessageContextValue;
77
-
78
- type ContentPartContextValue = {
79
- useContentPart: UseBoundStore<StoreApi<ContentPartState>>;
80
- };
81
- declare const useContentPartContext: () => ContentPartContextValue;
82
-
83
- declare const useAssistantInstructions: (instruction: string) => void;
84
-
85
- export { type AssistantContextValue, type AssistantModelConfigState, type ComposerContextValue, type ComposerState, type ContentPartContextValue, type ContentPartState, type EditComposerState, type MessageContextValue, type MessageState, ModelConfigProvider, type ThreadContextValue, ThreadState, type ThreadViewportState, useAssistantContext, useAssistantInstructions, useComposerContext, useContentPartContext, useMessageContext, useThreadContext };
@@ -1,123 +0,0 @@
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
- useAssistantContext: () => useAssistantContext,
24
- useAssistantInstructions: () => useAssistantInstructions,
25
- useComposerContext: () => useComposerContext,
26
- useContentPartContext: () => useContentPartContext,
27
- useMessageContext: () => useMessageContext,
28
- useThreadContext: () => useThreadContext
29
- });
30
- module.exports = __toCommonJS(experimental_exports);
31
-
32
- // src/context/AssistantContext.ts
33
- var import_react = require("react");
34
- var AssistantContext = (0, import_react.createContext)(
35
- null
36
- );
37
- var useAssistantContext = () => {
38
- const context = (0, import_react.useContext)(AssistantContext);
39
- if (!context)
40
- throw new Error(
41
- "This component must be used within an AssistantRuntimeProvider."
42
- );
43
- return context;
44
- };
45
-
46
- // src/context/ThreadContext.ts
47
- var import_react2 = require("react");
48
- var ThreadContext = (0, import_react2.createContext)(null);
49
- var useThreadContext = () => {
50
- const context = (0, import_react2.useContext)(ThreadContext);
51
- if (!context)
52
- throw new Error("This component must be used within an AssistantRuntimeProvider.");
53
- return context;
54
- };
55
-
56
- // src/context/ComposerContext.ts
57
- var import_react4 = require("react");
58
-
59
- // src/context/MessageContext.ts
60
- var import_react3 = require("react");
61
- var MessageContext = (0, import_react3.createContext)(null);
62
- var useMessageContext = () => {
63
- const context = (0, import_react3.useContext)(MessageContext);
64
- if (!context)
65
- throw new Error(
66
- "This component can only be used inside a component passed to <ThreadPrimitive.Messages components={...} />."
67
- );
68
- return context;
69
- };
70
-
71
- // src/context/ComposerContext.ts
72
- var useComposerContext = () => {
73
- const { useComposer } = useThreadContext();
74
- const { useComposer: useEditComposer } = (0, import_react4.useContext)(MessageContext) ?? {};
75
- return (0, import_react4.useMemo)(
76
- () => ({
77
- useComposer: useEditComposer ?? useComposer,
78
- type: useEditComposer ? "edit" : "new"
79
- }),
80
- [useEditComposer, useComposer]
81
- );
82
- };
83
-
84
- // src/context/ContentPartContext.ts
85
- var import_react5 = require("react");
86
- var ContentPartContext = (0, import_react5.createContext)(
87
- null
88
- );
89
- var useContentPartContext = () => {
90
- const context = (0, import_react5.useContext)(ContentPartContext);
91
- if (!context)
92
- throw new Error(
93
- "This component can only be used inside a component passed to <MessagePrimitive.Content components={...} >."
94
- );
95
- return context;
96
- };
97
-
98
- // src/model-config/useAssistantInstructions.tsx
99
- var import_react6 = require("react");
100
- var useAssistantInstructions = (instruction) => {
101
- const { useModelConfig } = useAssistantContext();
102
- const addContextProvider = useModelConfig(
103
- (s) => s.registerModelConfigProvider
104
- );
105
- (0, import_react6.useEffect)(
106
- () => addContextProvider(() => {
107
- return {
108
- system: instruction
109
- };
110
- }),
111
- [addContextProvider, instruction]
112
- );
113
- };
114
- // Annotate the CommonJS export names for ESM import in node:
115
- 0 && (module.exports = {
116
- useAssistantContext,
117
- useAssistantInstructions,
118
- useComposerContext,
119
- useContentPartContext,
120
- useMessageContext,
121
- useThreadContext
122
- });
123
- //# sourceMappingURL=experimental.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/experimental.ts","../src/context/AssistantContext.ts","../src/context/ThreadContext.ts","../src/context/ComposerContext.ts","../src/context/MessageContext.ts","../src/context/ContentPartContext.ts","../src/model-config/useAssistantInstructions.tsx"],"sourcesContent":["export type {\n ImageContentPart,\n ToolCallContentPart,\n UIContentPart,\n} from \"./utils/AssistantTypes\";\n\nexport type { ModelConfigProvider } from \"./utils/ModelConfigTypes\";\n\nexport * from \"./context\";\nexport { useAssistantInstructions } from \"./model-config/useAssistantInstructions\";\n","import { createContext, useContext } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport type { AssistantModelConfigState } from \"./stores/AssistantModelConfig\";\n\nexport type AssistantContextValue = {\n useModelConfig: UseBoundStore<StoreApi<AssistantModelConfigState>>;\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 { 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 { 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 { 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","\"use client\";\n\nimport { useEffect } from \"react\";\nimport { useAssistantContext } from \"../context/AssistantContext\";\n\nexport const useAssistantInstructions = (instruction: string) => {\n const { useModelConfig } = useAssistantContext();\n const addContextProvider = useModelConfig(\n (s) => s.registerModelConfigProvider,\n );\n useEffect(\n () =>\n addContextProvider(() => {\n return {\n system: instruction,\n };\n }),\n [addContextProvider, instruction],\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA0C;AAQnC,IAAM,uBAAmB;AAAA,EAC9B;AACF;AAEO,IAAM,sBAAsB,MAA6B;AAC9D,QAAM,cAAU,yBAAW,gBAAgB;AAC3C,MAAI,CAAC;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;;;ACnBA,IAAAA,gBAA0C;AAYnC,IAAM,oBAAgB,6BAAyC,IAAI;AAEnE,IAAM,mBAAmB,MAA0B;AACxD,QAAM,cAAU,0BAAW,aAAa;AACxC,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,iEAAiE;AACnF,SAAO;AACT;;;ACnBA,IAAAC,gBAAoC;;;ACApC,IAAAC,gBAA0C;AAUnC,IAAM,qBAAiB,6BAA0C,IAAI;AAErE,IAAM,oBAAoB,MAAM;AACrC,QAAM,cAAU,0BAAW,cAAc;AACzC,MAAI,CAAC;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;;;ADPO,IAAM,qBAAqB,MAA4B;AAC5D,QAAM,EAAE,YAAY,IAAI,iBAAiB;AACzC,QAAM,EAAE,aAAa,gBAAgB,QAAI,0BAAW,cAAc,KAAK,CAAC;AACxE,aAAO;AAAA,IACL,OAAO;AAAA,MACL,aAAc,mBAAmB;AAAA,MAGjC,MAAM,kBAAmB,SAAoB;AAAA,IAC/C;AAAA,IACA,CAAC,iBAAiB,WAAW;AAAA,EAC/B;AACF;;;AExBA,IAAAC,gBAA0C;AAQnC,IAAM,yBAAqB;AAAA,EAChC;AACF;AAEO,IAAM,wBAAwB,MAA+B;AAClE,QAAM,cAAU,0BAAW,kBAAkB;AAC7C,MAAI,CAAC;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;;;ACjBA,IAAAC,gBAA0B;AAGnB,IAAM,2BAA2B,CAAC,gBAAwB;AAC/D,QAAM,EAAE,eAAe,IAAI,oBAAoB;AAC/C,QAAM,qBAAqB;AAAA,IACzB,CAAC,MAAM,EAAE;AAAA,EACX;AACA;AAAA,IACE,MACE,mBAAmB,MAAM;AACvB,aAAO;AAAA,QACL,QAAQ;AAAA,MACV;AAAA,IACF,CAAC;AAAA,IACH,CAAC,oBAAoB,WAAW;AAAA,EAClC;AACF;","names":["import_react","import_react","import_react","import_react","import_react"]}
@@ -1,33 +0,0 @@
1
- import {
2
- useAssistantContext,
3
- useComposerContext,
4
- useContentPartContext,
5
- useMessageContext,
6
- useThreadContext
7
- } from "./chunk-SCWPIDP6.mjs";
8
-
9
- // src/model-config/useAssistantInstructions.tsx
10
- import { useEffect } from "react";
11
- var useAssistantInstructions = (instruction) => {
12
- const { useModelConfig } = useAssistantContext();
13
- const addContextProvider = useModelConfig(
14
- (s) => s.registerModelConfigProvider
15
- );
16
- useEffect(
17
- () => addContextProvider(() => {
18
- return {
19
- system: instruction
20
- };
21
- }),
22
- [addContextProvider, instruction]
23
- );
24
- };
25
- export {
26
- useAssistantContext,
27
- useAssistantInstructions,
28
- useComposerContext,
29
- useContentPartContext,
30
- useMessageContext,
31
- useThreadContext
32
- };
33
- //# sourceMappingURL=experimental.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/model-config/useAssistantInstructions.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect } from \"react\";\nimport { useAssistantContext } from \"../context/AssistantContext\";\n\nexport const useAssistantInstructions = (instruction: string) => {\n const { useModelConfig } = useAssistantContext();\n const addContextProvider = useModelConfig(\n (s) => s.registerModelConfigProvider,\n );\n useEffect(\n () =>\n addContextProvider(() => {\n return {\n system: instruction,\n };\n }),\n [addContextProvider, instruction],\n );\n};\n"],"mappings":";;;;;;;;;AAEA,SAAS,iBAAiB;AAGnB,IAAM,2BAA2B,CAAC,gBAAwB;AAC/D,QAAM,EAAE,eAAe,IAAI,oBAAoB;AAC/C,QAAM,qBAAqB;AAAA,IACzB,CAAC,MAAM,EAAE;AAAA,EACX;AACA;AAAA,IACE,MACE,mBAAmB,MAAM;AACvB,aAAO;AAAA,QACL,QAAQ;AAAA,MACV;AAAA,IACF,CAAC;AAAA,IACH,CAAC,oBAAoB,WAAW;AAAA,EAClC;AACF;","names":[]}