@mitralab.io/sdk-core 0.3.0 → 0.3.1

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/dist/index.d.ts CHANGED
@@ -536,6 +536,8 @@ interface AgentMessageListOptions extends PageOptions {
536
536
  * and `TOOL_USE` rows of the chat itself, as before.
537
537
  */
538
538
  kinds?: "all";
539
+ /** Id of a message: only the rows recorded before it, so the next page back holds still. */
540
+ before?: string;
539
541
  }
540
542
  type AppColor = {
541
543
  type: "SOLID";
@@ -1281,6 +1283,22 @@ interface AgentModel {
1281
1283
  /** Name the person chose for a custom provider; null on built-in models. Absent on an older Copilot. */
1282
1284
  providerName?: string | null;
1283
1285
  }
1286
+ /**
1287
+ * A provider the next turn can run on, with the models the catalog offers on it and the last
1288
+ * subscription reading of the person's login.
1289
+ */
1290
+ interface AgentReadyProvider {
1291
+ provider: CopilotProvider;
1292
+ /** Name the person chose for a custom provider; null on a built-in one. */
1293
+ providerName: string | null;
1294
+ /** The catalog's models of this provider, in the catalog's order. */
1295
+ models: AgentModel[];
1296
+ /**
1297
+ * The same reading `usage(provider)` answers; null on an API key, before a turn reported a
1298
+ * window, on a custom provider, which has no subscription, and when the Copilot could not read it.
1299
+ */
1300
+ usage: CredentialUsage | null;
1301
+ }
1284
1302
  interface CredentialStatus {
1285
1303
  provider: CopilotProvider;
1286
1304
  connected: boolean;
@@ -1401,6 +1419,108 @@ interface SendEmailInput {
1401
1419
  /** Plain-text alternative for clients that do not render HTML. */
1402
1420
  text?: string;
1403
1421
  }
1422
+ /**
1423
+ * The account emails an app may rewrite with its own token. Messenger sends them from the app's
1424
+ * sender settings or the brand, so a template never picks its sender.
1425
+ */
1426
+ type EmailTemplateType = "SIGN_IN" | "SSO_GUIDANCE" | "APP_USER_INVITED" | "APP_ACCESS_REQUIRED";
1427
+ interface EmailTemplate {
1428
+ id: string;
1429
+ /**
1430
+ * An `EmailTemplateType` with an app token. Kept as a string because a console token also
1431
+ * lists the platform's other types, and a type Messenger opens later must not break the list.
1432
+ */
1433
+ type: string;
1434
+ /** Always null for these types: their sender comes from the app settings or the brand. */
1435
+ senderIdentityId: string | null;
1436
+ subject: string;
1437
+ htmlBody: string;
1438
+ textBody: string | null;
1439
+ /** True on a platform row. The list returns it next to the app's own row when the app rewrote the type. */
1440
+ platformDefault: boolean;
1441
+ createdAt: string;
1442
+ updatedAt: string;
1443
+ }
1444
+ interface EmailTemplateVariable {
1445
+ /** Referenced in a template as `$name`. */
1446
+ name: string;
1447
+ /** A required variable must appear in the subject or the HTML body. */
1448
+ required: boolean;
1449
+ description: string | null;
1450
+ /** Sample value used to render the preview. */
1451
+ preview: string | null;
1452
+ }
1453
+ interface EmailTemplateTypeCatalog {
1454
+ type: string;
1455
+ variables: EmailTemplateVariable[];
1456
+ }
1457
+ /** Replaces the app's version of the template as a whole. */
1458
+ interface EmailTemplateInput {
1459
+ subject: string;
1460
+ htmlBody: string;
1461
+ /** Left out, the plain-text version saved before is cleared. */
1462
+ textBody?: string;
1463
+ }
1464
+ /** The template rendered with the preview values of its variables. */
1465
+ interface EmailTemplatePreview {
1466
+ subject: string;
1467
+ htmlBody: string;
1468
+ textBody: string | null;
1469
+ }
1470
+ interface EmailTemplateUpsertResult {
1471
+ template: EmailTemplate;
1472
+ /** Null when only the preview failed; the template is saved all the same. */
1473
+ preview: EmailTemplatePreview | null;
1474
+ /** The transport or response error of the preview, unchanged, when `preview` is null. */
1475
+ previewError?: unknown;
1476
+ }
1477
+ /** An address of a person, available as a sender in the app's workspace. */
1478
+ interface EmailSender {
1479
+ id: string;
1480
+ email: string;
1481
+ displayName: string;
1482
+ /**
1483
+ * `PENDING`, `VERIFIED` or `FAILED`. Kept as a string so a status Messenger adds later does not
1484
+ * break the list. Only a `VERIFIED` address signs the app's emails.
1485
+ */
1486
+ status: string;
1487
+ sharedWithCurrentWorkspace: boolean;
1488
+ /** True until the person confirms the 6-digit code Messenger sent to the address. */
1489
+ ownerConfirmationPending: boolean;
1490
+ createdAt: string;
1491
+ updatedAt: string;
1492
+ }
1493
+ interface EmailSenderInput {
1494
+ email: string;
1495
+ /** Name of the address; the app settings may override it in the From header. */
1496
+ displayName: string;
1497
+ }
1498
+ /** The From the app's emails use now, which falls back to the brand while the app sender cannot sign. */
1499
+ interface EffectiveEmailSender {
1500
+ email: string;
1501
+ displayName: string | null;
1502
+ /** `APP_SENDER` or `BRAND_DEFAULT`, as a string for the same reason as `EmailSender.status`. */
1503
+ source: string;
1504
+ /** Why the brand signs: `NO_SETTINGS`, `IDENTITY_NOT_VERIFIED` or `IDENTITY_NOT_SHARED`. */
1505
+ reason: string | null;
1506
+ }
1507
+ interface EmailSettings {
1508
+ appId: string;
1509
+ senderIdentityId: string | null;
1510
+ displayName: string | null;
1511
+ replyTo: string | null;
1512
+ effectiveSender: EffectiveEmailSender;
1513
+ /** True when the app's own templates go out even while the brand signs. */
1514
+ ownTemplateSendsFromBrand: boolean;
1515
+ }
1516
+ /** Replaces the app's settings as a whole: a field left out or null is cleared. */
1517
+ interface EmailSettingsInput {
1518
+ /** An `EmailSender.id` from `listEmailSenders`; without it the app sends from the brand. */
1519
+ senderIdentityId?: string | null;
1520
+ /** Single line, shown in the From header. */
1521
+ displayName?: string | null;
1522
+ replyTo?: string | null;
1523
+ }
1404
1524
  interface AppContext {
1405
1525
  appId: string;
1406
1526
  app: AppDefinition;
@@ -1461,6 +1581,14 @@ interface AgentCredentialsModule {
1461
1581
  list(options?: AgentCredentialOptions): Promise<CredentialStatus[]>;
1462
1582
  /** Lists models backed by a usable credential, optionally through a business agent connection. */
1463
1583
  listModels(agentId?: string, options?: AgentCredentialOptions): Promise<AgentModel[]>;
1584
+ /**
1585
+ * The providers the next turn can run on, as the Copilot assembles them in one call: one entry
1586
+ * per built-in provider and per custom provider of `listModels(agentId)`, in the catalog's order,
1587
+ * each with its models and, for the built-in ones, the reading `usage(provider)` answers. A
1588
+ * reading the Copilot cannot get comes as null. With an `agentId` the models are the agent
1589
+ * connection's, and the reading is still the person's own login.
1590
+ */
1591
+ providers(agentId?: string, options?: AgentCredentialOptions): Promise<AgentReadyProvider[]>;
1464
1592
  /**
1465
1593
  * The last subscription window a chat on this credential reported, readable with no chat open.
1466
1594
  * Resolves to null until a turn on the provider's subscription login has reported one; an API
@@ -1893,8 +2021,48 @@ interface MessengerModule {
1893
2021
  notify(content: string): Promise<MessageAccepted>;
1894
2022
  /** Sends an email from the app's sender; only the app's backend token may send. */
1895
2023
  sendEmail(input: SendEmailInput): Promise<MessageAccepted>;
1896
- }
1897
- declare function createMessengerModule(transport: Transport, errors?: SdkCoreErrorFactory): MessengerModule;
2024
+ /**
2025
+ * Lists the current app's email templates: the platform row (`platformDefault: true`) of every
2026
+ * type and, beside it, the app's row for each type the app has rewritten.
2027
+ */
2028
+ listEmailTemplates(): Promise<EmailTemplate[]>;
2029
+ /** Gets the variables a type accepts, referenced as `$name` in the subject and HTML body. */
2030
+ getEmailTemplateType(type: EmailTemplateType): Promise<EmailTemplateTypeCatalog>;
2031
+ /** Gets the current app's version of a template, or the platform text when it has none. */
2032
+ getEmailTemplate(type: EmailTemplateType): Promise<EmailTemplate>;
2033
+ /**
2034
+ * Replaces the current app's version of a template and renders its preview. Every required
2035
+ * variable must appear in the subject or the HTML body.
2036
+ */
2037
+ upsertEmailTemplate(type: EmailTemplateType, input: EmailTemplateInput): Promise<EmailTemplateUpsertResult>;
2038
+ /**
2039
+ * Renders the app's saved template, or the platform one, with the catalog's sample values. It
2040
+ * does not prove which HTML goes out: the sender and the brand policy decide that at send time.
2041
+ */
2042
+ previewEmailTemplate(type: EmailTemplateType): Promise<EmailTemplatePreview>;
2043
+ /** Deletes the current app's version of a template, so the platform text applies again. */
2044
+ deleteEmailTemplate(type: EmailTemplateType): Promise<void>;
2045
+ /** Lists the addresses available as senders in the workspace of the token. */
2046
+ listEmailSenders(): Promise<EmailSender[]>;
2047
+ /**
2048
+ * Registers an address in the name of the person in the token and makes it available in the
2049
+ * app's workspace. An address the person already owns comes back as saved, made available too.
2050
+ * Messenger mails a verification link and a 6-digit code to the address.
2051
+ */
2052
+ registerEmailSender(input: EmailSenderInput): Promise<EmailSender>;
2053
+ /**
2054
+ * Mails the AWS link again while AWS has not verified the address, and a new code only while
2055
+ * the person has not confirmed one yet.
2056
+ */
2057
+ resendEmailSenderVerification(senderId: string): Promise<EmailSender>;
2058
+ /** Confirms the 6-digit code the person read in the mailbox of the address. */
2059
+ confirmEmailSender(senderId: string, code: string): Promise<EmailSender>;
2060
+ /** Gets the current app's sender settings and the From its emails use now. */
2061
+ getEmailSettings(): Promise<EmailSettings>;
2062
+ /** Replaces the current app's sender settings; a field left out is cleared. */
2063
+ updateEmailSettings(input: EmailSettingsInput): Promise<EmailSettings>;
2064
+ }
2065
+ declare function createMessengerModule(transport: Transport, errors?: SdkCoreErrorFactory, getAppId?: () => string | undefined): MessengerModule;
1898
2066
 
1899
2067
  interface PublicFunctionsModule {
1900
2068
  /**
@@ -1966,7 +2134,7 @@ interface SdkCoreTransports {
1966
2134
  codeStudio?: Transport;
1967
2135
  /** Copilot transport for tasks, credentials, models, and app connections. */
1968
2136
  copilot?: Transport;
1969
- /** Messenger transport for current-user notifications. */
2137
+ /** Messenger transport for current-user notifications, app emails, and their templates. */
1970
2138
  messenger?: Transport;
1971
2139
  /**
1972
2140
  * Anonymous Functions transport. It must not add Authorization or X-App-Id headers.
@@ -2398,6 +2566,18 @@ interface AgentTaskSession {
2398
2566
  loadHistory(options?: {
2399
2567
  limit?: number;
2400
2568
  }): Promise<readonly AgentTimelineItem[]>;
2569
+ /**
2570
+ * Whether the Copilot has rows older than the oldest row `history` holds, as the last page read
2571
+ * said. False until a history was loaded.
2572
+ */
2573
+ readonly hasOlder: boolean;
2574
+ /**
2575
+ * Reads the page before the oldest row `history` holds, with the size `loadHistory` used, and
2576
+ * puts it before `history`, in the box's order. Resolves with the items it added (none when
2577
+ * there is nothing older) and emits `historyLoaded`. A read still running when `history` is
2578
+ * replaced resolves with nothing.
2579
+ */
2580
+ loadOlder(): Promise<readonly AgentTimelineItem[]>;
2401
2581
  /** Changes the text of a queued message (T3's `queued-run.edit`); only the box channel takes it. */
2402
2582
  editQueueItem(id: string, text: string): void;
2403
2583
  /** Takes a message out of the queue (T3's `queued-run.cancel`); only the box channel takes it. */
@@ -2492,4 +2672,4 @@ declare function expectPage<T extends object>(value: unknown, context: string, e
2492
2672
  declare function expectLegacyPage<T extends object>(value: unknown, context: string, errors?: SdkCoreErrorFactory, validateItem?: (value: unknown, context: string, errors: SdkCoreErrorFactory) => T): LegacyPage<T>;
2493
2673
  declare function expectEmpty(value: unknown, context: string, errors?: SdkCoreErrorFactory): void;
2494
2674
 
2495
- export { API_KEY_EXCHANGE_PATH, type AgentBackgroundTask, type AgentBulkDeleteResult, type AgentConnection, type AgentConnectionCreateInput, type AgentConnectionCustomProvider, type AgentConnectionCustomProviderInput, type AgentConnectionsModule, type AgentCredentialOptions, type AgentCredentialScope, type AgentCredentialsModule, type AgentDefinition, type AgentDirectChannelOptions, type AgentFetch, type AgentFetchResponse, type AgentHistoryCursor, type AgentInput, type AgentMessage, type AgentMessageListOptions, type AgentModel, type AgentPieceIdentity, type AgentProviderUsage, type AgentQueueItem, type AgentSendAndWaitOptions, type AgentSendOptions, type AgentSessionTransport, type AgentSubagent, type AgentSubagentFrame, type AgentSubagentStatus, type AgentTask, type AgentTaskChannel, type AgentTaskCreateInput, type AgentTaskEvent, type AgentTaskEventConnection, type AgentTaskEventObserver, type AgentTaskEventSource, type AgentTaskInput, type AgentTaskListOptions, type AgentTaskRuntime, type AgentTaskSession, type AgentTaskSessionEventMap, type AgentTaskSessionManager, type AgentTaskSessionManagerOptions, type AgentTaskSessionOptions, type AgentTaskSessionStatus, AgentTaskTurnError, type AgentTasksModule, type AgentTasksWithSessions, type AgentTimelineItem, type AgentTimelineItemIdentity, type AgentToolEvent, type AgentTurnResult, type AgentTurnUsage, type AgentTurnUsageRequest, type AgentUpdateItem, type AgentWebSocket, type AgentWebSocketConstructor, type AgentsModule, type ApiKeyExchangeCaller, type AppColor, type AppContext, type AppCreateInput, type AppDefinition, type AppDeploy, type AppDomain, type AppFiles, type AppGetOptions, type AppListOptions, type AppMember, type AppPublishOptions, type AppSummary, type AppUpdateInput, type AppVersion, type AppVersionStatus, type AppsModule, type AuthModule, type AuthenticationResult, type BatchExecution, type BatchStatementResult, type BulkUnsubscribeResult, type ColumnInput, type ConnectionConfig, type ConnectionConfigResponse, type ConnectionTestResult, type ContextModule, type ContextModuleDependencies, type CopilotProvider, type CredentialStatus, type CredentialUsage, type CredentialUsageWindow, type CustomQueriesModule, type CustomQueryDefinition, type CustomQueryInput, type CustomQuerySummary, type CustomQueryUpdateInput, type DataSourceBulkItemResult, type DataSourceBulkResult, type DataSourceCreateInput, type DataSourceDbType, type DataSourceDefinition, type DataSourceInstanceType, type DataSourceUpdateInput, type DataSourcesModule, type DdlStatement, type DeviceAuthorization, type DmlStatement, type EmptyFunctionInput, type EntitiesModule, type EntitiesProxy, type EntityListOptions, type EntityListResponse, type EntityTable, type ExistingAgentTaskSessionOptions, type FunctionBulkCreateInput, type FunctionBulkDeleteInput, type FunctionBulkDeleteResult, type FunctionBulkPatchInput, type FunctionBulkPatchItem, type FunctionBulkUpdateItem, type FunctionCreateInput, type FunctionDefinition, type FunctionExecution, type FunctionListOptions, type FunctionPatchInput, type FunctionRuntime, type FunctionSecrets, type FunctionSummary, type FunctionUpdateInput, type FunctionVersion, type FunctionVersionListOptions, type FunctionVisibility, type FunctionsAdminModule, type FunctionsModule, type FunctionsModuleOptions, type HttpMethod, type ImportColumnMapping, type ImportDefinition, type ImportExecution, type ImportExecutionListOptions, type ImportInput, type ImportProcessing, type ImportSchedule, type ImportSource, type ImportSourceResponse, type ImportTarget, type ImportsModule, type IntegrationAdminModule, type IntegrationConnectionStatus, type IntegrationCredentialRule, type IntegrationExecution, type IntegrationFieldSchema, type IntegrationFieldSchemaInput, type IntegrationLoginConfig, type IntegrationModule, type IntegrationProxyMode, type IntegrationRequestConfig, type IntegrationResource, type IntegrationResourceInput, type IntegrationResourceParam, type IntegrationResourceSummary, type IntegrationResourceUpdateInput, type IntegrationResourcesModule, type IntegrationTemplate, type IntegrationTemplateSummary, type IntegrationTemplateType, type IntegrationTemplatesModule, type IntegrationTokenExtraction, type InviteAppUserInput, type InvocationType, type JsonValue, type LegacyPage, type ListTablesOptions, type ListTemplateConfigsOptions, type MembersModule, type MessageAccepted, type MessengerModule, type NewAgentTaskSessionOptions, type OAuthExchangeInput, type OAuthStartResult, type Page, type PageOptions, type PlanPrice, type ProviderCredentialStatus, type ProxyInput, type ProxyResult, type PublicFunctionAsyncResult, type PublicFunctionResult, type PublicFunctionsModule, type QueriesModule, type QueryParamPrimitive, type QueryParamValue, type QueryResult, type SchemaModule, type SchemaScope, type SchemaTables, type SdkCore, SdkCoreConfigurationError, type SdkCoreErrorFactory, type SdkCoreOptions, SdkCoreResponseError, type SdkCoreTransports, type SendEmailInput, type SqlModule, type TableColumn, type TableDefinition, type TableForeignKey, type TemplateConfig, type TemplateConfigBulkItemResult, type TemplateConfigBulkResult, type TemplateConfigCreateInput, type TemplateConfigPage, type TemplateConfigSummary, type TemplateConfigUpdateInput, type Tenant, type TestCredentialsInput, type Transport, type TransportRequestOptions, type User, type UserPlan, type WorkflowDefinition, type WorkflowExecution, type WorkflowInput, type WorkflowSummary, type WorkflowsModule, appAccessTokenPath, createAgentConnectionsModule, createAgentCredentialsModule, createAgentTaskSessionManager, createAgentTasksModule, createAgentsModule, createAppsModule, createAuthModule, createContextModule, createCustomQueriesModule, createDataSourcesModule, createEntitiesModule, createFunctionsAdminModule, createFunctionsModule, createImportsModule, createIntegrationAdminModule, createIntegrationModule, createIntegrationResourcesModule, createIntegrationTemplatesModule, createMembersModule, createMessengerModule, createPublicFunctionsModule, createQueriesModule, createSchemaModule, createSdkCore, createSqlModule, createWorkflowsModule, defaultSdkCoreErrorFactory, encodePathSegment, expectEmpty, expectLegacyPage, expectNullableObject, expectObject, expectObjectArray, expectPage, expectStringArray, isWorkspaceSession, readTokenAppId, readTokenExpiry, resolveApiKeyToken, toAgentTimelineItem, tokenAuthorizesApp, withAgentTaskSessions };
2675
+ export { API_KEY_EXCHANGE_PATH, type AgentBackgroundTask, type AgentBulkDeleteResult, type AgentConnection, type AgentConnectionCreateInput, type AgentConnectionCustomProvider, type AgentConnectionCustomProviderInput, type AgentConnectionsModule, type AgentCredentialOptions, type AgentCredentialScope, type AgentCredentialsModule, type AgentDefinition, type AgentDirectChannelOptions, type AgentFetch, type AgentFetchResponse, type AgentHistoryCursor, type AgentInput, type AgentMessage, type AgentMessageListOptions, type AgentModel, type AgentPieceIdentity, type AgentProviderUsage, type AgentQueueItem, type AgentReadyProvider, type AgentSendAndWaitOptions, type AgentSendOptions, type AgentSessionTransport, type AgentSubagent, type AgentSubagentFrame, type AgentSubagentStatus, type AgentTask, type AgentTaskChannel, type AgentTaskCreateInput, type AgentTaskEvent, type AgentTaskEventConnection, type AgentTaskEventObserver, type AgentTaskEventSource, type AgentTaskInput, type AgentTaskListOptions, type AgentTaskRuntime, type AgentTaskSession, type AgentTaskSessionEventMap, type AgentTaskSessionManager, type AgentTaskSessionManagerOptions, type AgentTaskSessionOptions, type AgentTaskSessionStatus, AgentTaskTurnError, type AgentTasksModule, type AgentTasksWithSessions, type AgentTimelineItem, type AgentTimelineItemIdentity, type AgentToolEvent, type AgentTurnResult, type AgentTurnUsage, type AgentTurnUsageRequest, type AgentUpdateItem, type AgentWebSocket, type AgentWebSocketConstructor, type AgentsModule, type ApiKeyExchangeCaller, type AppColor, type AppContext, type AppCreateInput, type AppDefinition, type AppDeploy, type AppDomain, type AppFiles, type AppGetOptions, type AppListOptions, type AppMember, type AppPublishOptions, type AppSummary, type AppUpdateInput, type AppVersion, type AppVersionStatus, type AppsModule, type AuthModule, type AuthenticationResult, type BatchExecution, type BatchStatementResult, type BulkUnsubscribeResult, type ColumnInput, type ConnectionConfig, type ConnectionConfigResponse, type ConnectionTestResult, type ContextModule, type ContextModuleDependencies, type CopilotProvider, type CredentialStatus, type CredentialUsage, type CredentialUsageWindow, type CustomQueriesModule, type CustomQueryDefinition, type CustomQueryInput, type CustomQuerySummary, type CustomQueryUpdateInput, type DataSourceBulkItemResult, type DataSourceBulkResult, type DataSourceCreateInput, type DataSourceDbType, type DataSourceDefinition, type DataSourceInstanceType, type DataSourceUpdateInput, type DataSourcesModule, type DdlStatement, type DeviceAuthorization, type DmlStatement, type EffectiveEmailSender, type EmailSender, type EmailSenderInput, type EmailSettings, type EmailSettingsInput, type EmailTemplate, type EmailTemplateInput, type EmailTemplatePreview, type EmailTemplateType, type EmailTemplateTypeCatalog, type EmailTemplateUpsertResult, type EmailTemplateVariable, type EmptyFunctionInput, type EntitiesModule, type EntitiesProxy, type EntityListOptions, type EntityListResponse, type EntityTable, type ExistingAgentTaskSessionOptions, type FunctionBulkCreateInput, type FunctionBulkDeleteInput, type FunctionBulkDeleteResult, type FunctionBulkPatchInput, type FunctionBulkPatchItem, type FunctionBulkUpdateItem, type FunctionCreateInput, type FunctionDefinition, type FunctionExecution, type FunctionListOptions, type FunctionPatchInput, type FunctionRuntime, type FunctionSecrets, type FunctionSummary, type FunctionUpdateInput, type FunctionVersion, type FunctionVersionListOptions, type FunctionVisibility, type FunctionsAdminModule, type FunctionsModule, type FunctionsModuleOptions, type HttpMethod, type ImportColumnMapping, type ImportDefinition, type ImportExecution, type ImportExecutionListOptions, type ImportInput, type ImportProcessing, type ImportSchedule, type ImportSource, type ImportSourceResponse, type ImportTarget, type ImportsModule, type IntegrationAdminModule, type IntegrationConnectionStatus, type IntegrationCredentialRule, type IntegrationExecution, type IntegrationFieldSchema, type IntegrationFieldSchemaInput, type IntegrationLoginConfig, type IntegrationModule, type IntegrationProxyMode, type IntegrationRequestConfig, type IntegrationResource, type IntegrationResourceInput, type IntegrationResourceParam, type IntegrationResourceSummary, type IntegrationResourceUpdateInput, type IntegrationResourcesModule, type IntegrationTemplate, type IntegrationTemplateSummary, type IntegrationTemplateType, type IntegrationTemplatesModule, type IntegrationTokenExtraction, type InviteAppUserInput, type InvocationType, type JsonValue, type LegacyPage, type ListTablesOptions, type ListTemplateConfigsOptions, type MembersModule, type MessageAccepted, type MessengerModule, type NewAgentTaskSessionOptions, type OAuthExchangeInput, type OAuthStartResult, type Page, type PageOptions, type PlanPrice, type ProviderCredentialStatus, type ProxyInput, type ProxyResult, type PublicFunctionAsyncResult, type PublicFunctionResult, type PublicFunctionsModule, type QueriesModule, type QueryParamPrimitive, type QueryParamValue, type QueryResult, type SchemaModule, type SchemaScope, type SchemaTables, type SdkCore, SdkCoreConfigurationError, type SdkCoreErrorFactory, type SdkCoreOptions, SdkCoreResponseError, type SdkCoreTransports, type SendEmailInput, type SqlModule, type TableColumn, type TableDefinition, type TableForeignKey, type TemplateConfig, type TemplateConfigBulkItemResult, type TemplateConfigBulkResult, type TemplateConfigCreateInput, type TemplateConfigPage, type TemplateConfigSummary, type TemplateConfigUpdateInput, type Tenant, type TestCredentialsInput, type Transport, type TransportRequestOptions, type User, type UserPlan, type WorkflowDefinition, type WorkflowExecution, type WorkflowInput, type WorkflowSummary, type WorkflowsModule, appAccessTokenPath, createAgentConnectionsModule, createAgentCredentialsModule, createAgentTaskSessionManager, createAgentTasksModule, createAgentsModule, createAppsModule, createAuthModule, createContextModule, createCustomQueriesModule, createDataSourcesModule, createEntitiesModule, createFunctionsAdminModule, createFunctionsModule, createImportsModule, createIntegrationAdminModule, createIntegrationModule, createIntegrationResourcesModule, createIntegrationTemplatesModule, createMembersModule, createMessengerModule, createPublicFunctionsModule, createQueriesModule, createSchemaModule, createSdkCore, createSqlModule, createWorkflowsModule, defaultSdkCoreErrorFactory, encodePathSegment, expectEmpty, expectLegacyPage, expectNullableObject, expectObject, expectObjectArray, expectPage, expectStringArray, isWorkspaceSession, readTokenAppId, readTokenExpiry, resolveApiKeyToken, toAgentTimelineItem, tokenAuthorizesApp, withAgentTaskSessions };
package/dist/index.js CHANGED
@@ -48,6 +48,9 @@ function isObject(value) {
48
48
  function isNullableString(value) {
49
49
  return value === null || typeof value === "string";
50
50
  }
51
+ function isNonEmptyString(value) {
52
+ return typeof value === "string" && value.length > 0;
53
+ }
51
54
  function isNullableBoolean(value) {
52
55
  return value === null || typeof value === "boolean";
53
56
  }
@@ -681,6 +684,83 @@ function expectMessageAccepted(value, context, errors = defaultSdkCoreErrorFacto
681
684
  if (typeof response.messageId !== "string") invalidField(context, "messageId", errors);
682
685
  return response;
683
686
  }
687
+ function expectEmailTemplate(value, context, errors = defaultSdkCoreErrorFactory) {
688
+ const template = expectObject(value, context, errors);
689
+ if (typeof template.id !== "string") invalidField(context, "id", errors);
690
+ if (!isNonEmptyString(template.type)) invalidField(context, "type", errors);
691
+ if (!isNullableString(template.senderIdentityId)) {
692
+ invalidField(context, "senderIdentityId", errors);
693
+ }
694
+ if (typeof template.subject !== "string") invalidField(context, "subject", errors);
695
+ if (typeof template.htmlBody !== "string") invalidField(context, "htmlBody", errors);
696
+ if (!isNullableString(template.textBody)) invalidField(context, "textBody", errors);
697
+ if (typeof template.platformDefault !== "boolean") {
698
+ invalidField(context, "platformDefault", errors);
699
+ }
700
+ if (typeof template.createdAt !== "string") invalidField(context, "createdAt", errors);
701
+ if (typeof template.updatedAt !== "string") invalidField(context, "updatedAt", errors);
702
+ return template;
703
+ }
704
+ function expectEmailTemplateTypeCatalog(value, context, errors = defaultSdkCoreErrorFactory) {
705
+ const catalog = expectObject(value, context, errors);
706
+ if (!isNonEmptyString(catalog.type)) invalidField(context, "type", errors);
707
+ expectObjectArray(catalog.variables, `${context} variables`, errors).forEach(
708
+ (variable, position) => {
709
+ const variableContext = `${context} variable ${position}`;
710
+ if (typeof variable.name !== "string") invalidField(variableContext, "name", errors);
711
+ if (typeof variable.required !== "boolean") {
712
+ invalidField(variableContext, "required", errors);
713
+ }
714
+ if (!isNullableString(variable.description)) {
715
+ invalidField(variableContext, "description", errors);
716
+ }
717
+ if (!isNullableString(variable.preview)) invalidField(variableContext, "preview", errors);
718
+ }
719
+ );
720
+ return catalog;
721
+ }
722
+ function expectEmailTemplatePreview(value, context, errors = defaultSdkCoreErrorFactory) {
723
+ const preview = expectObject(value, context, errors);
724
+ if (typeof preview.subject !== "string") invalidField(context, "subject", errors);
725
+ if (typeof preview.htmlBody !== "string") invalidField(context, "htmlBody", errors);
726
+ if (!isNullableString(preview.textBody)) invalidField(context, "textBody", errors);
727
+ return preview;
728
+ }
729
+ function expectEmailSender(value, context, errors = defaultSdkCoreErrorFactory) {
730
+ const sender = expectObject(value, context, errors);
731
+ if (typeof sender.id !== "string") invalidField(context, "id", errors);
732
+ if (typeof sender.email !== "string") invalidField(context, "email", errors);
733
+ if (typeof sender.displayName !== "string") invalidField(context, "displayName", errors);
734
+ if (!isNonEmptyString(sender.status)) invalidField(context, "status", errors);
735
+ if (typeof sender.sharedWithCurrentWorkspace !== "boolean") {
736
+ invalidField(context, "sharedWithCurrentWorkspace", errors);
737
+ }
738
+ if (typeof sender.ownerConfirmationPending !== "boolean") {
739
+ invalidField(context, "ownerConfirmationPending", errors);
740
+ }
741
+ if (typeof sender.createdAt !== "string") invalidField(context, "createdAt", errors);
742
+ if (typeof sender.updatedAt !== "string") invalidField(context, "updatedAt", errors);
743
+ return sender;
744
+ }
745
+ function expectEmailSettings(value, context, errors = defaultSdkCoreErrorFactory) {
746
+ const settings = expectObject(value, context, errors);
747
+ if (typeof settings.appId !== "string") invalidField(context, "appId", errors);
748
+ if (!isNullableString(settings.senderIdentityId)) {
749
+ invalidField(context, "senderIdentityId", errors);
750
+ }
751
+ if (!isNullableString(settings.displayName)) invalidField(context, "displayName", errors);
752
+ if (!isNullableString(settings.replyTo)) invalidField(context, "replyTo", errors);
753
+ if (typeof settings.ownTemplateSendsFromBrand !== "boolean") {
754
+ invalidField(context, "ownTemplateSendsFromBrand", errors);
755
+ }
756
+ const senderContext = `${context} effectiveSender`;
757
+ const sender = expectObject(settings.effectiveSender, senderContext, errors);
758
+ if (typeof sender.email !== "string") invalidField(senderContext, "email", errors);
759
+ if (!isNullableString(sender.displayName)) invalidField(senderContext, "displayName", errors);
760
+ if (!isNonEmptyString(sender.source)) invalidField(senderContext, "source", errors);
761
+ if (!isNullableString(sender.reason)) invalidField(senderContext, "reason", errors);
762
+ return settings;
763
+ }
684
764
  function expectAgentDefinition(value, context, errors = defaultSdkCoreErrorFactory) {
685
765
  const agent = expectObject(value, context, errors);
686
766
  if (typeof agent.id !== "string") invalidField(context, "id", errors);
@@ -1055,6 +1135,14 @@ function expectCredentialUsage(value, context, errors = defaultSdkCoreErrorFacto
1055
1135
  }
1056
1136
  return usage;
1057
1137
  }
1138
+ function expectAgentReadyProvider(value, context, errors = defaultSdkCoreErrorFactory) {
1139
+ const entry = expectObject(value, context, errors);
1140
+ if (typeof entry.provider !== "string") invalidField(context, "provider", errors);
1141
+ if (!isNullableString(entry.providerName)) invalidField(context, "providerName", errors);
1142
+ expectObjectArray(entry.models, `${context} models`, errors, expectAgentModel);
1143
+ if (entry.usage !== null) expectCredentialUsage(entry.usage, `${context} usage`, errors);
1144
+ return entry;
1145
+ }
1058
1146
  var CREDENTIAL_USAGE_NOT_FOUND = "CREDENTIAL_USAGE_NOT_FOUND";
1059
1147
  async function readCredentialUsage(request, context, errors = defaultSdkCoreErrorFactory) {
1060
1148
  let value;
@@ -1343,6 +1431,17 @@ function createAgentCredentialsModule(transport, errors = defaultSdkCoreErrorFac
1343
1431
  expectAgentModel
1344
1432
  );
1345
1433
  },
1434
+ async providers(agentId, options) {
1435
+ return expectObjectArray(
1436
+ await transport.request("/api/v1/models/providers", {
1437
+ method: "GET",
1438
+ params: { agentId, ...scopeParams(options).params }
1439
+ }),
1440
+ "Ready provider response",
1441
+ errors,
1442
+ expectAgentReadyProvider
1443
+ );
1444
+ },
1346
1445
  async usage(provider, options) {
1347
1446
  return readCredentialUsage(
1348
1447
  transport.request(`/api/v1/credentials/${providerSegment(provider)}/usage`, {
@@ -1619,7 +1718,8 @@ function createAgentTasksModule(transport, errors = defaultSdkCoreErrorFactory)
1619
1718
  page: options.page,
1620
1719
  size: options.size,
1621
1720
  sort: options.sort,
1622
- kinds: options.kinds
1721
+ kinds: options.kinds,
1722
+ before: options.before
1623
1723
  }
1624
1724
  }),
1625
1725
  context,
@@ -2858,7 +2958,23 @@ function createMembersModule(transport, errors = defaultSdkCoreErrorFactory) {
2858
2958
  }
2859
2959
 
2860
2960
  // src/modules/messenger.ts
2861
- function createMessengerModule(transport, errors = defaultSdkCoreErrorFactory) {
2961
+ function createMessengerModule(transport, errors = defaultSdkCoreErrorFactory, getAppId) {
2962
+ const templatePath = (type) => `/api/v1/email/templates/${encodePathSegment(type, "email template type", errors)}`;
2963
+ const senderPath = (senderId) => `/api/v1/email/identities/${encodePathSegment(senderId, "email sender id", errors)}`;
2964
+ const currentAppId = () => {
2965
+ const appId = getAppId?.();
2966
+ if (!appId) configurationError("An appId is required for app email calls", errors);
2967
+ return appId;
2968
+ };
2969
+ const settingsPath = () => `/api/v1/email/apps/${encodePathSegment(currentAppId(), "app id", errors)}/settings`;
2970
+ const preview = async (type, appId) => expectEmailTemplatePreview(
2971
+ await transport.request(`${templatePath(type)}/preview`, {
2972
+ method: "GET",
2973
+ params: { appId }
2974
+ }),
2975
+ "Email template preview response",
2976
+ errors
2977
+ );
2862
2978
  return {
2863
2979
  async notify(content) {
2864
2980
  return expectMessageAccepted(
@@ -2879,6 +2995,120 @@ function createMessengerModule(transport, errors = defaultSdkCoreErrorFactory) {
2879
2995
  "Send email response",
2880
2996
  errors
2881
2997
  );
2998
+ },
2999
+ async listEmailTemplates() {
3000
+ return expectObjectArray(
3001
+ await transport.request("/api/v1/email/templates", {
3002
+ method: "GET",
3003
+ params: { appId: currentAppId() }
3004
+ }),
3005
+ "Email template list response",
3006
+ errors,
3007
+ expectEmailTemplate
3008
+ );
3009
+ },
3010
+ async getEmailTemplateType(type) {
3011
+ return expectEmailTemplateTypeCatalog(
3012
+ await transport.request(
3013
+ `/api/v1/email/template-types/${encodePathSegment(type, "email template type", errors)}`,
3014
+ { method: "GET" }
3015
+ ),
3016
+ "Email template type response",
3017
+ errors
3018
+ );
3019
+ },
3020
+ async getEmailTemplate(type) {
3021
+ return expectEmailTemplate(
3022
+ await transport.request(templatePath(type), {
3023
+ method: "GET",
3024
+ params: { appId: currentAppId() }
3025
+ }),
3026
+ "Email template response",
3027
+ errors
3028
+ );
3029
+ },
3030
+ async upsertEmailTemplate(type, input) {
3031
+ const appId = currentAppId();
3032
+ const template = expectEmailTemplate(
3033
+ await transport.request(templatePath(type), {
3034
+ method: "PUT",
3035
+ body: templateBody(appId, input)
3036
+ }),
3037
+ "Upsert email template response",
3038
+ errors
3039
+ );
3040
+ try {
3041
+ return { template, preview: await preview(type, appId) };
3042
+ } catch (previewError) {
3043
+ return { template, preview: null, previewError };
3044
+ }
3045
+ },
3046
+ async previewEmailTemplate(type) {
3047
+ return preview(type, currentAppId());
3048
+ },
3049
+ async deleteEmailTemplate(type) {
3050
+ expectEmpty(
3051
+ await transport.request(templatePath(type), {
3052
+ method: "DELETE",
3053
+ params: { appId: currentAppId() }
3054
+ }),
3055
+ "Delete email template response",
3056
+ errors
3057
+ );
3058
+ },
3059
+ async listEmailSenders() {
3060
+ return expectObjectArray(
3061
+ await transport.request("/api/v1/email/identities/workspace", { method: "GET" }),
3062
+ "Email sender list response",
3063
+ errors,
3064
+ expectEmailSender
3065
+ );
3066
+ },
3067
+ async registerEmailSender(input) {
3068
+ return expectEmailSender(
3069
+ await transport.request("/api/v1/email/identities", {
3070
+ method: "POST",
3071
+ body: { email: input.email, displayName: input.displayName }
3072
+ }),
3073
+ "Register email sender response",
3074
+ errors
3075
+ );
3076
+ },
3077
+ async resendEmailSenderVerification(senderId) {
3078
+ return expectEmailSender(
3079
+ await transport.request(`${senderPath(senderId)}/resend-verification`, {
3080
+ method: "POST"
3081
+ }),
3082
+ "Resend email sender verification response",
3083
+ errors
3084
+ );
3085
+ },
3086
+ async confirmEmailSender(senderId, code) {
3087
+ return expectEmailSender(
3088
+ await transport.request(`${senderPath(senderId)}/confirm`, {
3089
+ method: "POST",
3090
+ body: { code }
3091
+ }),
3092
+ "Confirm email sender response",
3093
+ errors
3094
+ );
3095
+ },
3096
+ async getEmailSettings() {
3097
+ return expectEmailSettings(
3098
+ await transport.request(settingsPath(), { method: "GET" }),
3099
+ "Email settings response",
3100
+ errors
3101
+ );
3102
+ },
3103
+ async updateEmailSettings(input) {
3104
+ return expectEmailSettings(
3105
+ await transport.request(settingsPath(), {
3106
+ method: "PUT",
3107
+ body: settingsBody(input)
3108
+ }),
3109
+ "Update email settings response",
3110
+ errors
3111
+ );
2882
3112
  }
2883
3113
  };
2884
3114
  }
@@ -2894,6 +3124,21 @@ function rawEmailPayload(input) {
2894
3124
  ...input.text === void 0 ? {} : { text: input.text }
2895
3125
  };
2896
3126
  }
3127
+ function templateBody(appId, input) {
3128
+ return {
3129
+ appId,
3130
+ subject: input.subject,
3131
+ htmlBody: input.htmlBody,
3132
+ ...input.textBody === void 0 ? {} : { textBody: input.textBody }
3133
+ };
3134
+ }
3135
+ function settingsBody(input) {
3136
+ return {
3137
+ ...input.senderIdentityId === void 0 ? {} : { senderIdentityId: input.senderIdentityId },
3138
+ ...input.displayName === void 0 ? {} : { displayName: input.displayName },
3139
+ ...input.replyTo === void 0 ? {} : { replyTo: input.replyTo }
3140
+ };
3141
+ }
2897
3142
 
2898
3143
  // src/modules/publicFunctions.ts
2899
3144
  function createPublicFunctionsModule(transport, errors = defaultSdkCoreErrorFactory) {
@@ -3211,7 +3456,7 @@ function createSdkCore(options) {
3211
3456
  integrationResources: createIntegrationResourcesModule(options.transports.integration, errors),
3212
3457
  integrationTemplates: createIntegrationTemplatesModule(options.transports.integration, errors),
3213
3458
  members,
3214
- messenger: createMessengerModule(messengerTransport, errors),
3459
+ messenger: createMessengerModule(messengerTransport, errors, options.getAppId),
3215
3460
  publicFunctions: createPublicFunctionsModule(options.transports.publicFunctions, errors),
3216
3461
  queries: createQueriesModule(options.transports.dataManager, errors),
3217
3462
  sql: createSqlModule(options.transports.dataManager, errors),
@@ -4168,6 +4413,9 @@ function historyCursorOf(history) {
4168
4413
  }
4169
4414
  return { sequence, ...newest.boxLog === void 0 ? {} : { boxLog: newest.boxLog } };
4170
4415
  }
4416
+ function hasOlderRows(page) {
4417
+ return page.page.totalPages > page.page.number + 1;
4418
+ }
4171
4419
  function isChatRow(message) {
4172
4420
  return (message.type === "TEXT" || message.type === "ERROR" || message.type === "TOOL_USE") && message.parentToolId === void 0;
4173
4421
  }
@@ -4350,6 +4598,11 @@ var CoreAgentTaskSession = class {
4350
4598
  acceptedIds = [];
4351
4599
  // Taken by the first channel of `session({ taskId })`; no later channel asks for a replay.
4352
4600
  openingCursor;
4601
+ historyLimit;
4602
+ _hasOlder = false;
4603
+ // Moves whenever `history` is replaced, so a `loadOlder` still reading drops what it read.
4604
+ historyGeneration = 0;
4605
+ olderRead = null;
4353
4606
  get taskId() {
4354
4607
  return this._taskId;
4355
4608
  }
@@ -4446,11 +4699,52 @@ var CoreAgentTaskSession = class {
4446
4699
  sort: "createdAt,desc",
4447
4700
  kinds: "all"
4448
4701
  });
4449
- this._history = [...page.content].reverse().map(toAgentTimelineItem);
4702
+ this.historyLimit = options.limit;
4703
+ this.replaceHistory(page);
4450
4704
  const history = this.history;
4451
4705
  this.emit("historyLoaded", { history });
4452
4706
  return history;
4453
4707
  }
4708
+ get hasOlder() {
4709
+ return this._hasOlder;
4710
+ }
4711
+ loadOlder() {
4712
+ if (this.olderRead?.generation !== this.historyGeneration) {
4713
+ const generation = this.historyGeneration;
4714
+ const promise = this.readOlder(generation).finally(() => {
4715
+ if (this.olderRead?.promise === promise) this.olderRead = null;
4716
+ });
4717
+ this.olderRead = { generation, promise };
4718
+ }
4719
+ return this.olderRead.promise;
4720
+ }
4721
+ async readOlder(generation) {
4722
+ const oldest = this._history.find((item) => !item.id.startsWith("live:"));
4723
+ if (!this._taskId || !this._hasOlder || !oldest) return [];
4724
+ let page;
4725
+ try {
4726
+ page = await this.dependencies.tasks.listMessages(this._taskId, {
4727
+ before: oldest.id,
4728
+ ...this.historyLimit !== void 0 ? { size: this.historyLimit } : {},
4729
+ sort: "createdAt,desc",
4730
+ kinds: "all"
4731
+ });
4732
+ } catch (error) {
4733
+ if (generation !== this.historyGeneration || this.isClosed()) return [];
4734
+ throw error;
4735
+ }
4736
+ if (generation !== this.historyGeneration || this.isClosed()) return [];
4737
+ const older = [...page.content].reverse().map(toAgentTimelineItem);
4738
+ this._hasOlder = hasOlderRows(page);
4739
+ this._history = [...older, ...this._history];
4740
+ this.emit("historyLoaded", { history: this.history });
4741
+ return older;
4742
+ }
4743
+ replaceHistory(page) {
4744
+ this.historyGeneration += 1;
4745
+ this._hasOlder = hasOlderRows(page);
4746
+ this._history = [...page.content].reverse().map(toAgentTimelineItem);
4747
+ }
4454
4748
  editQueueItem(id, text) {
4455
4749
  this.requireOpen();
4456
4750
  if (this.sentTexts.has(id)) this.sentTexts.set(id, text);
@@ -4814,7 +5108,7 @@ var CoreAgentTaskSession = class {
4814
5108
  sort: "createdAt,desc",
4815
5109
  kinds: "all"
4816
5110
  });
4817
- this._history = [...page.content].reverse().map(toAgentTimelineItem);
5111
+ this.replaceHistory(page);
4818
5112
  this.emit("historyLoaded", { history: this.history });
4819
5113
  const rows = page.content.filter(isChatRow);
4820
5114
  const recovered = rows.find(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mitralab.io/sdk-core",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Environment-neutral contracts and modules shared by Mitra JavaScript SDKs",
5
5
  "type": "module",
6
6
  "sideEffects": false,