@bobannomi/client 0.1.0 → 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 +87 -76
- package/dist/index.js +274 -233
- package/dist/index.js.map +3 -3
- package/dist/service.js +317 -260
- 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(
|
|
@@ -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 {
|
|
@@ -3704,17 +3685,17 @@ var SseTransport = class {
|
|
|
3704
3685
|
options.onOpen?.();
|
|
3705
3686
|
resetIdleTimer();
|
|
3706
3687
|
try {
|
|
3707
|
-
for await (const
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3688
|
+
for await (const value of readSseFrames(response.body)) {
|
|
3689
|
+
resetIdleTimer();
|
|
3690
|
+
const frame = parseRawSseFrame(value);
|
|
3691
|
+
if (!frame) continue;
|
|
3711
3692
|
if (frame.retry !== void 0) reconnectDelayMs = frame.retry;
|
|
3712
3693
|
if (frame.data !== void 0) {
|
|
3713
|
-
const
|
|
3694
|
+
const value2 = (options.decode ?? ((value3) => value3))(
|
|
3714
3695
|
JSON.parse(frame.data)
|
|
3715
3696
|
);
|
|
3716
3697
|
if (frame.id !== void 0) lastEventId = frame.id;
|
|
3717
|
-
yield
|
|
3698
|
+
yield value2;
|
|
3718
3699
|
}
|
|
3719
3700
|
}
|
|
3720
3701
|
} catch (error) {
|
|
@@ -3730,7 +3711,7 @@ var SseTransport = class {
|
|
|
3730
3711
|
}
|
|
3731
3712
|
}
|
|
3732
3713
|
};
|
|
3733
|
-
async function*
|
|
3714
|
+
async function* readSseFrames(stream) {
|
|
3734
3715
|
const reader = stream.getReader();
|
|
3735
3716
|
const decoder = new TextDecoder();
|
|
3736
3717
|
let buffer = "";
|
|
@@ -3741,11 +3722,7 @@ async function* readRawSseFrames(stream, onFrame) {
|
|
|
3741
3722
|
buffer += decoder.decode(chunk.value, { stream: true });
|
|
3742
3723
|
const frames = buffer.split(/\r?\n\r?\n/);
|
|
3743
3724
|
buffer = frames.pop() ?? "";
|
|
3744
|
-
|
|
3745
|
-
onFrame?.();
|
|
3746
|
-
const frame = parseRawSseFrame(value);
|
|
3747
|
-
if (frame) yield frame;
|
|
3748
|
-
}
|
|
3725
|
+
yield* frames;
|
|
3749
3726
|
}
|
|
3750
3727
|
} finally {
|
|
3751
3728
|
try {
|
|
@@ -3817,6 +3794,185 @@ var RuntimeResource = class {
|
|
|
3817
3794
|
}
|
|
3818
3795
|
};
|
|
3819
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
|
+
|
|
3820
3976
|
// src/resources/session/session-terminal-resource.ts
|
|
3821
3977
|
var SessionTerminalResource = class {
|
|
3822
3978
|
constructor(transport) {
|
|
@@ -3896,14 +4052,6 @@ var SessionManagementResource = class {
|
|
|
3896
4052
|
};
|
|
3897
4053
|
|
|
3898
4054
|
// src/resources/session/session-resource.ts
|
|
3899
|
-
var promptRequestCounter = 0;
|
|
3900
|
-
function createPromptRequestId() {
|
|
3901
|
-
if (typeof globalThis.crypto?.randomUUID === "function") {
|
|
3902
|
-
return globalThis.crypto.randomUUID();
|
|
3903
|
-
}
|
|
3904
|
-
promptRequestCounter += 1;
|
|
3905
|
-
return `prompt-${Date.now().toString(36)}-${promptRequestCounter.toString(36)}`;
|
|
3906
|
-
}
|
|
3907
4055
|
var SessionResource = class {
|
|
3908
4056
|
constructor(transport) {
|
|
3909
4057
|
this.transport = transport;
|
|
@@ -3913,17 +4061,6 @@ var SessionResource = class {
|
|
|
3913
4061
|
transport;
|
|
3914
4062
|
resources;
|
|
3915
4063
|
terminals;
|
|
3916
|
-
checkOutputSchema(input, signal) {
|
|
3917
|
-
assertPromptMetadataAllowed2(input);
|
|
3918
|
-
if (input.outputSchema === void 0) return;
|
|
3919
|
-
return this.transport.ensureProtocol(signal).then((capabilities) => {
|
|
3920
|
-
if ((capabilities.features.structuredDelivery ?? 0) < 1) {
|
|
3921
|
-
throw new Error(
|
|
3922
|
-
"Server does not support structured delivery (outputSchema)"
|
|
3923
|
-
);
|
|
3924
|
-
}
|
|
3925
|
-
});
|
|
3926
|
-
}
|
|
3927
4064
|
/** `GET /sessions/search` - search saved conversation text without opening it. */
|
|
3928
4065
|
async search(options) {
|
|
3929
4066
|
const { signal, ...query } = options;
|
|
@@ -3948,23 +4085,8 @@ var SessionResource = class {
|
|
|
3948
4085
|
signal: options.signal
|
|
3949
4086
|
});
|
|
3950
4087
|
}
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
throw new ProtocolDataError("Invalid draft composer target");
|
|
3954
|
-
const { workspaceId, outsideProject, roleId } = input;
|
|
3955
|
-
const path2 = this.transport.path("/sessions/configuration-options", {
|
|
3956
|
-
kind: "draft",
|
|
3957
|
-
workspaceId,
|
|
3958
|
-
outsideProject,
|
|
3959
|
-
roleId: roleId ?? void 0
|
|
3960
|
-
});
|
|
3961
|
-
const result = await this.transport.request(path2, {
|
|
3962
|
-
signal: options.signal
|
|
3963
|
-
});
|
|
3964
|
-
if (!validSessionControlResult("sessions.getDraftComposerOptions", result) || result.source !== input.source) {
|
|
3965
|
-
throw new ProtocolDataError("Draft composer options do not match target");
|
|
3966
|
-
}
|
|
3967
|
-
return result;
|
|
4088
|
+
getDraftComposerOptions(input, options = {}) {
|
|
4089
|
+
return getDraftComposerOptions(this.transport, input, options);
|
|
3968
4090
|
}
|
|
3969
4091
|
async getControls(sessionId, options = {}) {
|
|
3970
4092
|
const result = await this.transport.request(
|
|
@@ -4011,62 +4133,23 @@ var SessionResource = class {
|
|
|
4011
4133
|
return response.session;
|
|
4012
4134
|
}
|
|
4013
4135
|
/** `POST /sessions` */
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
"/sessions",
|
|
4017
|
-
{
|
|
4018
|
-
method: "POST",
|
|
4019
|
-
body: parseCreateSessionRequest({
|
|
4020
|
-
...input,
|
|
4021
|
-
id: input.id ?? createPromptRequestId(),
|
|
4022
|
-
requestId: input.requestId ?? createPromptRequestId()
|
|
4023
|
-
}),
|
|
4024
|
-
signal: options.signal
|
|
4025
|
-
}
|
|
4026
|
-
);
|
|
4027
|
-
return response.session;
|
|
4136
|
+
create(input, options = {}) {
|
|
4137
|
+
return create(this.transport, input, options);
|
|
4028
4138
|
}
|
|
4029
|
-
|
|
4030
|
-
return this.transport
|
|
4031
|
-
this.transport.path("/sessions/configuration-options", input),
|
|
4032
|
-
{ signal: options.signal }
|
|
4033
|
-
);
|
|
4139
|
+
getConfigurationOptions(input, options = {}) {
|
|
4140
|
+
return getConfigurationOptions(this.transport, input, options);
|
|
4034
4141
|
}
|
|
4035
|
-
|
|
4036
|
-
return this.transport
|
|
4037
|
-
method: "POST",
|
|
4038
|
-
body: input,
|
|
4039
|
-
signal: options.signal
|
|
4040
|
-
});
|
|
4142
|
+
getCreationResult(input, options = {}) {
|
|
4143
|
+
return getCreationResult(this.transport, input, options);
|
|
4041
4144
|
}
|
|
4042
|
-
|
|
4043
|
-
|
|
4044
|
-
`/sessions/${encodeURIComponent(sessionId)}/configuration`,
|
|
4045
|
-
{ signal: options.signal }
|
|
4046
|
-
);
|
|
4047
|
-
return decodeSessionConfigurationSnapshot(value);
|
|
4145
|
+
getConfiguration(sessionId, options = {}) {
|
|
4146
|
+
return getConfiguration(this.transport, sessionId, options);
|
|
4048
4147
|
}
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
const response = await this.transport.requestUnknown(
|
|
4052
|
-
`/sessions/${encodeURIComponent(sessionId)}/configure`,
|
|
4053
|
-
{ method: "POST", body, signal: options.signal }
|
|
4054
|
-
);
|
|
4055
|
-
return decodeSessionConfigurationReceipt(response, {
|
|
4056
|
-
sessionId,
|
|
4057
|
-
requestId: body.requestId
|
|
4058
|
-
});
|
|
4148
|
+
configure(sessionId, input, options = {}) {
|
|
4149
|
+
return configure(this.transport, sessionId, input, options);
|
|
4059
4150
|
}
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
const response = await this.transport.requestUnknown(
|
|
4063
|
-
`/sessions/${encodeURIComponent(sessionId)}/configuration-result`,
|
|
4064
|
-
{ method: "POST", body, signal: options.signal }
|
|
4065
|
-
);
|
|
4066
|
-
return response === null ? null : decodeSessionConfigurationReceipt(response, {
|
|
4067
|
-
sessionId,
|
|
4068
|
-
requestId: body.requestId
|
|
4069
|
-
});
|
|
4151
|
+
getConfigurationResult(sessionId, input, options = {}) {
|
|
4152
|
+
return getConfigurationResult(this.transport, sessionId, input, options);
|
|
4070
4153
|
}
|
|
4071
4154
|
/** `PATCH /sessions/:id` - update title or application metadata. */
|
|
4072
4155
|
async update(sessionId, input, options = {}) {
|
|
@@ -4160,88 +4243,30 @@ var SessionResource = class {
|
|
|
4160
4243
|
return response.part;
|
|
4161
4244
|
}
|
|
4162
4245
|
/** `POST /sessions/:id/prompts` — 提交用户输入并触发/排队一次 run。 */
|
|
4163
|
-
|
|
4164
|
-
|
|
4165
|
-
if (schemaCheck) await schemaCheck;
|
|
4166
|
-
return await this.transport.request(
|
|
4167
|
-
`/sessions/${encodeURIComponent(sessionId)}/prompts`,
|
|
4168
|
-
{
|
|
4169
|
-
method: "POST",
|
|
4170
|
-
body: { ...input, id: input.id ?? createPromptRequestId() },
|
|
4171
|
-
signal: options.signal
|
|
4172
|
-
}
|
|
4173
|
-
);
|
|
4246
|
+
admitPrompt(sessionId, input, options = {}) {
|
|
4247
|
+
return admitPrompt(this.transport, sessionId, input, options);
|
|
4174
4248
|
}
|
|
4175
4249
|
/** `POST /sessions/:id/prompts/latest/edit` */
|
|
4176
|
-
|
|
4177
|
-
|
|
4178
|
-
return await this.transport.request(
|
|
4179
|
-
`/sessions/${encodeURIComponent(sessionId)}/prompts/latest/edit`,
|
|
4180
|
-
{
|
|
4181
|
-
method: "POST",
|
|
4182
|
-
body: input,
|
|
4183
|
-
signal: options.signal
|
|
4184
|
-
}
|
|
4185
|
-
);
|
|
4250
|
+
editLatestPrompt(sessionId, input, options = {}) {
|
|
4251
|
+
return editLatestPrompt(this.transport, sessionId, input, options);
|
|
4186
4252
|
}
|
|
4187
4253
|
/** Promote one durable queued prompt into the exact active run. */
|
|
4188
|
-
|
|
4189
|
-
return
|
|
4190
|
-
`/sessions/${encodeURIComponent(sessionId)}/prompts/${encodeURIComponent(inputId)}/promote`,
|
|
4191
|
-
{ method: "POST", body: input, signal: options.signal }
|
|
4192
|
-
);
|
|
4254
|
+
promoteQueuedPrompt(sessionId, inputId, input, options = {}) {
|
|
4255
|
+
return promoteQueuedPrompt(this.transport, sessionId, inputId, input, options);
|
|
4193
4256
|
}
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
const response = await this.transport.request(
|
|
4197
|
-
`/sessions/${encodeURIComponent(sessionId)}/prompts/${encodeURIComponent(inputId)}/cancel`,
|
|
4198
|
-
{
|
|
4199
|
-
method: "POST",
|
|
4200
|
-
body: {
|
|
4201
|
-
...input,
|
|
4202
|
-
...options.responseMode ? { responseMode: mode } : {}
|
|
4203
|
-
},
|
|
4204
|
-
signal: options.signal
|
|
4205
|
-
}
|
|
4206
|
-
);
|
|
4207
|
-
if (mode === "receipt") {
|
|
4208
|
-
const receipt2 = decodeQueuedPromptCancelReceipt(response);
|
|
4209
|
-
if (receipt2.inputId !== inputId || receipt2.queuedRunId !== input.queuedRunId)
|
|
4210
|
-
throw new ProtocolDataError(
|
|
4211
|
-
"Cancellation receipt does not match target"
|
|
4212
|
-
);
|
|
4213
|
-
return receipt2;
|
|
4214
|
-
}
|
|
4215
|
-
return response;
|
|
4257
|
+
cancelQueuedPrompt(sessionId, inputId, input, options = {}) {
|
|
4258
|
+
return cancelQueuedPrompt(this.transport, sessionId, inputId, input, options);
|
|
4216
4259
|
}
|
|
4217
4260
|
/**
|
|
4218
4261
|
* `POST /sessions/:id/runs/:runId/resume` — 显式重放一次中断 run 的原始 prompt。
|
|
4219
|
-
*
|
|
4262
|
+
* 服务端复用原 Input,创建一个带恢复来源的新 Run。旧模型连接已经结束。
|
|
4220
4263
|
*/
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
return await this.transport.request(
|
|
4224
|
-
`/sessions/${encodeURIComponent(sessionId)}/runs/${encodeURIComponent(runId)}/resume`,
|
|
4225
|
-
{
|
|
4226
|
-
method: "POST",
|
|
4227
|
-
body: { ...input, id: input.id ?? createPromptRequestId() },
|
|
4228
|
-
signal: options.signal
|
|
4229
|
-
}
|
|
4230
|
-
);
|
|
4264
|
+
resumeInterruptedRun(sessionId, runId, input = {}, options = {}) {
|
|
4265
|
+
return resumeInterruptedRun(this.transport, sessionId, runId, input, options);
|
|
4231
4266
|
}
|
|
4232
4267
|
/** `POST /sessions/:id/interrupt` — 中断当前/排队中的 run。 */
|
|
4233
|
-
|
|
4234
|
-
return
|
|
4235
|
-
`/sessions/${encodeURIComponent(sessionId)}/interrupt`,
|
|
4236
|
-
{
|
|
4237
|
-
method: "POST",
|
|
4238
|
-
body: options.expectedRunId || options.source ? {
|
|
4239
|
-
...options.expectedRunId ? { expectedRunId: options.expectedRunId } : {},
|
|
4240
|
-
...options.source ? { source: options.source } : {}
|
|
4241
|
-
} : void 0,
|
|
4242
|
-
signal: options.signal
|
|
4243
|
-
}
|
|
4244
|
-
);
|
|
4268
|
+
interrupt(sessionId, options = {}) {
|
|
4269
|
+
return interrupt(this.transport, sessionId, options);
|
|
4245
4270
|
}
|
|
4246
4271
|
/** `POST /sessions/:id/compact` */
|
|
4247
4272
|
async compact(sessionId, options = {}) {
|
|
@@ -4645,8 +4670,8 @@ function startProcess(command, cwd, env) {
|
|
|
4645
4670
|
shell: false
|
|
4646
4671
|
});
|
|
4647
4672
|
let failure;
|
|
4648
|
-
child.
|
|
4649
|
-
failure
|
|
4673
|
+
child.on("error", () => {
|
|
4674
|
+
failure ??= new Error("Cannot spawn BobanNomi service executable.");
|
|
4650
4675
|
});
|
|
4651
4676
|
child.once("exit", (code, signal) => {
|
|
4652
4677
|
failure ??= new Error(`BobanNomi service exited before registration (${signal ?? code}).`);
|
|
@@ -4659,7 +4684,6 @@ async function abandonProcess(child) {
|
|
|
4659
4684
|
await new Promise((resolve5) => {
|
|
4660
4685
|
const timer = setTimeout(() => {
|
|
4661
4686
|
child.kill("SIGKILL");
|
|
4662
|
-
resolve5();
|
|
4663
4687
|
}, 500);
|
|
4664
4688
|
child.once("exit", () => {
|
|
4665
4689
|
clearTimeout(timer);
|
|
@@ -4713,9 +4737,19 @@ function sameInstance(left, right) {
|
|
|
4713
4737
|
|
|
4714
4738
|
// src/service/startup-lock.ts
|
|
4715
4739
|
var import_proper_lockfile = __toESM(require_proper_lockfile(), 1);
|
|
4716
|
-
import { mkdir } from "node:fs/promises";
|
|
4740
|
+
import { lstat, mkdir } from "node:fs/promises";
|
|
4717
4741
|
import { dirname as dirname2 } from "node:path";
|
|
4718
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
|
+
}
|
|
4719
4753
|
async function acquireStartupLock(file, end, signal) {
|
|
4720
4754
|
await mkdir(dirname2(file), { recursive: true });
|
|
4721
4755
|
const compromised = new AbortController();
|
|
@@ -4724,7 +4758,7 @@ async function acquireStartupLock(file, end, signal) {
|
|
|
4724
4758
|
try {
|
|
4725
4759
|
const release = await (0, import_proper_lockfile.lock)(file, {
|
|
4726
4760
|
realpath: false,
|
|
4727
|
-
lockfilePath:
|
|
4761
|
+
lockfilePath: startupLockPath(file),
|
|
4728
4762
|
stale: 1e4,
|
|
4729
4763
|
update: 5e3,
|
|
4730
4764
|
retries: 0,
|
|
@@ -4809,6 +4843,7 @@ async function realpathAllowMissing(path2) {
|
|
|
4809
4843
|
}
|
|
4810
4844
|
}
|
|
4811
4845
|
var startups = /* @__PURE__ */ new Map();
|
|
4846
|
+
var STARTUP_CLEANUP_TIMEOUT_MS = 2e3;
|
|
4812
4847
|
function waitForStartup(pending, signal) {
|
|
4813
4848
|
signal?.throwIfAborted();
|
|
4814
4849
|
if (!signal) return pending;
|
|
@@ -4824,11 +4859,14 @@ async function ensure(options = {}) {
|
|
|
4824
4859
|
const env = { ...process.env, ...options.env };
|
|
4825
4860
|
const { file, paths } = await serviceLocation(options.file, env);
|
|
4826
4861
|
const existing = await discoverAt({ ...options, file, paths });
|
|
4827
|
-
if (existing)
|
|
4862
|
+
if (existing && !await hasStartupLock(file) && sameInstance(existing, await readEndpoint(file)) && pidAlive(existing.pid)) {
|
|
4863
|
+
options.signal?.throwIfAborted();
|
|
4864
|
+
return existing;
|
|
4865
|
+
}
|
|
4828
4866
|
let pending = startups.get(file);
|
|
4829
4867
|
const joining = pending !== void 0;
|
|
4830
4868
|
if (!pending) {
|
|
4831
|
-
pending = startService({ ...options, file, paths }, env).finally(() => {
|
|
4869
|
+
pending = startService({ ...options, file, paths }, env, existing !== void 0).finally(() => {
|
|
4832
4870
|
startups.delete(file);
|
|
4833
4871
|
});
|
|
4834
4872
|
startups.set(file, pending);
|
|
@@ -4842,52 +4880,71 @@ async function ensure(options = {}) {
|
|
|
4842
4880
|
}
|
|
4843
4881
|
return endpoint;
|
|
4844
4882
|
}
|
|
4845
|
-
async function startService(options, env) {
|
|
4883
|
+
async function startService(options, env, mayReuseRegistration) {
|
|
4846
4884
|
const end = Date.now() + timeout(options.timeoutMs, 1e4);
|
|
4847
|
-
|
|
4848
|
-
|
|
4849
|
-
|
|
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();
|
|
4850
4891
|
if (options.paths) env.BOBANNOMI_CONFIG_DIR = selectDataRoot(void 0, env);
|
|
4851
4892
|
options.signal?.throwIfAborted();
|
|
4852
4893
|
const lease = await acquireStartupLock(options.file, end, options.signal);
|
|
4894
|
+
let started;
|
|
4895
|
+
let backgroundCleanup;
|
|
4853
4896
|
try {
|
|
4854
4897
|
const locked = { ...options, signal: lease.signal };
|
|
4855
4898
|
const existing = await discoverAt({ ...locked, timeoutMs: Math.max(1, Math.min(1e3, end - Date.now())) });
|
|
4856
4899
|
if (existing) return existing;
|
|
4857
|
-
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
|
|
4862
|
-
|
|
4863
|
-
|
|
4864
|
-
|
|
4865
|
-
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
const cwd = resolve4(options.cwd ?? process.cwd());
|
|
4869
|
-
const command = options.command ?? await defaultCommand(cwd, selectDataRoot(void 0, env));
|
|
4870
|
-
options.signal?.throwIfAborted();
|
|
4871
|
-
if (Date.now() >= end) throw new Error("BobanNomi service startup timed out before process creation.");
|
|
4872
|
-
const started = startProcess(command, cwd, env);
|
|
4873
|
-
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);
|
|
4874
4911
|
while (Date.now() < end) {
|
|
4875
|
-
|
|
4876
|
-
const endpoint = await discoverAt({ ...
|
|
4912
|
+
locked.signal.throwIfAborted();
|
|
4913
|
+
const endpoint = await discoverAt({ ...locked, timeoutMs: Math.max(1, Math.min(1e3, end - Date.now())) });
|
|
4877
4914
|
if (endpoint && !sameInstance(endpoint, previous)) return endpoint;
|
|
4878
4915
|
const failure = started.failure();
|
|
4879
4916
|
if (failure) throw failure;
|
|
4880
|
-
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 });
|
|
4881
4918
|
}
|
|
4882
4919
|
throw new Error("BobanNomi service startup timed out before compatible registration.");
|
|
4883
4920
|
} catch (error) {
|
|
4884
|
-
|
|
4885
|
-
|
|
4886
|
-
|
|
4887
|
-
|
|
4888
|
-
|
|
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
|
+
}
|
|
4889
4932
|
}
|
|
4890
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
|
+
});
|
|
4891
4948
|
}
|
|
4892
4949
|
}
|
|
4893
4950
|
async function stop(endpoint, options = {}) {
|