@kontext-dev/js-sdk 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.
Files changed (84) hide show
  1. package/README.md +70 -0
  2. package/dist/adapters/ai/index.cjs +175 -0
  3. package/dist/adapters/ai/index.cjs.map +1 -0
  4. package/dist/adapters/ai/index.d.cts +51 -0
  5. package/dist/adapters/ai/index.d.ts +51 -0
  6. package/dist/adapters/ai/index.js +173 -0
  7. package/dist/adapters/ai/index.js.map +1 -0
  8. package/dist/adapters/cloudflare/index.cjs +598 -0
  9. package/dist/adapters/cloudflare/index.cjs.map +1 -0
  10. package/dist/adapters/cloudflare/index.d.cts +214 -0
  11. package/dist/adapters/cloudflare/index.d.ts +214 -0
  12. package/dist/adapters/cloudflare/index.js +594 -0
  13. package/dist/adapters/cloudflare/index.js.map +1 -0
  14. package/dist/adapters/cloudflare/react.cjs +156 -0
  15. package/dist/adapters/cloudflare/react.cjs.map +1 -0
  16. package/dist/adapters/cloudflare/react.d.cts +68 -0
  17. package/dist/adapters/cloudflare/react.d.ts +68 -0
  18. package/dist/adapters/cloudflare/react.js +152 -0
  19. package/dist/adapters/cloudflare/react.js.map +1 -0
  20. package/dist/adapters/react/index.cjs +146 -0
  21. package/dist/adapters/react/index.cjs.map +1 -0
  22. package/dist/adapters/react/index.d.cts +103 -0
  23. package/dist/adapters/react/index.d.ts +103 -0
  24. package/dist/adapters/react/index.js +142 -0
  25. package/dist/adapters/react/index.js.map +1 -0
  26. package/dist/client/index.cjs +2415 -0
  27. package/dist/client/index.cjs.map +1 -0
  28. package/dist/client/index.d.cts +125 -0
  29. package/dist/client/index.d.ts +125 -0
  30. package/dist/client/index.js +2412 -0
  31. package/dist/client/index.js.map +1 -0
  32. package/dist/errors.cjs +213 -0
  33. package/dist/errors.cjs.map +1 -0
  34. package/dist/errors.d.cts +161 -0
  35. package/dist/errors.d.ts +161 -0
  36. package/dist/errors.js +201 -0
  37. package/dist/errors.js.map +1 -0
  38. package/dist/index-D5hS5PGn.d.ts +54 -0
  39. package/dist/index-DcL4a5Vq.d.cts +54 -0
  40. package/dist/index.cjs +4046 -0
  41. package/dist/index.cjs.map +1 -0
  42. package/dist/index.d.cts +15 -0
  43. package/dist/index.d.ts +15 -0
  44. package/dist/index.js +4029 -0
  45. package/dist/index.js.map +1 -0
  46. package/dist/kontext-CgIBANFo.d.cts +308 -0
  47. package/dist/kontext-CgIBANFo.d.ts +308 -0
  48. package/dist/management/index.cjs +867 -0
  49. package/dist/management/index.cjs.map +1 -0
  50. package/dist/management/index.d.cts +467 -0
  51. package/dist/management/index.d.ts +467 -0
  52. package/dist/management/index.js +855 -0
  53. package/dist/management/index.js.map +1 -0
  54. package/dist/mcp/index.cjs +799 -0
  55. package/dist/mcp/index.cjs.map +1 -0
  56. package/dist/mcp/index.d.cts +231 -0
  57. package/dist/mcp/index.d.ts +231 -0
  58. package/dist/mcp/index.js +797 -0
  59. package/dist/mcp/index.js.map +1 -0
  60. package/dist/oauth/index.cjs +418 -0
  61. package/dist/oauth/index.cjs.map +1 -0
  62. package/dist/oauth/index.d.cts +235 -0
  63. package/dist/oauth/index.d.ts +235 -0
  64. package/dist/oauth/index.js +414 -0
  65. package/dist/oauth/index.js.map +1 -0
  66. package/dist/server/index.cjs +1634 -0
  67. package/dist/server/index.cjs.map +1 -0
  68. package/dist/server/index.d.cts +10 -0
  69. package/dist/server/index.d.ts +10 -0
  70. package/dist/server/index.js +1629 -0
  71. package/dist/server/index.js.map +1 -0
  72. package/dist/types-CzhnlJHW.d.cts +397 -0
  73. package/dist/types-CzhnlJHW.d.ts +397 -0
  74. package/dist/types-RIzHnRpk.d.cts +23 -0
  75. package/dist/types-RIzHnRpk.d.ts +23 -0
  76. package/dist/verifier-CoJmYiw3.d.cts +109 -0
  77. package/dist/verifier-CoJmYiw3.d.ts +109 -0
  78. package/dist/verify/index.cjs +319 -0
  79. package/dist/verify/index.cjs.map +1 -0
  80. package/dist/verify/index.d.cts +63 -0
  81. package/dist/verify/index.d.ts +63 -0
  82. package/dist/verify/index.js +315 -0
  83. package/dist/verify/index.js.map +1 -0
  84. package/package.json +221 -0
