@bobannomi/client 0.1.0-next.1 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +90 -80
- package/dist/index.js +284 -246
- package/dist/index.js.map +3 -3
- package/dist/service.js +327 -273
- package/dist/service.js.map +3 -3
- package/package.json +1 -1
package/dist/service.js
CHANGED
|
@@ -1744,6 +1744,14 @@ var ScheduleResource = class {
|
|
|
1744
1744
|
);
|
|
1745
1745
|
return response.run;
|
|
1746
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
|
+
}
|
|
1747
1755
|
async listRuns(options = {}) {
|
|
1748
1756
|
const { signal, ...query } = options;
|
|
1749
1757
|
const response = await this.transport.request(
|
|
@@ -1752,10 +1760,18 @@ var ScheduleResource = class {
|
|
|
1752
1760
|
);
|
|
1753
1761
|
return response.runs;
|
|
1754
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
|
+
}
|
|
1755
1771
|
async setRunUnread(id2, unread, options = {}) {
|
|
1756
1772
|
const response = await this.transport.request(
|
|
1757
1773
|
`/schedules/runs/${encodeURIComponent(id2)}/read`,
|
|
1758
|
-
{ method: "PATCH", body: { unread }, signal: options.signal }
|
|
1774
|
+
{ method: "PATCH", body: { unread, ...options.taskId === void 0 ? {} : { taskId: options.taskId } }, signal: options.signal }
|
|
1759
1775
|
);
|
|
1760
1776
|
return response.run;
|
|
1761
1777
|
}
|
|
@@ -1928,7 +1944,7 @@ function assertPromptMetadataAllowed(input) {
|
|
|
1928
1944
|
const field = `${namespace}.outputSchema`;
|
|
1929
1945
|
throw new DomainValidationError(`${field} is a stored snapshot; use explicit outputSchema`, field);
|
|
1930
1946
|
}
|
|
1931
|
-
for (const name of ["pluginUi", "uiAction", "pluginUiSubmission", "pluginAppAction", "pluginAppSubmission", "pluginAppSource", "consumedForkHistory", "executionBinding", "
|
|
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"]) {
|
|
1932
1948
|
if (Object.hasOwn(metadata, name)) {
|
|
1933
1949
|
const field = `${namespace}.${name}`;
|
|
1934
1950
|
throw new DomainValidationError(
|
|
@@ -3153,6 +3169,16 @@ var json = (value) => {
|
|
|
3153
3169
|
var jsonObject = (v) => !!v && typeof v === "object" && !Array.isArray(v) && json(v);
|
|
3154
3170
|
var wireConnection = object2({ connectionId: text2(256), baseUrl: text2(2048) });
|
|
3155
3171
|
|
|
3172
|
+
// ../domain-contracts/src/app-host/fetch.ts
|
|
3173
|
+
var FETCH_CHUNK_BYTES = 64 * 1024;
|
|
3174
|
+
var FETCH_INLINE_BODY_BYTES = 8 * 1024;
|
|
3175
|
+
var FETCH_METADATA_BYTES = 64 * 1024;
|
|
3176
|
+
|
|
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
|
+
|
|
3156
3182
|
// ../domain-contracts/src/app-host/workspace-conversations.ts
|
|
3157
3183
|
var validWorkspaceConversation = (value) => {
|
|
3158
3184
|
if (!object2(
|
|
@@ -3241,16 +3267,6 @@ function validSessionControlResult(method, value) {
|
|
|
3241
3267
|
return false;
|
|
3242
3268
|
}
|
|
3243
3269
|
|
|
3244
|
-
// ../domain-contracts/src/app-host/fetch.ts
|
|
3245
|
-
var FETCH_CHUNK_BYTES = 64 * 1024;
|
|
3246
|
-
var FETCH_INLINE_BODY_BYTES = 8 * 1024;
|
|
3247
|
-
var FETCH_METADATA_BYTES = 64 * 1024;
|
|
3248
|
-
|
|
3249
|
-
// ../domain-contracts/src/app-host/service-host-protocol.ts
|
|
3250
|
-
var SERVICE_HOST_MAX_FRAME_BYTES = 512 * 1024;
|
|
3251
|
-
var worktreeBody = { workspaceId: id, expectedHead: text2(256), branch: text2(1024) };
|
|
3252
|
-
var worktreeReceipt = object2({ requestId: id, state: enumeration("accepted", "completed", "failed", "unknown") }, { result: object2({ executionRoot: id, workspaceId: id, branch: text2(1024), sourceHead: text2(256) }) });
|
|
3253
|
-
|
|
3254
3270
|
// ../domain-contracts/src/app-host/model-providers.ts
|
|
3255
3271
|
var provider = text2(256);
|
|
3256
3272
|
var imageInputSupport = enumeration("native", "unsupported", "unknown");
|
|
@@ -3450,11 +3466,11 @@ function assertPositiveSafeInteger(value, field) {
|
|
|
3450
3466
|
}
|
|
3451
3467
|
}
|
|
3452
3468
|
async function throwResponseError(response) {
|
|
3453
|
-
|
|
3469
|
+
const text3 = await response.text().catch(() => "");
|
|
3470
|
+
let body = text3;
|
|
3454
3471
|
try {
|
|
3455
|
-
body =
|
|
3472
|
+
body = JSON.parse(text3);
|
|
3456
3473
|
} catch {
|
|
3457
|
-
body = await response.text().catch(() => "");
|
|
3458
3474
|
}
|
|
3459
3475
|
const message = body && typeof body === "object" && "error" in body && typeof body.error === "string" ? body.error : body && typeof body === "object" && "message" in body && typeof body.message === "string" ? body.message : `BobanNomi API request failed with ${response.status}`;
|
|
3460
3476
|
throw new BobanNomiApiError(message, response.status, body);
|
|
@@ -3537,42 +3553,26 @@ var HttpTransport = class {
|
|
|
3537
3553
|
return `${this.baseUrl}${resolvedPath}`;
|
|
3538
3554
|
}
|
|
3539
3555
|
async request(path2, options = {}) {
|
|
3540
|
-
const
|
|
3541
|
-
|
|
3542
|
-
options.signal?.throwIfAborted();
|
|
3543
|
-
const url = this.resolveUrl(path2, options.query);
|
|
3544
|
-
const hasJsonBody = options.body !== void 0;
|
|
3545
|
-
const headers2 = mergeHeaders(
|
|
3546
|
-
this.headers(hasJsonBody, options.auth ?? true),
|
|
3547
|
-
options.headers
|
|
3548
|
-
);
|
|
3549
|
-
if (business) headers2[PROTOCOL_VERSION_HEADER] = String(CURRENT_PROTOCOL_VERSION);
|
|
3550
|
-
const response = await this.fetchImpl(url, {
|
|
3551
|
-
method: options.method ?? "GET",
|
|
3552
|
-
headers: headers2,
|
|
3553
|
-
body: hasJsonBody ? JSON.stringify(options.body) : void 0,
|
|
3554
|
-
signal: options.signal
|
|
3555
|
-
});
|
|
3556
|
-
if (!response.ok) {
|
|
3557
|
-
await throwResponseError(response);
|
|
3558
|
-
}
|
|
3556
|
+
const { body, method, headers: headers2, signal, auth, query } = options;
|
|
3557
|
+
const response = await this.#send(path2, { method: method ?? "GET", headers: headers2, signal, auth, query }, { body });
|
|
3559
3558
|
return await response.json();
|
|
3560
3559
|
}
|
|
3561
3560
|
async requestUnknown(path2, options = {}) {
|
|
3562
3561
|
return this.request(path2, options);
|
|
3563
3562
|
}
|
|
3564
3563
|
async requestResponse(path2, options = {}) {
|
|
3564
|
+
return this.#send(path2, options);
|
|
3565
|
+
}
|
|
3566
|
+
async #send(path2, options, json2) {
|
|
3565
3567
|
const business = !this.isHandshakeExempt(path2);
|
|
3566
|
-
if (business) await this.ensureProtocol(options.signal ?? void 0);
|
|
3568
|
+
if (business && (!json2 || !this.protocolVerified)) await this.ensureProtocol(options.signal ?? void 0);
|
|
3567
3569
|
options.signal?.throwIfAborted();
|
|
3568
|
-
const
|
|
3569
|
-
const
|
|
3570
|
-
const
|
|
3570
|
+
const { query, auth, ...request } = options;
|
|
3571
|
+
const url = this.resolveUrl(path2, query);
|
|
3572
|
+
const hasJsonBody = json2?.body !== void 0;
|
|
3573
|
+
const headers2 = mergeHeaders(this.headers(hasJsonBody, auth ?? true), options.headers);
|
|
3571
3574
|
if (business) headers2[PROTOCOL_VERSION_HEADER] = String(CURRENT_PROTOCOL_VERSION);
|
|
3572
|
-
const init = {
|
|
3573
|
-
...options,
|
|
3574
|
-
headers: headers2
|
|
3575
|
-
};
|
|
3575
|
+
const init = json2 ? { ...request, headers: headers2, body: hasJsonBody ? JSON.stringify(json2.body) : void 0 } : { ...options, headers: headers2 };
|
|
3576
3576
|
if (isReadableStream(init.body) && !init.duplex) {
|
|
3577
3577
|
init.duplex = "half";
|
|
3578
3578
|
}
|
|
@@ -3640,28 +3640,9 @@ ${slice}` : slice;
|
|
|
3640
3640
|
return JSON.parse(data);
|
|
3641
3641
|
}
|
|
3642
3642
|
async function* streamServerSentEvents(open, decode = (value) => value) {
|
|
3643
|
-
const
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
try {
|
|
3647
|
-
while (true) {
|
|
3648
|
-
const chunk = await reader.read();
|
|
3649
|
-
if (chunk.done) break;
|
|
3650
|
-
buffer += decoder.decode(chunk.value, { stream: true });
|
|
3651
|
-
const frames = buffer.split(/\r?\n\r?\n/);
|
|
3652
|
-
buffer = frames.pop() ?? "";
|
|
3653
|
-
for (const frame of frames) {
|
|
3654
|
-
const event = parseSseFrame(frame);
|
|
3655
|
-
if (event !== void 0) yield decode(event);
|
|
3656
|
-
}
|
|
3657
|
-
}
|
|
3658
|
-
} finally {
|
|
3659
|
-
try {
|
|
3660
|
-
await reader.cancel();
|
|
3661
|
-
} catch {
|
|
3662
|
-
} finally {
|
|
3663
|
-
reader.releaseLock();
|
|
3664
|
-
}
|
|
3643
|
+
for await (const frame of readSseFrames(await open())) {
|
|
3644
|
+
const event = parseSseFrame(frame);
|
|
3645
|
+
if (event !== void 0) yield decode(event);
|
|
3665
3646
|
}
|
|
3666
3647
|
}
|
|
3667
3648
|
var SseTransport = class {
|
|
@@ -3669,9 +3650,6 @@ var SseTransport = class {
|
|
|
3669
3650
|
this.transport = transport;
|
|
3670
3651
|
}
|
|
3671
3652
|
transport;
|
|
3672
|
-
streamFromReader(open, decode = (val) => val) {
|
|
3673
|
-
return streamServerSentEvents(open, decode);
|
|
3674
|
-
}
|
|
3675
3653
|
async *stream(url, options = {}) {
|
|
3676
3654
|
let lastEventId = options.lastEventId;
|
|
3677
3655
|
let reconnectDelayMs = options.reconnectDelayMs ?? 250;
|
|
@@ -3707,17 +3685,17 @@ var SseTransport = class {
|
|
|
3707
3685
|
options.onOpen?.();
|
|
3708
3686
|
resetIdleTimer();
|
|
3709
3687
|
try {
|
|
3710
|
-
for await (const
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
|
|
3688
|
+
for await (const value of readSseFrames(response.body)) {
|
|
3689
|
+
resetIdleTimer();
|
|
3690
|
+
const frame = parseRawSseFrame(value);
|
|
3691
|
+
if (!frame) continue;
|
|
3714
3692
|
if (frame.retry !== void 0) reconnectDelayMs = frame.retry;
|
|
3715
3693
|
if (frame.data !== void 0) {
|
|
3716
|
-
const
|
|
3694
|
+
const value2 = (options.decode ?? ((value3) => value3))(
|
|
3717
3695
|
JSON.parse(frame.data)
|
|
3718
3696
|
);
|
|
3719
3697
|
if (frame.id !== void 0) lastEventId = frame.id;
|
|
3720
|
-
yield
|
|
3698
|
+
yield value2;
|
|
3721
3699
|
}
|
|
3722
3700
|
}
|
|
3723
3701
|
} catch (error) {
|
|
@@ -3733,7 +3711,7 @@ var SseTransport = class {
|
|
|
3733
3711
|
}
|
|
3734
3712
|
}
|
|
3735
3713
|
};
|
|
3736
|
-
async function*
|
|
3714
|
+
async function* readSseFrames(stream) {
|
|
3737
3715
|
const reader = stream.getReader();
|
|
3738
3716
|
const decoder = new TextDecoder();
|
|
3739
3717
|
let buffer = "";
|
|
@@ -3744,11 +3722,7 @@ async function* readRawSseFrames(stream, onFrame) {
|
|
|
3744
3722
|
buffer += decoder.decode(chunk.value, { stream: true });
|
|
3745
3723
|
const frames = buffer.split(/\r?\n\r?\n/);
|
|
3746
3724
|
buffer = frames.pop() ?? "";
|
|
3747
|
-
|
|
3748
|
-
onFrame?.();
|
|
3749
|
-
const frame = parseRawSseFrame(value);
|
|
3750
|
-
if (frame) yield frame;
|
|
3751
|
-
}
|
|
3725
|
+
yield* frames;
|
|
3752
3726
|
}
|
|
3753
3727
|
} finally {
|
|
3754
3728
|
try {
|
|
@@ -3820,6 +3794,185 @@ var RuntimeResource = class {
|
|
|
3820
3794
|
}
|
|
3821
3795
|
};
|
|
3822
3796
|
|
|
3797
|
+
// src/resources/session/session-request-id.ts
|
|
3798
|
+
var promptRequestCounter = 0;
|
|
3799
|
+
function createPromptRequestId() {
|
|
3800
|
+
if (typeof globalThis.crypto?.randomUUID === "function") {
|
|
3801
|
+
return globalThis.crypto.randomUUID();
|
|
3802
|
+
}
|
|
3803
|
+
promptRequestCounter += 1;
|
|
3804
|
+
return `prompt-${Date.now().toString(36)}-${promptRequestCounter.toString(36)}`;
|
|
3805
|
+
}
|
|
3806
|
+
|
|
3807
|
+
// src/resources/session/session-configuration-requests.ts
|
|
3808
|
+
async function getDraftComposerOptions(transport, input, options = {}) {
|
|
3809
|
+
if (!validSessionControlInput("sessions.getDraftComposerOptions", input))
|
|
3810
|
+
throw new ProtocolDataError("Invalid draft composer target");
|
|
3811
|
+
const { workspaceId, outsideProject, roleId } = input;
|
|
3812
|
+
const path2 = transport.path("/sessions/configuration-options", {
|
|
3813
|
+
kind: "draft",
|
|
3814
|
+
workspaceId,
|
|
3815
|
+
outsideProject,
|
|
3816
|
+
roleId: roleId ?? void 0
|
|
3817
|
+
});
|
|
3818
|
+
const result = await transport.request(path2, {
|
|
3819
|
+
signal: options.signal
|
|
3820
|
+
});
|
|
3821
|
+
if (!validSessionControlResult("sessions.getDraftComposerOptions", result) || result.source !== input.source) {
|
|
3822
|
+
throw new ProtocolDataError("Draft composer options do not match target");
|
|
3823
|
+
}
|
|
3824
|
+
return result;
|
|
3825
|
+
}
|
|
3826
|
+
async function create(transport, input, options = {}) {
|
|
3827
|
+
const response = await transport.request(
|
|
3828
|
+
"/sessions",
|
|
3829
|
+
{
|
|
3830
|
+
method: "POST",
|
|
3831
|
+
body: parseCreateSessionRequest({
|
|
3832
|
+
...input,
|
|
3833
|
+
id: input.id ?? createPromptRequestId(),
|
|
3834
|
+
requestId: input.requestId ?? createPromptRequestId()
|
|
3835
|
+
}),
|
|
3836
|
+
signal: options.signal
|
|
3837
|
+
}
|
|
3838
|
+
);
|
|
3839
|
+
return response.session;
|
|
3840
|
+
}
|
|
3841
|
+
async function getConfigurationOptions(transport, input, options = {}) {
|
|
3842
|
+
return transport.request(
|
|
3843
|
+
transport.path("/sessions/configuration-options", input),
|
|
3844
|
+
{ signal: options.signal }
|
|
3845
|
+
);
|
|
3846
|
+
}
|
|
3847
|
+
async function getCreationResult(transport, input, options = {}) {
|
|
3848
|
+
return transport.request("/sessions/creation-result", {
|
|
3849
|
+
method: "POST",
|
|
3850
|
+
body: input,
|
|
3851
|
+
signal: options.signal
|
|
3852
|
+
});
|
|
3853
|
+
}
|
|
3854
|
+
async function getConfiguration(transport, sessionId, options = {}) {
|
|
3855
|
+
const value = await transport.requestUnknown(
|
|
3856
|
+
`/sessions/${encodeURIComponent(sessionId)}/configuration`,
|
|
3857
|
+
{ signal: options.signal }
|
|
3858
|
+
);
|
|
3859
|
+
return decodeSessionConfigurationSnapshot(value);
|
|
3860
|
+
}
|
|
3861
|
+
async function configure(transport, sessionId, input, options = {}) {
|
|
3862
|
+
const body = parseConfigureSessionRequest(input);
|
|
3863
|
+
const response = await transport.requestUnknown(
|
|
3864
|
+
`/sessions/${encodeURIComponent(sessionId)}/configure`,
|
|
3865
|
+
{ method: "POST", body, signal: options.signal }
|
|
3866
|
+
);
|
|
3867
|
+
return decodeSessionConfigurationReceipt(response, {
|
|
3868
|
+
sessionId,
|
|
3869
|
+
requestId: body.requestId
|
|
3870
|
+
});
|
|
3871
|
+
}
|
|
3872
|
+
async function getConfigurationResult(transport, sessionId, input, options = {}) {
|
|
3873
|
+
const body = parseConfigurationResultRequest(input);
|
|
3874
|
+
const response = await transport.requestUnknown(
|
|
3875
|
+
`/sessions/${encodeURIComponent(sessionId)}/configuration-result`,
|
|
3876
|
+
{ method: "POST", body, signal: options.signal }
|
|
3877
|
+
);
|
|
3878
|
+
return response === null ? null : decodeSessionConfigurationReceipt(response, {
|
|
3879
|
+
sessionId,
|
|
3880
|
+
requestId: body.requestId
|
|
3881
|
+
});
|
|
3882
|
+
}
|
|
3883
|
+
|
|
3884
|
+
// src/resources/session/session-run-requests.ts
|
|
3885
|
+
function checkOutputSchema(transport, input, signal) {
|
|
3886
|
+
assertPromptMetadataAllowed2(input);
|
|
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
|
+
|
|
3823
3976
|
// src/resources/session/session-terminal-resource.ts
|
|
3824
3977
|
var SessionTerminalResource = class {
|
|
3825
3978
|
constructor(transport) {
|
|
@@ -3899,14 +4052,6 @@ var SessionManagementResource = class {
|
|
|
3899
4052
|
};
|
|
3900
4053
|
|
|
3901
4054
|
// src/resources/session/session-resource.ts
|
|
3902
|
-
var promptRequestCounter = 0;
|
|
3903
|
-
function createPromptRequestId() {
|
|
3904
|
-
if (typeof globalThis.crypto?.randomUUID === "function") {
|
|
3905
|
-
return globalThis.crypto.randomUUID();
|
|
3906
|
-
}
|
|
3907
|
-
promptRequestCounter += 1;
|
|
3908
|
-
return `prompt-${Date.now().toString(36)}-${promptRequestCounter.toString(36)}`;
|
|
3909
|
-
}
|
|
3910
4055
|
var SessionResource = class {
|
|
3911
4056
|
constructor(transport) {
|
|
3912
4057
|
this.transport = transport;
|
|
@@ -3916,17 +4061,6 @@ var SessionResource = class {
|
|
|
3916
4061
|
transport;
|
|
3917
4062
|
resources;
|
|
3918
4063
|
terminals;
|
|
3919
|
-
checkOutputSchema(input, signal) {
|
|
3920
|
-
assertPromptMetadataAllowed2(input);
|
|
3921
|
-
if (input.outputSchema === void 0) return;
|
|
3922
|
-
return this.transport.ensureProtocol(signal).then((capabilities) => {
|
|
3923
|
-
if ((capabilities.features.structuredDelivery ?? 0) < 1) {
|
|
3924
|
-
throw new Error(
|
|
3925
|
-
"Server does not support structured delivery (outputSchema)"
|
|
3926
|
-
);
|
|
3927
|
-
}
|
|
3928
|
-
});
|
|
3929
|
-
}
|
|
3930
4064
|
/** `GET /sessions/search` - search saved conversation text without opening it. */
|
|
3931
4065
|
async search(options) {
|
|
3932
4066
|
const { signal, ...query } = options;
|
|
@@ -3951,23 +4085,8 @@ var SessionResource = class {
|
|
|
3951
4085
|
signal: options.signal
|
|
3952
4086
|
});
|
|
3953
4087
|
}
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
throw new ProtocolDataError("Invalid draft composer target");
|
|
3957
|
-
const { workspaceId, outsideProject, roleId } = input;
|
|
3958
|
-
const path2 = this.transport.path("/sessions/configuration-options", {
|
|
3959
|
-
kind: "draft",
|
|
3960
|
-
workspaceId,
|
|
3961
|
-
outsideProject,
|
|
3962
|
-
roleId: roleId ?? void 0
|
|
3963
|
-
});
|
|
3964
|
-
const result = await this.transport.request(path2, {
|
|
3965
|
-
signal: options.signal
|
|
3966
|
-
});
|
|
3967
|
-
if (!validSessionControlResult("sessions.getDraftComposerOptions", result) || result.source !== input.source) {
|
|
3968
|
-
throw new ProtocolDataError("Draft composer options do not match target");
|
|
3969
|
-
}
|
|
3970
|
-
return result;
|
|
4088
|
+
getDraftComposerOptions(input, options = {}) {
|
|
4089
|
+
return getDraftComposerOptions(this.transport, input, options);
|
|
3971
4090
|
}
|
|
3972
4091
|
async getControls(sessionId, options = {}) {
|
|
3973
4092
|
const result = await this.transport.request(
|
|
@@ -4014,62 +4133,23 @@ var SessionResource = class {
|
|
|
4014
4133
|
return response.session;
|
|
4015
4134
|
}
|
|
4016
4135
|
/** `POST /sessions` */
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
"/sessions",
|
|
4020
|
-
{
|
|
4021
|
-
method: "POST",
|
|
4022
|
-
body: parseCreateSessionRequest({
|
|
4023
|
-
...input,
|
|
4024
|
-
id: input.id ?? createPromptRequestId(),
|
|
4025
|
-
requestId: input.requestId ?? createPromptRequestId()
|
|
4026
|
-
}),
|
|
4027
|
-
signal: options.signal
|
|
4028
|
-
}
|
|
4029
|
-
);
|
|
4030
|
-
return response.session;
|
|
4136
|
+
create(input, options = {}) {
|
|
4137
|
+
return create(this.transport, input, options);
|
|
4031
4138
|
}
|
|
4032
|
-
|
|
4033
|
-
return this.transport
|
|
4034
|
-
this.transport.path("/sessions/configuration-options", input),
|
|
4035
|
-
{ signal: options.signal }
|
|
4036
|
-
);
|
|
4139
|
+
getConfigurationOptions(input, options = {}) {
|
|
4140
|
+
return getConfigurationOptions(this.transport, input, options);
|
|
4037
4141
|
}
|
|
4038
|
-
|
|
4039
|
-
return this.transport
|
|
4040
|
-
method: "POST",
|
|
4041
|
-
body: input,
|
|
4042
|
-
signal: options.signal
|
|
4043
|
-
});
|
|
4142
|
+
getCreationResult(input, options = {}) {
|
|
4143
|
+
return getCreationResult(this.transport, input, options);
|
|
4044
4144
|
}
|
|
4045
|
-
|
|
4046
|
-
|
|
4047
|
-
`/sessions/${encodeURIComponent(sessionId)}/configuration`,
|
|
4048
|
-
{ signal: options.signal }
|
|
4049
|
-
);
|
|
4050
|
-
return decodeSessionConfigurationSnapshot(value);
|
|
4145
|
+
getConfiguration(sessionId, options = {}) {
|
|
4146
|
+
return getConfiguration(this.transport, sessionId, options);
|
|
4051
4147
|
}
|
|
4052
|
-
|
|
4053
|
-
|
|
4054
|
-
const response = await this.transport.requestUnknown(
|
|
4055
|
-
`/sessions/${encodeURIComponent(sessionId)}/configure`,
|
|
4056
|
-
{ method: "POST", body, signal: options.signal }
|
|
4057
|
-
);
|
|
4058
|
-
return decodeSessionConfigurationReceipt(response, {
|
|
4059
|
-
sessionId,
|
|
4060
|
-
requestId: body.requestId
|
|
4061
|
-
});
|
|
4148
|
+
configure(sessionId, input, options = {}) {
|
|
4149
|
+
return configure(this.transport, sessionId, input, options);
|
|
4062
4150
|
}
|
|
4063
|
-
|
|
4064
|
-
|
|
4065
|
-
const response = await this.transport.requestUnknown(
|
|
4066
|
-
`/sessions/${encodeURIComponent(sessionId)}/configuration-result`,
|
|
4067
|
-
{ method: "POST", body, signal: options.signal }
|
|
4068
|
-
);
|
|
4069
|
-
return response === null ? null : decodeSessionConfigurationReceipt(response, {
|
|
4070
|
-
sessionId,
|
|
4071
|
-
requestId: body.requestId
|
|
4072
|
-
});
|
|
4151
|
+
getConfigurationResult(sessionId, input, options = {}) {
|
|
4152
|
+
return getConfigurationResult(this.transport, sessionId, input, options);
|
|
4073
4153
|
}
|
|
4074
4154
|
/** `PATCH /sessions/:id` - update title or application metadata. */
|
|
4075
4155
|
async update(sessionId, input, options = {}) {
|
|
@@ -4163,88 +4243,30 @@ var SessionResource = class {
|
|
|
4163
4243
|
return response.part;
|
|
4164
4244
|
}
|
|
4165
4245
|
/** `POST /sessions/:id/prompts` — 提交用户输入并触发/排队一次 run。 */
|
|
4166
|
-
|
|
4167
|
-
|
|
4168
|
-
if (schemaCheck) await schemaCheck;
|
|
4169
|
-
return await this.transport.request(
|
|
4170
|
-
`/sessions/${encodeURIComponent(sessionId)}/prompts`,
|
|
4171
|
-
{
|
|
4172
|
-
method: "POST",
|
|
4173
|
-
body: { ...input, id: input.id ?? createPromptRequestId() },
|
|
4174
|
-
signal: options.signal
|
|
4175
|
-
}
|
|
4176
|
-
);
|
|
4246
|
+
admitPrompt(sessionId, input, options = {}) {
|
|
4247
|
+
return admitPrompt(this.transport, sessionId, input, options);
|
|
4177
4248
|
}
|
|
4178
4249
|
/** `POST /sessions/:id/prompts/latest/edit` */
|
|
4179
|
-
|
|
4180
|
-
|
|
4181
|
-
return await this.transport.request(
|
|
4182
|
-
`/sessions/${encodeURIComponent(sessionId)}/prompts/latest/edit`,
|
|
4183
|
-
{
|
|
4184
|
-
method: "POST",
|
|
4185
|
-
body: input,
|
|
4186
|
-
signal: options.signal
|
|
4187
|
-
}
|
|
4188
|
-
);
|
|
4250
|
+
editLatestPrompt(sessionId, input, options = {}) {
|
|
4251
|
+
return editLatestPrompt(this.transport, sessionId, input, options);
|
|
4189
4252
|
}
|
|
4190
4253
|
/** Promote one durable queued prompt into the exact active run. */
|
|
4191
|
-
|
|
4192
|
-
return
|
|
4193
|
-
`/sessions/${encodeURIComponent(sessionId)}/prompts/${encodeURIComponent(inputId)}/promote`,
|
|
4194
|
-
{ method: "POST", body: input, signal: options.signal }
|
|
4195
|
-
);
|
|
4254
|
+
promoteQueuedPrompt(sessionId, inputId, input, options = {}) {
|
|
4255
|
+
return promoteQueuedPrompt(this.transport, sessionId, inputId, input, options);
|
|
4196
4256
|
}
|
|
4197
|
-
|
|
4198
|
-
|
|
4199
|
-
const response = await this.transport.request(
|
|
4200
|
-
`/sessions/${encodeURIComponent(sessionId)}/prompts/${encodeURIComponent(inputId)}/cancel`,
|
|
4201
|
-
{
|
|
4202
|
-
method: "POST",
|
|
4203
|
-
body: {
|
|
4204
|
-
...input,
|
|
4205
|
-
...options.responseMode ? { responseMode: mode } : {}
|
|
4206
|
-
},
|
|
4207
|
-
signal: options.signal
|
|
4208
|
-
}
|
|
4209
|
-
);
|
|
4210
|
-
if (mode === "receipt") {
|
|
4211
|
-
const receipt2 = decodeQueuedPromptCancelReceipt(response);
|
|
4212
|
-
if (receipt2.inputId !== inputId || receipt2.queuedRunId !== input.queuedRunId)
|
|
4213
|
-
throw new ProtocolDataError(
|
|
4214
|
-
"Cancellation receipt does not match target"
|
|
4215
|
-
);
|
|
4216
|
-
return receipt2;
|
|
4217
|
-
}
|
|
4218
|
-
return response;
|
|
4257
|
+
cancelQueuedPrompt(sessionId, inputId, input, options = {}) {
|
|
4258
|
+
return cancelQueuedPrompt(this.transport, sessionId, inputId, input, options);
|
|
4219
4259
|
}
|
|
4220
4260
|
/**
|
|
4221
4261
|
* `POST /sessions/:id/runs/:runId/resume` — 显式重放一次中断 run 的原始 prompt。
|
|
4222
|
-
*
|
|
4262
|
+
* 服务端复用原 Input,创建一个带恢复来源的新 Run。旧模型连接已经结束。
|
|
4223
4263
|
*/
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
return await this.transport.request(
|
|
4227
|
-
`/sessions/${encodeURIComponent(sessionId)}/runs/${encodeURIComponent(runId)}/resume`,
|
|
4228
|
-
{
|
|
4229
|
-
method: "POST",
|
|
4230
|
-
body: { ...input, id: input.id ?? createPromptRequestId() },
|
|
4231
|
-
signal: options.signal
|
|
4232
|
-
}
|
|
4233
|
-
);
|
|
4264
|
+
resumeInterruptedRun(sessionId, runId, input = {}, options = {}) {
|
|
4265
|
+
return resumeInterruptedRun(this.transport, sessionId, runId, input, options);
|
|
4234
4266
|
}
|
|
4235
4267
|
/** `POST /sessions/:id/interrupt` — 中断当前/排队中的 run。 */
|
|
4236
|
-
|
|
4237
|
-
return
|
|
4238
|
-
`/sessions/${encodeURIComponent(sessionId)}/interrupt`,
|
|
4239
|
-
{
|
|
4240
|
-
method: "POST",
|
|
4241
|
-
body: options.expectedRunId || options.source ? {
|
|
4242
|
-
...options.expectedRunId ? { expectedRunId: options.expectedRunId } : {},
|
|
4243
|
-
...options.source ? { source: options.source } : {}
|
|
4244
|
-
} : void 0,
|
|
4245
|
-
signal: options.signal
|
|
4246
|
-
}
|
|
4247
|
-
);
|
|
4268
|
+
interrupt(sessionId, options = {}) {
|
|
4269
|
+
return interrupt(this.transport, sessionId, options);
|
|
4248
4270
|
}
|
|
4249
4271
|
/** `POST /sessions/:id/compact` */
|
|
4250
4272
|
async compact(sessionId, options = {}) {
|
|
@@ -4648,8 +4670,8 @@ function startProcess(command, cwd, env) {
|
|
|
4648
4670
|
shell: false
|
|
4649
4671
|
});
|
|
4650
4672
|
let failure;
|
|
4651
|
-
child.
|
|
4652
|
-
failure
|
|
4673
|
+
child.on("error", () => {
|
|
4674
|
+
failure ??= new Error("Cannot spawn BobanNomi service executable.");
|
|
4653
4675
|
});
|
|
4654
4676
|
child.once("exit", (code, signal) => {
|
|
4655
4677
|
failure ??= new Error(`BobanNomi service exited before registration (${signal ?? code}).`);
|
|
@@ -4662,7 +4684,6 @@ async function abandonProcess(child) {
|
|
|
4662
4684
|
await new Promise((resolve5) => {
|
|
4663
4685
|
const timer = setTimeout(() => {
|
|
4664
4686
|
child.kill("SIGKILL");
|
|
4665
|
-
resolve5();
|
|
4666
4687
|
}, 500);
|
|
4667
4688
|
child.once("exit", () => {
|
|
4668
4689
|
clearTimeout(timer);
|
|
@@ -4716,9 +4737,19 @@ function sameInstance(left, right) {
|
|
|
4716
4737
|
|
|
4717
4738
|
// src/service/startup-lock.ts
|
|
4718
4739
|
var import_proper_lockfile = __toESM(require_proper_lockfile(), 1);
|
|
4719
|
-
import { mkdir } from "node:fs/promises";
|
|
4740
|
+
import { lstat, mkdir } from "node:fs/promises";
|
|
4720
4741
|
import { dirname as dirname2 } from "node:path";
|
|
4721
4742
|
import { setTimeout as sleep } from "node:timers/promises";
|
|
4743
|
+
var startupLockPath = (file) => `${file}.sdk-start.lock`;
|
|
4744
|
+
async function hasStartupLock(file) {
|
|
4745
|
+
try {
|
|
4746
|
+
await lstat(startupLockPath(file));
|
|
4747
|
+
return true;
|
|
4748
|
+
} catch (error) {
|
|
4749
|
+
if (error.code === "ENOENT") return false;
|
|
4750
|
+
throw error;
|
|
4751
|
+
}
|
|
4752
|
+
}
|
|
4722
4753
|
async function acquireStartupLock(file, end, signal) {
|
|
4723
4754
|
await mkdir(dirname2(file), { recursive: true });
|
|
4724
4755
|
const compromised = new AbortController();
|
|
@@ -4727,7 +4758,7 @@ async function acquireStartupLock(file, end, signal) {
|
|
|
4727
4758
|
try {
|
|
4728
4759
|
const release = await (0, import_proper_lockfile.lock)(file, {
|
|
4729
4760
|
realpath: false,
|
|
4730
|
-
lockfilePath:
|
|
4761
|
+
lockfilePath: startupLockPath(file),
|
|
4731
4762
|
stale: 1e4,
|
|
4732
4763
|
update: 5e3,
|
|
4733
4764
|
retries: 0,
|
|
@@ -4812,6 +4843,7 @@ async function realpathAllowMissing(path2) {
|
|
|
4812
4843
|
}
|
|
4813
4844
|
}
|
|
4814
4845
|
var startups = /* @__PURE__ */ new Map();
|
|
4846
|
+
var STARTUP_CLEANUP_TIMEOUT_MS = 2e3;
|
|
4815
4847
|
function waitForStartup(pending, signal) {
|
|
4816
4848
|
signal?.throwIfAborted();
|
|
4817
4849
|
if (!signal) return pending;
|
|
@@ -4827,11 +4859,14 @@ async function ensure(options = {}) {
|
|
|
4827
4859
|
const env = { ...process.env, ...options.env };
|
|
4828
4860
|
const { file, paths } = await serviceLocation(options.file, env);
|
|
4829
4861
|
const existing = await discoverAt({ ...options, file, paths });
|
|
4830
|
-
if (existing)
|
|
4862
|
+
if (existing && !await hasStartupLock(file) && sameInstance(existing, await readEndpoint(file)) && pidAlive(existing.pid)) {
|
|
4863
|
+
options.signal?.throwIfAborted();
|
|
4864
|
+
return existing;
|
|
4865
|
+
}
|
|
4831
4866
|
let pending = startups.get(file);
|
|
4832
4867
|
const joining = pending !== void 0;
|
|
4833
4868
|
if (!pending) {
|
|
4834
|
-
pending = startService({ ...options, file, paths }, env).finally(() => {
|
|
4869
|
+
pending = startService({ ...options, file, paths }, env, existing !== void 0).finally(() => {
|
|
4835
4870
|
startups.delete(file);
|
|
4836
4871
|
});
|
|
4837
4872
|
startups.set(file, pending);
|
|
@@ -4845,52 +4880,71 @@ async function ensure(options = {}) {
|
|
|
4845
4880
|
}
|
|
4846
4881
|
return endpoint;
|
|
4847
4882
|
}
|
|
4848
|
-
async function startService(options, env) {
|
|
4883
|
+
async function startService(options, env, mayReuseRegistration) {
|
|
4849
4884
|
const end = Date.now() + timeout(options.timeoutMs, 1e4);
|
|
4850
|
-
|
|
4851
|
-
|
|
4852
|
-
|
|
4885
|
+
const checkStartupCommand = async () => {
|
|
4886
|
+
if (!options.command && !options.paths && options.file !== (await serviceLocation(void 0, env)).file) {
|
|
4887
|
+
throw new Error("A custom registry file requires a command that writes it, or a matching BOBANNOMI_CONFIG_DIR.");
|
|
4888
|
+
}
|
|
4889
|
+
};
|
|
4890
|
+
if (!mayReuseRegistration) await checkStartupCommand();
|
|
4853
4891
|
if (options.paths) env.BOBANNOMI_CONFIG_DIR = selectDataRoot(void 0, env);
|
|
4854
4892
|
options.signal?.throwIfAborted();
|
|
4855
4893
|
const lease = await acquireStartupLock(options.file, end, options.signal);
|
|
4894
|
+
let started;
|
|
4895
|
+
let backgroundCleanup;
|
|
4856
4896
|
try {
|
|
4857
4897
|
const locked = { ...options, signal: lease.signal };
|
|
4858
4898
|
const existing = await discoverAt({ ...locked, timeoutMs: Math.max(1, Math.min(1e3, end - Date.now())) });
|
|
4859
4899
|
if (existing) return existing;
|
|
4860
|
-
|
|
4861
|
-
|
|
4862
|
-
|
|
4863
|
-
|
|
4864
|
-
|
|
4865
|
-
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
const cwd = resolve4(options.cwd ?? process.cwd());
|
|
4872
|
-
const command = options.command ?? await defaultCommand(cwd, selectDataRoot(void 0, env));
|
|
4873
|
-
options.signal?.throwIfAborted();
|
|
4874
|
-
if (Date.now() >= end) throw new Error("BobanNomi service startup timed out before process creation.");
|
|
4875
|
-
const started = startProcess(command, cwd, env);
|
|
4876
|
-
try {
|
|
4900
|
+
if (mayReuseRegistration) await checkStartupCommand();
|
|
4901
|
+
const previous = await readEndpoint(locked.file);
|
|
4902
|
+
if (previous && pidAlive(previous.pid))
|
|
4903
|
+
throw new Error("Registered BobanNomi service is incompatible or unhealthy; manage it explicitly before starting another.");
|
|
4904
|
+
if (!previous && await access(locked.file).then(() => true, () => false))
|
|
4905
|
+
throw new Error("BobanNomi registry is malformed; inspect it before starting a service.");
|
|
4906
|
+
const cwd = resolve4(locked.cwd ?? process.cwd());
|
|
4907
|
+
const command = locked.command ?? await defaultCommand(cwd, selectDataRoot(void 0, env));
|
|
4908
|
+
locked.signal.throwIfAborted();
|
|
4909
|
+
if (Date.now() >= end) throw new Error("BobanNomi service startup timed out before process creation.");
|
|
4910
|
+
started = startProcess(command, cwd, env);
|
|
4877
4911
|
while (Date.now() < end) {
|
|
4878
|
-
|
|
4879
|
-
const endpoint = await discoverAt({ ...
|
|
4912
|
+
locked.signal.throwIfAborted();
|
|
4913
|
+
const endpoint = await discoverAt({ ...locked, timeoutMs: Math.max(1, Math.min(1e3, end - Date.now())) });
|
|
4880
4914
|
if (endpoint && !sameInstance(endpoint, previous)) return endpoint;
|
|
4881
4915
|
const failure = started.failure();
|
|
4882
4916
|
if (failure) throw failure;
|
|
4883
|
-
await sleep2(Math.min(50, Math.max(1, end - Date.now())), void 0, { signal:
|
|
4917
|
+
await sleep2(Math.min(50, Math.max(1, end - Date.now())), void 0, { signal: locked.signal });
|
|
4884
4918
|
}
|
|
4885
4919
|
throw new Error("BobanNomi service startup timed out before compatible registration.");
|
|
4886
4920
|
} catch (error) {
|
|
4887
|
-
|
|
4888
|
-
|
|
4889
|
-
|
|
4890
|
-
|
|
4891
|
-
|
|
4921
|
+
if (started) {
|
|
4922
|
+
const cleanup = cleanFailedStartup(options.file, started.child);
|
|
4923
|
+
const timer = new AbortController();
|
|
4924
|
+
const completed = await Promise.race([
|
|
4925
|
+
cleanup.then(() => true),
|
|
4926
|
+
sleep2(STARTUP_CLEANUP_TIMEOUT_MS, false, { signal: timer.signal })
|
|
4927
|
+
]).finally(() => timer.abort());
|
|
4928
|
+
if (!completed) {
|
|
4929
|
+
backgroundCleanup = cleanup;
|
|
4930
|
+
throw new Error("Could not confirm the BobanNomi service process exited after forced termination.", { cause: error });
|
|
4931
|
+
}
|
|
4892
4932
|
}
|
|
4893
4933
|
throw error;
|
|
4934
|
+
} finally {
|
|
4935
|
+
if (backgroundCleanup) {
|
|
4936
|
+
void backgroundCleanup.finally(lease.release).catch(() => void 0);
|
|
4937
|
+
} else {
|
|
4938
|
+
await lease.release();
|
|
4939
|
+
}
|
|
4940
|
+
}
|
|
4941
|
+
}
|
|
4942
|
+
async function cleanFailedStartup(file, child) {
|
|
4943
|
+
await abandonProcess(child);
|
|
4944
|
+
const current = await readEndpoint(file);
|
|
4945
|
+
if (current && current.pid === child.pid && !pidAlive(current.pid) && sameInstance(current, await readEndpoint(file))) {
|
|
4946
|
+
await unlink(file).catch(() => {
|
|
4947
|
+
});
|
|
4894
4948
|
}
|
|
4895
4949
|
}
|
|
4896
4950
|
async function stop(endpoint, options = {}) {
|