@applica-software-guru/persona-sdk 0.0.1-preview0
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/.eslintrc.cjs +11 -0
- package/.nvmrc +1 -0
- package/.prettierignore +5 -0
- package/.prettierrc +8 -0
- package/README.md +66 -0
- package/bitbucket-pipelines.yml +29 -0
- package/dist/bundle.cjs.js +27 -0
- package/dist/bundle.cjs.js.map +1 -0
- package/dist/bundle.es.js +6585 -0
- package/dist/bundle.es.js.map +1 -0
- package/dist/bundle.iife.js +27 -0
- package/dist/bundle.iife.js.map +1 -0
- package/dist/bundle.umd.js +27 -0
- package/dist/bundle.umd.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/logging.d.ts +18 -0
- package/dist/logging.d.ts.map +1 -0
- package/dist/messages.d.ts +7 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/protocol/base.d.ts +23 -0
- package/dist/protocol/base.d.ts.map +1 -0
- package/dist/protocol/index.d.ts +5 -0
- package/dist/protocol/index.d.ts.map +1 -0
- package/dist/protocol/rest.d.ts +22 -0
- package/dist/protocol/rest.d.ts.map +1 -0
- package/dist/protocol/webrtc.d.ts +56 -0
- package/dist/protocol/webrtc.d.ts.map +1 -0
- package/dist/protocol/websocket.d.ts +22 -0
- package/dist/protocol/websocket.d.ts.map +1 -0
- package/dist/runtime.d.ts +21 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/types.d.ts +79 -0
- package/dist/types.d.ts.map +1 -0
- package/jsconfig.node.json +10 -0
- package/package.json +72 -0
- package/playground/index.html +14 -0
- package/playground/src/app.tsx +10 -0
- package/playground/src/chat.tsx +52 -0
- package/playground/src/components/assistant-ui/assistant-modal.tsx +57 -0
- package/playground/src/components/assistant-ui/markdown-text.tsx +119 -0
- package/playground/src/components/assistant-ui/thread-list.tsx +62 -0
- package/playground/src/components/assistant-ui/thread.tsx +249 -0
- package/playground/src/components/assistant-ui/tool-fallback.tsx +33 -0
- package/playground/src/components/assistant-ui/tooltip-icon-button.tsx +38 -0
- package/playground/src/components/ui/avatar.tsx +35 -0
- package/playground/src/components/ui/button.tsx +43 -0
- package/playground/src/components/ui/tooltip.tsx +32 -0
- package/playground/src/lib/utils.ts +6 -0
- package/playground/src/main.tsx +10 -0
- package/playground/src/styles.css +1 -0
- package/playground/src/vite-env.d.ts +1 -0
- package/preview.sh +13 -0
- package/src/index.ts +4 -0
- package/src/logging.ts +34 -0
- package/src/messages.ts +79 -0
- package/src/protocol/base.ts +55 -0
- package/src/protocol/index.ts +4 -0
- package/src/protocol/rest.ts +64 -0
- package/src/protocol/webrtc.ts +337 -0
- package/src/protocol/websocket.ts +106 -0
- package/src/runtime.tsx +214 -0
- package/src/types.ts +98 -0
- package/tsconfig.json +36 -0
- package/tsconfig.node.json +15 -0
- package/vite.config.ts +69 -0
package/src/runtime.tsx
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { useState, useEffect, useCallback, PropsWithChildren, createContext, useContext, useMemo, useRef } from 'react';
|
|
2
|
+
import { useExternalStoreRuntime, AppendMessage, AssistantRuntimeProvider } from '@assistant-ui/react';
|
|
3
|
+
import {
|
|
4
|
+
PersonaConfig,
|
|
5
|
+
PersonaMessage,
|
|
6
|
+
PersonaProtocol,
|
|
7
|
+
PersonaProtocolBaseConfig,
|
|
8
|
+
PersonaResponse,
|
|
9
|
+
ProtocolStatus,
|
|
10
|
+
Session,
|
|
11
|
+
} from './types';
|
|
12
|
+
import { parseMessages, convertMessage } from './messages';
|
|
13
|
+
import {
|
|
14
|
+
PersonaRESTProtocol,
|
|
15
|
+
PersonaRESTProtocolConfig,
|
|
16
|
+
PersonaWebRTCProtocol,
|
|
17
|
+
PersonaWebRTCProtocolConfig,
|
|
18
|
+
PersonaWebSocketProtocol,
|
|
19
|
+
PersonaWebSocketProtocolConfig,
|
|
20
|
+
} from './protocol';
|
|
21
|
+
|
|
22
|
+
type PersonaRuntimeContextType = {
|
|
23
|
+
protocols: PersonaProtocol[];
|
|
24
|
+
protocolsStatus: Map<string, ProtocolStatus>;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const PersonaRuntimeContext = createContext<PersonaRuntimeContextType | undefined>(undefined);
|
|
28
|
+
|
|
29
|
+
function PersonaRuntimeProviderInner({
|
|
30
|
+
dev = false,
|
|
31
|
+
protocols: _protocols,
|
|
32
|
+
logger,
|
|
33
|
+
children,
|
|
34
|
+
session: defaultSession = 'new',
|
|
35
|
+
...config
|
|
36
|
+
}: Readonly<PersonaConfig>) {
|
|
37
|
+
const [isRunning, setIsRunning] = useState(false);
|
|
38
|
+
const [messages, setMessages] = useState<PersonaMessage[]>([]);
|
|
39
|
+
const [session, setSession] = useState<Session>(defaultSession);
|
|
40
|
+
const [protocolsStatus, setProtocolsStatus] = useState<Map<string, ProtocolStatus>>(new Map());
|
|
41
|
+
const didMount = useRef(false);
|
|
42
|
+
|
|
43
|
+
const protocols = useMemo<PersonaProtocol[]>(() => {
|
|
44
|
+
if (Array.isArray(_protocols)) {
|
|
45
|
+
return _protocols;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (typeof _protocols === 'object' && _protocols !== null) {
|
|
49
|
+
const baseEndpoint = dev ? 'localhost:8000' : 'persona.applica.guru/api';
|
|
50
|
+
const baseEndpointProtocol = dev ? 'http' : 'https';
|
|
51
|
+
const baseWebSocketProtocol = dev ? 'ws' : 'wss';
|
|
52
|
+
const availableProtocols = Object.keys(_protocols).map((key) => {
|
|
53
|
+
switch (key) {
|
|
54
|
+
case 'rest':
|
|
55
|
+
const restConfig: PersonaProtocolBaseConfig | true | undefined = _protocols[key];
|
|
56
|
+
if (restConfig === true) {
|
|
57
|
+
return new PersonaRESTProtocol({
|
|
58
|
+
apiUrl: `${baseEndpointProtocol}://${baseEndpoint}`,
|
|
59
|
+
apiKey: config.apiKey,
|
|
60
|
+
agentId: config.agentId,
|
|
61
|
+
logger,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return new PersonaRESTProtocol(restConfig as PersonaRESTProtocolConfig);
|
|
65
|
+
case 'webrtc':
|
|
66
|
+
const webrtcConfig: PersonaProtocolBaseConfig | true | undefined = _protocols[key];
|
|
67
|
+
if (webrtcConfig === true) {
|
|
68
|
+
return new PersonaWebRTCProtocol({
|
|
69
|
+
webrtcUrl: `${baseWebSocketProtocol}://${baseEndpoint}/webrtc`,
|
|
70
|
+
apiKey: config.apiKey,
|
|
71
|
+
agentId: config.agentId,
|
|
72
|
+
logger,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return new PersonaWebRTCProtocol(webrtcConfig as PersonaWebRTCProtocolConfig);
|
|
76
|
+
case 'websocket':
|
|
77
|
+
const websocketConfig: PersonaProtocolBaseConfig | true | undefined = _protocols[key];
|
|
78
|
+
if (websocketConfig === true) {
|
|
79
|
+
return new PersonaWebSocketProtocol({
|
|
80
|
+
webSocketUrl: `${baseWebSocketProtocol}://${baseEndpoint}/websocket`,
|
|
81
|
+
apiKey: config.apiKey,
|
|
82
|
+
agentId: config.agentId,
|
|
83
|
+
logger,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return new PersonaWebSocketProtocol(websocketConfig as PersonaWebSocketProtocolConfig);
|
|
87
|
+
default:
|
|
88
|
+
throw new Error(`Unknown protocol: ${key}`);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
return availableProtocols;
|
|
92
|
+
}
|
|
93
|
+
throw new Error('Invalid protocols configuration');
|
|
94
|
+
}, []);
|
|
95
|
+
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
if (didMount.current) return;
|
|
98
|
+
|
|
99
|
+
didMount.current = true;
|
|
100
|
+
logger?.debug(
|
|
101
|
+
'Initializing protocols: ',
|
|
102
|
+
protocols.map((protocol) => protocol.getName()),
|
|
103
|
+
);
|
|
104
|
+
protocols.forEach((protocol) => {
|
|
105
|
+
protocol.setSession(session);
|
|
106
|
+
protocol.clearListeners();
|
|
107
|
+
protocol.addStatusChangeListener((status: ProtocolStatus) => {
|
|
108
|
+
logger?.debug(`${protocol.getName()} has notified new status: ${status}`);
|
|
109
|
+
protocolsStatus.set(protocol.getName(), status);
|
|
110
|
+
setProtocolsStatus(new Map(protocolsStatus));
|
|
111
|
+
});
|
|
112
|
+
protocol.addMessageListener((message: PersonaMessage) => {
|
|
113
|
+
setMessages((currentConversation) => parseMessages([...currentConversation, ...[{ ...message, protocol: protocol.getName() }]]));
|
|
114
|
+
});
|
|
115
|
+
if (protocol.autostart && protocol.status === 'disconnected') {
|
|
116
|
+
logger?.debug(`Connecting to protocol: ${protocol.getName()}`);
|
|
117
|
+
protocol.connect(session);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}, [session, protocols, logger, protocolsStatus]);
|
|
121
|
+
|
|
122
|
+
const onNew = async (message: AppendMessage) => {
|
|
123
|
+
if (message.content[0]?.type !== 'text') throw new Error('Only text messages are supported');
|
|
124
|
+
|
|
125
|
+
const input = message.content[0].text;
|
|
126
|
+
setMessages((currentConversation) => [...currentConversation, { role: 'user', type: 'text', text: input }]);
|
|
127
|
+
setIsRunning(true);
|
|
128
|
+
|
|
129
|
+
const protocol = protocols.sort((a, b) => b.getPriority() - a.getPriority()).find((protocol) => protocol.status === 'connected');
|
|
130
|
+
|
|
131
|
+
await protocol?.send(input);
|
|
132
|
+
|
|
133
|
+
setIsRunning(false);
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const onCancel = useCallback(() => {
|
|
137
|
+
setIsRunning(false);
|
|
138
|
+
setMessages([]);
|
|
139
|
+
setSession('new');
|
|
140
|
+
return Promise.resolve();
|
|
141
|
+
}, []);
|
|
142
|
+
|
|
143
|
+
const onReload = useCallback(() => {
|
|
144
|
+
return Promise.resolve();
|
|
145
|
+
}, []);
|
|
146
|
+
|
|
147
|
+
const runtime = useExternalStoreRuntime({
|
|
148
|
+
isRunning,
|
|
149
|
+
messages,
|
|
150
|
+
convertMessage,
|
|
151
|
+
onNew,
|
|
152
|
+
onCancel,
|
|
153
|
+
onReload,
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
return (
|
|
157
|
+
<PersonaRuntimeContext.Provider value={{ protocols, protocolsStatus }}>
|
|
158
|
+
<AssistantRuntimeProvider runtime={runtime}>{children}</AssistantRuntimeProvider>
|
|
159
|
+
</PersonaRuntimeContext.Provider>
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function PersonaRuntimeProvider({ children, ...config }: PropsWithChildren<PersonaConfig>) {
|
|
164
|
+
return <PersonaRuntimeProviderInner {...config}>{children}</PersonaRuntimeProviderInner>;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function usePersonaRuntime(): PersonaRuntimeContextType {
|
|
168
|
+
const context = useContext(PersonaRuntimeContext);
|
|
169
|
+
if (!context) {
|
|
170
|
+
throw new Error('usePersonaRuntime must be used within a PersonaRuntimeProvider');
|
|
171
|
+
}
|
|
172
|
+
return context;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Retrieves a specific protocol instance from the PersonaRuntimeContext.
|
|
177
|
+
*
|
|
178
|
+
* @param protocol - The name of the protocol to use.
|
|
179
|
+
* @returns {PersonaProtocol | null} - The protocol instance or null if not found.
|
|
180
|
+
* @throws {Error} - If the hook is used outside of a PersonaRuntimeProvider.
|
|
181
|
+
*/
|
|
182
|
+
function usePersonaRuntimeProtocol(protocol: string): PersonaProtocol | null {
|
|
183
|
+
const context = useContext(PersonaRuntimeContext);
|
|
184
|
+
if (!context) {
|
|
185
|
+
throw new Error('usePersonaRuntimeProtocol must be used within a PersonaRuntimeProvider');
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const protocolInstance = context.protocols.find((p) => p.getName() === protocol);
|
|
189
|
+
if (!protocolInstance) {
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const status = context.protocolsStatus.get(protocolInstance.getName());
|
|
194
|
+
|
|
195
|
+
return {
|
|
196
|
+
...protocolInstance,
|
|
197
|
+
connect: protocolInstance.connect.bind(protocolInstance),
|
|
198
|
+
disconnect: protocolInstance.disconnect.bind(protocolInstance),
|
|
199
|
+
send: protocolInstance.send.bind(protocolInstance),
|
|
200
|
+
setSession: protocolInstance.setSession.bind(protocolInstance),
|
|
201
|
+
addStatusChangeListener: protocolInstance.addStatusChangeListener.bind(protocolInstance),
|
|
202
|
+
addMessageListener: protocolInstance.addMessageListener.bind(protocolInstance),
|
|
203
|
+
getName: protocolInstance.getName.bind(protocolInstance),
|
|
204
|
+
getPriority: protocolInstance.getPriority.bind(protocolInstance),
|
|
205
|
+
status: status || protocolInstance.status,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function usePersonaRuntimeWebRTCProtocol(): PersonaWebRTCProtocol | null {
|
|
210
|
+
return usePersonaRuntimeProtocol('webrtc') as PersonaWebRTCProtocol;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export { PersonaRuntimeProvider, usePersonaRuntime, usePersonaRuntimeProtocol, usePersonaRuntimeWebRTCProtocol };
|
|
214
|
+
export type { PersonaMessage, PersonaResponse };
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { PersonaLogger } from './logging';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
export type ReadonlyJSONObject = {
|
|
5
|
+
readonly [key: string]: string | number | boolean | null | ReadonlyJSONObject | ReadonlyArray<ReadonlyJSONObject>;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type FunctionCall = {
|
|
9
|
+
id?: string;
|
|
10
|
+
name: string;
|
|
11
|
+
args: ReadonlyJSONObject;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type FunctionResponse = {
|
|
15
|
+
name: string;
|
|
16
|
+
result: unknown;
|
|
17
|
+
function_call_id: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type PersonaMessage = {
|
|
21
|
+
id?: string | null;
|
|
22
|
+
protocol?: string;
|
|
23
|
+
text: string;
|
|
24
|
+
type: 'reasoning' | 'text';
|
|
25
|
+
role: 'user' | 'assistant' | 'function';
|
|
26
|
+
sessionId?: string;
|
|
27
|
+
finishReason?: 'stop' | 'function_call';
|
|
28
|
+
functionCalls?: FunctionCall[];
|
|
29
|
+
functionResponse?: FunctionResponse;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type ModelResponse = {
|
|
33
|
+
messages: PersonaMessage[];
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type PersonaResponse = {
|
|
37
|
+
sessionId: string;
|
|
38
|
+
response: ModelResponse;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export type PersonaBaseConfig = {
|
|
42
|
+
logger?: PersonaLogger;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export type PersonaWebRTCConfig = PersonaBaseConfig & {
|
|
46
|
+
webrtcUrl: string;
|
|
47
|
+
iceServers?: RTCIceServer[];
|
|
48
|
+
onDataMessage?: (msg: MessageEvent) => void;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export type Session = string | null | undefined;
|
|
52
|
+
export type Message = string;
|
|
53
|
+
|
|
54
|
+
export type MessageListenerCallback = (message: PersonaMessage) => void;
|
|
55
|
+
export type StatusChangeCallback = (status: ProtocolStatus) => void;
|
|
56
|
+
|
|
57
|
+
export type ProtocolStatus = 'disconnected' | 'connecting' | 'connected';
|
|
58
|
+
|
|
59
|
+
export type PersonaProtocolBaseConfig = {
|
|
60
|
+
logger?: PersonaLogger;
|
|
61
|
+
apiKey: string;
|
|
62
|
+
agentId: string;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export interface PersonaProtocol {
|
|
66
|
+
status: ProtocolStatus;
|
|
67
|
+
autostart: boolean;
|
|
68
|
+
|
|
69
|
+
getName: () => string;
|
|
70
|
+
getPriority: () => number;
|
|
71
|
+
connect: (session?: Session) => Promise<Session>;
|
|
72
|
+
disconnect: () => Promise<void>;
|
|
73
|
+
|
|
74
|
+
setSession: (session: Session) => Promise<void>;
|
|
75
|
+
|
|
76
|
+
send: (message: Message) => Promise<void>;
|
|
77
|
+
clearListeners: () => void;
|
|
78
|
+
addStatusChangeListener: (callback: StatusChangeCallback) => void;
|
|
79
|
+
addMessageListener: (callback: MessageListenerCallback) => void;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export type PersonaConfig = PersonaBaseConfig &
|
|
83
|
+
PersonaProtocolBaseConfig & {
|
|
84
|
+
/**
|
|
85
|
+
* In 'dev' mode the endpoint is set to localhost:8000,
|
|
86
|
+
* use it only for development purposes.
|
|
87
|
+
*/
|
|
88
|
+
dev?: boolean;
|
|
89
|
+
session?: Session;
|
|
90
|
+
children: ReactNode;
|
|
91
|
+
protocols:
|
|
92
|
+
| PersonaProtocol[]
|
|
93
|
+
| {
|
|
94
|
+
rest?: PersonaProtocolBaseConfig | true;
|
|
95
|
+
webrtc?: PersonaProtocolBaseConfig | true;
|
|
96
|
+
websocket?: PersonaProtocolBaseConfig | true;
|
|
97
|
+
};
|
|
98
|
+
};
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"allowJs": true,
|
|
4
|
+
"allowSyntheticDefaultImports": true,
|
|
5
|
+
"baseUrl": ".",
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"declarationMap": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"forceConsistentCasingInFileNames": true,
|
|
10
|
+
"isolatedModules": true,
|
|
11
|
+
"jsx": "react-jsx",
|
|
12
|
+
"lib": ["DOM", "DOM.Iterable", "ESNext"],
|
|
13
|
+
"module": "ESNext",
|
|
14
|
+
"moduleResolution": "Node",
|
|
15
|
+
"noEmit": false,
|
|
16
|
+
"noUnusedLocals": true,
|
|
17
|
+
"noUnusedParameters": true,
|
|
18
|
+
"outDir": "dist",
|
|
19
|
+
"paths": {
|
|
20
|
+
"@/*": ["playground/src/*"],
|
|
21
|
+
"@applica-software-guru/persona-sdk": ["src/index.ts"]
|
|
22
|
+
},
|
|
23
|
+
"resolveJsonModule": true,
|
|
24
|
+
"skipLibCheck": true,
|
|
25
|
+
"strict": true,
|
|
26
|
+
"target": "ESNext",
|
|
27
|
+
"typeRoots": ["node_modules/@types", "src/assets.d.ts", "src/index.d.ts", "src/types.d.ts"],
|
|
28
|
+
"useDefineForClassFields": true
|
|
29
|
+
},
|
|
30
|
+
"include": ["src", "playground/src"],
|
|
31
|
+
"references": [
|
|
32
|
+
{
|
|
33
|
+
"path": "./jsconfig.node.json"
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"allowJs": true,
|
|
4
|
+
"allowSyntheticDefaultImports": true,
|
|
5
|
+
"composite": true,
|
|
6
|
+
"jsx": "react-jsx",
|
|
7
|
+
"module": "ESNext",
|
|
8
|
+
"moduleResolution": "bundler",
|
|
9
|
+
"resolveJsonModule": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"strict": true,
|
|
12
|
+
"target": "ES6"
|
|
13
|
+
},
|
|
14
|
+
"include": ["vite.config.ts", "package.json", "playground/src", "src/**/*"]
|
|
15
|
+
}
|
package/vite.config.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import react from '@vitejs/plugin-react';
|
|
2
|
+
import * as packageJson from './package.json';
|
|
3
|
+
import { resolve } from 'path';
|
|
4
|
+
import { ConfigEnv, defineConfig, UserConfig } from 'vite';
|
|
5
|
+
import { default as dts } from 'vite-plugin-dts';
|
|
6
|
+
import tailwindcss from '@tailwindcss/vite';
|
|
7
|
+
|
|
8
|
+
export default defineConfig((configEnv: ConfigEnv) => {
|
|
9
|
+
const { mode } = configEnv;
|
|
10
|
+
const isDevelopment = mode === 'development';
|
|
11
|
+
console.log({
|
|
12
|
+
mode,
|
|
13
|
+
isDevelopment,
|
|
14
|
+
peerDependencies: packageJson.peerDependencies,
|
|
15
|
+
});
|
|
16
|
+
const config: UserConfig = {
|
|
17
|
+
build: {
|
|
18
|
+
sourcemap: true,
|
|
19
|
+
lib: {
|
|
20
|
+
entry: resolve('src', 'index.ts'),
|
|
21
|
+
name: 'personaSDK',
|
|
22
|
+
formats: ['es', 'umd', 'cjs', 'iife'],
|
|
23
|
+
fileName: (format: string) => `bundle.${format}.js`,
|
|
24
|
+
},
|
|
25
|
+
rollupOptions: {
|
|
26
|
+
external: Object.keys(packageJson.peerDependencies || {}),
|
|
27
|
+
input: resolve(__dirname, 'src', 'index.ts'),
|
|
28
|
+
output: {
|
|
29
|
+
globals: {
|
|
30
|
+
'react-dom': 'ReactDOM',
|
|
31
|
+
react: 'React',
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
resolve: {
|
|
37
|
+
dedupe: Object.keys(packageJson.peerDependencies || {}),
|
|
38
|
+
alias: {
|
|
39
|
+
'@applica-software-guru/persona-sdk': resolve(__dirname, 'src'),
|
|
40
|
+
'@': resolve(__dirname, 'playground/src'),
|
|
41
|
+
'@/*': resolve(__dirname, 'playground/src/*'),
|
|
42
|
+
'*': resolve(__dirname, 'src/*'),
|
|
43
|
+
react: resolve(__dirname, 'node_modules', 'react'),
|
|
44
|
+
'react-dom': resolve(__dirname, 'node_modules', 'react-dom'),
|
|
45
|
+
'react/jsx-runtime': resolve(__dirname, 'node_modules', 'react/jsx-runtime'),
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
plugins: [
|
|
49
|
+
dts({
|
|
50
|
+
include: ['./src/**/*.{js,jsx,ts,tsx}'],
|
|
51
|
+
}),
|
|
52
|
+
react(),
|
|
53
|
+
],
|
|
54
|
+
define: {
|
|
55
|
+
'process.env': {
|
|
56
|
+
NODE_ENV: 'client',
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
optimizeDeps: {
|
|
60
|
+
include: Object.keys(packageJson.peerDependencies || {}),
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
if (isDevelopment) {
|
|
64
|
+
config.plugins = [react(), tailwindcss()];
|
|
65
|
+
config.root = resolve(__dirname, 'playground');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return config;
|
|
69
|
+
});
|