@getmodus/sdk 0.5.0 → 0.7.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 +85 -5
- package/README.md +9 -1
- package/dist/{chunk-H76PTY5G.js → chunk-JMFT5KO5.js} +395 -10
- package/dist/chunk-JMFT5KO5.js.map +1 -0
- package/dist/{conversations-Pe3kNikF.d.cts → conversations-B0_jmEuT.d.cts} +11469 -2916
- package/dist/{conversations-Pe3kNikF.d.ts → conversations-B0_jmEuT.d.ts} +11469 -2916
- package/dist/index.cjs +683 -57
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +373 -55
- package/dist/index.d.ts +373 -55
- package/dist/index.js +290 -49
- package/dist/index.js.map +1 -1
- package/dist/management/index.cjs +1538 -55
- package/dist/management/index.cjs.map +1 -1
- package/dist/management/index.d.cts +747 -9
- package/dist/management/index.d.ts +747 -9
- package/dist/management/index.js +1108 -7
- package/dist/management/index.js.map +1 -1
- package/package.json +2 -3
- package/dist/chunk-H76PTY5G.js.map +0 -1
package/dist/management/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CustomContextItemsResource,
|
|
3
3
|
ModusClientBase,
|
|
4
|
+
ModusError,
|
|
4
5
|
ScopeConversationsResource,
|
|
5
6
|
aipListParams,
|
|
6
7
|
asRecord,
|
|
@@ -9,7 +10,7 @@ import {
|
|
|
9
10
|
omitUndefined,
|
|
10
11
|
validateId,
|
|
11
12
|
validatePageSize
|
|
12
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-JMFT5KO5.js";
|
|
13
14
|
|
|
14
15
|
// src/_query.ts
|
|
15
16
|
function updateMaskQuery(updateMask) {
|
|
@@ -160,6 +161,13 @@ var ManagementWorkflowsResource = class {
|
|
|
160
161
|
* @param options.view - Variation view: `"active"` (deployed) or `"draft"`.
|
|
161
162
|
* @param options.includeVariation - Include variation payload on each list row.
|
|
162
163
|
* @returns A page of workflows.
|
|
164
|
+
* @example
|
|
165
|
+
* ```ts
|
|
166
|
+
* const mgmt = new ModusManagement()
|
|
167
|
+
* for await (const wf of (await mgmt.workflows.list({ search: 'digest' })).autoPagingIter()) {
|
|
168
|
+
* console.log(wf.id, wf.name, wf.status)
|
|
169
|
+
* }
|
|
170
|
+
* ```
|
|
163
171
|
*/
|
|
164
172
|
list(options = {}) {
|
|
165
173
|
const pageSize = options.pageSize ?? 25;
|
|
@@ -192,6 +200,12 @@ var ManagementWorkflowsResource = class {
|
|
|
192
200
|
* @param workflowId - Workflow id.
|
|
193
201
|
* @param options.view - Variation view: `"active"` (deployed) or `"draft"`.
|
|
194
202
|
* @returns The workflow.
|
|
203
|
+
* @example
|
|
204
|
+
* ```ts
|
|
205
|
+
* const mgmt = new ModusManagement()
|
|
206
|
+
* const wf = await mgmt.workflows.get('weekly-digest')
|
|
207
|
+
* console.log(wf.name, wf.status)
|
|
208
|
+
* ```
|
|
195
209
|
*/
|
|
196
210
|
async get(workflowId, options = {}) {
|
|
197
211
|
validateId(workflowId, "workflow_id");
|
|
@@ -221,7 +235,8 @@ var ManagementWorkflowsResource = class {
|
|
|
221
235
|
* @returns The created workflow (draft).
|
|
222
236
|
* @example
|
|
223
237
|
* ```ts
|
|
224
|
-
* const
|
|
238
|
+
* const mgmt = new ModusManagement()
|
|
239
|
+
* const wf = await mgmt.workflows.create({ name: 'Daily report', type: 'task' })
|
|
225
240
|
* ```
|
|
226
241
|
*/
|
|
227
242
|
async create(options) {
|
|
@@ -249,6 +264,11 @@ var ManagementWorkflowsResource = class {
|
|
|
249
264
|
* @param options.guardrails - Guardrail labels to set. Fetches the current workflow first to merge. Pass `[]` to clear all.
|
|
250
265
|
* @param options.updateMask - Comma-separated field names to update or clear.
|
|
251
266
|
* @returns The updated workflow.
|
|
267
|
+
* @example
|
|
268
|
+
* ```ts
|
|
269
|
+
* const mgmt = new ModusManagement()
|
|
270
|
+
* const wf = await mgmt.workflows.update('PLACEHOLDER_WORKFLOW_ID', { description: 'Runs every morning' })
|
|
271
|
+
* ```
|
|
252
272
|
*/
|
|
253
273
|
async update(workflowId, options = {}) {
|
|
254
274
|
validateId(workflowId, "workflow_id");
|
|
@@ -284,8 +304,9 @@ var ManagementWorkflowsResource = class {
|
|
|
284
304
|
* @returns The published workflow.
|
|
285
305
|
* @example
|
|
286
306
|
* ```ts
|
|
287
|
-
*
|
|
288
|
-
*
|
|
307
|
+
* const mgmt = new ModusManagement()
|
|
308
|
+
* await mgmt.workflows.update('PLACEHOLDER_WORKFLOW_ID', { description: 'Runs every morning' })
|
|
309
|
+
* const published = await mgmt.workflows.deploy('PLACEHOLDER_WORKFLOW_ID')
|
|
289
310
|
* ```
|
|
290
311
|
*/
|
|
291
312
|
async deploy(workflowId) {
|
|
@@ -318,6 +339,11 @@ var ManagementWorkflowsResource = class {
|
|
|
318
339
|
*
|
|
319
340
|
* @param workflowId - Workflow id.
|
|
320
341
|
* @returns Resolves when the workflow is deleted.
|
|
342
|
+
* @example
|
|
343
|
+
* ```ts
|
|
344
|
+
* const mgmt = new ModusManagement()
|
|
345
|
+
* await mgmt.workflows.delete('PLACEHOLDER_WORKFLOW_ID')
|
|
346
|
+
* ```
|
|
321
347
|
*/
|
|
322
348
|
async delete(workflowId) {
|
|
323
349
|
validateId(workflowId, "workflow_id");
|
|
@@ -471,6 +497,1011 @@ async function resolveAndUpdateLink(items, uid, options) {
|
|
|
471
497
|
});
|
|
472
498
|
}
|
|
473
499
|
|
|
500
|
+
// src/management/context/dashboards.ts
|
|
501
|
+
var ManagementDashboardElementsResource = class {
|
|
502
|
+
/** @internal */
|
|
503
|
+
constructor(http, config, dashboardId) {
|
|
504
|
+
this.http = http;
|
|
505
|
+
this.config = config;
|
|
506
|
+
this.dashboardId = dashboardId;
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* List every tile and filter on the dashboard draft.
|
|
510
|
+
*
|
|
511
|
+
* @returns Each element's id, kind, title and grid position, plus the current
|
|
512
|
+
* `draftRevision` to pass as `expectedRevision` on the next change.
|
|
513
|
+
* @throws NotFoundError - The dashboard does not exist or you cannot edit it.
|
|
514
|
+
* @example
|
|
515
|
+
* ```ts
|
|
516
|
+
* const listed = await mgmt.context.dashboards.elements('DASHBOARD_ID').list()
|
|
517
|
+
* listed.elements.map((element) => element.id)
|
|
518
|
+
* ```
|
|
519
|
+
*/
|
|
520
|
+
async list() {
|
|
521
|
+
return asRecord(
|
|
522
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_listElements", {
|
|
523
|
+
pathParams: { dashboardId: this.dashboardId }
|
|
524
|
+
})
|
|
525
|
+
);
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* Get the full draft settings of one tile or filter.
|
|
529
|
+
*
|
|
530
|
+
* @param elementId - Id of the tile or filter, as returned by `list()`.
|
|
531
|
+
* @returns The element's settings and the current `draftRevision`.
|
|
532
|
+
* @throws NotFoundError - The dashboard or the element does not exist, or you cannot
|
|
533
|
+
* edit the dashboard.
|
|
534
|
+
* @example
|
|
535
|
+
* ```ts
|
|
536
|
+
* const result = await mgmt.context.dashboards.elements('DASHBOARD_ID').get('ELEMENT_ID')
|
|
537
|
+
* result.element.title
|
|
538
|
+
* ```
|
|
539
|
+
*/
|
|
540
|
+
async get(elementId) {
|
|
541
|
+
validateId(elementId, "elementId");
|
|
542
|
+
return asRecord(
|
|
543
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_getElement", {
|
|
544
|
+
pathParams: { dashboardId: this.dashboardId, elementId }
|
|
545
|
+
})
|
|
546
|
+
);
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* Add a blank tile or filter to the dashboard draft.
|
|
550
|
+
*
|
|
551
|
+
* Modus assigns the new element's id; configure it afterwards with `update()`.
|
|
552
|
+
*
|
|
553
|
+
* @param input.expectedRevision - The `draftRevision` your change is based on.
|
|
554
|
+
* @param input.kind - `chart`, `kpi`, `table`, `markdown` or `filter`.
|
|
555
|
+
* @param input.title - Title shown on the element.
|
|
556
|
+
* @param input.layout - Grid position with `x` (0-11), `y`, `w` (1-12) and `h`.
|
|
557
|
+
* @returns The created element and the new `draftRevision`.
|
|
558
|
+
* @throws ConflictError - The draft changed since `expectedRevision`; list the
|
|
559
|
+
* elements again and retry with the new revision.
|
|
560
|
+
* @example
|
|
561
|
+
* ```ts
|
|
562
|
+
* const created = await mgmt.context.dashboards.elements('DASHBOARD_ID').create({
|
|
563
|
+
* expectedRevision: 3,
|
|
564
|
+
* kind: 'chart',
|
|
565
|
+
* title: 'Sales by region',
|
|
566
|
+
* layout: { x: 0, y: 4, w: 6, h: 4 },
|
|
567
|
+
* })
|
|
568
|
+
* ```
|
|
569
|
+
*/
|
|
570
|
+
async create(input) {
|
|
571
|
+
return asRecord(
|
|
572
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_createElement", {
|
|
573
|
+
pathParams: { dashboardId: this.dashboardId },
|
|
574
|
+
jsonBody: {
|
|
575
|
+
expectedRevision: input.expectedRevision,
|
|
576
|
+
kind: input.kind,
|
|
577
|
+
title: input.title,
|
|
578
|
+
layout: input.layout
|
|
579
|
+
}
|
|
580
|
+
})
|
|
581
|
+
);
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Change settings of one tile or filter on the dashboard draft.
|
|
585
|
+
*
|
|
586
|
+
* @param elementId - Id of the tile or filter to change.
|
|
587
|
+
* @param input.expectedRevision - The `draftRevision` your change is based on.
|
|
588
|
+
* @param input.patch - The settings to change, for example `{ title: 'Sales' }`
|
|
589
|
+
* or `{ defaultValue: null }`. `null` clears a setting that supports clearing.
|
|
590
|
+
* @returns The whole dashboard after the change, including the new `draftRevision`.
|
|
591
|
+
* @throws ConflictError - The draft changed since `expectedRevision`.
|
|
592
|
+
* @throws NotFoundError - The dashboard or the element does not exist, or you cannot
|
|
593
|
+
* edit the dashboard.
|
|
594
|
+
* @example
|
|
595
|
+
* ```ts
|
|
596
|
+
* const dashboard = await mgmt.context.dashboards
|
|
597
|
+
* .elements('DASHBOARD_ID')
|
|
598
|
+
* .update('ELEMENT_ID', { expectedRevision: 3, patch: { title: 'Revenue' } })
|
|
599
|
+
* ```
|
|
600
|
+
*/
|
|
601
|
+
async update(elementId, input) {
|
|
602
|
+
validateId(elementId, "elementId");
|
|
603
|
+
return asRecord(
|
|
604
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_updateElement", {
|
|
605
|
+
pathParams: { dashboardId: this.dashboardId, elementId },
|
|
606
|
+
jsonBody: { expectedRevision: input.expectedRevision, patch: input.patch }
|
|
607
|
+
})
|
|
608
|
+
);
|
|
609
|
+
}
|
|
610
|
+
};
|
|
611
|
+
var ManagementDashboardsResource = class {
|
|
612
|
+
/** @internal */
|
|
613
|
+
constructor(http, config) {
|
|
614
|
+
this.http = http;
|
|
615
|
+
this.config = config;
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* List dashboards with their full definitions.
|
|
619
|
+
*
|
|
620
|
+
* @param options.view - `active` (default) lists published dashboards you can open;
|
|
621
|
+
* `draft` lists the drafts of dashboards you can edit.
|
|
622
|
+
* @returns Every matching dashboard. The list is not paginated.
|
|
623
|
+
* @example
|
|
624
|
+
* ```ts
|
|
625
|
+
* const drafts = await mgmt.context.dashboards.list({ view: 'draft' })
|
|
626
|
+
* drafts.map((dashboard) => [dashboard.id, dashboard.draftRevision])
|
|
627
|
+
* ```
|
|
628
|
+
*/
|
|
629
|
+
async list(options = {}) {
|
|
630
|
+
const data = asRecord(
|
|
631
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_list", {
|
|
632
|
+
query: { view: options.view }
|
|
633
|
+
})
|
|
634
|
+
);
|
|
635
|
+
return data.dashboards;
|
|
636
|
+
}
|
|
637
|
+
/**
|
|
638
|
+
* Get one dashboard with its full definition.
|
|
639
|
+
*
|
|
640
|
+
* @param dashboardId - Id of the dashboard.
|
|
641
|
+
* @param options.view - `active` (default) returns the published version; `draft`
|
|
642
|
+
* returns the working draft and requires edit access.
|
|
643
|
+
* @returns The dashboard, including `draftRevision` for the next change.
|
|
644
|
+
* @throws NotFoundError - The dashboard does not exist or you cannot open it.
|
|
645
|
+
* @example
|
|
646
|
+
* ```ts
|
|
647
|
+
* const draft = await mgmt.context.dashboards.get('DASHBOARD_ID', { view: 'draft' })
|
|
648
|
+
* draft.draftRevision
|
|
649
|
+
* ```
|
|
650
|
+
*/
|
|
651
|
+
async get(dashboardId, options = {}) {
|
|
652
|
+
validateId(dashboardId, "dashboardId");
|
|
653
|
+
return asRecord(
|
|
654
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_get", {
|
|
655
|
+
pathParams: { dashboardId },
|
|
656
|
+
query: { view: options.view }
|
|
657
|
+
})
|
|
658
|
+
);
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* Create a dashboard draft.
|
|
662
|
+
*
|
|
663
|
+
* The new dashboard is not visible to others until you `publish()` it.
|
|
664
|
+
*
|
|
665
|
+
* @param input.title - Dashboard title.
|
|
666
|
+
* @param input.definition - Tiles, filters and layout, for example
|
|
667
|
+
* `{ tiles: [], filters: [] }`. Element ids must be unique.
|
|
668
|
+
* @param input.description - Optional dashboard description.
|
|
669
|
+
* @param input.access - Optional `visibility`, `groupPermissions` and `sharedWith`.
|
|
670
|
+
* Defaults to private.
|
|
671
|
+
* @returns The created dashboard in its draft view.
|
|
672
|
+
* @throws ModusError - The definition or access settings are invalid.
|
|
673
|
+
* @example
|
|
674
|
+
* ```ts
|
|
675
|
+
* const dashboard = await mgmt.context.dashboards.create({
|
|
676
|
+
* title: 'Revenue',
|
|
677
|
+
* definition: { tiles: [], filters: [] },
|
|
678
|
+
* })
|
|
679
|
+
* dashboard.id
|
|
680
|
+
* ```
|
|
681
|
+
*/
|
|
682
|
+
async create(input) {
|
|
683
|
+
return asRecord(
|
|
684
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_create", {
|
|
685
|
+
jsonBody: {
|
|
686
|
+
title: input.title,
|
|
687
|
+
description: input.description,
|
|
688
|
+
definition: input.definition,
|
|
689
|
+
access: input.access
|
|
690
|
+
}
|
|
691
|
+
})
|
|
692
|
+
);
|
|
693
|
+
}
|
|
694
|
+
/**
|
|
695
|
+
* Replace the whole draft definition, and optionally the title and description.
|
|
696
|
+
*
|
|
697
|
+
* @param dashboardId - Id of the dashboard.
|
|
698
|
+
* @param input.expectedRevision - The `draftRevision` your change is based on.
|
|
699
|
+
* @param input.definition - The complete new definition. Tiles and filters left
|
|
700
|
+
* out are removed.
|
|
701
|
+
* @param input.title - New title; unchanged when omitted.
|
|
702
|
+
* @param input.description - New description; unchanged when omitted.
|
|
703
|
+
* @returns The dashboard draft after the change, including the new `draftRevision`.
|
|
704
|
+
* @throws ConflictError - The draft changed since `expectedRevision`; get the draft
|
|
705
|
+
* again and retry with the new revision.
|
|
706
|
+
* @throws NotFoundError - The dashboard does not exist or you cannot edit it.
|
|
707
|
+
* @example
|
|
708
|
+
* ```ts
|
|
709
|
+
* const draft = await mgmt.context.dashboards.get('DASHBOARD_ID', { view: 'draft' })
|
|
710
|
+
* await mgmt.context.dashboards.updateDraft('DASHBOARD_ID', {
|
|
711
|
+
* expectedRevision: draft.draftRevision,
|
|
712
|
+
* definition: draft.definition,
|
|
713
|
+
* title: 'Revenue',
|
|
714
|
+
* })
|
|
715
|
+
* ```
|
|
716
|
+
*/
|
|
717
|
+
async updateDraft(dashboardId, input) {
|
|
718
|
+
validateId(dashboardId, "dashboardId");
|
|
719
|
+
return asRecord(
|
|
720
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_updateDraft", {
|
|
721
|
+
pathParams: { dashboardId },
|
|
722
|
+
jsonBody: {
|
|
723
|
+
expectedRevision: input.expectedRevision,
|
|
724
|
+
title: input.title,
|
|
725
|
+
description: input.description,
|
|
726
|
+
definition: input.definition
|
|
727
|
+
}
|
|
728
|
+
})
|
|
729
|
+
);
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* Publish the draft as a new version that everyone with access sees.
|
|
733
|
+
*
|
|
734
|
+
* Alert workflows defined on the dashboard are updated to match.
|
|
735
|
+
*
|
|
736
|
+
* @param dashboardId - Id of the dashboard.
|
|
737
|
+
* @param input.expectedRevision - The `draftRevision` you reviewed and want to publish.
|
|
738
|
+
* @returns The published `dashboard` and the new `version`.
|
|
739
|
+
* @throws ConflictError - The draft changed since `expectedRevision`.
|
|
740
|
+
* @throws NotFoundError - The dashboard does not exist or you cannot edit it.
|
|
741
|
+
* @example
|
|
742
|
+
* ```ts
|
|
743
|
+
* const result = await mgmt.context.dashboards.publish('DASHBOARD_ID', { expectedRevision: 4 })
|
|
744
|
+
* result.version.versionNumber
|
|
745
|
+
* ```
|
|
746
|
+
*/
|
|
747
|
+
async publish(dashboardId, input) {
|
|
748
|
+
validateId(dashboardId, "dashboardId");
|
|
749
|
+
return asRecord(
|
|
750
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_publish", {
|
|
751
|
+
pathParams: { dashboardId },
|
|
752
|
+
jsonBody: { expectedRevision: input.expectedRevision }
|
|
753
|
+
})
|
|
754
|
+
);
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* Delete a dashboard and the alert workflows defined on it.
|
|
758
|
+
*
|
|
759
|
+
* A deleted dashboard cannot be restored.
|
|
760
|
+
*
|
|
761
|
+
* @param dashboardId - Id of the dashboard.
|
|
762
|
+
* @throws NotFoundError - The dashboard does not exist or you cannot edit it.
|
|
763
|
+
* @example
|
|
764
|
+
* ```ts
|
|
765
|
+
* await mgmt.context.dashboards.delete('DASHBOARD_ID')
|
|
766
|
+
* ```
|
|
767
|
+
*/
|
|
768
|
+
async delete(dashboardId) {
|
|
769
|
+
validateId(dashboardId, "dashboardId");
|
|
770
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_delete", {
|
|
771
|
+
pathParams: { dashboardId }
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
/**
|
|
775
|
+
* List the published versions of a dashboard, newest first.
|
|
776
|
+
*
|
|
777
|
+
* @param dashboardId - Id of the dashboard.
|
|
778
|
+
* @returns Every published version with its full definition. Definitions are
|
|
779
|
+
* returned as stored, so older versions may lack newer fields. The list is
|
|
780
|
+
* not paginated.
|
|
781
|
+
* @throws NotFoundError - The dashboard does not exist or you cannot open it.
|
|
782
|
+
* @example
|
|
783
|
+
* ```ts
|
|
784
|
+
* const versions = await mgmt.context.dashboards.listVersions('DASHBOARD_ID')
|
|
785
|
+
* versions.map((version) => [version.uid, version.versionNumber])
|
|
786
|
+
* ```
|
|
787
|
+
*/
|
|
788
|
+
async listVersions(dashboardId) {
|
|
789
|
+
validateId(dashboardId, "dashboardId");
|
|
790
|
+
const data = asRecord(
|
|
791
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_listVersions", {
|
|
792
|
+
pathParams: { dashboardId }
|
|
793
|
+
})
|
|
794
|
+
);
|
|
795
|
+
return data.versions;
|
|
796
|
+
}
|
|
797
|
+
/**
|
|
798
|
+
* Get a dashboard as it was in one version.
|
|
799
|
+
*
|
|
800
|
+
* @param dashboardId - Id of the dashboard.
|
|
801
|
+
* @param versionId - Id of the version, as returned by `listVersions()`.
|
|
802
|
+
* @returns The dashboard with that version's definition.
|
|
803
|
+
* @throws NotFoundError - The dashboard or the version does not exist, or you cannot
|
|
804
|
+
* open the dashboard.
|
|
805
|
+
* @example
|
|
806
|
+
* ```ts
|
|
807
|
+
* const old = await mgmt.context.dashboards.getVersion('DASHBOARD_ID', 'VERSION_ID')
|
|
808
|
+
* old.selectedVersion.versionNumber
|
|
809
|
+
* ```
|
|
810
|
+
*/
|
|
811
|
+
async getVersion(dashboardId, versionId) {
|
|
812
|
+
validateId(dashboardId, "dashboardId");
|
|
813
|
+
validateId(versionId, "versionId");
|
|
814
|
+
return asRecord(
|
|
815
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_getVersion", {
|
|
816
|
+
pathParams: { dashboardId, versionId }
|
|
817
|
+
})
|
|
818
|
+
);
|
|
819
|
+
}
|
|
820
|
+
/**
|
|
821
|
+
* Replace the draft with the content of an earlier version.
|
|
822
|
+
*
|
|
823
|
+
* The draft being replaced is kept as a draft snapshot. Call `publish()`
|
|
824
|
+
* afterwards to make the restored content visible.
|
|
825
|
+
*
|
|
826
|
+
* @param dashboardId - Id of the dashboard.
|
|
827
|
+
* @param versionId - Id of the version or draft snapshot to restore.
|
|
828
|
+
* @returns The dashboard draft after the restore.
|
|
829
|
+
* @throws NotFoundError - The dashboard or the version does not exist, or you cannot
|
|
830
|
+
* edit the dashboard.
|
|
831
|
+
* @example
|
|
832
|
+
* ```ts
|
|
833
|
+
* await mgmt.context.dashboards.restoreVersion('DASHBOARD_ID', 'VERSION_ID')
|
|
834
|
+
* ```
|
|
835
|
+
*/
|
|
836
|
+
async restoreVersion(dashboardId, versionId) {
|
|
837
|
+
validateId(dashboardId, "dashboardId");
|
|
838
|
+
validateId(versionId, "versionId");
|
|
839
|
+
return asRecord(
|
|
840
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_restore", {
|
|
841
|
+
pathParams: { dashboardId, versionId }
|
|
842
|
+
})
|
|
843
|
+
);
|
|
844
|
+
}
|
|
845
|
+
/**
|
|
846
|
+
* List recent snapshots of the dashboard draft, newest first.
|
|
847
|
+
*
|
|
848
|
+
* @param dashboardId - Id of the dashboard.
|
|
849
|
+
* @returns Up to 100 snapshots with their id, author and time. Pass an id to
|
|
850
|
+
* `restoreVersion()` to bring that draft back.
|
|
851
|
+
* @throws NotFoundError - The dashboard does not exist or you cannot edit it.
|
|
852
|
+
* @example
|
|
853
|
+
* ```ts
|
|
854
|
+
* const snapshots = await mgmt.context.dashboards.listDraftSnapshots('DASHBOARD_ID')
|
|
855
|
+
* snapshots.map((snapshot) => snapshot.uid)
|
|
856
|
+
* ```
|
|
857
|
+
*/
|
|
858
|
+
async listDraftSnapshots(dashboardId) {
|
|
859
|
+
validateId(dashboardId, "dashboardId");
|
|
860
|
+
const data = asRecord(
|
|
861
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_listDraftSnapshots", {
|
|
862
|
+
pathParams: { dashboardId }
|
|
863
|
+
})
|
|
864
|
+
);
|
|
865
|
+
return data.snapshots;
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* Replace who can open and edit a dashboard.
|
|
869
|
+
*
|
|
870
|
+
* All three settings are required and replace the current ones.
|
|
871
|
+
*
|
|
872
|
+
* @param dashboardId - Id of the dashboard.
|
|
873
|
+
* @param input.visibility - `shared` (the owner plus the groups in
|
|
874
|
+
* `groupPermissions`) or `private` (the owner plus the users in `sharedWith`).
|
|
875
|
+
* @param input.groupPermissions - Group id to `{ use, manage }`. Used only when shared.
|
|
876
|
+
* @param input.sharedWith - Users such as `{ email: 'ana@example.com', permission: 'use' }`.
|
|
877
|
+
* Used only when private.
|
|
878
|
+
* @returns The dashboard with its new access settings.
|
|
879
|
+
* @throws NotFoundError - The dashboard does not exist or you cannot edit it.
|
|
880
|
+
* @throws ModusError - A group, user or permission is invalid.
|
|
881
|
+
* @example
|
|
882
|
+
* ```ts
|
|
883
|
+
* await mgmt.context.dashboards.updateAccess('DASHBOARD_ID', {
|
|
884
|
+
* visibility: 'private',
|
|
885
|
+
* groupPermissions: {},
|
|
886
|
+
* sharedWith: [{ email: 'ana@example.com', permission: 'use' }],
|
|
887
|
+
* })
|
|
888
|
+
* ```
|
|
889
|
+
*/
|
|
890
|
+
async updateAccess(dashboardId, input) {
|
|
891
|
+
validateId(dashboardId, "dashboardId");
|
|
892
|
+
return asRecord(
|
|
893
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_updateAccess", {
|
|
894
|
+
pathParams: { dashboardId },
|
|
895
|
+
jsonBody: {
|
|
896
|
+
visibility: input.visibility,
|
|
897
|
+
groupPermissions: input.groupPermissions,
|
|
898
|
+
sharedWith: input.sharedWith
|
|
899
|
+
}
|
|
900
|
+
})
|
|
901
|
+
);
|
|
902
|
+
}
|
|
903
|
+
/**
|
|
904
|
+
* Ask another member of your organization to take ownership of a dashboard.
|
|
905
|
+
*
|
|
906
|
+
* Only the owner can request a transfer. Ownership moves when the recipient
|
|
907
|
+
* calls `acceptOwnershipTransfer()`.
|
|
908
|
+
*
|
|
909
|
+
* @param dashboardId - Id of the dashboard.
|
|
910
|
+
* @param input.newOwnerUserId - User id of the member who should become the owner.
|
|
911
|
+
* @returns The dashboard with `pendingOwnershipTransfer` set.
|
|
912
|
+
* @throws PermissionDeniedError - You are not the owner.
|
|
913
|
+
* @throws NotFoundError - The dashboard does not exist or you cannot open it.
|
|
914
|
+
* @example
|
|
915
|
+
* ```ts
|
|
916
|
+
* await mgmt.context.dashboards.requestOwnershipTransfer('DASHBOARD_ID', {
|
|
917
|
+
* newOwnerUserId: 'USER_ID',
|
|
918
|
+
* })
|
|
919
|
+
* ```
|
|
920
|
+
*/
|
|
921
|
+
async requestOwnershipTransfer(dashboardId, input) {
|
|
922
|
+
validateId(dashboardId, "dashboardId");
|
|
923
|
+
validateId(input.newOwnerUserId, "newOwnerUserId");
|
|
924
|
+
return asRecord(
|
|
925
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_transferOwnership", {
|
|
926
|
+
pathParams: { dashboardId },
|
|
927
|
+
jsonBody: { newOwnerUserId: input.newOwnerUserId }
|
|
928
|
+
})
|
|
929
|
+
);
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
* Accept a pending ownership transfer and become the dashboard owner.
|
|
933
|
+
*
|
|
934
|
+
* Only the requested recipient can accept.
|
|
935
|
+
*
|
|
936
|
+
* @param dashboardId - Id of the dashboard.
|
|
937
|
+
* @returns The dashboard with you as its owner.
|
|
938
|
+
* @throws NotFoundError - The dashboard does not exist, or it has no pending transfer
|
|
939
|
+
* addressed to you.
|
|
940
|
+
* @example
|
|
941
|
+
* ```ts
|
|
942
|
+
* await mgmt.context.dashboards.acceptOwnershipTransfer('DASHBOARD_ID')
|
|
943
|
+
* ```
|
|
944
|
+
*/
|
|
945
|
+
async acceptOwnershipTransfer(dashboardId) {
|
|
946
|
+
validateId(dashboardId, "dashboardId");
|
|
947
|
+
return asRecord(
|
|
948
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_acceptOwnership", {
|
|
949
|
+
pathParams: { dashboardId }
|
|
950
|
+
})
|
|
951
|
+
);
|
|
952
|
+
}
|
|
953
|
+
/**
|
|
954
|
+
* Cancel a pending ownership transfer.
|
|
955
|
+
*
|
|
956
|
+
* Only the owner can cancel.
|
|
957
|
+
*
|
|
958
|
+
* @param dashboardId - Id of the dashboard.
|
|
959
|
+
* @returns The dashboard with no pending transfer.
|
|
960
|
+
* @throws NotFoundError - The dashboard does not exist, you cannot open it, or you are
|
|
961
|
+
* not the owner.
|
|
962
|
+
* @example
|
|
963
|
+
* ```ts
|
|
964
|
+
* await mgmt.context.dashboards.cancelOwnershipTransfer('DASHBOARD_ID')
|
|
965
|
+
* ```
|
|
966
|
+
*/
|
|
967
|
+
async cancelOwnershipTransfer(dashboardId) {
|
|
968
|
+
validateId(dashboardId, "dashboardId");
|
|
969
|
+
return asRecord(
|
|
970
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_cancelOwnership", {
|
|
971
|
+
pathParams: { dashboardId }
|
|
972
|
+
})
|
|
973
|
+
);
|
|
974
|
+
}
|
|
975
|
+
/**
|
|
976
|
+
* Work with the tiles and filters of one dashboard draft.
|
|
977
|
+
*
|
|
978
|
+
* @param dashboardId - Id of the dashboard.
|
|
979
|
+
* @returns A resource bound to that dashboard.
|
|
980
|
+
* @example
|
|
981
|
+
* ```ts
|
|
982
|
+
* await mgmt.context.dashboards.elements('DASHBOARD_ID').list()
|
|
983
|
+
* ```
|
|
984
|
+
*/
|
|
985
|
+
elements(dashboardId) {
|
|
986
|
+
validateId(dashboardId, "dashboardId");
|
|
987
|
+
return new ManagementDashboardElementsResource(this.http, this.config, dashboardId);
|
|
988
|
+
}
|
|
989
|
+
/**
|
|
990
|
+
* Move or resize several tiles and filters in one change.
|
|
991
|
+
*
|
|
992
|
+
* @param dashboardId - Id of the dashboard.
|
|
993
|
+
* @param input.expectedRevision - The `draftRevision` your change is based on.
|
|
994
|
+
* @param input.elements - Every element to place, each with `elementId` and its
|
|
995
|
+
* final `layout`.
|
|
996
|
+
* @returns The whole dashboard after the change, including the new `draftRevision`.
|
|
997
|
+
* @throws ConflictError - The draft changed since `expectedRevision`.
|
|
998
|
+
* @example
|
|
999
|
+
* ```ts
|
|
1000
|
+
* await mgmt.context.dashboards.updateLayout('DASHBOARD_ID', {
|
|
1001
|
+
* expectedRevision: 3,
|
|
1002
|
+
* elements: [{ elementId: 'ELEMENT_ID', layout: { x: 0, y: 0, w: 12, h: 2 } }],
|
|
1003
|
+
* })
|
|
1004
|
+
* ```
|
|
1005
|
+
*/
|
|
1006
|
+
async updateLayout(dashboardId, input) {
|
|
1007
|
+
validateId(dashboardId, "dashboardId");
|
|
1008
|
+
return asRecord(
|
|
1009
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_updateLayout", {
|
|
1010
|
+
pathParams: { dashboardId },
|
|
1011
|
+
jsonBody: { expectedRevision: input.expectedRevision, elements: input.elements }
|
|
1012
|
+
})
|
|
1013
|
+
);
|
|
1014
|
+
}
|
|
1015
|
+
};
|
|
1016
|
+
|
|
1017
|
+
// src/management/context/files.ts
|
|
1018
|
+
import { readdir, readFile, stat } from "fs/promises";
|
|
1019
|
+
import { dirname, join, relative } from "path";
|
|
1020
|
+
var MAX_BULK_UPLOAD_FILES = 100;
|
|
1021
|
+
var DEFAULT_LIST_PAGE_SIZE = 50;
|
|
1022
|
+
var DEFAULT_PUT_TIMEOUT_MS = 6e4;
|
|
1023
|
+
var DEFAULT_POLL_INTERVAL_MS = 500;
|
|
1024
|
+
var DEFAULT_UPLOAD_TIMEOUT_MS = 12e4;
|
|
1025
|
+
var DEFAULT_CONCURRENCY = 10;
|
|
1026
|
+
var STATUS_ORDER = { pending: 0, processing: 1, ready: 2 };
|
|
1027
|
+
var WAIT_UNTIL_VALUES = /* @__PURE__ */ new Set(["processing", "ready"]);
|
|
1028
|
+
var DEFER_CONTENT_TYPE_TO_SERVER = "application/octet-stream";
|
|
1029
|
+
function validateWaitUntil(waitUntil) {
|
|
1030
|
+
if (!WAIT_UNTIL_VALUES.has(waitUntil)) {
|
|
1031
|
+
throw new Error(`waitUntil must be one of ${[...WAIT_UNTIL_VALUES].join(", ")}, got ${waitUntil}`);
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
function validateBulkSize(count, name) {
|
|
1035
|
+
if (count === 0) throw new Error(`${name} must not be empty`);
|
|
1036
|
+
if (count > MAX_BULK_UPLOAD_FILES) {
|
|
1037
|
+
throw new Error(`${name} must have at most ${MAX_BULK_UPLOAD_FILES} entries, got ${count}`);
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
function statusSatisfies(status, waitUntil) {
|
|
1041
|
+
if (status === "failed") return true;
|
|
1042
|
+
return (STATUS_ORDER[status] ?? 0) >= STATUS_ORDER[waitUntil];
|
|
1043
|
+
}
|
|
1044
|
+
function sleep(ms) {
|
|
1045
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
1046
|
+
}
|
|
1047
|
+
function chunked(items, size) {
|
|
1048
|
+
const out = [];
|
|
1049
|
+
for (let i = 0; i < items.length; i += size) out.push(items.slice(i, i + size));
|
|
1050
|
+
return out;
|
|
1051
|
+
}
|
|
1052
|
+
async function mapWithConcurrency(items, concurrency, worker, onItemDone) {
|
|
1053
|
+
const results = new Array(items.length);
|
|
1054
|
+
let cursor = 0;
|
|
1055
|
+
async function run() {
|
|
1056
|
+
for (; ; ) {
|
|
1057
|
+
const index = cursor++;
|
|
1058
|
+
if (index >= items.length) return;
|
|
1059
|
+
const result = await worker(items[index]);
|
|
1060
|
+
results[index] = result;
|
|
1061
|
+
onItemDone?.(result);
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
await Promise.all(Array.from({ length: Math.min(concurrency, items.length) }, run));
|
|
1065
|
+
return results;
|
|
1066
|
+
}
|
|
1067
|
+
async function walkFiles(root, recursive) {
|
|
1068
|
+
const out = [];
|
|
1069
|
+
async function walk(dir) {
|
|
1070
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
1071
|
+
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
1072
|
+
for (const entry of entries) {
|
|
1073
|
+
if (entry.name.startsWith(".") || entry.isSymbolicLink()) continue;
|
|
1074
|
+
const full = join(dir, entry.name);
|
|
1075
|
+
if (entry.isDirectory()) {
|
|
1076
|
+
if (recursive) await walk(full);
|
|
1077
|
+
} else if (entry.isFile()) {
|
|
1078
|
+
out.push(full);
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
await walk(root);
|
|
1083
|
+
return out;
|
|
1084
|
+
}
|
|
1085
|
+
async function putBytes(fetchImpl, url, data, contentType, timeoutMs) {
|
|
1086
|
+
const response = await fetchImpl(url, {
|
|
1087
|
+
method: "PUT",
|
|
1088
|
+
body: data,
|
|
1089
|
+
headers: { "Content-Type": contentType },
|
|
1090
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
1091
|
+
});
|
|
1092
|
+
if (!response.ok) {
|
|
1093
|
+
const text = await response.text().catch(() => "");
|
|
1094
|
+
throw new ModusError(`Upload PUT to presigned URL failed with HTTP ${response.status}.`, {
|
|
1095
|
+
statusCode: response.status,
|
|
1096
|
+
body: text ? text.slice(0, 500) : void 0
|
|
1097
|
+
});
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
function createSlotsPayload(files) {
|
|
1101
|
+
return {
|
|
1102
|
+
files: files.map((f) => ({ fileName: f.fileName, contentType: f.contentType, fileSize: f.fileSize }))
|
|
1103
|
+
};
|
|
1104
|
+
}
|
|
1105
|
+
function uploadFromUrlsPayload(urls) {
|
|
1106
|
+
return {
|
|
1107
|
+
urls: urls.map((u) => ({
|
|
1108
|
+
url: u.url,
|
|
1109
|
+
...u.fileName !== void 0 ? { fileName: u.fileName } : {},
|
|
1110
|
+
...u.folderPath !== void 0 ? { folderPath: u.folderPath } : {}
|
|
1111
|
+
}))
|
|
1112
|
+
};
|
|
1113
|
+
}
|
|
1114
|
+
function assignSlots(batch, result, failed) {
|
|
1115
|
+
const failedIndices = new Set(result.failed.map((f) => f.index));
|
|
1116
|
+
for (const f of result.failed) {
|
|
1117
|
+
failed.push({ path: batch[f.index]?.path ?? "", error: f.error });
|
|
1118
|
+
}
|
|
1119
|
+
const remaining = batch.filter((_, i) => !failedIndices.has(i));
|
|
1120
|
+
const uploaded = result.uploaded;
|
|
1121
|
+
if (uploaded.length < remaining.length) {
|
|
1122
|
+
for (const file of remaining.slice(uploaded.length)) {
|
|
1123
|
+
failed.push({ path: file.path, error: "Server returned fewer upload slots than requested files." });
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
const paired = Math.min(remaining.length, uploaded.length);
|
|
1127
|
+
const assignments = [];
|
|
1128
|
+
for (let i = 0; i < paired; i++) {
|
|
1129
|
+
assignments.push({ ...remaining[i], slot: uploaded[i] });
|
|
1130
|
+
}
|
|
1131
|
+
return assignments;
|
|
1132
|
+
}
|
|
1133
|
+
var ManagementContextFilesResource = class {
|
|
1134
|
+
/** @internal */
|
|
1135
|
+
constructor(http, config) {
|
|
1136
|
+
this.http = http;
|
|
1137
|
+
this.config = config;
|
|
1138
|
+
}
|
|
1139
|
+
/**
|
|
1140
|
+
* Get a presigned S3 PUT URL for one file.
|
|
1141
|
+
*
|
|
1142
|
+
* @param input.fileName - Original file name — used to build the S3 object key.
|
|
1143
|
+
* @param input.contentType - MIME type. Allowed categories: PDF, images, text,
|
|
1144
|
+
* Office/OpenDocument documents, audio, and video.
|
|
1145
|
+
* @param input.fileSize - File size in bytes. Rejected above 50MB.
|
|
1146
|
+
* @returns Presigned upload slot. PUT the raw bytes to `uploadUrl` within 15
|
|
1147
|
+
* minutes, then call `finalize(slot.uploadId, slot.fileName)`. Pass the
|
|
1148
|
+
* slot's own `fileName` rather than your local basename — the server may
|
|
1149
|
+
* sanitize the requested name when it mints the key, and finalization
|
|
1150
|
+
* re-derives the key from `uploadId` and `fileName`.
|
|
1151
|
+
*/
|
|
1152
|
+
async createUploadUrl(input) {
|
|
1153
|
+
return asRecord(
|
|
1154
|
+
await invokeWithRetry(this.config, this.http, "ContextFilesController_uploadUrl", {
|
|
1155
|
+
jsonBody: { fileName: input.fileName, contentType: input.contentType, fileSize: input.fileSize }
|
|
1156
|
+
})
|
|
1157
|
+
);
|
|
1158
|
+
}
|
|
1159
|
+
/**
|
|
1160
|
+
* Get presigned S3 PUT URLs for up to 100 files in one call.
|
|
1161
|
+
*
|
|
1162
|
+
* @param files - Files to create upload slots for (max 100).
|
|
1163
|
+
* @returns Slots for every file that passed validation, plus per-index
|
|
1164
|
+
* failures (bad MIME type, oversize) for the rest — never a partial 4xx.
|
|
1165
|
+
*/
|
|
1166
|
+
async createUploadUrls(files) {
|
|
1167
|
+
validateBulkSize(files.length, "files");
|
|
1168
|
+
return asRecord(
|
|
1169
|
+
await invokeWithRetry(this.config, this.http, "ContextFilesController_uploadUrls", {
|
|
1170
|
+
jsonBody: createSlotsPayload(files)
|
|
1171
|
+
})
|
|
1172
|
+
);
|
|
1173
|
+
}
|
|
1174
|
+
/**
|
|
1175
|
+
* Fetch one file from a URL and land it as durable context.
|
|
1176
|
+
*
|
|
1177
|
+
* @param url - Source URL to fetch (SSRF-guarded, 50MB cap, same MIME
|
|
1178
|
+
* allow-list as `createUploadUrl`).
|
|
1179
|
+
* @param options.fileName - Override file name. Inferred from the URL path when omitted.
|
|
1180
|
+
* @returns File upload resource with status `processing` — parsing continues async.
|
|
1181
|
+
*/
|
|
1182
|
+
async uploadFromUrl(url, options = {}) {
|
|
1183
|
+
return asRecord(
|
|
1184
|
+
await invokeWithRetry(this.config, this.http, "ContextFilesController_uploadFromUrl", {
|
|
1185
|
+
jsonBody: {
|
|
1186
|
+
url,
|
|
1187
|
+
...options.fileName !== void 0 ? { fileName: options.fileName } : {},
|
|
1188
|
+
...options.folderPath !== void 0 ? { folderPath: options.folderPath } : {}
|
|
1189
|
+
}
|
|
1190
|
+
})
|
|
1191
|
+
);
|
|
1192
|
+
}
|
|
1193
|
+
/**
|
|
1194
|
+
* Fetch up to 100 files from URLs in one call.
|
|
1195
|
+
*
|
|
1196
|
+
* @param urls - URLs to fetch and upload (max 100).
|
|
1197
|
+
* @returns File upload resources for every URL that landed, plus per-index
|
|
1198
|
+
* failures for the rest — never a partial 4xx.
|
|
1199
|
+
*/
|
|
1200
|
+
async uploadFromUrls(urls) {
|
|
1201
|
+
validateBulkSize(urls.length, "urls");
|
|
1202
|
+
return asRecord(
|
|
1203
|
+
await invokeWithRetry(this.config, this.http, "ContextFilesController_uploadFromUrls", {
|
|
1204
|
+
jsonBody: uploadFromUrlsPayload(urls)
|
|
1205
|
+
})
|
|
1206
|
+
);
|
|
1207
|
+
}
|
|
1208
|
+
/**
|
|
1209
|
+
* Fetch one file upload by its id.
|
|
1210
|
+
*
|
|
1211
|
+
* @param uploadId - Upload id returned by `createUploadUrl` / `uploadFromUrl`.
|
|
1212
|
+
* @returns The file upload resource, including its processing `status`.
|
|
1213
|
+
*/
|
|
1214
|
+
async get(uploadId) {
|
|
1215
|
+
validateId(uploadId, "uploadId");
|
|
1216
|
+
return asRecord(
|
|
1217
|
+
await invokeWithRetry(this.config, this.http, "ContextFilesController_get", {
|
|
1218
|
+
pathParams: { uploadId }
|
|
1219
|
+
})
|
|
1220
|
+
);
|
|
1221
|
+
}
|
|
1222
|
+
/**
|
|
1223
|
+
* List durable file uploads.
|
|
1224
|
+
*
|
|
1225
|
+
* @param options.pageSize - Items per page (default 50).
|
|
1226
|
+
* @param options.pageToken - Opaque token from a previous page's `nextPageToken`.
|
|
1227
|
+
* @returns Page of file uploads. Uploads that only have a pending row (not yet
|
|
1228
|
+
* landed) aren't included here — use `get(uploadId)` for those.
|
|
1229
|
+
*/
|
|
1230
|
+
list(options = {}) {
|
|
1231
|
+
const pageSize = options.pageSize ?? DEFAULT_LIST_PAGE_SIZE;
|
|
1232
|
+
validatePageSize(pageSize, 200);
|
|
1233
|
+
return this.listPage(pageSize, options.pageToken);
|
|
1234
|
+
}
|
|
1235
|
+
async listPage(pageSize, pageToken) {
|
|
1236
|
+
const data = asRecord(
|
|
1237
|
+
await invokeWithRetry(this.config, this.http, "ContextFilesController_list", {
|
|
1238
|
+
query: aipListParams(pageSize, pageToken)
|
|
1239
|
+
})
|
|
1240
|
+
);
|
|
1241
|
+
return buildAipPage(data, "files", (raw) => raw, (token) => this.listPage(pageSize, token));
|
|
1242
|
+
}
|
|
1243
|
+
/**
|
|
1244
|
+
* Turn a file already PUT to a presigned URL into durable context.
|
|
1245
|
+
*
|
|
1246
|
+
* Call this once the PUT completes. The server locates the object from
|
|
1247
|
+
* `uploadId` + `fileName` and validates the bytes that actually arrived.
|
|
1248
|
+
* Safe to retry — a second call returns the same resource.
|
|
1249
|
+
*
|
|
1250
|
+
* @param uploadId - Upload id returned by `createUploadUrl`.
|
|
1251
|
+
* @param fileName - File name returned alongside it.
|
|
1252
|
+
* @returns The file upload resource, status `"processing"`.
|
|
1253
|
+
*/
|
|
1254
|
+
async finalize(uploadId, fileName, options = {}) {
|
|
1255
|
+
validateId(uploadId, "uploadId");
|
|
1256
|
+
return asRecord(
|
|
1257
|
+
await invokeWithRetry(this.config, this.http, "ContextFilesController_finalize", {
|
|
1258
|
+
pathParams: { uploadId },
|
|
1259
|
+
jsonBody: { fileName, ...options.folderPath !== void 0 ? { folderPath: options.folderPath } : {} }
|
|
1260
|
+
})
|
|
1261
|
+
);
|
|
1262
|
+
}
|
|
1263
|
+
/**
|
|
1264
|
+
* Finalize up to 100 uploads in one call.
|
|
1265
|
+
*
|
|
1266
|
+
* What makes directory upload cheap: 2000 files cost 20 requests here rather
|
|
1267
|
+
* than 2000.
|
|
1268
|
+
*
|
|
1269
|
+
* @param uploads - Uploads to finalize (max 100).
|
|
1270
|
+
* @returns Resources for every upload that finalized, plus per-index
|
|
1271
|
+
* failures for the rest — never a partial 4xx.
|
|
1272
|
+
*/
|
|
1273
|
+
async finalizeMany(uploads) {
|
|
1274
|
+
validateBulkSize(uploads.length, "uploads");
|
|
1275
|
+
return asRecord(
|
|
1276
|
+
await invokeWithRetry(this.config, this.http, "ContextFilesController_finalizeMany", {
|
|
1277
|
+
jsonBody: {
|
|
1278
|
+
uploads: uploads.map((u) => ({
|
|
1279
|
+
uploadId: u.uploadId,
|
|
1280
|
+
fileName: u.fileName,
|
|
1281
|
+
...u.folderPath !== void 0 ? { folderPath: u.folderPath } : {}
|
|
1282
|
+
}))
|
|
1283
|
+
}
|
|
1284
|
+
})
|
|
1285
|
+
);
|
|
1286
|
+
}
|
|
1287
|
+
/**
|
|
1288
|
+
* Upload an explicit list of local files.
|
|
1289
|
+
*
|
|
1290
|
+
* Same machinery as `uploadDir`, without the directory walk — use it when
|
|
1291
|
+
* the caller already knows which files to send.
|
|
1292
|
+
*
|
|
1293
|
+
* @param paths - Paths to local files.
|
|
1294
|
+
* @param options.concurrency - Max concurrent PUTs (default 10).
|
|
1295
|
+
* @param options.waitUntil - `"processing"` (default) or `"ready"`.
|
|
1296
|
+
* @param options.onProgress - Optional progress callback after each file.
|
|
1297
|
+
*/
|
|
1298
|
+
async uploadFiles(paths, options = {}) {
|
|
1299
|
+
return this.uploadPaths(paths.map((input) => typeof input === "string" ? { path: input } : input), options);
|
|
1300
|
+
}
|
|
1301
|
+
/**
|
|
1302
|
+
* Upload a local file and wait for it to reach `"processing"` or `"ready"`.
|
|
1303
|
+
*
|
|
1304
|
+
* Gets a presigned URL, PUTs the file bytes, then polls `get()` until the
|
|
1305
|
+
* upload leaves `"pending"` (or reaches `"ready"`/`"failed"`).
|
|
1306
|
+
*
|
|
1307
|
+
* @param path - Path to a local file.
|
|
1308
|
+
* @param options.waitUntil - `"processing"` (parsing started, default) or
|
|
1309
|
+
* `"ready"` (parsing finished).
|
|
1310
|
+
* @param options.pollIntervalMs - Milliseconds between status polls.
|
|
1311
|
+
* @param options.timeoutMs - Max milliseconds to wait before raising.
|
|
1312
|
+
* @returns The file upload resource once it reaches `waitUntil` (or `"failed"`).
|
|
1313
|
+
* @throws {ModusError} If the PUT fails, or polling times out.
|
|
1314
|
+
*/
|
|
1315
|
+
async upload(path, options = {}) {
|
|
1316
|
+
const waitUntil = options.waitUntil ?? "processing";
|
|
1317
|
+
validateWaitUntil(waitUntil);
|
|
1318
|
+
const fileStat = await stat(path);
|
|
1319
|
+
if (!fileStat.isFile()) throw new Error(`Not a file: ${path}`);
|
|
1320
|
+
const fileName = path.split(/[/\\]/).pop();
|
|
1321
|
+
const slot = await this.createUploadUrl({
|
|
1322
|
+
fileName,
|
|
1323
|
+
contentType: DEFER_CONTENT_TYPE_TO_SERVER,
|
|
1324
|
+
fileSize: fileStat.size
|
|
1325
|
+
});
|
|
1326
|
+
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);
|
|
1329
|
+
if (statusSatisfies(finalized.status, waitUntil)) return finalized;
|
|
1330
|
+
return this.pollUntil(
|
|
1331
|
+
slot.uploadId,
|
|
1332
|
+
waitUntil,
|
|
1333
|
+
options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS,
|
|
1334
|
+
options.timeoutMs ?? DEFAULT_UPLOAD_TIMEOUT_MS
|
|
1335
|
+
);
|
|
1336
|
+
}
|
|
1337
|
+
async pollUntil(uploadId, waitUntil, pollIntervalMs, timeoutMs) {
|
|
1338
|
+
const deadline = Date.now() + timeoutMs;
|
|
1339
|
+
for (; ; ) {
|
|
1340
|
+
const item = await this.get(uploadId);
|
|
1341
|
+
if (statusSatisfies(item.status, waitUntil)) return item;
|
|
1342
|
+
if (Date.now() >= deadline) {
|
|
1343
|
+
throw new ModusError(
|
|
1344
|
+
`Timed out after ${timeoutMs}ms waiting for upload ${JSON.stringify(uploadId)} to reach status ${JSON.stringify(waitUntil)}; last status was ${JSON.stringify(item.status)}.`
|
|
1345
|
+
);
|
|
1346
|
+
}
|
|
1347
|
+
await sleep(pollIntervalMs);
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
/**
|
|
1351
|
+
* Upload every file in a local directory.
|
|
1352
|
+
*
|
|
1353
|
+
* Walks `path` (skipping hidden files/directories and symlinks), pages
|
|
1354
|
+
* through `createUploadUrls()` in batches of up to 100, then PUTs and polls
|
|
1355
|
+
* each file with up to `concurrency` in flight at once. A failure on one
|
|
1356
|
+
* file does not stop the others — check `result.failed`.
|
|
1357
|
+
*
|
|
1358
|
+
* @param path - Path to a local directory.
|
|
1359
|
+
* @param options.recursive - Recurse into subdirectories (default `true`).
|
|
1360
|
+
* @param options.concurrency - Max concurrent PUT+poll operations (default 10).
|
|
1361
|
+
* @param options.waitUntil - `"processing"` (default) or `"ready"` — same as `upload()`.
|
|
1362
|
+
* @param options.onProgress - Optional progress callback after each file.
|
|
1363
|
+
* @returns `UploadDirResult` with every successful `FileUpload` and every
|
|
1364
|
+
* per-file failure (slot creation or PUT/poll), each tagged with its local path.
|
|
1365
|
+
*/
|
|
1366
|
+
async uploadDir(path, options = {}) {
|
|
1367
|
+
const waitUntil = options.waitUntil ?? "processing";
|
|
1368
|
+
validateWaitUntil(waitUntil);
|
|
1369
|
+
const concurrency = options.concurrency ?? DEFAULT_CONCURRENCY;
|
|
1370
|
+
if (concurrency < 1) throw new Error(`concurrency must be >= 1, got ${concurrency}`);
|
|
1371
|
+
const dirStat = await stat(path);
|
|
1372
|
+
if (!dirStat.isDirectory()) throw new Error(`Not a directory: ${path}`);
|
|
1373
|
+
const files = await walkFiles(path, options.recursive ?? true);
|
|
1374
|
+
return this.uploadPaths(files.map((file) => {
|
|
1375
|
+
const folderPath = relative(path, dirname(file)).replace(/\\/g, "/");
|
|
1376
|
+
return { path: file, ...folderPath.length > 0 ? { folderPath } : {} };
|
|
1377
|
+
}), options);
|
|
1378
|
+
}
|
|
1379
|
+
/** Shared body of `uploadFiles` and `uploadDir`: presign in batches of 100,
|
|
1380
|
+
* PUT with bounded concurrency, then bulk-finalize the batch. */
|
|
1381
|
+
async uploadPaths(files, options) {
|
|
1382
|
+
const waitUntil = options.waitUntil ?? "processing";
|
|
1383
|
+
validateWaitUntil(waitUntil);
|
|
1384
|
+
const concurrency = options.concurrency ?? DEFAULT_CONCURRENCY;
|
|
1385
|
+
if (concurrency < 1) throw new Error(`concurrency must be >= 1, got ${concurrency}`);
|
|
1386
|
+
const uploaded = [];
|
|
1387
|
+
const failed = [];
|
|
1388
|
+
const total = files.length;
|
|
1389
|
+
let completed = 0;
|
|
1390
|
+
const emit = () => {
|
|
1391
|
+
completed += 1;
|
|
1392
|
+
options.onProgress?.({
|
|
1393
|
+
completed,
|
|
1394
|
+
total,
|
|
1395
|
+
succeeded: uploaded.length,
|
|
1396
|
+
failed: failed.length
|
|
1397
|
+
});
|
|
1398
|
+
};
|
|
1399
|
+
for (const batch of chunked(files, MAX_BULK_UPLOAD_FILES)) {
|
|
1400
|
+
const failedBefore = failed.length;
|
|
1401
|
+
const slots = await this.createSlots(batch, failed);
|
|
1402
|
+
for (let reported = failedBefore + 1; reported <= failed.length; reported += 1) {
|
|
1403
|
+
completed += 1;
|
|
1404
|
+
options.onProgress?.({ completed, total, succeeded: uploaded.length, failed: reported });
|
|
1405
|
+
}
|
|
1406
|
+
await this.uploadBatch(slots, waitUntil, concurrency, (result) => {
|
|
1407
|
+
if ("error" in result) failed.push(result);
|
|
1408
|
+
else uploaded.push(result);
|
|
1409
|
+
emit();
|
|
1410
|
+
});
|
|
1411
|
+
}
|
|
1412
|
+
return { uploaded, failed };
|
|
1413
|
+
}
|
|
1414
|
+
async createSlots(batch, failed) {
|
|
1415
|
+
const readable = [];
|
|
1416
|
+
const inputs = [];
|
|
1417
|
+
for (const file of batch) {
|
|
1418
|
+
try {
|
|
1419
|
+
const fileStat = await stat(file.path);
|
|
1420
|
+
const fileName = file.path.split(/[/\\]/).pop();
|
|
1421
|
+
inputs.push({ fileName, contentType: DEFER_CONTENT_TYPE_TO_SERVER, fileSize: fileStat.size });
|
|
1422
|
+
readable.push(file);
|
|
1423
|
+
} catch (error) {
|
|
1424
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1425
|
+
failed.push({ path: file.path, error: message });
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
if (inputs.length === 0) return [];
|
|
1429
|
+
const result = await this.createUploadUrls(inputs);
|
|
1430
|
+
return assignSlots(readable, result, failed);
|
|
1431
|
+
}
|
|
1432
|
+
async uploadBatch(slots, waitUntil, concurrency, onOutcome) {
|
|
1433
|
+
if (slots.length === 0) return [];
|
|
1434
|
+
const out = [];
|
|
1435
|
+
const put = await mapWithConcurrency(
|
|
1436
|
+
slots,
|
|
1437
|
+
concurrency,
|
|
1438
|
+
async ({ path, folderPath, slot }) => {
|
|
1439
|
+
try {
|
|
1440
|
+
const data = await readFile(path);
|
|
1441
|
+
await putBytes(this.config.fetch, slot.uploadUrl, data, slot.contentType, DEFAULT_PUT_TIMEOUT_MS);
|
|
1442
|
+
return { landed: { path, ...folderPath !== void 0 ? { folderPath } : {}, slot } };
|
|
1443
|
+
} catch (error) {
|
|
1444
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1445
|
+
return { failure: { path, error: message } };
|
|
1446
|
+
}
|
|
1447
|
+
},
|
|
1448
|
+
(outcome) => {
|
|
1449
|
+
if ("failure" in outcome) {
|
|
1450
|
+
out.push(outcome.failure);
|
|
1451
|
+
onOutcome?.(outcome.failure);
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
);
|
|
1455
|
+
const landed = [];
|
|
1456
|
+
for (const entry of put) {
|
|
1457
|
+
if ("failure" in entry) {
|
|
1458
|
+
continue;
|
|
1459
|
+
}
|
|
1460
|
+
landed.push(entry.landed);
|
|
1461
|
+
}
|
|
1462
|
+
if (landed.length === 0) return out;
|
|
1463
|
+
const result = await this.finalizeMany(
|
|
1464
|
+
landed.map(({ slot, folderPath }) => ({
|
|
1465
|
+
uploadId: slot.uploadId,
|
|
1466
|
+
fileName: slot.fileName,
|
|
1467
|
+
...folderPath !== void 0 ? { folderPath } : {}
|
|
1468
|
+
}))
|
|
1469
|
+
);
|
|
1470
|
+
const failedIndices = new Set(result.failed.map((f) => f.index));
|
|
1471
|
+
for (const f of result.failed) {
|
|
1472
|
+
const failure = { path: landed[f.index]?.path ?? "", error: f.error };
|
|
1473
|
+
out.push(failure);
|
|
1474
|
+
onOutcome?.(failure);
|
|
1475
|
+
}
|
|
1476
|
+
const finalized = result.finalized;
|
|
1477
|
+
const remaining = landed.filter((_, i) => !failedIndices.has(i));
|
|
1478
|
+
if (waitUntil !== "ready") {
|
|
1479
|
+
for (const item of finalized) {
|
|
1480
|
+
out.push(item);
|
|
1481
|
+
onOutcome?.(item);
|
|
1482
|
+
}
|
|
1483
|
+
return out;
|
|
1484
|
+
}
|
|
1485
|
+
await mapWithConcurrency(
|
|
1486
|
+
remaining,
|
|
1487
|
+
concurrency,
|
|
1488
|
+
async ({ path, slot }) => {
|
|
1489
|
+
try {
|
|
1490
|
+
return await this.pollUntil(slot.uploadId, waitUntil, DEFAULT_POLL_INTERVAL_MS, DEFAULT_UPLOAD_TIMEOUT_MS);
|
|
1491
|
+
} catch (error) {
|
|
1492
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1493
|
+
return { path, error: message };
|
|
1494
|
+
}
|
|
1495
|
+
},
|
|
1496
|
+
(item) => {
|
|
1497
|
+
out.push(item);
|
|
1498
|
+
onOutcome?.(item);
|
|
1499
|
+
}
|
|
1500
|
+
);
|
|
1501
|
+
return out;
|
|
1502
|
+
}
|
|
1503
|
+
};
|
|
1504
|
+
|
|
474
1505
|
// src/management/context/items.ts
|
|
475
1506
|
function contextListParams(pageSize, pageToken, contextType) {
|
|
476
1507
|
const extra = {};
|
|
@@ -581,6 +1612,8 @@ var ManagementContextResource = class {
|
|
|
581
1612
|
this.config = config;
|
|
582
1613
|
this.items = new ManagementContextItemsResource(http, config);
|
|
583
1614
|
this.customItems = new CustomContextItemsResource(http, config);
|
|
1615
|
+
this.files = new ManagementContextFilesResource(http, config);
|
|
1616
|
+
this.dashboards = new ManagementDashboardsResource(http, config);
|
|
584
1617
|
}
|
|
585
1618
|
/**
|
|
586
1619
|
* Add a free-form text note to the knowledge base.
|
|
@@ -590,6 +1623,7 @@ var ManagementContextResource = class {
|
|
|
590
1623
|
* @returns The created context item.
|
|
591
1624
|
* @example
|
|
592
1625
|
* ```ts
|
|
1626
|
+
* const mgmt = new ModusManagement()
|
|
593
1627
|
* const note = await mgmt.context.createNote('Runbook', '# Steps\n1. Check logs')
|
|
594
1628
|
* ```
|
|
595
1629
|
*/
|
|
@@ -607,6 +1641,14 @@ var ManagementContextResource = class {
|
|
|
607
1641
|
* @param options.body - New markdown body.
|
|
608
1642
|
* @param options.existing - Optional cached item to avoid a GET.
|
|
609
1643
|
* @returns The updated context item.
|
|
1644
|
+
* @example
|
|
1645
|
+
* ```ts
|
|
1646
|
+
* const mgmt = new ModusManagement()
|
|
1647
|
+
* const item = await mgmt.context.updateNote('PLACEHOLDER_UID', {
|
|
1648
|
+
* title: 'Runbook',
|
|
1649
|
+
* body: '# Steps\n1. Check logs\n2. Escalate',
|
|
1650
|
+
* })
|
|
1651
|
+
* ```
|
|
610
1652
|
*/
|
|
611
1653
|
updateNote(uid, options) {
|
|
612
1654
|
return resolveAndUpdateNote(this.items, uid, options);
|
|
@@ -619,6 +1661,14 @@ var ManagementContextResource = class {
|
|
|
619
1661
|
* @param options.query - SQL text.
|
|
620
1662
|
* @param options.path - Optional hierarchy path segments.
|
|
621
1663
|
* @returns The created context item.
|
|
1664
|
+
* @example
|
|
1665
|
+
* ```ts
|
|
1666
|
+
* const mgmt = new ModusManagement()
|
|
1667
|
+
* const query = await mgmt.context.createSavedQuery('Monthly ARR', {
|
|
1668
|
+
* connectionId: 'conn_warehouse',
|
|
1669
|
+
* query: 'select * from arr_monthly',
|
|
1670
|
+
* })
|
|
1671
|
+
* ```
|
|
622
1672
|
*/
|
|
623
1673
|
createSavedQuery(name, options) {
|
|
624
1674
|
return this.create(
|
|
@@ -640,6 +1690,14 @@ var ManagementContextResource = class {
|
|
|
640
1690
|
* @param options.query - New SQL text.
|
|
641
1691
|
* @param options.existing - Optional cached item to avoid a GET.
|
|
642
1692
|
* @returns The updated context item.
|
|
1693
|
+
* @example
|
|
1694
|
+
* ```ts
|
|
1695
|
+
* const mgmt = new ModusManagement()
|
|
1696
|
+
* const item = await mgmt.context.updateSavedQuery('PLACEHOLDER_UID', {
|
|
1697
|
+
* name: 'Monthly ARR',
|
|
1698
|
+
* query: 'select sum(amount) from arr_monthly',
|
|
1699
|
+
* })
|
|
1700
|
+
* ```
|
|
643
1701
|
*/
|
|
644
1702
|
updateSavedQuery(uid, options) {
|
|
645
1703
|
return resolveAndUpdateSavedQuery(this.items, uid, options);
|
|
@@ -652,6 +1710,13 @@ var ManagementContextResource = class {
|
|
|
652
1710
|
* @param options.isCrawl - When true, crawl linked pages into context.
|
|
653
1711
|
* @param options.pageLimit - Maximum pages to crawl when `isCrawl` is true.
|
|
654
1712
|
* @returns The created context item.
|
|
1713
|
+
* @example
|
|
1714
|
+
* ```ts
|
|
1715
|
+
* const mgmt = new ModusManagement()
|
|
1716
|
+
* const link = await mgmt.context.createLink('https://docs.example.com/runbook', {
|
|
1717
|
+
* title: 'Ops runbook',
|
|
1718
|
+
* })
|
|
1719
|
+
* ```
|
|
655
1720
|
*/
|
|
656
1721
|
createLink(url, options = {}) {
|
|
657
1722
|
return this.create(
|
|
@@ -674,6 +1739,13 @@ var ManagementContextResource = class {
|
|
|
674
1739
|
* @param options.url - New URL.
|
|
675
1740
|
* @param options.existing - Optional cached item to avoid a GET.
|
|
676
1741
|
* @returns The updated context item.
|
|
1742
|
+
* @example
|
|
1743
|
+
* ```ts
|
|
1744
|
+
* const mgmt = new ModusManagement()
|
|
1745
|
+
* const item = await mgmt.context.updateLink('PLACEHOLDER_UID', {
|
|
1746
|
+
* title: 'Ops runbook (2025)',
|
|
1747
|
+
* })
|
|
1748
|
+
* ```
|
|
677
1749
|
*/
|
|
678
1750
|
updateLink(uid, options) {
|
|
679
1751
|
return resolveAndUpdateLink(this.items, uid, options);
|
|
@@ -977,7 +2049,14 @@ var ManagementScopesResource = class {
|
|
|
977
2049
|
* @param options.search - Case-insensitive substring filter on the scope name.
|
|
978
2050
|
* @param options.view - Variation view: `"active"` (deployed) or `"draft"`.
|
|
979
2051
|
* @param options.managerId - Return only scopes supervised by this manager scope id.
|
|
980
|
-
* @returns A page of scopes.
|
|
2052
|
+
* @returns A page of scopes — use `.autoPagingIter()` for all pages.
|
|
2053
|
+
* @example
|
|
2054
|
+
* ```ts
|
|
2055
|
+
* const mgmt = new ModusManagement()
|
|
2056
|
+
* for await (const scope of (await mgmt.scopes.list()).autoPagingIter()) {
|
|
2057
|
+
* console.log(scope.id, scope.name, scope.status)
|
|
2058
|
+
* }
|
|
2059
|
+
* ```
|
|
981
2060
|
*/
|
|
982
2061
|
list(options = {}) {
|
|
983
2062
|
const pageSize = options.pageSize ?? 25;
|
|
@@ -1009,6 +2088,12 @@ var ManagementScopesResource = class {
|
|
|
1009
2088
|
* @param scopeId - Scope id.
|
|
1010
2089
|
* @param options.view - Variation view: `"active"` (deployed) or `"draft"`.
|
|
1011
2090
|
* @returns The scope.
|
|
2091
|
+
* @example
|
|
2092
|
+
* ```ts
|
|
2093
|
+
* const mgmt = new ModusManagement()
|
|
2094
|
+
* const scope = await mgmt.scopes.get('PLACEHOLDER_SCOPE_ID')
|
|
2095
|
+
* console.log(scope.name, scope.status)
|
|
2096
|
+
* ```
|
|
1012
2097
|
*/
|
|
1013
2098
|
async get(scopeId, options = {}) {
|
|
1014
2099
|
validateId(scopeId, "scope_id");
|
|
@@ -1031,7 +2116,9 @@ var ManagementScopesResource = class {
|
|
|
1031
2116
|
* @returns The created scope (draft).
|
|
1032
2117
|
* @example
|
|
1033
2118
|
* ```ts
|
|
2119
|
+
* const mgmt = new ModusManagement()
|
|
1034
2120
|
* const scope = await mgmt.scopes.create({ name: 'Support assistant', model: 'claude-sonnet-5' })
|
|
2121
|
+
* console.log(scope.id, scope.name)
|
|
1035
2122
|
* ```
|
|
1036
2123
|
*/
|
|
1037
2124
|
async create(options) {
|
|
@@ -1062,6 +2149,13 @@ var ManagementScopesResource = class {
|
|
|
1062
2149
|
* @param options.guardrails - Guardrail labels to set. Fetches the current scope first to merge. Pass `[]` to clear all.
|
|
1063
2150
|
* @param options.updateMask - Comma-separated field names to update or clear.
|
|
1064
2151
|
* @returns The updated scope.
|
|
2152
|
+
* @example
|
|
2153
|
+
* ```ts
|
|
2154
|
+
* const mgmt = new ModusManagement()
|
|
2155
|
+
* const scope = await mgmt.scopes.update('PLACEHOLDER_SCOPE_ID', {
|
|
2156
|
+
* description: 'Answers billing questions for enterprise customers.',
|
|
2157
|
+
* })
|
|
2158
|
+
* ```
|
|
1065
2159
|
*/
|
|
1066
2160
|
async update(scopeId, options = {}) {
|
|
1067
2161
|
validateId(scopeId, "scope_id");
|
|
@@ -1103,8 +2197,10 @@ var ManagementScopesResource = class {
|
|
|
1103
2197
|
* @returns The published scope.
|
|
1104
2198
|
* @example
|
|
1105
2199
|
* ```ts
|
|
1106
|
-
*
|
|
1107
|
-
* const
|
|
2200
|
+
* const mgmt = new ModusManagement()
|
|
2201
|
+
* const scope = await mgmt.scopes.create({ name: 'Support assistant' })
|
|
2202
|
+
* const published = await mgmt.scopes.deploy(scope.id)
|
|
2203
|
+
* console.log(published.status)
|
|
1108
2204
|
* ```
|
|
1109
2205
|
*/
|
|
1110
2206
|
async deploy(scopeId) {
|
|
@@ -1122,6 +2218,11 @@ var ManagementScopesResource = class {
|
|
|
1122
2218
|
*
|
|
1123
2219
|
* @param scopeId - Scope id.
|
|
1124
2220
|
* @returns Resolves when the scope is deleted.
|
|
2221
|
+
* @example
|
|
2222
|
+
* ```ts
|
|
2223
|
+
* const mgmt = new ModusManagement()
|
|
2224
|
+
* await mgmt.scopes.delete('PLACEHOLDER_SCOPE_ID')
|
|
2225
|
+
* ```
|
|
1125
2226
|
*/
|
|
1126
2227
|
async delete(scopeId) {
|
|
1127
2228
|
validateId(scopeId, "scope_id");
|