nolo-cli 0.89.0-alpha.1 → 0.90.0-alpha.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 +2 -2
- package/{_executeModel-I3XRMAJ2.js → _executeModel-W26HVI75.js} +38 -38
- package/{action-7GHFPDSQ.js → action-6DXQGJMX.js} +7 -7
- package/{addContentAction-ZNVB2NOV.js → addContentAction-I7VX5SAC.js} +5 -5
- package/{addDialogAgentAction-CIDFWATM.js → addDialogAgentAction-OJSFV7DZ.js} +4 -4
- package/{agentDeleteCommand-DCTG26JW.js → agentDeleteCommand-XNFWCKBH.js} +24 -23
- package/{agentEmailCommands-MRRHBLDQ.js → agentEmailCommands-W3X3EJ3V.js} +50 -49
- package/{agentGrantCommands-R3VQEZJR.js → agentGrantCommands-YW6PQAQ2.js} +2 -2
- package/{agentListCommands-CUE46CSP.js → agentListCommands-DFWFU6XO.js} +32 -25
- package/{agentMachineCommands-FYDEKBIO.js → agentMachineCommands-LMFOAEL4.js} +24 -23
- package/{agentProviderCommands-X3FA6BUM.js → agentProviderCommands-ZBYHGTGY.js} +1 -1
- package/{agentPullCommand-U73W5IBM.js → agentPullCommand-GLOOXJ2E.js} +2 -2
- package/{agentRecordCommands-P2MSNP7R.js → agentRecordCommands-FVVVCQFM.js} +48 -47
- package/{agentRunCommand-QJGP7JEN.js → agentRunCommand-HTBVIBGV.js} +49 -48
- package/{agentRunControl-T44MESII.js → agentRunControl-XLGD3UZ5.js} +1 -1
- package/{agentRuntimeLocal-T43UNWAY.js → agentRuntimeLocal-2JFG4HDU.js} +20 -19
- package/{agentSlice-7GDS5Q2S.js → agentSlice-ZNLGFUB5.js} +5 -5
- package/{appDeleteCommands-YBKY3VEI.js → appDeleteCommands-2UN4N2NR.js} +25 -24
- package/{appDeployCommands-EBC76HO4.js → appDeployCommands-37D74KRR.js} +25 -24
- package/{appDeployStatusCommands-WXRC5KEK.js → appDeployStatusCommands-QBLWL2IA.js} +25 -24
- package/{appGetCommands-VZZQEDOV.js → appGetCommands-6KXIDF2T.js} +25 -24
- package/{appListCommands-HYSPVQ77.js → appListCommands-G2WFGEWQ.js} +25 -24
- package/{authCommand-E4GDVKMW.js → authCommand-V2DJ7DB7.js} +84 -18
- package/{authCommands-VOTT6XWX.js → authCommands-RGOGCPP6.js} +2 -2
- package/{builtinSkillRegistry-5SYVTS6Z.js → builtinSkillRegistry-WBGYKIAZ.js} +5 -5
- package/{chatQueueReduxAdapter-CXEWIDFZ.js → chatQueueReduxAdapter-XCJHIY3R.js} +17 -17
- package/{chunk-P3AS5IPM.js → chunk-2ADBVBEM.js} +3 -2
- package/{chunk-GRJTR4PU.js → chunk-2AYMFHUG.js} +4 -4
- package/{chunk-UO66QKGI.js → chunk-2F4VYGFW.js} +2 -2
- package/{chunk-LEYH5NOH.js → chunk-3CMTBX3X.js} +4 -4
- package/{chunk-GXWEF4IZ.js → chunk-3CR2LC6X.js} +1 -1
- package/{chunk-ZKGIAM7I.js → chunk-3R5PH4IP.js} +1 -1
- package/{chunk-VW3YGKWR.js → chunk-4BYPU626.js} +294 -203
- package/{chunk-PHDKTASK.js → chunk-4DRWWIOL.js} +1 -1
- package/{chunk-BNMZ7QUV.js → chunk-576IMUGH.js} +1 -1
- package/{chunk-AYT2OKNM.js → chunk-5DFFKASO.js} +3 -3
- package/{chunk-Q246OUG5.js → chunk-5NMZNPTN.js} +5 -5
- package/{chunk-5XTOKQLW.js → chunk-5UTFL4QJ.js} +6 -2
- package/{chunk-6RCZYDDC.js → chunk-5V4NJHRM.js} +6 -6
- package/chunk-5ZUL4CUO.js +10 -0
- package/{chunk-US463UAD.js → chunk-6BEA566T.js} +2 -2
- package/{chunk-UINEAQ2R.js → chunk-6D6VBVEW.js} +1 -1
- package/{chunk-JC2WQS66.js → chunk-7MYYE7WX.js} +20 -16
- package/{chunk-3T4PRBHV.js → chunk-A2C4AKKM.js} +1 -1
- package/{chunk-6ZC5KPXV.js → chunk-AQZRTHDZ.js} +903 -40
- package/{chunk-UWMQ6FPM.js → chunk-ASGDO77C.js} +118 -1
- package/{chunk-2KDR4CWE.js → chunk-BYMV6QZG.js} +24 -1
- package/{chunk-XCSSFPTB.js → chunk-CLI4LFSM.js} +1 -1
- package/{chunk-HH65VA5U.js → chunk-CPH3W5A7.js} +15 -3
- package/{chunk-TGRQUFLU.js → chunk-DNQPPRHY.js} +1 -1
- package/{chunk-2XEVK4BT.js → chunk-DPQ2WVBY.js} +1 -1
- package/{chunk-OCL2YCAU.js → chunk-F2CGG72C.js} +40 -40
- package/{chunk-S6STPUMG.js → chunk-FQYMLZ6C.js} +5 -5
- package/{chunk-BJIRLHJR.js → chunk-GII32WZW.js} +1 -0
- package/{chunk-VARZWSKW.js → chunk-GRYGRGPS.js} +3 -3
- package/{chunk-L2VNQQ7M.js → chunk-HMEMJ7GH.js} +364 -24
- package/{chunk-OZX2IPKM.js → chunk-HQCSU3DI.js} +1 -1
- package/{chunk-VQD6BTML.js → chunk-HYZHJ5GW.js} +3 -3
- package/{chunk-OAJRZ35U.js → chunk-IIKPWSPX.js} +1 -1
- package/{chunk-W7PGACND.js → chunk-JBBZ5KUM.js} +10 -10
- package/{chunk-KC5FAHVS.js → chunk-JEDZAO7L.js} +1 -1
- package/{chunk-LSV2BOJL.js → chunk-JTK3TJYV.js} +1 -1
- package/{chunk-X77EN2BJ.js → chunk-K7M3MWCE.js} +2 -2
- package/{chunk-OHUU52T3.js → chunk-L2ICPOAL.js} +1 -1
- package/{chunk-EVBFYPDC.js → chunk-MC4XLIJ7.js} +6 -2
- package/{chunk-DS3SQTDT.js → chunk-MJHQ3NRV.js} +1 -1
- package/{chunk-Q4KVAB6L.js → chunk-N3OAPEZE.js} +28 -9
- package/{chunk-T4F2EQGN.js → chunk-ND2J3NRB.js} +2 -2
- package/{chunk-IMDA4FW4.js → chunk-NFMHIUY3.js} +61 -46
- package/{chunk-JITSBA52.js → chunk-PH5J5VUY.js} +2 -2
- package/{chunk-FMODTASJ.js → chunk-Q5FJJ6XI.js} +1 -7
- package/{chunk-JYYZCK2Z.js → chunk-QFMFJZLO.js} +1 -1
- package/{chunk-WSOMSDQB.js → chunk-QHETQ3KI.js} +35 -1
- package/{chunk-IZAWJCG7.js → chunk-RZANZZL2.js} +1 -1
- package/{chunk-SPAQ4PVV.js → chunk-SAFZABH7.js} +1 -1
- package/{chunk-EXWOCYCR.js → chunk-SMZSWB44.js} +10 -5
- package/{chunk-HJKGQPYF.js → chunk-TL6L5XUT.js} +1 -1
- package/{chunk-4FRNB4ZG.js → chunk-TVNI5FLG.js} +4 -4
- package/{chunk-5EJZGJS2.js → chunk-UA5S3LQQ.js} +3 -3
- package/{chunk-Y2IFJ7VM.js → chunk-UTCCPWB2.js} +3 -3
- package/{chunk-KT6LENVP.js → chunk-VHJLQHPQ.js} +2 -2
- package/{chunk-6H7GN3JL.js → chunk-VRLI2WNW.js} +10 -1
- package/{chunk-23RQKXP6.js → chunk-WS22FPWT.js} +1 -1
- package/{chunk-NVHJWYUO.js → chunk-WXPVOQD7.js} +35 -33
- package/{chunk-MFW4BGJS.js → chunk-XKQJJK4F.js} +1 -1
- package/{chunk-GIG262ZG.js → chunk-XMGHGEN6.js} +1 -1
- package/{chunk-IO7DYRPW.js → chunk-XTUY5EL4.js} +16 -12
- package/{chunk-OKCTLCKS.js → chunk-YOXYA2GU.js} +1 -1
- package/{chunk-ZIHJVHFH.js → chunk-Z33ARZCP.js} +1 -1
- package/{chunk-ZSG2AQU4.js → chunk-ZAB3A45K.js} +62 -11
- package/{chunk-YZHP76TR.js → chunk-ZBT3WNBK.js} +1 -1
- package/{contentThunks-Y2ACIFDB.js → contentThunks-VURN3DFW.js} +18 -18
- package/{createAgentAutomationAction-TNE3QMJR.js → createAgentAutomationAction-QZAAY77R.js} +18 -18
- package/{createDialogAction-BMGHBTQB.js → createDialogAction-CHGXVTAC.js} +20 -20
- package/{createPageAction-FFNIZPIS.js → createPageAction-IOGAFIN7.js} +18 -18
- package/{dbSlice-4CUQE35F.js → dbSlice-YXQ6RYIH.js} +4 -4
- package/{dialogCommands-3JC3BIXC.js → dialogCommands-XREAP6WQ.js} +26 -25
- package/{dialogSlice-3E7Z7HZV.js → dialogSlice-DOPGWGS4.js} +17 -17
- package/{docCreateCommands-6LNQLCTA.js → docCreateCommands-3PYZGSCL.js} +24 -23
- package/{docDeleteCommands-ZJOAPWZS.js → docDeleteCommands-3Y6MU44Q.js} +25 -24
- package/{docReadCommands-LJTRSBG6.js → docReadCommands-UBANMAFR.js} +24 -23
- package/{docStore-R47ABXBB.js → docStore-SYYFBENY.js} +5 -5
- package/{docUpdateCommands-7P3QF3N2.js → docUpdateCommands-4GK2X6BN.js} +24 -23
- package/{getPricing-TV6ZB7ES.js → getPricing-F2C65RIX.js} +3 -3
- package/{handleSendMessageAction-FFYOGXAO.js → handleSendMessageAction-NPVTY2GE.js} +17 -17
- package/index.js +81 -81
- package/{machineCommands-FN5GGQV3.js → machineCommands-I66X2XB7.js} +47 -46
- package/{machineWsRunDispatch-H47IA7ZT.js → machineWsRunDispatch-W4FVBOUM.js} +47 -46
- package/{memberThunks-N35XAOC6.js → memberThunks-5T4J6KXQ.js} +5 -5
- package/{models-CMXFDBQH.js → models-WW7VFNXB.js} +2 -2
- package/{offlineMarxistsAgentCommand-GEH6SNNA.js → offlineMarxistsAgentCommand-JEWCIAWM.js} +1 -1
- package/package.json +1 -1
- package/{providerPresetApply-D2GGHPI7.js → providerPresetApply-OCWWKBSD.js} +6 -6
- package/{providerRegistry-MU6C4ABD.js → providerRegistry-ZJQU7AJ7.js} +6 -6
- package/{read-2PV4PN2E.js → read-M2Q6WEKB.js} +3 -3
- package/{readDocTool-FGK5XGAW.js → readDocTool-T37P3YPB.js} +1 -1
- package/{readlineWorkspace-NXKHYZEU.js → readlineWorkspace-VY5AMOGR.js} +123 -91
- package/{removeDialogAgentAction-O2POGBOE.js → removeDialogAgentAction-HB3JBVAI.js} +7 -7
- package/{runAgentClientLoop-CEBV5UPD.js → runAgentClientLoop-3NDADLVE.js} +36 -36
- package/{setDialogExtraReferencesAction-KPSVVY3C.js → setDialogExtraReferencesAction-4XLHRV37.js} +5 -5
- package/{setPrimaryDialogAgentAction-RMJETONI.js → setPrimaryDialogAgentAction-C3JOFC4W.js} +7 -7
- package/{settingSlice-I6MTTNDX.js → settingSlice-CZRURSTH.js} +6 -6
- package/{spaceCommands-JHT4ALCQ.js → spaceCommands-ENYCUUZH.js} +24 -23
- package/{streamAgentChatTurn-SFCZP4GY.js → streamAgentChatTurn-634OFUSR.js} +44 -42
- package/{switchDialogAgentAction-OQSGWVQQ.js → switchDialogAgentAction-C6KVUKJP.js} +4 -4
- package/{tableCommands-SUNTHAYX.js → tableCommands-O6NWHFKV.js} +1 -1
- package/{toolApiClient-VGYUB4P5.js → toolApiClient-7PSIFQPJ.js} +2 -2
- package/{tools-K3YOTESV.js → tools-ILBLCF7D.js} +33 -33
- package/tuiSummaryLlmCaller-LFUBZKXK.js +127 -0
- package/{updateCommands-Y363MC3L.js → updateCommands-2M74UL7P.js} +2 -2
- package/{updateDialogTitleAction-CSPKYQRO.js → updateDialogTitleAction-RKFET73N.js} +38 -21
- package/tuiSummaryLlmCaller-T2OA5ZVB.js +0 -116
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
resolveRawAgentInput,
|
|
10
10
|
resolveServerUrl,
|
|
11
11
|
writeUsage
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-QFMFJZLO.js";
|
|
13
13
|
import {
|
|
14
14
|
agentRunCardLabels,
|
|
15
15
|
createCliLocalRuntimeAdapter,
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
resolveLocalUserId,
|
|
28
28
|
t,
|
|
29
29
|
toolLabel
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-NFMHIUY3.js";
|
|
31
31
|
import {
|
|
32
32
|
createRunActivityTracker,
|
|
33
33
|
popSingleQueueMessage,
|
|
@@ -35,7 +35,7 @@ import {
|
|
|
35
35
|
resolveRunQueuePath,
|
|
36
36
|
settleRunTerminalAuthoritatively,
|
|
37
37
|
spawnLocalBackgroundRun
|
|
38
|
-
} from "./chunk-
|
|
38
|
+
} from "./chunk-CPH3W5A7.js";
|
|
39
39
|
import {
|
|
40
40
|
readCredentialEntry,
|
|
41
41
|
recordCredentialProbe,
|
|
@@ -47,10 +47,10 @@ import {
|
|
|
47
47
|
import {
|
|
48
48
|
readDbRecord,
|
|
49
49
|
resolveAgentRecordFromHybridStore
|
|
50
|
-
} from "./chunk-
|
|
50
|
+
} from "./chunk-UTCCPWB2.js";
|
|
51
51
|
import {
|
|
52
52
|
isLocalCliAgentKey
|
|
53
|
-
} from "./chunk-
|
|
53
|
+
} from "./chunk-SAFZABH7.js";
|
|
54
54
|
import {
|
|
55
55
|
CliProviderQuotaError
|
|
56
56
|
} from "./chunk-MP64VFGD.js";
|
|
@@ -63,10 +63,10 @@ import {
|
|
|
63
63
|
} from "./chunk-LTRXGFMS.js";
|
|
64
64
|
import {
|
|
65
65
|
formatAgentListCard
|
|
66
|
-
} from "./chunk-
|
|
66
|
+
} from "./chunk-WXPVOQD7.js";
|
|
67
67
|
import {
|
|
68
68
|
isTransientFetchError
|
|
69
|
-
} from "./chunk-
|
|
69
|
+
} from "./chunk-5UTFL4QJ.js";
|
|
70
70
|
import {
|
|
71
71
|
isGatewayHttpStatus
|
|
72
72
|
} from "./chunk-NF64D32W.js";
|
|
@@ -84,11 +84,11 @@ import {
|
|
|
84
84
|
chooseMemoryOwners,
|
|
85
85
|
loadMemoryCandidatesFromDb,
|
|
86
86
|
resolveAgentMemoryPolicy
|
|
87
|
-
} from "./chunk-
|
|
87
|
+
} from "./chunk-5V4NJHRM.js";
|
|
88
88
|
import {
|
|
89
89
|
API_REPORTED_COST_MULTIPLIER,
|
|
90
90
|
parseUiAskChoiceContent
|
|
91
|
-
} from "./chunk-
|
|
91
|
+
} from "./chunk-HMEMJ7GH.js";
|
|
92
92
|
import {
|
|
93
93
|
isOAuthApiKeyRef
|
|
94
94
|
} from "./chunk-YYLHWIW6.js";
|
|
@@ -111,16 +111,17 @@ import {
|
|
|
111
111
|
LOCAL_AGENT_CONFIG_MISSING_CODE,
|
|
112
112
|
LOCAL_TURN_ABORTED_CODE,
|
|
113
113
|
readActionGate
|
|
114
|
-
} from "./chunk-
|
|
114
|
+
} from "./chunk-4BYPU626.js";
|
|
115
115
|
import {
|
|
116
116
|
resolveAgentRuntimeConfigFromRecord
|
|
117
|
-
} from "./chunk-
|
|
117
|
+
} from "./chunk-QHETQ3KI.js";
|
|
118
118
|
import {
|
|
119
119
|
createThinkParserState,
|
|
120
120
|
flushThinkParser,
|
|
121
121
|
processThinkChunk
|
|
122
122
|
} from "./chunk-N7J63Q6C.js";
|
|
123
123
|
import {
|
|
124
|
+
QUOTA_ERROR_PATTERNS,
|
|
124
125
|
isQuotaExhaustedError,
|
|
125
126
|
isQuotaLimited403Body,
|
|
126
127
|
mergeAvailabilityDeadline,
|
|
@@ -128,21 +129,21 @@ import {
|
|
|
128
129
|
} from "./chunk-CJCJF5XB.js";
|
|
129
130
|
import {
|
|
130
131
|
isAntigravityOAuthAgent
|
|
131
|
-
} from "./chunk-
|
|
132
|
+
} from "./chunk-MJHQ3NRV.js";
|
|
132
133
|
import {
|
|
133
134
|
resolveClientVersion
|
|
134
|
-
} from "./chunk-
|
|
135
|
+
} from "./chunk-K7M3MWCE.js";
|
|
135
136
|
import {
|
|
136
137
|
DEFAULT_CONTEXT_WINDOW,
|
|
137
138
|
getModelContextWindow,
|
|
138
139
|
normalizeUsage
|
|
139
|
-
} from "./chunk-
|
|
140
|
+
} from "./chunk-F2CGG72C.js";
|
|
140
141
|
import {
|
|
141
142
|
clipCompactText
|
|
142
|
-
} from "./chunk-
|
|
143
|
+
} from "./chunk-VHJLQHPQ.js";
|
|
143
144
|
import {
|
|
144
145
|
findModelConfig
|
|
145
|
-
} from "./chunk-
|
|
146
|
+
} from "./chunk-VRLI2WNW.js";
|
|
146
147
|
import {
|
|
147
148
|
compactWhitespace
|
|
148
149
|
} from "./chunk-DWLEOOGR.js";
|
|
@@ -167,12 +168,13 @@ import {
|
|
|
167
168
|
CLIENT_VERSION_TOO_OLD_CODE,
|
|
168
169
|
NOLO_CLIENT_VERSION_HEADER,
|
|
169
170
|
buildClientVersionUpgradeMessage
|
|
170
|
-
} from "./chunk-
|
|
171
|
+
} from "./chunk-ASGDO77C.js";
|
|
171
172
|
import {
|
|
172
173
|
parsePositiveFiniteNumberOrFallback
|
|
173
174
|
} from "./chunk-Y5GCAMGP.js";
|
|
174
175
|
import {
|
|
175
|
-
createMemoryKey
|
|
176
|
+
createMemoryKey,
|
|
177
|
+
ulid
|
|
176
178
|
} from "./chunk-VMFTFOWF.js";
|
|
177
179
|
import {
|
|
178
180
|
asTrimmedLowercaseString
|
|
@@ -181,10 +183,13 @@ import {
|
|
|
181
183
|
BUILTIN_NOLO_AGENT_KEY,
|
|
182
184
|
BUILTIN_NOLO_AGENT_NAME,
|
|
183
185
|
builtinAgentCatalogEntryById
|
|
184
|
-
} from "./chunk-
|
|
186
|
+
} from "./chunk-TL6L5XUT.js";
|
|
185
187
|
import {
|
|
186
188
|
parsePublicAgentId
|
|
187
|
-
} from "./chunk-
|
|
189
|
+
} from "./chunk-GII32WZW.js";
|
|
190
|
+
import {
|
|
191
|
+
isLevelNotFoundError
|
|
192
|
+
} from "./chunk-OW765XBU.js";
|
|
188
193
|
import {
|
|
189
194
|
asTrimmedString
|
|
190
195
|
} from "./chunk-3EUW3WEO.js";
|
|
@@ -10411,9 +10416,9 @@ function findCollapsedPasteSpanAt(buffer, pos, opts = {}) {
|
|
|
10411
10416
|
}
|
|
10412
10417
|
|
|
10413
10418
|
// packages/cli/client/agentRun.ts
|
|
10414
|
-
import { ulid } from "ulid";
|
|
10419
|
+
import { ulid as ulid2 } from "ulid";
|
|
10415
10420
|
async function loadRunLocalAgentTurn() {
|
|
10416
|
-
const { runLocalAgentTurn } = await import("./agentRuntimeLocal-
|
|
10421
|
+
const { runLocalAgentTurn } = await import("./agentRuntimeLocal-2JFG4HDU.js");
|
|
10417
10422
|
return runLocalAgentTurn;
|
|
10418
10423
|
}
|
|
10419
10424
|
var stripDebugNoise = (s) => s.replace(/\s*raw="[\s\S]*"/g, "").replace(/\s*raw=\S+/g, "").replace(/\s*headers=\[[^\]]*\]/g, "").replace(/\s*headers=\S+/g, "").trim();
|
|
@@ -10676,27 +10681,62 @@ function isMissingLocalAgentConfigError(error, agentRef) {
|
|
|
10676
10681
|
}
|
|
10677
10682
|
var PROVIDER_HTTP_FAILED_RE = /(.+?) provider failed:\s*HTTP\s+(\d+)\b/i;
|
|
10678
10683
|
var PLATFORM_TRANSPORT_RE = /\bplatform provider failed\b/i;
|
|
10684
|
+
var EXTRA_RATE_LIMIT_TEXT_RE = /\brate[\s_-]?limit(?:ed|ing|s)?\b|\bresource[_\s-]?exhausted\b|\bmax_concurrent_reached\b/i;
|
|
10685
|
+
function looksLikeRateLimitedText(message) {
|
|
10686
|
+
return EXTRA_RATE_LIMIT_TEXT_RE.test(message) || QUOTA_ERROR_PATTERNS.some((pattern) => pattern.test(message));
|
|
10687
|
+
}
|
|
10688
|
+
var AUTH_TEXT_SIGNAL_RE = /\b401\b|unauthori[sz]ed|invalid[_\s-]?(?:api[_\s-]?key|token|credential)s?|(?:api[_\s-]?key|token|credential)s?[_\s-](?:invalid|expired|rejected|missing|not[_\s-]?found)|authentication[_\s-]?(?:error|failed|required)/i;
|
|
10689
|
+
var QUOTA_EXHAUSTED_EXTRA_RE = /insufficient[_\s-]?(?:quota|balance|credits?)|余额不足|额度已?用尽/i;
|
|
10690
|
+
function looksLikeQuotaExhaustedText(message) {
|
|
10691
|
+
return isQuotaLimited403Body(message) || QUOTA_EXHAUSTED_EXTRA_RE.test(message);
|
|
10692
|
+
}
|
|
10693
|
+
var BARE_UPSTREAM_5XX_RE = /\bHTTP[:\s]+(5\d\d)\b|\bstatus[:\s=]+(5\d\d)\b|\breturned error\s+(5\d\d)\b/i;
|
|
10679
10694
|
function classifyLocalRunError(message) {
|
|
10680
10695
|
const m = message.match(PROVIDER_HTTP_FAILED_RE);
|
|
10681
|
-
if (
|
|
10682
|
-
|
|
10683
|
-
|
|
10684
|
-
|
|
10685
|
-
|
|
10686
|
-
|
|
10687
|
-
|
|
10688
|
-
|
|
10689
|
-
|
|
10690
|
-
|
|
10691
|
-
|
|
10696
|
+
if (m) {
|
|
10697
|
+
const status = Number(m[2]);
|
|
10698
|
+
const transport2 = PLATFORM_TRANSPORT_RE.test(message) ? "platform" : "local";
|
|
10699
|
+
const quotaExhausted = looksLikeQuotaExhaustedText(message);
|
|
10700
|
+
if (status === 401) {
|
|
10701
|
+
return { kind: "auth", transport: transport2, status };
|
|
10702
|
+
}
|
|
10703
|
+
if (status === 403) {
|
|
10704
|
+
return quotaExhausted ? { kind: "rate-limit", transport: transport2, status, quotaExhausted: true } : { kind: "auth", transport: transport2, status };
|
|
10705
|
+
}
|
|
10706
|
+
if (status === 400 || status === 422) {
|
|
10707
|
+
return { kind: "rejected-payload", transport: transport2, status };
|
|
10708
|
+
}
|
|
10709
|
+
if (status === 429) {
|
|
10710
|
+
return {
|
|
10711
|
+
kind: "rate-limit",
|
|
10712
|
+
transport: transport2,
|
|
10713
|
+
status,
|
|
10714
|
+
...quotaExhausted ? { quotaExhausted: true } : {}
|
|
10715
|
+
};
|
|
10716
|
+
}
|
|
10717
|
+
if (status >= 500 && status <= 599) {
|
|
10718
|
+
return { kind: "transient", transport: transport2, status };
|
|
10719
|
+
}
|
|
10720
|
+
return { kind: "upstream", transport: transport2, status };
|
|
10692
10721
|
}
|
|
10693
|
-
|
|
10694
|
-
|
|
10722
|
+
const transport = PLATFORM_TRANSPORT_RE.test(message) ? "platform" : "local";
|
|
10723
|
+
if (AUTH_TEXT_SIGNAL_RE.test(message)) return { kind: "generic" };
|
|
10724
|
+
if (looksLikeRateLimitedText(message)) {
|
|
10725
|
+
const quotaExhausted = looksLikeQuotaExhaustedText(message);
|
|
10726
|
+
return {
|
|
10727
|
+
kind: "rate-limit",
|
|
10728
|
+
transport,
|
|
10729
|
+
status: 429,
|
|
10730
|
+
statusInferred: true,
|
|
10731
|
+
...quotaExhausted ? { quotaExhausted: true } : {}
|
|
10732
|
+
};
|
|
10695
10733
|
}
|
|
10696
|
-
|
|
10734
|
+
const bare5xx = message.match(BARE_UPSTREAM_5XX_RE);
|
|
10735
|
+
if (bare5xx) {
|
|
10736
|
+
const status = Number(bare5xx[1] ?? bare5xx[2] ?? bare5xx[3]);
|
|
10697
10737
|
return { kind: "transient", transport, status };
|
|
10698
10738
|
}
|
|
10699
|
-
return { kind: "
|
|
10739
|
+
return { kind: "generic" };
|
|
10700
10740
|
}
|
|
10701
10741
|
var HISTORY_REPLAY_REJECTION_RE = /invalid_request_error|invalid\s+tool\s+call\s+arguments?/i;
|
|
10702
10742
|
var RUN_UNAVAILABLE_PREFIX = "[nolo] auto runtime: local run unavailable";
|
|
@@ -10717,9 +10757,18 @@ function buildRejectedPayloadFailure(ctx) {
|
|
|
10717
10757
|
return `${RUN_UNAVAILABLE_PREFIX} (${ctx.where} returned HTTP ${ctx.status}, the provider rejected the request body \u2014 this is NOT a local credential/config issue). Detail: ${ctx.message}${cause} ${NO_FALLBACK} Use --server to run on the server explicitly, or start a fresh dialog.
|
|
10718
10758
|
`;
|
|
10719
10759
|
}
|
|
10760
|
+
var RATE_LIMIT_RESET_HINT_RE = /retry[-_\s]?after\s*[:=]?\s*\d[\w:-]*|resets?\s+(?:in|at)\s+\d[\w:-]*(?:[ T]\d[\w:-]*)?/i;
|
|
10761
|
+
function extractRateLimitResetHint(message) {
|
|
10762
|
+
const match = message.match(RATE_LIMIT_RESET_HINT_RE);
|
|
10763
|
+
return match ? match[0].trim() : void 0;
|
|
10764
|
+
}
|
|
10720
10765
|
function buildRateLimitFailure(ctx) {
|
|
10721
10766
|
const cooldownNote = ctx.cooldownUntil ? ` \u5DF2\u6807\u8BB0\u51B7\u5374\u81F3 ${ctx.cooldownUntil}\uFF0C\u5230\u671F\u524D\u6D3E\u53D1\u4F1A\u88AB\u51B7\u5374\u95E8\u63A7\u62E6\u622A\uFF08\u5230\u671F\u81EA\u52A8 probe \u6062\u590D\uFF09\u3002` : "";
|
|
10722
|
-
|
|
10767
|
+
const headline = ctx.statusInferred ? `${ctx.where} hit an upstream rate-limit/quota error` : `${ctx.where} returned HTTP ${ctx.status}, rate limited`;
|
|
10768
|
+
const cause = ctx.quotaExhausted ? "The upstream quota/balance for this agent is exhausted \u2014 NOT a local credential/config issue" : "This agent is being throttled by the upstream provider \u2014 NOT a local credential/config issue";
|
|
10769
|
+
const reset = extractRateLimitResetHint(ctx.message);
|
|
10770
|
+
const advice = ctx.quotaExhausted ? `Retry after the upstream quota resets${reset ? ` (${reset})` : ""}` : `Retry shortly${reset ? ` (${reset})` : ""}`;
|
|
10771
|
+
return `${RUN_UNAVAILABLE_PREFIX} (${headline}). Detail: ${ctx.message} ${NO_FALLBACK} ${cause}. ${advice}, switch to another agent (\`nolo agent list\`), ${SERVER_FALLBACK_HINT}${cooldownNote}
|
|
10723
10772
|
`;
|
|
10724
10773
|
}
|
|
10725
10774
|
function buildTransientFailure(ctx) {
|
|
@@ -10814,6 +10863,8 @@ function describeLocalRunFailure(message, rawError) {
|
|
|
10814
10863
|
message,
|
|
10815
10864
|
where: cls.transport === "platform" ? "server chat proxy" : "local provider",
|
|
10816
10865
|
status: cls.status,
|
|
10866
|
+
...cls.statusInferred ? { statusInferred: true } : {},
|
|
10867
|
+
...cls.quotaExhausted ? { quotaExhausted: true } : {},
|
|
10817
10868
|
...cooldownUntil ? { cooldownUntil } : {}
|
|
10818
10869
|
};
|
|
10819
10870
|
return FAILURE_BUILDERS[cls.kind](ctx);
|
|
@@ -11078,8 +11129,8 @@ async function runLocalAgentTurnForCli(options, settings) {
|
|
|
11078
11129
|
...options.parentWakeOnTerminal ? { parentWakeOnTerminal: true } : {},
|
|
11079
11130
|
...options.parentDialogId ? { parentThreadId: options.parentDialogId } : {}
|
|
11080
11131
|
} : void 0;
|
|
11081
|
-
const currentDialogId = options.continueDialogId ??
|
|
11082
|
-
const turnId = `turn-${
|
|
11132
|
+
const currentDialogId = options.continueDialogId ?? ulid2();
|
|
11133
|
+
const turnId = `turn-${ulid2()}`;
|
|
11083
11134
|
const runtimeContextWithOwnership = {
|
|
11084
11135
|
...runtimeContext ?? {},
|
|
11085
11136
|
dialogId: currentDialogId,
|
|
@@ -12076,8 +12127,15 @@ var rankMemoryCandidates = (items, query, context) => {
|
|
|
12076
12127
|
// packages/ai/memory/vnext/store.ts
|
|
12077
12128
|
var enc = (value) => encodeURIComponent(value).replace(/-/g, "%2D");
|
|
12078
12129
|
var rangeOf = (prefix) => ({ gte: prefix, lte: `${prefix}\uFFFF` });
|
|
12130
|
+
var entityKey = (ownerId, id) => `mem2-e-${enc(ownerId)}-${enc(id)}`;
|
|
12079
12131
|
var entityOwnerPrefix = (ownerId) => `mem2-e-${enc(ownerId)}-`;
|
|
12132
|
+
var stateKey = (ownerId, id) => `mem2-s-${enc(ownerId)}-${enc(id)}`;
|
|
12133
|
+
var stateEntityIndexKey = (ownerId, entityId, stateId) => `mem2-si-${enc(ownerId)}-${enc(entityId)}-${enc(stateId)}`;
|
|
12080
12134
|
var stateEntityIndexPrefix = (ownerId, entityId) => `mem2-si-${enc(ownerId)}-${enc(entityId)}-`;
|
|
12135
|
+
var evidenceKey = (ownerId, id) => `mem2-v-${enc(ownerId)}-${enc(id)}`;
|
|
12136
|
+
var relationKey = (ownerId, id) => `mem2-r-${enc(ownerId)}-${enc(id)}`;
|
|
12137
|
+
var relationFromIndexKey = (ownerId, from, relationId) => `mem2-rf-${enc(ownerId)}-${enc(from)}-${enc(relationId)}`;
|
|
12138
|
+
var relationToIndexKey = (ownerId, to, relationId) => `mem2-rt-${enc(ownerId)}-${enc(to)}-${enc(relationId)}`;
|
|
12081
12139
|
var readIndexed = async (db, prefix) => {
|
|
12082
12140
|
const refs = [];
|
|
12083
12141
|
for await (const [, value] of db.iterator({ ...rangeOf(prefix), reverse: false })) {
|
|
@@ -12086,6 +12144,7 @@ var readIndexed = async (db, prefix) => {
|
|
|
12086
12144
|
const rows = await Promise.all(refs.map((key) => db.get(key).catch(() => null)));
|
|
12087
12145
|
return rows.filter((row) => !!row);
|
|
12088
12146
|
};
|
|
12147
|
+
var getMemoryEntityVNext = async (db, ownerId, entityId) => db.get(entityKey(ownerId, entityId)).catch(() => null);
|
|
12089
12148
|
var listMemoryEntitiesVNext = async (db, ownerId) => {
|
|
12090
12149
|
const rows = [];
|
|
12091
12150
|
for await (const [, value] of db.iterator({
|
|
@@ -12096,7 +12155,40 @@ var listMemoryEntitiesVNext = async (db, ownerId) => {
|
|
|
12096
12155
|
}
|
|
12097
12156
|
return rows;
|
|
12098
12157
|
};
|
|
12158
|
+
var getMemoryStateVNext = async (db, ownerId, stateId) => db.get(stateKey(ownerId, stateId)).catch(() => null);
|
|
12099
12159
|
var listMemoryStatesForEntityVNext = (db, ownerId, entityId) => readIndexed(db, stateEntityIndexPrefix(ownerId, entityId));
|
|
12160
|
+
var putMemoryEvidenceVNext = async (db, evidence) => {
|
|
12161
|
+
await db.put(evidenceKey(evidence.ownerId, evidence.id), evidence);
|
|
12162
|
+
};
|
|
12163
|
+
var getMemoryEvidenceVNext = async (db, ownerId, evidenceId) => db.get(evidenceKey(ownerId, evidenceId)).catch(() => null);
|
|
12164
|
+
var getMemoryEvidenceVNextStrict = async (db, ownerId, evidenceId) => {
|
|
12165
|
+
try {
|
|
12166
|
+
return await db.get(evidenceKey(ownerId, evidenceId));
|
|
12167
|
+
} catch (error) {
|
|
12168
|
+
if (isLevelNotFoundError(error)) return null;
|
|
12169
|
+
throw error;
|
|
12170
|
+
}
|
|
12171
|
+
};
|
|
12172
|
+
var _appendEntityBatch = (batch, entity) => {
|
|
12173
|
+
batch.put(entityKey(entity.ownerId, entity.id), entity);
|
|
12174
|
+
};
|
|
12175
|
+
var _appendEvidenceBatch = (batch, evidence) => {
|
|
12176
|
+
batch.put(evidenceKey(evidence.ownerId, evidence.id), evidence);
|
|
12177
|
+
};
|
|
12178
|
+
var _appendStateBatch = (batch, state2) => {
|
|
12179
|
+
const key = stateKey(state2.ownerId, state2.id);
|
|
12180
|
+
batch.put(key, state2);
|
|
12181
|
+
batch.put(stateEntityIndexKey(state2.ownerId, state2.entityId, state2.id), { key });
|
|
12182
|
+
};
|
|
12183
|
+
var _appendRetiredStateBatch = (batch, state2) => {
|
|
12184
|
+
batch.put(stateKey(state2.ownerId, state2.id), state2);
|
|
12185
|
+
};
|
|
12186
|
+
var _appendRelationBatch = (batch, relation) => {
|
|
12187
|
+
const key = relationKey(relation.ownerId, relation.id);
|
|
12188
|
+
batch.put(key, relation);
|
|
12189
|
+
batch.put(relationFromIndexKey(relation.ownerId, relation.from, relation.id), { key });
|
|
12190
|
+
batch.put(relationToIndexKey(relation.ownerId, relation.to, relation.id), { key });
|
|
12191
|
+
};
|
|
12100
12192
|
|
|
12101
12193
|
// packages/ai/memory/vnext/recall.ts
|
|
12102
12194
|
var MAX_RECALL_REFS = 6;
|
|
@@ -12227,11 +12319,41 @@ ${catalogText(entities, states)}`
|
|
|
12227
12319
|
};
|
|
12228
12320
|
|
|
12229
12321
|
// packages/ai/memory/vnext/legacyMigration.ts
|
|
12322
|
+
import { createHash } from "crypto";
|
|
12323
|
+
var LEGACY_MEMORY_SOURCE_REF_PREFIX = "legacy-memory";
|
|
12324
|
+
var LEGACY_MEMORY_EVIDENCE_ID_PREFIX = "mem-legacy-";
|
|
12230
12325
|
var resolveLegacyMemoryPrincipal = (item) => ({
|
|
12231
12326
|
ownerType: item.ownerType,
|
|
12232
12327
|
ownerId: item.ownerId,
|
|
12233
12328
|
principalId: `${item.ownerType}:${encodeURIComponent(item.ownerId)}`
|
|
12234
12329
|
});
|
|
12330
|
+
var buildLegacyMemorySourceRef = (item) => {
|
|
12331
|
+
const { principalId } = resolveLegacyMemoryPrincipal(item);
|
|
12332
|
+
return `${LEGACY_MEMORY_SOURCE_REF_PREFIX}:${principalId}:${encodeURIComponent(item.id)}`;
|
|
12333
|
+
};
|
|
12334
|
+
var legacyEvidenceSeed = (principalId, itemId) => JSON.stringify([principalId, itemId]);
|
|
12335
|
+
var buildLegacyEvidenceId = (item) => {
|
|
12336
|
+
const { principalId } = resolveLegacyMemoryPrincipal(item);
|
|
12337
|
+
const digest = createHash("sha256").update(legacyEvidenceSeed(principalId, item.id)).digest("hex");
|
|
12338
|
+
return `${LEGACY_MEMORY_EVIDENCE_ID_PREFIX}${digest.slice(0, 32)}`;
|
|
12339
|
+
};
|
|
12340
|
+
var clampLegacyConfidence = (value) => {
|
|
12341
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return 0;
|
|
12342
|
+
if (value < 0) return 0;
|
|
12343
|
+
if (value > 1) return 1;
|
|
12344
|
+
return value;
|
|
12345
|
+
};
|
|
12346
|
+
var buildLegacyMemoryEvidence = (item) => {
|
|
12347
|
+
const { principalId } = resolveLegacyMemoryPrincipal(item);
|
|
12348
|
+
return {
|
|
12349
|
+
id: buildLegacyEvidenceId(item),
|
|
12350
|
+
ownerId: principalId,
|
|
12351
|
+
text: item.content,
|
|
12352
|
+
sourceRef: buildLegacyMemorySourceRef(item),
|
|
12353
|
+
confidence: clampLegacyConfidence(item.confidence),
|
|
12354
|
+
createdAt: item.createdAt
|
|
12355
|
+
};
|
|
12356
|
+
};
|
|
12235
12357
|
|
|
12236
12358
|
// packages/ai/memory/vnext/shadowRead.ts
|
|
12237
12359
|
var SHADOW_TIMEOUT_MS = 2e4;
|
|
@@ -12340,6 +12462,736 @@ var runMemoryVNextShadowRead = async (input) => {
|
|
|
12340
12462
|
};
|
|
12341
12463
|
var isMemoryVNextShadowReadEnabled = (env = typeof process !== "undefined" ? process.env : {}) => env.NOLO_MEMORY_VNEXT_SHADOW_READ === "1" || env.NOLO_MEMORY_VNEXT_SHADOW_READ === "true";
|
|
12342
12464
|
|
|
12465
|
+
// packages/ai/memory/vnext/applyMutation.ts
|
|
12466
|
+
async function validateMutation(db, ownerId, mutation) {
|
|
12467
|
+
const pending = {
|
|
12468
|
+
evidenceIds: /* @__PURE__ */ new Set(),
|
|
12469
|
+
entityIds: /* @__PURE__ */ new Set(),
|
|
12470
|
+
stateIds: /* @__PURE__ */ new Set(),
|
|
12471
|
+
relationIds: /* @__PURE__ */ new Set()
|
|
12472
|
+
};
|
|
12473
|
+
for (const ev of mutation.evidence ?? []) {
|
|
12474
|
+
if (!ev.id || typeof ev.id !== "string") {
|
|
12475
|
+
throw new Error("evidence id must be a non-empty string");
|
|
12476
|
+
}
|
|
12477
|
+
if (pending.evidenceIds.has(ev.id)) {
|
|
12478
|
+
throw new Error(`duplicate evidence id in mutation: ${ev.id}`);
|
|
12479
|
+
}
|
|
12480
|
+
pending.evidenceIds.add(ev.id);
|
|
12481
|
+
}
|
|
12482
|
+
for (const ent of mutation.entities ?? []) {
|
|
12483
|
+
if (!ent.id || typeof ent.id !== "string") {
|
|
12484
|
+
throw new Error("entity id must be a non-empty string");
|
|
12485
|
+
}
|
|
12486
|
+
if (pending.entityIds.has(ent.id)) {
|
|
12487
|
+
throw new Error(`duplicate entity id in mutation: ${ent.id}`);
|
|
12488
|
+
}
|
|
12489
|
+
pending.entityIds.add(ent.id);
|
|
12490
|
+
}
|
|
12491
|
+
for (const st of mutation.states ?? []) {
|
|
12492
|
+
if (!st.id || typeof st.id !== "string") {
|
|
12493
|
+
throw new Error("state id must be a non-empty string");
|
|
12494
|
+
}
|
|
12495
|
+
if (pending.stateIds.has(st.id)) {
|
|
12496
|
+
throw new Error(`duplicate state id in mutation: ${st.id}`);
|
|
12497
|
+
}
|
|
12498
|
+
pending.stateIds.add(st.id);
|
|
12499
|
+
}
|
|
12500
|
+
for (const rel of mutation.relations ?? []) {
|
|
12501
|
+
if (!rel.id || typeof rel.id !== "string") {
|
|
12502
|
+
throw new Error("relation id must be a non-empty string");
|
|
12503
|
+
}
|
|
12504
|
+
if (pending.relationIds.has(rel.id)) {
|
|
12505
|
+
throw new Error(`duplicate relation id in mutation: ${rel.id}`);
|
|
12506
|
+
}
|
|
12507
|
+
pending.relationIds.add(rel.id);
|
|
12508
|
+
}
|
|
12509
|
+
const supersededIds = /* @__PURE__ */ new Set();
|
|
12510
|
+
for (const sid of mutation.supersededStateIds ?? []) {
|
|
12511
|
+
if (supersededIds.has(sid)) {
|
|
12512
|
+
throw new Error(`duplicate supersededStateId in mutation: ${sid}`);
|
|
12513
|
+
}
|
|
12514
|
+
supersededIds.add(sid);
|
|
12515
|
+
}
|
|
12516
|
+
for (const ev of mutation.evidence ?? []) {
|
|
12517
|
+
if (ev.ownerId !== ownerId) {
|
|
12518
|
+
throw new Error(
|
|
12519
|
+
`evidence ${ev.id} has ownerId ${ev.ownerId}, expected ${ownerId}`
|
|
12520
|
+
);
|
|
12521
|
+
}
|
|
12522
|
+
}
|
|
12523
|
+
for (const ent of mutation.entities ?? []) {
|
|
12524
|
+
if (ent.ownerId !== ownerId) {
|
|
12525
|
+
throw new Error(
|
|
12526
|
+
`entity ${ent.id} has ownerId ${ent.ownerId}, expected ${ownerId}`
|
|
12527
|
+
);
|
|
12528
|
+
}
|
|
12529
|
+
}
|
|
12530
|
+
for (const st of mutation.states ?? []) {
|
|
12531
|
+
if (st.ownerId !== ownerId) {
|
|
12532
|
+
throw new Error(
|
|
12533
|
+
`state ${st.id} has ownerId ${st.ownerId}, expected ${ownerId}`
|
|
12534
|
+
);
|
|
12535
|
+
}
|
|
12536
|
+
}
|
|
12537
|
+
for (const rel of mutation.relations ?? []) {
|
|
12538
|
+
if (rel.ownerId !== ownerId) {
|
|
12539
|
+
throw new Error(
|
|
12540
|
+
`relation ${rel.id} has ownerId ${rel.ownerId}, expected ${ownerId}`
|
|
12541
|
+
);
|
|
12542
|
+
}
|
|
12543
|
+
}
|
|
12544
|
+
for (const st of mutation.states ?? []) {
|
|
12545
|
+
if (supersededIds.has(st.id)) {
|
|
12546
|
+
throw new Error(
|
|
12547
|
+
`state ${st.id} appears in both states and supersededStateIds; a record cannot be created and retired in the same mutation`
|
|
12548
|
+
);
|
|
12549
|
+
}
|
|
12550
|
+
}
|
|
12551
|
+
const facetSlots = /* @__PURE__ */ new Set();
|
|
12552
|
+
for (const st of mutation.states ?? []) {
|
|
12553
|
+
const slot = `${st.entityId} ${st.facet}`;
|
|
12554
|
+
if (facetSlots.has(slot)) {
|
|
12555
|
+
throw new Error(
|
|
12556
|
+
`mutation writes parallel current states for entity ${st.entityId} facet ${st.facet}`
|
|
12557
|
+
);
|
|
12558
|
+
}
|
|
12559
|
+
facetSlots.add(slot);
|
|
12560
|
+
}
|
|
12561
|
+
for (const ev of mutation.evidence ?? []) {
|
|
12562
|
+
const existing = await getMemoryEvidenceVNext(db, ownerId, ev.id);
|
|
12563
|
+
if (existing) {
|
|
12564
|
+
throw new Error(
|
|
12565
|
+
`evidence ${ev.id} already exists (owner ${ownerId}); use a unique id`
|
|
12566
|
+
);
|
|
12567
|
+
}
|
|
12568
|
+
}
|
|
12569
|
+
for (const ent of mutation.entities ?? []) {
|
|
12570
|
+
const existing = await getMemoryEntityVNext(db, ownerId, ent.id);
|
|
12571
|
+
if (existing) {
|
|
12572
|
+
throw new Error(
|
|
12573
|
+
`entity ${ent.id} already exists (owner ${ownerId}); use a unique id`
|
|
12574
|
+
);
|
|
12575
|
+
}
|
|
12576
|
+
}
|
|
12577
|
+
for (const st of mutation.states ?? []) {
|
|
12578
|
+
if (!pending.entityIds.has(st.entityId)) {
|
|
12579
|
+
const entity = await getMemoryEntityVNext(db, ownerId, st.entityId);
|
|
12580
|
+
if (!entity) {
|
|
12581
|
+
throw new Error(
|
|
12582
|
+
`memory state ${st.id} references missing entity ${st.entityId} (owner ${ownerId})`
|
|
12583
|
+
);
|
|
12584
|
+
}
|
|
12585
|
+
}
|
|
12586
|
+
for (const evidenceId of st.evidenceIds) {
|
|
12587
|
+
if (!pending.evidenceIds.has(evidenceId)) {
|
|
12588
|
+
const ev = await getMemoryEvidenceVNext(db, ownerId, evidenceId);
|
|
12589
|
+
if (!ev) {
|
|
12590
|
+
throw new Error(
|
|
12591
|
+
`memory state ${st.id} references missing evidence ${evidenceId} (owner ${ownerId})`
|
|
12592
|
+
);
|
|
12593
|
+
}
|
|
12594
|
+
}
|
|
12595
|
+
}
|
|
12596
|
+
const existing = await getMemoryStateVNext(db, ownerId, st.id);
|
|
12597
|
+
if (existing) {
|
|
12598
|
+
if (existing.retiredAt) {
|
|
12599
|
+
throw new Error(
|
|
12600
|
+
`cannot update retired memory state ${st.id} (owner ${ownerId})`
|
|
12601
|
+
);
|
|
12602
|
+
}
|
|
12603
|
+
if (existing.entityId !== st.entityId || existing.facet !== st.facet) {
|
|
12604
|
+
throw new Error(
|
|
12605
|
+
`state ${st.id} already exists with different entity/facet (${existing.entityId}/${existing.facet} vs ${st.entityId}/${st.facet}); use supersede instead`
|
|
12606
|
+
);
|
|
12607
|
+
}
|
|
12608
|
+
}
|
|
12609
|
+
if (!existing) {
|
|
12610
|
+
const existingStates = await listMemoryStatesForEntityVNext(db, ownerId, st.entityId);
|
|
12611
|
+
for (const es of existingStates) {
|
|
12612
|
+
if (es.facet === st.facet && !es.retiredAt) {
|
|
12613
|
+
if (!supersededIds.has(es.id)) {
|
|
12614
|
+
throw new Error(
|
|
12615
|
+
`entity ${st.entityId} facet ${st.facet} already has current state ${es.id}; supersede it or use a different facet`
|
|
12616
|
+
);
|
|
12617
|
+
}
|
|
12618
|
+
}
|
|
12619
|
+
}
|
|
12620
|
+
}
|
|
12621
|
+
}
|
|
12622
|
+
for (const sid of mutation.supersededStateIds ?? []) {
|
|
12623
|
+
const existing = await getMemoryStateVNext(db, ownerId, sid);
|
|
12624
|
+
if (!existing) {
|
|
12625
|
+
throw new Error(
|
|
12626
|
+
`cannot supersede missing memory state: ${sid} (owner ${ownerId})`
|
|
12627
|
+
);
|
|
12628
|
+
}
|
|
12629
|
+
if (existing.retiredAt) {
|
|
12630
|
+
throw new Error(
|
|
12631
|
+
`cannot supersede already retired memory state: ${sid} (owner ${ownerId})`
|
|
12632
|
+
);
|
|
12633
|
+
}
|
|
12634
|
+
const replacement = (mutation.states ?? []).find(
|
|
12635
|
+
(st) => st.entityId === existing.entityId && st.facet === existing.facet
|
|
12636
|
+
);
|
|
12637
|
+
if (!replacement) {
|
|
12638
|
+
throw new Error(
|
|
12639
|
+
`superseded state ${sid} (entity ${existing.entityId} facet ${existing.facet}) has no replacement in this mutation`
|
|
12640
|
+
);
|
|
12641
|
+
}
|
|
12642
|
+
}
|
|
12643
|
+
for (const rel of mutation.relations ?? []) {
|
|
12644
|
+
for (const [side, ref] of [
|
|
12645
|
+
["from", rel.from],
|
|
12646
|
+
["to", rel.to]
|
|
12647
|
+
]) {
|
|
12648
|
+
if (pending.entityIds.has(ref) || pending.stateIds.has(ref) || pending.evidenceIds.has(ref)) {
|
|
12649
|
+
continue;
|
|
12650
|
+
}
|
|
12651
|
+
const resolved = await getMemoryEntityVNext(db, ownerId, ref) ?? await getMemoryStateVNext(db, ownerId, ref) ?? await getMemoryEvidenceVNext(db, ownerId, ref);
|
|
12652
|
+
if (!resolved) {
|
|
12653
|
+
throw new Error(
|
|
12654
|
+
`memory relation ${rel.id} references missing ${side} ${ref} (owner ${ownerId})`
|
|
12655
|
+
);
|
|
12656
|
+
}
|
|
12657
|
+
}
|
|
12658
|
+
}
|
|
12659
|
+
}
|
|
12660
|
+
var applyMemoryInterpreterMutation = async (db, ownerId, mutation) => {
|
|
12661
|
+
await validateMutation(db, ownerId, mutation);
|
|
12662
|
+
const batch = db.batch();
|
|
12663
|
+
for (const ev of mutation.evidence ?? []) {
|
|
12664
|
+
_appendEvidenceBatch(batch, ev);
|
|
12665
|
+
}
|
|
12666
|
+
for (const ent of mutation.entities ?? []) {
|
|
12667
|
+
_appendEntityBatch(batch, ent);
|
|
12668
|
+
}
|
|
12669
|
+
for (const st of mutation.states ?? []) {
|
|
12670
|
+
_appendStateBatch(batch, st);
|
|
12671
|
+
}
|
|
12672
|
+
for (const sid of mutation.supersededStateIds ?? []) {
|
|
12673
|
+
const existing = await getMemoryStateVNext(db, ownerId, sid);
|
|
12674
|
+
if (!existing) {
|
|
12675
|
+
throw new Error(
|
|
12676
|
+
`cannot supersede missing memory state: ${sid} (owner ${ownerId})`
|
|
12677
|
+
);
|
|
12678
|
+
}
|
|
12679
|
+
const replacement = (mutation.states ?? []).find(
|
|
12680
|
+
(st) => st.entityId === existing.entityId && st.facet === existing.facet
|
|
12681
|
+
);
|
|
12682
|
+
const retired = {
|
|
12683
|
+
...existing,
|
|
12684
|
+
retiredAt: replacement?.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
12685
|
+
};
|
|
12686
|
+
_appendRetiredStateBatch(batch, retired);
|
|
12687
|
+
}
|
|
12688
|
+
for (const rel of mutation.relations ?? []) {
|
|
12689
|
+
_appendRelationBatch(batch, rel);
|
|
12690
|
+
}
|
|
12691
|
+
await batch.write();
|
|
12692
|
+
};
|
|
12693
|
+
|
|
12694
|
+
// packages/ai/memory/vnext/legacyMigrationApply.ts
|
|
12695
|
+
var isSameLegacyMemoryEvidence = (left, right) => left.id === right.id && left.ownerId === right.ownerId && left.text === right.text && left.sourceRef === right.sourceRef && left.confidence === right.confidence && left.createdAt === right.createdAt;
|
|
12696
|
+
var applyLegacyMemoryEvidence = async (db, item) => {
|
|
12697
|
+
const incoming = buildLegacyMemoryEvidence(item);
|
|
12698
|
+
const existing = await getMemoryEvidenceVNextStrict(db, incoming.ownerId, incoming.id);
|
|
12699
|
+
if (existing) {
|
|
12700
|
+
return isSameLegacyMemoryEvidence(existing, incoming) ? { status: "already_exists", evidence: existing } : { status: "conflict", existing, incoming };
|
|
12701
|
+
}
|
|
12702
|
+
await putMemoryEvidenceVNext(db, incoming);
|
|
12703
|
+
return { status: "created", evidence: incoming };
|
|
12704
|
+
};
|
|
12705
|
+
|
|
12706
|
+
// packages/ai/memory/vnext/types.ts
|
|
12707
|
+
var MEMORY_ENTITY_TYPES = [
|
|
12708
|
+
"person",
|
|
12709
|
+
"organization",
|
|
12710
|
+
"project",
|
|
12711
|
+
"place",
|
|
12712
|
+
"object",
|
|
12713
|
+
"activity",
|
|
12714
|
+
"concept"
|
|
12715
|
+
];
|
|
12716
|
+
var MEMORY_RELATION_TYPES = [
|
|
12717
|
+
"related_to",
|
|
12718
|
+
"part_of",
|
|
12719
|
+
"uses",
|
|
12720
|
+
"involves",
|
|
12721
|
+
"supersedes"
|
|
12722
|
+
];
|
|
12723
|
+
|
|
12724
|
+
// packages/ai/memory/vnext/interpreterWireProtocol.ts
|
|
12725
|
+
var isObject = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
12726
|
+
var isString = (value) => typeof value === "string" && value.trim().length > 0;
|
|
12727
|
+
var isStringArray = (value) => Array.isArray(value) && value.every(isString);
|
|
12728
|
+
var optionalArray = (value, validate2) => value === void 0 || Array.isArray(value) && value.every(validate2);
|
|
12729
|
+
var ACTIONS = /* @__PURE__ */ new Set([
|
|
12730
|
+
"no_op",
|
|
12731
|
+
"create",
|
|
12732
|
+
"update",
|
|
12733
|
+
"specialize",
|
|
12734
|
+
"supersede",
|
|
12735
|
+
"ambiguous"
|
|
12736
|
+
]);
|
|
12737
|
+
var validateEvidence = (value) => {
|
|
12738
|
+
if (!isObject(value)) return false;
|
|
12739
|
+
return isString(value.key) && isString(value.text) && typeof value.confidence === "number" && Number.isFinite(value.confidence) && value.confidence >= 0 && value.confidence <= 1 && (value.sourceRef === void 0 || isString(value.sourceRef));
|
|
12740
|
+
};
|
|
12741
|
+
var validateEntity = (value) => {
|
|
12742
|
+
if (!isObject(value)) return false;
|
|
12743
|
+
return isString(value.key) && MEMORY_ENTITY_TYPES.includes(value.type) && isString(value.name) && (value.subtype === void 0 || isString(value.subtype)) && (value.aliases === void 0 || isStringArray(value.aliases));
|
|
12744
|
+
};
|
|
12745
|
+
var validateState = (value) => {
|
|
12746
|
+
if (!isObject(value)) return false;
|
|
12747
|
+
return (value.stateId === void 0 || isString(value.stateId)) && (value.supersedes === void 0 || isString(value.supersedes)) && isString(value.entityRef) && isString(value.facet) && "value" in value && isString(value.text) && isStringArray(value.evidenceRefs);
|
|
12748
|
+
};
|
|
12749
|
+
var validateRelation = (value) => {
|
|
12750
|
+
if (!isObject(value)) return false;
|
|
12751
|
+
return isString(value.fromRef) && MEMORY_RELATION_TYPES.includes(value.type) && isString(value.toRef);
|
|
12752
|
+
};
|
|
12753
|
+
var stripJsonFence = (raw) => {
|
|
12754
|
+
const trimmed = raw.trim();
|
|
12755
|
+
const match = trimmed.match(/^```(?:json)?\s*([\s\S]*?)\s*```$/i);
|
|
12756
|
+
return match ? match[1].trim() : trimmed;
|
|
12757
|
+
};
|
|
12758
|
+
var parseMemoryInterpreterWireMutation = (raw) => {
|
|
12759
|
+
let parsed;
|
|
12760
|
+
try {
|
|
12761
|
+
parsed = JSON.parse(stripJsonFence(raw));
|
|
12762
|
+
} catch {
|
|
12763
|
+
return { ok: false, error: "interpreter output is not valid JSON" };
|
|
12764
|
+
}
|
|
12765
|
+
if (!isObject(parsed)) return { ok: false, error: "interpreter output must be an object" };
|
|
12766
|
+
if (!isString(parsed.action) || !ACTIONS.has(parsed.action)) {
|
|
12767
|
+
return { ok: false, error: "invalid reconciliation action" };
|
|
12768
|
+
}
|
|
12769
|
+
if (!isString(parsed.reason)) return { ok: false, error: "reason is required" };
|
|
12770
|
+
if (!optionalArray(parsed.evidence, validateEvidence)) return { ok: false, error: "invalid evidence array" };
|
|
12771
|
+
if (!optionalArray(parsed.entities, validateEntity)) return { ok: false, error: "invalid entities array" };
|
|
12772
|
+
if (!optionalArray(parsed.states, validateState)) return { ok: false, error: "invalid states array" };
|
|
12773
|
+
if (!optionalArray(parsed.relations, validateRelation)) return { ok: false, error: "invalid relations array" };
|
|
12774
|
+
return { ok: true, value: parsed };
|
|
12775
|
+
};
|
|
12776
|
+
var buildMemoryInterpreterWireContract = () => `
|
|
12777
|
+
Return ONLY one JSON object:
|
|
12778
|
+
{
|
|
12779
|
+
"action": "no_op|create|update|specialize|supersede|ambiguous",
|
|
12780
|
+
"reason": "short explanation",
|
|
12781
|
+
"evidence": [{ "key": "e1", "text": "...", "confidence": 0.9, "sourceRef": "optional" }],
|
|
12782
|
+
"entities": [{ "key": "n1", "type": "person|organization|project|place|object|activity|concept", "name": "...", "subtype": "optional", "aliases": [] }],
|
|
12783
|
+
"states": [{ "stateId": "optional-existing-state-id", "supersedes": "optional-existing-state-id-this-statement-replaces", "entityRef": "existing-entity-id-or-new-entity-key", "facet": "...", "value": {}, "text": "...", "evidenceRefs": ["e1"] }],
|
|
12784
|
+
"relations": [{ "fromRef": "existing-id-or-local-key", "type": "related_to|part_of|uses|involves|supersedes", "toRef": "existing-id-or-local-key" }]
|
|
12785
|
+
}
|
|
12786
|
+
|
|
12787
|
+
Do not generate persistent ids, owner ids, timestamps or storage keys. Runtime owns identity and time.
|
|
12788
|
+
Use short local keys only to connect records created in the SAME response. Every local key must be unique across evidence/entities.
|
|
12789
|
+
State evidenceRefs may reference Evidence emitted in this response. Evidence ids marked referenceable in the supplied memory context may be referenced directly. Do not reference any other prior Evidence id.
|
|
12790
|
+
When updating an existing State, reuse its exact stateId, exact entityRef and exact facet. Runtime preserves that State's original entity/facet/createdAt and appends new Evidence provenance.
|
|
12791
|
+
When creating a new State, omit stateId.
|
|
12792
|
+
For supersede: emit the replacing statement as a NEW State (omit stateId) and set supersedes to the exact id of the replaced current State. Runtime retires the replaced State \u2014 it stays recoverable as history but is no longer current, and the new State becomes the only current one for that facet. Never update or supersede an already retired State.
|
|
12793
|
+
supersedes and stateId are mutually exclusive on one State.
|
|
12794
|
+
Do not emit an existing Entity again merely to update its State; reference its exact id in entityRef.
|
|
12795
|
+
Relations may reference only known persisted Entity/State/Evidence ids or local Entity/Evidence keys emitted in the same response.
|
|
12796
|
+
Do not invent new Entity or Relation types. Keep expressive detail in subtype/facet/value/text.
|
|
12797
|
+
`.trim();
|
|
12798
|
+
var assertUniqueLocalKeys = (wire) => {
|
|
12799
|
+
const seen = /* @__PURE__ */ new Set();
|
|
12800
|
+
for (const item of [...wire.evidence ?? [], ...wire.entities ?? []]) {
|
|
12801
|
+
if (seen.has(item.key)) throw new Error(`duplicate local key: ${item.key}`);
|
|
12802
|
+
seen.add(item.key);
|
|
12803
|
+
}
|
|
12804
|
+
};
|
|
12805
|
+
var materializeMemoryInterpreterMutation = (input) => {
|
|
12806
|
+
assertUniqueLocalKeys(input.wire);
|
|
12807
|
+
const now = input.now ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
12808
|
+
const nextId = input.nextId ?? ulid;
|
|
12809
|
+
const existingStates = new Map((input.existingStates ?? []).map((state2) => [state2.id, state2]));
|
|
12810
|
+
const existingStateIds = new Set(existingStates.keys());
|
|
12811
|
+
const existingEvidenceIds = new Set(
|
|
12812
|
+
[...existingStates.values()].flatMap((state2) => state2.evidenceIds)
|
|
12813
|
+
);
|
|
12814
|
+
const existingEntityIds = new Set(input.existingEntityIds ?? []);
|
|
12815
|
+
const entityRefs = /* @__PURE__ */ new Map();
|
|
12816
|
+
const evidenceRefs = /* @__PURE__ */ new Map();
|
|
12817
|
+
const evidence = (input.wire.evidence ?? []).map((item) => {
|
|
12818
|
+
const id = nextId();
|
|
12819
|
+
evidenceRefs.set(item.key, id);
|
|
12820
|
+
return {
|
|
12821
|
+
id,
|
|
12822
|
+
ownerId: input.ownerId,
|
|
12823
|
+
text: item.text,
|
|
12824
|
+
...item.sourceRef ? { sourceRef: item.sourceRef } : {},
|
|
12825
|
+
confidence: item.confidence,
|
|
12826
|
+
createdAt: now
|
|
12827
|
+
};
|
|
12828
|
+
});
|
|
12829
|
+
const entities = (input.wire.entities ?? []).map((item) => {
|
|
12830
|
+
const id = nextId();
|
|
12831
|
+
entityRefs.set(item.key, id);
|
|
12832
|
+
return {
|
|
12833
|
+
id,
|
|
12834
|
+
ownerId: input.ownerId,
|
|
12835
|
+
type: item.type,
|
|
12836
|
+
name: item.name,
|
|
12837
|
+
...item.subtype ? { subtype: item.subtype } : {},
|
|
12838
|
+
...item.aliases ? { aliases: item.aliases } : {},
|
|
12839
|
+
createdAt: now,
|
|
12840
|
+
updatedAt: now
|
|
12841
|
+
};
|
|
12842
|
+
});
|
|
12843
|
+
const resolveEntityRef = (ref) => {
|
|
12844
|
+
const created = entityRefs.get(ref);
|
|
12845
|
+
if (created) return created;
|
|
12846
|
+
if (existingEntityIds.has(ref)) return ref;
|
|
12847
|
+
throw new Error(`unknown entity ref: ${ref}`);
|
|
12848
|
+
};
|
|
12849
|
+
const supersededStateIds = [];
|
|
12850
|
+
const referenceableEvidenceIds = new Set(input.referenceableEvidenceIds ?? []);
|
|
12851
|
+
const resolveEvidenceRef = (ref) => {
|
|
12852
|
+
const created = evidenceRefs.get(ref);
|
|
12853
|
+
if (created) return created;
|
|
12854
|
+
if (referenceableEvidenceIds.has(ref)) return ref;
|
|
12855
|
+
throw new Error(`unknown evidence ref: ${ref}`);
|
|
12856
|
+
};
|
|
12857
|
+
const states = (input.wire.states ?? []).map((item) => {
|
|
12858
|
+
const prior = item.stateId ? existingStates.get(item.stateId) : void 0;
|
|
12859
|
+
if (item.stateId && !prior) {
|
|
12860
|
+
throw new Error(`unknown existing state: ${item.stateId}`);
|
|
12861
|
+
}
|
|
12862
|
+
if (prior?.retiredAt) {
|
|
12863
|
+
throw new Error(`retired state cannot be updated: ${item.stateId}`);
|
|
12864
|
+
}
|
|
12865
|
+
if (prior && item.entityRef !== prior.entityId) {
|
|
12866
|
+
throw new Error(`existing state entityRef changed: ${item.stateId}`);
|
|
12867
|
+
}
|
|
12868
|
+
if (prior && item.facet !== prior.facet) {
|
|
12869
|
+
throw new Error(`existing state facet changed: ${item.stateId}`);
|
|
12870
|
+
}
|
|
12871
|
+
let supersededStateId;
|
|
12872
|
+
if (item.supersedes !== void 0) {
|
|
12873
|
+
if (input.wire.action !== "supersede") {
|
|
12874
|
+
throw new Error(
|
|
12875
|
+
`supersedes is only valid for the supersede action, got ${input.wire.action}`
|
|
12876
|
+
);
|
|
12877
|
+
}
|
|
12878
|
+
if (item.stateId !== void 0) {
|
|
12879
|
+
throw new Error("supersedes and stateId are mutually exclusive on one state");
|
|
12880
|
+
}
|
|
12881
|
+
const superseded = existingStates.get(item.supersedes);
|
|
12882
|
+
if (!superseded) {
|
|
12883
|
+
throw new Error(`unknown superseded state id: ${item.supersedes}`);
|
|
12884
|
+
}
|
|
12885
|
+
if (superseded.retiredAt) {
|
|
12886
|
+
throw new Error(`retired state cannot be superseded: ${item.supersedes}`);
|
|
12887
|
+
}
|
|
12888
|
+
if (supersededStateIds.includes(item.supersedes)) {
|
|
12889
|
+
throw new Error(`duplicate superseded state id: ${item.supersedes}`);
|
|
12890
|
+
}
|
|
12891
|
+
supersededStateId = item.supersedes;
|
|
12892
|
+
}
|
|
12893
|
+
const newEvidenceIds = item.evidenceRefs.map(resolveEvidenceRef);
|
|
12894
|
+
const id = prior?.id ?? nextId();
|
|
12895
|
+
if (supersededStateId !== void 0) supersededStateIds.push(supersededStateId);
|
|
12896
|
+
return {
|
|
12897
|
+
id,
|
|
12898
|
+
ownerId: input.ownerId,
|
|
12899
|
+
entityId: prior?.entityId ?? resolveEntityRef(item.entityRef),
|
|
12900
|
+
facet: prior?.facet ?? item.facet,
|
|
12901
|
+
value: item.value,
|
|
12902
|
+
text: item.text,
|
|
12903
|
+
evidenceIds: [.../* @__PURE__ */ new Set([...prior?.evidenceIds ?? [], ...newEvidenceIds])],
|
|
12904
|
+
createdAt: prior?.createdAt ?? now,
|
|
12905
|
+
updatedAt: now
|
|
12906
|
+
};
|
|
12907
|
+
});
|
|
12908
|
+
const resolveRelationRef = (ref) => {
|
|
12909
|
+
const createdEntity = entityRefs.get(ref);
|
|
12910
|
+
if (createdEntity) return createdEntity;
|
|
12911
|
+
const createdEvidence = evidenceRefs.get(ref);
|
|
12912
|
+
if (createdEvidence) return createdEvidence;
|
|
12913
|
+
if (existingEntityIds.has(ref) || existingStateIds.has(ref) || existingEvidenceIds.has(ref)) {
|
|
12914
|
+
return ref;
|
|
12915
|
+
}
|
|
12916
|
+
throw new Error(`unknown relation ref: ${ref}`);
|
|
12917
|
+
};
|
|
12918
|
+
const relations = (input.wire.relations ?? []).map((item) => ({
|
|
12919
|
+
id: nextId(),
|
|
12920
|
+
ownerId: input.ownerId,
|
|
12921
|
+
from: resolveRelationRef(item.fromRef),
|
|
12922
|
+
type: item.type,
|
|
12923
|
+
to: resolveRelationRef(item.toRef),
|
|
12924
|
+
createdAt: now
|
|
12925
|
+
}));
|
|
12926
|
+
return {
|
|
12927
|
+
action: input.wire.action,
|
|
12928
|
+
reason: input.wire.reason,
|
|
12929
|
+
...evidence.length ? { evidence } : {},
|
|
12930
|
+
...entities.length ? { entities } : {},
|
|
12931
|
+
...states.length ? { states } : {},
|
|
12932
|
+
...supersededStateIds.length ? { supersededStateIds } : {},
|
|
12933
|
+
...relations.length ? { relations } : {}
|
|
12934
|
+
};
|
|
12935
|
+
};
|
|
12936
|
+
|
|
12937
|
+
// packages/ai/memory/vnext/interpreterPrompt.ts
|
|
12938
|
+
var MEMORY_VNEXT_ENTITY_CREATION_CONTRACT = `
|
|
12939
|
+
Entity creation is NOT named-entity recognition.
|
|
12940
|
+
|
|
12941
|
+
Create a new long-lived Entity only when the subject has future continuity value.
|
|
12942
|
+
A mention alone is insufficient.
|
|
12943
|
+
|
|
12944
|
+
Prefer leaving information as Evidence until at least one strong continuity signal exists:
|
|
12945
|
+
1. The subject recurs across independent dialogs, or the user explicitly describes it as enduring.
|
|
12946
|
+
2. The user connects it to their own preferences, relationships, goals, identity, worldview, ongoing work, or repeated activity.
|
|
12947
|
+
3. Future conversations are likely to refer back to it under different wording, so a stable anchor materially improves cross-dialog continuity.
|
|
12948
|
+
4. Creating the anchor is necessary to update or relate existing long-lived State.
|
|
12949
|
+
|
|
12950
|
+
Do NOT create an Entity merely because the text contains a named person, product, place, historical event, book, philosopher, food, device, or concept.
|
|
12951
|
+
When uncertain, keep Evidence and defer Entity creation.
|
|
12952
|
+
|
|
12953
|
+
Concept-specific rule:
|
|
12954
|
+
- concept is for abstract subjects that become part of the user's personal meaning world, such as freedom, absurdism, privacy, modernity, beauty, loneliness, safety, or maintainability.
|
|
12955
|
+
- Do not create a Concept Entity for every topic discussed or external fact queried.
|
|
12956
|
+
- Promote a concept only when it recurs, carries a durable user stance/interest/tension, connects multiple memories, or is likely to become a future recall/navigation anchor.
|
|
12957
|
+
- A one-off question such as "when was Kant born?" should normally create no long-lived Concept or Person Entity. Repeated discussion about Kant, freedom, and the user's own values may justify them.
|
|
12958
|
+
`.trim();
|
|
12959
|
+
var MEMORY_VNEXT_THIRD_PARTY_RELEVANCE_CONTRACT = `
|
|
12960
|
+
Third-party relevance test:
|
|
12961
|
+
- A fact about another person is durable only when it concerns the user's own world. Observation-only third-party facts \u2014 someone's appearance, news, habits, or the doings of a person the user merely encounters \u2014 stay Evidence, no matter how often they recur.
|
|
12962
|
+
- Closeness of that person, and repeated mentions across independent dialogs, do not by themselves make such an observation durable: never invent a user-world consequence to justify promotion (for example "the user keeps watching this person").
|
|
12963
|
+
- Matters that are part of the user's own shared life \u2014 household or family arrangements the user takes part in, a family member's health, or what the user relies on someone for \u2014 do belong to the user's world: state the user-world side (caregiving, changed time, changed plans, a sustained constraint) instead of a chronicle of the other person's doings.
|
|
12964
|
+
`.trim();
|
|
12965
|
+
var MEMORY_VNEXT_RECONCILIATION_CONTRACT = `
|
|
12966
|
+
When durable understanding changes, choose the smallest correct reconciliation:
|
|
12967
|
+
- no_op: no durable change.
|
|
12968
|
+
- create: genuinely new durable state/entity.
|
|
12969
|
+
- update: advance an existing state without changing its scope.
|
|
12970
|
+
- specialize: add a scoped exception/qualification; do not replace the broader state.
|
|
12971
|
+
- supersede: a newer statement explicitly replaces old current state. Emit the replacement as a NEW State and name the replaced current State in its supersedes field; runtime retires the old one (kept as recoverable history, no longer current).
|
|
12972
|
+
- ambiguous: evidence conflicts with current state, but replacement vs exception cannot be determined reliably.
|
|
12973
|
+
|
|
12974
|
+
Examples:
|
|
12975
|
+
- "\u56DE\u7B54\u7B80\u5355" then "\u5B89\u5168\u548C bug \u6392\u67E5\u8BE6\u7EC6" => specialize, not supersede.
|
|
12976
|
+
- "\u6211\u6709 Ollama Pro" then "\u6211\u5DF2\u7ECF\u4E0D\u7528 Ollama Pro \u4E86" => supersede.
|
|
12977
|
+
- Repeatedly choosing thin noodles without explicitly rejecting thick noodles => update or ambiguous, not automatic supersession.
|
|
12978
|
+
|
|
12979
|
+
Preserve ambiguity. Do not ask the user merely to clean memory. A later task may ask only if the unresolved state materially changes the answer.
|
|
12980
|
+
`.trim();
|
|
12981
|
+
var buildMemoryVNextInterpreterPrompt = () => [
|
|
12982
|
+
"You maintain long-lived adaptive relationship memory backed by evidence.",
|
|
12983
|
+
"External dialogs/files/web facts remain authoritative outside memory.",
|
|
12984
|
+
"Prefer a small stable set of Entities and updateable States over an ever-growing bag of facts.",
|
|
12985
|
+
MEMORY_VNEXT_ENTITY_CREATION_CONTRACT,
|
|
12986
|
+
MEMORY_VNEXT_THIRD_PARTY_RELEVANCE_CONTRACT,
|
|
12987
|
+
MEMORY_VNEXT_RECONCILIATION_CONTRACT,
|
|
12988
|
+
buildMemoryInterpreterWireContract()
|
|
12989
|
+
].join("\n\n");
|
|
12990
|
+
|
|
12991
|
+
// packages/ai/memory/vnext/legacyMigrationShadow.ts
|
|
12992
|
+
var LEGACY_MIGRATION_SHADOW_INSTRUCTION = `
|
|
12993
|
+
This Evidence came from a legacy memory record.
|
|
12994
|
+
Legacy kind and subject metadata are advisory hints only.
|
|
12995
|
+
Re-evaluate it under the current vNext contract.
|
|
12996
|
+
Do not mechanically map:
|
|
12997
|
+
- semantic -> State
|
|
12998
|
+
- procedural -> procedure State
|
|
12999
|
+
- subjectType=agent -> agent Entity
|
|
13000
|
+
- visibility -> scope
|
|
13001
|
+
Prefer Evidence-only when durable semantic value is unclear.
|
|
13002
|
+
`.trim();
|
|
13003
|
+
var serializeExisting = (existing) => JSON.stringify({
|
|
13004
|
+
entityIds: existing?.entityIds ?? [],
|
|
13005
|
+
states: (existing?.states ?? []).map((state2) => ({
|
|
13006
|
+
stateId: state2.id,
|
|
13007
|
+
entityId: state2.entityId,
|
|
13008
|
+
facet: state2.facet,
|
|
13009
|
+
text: state2.text
|
|
13010
|
+
}))
|
|
13011
|
+
});
|
|
13012
|
+
var buildLegacyMigrationInterpreterInput = (input) => [
|
|
13013
|
+
LEGACY_MIGRATION_SHADOW_INSTRUCTION,
|
|
13014
|
+
`The legacy record's Evidence is marked referenceable with id "${input.evidence.id}" and sourceRef "${input.evidence.sourceRef}". Evidence ids marked referenceable in the supplied memory context may be referenced directly. When a State cites it, reference that exact id in evidenceRefs. Do not emit another Evidence for this legacy record.`,
|
|
13015
|
+
`Imported Evidence (text is the authoritative legacy content, referenceable directly):
|
|
13016
|
+
${JSON.stringify(
|
|
13017
|
+
{
|
|
13018
|
+
...input.evidence,
|
|
13019
|
+
referenceable: true
|
|
13020
|
+
},
|
|
13021
|
+
null,
|
|
13022
|
+
2
|
|
13023
|
+
)}`,
|
|
13024
|
+
`Legacy metadata (advisory hints only, NOT vNext semantics):
|
|
13025
|
+
${JSON.stringify(
|
|
13026
|
+
{
|
|
13027
|
+
kind: input.item.kind,
|
|
13028
|
+
visibility: input.item.visibility,
|
|
13029
|
+
subjectType: input.item.subjectType,
|
|
13030
|
+
subjectId: input.item.subjectId,
|
|
13031
|
+
facet: input.item.facet,
|
|
13032
|
+
importance: input.item.importance,
|
|
13033
|
+
resident: input.item.resident
|
|
13034
|
+
},
|
|
13035
|
+
null,
|
|
13036
|
+
2
|
|
13037
|
+
)}`,
|
|
13038
|
+
`Existing vNext context for this principal (caller-supplied shadow snapshot):
|
|
13039
|
+
${serializeExisting(
|
|
13040
|
+
input.existing
|
|
13041
|
+
)}`
|
|
13042
|
+
].join("\n\n");
|
|
13043
|
+
var mergeImportedEvidence = (mutation, imported) => {
|
|
13044
|
+
const emitted = mutation.evidence ?? [];
|
|
13045
|
+
const duplicatedIds = new Set(
|
|
13046
|
+
emitted.filter(
|
|
13047
|
+
(item) => item.sourceRef === imported.sourceRef || // A re-emitted copy that drops sourceRef is still the same legacy record:
|
|
13048
|
+
// text equality is the only identity left on the wire to catch it.
|
|
13049
|
+
item.sourceRef === void 0 && item.text === imported.text
|
|
13050
|
+
).map((item) => item.id)
|
|
13051
|
+
);
|
|
13052
|
+
const rewrite = (id) => duplicatedIds.has(id) ? imported.id : id;
|
|
13053
|
+
return {
|
|
13054
|
+
...mutation,
|
|
13055
|
+
evidence: [imported, ...emitted.filter((item) => !duplicatedIds.has(item.id))],
|
|
13056
|
+
...mutation.states ? {
|
|
13057
|
+
states: mutation.states.map((state2) => ({
|
|
13058
|
+
...state2,
|
|
13059
|
+
evidenceIds: [...new Set(state2.evidenceIds.map(rewrite))]
|
|
13060
|
+
}))
|
|
13061
|
+
} : {},
|
|
13062
|
+
...mutation.relations ? {
|
|
13063
|
+
relations: mutation.relations.map((relation) => ({
|
|
13064
|
+
...relation,
|
|
13065
|
+
from: rewrite(relation.from),
|
|
13066
|
+
to: rewrite(relation.to)
|
|
13067
|
+
}))
|
|
13068
|
+
} : {}
|
|
13069
|
+
};
|
|
13070
|
+
};
|
|
13071
|
+
var runLegacyMemoryMigrationShadow = async (input) => {
|
|
13072
|
+
const principal = resolveLegacyMemoryPrincipal(input.item);
|
|
13073
|
+
const evidence = buildLegacyMemoryEvidence(input.item);
|
|
13074
|
+
const completion = await input.provider.complete(
|
|
13075
|
+
[
|
|
13076
|
+
{ role: "system", content: buildMemoryVNextInterpreterPrompt() },
|
|
13077
|
+
{
|
|
13078
|
+
role: "user",
|
|
13079
|
+
content: buildLegacyMigrationInterpreterInput({
|
|
13080
|
+
item: input.item,
|
|
13081
|
+
evidence,
|
|
13082
|
+
...input.existing ? { existing: input.existing } : {}
|
|
13083
|
+
})
|
|
13084
|
+
}
|
|
13085
|
+
],
|
|
13086
|
+
input.timeoutMs === void 0 ? void 0 : { timeoutMs: input.timeoutMs }
|
|
13087
|
+
);
|
|
13088
|
+
const parsed = parseMemoryInterpreterWireMutation(completion.content);
|
|
13089
|
+
if (!parsed.ok) {
|
|
13090
|
+
throw new Error(`legacy migration shadow: unparsable interpreter response (${parsed.error})`);
|
|
13091
|
+
}
|
|
13092
|
+
const candidate = materializeMemoryInterpreterMutation({
|
|
13093
|
+
// The principal identity (user:/space:/system:<id>) is the migration owner
|
|
13094
|
+
// space, so a space migration can never land in a user space.
|
|
13095
|
+
ownerId: evidence.ownerId,
|
|
13096
|
+
wire: parsed.value,
|
|
13097
|
+
...input.existing?.states ? { existingStates: [...input.existing.states] } : {},
|
|
13098
|
+
...input.existing?.entityIds ? { existingEntityIds: [...input.existing.entityIds] } : {},
|
|
13099
|
+
referenceableEvidenceIds: [evidence.id],
|
|
13100
|
+
...input.now === void 0 ? {} : { now: input.now },
|
|
13101
|
+
...input.nextId ? { nextId: input.nextId } : {}
|
|
13102
|
+
});
|
|
13103
|
+
const mutation = mergeImportedEvidence(candidate, evidence);
|
|
13104
|
+
return {
|
|
13105
|
+
principal,
|
|
13106
|
+
evidence,
|
|
13107
|
+
wire: parsed.value,
|
|
13108
|
+
mutation,
|
|
13109
|
+
action: mutation.action,
|
|
13110
|
+
reason: mutation.reason
|
|
13111
|
+
};
|
|
13112
|
+
};
|
|
13113
|
+
|
|
13114
|
+
// packages/ai/memory/vnext/lazyPromotion.ts
|
|
13115
|
+
var ERROR_MESSAGE_MAX2 = 120;
|
|
13116
|
+
var inFlight = /* @__PURE__ */ new Set();
|
|
13117
|
+
var shortError2 = (error) => {
|
|
13118
|
+
const message = error instanceof Error ? `${error.name}: ${error.message}` : String(error);
|
|
13119
|
+
return message.length > ERROR_MESSAGE_MAX2 ? `${message.slice(0, ERROR_MESSAGE_MAX2)}\u2026` : message;
|
|
13120
|
+
};
|
|
13121
|
+
var loadExistingContext = async (db, ownerId) => {
|
|
13122
|
+
const entities = await listMemoryEntitiesVNext(db, ownerId);
|
|
13123
|
+
const states = (await Promise.all(
|
|
13124
|
+
entities.map((entity) => listMemoryStatesForEntityVNext(db, ownerId, entity.id))
|
|
13125
|
+
)).flat();
|
|
13126
|
+
return {
|
|
13127
|
+
entityIds: entities.map((entity) => entity.id),
|
|
13128
|
+
states
|
|
13129
|
+
};
|
|
13130
|
+
};
|
|
13131
|
+
var withoutImportedEvidence = (mutation, importedEvidenceId) => ({
|
|
13132
|
+
...mutation,
|
|
13133
|
+
evidence: (mutation.evidence ?? []).filter((evidence) => evidence.id !== importedEvidenceId)
|
|
13134
|
+
});
|
|
13135
|
+
var hasWrites = (mutation) => (mutation.evidence?.length ?? 0) > 0 || (mutation.entities?.length ?? 0) > 0 || (mutation.states?.length ?? 0) > 0 || (mutation.supersededStateIds?.length ?? 0) > 0 || (mutation.relations?.length ?? 0) > 0;
|
|
13136
|
+
var runMemoryVNextLazyPromotion = async (input) => {
|
|
13137
|
+
const clock = input.clock ?? (() => performance.now());
|
|
13138
|
+
const startedAt = clock();
|
|
13139
|
+
const emit = input.emit ?? ((observation) => console.info("[memory] vnext lazy promotion", {
|
|
13140
|
+
event: "memory_vnext_lazy_promotion",
|
|
13141
|
+
...observation
|
|
13142
|
+
}));
|
|
13143
|
+
const finish = (partial) => {
|
|
13144
|
+
const observation = {
|
|
13145
|
+
...partial,
|
|
13146
|
+
latencyMs: Math.round((clock() - startedAt) * 10) / 10
|
|
13147
|
+
};
|
|
13148
|
+
try {
|
|
13149
|
+
emit(observation);
|
|
13150
|
+
} catch {
|
|
13151
|
+
}
|
|
13152
|
+
return observation;
|
|
13153
|
+
};
|
|
13154
|
+
const deterministicEvidence = buildLegacyMemoryEvidence(input.item);
|
|
13155
|
+
const flightKey = `${deterministicEvidence.ownerId}\0${deterministicEvidence.id}`;
|
|
13156
|
+
if (inFlight.has(flightKey)) {
|
|
13157
|
+
return finish({ status: "in_flight" });
|
|
13158
|
+
}
|
|
13159
|
+
inFlight.add(flightKey);
|
|
13160
|
+
try {
|
|
13161
|
+
const evidenceResult = await applyLegacyMemoryEvidence(input.db, input.item);
|
|
13162
|
+
if (evidenceResult.status === "conflict") {
|
|
13163
|
+
return finish({ status: "conflict" });
|
|
13164
|
+
}
|
|
13165
|
+
const evidence = evidenceResult.evidence;
|
|
13166
|
+
const existing = await loadExistingContext(input.db, evidence.ownerId);
|
|
13167
|
+
const alreadyCovered = (existing.states ?? []).some(
|
|
13168
|
+
(state2) => !state2.retiredAt && state2.evidenceIds.includes(evidence.id)
|
|
13169
|
+
);
|
|
13170
|
+
if (alreadyCovered) {
|
|
13171
|
+
return finish({ status: "already_covered" });
|
|
13172
|
+
}
|
|
13173
|
+
const interpreted = await runLegacyMemoryMigrationShadow({
|
|
13174
|
+
item: input.item,
|
|
13175
|
+
provider: input.provider,
|
|
13176
|
+
existing,
|
|
13177
|
+
...input.timeoutMs === void 0 ? {} : { timeoutMs: input.timeoutMs },
|
|
13178
|
+
...input.now === void 0 ? {} : { now: input.now },
|
|
13179
|
+
...input.nextId ? { nextId: input.nextId } : {}
|
|
13180
|
+
});
|
|
13181
|
+
const semanticMutation = withoutImportedEvidence(interpreted.mutation, evidence.id);
|
|
13182
|
+
if (!hasWrites(semanticMutation)) {
|
|
13183
|
+
return finish({ status: "no_op", action: semanticMutation.action });
|
|
13184
|
+
}
|
|
13185
|
+
await applyMemoryInterpreterMutation(input.db, evidence.ownerId, semanticMutation);
|
|
13186
|
+
return finish({ status: "promoted", action: semanticMutation.action });
|
|
13187
|
+
} catch (error) {
|
|
13188
|
+
return finish({ status: "error", error: shortError2(error) });
|
|
13189
|
+
} finally {
|
|
13190
|
+
inFlight.delete(flightKey);
|
|
13191
|
+
}
|
|
13192
|
+
};
|
|
13193
|
+
var isMemoryVNextLazyPromotionEnabled = (env = typeof process !== "undefined" ? process.env : {}) => env.NOLO_MEMORY_VNEXT_LAZY_PROMOTION === "1" || env.NOLO_MEMORY_VNEXT_LAZY_PROMOTION === "true";
|
|
13194
|
+
|
|
12343
13195
|
// packages/ai/memory/runtime.ts
|
|
12344
13196
|
var COLD_STORAGE_CONFIDENCE = 0.3;
|
|
12345
13197
|
var MEMORY_OVERLAY_TOKEN_BUDGET = DEFAULT_MEMORY_OVERLAY_TOKEN_BUDGET;
|
|
@@ -12506,6 +13358,17 @@ var resolveMemoryRuntime = async (input) => {
|
|
|
12506
13358
|
legacyContextChars: promptBlock?.length ?? 0
|
|
12507
13359
|
});
|
|
12508
13360
|
}
|
|
13361
|
+
const promotionCandidate = selected[0];
|
|
13362
|
+
const lazyPromotionEnabled = input.vNextShadowProvider != null && isMemoryVNextLazyPromotionEnabled();
|
|
13363
|
+
if (lazyPromotionEnabled && promotionCandidate) {
|
|
13364
|
+
void runMemoryVNextLazyPromotion({
|
|
13365
|
+
db: input.db,
|
|
13366
|
+
item: promotionCandidate,
|
|
13367
|
+
provider: input.vNextShadowProvider,
|
|
13368
|
+
...input.lazyPromotionEmit ? { emit: input.lazyPromotionEmit } : {}
|
|
13369
|
+
}).catch(() => {
|
|
13370
|
+
});
|
|
13371
|
+
}
|
|
12509
13372
|
if (selected.length === 0) {
|
|
12510
13373
|
return { selectedItems: [], promptBlock: null };
|
|
12511
13374
|
}
|