@mitralab.io/sdk-core 0.2.4 → 0.2.6-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/dist/index.js CHANGED
@@ -923,6 +923,8 @@ function expectAgentTask(value, context, errors = defaultSdkCoreErrorFactory) {
923
923
  for (const field of ["appId", "agentId", "userId", "title", "reasoningEffort"]) {
924
924
  if (!isNullableString(task[field])) invalidField(context, field, errors);
925
925
  }
926
+ if ("scope" in task && !isNullableString(task.scope)) invalidField(context, "scope", errors);
927
+ if ("model" in task && !isNullableString(task.model)) invalidField(context, "model", errors);
926
928
  if (typeof task.agentType !== "string") invalidField(context, "agentType", errors);
927
929
  if (typeof task.archived !== "boolean") invalidField(context, "archived", errors);
928
930
  if (!isNullableString(task.createdAt)) invalidField(context, "createdAt", errors);
@@ -942,6 +944,9 @@ function expectAgentModel(value, context, errors = defaultSdkCoreErrorFactory) {
942
944
  if (typeof model[field] !== "string") invalidField(context, field, errors);
943
945
  }
944
946
  if (!isStringArray(model.reasoningOptions)) invalidField(context, "reasoningOptions", errors);
947
+ if ("providerName" in model && !isNullableString(model.providerName)) {
948
+ invalidField(context, "providerName", errors);
949
+ }
945
950
  return model;
946
951
  }
