@mitralab.io/platform-sdk 1.0.9 → 1.1.0-beta.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/CHANGELOG.md +33 -1
- package/README.md +184 -17
- package/dist/index.cjs +1228 -115
- package/dist/index.d.cts +399 -97
- package/dist/index.d.ts +399 -97
- package/dist/index.js +1207 -105
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { Transport, TransportRequestOptions, QueryParamValue, EntityTable, ProxyResult } from '@mitralab.io/sdk-core';
|
|
2
|
-
export { EntityListOptions, EntityTable, ProxyResult } from '@mitralab.io/sdk-core';
|
|
1
|
+
import { Transport, TransportRequestOptions, QueryParamValue, EntityTable, FunctionExecution, ListTemplateConfigsOptions, TemplateConfigPage, ProxyResult, ProxyInput, QueryResult, CredentialStatus, AgentModel as AgentModel$1, OAuthStartResult, OAuthExchangeInput, AuthenticationResult, DeviceAuthorization, PublicFunctionsModule, AgentTasksWithSessions } from '@mitralab.io/sdk-core';
|
|
2
|
+
export { AgentQueueItem, AgentSendAndWaitOptions, AgentSendOptions, AgentSessionTransport, AgentTask, AgentTaskCreateInput, AgentTaskInput, AgentTaskListOptions, AgentTaskSessionEventMap, AgentTaskSessionOptions, AgentTaskSessionStatus, AgentTurnResult, AuthenticationResult, CredentialStatus, DeviceAuthorization, EntityListOptions, EntityTable, ExistingAgentTaskSessionOptions, FunctionExecution, ListTemplateConfigsOptions, AgentMessage as NativeAgentMessage, AgentModel as NativeAgentModel, AgentTaskSession as NativeAgentTaskSession, AgentTimelineItem as NativeAgentTimelineItem, AgentToolEvent as NativeAgentToolEvent, NewAgentTaskSessionOptions, OAuthExchangeInput, OAuthStartResult, Page, PageOptions, ProxyInput, ProxyResult, PublicFunctionAsyncResult, PublicFunctionResult, PublicFunctionsModule, QueryResult, TemplateConfigPage } from '@mitralab.io/sdk-core';
|
|
3
|
+
import * as LegacyTypes from 'mitra-interactions-sdk';
|
|
4
|
+
import { exchangeSsoCodeMitra as exchangeSsoCodeMitra$1, loginMitra as loginMitra$1, loginWithGoogleMitra as loginWithGoogleMitra$1, loginWithMicrosoftMitra as loginWithMicrosoftMitra$1 } from 'mitra-interactions-sdk';
|
|
5
|
+
export { callIntegrationMitra, configureSdkMitra, createMitraInstance, createRecordMitra, createRecordsBatchMitra, deleteRecordMitra, executePublicServerFunctionAsyncMitra, executePublicServerFunctionMitra, executeServerFunctionAsyncMitra, executeServerFunctionMitra, getAgentTaskMitra, getConfig, getPublicServerFunctionExecutionMitra, getRecordMitra, listIntegrationsMitra, listRecordsMitra, manageAgentChatMitra, manageAgentCredentialMitra, patchRecordMitra, refreshTokenSilently, resolveProjectId, stopServerFunctionExecutionMitra, updateRecordMitra } from 'mitra-interactions-sdk';
|
|
3
6
|
|
|
4
7
|
/**
|
|
5
8
|
* Configuration options for creating an HttpClient instance.
|
|
@@ -9,8 +12,13 @@ interface HttpClientConfig {
|
|
|
9
12
|
baseUrl: string;
|
|
10
13
|
/** Function that returns the current authentication token, or null if not authenticated */
|
|
11
14
|
getToken?: () => string | null;
|
|
12
|
-
/**
|
|
13
|
-
|
|
15
|
+
/** Refreshes an authenticated session before the Authorization header is constructed. */
|
|
16
|
+
beforeAuthenticatedRequest?: () => Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Callback invoked on a 401 with the token used by that request. Returns
|
|
19
|
+
* true when the request should be retried once with the current credential.
|
|
20
|
+
*/
|
|
21
|
+
onUnauthorized?: (requestToken: string | null) => Promise<boolean>;
|
|
14
22
|
/** Called whenever an API request fails. Useful for global error handling (e.g., toast notifications). */
|
|
15
23
|
onError?: (error: MitraApiError) => void;
|
|
16
24
|
/** Headers included in every request (e.g., X-App-Id for tracing). */
|
|
@@ -51,6 +59,7 @@ interface RequestOptions extends Omit<TransportRequestOptions, 'method'> {
|
|
|
51
59
|
declare class HttpClient implements Transport {
|
|
52
60
|
private readonly baseUrl;
|
|
53
61
|
private readonly tokenGetter;
|
|
62
|
+
private readonly beforeAuthenticatedRequest?;
|
|
54
63
|
private readonly onUnauthorized?;
|
|
55
64
|
private readonly onError?;
|
|
56
65
|
private readonly defaultHeaders;
|
|
@@ -77,6 +86,8 @@ declare class HttpClient implements Transport {
|
|
|
77
86
|
* ```
|
|
78
87
|
*/
|
|
79
88
|
request<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
89
|
+
private errorFromResponse;
|
|
90
|
+
private parseResponseBody;
|
|
80
91
|
/**
|
|
81
92
|
* Makes a GET request.
|
|
82
93
|
*
|
|
@@ -187,19 +198,35 @@ interface SignUpData {
|
|
|
187
198
|
password: string;
|
|
188
199
|
name?: string;
|
|
189
200
|
}
|
|
201
|
+
/** App-scoped session received from a trusted platform boundary. */
|
|
202
|
+
interface AuthSession {
|
|
203
|
+
accessToken: string;
|
|
204
|
+
refreshToken?: string | null;
|
|
205
|
+
}
|
|
206
|
+
/** Options for Google SSO. */
|
|
207
|
+
interface GoogleSignInOptions {
|
|
208
|
+
/** Opens a popup by default. Redirect mode navigates the current page. */
|
|
209
|
+
mode?: 'popup' | 'redirect';
|
|
210
|
+
}
|
|
211
|
+
/** Options for Microsoft SSO. Same handshake as Google, through the brand auth page. */
|
|
212
|
+
type MicrosoftSignInOptions = GoogleSignInOptions;
|
|
190
213
|
/** Callback for auth state changes. Receives the user on login, null on logout. */
|
|
191
214
|
type AuthStateChangeCallback = (user: User | null) => void;
|
|
192
215
|
|
|
216
|
+
interface AuthModuleOptions {
|
|
217
|
+
apiUrl?: string;
|
|
218
|
+
authPageUrl?: string;
|
|
219
|
+
}
|
|
193
220
|
/**
|
|
194
221
|
* Authentication module for managing user sessions.
|
|
195
222
|
*
|
|
196
|
-
* Handles
|
|
223
|
+
* Handles Google SSO, trusted session adoption, sign-out, and automatic token refresh.
|
|
197
224
|
* Auth state is persisted to localStorage with key `mitra_auth_{appId}`
|
|
198
225
|
* and restored on page reload.
|
|
199
226
|
*
|
|
200
227
|
* @example
|
|
201
228
|
* ```typescript
|
|
202
|
-
* await mitra.auth.
|
|
229
|
+
* await mitra.auth.signInWithGoogle({ mode: 'popup' });
|
|
203
230
|
* console.log(mitra.auth.currentUser);
|
|
204
231
|
* ```
|
|
205
232
|
*/
|
|
@@ -207,55 +234,91 @@ declare class AuthModule {
|
|
|
207
234
|
#private;
|
|
208
235
|
private readonly appId;
|
|
209
236
|
private _currentUser;
|
|
210
|
-
private
|
|
237
|
+
private sessionGeneration;
|
|
238
|
+
private refreshFlight;
|
|
239
|
+
private transientRefreshFailureGeneration;
|
|
211
240
|
private readonly listeners;
|
|
241
|
+
private readonly sessionListeners;
|
|
212
242
|
private readonly storageKey;
|
|
213
243
|
private readonly publicClient;
|
|
214
244
|
private readonly authedClient;
|
|
215
245
|
private readonly currentUserApi;
|
|
216
|
-
|
|
246
|
+
private readonly googleAuth;
|
|
247
|
+
private readonly microsoftAuth;
|
|
248
|
+
constructor(appId: string, iamBaseUrl: string, options?: AuthModuleOptions);
|
|
217
249
|
/** The currently authenticated user, or null. */
|
|
218
250
|
get currentUser(): User | null;
|
|
219
251
|
/** The current JWT access token, or null. */
|
|
220
252
|
get accessToken(): string | null;
|
|
221
253
|
/** Whether a user is currently authenticated (local check, not server-validated). */
|
|
222
254
|
get isAuthenticated(): boolean;
|
|
255
|
+
/** @deprecated Email/password authentication is not implemented by IAM. Use Google or Microsoft SSO. */
|
|
256
|
+
signIn(_credentials: SignInCredentials): Promise<User>;
|
|
223
257
|
/**
|
|
224
|
-
* Signs in
|
|
258
|
+
* Signs in with Google SSO.
|
|
259
|
+
*
|
|
260
|
+
* Popup mode is used by default. Redirect mode stores a one-time CSRF context
|
|
261
|
+
* in `sessionStorage` and navigates to the configured `sdk-auth.html` page.
|
|
262
|
+
* Call {@link completeGoogleSignInRedirect} during application startup to
|
|
263
|
+
* finish a redirect response.
|
|
225
264
|
*
|
|
226
|
-
*
|
|
227
|
-
*
|
|
265
|
+
* The auth page is resolved from `createClient({ authPageUrl })`, then
|
|
266
|
+
* `window.__mitraEnv.authPageUrl`, and finally `/sdk-auth.html` on the API
|
|
267
|
+
* gateway origin.
|
|
228
268
|
*
|
|
229
|
-
* @param
|
|
230
|
-
* @returns The authenticated user.
|
|
231
|
-
* @throws {MitraApiError}
|
|
269
|
+
* @param options - Popup or redirect mode.
|
|
270
|
+
* @returns The authenticated and hydrated user in popup mode.
|
|
271
|
+
* @throws {MitraApiError} When IAM rejects the authorization code.
|
|
272
|
+
* @throws {Error} When the browser blocks or cancels the popup, the flow times
|
|
273
|
+
* out, or the OAuth response fails origin, source, state, or shape validation.
|
|
232
274
|
*
|
|
233
275
|
* @example
|
|
234
276
|
* ```typescript
|
|
235
|
-
* const user = await mitra.auth.
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
277
|
+
* const user = await mitra.auth.signInWithGoogle();
|
|
278
|
+
* ```
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* ```typescript
|
|
282
|
+
* await mitra.auth.signInWithGoogle({ mode: 'redirect' });
|
|
239
283
|
* ```
|
|
240
284
|
*/
|
|
241
|
-
|
|
285
|
+
signInWithGoogle(options?: GoogleSignInOptions): Promise<User>;
|
|
242
286
|
/**
|
|
243
|
-
*
|
|
287
|
+
* Completes a Google redirect response from `#codeMitra` and `#stateMitra`.
|
|
244
288
|
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
289
|
+
* The method consumes and clears the fragment and stored CSRF context, sends
|
|
290
|
+
* the single-use code directly to IAM, persists both tokens, calls `auth.me()`,
|
|
291
|
+
* and notifies auth-state listeners. It returns `null` when the current URL is
|
|
292
|
+
* not a Google SSO redirect. Redirect errors must carry the same `stateMitra`
|
|
293
|
+
* stored at the start of the flow before their message is exposed or consumed.
|
|
294
|
+
*
|
|
295
|
+
* @returns The authenticated user, or `null` when no redirect result is present.
|
|
248
296
|
*
|
|
249
297
|
* @example
|
|
250
298
|
* ```typescript
|
|
251
|
-
* const
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
|
|
255
|
-
|
|
299
|
+
* const redirectedUser = await mitra.auth.completeGoogleSignInRedirect();
|
|
300
|
+
* if (redirectedUser) console.log(redirectedUser.email);
|
|
301
|
+
* ```
|
|
302
|
+
*/
|
|
303
|
+
completeGoogleSignInRedirect(): Promise<User | null>;
|
|
304
|
+
/**
|
|
305
|
+
* Signs in with Microsoft SSO: the same auth-page handshake as Google, exchanged
|
|
306
|
+
* at IAM's `/auth/microsoft`. Popup by default; redirect mode navigates away.
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
* ```typescript
|
|
310
|
+
* const user = await mitra.auth.signInWithMicrosoft();
|
|
256
311
|
* ```
|
|
257
312
|
*/
|
|
258
|
-
|
|
313
|
+
signInWithMicrosoft(options?: MicrosoftSignInOptions): Promise<User>;
|
|
314
|
+
/**
|
|
315
|
+
* Completes a Microsoft redirect response from `#codeMitra` and `#stateMitra`.
|
|
316
|
+
* Mirrors {@link completeGoogleSignInRedirect}; returns `null` when the current
|
|
317
|
+
* URL is not a Microsoft SSO redirect.
|
|
318
|
+
*/
|
|
319
|
+
completeMicrosoftSignInRedirect(): Promise<User | null>;
|
|
320
|
+
/** @deprecated Email/password registration is not implemented by IAM. Use Google or Microsoft SSO. */
|
|
321
|
+
signUp(_data: SignUpData): Promise<User>;
|
|
259
322
|
/**
|
|
260
323
|
* Signs out the current user, clearing all auth state and localStorage.
|
|
261
324
|
*
|
|
@@ -271,9 +334,9 @@ declare class AuthModule {
|
|
|
271
334
|
/**
|
|
272
335
|
* Refreshes the session using the stored refresh token.
|
|
273
336
|
*
|
|
274
|
-
* Called automatically
|
|
275
|
-
*
|
|
276
|
-
*
|
|
337
|
+
* Called automatically before requests whose JWT is close to expiry and on
|
|
338
|
+
* `401` responses. Can also be called manually. Multiple proactive, reactive,
|
|
339
|
+
* and manual calls are deduplicated into one refresh request.
|
|
277
340
|
*
|
|
278
341
|
* @returns `true` if refresh succeeded, `false` otherwise.
|
|
279
342
|
*
|
|
@@ -284,11 +347,23 @@ declare class AuthModule {
|
|
|
284
347
|
* ```
|
|
285
348
|
*/
|
|
286
349
|
refreshSession(): Promise<boolean>;
|
|
350
|
+
/**
|
|
351
|
+
* Resolves a 401 against the credential that actually reached the server.
|
|
352
|
+
* A newer session is retried as-is instead of being refreshed because of an
|
|
353
|
+
* older request. A signed-out session is neither refreshed nor retried.
|
|
354
|
+
*
|
|
355
|
+
* @param requestToken - Access token attached to the rejected request.
|
|
356
|
+
* @returns Whether the request should be retried once with the current token.
|
|
357
|
+
*
|
|
358
|
+
* @internal
|
|
359
|
+
*/
|
|
360
|
+
private handleUnauthorized;
|
|
287
361
|
/**
|
|
288
362
|
* Fetches the current user from the server and updates local state.
|
|
289
363
|
*
|
|
290
|
-
*
|
|
291
|
-
*
|
|
364
|
+
* Clears auth state on a definitive 401. When the request reaches 401 after
|
|
365
|
+
* IAM refresh failed due to a network error, 408, 429, or 5xx response, the
|
|
366
|
+
* retained session is preserved and this method returns null.
|
|
292
367
|
*
|
|
293
368
|
* @returns The user if authenticated, `null` otherwise.
|
|
294
369
|
*
|
|
@@ -326,6 +401,66 @@ declare class AuthModule {
|
|
|
326
401
|
* ```
|
|
327
402
|
*/
|
|
328
403
|
setToken(token: string, saveToStorage?: boolean): void;
|
|
404
|
+
/**
|
|
405
|
+
* Reads the tokens currently held by this module.
|
|
406
|
+
*
|
|
407
|
+
* Used by the legacy session bridge to hand a session persisted by this SDK
|
|
408
|
+
* over to `mitra-interactions-sdk` on startup.
|
|
409
|
+
*
|
|
410
|
+
* @returns The access and refresh tokens, each `null` when absent.
|
|
411
|
+
*
|
|
412
|
+
* @internal
|
|
413
|
+
*/
|
|
414
|
+
private readSessionTokens;
|
|
415
|
+
/**
|
|
416
|
+
* Adopts an app-scoped session received from a trusted platform boundary.
|
|
417
|
+
*
|
|
418
|
+
* This preserves the access and refresh tokens together so the normal refresh
|
|
419
|
+
* lifecycle continues after an embedded preview hands its session to the app.
|
|
420
|
+
* Call {@link checkAuth} afterward to validate the token and hydrate the user.
|
|
421
|
+
*/
|
|
422
|
+
setSession(session: AuthSession): boolean;
|
|
423
|
+
/**
|
|
424
|
+
* Ensures the current access token has enough remaining validity.
|
|
425
|
+
*
|
|
426
|
+
* JWT decoding is used only as a scheduling heuristic. Opaque tokens and JWTs
|
|
427
|
+
* without a numeric `exp` claim proceed unchanged and remain server-authoritative.
|
|
428
|
+
* Multiple proactive and reactive callers share the same refresh request.
|
|
429
|
+
* Transient refresh failures preserve the current session so the caller can
|
|
430
|
+
* continue and rely on the normal one-time `401` refresh fallback.
|
|
431
|
+
*
|
|
432
|
+
* This method is suitable for authenticated HTTP, WebSocket, and Server-Sent
|
|
433
|
+
* Events boundaries that need a fresh token before connecting.
|
|
434
|
+
*
|
|
435
|
+
* @param minValidityMs - Minimum remaining token lifetime. Defaults to 30 seconds.
|
|
436
|
+
* @returns `true` when no refresh is needed or refresh succeeds. Returns
|
|
437
|
+
* `false` when a required refresh fails, even when a transient failure keeps
|
|
438
|
+
* the current session available for a reactive server-authoritative fallback.
|
|
439
|
+
*/
|
|
440
|
+
ensureFreshSession(minValidityMs?: number): Promise<boolean>;
|
|
441
|
+
/**
|
|
442
|
+
* Subscribes an internal boundary to token changes without triggering login
|
|
443
|
+
* or refresh. Unlike auth-state listeners, this callback is not invoked
|
|
444
|
+
* immediately and does not depend on the user being hydrated.
|
|
445
|
+
*
|
|
446
|
+
* @param callback - Receives the current access and refresh tokens.
|
|
447
|
+
* @returns A function that removes the callback.
|
|
448
|
+
*
|
|
449
|
+
* @internal
|
|
450
|
+
*/
|
|
451
|
+
private onSessionChange;
|
|
452
|
+
/**
|
|
453
|
+
* Adopts a session produced outside this module, such as a legacy SSO login.
|
|
454
|
+
*
|
|
455
|
+
* Replaces the in-memory tokens and persists them under the same storage key
|
|
456
|
+
* the rest of the module uses. The current user is left untouched because the
|
|
457
|
+
* legacy SDK does not return one; call `me()` to hydrate it.
|
|
458
|
+
*
|
|
459
|
+
* @param session - Access token and, when the issuer returned one, refresh token.
|
|
460
|
+
*
|
|
461
|
+
* @internal
|
|
462
|
+
*/
|
|
463
|
+
private adoptSession;
|
|
329
464
|
/**
|
|
330
465
|
* Redirects to `/login?returnUrl=...` for unauthenticated users.
|
|
331
466
|
*
|
|
@@ -360,9 +495,14 @@ declare class AuthModule {
|
|
|
360
495
|
*/
|
|
361
496
|
onAuthStateChange(callback: AuthStateChangeCallback): () => void;
|
|
362
497
|
private doRefresh;
|
|
498
|
+
private establishSession;
|
|
363
499
|
private setAuthState;
|
|
364
500
|
private getCurrentUser;
|
|
365
501
|
private clearAuthState;
|
|
502
|
+
private invalidatePendingRefreshes;
|
|
503
|
+
private hasValidAppIdentity;
|
|
504
|
+
private belongsToConfiguredApp;
|
|
505
|
+
private notifySessionListeners;
|
|
366
506
|
private notifyListeners;
|
|
367
507
|
private saveToStorage;
|
|
368
508
|
private loadFromStorage;
|
|
@@ -389,85 +529,61 @@ type EntitiesProxy = EntitiesModule & {
|
|
|
389
529
|
[tableName: string]: EntityTable;
|
|
390
530
|
};
|
|
391
531
|
|
|
392
|
-
/** Result of a serverless function execution. */
|
|
393
|
-
interface FunctionExecution {
|
|
394
|
-
/** Unique execution ID. */
|
|
395
|
-
id: string;
|
|
396
|
-
/** ID of the executed function. */
|
|
397
|
-
functionId: string;
|
|
398
|
-
/** ID of the function version that was executed. */
|
|
399
|
-
functionVersionId: string;
|
|
400
|
-
/** Execution status returned by the Functions service. */
|
|
401
|
-
status: string;
|
|
402
|
-
/** Input data passed to the function. */
|
|
403
|
-
input: Record<string, unknown>;
|
|
404
|
-
/** Output data returned by the function. */
|
|
405
|
-
output: Record<string, unknown> | null;
|
|
406
|
-
/** Error message if execution failed. */
|
|
407
|
-
errorMessage: string | null;
|
|
408
|
-
/** Execution logs. */
|
|
409
|
-
logs: string | null;
|
|
410
|
-
/** Duration in milliseconds. */
|
|
411
|
-
durationMs: number | null;
|
|
412
|
-
/** When execution started (ISO 8601). */
|
|
413
|
-
startedAt: string | null;
|
|
414
|
-
/** When execution finished (ISO 8601). */
|
|
415
|
-
finishedAt: string | null;
|
|
416
|
-
/** When the execution record was created (ISO 8601). */
|
|
417
|
-
createdAt: string;
|
|
418
|
-
}
|
|
419
|
-
|
|
420
532
|
/** Platform SDK 1.x facade over the shared Function contract. */
|
|
421
533
|
declare class FunctionsModule {
|
|
422
534
|
private readonly core;
|
|
423
535
|
constructor(httpClient: HttpClient);
|
|
424
536
|
/**
|
|
425
|
-
* Executes a Function
|
|
426
|
-
* The runtime SDK uses an explicit invocation header instead.
|
|
537
|
+
* Executes a Function synchronously and waits for its terminal result.
|
|
427
538
|
*/
|
|
428
539
|
execute(functionId: string, input?: Record<string, unknown>): Promise<FunctionExecution>;
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
/**
|
|
432
|
-
|
|
433
|
-
/**
|
|
434
|
-
|
|
435
|
-
/** API endpoint path (appended to the template's baseUrl). */
|
|
436
|
-
endpoint: string;
|
|
437
|
-
/** Additional headers. */
|
|
438
|
-
headers?: Record<string, string>;
|
|
439
|
-
/** Request body. */
|
|
440
|
-
body?: unknown;
|
|
441
|
-
/** Query parameters. */
|
|
442
|
-
queryParams?: Record<string, string>;
|
|
540
|
+
/** Queues a Function and returns its initial execution record. */
|
|
541
|
+
executeAsync(functionId: string, input?: Record<string, unknown>): Promise<FunctionExecution>;
|
|
542
|
+
/** Reads the current state of an asynchronous Function execution. */
|
|
543
|
+
getExecution(executionId: string): Promise<FunctionExecution>;
|
|
544
|
+
/** Requests cancellation of a queued or running Function execution. */
|
|
545
|
+
cancelExecution(executionId: string): Promise<void>;
|
|
443
546
|
}
|
|
444
547
|
|
|
445
548
|
/** Platform SDK 1.x facade over the shared integration contract. */
|
|
446
549
|
declare class IntegrationModule {
|
|
447
550
|
private readonly core;
|
|
551
|
+
private readonly configs;
|
|
448
552
|
constructor(httpClient: HttpClient);
|
|
553
|
+
/** Lists the current app's integration configs without exposing admin mutations. */
|
|
554
|
+
list(options?: ListTemplateConfigsOptions): Promise<TemplateConfigPage>;
|
|
449
555
|
executeResource(resourceId: string, params?: Record<string, unknown>): Promise<ProxyResult>;
|
|
450
556
|
execute(configId: string, request: ProxyInput): Promise<ProxyResult>;
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
/** Result of executing a custom query. */
|
|
454
|
-
interface QueryResult {
|
|
455
|
-
/** Array of row objects returned by the query. */
|
|
456
|
-
rows: Record<string, unknown>[];
|
|
457
|
-
/** Number of affected rows (null for SELECT). */
|
|
458
|
-
affectedRows: number | null;
|
|
557
|
+
/** Executes a saved integration config selected by its app-scoped alias. */
|
|
558
|
+
executeByAlias(alias: string, request: ProxyInput): Promise<ProxyResult>;
|
|
459
559
|
}
|
|
460
560
|
|
|
461
561
|
/** Platform SDK 1.x facade over the shared custom query contract. */
|
|
462
562
|
declare class QueriesModule {
|
|
463
|
-
private dataSourceId;
|
|
464
563
|
private readonly core;
|
|
465
564
|
constructor(httpClient: HttpClient);
|
|
466
|
-
/**
|
|
467
|
-
|
|
565
|
+
/**
|
|
566
|
+
* @deprecated Preserved for Platform SDK 1.x source compatibility. Data Manager now resolves
|
|
567
|
+
* the Data Source from the authenticated app.
|
|
568
|
+
*/
|
|
569
|
+
setDataSourceId(_dataSourceId: string): void;
|
|
468
570
|
execute(id: string, parameters?: Record<string, unknown>): Promise<QueryResult>;
|
|
469
571
|
}
|
|
470
572
|
|
|
573
|
+
type AgentCredentialProvider = 'ANTHROPIC' | 'OPENAI';
|
|
574
|
+
type AgentOAuthProvider = 'ANTHROPIC';
|
|
575
|
+
type AgentDeviceProvider = 'OPENAI';
|
|
576
|
+
interface AgentCredentialsModule {
|
|
577
|
+
list(): Promise<CredentialStatus[]>;
|
|
578
|
+
listModels(agentId?: string): Promise<AgentModel$1[]>;
|
|
579
|
+
saveApiKey(provider: AgentCredentialProvider, apiKey: string): Promise<void>;
|
|
580
|
+
remove(provider: AgentCredentialProvider): Promise<void>;
|
|
581
|
+
startOAuth(provider: AgentOAuthProvider): Promise<OAuthStartResult>;
|
|
582
|
+
exchangeOAuth(provider: AgentOAuthProvider, input: OAuthExchangeInput): Promise<AuthenticationResult>;
|
|
583
|
+
startDeviceAuthorization(provider: AgentDeviceProvider): Promise<DeviceAuthorization>;
|
|
584
|
+
pollDeviceAuthorization(provider: AgentDeviceProvider, deviceAuthId: string): Promise<AuthenticationResult>;
|
|
585
|
+
}
|
|
586
|
+
|
|
471
587
|
/**
|
|
472
588
|
* Configuration options for creating a Mitra client.
|
|
473
589
|
*/
|
|
@@ -488,6 +604,18 @@ interface MitraClientConfig {
|
|
|
488
604
|
* ```
|
|
489
605
|
*/
|
|
490
606
|
apiUrl: string;
|
|
607
|
+
/**
|
|
608
|
+
* Absolute URL of the Mitra Google SSO page.
|
|
609
|
+
*
|
|
610
|
+
* When omitted, the SDK reads `window.__mitraEnv.authPageUrl` and then falls
|
|
611
|
+
* back to `/sdk-auth.html` on the origin of `apiUrl`.
|
|
612
|
+
*
|
|
613
|
+
* @example
|
|
614
|
+
* ```typescript
|
|
615
|
+
* authPageUrl: 'https://auth.example.com/sdk-auth.html'
|
|
616
|
+
* ```
|
|
617
|
+
*/
|
|
618
|
+
authPageUrl?: string;
|
|
491
619
|
/**
|
|
492
620
|
* Global error handler called whenever an API request fails.
|
|
493
621
|
* Useful for displaying toast notifications or logging errors.
|
|
@@ -517,7 +645,7 @@ interface MitraClientConfig {
|
|
|
517
645
|
* await mitra.init();
|
|
518
646
|
*
|
|
519
647
|
* // Authentication
|
|
520
|
-
* await mitra.auth.
|
|
648
|
+
* await mitra.auth.signInWithGoogle({ mode: 'popup' });
|
|
521
649
|
*
|
|
522
650
|
* // Database operations
|
|
523
651
|
* const tasks = await mitra.entities.Task.list();
|
|
@@ -530,8 +658,7 @@ interface MitraClient {
|
|
|
530
658
|
/**
|
|
531
659
|
* Initializes the client by resolving app config from the server.
|
|
532
660
|
*
|
|
533
|
-
*
|
|
534
|
-
* Fetches dataSourceId and allowSignup from the public app info endpoint.
|
|
661
|
+
* Fetches the compatibility dataSourceId and allowSignup from the public app info endpoint.
|
|
535
662
|
*
|
|
536
663
|
* Safe to call multiple times. Subsequent calls are no-ops.
|
|
537
664
|
*
|
|
@@ -548,11 +675,11 @@ interface MitraClient {
|
|
|
548
675
|
/**
|
|
549
676
|
* Authentication module for managing user sessions.
|
|
550
677
|
*
|
|
551
|
-
* Handles
|
|
678
|
+
* Handles Google SSO, trusted preview sessions, and session lifecycle.
|
|
552
679
|
*
|
|
553
680
|
* @example
|
|
554
681
|
* ```typescript
|
|
555
|
-
* await mitra.auth.
|
|
682
|
+
* await mitra.auth.signInWithGoogle({ mode: 'popup' });
|
|
556
683
|
* console.log(mitra.auth.currentUser);
|
|
557
684
|
* ```
|
|
558
685
|
*/
|
|
@@ -579,6 +706,12 @@ interface MitraClient {
|
|
|
579
706
|
* ```
|
|
580
707
|
*/
|
|
581
708
|
functions: FunctionsModule;
|
|
709
|
+
/** Anonymous execution of Functions explicitly published as public. */
|
|
710
|
+
publicFunctions: PublicFunctionsModule;
|
|
711
|
+
/** Browser-safe Agent task REST API and native live sessions. */
|
|
712
|
+
agentTasks: AgentTasksWithSessions;
|
|
713
|
+
/** Browser-safe credential status, model discovery, and provider auth flows. */
|
|
714
|
+
agentCredentials: AgentCredentialsModule;
|
|
582
715
|
/**
|
|
583
716
|
* Integration module for proxying HTTP requests to external APIs.
|
|
584
717
|
*
|
|
@@ -625,7 +758,7 @@ interface MitraClient {
|
|
|
625
758
|
* - **integration**: Proxy HTTP requests to external APIs
|
|
626
759
|
* - **queries**: Custom query management and execution
|
|
627
760
|
*
|
|
628
|
-
* After creating the client, call `init()` to resolve the app's config
|
|
761
|
+
* After creating the client, call `init()` to resolve the app's compatibility config
|
|
629
762
|
* (dataSourceId, allowSignup) automatically from the server.
|
|
630
763
|
*
|
|
631
764
|
* @param config - Configuration options for the client.
|
|
@@ -643,7 +776,7 @@ interface MitraClient {
|
|
|
643
776
|
* await mitra.init();
|
|
644
777
|
*
|
|
645
778
|
* // Use the client
|
|
646
|
-
* await mitra.auth.
|
|
779
|
+
* await mitra.auth.signInWithGoogle({ mode: 'popup' });
|
|
647
780
|
* const tasks = await mitra.entities.Task.list();
|
|
648
781
|
* ```
|
|
649
782
|
*
|
|
@@ -661,4 +794,173 @@ interface MitraClient {
|
|
|
661
794
|
*/
|
|
662
795
|
declare function createClient(config: MitraClientConfig): MitraClient;
|
|
663
796
|
|
|
664
|
-
|
|
797
|
+
/**
|
|
798
|
+
* Legacy `mitra-interactions-sdk` surface, re-exported so an application can
|
|
799
|
+
* swap the legacy package for `@mitralab.io/platform-sdk` without rewriting
|
|
800
|
+
* call sites first.
|
|
801
|
+
*
|
|
802
|
+
* Everything here is deprecated. The capabilities remain available during
|
|
803
|
+
* migration even when the native API has different input or response
|
|
804
|
+
* semantics.
|
|
805
|
+
*
|
|
806
|
+
* The four legacy entry points that produce a session are wrapped so the
|
|
807
|
+
* resulting session also lands in this SDK. Every other export is the legacy
|
|
808
|
+
* implementation itself.
|
|
809
|
+
*
|
|
810
|
+
* @module
|
|
811
|
+
*/
|
|
812
|
+
|
|
813
|
+
/**
|
|
814
|
+
* @deprecated Use `mitra.auth.signInWithGoogle()` when `method` is Google.
|
|
815
|
+
* Other legacy login methods remain supported until an equivalent exists.
|
|
816
|
+
*/
|
|
817
|
+
declare const loginMitra: typeof loginMitra$1;
|
|
818
|
+
/**
|
|
819
|
+
* @deprecated Use `mitra.auth.signInWithGoogle()`.
|
|
820
|
+
*/
|
|
821
|
+
declare const loginWithGoogleMitra: typeof loginWithGoogleMitra$1;
|
|
822
|
+
/**
|
|
823
|
+
* @deprecated Use `mitra.auth.signInWithMicrosoft()`.
|
|
824
|
+
*/
|
|
825
|
+
declare const loginWithMicrosoftMitra: typeof loginWithMicrosoftMitra$1;
|
|
826
|
+
/**
|
|
827
|
+
* @deprecated For Google redirects, use
|
|
828
|
+
* `mitra.auth.completeGoogleSignInRedirect()`. Other providers remain supported
|
|
829
|
+
* through the legacy surface.
|
|
830
|
+
*/
|
|
831
|
+
declare const exchangeSsoCodeMitra: typeof exchangeSsoCodeMitra$1;
|
|
832
|
+
|
|
833
|
+
/** @deprecated Legacy compatibility type. */
|
|
834
|
+
type AgentChat = LegacyTypes.AgentChat;
|
|
835
|
+
/** @deprecated Legacy compatibility type. */
|
|
836
|
+
type AgentCredentialStatus = LegacyTypes.AgentCredentialStatus;
|
|
837
|
+
/** @deprecated Legacy compatibility type. */
|
|
838
|
+
type AgentDeltaEvent = LegacyTypes.AgentDeltaEvent;
|
|
839
|
+
/** @deprecated Legacy compatibility type. */
|
|
840
|
+
type AgentErrorEvent = LegacyTypes.AgentErrorEvent;
|
|
841
|
+
/** @deprecated Legacy compatibility type. */
|
|
842
|
+
type AgentMessage = LegacyTypes.AgentMessage;
|
|
843
|
+
/** @deprecated Legacy compatibility type. */
|
|
844
|
+
type AgentModel = LegacyTypes.AgentModel;
|
|
845
|
+
/** @deprecated Legacy compatibility type. */
|
|
846
|
+
type AgentProvider = LegacyTypes.AgentProvider;
|
|
847
|
+
/** @deprecated Legacy compatibility type. */
|
|
848
|
+
type AgentQueueChangeEvent = LegacyTypes.AgentQueueChangeEvent;
|
|
849
|
+
/** @deprecated Legacy compatibility type. */
|
|
850
|
+
type AgentRawEvent = LegacyTypes.AgentRawEvent;
|
|
851
|
+
/** @deprecated Legacy compatibility type. */
|
|
852
|
+
type AgentStatusChangeEvent = LegacyTypes.AgentStatusChangeEvent;
|
|
853
|
+
/** @deprecated Legacy compatibility type. */
|
|
854
|
+
type AgentTaskCreatedEvent = LegacyTypes.AgentTaskCreatedEvent;
|
|
855
|
+
/** @deprecated Legacy compatibility type. */
|
|
856
|
+
type AgentTaskEventMap = LegacyTypes.AgentTaskEventMap;
|
|
857
|
+
/** @deprecated Legacy compatibility type. */
|
|
858
|
+
type AgentTaskEventName = LegacyTypes.AgentTaskEventName;
|
|
859
|
+
/** @deprecated Legacy compatibility type. */
|
|
860
|
+
type AgentTaskSession = LegacyTypes.AgentTaskSession;
|
|
861
|
+
/** @deprecated Legacy compatibility type. */
|
|
862
|
+
type AgentTaskStatus = LegacyTypes.AgentTaskStatus;
|
|
863
|
+
/** @deprecated Legacy compatibility type. */
|
|
864
|
+
type AgentTaskTransport = LegacyTypes.AgentTaskTransport;
|
|
865
|
+
/** @deprecated Legacy compatibility type. */
|
|
866
|
+
type AgentTimelineItem = LegacyTypes.AgentTimelineItem;
|
|
867
|
+
/** @deprecated Legacy compatibility type. */
|
|
868
|
+
type AgentToolEvent = LegacyTypes.AgentToolEvent;
|
|
869
|
+
/** @deprecated Legacy compatibility type. */
|
|
870
|
+
type AgentTurnEndEvent = LegacyTypes.AgentTurnEndEvent;
|
|
871
|
+
/** @deprecated Legacy compatibility type. */
|
|
872
|
+
type AgentType = LegacyTypes.AgentType;
|
|
873
|
+
/** @deprecated Legacy compatibility type. */
|
|
874
|
+
type AuthAgentCredentialResult = LegacyTypes.AuthAgentCredentialResult;
|
|
875
|
+
/** @deprecated Legacy compatibility type. */
|
|
876
|
+
type CallIntegrationOptions = LegacyTypes.CallIntegrationOptions;
|
|
877
|
+
/** @deprecated Legacy compatibility type. */
|
|
878
|
+
type CallIntegrationResponse = LegacyTypes.CallIntegrationResponse;
|
|
879
|
+
/** @deprecated Legacy compatibility type. */
|
|
880
|
+
type ChatManageAction = LegacyTypes.ChatManageAction;
|
|
881
|
+
/** @deprecated Legacy compatibility type. */
|
|
882
|
+
type ConnectAgentCredentialResult = LegacyTypes.ConnectAgentCredentialResult;
|
|
883
|
+
/** @deprecated Legacy compatibility type. */
|
|
884
|
+
type CreateRecordOptions = LegacyTypes.CreateRecordOptions;
|
|
885
|
+
/** @deprecated Legacy compatibility type. */
|
|
886
|
+
type CreateRecordsBatchOptions = LegacyTypes.CreateRecordsBatchOptions;
|
|
887
|
+
/** @deprecated Legacy compatibility type. */
|
|
888
|
+
type CredentialAction = LegacyTypes.CredentialAction;
|
|
889
|
+
/** @deprecated Legacy compatibility type. */
|
|
890
|
+
type DeleteAgentChatResult = LegacyTypes.DeleteAgentChatResult;
|
|
891
|
+
/** @deprecated Legacy compatibility type. */
|
|
892
|
+
type DeleteRecordOptions = LegacyTypes.DeleteRecordOptions;
|
|
893
|
+
/** @deprecated Legacy compatibility type. */
|
|
894
|
+
type DeviceAuthAgentCredentialResult = LegacyTypes.DeviceAuthAgentCredentialResult;
|
|
895
|
+
/** @deprecated Legacy compatibility type. */
|
|
896
|
+
type ExecutePublicServerFunctionAsyncResponse = LegacyTypes.ExecutePublicServerFunctionAsyncResponse;
|
|
897
|
+
/** @deprecated Legacy compatibility type. */
|
|
898
|
+
type ExecutePublicServerFunctionOptions = LegacyTypes.ExecutePublicServerFunctionOptions;
|
|
899
|
+
/** @deprecated Legacy compatibility type. */
|
|
900
|
+
type ExecutePublicServerFunctionResponse = LegacyTypes.ExecutePublicServerFunctionResponse;
|
|
901
|
+
/** @deprecated Legacy compatibility type. */
|
|
902
|
+
type ExecuteServerFunctionAsyncOptions = LegacyTypes.ExecuteServerFunctionAsyncOptions;
|
|
903
|
+
/** @deprecated Legacy compatibility type. */
|
|
904
|
+
type ExecuteServerFunctionAsyncResponse = LegacyTypes.ExecuteServerFunctionAsyncResponse;
|
|
905
|
+
/** @deprecated Legacy compatibility type. */
|
|
906
|
+
type ExecuteServerFunctionOptions = LegacyTypes.ExecuteServerFunctionOptions;
|
|
907
|
+
/** @deprecated Legacy compatibility type. */
|
|
908
|
+
type ExecuteServerFunctionResponse = LegacyTypes.ExecuteServerFunctionResponse;
|
|
909
|
+
/** @deprecated Legacy compatibility type. */
|
|
910
|
+
type GetAgentTaskCreateOptions = LegacyTypes.GetAgentTaskCreateOptions;
|
|
911
|
+
/** @deprecated Legacy compatibility type. */
|
|
912
|
+
type GetAgentTaskOpenOptions = LegacyTypes.GetAgentTaskOpenOptions;
|
|
913
|
+
/** @deprecated Legacy compatibility type. */
|
|
914
|
+
type GetAgentTaskOptions = LegacyTypes.GetAgentTaskOptions;
|
|
915
|
+
/** @deprecated Legacy compatibility type. */
|
|
916
|
+
type GetPublicServerFunctionExecutionOptions = LegacyTypes.GetPublicServerFunctionExecutionOptions;
|
|
917
|
+
/** @deprecated Legacy compatibility type. */
|
|
918
|
+
type GetPublicServerFunctionExecutionResponse = LegacyTypes.GetPublicServerFunctionExecutionResponse;
|
|
919
|
+
/** @deprecated Legacy compatibility type. */
|
|
920
|
+
type GetRecordOptions = LegacyTypes.GetRecordOptions;
|
|
921
|
+
/** @deprecated Legacy compatibility type. */
|
|
922
|
+
type IntegrationResponse = LegacyTypes.IntegrationResponse;
|
|
923
|
+
/** @deprecated Legacy compatibility type. */
|
|
924
|
+
type ListAgentModelsResult = LegacyTypes.ListAgentModelsResult;
|
|
925
|
+
/** @deprecated Legacy compatibility type. */
|
|
926
|
+
type ListAgentProvidersResult = LegacyTypes.ListAgentProvidersResult;
|
|
927
|
+
/** @deprecated Legacy compatibility type. */
|
|
928
|
+
type ListIntegrationsOptions = LegacyTypes.ListIntegrationsOptions;
|
|
929
|
+
/** @deprecated Legacy compatibility type. */
|
|
930
|
+
type ListRecordsOptions = LegacyTypes.ListRecordsOptions;
|
|
931
|
+
/** @deprecated Legacy compatibility type. */
|
|
932
|
+
type ListRecordsResponse = LegacyTypes.ListRecordsResponse;
|
|
933
|
+
/** @deprecated Legacy compatibility type. */
|
|
934
|
+
type LoginOptions = LegacyTypes.LoginOptions;
|
|
935
|
+
/** @deprecated Legacy compatibility type. */
|
|
936
|
+
type LoginResponse = LegacyTypes.LoginResponse;
|
|
937
|
+
/** @deprecated Legacy compatibility type. */
|
|
938
|
+
type ManageAgentChatDeleteOptions = LegacyTypes.ManageAgentChatDeleteOptions;
|
|
939
|
+
/** @deprecated Legacy compatibility type. */
|
|
940
|
+
type ManageAgentChatListOptions = LegacyTypes.ManageAgentChatListOptions;
|
|
941
|
+
/** @deprecated Legacy compatibility type. */
|
|
942
|
+
type ManageAgentChatOptions = LegacyTypes.ManageAgentChatOptions;
|
|
943
|
+
/** @deprecated Legacy compatibility type. */
|
|
944
|
+
type ManageAgentChatRenameOptions = LegacyTypes.ManageAgentChatRenameOptions;
|
|
945
|
+
/** @deprecated Legacy compatibility type. */
|
|
946
|
+
type ManageAgentCredentialOptions = LegacyTypes.ManageAgentCredentialOptions;
|
|
947
|
+
/** @deprecated Legacy compatibility type. */
|
|
948
|
+
type MitraConfig = LegacyTypes.MitraConfig;
|
|
949
|
+
/** @deprecated Legacy compatibility type. */
|
|
950
|
+
type MitraInstance = LegacyTypes.MitraInstance;
|
|
951
|
+
/** @deprecated Legacy compatibility type. */
|
|
952
|
+
type PatchRecordOptions = LegacyTypes.PatchRecordOptions;
|
|
953
|
+
/** @deprecated Legacy compatibility type. */
|
|
954
|
+
type QueuedItem = LegacyTypes.QueuedItem;
|
|
955
|
+
/** @deprecated Legacy compatibility type. */
|
|
956
|
+
type RenameAgentChatResult = LegacyTypes.RenameAgentChatResult;
|
|
957
|
+
/** @deprecated Legacy compatibility type. */
|
|
958
|
+
type SendOptions = LegacyTypes.SendOptions;
|
|
959
|
+
/** @deprecated Legacy compatibility type. */
|
|
960
|
+
type StopServerFunctionExecutionOptions = LegacyTypes.StopServerFunctionExecutionOptions;
|
|
961
|
+
/** @deprecated Legacy compatibility type. */
|
|
962
|
+
type StopServerFunctionExecutionResponse = LegacyTypes.StopServerFunctionExecutionResponse;
|
|
963
|
+
/** @deprecated Legacy compatibility type. */
|
|
964
|
+
type UpdateRecordOptions = LegacyTypes.UpdateRecordOptions;
|
|
965
|
+
|
|
966
|
+
export { type AgentChat, type AgentCredentialProvider, type AgentCredentialStatus, type AgentCredentialsModule, type AgentDeltaEvent, type AgentDeviceProvider, type AgentErrorEvent, type AgentMessage, type AgentModel, type AgentOAuthProvider, type AgentProvider, type AgentQueueChangeEvent, type AgentRawEvent, type AgentStatusChangeEvent, type AgentTaskCreatedEvent, type AgentTaskEventMap, type AgentTaskEventName, type AgentTaskSession, type AgentTaskStatus, type AgentTaskTransport, type AgentTimelineItem, type AgentToolEvent, type AgentTurnEndEvent, type AgentType, type AuthAgentCredentialResult, type CallIntegrationOptions, type CallIntegrationResponse, type ChatManageAction, type ConnectAgentCredentialResult, type CreateRecordOptions, type CreateRecordsBatchOptions, type CredentialAction, type DeleteAgentChatResult, type DeleteRecordOptions, type DeviceAuthAgentCredentialResult, type ExecutePublicServerFunctionAsyncResponse, type ExecutePublicServerFunctionOptions, type ExecutePublicServerFunctionResponse, type ExecuteServerFunctionAsyncOptions, type ExecuteServerFunctionAsyncResponse, type ExecuteServerFunctionOptions, type ExecuteServerFunctionResponse, type GetAgentTaskCreateOptions, type GetAgentTaskOpenOptions, type GetAgentTaskOptions, type GetPublicServerFunctionExecutionOptions, type GetPublicServerFunctionExecutionResponse, type GetRecordOptions, type GoogleSignInOptions, type IntegrationResponse, type ListAgentModelsResult, type ListAgentProvidersResult, type ListIntegrationsOptions, type ListRecordsOptions, type ListRecordsResponse, type LoginOptions, type LoginResponse, type ManageAgentChatDeleteOptions, type ManageAgentChatListOptions, type ManageAgentChatOptions, type ManageAgentChatRenameOptions, type ManageAgentCredentialOptions, type MicrosoftSignInOptions, MitraApiError, type MitraClient, type MitraClientConfig, type MitraConfig, type MitraInstance, type PatchRecordOptions, type QueuedItem, type RenameAgentChatResult, type SendOptions, type SignInCredentials, type SignUpData, type StopServerFunctionExecutionOptions, type StopServerFunctionExecutionResponse, type UpdateRecordOptions, type User, createClient, exchangeSsoCodeMitra, loginMitra, loginWithGoogleMitra, loginWithMicrosoftMitra };
|