lyzr-cortex-sdk 0.1.2
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/README.md +445 -0
- package/dist/index.d.mts +438 -0
- package/dist/index.d.ts +438 -0
- package/dist/index.js +445 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +434 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +59 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Cortex SDK Type Definitions
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* User context from Cortex platform.
|
|
9
|
+
* Contains identity, organization, team memberships, and permissions.
|
|
10
|
+
*/
|
|
11
|
+
interface CortexUser {
|
|
12
|
+
/** User's unique identifier */
|
|
13
|
+
id: string;
|
|
14
|
+
/** User's email address */
|
|
15
|
+
email: string;
|
|
16
|
+
/** User's display name */
|
|
17
|
+
name?: string;
|
|
18
|
+
/** Organization ID */
|
|
19
|
+
orgId: string;
|
|
20
|
+
/** Organization name */
|
|
21
|
+
orgName?: string;
|
|
22
|
+
/** Team memberships */
|
|
23
|
+
teams: Array<{
|
|
24
|
+
id: string;
|
|
25
|
+
name: string;
|
|
26
|
+
}>;
|
|
27
|
+
/** Organization role: admin, member */
|
|
28
|
+
role: string;
|
|
29
|
+
/** Permission list */
|
|
30
|
+
permissions: string[];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Document to push to Cortex Knowledge Graph.
|
|
34
|
+
*/
|
|
35
|
+
interface CortexDocument {
|
|
36
|
+
/** Unique ID from source tool */
|
|
37
|
+
externalId: string;
|
|
38
|
+
/** Document type: meeting_transcript, deal, etc. */
|
|
39
|
+
type: string;
|
|
40
|
+
/** Text content for RAG indexing */
|
|
41
|
+
content: string;
|
|
42
|
+
/** Display name */
|
|
43
|
+
name?: string;
|
|
44
|
+
/** URL to view in source tool */
|
|
45
|
+
externalUrl?: string;
|
|
46
|
+
/** Access scope */
|
|
47
|
+
scope?: 'global' | 'team' | 'personal';
|
|
48
|
+
/** Team IDs if scope is 'team' */
|
|
49
|
+
teamIds?: string[];
|
|
50
|
+
/** Additional metadata for filtering */
|
|
51
|
+
metadata?: Record<string, unknown>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Source document returned from a query.
|
|
55
|
+
*/
|
|
56
|
+
interface CortexSource {
|
|
57
|
+
/** Document ID in Cortex */
|
|
58
|
+
id: string;
|
|
59
|
+
/** Document type */
|
|
60
|
+
type: string;
|
|
61
|
+
/** Document name */
|
|
62
|
+
name: string;
|
|
63
|
+
/** Relevant excerpt */
|
|
64
|
+
excerpt: string;
|
|
65
|
+
/** Relevance score */
|
|
66
|
+
score?: number;
|
|
67
|
+
/** URL to source */
|
|
68
|
+
url?: string;
|
|
69
|
+
/** Additional metadata */
|
|
70
|
+
metadata?: Record<string, unknown>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Result from Cortex knowledge query.
|
|
74
|
+
*/
|
|
75
|
+
interface CortexQueryResult {
|
|
76
|
+
/** AI-generated answer */
|
|
77
|
+
answer: string;
|
|
78
|
+
/** Source documents used */
|
|
79
|
+
sources: CortexSource[];
|
|
80
|
+
/** Original query */
|
|
81
|
+
query: string;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Options for querying Cortex.
|
|
85
|
+
*/
|
|
86
|
+
interface QueryOptions {
|
|
87
|
+
/** Filter by document type, etc. */
|
|
88
|
+
filters?: Record<string, unknown>;
|
|
89
|
+
/** Limit to recent documents (days) */
|
|
90
|
+
timeRangeDays?: number;
|
|
91
|
+
/** Maximum results to return */
|
|
92
|
+
maxResults?: number;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* SDK configuration options.
|
|
96
|
+
*/
|
|
97
|
+
interface CortexConfig {
|
|
98
|
+
/** Cortex gateway URL */
|
|
99
|
+
apiUrl?: string;
|
|
100
|
+
/** Tool's API key */
|
|
101
|
+
apiKey?: string;
|
|
102
|
+
/** Tool identifier */
|
|
103
|
+
toolId?: string;
|
|
104
|
+
/** Enable debug logging */
|
|
105
|
+
debug?: boolean;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Context value provided by CortexProvider.
|
|
109
|
+
*/
|
|
110
|
+
interface CortexContextValue {
|
|
111
|
+
/** Current user (null if not in embedded mode) */
|
|
112
|
+
user: CortexUser | null;
|
|
113
|
+
/** Whether app is embedded in Cortex shell */
|
|
114
|
+
isEmbedded: boolean;
|
|
115
|
+
/** Whether SDK is initialized and ready */
|
|
116
|
+
isReady: boolean;
|
|
117
|
+
/** Current theme from Cortex */
|
|
118
|
+
theme: 'light' | 'dark';
|
|
119
|
+
/** Push a document to Knowledge Graph */
|
|
120
|
+
push: (doc: Omit<CortexDocument, 'externalId'> & {
|
|
121
|
+
id: string;
|
|
122
|
+
}) => Promise<void>;
|
|
123
|
+
/** Query the Knowledge Graph */
|
|
124
|
+
query: (question: string, options?: QueryOptions) => Promise<CortexQueryResult>;
|
|
125
|
+
/** Open Cortex chat with optional prefilled query */
|
|
126
|
+
openChat: (prefilledQuery?: string) => void;
|
|
127
|
+
/** Show notification in Cortex shell */
|
|
128
|
+
showNotification: (message: string, type?: 'success' | 'error' | 'info') => void;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Message types for postMessage communication.
|
|
132
|
+
*/
|
|
133
|
+
type CortexMessageType = 'TOOL_READY' | 'CORTEX_INIT' | 'CORTEX_THEME' | 'OPEN_CHAT' | 'SHOW_NOTIFICATION' | 'NAVIGATE';
|
|
134
|
+
/**
|
|
135
|
+
* PostMessage structure.
|
|
136
|
+
*/
|
|
137
|
+
interface CortexMessage<T = unknown> {
|
|
138
|
+
type: CortexMessageType;
|
|
139
|
+
payload?: T;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Payload for CORTEX_INIT message.
|
|
143
|
+
*/
|
|
144
|
+
interface CortexInitPayload {
|
|
145
|
+
user: CortexUser | null;
|
|
146
|
+
theme?: 'light' | 'dark';
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Payload for CORTEX_THEME message.
|
|
150
|
+
*/
|
|
151
|
+
interface CortexThemePayload {
|
|
152
|
+
theme: 'light' | 'dark';
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Payload for OPEN_CHAT message.
|
|
156
|
+
*/
|
|
157
|
+
interface OpenChatPayload {
|
|
158
|
+
query?: string;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Payload for SHOW_NOTIFICATION message.
|
|
162
|
+
*/
|
|
163
|
+
interface ShowNotificationPayload {
|
|
164
|
+
message: string;
|
|
165
|
+
type?: 'success' | 'error' | 'info';
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Payload for NAVIGATE message.
|
|
169
|
+
*/
|
|
170
|
+
interface NavigatePayload {
|
|
171
|
+
path: string;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Props for CortexProvider component.
|
|
176
|
+
*/
|
|
177
|
+
interface CortexProviderProps {
|
|
178
|
+
children: ReactNode;
|
|
179
|
+
/** Cortex gateway URL (for API calls) */
|
|
180
|
+
apiUrl?: string;
|
|
181
|
+
/** Tool's API key */
|
|
182
|
+
apiKey?: string;
|
|
183
|
+
/** Tool identifier */
|
|
184
|
+
toolId?: string;
|
|
185
|
+
/** Enable debug logging */
|
|
186
|
+
debug?: boolean;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Provider component for Cortex integration.
|
|
190
|
+
*
|
|
191
|
+
* Wrap your app with this provider to enable Cortex features.
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```tsx
|
|
195
|
+
* function App() {
|
|
196
|
+
* return (
|
|
197
|
+
* <CortexProvider
|
|
198
|
+
* apiUrl={process.env.REACT_APP_CORTEX_API_URL}
|
|
199
|
+
* apiKey={process.env.REACT_APP_CORTEX_API_KEY}
|
|
200
|
+
* >
|
|
201
|
+
* <YourApp />
|
|
202
|
+
* </CortexProvider>
|
|
203
|
+
* );
|
|
204
|
+
* }
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
declare function CortexProvider({ children, apiUrl, apiKey, toolId, debug, }: CortexProviderProps): react_jsx_runtime.JSX.Element;
|
|
208
|
+
/**
|
|
209
|
+
* Hook to access Cortex context.
|
|
210
|
+
*
|
|
211
|
+
* Returns a no-op implementation if used outside CortexProvider,
|
|
212
|
+
* making it safe to use in components that may render both
|
|
213
|
+
* inside and outside the provider.
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```tsx
|
|
217
|
+
* function MeetingCard({ meeting }) {
|
|
218
|
+
* const { isEmbedded, openChat } = useCortex();
|
|
219
|
+
*
|
|
220
|
+
* return (
|
|
221
|
+
* <div>
|
|
222
|
+
* <h3>{meeting.title}</h3>
|
|
223
|
+
* {isEmbedded && (
|
|
224
|
+
* <button onClick={() => openChat(`Tell me about ${meeting.title}`)}>
|
|
225
|
+
* Ask Cortex
|
|
226
|
+
* </button>
|
|
227
|
+
* )}
|
|
228
|
+
* </div>
|
|
229
|
+
* );
|
|
230
|
+
* }
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
declare function useCortex(): CortexContextValue;
|
|
234
|
+
/**
|
|
235
|
+
* Hook to check if currently embedded in Cortex.
|
|
236
|
+
* More efficient than useCortex() if you only need the embedded status.
|
|
237
|
+
*/
|
|
238
|
+
declare function useIsEmbedded(): boolean;
|
|
239
|
+
/**
|
|
240
|
+
* Hook to get current Cortex user.
|
|
241
|
+
* Returns null if not embedded or not authenticated.
|
|
242
|
+
*/
|
|
243
|
+
declare function useCortexUser(): CortexUser | null;
|
|
244
|
+
/**
|
|
245
|
+
* Hook to get current theme from Cortex.
|
|
246
|
+
*/
|
|
247
|
+
declare function useCortexTheme(): 'light' | 'dark';
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* CortexBridge - PostMessage communication for iframe embedding.
|
|
251
|
+
*
|
|
252
|
+
* Handles bidirectional communication between tool (iframe) and
|
|
253
|
+
* Cortex shell (parent window).
|
|
254
|
+
*/
|
|
255
|
+
|
|
256
|
+
type MessageHandler<T = unknown> = (payload: T) => void;
|
|
257
|
+
/**
|
|
258
|
+
* Public interface for CortexBridge.
|
|
259
|
+
*/
|
|
260
|
+
interface ICortexBridge {
|
|
261
|
+
readonly isEmbedded: boolean;
|
|
262
|
+
readonly isReady: boolean;
|
|
263
|
+
readonly user: CortexUser | null;
|
|
264
|
+
readonly theme: 'light' | 'dark';
|
|
265
|
+
waitForReady(): Promise<CortexUser | null>;
|
|
266
|
+
on<T = unknown>(messageType: string, handler: MessageHandler<T>): () => void;
|
|
267
|
+
sendToParent(message: CortexMessage): void;
|
|
268
|
+
openChat(prefilledQuery?: string): void;
|
|
269
|
+
showNotification(message: string, type?: 'success' | 'error' | 'info'): void;
|
|
270
|
+
navigate(path: string): void;
|
|
271
|
+
destroy(): void;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Bridge for postMessage communication with Cortex shell.
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* ```typescript
|
|
278
|
+
* const bridge = new CortexBridge();
|
|
279
|
+
*
|
|
280
|
+
* // Wait for initialization
|
|
281
|
+
* const user = await bridge.waitForReady();
|
|
282
|
+
*
|
|
283
|
+
* // Send messages to Cortex
|
|
284
|
+
* bridge.openChat('What were the action items?');
|
|
285
|
+
* bridge.showNotification('Document saved', 'success');
|
|
286
|
+
* ```
|
|
287
|
+
*/
|
|
288
|
+
declare class CortexBridge implements ICortexBridge {
|
|
289
|
+
private handlers;
|
|
290
|
+
private parentOrigin;
|
|
291
|
+
private _isEmbedded;
|
|
292
|
+
private _isReady;
|
|
293
|
+
private _user;
|
|
294
|
+
private _theme;
|
|
295
|
+
private readyPromise;
|
|
296
|
+
private readyResolve;
|
|
297
|
+
constructor();
|
|
298
|
+
/** Whether app is embedded in Cortex shell */
|
|
299
|
+
get isEmbedded(): boolean;
|
|
300
|
+
/** Whether bridge is initialized */
|
|
301
|
+
get isReady(): boolean;
|
|
302
|
+
/** Current user from Cortex (null if standalone) */
|
|
303
|
+
get user(): CortexUser | null;
|
|
304
|
+
/** Current theme from Cortex */
|
|
305
|
+
get theme(): 'light' | 'dark';
|
|
306
|
+
/**
|
|
307
|
+
* Wait for Cortex initialization.
|
|
308
|
+
* Resolves with user if embedded, null if standalone.
|
|
309
|
+
*/
|
|
310
|
+
waitForReady(): Promise<CortexUser | null>;
|
|
311
|
+
private handleMessage;
|
|
312
|
+
/**
|
|
313
|
+
* Register a handler for a message type.
|
|
314
|
+
* Returns unsubscribe function.
|
|
315
|
+
*/
|
|
316
|
+
on<T = unknown>(messageType: string, handler: MessageHandler<T>): () => void;
|
|
317
|
+
/**
|
|
318
|
+
* Send a message to parent window (Cortex shell).
|
|
319
|
+
*/
|
|
320
|
+
sendToParent(message: CortexMessage): void;
|
|
321
|
+
/**
|
|
322
|
+
* Open Cortex chat, optionally with a prefilled query.
|
|
323
|
+
*/
|
|
324
|
+
openChat(prefilledQuery?: string): void;
|
|
325
|
+
/**
|
|
326
|
+
* Show a notification in Cortex shell.
|
|
327
|
+
*/
|
|
328
|
+
showNotification(message: string, type?: 'success' | 'error' | 'info'): void;
|
|
329
|
+
/**
|
|
330
|
+
* Navigate to a path within Cortex.
|
|
331
|
+
*/
|
|
332
|
+
navigate(path: string): void;
|
|
333
|
+
/**
|
|
334
|
+
* Cleanup - remove message listener.
|
|
335
|
+
*/
|
|
336
|
+
destroy(): void;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Get the shared CortexBridge instance.
|
|
340
|
+
* Creates one if it doesn't exist.
|
|
341
|
+
*/
|
|
342
|
+
declare function getBridge(): ICortexBridge;
|
|
343
|
+
/**
|
|
344
|
+
* Check if currently embedded in Cortex shell.
|
|
345
|
+
* Safe to call during SSR.
|
|
346
|
+
*/
|
|
347
|
+
declare function isEmbeddedInCortex(): boolean;
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* CortexClient - HTTP client for Cortex API.
|
|
351
|
+
*
|
|
352
|
+
* For direct API calls without React context.
|
|
353
|
+
*/
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* HTTP client for Cortex Platform APIs.
|
|
357
|
+
*
|
|
358
|
+
* @example
|
|
359
|
+
* ```typescript
|
|
360
|
+
* const client = new CortexClient({
|
|
361
|
+
* apiUrl: 'https://api.cortex.ai',
|
|
362
|
+
* apiKey: 'your-api-key',
|
|
363
|
+
* toolId: 'your-tool',
|
|
364
|
+
* });
|
|
365
|
+
*
|
|
366
|
+
* await client.push({
|
|
367
|
+
* id: 'doc_123',
|
|
368
|
+
* type: 'meeting_transcript',
|
|
369
|
+
* content: 'Full transcript...',
|
|
370
|
+
* });
|
|
371
|
+
* ```
|
|
372
|
+
*/
|
|
373
|
+
declare class CortexClient {
|
|
374
|
+
private apiUrl;
|
|
375
|
+
private apiKey;
|
|
376
|
+
private toolId;
|
|
377
|
+
private debug;
|
|
378
|
+
constructor(config?: CortexConfig);
|
|
379
|
+
/** Whether client is configured */
|
|
380
|
+
get isConfigured(): boolean;
|
|
381
|
+
private log;
|
|
382
|
+
private request;
|
|
383
|
+
/**
|
|
384
|
+
* Push a document to Cortex Knowledge Graph.
|
|
385
|
+
*/
|
|
386
|
+
push(doc: Omit<CortexDocument, 'externalId'> & {
|
|
387
|
+
id: string;
|
|
388
|
+
}): Promise<{
|
|
389
|
+
id: string;
|
|
390
|
+
status: string;
|
|
391
|
+
}>;
|
|
392
|
+
/**
|
|
393
|
+
* Query Cortex Knowledge Graph.
|
|
394
|
+
*/
|
|
395
|
+
query(question: string, options?: QueryOptions & {
|
|
396
|
+
userEmail?: string;
|
|
397
|
+
}): Promise<CortexQueryResult>;
|
|
398
|
+
/**
|
|
399
|
+
* Get user context from Cortex.
|
|
400
|
+
* Calls GET /api/tools/context/{userEmail}
|
|
401
|
+
*/
|
|
402
|
+
getUserContext(userEmail: string): Promise<CortexUser | null>;
|
|
403
|
+
/**
|
|
404
|
+
* Share a document with another user.
|
|
405
|
+
* Calls POST /api/tools/share-document-for-user
|
|
406
|
+
*
|
|
407
|
+
* Creates a share record so the document appears in
|
|
408
|
+
* the recipient's "Shared with Me" at /personal/shared.
|
|
409
|
+
*/
|
|
410
|
+
shareDocument(params: {
|
|
411
|
+
documentExternalId: string;
|
|
412
|
+
sharedByEmail: string;
|
|
413
|
+
sharedWithEmail: string;
|
|
414
|
+
documentName?: string;
|
|
415
|
+
content?: string;
|
|
416
|
+
externalUrl?: string;
|
|
417
|
+
metadata?: Record<string, unknown>;
|
|
418
|
+
}): Promise<{
|
|
419
|
+
success: boolean;
|
|
420
|
+
id?: string;
|
|
421
|
+
}>;
|
|
422
|
+
/**
|
|
423
|
+
* Get list of users in the tool's organization.
|
|
424
|
+
* Calls GET /api/tools/org-users-for-tool
|
|
425
|
+
*/
|
|
426
|
+
getOrgUsers(excludeEmail?: string): Promise<Array<{
|
|
427
|
+
id: string;
|
|
428
|
+
email: string;
|
|
429
|
+
full_name: string;
|
|
430
|
+
avatar_url?: string;
|
|
431
|
+
}>>;
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Create a configured CortexClient instance.
|
|
435
|
+
*/
|
|
436
|
+
declare function createCortexClient(config: CortexConfig): CortexClient;
|
|
437
|
+
|
|
438
|
+
export { CortexBridge, CortexClient, type CortexConfig, type CortexContextValue, type CortexDocument, type CortexInitPayload, type CortexMessage, type CortexMessageType, CortexProvider, type CortexProviderProps, type CortexQueryResult, type CortexSource, type CortexThemePayload, type CortexUser, type ICortexBridge, type NavigatePayload, type OpenChatPayload, type QueryOptions, type ShowNotificationPayload, createCortexClient, getBridge, isEmbeddedInCortex, useCortex, useCortexTheme, useCortexUser, useIsEmbedded };
|