@getmodus/sdk 0.5.0 → 0.6.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/CHANGELOG.md +2 -2
- package/dist/{chunk-H76PTY5G.js → chunk-HEHHN4D6.js} +70 -4
- package/dist/chunk-HEHHN4D6.js.map +1 -0
- package/dist/{conversations-Pe3kNikF.d.cts → conversations-BRg8gEKX.d.cts} +1378 -98
- package/dist/{conversations-Pe3kNikF.d.ts → conversations-BRg8gEKX.d.ts} +1378 -98
- package/dist/index.cjs +69 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/management/index.cjs +396 -3
- package/dist/management/index.cjs.map +1 -1
- package/dist/management/index.d.cts +150 -3
- package/dist/management/index.d.ts +150 -3
- package/dist/management/index.js +331 -1
- package/dist/management/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-H76PTY5G.js.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as components, H as HttpClient, M as ModusConfig, P as Page, W as WorkflowType, V as VariationView, a as Workflow, C as ContextItem, b as ContextItemLookupRow, d as CustomContextItemsResource, e as ConversationKind, f as ConversationListItem, g as Conversation, S as ScopeConversationsResource, h as Scope, i as ModusClientBase, j as ModusOptions } from './conversations-
|
|
2
|
-
export { A as Agent, k as AgentType, l as ContextType, m as Message, O as OPERATIONS, n as OperationId, o as OperationSpec, p as ScopeStatus, q as ScopeVariation, r as Skill, s as SkillStatus, t as SkillVariation, u as conversationScopeId, v as conversationSkillId, w as operations, x as paths } from './conversations-
|
|
1
|
+
import { c as components, H as HttpClient, M as ModusConfig, P as Page, W as WorkflowType, V as VariationView, a as Workflow, C as ContextItem, b as ContextItemLookupRow, d as CustomContextItemsResource, e as ConversationKind, f as ConversationListItem, g as Conversation, S as ScopeConversationsResource, h as Scope, i as ModusClientBase, j as ModusOptions } from './conversations-BRg8gEKX.cjs';
|
|
2
|
+
export { A as Agent, k as AgentType, l as ContextType, m as Message, O as OPERATIONS, n as OperationId, o as OperationSpec, p as ScopeStatus, q as ScopeVariation, r as Skill, s as SkillStatus, t as SkillVariation, u as conversationScopeId, v as conversationSkillId, w as operations, x as paths } from './conversations-BRg8gEKX.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Base class for all Modus SDK errors.
|
|
@@ -107,7 +107,7 @@ declare class ValidationError extends ModusError {
|
|
|
107
107
|
* - `claude-sonnet-5`, `claude-sonnet-4.6`, `claude-opus-4.8`
|
|
108
108
|
* - `gpt-5.2`, `gpt-5.5`, `gpt-5-mini`, `gpt-oss-120b`, `gpt-oss-20b`
|
|
109
109
|
* - `qwen3-235b-a22b-2507`, `qwen3-coder`, `qwen3-32b`
|
|
110
|
-
* - `deepseek-chat-v3.1`, `minimax-m2.7`
|
|
110
|
+
* - `deepseek-chat-v3.1`, `deepseek-v4-pro`, `deepseek-v4-flash-latest`, `minimax-m2.7`
|
|
111
111
|
* - `llama-4-maverick`, `llama-4-scout`, `llama-3.3-70b-instruct`
|
|
112
112
|
* - `gemini-3.1-pro-preview`, `gemini-3-flash-preview`
|
|
113
113
|
* - `grok-4.3-fast`, `grok-4.3`
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as components, H as HttpClient, M as ModusConfig, P as Page, W as WorkflowType, V as VariationView, a as Workflow, C as ContextItem, b as ContextItemLookupRow, d as CustomContextItemsResource, e as ConversationKind, f as ConversationListItem, g as Conversation, S as ScopeConversationsResource, h as Scope, i as ModusClientBase, j as ModusOptions } from './conversations-
|
|
2
|
-
export { A as Agent, k as AgentType, l as ContextType, m as Message, O as OPERATIONS, n as OperationId, o as OperationSpec, p as ScopeStatus, q as ScopeVariation, r as Skill, s as SkillStatus, t as SkillVariation, u as conversationScopeId, v as conversationSkillId, w as operations, x as paths } from './conversations-
|
|
1
|
+
import { c as components, H as HttpClient, M as ModusConfig, P as Page, W as WorkflowType, V as VariationView, a as Workflow, C as ContextItem, b as ContextItemLookupRow, d as CustomContextItemsResource, e as ConversationKind, f as ConversationListItem, g as Conversation, S as ScopeConversationsResource, h as Scope, i as ModusClientBase, j as ModusOptions } from './conversations-BRg8gEKX.js';
|
|
2
|
+
export { A as Agent, k as AgentType, l as ContextType, m as Message, O as OPERATIONS, n as OperationId, o as OperationSpec, p as ScopeStatus, q as ScopeVariation, r as Skill, s as SkillStatus, t as SkillVariation, u as conversationScopeId, v as conversationSkillId, w as operations, x as paths } from './conversations-BRg8gEKX.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Base class for all Modus SDK errors.
|
|
@@ -107,7 +107,7 @@ declare class ValidationError extends ModusError {
|
|
|
107
107
|
* - `claude-sonnet-5`, `claude-sonnet-4.6`, `claude-opus-4.8`
|
|
108
108
|
* - `gpt-5.2`, `gpt-5.5`, `gpt-5-mini`, `gpt-oss-120b`, `gpt-oss-20b`
|
|
109
109
|
* - `qwen3-235b-a22b-2507`, `qwen3-coder`, `qwen3-32b`
|
|
110
|
-
* - `deepseek-chat-v3.1`, `minimax-m2.7`
|
|
110
|
+
* - `deepseek-chat-v3.1`, `deepseek-v4-pro`, `deepseek-v4-flash-latest`, `minimax-m2.7`
|
|
111
111
|
* - `llama-4-maverick`, `llama-4-scout`, `llama-3.3-70b-instruct`
|
|
112
112
|
* - `gemini-3.1-pro-preview`, `gemini-3-flash-preview`
|
|
113
113
|
* - `grok-4.3-fast`, `grok-4.3`
|
package/dist/index.js
CHANGED
|
@@ -216,7 +216,7 @@ function formatConfigForLog(config) {
|
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
// src/_http.ts
|
|
219
|
-
var USER_AGENT = `modus-typescript/${"0.
|
|
219
|
+
var USER_AGENT = `modus-typescript/${"0.6.0"} (node/${process.version}; ${process.platform})`;
|
|
220
220
|
function buildUrl(baseUrl, path, params) {
|
|
221
221
|
const url = new URL(path.startsWith("/") ? path : `/${path}`, baseUrl);
|
|
222
222
|
if (params) {
|
|
@@ -592,6 +592,66 @@ var OPERATIONS = {
|
|
|
592
592
|
requestSchema: "CreateSavedQueryDto",
|
|
593
593
|
responseSchema: "CreatedContextItemResponseDto"
|
|
594
594
|
},
|
|
595
|
+
"ContextFilesController_get": {
|
|
596
|
+
method: "GET",
|
|
597
|
+
path: "/api/v1/context/files/{uploadId}",
|
|
598
|
+
service: "modus-api",
|
|
599
|
+
serverUrl: "https://api.getmodus.com",
|
|
600
|
+
pathParams: ["uploadId"],
|
|
601
|
+
queryParams: [],
|
|
602
|
+
requestSchema: null,
|
|
603
|
+
responseSchema: "FileUploadResourceDto"
|
|
604
|
+
},
|
|
605
|
+
"ContextFilesController_list": {
|
|
606
|
+
method: "GET",
|
|
607
|
+
path: "/api/v1/context/files",
|
|
608
|
+
service: "modus-api",
|
|
609
|
+
serverUrl: "https://api.getmodus.com",
|
|
610
|
+
pathParams: [],
|
|
611
|
+
queryParams: ["pageToken", "pageSize"],
|
|
612
|
+
requestSchema: null,
|
|
613
|
+
responseSchema: "ListFilesResponseDto"
|
|
614
|
+
},
|
|
615
|
+
"ContextFilesController_uploadFromUrl": {
|
|
616
|
+
method: "POST",
|
|
617
|
+
path: "/api/v1/context/files/uploadFromUrl",
|
|
618
|
+
service: "modus-api",
|
|
619
|
+
serverUrl: "https://api.getmodus.com",
|
|
620
|
+
pathParams: [],
|
|
621
|
+
queryParams: [],
|
|
622
|
+
requestSchema: "UploadFromUrlDto",
|
|
623
|
+
responseSchema: "FileUploadResourceDto"
|
|
624
|
+
},
|
|
625
|
+
"ContextFilesController_uploadFromUrls": {
|
|
626
|
+
method: "POST",
|
|
627
|
+
path: "/api/v1/context/files/uploadFromUrls",
|
|
628
|
+
service: "modus-api",
|
|
629
|
+
serverUrl: "https://api.getmodus.com",
|
|
630
|
+
pathParams: [],
|
|
631
|
+
queryParams: [],
|
|
632
|
+
requestSchema: "BulkUploadFromUrlsDto",
|
|
633
|
+
responseSchema: "BulkUploadFromUrlsResponseDto"
|
|
634
|
+
},
|
|
635
|
+
"ContextFilesController_uploadUrl": {
|
|
636
|
+
method: "POST",
|
|
637
|
+
path: "/api/v1/context/files/uploadUrl",
|
|
638
|
+
service: "modus-api",
|
|
639
|
+
serverUrl: "https://api.getmodus.com",
|
|
640
|
+
pathParams: [],
|
|
641
|
+
queryParams: [],
|
|
642
|
+
requestSchema: "UploadUrlDto",
|
|
643
|
+
responseSchema: "UploadUrlResponseDto"
|
|
644
|
+
},
|
|
645
|
+
"ContextFilesController_uploadUrls": {
|
|
646
|
+
method: "POST",
|
|
647
|
+
path: "/api/v1/context/files/uploadUrls",
|
|
648
|
+
service: "modus-api",
|
|
649
|
+
serverUrl: "https://api.getmodus.com",
|
|
650
|
+
pathParams: [],
|
|
651
|
+
queryParams: [],
|
|
652
|
+
requestSchema: "BulkUploadUrlsDto",
|
|
653
|
+
responseSchema: "BulkUploadUrlsResponseDto"
|
|
654
|
+
},
|
|
595
655
|
"ContextItemsController_delete": {
|
|
596
656
|
method: "DELETE",
|
|
597
657
|
path: "/api/v1/context/items/{uid}",
|
|
@@ -818,7 +878,7 @@ var OPERATIONS = {
|
|
|
818
878
|
service: "modus-api",
|
|
819
879
|
serverUrl: "https://api.getmodus.com",
|
|
820
880
|
pathParams: [],
|
|
821
|
-
queryParams: ["pageToken", "page", "pageSize", "userId", "toolName", "timeframe", "includeTools", "kind"],
|
|
881
|
+
queryParams: ["pageToken", "page", "pageSize", "userId", "toolName", "source", "timeframe", "includeTools", "kind"],
|
|
822
882
|
requestSchema: null,
|
|
823
883
|
responseSchema: "ListConversationsResponseDto"
|
|
824
884
|
},
|
|
@@ -968,7 +1028,7 @@ var OPERATIONS = {
|
|
|
968
1028
|
service: "modus-api",
|
|
969
1029
|
serverUrl: "https://api.getmodus.com",
|
|
970
1030
|
pathParams: ["id"],
|
|
971
|
-
queryParams: ["pageToken", "page", "pageSize", "userId", "toolName", "timeframe", "includeTools"],
|
|
1031
|
+
queryParams: ["pageToken", "page", "pageSize", "userId", "toolName", "source", "timeframe", "includeTools"],
|
|
972
1032
|
requestSchema: null,
|
|
973
1033
|
responseSchema: "ListConversationsResponseDto"
|
|
974
1034
|
},
|
|
@@ -1521,6 +1581,10 @@ var WRITE_BODY_ALLOWED_KEYS = {
|
|
|
1521
1581
|
ContextCreatorsController_createLink: ["url", "title", "isCrawl", "pageLimit"],
|
|
1522
1582
|
ContextCreatorsController_createNote: ["title", "content"],
|
|
1523
1583
|
ContextCreatorsController_createSavedQuery: ["name", "connectionId", "query", "description", "path"],
|
|
1584
|
+
ContextFilesController_uploadFromUrl: ["url", "fileName"],
|
|
1585
|
+
ContextFilesController_uploadFromUrls: ["urls"],
|
|
1586
|
+
ContextFilesController_uploadUrl: ["fileName", "contentType", "fileSize"],
|
|
1587
|
+
ContextFilesController_uploadUrls: ["files"],
|
|
1524
1588
|
ContextItemsController_lookup: ["contextType", "dataPath", "contentProjection"],
|
|
1525
1589
|
ContextItemsController_update: ["contextType", "content", "description", "userFeedback", "topics"],
|
|
1526
1590
|
CustomContextItemsController_batchCreate: ["items"],
|
|
@@ -2219,6 +2283,334 @@ async function resolveAndUpdateLink(items, uid, options) {
|
|
|
2219
2283
|
});
|
|
2220
2284
|
}
|
|
2221
2285
|
|
|
2286
|
+
// src/management/context/files.ts
|
|
2287
|
+
var import_promises = require("fs/promises");
|
|
2288
|
+
var import_node_path = require("path");
|
|
2289
|
+
var MAX_BULK_UPLOAD_FILES = 100;
|
|
2290
|
+
var DEFAULT_LIST_PAGE_SIZE = 50;
|
|
2291
|
+
var DEFAULT_PUT_TIMEOUT_MS = 6e4;
|
|
2292
|
+
var DEFAULT_POLL_INTERVAL_MS = 500;
|
|
2293
|
+
var DEFAULT_UPLOAD_TIMEOUT_MS = 12e4;
|
|
2294
|
+
var DEFAULT_CONCURRENCY = 10;
|
|
2295
|
+
var STATUS_ORDER = { pending: 0, processing: 1, ready: 2 };
|
|
2296
|
+
var WAIT_UNTIL_VALUES = /* @__PURE__ */ new Set(["processing", "ready"]);
|
|
2297
|
+
var DEFER_CONTENT_TYPE_TO_SERVER = "application/octet-stream";
|
|
2298
|
+
function validateWaitUntil(waitUntil) {
|
|
2299
|
+
if (!WAIT_UNTIL_VALUES.has(waitUntil)) {
|
|
2300
|
+
throw new Error(`waitUntil must be one of ${[...WAIT_UNTIL_VALUES].join(", ")}, got ${waitUntil}`);
|
|
2301
|
+
}
|
|
2302
|
+
}
|
|
2303
|
+
function validateBulkSize(count, name) {
|
|
2304
|
+
if (count === 0) throw new Error(`${name} must not be empty`);
|
|
2305
|
+
if (count > MAX_BULK_UPLOAD_FILES) {
|
|
2306
|
+
throw new Error(`${name} must have at most ${MAX_BULK_UPLOAD_FILES} entries, got ${count}`);
|
|
2307
|
+
}
|
|
2308
|
+
}
|
|
2309
|
+
function statusSatisfies(status, waitUntil) {
|
|
2310
|
+
if (status === "failed") return true;
|
|
2311
|
+
return (STATUS_ORDER[status] ?? 0) >= STATUS_ORDER[waitUntil];
|
|
2312
|
+
}
|
|
2313
|
+
function sleep2(ms) {
|
|
2314
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
2315
|
+
}
|
|
2316
|
+
function chunked(items, size) {
|
|
2317
|
+
const out = [];
|
|
2318
|
+
for (let i = 0; i < items.length; i += size) out.push(items.slice(i, i + size));
|
|
2319
|
+
return out;
|
|
2320
|
+
}
|
|
2321
|
+
async function mapWithConcurrency(items, concurrency, worker) {
|
|
2322
|
+
const results = new Array(items.length);
|
|
2323
|
+
let cursor = 0;
|
|
2324
|
+
async function run() {
|
|
2325
|
+
for (; ; ) {
|
|
2326
|
+
const index = cursor++;
|
|
2327
|
+
if (index >= items.length) return;
|
|
2328
|
+
results[index] = await worker(items[index]);
|
|
2329
|
+
}
|
|
2330
|
+
}
|
|
2331
|
+
await Promise.all(Array.from({ length: Math.min(concurrency, items.length) }, run));
|
|
2332
|
+
return results;
|
|
2333
|
+
}
|
|
2334
|
+
async function walkFiles(root, recursive) {
|
|
2335
|
+
const out = [];
|
|
2336
|
+
async function walk(dir) {
|
|
2337
|
+
const entries = await (0, import_promises.readdir)(dir, { withFileTypes: true });
|
|
2338
|
+
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
2339
|
+
for (const entry of entries) {
|
|
2340
|
+
if (entry.name.startsWith(".") || entry.isSymbolicLink()) continue;
|
|
2341
|
+
const full = (0, import_node_path.join)(dir, entry.name);
|
|
2342
|
+
if (entry.isDirectory()) {
|
|
2343
|
+
if (recursive) await walk(full);
|
|
2344
|
+
} else if (entry.isFile()) {
|
|
2345
|
+
out.push(full);
|
|
2346
|
+
}
|
|
2347
|
+
}
|
|
2348
|
+
}
|
|
2349
|
+
await walk(root);
|
|
2350
|
+
return out;
|
|
2351
|
+
}
|
|
2352
|
+
async function putBytes(fetchImpl, url, data, contentType, timeoutMs) {
|
|
2353
|
+
const response = await fetchImpl(url, {
|
|
2354
|
+
method: "PUT",
|
|
2355
|
+
body: data,
|
|
2356
|
+
headers: { "Content-Type": contentType },
|
|
2357
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
2358
|
+
});
|
|
2359
|
+
if (!response.ok) {
|
|
2360
|
+
const text = await response.text().catch(() => "");
|
|
2361
|
+
throw new ModusError(`Upload PUT to presigned URL failed with HTTP ${response.status}.`, {
|
|
2362
|
+
statusCode: response.status,
|
|
2363
|
+
body: text ? text.slice(0, 500) : void 0
|
|
2364
|
+
});
|
|
2365
|
+
}
|
|
2366
|
+
}
|
|
2367
|
+
function createSlotsPayload(files) {
|
|
2368
|
+
return {
|
|
2369
|
+
files: files.map((f) => ({ fileName: f.fileName, contentType: f.contentType, fileSize: f.fileSize }))
|
|
2370
|
+
};
|
|
2371
|
+
}
|
|
2372
|
+
function uploadFromUrlsPayload(urls) {
|
|
2373
|
+
return {
|
|
2374
|
+
urls: urls.map((u) => u.fileName !== void 0 ? { url: u.url, fileName: u.fileName } : { url: u.url })
|
|
2375
|
+
};
|
|
2376
|
+
}
|
|
2377
|
+
function assignSlots(batch, result, failed) {
|
|
2378
|
+
const failedIndices = new Set(result.failed.map((f) => f.index));
|
|
2379
|
+
for (const f of result.failed) {
|
|
2380
|
+
failed.push({ path: batch[f.index], error: f.error });
|
|
2381
|
+
}
|
|
2382
|
+
const remaining = batch.filter((_, i) => !failedIndices.has(i));
|
|
2383
|
+
const uploaded = result.uploaded;
|
|
2384
|
+
if (uploaded.length < remaining.length) {
|
|
2385
|
+
for (const path of remaining.slice(uploaded.length)) {
|
|
2386
|
+
failed.push({ path, error: "Server returned fewer upload slots than requested files." });
|
|
2387
|
+
}
|
|
2388
|
+
}
|
|
2389
|
+
const paired = Math.min(remaining.length, uploaded.length);
|
|
2390
|
+
const assignments = [];
|
|
2391
|
+
for (let i = 0; i < paired; i++) {
|
|
2392
|
+
assignments.push({ path: remaining[i], slot: uploaded[i] });
|
|
2393
|
+
}
|
|
2394
|
+
return assignments;
|
|
2395
|
+
}
|
|
2396
|
+
var ManagementContextFilesResource = class {
|
|
2397
|
+
/** @internal */
|
|
2398
|
+
constructor(http, config) {
|
|
2399
|
+
this.http = http;
|
|
2400
|
+
this.config = config;
|
|
2401
|
+
}
|
|
2402
|
+
/**
|
|
2403
|
+
* Get a presigned S3 PUT URL for one file.
|
|
2404
|
+
*
|
|
2405
|
+
* @param input.fileName - Original file name — used to build the S3 object key.
|
|
2406
|
+
* @param input.contentType - MIME type. Allowed categories: PDF, images, text,
|
|
2407
|
+
* Office/OpenDocument documents, audio, and video.
|
|
2408
|
+
* @param input.fileSize - File size in bytes. Rejected above 50MB.
|
|
2409
|
+
* @returns Presigned upload slot. PUT the raw bytes to `uploadUrl` within 15
|
|
2410
|
+
* minutes, then poll `get(uploadId)` — there is no separate finalize call.
|
|
2411
|
+
*/
|
|
2412
|
+
async createUploadUrl(input) {
|
|
2413
|
+
return asRecord(
|
|
2414
|
+
await invokeWithRetry(this.config, this.http, "ContextFilesController_uploadUrl", {
|
|
2415
|
+
jsonBody: { fileName: input.fileName, contentType: input.contentType, fileSize: input.fileSize }
|
|
2416
|
+
})
|
|
2417
|
+
);
|
|
2418
|
+
}
|
|
2419
|
+
/**
|
|
2420
|
+
* Get presigned S3 PUT URLs for up to 100 files in one call.
|
|
2421
|
+
*
|
|
2422
|
+
* @param files - Files to create upload slots for (max 100).
|
|
2423
|
+
* @returns Slots for every file that passed validation, plus per-index
|
|
2424
|
+
* failures (bad MIME type, oversize) for the rest — never a partial 4xx.
|
|
2425
|
+
*/
|
|
2426
|
+
async createUploadUrls(files) {
|
|
2427
|
+
validateBulkSize(files.length, "files");
|
|
2428
|
+
return asRecord(
|
|
2429
|
+
await invokeWithRetry(this.config, this.http, "ContextFilesController_uploadUrls", {
|
|
2430
|
+
jsonBody: createSlotsPayload(files)
|
|
2431
|
+
})
|
|
2432
|
+
);
|
|
2433
|
+
}
|
|
2434
|
+
/**
|
|
2435
|
+
* Fetch one file from a URL and land it as durable context.
|
|
2436
|
+
*
|
|
2437
|
+
* @param url - Source URL to fetch (SSRF-guarded, 50MB cap, same MIME
|
|
2438
|
+
* allow-list as `createUploadUrl`).
|
|
2439
|
+
* @param options.fileName - Override file name. Inferred from the URL path when omitted.
|
|
2440
|
+
* @returns File upload resource with status `processing` — parsing continues async.
|
|
2441
|
+
*/
|
|
2442
|
+
async uploadFromUrl(url, options = {}) {
|
|
2443
|
+
return asRecord(
|
|
2444
|
+
await invokeWithRetry(this.config, this.http, "ContextFilesController_uploadFromUrl", {
|
|
2445
|
+
jsonBody: options.fileName !== void 0 ? { url, fileName: options.fileName } : { url }
|
|
2446
|
+
})
|
|
2447
|
+
);
|
|
2448
|
+
}
|
|
2449
|
+
/**
|
|
2450
|
+
* Fetch up to 100 files from URLs in one call.
|
|
2451
|
+
*
|
|
2452
|
+
* @param urls - URLs to fetch and upload (max 100).
|
|
2453
|
+
* @returns File upload resources for every URL that landed, plus per-index
|
|
2454
|
+
* failures for the rest — never a partial 4xx.
|
|
2455
|
+
*/
|
|
2456
|
+
async uploadFromUrls(urls) {
|
|
2457
|
+
validateBulkSize(urls.length, "urls");
|
|
2458
|
+
return asRecord(
|
|
2459
|
+
await invokeWithRetry(this.config, this.http, "ContextFilesController_uploadFromUrls", {
|
|
2460
|
+
jsonBody: uploadFromUrlsPayload(urls)
|
|
2461
|
+
})
|
|
2462
|
+
);
|
|
2463
|
+
}
|
|
2464
|
+
/**
|
|
2465
|
+
* Fetch one file upload by its id.
|
|
2466
|
+
*
|
|
2467
|
+
* @param uploadId - Upload id returned by `createUploadUrl` / `uploadFromUrl`.
|
|
2468
|
+
* @returns The file upload resource, including its processing `status`.
|
|
2469
|
+
*/
|
|
2470
|
+
async get(uploadId) {
|
|
2471
|
+
validateId(uploadId, "uploadId");
|
|
2472
|
+
return asRecord(
|
|
2473
|
+
await invokeWithRetry(this.config, this.http, "ContextFilesController_get", {
|
|
2474
|
+
pathParams: { uploadId }
|
|
2475
|
+
})
|
|
2476
|
+
);
|
|
2477
|
+
}
|
|
2478
|
+
/**
|
|
2479
|
+
* List durable file uploads.
|
|
2480
|
+
*
|
|
2481
|
+
* @param options.pageSize - Items per page (default 50).
|
|
2482
|
+
* @param options.pageToken - Opaque token from a previous page's `nextPageToken`.
|
|
2483
|
+
* @returns Page of file uploads. Uploads that only have a pending row (not yet
|
|
2484
|
+
* landed) aren't included here — use `get(uploadId)` for those.
|
|
2485
|
+
*/
|
|
2486
|
+
list(options = {}) {
|
|
2487
|
+
const pageSize = options.pageSize ?? DEFAULT_LIST_PAGE_SIZE;
|
|
2488
|
+
validatePageSize(pageSize, 200);
|
|
2489
|
+
return this.listPage(pageSize, options.pageToken);
|
|
2490
|
+
}
|
|
2491
|
+
async listPage(pageSize, pageToken) {
|
|
2492
|
+
const data = asRecord(
|
|
2493
|
+
await invokeWithRetry(this.config, this.http, "ContextFilesController_list", {
|
|
2494
|
+
query: aipListParams(pageSize, pageToken)
|
|
2495
|
+
})
|
|
2496
|
+
);
|
|
2497
|
+
return buildAipPage(data, "files", (raw) => raw, (token) => this.listPage(pageSize, token));
|
|
2498
|
+
}
|
|
2499
|
+
/**
|
|
2500
|
+
* Upload a local file and wait for it to reach `"processing"` or `"ready"`.
|
|
2501
|
+
*
|
|
2502
|
+
* Gets a presigned URL, PUTs the file bytes, then polls `get()` until the
|
|
2503
|
+
* upload leaves `"pending"` (or reaches `"ready"`/`"failed"`).
|
|
2504
|
+
*
|
|
2505
|
+
* @param path - Path to a local file.
|
|
2506
|
+
* @param options.waitUntil - `"processing"` (parsing started, default) or
|
|
2507
|
+
* `"ready"` (parsing finished).
|
|
2508
|
+
* @param options.pollIntervalMs - Milliseconds between status polls.
|
|
2509
|
+
* @param options.timeoutMs - Max milliseconds to wait before raising.
|
|
2510
|
+
* @returns The file upload resource once it reaches `waitUntil` (or `"failed"`).
|
|
2511
|
+
* @throws {ModusError} If the PUT fails, or polling times out.
|
|
2512
|
+
*/
|
|
2513
|
+
async upload(path, options = {}) {
|
|
2514
|
+
const waitUntil = options.waitUntil ?? "processing";
|
|
2515
|
+
validateWaitUntil(waitUntil);
|
|
2516
|
+
const fileStat = await (0, import_promises.stat)(path);
|
|
2517
|
+
if (!fileStat.isFile()) throw new Error(`Not a file: ${path}`);
|
|
2518
|
+
const fileName = path.split(/[/\\]/).pop();
|
|
2519
|
+
const slot = await this.createUploadUrl({
|
|
2520
|
+
fileName,
|
|
2521
|
+
contentType: DEFER_CONTENT_TYPE_TO_SERVER,
|
|
2522
|
+
fileSize: fileStat.size
|
|
2523
|
+
});
|
|
2524
|
+
const data = await (0, import_promises.readFile)(path);
|
|
2525
|
+
await putBytes(this.config.fetch, slot.uploadUrl, data, slot.contentType, DEFAULT_PUT_TIMEOUT_MS);
|
|
2526
|
+
return this.pollUntil(
|
|
2527
|
+
slot.uploadId,
|
|
2528
|
+
waitUntil,
|
|
2529
|
+
options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS,
|
|
2530
|
+
options.timeoutMs ?? DEFAULT_UPLOAD_TIMEOUT_MS
|
|
2531
|
+
);
|
|
2532
|
+
}
|
|
2533
|
+
async pollUntil(uploadId, waitUntil, pollIntervalMs, timeoutMs) {
|
|
2534
|
+
const deadline = Date.now() + timeoutMs;
|
|
2535
|
+
for (; ; ) {
|
|
2536
|
+
const item = await this.get(uploadId);
|
|
2537
|
+
if (statusSatisfies(item.status, waitUntil)) return item;
|
|
2538
|
+
if (Date.now() >= deadline) {
|
|
2539
|
+
throw new ModusError(
|
|
2540
|
+
`Timed out after ${timeoutMs}ms waiting for upload ${JSON.stringify(uploadId)} to reach status ${JSON.stringify(waitUntil)}; last status was ${JSON.stringify(item.status)}.`
|
|
2541
|
+
);
|
|
2542
|
+
}
|
|
2543
|
+
await sleep2(pollIntervalMs);
|
|
2544
|
+
}
|
|
2545
|
+
}
|
|
2546
|
+
/**
|
|
2547
|
+
* Upload every file in a local directory.
|
|
2548
|
+
*
|
|
2549
|
+
* Walks `path` (skipping hidden files/directories and symlinks), pages
|
|
2550
|
+
* through `createUploadUrls()` in batches of up to 100, then PUTs and polls
|
|
2551
|
+
* each file with up to `concurrency` in flight at once. A failure on one
|
|
2552
|
+
* file does not stop the others — check `result.failed`.
|
|
2553
|
+
*
|
|
2554
|
+
* @param path - Path to a local directory.
|
|
2555
|
+
* @param options.recursive - Recurse into subdirectories (default `true`).
|
|
2556
|
+
* @param options.concurrency - Max concurrent PUT+poll operations (default 10).
|
|
2557
|
+
* @param options.waitUntil - `"processing"` (default) or `"ready"` — same as `upload()`.
|
|
2558
|
+
* @returns `UploadDirResult` with every successful `FileUpload` and every
|
|
2559
|
+
* per-file failure (slot creation or PUT/poll), each tagged with its local path.
|
|
2560
|
+
*/
|
|
2561
|
+
async uploadDir(path, options = {}) {
|
|
2562
|
+
const waitUntil = options.waitUntil ?? "processing";
|
|
2563
|
+
validateWaitUntil(waitUntil);
|
|
2564
|
+
const concurrency = options.concurrency ?? DEFAULT_CONCURRENCY;
|
|
2565
|
+
if (concurrency < 1) throw new Error(`concurrency must be >= 1, got ${concurrency}`);
|
|
2566
|
+
const dirStat = await (0, import_promises.stat)(path);
|
|
2567
|
+
if (!dirStat.isDirectory()) throw new Error(`Not a directory: ${path}`);
|
|
2568
|
+
const uploaded = [];
|
|
2569
|
+
const failed = [];
|
|
2570
|
+
const files = await walkFiles(path, options.recursive ?? true);
|
|
2571
|
+
for (const batch of chunked(files, MAX_BULK_UPLOAD_FILES)) {
|
|
2572
|
+
const slots = await this.createSlots(batch, failed);
|
|
2573
|
+
const results = await this.uploadBatch(slots, waitUntil, concurrency);
|
|
2574
|
+
for (const result of results) {
|
|
2575
|
+
if ("error" in result) failed.push(result);
|
|
2576
|
+
else uploaded.push(result);
|
|
2577
|
+
}
|
|
2578
|
+
}
|
|
2579
|
+
return { uploaded, failed };
|
|
2580
|
+
}
|
|
2581
|
+
async createSlots(batch, failed) {
|
|
2582
|
+
const readable = [];
|
|
2583
|
+
const inputs = [];
|
|
2584
|
+
for (const path of batch) {
|
|
2585
|
+
try {
|
|
2586
|
+
const fileStat = await (0, import_promises.stat)(path);
|
|
2587
|
+
const fileName = path.split(/[/\\]/).pop();
|
|
2588
|
+
inputs.push({ fileName, contentType: DEFER_CONTENT_TYPE_TO_SERVER, fileSize: fileStat.size });
|
|
2589
|
+
readable.push(path);
|
|
2590
|
+
} catch (error) {
|
|
2591
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2592
|
+
failed.push({ path, error: message });
|
|
2593
|
+
}
|
|
2594
|
+
}
|
|
2595
|
+
if (inputs.length === 0) return [];
|
|
2596
|
+
const result = await this.createUploadUrls(inputs);
|
|
2597
|
+
return assignSlots(readable, result, failed);
|
|
2598
|
+
}
|
|
2599
|
+
async uploadBatch(slots, waitUntil, concurrency) {
|
|
2600
|
+
if (slots.length === 0) return [];
|
|
2601
|
+
return mapWithConcurrency(slots, concurrency, async ({ path, slot }) => {
|
|
2602
|
+
try {
|
|
2603
|
+
const data = await (0, import_promises.readFile)(path);
|
|
2604
|
+
await putBytes(this.config.fetch, slot.uploadUrl, data, slot.contentType, DEFAULT_PUT_TIMEOUT_MS);
|
|
2605
|
+
return await this.pollUntil(slot.uploadId, waitUntil, DEFAULT_POLL_INTERVAL_MS, DEFAULT_UPLOAD_TIMEOUT_MS);
|
|
2606
|
+
} catch (error) {
|
|
2607
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2608
|
+
return { path, error: message };
|
|
2609
|
+
}
|
|
2610
|
+
});
|
|
2611
|
+
}
|
|
2612
|
+
};
|
|
2613
|
+
|
|
2222
2614
|
// src/management/context/items.ts
|
|
2223
2615
|
function contextListParams(pageSize, pageToken, contextType) {
|
|
2224
2616
|
const extra = {};
|
|
@@ -2329,6 +2721,7 @@ var ManagementContextResource = class {
|
|
|
2329
2721
|
this.config = config;
|
|
2330
2722
|
this.items = new ManagementContextItemsResource(http, config);
|
|
2331
2723
|
this.customItems = new CustomContextItemsResource(http, config);
|
|
2724
|
+
this.files = new ManagementContextFilesResource(http, config);
|
|
2332
2725
|
}
|
|
2333
2726
|
/**
|
|
2334
2727
|
* Add a free-form text note to the knowledge base.
|