@lifestreamdynamics/vault-sdk 1.0.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/LICENSE +21 -0
- package/README.md +1121 -0
- package/dist/client.d.ts +143 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +286 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +28 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +49 -0
- package/dist/errors.js.map +1 -0
- package/dist/handle-error.d.ts +8 -0
- package/dist/handle-error.d.ts.map +1 -0
- package/dist/handle-error.js +35 -0
- package/dist/handle-error.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/audit-logger.d.ts +29 -0
- package/dist/lib/audit-logger.d.ts.map +1 -0
- package/dist/lib/audit-logger.js +99 -0
- package/dist/lib/audit-logger.js.map +1 -0
- package/dist/lib/encryption.d.ts +34 -0
- package/dist/lib/encryption.d.ts.map +1 -0
- package/dist/lib/encryption.js +87 -0
- package/dist/lib/encryption.js.map +1 -0
- package/dist/lib/signature.d.ts +47 -0
- package/dist/lib/signature.d.ts.map +1 -0
- package/dist/lib/signature.js +71 -0
- package/dist/lib/signature.js.map +1 -0
- package/dist/lib/token-manager.d.ts +80 -0
- package/dist/lib/token-manager.d.ts.map +1 -0
- package/dist/lib/token-manager.js +116 -0
- package/dist/lib/token-manager.js.map +1 -0
- package/dist/resources/admin.d.ts +280 -0
- package/dist/resources/admin.d.ts.map +1 -0
- package/dist/resources/admin.js +236 -0
- package/dist/resources/admin.js.map +1 -0
- package/dist/resources/ai.d.ts +184 -0
- package/dist/resources/ai.d.ts.map +1 -0
- package/dist/resources/ai.js +179 -0
- package/dist/resources/ai.js.map +1 -0
- package/dist/resources/api-keys.d.ts +172 -0
- package/dist/resources/api-keys.d.ts.map +1 -0
- package/dist/resources/api-keys.js +166 -0
- package/dist/resources/api-keys.js.map +1 -0
- package/dist/resources/connectors.d.ts +263 -0
- package/dist/resources/connectors.d.ts.map +1 -0
- package/dist/resources/connectors.js +226 -0
- package/dist/resources/connectors.js.map +1 -0
- package/dist/resources/documents.d.ts +334 -0
- package/dist/resources/documents.d.ts.map +1 -0
- package/dist/resources/documents.js +377 -0
- package/dist/resources/documents.js.map +1 -0
- package/dist/resources/hooks.d.ts +195 -0
- package/dist/resources/hooks.d.ts.map +1 -0
- package/dist/resources/hooks.js +166 -0
- package/dist/resources/hooks.js.map +1 -0
- package/dist/resources/publish.d.ts +165 -0
- package/dist/resources/publish.d.ts.map +1 -0
- package/dist/resources/publish.js +150 -0
- package/dist/resources/publish.js.map +1 -0
- package/dist/resources/search.d.ts +94 -0
- package/dist/resources/search.d.ts.map +1 -0
- package/dist/resources/search.js +76 -0
- package/dist/resources/search.js.map +1 -0
- package/dist/resources/shares.d.ts +130 -0
- package/dist/resources/shares.d.ts.map +1 -0
- package/dist/resources/shares.js +115 -0
- package/dist/resources/shares.js.map +1 -0
- package/dist/resources/subscription.d.ts +172 -0
- package/dist/resources/subscription.d.ts.map +1 -0
- package/dist/resources/subscription.js +166 -0
- package/dist/resources/subscription.js.map +1 -0
- package/dist/resources/teams.d.ts +356 -0
- package/dist/resources/teams.d.ts.map +1 -0
- package/dist/resources/teams.js +395 -0
- package/dist/resources/teams.js.map +1 -0
- package/dist/resources/user.d.ts +92 -0
- package/dist/resources/user.d.ts.map +1 -0
- package/dist/resources/user.js +64 -0
- package/dist/resources/user.js.map +1 -0
- package/dist/resources/vaults.d.ts +144 -0
- package/dist/resources/vaults.d.ts.map +1 -0
- package/dist/resources/vaults.js +158 -0
- package/dist/resources/vaults.js.map +1 -0
- package/dist/resources/webhooks.d.ts +187 -0
- package/dist/resources/webhooks.d.ts.map +1 -0
- package/dist/resources/webhooks.js +171 -0
- package/dist/resources/webhooks.js.map +1 -0
- package/dist/types/api.d.ts +17 -0
- package/dist/types/api.d.ts.map +1 -0
- package/dist/types/api.js +2 -0
- package/dist/types/api.js.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/resources.d.ts +5 -0
- package/dist/types/resources.d.ts.map +1 -0
- package/dist/types/resources.js +2 -0
- package/dist/types/resources.js.map +1 -0
- package/package.json +58 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import type { KyInstance } from 'ky';
|
|
2
|
+
/** An AI chat session with optional vault context. */
|
|
3
|
+
export interface AiChatSession {
|
|
4
|
+
/** Unique session identifier. */
|
|
5
|
+
id: string;
|
|
6
|
+
/** Auto-generated or user-provided session title. */
|
|
7
|
+
title: string;
|
|
8
|
+
/** ID of the vault scoped to this session, or `null` for cross-vault sessions. */
|
|
9
|
+
vaultId: string | null;
|
|
10
|
+
/** ISO 8601 creation timestamp. */
|
|
11
|
+
createdAt: string;
|
|
12
|
+
/** ISO 8601 last-updated timestamp. */
|
|
13
|
+
updatedAt: string;
|
|
14
|
+
}
|
|
15
|
+
/** A single message in an AI chat session. */
|
|
16
|
+
export interface AiChatMessage {
|
|
17
|
+
/** Unique message identifier. */
|
|
18
|
+
id: string;
|
|
19
|
+
/** The role of the message sender. */
|
|
20
|
+
role: 'user' | 'assistant' | 'system';
|
|
21
|
+
/** Message text content. */
|
|
22
|
+
content: string;
|
|
23
|
+
/** Number of tokens consumed by this message. */
|
|
24
|
+
tokensUsed: number;
|
|
25
|
+
/** ISO 8601 creation timestamp. */
|
|
26
|
+
createdAt: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Resource for AI-powered chat and document analysis.
|
|
30
|
+
*
|
|
31
|
+
* Provides conversational AI with optional vault context for document-aware
|
|
32
|
+
* responses, as well as standalone document summarization. Requires a
|
|
33
|
+
* subscription tier that includes AI features.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const response = await client.ai.chat({
|
|
38
|
+
* message: 'Summarize my recent meeting notes',
|
|
39
|
+
* vaultId: 'vault-uuid',
|
|
40
|
+
* });
|
|
41
|
+
* console.log(response.message.content);
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare class AiResource {
|
|
45
|
+
private http;
|
|
46
|
+
constructor(http: KyInstance);
|
|
47
|
+
/**
|
|
48
|
+
* Sends a message to the AI chat and receives a response.
|
|
49
|
+
*
|
|
50
|
+
* If `sessionId` is provided, the message is appended to an existing
|
|
51
|
+
* conversation. Otherwise, a new session is created automatically.
|
|
52
|
+
* When `vaultId` is provided, the AI has access to documents in that
|
|
53
|
+
* vault for context-aware responses.
|
|
54
|
+
*
|
|
55
|
+
* @param params - Chat parameters
|
|
56
|
+
* @param params.message - The user's message text (required)
|
|
57
|
+
* @param params.sessionId - Optional existing session ID to continue a conversation
|
|
58
|
+
* @param params.vaultId - Optional vault ID to scope the AI's document context
|
|
59
|
+
* @returns The AI response with session ID, message content, document sources, and token usage
|
|
60
|
+
* @throws {NotFoundError} If the specified session or vault does not exist
|
|
61
|
+
* @throws {AuthenticationError} If the request is not authenticated
|
|
62
|
+
* @throws {AuthorizationError} If the user's subscription does not include AI features
|
|
63
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* // Start a new conversation
|
|
68
|
+
* const response = await client.ai.chat({
|
|
69
|
+
* message: 'What are my open action items?',
|
|
70
|
+
* vaultId: 'vault-uuid',
|
|
71
|
+
* });
|
|
72
|
+
* console.log(response.message.content);
|
|
73
|
+
* console.log('Sources:', response.message.sources);
|
|
74
|
+
*
|
|
75
|
+
* // Continue the conversation
|
|
76
|
+
* const followUp = await client.ai.chat({
|
|
77
|
+
* message: 'Which ones are due this week?',
|
|
78
|
+
* sessionId: response.sessionId,
|
|
79
|
+
* });
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @see {@link AiResource.listSessions} to list past conversations
|
|
83
|
+
*/
|
|
84
|
+
chat(params: {
|
|
85
|
+
message: string;
|
|
86
|
+
sessionId?: string;
|
|
87
|
+
vaultId?: string;
|
|
88
|
+
}): Promise<{
|
|
89
|
+
sessionId: string;
|
|
90
|
+
message: {
|
|
91
|
+
role: string;
|
|
92
|
+
content: string;
|
|
93
|
+
sources: string[];
|
|
94
|
+
};
|
|
95
|
+
tokensUsed: number;
|
|
96
|
+
}>;
|
|
97
|
+
/**
|
|
98
|
+
* Lists all AI chat sessions for the authenticated user.
|
|
99
|
+
*
|
|
100
|
+
* @returns Array of chat session objects, ordered by most recent first
|
|
101
|
+
* @throws {AuthenticationError} If the request is not authenticated
|
|
102
|
+
* @throws {AuthorizationError} If the user's subscription does not include AI features
|
|
103
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* const sessions = await client.ai.listSessions();
|
|
108
|
+
* for (const session of sessions) {
|
|
109
|
+
* console.log(session.title, session.createdAt);
|
|
110
|
+
* }
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
listSessions(): Promise<AiChatSession[]>;
|
|
114
|
+
/**
|
|
115
|
+
* Retrieves a chat session with its full message history.
|
|
116
|
+
*
|
|
117
|
+
* @param sessionId - The unique identifier of the session
|
|
118
|
+
* @returns The session metadata and array of all messages in chronological order
|
|
119
|
+
* @throws {NotFoundError} If no session exists with the given ID
|
|
120
|
+
* @throws {AuthenticationError} If the request is not authenticated
|
|
121
|
+
* @throws {AuthorizationError} If the user's subscription does not include AI features
|
|
122
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* const { session, messages } = await client.ai.getSession('session-uuid');
|
|
127
|
+
* console.log(`Session: ${session.title}`);
|
|
128
|
+
* for (const msg of messages) {
|
|
129
|
+
* console.log(`[${msg.role}] ${msg.content}`);
|
|
130
|
+
* }
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
getSession(sessionId: string): Promise<{
|
|
134
|
+
session: AiChatSession;
|
|
135
|
+
messages: AiChatMessage[];
|
|
136
|
+
}>;
|
|
137
|
+
/**
|
|
138
|
+
* Permanently deletes a chat session and all its messages.
|
|
139
|
+
*
|
|
140
|
+
* This action is irreversible.
|
|
141
|
+
*
|
|
142
|
+
* @param sessionId - The unique identifier of the session to delete
|
|
143
|
+
* @throws {NotFoundError} If no session exists with the given ID
|
|
144
|
+
* @throws {AuthenticationError} If the request is not authenticated
|
|
145
|
+
* @throws {AuthorizationError} If the user's subscription does not include AI features
|
|
146
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```typescript
|
|
150
|
+
* await client.ai.deleteSession('session-uuid');
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
deleteSession(sessionId: string): Promise<void>;
|
|
154
|
+
/**
|
|
155
|
+
* Generates an AI summary of a specific document.
|
|
156
|
+
*
|
|
157
|
+
* Analyzes the document content and produces a concise summary along
|
|
158
|
+
* with a list of key topics identified in the text.
|
|
159
|
+
*
|
|
160
|
+
* @param vaultId - The vault ID containing the document
|
|
161
|
+
* @param documentPath - File path of the document to summarize
|
|
162
|
+
* @returns Object containing the summary text, extracted key topics, and token usage
|
|
163
|
+
* @throws {NotFoundError} If the vault or document does not exist
|
|
164
|
+
* @throws {AuthenticationError} If the request is not authenticated
|
|
165
|
+
* @throws {AuthorizationError} If the user's subscription does not include AI features
|
|
166
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* const result = await client.ai.summarize('vault-uuid', 'notes/long-article.md');
|
|
171
|
+
* console.log(result.summary);
|
|
172
|
+
* console.log('Key topics:', result.keyTopics.join(', '));
|
|
173
|
+
* console.log(`Tokens used: ${result.tokensUsed}`);
|
|
174
|
+
* ```
|
|
175
|
+
*
|
|
176
|
+
* @see {@link AiResource.chat} for interactive document Q&A
|
|
177
|
+
*/
|
|
178
|
+
summarize(vaultId: string, documentPath: string): Promise<{
|
|
179
|
+
summary: string;
|
|
180
|
+
keyTopics: string[];
|
|
181
|
+
tokensUsed: number;
|
|
182
|
+
}>;
|
|
183
|
+
}
|
|
184
|
+
//# sourceMappingURL=ai.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai.d.ts","sourceRoot":"","sources":["../../src/resources/ai.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAGrC,sDAAsD;AACtD,MAAM,WAAW,aAAa;IAC5B,iCAAiC;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,qDAAqD;IACrD,KAAK,EAAE,MAAM,CAAC;IACd,kFAAkF;IAClF,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,mCAAmC;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,uCAAuC;IACvC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,8CAA8C;AAC9C,MAAM,WAAW,aAAa;IAC5B,iCAAiC;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,sCAAsC;IACtC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAC;IACtC,4BAA4B;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,iDAAiD;IACjD,UAAU,EAAE,MAAM,CAAC;IACnB,mCAAmC;IACnC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,UAAU;IACT,OAAO,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAEpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoCG;IACG,IAAI,CAAC,MAAM,EAAE;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,GAAG,OAAO,CAAC;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,MAAM,EAAE,CAAA;SAAE,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;IAQrH;;;;;;;;;;;;;;;OAeG;IACG,YAAY,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;IAS9C;;;;;;;;;;;;;;;;;;OAkBG;IACG,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,aAAa,CAAC;QAAC,QAAQ,EAAE,aAAa,EAAE,CAAA;KAAE,CAAC;IAQnG;;;;;;;;;;;;;;;OAeG;IACG,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQrD;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACG,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,EAAE,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;CAS9H"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { handleError } from '../handle-error.js';
|
|
2
|
+
/**
|
|
3
|
+
* Resource for AI-powered chat and document analysis.
|
|
4
|
+
*
|
|
5
|
+
* Provides conversational AI with optional vault context for document-aware
|
|
6
|
+
* responses, as well as standalone document summarization. Requires a
|
|
7
|
+
* subscription tier that includes AI features.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const response = await client.ai.chat({
|
|
12
|
+
* message: 'Summarize my recent meeting notes',
|
|
13
|
+
* vaultId: 'vault-uuid',
|
|
14
|
+
* });
|
|
15
|
+
* console.log(response.message.content);
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export class AiResource {
|
|
19
|
+
http;
|
|
20
|
+
constructor(http) {
|
|
21
|
+
this.http = http;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Sends a message to the AI chat and receives a response.
|
|
25
|
+
*
|
|
26
|
+
* If `sessionId` is provided, the message is appended to an existing
|
|
27
|
+
* conversation. Otherwise, a new session is created automatically.
|
|
28
|
+
* When `vaultId` is provided, the AI has access to documents in that
|
|
29
|
+
* vault for context-aware responses.
|
|
30
|
+
*
|
|
31
|
+
* @param params - Chat parameters
|
|
32
|
+
* @param params.message - The user's message text (required)
|
|
33
|
+
* @param params.sessionId - Optional existing session ID to continue a conversation
|
|
34
|
+
* @param params.vaultId - Optional vault ID to scope the AI's document context
|
|
35
|
+
* @returns The AI response with session ID, message content, document sources, and token usage
|
|
36
|
+
* @throws {NotFoundError} If the specified session or vault does not exist
|
|
37
|
+
* @throws {AuthenticationError} If the request is not authenticated
|
|
38
|
+
* @throws {AuthorizationError} If the user's subscription does not include AI features
|
|
39
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* // Start a new conversation
|
|
44
|
+
* const response = await client.ai.chat({
|
|
45
|
+
* message: 'What are my open action items?',
|
|
46
|
+
* vaultId: 'vault-uuid',
|
|
47
|
+
* });
|
|
48
|
+
* console.log(response.message.content);
|
|
49
|
+
* console.log('Sources:', response.message.sources);
|
|
50
|
+
*
|
|
51
|
+
* // Continue the conversation
|
|
52
|
+
* const followUp = await client.ai.chat({
|
|
53
|
+
* message: 'Which ones are due this week?',
|
|
54
|
+
* sessionId: response.sessionId,
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @see {@link AiResource.listSessions} to list past conversations
|
|
59
|
+
*/
|
|
60
|
+
async chat(params) {
|
|
61
|
+
try {
|
|
62
|
+
return await this.http.post('ai/chat', { json: params }).json();
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
throw await handleError(error, 'AI Chat', params.sessionId ?? '');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Lists all AI chat sessions for the authenticated user.
|
|
70
|
+
*
|
|
71
|
+
* @returns Array of chat session objects, ordered by most recent first
|
|
72
|
+
* @throws {AuthenticationError} If the request is not authenticated
|
|
73
|
+
* @throws {AuthorizationError} If the user's subscription does not include AI features
|
|
74
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* const sessions = await client.ai.listSessions();
|
|
79
|
+
* for (const session of sessions) {
|
|
80
|
+
* console.log(session.title, session.createdAt);
|
|
81
|
+
* }
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
async listSessions() {
|
|
85
|
+
try {
|
|
86
|
+
const data = await this.http.get('ai/sessions').json();
|
|
87
|
+
return data.sessions;
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
throw await handleError(error, 'AI Sessions', '');
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Retrieves a chat session with its full message history.
|
|
95
|
+
*
|
|
96
|
+
* @param sessionId - The unique identifier of the session
|
|
97
|
+
* @returns The session metadata and array of all messages in chronological order
|
|
98
|
+
* @throws {NotFoundError} If no session exists with the given ID
|
|
99
|
+
* @throws {AuthenticationError} If the request is not authenticated
|
|
100
|
+
* @throws {AuthorizationError} If the user's subscription does not include AI features
|
|
101
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const { session, messages } = await client.ai.getSession('session-uuid');
|
|
106
|
+
* console.log(`Session: ${session.title}`);
|
|
107
|
+
* for (const msg of messages) {
|
|
108
|
+
* console.log(`[${msg.role}] ${msg.content}`);
|
|
109
|
+
* }
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
async getSession(sessionId) {
|
|
113
|
+
try {
|
|
114
|
+
return await this.http.get(`ai/sessions/${sessionId}`).json();
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
throw await handleError(error, 'AI Session', sessionId);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Permanently deletes a chat session and all its messages.
|
|
122
|
+
*
|
|
123
|
+
* This action is irreversible.
|
|
124
|
+
*
|
|
125
|
+
* @param sessionId - The unique identifier of the session to delete
|
|
126
|
+
* @throws {NotFoundError} If no session exists with the given ID
|
|
127
|
+
* @throws {AuthenticationError} If the request is not authenticated
|
|
128
|
+
* @throws {AuthorizationError} If the user's subscription does not include AI features
|
|
129
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* await client.ai.deleteSession('session-uuid');
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
async deleteSession(sessionId) {
|
|
137
|
+
try {
|
|
138
|
+
await this.http.delete(`ai/sessions/${sessionId}`);
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
throw await handleError(error, 'AI Session', sessionId);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Generates an AI summary of a specific document.
|
|
146
|
+
*
|
|
147
|
+
* Analyzes the document content and produces a concise summary along
|
|
148
|
+
* with a list of key topics identified in the text.
|
|
149
|
+
*
|
|
150
|
+
* @param vaultId - The vault ID containing the document
|
|
151
|
+
* @param documentPath - File path of the document to summarize
|
|
152
|
+
* @returns Object containing the summary text, extracted key topics, and token usage
|
|
153
|
+
* @throws {NotFoundError} If the vault or document does not exist
|
|
154
|
+
* @throws {AuthenticationError} If the request is not authenticated
|
|
155
|
+
* @throws {AuthorizationError} If the user's subscription does not include AI features
|
|
156
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* const result = await client.ai.summarize('vault-uuid', 'notes/long-article.md');
|
|
161
|
+
* console.log(result.summary);
|
|
162
|
+
* console.log('Key topics:', result.keyTopics.join(', '));
|
|
163
|
+
* console.log(`Tokens used: ${result.tokensUsed}`);
|
|
164
|
+
* ```
|
|
165
|
+
*
|
|
166
|
+
* @see {@link AiResource.chat} for interactive document Q&A
|
|
167
|
+
*/
|
|
168
|
+
async summarize(vaultId, documentPath) {
|
|
169
|
+
try {
|
|
170
|
+
return await this.http.post('ai/summarize', {
|
|
171
|
+
json: { vaultId, documentPath },
|
|
172
|
+
}).json();
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
throw await handleError(error, 'AI Summarize', documentPath);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=ai.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai.js","sourceRoot":"","sources":["../../src/resources/ai.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AA8BjD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,UAAU;IACD;IAApB,YAAoB,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;IAAG,CAAC;IAExC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoCG;IACH,KAAK,CAAC,IAAI,CAAC,MAIV;QACC,IAAI,CAAC;YACH,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QAClE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,MAAM,WAAW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BAC1C,IAAI,EAAE,EAAE,OAAO,EAAE,YAAY,EAAE;aAChC,CAAC,CAAC,IAAI,EAAE,CAAC;QACZ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,MAAM,WAAW,CAAC,KAAK,EAAE,cAAc,EAAE,YAAY,CAAC,CAAC;QAC/D,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import type { KyInstance } from 'ky';
|
|
2
|
+
/** An API key object returned by the API (secret not included). */
|
|
3
|
+
export interface ApiKey {
|
|
4
|
+
/** Unique API key identifier. */
|
|
5
|
+
id: string;
|
|
6
|
+
/** Human-readable name for the key. */
|
|
7
|
+
name: string;
|
|
8
|
+
/** Short prefix for identifying the key (e.g., `lsv_k_ab12cd34`). */
|
|
9
|
+
prefix: string;
|
|
10
|
+
/** Permission scopes granted to this key (e.g., `['read', 'write']`). */
|
|
11
|
+
scopes: string[];
|
|
12
|
+
/** Vault ID this key is restricted to, or `null` for unrestricted access. */
|
|
13
|
+
vaultId: string | null;
|
|
14
|
+
/** ISO 8601 expiration timestamp, or `null` if the key does not expire. */
|
|
15
|
+
expiresAt: string | null;
|
|
16
|
+
/** Whether the key is currently active. */
|
|
17
|
+
isActive: boolean;
|
|
18
|
+
/** ISO 8601 timestamp of last usage, or `null` if never used. */
|
|
19
|
+
lastUsedAt: string | null;
|
|
20
|
+
/** ISO 8601 creation timestamp. */
|
|
21
|
+
createdAt: string;
|
|
22
|
+
/** ISO 8601 last-updated timestamp. */
|
|
23
|
+
updatedAt: string;
|
|
24
|
+
}
|
|
25
|
+
/** An API key object that includes the full secret. Only returned on creation. */
|
|
26
|
+
export interface ApiKeyWithSecret extends ApiKey {
|
|
27
|
+
/** The full API key string including secret. Only available at creation time. */
|
|
28
|
+
key: string;
|
|
29
|
+
}
|
|
30
|
+
/** Parameters for creating a new API key. */
|
|
31
|
+
export interface CreateApiKeyParams {
|
|
32
|
+
/** Human-readable name for the key. */
|
|
33
|
+
name: string;
|
|
34
|
+
/** Permission scopes to grant (e.g., `['read', 'write']`). */
|
|
35
|
+
scopes: string[];
|
|
36
|
+
/** Optional vault ID to restrict the key to a single vault. */
|
|
37
|
+
vaultId?: string | null;
|
|
38
|
+
/** Optional ISO 8601 expiration date. */
|
|
39
|
+
expiresAt?: string | null;
|
|
40
|
+
}
|
|
41
|
+
/** Parameters for updating an existing API key. */
|
|
42
|
+
export interface UpdateApiKeyParams {
|
|
43
|
+
/** New name for the key. */
|
|
44
|
+
name?: string;
|
|
45
|
+
/** Whether the key should be active. */
|
|
46
|
+
isActive?: boolean;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Resource for managing API keys.
|
|
50
|
+
*
|
|
51
|
+
* API keys provide programmatic access to the Lifestream Vault API.
|
|
52
|
+
* Keys can be scoped to specific permissions and optionally restricted
|
|
53
|
+
* to a single vault.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* const keys = await client.apiKeys.list();
|
|
58
|
+
* const newKey = await client.apiKeys.create({
|
|
59
|
+
* name: 'CI/CD Key',
|
|
60
|
+
* scopes: ['read', 'write'],
|
|
61
|
+
* });
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare class ApiKeysResource {
|
|
65
|
+
private http;
|
|
66
|
+
constructor(http: KyInstance);
|
|
67
|
+
/**
|
|
68
|
+
* Lists all API keys for the authenticated user.
|
|
69
|
+
*
|
|
70
|
+
* Returns key metadata without secrets. Use this to audit existing keys
|
|
71
|
+
* or find keys to update/revoke.
|
|
72
|
+
*
|
|
73
|
+
* @returns Array of API key objects (without secrets)
|
|
74
|
+
* @throws {AuthenticationError} If not authenticated
|
|
75
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* const keys = await client.apiKeys.list();
|
|
80
|
+
* for (const key of keys) {
|
|
81
|
+
* console.log(key.name, key.prefix, key.isActive);
|
|
82
|
+
* }
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
list(): Promise<ApiKey[]>;
|
|
86
|
+
/**
|
|
87
|
+
* Retrieves a specific API key by ID.
|
|
88
|
+
*
|
|
89
|
+
* @param keyId - The unique identifier of the API key
|
|
90
|
+
* @returns The API key object (without secret)
|
|
91
|
+
* @throws {NotFoundError} If no API key exists with the given ID
|
|
92
|
+
* @throws {AuthenticationError} If not authenticated
|
|
93
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const key = await client.apiKeys.get('key-uuid');
|
|
98
|
+
* console.log(key.name, key.scopes);
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
get(keyId: string): Promise<ApiKey>;
|
|
102
|
+
/**
|
|
103
|
+
* Creates a new API key.
|
|
104
|
+
*
|
|
105
|
+
* The full key string (including secret) is only returned on creation.
|
|
106
|
+
* Store it securely — it cannot be retrieved later.
|
|
107
|
+
*
|
|
108
|
+
* @param params - API key creation parameters
|
|
109
|
+
* @param params.name - Human-readable name for the key
|
|
110
|
+
* @param params.scopes - Permission scopes to grant
|
|
111
|
+
* @param params.vaultId - Optional vault ID to restrict the key to
|
|
112
|
+
* @param params.expiresAt - Optional ISO 8601 expiration date
|
|
113
|
+
* @returns API key object including the full key string
|
|
114
|
+
* @throws {ValidationError} If parameters are invalid
|
|
115
|
+
* @throws {AuthenticationError} If not authenticated
|
|
116
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* const apiKey = await client.apiKeys.create({
|
|
121
|
+
* name: 'Production Key',
|
|
122
|
+
* scopes: ['read', 'write'],
|
|
123
|
+
* vaultId: 'vault-123',
|
|
124
|
+
* expiresAt: '2027-01-01T00:00:00Z',
|
|
125
|
+
* });
|
|
126
|
+
* console.log('Save this key:', apiKey.key);
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
create(params: CreateApiKeyParams): Promise<ApiKeyWithSecret>;
|
|
130
|
+
/**
|
|
131
|
+
* Updates an existing API key.
|
|
132
|
+
*
|
|
133
|
+
* Only the provided fields are modified; omitted fields remain unchanged.
|
|
134
|
+
*
|
|
135
|
+
* @param keyId - The unique identifier of the API key to update
|
|
136
|
+
* @param params - Fields to update
|
|
137
|
+
* @param params.name - New name for the key
|
|
138
|
+
* @param params.isActive - Whether the key should be active
|
|
139
|
+
* @returns The updated API key object
|
|
140
|
+
* @throws {ValidationError} If parameters are invalid
|
|
141
|
+
* @throws {NotFoundError} If no API key exists with the given ID
|
|
142
|
+
* @throws {AuthenticationError} If not authenticated
|
|
143
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```typescript
|
|
147
|
+
* const updated = await client.apiKeys.update('key-uuid', {
|
|
148
|
+
* name: 'Renamed Key',
|
|
149
|
+
* isActive: false,
|
|
150
|
+
* });
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
update(keyId: string, params: UpdateApiKeyParams): Promise<ApiKey>;
|
|
154
|
+
/**
|
|
155
|
+
* Deletes an API key permanently.
|
|
156
|
+
*
|
|
157
|
+
* Once deleted, the key can no longer be used for authentication.
|
|
158
|
+
* This action is irreversible.
|
|
159
|
+
*
|
|
160
|
+
* @param keyId - The unique identifier of the API key to delete
|
|
161
|
+
* @throws {NotFoundError} If no API key exists with the given ID
|
|
162
|
+
* @throws {AuthenticationError} If not authenticated
|
|
163
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```typescript
|
|
167
|
+
* await client.apiKeys.delete('key-uuid');
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
delete(keyId: string): Promise<void>;
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL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