947
952
  function expectCredentialStatus(value, context, errors = defaultSdkCoreErrorFactory) {
@@ -981,6 +986,14 @@ function expectProviderCredentialStatus(value, context, errors) {
981
986
  if (!isNullableString(status.accountEmail)) invalidField(context, "accountEmail", errors);
982
987
  return status;
983
988
  }
989
+ function expectAgentConnectionCustomProvider(value, context, errors) {
990
+ const provider = expectObject(value, context, errors);
991
+ for (const field of ["id", "name", "baseUrl", "maskedApiKey"]) {
992
+ if (typeof provider[field] !== "string") invalidField(context, field, errors);
993
+ }
994
+ if (!isStringArray(provider.models)) invalidField(context, "models", errors);
995
+ return provider;
996
+ }
984
997
  function expectAgentConnection(value, context, errors = defaultSdkCoreErrorFactory) {
985
998
  const connection = expectObject(value, context, errors);
986
999
  if (typeof connection.id !== "string") invalidField(context, "id", errors);
@@ -993,6 +1006,14 @@ function expectAgentConnection(value, context, errors = defaultSdkCoreErrorFacto
993
1006
  errors,
994
1007
  expectProviderCredentialStatus
995
1008
  );
1009
+ if ("customProviders" in connection) {
1010
+ expectObjectArray(
1011
+ connection.customProviders,
1012
+ `${context} customProviders`,
1013
+ errors,
1014
+ expectAgentConnectionCustomProvider
1015
+ );
1016
+ }
996
1017
  return connection;
997
1018
  }
998
1019
  function expectTableDefinition(value, context, errors = defaultSdkCoreErrorFactory) {
@@ -1047,6 +1068,7 @@ function expectEmpty(value, context, errors = defaultSdkCoreErrorFactory) {
1047
1068
 
1048
1069
  // src/modules/agentConnections.ts
1049
1070
  var MAX_CONNECTIONS = 100;
1071
+ var MAX_CUSTOM_PROVIDER_MODELS = 32;
1050
1072
  function createAgentConnectionsModule(transport, errors = defaultSdkCoreErrorFactory) {
1051
1073
  const path = (id) => `/api/v1/connections/${encodePathSegment(id, "connection id", errors)}`;
1052
1074
  const providerPath = (id, provider) => `${path(id)}/providers/${encodePathSegment(provider, "provider", errors)}`;
@@ -1153,6 +1175,27 @@ function createAgentConnectionsModule(transport, errors = defaultSdkCoreErrorFac
1153
1175
  "Connection device authorization poll response",
1154
1176
  errors
1155
1177
  );
1178
+ },
1179
+ async createCustomProvider(id, input) {
1180
+ requireBatchSize(input.models, "models", MAX_CUSTOM_PROVIDER_MODELS, errors);
1181
+ return expectAgentConnection(
1182
+ await transport.request(`${path(id)}/custom-providers`, {
1183
+ method: "POST",
1184
+ body: input
1185
+ }),
1186
+ "Create connection custom provider response",
1187
+ errors
1188
+ );
1189
+ },
1190
+ async deleteCustomProvider(id, providerId) {
1191
+ expectEmpty(
1192
+ await transport.request(
1193
+ `${path(id)}/custom-providers/${encodePathSegment(providerId, "custom provider id", errors)}`,
1194
+ { method: "DELETE" }
1195
+ ),
1196
+ "Delete connection custom provider response",
1197
+ errors
1198
+ );
1156
1199
  }
1157
1200
  };
1158
1201
  }
@@ -1160,76 +1203,83 @@ function createAgentConnectionsModule(transport, errors = defaultSdkCoreErrorFac
1160
1203
  // src/modules/agentCredentials.ts
1161
1204
  function createAgentCredentialsModule(transport, errors = defaultSdkCoreErrorFactory) {
1162
1205
  const providerSegment = (provider) => encodePathSegment(provider, "provider", errors);
1206
+ const scopeParams = (options) => options?.scope ? { params: { scope: options.scope } } : {};
1163
1207
  return {
1164
- async list() {
1208
+ async list(options) {
1165
1209
  return expectObjectArray(
1166
- await transport.request("/api/v1/credentials", { method: "GET" }),
1210
+ await transport.request("/api/v1/credentials", {
1211
+ method: "GET",
1212
+ ...scopeParams(options)
1213
+ }),
1167
1214
  "Credential status response",
1168
1215
  errors,
1169
1216
  expectCredentialStatus
1170
1217
  );
1171
1218
  },
1172
- async listModels(agentId) {
1219
+ async listModels(agentId, options) {
1173
1220
  return expectObjectArray(
1174
1221
  await transport.request("/api/v1/models", {
1175
1222
  method: "GET",
1176
- params: { agentId }
1223
+ params: { agentId, ...scopeParams(options).params }
1177
1224
  }),
1178
1225
  "Agent model response",
1179
1226
  errors,
1180
1227
  expectAgentModel
1181
1228
  );
1182
1229
  },
1183
- async saveApiKey(provider, apiKey) {
1230
+ async saveApiKey(provider, apiKey, options) {
1184
1231
  expectEmpty(
1185
1232
  await transport.request(
1186
1233
  `/api/v1/credentials/${providerSegment(provider)}/api-key`,
1187
- { method: "PUT", body: { apiKey } }
1234
+ { method: "PUT", body: { apiKey }, ...scopeParams(options) }
1188
1235
  ),
1189
1236
  "Save API key response",
1190
1237
  errors
1191
1238
  );
1192
1239
  },
1193
- async remove(provider) {
1240
+ async remove(provider, options) {
1194
1241
  expectEmpty(
1195
1242
  await transport.request(`/api/v1/credentials/${providerSegment(provider)}`, {
1196
- method: "DELETE"
1243
+ method: "DELETE",
1244
+ ...scopeParams(options)
1197
1245
  }),
1198
1246
  "Remove credential response",
1199
1247
  errors
1200
1248
  );
1201
1249
  },
1202
- async startOAuth(provider) {
1250
+ async startOAuth(provider, options) {
1203
1251
  return expectOAuthStartResult(
1204
1252
  await transport.request("/api/v1/oauth/start", {
1205
1253
  method: "POST",
1206
- body: { provider }
1254
+ body: { provider },
1255
+ ...scopeParams(options)
1207
1256
  }),
1208
1257
  "OAuth start response",
1209
1258
  errors
1210
1259
  );
1211
1260
  },
1212
- async exchangeOAuth(provider, input) {
1261
+ async exchangeOAuth(provider, input, options) {
1213
1262
  return expectAuthenticationResult(
1214
1263
  await transport.request("/api/v1/oauth/exchange", {
1215
1264
  method: "POST",
1216
- body: { provider, ...input }
1265
+ body: { provider, ...input },
1266
+ ...scopeParams(options)
1217
1267
  }),
1218
1268
  "OAuth exchange response",
1219
1269
  errors
1220
1270
  );
1221
1271
  },
1222
- async startDeviceAuthorization(provider) {
1272
+ async startDeviceAuthorization(provider, options) {
1223
1273
  return expectDeviceAuthorization(
1224
1274
  await transport.request(
1225
1275
  `/api/v1/credentials/${providerSegment(provider)}/device-authorizations`,
1226
- { method: "POST" }
1276
+ { method: "POST", ...scopeParams(options) }
1227
1277
  ),
1228
1278
  "Device authorization response",
1229
1279
  errors
1230
1280
  );
1231
1281
  },
1232
- async pollDeviceAuthorization(provider, deviceAuthId) {
1282
+ async pollDeviceAuthorization(provider, deviceAuthId, options) {
1233
1283
  return expectAuthenticationResult(
1234
1284
  await transport.request(
1235
1285
  `/api/v1/credentials/${providerSegment(provider)}/device-authorizations/${encodePathSegment(
@@ -1237,7 +1287,7 @@ function createAgentCredentialsModule(transport, errors = defaultSdkCoreErrorFac
1237
1287
  "device authorization id",
1238
1288
  errors
1239
1289
  )}/poll`,
1240
- { method: "POST" }
1290
+ { method: "POST", ...scopeParams(options) }
1241
1291
  ),
1242
1292
  "Device authorization poll response",
1243
1293
  errors
@@ -3120,7 +3170,8 @@ var CoreAgentTaskSession = class {
3120
3170
  text: item.text,
3121
3171
  createdAt: item.createdAt,
3122
3172
  ...item.agentType ? { agentType: item.agentType } : {},
3123
- ...item.reasoningEffort ? { reasoningEffort: item.reasoningEffort } : {}
3173
+ ...item.reasoningEffort ? { reasoningEffort: item.reasoningEffort } : {},
3174
+ ...item.model ? { model: item.model } : {}
3124
3175
  }));
3125
3176
  }
3126
3177
  send(prompt, options = {}) {
@@ -3139,7 +3190,8 @@ var CoreAgentTaskSession = class {
3139
3190
  if (waiter.settled) return waiter.promise;
3140
3191
  const sendOptions = {
3141
3192
  ...options.agentType ? { agentType: options.agentType } : {},
3142
- ...options.reasoningEffort ? { reasoningEffort: options.reasoningEffort } : {}
3193
+ ...options.reasoningEffort ? { reasoningEffort: options.reasoningEffort } : {},
3194
+ ...options.model ? { model: options.model } : {}
3143
3195
  };
3144
3196
  if (this.isBusy()) {
3145
3197
  const queueId = this.enqueue(prompt, sendOptions, waiter);
@@ -3276,7 +3328,8 @@ var CoreAgentTaskSession = class {
3276
3328
  type: "message",
3277
3329
  content: prompt,
3278
3330
  ...options.agentType ? { agentType: options.agentType } : {},
3279
- ...options.reasoningEffort ? { reasoningEffort: options.reasoningEffort } : {}
3331
+ ...options.reasoningEffort ? { reasoningEffort: options.reasoningEffort } : {},
3332
+ ...options.model ? { model: options.model } : {}
3280
3333
  };
3281
3334
  if (this.isClosed()) {
3282
3335
  await this.sendInput(input).catch(() => void 0);
@@ -3306,8 +3359,10 @@ var CoreAgentTaskSession = class {
3306
3359
  ...createOptions.title ? { title: createOptions.title } : {},
3307
3360
  ...createOptions.agentId ? { agentId: createOptions.agentId } : {},
3308
3361
  ...createOptions.reasoningEffort ? { reasoningEffort: createOptions.reasoningEffort } : {},
3362
+ ...createOptions.model ? { model: createOptions.model } : {},
3309
3363
  ...createOptions.userId ? { userId: createOptions.userId } : {},
3310
- ...createOptions.runtime ? { runtime: createOptions.runtime } : {}
3364
+ ...createOptions.runtime ? { runtime: createOptions.runtime } : {},
3365
+ ...createOptions.scope ? { scope: createOptions.scope } : {}
3311
3366
  });
3312
3367
  this._task = task;
3313
3368
  this._taskId = task.id;
@@ -3571,7 +3626,8 @@ var CoreAgentTaskSession = class {
3571
3626
  next.text,
3572
3627
  {
3573
3628
  ...next.agentType ? { agentType: next.agentType } : {},
3574
- ...next.reasoningEffort ? { reasoningEffort: next.reasoningEffort } : {}
3629
+ ...next.reasoningEffort ? { reasoningEffort: next.reasoningEffort } : {},
3630
+ ...next.model ? { model: next.model } : {}
3575
3631
  },
3576
3632
  next.waiter
3577
3633
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mitralab.io/sdk-core",
3
- "version": "0.2.4",
3
+ "version": "0.2.6-beta.0",
4
4
  "description": "Environment-neutral contracts and modules shared by Mitra JavaScript SDKs",
5
5
  "type": "module",
6
6
  "sideEffects": false,