@getmodus/sdk 0.9.0 → 0.11.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.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { c as components, H as HttpClient, M as ModusConfig, P as Page, W as WorkflowType, V as VariationView, a as Workflow, C as ContextItem, b as ContextItemLookupRow, d as CustomContextItemsResource, e as Conversation, f as ConversationKind, g as ConversationListItem, S as Scope, h as ScopeConversationsResource, i as ModusClientBase, j as ModusOptions } from './conversations-D7ffhHIh.cjs';
2
- export { A as Agent, k as AgentType, l as ContextItemAncestor, m as ContextItemDeletion, n as ContextItemMove, o as ContextType, p as Message, O as OPERATIONS, q as OperationId, r as OperationSpec, s as ScopeStatus, t as ScopeVariation, u as Skill, v as SkillStatus, w as SkillVariation, x as conversationScopeId, y as conversationSkillId, z as operations, B as paths } from './conversations-D7ffhHIh.cjs';
1
+ import { H as HttpClient, c as components, M as ModusConfig, P as Page, V as VariationView, S as Scope, a as ScopeConversationsResource, C as Conversation, b as ConversationKind, d as ConversationListItem, W as WorkflowType, e as Workflow, f as ContextItemsQuery, g as ContextItemsQueryResult, h as ContextItem, i as ContextItemLookupRow, j as CustomContextItemsResource, k as ModusClientBase, l as ModusOptions } from './_client-base-DdnxB9JA.cjs';
2
+ export { A as Agent, m as AgentType, n as ContextItemAccessUpdate, o as ContextItemAncestor, p as ContextItemDeletion, q as ContextItemMove, r as ContextType, s as CreateCustomContextItemInput, t as CreatedCustomContextItem, u as CustomAttributeInput, v as CustomContextItemDeletion, w as CustomContextItemKind, x as CustomContextItemRelationInput, y as Message, O as OPERATIONS, z as OperationId, B as OperationSpec, D as ScopeStatus, E as ScopeVariation, F as Skill, G as SkillStatus, I as SkillVariation, J as SupervisionView, U as UpdateContextItemAccessInput, K as UpdateCustomContextItemInput, L as conversationScopeId, N as conversationSkillId, Q as operations, R as paths } from './_client-base-DdnxB9JA.cjs';
3
3
 
4
4
  /**
5
5
  * Base class for all Modus SDK errors.
@@ -9,16 +9,36 @@ export { A as Agent, k as AgentType, l as ContextItemAncestor, m as ContextItemD
9
9
  */
10
10
  declare class ModusError extends Error {
11
11
  readonly statusCode?: number;
12
+ /** The `requestId` of the error envelope (or the `x-request-id` header); quote it to support. */
12
13
  readonly requestId?: string;
14
+ /**
15
+ * The W3C trace id of the request that failed (from the `traceparent` the SDK sent). Quote
16
+ * it with `requestId`: it also names a request that never reached Modus, and every retry of it.
17
+ */
18
+ readonly traceId?: string;
13
19
  readonly responseHeaders?: Record<string, string>;
14
20
  readonly body?: string;
21
+ /** Machine-readable error code from the envelope, e.g. `NOT_FOUND`, `VALIDATION`. */
15
22
  readonly code?: string;
23
+ /** Structured detail from the envelope, e.g. `{ missing: ['scopes:write'] }` on a 403. */
24
+ readonly info?: Record<string, unknown>;
25
+ /**
26
+ * Whether the SDK's retry rule allows re-sending this call. True for a 429 whose
27
+ * `Retry-After` is absent or at most 60 s, and for a connection that never opened. For
28
+ * 408, 500, 502, 503, 504, a dropped connection or a timeout: true on GET, PUT, PATCH and
29
+ * DELETE and on POSTs that only read or set a state, false on any other POST, which may
30
+ * already have run. The SDK already retried a retryable error up to `maxRetries` times.
31
+ */
32
+ readonly retryable: boolean;
16
33
  constructor(message: string, options?: {
17
34
  statusCode?: number;
18
35
  requestId?: string;
36
+ traceId?: string;
19
37
  responseHeaders?: Record<string, string>;
20
38
  body?: string;
21
39
  code?: string;
40
+ info?: Record<string, unknown>;
41
+ retryable?: boolean;
22
42
  });
23
43
  }
24
44
  /**
@@ -26,7 +46,18 @@ declare class ModusError extends Error {
26
46
  * automatic retries are exhausted.
27
47
  */
28
48
  declare class APIConnectionError extends ModusError {
29
- constructor(message: string);
49
+ constructor(message: string, options?: {
50
+ retryable?: boolean;
51
+ traceId?: string;
52
+ });
53
+ }
54
+ /**
55
+ * The request was malformed (HTTP 400): a parameter or body field failed schema
56
+ * validation, an unknown property was sent, or an id was not a number. `message`
57
+ * names the field.
58
+ */
59
+ declare class BadRequestError extends ModusError {
60
+ constructor(message: string, options?: ConstructorParameters<typeof ModusError>[1]);
30
61
  }
31
62
  /**
32
63
  * The API key is missing, invalid, or expired (HTTP 401).
@@ -58,9 +89,12 @@ declare class ConflictError extends ModusError {
58
89
  constructor(message: string, options?: ConstructorParameters<typeof ModusError>[1]);
59
90
  }
60
91
  /**
61
- * Request validation failed (HTTP 422).
92
+ * The request was well-formed but failed a business rule (HTTP 422, `code: VALIDATION`),
93
+ * for example a toolset rule or a disallowed file type. Schema failures are
94
+ * {@link BadRequestError} (400) instead.
62
95
  *
63
- * Inspect `errors` when present for field-level details.
96
+ * `info` carries the rule detail when the server sends one (e.g. `info.violations`);
97
+ * `errors` is the whole parsed error envelope.
64
98
  */
