@codelia/core 0.1.26 → 0.1.29
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.cjs +129 -92
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +129 -92
- package/package.json +4 -4
- package/prompts/system.md +7 -0
package/dist/index.cjs
CHANGED
|
@@ -2419,6 +2419,16 @@ var isOpenAIAssistantInputContent = (value) => {
|
|
|
2419
2419
|
}
|
|
2420
2420
|
return false;
|
|
2421
2421
|
};
|
|
2422
|
+
var isReplayableOpenAIHistoryItem = (value) => {
|
|
2423
|
+
if (!value || typeof value !== "object") {
|
|
2424
|
+
return false;
|
|
2425
|
+
}
|
|
2426
|
+
const type = value.type;
|
|
2427
|
+
if (type === "reasoning") {
|
|
2428
|
+
return typeof value.id === "string";
|
|
2429
|
+
}
|
|
2430
|
+
return type === "web_search_call";
|
|
2431
|
+
};
|
|
2422
2432
|
var isReplayableOpenAIFunctionCallItem = (value) => {
|
|
2423
2433
|
if (!value || typeof value !== "object") {
|
|
2424
2434
|
return false;
|
|
@@ -2592,6 +2602,9 @@ function toResponsesInput(messages) {
|
|
|
2592
2602
|
continue;
|
|
2593
2603
|
}
|
|
2594
2604
|
if (message.role === "reasoning") {
|
|
2605
|
+
if (isReplayableOpenAIHistoryItem(message.raw_item)) {
|
|
2606
|
+
items.push(message.raw_item);
|
|
2607
|
+
}
|
|
2595
2608
|
continue;
|
|
2596
2609
|
}
|
|
2597
2610
|
if (message.role === "assistant") {
|
|
@@ -2762,13 +2775,19 @@ var invokeOpenAiHttp = async (client, request, signal, sessionIdHeader) => {
|
|
|
2762
2775
|
|
|
2763
2776
|
// src/llm/openai/websocket-transport.ts
|
|
2764
2777
|
var import_ws = require("openai/resources/responses/ws");
|
|
2765
|
-
var WS_CONNECT_TIMEOUT_MS =
|
|
2766
|
-
var
|
|
2778
|
+
var WS_CONNECT_TIMEOUT_MS = 2e4;
|
|
2779
|
+
var WS_RESPONSE_IDLE_TIMEOUT_MS = 3e5;
|
|
2767
2780
|
var WS_UNEXPECTED_RESPONSE_BODY_TIMEOUT_MS = 250;
|
|
2768
2781
|
var WS_UNEXPECTED_RESPONSE_BODY_MAX_CHARS = 2e3;
|
|
2769
2782
|
var OPENAI_BETA_HEADER = "OpenAI-Beta";
|
|
2770
2783
|
var OPENAI_BETA_RESPONSES_WEBSOCKETS_V1 = "responses_websockets=2026-02-04";
|
|
2771
2784
|
var OPENAI_BETA_RESPONSES_WEBSOCKETS_V2 = "responses_websockets=2026-02-06";
|
|
2785
|
+
var resolveTimeoutMs = (value, fallbackMs) => {
|
|
2786
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
|
|
2787
|
+
return fallbackMs;
|
|
2788
|
+
}
|
|
2789
|
+
return Math.floor(value);
|
|
2790
|
+
};
|
|
2772
2791
|
var WsResponseError = class extends Error {
|
|
2773
2792
|
constructor(message, code) {
|
|
2774
2793
|
super(message);
|
|
@@ -2779,10 +2798,20 @@ var OpenAiWsTransport = class {
|
|
|
2779
2798
|
client;
|
|
2780
2799
|
websocketApiVersion;
|
|
2781
2800
|
createResponsesWs;
|
|
2801
|
+
wsConnectTimeoutMs;
|
|
2802
|
+
wsResponseIdleTimeoutMs;
|
|
2782
2803
|
constructor(options) {
|
|
2783
2804
|
this.client = options.client;
|
|
2784
2805
|
this.websocketApiVersion = options.websocketApiVersion;
|
|
2785
2806
|
this.createResponsesWs = options.createResponsesWs;
|
|
2807
|
+
this.wsConnectTimeoutMs = resolveTimeoutMs(
|
|
2808
|
+
options.wsConnectTimeoutMs,
|
|
2809
|
+
WS_CONNECT_TIMEOUT_MS
|
|
2810
|
+
);
|
|
2811
|
+
this.wsResponseIdleTimeoutMs = resolveTimeoutMs(
|
|
2812
|
+
options.wsResponseIdleTimeoutMs,
|
|
2813
|
+
WS_RESPONSE_IDLE_TIMEOUT_MS
|
|
2814
|
+
);
|
|
2786
2815
|
}
|
|
2787
2816
|
async invoke(args) {
|
|
2788
2817
|
await this.prepareClientForWsHandshake();
|
|
@@ -2815,21 +2844,34 @@ var OpenAiWsTransport = class {
|
|
|
2815
2844
|
const nativeSocket = this.getNativeSocket(ws);
|
|
2816
2845
|
let removeNativeClose;
|
|
2817
2846
|
let removeNativeError;
|
|
2818
|
-
|
|
2847
|
+
let removeNativeMessage;
|
|
2848
|
+
let timeout;
|
|
2849
|
+
const resetResponseTimeout = () => {
|
|
2819
2850
|
if (settled) return;
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2851
|
+
if (timeout) {
|
|
2852
|
+
clearTimeout(timeout);
|
|
2853
|
+
}
|
|
2854
|
+
timeout = setTimeout(() => {
|
|
2855
|
+
if (settled) return;
|
|
2856
|
+
settled = true;
|
|
2857
|
+
teardown();
|
|
2858
|
+
reject(new Error("openai websocket response timeout"));
|
|
2859
|
+
}, this.wsResponseIdleTimeoutMs);
|
|
2860
|
+
};
|
|
2824
2861
|
const teardown = () => {
|
|
2825
2862
|
if (ws.off) {
|
|
2826
2863
|
ws.off("error", onError);
|
|
2864
|
+
ws.off("event", onEvent);
|
|
2827
2865
|
ws.off("response.failed", onResponseFailed);
|
|
2828
2866
|
ws.off("response.completed", onResponseCompleted);
|
|
2829
2867
|
ws.off("close", onClose);
|
|
2830
2868
|
}
|
|
2869
|
+
if (timeout) {
|
|
2870
|
+
clearTimeout(timeout);
|
|
2871
|
+
}
|
|
2831
2872
|
removeNativeClose?.();
|
|
2832
2873
|
removeNativeError?.();
|
|
2874
|
+
removeNativeMessage?.();
|
|
2833
2875
|
if (args.signal && onAbort) {
|
|
2834
2876
|
args.signal.removeEventListener("abort", onAbort);
|
|
2835
2877
|
}
|
|
@@ -2837,14 +2879,12 @@ var OpenAiWsTransport = class {
|
|
|
2837
2879
|
const resolveOnce = (response2) => {
|
|
2838
2880
|
if (settled) return;
|
|
2839
2881
|
settled = true;
|
|
2840
|
-
clearTimeout(timeout);
|
|
2841
2882
|
teardown();
|
|
2842
2883
|
resolve(response2);
|
|
2843
2884
|
};
|
|
2844
2885
|
const rejectOnce = (error) => {
|
|
2845
2886
|
if (settled) return;
|
|
2846
2887
|
settled = true;
|
|
2847
|
-
clearTimeout(timeout);
|
|
2848
2888
|
teardown();
|
|
2849
2889
|
reject(error);
|
|
2850
2890
|
};
|
|
@@ -2852,6 +2892,9 @@ var OpenAiWsTransport = class {
|
|
|
2852
2892
|
const onError = (error) => {
|
|
2853
2893
|
rejectOnce(error);
|
|
2854
2894
|
};
|
|
2895
|
+
const onEvent = () => {
|
|
2896
|
+
resetResponseTimeout();
|
|
2897
|
+
};
|
|
2855
2898
|
const onResponseFailed = (event) => {
|
|
2856
2899
|
const failed = event;
|
|
2857
2900
|
const message = failed.response?.error?.message;
|
|
@@ -2876,6 +2919,7 @@ var OpenAiWsTransport = class {
|
|
|
2876
2919
|
);
|
|
2877
2920
|
};
|
|
2878
2921
|
ws.on("error", onError);
|
|
2922
|
+
ws.on("event", onEvent);
|
|
2879
2923
|
ws.on("response.failed", onResponseFailed);
|
|
2880
2924
|
ws.on("response.completed", onResponseCompleted);
|
|
2881
2925
|
ws.on("close", onClose);
|
|
@@ -2893,6 +2937,13 @@ var OpenAiWsTransport = class {
|
|
|
2893
2937
|
onError(error);
|
|
2894
2938
|
}
|
|
2895
2939
|
);
|
|
2940
|
+
removeNativeMessage = this.addNativeSocketListener(
|
|
2941
|
+
nativeSocket,
|
|
2942
|
+
"message",
|
|
2943
|
+
() => {
|
|
2944
|
+
resetResponseTimeout();
|
|
2945
|
+
}
|
|
2946
|
+
);
|
|
2896
2947
|
if (args.signal) {
|
|
2897
2948
|
onAbort = () => {
|
|
2898
2949
|
rejectOnce(new Error("openai websocket request aborted"));
|
|
@@ -2903,6 +2954,7 @@ var OpenAiWsTransport = class {
|
|
|
2903
2954
|
onAbort();
|
|
2904
2955
|
}
|
|
2905
2956
|
}
|
|
2957
|
+
resetResponseTimeout();
|
|
2906
2958
|
});
|
|
2907
2959
|
const responseCreateEvent = {
|
|
2908
2960
|
type: "response.create",
|
|
@@ -3242,7 +3294,7 @@ var OpenAiWsTransport = class {
|
|
|
3242
3294
|
};
|
|
3243
3295
|
const timeout = setTimeout(() => {
|
|
3244
3296
|
settleReject(new Error("openai websocket connect timeout"));
|
|
3245
|
-
},
|
|
3297
|
+
}, this.wsConnectTimeoutMs);
|
|
3246
3298
|
addSocketListener("open", () => {
|
|
3247
3299
|
settleResolve();
|
|
3248
3300
|
});
|
|
@@ -3292,9 +3344,6 @@ var getSessionIdHeaderValue = (promptCacheKey) => {
|
|
|
3292
3344
|
var WS_SESSION_IDLE_TTL_MS = 10 * 6e4;
|
|
3293
3345
|
var WS_SESSION_DISABLE_TTL_MS = 6e4;
|
|
3294
3346
|
var WS_REUSE_MAX_IDLE_MS = 3e4;
|
|
3295
|
-
var WS_ON_MODE_RETRY_MAX_ATTEMPTS = 3;
|
|
3296
|
-
var WS_ON_MODE_RETRY_BASE_BACKOFF_MS = 250;
|
|
3297
|
-
var WS_ON_MODE_RETRY_MAX_BACKOFF_MS = 2e3;
|
|
3298
3347
|
var ChatOpenAI = class {
|
|
3299
3348
|
provider = PROVIDER_NAME2;
|
|
3300
3349
|
model;
|
|
@@ -3319,7 +3368,9 @@ var ChatOpenAI = class {
|
|
|
3319
3368
|
this.wsTransport = new OpenAiWsTransport({
|
|
3320
3369
|
client: this.client,
|
|
3321
3370
|
websocketApiVersion: this.websocketApiVersion,
|
|
3322
|
-
createResponsesWs: options.createResponsesWs
|
|
3371
|
+
createResponsesWs: options.createResponsesWs,
|
|
3372
|
+
wsConnectTimeoutMs: options.websocketConnectTimeoutMs,
|
|
3373
|
+
wsResponseIdleTimeoutMs: options.websocketResponseIdleTimeoutMs
|
|
3323
3374
|
});
|
|
3324
3375
|
}
|
|
3325
3376
|
async ainvoke(input, context) {
|
|
@@ -3447,7 +3498,7 @@ var ChatOpenAI = class {
|
|
|
3447
3498
|
const canUsePreviousResponseId = this.websocketApiVersion === "v2" && Boolean(wsState.previousResponseId) && !shouldResetChain && incrementalInput !== null;
|
|
3448
3499
|
const chainReset = shouldResetChain || Boolean(wsState.previousResponseId) && !canUsePreviousResponseId;
|
|
3449
3500
|
let wsInputMode = "full_no_previous";
|
|
3450
|
-
if (wsState.previousResponseId) {
|
|
3501
|
+
if (Boolean(wsState.previousResponseId)) {
|
|
3451
3502
|
if (canUsePreviousResponseId) {
|
|
3452
3503
|
if (Array.isArray(incrementalInput) && incrementalInput.length === 0) {
|
|
3453
3504
|
wsInputMode = "empty";
|
|
@@ -3509,50 +3560,43 @@ var ChatOpenAI = class {
|
|
|
3509
3560
|
} catch (error) {
|
|
3510
3561
|
let failure = error;
|
|
3511
3562
|
if (this.websocketMode === "on" && this.isWsReconnectRetryableError(failure)) {
|
|
3512
|
-
const retryWsInputMode =
|
|
3563
|
+
const retryWsInputMode = Boolean(
|
|
3564
|
+
wsState.previousResponseId
|
|
3565
|
+
) ? "full_regenerated" : "full_no_previous";
|
|
3513
3566
|
this.closeWsWithoutMaskingPrimaryError(wsState.ws, "retry_reset", failure);
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
chainReset: true,
|
|
3548
|
-
wsInputMode: retryWsInputMode
|
|
3549
|
-
};
|
|
3550
|
-
} catch (retryError) {
|
|
3551
|
-
failure = retryError;
|
|
3552
|
-
if (!this.isWsReconnectRetryableError(failure)) {
|
|
3553
|
-
break;
|
|
3554
|
-
}
|
|
3555
|
-
}
|
|
3567
|
+
try {
|
|
3568
|
+
await this.debugRequestIfEnabled(
|
|
3569
|
+
args.request,
|
|
3570
|
+
args.debugSeq,
|
|
3571
|
+
args.sessionIdHeader,
|
|
3572
|
+
"ws_mode",
|
|
3573
|
+
false,
|
|
3574
|
+
true,
|
|
3575
|
+
retryWsInputMode
|
|
3576
|
+
);
|
|
3577
|
+
const { response, ws } = await this.invokeViaWs({
|
|
3578
|
+
request: args.request,
|
|
3579
|
+
signal: args.signal,
|
|
3580
|
+
sessionIdHeader: args.sessionIdHeader,
|
|
3581
|
+
ws: void 0
|
|
3582
|
+
});
|
|
3583
|
+
this.wsReconnectCount += 1;
|
|
3584
|
+
this.persistWsSessionState({
|
|
3585
|
+
sessionKey: args.sessionKey,
|
|
3586
|
+
request: args.request,
|
|
3587
|
+
requestMeta: args.requestMeta,
|
|
3588
|
+
response,
|
|
3589
|
+
ws
|
|
3590
|
+
});
|
|
3591
|
+
return {
|
|
3592
|
+
response,
|
|
3593
|
+
transport: "ws_mode",
|
|
3594
|
+
fallbackUsed: false,
|
|
3595
|
+
chainReset: true,
|
|
3596
|
+
wsInputMode: retryWsInputMode
|
|
3597
|
+
};
|
|
3598
|
+
} catch (retryError) {
|
|
3599
|
+
failure = retryError;
|
|
3556
3600
|
}
|
|
3557
3601
|
}
|
|
3558
3602
|
const wsErrorCode = this.extractWsErrorCode(failure);
|
|
@@ -3610,11 +3654,21 @@ var ChatOpenAI = class {
|
|
|
3610
3654
|
instructionsHash: args.requestMeta.instructionsHash,
|
|
3611
3655
|
toolsHash: args.requestMeta.toolsHash,
|
|
3612
3656
|
model: args.requestMeta.model,
|
|
3613
|
-
lastInput: args.request.input,
|
|
3657
|
+
lastInput: this.buildWsLastInput(args.request.input, args.response),
|
|
3614
3658
|
ws: args.ws,
|
|
3615
3659
|
lastUsedAt: Date.now()
|
|
3616
3660
|
});
|
|
3617
3661
|
}
|
|
3662
|
+
buildWsLastInput(requestInput, response) {
|
|
3663
|
+
if (!Array.isArray(requestInput)) {
|
|
3664
|
+
return requestInput;
|
|
3665
|
+
}
|
|
3666
|
+
const replayItems = toResponsesInput(toChatInvokeCompletion2(response).messages);
|
|
3667
|
+
if (replayItems.length === 0) {
|
|
3668
|
+
return requestInput;
|
|
3669
|
+
}
|
|
3670
|
+
return [...requestInput, ...replayItems];
|
|
3671
|
+
}
|
|
3618
3672
|
async invokeViaWs(args) {
|
|
3619
3673
|
return this.wsTransport.invoke(args);
|
|
3620
3674
|
}
|
|
@@ -3637,35 +3691,6 @@ var ChatOpenAI = class {
|
|
|
3637
3691
|
const message = error.message.toLowerCase();
|
|
3638
3692
|
return message.includes("response timeout") || message.includes("closed before response") || message.includes("closed before open") || message.includes("connect timeout") || message.includes("could not send data") || message.includes("websocket is not open");
|
|
3639
3693
|
}
|
|
3640
|
-
getWsReconnectRetryDelayMs(retryAttempt) {
|
|
3641
|
-
const backoff = WS_ON_MODE_RETRY_BASE_BACKOFF_MS * 2 ** Math.max(retryAttempt - 1, 0);
|
|
3642
|
-
return Math.min(backoff, WS_ON_MODE_RETRY_MAX_BACKOFF_MS);
|
|
3643
|
-
}
|
|
3644
|
-
async waitForWsReconnectRetryDelay(retryAttempt, signal) {
|
|
3645
|
-
if (signal?.aborted) {
|
|
3646
|
-
throw new Error("openai websocket request aborted");
|
|
3647
|
-
}
|
|
3648
|
-
const delayMs = this.getWsReconnectRetryDelayMs(retryAttempt);
|
|
3649
|
-
await new Promise((resolve, reject) => {
|
|
3650
|
-
const timeout = setTimeout(() => {
|
|
3651
|
-
teardown();
|
|
3652
|
-
resolve();
|
|
3653
|
-
}, delayMs);
|
|
3654
|
-
const onAbort = () => {
|
|
3655
|
-
teardown();
|
|
3656
|
-
reject(new Error("openai websocket request aborted"));
|
|
3657
|
-
};
|
|
3658
|
-
const teardown = () => {
|
|
3659
|
-
clearTimeout(timeout);
|
|
3660
|
-
if (signal) {
|
|
3661
|
-
signal.removeEventListener("abort", onAbort);
|
|
3662
|
-
}
|
|
3663
|
-
};
|
|
3664
|
-
if (signal) {
|
|
3665
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
3666
|
-
}
|
|
3667
|
-
});
|
|
3668
|
-
}
|
|
3669
3694
|
isWsConnectionReusable(ws) {
|
|
3670
3695
|
return this.wsTransport.isConnectionReusable(ws);
|
|
3671
3696
|
}
|
|
@@ -3711,7 +3736,7 @@ var ChatOpenAI = class {
|
|
|
3711
3736
|
return void 0;
|
|
3712
3737
|
}
|
|
3713
3738
|
if (!Array.isArray(previousInput) || !Array.isArray(currentInput)) {
|
|
3714
|
-
return
|
|
3739
|
+
return null;
|
|
3715
3740
|
}
|
|
3716
3741
|
if (previousInput.length > currentInput.length) {
|
|
3717
3742
|
return null;
|
|
@@ -3722,7 +3747,7 @@ var ChatOpenAI = class {
|
|
|
3722
3747
|
}
|
|
3723
3748
|
}
|
|
3724
3749
|
if (previousInput.length === currentInput.length) {
|
|
3725
|
-
return
|
|
3750
|
+
return null;
|
|
3726
3751
|
}
|
|
3727
3752
|
return currentInput.slice(previousInput.length);
|
|
3728
3753
|
}
|
|
@@ -4507,6 +4532,18 @@ var withRequiredProperties = (schema) => mapSchema(schema, (next) => {
|
|
|
4507
4532
|
}
|
|
4508
4533
|
return next;
|
|
4509
4534
|
});
|
|
4535
|
+
var withTopLevelObjectTypeForObjectUnions = (schema) => {
|
|
4536
|
+
if (schema.type !== void 0) return schema;
|
|
4537
|
+
const variants = (Array.isArray(schema.anyOf) && schema.anyOf.length > 0 ? schema.anyOf : Array.isArray(schema.oneOf) && schema.oneOf.length > 0 ? schema.oneOf : null) ?? null;
|
|
4538
|
+
if (!variants) return schema;
|
|
4539
|
+
const allObjectVariants = variants.every((variant) => {
|
|
4540
|
+
if (!variant || typeof variant !== "object") return false;
|
|
4541
|
+
const jsonSchema = variant;
|
|
4542
|
+
return jsonSchema.type === "object";
|
|
4543
|
+
});
|
|
4544
|
+
if (!allObjectVariants) return schema;
|
|
4545
|
+
return { ...schema, type: "object" };
|
|
4546
|
+
};
|
|
4510
4547
|
function toToolResult(value) {
|
|
4511
4548
|
if (isToolResult(value)) return value;
|
|
4512
4549
|
if (typeof value === "string") return { type: "text", text: value };
|
|
@@ -4519,8 +4556,8 @@ function defineTool(toolOptions) {
|
|
|
4519
4556
|
target: "draft-07",
|
|
4520
4557
|
io: "input"
|
|
4521
4558
|
});
|
|
4522
|
-
const strictParameters =
|
|
4523
|
-
withNoAdditionalProperties(parameters)
|
|
4559
|
+
const strictParameters = withTopLevelObjectTypeForObjectUnions(
|
|
4560
|
+
withRequiredProperties(withNoAdditionalProperties(parameters))
|
|
4524
4561
|
);
|
|
4525
4562
|
return {
|
|
4526
4563
|
name: toolOptions.name,
|
package/dist/index.d.cts
CHANGED
|
@@ -667,6 +667,8 @@ type ChatOpenAIOptions = {
|
|
|
667
667
|
websocketMode?: OpenAiWebsocketMode;
|
|
668
668
|
websocketApiVersion?: OpenAiWebsocketApiVersion;
|
|
669
669
|
createResponsesWs?: (client: OpenAI, options?: ConstructorParameters<typeof ResponsesWS>[1]) => OpenAiResponsesWsLike;
|
|
670
|
+
websocketConnectTimeoutMs?: number;
|
|
671
|
+
websocketResponseIdleTimeoutMs?: number;
|
|
670
672
|
};
|
|
671
673
|
declare class ChatOpenAI implements BaseChatModel<typeof PROVIDER_NAME$1, OpenAIInvokeOptions> {
|
|
672
674
|
readonly provider: typeof PROVIDER_NAME$1;
|
|
@@ -689,13 +691,12 @@ declare class ChatOpenAI implements BaseChatModel<typeof PROVIDER_NAME$1, OpenAI
|
|
|
689
691
|
private invokeWithTransport;
|
|
690
692
|
private invokeHttpTransportWithDebug;
|
|
691
693
|
private persistWsSessionState;
|
|
694
|
+
private buildWsLastInput;
|
|
692
695
|
private invokeViaWs;
|
|
693
696
|
private closeWsSafely;
|
|
694
697
|
private closeWsWithoutMaskingPrimaryError;
|
|
695
698
|
private isWsConnectionReuseExpired;
|
|
696
699
|
private isWsReconnectRetryableError;
|
|
697
|
-
private getWsReconnectRetryDelayMs;
|
|
698
|
-
private waitForWsReconnectRetryDelay;
|
|
699
700
|
private isWsConnectionReusable;
|
|
700
701
|
private extractWsErrorCode;
|
|
701
702
|
private clearWsSessionState;
|
package/dist/index.d.ts
CHANGED
|
@@ -667,6 +667,8 @@ type ChatOpenAIOptions = {
|
|
|
667
667
|
websocketMode?: OpenAiWebsocketMode;
|
|
668
668
|
websocketApiVersion?: OpenAiWebsocketApiVersion;
|
|
669
669
|
createResponsesWs?: (client: OpenAI, options?: ConstructorParameters<typeof ResponsesWS>[1]) => OpenAiResponsesWsLike;
|
|
670
|
+
websocketConnectTimeoutMs?: number;
|
|
671
|
+
websocketResponseIdleTimeoutMs?: number;
|
|
670
672
|
};
|
|
671
673
|
declare class ChatOpenAI implements BaseChatModel<typeof PROVIDER_NAME$1, OpenAIInvokeOptions> {
|
|
672
674
|
readonly provider: typeof PROVIDER_NAME$1;
|
|
@@ -689,13 +691,12 @@ declare class ChatOpenAI implements BaseChatModel<typeof PROVIDER_NAME$1, OpenAI
|
|
|
689
691
|
private invokeWithTransport;
|
|
690
692
|
private invokeHttpTransportWithDebug;
|
|
691
693
|
private persistWsSessionState;
|
|
694
|
+
private buildWsLastInput;
|
|
692
695
|
private invokeViaWs;
|
|
693
696
|
private closeWsSafely;
|
|
694
697
|
private closeWsWithoutMaskingPrimaryError;
|
|
695
698
|
private isWsConnectionReuseExpired;
|
|
696
699
|
private isWsReconnectRetryableError;
|
|
697
|
-
private getWsReconnectRetryDelayMs;
|
|
698
|
-
private waitForWsReconnectRetryDelay;
|
|
699
700
|
private isWsConnectionReusable;
|
|
700
701
|
private extractWsErrorCode;
|
|
701
702
|
private clearWsSessionState;
|
package/dist/index.js
CHANGED
|
@@ -2362,6 +2362,16 @@ var isOpenAIAssistantInputContent = (value) => {
|
|
|
2362
2362
|
}
|
|
2363
2363
|
return false;
|
|
2364
2364
|
};
|
|
2365
|
+
var isReplayableOpenAIHistoryItem = (value) => {
|
|
2366
|
+
if (!value || typeof value !== "object") {
|
|
2367
|
+
return false;
|
|
2368
|
+
}
|
|
2369
|
+
const type = value.type;
|
|
2370
|
+
if (type === "reasoning") {
|
|
2371
|
+
return typeof value.id === "string";
|
|
2372
|
+
}
|
|
2373
|
+
return type === "web_search_call";
|
|
2374
|
+
};
|
|
2365
2375
|
var isReplayableOpenAIFunctionCallItem = (value) => {
|
|
2366
2376
|
if (!value || typeof value !== "object") {
|
|
2367
2377
|
return false;
|
|
@@ -2535,6 +2545,9 @@ function toResponsesInput(messages) {
|
|
|
2535
2545
|
continue;
|
|
2536
2546
|
}
|
|
2537
2547
|
if (message.role === "reasoning") {
|
|
2548
|
+
if (isReplayableOpenAIHistoryItem(message.raw_item)) {
|
|
2549
|
+
items.push(message.raw_item);
|
|
2550
|
+
}
|
|
2538
2551
|
continue;
|
|
2539
2552
|
}
|
|
2540
2553
|
if (message.role === "assistant") {
|
|
@@ -2705,13 +2718,19 @@ var invokeOpenAiHttp = async (client, request, signal, sessionIdHeader) => {
|
|
|
2705
2718
|
|
|
2706
2719
|
// src/llm/openai/websocket-transport.ts
|
|
2707
2720
|
import { ResponsesWS } from "openai/resources/responses/ws";
|
|
2708
|
-
var WS_CONNECT_TIMEOUT_MS =
|
|
2709
|
-
var
|
|
2721
|
+
var WS_CONNECT_TIMEOUT_MS = 2e4;
|
|
2722
|
+
var WS_RESPONSE_IDLE_TIMEOUT_MS = 3e5;
|
|
2710
2723
|
var WS_UNEXPECTED_RESPONSE_BODY_TIMEOUT_MS = 250;
|
|
2711
2724
|
var WS_UNEXPECTED_RESPONSE_BODY_MAX_CHARS = 2e3;
|
|
2712
2725
|
var OPENAI_BETA_HEADER = "OpenAI-Beta";
|
|
2713
2726
|
var OPENAI_BETA_RESPONSES_WEBSOCKETS_V1 = "responses_websockets=2026-02-04";
|
|
2714
2727
|
var OPENAI_BETA_RESPONSES_WEBSOCKETS_V2 = "responses_websockets=2026-02-06";
|
|
2728
|
+
var resolveTimeoutMs = (value, fallbackMs) => {
|
|
2729
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
|
|
2730
|
+
return fallbackMs;
|
|
2731
|
+
}
|
|
2732
|
+
return Math.floor(value);
|
|
2733
|
+
};
|
|
2715
2734
|
var WsResponseError = class extends Error {
|
|
2716
2735
|
constructor(message, code) {
|
|
2717
2736
|
super(message);
|
|
@@ -2722,10 +2741,20 @@ var OpenAiWsTransport = class {
|
|
|
2722
2741
|
client;
|
|
2723
2742
|
websocketApiVersion;
|
|
2724
2743
|
createResponsesWs;
|
|
2744
|
+
wsConnectTimeoutMs;
|
|
2745
|
+
wsResponseIdleTimeoutMs;
|
|
2725
2746
|
constructor(options) {
|
|
2726
2747
|
this.client = options.client;
|
|
2727
2748
|
this.websocketApiVersion = options.websocketApiVersion;
|
|
2728
2749
|
this.createResponsesWs = options.createResponsesWs;
|
|
2750
|
+
this.wsConnectTimeoutMs = resolveTimeoutMs(
|
|
2751
|
+
options.wsConnectTimeoutMs,
|
|
2752
|
+
WS_CONNECT_TIMEOUT_MS
|
|
2753
|
+
);
|
|
2754
|
+
this.wsResponseIdleTimeoutMs = resolveTimeoutMs(
|
|
2755
|
+
options.wsResponseIdleTimeoutMs,
|
|
2756
|
+
WS_RESPONSE_IDLE_TIMEOUT_MS
|
|
2757
|
+
);
|
|
2729
2758
|
}
|
|
2730
2759
|
async invoke(args) {
|
|
2731
2760
|
await this.prepareClientForWsHandshake();
|
|
@@ -2758,21 +2787,34 @@ var OpenAiWsTransport = class {
|
|
|
2758
2787
|
const nativeSocket = this.getNativeSocket(ws);
|
|
2759
2788
|
let removeNativeClose;
|
|
2760
2789
|
let removeNativeError;
|
|
2761
|
-
|
|
2790
|
+
let removeNativeMessage;
|
|
2791
|
+
let timeout;
|
|
2792
|
+
const resetResponseTimeout = () => {
|
|
2762
2793
|
if (settled) return;
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2794
|
+
if (timeout) {
|
|
2795
|
+
clearTimeout(timeout);
|
|
2796
|
+
}
|
|
2797
|
+
timeout = setTimeout(() => {
|
|
2798
|
+
if (settled) return;
|
|
2799
|
+
settled = true;
|
|
2800
|
+
teardown();
|
|
2801
|
+
reject(new Error("openai websocket response timeout"));
|
|
2802
|
+
}, this.wsResponseIdleTimeoutMs);
|
|
2803
|
+
};
|
|
2767
2804
|
const teardown = () => {
|
|
2768
2805
|
if (ws.off) {
|
|
2769
2806
|
ws.off("error", onError);
|
|
2807
|
+
ws.off("event", onEvent);
|
|
2770
2808
|
ws.off("response.failed", onResponseFailed);
|
|
2771
2809
|
ws.off("response.completed", onResponseCompleted);
|
|
2772
2810
|
ws.off("close", onClose);
|
|
2773
2811
|
}
|
|
2812
|
+
if (timeout) {
|
|
2813
|
+
clearTimeout(timeout);
|
|
2814
|
+
}
|
|
2774
2815
|
removeNativeClose?.();
|
|
2775
2816
|
removeNativeError?.();
|
|
2817
|
+
removeNativeMessage?.();
|
|
2776
2818
|
if (args.signal && onAbort) {
|
|
2777
2819
|
args.signal.removeEventListener("abort", onAbort);
|
|
2778
2820
|
}
|
|
@@ -2780,14 +2822,12 @@ var OpenAiWsTransport = class {
|
|
|
2780
2822
|
const resolveOnce = (response2) => {
|
|
2781
2823
|
if (settled) return;
|
|
2782
2824
|
settled = true;
|
|
2783
|
-
clearTimeout(timeout);
|
|
2784
2825
|
teardown();
|
|
2785
2826
|
resolve(response2);
|
|
2786
2827
|
};
|
|
2787
2828
|
const rejectOnce = (error) => {
|
|
2788
2829
|
if (settled) return;
|
|
2789
2830
|
settled = true;
|
|
2790
|
-
clearTimeout(timeout);
|
|
2791
2831
|
teardown();
|
|
2792
2832
|
reject(error);
|
|
2793
2833
|
};
|
|
@@ -2795,6 +2835,9 @@ var OpenAiWsTransport = class {
|
|
|
2795
2835
|
const onError = (error) => {
|
|
2796
2836
|
rejectOnce(error);
|
|
2797
2837
|
};
|
|
2838
|
+
const onEvent = () => {
|
|
2839
|
+
resetResponseTimeout();
|
|
2840
|
+
};
|
|
2798
2841
|
const onResponseFailed = (event) => {
|
|
2799
2842
|
const failed = event;
|
|
2800
2843
|
const message = failed.response?.error?.message;
|
|
@@ -2819,6 +2862,7 @@ var OpenAiWsTransport = class {
|
|
|
2819
2862
|
);
|
|
2820
2863
|
};
|
|
2821
2864
|
ws.on("error", onError);
|
|
2865
|
+
ws.on("event", onEvent);
|
|
2822
2866
|
ws.on("response.failed", onResponseFailed);
|
|
2823
2867
|
ws.on("response.completed", onResponseCompleted);
|
|
2824
2868
|
ws.on("close", onClose);
|
|
@@ -2836,6 +2880,13 @@ var OpenAiWsTransport = class {
|
|
|
2836
2880
|
onError(error);
|
|
2837
2881
|
}
|
|
2838
2882
|
);
|
|
2883
|
+
removeNativeMessage = this.addNativeSocketListener(
|
|
2884
|
+
nativeSocket,
|
|
2885
|
+
"message",
|
|
2886
|
+
() => {
|
|
2887
|
+
resetResponseTimeout();
|
|
2888
|
+
}
|
|
2889
|
+
);
|
|
2839
2890
|
if (args.signal) {
|
|
2840
2891
|
onAbort = () => {
|
|
2841
2892
|
rejectOnce(new Error("openai websocket request aborted"));
|
|
@@ -2846,6 +2897,7 @@ var OpenAiWsTransport = class {
|
|
|
2846
2897
|
onAbort();
|
|
2847
2898
|
}
|
|
2848
2899
|
}
|
|
2900
|
+
resetResponseTimeout();
|
|
2849
2901
|
});
|
|
2850
2902
|
const responseCreateEvent = {
|
|
2851
2903
|
type: "response.create",
|
|
@@ -3185,7 +3237,7 @@ var OpenAiWsTransport = class {
|
|
|
3185
3237
|
};
|
|
3186
3238
|
const timeout = setTimeout(() => {
|
|
3187
3239
|
settleReject(new Error("openai websocket connect timeout"));
|
|
3188
|
-
},
|
|
3240
|
+
}, this.wsConnectTimeoutMs);
|
|
3189
3241
|
addSocketListener("open", () => {
|
|
3190
3242
|
settleResolve();
|
|
3191
3243
|
});
|
|
@@ -3235,9 +3287,6 @@ var getSessionIdHeaderValue = (promptCacheKey) => {
|
|
|
3235
3287
|
var WS_SESSION_IDLE_TTL_MS = 10 * 6e4;
|
|
3236
3288
|
var WS_SESSION_DISABLE_TTL_MS = 6e4;
|
|
3237
3289
|
var WS_REUSE_MAX_IDLE_MS = 3e4;
|
|
3238
|
-
var WS_ON_MODE_RETRY_MAX_ATTEMPTS = 3;
|
|
3239
|
-
var WS_ON_MODE_RETRY_BASE_BACKOFF_MS = 250;
|
|
3240
|
-
var WS_ON_MODE_RETRY_MAX_BACKOFF_MS = 2e3;
|
|
3241
3290
|
var ChatOpenAI = class {
|
|
3242
3291
|
provider = PROVIDER_NAME2;
|
|
3243
3292
|
model;
|
|
@@ -3262,7 +3311,9 @@ var ChatOpenAI = class {
|
|
|
3262
3311
|
this.wsTransport = new OpenAiWsTransport({
|
|
3263
3312
|
client: this.client,
|
|
3264
3313
|
websocketApiVersion: this.websocketApiVersion,
|
|
3265
|
-
createResponsesWs: options.createResponsesWs
|
|
3314
|
+
createResponsesWs: options.createResponsesWs,
|
|
3315
|
+
wsConnectTimeoutMs: options.websocketConnectTimeoutMs,
|
|
3316
|
+
wsResponseIdleTimeoutMs: options.websocketResponseIdleTimeoutMs
|
|
3266
3317
|
});
|
|
3267
3318
|
}
|
|
3268
3319
|
async ainvoke(input, context) {
|
|
@@ -3390,7 +3441,7 @@ var ChatOpenAI = class {
|
|
|
3390
3441
|
const canUsePreviousResponseId = this.websocketApiVersion === "v2" && Boolean(wsState.previousResponseId) && !shouldResetChain && incrementalInput !== null;
|
|
3391
3442
|
const chainReset = shouldResetChain || Boolean(wsState.previousResponseId) && !canUsePreviousResponseId;
|
|
3392
3443
|
let wsInputMode = "full_no_previous";
|
|
3393
|
-
if (wsState.previousResponseId) {
|
|
3444
|
+
if (Boolean(wsState.previousResponseId)) {
|
|
3394
3445
|
if (canUsePreviousResponseId) {
|
|
3395
3446
|
if (Array.isArray(incrementalInput) && incrementalInput.length === 0) {
|
|
3396
3447
|
wsInputMode = "empty";
|
|
@@ -3452,50 +3503,43 @@ var ChatOpenAI = class {
|
|
|
3452
3503
|
} catch (error) {
|
|
3453
3504
|
let failure = error;
|
|
3454
3505
|
if (this.websocketMode === "on" && this.isWsReconnectRetryableError(failure)) {
|
|
3455
|
-
const retryWsInputMode =
|
|
3506
|
+
const retryWsInputMode = Boolean(
|
|
3507
|
+
wsState.previousResponseId
|
|
3508
|
+
) ? "full_regenerated" : "full_no_previous";
|
|
3456
3509
|
this.closeWsWithoutMaskingPrimaryError(wsState.ws, "retry_reset", failure);
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
chainReset: true,
|
|
3491
|
-
wsInputMode: retryWsInputMode
|
|
3492
|
-
};
|
|
3493
|
-
} catch (retryError) {
|
|
3494
|
-
failure = retryError;
|
|
3495
|
-
if (!this.isWsReconnectRetryableError(failure)) {
|
|
3496
|
-
break;
|
|
3497
|
-
}
|
|
3498
|
-
}
|
|
3510
|
+
try {
|
|
3511
|
+
await this.debugRequestIfEnabled(
|
|
3512
|
+
args.request,
|
|
3513
|
+
args.debugSeq,
|
|
3514
|
+
args.sessionIdHeader,
|
|
3515
|
+
"ws_mode",
|
|
3516
|
+
false,
|
|
3517
|
+
true,
|
|
3518
|
+
retryWsInputMode
|
|
3519
|
+
);
|
|
3520
|
+
const { response, ws } = await this.invokeViaWs({
|
|
3521
|
+
request: args.request,
|
|
3522
|
+
signal: args.signal,
|
|
3523
|
+
sessionIdHeader: args.sessionIdHeader,
|
|
3524
|
+
ws: void 0
|
|
3525
|
+
});
|
|
3526
|
+
this.wsReconnectCount += 1;
|
|
3527
|
+
this.persistWsSessionState({
|
|
3528
|
+
sessionKey: args.sessionKey,
|
|
3529
|
+
request: args.request,
|
|
3530
|
+
requestMeta: args.requestMeta,
|
|
3531
|
+
response,
|
|
3532
|
+
ws
|
|
3533
|
+
});
|
|
3534
|
+
return {
|
|
3535
|
+
response,
|
|
3536
|
+
transport: "ws_mode",
|
|
3537
|
+
fallbackUsed: false,
|
|
3538
|
+
chainReset: true,
|
|
3539
|
+
wsInputMode: retryWsInputMode
|
|
3540
|
+
};
|
|
3541
|
+
} catch (retryError) {
|
|
3542
|
+
failure = retryError;
|
|
3499
3543
|
}
|
|
3500
3544
|
}
|
|
3501
3545
|
const wsErrorCode = this.extractWsErrorCode(failure);
|
|
@@ -3553,11 +3597,21 @@ var ChatOpenAI = class {
|
|
|
3553
3597
|
instructionsHash: args.requestMeta.instructionsHash,
|
|
3554
3598
|
toolsHash: args.requestMeta.toolsHash,
|
|
3555
3599
|
model: args.requestMeta.model,
|
|
3556
|
-
lastInput: args.request.input,
|
|
3600
|
+
lastInput: this.buildWsLastInput(args.request.input, args.response),
|
|
3557
3601
|
ws: args.ws,
|
|
3558
3602
|
lastUsedAt: Date.now()
|
|
3559
3603
|
});
|
|
3560
3604
|
}
|
|
3605
|
+
buildWsLastInput(requestInput, response) {
|
|
3606
|
+
if (!Array.isArray(requestInput)) {
|
|
3607
|
+
return requestInput;
|
|
3608
|
+
}
|
|
3609
|
+
const replayItems = toResponsesInput(toChatInvokeCompletion2(response).messages);
|
|
3610
|
+
if (replayItems.length === 0) {
|
|
3611
|
+
return requestInput;
|
|
3612
|
+
}
|
|
3613
|
+
return [...requestInput, ...replayItems];
|
|
3614
|
+
}
|
|
3561
3615
|
async invokeViaWs(args) {
|
|
3562
3616
|
return this.wsTransport.invoke(args);
|
|
3563
3617
|
}
|
|
@@ -3580,35 +3634,6 @@ var ChatOpenAI = class {
|
|
|
3580
3634
|
const message = error.message.toLowerCase();
|
|
3581
3635
|
return message.includes("response timeout") || message.includes("closed before response") || message.includes("closed before open") || message.includes("connect timeout") || message.includes("could not send data") || message.includes("websocket is not open");
|
|
3582
3636
|
}
|
|
3583
|
-
getWsReconnectRetryDelayMs(retryAttempt) {
|
|
3584
|
-
const backoff = WS_ON_MODE_RETRY_BASE_BACKOFF_MS * 2 ** Math.max(retryAttempt - 1, 0);
|
|
3585
|
-
return Math.min(backoff, WS_ON_MODE_RETRY_MAX_BACKOFF_MS);
|
|
3586
|
-
}
|
|
3587
|
-
async waitForWsReconnectRetryDelay(retryAttempt, signal) {
|
|
3588
|
-
if (signal?.aborted) {
|
|
3589
|
-
throw new Error("openai websocket request aborted");
|
|
3590
|
-
}
|
|
3591
|
-
const delayMs = this.getWsReconnectRetryDelayMs(retryAttempt);
|
|
3592
|
-
await new Promise((resolve, reject) => {
|
|
3593
|
-
const timeout = setTimeout(() => {
|
|
3594
|
-
teardown();
|
|
3595
|
-
resolve();
|
|
3596
|
-
}, delayMs);
|
|
3597
|
-
const onAbort = () => {
|
|
3598
|
-
teardown();
|
|
3599
|
-
reject(new Error("openai websocket request aborted"));
|
|
3600
|
-
};
|
|
3601
|
-
const teardown = () => {
|
|
3602
|
-
clearTimeout(timeout);
|
|
3603
|
-
if (signal) {
|
|
3604
|
-
signal.removeEventListener("abort", onAbort);
|
|
3605
|
-
}
|
|
3606
|
-
};
|
|
3607
|
-
if (signal) {
|
|
3608
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
3609
|
-
}
|
|
3610
|
-
});
|
|
3611
|
-
}
|
|
3612
3637
|
isWsConnectionReusable(ws) {
|
|
3613
3638
|
return this.wsTransport.isConnectionReusable(ws);
|
|
3614
3639
|
}
|
|
@@ -3654,7 +3679,7 @@ var ChatOpenAI = class {
|
|
|
3654
3679
|
return void 0;
|
|
3655
3680
|
}
|
|
3656
3681
|
if (!Array.isArray(previousInput) || !Array.isArray(currentInput)) {
|
|
3657
|
-
return
|
|
3682
|
+
return null;
|
|
3658
3683
|
}
|
|
3659
3684
|
if (previousInput.length > currentInput.length) {
|
|
3660
3685
|
return null;
|
|
@@ -3665,7 +3690,7 @@ var ChatOpenAI = class {
|
|
|
3665
3690
|
}
|
|
3666
3691
|
}
|
|
3667
3692
|
if (previousInput.length === currentInput.length) {
|
|
3668
|
-
return
|
|
3693
|
+
return null;
|
|
3669
3694
|
}
|
|
3670
3695
|
return currentInput.slice(previousInput.length);
|
|
3671
3696
|
}
|
|
@@ -4449,6 +4474,18 @@ var withRequiredProperties = (schema) => mapSchema(schema, (next) => {
|
|
|
4449
4474
|
}
|
|
4450
4475
|
return next;
|
|
4451
4476
|
});
|
|
4477
|
+
var withTopLevelObjectTypeForObjectUnions = (schema) => {
|
|
4478
|
+
if (schema.type !== void 0) return schema;
|
|
4479
|
+
const variants = (Array.isArray(schema.anyOf) && schema.anyOf.length > 0 ? schema.anyOf : Array.isArray(schema.oneOf) && schema.oneOf.length > 0 ? schema.oneOf : null) ?? null;
|
|
4480
|
+
if (!variants) return schema;
|
|
4481
|
+
const allObjectVariants = variants.every((variant) => {
|
|
4482
|
+
if (!variant || typeof variant !== "object") return false;
|
|
4483
|
+
const jsonSchema = variant;
|
|
4484
|
+
return jsonSchema.type === "object";
|
|
4485
|
+
});
|
|
4486
|
+
if (!allObjectVariants) return schema;
|
|
4487
|
+
return { ...schema, type: "object" };
|
|
4488
|
+
};
|
|
4452
4489
|
function toToolResult(value) {
|
|
4453
4490
|
if (isToolResult(value)) return value;
|
|
4454
4491
|
if (typeof value === "string") return { type: "text", text: value };
|
|
@@ -4461,8 +4498,8 @@ function defineTool(toolOptions) {
|
|
|
4461
4498
|
target: "draft-07",
|
|
4462
4499
|
io: "input"
|
|
4463
4500
|
});
|
|
4464
|
-
const strictParameters =
|
|
4465
|
-
withNoAdditionalProperties(parameters)
|
|
4501
|
+
const strictParameters = withTopLevelObjectTypeForObjectUnions(
|
|
4502
|
+
withRequiredProperties(withNoAdditionalProperties(parameters))
|
|
4466
4503
|
);
|
|
4467
4504
|
return {
|
|
4468
4505
|
name: toolOptions.name,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codelia/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.29",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@anthropic-ai/sdk": "^0.78.0",
|
|
28
|
-
"@codelia/config": "0.1.
|
|
29
|
-
"@codelia/shared-types": "0.1.
|
|
28
|
+
"@codelia/config": "0.1.29",
|
|
29
|
+
"@codelia/shared-types": "0.1.29",
|
|
30
30
|
"@google-cloud/vertexai": "^1.10.0",
|
|
31
31
|
"@google/genai": "^1.37.0",
|
|
32
32
|
"json-schema": "^0.4.0",
|
|
33
|
-
"openai": "^6.
|
|
33
|
+
"openai": "^6.25.0",
|
|
34
34
|
"zod": "^4.3.5"
|
|
35
35
|
}
|
|
36
36
|
}
|
package/prompts/system.md
CHANGED
|
@@ -52,6 +52,9 @@ Assume:
|
|
|
52
52
|
- Keep types tight in typed languages; avoid escaping the type system when safer narrowing is possible.
|
|
53
53
|
- Prefer the smallest correct edit. Avoid broad refactors unless explicitly requested.
|
|
54
54
|
- When editing, prefer `edit` for targeted patches; prefer `write` only when replacing an entire file is simpler/safer.
|
|
55
|
+
- Treat `edit` misses (for example `String not found in <path>`) as hard failures, not partial success.
|
|
56
|
+
- After an `edit`, verify the intended change (e.g. re-read target lines or inspect diff) before proceeding to follow-up edits.
|
|
57
|
+
- If an `edit` misses repeatedly on the same target, stop and re-locate the exact current text instead of retrying the same patch blindly.
|
|
55
58
|
|
|
56
59
|
## Workflow expectations
|
|
57
60
|
|
|
@@ -89,6 +92,10 @@ When implementing features/changes:
|
|
|
89
92
|
- Create a short plan before execution for non-trivial tasks.
|
|
90
93
|
- Keep the plan short, ordered, and update it when scope or facts change.
|
|
91
94
|
- Skip formal plans for straightforward tasks; do not make single-step plans.
|
|
95
|
+
- For non-trivial work, maintain the plan with `todo_write` / `todo_read` instead of keeping it only in free-form text.
|
|
96
|
+
- Keep at most one todo item in `in_progress`; complete or reprioritize it before starting another.
|
|
97
|
+
- Use `todo_write` modes intentionally: `new` for initial/restart planning, `append` for newly discovered tasks, `patch` for progress/status updates by id, and `clear` when the plan should be reset.
|
|
98
|
+
- Before final response on non-trivial work, check `todo_read` and either finish pending work or explicitly report what remains.
|
|
92
99
|
|
|
93
100
|
## Special user requests
|
|
94
101
|
|