@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.
- package/README.md +70 -0
- package/dist/adapters/ai/index.cjs +175 -0
- package/dist/adapters/ai/index.cjs.map +1 -0
- package/dist/adapters/ai/index.d.cts +51 -0
- package/dist/adapters/ai/index.d.ts +51 -0
- package/dist/adapters/ai/index.js +173 -0
- package/dist/adapters/ai/index.js.map +1 -0
- package/dist/adapters/cloudflare/index.cjs +598 -0
- package/dist/adapters/cloudflare/index.cjs.map +1 -0
- package/dist/adapters/cloudflare/index.d.cts +214 -0
- package/dist/adapters/cloudflare/index.d.ts +214 -0
- package/dist/adapters/cloudflare/index.js +594 -0
- package/dist/adapters/cloudflare/index.js.map +1 -0
- package/dist/adapters/cloudflare/react.cjs +156 -0
- package/dist/adapters/cloudflare/react.cjs.map +1 -0
- package/dist/adapters/cloudflare/react.d.cts +68 -0
- package/dist/adapters/cloudflare/react.d.ts +68 -0
- package/dist/adapters/cloudflare/react.js +152 -0
- package/dist/adapters/cloudflare/react.js.map +1 -0
- package/dist/adapters/react/index.cjs +146 -0
- package/dist/adapters/react/index.cjs.map +1 -0
- package/dist/adapters/react/index.d.cts +103 -0
- package/dist/adapters/react/index.d.ts +103 -0
- package/dist/adapters/react/index.js +142 -0
- package/dist/adapters/react/index.js.map +1 -0
- package/dist/client/index.cjs +2415 -0
- package/dist/client/index.cjs.map +1 -0
- package/dist/client/index.d.cts +125 -0
- package/dist/client/index.d.ts +125 -0
- package/dist/client/index.js +2412 -0
- package/dist/client/index.js.map +1 -0
- package/dist/errors.cjs +213 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.cts +161 -0
- package/dist/errors.d.ts +161 -0
- package/dist/errors.js +201 -0
- package/dist/errors.js.map +1 -0
- package/dist/index-D5hS5PGn.d.ts +54 -0
- package/dist/index-DcL4a5Vq.d.cts +54 -0
- package/dist/index.cjs +4046 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +4029 -0
- package/dist/index.js.map +1 -0
- package/dist/kontext-CgIBANFo.d.cts +308 -0
- package/dist/kontext-CgIBANFo.d.ts +308 -0
- package/dist/management/index.cjs +867 -0
- package/dist/management/index.cjs.map +1 -0
- package/dist/management/index.d.cts +467 -0
- package/dist/management/index.d.ts +467 -0
- package/dist/management/index.js +855 -0
- package/dist/management/index.js.map +1 -0
- package/dist/mcp/index.cjs +799 -0
- package/dist/mcp/index.cjs.map +1 -0
- package/dist/mcp/index.d.cts +231 -0
- package/dist/mcp/index.d.ts +231 -0
- package/dist/mcp/index.js +797 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/oauth/index.cjs +418 -0
- package/dist/oauth/index.cjs.map +1 -0
- package/dist/oauth/index.d.cts +235 -0
- package/dist/oauth/index.d.ts +235 -0
- package/dist/oauth/index.js +414 -0
- package/dist/oauth/index.js.map +1 -0
- package/dist/server/index.cjs +1634 -0
- package/dist/server/index.cjs.map +1 -0
- package/dist/server/index.d.cts +10 -0
- package/dist/server/index.d.ts +10 -0
- package/dist/server/index.js +1629 -0
- package/dist/server/index.js.map +1 -0
- package/dist/types-CzhnlJHW.d.cts +397 -0
- package/dist/types-CzhnlJHW.d.ts +397 -0
- package/dist/types-RIzHnRpk.d.cts +23 -0
- package/dist/types-RIzHnRpk.d.ts +23 -0
- package/dist/verifier-CoJmYiw3.d.cts +109 -0
- package/dist/verifier-CoJmYiw3.d.ts +109 -0
- package/dist/verify/index.cjs +319 -0
- package/dist/verify/index.cjs.map +1 -0
- package/dist/verify/index.d.cts +63 -0
- package/dist/verify/index.d.ts +63 -0
- package/dist/verify/index.js +315 -0
- package/dist/verify/index.js.map +1 -0
- package/package.json +221 -0
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core types for the Kontext SDK
|
|
3
|
+
* These mirror the API DTOs for type-safe interactions
|
|
4
|
+
*/
|
|
5
|
+
interface Application {
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
canModify?: boolean;
|
|
9
|
+
activeSessionCount?: number;
|
|
10
|
+
idleSessionCount?: number;
|
|
11
|
+
liveSessionCount?: number;
|
|
12
|
+
totalSessionCount?: number;
|
|
13
|
+
oauth?: ApplicationOAuth;
|
|
14
|
+
archivedAt?: string;
|
|
15
|
+
createdAt: string;
|
|
16
|
+
updatedAt: string;
|
|
17
|
+
}
|
|
18
|
+
interface ApplicationOAuth {
|
|
19
|
+
type: "public" | "confidential";
|
|
20
|
+
clientId: string;
|
|
21
|
+
clientSecret?: string;
|
|
22
|
+
pkceRequired: boolean;
|
|
23
|
+
scopes: string[];
|
|
24
|
+
authorizationUrl: string;
|
|
25
|
+
tokenUrl: string;
|
|
26
|
+
gatewayUrl: string;
|
|
27
|
+
redirectUris: string[];
|
|
28
|
+
}
|
|
29
|
+
interface CreateApplicationOAuthInput {
|
|
30
|
+
type?: "public" | "confidential";
|
|
31
|
+
redirectUris: string[];
|
|
32
|
+
pkceRequired?: boolean;
|
|
33
|
+
scopes?: string[];
|
|
34
|
+
}
|
|
35
|
+
interface CreateApplicationInput {
|
|
36
|
+
name: string;
|
|
37
|
+
oauth: CreateApplicationOAuthInput;
|
|
38
|
+
}
|
|
39
|
+
interface UpdateApplicationInput {
|
|
40
|
+
name?: string;
|
|
41
|
+
}
|
|
42
|
+
interface UpdateApplicationOAuthInput {
|
|
43
|
+
pkceRequired?: boolean;
|
|
44
|
+
scopes?: string[];
|
|
45
|
+
redirectUris?: string[];
|
|
46
|
+
}
|
|
47
|
+
interface CreateApplicationResponse {
|
|
48
|
+
application: Application;
|
|
49
|
+
oauth: ApplicationOAuth;
|
|
50
|
+
}
|
|
51
|
+
interface ApplicationResponse {
|
|
52
|
+
application: Application;
|
|
53
|
+
}
|
|
54
|
+
interface ApplicationOAuthResponse {
|
|
55
|
+
oauth: ApplicationOAuth;
|
|
56
|
+
}
|
|
57
|
+
interface ListApplicationsResponse {
|
|
58
|
+
items: Application[];
|
|
59
|
+
nextCursor?: string;
|
|
60
|
+
}
|
|
61
|
+
interface RotateApplicationSecretResponse {
|
|
62
|
+
oauth: ApplicationOAuth;
|
|
63
|
+
}
|
|
64
|
+
interface UpdateApplicationIntegrationsInput {
|
|
65
|
+
integrationIds: string[];
|
|
66
|
+
}
|
|
67
|
+
interface ApplicationIntegrationsResponse {
|
|
68
|
+
integrationIds: string[];
|
|
69
|
+
}
|
|
70
|
+
type IntegrationAuthMode = "oauth" | "user_token" | "server_token" | "none";
|
|
71
|
+
type IntegrationValidationStatus = "pending" | "valid" | "invalid";
|
|
72
|
+
interface IntegrationOAuthSummary {
|
|
73
|
+
provider?: string;
|
|
74
|
+
issuer?: string;
|
|
75
|
+
scopes?: string[];
|
|
76
|
+
metadata?: Record<string, unknown>;
|
|
77
|
+
}
|
|
78
|
+
interface IntegrationCapabilities {
|
|
79
|
+
tools?: boolean;
|
|
80
|
+
resources?: boolean;
|
|
81
|
+
prompts?: boolean;
|
|
82
|
+
}
|
|
83
|
+
interface Integration {
|
|
84
|
+
id: string;
|
|
85
|
+
name: string;
|
|
86
|
+
url: string;
|
|
87
|
+
authMode: IntegrationAuthMode;
|
|
88
|
+
oauth?: IntegrationOAuthSummary;
|
|
89
|
+
capabilities?: IntegrationCapabilities;
|
|
90
|
+
serverTokenConfigured: boolean;
|
|
91
|
+
validationStatus: IntegrationValidationStatus;
|
|
92
|
+
validationMessage?: string;
|
|
93
|
+
lastValidatedAt?: string;
|
|
94
|
+
userConnection?: ConnectionStatusResponse;
|
|
95
|
+
createdAt: string;
|
|
96
|
+
updatedAt: string;
|
|
97
|
+
archivedAt?: string;
|
|
98
|
+
}
|
|
99
|
+
interface IntegrationOAuthConfigInput {
|
|
100
|
+
provider?: string;
|
|
101
|
+
issuer?: string;
|
|
102
|
+
scopes?: string[];
|
|
103
|
+
}
|
|
104
|
+
interface CreateIntegrationInput {
|
|
105
|
+
name: string;
|
|
106
|
+
url: string;
|
|
107
|
+
authMode?: IntegrationAuthMode;
|
|
108
|
+
oauth?: IntegrationOAuthConfigInput;
|
|
109
|
+
capabilities?: IntegrationCapabilities;
|
|
110
|
+
serverToken?: string;
|
|
111
|
+
}
|
|
112
|
+
interface UpdateIntegrationInput {
|
|
113
|
+
name?: string;
|
|
114
|
+
url?: string;
|
|
115
|
+
authMode?: IntegrationAuthMode;
|
|
116
|
+
oauth?: IntegrationOAuthConfigInput;
|
|
117
|
+
capabilities?: IntegrationCapabilities;
|
|
118
|
+
serverToken?: string;
|
|
119
|
+
}
|
|
120
|
+
interface CreateIntegrationResponse {
|
|
121
|
+
integration: Integration;
|
|
122
|
+
}
|
|
123
|
+
interface IntegrationResponse {
|
|
124
|
+
integration: Integration;
|
|
125
|
+
}
|
|
126
|
+
interface ListIntegrationsResponse {
|
|
127
|
+
items: Integration[];
|
|
128
|
+
nextCursor?: string;
|
|
129
|
+
}
|
|
130
|
+
interface ValidateIntegrationResponse {
|
|
131
|
+
status: IntegrationValidationStatus;
|
|
132
|
+
message?: string;
|
|
133
|
+
}
|
|
134
|
+
type ConnectionStatus = "connected" | "disconnected";
|
|
135
|
+
interface ConnectionStatusResponse {
|
|
136
|
+
connected: boolean;
|
|
137
|
+
status?: ConnectionStatus;
|
|
138
|
+
expiresAt?: string;
|
|
139
|
+
displayName?: string;
|
|
140
|
+
}
|
|
141
|
+
interface ConnectionResponse {
|
|
142
|
+
connection: ConnectionStatusResponse;
|
|
143
|
+
}
|
|
144
|
+
interface AddUserTokenInput {
|
|
145
|
+
token: string;
|
|
146
|
+
}
|
|
147
|
+
interface ServiceAccount {
|
|
148
|
+
id: string;
|
|
149
|
+
name: string;
|
|
150
|
+
description: string | null;
|
|
151
|
+
createdAt: string;
|
|
152
|
+
}
|
|
153
|
+
interface ServiceAccountCredentials {
|
|
154
|
+
clientId: string;
|
|
155
|
+
clientSecret: string;
|
|
156
|
+
}
|
|
157
|
+
interface CreateServiceAccountInput {
|
|
158
|
+
name: string;
|
|
159
|
+
description?: string;
|
|
160
|
+
}
|
|
161
|
+
interface CreateServiceAccountResponse {
|
|
162
|
+
serviceAccount: ServiceAccount;
|
|
163
|
+
credentials: ServiceAccountCredentials;
|
|
164
|
+
}
|
|
165
|
+
interface RotateSecretResponse {
|
|
166
|
+
credentials: ServiceAccountCredentials;
|
|
167
|
+
}
|
|
168
|
+
interface ListServiceAccountsResponse {
|
|
169
|
+
items: ServiceAccount[];
|
|
170
|
+
nextCursor: string | null;
|
|
171
|
+
}
|
|
172
|
+
interface ServiceAccountResponse {
|
|
173
|
+
serviceAccount: ServiceAccount;
|
|
174
|
+
}
|
|
175
|
+
type AgentSessionStatus = "active" | "disconnected";
|
|
176
|
+
type AgentSessionDerivedStatus = "active" | "idle" | "expired" | "disconnected";
|
|
177
|
+
interface AgentSession {
|
|
178
|
+
id: string;
|
|
179
|
+
agentId: string;
|
|
180
|
+
organizationId: string;
|
|
181
|
+
name: string;
|
|
182
|
+
hostname?: string | null;
|
|
183
|
+
userAgent?: string | null;
|
|
184
|
+
clientInfo?: Record<string, unknown> | null;
|
|
185
|
+
status: AgentSessionStatus;
|
|
186
|
+
derivedStatus: AgentSessionDerivedStatus;
|
|
187
|
+
connectedAt?: string;
|
|
188
|
+
lastActiveAt?: string;
|
|
189
|
+
disconnectedAt?: string;
|
|
190
|
+
tokenExpiresAt?: string;
|
|
191
|
+
createdAt: string;
|
|
192
|
+
}
|
|
193
|
+
interface AgentSessionResponse {
|
|
194
|
+
session: AgentSession;
|
|
195
|
+
}
|
|
196
|
+
interface ListAgentSessionsResponse {
|
|
197
|
+
items: AgentSession[];
|
|
198
|
+
}
|
|
199
|
+
interface RevokeAllSessionsResponse {
|
|
200
|
+
success: boolean;
|
|
201
|
+
disconnectedCount: number;
|
|
202
|
+
}
|
|
203
|
+
interface Trace {
|
|
204
|
+
traceId: string | null;
|
|
205
|
+
sessionId: string;
|
|
206
|
+
startedAt: string | null;
|
|
207
|
+
endedAt: string | null;
|
|
208
|
+
eventCount: number;
|
|
209
|
+
okCount?: number;
|
|
210
|
+
warnCount?: number;
|
|
211
|
+
errorCount?: number;
|
|
212
|
+
agentId?: string;
|
|
213
|
+
ownerUserId?: string;
|
|
214
|
+
ownerEmail?: string;
|
|
215
|
+
agentName?: string;
|
|
216
|
+
agentSessionId?: string;
|
|
217
|
+
agentSessionName?: string;
|
|
218
|
+
}
|
|
219
|
+
interface TraceEvent {
|
|
220
|
+
id: string;
|
|
221
|
+
createdAt: string;
|
|
222
|
+
sessionId: string;
|
|
223
|
+
agentId: string;
|
|
224
|
+
traceId?: string | null;
|
|
225
|
+
apiKeyId?: string | null;
|
|
226
|
+
eventType: string;
|
|
227
|
+
status: string;
|
|
228
|
+
durationMs?: number | null;
|
|
229
|
+
integrationId?: string | null;
|
|
230
|
+
toolName?: string | null;
|
|
231
|
+
errorMessage?: string | null;
|
|
232
|
+
bytesIn?: number | null;
|
|
233
|
+
bytesOut?: number | null;
|
|
234
|
+
requestJson?: unknown;
|
|
235
|
+
responseJson?: unknown;
|
|
236
|
+
parentEventId?: string | null;
|
|
237
|
+
agentSessionId?: string | null;
|
|
238
|
+
/** @deprecated Use createdAt */
|
|
239
|
+
timestamp?: string;
|
|
240
|
+
/** @deprecated Use status */
|
|
241
|
+
level?: "ok" | "warn" | "error";
|
|
242
|
+
/** @deprecated Use eventType */
|
|
243
|
+
type?: string;
|
|
244
|
+
/** @deprecated May be encoded in requestJson/responseJson */
|
|
245
|
+
method?: string;
|
|
246
|
+
/** @deprecated Use toolName */
|
|
247
|
+
tool?: string;
|
|
248
|
+
/** @deprecated Use durationMs */
|
|
249
|
+
duration?: number;
|
|
250
|
+
/** @deprecated Use status/errorMessage fields */
|
|
251
|
+
errorType?: string;
|
|
252
|
+
/** @deprecated May be encoded in requestJson/responseJson */
|
|
253
|
+
metadata?: Record<string, unknown>;
|
|
254
|
+
}
|
|
255
|
+
interface ListTracesResponse {
|
|
256
|
+
items: Trace[];
|
|
257
|
+
nextCursor?: string;
|
|
258
|
+
}
|
|
259
|
+
interface TraceResponse {
|
|
260
|
+
trace: Trace;
|
|
261
|
+
events: TraceEvent[];
|
|
262
|
+
}
|
|
263
|
+
interface McpEvent {
|
|
264
|
+
id: string;
|
|
265
|
+
createdAt: string;
|
|
266
|
+
agentId: string;
|
|
267
|
+
integrationId: string | null;
|
|
268
|
+
toolName: string | null;
|
|
269
|
+
eventType: string;
|
|
270
|
+
status: string;
|
|
271
|
+
}
|
|
272
|
+
interface McpEventListResponse {
|
|
273
|
+
items: McpEvent[];
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* @deprecated Use McpEventListResponse instead.
|
|
277
|
+
*/
|
|
278
|
+
type ListEventsResponse = McpEventListResponse;
|
|
279
|
+
interface TraceStats {
|
|
280
|
+
totalTraces: number;
|
|
281
|
+
totalEvents: number;
|
|
282
|
+
eventCounts: {
|
|
283
|
+
ok: number;
|
|
284
|
+
warn: number;
|
|
285
|
+
error: number;
|
|
286
|
+
};
|
|
287
|
+
errorRate: number;
|
|
288
|
+
latency: {
|
|
289
|
+
avg: number;
|
|
290
|
+
p50: number;
|
|
291
|
+
p95: number;
|
|
292
|
+
p99: number;
|
|
293
|
+
};
|
|
294
|
+
bytesTransferred: {
|
|
295
|
+
in: number;
|
|
296
|
+
out: number;
|
|
297
|
+
};
|
|
298
|
+
errorsByType: Array<{
|
|
299
|
+
type: string;
|
|
300
|
+
count: number;
|
|
301
|
+
percentage: number;
|
|
302
|
+
}>;
|
|
303
|
+
topTools: Array<{
|
|
304
|
+
name: string;
|
|
305
|
+
count: number;
|
|
306
|
+
avgDuration: number;
|
|
307
|
+
}>;
|
|
308
|
+
timeline: Array<{
|
|
309
|
+
date: string;
|
|
310
|
+
traceCount: number;
|
|
311
|
+
eventCount: number;
|
|
312
|
+
warnCount: number;
|
|
313
|
+
errorCount: number;
|
|
314
|
+
bytesIn: number;
|
|
315
|
+
bytesOut: number;
|
|
316
|
+
}>;
|
|
317
|
+
}
|
|
318
|
+
interface TraceStatsResponse {
|
|
319
|
+
stats: TraceStats;
|
|
320
|
+
}
|
|
321
|
+
interface PaginationParams {
|
|
322
|
+
cursor?: string;
|
|
323
|
+
limit?: number;
|
|
324
|
+
}
|
|
325
|
+
interface OAuthTokens {
|
|
326
|
+
accessToken: string;
|
|
327
|
+
refreshToken?: string;
|
|
328
|
+
tokenType: string;
|
|
329
|
+
scope?: string;
|
|
330
|
+
expiresAt?: string;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* RFC 8693 Token Exchange grant type
|
|
334
|
+
*/
|
|
335
|
+
declare const TOKEN_EXCHANGE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:token-exchange";
|
|
336
|
+
/**
|
|
337
|
+
* RFC 8693 token type identifier for access tokens
|
|
338
|
+
*/
|
|
339
|
+
declare const TOKEN_TYPE_ACCESS_TOKEN = "urn:ietf:params:oauth:token-type:access_token";
|
|
340
|
+
/**
|
|
341
|
+
* Request body for RFC 8693 token exchange
|
|
342
|
+
*/
|
|
343
|
+
interface TokenExchangeRequest {
|
|
344
|
+
grant_type: typeof TOKEN_EXCHANGE_GRANT_TYPE;
|
|
345
|
+
subject_token: string;
|
|
346
|
+
subject_token_type?: string;
|
|
347
|
+
resource: string;
|
|
348
|
+
scope?: string;
|
|
349
|
+
audience?: string;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Response from RFC 8693 token exchange
|
|
353
|
+
*/
|
|
354
|
+
interface TokenExchangeResponse {
|
|
355
|
+
access_token: string;
|
|
356
|
+
issued_token_type: string;
|
|
357
|
+
token_type: string;
|
|
358
|
+
expires_in?: number;
|
|
359
|
+
scope?: string;
|
|
360
|
+
refresh_token?: string;
|
|
361
|
+
}
|
|
362
|
+
interface KontextManagementClientConfig {
|
|
363
|
+
/**
|
|
364
|
+
* Base URL for the Kontext API (e.g., "https://api.kontext.dev")
|
|
365
|
+
*/
|
|
366
|
+
baseUrl: string;
|
|
367
|
+
/**
|
|
368
|
+
* API version to use (default: "v1")
|
|
369
|
+
*/
|
|
370
|
+
apiVersion?: string;
|
|
371
|
+
/**
|
|
372
|
+
* OAuth token endpoint URL (optional)
|
|
373
|
+
* If not specified, defaults to `${baseUrl}/oauth2/token`
|
|
374
|
+
* Useful for local development where Hydra runs on a different port
|
|
375
|
+
*/
|
|
376
|
+
tokenUrl?: string;
|
|
377
|
+
/**
|
|
378
|
+
* OAuth scopes to request (optional)
|
|
379
|
+
* Defaults to ["management:all"]
|
|
380
|
+
*/
|
|
381
|
+
scopes?: string[];
|
|
382
|
+
/**
|
|
383
|
+
* OAuth audience for token requests (optional)
|
|
384
|
+
* If not specified, defaults to `${baseUrl}/api/${apiVersion}`
|
|
385
|
+
* Required for Hydra token introspection
|
|
386
|
+
*/
|
|
387
|
+
audience?: string;
|
|
388
|
+
/**
|
|
389
|
+
* Service account credentials for authentication
|
|
390
|
+
*/
|
|
391
|
+
credentials: {
|
|
392
|
+
clientId: string;
|
|
393
|
+
clientSecret: string;
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
export { TOKEN_TYPE_ACCESS_TOKEN as $, type ApplicationResponse as A, type ConnectionResponse as B, type CreateServiceAccountInput as C, type ConnectionStatus as D, type ConnectionStatusResponse as E, type CreateApplicationOAuthInput as F, type Integration as G, type IntegrationAuthMode as H, type IntegrationResponse as I, type IntegrationCapabilities as J, type KontextManagementClientConfig as K, type ListServiceAccountsResponse as L, type McpEventListResponse as M, type IntegrationOAuthConfigInput as N, type IntegrationOAuthSummary as O, type PaginationParams as P, type IntegrationValidationStatus as Q, type RotateSecretResponse as R, type ServiceAccountResponse as S, type TokenExchangeRequest as T, type UpdateApplicationInput as U, type ValidateIntegrationResponse as V, type ListEventsResponse as W, type McpEvent as X, type OAuthTokens as Y, type ServiceAccount as Z, TOKEN_EXCHANGE_GRANT_TYPE as _, type TokenExchangeResponse as a, type Trace as a0, type TraceEvent as a1, type TraceStats as a2, type CreateServiceAccountResponse as b, type CreateApplicationInput as c, type CreateApplicationResponse as d, type ListApplicationsResponse as e, type ApplicationOAuthResponse as f, type UpdateApplicationOAuthInput as g, type RotateApplicationSecretResponse as h, type ApplicationIntegrationsResponse as i, type UpdateApplicationIntegrationsInput as j, type RevokeAllSessionsResponse as k, type CreateIntegrationInput as l, type CreateIntegrationResponse as m, type ListIntegrationsResponse as n, type UpdateIntegrationInput as o, type ListAgentSessionsResponse as p, type AgentSessionResponse as q, type ListTracesResponse as r, type TraceResponse as s, type TraceStatsResponse as t, type AddUserTokenInput as u, type AgentSession as v, type AgentSessionDerivedStatus as w, type AgentSessionStatus as x, type Application as y, type ApplicationOAuth as z };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage interface for persisting SDK state
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Generic storage interface for the Kontext SDK
|
|
6
|
+
* Implementations can store data in memory, file system, or external services
|
|
7
|
+
*/
|
|
8
|
+
interface KontextStorage {
|
|
9
|
+
/**
|
|
10
|
+
* Retrieve a JSON value by key
|
|
11
|
+
* @param key Storage key
|
|
12
|
+
* @returns The stored value or undefined if not found
|
|
13
|
+
*/
|
|
14
|
+
getJson<T>(key: string): Promise<T | undefined>;
|
|
15
|
+
/**
|
|
16
|
+
* Store a JSON value by key
|
|
17
|
+
* @param key Storage key
|
|
18
|
+
* @param value The value to store, or undefined to delete
|
|
19
|
+
*/
|
|
20
|
+
setJson<T>(key: string, value: T | undefined): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type { KontextStorage as K };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage interface for persisting SDK state
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Generic storage interface for the Kontext SDK
|
|
6
|
+
* Implementations can store data in memory, file system, or external services
|
|
7
|
+
*/
|
|
8
|
+
interface KontextStorage {
|
|
9
|
+
/**
|
|
10
|
+
* Retrieve a JSON value by key
|
|
11
|
+
* @param key Storage key
|
|
12
|
+
* @returns The stored value or undefined if not found
|
|
13
|
+
*/
|
|
14
|
+
getJson<T>(key: string): Promise<T | undefined>;
|
|
15
|
+
/**
|
|
16
|
+
* Store a JSON value by key
|
|
17
|
+
* @param key Storage key
|
|
18
|
+
* @param value The value to store, or undefined to delete
|
|
19
|
+
*/
|
|
20
|
+
setJson<T>(key: string, value: T | undefined): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type { KontextStorage as K };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token verification error codes.
|
|
3
|
+
* These provide structured error information for debugging and error handling.
|
|
4
|
+
*/
|
|
5
|
+
type TokenVerificationErrorCode = "INVALID_TOKEN_FORMAT" | "INVALID_SIGNATURE" | "TOKEN_EXPIRED" | "TOKEN_NOT_YET_VALID" | "INVALID_ISSUER" | "INVALID_AUDIENCE" | "MISSING_SCOPE" | "MISSING_CLAIMS" | "JWKS_FETCH_FAILED" | "UNKNOWN_KID" | "UNSUPPORTED_ALGORITHM";
|
|
6
|
+
/**
|
|
7
|
+
* Error thrown when token verification fails.
|
|
8
|
+
* Contains a structured error code for programmatic handling.
|
|
9
|
+
*/
|
|
10
|
+
declare class TokenVerificationError extends Error {
|
|
11
|
+
readonly code: TokenVerificationErrorCode;
|
|
12
|
+
constructor(code: TokenVerificationErrorCode, message: string);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Configuration for KontextTokenVerifier.
|
|
17
|
+
*/
|
|
18
|
+
interface KontextTokenVerifierConfig {
|
|
19
|
+
/** JWKS endpoint URL (e.g., "https://api.kontext.dev/.well-known/jwks.json") */
|
|
20
|
+
jwksUrl: string;
|
|
21
|
+
/** Expected issuer claim (iss) — may be a single string or an array of accepted issuers */
|
|
22
|
+
issuer: string | string[];
|
|
23
|
+
/** Expected audience claim(s) - token must contain at least one */
|
|
24
|
+
audience: string | string[];
|
|
25
|
+
/** Required scopes - token must contain all of these */
|
|
26
|
+
requiredScopes?: string[];
|
|
27
|
+
/** JWKS cache TTL in milliseconds (default: 5 minutes) */
|
|
28
|
+
cacheTtlMs?: number;
|
|
29
|
+
/** Minimum time between JWKS refetches in milliseconds (default: 30 seconds) */
|
|
30
|
+
refetchCooldownMs?: number;
|
|
31
|
+
/** Clock tolerance in seconds for expiration/not-before checks (default: 30) */
|
|
32
|
+
clockToleranceSec?: number;
|
|
33
|
+
/** Custom fetch function for testing */
|
|
34
|
+
fetch?: typeof globalThis.fetch;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* JWT payload structure from verified token.
|
|
38
|
+
*/
|
|
39
|
+
interface JwtPayload {
|
|
40
|
+
iss?: string;
|
|
41
|
+
sub?: string;
|
|
42
|
+
aud?: string | string[];
|
|
43
|
+
exp?: number;
|
|
44
|
+
iat?: number;
|
|
45
|
+
nbf?: number;
|
|
46
|
+
jti?: string;
|
|
47
|
+
client_id?: string;
|
|
48
|
+
scope?: string;
|
|
49
|
+
[key: string]: unknown;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Verified token claims returned on successful verification.
|
|
53
|
+
*/
|
|
54
|
+
interface VerifiedTokenClaims {
|
|
55
|
+
/** Subject claim (sub) */
|
|
56
|
+
sub: string;
|
|
57
|
+
/** Client ID (client_id claim or sub) */
|
|
58
|
+
clientId: string;
|
|
59
|
+
/** Scopes (space-separated scope claim split into array) */
|
|
60
|
+
scopes: string[];
|
|
61
|
+
/** Expiration time as Date */
|
|
62
|
+
expiresAt: Date;
|
|
63
|
+
/** JWT ID (jti) if present */
|
|
64
|
+
jti?: string;
|
|
65
|
+
/** Raw payload for access to additional claims */
|
|
66
|
+
payload: JwtPayload;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Result type for token verification.
|
|
70
|
+
* Provides structured success/failure information.
|
|
71
|
+
*/
|
|
72
|
+
type VerifyResult = {
|
|
73
|
+
success: true;
|
|
74
|
+
claims: VerifiedTokenClaims;
|
|
75
|
+
} | {
|
|
76
|
+
success: false;
|
|
77
|
+
error: TokenVerificationError;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
declare class KontextTokenVerifier {
|
|
81
|
+
private readonly config;
|
|
82
|
+
private readonly jwksClient;
|
|
83
|
+
private readonly audiences;
|
|
84
|
+
constructor(config: KontextTokenVerifierConfig);
|
|
85
|
+
/**
|
|
86
|
+
* Verify a JWT token.
|
|
87
|
+
*
|
|
88
|
+
* @param token - The JWT token string (without "Bearer " prefix)
|
|
89
|
+
* @returns VerifyResult with success=true and claims, or success=false and error
|
|
90
|
+
*/
|
|
91
|
+
verify(token: string): Promise<VerifyResult>;
|
|
92
|
+
/**
|
|
93
|
+
* Verify a JWT token and return claims or null.
|
|
94
|
+
* Simpler API for cases where you don't need error details.
|
|
95
|
+
*
|
|
96
|
+
* @param token - The JWT token string (without "Bearer " prefix)
|
|
97
|
+
* @returns VerifiedTokenClaims if valid, null if invalid
|
|
98
|
+
*/
|
|
99
|
+
verifyOrNull(token: string): Promise<VerifiedTokenClaims | null>;
|
|
100
|
+
/**
|
|
101
|
+
* Clear the JWKS cache, forcing a fresh fetch on next verification.
|
|
102
|
+
*/
|
|
103
|
+
clearCache(): void;
|
|
104
|
+
private verifyInternal;
|
|
105
|
+
private parseScopes;
|
|
106
|
+
private extractKid;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export { type JwtPayload as J, KontextTokenVerifier as K, TokenVerificationError as T, type VerifiedTokenClaims as V, type KontextTokenVerifierConfig as a, type TokenVerificationErrorCode as b, type VerifyResult as c };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token verification error codes.
|
|
3
|
+
* These provide structured error information for debugging and error handling.
|
|
4
|
+
*/
|
|
5
|
+
type TokenVerificationErrorCode = "INVALID_TOKEN_FORMAT" | "INVALID_SIGNATURE" | "TOKEN_EXPIRED" | "TOKEN_NOT_YET_VALID" | "INVALID_ISSUER" | "INVALID_AUDIENCE" | "MISSING_SCOPE" | "MISSING_CLAIMS" | "JWKS_FETCH_FAILED" | "UNKNOWN_KID" | "UNSUPPORTED_ALGORITHM";
|
|
6
|
+
/**
|
|
7
|
+
* Error thrown when token verification fails.
|
|
8
|
+
* Contains a structured error code for programmatic handling.
|
|
9
|
+
*/
|
|
10
|
+
declare class TokenVerificationError extends Error {
|
|
11
|
+
readonly code: TokenVerificationErrorCode;
|
|
12
|
+
constructor(code: TokenVerificationErrorCode, message: string);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Configuration for KontextTokenVerifier.
|
|
17
|
+
*/
|
|
18
|
+
interface KontextTokenVerifierConfig {
|
|
19
|
+
/** JWKS endpoint URL (e.g., "https://api.kontext.dev/.well-known/jwks.json") */
|
|
20
|
+
jwksUrl: string;
|
|
21
|
+
/** Expected issuer claim (iss) — may be a single string or an array of accepted issuers */
|
|
22
|
+
issuer: string | string[];
|
|
23
|
+
/** Expected audience claim(s) - token must contain at least one */
|
|
24
|
+
audience: string | string[];
|
|
25
|
+
/** Required scopes - token must contain all of these */
|
|
26
|
+
requiredScopes?: string[];
|
|
27
|
+
/** JWKS cache TTL in milliseconds (default: 5 minutes) */
|
|
28
|
+
cacheTtlMs?: number;
|
|
29
|
+
/** Minimum time between JWKS refetches in milliseconds (default: 30 seconds) */
|
|
30
|
+
refetchCooldownMs?: number;
|
|
31
|
+
/** Clock tolerance in seconds for expiration/not-before checks (default: 30) */
|
|
32
|
+
clockToleranceSec?: number;
|
|
33
|
+
/** Custom fetch function for testing */
|
|
34
|
+
fetch?: typeof globalThis.fetch;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* JWT payload structure from verified token.
|
|
38
|
+
*/
|
|
39
|
+
interface JwtPayload {
|
|
40
|
+
iss?: string;
|
|
41
|
+
sub?: string;
|
|
42
|
+
aud?: string | string[];
|
|
43
|
+
exp?: number;
|
|
44
|
+
iat?: number;
|
|
45
|
+
nbf?: number;
|
|
46
|
+
jti?: string;
|
|
47
|
+
client_id?: string;
|
|
48
|
+
scope?: string;
|
|
49
|
+
[key: string]: unknown;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Verified token claims returned on successful verification.
|
|
53
|
+
*/
|
|
54
|
+
interface VerifiedTokenClaims {
|
|
55
|
+
/** Subject claim (sub) */
|
|
56
|
+
sub: string;
|
|
57
|
+
/** Client ID (client_id claim or sub) */
|
|
58
|
+
clientId: string;
|
|
59
|
+
/** Scopes (space-separated scope claim split into array) */
|
|
60
|
+
scopes: string[];
|
|
61
|
+
/** Expiration time as Date */
|
|
62
|
+
expiresAt: Date;
|
|
63
|
+
/** JWT ID (jti) if present */
|
|
64
|
+
jti?: string;
|
|
65
|
+
/** Raw payload for access to additional claims */
|
|
66
|
+
payload: JwtPayload;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Result type for token verification.
|
|
70
|
+
* Provides structured success/failure information.
|
|
71
|
+
*/
|
|
72
|
+
type VerifyResult = {
|
|
73
|
+
success: true;
|
|
74
|
+
claims: VerifiedTokenClaims;
|
|
75
|
+
} | {
|
|
76
|
+
success: false;
|
|
77
|
+
error: TokenVerificationError;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
declare class KontextTokenVerifier {
|
|
81
|
+
private readonly config;
|
|
82
|
+
private readonly jwksClient;
|
|
83
|
+
private readonly audiences;
|
|
84
|
+
constructor(config: KontextTokenVerifierConfig);
|
|
85
|
+
/**
|
|
86
|
+
* Verify a JWT token.
|
|
87
|
+
*
|
|
88
|
+
* @param token - The JWT token string (without "Bearer " prefix)
|
|
89
|
+
* @returns VerifyResult with success=true and claims, or success=false and error
|
|
90
|
+
*/
|
|
91
|
+
verify(token: string): Promise<VerifyResult>;
|
|
92
|
+
/**
|
|
93
|
+
* Verify a JWT token and return claims or null.
|
|
94
|
+
* Simpler API for cases where you don't need error details.
|
|
95
|
+
*
|
|
96
|
+
* @param token - The JWT token string (without "Bearer " prefix)
|
|
97
|
+
* @returns VerifiedTokenClaims if valid, null if invalid
|
|
98
|
+
*/
|
|
99
|
+
verifyOrNull(token: string): Promise<VerifiedTokenClaims | null>;
|
|
100
|
+
/**
|
|
101
|
+
* Clear the JWKS cache, forcing a fresh fetch on next verification.
|
|
102
|
+
*/
|
|
103
|
+
clearCache(): void;
|
|
104
|
+
private verifyInternal;
|
|
105
|
+
private parseScopes;
|
|
106
|
+
private extractKid;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export { type JwtPayload as J, KontextTokenVerifier as K, TokenVerificationError as T, type VerifiedTokenClaims as V, type KontextTokenVerifierConfig as a, type TokenVerificationErrorCode as b, type VerifyResult as c };
|