@getmodus/sdk 0.1.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/dist/index.js ADDED
@@ -0,0 +1,888 @@
1
+ import {
2
+ APIConnectionError,
3
+ AuthenticationError,
4
+ ConflictError,
5
+ CustomContextItemsResource,
6
+ DEFAULT_MAX_PAGE_SIZE,
7
+ InternalServerError,
8
+ ModusClientBase,
9
+ ModusError,
10
+ NotFoundError,
11
+ OPERATIONS,
12
+ Page,
13
+ PermissionDeniedError,
14
+ RateLimitError,
15
+ RunCancelledError,
16
+ ScopeConversationsResource,
17
+ StreamTimeoutError,
18
+ UnprocessableError,
19
+ ValidationError,
20
+ aipListParams,
21
+ asRecord,
22
+ buildAipPage,
23
+ formatOperationPath,
24
+ getOperation,
25
+ invokeWithRetry,
26
+ normalizePageToken,
27
+ omitUndefined,
28
+ operationBaseUrl,
29
+ validateChatModel,
30
+ validateId,
31
+ validatePageSize
32
+ } from "./chunk-VLHNZJBG.js";
33
+
34
+ // src/_streaming.ts
35
+ var SILENTLY_IGNORED = /* @__PURE__ */ new Set([
36
+ "heartbeat",
37
+ "ws_chunk",
38
+ "unknown",
39
+ "tool_start",
40
+ "tool_end",
41
+ "tool_chunk",
42
+ "agent_thinking",
43
+ "warning",
44
+ "selected_final_content"
45
+ ]);
46
+ function parseLine(line) {
47
+ if (!line.startsWith("data:")) return void 0;
48
+ const raw = line.slice(5).trimStart();
49
+ if (!raw || raw === "[DONE]") return void 0;
50
+ try {
51
+ const data = JSON.parse(raw);
52
+ if (data && typeof data === "object" && !Array.isArray(data)) {
53
+ return data;
54
+ }
55
+ } catch {
56
+ return void 0;
57
+ }
58
+ return void 0;
59
+ }
60
+ function isAsyncIterable(value) {
61
+ return Symbol.asyncIterator in Object(value);
62
+ }
63
+ function* parseData(data) {
64
+ const eventType = typeof data.type === "string" ? data.type : "unknown";
65
+ if (eventType === "token") {
66
+ const event = {
67
+ type: "token",
68
+ content: typeof data.content === "string" ? data.content : ""
69
+ };
70
+ yield event;
71
+ } else if (eventType === "done") {
72
+ const event = {
73
+ type: "done",
74
+ runId: typeof data.runId === "string" ? data.runId : "",
75
+ threadId: typeof data.threadId === "string" ? data.threadId : ""
76
+ };
77
+ yield event;
78
+ } else if (eventType === "error") {
79
+ const msg = data.error ?? data.message ?? data.content ?? "Unknown run error";
80
+ const event = { type: "error", message: String(msg) };
81
+ yield event;
82
+ } else if (eventType === "cancelled") {
83
+ const event = { type: "cancelled" };
84
+ yield event;
85
+ } else if (eventType === "stream_timeout") {
86
+ const event = { type: "stream_timeout" };
87
+ yield event;
88
+ } else if (eventType === "assistant_content_reset") {
89
+ if (typeof data.content !== "string") return;
90
+ const event = {
91
+ type: "assistant_content_reset",
92
+ content: data.content,
93
+ ...typeof data.visibleContent === "string" ? { visibleContent: data.visibleContent } : {},
94
+ attempt: typeof data.attempt === "number" ? data.attempt : 1,
95
+ reason: "provider_stream_failed"
96
+ };
97
+ yield event;
98
+ } else if (!SILENTLY_IGNORED.has(eventType)) {
99
+ return;
100
+ }
101
+ }
102
+ function* parseSyncSseLines(lines) {
103
+ for (const line of lines) {
104
+ const data = parseLine(line);
105
+ if (data !== void 0) yield* parseData(data);
106
+ }
107
+ }
108
+ async function* parseAsyncSseLines(lines) {
109
+ for await (const line of lines) {
110
+ const data = parseLine(line);
111
+ if (data !== void 0) yield* parseData(data);
112
+ }
113
+ }
114
+ function parseSseStream(lines) {
115
+ return isAsyncIterable(lines) ? parseAsyncSseLines(lines) : parseSyncSseLines(lines);
116
+ }
117
+
118
+ // src/_chat.ts
119
+ function effectiveThreadId(threadId) {
120
+ if (threadId === void 0) return void 0;
121
+ if (!threadId.trim()) return void 0;
122
+ return threadId;
123
+ }
124
+ function chatPath(resource, resourceId, options) {
125
+ const safeId = encodeURIComponent(String(resourceId));
126
+ const suffix = options.stream ? "/stream" : "";
127
+ const tid = effectiveThreadId(options.threadId);
128
+ if (tid !== void 0) {
129
+ const safeTid = encodeURIComponent(tid);
130
+ return `/api/v1/${resource}/${safeId}/conversations/${safeTid}/chat${suffix}`;
131
+ }
132
+ return `/api/v1/${resource}/${safeId}/chat${suffix}`;
133
+ }
134
+ function modusChatPath(options) {
135
+ const suffix = options.stream ? "/stream" : "";
136
+ const tid = effectiveThreadId(options.threadId);
137
+ if (tid !== void 0) {
138
+ validateId(tid, "thread_id");
139
+ return `/api/v1/modus/conversations/${encodeURIComponent(tid)}/chat${suffix}`;
140
+ }
141
+ return `/api/v1/modus/chat${suffix}`;
142
+ }
143
+ function chatBody(message, model) {
144
+ return { message, model };
145
+ }
146
+ function raiseForEvent(event) {
147
+ if (event.type === "error") throw new ModusError(event.message);
148
+ if (event.type === "cancelled") throw new RunCancelledError();
149
+ if (event.type === "stream_timeout") throw new StreamTimeoutError();
150
+ return event;
151
+ }
152
+ var ChatStream = class {
153
+ constructor(http, path, body) {
154
+ this.http = http;
155
+ this.path = path;
156
+ this.body = body;
157
+ this.textParts = [];
158
+ }
159
+ async *textStream() {
160
+ for await (const event of this.events(false)) {
161
+ if (event.type === "token") yield event.content;
162
+ }
163
+ }
164
+ async *eventStream() {
165
+ yield* this.events(true);
166
+ }
167
+ async *events(supportsReset) {
168
+ const body = supportsReset ? { ...this.body, streamProtocolVersion: 2 } : this.body;
169
+ for await (const line of this.http.streamPost(this.path, body)) {
170
+ for (const event of parseSseStream([line])) {
171
+ const normalized = raiseForEvent(event);
172
+ if (normalized.type === "token") this.textParts.push(normalized.content);
173
+ if (normalized.type === "assistant_content_reset") {
174
+ this.textParts.length = 0;
175
+ this.textParts.push(normalized.content);
176
+ }
177
+ if (normalized.type === "done") {
178
+ this.final = {
179
+ content: this.textParts.join(""),
180
+ threadId: normalized.threadId,
181
+ runId: normalized.runId
182
+ };
183
+ yield normalized;
184
+ return;
185
+ }
186
+ yield normalized;
187
+ }
188
+ }
189
+ }
190
+ getFinalResult() {
191
+ if (this.final === void 0) {
192
+ throw new ModusError(
193
+ "Stream ended without a done event; call getFinalResult() only after consuming textStream() or eventStream()."
194
+ );
195
+ }
196
+ return this.final;
197
+ }
198
+ };
199
+ async function chatBuffered(http, resource, resourceId, message, options) {
200
+ validateId(resourceId, `${resource}_id`);
201
+ validateChatModel(options.model);
202
+ const path = chatPath(resource, resourceId, {
203
+ threadId: options.threadId,
204
+ stream: false
205
+ });
206
+ const data = await http.post(path, chatBody(message, options.model));
207
+ return data;
208
+ }
209
+ function chatStreamSession(http, resource, resourceId, message, options) {
210
+ validateId(resourceId, `${resource}_id`);
211
+ validateChatModel(options.model);
212
+ const path = chatPath(resource, resourceId, {
213
+ threadId: options.threadId,
214
+ stream: true
215
+ });
216
+ return new ChatStream(http, path, chatBody(message, options.model));
217
+ }
218
+ async function modusChatBuffered(http, message, options) {
219
+ validateChatModel(options.model);
220
+ const path = modusChatPath({ threadId: options.threadId, stream: false });
221
+ const data = await http.post(path, chatBody(message, options.model));
222
+ return data;
223
+ }
224
+ function modusChatStreamSession(http, message, options) {
225
+ validateChatModel(options.model);
226
+ const path = modusChatPath({ threadId: options.threadId, stream: true });
227
+ return new ChatStream(http, path, chatBody(message, options.model));
228
+ }
229
+
230
+ // src/types/conversations.ts
231
+ function conversationSkillId(item) {
232
+ return item.skillId === 0 ? void 0 : item.skillId;
233
+ }
234
+
235
+ // src/resources/agents/runs.ts
236
+ var RUNS_MAX_PAGE_SIZE = 100;
237
+ function runsListParams(pageSize, pageToken, status, timeframe, approvalScope, search) {
238
+ const params = { pageSize };
239
+ const token = normalizePageToken(pageToken);
240
+ if (token !== void 0) params.pageToken = token;
241
+ if (status !== void 0) params.status = status;
242
+ if (timeframe !== void 0) params.timeframe = timeframe;
243
+ if (approvalScope !== void 0) params.approvalScope = approvalScope;
244
+ if (search !== void 0) params.search = search;
245
+ return params;
246
+ }
247
+ function activeRunsParams(pageSize, pageToken) {
248
+ const params = { pageSize };
249
+ const token = normalizePageToken(pageToken);
250
+ if (token !== void 0) params.pageToken = token;
251
+ return params;
252
+ }
253
+ function parseRun(raw) {
254
+ return raw;
255
+ }
256
+ function parseActiveRunsArray(raw) {
257
+ const data = asRecord(raw);
258
+ const runs = data.runs;
259
+ if (!Array.isArray(runs)) {
260
+ throw new ModusError(
261
+ `Unexpected active runs response shape: runs must be a list, got ${typeof runs}.`
262
+ );
263
+ }
264
+ return runs;
265
+ }
266
+ function parseActiveRunsPage(raw, fetchPage) {
267
+ const data = asRecord(raw);
268
+ const runs = data.runs;
269
+ if (!Array.isArray(runs)) {
270
+ throw new ModusError(
271
+ `Unexpected active runs response shape: runs must be a list, got ${typeof runs}.`
272
+ );
273
+ }
274
+ return new Page(
275
+ runs,
276
+ normalizePageToken(
277
+ typeof data.nextPageToken === "string" ? data.nextPageToken : void 0
278
+ ),
279
+ fetchPage
280
+ );
281
+ }
282
+ function randomRunId() {
283
+ return crypto.randomUUID();
284
+ }
285
+ var WorkflowRunsResource = class {
286
+ constructor(http, config) {
287
+ this.http = http;
288
+ this.config = config;
289
+ }
290
+ list(workflowId, options = {}) {
291
+ validateId(workflowId, "workflow_id");
292
+ const pageSize = options.pageSize ?? 25;
293
+ validatePageSize(pageSize, RUNS_MAX_PAGE_SIZE);
294
+ return this.listPage(workflowId, pageSize, options.pageToken, options);
295
+ }
296
+ async listPage(workflowId, pageSize, pageToken, filters) {
297
+ const data = asRecord(
298
+ await invokeWithRetry(this.config, this.http, "WorkflowRunsController_list", {
299
+ pathParams: { id: workflowId },
300
+ query: runsListParams(
301
+ pageSize,
302
+ pageToken,
303
+ filters.status,
304
+ filters.timeframe,
305
+ filters.approvalScope,
306
+ filters.search
307
+ )
308
+ })
309
+ );
310
+ const runs = data.runs;
311
+ if (!Array.isArray(runs)) {
312
+ throw new ModusError(
313
+ `Unexpected list response shape: runs must be a list, got ${typeof runs}.`
314
+ );
315
+ }
316
+ return new Page(
317
+ runs,
318
+ normalizePageToken(
319
+ typeof data.nextPageToken === "string" ? data.nextPageToken : void 0
320
+ ),
321
+ (token) => this.listPage(workflowId, pageSize, token, filters)
322
+ );
323
+ }
324
+ async get(workflowId, runId, options = {}) {
325
+ validateId(workflowId, "workflow_id");
326
+ if (!runId.trim()) throw new Error("run_id must be a non-empty string");
327
+ const query = options.temporalRunId !== void 0 ? { temporalRunId: options.temporalRunId } : void 0;
328
+ const data = await invokeWithRetry(this.config, this.http, "WorkflowRunsController_get", {
329
+ pathParams: { id: workflowId, runId },
330
+ query
331
+ });
332
+ return parseRun(data);
333
+ }
334
+ async create(workflowId, body, options = {}) {
335
+ validateId(workflowId, "workflow_id");
336
+ return this.createRun("WorkflowRunsController_create", body, { id: workflowId }, options);
337
+ }
338
+ async createScope(scopeId, body, options = {}) {
339
+ validateId(scopeId, "scope_id");
340
+ return this.createRun("ScopeRunsController_create", body, { id: scopeId }, options);
341
+ }
342
+ async createModus(body, options = {}) {
343
+ return this.createRun("ModusRunsController_create", body, {}, options);
344
+ }
345
+ async resume(runId, body, options = {}) {
346
+ validateId(runId, "run_id");
347
+ return this.createRun("ResumeRunsController_create", body, { runId }, options);
348
+ }
349
+ async cancel(runId) {
350
+ validateId(runId, "run_id");
351
+ await invokeWithRetry(this.config, this.http, "RunLifecycleController_cancel", {
352
+ pathParams: { runId },
353
+ jsonBody: {}
354
+ });
355
+ }
356
+ async events(runId) {
357
+ validateId(runId, "run_id");
358
+ return invokeWithRetry(this.config, this.http, "RunLifecycleController_events", {
359
+ pathParams: { runId }
360
+ });
361
+ }
362
+ async interrupt(runId) {
363
+ validateId(runId, "run_id");
364
+ await invokeWithRetry(this.config, this.http, "RunLifecycleController_interrupt", {
365
+ pathParams: { runId },
366
+ jsonBody: {}
367
+ });
368
+ }
369
+ async editQueued(runId) {
370
+ validateId(runId, "run_id");
371
+ await invokeWithRetry(this.config, this.http, "RunLifecycleController_editQueued", {
372
+ pathParams: { runId },
373
+ jsonBody: {}
374
+ });
375
+ }
376
+ active(options = {}) {
377
+ const pageSize = options.pageSize ?? 50;
378
+ validatePageSize(pageSize, RUNS_MAX_PAGE_SIZE);
379
+ return this.activePage(pageSize, options.pageToken);
380
+ }
381
+ async activePage(pageSize, pageToken) {
382
+ return parseActiveRunsPage(
383
+ await invokeWithRetry(this.config, this.http, "RunLifecycleController_active", {
384
+ query: activeRunsParams(pageSize, pageToken)
385
+ }),
386
+ (token) => this.activePage(pageSize, token)
387
+ );
388
+ }
389
+ async activeBySession(sessionIds) {
390
+ const uniqueSessionIds = [...new Set(sessionIds.map((id) => id.trim()).filter(Boolean))];
391
+ if (uniqueSessionIds.length > 100) {
392
+ throw new Error("sessionIds must contain at most 100 ids");
393
+ }
394
+ return parseActiveRunsArray(
395
+ await invokeWithRetry(this.config, this.http, "RunLifecycleController_activeBySession", {
396
+ jsonBody: { sessionIds: uniqueSessionIds }
397
+ })
398
+ );
399
+ }
400
+ stream(runId, options = {}) {
401
+ validateId(runId, "run_id");
402
+ const op = getOperation("RunLifecycleController_stream");
403
+ const path = formatOperationPath("RunLifecycleController_stream", { runId });
404
+ const lines = this.http.streamGet(path, void 0, {
405
+ baseUrl: operationBaseUrl(this.http, op),
406
+ headers: options.lastEventId ? { "Last-Event-ID": options.lastEventId } : void 0
407
+ });
408
+ return { runId, events: this.parseEvents(lines) };
409
+ }
410
+ createRun(operationId, body, pathParams, options) {
411
+ const runId = options.idempotencyKey?.trim() || body.runId?.trim() || randomRunId();
412
+ const op = getOperation(operationId);
413
+ const path = formatOperationPath(operationId, pathParams);
414
+ const lines = this.http.streamPost(path, {
415
+ ...body,
416
+ streamProtocolVersion: 2
417
+ }, {
418
+ baseUrl: operationBaseUrl(this.http, op),
419
+ headers: { "Idempotency-Key": runId }
420
+ });
421
+ return { runId, events: this.parseEvents(lines) };
422
+ }
423
+ async *parseEvents(lines) {
424
+ yield* parseSseStream(lines);
425
+ }
426
+ };
427
+
428
+ // src/resources/agents/workflow-actions.ts
429
+ function randomRunId2() {
430
+ return crypto.randomUUID();
431
+ }
432
+ var AgentWorkflowActionsResource = class {
433
+ constructor(http, config) {
434
+ this.http = http;
435
+ this.config = config;
436
+ }
437
+ async execute(body, options = {}) {
438
+ const runId = options.idempotencyKey?.trim() || body.runId?.trim() || randomRunId2();
439
+ const op = getOperation("WorkflowActionsController_execute");
440
+ const path = formatOperationPath("WorkflowActionsController_execute");
441
+ const lines = this.http.streamPost(path, body, {
442
+ baseUrl: operationBaseUrl(this.http, op),
443
+ headers: { "Idempotency-Key": runId }
444
+ });
445
+ return { runId, events: this.parseEvents(lines) };
446
+ }
447
+ async cancel(runId) {
448
+ validateId(runId, "run_id");
449
+ await invokeWithRetry(this.config, this.http, "WorkflowActionsController_cancel", {
450
+ pathParams: { runId },
451
+ jsonBody: {}
452
+ });
453
+ }
454
+ async *parseEvents(lines) {
455
+ yield* parseSseStream(lines);
456
+ }
457
+ };
458
+
459
+ // src/resources/agents.ts
460
+ function workflowsListParams(pageSize, pageToken, search, type, view, includeVariation) {
461
+ const extra = {};
462
+ if (search !== void 0) extra.search = search;
463
+ if (type !== void 0) extra.type = type;
464
+ if (view !== void 0) extra.view = view;
465
+ if (includeVariation !== void 0) extra.includeVariation = includeVariation;
466
+ return aipListParams(pageSize, pageToken, extra);
467
+ }
468
+ function parseWorkflow(raw) {
469
+ return raw;
470
+ }
471
+ var WorkflowsResource = class {
472
+ constructor(http, config) {
473
+ this.http = http;
474
+ this.config = config;
475
+ this.runs = new WorkflowRunsResource(http, config);
476
+ this.workflowActions = new AgentWorkflowActionsResource(http, config);
477
+ }
478
+ list(options = {}) {
479
+ const pageSize = options.pageSize ?? 25;
480
+ validatePageSize(pageSize);
481
+ return this.listPage(
482
+ pageSize,
483
+ options.pageToken,
484
+ options.search,
485
+ options.type,
486
+ options.view,
487
+ options.includeVariation
488
+ );
489
+ }
490
+ async listPage(pageSize, pageToken, search, type, view, includeVariation) {
491
+ const data = asRecord(
492
+ await invokeWithRetry(this.config, this.http, "WorkflowsController_list", {
493
+ query: workflowsListParams(
494
+ pageSize,
495
+ pageToken,
496
+ search,
497
+ type,
498
+ view,
499
+ includeVariation
500
+ )
501
+ })
502
+ );
503
+ return buildAipPage(
504
+ data,
505
+ "agents",
506
+ parseWorkflow,
507
+ (token) => this.listPage(pageSize, token, search, type, view, includeVariation)
508
+ );
509
+ }
510
+ async get(workflowId, options = {}) {
511
+ validateId(workflowId, "workflow_id");
512
+ const query = {};
513
+ if (options.view !== void 0) query.view = options.view;
514
+ if (options.includeVariation !== void 0) {
515
+ query.includeVariation = options.includeVariation;
516
+ }
517
+ const data = await invokeWithRetry(this.config, this.http, "WorkflowsController_get", {
518
+ pathParams: { id: workflowId },
519
+ query: Object.keys(query).length > 0 ? query : void 0
520
+ });
521
+ return parseWorkflow(data);
522
+ }
523
+ };
524
+
525
+ // src/resources/connections.ts
526
+ function connectionsListParams(pageSize, pageToken, type) {
527
+ const extra = {};
528
+ if (type !== void 0) extra.type = type;
529
+ return aipListParams(pageSize, pageToken, extra);
530
+ }
531
+ function parseConnection(raw) {
532
+ return raw;
533
+ }
534
+ var ConnectionsResource = class {
535
+ constructor(http, config) {
536
+ this.http = http;
537
+ this.config = config;
538
+ }
539
+ list(options = {}) {
540
+ const pageSize = options.pageSize ?? 25;
541
+ validatePageSize(pageSize);
542
+ return this.listPage(pageSize, options.pageToken, options.type);
543
+ }
544
+ async listPage(pageSize, pageToken, type) {
545
+ const data = asRecord(
546
+ await invokeWithRetry(this.config, this.http, "ConnectionsController_list", {
547
+ query: connectionsListParams(pageSize, pageToken, type)
548
+ })
549
+ );
550
+ return buildAipPage(
551
+ data,
552
+ "connections",
553
+ parseConnection,
554
+ (token) => this.listPage(pageSize, token, type)
555
+ );
556
+ }
557
+ async find(options) {
558
+ const pageSize = options.pageSize ?? 25;
559
+ validatePageSize(pageSize);
560
+ const target = options.name.trim().toLowerCase();
561
+ let token;
562
+ do {
563
+ const page = await this.listPage(pageSize, token, options.type);
564
+ const match = page.items.find((c) => c.name?.toLowerCase() === target);
565
+ if (match) return match;
566
+ if (!page.hasNextPage()) break;
567
+ token = page.nextPageToken;
568
+ } while (token !== void 0);
569
+ return void 0;
570
+ }
571
+ };
572
+
573
+ // src/resources/context/items.ts
574
+ function contextListParams(pageSize, pageToken, contextType) {
575
+ const extra = {};
576
+ if (contextType !== void 0) extra.contextTypes = [contextType];
577
+ return aipListParams(pageSize, pageToken, extra);
578
+ }
579
+ function parseContextItem(raw) {
580
+ return raw;
581
+ }
582
+ function parseContextValueRow(raw) {
583
+ return raw;
584
+ }
585
+ function parseLookupResponse(raw) {
586
+ const item = raw.item;
587
+ if (item === null || item === void 0) return void 0;
588
+ return item;
589
+ }
590
+ var ContextItemsResource = class {
591
+ constructor(http, config) {
592
+ this.http = http;
593
+ this.config = config;
594
+ }
595
+ list(options = {}) {
596
+ const pageSize = options.pageSize ?? 25;
597
+ validatePageSize(pageSize);
598
+ return this.listPage(pageSize, options.pageToken, options.contextType);
599
+ }
600
+ async listPage(pageSize, pageToken, contextType) {
601
+ const data = asRecord(
602
+ await invokeWithRetry(this.config, this.http, "ContextItemsController_list", {
603
+ query: contextListParams(pageSize, pageToken, contextType)
604
+ })
605
+ );
606
+ return buildAipPage(
607
+ data,
608
+ "contextItems",
609
+ parseContextItem,
610
+ (token) => this.listPage(pageSize, token, contextType)
611
+ );
612
+ }
613
+ async get(uid) {
614
+ const data = await invokeWithRetry(this.config, this.http, "ContextItemsController_get", {
615
+ pathParams: { uid }
616
+ });
617
+ return parseContextItem(data);
618
+ }
619
+ async lookup(options) {
620
+ const body = omitUndefined({
621
+ contextType: options.contextType,
622
+ dataPath: options.dataPath,
623
+ contentProjection: options.contentProjection
624
+ });
625
+ try {
626
+ const raw = asRecord(
627
+ await invokeWithRetry(this.config, this.http, "ContextItemsController_lookup", {
628
+ jsonBody: body
629
+ })
630
+ );
631
+ return parseLookupResponse(raw);
632
+ } catch (error) {
633
+ if (error instanceof NotFoundError) return void 0;
634
+ throw error;
635
+ }
636
+ }
637
+ listValues(uid, contextType, contentKeyPath, options = {}) {
638
+ const pageSize = options.pageSize ?? 25;
639
+ validatePageSize(pageSize, DEFAULT_MAX_PAGE_SIZE);
640
+ return this.listValuesPage(uid, contextType, contentKeyPath, pageSize, options.pageToken);
641
+ }
642
+ listValuesFor(item, contentKeyPath, options = {}) {
643
+ return this.listValues(item.uid, item.contextType, contentKeyPath, options);
644
+ }
645
+ async listValuesPage(uid, contextType, contentKeyPath, pageSize, pageToken) {
646
+ const data = asRecord(
647
+ await invokeWithRetry(this.config, this.http, "ContextItemsController_listValues", {
648
+ pathParams: { uid },
649
+ query: aipListParams(pageSize, pageToken, {
650
+ contextType,
651
+ contentKeyPath
652
+ })
653
+ })
654
+ );
655
+ return buildAipPage(
656
+ data,
657
+ "values",
658
+ parseContextValueRow,
659
+ (token) => this.listValuesPage(uid, contextType, contentKeyPath, pageSize, token)
660
+ );
661
+ }
662
+ };
663
+
664
+ // src/resources/context/context.ts
665
+ var ContextResource = class {
666
+ constructor(http, config) {
667
+ this.items = new ContextItemsResource(http, config);
668
+ this.customItems = new CustomContextItemsResource(http, config);
669
+ }
670
+ };
671
+
672
+ // src/resources/modus/conversations.ts
673
+ var ALLOWED_KINDS = /* @__PURE__ */ new Set(["all", "modus", "skills"]);
674
+ function listParams(pageSize, pageToken, kind) {
675
+ if (kind !== void 0 && !ALLOWED_KINDS.has(kind)) {
676
+ throw new Error(
677
+ `kind must be one of ${[...ALLOWED_KINDS].sort().join(", ")}, got ${JSON.stringify(kind)}`
678
+ );
679
+ }
680
+ const extra = {};
681
+ if (kind !== void 0) extra.kind = kind;
682
+ return aipListParams(pageSize, pageToken, extra);
683
+ }
684
+ function parseListItem(raw) {
685
+ return raw;
686
+ }
687
+ function parseConversation(raw) {
688
+ return raw;
689
+ }
690
+ var ModusConversationsResource = class {
691
+ constructor(http, config) {
692
+ this.http = http;
693
+ this.config = config;
694
+ }
695
+ list(options = {}) {
696
+ const pageSize = options.pageSize ?? 25;
697
+ validatePageSize(pageSize);
698
+ return this.listPage(pageSize, options.pageToken, options.kind);
699
+ }
700
+ async listPage(pageSize, pageToken, kind) {
701
+ const data = asRecord(
702
+ await invokeWithRetry(this.config, this.http, "ModusConversationsController_list", {
703
+ query: listParams(pageSize, pageToken, kind)
704
+ })
705
+ );
706
+ return buildAipPage(
707
+ data,
708
+ "conversations",
709
+ parseListItem,
710
+ (token) => this.listPage(pageSize, token, kind)
711
+ );
712
+ }
713
+ async get(threadId) {
714
+ validateId(threadId, "thread_id");
715
+ const data = await invokeWithRetry(this.config, this.http, "ModusConversationsController_get", {
716
+ pathParams: { threadId }
717
+ });
718
+ return parseConversation(data);
719
+ }
720
+ };
721
+
722
+ // src/resources/modus/modus.ts
723
+ var ModusResource = class {
724
+ constructor(http, config) {
725
+ this.http = http;
726
+ this.config = config;
727
+ this.conversations = new ModusConversationsResource(http, config);
728
+ }
729
+ async getContext(message, options = {}) {
730
+ const data = await invokeWithRetry(this.config, this.http, "ModusContextController_compose", {
731
+ jsonBody: omitUndefined({ message, limit: options.limit })
732
+ });
733
+ return data;
734
+ }
735
+ chat(message, options) {
736
+ return modusChatBuffered(this.http, message, options);
737
+ }
738
+ chatStream(message, options) {
739
+ return modusChatStreamSession(this.http, message, options);
740
+ }
741
+ };
742
+
743
+ // src/resources/skills.ts
744
+ function scopesListParams(pageSize, pageToken, search, view, managerId) {
745
+ const extra = {};
746
+ if (search !== void 0) extra.search = search;
747
+ if (view !== void 0) extra.view = view;
748
+ if (managerId !== void 0) extra.managerId = managerId;
749
+ return aipListParams(pageSize, pageToken, extra);
750
+ }
751
+ function parseScope(raw) {
752
+ return raw;
753
+ }
754
+ var ScopesResource = class {
755
+ constructor(http, config) {
756
+ this.http = http;
757
+ this.config = config;
758
+ }
759
+ conversations(scopeId) {
760
+ return new ScopeConversationsResource(this.http, this.config, scopeId);
761
+ }
762
+ list(options = {}) {
763
+ const pageSize = options.pageSize ?? 25;
764
+ validatePageSize(pageSize);
765
+ return this.listPage(
766
+ pageSize,
767
+ options.pageToken,
768
+ options.search,
769
+ options.view,
770
+ options.managerId
771
+ );
772
+ }
773
+ async listPage(pageSize, pageToken, search, view, managerId) {
774
+ const data = asRecord(
775
+ await invokeWithRetry(this.config, this.http, "ScopesController_list", {
776
+ query: scopesListParams(pageSize, pageToken, search, view, managerId)
777
+ })
778
+ );
779
+ return buildAipPage(
780
+ data,
781
+ "skills",
782
+ parseScope,
783
+ (token) => this.listPage(pageSize, token, search, view, managerId)
784
+ );
785
+ }
786
+ async get(scopeId, options = {}) {
787
+ validateId(scopeId, "scope_id");
788
+ const query = options.view !== void 0 ? { view: options.view } : void 0;
789
+ const data = await invokeWithRetry(this.config, this.http, "ScopesController_get", {
790
+ pathParams: { id: scopeId },
791
+ query
792
+ });
793
+ return parseScope(data);
794
+ }
795
+ async getContext(scopeId, message, options = {}) {
796
+ validateId(scopeId, "scope_id");
797
+ const data = await invokeWithRetry(this.config, this.http, "ScopeContextController_compose", {
798
+ pathParams: { id: scopeId },
799
+ jsonBody: omitUndefined({ message, limit: options.limit })
800
+ });
801
+ return data;
802
+ }
803
+ chat(scopeId, message, options) {
804
+ return chatBuffered(this.http, "scopes", scopeId, message, options);
805
+ }
806
+ chatStream(scopeId, message, options) {
807
+ return chatStreamSession(this.http, "scopes", scopeId, message, options);
808
+ }
809
+ };
810
+
811
+ // src/resources/suggestions.ts
812
+ var DEFAULT_SUGGESTIONS_PAGE_SIZE = 5;
813
+ var MAX_SUGGESTIONS_PAGE_SIZE = 12;
814
+ function parseSuggestion(raw) {
815
+ return raw;
816
+ }
817
+ function suggestionListParams(options) {
818
+ return {
819
+ pageSize: options.pageSize,
820
+ pageToken: options.pageToken,
821
+ skill_id: options.skillId,
822
+ skill_ids: options.skillIds?.join(",")
823
+ };
824
+ }
825
+ var SuggestionsResource = class {
826
+ constructor(http, config) {
827
+ this.http = http;
828
+ this.config = config;
829
+ }
830
+ list(options = {}) {
831
+ const pageSize = options.pageSize ?? DEFAULT_SUGGESTIONS_PAGE_SIZE;
832
+ validatePageSize(pageSize, MAX_SUGGESTIONS_PAGE_SIZE);
833
+ return this.listPage(pageSize, options.pageToken, options.skillId, options.skillIds);
834
+ }
835
+ async listPage(pageSize, pageToken, skillId, skillIds) {
836
+ const data = asRecord(
837
+ await invokeWithRetry(this.config, this.http, "SuggestionsController_listApproved", {
838
+ query: suggestionListParams({ pageSize, pageToken, skillId, skillIds })
839
+ })
840
+ );
841
+ return buildAipPage(
842
+ data,
843
+ "suggestions",
844
+ parseSuggestion,
845
+ (token) => this.listPage(pageSize, token, skillId, skillIds)
846
+ );
847
+ }
848
+ async recordEvent(id, event) {
849
+ validateId(id, "id");
850
+ await invokeWithRetry(this.config, this.http, "SuggestionsController_recordEvent", {
851
+ pathParams: { id },
852
+ jsonBody: event
853
+ });
854
+ }
855
+ };
856
+
857
+ // src/index.ts
858
+ var Modus = class extends ModusClientBase {
859
+ constructor(options = {}) {
860
+ super(options);
861
+ this.scopes = new ScopesResource(this.http, this.config);
862
+ this.modus = new ModusResource(this.http, this.config);
863
+ this.workflows = new WorkflowsResource(this.http, this.config);
864
+ this.context = new ContextResource(this.http, this.config);
865
+ this.connections = new ConnectionsResource(this.http, this.config);
866
+ this.suggestions = new SuggestionsResource(this.http, this.config);
867
+ }
868
+ };
869
+ export {
870
+ APIConnectionError,
871
+ AuthenticationError,
872
+ ChatStream,
873
+ ConflictError,
874
+ InternalServerError,
875
+ Modus,
876
+ ModusError,
877
+ NotFoundError,
878
+ OPERATIONS,
879
+ Page,
880
+ PermissionDeniedError,
881
+ RateLimitError,
882
+ RunCancelledError,
883
+ StreamTimeoutError,
884
+ UnprocessableError,
885
+ ValidationError,
886
+ conversationSkillId
887
+ };
888
+ //# sourceMappingURL=index.js.map