@getmodus/sdk 0.7.0 → 0.8.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.
@@ -10,7 +10,7 @@ import {
10
10
  omitUndefined,
11
11
  validateId,
12
12
  validatePageSize
13
- } from "../chunk-JMFT5KO5.js";
13
+ } from "../chunk-GFS7CNON.js";
14
14
 
15
15
  // src/_query.ts
16
16
  function updateMaskQuery(updateMask) {
@@ -1049,6 +1049,12 @@ function chunked(items, size) {
1049
1049
  for (let i = 0; i < items.length; i += size) out.push(items.slice(i, i + size));
1050
1050
  return out;
1051
1051
  }
1052
+ function joinDestination(prefix, relative2) {
1053
+ const head = prefix === void 0 || prefix.length === 0 ? void 0 : prefix;
1054
+ const tail = relative2 === void 0 || relative2.length === 0 ? void 0 : relative2;
1055
+ if (head !== void 0 && tail !== void 0) return `${head}/${tail}`;
1056
+ return head ?? tail;
1057
+ }
1052
1058
  async function mapWithConcurrency(items, concurrency, worker, onItemDone) {
1053
1059
  const results = new Array(items.length);
1054
1060
  let cursor = 0;
@@ -1082,11 +1088,11 @@ async function walkFiles(root, recursive) {
1082
1088
  await walk(root);
1083
1089
  return out;
1084
1090
  }
1085
- async function putBytes(fetchImpl, url, data, contentType, timeoutMs) {
1086
- const response = await fetchImpl(url, {
1091
+ async function putBytes(fetchImpl, slot, data, timeoutMs) {
1092
+ const response = await fetchImpl(slot.uploadUrl, {
1087
1093
  method: "PUT",
1088
1094
  body: data,
1089
- headers: { "Content-Type": contentType },
1095
+ headers: { "Content-Type": slot.contentType, ...slot.headers },
1090
1096
  signal: AbortSignal.timeout(timeoutMs)
1091
1097
  });
1092
1098
  if (!response.ok) {
@@ -1144,7 +1150,7 @@ var ManagementContextFilesResource = class {
1144
1150
  * Office/OpenDocument documents, audio, and video.
1145
1151
  * @param input.fileSize - File size in bytes. Rejected above 50MB.
1146
1152
  * @returns Presigned upload slot. PUT the raw bytes to `uploadUrl` within 15
1147
- * minutes, then call `finalize(slot.uploadId, slot.fileName)`. Pass the
1153
+ * minutes, sending `headers` unchanged, then call `finalize(slot.uploadId, slot.fileName)`. Pass the
1148
1154
  * slot's own `fileName` rather than your local basename — the server may
1149
1155
  * sanitize the requested name when it mints the key, and finalization
1150
1156
  * re-derives the key from `uploadId` and `fileName`.
@@ -1177,6 +1183,7 @@ var ManagementContextFilesResource = class {
1177
1183
  * @param url - Source URL to fetch (SSRF-guarded, 50MB cap, same MIME
1178
1184
  * allow-list as `createUploadUrl`).
1179
1185
  * @param options.fileName - Override file name. Inferred from the URL path when omitted.
1186
+ * @param options.folderPath - Root-relative folder to upload under.
1180
1187
  * @returns File upload resource with status `processing` — parsing continues async.
1181
1188
  */
1182
1189
  async uploadFromUrl(url, options = {}) {
@@ -1294,6 +1301,16 @@ var ManagementContextFilesResource = class {
1294
1301
  * @param options.concurrency - Max concurrent PUTs (default 10).
1295
1302
  * @param options.waitUntil - `"processing"` (default) or `"ready"`.
1296
1303
  * @param options.onProgress - Optional progress callback after each file.
1304
+ * @param options.folderPath - Root-relative folder to upload under. Nested
1305
+ * files keep their existing relative folder labels under this prefix.
1306
+ * @example
1307
+ * ```ts
1308
+ * const mgmt = new ModusManagement()
1309
+ * const result = await mgmt.context.files.uploadFiles(
1310
+ * ['./q3.pdf', './notes.md'],
1311
+ * { folderPath: 'reports/2026' },
1312
+ * )
1313
+ * ```
1297
1314
  */
1298
1315
  async uploadFiles(paths, options = {}) {
1299
1316
  return this.uploadPaths(paths.map((input) => typeof input === "string" ? { path: input } : input), options);
@@ -1301,16 +1318,23 @@ var ManagementContextFilesResource = class {
1301
1318
  /**
1302
1319
  * Upload a local file and wait for it to reach `"processing"` or `"ready"`.
1303
1320
  *
1304
- * Gets a presigned URL, PUTs the file bytes, then polls `get()` until the
1305
- * upload leaves `"pending"` (or reaches `"ready"`/`"failed"`).
1321
+ * Gets a presigned URL, PUTs the file bytes, then polls `get()`
1322
+ * until the upload leaves `"pending"` (or reaches `"ready"`/`"failed"`).
1306
1323
  *
1307
1324
  * @param path - Path to a local file.
1308
1325
  * @param options.waitUntil - `"processing"` (parsing started, default) or
1309
1326
  * `"ready"` (parsing finished).
1310
1327
  * @param options.pollIntervalMs - Milliseconds between status polls.
1311
1328
  * @param options.timeoutMs - Max milliseconds to wait before raising.
1329
+ * @param options.folderPath - Root-relative folder to upload under. Example:
1330
+ * `{ folderPath: 'reports/2026' }` places `./report.pdf` at `reports/2026`.
1312
1331
  * @returns The file upload resource once it reaches `waitUntil` (or `"failed"`).
1313
1332
  * @throws {ModusError} If the PUT fails, or polling times out.
1333
+ * @example
1334
+ * ```ts
1335
+ * const mgmt = new ModusManagement()
1336
+ * const file = await mgmt.context.files.upload('./report.pdf', { folderPath: 'reports/2026' })
1337
+ * ```
1314
1338
  */
1315
1339
  async upload(path, options = {}) {
1316
1340
  const waitUntil = options.waitUntil ?? "processing";
@@ -1324,8 +1348,10 @@ var ManagementContextFilesResource = class {
1324
1348
  fileSize: fileStat.size
1325
1349
  });
1326
1350
  const data = await readFile(path);
1327
- await putBytes(this.config.fetch, slot.uploadUrl, data, slot.contentType, DEFAULT_PUT_TIMEOUT_MS);
1328
- const finalized = await this.finalize(slot.uploadId, slot.fileName);
1351
+ await putBytes(this.config.fetch, slot, data, DEFAULT_PUT_TIMEOUT_MS);
1352
+ const finalized = await this.finalize(slot.uploadId, slot.fileName, {
1353
+ ...options.folderPath !== void 0 ? { folderPath: options.folderPath } : {}
1354
+ });
1329
1355
  if (statusSatisfies(finalized.status, waitUntil)) return finalized;
1330
1356
  return this.pollUntil(
1331
1357
  slot.uploadId,
@@ -1360,8 +1386,17 @@ var ManagementContextFilesResource = class {
1360
1386
  * @param options.concurrency - Max concurrent PUT+poll operations (default 10).
1361
1387
  * @param options.waitUntil - `"processing"` (default) or `"ready"` — same as `upload()`.
1362
1388
  * @param options.onProgress - Optional progress callback after each file.
1389
+ * @param options.folderPath - Root-relative folder to upload under. Nested
1390
+ * files keep their path relative to `path` under this prefix. Example:
1391
+ * `uploadDir('./docs', { folderPath: 'reports' })` places `./docs/a.txt` at
1392
+ * `reports` and `./docs/nested/b.txt` at `reports/nested`.
1363
1393
  * @returns `UploadDirResult` with every successful `FileUpload` and every
1364
1394
  * per-file failure (slot creation or PUT/poll), each tagged with its local path.
1395
+ * @example
1396
+ * ```ts
1397
+ * const mgmt = new ModusManagement()
1398
+ * const result = await mgmt.context.files.uploadDir('./docs', { folderPath: 'reports' })
1399
+ * ```
1365
1400
  */
1366
1401
  async uploadDir(path, options = {}) {
1367
1402
  const waitUntil = options.waitUntil ?? "processing";
@@ -1383,6 +1418,10 @@ var ManagementContextFilesResource = class {
1383
1418
  validateWaitUntil(waitUntil);
1384
1419
  const concurrency = options.concurrency ?? DEFAULT_CONCURRENCY;
1385
1420
  if (concurrency < 1) throw new Error(`concurrency must be >= 1, got ${concurrency}`);
1421
+ const prefixed = files.map((file) => {
1422
+ const folderPath = joinDestination(options.folderPath, file.folderPath);
1423
+ return { path: file.path, ...folderPath !== void 0 ? { folderPath } : {} };
1424
+ });
1386
1425
  const uploaded = [];
1387
1426
  const failed = [];
1388
1427
  const total = files.length;
@@ -1396,7 +1435,7 @@ var ManagementContextFilesResource = class {
1396
1435
  failed: failed.length
1397
1436
  });
1398
1437
  };
1399
- for (const batch of chunked(files, MAX_BULK_UPLOAD_FILES)) {
1438
+ for (const batch of chunked(prefixed, MAX_BULK_UPLOAD_FILES)) {
1400
1439
  const failedBefore = failed.length;
1401
1440
  const slots = await this.createSlots(batch, failed);
1402
1441
  for (let reported = failedBefore + 1; reported <= failed.length; reported += 1) {
@@ -1438,7 +1477,7 @@ var ManagementContextFilesResource = class {
1438
1477
  async ({ path, folderPath, slot }) => {
1439
1478
  try {
1440
1479
  const data = await readFile(path);
1441
- await putBytes(this.config.fetch, slot.uploadUrl, data, slot.contentType, DEFAULT_PUT_TIMEOUT_MS);
1480
+ await putBytes(this.config.fetch, slot, data, DEFAULT_PUT_TIMEOUT_MS);
1442
1481
  return { landed: { path, ...folderPath !== void 0 ? { folderPath } : {}, slot } };
1443
1482
  } catch (error) {
1444
1483
  const message = error instanceof Error ? error.message : String(error);
@@ -1503,9 +1542,18 @@ var ManagementContextFilesResource = class {
1503
1542
  };
1504
1543
 
1505
1544
  // src/management/context/items.ts
1506
- function contextListParams(pageSize, pageToken, contextType) {
1545
+ function contextListParams(pageSize, pageToken, filters = {}) {
1507
1546
  const extra = {};
1508
- if (contextType !== void 0) extra.contextTypes = [contextType];
1547
+ if (filters.contextType !== void 0) extra.contextTypes = [filters.contextType];
1548
+ if (filters.parentUids !== void 0) {
1549
+ extra.parentUids = filters.parentUids.length === 0 ? "" : [...filters.parentUids];
1550
+ }
1551
+ if (filters.ancestorUids !== void 0) {
1552
+ extra.ancestorUids = filters.ancestorUids.length === 0 ? "" : [...filters.ancestorUids];
1553
+ }
1554
+ if (filters.connectionIds !== void 0) {
1555
+ extra.connectionIds = filters.connectionIds.length === 0 ? "" : [...filters.connectionIds];
1556
+ }
1509
1557
  return aipListParams(pageSize, pageToken, extra);
1510
1558
  }
1511
1559
  function parseContextItem(raw) {
@@ -1522,24 +1570,48 @@ var ManagementContextItemsResource = class {
1522
1570
  * @param options.pageSize - Items per page (default 25).
1523
1571
  * @param options.pageToken - Token from a previous page's `nextPageToken`.
1524
1572
  * @param options.contextType - Filter to one context type (for example `"note"`).
1573
+ * @param options.parentUids - Exact ordered native ancestry chain for direct
1574
+ * children. Omit to leave parent unrestricted; pass `[]` for the known-empty
1575
+ * root. Native UIDs are exact tokens; for a folder's children send ancestry
1576
+ * UIDs plus the last `dataPath` token, not the hashed context-item `uid`.
1577
+ * @param options.ancestorUids - Ordered UID ancestry prefix for strict
1578
+ * descendants. Omit to leave unrestricted; pass `[]` for every item with
1579
+ * non-null ancestry.
1580
+ * @param options.connectionIds - Restrict to these connection ids. Omit to
1581
+ * leave unfiltered; pass `[]` to match none. The Files root is
1582
+ * `connectionIds: ['files']` with `parentUids: []`.
1525
1583
  * @returns A page of context items.
1584
+ *
1585
+ * @example
1586
+ * ```ts
1587
+ * const rootFiles = await mgmt.context.items.list({
1588
+ * connectionIds: ['files'],
1589
+ * contextType: 'file_upload',
1590
+ * parentUids: [],
1591
+ * })
1592
+ * ```
1526
1593
  */
1527
1594
  list(options = {}) {
1528
1595
  const pageSize = options.pageSize ?? 25;
1529
1596
  validatePageSize(pageSize);
1530
- return this.listPage(pageSize, options.pageToken, options.contextType);
1597
+ return this.listPage(pageSize, options.pageToken, {
1598
+ contextType: options.contextType,
1599
+ parentUids: options.parentUids,
1600
+ ancestorUids: options.ancestorUids,
1601
+ connectionIds: options.connectionIds
1602
+ });
1531
1603
  }
1532
- async listPage(pageSize, pageToken, contextType) {
1604
+ async listPage(pageSize, pageToken, filters) {
1533
1605
  const data = asRecord(
1534
1606
  await invokeWithRetry(this.config, this.http, "ContextItemsController_list", {
1535
- query: contextListParams(pageSize, pageToken, contextType)
1607
+ query: contextListParams(pageSize, pageToken, filters)
1536
1608
  })
1537
1609
  );
1538
1610
  return buildAipPage(
1539
1611
  data,
1540
1612
  "contextItems",
1541
1613
  parseContextItem,
1542
- (token) => this.listPage(pageSize, token, contextType)
1614
+ (token) => this.listPage(pageSize, token, filters)
1543
1615
  );
1544
1616
  }
1545
1617
  /**
@@ -1591,7 +1663,7 @@ var ManagementContextItemsResource = class {
1591
1663
  return this.get(uid);
1592
1664
  }
1593
1665
  /**
1594
- * Delete a context item.
1666
+ * Delete a context item. Deleting a Files folder also deletes all its contents.
1595
1667
  *
1596
1668
  * @param uid - Context item uid.
1597
1669
  * @returns Deletion confirmation details.
@@ -1602,6 +1674,44 @@ var ManagementContextItemsResource = class {
1602
1674
  });
1603
1675
  return data;
1604
1676
  }
1677
+ /**
1678
+ * Move a live file or Files folder.
1679
+ *
1680
+ * Pass `destinationFolderUid: null` to move to the Files root. The
1681
+ * destination folder must already exist. Same-parent moves succeed as a
1682
+ * no-op. Does not rename or merge folders.
1683
+ *
1684
+ * @param uid - Stored context-item uid of the file or folder to move.
1685
+ * @param options.destinationFolderUid - Stored context-item uid of the
1686
+ * destination folder, or `null` for the Files root.
1687
+ * @returns How many items changed parent (`0` is a successful no-op).
1688
+ * @throws {NotFoundError} The source is missing or not visible.
1689
+ * @throws {ModusError} The destination is missing, not a Files folder, or
1690
+ * the move would create a cycle (HTTP 400).
1691
+ * @throws {PermissionDeniedError} The destination exists but is not writable
1692
+ * for this caller.
1693
+ * @throws {ConflictError} A sibling with the same name already exists.
1694
+ *
1695
+ * @example
1696
+ * ```ts
1697
+ * const moved = await mgmt.context.items.move('PLACEHOLDER_UID', {
1698
+ * destinationFolderUid: 'PLACEHOLDER_FOLDER_UID',
1699
+ * })
1700
+ * console.log(moved.movedItems)
1701
+ * ```
1702
+ */
1703
+ async move(uid, options) {
1704
+ const data = await invokeWithRetry(
1705
+ this.config,
1706
+ this.http,
1707
+ "ContextItemsController_move",
1708
+ {
1709
+ pathParams: { uid },
1710
+ jsonBody: { destinationFolderUid: options.destinationFolderUid }
1711
+ }
1712
+ );
1713
+ return data;
1714
+ }
1605
1715
  };
1606
1716
 
1607
1717
  // src/management/context/context.ts
@@ -1926,6 +2036,65 @@ var ScopeEvaluationsResource = class {
1926
2036
  }
1927
2037
  };
1928
2038
 
2039
+ // src/management/scopes/interfaces.ts
2040
+ var ScopeInterfacesResource = class {
2041
+ constructor(http, config, scopeId) {
2042
+ this.http = http;
2043
+ this.config = config;
2044
+ this.scopeId = scopeId;
2045
+ }
2046
+ /** List the Slack and Microsoft Teams interfaces on this scope. */
2047
+ async list() {
2048
+ validateId(this.scopeId, "scope_id");
2049
+ const data = await invokeWithRetry(this.config, this.http, "ScopeInterfacesController_list", {
2050
+ pathParams: { id: this.scopeId }
2051
+ });
2052
+ return data.interfaces;
2053
+ }
2054
+ /**
2055
+ * Add a Slack or Microsoft Teams interface to this scope.
2056
+ *
2057
+ * @param options - Interface type, optional name and config.
2058
+ * @returns The created interface.
2059
+ */
2060
+ async create(options) {
2061
+ validateId(this.scopeId, "scope_id");
2062
+ return await invokeWithRetry(this.config, this.http, "ScopeInterfacesController_add", {
2063
+ pathParams: { id: this.scopeId },
2064
+ jsonBody: omitUndefined(options)
2065
+ });
2066
+ }
2067
+ /**
2068
+ * Update an interface on this scope.
2069
+ *
2070
+ * @param interfaceId - Interface id.
2071
+ * @param options - Updated name and/or config.
2072
+ * @param updateMask - Optional comma-separated field names to update.
2073
+ * @returns The updated interface.
2074
+ */
2075
+ async update(interfaceId, options, updateMask) {
2076
+ validateId(this.scopeId, "scope_id");
2077
+ validateId(interfaceId, "interface_id");
2078
+ return await invokeWithRetry(this.config, this.http, "ScopeInterfacesController_update", {
2079
+ pathParams: { id: this.scopeId, interfaceId },
2080
+ query: updateMaskQuery(updateMask),
2081
+ jsonBody: updateMask === void 0 ? omitUndefined(options) : options
2082
+ });
2083
+ }
2084
+ /**
2085
+ * Remove an interface from this scope.
2086
+ *
2087
+ * @param interfaceId - Interface id.
2088
+ */
2089
+ async delete(interfaceId) {
2090
+ validateId(this.scopeId, "scope_id");
2091
+ validateId(interfaceId, "interface_id");
2092
+ await invokeWithRetry(this.config, this.http, "ScopeInterfacesController_delete", {
2093
+ pathParams: { id: this.scopeId, interfaceId }
2094
+ });
2095
+ }
2096
+ };
2097
+
1929
2098
  // src/management/scopes/supervision.ts
1930
2099
  var ScopeSupervisionResource = class {
1931
2100
  constructor(http, config, scopeId) {
@@ -2041,6 +2210,15 @@ var ManagementScopesResource = class {
2041
2210
  supervision(scopeId) {
2042
2211
  return new ScopeSupervisionResource(this.http, this.config, scopeId);
2043
2212
  }
2213
+ /**
2214
+ * Slack and Microsoft Teams interfaces for a scope.
2215
+ *
2216
+ * @param scopeId - Scope id.
2217
+ * @returns An interfaces resource scoped to the scope.
2218
+ */
2219
+ interfaces(scopeId) {
2220
+ return new ScopeInterfacesResource(this.http, this.config, scopeId);
2221
+ }
2044
2222
  /**
2045
2223
  * List scopes in the organization.
2046
2224
  *
@@ -2112,6 +2290,7 @@ var ManagementScopesResource = class {
2112
2290
  * @param options.instructions - Optional system instructions.
2113
2291
  * @param options.model - Optional model id.
2114
2292
  * @param options.toolset - Optional tool selection for the scope.
2293
+ * @param options.includeOwnLearnings - Whether the scope reads what is taught while using it. Defaults to true.
2115
2294
  * @param options.guardrails - Runtime guardrail labels (for example `"no-pii"`). Omit to create with no guardrails.
2116
2295
  * @returns The created scope (draft).
2117
2296
  * @example
@@ -2131,6 +2310,7 @@ var ManagementScopesResource = class {
2131
2310
  model: options.model,
2132
2311
  connectionSet: options.connectionSet,
2133
2312
  contextSelections: options.contextSelections,
2313
+ includeOwnLearnings: options.includeOwnLearnings,
2134
2314
  interfaces: options.interfaces,
2135
2315
  accessConfig: accessConfigBodyForCreate(options.guardrails)
2136
2316
  });