@gdrl/kronos-lib 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/README.md +208 -0
- package/dist/index.d.mts +336 -0
- package/dist/index.d.ts +336 -0
- package/dist/index.js +748 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +713 -0
- package/dist/index.mjs.map +1 -0
- package/dist/react/index.d.mts +162 -0
- package/dist/react/index.d.ts +162 -0
- package/dist/react/index.js +869 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/index.mjs +847 -0
- package/dist/react/index.mjs.map +1 -0
- package/dist/types-Gt5ZdRxW.d.mts +364 -0
- package/dist/types-Gt5ZdRxW.d.ts +364 -0
- package/package.json +55 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import { K as KronosClientConfig, I as IngestResponse, a as IngestStatusResponse, C as CreateMCPServerResponse, L as ListMCPServersResponse, G as GetMCPServerResponse, b as ConnectMCPServerResponse, R as RotateMCPServerTokenResponse, M as MemoryStatsResponse, S as ScratchsheetResponse, c as ListScopesResponse, d as GetScopeResponse, e as ScopeSpec, f as CreateScopeResponse, U as UpdateScopeResponse, g as ListTriggersResponse, h as CreateTriggerRequest, i as CreateTriggerResponse, T as TriggerRecord, j as UpdateTriggerRequest, k as UpdateTriggerResponse, D as DeleteTriggerResponse, l as CreateFrontendTokenResponse, m as SkillManageParams, n as SkillManageResponse, o as ContextGraphSummaryResponse, p as ContextGraphReadResponse } from './types-Gt5ZdRxW.js';
|
|
2
|
+
export { x as ConnectMCPServerRequest, Y as ContextGraphProcedureSummary, F as CreateFrontendTokenRequest, t as CreateMCPServerRequest, B as CreateScopeRequest, r as IngestMemoryDisposition, s as IngestRequest, q as IngestStatus, w as MCPServerDetails, u as MCPServerStatus, v as MCPServerToolCapabilities, O as OnTriggered, y as RotateMCPServerTokenRequest, A as ScopeDetail, z as ScopeSummary, N as SkillFileContentMode, P as SkillFileInput, Q as SkillFileRecord, H as SkillFileType, W as SkillMetadataRecord, J as SkillReadMode, X as SkillSummaryRecord, V as SkillTreeNode, E as TriggerType } from './types-Gt5ZdRxW.js';
|
|
3
|
+
|
|
4
|
+
declare class KronosClient {
|
|
5
|
+
private readonly workerUrl;
|
|
6
|
+
private readonly mastraUrl;
|
|
7
|
+
private readonly apiKey;
|
|
8
|
+
private readonly appId;
|
|
9
|
+
constructor(config: KronosClientConfig);
|
|
10
|
+
/**
|
|
11
|
+
* Perform a health check to verify the client can connect to the Kronos worker
|
|
12
|
+
* This is called automatically during initialization
|
|
13
|
+
*/
|
|
14
|
+
private healthCheck;
|
|
15
|
+
private workerFetch;
|
|
16
|
+
private mastraFetch;
|
|
17
|
+
private handleResponse;
|
|
18
|
+
/**
|
|
19
|
+
* Submit a document for ingestion.
|
|
20
|
+
* @param params - source_type, content, optional metadata, addToMemory, and idempotencyKey
|
|
21
|
+
* @returns ingest_id
|
|
22
|
+
*/
|
|
23
|
+
ingest(params: {
|
|
24
|
+
tenant_user_id: string;
|
|
25
|
+
source_type: string;
|
|
26
|
+
priority?: 'low' | 'medium' | 'high';
|
|
27
|
+
addToMemory?: boolean;
|
|
28
|
+
content: {
|
|
29
|
+
type: 'text';
|
|
30
|
+
text: string;
|
|
31
|
+
};
|
|
32
|
+
metadata?: Record<string, unknown>;
|
|
33
|
+
idempotencyKey?: string;
|
|
34
|
+
}): Promise<IngestResponse>;
|
|
35
|
+
/**
|
|
36
|
+
* Get the status of an ingest.
|
|
37
|
+
*/
|
|
38
|
+
getIngestStatus(ingestId: string): Promise<IngestStatusResponse>;
|
|
39
|
+
/**
|
|
40
|
+
* Create an MCP server scoped to the given scopes.
|
|
41
|
+
* Use connectMCPServer() to get a short-lived access token for MCP auth.
|
|
42
|
+
*/
|
|
43
|
+
createMCPServer(params: {
|
|
44
|
+
tenant_user_id: string;
|
|
45
|
+
name: string;
|
|
46
|
+
/** Omit or pass [] for all-memory access. */
|
|
47
|
+
scope_ids?: string[] | null;
|
|
48
|
+
description?: string;
|
|
49
|
+
options?: {
|
|
50
|
+
/** Expose `search_skills` and `read_skill`. Defaults to true. */
|
|
51
|
+
exposeSkillsTool?: boolean;
|
|
52
|
+
/** Expose the read-only `context_graph` tool. Defaults to false. */
|
|
53
|
+
exposeContextGraphTool?: boolean;
|
|
54
|
+
};
|
|
55
|
+
}): Promise<CreateMCPServerResponse>;
|
|
56
|
+
/**
|
|
57
|
+
* List MCP servers for a user. Returns metadata only (no token).
|
|
58
|
+
*/
|
|
59
|
+
listMCPServers(params: {
|
|
60
|
+
tenant_user_id: string;
|
|
61
|
+
}): Promise<ListMCPServersResponse>;
|
|
62
|
+
/**
|
|
63
|
+
* Get MCP server details for a user by server ID. Returns metadata only (no token).
|
|
64
|
+
*/
|
|
65
|
+
getMCPServer(params: {
|
|
66
|
+
tenant_user_id: string;
|
|
67
|
+
serverId: string;
|
|
68
|
+
}): Promise<GetMCPServerResponse>;
|
|
69
|
+
updateMCPServer(params: {
|
|
70
|
+
tenant_user_id: string;
|
|
71
|
+
serverId: string;
|
|
72
|
+
tool_capabilities: {
|
|
73
|
+
skills: boolean;
|
|
74
|
+
context_graph: boolean;
|
|
75
|
+
};
|
|
76
|
+
}): Promise<GetMCPServerResponse>;
|
|
77
|
+
/**
|
|
78
|
+
* Connect to an MCP server by ID and receive a short-lived access token.
|
|
79
|
+
* Use the returned access_token as Bearer token when calling the MCP endpoint.
|
|
80
|
+
*/
|
|
81
|
+
connectMCPServer(params: {
|
|
82
|
+
tenant_user_id: string;
|
|
83
|
+
serverId: string;
|
|
84
|
+
}): Promise<ConnectMCPServerResponse>;
|
|
85
|
+
/**
|
|
86
|
+
* Rotate the token for an MCP server. The new token is returned only on rotate.
|
|
87
|
+
*/
|
|
88
|
+
rotateMCPServerToken(params: {
|
|
89
|
+
tenant_user_id: string;
|
|
90
|
+
serverId: string;
|
|
91
|
+
}): Promise<RotateMCPServerTokenResponse>;
|
|
92
|
+
/**
|
|
93
|
+
* Get memory stats for a user (total claim count across entire memory graph).
|
|
94
|
+
* Worker caches the response for 5 minutes per user.
|
|
95
|
+
*/
|
|
96
|
+
getMemoryStats(params: {
|
|
97
|
+
tenant_user_id: string;
|
|
98
|
+
}): Promise<MemoryStatsResponse>;
|
|
99
|
+
/**
|
|
100
|
+
* Read the current scratchsheet document for a user.
|
|
101
|
+
*/
|
|
102
|
+
getScratchsheet(params: {
|
|
103
|
+
tenant_user_id: string;
|
|
104
|
+
}): Promise<ScratchsheetResponse>;
|
|
105
|
+
/**
|
|
106
|
+
* List scopes for a user. Returns full scope details. Cached 5 min per user.
|
|
107
|
+
*/
|
|
108
|
+
listScopes(params: {
|
|
109
|
+
tenant_user_id: string;
|
|
110
|
+
}): Promise<ListScopesResponse>;
|
|
111
|
+
/**
|
|
112
|
+
* Get a single scope by ID. Returns full scope details.
|
|
113
|
+
*/
|
|
114
|
+
getScope(params: {
|
|
115
|
+
tenant_user_id: string;
|
|
116
|
+
scope_id: string;
|
|
117
|
+
}): Promise<GetScopeResponse>;
|
|
118
|
+
/**
|
|
119
|
+
* Create a scope. A backfill job runs asynchronously to populate it.
|
|
120
|
+
* If spec.allowed_source_types is omitted, it defaults to ['all'].
|
|
121
|
+
* Uses the Worker so the scopes list cache is invalidated after create.
|
|
122
|
+
*/
|
|
123
|
+
createScope(params: {
|
|
124
|
+
tenant_user_id: string;
|
|
125
|
+
spec: ScopeSpec;
|
|
126
|
+
created_by: string;
|
|
127
|
+
description?: string;
|
|
128
|
+
}): Promise<CreateScopeResponse>;
|
|
129
|
+
/**
|
|
130
|
+
* Update a scope. Only provided fields are updated.
|
|
131
|
+
* If include_query, exclude_query, match_mode, time_range, or allowed_source_types change,
|
|
132
|
+
* a backfill job runs to recompute membership (response includes backfill_job_id).
|
|
133
|
+
* Otherwise only DB and Neo4j metadata are updated.
|
|
134
|
+
*/
|
|
135
|
+
updateScope(params: {
|
|
136
|
+
tenant_user_id: string;
|
|
137
|
+
scope_id: string;
|
|
138
|
+
name?: string;
|
|
139
|
+
description?: string | null;
|
|
140
|
+
include_query?: string;
|
|
141
|
+
exclude_query?: string | null;
|
|
142
|
+
match_mode?: 'strict' | 'broad';
|
|
143
|
+
time_range?: {
|
|
144
|
+
start?: string;
|
|
145
|
+
end?: string;
|
|
146
|
+
};
|
|
147
|
+
allowed_source_types?: string[] | 'all';
|
|
148
|
+
}): Promise<UpdateScopeResponse>;
|
|
149
|
+
/**
|
|
150
|
+
* Soft-delete a scope. Invalidates the scopes list cache for that user.
|
|
151
|
+
*/
|
|
152
|
+
deleteScope(params: {
|
|
153
|
+
tenant_user_id: string;
|
|
154
|
+
scope_id: string;
|
|
155
|
+
}): Promise<{
|
|
156
|
+
deleted: boolean;
|
|
157
|
+
}>;
|
|
158
|
+
/**
|
|
159
|
+
* Verify a webhook secret for a trigger.
|
|
160
|
+
* This method calls the Kronos worker API to verify the webhook secret.
|
|
161
|
+
*
|
|
162
|
+
* @param params - app_id, tenant_user_id, trigger_id and received_secret to verify
|
|
163
|
+
* @returns true if secret is valid, false otherwise
|
|
164
|
+
*/
|
|
165
|
+
verifyWebhookSecret(params: {
|
|
166
|
+
tenant_user_id: string;
|
|
167
|
+
trigger_id: string;
|
|
168
|
+
received_secret: string;
|
|
169
|
+
}): Promise<boolean>;
|
|
170
|
+
/**
|
|
171
|
+
* List triggers for a tenant user.
|
|
172
|
+
*/
|
|
173
|
+
listTriggers(params: {
|
|
174
|
+
tenant_user_id: string;
|
|
175
|
+
}): Promise<ListTriggersResponse>;
|
|
176
|
+
/**
|
|
177
|
+
* Create a trigger.
|
|
178
|
+
* Supports NL creation (trigger_description) or manual creation (trigger_type/trigger_spec).
|
|
179
|
+
*
|
|
180
|
+
* @returns CreateTriggerResponse (accepted for NL, trigger_id for manual)
|
|
181
|
+
*/
|
|
182
|
+
createTrigger(params: {
|
|
183
|
+
tenant_user_id: string;
|
|
184
|
+
webhook_url: string;
|
|
185
|
+
webhook_secret: string;
|
|
186
|
+
title?: string | null;
|
|
187
|
+
action_description?: string;
|
|
188
|
+
skill_id?: string;
|
|
189
|
+
skill_version_id?: string;
|
|
190
|
+
trigger_description?: string;
|
|
191
|
+
trigger_type?: CreateTriggerRequest['trigger_type'];
|
|
192
|
+
trigger_spec?: CreateTriggerRequest['trigger_spec'];
|
|
193
|
+
next_run_at?: string;
|
|
194
|
+
on_triggered?: CreateTriggerRequest['on_triggered'];
|
|
195
|
+
metadata?: Record<string, unknown>;
|
|
196
|
+
idempotencyKey?: string;
|
|
197
|
+
}): Promise<CreateTriggerResponse>;
|
|
198
|
+
/**
|
|
199
|
+
* Get details for a specific trigger.
|
|
200
|
+
* Uses listTriggers and filters by trigger_id.
|
|
201
|
+
*/
|
|
202
|
+
getTriggerDetails(params: {
|
|
203
|
+
tenant_user_id: string;
|
|
204
|
+
trigger_id: string;
|
|
205
|
+
}): Promise<TriggerRecord>;
|
|
206
|
+
/**
|
|
207
|
+
* Update a trigger.
|
|
208
|
+
* Updates the webhook_url, action_description, status, or metadata of an existing trigger.
|
|
209
|
+
*
|
|
210
|
+
* @param params - app_id, tenant_user_id, trigger_id and fields to update
|
|
211
|
+
* @returns UpdateTriggerResponse with success status
|
|
212
|
+
*/
|
|
213
|
+
updateTrigger(params: {
|
|
214
|
+
tenant_user_id: string;
|
|
215
|
+
trigger_id: string;
|
|
216
|
+
webhook_url?: string;
|
|
217
|
+
title?: string | null;
|
|
218
|
+
trigger_type?: UpdateTriggerRequest['trigger_type'];
|
|
219
|
+
trigger_spec?: UpdateTriggerRequest['trigger_spec'];
|
|
220
|
+
next_run_at?: UpdateTriggerRequest['next_run_at'];
|
|
221
|
+
action_description?: string;
|
|
222
|
+
skill_id?: string | null;
|
|
223
|
+
skill_version_id?: string | null;
|
|
224
|
+
on_triggered?: UpdateTriggerRequest['on_triggered'];
|
|
225
|
+
status?: string;
|
|
226
|
+
metadata?: Record<string, unknown>;
|
|
227
|
+
}): Promise<UpdateTriggerResponse>;
|
|
228
|
+
/**
|
|
229
|
+
* Delete a trigger.
|
|
230
|
+
*/
|
|
231
|
+
deleteTrigger(params: {
|
|
232
|
+
tenant_user_id: string;
|
|
233
|
+
trigger_id: string;
|
|
234
|
+
}): Promise<DeleteTriggerResponse>;
|
|
235
|
+
/**
|
|
236
|
+
* Issue a short-lived, user-scoped frontend token.
|
|
237
|
+
* The browser can use this token directly against the Kronos worker for
|
|
238
|
+
* allowed operations (e.g. trigger CRUD) without needing the app API key.
|
|
239
|
+
*
|
|
240
|
+
* This method must be called from a trusted server environment.
|
|
241
|
+
*/
|
|
242
|
+
createFrontendToken(params: {
|
|
243
|
+
tenantUserId: string;
|
|
244
|
+
ttlSeconds?: number;
|
|
245
|
+
ops?: string[];
|
|
246
|
+
}): Promise<CreateFrontendTokenResponse>;
|
|
247
|
+
/**
|
|
248
|
+
* Canonical skills API with operation-based contract.
|
|
249
|
+
*/
|
|
250
|
+
manageSkill(params: SkillManageParams): Promise<SkillManageResponse>;
|
|
251
|
+
private resolveContextGraphSkillId;
|
|
252
|
+
private parseContextGraphProcedures;
|
|
253
|
+
getContextGraph(params: {
|
|
254
|
+
tenant_user_id: string;
|
|
255
|
+
}): Promise<ContextGraphSummaryResponse>;
|
|
256
|
+
readContextGraph(params: {
|
|
257
|
+
tenant_user_id: string;
|
|
258
|
+
path?: string;
|
|
259
|
+
}): Promise<ContextGraphReadResponse>;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Generate an idempotency key for ingest requests.
|
|
264
|
+
* Uses crypto.randomUUID() when available; falls back to a timestamp-based value.
|
|
265
|
+
* Callers can pass their own key via the ingest options to achieve true idempotency.
|
|
266
|
+
*/
|
|
267
|
+
declare function generateIdempotencyKey(): string;
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Webhook verification utilities for Kronos triggers
|
|
271
|
+
* Provides secure constant-time comparison for webhook secrets
|
|
272
|
+
*/
|
|
273
|
+
/**
|
|
274
|
+
* Verify a webhook secret using constant-time comparison to prevent timing attacks.
|
|
275
|
+
*
|
|
276
|
+
* @param receivedSecret - The secret received in the webhook header
|
|
277
|
+
* @param storedSecret - The secret stored in the database for the trigger
|
|
278
|
+
* @returns true if secrets match, false otherwise
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* ```typescript
|
|
282
|
+
* import { verifyWebhookSecret } from '@gdrl/kronos-lib/webhook-verification';
|
|
283
|
+
*
|
|
284
|
+
* const isValid = verifyWebhookSecret(
|
|
285
|
+
* request.headers.get('X-Kronos-Webhook-Secret'),
|
|
286
|
+
* trigger.webhook_secret
|
|
287
|
+
* );
|
|
288
|
+
*
|
|
289
|
+
* if (!isValid) {
|
|
290
|
+
* return new Response('Unauthorized', { status: 401 });
|
|
291
|
+
* }
|
|
292
|
+
* ```
|
|
293
|
+
*/
|
|
294
|
+
declare function verifyWebhookSecret(receivedSecret: string | null | undefined, storedSecret: string | null | undefined): boolean;
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Base error for Kronos API failures
|
|
298
|
+
*/
|
|
299
|
+
declare class KronosError extends Error {
|
|
300
|
+
readonly status?: number | undefined;
|
|
301
|
+
readonly code?: string | undefined;
|
|
302
|
+
readonly body?: unknown | undefined;
|
|
303
|
+
constructor(message: string, status?: number | undefined, code?: string | undefined, body?: unknown | undefined);
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* 400 Bad Request - invalid or missing parameters
|
|
307
|
+
*/
|
|
308
|
+
declare class KronosBadRequestError extends KronosError {
|
|
309
|
+
constructor(message: string, body?: unknown);
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* 401 Unauthorized - invalid or missing API key
|
|
313
|
+
*/
|
|
314
|
+
declare class KronosUnauthorizedError extends KronosError {
|
|
315
|
+
constructor(message: string, body?: unknown);
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* 403 Forbidden - valid auth but insufficient permissions
|
|
319
|
+
*/
|
|
320
|
+
declare class KronosForbiddenError extends KronosError {
|
|
321
|
+
constructor(message: string, body?: unknown);
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* 404 Not Found - resource does not exist
|
|
325
|
+
*/
|
|
326
|
+
declare class KronosNotFoundError extends KronosError {
|
|
327
|
+
constructor(message: string, body?: unknown);
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* 5xx or network/unknown errors
|
|
331
|
+
*/
|
|
332
|
+
declare class KronosServerError extends KronosError {
|
|
333
|
+
constructor(message: string, status?: number, body?: unknown);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
export { ConnectMCPServerResponse, ContextGraphReadResponse, ContextGraphSummaryResponse, CreateFrontendTokenResponse, CreateMCPServerResponse, CreateScopeResponse, CreateTriggerRequest, CreateTriggerResponse, DeleteTriggerResponse, GetMCPServerResponse, GetScopeResponse, IngestResponse, IngestStatusResponse, KronosBadRequestError, KronosClient, KronosClientConfig, KronosError, KronosForbiddenError, KronosNotFoundError, KronosServerError, KronosUnauthorizedError, ListMCPServersResponse, ListScopesResponse, ListTriggersResponse, MemoryStatsResponse, RotateMCPServerTokenResponse, ScopeSpec, ScratchsheetResponse, SkillManageParams, SkillManageResponse, TriggerRecord, UpdateTriggerRequest, UpdateTriggerResponse, generateIdempotencyKey, verifyWebhookSecret };
|