@bobannomi/client 0.1.1 → 0.3.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 +44 -27
- package/dist/index.d.ts +2083 -534
- package/dist/index.js +2420 -1352
- package/dist/index.js.map +3 -3
- package/dist/service.js +2330 -689
- package/dist/service.js.map +3 -3
- package/package.json +4 -3
package/dist/service.js
CHANGED
|
@@ -1686,97 +1686,138 @@ function assertUnifiedDataRoot(paths, env = process.env) {
|
|
|
1686
1686
|
|
|
1687
1687
|
// src/resources/schedule-resource.ts
|
|
1688
1688
|
var ScheduleResource = class {
|
|
1689
|
+
#transport;
|
|
1689
1690
|
constructor(transport) {
|
|
1690
|
-
this
|
|
1691
|
-
}
|
|
1692
|
-
|
|
1691
|
+
this.#transport = transport;
|
|
1692
|
+
}
|
|
1693
|
+
tasks = {
|
|
1694
|
+
list: async (options = {}) => {
|
|
1695
|
+
const { signal, ...query } = options;
|
|
1696
|
+
const response = await this.#transport.request(
|
|
1697
|
+
this.#transport.path("/schedules/tasks", query),
|
|
1698
|
+
{ signal }
|
|
1699
|
+
);
|
|
1700
|
+
return response.tasks;
|
|
1701
|
+
},
|
|
1702
|
+
get: async (id2, options = {}) => {
|
|
1703
|
+
const response = await this.#transport.request(
|
|
1704
|
+
`/schedules/tasks/${encodeURIComponent(id2)}`,
|
|
1705
|
+
{ signal: options.signal }
|
|
1706
|
+
);
|
|
1707
|
+
return response.task;
|
|
1708
|
+
},
|
|
1709
|
+
create: async (input, options = {}) => {
|
|
1710
|
+
const response = await this.#transport.request(
|
|
1711
|
+
"/schedules/tasks",
|
|
1712
|
+
{
|
|
1713
|
+
method: "POST",
|
|
1714
|
+
body: input,
|
|
1715
|
+
signal: options.signal
|
|
1716
|
+
}
|
|
1717
|
+
);
|
|
1718
|
+
return response.task;
|
|
1719
|
+
},
|
|
1720
|
+
update: async (id2, input, options = {}) => {
|
|
1721
|
+
const response = await this.#transport.request(
|
|
1722
|
+
`/schedules/tasks/${encodeURIComponent(id2)}`,
|
|
1723
|
+
{ method: "PATCH", body: input, signal: options.signal }
|
|
1724
|
+
);
|
|
1725
|
+
return response.task;
|
|
1726
|
+
},
|
|
1727
|
+
remove: async (id2, options = {}) => {
|
|
1728
|
+
await this.#transport.request(
|
|
1729
|
+
`/schedules/tasks/${encodeURIComponent(id2)}`,
|
|
1730
|
+
{
|
|
1731
|
+
method: "DELETE",
|
|
1732
|
+
signal: options.signal
|
|
1733
|
+
}
|
|
1734
|
+
);
|
|
1735
|
+
},
|
|
1736
|
+
trigger: async (id2, options = {}) => {
|
|
1737
|
+
const response = await this.#transport.request(
|
|
1738
|
+
this.#transport.path(`/schedules/tasks/${encodeURIComponent(id2)}/run`, { requestId: options.requestId }),
|
|
1739
|
+
{ method: "POST", signal: options.signal }
|
|
1740
|
+
);
|
|
1741
|
+
return response.run;
|
|
1742
|
+
},
|
|
1743
|
+
/** Reads the exact manual request without starting work. A missing record does not authorize replay. */
|
|
1744
|
+
getTriggerResult: async (id2, requestId, options = {}) => {
|
|
1745
|
+
const response = await this.#transport.request(
|
|
1746
|
+
this.#transport.path(`/schedules/tasks/${encodeURIComponent(id2)}/run`, { requestId }),
|
|
1747
|
+
{ signal: options.signal }
|
|
1748
|
+
);
|
|
1749
|
+
return response.run;
|
|
1750
|
+
}
|
|
1751
|
+
};
|
|
1752
|
+
runs = {
|
|
1753
|
+
list: async (options = {}) => {
|
|
1754
|
+
const { signal, unread, ...query } = options;
|
|
1755
|
+
const response = await this.#transport.request(
|
|
1756
|
+
this.#transport.path("/schedules/runs", { ...query, unread: unread === void 0 ? void 0 : String(unread) }),
|
|
1757
|
+
{ signal }
|
|
1758
|
+
);
|
|
1759
|
+
return response.runs;
|
|
1760
|
+
},
|
|
1761
|
+
/** Reads one run belonging to this task, regardless of how it was triggered. */
|
|
1762
|
+
get: async (taskId, runId, options = {}) => {
|
|
1763
|
+
const response = await this.#transport.request(
|
|
1764
|
+
`/schedules/tasks/${encodeURIComponent(taskId)}/runs/${encodeURIComponent(runId)}`,
|
|
1765
|
+
{ signal: options.signal }
|
|
1766
|
+
);
|
|
1767
|
+
return response.run;
|
|
1768
|
+
},
|
|
1769
|
+
setUnread: async (id2, unread, options = {}) => {
|
|
1770
|
+
const response = await this.#transport.request(
|
|
1771
|
+
`/schedules/runs/${encodeURIComponent(id2)}/read`,
|
|
1772
|
+
{ method: "PATCH", body: { unread, ...options.taskId === void 0 ? {} : { taskId: options.taskId } }, signal: options.signal }
|
|
1773
|
+
);
|
|
1774
|
+
return response.run;
|
|
1775
|
+
}
|
|
1776
|
+
};
|
|
1693
1777
|
async getStatus(options = {}) {
|
|
1694
|
-
return await this
|
|
1778
|
+
return await this.#transport.request("/schedules/status", {
|
|
1695
1779
|
signal: options.signal
|
|
1696
1780
|
});
|
|
1697
1781
|
}
|
|
1698
|
-
async listTasks(options = {}) {
|
|
1699
|
-
const { signal, ...query } = options;
|
|
1700
|
-
const response = await this.transport.request(
|
|
1701
|
-
this.transport.path("/schedules/tasks", query),
|
|
1702
|
-
{ signal }
|
|
1703
|
-
);
|
|
1704
|
-
return response.tasks;
|
|
1705
|
-
}
|
|
1706
|
-
async getTask(id2, options = {}) {
|
|
1707
|
-
const response = await this.transport.request(
|
|
1708
|
-
`/schedules/tasks/${encodeURIComponent(id2)}`,
|
|
1709
|
-
{ signal: options.signal }
|
|
1710
|
-
);
|
|
1711
|
-
return response.task;
|
|
1712
|
-
}
|
|
1713
|
-
async createTask(input, options = {}) {
|
|
1714
|
-
const response = await this.transport.request(
|
|
1715
|
-
"/schedules/tasks",
|
|
1716
|
-
{
|
|
1717
|
-
method: "POST",
|
|
1718
|
-
body: input,
|
|
1719
|
-
signal: options.signal
|
|
1720
|
-
}
|
|
1721
|
-
);
|
|
1722
|
-
return response.task;
|
|
1723
|
-
}
|
|
1724
|
-
async updateTask(id2, input, options = {}) {
|
|
1725
|
-
const response = await this.transport.request(
|
|
1726
|
-
`/schedules/tasks/${encodeURIComponent(id2)}`,
|
|
1727
|
-
{ method: "PATCH", body: input, signal: options.signal }
|
|
1728
|
-
);
|
|
1729
|
-
return response.task;
|
|
1730
|
-
}
|
|
1731
|
-
async removeTask(id2, options = {}) {
|
|
1732
|
-
await this.transport.request(
|
|
1733
|
-
`/schedules/tasks/${encodeURIComponent(id2)}`,
|
|
1734
|
-
{
|
|
1735
|
-
method: "DELETE",
|
|
1736
|
-
signal: options.signal
|
|
1737
|
-
}
|
|
1738
|
-
);
|
|
1739
|
-
}
|
|
1740
|
-
async triggerTask(id2, options = {}) {
|
|
1741
|
-
const response = await this.transport.request(
|
|
1742
|
-
this.transport.path(`/schedules/tasks/${encodeURIComponent(id2)}/run`, { requestId: options.requestId }),
|
|
1743
|
-
{ method: "POST", signal: options.signal }
|
|
1744
|
-
);
|
|
1745
|
-
return response.run;
|
|
1746
|
-
}
|
|
1747
|
-
/** Reads the exact manual request without starting work. A missing record does not authorize replay. */
|
|
1748
|
-
async getTriggerTaskResult(id2, requestId, options = {}) {
|
|
1749
|
-
const response = await this.transport.request(
|
|
1750
|
-
this.transport.path(`/schedules/tasks/${encodeURIComponent(id2)}/run`, { requestId }),
|
|
1751
|
-
{ signal: options.signal }
|
|
1752
|
-
);
|
|
1753
|
-
return response.run;
|
|
1754
|
-
}
|
|
1755
|
-
async listRuns(options = {}) {
|
|
1756
|
-
const { signal, ...query } = options;
|
|
1757
|
-
const response = await this.transport.request(
|
|
1758
|
-
this.transport.path("/schedules/runs", query),
|
|
1759
|
-
{ signal }
|
|
1760
|
-
);
|
|
1761
|
-
return response.runs;
|
|
1762
|
-
}
|
|
1763
|
-
/** Reads one run belonging to this task, regardless of how it was triggered. */
|
|
1764
|
-
async getRun(taskId, runId, options = {}) {
|
|
1765
|
-
const response = await this.transport.request(
|
|
1766
|
-
`/schedules/tasks/${encodeURIComponent(taskId)}/runs/${encodeURIComponent(runId)}`,
|
|
1767
|
-
{ signal: options.signal }
|
|
1768
|
-
);
|
|
1769
|
-
return response.run;
|
|
1770
|
-
}
|
|
1771
|
-
async setRunUnread(id2, unread, options = {}) {
|
|
1772
|
-
const response = await this.transport.request(
|
|
1773
|
-
`/schedules/runs/${encodeURIComponent(id2)}/read`,
|
|
1774
|
-
{ method: "PATCH", body: { unread, ...options.taskId === void 0 ? {} : { taskId: options.taskId } }, signal: options.signal }
|
|
1775
|
-
);
|
|
1776
|
-
return response.run;
|
|
1777
|
-
}
|
|
1778
1782
|
};
|
|
1779
1783
|
|
|
1784
|
+
// ../domain-contracts/src/sessions/records.ts
|
|
1785
|
+
var SESSION_EVENT_SCHEMA_VERSION = 1;
|
|
1786
|
+
var SESSION_EVENT_SCHEMA_VERSIONS = {
|
|
1787
|
+
"session.input.admitted": 2
|
|
1788
|
+
};
|
|
1789
|
+
function sessionEventSchemaVersion(type) {
|
|
1790
|
+
return SESSION_EVENT_SCHEMA_VERSIONS[type] ?? SESSION_EVENT_SCHEMA_VERSION;
|
|
1791
|
+
}
|
|
1792
|
+
|
|
1793
|
+
// ../domain-contracts/src/sessions/model-metadata.ts
|
|
1794
|
+
function isRecordValue(value) {
|
|
1795
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1796
|
+
}
|
|
1797
|
+
function readNonEmptyString(value) {
|
|
1798
|
+
return typeof value === "string" && value.trim() ? value : void 0;
|
|
1799
|
+
}
|
|
1800
|
+
function readPositiveInteger(value) {
|
|
1801
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 1 ? value : void 0;
|
|
1802
|
+
}
|
|
1803
|
+
function readModelGenerationMetadata(metadata) {
|
|
1804
|
+
if (!isRecordValue(metadata)) return void 0;
|
|
1805
|
+
const raw = metadata.modelGeneration;
|
|
1806
|
+
if (!isRecordValue(raw)) return void 0;
|
|
1807
|
+
const generationId = readNonEmptyString(raw.generationId);
|
|
1808
|
+
const attempt = readPositiveInteger(raw.attempt);
|
|
1809
|
+
if (!generationId || attempt === void 0) return void 0;
|
|
1810
|
+
return {
|
|
1811
|
+
generationId,
|
|
1812
|
+
attempt,
|
|
1813
|
+
...raw.superseded === true ? { superseded: true } : {},
|
|
1814
|
+
...raw.committed === true ? { committed: true } : {}
|
|
1815
|
+
};
|
|
1816
|
+
}
|
|
1817
|
+
function isSupersededModelPart(part) {
|
|
1818
|
+
return readModelGenerationMetadata(part.metadata)?.superseded === true;
|
|
1819
|
+
}
|
|
1820
|
+
|
|
1780
1821
|
// ../domain-contracts/src/validation-error.ts
|
|
1781
1822
|
var DomainValidationError = class extends Error {
|
|
1782
1823
|
constructor(message, field, reason) {
|
|
@@ -1790,6 +1831,17 @@ var DomainValidationError = class extends Error {
|
|
|
1790
1831
|
code = "invalid_request";
|
|
1791
1832
|
};
|
|
1792
1833
|
|
|
1834
|
+
// ../domain-contracts/src/sessions/model-connection.ts
|
|
1835
|
+
function parseExpectedModelConnection(value) {
|
|
1836
|
+
const proof = value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
1837
|
+
const provider2 = proof?.provider;
|
|
1838
|
+
const fingerprint = proof?.fingerprint;
|
|
1839
|
+
if (!proof || Object.keys(proof).length !== 2 || !Object.hasOwn(proof, "provider") || !Object.hasOwn(proof, "fingerprint") || typeof provider2 !== "string" || !/^[a-z0-9][a-z0-9_-]{0,255}$/.test(provider2) || typeof fingerprint !== "string" || !/^[a-f0-9]{64}$/.test(fingerprint)) {
|
|
1840
|
+
throw new DomainValidationError("invalid_expected_model_connection", "expectedModelConnection");
|
|
1841
|
+
}
|
|
1842
|
+
return { provider: provider2, fingerprint };
|
|
1843
|
+
}
|
|
1844
|
+
|
|
1793
1845
|
// ../domain-contracts/src/sessions/resource-actions.ts
|
|
1794
1846
|
var record = (v) => !!v && typeof v === "object" && !Array.isArray(v) && [Object.prototype, null].includes(Object.getPrototypeOf(v));
|
|
1795
1847
|
var exact = (v, required, optional = []) => record(v) && required.every((k) => Object.hasOwn(v, k)) && Reflect.ownKeys(v).every((k) => {
|
|
@@ -1892,7 +1944,7 @@ function fields(body, allowed) {
|
|
|
1892
1944
|
// ../domain-contracts/src/sessions/configuration-validation.ts
|
|
1893
1945
|
function parseSessionConfiguration(value) {
|
|
1894
1946
|
const body = record2(value);
|
|
1895
|
-
fields(body, ["model", "roleId", "systemPrompt", "executionInstructions", "effort", "workMode", "maxTurns", "sessionMode", "replyStyle", "approvalMode", "tools", "pluginsEnabled", "pluginAutoSelectionEnabled", "activePluginId", "pluginIds", "
|
|
1947
|
+
fields(body, ["model", "roleId", "systemPrompt", "executionInstructions", "effort", "workMode", "maxTurns", "sessionMode", "replyStyle", "approvalMode", "tools", "pluginsEnabled", "pluginAutoSelectionEnabled", "activePluginId", "pluginIds", "memory"]);
|
|
1896
1948
|
for (const key of ["roleId", "systemPrompt", "effort", "activePluginId"]) if (body[key] !== null) optionalString(body, key);
|
|
1897
1949
|
for (const key of ["pluginsEnabled", "pluginAutoSelectionEnabled"]) optionalBoolean(body, key);
|
|
1898
1950
|
optionalEnum(body, "workMode", ["execute", "plan"]);
|
|
@@ -1900,7 +1952,7 @@ function parseSessionConfiguration(value) {
|
|
|
1900
1952
|
optionalEnum(body, "replyStyle", ["collaborative", "direct", "explanatory"]);
|
|
1901
1953
|
optionalEnum(body, "approvalMode", ["ask", "auto_review", "full_access"]);
|
|
1902
1954
|
optionalNumber(body, "maxTurns", { integer: true, minimum: 0 });
|
|
1903
|
-
|
|
1955
|
+
optionalStringArray(body, "pluginIds");
|
|
1904
1956
|
if (body.model !== void 0) {
|
|
1905
1957
|
const model = record2(body.model);
|
|
1906
1958
|
fields(model, ["provider", "model"]);
|
|
@@ -1944,7 +1996,7 @@ function assertPromptMetadataAllowed(input) {
|
|
|
1944
1996
|
const field = `${namespace}.outputSchema`;
|
|
1945
1997
|
throw new DomainValidationError(`${field} is a stored snapshot; use explicit outputSchema`, field);
|
|
1946
1998
|
}
|
|
1947
|
-
for (const name of ["pluginUi", "uiAction", "pluginUiSubmission", "pluginAppAction", "pluginAppSubmission", "pluginAppSource", "consumedForkHistory", "executionBinding", "steeredRunId", "steerTargetRunId", "appliedInputState", "appliedFollowUpInputIds", "unappliedFollowUpInputIds", "unappliedPromotion", "steerDeliveryFailed", "sessionObservationGrant", "sessionObservationAccess", "promotion", "cancellation", "interruption"]) {
|
|
1999
|
+
for (const name of ["pluginUi", "uiAction", "pluginUiSubmission", "pluginAppAction", "pluginAppSubmission", "pluginAppSource", "consumedForkHistory", "executionBinding", "steeredRunId", "steerTargetRunId", "appliedInputState", "appliedFollowUpInputIds", "unappliedFollowUpInputIds", "unappliedPromotion", "steerDeliveryFailed", "sessionObservationGrant", "sessionObservationAccess", "sessionLookupAllowed", "promotion", "cancellation", "interruption", "expectedModelConnection", "modelConnectionProofSupplied"]) {
|
|
1948
2000
|
if (Object.hasOwn(metadata, name)) {
|
|
1949
2001
|
const field = `${namespace}.${name}`;
|
|
1950
2002
|
throw new DomainValidationError(
|
|
@@ -2137,14 +2189,24 @@ function appMetadata(value) {
|
|
|
2137
2189
|
optionalRecord(metadata, "app");
|
|
2138
2190
|
return metadata;
|
|
2139
2191
|
}
|
|
2192
|
+
var reservedSessionIds = /* @__PURE__ */ new Set(["directory", "activity", "search", "configuration-options", ".", ".."]);
|
|
2193
|
+
function validateSessionId(id2) {
|
|
2194
|
+
if (!id2.trim() || reservedSessionIds.has(id2)) {
|
|
2195
|
+
throw new ProtocolValidationError("id must be nonempty and outside reserved session paths", "id");
|
|
2196
|
+
}
|
|
2197
|
+
return id2;
|
|
2198
|
+
}
|
|
2140
2199
|
function parseCreateSessionRequest(value) {
|
|
2141
2200
|
const body = record3(value);
|
|
2142
2201
|
fields2(body, ["id", "requestId", "cwd", "projectId", "title", "storage", "configuration", "optionsRevision", "metadata"]);
|
|
2143
|
-
const cwd =
|
|
2144
|
-
const id2 = requiredString2(body, "id");
|
|
2202
|
+
const cwd = optionalString2(body, "cwd");
|
|
2203
|
+
const id2 = validateSessionId(requiredString2(body, "id"));
|
|
2145
2204
|
const requestId = requiredString2(body, "requestId");
|
|
2146
|
-
if (
|
|
2147
|
-
|
|
2205
|
+
if (cwd !== void 0 && !cwd.trim()) throw new ProtocolValidationError("cwd cannot be empty", "cwd");
|
|
2206
|
+
if (!requestId.trim()) throw new ProtocolValidationError("requestId cannot be empty", "requestId");
|
|
2207
|
+
const target = cwd === void 0 ? { projectId: requiredString2(body, "projectId") } : { cwd };
|
|
2208
|
+
if (cwd === void 0 && !target.projectId?.trim()) throw new ProtocolValidationError("projectId cannot be empty", "projectId");
|
|
2209
|
+
const result = { id: id2, requestId, ...target };
|
|
2148
2210
|
for (const key of ["projectId", "title", "optionsRevision"]) if (body[key] !== void 0) result[key] = optionalString2(body, key);
|
|
2149
2211
|
if (body.storage !== void 0) result.storage = optionalEnum2(body, "storage", ["sqlite", "memory"]);
|
|
2150
2212
|
if (body.configuration !== void 0) result.configuration = parseSessionConfiguration2(body.configuration);
|
|
@@ -2153,6 +2215,7 @@ function parseCreateSessionRequest(value) {
|
|
|
2153
2215
|
}
|
|
2154
2216
|
function parseForkSessionRequest(value) {
|
|
2155
2217
|
const body = record3(value);
|
|
2218
|
+
const id2 = optionalString2(body, "id");
|
|
2156
2219
|
const beforeMessageId = optionalString2(body, "beforeMessageId");
|
|
2157
2220
|
const afterMessageId = optionalString2(body, "afterMessageId");
|
|
2158
2221
|
const storage = optionalEnum2(body, "storage", ["sqlite", "memory"]);
|
|
@@ -2164,7 +2227,7 @@ function parseForkSessionRequest(value) {
|
|
|
2164
2227
|
);
|
|
2165
2228
|
}
|
|
2166
2229
|
return {
|
|
2167
|
-
...
|
|
2230
|
+
...id2 === void 0 ? {} : { id: validateSessionId(id2) },
|
|
2168
2231
|
...body.requestId !== void 0 ? { requestId: optionalString2(body, "requestId") } : {},
|
|
2169
2232
|
...copyHistory !== void 0 ? { copyHistory } : {},
|
|
2170
2233
|
...beforeMessageId !== void 0 ? { beforeMessageId } : {},
|
|
@@ -2179,6 +2242,9 @@ function parseUpdateSessionRequest(value) {
|
|
|
2179
2242
|
const metadata = body.metadata === void 0 ? void 0 : appMetadata(optionalRecord(body, "metadata"));
|
|
2180
2243
|
return { ...title === void 0 ? {} : { title }, ...metadata === void 0 ? {} : { metadata } };
|
|
2181
2244
|
}
|
|
2245
|
+
function parseExpectedModelConnection2(value) {
|
|
2246
|
+
return adaptDomainInput(() => parseExpectedModelConnection(value));
|
|
2247
|
+
}
|
|
2182
2248
|
function adaptDomainInput(read) {
|
|
2183
2249
|
try {
|
|
2184
2250
|
return read();
|
|
@@ -2216,7 +2282,7 @@ function decodeSessionConfigurationSnapshot(value) {
|
|
|
2216
2282
|
} catch {
|
|
2217
2283
|
throw new ProtocolDataError("Invalid resolved configuration");
|
|
2218
2284
|
}
|
|
2219
|
-
const required = ["model", "roleId", "systemPrompt", "executionInstructions", "effort", "workMode", "maxTurns", "sessionMode", "replyStyle", "approvalMode", "tools", "pluginsEnabled", "pluginAutoSelectionEnabled", "activePluginId", "pluginIds", "
|
|
2285
|
+
const required = ["model", "roleId", "systemPrompt", "executionInstructions", "effort", "workMode", "maxTurns", "sessionMode", "replyStyle", "approvalMode", "tools", "pluginsEnabled", "pluginAutoSelectionEnabled", "activePluginId", "pluginIds", "memory"];
|
|
2220
2286
|
if (required.some((key) => !Object.hasOwn(configuration, key)) || !configuration.tools?.allowed || !configuration.tools.denied) throw new ProtocolDataError("Resolved configuration is incomplete");
|
|
2221
2287
|
return { revision: snapshot.revision, configuration, configurationRoot: { cwd, settingsRoot } };
|
|
2222
2288
|
}
|
|
@@ -2985,6 +3051,76 @@ function decodeSessionGoalRequestReceipt(value) {
|
|
|
2985
3051
|
return receipt2;
|
|
2986
3052
|
}
|
|
2987
3053
|
|
|
3054
|
+
// ../protocol/src/extensions/mcp-oauth.ts
|
|
3055
|
+
var MCP_OAUTH_LOGIN_UPDATED_EVENT = "mcp.oauth.login.updated";
|
|
3056
|
+
var MCP_OAUTH_LOGIN_COMPLETED_EVENT = "mcp.oauth.login.completed";
|
|
3057
|
+
var MAX_OAUTH_ID_LENGTH = 200;
|
|
3058
|
+
function parseOAuthOperationEvent(value) {
|
|
3059
|
+
const record4 = requiredRecord(value, "operation event");
|
|
3060
|
+
if (record4.event !== MCP_OAUTH_LOGIN_UPDATED_EVENT && record4.event !== MCP_OAUTH_LOGIN_COMPLETED_EVENT) {
|
|
3061
|
+
throw new Error("unknown MCP OAuth event name");
|
|
3062
|
+
}
|
|
3063
|
+
const data = requiredRecord(record4.data, "operation event data");
|
|
3064
|
+
const event = {
|
|
3065
|
+
event: record4.event,
|
|
3066
|
+
data: {
|
|
3067
|
+
loginId: boundedId(data.loginId, "loginId"),
|
|
3068
|
+
name: boundedId(data.name, "name"),
|
|
3069
|
+
state: operationState(data.state),
|
|
3070
|
+
credentialCommitted: requiredBoolean(data.credentialCommitted, "credentialCommitted"),
|
|
3071
|
+
authorizationReady: requiredBoolean(data.authorizationReady, "authorizationReady"),
|
|
3072
|
+
...data.errorCode !== void 0 ? { errorCode: boundedId(data.errorCode, "errorCode") } : {}
|
|
3073
|
+
}
|
|
3074
|
+
};
|
|
3075
|
+
if (data.runtimeSync !== void 0) {
|
|
3076
|
+
event.data.runtimeSync = parseRuntimeSync(data.runtimeSync);
|
|
3077
|
+
}
|
|
3078
|
+
return event;
|
|
3079
|
+
}
|
|
3080
|
+
function parseRuntimeSync(value) {
|
|
3081
|
+
const runtimeSync = requiredRecord(value, "runtimeSync");
|
|
3082
|
+
return {
|
|
3083
|
+
status: runtimeSyncStatus(runtimeSync.status),
|
|
3084
|
+
affectedRuntimes: nonNegativeInteger2(runtimeSync.affectedRuntimes, "affectedRuntimes"),
|
|
3085
|
+
failures: Array.isArray(runtimeSync.failures) ? runtimeSync.failures.map((failure) => {
|
|
3086
|
+
const item = requiredRecord(failure, "runtimeSync failure");
|
|
3087
|
+
return { runtimeId: boundedId(item.runtimeId, "runtimeId"), message: boundedId(item.message, "message") };
|
|
3088
|
+
}) : []
|
|
3089
|
+
};
|
|
3090
|
+
}
|
|
3091
|
+
function operationState(value) {
|
|
3092
|
+
if (value !== "pending" && value !== "completed" && value !== "failed" && value !== "cancelled") {
|
|
3093
|
+
throw new Error("invalid operation state");
|
|
3094
|
+
}
|
|
3095
|
+
return value;
|
|
3096
|
+
}
|
|
3097
|
+
function runtimeSyncStatus(value) {
|
|
3098
|
+
if (value !== "connected" && value !== "disconnected" && value !== "error" && value !== "unavailable") {
|
|
3099
|
+
throw new Error("invalid runtime status");
|
|
3100
|
+
}
|
|
3101
|
+
return value;
|
|
3102
|
+
}
|
|
3103
|
+
function boundedId(value, field) {
|
|
3104
|
+
if (typeof value !== "string" || value.length === 0 || value.length > MAX_OAUTH_ID_LENGTH) {
|
|
3105
|
+
throw new Error(`${field} must be a bounded non-empty string`);
|
|
3106
|
+
}
|
|
3107
|
+
return value;
|
|
3108
|
+
}
|
|
3109
|
+
function requiredBoolean(value, field) {
|
|
3110
|
+
if (typeof value !== "boolean") throw new Error(`${field} must be a boolean`);
|
|
3111
|
+
return value;
|
|
3112
|
+
}
|
|
3113
|
+
function nonNegativeInteger2(value, field) {
|
|
3114
|
+
if (!Number.isSafeInteger(value) || Number(value) < 0) throw new Error(`${field} must be a non-negative integer`);
|
|
3115
|
+
return Number(value);
|
|
3116
|
+
}
|
|
3117
|
+
function requiredRecord(value, field) {
|
|
3118
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
3119
|
+
throw new Error(`${field} must be an object`);
|
|
3120
|
+
}
|
|
3121
|
+
return value;
|
|
3122
|
+
}
|
|
3123
|
+
|
|
2988
3124
|
// ../protocol/src/runtime/execution-observability.ts
|
|
2989
3125
|
var EXECUTION_KINDS = [
|
|
2990
3126
|
"root_agent_run",
|
|
@@ -3174,11 +3310,6 @@ var FETCH_CHUNK_BYTES = 64 * 1024;
|
|
|
3174
3310
|
var FETCH_INLINE_BODY_BYTES = 8 * 1024;
|
|
3175
3311
|
var FETCH_METADATA_BYTES = 64 * 1024;
|
|
3176
3312
|
|
|
3177
|
-
// ../domain-contracts/src/app-host/service-host-protocol.ts
|
|
3178
|
-
var SERVICE_HOST_MAX_FRAME_BYTES = 512 * 1024;
|
|
3179
|
-
var worktreeBody = { workspaceId: id, expectedHead: text2(256), branch: text2(1024) };
|
|
3180
|
-
var worktreeReceipt = object2({ requestId: id, state: enumeration("accepted", "completed", "failed", "unknown") }, { result: object2({ executionRoot: id, workspaceId: id, branch: text2(1024), sourceHead: text2(256) }) });
|
|
3181
|
-
|
|
3182
3313
|
// ../domain-contracts/src/app-host/workspace-conversations.ts
|
|
3183
3314
|
var validWorkspaceConversation = (value) => {
|
|
3184
3315
|
if (!object2(
|
|
@@ -3217,7 +3348,6 @@ var workspaceConversationResult = object2({
|
|
|
3217
3348
|
revision: count2,
|
|
3218
3349
|
session: sessionRecord,
|
|
3219
3350
|
operationState: enumeration("prepared", "running", "completed", "failed", "unknown"),
|
|
3220
|
-
indexBindingPending: (v) => v === true,
|
|
3221
3351
|
workspaceId: id,
|
|
3222
3352
|
executionRoot: id,
|
|
3223
3353
|
privateSessionId: id,
|
|
@@ -3248,7 +3378,6 @@ function validSessionControlInput(method, value) {
|
|
|
3248
3378
|
const target = value;
|
|
3249
3379
|
return target.workspaceId !== void 0 ? target.outsideProject !== true : target.outsideProject === true;
|
|
3250
3380
|
}
|
|
3251
|
-
if (method === "sessions.bindConversationIndex") return object2({ original: validWorkspaceConversation, dataScopeId: text2() })(value);
|
|
3252
3381
|
if (method === "sessions.createConversation" || method === "sessions.getConversationCreationResult") return validWorkspaceConversation(value);
|
|
3253
3382
|
if (method === "sessions.getControls") return object2({ connectionId: text2(), sessionId: text2() })(value);
|
|
3254
3383
|
if (!object2({ requestId: id, sessionId: text2(), original: validSessionControlOriginal }, { connectionId: text2() })(value)) return false;
|
|
@@ -3258,10 +3387,9 @@ function validSessionControlInput(method, value) {
|
|
|
3258
3387
|
function validSessionControlResult(method, value) {
|
|
3259
3388
|
if (!json(value)) return false;
|
|
3260
3389
|
if (method === "sessions.getDraftComposerOptions") return object2({ source: enumeration("instance"), optionsRevision: text2(), skills: array(object2({ id: text2(), name: text2(), path: text2(4096, true) }, { source: enumeration("bundled", "user", "project", "plugin") }), 128), plugins: array(object2({ id: text2(), name: text2(), agents: array(option, 128) }), 128) })(value);
|
|
3261
|
-
if (method === "sessions.bindConversationIndex") return validWorkspaceConversationResult(value);
|
|
3262
3390
|
if (method === "sessions.createConversation" || method === "sessions.getConversationCreationResult")
|
|
3263
3391
|
return method === "sessions.getConversationCreationResult" && value === null || validWorkspaceConversationResult(value);
|
|
3264
|
-
if (method === "sessions.getControls") return object2({ dataScopeId: text2(), sessionId: text2(), source: enumeration("instance", "auxiliary", "im"), revision: count2, optionsRevision: text2(), actions: object2(Object.fromEntries(["readContext", "configure", "compact", "edit", "fork", "resume", "goalRead", "goalWrite", "goalStop"].map((k) => [k, bool]))), models: choices, roles: choices, efforts: effortChoices, workModes: choices, skills: array(object2({ id: text2(), name: text2(), path: text2(4096, true) }, { source: enumeration("bundled", "user", "project", "plugin") })), commands: choices, contexts: choices }, { permissionModes: array(option, 128),
|
|
3392
|
+
if (method === "sessions.getControls") return object2({ dataScopeId: text2(), sessionId: text2(), source: enumeration("instance", "auxiliary", "im"), revision: count2, optionsRevision: text2(), actions: object2(Object.fromEntries(["readContext", "configure", "compact", "edit", "fork", "resume", "goalRead", "goalWrite", "goalStop"].map((k) => [k, bool]))), models: choices, roles: choices, efforts: effortChoices, workModes: choices, skills: array(object2({ id: text2(), name: text2(), path: text2(4096, true) }, { source: enumeration("bundled", "user", "project", "plugin") })), commands: choices, contexts: choices }, { permissionModes: array(option, 128), plugins: array(object2({ id: text2(), name: text2(), agents: choices })) })(value);
|
|
3265
3393
|
if (method === "sessions.getControlResult") return value === null || receipt(value);
|
|
3266
3394
|
if (!receipt(value)) return false;
|
|
3267
3395
|
return false;
|
|
@@ -3324,7 +3452,7 @@ var validProviderDefaultsSnapshot = object2({
|
|
|
3324
3452
|
verified,
|
|
3325
3453
|
fastModeAvailable: enumeration(false),
|
|
3326
3454
|
fastModeReason: text2(1024)
|
|
3327
|
-
});
|
|
3455
|
+
}, { accountGatewayMatches: bool });
|
|
3328
3456
|
var validProviderConnectionTestResult = object2({
|
|
3329
3457
|
status: enumeration("verified", "failed"),
|
|
3330
3458
|
detail: text2(8192),
|
|
@@ -3512,14 +3640,7 @@ var HttpTransport = class {
|
|
|
3512
3640
|
this.protocolHandshake = void 0;
|
|
3513
3641
|
throw error;
|
|
3514
3642
|
});
|
|
3515
|
-
|
|
3516
|
-
return new Promise((resolve5, reject) => {
|
|
3517
|
-
const onAbort = () => reject(signal.reason);
|
|
3518
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
3519
|
-
this.protocolHandshake.then(resolve5, reject).finally(() => {
|
|
3520
|
-
signal.removeEventListener("abort", onAbort);
|
|
3521
|
-
});
|
|
3522
|
-
});
|
|
3643
|
+
return waitForRequest(this.protocolHandshake, signal);
|
|
3523
3644
|
}
|
|
3524
3645
|
headers(jsonOrOptions = false, auth = true) {
|
|
3525
3646
|
let json2 = false;
|
|
@@ -3586,6 +3707,21 @@ var HttpTransport = class {
|
|
|
3586
3707
|
return throwResponseError(response);
|
|
3587
3708
|
}
|
|
3588
3709
|
};
|
|
3710
|
+
function waitForRequest(request, signal) {
|
|
3711
|
+
if (!signal) return request;
|
|
3712
|
+
return new Promise((resolve5, reject) => {
|
|
3713
|
+
const onAbort = () => reject(signal.reason);
|
|
3714
|
+
if (signal.aborted) onAbort();
|
|
3715
|
+
else signal.addEventListener("abort", onAbort, { once: true });
|
|
3716
|
+
void request.then(resolve5, reject).finally(() => signal.removeEventListener("abort", onAbort));
|
|
3717
|
+
});
|
|
3718
|
+
}
|
|
3719
|
+
async function requireDaemonFeature(transport, feature, signal) {
|
|
3720
|
+
const capabilities = await transport.ensureProtocol(signal);
|
|
3721
|
+
if ((capabilities.features[feature] ?? 0) < 1) {
|
|
3722
|
+
throw new IncompatibleProtocolError(capabilities, `Daemon does not support ${feature}. Update the daemon before calling this method.`);
|
|
3723
|
+
}
|
|
3724
|
+
}
|
|
3589
3725
|
function mergeHeaders(defaults, overrides) {
|
|
3590
3726
|
const headers2 = new Headers(defaults);
|
|
3591
3727
|
if (overrides) {
|
|
@@ -3639,8 +3775,9 @@ ${slice}` : slice;
|
|
|
3639
3775
|
if (!data) return void 0;
|
|
3640
3776
|
return JSON.parse(data);
|
|
3641
3777
|
}
|
|
3642
|
-
async function* streamServerSentEvents(open, decode = (value) => value) {
|
|
3643
|
-
|
|
3778
|
+
async function* streamServerSentEvents(open, decode = (value) => value, options) {
|
|
3779
|
+
options?.signal?.throwIfAborted();
|
|
3780
|
+
for await (const frame of readSseFrames(await open(), options)) {
|
|
3644
3781
|
const event = parseSseFrame(frame);
|
|
3645
3782
|
if (event !== void 0) yield decode(event);
|
|
3646
3783
|
}
|
|
@@ -3711,26 +3848,43 @@ var SseTransport = class {
|
|
|
3711
3848
|
}
|
|
3712
3849
|
}
|
|
3713
3850
|
};
|
|
3714
|
-
async function* readSseFrames(stream) {
|
|
3851
|
+
async function* readSseFrames(stream, { signal, maxFrameBytes, onChunk } = {}) {
|
|
3715
3852
|
const reader = stream.getReader();
|
|
3716
3853
|
const decoder = new TextDecoder();
|
|
3854
|
+
const encoder = new TextEncoder();
|
|
3855
|
+
const checkSize = (frame) => {
|
|
3856
|
+
if (maxFrameBytes !== void 0 && encoder.encode(frame).byteLength > maxFrameBytes) {
|
|
3857
|
+
throw new Error(`SSE frame exceeds ${maxFrameBytes} bytes`);
|
|
3858
|
+
}
|
|
3859
|
+
};
|
|
3860
|
+
const cancel = () => reader.cancel().catch(() => {
|
|
3861
|
+
});
|
|
3862
|
+
const onAbort = () => {
|
|
3863
|
+
void cancel();
|
|
3864
|
+
};
|
|
3865
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
3717
3866
|
let buffer = "";
|
|
3718
3867
|
try {
|
|
3719
3868
|
while (true) {
|
|
3869
|
+
signal?.throwIfAborted();
|
|
3720
3870
|
const chunk = await reader.read();
|
|
3871
|
+
signal?.throwIfAborted();
|
|
3721
3872
|
if (chunk.done) break;
|
|
3873
|
+
onChunk?.();
|
|
3722
3874
|
buffer += decoder.decode(chunk.value, { stream: true });
|
|
3723
3875
|
const frames = buffer.split(/\r?\n\r?\n/);
|
|
3724
3876
|
buffer = frames.pop() ?? "";
|
|
3725
|
-
|
|
3877
|
+
for (const frame of frames) {
|
|
3878
|
+
signal?.throwIfAborted();
|
|
3879
|
+
checkSize(frame);
|
|
3880
|
+
yield frame;
|
|
3881
|
+
}
|
|
3882
|
+
if (maxFrameBytes !== void 0) checkSize(buffer.replace(/(?:\r?\n\r?|\r)$/, ""));
|
|
3726
3883
|
}
|
|
3727
3884
|
} finally {
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
} finally {
|
|
3732
|
-
reader.releaseLock();
|
|
3733
|
-
}
|
|
3885
|
+
signal?.removeEventListener("abort", onAbort);
|
|
3886
|
+
await cancel();
|
|
3887
|
+
reader.releaseLock();
|
|
3734
3888
|
}
|
|
3735
3889
|
}
|
|
3736
3890
|
function waitForReconnect(ms, signal) {
|
|
@@ -3760,48 +3914,14 @@ function withoutCursor(url) {
|
|
|
3760
3914
|
return parsed.toString();
|
|
3761
3915
|
}
|
|
3762
3916
|
|
|
3763
|
-
// src/resources/runtime/runtime-resource.ts
|
|
3764
|
-
var RuntimeResource = class {
|
|
3765
|
-
constructor(transport) {
|
|
3766
|
-
this.transport = transport;
|
|
3767
|
-
}
|
|
3768
|
-
transport;
|
|
3769
|
-
async listModels(options = {}) {
|
|
3770
|
-
const response = await this.transport.request("/models", options);
|
|
3771
|
-
return response.providers;
|
|
3772
|
-
}
|
|
3773
|
-
async modelProviders(input = { action: "list" }, options = {}) {
|
|
3774
|
-
const response = await this.transport.request("/providers/manage", { ...options, method: "POST", body: input });
|
|
3775
|
-
if (!validModelProviderConnections(response?.providers)) throw new Error("Invalid model provider response");
|
|
3776
|
-
return response.providers;
|
|
3777
|
-
}
|
|
3778
|
-
async providerDefaults(input = { action: "snapshot" }, options = {}) {
|
|
3779
|
-
const result = await this.transport.request("/providers/defaults", { ...options, method: "POST", body: input });
|
|
3780
|
-
const valid = input.action === "test" ? validProviderConnectionTestResult(result) : validProviderDefaultsSnapshot(result);
|
|
3781
|
-
if (!valid) throw new Error("Invalid provider defaults response");
|
|
3782
|
-
return result;
|
|
3783
|
-
}
|
|
3784
|
-
async listAgentPersonas(options = {}) {
|
|
3785
|
-
const response = await this.transport.request("/agent-personas", options);
|
|
3786
|
-
return response.agents;
|
|
3787
|
-
}
|
|
3788
|
-
listSkills(options = {}) {
|
|
3789
|
-
return this.transport.request("/skills", options);
|
|
3790
|
-
}
|
|
3791
|
-
async getSessionMcp(sessionId, options = {}) {
|
|
3792
|
-
const response = await this.transport.request(`/sessions/${encodeURIComponent(sessionId)}/mcp`, options);
|
|
3793
|
-
return response.servers;
|
|
3794
|
-
}
|
|
3795
|
-
};
|
|
3796
|
-
|
|
3797
3917
|
// src/resources/session/session-request-id.ts
|
|
3798
|
-
var
|
|
3799
|
-
function
|
|
3918
|
+
var sessionRequestCounter = 0;
|
|
3919
|
+
function createSessionRequestId() {
|
|
3800
3920
|
if (typeof globalThis.crypto?.randomUUID === "function") {
|
|
3801
3921
|
return globalThis.crypto.randomUUID();
|
|
3802
3922
|
}
|
|
3803
|
-
|
|
3804
|
-
return `prompt-${Date.now().toString(36)}-${
|
|
3923
|
+
sessionRequestCounter += 1;
|
|
3924
|
+
return `prompt-${Date.now().toString(36)}-${sessionRequestCounter.toString(36)}`;
|
|
3805
3925
|
}
|
|
3806
3926
|
|
|
3807
3927
|
// src/resources/session/session-configuration-requests.ts
|
|
@@ -3824,27 +3944,31 @@ async function getDraftComposerOptions(transport, input, options = {}) {
|
|
|
3824
3944
|
return result;
|
|
3825
3945
|
}
|
|
3826
3946
|
async function create(transport, input, options = {}) {
|
|
3947
|
+
const body = parseCreateSessionRequest({
|
|
3948
|
+
...input,
|
|
3949
|
+
id: input.id ?? createSessionRequestId(),
|
|
3950
|
+
requestId: input.requestId ?? createSessionRequestId()
|
|
3951
|
+
});
|
|
3952
|
+
if (body.cwd === void 0) await requireDaemonFeature(transport, "projectSessionCreation", options.signal);
|
|
3827
3953
|
const response = await transport.request(
|
|
3828
3954
|
"/sessions",
|
|
3829
3955
|
{
|
|
3830
3956
|
method: "POST",
|
|
3831
|
-
body
|
|
3832
|
-
...input,
|
|
3833
|
-
id: input.id ?? createPromptRequestId(),
|
|
3834
|
-
requestId: input.requestId ?? createPromptRequestId()
|
|
3835
|
-
}),
|
|
3957
|
+
body,
|
|
3836
3958
|
signal: options.signal
|
|
3837
3959
|
}
|
|
3838
3960
|
);
|
|
3839
3961
|
return response.session;
|
|
3840
3962
|
}
|
|
3841
3963
|
async function getConfigurationOptions(transport, input, options = {}) {
|
|
3964
|
+
if (input.cwd === void 0) await requireDaemonFeature(transport, "projectSessionCreation", options.signal);
|
|
3842
3965
|
return transport.request(
|
|
3843
3966
|
transport.path("/sessions/configuration-options", input),
|
|
3844
3967
|
{ signal: options.signal }
|
|
3845
3968
|
);
|
|
3846
3969
|
}
|
|
3847
3970
|
async function getCreationResult(transport, input, options = {}) {
|
|
3971
|
+
if (input.original.cwd === void 0) await requireDaemonFeature(transport, "projectSessionCreation", options.signal);
|
|
3848
3972
|
return transport.request("/sessions/creation-result", {
|
|
3849
3973
|
method: "POST",
|
|
3850
3974
|
body: input,
|
|
@@ -3881,123 +4005,39 @@ async function getConfigurationResult(transport, sessionId, input, options = {})
|
|
|
3881
4005
|
});
|
|
3882
4006
|
}
|
|
3883
4007
|
|
|
3884
|
-
// src/resources/session/
|
|
3885
|
-
|
|
3886
|
-
|
|
3887
|
-
if (input.outputSchema === void 0) return;
|
|
3888
|
-
return transport.ensureProtocol(signal).then((capabilities) => {
|
|
3889
|
-
if ((capabilities.features.structuredDelivery ?? 0) < 1) {
|
|
3890
|
-
throw new Error(
|
|
3891
|
-
"Server does not support structured delivery (outputSchema)"
|
|
3892
|
-
);
|
|
3893
|
-
}
|
|
3894
|
-
});
|
|
3895
|
-
}
|
|
3896
|
-
async function admitPrompt(transport, sessionId, input, options = {}) {
|
|
3897
|
-
const schemaCheck = checkOutputSchema(transport, input, options.signal);
|
|
3898
|
-
if (schemaCheck) await schemaCheck;
|
|
3899
|
-
if (input.expectedActiveRunId !== void 0) {
|
|
3900
|
-
const capabilities = await transport.ensureProtocol(options.signal);
|
|
3901
|
-
if ((capabilities.features.steer ?? 0) < 2) {
|
|
3902
|
-
throw new IncompatibleProtocolError(capabilities, "\u540E\u53F0\u7248\u672C\u4E0D\u652F\u6301\u8FD0\u884C\u4E2D\u8865\u5145\uFF0C\u8BF7\u66F4\u65B0\u540E\u91CD\u8BD5\u3002");
|
|
3903
|
-
}
|
|
3904
|
-
}
|
|
3905
|
-
return await transport.request(
|
|
3906
|
-
`/sessions/${encodeURIComponent(sessionId)}/prompts`,
|
|
3907
|
-
{
|
|
3908
|
-
method: "POST",
|
|
3909
|
-
body: { ...input, id: input.id ?? createPromptRequestId() },
|
|
3910
|
-
signal: options.signal
|
|
3911
|
-
}
|
|
3912
|
-
);
|
|
3913
|
-
}
|
|
3914
|
-
async function editLatestPrompt(transport, sessionId, input, options = {}) {
|
|
3915
|
-
await checkOutputSchema(transport, input, options.signal);
|
|
3916
|
-
return await transport.request(
|
|
3917
|
-
`/sessions/${encodeURIComponent(sessionId)}/prompts/latest/edit`,
|
|
3918
|
-
{
|
|
3919
|
-
method: "POST",
|
|
3920
|
-
body: input,
|
|
3921
|
-
signal: options.signal
|
|
3922
|
-
}
|
|
3923
|
-
);
|
|
3924
|
-
}
|
|
3925
|
-
async function promoteQueuedPrompt(transport, sessionId, inputId, input, options = {}) {
|
|
3926
|
-
return await transport.request(
|
|
3927
|
-
`/sessions/${encodeURIComponent(sessionId)}/prompts/${encodeURIComponent(inputId)}/promote`,
|
|
3928
|
-
{ method: "POST", body: input, signal: options.signal }
|
|
3929
|
-
);
|
|
3930
|
-
}
|
|
3931
|
-
async function cancelQueuedPrompt(transport, sessionId, inputId, input, options = {}) {
|
|
3932
|
-
const mode = parseCancelResponseMode(options.responseMode);
|
|
3933
|
-
const response = await transport.request(
|
|
3934
|
-
`/sessions/${encodeURIComponent(sessionId)}/prompts/${encodeURIComponent(inputId)}/cancel`,
|
|
3935
|
-
{
|
|
3936
|
-
method: "POST",
|
|
3937
|
-
body: {
|
|
3938
|
-
...input,
|
|
3939
|
-
...options.responseMode ? { responseMode: mode } : {}
|
|
3940
|
-
},
|
|
3941
|
-
signal: options.signal
|
|
3942
|
-
}
|
|
3943
|
-
);
|
|
3944
|
-
if (mode === "receipt") {
|
|
3945
|
-
const receipt2 = decodeQueuedPromptCancelReceipt(response);
|
|
3946
|
-
if (receipt2.inputId !== inputId || receipt2.queuedRunId !== input.queuedRunId)
|
|
3947
|
-
throw new ProtocolDataError(
|
|
3948
|
-
"Cancellation receipt does not match target"
|
|
3949
|
-
);
|
|
3950
|
-
return receipt2;
|
|
3951
|
-
}
|
|
3952
|
-
return response;
|
|
3953
|
-
}
|
|
3954
|
-
async function resumeInterruptedRun(transport, sessionId, runId, input = {}, options = {}) {
|
|
3955
|
-
await checkOutputSchema(transport, input, options.signal);
|
|
3956
|
-
return await transport.request(
|
|
3957
|
-
`/sessions/${encodeURIComponent(sessionId)}/runs/${encodeURIComponent(runId)}/resume`,
|
|
3958
|
-
{
|
|
3959
|
-
method: "POST",
|
|
3960
|
-
body: { ...input, id: input.id ?? createPromptRequestId() },
|
|
3961
|
-
signal: options.signal
|
|
3962
|
-
}
|
|
3963
|
-
);
|
|
3964
|
-
}
|
|
3965
|
-
async function interrupt(transport, sessionId, options = {}) {
|
|
3966
|
-
return await transport.request(
|
|
3967
|
-
`/sessions/${encodeURIComponent(sessionId)}/interrupt`,
|
|
3968
|
-
{
|
|
3969
|
-
method: "POST",
|
|
3970
|
-
body: options.expectedRunId === void 0 ? void 0 : { expectedRunId: options.expectedRunId },
|
|
3971
|
-
signal: options.signal
|
|
3972
|
-
}
|
|
3973
|
-
);
|
|
3974
|
-
}
|
|
3975
|
-
|
|
3976
|
-
// src/resources/session/session-terminal-resource.ts
|
|
3977
|
-
var SessionTerminalResource = class {
|
|
3978
|
-
constructor(transport) {
|
|
4008
|
+
// src/resources/session/event-resource.ts
|
|
4009
|
+
var EventResource = class {
|
|
4010
|
+
constructor(transport, sse) {
|
|
3979
4011
|
this.transport = transport;
|
|
4012
|
+
this.sse = sse;
|
|
3980
4013
|
}
|
|
3981
4014
|
transport;
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
}
|
|
3986
|
-
async read(sessionId, terminalId, options = {}) {
|
|
4015
|
+
sse;
|
|
4016
|
+
/** `GET /events` — 用于 attach 时的历史 replay。 */
|
|
4017
|
+
async list(options = {}) {
|
|
3987
4018
|
const { signal, ...query } = options;
|
|
3988
|
-
const response = await this.transport.
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
4019
|
+
const response = await this.transport.request(
|
|
4020
|
+
this.transport.path("/events", query),
|
|
4021
|
+
{ signal }
|
|
4022
|
+
);
|
|
4023
|
+
return responseArray2(response, "events", decodeSessionEventRecord);
|
|
4024
|
+
}
|
|
4025
|
+
stream(options = {}) {
|
|
4026
|
+
const query = {
|
|
4027
|
+
partView: options.partView,
|
|
4028
|
+
cursor: options.cursor,
|
|
4029
|
+
sessionId: options.sessionId
|
|
4030
|
+
};
|
|
4031
|
+
return this.sse.stream(this.transport.resolveUrl("/events/stream", query), {
|
|
4032
|
+
headers: this.transport.headers(),
|
|
4033
|
+
signal: options.signal,
|
|
4034
|
+
decode: decodeSessionEventRecord,
|
|
4035
|
+
reconnect: options.transportReconnect ?? false,
|
|
4036
|
+
onOpen: options.onOpen,
|
|
4037
|
+
idleTimeoutMs: options.idleTimeoutMs
|
|
4038
|
+
});
|
|
3996
4039
|
}
|
|
3997
4040
|
};
|
|
3998
|
-
function path(sessionId, terminalId) {
|
|
3999
|
-
return `/sessions/${encodeURIComponent(sessionId)}/terminals${terminalId === void 0 ? "" : `/${encodeURIComponent(terminalId)}`}`;
|
|
4000
|
-
}
|
|
4001
4041
|
|
|
4002
4042
|
// src/resources/session/session-management-resource.ts
|
|
4003
4043
|
var SessionManagementResource = class {
|
|
@@ -4051,594 +4091,2195 @@ var SessionManagementResource = class {
|
|
|
4051
4091
|
}
|
|
4052
4092
|
};
|
|
4053
4093
|
|
|
4054
|
-
// src/
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
}
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
|
|
4065
|
-
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
|
|
4094
|
+
// src/state/selectors.ts
|
|
4095
|
+
function selectSessionMessagesWithParts(bucket) {
|
|
4096
|
+
if (!bucket) return [];
|
|
4097
|
+
return [...bucket.messages].sort((a, b) => a.seq - b.seq).map((message) => ({
|
|
4098
|
+
message,
|
|
4099
|
+
parts: [...bucket.partsByMessageId[message.id] ?? []].sort((a, b) => a.seq - b.seq)
|
|
4100
|
+
}));
|
|
4101
|
+
}
|
|
4102
|
+
function getVisibleSessionMessages(bucket) {
|
|
4103
|
+
return selectSessionMessagesWithParts(bucket).map(({ message, parts }) => ({
|
|
4104
|
+
message,
|
|
4105
|
+
parts: parts.filter((part) => !isSupersededModelPart(part))
|
|
4106
|
+
})).filter(
|
|
4107
|
+
({ message, parts }) => parts.length > 0 || message.role !== "assistant"
|
|
4108
|
+
);
|
|
4109
|
+
}
|
|
4110
|
+
|
|
4111
|
+
// src/state/reducer.ts
|
|
4112
|
+
var UnsupportedSessionEventSchemaVersionError = class extends Error {
|
|
4113
|
+
event;
|
|
4114
|
+
constructor(event) {
|
|
4115
|
+
const expected = sessionEventSchemaVersion(event.type);
|
|
4116
|
+
super(
|
|
4117
|
+
`Unsupported session event schema version ${event.schemaVersion} for ${event.type} at sequence ${event.seq}; expected ${expected}`
|
|
4118
|
+
);
|
|
4119
|
+
this.name = "UnsupportedSessionEventSchemaVersionError";
|
|
4120
|
+
this.event = {
|
|
4121
|
+
seq: event.seq,
|
|
4122
|
+
type: event.type,
|
|
4123
|
+
schemaVersion: event.schemaVersion
|
|
4124
|
+
};
|
|
4069
4125
|
}
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4126
|
+
};
|
|
4127
|
+
function createClientState() {
|
|
4128
|
+
return {
|
|
4129
|
+
sessions: {},
|
|
4130
|
+
sessionOrder: [],
|
|
4131
|
+
buckets: {},
|
|
4132
|
+
eventsBySeq: {},
|
|
4133
|
+
snapshotCursorBySession: {},
|
|
4134
|
+
transientCursor: 0,
|
|
4135
|
+
lastSeq: 0
|
|
4136
|
+
};
|
|
4137
|
+
}
|
|
4138
|
+
function replaceSessionState(state, snapshot) {
|
|
4139
|
+
const knownCursor = state.snapshotCursorBySession[snapshot.session.id] ?? 0;
|
|
4140
|
+
if (snapshot.cursor < knownCursor) return state;
|
|
4141
|
+
if (Object.values(state.eventsBySeq).some((event) => event.sessionId === snapshot.session.id && event.seq > snapshot.cursor)) return state;
|
|
4142
|
+
const partsByMessageId = {};
|
|
4143
|
+
for (const part of snapshot.parts) {
|
|
4144
|
+
const parts = partsByMessageId[part.messageId] ?? [];
|
|
4145
|
+
parts.push(part);
|
|
4146
|
+
partsByMessageId[part.messageId] = parts;
|
|
4147
|
+
}
|
|
4148
|
+
for (const parts of Object.values(partsByMessageId)) parts.sort((a, b) => a.seq - b.seq);
|
|
4149
|
+
const sessions = { ...state.sessions, [snapshot.session.id]: snapshot.session };
|
|
4150
|
+
return {
|
|
4151
|
+
...state,
|
|
4152
|
+
sessions,
|
|
4153
|
+
sessionOrder: sortSessionOrder(sessions),
|
|
4154
|
+
buckets: {
|
|
4155
|
+
...state.buckets,
|
|
4156
|
+
[snapshot.session.id]: {
|
|
4157
|
+
goal: snapshot.goal,
|
|
4158
|
+
goalEventSeq: snapshot.cursor,
|
|
4159
|
+
session: snapshot.session,
|
|
4160
|
+
inputs: [...snapshot.inputs].sort((a, b) => a.seq - b.seq),
|
|
4161
|
+
messages: [...snapshot.messages].sort((a, b) => a.seq - b.seq),
|
|
4162
|
+
partsByMessageId,
|
|
4163
|
+
runs: Object.fromEntries(snapshot.runs.map((run) => [run.id, run])),
|
|
4164
|
+
attempts: Object.fromEntries((snapshot.attempts ?? []).map((attempt) => [attempt.id, attempt])),
|
|
4165
|
+
tasks: Object.fromEntries((snapshot.tasks ?? []).map((task) => [task.id, task])),
|
|
4166
|
+
permissions: Object.fromEntries(snapshot.permissions.map((request) => [request.id, request]))
|
|
4167
|
+
}
|
|
4168
|
+
},
|
|
4169
|
+
snapshotCursorBySession: {
|
|
4170
|
+
...state.snapshotCursorBySession,
|
|
4171
|
+
[snapshot.session.id]: Math.max(
|
|
4172
|
+
state.snapshotCursorBySession[snapshot.session.id] ?? 0,
|
|
4173
|
+
snapshot.cursor
|
|
4174
|
+
)
|
|
4175
|
+
},
|
|
4176
|
+
transientCursor: Math.max(state.transientCursor, snapshot.cursor),
|
|
4177
|
+
lastSeq: Math.max(state.lastSeq, snapshot.cursor)
|
|
4178
|
+
};
|
|
4179
|
+
}
|
|
4180
|
+
function applyEvent(state, event) {
|
|
4181
|
+
if (event.schemaVersion !== sessionEventSchemaVersion(event.type)) {
|
|
4182
|
+
throw new UnsupportedSessionEventSchemaVersionError(event);
|
|
4183
|
+
}
|
|
4184
|
+
const transient = event.type === "session.message.part.delta";
|
|
4185
|
+
const snapshotCursor = event.sessionId ? state.snapshotCursorBySession[event.sessionId] ?? 0 : 0;
|
|
4186
|
+
if (event.seq <= snapshotCursor) return state;
|
|
4187
|
+
if (transient && event.seq <= state.transientCursor) return state;
|
|
4188
|
+
if (!transient && state.eventsBySeq[event.seq]) return state;
|
|
4189
|
+
if (!transient) state.eventsBySeq[event.seq] = event;
|
|
4190
|
+
let next = {
|
|
4191
|
+
...state,
|
|
4192
|
+
eventsBySeq: state.eventsBySeq,
|
|
4193
|
+
transientCursor: transient ? event.seq : state.transientCursor,
|
|
4194
|
+
lastSeq: Math.max(state.lastSeq, event.seq)
|
|
4195
|
+
};
|
|
4196
|
+
switch (event.type) {
|
|
4197
|
+
case "session.goal.created":
|
|
4198
|
+
case "session.goal.updated": {
|
|
4199
|
+
next = upsertGoal(next, event);
|
|
4200
|
+
break;
|
|
4201
|
+
}
|
|
4202
|
+
case "session.goal.usage.updated": {
|
|
4203
|
+
const bucket = event.sessionId ? next.buckets[event.sessionId] : void 0;
|
|
4204
|
+
const usage = readPayloadRecord(event, "usage");
|
|
4205
|
+
if (bucket?.goal && bucket.goal.id === event.payload.goalId && usage && usage.seq > bucket.goal.usage.seq) {
|
|
4206
|
+
next = { ...next, buckets: { ...next.buckets, [event.sessionId]: { ...bucket, goal: { ...bucket.goal, usage } } } };
|
|
4207
|
+
}
|
|
4208
|
+
break;
|
|
4209
|
+
}
|
|
4210
|
+
case "session.created":
|
|
4211
|
+
case "session.updated":
|
|
4212
|
+
next = upsertSession(next, readPayloadRecord(event, "session"));
|
|
4213
|
+
break;
|
|
4214
|
+
case "session.archived":
|
|
4215
|
+
next = archiveSession(next, event);
|
|
4216
|
+
break;
|
|
4217
|
+
case "session.deleted":
|
|
4218
|
+
next = deleteSessions(next, event);
|
|
4219
|
+
break;
|
|
4220
|
+
case "session.input.admitted":
|
|
4221
|
+
next = upsertInput(next, readPayloadRecord(event, "input"));
|
|
4222
|
+
break;
|
|
4223
|
+
case "session.message.created":
|
|
4224
|
+
next = upsertMessage(next, readPayloadRecord(event, "message"));
|
|
4225
|
+
break;
|
|
4226
|
+
case "session.transcript.replaced":
|
|
4227
|
+
next = replaceTranscript(next, event);
|
|
4228
|
+
break;
|
|
4229
|
+
case "session.message.part.updated":
|
|
4230
|
+
next = upsertPart(next, readPayloadRecord(event, "part"));
|
|
4231
|
+
break;
|
|
4232
|
+
case "session.message.part.delta":
|
|
4233
|
+
next = appendPartDelta(next, event);
|
|
4234
|
+
break;
|
|
4235
|
+
case "session.run.created":
|
|
4236
|
+
case "session.run.updated":
|
|
4237
|
+
next = upsertRun(next, readPayloadRecord(event, "run"));
|
|
4238
|
+
break;
|
|
4239
|
+
case "session.run_attempt.created":
|
|
4240
|
+
case "session.run_attempt.updated":
|
|
4241
|
+
next = upsertRunAttempt(next, readPayloadRecord(event, "attempt"));
|
|
4242
|
+
break;
|
|
4243
|
+
case "session.task.created":
|
|
4244
|
+
case "session.task.updated":
|
|
4245
|
+
next = upsertTask(next, readPayloadRecord(event, "task"));
|
|
4246
|
+
break;
|
|
4247
|
+
case "permission.asked":
|
|
4248
|
+
case "permission.replied":
|
|
4249
|
+
next = upsertPermission(next, readPayloadRecord(event, "request"));
|
|
4250
|
+
break;
|
|
4251
|
+
}
|
|
4252
|
+
return next;
|
|
4253
|
+
}
|
|
4254
|
+
function readPayloadRecord(event, key) {
|
|
4255
|
+
const value = event.payload[key];
|
|
4256
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
4257
|
+
}
|
|
4258
|
+
function upsertGoal(state, event) {
|
|
4259
|
+
const goal = readPayloadRecord(event, "goal");
|
|
4260
|
+
if (!goal || goal.sessionId !== event.sessionId) return state;
|
|
4261
|
+
const bucket = state.buckets[goal.sessionId];
|
|
4262
|
+
const current = bucket?.goal;
|
|
4263
|
+
const seq = bucket?.goalEventSeq ?? 0;
|
|
4264
|
+
const sameGoal = current?.id === goal.id;
|
|
4265
|
+
if (current && !sameGoal && (event.type !== "session.goal.created" || event.seq <= seq)) return state;
|
|
4266
|
+
const isNewer = !sameGoal || goal.revision > current.revision || goal.revision === current.revision && event.seq > seq;
|
|
4267
|
+
const record4 = isNewer ? goal : current;
|
|
4268
|
+
const usage = sameGoal && current.usage.seq >= goal.usage.seq ? current.usage : goal.usage;
|
|
4269
|
+
if (!isNewer && usage === current.usage) return state;
|
|
4270
|
+
return { ...state, buckets: { ...state.buckets, [goal.sessionId]: {
|
|
4271
|
+
...bucket ?? cloneBucket(void 0),
|
|
4272
|
+
goal: usage === record4.usage ? record4 : { ...record4, usage },
|
|
4273
|
+
goalEventSeq: isNewer ? Math.max(seq, event.seq) : seq
|
|
4274
|
+
} } };
|
|
4275
|
+
}
|
|
4276
|
+
function upsertSession(state, session) {
|
|
4277
|
+
if (!session) return state;
|
|
4278
|
+
const bucket = cloneBucket(state.buckets[session.id]);
|
|
4279
|
+
bucket.session = session;
|
|
4280
|
+
const sessions = { ...state.sessions, [session.id]: session };
|
|
4281
|
+
return {
|
|
4282
|
+
...state,
|
|
4283
|
+
sessions,
|
|
4284
|
+
sessionOrder: sortSessionOrder(sessions),
|
|
4285
|
+
buckets: { ...state.buckets, [session.id]: bucket }
|
|
4286
|
+
};
|
|
4287
|
+
}
|
|
4288
|
+
function archiveSession(state, event) {
|
|
4289
|
+
const sessionId = typeof event.payload.sessionId === "string" ? event.payload.sessionId : event.sessionId;
|
|
4290
|
+
if (!sessionId) return state;
|
|
4291
|
+
const current = state.sessions[sessionId];
|
|
4292
|
+
if (!current) return state;
|
|
4293
|
+
const archived = {
|
|
4294
|
+
...current,
|
|
4295
|
+
status: "archived",
|
|
4296
|
+
archivedAt: current.archivedAt ?? event.createdAt,
|
|
4297
|
+
updatedAt: Math.max(current.updatedAt, event.createdAt)
|
|
4298
|
+
};
|
|
4299
|
+
return upsertSession(state, archived);
|
|
4300
|
+
}
|
|
4301
|
+
function deleteSessions(state, event) {
|
|
4302
|
+
const ids = new Set(Array.isArray(event.payload.sessionIds) ? event.payload.sessionIds.filter((id2) => typeof id2 === "string") : []);
|
|
4303
|
+
if (ids.size === 0) return state;
|
|
4304
|
+
return {
|
|
4305
|
+
...state,
|
|
4306
|
+
sessions: Object.fromEntries(Object.entries(state.sessions).filter(([id2]) => !ids.has(id2))),
|
|
4307
|
+
sessionOrder: state.sessionOrder.filter((id2) => !ids.has(id2)),
|
|
4308
|
+
buckets: Object.fromEntries(Object.entries(state.buckets).filter(([id2]) => !ids.has(id2))),
|
|
4309
|
+
snapshotCursorBySession: Object.fromEntries(Object.entries(state.snapshotCursorBySession).filter(([id2]) => !ids.has(id2))),
|
|
4310
|
+
eventsBySeq: Object.fromEntries(Object.entries(state.eventsBySeq).filter(([, item]) => !item.sessionId || !ids.has(item.sessionId)))
|
|
4311
|
+
};
|
|
4312
|
+
}
|
|
4313
|
+
function upsertInput(state, input) {
|
|
4314
|
+
if (!input) return state;
|
|
4315
|
+
const bucket = cloneBucket(state.buckets[input.sessionId]);
|
|
4316
|
+
bucket.inputs = upsertSorted(bucket.inputs, input, (row) => row.seq);
|
|
4317
|
+
return { ...state, buckets: { ...state.buckets, [input.sessionId]: bucket } };
|
|
4318
|
+
}
|
|
4319
|
+
function upsertMessage(state, message) {
|
|
4320
|
+
if (!message) return state;
|
|
4321
|
+
const bucket = cloneBucket(state.buckets[message.sessionId]);
|
|
4322
|
+
bucket.messages = upsertSorted(bucket.messages, message, (row) => row.seq);
|
|
4323
|
+
return { ...state, buckets: { ...state.buckets, [message.sessionId]: bucket } };
|
|
4324
|
+
}
|
|
4325
|
+
function replaceTranscript(state, event) {
|
|
4326
|
+
const sessionId = event.sessionId;
|
|
4327
|
+
if (!sessionId) return state;
|
|
4328
|
+
const messages = Array.isArray(event.payload.messages) ? event.payload.messages.filter((row) => !!row && typeof row === "object" && !Array.isArray(row) && typeof row.id === "string") : [];
|
|
4329
|
+
const parts = Array.isArray(event.payload.parts) ? event.payload.parts.filter((row) => !!row && typeof row === "object" && !Array.isArray(row) && typeof row.id === "string") : [];
|
|
4330
|
+
const bucket = cloneBucket(state.buckets[sessionId]);
|
|
4331
|
+
const partsByMessageId = {};
|
|
4332
|
+
for (const part of parts) {
|
|
4333
|
+
const rows = partsByMessageId[part.messageId] ?? [];
|
|
4334
|
+
rows.push(part);
|
|
4335
|
+
partsByMessageId[part.messageId] = rows;
|
|
4336
|
+
}
|
|
4337
|
+
for (const rows of Object.values(partsByMessageId)) rows.sort((a, b) => a.seq - b.seq);
|
|
4338
|
+
bucket.messages = [...messages].sort((a, b) => a.seq - b.seq);
|
|
4339
|
+
bucket.partsByMessageId = partsByMessageId;
|
|
4340
|
+
if (bucket.session) {
|
|
4341
|
+
bucket.session = {
|
|
4342
|
+
...bucket.session,
|
|
4343
|
+
updatedAt: Math.max(bucket.session.updatedAt, event.createdAt)
|
|
4344
|
+
};
|
|
4075
4345
|
}
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4346
|
+
const sessions = bucket.session ? { ...state.sessions, [sessionId]: bucket.session } : state.sessions;
|
|
4347
|
+
return {
|
|
4348
|
+
...state,
|
|
4349
|
+
sessions,
|
|
4350
|
+
sessionOrder: sortSessionOrder(sessions),
|
|
4351
|
+
buckets: { ...state.buckets, [sessionId]: bucket }
|
|
4352
|
+
};
|
|
4353
|
+
}
|
|
4354
|
+
function upsertPart(state, part) {
|
|
4355
|
+
if (!part) return state;
|
|
4356
|
+
const bucket = cloneBucketForPartWrite(state.buckets[part.sessionId]);
|
|
4357
|
+
const existing = bucket.partsByMessageId[part.messageId] ?? [];
|
|
4358
|
+
bucket.partsByMessageId = {
|
|
4359
|
+
...bucket.partsByMessageId,
|
|
4360
|
+
[part.messageId]: upsertSorted(existing, part, (row) => row.seq)
|
|
4361
|
+
};
|
|
4362
|
+
return { ...state, buckets: { ...state.buckets, [part.sessionId]: bucket } };
|
|
4363
|
+
}
|
|
4364
|
+
function appendPartDelta(state, event) {
|
|
4365
|
+
const sessionId = typeof event.payload.sessionId === "string" ? event.payload.sessionId : event.sessionId;
|
|
4366
|
+
const messageId = typeof event.payload.messageId === "string" ? event.payload.messageId : void 0;
|
|
4367
|
+
const partId = typeof event.payload.partId === "string" ? event.payload.partId : void 0;
|
|
4368
|
+
const field = event.payload.field;
|
|
4369
|
+
const delta = typeof event.payload.delta === "string" ? event.payload.delta : void 0;
|
|
4370
|
+
if (field !== "text" && field !== "reasoning") return state;
|
|
4371
|
+
if (!sessionId || !messageId || !partId || delta === void 0) return state;
|
|
4372
|
+
const bucket = cloneBucketForPartWrite(state.buckets[sessionId]);
|
|
4373
|
+
const currentParts = bucket.partsByMessageId[messageId] ?? [];
|
|
4374
|
+
const index = currentParts.findIndex((part) => part.id === partId);
|
|
4375
|
+
const nextParts = [...currentParts];
|
|
4376
|
+
if (index >= 0) {
|
|
4377
|
+
const current = nextParts[index];
|
|
4378
|
+
if (isSupersededModelPart(current)) return state;
|
|
4379
|
+
nextParts[index] = {
|
|
4380
|
+
...current,
|
|
4381
|
+
text: `${current.text ?? ""}${delta}`,
|
|
4382
|
+
updatedAt: Math.max(current.updatedAt, event.createdAt)
|
|
4383
|
+
};
|
|
4384
|
+
} else {
|
|
4385
|
+
const seq = currentParts.reduce((max, part) => Math.max(max, part.seq), 0) + 1;
|
|
4386
|
+
nextParts.push({
|
|
4387
|
+
id: partId,
|
|
4388
|
+
sessionId,
|
|
4389
|
+
messageId,
|
|
4390
|
+
seq,
|
|
4391
|
+
type: field === "reasoning" ? "reasoning" : "text",
|
|
4392
|
+
status: "running",
|
|
4393
|
+
text: delta,
|
|
4394
|
+
metadata: {},
|
|
4395
|
+
createdAt: event.createdAt,
|
|
4396
|
+
updatedAt: event.createdAt
|
|
4397
|
+
});
|
|
4082
4398
|
}
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
|
|
4399
|
+
const sortedParts = index >= 0 ? nextParts : nextParts.sort((a, b) => a.seq - b.seq);
|
|
4400
|
+
bucket.partsByMessageId = {
|
|
4401
|
+
...bucket.partsByMessageId,
|
|
4402
|
+
[messageId]: sortedParts
|
|
4403
|
+
};
|
|
4404
|
+
return { ...state, buckets: { ...state.buckets, [sessionId]: bucket } };
|
|
4405
|
+
}
|
|
4406
|
+
function upsertRun(state, run) {
|
|
4407
|
+
if (!run) return state;
|
|
4408
|
+
const bucket = cloneBucket(state.buckets[run.sessionId]);
|
|
4409
|
+
bucket.runs = { ...bucket.runs, [run.id]: run };
|
|
4410
|
+
const session = refreshSessionStatusFromRuns(bucket.session, bucket.runs, run.updatedAt);
|
|
4411
|
+
bucket.session = session;
|
|
4412
|
+
const sessions = session ? { ...state.sessions, [run.sessionId]: session } : state.sessions;
|
|
4413
|
+
return {
|
|
4414
|
+
...state,
|
|
4415
|
+
sessions,
|
|
4416
|
+
sessionOrder: session ? sortSessionOrder(sessions) : state.sessionOrder,
|
|
4417
|
+
buckets: { ...state.buckets, [run.sessionId]: bucket }
|
|
4418
|
+
};
|
|
4419
|
+
}
|
|
4420
|
+
function upsertRunAttempt(state, attempt) {
|
|
4421
|
+
if (!attempt) return state;
|
|
4422
|
+
const run = Object.values(state.buckets).flatMap((bucket2) => Object.values(bucket2.runs)).find((candidate) => candidate.id === attempt.runId);
|
|
4423
|
+
if (!run) return state;
|
|
4424
|
+
const bucket = cloneBucket(state.buckets[run.sessionId]);
|
|
4425
|
+
bucket.attempts = { ...bucket.attempts, [attempt.id]: attempt };
|
|
4426
|
+
return { ...state, buckets: { ...state.buckets, [run.sessionId]: bucket } };
|
|
4427
|
+
}
|
|
4428
|
+
function refreshSessionStatusFromRuns(session, runs, updatedAt) {
|
|
4429
|
+
if (!session || session.status === "archived" || session.status === "closing") return session;
|
|
4430
|
+
const running = Object.values(runs).some(
|
|
4431
|
+
(candidate) => candidate.status === "pending" || candidate.status === "running"
|
|
4432
|
+
);
|
|
4433
|
+
return {
|
|
4434
|
+
...session,
|
|
4435
|
+
status: running ? "running" : "idle",
|
|
4436
|
+
updatedAt: Math.max(session.updatedAt, updatedAt)
|
|
4437
|
+
};
|
|
4438
|
+
}
|
|
4439
|
+
function upsertPermission(state, request) {
|
|
4440
|
+
if (!request) return state;
|
|
4441
|
+
const bucket = cloneBucket(state.buckets[request.sessionId]);
|
|
4442
|
+
bucket.permissions = { ...bucket.permissions, [request.id]: request };
|
|
4443
|
+
return { ...state, buckets: { ...state.buckets, [request.sessionId]: bucket } };
|
|
4444
|
+
}
|
|
4445
|
+
function upsertTask(state, task) {
|
|
4446
|
+
if (!task) return state;
|
|
4447
|
+
const bucket = cloneBucket(state.buckets[task.sessionId]);
|
|
4448
|
+
bucket.tasks = { ...bucket.tasks, [task.id]: task };
|
|
4449
|
+
return { ...state, buckets: { ...state.buckets, [task.sessionId]: bucket } };
|
|
4450
|
+
}
|
|
4451
|
+
function cloneBucket(bucket) {
|
|
4452
|
+
return {
|
|
4453
|
+
...bucket?.goal !== void 0 ? { goal: bucket.goal } : {},
|
|
4454
|
+
...bucket?.goalEventSeq !== void 0 ? { goalEventSeq: bucket.goalEventSeq } : {},
|
|
4455
|
+
session: bucket?.session,
|
|
4456
|
+
inputs: bucket?.inputs ? [...bucket.inputs] : [],
|
|
4457
|
+
messages: bucket?.messages ? [...bucket.messages] : [],
|
|
4458
|
+
partsByMessageId: bucket?.partsByMessageId ? Object.fromEntries(Object.entries(bucket.partsByMessageId).map(([id2, parts]) => [id2, [...parts]])) : {},
|
|
4459
|
+
runs: bucket?.runs ? { ...bucket.runs } : {},
|
|
4460
|
+
attempts: bucket?.attempts ? { ...bucket.attempts } : {},
|
|
4461
|
+
tasks: bucket?.tasks ? { ...bucket.tasks } : {},
|
|
4462
|
+
permissions: bucket?.permissions ? { ...bucket.permissions } : {}
|
|
4463
|
+
};
|
|
4464
|
+
}
|
|
4465
|
+
function cloneBucketForPartWrite(bucket) {
|
|
4466
|
+
return {
|
|
4467
|
+
...bucket?.goal !== void 0 ? { goal: bucket.goal } : {},
|
|
4468
|
+
...bucket?.goalEventSeq !== void 0 ? { goalEventSeq: bucket.goalEventSeq } : {},
|
|
4469
|
+
session: bucket?.session,
|
|
4470
|
+
inputs: bucket?.inputs ?? [],
|
|
4471
|
+
messages: bucket?.messages ?? [],
|
|
4472
|
+
partsByMessageId: bucket?.partsByMessageId ?? {},
|
|
4473
|
+
runs: bucket?.runs ?? {},
|
|
4474
|
+
attempts: bucket?.attempts ?? {},
|
|
4475
|
+
tasks: bucket?.tasks ?? {},
|
|
4476
|
+
permissions: bucket?.permissions ?? {}
|
|
4477
|
+
};
|
|
4478
|
+
}
|
|
4479
|
+
function upsertSorted(rows, row, sortKey) {
|
|
4480
|
+
const without = rows.filter((existing) => existing.id !== row.id);
|
|
4481
|
+
without.push(row);
|
|
4482
|
+
return without.sort((a, b) => sortKey(a) - sortKey(b));
|
|
4483
|
+
}
|
|
4484
|
+
function sortSessionOrder(sessions) {
|
|
4485
|
+
return Object.values(sessions).sort((a, b) => b.updatedAt - a.updatedAt || a.id.localeCompare(b.id)).map((session) => session.id);
|
|
4486
|
+
}
|
|
4487
|
+
|
|
4488
|
+
// src/state/session-stream-state.ts
|
|
4489
|
+
function applySessionStreamEvent(state, event) {
|
|
4490
|
+
if (event.seq <= state.lastSeq) return state;
|
|
4491
|
+
const next = applyEvent({ ...state, eventsBySeq: {} }, event);
|
|
4492
|
+
return { ...next, eventsBySeq: {} };
|
|
4493
|
+
}
|
|
4494
|
+
function applySessionStreamSnapshot(state, snapshot) {
|
|
4495
|
+
if (snapshot.cursor < state.lastSeq) return state;
|
|
4496
|
+
return { ...replaceSessionState(state, snapshot), eventsBySeq: {} };
|
|
4497
|
+
}
|
|
4498
|
+
|
|
4499
|
+
// src/state/sync.ts
|
|
4500
|
+
var DEFAULT_RECONNECT_DELAY_MS = (attempt) => Math.min(3e4, 250 * 2 ** Math.max(0, attempt));
|
|
4501
|
+
var DEFAULT_SESSION_IDLE_TIMEOUT_MS = 6e4;
|
|
4502
|
+
var EVENT_REPLAY_PAGE_SIZE = 128;
|
|
4503
|
+
async function* syncEvents(client, options = {}) {
|
|
4504
|
+
yield* runEventSync(client, {
|
|
4505
|
+
...options,
|
|
4506
|
+
// 会话迭代接口从完整快照开始;只有全局 replay 使用调用方游标。
|
|
4507
|
+
cursor: options.sessionId ? void 0 : options.cursor,
|
|
4508
|
+
idleTimeoutMs: options.idleTimeoutMs ?? DEFAULT_SESSION_IDLE_TIMEOUT_MS
|
|
4509
|
+
});
|
|
4510
|
+
}
|
|
4511
|
+
async function* runEventSync(client, options, initialState = createClientState(), onLiveEvent) {
|
|
4512
|
+
let state = initialState;
|
|
4513
|
+
let cursor = Math.max(0, options.cursor ?? 0, state.lastSeq);
|
|
4514
|
+
let attempt = 0;
|
|
4515
|
+
const signal = options.signal;
|
|
4516
|
+
const delayMs = options.reconnectDelayMs ?? DEFAULT_RECONNECT_DELAY_MS;
|
|
4517
|
+
const reduce = options.sessionId ? applySessionStreamEvent : options.globalReducer ?? applyEvent;
|
|
4518
|
+
if (signal?.aborted) return;
|
|
4519
|
+
const session = options.sessionId ? client.sessions.byId(options.sessionId) : void 0;
|
|
4520
|
+
const refreshSession = async (initial) => {
|
|
4521
|
+
const snapshot = await session.getState({
|
|
4522
|
+
signal,
|
|
4523
|
+
partView: options.partView
|
|
4086
4524
|
});
|
|
4525
|
+
if (signal?.aborted) return;
|
|
4526
|
+
const next = initial ? replaceSessionState(state, snapshot) : applySessionStreamSnapshot(state, snapshot);
|
|
4527
|
+
state = Object.keys(next.eventsBySeq).length ? { ...next, eventsBySeq: {} } : next;
|
|
4528
|
+
cursor = Math.max(cursor, snapshot.cursor, state.lastSeq);
|
|
4529
|
+
};
|
|
4530
|
+
const replayHistory = async function* (initial, beforeSeq) {
|
|
4531
|
+
let pageCursor = cursor;
|
|
4532
|
+
while (!signal?.aborted) {
|
|
4533
|
+
const page = await client.events.list({
|
|
4534
|
+
cursor: pageCursor,
|
|
4535
|
+
limit: EVENT_REPLAY_PAGE_SIZE,
|
|
4536
|
+
partView: options.partView,
|
|
4537
|
+
signal
|
|
4538
|
+
});
|
|
4539
|
+
if (signal?.aborted) return;
|
|
4540
|
+
for (const event of page) {
|
|
4541
|
+
if (signal?.aborted || beforeSeq !== void 0 && event.seq >= beforeSeq) return;
|
|
4542
|
+
const before = state;
|
|
4543
|
+
state = reduce(state, event);
|
|
4544
|
+
cursor = Math.max(cursor, event.seq, state.lastSeq);
|
|
4545
|
+
if (initial || state !== before) yield { event, state, source: "replay" };
|
|
4546
|
+
}
|
|
4547
|
+
const through = page.at(-1)?.seq ?? pageCursor;
|
|
4548
|
+
if (page.length < EVENT_REPLAY_PAGE_SIZE || through <= pageCursor) return;
|
|
4549
|
+
pageCursor = through;
|
|
4550
|
+
}
|
|
4551
|
+
};
|
|
4552
|
+
try {
|
|
4553
|
+
if (options.sessionId) {
|
|
4554
|
+
await refreshSession(true);
|
|
4555
|
+
} else {
|
|
4556
|
+
yield* replayHistory(true);
|
|
4557
|
+
}
|
|
4558
|
+
if (signal?.aborted) return;
|
|
4559
|
+
yield { state, source: "snapshot" };
|
|
4560
|
+
let needsSnapshot = false;
|
|
4561
|
+
while (!signal?.aborted) {
|
|
4562
|
+
try {
|
|
4563
|
+
if (needsSnapshot) {
|
|
4564
|
+
await refreshSession(false);
|
|
4565
|
+
if (signal?.aborted) return;
|
|
4566
|
+
needsSnapshot = false;
|
|
4567
|
+
yield { state, source: "snapshot" };
|
|
4568
|
+
}
|
|
4569
|
+
if (signal?.aborted) return;
|
|
4570
|
+
for await (const event of client.events.stream({
|
|
4571
|
+
cursor,
|
|
4572
|
+
sessionId: options.sessionId,
|
|
4573
|
+
signal,
|
|
4574
|
+
partView: options.partView,
|
|
4575
|
+
transportReconnect: false,
|
|
4576
|
+
idleTimeoutMs: options.idleTimeoutMs
|
|
4577
|
+
})) {
|
|
4578
|
+
if (signal?.aborted) return;
|
|
4579
|
+
onLiveEvent?.();
|
|
4580
|
+
if (signal?.aborted) return;
|
|
4581
|
+
attempt = 0;
|
|
4582
|
+
if (event.seq > cursor + 1 && !options.sessionId) {
|
|
4583
|
+
yield* replayHistory(false, event.seq);
|
|
4584
|
+
}
|
|
4585
|
+
if (signal?.aborted) return;
|
|
4586
|
+
const before = state;
|
|
4587
|
+
state = reduce(state, event);
|
|
4588
|
+
cursor = Math.max(cursor, event.seq, state.lastSeq);
|
|
4589
|
+
if (state !== before) yield { event, state, source: "live" };
|
|
4590
|
+
}
|
|
4591
|
+
} catch (error) {
|
|
4592
|
+
if (error instanceof UnsupportedSessionEventSchemaVersionError) throw error;
|
|
4593
|
+
if (isAbortError(error) || signal?.aborted) return;
|
|
4594
|
+
if (options.shouldRetry?.(error) === false) throw error;
|
|
4595
|
+
if (error instanceof BobanNomiApiError && error.status >= 400 && error.status < 500 && ![408, 425, 429].includes(error.status)) throw error;
|
|
4596
|
+
}
|
|
4597
|
+
if (signal?.aborted) return;
|
|
4598
|
+
needsSnapshot = Boolean(options.sessionId);
|
|
4599
|
+
yield { state, source: "reconnecting" };
|
|
4600
|
+
if (!await waitForReconnect2(delayMs(attempt), signal)) return;
|
|
4601
|
+
attempt += 1;
|
|
4602
|
+
}
|
|
4603
|
+
} catch (error) {
|
|
4604
|
+
if (!isAbortError(error) && !signal?.aborted) throw error;
|
|
4087
4605
|
}
|
|
4088
|
-
|
|
4089
|
-
|
|
4606
|
+
}
|
|
4607
|
+
async function waitForReconnect2(ms, signal) {
|
|
4608
|
+
if (signal?.aborted) return false;
|
|
4609
|
+
if (ms <= 0) return true;
|
|
4610
|
+
return new Promise((resolve5) => {
|
|
4611
|
+
const onAbort = () => {
|
|
4612
|
+
clearTimeout(timer);
|
|
4613
|
+
resolve5(false);
|
|
4614
|
+
};
|
|
4615
|
+
const timer = setTimeout(() => {
|
|
4616
|
+
signal?.removeEventListener("abort", onAbort);
|
|
4617
|
+
resolve5(!signal?.aborted);
|
|
4618
|
+
}, ms);
|
|
4619
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
4620
|
+
});
|
|
4621
|
+
}
|
|
4622
|
+
function isAbortError(error) {
|
|
4623
|
+
return Boolean(error && typeof error === "object" && "name" in error && error.name === "AbortError");
|
|
4624
|
+
}
|
|
4625
|
+
|
|
4626
|
+
// src/state/wait-for-run.ts
|
|
4627
|
+
async function waitForRun(client, options) {
|
|
4628
|
+
options.signal?.throwIfAborted();
|
|
4629
|
+
for await (const update of syncEvents(client, { sessionId: options.sessionId, signal: options.signal })) {
|
|
4630
|
+
options.signal?.throwIfAborted();
|
|
4631
|
+
const bucket = update.state.buckets[options.sessionId];
|
|
4632
|
+
const run = bucket?.runs[options.runId];
|
|
4633
|
+
if (!run || run.status === "pending" || run.status === "running") continue;
|
|
4634
|
+
return {
|
|
4635
|
+
run,
|
|
4636
|
+
messages: getVisibleSessionMessages(bucket).filter((item) => item.message.runId === options.runId)
|
|
4637
|
+
};
|
|
4090
4638
|
}
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
|
|
4639
|
+
options.signal?.throwIfAborted();
|
|
4640
|
+
throw new Error(`Run ${options.runId} observation ended before a terminal state was available`);
|
|
4641
|
+
}
|
|
4642
|
+
|
|
4643
|
+
// src/resources/files/files-resource.ts
|
|
4644
|
+
var FilesResource = class {
|
|
4645
|
+
#transport;
|
|
4646
|
+
#sessionId;
|
|
4647
|
+
constructor(transport, sessionId) {
|
|
4648
|
+
this.#transport = transport;
|
|
4649
|
+
this.#sessionId = sessionId;
|
|
4100
4650
|
}
|
|
4101
|
-
async
|
|
4102
|
-
const {
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
{
|
|
4107
|
-
method: "POST",
|
|
4108
|
-
body: { requestId, original },
|
|
4109
|
-
signal: options.signal
|
|
4110
|
-
}
|
|
4651
|
+
async list(options = {}) {
|
|
4652
|
+
const { signal, ...query } = options;
|
|
4653
|
+
const response = await this.#transport.request(
|
|
4654
|
+
this.#transport.path(`/sessions/${encodeURIComponent(this.#sessionId)}/files`, query),
|
|
4655
|
+
{ signal }
|
|
4111
4656
|
);
|
|
4112
|
-
|
|
4113
|
-
throw new ProtocolDataError(
|
|
4114
|
-
"Control receipt does not match original request"
|
|
4115
|
-
);
|
|
4116
|
-
return result;
|
|
4657
|
+
return decodeSessionDirectoryResult(response);
|
|
4117
4658
|
}
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
`/sessions/${encodeURIComponent(sessionId)}/context-usage`,
|
|
4659
|
+
async stat(path2, options = {}) {
|
|
4660
|
+
const response = await this.#transport.request(
|
|
4661
|
+
this.#transport.path(`/sessions/${encodeURIComponent(this.#sessionId)}/files/stat`, { path: path2 }),
|
|
4122
4662
|
{ signal: options.signal }
|
|
4123
4663
|
);
|
|
4664
|
+
return decodeSessionFileInfo(response);
|
|
4124
4665
|
}
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
const response = await this
|
|
4128
|
-
`/sessions/${encodeURIComponent(sessionId)}`,
|
|
4129
|
-
{
|
|
4130
|
-
signal: options.signal
|
|
4131
|
-
}
|
|
4666
|
+
async readText(path2, options = {}) {
|
|
4667
|
+
const { signal, ...query } = options;
|
|
4668
|
+
const response = await this.#transport.request(
|
|
4669
|
+
this.#transport.path(`/sessions/${encodeURIComponent(this.#sessionId)}/files/text`, { path: path2, ...query }),
|
|
4670
|
+
{ signal }
|
|
4132
4671
|
);
|
|
4133
|
-
return response
|
|
4134
|
-
}
|
|
4135
|
-
/** `POST /sessions` */
|
|
4136
|
-
create(input, options = {}) {
|
|
4137
|
-
return create(this.transport, input, options);
|
|
4138
|
-
}
|
|
4139
|
-
getConfigurationOptions(input, options = {}) {
|
|
4140
|
-
return getConfigurationOptions(this.transport, input, options);
|
|
4141
|
-
}
|
|
4142
|
-
getCreationResult(input, options = {}) {
|
|
4143
|
-
return getCreationResult(this.transport, input, options);
|
|
4672
|
+
return decodeSessionTextFileResult(response);
|
|
4144
4673
|
}
|
|
4145
|
-
|
|
4146
|
-
|
|
4674
|
+
async find(options) {
|
|
4675
|
+
const { signal, ...query } = options;
|
|
4676
|
+
const response = await this.#transport.request(
|
|
4677
|
+
this.#transport.path(`/sessions/${encodeURIComponent(this.#sessionId)}/files/find`, query),
|
|
4678
|
+
{ signal }
|
|
4679
|
+
);
|
|
4680
|
+
return decodeSessionFindFilesResult(response);
|
|
4147
4681
|
}
|
|
4148
|
-
|
|
4149
|
-
|
|
4682
|
+
async search(options) {
|
|
4683
|
+
const { signal, caseSensitive, ...query } = options;
|
|
4684
|
+
const response = await this.#transport.request(
|
|
4685
|
+
this.#transport.path(`/sessions/${encodeURIComponent(this.#sessionId)}/files/search`, {
|
|
4686
|
+
...query,
|
|
4687
|
+
...caseSensitive === void 0 ? {} : { caseSensitive: String(caseSensitive) }
|
|
4688
|
+
}),
|
|
4689
|
+
{ signal }
|
|
4690
|
+
);
|
|
4691
|
+
return decodeSessionSearchFilesResult(response);
|
|
4150
4692
|
}
|
|
4151
|
-
|
|
4152
|
-
|
|
4693
|
+
};
|
|
4694
|
+
|
|
4695
|
+
// src/resources/runtime/job-resource.ts
|
|
4696
|
+
var JobResource = class {
|
|
4697
|
+
#transport;
|
|
4698
|
+
#sessionId;
|
|
4699
|
+
constructor(transport, sessionId) {
|
|
4700
|
+
this.#transport = transport;
|
|
4701
|
+
this.#sessionId = sessionId;
|
|
4153
4702
|
}
|
|
4154
|
-
|
|
4155
|
-
|
|
4156
|
-
const response = await this
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
|
|
4160
|
-
|
|
4161
|
-
|
|
4162
|
-
|
|
4703
|
+
async list(options = {}) {
|
|
4704
|
+
const { signal, kinds, statuses, includeFinished, ...query } = options;
|
|
4705
|
+
const response = await this.#transport.request(
|
|
4706
|
+
this.#transport.path("/jobs", {
|
|
4707
|
+
...query,
|
|
4708
|
+
sessionId: this.#sessionId,
|
|
4709
|
+
...kinds ? { kinds: kinds.join(",") } : {},
|
|
4710
|
+
...statuses ? { statuses: statuses.join(",") } : {},
|
|
4711
|
+
...includeFinished !== void 0 ? { includeFinished: String(includeFinished) } : {}
|
|
4712
|
+
}),
|
|
4713
|
+
{ signal }
|
|
4163
4714
|
);
|
|
4164
|
-
return response
|
|
4715
|
+
return decodeJobListResult(response);
|
|
4165
4716
|
}
|
|
4166
|
-
|
|
4167
|
-
|
|
4168
|
-
|
|
4169
|
-
`/sessions/${encodeURIComponent(sessionId)}/fork`,
|
|
4717
|
+
async createBackgroundShell(input, options = {}) {
|
|
4718
|
+
return await this.#transport.request(
|
|
4719
|
+
"/background-shells",
|
|
4170
4720
|
{
|
|
4171
4721
|
method: "POST",
|
|
4172
|
-
body:
|
|
4173
|
-
...input,
|
|
4174
|
-
id: input.id ?? createPromptRequestId(),
|
|
4175
|
-
requestId: input.requestId ?? createPromptRequestId()
|
|
4176
|
-
}),
|
|
4722
|
+
body: { ...input, sessionId: this.#sessionId },
|
|
4177
4723
|
signal: options.signal
|
|
4178
4724
|
}
|
|
4179
4725
|
);
|
|
4180
|
-
return response.session;
|
|
4181
4726
|
}
|
|
4182
|
-
|
|
4183
|
-
|
|
4184
|
-
const response = await this
|
|
4185
|
-
`/
|
|
4727
|
+
async read(target, options = {}) {
|
|
4728
|
+
const { signal, ...query } = options;
|
|
4729
|
+
const response = await this.#transport.request(
|
|
4730
|
+
this.#transport.path(`/jobs/${encodeURIComponent(target.jobId)}`, { ...query, sessionId: this.#sessionId, kind: target.kind, ...target.kind === "agent" ? { runId: target.runId } : {} }),
|
|
4731
|
+
{ signal }
|
|
4732
|
+
);
|
|
4733
|
+
return decodeJobReadResult(response);
|
|
4734
|
+
}
|
|
4735
|
+
async wait(target, input = {}, options = {}) {
|
|
4736
|
+
const response = await this.#transport.request(
|
|
4737
|
+
`/jobs/${encodeURIComponent(target.jobId)}/wait`,
|
|
4186
4738
|
{
|
|
4187
|
-
method: "
|
|
4739
|
+
method: "POST",
|
|
4740
|
+
body: { ...input, sessionId: this.#sessionId, target },
|
|
4188
4741
|
signal: options.signal
|
|
4189
4742
|
}
|
|
4190
4743
|
);
|
|
4191
|
-
return response
|
|
4744
|
+
return decodeJobWaitResult(response);
|
|
4192
4745
|
}
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
|
|
4746
|
+
async send(target, input, options = {}) {
|
|
4747
|
+
const response = await this.#transport.request(`/jobs/${encodeURIComponent(target.jobId)}/input`, {
|
|
4748
|
+
method: "POST",
|
|
4749
|
+
body: { ...input, sessionId: this.#sessionId, target },
|
|
4197
4750
|
signal: options.signal
|
|
4198
4751
|
});
|
|
4199
|
-
|
|
4752
|
+
if (responseField(response, "sent") !== true) throw new ProtocolDataError("Job input was not accepted", "sent");
|
|
4753
|
+
const receipt2 = response.receipt;
|
|
4754
|
+
return receipt2 === void 0 ? void 0 : decodeJobInputReceipt(receipt2);
|
|
4200
4755
|
}
|
|
4201
|
-
|
|
4202
|
-
|
|
4203
|
-
const response = await this
|
|
4204
|
-
|
|
4205
|
-
|
|
4206
|
-
}),
|
|
4207
|
-
{
|
|
4208
|
-
signal: options.signal
|
|
4209
|
-
}
|
|
4756
|
+
async cancel(target, input = {}, options = {}) {
|
|
4757
|
+
const mode = parseCancelResponseMode(options.responseMode);
|
|
4758
|
+
const response = await this.#transport.request(
|
|
4759
|
+
`/jobs/${encodeURIComponent(target.jobId)}/cancel`,
|
|
4760
|
+
{ method: "POST", body: { ...input, sessionId: this.#sessionId, target, ...options.responseMode ? { responseMode: mode } : {} }, signal: options.signal }
|
|
4210
4761
|
);
|
|
4211
|
-
|
|
4762
|
+
if (mode === "receipt") {
|
|
4763
|
+
const receipt2 = decodeJobCancelReceipt(response);
|
|
4764
|
+
if (receipt2.id !== target.jobId) throw new ProtocolDataError("Cancellation receipt does not match target");
|
|
4765
|
+
return receipt2;
|
|
4766
|
+
}
|
|
4767
|
+
return decodeJobSnapshot(responseField(response, "snapshot"));
|
|
4212
4768
|
}
|
|
4213
|
-
|
|
4214
|
-
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
|
|
4769
|
+
};
|
|
4770
|
+
|
|
4771
|
+
// src/resources/session/session-terminal-resource.ts
|
|
4772
|
+
var SessionTerminalResource = class {
|
|
4773
|
+
#transport;
|
|
4774
|
+
#sessionId;
|
|
4775
|
+
constructor(transport, sessionId) {
|
|
4776
|
+
this.#transport = transport;
|
|
4777
|
+
this.#sessionId = sessionId;
|
|
4778
|
+
}
|
|
4779
|
+
async list(options = {}) {
|
|
4780
|
+
const response = await this.#transport.requestUnknown(path(this.#sessionId), options);
|
|
4781
|
+
return responseArray2(response, "terminals", decodeTerminalSessionInfo);
|
|
4224
4782
|
}
|
|
4225
|
-
|
|
4226
|
-
async listMessageParts(sessionId, options = {}) {
|
|
4783
|
+
async read(terminalId, options = {}) {
|
|
4227
4784
|
const { signal, ...query } = options;
|
|
4228
|
-
const response = await this
|
|
4229
|
-
|
|
4230
|
-
`/sessions/${encodeURIComponent(sessionId)}/parts`,
|
|
4231
|
-
query
|
|
4232
|
-
),
|
|
4233
|
-
{ signal }
|
|
4234
|
-
);
|
|
4235
|
-
return response.parts;
|
|
4785
|
+
const response = await this.#transport.requestUnknown(path(this.#sessionId, terminalId) + "/output", { signal, query });
|
|
4786
|
+
return decodeTerminalReadResult(responseField(response, "snapshot"));
|
|
4236
4787
|
}
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
const
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
);
|
|
4243
|
-
return response.part;
|
|
4788
|
+
async stream(terminalId, options = {}) {
|
|
4789
|
+
const response = await this.#transport.requestResponse(path(this.#sessionId, terminalId) + "/stream", options);
|
|
4790
|
+
const body = response.body;
|
|
4791
|
+
if (!body) throw new Error("Terminal event stream did not return a body");
|
|
4792
|
+
return streamServerSentEvents(async () => body, decodeTerminalEvent);
|
|
4244
4793
|
}
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4794
|
+
};
|
|
4795
|
+
function path(sessionId, terminalId) {
|
|
4796
|
+
return `/sessions/${encodeURIComponent(sessionId)}/terminals${terminalId === void 0 ? "" : `/${encodeURIComponent(terminalId)}`}`;
|
|
4797
|
+
}
|
|
4798
|
+
|
|
4799
|
+
// src/resources/session/session-run-requests.ts
|
|
4800
|
+
async function checkModelConnectionBinding(transport, input, signal) {
|
|
4801
|
+
const binding = parseExpectedModelConnection2(input);
|
|
4802
|
+
await requireDaemonFeature(transport, "runModelConnectionBinding", signal);
|
|
4803
|
+
return binding;
|
|
4804
|
+
}
|
|
4805
|
+
function checkOutputSchema(transport, input, signal) {
|
|
4806
|
+
assertPromptMetadataAllowed2(input);
|
|
4807
|
+
if (input.outputSchema === void 0) return;
|
|
4808
|
+
return transport.ensureProtocol(signal).then((capabilities) => {
|
|
4809
|
+
if ((capabilities.features.structuredDelivery ?? 0) < 1) {
|
|
4810
|
+
throw new Error(
|
|
4811
|
+
"Server does not support structured delivery (outputSchema)"
|
|
4812
|
+
);
|
|
4813
|
+
}
|
|
4814
|
+
});
|
|
4815
|
+
}
|
|
4816
|
+
async function admitPrompt(transport, sessionId, input, options = {}) {
|
|
4817
|
+
const expectedModelConnection = input.expectedModelConnection === void 0 ? void 0 : await checkModelConnectionBinding(transport, input.expectedModelConnection, options.signal);
|
|
4818
|
+
const schemaCheck = checkOutputSchema(transport, input, options.signal);
|
|
4819
|
+
if (schemaCheck) await schemaCheck;
|
|
4820
|
+
if (input.expectedActiveRunId !== void 0) {
|
|
4821
|
+
const capabilities = await transport.ensureProtocol(options.signal);
|
|
4822
|
+
if ((capabilities.features.steer ?? 0) < 2) {
|
|
4823
|
+
throw new IncompatibleProtocolError(capabilities, "\u540E\u53F0\u7248\u672C\u4E0D\u652F\u6301\u8FD0\u884C\u4E2D\u8865\u5145\uFF0C\u8BF7\u66F4\u65B0\u540E\u91CD\u8BD5\u3002");
|
|
4824
|
+
}
|
|
4825
|
+
}
|
|
4826
|
+
return await transport.request(
|
|
4827
|
+
`/sessions/${encodeURIComponent(sessionId)}/prompts`,
|
|
4828
|
+
{
|
|
4829
|
+
method: "POST",
|
|
4830
|
+
body: { ...input, expectedModelConnection, id: input.id ?? createSessionRequestId() },
|
|
4831
|
+
signal: options.signal
|
|
4832
|
+
}
|
|
4833
|
+
);
|
|
4834
|
+
}
|
|
4835
|
+
async function editLatestPrompt(transport, sessionId, input, options = {}) {
|
|
4836
|
+
const expectedModelConnection = input.expectedModelConnection === void 0 ? void 0 : await checkModelConnectionBinding(transport, input.expectedModelConnection, options.signal);
|
|
4837
|
+
await checkOutputSchema(transport, input, options.signal);
|
|
4838
|
+
return await transport.request(
|
|
4839
|
+
`/sessions/${encodeURIComponent(sessionId)}/prompts/latest/edit`,
|
|
4840
|
+
{
|
|
4841
|
+
method: "POST",
|
|
4842
|
+
body: { ...input, expectedModelConnection },
|
|
4843
|
+
signal: options.signal
|
|
4844
|
+
}
|
|
4845
|
+
);
|
|
4846
|
+
}
|
|
4847
|
+
async function promoteQueuedPrompt(transport, sessionId, inputId, input, options = {}) {
|
|
4848
|
+
return await transport.request(
|
|
4849
|
+
`/sessions/${encodeURIComponent(sessionId)}/prompts/${encodeURIComponent(inputId)}/promote`,
|
|
4850
|
+
{ method: "POST", body: input, signal: options.signal }
|
|
4851
|
+
);
|
|
4852
|
+
}
|
|
4853
|
+
async function cancelQueuedPrompt(transport, sessionId, inputId, input, options = {}) {
|
|
4854
|
+
const mode = parseCancelResponseMode(options.responseMode);
|
|
4855
|
+
const response = await transport.request(
|
|
4856
|
+
`/sessions/${encodeURIComponent(sessionId)}/prompts/${encodeURIComponent(inputId)}/cancel`,
|
|
4857
|
+
{
|
|
4858
|
+
method: "POST",
|
|
4859
|
+
body: {
|
|
4860
|
+
...input,
|
|
4861
|
+
...options.responseMode ? { responseMode: mode } : {}
|
|
4862
|
+
},
|
|
4863
|
+
signal: options.signal
|
|
4864
|
+
}
|
|
4865
|
+
);
|
|
4866
|
+
if (mode === "receipt") {
|
|
4867
|
+
const receipt2 = decodeQueuedPromptCancelReceipt(response);
|
|
4868
|
+
if (receipt2.inputId !== inputId || receipt2.queuedRunId !== input.queuedRunId)
|
|
4869
|
+
throw new ProtocolDataError(
|
|
4870
|
+
"Cancellation receipt does not match target"
|
|
4871
|
+
);
|
|
4872
|
+
return receipt2;
|
|
4873
|
+
}
|
|
4874
|
+
return response;
|
|
4875
|
+
}
|
|
4876
|
+
async function resumeInterruptedRun(transport, sessionId, runId, input = {}, options = {}) {
|
|
4877
|
+
await checkOutputSchema(transport, input, options.signal);
|
|
4878
|
+
return await transport.request(
|
|
4879
|
+
`/sessions/${encodeURIComponent(sessionId)}/runs/${encodeURIComponent(runId)}/resume`,
|
|
4880
|
+
{
|
|
4881
|
+
method: "POST",
|
|
4882
|
+
body: { ...input, id: input.id ?? createSessionRequestId() },
|
|
4883
|
+
signal: options.signal
|
|
4884
|
+
}
|
|
4885
|
+
);
|
|
4886
|
+
}
|
|
4887
|
+
async function interrupt(transport, sessionId, options = {}) {
|
|
4888
|
+
return await transport.request(
|
|
4889
|
+
`/sessions/${encodeURIComponent(sessionId)}/interrupt`,
|
|
4890
|
+
{
|
|
4891
|
+
method: "POST",
|
|
4892
|
+
body: options.expectedRunId === void 0 ? void 0 : { expectedRunId: options.expectedRunId },
|
|
4893
|
+
signal: options.signal
|
|
4894
|
+
}
|
|
4895
|
+
);
|
|
4896
|
+
}
|
|
4897
|
+
|
|
4898
|
+
// src/resources/session/session-handle.ts
|
|
4899
|
+
function createSessionHandle(transport, syncClient, management, sessionId) {
|
|
4900
|
+
function cancelQueuedPrompt2(inputId, input, options) {
|
|
4901
|
+
return cancelQueuedPrompt(transport, sessionId, inputId, input, options);
|
|
4902
|
+
}
|
|
4903
|
+
const path2 = `/sessions/${encodeURIComponent(sessionId)}`;
|
|
4904
|
+
async function saveGoal(target, method, input) {
|
|
4905
|
+
const expectedModelConnection = input.expectedModelConnection === void 0 ? void 0 : await checkModelConnectionBinding(transport, input.expectedModelConnection);
|
|
4906
|
+
const response = await transport.request(target, { method, body: { ...input, expectedModelConnection } });
|
|
4907
|
+
return response.goal;
|
|
4908
|
+
}
|
|
4909
|
+
return {
|
|
4910
|
+
id: sessionId,
|
|
4911
|
+
waitForRun: (runId, options) => waitForRun(syncClient, { sessionId, runId, signal: options?.signal }),
|
|
4912
|
+
async updateAppMetadata(metadata, options) {
|
|
4913
|
+
const body = parseUpdateSessionRequest({ metadata: { app: metadata } });
|
|
4914
|
+
const response = await transport.request(path2, {
|
|
4915
|
+
method: "PATCH",
|
|
4916
|
+
body,
|
|
4917
|
+
signal: options?.signal
|
|
4918
|
+
});
|
|
4919
|
+
return response.session;
|
|
4920
|
+
},
|
|
4921
|
+
/** `GET /sessions/:id` */
|
|
4922
|
+
async get(options = {}) {
|
|
4923
|
+
const response = await transport.request(
|
|
4924
|
+
path2,
|
|
4925
|
+
{
|
|
4926
|
+
signal: options.signal
|
|
4927
|
+
}
|
|
4928
|
+
);
|
|
4929
|
+
if (response?.session?.id !== sessionId) {
|
|
4930
|
+
throw new ProtocolDataError("Response does not contain the bound session", "session");
|
|
4931
|
+
}
|
|
4932
|
+
return response.session;
|
|
4933
|
+
},
|
|
4934
|
+
/** `GET /sessions/:id/state` - atomic attach snapshot plus SSE cursor. */
|
|
4935
|
+
async getState(options = {}) {
|
|
4936
|
+
const response = await transport.request(
|
|
4937
|
+
transport.path(`${path2}/state`, {
|
|
4938
|
+
partView: options.partView
|
|
4939
|
+
}),
|
|
4940
|
+
{
|
|
4941
|
+
signal: options.signal
|
|
4942
|
+
}
|
|
4943
|
+
);
|
|
4944
|
+
return decodeAgentSessionStateSnapshot(response);
|
|
4945
|
+
},
|
|
4946
|
+
/** `POST /sessions/:id/prompts` — 提交用户输入并触发/排队一次 run。 */
|
|
4947
|
+
prompt(input, options = {}) {
|
|
4948
|
+
return admitPrompt(transport, sessionId, input, options);
|
|
4949
|
+
},
|
|
4950
|
+
/** `POST /sessions/:id/interrupt` — 中断当前/排队中的 run。 */
|
|
4951
|
+
interrupt(options = {}) {
|
|
4952
|
+
return interrupt(transport, sessionId, options);
|
|
4953
|
+
},
|
|
4954
|
+
async getControls(options = {}) {
|
|
4955
|
+
const result = await transport.request(
|
|
4956
|
+
`${path2}/controls`,
|
|
4957
|
+
{ signal: options.signal }
|
|
4958
|
+
);
|
|
4959
|
+
if (!validSessionControlResult("sessions.getControls", result) || result.sessionId !== sessionId) {
|
|
4960
|
+
throw new ProtocolDataError("Session controls do not match target");
|
|
4961
|
+
}
|
|
4962
|
+
return result;
|
|
4963
|
+
},
|
|
4964
|
+
async getControlResult(input, options = {}) {
|
|
4965
|
+
const { requestId, original } = input;
|
|
4966
|
+
if (!validSessionControlOriginal(original) || original.body.requestId !== requestId) throw new ProtocolDataError("Invalid original control request");
|
|
4967
|
+
const result = await transport.request(
|
|
4968
|
+
`${path2}/control-result`,
|
|
4969
|
+
{
|
|
4970
|
+
method: "POST",
|
|
4971
|
+
body: { requestId, original },
|
|
4972
|
+
signal: options.signal
|
|
4973
|
+
}
|
|
4974
|
+
);
|
|
4975
|
+
if (!validSessionControlResult("sessions.getControlResult", result) || result && (result.sessionId !== sessionId || result.requestId !== requestId || result.action !== original.action || original.action === "fork" && result.targetSessionId !== original.body.id))
|
|
4976
|
+
throw new ProtocolDataError(
|
|
4977
|
+
"Control receipt does not match original request"
|
|
4978
|
+
);
|
|
4979
|
+
return result;
|
|
4980
|
+
},
|
|
4981
|
+
/** Current context assembly requires execution authority; /usage is historical billing. */
|
|
4982
|
+
async getContextUsage(options = {}) {
|
|
4983
|
+
return transport.request(
|
|
4984
|
+
`${path2}/context-usage`,
|
|
4985
|
+
{ signal: options.signal }
|
|
4986
|
+
);
|
|
4987
|
+
},
|
|
4988
|
+
/** `GET /sessions/:id/usage` */
|
|
4989
|
+
async getUsage(options = {}) {
|
|
4990
|
+
return transport.request(
|
|
4991
|
+
`${path2}/usage`,
|
|
4992
|
+
{ signal: options.signal }
|
|
4993
|
+
);
|
|
4994
|
+
},
|
|
4995
|
+
/** `POST /sessions/:id/prompts/latest/edit` */
|
|
4996
|
+
editLatestPrompt(input, options = {}) {
|
|
4997
|
+
return editLatestPrompt(transport, sessionId, input, options);
|
|
4998
|
+
},
|
|
4999
|
+
/**
|
|
5000
|
+
* `POST /sessions/:id/runs/:runId/resume` — 显式重放一次中断 run 的原始 prompt。
|
|
5001
|
+
* 服务端复用原 Input,创建一个带恢复来源的新 Run。旧模型连接已经结束。
|
|
5002
|
+
*/
|
|
5003
|
+
resumeInterruptedRun(runId, input = {}, options = {}) {
|
|
5004
|
+
return resumeInterruptedRun(transport, sessionId, runId, input, options);
|
|
5005
|
+
},
|
|
5006
|
+
/** `POST /sessions/:id/fork` */
|
|
5007
|
+
async fork(input = {}, options = {}) {
|
|
5008
|
+
const response = await transport.request(
|
|
5009
|
+
`${path2}/fork`,
|
|
5010
|
+
{
|
|
5011
|
+
method: "POST",
|
|
5012
|
+
body: parseForkSessionRequest({
|
|
5013
|
+
...input,
|
|
5014
|
+
id: input.id ?? createSessionRequestId(),
|
|
5015
|
+
requestId: input.requestId ?? createSessionRequestId()
|
|
5016
|
+
}),
|
|
5017
|
+
signal: options.signal
|
|
5018
|
+
}
|
|
5019
|
+
);
|
|
5020
|
+
return response.session;
|
|
5021
|
+
},
|
|
5022
|
+
/** `POST /sessions/:id/compact` */
|
|
5023
|
+
async compact(input, options) {
|
|
5024
|
+
const body = { ...input };
|
|
5025
|
+
if (!validSessionControlOriginal({ action: "compact", body }))
|
|
5026
|
+
throw new ProtocolDataError("Invalid original compact request");
|
|
5027
|
+
const result = await transport.request(
|
|
5028
|
+
`${path2}/compact`,
|
|
5029
|
+
{ method: "POST", body, signal: options?.signal }
|
|
5030
|
+
);
|
|
5031
|
+
if (!validSessionControlResult("sessions.getControlResult", result) || !result || result.action !== "compact" || result.sessionId !== sessionId || result.requestId !== body.requestId || result.revision !== body.expectedRevision) throw new ProtocolDataError("Compact receipt does not match original request");
|
|
5032
|
+
return result;
|
|
5033
|
+
},
|
|
5034
|
+
/** `POST /sessions/:id/rewind` */
|
|
5035
|
+
async rewind(input = {}, options = {}) {
|
|
5036
|
+
return transport.request(
|
|
5037
|
+
`${path2}/rewind`,
|
|
5038
|
+
{ method: "POST", body: input, signal: options.signal }
|
|
5039
|
+
);
|
|
5040
|
+
},
|
|
5041
|
+
/** `POST /sessions/:id/remember` */
|
|
5042
|
+
async remember(options = {}) {
|
|
5043
|
+
return transport.request(
|
|
5044
|
+
`${path2}/remember`,
|
|
5045
|
+
{ method: "POST", signal: options.signal }
|
|
5046
|
+
);
|
|
5047
|
+
},
|
|
5048
|
+
/** `POST /sessions/:id/export` */
|
|
5049
|
+
async export(input = {}, options = {}) {
|
|
5050
|
+
return transport.request(
|
|
5051
|
+
`${path2}/export`,
|
|
5052
|
+
{ method: "POST", body: input, signal: options.signal }
|
|
5053
|
+
);
|
|
5054
|
+
},
|
|
5055
|
+
configuration: {
|
|
5056
|
+
get(options = {}) {
|
|
5057
|
+
return getConfiguration(transport, sessionId, options);
|
|
5058
|
+
},
|
|
5059
|
+
update(input, options = {}) {
|
|
5060
|
+
return configure(transport, sessionId, input, options);
|
|
5061
|
+
},
|
|
5062
|
+
getResult(input, options = {}) {
|
|
5063
|
+
return getConfigurationResult(transport, sessionId, input, options);
|
|
5064
|
+
}
|
|
5065
|
+
},
|
|
5066
|
+
queue: {
|
|
5067
|
+
/** Promote one durable queued prompt into the exact active run. */
|
|
5068
|
+
promote(inputId, input, options = {}) {
|
|
5069
|
+
return promoteQueuedPrompt(transport, sessionId, inputId, input, options);
|
|
5070
|
+
},
|
|
5071
|
+
cancel: cancelQueuedPrompt2
|
|
5072
|
+
},
|
|
5073
|
+
goal: {
|
|
5074
|
+
/** `GET /sessions/:id/goal` */
|
|
5075
|
+
async get() {
|
|
5076
|
+
const response = await transport.request(
|
|
5077
|
+
`${path2}/goal`
|
|
5078
|
+
);
|
|
5079
|
+
return response.goal;
|
|
5080
|
+
},
|
|
5081
|
+
/** `POST /sessions/:id/goals` */
|
|
5082
|
+
async create(input) {
|
|
5083
|
+
return saveGoal(`${path2}/goals`, "POST", input);
|
|
5084
|
+
},
|
|
5085
|
+
/** `PATCH /sessions/:id/goals/:goalId` */
|
|
5086
|
+
async update(goalId, input) {
|
|
5087
|
+
return saveGoal(`${path2}/goals/${encodeURIComponent(goalId)}`, "PATCH", input);
|
|
5088
|
+
},
|
|
5089
|
+
/** `POST /sessions/:id/goals/:goalId/actions` */
|
|
5090
|
+
async applyAction(goalId, input) {
|
|
5091
|
+
return saveGoal(`${path2}/goals/${encodeURIComponent(goalId)}/actions`, "POST", input);
|
|
5092
|
+
},
|
|
5093
|
+
/** Reads the original durable action receipt after a response was lost. */
|
|
5094
|
+
async getRequest(requestId) {
|
|
5095
|
+
const receipt2 = decodeSessionGoalRequestReceipt(
|
|
5096
|
+
await transport.request(
|
|
5097
|
+
`${path2}/goal/requests/${encodeURIComponent(requestId)}`
|
|
5098
|
+
)
|
|
5099
|
+
);
|
|
5100
|
+
if (receipt2.sessionId !== sessionId || receipt2.requestId !== requestId)
|
|
5101
|
+
throw new ProtocolDataError(
|
|
5102
|
+
"Goal request receipt does not match request"
|
|
5103
|
+
);
|
|
5104
|
+
return receipt2;
|
|
5105
|
+
}
|
|
5106
|
+
},
|
|
5107
|
+
messages: {
|
|
5108
|
+
/** `GET /sessions/:id/messages` */
|
|
5109
|
+
async list(options = {}) {
|
|
5110
|
+
const { signal, ...query } = options;
|
|
5111
|
+
const response = await transport.request(
|
|
5112
|
+
transport.path(
|
|
5113
|
+
`${path2}/messages`,
|
|
5114
|
+
query
|
|
5115
|
+
),
|
|
5116
|
+
{ signal }
|
|
5117
|
+
);
|
|
5118
|
+
return response.messages;
|
|
5119
|
+
},
|
|
5120
|
+
/** `GET /sessions/:id/parts` */
|
|
5121
|
+
async listParts(options = {}) {
|
|
5122
|
+
const { signal, ...query } = options;
|
|
5123
|
+
const response = await transport.request(
|
|
5124
|
+
transport.path(
|
|
5125
|
+
`${path2}/parts`,
|
|
5126
|
+
query
|
|
5127
|
+
),
|
|
5128
|
+
{ signal }
|
|
5129
|
+
);
|
|
5130
|
+
return response.parts;
|
|
5131
|
+
},
|
|
5132
|
+
/** Read full canonical content for one part in its session/message scope. */
|
|
5133
|
+
async getPart(messageId, partId, options = {}) {
|
|
5134
|
+
const response = await transport.request(
|
|
5135
|
+
`${path2}/messages/${encodeURIComponent(messageId)}/parts/${encodeURIComponent(partId)}`,
|
|
5136
|
+
options
|
|
5137
|
+
);
|
|
5138
|
+
return response.part;
|
|
5139
|
+
}
|
|
5140
|
+
},
|
|
5141
|
+
management: {
|
|
5142
|
+
async archiveAndInterrupt(options) {
|
|
5143
|
+
const response = await transport.request(path2, { ...options, method: "DELETE" });
|
|
5144
|
+
return response.session;
|
|
5145
|
+
},
|
|
5146
|
+
getRevision: management.getRevision.bind(management, sessionId),
|
|
5147
|
+
rename: management.rename.bind(management, sessionId),
|
|
5148
|
+
setPinned: management.setPinned.bind(management, sessionId),
|
|
5149
|
+
archive: management.archive.bind(management, sessionId),
|
|
5150
|
+
delete: management.delete.bind(management, sessionId),
|
|
5151
|
+
getMutation: management.getMutation.bind(management, sessionId)
|
|
5152
|
+
},
|
|
5153
|
+
files: new FilesResource(transport, sessionId),
|
|
5154
|
+
terminals: new SessionTerminalResource(transport, sessionId),
|
|
5155
|
+
jobs: new JobResource(transport, sessionId),
|
|
5156
|
+
mcp: {
|
|
5157
|
+
async list(options) {
|
|
5158
|
+
const response = await transport.request(`${path2}/mcp`, options);
|
|
5159
|
+
return response.servers;
|
|
5160
|
+
}
|
|
5161
|
+
}
|
|
5162
|
+
};
|
|
5163
|
+
}
|
|
5164
|
+
|
|
5165
|
+
// src/resources/session/session-resource.ts
|
|
5166
|
+
var SessionResource = class {
|
|
5167
|
+
#management;
|
|
5168
|
+
#events;
|
|
5169
|
+
#transport;
|
|
5170
|
+
constructor(transport, events) {
|
|
5171
|
+
this.#transport = transport;
|
|
5172
|
+
this.#management = new SessionManagementResource(transport);
|
|
5173
|
+
this.#events = events ?? new EventResource(transport, new SseTransport(transport));
|
|
5174
|
+
}
|
|
5175
|
+
/** Bind a session ID locally. Operations use this resource's daemon connection when called. */
|
|
5176
|
+
byId(sessionId) {
|
|
5177
|
+
return createSessionHandle(this.#transport, { sessions: this, events: this.#events }, this.#management, sessionId);
|
|
5178
|
+
}
|
|
5179
|
+
/** `GET /sessions/search` - search saved conversation text without opening it. */
|
|
5180
|
+
async search(options) {
|
|
5181
|
+
const { signal, ...query } = options;
|
|
5182
|
+
const response = await this.#transport.request(this.#transport.path("/sessions/search", query), { signal });
|
|
5183
|
+
return response.results;
|
|
5184
|
+
}
|
|
5185
|
+
/** `GET /sessions` */
|
|
5186
|
+
async list(options = {}) {
|
|
5187
|
+
const { signal, ...query } = options;
|
|
5188
|
+
const response = await this.#transport.request(this.#transport.path("/sessions", query), { signal });
|
|
5189
|
+
return response.sessions;
|
|
4248
5190
|
}
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
return
|
|
5191
|
+
listDirectory(options = {}) {
|
|
5192
|
+
const { signal, ...query } = options;
|
|
5193
|
+
return this.#transport.request(
|
|
5194
|
+
this.#transport.path("/sessions/directory", query),
|
|
5195
|
+
{ signal }
|
|
5196
|
+
);
|
|
4252
5197
|
}
|
|
4253
|
-
|
|
4254
|
-
|
|
4255
|
-
|
|
5198
|
+
getActivity(options = {}) {
|
|
5199
|
+
return this.#transport.request("/sessions/activity", {
|
|
5200
|
+
signal: options.signal
|
|
5201
|
+
});
|
|
4256
5202
|
}
|
|
4257
|
-
|
|
4258
|
-
return
|
|
5203
|
+
getDraftComposerOptions(input, options = {}) {
|
|
5204
|
+
return getDraftComposerOptions(this.#transport, input, options);
|
|
4259
5205
|
}
|
|
4260
|
-
/**
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
*/
|
|
4264
|
-
resumeInterruptedRun(sessionId, runId, input = {}, options = {}) {
|
|
4265
|
-
return resumeInterruptedRun(this.transport, sessionId, runId, input, options);
|
|
5206
|
+
/** `POST /sessions` */
|
|
5207
|
+
create(input, options = {}) {
|
|
5208
|
+
return create(this.#transport, input, options);
|
|
4266
5209
|
}
|
|
4267
|
-
|
|
4268
|
-
|
|
4269
|
-
return interrupt(this.transport, sessionId, options);
|
|
5210
|
+
getConfigurationOptions(input, options = {}) {
|
|
5211
|
+
return getConfigurationOptions(this.#transport, input, options);
|
|
4270
5212
|
}
|
|
4271
|
-
|
|
4272
|
-
|
|
4273
|
-
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
|
|
4277
|
-
|
|
4278
|
-
|
|
4279
|
-
|
|
4280
|
-
|
|
4281
|
-
|
|
4282
|
-
|
|
4283
|
-
|
|
5213
|
+
getCreationResult(input, options = {}) {
|
|
5214
|
+
return getCreationResult(this.#transport, input, options);
|
|
5215
|
+
}
|
|
5216
|
+
};
|
|
5217
|
+
|
|
5218
|
+
// src/resources/session/attachment-resource.ts
|
|
5219
|
+
var AttachmentResource = class {
|
|
5220
|
+
constructor(transport) {
|
|
5221
|
+
this.transport = transport;
|
|
5222
|
+
}
|
|
5223
|
+
transport;
|
|
5224
|
+
/** Manage daemon attachment storage. Ordinary session connections cannot use these methods. */
|
|
5225
|
+
storage = {
|
|
5226
|
+
scan: (options) => this.transport.request("/attachments/storage", options),
|
|
5227
|
+
repair: (options) => this.transport.request("/attachments/storage/actions", { ...options, method: "POST", body: { action: "repair-safe" } }),
|
|
5228
|
+
gc: (options) => this.transport.request("/attachments/storage/actions", { ...options, method: "POST", body: { action: "gc" } })
|
|
5229
|
+
};
|
|
5230
|
+
/** `POST /attachments` — upload bytes without JSON or multipart buffering. */
|
|
5231
|
+
async upload(input) {
|
|
5232
|
+
const headers2 = uploadIdentityHeaders(input);
|
|
5233
|
+
headers2["x-bobannomi-filename"] = encodeURIComponent(input.displayName);
|
|
5234
|
+
if (input.mediaType) headers2["content-type"] = input.mediaType;
|
|
5235
|
+
const response = await this.transport.requestResponse("/attachments", {
|
|
5236
|
+
method: "POST",
|
|
5237
|
+
headers: headers2,
|
|
5238
|
+
body: input.body,
|
|
5239
|
+
signal: input.signal
|
|
5240
|
+
});
|
|
5241
|
+
return parseAttachmentAssetRecord(await response.json());
|
|
5242
|
+
}
|
|
5243
|
+
async getUpload(input) {
|
|
5244
|
+
const response = await this.transport.requestResponse("/attachments/uploads", { headers: uploadIdentityHeaders(input), signal: input.signal });
|
|
5245
|
+
const value = await response.json();
|
|
5246
|
+
return value === null ? null : parseAttachmentAssetRecord(value);
|
|
5247
|
+
}
|
|
5248
|
+
async get(id2, options = {}) {
|
|
5249
|
+
const value = await this.transport.request(
|
|
5250
|
+
`/attachments/${encodeURIComponent(id2)}`,
|
|
5251
|
+
{ signal: options.signal }
|
|
5252
|
+
);
|
|
5253
|
+
return parseAttachmentAssetRecord(value);
|
|
5254
|
+
}
|
|
5255
|
+
/** Returns the raw response so callers can consume the body as a stream. */
|
|
5256
|
+
async download(id2, options = {}) {
|
|
5257
|
+
const range = attachmentRangeHeader(options.range);
|
|
5258
|
+
const headers2 = {};
|
|
5259
|
+
if (range) headers2.range = range;
|
|
5260
|
+
return await this.transport.requestResponse(
|
|
5261
|
+
`/attachments/${encodeURIComponent(id2)}/content`,
|
|
5262
|
+
{ method: "GET", headers: headers2, signal: options.signal }
|
|
5263
|
+
);
|
|
5264
|
+
}
|
|
5265
|
+
async delete(id2, options = {}) {
|
|
5266
|
+
const value = await this.transport.request(
|
|
5267
|
+
`/attachments/${encodeURIComponent(id2)}`,
|
|
5268
|
+
{ method: "DELETE", signal: options.signal }
|
|
5269
|
+
);
|
|
5270
|
+
return parseAttachmentAssetRecord(value);
|
|
5271
|
+
}
|
|
5272
|
+
};
|
|
5273
|
+
function uploadIdentityHeaders(input) {
|
|
5274
|
+
parseAttachmentUploadRequest({ ...input, declaredMediaType: input.mediaType });
|
|
5275
|
+
return { "x-bobannomi-request-id": input.requestId, "x-bobannomi-draft-id": input.draftId, "x-bobannomi-sha256": input.expectedSha256, "x-bobannomi-byte-length": String(input.byteLength), "x-bobannomi-filename": encodeURIComponent(input.displayName), ...input.mediaType ? { "content-type": input.mediaType } : {} };
|
|
5276
|
+
}
|
|
5277
|
+
|
|
5278
|
+
// src/resources/configuration/permission-resource.ts
|
|
5279
|
+
var PermissionResource = class {
|
|
5280
|
+
#transport;
|
|
5281
|
+
constructor(transport) {
|
|
5282
|
+
this.#transport = transport;
|
|
5283
|
+
}
|
|
5284
|
+
requests = {
|
|
5285
|
+
/** `GET /permissions` */
|
|
5286
|
+
list: async (options = {}) => {
|
|
5287
|
+
const { signal, ...query } = options;
|
|
5288
|
+
const response = await this.#transport.request(this.#transport.path("/permissions", query), { signal });
|
|
5289
|
+
return response.requests;
|
|
5290
|
+
},
|
|
5291
|
+
/** `POST /permissions/:id/reply` — 批准/拒绝工具权限请求。 */
|
|
5292
|
+
reply: async (requestId, input, options = {}) => {
|
|
5293
|
+
const response = await this.#transport.request(
|
|
5294
|
+
`/permissions/${encodeURIComponent(requestId)}/reply`,
|
|
5295
|
+
{
|
|
5296
|
+
method: "POST",
|
|
5297
|
+
body: input,
|
|
5298
|
+
signal: options.signal
|
|
5299
|
+
}
|
|
5300
|
+
);
|
|
5301
|
+
return response.request;
|
|
5302
|
+
},
|
|
5303
|
+
/** Answer an actual AskUser question; this cannot approve tools. */
|
|
5304
|
+
answerQuestion: async (requestId, input, options = {}) => {
|
|
5305
|
+
const capabilities = await this.#transport.ensureProtocol(options.signal);
|
|
5306
|
+
if ((capabilities.features.questions ?? 0) < 1) throw new Error("Server does not support questions");
|
|
5307
|
+
const response = await this.#transport.request(
|
|
5308
|
+
`/permissions/${encodeURIComponent(requestId)}/answer`,
|
|
5309
|
+
{ method: "POST", body: input, signal: options.signal }
|
|
5310
|
+
);
|
|
5311
|
+
return response.request;
|
|
5312
|
+
}
|
|
5313
|
+
};
|
|
5314
|
+
approvals = {
|
|
5315
|
+
list: async () => {
|
|
5316
|
+
const response = await this.#transport.request("/permissions/approvals");
|
|
5317
|
+
return response.requests;
|
|
5318
|
+
},
|
|
5319
|
+
revoke: async (requestId) => {
|
|
5320
|
+
const response = await this.#transport.request(
|
|
5321
|
+
`/permissions/${encodeURIComponent(requestId)}/revoke`,
|
|
5322
|
+
{ method: "POST" }
|
|
5323
|
+
);
|
|
5324
|
+
return response.request;
|
|
5325
|
+
}
|
|
5326
|
+
};
|
|
5327
|
+
};
|
|
5328
|
+
|
|
5329
|
+
// src/resources/runtime/runtime-resource.ts
|
|
5330
|
+
function createRuntimeResources(transport, providers) {
|
|
5331
|
+
const catalog = typeof providers === "function" || providers === void 0 ? providers : structuredClone([...providers]);
|
|
5332
|
+
async function modelProviders(input, options = {}) {
|
|
5333
|
+
const response = await transport.request("/providers/manage", { ...options, method: "POST", body: input });
|
|
5334
|
+
if (!validModelProviderConnections(response?.providers)) throw new Error("Invalid model provider response");
|
|
5335
|
+
return response.providers;
|
|
5336
|
+
}
|
|
5337
|
+
async function providerDefaults(input, options = {}) {
|
|
5338
|
+
const result = await transport.request("/providers/defaults", { ...options, method: "POST", body: input });
|
|
5339
|
+
const valid = input.action === "test" ? validProviderConnectionTestResult(result) : validProviderDefaultsSnapshot(result);
|
|
5340
|
+
if (!valid) throw new Error("Invalid provider defaults response");
|
|
5341
|
+
return result;
|
|
5342
|
+
}
|
|
5343
|
+
return {
|
|
5344
|
+
models: {
|
|
5345
|
+
async list({ signal } = {}) {
|
|
5346
|
+
if (catalog === void 0) {
|
|
5347
|
+
const response = await transport.request("/models", { signal });
|
|
5348
|
+
return response.providers;
|
|
5349
|
+
}
|
|
5350
|
+
signal?.throwIfAborted();
|
|
5351
|
+
const providers2 = typeof catalog === "function" ? await waitForRequest(Promise.resolve().then(() => {
|
|
5352
|
+
signal?.throwIfAborted();
|
|
5353
|
+
return catalog({ signal });
|
|
5354
|
+
}), signal) : catalog;
|
|
5355
|
+
signal?.throwIfAborted();
|
|
5356
|
+
return structuredClone([...providers2]);
|
|
4284
5357
|
}
|
|
5358
|
+
},
|
|
5359
|
+
agents: {
|
|
5360
|
+
async list(options) {
|
|
5361
|
+
const response = await transport.request("/agent-personas", options);
|
|
5362
|
+
return response.agents;
|
|
5363
|
+
}
|
|
5364
|
+
},
|
|
5365
|
+
skills: {
|
|
5366
|
+
list: (options) => transport.request("/skills", options),
|
|
5367
|
+
marketplace: {
|
|
5368
|
+
list: (options) => transport.request("/skills/marketplace", options),
|
|
5369
|
+
install: (body, options) => transport.request("/skills/marketplace/install", { ...options, method: "POST", body })
|
|
5370
|
+
},
|
|
5371
|
+
remove: (id2, body, options) => transport.request(`/skills/${encodeURIComponent(id2)}`, { ...options, method: "DELETE", body })
|
|
5372
|
+
},
|
|
5373
|
+
modelProviders: {
|
|
5374
|
+
/** Provider catalog including non-connected providers. See list() for management status. */
|
|
5375
|
+
async catalog(options) {
|
|
5376
|
+
const response = await transport.request("/providers", options);
|
|
5377
|
+
return response.providers;
|
|
5378
|
+
},
|
|
5379
|
+
auth: {
|
|
5380
|
+
async status(options) {
|
|
5381
|
+
const response = await transport.request("/auth", options);
|
|
5382
|
+
return response.auth;
|
|
5383
|
+
},
|
|
5384
|
+
login: (body, options) => transport.request("/auth/login", { ...options, method: "POST", body }),
|
|
5385
|
+
logout: (body, options) => transport.request("/auth/logout", { ...options, method: "POST", body })
|
|
5386
|
+
},
|
|
5387
|
+
list: (options) => modelProviders({ action: "list" }, options),
|
|
5388
|
+
refresh: (options) => modelProviders({ action: "refresh" }, options),
|
|
5389
|
+
connect: (input, options) => modelProviders({ ...input, action: "connect" }, options),
|
|
5390
|
+
updateHeaders: (input, options) => modelProviders({ ...input, action: "updateHeaders" }, options),
|
|
5391
|
+
createCustom: (input, options) => modelProviders({ ...input, action: "createCustom" }, options),
|
|
5392
|
+
syncAccount: (input, options) => modelProviders({ ...input, action: "syncAccount" }, options),
|
|
5393
|
+
updateCustom: (input, options) => modelProviders({ ...input, action: "updateCustom" }, options),
|
|
5394
|
+
disconnect: (input, options) => modelProviders({ ...input, action: "disconnect" }, options),
|
|
5395
|
+
removeCustom: (input, options) => modelProviders({ ...input, action: "removeCustom" }, options),
|
|
5396
|
+
defaults: {
|
|
5397
|
+
get: ({ accountGatewayProof, signal } = {}) => providerDefaults({ action: "snapshot", accountGatewayProof }, { signal }),
|
|
5398
|
+
updateModel: (input, options) => providerDefaults({ ...input, action: "updateModel" }, options),
|
|
5399
|
+
updateEffort: (input, options) => providerDefaults({ ...input, action: "updateEffort" }, options),
|
|
5400
|
+
test: (input, options) => providerDefaults({ ...input, action: "test" }, options)
|
|
5401
|
+
}
|
|
5402
|
+
}
|
|
5403
|
+
};
|
|
5404
|
+
}
|
|
5405
|
+
|
|
5406
|
+
// src/resources/plugins/plugin-marketplace-resource.ts
|
|
5407
|
+
var market = "/plugins/marketplace";
|
|
5408
|
+
var PluginMarketplaceResource = class {
|
|
5409
|
+
constructor(transport) {
|
|
5410
|
+
this.transport = transport;
|
|
5411
|
+
}
|
|
5412
|
+
transport;
|
|
5413
|
+
catalog({ signal, ...query }) {
|
|
5414
|
+
return this.transport.request(`${market}/catalog`, { query, signal });
|
|
5415
|
+
}
|
|
5416
|
+
listSources(options) {
|
|
5417
|
+
return this.transport.request(`${market}/sources`, options);
|
|
5418
|
+
}
|
|
5419
|
+
addSource(input, options) {
|
|
5420
|
+
return this.transport.request(`${market}/sources`, { ...options, method: "POST", body: input });
|
|
5421
|
+
}
|
|
5422
|
+
setSourceEnabled(sourceId, input, options) {
|
|
5423
|
+
return this.transport.request(`${market}/sources/${encodeURIComponent(sourceId)}`, { ...options, method: "PATCH", body: input });
|
|
5424
|
+
}
|
|
5425
|
+
removeSource(sourceId, options) {
|
|
5426
|
+
return this.transport.request(`${market}/sources/${encodeURIComponent(sourceId)}`, { ...options, method: "DELETE" });
|
|
5427
|
+
}
|
|
5428
|
+
preview(input, options) {
|
|
5429
|
+
return this.transport.request(`${market}/preview`, { ...options, method: "POST", body: input });
|
|
5430
|
+
}
|
|
5431
|
+
cancel(input, options) {
|
|
5432
|
+
return this.transport.request(`${market}/cancel`, { ...options, method: "POST", body: input });
|
|
5433
|
+
}
|
|
5434
|
+
/** Save the operation ID before submitting. Recover an uncertain result with getOperation. */
|
|
5435
|
+
async install(input, options) {
|
|
5436
|
+
const { operationId } = input;
|
|
5437
|
+
const receipt2 = await this.transport.request(`${market}/install`, { ...options, method: "POST", body: input });
|
|
5438
|
+
return matchingOperation(receipt2, operationId);
|
|
5439
|
+
}
|
|
5440
|
+
/** Look up the original operation without repeating its install. */
|
|
5441
|
+
async getOperation(operationId, options) {
|
|
5442
|
+
const receipt2 = await this.transport.request(`${market}/operations/${encodeURIComponent(operationId)}`, options);
|
|
5443
|
+
return matchingOperation(receipt2, operationId);
|
|
5444
|
+
}
|
|
5445
|
+
};
|
|
5446
|
+
function matchingOperation(receipt2, operationId) {
|
|
5447
|
+
if (receipt2?.operationId !== operationId) {
|
|
5448
|
+
throw new ProtocolDataError("Marketplace receipt does not match original operation", "operationId");
|
|
5449
|
+
}
|
|
5450
|
+
return receipt2;
|
|
5451
|
+
}
|
|
5452
|
+
|
|
5453
|
+
// src/resources/plugins/plugin-resource.ts
|
|
5454
|
+
var PluginResource = class {
|
|
5455
|
+
constructor(transport) {
|
|
5456
|
+
this.transport = transport;
|
|
5457
|
+
this.marketplace = new PluginMarketplaceResource(transport);
|
|
5458
|
+
}
|
|
5459
|
+
transport;
|
|
5460
|
+
marketplace;
|
|
5461
|
+
/** List native plugins for a directory in the daemon environment. */
|
|
5462
|
+
list({ signal, cwd }) {
|
|
5463
|
+
return this.transport.request("/plugins", { query: { cwd }, signal });
|
|
5464
|
+
}
|
|
5465
|
+
enable(id2, input, options) {
|
|
5466
|
+
return this.transport.request(`/plugins/${encodeURIComponent(id2)}/enable`, { ...options, method: "POST", body: input });
|
|
5467
|
+
}
|
|
5468
|
+
disable(id2, input, options) {
|
|
5469
|
+
return this.transport.request(`/plugins/${encodeURIComponent(id2)}/disable`, { ...options, method: "POST", body: input });
|
|
5470
|
+
}
|
|
5471
|
+
/** Read the identity, digest and requested permissions for a directory on the daemon machine. */
|
|
5472
|
+
async previewLocal(input, options) {
|
|
5473
|
+
await requireDaemonFeature(this.transport, "pluginLocalPreview", options?.signal);
|
|
5474
|
+
const preview = await this.transport.request("/plugins/local/preview", { ...options, method: "POST", body: input });
|
|
5475
|
+
if (typeof preview?.sourceDigest !== "string" || !/^[a-f0-9]{64}$/.test(preview.sourceDigest)) {
|
|
5476
|
+
throw new ProtocolDataError("Plugin directory preview must include a SHA-256 digest", "sourceDigest");
|
|
5477
|
+
}
|
|
5478
|
+
return preview;
|
|
5479
|
+
}
|
|
5480
|
+
/** Install or link a plugin directory the daemon can read after approval. */
|
|
5481
|
+
async installLocal(input, options) {
|
|
5482
|
+
if (input.expectedSourceDigest !== void 0 || input.allowSourceChange === true) {
|
|
5483
|
+
await requireDaemonFeature(this.transport, "pluginLocalPreview", options?.signal);
|
|
5484
|
+
}
|
|
5485
|
+
return this.transport.request(input.link ? "/plugins/link-local" : "/plugins/install-local", { ...options, method: "POST", body: input });
|
|
5486
|
+
}
|
|
5487
|
+
/** Read the digest and required permissions for an archive on the daemon machine. */
|
|
5488
|
+
previewArchive(input, options) {
|
|
5489
|
+
return this.transport.request("/plugins/archive/preview", { ...options, method: "POST", body: input });
|
|
5490
|
+
}
|
|
5491
|
+
/** Install the previewed archive with its original digest and approved permissions. */
|
|
5492
|
+
installArchive(input, options) {
|
|
5493
|
+
return this.transport.request("/plugins/archive/install", { ...options, method: "POST", body: input });
|
|
5494
|
+
}
|
|
5495
|
+
/** Read the digest and required permissions for a Git source. */
|
|
5496
|
+
previewGit(input, options) {
|
|
5497
|
+
return this.transport.request("/plugins/git/preview", { ...options, method: "POST", body: input });
|
|
5498
|
+
}
|
|
5499
|
+
/** Install the previewed Git source with its original digest and approved permissions. */
|
|
5500
|
+
installGit(input, options) {
|
|
5501
|
+
return this.transport.request("/plugins/git/install", { ...options, method: "POST", body: input });
|
|
5502
|
+
}
|
|
5503
|
+
uninstall(id2, input, options) {
|
|
5504
|
+
return this.transport.request(`/plugins/${encodeURIComponent(id2)}`, { ...options, method: "DELETE", body: input });
|
|
5505
|
+
}
|
|
5506
|
+
reload(input, options) {
|
|
5507
|
+
return this.transport.request("/plugins/reload", { ...options, method: "POST", body: input });
|
|
5508
|
+
}
|
|
5509
|
+
};
|
|
5510
|
+
|
|
5511
|
+
// src/resources/channels/channel-resource.ts
|
|
5512
|
+
var ChannelResource = class {
|
|
5513
|
+
constructor(transport) {
|
|
5514
|
+
this.transport = transport;
|
|
5515
|
+
}
|
|
5516
|
+
transport;
|
|
5517
|
+
/** Read the running connectors or temporarily start and stop them. */
|
|
5518
|
+
runtime = {
|
|
5519
|
+
status: (options) => this.transport.request("/channels/runtime/status", options),
|
|
5520
|
+
start: (input = {}, options) => this.transport.request("/channels/runtime/start", { ...options, method: "POST", body: input }),
|
|
5521
|
+
stop: (input = {}, options) => this.transport.request("/channels/runtime/stop", { ...options, method: "POST", body: input })
|
|
5522
|
+
};
|
|
5523
|
+
/** Configure Feishu or Lark. Status snapshots omit credentials. */
|
|
5524
|
+
feishu = {
|
|
5525
|
+
status: (options) => this.transport.request("/channels/feishu", options),
|
|
5526
|
+
connect: (input, options) => this.transport.request("/channels/feishu/connect", { ...options, method: "POST", body: input }),
|
|
5527
|
+
update: (input, options) => this.transport.request("/channels/feishu", { ...options, method: "PATCH", body: input }),
|
|
5528
|
+
disconnect: (options) => this.transport.request("/channels/feishu", { ...options, method: "DELETE" }),
|
|
5529
|
+
allowlist: {
|
|
5530
|
+
add: (input, options) => this.transport.request("/channels/feishu/allow", { ...options, method: "POST", body: input }),
|
|
5531
|
+
remove: (key, options) => this.transport.request(`/channels/feishu/allow/${encodeURIComponent(key)}`, { ...options, method: "DELETE" })
|
|
5532
|
+
},
|
|
5533
|
+
registration: {
|
|
5534
|
+
start: (input = {}, options) => this.transport.request("/channels/feishu/registration", { ...options, method: "POST", body: input }),
|
|
5535
|
+
status: (options) => this.transport.request("/channels/feishu/registration", options),
|
|
5536
|
+
cancel: (options) => this.transport.request("/channels/feishu/registration", { ...options, method: "DELETE" })
|
|
5537
|
+
}
|
|
5538
|
+
};
|
|
5539
|
+
/** Submit external messages and work with durable delivery records. */
|
|
5540
|
+
connector = {
|
|
5541
|
+
/** Retain the external message ID when retrying the same input. */
|
|
5542
|
+
submitMessage: (input, options) => this.transport.request("/channels/messages", { ...options, method: "POST", body: input }),
|
|
5543
|
+
status: (query, options) => this.transport.request("/channels/status", { ...options, query: { ...query } }),
|
|
5544
|
+
listPendingDeliveries: async (query, options) => {
|
|
5545
|
+
const response = await this.transport.request(
|
|
5546
|
+
"/channels/deliveries/pending",
|
|
5547
|
+
{ ...options, query: { ...query } }
|
|
5548
|
+
);
|
|
5549
|
+
return response.deliveries;
|
|
5550
|
+
},
|
|
5551
|
+
/** Look up the stored result after an interrupted request. Returns null for an unknown ID. */
|
|
5552
|
+
getDelivery: async (deliveryId, options) => {
|
|
5553
|
+
await requireDaemonFeature(this.transport, "channelDeliveryLookup", options?.signal);
|
|
5554
|
+
const response = await this.transport.request(
|
|
5555
|
+
`/channels/deliveries/${encodeURIComponent(deliveryId)}/result`,
|
|
5556
|
+
options
|
|
5557
|
+
);
|
|
5558
|
+
return response.delivery;
|
|
5559
|
+
},
|
|
5560
|
+
recordDelivery: async (deliveryId, input, options) => {
|
|
5561
|
+
const response = await this.transport.request(
|
|
5562
|
+
`/channels/deliveries/${encodeURIComponent(deliveryId)}/result`,
|
|
5563
|
+
{ ...options, method: "POST", body: input }
|
|
5564
|
+
);
|
|
5565
|
+
return response.delivery;
|
|
5566
|
+
}
|
|
5567
|
+
};
|
|
5568
|
+
};
|
|
5569
|
+
|
|
5570
|
+
// src/resources/workspace/project-resource.ts
|
|
5571
|
+
var ProjectResource = class {
|
|
5572
|
+
constructor(transport) {
|
|
5573
|
+
this.transport = transport;
|
|
5574
|
+
}
|
|
5575
|
+
transport;
|
|
5576
|
+
/** `GET /projects` */
|
|
5577
|
+
async list(options = {}) {
|
|
5578
|
+
const { signal, ...query } = options;
|
|
5579
|
+
const response = await this.transport.request(
|
|
5580
|
+
this.transport.path("/projects", query),
|
|
5581
|
+
{ signal }
|
|
5582
|
+
);
|
|
5583
|
+
return response.projects;
|
|
5584
|
+
}
|
|
5585
|
+
/** Register or reopen a directory on the daemon host and update its last-opened time. */
|
|
5586
|
+
async register(path2, options) {
|
|
5587
|
+
return (await this.transport.request("/projects/inspect", {
|
|
5588
|
+
...options,
|
|
5589
|
+
method: "POST",
|
|
5590
|
+
body: { path: path2 }
|
|
5591
|
+
})).project;
|
|
5592
|
+
}
|
|
5593
|
+
/** Alias for register. This can create or restore a project record. */
|
|
5594
|
+
inspect(path2, options) {
|
|
5595
|
+
return this.register(path2, options);
|
|
5596
|
+
}
|
|
5597
|
+
/** `PATCH /projects/:id` (name) */
|
|
5598
|
+
async rename(projectId, name, options) {
|
|
5599
|
+
return (await this.transport.request(
|
|
5600
|
+
`/projects/${encodeURIComponent(projectId)}`,
|
|
5601
|
+
{ ...options, method: "PATCH", body: { name } }
|
|
5602
|
+
)).project;
|
|
5603
|
+
}
|
|
5604
|
+
/** `PATCH /projects/:id` (pinned) */
|
|
5605
|
+
async setPinned(projectId, pinned, options) {
|
|
5606
|
+
return (await this.transport.request(
|
|
5607
|
+
`/projects/${encodeURIComponent(projectId)}`,
|
|
5608
|
+
{ ...options, method: "PATCH", body: { pinned } }
|
|
5609
|
+
)).project;
|
|
5610
|
+
}
|
|
5611
|
+
/** `PATCH /projects/:id` (defaultShell) */
|
|
5612
|
+
async setDefaultShell(projectId, defaultShell, options) {
|
|
5613
|
+
return (await this.transport.request(
|
|
5614
|
+
`/projects/${encodeURIComponent(projectId)}`,
|
|
5615
|
+
{ ...options, method: "PATCH", body: { defaultShell } }
|
|
5616
|
+
)).project;
|
|
5617
|
+
}
|
|
5618
|
+
/** `POST /projects/:id/rebind` */
|
|
5619
|
+
async rebind(projectId, path2, options) {
|
|
5620
|
+
const { expectedPath, signal } = typeof options === "string" ? { expectedPath: options } : options ?? {};
|
|
5621
|
+
return (await this.transport.request(
|
|
5622
|
+
`/projects/${encodeURIComponent(projectId)}/rebind`,
|
|
5623
|
+
{ signal, method: "POST", body: { path: path2, expectedPath } }
|
|
5624
|
+
)).project;
|
|
5625
|
+
}
|
|
5626
|
+
/** `DELETE /projects/:id` */
|
|
5627
|
+
async archive(projectId, options) {
|
|
5628
|
+
return (await this.transport.request(
|
|
5629
|
+
`/projects/${encodeURIComponent(projectId)}`,
|
|
5630
|
+
{ ...options, method: "DELETE" }
|
|
5631
|
+
)).project;
|
|
5632
|
+
}
|
|
5633
|
+
/** `POST /project/init` */
|
|
5634
|
+
async init(input, options = {}) {
|
|
5635
|
+
const response = await this.transport.request("/project/init", {
|
|
5636
|
+
method: "POST",
|
|
5637
|
+
body: input,
|
|
5638
|
+
signal: options.signal
|
|
5639
|
+
});
|
|
5640
|
+
return response.report;
|
|
5641
|
+
}
|
|
5642
|
+
};
|
|
5643
|
+
|
|
5644
|
+
// src/resources/workspace/worktree-resource.ts
|
|
5645
|
+
var WorktreeResource = class {
|
|
5646
|
+
constructor(transport) {
|
|
5647
|
+
this.transport = transport;
|
|
5648
|
+
}
|
|
5649
|
+
transport;
|
|
5650
|
+
async list(options) {
|
|
5651
|
+
await requireDaemonFeature(this.transport, "taskWorktrees", options?.signal);
|
|
5652
|
+
const result = await this.transport.request("/worktrees", options);
|
|
5653
|
+
if (!Array.isArray(result)) throw new ProtocolDataError("Task worktrees must be an array");
|
|
5654
|
+
return result;
|
|
5655
|
+
}
|
|
5656
|
+
async cleanup(id2, options) {
|
|
5657
|
+
await requireDaemonFeature(this.transport, "taskWorktrees", options?.signal);
|
|
5658
|
+
await this.transport.request(`/worktrees/${encodeURIComponent(id2)}/cleanup`, { ...options, method: "POST", body: {} });
|
|
5659
|
+
}
|
|
5660
|
+
async setDisposable(id2, disposable, options) {
|
|
5661
|
+
await requireDaemonFeature(this.transport, "taskWorktrees", options?.signal);
|
|
5662
|
+
await this.transport.request(`/worktrees/${encodeURIComponent(id2)}/disposable`, { ...options, method: "POST", body: { disposable } });
|
|
5663
|
+
}
|
|
5664
|
+
};
|
|
5665
|
+
|
|
5666
|
+
// src/resources/workspace/git-resource.ts
|
|
5667
|
+
var GitResource = class {
|
|
5668
|
+
constructor(transport) {
|
|
5669
|
+
this.transport = transport;
|
|
5670
|
+
}
|
|
5671
|
+
transport;
|
|
5672
|
+
/** `GET /git/diff?cwd=&full=` */
|
|
5673
|
+
async getDiff(options) {
|
|
5674
|
+
const { signal, cwd, full } = options;
|
|
5675
|
+
const response = await this.transport.request(
|
|
5676
|
+
this.transport.path("/git/diff", { cwd, ...full ? { full: "true" } : {} }),
|
|
5677
|
+
{ signal }
|
|
5678
|
+
);
|
|
5679
|
+
return response.output;
|
|
5680
|
+
}
|
|
5681
|
+
/** `GET /git/branch?cwd=&list=` */
|
|
5682
|
+
async getBranch(options) {
|
|
5683
|
+
const { signal, cwd, list } = options;
|
|
5684
|
+
const response = await this.transport.request(
|
|
5685
|
+
this.transport.path("/git/branch", { cwd, ...list ? { list: "true" } : {} }),
|
|
5686
|
+
{ signal }
|
|
5687
|
+
);
|
|
5688
|
+
return response.output;
|
|
5689
|
+
}
|
|
5690
|
+
/** `GET /git/status?cwd=` */
|
|
5691
|
+
async getStatus(options) {
|
|
5692
|
+
const { signal, cwd } = options;
|
|
5693
|
+
const response = await this.transport.request(
|
|
5694
|
+
this.transport.path("/git/status", { cwd }),
|
|
5695
|
+
{ signal }
|
|
5696
|
+
);
|
|
5697
|
+
return response.output;
|
|
5698
|
+
}
|
|
5699
|
+
/** `POST /git/commit` */
|
|
5700
|
+
async commit(input, options = {}) {
|
|
5701
|
+
const response = await this.transport.request("/git/commit", {
|
|
5702
|
+
method: "POST",
|
|
5703
|
+
body: input,
|
|
5704
|
+
signal: options.signal
|
|
5705
|
+
});
|
|
5706
|
+
return response.output;
|
|
5707
|
+
}
|
|
5708
|
+
};
|
|
5709
|
+
|
|
5710
|
+
// src/resources/workspace/hook-resource.ts
|
|
5711
|
+
var HookResource = class {
|
|
5712
|
+
constructor(transport) {
|
|
5713
|
+
this.transport = transport;
|
|
5714
|
+
}
|
|
5715
|
+
transport;
|
|
5716
|
+
/** `GET /hooks?cwd=&sessionId=` */
|
|
5717
|
+
async list(options) {
|
|
5718
|
+
const { signal, ...query } = options;
|
|
5719
|
+
const response = await this.transport.request(
|
|
5720
|
+
this.transport.path("/hooks", query),
|
|
5721
|
+
{ signal }
|
|
5722
|
+
);
|
|
5723
|
+
return response.hooks;
|
|
5724
|
+
}
|
|
5725
|
+
};
|
|
5726
|
+
|
|
5727
|
+
// src/resources/configuration/mcp-resource.ts
|
|
5728
|
+
var McpServersResource = class {
|
|
5729
|
+
constructor(transport) {
|
|
5730
|
+
this.transport = transport;
|
|
5731
|
+
}
|
|
5732
|
+
transport;
|
|
5733
|
+
basePath = "/mcp/config/servers";
|
|
5734
|
+
list(options) {
|
|
5735
|
+
return this.request(this.basePath, options);
|
|
5736
|
+
}
|
|
5737
|
+
getConfig(name, options) {
|
|
5738
|
+
return this.request(this.serverPath(name), options);
|
|
5739
|
+
}
|
|
5740
|
+
exportConfig(options) {
|
|
5741
|
+
return this.request(`${this.basePath}/config/export`, options);
|
|
5742
|
+
}
|
|
5743
|
+
add(input, options) {
|
|
5744
|
+
return this.request(this.basePath, { ...options, method: "POST", body: input });
|
|
5745
|
+
}
|
|
5746
|
+
update({ name, ...body }, options) {
|
|
5747
|
+
return this.request(this.serverPath(name), { ...options, method: "PUT", body });
|
|
5748
|
+
}
|
|
5749
|
+
setEnabled({ name, enabled }, options) {
|
|
5750
|
+
return this.request(`${this.serverPath(name)}/enabled`, { ...options, method: "PUT", body: { enabled } });
|
|
5751
|
+
}
|
|
5752
|
+
remove(name, options) {
|
|
5753
|
+
return this.request(this.serverPath(name), { ...options, method: "DELETE" });
|
|
5754
|
+
}
|
|
5755
|
+
serverPath(name) {
|
|
5756
|
+
return `${this.basePath}/${encodeURIComponent(name)}`;
|
|
5757
|
+
}
|
|
5758
|
+
async request(path2, options) {
|
|
5759
|
+
await requireDaemonFeature(this.transport, "mcpServerManagement", options?.signal);
|
|
5760
|
+
return this.transport.request(path2, options);
|
|
5761
|
+
}
|
|
5762
|
+
};
|
|
5763
|
+
var McpResource = class {
|
|
5764
|
+
constructor(transport) {
|
|
5765
|
+
this.transport = transport;
|
|
5766
|
+
this.servers = new McpServersResource(transport);
|
|
5767
|
+
}
|
|
5768
|
+
transport;
|
|
5769
|
+
servers;
|
|
5770
|
+
listAppServers(options = {}) {
|
|
5771
|
+
return this.transport.request("/mcp/app-servers", {
|
|
5772
|
+
signal: options.signal
|
|
5773
|
+
});
|
|
5774
|
+
}
|
|
5775
|
+
runtimeStatus(ref, fingerprintOrOptions, legacyOptions) {
|
|
5776
|
+
const { name, fingerprint, options } = runtimeRequest(ref, fingerprintOrOptions, legacyOptions);
|
|
5777
|
+
return this.transport.request(
|
|
5778
|
+
this.transport.path(
|
|
5779
|
+
`/mcp/${encodeURIComponent(name)}/runtime-status`,
|
|
5780
|
+
{ fingerprint }
|
|
5781
|
+
),
|
|
5782
|
+
options
|
|
5783
|
+
);
|
|
5784
|
+
}
|
|
5785
|
+
synchronize(ref, fingerprintOrOptions, legacyOptions) {
|
|
5786
|
+
const { name, fingerprint, options } = runtimeRequest(ref, fingerprintOrOptions, legacyOptions);
|
|
5787
|
+
return this.transport.request(
|
|
5788
|
+
`/mcp/${encodeURIComponent(name)}/synchronize`,
|
|
5789
|
+
{ ...options, method: "POST", body: { fingerprint } }
|
|
5790
|
+
);
|
|
5791
|
+
}
|
|
5792
|
+
/**
|
|
5793
|
+
* Ask every active Runtime to re-check the latest global config for `name`.
|
|
5794
|
+
* Only the server name crosses the wire.
|
|
5795
|
+
*/
|
|
5796
|
+
async reconcileGlobal(name, options = {}) {
|
|
5797
|
+
return await this.transport.request(
|
|
5798
|
+
`/mcp/${encodeURIComponent(name)}/reconcile-global`,
|
|
5799
|
+
{ method: "POST", body: {}, signal: options.signal }
|
|
4285
5800
|
);
|
|
4286
5801
|
}
|
|
4287
|
-
|
|
4288
|
-
async
|
|
5802
|
+
// --- MCP OAuth login operations -----------------------------------------
|
|
5803
|
+
async authStatus(options = {}) {
|
|
5804
|
+
return await this.transport.request("/mcp/oauth/status", { signal: options.signal });
|
|
5805
|
+
}
|
|
5806
|
+
async startLogin(name, input, options = {}) {
|
|
4289
5807
|
return await this.transport.request(
|
|
4290
|
-
`/
|
|
5808
|
+
`/mcp/${encodeURIComponent(name)}/oauth/login`,
|
|
4291
5809
|
{ method: "POST", body: input, signal: options.signal }
|
|
4292
5810
|
);
|
|
4293
5811
|
}
|
|
4294
|
-
|
|
4295
|
-
async remember(sessionId, options = {}) {
|
|
5812
|
+
async getLogin(loginId, options = {}) {
|
|
4296
5813
|
return await this.transport.request(
|
|
4297
|
-
`/
|
|
4298
|
-
{
|
|
5814
|
+
`/mcp/oauth/operations/${encodeURIComponent(loginId)}`,
|
|
5815
|
+
{ signal: options.signal }
|
|
4299
5816
|
);
|
|
4300
5817
|
}
|
|
4301
|
-
|
|
4302
|
-
async export(sessionId, input = {}, options = {}) {
|
|
5818
|
+
async submitCallback(loginId, callbackUrl, options = {}) {
|
|
4303
5819
|
return await this.transport.request(
|
|
4304
|
-
`/
|
|
4305
|
-
{ method: "POST", body:
|
|
5820
|
+
`/mcp/oauth/operations/${encodeURIComponent(loginId)}/callback`,
|
|
5821
|
+
{ method: "POST", body: { callbackUrl }, signal: options.signal }
|
|
4306
5822
|
);
|
|
4307
5823
|
}
|
|
4308
|
-
|
|
4309
|
-
async getUsage(sessionId, options = {}) {
|
|
5824
|
+
async cancelLogin(loginId, options = {}) {
|
|
4310
5825
|
return await this.transport.request(
|
|
4311
|
-
`/
|
|
4312
|
-
{ signal: options.signal }
|
|
5826
|
+
`/mcp/oauth/operations/${encodeURIComponent(loginId)}`,
|
|
5827
|
+
{ method: "DELETE", signal: options.signal }
|
|
4313
5828
|
);
|
|
4314
5829
|
}
|
|
4315
|
-
|
|
4316
|
-
|
|
4317
|
-
|
|
4318
|
-
|
|
5830
|
+
async logout(name, options = {}) {
|
|
5831
|
+
return await this.transport.request(
|
|
5832
|
+
`/mcp/${encodeURIComponent(name)}/oauth/logout`,
|
|
5833
|
+
{ method: "POST", body: {}, signal: options.signal }
|
|
4319
5834
|
);
|
|
4320
|
-
return response.goal;
|
|
4321
5835
|
}
|
|
4322
|
-
|
|
4323
|
-
|
|
4324
|
-
|
|
4325
|
-
|
|
4326
|
-
`/sessions/${encodeURIComponent(sessionId)}/goal/requests/${encodeURIComponent(requestId)}`
|
|
4327
|
-
)
|
|
5836
|
+
async *watchLogin(loginId, options = {}) {
|
|
5837
|
+
const response = await this.transport.requestResponse(
|
|
5838
|
+
`/mcp/oauth/operations/${encodeURIComponent(loginId)}/events`,
|
|
5839
|
+
{ signal: options.signal }
|
|
4328
5840
|
);
|
|
4329
|
-
if (
|
|
4330
|
-
|
|
4331
|
-
|
|
4332
|
-
|
|
4333
|
-
|
|
5841
|
+
if (!response.body) return;
|
|
5842
|
+
try {
|
|
5843
|
+
yield* streamServerSentEvents(async () => response.body, parseOAuthOperationEvent);
|
|
5844
|
+
} finally {
|
|
5845
|
+
await response.body.cancel().catch(() => void 0);
|
|
5846
|
+
}
|
|
5847
|
+
}
|
|
5848
|
+
};
|
|
5849
|
+
function runtimeRequest(ref, fingerprintOrOptions, legacyOptions) {
|
|
5850
|
+
return typeof ref === "string" ? { name: ref, fingerprint: fingerprintOrOptions, options: legacyOptions } : { name: ref.name, fingerprint: ref.endpointFingerprint, options: fingerprintOrOptions };
|
|
5851
|
+
}
|
|
5852
|
+
|
|
5853
|
+
// src/resources/configuration/command-resource.ts
|
|
5854
|
+
var CommandResource = class {
|
|
5855
|
+
constructor(transport) {
|
|
5856
|
+
this.transport = transport;
|
|
4334
5857
|
}
|
|
4335
|
-
|
|
4336
|
-
|
|
5858
|
+
transport;
|
|
5859
|
+
/** `GET /commands` */
|
|
5860
|
+
async list(options) {
|
|
5861
|
+
const { signal, ...query } = options;
|
|
4337
5862
|
const response = await this.transport.request(
|
|
4338
|
-
|
|
4339
|
-
{
|
|
5863
|
+
this.transport.path("/commands", query),
|
|
5864
|
+
{ signal }
|
|
4340
5865
|
);
|
|
4341
|
-
return response.
|
|
5866
|
+
return response.commands;
|
|
5867
|
+
}
|
|
5868
|
+
};
|
|
5869
|
+
|
|
5870
|
+
// src/resources/configuration/context-resource.ts
|
|
5871
|
+
var ContextResource = class {
|
|
5872
|
+
constructor(transport) {
|
|
5873
|
+
this.transport = transport;
|
|
4342
5874
|
}
|
|
4343
|
-
|
|
4344
|
-
|
|
5875
|
+
transport;
|
|
5876
|
+
/** `GET /context?cwd=` */
|
|
5877
|
+
async getPreview(options) {
|
|
5878
|
+
const { signal, ...query } = options;
|
|
4345
5879
|
const response = await this.transport.request(
|
|
4346
|
-
|
|
4347
|
-
{
|
|
5880
|
+
this.transport.path("/context", query),
|
|
5881
|
+
{ signal }
|
|
4348
5882
|
);
|
|
4349
|
-
return response.
|
|
5883
|
+
return response.report;
|
|
4350
5884
|
}
|
|
4351
|
-
/** `
|
|
4352
|
-
async
|
|
5885
|
+
/** `GET /context/status?cwd=` */
|
|
5886
|
+
async getStatus(options) {
|
|
5887
|
+
const { signal, ...query } = options;
|
|
4353
5888
|
const response = await this.transport.request(
|
|
4354
|
-
|
|
4355
|
-
{
|
|
5889
|
+
this.transport.path("/context/status", query),
|
|
5890
|
+
{ signal }
|
|
5891
|
+
);
|
|
5892
|
+
return response.report;
|
|
5893
|
+
}
|
|
5894
|
+
/** `GET /context/usage?cwd=&sessionId=&refresh=` */
|
|
5895
|
+
async getUsage(options) {
|
|
5896
|
+
const { signal, refresh, previousContextWindow, ...rest } = options;
|
|
5897
|
+
const query = {
|
|
5898
|
+
...rest,
|
|
5899
|
+
...refresh !== void 0 ? { refresh: refresh ? "true" : "false" } : {},
|
|
5900
|
+
...previousContextWindow !== void 0 ? { previousContextWindow: String(previousContextWindow) } : {}
|
|
5901
|
+
};
|
|
5902
|
+
return await this.transport.request(
|
|
5903
|
+
this.transport.path("/context/usage", query),
|
|
5904
|
+
{ signal }
|
|
4356
5905
|
);
|
|
4357
|
-
return response.goal;
|
|
4358
5906
|
}
|
|
4359
5907
|
};
|
|
4360
5908
|
|
|
4361
|
-
// src/resources/
|
|
4362
|
-
var
|
|
5909
|
+
// src/resources/configuration/diagnostic-resource.ts
|
|
5910
|
+
var diagnosticPaths = {
|
|
5911
|
+
readiness: "/maintenance/readiness",
|
|
5912
|
+
runtime: "/debug/runtime",
|
|
5913
|
+
storageHealth: "/maintenance/storage/health",
|
|
5914
|
+
environment: "/maintenance/environment",
|
|
5915
|
+
logs: "/maintenance/logs",
|
|
5916
|
+
errors: "/maintenance/errors",
|
|
5917
|
+
details: "/maintenance/diagnostics/details"
|
|
5918
|
+
};
|
|
5919
|
+
var DiagnosticResource = class {
|
|
4363
5920
|
constructor(transport) {
|
|
4364
5921
|
this.transport = transport;
|
|
4365
5922
|
}
|
|
4366
5923
|
transport;
|
|
4367
|
-
/**
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
headers2["x-bobannomi-filename"] = encodeURIComponent(input.displayName);
|
|
4371
|
-
if (input.mediaType) headers2["content-type"] = input.mediaType;
|
|
4372
|
-
const response = await this.transport.requestResponse("/attachments", {
|
|
4373
|
-
method: "POST",
|
|
4374
|
-
headers: headers2,
|
|
4375
|
-
body: input.body,
|
|
4376
|
-
signal: input.signal
|
|
4377
|
-
});
|
|
4378
|
-
return parseAttachmentAssetRecord(await response.json());
|
|
5924
|
+
/** The original normalized endpoint, without this connection's bearer token. */
|
|
5925
|
+
target() {
|
|
5926
|
+
return this.transport.baseUrl;
|
|
4379
5927
|
}
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
return
|
|
5928
|
+
/** Finite native-host diagnostics; this never accepts an arbitrary route or mutation. */
|
|
5929
|
+
async get(kind, options = {}) {
|
|
5930
|
+
if (!Object.hasOwn(diagnosticPaths, kind)) throw new Error("Unknown diagnostic kind");
|
|
5931
|
+
return this.transport.request(diagnosticPaths[kind], { signal: options.signal });
|
|
4384
5932
|
}
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
`/attachments/${encodeURIComponent(id2)}`,
|
|
4388
|
-
{ signal: options.signal }
|
|
4389
|
-
);
|
|
4390
|
-
return parseAttachmentAssetRecord(value);
|
|
5933
|
+
getRun(runId, { signal, ...query } = {}) {
|
|
5934
|
+
return this.transport.request(`/debug/runs/${encodeURIComponent(runId)}`, { query, signal });
|
|
4391
5935
|
}
|
|
4392
|
-
|
|
4393
|
-
|
|
4394
|
-
const range = attachmentRangeHeader(options.range);
|
|
4395
|
-
const headers2 = {};
|
|
4396
|
-
if (range) headers2.range = range;
|
|
4397
|
-
return await this.transport.requestResponse(
|
|
4398
|
-
`/attachments/${encodeURIComponent(id2)}/content`,
|
|
4399
|
-
{ method: "GET", headers: headers2, signal: options.signal }
|
|
4400
|
-
);
|
|
5936
|
+
listSettlements({ signal, ...query } = {}) {
|
|
5937
|
+
return this.transport.request("/debug/projection-settlements", { query, signal });
|
|
4401
5938
|
}
|
|
4402
|
-
|
|
4403
|
-
|
|
4404
|
-
|
|
4405
|
-
|
|
4406
|
-
|
|
4407
|
-
|
|
5939
|
+
listExecutions({ signal, ...query } = {}) {
|
|
5940
|
+
return this.transport.request("/debug/executions", { query, signal });
|
|
5941
|
+
}
|
|
5942
|
+
setDetails(minutes, options) {
|
|
5943
|
+
return this.transport.request("/maintenance/diagnostics/details", {
|
|
5944
|
+
...options,
|
|
5945
|
+
method: "POST",
|
|
5946
|
+
body: { minutes }
|
|
5947
|
+
});
|
|
4408
5948
|
}
|
|
4409
5949
|
};
|
|
4410
|
-
function uploadIdentityHeaders(input) {
|
|
4411
|
-
parseAttachmentUploadRequest({ ...input, declaredMediaType: input.mediaType });
|
|
4412
|
-
return { "x-bobannomi-request-id": input.requestId, "x-bobannomi-draft-id": input.draftId, "x-bobannomi-sha256": input.expectedSha256, "x-bobannomi-byte-length": String(input.byteLength), "x-bobannomi-filename": encodeURIComponent(input.displayName), ...input.mediaType ? { "content-type": input.mediaType } : {} };
|
|
4413
|
-
}
|
|
4414
5950
|
|
|
4415
|
-
// src/resources/configuration/
|
|
4416
|
-
var
|
|
5951
|
+
// src/resources/configuration/maintenance-resource.ts
|
|
5952
|
+
var MaintenanceResource = class {
|
|
4417
5953
|
constructor(transport) {
|
|
4418
5954
|
this.transport = transport;
|
|
4419
5955
|
}
|
|
4420
5956
|
transport;
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
5957
|
+
getRestartPreview(options) {
|
|
5958
|
+
return this.transport.request("/maintenance/restart-preview", options);
|
|
5959
|
+
}
|
|
5960
|
+
prepareRestart({ stopActive = false, signal } = {}) {
|
|
5961
|
+
return this.post("/prepare-restart", { stopActive }, { signal });
|
|
5962
|
+
}
|
|
5963
|
+
cleanup = {
|
|
5964
|
+
preview: (input, options) => this.post("/cleanup/preview", input, options),
|
|
5965
|
+
execute: (input, options) => this.post("/cleanup/execute", input, options),
|
|
5966
|
+
audits: (options) => this.transport.request("/maintenance/cleanup/audits", options),
|
|
5967
|
+
getPolicy: (options) => this.transport.request("/maintenance/cleanup/policy", options),
|
|
5968
|
+
updatePolicy: (input, options) => this.post("/cleanup/policy", input, options),
|
|
5969
|
+
runPolicy: (options) => this.post("/cleanup/policy/run", {}, options)
|
|
5970
|
+
};
|
|
5971
|
+
usage = {
|
|
5972
|
+
get: (input = {}, options) => this.post("/usage", input, options),
|
|
5973
|
+
getSettings: (options) => this.transport.request("/maintenance/usage/settings", options),
|
|
5974
|
+
updateBudget: (input, options) => this.post("/usage/budget", input, options),
|
|
5975
|
+
addPrice: (input, options) => this.post("/usage/price", input, options)
|
|
5976
|
+
};
|
|
5977
|
+
storage = {
|
|
5978
|
+
get: (options) => this.transport.request("/maintenance/storage", options)
|
|
5979
|
+
};
|
|
5980
|
+
backups = {
|
|
5981
|
+
create: (input, options) => this.post("/backup", input, options),
|
|
5982
|
+
verify: (source, options) => this.post("/backup/verify", { source }, options),
|
|
5983
|
+
restore: (input, options) => this.post("/backup/restore", input, options)
|
|
5984
|
+
};
|
|
5985
|
+
post(path2, body, options) {
|
|
5986
|
+
return this.transport.request(`/maintenance${path2}`, { ...options, method: "POST", body });
|
|
5987
|
+
}
|
|
5988
|
+
};
|
|
5989
|
+
|
|
5990
|
+
// src/resources/configuration/memory-resource.ts
|
|
5991
|
+
var MemoryResource = class {
|
|
5992
|
+
constructor(transport) {
|
|
5993
|
+
this.transport = transport;
|
|
5994
|
+
}
|
|
5995
|
+
transport;
|
|
5996
|
+
/** `GET /memory?cwd=` */
|
|
5997
|
+
async listMemory(options) {
|
|
5998
|
+
const { signal, ...query } = options;
|
|
5999
|
+
return await this.transport.request(
|
|
6000
|
+
this.transport.path("/memory", query),
|
|
6001
|
+
{ signal }
|
|
4428
6002
|
);
|
|
4429
|
-
return response.request;
|
|
4430
6003
|
}
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
6004
|
+
/** `GET /facts?cwd=` — current project environment facts. */
|
|
6005
|
+
async listFacts(options) {
|
|
6006
|
+
const { signal, ...query } = options;
|
|
6007
|
+
return await this.transport.request(
|
|
6008
|
+
this.transport.path("/facts", query),
|
|
6009
|
+
{ signal }
|
|
6010
|
+
);
|
|
4434
6011
|
}
|
|
4435
|
-
|
|
6012
|
+
/** `POST /facts/replace` — replace exactly one selected environment fact. */
|
|
6013
|
+
async replaceFact(input, options = {}) {
|
|
4436
6014
|
const response = await this.transport.request(
|
|
4437
|
-
|
|
4438
|
-
{ method: "POST" }
|
|
6015
|
+
"/facts/replace",
|
|
6016
|
+
{ method: "POST", body: input, signal: options.signal }
|
|
4439
6017
|
);
|
|
4440
|
-
return response.
|
|
6018
|
+
return response.result;
|
|
4441
6019
|
}
|
|
4442
|
-
/** `GET /
|
|
4443
|
-
async
|
|
4444
|
-
const { signal,
|
|
4445
|
-
const response = await this.transport.request(
|
|
4446
|
-
|
|
6020
|
+
/** `GET /memory/:id?cwd=` */
|
|
6021
|
+
async getMemory(entryId, options) {
|
|
6022
|
+
const { signal, cwd } = options;
|
|
6023
|
+
const response = await this.transport.request(
|
|
6024
|
+
this.transport.path(`/memory/${encodeURIComponent(entryId)}`, { cwd }),
|
|
6025
|
+
{ signal }
|
|
6026
|
+
);
|
|
6027
|
+
return response.entry;
|
|
4447
6028
|
}
|
|
4448
|
-
/** `POST /
|
|
4449
|
-
async
|
|
6029
|
+
/** `POST /memory` */
|
|
6030
|
+
async addMemory(input, options = {}) {
|
|
4450
6031
|
const response = await this.transport.request(
|
|
4451
|
-
|
|
6032
|
+
"/memory",
|
|
4452
6033
|
{
|
|
4453
6034
|
method: "POST",
|
|
4454
6035
|
body: input,
|
|
4455
6036
|
signal: options.signal
|
|
4456
6037
|
}
|
|
4457
6038
|
);
|
|
4458
|
-
return response.
|
|
6039
|
+
return response.entry;
|
|
6040
|
+
}
|
|
6041
|
+
/** `DELETE /memory/:id?cwd=` */
|
|
6042
|
+
async removeMemory(entryId, options) {
|
|
6043
|
+
const { signal, cwd, expectedRevision } = options;
|
|
6044
|
+
await this.transport.request(
|
|
6045
|
+
this.transport.path(`/memory/${encodeURIComponent(entryId)}`, { cwd, expectedRevision }),
|
|
6046
|
+
{ method: "DELETE", signal }
|
|
6047
|
+
);
|
|
6048
|
+
}
|
|
6049
|
+
async updateMemory(input, options = {}) {
|
|
6050
|
+
const { id: id2, ...body } = input;
|
|
6051
|
+
const result = await this.transport.request(`/memory/${encodeURIComponent(id2)}`, { method: "PATCH", body, signal: options.signal });
|
|
6052
|
+
return result.entry;
|
|
6053
|
+
}
|
|
6054
|
+
async clearMemory(input, options = {}) {
|
|
6055
|
+
return this.transport.request("/memory/clear", { method: "POST", body: input, signal: options.signal });
|
|
6056
|
+
}
|
|
6057
|
+
async getDreamStatus(input) {
|
|
6058
|
+
return this.transport.request(this.transport.path("/dream", input));
|
|
6059
|
+
}
|
|
6060
|
+
/** `POST /dream` */
|
|
6061
|
+
async startDream(input, options = {}) {
|
|
6062
|
+
return await this.transport.request("/dream", {
|
|
6063
|
+
method: "POST",
|
|
6064
|
+
body: input,
|
|
6065
|
+
signal: options.signal
|
|
6066
|
+
});
|
|
4459
6067
|
}
|
|
4460
6068
|
};
|
|
4461
6069
|
|
|
4462
|
-
// src/resources/
|
|
4463
|
-
var
|
|
6070
|
+
// src/resources/configuration/settings-resource.ts
|
|
6071
|
+
var SettingsResource = class {
|
|
4464
6072
|
constructor(transport) {
|
|
4465
6073
|
this.transport = transport;
|
|
4466
6074
|
}
|
|
4467
6075
|
transport;
|
|
4468
|
-
|
|
4469
|
-
|
|
6076
|
+
/** Read the daemon's current global settings. */
|
|
6077
|
+
getGlobal({ signal } = {}) {
|
|
6078
|
+
return this.get({ signal });
|
|
6079
|
+
}
|
|
6080
|
+
/** Read effective settings including overrides for a daemon-side project directory. */
|
|
6081
|
+
getEffective(options) {
|
|
6082
|
+
if (typeof options.cwd !== "string" || !options.cwd.trim())
|
|
6083
|
+
return Promise.reject(new TypeError("cwd must be a nonempty daemon directory"));
|
|
6084
|
+
return this.get(options);
|
|
6085
|
+
}
|
|
6086
|
+
/** Read global settings without cwd, or the merged project settings with cwd. */
|
|
6087
|
+
async get(options = {}) {
|
|
4470
6088
|
const response = await this.transport.request(
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
...kinds ? { kinds: kinds.join(",") } : {},
|
|
4474
|
-
...statuses ? { statuses: statuses.join(",") } : {},
|
|
4475
|
-
...includeFinished !== void 0 ? { includeFinished: String(includeFinished) } : {}
|
|
4476
|
-
}),
|
|
4477
|
-
{ signal }
|
|
6089
|
+
options.cwd ? `/settings?cwd=${encodeURIComponent(options.cwd)}` : "/settings",
|
|
6090
|
+
{ signal: options.signal }
|
|
4478
6091
|
);
|
|
4479
|
-
return
|
|
6092
|
+
return response.settings;
|
|
4480
6093
|
}
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
6094
|
+
/** Apply a targeted change to global settings. Pass only the fields the caller changes. */
|
|
6095
|
+
updateGlobal(patch, options) {
|
|
6096
|
+
return this.update(patch, options);
|
|
6097
|
+
}
|
|
6098
|
+
/** Apply a global patch. Existing callers may use this alias. */
|
|
6099
|
+
async update(patch, options = {}) {
|
|
6100
|
+
const response = await this.transport.request(
|
|
6101
|
+
"/settings",
|
|
4484
6102
|
{
|
|
4485
|
-
method: "
|
|
4486
|
-
body:
|
|
6103
|
+
method: "PATCH",
|
|
6104
|
+
body: patch,
|
|
4487
6105
|
signal: options.signal
|
|
4488
6106
|
}
|
|
4489
6107
|
);
|
|
6108
|
+
return response.settings;
|
|
4490
6109
|
}
|
|
4491
|
-
|
|
4492
|
-
|
|
4493
|
-
const response = await this.transport.request(
|
|
4494
|
-
|
|
4495
|
-
|
|
4496
|
-
|
|
4497
|
-
return decodeJobReadResult(response);
|
|
6110
|
+
/** `GET /profile` */
|
|
6111
|
+
async getProfileStatus(options = {}) {
|
|
6112
|
+
const response = await this.transport.request("/profile", {
|
|
6113
|
+
signal: options.signal
|
|
6114
|
+
});
|
|
6115
|
+
return response.report;
|
|
4498
6116
|
}
|
|
4499
|
-
|
|
6117
|
+
/** `POST /profile/init` */
|
|
6118
|
+
async initProfile(options = {}) {
|
|
4500
6119
|
const response = await this.transport.request(
|
|
4501
|
-
|
|
6120
|
+
"/profile/init",
|
|
4502
6121
|
{
|
|
4503
6122
|
method: "POST",
|
|
4504
|
-
body: { ...input, target },
|
|
4505
6123
|
signal: options.signal
|
|
4506
6124
|
}
|
|
4507
6125
|
);
|
|
4508
|
-
return
|
|
4509
|
-
}
|
|
4510
|
-
async send(target, input, options = {}) {
|
|
4511
|
-
const response = await this.transport.request(`/jobs/${encodeURIComponent(target.jobId)}/input`, {
|
|
4512
|
-
method: "POST",
|
|
4513
|
-
body: { ...input, target },
|
|
4514
|
-
signal: options.signal
|
|
4515
|
-
});
|
|
4516
|
-
if (responseField(response, "sent") !== true) throw new ProtocolDataError("Job input was not accepted", "sent");
|
|
4517
|
-
const receipt2 = response.receipt;
|
|
4518
|
-
return receipt2 === void 0 ? void 0 : decodeJobInputReceipt(receipt2);
|
|
6126
|
+
return response.report;
|
|
4519
6127
|
}
|
|
4520
|
-
|
|
4521
|
-
|
|
6128
|
+
/** `GET /output-styles` */
|
|
6129
|
+
async listOutputStyles(options = {}) {
|
|
4522
6130
|
const response = await this.transport.request(
|
|
4523
|
-
|
|
4524
|
-
{
|
|
6131
|
+
"/output-styles",
|
|
6132
|
+
{
|
|
6133
|
+
signal: options.signal
|
|
6134
|
+
}
|
|
4525
6135
|
);
|
|
4526
|
-
|
|
4527
|
-
const receipt2 = decodeJobCancelReceipt(response);
|
|
4528
|
-
if (receipt2.id !== target.jobId) throw new ProtocolDataError("Cancellation receipt does not match target");
|
|
4529
|
-
return receipt2;
|
|
4530
|
-
}
|
|
4531
|
-
return decodeJobSnapshot(responseField(response, "snapshot"));
|
|
6136
|
+
return response.styles;
|
|
4532
6137
|
}
|
|
4533
6138
|
};
|
|
4534
6139
|
|
|
4535
|
-
// src/resources/
|
|
4536
|
-
var
|
|
6140
|
+
// src/resources/runtime/terminal-resource.ts
|
|
6141
|
+
var TerminalResource = class {
|
|
4537
6142
|
constructor(transport, sse) {
|
|
4538
6143
|
this.transport = transport;
|
|
4539
6144
|
this.sse = sse;
|
|
4540
6145
|
}
|
|
4541
6146
|
transport;
|
|
4542
6147
|
sse;
|
|
4543
|
-
|
|
6148
|
+
async create(input, options = {}) {
|
|
6149
|
+
const response = await this.transport.request("/terminals", {
|
|
6150
|
+
method: "POST",
|
|
6151
|
+
body: input,
|
|
6152
|
+
signal: options.signal
|
|
6153
|
+
});
|
|
6154
|
+
return decodeTerminalSessionInfo(responseField(response, "terminal"));
|
|
6155
|
+
}
|
|
4544
6156
|
async list(options = {}) {
|
|
4545
6157
|
const { signal, ...query } = options;
|
|
4546
6158
|
const response = await this.transport.request(
|
|
4547
|
-
this.transport.path("/
|
|
6159
|
+
this.transport.path("/terminals", query),
|
|
4548
6160
|
{ signal }
|
|
4549
6161
|
);
|
|
4550
|
-
return responseArray2(response, "
|
|
4551
|
-
}
|
|
4552
|
-
stream(options = {}) {
|
|
4553
|
-
const query = {
|
|
4554
|
-
partView: options.partView,
|
|
4555
|
-
cursor: options.cursor,
|
|
4556
|
-
sessionId: options.sessionId
|
|
4557
|
-
};
|
|
4558
|
-
return this.sse.stream(this.transport.resolveUrl("/events/stream", query), {
|
|
4559
|
-
headers: this.transport.headers(),
|
|
4560
|
-
signal: options.signal,
|
|
4561
|
-
decode: decodeSessionEventRecord,
|
|
4562
|
-
reconnect: options.transportReconnect ?? false,
|
|
4563
|
-
onOpen: options.onOpen,
|
|
4564
|
-
idleTimeoutMs: options.idleTimeoutMs
|
|
4565
|
-
});
|
|
4566
|
-
}
|
|
4567
|
-
};
|
|
4568
|
-
|
|
4569
|
-
// src/resources/files/files-resource.ts
|
|
4570
|
-
var FilesResource = class {
|
|
4571
|
-
constructor(transport) {
|
|
4572
|
-
this.transport = transport;
|
|
6162
|
+
return responseArray2(response, "terminals", decodeTerminalSessionInfo);
|
|
4573
6163
|
}
|
|
4574
|
-
|
|
4575
|
-
async list(sessionId, options = {}) {
|
|
4576
|
-
const { signal, ...query } = options;
|
|
6164
|
+
async get(terminalId, options = {}) {
|
|
4577
6165
|
const response = await this.transport.request(
|
|
4578
|
-
|
|
4579
|
-
{ signal }
|
|
6166
|
+
`/terminals/${encodeURIComponent(terminalId)}`,
|
|
6167
|
+
{ signal: options.signal }
|
|
4580
6168
|
);
|
|
4581
|
-
return
|
|
6169
|
+
return decodeTerminalSessionInfo(responseField(response, "terminal"));
|
|
4582
6170
|
}
|
|
4583
|
-
async
|
|
6171
|
+
async read(terminalId, options = {}) {
|
|
4584
6172
|
const response = await this.transport.request(
|
|
4585
|
-
|
|
6173
|
+
`/terminals/${encodeURIComponent(terminalId)}/output`,
|
|
4586
6174
|
{ signal: options.signal }
|
|
4587
6175
|
);
|
|
4588
|
-
return
|
|
6176
|
+
return decodeTerminalReadResult(responseField(response, "snapshot"));
|
|
4589
6177
|
}
|
|
4590
|
-
async
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
{ signal }
|
|
6178
|
+
async write(input, options = {}) {
|
|
6179
|
+
await this.transport.request(
|
|
6180
|
+
`/terminals/${encodeURIComponent(input.terminalId)}/input`,
|
|
6181
|
+
{ method: "POST", body: { data: input.data }, signal: options.signal }
|
|
4595
6182
|
);
|
|
4596
|
-
return decodeSessionTextFileResult(response);
|
|
4597
6183
|
}
|
|
4598
|
-
async
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
|
|
6184
|
+
async resize(input, options = {}) {
|
|
6185
|
+
await this.transport.request(
|
|
6186
|
+
`/terminals/${encodeURIComponent(input.terminalId)}/resize`,
|
|
6187
|
+
{
|
|
6188
|
+
method: "POST",
|
|
6189
|
+
body: { cols: input.cols, rows: input.rows },
|
|
6190
|
+
signal: options.signal
|
|
6191
|
+
}
|
|
4603
6192
|
);
|
|
4604
|
-
return decodeSessionFindFilesResult(response);
|
|
4605
6193
|
}
|
|
4606
|
-
async
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
6194
|
+
async signal(terminalId, signal, options = {}) {
|
|
6195
|
+
await this.transport.request(
|
|
6196
|
+
`/terminals/${encodeURIComponent(terminalId)}/signal`,
|
|
6197
|
+
{ method: "POST", body: { signal }, signal: options.signal }
|
|
6198
|
+
);
|
|
6199
|
+
}
|
|
6200
|
+
async close(terminalId, options = {}) {
|
|
6201
|
+
await this.transport.request(
|
|
6202
|
+
`/terminals/${encodeURIComponent(terminalId)}`,
|
|
6203
|
+
{
|
|
6204
|
+
method: "DELETE",
|
|
6205
|
+
signal: options.signal
|
|
6206
|
+
}
|
|
6207
|
+
);
|
|
6208
|
+
}
|
|
6209
|
+
streamEvents(options = {}) {
|
|
6210
|
+
return this.sse.stream(
|
|
6211
|
+
this.transport.resolveUrl("/terminals/stream"),
|
|
6212
|
+
{
|
|
6213
|
+
headers: this.transport.headers(),
|
|
6214
|
+
signal: options.signal,
|
|
6215
|
+
decode: decodeTerminalEvent,
|
|
6216
|
+
noBodyMessage: "Terminal event stream response has no body"
|
|
6217
|
+
}
|
|
4614
6218
|
);
|
|
4615
|
-
return decodeSessionSearchFilesResult(response);
|
|
4616
6219
|
}
|
|
4617
6220
|
};
|
|
4618
6221
|
|
|
4619
6222
|
// src/transport/http-client.ts
|
|
4620
6223
|
var BobanNomiClient = class {
|
|
4621
6224
|
protocol;
|
|
4622
|
-
|
|
6225
|
+
/** Models grouped by provider, from the caller's catalog or the daemon. */
|
|
6226
|
+
models;
|
|
6227
|
+
/** Model-provider connections and defaults. Requires daemon management access. */
|
|
6228
|
+
modelProviders;
|
|
6229
|
+
/** Agent roles available to this connection. */
|
|
6230
|
+
agents;
|
|
6231
|
+
/** Available skills and their sources. */
|
|
6232
|
+
skills;
|
|
4623
6233
|
schedules;
|
|
4624
6234
|
sessions;
|
|
4625
6235
|
attachments;
|
|
4626
6236
|
permissions;
|
|
4627
|
-
jobs;
|
|
4628
6237
|
events;
|
|
4629
|
-
|
|
6238
|
+
/** Daemon plugin installation and lifecycle. Requires management access. */
|
|
6239
|
+
plugins;
|
|
6240
|
+
channels;
|
|
6241
|
+
projects;
|
|
6242
|
+
worktrees;
|
|
6243
|
+
git;
|
|
6244
|
+
hooks;
|
|
6245
|
+
mcp;
|
|
6246
|
+
commands;
|
|
6247
|
+
context;
|
|
6248
|
+
diagnostics;
|
|
6249
|
+
maintenance;
|
|
6250
|
+
memory;
|
|
6251
|
+
settings;
|
|
6252
|
+
/** Global daemon execution terminal access. Session-scoped output is under sessions.byId(). */
|
|
6253
|
+
terminals;
|
|
4630
6254
|
constructor(options) {
|
|
4631
|
-
const transport = new HttpTransport(options);
|
|
6255
|
+
const transport = options instanceof HttpTransport ? options : new HttpTransport(options);
|
|
4632
6256
|
const sse = new SseTransport(transport);
|
|
4633
6257
|
this.protocol = new ProtocolClient(transport);
|
|
4634
|
-
|
|
6258
|
+
const providers = options instanceof HttpTransport ? void 0 : options.providers;
|
|
6259
|
+
const { models, modelProviders, agents, skills } = createRuntimeResources(transport, providers);
|
|
6260
|
+
this.models = models;
|
|
6261
|
+
this.modelProviders = modelProviders;
|
|
6262
|
+
this.agents = agents;
|
|
6263
|
+
this.skills = skills;
|
|
4635
6264
|
this.schedules = new ScheduleResource(transport);
|
|
4636
|
-
this.sessions = new SessionResource(transport);
|
|
4637
6265
|
this.attachments = new AttachmentResource(transport);
|
|
4638
6266
|
this.permissions = new PermissionResource(transport);
|
|
4639
|
-
this.jobs = new JobResource(transport);
|
|
4640
6267
|
this.events = new EventResource(transport, sse);
|
|
4641
|
-
this.
|
|
6268
|
+
this.sessions = new SessionResource(transport, this.events);
|
|
6269
|
+
this.plugins = new PluginResource(transport);
|
|
6270
|
+
this.channels = new ChannelResource(transport);
|
|
6271
|
+
this.projects = new ProjectResource(transport);
|
|
6272
|
+
this.worktrees = new WorktreeResource(transport);
|
|
6273
|
+
this.git = new GitResource(transport);
|
|
6274
|
+
this.hooks = new HookResource(transport);
|
|
6275
|
+
this.mcp = new McpResource(transport);
|
|
6276
|
+
this.commands = new CommandResource(transport);
|
|
6277
|
+
this.context = new ContextResource(transport);
|
|
6278
|
+
this.diagnostics = new DiagnosticResource(transport);
|
|
6279
|
+
this.maintenance = new MaintenanceResource(transport);
|
|
6280
|
+
this.memory = new MemoryResource(transport);
|
|
6281
|
+
this.settings = new SettingsResource(transport);
|
|
6282
|
+
this.terminals = new TerminalResource(transport, sse);
|
|
4642
6283
|
}
|
|
4643
6284
|
};
|
|
4644
6285
|
|
|
@@ -4656,7 +6297,7 @@ async function defaultCommand(cwd, dataRoot) {
|
|
|
4656
6297
|
if (typeof bin !== "string") throw new Error("CLI bin is missing");
|
|
4657
6298
|
return [process.execPath, resolve2(dirname(manifestPath), bin), "--data-root", dataRoot, "serve", "--register", "--host", "127.0.0.1", "--port", "0"];
|
|
4658
6299
|
} catch {
|
|
4659
|
-
throw new Error("Cannot locate BobanNomi CLI.
|
|
6300
|
+
throw new Error("Cannot locate BobanNomi CLI. Pass Service.ensure({ command: [executable, ...args] }) with a built CLI.");
|
|
4660
6301
|
}
|
|
4661
6302
|
}
|
|
4662
6303
|
function startProcess(command, cwd, env) {
|