@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.js CHANGED
@@ -48,9 +48,6 @@ 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
- }
54
51
  function isNullableBoolean(value) {
55
52
  return value === null || typeof value === "boolean";
56
53
  }
@@ -439,9 +436,6 @@ function expectAppFields(app, context, errors) {
439
436
  if (!isNullableString(app.icon)) invalidField(context, "icon", errors);
440
437
  if (!isNullableString(app.template)) invalidField(context, "template", errors);
441
438
  if (typeof app.allowSignup !== "boolean") invalidField(context, "allowSignup", errors);
442
- for (const field of ["emailLoginEnabled", "passwordLoginEnabled"]) {
443
- if (field in app && typeof app[field] !== "boolean") invalidField(context, field, errors);
444
- }
445
439
  if (typeof app.externalAccessEnabled !== "boolean") {
446
440
  invalidField(context, "externalAccessEnabled", errors);
447
441
  }
@@ -684,83 +678,6 @@ function expectMessageAccepted(value, context, errors = defaultSdkCoreErrorFacto
684
678
  if (typeof response.messageId !== "string") invalidField(context, "messageId", errors);
685
679
  return response;
686
680
  }
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
- }
764
681
  function expectAgentDefinition(value, context, errors = defaultSdkCoreErrorFactory) {
765
682
  const agent = expectObject(value, context, errors);
766
683
  if (typeof agent.id !== "string") invalidField(context, "id", errors);
@@ -1109,6 +1026,78 @@ function expectAgentModel(value, context, errors = defaultSdkCoreErrorFactory) {
1109
1026
  }
1110
1027
  return model;
1111
1028
  }
1029
+ function expectAiProviders(value, context, errors = defaultSdkCoreErrorFactory) {
1030
+ const providers = expectObject(value, context, errors);
1031
+ if (typeof providers.activeEngine !== "string") {
1032
+ invalidField(context, "activeEngine", errors);
1033
+ }
1034
+ if (typeof providers.includedAiAvailable !== "boolean") {
1035
+ invalidField(context, "includedAiAvailable", errors);
1036
+ }
1037
+ if (!isNullableString(providers.activeCustomProviderId)) {
1038
+ invalidField(context, "activeCustomProviderId", errors);
1039
+ }
1040
+ expectObjectArray(
1041
+ providers.customProviders,
1042
+ `${context} customProviders`,
1043
+ errors,
1044
+ expectAgentConnectionCustomProvider
1045
+ );
1046
+ if (providers.includedAiQuota !== null) {
1047
+ expectIncludedAiQuota(providers.includedAiQuota, `${context} includedAiQuota`, errors);
1048
+ }
1049
+ const opencode = expectObject(providers.opencode, `${context} opencode`, errors);
1050
+ if (typeof opencode.connected !== "boolean") invalidField(context, "opencode.connected", errors);
1051
+ for (const field of ["presetId", "presetName", "providerId", "baseUrl"]) {
1052
+ if (!isNullableString(opencode[field])) invalidField(context, `opencode.${field}`, errors);
1053
+ }
1054
+ if (!isNullableString(opencode.authMethod)) {
1055
+ invalidField(context, "opencode.authMethod", errors);
1056
+ }
1057
+ if (opencode.models !== null && !isStringArray(opencode.models)) {
1058
+ invalidField(context, "opencode.models", errors);
1059
+ }
1060
+ if (hasOwn(providers, "managedAiProfile") && providers.managedAiProfile !== null) {
1061
+ const profile = expectObject(
1062
+ providers.managedAiProfile,
1063
+ `${context} managedAiProfile`,
1064
+ errors
1065
+ );
1066
+ for (const field of [
1067
+ "profile",
1068
+ "agentType",
1069
+ "selectionMode",
1070
+ "model",
1071
+ "requiredScope"
1072
+ ]) {
1073
+ if (typeof profile[field] !== "string") {
1074
+ invalidField(context, `managedAiProfile.${field}`, errors);
1075
+ }
1076
+ }
1077
+ }
1078
+ return providers;
1079
+ }
1080
+ function expectIncludedAiQuota(value, context, errors) {
1081
+ const quota = expectObject(value, context, errors);
1082
+ if (typeof quota.planCode !== "string") invalidField(context, "planCode", errors);
1083
+ if (hasOwn(quota, "blockingWindow") && typeof quota.blockingWindow !== "string") {
1084
+ invalidField(context, "blockingWindow", errors);
1085
+ }
1086
+ if (hasOwn(quota, "remainingTokens") && !isInteger(quota.remainingTokens)) {
1087
+ invalidField(context, "remainingTokens", errors);
1088
+ }
1089
+ const windows = expectObject(quota.windows, `${context} windows`, errors);
1090
+ for (const kind of ["day", "month"]) {
1091
+ if (!hasOwn(windows, kind)) continue;
1092
+ const window = expectObject(windows[kind], `${context} windows.${kind}`, errors);
1093
+ for (const field of ["limit", "left", "leftCenticredits"]) {
1094
+ if (!isInteger(window[field])) invalidField(context, `windows.${kind}.${field}`, errors);
1095
+ }
1096
+ if (typeof window.resetsAt !== "string") {
1097
+ invalidField(context, `windows.${kind}.resetsAt`, errors);
1098
+ }
1099
+ }
1100
+ }
1112
1101
  function expectCredentialStatus(value, context, errors = defaultSdkCoreErrorFactory) {
1113
1102
  const status = expectObject(value, context, errors);
1114
1103
  if (typeof status.provider !== "string") invalidField(context, "provider", errors);
@@ -1743,6 +1732,19 @@ function createAgentTasksModule(transport, errors = defaultSdkCoreErrorFactory)
1743
1732
  };
