@mitralab.io/sdk-core 0.3.7 → 0.3.8

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.cjs CHANGED
@@ -30,6 +30,7 @@ __export(index_exports, {
30
30
  createAgentTaskSessionManager: () => createAgentTaskSessionManager,
31
31
  createAgentTasksModule: () => createAgentTasksModule,
32
32
  createAgentsModule: () => createAgentsModule,
33
+ createAiProvidersModule: () => createAiProvidersModule,
33
34
  createAppsModule: () => createAppsModule,
34
35
  createAuthModule: () => createAuthModule,
35
36
  createContextModule: () => createContextModule,
@@ -120,9 +121,6 @@ function isObject(value) {
120
121
  function isNullableString(value) {
121
122
  return value === null || typeof value === "string";
122
123
  }
123
- function isNonEmptyString(value) {
124
- return typeof value === "string" && value.length > 0;
125
- }
126
124
  function isNullableBoolean(value) {
127
125
  return value === null || typeof value === "boolean";
128
126
  }
@@ -511,9 +509,6 @@ function expectAppFields(app, context, errors) {
511
509
  if (!isNullableString(app.icon)) invalidField(context, "icon", errors);
512
510
  if (!isNullableString(app.template)) invalidField(context, "template", errors);
513
511
  if (typeof app.allowSignup !== "boolean") invalidField(context, "allowSignup", errors);
514
- for (const field of ["emailLoginEnabled", "passwordLoginEnabled"]) {
515
- if (field in app && typeof app[field] !== "boolean") invalidField(context, field, errors);
516
- }
517
512
  if (typeof app.externalAccessEnabled !== "boolean") {
518
513
  invalidField(context, "externalAccessEnabled", errors);
519
514
  }
@@ -756,83 +751,6 @@ function expectMessageAccepted(value, context, errors = defaultSdkCoreErrorFacto
756
751
  if (typeof response.messageId !== "string") invalidField(context, "messageId", errors);
757
752
  return response;
758
753
  }
759
- function expectEmailTemplate(value, context, errors = defaultSdkCoreErrorFactory) {
760
- const template = expectObject(value, context, errors);
761
- if (typeof template.id !== "string") invalidField(context, "id", errors);
762
- if (!isNonEmptyString(template.type)) invalidField(context, "type", errors);
763
- if (!isNullableString(template.senderIdentityId)) {
764
- invalidField(context, "senderIdentityId", errors);
765
- }
766
- if (typeof template.subject !== "string") invalidField(context, "subject", errors);
767
- if (typeof template.htmlBody !== "string") invalidField(context, "htmlBody", errors);
768
- if (!isNullableString(template.textBody)) invalidField(context, "textBody", errors);
769
- if (typeof template.platformDefault !== "boolean") {
770
- invalidField(context, "platformDefault", errors);
771
- }
772
- if (typeof template.createdAt !== "string") invalidField(context, "createdAt", errors);
773
- if (typeof template.updatedAt !== "string") invalidField(context, "updatedAt", errors);
774
- return template;
775
- }
776
- function expectEmailTemplateTypeCatalog(value, context, errors = defaultSdkCoreErrorFactory) {
777
- const catalog = expectObject(value, context, errors);
778
- if (!isNonEmptyString(catalog.type)) invalidField(context, "type", errors);
779
- expectObjectArray(catalog.variables, `${context} variables`, errors).forEach(
780
- (variable, position) => {
781
- const variableContext = `${context} variable ${position}`;
782
- if (typeof variable.name !== "string") invalidField(variableContext, "name", errors);
783
- if (typeof variable.required !== "boolean") {
784
- invalidField(variableContext, "required", errors);
785
- }
786
- if (!isNullableString(variable.description)) {
787
- invalidField(variableContext, "description", errors);
788
- }
789
- if (!isNullableString(variable.preview)) invalidField(variableContext, "preview", errors);
790
- }
791
- );
792
- return catalog;
793
- }
794
- function expectEmailTemplatePreview(value, context, errors = defaultSdkCoreErrorFactory) {
795
- const preview = expectObject(value, context, errors);
796
- if (typeof preview.subject !== "string") invalidField(context, "subject", errors);
797
- if (typeof preview.htmlBody !== "string") invalidField(context, "htmlBody", errors);
798
- if (!isNullableString(preview.textBody)) invalidField(context, "textBody", errors);
799
- return preview;
800
- }
801
- function expectEmailSender(value, context, errors = defaultSdkCoreErrorFactory) {
802
- const sender = expectObject(value, context, errors);
803
- if (typeof sender.id !== "string") invalidField(context, "id", errors);
804
- if (typeof sender.email !== "string") invalidField(context, "email", errors);
805
- if (typeof sender.displayName !== "string") invalidField(context, "displayName", errors);
806
- if (!isNonEmptyString(sender.status)) invalidField(context, "status", errors);
807
- if (typeof sender.sharedWithCurrentWorkspace !== "boolean") {
808
- invalidField(context, "sharedWithCurrentWorkspace", errors);
809
- }
810
- if (typeof sender.ownerConfirmationPending !== "boolean") {
811
- invalidField(context, "ownerConfirmationPending", errors);
812
- }
813
- if (typeof sender.createdAt !== "string") invalidField(context, "createdAt", errors);
814
- if (typeof sender.updatedAt !== "string") invalidField(context, "updatedAt", errors);
815
- return sender;
816
- }
817
- function expectEmailSettings(value, context, errors = defaultSdkCoreErrorFactory) {
818
- const settings = expectObject(value, context, errors);
819
- if (typeof settings.appId !== "string") invalidField(context, "appId", errors);
820
- if (!isNullableString(settings.senderIdentityId)) {
821
- invalidField(context, "senderIdentityId", errors);
822
- }
823
- if (!isNullableString(settings.displayName)) invalidField(context, "displayName", errors);
824
- if (!isNullableString(settings.replyTo)) invalidField(context, "replyTo", errors);
825
- if (typeof settings.ownTemplateSendsFromBrand !== "boolean") {
826
- invalidField(context, "ownTemplateSendsFromBrand", errors);
827
- }
828
- const senderContext = `${context} effectiveSender`;
829
- const sender = expectObject(settings.effectiveSender, senderContext, errors);
830
- if (typeof sender.email !== "string") invalidField(senderContext, "email", errors);
831
- if (!isNullableString(sender.displayName)) invalidField(senderContext, "displayName", errors);
832
- if (!isNonEmptyString(sender.source)) invalidField(senderContext, "source", errors);
833
- if (!isNullableString(sender.reason)) invalidField(senderContext, "reason", errors);
834
- return settings;
835
- }
836
754
  function expectAgentDefinition(value, context, errors = defaultSdkCoreErrorFactory) {
837
755
  const agent = expectObject(value, context, errors);
838
756
  if (typeof agent.id !== "string") invalidField(context, "id", errors);
@@ -1181,6 +1099,78 @@ function expectAgentModel(value, context, errors = defaultSdkCoreErrorFactory) {
1181
1099
  }
1182
1100
  return model;
1183
1101
  }
1102
+ function expectAiProviders(value, context, errors = defaultSdkCoreErrorFactory) {
1103
+ const providers = expectObject(value, context, errors);
1104
+ if (typeof providers.activeEngine !== "string") {
1105
+ invalidField(context, "activeEngine", errors);
1106
+ }
1107
+ if (typeof providers.includedAiAvailable !== "boolean") {
1108
+ invalidField(context, "includedAiAvailable", errors);
1109
+ }
1110
+ if (!isNullableString(providers.activeCustomProviderId)) {
1111
+ invalidField(context, "activeCustomProviderId", errors);
1112
+ }
1113
+ expectObjectArray(
1114
+ providers.customProviders,
1115
+ `${context} customProviders`,
1116
+ errors,
1117
+ expectAgentConnectionCustomProvider
1118
+ );
1119
+ if (providers.includedAiQuota !== null) {
1120
+ expectIncludedAiQuota(providers.includedAiQuota, `${context} includedAiQuota`, errors);
1121
+ }
1122
+ const opencode = expectObject(providers.opencode, `${context} opencode`, errors);
1123
+ if (typeof opencode.connected !== "boolean") invalidField(context, "opencode.connected", errors);
1124
+ for (const field of ["presetId", "presetName", "providerId", "baseUrl"]) {
1125
+ if (!isNullableString(opencode[field])) invalidField(context, `opencode.${field}`, errors);
1126
+ }
1127
+ if (!isNullableString(opencode.authMethod)) {
1128
+ invalidField(context, "opencode.authMethod", errors);
1129
+ }
1130
+ if (opencode.models !== null && !isStringArray(opencode.models)) {
1131
+ invalidField(context, "opencode.models", errors);
1132
+ }
1133
+ if (hasOwn(providers, "managedAiProfile") && providers.managedAiProfile !== null) {
1134
+ const profile = expectObject(
1135
+ providers.managedAiProfile,
1136
+ `${context} managedAiProfile`,
1137
+ errors
1138
+ );
1139
+ for (const field of [
1140
+ "profile",
1141
+ "agentType",
1142
+ "selectionMode",
1143
+ "model",
1144
+ "requiredScope"
1145
+ ]) {
1146
+ if (typeof profile[field] !== "string") {
1147
+ invalidField(context, `managedAiProfile.${field}`, errors);
1148
+ }
1149
+ }
1150
+ }
1151
+ return providers;
1152
+ }
1153
+ function expectIncludedAiQuota(value, context, errors) {
1154
+ const quota = expectObject(value, context, errors);
1155
+ if (typeof quota.planCode !== "string") invalidField(context, "planCode", errors);
1156
+ if (hasOwn(quota, "blockingWindow") && typeof quota.blockingWindow !== "string") {
1157
+ invalidField(context, "blockingWindow", errors);
1158
+ }
1159
+ if (hasOwn(quota, "remainingTokens") && !isInteger(quota.remainingTokens)) {
1160
+ invalidField(context, "remainingTokens", errors);
1161
+ }
1162
+ const windows = expectObject(quota.windows, `${context} windows`, errors);
1163
+ for (const kind of ["day", "month"]) {
1164
+ if (!hasOwn(windows, kind)) continue;
1165
+ const window = expectObject(windows[kind], `${context} windows.${kind}`, errors);
1166
+ for (const field of ["limit", "left", "leftCenticredits"]) {
1167
+ if (!isInteger(window[field])) invalidField(context, `windows.${kind}.${field}`, errors);
1168
+ }
1169
+ if (typeof window.resetsAt !== "string") {
1170
+ invalidField(context, `windows.${kind}.resetsAt`, errors);
1171
+ }
1172
+ }
1173
+ }
1184
1174
  function expectCredentialStatus(value, context, errors = defaultSdkCoreErrorFactory) {
1185
1175
  const status = expectObject(value, context, errors);
1186
1176
  if (typeof status.provider !== "string") invalidField(context, "provider", errors);
@@ -1815,6 +1805,19 @@ function createAgentTasksModule(transport, errors = defaultSdkCoreErrorFactory)
1815
1805
  };
1816
1806
  }
1817
1807
 
1808
+ // src/modules/aiProviders.ts
1809
+ function createAiProvidersModule(transport, errors = defaultSdkCoreErrorFactory) {
1810
+ return {
1811
+ async get() {
1812
+ return expectAiProviders(
1813
+ await transport.request("/api/v1/ai-providers", { method: "GET" }),
1814
+ "AI providers response",
1815
+ errors
1816
+ );
1817
+ }
1818
+ };
1819
+ }
1820
+
1818
1821
  // src/modules/apps.ts
1819
1822
  function createAppsModule(transport, errors = defaultSdkCoreErrorFactory) {
1820
1823
  const appPath = (appId) => `/api/v1/apps/${encodePathSegment(appId, "app id", errors)}`;
@@ -3031,23 +3034,7 @@ function createMembersModule(transport, errors = defaultSdkCoreErrorFactory) {
3031
3034
  }
3032
3035
 
3033
3036
  // src/modules/messenger.ts
3034
- function createMessengerModule(transport, errors = defaultSdkCoreErrorFactory, getAppId) {
3035
- const templatePath = (type) => `/api/v1/email/templates/${encodePathSegment(type, "email template type", errors)}`;
3036
- const senderPath = (senderId) => `/api/v1/email/identities/${encodePathSegment(senderId, "email sender id", errors)}`;
3037
- const currentAppId = () => {
3038
- const appId = getAppId?.();
3039
- if (!appId) configurationError("An appId is required for app email calls", errors);
3040
- return appId;
3041
- };
3042
- const settingsPath = () => `/api/v1/email/apps/${encodePathSegment(currentAppId(), "app id", errors)}/settings`;
3043
- const preview = async (type, appId) => expectEmailTemplatePreview(
3044
- await transport.request(`${templatePath(type)}/preview`, {
3045
- method: "GET",
3046
- params: { appId }
3047
- }),
3048
- "Email template preview response",
3049
- errors
3050
- );
3037
+ function createMessengerModule(transport, errors = defaultSdkCoreErrorFactory) {
3051
3038
  return {
3052
3039
  async notify(content) {
3053
3040
  return expectMessageAccepted(
@@ -3068,120 +3055,6 @@ function createMessengerModule(transport, errors = defaultSdkCoreErrorFactory, g
3068
3055
  "Send email response",
3069
3056
  errors
3070
3057
  );
3071
- },
3072
- async listEmailTemplates() {
3073
- return expectObjectArray(
3074
- await transport.request("/api/v1/email/templates", {
3075
- method: "GET",
3076
- params: { appId: currentAppId() }
3077
- }),
3078
- "Email template list response",
3079
- errors,
3080
- expectEmailTemplate
3081
- );
3082
- },
3083
- async getEmailTemplateType(type) {
3084
- return expectEmailTemplateTypeCatalog(
3085
- await transport.request(
3086
- `/api/v1/email/template-types/${encodePathSegment(type, "email template type", errors)}`,
3087
- { method: "GET" }
3088
- ),
3089
- "Email template type response",
3090
- errors
3091
- );
3092
- },
3093
- async getEmailTemplate(type) {
3094
- return expectEmailTemplate(
3095
- await transport.request(templatePath(type), {
3096
- method: "GET",
3097
- params: { appId: currentAppId() }
3098
- }),
3099
- "Email template response",
3100
- errors
3101
- );
3102
- },
3103
- async upsertEmailTemplate(type, input) {
3104
- const appId = currentAppId();
3105
- const template = expectEmailTemplate(
3106
- await transport.request(templatePath(type), {
3107
- method: "PUT",
3108
- body: templateBody(appId, input)
3109
- }),
3110
- "Upsert email template response",
3111
- errors
3112
- );
3113
- try {
3114
- return { template, preview: await preview(type, appId) };
3115
- } catch (previewError) {
3116
- return { template, preview: null, previewError };
3117
- }
3118
- },
3119
- async previewEmailTemplate(type) {
3120
- return preview(type, currentAppId());
3121
- },
3122
- async deleteEmailTemplate(type) {
3123
- expectEmpty(
3124
- await transport.request(templatePath(type), {
3125
- method: "DELETE",
3126
- params: { appId: currentAppId() }
3127
- }),
3128
- "Delete email template response",
3129
- errors
3130
- );
3131
- },
3132
- async listEmailSenders() {
3133
- return expectObjectArray(
3134
- await transport.request("/api/v1/email/identities/workspace", { method: "GET" }),
3135
- "Email sender list response",
3136
- errors,
3137
- expectEmailSender
3138
- );
3139
- },
3140
- async registerEmailSender(input) {
3141
- return expectEmailSender(
3142
- await transport.request("/api/v1/email/identities", {
3143
- method: "POST",
3144
- body: { email: input.email, displayName: input.displayName }
3145
- }),
3146
- "Register email sender response",
3147
- errors
3148
- );
3149
- },
3150
- async resendEmailSenderVerification(senderId) {
3151
- return expectEmailSender(
3152
- await transport.request(`${senderPath(senderId)}/resend-verification`, {
3153
- method: "POST"
3154
- }),
3155
- "Resend email sender verification response",
3156
- errors
3157
- );
3158
- },
3159
- async confirmEmailSender(senderId, code) {
3160
- return expectEmailSender(
3161
- await transport.request(`${senderPath(senderId)}/confirm`, {
3162
- method: "POST",
3163
- body: { code }
3164
- }),
3165
- "Confirm email sender response",
3166
- errors
3167
- );
3168
- },
3169
- async getEmailSettings() {
3170
- return expectEmailSettings(
3171
- await transport.request(settingsPath(), { method: "GET" }),
3172
- "Email settings response",
3173
- errors
3174
- );
3175
- },
3176
- async updateEmailSettings(input) {
3177
- return expectEmailSettings(
3178
- await transport.request(settingsPath(), {
3179
- method: "PUT",
3180
- body: settingsBody(input)
3181
- }),
3182
- "Update email settings response",
3183
- errors
3184
- );
3185
3058
  }
3186
3059
  };
3187
3060
  }
@@ -3197,21 +3070,6 @@ function rawEmailPayload(input) {
3197
3070
  ...input.text === void 0 ? {} : { text: input.text }
3198
3071
  };
3199
3072
  }
3200
- function templateBody(appId, input) {
3201
- return {
3202
- appId,
3203
- subject: input.subject,
3204
- htmlBody: input.htmlBody,
3205
- ...input.textBody === void 0 ? {} : { textBody: input.textBody }
3206
- };
3207
- }
3208
- function settingsBody(input) {
3209
- return {
3210
- ...input.senderIdentityId === void 0 ? {} : { senderIdentityId: input.senderIdentityId },
3211
- ...input.displayName === void 0 ? {} : { displayName: input.displayName },
3212
- ...input.replyTo === void 0 ? {} : { replyTo: input.replyTo }
3213
- };
3214
- }
3215
3073
 
3216
3074
  // src/modules/publicFunctions.ts
3217
3075
  function createPublicFunctionsModule(transport, errors = defaultSdkCoreErrorFactory) {
@@ -3504,6 +3362,7 @@ function createSdkCore(options) {
3504
3362
  agentCredentials: createAgentCredentialsModule(copilot, errors),
3505
3363
  agents,
3506
3364
  agentTasks: createAgentTasksModule(copilot, errors),
3365
+ aiProviders: createAiProvidersModule(copilot, errors),
3507
3366
  apps,
3508
3367
  auth: createAuthModule(options.transports.auth, errors),
3509
3368
  context: createContextModule(
@@ -3529,7 +3388,7 @@ function createSdkCore(options) {
3529
3388
  integrationResources: createIntegrationResourcesModule(options.transports.integration, errors),
3530
3389
  integrationTemplates: createIntegrationTemplatesModule(options.transports.integration, errors),
3531
3390
  members,
3532
- messenger: createMessengerModule(messengerTransport, errors, options.getAppId),
3391
+ messenger: createMessengerModule(messengerTransport, errors),
3533
3392
  publicFunctions: createPublicFunctionsModule(options.transports.publicFunctions, errors),
3534
3393
  queries: createQueriesModule(options.transports.dataManager, errors),
3535
3394
  sql: createSqlModule(options.transports.dataManager, errors),
@@ -6133,6 +5992,7 @@ async function resolveApiKeyToken(call, appId, apiKey, errors = defaultSdkCoreEr
6133
5992
  createAgentTaskSessionManager,
6134
5993
  createAgentTasksModule,
6135
5994
  createAgentsModule,
5995
+ createAiProvidersModule,
6136
5996
  createAppsModule,
6137
5997
  createAuthModule,
6138
5998
  createContextModule,