@assistant-ui/react 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +6 -15
- package/dist/AssistantRuntime-BM_jVV3g.d.mts +0 -23
- package/dist/AssistantRuntime-CBMSAJqH.d.mts +0 -23
- package/dist/AssistantRuntime-C_BvM7ZT.d.ts +0 -23
- package/dist/AssistantRuntime-DELpXWfG.d.ts +0 -23
- package/dist/ModelConfigTypes-B9UY4zxv.d.mts +0 -55
- package/dist/ModelConfigTypes-B9UY4zxv.d.ts +0 -55
- package/dist/ModelConfigTypes-BF5HxVrH.d.mts +0 -55
- package/dist/ModelConfigTypes-BF5HxVrH.d.ts +0 -55
- package/dist/ModelConfigTypes-Cf3yjaDu.d.mts +0 -55
- package/dist/ModelConfigTypes-Cf3yjaDu.d.ts +0 -55
- package/dist/ModelConfigTypes-CzmXY3sn.d.mts +0 -55
- package/dist/ModelConfigTypes-CzmXY3sn.d.ts +0 -55
- package/dist/Thread-BMASJT4a.d.ts +0 -15
- package/dist/Thread-UEVsUmvl.d.mts +0 -15
- package/dist/chunk-3XZUKECF.mjs +0 -207
- package/dist/chunk-3XZUKECF.mjs.map +0 -1
- package/dist/chunk-4DQ2CIAD.mjs +0 -69
- package/dist/chunk-4DQ2CIAD.mjs.map +0 -1
- package/dist/chunk-5YONSDN4.mjs +0 -200
- package/dist/chunk-5YONSDN4.mjs.map +0 -1
- package/dist/chunk-CY4TTHR7.mjs +0 -76
- package/dist/chunk-CY4TTHR7.mjs.map +0 -1
- package/dist/chunk-DKAWDNW5.mjs +0 -22
- package/dist/chunk-DKAWDNW5.mjs.map +0 -1
- package/dist/chunk-GQKH2ADD.mjs +0 -165
- package/dist/chunk-GQKH2ADD.mjs.map +0 -1
- package/dist/chunk-J5LGTIGS.mjs +0 -10
- package/dist/chunk-J5LGTIGS.mjs.map +0 -1
- package/dist/chunk-NSBOH42A.mjs +0 -200
- package/dist/chunk-NSBOH42A.mjs.map +0 -1
- package/dist/chunk-X4HBDEFP.mjs +0 -30
- package/dist/chunk-X4HBDEFP.mjs.map +0 -1
- package/dist/experimental.d.mts +0 -86
- package/dist/experimental.d.ts +0 -86
- package/dist/experimental.js +0 -123
- package/dist/experimental.js.map +0 -1
- package/dist/experimental.mjs +0 -34
- package/dist/experimental.mjs.map +0 -1
- package/dist/index.d.mts +0 -289
- package/dist/index.d.ts +0 -289
- package/dist/index.js +0 -1500
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -1245
- package/dist/index.mjs.map +0 -1
- package/dist/internal-dlLjX30u.d.mts +0 -75
- package/dist/internal-dlLjX30u.d.ts +0 -75
- package/dist/internal.d.mts +0 -25
- package/dist/internal.d.ts +0 -25
- package/dist/internal.js +0 -225
- package/dist/internal.js.map +0 -1
- package/dist/internal.mjs +0 -10
- package/dist/internal.mjs.map +0 -1
package/dist/chunk-GQKH2ADD.mjs
DELETED
@@ -1,165 +0,0 @@
|
|
1
|
-
// src/runtime/utils/idUtils.tsx
|
2
|
-
import { customAlphabet } from "nanoid/non-secure";
|
3
|
-
var generateId = customAlphabet(
|
4
|
-
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
5
|
-
7
|
6
|
-
);
|
7
|
-
var optimisticPrefix = "__optimistic__";
|
8
|
-
var generateOptimisticId = () => `${optimisticPrefix}${generateId()}`;
|
9
|
-
|
10
|
-
// src/runtime/utils/MessageRepository.tsx
|
11
|
-
var findHead = (message) => {
|
12
|
-
if (message.next) return findHead(message.next);
|
13
|
-
return message;
|
14
|
-
};
|
15
|
-
var MessageRepository = class {
|
16
|
-
messages = /* @__PURE__ */ new Map();
|
17
|
-
// message_id -> item
|
18
|
-
head = null;
|
19
|
-
root = {
|
20
|
-
children: []
|
21
|
-
};
|
22
|
-
performOp(newParent, child, operation) {
|
23
|
-
const parentOrRoot = child.prev ?? this.root;
|
24
|
-
const newParentOrRoot = newParent ?? this.root;
|
25
|
-
if (operation === "relink" && parentOrRoot === newParentOrRoot) return;
|
26
|
-
if (operation !== "link") {
|
27
|
-
parentOrRoot.children = parentOrRoot.children.filter(
|
28
|
-
(m) => m !== child.current.id
|
29
|
-
);
|
30
|
-
if (child.prev?.next === child) {
|
31
|
-
const fallbackId = child.prev.children.at(-1);
|
32
|
-
const fallback = fallbackId ? this.messages.get(fallbackId) : null;
|
33
|
-
if (fallback === void 0) {
|
34
|
-
throw new Error(
|
35
|
-
"MessageRepository(performOp/cut): Fallback sibling message not found. This is likely an internal bug in assistant-ui."
|
36
|
-
);
|
37
|
-
}
|
38
|
-
child.prev.next = fallback;
|
39
|
-
}
|
40
|
-
}
|
41
|
-
if (operation !== "cut") {
|
42
|
-
newParentOrRoot.children = [
|
43
|
-
...newParentOrRoot.children,
|
44
|
-
child.current.id
|
45
|
-
];
|
46
|
-
if (newParent && (findHead(child) === this.head || newParent.next === null)) {
|
47
|
-
newParent.next = child;
|
48
|
-
}
|
49
|
-
child.prev = newParent;
|
50
|
-
}
|
51
|
-
}
|
52
|
-
getMessages() {
|
53
|
-
const messages = new Array(this.head?.level ?? 0);
|
54
|
-
for (let current = this.head; current; current = current.prev) {
|
55
|
-
messages[current.level] = current.current;
|
56
|
-
}
|
57
|
-
return messages;
|
58
|
-
}
|
59
|
-
addOrUpdateMessage(parentId, message) {
|
60
|
-
const existingItem = this.messages.get(message.id);
|
61
|
-
const prev = parentId ? this.messages.get(parentId) : null;
|
62
|
-
if (prev === void 0)
|
63
|
-
throw new Error(
|
64
|
-
"MessageRepository(addOrUpdateMessage): Parent message not found. This is likely an internal bug in assistant-ui."
|
65
|
-
);
|
66
|
-
if (existingItem) {
|
67
|
-
existingItem.current = message;
|
68
|
-
this.performOp(prev, existingItem, "relink");
|
69
|
-
return;
|
70
|
-
}
|
71
|
-
const newItem = {
|
72
|
-
prev,
|
73
|
-
current: message,
|
74
|
-
next: null,
|
75
|
-
children: [],
|
76
|
-
level: prev ? prev.level + 1 : 0
|
77
|
-
};
|
78
|
-
this.messages.set(message.id, newItem);
|
79
|
-
this.performOp(prev, newItem, "link");
|
80
|
-
if (this.head === prev) {
|
81
|
-
this.head = newItem;
|
82
|
-
}
|
83
|
-
}
|
84
|
-
appendOptimisticMessage(parentId, message) {
|
85
|
-
let optimisticId;
|
86
|
-
do {
|
87
|
-
optimisticId = generateOptimisticId();
|
88
|
-
} while (this.messages.has(optimisticId));
|
89
|
-
this.addOrUpdateMessage(parentId, {
|
90
|
-
...message,
|
91
|
-
id: optimisticId,
|
92
|
-
createdAt: /* @__PURE__ */ new Date(),
|
93
|
-
...message.role === "assistant" ? { status: "in_progress" } : void 0
|
94
|
-
});
|
95
|
-
return optimisticId;
|
96
|
-
}
|
97
|
-
deleteMessage(messageId, replacementId) {
|
98
|
-
const message = this.messages.get(messageId);
|
99
|
-
if (!message)
|
100
|
-
throw new Error(
|
101
|
-
"MessageRepository(deleteMessage): Optimistic message not found. This is likely an internal bug in assistant-ui."
|
102
|
-
);
|
103
|
-
const replacement = replacementId === void 0 ? message.prev : replacementId === null ? null : this.messages.get(replacementId);
|
104
|
-
if (replacement === void 0)
|
105
|
-
throw new Error(
|
106
|
-
"MessageRepository(deleteMessage): Replacement not found. This is likely an internal bug in assistant-ui."
|
107
|
-
);
|
108
|
-
for (const child of message.children) {
|
109
|
-
const childMessage = this.messages.get(child);
|
110
|
-
if (!childMessage)
|
111
|
-
throw new Error(
|
112
|
-
"MessageRepository(deleteMessage): Child message not found. This is likely an internal bug in assistant-ui."
|
113
|
-
);
|
114
|
-
this.performOp(replacement, childMessage, "relink");
|
115
|
-
}
|
116
|
-
this.performOp(null, message, "cut");
|
117
|
-
this.messages.delete(messageId);
|
118
|
-
if (this.head === message) {
|
119
|
-
this.head = replacement ? findHead(replacement) : null;
|
120
|
-
}
|
121
|
-
}
|
122
|
-
getBranches(messageId) {
|
123
|
-
const message = this.messages.get(messageId);
|
124
|
-
if (!message)
|
125
|
-
throw new Error(
|
126
|
-
"MessageRepository(getBranches): Message not found. This is likely an internal bug in assistant-ui."
|
127
|
-
);
|
128
|
-
const { children } = message.prev ?? this.root;
|
129
|
-
return children;
|
130
|
-
}
|
131
|
-
switchToBranch(messageId) {
|
132
|
-
const message = this.messages.get(messageId);
|
133
|
-
if (!message)
|
134
|
-
throw new Error(
|
135
|
-
"MessageRepository(switchToBranch): Branch not found. This is likely an internal bug in assistant-ui."
|
136
|
-
);
|
137
|
-
if (message.prev) {
|
138
|
-
message.prev.next = message;
|
139
|
-
}
|
140
|
-
this.head = findHead(message);
|
141
|
-
}
|
142
|
-
resetHead(messageId) {
|
143
|
-
if (messageId === null) {
|
144
|
-
this.head = null;
|
145
|
-
return;
|
146
|
-
}
|
147
|
-
const message = this.messages.get(messageId);
|
148
|
-
if (!message)
|
149
|
-
throw new Error(
|
150
|
-
"MessageRepository(resetHead): Branch not found. This is likely an internal bug in assistant-ui."
|
151
|
-
);
|
152
|
-
this.head = message;
|
153
|
-
for (let current = message; current; current = current.prev) {
|
154
|
-
if (current.prev) {
|
155
|
-
current.prev.next = current;
|
156
|
-
}
|
157
|
-
}
|
158
|
-
}
|
159
|
-
};
|
160
|
-
|
161
|
-
export {
|
162
|
-
generateId,
|
163
|
-
MessageRepository
|
164
|
-
};
|
165
|
-
//# sourceMappingURL=chunk-GQKH2ADD.mjs.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../src/runtime/utils/idUtils.tsx","../src/runtime/utils/MessageRepository.tsx"],"sourcesContent":["import { customAlphabet } from \"nanoid/non-secure\";\n\nexport const generateId = customAlphabet(\n \"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\",\n 7,\n);\n\nconst optimisticPrefix = \"__optimistic__\";\nexport const generateOptimisticId = () => `${optimisticPrefix}${generateId()}`;\nexport const isOptimisticId = (id: string) => id.startsWith(optimisticPrefix);\n","import type { ThreadMessage } from \"../../utils/AssistantTypes\";\nimport { generateOptimisticId } from \"./idUtils\";\n\ntype RepositoryParent = {\n children: string[];\n};\n\ntype RepositoryMessage = RepositoryParent & {\n prev: RepositoryMessage | null;\n current: ThreadMessage;\n next: RepositoryMessage | null;\n level: number;\n};\n\nconst findHead = (message: RepositoryMessage): RepositoryMessage => {\n if (message.next) return findHead(message.next);\n return message;\n};\n\nexport class MessageRepository {\n private messages = new Map<string, RepositoryMessage>(); // message_id -> item\n private head: RepositoryMessage | null = null;\n private root: RepositoryParent = {\n children: [],\n };\n\n private performOp(\n newParent: RepositoryMessage | null,\n child: RepositoryMessage,\n operation: \"cut\" | \"link\" | \"relink\",\n ) {\n const parentOrRoot = child.prev ?? this.root;\n const newParentOrRoot = newParent ?? this.root;\n\n if (operation === \"relink\" && parentOrRoot === newParentOrRoot) return;\n\n // cut\n if (operation !== \"link\") {\n parentOrRoot.children = parentOrRoot.children.filter(\n (m) => m !== child.current.id,\n );\n\n if (child.prev?.next === child) {\n const fallbackId = child.prev.children.at(-1);\n const fallback = fallbackId ? this.messages.get(fallbackId) : null;\n if (fallback === undefined) {\n throw new Error(\n \"MessageRepository(performOp/cut): Fallback sibling message not found. This is likely an internal bug in assistant-ui.\",\n );\n }\n child.prev.next = fallback;\n }\n }\n\n // link\n if (operation !== \"cut\") {\n newParentOrRoot.children = [\n ...newParentOrRoot.children,\n child.current.id,\n ];\n\n if (\n newParent &&\n (findHead(child) === this.head || newParent.next === null)\n ) {\n newParent.next = child;\n }\n\n child.prev = newParent;\n }\n }\n getMessages() {\n const messages = new Array<ThreadMessage>(this.head?.level ?? 0);\n for (let current = this.head; current; current = current.prev) {\n messages[current.level] = current.current;\n }\n return messages;\n }\n\n addOrUpdateMessage(parentId: string | null, message: ThreadMessage) {\n const existingItem = this.messages.get(message.id);\n const prev = parentId ? this.messages.get(parentId) : null;\n if (prev === undefined)\n throw new Error(\n \"MessageRepository(addOrUpdateMessage): Parent message not found. This is likely an internal bug in assistant-ui.\",\n );\n\n // update existing message\n if (existingItem) {\n existingItem.current = message;\n this.performOp(prev, existingItem, \"relink\");\n return;\n }\n\n // create a new message\n const newItem: RepositoryMessage = {\n prev,\n current: message,\n next: null,\n children: [],\n level: prev ? prev.level + 1 : 0,\n };\n\n this.messages.set(message.id, newItem);\n this.performOp(prev, newItem, \"link\");\n\n if (this.head === prev) {\n this.head = newItem;\n }\n }\n\n appendOptimisticMessage(\n parentId: string | null,\n message: Omit<ThreadMessage, \"id\" | \"createdAt\">,\n ) {\n let optimisticId: string;\n do {\n optimisticId = generateOptimisticId();\n } while (this.messages.has(optimisticId));\n\n this.addOrUpdateMessage(parentId, {\n ...message,\n id: optimisticId,\n createdAt: new Date(),\n ...(message.role === \"assistant\" ? { status: \"in_progress\" } : undefined),\n } as ThreadMessage);\n\n return optimisticId;\n }\n\n deleteMessage(messageId: string, replacementId?: string | null | undefined) {\n const message = this.messages.get(messageId);\n\n if (!message)\n throw new Error(\n \"MessageRepository(deleteMessage): Optimistic message not found. This is likely an internal bug in assistant-ui.\",\n );\n\n const replacement =\n replacementId === undefined\n ? message.prev // if no replacementId is provided, use the parent\n : replacementId === null\n ? null\n : this.messages.get(replacementId);\n if (replacement === undefined)\n throw new Error(\n \"MessageRepository(deleteMessage): Replacement not found. This is likely an internal bug in assistant-ui.\",\n );\n\n for (const child of message.children) {\n const childMessage = this.messages.get(child);\n if (!childMessage)\n throw new Error(\n \"MessageRepository(deleteMessage): Child message not found. This is likely an internal bug in assistant-ui.\",\n );\n this.performOp(replacement, childMessage, \"relink\");\n }\n\n this.performOp(null, message, \"cut\");\n this.messages.delete(messageId);\n\n if (this.head === message) {\n this.head = replacement ? findHead(replacement) : null;\n }\n }\n\n getBranches(messageId: string) {\n const message = this.messages.get(messageId);\n if (!message)\n throw new Error(\n \"MessageRepository(getBranches): Message not found. This is likely an internal bug in assistant-ui.\",\n );\n\n const { children } = message.prev ?? this.root;\n return children;\n }\n\n switchToBranch(messageId: string) {\n const message = this.messages.get(messageId);\n if (!message)\n throw new Error(\n \"MessageRepository(switchToBranch): Branch not found. This is likely an internal bug in assistant-ui.\",\n );\n\n if (message.prev) {\n message.prev.next = message;\n }\n\n this.head = findHead(message);\n }\n\n resetHead(messageId: string | null) {\n if (messageId === null) {\n this.head = null;\n return;\n }\n\n const message = this.messages.get(messageId);\n if (!message)\n throw new Error(\n \"MessageRepository(resetHead): Branch not found. This is likely an internal bug in assistant-ui.\",\n );\n\n this.head = message;\n for (\n let current: RepositoryMessage | null = message;\n current;\n current = current.prev\n ) {\n if (current.prev) {\n current.prev.next = current;\n }\n }\n }\n}\n"],"mappings":";AAAA,SAAS,sBAAsB;AAExB,IAAM,aAAa;AAAA,EACxB;AAAA,EACA;AACF;AAEA,IAAM,mBAAmB;AAClB,IAAM,uBAAuB,MAAM,GAAG,gBAAgB,GAAG,WAAW,CAAC;;;ACM5E,IAAM,WAAW,CAAC,YAAkD;AAClE,MAAI,QAAQ,KAAM,QAAO,SAAS,QAAQ,IAAI;AAC9C,SAAO;AACT;AAEO,IAAM,oBAAN,MAAwB;AAAA,EACrB,WAAW,oBAAI,IAA+B;AAAA;AAAA,EAC9C,OAAiC;AAAA,EACjC,OAAyB;AAAA,IAC/B,UAAU,CAAC;AAAA,EACb;AAAA,EAEQ,UACN,WACA,OACA,WACA;AACA,UAAM,eAAe,MAAM,QAAQ,KAAK;AACxC,UAAM,kBAAkB,aAAa,KAAK;AAE1C,QAAI,cAAc,YAAY,iBAAiB,gBAAiB;AAGhE,QAAI,cAAc,QAAQ;AACxB,mBAAa,WAAW,aAAa,SAAS;AAAA,QAC5C,CAAC,MAAM,MAAM,MAAM,QAAQ;AAAA,MAC7B;AAEA,UAAI,MAAM,MAAM,SAAS,OAAO;AAC9B,cAAM,aAAa,MAAM,KAAK,SAAS,GAAG,EAAE;AAC5C,cAAM,WAAW,aAAa,KAAK,SAAS,IAAI,UAAU,IAAI;AAC9D,YAAI,aAAa,QAAW;AAC1B,gBAAM,IAAI;AAAA,YACR;AAAA,UACF;AAAA,QACF;AACA,cAAM,KAAK,OAAO;AAAA,MACpB;AAAA,IACF;AAGA,QAAI,cAAc,OAAO;AACvB,sBAAgB,WAAW;AAAA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AAS;AAC3C,QAAI,CAAC;AACH,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAEF,SAAK,OAAO;AACZ,aACM,UAAoC,SACxC,SACA,UAAU,QAAQ,MAClB;AACA,UAAI,QAAQ,MAAM;AAChB,gBAAQ,KAAK,OAAO;AAAA,MACtB;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/dist/chunk-J5LGTIGS.mjs
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/chunk-NSBOH42A.mjs
DELETED
@@ -1,200 +0,0 @@
|
|
1
|
-
// src/runtime/utils/idUtils.tsx
|
2
|
-
import { customAlphabet } from "nanoid/non-secure";
|
3
|
-
var generateId = customAlphabet(
|
4
|
-
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
5
|
-
7
|
6
|
-
);
|
7
|
-
var optimisticPrefix = "__optimistic__";
|
8
|
-
var generateOptimisticId = () => `${optimisticPrefix}${generateId()}`;
|
9
|
-
|
10
|
-
// src/runtime/utils/MessageRepository.tsx
|
11
|
-
var findHead = (message) => {
|
12
|
-
if (message.next) return findHead(message.next);
|
13
|
-
return message;
|
14
|
-
};
|
15
|
-
var MessageRepository = class {
|
16
|
-
messages = /* @__PURE__ */ new Map();
|
17
|
-
// message_id -> item
|
18
|
-
head = null;
|
19
|
-
root = {
|
20
|
-
children: []
|
21
|
-
};
|
22
|
-
performOp(newParent, child, operation) {
|
23
|
-
const parentOrRoot = child.prev ?? this.root;
|
24
|
-
const newParentOrRoot = newParent ?? this.root;
|
25
|
-
if (operation === "relink" && parentOrRoot === newParentOrRoot) return;
|
26
|
-
if (operation !== "link") {
|
27
|
-
parentOrRoot.children = parentOrRoot.children.filter(
|
28
|
-
(m) => m !== child.current.id
|
29
|
-
);
|
30
|
-
if (child.prev?.next === child) {
|
31
|
-
const fallbackId = child.prev.children.at(-1);
|
32
|
-
const fallback = fallbackId ? this.messages.get(fallbackId) : null;
|
33
|
-
if (fallback === void 0) {
|
34
|
-
throw new Error(
|
35
|
-
"MessageRepository(performOp/cut): Fallback sibling message not found. This is likely an internal bug in assistant-ui."
|
36
|
-
);
|
37
|
-
}
|
38
|
-
child.prev.next = fallback;
|
39
|
-
}
|
40
|
-
}
|
41
|
-
if (operation !== "cut") {
|
42
|
-
newParentOrRoot.children = [
|
43
|
-
...newParentOrRoot.children,
|
44
|
-
child.current.id
|
45
|
-
];
|
46
|
-
if (newParent && (findHead(child) === this.head || newParent.next === null)) {
|
47
|
-
newParent.next = child;
|
48
|
-
}
|
49
|
-
child.prev = newParent;
|
50
|
-
}
|
51
|
-
}
|
52
|
-
getMessages() {
|
53
|
-
const messages = new Array(this.head?.level ?? 0);
|
54
|
-
for (let current = this.head; current; current = current.prev) {
|
55
|
-
messages[current.level] = current.current;
|
56
|
-
}
|
57
|
-
return messages;
|
58
|
-
}
|
59
|
-
addOrUpdateMessage(parentId, message) {
|
60
|
-
const existingItem = this.messages.get(message.id);
|
61
|
-
const prev = parentId ? this.messages.get(parentId) : null;
|
62
|
-
if (prev === void 0)
|
63
|
-
throw new Error(
|
64
|
-
"MessageRepository(addOrUpdateMessage): Parent message not found. This is likely an internal bug in assistant-ui."
|
65
|
-
);
|
66
|
-
if (existingItem) {
|
67
|
-
existingItem.current = message;
|
68
|
-
this.performOp(prev, existingItem, "relink");
|
69
|
-
return;
|
70
|
-
}
|
71
|
-
const newItem = {
|
72
|
-
prev,
|
73
|
-
current: message,
|
74
|
-
next: null,
|
75
|
-
children: [],
|
76
|
-
level: prev ? prev.level + 1 : 0
|
77
|
-
};
|
78
|
-
this.messages.set(message.id, newItem);
|
79
|
-
this.performOp(prev, newItem, "link");
|
80
|
-
if (this.head === prev) {
|
81
|
-
this.head = newItem;
|
82
|
-
}
|
83
|
-
}
|
84
|
-
appendOptimisticMessage(parentId, message) {
|
85
|
-
let optimisticId;
|
86
|
-
do {
|
87
|
-
optimisticId = generateOptimisticId();
|
88
|
-
} while (this.messages.has(optimisticId));
|
89
|
-
this.addOrUpdateMessage(parentId, {
|
90
|
-
...message,
|
91
|
-
id: optimisticId,
|
92
|
-
createdAt: /* @__PURE__ */ new Date(),
|
93
|
-
...message.role === "assistant" ? { status: "in_progress" } : void 0
|
94
|
-
});
|
95
|
-
return optimisticId;
|
96
|
-
}
|
97
|
-
deleteMessage(messageId, replacementId) {
|
98
|
-
const message = this.messages.get(messageId);
|
99
|
-
if (!message)
|
100
|
-
throw new Error(
|
101
|
-
"MessageRepository(deleteMessage): Optimistic message not found. This is likely an internal bug in assistant-ui."
|
102
|
-
);
|
103
|
-
const replacement = replacementId === void 0 ? message.prev : replacementId === null ? null : this.messages.get(replacementId);
|
104
|
-
if (replacement === void 0)
|
105
|
-
throw new Error(
|
106
|
-
"MessageRepository(deleteMessage): Replacement not found. This is likely an internal bug in assistant-ui."
|
107
|
-
);
|
108
|
-
for (const child of message.children) {
|
109
|
-
const childMessage = this.messages.get(child);
|
110
|
-
if (!childMessage)
|
111
|
-
throw new Error(
|
112
|
-
"MessageRepository(deleteMessage): Child message not found. This is likely an internal bug in assistant-ui."
|
113
|
-
);
|
114
|
-
this.performOp(replacement, childMessage, "relink");
|
115
|
-
}
|
116
|
-
this.performOp(null, message, "cut");
|
117
|
-
this.messages.delete(messageId);
|
118
|
-
if (this.head === message) {
|
119
|
-
this.head = replacement ? findHead(replacement) : null;
|
120
|
-
}
|
121
|
-
}
|
122
|
-
getBranches(messageId) {
|
123
|
-
const message = this.messages.get(messageId);
|
124
|
-
if (!message)
|
125
|
-
throw new Error(
|
126
|
-
"MessageRepository(getBranches): Message not found. This is likely an internal bug in assistant-ui."
|
127
|
-
);
|
128
|
-
const { children } = message.prev ?? this.root;
|
129
|
-
return children;
|
130
|
-
}
|
131
|
-
switchToBranch(messageId) {
|
132
|
-
const message = this.messages.get(messageId);
|
133
|
-
if (!message)
|
134
|
-
throw new Error(
|
135
|
-
"MessageRepository(switchToBranch): Branch not found. This is likely an internal bug in assistant-ui."
|
136
|
-
);
|
137
|
-
if (message.prev) {
|
138
|
-
message.prev.next = message;
|
139
|
-
}
|
140
|
-
this.head = findHead(message);
|
141
|
-
}
|
142
|
-
resetHead(messageId) {
|
143
|
-
if (messageId === null) {
|
144
|
-
this.head = null;
|
145
|
-
return;
|
146
|
-
}
|
147
|
-
const message = this.messages.get(messageId);
|
148
|
-
if (!message)
|
149
|
-
throw new Error(
|
150
|
-
"MessageRepository(resetHead): Branch not found. This is likely an internal bug in assistant-ui."
|
151
|
-
);
|
152
|
-
this.head = message;
|
153
|
-
for (let current = message; current; current = current.prev) {
|
154
|
-
if (current.prev) {
|
155
|
-
current.prev.next = current;
|
156
|
-
}
|
157
|
-
}
|
158
|
-
}
|
159
|
-
};
|
160
|
-
|
161
|
-
// src/utils/ModelConfigTypes.ts
|
162
|
-
var mergeModelConfigs = (configs) => {
|
163
|
-
return configs.reduce((acc, config) => {
|
164
|
-
if (config.system) {
|
165
|
-
if (acc.system) {
|
166
|
-
acc.system += `
|
167
|
-
|
168
|
-
${config.system}`;
|
169
|
-
} else {
|
170
|
-
acc.system = config.system;
|
171
|
-
}
|
172
|
-
}
|
173
|
-
if (config.tools) {
|
174
|
-
acc.tools = { ...acc.tools, ...config.tools };
|
175
|
-
}
|
176
|
-
return acc;
|
177
|
-
}, {});
|
178
|
-
};
|
179
|
-
|
180
|
-
// src/utils/ProxyConfigProvider.ts
|
181
|
-
var ProxyConfigProvider = class {
|
182
|
-
_providers = /* @__PURE__ */ new Set();
|
183
|
-
getModelConfig() {
|
184
|
-
return mergeModelConfigs([...this._providers].map((p) => p()));
|
185
|
-
}
|
186
|
-
registerModelConfigProvider(provider) {
|
187
|
-
this._providers.add(provider);
|
188
|
-
return () => {
|
189
|
-
this._providers.delete(provider);
|
190
|
-
};
|
191
|
-
}
|
192
|
-
};
|
193
|
-
|
194
|
-
export {
|
195
|
-
mergeModelConfigs,
|
196
|
-
generateId,
|
197
|
-
MessageRepository,
|
198
|
-
ProxyConfigProvider
|
199
|
-
};
|
200
|
-
//# sourceMappingURL=chunk-NSBOH42A.mjs.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../src/runtime/utils/idUtils.tsx","../src/runtime/utils/MessageRepository.tsx","../src/utils/ModelConfigTypes.ts","../src/utils/ProxyConfigProvider.ts"],"sourcesContent":["import { customAlphabet } from \"nanoid/non-secure\";\n\nexport const generateId = customAlphabet(\n \"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\",\n 7,\n);\n\nconst optimisticPrefix = \"__optimistic__\";\nexport const generateOptimisticId = () => `${optimisticPrefix}${generateId()}`;\nexport const isOptimisticId = (id: string) => id.startsWith(optimisticPrefix);\n","import type { ThreadMessage } from \"../../utils/AssistantTypes\";\nimport { generateOptimisticId } from \"./idUtils\";\n\ntype RepositoryParent = {\n children: string[];\n};\n\ntype RepositoryMessage = RepositoryParent & {\n prev: RepositoryMessage | null;\n current: ThreadMessage;\n next: RepositoryMessage | null;\n level: number;\n};\n\nconst findHead = (message: RepositoryMessage): RepositoryMessage => {\n if (message.next) return findHead(message.next);\n return message;\n};\n\nexport class MessageRepository {\n private messages = new Map<string, RepositoryMessage>(); // message_id -> item\n private head: RepositoryMessage | null = null;\n private root: RepositoryParent = {\n children: [],\n };\n\n private performOp(\n newParent: RepositoryMessage | null,\n child: RepositoryMessage,\n operation: \"cut\" | \"link\" | \"relink\",\n ) {\n const parentOrRoot = child.prev ?? this.root;\n const newParentOrRoot = newParent ?? this.root;\n\n if (operation === \"relink\" && parentOrRoot === newParentOrRoot) return;\n\n // cut\n if (operation !== \"link\") {\n parentOrRoot.children = parentOrRoot.children.filter(\n (m) => m !== child.current.id,\n );\n\n if (child.prev?.next === child) {\n const fallbackId = child.prev.children.at(-1);\n const fallback = fallbackId ? this.messages.get(fallbackId) : null;\n if (fallback === undefined) {\n throw new Error(\n \"MessageRepository(performOp/cut): Fallback sibling message not found. This is likely an internal bug in assistant-ui.\",\n );\n }\n child.prev.next = fallback;\n }\n }\n\n // link\n if (operation !== \"cut\") {\n newParentOrRoot.children = [\n ...newParentOrRoot.children,\n child.current.id,\n ];\n\n if (\n newParent &&\n (findHead(child) === this.head || newParent.next === null)\n ) {\n newParent.next = child;\n }\n\n child.prev = newParent;\n }\n }\n getMessages() {\n const messages = new Array<ThreadMessage>(this.head?.level ?? 0);\n for (let current = this.head; current; current = current.prev) {\n messages[current.level] = current.current;\n }\n return messages;\n }\n\n addOrUpdateMessage(parentId: string | null, message: ThreadMessage) {\n const existingItem = this.messages.get(message.id);\n const prev = parentId ? this.messages.get(parentId) : null;\n if (prev === undefined)\n throw new Error(\n \"MessageRepository(addOrUpdateMessage): Parent message not found. This is likely an internal bug in assistant-ui.\",\n );\n\n // update existing message\n if (existingItem) {\n existingItem.current = message;\n this.performOp(prev, existingItem, \"relink\");\n return;\n }\n\n // create a new message\n const newItem: RepositoryMessage = {\n prev,\n current: message,\n next: null,\n children: [],\n level: prev ? prev.level + 1 : 0,\n };\n\n this.messages.set(message.id, newItem);\n this.performOp(prev, newItem, \"link\");\n\n if (this.head === prev) {\n this.head = newItem;\n }\n }\n\n appendOptimisticMessage(\n parentId: string | null,\n message: Omit<ThreadMessage, \"id\" | \"createdAt\">,\n ) {\n let optimisticId: string;\n do {\n optimisticId = generateOptimisticId();\n } while (this.messages.has(optimisticId));\n\n this.addOrUpdateMessage(parentId, {\n ...message,\n id: optimisticId,\n createdAt: new Date(),\n ...(message.role === \"assistant\" ? { status: \"in_progress\" } : undefined),\n } as ThreadMessage);\n\n return optimisticId;\n }\n\n deleteMessage(messageId: string, replacementId?: string | null | undefined) {\n const message = this.messages.get(messageId);\n\n if (!message)\n throw new Error(\n \"MessageRepository(deleteMessage): Optimistic message not found. This is likely an internal bug in assistant-ui.\",\n );\n\n const replacement =\n replacementId === undefined\n ? message.prev // if no replacementId is provided, use the parent\n : replacementId === null\n ? null\n : this.messages.get(replacementId);\n if (replacement === undefined)\n throw new Error(\n \"MessageRepository(deleteMessage): Replacement not found. This is likely an internal bug in assistant-ui.\",\n );\n\n for (const child of message.children) {\n const childMessage = this.messages.get(child);\n if (!childMessage)\n throw new Error(\n \"MessageRepository(deleteMessage): Child message not found. This is likely an internal bug in assistant-ui.\",\n );\n this.performOp(replacement, childMessage, \"relink\");\n }\n\n this.performOp(null, message, \"cut\");\n this.messages.delete(messageId);\n\n if (this.head === message) {\n this.head = replacement ? findHead(replacement) : null;\n }\n }\n\n getBranches(messageId: string) {\n const message = this.messages.get(messageId);\n if (!message)\n throw new Error(\n \"MessageRepository(getBranches): Message not found. This is likely an internal bug in assistant-ui.\",\n );\n\n const { children } = message.prev ?? this.root;\n return children;\n }\n\n switchToBranch(messageId: string) {\n const message = this.messages.get(messageId);\n if (!message)\n throw new Error(\n \"MessageRepository(switchToBranch): Branch not found. This is likely an internal bug in assistant-ui.\",\n );\n\n if (message.prev) {\n message.prev.next = message;\n }\n\n this.head = findHead(message);\n }\n\n resetHead(messageId: string | null) {\n if (messageId === null) {\n this.head = null;\n return;\n }\n\n const message = this.messages.get(messageId);\n if (!message)\n throw new Error(\n \"MessageRepository(resetHead): Branch not found. This is likely an internal bug in assistant-ui.\",\n );\n\n this.head = message;\n for (\n let current: RepositoryMessage | null = message;\n current;\n current = current.prev\n ) {\n if (current.prev) {\n current.prev.next = current;\n }\n }\n }\n}\n","\"use client\";\nimport type { z } from \"zod\";\n\nexport type Tool<TArgs> = {\n description: string;\n parameters: z.ZodSchema<TArgs>;\n execute: (args: TArgs) => unknown; // TODO return type\n};\n\nexport type ModelConfig = {\n system?: string;\n // biome-ignore lint/suspicious/noExplicitAny: TODO\n tools?: Record<string, Tool<any>>;\n};\n\nexport type ModelConfigProvider = () => ModelConfig;\n\nexport const mergeModelConfigs = (configs: ModelConfig[]): ModelConfig => {\n return configs.reduce((acc, config) => {\n if (config.system) {\n if (acc.system) {\n // TODO should the separator be configurable?\n acc.system += `\\n\\n${config.system}`;\n } else {\n acc.system = config.system;\n }\n }\n if (config.tools) {\n acc.tools = { ...acc.tools, ...config.tools };\n }\n return acc;\n }, {} as ModelConfig);\n};\n","\"use client\";\nimport {\n type ModelConfigProvider,\n mergeModelConfigs,\n} from \"./ModelConfigTypes\";\n\nexport class ProxyConfigProvider {\n private _providers = new Set<ModelConfigProvider>();\n\n getModelConfig() {\n return mergeModelConfigs([...this._providers].map((p) => p()));\n }\n\n registerModelConfigProvider(provider: ModelConfigProvider) {\n this._providers.add(provider);\n return () => {\n this._providers.delete(provider);\n };\n }\n}\n"],"mappings":";AAAA,SAAS,sBAAsB;AAExB,IAAM,aAAa;AAAA,EACxB;AAAA,EACA;AACF;AAEA,IAAM,mBAAmB;AAClB,IAAM,uBAAuB,MAAM,GAAG,gBAAgB,GAAG,WAAW,CAAC;;;ACM5E,IAAM,WAAW,CAAC,YAAkD;AAClE,MAAI,QAAQ,KAAM,QAAO,SAAS,QAAQ,IAAI;AAC9C,SAAO;AACT;AAEO,IAAM,oBAAN,MAAwB;AAAA,EACrB,WAAW,oBAAI,IAA+B;AAAA;AAAA,EAC9C,OAAiC;AAAA,EACjC,OAAyB;AAAA,IAC/B,UAAU,CAAC;AAAA,EACb;AAAA,EAEQ,UACN,WACA,OACA,WACA;AACA,UAAM,eAAe,MAAM,QAAQ,KAAK;AACxC,UAAM,kBAAkB,aAAa,KAAK;AAE1C,QAAI,cAAc,YAAY,iBAAiB,gBAAiB;AAGhE,QAAI,cAAc,QAAQ;AACxB,mBAAa,WAAW,aAAa,SAAS;AAAA,QAC5C,CAAC,MAAM,MAAM,MAAM,QAAQ;AAAA,MAC7B;AAEA,UAAI,MAAM,MAAM,SAAS,OAAO;AAC9B,cAAM,aAAa,MAAM,KAAK,SAAS,GAAG,EAAE;AAC5C,cAAM,WAAW,aAAa,KAAK,SAAS,IAAI,UAAU,IAAI;AAC9D,YAAI,aAAa,QAAW;AAC1B,gBAAM,IAAI;AAAA,YACR;AAAA,UACF;AAAA,QACF;AACA,cAAM,KAAK,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MAAM;AACtB,WAAK,OAAO;AACZ;AAAA,IACF;AAEA,UAAM,UAAU,KAAK,SAAS,IAAI,SAAS;AAC3C,QAAI,CAAC;AACH,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAEF,SAAK,OAAO;AACZ,aACM,UAAoC,SACxC,SACA,UAAU,QAAQ,MAClB;AACA,UAAI,QAAQ,MAAM;AAChB,gBAAQ,KAAK,OAAO;AAAA,MACtB;AAAA,IACF;AAAA,EACF;AACF;;;ACrMO,IAAM,oBAAoB,CAAC,YAAwC;AACxE,SAAO,QAAQ,OAAO,CAAC,KAAK,WAAW;AACrC,QAAI,OAAO,QAAQ;AACjB,UAAI,IAAI,QAAQ;AAEd,YAAI,UAAU;AAAA;AAAA,EAAO,OAAO,MAAM;AAAA,MACpC,OAAO;AACL,YAAI,SAAS,OAAO;AAAA,MACtB;AAAA,IACF;AACA,QAAI,OAAO,OAAO;AAChB,UAAI,QAAQ,EAAE,GAAG,IAAI,OAAO,GAAG,OAAO,MAAM;AAAA,IAC9C;AACA,WAAO;AAAA,EACT,GAAG,CAAC,CAAgB;AACtB;;;AC1BO,IAAM,sBAAN,MAA0B;AAAA,EACvB,aAAa,oBAAI,IAAyB;AAAA,EAElD,iBAAiB;AACf,WAAO,kBAAkB,CAAC,GAAG,KAAK,UAAU,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;AAAA,EAC/D;AAAA,EAEA,4BAA4B,UAA+B;AACzD,SAAK,WAAW,IAAI,QAAQ;AAC5B,WAAO,MAAM;AACX,WAAK,WAAW,OAAO,QAAQ;AAAA,IACjC;AAAA,EACF;AACF;","names":[]}
|
package/dist/chunk-X4HBDEFP.mjs
DELETED
@@ -1,30 +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/utils/ModelConfigTypes.ts
|
8
|
-
var mergeModelConfigs = (configs) => {
|
9
|
-
return configs.reduce((acc, config) => {
|
10
|
-
if (config.system) {
|
11
|
-
if (acc.system) {
|
12
|
-
acc.system += `
|
13
|
-
|
14
|
-
${config.system}`;
|
15
|
-
} else {
|
16
|
-
acc.system = config.system;
|
17
|
-
}
|
18
|
-
}
|
19
|
-
if (config.tools) {
|
20
|
-
acc.tools = { ...acc.tools, ...config.tools };
|
21
|
-
}
|
22
|
-
return acc;
|
23
|
-
}, {});
|
24
|
-
};
|
25
|
-
|
26
|
-
export {
|
27
|
-
__export,
|
28
|
-
mergeModelConfigs
|
29
|
-
};
|
30
|
-
//# sourceMappingURL=chunk-X4HBDEFP.mjs.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../src/utils/ModelConfigTypes.ts"],"sourcesContent":["\"use client\";\nimport type { z } from \"zod\";\n\nexport type Tool<TArgs> = {\n description: string;\n parameters: z.ZodSchema<TArgs>;\n execute: (args: TArgs) => unknown; // TODO return type\n};\n\nexport type ModelConfig = {\n system?: string;\n // biome-ignore lint/suspicious/noExplicitAny: TODO\n tools?: Record<string, Tool<any>>;\n};\n\nexport type ModelConfigProvider = () => ModelConfig;\n\nexport const mergeModelConfigs = (configs: ModelConfig[]): ModelConfig => {\n return configs.reduce((acc, config) => {\n if (config.system) {\n if (acc.system) {\n // TODO should the separator be configurable?\n acc.system += `\\n\\n${config.system}`;\n } else {\n acc.system = config.system;\n }\n }\n if (config.tools) {\n acc.tools = { ...acc.tools, ...config.tools };\n }\n return acc;\n }, {} as ModelConfig);\n};\n"],"mappings":";;;;;;;AAiBO,IAAM,oBAAoB,CAAC,YAAwC;AACxE,SAAO,QAAQ,OAAO,CAAC,KAAK,WAAW;AACrC,QAAI,OAAO,QAAQ;AACjB,UAAI,IAAI,QAAQ;AAEd,YAAI,UAAU;AAAA;AAAA,EAAO,OAAO,MAAM;AAAA,MACpC,OAAO;AACL,YAAI,SAAS,OAAO;AAAA,MACtB;AAAA,IACF;AACA,QAAI,OAAO,OAAO;AAChB,UAAI,QAAQ,EAAE,GAAG,IAAI,OAAO,GAAG,OAAO,MAAM;AAAA,IAC9C;AACA,WAAO;AAAA,EACT,GAAG,CAAC,CAAgB;AACtB;","names":[]}
|
package/dist/experimental.d.mts
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
import { M as ModelConfigProvider, b as ThreadMessage } from './ModelConfigTypes-CzmXY3sn.mjs';
|
2
|
-
export { I as ImageContentPart, a as ToolCallContentPart, U as UIContentPart } from './ModelConfigTypes-CzmXY3sn.mjs';
|
3
|
-
import { ReactNode } from 'react';
|
4
|
-
import { U as Unsubscribe, T as ThreadState } from './Thread-UEVsUmvl.mjs';
|
5
|
-
import { UseBoundStore, StoreApi } from 'zustand';
|
6
|
-
import 'zod';
|
7
|
-
|
8
|
-
type AssistantModelConfigState = {
|
9
|
-
getModelConfig: ModelConfigProvider;
|
10
|
-
registerModelConfigProvider: (provider: ModelConfigProvider) => () => void;
|
11
|
-
};
|
12
|
-
|
13
|
-
type ContentPartState = Readonly<{
|
14
|
-
status: "in_progress" | "done" | "error";
|
15
|
-
part: ThreadMessage["content"][number];
|
16
|
-
}>;
|
17
|
-
|
18
|
-
type MessageState = Readonly<{
|
19
|
-
message: Readonly<ThreadMessage>;
|
20
|
-
parentId: string | null;
|
21
|
-
branches: readonly string[];
|
22
|
-
isLast: boolean;
|
23
|
-
inProgressIndicator: ReactNode | null;
|
24
|
-
setInProgressIndicator: (value: ReactNode | null) => void;
|
25
|
-
isCopied: boolean;
|
26
|
-
setIsCopied: (value: boolean) => void;
|
27
|
-
isHovering: boolean;
|
28
|
-
setIsHovering: (value: boolean) => void;
|
29
|
-
}>;
|
30
|
-
|
31
|
-
type BaseComposerState = Readonly<{
|
32
|
-
value: string;
|
33
|
-
setValue: (value: string) => void;
|
34
|
-
}>;
|
35
|
-
|
36
|
-
type EditComposerState = BaseComposerState & Readonly<{
|
37
|
-
isEditing: boolean;
|
38
|
-
edit: () => void;
|
39
|
-
send: () => void;
|
40
|
-
cancel: () => boolean;
|
41
|
-
}>;
|
42
|
-
|
43
|
-
type ComposerState = BaseComposerState & Readonly<{
|
44
|
-
isEditing: true;
|
45
|
-
send: () => void;
|
46
|
-
cancel: () => boolean;
|
47
|
-
}>;
|
48
|
-
|
49
|
-
type ThreadViewportState = {
|
50
|
-
isAtBottom: boolean;
|
51
|
-
scrollToBottom: () => void;
|
52
|
-
onScrollToBottom: (callback: () => void) => Unsubscribe;
|
53
|
-
};
|
54
|
-
|
55
|
-
type AssistantContextValue = {
|
56
|
-
useModelConfig: UseBoundStore<StoreApi<AssistantModelConfigState>>;
|
57
|
-
};
|
58
|
-
declare const useAssistantContext: () => AssistantContextValue;
|
59
|
-
|
60
|
-
type ThreadContextValue = {
|
61
|
-
useThread: UseBoundStore<StoreApi<ThreadState>>;
|
62
|
-
useComposer: UseBoundStore<StoreApi<ComposerState>>;
|
63
|
-
useViewport: UseBoundStore<StoreApi<ThreadViewportState>>;
|
64
|
-
};
|
65
|
-
declare const useThreadContext: () => ThreadContextValue;
|
66
|
-
|
67
|
-
type ComposerContextValue = {
|
68
|
-
useComposer: UseBoundStore<StoreApi<EditComposerState | ComposerState>>;
|
69
|
-
type: "edit" | "new";
|
70
|
-
};
|
71
|
-
declare const useComposerContext: () => ComposerContextValue;
|
72
|
-
|
73
|
-
type MessageContextValue = {
|
74
|
-
useMessage: UseBoundStore<StoreApi<MessageState>>;
|
75
|
-
useComposer: UseBoundStore<StoreApi<EditComposerState>>;
|
76
|
-
};
|
77
|
-
declare const useMessageContext: () => MessageContextValue;
|
78
|
-
|
79
|
-
type ContentPartContextValue = {
|
80
|
-
useContentPart: UseBoundStore<StoreApi<ContentPartState>>;
|
81
|
-
};
|
82
|
-
declare const useContentPartContext: () => ContentPartContextValue;
|
83
|
-
|
84
|
-
declare const useAssistantInstructions: (instruction: string) => void;
|
85
|
-
|
86
|
-
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 };
|
package/dist/experimental.d.ts
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
import { M as ModelConfigProvider, b as ThreadMessage } from './ModelConfigTypes-CzmXY3sn.js';
|
2
|
-
export { I as ImageContentPart, a as ToolCallContentPart, U as UIContentPart } from './ModelConfigTypes-CzmXY3sn.js';
|
3
|
-
import { ReactNode } from 'react';
|
4
|
-
import { U as Unsubscribe, T as ThreadState } from './Thread-BMASJT4a.js';
|
5
|
-
import { UseBoundStore, StoreApi } from 'zustand';
|
6
|
-
import 'zod';
|
7
|
-
|
8
|
-
type AssistantModelConfigState = {
|
9
|
-
getModelConfig: ModelConfigProvider;
|
10
|
-
registerModelConfigProvider: (provider: ModelConfigProvider) => () => void;
|
11
|
-
};
|
12
|
-
|
13
|
-
type ContentPartState = Readonly<{
|
14
|
-
status: "in_progress" | "done" | "error";
|
15
|
-
part: ThreadMessage["content"][number];
|
16
|
-
}>;
|
17
|
-
|
18
|
-
type MessageState = Readonly<{
|
19
|
-
message: Readonly<ThreadMessage>;
|
20
|
-
parentId: string | null;
|
21
|
-
branches: readonly string[];
|
22
|
-
isLast: boolean;
|
23
|
-
inProgressIndicator: ReactNode | null;
|
24
|
-
setInProgressIndicator: (value: ReactNode | null) => void;
|
25
|
-
isCopied: boolean;
|
26
|
-
setIsCopied: (value: boolean) => void;
|
27
|
-
isHovering: boolean;
|
28
|
-
setIsHovering: (value: boolean) => void;
|
29
|
-
}>;
|
30
|
-
|
31
|
-
type BaseComposerState = Readonly<{
|
32
|
-
value: string;
|
33
|
-
setValue: (value: string) => void;
|
34
|
-
}>;
|
35
|
-
|
36
|
-
type EditComposerState = BaseComposerState & Readonly<{
|
37
|
-
isEditing: boolean;
|
38
|
-
edit: () => void;
|
39
|
-
send: () => void;
|
40
|
-
cancel: () => boolean;
|
41
|
-
}>;
|
42
|
-
|
43
|
-
type ComposerState = BaseComposerState & Readonly<{
|
44
|
-
isEditing: true;
|
45
|
-
send: () => void;
|
46
|
-
cancel: () => boolean;
|
47
|
-
}>;
|
48
|
-
|
49
|
-
type ThreadViewportState = {
|
50
|
-
isAtBottom: boolean;
|
51
|
-
scrollToBottom: () => void;
|
52
|
-
onScrollToBottom: (callback: () => void) => Unsubscribe;
|
53
|
-
};
|
54
|
-
|
55
|
-
type AssistantContextValue = {
|
56
|
-
useModelConfig: UseBoundStore<StoreApi<AssistantModelConfigState>>;
|
57
|
-
};
|
58
|
-
declare const useAssistantContext: () => AssistantContextValue;
|
59
|
-
|
60
|
-
type ThreadContextValue = {
|
61
|
-
useThread: UseBoundStore<StoreApi<ThreadState>>;
|
62
|
-
useComposer: UseBoundStore<StoreApi<ComposerState>>;
|
63
|
-
useViewport: UseBoundStore<StoreApi<ThreadViewportState>>;
|
64
|
-
};
|
65
|
-
declare const useThreadContext: () => ThreadContextValue;
|
66
|
-
|
67
|
-
type ComposerContextValue = {
|
68
|
-
useComposer: UseBoundStore<StoreApi<EditComposerState | ComposerState>>;
|
69
|
-
type: "edit" | "new";
|
70
|
-
};
|
71
|
-
declare const useComposerContext: () => ComposerContextValue;
|
72
|
-
|
73
|
-
type MessageContextValue = {
|
74
|
-
useMessage: UseBoundStore<StoreApi<MessageState>>;
|
75
|
-
useComposer: UseBoundStore<StoreApi<EditComposerState>>;
|
76
|
-
};
|
77
|
-
declare const useMessageContext: () => MessageContextValue;
|
78
|
-
|
79
|
-
type ContentPartContextValue = {
|
80
|
-
useContentPart: UseBoundStore<StoreApi<ContentPartState>>;
|
81
|
-
};
|
82
|
-
declare const useContentPartContext: () => ContentPartContextValue;
|
83
|
-
|
84
|
-
declare const useAssistantInstructions: (instruction: string) => void;
|
85
|
-
|
86
|
-
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 };
|