1744
1733
  }
1745
1734
 
1735
+ // src/modules/aiProviders.ts
1736
+ function createAiProvidersModule(transport, errors = defaultSdkCoreErrorFactory) {
1737
+ return {
1738
+ async get() {
1739
+ return expectAiProviders(
1740
+ await transport.request("/api/v1/ai-providers", { method: "GET" }),
1741
+ "AI providers response",
1742
+ errors
1743
+ );
1744
+ }
1745
+ };
1746
+ }
1747
+
1746
1748
  // src/modules/apps.ts
1747
1749
  function createAppsModule(transport, errors = defaultSdkCoreErrorFactory) {
1748
1750
  const appPath = (appId) => `/api/v1/apps/${encodePathSegment(appId, "app id", errors)}`;
@@ -2959,23 +2961,7 @@ function createMembersModule(transport, errors = defaultSdkCoreErrorFactory) {
2959
2961
  }
2960
2962
 
2961
2963
  // src/modules/messenger.ts
2962
- function createMessengerModule(transport, errors = defaultSdkCoreErrorFactory, getAppId) {
2963
- const templatePath = (type) => `/api/v1/email/templates/${encodePathSegment(type, "email template type", errors)}`;
2964
- const senderPath = (senderId) => `/api/v1/email/identities/${encodePathSegment(senderId, "email sender id", errors)}`;
2965
- const currentAppId = () => {
2966
- const appId = getAppId?.();
2967
- if (!appId) configurationError("An appId is required for app email calls", errors);
2968
- return appId;
2969
- };
2970
- const settingsPath = () => `/api/v1/email/apps/${encodePathSegment(currentAppId(), "app id", errors)}/settings`;
2971
- const preview = async (type, appId) => expectEmailTemplatePreview(
2972
- await transport.request(`${templatePath(type)}/preview`, {
2973
- method: "GET",
2974
- params: { appId }
2975
- }),
2976
- "Email template preview response",
2977
- errors
2978
- );
2964
+ function createMessengerModule(transport, errors = defaultSdkCoreErrorFactory) {
2979
2965
  return {
2980
2966
  async notify(content) {
2981
2967
  return expectMessageAccepted(
@@ -2996,120 +2982,6 @@ function createMessengerModule(transport, errors = defaultSdkCoreErrorFactory, g
2996
2982
  "Send email response",
2997
2983
  errors
2998
2984
  );
2999
- },
3000
- async listEmailTemplates() {
3001
- return expectObjectArray(
3002
- await transport.request("/api/v1/email/templates", {
3003
- method: "GET",
3004
- params: { appId: currentAppId() }
3005
- }),
3006
- "Email template list response",
3007
- errors,
3008
- expectEmailTemplate
3009
- );
3010
- },
3011
- async getEmailTemplateType(type) {
3012
- return expectEmailTemplateTypeCatalog(
3013
- await transport.request(
3014
- `/api/v1/email/template-types/${encodePathSegment(type, "email template type", errors)}`,
3015
- { method: "GET" }
3016
- ),
3017
- "Email template type response",
3018
- errors
3019
- );
3020
- },
3021
- async getEmailTemplate(type) {
3022
- return expectEmailTemplate(
3023
- await transport.request(templatePath(type), {
3024
- method: "GET",
3025
- params: { appId: currentAppId() }
3026
- }),
3027
- "Email template response",
3028
- errors
3029
- );
3030
- },
3031
- async upsertEmailTemplate(type, input) {
3032
- const appId = currentAppId();
3033
- const template = expectEmailTemplate(
3034
- await transport.request(templatePath(type), {
3035
- method: "PUT",
3036
- body: templateBody(appId, input)
3037
- }),
3038
- "Upsert email template response",
3039
- errors
3040
- );
3041
- try {
3042
- return { template, preview: await preview(type, appId) };
3043
- } catch (previewError) {
3044
- return { template, preview: null, previewError };
3045
- }
3046
- },
3047
- async previewEmailTemplate(type) {
3048
- return preview(type, currentAppId());
3049
- },
3050
- async deleteEmailTemplate(type) {
3051
- expectEmpty(
3052
- await transport.request(templatePath(type), {
3053
- method: "DELETE",
3054
- params: { appId: currentAppId() }
3055
- }),
3056
- "Delete email template response",
3057
- errors
3058
- );
3059
- },
3060
- async listEmailSenders() {
3061
- return expectObjectArray(
3062
- await transport.request("/api/v1/email/identities/workspace", { method: "GET" }),
3063
- "Email sender list response",
3064
- errors,
3065
- expectEmailSender
3066
- );
3067
- },
3068
- async registerEmailSender(input) {
3069
- return expectEmailSender(
3070
- await transport.request("/api/v1/email/identities", {
3071
- method: "POST",
3072
- body: { email: input.email, displayName: input.displayName }
3073
- }),
3074
- "Register email sender response",
3075
- errors
3076
- );
3077
- },
3078
- async resendEmailSenderVerification(senderId) {
3079
- return expectEmailSender(
3080
- await transport.request(`${senderPath(senderId)}/resend-verification`, {
3081
- method: "POST"
3082
- }),
3083
- "Resend email sender verification response",
3084
- errors
3085
- );
3086
- },
3087
- async confirmEmailSender(senderId, code) {
3088
- return expectEmailSender(
3089
- await transport.request(`${senderPath(senderId)}/confirm`, {
3090
- method: "POST",
3091
- body: { code }
3092
- }),
3093
- "Confirm email sender response",
3094
- errors
3095
- );
3096
- },
3097
- async getEmailSettings() {
3098
- return expectEmailSettings(
3099
- await transport.request(settingsPath(), { method: "GET" }),
3100
- "Email settings response",
3101
- errors
3102
- );
3103
- },
3104
- async updateEmailSettings(input) {
3105
- return expectEmailSettings(
3106
- await transport.request(settingsPath(), {
3107
- method: "PUT",
3108
- body: settingsBody(input)
3109
- }),
3110
- "Update email settings response",
3111
- errors
3112
- );
3113
2985
  }
3114
2986
  };
3115
2987
  }
@@ -3125,21 +2997,6 @@ function rawEmailPayload(input) {
3125
2997
  ...input.text === void 0 ? {} : { text: input.text }
3126
2998
  };
3127
2999
  }
3128
- function templateBody(appId, input) {
3129
- return {
3130
- appId,
3131
- subject: input.subject,
3132
- htmlBody: input.htmlBody,
3133
- ...input.textBody === void 0 ? {} : { textBody: input.textBody }
3134
- };
3135
- }
3136
- function settingsBody(input) {
3137
- return {
3138
- ...input.senderIdentityId === void 0 ? {} : { senderIdentityId: input.senderIdentityId },
3139
- ...input.displayName === void 0 ? {} : { displayName: input.displayName },
3140
- ...input.replyTo === void 0 ? {} : { replyTo: input.replyTo }
3141
- };
3142
- }
3143
3000
 
3144
3001
  // src/modules/publicFunctions.ts
3145
3002
  function createPublicFunctionsModule(transport, errors = defaultSdkCoreErrorFactory) {
@@ -3432,6 +3289,7 @@ function createSdkCore(options) {
3432
3289
  agentCredentials: createAgentCredentialsModule(copilot, errors),
3433
3290
  agents,
3434
3291
  agentTasks: createAgentTasksModule(copilot, errors),
3292
+ aiProviders: createAiProvidersModule(copilot, errors),
3435
3293
  apps,
3436
3294
  auth: createAuthModule(options.transports.auth, errors),
3437
3295
  context: createContextModule(
@@ -3457,7 +3315,7 @@ function createSdkCore(options) {
3457
3315
  integrationResources: createIntegrationResourcesModule(options.transports.integration, errors),
3458
3316
  integrationTemplates: createIntegrationTemplatesModule(options.transports.integration, errors),
3459
3317
  members,
3460
- messenger: createMessengerModule(messengerTransport, errors, options.getAppId),
3318
+ messenger: createMessengerModule(messengerTransport, errors),
3461
3319
  publicFunctions: createPublicFunctionsModule(options.transports.publicFunctions, errors),
3462
3320
  queries: createQueriesModule(options.transports.dataManager, errors),
3463
3321
  sql: createSqlModule(options.transports.dataManager, errors),
@@ -6060,6 +5918,7 @@ export {
6060
5918
  createAgentTaskSessionManager,
6061
5919
  createAgentTasksModule,
6062
5920
  createAgentsModule,
5921
+ createAiProvidersModule,
6063
5922
  createAppsModule,
6064
5923
  createAuthModule,
6065
5924
  createContextModule,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mitralab.io/sdk-core",
3
- "version": "0.3.7",
3
+ "version": "0.3.8",
4
4
  "description": "Environment-neutral contracts and modules shared by Mitra JavaScript SDKs",
5
5
  "type": "module",
6
6
  "sideEffects": false,