nolo-cli 0.1.41 → 0.1.42
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 +27 -12
- package/agent-runtime/agentThread.ts +222 -0
- package/agent-runtime/agentThreadAdmission.ts +74 -0
- package/agent-runtime/dialogWritePlan.ts +42 -0
- package/agent-runtime/hostAdapter.ts +1 -0
- package/agent-runtime/index.ts +43 -0
- package/agent-runtime/localLoop.ts +31 -2
- package/agent-runtime/localToolPolicy.ts +1 -0
- package/agent-runtime/localWorkspaceTools.ts +1258 -78
- package/agent-runtime/noloWorkspaceTools.ts +20 -1
- package/agent-runtime/runtimeToolPolicy.ts +1 -5
- package/agent-runtime/runtimeToolSurface.ts +1 -0
- package/agentAliases.ts +29 -9
- package/agentInternalCommandEntries.ts +11 -3
- package/agentMachineCommands.ts +1 -0
- package/agentRecordCommands.ts +2 -2
- package/agentRecordHelpers.ts +59 -6
- package/agentRunCommand.ts +84 -19
- package/ai/agent/buildSystemPrompt.ts +14 -0
- package/ai/agent/cliExecutor.ts +202 -43
- package/ai/agent/createAgentSchema.ts +2 -2
- package/ai/agent/liveAudioModel.ts +1 -1
- package/ai/agent/streamAgentChatTurn.ts +154 -20
- package/ai/agent/streamAgentChatTurnUtils.ts +63 -0
- package/ai/ai.locale.ts +70 -0
- package/ai/chat/inlineImageUrlsForCustomProvider.ts +7 -2
- package/ai/chat/sendOpenAICompletionsRequest.ts +25 -1
- package/ai/llm/kimi.ts +0 -1
- package/ai/llm/openrouterModels.ts +27 -2
- package/ai/memory/policy.ts +49 -0
- package/ai/memory/queryShared.ts +10 -4
- package/ai/memory/recentRelationshipRecap.ts +4 -0
- package/ai/memory/remember.ts +48 -104
- package/ai/memory/scope.ts +74 -0
- package/ai/memory/types.ts +6 -0
- package/ai/memory/understanding.ts +10 -18
- package/ai/policy/runtimePolicy.ts +95 -23
- package/ai/tools/agent/agentTools.ts +0 -21
- package/ai/tools/agent/startAgentDialogTool.ts +2 -1
- package/ai/tools/index.ts +2 -20
- package/ai/tools/prepareTools.ts +171 -1
- package/ai/tools/readXhsProfileTool.ts +80 -69
- package/ai/tools/table/createTableTool.ts +11 -0
- package/ai/tools/toolPacks.ts +19 -0
- package/ai/types.ts +3 -0
- package/app/favorite/deletedFavoriteProjection.ts +31 -0
- package/app/hooks/deleteDbKey.ts +24 -3
- package/app/i18n/translations/interface.locale.ts +48 -16
- package/app/types/appSummary.ts +4 -0
- package/app/utils/desktopAgentRuntimeTurnClient.ts +2 -0
- package/auth/adminPermissions.ts +64 -4
- package/auth/routes.ts +5 -0
- package/chat/chat.locale.ts +4 -0
- package/chat/dialog/actions/handleSendMessageAction.ts +7 -2
- package/chat/dialog/dialogAttachmentCleanup.ts +135 -0
- package/chat/dialog/dialogSlice.ts +117 -4
- package/chat/messages/activityCompletion.ts +97 -0
- package/chat/messages/imagePayloadPersistence.ts +22 -0
- package/chat/messages/messageContent.ts +20 -16
- package/chat/messages/messageSlice.ts +20 -1
- package/chat/messages/toolThunks.ts +32 -11
- package/chat/messages/types.ts +8 -1
- package/chat/messages/web/toolDisplayName.ts +686 -0
- package/cli/agentAliases.ts +29 -9
- package/cli/agentInternalCommandEntries.ts +11 -3
- package/cli/agentMachineCommands.ts +1 -0
- package/cli/agentRecordCommands.ts +2 -2
- package/cli/agentRecordHelpers.ts +59 -6
- package/cli/agentRunCommand.ts +84 -19
- package/cli/client/agentRun.ts +65 -253
- package/cli/client/localRuntimeAdapter.ts +179 -53
- package/cli/commandRegistry.ts +7 -4
- package/cli/dialogAttachmentCleanup.ts +151 -0
- package/cli/dialogCommands.ts +163 -61
- package/cli/dialogInternalCommandEntries.ts +1 -1
- package/cli/docCreateCommands.ts +345 -0
- package/cli/docInternalCommandEntries.ts +11 -0
- package/cli/docPageHelpers.ts +80 -0
- package/cli/docSkillHelpers.ts +67 -0
- package/cli/docSpaceHelpers.ts +46 -0
- package/cli/internalCommandEntries.ts +4 -0
- package/cli/machineCommands.ts +18 -34
- package/cli/memoryCommands.ts +253 -0
- package/cli/memoryInternalCommandEntries.ts +9 -0
- package/cli/qoderUsageProbe.ts +252 -0
- package/cli/scriptCommandEntries.ts +0 -3
- package/cli/secretScan.ts +31 -0
- package/cli/tableCommands.ts +248 -13
- package/cli/workflowInternalCommandEntries.ts +2 -3
- package/client/agentRun.test.ts +68 -84
- package/client/agentRun.ts +65 -253
- package/client/localRuntimeAdapter.test.ts +505 -74
- package/client/localRuntimeAdapter.ts +179 -53
- package/commandRegistry.ts +7 -4
- package/connector-experimental/capabilities.ts +10 -9
- package/create/space/sidebarVisibleTypes.ts +19 -0
- package/dialogAttachmentCleanup.ts +151 -0
- package/dialogCommands.ts +163 -61
- package/dialogInternalCommandEntries.ts +1 -1
- package/docCreateCommands.ts +345 -0
- package/docInternalCommandEntries.ts +11 -0
- package/docPageHelpers.ts +80 -0
- package/docSkillHelpers.ts +67 -0
- package/docSpaceHelpers.ts +46 -0
- package/integrations/google/models.ts +4 -4
- package/integrations/openai/generateOpenAIRequestBody.ts +0 -3
- package/integrations/xhs-reader/types.ts +36 -3
- package/integrations/xhs-reader/url.ts +24 -1
- package/internalCommandEntries.ts +4 -0
- package/machineCommands.ts +18 -34
- package/memoryCommands.ts +253 -0
- package/memoryInternalCommandEntries.ts +9 -0
- package/package.json +133 -114
- package/qoderUsageProbe.ts +252 -0
- package/render/contentIcon/types.ts +167 -0
- package/render/page/docSlice.ts +30 -3
- package/render/page/types.ts +2 -0
- package/render/table/createTableAction.ts +4 -0
- package/render/table/tableSlice.ts +61 -0
- package/render/table/types.ts +10 -0
- package/scriptCommandEntries.ts +0 -3
- package/secretScan.ts +31 -0
- package/server/handlers/agentRun/types.ts +24 -23
- package/tableCommands.ts +248 -13
- package/workflowInternalCommandEntries.ts +2 -3
- package/ai/tools/agent/taskRunTool.ts +0 -112
- package/cli/client/taskRunPrompt.ts +0 -27
- package/cli/taskRunCommand.ts +0 -265
- package/client/taskRunPrompt.ts +0 -27
- package/integrations/xhs-reader/analyze/profileAnalyzer.ts +0 -205
- package/integrations/xhs-reader/backends/playwrightProfileCollector.ts +0 -624
- package/integrations/xhs-reader/bridge/readXhsProfileWithBridge.ts +0 -227
- package/integrations/xhs-reader/client/xhsWebApiClient.ts +0 -229
- package/integrations/xhs-reader/normalize.ts +0 -390
- package/integrations/xhs-reader/orchestrator.ts +0 -178
- package/taskRunCommand.ts +0 -265
package/ai/memory/remember.ts
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import serverDb from "../../database/server/db";
|
|
2
|
+
import { resolveScopedMemoryTargets, type MemoryScope } from "./scope";
|
|
2
3
|
import { createMemoryItem, writeMemoryItemWithIndexesToDb } from "./store";
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import type {
|
|
5
|
+
MemoryItem,
|
|
6
|
+
MemoryKind,
|
|
7
|
+
MemoryOwnerType,
|
|
8
|
+
MemorySubjectType,
|
|
9
|
+
MemoryVisibility,
|
|
10
|
+
} from "./types";
|
|
11
|
+
|
|
12
|
+
export type RememberMemoryScope = MemoryScope;
|
|
6
13
|
|
|
7
14
|
export interface RememberMemoryInput {
|
|
8
15
|
db?: any;
|
|
@@ -15,10 +22,11 @@ export interface RememberMemoryInput {
|
|
|
15
22
|
}
|
|
16
23
|
|
|
17
24
|
export interface RememberMemoryResult {
|
|
18
|
-
success: true;
|
|
19
|
-
content: string;
|
|
20
|
-
requestedScope: RememberMemoryScope;
|
|
21
|
-
|
|
25
|
+
success: true;
|
|
26
|
+
content: string;
|
|
27
|
+
requestedScope: RememberMemoryScope;
|
|
28
|
+
savedItems: MemoryItem[];
|
|
29
|
+
resolvedScopes: Array<{
|
|
22
30
|
ownerType: MemoryOwnerType;
|
|
23
31
|
ownerId: string;
|
|
24
32
|
subjectType: MemorySubjectType;
|
|
@@ -29,85 +37,6 @@ export interface RememberMemoryResult {
|
|
|
29
37
|
|
|
30
38
|
const MEMORY_KINDS = new Set<MemoryKind>(["episodic", "semantic", "procedural"]);
|
|
31
39
|
|
|
32
|
-
const buildRememberTargets = (input: {
|
|
33
|
-
userId?: string | null;
|
|
34
|
-
spaceId?: string | null;
|
|
35
|
-
scope: RememberMemoryScope;
|
|
36
|
-
}): Array<{
|
|
37
|
-
ownerType: MemoryOwnerType;
|
|
38
|
-
ownerId: string;
|
|
39
|
-
visibility: MemoryVisibility;
|
|
40
|
-
subjectType: MemorySubjectType;
|
|
41
|
-
subjectId: string;
|
|
42
|
-
}> => {
|
|
43
|
-
if (input.scope === "user") {
|
|
44
|
-
if (!input.userId) {
|
|
45
|
-
throw new Error("rememberMemory: user scope requires userId");
|
|
46
|
-
}
|
|
47
|
-
return [
|
|
48
|
-
{
|
|
49
|
-
ownerType: "user",
|
|
50
|
-
ownerId: input.userId,
|
|
51
|
-
visibility: "private",
|
|
52
|
-
subjectType: "user",
|
|
53
|
-
subjectId: input.userId,
|
|
54
|
-
},
|
|
55
|
-
];
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (input.scope === "space") {
|
|
59
|
-
if (input.spaceId) {
|
|
60
|
-
return [
|
|
61
|
-
{
|
|
62
|
-
ownerType: "space",
|
|
63
|
-
ownerId: input.spaceId,
|
|
64
|
-
visibility: "shared",
|
|
65
|
-
subjectType: "space",
|
|
66
|
-
subjectId: input.spaceId,
|
|
67
|
-
},
|
|
68
|
-
];
|
|
69
|
-
}
|
|
70
|
-
if (input.userId) {
|
|
71
|
-
return [
|
|
72
|
-
{
|
|
73
|
-
ownerType: "user",
|
|
74
|
-
ownerId: input.userId,
|
|
75
|
-
visibility: "private",
|
|
76
|
-
subjectType: "user",
|
|
77
|
-
subjectId: input.userId,
|
|
78
|
-
},
|
|
79
|
-
];
|
|
80
|
-
}
|
|
81
|
-
throw new Error("rememberMemory: space scope requires spaceId");
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (input.userId) {
|
|
85
|
-
return [
|
|
86
|
-
{
|
|
87
|
-
ownerType: "user",
|
|
88
|
-
ownerId: input.userId,
|
|
89
|
-
visibility: "private",
|
|
90
|
-
subjectType: "user",
|
|
91
|
-
subjectId: input.userId,
|
|
92
|
-
},
|
|
93
|
-
];
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (input.spaceId) {
|
|
97
|
-
return [
|
|
98
|
-
{
|
|
99
|
-
ownerType: "space",
|
|
100
|
-
ownerId: input.spaceId,
|
|
101
|
-
visibility: "shared",
|
|
102
|
-
subjectType: "space",
|
|
103
|
-
subjectId: input.spaceId,
|
|
104
|
-
},
|
|
105
|
-
];
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return [];
|
|
109
|
-
};
|
|
110
|
-
|
|
111
40
|
export const rememberMemory = async (
|
|
112
41
|
input: RememberMemoryInput
|
|
113
42
|
): Promise<RememberMemoryResult> => {
|
|
@@ -116,21 +45,34 @@ export const rememberMemory = async (
|
|
|
116
45
|
throw new Error("rememberMemory: content is required");
|
|
117
46
|
}
|
|
118
47
|
|
|
119
|
-
const scope = input.scope ?? "auto";
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
48
|
+
const scope = input.scope ?? "auto";
|
|
49
|
+
let targets: ReturnType<typeof resolveScopedMemoryTargets>;
|
|
50
|
+
try {
|
|
51
|
+
targets = resolveScopedMemoryTargets({
|
|
52
|
+
userId: input.userId,
|
|
53
|
+
spaceId: input.spaceId,
|
|
54
|
+
scope,
|
|
55
|
+
fallbackToUserForMissingSpace: true,
|
|
56
|
+
});
|
|
57
|
+
} catch (error) {
|
|
58
|
+
if (scope === "user") {
|
|
59
|
+
throw new Error("rememberMemory: user scope requires userId");
|
|
60
|
+
}
|
|
61
|
+
if (scope === "space") {
|
|
62
|
+
throw new Error("rememberMemory: space scope requires spaceId");
|
|
63
|
+
}
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
if (targets.length === 0) {
|
|
67
|
+
throw new Error("rememberMemory: no valid owner scope found");
|
|
68
|
+
}
|
|
128
69
|
|
|
129
70
|
const db = input.db ?? serverDb;
|
|
130
71
|
const kind = input.kind ?? "episodic";
|
|
131
72
|
if (!MEMORY_KINDS.has(kind)) {
|
|
132
73
|
throw new Error("rememberMemory: kind must be episodic, semantic, or procedural");
|
|
133
74
|
}
|
|
75
|
+
const savedItems: MemoryItem[] = [];
|
|
134
76
|
for (const target of targets) {
|
|
135
77
|
const item = createMemoryItem({
|
|
136
78
|
ownerType: target.ownerType,
|
|
@@ -149,14 +91,16 @@ export const rememberMemory = async (
|
|
|
149
91
|
patternKey: kind === "procedural" ? "procedural-runbook" : "agent-remember",
|
|
150
92
|
sourceDialogId: input.dialogId ?? undefined,
|
|
151
93
|
});
|
|
152
|
-
await writeMemoryItemWithIndexesToDb(db, item);
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
94
|
+
await writeMemoryItemWithIndexesToDb(db, item);
|
|
95
|
+
savedItems.push(item);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
success: true,
|
|
100
|
+
content,
|
|
101
|
+
requestedScope: scope,
|
|
102
|
+
savedItems,
|
|
103
|
+
resolvedScopes: targets.map((target) => ({
|
|
160
104
|
ownerType: target.ownerType,
|
|
161
105
|
ownerId: target.ownerId,
|
|
162
106
|
subjectType: target.subjectType,
|
|
@@ -164,4 +108,4 @@ export const rememberMemory = async (
|
|
|
164
108
|
visibility: target.visibility,
|
|
165
109
|
})),
|
|
166
110
|
};
|
|
167
|
-
};
|
|
111
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
MemoryOwnerType,
|
|
3
|
+
MemorySubjectType,
|
|
4
|
+
MemoryVisibility,
|
|
5
|
+
} from "./types";
|
|
6
|
+
|
|
7
|
+
export type MemoryScope = "auto" | "user" | "space";
|
|
8
|
+
|
|
9
|
+
export interface MemoryScopeTarget {
|
|
10
|
+
ownerType: MemoryOwnerType;
|
|
11
|
+
ownerId: string;
|
|
12
|
+
visibility: MemoryVisibility;
|
|
13
|
+
subjectType: MemorySubjectType;
|
|
14
|
+
subjectId: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const buildUserMemoryTarget = (userId: string): MemoryScopeTarget => ({
|
|
18
|
+
ownerType: "user",
|
|
19
|
+
ownerId: userId,
|
|
20
|
+
visibility: "private",
|
|
21
|
+
subjectType: "user",
|
|
22
|
+
subjectId: userId,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export const buildSpaceMemoryTarget = (spaceId: string): MemoryScopeTarget => ({
|
|
26
|
+
ownerType: "space",
|
|
27
|
+
ownerId: spaceId,
|
|
28
|
+
visibility: "shared",
|
|
29
|
+
subjectType: "space",
|
|
30
|
+
subjectId: spaceId,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export const resolveUserOrSpaceMemoryTarget = (input: {
|
|
34
|
+
userId?: string | null;
|
|
35
|
+
spaceId?: string | null;
|
|
36
|
+
}): MemoryScopeTarget | null => {
|
|
37
|
+
if (input.userId) return buildUserMemoryTarget(input.userId);
|
|
38
|
+
if (input.spaceId) return buildSpaceMemoryTarget(input.spaceId);
|
|
39
|
+
return null;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const resolveScopedMemoryTargets = (input: {
|
|
43
|
+
userId?: string | null;
|
|
44
|
+
spaceId?: string | null;
|
|
45
|
+
scope?: MemoryScope;
|
|
46
|
+
fallbackToUserForMissingSpace?: boolean;
|
|
47
|
+
}): MemoryScopeTarget[] => {
|
|
48
|
+
const scope = input.scope ?? "auto";
|
|
49
|
+
if (scope === "user") {
|
|
50
|
+
if (!input.userId) throw new Error("memory scope requires userId");
|
|
51
|
+
return [buildUserMemoryTarget(input.userId)];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (scope === "space") {
|
|
55
|
+
if (input.spaceId) return [buildSpaceMemoryTarget(input.spaceId)];
|
|
56
|
+
if (input.fallbackToUserForMissingSpace && input.userId) {
|
|
57
|
+
return [buildUserMemoryTarget(input.userId)];
|
|
58
|
+
}
|
|
59
|
+
throw new Error("memory space scope requires spaceId");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const target = resolveUserOrSpaceMemoryTarget(input);
|
|
63
|
+
return target ? [target] : [];
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const buildAgentSubjectTarget = (
|
|
67
|
+
target: Pick<MemoryScopeTarget, "ownerType" | "ownerId" | "visibility">,
|
|
68
|
+
agentKey: string
|
|
69
|
+
) => ({
|
|
70
|
+
owner: { ownerType: target.ownerType, ownerId: target.ownerId },
|
|
71
|
+
visibility: target.visibility,
|
|
72
|
+
subjectType: "agent" as const,
|
|
73
|
+
subjectId: agentKey,
|
|
74
|
+
});
|
package/ai/memory/types.ts
CHANGED
|
@@ -9,6 +9,11 @@ export type MemoryFacet =
|
|
|
9
9
|
| "goal"
|
|
10
10
|
| "style";
|
|
11
11
|
|
|
12
|
+
export type MemorySourceKind =
|
|
13
|
+
| "explicit-user-directive"
|
|
14
|
+
| "agent-tool"
|
|
15
|
+
| "inferred-understanding";
|
|
16
|
+
|
|
12
17
|
export interface MemoryItem {
|
|
13
18
|
id: string;
|
|
14
19
|
ownerType: MemoryOwnerType;
|
|
@@ -26,6 +31,7 @@ export interface MemoryItem {
|
|
|
26
31
|
tags?: string[];
|
|
27
32
|
facet?: MemoryFacet;
|
|
28
33
|
patternKey?: string;
|
|
34
|
+
sourceKind?: MemorySourceKind;
|
|
29
35
|
sourceDialogId?: string;
|
|
30
36
|
sourceMessageId?: string;
|
|
31
37
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ChatMessage } from "../../server/handlers/agentRun/types";
|
|
2
2
|
import { createMemoryItem, writeMemoryItemWithIndexesToDb } from "./storeShared";
|
|
3
3
|
import { loadMemoryCandidatesFromDb } from "./queryShared";
|
|
4
|
+
import { buildAgentSubjectTarget, resolveUserOrSpaceMemoryTarget } from "./scope";
|
|
4
5
|
import type {
|
|
5
6
|
MemoryFacet,
|
|
6
7
|
MemoryItem,
|
|
@@ -247,20 +248,11 @@ const buildUnderstandingTarget = (input: {
|
|
|
247
248
|
}): {
|
|
248
249
|
owner: MemoryOwnerRef;
|
|
249
250
|
visibility: MemoryVisibility;
|
|
251
|
+
subjectType: "agent";
|
|
252
|
+
subjectId: string;
|
|
250
253
|
} | null => {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
owner: { ownerType: "user", ownerId: input.userId },
|
|
254
|
-
visibility: "private",
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
if (input.spaceId) {
|
|
258
|
-
return {
|
|
259
|
-
owner: { ownerType: "space", ownerId: input.spaceId },
|
|
260
|
-
visibility: "shared",
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
return null;
|
|
254
|
+
const target = resolveUserOrSpaceMemoryTarget(input);
|
|
255
|
+
return target ? buildAgentSubjectTarget(target, input.agentKey) : null;
|
|
264
256
|
};
|
|
265
257
|
|
|
266
258
|
const sameUnderstanding = (item: MemoryItem, candidate: UnderstandingMemoryCandidate, agentKey: string) =>
|
|
@@ -288,7 +280,7 @@ export const captureUnderstandingMemoryFromDialog = async (input: {
|
|
|
288
280
|
|
|
289
281
|
const existing = await loadMemoryCandidatesFromDb(input.db, {
|
|
290
282
|
owners: [target.owner],
|
|
291
|
-
subjects: [{ subjectType:
|
|
283
|
+
subjects: [{ subjectType: target.subjectType, subjectId: target.subjectId }],
|
|
292
284
|
kinds: ["episodic", "semantic"],
|
|
293
285
|
ownerLimit: 100,
|
|
294
286
|
});
|
|
@@ -308,8 +300,8 @@ export const captureUnderstandingMemoryFromDialog = async (input: {
|
|
|
308
300
|
ownerType: target.owner.ownerType,
|
|
309
301
|
ownerId: target.owner.ownerId,
|
|
310
302
|
visibility: target.visibility,
|
|
311
|
-
subjectType:
|
|
312
|
-
subjectId:
|
|
303
|
+
subjectType: target.subjectType,
|
|
304
|
+
subjectId: target.subjectId,
|
|
313
305
|
kind: "semantic",
|
|
314
306
|
content: candidate.content,
|
|
315
307
|
facet: candidate.facet,
|
|
@@ -332,8 +324,8 @@ export const captureUnderstandingMemoryFromDialog = async (input: {
|
|
|
332
324
|
ownerType: target.owner.ownerType,
|
|
333
325
|
ownerId: target.owner.ownerId,
|
|
334
326
|
visibility: target.visibility,
|
|
335
|
-
subjectType:
|
|
336
|
-
subjectId:
|
|
327
|
+
subjectType: target.subjectType,
|
|
328
|
+
subjectId: target.subjectId,
|
|
337
329
|
kind: "episodic",
|
|
338
330
|
content: candidate.content,
|
|
339
331
|
facet: candidate.facet,
|
|
@@ -14,8 +14,8 @@ import {
|
|
|
14
14
|
DEFAULT_USER_PREFERENCE_PROFILE,
|
|
15
15
|
} from "./types";
|
|
16
16
|
|
|
17
|
-
export type CaptureIntent = "none" | "possible" | "strong";
|
|
18
|
-
export type SpaceNeed = "none" | "light" | "deep";
|
|
17
|
+
export type CaptureIntent = "none" | "possible" | "strong";
|
|
18
|
+
export type SpaceNeed = "none" | "light" | "deep";
|
|
19
19
|
export type KnowledgeCaptureMode = "blocked" | "ask" | "suggest" | "auto";
|
|
20
20
|
|
|
21
21
|
export interface ResolvedRuntimePolicy {
|
|
@@ -152,8 +152,31 @@ export const resolveUserPreferenceProfile = (
|
|
|
152
152
|
};
|
|
153
153
|
};
|
|
154
154
|
|
|
155
|
-
const containsAny = (text: string, patterns: string[]): boolean =>
|
|
156
|
-
patterns.some((pattern) => text.includes(pattern));
|
|
155
|
+
const containsAny = (text: string, patterns: string[]): boolean =>
|
|
156
|
+
patterns.some((pattern) => text.includes(pattern));
|
|
157
|
+
|
|
158
|
+
const spaceNeedRank: Record<SpaceNeed, number> = {
|
|
159
|
+
none: 0,
|
|
160
|
+
light: 1,
|
|
161
|
+
deep: 2,
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const maxSpaceNeed = (left: SpaceNeed, right: SpaceNeed): SpaceNeed =>
|
|
165
|
+
spaceNeedRank[left] >= spaceNeedRank[right] ? left : right;
|
|
166
|
+
|
|
167
|
+
const normalizeReferenceText = (value: unknown): string => {
|
|
168
|
+
if (!value || typeof value !== "object") return "";
|
|
169
|
+
const record = value as Record<string, unknown>;
|
|
170
|
+
return [
|
|
171
|
+
record.title,
|
|
172
|
+
record.name,
|
|
173
|
+
record.type,
|
|
174
|
+
record.dbKey,
|
|
175
|
+
record.key,
|
|
176
|
+
]
|
|
177
|
+
.filter((item): item is string => typeof item === "string")
|
|
178
|
+
.join("\n");
|
|
179
|
+
};
|
|
157
180
|
|
|
158
181
|
export const inferCaptureIntent = (userInput: string): CaptureIntent => {
|
|
159
182
|
const normalized = userInput.toLowerCase();
|
|
@@ -177,12 +200,16 @@ export const inferCaptureIntent = (userInput: string): CaptureIntent => {
|
|
|
177
200
|
"创建这个 skill",
|
|
178
201
|
"skill 文档",
|
|
179
202
|
"创建表格",
|
|
203
|
+
"createtable",
|
|
204
|
+
"addtablerow",
|
|
205
|
+
"addtablerows",
|
|
180
206
|
"建表",
|
|
181
207
|
"建个表",
|
|
182
208
|
"做个表",
|
|
183
209
|
"做一张表",
|
|
184
210
|
"写表",
|
|
185
211
|
"写入表",
|
|
212
|
+
"写入一行",
|
|
186
213
|
"写入 table",
|
|
187
214
|
"放到 table",
|
|
188
215
|
"存到 table",
|
|
@@ -237,7 +264,7 @@ export const inferCaptureIntent = (userInput: string): CaptureIntent => {
|
|
|
237
264
|
return "none";
|
|
238
265
|
};
|
|
239
266
|
|
|
240
|
-
export const inferSpaceNeed = (userInput: string): SpaceNeed => {
|
|
267
|
+
export const inferSpaceNeed = (userInput: string): SpaceNeed => {
|
|
241
268
|
const normalized = userInput.toLowerCase();
|
|
242
269
|
|
|
243
270
|
if (
|
|
@@ -270,9 +297,52 @@ export const inferSpaceNeed = (userInput: string): SpaceNeed => {
|
|
|
270
297
|
) {
|
|
271
298
|
return "light";
|
|
272
299
|
}
|
|
273
|
-
|
|
274
|
-
return "none";
|
|
275
|
-
};
|
|
300
|
+
|
|
301
|
+
return "none";
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
export const inferAgentSpaceNeed = (agentConfig?: Agent | any): SpaceNeed => {
|
|
305
|
+
const references = Array.isArray(agentConfig?.references)
|
|
306
|
+
? agentConfig.references
|
|
307
|
+
: [];
|
|
308
|
+
if (!references.length) return "none";
|
|
309
|
+
|
|
310
|
+
const combined = [
|
|
311
|
+
agentConfig?.prompt,
|
|
312
|
+
agentConfig?.systemPrompt,
|
|
313
|
+
agentConfig?.instructions,
|
|
314
|
+
agentConfig?.introduction,
|
|
315
|
+
...references.map(normalizeReferenceText),
|
|
316
|
+
]
|
|
317
|
+
.filter((item): item is string => typeof item === "string")
|
|
318
|
+
.join("\n")
|
|
319
|
+
.toLowerCase();
|
|
320
|
+
|
|
321
|
+
if (
|
|
322
|
+
containsAny(combined, [
|
|
323
|
+
"readDoc",
|
|
324
|
+
"readdoc",
|
|
325
|
+
"读取总索引",
|
|
326
|
+
"读取对应 doc",
|
|
327
|
+
"先读取",
|
|
328
|
+
"课程资料",
|
|
329
|
+
"挂载资料",
|
|
330
|
+
"资料索引",
|
|
331
|
+
"知识库",
|
|
332
|
+
"总索引",
|
|
333
|
+
"docs index",
|
|
334
|
+
"doc index",
|
|
335
|
+
"knowledge",
|
|
336
|
+
"references",
|
|
337
|
+
"source docs",
|
|
338
|
+
"based on the docs",
|
|
339
|
+
])
|
|
340
|
+
) {
|
|
341
|
+
return "deep";
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
return "light";
|
|
345
|
+
};
|
|
276
346
|
|
|
277
347
|
const resolveTonePreset = (
|
|
278
348
|
agentTone: TonePreset,
|
|
@@ -291,24 +361,24 @@ const resolveTonePreset = (
|
|
|
291
361
|
|
|
292
362
|
const maxReadCallsPerTurnByLevel = (
|
|
293
363
|
level: SpaceContextLevel,
|
|
294
|
-
need: SpaceNeed,
|
|
295
|
-
): number => {
|
|
296
|
-
if (need === "deep") {
|
|
297
|
-
return { 1:
|
|
298
|
-
}
|
|
364
|
+
need: SpaceNeed,
|
|
365
|
+
): number => {
|
|
366
|
+
if (need === "deep") {
|
|
367
|
+
return { 1: 3, 2: 4, 3: 6, 4: 8 }[level];
|
|
368
|
+
}
|
|
299
369
|
if (need === "light") {
|
|
300
370
|
return { 1: 1, 2: 2, 3: 3, 4: 4 }[level];
|
|
301
371
|
}
|
|
302
372
|
return { 1: 0, 2: 0, 3: 1, 4: 2 }[level];
|
|
303
373
|
};
|
|
304
374
|
|
|
305
|
-
const maxReadCallsPerDialogByLevel = (
|
|
306
|
-
level: SpaceContextLevel,
|
|
307
|
-
need: SpaceNeed,
|
|
308
|
-
): number => {
|
|
309
|
-
if (need === "deep") {
|
|
310
|
-
return { 1:
|
|
311
|
-
}
|
|
375
|
+
const maxReadCallsPerDialogByLevel = (
|
|
376
|
+
level: SpaceContextLevel,
|
|
377
|
+
need: SpaceNeed,
|
|
378
|
+
): number => {
|
|
379
|
+
if (need === "deep") {
|
|
380
|
+
return { 1: 6, 2: 10, 3: 16, 4: 24 }[level];
|
|
381
|
+
}
|
|
312
382
|
if (need === "light") {
|
|
313
383
|
return { 1: 2, 2: 3, 3: 4, 4: 6 }[level];
|
|
314
384
|
}
|
|
@@ -342,9 +412,11 @@ export const resolveRuntimePolicy = (params: {
|
|
|
342
412
|
) as SpaceContextLevel;
|
|
343
413
|
|
|
344
414
|
const captureIntent = inferCaptureIntent(userInput);
|
|
345
|
-
const
|
|
346
|
-
const
|
|
347
|
-
const
|
|
415
|
+
const userSpaceNeed = inferSpaceNeed(userInput);
|
|
416
|
+
const agentSpaceNeed = inferAgentSpaceNeed(agentConfig);
|
|
417
|
+
const spaceNeed = maxSpaceNeed(userSpaceNeed, agentSpaceNeed);
|
|
418
|
+
const explicitCaptureRequest = captureIntent === "strong";
|
|
419
|
+
const explicitSpaceRequest = userSpaceNeed !== "none";
|
|
348
420
|
|
|
349
421
|
const currentAutoCreates = Math.max(
|
|
350
422
|
0,
|
|
@@ -44,10 +44,6 @@ import {
|
|
|
44
44
|
runLlmFunctionSchema,
|
|
45
45
|
runLlmToolFunc,
|
|
46
46
|
} from "./runLlmTool";
|
|
47
|
-
import {
|
|
48
|
-
taskRunFunctionSchema,
|
|
49
|
-
taskRunFunc,
|
|
50
|
-
} from "./taskRunTool";
|
|
51
47
|
|
|
52
48
|
import type { ToolDefinition } from "../index";
|
|
53
49
|
|
|
@@ -215,21 +211,4 @@ export const agentToolDefinitions: ToolDefinition[] = [
|
|
|
215
211
|
behavior: "action",
|
|
216
212
|
uiGroup: "agent",
|
|
217
213
|
},
|
|
218
|
-
{
|
|
219
|
-
id: "taskRun",
|
|
220
|
-
schema: taskRunFunctionSchema,
|
|
221
|
-
executor: taskRunFunc,
|
|
222
|
-
description: {
|
|
223
|
-
name: "taskRun",
|
|
224
|
-
description:
|
|
225
|
-
"读写任务卡里的轻量 task-run 上下文,让 PM、实现 agent、reviewer 共享工作项、交接物、阻塞和 review 状态。",
|
|
226
|
-
category: "计划与编排",
|
|
227
|
-
},
|
|
228
|
-
behavior: "action",
|
|
229
|
-
uiGroup: "agent",
|
|
230
|
-
capability: "general",
|
|
231
|
-
riskLevel: "medium",
|
|
232
|
-
costLevel: "low",
|
|
233
|
-
defaultConsent: "auto",
|
|
234
|
-
},
|
|
235
214
|
];
|
|
@@ -19,7 +19,8 @@ export const startAgentDialogFunctionSchema = {
|
|
|
19
19
|
},
|
|
20
20
|
subjectRefs: {
|
|
21
21
|
type: "array",
|
|
22
|
-
description:
|
|
22
|
+
description:
|
|
23
|
+
"可选。与本次子 dialog 相关的业务对象引用,保持行业中立。交接任务行时传 {kind:\"table-row\", id: rowDbKey, role:\"task\"};服务端会继承父 dialog/runtimeContext 已有的 subjectRefs。",
|
|
23
24
|
items: {
|
|
24
25
|
type: "object",
|
|
25
26
|
properties: {
|
package/ai/tools/index.ts
CHANGED
|
@@ -197,6 +197,8 @@ import {
|
|
|
197
197
|
readXhsProfileFunctionSchema,
|
|
198
198
|
readXhsProfileFunc,
|
|
199
199
|
} from "./readXhsProfileTool";
|
|
200
|
+
export { TOOL_PACKS } from "./toolPacks";
|
|
201
|
+
import { TOOL_PACKS } from "./toolPacks";
|
|
200
202
|
import {
|
|
201
203
|
surfWeatherFunctionSchema,
|
|
202
204
|
surfWeatherFunc,
|
|
@@ -506,26 +508,6 @@ export interface ToolDefinition {
|
|
|
506
508
|
};
|
|
507
509
|
}
|
|
508
510
|
|
|
509
|
-
/**
|
|
510
|
-
* 能力分级定义 (Capability Tiers)
|
|
511
|
-
*/
|
|
512
|
-
export const TOOL_PACKS = {
|
|
513
|
-
// L1 - 核心:交互 + 记忆读写 + 自我更新,所有 Agent 必有
|
|
514
|
-
CORE: ["ui_ask_choice", "rememberMemory", "read", "searchDialogMessages", "createDoc", "updateDoc", "search_workspace", "search_all_spaces", "updateSelf", "queryModelUsage", "createDialogGoal", "getDialogGoal", "completeDialogGoal", "createScheduledTask", "notifyUser"],
|
|
515
|
-
// L2 - 联网搜索:配置了 tools 的 Agent 默认加,纯 QA bot 不加
|
|
516
|
-
LIGHT_WEB: ["exa_search", "read_x_post", "read_xhs_profile"],
|
|
517
|
-
// L3 - 深度浏览器:全套复杂网页交互
|
|
518
|
-
FULL_BROWSER: [
|
|
519
|
-
"browser_openSession",
|
|
520
|
-
"browser_closeSession",
|
|
521
|
-
"browser_click",
|
|
522
|
-
"browser_typeText",
|
|
523
|
-
"browser_readContent",
|
|
524
|
-
"browser_selectOption",
|
|
525
|
-
"fetchWebpage",
|
|
526
|
-
],
|
|
527
|
-
};
|
|
528
|
-
|
|
529
511
|
/* ==================================================================
|
|
530
512
|
* 2.1 toolquery 工具:帮助模型发现可用工具
|
|
531
513
|
* ================================================================== */
|