@getmodus/sdk 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +189 -0
- package/README.md +182 -14
- package/dist/{conversations-COA6NW8I.d.cts → _client-base-H5rt5EGy.d.cts} +3789 -972
- package/dist/{conversations-COA6NW8I.d.ts → _client-base-H5rt5EGy.d.ts} +3789 -972
- package/dist/{chunk-GFS7CNON.js → chunk-BMYCORZF.js} +656 -325
- package/dist/chunk-BMYCORZF.js.map +1 -0
- package/dist/chunk-NA3ZD35T.cjs +2666 -0
- package/dist/chunk-NA3ZD35T.cjs.map +1 -0
- package/dist/index.cjs +722 -2870
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +743 -497
- package/dist/index.d.ts +743 -497
- package/dist/index.js +601 -434
- package/dist/index.js.map +1 -1
- package/dist/management/index.cjs +1293 -3126
- package/dist/management/index.cjs.map +1 -1
- package/dist/management/index.d.cts +867 -436
- package/dist/management/index.d.ts +867 -436
- package/dist/management/index.js +1110 -680
- package/dist/management/index.js.map +1 -1
- package/package.json +15 -8
- package/dist/chunk-GFS7CNON.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
APIConnectionError,
|
|
3
3
|
AuthenticationError,
|
|
4
|
+
BadRequestError,
|
|
4
5
|
ConflictError,
|
|
5
6
|
CustomContextItemsResource,
|
|
6
7
|
DEFAULT_MAX_PAGE_SIZE,
|
|
@@ -26,10 +27,11 @@ import {
|
|
|
26
27
|
normalizePageToken,
|
|
27
28
|
omitUndefined,
|
|
28
29
|
operationBaseUrl,
|
|
30
|
+
requireAgentHost,
|
|
29
31
|
validateChatModel,
|
|
30
32
|
validateId,
|
|
31
33
|
validatePageSize
|
|
32
|
-
} from "./chunk-
|
|
34
|
+
} from "./chunk-BMYCORZF.js";
|
|
33
35
|
|
|
34
36
|
// src/_agent_run_request.ts
|
|
35
37
|
import { randomUUID } from "crypto";
|
|
@@ -39,17 +41,6 @@ function resolveAgentRunSessionId(sessionId) {
|
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
// src/_streaming.ts
|
|
42
|
-
var SILENTLY_IGNORED = /* @__PURE__ */ new Set([
|
|
43
|
-
"heartbeat",
|
|
44
|
-
"ws_chunk",
|
|
45
|
-
"unknown",
|
|
46
|
-
"tool_start",
|
|
47
|
-
"tool_end",
|
|
48
|
-
"tool_chunk",
|
|
49
|
-
"agent_thinking",
|
|
50
|
-
"warning",
|
|
51
|
-
"selected_final_content"
|
|
52
|
-
]);
|
|
53
44
|
function parseLine(line) {
|
|
54
45
|
if (!line.startsWith("data:")) return void 0;
|
|
55
46
|
const raw = line.slice(5).trimStart();
|
|
@@ -67,30 +58,61 @@ function parseLine(line) {
|
|
|
67
58
|
function isAsyncIterable(value) {
|
|
68
59
|
return Symbol.asyncIterator in Object(value);
|
|
69
60
|
}
|
|
70
|
-
|
|
61
|
+
var NODE_TERMINAL_TYPES = /* @__PURE__ */ new Set(["done", "error", "cancelled", "stream_timeout"]);
|
|
62
|
+
function* parseData(data, id) {
|
|
71
63
|
const eventType = typeof data.type === "string" ? data.type : "unknown";
|
|
72
|
-
|
|
64
|
+
const withId = id === void 0 ? {} : { id };
|
|
65
|
+
if (eventType === "node_content") {
|
|
66
|
+
const inner = data.event;
|
|
67
|
+
if (inner && typeof inner === "object" && !Array.isArray(inner)) {
|
|
68
|
+
const frame = inner;
|
|
69
|
+
if (!NODE_TERMINAL_TYPES.has(frame.type)) yield* parseData(frame, id);
|
|
70
|
+
}
|
|
71
|
+
} else if (eventType === "token") {
|
|
73
72
|
const event = {
|
|
74
73
|
type: "token",
|
|
75
|
-
content: typeof data.content === "string" ? data.content : ""
|
|
74
|
+
content: typeof data.content === "string" ? data.content : "",
|
|
75
|
+
...typeof data.subAgent === "string" ? { subAgent: data.subAgent } : {},
|
|
76
|
+
...withId
|
|
76
77
|
};
|
|
77
78
|
yield event;
|
|
78
|
-
} else if (eventType === "done") {
|
|
79
|
+
} else if (eventType === "done" || eventType === "workflow_done") {
|
|
80
|
+
const content = eventType === "done" ? data.content : data.finalOutput;
|
|
79
81
|
const event = {
|
|
80
82
|
type: "done",
|
|
81
83
|
runId: typeof data.runId === "string" ? data.runId : "",
|
|
82
|
-
threadId: typeof data.threadId === "string" ? data.threadId : ""
|
|
84
|
+
threadId: typeof data.threadId === "string" ? data.threadId : "",
|
|
85
|
+
...typeof content === "string" ? { content } : {},
|
|
86
|
+
...withId
|
|
83
87
|
};
|
|
84
88
|
yield event;
|
|
85
|
-
} else if (eventType === "
|
|
89
|
+
} else if (eventType === "approval_required") {
|
|
90
|
+
const event = { type: "approval_required" };
|
|
91
|
+
for (const key of ["toolId", "toolName", "title", "description", "nodeId", "prompt"]) {
|
|
92
|
+
const value = data[key];
|
|
93
|
+
if (typeof value === "string") event[key] = value;
|
|
94
|
+
}
|
|
95
|
+
const { args, options } = data;
|
|
96
|
+
if (args && typeof args === "object" && !Array.isArray(args)) event.args = args;
|
|
97
|
+
if (Array.isArray(options)) event.options = options;
|
|
98
|
+
yield { ...event, ...withId };
|
|
99
|
+
} else if (eventType === "workflow_cancelled") {
|
|
100
|
+
const event = { type: "cancelled", ...withId };
|
|
101
|
+
yield event;
|
|
102
|
+
} else if (eventType === "error" || eventType === "workflow_error") {
|
|
86
103
|
const msg = data.error ?? data.message ?? data.content ?? "Unknown run error";
|
|
87
|
-
const event = {
|
|
104
|
+
const event = {
|
|
105
|
+
type: "error",
|
|
106
|
+
message: String(msg),
|
|
107
|
+
...typeof data.requestId === "string" ? { requestId: data.requestId } : {},
|
|
108
|
+
...withId
|
|
109
|
+
};
|
|
88
110
|
yield event;
|
|
89
111
|
} else if (eventType === "cancelled") {
|
|
90
|
-
const event = { type: "cancelled" };
|
|
112
|
+
const event = { type: "cancelled", ...withId };
|
|
91
113
|
yield event;
|
|
92
114
|
} else if (eventType === "stream_timeout") {
|
|
93
|
-
const event = { type: "stream_timeout" };
|
|
115
|
+
const event = { type: "stream_timeout", ...withId };
|
|
94
116
|
yield event;
|
|
95
117
|
} else if (eventType === "assistant_content_reset") {
|
|
96
118
|
if (typeof data.content !== "string") return;
|
|
@@ -99,24 +121,31 @@ function* parseData(data) {
|
|
|
99
121
|
content: data.content,
|
|
100
122
|
...typeof data.visibleContent === "string" ? { visibleContent: data.visibleContent } : {},
|
|
101
123
|
attempt: typeof data.attempt === "number" ? data.attempt : 1,
|
|
102
|
-
reason: "provider_stream_failed"
|
|
124
|
+
reason: "provider_stream_failed",
|
|
125
|
+
...data.subAgent && typeof data.subAgent === "object" && !Array.isArray(data.subAgent) ? { subAgent: data.subAgent } : {},
|
|
126
|
+
...withId
|
|
103
127
|
};
|
|
104
128
|
yield event;
|
|
105
|
-
} else if (!SILENTLY_IGNORED.has(eventType)) {
|
|
106
|
-
return;
|
|
107
129
|
}
|
|
108
130
|
}
|
|
109
|
-
function
|
|
110
|
-
|
|
131
|
+
function sseLineParser() {
|
|
132
|
+
let lastId;
|
|
133
|
+
return function* (line) {
|
|
134
|
+
if (line.startsWith("id:")) {
|
|
135
|
+
lastId = line.slice(3).trim() || void 0;
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
111
138
|
const data = parseLine(line);
|
|
112
|
-
if (data !== void 0) yield* parseData(data);
|
|
113
|
-
}
|
|
139
|
+
if (data !== void 0) yield* parseData(data, lastId);
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
function* parseSyncSseLines(lines) {
|
|
143
|
+
const parse = sseLineParser();
|
|
144
|
+
for (const line of lines) yield* parse(line);
|
|
114
145
|
}
|
|
115
146
|
async function* parseAsyncSseLines(lines) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
if (data !== void 0) yield* parseData(data);
|
|
119
|
-
}
|
|
147
|
+
const parse = sseLineParser();
|
|
148
|
+
for await (const line of lines) yield* parse(line);
|
|
120
149
|
}
|
|
121
150
|
function parseSseStream(lines) {
|
|
122
151
|
return isAsyncIterable(lines) ? parseAsyncSseLines(lines) : parseSyncSseLines(lines);
|
|
@@ -124,174 +153,199 @@ function parseSseStream(lines) {
|
|
|
124
153
|
|
|
125
154
|
// src/_chat.ts
|
|
126
155
|
function effectiveThreadId(threadId) {
|
|
127
|
-
if (threadId === void 0) return void 0;
|
|
128
|
-
if (!threadId.trim()) return void 0;
|
|
156
|
+
if (threadId === void 0 || !threadId.trim()) return void 0;
|
|
129
157
|
return threadId;
|
|
130
158
|
}
|
|
131
|
-
function
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
function chatPath(resource, resourceId, options) {
|
|
135
|
-
const safeId = encodeURIComponent(String(resourceId));
|
|
136
|
-
const tid = effectiveThreadId(options.threadId);
|
|
137
|
-
if (tid !== void 0) {
|
|
138
|
-
const safeTid = encodeURIComponent(tid);
|
|
139
|
-
return `/api/v1/${resource}/${safeId}/conversations/${safeTid}/chat`;
|
|
140
|
-
}
|
|
141
|
-
return `/api/v1/${resource}/${safeId}/chat`;
|
|
142
|
-
}
|
|
143
|
-
function modusChatPath(options) {
|
|
144
|
-
const tid = effectiveThreadId(options.threadId);
|
|
145
|
-
if (tid !== void 0) {
|
|
146
|
-
validateId(tid, "thread_id");
|
|
147
|
-
return `/api/v1/modus/conversations/${encodeURIComponent(tid)}/chat`;
|
|
148
|
-
}
|
|
149
|
-
return `/api/v1/modus/chat`;
|
|
150
|
-
}
|
|
151
|
-
function agentHostRunsPath(resource, resourceId) {
|
|
152
|
-
if (resource === "modus") return "/agent/v1/modus/runs";
|
|
153
|
-
const safeId = encodeURIComponent(String(resourceId));
|
|
154
|
-
return `/agent/v1/${resource}/${safeId}/runs`;
|
|
155
|
-
}
|
|
156
|
-
function chatBody(message, model) {
|
|
157
|
-
return { message, model };
|
|
158
|
-
}
|
|
159
|
-
function agentRunsBody(message, model, options) {
|
|
160
|
-
const body = {
|
|
161
|
-
message,
|
|
162
|
-
config: { model },
|
|
163
|
-
sessionId: options.sessionId
|
|
164
|
-
};
|
|
165
|
-
if (options.organizationId !== void 0) {
|
|
166
|
-
body.organizationId = options.organizationId;
|
|
167
|
-
}
|
|
168
|
-
if (options.version !== void 0) {
|
|
169
|
-
body.version = options.version;
|
|
170
|
-
}
|
|
171
|
-
return body;
|
|
159
|
+
function runsPath(target) {
|
|
160
|
+
if (target.kind === "modus") return "/agent/v1/modus/runs";
|
|
161
|
+
return `/agent/v1/${target.kind}/${encodeURIComponent(String(target.id))}/runs`;
|
|
172
162
|
}
|
|
173
163
|
function raiseForEvent(event) {
|
|
174
|
-
if (event.type === "error") throw new ModusError(event.message);
|
|
164
|
+
if (event.type === "error") throw new ModusError(event.message, { requestId: event.requestId });
|
|
175
165
|
if (event.type === "cancelled") throw new RunCancelledError();
|
|
176
166
|
if (event.type === "stream_timeout") throw new StreamTimeoutError();
|
|
177
167
|
return event;
|
|
178
168
|
}
|
|
179
|
-
var
|
|
180
|
-
|
|
169
|
+
var ChatSession = class _ChatSession {
|
|
170
|
+
/**
|
|
171
|
+
* @internal A session built with `failure` never sends; every read rejects
|
|
172
|
+
* with it, as the promise `chat()` used to return did.
|
|
173
|
+
*/
|
|
174
|
+
constructor(http, request, failure) {
|
|
181
175
|
this.http = http;
|
|
182
|
-
this.
|
|
183
|
-
this.
|
|
184
|
-
this.
|
|
185
|
-
|
|
176
|
+
this.request = request;
|
|
177
|
+
this.received = [];
|
|
178
|
+
this.finished = false;
|
|
179
|
+
if (failure !== void 0) {
|
|
180
|
+
this.failure = failure;
|
|
181
|
+
this.finished = true;
|
|
182
|
+
}
|
|
186
183
|
}
|
|
187
184
|
/**
|
|
188
|
-
*
|
|
185
|
+
* The assistant's reply as text chunks, as they arrive. Sub-agent output is
|
|
186
|
+
* left out.
|
|
189
187
|
*
|
|
190
|
-
* @
|
|
191
|
-
* @throws {ModusError} When the stream emits an error event.
|
|
188
|
+
* @throws {ModusError} When the run reports an error.
|
|
192
189
|
* @throws {RunCancelledError} When the run is cancelled.
|
|
193
|
-
* @throws {StreamTimeoutError} When the
|
|
190
|
+
* @throws {StreamTimeoutError} When the run times out.
|
|
194
191
|
*/
|
|
195
192
|
async *textStream() {
|
|
196
|
-
|
|
197
|
-
|
|
193
|
+
const lastReset = this.received.findLastIndex(
|
|
194
|
+
(event) => event.type === "assistant_content_reset" && event.subAgent === void 0
|
|
195
|
+
);
|
|
196
|
+
let index = 0;
|
|
197
|
+
for await (const event of this.replay(false)) {
|
|
198
|
+
const at = index++;
|
|
199
|
+
if (at < lastReset) continue;
|
|
200
|
+
if (at === lastReset && event.type === "assistant_content_reset") {
|
|
201
|
+
if (event.content) yield event.content;
|
|
202
|
+
} else if (event.type === "token" && event.subAgent === void 0) {
|
|
203
|
+
yield event.content;
|
|
204
|
+
}
|
|
198
205
|
}
|
|
199
206
|
}
|
|
200
207
|
/**
|
|
201
|
-
*
|
|
208
|
+
* Every run event (tokens, approvals, `done`, …) as it arrives.
|
|
202
209
|
*
|
|
203
|
-
* @
|
|
204
|
-
* @throws {ModusError} When the stream emits an error event.
|
|
210
|
+
* @throws {ModusError} When the run reports an error.
|
|
205
211
|
* @throws {RunCancelledError} When the run is cancelled.
|
|
206
|
-
* @throws {StreamTimeoutError} When the
|
|
212
|
+
* @throws {StreamTimeoutError} When the run times out.
|
|
207
213
|
*/
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
if (normalized.type === "assistant_content_reset") {
|
|
220
|
-
this.textParts.length = 0;
|
|
221
|
-
this.textParts.push(normalized.content);
|
|
222
|
-
}
|
|
223
|
-
if (normalized.type === "done") {
|
|
224
|
-
this.final = {
|
|
225
|
-
content: this.textParts.join(""),
|
|
226
|
-
threadId: normalized.threadId,
|
|
227
|
-
runId: normalized.runId
|
|
228
|
-
};
|
|
229
|
-
yield normalized;
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
yield normalized;
|
|
233
|
-
}
|
|
214
|
+
eventStream() {
|
|
215
|
+
return this.replay(true);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Waits for the run to finish and returns its final answer. `approval` is
|
|
219
|
+
* set when the run stopped for a decision; continue with {@link resume}.
|
|
220
|
+
*
|
|
221
|
+
* @throws {ModusError} When the run reports an error or ends without finishing.
|
|
222
|
+
*/
|
|
223
|
+
async result() {
|
|
224
|
+
for await (const _event of this.replay(true)) {
|
|
234
225
|
}
|
|
226
|
+
if (this.final === void 0) throw new ModusError("Chat stream ended without a done event");
|
|
227
|
+
return this.final;
|
|
228
|
+
}
|
|
229
|
+
/** Resolve with the final {@link ChatResult}, so the session can be awaited. */
|
|
230
|
+
then(onfulfilled, onrejected) {
|
|
231
|
+
return this.result().then(onfulfilled, onrejected);
|
|
232
|
+
}
|
|
233
|
+
/** Handle a failed run, as on the promise `chat()` used to return. */
|
|
234
|
+
catch(onrejected) {
|
|
235
|
+
return this.result().catch(onrejected);
|
|
236
|
+
}
|
|
237
|
+
/** Run `onfinally` once the run settles, as on the promise `chat()` used to return. */
|
|
238
|
+
finally(onfinally) {
|
|
239
|
+
return this.result().finally(onfinally);
|
|
235
240
|
}
|
|
236
241
|
/**
|
|
237
|
-
*
|
|
242
|
+
* Approve or deny the action this run stopped for, continuing the same
|
|
243
|
+
* conversation.
|
|
238
244
|
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
245
|
+
* @param input.decision - `approve` or `deny`.
|
|
246
|
+
* @returns A new session for the continued run.
|
|
247
|
+
* @throws {ModusError} When called before the run has finished.
|
|
241
248
|
*
|
|
242
|
-
* @
|
|
243
|
-
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```ts
|
|
251
|
+
* const chat = client.modus.chat('Fix the typo in accounts', { model: 'claude-sonnet-5.5' })
|
|
252
|
+
* const first = await chat
|
|
253
|
+
* if (first.approval) {
|
|
254
|
+
* const done = await chat.resume({ decision: 'approve' })
|
|
255
|
+
* }
|
|
256
|
+
* ```
|
|
244
257
|
*/
|
|
245
|
-
|
|
258
|
+
resume(input) {
|
|
246
259
|
if (this.final === void 0) {
|
|
247
|
-
throw new ModusError(
|
|
248
|
-
|
|
249
|
-
|
|
260
|
+
throw new ModusError("resume() needs a finished run: await the chat first");
|
|
261
|
+
}
|
|
262
|
+
const { runId, threadId } = this.final;
|
|
263
|
+
validateId(runId, "run_id");
|
|
264
|
+
return new _ChatSession(this.http, {
|
|
265
|
+
path: `/agent/v1/runs/${encodeURIComponent(runId)}/resume`,
|
|
266
|
+
body: { sessionId: threadId, decision: input.decision },
|
|
267
|
+
sessionId: threadId,
|
|
268
|
+
baseUrl: this.request.baseUrl
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Stop reading the run and release its connection. Call it when you stop
|
|
273
|
+
* iterating before the run ends; a session that reached `done` has already
|
|
274
|
+
* let go. The run itself keeps going on the server.
|
|
275
|
+
*/
|
|
276
|
+
async close() {
|
|
277
|
+
this.finished = true;
|
|
278
|
+
await this.live?.return(void 0);
|
|
279
|
+
}
|
|
280
|
+
// ponytail: one consumer at a time; concurrent iterators would race on `live`.
|
|
281
|
+
async *replay(resetAware) {
|
|
282
|
+
let index = 0;
|
|
283
|
+
while (true) {
|
|
284
|
+
if (index < this.received.length) {
|
|
285
|
+
yield this.received[index++];
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
if (this.failure !== void 0) throw this.failure;
|
|
289
|
+
if (this.finished) return;
|
|
290
|
+
this.live ?? (this.live = this.open(resetAware));
|
|
291
|
+
try {
|
|
292
|
+
const next = await this.live.next();
|
|
293
|
+
if (next.done) {
|
|
294
|
+
this.finished = true;
|
|
295
|
+
} else {
|
|
296
|
+
this.received.push(next.value);
|
|
297
|
+
if (next.value.type === "done") await this.close();
|
|
298
|
+
}
|
|
299
|
+
} catch (error) {
|
|
300
|
+
this.failure = error;
|
|
301
|
+
throw error;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
async *open(resetAware) {
|
|
306
|
+
const request = this.request;
|
|
307
|
+
const body = resetAware ? { ...request.body, streamProtocolVersion: 2 } : request.body;
|
|
308
|
+
const lines = this.http.streamPost(request.path, body, { baseUrl: request.baseUrl });
|
|
309
|
+
for await (const event of parseSseStream(lines)) {
|
|
310
|
+
raiseForEvent(event);
|
|
311
|
+
if (event.type === "approval_required") this.approval = event;
|
|
312
|
+
if (event.type === "done") {
|
|
313
|
+
this.final = {
|
|
314
|
+
content: event.content ?? "",
|
|
315
|
+
threadId: event.threadId || this.request.sessionId,
|
|
316
|
+
runId: event.runId,
|
|
317
|
+
...this.approval !== void 0 ? { approval: this.approval } : {}
|
|
318
|
+
};
|
|
319
|
+
yield event;
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
yield event;
|
|
250
323
|
}
|
|
251
|
-
return this.final;
|
|
252
324
|
}
|
|
253
325
|
};
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
}
|
|
260
|
-
const data = await http.post(path, chatBody(message, options.model));
|
|
261
|
-
return data;
|
|
262
|
-
}
|
|
263
|
-
function chatStreamSession(http, config, resource, resourceId, message, options) {
|
|
264
|
-
validateId(resourceId, `${resource}_id`);
|
|
265
|
-
validateChatModel(options.model);
|
|
266
|
-
const path = agentHostRunsPath(resource, resourceId);
|
|
267
|
-
return new ChatStream(
|
|
268
|
-
http,
|
|
269
|
-
path,
|
|
270
|
-
agentRunsBody(message, options.model, {
|
|
271
|
-
sessionId: resolveSessionId(options.threadId),
|
|
272
|
-
organizationId: config.organizationId,
|
|
273
|
-
version: options.version
|
|
274
|
-
}),
|
|
275
|
-
config.agentHost
|
|
276
|
-
);
|
|
277
|
-
}
|
|
278
|
-
async function modusChatBuffered(http, message, options) {
|
|
279
|
-
validateChatModel(options.model);
|
|
280
|
-
const path = modusChatPath({ threadId: options.threadId });
|
|
281
|
-
const data = await http.post(path, chatBody(message, options.model));
|
|
282
|
-
return data;
|
|
326
|
+
function startChat(http, config, target, message, options) {
|
|
327
|
+
try {
|
|
328
|
+
return new ChatSession(http, chatRequest(config, target, message, options));
|
|
329
|
+
} catch (error) {
|
|
330
|
+
return new ChatSession(http, void 0, error);
|
|
331
|
+
}
|
|
283
332
|
}
|
|
284
|
-
function
|
|
333
|
+
function chatRequest(config, target, message, options) {
|
|
334
|
+
if (target.kind !== "modus") validateId(target.id, `${target.kind.slice(0, -1)}_id`);
|
|
285
335
|
validateChatModel(options.model);
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
336
|
+
const baseUrl = requireAgentHost(config);
|
|
337
|
+
const sessionId = resolveAgentRunSessionId(effectiveThreadId(options.threadId));
|
|
338
|
+
return {
|
|
339
|
+
path: runsPath(target),
|
|
340
|
+
body: {
|
|
341
|
+
message,
|
|
342
|
+
config: { model: options.model },
|
|
343
|
+
sessionId,
|
|
344
|
+
...config.organizationId !== void 0 ? { organizationId: config.organizationId } : {}
|
|
345
|
+
},
|
|
346
|
+
sessionId,
|
|
347
|
+
baseUrl
|
|
348
|
+
};
|
|
295
349
|
}
|
|
296
350
|
|
|
297
351
|
// src/types/workflows.ts
|
|
@@ -309,6 +363,65 @@ function conversationSkillId(item) {
|
|
|
309
363
|
return item.scopeId;
|
|
310
364
|
}
|
|
311
365
|
|
|
366
|
+
// src/_generated/resources/consumption/workflows.ts
|
|
367
|
+
var WorkflowsResourceBase = class {
|
|
368
|
+
/** @internal */
|
|
369
|
+
constructor(http, config) {
|
|
370
|
+
this.http = http;
|
|
371
|
+
this.config = config;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* List workflows.
|
|
375
|
+
*
|
|
376
|
+
* Returns a paginated page of workflows the caller can at least `use`. Workflows the caller
|
|
377
|
+
* cannot see are filtered out. Pagination uses an opaque token returned in `nextPageToken`.
|
|
378
|
+
*
|
|
379
|
+
* **Requires:** `workflows:read`
|
|
380
|
+
*
|
|
381
|
+
* @param options.pageSize - Items per page. Defaults to 25.
|
|
382
|
+
* @param options.pageToken - Opaque page token from a previous response's `nextPageToken`. Omit
|
|
383
|
+
* for the first page.
|
|
384
|
+
* @param options.search - Case-insensitive substring filter on workflow name.
|
|
385
|
+
* @param options.type - Filter by workflow type.
|
|
386
|
+
* @param options.view - Variation view. `active` reads the deployed version. `draft` reads the
|
|
387
|
+
* latest builder snapshot. `published` reads only a published workflow of type workflow that
|
|
388
|
+
* you can use; tasks are excluded.
|
|
389
|
+
* @param options.includeVariation - Include the requested variation payload (`trigger`,
|
|
390
|
+
* `workflowStructure`, `agentSelection`) on list rows.
|
|
391
|
+
* @returns A page of workflows.
|
|
392
|
+
*
|
|
393
|
+
* @example
|
|
394
|
+
* ```ts
|
|
395
|
+
* for await (const wf of (await client.workflows.list({ search: 'digest' })).autoPagingIter()) {
|
|
396
|
+
* console.log(wf.id, wf.name, wf.status)
|
|
397
|
+
* }
|
|
398
|
+
* ```
|
|
399
|
+
*/
|
|
400
|
+
list(options = {}) {
|
|
401
|
+
const pageSize = options.pageSize ?? 25;
|
|
402
|
+
validatePageSize(pageSize);
|
|
403
|
+
return this.listPage(pageSize, options.pageToken, options.search, options.type, options.view, options.includeVariation);
|
|
404
|
+
}
|
|
405
|
+
async listPage(pageSize, pageToken, search, type, view, includeVariation) {
|
|
406
|
+
const extra = {};
|
|
407
|
+
if (search !== void 0) extra.search = search;
|
|
408
|
+
if (type !== void 0) extra.type = type;
|
|
409
|
+
if (view !== void 0) extra.view = view;
|
|
410
|
+
if (includeVariation !== void 0) extra.includeVariation = includeVariation;
|
|
411
|
+
const data = asRecord(
|
|
412
|
+
await invokeWithRetry(this.config, this.http, "WorkflowsController_list", {
|
|
413
|
+
query: aipListParams(pageSize, pageToken, extra)
|
|
414
|
+
})
|
|
415
|
+
);
|
|
416
|
+
return buildAipPage(
|
|
417
|
+
data,
|
|
418
|
+
"workflows",
|
|
419
|
+
(raw) => raw,
|
|
420
|
+
(token) => this.listPage(pageSize, token, search, type, view, includeVariation)
|
|
421
|
+
);
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
|
|
312
425
|
// src/resources/workflows/runs.ts
|
|
313
426
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
314
427
|
var RUNS_MAX_PAGE_SIZE = 100;
|
|
@@ -363,6 +476,11 @@ function randomRunId() {
|
|
|
363
476
|
function sessionIdFromBody(body) {
|
|
364
477
|
return resolveAgentRunSessionId(body.sessionId);
|
|
365
478
|
}
|
|
479
|
+
function requireSessionId(sessionId) {
|
|
480
|
+
if (!sessionId?.trim()) {
|
|
481
|
+
throw new ValidationError("sessionId must be the run's conversation id (a non-empty string)");
|
|
482
|
+
}
|
|
483
|
+
}
|
|
366
484
|
function makeAgentRunStream(runId, events) {
|
|
367
485
|
return {
|
|
368
486
|
runId,
|
|
@@ -381,7 +499,7 @@ var WorkflowRunsResource = class {
|
|
|
381
499
|
/**
|
|
382
500
|
* List runs for a workflow.
|
|
383
501
|
*
|
|
384
|
-
* @param workflowId -
|
|
502
|
+
* @param workflowId - Numeric workflow id.
|
|
385
503
|
* @param options.pageSize - Maximum items per page (default 25, max 100).
|
|
386
504
|
* @param options.pageToken - Opaque token from a previous page.
|
|
387
505
|
* @param options.status - Filter by run status.
|
|
@@ -436,7 +554,7 @@ var WorkflowRunsResource = class {
|
|
|
436
554
|
/**
|
|
437
555
|
* Retrieve a workflow run by id.
|
|
438
556
|
*
|
|
439
|
-
* @param workflowId -
|
|
557
|
+
* @param workflowId - Numeric workflow id the run belongs to.
|
|
440
558
|
* @param runId - Run id (the list row's `workflowId` field, not the composite `id`).
|
|
441
559
|
* @param options.temporalRunId - Optional internal execution id when disambiguating retries.
|
|
442
560
|
* @returns Run details including status and output.
|
|
@@ -450,7 +568,7 @@ var WorkflowRunsResource = class {
|
|
|
450
568
|
*/
|
|
451
569
|
async get(workflowId, runId, options = {}) {
|
|
452
570
|
validateId(workflowId, "workflow_id");
|
|
453
|
-
if (!runId.trim()) throw new
|
|
571
|
+
if (!runId.trim()) throw new ValidationError("run_id must be a non-empty string");
|
|
454
572
|
const query = options.temporalRunId !== void 0 ? { temporalRunId: options.temporalRunId } : void 0;
|
|
455
573
|
const data = await invokeWithRetry(this.config, this.http, "WorkflowRunsController_get", {
|
|
456
574
|
pathParams: { id: workflowId, runId },
|
|
@@ -461,7 +579,7 @@ var WorkflowRunsResource = class {
|
|
|
461
579
|
/**
|
|
462
580
|
* Start a workflow run and stream run events.
|
|
463
581
|
*
|
|
464
|
-
* @param workflowId -
|
|
582
|
+
* @param workflowId - Numeric workflow id to run.
|
|
465
583
|
* @param body - Run body (`message`, optional `sessionId`, optional `version` as `published` or `draft`).
|
|
466
584
|
* @param options.idempotencyKey - Client-supplied idempotency key; defaults to `body.runId` or a new uuid.
|
|
467
585
|
* @returns A stream of run events (tokens, completion, errors, and related signals).
|
|
@@ -529,18 +647,21 @@ var WorkflowRunsResource = class {
|
|
|
529
647
|
return this.createRun("ModusRunsController_create", body, {}, options);
|
|
530
648
|
}
|
|
531
649
|
/**
|
|
532
|
-
* Resume an
|
|
650
|
+
* Resume a run paused at an approval or connect interrupt, and stream the continuation's events.
|
|
651
|
+
*
|
|
652
|
+
* The decision is the whole turn: send no `message` (a non-empty one is rejected).
|
|
533
653
|
*
|
|
534
|
-
* @param runId -
|
|
535
|
-
* @param body -
|
|
654
|
+
* @param runId - Id of the interrupted run.
|
|
655
|
+
* @param body - `sessionId` (the run's conversation id, required) and `decision`
|
|
656
|
+
* (`approve` / `deny` / `connected` / `cancelled`); optional `approvalTarget`.
|
|
536
657
|
* @param options.idempotencyKey - Client-supplied idempotency key; defaults to `body.runId` or a new uuid.
|
|
537
658
|
* @returns A stream of run events.
|
|
659
|
+
* @throws {ValidationError} When `sessionId` is blank, before any request is sent.
|
|
538
660
|
*
|
|
539
661
|
* @example
|
|
540
662
|
* ```ts
|
|
541
663
|
* const stream = client.workflows.runs.resume(runId, {
|
|
542
664
|
* decision: 'approve',
|
|
543
|
-
* message: 'Looks good — continue.',
|
|
544
665
|
* sessionId,
|
|
545
666
|
* })
|
|
546
667
|
* for await (const event of stream) {
|
|
@@ -550,6 +671,7 @@ var WorkflowRunsResource = class {
|
|
|
550
671
|
*/
|
|
551
672
|
resume(runId, body, options = {}) {
|
|
552
673
|
validateId(runId, "run_id");
|
|
674
|
+
requireSessionId(body.sessionId);
|
|
553
675
|
return this.createRun("ResumeRunsController_create", body, { runId }, options);
|
|
554
676
|
}
|
|
555
677
|
/**
|
|
@@ -570,39 +692,79 @@ var WorkflowRunsResource = class {
|
|
|
570
692
|
});
|
|
571
693
|
}
|
|
572
694
|
/**
|
|
573
|
-
*
|
|
695
|
+
* Poll a run's buffered events once (the JSON transport, not SSE).
|
|
574
696
|
*
|
|
575
697
|
* @param runId - Run id.
|
|
576
|
-
* @returns
|
|
698
|
+
* @returns The poll response: `events` (each with its stream `id` and `type`), `cursor`,
|
|
699
|
+
* `status` and `done`.
|
|
577
700
|
*/
|
|
578
701
|
async events(runId) {
|
|
579
702
|
validateId(runId, "run_id");
|
|
580
|
-
return invokeWithRetry(this.config, this.http, "RunLifecycleController_events", {
|
|
703
|
+
return await invokeWithRetry(this.config, this.http, "RunLifecycleController_events", {
|
|
581
704
|
pathParams: { runId }
|
|
582
705
|
});
|
|
583
706
|
}
|
|
584
707
|
/**
|
|
585
|
-
*
|
|
708
|
+
* Supersede a run's current turn with a follow-up turn.
|
|
709
|
+
*
|
|
710
|
+
* The run is cancelled and `nextRun` starts as a new run on the same conversation.
|
|
711
|
+
* On a run that has already finished nothing is cancelled, and `nextRun` simply
|
|
712
|
+
* starts a follow-up turn. `nextRun.runId` is pinned (a new uuid when you do not
|
|
713
|
+
* set one), so a retried request returns the same run instead of starting another.
|
|
586
714
|
*
|
|
587
715
|
* @param runId - Run id to interrupt.
|
|
716
|
+
* @param nextRun - The follow-up turn: `message` and `sessionId` (the run's conversation id).
|
|
717
|
+
* @param options.lastSeenEventId - Id of the last event you rendered, so the cancelled
|
|
718
|
+
* turn's saved output stops there.
|
|
719
|
+
* @returns The new run (`runId`, `status`); follow it with {@link stream}.
|
|
720
|
+
* @throws {ValidationError} When `nextRun.sessionId` is blank, before any request is sent.
|
|
721
|
+
*
|
|
722
|
+
* @example
|
|
723
|
+
* ```ts
|
|
724
|
+
* const { runId: nextRunId } = await client.workflows.runs.interrupt(runId, {
|
|
725
|
+
* message: 'Only count EMEA.',
|
|
726
|
+
* sessionId,
|
|
727
|
+
* })
|
|
728
|
+
* for await (const event of client.workflows.runs.stream(nextRunId)) {
|
|
729
|
+
* if (event.type === 'token') process.stdout.write(event.content)
|
|
730
|
+
* }
|
|
731
|
+
* ```
|
|
588
732
|
*/
|
|
589
|
-
async interrupt(runId) {
|
|
733
|
+
async interrupt(runId, nextRun, options = {}) {
|
|
590
734
|
validateId(runId, "run_id");
|
|
591
|
-
|
|
735
|
+
requireSessionId(nextRun.sessionId);
|
|
736
|
+
const jsonBody = {
|
|
737
|
+
nextRun: { ...nextRun, runId: nextRun.runId?.trim() || randomRunId() },
|
|
738
|
+
...options.lastSeenEventId ? { lastSeenEventId: options.lastSeenEventId } : {}
|
|
739
|
+
};
|
|
740
|
+
return await invokeWithRetry(this.config, this.http, "RunLifecycleController_interrupt", {
|
|
592
741
|
pathParams: { runId },
|
|
593
|
-
jsonBody
|
|
742
|
+
jsonBody
|
|
594
743
|
});
|
|
595
744
|
}
|
|
596
745
|
/**
|
|
597
|
-
*
|
|
746
|
+
* Replace the turn of a run that is still queued (not yet started).
|
|
598
747
|
*
|
|
599
748
|
* @param runId - Queued run id.
|
|
749
|
+
* @param nextRun - The replacement turn: `message` and `sessionId` (the run's conversation id).
|
|
750
|
+
* @returns The edited run (`runId`, `status`).
|
|
751
|
+
* @throws {ValidationError} When `nextRun.sessionId` is blank, before any request is sent.
|
|
752
|
+
* @throws {ConflictError} When the run has already started.
|
|
753
|
+
*
|
|
754
|
+
* @example
|
|
755
|
+
* ```ts
|
|
756
|
+
* await client.workflows.runs.editQueued(queuedRunId, {
|
|
757
|
+
* message: 'Summarize last week instead.',
|
|
758
|
+
* sessionId,
|
|
759
|
+
* })
|
|
760
|
+
* ```
|
|
600
761
|
*/
|
|
601
|
-
async editQueued(runId) {
|
|
762
|
+
async editQueued(runId, nextRun) {
|
|
602
763
|
validateId(runId, "run_id");
|
|
603
|
-
|
|
764
|
+
requireSessionId(nextRun.sessionId);
|
|
765
|
+
return await invokeWithRetry(this.config, this.http, "RunLifecycleController_editQueued", {
|
|
604
766
|
pathParams: { runId },
|
|
605
|
-
jsonBody: {}
|
|
767
|
+
jsonBody: { nextRun }
|
|
606
768
|
});
|
|
607
769
|
}
|
|
608
770
|
/**
|
|
@@ -630,12 +792,12 @@ var WorkflowRunsResource = class {
|
|
|
630
792
|
*
|
|
631
793
|
* @param sessionIds - Up to 100 session ids.
|
|
632
794
|
* @returns Active runs matching any of the given sessions.
|
|
633
|
-
* @throws {
|
|
795
|
+
* @throws {ValidationError} When more than 100 session ids are provided.
|
|
634
796
|
*/
|
|
635
797
|
async activeBySession(sessionIds) {
|
|
636
798
|
const uniqueSessionIds = [...new Set(sessionIds.map((id) => id.trim()).filter(Boolean))];
|
|
637
799
|
if (uniqueSessionIds.length > 100) {
|
|
638
|
-
throw new
|
|
800
|
+
throw new ValidationError("sessionIds must contain at most 100 ids");
|
|
639
801
|
}
|
|
640
802
|
return parseActiveRunsArray(
|
|
641
803
|
await invokeWithRetry(this.config, this.http, "RunLifecycleController_activeBySession", {
|
|
@@ -644,17 +806,19 @@ var WorkflowRunsResource = class {
|
|
|
644
806
|
);
|
|
645
807
|
}
|
|
646
808
|
/**
|
|
647
|
-
* Reconnect to
|
|
809
|
+
* Reconnect to a run and stream its events.
|
|
648
810
|
*
|
|
649
811
|
* @param runId - Run id to follow.
|
|
650
|
-
* @param options.lastEventId -
|
|
651
|
-
*
|
|
812
|
+
* @param options.lastEventId - The `id` of the last event you handled; the stream resumes
|
|
813
|
+
* after it. Omit to replay the run from its first event.
|
|
814
|
+
* @returns A stream of run events.
|
|
652
815
|
*
|
|
653
816
|
* @example
|
|
654
817
|
* ```ts
|
|
655
|
-
*
|
|
656
|
-
* for await (const event of stream) {
|
|
818
|
+
* let lastEventId: string | undefined
|
|
819
|
+
* for await (const event of client.workflows.runs.stream(runId, { lastEventId })) {
|
|
657
820
|
* if (event.type === 'token') process.stdout.write(event.content)
|
|
821
|
+
* lastEventId = event.id // after handling it: reconnect with it if the connection drops
|
|
658
822
|
* }
|
|
659
823
|
* ```
|
|
660
824
|
*/
|
|
@@ -734,87 +898,29 @@ var AgentWorkflowActionsResource = class {
|
|
|
734
898
|
};
|
|
735
899
|
|
|
736
900
|
// src/resources/workflows.ts
|
|
737
|
-
function workflowsListParams(pageSize, pageToken, search, type, view, includeVariation) {
|
|
738
|
-
const extra = {};
|
|
739
|
-
if (search !== void 0) extra.search = search;
|
|
740
|
-
if (type !== void 0) extra.type = type;
|
|
741
|
-
if (view !== void 0) extra.view = view;
|
|
742
|
-
if (includeVariation !== void 0) extra.includeVariation = includeVariation;
|
|
743
|
-
return aipListParams(pageSize, pageToken, extra);
|
|
744
|
-
}
|
|
745
901
|
function parseWorkflow(raw) {
|
|
746
902
|
return raw;
|
|
747
903
|
}
|
|
748
|
-
var WorkflowsResource = class {
|
|
904
|
+
var WorkflowsResource = class extends WorkflowsResourceBase {
|
|
749
905
|
/** @internal */
|
|
750
906
|
constructor(http, config) {
|
|
751
|
-
|
|
752
|
-
this.config = config;
|
|
907
|
+
super(http, config);
|
|
753
908
|
this.runs = new WorkflowRunsResource(http, config);
|
|
754
909
|
this.workflowActions = new AgentWorkflowActionsResource(http, config);
|
|
755
910
|
}
|
|
756
911
|
/**
|
|
757
|
-
*
|
|
912
|
+
* Retrieve a workflow by its numeric id.
|
|
758
913
|
*
|
|
759
|
-
* @param
|
|
760
|
-
* @param options.pageToken - Opaque token from a previous page.
|
|
761
|
-
* @param options.search - Case-insensitive substring filter on the workflow name.
|
|
762
|
-
* @param options.type - Workflow kind: `"task"` or `"workflow"`.
|
|
763
|
-
* @param options.view - Which saved version to return (`active` or `draft`).
|
|
764
|
-
* @param options.includeVariation - Include variation metadata when supported.
|
|
765
|
-
* @returns A page of workflows — use `.autoPagingIter()` for all pages.
|
|
766
|
-
*
|
|
767
|
-
* @example
|
|
768
|
-
* ```ts
|
|
769
|
-
* for await (const wf of (await client.workflows.list({ search: 'digest' })).autoPagingIter()) {
|
|
770
|
-
* console.log(wf.id, wf.name, wf.status)
|
|
771
|
-
* }
|
|
772
|
-
* ```
|
|
773
|
-
*/
|
|
774
|
-
list(options = {}) {
|
|
775
|
-
const pageSize = options.pageSize ?? 25;
|
|
776
|
-
validatePageSize(pageSize);
|
|
777
|
-
return this.listPage(
|
|
778
|
-
pageSize,
|
|
779
|
-
options.pageToken,
|
|
780
|
-
options.search,
|
|
781
|
-
options.type,
|
|
782
|
-
options.view,
|
|
783
|
-
options.includeVariation
|
|
784
|
-
);
|
|
785
|
-
}
|
|
786
|
-
async listPage(pageSize, pageToken, search, type, view, includeVariation) {
|
|
787
|
-
const data = asRecord(
|
|
788
|
-
await invokeWithRetry(this.config, this.http, "WorkflowsController_list", {
|
|
789
|
-
query: workflowsListParams(
|
|
790
|
-
pageSize,
|
|
791
|
-
pageToken,
|
|
792
|
-
search,
|
|
793
|
-
type,
|
|
794
|
-
view,
|
|
795
|
-
includeVariation
|
|
796
|
-
)
|
|
797
|
-
})
|
|
798
|
-
);
|
|
799
|
-
return buildAipPage(
|
|
800
|
-
data,
|
|
801
|
-
"workflows",
|
|
802
|
-
parseWorkflow,
|
|
803
|
-
(token) => this.listPage(pageSize, token, search, type, view, includeVariation)
|
|
804
|
-
);
|
|
805
|
-
}
|
|
806
|
-
/**
|
|
807
|
-
* Retrieve a workflow by ID or slug.
|
|
808
|
-
*
|
|
809
|
-
* @param workflowId - Numeric id or slug.
|
|
914
|
+
* @param workflowId - Numeric workflow id.
|
|
810
915
|
* @param options.view - Which saved version to return (`active` or `draft`).
|
|
811
916
|
* @param options.includeVariation - Include variation metadata when supported.
|
|
812
917
|
* @returns The workflow (`id`, `name`, `status`, …).
|
|
813
|
-
* @throws {NotFoundError} When no workflow
|
|
918
|
+
* @throws {NotFoundError} When no workflow has this id.
|
|
814
919
|
*
|
|
815
920
|
* @example
|
|
816
921
|
* ```ts
|
|
817
|
-
* const
|
|
922
|
+
* const [first] = (await client.workflows.list()).items
|
|
923
|
+
* const wf = await client.workflows.get(first.id)
|
|
818
924
|
* console.log(wf.name, wf.status)
|
|
819
925
|
* ```
|
|
820
926
|
*/
|
|
@@ -831,29 +937,51 @@ var WorkflowsResource = class {
|
|
|
831
937
|
});
|
|
832
938
|
return parseWorkflow(data);
|
|
833
939
|
}
|
|
940
|
+
/**
|
|
941
|
+
* Chat with a published workflow. Node output streams live from the agent
|
|
942
|
+
* host: iterate `textStream()` for tokens, or `await` the result for the
|
|
943
|
+
* workflow's final output.
|
|
944
|
+
*
|
|
945
|
+
* @param workflowId - Numeric workflow id.
|
|
946
|
+
* @param message - User message text.
|
|
947
|
+
* @param options.model - Required model id (e.g. `"claude-sonnet-5.5"`).
|
|
948
|
+
* @param options.threadId - Continue an existing conversation; omit to start new.
|
|
949
|
+
* @returns A chat session — iterate it or `await` it for `content`, `threadId`, `runId`.
|
|
950
|
+
* @throws {ModusError} When no agent host is known for a custom `baseUrl`.
|
|
951
|
+
*
|
|
952
|
+
* @example
|
|
953
|
+
* ```ts
|
|
954
|
+
* const { content } = await client.workflows.chat(workflowId, 'Run this week\'s digest', {
|
|
955
|
+
* model: 'claude-sonnet-5.5',
|
|
956
|
+
* })
|
|
957
|
+
* console.log(content)
|
|
958
|
+
* ```
|
|
959
|
+
*/
|
|
960
|
+
chat(workflowId, message, options) {
|
|
961
|
+
return startChat(this.http, this.config, { kind: "workflows", id: workflowId }, message, options);
|
|
962
|
+
}
|
|
834
963
|
};
|
|
835
964
|
|
|
836
|
-
// src/resources/connections.ts
|
|
837
|
-
|
|
838
|
-
const extra = {};
|
|
839
|
-
if (type !== void 0) extra.type = type;
|
|
840
|
-
return aipListParams(pageSize, pageToken, extra);
|
|
841
|
-
}
|
|
842
|
-
function parseConnection(raw) {
|
|
843
|
-
return raw;
|
|
844
|
-
}
|
|
845
|
-
var ConnectionsResource = class {
|
|
965
|
+
// src/_generated/resources/consumption/connections.ts
|
|
966
|
+
var ConnectionsResourceBase = class {
|
|
846
967
|
/** @internal */
|
|
847
968
|
constructor(http, config) {
|
|
848
969
|
this.http = http;
|
|
849
970
|
this.config = config;
|
|
850
971
|
}
|
|
851
972
|
/**
|
|
852
|
-
* List
|
|
973
|
+
* List connections.
|
|
853
974
|
*
|
|
854
|
-
*
|
|
855
|
-
*
|
|
856
|
-
*
|
|
975
|
+
* Returns a paginated page of warehouse and SaaS integration connections the caller can `use`.
|
|
976
|
+
* Connections the caller cannot access are filtered out. Use the returned `id` when creating
|
|
977
|
+
* saved-query context items. Pagination uses an opaque token returned in `nextPageToken`.
|
|
978
|
+
*
|
|
979
|
+
* **Requires:** `context:read`
|
|
980
|
+
*
|
|
981
|
+
* @param options.pageSize - Items per page. Defaults to 25.
|
|
982
|
+
* @param options.pageToken - Opaque page token from a previous response's `nextPageToken`. Omit
|
|
983
|
+
* for the first page.
|
|
984
|
+
* @param options.type - Filter by effective integration category (case-sensitive exact match).
|
|
857
985
|
* @returns A page of connections.
|
|
858
986
|
*/
|
|
859
987
|
list(options = {}) {
|
|
@@ -862,18 +990,24 @@ var ConnectionsResource = class {
|
|
|
862
990
|
return this.listPage(pageSize, options.pageToken, options.type);
|
|
863
991
|
}
|
|
864
992
|
async listPage(pageSize, pageToken, type) {
|
|
993
|
+
const extra = {};
|
|
994
|
+
if (type !== void 0) extra.type = type;
|
|
865
995
|
const data = asRecord(
|
|
866
996
|
await invokeWithRetry(this.config, this.http, "ConnectionsController_list", {
|
|
867
|
-
query:
|
|
997
|
+
query: aipListParams(pageSize, pageToken, extra)
|
|
868
998
|
})
|
|
869
999
|
);
|
|
870
1000
|
return buildAipPage(
|
|
871
1001
|
data,
|
|
872
1002
|
"connections",
|
|
873
|
-
|
|
1003
|
+
(raw) => raw,
|
|
874
1004
|
(token) => this.listPage(pageSize, token, type)
|
|
875
1005
|
);
|
|
876
1006
|
}
|
|
1007
|
+
};
|
|
1008
|
+
|
|
1009
|
+
// src/resources/connections.ts
|
|
1010
|
+
var ConnectionsResource = class extends ConnectionsResourceBase {
|
|
877
1011
|
/**
|
|
878
1012
|
* Find the first connection whose name matches (case-insensitive).
|
|
879
1013
|
*
|
|
@@ -898,6 +1032,52 @@ var ConnectionsResource = class {
|
|
|
898
1032
|
} while (token !== void 0);
|
|
899
1033
|
return void 0;
|
|
900
1034
|
}
|
|
1035
|
+
/**
|
|
1036
|
+
* List the selectable units on a connection (a repository, a schema, a project).
|
|
1037
|
+
*
|
|
1038
|
+
* @param connectionId - Connection id.
|
|
1039
|
+
* @param options.pageSize - Maximum items per page (default 25).
|
|
1040
|
+
* @param options.pageToken - Opaque token from a previous page.
|
|
1041
|
+
* @returns A page of selectable units — use {@link iterSelections} or `.autoPagingIter()` for every page.
|
|
1042
|
+
* @example
|
|
1043
|
+
* for await (const unit of client.connections.iterSelections('7a3f9d2c-1111-4000-a000-000000000abc')) {
|
|
1044
|
+
* console.log(unit.objectType, unit.path)
|
|
1045
|
+
* }
|
|
1046
|
+
*/
|
|
1047
|
+
listSelections(connectionId, options = {}) {
|
|
1048
|
+
validateId(connectionId, "connection_id");
|
|
1049
|
+
const pageSize = options.pageSize ?? 25;
|
|
1050
|
+
validatePageSize(pageSize);
|
|
1051
|
+
return this.listSelectionsPage(connectionId, pageSize, options.pageToken);
|
|
1052
|
+
}
|
|
1053
|
+
async listSelectionsPage(connectionId, pageSize, pageToken) {
|
|
1054
|
+
const data = asRecord(
|
|
1055
|
+
await invokeWithRetry(this.config, this.http, "ConnectionsController_listSelections", {
|
|
1056
|
+
pathParams: { connectionId },
|
|
1057
|
+
query: aipListParams(pageSize, pageToken)
|
|
1058
|
+
})
|
|
1059
|
+
);
|
|
1060
|
+
return buildAipPage(
|
|
1061
|
+
data,
|
|
1062
|
+
"selections",
|
|
1063
|
+
(raw) => raw,
|
|
1064
|
+
(token) => this.listSelectionsPage(connectionId, pageSize, token)
|
|
1065
|
+
);
|
|
1066
|
+
}
|
|
1067
|
+
/**
|
|
1068
|
+
* Yield every selectable unit on a connection, following pages.
|
|
1069
|
+
*
|
|
1070
|
+
* @param connectionId - Connection id.
|
|
1071
|
+
* @param options.pageSize - Maximum items per page (default 25).
|
|
1072
|
+
* @example
|
|
1073
|
+
* for await (const unit of client.connections.iterSelections('7a3f9d2c-1111-4000-a000-000000000abc')) {
|
|
1074
|
+
* console.log(unit.objectType, unit.displayName)
|
|
1075
|
+
* }
|
|
1076
|
+
*/
|
|
1077
|
+
async *iterSelections(connectionId, options = {}) {
|
|
1078
|
+
const page = await this.listSelections(connectionId, options);
|
|
1079
|
+
yield* page.autoPagingIter();
|
|
1080
|
+
}
|
|
901
1081
|
};
|
|
902
1082
|
|
|
903
1083
|
// src/resources/context/items.ts
|
|
@@ -1034,7 +1214,7 @@ var ContextItemsResource = class {
|
|
|
1034
1214
|
* contextType: 'note',
|
|
1035
1215
|
* dataPath: ['finance', 'arr-definition'],
|
|
1036
1216
|
* })
|
|
1037
|
-
* if (found) console.log(found.uid, found.
|
|
1217
|
+
* if (found) console.log(found.uid, found.content)
|
|
1038
1218
|
* ```
|
|
1039
1219
|
*/
|
|
1040
1220
|
async lookup(options) {
|
|
@@ -1056,14 +1236,19 @@ var ContextItemsResource = class {
|
|
|
1056
1236
|
}
|
|
1057
1237
|
}
|
|
1058
1238
|
/**
|
|
1059
|
-
*
|
|
1239
|
+
* Page through the elements of an array field inside one context item's content.
|
|
1240
|
+
*
|
|
1241
|
+
* Each row is `{ index, value }`: the element's position in the array and the
|
|
1242
|
+
* element itself. A field that is not an array reads as one element; a missing
|
|
1243
|
+
* field as none. Rejects with a not-found error when the item does not exist,
|
|
1244
|
+
* you cannot read it, or its context type is not `contextType`.
|
|
1060
1245
|
*
|
|
1061
1246
|
* @param uid - Item uid.
|
|
1062
1247
|
* @param contextType - Context type of the item.
|
|
1063
|
-
* @param contentKeyPath - Dot path to the
|
|
1064
|
-
* @param options.pageSize - Maximum
|
|
1065
|
-
* @param options.pageToken - Opaque token from a previous page.
|
|
1066
|
-
* @returns A page of value rows.
|
|
1248
|
+
* @param contentKeyPath - Dot path to the array inside item content (e.g. `"enumValues"`).
|
|
1249
|
+
* @param options.pageSize - Maximum elements per page (default 25).
|
|
1250
|
+
* @param options.pageToken - Opaque token from a previous page of the same item.
|
|
1251
|
+
* @returns A page of `{ index, value }` rows.
|
|
1067
1252
|
*
|
|
1068
1253
|
* @example
|
|
1069
1254
|
* ```ts
|
|
@@ -1074,7 +1259,7 @@ var ContextItemsResource = class {
|
|
|
1074
1259
|
* 'enumValues',
|
|
1075
1260
|
* { pageSize: 25 },
|
|
1076
1261
|
* )
|
|
1077
|
-
* for (const row of page.items) console.log(row)
|
|
1262
|
+
* for (const row of page.items) console.log(row.index, row.value)
|
|
1078
1263
|
* ```
|
|
1079
1264
|
*/
|
|
1080
1265
|
listValues(uid, contextType, contentKeyPath, options = {}) {
|
|
@@ -1083,13 +1268,13 @@ var ContextItemsResource = class {
|
|
|
1083
1268
|
return this.listValuesPage(uid, contextType, contentKeyPath, pageSize, options.pageToken);
|
|
1084
1269
|
}
|
|
1085
1270
|
/**
|
|
1086
|
-
*
|
|
1271
|
+
* Page through an array field of a context item already loaded via {@link ContextItemsResource.list} or {@link ContextItemsResource.get}.
|
|
1087
1272
|
*
|
|
1088
1273
|
* @param item - Context item (uses `item.uid` and `item.contextType`).
|
|
1089
|
-
* @param contentKeyPath - Dot path to the
|
|
1090
|
-
* @param options.pageSize - Maximum
|
|
1091
|
-
* @param options.pageToken - Opaque token from a previous page.
|
|
1092
|
-
* @returns A page of value rows.
|
|
1274
|
+
* @param contentKeyPath - Dot path to the array inside item content.
|
|
1275
|
+
* @param options.pageSize - Maximum elements per page (default 25).
|
|
1276
|
+
* @param options.pageToken - Opaque token from a previous page of the same item.
|
|
1277
|
+
* @returns A page of `{ index, value }` rows.
|
|
1093
1278
|
*
|
|
1094
1279
|
* @example
|
|
1095
1280
|
* ```ts
|
|
@@ -1172,11 +1357,36 @@ var IngestedDataResource = class {
|
|
|
1172
1357
|
}
|
|
1173
1358
|
};
|
|
1174
1359
|
|
|
1360
|
+
// src/_generated/resources/consumption/modus/conversations.ts
|
|
1361
|
+
var ModusConversationsResourceBase = class {
|
|
1362
|
+
/** @internal */
|
|
1363
|
+
constructor(http, config) {
|
|
1364
|
+
this.http = http;
|
|
1365
|
+
this.config = config;
|
|
1366
|
+
}
|
|
1367
|
+
/**
|
|
1368
|
+
* Get a Modus conversation.
|
|
1369
|
+
*
|
|
1370
|
+
* Returns the full message history for a conversation thread.
|
|
1371
|
+
*
|
|
1372
|
+
* **Requires:** `scopes:read`
|
|
1373
|
+
*
|
|
1374
|
+
* @param threadId - Thread id from a conversation list or chat response.
|
|
1375
|
+
*/
|
|
1376
|
+
async get(threadId) {
|
|
1377
|
+
validateId(threadId, "thread_id");
|
|
1378
|
+
const data = await invokeWithRetry(this.config, this.http, "ModusConversationsController_get", {
|
|
1379
|
+
pathParams: { threadId }
|
|
1380
|
+
});
|
|
1381
|
+
return data;
|
|
1382
|
+
}
|
|
1383
|
+
};
|
|
1384
|
+
|
|
1175
1385
|
// src/resources/modus/conversations.ts
|
|
1176
1386
|
var ALLOWED_KINDS = /* @__PURE__ */ new Set(["all", "modus", "scopes"]);
|
|
1177
1387
|
function listParams(pageSize, pageToken, kind, source, sourceRef) {
|
|
1178
1388
|
if (kind !== void 0 && !ALLOWED_KINDS.has(kind)) {
|
|
1179
|
-
throw new
|
|
1389
|
+
throw new ValidationError(
|
|
1180
1390
|
`kind must be one of ${[...ALLOWED_KINDS].sort().join(", ")}, got ${JSON.stringify(kind)}`
|
|
1181
1391
|
);
|
|
1182
1392
|
}
|
|
@@ -1189,13 +1399,9 @@ function listParams(pageSize, pageToken, kind, source, sourceRef) {
|
|
|
1189
1399
|
function parseListItem(raw) {
|
|
1190
1400
|
return raw;
|
|
1191
1401
|
}
|
|
1192
|
-
|
|
1193
|
-
return raw;
|
|
1194
|
-
}
|
|
1195
|
-
var ModusConversationsResource = class {
|
|
1402
|
+
var ModusConversationsResource = class extends ModusConversationsResourceBase {
|
|
1196
1403
|
constructor(http, config) {
|
|
1197
|
-
|
|
1198
|
-
this.config = config;
|
|
1404
|
+
super(http, config);
|
|
1199
1405
|
}
|
|
1200
1406
|
/**
|
|
1201
1407
|
* List conversations.
|
|
@@ -1231,19 +1437,6 @@ var ModusConversationsResource = class {
|
|
|
1231
1437
|
(token) => this.listPage(pageSize, token, kind, source, sourceRef)
|
|
1232
1438
|
);
|
|
1233
1439
|
}
|
|
1234
|
-
/**
|
|
1235
|
-
* Retrieve a conversation thread with full message history.
|
|
1236
|
-
*
|
|
1237
|
-
* @param threadId - Conversation thread id.
|
|
1238
|
-
* @returns Conversation with messages.
|
|
1239
|
-
*/
|
|
1240
|
-
async get(threadId) {
|
|
1241
|
-
validateId(threadId, "thread_id");
|
|
1242
|
-
const data = await invokeWithRetry(this.config, this.http, "ModusConversationsController_get", {
|
|
1243
|
-
pathParams: { threadId }
|
|
1244
|
-
});
|
|
1245
|
-
return parseConversation(data);
|
|
1246
|
-
}
|
|
1247
1440
|
};
|
|
1248
1441
|
|
|
1249
1442
|
// src/resources/modus/modus.ts
|
|
@@ -1256,6 +1449,9 @@ var ModusResource = class {
|
|
|
1256
1449
|
/**
|
|
1257
1450
|
* Compose full-environment context for an intent without running chat.
|
|
1258
1451
|
*
|
|
1452
|
+
* Runs on the agent host, like `chat`, so a compose may take up to 90 seconds; keep `timeoutMs`
|
|
1453
|
+
* above that. A compose still running at 90 seconds fails with `UPSTREAM_TIMEOUT` (504).
|
|
1454
|
+
*
|
|
1259
1455
|
* @param message - Natural-language intent used to select context.
|
|
1260
1456
|
* @param options.limit - Maximum context items to return. Omit to return all selected items.
|
|
1261
1457
|
* @returns Composition metadata (counts / session id). Use `chat` for a reply.
|
|
@@ -1267,104 +1463,64 @@ var ModusResource = class {
|
|
|
1267
1463
|
* ```
|
|
1268
1464
|
*/
|
|
1269
1465
|
async getContext(message, options = {}) {
|
|
1270
|
-
const data = await invokeWithRetry(this.config, this.http, "
|
|
1466
|
+
const data = await invokeWithRetry(this.config, this.http, "ModusContextComposeController_compose", {
|
|
1271
1467
|
jsonBody: omitUndefined({ message, limit: options.limit })
|
|
1272
1468
|
});
|
|
1273
1469
|
return data;
|
|
1274
1470
|
}
|
|
1275
1471
|
/**
|
|
1276
|
-
*
|
|
1472
|
+
* Chat with Modus, the org-wide assistant. The reply streams live from the
|
|
1473
|
+
* agent host: iterate `textStream()` for tokens, or `await` the result for
|
|
1474
|
+
* the final answer. Pass the returned `threadId` back to continue.
|
|
1277
1475
|
*
|
|
1278
1476
|
* @param message - User message text.
|
|
1279
|
-
* @param options.model - Required model id (e.g. `"claude-sonnet-5"`).
|
|
1477
|
+
* @param options.model - Required model id (e.g. `"claude-sonnet-5.5"`).
|
|
1280
1478
|
* @param options.threadId - Continue an existing conversation; omit to start new.
|
|
1281
|
-
* @returns
|
|
1479
|
+
* @returns A chat session — iterate it or `await` it for `content`, `threadId`, `runId`.
|
|
1480
|
+
* @throws {ModusError} When no agent host is known for a custom `baseUrl`.
|
|
1282
1481
|
*
|
|
1283
1482
|
* @example
|
|
1284
1483
|
* ```ts
|
|
1285
1484
|
* const result = await client.modus.chat('What tables describe revenue?', {
|
|
1286
|
-
* model: 'claude-sonnet-5',
|
|
1485
|
+
* model: 'claude-sonnet-5.5',
|
|
1287
1486
|
* })
|
|
1288
|
-
* console.log(result.content
|
|
1289
|
-
* const follow =
|
|
1290
|
-
* model: 'claude-sonnet-5',
|
|
1487
|
+
* console.log(result.content)
|
|
1488
|
+
* const follow = client.modus.chat('Break that down by region.', {
|
|
1489
|
+
* model: 'claude-sonnet-5.5',
|
|
1291
1490
|
* threadId: result.threadId,
|
|
1292
1491
|
* })
|
|
1492
|
+
* for await (const token of follow.textStream()) process.stdout.write(token)
|
|
1293
1493
|
* ```
|
|
1294
1494
|
*/
|
|
1295
1495
|
chat(message, options) {
|
|
1296
|
-
return
|
|
1297
|
-
}
|
|
1298
|
-
/**
|
|
1299
|
-
* Stream a Modus reply token by token (SSE).
|
|
1300
|
-
*
|
|
1301
|
-
* The request starts when you consume `textStream()` or `eventStream()`.
|
|
1302
|
-
*
|
|
1303
|
-
* @param message - User message text.
|
|
1304
|
-
* @param options.model - Required model id (e.g. `"claude-sonnet-5"`).
|
|
1305
|
-
* @param options.threadId - Continue an existing conversation; omit to start new.
|
|
1306
|
-
* @returns Chat stream — iterate `textStream()` for tokens.
|
|
1307
|
-
*
|
|
1308
|
-
* @example
|
|
1309
|
-
* ```ts
|
|
1310
|
-
* const stream = client.modus.chatStream('Summarize ARR in three bullets.', {
|
|
1311
|
-
* model: 'claude-sonnet-5',
|
|
1312
|
-
* })
|
|
1313
|
-
* for await (const token of stream.textStream()) {
|
|
1314
|
-
* process.stdout.write(token)
|
|
1315
|
-
* }
|
|
1316
|
-
* console.log(stream.getFinalResult().threadId)
|
|
1317
|
-
* ```
|
|
1318
|
-
*/
|
|
1319
|
-
chatStream(message, options) {
|
|
1320
|
-
return modusChatStreamSession(this.http, this.config, message, options);
|
|
1496
|
+
return startChat(this.http, this.config, { kind: "modus" }, message, options);
|
|
1321
1497
|
}
|
|
1322
1498
|
};
|
|
1323
1499
|
|
|
1324
|
-
// src/resources/scopes.ts
|
|
1325
|
-
|
|
1326
|
-
const extra = {};
|
|
1327
|
-
if (search !== void 0) extra.search = search;
|
|
1328
|
-
if (view !== void 0) extra.view = view;
|
|
1329
|
-
if (managerId !== void 0) extra.managerId = managerId;
|
|
1330
|
-
return aipListParams(pageSize, pageToken, extra);
|
|
1331
|
-
}
|
|
1332
|
-
function parseScope(raw) {
|
|
1333
|
-
return raw;
|
|
1334
|
-
}
|
|
1335
|
-
var ScopesResource = class {
|
|
1500
|
+
// src/_generated/resources/consumption/scopes.ts
|
|
1501
|
+
var ScopesResourceBase = class {
|
|
1336
1502
|
/** @internal */
|
|
1337
1503
|
constructor(http, config) {
|
|
1338
1504
|
this.http = http;
|
|
1339
1505
|
this.config = config;
|
|
1340
1506
|
}
|
|
1341
1507
|
/**
|
|
1342
|
-
*
|
|
1508
|
+
* List scopes.
|
|
1343
1509
|
*
|
|
1344
|
-
*
|
|
1345
|
-
*
|
|
1510
|
+
* Returns a paginated page of scopes the caller can at least `use`. Scopes the caller cannot see
|
|
1511
|
+
* are filtered out. Pagination uses an opaque token returned in `nextPageToken`.
|
|
1346
1512
|
*
|
|
1347
|
-
*
|
|
1348
|
-
* ```ts
|
|
1349
|
-
* for await (const row of (
|
|
1350
|
-
* await client.scopes.conversations(scopeId).list({ pageSize: 10 })
|
|
1351
|
-
* ).autoPagingIter()) {
|
|
1352
|
-
* console.log(row.threadId, row.firstMessage)
|
|
1353
|
-
* }
|
|
1354
|
-
* ```
|
|
1355
|
-
*/
|
|
1356
|
-
conversations(scopeId) {
|
|
1357
|
-
return new ScopeConversationsResource(this.http, this.config, scopeId);
|
|
1358
|
-
}
|
|
1359
|
-
/**
|
|
1360
|
-
* List scopes in the organisation.
|
|
1513
|
+
* **Requires:** `scopes:read`
|
|
1361
1514
|
*
|
|
1362
|
-
* @param options.pageSize - Items per page
|
|
1363
|
-
* @param options.pageToken - Opaque token from a previous
|
|
1364
|
-
*
|
|
1365
|
-
* @param options.
|
|
1366
|
-
* @param options.
|
|
1367
|
-
*
|
|
1515
|
+
* @param options.pageSize - Items per page. Defaults to 25.
|
|
1516
|
+
* @param options.pageToken - Opaque page token from a previous response's `nextPageToken`. Omit
|
|
1517
|
+
* for the first page.
|
|
1518
|
+
* @param options.search - Case-insensitive substring filter on scope name.
|
|
1519
|
+
* @param options.view - Variation view. `active` reads the deployed version, or the latest draft
|
|
1520
|
+
* when nothing is published. `draft` reads the latest builder snapshot. `published` reads only
|
|
1521
|
+
* the published version, and only scopes you can use.
|
|
1522
|
+
* @param options.managerId - Return only scopes supervised by this manager scope id.
|
|
1523
|
+
* @returns A page of scopes.
|
|
1368
1524
|
*
|
|
1369
1525
|
* @example
|
|
1370
1526
|
* ```ts
|
|
@@ -1376,57 +1532,87 @@ var ScopesResource = class {
|
|
|
1376
1532
|
list(options = {}) {
|
|
1377
1533
|
const pageSize = options.pageSize ?? 25;
|
|
1378
1534
|
validatePageSize(pageSize);
|
|
1379
|
-
return this.listPage(
|
|
1380
|
-
pageSize,
|
|
1381
|
-
options.pageToken,
|
|
1382
|
-
options.search,
|
|
1383
|
-
options.view,
|
|
1384
|
-
options.managerId
|
|
1385
|
-
);
|
|
1535
|
+
return this.listPage(pageSize, options.pageToken, options.search, options.view, options.managerId);
|
|
1386
1536
|
}
|
|
1387
1537
|
async listPage(pageSize, pageToken, search, view, managerId) {
|
|
1538
|
+
const extra = {};
|
|
1539
|
+
if (search !== void 0) extra.search = search;
|
|
1540
|
+
if (view !== void 0) extra.view = view;
|
|
1541
|
+
if (managerId !== void 0) extra.managerId = managerId;
|
|
1388
1542
|
const data = asRecord(
|
|
1389
1543
|
await invokeWithRetry(this.config, this.http, "ScopesController_list", {
|
|
1390
|
-
query:
|
|
1544
|
+
query: aipListParams(pageSize, pageToken, extra)
|
|
1391
1545
|
})
|
|
1392
1546
|
);
|
|
1393
1547
|
return buildAipPage(
|
|
1394
1548
|
data,
|
|
1395
1549
|
"scopes",
|
|
1396
|
-
|
|
1550
|
+
(raw) => raw,
|
|
1397
1551
|
(token) => this.listPage(pageSize, token, search, view, managerId)
|
|
1398
1552
|
);
|
|
1399
1553
|
}
|
|
1400
1554
|
/**
|
|
1401
|
-
*
|
|
1555
|
+
* Get a scope.
|
|
1402
1556
|
*
|
|
1403
|
-
*
|
|
1404
|
-
*
|
|
1405
|
-
*
|
|
1406
|
-
*
|
|
1557
|
+
* Returns a scope. `view=active` (default) is the deployed version, or the latest draft when
|
|
1558
|
+
* nothing is published. `view=draft` is the latest edits. `view=published` is only the published
|
|
1559
|
+
* version, and only if you can use the scope. Returns 404 if you cannot access it.
|
|
1560
|
+
*
|
|
1561
|
+
* **Requires:** `scopes:read`
|
|
1562
|
+
*
|
|
1563
|
+
* @param scopeId - Numeric scope id.
|
|
1564
|
+
* @param options.view - Which version to read. Defaults to `active`. `published` is only the
|
|
1565
|
+
* published version, and only if you can use the scope.
|
|
1407
1566
|
*
|
|
1408
1567
|
* @example
|
|
1409
1568
|
* ```ts
|
|
1410
|
-
* const
|
|
1569
|
+
* const [first] = (await client.scopes.list()).items
|
|
1570
|
+
* const scope = await client.scopes.get(first.id)
|
|
1411
1571
|
* console.log(scope.name, scope.status)
|
|
1412
1572
|
* ```
|
|
1413
1573
|
*/
|
|
1414
1574
|
async get(scopeId, options = {}) {
|
|
1415
1575
|
validateId(scopeId, "scope_id");
|
|
1416
|
-
const query = options.view !== void 0 ? { view: options.view } : void 0;
|
|
1417
1576
|
const data = await invokeWithRetry(this.config, this.http, "ScopesController_get", {
|
|
1418
1577
|
pathParams: { id: scopeId },
|
|
1419
|
-
query
|
|
1578
|
+
query: { view: options.view }
|
|
1420
1579
|
});
|
|
1421
|
-
return
|
|
1580
|
+
return data;
|
|
1581
|
+
}
|
|
1582
|
+
};
|
|
1583
|
+
|
|
1584
|
+
// src/resources/scopes.ts
|
|
1585
|
+
var ScopesResource = class extends ScopesResourceBase {
|
|
1586
|
+
/**
|
|
1587
|
+
* Return the conversations sub-resource scoped to `scopeId`.
|
|
1588
|
+
*
|
|
1589
|
+
* @param scopeId - Numeric scope id.
|
|
1590
|
+
* @returns Conversations resource for the scope.
|
|
1591
|
+
*
|
|
1592
|
+
* @example
|
|
1593
|
+
* ```ts
|
|
1594
|
+
* for await (const row of (
|
|
1595
|
+
* await client.scopes.conversations(scopeId).list({ pageSize: 10 })
|
|
1596
|
+
* ).autoPagingIter()) {
|
|
1597
|
+
* console.log(row.threadId, row.firstMessage)
|
|
1598
|
+
* }
|
|
1599
|
+
* ```
|
|
1600
|
+
*/
|
|
1601
|
+
conversations(scopeId) {
|
|
1602
|
+
return new ScopeConversationsResource(this.http, this.config, scopeId);
|
|
1422
1603
|
}
|
|
1423
1604
|
/**
|
|
1424
1605
|
* Compose context this scope would use for an intent, without running chat.
|
|
1425
1606
|
*
|
|
1426
|
-
*
|
|
1607
|
+
* Large bodies are bounded inline previews. This REST method does not expose file references
|
|
1608
|
+
* or a full-content fetch operation. Runs on the agent host, like `chat`, so a compose may take
|
|
1609
|
+
* up to 90 seconds; keep `timeoutMs` above that. A compose still running at 90 seconds fails
|
|
1610
|
+
* with `UPSTREAM_TIMEOUT` (504).
|
|
1611
|
+
*
|
|
1612
|
+
* @param scopeId - Numeric scope id.
|
|
1427
1613
|
* @param message - Natural-language intent used to select context.
|
|
1428
1614
|
* @param options.limit - Maximum context items to return. Omit to return all selected items.
|
|
1429
|
-
* @returns
|
|
1615
|
+
* @returns Composed context text plus selection counts, item UIDs, and correlation session id.
|
|
1430
1616
|
*
|
|
1431
1617
|
* @example
|
|
1432
1618
|
* ```ts
|
|
@@ -1438,63 +1624,40 @@ var ScopesResource = class {
|
|
|
1438
1624
|
*/
|
|
1439
1625
|
async getContext(scopeId, message, options = {}) {
|
|
1440
1626
|
validateId(scopeId, "scope_id");
|
|
1441
|
-
const data = await invokeWithRetry(this.config, this.http, "
|
|
1627
|
+
const data = await invokeWithRetry(this.config, this.http, "ScopeContextComposeController_compose", {
|
|
1442
1628
|
pathParams: { id: scopeId },
|
|
1443
1629
|
jsonBody: omitUndefined({ message, limit: options.limit })
|
|
1444
1630
|
});
|
|
1445
1631
|
return data;
|
|
1446
1632
|
}
|
|
1447
1633
|
/**
|
|
1448
|
-
*
|
|
1634
|
+
* Chat with a published scope. The reply streams live from the agent host:
|
|
1635
|
+
* iterate `textStream()` for tokens, or `await` the result for the final
|
|
1636
|
+
* answer. Pass the returned `threadId` back to continue the conversation.
|
|
1449
1637
|
*
|
|
1450
1638
|
* For the org-wide assistant use `client.modus.chat` instead.
|
|
1451
1639
|
*
|
|
1452
|
-
* @param scopeId -
|
|
1640
|
+
* @param scopeId - Numeric scope id (must be active for chat).
|
|
1453
1641
|
* @param message - User message text.
|
|
1454
|
-
* @param options.model - Required model id (e.g. `"claude-sonnet-5"`).
|
|
1642
|
+
* @param options.model - Required model id (e.g. `"claude-sonnet-5.5"`).
|
|
1455
1643
|
* @param options.threadId - Continue an existing conversation; omit to start new.
|
|
1456
|
-
* @returns
|
|
1644
|
+
* @returns A chat session — iterate it or `await` it for `content`, `threadId`, `runId`.
|
|
1645
|
+
* @throws {ModusError} When no agent host is known for a custom `baseUrl`.
|
|
1457
1646
|
*
|
|
1458
1647
|
* @example
|
|
1459
1648
|
* ```ts
|
|
1460
|
-
* const
|
|
1461
|
-
*
|
|
1462
|
-
* }
|
|
1463
|
-
* console.log(result.content, result.threadId)
|
|
1649
|
+
* const chat = client.scopes.chat(scopeId, 'What is our ARR trend?', { model: 'claude-sonnet-5.5' })
|
|
1650
|
+
* for await (const token of chat.textStream()) process.stdout.write(token)
|
|
1651
|
+
* const { threadId } = await chat
|
|
1464
1652
|
* const follow = await client.scopes.chat(scopeId, 'Break that down by segment.', {
|
|
1465
|
-
* model: 'claude-sonnet-5',
|
|
1466
|
-
* threadId
|
|
1653
|
+
* model: 'claude-sonnet-5.5',
|
|
1654
|
+
* threadId,
|
|
1467
1655
|
* })
|
|
1656
|
+
* console.log(follow.content)
|
|
1468
1657
|
* ```
|
|
1469
1658
|
*/
|
|
1470
1659
|
chat(scopeId, message, options) {
|
|
1471
|
-
return
|
|
1472
|
-
}
|
|
1473
|
-
/**
|
|
1474
|
-
* Stream a scope reply token by token (SSE).
|
|
1475
|
-
*
|
|
1476
|
-
* The request starts when you consume `textStream()` or `eventStream()`.
|
|
1477
|
-
*
|
|
1478
|
-
* @param scopeId - Scope numeric id or slug.
|
|
1479
|
-
* @param message - User message text.
|
|
1480
|
-
* @param options.model - Required model id (e.g. `"claude-sonnet-5"`).
|
|
1481
|
-
* @param options.threadId - Continue an existing conversation; omit to start new.
|
|
1482
|
-
* @param options.version - `"published"` or `"draft"`.
|
|
1483
|
-
* @returns Chat stream — iterate `textStream()` for tokens.
|
|
1484
|
-
*
|
|
1485
|
-
* @example
|
|
1486
|
-
* ```ts
|
|
1487
|
-
* const stream = client.scopes.chatStream(scopeId, 'Summarize in three bullets.', {
|
|
1488
|
-
* model: 'claude-sonnet-5',
|
|
1489
|
-
* })
|
|
1490
|
-
* for await (const token of stream.textStream()) {
|
|
1491
|
-
* process.stdout.write(token)
|
|
1492
|
-
* }
|
|
1493
|
-
* console.log(stream.getFinalResult().threadId)
|
|
1494
|
-
* ```
|
|
1495
|
-
*/
|
|
1496
|
-
chatStream(scopeId, message, options) {
|
|
1497
|
-
return chatStreamSession(this.http, this.config, "scopes", scopeId, message, options);
|
|
1660
|
+
return startChat(this.http, this.config, { kind: "scopes", id: scopeId }, message, options);
|
|
1498
1661
|
}
|
|
1499
1662
|
};
|
|
1500
1663
|
|
|
@@ -1524,12 +1687,15 @@ var SuggestionsResource = class {
|
|
|
1524
1687
|
* @param options.pageSize - Maximum items per page (default 5, max 12).
|
|
1525
1688
|
* @param options.pageToken - Opaque token from a previous page.
|
|
1526
1689
|
* @param options.scopeId - Filter to a single scope.
|
|
1527
|
-
* @param options.scopeIds - Filter to one or more scopes.
|
|
1690
|
+
* @param options.scopeIds - Filter to one or more scopes. An empty list throws; omit it for every scope.
|
|
1528
1691
|
* @returns A page of suggested questions.
|
|
1529
1692
|
*/
|
|
1530
1693
|
list(options = {}) {
|
|
1531
1694
|
const pageSize = options.pageSize ?? DEFAULT_SUGGESTIONS_PAGE_SIZE;
|
|
1532
1695
|
validatePageSize(pageSize, MAX_SUGGESTIONS_PAGE_SIZE);
|
|
1696
|
+
if (options.scopeIds?.length === 0) {
|
|
1697
|
+
throw new ValidationError("scopeIds requires at least one id; omit it to list suggestions for every scope");
|
|
1698
|
+
}
|
|
1533
1699
|
return this.listPage(pageSize, options.pageToken, options.scopeId, options.scopeIds);
|
|
1534
1700
|
}
|
|
1535
1701
|
async listPage(pageSize, pageToken, scopeId, scopeIds) {
|
|
@@ -1577,7 +1743,8 @@ export {
|
|
|
1577
1743
|
APIConnectionError,
|
|
1578
1744
|
AgentType,
|
|
1579
1745
|
AuthenticationError,
|
|
1580
|
-
|
|
1746
|
+
BadRequestError,
|
|
1747
|
+
ChatSession,
|
|
1581
1748
|
ConflictError,
|
|
1582
1749
|
InternalServerError,
|
|
1583
1750
|
Modus,
|