nolo-cli 0.1.10 → 0.1.11
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 +0 -32
- package/agentRuntimeCommands.ts +3 -3
- package/commandRegistry.ts +2 -2
- package/machineCommands.ts +31 -6
- package/package.json +6 -22
- package/ai/agent/_executeModel.ts +0 -118
- package/ai/agent/agentSlice.ts +0 -525
- package/ai/agent/appWorkingMemory.ts +0 -126
- package/ai/agent/avatarUtils.ts +0 -24
- package/ai/agent/buildEditingContext.ts +0 -373
- package/ai/agent/buildSystemPrompt.ts +0 -532
- package/ai/agent/cleanAgentMessages.ts +0 -140
- package/ai/agent/cliChatClient.ts +0 -119
- package/ai/agent/cliExecutor.ts +0 -733
- package/ai/agent/cliPrompt.ts +0 -10
- package/ai/agent/contextCompiler.ts +0 -107
- package/ai/agent/contextLayerContract.ts +0 -44
- package/ai/agent/createAgentSchema.ts +0 -234
- package/ai/agent/executeToolCall.ts +0 -58
- package/ai/agent/fetchAgentContexts.ts +0 -42
- package/ai/agent/generatePrompt.ts +0 -3
- package/ai/agent/getFullChatContextKeys.ts +0 -168
- package/ai/agent/hooks/fetchPublicAgents.ts +0 -133
- package/ai/agent/hooks/useAgentConfig.ts +0 -61
- package/ai/agent/hooks/useAgentDialog.ts +0 -35
- package/ai/agent/hooks/useAgentFormValidation.ts +0 -202
- package/ai/agent/hooks/usePublicAgents.ts +0 -473
- package/ai/agent/machineRunPermissions.ts +0 -95
- package/ai/agent/persistMessageWithFixedId.ts +0 -37
- package/ai/agent/planSlice.ts +0 -259
- package/ai/agent/referenceUtils.ts +0 -229
- package/ai/agent/runAgentBackground.ts +0 -238
- package/ai/agent/runAgentClientLoop.ts +0 -138
- package/ai/agent/runtimeGuidance.ts +0 -97
- package/ai/agent/runtimeServerBase.ts +0 -37
- package/ai/agent/server/fetchPublicAgents.ts +0 -128
- package/ai/agent/startParallelAgentStreams.ts +0 -424
- package/ai/agent/startupProtocol.ts +0 -53
- package/ai/agent/streamAgentChatTurn.ts +0 -1278
- package/ai/agent/streamAgentChatTurnUtils.ts +0 -738
- package/ai/agent/types.ts +0 -71
- package/ai/agent/utils/imageOutput.ts +0 -33
- package/ai/agent/utils/sortUtils.ts +0 -250
- package/ai/agent/web/referencePickerUtils.ts +0 -146
- package/ai/ai.locale.ts +0 -1079
- package/ai/chat/accumulateToolCallChunks.ts +0 -95
- package/ai/chat/fetchUtils.native.ts +0 -276
- package/ai/chat/fetchUtils.ts +0 -153
- package/ai/chat/parseApiError.ts +0 -64
- package/ai/chat/parseMultilineSSE.ts +0 -95
- package/ai/chat/sendOpenAICompletionsRequest.native.ts +0 -682
- package/ai/chat/sendOpenAICompletionsRequest.ts +0 -703
- package/ai/chat/sendOpenAIResponseRequest.ts +0 -491
- package/ai/chat/shouldUseServerProxy.ts +0 -18
- package/ai/chat/sseClient.native.ts +0 -91
- package/ai/chat/sseClient.ts +0 -67
- package/ai/chat/streamReader.native.ts +0 -31
- package/ai/chat/streamReader.ts +0 -62
- package/ai/chat/updateTotalUsage.ts +0 -72
- package/ai/context/buildReferenceContext.ts +0 -437
- package/ai/context/calculateContextUsage.ts +0 -133
- package/ai/context/retention.ts +0 -165
- package/ai/context/tokenUtils.ts +0 -78
- package/ai/index.ts +0 -1
- package/ai/llm/calculateGeminiImageTokens.ts +0 -57
- package/ai/llm/deepinfra.ts +0 -28
- package/ai/llm/fireworks.ts +0 -50
- package/ai/llm/generateRequestBody.ts +0 -165
- package/ai/llm/getModelContextWindow.ts +0 -84
- package/ai/llm/getNoloKey.ts +0 -31
- package/ai/llm/getPricing.ts +0 -199
- package/ai/llm/hooks/useModelPricing.ts +0 -75
- package/ai/llm/imagePricing.ts +0 -40
- package/ai/llm/isResponseAPIModel.ts +0 -13
- package/ai/llm/mimo.ts +0 -71
- package/ai/llm/mistral.ts +0 -22
- package/ai/llm/modelAvatar.ts +0 -427
- package/ai/llm/models.ts +0 -45
- package/ai/llm/openrouterModels.ts +0 -269
- package/ai/llm/providers.ts +0 -306
- package/ai/llm/reasoningModels.ts +0 -28
- package/ai/llm/types.ts +0 -59
- package/ai/llm/usageRequestOptions.ts +0 -59
- package/ai/memory/capture.ts +0 -148
- package/ai/memory/consolidate.ts +0 -104
- package/ai/memory/delete.ts +0 -147
- package/ai/memory/overlay.ts +0 -84
- package/ai/memory/query.ts +0 -38
- package/ai/memory/queryShared.ts +0 -160
- package/ai/memory/rank.ts +0 -105
- package/ai/memory/recentRelationshipRecap.ts +0 -249
- package/ai/memory/remember.ts +0 -167
- package/ai/memory/runtime.ts +0 -76
- package/ai/memory/store.ts +0 -20
- package/ai/memory/storeShared.ts +0 -76
- package/ai/memory/types.ts +0 -46
- package/ai/memory/understanding.ts +0 -349
- package/ai/memory/understandingGreeting.ts +0 -264
- package/ai/messages/type.ts +0 -20
- package/ai/policy/personalizationDialog.ts +0 -333
- package/ai/policy/runtimePolicy.ts +0 -440
- package/ai/policy/selfUpdateFields.ts +0 -48
- package/ai/policy/types.ts +0 -64
- package/ai/skills/referenceRuntime.ts +0 -274
- package/ai/skills/skillDiagnostics.ts +0 -251
- package/ai/skills/skillDocBuilder.ts +0 -139
- package/ai/skills/skillDocProtocol.ts +0 -434
- package/ai/skills/skillReferenceSummary.ts +0 -63
- package/ai/skills/skillSummaryMarker.ts +0 -26
- package/ai/token/calculatePrice.ts +0 -544
- package/ai/token/db.ts +0 -98
- package/ai/token/externalToolCost.ts +0 -330
- package/ai/token/hooks/useRecords.ts +0 -65
- package/ai/token/missingUsageEstimate.ts +0 -42
- package/ai/token/modelUsageQuery.ts +0 -252
- package/ai/token/normalizeUsage.ts +0 -84
- package/ai/token/openaiImageGenerationUsage.ts +0 -56
- package/ai/token/prepareTokenUsageData.ts +0 -88
- package/ai/token/query.ts +0 -88
- package/ai/token/queryUserTokens.ts +0 -59
- package/ai/token/resolveBillingTarget.ts +0 -52
- package/ai/token/saveTokenRecord.ts +0 -53
- package/ai/token/serverDialogProjection.ts +0 -78
- package/ai/token/serverTokenWriter.ts +0 -143
- package/ai/token/stats.ts +0 -21
- package/ai/token/tokenThunks.ts +0 -24
- package/ai/token/types.ts +0 -93
- package/ai/tools/agent/agentTools.ts +0 -176
- package/ai/tools/agent/agentUpdateShared.ts +0 -311
- package/ai/tools/agent/callAgentTool.ts +0 -139
- package/ai/tools/agent/createAgentTool.ts +0 -512
- package/ai/tools/agent/createDialogTool.ts +0 -69
- package/ai/tools/agent/createSkillAgentTool.ts +0 -62
- package/ai/tools/agent/parallelBudget.ts +0 -221
- package/ai/tools/agent/presets/appBuilderPreset.ts +0 -145
- package/ai/tools/agent/runLlmTool.ts +0 -96
- package/ai/tools/agent/runStreamingAgentTool.ts +0 -73
- package/ai/tools/agent/skillAgentArgs.ts +0 -106
- package/ai/tools/agent/skillAgentPreset.ts +0 -89
- package/ai/tools/agent/streamParallelAgentsTool.ts +0 -122
- package/ai/tools/agent/updateAgentTool.ts +0 -96
- package/ai/tools/agent/updateSelfTool.ts +0 -113
- package/ai/tools/amazonProductScraperTool.ts +0 -86
- package/ai/tools/apifyActorClient.ts +0 -45
- package/ai/tools/appEditGuard.ts +0 -372
- package/ai/tools/appReadSnapshot.ts +0 -153
- package/ai/tools/appTools.ts +0 -1549
- package/ai/tools/applyEditTool.ts +0 -256
- package/ai/tools/applyLineEditsTool.ts +0 -312
- package/ai/tools/browserTools/click.ts +0 -33
- package/ai/tools/browserTools/closeSession.ts +0 -29
- package/ai/tools/browserTools/common.ts +0 -27
- package/ai/tools/browserTools/openSession.ts +0 -48
- package/ai/tools/browserTools/readContent.ts +0 -38
- package/ai/tools/browserTools/selectOption.ts +0 -46
- package/ai/tools/browserTools/typeText.ts +0 -42
- package/ai/tools/category/createCategoryTool.ts +0 -66
- package/ai/tools/category/queryContentsByCategoryTool.ts +0 -69
- package/ai/tools/category/updateContentCategoryTool.ts +0 -75
- package/ai/tools/cfBrowserTools.ts +0 -319
- package/ai/tools/cfSpeechToTextTool.ts +0 -49
- package/ai/tools/checkEnvTool.ts +0 -65
- package/ai/tools/cloudflareCrawlTool.ts +0 -289
- package/ai/tools/codeSearchTool.ts +0 -111
- package/ai/tools/codeTools.ts +0 -101
- package/ai/tools/createDocTool.ts +0 -132
- package/ai/tools/createPlanTool.ts +0 -999
- package/ai/tools/createSkillDocTool.ts +0 -155
- package/ai/tools/createWorkflowTool.ts +0 -154
- package/ai/tools/deepseekOcrTool.ts +0 -34
- package/ai/tools/delayTool.ts +0 -31
- package/ai/tools/deleteSpacesTool.ts +0 -325
- package/ai/tools/deleteSpacesToolModel.ts +0 -159
- package/ai/tools/devReloadUtils.ts +0 -29
- package/ai/tools/dialogMessageSearch.ts +0 -137
- package/ai/tools/doctorSkillTool.ts +0 -72
- package/ai/tools/ecommerceScraperTool.ts +0 -86
- package/ai/tools/emailTools.ts +0 -549
- package/ai/tools/evalSkillTool.ts +0 -92
- package/ai/tools/exaSearchTool.ts +0 -64
- package/ai/tools/execBashTool.ts +0 -379
- package/ai/tools/executeSqlTool.ts +0 -192
- package/ai/tools/fetchWebpageSupport.ts +0 -309
- package/ai/tools/fetchWebpageTool.ts +0 -84
- package/ai/tools/geminiImagePreviewTool.ts +0 -361
- package/ai/tools/generateDocxTool.ts +0 -215
- package/ai/tools/googleSearchScraperTool.ts +0 -106
- package/ai/tools/importDataTool.ts +0 -133
- package/ai/tools/importSkillTool.ts +0 -162
- package/ai/tools/index.ts +0 -1858
- package/ai/tools/listFilesTool.ts +0 -82
- package/ai/tools/listUserSpacesTool.ts +0 -113
- package/ai/tools/modelUsageTools.ts +0 -142
- package/ai/tools/olmOcrTool.ts +0 -34
- package/ai/tools/openaiImageTool.ts +0 -218
- package/ai/tools/paddleOcrTool.ts +0 -34
- package/ai/tools/prepareTools.ts +0 -23
- package/ai/tools/readDocTool.ts +0 -84
- package/ai/tools/readFileTool.ts +0 -211
- package/ai/tools/readTool.ts +0 -163
- package/ai/tools/readXPostTool.ts +0 -233
- package/ai/tools/rememberMemoryTool.ts +0 -84
- package/ai/tools/remotionVideoTool.ts +0 -151
- package/ai/tools/searchDialogMessagesTool.ts +0 -222
- package/ai/tools/searchRepoTool.ts +0 -115
- package/ai/tools/searchWorkspaceTool.ts +0 -259
- package/ai/tools/skillFollowup.ts +0 -86
- package/ai/tools/surfWeatherTool.ts +0 -169
- package/ai/tools/table/addTableRowTool.ts +0 -217
- package/ai/tools/table/createTableTool.ts +0 -315
- package/ai/tools/table/rowTools.ts +0 -366
- package/ai/tools/table/schemaTools.ts +0 -244
- package/ai/tools/table/shareTableTool.ts +0 -148
- package/ai/tools/table/toolShared.ts +0 -129
- package/ai/tools/toolApiClient.ts +0 -198
- package/ai/tools/toolNameAliases.ts +0 -57
- package/ai/tools/toolResultError.ts +0 -42
- package/ai/tools/toolRunSlice.ts +0 -303
- package/ai/tools/toolSchemaCompatibility.ts +0 -53
- package/ai/tools/toolVisibility.ts +0 -4
- package/ai/tools/types.ts +0 -20
- package/ai/tools/uiAskChoiceTool.ts +0 -104
- package/ai/tools/updateContentTitleTool.ts +0 -84
- package/ai/tools/updateDocTool.ts +0 -105
- package/ai/tools/updateUserPreferenceProfileTool.ts +0 -145
- package/ai/tools/whisperTool.ts +0 -77
- package/ai/tools/writeFileTool.ts +0 -210
- package/ai/tools/youtubeScraperTool.ts +0 -116
- package/ai/tools/ziweiChartTool.ts +0 -678
- package/ai/types.ts +0 -55
- package/ai/workflow/workflowExecutor.ts +0 -323
- package/ai/workflow/workflowSlice.ts +0 -73
- package/ai/workflow/workflowTypes.ts +0 -106
- package/client/compactDialog.ts +0 -222
- package/connector-experimental/capabilities.ts +0 -73
- package/connector-experimental/codexBinary.ts +0 -41
- package/connector-experimental/heartbeatLoop.ts +0 -22
- package/connector-experimental/index.ts +0 -5
- package/connector-experimental/machineInfo.ts +0 -46
- package/connector-experimental/protocol.ts +0 -54
|
@@ -1,440 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,48 +0,0 @@
|
|
|
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
|
-
};
|
package/ai/policy/types.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
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
|
-
|