@maintainer-pro/ai-ui 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai-ui.css +2 -0
- package/dist/ai-ui.iife.js +63 -0
- package/dist/ai-ui.iife.js.map +1 -0
- package/dist/index.cjs +2097 -0
- package/dist/index.d.cts +181 -0
- package/dist/index.d.ts +181 -0
- package/dist/index.js +2071 -0
- package/embed.d.ts +75 -0
- package/package.json +59 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { ClientContext, ToolCall, ChatUser } from '@maintainer-pro/ai-cli';
|
|
4
|
+
export { ChatAttachment, ChatSenderType, ChatUser, ClientContext, ToolCall } from '@maintainer-pro/ai-cli';
|
|
5
|
+
|
|
6
|
+
interface AiChatProps {
|
|
7
|
+
apiUrl?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Live client context for each turn. Defaults to browser route + page title
|
|
10
|
+
* via `buildBrowserClientContext()`.
|
|
11
|
+
*/
|
|
12
|
+
buildContext?: () => ClientContext;
|
|
13
|
+
onToolCalls?: (toolCalls: ToolCall[]) => void | Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Snapshot app state at the start of a turn so an interrupted turn can be
|
|
16
|
+
* reverted when the user sends another message mid-run.
|
|
17
|
+
*/
|
|
18
|
+
captureState?: () => unknown;
|
|
19
|
+
/** Restore a snapshot previously returned by captureState. */
|
|
20
|
+
restoreState?: (snapshot: unknown) => void;
|
|
21
|
+
conversationId?: string;
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated Ignored — sessions are shared via the server store.
|
|
24
|
+
* Kept so existing call sites keep type-checking.
|
|
25
|
+
*/
|
|
26
|
+
conversationStorageKey?: string;
|
|
27
|
+
title?: string;
|
|
28
|
+
emptyState?: ReactNode;
|
|
29
|
+
className?: string;
|
|
30
|
+
/**
|
|
31
|
+
* People in this chat. Prefer omitting this when Maintainer Pro is configured
|
|
32
|
+
* so accounts load from `/api/v1/client/chat-users` (roles included).
|
|
33
|
+
* Client messages go to the AI; developer messages are human replies only.
|
|
34
|
+
* Include `{ type: "ai", name }` to label AI replies for @mentions.
|
|
35
|
+
*/
|
|
36
|
+
users?: ChatUser[];
|
|
37
|
+
/**
|
|
38
|
+
* When set, chat history and users (if `users` omitted) load from Maintainer
|
|
39
|
+
* Pro using a client-scoped API key. AI turns still use `apiUrl`.
|
|
40
|
+
*/
|
|
41
|
+
maintainerProUrl?: string;
|
|
42
|
+
maintainerProApiKey?: string;
|
|
43
|
+
}
|
|
44
|
+
declare function AiChat({ apiUrl, buildContext, onToolCalls, captureState, restoreState, conversationId: conversationIdProp, title, emptyState, className, users, maintainerProUrl, maintainerProApiKey, }: AiChatProps): react.JSX.Element;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Chat panel open/closed state persisted in `localStorage`.
|
|
48
|
+
* Starts from `defaultOpen` on the server / first paint, then hydrates from storage.
|
|
49
|
+
*/
|
|
50
|
+
declare function usePersistedChatOpen(storageKey?: string, defaultOpen?: boolean): [boolean, (value: boolean | ((prev: boolean) => boolean)) => void];
|
|
51
|
+
|
|
52
|
+
type ChatUnreadSourceOptions = {
|
|
53
|
+
apiUrl?: string;
|
|
54
|
+
maintainerProUrl?: string;
|
|
55
|
+
maintainerProApiKey?: string;
|
|
56
|
+
conversationId?: string;
|
|
57
|
+
/** localStorage key for last-read watermark (default derived from conversation). */
|
|
58
|
+
storageKey?: string;
|
|
59
|
+
};
|
|
60
|
+
type StoredChatMessage = {
|
|
61
|
+
id?: string;
|
|
62
|
+
role: string;
|
|
63
|
+
content: string;
|
|
64
|
+
provider?: string | null;
|
|
65
|
+
senderType?: string | null;
|
|
66
|
+
senderName?: string | null;
|
|
67
|
+
createdAt?: string;
|
|
68
|
+
};
|
|
69
|
+
declare function rememberConversationId(baseUrl: string, apiKey: string, conversationId: string): void;
|
|
70
|
+
/** Full stored messages for live thread sync (messages endpoint only). */
|
|
71
|
+
declare function fetchChatMessages(options: ChatUnreadSourceOptions): Promise<StoredChatMessage[]>;
|
|
72
|
+
/**
|
|
73
|
+
* Lightweight timestamps for unread badges.
|
|
74
|
+
* Prefer conversation summaries (one call) when Maintainer Pro is configured.
|
|
75
|
+
*/
|
|
76
|
+
declare function fetchChatMessageTimestamps(options: ChatUnreadSourceOptions): Promise<string[]>;
|
|
77
|
+
declare function countUnreadSince(timestamps: string[], lastReadAt: string | null): number;
|
|
78
|
+
type ChatUnreadPoller = {
|
|
79
|
+
stop: () => void;
|
|
80
|
+
/** Refresh unread count immediately. */
|
|
81
|
+
refresh: () => Promise<void>;
|
|
82
|
+
/** Mark everything currently known as read. */
|
|
83
|
+
markRead: () => Promise<void>;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Poll for new chat messages while the panel is closed. First successful fetch
|
|
87
|
+
* seeds the read watermark so existing history is not treated as unread.
|
|
88
|
+
*/
|
|
89
|
+
declare function startChatUnreadPoller(options: ChatUnreadSourceOptions & {
|
|
90
|
+
isOpen: () => boolean;
|
|
91
|
+
onChange: (unreadCount: number) => void;
|
|
92
|
+
pollIntervalMs?: number;
|
|
93
|
+
}): ChatUnreadPoller;
|
|
94
|
+
|
|
95
|
+
type UseChatUnreadOptions = ChatUnreadSourceOptions & {
|
|
96
|
+
/** When true, unread clears and new messages while open are marked read. */
|
|
97
|
+
chatOpen: boolean;
|
|
98
|
+
pollIntervalMs?: number;
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Tracks unread chat messages for a closed FAB / drawer.
|
|
102
|
+
* Polls Maintainer Pro (or `/api/chat`) while the panel is closed.
|
|
103
|
+
*/
|
|
104
|
+
declare function useChatUnread(options: UseChatUnreadOptions): {
|
|
105
|
+
unreadCount: number;
|
|
106
|
+
hasUnread: boolean;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
type BuildClientContextInput = {
|
|
110
|
+
route?: string;
|
|
111
|
+
pageTitle?: string;
|
|
112
|
+
visiblePanels?: string[];
|
|
113
|
+
relevantFiles?: string[];
|
|
114
|
+
data?: Record<string, unknown>;
|
|
115
|
+
};
|
|
116
|
+
/** Helper to assemble a ClientContext from browser + host data. */
|
|
117
|
+
declare function buildBrowserClientContext(input?: BuildClientContextInput): ClientContext;
|
|
118
|
+
declare function useClientContextBuilder(getInput: () => BuildClientContextInput): () => ClientContext;
|
|
119
|
+
|
|
120
|
+
type MaintainerProClientOptions = {
|
|
121
|
+
baseUrl: string;
|
|
122
|
+
apiKey: string;
|
|
123
|
+
fetchImpl?: typeof fetch;
|
|
124
|
+
};
|
|
125
|
+
type MaintainerProApplication = {
|
|
126
|
+
id: string;
|
|
127
|
+
name: string;
|
|
128
|
+
clientId: string;
|
|
129
|
+
clientName: string;
|
|
130
|
+
/** @deprecated Use clientId */
|
|
131
|
+
companyId?: string;
|
|
132
|
+
/** @deprecated Use clientName */
|
|
133
|
+
companyName?: string;
|
|
134
|
+
partnerId: string;
|
|
135
|
+
sandboxId?: string;
|
|
136
|
+
sandboxName?: string;
|
|
137
|
+
};
|
|
138
|
+
type MaintainerProStoredMessage = {
|
|
139
|
+
id: string;
|
|
140
|
+
conversationId: string;
|
|
141
|
+
role: string;
|
|
142
|
+
content: string;
|
|
143
|
+
provider?: string | null;
|
|
144
|
+
senderType?: string | null;
|
|
145
|
+
senderName?: string | null;
|
|
146
|
+
createdAt?: string;
|
|
147
|
+
attachmentPaths?: string[];
|
|
148
|
+
attachmentIds?: string[];
|
|
149
|
+
};
|
|
150
|
+
type MaintainerProConversationSummary = {
|
|
151
|
+
id: string;
|
|
152
|
+
updatedAt: string;
|
|
153
|
+
messages: Array<{
|
|
154
|
+
role: string;
|
|
155
|
+
content: string;
|
|
156
|
+
createdAt?: string;
|
|
157
|
+
}>;
|
|
158
|
+
};
|
|
159
|
+
type MaintainerProChatUser = {
|
|
160
|
+
name: string;
|
|
161
|
+
type: "client" | "developer" | "ai";
|
|
162
|
+
default?: boolean;
|
|
163
|
+
email?: string;
|
|
164
|
+
role?: string;
|
|
165
|
+
};
|
|
166
|
+
declare function createMaintainerProClient(options: MaintainerProClientOptions): {
|
|
167
|
+
getApplication(): Promise<MaintainerProApplication>;
|
|
168
|
+
listConversations(): Promise<MaintainerProConversationSummary[]>;
|
|
169
|
+
listChatUsers(): Promise<MaintainerProChatUser[]>;
|
|
170
|
+
loginChatUser(email: string, password: string): Promise<{
|
|
171
|
+
name: string;
|
|
172
|
+
email: string;
|
|
173
|
+
type: "client" | "developer";
|
|
174
|
+
role?: string;
|
|
175
|
+
}>;
|
|
176
|
+
listMessages(conversationId: string): Promise<MaintainerProStoredMessage[]>;
|
|
177
|
+
attachmentUrl(attachmentId: string): string;
|
|
178
|
+
};
|
|
179
|
+
type MaintainerProClient = ReturnType<typeof createMaintainerProClient>;
|
|
180
|
+
|
|
181
|
+
export { AiChat, type AiChatProps, type BuildClientContextInput, type ChatUnreadPoller, type ChatUnreadSourceOptions, type MaintainerProApplication, type MaintainerProChatUser, type MaintainerProClient, type MaintainerProClientOptions, type MaintainerProConversationSummary, type MaintainerProStoredMessage, type StoredChatMessage, type UseChatUnreadOptions, buildBrowserClientContext, countUnreadSince, createMaintainerProClient, fetchChatMessageTimestamps, fetchChatMessages, rememberConversationId, startChatUnreadPoller, useChatUnread, useClientContextBuilder, usePersistedChatOpen };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { ClientContext, ToolCall, ChatUser } from '@maintainer-pro/ai-cli';
|
|
4
|
+
export { ChatAttachment, ChatSenderType, ChatUser, ClientContext, ToolCall } from '@maintainer-pro/ai-cli';
|
|
5
|
+
|
|
6
|
+
interface AiChatProps {
|
|
7
|
+
apiUrl?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Live client context for each turn. Defaults to browser route + page title
|
|
10
|
+
* via `buildBrowserClientContext()`.
|
|
11
|
+
*/
|
|
12
|
+
buildContext?: () => ClientContext;
|
|
13
|
+
onToolCalls?: (toolCalls: ToolCall[]) => void | Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Snapshot app state at the start of a turn so an interrupted turn can be
|
|
16
|
+
* reverted when the user sends another message mid-run.
|
|
17
|
+
*/
|
|
18
|
+
captureState?: () => unknown;
|
|
19
|
+
/** Restore a snapshot previously returned by captureState. */
|
|
20
|
+
restoreState?: (snapshot: unknown) => void;
|
|
21
|
+
conversationId?: string;
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated Ignored — sessions are shared via the server store.
|
|
24
|
+
* Kept so existing call sites keep type-checking.
|
|
25
|
+
*/
|
|
26
|
+
conversationStorageKey?: string;
|
|
27
|
+
title?: string;
|
|
28
|
+
emptyState?: ReactNode;
|
|
29
|
+
className?: string;
|
|
30
|
+
/**
|
|
31
|
+
* People in this chat. Prefer omitting this when Maintainer Pro is configured
|
|
32
|
+
* so accounts load from `/api/v1/client/chat-users` (roles included).
|
|
33
|
+
* Client messages go to the AI; developer messages are human replies only.
|
|
34
|
+
* Include `{ type: "ai", name }` to label AI replies for @mentions.
|
|
35
|
+
*/
|
|
36
|
+
users?: ChatUser[];
|
|
37
|
+
/**
|
|
38
|
+
* When set, chat history and users (if `users` omitted) load from Maintainer
|
|
39
|
+
* Pro using a client-scoped API key. AI turns still use `apiUrl`.
|
|
40
|
+
*/
|
|
41
|
+
maintainerProUrl?: string;
|
|
42
|
+
maintainerProApiKey?: string;
|
|
43
|
+
}
|
|
44
|
+
declare function AiChat({ apiUrl, buildContext, onToolCalls, captureState, restoreState, conversationId: conversationIdProp, title, emptyState, className, users, maintainerProUrl, maintainerProApiKey, }: AiChatProps): react.JSX.Element;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Chat panel open/closed state persisted in `localStorage`.
|
|
48
|
+
* Starts from `defaultOpen` on the server / first paint, then hydrates from storage.
|
|
49
|
+
*/
|
|
50
|
+
declare function usePersistedChatOpen(storageKey?: string, defaultOpen?: boolean): [boolean, (value: boolean | ((prev: boolean) => boolean)) => void];
|
|
51
|
+
|
|
52
|
+
type ChatUnreadSourceOptions = {
|
|
53
|
+
apiUrl?: string;
|
|
54
|
+
maintainerProUrl?: string;
|
|
55
|
+
maintainerProApiKey?: string;
|
|
56
|
+
conversationId?: string;
|
|
57
|
+
/** localStorage key for last-read watermark (default derived from conversation). */
|
|
58
|
+
storageKey?: string;
|
|
59
|
+
};
|
|
60
|
+
type StoredChatMessage = {
|
|
61
|
+
id?: string;
|
|
62
|
+
role: string;
|
|
63
|
+
content: string;
|
|
64
|
+
provider?: string | null;
|
|
65
|
+
senderType?: string | null;
|
|
66
|
+
senderName?: string | null;
|
|
67
|
+
createdAt?: string;
|
|
68
|
+
};
|
|
69
|
+
declare function rememberConversationId(baseUrl: string, apiKey: string, conversationId: string): void;
|
|
70
|
+
/** Full stored messages for live thread sync (messages endpoint only). */
|
|
71
|
+
declare function fetchChatMessages(options: ChatUnreadSourceOptions): Promise<StoredChatMessage[]>;
|
|
72
|
+
/**
|
|
73
|
+
* Lightweight timestamps for unread badges.
|
|
74
|
+
* Prefer conversation summaries (one call) when Maintainer Pro is configured.
|
|
75
|
+
*/
|
|
76
|
+
declare function fetchChatMessageTimestamps(options: ChatUnreadSourceOptions): Promise<string[]>;
|
|
77
|
+
declare function countUnreadSince(timestamps: string[], lastReadAt: string | null): number;
|
|
78
|
+
type ChatUnreadPoller = {
|
|
79
|
+
stop: () => void;
|
|
80
|
+
/** Refresh unread count immediately. */
|
|
81
|
+
refresh: () => Promise<void>;
|
|
82
|
+
/** Mark everything currently known as read. */
|
|
83
|
+
markRead: () => Promise<void>;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Poll for new chat messages while the panel is closed. First successful fetch
|
|
87
|
+
* seeds the read watermark so existing history is not treated as unread.
|
|
88
|
+
*/
|
|
89
|
+
declare function startChatUnreadPoller(options: ChatUnreadSourceOptions & {
|
|
90
|
+
isOpen: () => boolean;
|
|
91
|
+
onChange: (unreadCount: number) => void;
|
|
92
|
+
pollIntervalMs?: number;
|
|
93
|
+
}): ChatUnreadPoller;
|
|
94
|
+
|
|
95
|
+
type UseChatUnreadOptions = ChatUnreadSourceOptions & {
|
|
96
|
+
/** When true, unread clears and new messages while open are marked read. */
|
|
97
|
+
chatOpen: boolean;
|
|
98
|
+
pollIntervalMs?: number;
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Tracks unread chat messages for a closed FAB / drawer.
|
|
102
|
+
* Polls Maintainer Pro (or `/api/chat`) while the panel is closed.
|
|
103
|
+
*/
|
|
104
|
+
declare function useChatUnread(options: UseChatUnreadOptions): {
|
|
105
|
+
unreadCount: number;
|
|
106
|
+
hasUnread: boolean;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
type BuildClientContextInput = {
|
|
110
|
+
route?: string;
|
|
111
|
+
pageTitle?: string;
|
|
112
|
+
visiblePanels?: string[];
|
|
113
|
+
relevantFiles?: string[];
|
|
114
|
+
data?: Record<string, unknown>;
|
|
115
|
+
};
|
|
116
|
+
/** Helper to assemble a ClientContext from browser + host data. */
|
|
117
|
+
declare function buildBrowserClientContext(input?: BuildClientContextInput): ClientContext;
|
|
118
|
+
declare function useClientContextBuilder(getInput: () => BuildClientContextInput): () => ClientContext;
|
|
119
|
+
|
|
120
|
+
type MaintainerProClientOptions = {
|
|
121
|
+
baseUrl: string;
|
|
122
|
+
apiKey: string;
|
|
123
|
+
fetchImpl?: typeof fetch;
|
|
124
|
+
};
|
|
125
|
+
type MaintainerProApplication = {
|
|
126
|
+
id: string;
|
|
127
|
+
name: string;
|
|
128
|
+
clientId: string;
|
|
129
|
+
clientName: string;
|
|
130
|
+
/** @deprecated Use clientId */
|
|
131
|
+
companyId?: string;
|
|
132
|
+
/** @deprecated Use clientName */
|
|
133
|
+
companyName?: string;
|
|
134
|
+
partnerId: string;
|
|
135
|
+
sandboxId?: string;
|
|
136
|
+
sandboxName?: string;
|
|
137
|
+
};
|
|
138
|
+
type MaintainerProStoredMessage = {
|
|
139
|
+
id: string;
|
|
140
|
+
conversationId: string;
|
|
141
|
+
role: string;
|
|
142
|
+
content: string;
|
|
143
|
+
provider?: string | null;
|
|
144
|
+
senderType?: string | null;
|
|
145
|
+
senderName?: string | null;
|
|
146
|
+
createdAt?: string;
|
|
147
|
+
attachmentPaths?: string[];
|
|
148
|
+
attachmentIds?: string[];
|
|
149
|
+
};
|
|
150
|
+
type MaintainerProConversationSummary = {
|
|
151
|
+
id: string;
|
|
152
|
+
updatedAt: string;
|
|
153
|
+
messages: Array<{
|
|
154
|
+
role: string;
|
|
155
|
+
content: string;
|
|
156
|
+
createdAt?: string;
|
|
157
|
+
}>;
|
|
158
|
+
};
|
|
159
|
+
type MaintainerProChatUser = {
|
|
160
|
+
name: string;
|
|
161
|
+
type: "client" | "developer" | "ai";
|
|
162
|
+
default?: boolean;
|
|
163
|
+
email?: string;
|
|
164
|
+
role?: string;
|
|
165
|
+
};
|
|
166
|
+
declare function createMaintainerProClient(options: MaintainerProClientOptions): {
|
|
167
|
+
getApplication(): Promise<MaintainerProApplication>;
|
|
168
|
+
listConversations(): Promise<MaintainerProConversationSummary[]>;
|
|
169
|
+
listChatUsers(): Promise<MaintainerProChatUser[]>;
|
|
170
|
+
loginChatUser(email: string, password: string): Promise<{
|
|
171
|
+
name: string;
|
|
172
|
+
email: string;
|
|
173
|
+
type: "client" | "developer";
|
|
174
|
+
role?: string;
|
|
175
|
+
}>;
|
|
176
|
+
listMessages(conversationId: string): Promise<MaintainerProStoredMessage[]>;
|
|
177
|
+
attachmentUrl(attachmentId: string): string;
|
|
178
|
+
};
|
|
179
|
+
type MaintainerProClient = ReturnType<typeof createMaintainerProClient>;
|
|
180
|
+
|
|
181
|
+
export { AiChat, type AiChatProps, type BuildClientContextInput, type ChatUnreadPoller, type ChatUnreadSourceOptions, type MaintainerProApplication, type MaintainerProChatUser, type MaintainerProClient, type MaintainerProClientOptions, type MaintainerProConversationSummary, type MaintainerProStoredMessage, type StoredChatMessage, type UseChatUnreadOptions, buildBrowserClientContext, countUnreadSince, createMaintainerProClient, fetchChatMessageTimestamps, fetchChatMessages, rememberConversationId, startChatUnreadPoller, useChatUnread, useClientContextBuilder, usePersistedChatOpen };
|