nolo-cli 0.97.0-alpha.2 → 0.97.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/README.md +1 -1
- package/{_executeModel-G2MRKK2K.js → _executeModel-DYHTQJZC.js} +68 -63
- package/{action-YVYQEAAV.js → action-GI44T4DR.js} +10 -10
- package/{addContentAction-O7R66HEX.js → addContentAction-B2DRF7P6.js} +9 -9
- package/{addDialogAgentAction-74OA7KYP.js → addDialogAgentAction-T3I7IXPK.js} +15 -17
- package/{agentDeleteCommand-4427YKQF.js → agentDeleteCommand-LLNNP3AM.js} +47 -43
- package/{agentEmailCommands-RNBKKO7Q.js → agentEmailCommands-MQOP76DK.js} +90 -82
- package/agentListCommands-J3MWAZWO.js +741 -0
- package/{agentMachineCommands-FOFX5S2Q.js → agentMachineCommands-EQIRKAZO.js} +42 -38
- package/{agentProviderCommands-GNPTL5XR.js → agentProviderCommands-EMZCM6VA.js} +1 -1
- package/{agentPullCommand-O5MPVJ5E.js → agentPullCommand-HF4A42D4.js} +1 -1
- package/agentRecordCommands-7MQRBMWZ.js +136 -0
- package/{agentRunCommand-2W3Q3A7M.js → agentRunCommand-H6BYSTJ7.js} +90 -80
- package/{agentRunControl-WCTKX5VL.js → agentRunControl-2TTTUTSW.js} +2 -2
- package/{agentRuntimeLocal-IW3IM5P6.js → agentRuntimeLocal-AY6YNUAL.js} +44 -36
- package/{agentSlice-SK47GTN7.js → agentSlice-FOZUXW7X.js} +11 -11
- package/{appDeleteCommands-ZXLXNRHF.js → appDeleteCommands-QTTL3QF3.js} +42 -38
- package/{appDeployCommands-PWB4YERK.js → appDeployCommands-43LJECGV.js} +42 -38
- package/{appDeployStatusCommands-2EZKZP7Y.js → appDeployStatusCommands-L5BKOLYW.js} +42 -38
- package/{appGetCommands-JNUKOWHO.js → appGetCommands-HOFZKOPC.js} +42 -38
- package/{appListCommands-6X3H67SS.js → appListCommands-I7C3SJCE.js} +42 -38
- package/{authCommand-F4EFRRX6.js → authCommand-2YPMMIJN.js} +117 -23
- package/{authCommands-RGOGCPP6.js → authCommands-FFDS4FVX.js} +7 -5
- package/{builtinSkillRegistry-FUAVTRVZ.js → builtinSkillRegistry-CALVIJTX.js} +6 -5
- package/{chatQueueReduxAdapter-ZJ555AT2.js → chatQueueReduxAdapter-NMEZRYC2.js} +30 -29
- package/{chromeCommands-FZYAU75D.js → chromeCommands-K27J4OVZ.js} +124 -28
- package/{chromeOpsCommands-62P2Q2YB.js → chromeOpsCommands-IXRLN57H.js} +4 -3
- package/{chunk-6OZ36FXI.js → chunk-27ONFIEY.js} +22 -4
- package/{chunk-JEDZAO7L.js → chunk-2SYTUTLI.js} +257 -37
- package/{chunk-YQTQQX2H.js → chunk-2UV22D2F.js} +1 -1
- package/{chunk-7D6Z6AA4.js → chunk-3BFMH6GE.js} +6 -7
- package/{chunk-OIVSQH2O.js → chunk-3BXNTXYI.js} +299 -5
- package/{chunk-QIAVMDHY.js → chunk-3LX6YE3P.js} +4 -4
- package/{chunk-EYAQT56M.js → chunk-4DPP773Q.js} +2 -2
- package/chunk-4LCOCOR5.js +50 -0
- package/{chunk-2GRGFCF6.js → chunk-4VJAC32I.js} +2 -1
- package/{chunk-MC4XLIJ7.js → chunk-523DITKR.js} +1 -1
- package/{chunk-E4MARS3Q.js → chunk-5GVBDNTO.js} +1 -1
- package/chunk-5J3PYNUP.js +255 -0
- package/chunk-5MMAK75Q.js +15 -0
- package/{chunk-JPGCXHNM.js → chunk-5OA5HMTL.js} +1 -1
- package/{chunk-42V6BK2E.js → chunk-62IL3KQV.js} +4 -34
- package/{chunk-6YTOJY35.js → chunk-6D2JFXLY.js} +35 -0
- package/{chunk-3BMYXEUW.js → chunk-6O4IK4V2.js} +1 -1
- package/{chunk-IIVGDG4I.js → chunk-6PHKBY2Q.js} +10 -4
- package/{chunk-ASQYTZTR.js → chunk-6ZWMH6TJ.js} +69 -36
- package/{chunk-ABQYVJBJ.js → chunk-7CHC4W22.js} +1 -1
- package/{chunk-GQBOR3G6.js → chunk-7KVZ5LDQ.js} +2 -2
- package/{chunk-SDTTBMBU.js → chunk-7WCQEMPB.js} +888 -1079
- package/{chunk-BLJWCTRL.js → chunk-AOPCEXTB.js} +1 -1
- package/{chunk-WGR3J4Q6.js → chunk-APMUYAPK.js} +17 -4
- package/{chunk-Q554LLSI.js → chunk-AUDNYVRC.js} +1 -1
- package/{chunk-RG6JBBX5.js → chunk-AWF3WO5R.js} +166 -13
- package/{chunk-GPCZ7UXG.js → chunk-AZRHIN5B.js} +1 -1
- package/chunk-BMQ2MJUK.js +153 -0
- package/{chunk-B4ZH7KVO.js → chunk-C3VLSD4K.js} +236 -36
- package/{chunk-4EZHSKTB.js → chunk-C53ZG23R.js} +2 -2
- package/chunk-CHOZJMJS.js +78 -0
- package/{chunk-HJUYAD4A.js → chunk-CPUFH46E.js} +8 -8
- package/{chunk-LS2ZANRJ.js → chunk-CTUQJVQM.js} +1 -1
- package/{chunk-BP4XNZRM.js → chunk-CU3QB4HW.js} +3 -3
- package/{chunk-ACTMNVHM.js → chunk-CYSYR67N.js} +1 -1
- package/{chunk-KQ4ONNQD.js → chunk-DAWDCRIG.js} +82 -8
- package/{chunk-VLTIYV3X.js → chunk-DCLMZ5TX.js} +4 -4
- package/{chunk-UKZDAFYT.js → chunk-DSSTTEKI.js} +6 -10
- package/{chunk-L7I247DF.js → chunk-EKS2APRJ.js} +21 -5
- package/{chunk-HVURBGF3.js → chunk-ESRMFY7G.js} +2 -2
- package/{chunk-TRV2MIDW.js → chunk-EXAJ6DCR.js} +1 -0
- package/chunk-GMZLP5DV.js +82 -0
- package/{chunk-FDTR4QJ6.js → chunk-H6A6X4EK.js} +32 -1
- package/{chunk-DVINR3PL.js → chunk-HDLLCBRF.js} +1 -1
- package/{chunk-OIMN34NA.js → chunk-HKTIX4ZE.js} +23 -76
- package/{chunk-ONXOABJR.js → chunk-HNGRBWYF.js} +3 -0
- package/{chunk-H62HCIUP.js → chunk-HYZIYH2H.js} +11 -10
- package/{chunk-3VNWWVKB.js → chunk-I3QNET24.js} +30 -17
- package/{chunk-WV42OMV7.js → chunk-IAESIMK7.js} +4 -4
- package/chunk-JBOO3DKI.js +7808 -0
- package/{chunk-O35EJJVP.js → chunk-JJ7P5CIY.js} +56 -34
- package/{chunk-OZPMVBJI.js → chunk-JZ5II5UV.js} +15 -20
- package/{chunk-JRQFUXY7.js → chunk-KCDUTE5V.js} +96 -19
- package/{chunk-QLNJRTKI.js → chunk-KHVJXNRY.js} +100 -100
- package/{chunk-ADTY7BWR.js → chunk-L76GP4ER.js} +24 -5
- package/{chunk-7S4YWN7P.js → chunk-MX574M24.js} +1 -1
- package/{chunk-FZGV4FGK.js → chunk-NUHHBEJC.js} +378 -187
- package/{chunk-53HEEOTT.js → chunk-O26PCYLS.js} +80 -13
- package/{chunk-3DII57IT.js → chunk-O2OWEFII.js} +1 -1
- package/{chunk-TDRTS7QW.js → chunk-O6JPWEEK.js} +77 -17
- package/chunk-OCZKATRC.js +129 -0
- package/{chunk-6D6VBVEW.js → chunk-OTEMQQZI.js} +80 -14
- package/chunk-P6GMCCAT.js +870 -0
- package/{chunk-3SK4LEIH.js → chunk-PLRLUZWS.js} +853 -209
- package/{chunk-DHDMC6FO.js → chunk-QKUMVP3O.js} +11 -6
- package/{chunk-X4QAVDFE.js → chunk-RMAWULCS.js} +498 -480
- package/{chunk-V4MJDUSR.js → chunk-RSEEDUMS.js} +2 -2
- package/{chunk-UZGQNTVW.js → chunk-S5XGT6GB.js} +5 -3
- package/{chunk-76WEAXJB.js → chunk-SACTCJAC.js} +18 -15
- package/{chunk-AFUORTY4.js → chunk-SONWNI3L.js} +21 -21
- package/{chunk-BYMV6QZG.js → chunk-TNIX77YM.js} +4 -0
- package/{chunk-2YMRWISD.js → chunk-TU5NE4U3.js} +9 -84
- package/chunk-TY3TIUJK.js +89 -0
- package/chunk-UEGYKNHO.js +13349 -0
- package/chunk-UNYJU5L6.js +780 -0
- package/{chunk-J4MOO56S.js → chunk-UQNS32WZ.js} +10 -2
- package/chunk-VIWDGTDA.js +8 -0
- package/chunk-VJVNU77E.js +83 -0
- package/{chunk-EHKBVWKL.js → chunk-VYN7O3OY.js} +1 -1
- package/{chunk-NEDZDG3M.js → chunk-WILHZY7K.js} +45 -45
- package/{chunk-UKWGR5SS.js → chunk-WIWM4FE3.js} +187 -398
- package/{chunk-R7N5TMTV.js → chunk-X7YLNILS.js} +13 -13
- package/{chunk-O6OSWFZQ.js → chunk-XUWRURDF.js} +6 -0
- package/{chunk-Q67DOFOO.js → chunk-Y3PMXGLH.js} +2 -0
- package/{chunk-SNPMM7H3.js → chunk-Y6AZRODX.js} +13 -13
- package/{chunk-RSJECD7I.js → chunk-YJKDTJ2X.js} +7 -7
- package/{chunk-SH43IESU.js → chunk-YUNJN43V.js} +44 -9
- package/{chunk-TOP2VXOR.js → chunk-Z4CSIXYP.js} +2 -2
- package/{chunk-2F7RJC6L.js → chunk-ZOVKKMF6.js} +1 -1
- package/chunk-ZRAU6T47.js +56 -0
- package/{chunk-Z77CRGTW.js → chunk-ZYWQNCBN.js} +1 -1
- package/commandRegistry-HUFXCF7Z.js +833 -0
- package/{contentThunks-YLWTUILV.js → contentThunks-TD5YOAQM.js} +32 -30
- package/{cooldownCommands-REAWYVTY.js → cooldownCommands-ZLEPIB4A.js} +2 -2
- package/{createAgentAutomationAction-HFLPOBWQ.js → createAgentAutomationAction-XUG62ANM.js} +32 -30
- package/{createDialogAction-4H52MURR.js → createDialogAction-L3CMZKNL.js} +36 -33
- package/{createPageAction-5YDRMJOS.js → createPageAction-WJ3MX6JS.js} +38 -36
- package/{chunk-NUVMWYJM.js → cursorProvider-YGGNMVWX.js} +2494 -9892
- package/{dbSlice-XVWBAGYN.js → dbSlice-DQ32LYTJ.js} +8 -8
- package/{deleteFile-YG6QMJLU.js → deleteFile-NX6QHCWZ.js} +3 -3
- package/{dialogCommands-KFK2FF5B.js → dialogCommands-VM3I4HBW.js} +45 -41
- package/{dialogSlice-TMSHUGEM.js → dialogSlice-DSHG3YUE.js} +36 -29
- package/{dist-VODFSGNG.js → dist-NJC2W7I4.js} +61 -54
- package/{docCreateCommands-V777WOZ7.js → docCreateCommands-TYUJPCOP.js} +44 -40
- package/{docDeleteCommands-5KHT7Z5Q.js → docDeleteCommands-5XEG2LXO.js} +44 -40
- package/{docReadCommands-BLROGWP3.js → docReadCommands-M6RO6QHV.js} +43 -39
- package/{docStore-OBC5QOW7.js → docStore-RYOGMPEF.js} +11 -10
- package/{docUpdateCommands-QXOZHQ5H.js → docUpdateCommands-DKOFTZRX.js} +44 -40
- package/{fetchMessages-EIU7UFFK.js → fetchMessages-67MEFPZR.js} +2 -2
- package/{getPricing-LUSEABA6.js → getPricing-NMMFT3YI.js} +3 -3
- package/{handleSendMessageAction-4LGNXH6T.js → handleSendMessageAction-XH742B27.js} +91 -83
- package/index.js +87 -884
- package/{localDialogRead-BTFJ4V2I.js → localDialogRead-EBRS242U.js} +2 -2
- package/{localRuntimeAuthority-6IR6BBXE.js → localRuntimeAuthority-5W6IJRAD.js} +6 -6
- package/{localRuntimeDb-SYQGUF4U.js → localRuntimeDb-3LRMNLCM.js} +1 -1
- package/{machineCommands-SNLCRHQK.js → machineCommands-EY3SKJCP.js} +85 -77
- package/{machineWsRunDispatch-ZGZVDQSO.js → machineWsRunDispatch-OJ77YNRD.js} +82 -74
- package/{memberThunks-QGFLFVCI.js → memberThunks-5ZXPR63F.js} +9 -9
- package/{models-T3SG6MJ5.js → models-ZPU5EDF4.js} +2 -2
- package/oauthTokenStore-ITEB663N.js +23 -0
- package/package.json +1 -1
- package/pdf-U6KSUEZZ.js +26435 -0
- package/processSpawn-SOAV3FEV.js +11 -0
- package/profileConfig-ZGOFORWV.js +43 -0
- package/{providerPresetApply-FG6NZ57W.js → providerPresetApply-76AVU3HD.js} +7 -7
- package/{providerRegistry-757OWH3O.js → providerRegistry-Z62NC45X.js} +11 -7
- package/{read-COE3ZYR6.js → read-EPTJRAEF.js} +5 -5
- package/{readDocTool-5USN4A6V.js → readDocTool-W4NDXNEX.js} +5 -3
- package/{readlineWorkspace-OUL7ZN7D.js → readlineWorkspace-PMTHAVMB.js} +2447 -2022
- package/{removeDialogAgentAction-IX3MN2ZO.js → removeDialogAgentAction-BVAWQKXE.js} +17 -19
- package/{runAgentClientLoop-GD3APV7V.js → runAgentClientLoop-7WXN6I7L.js} +62 -58
- package/{runtimeDoctorCommands-X6WDBEQX.js → runtimeDoctorCommands-3USD722U.js} +3 -3
- package/runtimeModeArgs-2Y7BALTO.js +31 -0
- package/{setDialogExtraReferencesAction-X4HCPNZL.js → setDialogExtraReferencesAction-LYY45IAD.js} +12 -11
- package/{setPrimaryDialogAgentAction-4GMIQLOD.js → setPrimaryDialogAgentAction-73IL7DLU.js} +18 -20
- package/{settingSlice-ZQZVUPKK.js → settingSlice-Q6EKL7EQ.js} +9 -9
- package/{skillDiscovery-CYUCJMAG.js → skillDiscovery-ZBU76COE.js} +3 -3
- package/{spaceCommands-TIDVUPDV.js → spaceCommands-QFP4ZXKG.js} +44 -40
- package/{streamAgentChatTurn-M73KWCCU.js → streamAgentChatTurn-B4PXPJJS.js} +184 -91
- package/{switchDialogAgentAction-N52LRPA3.js → switchDialogAgentAction-UUXDSQ6X.js} +15 -17
- package/{tableCommands-O6NWHFKV.js → tableCommands-G7RV3RU3.js} +4 -4
- package/{toolApiClient-QVJ6HDNN.js → toolApiClient-INIQCPGY.js} +3 -3
- package/{tools-DXXDQ2CP.js → tools-QFS2L7BU.js} +55 -51
- package/{tuiSummaryLlmCaller-VJY3YD2Q.js → tuiSummaryLlmCaller-74NRRLVW.js} +18 -16
- package/{updateCommands-2M74UL7P.js → updateCommands-4EHDLF5J.js} +3 -3
- package/{updateDialogTitleAction-XI73NQMU.js → updateDialogTitleAction-HTDYCNNZ.js} +81 -43
- package/agentListCommands-O4AEMQVV.js +0 -406
- package/agentRecordCommands-6QK7AMXQ.js +0 -128
- package/chunk-M76ECQRD.js +0 -13658
- package/chunk-Q5FJJ6XI.js +0 -103
- package/chunk-S7Z2HMCN.js +0 -25
- package/chunk-WRFW73PB.js +0 -18881
- package/{chunk-VMFTFOWF.js → chunk-3AH7LNUB.js} +7 -7
- package/{chunk-X7HHHIOZ.js → chunk-Y6ROFCZO.js} +0 -0
- package/{db-WK5MDZVN.js → db-VQSAOWAO.js} +1 -1
|
@@ -11,13 +11,13 @@ import {
|
|
|
11
11
|
getAntigravityUserAgent,
|
|
12
12
|
normalizeAntigravityTokenPayload,
|
|
13
13
|
refreshAntigravityToken
|
|
14
|
-
} from "./chunk-
|
|
15
|
-
import {
|
|
16
|
-
writeOAuthCredential
|
|
17
|
-
} from "./chunk-ONXOABJR.js";
|
|
14
|
+
} from "./chunk-S5XGT6GB.js";
|
|
18
15
|
import {
|
|
19
16
|
toErrorMessage
|
|
20
17
|
} from "./chunk-HNMXYYJR.js";
|
|
18
|
+
import {
|
|
19
|
+
writeOAuthCredential
|
|
20
|
+
} from "./chunk-HNGRBWYF.js";
|
|
21
21
|
import {
|
|
22
22
|
asOptionalFiniteNumber
|
|
23
23
|
} from "./chunk-WWC7I6TA.js";
|
|
@@ -367,6 +367,77 @@ async function refreshAntigravityOAuthToken(credential, deps = {}) {
|
|
|
367
367
|
// packages/cli/oauth/flows/openai-codex.ts
|
|
368
368
|
import { createHash as createHash2 } from "node:crypto";
|
|
369
369
|
|
|
370
|
+
// packages/agent-runtime/oauthRefreshError.ts
|
|
371
|
+
var PERMANENT_REFRESH_CODES = /* @__PURE__ */ new Set([
|
|
372
|
+
"invalid_grant",
|
|
373
|
+
// OpenAI 令牌端点对失效/不存在的 refresh token 返回 401
|
|
374
|
+
// {"error":{"code":"invalid_refresh_token",...}}(2026-10-01 用必然无效的
|
|
375
|
+
// token 实测)。线上 chatgpt 凭据正是因为没认出它,被当成临时的
|
|
376
|
+
// "unauthorized"、每 15 分钟重试一次且永远不提示重新授权。
|
|
377
|
+
"invalid_refresh_token",
|
|
378
|
+
"refresh_token_reused",
|
|
379
|
+
"invalid_client"
|
|
380
|
+
]);
|
|
381
|
+
var SAFE_MESSAGES = {
|
|
382
|
+
invalid_grant: "refresh token \u5DF2\u5931\u6548\uFF0C\u8BF7\u91CD\u65B0\u6388\u6743",
|
|
383
|
+
invalid_refresh_token: "refresh token \u5DF2\u5931\u6548\uFF0C\u8BF7\u91CD\u65B0\u6388\u6743",
|
|
384
|
+
refresh_token_reused: "refresh token \u5DF2\u88AB\u5176\u4ED6\u526F\u672C\u4F7F\u7528\uFF0C\u8BF7\u91CD\u65B0\u6388\u6743",
|
|
385
|
+
invalid_client: "OAuth \u5BA2\u6237\u7AEF\u88AB\u62D2\u7EDD\uFF0C\u8BF7\u91CD\u65B0\u6388\u6743",
|
|
386
|
+
unauthorized: "\u4E0A\u6E38\u62D2\u7EDD\u4E86\u5237\u65B0\u8BF7\u6C42\uFF08401/403\uFF09",
|
|
387
|
+
rate_limited: "\u4E0A\u6E38\u9650\u6D41\uFF0C\u7A0D\u540E\u91CD\u8BD5",
|
|
388
|
+
http_5xx: "\u4E0A\u6E38\u670D\u52A1\u6682\u65F6\u4E0D\u53EF\u7528",
|
|
389
|
+
network: "\u65E0\u6CD5\u8FDE\u63A5\u4E0A\u6E38",
|
|
390
|
+
bad_response: "\u4E0A\u6E38\u8FD4\u56DE\u4E86\u65E0\u6CD5\u8BC6\u522B\u7684\u54CD\u5E94",
|
|
391
|
+
unknown: "\u5237\u65B0\u5931\u8D25"
|
|
392
|
+
};
|
|
393
|
+
var OAuthRefreshError = class extends Error {
|
|
394
|
+
code;
|
|
395
|
+
status;
|
|
396
|
+
retryAfterMs;
|
|
397
|
+
constructor(code, opts = {}) {
|
|
398
|
+
super(SAFE_MESSAGES[code]);
|
|
399
|
+
this.name = "OAuthRefreshError";
|
|
400
|
+
this.code = code;
|
|
401
|
+
if (opts.status !== void 0) this.status = opts.status;
|
|
402
|
+
if (opts.retryAfterMs !== void 0) this.retryAfterMs = opts.retryAfterMs;
|
|
403
|
+
}
|
|
404
|
+
get permanent() {
|
|
405
|
+
return PERMANENT_REFRESH_CODES.has(this.code);
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
function readErrorCode(payload) {
|
|
409
|
+
if (!payload || typeof payload !== "object") return void 0;
|
|
410
|
+
const err = payload.error;
|
|
411
|
+
if (typeof err === "string") return err;
|
|
412
|
+
if (err && typeof err === "object") {
|
|
413
|
+
const code = err.code;
|
|
414
|
+
if (typeof code === "string") return code;
|
|
415
|
+
}
|
|
416
|
+
return void 0;
|
|
417
|
+
}
|
|
418
|
+
function classifyOAuthRefreshHttpFailure(status, payload, headers) {
|
|
419
|
+
const raw = readErrorCode(payload)?.toLowerCase();
|
|
420
|
+
if (raw === "invalid_grant") return new OAuthRefreshError("invalid_grant", { status });
|
|
421
|
+
if (raw === "invalid_refresh_token") {
|
|
422
|
+
return new OAuthRefreshError("invalid_refresh_token", { status });
|
|
423
|
+
}
|
|
424
|
+
if (raw === "refresh_token_reused") {
|
|
425
|
+
return new OAuthRefreshError("refresh_token_reused", { status });
|
|
426
|
+
}
|
|
427
|
+
if (raw === "invalid_client") return new OAuthRefreshError("invalid_client", { status });
|
|
428
|
+
if (status === 429) {
|
|
429
|
+
const seconds = Number(headers?.get("retry-after"));
|
|
430
|
+
return new OAuthRefreshError("rate_limited", {
|
|
431
|
+
status,
|
|
432
|
+
...Number.isFinite(seconds) && seconds > 0 ? { retryAfterMs: seconds * 1e3 } : {}
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
if (status === 401 || status === 403) return new OAuthRefreshError("unauthorized", { status });
|
|
436
|
+
if (status >= 500) return new OAuthRefreshError("http_5xx", { status });
|
|
437
|
+
return new OAuthRefreshError("unknown", { status });
|
|
438
|
+
}
|
|
439
|
+
var TRANSIENT_MAX_MS = 15 * 6e4;
|
|
440
|
+
|
|
370
441
|
// packages/agent-runtime/openaiCodexOAuth.ts
|
|
371
442
|
var OPENAI_CODEX_CLIENT_ID = "app_EMoamEEZ73f0CkXaXp7hrann";
|
|
372
443
|
var OPENAI_CODEX_SCOPES = [
|
|
@@ -463,17 +534,14 @@ async function refreshOpenAiCodexToken(credential, deps = {}) {
|
|
|
463
534
|
signal: AbortSignal.timeout(OPENAI_CODEX_TOKEN_REQUEST_TIMEOUT_MS)
|
|
464
535
|
});
|
|
465
536
|
} catch (error) {
|
|
466
|
-
throw new
|
|
467
|
-
`OpenAI Codex token refresh failed: ${toErrorMessage(error)}`
|
|
468
|
-
);
|
|
537
|
+
throw new OAuthRefreshError("network");
|
|
469
538
|
}
|
|
470
539
|
const payload = await response.json().catch(() => ({}));
|
|
471
540
|
if (!response.ok) {
|
|
472
|
-
|
|
473
|
-
throw new Error(`OpenAI Codex token refresh failed: ${detail}`);
|
|
541
|
+
throw classifyOAuthRefreshHttpFailure(response.status, payload, response.headers);
|
|
474
542
|
}
|
|
475
543
|
if (typeof payload.access_token !== "string" || !payload.access_token.trim()) {
|
|
476
|
-
throw new
|
|
544
|
+
throw new OAuthRefreshError("bad_response");
|
|
477
545
|
}
|
|
478
546
|
const now = deps.now?.() ?? Date.now();
|
|
479
547
|
return normalizeOpenAiCodexTokenPayload({
|
|
@@ -1047,11 +1115,10 @@ async function refreshAnthropicToken(credential, deps = {}) {
|
|
|
1047
1115
|
});
|
|
1048
1116
|
const payload = await response.json().catch(() => ({}));
|
|
1049
1117
|
if (!response.ok) {
|
|
1050
|
-
|
|
1051
|
-
throw new Error(`Claude token refresh failed: ${detail}`);
|
|
1118
|
+
throw classifyOAuthRefreshHttpFailure(response.status, payload, response.headers);
|
|
1052
1119
|
}
|
|
1053
1120
|
if (typeof payload.access_token !== "string" || !payload.access_token.trim()) {
|
|
1054
|
-
throw new
|
|
1121
|
+
throw new OAuthRefreshError("bad_response");
|
|
1055
1122
|
}
|
|
1056
1123
|
const now = deps.now?.() ?? Date.now();
|
|
1057
1124
|
return normalizeAnthropicTokenPayload({
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
listUserRecordsFromServers,
|
|
3
3
|
readLiveDbRecordAfterTombstoneMerge
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-AOPCEXTB.js";
|
|
5
5
|
import {
|
|
6
6
|
agentRecordHasConfiguredCredential
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-SACTCJAC.js";
|
|
8
8
|
import {
|
|
9
|
-
deriveCredentialGroup
|
|
10
|
-
|
|
11
|
-
} from "./chunk-RG6JBBX5.js";
|
|
9
|
+
deriveCredentialGroup
|
|
10
|
+
} from "./chunk-AWF3WO5R.js";
|
|
12
11
|
import {
|
|
13
12
|
PUBLIC_AGENT_KEY_PREFIX,
|
|
14
|
-
isOwnedAgentKey,
|
|
15
13
|
ownedAgentKey,
|
|
16
14
|
ownedAgentKeyPrefix,
|
|
17
15
|
parseOwnedAgentId,
|
|
@@ -53,6 +51,9 @@ function normalizeListedAgent(record) {
|
|
|
53
51
|
...typeof record?.handle === "string" && record.handle ? { handle: record.handle } : {},
|
|
54
52
|
...typeof record?.introduction === "string" && record.introduction ? { introduction: record.introduction } : typeof record?.description === "string" && record.description ? { introduction: record.description } : {},
|
|
55
53
|
...typeof record?.provider === "string" && record.provider ? { provider: record.provider } : {},
|
|
54
|
+
// 仅供 resolveBillingSource 判定订阅端点(Step Plan / OpenCode Go 等),
|
|
55
|
+
// safe 投影不输出它。缺了它本地 agent list 会把订阅端点全报成 user_api。
|
|
56
|
+
...typeof record?.customProviderUrl === "string" && record.customProviderUrl ? { customProviderUrl: record.customProviderUrl } : {},
|
|
56
57
|
...typeof record?.inputPrice === "number" && Number.isFinite(record.inputPrice) ? { inputPrice: record.inputPrice } : {},
|
|
57
58
|
...typeof record?.outputPrice === "number" && Number.isFinite(record.outputPrice) ? { outputPrice: record.outputPrice } : {},
|
|
58
59
|
updatedAt: typeof record?.updatedAt === "string" || typeof record?.updatedAt === "number" ? record.updatedAt : typeof record?.createdAt === "string" || typeof record?.createdAt === "number" ? record.createdAt : typeof record?.created === "string" || typeof record?.created === "number" ? record.created : null,
|
|
@@ -67,16 +68,10 @@ function normalizeListedAgent(record) {
|
|
|
67
68
|
...credentialKind !== void 0 ? { credentialKind } : {},
|
|
68
69
|
...typeof record?.apiSource === "string" && record.apiSource ? { apiSource: record.apiSource } : {},
|
|
69
70
|
...typeof record?.cliProvider === "string" && record.cliProvider ? { cliProvider: record.cliProvider } : {},
|
|
70
|
-
...typeof record?.nextAvailableAt === "number" && Number.isFinite(record.nextAvailableAt) ? { nextAvailableAt: record.nextAvailableAt } : {}
|
|
71
|
+
...typeof record?.nextAvailableAt === "number" && Number.isFinite(record.nextAvailableAt) ? { nextAvailableAt: record.nextAvailableAt } : {},
|
|
72
|
+
...record?.quota && typeof record.quota === "object" && Array.isArray(record.quota.windows) ? { quota: record.quota } : {}
|
|
71
73
|
};
|
|
72
74
|
}
|
|
73
|
-
function toSafeListedAgentSummary(agent, options) {
|
|
74
|
-
const summary = toSafeAgentSummary(agent, options);
|
|
75
|
-
if (agent.publicRecordExists === false) {
|
|
76
|
-
delete summary.publicKey;
|
|
77
|
-
}
|
|
78
|
-
return summary;
|
|
79
|
-
}
|
|
80
75
|
function sortListedAgents(agents) {
|
|
81
76
|
agents.sort((a, b) => {
|
|
82
77
|
const ta = a.updatedAt == null ? 0 : new Date(a.updatedAt).getTime();
|
|
@@ -97,6 +92,7 @@ function parseAgentListArgs(args) {
|
|
|
97
92
|
publicOnly: args.includes("--public-only"),
|
|
98
93
|
idsOnly: args.includes("--ids-only"),
|
|
99
94
|
scope: readArgValue(args, "--scope"),
|
|
95
|
+
query: readArgValue(args, "--query"),
|
|
100
96
|
showUnavailable: args.includes("--show-unavailable"),
|
|
101
97
|
// --safe 默认输出精简投影(与 server listAgents 一致,防大列表被截断);
|
|
102
98
|
// --verbose 拿回完整字段集排障。
|
|
@@ -110,7 +106,7 @@ async function listLocalCachedAgents(args) {
|
|
|
110
106
|
for (const prefix of [ownedPrefix, PUBLIC_AGENT_KEY_PREFIX]) {
|
|
111
107
|
for await (const [key, value] of args.db.iterator({ gte: prefix, lte: `${prefix}\uFFFF` })) {
|
|
112
108
|
if (typeof key !== "string" || !value || typeof value !== "object") continue;
|
|
113
|
-
if (
|
|
109
|
+
if (key.startsWith(ownedPrefix)) {
|
|
114
110
|
privateRecords.set(key, { ...value, dbKey: key });
|
|
115
111
|
continue;
|
|
116
112
|
}
|
|
@@ -237,14 +233,78 @@ async function decorateAgentsWithPublicStatusAcrossServers(args) {
|
|
|
237
233
|
return args.agents;
|
|
238
234
|
}
|
|
239
235
|
|
|
236
|
+
// packages/ai/agent/quotaSnapshot.ts
|
|
237
|
+
function findTightestQuotaWindow(quota, now = Date.now()) {
|
|
238
|
+
if (!quota || !Array.isArray(quota.windows) || quota.windows.length === 0) {
|
|
239
|
+
return void 0;
|
|
240
|
+
}
|
|
241
|
+
let best;
|
|
242
|
+
let bestScore = -Infinity;
|
|
243
|
+
for (const w of quota.windows) {
|
|
244
|
+
let score = 0;
|
|
245
|
+
if (typeof w.utilization === "number" && w.utilization >= 0) {
|
|
246
|
+
score = 500 + Math.min(w.utilization, 1) * 500;
|
|
247
|
+
} else if (typeof w.remaining === "number" && typeof w.limit === "number" && w.limit > 0) {
|
|
248
|
+
const util = Math.max(0, 1 - w.remaining / w.limit);
|
|
249
|
+
score = 500 + util * 500;
|
|
250
|
+
} else if (typeof w.resetAt === "number" && w.resetAt > now) {
|
|
251
|
+
score = 200;
|
|
252
|
+
} else if (typeof w.remaining === "number") {
|
|
253
|
+
score = 100;
|
|
254
|
+
}
|
|
255
|
+
if (score > bestScore) {
|
|
256
|
+
bestScore = score;
|
|
257
|
+
best = w;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return best ?? quota.windows[0];
|
|
261
|
+
}
|
|
262
|
+
function formatQuotaSummary(quota, now = Date.now(), options) {
|
|
263
|
+
const tightest = findTightestQuotaWindow(quota, now);
|
|
264
|
+
if (!tightest) return void 0;
|
|
265
|
+
const compact = options?.compact === true;
|
|
266
|
+
const parts = [];
|
|
267
|
+
if (typeof tightest.utilization === "number") {
|
|
268
|
+
const pct = Math.round(tightest.utilization * 100);
|
|
269
|
+
parts.push(`${pct}%\u5DF2\u7528`);
|
|
270
|
+
} else if (typeof tightest.remaining === "number") {
|
|
271
|
+
if (typeof tightest.limit === "number") {
|
|
272
|
+
parts.push(`${tightest.remaining}/${tightest.limit}${tightest.unit ? ` ${tightest.unit}` : ""}`);
|
|
273
|
+
} else {
|
|
274
|
+
parts.push(`\u4F59${tightest.remaining}${tightest.unit ? ` ${tightest.unit}` : ""}`);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
if (compact) return parts.length > 0 ? parts[0] : void 0;
|
|
278
|
+
if (tightest.scope && tightest.scope !== "user" && tightest.scope !== "project" && tightest.scope !== tightest.unit) {
|
|
279
|
+
parts.push(tightest.scope);
|
|
280
|
+
}
|
|
281
|
+
if (typeof tightest.resetAt === "number" && tightest.resetAt > now) {
|
|
282
|
+
const diffSec = Math.round((tightest.resetAt - now) / 1e3);
|
|
283
|
+
if (diffSec < 60) {
|
|
284
|
+
parts.push(`${diffSec}s\u540E\u91CD\u7F6E`);
|
|
285
|
+
} else if (diffSec < 3600) {
|
|
286
|
+
parts.push(`${Math.round(diffSec / 60)}m\u540E\u91CD\u7F6E`);
|
|
287
|
+
} else if (diffSec < 86400) {
|
|
288
|
+
const hours = (diffSec / 3600).toFixed(1).replace(/\.0$/, "");
|
|
289
|
+
parts.push(`${hours}h\u540E\u91CD\u7F6E`);
|
|
290
|
+
} else {
|
|
291
|
+
const days = (diffSec / 86400).toFixed(1).replace(/\.0$/, "");
|
|
292
|
+
parts.push(`${days}d\u540E\u91CD\u7F6E`);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
if (parts.length === 0) return void 0;
|
|
296
|
+
if (parts.length === 1 && parts[0] === tightest.scope) return void 0;
|
|
297
|
+
return parts.join(" \xB7 ");
|
|
298
|
+
}
|
|
299
|
+
|
|
240
300
|
export {
|
|
241
301
|
normalizeListedAgent,
|
|
242
|
-
toSafeListedAgentSummary,
|
|
243
302
|
parseAgentListArgs,
|
|
244
303
|
listLocalCachedAgents,
|
|
245
304
|
listRemotePublicAgents,
|
|
246
305
|
listRemoteAgents,
|
|
247
306
|
listRemoteAgentsAcrossServers,
|
|
248
307
|
listFavoriteAgentIdsAcrossServers,
|
|
249
|
-
decorateAgentsWithPublicStatusAcrossServers
|
|
308
|
+
decorateAgentsWithPublicStatusAcrossServers,
|
|
309
|
+
formatQuotaSummary
|
|
250
310
|
};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// packages/ai/chat/parseApiError.ts
|
|
2
|
+
var CONTEXT_OVERFLOW_ACTIONS = [
|
|
3
|
+
"compact-and-retry",
|
|
4
|
+
"new-dialog",
|
|
5
|
+
"switch-model",
|
|
6
|
+
"retry"
|
|
7
|
+
];
|
|
8
|
+
var CONTEXT_TOO_LARGE_ACTIONS = [
|
|
9
|
+
"new-dialog",
|
|
10
|
+
"switch-model",
|
|
11
|
+
"retry"
|
|
12
|
+
];
|
|
13
|
+
var truncateErrorMessage = (message, maxChars = 320) => message.length <= maxChars ? message : `${message.slice(0, maxChars)}\u2026`;
|
|
14
|
+
var isContextOverflowText = (message) => /maximum context|context (length|window|overflow|limit)|context_length_exceed\w*|requested about .*tokens|too many tokens|prompt is too long|exceeds? (the )?(model|max)/i.test(
|
|
15
|
+
message
|
|
16
|
+
);
|
|
17
|
+
function classifyApiError(input) {
|
|
18
|
+
const { status, message, body, code } = input;
|
|
19
|
+
const errorMessage = message;
|
|
20
|
+
let defaultMessage = `\u72B6\u6001\u7801 ${status} ${input.statusText ?? ""}`;
|
|
21
|
+
switch (status) {
|
|
22
|
+
case 400:
|
|
23
|
+
if (isContextOverflowText(errorMessage) || isContextOverflowText(body) || code === "UPSTREAM_400") {
|
|
24
|
+
return {
|
|
25
|
+
kind: "context_overflow",
|
|
26
|
+
message: "\u4E0A\u4E0B\u6587\u8FC7\u957F\uFF1A\u672C\u8F6E\u6D88\u606F\u6216\u5DE5\u5177\u7ED3\u679C\u592A\u5927\u3002\u8BF7\u7F29\u5C0F\u8303\u56F4\uFF0C\u6216\u5148\u8BFB\u53D6\u66F4\u5C0F\u7247\u6BB5\u540E\u518D\u7EE7\u7EED\u3002",
|
|
27
|
+
code,
|
|
28
|
+
status,
|
|
29
|
+
retryable: true,
|
|
30
|
+
actions: [...CONTEXT_OVERFLOW_ACTIONS]
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
if (code === "MISSING_PROVIDER_API_KEY") {
|
|
34
|
+
return {
|
|
35
|
+
kind: "generic",
|
|
36
|
+
message: truncateErrorMessage(errorMessage),
|
|
37
|
+
code,
|
|
38
|
+
status,
|
|
39
|
+
retryable: false
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
if (errorMessage && errorMessage !== defaultMessage) {
|
|
43
|
+
return {
|
|
44
|
+
kind: "generic",
|
|
45
|
+
message: `\u8BF7\u6C42\u53C2\u6570\u9519\u8BEF: ${truncateErrorMessage(errorMessage)}`,
|
|
46
|
+
code,
|
|
47
|
+
status,
|
|
48
|
+
retryable: false
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
return { kind: "generic", message: "\u8BF7\u6C42\u53C2\u6570\u9519\u8BEF\uFF0C\u8BF7\u68C0\u67E5\u8F93\u5165", code, status, retryable: false };
|
|
52
|
+
case 413:
|
|
53
|
+
return {
|
|
54
|
+
kind: "context_too_large",
|
|
55
|
+
message: "\u8BF7\u6C42\u5185\u5BB9\u8FC7\u5927\uFF1A\u8BF7\u51CF\u5C11\u4E00\u6B21\u53D1\u9001\u7684\u6D88\u606F\u3001\u6587\u4EF6\u6216\u5DE5\u5177\u7ED3\u679C\u3002",
|
|
56
|
+
code,
|
|
57
|
+
status,
|
|
58
|
+
retryable: true,
|
|
59
|
+
actions: [...CONTEXT_TOO_LARGE_ACTIONS]
|
|
60
|
+
};
|
|
61
|
+
case 401:
|
|
62
|
+
return {
|
|
63
|
+
kind: "auth",
|
|
64
|
+
message: code === "AUTH_TOKEN_EXPIRED" ? "\u767B\u5F55\u72B6\u6001\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u5148\u767B\u51FA\u540E\u91CD\u65B0\u767B\u5F55" : code === "AUTH_ACCOUNT_INVALID" ? "\u8D26\u6237\u65E0\u6548\u6216\u5DF2\u88AB\u505C\u7528\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458" : code === "AUTH_NO_TOKEN" ? "\u672A\u68C0\u6D4B\u5230\u767B\u5F55\u72B6\u6001\uFF0C\u8BF7\u5148\u767B\u5F55" : code === "AUTH_INVALID_TOKEN" ? "\u767B\u5F55\u51ED\u8BC1\u65E0\u6548\uFF0C\u8BF7\u5148\u767B\u51FA\u540E\u91CD\u65B0\u767B\u5F55" : code === "AUTH_TOKEN_NOT_ACTIVE" ? "\u4EE4\u724C\u5C1A\u672A\u751F\u6548\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5" : errorMessage && errorMessage !== `\u72B6\u6001\u7801 401 Unauthorized` ? `\u8BA4\u8BC1\u9519\u8BEF: ${truncateErrorMessage(errorMessage)}` : "\u8EAB\u4EFD\u9A8C\u8BC1\u5931\u8D25\uFF0C\u8BF7\u5148\u767B\u51FA\u540E\u91CD\u65B0\u767B\u5F55",
|
|
65
|
+
code,
|
|
66
|
+
status,
|
|
67
|
+
retryable: true,
|
|
68
|
+
actions: ["retry"]
|
|
69
|
+
};
|
|
70
|
+
case 503:
|
|
71
|
+
return {
|
|
72
|
+
kind: "server",
|
|
73
|
+
message: errorMessage && errorMessage !== `\u72B6\u6001\u7801 503 Service Unavailable` ? truncateErrorMessage(errorMessage) : "\u670D\u52A1\u6682\u65F6\u4E0D\u53EF\u7528\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5",
|
|
74
|
+
code,
|
|
75
|
+
status,
|
|
76
|
+
retryable: true,
|
|
77
|
+
actions: ["retry"]
|
|
78
|
+
};
|
|
79
|
+
case 504:
|
|
80
|
+
return {
|
|
81
|
+
kind: "timeout",
|
|
82
|
+
message: "\u8BF7\u6C42\u8D85\u65F6\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5",
|
|
83
|
+
code,
|
|
84
|
+
status,
|
|
85
|
+
retryable: true,
|
|
86
|
+
actions: ["retry"]
|
|
87
|
+
};
|
|
88
|
+
default:
|
|
89
|
+
return {
|
|
90
|
+
kind: "generic",
|
|
91
|
+
message: `API\u8BF7\u6C42\u5931\u8D25: ${truncateErrorMessage(errorMessage)}`,
|
|
92
|
+
code,
|
|
93
|
+
status,
|
|
94
|
+
retryable: true,
|
|
95
|
+
actions: ["retry"]
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async function parseApiErrorInfo(response) {
|
|
100
|
+
const errorBody = await response.text();
|
|
101
|
+
let errorMessage = `\u72B6\u6001\u7801 ${response.status} ${response.statusText}`;
|
|
102
|
+
let errorCode = `E${response.status}`;
|
|
103
|
+
try {
|
|
104
|
+
const errorJson = JSON.parse(errorBody);
|
|
105
|
+
errorMessage = errorJson?.error?.message || errorJson?.message || errorJson?.msg || errorBody || errorMessage;
|
|
106
|
+
errorCode = errorJson?.error?.code || errorJson?.code || errorCode;
|
|
107
|
+
} catch (_e) {
|
|
108
|
+
if (errorBody) {
|
|
109
|
+
errorMessage = errorBody;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return classifyApiError({
|
|
113
|
+
status: response.status,
|
|
114
|
+
statusText: response.statusText,
|
|
115
|
+
message: errorMessage,
|
|
116
|
+
body: errorBody,
|
|
117
|
+
code: errorCode
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
async function parseApiError(response) {
|
|
121
|
+
return (await parseApiErrorInfo(response)).message;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export {
|
|
125
|
+
CONTEXT_OVERFLOW_ACTIONS,
|
|
126
|
+
CONTEXT_TOO_LARGE_ACTIONS,
|
|
127
|
+
isContextOverflowText,
|
|
128
|
+
parseApiError
|
|
129
|
+
};
|
|
@@ -1,9 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
_appendRetiredStateBatch,
|
|
3
|
+
loadMemoryVNextCatalog
|
|
4
|
+
} from "./chunk-TY3TIUJK.js";
|
|
1
5
|
import {
|
|
2
6
|
resolveMachineId
|
|
3
7
|
} from "./chunk-ESHYE7WU.js";
|
|
4
8
|
import {
|
|
5
9
|
getDefaultCliLocalRuntimeDb
|
|
6
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-ZOVKKMF6.js";
|
|
11
|
+
import {
|
|
12
|
+
resolveAuthTokenFromEnv
|
|
13
|
+
} from "./chunk-A7GB5UGH.js";
|
|
14
|
+
import {
|
|
15
|
+
DEFAULT_NOLO_SERVER_URL
|
|
16
|
+
} from "./chunk-OLZBQWZU.js";
|
|
7
17
|
import {
|
|
8
18
|
buildCliRuntimeEnv,
|
|
9
19
|
clearProfileAuthToken,
|
|
@@ -12,20 +22,14 @@ import {
|
|
|
12
22
|
getProfileTokens,
|
|
13
23
|
loadProfileConfig,
|
|
14
24
|
saveDefaultProfile
|
|
15
|
-
} from "./chunk-
|
|
16
|
-
import {
|
|
17
|
-
resolveAuthTokenFromEnv
|
|
18
|
-
} from "./chunk-A7GB5UGH.js";
|
|
19
|
-
import {
|
|
20
|
-
DEFAULT_NOLO_SERVER_URL
|
|
21
|
-
} from "./chunk-OLZBQWZU.js";
|
|
25
|
+
} from "./chunk-TNIX77YM.js";
|
|
22
26
|
import {
|
|
23
27
|
asTrimmedNonEmptyStringArray,
|
|
24
28
|
createMemoryKey,
|
|
25
29
|
createMemoryOwnerIndexKey,
|
|
26
30
|
createMemorySubjectKindIndexKey,
|
|
27
31
|
memoryOwnerRange
|
|
28
|
-
} from "./chunk-
|
|
32
|
+
} from "./chunk-3AH7LNUB.js";
|
|
29
33
|
import {
|
|
30
34
|
asTrimmedString
|
|
31
35
|
} from "./chunk-3EUW3WEO.js";
|
|
@@ -39,6 +43,29 @@ import { stdin as input, stdout as output } from "node:process";
|
|
|
39
43
|
import { spawn } from "node:child_process";
|
|
40
44
|
|
|
41
45
|
// packages/ai/memory/delete.ts
|
|
46
|
+
var VNEXT_STATE_ID_PREFIX = "vnext-state-";
|
|
47
|
+
var toVNextMemoryItem = (state, owner) => ({
|
|
48
|
+
id: `${VNEXT_STATE_ID_PREFIX}${state.id}`,
|
|
49
|
+
ownerType: owner.ownerType,
|
|
50
|
+
ownerId: owner.ownerId,
|
|
51
|
+
visibility: "private",
|
|
52
|
+
subjectType: "user",
|
|
53
|
+
subjectId: owner.ownerId,
|
|
54
|
+
kind: "semantic",
|
|
55
|
+
content: state.text.trim(),
|
|
56
|
+
createdAt: state.createdAt,
|
|
57
|
+
lastActivatedAt: state.createdAt,
|
|
58
|
+
activationCount: 1,
|
|
59
|
+
importance: 0.9,
|
|
60
|
+
confidence: 0.9,
|
|
61
|
+
resident: state.facet === "preference" || state.facet === "style"
|
|
62
|
+
});
|
|
63
|
+
var matchesVNextFilters = (state, idSet, contentSub) => {
|
|
64
|
+
if (!idSet && !contentSub) return false;
|
|
65
|
+
if (idSet && !idSet.has(`${VNEXT_STATE_ID_PREFIX}${state.id}`)) return false;
|
|
66
|
+
if (contentSub && !state.text.toLowerCase().includes(contentSub)) return false;
|
|
67
|
+
return true;
|
|
68
|
+
};
|
|
42
69
|
function hasExplicitDeleteFilters(filters) {
|
|
43
70
|
return Boolean(
|
|
44
71
|
filters.ids && filters.ids.length > 0 || typeof filters.contentSubstring === "string" && filters.contentSubstring.trim().length > 0 || filters.tags && filters.tags.length > 0 || typeof filters.sourceDialogId === "string" && filters.sourceDialogId.trim().length > 0 || typeof filters.patternKeyPrefix === "string" && filters.patternKeyPrefix.trim().length > 0 || filters.facets && filters.facets.length > 0 || typeof filters.subjectId === "string" && filters.subjectId.trim().length > 0
|
|
@@ -127,8 +154,32 @@ var deleteMemoriesForOwnerFromDb = async (db, owner, filters = {}) => {
|
|
|
127
154
|
matchedItems.push(item);
|
|
128
155
|
if (matchedItems.length >= limit) break;
|
|
129
156
|
}
|
|
157
|
+
const idSet = normalizeSet(filters.ids);
|
|
158
|
+
const contentSub = asTrimmedString(filters.contentSubstring).toLowerCase();
|
|
159
|
+
const vnextStateIdsToRetire = [];
|
|
160
|
+
const vnextStatesToRetire = [];
|
|
161
|
+
const vnextMatchedItems = [];
|
|
162
|
+
let vnextPrincipalId = null;
|
|
163
|
+
const hasScopingFilters = Boolean(
|
|
164
|
+
normalizeSet(filters.kinds) || normalizeSet(filters.facets) || normalizeSet(filters.tags) || asTrimmedString(filters.subjectType) || asTrimmedString(filters.subjectId) || asTrimmedString(filters.patternKeyPrefix) || asTrimmedString(filters.sourceDialogId)
|
|
165
|
+
);
|
|
166
|
+
const canMatchVNext = !hasScopingFilters && (contentSub.length > 0 || idSet !== null && [...idSet].some((id) => id.startsWith(VNEXT_STATE_ID_PREFIX)));
|
|
167
|
+
if (canMatchVNext) {
|
|
168
|
+
vnextPrincipalId = `${owner.ownerType}:${encodeURIComponent(owner.ownerId)}`;
|
|
169
|
+
const catalog = await loadMemoryVNextCatalog(db, vnextPrincipalId);
|
|
170
|
+
for (const state of catalog.states) {
|
|
171
|
+
if (matchedItems.length >= limit) break;
|
|
172
|
+
if (state.retiredAt) continue;
|
|
173
|
+
if (!matchesVNextFilters(state, idSet, contentSub)) continue;
|
|
174
|
+
vnextStateIdsToRetire.push(state.id);
|
|
175
|
+
vnextStatesToRetire.push(state);
|
|
176
|
+
const projected = toVNextMemoryItem(state, owner);
|
|
177
|
+
vnextMatchedItems.push(projected);
|
|
178
|
+
matchedItems.push(projected);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
130
181
|
if (matchedItems.length === 0) {
|
|
131
|
-
return { deletedCount: 0, deletedIds: [], matchedItems: [] };
|
|
182
|
+
return { deletedCount: 0, deletedIds: [], retiredIds: [], matchedItems: [] };
|
|
132
183
|
}
|
|
133
184
|
const token = generateMemoryDeletionToken(
|
|
134
185
|
owner.ownerId,
|
|
@@ -138,6 +189,7 @@ var deleteMemoriesForOwnerFromDb = async (db, owner, filters = {}) => {
|
|
|
138
189
|
return {
|
|
139
190
|
deletedCount: 0,
|
|
140
191
|
deletedIds: [],
|
|
192
|
+
retiredIds: [],
|
|
141
193
|
matchedItems,
|
|
142
194
|
deletionToken: token
|
|
143
195
|
};
|
|
@@ -147,14 +199,28 @@ var deleteMemoriesForOwnerFromDb = async (db, owner, filters = {}) => {
|
|
|
147
199
|
"deletionToken mismatch: memory dataset changed since preview; please rerun dry-run preview before confirming."
|
|
148
200
|
);
|
|
149
201
|
}
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
202
|
+
const vnextMatchedIdSet = new Set(
|
|
203
|
+
vnextStateIdsToRetire.map((stateId) => `${VNEXT_STATE_ID_PREFIX}${stateId}`)
|
|
204
|
+
);
|
|
205
|
+
const legacyItems = matchedItems.filter((item) => !vnextMatchedIdSet.has(item.id));
|
|
206
|
+
const shouldRetireVNext = vnextStatesToRetire.length > 0;
|
|
207
|
+
if (legacyItems.length > 0 || shouldRetireVNext) {
|
|
208
|
+
const batch = db.batch();
|
|
209
|
+
for (const item of legacyItems) {
|
|
210
|
+
deleteMemoryItemWithIndexesInBatch(batch, item);
|
|
211
|
+
}
|
|
212
|
+
if (shouldRetireVNext) {
|
|
213
|
+
const nowIso = (/* @__PURE__ */ new Date()).toISOString();
|
|
214
|
+
for (const state of vnextStatesToRetire) {
|
|
215
|
+
_appendRetiredStateBatch(batch, { ...state, retiredAt: nowIso });
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
await batch.write();
|
|
153
219
|
}
|
|
154
|
-
await batch.write();
|
|
155
220
|
return {
|
|
156
221
|
deletedCount: matchedItems.length,
|
|
157
222
|
deletedIds: matchedItems.map((item) => item.id),
|
|
223
|
+
retiredIds: vnextMatchedItems.map((item) => item.id),
|
|
158
224
|
matchedItems,
|
|
159
225
|
deletionToken: token
|
|
160
226
|
};
|