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,440 @@
|
|
|
1
|
+
import type { Agent } from "app/types";
|
|
2
|
+
import type {
|
|
3
|
+
AgentBasePolicy,
|
|
4
|
+
DialogPolicyState,
|
|
5
|
+
KnowledgeCaptureLevel,
|
|
6
|
+
SelfEvolutionMode,
|
|
7
|
+
SpaceContextLevel,
|
|
8
|
+
TonePreset,
|
|
9
|
+
ToneResolutionMode,
|
|
10
|
+
UserPreferenceProfile,
|
|
11
|
+
} from "./types";
|
|
12
|
+
import {
|
|
13
|
+
DEFAULT_AGENT_BASE_POLICY,
|
|
14
|
+
DEFAULT_USER_PREFERENCE_PROFILE,
|
|
15
|
+
} from "./types";
|
|
16
|
+
|
|
17
|
+
export type CaptureIntent = "none" | "possible" | "strong";
|
|
18
|
+
export type SpaceNeed = "none" | "light" | "deep";
|
|
19
|
+
export type KnowledgeCaptureMode = "blocked" | "ask" | "suggest" | "auto";
|
|
20
|
+
|
|
21
|
+
export interface ResolvedRuntimePolicy {
|
|
22
|
+
tonePreset: TonePreset;
|
|
23
|
+
toneResolutionMode: ToneResolutionMode;
|
|
24
|
+
knowledgeCapture: {
|
|
25
|
+
level: KnowledgeCaptureLevel;
|
|
26
|
+
mode: KnowledgeCaptureMode;
|
|
27
|
+
explicitRequest: boolean;
|
|
28
|
+
maxAutoCreatesPerDialog: number;
|
|
29
|
+
currentAutoCreates: number;
|
|
30
|
+
captureIntent: CaptureIntent;
|
|
31
|
+
};
|
|
32
|
+
spaceContext: {
|
|
33
|
+
level: SpaceContextLevel;
|
|
34
|
+
explicitRequest: boolean;
|
|
35
|
+
need: SpaceNeed;
|
|
36
|
+
maxReadCallsPerTurn: number;
|
|
37
|
+
maxReadCallsPerDialog: number;
|
|
38
|
+
currentAutoReads: number;
|
|
39
|
+
preloadSummaryCount: number;
|
|
40
|
+
preloadBudgetRatio: number;
|
|
41
|
+
};
|
|
42
|
+
selfEvolutionMode: SelfEvolutionMode;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const clampLevel = <T extends 1 | 2 | 3 | 4>(
|
|
46
|
+
value: unknown,
|
|
47
|
+
fallback: T,
|
|
48
|
+
): T => {
|
|
49
|
+
const n = Number(value);
|
|
50
|
+
if (n === 1 || n === 2 || n === 3 || n === 4) {
|
|
51
|
+
return n as T;
|
|
52
|
+
}
|
|
53
|
+
return fallback;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const normalizeTonePreset = (value: unknown, fallback: TonePreset): TonePreset => {
|
|
57
|
+
switch (value) {
|
|
58
|
+
case "professional":
|
|
59
|
+
case "friendly":
|
|
60
|
+
case "direct":
|
|
61
|
+
case "pragmatic":
|
|
62
|
+
case "default":
|
|
63
|
+
return value;
|
|
64
|
+
default:
|
|
65
|
+
return fallback;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const normalizeToneResolutionMode = (
|
|
70
|
+
value: unknown,
|
|
71
|
+
fallback: ToneResolutionMode,
|
|
72
|
+
): ToneResolutionMode => {
|
|
73
|
+
switch (value) {
|
|
74
|
+
case "agent_first":
|
|
75
|
+
case "user_first":
|
|
76
|
+
case "blend":
|
|
77
|
+
return value;
|
|
78
|
+
default:
|
|
79
|
+
return fallback;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const normalizeSelfEvolutionMode = (
|
|
84
|
+
value: unknown,
|
|
85
|
+
fallback: SelfEvolutionMode,
|
|
86
|
+
): SelfEvolutionMode => {
|
|
87
|
+
switch (value) {
|
|
88
|
+
case "none":
|
|
89
|
+
case "knowledge_only":
|
|
90
|
+
case "prompt_and_refs":
|
|
91
|
+
case "full":
|
|
92
|
+
return value;
|
|
93
|
+
default:
|
|
94
|
+
return fallback;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export const resolveAgentBasePolicy = (agentConfig?: Agent | any): AgentBasePolicy => {
|
|
99
|
+
const raw = agentConfig?.basePolicy ?? {};
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
version: 1,
|
|
103
|
+
tone: {
|
|
104
|
+
preset: normalizeTonePreset(
|
|
105
|
+
raw?.tone?.preset,
|
|
106
|
+
DEFAULT_AGENT_BASE_POLICY.tone?.preset ?? "default",
|
|
107
|
+
),
|
|
108
|
+
resolutionMode: normalizeToneResolutionMode(
|
|
109
|
+
raw?.tone?.resolutionMode,
|
|
110
|
+
DEFAULT_AGENT_BASE_POLICY.tone?.resolutionMode ?? "blend",
|
|
111
|
+
),
|
|
112
|
+
},
|
|
113
|
+
knowledgeCaptureMaxLevel: clampLevel(
|
|
114
|
+
raw?.knowledgeCaptureMaxLevel,
|
|
115
|
+
DEFAULT_AGENT_BASE_POLICY.knowledgeCaptureMaxLevel,
|
|
116
|
+
),
|
|
117
|
+
spaceContextMaxLevel: clampLevel(
|
|
118
|
+
raw?.spaceContextMaxLevel,
|
|
119
|
+
DEFAULT_AGENT_BASE_POLICY.spaceContextMaxLevel,
|
|
120
|
+
),
|
|
121
|
+
selfEvolutionMode: normalizeSelfEvolutionMode(
|
|
122
|
+
raw?.selfEvolutionMode,
|
|
123
|
+
DEFAULT_AGENT_BASE_POLICY.selfEvolutionMode,
|
|
124
|
+
),
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export const resolveUserPreferenceProfile = (
|
|
129
|
+
settingsRecord?: Record<string, any> | null,
|
|
130
|
+
): UserPreferenceProfile => {
|
|
131
|
+
const fallbackSpaceLevel =
|
|
132
|
+
settingsRecord?.enableReadCurrentSpace === false
|
|
133
|
+
? 1
|
|
134
|
+
: DEFAULT_USER_PREFERENCE_PROFILE.spaceContextLevel;
|
|
135
|
+
|
|
136
|
+
return {
|
|
137
|
+
version: 1,
|
|
138
|
+
tone: {
|
|
139
|
+
preset: normalizeTonePreset(
|
|
140
|
+
settingsRecord?.userTonePreset,
|
|
141
|
+
DEFAULT_USER_PREFERENCE_PROFILE.tone?.preset ?? "default",
|
|
142
|
+
),
|
|
143
|
+
},
|
|
144
|
+
knowledgeCaptureLevel: clampLevel(
|
|
145
|
+
settingsRecord?.knowledgeCaptureLevel,
|
|
146
|
+
DEFAULT_USER_PREFERENCE_PROFILE.knowledgeCaptureLevel,
|
|
147
|
+
),
|
|
148
|
+
spaceContextLevel: clampLevel(
|
|
149
|
+
settingsRecord?.spaceContextLevel,
|
|
150
|
+
fallbackSpaceLevel,
|
|
151
|
+
),
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const containsAny = (text: string, patterns: string[]): boolean =>
|
|
156
|
+
patterns.some((pattern) => text.includes(pattern));
|
|
157
|
+
|
|
158
|
+
export const inferCaptureIntent = (userInput: string): CaptureIntent => {
|
|
159
|
+
const normalized = userInput.toLowerCase();
|
|
160
|
+
|
|
161
|
+
if (
|
|
162
|
+
containsAny(normalized, [
|
|
163
|
+
"保存",
|
|
164
|
+
"存一下",
|
|
165
|
+
"沉淀",
|
|
166
|
+
"记住",
|
|
167
|
+
"写入文档",
|
|
168
|
+
"建文档",
|
|
169
|
+
"创建文档",
|
|
170
|
+
"导入 skill",
|
|
171
|
+
"导入这个 skill",
|
|
172
|
+
"确认导入",
|
|
173
|
+
"确认导入这个 skill",
|
|
174
|
+
"导入这个技能",
|
|
175
|
+
"确认导入这个技能",
|
|
176
|
+
"创建 skill",
|
|
177
|
+
"创建这个 skill",
|
|
178
|
+
"skill 文档",
|
|
179
|
+
"创建表格",
|
|
180
|
+
"建表",
|
|
181
|
+
"建个表",
|
|
182
|
+
"做个表",
|
|
183
|
+
"做一张表",
|
|
184
|
+
"整理成表",
|
|
185
|
+
"整理成一张表",
|
|
186
|
+
"建立一个表",
|
|
187
|
+
"建立一张表",
|
|
188
|
+
"建立成表",
|
|
189
|
+
"建立成一张表",
|
|
190
|
+
"创建这个表格",
|
|
191
|
+
"确认创建",
|
|
192
|
+
"确认创建这张表格",
|
|
193
|
+
"create doc",
|
|
194
|
+
"import skill",
|
|
195
|
+
"confirm import",
|
|
196
|
+
"create skill",
|
|
197
|
+
"create table",
|
|
198
|
+
"save this",
|
|
199
|
+
"remember this",
|
|
200
|
+
"document this",
|
|
201
|
+
])
|
|
202
|
+
) {
|
|
203
|
+
return "strong";
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (
|
|
207
|
+
containsAny(normalized, [
|
|
208
|
+
"总结",
|
|
209
|
+
"方案",
|
|
210
|
+
"调研",
|
|
211
|
+
"规范",
|
|
212
|
+
"会议纪要",
|
|
213
|
+
"总结一下",
|
|
214
|
+
"research",
|
|
215
|
+
"proposal",
|
|
216
|
+
"spec",
|
|
217
|
+
"summary",
|
|
218
|
+
])
|
|
219
|
+
) {
|
|
220
|
+
return "possible";
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return "none";
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
export const inferSpaceNeed = (userInput: string): SpaceNeed => {
|
|
227
|
+
const normalized = userInput.toLowerCase();
|
|
228
|
+
|
|
229
|
+
if (
|
|
230
|
+
containsAny(normalized, [
|
|
231
|
+
"当前空间",
|
|
232
|
+
"这个空间",
|
|
233
|
+
"这些文档",
|
|
234
|
+
"根据空间",
|
|
235
|
+
"workspace",
|
|
236
|
+
"current space",
|
|
237
|
+
"these docs",
|
|
238
|
+
"based on the docs",
|
|
239
|
+
])
|
|
240
|
+
) {
|
|
241
|
+
return "deep";
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (
|
|
245
|
+
containsAny(normalized, [
|
|
246
|
+
"文档",
|
|
247
|
+
"文件",
|
|
248
|
+
"页面",
|
|
249
|
+
"目录",
|
|
250
|
+
"page",
|
|
251
|
+
"pages",
|
|
252
|
+
"docs",
|
|
253
|
+
"files",
|
|
254
|
+
"目录结构",
|
|
255
|
+
])
|
|
256
|
+
) {
|
|
257
|
+
return "light";
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
return "none";
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
const resolveTonePreset = (
|
|
264
|
+
agentTone: TonePreset,
|
|
265
|
+
userTone: TonePreset,
|
|
266
|
+
mode: ToneResolutionMode,
|
|
267
|
+
): TonePreset => {
|
|
268
|
+
if (mode === "agent_first") {
|
|
269
|
+
return agentTone === "default" ? userTone : agentTone;
|
|
270
|
+
}
|
|
271
|
+
if (mode === "user_first") {
|
|
272
|
+
return userTone === "default" ? agentTone : userTone;
|
|
273
|
+
}
|
|
274
|
+
if (userTone !== "default") return userTone;
|
|
275
|
+
return agentTone;
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
const maxReadCallsPerTurnByLevel = (
|
|
279
|
+
level: SpaceContextLevel,
|
|
280
|
+
need: SpaceNeed,
|
|
281
|
+
): number => {
|
|
282
|
+
if (need === "deep") {
|
|
283
|
+
return { 1: 2, 2: 3, 3: 4, 4: 6 }[level];
|
|
284
|
+
}
|
|
285
|
+
if (need === "light") {
|
|
286
|
+
return { 1: 1, 2: 2, 3: 3, 4: 4 }[level];
|
|
287
|
+
}
|
|
288
|
+
return { 1: 0, 2: 0, 3: 1, 4: 2 }[level];
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
const maxReadCallsPerDialogByLevel = (
|
|
292
|
+
level: SpaceContextLevel,
|
|
293
|
+
need: SpaceNeed,
|
|
294
|
+
): number => {
|
|
295
|
+
if (need === "deep") {
|
|
296
|
+
return { 1: 3, 2: 4, 3: 6, 4: 8 }[level];
|
|
297
|
+
}
|
|
298
|
+
if (need === "light") {
|
|
299
|
+
return { 1: 2, 2: 3, 3: 4, 4: 6 }[level];
|
|
300
|
+
}
|
|
301
|
+
return { 1: 0, 2: 0, 3: 2, 4: 4 }[level];
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
const preloadSummaryCountByLevel = (level: SpaceContextLevel): number =>
|
|
305
|
+
({ 1: 0, 2: 0, 3: 8, 4: 16 }[level]);
|
|
306
|
+
|
|
307
|
+
const preloadBudgetRatioByLevel = (level: SpaceContextLevel): number =>
|
|
308
|
+
({ 1: 0, 2: 0.01, 3: 0.04, 4: 0.08 }[level]);
|
|
309
|
+
|
|
310
|
+
export const resolveRuntimePolicy = (params: {
|
|
311
|
+
agentConfig?: Agent | any;
|
|
312
|
+
settingsRecord?: Record<string, any> | null;
|
|
313
|
+
userInput: string;
|
|
314
|
+
dialogPolicyState?: DialogPolicyState | null;
|
|
315
|
+
}): ResolvedRuntimePolicy => {
|
|
316
|
+
const { agentConfig, settingsRecord, userInput, dialogPolicyState } = params;
|
|
317
|
+
|
|
318
|
+
const agentBasePolicy = resolveAgentBasePolicy(agentConfig);
|
|
319
|
+
const userPreferenceProfile = resolveUserPreferenceProfile(settingsRecord);
|
|
320
|
+
|
|
321
|
+
const knowledgeLevel = Math.min(
|
|
322
|
+
agentBasePolicy.knowledgeCaptureMaxLevel,
|
|
323
|
+
userPreferenceProfile.knowledgeCaptureLevel,
|
|
324
|
+
) as KnowledgeCaptureLevel;
|
|
325
|
+
const spaceLevel = Math.min(
|
|
326
|
+
agentBasePolicy.spaceContextMaxLevel,
|
|
327
|
+
userPreferenceProfile.spaceContextLevel,
|
|
328
|
+
) as SpaceContextLevel;
|
|
329
|
+
|
|
330
|
+
const captureIntent = inferCaptureIntent(userInput);
|
|
331
|
+
const spaceNeed = inferSpaceNeed(userInput);
|
|
332
|
+
const explicitCaptureRequest = captureIntent === "strong";
|
|
333
|
+
const explicitSpaceRequest = spaceNeed !== "none";
|
|
334
|
+
|
|
335
|
+
const currentAutoCreates = Math.max(
|
|
336
|
+
0,
|
|
337
|
+
Number(dialogPolicyState?.autoKnowledgeCaptureCount ?? 0),
|
|
338
|
+
);
|
|
339
|
+
const currentAutoReads = Math.max(
|
|
340
|
+
0,
|
|
341
|
+
Number(dialogPolicyState?.autoSpaceReadCount ?? 0),
|
|
342
|
+
);
|
|
343
|
+
|
|
344
|
+
let knowledgeMode: KnowledgeCaptureMode = "blocked";
|
|
345
|
+
if (explicitCaptureRequest) {
|
|
346
|
+
knowledgeMode = "auto";
|
|
347
|
+
} else if (knowledgeLevel === 2) {
|
|
348
|
+
knowledgeMode = "ask";
|
|
349
|
+
} else if (knowledgeLevel === 3) {
|
|
350
|
+
knowledgeMode = "suggest";
|
|
351
|
+
} else if (knowledgeLevel >= 4 && captureIntent !== "none") {
|
|
352
|
+
knowledgeMode = "auto";
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
return {
|
|
356
|
+
tonePreset: resolveTonePreset(
|
|
357
|
+
agentBasePolicy.tone?.preset ?? "default",
|
|
358
|
+
userPreferenceProfile.tone?.preset ?? "default",
|
|
359
|
+
agentBasePolicy.tone?.resolutionMode ?? "blend",
|
|
360
|
+
),
|
|
361
|
+
toneResolutionMode: agentBasePolicy.tone?.resolutionMode ?? "blend",
|
|
362
|
+
knowledgeCapture: {
|
|
363
|
+
level: knowledgeLevel,
|
|
364
|
+
mode: knowledgeMode,
|
|
365
|
+
explicitRequest: explicitCaptureRequest,
|
|
366
|
+
maxAutoCreatesPerDialog: explicitCaptureRequest ? 99 : 1,
|
|
367
|
+
currentAutoCreates,
|
|
368
|
+
captureIntent,
|
|
369
|
+
},
|
|
370
|
+
spaceContext: {
|
|
371
|
+
level: spaceLevel,
|
|
372
|
+
explicitRequest: explicitSpaceRequest,
|
|
373
|
+
need: spaceNeed,
|
|
374
|
+
maxReadCallsPerTurn: maxReadCallsPerTurnByLevel(spaceLevel, spaceNeed),
|
|
375
|
+
maxReadCallsPerDialog: maxReadCallsPerDialogByLevel(spaceLevel, spaceNeed),
|
|
376
|
+
currentAutoReads,
|
|
377
|
+
preloadSummaryCount: preloadSummaryCountByLevel(spaceLevel),
|
|
378
|
+
preloadBudgetRatio: preloadBudgetRatioByLevel(spaceLevel),
|
|
379
|
+
},
|
|
380
|
+
selfEvolutionMode: agentBasePolicy.selfEvolutionMode,
|
|
381
|
+
};
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
export const buildUserPolicyContext = (
|
|
385
|
+
policy: ResolvedRuntimePolicy,
|
|
386
|
+
): string => {
|
|
387
|
+
const lines = [
|
|
388
|
+
`用户语气偏好:${policy.tonePreset}`,
|
|
389
|
+
`知识沉淀级别:${policy.knowledgeCapture.level}(当前模式:${policy.knowledgeCapture.mode})`,
|
|
390
|
+
`空间上下文级别:${policy.spaceContext.level}(本轮最多自动 read ${policy.spaceContext.maxReadCallsPerTurn} 次)`,
|
|
391
|
+
"如果工具返回 policy limit,不要重试同一路径,应改为解释限制、先给答案或向用户确认。",
|
|
392
|
+
];
|
|
393
|
+
|
|
394
|
+
if (policy.knowledgeCapture.mode === "ask") {
|
|
395
|
+
lines.push("当前用户偏好要求:创建知识文档前先询问用户。");
|
|
396
|
+
} else if (policy.knowledgeCapture.mode === "suggest") {
|
|
397
|
+
lines.push("当前用户偏好要求:先完成回答,再建议是否沉淀成文档/表格。");
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
return lines.join("\n");
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
export const buildStaticUserPolicyContext = (params: {
|
|
404
|
+
agentConfig?: Agent | any;
|
|
405
|
+
settingsRecord?: Record<string, any> | null;
|
|
406
|
+
}): string => {
|
|
407
|
+
const agentBasePolicy = resolveAgentBasePolicy(params.agentConfig);
|
|
408
|
+
const userPreferenceProfile = resolveUserPreferenceProfile(params.settingsRecord);
|
|
409
|
+
const tonePreset = resolveTonePreset(
|
|
410
|
+
agentBasePolicy.tone?.preset ?? "default",
|
|
411
|
+
userPreferenceProfile.tone?.preset ?? "default",
|
|
412
|
+
agentBasePolicy.tone?.resolutionMode ?? "blend",
|
|
413
|
+
);
|
|
414
|
+
|
|
415
|
+
return [
|
|
416
|
+
`用户语气偏好:${tonePreset}`,
|
|
417
|
+
`知识沉淀级别:${Math.min(agentBasePolicy.knowledgeCaptureMaxLevel, userPreferenceProfile.knowledgeCaptureLevel)}`,
|
|
418
|
+
`空间上下文级别:${Math.min(agentBasePolicy.spaceContextMaxLevel, userPreferenceProfile.spaceContextLevel)}`,
|
|
419
|
+
"请尽量保留 agent 自身角色设定,同时按用户偏好调整表达和自动化程度。",
|
|
420
|
+
].join("\n");
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
export const resolveSpaceContextPreloadPlan = (level: SpaceContextLevel) => ({
|
|
424
|
+
preloadSummaryCount: preloadSummaryCountByLevel(level),
|
|
425
|
+
preloadBudgetRatio: preloadBudgetRatioByLevel(level),
|
|
426
|
+
includeRecentContent: level >= 3,
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
export const isBudgetedWorkspaceReadKey = (dbKey: string): boolean => {
|
|
430
|
+
const normalized = dbKey.toLowerCase();
|
|
431
|
+
return (
|
|
432
|
+
normalized.startsWith("page-") ||
|
|
433
|
+
normalized.startsWith("dialog-") ||
|
|
434
|
+
normalized.startsWith("space-") ||
|
|
435
|
+
normalized.startsWith("table-") ||
|
|
436
|
+
normalized.startsWith("table_row-") ||
|
|
437
|
+
normalized.startsWith("row-") ||
|
|
438
|
+
normalized.startsWith("meta-")
|
|
439
|
+
);
|
|
440
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export const AGENT_UPDATE_FIELD_NAMES = [
|
|
2
|
+
"name",
|
|
3
|
+
"model",
|
|
4
|
+
"provider",
|
|
5
|
+
"prompt",
|
|
6
|
+
"introduction",
|
|
7
|
+
"greeting",
|
|
8
|
+
"isPublic",
|
|
9
|
+
"tags",
|
|
10
|
+
"tools",
|
|
11
|
+
"references",
|
|
12
|
+
"temperature",
|
|
13
|
+
"top_p",
|
|
14
|
+
"frequency_penalty",
|
|
15
|
+
"presence_penalty",
|
|
16
|
+
"max_tokens",
|
|
17
|
+
"reasoning_effort",
|
|
18
|
+
] as const;
|
|
19
|
+
|
|
20
|
+
export type AgentUpdateField = (typeof AGENT_UPDATE_FIELD_NAMES)[number];
|
|
21
|
+
|
|
22
|
+
export const DEFAULT_AUTO_APPROVED_SELF_UPDATE_FIELDS: AgentUpdateField[] = [
|
|
23
|
+
"greeting",
|
|
24
|
+
"introduction",
|
|
25
|
+
"tags",
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
const VALID_AGENT_UPDATE_FIELDS = new Set<string>(AGENT_UPDATE_FIELD_NAMES);
|
|
29
|
+
|
|
30
|
+
export const normalizeAgentUpdateFieldList = (
|
|
31
|
+
value: unknown,
|
|
32
|
+
fallback: readonly AgentUpdateField[] = DEFAULT_AUTO_APPROVED_SELF_UPDATE_FIELDS,
|
|
33
|
+
): AgentUpdateField[] => {
|
|
34
|
+
if (!Array.isArray(value)) {
|
|
35
|
+
return [...fallback];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const normalized = Array.from(
|
|
39
|
+
new Set(
|
|
40
|
+
value.filter(
|
|
41
|
+
(item): item is AgentUpdateField =>
|
|
42
|
+
typeof item === "string" && VALID_AGENT_UPDATE_FIELDS.has(item),
|
|
43
|
+
),
|
|
44
|
+
),
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
return normalized;
|
|
48
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export type TonePreset =
|
|
2
|
+
| "default"
|
|
3
|
+
| "professional"
|
|
4
|
+
| "friendly"
|
|
5
|
+
| "direct"
|
|
6
|
+
| "pragmatic";
|
|
7
|
+
|
|
8
|
+
export type ToneResolutionMode = "agent_first" | "user_first" | "blend";
|
|
9
|
+
|
|
10
|
+
export type KnowledgeCaptureLevel = 1 | 2 | 3 | 4;
|
|
11
|
+
export type SpaceContextLevel = 1 | 2 | 3 | 4;
|
|
12
|
+
|
|
13
|
+
export type SelfEvolutionMode =
|
|
14
|
+
| "none"
|
|
15
|
+
| "knowledge_only"
|
|
16
|
+
| "prompt_and_refs"
|
|
17
|
+
| "full";
|
|
18
|
+
|
|
19
|
+
export interface AgentBasePolicy {
|
|
20
|
+
version: 1;
|
|
21
|
+
tone?: {
|
|
22
|
+
preset?: TonePreset;
|
|
23
|
+
resolutionMode?: ToneResolutionMode;
|
|
24
|
+
};
|
|
25
|
+
knowledgeCaptureMaxLevel: KnowledgeCaptureLevel;
|
|
26
|
+
spaceContextMaxLevel: SpaceContextLevel;
|
|
27
|
+
selfEvolutionMode: SelfEvolutionMode;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface UserPreferenceProfile {
|
|
31
|
+
version: 1;
|
|
32
|
+
tone?: {
|
|
33
|
+
preset?: TonePreset;
|
|
34
|
+
};
|
|
35
|
+
knowledgeCaptureLevel: KnowledgeCaptureLevel;
|
|
36
|
+
spaceContextLevel: SpaceContextLevel;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface DialogPolicyState {
|
|
40
|
+
autoKnowledgeCaptureCount?: number;
|
|
41
|
+
autoSpaceReadCount?: number;
|
|
42
|
+
updatedAt?: number;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const DEFAULT_AGENT_BASE_POLICY: AgentBasePolicy = {
|
|
46
|
+
version: 1,
|
|
47
|
+
tone: {
|
|
48
|
+
preset: "default",
|
|
49
|
+
resolutionMode: "blend",
|
|
50
|
+
},
|
|
51
|
+
knowledgeCaptureMaxLevel: 4,
|
|
52
|
+
spaceContextMaxLevel: 4,
|
|
53
|
+
selfEvolutionMode: "knowledge_only",
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export const DEFAULT_USER_PREFERENCE_PROFILE: UserPreferenceProfile = {
|
|
57
|
+
version: 1,
|
|
58
|
+
tone: {
|
|
59
|
+
preset: "default",
|
|
60
|
+
},
|
|
61
|
+
knowledgeCaptureLevel: 2,
|
|
62
|
+
spaceContextLevel: 3,
|
|
63
|
+
};
|
|
64
|
+
|