nolo-cli 0.1.13 → 0.1.15
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 +9 -2
- package/agent-runtime/hostAdapter.ts +53 -0
- package/agent-runtime/index.ts +28 -0
- package/agent-runtime/localLoop.ts +62 -0
- package/agent-runtime/runtimeDecision.ts +70 -0
- package/agent-runtime/types.ts +87 -0
- package/agentRunCommand.ts +104 -0
- package/agentRuntimeCommands.ts +139 -22
- package/agentRuntimeLocal.ts +7 -0
- package/ai/agent/_executeModel.ts +118 -0
- package/ai/agent/agentSlice.ts +544 -1
- package/ai/agent/appWorkingMemory.ts +126 -0
- package/ai/agent/avatarUtils.ts +24 -0
- package/ai/agent/buildEditingContext.ts +373 -0
- package/ai/agent/buildSystemPrompt.ts +532 -0
- package/ai/agent/cleanAgentMessages.ts +140 -0
- package/ai/agent/cliChatClient.ts +119 -0
- package/ai/agent/contextCompiler.ts +107 -0
- package/ai/agent/contextLayerContract.ts +44 -0
- package/ai/agent/createAgentSchema.ts +234 -0
- package/ai/agent/executeToolCall.ts +58 -0
- package/ai/agent/fetchAgentContexts.ts +42 -0
- package/ai/agent/generatePrompt.ts +3 -0
- package/ai/agent/getFullChatContextKeys.ts +168 -0
- package/ai/agent/hooks/fetchPublicAgents.ts +133 -0
- package/ai/agent/hooks/useAgentConfig.ts +61 -0
- package/ai/agent/hooks/useAgentDialog.ts +35 -0
- package/ai/agent/hooks/useAgentFormValidation.ts +202 -0
- package/ai/agent/hooks/usePublicAgents.ts +473 -0
- package/ai/agent/persistMessageWithFixedId.ts +37 -0
- package/ai/agent/planSlice.ts +259 -0
- package/ai/agent/referenceUtils.ts +229 -0
- package/ai/agent/runAgentBackground.ts +238 -0
- package/ai/agent/runAgentClientLoop.ts +138 -0
- package/ai/agent/runtimeGuidance.ts +97 -0
- package/ai/agent/runtimeServerBase.ts +37 -0
- package/ai/agent/server/fetchPublicAgents.ts +128 -0
- package/ai/agent/startParallelAgentStreams.ts +424 -0
- package/ai/agent/startupProtocol.ts +53 -0
- package/ai/agent/streamAgentChatTurn.ts +1299 -0
- package/ai/agent/streamAgentChatTurnUtils.ts +738 -0
- package/ai/agent/types.ts +71 -0
- package/ai/agent/utils/imageOutput.ts +39 -0
- package/ai/agent/utils/publicImageAgentMode.ts +26 -0
- package/ai/agent/utils/sortUtils.ts +250 -0
- package/ai/agent/web/referencePickerUtils.ts +146 -0
- package/ai/ai.locale.ts +1083 -0
- package/ai/chat/accumulateToolCallChunks.ts +95 -0
- package/ai/chat/fetchUtils.native.ts +276 -0
- package/ai/chat/fetchUtils.ts +153 -0
- package/ai/chat/inlineImageUrlsForCustomProvider.ts +117 -0
- package/ai/chat/parseApiError.ts +64 -0
- package/ai/chat/parseMultilineSSE.ts +95 -0
- package/ai/chat/sendOpenAICompletionsRequest.native.ts +682 -0
- package/ai/chat/sendOpenAICompletionsRequest.ts +712 -0
- package/ai/chat/sendOpenAIResponseRequest.ts +512 -0
- package/ai/chat/shouldUseServerProxy.ts +18 -0
- package/ai/chat/sseClient.native.ts +91 -0
- package/ai/chat/sseClient.ts +67 -0
- package/ai/chat/streamReader.native.ts +31 -0
- package/ai/chat/streamReader.ts +62 -0
- package/ai/chat/updateTotalUsage.ts +72 -0
- package/ai/context/buildReferenceContext.ts +437 -0
- package/ai/context/calculateContextUsage.ts +133 -0
- package/ai/context/retention.ts +165 -0
- package/ai/context/tokenUtils.ts +78 -0
- package/ai/index.ts +1 -1
- package/ai/llm/agentCapabilities.ts +74 -0
- package/ai/llm/calculateGeminiImageTokens.ts +57 -0
- package/ai/llm/deepinfra.ts +28 -0
- package/ai/llm/fireworks.ts +68 -0
- package/ai/llm/generateRequestBody.ts +165 -0
- package/ai/llm/getModelContextWindow.ts +84 -0
- package/ai/llm/getNoloKey.ts +37 -0
- package/ai/llm/getPricing.ts +232 -0
- package/ai/llm/hooks/useModelPricing.ts +75 -0
- package/ai/llm/imagePricing.ts +66 -0
- package/ai/llm/isResponseAPIModel.ts +13 -0
- package/ai/llm/kimi.ts +18 -0
- package/ai/llm/mimo.ts +71 -0
- package/ai/llm/mistral.ts +22 -0
- package/ai/llm/modelAvatar.ts +427 -0
- package/ai/llm/models.ts +45 -0
- package/ai/llm/openrouterModels.ts +141 -0
- package/ai/llm/providers.ts +307 -0
- package/ai/llm/reasoningModels.ts +28 -0
- package/ai/llm/types.ts +59 -0
- package/ai/llm/usageRequestOptions.ts +59 -0
- package/ai/memory/capture.ts +148 -0
- package/ai/memory/consolidate.ts +104 -0
- package/ai/memory/delete.ts +147 -0
- package/ai/memory/overlay.ts +84 -0
- package/ai/memory/query.ts +38 -0
- package/ai/memory/queryShared.ts +160 -0
- package/ai/memory/rank.ts +105 -0
- package/ai/memory/recentRelationshipRecap.ts +247 -0
- package/ai/memory/remember.ts +167 -0
- package/ai/memory/runtime.ts +76 -0
- package/ai/memory/store.ts +20 -0
- package/ai/memory/storeShared.ts +76 -0
- package/ai/memory/types.ts +46 -0
- package/ai/memory/understanding.ts +349 -0
- package/ai/memory/understandingGreeting.ts +264 -0
- package/ai/messages/type.ts +20 -0
- package/ai/policy/personalizationDialog.ts +333 -0
- package/ai/policy/runtimePolicy.ts +440 -0
- package/ai/policy/selfUpdateFields.ts +48 -0
- package/ai/policy/types.ts +64 -0
- package/ai/skills/referenceRuntime.ts +274 -0
- package/ai/skills/skillDiagnostics.ts +251 -0
- package/ai/skills/skillDocBuilder.ts +139 -0
- package/ai/skills/skillDocProtocol.ts +434 -0
- package/ai/skills/skillReferenceSummary.ts +63 -0
- package/ai/skills/skillSummaryMarker.ts +26 -0
- package/ai/token/calculatePrice.ts +546 -0
- package/ai/token/db.ts +98 -0
- package/ai/token/externalToolCost.ts +321 -0
- package/ai/token/hooks/useRecords.ts +65 -0
- package/ai/token/missingUsageEstimate.ts +42 -0
- package/ai/token/modelUsageQuery.ts +252 -0
- package/ai/token/normalizeUsage.ts +84 -0
- package/ai/token/openaiImageGenerationUsage.ts +56 -0
- package/ai/token/prepareTokenUsageData.ts +88 -0
- package/ai/token/query.ts +88 -0
- package/ai/token/queryUserTokens.ts +59 -0
- package/ai/token/resolveBillingTarget.ts +52 -0
- package/ai/token/saveTokenRecord.ts +53 -0
- package/ai/token/serverDialogProjection.ts +78 -0
- package/ai/token/serverTokenWriter.ts +143 -0
- package/ai/token/stats.ts +21 -0
- package/ai/token/tokenThunks.ts +24 -0
- package/ai/token/types.ts +93 -0
- package/ai/tools/agent/agentTools.ts +176 -0
- package/ai/tools/agent/agentUpdateShared.ts +311 -0
- package/ai/tools/agent/callAgentTool.ts +139 -0
- package/ai/tools/agent/createAgentTool.ts +512 -0
- package/ai/tools/agent/createDialogTool.ts +69 -0
- package/ai/tools/agent/createSkillAgentTool.ts +62 -0
- package/ai/tools/agent/parallelBudget.ts +221 -0
- package/ai/tools/agent/presets/appBuilderPreset.ts +147 -0
- package/ai/tools/agent/runLlmTool.ts +96 -0
- package/ai/tools/agent/runStreamingAgentTool.ts +73 -0
- package/ai/tools/agent/skillAgentArgs.ts +106 -0
- package/ai/tools/agent/skillAgentPreset.ts +89 -0
- package/ai/tools/agent/streamParallelAgentsTool.ts +122 -0
- package/ai/tools/agent/updateAgentTool.ts +96 -0
- package/ai/tools/agent/updateSelfTool.ts +113 -0
- package/ai/tools/amazonProductScraperTool.ts +86 -0
- package/ai/tools/apifyActorClient.ts +45 -0
- package/ai/tools/appEditGuard.ts +372 -0
- package/ai/tools/appReadSnapshot.ts +153 -0
- package/ai/tools/appTools.ts +1549 -0
- package/ai/tools/applyEditTool.ts +256 -0
- package/ai/tools/applyLineEditsTool.ts +312 -0
- package/ai/tools/browserTools/click.ts +33 -0
- package/ai/tools/browserTools/closeSession.ts +29 -0
- package/ai/tools/browserTools/common.ts +27 -0
- package/ai/tools/browserTools/openSession.ts +48 -0
- package/ai/tools/browserTools/readContent.ts +38 -0
- package/ai/tools/browserTools/selectOption.ts +46 -0
- package/ai/tools/browserTools/typeText.ts +42 -0
- package/ai/tools/category/createCategoryTool.ts +66 -0
- package/ai/tools/category/queryContentsByCategoryTool.ts +69 -0
- package/ai/tools/category/updateContentCategoryTool.ts +75 -0
- package/ai/tools/cfBrowserTools.ts +319 -0
- package/ai/tools/cfSpeechToTextTool.ts +49 -0
- package/ai/tools/checkEnvTool.ts +65 -0
- package/ai/tools/cloudflareCrawlTool.ts +289 -0
- package/ai/tools/codeSearchTool.ts +111 -0
- package/ai/tools/codeTools.ts +101 -0
- package/ai/tools/createDocTool.ts +132 -0
- package/ai/tools/createPlanTool.ts +999 -0
- package/ai/tools/createSkillDocTool.ts +155 -0
- package/ai/tools/createWorkflowTool.ts +154 -0
- package/ai/tools/deepseekOcrTool.ts +34 -0
- package/ai/tools/delayTool.ts +31 -0
- package/ai/tools/deleteSpacesTool.ts +325 -0
- package/ai/tools/deleteSpacesToolModel.ts +159 -0
- package/ai/tools/devReloadUtils.ts +29 -0
- package/ai/tools/dialogMessageSearch.ts +137 -0
- package/ai/tools/doctorSkillTool.ts +72 -0
- package/ai/tools/ecommerceScraperTool.ts +86 -0
- package/ai/tools/emailTools.ts +549 -0
- package/ai/tools/evalSkillTool.ts +92 -0
- package/ai/tools/exaSearchTool.ts +64 -0
- package/ai/tools/execBashTool.ts +379 -0
- package/ai/tools/executeSqlTool.ts +192 -0
- package/ai/tools/fetchWebpageSupport.ts +309 -0
- package/ai/tools/fetchWebpageTool.ts +84 -0
- package/ai/tools/geminiImagePreviewTool.ts +361 -0
- package/ai/tools/generateDocxTool.ts +215 -0
- package/ai/tools/googleSearchScraperTool.ts +106 -0
- package/ai/tools/importDataTool.ts +133 -0
- package/ai/tools/importSkillTool.ts +162 -0
- package/ai/tools/index.ts +1927 -0
- package/ai/tools/listFilesTool.ts +82 -0
- package/ai/tools/listUserSpacesTool.ts +113 -0
- package/ai/tools/modelUsageTools.ts +199 -0
- package/ai/tools/olmOcrTool.ts +34 -0
- package/ai/tools/openaiImageTool.ts +267 -0
- package/ai/tools/prepareTools.ts +23 -0
- package/ai/tools/readDocTool.ts +84 -0
- package/ai/tools/readFileTool.ts +211 -0
- package/ai/tools/readTool.ts +163 -0
- package/ai/tools/readXPostTool.ts +233 -0
- package/ai/tools/rememberMemoryTool.ts +84 -0
- package/ai/tools/remotionVideoTool.ts +151 -0
- package/ai/tools/searchDialogMessagesTool.ts +222 -0
- package/ai/tools/searchRepoTool.ts +115 -0
- package/ai/tools/searchWorkspaceTool.ts +259 -0
- package/ai/tools/skillFollowup.ts +86 -0
- package/ai/tools/surfWeatherTool.ts +169 -0
- package/ai/tools/table/addTableRowTool.ts +217 -0
- package/ai/tools/table/createTableTool.ts +315 -0
- package/ai/tools/table/rowTools.ts +366 -0
- package/ai/tools/table/schemaTools.ts +244 -0
- package/ai/tools/table/shareTableTool.ts +148 -0
- package/ai/tools/table/toolShared.ts +129 -0
- package/ai/tools/toolApiClient.ts +198 -0
- package/ai/tools/toolNameAliases.ts +57 -0
- package/ai/tools/toolResultError.ts +42 -0
- package/ai/tools/toolRunSlice.ts +303 -0
- package/ai/tools/toolSchemaCompatibility.ts +53 -0
- package/ai/tools/toolVisibility.ts +4 -0
- package/ai/tools/types.ts +20 -0
- package/ai/tools/uiAskChoiceTool.ts +104 -0
- package/ai/tools/updateContentTitleTool.ts +84 -0
- package/ai/tools/updateDocTool.ts +105 -0
- package/ai/tools/updateUserPreferenceProfileTool.ts +145 -0
- package/ai/tools/whisperTool.ts +77 -0
- package/ai/tools/writeFileTool.ts +210 -0
- package/ai/tools/youtubeScraperTool.ts +116 -0
- package/ai/tools/ziweiChartTool.ts +678 -0
- package/ai/types.ts +55 -0
- package/ai/workflow/workflowExecutor.ts +323 -0
- package/ai/workflow/workflowSlice.ts +73 -0
- package/ai/workflow/workflowTypes.ts +106 -0
- package/client/agentRun.test.ts +240 -0
- package/client/agentRun.ts +182 -19
- package/client/compactDialog.test.ts +238 -0
- package/client/localRuntimeAdapter.test.ts +135 -0
- package/client/localRuntimeAdapter.ts +244 -0
- package/client/profileConfig.test.ts +40 -0
- package/client/streamingOutput.test.ts +22 -0
- package/client/streamingOutput.ts +38 -0
- package/commandRegistry.ts +11 -2
- package/connector-experimental/index.ts +5 -0
- package/database/actions/cacheMergedUserData.ts +64 -0
- package/database/actions/common.ts +242 -0
- package/database/actions/deleteFile.ts +40 -0
- package/database/actions/fetchUserData.ts +16 -0
- package/database/actions/fileContent.ts +125 -0
- package/database/actions/patch.ts +155 -0
- package/database/actions/read.ts +337 -0
- package/database/actions/readAndWait.ts +224 -0
- package/database/actions/readRequestManager.ts +120 -0
- package/database/actions/remove.ts +94 -0
- package/database/actions/replication.ts +366 -0
- package/database/actions/upload.ts +174 -0
- package/database/actions/upsert.ts +56 -0
- package/database/actions/write.ts +126 -0
- package/database/client/db.native.ts +73 -0
- package/database/client/db.ts +51 -0
- package/database/client/fetchUserData.ts +61 -0
- package/database/client/handleError.ts +19 -0
- package/database/client/queryRequest.ts +21 -0
- package/database/config.ts +21 -0
- package/database/dbActionThunks.ts +1 -0
- package/database/dbSlice.ts +149 -0
- package/database/email.ts +42 -0
- package/database/fileRing.ts +51 -0
- package/database/fileSharding.ts +70 -0
- package/database/fileStorage.native.ts +92 -0
- package/database/fileStorage.ts +232 -0
- package/database/fileUrl.ts +34 -0
- package/database/hooks/useUserData.ts +489 -0
- package/database/index.ts +1 -0
- package/database/keys.ts +765 -0
- package/database/queryPrefixes.ts +14 -0
- package/database/requests.ts +443 -0
- package/database/runtimeServerContext.ts +35 -0
- package/database/server/MemoryDB.ts +76 -0
- package/database/server/actorAccess.ts +76 -0
- package/database/server/agentDelegation.ts +124 -0
- package/database/server/coreDataOwnership.ts +13 -0
- package/database/server/coreDataProxy.ts +76 -0
- package/database/server/cybotReadonly.ts +18 -0
- package/database/server/dataHandlers.ts +111 -0
- package/database/server/db.ts +118 -0
- package/database/server/dbPath.ts +20 -0
- package/database/server/delete.ts +499 -0
- package/database/server/emailRepository.ts +1480 -0
- package/database/server/ensureDbOpen.ts +12 -0
- package/database/server/fileRead.ts +337 -0
- package/database/server/fileService.ts +436 -0
- package/database/server/handleTransaction.ts +86 -0
- package/database/server/patch.ts +282 -0
- package/database/server/query.ts +138 -0
- package/database/server/read.ts +325 -0
- package/database/server/resourceAccess.ts +211 -0
- package/database/server/routes.ts +110 -0
- package/database/server/spaceMemberAuthority.ts +67 -0
- package/database/server/upload.ts +159 -0
- package/database/server/write.ts +494 -0
- package/database/server/writeAuthority.ts +133 -0
- package/database/sqliteDb.ts +46 -0
- package/database/table/deleteTable.ts +120 -0
- package/database/tenantPlacement.ts +57 -0
- package/database/tombstones.ts +52 -0
- package/database/userDataLoadDecision.ts +17 -0
- package/database/userDataMerge.ts +95 -0
- package/database/userPreferenceRegister.ts +108 -0
- package/database/utils/dbPath.ts +47 -0
- package/database/utils/ulid.native.ts +6 -0
- package/database/utils/ulid.ts +1 -0
- package/index.ts +37 -19
- package/localRuntimeDb.ts +28 -0
- package/package.json +17 -4
- package/runtimeModeArgs.ts +33 -0
- package/tui/readlineWorkspace.ts +1 -0
- package/tui/session.ts +22 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// ai/context/calculateContextUsage.ts
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 计算 Agent 的 Context 使用情况。
|
|
5
|
+
*
|
|
6
|
+
* 用于:
|
|
7
|
+
* 1. Agent 编辑页面的 Token 预算可视化
|
|
8
|
+
* 2. 运行时的 Context 监控
|
|
9
|
+
* 3. 超标警告
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { estimateTokenCount, CONTEXT_BUDGET, calcTokenUsagePercent } from "./tokenUtils";
|
|
13
|
+
import { getModelContextWindow } from "../llm/getModelContextWindow";
|
|
14
|
+
import type { ReferenceItem } from "app/types";
|
|
15
|
+
|
|
16
|
+
export interface ContextUsageBreakdown {
|
|
17
|
+
// 各部分 Token 使用
|
|
18
|
+
referencesTokens: number;
|
|
19
|
+
spaceContextTokens: number;
|
|
20
|
+
systemPromptTokens: number;
|
|
21
|
+
historyTokens: number;
|
|
22
|
+
|
|
23
|
+
// 总计
|
|
24
|
+
totalUsed: number;
|
|
25
|
+
modelContextWindow: number;
|
|
26
|
+
availableTokens: number;
|
|
27
|
+
|
|
28
|
+
// 百分比
|
|
29
|
+
usedPercent: number;
|
|
30
|
+
referencesPercent: number;
|
|
31
|
+
|
|
32
|
+
// 状态
|
|
33
|
+
isWarning: boolean;
|
|
34
|
+
isCritical: boolean;
|
|
35
|
+
warningMessage?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface ContextUsageInput {
|
|
39
|
+
modelName: string;
|
|
40
|
+
references?: ReferenceItem[];
|
|
41
|
+
referencesContent?: string; // 如果已经拼接好的内容
|
|
42
|
+
spaceContext?: string | null;
|
|
43
|
+
systemPrompt?: string;
|
|
44
|
+
historyContext?: string | null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 计算 Context 使用情况
|
|
49
|
+
*/
|
|
50
|
+
export const calculateContextUsage = (input: ContextUsageInput): ContextUsageBreakdown => {
|
|
51
|
+
const {
|
|
52
|
+
modelName,
|
|
53
|
+
references,
|
|
54
|
+
referencesContent,
|
|
55
|
+
spaceContext,
|
|
56
|
+
systemPrompt,
|
|
57
|
+
historyContext,
|
|
58
|
+
} = input;
|
|
59
|
+
|
|
60
|
+
// 获取模型的 Context Window
|
|
61
|
+
const modelContextWindow = getModelContextWindow(modelName);
|
|
62
|
+
|
|
63
|
+
// 估算各部分 Token 数
|
|
64
|
+
// References: 如果提供了 content 直接用,否则根据数量估算
|
|
65
|
+
let referencesTokens = 0;
|
|
66
|
+
if (referencesContent) {
|
|
67
|
+
referencesTokens = estimateTokenCount(referencesContent);
|
|
68
|
+
} else if (references && references.length > 0) {
|
|
69
|
+
// 粗略估算:每个 reference 平均 2000 tokens(需要实际获取内容才能精确)
|
|
70
|
+
referencesTokens = references.length * 2000;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const spaceContextTokens = estimateTokenCount(spaceContext || "");
|
|
74
|
+
const systemPromptTokens = estimateTokenCount(systemPrompt || "");
|
|
75
|
+
const historyTokens = estimateTokenCount(historyContext || "");
|
|
76
|
+
|
|
77
|
+
// 计算总使用量(References + Space 是预分配的,其他是动态的)
|
|
78
|
+
const preAllocatedTokens = referencesTokens + spaceContextTokens;
|
|
79
|
+
const totalUsed = preAllocatedTokens + systemPromptTokens + historyTokens;
|
|
80
|
+
const availableTokens = modelContextWindow - totalUsed;
|
|
81
|
+
|
|
82
|
+
// 计算百分比
|
|
83
|
+
const usedPercent = calcTokenUsagePercent(totalUsed, modelContextWindow);
|
|
84
|
+
const referencesPercent = calcTokenUsagePercent(preAllocatedTokens, modelContextWindow);
|
|
85
|
+
|
|
86
|
+
// 判断状态
|
|
87
|
+
const isWarning = referencesPercent > CONTEXT_BUDGET.REFERENCES_MAX_PERCENT;
|
|
88
|
+
const isCritical = usedPercent > 80;
|
|
89
|
+
|
|
90
|
+
// 生成警告消息
|
|
91
|
+
let warningMessage: string | undefined;
|
|
92
|
+
if (isCritical) {
|
|
93
|
+
warningMessage = `⚠️ 上下文已使用 ${usedPercent}%,可能影响对话质量。建议减少 References 或 Space 内容。`;
|
|
94
|
+
} else if (isWarning) {
|
|
95
|
+
warningMessage = `⚡ References 和 Space 已占用 ${referencesPercent}% 上下文,建议控制在 ${CONTEXT_BUDGET.REFERENCES_MAX_PERCENT}% 以内。`;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
referencesTokens,
|
|
100
|
+
spaceContextTokens,
|
|
101
|
+
systemPromptTokens,
|
|
102
|
+
historyTokens,
|
|
103
|
+
totalUsed,
|
|
104
|
+
modelContextWindow,
|
|
105
|
+
availableTokens,
|
|
106
|
+
usedPercent,
|
|
107
|
+
referencesPercent,
|
|
108
|
+
isWarning,
|
|
109
|
+
isCritical,
|
|
110
|
+
warningMessage,
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* 快速检查 References 是否超标
|
|
116
|
+
* 用于 Agent 编辑页面的实时反馈
|
|
117
|
+
*/
|
|
118
|
+
export const checkReferencesOverBudget = (
|
|
119
|
+
modelName: string,
|
|
120
|
+
referencesTokens: number
|
|
121
|
+
): { isOver: boolean; percent: number; message?: string } => {
|
|
122
|
+
const modelContextWindow = getModelContextWindow(modelName);
|
|
123
|
+
const percent = calcTokenUsagePercent(referencesTokens, modelContextWindow);
|
|
124
|
+
const isOver = percent > CONTEXT_BUDGET.REFERENCES_MAX_PERCENT;
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
isOver,
|
|
128
|
+
percent,
|
|
129
|
+
message: isOver
|
|
130
|
+
? `References 占用 ${percent}%,超过建议上限 ${CONTEXT_BUDGET.REFERENCES_MAX_PERCENT}%`
|
|
131
|
+
: undefined,
|
|
132
|
+
};
|
|
133
|
+
};
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// 文件路径: packages/ai/context/retention.ts
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 将 contextRetention slider (1–100) 映射为实际保留比例 R ∈ (0, 1)。
|
|
5
|
+
*
|
|
6
|
+
* 分三档线性映射:
|
|
7
|
+
* - 低保留: 1–30 → 15% ~ 30%
|
|
8
|
+
* - 中保留: 31–70 → 30% ~ 60%
|
|
9
|
+
* - 高保留: 71–100 → 60% ~ 85%
|
|
10
|
+
*/
|
|
11
|
+
export const mapRetentionSliderToRatio = (slider: number): number => {
|
|
12
|
+
const s = Math.min(100, Math.max(1, slider));
|
|
13
|
+
|
|
14
|
+
if (s <= 30) {
|
|
15
|
+
// Low retention: 15% ~ 30%
|
|
16
|
+
return 0.15 + (0.30 - 0.15) * (s / 30);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (s <= 70) {
|
|
20
|
+
// Medium retention: 30% ~ 60%
|
|
21
|
+
return 0.30 + (0.60 - 0.30) * ((s - 30) / 40);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// High retention: 60% ~ 85%
|
|
25
|
+
return 0.60 + (0.85 - 0.60) * ((s - 70) / 30);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 安全系数:只允许历史对话最多占用 contextWindow 的 SAFE_BUFFER_RATIO 部分,
|
|
30
|
+
* 预留剩余空间给 system prompt / 工具描述等固定开销。
|
|
31
|
+
*/
|
|
32
|
+
export const SAFE_BUFFER_RATIO = 0.9;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 对话负载分档:
|
|
36
|
+
* - light :短句聊天为主
|
|
37
|
+
* - medium :中等长度混合
|
|
38
|
+
* - heavy :长代码 / 长文档为主
|
|
39
|
+
*/
|
|
40
|
+
export type ConversationLoad = "light" | "medium" | "heavy";
|
|
41
|
+
|
|
42
|
+
export interface ContextPlan {
|
|
43
|
+
/**
|
|
44
|
+
* 历史总预算(summary + 原始消息),单位:token
|
|
45
|
+
* 实际不会超过 contextWindow * SAFE_BUFFER_RATIO
|
|
46
|
+
*/
|
|
47
|
+
historyBudget: number;
|
|
48
|
+
/**
|
|
49
|
+
* 历史中分配给「原始消息」的预算,单位:token
|
|
50
|
+
* 用于 trimMessagesWithSummary 之类的裁剪逻辑。
|
|
51
|
+
*/
|
|
52
|
+
rawMessageBudget: number;
|
|
53
|
+
/**
|
|
54
|
+
* 希望至少保留的「最近尾部消息」的 token 数,用作二次兜底,
|
|
55
|
+
* 确保短句对话能多保几轮,重内容对话能保住最近几条大块内容。
|
|
56
|
+
*/
|
|
57
|
+
minTailTokens: number;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const clamp = (v: number, min: number, max: number): number =>
|
|
61
|
+
Math.min(max, Math.max(min, v));
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 统一的上下文使用规划函数:
|
|
65
|
+
* - 输入:模型 window、用户 slider、现有 summary 长度、近期对话负载分档
|
|
66
|
+
* - 输出:历史总预算 + 原始消息预算 + 尾部最少保留 token 数
|
|
67
|
+
*
|
|
68
|
+
* 约束与策略:
|
|
69
|
+
* - 历史最多只能占用 contextWindow * SAFE_BUFFER_RATIO
|
|
70
|
+
* - slider 决定「整体偏好多记还是少记」
|
|
71
|
+
* - recentLoad 决定在该偏好下的微调:
|
|
72
|
+
* - light :适当放宽,给更多历史空间
|
|
73
|
+
* - heavy :适当收紧,为当前大块内容 / 工具描述预留空间
|
|
74
|
+
*/
|
|
75
|
+
export const planContextUsage = (params: {
|
|
76
|
+
contextWindow: number;
|
|
77
|
+
retentionSlider: number;
|
|
78
|
+
summaryTokens: number;
|
|
79
|
+
recentLoad: ConversationLoad;
|
|
80
|
+
}): ContextPlan => {
|
|
81
|
+
const { contextWindow, retentionSlider, summaryTokens, recentLoad } = params;
|
|
82
|
+
|
|
83
|
+
const safeWindowLimit = Math.floor(contextWindow * SAFE_BUFFER_RATIO);
|
|
84
|
+
|
|
85
|
+
const s = Math.min(100, Math.max(1, retentionSlider));
|
|
86
|
+
const iq = s / 100; // 0~1,表示用户偏好的“记忆强度”
|
|
87
|
+
|
|
88
|
+
const isBigWindow = contextWindow >= 128000; // 例如 128k / 1M 等大模型
|
|
89
|
+
const isSmallWindow = contextWindow <= 32000; // 例如 8k / 16k 等小模型
|
|
90
|
+
|
|
91
|
+
// 基础历史比例(只考虑 slider,不考虑对话负载)
|
|
92
|
+
// - 小窗口:历史占 35% ~ 70% 的 safeWindow
|
|
93
|
+
// - 中窗口:历史占 40% ~ 75%
|
|
94
|
+
// - 大窗口:历史占 65% ~ 90%(尽量吃满大模型上下文)
|
|
95
|
+
let baseHistoryRatio: number;
|
|
96
|
+
if (isBigWindow) {
|
|
97
|
+
baseHistoryRatio = 0.65 + 0.25 * iq; // 0.65 ~ 0.90
|
|
98
|
+
} else if (isSmallWindow) {
|
|
99
|
+
baseHistoryRatio = 0.35 + 0.35 * iq; // 0.35 ~ 0.70
|
|
100
|
+
} else {
|
|
101
|
+
baseHistoryRatio = 0.40 + 0.35 * iq; // 0.40 ~ 0.75
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// 1. 历史比例:在 baseHistoryRatio 基础上,根据对话负载做微调
|
|
105
|
+
let historyRatio = baseHistoryRatio;
|
|
106
|
+
|
|
107
|
+
switch (recentLoad) {
|
|
108
|
+
case "light": {
|
|
109
|
+
// 短句对话:可以多给一点历史空间,但仍保留少量余量给其他上下文
|
|
110
|
+
const maxRatio = isBigWindow ? 0.95 : 0.85;
|
|
111
|
+
historyRatio = clamp(historyRatio * 1.05, 0.3, maxRatio);
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
case "heavy": {
|
|
115
|
+
// 重内容对话:适当收紧历史比例,为当前大块内容 / 工具描述等预留更多窗口
|
|
116
|
+
const maxRatio = isBigWindow ? 0.90 : 0.80;
|
|
117
|
+
historyRatio = clamp(historyRatio * 0.9, 0.3, maxRatio);
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
case "medium":
|
|
121
|
+
default: {
|
|
122
|
+
const maxRatio = isBigWindow ? 0.90 : 0.85;
|
|
123
|
+
historyRatio = clamp(historyRatio, 0.3, maxRatio);
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const historyBudget = Math.max(
|
|
129
|
+
0,
|
|
130
|
+
Math.floor(safeWindowLimit * historyRatio),
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
// 2. 在历史预算里分配给「原始消息」的预算
|
|
134
|
+
// - summary 已经占用一部分
|
|
135
|
+
// - 同时保证原始消息至少有一部分空间(heavy 用户更多一点)
|
|
136
|
+
const minRawRatio = recentLoad === "heavy" ? 0.4 : 0.2;
|
|
137
|
+
|
|
138
|
+
const rawMessageBudget = Math.max(
|
|
139
|
+
Math.floor(historyBudget * minRawRatio),
|
|
140
|
+
historyBudget - summaryTokens,
|
|
141
|
+
0,
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
// 3. 希望至少保留的尾部 token 数
|
|
145
|
+
// - light :多保几轮短句(不超过 30% window,且上限 8k)
|
|
146
|
+
// - heavy :至少给几条大块代码空间(>= 16k,或 25% window)
|
|
147
|
+
// - medium:取中间值
|
|
148
|
+
let minTailTokens: number;
|
|
149
|
+
|
|
150
|
+
if (recentLoad === "light") {
|
|
151
|
+
minTailTokens = Math.min(
|
|
152
|
+
Math.floor(safeWindowLimit * 0.3),
|
|
153
|
+
8000,
|
|
154
|
+
);
|
|
155
|
+
} else if (recentLoad === "heavy") {
|
|
156
|
+
minTailTokens = Math.max(
|
|
157
|
+
Math.floor(safeWindowLimit * 0.25),
|
|
158
|
+
16000,
|
|
159
|
+
);
|
|
160
|
+
} else {
|
|
161
|
+
minTailTokens = Math.floor(safeWindowLimit * 0.2);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return { historyBudget, rawMessageBudget, minTailTokens };
|
|
165
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// ai/context/tokenUtils.ts
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 简单的 Token 估算工具。
|
|
5
|
+
*
|
|
6
|
+
* 规则:
|
|
7
|
+
* - 中文字符:约 1.5 tokens/字
|
|
8
|
+
* - 英文及其他字符:约 0.25 tokens/字符(即 4 字符 ≈ 1 token)
|
|
9
|
+
*
|
|
10
|
+
* 这是一个粗略估算,精确值需要使用 tiktoken 等库。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 估算文本的 Token 数量
|
|
15
|
+
*/
|
|
16
|
+
export const estimateTokenCount = (text: string): number => {
|
|
17
|
+
if (!text) return 0;
|
|
18
|
+
|
|
19
|
+
// 匹配中文字符(包括常用汉字范围)
|
|
20
|
+
const chineseChars = (text.match(/[\u4e00-\u9fa5\u3400-\u4dbf]/g) || []).length;
|
|
21
|
+
const otherChars = text.length - chineseChars;
|
|
22
|
+
|
|
23
|
+
// 中文 1.5 token/字,其他 0.25 token/字符
|
|
24
|
+
return Math.ceil(chineseChars * 1.5 + otherChars * 0.25);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 估算多个文本的 Token 总数
|
|
29
|
+
*/
|
|
30
|
+
export const estimateTotalTokens = (texts: (string | undefined | null)[]): number => {
|
|
31
|
+
return texts.reduce((sum, text) => sum + estimateTokenCount(text || ""), 0);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 格式化 Token 数量为可读字符串
|
|
36
|
+
* 例如:1500 -> "1.5k", 150000 -> "150k"
|
|
37
|
+
*/
|
|
38
|
+
export const formatTokenCount = (count: number): string => {
|
|
39
|
+
if (count < 1000) return String(count);
|
|
40
|
+
if (count < 10000) return `${(count / 1000).toFixed(1)}k`;
|
|
41
|
+
return `${Math.round(count / 1000)}k`;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 计算 Token 使用百分比
|
|
46
|
+
*/
|
|
47
|
+
export const calcTokenUsagePercent = (used: number, total: number): number => {
|
|
48
|
+
if (total <= 0) return 0;
|
|
49
|
+
return Math.min(100, Math.round((used / total) * 100));
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Context 分配建议阈值
|
|
54
|
+
* - References/Space Context 不应超过总量的 40%
|
|
55
|
+
* - 为对话历史和用户输入预留 40%
|
|
56
|
+
* - 为系统提示预留 10%
|
|
57
|
+
* - 为输出预留 10%
|
|
58
|
+
*/
|
|
59
|
+
export const CONTEXT_BUDGET = {
|
|
60
|
+
REFERENCES_MAX_PERCENT: 40, // References + Space Context 最大占比
|
|
61
|
+
HISTORY_RESERVE_PERCENT: 40, // 为对话历史预留
|
|
62
|
+
SYSTEM_RESERVE_PERCENT: 10, // 系统提示预留
|
|
63
|
+
OUTPUT_RESERVE_PERCENT: 10, // 输出预留
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 判断 Token 使用是否超过警告阈值
|
|
68
|
+
*/
|
|
69
|
+
export const isTokenUsageWarning = (usedPercent: number): boolean => {
|
|
70
|
+
return usedPercent > CONTEXT_BUDGET.REFERENCES_MAX_PERCENT;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 判断 Token 使用是否严重超标
|
|
75
|
+
*/
|
|
76
|
+
export const isTokenUsageCritical = (usedPercent: number): boolean => {
|
|
77
|
+
return usedPercent > 60; // 超过 60% 可能影响对话历史
|
|
78
|
+
};
|
package/ai/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
console.log('Hello via Bun!');
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import {
|
|
2
|
+
findModelConfig,
|
|
3
|
+
getProviderByModelName,
|
|
4
|
+
} from "./providers";
|
|
5
|
+
|
|
6
|
+
type AgentCapabilityConfig = {
|
|
7
|
+
apiSource?: string | null;
|
|
8
|
+
provider?: string | null;
|
|
9
|
+
model?: string | null;
|
|
10
|
+
hasVision?: boolean | null;
|
|
11
|
+
useServerProxy?: boolean | null;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const isCustomAgent = (agent: AgentCapabilityConfig): boolean => {
|
|
15
|
+
const apiSource = agent.apiSource?.toLowerCase();
|
|
16
|
+
const provider = agent.provider?.toLowerCase();
|
|
17
|
+
return apiSource === "custom" || provider === "custom";
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const lookupKnownModelVision = (
|
|
21
|
+
provider: string | null,
|
|
22
|
+
model: string,
|
|
23
|
+
): boolean | undefined => {
|
|
24
|
+
if (!model) return undefined;
|
|
25
|
+
|
|
26
|
+
if (provider) {
|
|
27
|
+
const direct = findModelConfig(provider, model);
|
|
28
|
+
if (direct) return direct.hasVision;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const detected = getProviderByModelName(model);
|
|
32
|
+
if (detected) {
|
|
33
|
+
return findModelConfig(detected, model)?.hasVision;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (!provider && model.includes("/")) {
|
|
37
|
+
const slash = model.indexOf("/");
|
|
38
|
+
const modelProvider = model.slice(0, slash).toLowerCase();
|
|
39
|
+
const modelName = model.slice(slash + 1);
|
|
40
|
+
const nested = findModelConfig(modelProvider, modelName);
|
|
41
|
+
if (nested) return nested.hasVision;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return undefined;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const resolveAgentImageInputSupport = (
|
|
48
|
+
agent: AgentCapabilityConfig | null | undefined,
|
|
49
|
+
): boolean => {
|
|
50
|
+
if (!agent) return true;
|
|
51
|
+
|
|
52
|
+
const provider = agent.provider?.trim().toLowerCase() || null;
|
|
53
|
+
const model = agent.model?.trim() || "";
|
|
54
|
+
const custom = isCustomAgent(agent);
|
|
55
|
+
const catalogHasVision = lookupKnownModelVision(
|
|
56
|
+
custom ? null : provider,
|
|
57
|
+
model,
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
if (!custom && catalogHasVision !== undefined) {
|
|
61
|
+
return catalogHasVision;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (custom) {
|
|
65
|
+
if (catalogHasVision === true) return true;
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (typeof agent.hasVision === "boolean") {
|
|
70
|
+
return agent.hasVision;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return true;
|
|
74
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// src/calcGeminiImageTokens.ts
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Gemini 图片 token 计算(粗略公式版)
|
|
5
|
+
*
|
|
6
|
+
* 规则:
|
|
7
|
+
* - 若宽高都 <= 384,则直接按 1 个图块:258 tokens
|
|
8
|
+
* - 否则:
|
|
9
|
+
* - uRaw = floor( min(width, height) / 1.5 )
|
|
10
|
+
* - u = clamp(uRaw, 256, 768)
|
|
11
|
+
* - tilesX = ceil(width / u)
|
|
12
|
+
* - tilesY = ceil(height / u)
|
|
13
|
+
* - tiles = tilesX * tilesY
|
|
14
|
+
* - tokens = tiles * 258
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export const GEMINI_IMAGE_TILE_TOKENS = 258;
|
|
18
|
+
export const GEMINI_SMALL_IMAGE_THRESHOLD = 384;
|
|
19
|
+
export const GEMINI_MIN_TILE_SIZE = 256;
|
|
20
|
+
export const GEMINI_MAX_TILE_SIZE = 768;
|
|
21
|
+
|
|
22
|
+
const clamp = (value: number, min: number, max: number): number =>
|
|
23
|
+
Math.min(Math.max(value, min), max);
|
|
24
|
+
|
|
25
|
+
const ceilDiv = (numerator: number, denominator: number): number =>
|
|
26
|
+
Math.ceil(numerator / denominator);
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 计算单张图片的 token 数(适用于 Gemini 1.5 / 2.0 / 2.5 的粗略估算)
|
|
30
|
+
*/
|
|
31
|
+
export const calculateGeminiImageTokens = (
|
|
32
|
+
width: number,
|
|
33
|
+
height: number,
|
|
34
|
+
): number => {
|
|
35
|
+
if (!Number.isFinite(width) || !Number.isFinite(height)) {
|
|
36
|
+
throw new TypeError('width 和 height 必须是有限数字');
|
|
37
|
+
}
|
|
38
|
+
if (width <= 0 || height <= 0) {
|
|
39
|
+
throw new RangeError('width 和 height 必须为正数');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 情况 1:小图(两个维度都 <= 384)
|
|
43
|
+
if (width <= GEMINI_SMALL_IMAGE_THRESHOLD && height <= GEMINI_SMALL_IMAGE_THRESHOLD) {
|
|
44
|
+
return GEMINI_IMAGE_TILE_TOKENS;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 情况 2:大图,按粗略公式计算图块数量
|
|
48
|
+
const minSide = Math.min(width, height);
|
|
49
|
+
const rawUnit = Math.floor(minSide / 1.5);
|
|
50
|
+
const unit = clamp(rawUnit, GEMINI_MIN_TILE_SIZE, GEMINI_MAX_TILE_SIZE);
|
|
51
|
+
|
|
52
|
+
const tilesX = ceilDiv(width, unit);
|
|
53
|
+
const tilesY = ceilDiv(height, unit);
|
|
54
|
+
const tiles = tilesX * tilesY;
|
|
55
|
+
|
|
56
|
+
return tiles * GEMINI_IMAGE_TILE_TOKENS;
|
|
57
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// ai/llm/deepinfra.ts
|
|
2
|
+
export const deepinfraModels = [
|
|
3
|
+
{
|
|
4
|
+
name: "moonshotai/Kimi-K2.5",
|
|
5
|
+
displayName: "MoonshotAI: Kimi K2.5 (DeepInfra)",
|
|
6
|
+
hasVision: true,
|
|
7
|
+
price: {
|
|
8
|
+
input: 0.45 * 8,
|
|
9
|
+
output: 2.25 * 8,
|
|
10
|
+
inputCacheHit: 0.07 * 8,
|
|
11
|
+
},
|
|
12
|
+
maxOutputTokens: 262144,
|
|
13
|
+
contextWindow: 262144,
|
|
14
|
+
supportsTool: true,
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
name: "zai-org/GLM-5.1",
|
|
18
|
+
displayName: "Z.AI: GLM 5.1 (DeepInfra)",
|
|
19
|
+
hasVision: false,
|
|
20
|
+
price: {
|
|
21
|
+
input: 1.26 * 8,
|
|
22
|
+
output: 3.96 * 8,
|
|
23
|
+
inputCacheHit: 0.26 * 8,
|
|
24
|
+
},
|
|
25
|
+
contextWindow: 202752,
|
|
26
|
+
supportsTool: true,
|
|
27
|
+
},
|
|
28
|
+
];
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// ai/llm/fireworks.ts
|
|
2
|
+
import {
|
|
3
|
+
FIREWORKS_KIMI_CURRENT_MODEL,
|
|
4
|
+
FIREWORKS_KIMI_LATEST_MODEL,
|
|
5
|
+
} from "./kimi";
|
|
6
|
+
|
|
7
|
+
export const fireworksModels = [
|
|
8
|
+
// --- MoonshotAI Models (Kimi) ---
|
|
9
|
+
{
|
|
10
|
+
name: FIREWORKS_KIMI_LATEST_MODEL,
|
|
11
|
+
displayName: "MoonshotAI: Kimi Latest",
|
|
12
|
+
hasVision: true,
|
|
13
|
+
price: {
|
|
14
|
+
input: 0.95 * 8,
|
|
15
|
+
output: 4.0 * 8,
|
|
16
|
+
cachingRead: 0.16 * 8,
|
|
17
|
+
},
|
|
18
|
+
maxOutputTokens: 262144,
|
|
19
|
+
contextWindow: 262144,
|
|
20
|
+
supportsTool: true,
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: FIREWORKS_KIMI_CURRENT_MODEL,
|
|
24
|
+
displayName: "MoonshotAI: Kimi K2.6",
|
|
25
|
+
hasVision: true,
|
|
26
|
+
price: {
|
|
27
|
+
input: 0.95 * 8,
|
|
28
|
+
output: 4.0 * 8,
|
|
29
|
+
cachingRead: 0.16 * 8,
|
|
30
|
+
},
|
|
31
|
+
maxOutputTokens: 262144,
|
|
32
|
+
contextWindow: 262144,
|
|
33
|
+
supportsTool: true,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: "accounts/fireworks/models/minimax-m2p7",
|
|
37
|
+
displayName: "MiniMax: MiniMax M2.7",
|
|
38
|
+
hasVision: true,
|
|
39
|
+
price: {
|
|
40
|
+
input: 0.3 * 8,
|
|
41
|
+
output: 1.2 * 8,
|
|
42
|
+
cachingRead: 0.06 * 8,
|
|
43
|
+
},
|
|
44
|
+
supportsTool: true,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: "accounts/fireworks/models/qwen3p6-plus",
|
|
48
|
+
displayName: "Qwen: Qwen 3.6 Plus",
|
|
49
|
+
hasVision: true,
|
|
50
|
+
price: {
|
|
51
|
+
input: 0.5 * 8,
|
|
52
|
+
output: 3.0 * 8,
|
|
53
|
+
cachingRead: 0.1 * 8,
|
|
54
|
+
},
|
|
55
|
+
supportsTool: true,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: "accounts/fireworks/models/glm-5p1",
|
|
59
|
+
displayName: "Z.AI: GLM 5.1",
|
|
60
|
+
hasVision: true,
|
|
61
|
+
price: {
|
|
62
|
+
input: 1.0 * 8,
|
|
63
|
+
output: 3.2 * 8,
|
|
64
|
+
cachingRead: 0.2 * 8,
|
|
65
|
+
},
|
|
66
|
+
supportsTool: true,
|
|
67
|
+
},
|
|
68
|
+
];
|