@getmodus/sdk 0.2.3 → 0.4.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 +7 -35
- package/README.md +4 -0
- package/dist/{chunk-ZFZQ2UMA.js → chunk-I56O44TR.js} +168 -37
- package/dist/chunk-I56O44TR.js.map +1 -0
- package/dist/{conversations-BP2sI3Q5.d.cts → conversations-Cq6OVlpQ.d.cts} +875 -3154
- package/dist/{conversations-BP2sI3Q5.d.ts → conversations-Cq6OVlpQ.d.ts} +875 -3154
- package/dist/index.cjs +546 -77
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +494 -32
- package/dist/index.d.ts +494 -32
- package/dist/index.js +378 -42
- package/dist/index.js.map +1 -1
- package/dist/management/index.cjs +635 -65
- package/dist/management/index.cjs.map +1 -1
- package/dist/management/index.d.cts +501 -43
- package/dist/management/index.d.ts +501 -43
- package/dist/management/index.js +469 -30
- package/dist/management/index.js.map +1 -1
- package/package.json +3 -1
- package/dist/chunk-ZFZQ2UMA.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
validateChatModel,
|
|
30
30
|
validateId,
|
|
31
31
|
validatePageSize
|
|
32
|
-
} from "./chunk-
|
|
32
|
+
} from "./chunk-I56O44TR.js";
|
|
33
33
|
|
|
34
34
|
// src/_agent_run_request.ts
|
|
35
35
|
import { randomUUID } from "crypto";
|
|
@@ -184,11 +184,27 @@ var ChatStream = class {
|
|
|
184
184
|
this.baseUrl = baseUrl;
|
|
185
185
|
this.textParts = [];
|
|
186
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* Async iterable of assistant text token chunks as they arrive.
|
|
189
|
+
*
|
|
190
|
+
* @returns An async generator yielding partial text strings.
|
|
191
|
+
* @throws {ModusError} When the stream emits an error event.
|
|
192
|
+
* @throws {RunCancelledError} When the run is cancelled.
|
|
193
|
+
* @throws {StreamTimeoutError} When the stream times out.
|
|
194
|
+
*/
|
|
187
195
|
async *textStream() {
|
|
188
196
|
for await (const event of this.events(false)) {
|
|
189
197
|
if (event.type === "token") yield event.content;
|
|
190
198
|
}
|
|
191
199
|
}
|
|
200
|
+
/**
|
|
201
|
+
* Async iterable of structured run events (tokens, tool calls, done, and so on).
|
|
202
|
+
*
|
|
203
|
+
* @returns An async generator yielding {@link RunEvent} objects.
|
|
204
|
+
* @throws {ModusError} When the stream emits an error event.
|
|
205
|
+
* @throws {RunCancelledError} When the run is cancelled.
|
|
206
|
+
* @throws {StreamTimeoutError} When the stream times out.
|
|
207
|
+
*/
|
|
192
208
|
async *eventStream() {
|
|
193
209
|
yield* this.events(true);
|
|
194
210
|
}
|
|
@@ -217,6 +233,15 @@ var ChatStream = class {
|
|
|
217
233
|
}
|
|
218
234
|
}
|
|
219
235
|
}
|
|
236
|
+
/**
|
|
237
|
+
* Final chat result after the stream completes.
|
|
238
|
+
*
|
|
239
|
+
* Call only after fully consuming {@link ChatStream.textStream} or
|
|
240
|
+
* {@link ChatStream.eventStream}.
|
|
241
|
+
*
|
|
242
|
+
* @returns The assembled assistant reply, thread id, and run id.
|
|
243
|
+
* @throws {ModusError} When called before the stream finishes with a done event.
|
|
244
|
+
*/
|
|
220
245
|
getFinalResult() {
|
|
221
246
|
if (this.final === void 0) {
|
|
222
247
|
throw new ModusError(
|
|
@@ -269,18 +294,22 @@ function modusChatStreamSession(http, config, message, options) {
|
|
|
269
294
|
);
|
|
270
295
|
}
|
|
271
296
|
|
|
272
|
-
// src/types/
|
|
273
|
-
var
|
|
297
|
+
// src/types/workflows.ts
|
|
298
|
+
var WorkflowType = {
|
|
274
299
|
task: "task",
|
|
275
300
|
workflow: "workflow"
|
|
276
301
|
};
|
|
302
|
+
var AgentType = WorkflowType;
|
|
277
303
|
|
|
278
304
|
// src/types/conversations.ts
|
|
305
|
+
function conversationScopeId(item) {
|
|
306
|
+
return item.scopeId === 0 ? void 0 : item.scopeId;
|
|
307
|
+
}
|
|
279
308
|
function conversationSkillId(item) {
|
|
280
|
-
return item.
|
|
309
|
+
return item.scopeId;
|
|
281
310
|
}
|
|
282
311
|
|
|
283
|
-
// src/resources/
|
|
312
|
+
// src/resources/workflows/runs.ts
|
|
284
313
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
285
314
|
var RUNS_MAX_PAGE_SIZE = 100;
|
|
286
315
|
function runsListParams(pageSize, pageToken, status, timeframe, approvalScope, search) {
|
|
@@ -344,10 +373,23 @@ function makeAgentRunStream(runId, events) {
|
|
|
344
373
|
};
|
|
345
374
|
}
|
|
346
375
|
var WorkflowRunsResource = class {
|
|
376
|
+
/** @internal */
|
|
347
377
|
constructor(http, config) {
|
|
348
378
|
this.http = http;
|
|
349
379
|
this.config = config;
|
|
350
380
|
}
|
|
381
|
+
/**
|
|
382
|
+
* List runs for a workflow.
|
|
383
|
+
*
|
|
384
|
+
* @param workflowId - Workflow id or slug.
|
|
385
|
+
* @param options.pageSize - Maximum items per page (default 25, max 100).
|
|
386
|
+
* @param options.pageToken - Opaque token from a previous page.
|
|
387
|
+
* @param options.status - Filter by run status.
|
|
388
|
+
* @param options.timeframe - Filter by recency (`last_hour`, `last_day`, or `last_week`).
|
|
389
|
+
* @param options.approvalScope - Filter approval-related runs (`mine` or `all`).
|
|
390
|
+
* @param options.search - Free-text search filter.
|
|
391
|
+
* @returns A page of run summaries.
|
|
392
|
+
*/
|
|
351
393
|
list(workflowId, options = {}) {
|
|
352
394
|
validateId(workflowId, "workflow_id");
|
|
353
395
|
const pageSize = options.pageSize ?? 25;
|
|
@@ -382,6 +424,15 @@ var WorkflowRunsResource = class {
|
|
|
382
424
|
(token) => this.listPage(workflowId, pageSize, token, filters)
|
|
383
425
|
);
|
|
384
426
|
}
|
|
427
|
+
/**
|
|
428
|
+
* Retrieve a workflow run by id.
|
|
429
|
+
*
|
|
430
|
+
* @param workflowId - Workflow id or slug the run belongs to.
|
|
431
|
+
* @param runId - Run id.
|
|
432
|
+
* @param options.temporalRunId - Optional internal execution id when disambiguating retries.
|
|
433
|
+
* @returns Run details including status and output.
|
|
434
|
+
* @throws {NotFoundError} When the run does not exist.
|
|
435
|
+
*/
|
|
385
436
|
async get(workflowId, runId, options = {}) {
|
|
386
437
|
validateId(workflowId, "workflow_id");
|
|
387
438
|
if (!runId.trim()) throw new Error("run_id must be a non-empty string");
|
|
@@ -392,21 +443,69 @@ var WorkflowRunsResource = class {
|
|
|
392
443
|
});
|
|
393
444
|
return parseRun(data);
|
|
394
445
|
}
|
|
446
|
+
/**
|
|
447
|
+
* Start a workflow run and stream run events.
|
|
448
|
+
*
|
|
449
|
+
* @param workflowId - Workflow id or slug to run.
|
|
450
|
+
* @param body - Run body (`message`, optional `sessionId`, optional `version` as `published` or `draft`).
|
|
451
|
+
* @param options.idempotencyKey - Client-supplied idempotency key; defaults to `body.runId` or a new uuid.
|
|
452
|
+
* @returns A stream of run events (tokens, completion, errors, and related signals).
|
|
453
|
+
*
|
|
454
|
+
* @example
|
|
455
|
+
* ```ts
|
|
456
|
+
* const stream = client.workflows.runs.create(workflowId, {
|
|
457
|
+
* message: 'Summarize yesterday\'s sales',
|
|
458
|
+
* sessionId: 'conv-abc',
|
|
459
|
+
* })
|
|
460
|
+
* for await (const event of stream) {
|
|
461
|
+
* if (event.type === 'token') process.stdout.write(event.content)
|
|
462
|
+
* if (event.type === 'done') break
|
|
463
|
+
* }
|
|
464
|
+
* ```
|
|
465
|
+
*/
|
|
395
466
|
create(workflowId, body, options = {}) {
|
|
396
467
|
validateId(workflowId, "workflow_id");
|
|
397
468
|
return this.createRun("WorkflowRunsController_create", body, { id: workflowId }, options);
|
|
398
469
|
}
|
|
470
|
+
/**
|
|
471
|
+
* Start a scope run and stream run events.
|
|
472
|
+
*
|
|
473
|
+
* @param scopeId - Scope id to run.
|
|
474
|
+
* @param body - Run body (`message`, optional `sessionId`, optional `version` as `published` or `draft`).
|
|
475
|
+
* @param options.idempotencyKey - Client-supplied idempotency key; defaults to `body.runId` or a new uuid.
|
|
476
|
+
* @returns A stream of run events.
|
|
477
|
+
*/
|
|
399
478
|
createScope(scopeId, body, options = {}) {
|
|
400
479
|
validateId(scopeId, "scope_id");
|
|
401
480
|
return this.createRun("ScopeRunsController_create", body, { id: scopeId }, options);
|
|
402
481
|
}
|
|
482
|
+
/**
|
|
483
|
+
* Start a Modus assistant run and stream run events.
|
|
484
|
+
*
|
|
485
|
+
* @param body - Run body (`message`, optional `sessionId`, optional `subordinateSkillIds` to narrow context).
|
|
486
|
+
* @param options.idempotencyKey - Client-supplied idempotency key; defaults to `body.runId` or a new uuid.
|
|
487
|
+
* @returns A stream of run events.
|
|
488
|
+
*/
|
|
403
489
|
createModus(body, options = {}) {
|
|
404
490
|
return this.createRun("ModusRunsController_create", body, {}, options);
|
|
405
491
|
}
|
|
492
|
+
/**
|
|
493
|
+
* Resume an interrupted run and stream run events.
|
|
494
|
+
*
|
|
495
|
+
* @param runId - Run id to resume.
|
|
496
|
+
* @param body - Resume body (`message`, `sessionId`, and `decision`: `approve` / `deny` / `connected` / `cancelled`).
|
|
497
|
+
* @param options.idempotencyKey - Client-supplied idempotency key; defaults to `body.runId` or a new uuid.
|
|
498
|
+
* @returns A stream of run events.
|
|
499
|
+
*/
|
|
406
500
|
resume(runId, body, options = {}) {
|
|
407
501
|
validateId(runId, "run_id");
|
|
408
502
|
return this.createRun("ResumeRunsController_create", body, { runId }, options);
|
|
409
503
|
}
|
|
504
|
+
/**
|
|
505
|
+
* Cancel a run that is still in progress.
|
|
506
|
+
*
|
|
507
|
+
* @param runId - Run id to cancel.
|
|
508
|
+
*/
|
|
410
509
|
async cancel(runId) {
|
|
411
510
|
validateId(runId, "run_id");
|
|
412
511
|
await invokeWithRetry(this.config, this.http, "RunLifecycleController_cancel", {
|
|
@@ -414,12 +513,23 @@ var WorkflowRunsResource = class {
|
|
|
414
513
|
jsonBody: {}
|
|
415
514
|
});
|
|
416
515
|
}
|
|
516
|
+
/**
|
|
517
|
+
* Fetch stored run events for a run.
|
|
518
|
+
*
|
|
519
|
+
* @param runId - Run id.
|
|
520
|
+
* @returns Run event history for replay or inspection.
|
|
521
|
+
*/
|
|
417
522
|
async events(runId) {
|
|
418
523
|
validateId(runId, "run_id");
|
|
419
524
|
return invokeWithRetry(this.config, this.http, "RunLifecycleController_events", {
|
|
420
525
|
pathParams: { runId }
|
|
421
526
|
});
|
|
422
527
|
}
|
|
528
|
+
/**
|
|
529
|
+
* Request a graceful stop for a running execution.
|
|
530
|
+
*
|
|
531
|
+
* @param runId - Run id to interrupt.
|
|
532
|
+
*/
|
|
423
533
|
async interrupt(runId) {
|
|
424
534
|
validateId(runId, "run_id");
|
|
425
535
|
await invokeWithRetry(this.config, this.http, "RunLifecycleController_interrupt", {
|
|
@@ -427,6 +537,11 @@ var WorkflowRunsResource = class {
|
|
|
427
537
|
jsonBody: {}
|
|
428
538
|
});
|
|
429
539
|
}
|
|
540
|
+
/**
|
|
541
|
+
* Move a queued run back into an editable state before it starts.
|
|
542
|
+
*
|
|
543
|
+
* @param runId - Queued run id.
|
|
544
|
+
*/
|
|
430
545
|
async editQueued(runId) {
|
|
431
546
|
validateId(runId, "run_id");
|
|
432
547
|
await invokeWithRetry(this.config, this.http, "RunLifecycleController_editQueued", {
|
|
@@ -434,6 +549,13 @@ var WorkflowRunsResource = class {
|
|
|
434
549
|
jsonBody: {}
|
|
435
550
|
});
|
|
436
551
|
}
|
|
552
|
+
/**
|
|
553
|
+
* List active conversation runs across the organization.
|
|
554
|
+
*
|
|
555
|
+
* @param options.pageSize - Maximum items per page (default 50, max 100).
|
|
556
|
+
* @param options.pageToken - Opaque token from a previous page.
|
|
557
|
+
* @returns A page of active runs with session and status metadata.
|
|
558
|
+
*/
|
|
437
559
|
active(options = {}) {
|
|
438
560
|
const pageSize = options.pageSize ?? 50;
|
|
439
561
|
validatePageSize(pageSize, RUNS_MAX_PAGE_SIZE);
|
|
@@ -447,6 +569,13 @@ var WorkflowRunsResource = class {
|
|
|
447
569
|
(token) => this.activePage(pageSize, token)
|
|
448
570
|
);
|
|
449
571
|
}
|
|
572
|
+
/**
|
|
573
|
+
* Look up active runs for specific conversation sessions.
|
|
574
|
+
*
|
|
575
|
+
* @param sessionIds - Up to 100 session ids.
|
|
576
|
+
* @returns Active runs matching any of the given sessions.
|
|
577
|
+
* @throws {Error} When more than 100 session ids are provided.
|
|
578
|
+
*/
|
|
450
579
|
async activeBySession(sessionIds) {
|
|
451
580
|
const uniqueSessionIds = [...new Set(sessionIds.map((id) => id.trim()).filter(Boolean))];
|
|
452
581
|
if (uniqueSessionIds.length > 100) {
|
|
@@ -458,6 +587,21 @@ var WorkflowRunsResource = class {
|
|
|
458
587
|
})
|
|
459
588
|
);
|
|
460
589
|
}
|
|
590
|
+
/**
|
|
591
|
+
* Reconnect to an in-progress run and stream run events.
|
|
592
|
+
*
|
|
593
|
+
* @param runId - Run id to follow.
|
|
594
|
+
* @param options.lastEventId - Resume after this event id when catching up.
|
|
595
|
+
* @returns A stream of run events from the current execution point.
|
|
596
|
+
*
|
|
597
|
+
* @example
|
|
598
|
+
* ```ts
|
|
599
|
+
* const stream = client.workflows.runs.stream(runId, { lastEventId: checkpoint })
|
|
600
|
+
* for await (const event of stream) {
|
|
601
|
+
* if (event.type === 'token') process.stdout.write(event.content)
|
|
602
|
+
* }
|
|
603
|
+
* ```
|
|
604
|
+
*/
|
|
461
605
|
stream(runId, options = {}) {
|
|
462
606
|
validateId(runId, "run_id");
|
|
463
607
|
const op = getOperation("RunLifecycleController_stream");
|
|
@@ -488,16 +632,24 @@ var WorkflowRunsResource = class {
|
|
|
488
632
|
}
|
|
489
633
|
};
|
|
490
634
|
|
|
491
|
-
// src/resources/
|
|
635
|
+
// src/resources/workflows/workflow-actions.ts
|
|
492
636
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
493
637
|
function randomRunId2() {
|
|
494
638
|
return randomUUID3();
|
|
495
639
|
}
|
|
496
640
|
var AgentWorkflowActionsResource = class {
|
|
641
|
+
/** @internal */
|
|
497
642
|
constructor(http, config) {
|
|
498
643
|
this.http = http;
|
|
499
644
|
this.config = config;
|
|
500
645
|
}
|
|
646
|
+
/**
|
|
647
|
+
* Execute a workflow action and stream run events.
|
|
648
|
+
*
|
|
649
|
+
* @param body - Action body (`organizationId`, `sessionId`, `workflowAction`, optional `previousOutputs`).
|
|
650
|
+
* @param options.idempotencyKey - Client-supplied idempotency key; defaults to `body.runId` or a new uuid.
|
|
651
|
+
* @returns A stream of run events for the action execution.
|
|
652
|
+
*/
|
|
501
653
|
execute(body, options = {}) {
|
|
502
654
|
const runId = options.idempotencyKey?.trim() || body.runId?.trim() || randomRunId2();
|
|
503
655
|
const op = getOperation("WorkflowActionsController_execute");
|
|
@@ -508,6 +660,11 @@ var AgentWorkflowActionsResource = class {
|
|
|
508
660
|
});
|
|
509
661
|
return makeAgentRunStream(runId, this.parseEvents(lines));
|
|
510
662
|
}
|
|
663
|
+
/**
|
|
664
|
+
* Cancel a workflow action run.
|
|
665
|
+
*
|
|
666
|
+
* @param runId - Action run id to cancel.
|
|
667
|
+
*/
|
|
511
668
|
async cancel(runId) {
|
|
512
669
|
validateId(runId, "run_id");
|
|
513
670
|
await invokeWithRetry(this.config, this.http, "WorkflowActionsController_cancel", {
|
|
@@ -520,7 +677,7 @@ var AgentWorkflowActionsResource = class {
|
|
|
520
677
|
}
|
|
521
678
|
};
|
|
522
679
|
|
|
523
|
-
// src/resources/
|
|
680
|
+
// src/resources/workflows.ts
|
|
524
681
|
function workflowsListParams(pageSize, pageToken, search, type, view, includeVariation) {
|
|
525
682
|
const extra = {};
|
|
526
683
|
if (search !== void 0) extra.search = search;
|
|
@@ -533,12 +690,24 @@ function parseWorkflow(raw) {
|
|
|
533
690
|
return raw;
|
|
534
691
|
}
|
|
535
692
|
var WorkflowsResource = class {
|
|
693
|
+
/** @internal */
|
|
536
694
|
constructor(http, config) {
|
|
537
695
|
this.http = http;
|
|
538
696
|
this.config = config;
|
|
539
697
|
this.runs = new WorkflowRunsResource(http, config);
|
|
540
698
|
this.workflowActions = new AgentWorkflowActionsResource(http, config);
|
|
541
699
|
}
|
|
700
|
+
/**
|
|
701
|
+
* List workflows.
|
|
702
|
+
*
|
|
703
|
+
* @param options.pageSize - Maximum items per page (default 25).
|
|
704
|
+
* @param options.pageToken - Opaque token from a previous page.
|
|
705
|
+
* @param options.search - Free-text search filter.
|
|
706
|
+
* @param options.type - Workflow kind: `"task"` or `"workflow"`.
|
|
707
|
+
* @param options.view - Which saved version to return (`active` or `draft`).
|
|
708
|
+
* @param options.includeVariation - Include variation metadata when supported.
|
|
709
|
+
* @returns A page of workflows.
|
|
710
|
+
*/
|
|
542
711
|
list(options = {}) {
|
|
543
712
|
const pageSize = options.pageSize ?? 25;
|
|
544
713
|
validatePageSize(pageSize);
|
|
@@ -566,11 +735,20 @@ var WorkflowsResource = class {
|
|
|
566
735
|
);
|
|
567
736
|
return buildAipPage(
|
|
568
737
|
data,
|
|
569
|
-
"
|
|
738
|
+
"workflows",
|
|
570
739
|
parseWorkflow,
|
|
571
740
|
(token) => this.listPage(pageSize, token, search, type, view, includeVariation)
|
|
572
741
|
);
|
|
573
742
|
}
|
|
743
|
+
/**
|
|
744
|
+
* Retrieve a workflow by ID or slug.
|
|
745
|
+
*
|
|
746
|
+
* @param workflowId - Numeric id or slug.
|
|
747
|
+
* @param options.view - Which saved version to return (`active` or `draft`).
|
|
748
|
+
* @param options.includeVariation - Include variation metadata when supported.
|
|
749
|
+
* @returns The workflow.
|
|
750
|
+
* @throws {NotFoundError} When no workflow matches the id or slug.
|
|
751
|
+
*/
|
|
574
752
|
async get(workflowId, options = {}) {
|
|
575
753
|
validateId(workflowId, "workflow_id");
|
|
576
754
|
const query = {};
|
|
@@ -584,12 +762,6 @@ var WorkflowsResource = class {
|
|
|
584
762
|
});
|
|
585
763
|
return parseWorkflow(data);
|
|
586
764
|
}
|
|
587
|
-
chat(workflowId, message, options) {
|
|
588
|
-
return chatBuffered(this.http, "workflows", workflowId, message, options);
|
|
589
|
-
}
|
|
590
|
-
chatStream(workflowId, message, options) {
|
|
591
|
-
return chatStreamSession(this.http, this.config, "workflows", workflowId, message, options);
|
|
592
|
-
}
|
|
593
765
|
};
|
|
594
766
|
|
|
595
767
|
// src/resources/connections.ts
|
|
@@ -602,10 +774,19 @@ function parseConnection(raw) {
|
|
|
602
774
|
return raw;
|
|
603
775
|
}
|
|
604
776
|
var ConnectionsResource = class {
|
|
777
|
+
/** @internal */
|
|
605
778
|
constructor(http, config) {
|
|
606
779
|
this.http = http;
|
|
607
780
|
this.config = config;
|
|
608
781
|
}
|
|
782
|
+
/**
|
|
783
|
+
* List integration connections.
|
|
784
|
+
*
|
|
785
|
+
* @param options.pageSize - Maximum items per page (default 25).
|
|
786
|
+
* @param options.pageToken - Opaque token from a previous page.
|
|
787
|
+
* @param options.type - Integration category; exact match filter.
|
|
788
|
+
* @returns A page of connections.
|
|
789
|
+
*/
|
|
609
790
|
list(options = {}) {
|
|
610
791
|
const pageSize = options.pageSize ?? 25;
|
|
611
792
|
validatePageSize(pageSize);
|
|
@@ -624,6 +805,16 @@ var ConnectionsResource = class {
|
|
|
624
805
|
(token) => this.listPage(pageSize, token, type)
|
|
625
806
|
);
|
|
626
807
|
}
|
|
808
|
+
/**
|
|
809
|
+
* Find the first connection whose name matches (case-insensitive).
|
|
810
|
+
*
|
|
811
|
+
* Pages through {@link ConnectionsResource.list} until a match is found.
|
|
812
|
+
*
|
|
813
|
+
* @param options.name - Connection name to search for.
|
|
814
|
+
* @param options.type - Optional integration category filter.
|
|
815
|
+
* @param options.pageSize - Page size when scanning (default 25).
|
|
816
|
+
* @returns The matching connection, or `undefined` if none is found.
|
|
817
|
+
*/
|
|
627
818
|
async find(options) {
|
|
628
819
|
const pageSize = options.pageSize ?? 25;
|
|
629
820
|
validatePageSize(pageSize);
|
|
@@ -658,10 +849,19 @@ function parseLookupResponse(raw) {
|
|
|
658
849
|
return item;
|
|
659
850
|
}
|
|
660
851
|
var ContextItemsResource = class {
|
|
852
|
+
/** @internal */
|
|
661
853
|
constructor(http, config) {
|
|
662
854
|
this.http = http;
|
|
663
855
|
this.config = config;
|
|
664
856
|
}
|
|
857
|
+
/**
|
|
858
|
+
* List knowledge-base items.
|
|
859
|
+
*
|
|
860
|
+
* @param options.pageSize - Maximum items per page (default 25).
|
|
861
|
+
* @param options.pageToken - Opaque token from a previous page.
|
|
862
|
+
* @param options.contextType - Filter to a single context type.
|
|
863
|
+
* @returns A page of context items.
|
|
864
|
+
*/
|
|
665
865
|
list(options = {}) {
|
|
666
866
|
const pageSize = options.pageSize ?? 25;
|
|
667
867
|
validatePageSize(pageSize);
|
|
@@ -680,12 +880,27 @@ var ContextItemsResource = class {
|
|
|
680
880
|
(token) => this.listPage(pageSize, token, contextType)
|
|
681
881
|
);
|
|
682
882
|
}
|
|
883
|
+
/**
|
|
884
|
+
* Retrieve a knowledge-base item by uid.
|
|
885
|
+
*
|
|
886
|
+
* @param uid - Item uid.
|
|
887
|
+
* @returns The context item.
|
|
888
|
+
* @throws {NotFoundError} When no item matches the uid.
|
|
889
|
+
*/
|
|
683
890
|
async get(uid) {
|
|
684
891
|
const data = await invokeWithRetry(this.config, this.http, "ContextItemsController_get", {
|
|
685
892
|
pathParams: { uid }
|
|
686
893
|
});
|
|
687
894
|
return parseContextItem(data);
|
|
688
895
|
}
|
|
896
|
+
/**
|
|
897
|
+
* Look up a knowledge-base item by type and data path.
|
|
898
|
+
*
|
|
899
|
+
* @param options.contextType - Context type to match.
|
|
900
|
+
* @param options.dataPath - Hierarchical path segments that identify the item.
|
|
901
|
+
* @param options.contentProjection - Optional fields to include from item content.
|
|
902
|
+
* @returns The matching row, or `undefined` when no item is found (404).
|
|
903
|
+
*/
|
|
689
904
|
async lookup(options) {
|
|
690
905
|
const body = omitUndefined({
|
|
691
906
|
contextType: options.contextType,
|
|
@@ -704,11 +919,30 @@ var ContextItemsResource = class {
|
|
|
704
919
|
throw error;
|
|
705
920
|
}
|
|
706
921
|
}
|
|
922
|
+
/**
|
|
923
|
+
* List values stored under a content key on a context item.
|
|
924
|
+
*
|
|
925
|
+
* @param uid - Item uid.
|
|
926
|
+
* @param contextType - Context type of the item.
|
|
927
|
+
* @param contentKeyPath - Dot path to the value field inside item content.
|
|
928
|
+
* @param options.pageSize - Maximum items per page (default 25).
|
|
929
|
+
* @param options.pageToken - Opaque token from a previous page.
|
|
930
|
+
* @returns A page of value rows.
|
|
931
|
+
*/
|
|
707
932
|
listValues(uid, contextType, contentKeyPath, options = {}) {
|
|
708
933
|
const pageSize = options.pageSize ?? 25;
|
|
709
934
|
validatePageSize(pageSize, DEFAULT_MAX_PAGE_SIZE);
|
|
710
935
|
return this.listValuesPage(uid, contextType, contentKeyPath, pageSize, options.pageToken);
|
|
711
936
|
}
|
|
937
|
+
/**
|
|
938
|
+
* List values for a context item already loaded via {@link ContextItemsResource.list} or {@link ContextItemsResource.get}.
|
|
939
|
+
*
|
|
940
|
+
* @param item - Context item (uses `item.uid` and `item.contextType`).
|
|
941
|
+
* @param contentKeyPath - Dot path to the value field inside item content.
|
|
942
|
+
* @param options.pageSize - Maximum items per page (default 25).
|
|
943
|
+
* @param options.pageToken - Opaque token from a previous page.
|
|
944
|
+
* @returns A page of value rows.
|
|
945
|
+
*/
|
|
712
946
|
listValuesFor(item, contentKeyPath, options = {}) {
|
|
713
947
|
return this.listValues(item.uid, item.contextType, contentKeyPath, options);
|
|
714
948
|
}
|
|
@@ -733,6 +967,7 @@ var ContextItemsResource = class {
|
|
|
733
967
|
|
|
734
968
|
// src/resources/context/context.ts
|
|
735
969
|
var ContextResource = class {
|
|
970
|
+
/** @internal */
|
|
736
971
|
constructor(http, config) {
|
|
737
972
|
this.items = new ContextItemsResource(http, config);
|
|
738
973
|
this.customItems = new CustomContextItemsResource(http, config);
|
|
@@ -740,7 +975,7 @@ var ContextResource = class {
|
|
|
740
975
|
};
|
|
741
976
|
|
|
742
977
|
// src/resources/modus/conversations.ts
|
|
743
|
-
var ALLOWED_KINDS = /* @__PURE__ */ new Set(["all", "modus", "
|
|
978
|
+
var ALLOWED_KINDS = /* @__PURE__ */ new Set(["all", "modus", "scopes"]);
|
|
744
979
|
function listParams(pageSize, pageToken, kind) {
|
|
745
980
|
if (kind !== void 0 && !ALLOWED_KINDS.has(kind)) {
|
|
746
981
|
throw new Error(
|
|
@@ -762,6 +997,14 @@ var ModusConversationsResource = class {
|
|
|
762
997
|
this.http = http;
|
|
763
998
|
this.config = config;
|
|
764
999
|
}
|
|
1000
|
+
/**
|
|
1001
|
+
* List conversations.
|
|
1002
|
+
*
|
|
1003
|
+
* @param options.pageSize - Items per page (default 25).
|
|
1004
|
+
* @param options.pageToken - Opaque token from a previous page.
|
|
1005
|
+
* @param options.kind - `"modus"`, `"scopes"`, or `"all"`.
|
|
1006
|
+
* @returns Page of conversation list items.
|
|
1007
|
+
*/
|
|
765
1008
|
list(options = {}) {
|
|
766
1009
|
const pageSize = options.pageSize ?? 25;
|
|
767
1010
|
validatePageSize(pageSize);
|
|
@@ -780,6 +1023,12 @@ var ModusConversationsResource = class {
|
|
|
780
1023
|
(token) => this.listPage(pageSize, token, kind)
|
|
781
1024
|
);
|
|
782
1025
|
}
|
|
1026
|
+
/**
|
|
1027
|
+
* Retrieve a conversation thread with full message history.
|
|
1028
|
+
*
|
|
1029
|
+
* @param threadId - Conversation thread id.
|
|
1030
|
+
* @returns Conversation with messages.
|
|
1031
|
+
*/
|
|
783
1032
|
async get(threadId) {
|
|
784
1033
|
validateId(threadId, "thread_id");
|
|
785
1034
|
const data = await invokeWithRetry(this.config, this.http, "ModusConversationsController_get", {
|
|
@@ -796,21 +1045,50 @@ var ModusResource = class {
|
|
|
796
1045
|
this.config = config;
|
|
797
1046
|
this.conversations = new ModusConversationsResource(http, config);
|
|
798
1047
|
}
|
|
1048
|
+
/**
|
|
1049
|
+
* Return composed full-environment context for an intent, without running chat.
|
|
1050
|
+
*
|
|
1051
|
+
* @param message - User intent or question to compose context for.
|
|
1052
|
+
* @param options.limit - Optional cap on structured fallback items.
|
|
1053
|
+
* @returns Composed Modus context.
|
|
1054
|
+
*/
|
|
799
1055
|
async getContext(message, options = {}) {
|
|
800
1056
|
const data = await invokeWithRetry(this.config, this.http, "ModusContextController_compose", {
|
|
801
1057
|
jsonBody: omitUndefined({ message, limit: options.limit })
|
|
802
1058
|
});
|
|
803
1059
|
return data;
|
|
804
1060
|
}
|
|
1061
|
+
/**
|
|
1062
|
+
* Send a message to Modus (org-wide assistant) and get the complete reply.
|
|
1063
|
+
*
|
|
1064
|
+
* @param message - Message to send.
|
|
1065
|
+
* @param options.model - Required model id (e.g. `"claude-sonnet-5"`).
|
|
1066
|
+
* @param options.threadId - Continue an existing conversation.
|
|
1067
|
+
* @returns Chat result with content and threadId.
|
|
1068
|
+
*
|
|
1069
|
+
* @example
|
|
1070
|
+
* ```ts
|
|
1071
|
+
* const result = await client.modus.chat('What tables describe revenue?', { model: 'claude-sonnet-5' })
|
|
1072
|
+
* console.log(result.content, result.threadId)
|
|
1073
|
+
* ```
|
|
1074
|
+
*/
|
|
805
1075
|
chat(message, options) {
|
|
806
1076
|
return modusChatBuffered(this.http, message, options);
|
|
807
1077
|
}
|
|
1078
|
+
/**
|
|
1079
|
+
* Stream a Modus reply token by token.
|
|
1080
|
+
*
|
|
1081
|
+
* @param message - Message to send.
|
|
1082
|
+
* @param options.model - Required model id (e.g. `"claude-sonnet-5"`).
|
|
1083
|
+
* @param options.threadId - Continue an existing conversation.
|
|
1084
|
+
* @returns Chat stream.
|
|
1085
|
+
*/
|
|
808
1086
|
chatStream(message, options) {
|
|
809
1087
|
return modusChatStreamSession(this.http, this.config, message, options);
|
|
810
1088
|
}
|
|
811
1089
|
};
|
|
812
1090
|
|
|
813
|
-
// src/resources/
|
|
1091
|
+
// src/resources/scopes.ts
|
|
814
1092
|
function scopesListParams(pageSize, pageToken, search, view, managerId) {
|
|
815
1093
|
const extra = {};
|
|
816
1094
|
if (search !== void 0) extra.search = search;
|
|
@@ -822,13 +1100,30 @@ function parseScope(raw) {
|
|
|
822
1100
|
return raw;
|
|
823
1101
|
}
|
|
824
1102
|
var ScopesResource = class {
|
|
1103
|
+
/** @internal */
|
|
825
1104
|
constructor(http, config) {
|
|
826
1105
|
this.http = http;
|
|
827
1106
|
this.config = config;
|
|
828
1107
|
}
|
|
1108
|
+
/**
|
|
1109
|
+
* Return the conversations sub-resource scoped to `scopeId`.
|
|
1110
|
+
*
|
|
1111
|
+
* @param scopeId - Scope numeric id or slug.
|
|
1112
|
+
* @returns Conversations resource for the scope.
|
|
1113
|
+
*/
|
|
829
1114
|
conversations(scopeId) {
|
|
830
1115
|
return new ScopeConversationsResource(this.http, this.config, scopeId);
|
|
831
1116
|
}
|
|
1117
|
+
/**
|
|
1118
|
+
* List scopes in the organisation.
|
|
1119
|
+
*
|
|
1120
|
+
* @param options.pageSize - Items per page (default 25).
|
|
1121
|
+
* @param options.pageToken - Opaque token from a previous page.
|
|
1122
|
+
* @param options.search - Case-insensitive substring filter on the scope name.
|
|
1123
|
+
* @param options.view - `"active"` (deployed) or `"draft"`.
|
|
1124
|
+
* @param options.managerId - Only scopes supervised by this manager scope id.
|
|
1125
|
+
* @returns Page of scopes.
|
|
1126
|
+
*/
|
|
832
1127
|
list(options = {}) {
|
|
833
1128
|
const pageSize = options.pageSize ?? 25;
|
|
834
1129
|
validatePageSize(pageSize);
|
|
@@ -848,11 +1143,19 @@ var ScopesResource = class {
|
|
|
848
1143
|
);
|
|
849
1144
|
return buildAipPage(
|
|
850
1145
|
data,
|
|
851
|
-
"
|
|
1146
|
+
"scopes",
|
|
852
1147
|
parseScope,
|
|
853
1148
|
(token) => this.listPage(pageSize, token, search, view, managerId)
|
|
854
1149
|
);
|
|
855
1150
|
}
|
|
1151
|
+
/**
|
|
1152
|
+
* Retrieve a scope by ID or slug.
|
|
1153
|
+
*
|
|
1154
|
+
* @param scopeId - Scope numeric id or slug.
|
|
1155
|
+
* @param options.view - `"active"` (deployed) or `"draft"`.
|
|
1156
|
+
* @throws {NotFoundError} When no scope matches the id or slug.
|
|
1157
|
+
* @returns Scope.
|
|
1158
|
+
*/
|
|
856
1159
|
async get(scopeId, options = {}) {
|
|
857
1160
|
validateId(scopeId, "scope_id");
|
|
858
1161
|
const query = options.view !== void 0 ? { view: options.view } : void 0;
|
|
@@ -862,6 +1165,14 @@ var ScopesResource = class {
|
|
|
862
1165
|
});
|
|
863
1166
|
return parseScope(data);
|
|
864
1167
|
}
|
|
1168
|
+
/**
|
|
1169
|
+
* Return composed context Modus would use for a scope query, without running chat.
|
|
1170
|
+
*
|
|
1171
|
+
* @param scopeId - Scope numeric id or slug.
|
|
1172
|
+
* @param message - User intent or question to compose context for.
|
|
1173
|
+
* @param options.limit - Optional cap on structured fallback items.
|
|
1174
|
+
* @returns Composed scope context.
|
|
1175
|
+
*/
|
|
865
1176
|
async getContext(scopeId, message, options = {}) {
|
|
866
1177
|
validateId(scopeId, "scope_id");
|
|
867
1178
|
const data = await invokeWithRetry(this.config, this.http, "ScopeContextController_compose", {
|
|
@@ -870,32 +1181,39 @@ var ScopesResource = class {
|
|
|
870
1181
|
});
|
|
871
1182
|
return data;
|
|
872
1183
|
}
|
|
1184
|
+
/**
|
|
1185
|
+
* Send a message to a scope and get the complete reply.
|
|
1186
|
+
*
|
|
1187
|
+
* @param scopeId - Scope numeric id or slug.
|
|
1188
|
+
* @param message - Message to send.
|
|
1189
|
+
* @param options.model - Required model id (e.g. `"claude-sonnet-5"`).
|
|
1190
|
+
* @param options.threadId - Continue an existing conversation.
|
|
1191
|
+
* @returns Chat result with content and threadId.
|
|
1192
|
+
*
|
|
1193
|
+
* @example
|
|
1194
|
+
* ```ts
|
|
1195
|
+
* const result = await client.scopes.chat(scopeId, 'Hello', { model: 'claude-sonnet-5' })
|
|
1196
|
+
* console.log(result.content, result.threadId)
|
|
1197
|
+
* ```
|
|
1198
|
+
*/
|
|
873
1199
|
chat(scopeId, message, options) {
|
|
874
1200
|
return chatBuffered(this.http, "scopes", scopeId, message, options);
|
|
875
1201
|
}
|
|
1202
|
+
/**
|
|
1203
|
+
* Stream a scope reply token by token.
|
|
1204
|
+
*
|
|
1205
|
+
* @param scopeId - Scope numeric id or slug.
|
|
1206
|
+
* @param message - Message to send.
|
|
1207
|
+
* @param options.model - Required model id (e.g. `"claude-sonnet-5"`).
|
|
1208
|
+
* @param options.threadId - Continue an existing conversation.
|
|
1209
|
+
* @param options.version - `"published"` or `"draft"`.
|
|
1210
|
+
* @returns Chat stream.
|
|
1211
|
+
*/
|
|
876
1212
|
chatStream(scopeId, message, options) {
|
|
877
1213
|
return chatStreamSession(this.http, this.config, "scopes", scopeId, message, options);
|
|
878
1214
|
}
|
|
879
1215
|
};
|
|
880
1216
|
|
|
881
|
-
// src/types/suggestions.ts
|
|
882
|
-
function normalizeRecordSuggestionEvent(event) {
|
|
883
|
-
const eventType = event.event_type ?? event.eventType;
|
|
884
|
-
if (eventType === void 0) {
|
|
885
|
-
throw new Error("recordEvent requires event_type (or eventType)");
|
|
886
|
-
}
|
|
887
|
-
const body = {
|
|
888
|
-
event_type: eventType,
|
|
889
|
-
source: event.source
|
|
890
|
-
};
|
|
891
|
-
const skillId = event.skill_id ?? event.skillId;
|
|
892
|
-
if (skillId !== void 0) body.skill_id = skillId;
|
|
893
|
-
const threadId = event.thread_id ?? event.threadId;
|
|
894
|
-
if (threadId !== void 0) body.thread_id = threadId;
|
|
895
|
-
if (event.metadata !== void 0) body.metadata = event.metadata;
|
|
896
|
-
return body;
|
|
897
|
-
}
|
|
898
|
-
|
|
899
1217
|
// src/resources/suggestions.ts
|
|
900
1218
|
var DEFAULT_SUGGESTIONS_PAGE_SIZE = 5;
|
|
901
1219
|
var MAX_SUGGESTIONS_PAGE_SIZE = 12;
|
|
@@ -906,38 +1224,54 @@ function suggestionListParams(options) {
|
|
|
906
1224
|
return {
|
|
907
1225
|
pageSize: options.pageSize,
|
|
908
1226
|
pageToken: options.pageToken,
|
|
909
|
-
|
|
910
|
-
|
|
1227
|
+
scopeId: options.scopeId,
|
|
1228
|
+
scopeIds: options.scopeIds?.join(",")
|
|
911
1229
|
};
|
|
912
1230
|
}
|
|
913
1231
|
var SuggestionsResource = class {
|
|
1232
|
+
/** @internal */
|
|
914
1233
|
constructor(http, config) {
|
|
915
1234
|
this.http = http;
|
|
916
1235
|
this.config = config;
|
|
917
1236
|
}
|
|
1237
|
+
/**
|
|
1238
|
+
* List approved suggested questions.
|
|
1239
|
+
*
|
|
1240
|
+
* @param options.pageSize - Maximum items per page (default 5, max 12).
|
|
1241
|
+
* @param options.pageToken - Opaque token from a previous page.
|
|
1242
|
+
* @param options.scopeId - Filter to a single scope.
|
|
1243
|
+
* @param options.scopeIds - Filter to one or more scopes.
|
|
1244
|
+
* @returns A page of suggested questions.
|
|
1245
|
+
*/
|
|
918
1246
|
list(options = {}) {
|
|
919
1247
|
const pageSize = options.pageSize ?? DEFAULT_SUGGESTIONS_PAGE_SIZE;
|
|
920
1248
|
validatePageSize(pageSize, MAX_SUGGESTIONS_PAGE_SIZE);
|
|
921
|
-
return this.listPage(pageSize, options.pageToken, options.
|
|
1249
|
+
return this.listPage(pageSize, options.pageToken, options.scopeId, options.scopeIds);
|
|
922
1250
|
}
|
|
923
|
-
async listPage(pageSize, pageToken,
|
|
1251
|
+
async listPage(pageSize, pageToken, scopeId, scopeIds) {
|
|
924
1252
|
const data = asRecord(
|
|
925
1253
|
await invokeWithRetry(this.config, this.http, "SuggestionsController_listApproved", {
|
|
926
|
-
query: suggestionListParams({ pageSize, pageToken,
|
|
1254
|
+
query: suggestionListParams({ pageSize, pageToken, scopeId, scopeIds })
|
|
927
1255
|
})
|
|
928
1256
|
);
|
|
929
1257
|
return buildAipPage(
|
|
930
1258
|
data,
|
|
931
1259
|
"suggestions",
|
|
932
1260
|
parseSuggestion,
|
|
933
|
-
(token) => this.listPage(pageSize, token,
|
|
1261
|
+
(token) => this.listPage(pageSize, token, scopeId, scopeIds)
|
|
934
1262
|
);
|
|
935
1263
|
}
|
|
1264
|
+
/**
|
|
1265
|
+
* Record that a suggested question was shown, clicked, dismissed, or submitted.
|
|
1266
|
+
*
|
|
1267
|
+
* @param id - Suggestion id.
|
|
1268
|
+
* @param event - Event details, including `eventType` (`shown`, `clicked`, `dismissed`, or `submitted`).
|
|
1269
|
+
*/
|
|
936
1270
|
async recordEvent(id, event) {
|
|
937
1271
|
validateId(id, "id");
|
|
938
1272
|
await invokeWithRetry(this.config, this.http, "SuggestionsController_recordEvent", {
|
|
939
1273
|
pathParams: { id },
|
|
940
|
-
jsonBody:
|
|
1274
|
+
jsonBody: event
|
|
941
1275
|
});
|
|
942
1276
|
}
|
|
943
1277
|
};
|
|
@@ -972,6 +1306,8 @@ export {
|
|
|
972
1306
|
StreamTimeoutError,
|
|
973
1307
|
UnprocessableError,
|
|
974
1308
|
ValidationError,
|
|
1309
|
+
WorkflowType,
|
|
1310
|
+
conversationScopeId,
|
|
975
1311
|
conversationSkillId
|
|
976
1312
|
};
|
|
977
1313
|
//# sourceMappingURL=index.js.map
|