@getmodus/sdk 0.6.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.
- package/CHANGELOG.md +128 -4
- package/README.md +28 -1
- package/dist/{chunk-HEHHN4D6.js → chunk-GFS7CNON.js} +418 -26
- package/dist/chunk-GFS7CNON.js.map +1 -0
- package/dist/{conversations-BRg8gEKX.d.cts → conversations-COA6NW8I.d.cts} +11987 -3565
- package/dist/{conversations-BRg8gEKX.d.ts → conversations-COA6NW8I.d.ts} +11987 -3565
- package/dist/index.cjs +756 -79
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +409 -58
- package/dist/index.d.ts +409 -58
- package/dist/index.js +340 -55
- package/dist/index.js.map +1 -1
- package/dist/management/index.cjs +1443 -106
- package/dist/management/index.cjs.map +1 -1
- package/dist/management/index.d.cts +729 -12
- package/dist/management/index.d.ts +729 -12
- package/dist/management/index.js +1001 -50
- package/dist/management/index.js.map +1 -1
- package/package.json +3 -4
- package/dist/chunk-HEHHN4D6.js.map +0 -1
package/dist/management/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
omitUndefined,
|
|
11
11
|
validateId,
|
|
12
12
|
validatePageSize
|
|
13
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-GFS7CNON.js";
|
|
14
14
|
|
|
15
15
|
// src/_query.ts
|
|
16
16
|
function updateMaskQuery(updateMask) {
|
|
@@ -161,6 +161,13 @@ var ManagementWorkflowsResource = class {
|
|
|
161
161
|
* @param options.view - Variation view: `"active"` (deployed) or `"draft"`.
|
|
162
162
|
* @param options.includeVariation - Include variation payload on each list row.
|
|
163
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
|
+
* ```
|
|
164
171
|
*/
|
|
165
172
|
list(options = {}) {
|
|
166
173
|
const pageSize = options.pageSize ?? 25;
|
|
@@ -193,6 +200,12 @@ var ManagementWorkflowsResource = class {
|
|
|
193
200
|
* @param workflowId - Workflow id.
|
|
194
201
|
* @param options.view - Variation view: `"active"` (deployed) or `"draft"`.
|
|
195
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
|
+
* ```
|
|
196
209
|
*/
|
|
197
210
|
async get(workflowId, options = {}) {
|
|
198
211
|
validateId(workflowId, "workflow_id");
|
|
@@ -222,7 +235,8 @@ var ManagementWorkflowsResource = class {
|
|
|
222
235
|
* @returns The created workflow (draft).
|
|
223
236
|
* @example
|
|
224
237
|
* ```ts
|
|
225
|
-
* const
|
|
238
|
+
* const mgmt = new ModusManagement()
|
|
239
|
+
* const wf = await mgmt.workflows.create({ name: 'Daily report', type: 'task' })
|
|
226
240
|
* ```
|
|
227
241
|
*/
|
|
228
242
|
async create(options) {
|
|
@@ -250,6 +264,11 @@ var ManagementWorkflowsResource = class {
|
|
|
250
264
|
* @param options.guardrails - Guardrail labels to set. Fetches the current workflow first to merge. Pass `[]` to clear all.
|
|
251
265
|
* @param options.updateMask - Comma-separated field names to update or clear.
|
|
252
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
|
+
* ```
|
|
253
272
|
*/
|
|
254
273
|
async update(workflowId, options = {}) {
|
|
255
274
|
validateId(workflowId, "workflow_id");
|
|
@@ -285,8 +304,9 @@ var ManagementWorkflowsResource = class {
|
|
|
285
304
|
* @returns The published workflow.
|
|
286
305
|
* @example
|
|
287
306
|
* ```ts
|
|
288
|
-
*
|
|
289
|
-
*
|
|
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')
|
|
290
310
|
* ```
|
|
291
311
|
*/
|
|
292
312
|
async deploy(workflowId) {
|
|
@@ -319,6 +339,11 @@ var ManagementWorkflowsResource = class {
|
|
|
319
339
|
*
|
|
320
340
|
* @param workflowId - Workflow id.
|
|
321
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
|
+
* ```
|
|
322
347
|
*/
|
|
323
348
|
async delete(workflowId) {
|
|
324
349
|
validateId(workflowId, "workflow_id");
|
|
@@ -472,9 +497,526 @@ async function resolveAndUpdateLink(items, uid, options) {
|
|
|
472
497
|
});
|
|
473
498
|
}
|
|
474
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
|
+
|
|
475
1017
|
// src/management/context/files.ts
|
|
476
1018
|
import { readdir, readFile, stat } from "fs/promises";
|
|
477
|
-
import { join } from "path";
|
|
1019
|
+
import { dirname, join, relative } from "path";
|
|
478
1020
|
var MAX_BULK_UPLOAD_FILES = 100;
|
|
479
1021
|
var DEFAULT_LIST_PAGE_SIZE = 50;
|
|
480
1022
|
var DEFAULT_PUT_TIMEOUT_MS = 6e4;
|
|
@@ -507,14 +1049,22 @@ function chunked(items, size) {
|
|
|
507
1049
|
for (let i = 0; i < items.length; i += size) out.push(items.slice(i, i + size));
|
|
508
1050
|
return out;
|
|
509
1051
|
}
|
|
510
|
-
|
|
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
|
+
}
|
|
1058
|
+
async function mapWithConcurrency(items, concurrency, worker, onItemDone) {
|
|
511
1059
|
const results = new Array(items.length);
|
|
512
1060
|
let cursor = 0;
|
|
513
1061
|
async function run() {
|
|
514
1062
|
for (; ; ) {
|
|
515
1063
|
const index = cursor++;
|
|
516
1064
|
if (index >= items.length) return;
|
|
517
|
-
|
|
1065
|
+
const result = await worker(items[index]);
|
|
1066
|
+
results[index] = result;
|
|
1067
|
+
onItemDone?.(result);
|
|
518
1068
|
}
|
|
519
1069
|
}
|
|
520
1070
|
await Promise.all(Array.from({ length: Math.min(concurrency, items.length) }, run));
|
|
@@ -538,11 +1088,11 @@ async function walkFiles(root, recursive) {
|
|
|
538
1088
|
await walk(root);
|
|
539
1089
|
return out;
|
|
540
1090
|
}
|
|
541
|
-
async function putBytes(fetchImpl,
|
|
542
|
-
const response = await fetchImpl(
|
|
1091
|
+
async function putBytes(fetchImpl, slot, data, timeoutMs) {
|
|
1092
|
+
const response = await fetchImpl(slot.uploadUrl, {
|
|
543
1093
|
method: "PUT",
|
|
544
1094
|
body: data,
|
|
545
|
-
headers: { "Content-Type": contentType },
|
|
1095
|
+
headers: { "Content-Type": slot.contentType, ...slot.headers },
|
|
546
1096
|
signal: AbortSignal.timeout(timeoutMs)
|
|
547
1097
|
});
|
|
548
1098
|
if (!response.ok) {
|
|
@@ -560,25 +1110,29 @@ function createSlotsPayload(files) {
|
|
|
560
1110
|
}
|
|
561
1111
|
function uploadFromUrlsPayload(urls) {
|
|
562
1112
|
return {
|
|
563
|
-
urls: urls.map((u) =>
|
|
1113
|
+
urls: urls.map((u) => ({
|
|
1114
|
+
url: u.url,
|
|
1115
|
+
...u.fileName !== void 0 ? { fileName: u.fileName } : {},
|
|
1116
|
+
...u.folderPath !== void 0 ? { folderPath: u.folderPath } : {}
|
|
1117
|
+
}))
|
|
564
1118
|
};
|
|
565
1119
|
}
|
|
566
1120
|
function assignSlots(batch, result, failed) {
|
|
567
1121
|
const failedIndices = new Set(result.failed.map((f) => f.index));
|
|
568
1122
|
for (const f of result.failed) {
|
|
569
|
-
failed.push({ path: batch[f.index], error: f.error });
|
|
1123
|
+
failed.push({ path: batch[f.index]?.path ?? "", error: f.error });
|
|
570
1124
|
}
|
|
571
1125
|
const remaining = batch.filter((_, i) => !failedIndices.has(i));
|
|
572
1126
|
const uploaded = result.uploaded;
|
|
573
1127
|
if (uploaded.length < remaining.length) {
|
|
574
|
-
for (const
|
|
575
|
-
failed.push({ path, error: "Server returned fewer upload slots than requested files." });
|
|
1128
|
+
for (const file of remaining.slice(uploaded.length)) {
|
|
1129
|
+
failed.push({ path: file.path, error: "Server returned fewer upload slots than requested files." });
|
|
576
1130
|
}
|
|
577
1131
|
}
|
|
578
1132
|
const paired = Math.min(remaining.length, uploaded.length);
|
|
579
1133
|
const assignments = [];
|
|
580
1134
|
for (let i = 0; i < paired; i++) {
|
|
581
|
-
assignments.push({
|
|
1135
|
+
assignments.push({ ...remaining[i], slot: uploaded[i] });
|
|
582
1136
|
}
|
|
583
1137
|
return assignments;
|
|
584
1138
|
}
|
|
@@ -596,7 +1150,10 @@ var ManagementContextFilesResource = class {
|
|
|
596
1150
|
* Office/OpenDocument documents, audio, and video.
|
|
597
1151
|
* @param input.fileSize - File size in bytes. Rejected above 50MB.
|
|
598
1152
|
* @returns Presigned upload slot. PUT the raw bytes to `uploadUrl` within 15
|
|
599
|
-
* minutes,
|
|
1153
|
+
* minutes, sending `headers` unchanged, then call `finalize(slot.uploadId, slot.fileName)`. Pass the
|
|
1154
|
+
* slot's own `fileName` rather than your local basename — the server may
|
|
1155
|
+
* sanitize the requested name when it mints the key, and finalization
|
|
1156
|
+
* re-derives the key from `uploadId` and `fileName`.
|
|
600
1157
|
*/
|
|
601
1158
|
async createUploadUrl(input) {
|
|
602
1159
|
return asRecord(
|
|
@@ -626,12 +1183,17 @@ var ManagementContextFilesResource = class {
|
|
|
626
1183
|
* @param url - Source URL to fetch (SSRF-guarded, 50MB cap, same MIME
|
|
627
1184
|
* allow-list as `createUploadUrl`).
|
|
628
1185
|
* @param options.fileName - Override file name. Inferred from the URL path when omitted.
|
|
1186
|
+
* @param options.folderPath - Root-relative folder to upload under.
|
|
629
1187
|
* @returns File upload resource with status `processing` — parsing continues async.
|
|
630
1188
|
*/
|
|
631
1189
|
async uploadFromUrl(url, options = {}) {
|
|
632
1190
|
return asRecord(
|
|
633
1191
|
await invokeWithRetry(this.config, this.http, "ContextFilesController_uploadFromUrl", {
|
|
634
|
-
jsonBody:
|
|
1192
|
+
jsonBody: {
|
|
1193
|
+
url,
|
|
1194
|
+
...options.fileName !== void 0 ? { fileName: options.fileName } : {},
|
|
1195
|
+
...options.folderPath !== void 0 ? { folderPath: options.folderPath } : {}
|
|
1196
|
+
}
|
|
635
1197
|
})
|
|
636
1198
|
);
|
|
637
1199
|
}
|
|
@@ -685,19 +1247,94 @@ var ManagementContextFilesResource = class {
|
|
|
685
1247
|
);
|
|
686
1248
|
return buildAipPage(data, "files", (raw) => raw, (token) => this.listPage(pageSize, token));
|
|
687
1249
|
}
|
|
1250
|
+
/**
|
|
1251
|
+
* Turn a file already PUT to a presigned URL into durable context.
|
|
1252
|
+
*
|
|
1253
|
+
* Call this once the PUT completes. The server locates the object from
|
|
1254
|
+
* `uploadId` + `fileName` and validates the bytes that actually arrived.
|
|
1255
|
+
* Safe to retry — a second call returns the same resource.
|
|
1256
|
+
*
|
|
1257
|
+
* @param uploadId - Upload id returned by `createUploadUrl`.
|
|
1258
|
+
* @param fileName - File name returned alongside it.
|
|
1259
|
+
* @returns The file upload resource, status `"processing"`.
|
|
1260
|
+
*/
|
|
1261
|
+
async finalize(uploadId, fileName, options = {}) {
|
|
1262
|
+
validateId(uploadId, "uploadId");
|
|
1263
|
+
return asRecord(
|
|
1264
|
+
await invokeWithRetry(this.config, this.http, "ContextFilesController_finalize", {
|
|
1265
|
+
pathParams: { uploadId },
|
|
1266
|
+
jsonBody: { fileName, ...options.folderPath !== void 0 ? { folderPath: options.folderPath } : {} }
|
|
1267
|
+
})
|
|
1268
|
+
);
|
|
1269
|
+
}
|
|
1270
|
+
/**
|
|
1271
|
+
* Finalize up to 100 uploads in one call.
|
|
1272
|
+
*
|
|
1273
|
+
* What makes directory upload cheap: 2000 files cost 20 requests here rather
|
|
1274
|
+
* than 2000.
|
|
1275
|
+
*
|
|
1276
|
+
* @param uploads - Uploads to finalize (max 100).
|
|
1277
|
+
* @returns Resources for every upload that finalized, plus per-index
|
|
1278
|
+
* failures for the rest — never a partial 4xx.
|
|
1279
|
+
*/
|
|
1280
|
+
async finalizeMany(uploads) {
|
|
1281
|
+
validateBulkSize(uploads.length, "uploads");
|
|
1282
|
+
return asRecord(
|
|
1283
|
+
await invokeWithRetry(this.config, this.http, "ContextFilesController_finalizeMany", {
|
|
1284
|
+
jsonBody: {
|
|
1285
|
+
uploads: uploads.map((u) => ({
|
|
1286
|
+
uploadId: u.uploadId,
|
|
1287
|
+
fileName: u.fileName,
|
|
1288
|
+
...u.folderPath !== void 0 ? { folderPath: u.folderPath } : {}
|
|
1289
|
+
}))
|
|
1290
|
+
}
|
|
1291
|
+
})
|
|
1292
|
+
);
|
|
1293
|
+
}
|
|
1294
|
+
/**
|
|
1295
|
+
* Upload an explicit list of local files.
|
|
1296
|
+
*
|
|
1297
|
+
* Same machinery as `uploadDir`, without the directory walk — use it when
|
|
1298
|
+
* the caller already knows which files to send.
|
|
1299
|
+
*
|
|
1300
|
+
* @param paths - Paths to local files.
|
|
1301
|
+
* @param options.concurrency - Max concurrent PUTs (default 10).
|
|
1302
|
+
* @param options.waitUntil - `"processing"` (default) or `"ready"`.
|
|
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
|
+
* ```
|
|
1314
|
+
*/
|
|
1315
|
+
async uploadFiles(paths, options = {}) {
|
|
1316
|
+
return this.uploadPaths(paths.map((input) => typeof input === "string" ? { path: input } : input), options);
|
|
1317
|
+
}
|
|
688
1318
|
/**
|
|
689
1319
|
* Upload a local file and wait for it to reach `"processing"` or `"ready"`.
|
|
690
1320
|
*
|
|
691
|
-
* Gets a presigned URL, PUTs the file bytes, then polls `get()`
|
|
692
|
-
* 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"`).
|
|
693
1323
|
*
|
|
694
1324
|
* @param path - Path to a local file.
|
|
695
1325
|
* @param options.waitUntil - `"processing"` (parsing started, default) or
|
|
696
1326
|
* `"ready"` (parsing finished).
|
|
697
1327
|
* @param options.pollIntervalMs - Milliseconds between status polls.
|
|
698
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`.
|
|
699
1331
|
* @returns The file upload resource once it reaches `waitUntil` (or `"failed"`).
|
|
700
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
|
+
* ```
|
|
701
1338
|
*/
|
|
702
1339
|
async upload(path, options = {}) {
|
|
703
1340
|
const waitUntil = options.waitUntil ?? "processing";
|
|
@@ -711,7 +1348,11 @@ var ManagementContextFilesResource = class {
|
|
|
711
1348
|
fileSize: fileStat.size
|
|
712
1349
|
});
|
|
713
1350
|
const data = await readFile(path);
|
|
714
|
-
await putBytes(this.config.fetch, slot
|
|
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
|
+
});
|
|
1355
|
+
if (statusSatisfies(finalized.status, waitUntil)) return finalized;
|
|
715
1356
|
return this.pollUntil(
|
|
716
1357
|
slot.uploadId,
|
|
717
1358
|
waitUntil,
|
|
@@ -744,8 +1385,18 @@ var ManagementContextFilesResource = class {
|
|
|
744
1385
|
* @param options.recursive - Recurse into subdirectories (default `true`).
|
|
745
1386
|
* @param options.concurrency - Max concurrent PUT+poll operations (default 10).
|
|
746
1387
|
* @param options.waitUntil - `"processing"` (default) or `"ready"` — same as `upload()`.
|
|
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`.
|
|
747
1393
|
* @returns `UploadDirResult` with every successful `FileUpload` and every
|
|
748
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
|
+
* ```
|
|
749
1400
|
*/
|
|
750
1401
|
async uploadDir(path, options = {}) {
|
|
751
1402
|
const waitUntil = options.waitUntil ?? "processing";
|
|
@@ -754,56 +1405,155 @@ var ManagementContextFilesResource = class {
|
|
|
754
1405
|
if (concurrency < 1) throw new Error(`concurrency must be >= 1, got ${concurrency}`);
|
|
755
1406
|
const dirStat = await stat(path);
|
|
756
1407
|
if (!dirStat.isDirectory()) throw new Error(`Not a directory: ${path}`);
|
|
1408
|
+
const files = await walkFiles(path, options.recursive ?? true);
|
|
1409
|
+
return this.uploadPaths(files.map((file) => {
|
|
1410
|
+
const folderPath = relative(path, dirname(file)).replace(/\\/g, "/");
|
|
1411
|
+
return { path: file, ...folderPath.length > 0 ? { folderPath } : {} };
|
|
1412
|
+
}), options);
|
|
1413
|
+
}
|
|
1414
|
+
/** Shared body of `uploadFiles` and `uploadDir`: presign in batches of 100,
|
|
1415
|
+
* PUT with bounded concurrency, then bulk-finalize the batch. */
|
|
1416
|
+
async uploadPaths(files, options) {
|
|
1417
|
+
const waitUntil = options.waitUntil ?? "processing";
|
|
1418
|
+
validateWaitUntil(waitUntil);
|
|
1419
|
+
const concurrency = options.concurrency ?? DEFAULT_CONCURRENCY;
|
|
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
|
+
});
|
|
757
1425
|
const uploaded = [];
|
|
758
1426
|
const failed = [];
|
|
759
|
-
const
|
|
760
|
-
|
|
1427
|
+
const total = files.length;
|
|
1428
|
+
let completed = 0;
|
|
1429
|
+
const emit = () => {
|
|
1430
|
+
completed += 1;
|
|
1431
|
+
options.onProgress?.({
|
|
1432
|
+
completed,
|
|
1433
|
+
total,
|
|
1434
|
+
succeeded: uploaded.length,
|
|
1435
|
+
failed: failed.length
|
|
1436
|
+
});
|
|
1437
|
+
};
|
|
1438
|
+
for (const batch of chunked(prefixed, MAX_BULK_UPLOAD_FILES)) {
|
|
1439
|
+
const failedBefore = failed.length;
|
|
761
1440
|
const slots = await this.createSlots(batch, failed);
|
|
762
|
-
|
|
763
|
-
|
|
1441
|
+
for (let reported = failedBefore + 1; reported <= failed.length; reported += 1) {
|
|
1442
|
+
completed += 1;
|
|
1443
|
+
options.onProgress?.({ completed, total, succeeded: uploaded.length, failed: reported });
|
|
1444
|
+
}
|
|
1445
|
+
await this.uploadBatch(slots, waitUntil, concurrency, (result) => {
|
|
764
1446
|
if ("error" in result) failed.push(result);
|
|
765
1447
|
else uploaded.push(result);
|
|
766
|
-
|
|
1448
|
+
emit();
|
|
1449
|
+
});
|
|
767
1450
|
}
|
|
768
1451
|
return { uploaded, failed };
|
|
769
1452
|
}
|
|
770
1453
|
async createSlots(batch, failed) {
|
|
771
1454
|
const readable = [];
|
|
772
1455
|
const inputs = [];
|
|
773
|
-
for (const
|
|
1456
|
+
for (const file of batch) {
|
|
774
1457
|
try {
|
|
775
|
-
const fileStat = await stat(path);
|
|
776
|
-
const fileName = path.split(/[/\\]/).pop();
|
|
1458
|
+
const fileStat = await stat(file.path);
|
|
1459
|
+
const fileName = file.path.split(/[/\\]/).pop();
|
|
777
1460
|
inputs.push({ fileName, contentType: DEFER_CONTENT_TYPE_TO_SERVER, fileSize: fileStat.size });
|
|
778
|
-
readable.push(
|
|
1461
|
+
readable.push(file);
|
|
779
1462
|
} catch (error) {
|
|
780
1463
|
const message = error instanceof Error ? error.message : String(error);
|
|
781
|
-
failed.push({ path, error: message });
|
|
1464
|
+
failed.push({ path: file.path, error: message });
|
|
782
1465
|
}
|
|
783
1466
|
}
|
|
784
1467
|
if (inputs.length === 0) return [];
|
|
785
1468
|
const result = await this.createUploadUrls(inputs);
|
|
786
1469
|
return assignSlots(readable, result, failed);
|
|
787
1470
|
}
|
|
788
|
-
async uploadBatch(slots, waitUntil, concurrency) {
|
|
1471
|
+
async uploadBatch(slots, waitUntil, concurrency, onOutcome) {
|
|
789
1472
|
if (slots.length === 0) return [];
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
1473
|
+
const out = [];
|
|
1474
|
+
const put = await mapWithConcurrency(
|
|
1475
|
+
slots,
|
|
1476
|
+
concurrency,
|
|
1477
|
+
async ({ path, folderPath, slot }) => {
|
|
1478
|
+
try {
|
|
1479
|
+
const data = await readFile(path);
|
|
1480
|
+
await putBytes(this.config.fetch, slot, data, DEFAULT_PUT_TIMEOUT_MS);
|
|
1481
|
+
return { landed: { path, ...folderPath !== void 0 ? { folderPath } : {}, slot } };
|
|
1482
|
+
} catch (error) {
|
|
1483
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1484
|
+
return { failure: { path, error: message } };
|
|
1485
|
+
}
|
|
1486
|
+
},
|
|
1487
|
+
(outcome) => {
|
|
1488
|
+
if ("failure" in outcome) {
|
|
1489
|
+
out.push(outcome.failure);
|
|
1490
|
+
onOutcome?.(outcome.failure);
|
|
1491
|
+
}
|
|
798
1492
|
}
|
|
799
|
-
|
|
1493
|
+
);
|
|
1494
|
+
const landed = [];
|
|
1495
|
+
for (const entry of put) {
|
|
1496
|
+
if ("failure" in entry) {
|
|
1497
|
+
continue;
|
|
1498
|
+
}
|
|
1499
|
+
landed.push(entry.landed);
|
|
1500
|
+
}
|
|
1501
|
+
if (landed.length === 0) return out;
|
|
1502
|
+
const result = await this.finalizeMany(
|
|
1503
|
+
landed.map(({ slot, folderPath }) => ({
|
|
1504
|
+
uploadId: slot.uploadId,
|
|
1505
|
+
fileName: slot.fileName,
|
|
1506
|
+
...folderPath !== void 0 ? { folderPath } : {}
|
|
1507
|
+
}))
|
|
1508
|
+
);
|
|
1509
|
+
const failedIndices = new Set(result.failed.map((f) => f.index));
|
|
1510
|
+
for (const f of result.failed) {
|
|
1511
|
+
const failure = { path: landed[f.index]?.path ?? "", error: f.error };
|
|
1512
|
+
out.push(failure);
|
|
1513
|
+
onOutcome?.(failure);
|
|
1514
|
+
}
|
|
1515
|
+
const finalized = result.finalized;
|
|
1516
|
+
const remaining = landed.filter((_, i) => !failedIndices.has(i));
|
|
1517
|
+
if (waitUntil !== "ready") {
|
|
1518
|
+
for (const item of finalized) {
|
|
1519
|
+
out.push(item);
|
|
1520
|
+
onOutcome?.(item);
|
|
1521
|
+
}
|
|
1522
|
+
return out;
|
|
1523
|
+
}
|
|
1524
|
+
await mapWithConcurrency(
|
|
1525
|
+
remaining,
|
|
1526
|
+
concurrency,
|
|
1527
|
+
async ({ path, slot }) => {
|
|
1528
|
+
try {
|
|
1529
|
+
return await this.pollUntil(slot.uploadId, waitUntil, DEFAULT_POLL_INTERVAL_MS, DEFAULT_UPLOAD_TIMEOUT_MS);
|
|
1530
|
+
} catch (error) {
|
|
1531
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1532
|
+
return { path, error: message };
|
|
1533
|
+
}
|
|
1534
|
+
},
|
|
1535
|
+
(item) => {
|
|
1536
|
+
out.push(item);
|
|
1537
|
+
onOutcome?.(item);
|
|
1538
|
+
}
|
|
1539
|
+
);
|
|
1540
|
+
return out;
|
|
800
1541
|
}
|
|
801
1542
|
};
|
|
802
1543
|
|
|
803
1544
|
// src/management/context/items.ts
|
|
804
|
-
function contextListParams(pageSize, pageToken,
|
|
1545
|
+
function contextListParams(pageSize, pageToken, filters = {}) {
|
|
805
1546
|
const extra = {};
|
|
806
|
-
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
|
+
}
|
|
807
1557
|
return aipListParams(pageSize, pageToken, extra);
|
|
808
1558
|
}
|
|
809
1559
|
function parseContextItem(raw) {
|
|
@@ -820,24 +1570,48 @@ var ManagementContextItemsResource = class {
|
|
|
820
1570
|
* @param options.pageSize - Items per page (default 25).
|
|
821
1571
|
* @param options.pageToken - Token from a previous page's `nextPageToken`.
|
|
822
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: []`.
|
|
823
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
|
+
* ```
|
|
824
1593
|
*/
|
|
825
1594
|
list(options = {}) {
|
|
826
1595
|
const pageSize = options.pageSize ?? 25;
|
|
827
1596
|
validatePageSize(pageSize);
|
|
828
|
-
return this.listPage(pageSize, options.pageToken,
|
|
1597
|
+
return this.listPage(pageSize, options.pageToken, {
|
|
1598
|
+
contextType: options.contextType,
|
|
1599
|
+
parentUids: options.parentUids,
|
|
1600
|
+
ancestorUids: options.ancestorUids,
|
|
1601
|
+
connectionIds: options.connectionIds
|
|
1602
|
+
});
|
|
829
1603
|
}
|
|
830
|
-
async listPage(pageSize, pageToken,
|
|
1604
|
+
async listPage(pageSize, pageToken, filters) {
|
|
831
1605
|
const data = asRecord(
|
|
832
1606
|
await invokeWithRetry(this.config, this.http, "ContextItemsController_list", {
|
|
833
|
-
query: contextListParams(pageSize, pageToken,
|
|
1607
|
+
query: contextListParams(pageSize, pageToken, filters)
|
|
834
1608
|
})
|
|
835
1609
|
);
|
|
836
1610
|
return buildAipPage(
|
|
837
1611
|
data,
|
|
838
1612
|
"contextItems",
|
|
839
1613
|
parseContextItem,
|
|
840
|
-
(token) => this.listPage(pageSize, token,
|
|
1614
|
+
(token) => this.listPage(pageSize, token, filters)
|
|
841
1615
|
);
|
|
842
1616
|
}
|
|
843
1617
|
/**
|
|
@@ -889,7 +1663,7 @@ var ManagementContextItemsResource = class {
|
|
|
889
1663
|
return this.get(uid);
|
|
890
1664
|
}
|
|
891
1665
|
/**
|
|
892
|
-
* Delete a context item.
|
|
1666
|
+
* Delete a context item. Deleting a Files folder also deletes all its contents.
|
|
893
1667
|
*
|
|
894
1668
|
* @param uid - Context item uid.
|
|
895
1669
|
* @returns Deletion confirmation details.
|
|
@@ -900,6 +1674,44 @@ var ManagementContextItemsResource = class {
|
|
|
900
1674
|
});
|
|
901
1675
|
return data;
|
|
902
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
|
+
}
|
|
903
1715
|
};
|
|
904
1716
|
|
|
905
1717
|
// src/management/context/context.ts
|
|
@@ -911,6 +1723,7 @@ var ManagementContextResource = class {
|
|
|
911
1723
|
this.items = new ManagementContextItemsResource(http, config);
|
|
912
1724
|
this.customItems = new CustomContextItemsResource(http, config);
|
|
913
1725
|
this.files = new ManagementContextFilesResource(http, config);
|
|
1726
|
+
this.dashboards = new ManagementDashboardsResource(http, config);
|
|
914
1727
|
}
|
|
915
1728
|
/**
|
|
916
1729
|
* Add a free-form text note to the knowledge base.
|
|
@@ -920,6 +1733,7 @@ var ManagementContextResource = class {
|
|
|
920
1733
|
* @returns The created context item.
|
|
921
1734
|
* @example
|
|
922
1735
|
* ```ts
|
|
1736
|
+
* const mgmt = new ModusManagement()
|
|
923
1737
|
* const note = await mgmt.context.createNote('Runbook', '# Steps\n1. Check logs')
|
|
924
1738
|
* ```
|
|
925
1739
|
*/
|
|
@@ -937,6 +1751,14 @@ var ManagementContextResource = class {
|
|
|
937
1751
|
* @param options.body - New markdown body.
|
|
938
1752
|
* @param options.existing - Optional cached item to avoid a GET.
|
|
939
1753
|
* @returns The updated context item.
|
|
1754
|
+
* @example
|
|
1755
|
+
* ```ts
|
|
1756
|
+
* const mgmt = new ModusManagement()
|
|
1757
|
+
* const item = await mgmt.context.updateNote('PLACEHOLDER_UID', {
|
|
1758
|
+
* title: 'Runbook',
|
|
1759
|
+
* body: '# Steps\n1. Check logs\n2. Escalate',
|
|
1760
|
+
* })
|
|
1761
|
+
* ```
|
|
940
1762
|
*/
|
|
941
1763
|
updateNote(uid, options) {
|
|
942
1764
|
return resolveAndUpdateNote(this.items, uid, options);
|
|
@@ -949,6 +1771,14 @@ var ManagementContextResource = class {
|
|
|
949
1771
|
* @param options.query - SQL text.
|
|
950
1772
|
* @param options.path - Optional hierarchy path segments.
|
|
951
1773
|
* @returns The created context item.
|
|
1774
|
+
* @example
|
|
1775
|
+
* ```ts
|
|
1776
|
+
* const mgmt = new ModusManagement()
|
|
1777
|
+
* const query = await mgmt.context.createSavedQuery('Monthly ARR', {
|
|
1778
|
+
* connectionId: 'conn_warehouse',
|
|
1779
|
+
* query: 'select * from arr_monthly',
|
|
1780
|
+
* })
|
|
1781
|
+
* ```
|
|
952
1782
|
*/
|
|
953
1783
|
createSavedQuery(name, options) {
|
|
954
1784
|
return this.create(
|
|
@@ -970,6 +1800,14 @@ var ManagementContextResource = class {
|
|
|
970
1800
|
* @param options.query - New SQL text.
|
|
971
1801
|
* @param options.existing - Optional cached item to avoid a GET.
|
|
972
1802
|
* @returns The updated context item.
|
|
1803
|
+
* @example
|
|
1804
|
+
* ```ts
|
|
1805
|
+
* const mgmt = new ModusManagement()
|
|
1806
|
+
* const item = await mgmt.context.updateSavedQuery('PLACEHOLDER_UID', {
|
|
1807
|
+
* name: 'Monthly ARR',
|
|
1808
|
+
* query: 'select sum(amount) from arr_monthly',
|
|
1809
|
+
* })
|
|
1810
|
+
* ```
|
|
973
1811
|
*/
|
|
974
1812
|
updateSavedQuery(uid, options) {
|
|
975
1813
|
return resolveAndUpdateSavedQuery(this.items, uid, options);
|
|
@@ -982,6 +1820,13 @@ var ManagementContextResource = class {
|
|
|
982
1820
|
* @param options.isCrawl - When true, crawl linked pages into context.
|
|
983
1821
|
* @param options.pageLimit - Maximum pages to crawl when `isCrawl` is true.
|
|
984
1822
|
* @returns The created context item.
|
|
1823
|
+
* @example
|
|
1824
|
+
* ```ts
|
|
1825
|
+
* const mgmt = new ModusManagement()
|
|
1826
|
+
* const link = await mgmt.context.createLink('https://docs.example.com/runbook', {
|
|
1827
|
+
* title: 'Ops runbook',
|
|
1828
|
+
* })
|
|
1829
|
+
* ```
|
|
985
1830
|
*/
|
|
986
1831
|
createLink(url, options = {}) {
|
|
987
1832
|
return this.create(
|
|
@@ -1004,6 +1849,13 @@ var ManagementContextResource = class {
|
|
|
1004
1849
|
* @param options.url - New URL.
|
|
1005
1850
|
* @param options.existing - Optional cached item to avoid a GET.
|
|
1006
1851
|
* @returns The updated context item.
|
|
1852
|
+
* @example
|
|
1853
|
+
* ```ts
|
|
1854
|
+
* const mgmt = new ModusManagement()
|
|
1855
|
+
* const item = await mgmt.context.updateLink('PLACEHOLDER_UID', {
|
|
1856
|
+
* title: 'Ops runbook (2025)',
|
|
1857
|
+
* })
|
|
1858
|
+
* ```
|
|
1007
1859
|
*/
|
|
1008
1860
|
updateLink(uid, options) {
|
|
1009
1861
|
return resolveAndUpdateLink(this.items, uid, options);
|
|
@@ -1184,6 +2036,65 @@ var ScopeEvaluationsResource = class {
|
|
|
1184
2036
|
}
|
|
1185
2037
|
};
|
|
1186
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
|
+
|
|
1187
2098
|
// src/management/scopes/supervision.ts
|
|
1188
2099
|
var ScopeSupervisionResource = class {
|
|
1189
2100
|
constructor(http, config, scopeId) {
|
|
@@ -1299,6 +2210,15 @@ var ManagementScopesResource = class {
|
|
|
1299
2210
|
supervision(scopeId) {
|
|
1300
2211
|
return new ScopeSupervisionResource(this.http, this.config, scopeId);
|
|
1301
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
|
+
}
|
|
1302
2222
|
/**
|
|
1303
2223
|
* List scopes in the organization.
|
|
1304
2224
|
*
|
|
@@ -1307,7 +2227,14 @@ var ManagementScopesResource = class {
|
|
|
1307
2227
|
* @param options.search - Case-insensitive substring filter on the scope name.
|
|
1308
2228
|
* @param options.view - Variation view: `"active"` (deployed) or `"draft"`.
|
|
1309
2229
|
* @param options.managerId - Return only scopes supervised by this manager scope id.
|
|
1310
|
-
* @returns A page of scopes.
|
|
2230
|
+
* @returns A page of scopes — use `.autoPagingIter()` for all pages.
|
|
2231
|
+
* @example
|
|
2232
|
+
* ```ts
|
|
2233
|
+
* const mgmt = new ModusManagement()
|
|
2234
|
+
* for await (const scope of (await mgmt.scopes.list()).autoPagingIter()) {
|
|
2235
|
+
* console.log(scope.id, scope.name, scope.status)
|
|
2236
|
+
* }
|
|
2237
|
+
* ```
|
|
1311
2238
|
*/
|
|
1312
2239
|
list(options = {}) {
|
|
1313
2240
|
const pageSize = options.pageSize ?? 25;
|
|
@@ -1339,6 +2266,12 @@ var ManagementScopesResource = class {
|
|
|
1339
2266
|
* @param scopeId - Scope id.
|
|
1340
2267
|
* @param options.view - Variation view: `"active"` (deployed) or `"draft"`.
|
|
1341
2268
|
* @returns The scope.
|
|
2269
|
+
* @example
|
|
2270
|
+
* ```ts
|
|
2271
|
+
* const mgmt = new ModusManagement()
|
|
2272
|
+
* const scope = await mgmt.scopes.get('PLACEHOLDER_SCOPE_ID')
|
|
2273
|
+
* console.log(scope.name, scope.status)
|
|
2274
|
+
* ```
|
|
1342
2275
|
*/
|
|
1343
2276
|
async get(scopeId, options = {}) {
|
|
1344
2277
|
validateId(scopeId, "scope_id");
|
|
@@ -1357,11 +2290,14 @@ var ManagementScopesResource = class {
|
|
|
1357
2290
|
* @param options.instructions - Optional system instructions.
|
|
1358
2291
|
* @param options.model - Optional model id.
|
|
1359
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.
|
|
1360
2294
|
* @param options.guardrails - Runtime guardrail labels (for example `"no-pii"`). Omit to create with no guardrails.
|
|
1361
2295
|
* @returns The created scope (draft).
|
|
1362
2296
|
* @example
|
|
1363
2297
|
* ```ts
|
|
2298
|
+
* const mgmt = new ModusManagement()
|
|
1364
2299
|
* const scope = await mgmt.scopes.create({ name: 'Support assistant', model: 'claude-sonnet-5' })
|
|
2300
|
+
* console.log(scope.id, scope.name)
|
|
1365
2301
|
* ```
|
|
1366
2302
|
*/
|
|
1367
2303
|
async create(options) {
|
|
@@ -1374,6 +2310,7 @@ var ManagementScopesResource = class {
|
|
|
1374
2310
|
model: options.model,
|
|
1375
2311
|
connectionSet: options.connectionSet,
|
|
1376
2312
|
contextSelections: options.contextSelections,
|
|
2313
|
+
includeOwnLearnings: options.includeOwnLearnings,
|
|
1377
2314
|
interfaces: options.interfaces,
|
|
1378
2315
|
accessConfig: accessConfigBodyForCreate(options.guardrails)
|
|
1379
2316
|
});
|
|
@@ -1392,6 +2329,13 @@ var ManagementScopesResource = class {
|
|
|
1392
2329
|
* @param options.guardrails - Guardrail labels to set. Fetches the current scope first to merge. Pass `[]` to clear all.
|
|
1393
2330
|
* @param options.updateMask - Comma-separated field names to update or clear.
|
|
1394
2331
|
* @returns The updated scope.
|
|
2332
|
+
* @example
|
|
2333
|
+
* ```ts
|
|
2334
|
+
* const mgmt = new ModusManagement()
|
|
2335
|
+
* const scope = await mgmt.scopes.update('PLACEHOLDER_SCOPE_ID', {
|
|
2336
|
+
* description: 'Answers billing questions for enterprise customers.',
|
|
2337
|
+
* })
|
|
2338
|
+
* ```
|
|
1395
2339
|
*/
|
|
1396
2340
|
async update(scopeId, options = {}) {
|
|
1397
2341
|
validateId(scopeId, "scope_id");
|
|
@@ -1433,8 +2377,10 @@ var ManagementScopesResource = class {
|
|
|
1433
2377
|
* @returns The published scope.
|
|
1434
2378
|
* @example
|
|
1435
2379
|
* ```ts
|
|
1436
|
-
*
|
|
1437
|
-
* const
|
|
2380
|
+
* const mgmt = new ModusManagement()
|
|
2381
|
+
* const scope = await mgmt.scopes.create({ name: 'Support assistant' })
|
|
2382
|
+
* const published = await mgmt.scopes.deploy(scope.id)
|
|
2383
|
+
* console.log(published.status)
|
|
1438
2384
|
* ```
|
|
1439
2385
|
*/
|
|
1440
2386
|
async deploy(scopeId) {
|
|
@@ -1452,6 +2398,11 @@ var ManagementScopesResource = class {
|
|
|
1452
2398
|
*
|
|
1453
2399
|
* @param scopeId - Scope id.
|
|
1454
2400
|
* @returns Resolves when the scope is deleted.
|
|
2401
|
+
* @example
|
|
2402
|
+
* ```ts
|
|
2403
|
+
* const mgmt = new ModusManagement()
|
|
2404
|
+
* await mgmt.scopes.delete('PLACEHOLDER_SCOPE_ID')
|
|
2405
|
+
* ```
|
|
1455
2406
|
*/
|
|
1456
2407
|
async delete(scopeId) {
|
|
1457
2408
|
validateId(scopeId, "scope_id");
|