65
99
  declare class UnprocessableError extends ModusError {
66
100
  readonly errors?: unknown;
@@ -71,7 +105,9 @@ declare class UnprocessableError extends ModusError {
71
105
  /**
72
106
  * Too many requests (HTTP 429).
73
107
  *
74
- * When present, `retryAfter` is the suggested wait in seconds.
108
+ * When present, `retryAfter` is the server's requested wait in whole seconds (from
109
+ * `retry-after-ms`, or `Retry-After` as seconds or an HTTP date). The SDK waits it out
110
+ * and retries when it is 60 s or less; a longer wait is thrown at once.
75
111
  */
76
112
  declare class RateLimitError extends ModusError {
77
113
  readonly retryAfter?: number;
@@ -99,20 +135,94 @@ declare class ValidationError extends ModusError {
99
135
  constructor(message: string);
100
136
  }
101
137
 
138
+ declare const CHAT_MODELS: readonly ["claude-sonnet-5", "claude-sonnet-5.5", "claude-sonnet-4.6", "claude-opus-4.8", "claude-opus-5.5", "claude-haiku-5.5", "gpt-5.2", "gpt-5.5", "gpt-5-mini", "gpt-5.6-luna", "gpt-6-luna", "gpt-oss-120b", "gpt-oss-20b", "qwen3-235b-a22b-2507", "qwen3-coder", "qwen3-32b", "deepseek-chat-v3.1", "deepseek-v4-pro", "deepseek-v4-flash-latest", "deepseek-v4.1-flash-1017", "minimax-m2.7", "llama-4-maverick", "llama-4-scout", "llama-3.3-70b-instruct", "gemini-3.1-pro-preview", "gemini-3-flash-preview", "gemini-3.8-flash", "grok-4.3-fast", "grok-4.3", "grok-4.7", "kimi-k3"];
139
+
140
+ /** Fields every run event carries. */
141
+ interface RunEventBase {
142
+ /**
143
+ * The SSE event id. Pass it as `lastEventId` to `runs.stream(runId, { lastEventId })`
144
+ * to resume after this event. Absent when the stream sent none.
145
+ */
146
+ readonly id?: string;
147
+ }
148
+ interface TokenEvent extends RunEventBase {
149
+ readonly type: 'token';
150
+ content: string;
151
+ /** Set when a sub-agent produced the token; absent for the assistant's own reply. */
152
+ subAgent?: string;
153
+ }
154
+ interface DoneEvent extends RunEventBase {
155
+ readonly type: 'done';
156
+ runId: string;
157
+ threadId: string;
158
+ /** The run's final answer. */
159
+ content?: string;
160
+ }
161
+ /**
162
+ * The run stopped for a human decision: a write tool needs approval (`toolId`,
163
+ * `toolName`, `title`, `description`, `args`) or a workflow approval node is
164
+ * waiting (`nodeId`, `prompt`, `options`).
165
+ */
166
+ interface ApprovalRequiredEvent extends RunEventBase {
167
+ readonly type: 'approval_required';
168
+ toolId?: string;
169
+ toolName?: string;
170
+ title?: string;
171
+ description?: string;
172
+ args?: Record<string, unknown>;
173
+ nodeId?: string;
174
+ prompt?: string;
175
+ options?: ReadonlyArray<{
176
+ id: string;
177
+ label: string;
178
+ }>;
179
+ }
180
+ interface ErrorEvent extends RunEventBase {
181
+ readonly type: 'error';
182
+ message: string;
183
+ /** The id to quote to support for this failure. */
184
+ requestId?: string;
185
+ }
186
+ interface CancelledEvent extends RunEventBase {
187
+ readonly type: 'cancelled';
188
+ }
189
+ interface StreamTimeoutEvent extends RunEventBase {
190
+ readonly type: 'stream_timeout';
191
+ }
192
+ interface AssistantContentResetEvent extends RunEventBase {
193
+ readonly type: 'assistant_content_reset';
194
+ content: string;
195
+ visibleContent?: string;
196
+ attempt: number;
197
+ reason: 'provider_stream_failed';
198
+ /** Set when the reset belongs to a sub-agent's timeline; absent for the assistant's own reply. */
199
+ subAgent?: Record<string, unknown>;
200
+ }
201
+ type ActiveConversationRunStatus = 'queued' | 'pending' | 'running';
202
+ interface ActiveConversationRun {
203
+ readonly runId: string;
204
+ readonly sessionId: string;
205
+ readonly status: ActiveConversationRunStatus;
206
+ readonly message?: string;
207
+ readonly createdAt: string;
208
+ readonly updatedAt: string;
209
+ }
210
+ type RunEvent = TokenEvent | DoneEvent | ErrorEvent | CancelledEvent | StreamTimeoutEvent | AssistantContentResetEvent | ApprovalRequiredEvent;
211
+
102
212
  /**
103
213
  * Canonical model id accepted by Modus chat APIs.
104
214
  *
105
- * Pass as `model` to `client.modus.chat(...)`, `client.scopes.chat(...)`,
106
- * and the matching stream methods. An unsupported value fails client-side
215
+ * Pass as `model` to `client.modus.chat(...)`, `client.scopes.chat(...)`
216
+ * or `client.workflows.chat(...)`. An unsupported value fails client-side
107
217
  * validation before the request is sent.
108
218
  *
109
219
  * Allowed values:
110
- * - `claude-sonnet-5`, `claude-sonnet-5.5`, `claude-sonnet-4.6`, `claude-opus-4.8`, `claude-opus-5.5`
220
+ * - `claude-sonnet-5`, `claude-sonnet-5.5`, `claude-sonnet-4.6`, `claude-opus-4.8`, `claude-opus-5.5`, `claude-haiku-5.5`
111
221
  * - `gpt-5.2`, `gpt-5.5`, `gpt-5-mini`, `gpt-5.6-luna`, `gpt-6-luna`, `gpt-oss-120b`, `gpt-oss-20b`
112
222
  * - `qwen3-235b-a22b-2507`, `qwen3-coder`, `qwen3-32b`
113
- * - `deepseek-chat-v3.1`, `deepseek-v4-pro`, `deepseek-v4-flash-latest`, `minimax-m2.7`
223
+ * - `deepseek-chat-v3.1`, `deepseek-v4-pro`, `deepseek-v4-flash-latest`, `deepseek-v4.1-flash-1017`, `minimax-m2.7`
114
224
  * - `llama-4-maverick`, `llama-4-scout`, `llama-3.3-70b-instruct`
115
- * - `gemini-3.1-pro-preview`, `gemini-3-flash-preview`
225
+ * - `gemini-3.1-pro-preview`, `gemini-3-flash-preview`, `gemini-3.8-flash`
116
226
  * - `grok-4.3-fast`, `grok-4.3`, `grok-4.7`, `kimi-k3`
117
227
  *
118
228
  * @example
@@ -122,19 +232,7 @@ declare class ValidationError extends ModusError {
122
232
  * })
123
233
  * ```
124
234
  */
125
- type ChatModel = components['schemas']['SkillChatRequestDto']['model'];
126
- /**
127
- * Chat request body (`message` + required `model`).
128
- *
129
- * Prefer `client.modus.chat(...)` / `client.scopes.chat(...)` — they take these
130
- * fields as method arguments so you rarely construct this type yourself.
131
- */
132
- interface ChatRequest {
133
- /** User message sent to the skill / Modus. */
134
- message: string;
135
- /** Canonical model id for this run (required). See {@link ChatModel}. */
136
- model: ChatModel;
137
- }
235
+ type ChatModel = (typeof CHAT_MODELS)[number];
138
236
  /**
139
237
  * Chat response: final assistant text plus `threadId` for follow-ups.
140
238
  */
@@ -145,99 +243,134 @@ interface ChatResult {
145
243
  threadId: string;
146
244
  /** Opaque run id for logging / correlation. */
147
245
  runId: string;
246
+ /** Set when the run stopped for a decision; continue with `ChatSession.resume`. */
247
+ approval?: ApprovalRequiredEvent;
148
248
  }
149
249
 
150
- interface TokenEvent {
151
- readonly type: 'token';
152
- content: string;
153
- }
154
- interface DoneEvent {
155
- readonly type: 'done';
156
- runId: string;
157
- threadId: string;
158
- }
159
- interface ErrorEvent {
160
- readonly type: 'error';
161
- message: string;
162
- }
163
- interface CancelledEvent {
164
- readonly type: 'cancelled';
165
- }
166
- interface StreamTimeoutEvent {
167
- readonly type: 'stream_timeout';
168
- }
169
- interface AssistantContentResetEvent {
170
- readonly type: 'assistant_content_reset';
171
- content: string;
172
- visibleContent?: string;
173
- attempt: number;
174
- reason: 'provider_stream_failed';
250
+ /** Options shared by every `chat()` method. */
251
+ interface ChatOptions {
252
+ /** Canonical model id for this run (required). See {@link ChatModel}. */
253
+ model: ChatModel;
254
+ /** Continue this conversation; omit to start a new one. */
255
+ threadId?: string;
175
256
  }
176
- type ActiveConversationRunStatus = 'queued' | 'pending' | 'running';
177
- interface ActiveConversationRun {
178
- readonly runId: string;
257
+ interface ChatRequest {
258
+ readonly path: string;
259
+ readonly body: Record<string, unknown>;
179
260
  readonly sessionId: string;
180
- readonly status: ActiveConversationRunStatus;
181
- readonly message?: string;
182
- readonly createdAt: string;
183
- readonly updatedAt: string;
261
+ readonly baseUrl: string;
184
262
  }
185
- type RunEvent = TokenEvent | DoneEvent | ErrorEvent | CancelledEvent | StreamTimeoutEvent | AssistantContentResetEvent;
186
-
187
263
  /**
188
- * Streaming chat session. Iterate {@link ChatStream.textStream} or
189
- * {@link ChatStream.eventStream}, then call {@link ChatStream.getFinalResult}.
264
+ * One chat turn, streamed live from the agent host.
265
+ *
266
+ * Iterate {@link ChatSession.textStream} for tokens as they arrive, or
267
+ * `await` the session for the final {@link ChatResult}. The request is sent
268
+ * once: iterating again, or awaiting after iterating, replays what arrived.
269
+ *
270
+ * @example
271
+ * ```ts
272
+ * const chat = client.scopes.chat(scopeId, 'What is our ARR trend?', { model: 'claude-sonnet-5.5' })
273
+ * for await (const token of chat.textStream()) process.stdout.write(token)
274
+ * const { threadId } = await chat
275
+ * ```
190
276
  */
191
- declare class ChatStream {
277
+ declare class ChatSession implements PromiseLike<ChatResult> {
192
278
  private readonly http;
193
- private readonly path;
194
- private readonly body;
195
- private readonly baseUrl?;
196
- private final?;
197
- private readonly textParts;
198
- constructor(http: HttpClient, path: string, body: Record<string, unknown>, baseUrl?: string | undefined);
279
+ private readonly request;
280
+ private readonly received;
281
+ private live;
282
+ private finished;
283
+ private failure;
284
+ private final;
285
+ private approval;
286
+ /**
287
+ * @internal A session built with `failure` never sends; every read rejects
288
+ * with it, as the promise `chat()` used to return did.
289
+ */
290
+ constructor(http: HttpClient, request: ChatRequest | undefined, failure?: unknown);
199
291
  /**
200
- * Async iterable of assistant text token chunks as they arrive.
292
+ * The assistant's reply as text chunks, as they arrive. Sub-agent output is
293
+ * left out.
201
294
  *
202
- * @returns An async generator yielding partial text strings.
203
- * @throws {ModusError} When the stream emits an error event.
295
+ * @throws {ModusError} When the run reports an error.
204
296
  * @throws {RunCancelledError} When the run is cancelled.
205
- * @throws {StreamTimeoutError} When the stream times out.
297
+ * @throws {StreamTimeoutError} When the run times out.
206
298
  */
207
299
  textStream(): AsyncGenerator<string>;
208
300
  /**
209
- * Async iterable of structured run events (tokens, tool calls, done, and so on).
301
+ * Every run event (tokens, approvals, `done`, …) as it arrives.
210
302
  *
211
- * @returns An async generator yielding {@link RunEvent} objects.
212
- * @throws {ModusError} When the stream emits an error event.
303
+ * @throws {ModusError} When the run reports an error.
213
304
  * @throws {RunCancelledError} When the run is cancelled.
214
- * @throws {StreamTimeoutError} When the stream times out.
305
+ * @throws {StreamTimeoutError} When the run times out.
215
306
  */
216
307
  eventStream(): AsyncGenerator<RunEvent>;
217
- private events;
218
308
  /**
219
- * Final chat result after the stream completes.
309
+ * Waits for the run to finish and returns its final answer. `approval` is
310
+ * set when the run stopped for a decision; continue with {@link resume}.
311
+ *
312
+ * @throws {ModusError} When the run reports an error or ends without finishing.
313
+ */
314
+ result(): Promise<ChatResult>;
315
+ /** Resolve with the final {@link ChatResult}, so the session can be awaited. */
316
+ then<TResult1 = ChatResult, TResult2 = never>(onfulfilled?: ((value: ChatResult) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): PromiseLike<TResult1 | TResult2>;
317
+ /** Handle a failed run, as on the promise `chat()` used to return. */
318
+ catch<TResult = never>(onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null): Promise<ChatResult | TResult>;
319
+ /** Run `onfinally` once the run settles, as on the promise `chat()` used to return. */
320
+ finally(onfinally?: (() => void) | null): Promise<ChatResult>;
321
+ /**
322
+ * Approve or deny the action this run stopped for, continuing the same
323
+ * conversation.
220
324
  *
221
- * Call only after fully consuming {@link ChatStream.textStream} or
222
- * {@link ChatStream.eventStream}.
325
+ * @param input.decision - `approve` or `deny`.
326
+ * @returns A new session for the continued run.
327
+ * @throws {ModusError} When called before the run has finished.
223
328
  *
224
- * @returns The assembled assistant reply, thread id, and run id.
225
- * @throws {ModusError} When called before the stream finishes with a done event.
329
+ * @example
330
+ * ```ts
331
+ * const chat = client.modus.chat('Fix the typo in accounts', { model: 'claude-sonnet-5.5' })
332
+ * const first = await chat
333
+ * if (first.approval) {
334
+ * const done = await chat.resume({ decision: 'approve' })
335
+ * }
336
+ * ```
226
337
  */
227
- getFinalResult(): ChatResult;
338
+ resume(input: {
339
+ decision: 'approve' | 'deny';
340
+ }): ChatSession;
341
+ /**
342
+ * Stop reading the run and release its connection. Call it when you stop
343
+ * iterating before the run ends; a session that reached `done` has already
344
+ * let go. The run itself keeps going on the server.
345
+ */
346
+ close(): Promise<void>;
347
+ private replay;
348
+ private open;
228
349
  }
229
350
 
230
351
  type AgentRunListItem = components['schemas']['AutomationRunListItemDto'];
231
352
  type AgentRun = components['schemas']['GetAutomationRunResponseDto'];
232
- type AgentRunCreateRequest = components['schemas']['AgentRunDto'];
233
- type SkillRunCreateRequest = components['schemas']['SkillRunDto'];
234
- type ModusRunCreateRequest = components['schemas']['ModusRunDto'];
353
+ /** A new run's body: `sessionId` is optional, because the SDK starts a new conversation when it is omitted. */
354
+ type NewRunBody<T extends {
355
+ sessionId: string;
356
+ }> = Omit<T, 'sessionId'> & {
357
+ sessionId?: string;
358
+ };
359
+ type AgentRunCreateRequest = NewRunBody<components['schemas']['AgentRunDto']>;
360
+ type SkillRunCreateRequest = NewRunBody<components['schemas']['SkillRunDto']>;
361
+ type ModusRunCreateRequest = NewRunBody<components['schemas']['ModusRunDto']>;
235
362
  type ResumeRunRequest = components['schemas']['ResumeRunDto'];
236
363
  type CreateAgentRunRequest = AgentRunCreateRequest;
237
364
  type CancelRunRequest = components['schemas']['CancelRunDto'];
238
365
  type InterruptRunRequest = components['schemas']['InterruptRunDto'];
239
366
  type EditQueuedRunRequest = components['schemas']['EditQueuedRunDto'];
367
+ /** The turn `runs.interrupt` / `runs.editQueued` send as `nextRun`. */
368
+ type FollowUpRunRequest = components['schemas']['FollowUpRunDto'];
369
+ /** The run `runs.interrupt` / `runs.editQueued` admitted. */
370
+ type RunAdmission = components['schemas']['RunAdmissionResponseDto'];
240
371
  type WorkflowActionRequest = components['schemas']['WorkflowActionDto'];
372
+ /** One `runs.events()` poll: the buffered events after the cursor, the next cursor and the run status. */
373
+ type RunEventsPollResponse = components['schemas']['RunEventsPollResponseDto'];
241
374
  type RunStatus = 'running' | 'awaiting_human' | 'completed' | 'error' | 'cancelled' | 'all_executions' | (string & {});
242
375
  type RunTimeframe = 'last_hour' | 'last_day' | 'last_week' | (string & {});
243
376
  type ApprovalScope = 'mine' | 'all' | (string & {});
@@ -271,7 +404,7 @@ declare class WorkflowRunsResource {
271
404
  /**
272
405
  * List runs for a workflow.
273
406
  *
274
- * @param workflowId - Workflow id or slug.
407
+ * @param workflowId - Numeric workflow id.
275
408
  * @param options.pageSize - Maximum items per page (default 25, max 100).
276
409
  * @param options.pageToken - Opaque token from a previous page.
277
410
  * @param options.status - Filter by run status.
@@ -301,7 +434,7 @@ declare class WorkflowRunsResource {
301
434
  /**
302
435
  * Retrieve a workflow run by id.
303
436
  *
304
- * @param workflowId - Workflow id or slug the run belongs to.
437
+ * @param workflowId - Numeric workflow id the run belongs to.
305
438
  * @param runId - Run id (the list row's `workflowId` field, not the composite `id`).
306
439
  * @param options.temporalRunId - Optional internal execution id when disambiguating retries.
307
440
  * @returns Run details including status and output.
@@ -319,7 +452,7 @@ declare class WorkflowRunsResource {
319
452
  /**
320
453
  * Start a workflow run and stream run events.
321
454
  *
322
- * @param workflowId - Workflow id or slug to run.
455
+ * @param workflowId - Numeric workflow id to run.
323
456
  * @param body - Run body (`message`, optional `sessionId`, optional `version` as `published` or `draft`).
324
457
  * @param options.idempotencyKey - Client-supplied idempotency key; defaults to `body.runId` or a new uuid.
325
458
  * @returns A stream of run events (tokens, completion, errors, and related signals).
@@ -385,18 +518,21 @@ declare class WorkflowRunsResource {
385
518
  idempotencyKey?: string;
386
519
  }): AgentRunStream;
387
520
  /**
388
- * Resume an interrupted run and stream run events.
521
+ * Resume a run paused at an approval or connect interrupt, and stream the continuation's events.
389
522
  *
390
- * @param runId - Run id to resume.
391
- * @param body - Resume body (`message`, `sessionId`, and `decision`: `approve` / `deny` / `connected` / `cancelled`).
523
+ * The decision is the whole turn: send no `message` (a non-empty one is rejected).
524
+ *
525
+ * @param runId - Id of the interrupted run.
526
+ * @param body - `sessionId` (the run's conversation id, required) and `decision`
527
+ * (`approve` / `deny` / `connected` / `cancelled`); optional `approvalTarget`.
392
528
  * @param options.idempotencyKey - Client-supplied idempotency key; defaults to `body.runId` or a new uuid.
393
529
  * @returns A stream of run events.
530
+ * @throws {ValidationError} When `sessionId` is blank, before any request is sent.
394
531
  *
395
532
  * @example
396
533
  * ```ts
397
534
  * const stream = client.workflows.runs.resume(runId, {
398
535
  * decision: 'approve',
399
- * message: 'Looks good — continue.',
400
536
  * sessionId,
401
537
  * })
402
538
  * for await (const event of stream) {
@@ -419,24 +555,60 @@ declare class WorkflowRunsResource {
419
555
  */
420
556
  cancel(runId: string): Promise<void>;
421
557
  /**
422
- * Fetch stored run events for a run.
558
+ * Poll a run's buffered events once (the JSON transport, not SSE).
423
559
  *
424
560
  * @param runId - Run id.
425
- * @returns Run event history for replay or inspection.
561
+ * @returns The poll response: `events` (each with its stream `id` and `type`), `cursor`,
562
+ * `status` and `done`.
426
563
  */
427
- events(runId: string): Promise<unknown>;
564
+ events(runId: string): Promise<RunEventsPollResponse>;
428
565
  /**
429
- * Request a graceful stop for a running execution.
566
+ * Supersede a run's current turn with a follow-up turn.
567
+ *
568
+ * The run is cancelled and `nextRun` starts as a new run on the same conversation.
569
+ * On a run that has already finished nothing is cancelled, and `nextRun` simply
570
+ * starts a follow-up turn. `nextRun.runId` is pinned (a new uuid when you do not
571
+ * set one), so a retried request returns the same run instead of starting another.
430
572
  *
431
573
  * @param runId - Run id to interrupt.
574
+ * @param nextRun - The follow-up turn: `message` and `sessionId` (the run's conversation id).
575
+ * @param options.lastSeenEventId - Id of the last event you rendered, so the cancelled
576
+ * turn's saved output stops there.
577
+ * @returns The new run (`runId`, `status`); follow it with {@link stream}.
578
+ * @throws {ValidationError} When `nextRun.sessionId` is blank, before any request is sent.
579
+ *
580
+ * @example
581
+ * ```ts
582
+ * const { runId: nextRunId } = await client.workflows.runs.interrupt(runId, {
583
+ * message: 'Only count EMEA.',
584
+ * sessionId,
585
+ * })
586
+ * for await (const event of client.workflows.runs.stream(nextRunId)) {
587
+ * if (event.type === 'token') process.stdout.write(event.content)
588
+ * }
589
+ * ```
432
590
  */
433
- interrupt(runId: string): Promise<void>;
591
+ interrupt(runId: string, nextRun: FollowUpRunRequest, options?: {
592
+ lastSeenEventId?: string;
593
+ }): Promise<RunAdmission>;
434
594
  /**
435
- * Move a queued run back into an editable state before it starts.
595
+ * Replace the turn of a run that is still queued (not yet started).
436
596
  *
437
597
  * @param runId - Queued run id.
598
+ * @param nextRun - The replacement turn: `message` and `sessionId` (the run's conversation id).
599
+ * @returns The edited run (`runId`, `status`).
600
+ * @throws {ValidationError} When `nextRun.sessionId` is blank, before any request is sent.
601
+ * @throws {ConflictError} When the run has already started.
602
+ *
603
+ * @example
604
+ * ```ts
605
+ * await client.workflows.runs.editQueued(queuedRunId, {
606
+ * message: 'Summarize last week instead.',
607
+ * sessionId,
608
+ * })
609
+ * ```
438
610
  */
439
- editQueued(runId: string): Promise<void>;
611
+ editQueued(runId: string, nextRun: FollowUpRunRequest): Promise<RunAdmission>;
440
612
  /**
441
613
  * List active conversation runs across the organization.
442
614
  *
@@ -454,21 +626,23 @@ declare class WorkflowRunsResource {
454
626
  *
455
627
  * @param sessionIds - Up to 100 session ids.
456
628
  * @returns Active runs matching any of the given sessions.
457
- * @throws {Error} When more than 100 session ids are provided.
629
+ * @throws {ValidationError} When more than 100 session ids are provided.
458
630
  */
459
631
  activeBySession(sessionIds: readonly string[]): Promise<ActiveConversationRun[]>;
460
632
  /**
461
- * Reconnect to an in-progress run and stream run events.
633
+ * Reconnect to a run and stream its events.
462
634
  *
463
635
  * @param runId - Run id to follow.
464
- * @param options.lastEventId - Resume after this event id when catching up.
465
- * @returns A stream of run events from the current execution point.
636
+ * @param options.lastEventId - The `id` of the last event you handled; the stream resumes
637
+ * after it. Omit to replay the run from its first event.
638
+ * @returns A stream of run events.
466
639
  *
467
640
  * @example
468
641
  * ```ts
469
- * const stream = client.workflows.runs.stream(runId, { lastEventId: checkpoint })
470
- * for await (const event of stream) {
642
+ * let lastEventId: string | undefined
643
+ * for await (const event of client.workflows.runs.stream(runId, { lastEventId })) {
471
644
  * if (event.type === 'token') process.stdout.write(event.content)
645
+ * lastEventId = event.id // after handling it: reconnect with it if the connection drops
472
646
  * }
473
647
  * ```
474
648
  */
@@ -482,8 +656,13 @@ declare class WorkflowRunsResource {
482
656
  type Connection = components['schemas']['ConnectionDto'];
483
657
  type ConnectionSelection = components['schemas']['ConnectionSelectionDto'];
484
658
 
485
- /** One value entry from context item listValues (shape varies by context type). */
486
- type ContextValueRow = Record<string, unknown>;
659
+ /** One element of a context item's array field, from `listValues`. */
660
+ type ContextValueRow = {
661
+ /** Position of the element in the array (0-based). */
662
+ readonly index: number;
663
+ /** The element itself, as JSON of any type. */
664
+ readonly value: unknown;
665
+ };
487
666
 
488
667
  type SkillContextComposition = components['schemas']['ComposeSkillContextResponseDto'];
489
668
  type ModusContextComposition = components['schemas']['ModusContextResponseDto'];
@@ -510,35 +689,37 @@ interface UploadIngestedDataOptions {
510
689
  /** Location and identity of a newly stored ingested-data envelope. */
511
690
  type IngestedDataUploadResult = components['schemas']['CreatedIngestedDataResponseDto'];
512
691
 
513
- /** Generated base for the consumption `workflows` resource. */
514
- declare class WorkflowsResourceBase {
692
+ type JsonObjectInput = Record<string, unknown>;
693
+ type ContentProjection = components['schemas']['ContentProjectionDto'];
694
+
695
+ /** Generated base for the consumption `scopes` resource. */
696
+ declare class ScopesResourceBase {
515
697
  protected readonly http: HttpClient;
516
698
  protected readonly config: ModusConfig;
517
699
  /** @internal */
518
700
  constructor(http: HttpClient, config: ModusConfig);
519
701
  /**
520
- * List workflows.
702
+ * List scopes.
521
703
  *
522
- * Returns a paginated page of workflows the caller can at least `use`. Workflows the caller
523
- * cannot see are filtered out. Pagination uses an opaque token returned in `nextPageToken`.
704
+ * Returns a paginated page of scopes the caller can at least `use`. Scopes the caller cannot see
705
+ * are filtered out. Pagination uses an opaque token returned in `nextPageToken`.
524
706
  *
525
- * **Requires:** `workflows:read`
707
+ * **Requires:** `scopes:read`
526
708
  *
527
709
  * @param options.pageSize - Items per page. Defaults to 25.
528
710
  * @param options.pageToken - Opaque page token from a previous response's `nextPageToken`. Omit
529
711
  * for the first page.
530
- * @param options.search - Case-insensitive substring filter on workflow name.
531
- * @param options.type - Filter by workflow type.
532
- * @param options.view - Variation view. `active` reads deployed; `draft` reads the latest builder
533
- * snapshot.
534
- * @param options.includeVariation - Include the requested variation payload (`trigger`,
535
- * `workflowStructure`, `agentSelection`) on list rows.
536
- * @returns A page of workflows.
712
+ * @param options.search - Case-insensitive substring filter on scope name.
713
+ * @param options.view - Variation view. `active` reads the deployed version, or the latest draft
714
+ * when nothing is published. `draft` reads the latest builder snapshot. `published` reads only
715
+ * the published version, and only scopes you can use.
716
+ * @param options.managerId - Return only scopes supervised by this manager scope id.
717
+ * @returns A page of scopes.
537
718
  *
538
719
  * @example
539
720
  * ```ts
540
- * for await (const wf of (await client.workflows.list({ search: 'digest' })).autoPagingIter()) {
541
- * console.log(wf.id, wf.name, wf.status)
721
+ * for await (const scope of (await client.scopes.list()).autoPagingIter()) {
722
+ * console.log(scope.id, scope.name, scope.status)
542
723
  * }
543
724
  * ```
544
725
  */
@@ -546,680 +727,655 @@ declare class WorkflowsResourceBase {
546
727
  pageSize?: number;
547
728
  pageToken?: string;
548
729
  search?: string;
549
- type?: WorkflowType;
550
730
  view?: VariationView;
551
- includeVariation?: boolean;
552
- }): Promise<Page<Workflow>>;
553
- protected listPage(pageSize: number, pageToken: string | undefined, search?: string, type?: WorkflowType, view?: VariationView, includeVariation?: boolean): Promise<Page<Workflow>>;
554
- }
555
-
556
- declare class AgentWorkflowActionsResource {
557
- private readonly http;
558
- private readonly config;
559
- /** @internal */
560
- constructor(http: HttpClient, config: ModusConfig);
731
+ managerId?: number;
732
+ }): Promise<Page<Scope>>;
733
+ protected listPage(pageSize: number, pageToken: string | undefined, search?: string, view?: VariationView, managerId?: number): Promise<Page<Scope>>;
561
734
  /**
562
- * Execute a workflow action and stream run events.
735
+ * Get a scope.
563
736
  *
564
- * @param body - Action body (`organizationId`, `sessionId`, `workflowAction`, optional `previousOutputs`).
565
- * @param options.idempotencyKey - Client-supplied idempotency key; defaults to `body.runId` or a new uuid.
566
- * @returns A stream of run events for the action execution.
567
- */
568
- execute(body: WorkflowActionRequest, options?: {
569
- idempotencyKey?: string;
570
- }): AgentRunStream;
571
- /**
572
- * Cancel a workflow action run.
737
+ * Returns a scope. `view=active` (default) is the deployed version, or the latest draft when
738
+ * nothing is published. `view=draft` is the latest edits. `view=published` is only the published
739
+ * version, and only if you can use the scope. Returns 404 if you cannot access it.
573
740
  *
574
- * @param runId - Action run id to cancel.
741
+ * **Requires:** `scopes:read`
742
+ *
743
+ * @param scopeId - Numeric scope id.
744
+ * @param options.view - Which version to read. Defaults to `active`. `published` is only the
745
+ * published version, and only if you can use the scope.
746
+ *
747
+ * @example
748
+ * ```ts
749
+ * const [first] = (await client.scopes.list()).items
750
+ * const scope = await client.scopes.get(first.id)
751
+ * console.log(scope.name, scope.status)
752
+ * ```
575
753
  */
576
- cancel(runId: string): Promise<void>;
577
- private parseEvents;
754
+ get(scopeId: number | string, options?: {
755
+ view?: VariationView;
756
+ }): Promise<Scope>;
578
757
  }
579
758
 
580
759
  /**
581
- * Read and run access to Modus workflows.
760
+ * Read / chat with published scopes.
582
761
  *
583
- * - `list` / `get` — browse workflows (`view: 'active'` or `'draft'`)
584
- * - {@link WorkflowRunsResource runs} — start, monitor, and control workflow runs
585
- * - {@link AgentWorkflowActionsResource workflowActions} — execute workflow actions
762
+ * Call path: `client.scopes` after `new Modus(...)`. Prefer `client.modus` for
763
+ * the org-wide assistant. Create/deploy via `ModusManagement`.
586
764
  *
587
765
  * @example
588
766
  * ```ts
589
- * import { Modus } from '@getmodus/sdk'
590
- * const client = new Modus()
591
- * for await (const wf of (await client.workflows.list()).autoPagingIter()) {
592
- * console.log(wf.id, wf.name, wf.status)
593
- * }
767
+ * const [scope] = (await client.scopes.list()).items
768
+ * const result = await client.scopes.chat(scope.id, 'What is our ARR trend?', {
769
+ * model: 'claude-sonnet-5',
770
+ * })
771
+ * console.log(result.content, result.threadId)
594
772
  * ```
595
773
  */
596
- declare class WorkflowsResource extends WorkflowsResourceBase {
597
- readonly runs: WorkflowRunsResource;
598
- readonly workflowActions: AgentWorkflowActionsResource;
599
- /** @internal */
600
- constructor(http: HttpClient, config: ModusConfig);
774
+ declare class ScopesResource extends ScopesResourceBase {
601
775
  /**
602
- * Retrieve a workflow by ID or slug.
776
+ * Return the conversations sub-resource scoped to `scopeId`.
603
777
  *
604
- * @param workflowId - Numeric id or slug.
605
- * @param options.view - Which saved version to return (`active` or `draft`).
606
- * @param options.includeVariation - Include variation metadata when supported.
607
- * @returns The workflow (`id`, `name`, `status`, …).
608
- * @throws {NotFoundError} When no workflow matches the id or slug.
778
+ * @param scopeId - Numeric scope id.
779
+ * @returns Conversations resource for the scope.
609
780
  *
610
781
  * @example
611
782
  * ```ts
612
- * const wf = await client.workflows.get('weekly-digest')
613
- * console.log(wf.name, wf.status)
783
+ * for await (const row of (
784
+ * await client.scopes.conversations(scopeId).list({ pageSize: 10 })
785
+ * ).autoPagingIter()) {
786
+ * console.log(row.threadId, row.firstMessage)
787
+ * }
614
788
  * ```
615
789
  */
616
- get(workflowId: number | string, options?: {
617
- view?: VariationView;
618
- includeVariation?: boolean;
619
- }): Promise<Workflow>;
620
- }
621
-
622
- /** Generated base for the consumption `connections` resource. */
623
- declare class ConnectionsResourceBase {
624
- protected readonly http: HttpClient;
625
- protected readonly config: ModusConfig;
626
- /** @internal */
627
- constructor(http: HttpClient, config: ModusConfig);
790
+ conversations(scopeId: number | string): ScopeConversationsResource;
628
791
  /**
629
- * List connections.
792
+ * Compose context this scope would use for an intent, without running chat.
630
793
  *
631
- * Returns a paginated page of warehouse and SaaS integration connections the caller can `use`.
632
- * Connections the caller cannot access are filtered out. Use the returned `id` when creating
633
- * saved-query context items. Pagination uses an opaque token returned in `nextPageToken`.
794
+ * Large bodies are bounded inline previews. This REST method does not expose file references
795
+ * or a full-content fetch operation. Runs on the agent host, like `chat`, so a compose may take
796
+ * up to 90 seconds; keep `timeoutMs` above that. A compose still running at 90 seconds fails
797
+ * with `UPSTREAM_TIMEOUT` (504).
634
798
  *
635
- * **Requires:** `context:read`
799
+ * @param scopeId - Numeric scope id.
800
+ * @param message - Natural-language intent used to select context.
801
+ * @param options.limit - Maximum context items to return. Omit to return all selected items.
802
+ * @returns Composed context text plus selection counts, item UIDs, and correlation session id.
636
803
  *
637
- * @param options.pageSize - Items per page. Defaults to 25.
638
- * @param options.pageToken - Opaque page token from a previous response's `nextPageToken`. Omit
639
- * for the first page.
640
- * @param options.type - Filter by effective integration category (case-sensitive exact match).
641
- * @returns A page of connections.
804
+ * @example
805
+ * ```ts
806
+ * const ctx = await client.scopes.getContext(scopeId, 'Which tables describe churn?', {
807
+ * limit: 5,
808
+ * })
809
+ * console.log(ctx.originalCount, ctx.sessionId)
810
+ * ```
642
811
  */
643
- list(options?: {
644
- pageSize?: number;
645
- pageToken?: string;
646
- type?: string;
647
- }): Promise<Page<Connection>>;
648
- protected listPage(pageSize: number, pageToken: string | undefined, type?: string): Promise<Page<Connection>>;
812
+ getContext(scopeId: number | string, message: string, options?: {
813
+ limit?: number;
814
+ }): Promise<SkillContextComposition>;
815
+ /**
816
+ * Chat with a published scope. The reply streams live from the agent host:
817
+ * iterate `textStream()` for tokens, or `await` the result for the final
818
+ * answer. Pass the returned `threadId` back to continue the conversation.
819
+ *
820
+ * For the org-wide assistant use `client.modus.chat` instead.
821
+ *
822
+ * @param scopeId - Numeric scope id (must be active for chat).
823
+ * @param message - User message text.
824
+ * @param options.model - Required model id (e.g. `"claude-sonnet-5.5"`).
825
+ * @param options.threadId - Continue an existing conversation; omit to start new.
826
+ * @returns A chat session — iterate it or `await` it for `content`, `threadId`, `runId`.
827
+ * @throws {ModusError} When no agent host is known for a custom `baseUrl`.
828
+ *
829
+ * @example
830
+ * ```ts
831
+ * const chat = client.scopes.chat(scopeId, 'What is our ARR trend?', { model: 'claude-sonnet-5.5' })
832
+ * for await (const token of chat.textStream()) process.stdout.write(token)
833
+ * const { threadId } = await chat
834
+ * const follow = await client.scopes.chat(scopeId, 'Break that down by segment.', {
835
+ * model: 'claude-sonnet-5.5',
836
+ * threadId,
837
+ * })
838
+ * console.log(follow.content)
839
+ * ```
840
+ */
841
+ chat(scopeId: number | string, message: string, options: ChatOptions): ChatSession;
649
842
  }
650
843
 
651
- /**
652
- * Read access to integration connections.
653
- */
654
- declare class ConnectionsResource extends ConnectionsResourceBase {
844
+ /** Generated base for the consumption `modus.conversations` resource. */
845
+ declare class ModusConversationsResourceBase {
846
+ protected readonly http: HttpClient;
847
+ protected readonly config: ModusConfig;
848
+ /** @internal */
849
+ constructor(http: HttpClient, config: ModusConfig);
655
850
  /**
656
- * Find the first connection whose name matches (case-insensitive).
851
+ * Get a Modus conversation.
657
852
  *
658
- * Pages through {@link ConnectionsResource.list} until a match is found.
853
+ * Returns the full message history for a conversation thread.
659
854
  *
660
- * @param options.name - Connection name to search for.
661
- * @param options.type - Optional integration category filter.
662
- * @param options.pageSize - Page size when scanning (default 25).
663
- * @returns The matching connection, or `undefined` if none is found.
855
+ * **Requires:** `scopes:read`
856
+ *
857
+ * @param threadId - Thread id from a conversation list or chat response.
664
858
  */
665
- find(options: {
666
- name: string;
667
- type?: string;
668
- pageSize?: number;
669
- }): Promise<Connection | undefined>;
859
+ get(threadId: string): Promise<Conversation>;
860
+ }
861
+
862
+ /** List and retrieve Modus / scope conversations. */
863
+ declare class ModusConversationsResource extends ModusConversationsResourceBase {
864
+ constructor(http: HttpClient, config: ModusConfig);
670
865
  /**
671
- * List the selectable units on a connection (a repository, a schema, a project).
866
+ * List conversations.
672
867
  *
673
- * @param connectionId - Connection id.
674
- * @param options.pageSize - Maximum items per page (default 25).
868
+ * @param options.pageSize - Items per page (default 25).
675
869
  * @param options.pageToken - Opaque token from a previous page.
676
- * @returns A page of selectable units — use {@link iterSelections} or `.autoPagingIter()` for every page.
677
- * @example
678
- * for await (const unit of client.connections.iterSelections('7a3f9d2c-1111-4000-a000-000000000abc')) {
679
- * console.log(unit.objectType, unit.path)
680
- * }
870
+ * @param options.kind - `"modus"`, `"scopes"`, or `"all"`.
871
+ * @param options.source - Restrict to conversations started from this UI surface
872
+ * (e.g. `"context_chat"`, `"dashboard_copilot"`, `"slack"`). Only valid with an
873
+ * omitted `kind` or `kind: "all"`; the API throws an `UnprocessableError` (422)
874
+ * if combined with `kind: "modus"` or `kind: "scopes"`.
875
+ * @param options.sourceRef - Narrow `source` to one instance of that surface — for
876
+ * `"dashboard_copilot"`, a dashboard id. Requires `source`; the API throws an
877
+ * `UnprocessableError` (422) if sent on its own. Conversations recorded before
878
+ * this filter shipped carry no instance key and never match it.
879
+ * @returns Page of conversation list items.
681
880
  */
682
- listSelections(connectionId: string, options?: {
881
+ list(options?: {
683
882
  pageSize?: number;
684
883
  pageToken?: string;
685
- }): Promise<Page<ConnectionSelection>>;
686
- private listSelectionsPage;
687
- /**
688
- * Yield every selectable unit on a connection, following pages.
689
- *
690
- * @param connectionId - Connection id.
691
- * @param options.pageSize - Maximum items per page (default 25).
692
- * @example
693
- * for await (const unit of client.connections.iterSelections('7a3f9d2c-1111-4000-a000-000000000abc')) {
694
- * console.log(unit.objectType, unit.displayName)
695
- * }
696
- */
697
- iterSelections(connectionId: string, options?: {
698
- pageSize?: number;
699
- }): AsyncGenerator<ConnectionSelection>;
884
+ kind?: ConversationKind;
885
+ source?: string;
886
+ sourceRef?: string;
887
+ }): Promise<Page<ConversationListItem>>;
888
+ private listPage;
700
889
  }
701
890
 
702
- type JsonObjectInput = Record<string, unknown>;
703
- type ContentProjection = components['schemas']['ContentProjectionDto'];
704
-
705
891
  /**
706
- * Read the org knowledge base (notes, metrics, saved queries, integration items).
892
+ * Org-wide Modus assistant (full environment context and tools).
707
893
  *
708
- * Use `client.context.items` after `new Modus()`. Prefer `list` / `get` /
709
- * `lookup` for discovery; use `listValues` when a field holds a large array
710
- * inside `content`.
894
+ * Prefer `client.modus` over `client.scopes` when the question is not tied to one
895
+ * published scope. Construct with `new Modus()` (reads `MODUS_API_KEY`).
896
+ *
897
+ * - `chat` — stream a reply live, or `await` it for the complete answer
898
+ * - `getContext` — preview composed context without a chat turn
899
+ * - `conversations` — list/get prior Modus threads
711
900
  *
712
901
  * @example
713
902
  * ```ts
714
903
  * import { Modus } from '@getmodus/sdk'
715
904
  * const client = new Modus()
716
- * for await (const item of (await client.context.items.list({ pageSize: 25 })).autoPagingIter()) {
717
- * console.log(item.contextType, item.description ?? item.uid)
718
- * }
905
+ * const result = await client.modus.chat('What tables describe revenue?', {
906
+ * model: 'claude-sonnet-5',
907
+ * })
908
+ * console.log(result.content, result.threadId)
719
909
  * ```
720
910
  */
721
- declare class ContextItemsResource {
911
+ declare class ModusResource {
722
912
  private readonly http;
723
913
  private readonly config;
724
- /** @internal */
914
+ readonly conversations: ModusConversationsResource;
725
915
  constructor(http: HttpClient, config: ModusConfig);
726
916
  /**
727
- * List knowledge-base items.
917
+ * Compose full-environment context for an intent without running chat.
728
918
  *
729
- * @param options.pageSize - Maximum items per page (default 25).
730
- * @param options.pageToken - Opaque token from a previous page.
731
- * @param options.contextType - Filter to a single context type (e.g. `"note"`).
732
- * @param options.parentUids - Exact ordered native ancestry chain for direct
733
- * children. Omit to leave parent unrestricted; pass `[]` for the known-empty
734
- * root. Native UIDs are exact tokens (including whitespace); do not use the
735
- * hashed context-item `uid`. For a folder's children, send that item's
736
- * `ancestry` UIDs plus its last `dataPath` token.
737
- * @param options.ancestorUids - Ordered UID ancestry prefix for strict
738
- * descendants. Omit to leave unrestricted; pass `[]` for every item with
739
- * non-null ancestry.
740
- * @param options.connectionIds - Restrict to these connection ids. Omit to
741
- * leave unfiltered; pass `[]` to match none. The Files root is
742
- * `connectionIds: ['files']` with `parentUids: []`.
743
- * @returns A page of context items — use `.autoPagingIter()` for all pages.
919
+ * Runs on the agent host, like `chat`, so a compose may take up to 90 seconds; keep `timeoutMs`
920
+ * above that. A compose still running at 90 seconds fails with `UPSTREAM_TIMEOUT` (504).
744
921
  *
745
- * @example
746
- * ```ts
747
- * const notes = await client.context.items.list({ contextType: 'note', pageSize: 50 })
748
- * for (const item of notes.items) {
749
- * console.log(item.description ?? item.uid, item.uid)
750
- * }
751
- * ```
922
+ * @param message - Natural-language intent used to select context.
923
+ * @param options.limit - Maximum context items to return. Omit to return all selected items.
924
+ * @returns Composition metadata (counts / session id). Use `chat` for a reply.
752
925
  *
753
926
  * @example
754
927
  * ```ts
755
- * const rootFolders = await client.context.items.list({
756
- * connectionIds: ['files'],
757
- * contextType: 'file_folder_metadata',
758
- * parentUids: [],
759
- * })
760
- * const folder = rootFolders.items[0]
761
- * const nativeUid = folder?.dataPath?.at(-1)
762
- * // Known ancestry only — never treat null/omitted ancestry as a root chain.
763
- * if (folder?.ancestry != null && nativeUid !== undefined) {
764
- * const filesInFolder = await client.context.items.list({
765
- * connectionIds: ['files'],
766
- * contextType: 'file_upload',
767
- * parentUids: [...folder.ancestry.map((a) => a.uid), nativeUid],
768
- * })
769
- * }
928
+ * const ctx = await client.modus.getContext('What tables describe revenue?', { limit: 5 })
929
+ * console.log(ctx.originalCount, ctx.sessionId)
770
930
  * ```
771
931
  */
772
- list(options?: {
773
- pageSize?: number;
774
- pageToken?: string;
775
- contextType?: string;
776
- parentUids?: readonly string[];
777
- ancestorUids?: readonly string[];
778
- connectionIds?: readonly string[];
779
- }): Promise<Page<ContextItem>>;
780
- private listPage;
932
+ getContext(message: string, options?: {
933
+ limit?: number;
934
+ }): Promise<ModusContextComposition>;
781
935
  /**
782
- * Retrieve a knowledge-base item by uid.
936
+ * Chat with Modus, the org-wide assistant. The reply streams live from the
937
+ * agent host: iterate `textStream()` for tokens, or `await` the result for
938
+ * the final answer. Pass the returned `threadId` back to continue.
783
939
  *
784
- * @param uid - Item uid.
785
- * @returns The context item (`uid`, `contextType`, `content`, …).
786
- * @throws {NotFoundError} When no item matches the uid.
940
+ * @param message - User message text.
941
+ * @param options.model - Required model id (e.g. `"claude-sonnet-5.5"`).
942
+ * @param options.threadId - Continue an existing conversation; omit to start new.
943
+ * @returns A chat session — iterate it or `await` it for `content`, `threadId`, `runId`.
944
+ * @throws {ModusError} When no agent host is known for a custom `baseUrl`.
787
945
  *
788
946
  * @example
789
947
  * ```ts
790
- * const item = await client.context.items.get(uid)
791
- * console.log(item.contextType, item.description ?? item.uid)
948
+ * const result = await client.modus.chat('What tables describe revenue?', {
949
+ * model: 'claude-sonnet-5.5',
950
+ * })
951
+ * console.log(result.content)
952
+ * const follow = client.modus.chat('Break that down by region.', {
953
+ * model: 'claude-sonnet-5.5',
954
+ * threadId: result.threadId,
955
+ * })
956
+ * for await (const token of follow.textStream()) process.stdout.write(token)
792
957
  * ```
793
958
  */
794
- get(uid: string): Promise<ContextItem>;
959
+ chat(message: string, options: ChatOptions): ChatSession;
960
+ }
961
+
962
+ /** Generated base for the consumption `workflows` resource. */
963
+ declare class WorkflowsResourceBase {
964
+ protected readonly http: HttpClient;
965
+ protected readonly config: ModusConfig;
966
+ /** @internal */
967
+ constructor(http: HttpClient, config: ModusConfig);
795
968
  /**
796
- * Look up a knowledge-base item by type and data path.
969
+ * List workflows.
797
970
  *
798
- * @param options.contextType - Context type to match (e.g. `"note"`).
799
- * @param options.dataPath - Hierarchical path segments that identify the item.
800
- * @param options.contentProjection - Optional fields to include from item content.
801
- * @returns The matching row, or `undefined` when no item is found (404).
971
+ * Returns a paginated page of workflows the caller can at least `use`. Workflows the caller
972
+ * cannot see are filtered out. Pagination uses an opaque token returned in `nextPageToken`.
802
973
  *
803
- * @example
804
- * ```ts
805
- * const found = await client.context.items.lookup({
806
- * contextType: 'note',
807
- * dataPath: ['finance', 'arr-definition'],
808
- * })
809
- * if (found) console.log(found.uid, found.description ?? found.uid)
810
- * ```
811
- */
812
- lookup(options: {
813
- contextType: string;
814
- dataPath: string[];
815
- contentProjection?: JsonObjectInput | ContentProjection;
816
- }): Promise<ContextItemLookupRow | undefined>;
817
- /**
818
- * List values stored under a content key on a context item.
974
+ * **Requires:** `workflows:read`
819
975
  *
820
- * @param uid - Item uid.
821
- * @param contextType - Context type of the item.
822
- * @param contentKeyPath - Dot path to the value field inside item content (e.g. `"enumValues"`).
823
- * @param options.pageSize - Maximum items per page (default 25).
824
- * @param options.pageToken - Opaque token from a previous page.
825
- * @returns A page of value rows.
976
+ * @param options.pageSize - Items per page. Defaults to 25.
977
+ * @param options.pageToken - Opaque page token from a previous response's `nextPageToken`. Omit
978
+ * for the first page.
979
+ * @param options.search - Case-insensitive substring filter on workflow name.
980
+ * @param options.type - Filter by workflow type.
981
+ * @param options.view - Variation view. `active` reads the deployed version. `draft` reads the
982
+ * latest builder snapshot. `published` reads only a published workflow of type workflow that
983
+ * you can use; tasks are excluded.
984
+ * @param options.includeVariation - Include the requested variation payload (`trigger`,
985
+ * `workflowStructure`, `agentSelection`) on list rows.
986
+ * @returns A page of workflows.
826
987
  *
827
988
  * @example
828
989
  * ```ts
829
- * // Replace PLACEHOLDER_UID with a real uid whose content has enumValues.
830
- * const page = await client.context.items.listValues(
831
- * 'PLACEHOLDER_UID',
832
- * 'table_column',
833
- * 'enumValues',
834
- * { pageSize: 25 },
835
- * )
836
- * for (const row of page.items) console.log(row)
990
+ * for await (const wf of (await client.workflows.list({ search: 'digest' })).autoPagingIter()) {
991
+ * console.log(wf.id, wf.name, wf.status)
992
+ * }
837
993
  * ```
838
994
  */
839
- listValues(uid: string, contextType: string, contentKeyPath: string, options?: {
995
+ list(options?: {
840
996
  pageSize?: number;
841
997
  pageToken?: string;
842
- }): Promise<Page<ContextValueRow>>;
998
+ search?: string;
999
+ type?: WorkflowType;
1000
+ view?: VariationView;
1001
+ includeVariation?: boolean;
1002
+ }): Promise<Page<Workflow>>;
1003
+ protected listPage(pageSize: number, pageToken: string | undefined, search?: string, type?: WorkflowType, view?: VariationView, includeVariation?: boolean): Promise<Page<Workflow>>;
1004
+ }
1005
+
1006
+ declare class AgentWorkflowActionsResource {
1007
+ private readonly http;
1008
+ private readonly config;
1009
+ /** @internal */
1010
+ constructor(http: HttpClient, config: ModusConfig);
843
1011
  /**
844
- * List values for a context item already loaded via {@link ContextItemsResource.list} or {@link ContextItemsResource.get}.
1012
+ * Execute a workflow action and stream run events.
845
1013
  *
846
- * @param item - Context item (uses `item.uid` and `item.contextType`).
847
- * @param contentKeyPath - Dot path to the value field inside item content.
848
- * @param options.pageSize - Maximum items per page (default 25).
849
- * @param options.pageToken - Opaque token from a previous page.
850
- * @returns A page of value rows.
1014
+ * @param body - Action body (`organizationId`, `sessionId`, `workflowAction`, optional `previousOutputs`).
1015
+ * @param options.idempotencyKey - Client-supplied idempotency key; defaults to `body.runId` or a new uuid.
1016
+ * @returns A stream of run events for the action execution.
1017
+ */
1018
+ execute(body: WorkflowActionRequest, options?: {
1019
+ idempotencyKey?: string;
1020
+ }): AgentRunStream;
1021
+ /**
1022
+ * Cancel a workflow action run.
851
1023
  *
852
- * @example
853
- * ```ts
854
- * // Replace PLACEHOLDER_UID with a real uid that has enumValues in content.
855
- * const item = await client.context.items.get('PLACEHOLDER_UID')
856
- * const page = await client.context.items.listValuesFor(item, 'enumValues')
857
- * for (const row of page.items) console.log(row)
858
- * ```
1024
+ * @param runId - Action run id to cancel.
859
1025
  */
860
- listValuesFor(item: ContextItem, contentKeyPath: string, options?: {
861
- pageSize?: number;
862
- pageToken?: string;
863
- }): Promise<Page<ContextValueRow>>;
864
- private listValuesPage;
1026
+ cancel(runId: string): Promise<void>;
1027
+ private parseEvents;
865
1028
  }
866
1029
 
867
1030
  /**
868
- * Read access to the Modus knowledge base.
1031
+ * Read and run access to Modus workflows.
869
1032
  *
870
- * - {@link ContextItemsResource items} — list and look up indexed knowledge-base items.
871
- * - {@link CustomContextItemsResource customItems} — create and manage custom context items.
1033
+ * - `list` / `get` — browse workflows (`view: 'active'`, `'draft'`, or `'published'`)
1034
+ * - `chat` — send a workflow a message and stream its reply
1035
+ * - {@link WorkflowRunsResource runs} — start, monitor, and control workflow runs
1036
+ * - {@link AgentWorkflowActionsResource workflowActions} — execute workflow actions
872
1037
  *
873
- * Call path: `client.context` after `new Modus(...)`.
1038
+ * @example
1039
+ * ```ts
1040
+ * import { Modus } from '@getmodus/sdk'
1041
+ * const client = new Modus()
1042
+ * for await (const wf of (await client.workflows.list()).autoPagingIter()) {
1043
+ * console.log(wf.id, wf.name, wf.status)
1044
+ * }
1045
+ * ```
874
1046
  */
875
- declare class ContextResource {
876
- readonly items: ContextItemsResource;
877
- readonly customItems: CustomContextItemsResource;
878
- /** @internal */
879
- constructor(http: HttpClient, config: ModusConfig);
880
- }
881
-
882
- /** Store exact integration requests and responses as immutable ingested data. */
883
- declare class IngestedDataResource {
884
- private readonly http;
885
- private readonly config;
1047
+ declare class WorkflowsResource extends WorkflowsResourceBase {
1048
+ readonly runs: WorkflowRunsResource;
1049
+ readonly workflowActions: AgentWorkflowActionsResource;
886
1050
  /** @internal */
887
1051
  constructor(http: HttpClient, config: ModusConfig);
888
1052
  /**
889
- * Store a complete SQL or HTTP request and response exactly once.
1053
+ * Retrieve a workflow by its numeric id.
890
1054
  *
891
- * Identity covers the complete organization, integration, request, and response
892
- * content. A duplicate raises `ConflictError`, which means the identical payload
893
- * is already stored and may be treated as a safe retry outcome.
1055
+ * @param workflowId - Numeric workflow id.
1056
+ * @param options.view - Which saved version to return (`active` or `draft`).
1057
+ * @param options.includeVariation - Include variation metadata when supported.
1058
+ * @returns The workflow (`id`, `name`, `status`, …).
1059
+ * @throws {NotFoundError} When no workflow has this id.
894
1060
  *
895
- * @param options.integrationType - Canonical Modus integration identifier.
896
- * @param options.request - Exact SQL or HTTP request that produced the response.
897
- * @param options.response - Response format, optional source HTTP status, and exact string content. SQL requires CSV.
898
- * @returns The checksum of the stored envelope.
899
- * @throws {ConflictError} When the complete payload is already stored.
1061
+ * @example
1062
+ * ```ts
1063
+ * const [first] = (await client.workflows.list()).items
1064
+ * const wf = await client.workflows.get(first.id)
1065
+ * console.log(wf.name, wf.status)
1066
+ * ```
1067
+ */
1068
+ get(workflowId: number | string, options?: {
1069
+ view?: VariationView;
1070
+ includeVariation?: boolean;
1071
+ }): Promise<Workflow>;
1072
+ /**
1073
+ * Chat with a published workflow. Node output streams live from the agent
1074
+ * host: iterate `textStream()` for tokens, or `await` the result for the
1075
+ * workflow's final output.
1076
+ *
1077
+ * @param workflowId - Numeric workflow id.
1078
+ * @param message - User message text.
1079
+ * @param options.model - Required model id (e.g. `"claude-sonnet-5.5"`).
1080
+ * @param options.threadId - Continue an existing conversation; omit to start new.
1081
+ * @returns A chat session — iterate it or `await` it for `content`, `threadId`, `runId`.
1082
+ * @throws {ModusError} When no agent host is known for a custom `baseUrl`.
900
1083
  *
901
1084
  * @example
902
1085
  * ```ts
903
- * const stored = await client.ingestedData.upload({
904
- * integrationType: 'generic',
905
- * request: { type: 'sql', query: 'SELECT id, total FROM orders' },
906
- * response: { format: 'csv', content: 'id,total\n1,42.00\n' },
1086
+ * const { content } = await client.workflows.chat(workflowId, 'Run this week\'s digest', {
1087
+ * model: 'claude-sonnet-5.5',
907
1088
  * })
908
- * console.log(stored.checksum)
1089
+ * console.log(content)
909
1090
  * ```
910
1091
  */
911
- upload(options: UploadIngestedDataOptions): Promise<IngestedDataUploadResult>;
1092
+ chat(workflowId: number | string, message: string, options: ChatOptions): ChatSession;
912
1093
  }
913
1094
 
914
- /** Generated base for the consumption `modus.conversations` resource. */
915
- declare class ModusConversationsResourceBase {
1095
+ /** Generated base for the consumption `context.items` resource. */
1096
+ declare class ContextItemsResourceBase {
916
1097
  protected readonly http: HttpClient;
917
1098
  protected readonly config: ModusConfig;
918
1099
  /** @internal */
919
1100
  constructor(http: HttpClient, config: ModusConfig);
920
1101
  /**
921
- * Get a Modus conversation.
1102
+ * Query context items with SQL.
922
1103
  *
923
- * Returns the full message history for a conversation thread.
1104
+ * Runs one read-only SQL statement over the `context_items` table and returns its rows. The query
1105
+ * sees only the items you can read. A query that is not read-only or not valid returns 400; one
1106
+ * that runs past 20 s returns 422.
924
1107
  *
925
- * **Requires:** `scopes:read`
1108
+ * **Requires:** `context:read`
926
1109
  *
927
- * @param threadId - Thread id from a conversation list or chat response.
928
- */
929
- get(threadId: string): Promise<Conversation>;
930
- }
931
-
932
- /** List and retrieve Modus / scope conversations. */
933
- declare class ModusConversationsResource extends ModusConversationsResourceBase {
934
- constructor(http: HttpClient, config: ModusConfig);
935
- /**
936
- * List conversations.
1110
+ * @param query - Request body; see `ContextItemsQuery`.
937
1111
  *
938
- * @param options.pageSize - Items per page (default 25).
939
- * @param options.pageToken - Opaque token from a previous page.
940
- * @param options.kind - `"modus"`, `"scopes"`, or `"all"`.
941
- * @param options.source - Restrict to conversations started from this UI surface
942
- * (e.g. `"context_chat"`, `"dashboard_copilot"`, `"slack"`). Only valid with an
943
- * omitted `kind` or `kind: "all"`; the API throws an `UnprocessableError` (422)
944
- * if combined with `kind: "modus"` or `kind: "scopes"`.
945
- * @param options.sourceRef - Narrow `source` to one instance of that surface — for
946
- * `"dashboard_copilot"`, a dashboard id. Requires `source`; the API throws an
947
- * `UnprocessableError` (422) if sent on its own. Conversations recorded before
948
- * this filter shipped carry no instance key and never match it.
949
- * @returns Page of conversation list items.
1112
+ * @example
1113
+ * ```ts
1114
+ * const result = await modus.context.items.query({
1115
+ * sql: 'SELECT context_type, count(*) AS items FROM context_items GROUP BY context_type',
1116
+ * })
1117
+ * result.rows
1118
+ * ```
950
1119
  */
951
- list(options?: {
952
- pageSize?: number;
953
- pageToken?: string;
954
- kind?: ConversationKind;
955
- source?: string;
956
- sourceRef?: string;
957
- }): Promise<Page<ConversationListItem>>;
958
- private listPage;
1120
+ query(query: ContextItemsQuery): Promise<ContextItemsQueryResult>;
959
1121
  }
960
1122
 
961
1123
  /**
962
- * Org-wide Modus assistant (full environment context and tools).
963
- *
964
- * Prefer `client.modus` over `client.scopes` when the question is not tied to one
965
- * published scope. Construct with `new Modus()` (reads `MODUS_API_KEY`).
1124
+ * Read the org knowledge base (notes, metrics, saved queries, integration items).
966
1125
  *
967
- * - `chat` — one complete reply
968
- * - `chatStream` — print tokens as they arrive (consume `textStream()`)
969
- * - `getContext` — preview composed context without a chat turn
970
- * - `conversations` — list/get prior Modus threads
1126
+ * Use `client.context.items` after `new Modus()`. Prefer `list` / `get` /
1127
+ * `lookup` for discovery; use `listValues` when a field holds a large array
1128
+ * inside `content`.
971
1129
  *
972
1130
  * @example
973
1131
  * ```ts
974
1132
  * import { Modus } from '@getmodus/sdk'
975
1133
  * const client = new Modus()
976
- * const result = await client.modus.chat('What tables describe revenue?', {
977
- * model: 'claude-sonnet-5',
978
- * })
979
- * console.log(result.content, result.threadId)
1134
+ * for await (const item of (await client.context.items.list({ pageSize: 25 })).autoPagingIter()) {
1135
+ * console.log(item.contextType, item.description ?? item.uid)
1136
+ * }
980
1137
  * ```
981
1138
  */
982
- declare class ModusResource {
983
- private readonly http;
984
- private readonly config;
985
- readonly conversations: ModusConversationsResource;
986
- constructor(http: HttpClient, config: ModusConfig);
1139
+ declare class ContextItemsResource extends ContextItemsResourceBase {
987
1140
  /**
988
- * Compose full-environment context for an intent without running chat.
1141
+ * List knowledge-base items.
989
1142
  *
990
- * @param message - Natural-language intent used to select context.
991
- * @param options.limit - Maximum context items to return. Omit to return all selected items.
992
- * @returns Composition metadata (counts / session id). Use `chat` for a reply.
1143
+ * @param options.pageSize - Maximum items per page (default 25).
1144
+ * @param options.pageToken - Opaque token from a previous page.
1145
+ * @param options.contextType - Filter to a single context type (e.g. `"note"`).
1146
+ * @param options.parentUids - Exact ordered native ancestry chain for direct
1147
+ * children. Omit to leave parent unrestricted; pass `[]` for the known-empty
1148
+ * root. Native UIDs are exact tokens (including whitespace); do not use the
1149
+ * hashed context-item `uid`. For a folder's children, send that item's
1150
+ * `ancestry` UIDs plus its last `dataPath` token.
1151
+ * @param options.ancestorUids - Ordered UID ancestry prefix for strict
1152
+ * descendants. Omit to leave unrestricted; pass `[]` for every item with
1153
+ * non-null ancestry.
1154
+ * @param options.connectionIds - Restrict to these connection ids. Omit to
1155
+ * leave unfiltered; pass `[]` to match none. The Files root is
1156
+ * `connectionIds: ['files']` with `parentUids: []`.
1157
+ * @returns A page of context items — use `.autoPagingIter()` for all pages.
993
1158
  *
994
1159
  * @example
995
1160
  * ```ts
996
- * const ctx = await client.modus.getContext('What tables describe revenue?', { limit: 5 })
997
- * console.log(ctx.originalCount, ctx.sessionId)
1161
+ * const notes = await client.context.items.list({ contextType: 'note', pageSize: 50 })
1162
+ * for (const item of notes.items) {
1163
+ * console.log(item.description ?? item.uid, item.uid)
1164
+ * }
1165
+ * ```
1166
+ *
1167
+ * @example
1168
+ * ```ts
1169
+ * const rootFolders = await client.context.items.list({
1170
+ * connectionIds: ['files'],
1171
+ * contextType: 'file_folder_metadata',
1172
+ * parentUids: [],
1173
+ * })
1174
+ * const folder = rootFolders.items[0]
1175
+ * const nativeUid = folder?.dataPath?.at(-1)
1176
+ * // Known ancestry only — never treat null/omitted ancestry as a root chain.
1177
+ * if (folder?.ancestry != null && nativeUid !== undefined) {
1178
+ * const filesInFolder = await client.context.items.list({
1179
+ * connectionIds: ['files'],
1180
+ * contextType: 'file_upload',
1181
+ * parentUids: [...folder.ancestry.map((a) => a.uid), nativeUid],
1182
+ * })
1183
+ * }
998
1184
  * ```
999
1185
  */
1000
- getContext(message: string, options?: {
1001
- limit?: number;
1002
- }): Promise<ModusContextComposition>;
1186
+ list(options?: {
1187
+ pageSize?: number;
1188
+ pageToken?: string;
1189
+ contextType?: string;
1190
+ parentUids?: readonly string[];
1191
+ ancestorUids?: readonly string[];
1192
+ connectionIds?: readonly string[];
1193
+ }): Promise<Page<ContextItem>>;
1194
+ private listPage;
1003
1195
  /**
1004
- * Send a message to Modus and wait for the complete reply.
1196
+ * Retrieve a knowledge-base item by uid.
1005
1197
  *
1006
- * @param message - User message text.
1007
- * @param options.model - Required model id (e.g. `"claude-sonnet-5"`).
1008
- * @param options.threadId - Continue an existing conversation; omit to start new.
1009
- * @returns Chat result: `content`, `threadId` (for follow-ups), `runId`.
1198
+ * @param uid - Item uid.
1199
+ * @returns The context item (`uid`, `contextType`, `content`, …).
1200
+ * @throws {NotFoundError} When no item matches the uid.
1010
1201
  *
1011
1202
  * @example
1012
1203
  * ```ts
1013
- * const result = await client.modus.chat('What tables describe revenue?', {
1014
- * model: 'claude-sonnet-5',
1015
- * })
1016
- * console.log(result.content, result.threadId)
1017
- * const follow = await client.modus.chat('Break that down by region.', {
1018
- * model: 'claude-sonnet-5',
1019
- * threadId: result.threadId,
1020
- * })
1204
+ * const item = await client.context.items.get(uid)
1205
+ * console.log(item.contextType, item.description ?? item.uid)
1021
1206
  * ```
1022
1207
  */
1023
- chat(message: string, options: {
1024
- model: ChatModel;
1025
- threadId?: string;
1026
- }): Promise<ChatResult>;
1208
+ get(uid: string): Promise<ContextItem>;
1027
1209
  /**
1028
- * Stream a Modus reply token by token (SSE).
1029
- *
1030
- * The request starts when you consume `textStream()` or `eventStream()`.
1210
+ * Look up a knowledge-base item by type and data path.
1031
1211
  *
1032
- * @param message - User message text.
1033
- * @param options.model - Required model id (e.g. `"claude-sonnet-5"`).
1034
- * @param options.threadId - Continue an existing conversation; omit to start new.
1035
- * @returns Chat stream — iterate `textStream()` for tokens.
1212
+ * @param options.contextType - Context type to match (e.g. `"note"`).
1213
+ * @param options.dataPath - Hierarchical path segments that identify the item.
1214
+ * @param options.contentProjection - Optional fields to include from item content.
1215
+ * @returns The matching row, or `undefined` when no item is found (404).
1036
1216
  *
1037
1217
  * @example
1038
1218
  * ```ts
1039
- * const stream = client.modus.chatStream('Summarize ARR in three bullets.', {
1040
- * model: 'claude-sonnet-5',
1219
+ * const found = await client.context.items.lookup({
1220
+ * contextType: 'note',
1221
+ * dataPath: ['finance', 'arr-definition'],
1041
1222
  * })
1042
- * for await (const token of stream.textStream()) {
1043
- * process.stdout.write(token)
1044
- * }
1045
- * console.log(stream.getFinalResult().threadId)
1223
+ * if (found) console.log(found.uid, found.content)
1046
1224
  * ```
1047
1225
  */
1048
- chatStream(message: string, options: {
1049
- model: ChatModel;
1050
- threadId?: string;
1051
- }): ChatStream;
1052
- }
1053
-
1054
- /** Generated base for the consumption `scopes` resource. */
1055
- declare class ScopesResourceBase {
1056
- protected readonly http: HttpClient;
1057
- protected readonly config: ModusConfig;
1058
- /** @internal */
1059
- constructor(http: HttpClient, config: ModusConfig);
1226
+ lookup(options: {
1227
+ contextType: string;
1228
+ dataPath: string[];
1229
+ contentProjection?: JsonObjectInput | ContentProjection;
1230
+ }): Promise<ContextItemLookupRow | undefined>;
1060
1231
  /**
1061
- * List scopes.
1062
- *
1063
- * Returns a paginated page of scopes the caller can at least `use`. Scopes the caller cannot see
1064
- * are filtered out. Pagination uses an opaque token returned in `nextPageToken`.
1232
+ * Page through the elements of an array field inside one context item's content.
1065
1233
  *
1066
- * **Requires:** `scopes:read`
1234
+ * Each row is `{ index, value }`: the element's position in the array and the
1235
+ * element itself. A field that is not an array reads as one element; a missing
1236
+ * field as none. Rejects with a not-found error when the item does not exist,
1237
+ * you cannot read it, or its context type is not `contextType`.
1067
1238
  *
1068
- * @param options.pageSize - Items per page. Defaults to 25.
1069
- * @param options.pageToken - Opaque page token from a previous response's `nextPageToken`. Omit
1070
- * for the first page.
1071
- * @param options.search - Case-insensitive substring filter on scope name.
1072
- * @param options.view - Variation view. `active` reads deployed; `draft` reads the latest builder
1073
- * snapshot.
1074
- * @param options.managerId - Return only scopes supervised by this manager scope id.
1075
- * @returns A page of scopes.
1239
+ * @param uid - Item uid.
1240
+ * @param contextType - Context type of the item.
1241
+ * @param contentKeyPath - Dot path to the array inside item content (e.g. `"enumValues"`).
1242
+ * @param options.pageSize - Maximum elements per page (default 25).
1243
+ * @param options.pageToken - Opaque token from a previous page of the same item.
1244
+ * @returns A page of `{ index, value }` rows.
1076
1245
  *
1077
1246
  * @example
1078
1247
  * ```ts
1079
- * for await (const scope of (await client.scopes.list()).autoPagingIter()) {
1080
- * console.log(scope.id, scope.name, scope.status)
1081
- * }
1248
+ * // Replace PLACEHOLDER_UID with a real uid whose content has enumValues.
1249
+ * const page = await client.context.items.listValues(
1250
+ * 'PLACEHOLDER_UID',
1251
+ * 'table_column',
1252
+ * 'enumValues',
1253
+ * { pageSize: 25 },
1254
+ * )
1255
+ * for (const row of page.items) console.log(row.index, row.value)
1082
1256
  * ```
1083
1257
  */
1084
- list(options?: {
1258
+ listValues(uid: string, contextType: string, contentKeyPath: string, options?: {
1085
1259
  pageSize?: number;
1086
1260
  pageToken?: string;
1087
- search?: string;
1088
- view?: VariationView;
1089
- managerId?: number;
1090
- }): Promise<Page<Scope>>;
1091
- protected listPage(pageSize: number, pageToken: string | undefined, search?: string, view?: VariationView, managerId?: number): Promise<Page<Scope>>;
1261
+ }): Promise<Page<ContextValueRow>>;
1092
1262
  /**
1093
- * Get a scope.
1094
- *
1095
- * Returns a scope. `view=active` (default) returns the deployed version; `view=draft` returns the
1096
- * latest unpublished edits. Returns 404 if you cannot access the scope.
1097
- *
1098
- * **Requires:** `scopes:read`
1263
+ * Page through an array field of a context item already loaded via {@link ContextItemsResource.list} or {@link ContextItemsResource.get}.
1099
1264
  *
1100
- * @param scopeId - Numeric scope id.
1101
- * @param options.view - Which variation snapshot to read. Defaults to `active`.
1265
+ * @param item - Context item (uses `item.uid` and `item.contextType`).
1266
+ * @param contentKeyPath - Dot path to the array inside item content.
1267
+ * @param options.pageSize - Maximum elements per page (default 25).
1268
+ * @param options.pageToken - Opaque token from a previous page of the same item.
1269
+ * @returns A page of `{ index, value }` rows.
1102
1270
  *
1103
1271
  * @example
1104
1272
  * ```ts
1105
- * const scope = await client.scopes.get('revenue-analysis')
1106
- * console.log(scope.name, scope.status)
1273
+ * // Replace PLACEHOLDER_UID with a real uid that has enumValues in content.
1274
+ * const item = await client.context.items.get('PLACEHOLDER_UID')
1275
+ * const page = await client.context.items.listValuesFor(item, 'enumValues')
1276
+ * for (const row of page.items) console.log(row)
1107
1277
  * ```
1108
1278
  */
1109
- get(scopeId: number | string, options?: {
1110
- view?: VariationView;
1111
- }): Promise<Scope>;
1279
+ listValuesFor(item: ContextItem, contentKeyPath: string, options?: {
1280
+ pageSize?: number;
1281
+ pageToken?: string;
1282
+ }): Promise<Page<ContextValueRow>>;
1283
+ private listValuesPage;
1112
1284
  }
1113
1285
 
1114
1286
  /**
1115
- * Read / chat with published scopes.
1287
+ * Read access to the Modus knowledge base.
1116
1288
  *
1117
- * Call path: `client.scopes` after `new Modus(...)`. Prefer `client.modus` for
1118
- * the org-wide assistant. Create/deploy via `ModusManagement`.
1289
+ * - {@link ContextItemsResource items} — list and look up indexed knowledge-base items.
1290
+ * - {@link CustomContextItemsResource customItems} — create and manage custom context items.
1119
1291
  *
1120
- * @example
1121
- * ```ts
1122
- * const scope = await client.scopes.get('revenue-analysis')
1123
- * const result = await client.scopes.chat(scope.id, 'What is our ARR trend?', {
1124
- * model: 'claude-sonnet-5',
1125
- * })
1126
- * console.log(result.content, result.threadId)
1127
- * ```
1292
+ * Call path: `client.context` after `new Modus(...)`.
1128
1293
  */
1129
- declare class ScopesResource extends ScopesResourceBase {
1294
+ declare class ContextResource {
1295
+ readonly items: ContextItemsResource;
1296
+ readonly customItems: CustomContextItemsResource;
1297
+ /** @internal */
1298
+ constructor(http: HttpClient, config: ModusConfig);
1299
+ }
1300
+
1301
+ /** Generated base for the consumption `connections` resource. */
1302
+ declare class ConnectionsResourceBase {
1303
+ protected readonly http: HttpClient;
1304
+ protected readonly config: ModusConfig;
1305
+ /** @internal */
1306
+ constructor(http: HttpClient, config: ModusConfig);
1130
1307
  /**
1131
- * Return the conversations sub-resource scoped to `scopeId`.
1308
+ * List connections.
1132
1309
  *
1133
- * @param scopeId - Scope numeric id or slug.
1134
- * @returns Conversations resource for the scope.
1310
+ * Returns a paginated page of warehouse and SaaS integration connections the caller can `use`.
1311
+ * Connections the caller cannot access are filtered out. Use the returned `id` when creating
1312
+ * saved-query context items. Pagination uses an opaque token returned in `nextPageToken`.
1135
1313
  *
1136
- * @example
1137
- * ```ts
1138
- * for await (const row of (
1139
- * await client.scopes.conversations(scopeId).list({ pageSize: 10 })
1140
- * ).autoPagingIter()) {
1141
- * console.log(row.threadId, row.firstMessage)
1142
- * }
1143
- * ```
1314
+ * **Requires:** `context:read`
1315
+ *
1316
+ * @param options.pageSize - Items per page. Defaults to 25.
1317
+ * @param options.pageToken - Opaque page token from a previous response's `nextPageToken`. Omit
1318
+ * for the first page.
1319
+ * @param options.type - Filter by effective integration category (case-sensitive exact match).
1320
+ * @returns A page of connections.
1144
1321
  */
1145
- conversations(scopeId: number | string): ScopeConversationsResource;
1322
+ list(options?: {
1323
+ pageSize?: number;
1324
+ pageToken?: string;
1325
+ type?: string;
1326
+ }): Promise<Page<Connection>>;
1327
+ protected listPage(pageSize: number, pageToken: string | undefined, type?: string): Promise<Page<Connection>>;
1328
+ }
1329
+
1330
+ /**
1331
+ * Read access to integration connections.
1332
+ */
1333
+ declare class ConnectionsResource extends ConnectionsResourceBase {
1146
1334
  /**
1147
- * Compose context this scope would use for an intent, without running chat.
1148
- *
1149
- * Large bodies are bounded inline previews. This REST method does not expose file references
1150
- * or a full-content fetch operation.
1335
+ * Find the first connection whose name matches (case-insensitive).
1151
1336
  *
1152
- * @param scopeId - Scope numeric id or slug.
1153
- * @param message - Natural-language intent used to select context.
1154
- * @param options.limit - Maximum context items to return. Omit to return all selected items.
1155
- * @returns Composed context text plus selection counts, item UIDs, and correlation session id.
1337
+ * Pages through {@link ConnectionsResource.list} until a match is found.
1156
1338
  *
1157
- * @example
1158
- * ```ts
1159
- * const ctx = await client.scopes.getContext(scopeId, 'Which tables describe churn?', {
1160
- * limit: 5,
1161
- * })
1162
- * console.log(ctx.originalCount, ctx.sessionId)
1163
- * ```
1339
+ * @param options.name - Connection name to search for.
1340
+ * @param options.type - Optional integration category filter.
1341
+ * @param options.pageSize - Page size when scanning (default 25).
1342
+ * @returns The matching connection, or `undefined` if none is found.
1164
1343
  */
1165
- getContext(scopeId: number | string, message: string, options?: {
1166
- limit?: number;
1167
- }): Promise<SkillContextComposition>;
1344
+ find(options: {
1345
+ name: string;
1346
+ type?: string;
1347
+ pageSize?: number;
1348
+ }): Promise<Connection | undefined>;
1168
1349
  /**
1169
- * Send a message to a published scope and wait for the complete reply.
1170
- *
1171
- * For the org-wide assistant use `client.modus.chat` instead.
1172
- *
1173
- * @param scopeId - Scope numeric id or slug (must be active for chat).
1174
- * @param message - User message text.
1175
- * @param options.model - Required model id (e.g. `"claude-sonnet-5"`).
1176
- * @param options.threadId - Continue an existing conversation; omit to start new.
1177
- * @returns Chat result: `content`, `threadId`, `runId`.
1350
+ * List the selectable units on a connection (a repository, a schema, a project).
1178
1351
  *
1352
+ * @param connectionId - Connection id.
1353
+ * @param options.pageSize - Maximum items per page (default 25).
1354
+ * @param options.pageToken - Opaque token from a previous page.
1355
+ * @returns A page of selectable units — use {@link iterSelections} or `.autoPagingIter()` for every page.
1179
1356
  * @example
1180
- * ```ts
1181
- * const result = await client.scopes.chat(scopeId, 'What is our ARR trend?', {
1182
- * model: 'claude-sonnet-5',
1183
- * })
1184
- * console.log(result.content, result.threadId)
1185
- * const follow = await client.scopes.chat(scopeId, 'Break that down by segment.', {
1186
- * model: 'claude-sonnet-5',
1187
- * threadId: result.threadId,
1188
- * })
1189
- * ```
1357
+ * for await (const unit of client.connections.iterSelections('7a3f9d2c-1111-4000-a000-000000000abc')) {
1358
+ * console.log(unit.objectType, unit.path)
1359
+ * }
1190
1360
  */
1191
- chat(scopeId: number | string, message: string, options: {
1192
- model: ChatModel;
1193
- threadId?: string;
1194
- }): Promise<ChatResult>;
1361
+ listSelections(connectionId: string, options?: {
1362
+ pageSize?: number;
1363
+ pageToken?: string;
1364
+ }): Promise<Page<ConnectionSelection>>;
1365
+ private listSelectionsPage;
1195
1366
  /**
1196
- * Stream a scope reply token by token (SSE).
1197
- *
1198
- * The request starts when you consume `textStream()` or `eventStream()`.
1199
- *
1200
- * @param scopeId - Scope numeric id or slug.
1201
- * @param message - User message text.
1202
- * @param options.model - Required model id (e.g. `"claude-sonnet-5"`).
1203
- * @param options.threadId - Continue an existing conversation; omit to start new.
1204
- * @param options.version - `"published"` or `"draft"`.
1205
- * @returns Chat stream — iterate `textStream()` for tokens.
1367
+ * Yield every selectable unit on a connection, following pages.
1206
1368
  *
1369
+ * @param connectionId - Connection id.
1370
+ * @param options.pageSize - Maximum items per page (default 25).
1207
1371
  * @example
1208
- * ```ts
1209
- * const stream = client.scopes.chatStream(scopeId, 'Summarize in three bullets.', {
1210
- * model: 'claude-sonnet-5',
1211
- * })
1212
- * for await (const token of stream.textStream()) {
1213
- * process.stdout.write(token)
1372
+ * for await (const unit of client.connections.iterSelections('7a3f9d2c-1111-4000-a000-000000000abc')) {
1373
+ * console.log(unit.objectType, unit.displayName)
1214
1374
  * }
1215
- * console.log(stream.getFinalResult().threadId)
1216
- * ```
1217
1375
  */
1218
- chatStream(scopeId: number | string, message: string, options: {
1219
- model: ChatModel;
1220
- threadId?: string;
1221
- version?: string;
1222
- }): ChatStream;
1376
+ iterSelections(connectionId: string, options?: {
1377
+ pageSize?: number;
1378
+ }): AsyncGenerator<ConnectionSelection>;
1223
1379
  }
1224
1380
 
1225
1381
  /**
@@ -1236,7 +1392,7 @@ declare class SuggestionsResource {
1236
1392
  * @param options.pageSize - Maximum items per page (default 5, max 12).
1237
1393
  * @param options.pageToken - Opaque token from a previous page.
1238
1394
  * @param options.scopeId - Filter to a single scope.
1239
- * @param options.scopeIds - Filter to one or more scopes.
1395
+ * @param options.scopeIds - Filter to one or more scopes. An empty list throws; omit it for every scope.
1240
1396
  * @returns A page of suggested questions.
1241
1397
  */
1242
1398
  list(options?: {
@@ -1255,6 +1411,38 @@ declare class SuggestionsResource {
1255
1411
  recordEvent(id: string, event: RecordSuggestionEventRequest): Promise<void>;
1256
1412
  }
1257
1413
 
1414
+ /** Store exact integration requests and responses as immutable ingested data. */
1415
+ declare class IngestedDataResource {
1416
+ private readonly http;
1417
+ private readonly config;
1418
+ /** @internal */
1419
+ constructor(http: HttpClient, config: ModusConfig);
1420
+ /**
1421
+ * Store a complete SQL or HTTP request and response exactly once.
1422
+ *
1423
+ * Identity covers the complete organization, integration, request, and response
1424
+ * content. A duplicate raises `ConflictError`, which means the identical payload
1425
+ * is already stored and may be treated as a safe retry outcome.
1426
+ *
1427
+ * @param options.integrationType - Canonical Modus integration identifier.
1428
+ * @param options.request - Exact SQL or HTTP request that produced the response.
1429
+ * @param options.response - Response format, optional source HTTP status, and exact string content. SQL requires CSV.
1430
+ * @returns The checksum of the stored envelope.
1431
+ * @throws {ConflictError} When the complete payload is already stored.
1432
+ *
1433
+ * @example
1434
+ * ```ts
1435
+ * const stored = await client.ingestedData.upload({
1436
+ * integrationType: 'generic',
1437
+ * request: { type: 'sql', query: 'SELECT id, total FROM orders' },
1438
+ * response: { format: 'csv', content: 'id,total\n1,42.00\n' },
1439
+ * })
1440
+ * console.log(stored.checksum)
1441
+ * ```
1442
+ */
1443
+ upload(options: UploadIngestedDataOptions): Promise<IngestedDataUploadResult>;
1444
+ }
1445
+
1258
1446
  /**
1259
1447
  * Read / invoke client for Modus scopes, workflows, connections, and more.
1260
1448
  *
@@ -1273,4 +1461,4 @@ declare class Modus extends ModusClientBase {
1273
1461
  constructor(options?: ModusOptions);
1274
1462
  }
1275
1463
 
1276
- export { APIConnectionError, type AgentRun, type AgentRunCreateRequest, type AgentRunListItem, type AgentRunStream, type ApprovalScope, type AssistantContentResetEvent, AuthenticationError, type CancelRunRequest, type CancelledEvent, type ChatModel, type ChatRequest, type ChatResult, ChatStream, type ComposeSkillContextRequest, ConflictError, type Connection, type ConnectionSelection, ContextItem, ContextItemLookupRow, type ContextValueRow, Conversation, ConversationKind, ConversationListItem, type CreateAgentRunRequest, type DoneEvent, type EditQueuedRunRequest, type ErrorEvent, type HttpIngestedDataRequest, type IngestedDataRequest, type IngestedDataResponse, type IngestedDataResponseFormat, type IngestedDataUploadResult, InternalServerError, type InterruptRunRequest, Modus, type ModusContextComposition, type ModusContextRequest, ModusError, ModusOptions, type ModusRunCreateRequest, NotFoundError, Page, PermissionDeniedError, RateLimitError, type RecordSuggestionEventRequest, type ResumeRunRequest, RunCancelledError, type RunEvent, type RunStatus, type RunTimeframe, Scope, type SkillContextComposition, type SkillRunCreateRequest, type SqlIngestedDataRequest, StreamTimeoutError, type StreamTimeoutEvent, type SuggestionEventSource, type SuggestionEventType, type SuggestionQuestion, type TokenEvent, UnprocessableError, type UploadIngestedDataOptions, ValidationError, VariationView, Workflow, type WorkflowActionRequest, WorkflowType, components };
1464
+ export { APIConnectionError, type ActiveConversationRun, type ActiveConversationRunStatus, type AgentRun, type AgentRunCreateRequest, type AgentRunListItem, type AgentRunStream, AgentWorkflowActionsResource, type ApprovalRequiredEvent, type ApprovalScope, type AssistantContentResetEvent, AuthenticationError, BadRequestError, type CancelRunRequest, type CancelledEvent, type ChatModel, type ChatOptions, type ChatResult, ChatSession, type ComposeSkillContextRequest, ConflictError, type Connection, type ConnectionSelection, ConnectionsResource, type ContentProjection, ContextItem, ContextItemLookupRow, ContextItemsQuery, ContextItemsQueryResult, ContextItemsResource, ContextResource, type ContextValueRow, Conversation, ConversationKind, ConversationListItem, type CreateAgentRunRequest, CustomContextItemsResource, type DoneEvent, type EditQueuedRunRequest, type ErrorEvent, type FollowUpRunRequest, type HttpIngestedDataRequest, type IngestedDataRequest, IngestedDataResource, type IngestedDataResponse, type IngestedDataResponseFormat, type IngestedDataUploadResult, InternalServerError, type InterruptRunRequest, type JsonObjectInput, Modus, ModusConfig, type ModusContextComposition, type ModusContextRequest, ModusConversationsResource, ModusError, ModusOptions, ModusResource, type ModusRunCreateRequest, NotFoundError, Page, PermissionDeniedError, RateLimitError, type RecordSuggestionEventRequest, type ResumeRunRequest, type RunAdmission, RunCancelledError, type RunEvent, type RunEventBase, type RunEventsPollResponse, type RunStatus, type RunTimeframe, Scope, ScopeConversationsResource, ScopesResource, type SkillContextComposition, type SkillRunCreateRequest, type SqlIngestedDataRequest, StreamTimeoutError, type StreamTimeoutEvent, type SuggestionEventSource, type SuggestionEventType, type SuggestionQuestion, SuggestionsResource, type TokenEvent, UnprocessableError, type UploadIngestedDataOptions, ValidationError, VariationView, Workflow, type WorkflowActionRequest, WorkflowRunsResource, WorkflowType, WorkflowsResource, components };