nolo-cli 0.252.0-alpha.3 → 0.253.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/{_executeModel-RXHY2BDR.js → _executeModel-VUXEWLLQ.js} +29 -29
- package/{addContentAction-F4XO3VRF.js → addContentAction-MT4BECXT.js} +6 -6
- package/{addDialogAgentAction-NSCVHTZJ.js → addDialogAgentAction-ZZTJ5GBD.js} +5 -5
- package/{agentDeleteCommand-OKR6IDGK.js → agentDeleteCommand-SU5IKIW3.js} +36 -36
- package/{agentEmailCommands-UKPURCCI.js → agentEmailCommands-SHLVY627.js} +36 -36
- package/{agentListCommands-CTY7WAMN.js → agentListCommands-3NTMYMVI.js} +16 -16
- package/{agentMachineCommands-WTCQHXHZ.js → agentMachineCommands-MYXLAKQF.js} +12 -11
- package/{agentRecordCommands-IM2WIFKB.js → agentRecordCommands-EIZTKSWW.js} +36 -36
- package/{agentRunCommand-7MCCRUJY.js → agentRunCommand-RB3EIT4I.js} +36 -36
- package/{agentRunControl-KNNDEEDI.js → agentRunControl-5ABAIBQT.js} +2 -2
- package/{agentRuntimeLocal-EOW6FFXL.js → agentRuntimeLocal-IO3GGTCJ.js} +7 -7
- package/{agentSlice-PVFGBJXB.js → agentSlice-TQVS23WV.js} +6 -6
- package/{appDeleteCommands-3VCRRWUX.js → appDeleteCommands-ZQ4ZEKTC.js} +13 -12
- package/{appDeployCommands-XN6IEMYK.js → appDeployCommands-4XT7PFW5.js} +13 -12
- package/{appDeployStatusCommands-ZSJJXMVR.js → appDeployStatusCommands-5RVMRYQW.js} +13 -12
- package/{appGetCommands-DJ7YQCEE.js → appGetCommands-VH5W3RFK.js} +13 -12
- package/{appListCommands-4KU5CV5H.js → appListCommands-TAHZLAL3.js} +13 -12
- package/{builtinSkillRegistry-PQWEXSFW.js → builtinSkillRegistry-66PEOD4Y.js} +1 -1
- package/{chunk-25GCVHBZ.js → chunk-25BDZGD7.js} +1 -1
- package/{chunk-2HF6DINU.js → chunk-2BJ53346.js} +6 -6
- package/{chunk-VZWYP7LD.js → chunk-2RCMFPUZ.js} +2 -2
- package/{chunk-OQOXDQLB.js → chunk-2VYX3ZCR.js} +3 -3
- package/{chunk-UDQZ5JT7.js → chunk-3SEBCWLD.js} +17394 -17306
- package/{chunk-NWZRCUHM.js → chunk-4AFKLWZP.js} +101 -192
- package/{chunk-GUFTHWDO.js → chunk-4BQ5QKIG.js} +9 -9
- package/{chunk-YWLMUFZ5.js → chunk-4GWNEPY6.js} +1 -1
- package/{chunk-GJ4UTSAW.js → chunk-53UOBNTI.js} +4 -4
- package/{chunk-V644LXPC.js → chunk-7STRX24O.js} +3 -3
- package/chunk-AIHNB5QH.js +1394 -0
- package/{chunk-BVCCRSGK.js → chunk-ANQ544EU.js} +5 -5
- package/{chunk-4KBKOG2L.js → chunk-CF7U32BX.js} +2 -2
- package/{chunk-MOAVLCCM.js → chunk-CMYZT2XN.js} +3 -3
- package/{chunk-U3ZK2MXG.js → chunk-CUQNRU4X.js} +3 -3
- package/{chunk-EQJK6LSN.js → chunk-D4CUS6NT.js} +3 -3
- package/{chunk-SBBSUBY3.js → chunk-DNY33GGQ.js} +1 -1
- package/{chunk-RE32BIKY.js → chunk-FZSGYLFV.js} +3 -3
- package/{chunk-N2ZAY2DK.js → chunk-GFXPPQZN.js} +1 -1
- package/{chunk-BTQU2PRC.js → chunk-GK772DEV.js} +1 -1
- package/{chunk-N7UXTVAR.js → chunk-HEQJ5XND.js} +1 -1
- package/{chunk-BLBGVSLB.js → chunk-HEUHCHAR.js} +5 -5
- package/{chunk-WNIBQBOR.js → chunk-HS4JGZQH.js} +1 -1
- package/{chunk-N2MDL5AZ.js → chunk-IRORRPH2.js} +9 -9
- package/chunk-JJABK3QO.js +321 -0
- package/{chunk-64ACTEAE.js → chunk-JKO32CCL.js} +1 -1
- package/{chunk-ZMXO5G3E.js → chunk-K4LLTJUO.js} +4 -2
- package/{chunk-MDWHMQON.js → chunk-M7GMJBQJ.js} +1 -1
- package/{chunk-FJPVVLP3.js → chunk-MARF3TN2.js} +4 -4
- package/{chunk-KO6JNZCF.js → chunk-MPOUZIF4.js} +21 -8
- package/{chunk-WJOC3AEM.js → chunk-MRYKRL2V.js} +1 -1
- package/{chunk-Z47UZT27.js → chunk-NMGG3NUB.js} +1 -1
- package/{chunk-EPBEZKYK.js → chunk-O3WZMJAN.js} +2 -2
- package/{chunk-3LL5HRIJ.js → chunk-OLS2J3WE.js} +1 -1
- package/{chunk-7XO73H5X.js → chunk-P4JX7YMQ.js} +1 -1
- package/{chunk-Q5M27DUE.js → chunk-PR25J652.js} +1 -1
- package/{chunk-JX2IG37T.js → chunk-PTY2VZM5.js} +1 -1
- package/{chunk-OTNPEE4G.js → chunk-SID2TFMV.js} +87 -63
- package/{chunk-26KL6533.js → chunk-TI2JIXK4.js} +18 -18
- package/{chunk-RGWYRTSY.js → chunk-TOHMK27J.js} +21 -23
- package/{chunk-SE7UURHT.js → chunk-UHTT23PH.js} +12 -12
- package/{chunk-IQXMWBI6.js → chunk-UMI4NNZP.js} +2 -2
- package/{chunk-CSTCYYCR.js → chunk-VKAITWPC.js} +9 -9
- package/{chunk-UGHNYYOE.js → chunk-VPSPVLCM.js} +2 -2
- package/{chunk-OTOPQXP5.js → chunk-XWR2YD4L.js} +1 -1
- package/{chunk-K7RWY7JH.js → chunk-YQYSQUP3.js} +7 -7
- package/{chunk-ZMWDHPNG.js → chunk-Z2ZCKNKX.js} +1 -5
- package/{cliLocalAgentRecordReader-OHAC4JTY.js → cliLocalAgentRecordReader-2WBUVRVD.js} +9 -9
- package/{commandRegistry-YSV6ZWPO.js → commandRegistry-JDCGWIWD.js} +46 -117
- package/{contentThunks-GSMUNWBA.js → contentThunks-B6BY7GS3.js} +11 -11
- package/{createAgentAutomationAction-RMADR4LG.js → createAgentAutomationAction-TQ6IA5SV.js} +11 -11
- package/{createDialogAction-CM5CBQVH.js → createDialogAction-QKMGD2TS.js} +12 -12
- package/{createPageAction-JMGVMCTH.js → createPageAction-7EEVGWGG.js} +12 -12
- package/{dbSlice-Q637QR4L.js → dbSlice-HXFRXGI3.js} +5 -5
- package/{deleteFile-TP6MKFUX.js → deleteFile-QDSZVTUJ.js} +3 -3
- package/{dialogCommands-IZSD4CQM.js → dialogCommands-MEH4CVRL.js} +15 -14
- package/{dialogSlice-ARQKXXTD.js → dialogSlice-6WIME53P.js} +9 -9
- package/{docCreateCommands-ZJFHCZV4.js → docCreateCommands-MVAYVGQ5.js} +12 -11
- package/{docDeleteCommands-LY5MF2BI.js → docDeleteCommands-TKXPRA3O.js} +13 -12
- package/{docReadCommands-4X2DHCNZ.js → docReadCommands-MR2YKCZP.js} +12 -11
- package/{docStore-QWRVKIRI.js → docStore-VEHQHXRM.js} +6 -6
- package/{docUpdateCommands-5TIT7DAJ.js → docUpdateCommands-VJ6A6F7F.js} +12 -11
- package/{handleSendMessageAction-TVR55KVT.js → handleSendMessageAction-X5LGNJX5.js} +22 -22
- package/{hostCredentialCreate-T33O7WLA.js → hostCredentialCreate-AQYSWUKA.js} +36 -36
- package/index.js +4 -4
- package/{localRuntimeAdapter-CNFP7ZEP.js → localRuntimeAdapter-FA4OGZGU.js} +35 -35
- package/{machineCommands-TGA5EH2G.js → machineCommands-VKU6MAFA.js} +36 -36
- package/{machineWsRunDispatch-LMJPGTTZ.js → machineWsRunDispatch-XQQHHOX4.js} +36 -36
- package/{memberThunks-IGYRMEQC.js → memberThunks-ZXEUM6DH.js} +7 -7
- package/package.json +1 -1
- package/{projectArchive-Q46BYZQ6.js → projectArchive-674NJOYI.js} +12 -12
- package/{read-MPPXZHAO.js → read-T5WPCAY7.js} +3 -3
- package/{readDocTool-PKZ35PCR.js → readDocTool-DW4DCRQG.js} +1 -1
- package/{readlineWorkspace-HA6DWK4N.js → readlineWorkspace-HFPEDOHN.js} +46 -64
- package/{removeDialogAgentAction-H6S7VLNA.js → removeDialogAgentAction-MXJEB77K.js} +6 -6
- package/{runAgentClientLoop-WZJ4HXOH.js → runAgentClientLoop-NU3JNHSH.js} +27 -27
- package/{setDialogExtraReferencesAction-CARUTAWS.js → setDialogExtraReferencesAction-BILVMHM7.js} +6 -6
- package/{setPrimaryDialogAgentAction-VRV56MLG.js → setPrimaryDialogAgentAction-CUBBWACR.js} +6 -6
- package/{settingThunks-4FC4HXGN.js → settingThunks-BRBBAGEK.js} +5 -5
- package/{spaceCommands-27Z5JAU3.js → spaceCommands-K4HHG7OO.js} +12 -11
- package/{streamAgentChatTurn-JKMBFM2O.js → streamAgentChatTurn-7FDXIRMB.js} +35 -35
- package/{switchDialogAgentAction-O236K6HB.js → switchDialogAgentAction-SSI2CSNE.js} +5 -5
- package/{tools-4RFLNHUW.js → tools-GC45557U.js} +23 -23
- package/{tuiRestart-GF4DGAAN.js → tuiRestart-7IKI6JZK.js} +3 -3
- package/{updateDialogTitleAction-F3ONQM3N.js → updateDialogTitleAction-OAC5MWMS.js} +11 -11
- package/chunk-CGSIW2KI.js +0 -594
- package/chunk-HF4C5WIU.js +0 -980
- package/chunk-U5LOKQ2R.js +0 -176
- package/{chunk-REINTCQF.js → chunk-4CL6QIQZ.js} +3 -3
- package/{chunk-5BRVDQTX.js → chunk-KWARDHBI.js} +7 -7
package/chunk-HF4C5WIU.js
DELETED
|
@@ -1,980 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
fnv1a32Hex
|
|
3
|
-
} from "./chunk-UEILX4EV.js";
|
|
4
|
-
import {
|
|
5
|
-
DISPATCH_TIER_RANK,
|
|
6
|
-
compareAgentSelection,
|
|
7
|
-
resolveAgentSelectionPriority,
|
|
8
|
-
resolveModelTier
|
|
9
|
-
} from "./chunk-ZMXO5G3E.js";
|
|
10
|
-
import {
|
|
11
|
-
DEFAULT_PROVIDER_RETRY_MS,
|
|
12
|
-
isAgentUnavailableNow,
|
|
13
|
-
isSubscriptionPeriodWindow,
|
|
14
|
-
resolveAgentAvailability
|
|
15
|
-
} from "./chunk-LS5KAVFQ.js";
|
|
16
|
-
import {
|
|
17
|
-
isOAuthApiKeyRef
|
|
18
|
-
} from "./chunk-UKZX3NHN.js";
|
|
19
|
-
import {
|
|
20
|
-
isOwnedAgentKey,
|
|
21
|
-
ownedAgentKey,
|
|
22
|
-
publicAgentKey
|
|
23
|
-
} from "./chunk-M2EJHDJP.js";
|
|
24
|
-
import {
|
|
25
|
-
isAntigravityOAuthAgent,
|
|
26
|
-
isSubscriptionEndpoint,
|
|
27
|
-
isSubscriptionOAuthCredential
|
|
28
|
-
} from "./chunk-6SOWMEAY.js";
|
|
29
|
-
import {
|
|
30
|
-
asTrimmedLowercaseString
|
|
31
|
-
} from "./chunk-QSJ3HFEF.js";
|
|
32
|
-
|
|
33
|
-
// packages/core/gptProTier.ts
|
|
34
|
-
var GPT_PRO_REQUIRED_RECHARGE_AMOUNT = 199;
|
|
35
|
-
var SUPPORTED_TIER_PROVIDERS = /* @__PURE__ */ new Set([
|
|
36
|
-
"nolo",
|
|
37
|
-
"openai",
|
|
38
|
-
"deepinfra"
|
|
39
|
-
]);
|
|
40
|
-
var CLAUDE_PREMIUM_RE = /^(?:anthropic\/)?claude-(opus|fable)(?:-\d+(?:[.-]\d+)*(?:-[a-z0-9]+)*)?$/i;
|
|
41
|
-
var GPT_PRO_RE = /^(?:openai\/)?gpt-[a-z0-9.-]+-pro(?:-[a-z0-9]+(?:[.-][a-z0-9]+)*)?$/i;
|
|
42
|
-
var GPT_SOL_RE = /^(?:openai\/)?gpt-\d+(?:\.\d+)*-sol(?:-[a-z0-9]+(?:[.-][a-z0-9]+)*)?$/i;
|
|
43
|
-
var GPT_ASTRA_RE = /^(?:openai\/)?gpt-\d+(?:\.\d+)*-astra(?:-[a-z0-9]+(?:[.-][a-z0-9]+)*)?$/i;
|
|
44
|
-
var KIMI_K3_MODELS = /* @__PURE__ */ new Set([
|
|
45
|
-
"kimi-k3",
|
|
46
|
-
"moonshotai/kimi-k3",
|
|
47
|
-
// 2026-11-18:K3 由 K3.1 Pro 接替(目录换成 kimi-k3.1-pro),旗舰档门槛保持一致 —
|
|
48
|
-
// 不因换代把 199 档位约束漏掉。
|
|
49
|
-
"kimi-k3.1-pro",
|
|
50
|
-
"moonshotai/kimi-k3.1-pro",
|
|
51
|
-
// 旧 K2.6 经 PLATFORM_MODEL_ALIASES 执行同一 K3.1 Pro 上游与计费:档位判定按
|
|
52
|
-
// 请求 id 直查,不带这一条就会出现「换个旧 id 绕过 premium 门槛」。
|
|
53
|
-
"kimi-k2.6",
|
|
54
|
-
"moonshotai/kimi-k2.6"
|
|
55
|
-
]);
|
|
56
|
-
function classifyPremiumModel(model) {
|
|
57
|
-
const normalizedModel = asTrimmedLowercaseString(model);
|
|
58
|
-
if (!normalizedModel) return void 0;
|
|
59
|
-
const claudeMatch = CLAUDE_PREMIUM_RE.exec(normalizedModel);
|
|
60
|
-
if (claudeMatch) {
|
|
61
|
-
return claudeMatch[1].toLowerCase() === "opus" ? "claude-opus" : "claude-fable";
|
|
62
|
-
}
|
|
63
|
-
if (GPT_PRO_RE.test(normalizedModel)) {
|
|
64
|
-
return "gpt-pro";
|
|
65
|
-
}
|
|
66
|
-
if (GPT_SOL_RE.test(normalizedModel)) {
|
|
67
|
-
return "gpt-sol";
|
|
68
|
-
}
|
|
69
|
-
if (GPT_ASTRA_RE.test(normalizedModel)) {
|
|
70
|
-
return "gpt-astra";
|
|
71
|
-
}
|
|
72
|
-
if (KIMI_K3_MODELS.has(normalizedModel)) {
|
|
73
|
-
return "kimi-k3";
|
|
74
|
-
}
|
|
75
|
-
return void 0;
|
|
76
|
-
}
|
|
77
|
-
function isGptProModel(provider, model) {
|
|
78
|
-
const normalizedProvider = asTrimmedLowercaseString(provider);
|
|
79
|
-
if (!SUPPORTED_TIER_PROVIDERS.has(normalizedProvider)) {
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
return classifyPremiumModel(model) !== void 0;
|
|
83
|
-
}
|
|
84
|
-
var GPT_PRO_BLOCKED_MESSAGE = `GPT Pro / Kimi K3.1 Pro \u7B49\u9AD8\u7EA7\u6A21\u578B\u9700\u8981\u5148\u5F00\u901A ${GPT_PRO_REQUIRED_RECHARGE_AMOUNT} \u79EF\u5206\u6863\u4F4D\u3002`;
|
|
85
|
-
function shouldBlockForGptPro(input) {
|
|
86
|
-
if (input?.premium !== true || input?.platformPaid !== true) {
|
|
87
|
-
return { blocked: false };
|
|
88
|
-
}
|
|
89
|
-
if (asTrimmedLowercaseString(input.gptProStatus) === "active") {
|
|
90
|
-
return { blocked: false };
|
|
91
|
-
}
|
|
92
|
-
return { blocked: true, message: GPT_PRO_BLOCKED_MESSAGE };
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// packages/ai/agent/agentBilling.ts
|
|
96
|
-
function resolveBillingSource(candidate) {
|
|
97
|
-
if (candidate?.local === true || candidate?.isLocal === true || candidate?.cliProvider === "local" || candidate?.apiSource === "local" || candidate?.provider === "local" || candidate?.billingSource === "local") return "local";
|
|
98
|
-
if (candidate?.isOwned !== true) {
|
|
99
|
-
const ownerUserId = typeof candidate?.userId === "string" && candidate.userId.trim() ? candidate.userId.trim() : typeof candidate?.ownerId === "string" && candidate.ownerId.trim() ? candidate.ownerId.trim() : "";
|
|
100
|
-
if (ownerUserId && (candidate?.isOAuth === true || isOAuthApiKeyRef(candidate?.apiKeyRef) || isAntigravityOAuthAgent({
|
|
101
|
-
key: "billing-source-probe",
|
|
102
|
-
apiKeyRef: candidate?.apiKeyRef ?? void 0,
|
|
103
|
-
provider: candidate?.provider ?? void 0,
|
|
104
|
-
customProviderUrl: candidate?.customProviderUrl ?? void 0
|
|
105
|
-
}))) {
|
|
106
|
-
return "owner_subscription";
|
|
107
|
-
}
|
|
108
|
-
return "platform_credits";
|
|
109
|
-
}
|
|
110
|
-
if (candidate?.isOAuth === true || candidate?.billingSource === "user_subscription" || candidate?.apiSource === "oauth" || isOAuthApiKeyRef(candidate?.apiKeyRef)) return "user_subscription";
|
|
111
|
-
if (candidate?.apiSource === "custom" || candidate?.billingSource === "user_api") {
|
|
112
|
-
if (isSubscriptionEndpoint(candidate?.customProviderUrl) || isSubscriptionOAuthCredential(candidate?.apiKeyRef)) {
|
|
113
|
-
return "user_subscription";
|
|
114
|
-
}
|
|
115
|
-
return "user_api";
|
|
116
|
-
}
|
|
117
|
-
return "platform_credits";
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// packages/ai/economics/economicsPolicy.ts
|
|
121
|
-
var DEEPSEEK_PRICING_DOC = "https://api-docs.deepseek.com/quick_start/pricing";
|
|
122
|
-
var BIGMODEL_CODING_PLAN_USAGE_NOTES = "https://docs.bigmodel.cn/cn/coding-plan/usage-notes";
|
|
123
|
-
var WEEKDAYS_MON_FRI = [1, 2, 3, 4, 5];
|
|
124
|
-
var DEEPSEEK_API_POLICY = {
|
|
125
|
-
id: "deepseek_api",
|
|
126
|
-
version: "2026-09-weekday-utc-peak-2x",
|
|
127
|
-
windows: [
|
|
128
|
-
{ timezone: "UTC", weekdays: WEEKDAYS_MON_FRI, startMinute: 60, endMinute: 240 },
|
|
129
|
-
{ timezone: "UTC", weekdays: WEEKDAYS_MON_FRI, startMinute: 360, endMinute: 600 }
|
|
130
|
-
],
|
|
131
|
-
effectiveFrom: Date.UTC(2026, 7, 16, 16, 0, 0),
|
|
132
|
-
peakPriceMultiplier: 2,
|
|
133
|
-
offPeakPriceMultiplier: 1,
|
|
134
|
-
sourceUrl: DEEPSEEK_PRICING_DOC
|
|
135
|
-
};
|
|
136
|
-
var BIGMODEL_GLM_CODING_PLAN_POLICY = {
|
|
137
|
-
id: "bigmodel_glm_coding_plan",
|
|
138
|
-
version: "2026-09-coding-plan-sh-peak-14-18",
|
|
139
|
-
windows: [
|
|
140
|
-
{ timezone: "Asia/Shanghai", weekdays: WEEKDAYS_MON_FRI, startMinute: 840, endMinute: 1080 }
|
|
141
|
-
],
|
|
142
|
-
peakQuotaMultiplier: 1,
|
|
143
|
-
offPeakQuotaMultiplier: 0.5,
|
|
144
|
-
sourceUrl: BIGMODEL_CODING_PLAN_USAGE_NOTES
|
|
145
|
-
};
|
|
146
|
-
var ECONOMICS_POLICIES = [
|
|
147
|
-
DEEPSEEK_API_POLICY,
|
|
148
|
-
BIGMODEL_GLM_CODING_PLAN_POLICY
|
|
149
|
-
];
|
|
150
|
-
function resolveEconomicsSourceId(input) {
|
|
151
|
-
const provider = typeof input?.provider === "string" ? input.provider.trim().toLowerCase() : "";
|
|
152
|
-
if (input?.apiSource?.trim().toLowerCase() === "platform") return null;
|
|
153
|
-
const rawUrl = typeof input?.customProviderUrl === "string" ? input.customProviderUrl.trim() : "";
|
|
154
|
-
let hostname = "";
|
|
155
|
-
let pathname = "";
|
|
156
|
-
if (rawUrl) {
|
|
157
|
-
try {
|
|
158
|
-
const parsed = new URL(rawUrl);
|
|
159
|
-
hostname = parsed.hostname.toLowerCase();
|
|
160
|
-
pathname = parsed.pathname;
|
|
161
|
-
} catch {
|
|
162
|
-
return null;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
if (provider === "deepseek") {
|
|
166
|
-
if (rawUrl && hostname !== "api.deepseek.com") return null;
|
|
167
|
-
return rawUrl ? "deepseek_api" : null;
|
|
168
|
-
}
|
|
169
|
-
if (provider === "bigmodel") {
|
|
170
|
-
if (hostname === "open.bigmodel.cn" && pathname.startsWith("/api/coding/")) {
|
|
171
|
-
return "bigmodel_glm_coding_plan";
|
|
172
|
-
}
|
|
173
|
-
return null;
|
|
174
|
-
}
|
|
175
|
-
return null;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// packages/ai/economics/economicsSnapshot.ts
|
|
179
|
-
var wallClockFormatterCache = /* @__PURE__ */ new Map();
|
|
180
|
-
function getWallClockFormatter(timezone) {
|
|
181
|
-
let formatter = wallClockFormatterCache.get(timezone);
|
|
182
|
-
if (!formatter) {
|
|
183
|
-
formatter = new Intl.DateTimeFormat("en-US", {
|
|
184
|
-
timeZone: timezone,
|
|
185
|
-
hourCycle: "h23",
|
|
186
|
-
year: "numeric",
|
|
187
|
-
month: "2-digit",
|
|
188
|
-
day: "2-digit",
|
|
189
|
-
hour: "2-digit",
|
|
190
|
-
minute: "2-digit",
|
|
191
|
-
second: "2-digit"
|
|
192
|
-
});
|
|
193
|
-
wallClockFormatterCache.set(timezone, formatter);
|
|
194
|
-
}
|
|
195
|
-
return formatter;
|
|
196
|
-
}
|
|
197
|
-
function getZonedWallClock(timezone, at) {
|
|
198
|
-
const parts = getWallClockFormatter(timezone).formatToParts(new Date(at));
|
|
199
|
-
const values = {};
|
|
200
|
-
for (const part of parts) {
|
|
201
|
-
if (part.type !== "literal") values[part.type] = Number(part.value);
|
|
202
|
-
}
|
|
203
|
-
const year = values.year;
|
|
204
|
-
const month = values.month;
|
|
205
|
-
const day = values.day;
|
|
206
|
-
const hour = values.hour;
|
|
207
|
-
const minute = values.minute;
|
|
208
|
-
const second = values.second;
|
|
209
|
-
const weekday = new Date(Date.UTC(year, month - 1, day)).getUTCDay();
|
|
210
|
-
return { year, month, day, hour, minute, second, weekday, minutesOfDay: hour * 60 + minute };
|
|
211
|
-
}
|
|
212
|
-
function getTimeZoneOffsetMs(timezone, at) {
|
|
213
|
-
const atSecond = Math.floor(at / 1e3) * 1e3;
|
|
214
|
-
const clock = getZonedWallClock(timezone, atSecond);
|
|
215
|
-
return Date.UTC(clock.year, clock.month - 1, clock.day, clock.hour, clock.minute, clock.second) - atSecond;
|
|
216
|
-
}
|
|
217
|
-
function zonedWallClockToEpochMs(timezone, year, month, day, minutesOfDay) {
|
|
218
|
-
const guess = Date.UTC(year, month - 1, day, Math.floor(minutesOfDay / 60), minutesOfDay % 60);
|
|
219
|
-
let instant = guess - getTimeZoneOffsetMs(timezone, guess);
|
|
220
|
-
instant = guess - getTimeZoneOffsetMs(timezone, instant);
|
|
221
|
-
return instant;
|
|
222
|
-
}
|
|
223
|
-
function resolveEconomicsPeriod(policy, at) {
|
|
224
|
-
for (const window of policy.windows) {
|
|
225
|
-
const clock = getZonedWallClock(window.timezone, at);
|
|
226
|
-
if (!window.weekdays.includes(clock.weekday)) continue;
|
|
227
|
-
if (clock.minutesOfDay >= window.startMinute && clock.minutesOfDay < window.endMinute) {
|
|
228
|
-
return "peak";
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
return "off_peak";
|
|
232
|
-
}
|
|
233
|
-
function findNextEconomicsBoundary(policy, at) {
|
|
234
|
-
let best;
|
|
235
|
-
for (const window of policy.windows) {
|
|
236
|
-
const anchor = getZonedWallClock(window.timezone, at);
|
|
237
|
-
for (let dayOffset = 0; dayOffset <= 7; dayOffset++) {
|
|
238
|
-
const dayUtc = new Date(Date.UTC(anchor.year, anchor.month - 1, anchor.day + dayOffset));
|
|
239
|
-
const weekday = dayUtc.getUTCDay();
|
|
240
|
-
if (!window.weekdays.includes(weekday)) continue;
|
|
241
|
-
const year = dayUtc.getUTCFullYear();
|
|
242
|
-
const month = dayUtc.getUTCMonth() + 1;
|
|
243
|
-
const day = dayUtc.getUTCDate();
|
|
244
|
-
for (const edge of [window.startMinute, window.endMinute]) {
|
|
245
|
-
const instant = zonedWallClockToEpochMs(window.timezone, year, month, day, edge);
|
|
246
|
-
if (instant > at && (best === void 0 || instant < best)) best = instant;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
return best;
|
|
251
|
-
}
|
|
252
|
-
function selectEconomicsPolicyVersion(policies, sourceId, at) {
|
|
253
|
-
const applicable = policies.filter(
|
|
254
|
-
(policy) => policy.id === sourceId && (policy.effectiveFrom === void 0 || policy.effectiveFrom <= at) && (policy.effectiveUntil === void 0 || at < policy.effectiveUntil)
|
|
255
|
-
);
|
|
256
|
-
if (applicable.length === 0) return null;
|
|
257
|
-
return applicable.reduce(
|
|
258
|
-
(latest, candidate) => (candidate.effectiveFrom ?? -Infinity) >= (latest.effectiveFrom ?? -Infinity) ? candidate : latest
|
|
259
|
-
);
|
|
260
|
-
}
|
|
261
|
-
function findNextPolicyBoundary(policy, at, policies) {
|
|
262
|
-
const boundaries = [
|
|
263
|
-
policy.effectiveUntil,
|
|
264
|
-
...policies.filter((candidate) => candidate.id === policy.id).map((candidate) => candidate.effectiveFrom).filter((value) => value !== void 0 && value > at)
|
|
265
|
-
].filter((value) => value !== void 0 && value > at);
|
|
266
|
-
return boundaries.length > 0 ? Math.min(...boundaries) : void 0;
|
|
267
|
-
}
|
|
268
|
-
function resolveEconomicsSnapshot(input, at, policies = ECONOMICS_POLICIES) {
|
|
269
|
-
const sourceId = resolveEconomicsSourceId(input);
|
|
270
|
-
if (!sourceId) return null;
|
|
271
|
-
const policy = selectEconomicsPolicyVersion(policies, sourceId, at);
|
|
272
|
-
if (!policy) return null;
|
|
273
|
-
const period = resolveEconomicsPeriod(policy, at);
|
|
274
|
-
const priceMultiplier = period === "peak" ? policy.peakPriceMultiplier : policy.offPeakPriceMultiplier;
|
|
275
|
-
const quotaMultiplier = period === "peak" ? policy.peakQuotaMultiplier : policy.offPeakQuotaMultiplier;
|
|
276
|
-
const windowBoundary = findNextEconomicsBoundary(policy, at);
|
|
277
|
-
const policyBoundary = findNextPolicyBoundary(policy, at, policies);
|
|
278
|
-
const changesAt = [windowBoundary, policyBoundary].filter((value) => value !== void 0).sort((a, b) => a - b)[0];
|
|
279
|
-
return {
|
|
280
|
-
source: sourceId,
|
|
281
|
-
policyVersion: policy.version,
|
|
282
|
-
period,
|
|
283
|
-
...priceMultiplier !== void 0 ? { priceMultiplier } : {},
|
|
284
|
-
...quotaMultiplier !== void 0 ? { quotaMultiplier } : {},
|
|
285
|
-
...changesAt !== void 0 ? { changesAt } : {}
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
// packages/ai/agent/safeAgentSummary.ts
|
|
290
|
-
function deriveCredentialGroup(ref) {
|
|
291
|
-
if (!ref || typeof ref !== "string") return void 0;
|
|
292
|
-
const trimmed = ref.trim();
|
|
293
|
-
if (!trimmed) return void 0;
|
|
294
|
-
if (isOAuthApiKeyRef(trimmed)) {
|
|
295
|
-
return {
|
|
296
|
-
credentialGroup: trimmed.toLowerCase(),
|
|
297
|
-
credentialKind: "oauth"
|
|
298
|
-
};
|
|
299
|
-
}
|
|
300
|
-
const hash = fnv1a32Hex(trimmed);
|
|
301
|
-
return {
|
|
302
|
-
credentialGroup: `cred-${hash}`,
|
|
303
|
-
credentialKind: "api-key"
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
|
-
function deriveCustomProviderCredentialGroup(userId, customProviderUrl) {
|
|
307
|
-
if (typeof customProviderUrl !== "string" || !customProviderUrl.trim()) {
|
|
308
|
-
return void 0;
|
|
309
|
-
}
|
|
310
|
-
const basis = `${userId ?? ""}|${customProviderUrl.trim().toLowerCase()}`;
|
|
311
|
-
return {
|
|
312
|
-
credentialGroup: `custom-${fnv1a32Hex(basis)}`,
|
|
313
|
-
credentialKind: "api-key"
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
function summarizeCredentialGroups(agents, now = Date.now()) {
|
|
317
|
-
const groups = /* @__PURE__ */ new Map();
|
|
318
|
-
for (const agent of agents) {
|
|
319
|
-
if (!agent.credentialGroup || !agent.credentialKind) continue;
|
|
320
|
-
if (agent.isOwned === false) continue;
|
|
321
|
-
const existing = groups.get(agent.credentialGroup);
|
|
322
|
-
const at = typeof agent.nextAvailableAt === "number" && agent.nextAvailableAt > now ? agent.nextAvailableAt : void 0;
|
|
323
|
-
if (!existing) {
|
|
324
|
-
groups.set(agent.credentialGroup, {
|
|
325
|
-
credentialGroup: agent.credentialGroup,
|
|
326
|
-
credentialKind: agent.credentialKind,
|
|
327
|
-
agentCount: 1,
|
|
328
|
-
...at !== void 0 ? { availableAt: at } : {}
|
|
329
|
-
});
|
|
330
|
-
} else {
|
|
331
|
-
existing.agentCount += 1;
|
|
332
|
-
if (at !== void 0) {
|
|
333
|
-
existing.availableAt = Math.max(existing.availableAt ?? 0, at);
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
return Array.from(groups.values()).sort(
|
|
338
|
-
(a, b) => a.credentialGroup.localeCompare(b.credentialGroup)
|
|
339
|
-
);
|
|
340
|
-
}
|
|
341
|
-
function parseTimestamp(val) {
|
|
342
|
-
if (typeof val === "number" && Number.isFinite(val)) return val;
|
|
343
|
-
if (typeof val === "string") return Date.parse(val) || 0;
|
|
344
|
-
return 0;
|
|
345
|
-
}
|
|
346
|
-
function safeTimestamp(val) {
|
|
347
|
-
if (typeof val === "number" && Number.isFinite(val)) return val;
|
|
348
|
-
if (typeof val === "string") return val;
|
|
349
|
-
return null;
|
|
350
|
-
}
|
|
351
|
-
function parseAgentRecordId(privateKey, explicitId) {
|
|
352
|
-
if (explicitId && typeof explicitId === "string" && explicitId.trim()) {
|
|
353
|
-
return explicitId.trim();
|
|
354
|
-
}
|
|
355
|
-
if (privateKey && typeof privateKey === "string") {
|
|
356
|
-
const match = privateKey.match(/^agent-[^-]+-(.+)$/i);
|
|
357
|
-
if (match?.[1]) return match[1];
|
|
358
|
-
}
|
|
359
|
-
return null;
|
|
360
|
-
}
|
|
361
|
-
function resolveFavoriteStatus(record2, options) {
|
|
362
|
-
if (options?.isFavorite !== void 0) {
|
|
363
|
-
return {
|
|
364
|
-
isFavorite: !!options.isFavorite,
|
|
365
|
-
favoritedAt: safeTimestamp(options.favoritedAt)
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
if (record2?.isFavorite === true) {
|
|
369
|
-
return {
|
|
370
|
-
isFavorite: true,
|
|
371
|
-
favoritedAt: safeTimestamp(record2?.favoritedAt)
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
const favoritesMap = options?.favoritesMap;
|
|
375
|
-
if (!favoritesMap) {
|
|
376
|
-
return { isFavorite: false, favoritedAt: null };
|
|
377
|
-
}
|
|
378
|
-
const candidateKeys = [];
|
|
379
|
-
if (typeof record2?.dbKey === "string" && record2.dbKey) candidateKeys.push(record2.dbKey);
|
|
380
|
-
if (typeof record2?.privateKey === "string" && record2.privateKey) candidateKeys.push(record2.privateKey);
|
|
381
|
-
if (typeof record2?.publicKey === "string" && record2.publicKey) candidateKeys.push(record2.publicKey);
|
|
382
|
-
if (typeof record2?.verifiedAgentKey === "string" && record2.verifiedAgentKey) {
|
|
383
|
-
candidateKeys.push(record2.verifiedAgentKey);
|
|
384
|
-
}
|
|
385
|
-
if (typeof record2?.id === "string" && record2.id) {
|
|
386
|
-
candidateKeys.push(record2.id);
|
|
387
|
-
candidateKeys.push(publicAgentKey(record2.id));
|
|
388
|
-
if (options?.userId) {
|
|
389
|
-
candidateKeys.push(ownedAgentKey(options.userId, record2.id));
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
let matched = false;
|
|
393
|
-
let highestFavAt = null;
|
|
394
|
-
let highestFavTime = -1;
|
|
395
|
-
for (const key of candidateKeys) {
|
|
396
|
-
const val = favoritesMap instanceof Map ? favoritesMap.get(key) : favoritesMap[key];
|
|
397
|
-
if (val !== void 0 && val !== false && val !== null) {
|
|
398
|
-
const favAt = val === true ? 1 : safeTimestamp(val);
|
|
399
|
-
if (favAt === null) continue;
|
|
400
|
-
matched = true;
|
|
401
|
-
const time = parseTimestamp(favAt);
|
|
402
|
-
if (time > highestFavTime) {
|
|
403
|
-
highestFavTime = time;
|
|
404
|
-
highestFavAt = favAt;
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
if (matched) {
|
|
409
|
-
return {
|
|
410
|
-
isFavorite: true,
|
|
411
|
-
favoritedAt: highestFavAt ?? 1
|
|
412
|
-
};
|
|
413
|
-
}
|
|
414
|
-
return { isFavorite: false, favoritedAt: null };
|
|
415
|
-
}
|
|
416
|
-
function isOwnedAgentRecord(record2, userId) {
|
|
417
|
-
if (!userId) return false;
|
|
418
|
-
if (typeof record2?.userId === "string" && record2.userId === userId || typeof record2?.ownerId === "string" && record2.ownerId === userId) {
|
|
419
|
-
return true;
|
|
420
|
-
}
|
|
421
|
-
return [record2?.dbKey, record2?.privateKey].some(
|
|
422
|
-
(key) => isOwnedAgentKey(key, userId)
|
|
423
|
-
);
|
|
424
|
-
}
|
|
425
|
-
function subscriptionQuotaChannel(source) {
|
|
426
|
-
if (typeof source !== "string") return void 0;
|
|
427
|
-
const id = source.toLowerCase();
|
|
428
|
-
if (id.includes("fetchavailablemodels:pool:")) return "antigravity";
|
|
429
|
-
const probe = id.match(/(?:^|[^a-z0-9-])(antigravity|codex|anthropic|claude|cursor|devin|xai)-oauth(?=$|[^a-z0-9-])/)?.[1];
|
|
430
|
-
if (probe === "codex") return "chatgpt";
|
|
431
|
-
if (probe === "anthropic") return "claude";
|
|
432
|
-
return probe;
|
|
433
|
-
}
|
|
434
|
-
function toSafeAgentSummary(record2, options) {
|
|
435
|
-
const rawId = parseAgentRecordId(
|
|
436
|
-
typeof record2?.privateKey === "string" ? record2.privateKey : record2?.dbKey,
|
|
437
|
-
typeof record2?.id === "string" ? record2.id : void 0
|
|
438
|
-
);
|
|
439
|
-
const id = rawId ?? (typeof record2?.id === "string" ? record2.id : null);
|
|
440
|
-
const publicRecordDenied = record2?.publicRecordExists === false || options?.publicRecordExists === false;
|
|
441
|
-
const publicRecordConfirmed = record2?.publicRecordExists === true || options?.publicRecordExists === true;
|
|
442
|
-
let publicKey;
|
|
443
|
-
if (typeof record2?.publicKey === "string" && record2.publicKey && !publicRecordDenied) {
|
|
444
|
-
publicKey = record2.publicKey;
|
|
445
|
-
} else if (publicRecordConfirmed && id) {
|
|
446
|
-
publicKey = publicAgentKey(id);
|
|
447
|
-
}
|
|
448
|
-
const name = typeof record2?.name === "string" && record2.name ? record2.name : "(unnamed)";
|
|
449
|
-
const handle = typeof record2?.handle === "string" && record2.handle ? record2.handle : null;
|
|
450
|
-
const introduction = typeof record2?.introduction === "string" && record2.introduction ? record2.introduction : typeof record2?.description === "string" && record2.description ? record2.description : null;
|
|
451
|
-
const roleText = typeof record2?.introduction === "string" ? record2.introduction.trim().replace(/\s+/g, " ") : "";
|
|
452
|
-
const roleChars = Array.from(roleText);
|
|
453
|
-
const roleHint = roleChars.length > 60 ? `${roleChars.slice(0, 59).join("")}\u2026` : roleText;
|
|
454
|
-
const model = typeof record2?.model === "string" && record2.model ? record2.model : null;
|
|
455
|
-
const provider = typeof record2?.provider === "string" && record2.provider ? record2.provider : typeof record2?.apiSource === "string" && record2.apiSource ? record2.apiSource : null;
|
|
456
|
-
const apiSource = typeof record2?.apiSource === "string" && record2.apiSource ? record2.apiSource : null;
|
|
457
|
-
const cliProvider = typeof record2?.cliProvider === "string" && record2.cliProvider ? record2.cliProvider : null;
|
|
458
|
-
const tools = Array.isArray(record2?.tools) ? record2.tools.filter((t) => typeof t === "string") : [];
|
|
459
|
-
const inputPrice = typeof record2?.inputPrice === "number" && Number.isFinite(record2.inputPrice) ? record2.inputPrice : null;
|
|
460
|
-
const outputPrice = typeof record2?.outputPrice === "number" && Number.isFinite(record2.outputPrice) ? record2.outputPrice : null;
|
|
461
|
-
const favStatus = resolveFavoriteStatus(record2, options);
|
|
462
|
-
const isPublic = record2?.isPublic === true || record2?.isPublicFlag === true || record2?.publicRecordExists === true;
|
|
463
|
-
const updatedAt = safeTimestamp(record2?.updatedAt ?? record2?.createdAt ?? record2?.created);
|
|
464
|
-
const nextAvailableAt = typeof record2?.nextAvailableAt === "number" && Number.isFinite(record2.nextAvailableAt) ? record2.nextAvailableAt : void 0;
|
|
465
|
-
const currentUserId = options?.userId;
|
|
466
|
-
const ownedKey = currentUserId ? [record2?.dbKey, record2?.privateKey].find(
|
|
467
|
-
(key) => isOwnedAgentKey(key, currentUserId)
|
|
468
|
-
) : void 0;
|
|
469
|
-
const isOwned = isOwnedAgentRecord(record2, currentUserId);
|
|
470
|
-
const isOAuth = isOAuthApiKeyRef(record2?.apiKeyRef);
|
|
471
|
-
const billingSource = resolveBillingSource({
|
|
472
|
-
...record2,
|
|
473
|
-
isOAuth,
|
|
474
|
-
isOwned,
|
|
475
|
-
apiSource,
|
|
476
|
-
cliProvider,
|
|
477
|
-
provider,
|
|
478
|
-
isPublic
|
|
479
|
-
});
|
|
480
|
-
const economics = resolveEconomicsSnapshot(
|
|
481
|
-
{
|
|
482
|
-
provider,
|
|
483
|
-
apiSource,
|
|
484
|
-
customProviderUrl: typeof record2?.customProviderUrl === "string" ? record2.customProviderUrl : null
|
|
485
|
-
},
|
|
486
|
-
options?.now ?? Date.now()
|
|
487
|
-
);
|
|
488
|
-
const verifiedSharedKey = typeof record2?.verifiedAgentKey === "string" && record2.verifiedAgentKey ? record2.verifiedAgentKey : void 0;
|
|
489
|
-
let agentKey;
|
|
490
|
-
if (currentUserId) {
|
|
491
|
-
if (isOwned) {
|
|
492
|
-
agentKey = ownedKey ?? (id ? ownedAgentKey(currentUserId, id) : void 0);
|
|
493
|
-
} else if (publicKey) {
|
|
494
|
-
agentKey = publicKey;
|
|
495
|
-
} else {
|
|
496
|
-
agentKey = verifiedSharedKey;
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
const rawCredRef = (typeof record2?.apiKeyRef === "string" && record2.apiKeyRef ? record2.apiKeyRef : void 0) ?? (typeof record2?.credentialRef === "string" && record2.credentialRef ? record2.credentialRef : void 0);
|
|
500
|
-
const credInfo = deriveCredentialGroup(record2?.credentialGroup ?? rawCredRef);
|
|
501
|
-
const credentialGroup = record2?.credentialGroup ?? credInfo?.credentialGroup;
|
|
502
|
-
const credentialKind = record2?.credentialKind ?? credInfo?.credentialKind;
|
|
503
|
-
const rawQuota = record2?.quota;
|
|
504
|
-
const snapshot = rawQuota && Array.isArray(rawQuota.windows) && Number.isFinite(rawQuota.observedAt) ? rawQuota : void 0;
|
|
505
|
-
const ref = typeof rawCredRef === "string" ? rawCredRef.trim().toLowerCase() : void 0;
|
|
506
|
-
const group = typeof credentialGroup === "string" ? credentialGroup.trim().toLowerCase() : void 0;
|
|
507
|
-
const oauthChannel = isOAuthApiKeyRef(ref) ? ref : isOAuthApiKeyRef(group) ? group : void 0;
|
|
508
|
-
const providerId = provider?.trim().toLowerCase();
|
|
509
|
-
const channel = oauthChannel ?? (providerId === "google-antigravity" ? "antigravity" : providerId);
|
|
510
|
-
const platformChannel = apiSource === "platform" || providerId === "nolo" && !oauthChannel && apiSource !== "custom";
|
|
511
|
-
const windows = snapshot?.windows.filter((window) => {
|
|
512
|
-
const origin = subscriptionQuotaChannel(window?.source);
|
|
513
|
-
return !origin || !platformChannel && (!channel || origin === channel);
|
|
514
|
-
});
|
|
515
|
-
const foreignOnly = Boolean(snapshot?.windows.length && windows?.length === 0);
|
|
516
|
-
const quota = snapshot && windows && !foreignOnly ? { ...snapshot, windows } : void 0;
|
|
517
|
-
const observedAt = record2?.quotaExhaustion?.observedAt;
|
|
518
|
-
const quotaExhaustion = !foreignOnly && typeof observedAt === "number" && Number.isFinite(observedAt) ? { observedAt } : void 0;
|
|
519
|
-
const availability = resolveAgentAvailability(
|
|
520
|
-
{ nextAvailableAt, quota, quotaExhaustion, model },
|
|
521
|
-
options?.now ?? Date.now()
|
|
522
|
-
);
|
|
523
|
-
return {
|
|
524
|
-
id,
|
|
525
|
-
...agentKey !== void 0 ? { agentKey } : {},
|
|
526
|
-
...publicKey !== void 0 ? { publicKey } : {},
|
|
527
|
-
name,
|
|
528
|
-
handle,
|
|
529
|
-
introduction,
|
|
530
|
-
...roleHint ? { roleHint } : {},
|
|
531
|
-
model,
|
|
532
|
-
modelTier: resolveModelTier(model),
|
|
533
|
-
provider,
|
|
534
|
-
apiSource,
|
|
535
|
-
cliProvider,
|
|
536
|
-
billingSource,
|
|
537
|
-
tools,
|
|
538
|
-
inputPrice,
|
|
539
|
-
outputPrice,
|
|
540
|
-
isFavorite: favStatus.isFavorite,
|
|
541
|
-
favoritedAt: favStatus.favoritedAt,
|
|
542
|
-
isPublic,
|
|
543
|
-
// 复用 platformPaidCall.ts 的唯一判据(该文件头明确它是「谁出钱」的真源):
|
|
544
|
-
// 自己写 billingSource === "platform_credits" 会与 199 门槛口径分叉——
|
|
545
|
-
// 例如 apiSource==="cli" 的本地 CLI Agent 在 resolveBillingSource 里会落到
|
|
546
|
-
// platform_credits,但 isPlatformPaidAgentCall 显式短路为「非平台垫付」。
|
|
547
|
-
requiresPaidApproval: isPlatformPaidAgentCall({
|
|
548
|
-
agentConfig: record2 ?? void 0,
|
|
549
|
-
callerUserId: currentUserId ?? void 0
|
|
550
|
-
}),
|
|
551
|
-
...economics ? { economics } : {},
|
|
552
|
-
isOwned,
|
|
553
|
-
isOAuth,
|
|
554
|
-
...nextAvailableAt !== void 0 ? { nextAvailableAt } : {},
|
|
555
|
-
availabilityStatus: availability.status,
|
|
556
|
-
availabilityReason: availability.reason,
|
|
557
|
-
...quota !== void 0 ? { quota } : {},
|
|
558
|
-
...quotaExhaustion ? { quotaExhaustion } : {},
|
|
559
|
-
...credentialGroup !== void 0 ? { credentialGroup } : {},
|
|
560
|
-
...credentialKind !== void 0 ? { credentialKind } : {},
|
|
561
|
-
// 「未知 ≠ 独立」:无 credentialGroup 时显式 credentialed:false,调用方
|
|
562
|
-
// 不得把缺失解读成独立凭证(并发扇出守卫依赖这个区分)。
|
|
563
|
-
credentialed: credentialGroup !== void 0,
|
|
564
|
-
updatedAt
|
|
565
|
-
};
|
|
566
|
-
}
|
|
567
|
-
function sortSafeAgentSummaries(agents) {
|
|
568
|
-
return [...agents].sort(compareAgentSelection);
|
|
569
|
-
}
|
|
570
|
-
var AGENT_SUMMARY_FIELDS = [
|
|
571
|
-
// —— 派发决策必需(短字段,必须排最前)——
|
|
572
|
-
// agentKey 是唯一不可推导、必须逐字复制的字段;截断时它首先被保住。
|
|
573
|
-
"agentKey",
|
|
574
|
-
"name",
|
|
575
|
-
"model",
|
|
576
|
-
"modelTier",
|
|
577
|
-
"billingSource",
|
|
578
|
-
// 扣费授权判据:listAgents 默认走 compact 投影,缺了它模型在默认派发
|
|
579
|
-
// 流程里读不到「派它之前要先问用户」(2026-11-15 事故成因)。
|
|
580
|
-
"requiresPaidApproval",
|
|
581
|
-
"availabilityStatus",
|
|
582
|
-
"credentialGroup",
|
|
583
|
-
"isFavorite",
|
|
584
|
-
"isOAuth",
|
|
585
|
-
"isOwned",
|
|
586
|
-
"isPublic",
|
|
587
|
-
// —— 次要身份/来源字段(仍很短)——
|
|
588
|
-
"provider",
|
|
589
|
-
"apiSource",
|
|
590
|
-
"credentialKind",
|
|
591
|
-
"credentialed",
|
|
592
|
-
// 仅限流中的 agent 才会带(可用 agent 上不存在)。额度/冷却只作参考信息,
|
|
593
|
-
// 不参与派发门控:这类 agent 同样在 agents 主列表里(带标注),不做过滤,
|
|
594
|
-
// 所以这两个字段只在确实限流时才占字节。
|
|
595
|
-
"nextAvailableAt",
|
|
596
|
-
"availabilityReason",
|
|
597
|
-
// —— 体积大的说明性字段(排在每条记录最后,截断时先牺牲它们)——
|
|
598
|
-
// Phase 2A economics 快照(period/multipliers/changesAt 等小对象)。
|
|
599
|
-
// 只对 DeepSeek API / BigModel GLM Coding Plan 存在;不含完整 policy/windows。
|
|
600
|
-
"economics"
|
|
601
|
-
];
|
|
602
|
-
var AGENT_SUMMARY_TRAILING_FIELDS = [
|
|
603
|
-
"tools",
|
|
604
|
-
// 额度快照(windows 数组,体积最大):只有上游真上报过窗口的 agent 才带。
|
|
605
|
-
"quota"
|
|
606
|
-
];
|
|
607
|
-
var COMPACT_AGENT_SUMMARY_FIELDS = [
|
|
608
|
-
...AGENT_SUMMARY_FIELDS,
|
|
609
|
-
"roleHint",
|
|
610
|
-
...AGENT_SUMMARY_TRAILING_FIELDS
|
|
611
|
-
];
|
|
612
|
-
function omitNullishAgentSummaryFields(summary) {
|
|
613
|
-
const result = {};
|
|
614
|
-
for (const [key, value] of Object.entries(summary)) {
|
|
615
|
-
if (value !== null && value !== void 0) {
|
|
616
|
-
result[key] = value;
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
return result;
|
|
620
|
-
}
|
|
621
|
-
function toCompactAgentSummary(summary) {
|
|
622
|
-
const compact = {};
|
|
623
|
-
for (const field of COMPACT_AGENT_SUMMARY_FIELDS) {
|
|
624
|
-
const value = summary[field];
|
|
625
|
-
if (value !== null && value !== void 0) {
|
|
626
|
-
compact[field] = value;
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
return compact;
|
|
630
|
-
}
|
|
631
|
-
var ULTRA_COMPACT_AGENT_SUMMARY_FIELDS = [
|
|
632
|
-
...AGENT_SUMMARY_FIELDS,
|
|
633
|
-
...AGENT_SUMMARY_TRAILING_FIELDS
|
|
634
|
-
];
|
|
635
|
-
function toUltraCompactAgentSummary(summary) {
|
|
636
|
-
const compact = {};
|
|
637
|
-
for (const field of ULTRA_COMPACT_AGENT_SUMMARY_FIELDS) {
|
|
638
|
-
const value = summary[field];
|
|
639
|
-
if (value !== null && value !== void 0) {
|
|
640
|
-
compact[field] = value;
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
return compact;
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
// packages/ai/agent/platformPaidCall.ts
|
|
647
|
-
var asTrimmed = (value) => typeof value === "string" ? value.trim() : "";
|
|
648
|
-
var hasOAuthCredentialShape = (agentConfig) => isOAuthApiKeyRef(agentConfig?.apiKeyRef) || isAntigravityOAuthAgent({
|
|
649
|
-
key: "platform-paid-call-probe",
|
|
650
|
-
apiKeyRef: agentConfig?.apiKeyRef ?? void 0,
|
|
651
|
-
provider: agentConfig?.provider ?? void 0,
|
|
652
|
-
customProviderUrl: agentConfig?.customProviderUrl ?? void 0
|
|
653
|
-
});
|
|
654
|
-
function isPlatformPaidAgentCall(probe) {
|
|
655
|
-
const agentConfig = probe?.agentConfig ?? {};
|
|
656
|
-
const authKind = asTrimmed(probe?.authKind);
|
|
657
|
-
if (authKind) return authKind === "platform-key";
|
|
658
|
-
if (asTrimmed(agentConfig.apiSource) === "cli") return false;
|
|
659
|
-
return resolveBillingSource({
|
|
660
|
-
local: agentConfig.local,
|
|
661
|
-
isLocal: agentConfig.isLocal,
|
|
662
|
-
cliProvider: agentConfig.cliProvider,
|
|
663
|
-
apiSource: agentConfig.apiSource,
|
|
664
|
-
provider: agentConfig.provider,
|
|
665
|
-
billingSource: agentConfig.billingSource,
|
|
666
|
-
// 形态证明而非记录自声明(见文件头):自声明 isOAuth 不足以证明 OAuth 通道归属。
|
|
667
|
-
isOAuth: hasOAuthCredentialShape(agentConfig),
|
|
668
|
-
apiKeyRef: agentConfig.apiKeyRef,
|
|
669
|
-
customProviderUrl: agentConfig.customProviderUrl,
|
|
670
|
-
isOwned: isOwnedAgentRecord(
|
|
671
|
-
agentConfig,
|
|
672
|
-
asTrimmed(probe?.callerUserId) || void 0
|
|
673
|
-
),
|
|
674
|
-
userId: agentConfig.userId,
|
|
675
|
-
ownerId: agentConfig.ownerId
|
|
676
|
-
}) === "platform_credits";
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
// packages/ai/agent/agentDiscovery.ts
|
|
680
|
-
function isPreferredAgent(agent) {
|
|
681
|
-
return agent.isFavorite === true || agent.isOwned === true || agent.isOAuth === true || agent.billingSource === "user_subscription" || agent.billingSource === "user_api" || agent.billingSource === "local";
|
|
682
|
-
}
|
|
683
|
-
function isPublicDiscoveryAgent(agent) {
|
|
684
|
-
return agent.isPublic === true && !isPreferredAgent(agent);
|
|
685
|
-
}
|
|
686
|
-
function resolveDiscoveryScope(args) {
|
|
687
|
-
const rawScope = typeof args?.scope === "string" ? args.scope.trim().toLowerCase() : void 0;
|
|
688
|
-
const hasScope = rawScope !== void 0 && rawScope !== "";
|
|
689
|
-
const hasPublicOnly = typeof args?.publicOnly === "boolean";
|
|
690
|
-
const publicOnly = args?.publicOnly === true;
|
|
691
|
-
if (hasScope) {
|
|
692
|
-
if (rawScope !== "preferred" && rawScope !== "public" && rawScope !== "all") {
|
|
693
|
-
throw new Error(`Invalid scope '${args?.scope}': must be 'preferred', 'public', or 'all'.`);
|
|
694
|
-
}
|
|
695
|
-
const scope = rawScope;
|
|
696
|
-
if (hasPublicOnly) {
|
|
697
|
-
if (publicOnly && scope !== "public") {
|
|
698
|
-
throw new Error(
|
|
699
|
-
`Conflicting arguments: scope='${args?.scope}' conflicts with publicOnly=true.`
|
|
700
|
-
);
|
|
701
|
-
}
|
|
702
|
-
if (!publicOnly && scope === "public") {
|
|
703
|
-
throw new Error(
|
|
704
|
-
`Conflicting arguments: scope='${args?.scope}' conflicts with publicOnly=false.`
|
|
705
|
-
);
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
return scope;
|
|
709
|
-
}
|
|
710
|
-
if (hasPublicOnly && publicOnly) {
|
|
711
|
-
return "public";
|
|
712
|
-
}
|
|
713
|
-
return "all";
|
|
714
|
-
}
|
|
715
|
-
function agentIdentityKeys(agent) {
|
|
716
|
-
return [agent.agentKey, agent.publicKey, agent.id].filter(
|
|
717
|
-
(key) => typeof key === "string" && key.length > 0
|
|
718
|
-
);
|
|
719
|
-
}
|
|
720
|
-
function deduplicateAgentSummaries(agents) {
|
|
721
|
-
const byIdentity = /* @__PURE__ */ new Map();
|
|
722
|
-
for (const agent of agents) {
|
|
723
|
-
const keys = agentIdentityKeys(agent);
|
|
724
|
-
const existing = keys.map((key) => byIdentity.get(key)).find(Boolean);
|
|
725
|
-
if (!existing) {
|
|
726
|
-
for (const key of keys) byIdentity.set(key, agent);
|
|
727
|
-
continue;
|
|
728
|
-
}
|
|
729
|
-
const winner = isPreferredAgent(agent) && !isPreferredAgent(existing) ? agent : existing;
|
|
730
|
-
for (const key of /* @__PURE__ */ new Set([...agentIdentityKeys(existing), ...keys])) byIdentity.set(key, winner);
|
|
731
|
-
}
|
|
732
|
-
return [...new Set(byIdentity.values())];
|
|
733
|
-
}
|
|
734
|
-
function filterAgentsByScope(agents, scope) {
|
|
735
|
-
const unique = deduplicateAgentSummaries(agents);
|
|
736
|
-
if (scope === "preferred") return unique.filter((agent) => isPreferredAgent(agent));
|
|
737
|
-
if (scope === "public") return unique.filter((agent) => isPublicDiscoveryAgent(agent));
|
|
738
|
-
return unique.filter((agent) => isPreferredAgent(agent) || agent.isPublic === true);
|
|
739
|
-
}
|
|
740
|
-
function recommendPlanning(agents, caller, poolComplete) {
|
|
741
|
-
const callerKey = typeof caller?.agentKey === "string" && caller.agentKey.trim() ? caller.agentKey : void 0;
|
|
742
|
-
const current = callerKey ? agents.find((a) => a.agentKey === callerKey) : void 0;
|
|
743
|
-
const currentTier = callerKey ? resolveModelTier(caller?.effectiveModel ?? current?.model) : "unknown";
|
|
744
|
-
const base = {
|
|
745
|
-
condition: "when_planning_needed_and_candidate_suitable",
|
|
746
|
-
action: "self",
|
|
747
|
-
currentTier,
|
|
748
|
-
poolComplete,
|
|
749
|
-
requiresPaidApproval: false
|
|
750
|
-
};
|
|
751
|
-
if (caller?.runKind === "subtask") return { ...base, reason: "bounded_subtask" };
|
|
752
|
-
if (!callerKey) return { ...base, reason: "caller_unknown" };
|
|
753
|
-
if (currentTier === "unknown") return { ...base, reason: "caller_tier_unknown" };
|
|
754
|
-
if (!poolComplete) return { ...base, reason: "pool_incomplete" };
|
|
755
|
-
const higher = agents.filter((a) => a.agentKey && a.agentKey !== callerKey && a.modelTier !== "unknown" && DISPATCH_TIER_RANK[a.modelTier] > DISPATCH_TIER_RANK[currentTier]);
|
|
756
|
-
const free = higher.filter((a) => a.requiresPaidApproval === false);
|
|
757
|
-
free.sort((a, b) => DISPATCH_TIER_RANK[b.modelTier] - DISPATCH_TIER_RANK[a.modelTier]);
|
|
758
|
-
const best = free[0];
|
|
759
|
-
if (best) return {
|
|
760
|
-
...base,
|
|
761
|
-
action: "delegate",
|
|
762
|
-
reason: "higher_suitable_agent",
|
|
763
|
-
agentKey: best.agentKey,
|
|
764
|
-
recommendedTier: best.modelTier
|
|
765
|
-
};
|
|
766
|
-
if (higher.length) return { ...base, reason: "paid_approval_required", requiresPaidApproval: true };
|
|
767
|
-
return { ...base, reason: "no_higher_suitable_agent" };
|
|
768
|
-
}
|
|
769
|
-
function resolvePaginationArgs(args) {
|
|
770
|
-
let limit;
|
|
771
|
-
let offset;
|
|
772
|
-
if (args?.limit !== void 0 && args?.limit !== null) {
|
|
773
|
-
const raw = args.limit;
|
|
774
|
-
if (typeof raw === "boolean") {
|
|
775
|
-
throw new Error(`Invalid limit '${raw}': must be a positive integer.`);
|
|
776
|
-
}
|
|
777
|
-
if (typeof raw === "number") {
|
|
778
|
-
if (!Number.isInteger(raw) || raw <= 0) {
|
|
779
|
-
throw new Error(`Invalid limit '${raw}': must be a positive integer.`);
|
|
780
|
-
}
|
|
781
|
-
limit = Math.min(raw, 500);
|
|
782
|
-
} else if (typeof raw === "string") {
|
|
783
|
-
if (raw.trim() !== "") {
|
|
784
|
-
if (!/^\d+$/.test(raw.trim())) {
|
|
785
|
-
throw new Error(`Invalid limit '${raw}': must be a positive integer.`);
|
|
786
|
-
}
|
|
787
|
-
const parsed = Number(raw.trim());
|
|
788
|
-
if (!Number.isInteger(parsed) || parsed <= 0) {
|
|
789
|
-
throw new Error(`Invalid limit '${raw}': must be a positive integer.`);
|
|
790
|
-
}
|
|
791
|
-
limit = Math.min(parsed, 500);
|
|
792
|
-
}
|
|
793
|
-
} else {
|
|
794
|
-
throw new Error(`Invalid limit '${String(raw)}': must be a positive integer.`);
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
if (args?.offset !== void 0 && args?.offset !== null) {
|
|
798
|
-
const raw = args.offset;
|
|
799
|
-
if (typeof raw === "boolean") {
|
|
800
|
-
throw new Error(`Invalid offset '${raw}': must be a non-negative integer.`);
|
|
801
|
-
}
|
|
802
|
-
if (typeof raw === "number") {
|
|
803
|
-
if (!Number.isInteger(raw) || raw < 0) {
|
|
804
|
-
throw new Error(`Invalid offset '${raw}': must be a non-negative integer.`);
|
|
805
|
-
}
|
|
806
|
-
offset = raw;
|
|
807
|
-
} else if (typeof raw === "string") {
|
|
808
|
-
if (raw.trim() !== "") {
|
|
809
|
-
if (!/^\d+$/.test(raw.trim())) {
|
|
810
|
-
throw new Error(`Invalid offset '${raw}': must be a non-negative integer.`);
|
|
811
|
-
}
|
|
812
|
-
const parsed = Number(raw.trim());
|
|
813
|
-
if (!Number.isInteger(parsed) || parsed < 0) {
|
|
814
|
-
throw new Error(`Invalid offset '${raw}': must be a non-negative integer.`);
|
|
815
|
-
}
|
|
816
|
-
offset = parsed;
|
|
817
|
-
}
|
|
818
|
-
} else {
|
|
819
|
-
throw new Error(`Invalid offset '${String(raw)}': must be a non-negative integer.`);
|
|
820
|
-
}
|
|
821
|
-
}
|
|
822
|
-
return { limit, offset };
|
|
823
|
-
}
|
|
824
|
-
function matchesAgentQuery(agent, query) {
|
|
825
|
-
if (!query || typeof query !== "string") return true;
|
|
826
|
-
const q = query.trim().toLowerCase();
|
|
827
|
-
if (!q) return true;
|
|
828
|
-
const candidates = [
|
|
829
|
-
agent.name,
|
|
830
|
-
agent.model,
|
|
831
|
-
agent.provider,
|
|
832
|
-
agent.handle,
|
|
833
|
-
agent.agentKey,
|
|
834
|
-
agent.publicKey,
|
|
835
|
-
agent.id
|
|
836
|
-
];
|
|
837
|
-
return candidates.some((text) => typeof text === "string" && text.toLowerCase().includes(q));
|
|
838
|
-
}
|
|
839
|
-
function nearestFundedSubscriptionReset(agent, now) {
|
|
840
|
-
let nearest = Infinity;
|
|
841
|
-
if (agent.billingSource !== "user_subscription") return nearest;
|
|
842
|
-
for (const window of agent.quota?.windows ?? []) {
|
|
843
|
-
const { resetAt, remaining, utilization } = window;
|
|
844
|
-
if (typeof resetAt === "number" && resetAt > now && resetAt < nearest && isSubscriptionPeriodWindow(window) && (typeof remaining === "number" && remaining > 0 || typeof utilization === "number" && utilization < 0.95)) {
|
|
845
|
-
nearest = resetAt;
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
return nearest;
|
|
849
|
-
}
|
|
850
|
-
function meteredUnitPrice(agent) {
|
|
851
|
-
if (agent.billingSource === "user_subscription" || agent.billingSource === "owner_subscription") return Infinity;
|
|
852
|
-
const input = agent.inputPrice !== null && Number.isFinite(agent.inputPrice) ? agent.inputPrice : 0;
|
|
853
|
-
const output = agent.outputPrice !== null && Number.isFinite(agent.outputPrice) ? agent.outputPrice : 0;
|
|
854
|
-
return input > 0 || output > 0 ? input + output : Infinity;
|
|
855
|
-
}
|
|
856
|
-
function buildAgentDiscoveryResult(options) {
|
|
857
|
-
const scope = resolveDiscoveryScope({
|
|
858
|
-
scope: options.scope,
|
|
859
|
-
publicOnly: options.publicOnly
|
|
860
|
-
});
|
|
861
|
-
const now = options.now ?? Date.now();
|
|
862
|
-
let scopedAgents = filterAgentsByScope(options.agents, scope);
|
|
863
|
-
if (options.query && typeof options.query === "string" && options.query.trim()) {
|
|
864
|
-
scopedAgents = scopedAgents.filter((a) => matchesAgentQuery(a, options.query));
|
|
865
|
-
}
|
|
866
|
-
scopedAgents = scopedAgents.map((agent) => {
|
|
867
|
-
const decision = resolveAgentAvailability(agent, now);
|
|
868
|
-
if (decision.status === "quota_exhausted") {
|
|
869
|
-
const resetAt = decision.resetAt ?? now + DEFAULT_PROVIDER_RETRY_MS;
|
|
870
|
-
const nextAvailableAt = typeof agent.nextAvailableAt === "number" && agent.nextAvailableAt > resetAt ? agent.nextAvailableAt : resetAt;
|
|
871
|
-
return {
|
|
872
|
-
...agent,
|
|
873
|
-
nextAvailableAt,
|
|
874
|
-
availableAt: nextAvailableAt,
|
|
875
|
-
availabilityStatus: decision.status,
|
|
876
|
-
availabilityReason: decision.reason
|
|
877
|
-
};
|
|
878
|
-
}
|
|
879
|
-
return {
|
|
880
|
-
...agent,
|
|
881
|
-
availabilityStatus: decision.status,
|
|
882
|
-
availabilityReason: decision.reason
|
|
883
|
-
};
|
|
884
|
-
});
|
|
885
|
-
const unavailableCount = scopedAgents.filter((a) => isAgentUnavailableNow(a, now)).length;
|
|
886
|
-
const credentialGroups = summarizeCredentialGroups(scopedAgents, now);
|
|
887
|
-
const pagination = resolvePaginationArgs({
|
|
888
|
-
limit: options.limit,
|
|
889
|
-
offset: options.offset
|
|
890
|
-
});
|
|
891
|
-
const offset = pagination.offset;
|
|
892
|
-
const limit = pagination.limit;
|
|
893
|
-
const sortedAgents = sortSafeAgentSummaries(scopedAgents);
|
|
894
|
-
const hasQuery = Boolean(options.query && typeof options.query === "string" && options.query.trim());
|
|
895
|
-
const hasFilteredCandidates = sortedAgents.length < options.agents.length;
|
|
896
|
-
let total;
|
|
897
|
-
if (hasQuery) {
|
|
898
|
-
total = sortedAgents.length;
|
|
899
|
-
} else if (hasFilteredCandidates) {
|
|
900
|
-
total = sortedAgents.length;
|
|
901
|
-
} else if (scope === "public") {
|
|
902
|
-
total = typeof options.upstreamTotal === "number" && options.upstreamTotal > sortedAgents.length ? options.upstreamTotal : sortedAgents.length;
|
|
903
|
-
} else if (scope === "all") {
|
|
904
|
-
const privateOnlyCount = scopedAgents.filter((a) => isPreferredAgent(a) && a.isPublic !== true).length;
|
|
905
|
-
const publicPulledCount = scopedAgents.filter((a) => a.isPublic === true).length;
|
|
906
|
-
const effectivePublicTotal = typeof options.upstreamTotal === "number" && options.upstreamTotal > publicPulledCount ? options.upstreamTotal : publicPulledCount;
|
|
907
|
-
total = options.upstreamTruncated === true ? privateOnlyCount + effectivePublicTotal : sortedAgents.length;
|
|
908
|
-
} else {
|
|
909
|
-
total = typeof options.upstreamTotal === "number" && options.upstreamTotal > sortedAgents.length ? options.upstreamTotal : sortedAgents.length;
|
|
910
|
-
}
|
|
911
|
-
const isTruncated = options.upstreamTruncated === true || !hasQuery && !hasFilteredCandidates && typeof options.upstreamTotal === "number" && options.upstreamTotal > sortedAgents.length;
|
|
912
|
-
const pagedAgents = typeof limit === "number" || typeof offset === "number" ? sortedAgents.slice(
|
|
913
|
-
offset ?? 0,
|
|
914
|
-
(offset ?? 0) + (limit ?? sortedAgents.length)
|
|
915
|
-
) : sortedAgents;
|
|
916
|
-
const projectedAgents = options.verbose === true ? pagedAgents.map(omitNullishAgentSummaryFields) : options.compact === true ? pagedAgents.map(toUltraCompactAgentSummary) : pagedAgents.map(toCompactAgentSummary);
|
|
917
|
-
const tierHints = {};
|
|
918
|
-
const tierHintPreferences = /* @__PURE__ */ new Map();
|
|
919
|
-
for (const agent of sortedAgents) {
|
|
920
|
-
const { agentKey, name, model, modelTier, requiresPaidApproval, availabilityStatus } = agent;
|
|
921
|
-
if (!agentKey || requiresPaidApproval !== false || modelTier === "unknown" || availabilityStatus === "quota_exhausted" || availabilityStatus === "rate_limited") continue;
|
|
922
|
-
const priority = resolveAgentSelectionPriority(agent);
|
|
923
|
-
const current = tierHintPreferences.get(modelTier);
|
|
924
|
-
if (current && current.priority !== priority) continue;
|
|
925
|
-
const resetAt = nearestFundedSubscriptionReset(agent, now);
|
|
926
|
-
const price = resetAt === Infinity ? meteredUnitPrice(agent) : Infinity;
|
|
927
|
-
if (current && (resetAt > current.resetAt || resetAt === current.resetAt && price >= current.price)) continue;
|
|
928
|
-
tierHintPreferences.set(modelTier, { priority, resetAt, price });
|
|
929
|
-
tierHints[modelTier] = { agentKey, name, model };
|
|
930
|
-
}
|
|
931
|
-
return {
|
|
932
|
-
total,
|
|
933
|
-
...typeof offset === "number" ? { offset } : {},
|
|
934
|
-
...typeof limit === "number" ? { limit } : {},
|
|
935
|
-
...isTruncated ? { truncated: true } : {},
|
|
936
|
-
unavailableCount,
|
|
937
|
-
availableCount: sortedAgents.length,
|
|
938
|
-
agents: projectedAgents,
|
|
939
|
-
planningRecommendation: recommendPlanning(
|
|
940
|
-
sortedAgents,
|
|
941
|
-
options.caller,
|
|
942
|
-
!isTruncated && scope === "all" && !hasQuery && !options.poolRestricted
|
|
943
|
-
),
|
|
944
|
-
...Object.keys(tierHints).length > 0 ? { tierHints } : {},
|
|
945
|
-
credentialGroups
|
|
946
|
-
};
|
|
947
|
-
}
|
|
948
|
-
function toDiscoverySafeAgentSummary(record2, options) {
|
|
949
|
-
const mergedOptions = record2?.publicRecordExists === true ? { ...options, publicRecordExists: true } : options;
|
|
950
|
-
return toSafeAgentSummary(record2, mergedOptions);
|
|
951
|
-
}
|
|
952
|
-
|
|
953
|
-
// packages/ai/agent/dispatchSpeedProvenance.ts
|
|
954
|
-
var record = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
955
|
-
function isServerDispatchSpeedSource(value, dialogId, userId) {
|
|
956
|
-
const dialog = record(value);
|
|
957
|
-
const proof = record(dialog.dispatchSpeedProvenance);
|
|
958
|
-
return proof.version === 1 && proof.source === "server-startAgentRun" && proof.userId === userId && record(dialog.runtimeBinding).tenantUserId === userId && dialog.id === dialogId;
|
|
959
|
-
}
|
|
960
|
-
function isLocalDispatchSpeedSource(value, dialogId, userId) {
|
|
961
|
-
const run = record(value);
|
|
962
|
-
const proof = record(run.dispatchSpeedProvenance);
|
|
963
|
-
return proof.version === 1 && proof.source === "cli-startAgentRun" && proof.userId === userId && typeof run.runId === "string" && run.runId.length > 0 && run.dialogId === dialogId && run.ephemeral !== true;
|
|
964
|
-
}
|
|
965
|
-
|
|
966
|
-
export {
|
|
967
|
-
isGptProModel,
|
|
968
|
-
shouldBlockForGptPro,
|
|
969
|
-
isPlatformPaidAgentCall,
|
|
970
|
-
deriveCredentialGroup,
|
|
971
|
-
deriveCustomProviderCredentialGroup,
|
|
972
|
-
summarizeCredentialGroups,
|
|
973
|
-
resolveDiscoveryScope,
|
|
974
|
-
resolvePaginationArgs,
|
|
975
|
-
matchesAgentQuery,
|
|
976
|
-
buildAgentDiscoveryResult,
|
|
977
|
-
toDiscoverySafeAgentSummary,
|
|
978
|
-
isServerDispatchSpeedSource,
|
|
979
|
-
isLocalDispatchSpeedSource
|
|
980
|
-
};
|