@corvio/cli 0.1.0-beta.36 → 0.1.0-beta.38
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/README.md +23 -2
- package/dist/cli.js +148 -16
- package/dist/core.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,6 +10,9 @@ corvio auth status
|
|
|
10
10
|
corvio agents connect --provider codex --project . --json
|
|
11
11
|
corvio collaboration status --json --no-input
|
|
12
12
|
corvio ask --prompt 'Summarize recurring launch risks' --json
|
|
13
|
+
corvio ask --background --prompt 'Reconcile the current launch evidence' --json
|
|
14
|
+
corvio questions operation <operation_id> --after-cursor <progress_cursor> --wait-until-terminal --json
|
|
15
|
+
corvio questions cancel <operation_id> --yes --json
|
|
13
16
|
corvio files upload --file ./research.pdf --json
|
|
14
17
|
corvio files get <asset_id> --content --json
|
|
15
18
|
corvio files organize <asset_id> --instruction 'Create a reusable decision brief' --yes --wait-until-terminal --timeout-seconds 1200 --json
|
|
@@ -38,11 +41,29 @@ require reauthorization.
|
|
|
38
41
|
|
|
39
42
|
The CLI rejects unknown/duplicate options and malformed integer bounds before network access. Normal API calls have a bounded timeout (`CORVIO_REQUEST_TIMEOUT_MS`, maximum ten minutes); only reads, explicit idempotency contracts, revision guards, and other owner-declared safe operations retry automatically. Document commands accept both bare document IDs and canonical `workspace_id/document_id` handles; a canonical handle that disagrees with the selected Workspace fails before remote access, and successful reads return `canonical_id` for direct reuse. `docs read --mode auto` returns a complete small Page or a large-Page overview, then supports exact section, line-range, literal-search, and full projections. `docs patch` applies 1–20 exact non-overlapping L# replacements at the fetched revision and returns a compact readback instead of replaying untouched content. `docs get --output` keeps compatibility full-body download but omits the body from stdout; create/update request compact mutation receipts. Document updates preflight only a bounded overview for the current revision when `--expected-revision` is omitted. `docs table-read` returns a bounded stable-ID projection; `docs table-mutate` accepts a JSON payload for at most 50 cell updates or row appends and requires the fetched revision, while formulas, styles, structure, sorting, and semantic transformations remain `corvio ask --allow-actions` work. When the executing principal is a connected Agent, document and table mutations also require `--change-summary`, create a visible document-level comment after the guarded update, and return its receipt; a comment failure is reported as a partial effect rather than silent success. When a Corvio document or comment supplied the task, use `corvio agent closeout` to return the verified outcome, optionally resolve the thread, and read both document and thread back. Downloads, uploads, and Markdown pulls verify SHA-256 receipts before replacing local files; local writes are atomic, remote default filenames cannot escape the current directory, and Sync refuses symbolic-link traversal while checkpointing each successful push.
|
|
40
43
|
|
|
41
|
-
For `corvio ask`,
|
|
42
|
-
|
|
44
|
+
For `corvio ask`, keep the user's natural question unchanged, then append the smallest complete decision-relevant context or stable handles
|
|
45
|
+
as a separate clause. A carried Project handle normally bounds a cross-branch question without enumerating all descendants. Handles are
|
|
46
|
+
evidence addresses: do not invent a comparison rubric, prescribe reasoning steps, substitute another user objective, or turn current Tree
|
|
47
|
+
labels into a detailed task plan. Unless the user chose them, do not invent taxonomy, titles, artifact counts, or Corvio's internal plan.
|
|
48
|
+
In a bounded read-only continuation, use `corvio ask --workspace <workspace_id> --prompt "<unchanged question; Context: project handle>"
|
|
49
|
+
--json --no-input` when a trusted current-task or prior receipt already
|
|
50
|
+
proves this authenticated CLI and exact Workspace. Answer-only is
|
|
51
|
+
the default: omit `--allow-actions`; the CLI has no `--mode` option. Start the command once; do not launch an identical Question concurrently
|
|
52
|
+
or retry before terminal exit. The command returns the terminal Question without model-visible
|
|
53
|
+
polling. Transport continuity does not prove a cheaper processing profile; leave profile selection on `auto` unless the unresolved semantic
|
|
54
|
+
bottleneck independently justifies another profile. Do not install, probe, or switch to the CLI only for that optimization, and do not
|
|
55
|
+
extend it to an unbound Workspace.
|
|
56
|
+
Read the terminal Question receipt and use `artifact.url` or
|
|
43
57
|
`links.primary_artifact` verbatim; `reader_output` artifacts are deliverables, `structure_container` artifacts are hierarchy, and
|
|
44
58
|
`node_id` is never a document URL.
|
|
45
59
|
|
|
60
|
+
For a Question that may outlive one host turn, add `--background`. The command returns one durable `operation_id` immediately. Continue
|
|
61
|
+
that same operation with `corvio questions operation`; `--wait-until-terminal` keeps the status loop inside the CLI, while
|
|
62
|
+
`--after-cursor` returns only later user-visible milestones. A local deadline is not remote cancellation. Use
|
|
63
|
+
`corvio questions cancel <operation_id> --yes` to request a stop, and do not report success until the returned state is actually
|
|
64
|
+
`cancelled`. Progress is a bounded phase summary, never hidden reasoning or a provisional final answer. To correct the objective, finish
|
|
65
|
+
or cancel the current operation and start a successor `corvio ask --conversation-id <conversation_id>` rather than silently replacing it.
|
|
66
|
+
|
|
46
67
|
Treat files as a value ladder, not one upload event. Upload/finalize preserves the exact original, provenance, hash, policy, and stable Asset ID. A selected Markdown file can become an editable Page through `corvio docs create --file`; for other formats or a coherent source set, use `corvio files organize` or `corvio ask --allow-actions` to produce the reader-facing Page, Spreadsheet, Presentation, Code, HTML Artifact, or reading layer that fits the task. Stable facts/preferences may enter Memory; only an evidence-backed reusable method, configuration, constraint, or quality bar should become a Project Skill.
|
|
47
68
|
|
|
48
69
|
Use `corvio files get <asset_id> --content` when the task needs only bounded facts from one retained source. The response preserves the immutable original as authority, reports its source hash and whether the projection is complete or truncated, and does not create a Question or materialize another document. Never infer unseen workbook rows/sheets or document sections.
|
package/dist/cli.js
CHANGED
|
@@ -39,7 +39,7 @@ import {
|
|
|
39
39
|
agentCredentialPath,
|
|
40
40
|
} from "./core.js";
|
|
41
41
|
|
|
42
|
-
const VERSION = "0.1.0-beta.
|
|
42
|
+
const VERSION = "0.1.0-beta.38";
|
|
43
43
|
const DEFAULT_API_BASE = "https://api.corvio.ai/v1";
|
|
44
44
|
const DEFAULT_APP_BASE = "https://corvio.ai";
|
|
45
45
|
const USER_AGENT = `corvio-cli/${VERSION}`;
|
|
@@ -49,6 +49,8 @@ const MAX_MARKDOWN_CHARACTERS = 120_000;
|
|
|
49
49
|
const DEFAULT_FILE_OPERATION_WAIT_TIMEOUT_SECONDS = 1_200;
|
|
50
50
|
const MAX_FILE_OPERATION_WAIT_TIMEOUT_SECONDS = 7_200;
|
|
51
51
|
const FILE_OPERATION_PENDING_STATUSES = new Set(["accepted", "pending", "prepared", "queued", "running"]);
|
|
52
|
+
const QUESTION_OPERATION_PENDING_STATUSES = new Set(["queued", "running"]);
|
|
53
|
+
const READ_ONLY_LOCAL_STATE_ERROR_CODES = new Set(["EACCES", "EPERM", "EROFS"]);
|
|
52
54
|
const CORVIO_SKILL_ARCHIVE = "https://corvio.ai/developers/skills/corvio-operate-workspace/corvio-operate-workspace.zip";
|
|
53
55
|
const AGENT_SKILLS_INSTALLER_VERSION = "1.5.23";
|
|
54
56
|
const GLOBAL_OPTIONS = Object.freeze([
|
|
@@ -63,6 +65,17 @@ const GLOBAL_OPTIONS = Object.freeze([
|
|
|
63
65
|
"version",
|
|
64
66
|
]);
|
|
65
67
|
|
|
68
|
+
function isReadOnlyLocalStateError(error) {
|
|
69
|
+
const visited = new Set();
|
|
70
|
+
let current = error;
|
|
71
|
+
while (current && typeof current === "object" && !visited.has(current)) {
|
|
72
|
+
visited.add(current);
|
|
73
|
+
if (READ_ONLY_LOCAL_STATE_ERROR_CODES.has(String(current.code || "").toUpperCase())) return true;
|
|
74
|
+
current = current.cause;
|
|
75
|
+
}
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
|
|
66
79
|
const COMMAND_OPTIONS = Object.freeze({
|
|
67
80
|
"auth:login": ["force"],
|
|
68
81
|
"auth:status": [],
|
|
@@ -76,7 +89,7 @@ const COMMAND_OPTIONS = Object.freeze({
|
|
|
76
89
|
"ask:": [
|
|
77
90
|
"prompt", "conversation-id", "sources", "allow-actions", "context-file", "idempotency-key",
|
|
78
91
|
"processing-profile", "max-processing-profile", "scan-mode", "skills-extraction-mode", "caller-model",
|
|
79
|
-
"file", "asset-ids", "mime-type",
|
|
92
|
+
"file", "asset-ids", "mime-type", "background",
|
|
80
93
|
],
|
|
81
94
|
"agents:list": ["include-revoked"],
|
|
82
95
|
"agents:connect": [
|
|
@@ -102,6 +115,8 @@ const COMMAND_OPTIONS = Object.freeze({
|
|
|
102
115
|
],
|
|
103
116
|
"questions:list": ["limit", "cursor", "conversation-id"],
|
|
104
117
|
"questions:get": ["id"],
|
|
118
|
+
"questions:operation": ["id", "after-cursor", "wait-until-terminal", "timeout-seconds"],
|
|
119
|
+
"questions:cancel": ["id"],
|
|
105
120
|
"conversations:list": ["limit", "cursor"],
|
|
106
121
|
"conversations:get": ["id"],
|
|
107
122
|
"search:": ["query", "limit", "page-id", "node-id"],
|
|
@@ -159,7 +174,7 @@ Usage:
|
|
|
159
174
|
corvio ask --prompt <text> [--file <path>] [--asset-ids <id,id>] [--conversation-id <id>] [--allow-actions] [--processing-profile auto|economy|standard|deep]
|
|
160
175
|
corvio agents list|connect|create|update|rotate [id]
|
|
161
176
|
corvio agent claim|renew|complete|fail|comments|comment|reply|status|closeout|run [id]
|
|
162
|
-
corvio questions list|get [id]
|
|
177
|
+
corvio questions list|get|operation|cancel [id]
|
|
163
178
|
corvio conversations list|get [id]
|
|
164
179
|
corvio search <query>
|
|
165
180
|
corvio docs list|get|read|patch|table-read|table-mutate|create|update|move|archive|restore|share|open [id]
|
|
@@ -185,10 +200,10 @@ const COMMAND_HELP = Object.freeze({
|
|
|
185
200
|
workspaces: `Usage:\n corvio workspaces list\n corvio workspaces use <workspace-id>\n corvio workspaces current\n corvio workspaces create --name <name> [--kind personal|team]\n\nWorkspace status and blocked capability reasons are returned with each item.`,
|
|
186
201
|
capabilities: `Usage: corvio capabilities [--json]\n\nShow live API resources, principal scopes, selected Workspace status, and CLI compatibility.`,
|
|
187
202
|
collaboration: `Usage:\n corvio collaboration status [--project <path>] [--provider codex|claude_code|copilot|workbuddy]\n\nCheck local Corvio prerequisites and every discoverable Corvio Skill copy. Current copies stay quiet; non-current receipts include one compact Agent notice and a source-aware next action. Standalone refresh commands pin the verified installer, select exactly one provider, and preserve project/global scope. WorkBuddy inspection is read-only and never changes ~/.workbuddy. The CLI cannot prove that the current host task loaded a particular copy, or whether remote MCP or host memory is active.`,
|
|
188
|
-
ask: `Usage: corvio ask --prompt <text> [--file <path>] [--asset-ids <id,id>] [--conversation-id <id>] [--sources workspace,web,memory] [--allow-actions] [--processing-profile auto|economy|standard|deep] [--max-processing-profile economy|standard|deep] [--scan-mode auto|always|off] [--skills-extraction-mode auto|always|off] [--caller-model <host-model>] [--context-file <json>] [--idempotency-key <key>]\n\
|
|
203
|
+
ask: `Usage: corvio ask --prompt <text> [--file <path>] [--asset-ids <id,id>] [--conversation-id <id>] [--sources workspace,web,memory] [--allow-actions] [--background] [--processing-profile auto|economy|standard|deep] [--max-processing-profile economy|standard|deep] [--scan-mode auto|always|off] [--skills-extraction-mode auto|always|off] [--caller-model <host-model>] [--context-file <json>] [--idempotency-key <key>]\n\nAnswer-only is the default: omit --allow-actions; there is no --mode option. Keep the user's natural question unchanged, then append the smallest complete decision-relevant context or stable handles as a separate clause. A carried Project handle normally bounds a cross-branch question without enumerating all descendants. Handles are evidence addresses: do not invent a comparison rubric, prescribe reasoning steps, substitute another user objective, or turn current Tree labels into a detailed task plan. Unless the user chose them, do not invent taxonomy, titles, artifact count, or Corvio's internal plan; Corvio chooses the cognitive structure and carriers. In a bounded read-only continuation, start this foreground command exactly once when a trusted current-task or prior receipt already proves this authenticated CLI and exact Workspace; do not launch an identical Question concurrently or retry before terminal exit. If the shell tool yields a running-session handle, wait on that exact handle until the CLI exits instead of answering from prior context. It returns the terminal Question without model-visible polling. Use --background for work that should outlive the current shell; it returns one durable operation immediately. Inspect it with questions operation, stop it with questions cancel, and use the terminal conversation_id for a corrected follow-up instead of silently changing an in-flight objective. Transport continuity does not prove a cheaper processing profile; leave processing on auto unless the remaining transformation independently justifies another profile. Do not install, probe, or switch to the CLI only to avoid MCP polling, and do not extend it to an unbound Workspace. --file retains the selected local file, verifies its hash, and attaches the finalized Asset to this exact question. --asset-ids attaches already-retained Corvio Assets. Use --allow-actions when Corvio should create the Page, Spreadsheet, Presentation, Code, HTML Artifact, Memory, or qualifying Project Skill that best serves the result. A continuation handle is subject evidence, not necessarily the durable write destination: for a reusable pattern or method, resolve the fitting same-scope Memory or Skill owner before admitting or merging it. Read the terminal Question receipt and use artifact.url or links.primary_artifact verbatim; reader_output artifacts are deliverables, structure_container artifacts are hierarchy, and node_id is never a document URL. Upload alone is not evidence of interpretation. Skill extraction mode always requires --allow-actions and an evidence-backed decision, not forced Skill creation; answer-only questions may use auto or off.`,
|
|
189
204
|
agents: `Usage:\n corvio agents list\n corvio agents connect [--provider codex|claude_code|copilot] [--project <path>] [--permission-profile read_only|workspace_write|danger_full_access] [--trigger-policy owner_only|workspace_members] [--display-name <name>] [--recover-credential] [--no-listen]\n corvio agents create --handle <handle> --display-name <name> [--provider codex|claude_code|copilot|custom] [--permissions read,comment,edit]\n corvio agents update <id> [--display-name <name>] [--status active|paused|revoked] [--permissions <list>]\n corvio agents rotate <id>\n\n'connect' binds the current Git project (or --project path) to one stable personal Agent. Repeating it is idempotent; another project creates another Agent. It reports provider/CLI, listener, and local Skill prerequisites separately; run corvio collaboration status after installing or refreshing the Skill. The CLI cannot prove that the current host task loaded those surfaces. The default workspace_write profile is limited by the provider's native sandbox. owner_only is the safe trigger default. Secrets and absolute project paths stay local.`,
|
|
190
205
|
agent: `Usage:\n corvio agent claim [--worker-id <id>] [--wait-seconds <0-30>]\n corvio agent renew <event-id> --lease-token <token> [--lease-seconds <30-900>]\n corvio agent complete <event-id> --lease-token <token> [--result-file <json>]\n corvio agent fail <event-id> --lease-token <token> --error <message>\n corvio agent mentions --document-id <id> [--query <name>]\n corvio agent comments --document-id <id>\n corvio agent comment --document-id <id> --body <text> [--selection-file <json>] [--start-new-chain] [--idempotency-key <key>]\n corvio agent reply <thread-id> --document-id <id> --body <text> [--source-event-id <id> --source-event-lease-token <token>|--start-new-chain] [--idempotency-key <key>]\n corvio agent status <thread-id> --document-id <id> --status open|resolved\n corvio agent closeout --document-id <id> [--thread-id <id>] --body <verified-result> [--status open|resolved] [--idempotency-key <key>]\n corvio agent run [--provider codex|claude_code|copilot|custom] [--handler <executable>] [--agent <id>] [--once] [--processing-profile auto|economy|standard|deep] [--max-processing-profile economy|standard|deep] [--scan-mode auto|always|off] [--skills-extraction-mode auto|always|off] [--caller-model <host-model>]\n\nUse mentions before commenting when the target is uncertain; aliases resolve to stable user or Agent IDs and ambiguity fails closed. Use closeout when a Corvio document or comment owned the task: it returns the verified result to that surface and reads document/comments back. Agent-to-Agent comments require either a claimed source event or explicit --start-new-chain. The runner iteratively exchanges origin-scoped evidence with Corvio Query/Writer, then invokes the bound provider inside its local project. Local code changes use the recorded provider permission profile; complex Corvio document changes belong to Query/Writer. Provider children never receive Corvio credentials.`,
|
|
191
|
-
questions: `Usage:\n corvio questions list [--limit <n>] [--cursor <cursor>] [--conversation-id <id>]\n corvio questions get <question-id
|
|
206
|
+
questions: `Usage:\n corvio questions list [--limit <n>] [--cursor <cursor>] [--conversation-id <id>]\n corvio questions get <question-id>\n corvio questions operation <operation-id> [--after-cursor <n>] [--wait-until-terminal] [--timeout-seconds <1-7200>]\n corvio questions cancel <operation-id> --yes\n\nA Question operation is the durable owner for background work. operation returns only new user-visible milestones after --after-cursor and never exposes hidden reasoning or provisional answer text. --wait-until-terminal keeps deterministic polling in this process and returns a typed deadline receipt if the local deadline expires. cancel is idempotent; treat cancellation_requested as non-terminal and verify cancelled before telling the user the task stopped. Cancellation does not roll back effects that already settled. To correct the objective, stop or finish the current operation, then use corvio ask --conversation-id <conversation_id> so the new Question is an explicit successor.`,
|
|
192
207
|
conversations: `Usage:\n corvio conversations list [--limit <n>] [--cursor <cursor>]\n corvio conversations get <conversation-id>`,
|
|
193
208
|
search: `Usage: corvio search <query> [--limit <n>] [--page-id <id>] [--node-id <id>]`,
|
|
194
209
|
docs: `Usage:\n corvio docs list [--limit <n>] [--cursor <cursor>] [--lifecycle active|archived]\n corvio docs get <id> [--output <path>]\n corvio docs read <id> [--mode auto|overview|line-range|section|search|full] [--start-line <n> --end-line <n>|--section-ref <S#>|--query <text>] [--max-chars <n>]\n corvio docs patch <id> --input <json> --yes [--operation-id <id>] [--change-summary <text>]\n corvio docs table-read <id> [--table-id <id>] [--after-row-id <id>] [--limit <1-100>]\n corvio docs table-mutate <id> --input <json> --yes [--operation-id <id>] [--change-summary <text>]\n corvio docs create --title <title> [--file <path>|--markdown <text>] [--parent-node-id <id>] [--idempotency-key <key>]\n corvio docs update <id> [--title <title>] [--file <path>|--markdown <text>] [--expected-revision <n>] [--change-summary <text>]\n corvio docs move <id> --parent-node-id <id>\n corvio docs archive <id> --yes\n corvio docs restore <id> --yes\n corvio docs share <id> --yes [--display-name <name>]\n corvio docs open <id>\n\nUse \`docs read --mode auto\` first for a small full body or a large-document overview, then read an exact section or line range. Use \`docs patch\` when the host already knows 1-20 exact L# replacements; it preserves untouched lines and returns a compact verified delta. A selected Markdown file can become an editable Page without resending the body through the model. Use \`docs update\` only when whole-body replacement is the smallest faithful change. Delegate document-wide judgment, cross-source synthesis, structure/formatting interpretation, and typed Spreadsheet, Presentation, Code, or HTML work to \`corvio ask --allow-actions\`. A Project is a structure container; body writes fail with project_structure_container_body_write_disabled, while a title-only Project rename remains valid. Projects stay at the Workspace root and cannot be nested; use \`files organize\` or \`ask --allow-actions\` for Work Model maintenance. Use table-read plus table-mutate for bounded stable-ID cell updates or row appends. Agent-authenticated document changes require --change-summary and create a visible document-level comment after the guarded update. When a document/comment is the task owner, use \`corvio agent closeout\` to return verified work to that same collaboration surface and read it back.`,
|
|
@@ -246,6 +261,8 @@ function validateInvocation(options, positionals) {
|
|
|
246
261
|
const actionsWithId = new Set([
|
|
247
262
|
"workspaces:use",
|
|
248
263
|
"questions:get",
|
|
264
|
+
"questions:operation",
|
|
265
|
+
"questions:cancel",
|
|
249
266
|
"conversations:get",
|
|
250
267
|
"docs:get",
|
|
251
268
|
"docs:read",
|
|
@@ -1262,7 +1279,7 @@ async function ask(options, positionals) {
|
|
|
1262
1279
|
const uniqueAssetIds = [...new Set(assetIds.map((value) => String(value).trim()).filter(Boolean))];
|
|
1263
1280
|
let result;
|
|
1264
1281
|
try {
|
|
1265
|
-
result = await api.request("/questions", {
|
|
1282
|
+
result = await api.request(options.background ? "/question-operations" : "/questions", {
|
|
1266
1283
|
method: "POST",
|
|
1267
1284
|
headers: {
|
|
1268
1285
|
"idempotency-key": idempotencyKey(options),
|
|
@@ -1280,7 +1297,7 @@ async function ask(options, positionals) {
|
|
|
1280
1297
|
skills_extraction_mode: skillsExtractionMode,
|
|
1281
1298
|
context,
|
|
1282
1299
|
},
|
|
1283
|
-
timeoutMs: 330_000,
|
|
1300
|
+
timeoutMs: options.background ? 30_000 : 330_000,
|
|
1284
1301
|
});
|
|
1285
1302
|
} catch (error) {
|
|
1286
1303
|
if (attachedAssets.length > 0) {
|
|
@@ -1300,18 +1317,31 @@ async function ask(options, positionals) {
|
|
|
1300
1317
|
throw error;
|
|
1301
1318
|
}
|
|
1302
1319
|
const conversationId = String(result?.conversation_id || result?.data?.conversation_id || "").trim();
|
|
1320
|
+
let localContinuity = null;
|
|
1303
1321
|
if (conversationId && execution.selection?.workspaceId) {
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1322
|
+
try {
|
|
1323
|
+
await storeConversationRoutingReceipt({
|
|
1324
|
+
conversationId,
|
|
1325
|
+
workspaceId: execution.selection.workspaceId,
|
|
1326
|
+
agentId: execution.credential?.metadata?.agent_id || null,
|
|
1327
|
+
apiBase: baseUrl(options),
|
|
1328
|
+
});
|
|
1329
|
+
} catch (error) {
|
|
1330
|
+
if (!isReadOnlyLocalStateError(error)) throw error;
|
|
1331
|
+
localContinuity = {
|
|
1332
|
+
status: "not_persisted",
|
|
1333
|
+
reason: "local_config_read_only",
|
|
1334
|
+
error_code: String(error.code || "").toUpperCase(),
|
|
1335
|
+
conversation_id: conversationId,
|
|
1336
|
+
workspace_id: execution.selection.workspaceId,
|
|
1337
|
+
};
|
|
1338
|
+
}
|
|
1310
1339
|
}
|
|
1311
1340
|
writeResult(
|
|
1312
1341
|
{
|
|
1313
1342
|
...result,
|
|
1314
1343
|
...(attachedAssets.length > 0 ? { attached_assets: attachedAssets } : {}),
|
|
1344
|
+
...(localContinuity ? { local_continuity: localContinuity } : {}),
|
|
1315
1345
|
routing: execution.routing,
|
|
1316
1346
|
},
|
|
1317
1347
|
{ json: options.json },
|
|
@@ -2927,12 +2957,114 @@ function pageQuery(options) {
|
|
|
2927
2957
|
|
|
2928
2958
|
async function questions(options, action, id) {
|
|
2929
2959
|
const { api } = await executionClient(options, { continuityId: options["conversation-id"] || null });
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2960
|
+
let result;
|
|
2961
|
+
if (action === "list") {
|
|
2962
|
+
result = await api.request("/questions", { query: pageQuery(options) });
|
|
2963
|
+
} else if (action === "get") {
|
|
2964
|
+
result = await api.request(`/questions/${resourcePath(id || option(options, "id", { required: true }))}`);
|
|
2965
|
+
} else if (action === "operation") {
|
|
2966
|
+
const operationId = id || option(options, "id", { required: true });
|
|
2967
|
+
const afterCursor = numberOption(options, "after-cursor", 0, { minimum: 0 });
|
|
2968
|
+
const timeoutSeconds = questionOperationWaitTimeoutSeconds(options);
|
|
2969
|
+
result = timeoutSeconds === null
|
|
2970
|
+
? await api.request(`/question-operations/${resourcePath(operationId)}`, {
|
|
2971
|
+
query: { after_cursor: afterCursor },
|
|
2972
|
+
})
|
|
2973
|
+
: await waitForQuestionOperation(api, operationId, {
|
|
2974
|
+
afterCursor,
|
|
2975
|
+
timeoutSeconds,
|
|
2976
|
+
});
|
|
2977
|
+
} else if (action === "cancel") {
|
|
2978
|
+
const operationId = id || option(options, "id", { required: true });
|
|
2979
|
+
requireConfirmation(options, `Cancelling Question operation ${operationId}`);
|
|
2980
|
+
result = await api.request(`/question-operations/${resourcePath(operationId)}/cancel`, {
|
|
2981
|
+
method: "POST",
|
|
2982
|
+
retrySafe: true,
|
|
2983
|
+
});
|
|
2984
|
+
} else {
|
|
2985
|
+
throw new CliError("questions action must be list, get, operation, or cancel.");
|
|
2986
|
+
}
|
|
2933
2987
|
writeResult(result, { json: options.json });
|
|
2934
2988
|
}
|
|
2935
2989
|
|
|
2990
|
+
function questionOperationWaitTimeoutSeconds(options) {
|
|
2991
|
+
if (!options["wait-until-terminal"]) {
|
|
2992
|
+
if (options["timeout-seconds"] !== undefined) {
|
|
2993
|
+
throw new CliError("--timeout-seconds requires --wait-until-terminal.", {
|
|
2994
|
+
code: "question_operation_wait_required",
|
|
2995
|
+
});
|
|
2996
|
+
}
|
|
2997
|
+
return null;
|
|
2998
|
+
}
|
|
2999
|
+
return numberOption(
|
|
3000
|
+
options,
|
|
3001
|
+
"timeout-seconds",
|
|
3002
|
+
DEFAULT_FILE_OPERATION_WAIT_TIMEOUT_SECONDS,
|
|
3003
|
+
{ minimum: 1, maximum: MAX_FILE_OPERATION_WAIT_TIMEOUT_SECONDS },
|
|
3004
|
+
);
|
|
3005
|
+
}
|
|
3006
|
+
|
|
3007
|
+
function questionOperationIsPending(result) {
|
|
3008
|
+
return QUESTION_OPERATION_PENDING_STATUSES.has(String(result?.status || "").trim().toLowerCase());
|
|
3009
|
+
}
|
|
3010
|
+
|
|
3011
|
+
function questionOperationDeadlineReceipt(result, { timeoutSeconds, startedAtMs, operationReadCount }) {
|
|
3012
|
+
return {
|
|
3013
|
+
...result,
|
|
3014
|
+
transport_wait: {
|
|
3015
|
+
status: "deadline_reached",
|
|
3016
|
+
terminal: false,
|
|
3017
|
+
timeout_seconds: timeoutSeconds,
|
|
3018
|
+
elapsed_seconds: Math.max(0, Math.round((Date.now() - startedAtMs) / 1000)),
|
|
3019
|
+
operation_read_count: operationReadCount,
|
|
3020
|
+
continuation: "Run the same questions operation command with --wait-until-terminal; do not start a replacement Question.",
|
|
3021
|
+
},
|
|
3022
|
+
};
|
|
3023
|
+
}
|
|
3024
|
+
|
|
3025
|
+
async function waitForQuestionOperation(api, operationId, { afterCursor, timeoutSeconds }) {
|
|
3026
|
+
const startedAtMs = Date.now();
|
|
3027
|
+
const deadlineAtMs = startedAtMs + timeoutSeconds * 1000;
|
|
3028
|
+
let cursor = Math.max(0, Number(afterCursor) || 0);
|
|
3029
|
+
let result = null;
|
|
3030
|
+
let operationReadCount = 0;
|
|
3031
|
+
while (true) {
|
|
3032
|
+
const remainingMs = deadlineAtMs - Date.now();
|
|
3033
|
+
if (remainingMs <= 0 && result) {
|
|
3034
|
+
return questionOperationDeadlineReceipt(result, {
|
|
3035
|
+
timeoutSeconds,
|
|
3036
|
+
startedAtMs,
|
|
3037
|
+
operationReadCount,
|
|
3038
|
+
});
|
|
3039
|
+
}
|
|
3040
|
+
result = await api.request(`/question-operations/${resourcePath(operationId)}`, {
|
|
3041
|
+
query: {
|
|
3042
|
+
after_cursor: cursor,
|
|
3043
|
+
wait_seconds: Math.max(0, Math.min(30, Math.ceil(remainingMs / 1000))),
|
|
3044
|
+
},
|
|
3045
|
+
timeoutMs: Math.max(35_000, Math.min(remainingMs + 5_000, 40_000)),
|
|
3046
|
+
});
|
|
3047
|
+
operationReadCount += 1;
|
|
3048
|
+
if (Number.isFinite(Number(result.progress_cursor))) {
|
|
3049
|
+
cursor = Math.max(cursor, Number(result.progress_cursor));
|
|
3050
|
+
}
|
|
3051
|
+
if (!questionOperationIsPending(result)) return result;
|
|
3052
|
+
const nextRemainingMs = deadlineAtMs - Date.now();
|
|
3053
|
+
if (nextRemainingMs <= 0) {
|
|
3054
|
+
return questionOperationDeadlineReceipt(result, {
|
|
3055
|
+
timeoutSeconds,
|
|
3056
|
+
startedAtMs,
|
|
3057
|
+
operationReadCount,
|
|
3058
|
+
});
|
|
3059
|
+
}
|
|
3060
|
+
const retryAfterSeconds = Number(result.retry_after_seconds);
|
|
3061
|
+
const requestedDelayMs = Number.isFinite(retryAfterSeconds) && retryAfterSeconds >= 0
|
|
3062
|
+
? retryAfterSeconds * 1000
|
|
3063
|
+
: 5_000;
|
|
3064
|
+
await sleep(Math.min(nextRemainingMs, Math.max(50, Math.min(30_000, requestedDelayMs))));
|
|
3065
|
+
}
|
|
3066
|
+
}
|
|
3067
|
+
|
|
2936
3068
|
async function conversations(options, action, id) {
|
|
2937
3069
|
const conversationId = action === "get" ? id || options.id || null : null;
|
|
2938
3070
|
const { api } = await executionClient(options, { continuityId: conversationId });
|
package/dist/core.js
CHANGED