codex-relay 1.5.2 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api-schema.js +2 -2
- package/dist/api-schema2.js +13 -1
- package/dist/paths.js +15 -4
- package/dist/src.js +90 -39
- package/package.json +3 -3
- package/src/api-schema.ts +15 -0
package/dist/api-schema.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $ as ResolveApprovalResponseSchema, $t as
|
|
2
|
-
export { AgentSkillSchema, AgentSkillSourceSchema, ApprovalDecisionSchema, ApprovalModeSchema, ArchiveThreadResponseSchema, ChatMessageKindSchema, ChatMessagePromptDetailsSchema, ChatMessageRoleSchema, ChatMessageSchema, ChatMessageStateSchema, CheckoutWorkspaceBranchRequestSchema, CodexModelSchema, CommitPushWorkspaceRequestSchema, ContextWindowUsageSchema, CreateThreadRequestSchema, CreateThreadResponseSchema, EncryptedPayloadSchema, ErrorResponseSchema, ImageAttachmentUploadResponseSchema, InterruptThreadRunResponseSchema, IsoDateTimeSchema, KnownReasoningEffortSchema, ListModelsResponseSchema, ListQueuedThreadInputsResponseSchema, ListSkillsResponseSchema, ListThreadsResponseSchema, ListWorkspaceDirectoriesResponseSchema, ListWorkspaceFilesResponseSchema, PairEncryptedPayloadSchema, PairRequestSchema, PairResponseSchema, PendingInputRequestOptionSchema, PendingInputRequestQuestionSchema, PendingInputRequestSchema, PromptAttachmentSchema, PromptAttachmentSummarySchema, PromptContextInputSchema, PromptContextSchema, PromptSkillSchema, PushNotificationIntentSchema, PushNotificationPreferencesSchema, PushNotificationSettingsResponseSchema, QueuedThreadInputActionResponseSchema, QueuedThreadInputSchema, RateLimitBucketSchema, RateLimitWindowSchema, RateLimitsResponseSchema, ReasoningEffortSchema, RegisterPushNotificationRequestSchema, RenameThreadRequestSchema, RenameThreadResponseSchema, ResolveApprovalRequestSchema, ResolveApprovalResponseSchema, RewindThreadRequestSchema, RunThreadRequestSchema, RunThreadResponseSchema, RuntimeModeSchema, RuntimePreferencesByWorkspacePathSchema, RuntimePreferencesResponseSchema, RuntimePreferencesSchema, SandboxModeSchema, StatusResponseSchema, StreamThreadRunEventSchema, StreamThreadRunRequestSchema, SubmitThreadInputResponseSchema, ThreadCollaborationModeSchema, ThreadContextWindowResponseSchema, ThreadDetailResponseSchema, ThreadGoalResponseSchema, ThreadGoalSchema, ThreadGoalStatusSchema, ThreadMessageDetailFieldSchema, ThreadMessageDetailResponseSchema, ThreadRunOptionsSchema, ThreadStateSchema, ThreadSummarySchema, UpdateRuntimePreferencesRequestSchema, UpdateThreadGoalRequestSchema, UpdateWorkspaceFileContentRequestSchema, VersionResponseSchema, WORKSPACE_PREVIEW_OPEN_PROTOCOL, WORKSPACE_PREVIEW_TAB_VALUES, WebPreviewTargetSchema, WorkspaceChangesResponseSchema, WorkspaceDirectoryEntrySchema, WorkspaceFileContentResponseSchema, WorkspaceFileMentionSchema, WorkspaceGitActionResponseSchema, WorkspaceMarkdownPreviewTargetSchema, WorkspacePreviewNavigationRequestSchema, WorkspacePreviewTabSchema, WorkspaceSelectionRequestSchema, WorkspaceTailscaleServeRequestSchema, WorkspaceTailscaleServeResponseSchema, WorkspaceTerminalInputRequestSchema, WorkspaceTerminalOutputChunkSchema, WorkspaceTerminalOutputResponseSchema, WorkspaceTerminalResizeRequestSchema, WorkspaceTerminalSessionResponseSchema, WorkspaceTerminalStartRequestSchema, apiPaths, chatMessageDetailsFromPromptContext, createOpenApiDocument, isPromptSkillMarkdownMention, normalizePromptContext, promptMarkdownWithSkills, promptSkillDisplayName, promptSkillMentionLabel, promptSkillMentionMarkdown, promptSkillMentionTextCandidates, stripPromptSkillMentions };
|
|
1
|
+
import { $ as ResolveApprovalResponseSchema, $t as promptMarkdownWithSkills, A as PairRequestSchema, At as WorkspaceChangesResponseSchema, B as PushNotificationIntentSchema, Bt as WorkspaceTailscaleServeResponseSchema, C as ListModelsResponseSchema, Ct as UpdateRuntimePreferencesRequestSchema, D as ListWorkspaceDirectoriesResponseSchema, Dt as WORKSPACE_PREVIEW_OPEN_PROTOCOL, E as ListThreadsResponseSchema, Et as VersionResponseSchema, F as PromptAttachmentSchema, Ft as WorkspaceMarkdownPreviewTargetSchema, G as RateLimitBucketSchema, Gt as WorkspaceTerminalSessionResponseSchema, H as PushNotificationSettingsResponseSchema, Ht as WorkspaceTerminalOutputChunkSchema, I as PromptAttachmentSummarySchema, It as WorkspacePreviewNavigationRequestSchema, J as ReasoningEffortSchema, Jt as chatMessageDetailsFromPromptContext, K as RateLimitWindowSchema, Kt as WorkspaceTerminalStartRequestSchema, L as PromptContextInputSchema, Lt as WorkspacePreviewTabSchema, M as PendingInputRequestOptionSchema, Mt as WorkspaceFileContentResponseSchema, N as PendingInputRequestQuestionSchema, Nt as WorkspaceFileMentionSchema, O as ListWorkspaceFilesResponseSchema, Ot as WORKSPACE_PREVIEW_TAB_VALUES, P as PendingInputRequestSchema, Pt as WorkspaceGitActionResponseSchema, Q as ResolveApprovalRequestSchema, Qt as normalizePromptContext, R as PromptContextSchema, Rt as WorkspaceSelectionRequestSchema, S as KnownReasoningEffortSchema, St as ThreadSummarySchema, T as ListSkillsResponseSchema, Tt as UpdateWorkspaceFileContentRequestSchema, U as QueuedThreadInputActionResponseSchema, Ut as WorkspaceTerminalOutputResponseSchema, V as PushNotificationPreferencesSchema, Vt as WorkspaceTerminalInputRequestSchema, W as QueuedThreadInputSchema, Wt as WorkspaceTerminalResizeRequestSchema, X as RenameThreadRequestSchema, Xt as isPromptSkillMarkdownMention, Y as RegisterPushNotificationRequestSchema, Yt as createOpenApiDocument, Z as RenameThreadResponseSchema, Zt as lowestRateLimitRemainingPercent, _ as EncryptedPayloadSchema, _t as ThreadGoalStatusSchema, a as ArchiveThreadResponseSchema, an as stripPromptSkillMentions, at as RuntimePreferencesResponseSchema, b as InterruptThreadRunResponseSchema, bt as ThreadRunOptionsSchema, c as ChatMessageRoleSchema, ct as StatusResponseSchema, d as CheckoutWorkspaceBranchRequestSchema, dt as SubmitThreadInputResponseSchema, en as promptSkillDisplayName, et as RewindThreadRequestSchema, f as CodexModelSchema, ft as ThreadCollaborationModeSchema, g as CreateThreadResponseSchema, gt as ThreadGoalSchema, h as CreateThreadRequestSchema, ht as ThreadGoalResponseSchema, i as ApprovalModeSchema, in as rateLimitRemainingPercent, it as RuntimePreferencesByWorkspacePathSchema, j as PairResponseSchema, jt as WorkspaceDirectoryEntrySchema, k as PairEncryptedPayloadSchema, kt as WebPreviewTargetSchema, l as ChatMessageSchema, lt as StreamThreadRunEventSchema, m as ContextWindowUsageSchema, mt as ThreadDetailResponseSchema, n as AgentSkillSourceSchema, nn as promptSkillMentionMarkdown, nt as RunThreadResponseSchema, o as ChatMessageKindSchema, ot as RuntimePreferencesSchema, p as CommitPushWorkspaceRequestSchema, pt as ThreadContextWindowResponseSchema, q as RateLimitsResponseSchema, qt as apiPaths, r as ApprovalDecisionSchema, rn as promptSkillMentionTextCandidates, rt as RuntimeModeSchema, s as ChatMessagePromptDetailsSchema, st as SandboxModeSchema, t as AgentSkillSchema, tn as promptSkillMentionLabel, tt as RunThreadRequestSchema, u as ChatMessageStateSchema, ut as StreamThreadRunRequestSchema, v as ErrorResponseSchema, vt as ThreadMessageDetailFieldSchema, w as ListQueuedThreadInputsResponseSchema, wt as UpdateThreadGoalRequestSchema, x as IsoDateTimeSchema, xt as ThreadStateSchema, y as ImageAttachmentUploadResponseSchema, yt as ThreadMessageDetailResponseSchema, z as PromptSkillSchema, zt as WorkspaceTailscaleServeRequestSchema } from "./api-schema2.js";
|
|
2
|
+
export { AgentSkillSchema, AgentSkillSourceSchema, ApprovalDecisionSchema, ApprovalModeSchema, ArchiveThreadResponseSchema, ChatMessageKindSchema, ChatMessagePromptDetailsSchema, ChatMessageRoleSchema, ChatMessageSchema, ChatMessageStateSchema, CheckoutWorkspaceBranchRequestSchema, CodexModelSchema, CommitPushWorkspaceRequestSchema, ContextWindowUsageSchema, CreateThreadRequestSchema, CreateThreadResponseSchema, EncryptedPayloadSchema, ErrorResponseSchema, ImageAttachmentUploadResponseSchema, InterruptThreadRunResponseSchema, IsoDateTimeSchema, KnownReasoningEffortSchema, ListModelsResponseSchema, ListQueuedThreadInputsResponseSchema, ListSkillsResponseSchema, ListThreadsResponseSchema, ListWorkspaceDirectoriesResponseSchema, ListWorkspaceFilesResponseSchema, PairEncryptedPayloadSchema, PairRequestSchema, PairResponseSchema, PendingInputRequestOptionSchema, PendingInputRequestQuestionSchema, PendingInputRequestSchema, PromptAttachmentSchema, PromptAttachmentSummarySchema, PromptContextInputSchema, PromptContextSchema, PromptSkillSchema, PushNotificationIntentSchema, PushNotificationPreferencesSchema, PushNotificationSettingsResponseSchema, QueuedThreadInputActionResponseSchema, QueuedThreadInputSchema, RateLimitBucketSchema, RateLimitWindowSchema, RateLimitsResponseSchema, ReasoningEffortSchema, RegisterPushNotificationRequestSchema, RenameThreadRequestSchema, RenameThreadResponseSchema, ResolveApprovalRequestSchema, ResolveApprovalResponseSchema, RewindThreadRequestSchema, RunThreadRequestSchema, RunThreadResponseSchema, RuntimeModeSchema, RuntimePreferencesByWorkspacePathSchema, RuntimePreferencesResponseSchema, RuntimePreferencesSchema, SandboxModeSchema, StatusResponseSchema, StreamThreadRunEventSchema, StreamThreadRunRequestSchema, SubmitThreadInputResponseSchema, ThreadCollaborationModeSchema, ThreadContextWindowResponseSchema, ThreadDetailResponseSchema, ThreadGoalResponseSchema, ThreadGoalSchema, ThreadGoalStatusSchema, ThreadMessageDetailFieldSchema, ThreadMessageDetailResponseSchema, ThreadRunOptionsSchema, ThreadStateSchema, ThreadSummarySchema, UpdateRuntimePreferencesRequestSchema, UpdateThreadGoalRequestSchema, UpdateWorkspaceFileContentRequestSchema, VersionResponseSchema, WORKSPACE_PREVIEW_OPEN_PROTOCOL, WORKSPACE_PREVIEW_TAB_VALUES, WebPreviewTargetSchema, WorkspaceChangesResponseSchema, WorkspaceDirectoryEntrySchema, WorkspaceFileContentResponseSchema, WorkspaceFileMentionSchema, WorkspaceGitActionResponseSchema, WorkspaceMarkdownPreviewTargetSchema, WorkspacePreviewNavigationRequestSchema, WorkspacePreviewTabSchema, WorkspaceSelectionRequestSchema, WorkspaceTailscaleServeRequestSchema, WorkspaceTailscaleServeResponseSchema, WorkspaceTerminalInputRequestSchema, WorkspaceTerminalOutputChunkSchema, WorkspaceTerminalOutputResponseSchema, WorkspaceTerminalResizeRequestSchema, WorkspaceTerminalSessionResponseSchema, WorkspaceTerminalStartRequestSchema, apiPaths, chatMessageDetailsFromPromptContext, createOpenApiDocument, isPromptSkillMarkdownMention, lowestRateLimitRemainingPercent, normalizePromptContext, promptMarkdownWithSkills, promptSkillDisplayName, promptSkillMentionLabel, promptSkillMentionMarkdown, promptSkillMentionTextCandidates, rateLimitRemainingPercent, stripPromptSkillMentions };
|
package/dist/api-schema2.js
CHANGED
|
@@ -107,6 +107,7 @@ const RuntimePreferencesResponseSchema = z.object({
|
|
|
107
107
|
const PushNotificationIntentSchema = z.enum(["turn_terminal", "action_required"]);
|
|
108
108
|
const PushNotificationPreferencesSchema = z.object({
|
|
109
109
|
actionRequired: z.boolean(),
|
|
110
|
+
includeRemainingUsage: z.boolean().default(false),
|
|
110
111
|
turnTerminal: z.boolean()
|
|
111
112
|
});
|
|
112
113
|
const RegisterPushNotificationRequestSchema = z.object({
|
|
@@ -169,6 +170,13 @@ const RateLimitBucketSchema = z.object({
|
|
|
169
170
|
rateLimitReachedType: z.string().nullable().optional()
|
|
170
171
|
});
|
|
171
172
|
const RateLimitsResponseSchema = z.object({ buckets: z.array(RateLimitBucketSchema) });
|
|
173
|
+
function rateLimitRemainingPercent(usedPercent) {
|
|
174
|
+
return 100 - Math.max(0, Math.min(100, usedPercent));
|
|
175
|
+
}
|
|
176
|
+
function lowestRateLimitRemainingPercent(buckets) {
|
|
177
|
+
const remaining = buckets.flatMap((bucket) => [bucket.primary, bucket.secondary].flatMap((window) => window ? [rateLimitRemainingPercent(window.usedPercent)] : []));
|
|
178
|
+
return remaining.length > 0 ? Math.min(...remaining) : void 0;
|
|
179
|
+
}
|
|
172
180
|
const ThreadContextWindowResponseSchema = z.object({
|
|
173
181
|
threadId: z.string().min(1),
|
|
174
182
|
usage: ContextWindowUsageSchema.nullable(),
|
|
@@ -1355,6 +1363,10 @@ function createOpenApiDocument() {
|
|
|
1355
1363
|
required: ["actionRequired", "turnTerminal"],
|
|
1356
1364
|
properties: {
|
|
1357
1365
|
actionRequired: { type: "boolean" },
|
|
1366
|
+
includeRemainingUsage: {
|
|
1367
|
+
type: "boolean",
|
|
1368
|
+
default: false
|
|
1369
|
+
},
|
|
1358
1370
|
turnTerminal: { type: "boolean" }
|
|
1359
1371
|
}
|
|
1360
1372
|
},
|
|
@@ -1867,4 +1879,4 @@ function jsonResponse(schemaName) {
|
|
|
1867
1879
|
};
|
|
1868
1880
|
}
|
|
1869
1881
|
//#endregion
|
|
1870
|
-
export { ResolveApprovalResponseSchema as $,
|
|
1882
|
+
export { ResolveApprovalResponseSchema as $, promptMarkdownWithSkills as $t, PairRequestSchema as A, WorkspaceChangesResponseSchema as At, PushNotificationIntentSchema as B, WorkspaceTailscaleServeResponseSchema as Bt, ListModelsResponseSchema as C, UpdateRuntimePreferencesRequestSchema as Ct, ListWorkspaceDirectoriesResponseSchema as D, WORKSPACE_PREVIEW_OPEN_PROTOCOL as Dt, ListThreadsResponseSchema as E, VersionResponseSchema as Et, PromptAttachmentSchema as F, WorkspaceMarkdownPreviewTargetSchema as Ft, RateLimitBucketSchema as G, WorkspaceTerminalSessionResponseSchema as Gt, PushNotificationSettingsResponseSchema as H, WorkspaceTerminalOutputChunkSchema as Ht, PromptAttachmentSummarySchema as I, WorkspacePreviewNavigationRequestSchema as It, ReasoningEffortSchema as J, chatMessageDetailsFromPromptContext as Jt, RateLimitWindowSchema as K, WorkspaceTerminalStartRequestSchema as Kt, PromptContextInputSchema as L, WorkspacePreviewTabSchema as Lt, PendingInputRequestOptionSchema as M, WorkspaceFileContentResponseSchema as Mt, PendingInputRequestQuestionSchema as N, WorkspaceFileMentionSchema as Nt, ListWorkspaceFilesResponseSchema as O, WORKSPACE_PREVIEW_TAB_VALUES as Ot, PendingInputRequestSchema as P, WorkspaceGitActionResponseSchema as Pt, ResolveApprovalRequestSchema as Q, normalizePromptContext as Qt, PromptContextSchema as R, WorkspaceSelectionRequestSchema as Rt, KnownReasoningEffortSchema as S, ThreadSummarySchema as St, ListSkillsResponseSchema as T, UpdateWorkspaceFileContentRequestSchema as Tt, QueuedThreadInputActionResponseSchema as U, WorkspaceTerminalOutputResponseSchema as Ut, PushNotificationPreferencesSchema as V, WorkspaceTerminalInputRequestSchema as Vt, QueuedThreadInputSchema as W, WorkspaceTerminalResizeRequestSchema as Wt, RenameThreadRequestSchema as X, isPromptSkillMarkdownMention as Xt, RegisterPushNotificationRequestSchema as Y, createOpenApiDocument as Yt, RenameThreadResponseSchema as Z, lowestRateLimitRemainingPercent as Zt, EncryptedPayloadSchema as _, ThreadGoalStatusSchema as _t, ArchiveThreadResponseSchema as a, stripPromptSkillMentions as an, RuntimePreferencesResponseSchema as at, InterruptThreadRunResponseSchema as b, ThreadRunOptionsSchema as bt, ChatMessageRoleSchema as c, StatusResponseSchema as ct, CheckoutWorkspaceBranchRequestSchema as d, SubmitThreadInputResponseSchema as dt, promptSkillDisplayName as en, RewindThreadRequestSchema as et, CodexModelSchema as f, ThreadCollaborationModeSchema as ft, CreateThreadResponseSchema as g, ThreadGoalSchema as gt, CreateThreadRequestSchema as h, ThreadGoalResponseSchema as ht, ApprovalModeSchema as i, rateLimitRemainingPercent as in, RuntimePreferencesByWorkspacePathSchema as it, PairResponseSchema as j, WorkspaceDirectoryEntrySchema as jt, PairEncryptedPayloadSchema as k, WebPreviewTargetSchema as kt, ChatMessageSchema as l, StreamThreadRunEventSchema as lt, ContextWindowUsageSchema as m, ThreadDetailResponseSchema as mt, AgentSkillSourceSchema as n, promptSkillMentionMarkdown as nn, RunThreadResponseSchema as nt, ChatMessageKindSchema as o, RuntimePreferencesSchema as ot, CommitPushWorkspaceRequestSchema as p, ThreadContextWindowResponseSchema as pt, RateLimitsResponseSchema as q, apiPaths as qt, ApprovalDecisionSchema as r, promptSkillMentionTextCandidates as rn, RuntimeModeSchema as rt, ChatMessagePromptDetailsSchema as s, SandboxModeSchema as st, AgentSkillSchema as t, promptSkillMentionLabel as tn, RunThreadRequestSchema as tt, ChatMessageStateSchema as u, StreamThreadRunRequestSchema as ut, ErrorResponseSchema as v, ThreadMessageDetailFieldSchema as vt, ListQueuedThreadInputsResponseSchema as w, UpdateThreadGoalRequestSchema as wt, IsoDateTimeSchema as x, ThreadStateSchema as xt, ImageAttachmentUploadResponseSchema as y, ThreadMessageDetailResponseSchema as yt, PromptSkillSchema as z, WorkspaceTailscaleServeRequestSchema as zt };
|
package/dist/paths.js
CHANGED
|
@@ -130,11 +130,13 @@ async function createTursoPairingSessionStore(path) {
|
|
|
130
130
|
platform TEXT NOT NULL,
|
|
131
131
|
turn_terminal_enabled INTEGER NOT NULL,
|
|
132
132
|
action_required_enabled INTEGER NOT NULL,
|
|
133
|
+
include_remaining_usage_enabled INTEGER NOT NULL DEFAULT 0,
|
|
133
134
|
created_at INTEGER NOT NULL,
|
|
134
135
|
updated_at INTEGER NOT NULL
|
|
135
136
|
);
|
|
136
137
|
`);
|
|
137
138
|
await ensurePairingSessionColumns();
|
|
139
|
+
await ensurePushNotificationSubscriptionColumns();
|
|
138
140
|
async function countActive() {
|
|
139
141
|
const row = await db.prepare("SELECT COUNT(DISTINCT COALESCE(client_session_id, token_hash)) AS count FROM pairing_sessions").get();
|
|
140
142
|
return Number(row?.count ?? 0);
|
|
@@ -250,7 +252,8 @@ async function createTursoPairingSessionStore(path) {
|
|
|
250
252
|
expo_push_token AS expoPushToken,
|
|
251
253
|
platform,
|
|
252
254
|
turn_terminal_enabled AS turnTerminal,
|
|
253
|
-
action_required_enabled AS actionRequired
|
|
255
|
+
action_required_enabled AS actionRequired,
|
|
256
|
+
include_remaining_usage_enabled AS includeRemainingUsage
|
|
254
257
|
FROM push_notification_subscriptions
|
|
255
258
|
WHERE client_session_id = ?`).get(clientSessionId);
|
|
256
259
|
return row ? pushNotificationSubscriptionFromRow(row) : void 0;
|
|
@@ -279,7 +282,8 @@ async function createTursoPairingSessionStore(path) {
|
|
|
279
282
|
subscriptions.expo_push_token AS expoPushToken,
|
|
280
283
|
subscriptions.platform,
|
|
281
284
|
subscriptions.turn_terminal_enabled AS turnTerminal,
|
|
282
|
-
subscriptions.action_required_enabled AS actionRequired
|
|
285
|
+
subscriptions.action_required_enabled AS actionRequired,
|
|
286
|
+
subscriptions.include_remaining_usage_enabled AS includeRemainingUsage
|
|
283
287
|
FROM push_notification_subscriptions AS subscriptions
|
|
284
288
|
INNER JOIN pairing_sessions AS sessions
|
|
285
289
|
ON sessions.client_session_id = subscriptions.client_session_id
|
|
@@ -343,16 +347,18 @@ async function createTursoPairingSessionStore(path) {
|
|
|
343
347
|
platform,
|
|
344
348
|
turn_terminal_enabled,
|
|
345
349
|
action_required_enabled,
|
|
350
|
+
include_remaining_usage_enabled,
|
|
346
351
|
created_at,
|
|
347
352
|
updated_at
|
|
348
353
|
)
|
|
349
|
-
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
354
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
350
355
|
ON CONFLICT(client_session_id) DO UPDATE SET
|
|
351
356
|
expo_push_token = excluded.expo_push_token,
|
|
352
357
|
platform = excluded.platform,
|
|
353
358
|
turn_terminal_enabled = excluded.turn_terminal_enabled,
|
|
354
359
|
action_required_enabled = excluded.action_required_enabled,
|
|
355
|
-
|
|
360
|
+
include_remaining_usage_enabled = excluded.include_remaining_usage_enabled,
|
|
361
|
+
updated_at = excluded.updated_at`).run(subscription.clientSessionId, subscription.expoPushToken, subscription.platform, subscription.turnTerminal ? 1 : 0, subscription.actionRequired ? 1 : 0, subscription.includeRemainingUsage ? 1 : 0, now, now);
|
|
356
362
|
}
|
|
357
363
|
};
|
|
358
364
|
async function ensurePairingSessionColumns() {
|
|
@@ -369,6 +375,10 @@ async function createTursoPairingSessionStore(path) {
|
|
|
369
375
|
const pendingRows = await db.prepare("PRAGMA table_info(pending_pairings)").all();
|
|
370
376
|
if (!new Set(resultRows(pendingRows).map((row) => String(row.name))).has("client_session_id")) await db.exec("ALTER TABLE pending_pairings ADD COLUMN client_session_id TEXT");
|
|
371
377
|
}
|
|
378
|
+
async function ensurePushNotificationSubscriptionColumns() {
|
|
379
|
+
const rows = await db.prepare("PRAGMA table_info(push_notification_subscriptions)").all();
|
|
380
|
+
if (!new Set(resultRows(rows).map((row) => String(row.name))).has("include_remaining_usage_enabled")) await db.exec("ALTER TABLE push_notification_subscriptions ADD COLUMN include_remaining_usage_enabled INTEGER NOT NULL DEFAULT 0");
|
|
381
|
+
}
|
|
372
382
|
}
|
|
373
383
|
function encodeSecureSession(session) {
|
|
374
384
|
if (!session) return;
|
|
@@ -397,6 +407,7 @@ function pushNotificationSubscriptionFromRow(row) {
|
|
|
397
407
|
actionRequired: Number(row.actionRequired) === 1,
|
|
398
408
|
clientSessionId: row.clientSessionId,
|
|
399
409
|
expoPushToken: row.expoPushToken,
|
|
410
|
+
includeRemainingUsage: Number(row.includeRemainingUsage) === 1,
|
|
400
411
|
platform,
|
|
401
412
|
turnTerminal: Number(row.turnTerminal) === 1
|
|
402
413
|
};
|
package/dist/src.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as ResolveApprovalResponseSchema, A as PairRequestSchema, At as WorkspaceChangesResponseSchema, Bt as WorkspaceTailscaleServeResponseSchema, C as ListModelsResponseSchema, Ct as UpdateRuntimePreferencesRequestSchema, D as ListWorkspaceDirectoriesResponseSchema, E as ListThreadsResponseSchema, Et as VersionResponseSchema, Gt as WorkspaceTerminalSessionResponseSchema, H as PushNotificationSettingsResponseSchema, J as ReasoningEffortSchema, Jt as chatMessageDetailsFromPromptContext, Kt as WorkspaceTerminalStartRequestSchema, Mt as WorkspaceFileContentResponseSchema, O as ListWorkspaceFilesResponseSchema, Pt as WorkspaceGitActionResponseSchema, Q as ResolveApprovalRequestSchema, Qt as
|
|
1
|
+
import { $ as ResolveApprovalResponseSchema, $t as promptMarkdownWithSkills, A as PairRequestSchema, At as WorkspaceChangesResponseSchema, Bt as WorkspaceTailscaleServeResponseSchema, C as ListModelsResponseSchema, Ct as UpdateRuntimePreferencesRequestSchema, D as ListWorkspaceDirectoriesResponseSchema, E as ListThreadsResponseSchema, Et as VersionResponseSchema, Gt as WorkspaceTerminalSessionResponseSchema, H as PushNotificationSettingsResponseSchema, J as ReasoningEffortSchema, Jt as chatMessageDetailsFromPromptContext, Kt as WorkspaceTerminalStartRequestSchema, Mt as WorkspaceFileContentResponseSchema, O as ListWorkspaceFilesResponseSchema, Pt as WorkspaceGitActionResponseSchema, Q as ResolveApprovalRequestSchema, Qt as normalizePromptContext, S as KnownReasoningEffortSchema, St as ThreadSummarySchema, T as ListSkillsResponseSchema, Tt as UpdateWorkspaceFileContentRequestSchema, U as QueuedThreadInputActionResponseSchema, Ut as WorkspaceTerminalOutputResponseSchema, Vt as WorkspaceTerminalInputRequestSchema, Wt as WorkspaceTerminalResizeRequestSchema, X as RenameThreadRequestSchema, Y as RegisterPushNotificationRequestSchema, Yt as createOpenApiDocument, Z as RenameThreadResponseSchema, Zt as lowestRateLimitRemainingPercent, _ as EncryptedPayloadSchema, _t as ThreadGoalStatusSchema, a as ArchiveThreadResponseSchema, an as stripPromptSkillMentions, at as RuntimePreferencesResponseSchema, b as InterruptThreadRunResponseSchema, ct as StatusResponseSchema, d as CheckoutWorkspaceBranchRequestSchema, dt as SubmitThreadInputResponseSchema, et as RewindThreadRequestSchema, gt as ThreadGoalSchema, h as CreateThreadRequestSchema, ht as ThreadGoalResponseSchema, j as PairResponseSchema, l as ChatMessageSchema, lt as StreamThreadRunEventSchema, m as ContextWindowUsageSchema, mt as ThreadDetailResponseSchema, ot as RuntimePreferencesSchema, p as CommitPushWorkspaceRequestSchema, pt as ThreadContextWindowResponseSchema, q as RateLimitsResponseSchema, qt as apiPaths, tt as RunThreadRequestSchema, ut as StreamThreadRunRequestSchema, vt as ThreadMessageDetailFieldSchema, w as ListQueuedThreadInputsResponseSchema, wt as UpdateThreadGoalRequestSchema, y as ImageAttachmentUploadResponseSchema, yt as ThreadMessageDetailResponseSchema, zt as WorkspaceTailscaleServeRequestSchema } from "./api-schema2.js";
|
|
2
2
|
import { a as getConnectUrlCandidates, c as permanentClientSessionExpiresAt, i as createPairingQrPayload, o as getConnectUrlGuidance, r as legacyCodexRelayDataPath, s as createTursoPairingSessionStore, t as codexRelayDataPath } from "./paths.js";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import qrcode from "qrcode-terminal";
|
|
@@ -1027,24 +1027,25 @@ function createExpoPushNotificationSender(fetchImpl = fetch) {
|
|
|
1027
1027
|
function createPushNotificationDispatcher(input) {
|
|
1028
1028
|
return { async dispatch(event) {
|
|
1029
1029
|
const subscriptions = await input.sessions.listActivePushNotificationSubscriptions();
|
|
1030
|
-
const
|
|
1031
|
-
if (
|
|
1032
|
-
const
|
|
1030
|
+
const selectedSubscriptions = new Map(subscriptions.filter((subscription) => notificationEnabled(subscription, event.intent)).map((subscription) => [subscription.expoPushToken, subscription]));
|
|
1031
|
+
if (selectedSubscriptions.size === 0) return;
|
|
1032
|
+
const remainingUsagePercent = event.intent === "turn_terminal" && [...selectedSubscriptions.values()].some((subscription) => subscription.includeRemainingUsage) ? await input.readRemainingUsagePercent?.().catch(() => void 0) : void 0;
|
|
1033
|
+
const delivery = await input.sender.send([...selectedSubscriptions.values()].map((subscription) => notificationForEvent(subscription.expoPushToken, event, subscription.includeRemainingUsage ? remainingUsagePercent : void 0)));
|
|
1033
1034
|
await Promise.all(delivery.invalidExpoPushTokens.map((expoPushToken) => input.sessions.deletePushNotificationSubscriptionsByExpoPushToken(expoPushToken)));
|
|
1034
1035
|
} };
|
|
1035
1036
|
}
|
|
1036
1037
|
function notificationEnabled(subscription, intent) {
|
|
1037
1038
|
return intent === "action_required" ? subscription.actionRequired : subscription.turnTerminal;
|
|
1038
1039
|
}
|
|
1039
|
-
function notificationForEvent(expoPushToken, event) {
|
|
1040
|
+
function notificationForEvent(expoPushToken, event, remainingUsagePercent) {
|
|
1040
1041
|
return {
|
|
1041
|
-
body: event.intent === "action_required" ? "Codex needs your attention." : "
|
|
1042
|
+
body: event.intent === "action_required" ? "Codex needs your attention." : remainingUsagePercent === void 0 ? "Finished working." : `Finished working. Remaining usage: ${remainingUsagePercent}%`,
|
|
1042
1043
|
data: {
|
|
1043
1044
|
intent: event.intent,
|
|
1044
1045
|
threadId: event.threadId,
|
|
1045
1046
|
...event.turnId ? { turnId: event.turnId } : {}
|
|
1046
1047
|
},
|
|
1047
|
-
title:
|
|
1048
|
+
title: event.threadTitle?.trim() || event.threadId,
|
|
1048
1049
|
to: expoPushToken
|
|
1049
1050
|
};
|
|
1050
1051
|
}
|
|
@@ -1573,7 +1574,7 @@ function shellEnvValue(value) {
|
|
|
1573
1574
|
//#endregion
|
|
1574
1575
|
//#region src/app.ts
|
|
1575
1576
|
const defaultWorkspacePath = process.cwd();
|
|
1576
|
-
const defaultCodexModel = "gpt-
|
|
1577
|
+
const defaultCodexModel = "gpt-6-astra";
|
|
1577
1578
|
const execFileAsync = promisify(execFile);
|
|
1578
1579
|
const IMAGE_ATTACHMENT_MAX_BYTES = 8 * 1024 * 1024;
|
|
1579
1580
|
const WORKSPACE_FILE_PREVIEW_MAX_BYTES = 256 * 1024;
|
|
@@ -1686,6 +1687,7 @@ function createApp(options = {}) {
|
|
|
1686
1687
|
return result;
|
|
1687
1688
|
}
|
|
1688
1689
|
const pushNotificationDispatcher = options.pairing ? createPushNotificationDispatcher({
|
|
1690
|
+
readRemainingUsagePercent: appServer ? async () => lowestRateLimitRemainingPercent(normalizeRateLimitBuckets(await appServer.readRateLimits())) : void 0,
|
|
1689
1691
|
sender: options.pushNotificationSender ?? createExpoPushNotificationSender(),
|
|
1690
1692
|
sessions: options.pairing.sessions
|
|
1691
1693
|
}) : void 0;
|
|
@@ -1922,6 +1924,7 @@ function createApp(options = {}) {
|
|
|
1922
1924
|
const response = PushNotificationSettingsResponseSchema.parse({
|
|
1923
1925
|
preferences: subscription ? {
|
|
1924
1926
|
actionRequired: subscription.actionRequired,
|
|
1927
|
+
includeRemainingUsage: subscription.includeRemainingUsage,
|
|
1925
1928
|
turnTerminal: subscription.turnTerminal
|
|
1926
1929
|
} : defaultPushNotificationPreferences(),
|
|
1927
1930
|
registered: Boolean(subscription)
|
|
@@ -1938,6 +1941,7 @@ function createApp(options = {}) {
|
|
|
1938
1941
|
actionRequired: parsed.data.preferences.actionRequired,
|
|
1939
1942
|
clientSessionId,
|
|
1940
1943
|
expoPushToken: parsed.data.expoPushToken,
|
|
1944
|
+
includeRemainingUsage: parsed.data.preferences.includeRemainingUsage,
|
|
1941
1945
|
platform: parsed.data.platform,
|
|
1942
1946
|
turnTerminal: parsed.data.preferences.turnTerminal
|
|
1943
1947
|
});
|
|
@@ -2171,7 +2175,11 @@ function createApp(options = {}) {
|
|
|
2171
2175
|
app.get(apiPaths.models, async (c) => {
|
|
2172
2176
|
try {
|
|
2173
2177
|
const models = appServer ? await appServer.listModels() : fallbackModels();
|
|
2174
|
-
|
|
2178
|
+
const hasAstra = models.some((model) => model.model === defaultCodexModel);
|
|
2179
|
+
return secureJson(c, options.pairing, secureSessionsByTokenHash, ListModelsResponseSchema.parse({ models: models.map((model) => mapAppServerModel(hasAstra ? {
|
|
2180
|
+
...model,
|
|
2181
|
+
isDefault: model.model === defaultCodexModel
|
|
2182
|
+
} : model)) }));
|
|
2175
2183
|
} catch {
|
|
2176
2184
|
return secureJson(c, options.pairing, secureSessionsByTokenHash, ListModelsResponseSchema.parse({ models: fallbackModels().map(mapAppServerModel) }));
|
|
2177
2185
|
}
|
|
@@ -2398,23 +2406,26 @@ function createApp(options = {}) {
|
|
|
2398
2406
|
const turns = threadBeforeRewind.turns ?? [];
|
|
2399
2407
|
const turnIndex = turns.findIndex((turn) => turn.id === parsed.data.turnId);
|
|
2400
2408
|
if (turnIndex < 0) return secureJson(c, options.pairing, secureSessionsByTokenHash, apiError("not_found", "The selected message is no longer available to rewind."), 404);
|
|
2401
|
-
|
|
2402
|
-
if (threadBeforeRewind.historyMode === "paginated" && typeof appServer.revertThread === "function") try {
|
|
2403
|
-
rolledBackThread = await appServer.revertThread({
|
|
2404
|
-
beforeTurnId: parsed.data.turnId,
|
|
2405
|
-
threadId
|
|
2406
|
-
});
|
|
2407
|
-
} catch (error) {
|
|
2408
|
-
if (!/method not found|unsupported|-32601/i.test(errorMessage(error))) throw error;
|
|
2409
|
-
rolledBackThread = await appServer.rollbackThread({
|
|
2410
|
-
threadId,
|
|
2411
|
-
numTurns: turns.length - turnIndex
|
|
2412
|
-
});
|
|
2413
|
-
}
|
|
2414
|
-
else rolledBackThread = await appServer.rollbackThread({
|
|
2409
|
+
const rollbackThread = () => appServer.rollbackThread({
|
|
2415
2410
|
threadId,
|
|
2416
2411
|
numTurns: turns.length - turnIndex
|
|
2417
2412
|
});
|
|
2413
|
+
let rolledBackThread;
|
|
2414
|
+
try {
|
|
2415
|
+
if (threadBeforeRewind.historyMode === "paginated" && typeof appServer.revertThread === "function") try {
|
|
2416
|
+
rolledBackThread = await appServer.revertThread({
|
|
2417
|
+
beforeTurnId: parsed.data.turnId,
|
|
2418
|
+
threadId
|
|
2419
|
+
});
|
|
2420
|
+
} catch (error) {
|
|
2421
|
+
if (!isMissingAppServerMethodError(error, "thread/revert")) throw error;
|
|
2422
|
+
rolledBackThread = await rollbackThread();
|
|
2423
|
+
}
|
|
2424
|
+
else rolledBackThread = await rollbackThread();
|
|
2425
|
+
} catch (error) {
|
|
2426
|
+
if (!isMissingAppServerMethodError(error, "thread/rollback")) throw error;
|
|
2427
|
+
return secureJson(c, options.pairing, secureSessionsByTokenHash, apiError("rewind_unsupported", "This chat uses Codex's legacy history format, which this Codex version can no longer rewind. Chats started after the update can be rewound."), 409);
|
|
2428
|
+
}
|
|
2418
2429
|
const threadWithTurns = rolledBackThread.turns === void 0 ? await appServer.readThread(threadId, { includeTurns: true }) : rolledBackThread;
|
|
2419
2430
|
const thread = rememberAppServerThread(threads, threadWithTurns, { authoritativeMessageCount: true });
|
|
2420
2431
|
const messages = mapAppServerMessages(threadWithTurns);
|
|
@@ -3078,6 +3089,7 @@ async function pairedClientSessionIdForAuthorization(authorization, pairing) {
|
|
|
3078
3089
|
function defaultPushNotificationPreferences() {
|
|
3079
3090
|
return {
|
|
3080
3091
|
actionRequired: false,
|
|
3092
|
+
includeRemainingUsage: false,
|
|
3081
3093
|
turnTerminal: false
|
|
3082
3094
|
};
|
|
3083
3095
|
}
|
|
@@ -4683,6 +4695,7 @@ function appServerUserMessageDetails(item) {
|
|
|
4683
4695
|
const attachments = item.content.flatMap((content) => {
|
|
4684
4696
|
switch (content.type) {
|
|
4685
4697
|
case "image":
|
|
4698
|
+
if (!content.url) return [];
|
|
4686
4699
|
if (content.url.startsWith("data:image/")) {
|
|
4687
4700
|
const materialized = materializeDataUriImage(content.url);
|
|
4688
4701
|
return materialized ? [materialized] : [];
|
|
@@ -5326,7 +5339,7 @@ function mapAppServerThread(thread, fallbackMessageCount) {
|
|
|
5326
5339
|
return ThreadSummarySchema.parse({
|
|
5327
5340
|
id: thread.id,
|
|
5328
5341
|
parentThreadId: thread.parentThreadId ?? void 0,
|
|
5329
|
-
title:
|
|
5342
|
+
title: appServerThreadTitle(thread),
|
|
5330
5343
|
createdAt,
|
|
5331
5344
|
updatedAt,
|
|
5332
5345
|
state: mappedState,
|
|
@@ -5337,6 +5350,9 @@ function mapAppServerThread(thread, fallbackMessageCount) {
|
|
|
5337
5350
|
lastActivityAt
|
|
5338
5351
|
});
|
|
5339
5352
|
}
|
|
5353
|
+
function appServerThreadTitle(thread) {
|
|
5354
|
+
return thread.name ?? preview(thread.preview || "Untitled thread");
|
|
5355
|
+
}
|
|
5340
5356
|
function rememberAppServerThread(threads, thread, options = {}) {
|
|
5341
5357
|
const existingThread = threads.get(thread.id);
|
|
5342
5358
|
const mappedThread = mapAppServerThread(thread, options.authoritativeMessageCount ? void 0 : existingThread?.messageCount);
|
|
@@ -6200,26 +6216,54 @@ function objectRecord(value) {
|
|
|
6200
6216
|
return value && typeof value === "object" ? value : void 0;
|
|
6201
6217
|
}
|
|
6202
6218
|
function fallbackModels() {
|
|
6203
|
-
|
|
6204
|
-
|
|
6205
|
-
|
|
6206
|
-
|
|
6207
|
-
|
|
6208
|
-
|
|
6219
|
+
const efforts = [
|
|
6220
|
+
"low",
|
|
6221
|
+
"medium",
|
|
6222
|
+
"high",
|
|
6223
|
+
"xhigh",
|
|
6224
|
+
"max"
|
|
6225
|
+
];
|
|
6226
|
+
return [
|
|
6227
|
+
fallbackModel({
|
|
6228
|
+
description: "Frontier intelligence for the most demanding work.",
|
|
6229
|
+
displayName: "GPT-6-Astra",
|
|
6230
|
+
efforts: [...efforts, "ultra"],
|
|
6231
|
+
fastDescription: "2x speed, increased usage",
|
|
6232
|
+
isDefault: true,
|
|
6233
|
+
model: defaultCodexModel
|
|
6234
|
+
}),
|
|
6235
|
+
fallbackModel({
|
|
6236
|
+
description: "Workhorse model for coding and everyday work.",
|
|
6237
|
+
displayName: "GPT-6-Sol",
|
|
6238
|
+
efforts: [...efforts, "ultra"],
|
|
6239
|
+
fastDescription: "1.5x speed",
|
|
6240
|
+
model: "gpt-6-sol"
|
|
6241
|
+
}),
|
|
6242
|
+
fallbackModel({
|
|
6243
|
+
description: "Fast and affordable model for easier tasks.",
|
|
6244
|
+
displayName: "GPT-6-Luna",
|
|
6245
|
+
efforts,
|
|
6246
|
+
fastDescription: "1.5x speed",
|
|
6247
|
+
model: "gpt-6-luna"
|
|
6248
|
+
})
|
|
6249
|
+
];
|
|
6250
|
+
}
|
|
6251
|
+
function fallbackModel({ description, displayName, efforts, fastDescription, isDefault = false, model }) {
|
|
6252
|
+
return {
|
|
6253
|
+
id: model,
|
|
6254
|
+
model,
|
|
6255
|
+
displayName,
|
|
6256
|
+
description,
|
|
6257
|
+
isDefault,
|
|
6209
6258
|
defaultReasoningEffort: "medium",
|
|
6210
|
-
supportedReasoningEfforts:
|
|
6211
|
-
{ reasoningEffort: "low" },
|
|
6212
|
-
{ reasoningEffort: "medium" },
|
|
6213
|
-
{ reasoningEffort: "high" },
|
|
6214
|
-
{ reasoningEffort: "xhigh" }
|
|
6215
|
-
],
|
|
6259
|
+
supportedReasoningEfforts: efforts.map((reasoningEffort) => ({ reasoningEffort })),
|
|
6216
6260
|
additionalSpeedTiers: ["fast"],
|
|
6217
6261
|
serviceTiers: [{
|
|
6218
6262
|
id: "priority",
|
|
6219
6263
|
name: "Fast",
|
|
6220
|
-
description:
|
|
6264
|
+
description: fastDescription
|
|
6221
6265
|
}]
|
|
6222
|
-
}
|
|
6266
|
+
};
|
|
6223
6267
|
}
|
|
6224
6268
|
function mapAppServerThreadState(status, turns) {
|
|
6225
6269
|
if (turns?.some(isAppServerTurnRunning)) return "running";
|
|
@@ -6415,7 +6459,10 @@ function observeAppServerPushNotifications(appServer, dispatcher) {
|
|
|
6415
6459
|
if (dispatchedEventIds.has(eventId)) return;
|
|
6416
6460
|
rememberEventId(eventId);
|
|
6417
6461
|
appServer.readThread(event.threadId, { includeTurns: false }).then((thread) => {
|
|
6418
|
-
if (!isSubagentThread(thread)) return dispatcher.dispatch(
|
|
6462
|
+
if (!isSubagentThread(thread)) return dispatcher.dispatch({
|
|
6463
|
+
...event,
|
|
6464
|
+
threadTitle: appServerThreadTitle(thread)
|
|
6465
|
+
});
|
|
6419
6466
|
}).catch((error) => {
|
|
6420
6467
|
relayDebugLog("push_notification.dispatch_failed", {
|
|
6421
6468
|
error: errorMessage(error),
|
|
@@ -7428,6 +7475,10 @@ function apiError(code, message, issues) {
|
|
|
7428
7475
|
function errorMessage(error) {
|
|
7429
7476
|
return error instanceof Error ? error.message : "Codex run failed.";
|
|
7430
7477
|
}
|
|
7478
|
+
function isMissingAppServerMethodError(error, method) {
|
|
7479
|
+
const message = errorMessage(error);
|
|
7480
|
+
return /method not found|-32601/i.test(message) || message.includes(`unknown variant \`${method}\``);
|
|
7481
|
+
}
|
|
7431
7482
|
//#endregion
|
|
7432
7483
|
//#region src/terminal-pairing.ts
|
|
7433
7484
|
function createTerminalPairingApprover(options) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codex-relay",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "Local Codex Relay CLI bridge for the Codex Relay mobile app.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"@noble/ciphers": "2.2.0",
|
|
42
42
|
"@noble/curves": "2.2.0",
|
|
43
43
|
"@noble/hashes": "2.2.0",
|
|
44
|
-
"@openai/codex": "0.
|
|
45
|
-
"@openai/codex-sdk": "0.
|
|
44
|
+
"@openai/codex": "0.156.1",
|
|
45
|
+
"@openai/codex-sdk": "0.156.1",
|
|
46
46
|
"base64-js": "1.5.1",
|
|
47
47
|
"commander": "^14.0.3",
|
|
48
48
|
"es-git": "^0.6.0",
|
package/src/api-schema.ts
CHANGED
|
@@ -99,6 +99,7 @@ export const PushNotificationIntentSchema = z.enum(["turn_terminal", "action_req
|
|
|
99
99
|
|
|
100
100
|
export const PushNotificationPreferencesSchema = z.object({
|
|
101
101
|
actionRequired: z.boolean(),
|
|
102
|
+
includeRemainingUsage: z.boolean().default(false),
|
|
102
103
|
turnTerminal: z.boolean(),
|
|
103
104
|
});
|
|
104
105
|
|
|
@@ -179,6 +180,19 @@ export const RateLimitsResponseSchema = z.object({
|
|
|
179
180
|
buckets: z.array(RateLimitBucketSchema),
|
|
180
181
|
});
|
|
181
182
|
|
|
183
|
+
export function rateLimitRemainingPercent(usedPercent: number) {
|
|
184
|
+
return 100 - Math.max(0, Math.min(100, usedPercent));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export function lowestRateLimitRemainingPercent(buckets: readonly RateLimitBucket[]) {
|
|
188
|
+
const remaining = buckets.flatMap((bucket) =>
|
|
189
|
+
[bucket.primary, bucket.secondary].flatMap((window) =>
|
|
190
|
+
window ? [rateLimitRemainingPercent(window.usedPercent)] : [],
|
|
191
|
+
),
|
|
192
|
+
);
|
|
193
|
+
return remaining.length > 0 ? Math.min(...remaining) : undefined;
|
|
194
|
+
}
|
|
195
|
+
|
|
182
196
|
export const ThreadContextWindowResponseSchema = z.object({
|
|
183
197
|
threadId: z.string().min(1),
|
|
184
198
|
usage: ContextWindowUsageSchema.nullable(),
|
|
@@ -1636,6 +1650,7 @@ export function createOpenApiDocument() {
|
|
|
1636
1650
|
required: ["actionRequired", "turnTerminal"],
|
|
1637
1651
|
properties: {
|
|
1638
1652
|
actionRequired: { type: "boolean" },
|
|
1653
|
+
includeRemainingUsage: { type: "boolean", default: false },
|
|
1639
1654
|
turnTerminal: { type: "boolean" },
|
|
1640
1655
|
},
|
|
1641
1656
|
},
|