@fro.bot/space-bus 0.13.1 → 0.15.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/README.md +5 -1
- package/dist/attach.js +12 -2
- package/dist/cli.js +28 -15
- package/dist/config.d.ts +9 -4
- package/dist/config.js +27 -11
- package/dist/contract.d.ts +16 -0
- package/dist/contract.js +12 -2
- package/dist/core.d.ts +116 -1
- package/dist/core.js +326 -42
- package/dist/format.d.ts +1 -0
- package/dist/format.js +9 -1
- package/dist/index.js +162 -51
- package/dist/mcp.js +166 -53
- package/dist/registry-entry.js +27 -11
- package/dist/server.js +27 -11
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -138,7 +138,11 @@ Semantics:
|
|
|
138
138
|
|
|
139
139
|
Experimental subpath exports expose the bus's internals directly — the functions the four tools run on, plus the managed-server lifecycle and the attach resolver — for renderers and other consumers that want structured state instead of formatted strings. Subpaths are experimental: shapes may change in minor releases; pin the version if you adopt them.
|
|
140
140
|
|
|
141
|
-
- `@fro.bot/space-bus/core` — browser-safe; no Node builtins, no ambient env reads. Every exported function takes a `context: BusContext` (`{ roster, credentials? }`) that you build yourself and pass in — core never resolves it for you. Includes `snapshot()`, a one-call composite of roster + per-project status + pending questions with bounded fan-out.
|
|
141
|
+
- `@fro.bot/space-bus/core` — browser-safe; no Node builtins, no ambient env reads. Every exported function takes a `context: BusContext` (`{ roster, credentials? }`) that you build yourself and pass in — core never resolves it for you. Includes `snapshot()`, a one-call composite of roster + per-project status + pending questions with bounded fan-out. Session-content primitives:
|
|
142
|
+
- `messages(sessionId, { context, limit? })` — bounded full-message read. Resolves session ownership from the roster (never a caller-supplied directory), fetches `GET /session/:id/message?limit=N` (default 20, hard maximum 200 — `limit` must be a finite positive integer at or under the maximum; `0`, negative, fractional, `NaN`, `Infinity`, and over-maximum values are rejected before any fetch). Returns `{ sessionId, project, messages: [{ id?, role, createdAt?, parts: [{ type, text? }] }] }` in the order the server returns them — `id`/`createdAt` are the message's stable identity/ordering metadata (from the envelope's `info.id`/`info.time.created`), and only those explicit fields plus parsed `parts` cross the boundary; unknown envelope fields are dropped. No directory/credential fields in the result.
|
|
143
|
+
- `questions(target, { context })` — complete project- or session-scoped pending-question read. `target` is `{ project }` or `{ sessionId }` — exactly one; both-present or neither-present is rejected before any fetch. Returns `{ questions: [{ requestId, sessionId, questions: [{ header?, question, multiple, custom, options: [{ label, description? }] }] }] }` — one entry per `/question` request, each carrying its **full nested subquestion list** (a single request can ask multiple subquestions), not just the first one.
|
|
144
|
+
- `answerQuestion({ sessionId, requestId, answers }, { context })` — explicit question answer. Runtime-validates `answers` is a non-empty `string[][]` (rejects non-arrays, non-array rows, and non-string cells) before any fetch; verifies `requestId` actually belongs to a pending question on `sessionId` (fetched fresh from `GET /question`, parsed with the full pending-question schema) before sending the reply — a `requestId` for a different session is refused with no mutation; and verifies `answers.length` equals that request's subquestion count before sending — mismatched cardinality is refused with no mutation. Sends the complete `string[][]` `answers` payload to `POST /question/:requestId/reply`. `requestId` must be the question's own id (`que_...`), never an SSE envelope id (`evt_...`).
|
|
145
|
+
- `dispatch(args, opts)` gained an optional `args.onPendingQuestion: "question-reply" | "blocked"` (default `"question-reply"`, backward-compatible with 0.13.1); `toDispatchArgs` validates and preserves this field, rejecting any other value. Steering a session that has a pending question with `onPendingQuestion: "blocked"` returns `{ ok: true, mode: "blocked", sessionId, project, requestId }` and sends **neither** a question reply **nor** a follow-up prompt — for callers (like `ide_dispatch_prompt`) that must never silently reinterpret prompt text as a question answer. `"blocked"` is fail-closed: if `GET /question` returns a non-2xx status or an unparseable body, the pending-question state is unknown and the call returns a stable `Result` error instead of falling through to any mutation. The default `"question-reply"` policy (omitted, or passed explicitly) preserves the original fail-open v0.13.1 behavior unchanged, including on an unreadable `/question` response (falls through to a normal follow-up prompt).
|
|
142
146
|
- `@fro.bot/space-bus/config` — Node-only. `loadContext(directory?)` reads `spacebus.json` (honoring `SPACE_BUS_CONFIG` the same as the plugin) and returns a ready-to-use `BusContext`, with per-project `exists` flags and env-derived credentials attached. Build a fresh context per call; it's per-call/short-lived by contract, not meant to be cached across filesystem changes. `loadContextForRoster(name)` resolves a registered roster name instead (via `registry.resolveRosterByName`) through the same read/attach/credentials pipeline, returning the canonical registered name alongside the context and path. `loadContextForRosterPath(path)` — experimental, like its siblings — loads a `BusContext` from an *already-resolved* roster path, skipping name resolution entirely; callers that resolve a name once (to decide whether to `ensureServer()`) use this to avoid a second, TOCTOU-prone re-resolution of the same name.
|
|
143
147
|
- `@fro.bot/space-bus/contract` — the zod schemas (and inferred types) behind the OpenCode API and `BusContext`, for consumers hitting the server directly and wanting the same shapes. Schemas are zod v4.
|
|
144
148
|
- `@fro.bot/space-bus/format` — the pure formatters the tools use to render output, for tool-identical text.
|
package/dist/attach.js
CHANGED
|
@@ -63,7 +63,11 @@ var messagePartSchema = z.looseObject({
|
|
|
63
63
|
text: z.string().optional()
|
|
64
64
|
});
|
|
65
65
|
var messageEnvelopeSchema = z.looseObject({
|
|
66
|
-
info: z.looseObject({
|
|
66
|
+
info: z.looseObject({
|
|
67
|
+
id: z.string().optional(),
|
|
68
|
+
role: z.string(),
|
|
69
|
+
time: z.looseObject({ created: z.number().optional() }).optional()
|
|
70
|
+
}),
|
|
67
71
|
parts: z.array(messagePartSchema)
|
|
68
72
|
});
|
|
69
73
|
var messageListSchema = z.array(messageEnvelopeSchema);
|
|
@@ -72,7 +76,13 @@ var pendingQuestionEntrySchema = z.looseObject({
|
|
|
72
76
|
sessionID: z.string(),
|
|
73
77
|
questions: z.array(z.looseObject({
|
|
74
78
|
question: z.string().optional(),
|
|
75
|
-
|
|
79
|
+
header: z.string().optional(),
|
|
80
|
+
multiple: z.boolean().optional(),
|
|
81
|
+
custom: z.boolean().optional(),
|
|
82
|
+
options: z.array(z.looseObject({
|
|
83
|
+
label: z.string().optional(),
|
|
84
|
+
description: z.string().optional()
|
|
85
|
+
})).optional()
|
|
76
86
|
})).optional()
|
|
77
87
|
});
|
|
78
88
|
var pendingQuestionListSchema = z.array(pendingQuestionEntrySchema);
|
package/dist/cli.js
CHANGED
|
@@ -73,7 +73,11 @@ var messagePartSchema = z.looseObject({
|
|
|
73
73
|
text: z.string().optional()
|
|
74
74
|
});
|
|
75
75
|
var messageEnvelopeSchema = z.looseObject({
|
|
76
|
-
info: z.looseObject({
|
|
76
|
+
info: z.looseObject({
|
|
77
|
+
id: z.string().optional(),
|
|
78
|
+
role: z.string(),
|
|
79
|
+
time: z.looseObject({ created: z.number().optional() }).optional()
|
|
80
|
+
}),
|
|
77
81
|
parts: z.array(messagePartSchema)
|
|
78
82
|
});
|
|
79
83
|
var messageListSchema = z.array(messageEnvelopeSchema);
|
|
@@ -82,7 +86,13 @@ var pendingQuestionEntrySchema = z.looseObject({
|
|
|
82
86
|
sessionID: z.string(),
|
|
83
87
|
questions: z.array(z.looseObject({
|
|
84
88
|
question: z.string().optional(),
|
|
85
|
-
|
|
89
|
+
header: z.string().optional(),
|
|
90
|
+
multiple: z.boolean().optional(),
|
|
91
|
+
custom: z.boolean().optional(),
|
|
92
|
+
options: z.array(z.looseObject({
|
|
93
|
+
label: z.string().optional(),
|
|
94
|
+
description: z.string().optional()
|
|
95
|
+
})).optional()
|
|
86
96
|
})).optional()
|
|
87
97
|
});
|
|
88
98
|
var pendingQuestionListSchema = z.array(pendingQuestionEntrySchema);
|
|
@@ -843,17 +853,23 @@ var manifestSchema = z3.object({
|
|
|
843
853
|
function expandHome(path) {
|
|
844
854
|
return path.startsWith("~") ? join3(homedir3(), path.slice(1)) : path;
|
|
845
855
|
}
|
|
846
|
-
function
|
|
856
|
+
function resolveExplicitOverride(override, sourceLabel) {
|
|
857
|
+
if (override.includes("://")) {
|
|
858
|
+
throw new Error(`space-bus: ${sourceLabel} must be an absolute path or start with ~ (got a URL: ${override})`);
|
|
859
|
+
}
|
|
860
|
+
const expanded = expandHome(override);
|
|
861
|
+
if (!expanded.startsWith("/")) {
|
|
862
|
+
throw new Error(`space-bus: ${sourceLabel} must be an absolute path or start with ~ (got: ${override})`);
|
|
863
|
+
}
|
|
864
|
+
return existsSync(expanded) ? realpathSync2(expanded) : expanded;
|
|
865
|
+
}
|
|
866
|
+
function resolveRosterPath(directory, explicitOverride) {
|
|
867
|
+
if (explicitOverride) {
|
|
868
|
+
return resolveExplicitOverride(explicitOverride, "--config");
|
|
869
|
+
}
|
|
847
870
|
const override = process.env["SPACE_BUS_CONFIG"];
|
|
848
871
|
if (override) {
|
|
849
|
-
|
|
850
|
-
throw new Error(`space-bus: SPACE_BUS_CONFIG must be an absolute path or start with ~ (got a URL: ${override})`);
|
|
851
|
-
}
|
|
852
|
-
const expanded = expandHome(override);
|
|
853
|
-
if (!expanded.startsWith("/")) {
|
|
854
|
-
throw new Error(`space-bus: SPACE_BUS_CONFIG must be an absolute path or start with ~ (got: ${override})`);
|
|
855
|
-
}
|
|
856
|
-
return existsSync(expanded) ? realpathSync2(expanded) : expanded;
|
|
872
|
+
return resolveExplicitOverride(override, "SPACE_BUS_CONFIG");
|
|
857
873
|
}
|
|
858
874
|
if (directory) {
|
|
859
875
|
const candidate = join3(directory, "spacebus.json");
|
|
@@ -2141,10 +2157,7 @@ function consumeArg(argv, i, result) {
|
|
|
2141
2157
|
return i;
|
|
2142
2158
|
}
|
|
2143
2159
|
function resolveRoster(config) {
|
|
2144
|
-
|
|
2145
|
-
process.env["SPACE_BUS_CONFIG"] = config;
|
|
2146
|
-
}
|
|
2147
|
-
return resolveRosterPath();
|
|
2160
|
+
return resolveRosterPath(undefined, config);
|
|
2148
2161
|
}
|
|
2149
2162
|
function printJson(json, data, plain) {
|
|
2150
2163
|
if (json) {
|
package/dist/config.d.ts
CHANGED
|
@@ -43,17 +43,22 @@ export declare function expandHome(path: string): string;
|
|
|
43
43
|
* Resolves the path to spacebus.json for a given workspace directory.
|
|
44
44
|
*
|
|
45
45
|
* Resolution order:
|
|
46
|
-
* 1.
|
|
46
|
+
* 1. `explicitOverride`, when passed (e.g. the CLI's `--config` flag) —
|
|
47
|
+
* validated with the same absolute-path/URL/~-expansion rules as
|
|
48
|
+
* SPACE_BUS_CONFIG below, but resolved directly without touching
|
|
49
|
+
* process.env. This lets callers thread an explicit override through
|
|
50
|
+
* a single call without a persistent global mutation.
|
|
51
|
+
* 2. SPACE_BUS_CONFIG env var (must be absolute or start with ~; URLs and
|
|
47
52
|
* bare-relative paths are rejected with an actionable error).
|
|
48
|
-
*
|
|
49
|
-
*
|
|
53
|
+
* 3. `<directory>/spacebus.json`.
|
|
54
|
+
* 4. Throws, naming both mechanisms.
|
|
50
55
|
*
|
|
51
56
|
* Exact-path discovery only — no upward directory walk. When the resolved
|
|
52
57
|
* file exists, the path is canonicalized with realpathSync; when it's
|
|
53
58
|
* missing, the un-canonicalized (but expanded/joined) path is used in the
|
|
54
59
|
* error message.
|
|
55
60
|
*/
|
|
56
|
-
export declare function resolveRosterPath(directory?: string): string;
|
|
61
|
+
export declare function resolveRosterPath(directory?: string, explicitOverride?: string): string;
|
|
57
62
|
/**
|
|
58
63
|
* Reads, validates, and expands the roster manifest at an already-resolved
|
|
59
64
|
* path. Extracted from `getRoster` so both directory-based resolution and
|
package/dist/config.js
CHANGED
|
@@ -72,7 +72,11 @@ var messagePartSchema = z.looseObject({
|
|
|
72
72
|
text: z.string().optional()
|
|
73
73
|
});
|
|
74
74
|
var messageEnvelopeSchema = z.looseObject({
|
|
75
|
-
info: z.looseObject({
|
|
75
|
+
info: z.looseObject({
|
|
76
|
+
id: z.string().optional(),
|
|
77
|
+
role: z.string(),
|
|
78
|
+
time: z.looseObject({ created: z.number().optional() }).optional()
|
|
79
|
+
}),
|
|
76
80
|
parts: z.array(messagePartSchema)
|
|
77
81
|
});
|
|
78
82
|
var messageListSchema = z.array(messageEnvelopeSchema);
|
|
@@ -81,7 +85,13 @@ var pendingQuestionEntrySchema = z.looseObject({
|
|
|
81
85
|
sessionID: z.string(),
|
|
82
86
|
questions: z.array(z.looseObject({
|
|
83
87
|
question: z.string().optional(),
|
|
84
|
-
|
|
88
|
+
header: z.string().optional(),
|
|
89
|
+
multiple: z.boolean().optional(),
|
|
90
|
+
custom: z.boolean().optional(),
|
|
91
|
+
options: z.array(z.looseObject({
|
|
92
|
+
label: z.string().optional(),
|
|
93
|
+
description: z.string().optional()
|
|
94
|
+
})).optional()
|
|
85
95
|
})).optional()
|
|
86
96
|
});
|
|
87
97
|
var pendingQuestionListSchema = z.array(pendingQuestionEntrySchema);
|
|
@@ -842,17 +852,23 @@ var manifestSchema = z3.object({
|
|
|
842
852
|
function expandHome(path) {
|
|
843
853
|
return path.startsWith("~") ? join3(homedir3(), path.slice(1)) : path;
|
|
844
854
|
}
|
|
845
|
-
function
|
|
855
|
+
function resolveExplicitOverride(override, sourceLabel) {
|
|
856
|
+
if (override.includes("://")) {
|
|
857
|
+
throw new Error(`space-bus: ${sourceLabel} must be an absolute path or start with ~ (got a URL: ${override})`);
|
|
858
|
+
}
|
|
859
|
+
const expanded = expandHome(override);
|
|
860
|
+
if (!expanded.startsWith("/")) {
|
|
861
|
+
throw new Error(`space-bus: ${sourceLabel} must be an absolute path or start with ~ (got: ${override})`);
|
|
862
|
+
}
|
|
863
|
+
return existsSync(expanded) ? realpathSync2(expanded) : expanded;
|
|
864
|
+
}
|
|
865
|
+
function resolveRosterPath(directory, explicitOverride) {
|
|
866
|
+
if (explicitOverride) {
|
|
867
|
+
return resolveExplicitOverride(explicitOverride, "--config");
|
|
868
|
+
}
|
|
846
869
|
const override = process.env["SPACE_BUS_CONFIG"];
|
|
847
870
|
if (override) {
|
|
848
|
-
|
|
849
|
-
throw new Error(`space-bus: SPACE_BUS_CONFIG must be an absolute path or start with ~ (got a URL: ${override})`);
|
|
850
|
-
}
|
|
851
|
-
const expanded = expandHome(override);
|
|
852
|
-
if (!expanded.startsWith("/")) {
|
|
853
|
-
throw new Error(`space-bus: SPACE_BUS_CONFIG must be an absolute path or start with ~ (got: ${override})`);
|
|
854
|
-
}
|
|
855
|
-
return existsSync(expanded) ? realpathSync2(expanded) : expanded;
|
|
871
|
+
return resolveExplicitOverride(override, "SPACE_BUS_CONFIG");
|
|
856
872
|
}
|
|
857
873
|
if (directory) {
|
|
858
874
|
const candidate = join3(directory, "spacebus.json");
|
package/dist/contract.d.ts
CHANGED
|
@@ -133,7 +133,11 @@ export declare const messagePartSchema: z.ZodObject<{
|
|
|
133
133
|
export type MessagePartSchema = z.infer<typeof messagePartSchema>;
|
|
134
134
|
export declare const messageEnvelopeSchema: z.ZodObject<{
|
|
135
135
|
info: z.ZodObject<{
|
|
136
|
+
id: z.ZodOptional<z.ZodString>;
|
|
136
137
|
role: z.ZodString;
|
|
138
|
+
time: z.ZodOptional<z.ZodObject<{
|
|
139
|
+
created: z.ZodOptional<z.ZodNumber>;
|
|
140
|
+
}, z.core.$loose>>;
|
|
137
141
|
}, z.core.$loose>;
|
|
138
142
|
parts: z.ZodArray<z.ZodObject<{
|
|
139
143
|
type: z.ZodString;
|
|
@@ -143,7 +147,11 @@ export declare const messageEnvelopeSchema: z.ZodObject<{
|
|
|
143
147
|
export type MessageEnvelopeSchema = z.infer<typeof messageEnvelopeSchema>;
|
|
144
148
|
export declare const messageListSchema: z.ZodArray<z.ZodObject<{
|
|
145
149
|
info: z.ZodObject<{
|
|
150
|
+
id: z.ZodOptional<z.ZodString>;
|
|
146
151
|
role: z.ZodString;
|
|
152
|
+
time: z.ZodOptional<z.ZodObject<{
|
|
153
|
+
created: z.ZodOptional<z.ZodNumber>;
|
|
154
|
+
}, z.core.$loose>>;
|
|
147
155
|
}, z.core.$loose>;
|
|
148
156
|
parts: z.ZodArray<z.ZodObject<{
|
|
149
157
|
type: z.ZodString;
|
|
@@ -156,8 +164,12 @@ export declare const pendingQuestionEntrySchema: z.ZodObject<{
|
|
|
156
164
|
sessionID: z.ZodString;
|
|
157
165
|
questions: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
158
166
|
question: z.ZodOptional<z.ZodString>;
|
|
167
|
+
header: z.ZodOptional<z.ZodString>;
|
|
168
|
+
multiple: z.ZodOptional<z.ZodBoolean>;
|
|
169
|
+
custom: z.ZodOptional<z.ZodBoolean>;
|
|
159
170
|
options: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
160
171
|
label: z.ZodOptional<z.ZodString>;
|
|
172
|
+
description: z.ZodOptional<z.ZodString>;
|
|
161
173
|
}, z.core.$loose>>>;
|
|
162
174
|
}, z.core.$loose>>>;
|
|
163
175
|
}, z.core.$loose>;
|
|
@@ -167,8 +179,12 @@ export declare const pendingQuestionListSchema: z.ZodArray<z.ZodObject<{
|
|
|
167
179
|
sessionID: z.ZodString;
|
|
168
180
|
questions: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
169
181
|
question: z.ZodOptional<z.ZodString>;
|
|
182
|
+
header: z.ZodOptional<z.ZodString>;
|
|
183
|
+
multiple: z.ZodOptional<z.ZodBoolean>;
|
|
184
|
+
custom: z.ZodOptional<z.ZodBoolean>;
|
|
170
185
|
options: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
171
186
|
label: z.ZodOptional<z.ZodString>;
|
|
187
|
+
description: z.ZodOptional<z.ZodString>;
|
|
172
188
|
}, z.core.$loose>>>;
|
|
173
189
|
}, z.core.$loose>>>;
|
|
174
190
|
}, z.core.$loose>>;
|
package/dist/contract.js
CHANGED
|
@@ -63,7 +63,11 @@ var messagePartSchema = z.looseObject({
|
|
|
63
63
|
text: z.string().optional()
|
|
64
64
|
});
|
|
65
65
|
var messageEnvelopeSchema = z.looseObject({
|
|
66
|
-
info: z.looseObject({
|
|
66
|
+
info: z.looseObject({
|
|
67
|
+
id: z.string().optional(),
|
|
68
|
+
role: z.string(),
|
|
69
|
+
time: z.looseObject({ created: z.number().optional() }).optional()
|
|
70
|
+
}),
|
|
67
71
|
parts: z.array(messagePartSchema)
|
|
68
72
|
});
|
|
69
73
|
var messageListSchema = z.array(messageEnvelopeSchema);
|
|
@@ -72,7 +76,13 @@ var pendingQuestionEntrySchema = z.looseObject({
|
|
|
72
76
|
sessionID: z.string(),
|
|
73
77
|
questions: z.array(z.looseObject({
|
|
74
78
|
question: z.string().optional(),
|
|
75
|
-
|
|
79
|
+
header: z.string().optional(),
|
|
80
|
+
multiple: z.boolean().optional(),
|
|
81
|
+
custom: z.boolean().optional(),
|
|
82
|
+
options: z.array(z.looseObject({
|
|
83
|
+
label: z.string().optional(),
|
|
84
|
+
description: z.string().optional()
|
|
85
|
+
})).optional()
|
|
76
86
|
})).optional()
|
|
77
87
|
});
|
|
78
88
|
var pendingQuestionListSchema = z.array(pendingQuestionEntrySchema);
|
package/dist/core.d.ts
CHANGED
|
@@ -3,9 +3,25 @@ export type { SessionState, SessionStateInfo } from "./contract";
|
|
|
3
3
|
type Ok<T> = {
|
|
4
4
|
ok: true;
|
|
5
5
|
} & T;
|
|
6
|
+
/**
|
|
7
|
+
* Typed partial-failure handle for dispatch() call sites only — omitted
|
|
8
|
+
* entirely on every other core function's errors. "indeterminate" means the
|
|
9
|
+
* failed request may already have mutated OpenCode state (a create/prompt/
|
|
10
|
+
* reply POST that failed, was lost, or returned an unparseable body after
|
|
11
|
+
* the mutating call was made); "not_sent" means the failure is definitely
|
|
12
|
+
* pre-mutation (target resolution, pending-question verification). Fields
|
|
13
|
+
* are included only when known — never present-but-undefined.
|
|
14
|
+
*/
|
|
15
|
+
export type DispatchFailure = {
|
|
16
|
+
phase: "not_sent" | "indeterminate";
|
|
17
|
+
project: string;
|
|
18
|
+
sessionId?: string;
|
|
19
|
+
messageId?: string;
|
|
20
|
+
};
|
|
6
21
|
type Err = {
|
|
7
22
|
ok: false;
|
|
8
23
|
error: string;
|
|
24
|
+
dispatchFailure?: DispatchFailure;
|
|
9
25
|
};
|
|
10
26
|
export type Result<T> = Ok<T> | Err;
|
|
11
27
|
/** Options every exported core function takes: a per-call BusContext. */
|
|
@@ -32,12 +48,43 @@ export type DispatchResult = {
|
|
|
32
48
|
} & ({
|
|
33
49
|
mode: "new";
|
|
34
50
|
directory: string;
|
|
51
|
+
messageId?: string;
|
|
52
|
+
} | {
|
|
53
|
+
mode: "follow-up";
|
|
54
|
+
messageId?: string;
|
|
35
55
|
} | {
|
|
36
|
-
mode: "question-reply"
|
|
56
|
+
mode: "question-reply";
|
|
57
|
+
} | {
|
|
58
|
+
mode: "blocked";
|
|
59
|
+
requestId: string;
|
|
37
60
|
});
|
|
61
|
+
/**
|
|
62
|
+
* Generates an OpenCode v1 user-message id (`msg_` + a 12-char lowercase-hex
|
|
63
|
+
* ascending timestamp/counter prefix + 14 random base62 chars) using only
|
|
64
|
+
* Web Crypto / global browser-safe APIs — no Node builtins — so it's usable
|
|
65
|
+
* from the browser-safe `/core` subpath.
|
|
66
|
+
*/
|
|
67
|
+
export declare function createDispatchMessageId(): string;
|
|
38
68
|
export type DispatchArgs = {
|
|
39
69
|
prompt: string;
|
|
40
70
|
title?: string;
|
|
71
|
+
/**
|
|
72
|
+
* Backward-compatible pending-question policy for the steering path.
|
|
73
|
+
* Defaults to v0.13.1's implicit "question-reply" behavior (a follow-up
|
|
74
|
+
* to a session with a pending question is sent as that question's
|
|
75
|
+
* reply). Passing "blocked" instead refuses the mutation entirely and
|
|
76
|
+
* returns a typed blocked result with no reply and no follow-up prompt —
|
|
77
|
+
* required by ide_dispatch_prompt (R2), which must never silently
|
|
78
|
+
* reinterpret prompt text as a question answer.
|
|
79
|
+
*/
|
|
80
|
+
onPendingQuestion?: "question-reply" | "blocked";
|
|
81
|
+
/**
|
|
82
|
+
* Caller-supplied OpenCode v1 user message id to correlate the dispatched
|
|
83
|
+
* prompt with the message OpenCode creates for it. Validated by
|
|
84
|
+
* toDispatchArgs against the msg_ + alphanumeric shape; never generated
|
|
85
|
+
* here — generation is the caller's job via createDispatchMessageId().
|
|
86
|
+
*/
|
|
87
|
+
messageId?: string;
|
|
41
88
|
} & ({
|
|
42
89
|
project: string;
|
|
43
90
|
sessionId?: undefined;
|
|
@@ -50,6 +97,8 @@ export declare function toDispatchArgs(input: {
|
|
|
50
97
|
title?: string;
|
|
51
98
|
project?: string;
|
|
52
99
|
sessionId?: string;
|
|
100
|
+
onPendingQuestion?: "question-reply" | "blocked";
|
|
101
|
+
messageId?: string;
|
|
53
102
|
}): Result<DispatchArgs>;
|
|
54
103
|
export declare function dispatch(args: DispatchArgs, opts: CoreOpts): Promise<Result<DispatchResult>>;
|
|
55
104
|
export type SessionStatusResult = {
|
|
@@ -148,3 +197,69 @@ export declare function wait(sessionIds: string[], opts: CoreOpts & {
|
|
|
148
197
|
timeoutMs?: number;
|
|
149
198
|
pollIntervalMs?: number;
|
|
150
199
|
}): Promise<Result<WaitResult>>;
|
|
200
|
+
export type MessageOpts = CoreOpts & {
|
|
201
|
+
limit?: number;
|
|
202
|
+
};
|
|
203
|
+
export type SessionMessage = {
|
|
204
|
+
id?: string;
|
|
205
|
+
role: string;
|
|
206
|
+
createdAt?: number;
|
|
207
|
+
parts: {
|
|
208
|
+
type: string;
|
|
209
|
+
text?: string;
|
|
210
|
+
}[];
|
|
211
|
+
};
|
|
212
|
+
export type MessagesResult = {
|
|
213
|
+
sessionId: string;
|
|
214
|
+
project: string;
|
|
215
|
+
messages: SessionMessage[];
|
|
216
|
+
};
|
|
217
|
+
export declare function messages(sessionId: string, opts: MessageOpts): Promise<Result<MessagesResult>>;
|
|
218
|
+
export type QuestionTarget = {
|
|
219
|
+
project: string;
|
|
220
|
+
sessionId?: undefined;
|
|
221
|
+
} | {
|
|
222
|
+
sessionId: string;
|
|
223
|
+
project?: undefined;
|
|
224
|
+
};
|
|
225
|
+
/** One subquestion within a pending-question request — a single request
|
|
226
|
+
* (`requestId`) can carry multiple subquestions, each with its own
|
|
227
|
+
* selection rules and option set. Preserving the full nested list (not
|
|
228
|
+
* just the first subquestion) is required to round-trip a multi-question
|
|
229
|
+
* request through answerQuestion()'s cardinality check. */
|
|
230
|
+
export type PendingSubquestion = {
|
|
231
|
+
header?: string;
|
|
232
|
+
question: string;
|
|
233
|
+
multiple: boolean;
|
|
234
|
+
custom: boolean;
|
|
235
|
+
options: {
|
|
236
|
+
label: string;
|
|
237
|
+
description?: string;
|
|
238
|
+
}[];
|
|
239
|
+
};
|
|
240
|
+
export type PendingQuestionView = {
|
|
241
|
+
requestId: string;
|
|
242
|
+
sessionId: string;
|
|
243
|
+
questions: PendingSubquestion[];
|
|
244
|
+
};
|
|
245
|
+
export type QuestionsResult = {
|
|
246
|
+
questions: PendingQuestionView[];
|
|
247
|
+
};
|
|
248
|
+
/**
|
|
249
|
+
* Complete project- or session-scoped pending-question read. Resolves the
|
|
250
|
+
* target to a manifest project (or a roster-owned session's project)
|
|
251
|
+
* before fetching /question, then returns the full current contract
|
|
252
|
+
* (requestID, sessionID, header/question text, selection rules, and
|
|
253
|
+
* option labels/descriptions) with no directory/credential fields.
|
|
254
|
+
*/
|
|
255
|
+
export declare function questions(target: QuestionTarget, opts: CoreOpts): Promise<Result<QuestionsResult>>;
|
|
256
|
+
export type AnswerQuestionArgs = {
|
|
257
|
+
sessionId: string;
|
|
258
|
+
requestId: string;
|
|
259
|
+
answers: string[][];
|
|
260
|
+
};
|
|
261
|
+
export type AnswerQuestionResult = {
|
|
262
|
+
sessionId: string;
|
|
263
|
+
requestId: string;
|
|
264
|
+
};
|
|
265
|
+
export declare function answerQuestion(args: AnswerQuestionArgs, opts: CoreOpts): Promise<Result<AnswerQuestionResult>>;
|