@@ -0,0 +1,467 @@
1
+ import { C as CreateServiceAccountInput, b as CreateServiceAccountResponse, P as PaginationParams, L as ListServiceAccountsResponse, S as ServiceAccountResponse, R as RotateSecretResponse, c as CreateApplicationInput, d as CreateApplicationResponse, e as ListApplicationsResponse, A as ApplicationResponse, U as UpdateApplicationInput, f as ApplicationOAuthResponse, g as UpdateApplicationOAuthInput, h as RotateApplicationSecretResponse, i as ApplicationIntegrationsResponse, j as UpdateApplicationIntegrationsInput, k as RevokeAllSessionsResponse, l as CreateIntegrationInput, m as CreateIntegrationResponse, n as ListIntegrationsResponse, I as IntegrationResponse, o as UpdateIntegrationInput, V as ValidateIntegrationResponse, p as ListAgentSessionsResponse, q as AgentSessionResponse, M as McpEventListResponse, r as ListTracesResponse, s as TraceResponse, t as TraceStatsResponse, K as KontextManagementClientConfig } from '../types-CzhnlJHW.js';
2
+ export { u as AddUserTokenInput, v as AgentSession, w as AgentSessionDerivedStatus, x as AgentSessionStatus, y as Application, z as ApplicationOAuth, B as ConnectionResponse, D as ConnectionStatus, E as ConnectionStatusResponse, F as CreateApplicationOAuthInput, G as Integration, H as IntegrationAuthMode, J as IntegrationCapabilities, N as IntegrationOAuthConfigInput, O as IntegrationOAuthSummary, Q as IntegrationValidationStatus, W as ListEventsResponse, X as McpEvent, Y as OAuthTokens, Z as ServiceAccount, _ as TOKEN_EXCHANGE_GRANT_TYPE, $ as TOKEN_TYPE_ACCESS_TOKEN, T as TokenExchangeRequest, a as TokenExchangeResponse, a0 as Trace, a1 as TraceEvent, a2 as TraceStats } from '../types-CzhnlJHW.js';
3
+
4
+ /**
5
+ * Service account authentication using OAuth 2.0 client_credentials flow
6
+ */
7
+ interface ServiceAccountCredentials {
8
+ clientId: string;
9
+ clientSecret: string;
10
+ }
11
+ interface AccessToken {
12
+ accessToken: string;
13
+ tokenType: string;
14
+ expiresAt: Date | null;
15
+ scope?: string;
16
+ }
17
+ /**
18
+ * Authenticates using the OAuth 2.0 client_credentials grant
19
+ * @param tokenUrl The token endpoint URL
20
+ * @param credentials Service account client credentials
21
+ * @param scopes Optional scopes to request
22
+ * @param audience Optional audience for the token
23
+ * @returns Access token response
24
+ */
25
+ declare function authenticateServiceAccount(tokenUrl: string, credentials: ServiceAccountCredentials, scopes?: string[], audience?: string): Promise<AccessToken>;
26
+ /**
27
+ * Token manager for automatic token refresh
28
+ */
29
+ declare class TokenManager {
30
+ private readonly tokenUrl;
31
+ private readonly credentials;
32
+ private readonly scopes?;
33
+ private readonly audience?;
34
+ private token;
35
+ private tokenPromise;
36
+ private readonly bufferSeconds;
37
+ constructor(tokenUrl: string, credentials: ServiceAccountCredentials, scopes?: string[] | undefined, audience?: string | undefined);
38
+ /**
39
+ * Get a valid access token, refreshing if necessary
40
+ */
41
+ getAccessToken(): Promise<string>;
42
+ /**
43
+ * Force a token refresh
44
+ */
45
+ refresh(): Promise<AccessToken>;
46
+ /**
47
+ * Clear the cached token
48
+ */
49
+ clear(): void;
50
+ private isExpired;
51
+ }
52
+
53
+ /**
54
+ * HTTP client utilities for the Management API
55
+ */
56
+
57
+ interface HttpClientConfig {
58
+ baseUrl: string;
59
+ apiVersion: string;
60
+ tokenManager: TokenManager;
61
+ }
62
+ /**
63
+ * Internal HTTP client for making authenticated API requests
64
+ */
65
+ declare class HttpClient {
66
+ private readonly config;
67
+ private readonly baseUrl;
68
+ constructor(config: HttpClientConfig);
69
+ /**
70
+ * Make a GET request
71
+ */
72
+ get<T>(path: string, params?: Record<string, string | number | undefined>): Promise<T>;
73
+ /**
74
+ * Make a POST request
75
+ */
76
+ post<T>(path: string, body?: unknown): Promise<T>;
77
+ /**
78
+ * Make a POST request without expecting a response body
79
+ */
80
+ postNoContent(path: string, body?: unknown): Promise<void>;
81
+ /**
82
+ * Make a PUT request
83
+ */
84
+ put<T>(path: string, body?: unknown): Promise<T>;
85
+ /**
86
+ * Make a PATCH request
87
+ */
88
+ patch<T>(path: string, body?: unknown): Promise<T>;
89
+ /**
90
+ * Make a DELETE request
91
+ */
92
+ delete(path: string): Promise<void>;
93
+ /**
94
+ * Make a DELETE request expecting a response body
95
+ */
96
+ deleteJson<T>(path: string): Promise<T>;
97
+ private buildUrl;
98
+ private request;
99
+ }
100
+
101
+ /**
102
+ * Service Accounts resource methods
103
+ */
104
+
105
+ /**
106
+ * Service Accounts API methods
107
+ */
108
+ declare class ServiceAccountsResource {
109
+ private readonly http;
110
+ constructor(http: HttpClient);
111
+ /**
112
+ * Create a new service account
113
+ * @param input Service account creation parameters
114
+ * @returns The created service account with credentials
115
+ */
116
+ create(input: CreateServiceAccountInput): Promise<CreateServiceAccountResponse>;
117
+ /**
118
+ * List all service accounts
119
+ * @param pagination Optional pagination parameters
120
+ * @returns List of service accounts
121
+ */
122
+ list(pagination?: PaginationParams): Promise<ListServiceAccountsResponse>;
123
+ /**
124
+ * Get a service account by ID
125
+ * @param id Service account ID
126
+ * @returns The service account
127
+ */
128
+ get(id: string): Promise<ServiceAccountResponse>;
129
+ /**
130
+ * Rotate a service account's client secret
131
+ * @param id Service account ID
132
+ * @returns New credentials
133
+ */
134
+ rotateSecret(id: string): Promise<RotateSecretResponse>;
135
+ /**
136
+ * Revoke (delete) a service account
137
+ * @param id Service account ID
138
+ */
139
+ revoke(id: string): Promise<void>;
140
+ }
141
+
142
+ /**
143
+ * Applications resource methods
144
+ */
145
+
146
+ /**
147
+ * Applications API methods
148
+ */
149
+ declare class ApplicationsResource {
150
+ private readonly http;
151
+ constructor(http: HttpClient);
152
+ /**
153
+ * Create a new application
154
+ * @param input Application creation parameters
155
+ * @returns The created application with OAuth config
156
+ */
157
+ create(input: CreateApplicationInput): Promise<CreateApplicationResponse>;
158
+ /**
159
+ * List all applications
160
+ * @param pagination Optional pagination parameters
161
+ * @returns List of applications
162
+ */
163
+ list(pagination?: PaginationParams): Promise<ListApplicationsResponse>;
164
+ /**
165
+ * Get an application by ID
166
+ * @param id Application ID
167
+ * @returns The application
168
+ */
169
+ get(id: string): Promise<ApplicationResponse>;
170
+ /**
171
+ * Update an application
172
+ * @param id Application ID
173
+ * @param input Update parameters
174
+ * @returns The updated application
175
+ */
176
+ update(id: string, input: UpdateApplicationInput): Promise<ApplicationResponse>;
177
+ /**
178
+ * Archive an application (soft delete)
179
+ * @param id Application ID
180
+ */
181
+ archive(id: string): Promise<void>;
182
+ /**
183
+ * Get an application's OAuth configuration
184
+ * @param id Application ID
185
+ * @returns The OAuth configuration
186
+ */
187
+ getOAuth(id: string): Promise<ApplicationOAuthResponse>;
188
+ /**
189
+ * Update an application's OAuth configuration
190
+ * @param id Application ID
191
+ * @param input OAuth update parameters
192
+ * @returns The updated OAuth configuration
193
+ */
194
+ updateOAuth(id: string, input: UpdateApplicationOAuthInput): Promise<ApplicationOAuthResponse>;
195
+ /**
196
+ * Rotate an application's client secret (confidential clients only)
197
+ * @param id Application ID
198
+ * @returns The new OAuth configuration with new secret
199
+ */
200
+ rotateSecret(id: string): Promise<RotateApplicationSecretResponse>;
201
+ /**
202
+ * List integrations attached to an application
203
+ * @param id Application ID
204
+ * @returns List of integration IDs
205
+ */
206
+ listIntegrations(id: string): Promise<ApplicationIntegrationsResponse>;
207
+ /**
208
+ * Set the integrations attached to an application (replaces all)
209
+ * @param id Application ID
210
+ * @param input Integration IDs to attach
211
+ * @returns Updated list of integration IDs
212
+ */
213
+ setIntegrations(id: string, input: UpdateApplicationIntegrationsInput): Promise<ApplicationIntegrationsResponse>;
214
+ /**
215
+ * Attach a single integration to an application
216
+ * @param id Application ID
217
+ * @param integrationId Integration ID to attach
218
+ */
219
+ attachIntegration(id: string, integrationId: string): Promise<void>;
220
+ /**
221
+ * Detach a single integration from an application
222
+ * @param id Application ID
223
+ * @param integrationId Integration ID to detach
224
+ */
225
+ detachIntegration(id: string, integrationId: string): Promise<void>;
226
+ /**
227
+ * Revoke all agent sessions for an application
228
+ * @param id Application ID
229
+ */
230
+ revokeAllAgentSessions(id: string): Promise<RevokeAllSessionsResponse>;
231
+ }
232
+
233
+ /**
234
+ * Integrations resource methods
235
+ */
236
+
237
+ /**
238
+ * Integrations API methods
239
+ */
240
+ declare class IntegrationsResource {
241
+ private readonly http;
242
+ constructor(http: HttpClient);
243
+ /**
244
+ * Create a new integration
245
+ * @param input Integration creation parameters
246
+ * @returns The created integration
247
+ */
248
+ create(input: CreateIntegrationInput): Promise<CreateIntegrationResponse>;
249
+ /**
250
+ * List all integrations
251
+ * @param pagination Optional pagination parameters
252
+ * @returns List of integrations
253
+ */
254
+ list(pagination?: PaginationParams): Promise<ListIntegrationsResponse>;
255
+ /**
256
+ * Get an integration by ID
257
+ * @param id Integration ID
258
+ * @returns The integration
259
+ */
260
+ get(id: string): Promise<IntegrationResponse>;
261
+ /**
262
+ * Update an integration
263
+ * @param id Integration ID
264
+ * @param input Update parameters
265
+ * @returns The updated integration
266
+ */
267
+ update(id: string, input: UpdateIntegrationInput): Promise<IntegrationResponse>;
268
+ /**
269
+ * Archive an integration (soft delete)
270
+ * @param id Integration ID
271
+ */
272
+ archive(id: string): Promise<void>;
273
+ /**
274
+ * Validate an integration (test connectivity)
275
+ * @param id Integration ID
276
+ * @returns Validation result
277
+ */
278
+ validate(id: string): Promise<ValidateIntegrationResponse>;
279
+ }
280
+
281
+ /**
282
+ * Agent Sessions resource methods
283
+ */
284
+
285
+ interface ListAgentSessionsParams {
286
+ /** Include inactive sessions (disconnected/expired) */
287
+ includeInactive?: boolean;
288
+ /** Filter by status; "all" or "inactive" enables includeInactive */
289
+ status?: "active" | "inactive" | "all";
290
+ /** Limit number of sessions returned */
291
+ limit?: number;
292
+ }
293
+ /**
294
+ * Agent Sessions API methods
295
+ */
296
+ declare class AgentSessionsResource {
297
+ private readonly http;
298
+ constructor(http: HttpClient);
299
+ /**
300
+ * List all agent sessions
301
+ * @param params Optional filter and pagination parameters
302
+ * @returns List of agent sessions
303
+ */
304
+ list(applicationId: string, params?: ListAgentSessionsParams): Promise<ListAgentSessionsResponse>;
305
+ /**
306
+ * Get an agent session by ID
307
+ * @param id Agent session ID
308
+ * @returns The agent session
309
+ */
310
+ get(applicationId: string, sessionId: string): Promise<AgentSessionResponse>;
311
+ /**
312
+ * Revoke all sessions for an application
313
+ */
314
+ revokeAll(applicationId: string): Promise<RevokeAllSessionsResponse>;
315
+ }
316
+
317
+ /**
318
+ * Traces and Events resource methods
319
+ */
320
+
321
+ interface ListTracesParams extends PaginationParams {
322
+ /** Filter by owner user ID (admin/owner only) */
323
+ userId?: string;
324
+ /** Filter by agent/application ID */
325
+ agentId?: string;
326
+ /** Filter by application ID (legacy alias for agentId) */
327
+ applicationId?: string;
328
+ /** Filter by agent session ID */
329
+ sessionId?: string;
330
+ /** Offset for pagination */
331
+ offset?: number;
332
+ /** @deprecated No longer supported by the API */
333
+ startAfter?: string;
334
+ /** @deprecated No longer supported by the API */
335
+ startBefore?: string;
336
+ }
337
+ interface ListEventsParams extends PaginationParams {
338
+ /** Maximum number of events to return (default: 100, max: 200) */
339
+ limit?: number;
340
+ }
341
+ interface TraceStatsParams {
342
+ /** Period window ("1d", "7d", "30d") */
343
+ period?: string;
344
+ /** Filter by owner user ID (admin/owner only) */
345
+ userId?: string;
346
+ /** @deprecated No longer supported by the API */
347
+ applicationId?: string;
348
+ /** @deprecated Legacy input; mapped to period when possible */
349
+ startTime?: string;
350
+ /** @deprecated Legacy input; currently unused */
351
+ endTime?: string;
352
+ }
353
+ /**
354
+ * Traces API methods
355
+ */
356
+ declare class TracesResource {
357
+ private readonly http;
358
+ constructor(http: HttpClient);
359
+ /**
360
+ * List traces
361
+ * @param params Optional filter and pagination parameters
362
+ * @returns List of traces
363
+ */
364
+ list(params?: ListTracesParams): Promise<ListTracesResponse>;
365
+ /**
366
+ * Get a trace by ID with its events
367
+ * @param id Trace ID
368
+ * @returns The trace with events
369
+ */
370
+ get(id: string, params?: {
371
+ userId?: string;
372
+ }): Promise<TraceResponse>;
373
+ /**
374
+ * Get trace statistics
375
+ * @param params Optional filter parameters
376
+ * @returns Trace statistics
377
+ */
378
+ stats(params?: TraceStatsParams): Promise<TraceStatsResponse>;
379
+ }
380
+ /**
381
+ * Events API methods
382
+ */
383
+ declare class EventsResource {
384
+ private readonly http;
385
+ constructor(http: HttpClient);
386
+ /**
387
+ * List events
388
+ * @param params Optional filter and pagination parameters
389
+ * @returns List of events
390
+ */
391
+ list(params?: ListEventsParams): Promise<McpEventListResponse>;
392
+ }
393
+
394
+ /**
395
+ * KontextManagementClient - Control plane client for administrative operations
396
+ */
397
+
398
+ /**
399
+ * Management API client for Kontext
400
+ *
401
+ * Use this client for administrative operations like:
402
+ * - Creating and managing service accounts
403
+ * - Creating and configuring applications
404
+ * - Managing integrations
405
+ * - Viewing agent sessions and traces
406
+ *
407
+ * @example
408
+ * ```typescript
409
+ * const client = new KontextManagementClient({
410
+ * baseUrl: 'https://api.kontext.dev',
411
+ * credentials: {
412
+ * clientId: 'your-service-account-client-id',
413
+ * clientSecret: 'your-service-account-client-secret',
414
+ * },
415
+ * });
416
+ *
417
+ * // Create an application
418
+ * const { application, oauth } = await client.applications.create({
419
+ * name: 'My Agent',
420
+ * oauth: {
421
+ * redirectUris: ['http://localhost:3000/callback'],
422
+ * },
423
+ * });
424
+ *
425
+ * // Create an integration
426
+ * const { integration } = await client.integrations.create({
427
+ * name: 'GitHub',
428
+ * url: 'https://mcp.github.com/sse',
429
+ * authMode: 'oauth',
430
+ * oauth: { provider: 'github' },
431
+ * });
432
+ *
433
+ * // Attach integration to application
434
+ * await client.applications.attachIntegration(application.id, integration.id);
435
+ * ```
436
+ */
437
+ declare class KontextManagementClient {
438
+ private readonly tokenManager;
439
+ private readonly http;
440
+ /** Service Accounts resource */
441
+ readonly serviceAccounts: ServiceAccountsResource;
442
+ /** Applications resource */
443
+ readonly applications: ApplicationsResource;
444
+ /** Integrations resource */
445
+ readonly integrations: IntegrationsResource;
446
+ /** Agent Sessions resource (alias: agentInstances) */
447
+ readonly agentSessions: AgentSessionsResource;
448
+ /** Agent Instances resource (alias for agentSessions, future naming) */
449
+ readonly agentInstances: AgentSessionsResource;
450
+ /** Traces resource */
451
+ readonly traces: TracesResource;
452
+ /** Events resource */
453
+ readonly events: EventsResource;
454
+ constructor(config: KontextManagementClientConfig);
455
+ /**
456
+ * Force refresh the access token
457
+ * Useful if you need to ensure a fresh token before a critical operation
458
+ */
459
+ refreshToken(): Promise<void>;
460
+ /**
461
+ * Clear the cached access token
462
+ * Useful when credentials have been rotated
463
+ */
464
+ clearToken(): void;
465
+ }
466
+
467
+ export { type AccessToken, AgentSessionResponse, AgentSessionsResource, ApplicationIntegrationsResponse, ApplicationOAuthResponse, ApplicationResponse, ApplicationsResource, CreateApplicationInput, CreateApplicationResponse, CreateIntegrationInput, CreateIntegrationResponse, CreateServiceAccountInput, CreateServiceAccountResponse, EventsResource, IntegrationResponse, IntegrationsResource, KontextManagementClient, KontextManagementClientConfig, type ListAgentSessionsParams, ListAgentSessionsResponse, ListApplicationsResponse, type ListEventsParams, ListIntegrationsResponse, ListServiceAccountsResponse, type ListTracesParams, ListTracesResponse, McpEventListResponse, PaginationParams, RevokeAllSessionsResponse, RotateApplicationSecretResponse, RotateSecretResponse, type ServiceAccountCredentials, ServiceAccountResponse, ServiceAccountsResource, TokenManager, TraceResponse, type TraceStatsParams, TraceStatsResponse, TracesResource, UpdateApplicationInput, UpdateApplicationIntegrationsInput, UpdateApplicationOAuthInput, UpdateIntegrationInput, ValidateIntegrationResponse, authenticateServiceAccount };