@xopcai/xopc 0.0.455 → 0.0.456
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/dist/browser-ext/manifest.json +1 -1
- package/dist/extensions/telegram/xopc.extension.json +1 -1
- package/dist/gateway/static/root/assets/{automations-page-Dt_Z1UTT.js → automations-page-CgQDpSpK.js} +1 -1
- package/dist/gateway/static/root/assets/{automations-workspace-BhHgruhH.js → automations-workspace-CWEDraTP.js} +2 -2
- package/dist/gateway/static/root/assets/{chat-page-dY6aCCRx.js → chat-page-BjYumhaI.js} +19 -19
- package/dist/gateway/static/root/assets/{desktop-pet-DlTuGzZ2.js → desktop-pet-Cn1TfGz4.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-narrative-cBFIPXzR.js → desktop-pet-narrative-JqMsz4rn.js} +1 -1
- package/dist/gateway/static/root/assets/{index-CZI3VGGW.js → index-DBlVVXOA.js} +5 -5
- package/dist/gateway/static/root/assets/index-DpkEeFEQ.css +1 -0
- package/dist/gateway/static/root/assets/{note-detail-panel-anM38aV6.js → note-detail-panel-C6s0WlNL.js} +2 -2
- package/dist/gateway/static/root/assets/{notes-page-BsZmT7Zw.js → notes-page-CR7dNVDi.js} +1 -1
- package/dist/gateway/static/root/assets/{personal-page-BSCNuRMT.js → personal-page-C89kLOIL.js} +1 -1
- package/dist/gateway/static/root/assets/{project-detail-page-ibZZ_w51.js → project-detail-page-sHcdluTm.js} +1 -1
- package/dist/gateway/static/root/assets/{route-preload-anuckzRl.js → route-preload-DrfQJkmW.js} +2 -2
- package/dist/gateway/static/root/assets/{settings-page-DAc5n-mM.js → settings-page-C4CYw21O.js} +1 -1
- package/dist/gateway/static/root/assets/{task-detail-page-BJok6V1K.js → task-detail-page-DBnkT1Nj.js} +1 -1
- package/dist/gateway/static/root/assets/tool-friendly-title-CP35P4VA.js +2 -0
- package/dist/gateway/static/root/assets/understanding-refresh-store-CIpGYSl0.js +1 -0
- package/dist/gateway/static/root/assets/user-model-page-Bbi2MpIS.js +2 -0
- package/dist/gateway/static/root/index.html +7 -7
- package/dist/package.js +1 -1
- package/dist/src/agent/agent-manager.js +7 -2
- package/dist/src/agent/background-review/prompts.d.ts +1 -1
- package/dist/src/agent/background-review/prompts.js +8 -1
- package/dist/src/agent/background-review/run-background-review.js +48 -4
- package/dist/src/agent/context/audit.js +18 -0
- package/dist/src/agent/context/coordinator.d.ts +4 -0
- package/dist/src/agent/context/coordinator.js +33 -7
- package/dist/src/agent/context/deep-recall.d.ts +33 -0
- package/dist/src/agent/context/deep-recall.js +190 -0
- package/dist/src/agent/context/execution-context.js +29 -5
- package/dist/src/agent/context/execution-context.types.d.ts +2 -0
- package/dist/src/agent/context/memory-claim-grounding.d.ts +2 -0
- package/dist/src/agent/context/memory-claim-grounding.js +20 -0
- package/dist/src/agent/context/recall-grounding.d.ts +3 -0
- package/dist/src/agent/context/recall-grounding.js +31 -0
- package/dist/src/agent/embedded/run-turn.js +46 -0
- package/dist/src/agent/external-tools/cliProvider.js +2 -2
- package/dist/src/agent/external-tools/composio-provider.js +2 -2
- package/dist/src/agent/external-tools/endpoint-provider.js +3 -3
- package/dist/src/agent/memory/context-recovery.d.ts +1 -1
- package/dist/src/agent/memory/index.js +1 -1
- package/dist/src/agent/service/process-direct-streaming.js +1 -1
- package/dist/src/agent/service.d.ts +1 -0
- package/dist/src/agent/service.js +6 -3
- package/dist/src/agent/skills/index.js +1 -1
- package/dist/src/agent/skills/managed-store.js +1 -1
- package/dist/src/agent/skills/skill-manage-ops.js +1 -1
- package/dist/src/agent/tools/factory.js +22 -0
- package/dist/src/agent/tools/knowledge-memory-tool.js +7 -1
- package/dist/src/agent/tools/personal-memory-tool.d.ts +11 -0
- package/dist/src/agent/tools/personal-memory-tool.js +387 -0
- package/dist/src/agent/tools/personal-read-tool.js +1 -1
- package/dist/src/agent/tools/session-search-tool.d.ts +2 -0
- package/dist/src/agent/tools/session-search-tool.js +21 -7
- package/dist/src/agent/tools/user-context-tool.js +11 -1
- package/dist/src/agent/tools/xopc-use-tool.js +2 -2
- package/dist/src/agent-catalog/capabilities.js +2 -2
- package/dist/src/agent-catalog/repository.js +1 -1
- package/dist/src/automations/api/routes.js +2 -2
- package/dist/src/automations/capabilities/drafts.js +1 -1
- package/dist/src/automations/capabilities/write.js +1 -1
- package/dist/src/automations/configuration-conversation.js +1 -1
- package/dist/src/browser/providers/browser-ext-install.js +1 -1
- package/dist/src/capabilities/runtime/dispatcher.js +1 -1
- package/dist/src/capabilities/runtime/product.js +1 -1
- package/dist/src/cli/commands/agents.js +1 -1
- package/dist/src/cli/commands/models.js +1 -1
- package/dist/src/cli/commands/onboard/model.js +1 -1
- package/dist/src/cli/utils/init-workspace-core.js +1 -1
- package/dist/src/computer/endpoint-transport.js +1 -1
- package/dist/src/config/agent-profile.js +1 -1
- package/dist/src/config/schema.d.ts +6 -0
- package/dist/src/config/schema.js +6 -0
- package/dist/src/execution-environments/local-worktree-manager.js +1 -1
- package/dist/src/extensions/agent-plugins/skill-catalog.js +1 -1
- package/dist/src/extensions/agent-plugins/validation.js +1 -1
- package/dist/src/gateway/agent-builtin-tools.d.ts +1 -1
- package/dist/src/gateway/agents-admin.js +2 -2
- package/dist/src/gateway/global-defaults-admin.js +1 -1
- package/dist/src/gateway/hono/lib/config-payload.d.ts +6 -0
- package/dist/src/gateway/hono/routes/agents.js +1 -1
- package/dist/src/gateway/hono/routes/auth-registry-extensions.js +1 -1
- package/dist/src/gateway/hono/routes/config-patch/misc.js +1 -1
- package/dist/src/gateway/hono/routes/local-app-run-streams.js +1 -1
- package/dist/src/gateway/hono/routes/notes.js +2 -2
- package/dist/src/gateway/hono/routes/phone-setup.js +1 -1
- package/dist/src/gateway/hono/routes/projects.js +2 -2
- package/dist/src/gateway/hono/routes/session-input-handler.js +1 -1
- package/dist/src/gateway/hono/routes/tasks.js +2 -2
- package/dist/src/gateway/hono/routes/user-model.js +47 -7
- package/dist/src/gateway/image-generation-setup.js +1 -1
- package/dist/src/gateway/service/config-coordinator.d.ts +6 -0
- package/dist/src/gateway/service.js +4 -4
- package/dist/src/gateway/xopc-cloud-capability-setup.js +1 -1
- package/dist/src/home-intelligence/host.js +2 -2
- package/dist/src/imports/importService.js +1 -1
- package/dist/src/knowledge-memory/index.js +2 -2
- package/dist/src/knowledge-memory/repository.d.ts +6 -0
- package/dist/src/knowledge-memory/repository.js +49 -1
- package/dist/src/knowledge-memory/usage-policy.js +7 -7
- package/dist/src/local-apps/automation-proposals.js +1 -1
- package/dist/src/local-apps/capabilities/automation-policy.js +1 -1
- package/dist/src/local-apps/capabilities/delegate.js +3 -3
- package/dist/src/local-apps/p1-services.js +1 -1
- package/dist/src/local-apps/service.js +1 -1
- package/dist/src/memory-learning/work-capture.js +3 -1
- package/dist/src/personal-agent/policy.d.ts +1 -1
- package/dist/src/personal-agent/policy.js +2 -1
- package/dist/src/personal-agent/prompts.js +7 -1
- package/dist/src/personal-agent/service.js +1 -1
- package/dist/src/providers/model-catalog-persistence.js +1 -1
- package/dist/src/runtime-tools/archive.js +1 -1
- package/dist/src/session/history-recall-policy.d.ts +6 -0
- package/dist/src/session/history-recall-policy.js +48 -0
- package/dist/src/tasks/capabilities/read.js +2 -2
- package/dist/src/tasks/capabilities/write.js +1 -1
- package/dist/src/tui/backends/embedded-backend.js +1 -1
- package/dist/src/user-context/config.d.ts +12 -0
- package/dist/src/user-context/config.js +14 -1
- package/dist/src/user-context/memory-version.d.ts +2 -0
- package/dist/src/user-context/memory-version.js +12 -0
- package/dist/src/user-model/capture/evidence-policy.d.ts +45 -0
- package/dist/src/user-model/capture/evidence-policy.js +143 -0
- package/dist/src/user-model/capture/executor.d.ts +1 -0
- package/dist/src/user-model/capture/executor.js +68 -8
- package/dist/src/user-model/capture/semantic.d.ts +16 -0
- package/dist/src/user-model/capture/semantic.js +66 -12
- package/dist/src/user-model/repository.js +11 -0
- package/dist/src/user-model/usage-policy.js +5 -5
- package/dist/src/voice/realtime/persona-context.js +1 -1
- package/dist/src/work-discovery/service.js +1 -1
- package/package.json +1 -1
- package/dist/gateway/static/root/assets/index-Bj5exyow.css +0 -1
- package/dist/gateway/static/root/assets/tool-friendly-title-DC8_9-Lo.js +0 -2
- package/dist/gateway/static/root/assets/understanding-refresh-store-Ihz2p9Vg.js +0 -1
- package/dist/gateway/static/root/assets/user-model-page-1eYattnk.js +0 -2
|
@@ -2,13 +2,13 @@ import { createLogger } from "../utils/logger/index.js";
|
|
|
2
2
|
import { init_logger } from "../utils/logger.js";
|
|
3
3
|
import { parseNoteAttachmentTarget } from "../notes/attachment-ref.js";
|
|
4
4
|
import { init_agent_scope, resolveAgentHomeDir, resolveDefaultAgentId } from "./agent-scope.js";
|
|
5
|
+
import { extractTextContent } from "./context/workspace.js";
|
|
5
6
|
import { getAgentDefaultModelRef, init_schema } from "../config/schema.js";
|
|
6
7
|
import { init_agent_session_key, resolveAgentIdFromConversationId } from "../routing/agent-session-key.js";
|
|
7
8
|
import { extractProfileAgentId, resolveEffectiveAgentConfigForSession } from "../config/agent-profile.js";
|
|
8
9
|
import { init_providers, resolveModel } from "../providers/index.js";
|
|
9
10
|
import { configureTracing, flushTracing } from "../observability/runtime.js";
|
|
10
11
|
import { getUserTimezone } from "../user-model/repository.js";
|
|
11
|
-
import { extractTextContent } from "./context/workspace.js";
|
|
12
12
|
import { resolveAgentTurnTimeoutMs } from "./orchestration/run-agent-turn-with-timeout.js";
|
|
13
13
|
import { applyConfigOverrides } from "../config/runtime-overrides.js";
|
|
14
14
|
import { effectiveWorkspacePathForSession } from "../session/session-workspace.js";
|
|
@@ -17,9 +17,9 @@ import { onSessionTranscriptUpdate } from "../session/transcript-events.js";
|
|
|
17
17
|
import { persistInboundAttachments } from "../channels/attachments/inbound-persist.js";
|
|
18
18
|
import { buildTranscriptUserMessage, hydrateUserTurnForLlm } from "./inbound/attachment-pipeline.js";
|
|
19
19
|
import { runWithEmbeddedExecutionSession } from "./embedded/execution-context.js";
|
|
20
|
+
import "../user-model/index.js";
|
|
20
21
|
import { removeSkillsLockEntry } from "./skills/hub-lock.js";
|
|
21
22
|
import { installSkillFromZip } from "./skills/managed-store.js";
|
|
22
|
-
import "../user-model/index.js";
|
|
23
23
|
import { resolveWorkspaceSkillsDir, resolveWorkspaceSkillsLockPath } from "./skills/workspace-skills-dir.js";
|
|
24
24
|
import { pullSkillFromSource } from "./skills/hub-pull.js";
|
|
25
25
|
import { resolveResponseLanguageForSession } from "./prompt/response-language.js";
|
|
@@ -165,6 +165,7 @@ var AgentService = class {
|
|
|
165
165
|
/** Gateway: notify UI after direct `SessionStore.updateMetadata` (no SessionManager emit). */
|
|
166
166
|
onSessionMetadataUpdated;
|
|
167
167
|
onSessionTranscriptUpdated;
|
|
168
|
+
stopSessionTranscriptUpdates;
|
|
168
169
|
effectiveAppConfig() {
|
|
169
170
|
const base = this.config.config;
|
|
170
171
|
return base ? applyConfigOverrides(base) : void 0;
|
|
@@ -183,7 +184,7 @@ var AgentService = class {
|
|
|
183
184
|
initializeCommands();
|
|
184
185
|
log.debug("Command system initialized");
|
|
185
186
|
this.sessionStore = config.sessionStore ?? this.createSessionStore();
|
|
186
|
-
onSessionTranscriptUpdate((update) => {
|
|
187
|
+
this.stopSessionTranscriptUpdates = onSessionTranscriptUpdate((update) => {
|
|
187
188
|
this.sessionStore.syncEmbeddedTranscriptUpdate(update).catch((err) => {
|
|
188
189
|
log.warn({
|
|
189
190
|
err,
|
|
@@ -890,6 +891,8 @@ var AgentService = class {
|
|
|
890
891
|
}
|
|
891
892
|
}
|
|
892
893
|
dispose() {
|
|
894
|
+
this.stopSessionTranscriptUpdates?.();
|
|
895
|
+
this.stopSessionTranscriptUpdates = void 0;
|
|
893
896
|
this.sessionStore.idleCompaction.dispose();
|
|
894
897
|
this.sessionTracker.dispose();
|
|
895
898
|
this.sessionState.disposeAll();
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { resolveStateDir } from "../../config/paths-state.js";
|
|
2
2
|
import { createLogger } from "../../utils/logger/index.js";
|
|
3
3
|
import { init_logger } from "../../utils/logger.js";
|
|
4
|
-
import { init_paths } from "../../config/paths.js";
|
|
5
4
|
import { parseFrontmatter } from "../../markdown/frontmatter.js";
|
|
5
|
+
import { init_paths } from "../../config/paths.js";
|
|
6
6
|
import { findInstallSpec, hasBinary, installSkill } from "./installer.js";
|
|
7
7
|
import { applySkillEnvOverrides, createSkillConfigManager, getSkillEnvironment, isSkillEnabled, resolveSkillConfig, validateSkillConfig } from "./config.js";
|
|
8
8
|
import { parseSkillToolConditions } from "./skill-tool-gating.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { init_paths, resolveSkillsDir } from "../../config/paths.js";
|
|
2
1
|
import { parseFrontmatter } from "../../markdown/frontmatter.js";
|
|
2
|
+
import { init_paths, resolveSkillsDir } from "../../config/paths.js";
|
|
3
3
|
import { loadSkillsLock } from "./hub-lock.js";
|
|
4
4
|
import { dirname, join, resolve, sep } from "node:path";
|
|
5
5
|
import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { init_paths, resolveSkillsDir } from "../../config/paths.js";
|
|
2
1
|
import { parseFrontmatter } from "../../markdown/frontmatter.js";
|
|
2
|
+
import { init_paths, resolveSkillsDir } from "../../config/paths.js";
|
|
3
3
|
import { resolveWorkspaceSkillsDir } from "./workspace-skills-dir.js";
|
|
4
4
|
import { formatScanSummary, scanSkillDirectory } from "./scanner.js";
|
|
5
5
|
import { fuzzyFindText, normalizeForFuzzyMatch, normalizeToLF, restoreLineEndings } from "../tools/edit-diff.js";
|
|
@@ -22,6 +22,7 @@ import { getEmbeddedExecutionRunId, getEmbeddedExecutionSession } from "../embed
|
|
|
22
22
|
import { createPhoneUseTool } from "./phone-use-tool.js";
|
|
23
23
|
import { LOCAL_READ_MAX_CHARS } from "./local-read-budget.js";
|
|
24
24
|
import { createPersonalAttentionTool } from "./personal-attention-tool.js";
|
|
25
|
+
import { createPersonalMemoryTool } from "./personal-memory-tool.js";
|
|
25
26
|
import { withCoreToolExposure } from "./toolExposure.js";
|
|
26
27
|
import { markCodemodeCoreRead } from "./codemode-permissions.js";
|
|
27
28
|
import "../../../packages/browser-control-contract/src/index.js";
|
|
@@ -74,6 +75,7 @@ import { createImageGenerateTool } from "./image-generate-tool.js";
|
|
|
74
75
|
import { createPersonalReadTool } from "./personal-read-tool.js";
|
|
75
76
|
import { createTaskCollaborationTool } from "./task-collaboration-tool.js";
|
|
76
77
|
import "./index.js";
|
|
78
|
+
import { canRecallConversation, canRecallHistoryEntry } from "../../session/history-recall-policy.js";
|
|
77
79
|
import { createPersonalResultTool } from "./personal-result-tool.js";
|
|
78
80
|
import { createPersonalTaskTool } from "./personal-task-tool.js";
|
|
79
81
|
import { withTaskEvidenceIdentity } from "./task-evidence.js";
|
|
@@ -566,6 +568,14 @@ var AgentToolsFactory = class AgentToolsFactory {
|
|
|
566
568
|
workspace,
|
|
567
569
|
getConfig: () => this.deps.getConfig?.()
|
|
568
570
|
})] : [],
|
|
571
|
+
...personalToolsConfigured ? [createPersonalMemoryTool({
|
|
572
|
+
getConversationId: currentConversationId,
|
|
573
|
+
getCurrentUserText: () => currentConversationId() ? getActiveTranscriptUserText(currentConversationId()) : void 0,
|
|
574
|
+
getConfig: () => this.deps.getConfig?.(),
|
|
575
|
+
agentId: resolvedAgentId,
|
|
576
|
+
workspaceId: workspace,
|
|
577
|
+
getProjectId: currentProjectId
|
|
578
|
+
})] : [],
|
|
569
579
|
...personalToolsConfigured || allowed?.has("user_context_read") ? [createUserContextReadTool({
|
|
570
580
|
getCurrentUserText: () => currentConversationId() ? getActiveTranscriptUserText(currentConversationId()) : void 0,
|
|
571
581
|
agentId: resolvedAgentId,
|
|
@@ -659,6 +669,18 @@ var AgentToolsFactory = class AgentToolsFactory {
|
|
|
659
669
|
})] : [],
|
|
660
670
|
...this.deps.getSessionStore && getPrimary ? [createSessionSearchTool({
|
|
661
671
|
localOnly: personalToolsConfigured,
|
|
672
|
+
canRecallConversation: (id) => canRecallConversation(this.deps.getConfig?.(), {
|
|
673
|
+
agentId: resolvedAgentId,
|
|
674
|
+
workspaceId: workspace,
|
|
675
|
+
conversationId: currentConversationId() ?? "",
|
|
676
|
+
projectId: currentProjectId()
|
|
677
|
+
}, id),
|
|
678
|
+
canRecallEntry: (id, entryId, text) => canRecallHistoryEntry({
|
|
679
|
+
agentId: resolvedAgentId,
|
|
680
|
+
workspaceId: workspace,
|
|
681
|
+
conversationId: currentConversationId() ?? "",
|
|
682
|
+
projectId: currentProjectId()
|
|
683
|
+
}, id, entryId, text),
|
|
662
684
|
getHistoryContext: () => ({
|
|
663
685
|
agentId: resolvedAgentId,
|
|
664
686
|
workspaceId: workspace,
|
|
@@ -4,6 +4,7 @@ import { getKnowledgeItem, searchKnowledgeItems, writeKnowledgeItem } from "../.
|
|
|
4
4
|
import "../../knowledge-memory/index.js";
|
|
5
5
|
import { projectForgottenEvidence } from "../../memory-learning/forgotten-history.js";
|
|
6
6
|
import "./local-read-budget.js";
|
|
7
|
+
import { memoryVersion } from "../../user-context/memory-version.js";
|
|
7
8
|
import { Type } from "@sinclair/typebox";
|
|
8
9
|
//#region src/agent/tools/knowledge-memory-tool.ts
|
|
9
10
|
const SearchSchema = Type.Object({
|
|
@@ -70,6 +71,7 @@ function createKnowledgeSearchTool(options) {
|
|
|
70
71
|
limit: input.maxResults ?? 12
|
|
71
72
|
}).map((item) => ({
|
|
72
73
|
...item,
|
|
74
|
+
version: memoryVersion(item),
|
|
73
75
|
source: projectForgottenEvidence(item.source, visibility(options), options.getCurrentUserText?.(), [item.sourceConversationId, item.sourceTurnId].filter((ref) => !!ref))
|
|
74
76
|
}));
|
|
75
77
|
return {
|
|
@@ -107,10 +109,14 @@ function createKnowledgeGetTool(options) {
|
|
|
107
109
|
return visible ? {
|
|
108
110
|
content: [{
|
|
109
111
|
type: "text",
|
|
110
|
-
text: JSON.stringify(
|
|
112
|
+
text: JSON.stringify({
|
|
113
|
+
...projected,
|
|
114
|
+
version: memoryVersion(item)
|
|
115
|
+
}, null, 2)
|
|
111
116
|
}],
|
|
112
117
|
details: {
|
|
113
118
|
item: projected,
|
|
119
|
+
version: memoryVersion(item),
|
|
114
120
|
complete: true
|
|
115
121
|
}
|
|
116
122
|
} : {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AgentTool } from '@earendil-works/pi-agent-core';
|
|
2
|
+
import type { Config } from '../../config/schema.js';
|
|
3
|
+
/** Explicit owner mutations use the existing domain transactions and atomic operation receipts. */
|
|
4
|
+
export declare function createPersonalMemoryTool(deps: {
|
|
5
|
+
getConversationId: () => string | undefined;
|
|
6
|
+
getCurrentUserText: () => string | undefined;
|
|
7
|
+
getConfig: () => Config | undefined;
|
|
8
|
+
agentId: string;
|
|
9
|
+
workspaceId: string;
|
|
10
|
+
getProjectId: () => string | undefined;
|
|
11
|
+
}): AgentTool;
|
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
import { getSqliteDatabase, init_transaction } from "../../storage/sqlite/transaction.js";
|
|
2
|
+
import { createCollaborationRule } from "../../storage/sqlite/collaboration-rule-repository.js";
|
|
3
|
+
import { createContextEvidence } from "../../storage/sqlite/context-evidence-repository.js";
|
|
4
|
+
import { init_session_instance_repository, readCurrentTranscriptId } from "../../storage/sqlite/session-instance-repository.js";
|
|
5
|
+
import { init_changes, notifyUserContextChange } from "../../user-context/changes.js";
|
|
6
|
+
import { executeAtomicOperation } from "../../capabilities/runtime/atomic-operations.js";
|
|
7
|
+
import { resolveUserContextSessionAccess } from "../../user-context/access-policy.js";
|
|
8
|
+
import { learningRoleSql, learningTranscriptMessage } from "../../memory-learning/transcript-source.js";
|
|
9
|
+
import { inferMemorySensitivity } from "../memory/sensitivity.js";
|
|
10
|
+
import { canUseKnowledge, knowledgeContentSources } from "../../knowledge-memory/usage-policy.js";
|
|
11
|
+
import { deleteKnowledgeItem, getKnowledgeItem, reviewKnowledgeItem, setKnowledgeScope, writeKnowledgeItem } from "../../knowledge-memory/repository.js";
|
|
12
|
+
import "../../knowledge-memory/index.js";
|
|
13
|
+
import { isUnquotedOwnerEvidence } from "../../memory-learning/owner-directive.js";
|
|
14
|
+
import { deleteUserAssertion, getAssertionSlot, getUserAssertion, reconcileAssertion, setAssertionStatus, setUserAssertionScope } from "../../user-model/repository.js";
|
|
15
|
+
import { canUseAssertion } from "../../user-model/usage-policy.js";
|
|
16
|
+
import { getPersonalAgentByConversation } from "../../personal-agent/repository.js";
|
|
17
|
+
import { getSessionInteractionPolicy } from "../session/interaction-policy.js";
|
|
18
|
+
import { memoryVersion } from "../../user-context/memory-version.js";
|
|
19
|
+
import "../../user-model/index.js";
|
|
20
|
+
import { extractAgentUserPlainText } from "../memory/user-message-text.js";
|
|
21
|
+
import { createHash } from "node:crypto";
|
|
22
|
+
import { Type } from "@sinclair/typebox";
|
|
23
|
+
import { Value } from "@sinclair/typebox/value";
|
|
24
|
+
//#region src/agent/tools/personal-memory-tool.ts
|
|
25
|
+
init_session_instance_repository();
|
|
26
|
+
init_transaction();
|
|
27
|
+
init_changes();
|
|
28
|
+
const schema = Type.Object({
|
|
29
|
+
command: Type.Union([
|
|
30
|
+
"remember",
|
|
31
|
+
"correct",
|
|
32
|
+
"forget",
|
|
33
|
+
"scope"
|
|
34
|
+
].map((value) => Type.Literal(value))),
|
|
35
|
+
target: Type.Union([Type.Literal("user"), Type.Literal("knowledge")]),
|
|
36
|
+
userEvidence: Type.String({
|
|
37
|
+
minLength: 1,
|
|
38
|
+
maxLength: 1e3
|
|
39
|
+
}),
|
|
40
|
+
content: Type.Optional(Type.String({
|
|
41
|
+
minLength: 1,
|
|
42
|
+
maxLength: 600
|
|
43
|
+
})),
|
|
44
|
+
id: Type.Optional(Type.String({
|
|
45
|
+
minLength: 1,
|
|
46
|
+
maxLength: 200
|
|
47
|
+
})),
|
|
48
|
+
version: Type.Optional(Type.String({
|
|
49
|
+
minLength: 1,
|
|
50
|
+
maxLength: 100
|
|
51
|
+
})),
|
|
52
|
+
scope: Type.Optional(Type.Union([
|
|
53
|
+
"global",
|
|
54
|
+
"agent",
|
|
55
|
+
"workspace",
|
|
56
|
+
"project",
|
|
57
|
+
"session"
|
|
58
|
+
].map((value) => Type.Literal(value)))),
|
|
59
|
+
predicate: Type.Optional(Type.String({ pattern: "^[a-z][a-z0-9_.-]{2,119}$" })),
|
|
60
|
+
userKind: Type.Optional(Type.Union([
|
|
61
|
+
"identity",
|
|
62
|
+
"preference",
|
|
63
|
+
"value",
|
|
64
|
+
"routine",
|
|
65
|
+
"capability",
|
|
66
|
+
"relationship",
|
|
67
|
+
"current_state"
|
|
68
|
+
].map((value) => Type.Literal(value)))),
|
|
69
|
+
knowledgeKind: Type.Optional(Type.Union([
|
|
70
|
+
"project_fact",
|
|
71
|
+
"workspace_fact",
|
|
72
|
+
"decision",
|
|
73
|
+
"task_lesson",
|
|
74
|
+
"commitment",
|
|
75
|
+
"open_question",
|
|
76
|
+
"episode",
|
|
77
|
+
"note"
|
|
78
|
+
].map((value) => Type.Literal(value)))),
|
|
79
|
+
validTo: Type.Optional(Type.Number({ minimum: 1 }))
|
|
80
|
+
}, { additionalProperties: false });
|
|
81
|
+
function visible(scope, context) {
|
|
82
|
+
return scope.type === "global" || scope.id === {
|
|
83
|
+
agent: context.agentId,
|
|
84
|
+
workspace: context.workspaceId,
|
|
85
|
+
project: context.projectId,
|
|
86
|
+
session: context.conversationId
|
|
87
|
+
}[scope.type];
|
|
88
|
+
}
|
|
89
|
+
function explicitRequest(text, quote, command) {
|
|
90
|
+
if (command === "forget") return isUnquotedOwnerEvidence(text, quote);
|
|
91
|
+
const author = text.replace(/```[\s\S]*?```|~~~[\s\S]*?~~~|^\s*>.*$/gmu, "").replace(/“[^”]*”|「[^」]*」|『[^』]*』|"[^"\n]*"/gu, (span) => /记住|保存|纠正|修改|remember|save|correct|scope/iu.test(span) ? "" : span);
|
|
92
|
+
if (!quote.trim() || !author.includes(quote.trim())) return false;
|
|
93
|
+
if (command === "remember") return !/不要.*(?:记住|保存)|别.*(?:记住|保存)|(?:don't|do not|never)\s+(?:remember|save|store)/iu.test(author) && /记住|保存|记下|记着|\b(?:remember|save|store)\b/iu.test(quote);
|
|
94
|
+
return /纠正|修正|改成|改为|修改|更正|不是|仅|只(?:在|用|对)|范围|所有|全局|\b(?:correct|change|update|instead|only|scope|global|all)\b/iu.test(quote) && !/(?:不要|别|不必)(?:再)?(?:修改|更正|纠正)|(?:don't|do not|never)\s+(?:change|correct|update)/iu.test(author);
|
|
95
|
+
}
|
|
96
|
+
/** Explicit owner mutations use the existing domain transactions and atomic operation receipts. */
|
|
97
|
+
function createPersonalMemoryTool(deps) {
|
|
98
|
+
return {
|
|
99
|
+
name: "personal_memory",
|
|
100
|
+
label: "Manage memory",
|
|
101
|
+
parameters: schema,
|
|
102
|
+
description: "Remember, correct, forget, or change the scope of memory only on an explicit current owner request. Quote that request in userEvidence. User identity/preferences use target=user; project facts/decisions/lessons use knowledge. For existing items first read their id and version with user_context_read or knowledge_read. Scope IDs come from the current conversation; never guess another agent/project. Report the committed receipt status and scope: saved is durable, pending is not yet usable, forgotten keeps original sources. Changes apply to future turns, not already running prompts. Memory never grants action authority.",
|
|
103
|
+
async execute(_callId, raw) {
|
|
104
|
+
const fail = (error) => ({
|
|
105
|
+
content: [{
|
|
106
|
+
type: "text",
|
|
107
|
+
text: JSON.stringify({
|
|
108
|
+
status: "failed",
|
|
109
|
+
error
|
|
110
|
+
})
|
|
111
|
+
}],
|
|
112
|
+
details: {
|
|
113
|
+
status: "failed",
|
|
114
|
+
error
|
|
115
|
+
},
|
|
116
|
+
isError: true
|
|
117
|
+
});
|
|
118
|
+
if (!Value.Check(schema, raw)) return fail("invalid_memory_arguments");
|
|
119
|
+
const input = raw;
|
|
120
|
+
try {
|
|
121
|
+
const conversationId = deps.getConversationId();
|
|
122
|
+
const config = deps.getConfig();
|
|
123
|
+
if (!conversationId || !config || !getPersonalAgentByConversation(conversationId)) return fail("personal_memory_unavailable");
|
|
124
|
+
const interaction = getSessionInteractionPolicy(conversationId);
|
|
125
|
+
if (interaction.mode === "plan" || interaction.access === "read-only") return fail("memory_write_denied");
|
|
126
|
+
const access = resolveUserContextSessionAccess(config, conversationId);
|
|
127
|
+
if (!(input.target === "user" ? access.userModel : access.knowledge)) return fail("memory_access_denied");
|
|
128
|
+
const writePolicy = input.target === "user" ? config.userContext.userModel.writePolicy : config.userContext.knowledgeMemory.writePolicy;
|
|
129
|
+
if (input.command !== "forget" && writePolicy !== "allow") return fail("memory_write_denied");
|
|
130
|
+
const db = getSqliteDatabase();
|
|
131
|
+
const transcriptId = readCurrentTranscriptId(db, conversationId);
|
|
132
|
+
const source = db.prepare(`SELECT entry_id, role, payload_json FROM transcript_entries
|
|
133
|
+
WHERE transcript_id = ? AND ${learningRoleSql("user")} ORDER BY seq DESC LIMIT 1`).get(transcriptId);
|
|
134
|
+
const message = source && learningTranscriptMessage(source);
|
|
135
|
+
const text = deps.getCurrentUserText();
|
|
136
|
+
if (!source || !message || !text || !extractAgentUserPlainText(message).includes(text) || !explicitRequest(text, input.userEvidence, input.command)) return fail("explicit_current_user_request_required");
|
|
137
|
+
const context = {
|
|
138
|
+
agentId: deps.agentId,
|
|
139
|
+
workspaceId: deps.workspaceId,
|
|
140
|
+
conversationId,
|
|
141
|
+
projectId: deps.getProjectId()
|
|
142
|
+
};
|
|
143
|
+
const resolveScope = (type) => {
|
|
144
|
+
if (type === "global") return { type };
|
|
145
|
+
const id = {
|
|
146
|
+
agent: context.agentId,
|
|
147
|
+
workspace: context.workspaceId,
|
|
148
|
+
project: context.projectId,
|
|
149
|
+
session: conversationId
|
|
150
|
+
}[type];
|
|
151
|
+
if (!id) throw new Error(`missing_${type}_scope`);
|
|
152
|
+
return {
|
|
153
|
+
type,
|
|
154
|
+
id
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
const requestedScope = [
|
|
158
|
+
["project", /(?:只|仅)(?:在|用|对|限于)?.{0,6}(?:本项目|这个项目|当前项目)|only.{0,20}(?:this|current) project/iu],
|
|
159
|
+
["workspace", /(?:只|仅)(?:在|用|对|限于)?.{0,6}(?:本工作区|这个工作区|当前工作区)|only.{0,20}(?:this|current) workspace/iu],
|
|
160
|
+
["session", /(?:只|仅)(?:在|用|对|限于)?.{0,6}(?:本会话|这个会话|当前会话|这次对话)|only.{0,20}(?:this|current) (?:chat|session|conversation)/iu],
|
|
161
|
+
["agent", /(?:只|仅)(?:在|用|对|限于)?.{0,6}(?:本助手|这个助手|当前助手)|only.{0,20}(?:this|current) (?:agent|assistant)/iu]
|
|
162
|
+
].find(([, pattern]) => pattern.test(input.userEvidence))?.[0];
|
|
163
|
+
if (requestedScope && input.scope && requestedScope !== input.scope) return fail("requested_scope_mismatch");
|
|
164
|
+
const digest = createHash("sha256").update(JSON.stringify(input)).digest("hex");
|
|
165
|
+
const receipt = executeAtomicOperation({
|
|
166
|
+
principalId: "local-owner",
|
|
167
|
+
capabilityId: "xopc.personal.memory",
|
|
168
|
+
idempotencyKey: `${source.entry_id}:${digest}`,
|
|
169
|
+
requestDigest: digest,
|
|
170
|
+
descriptorDigest: "chat-memory-v1",
|
|
171
|
+
surface: "personal_chat"
|
|
172
|
+
}, (operationId) => {
|
|
173
|
+
const now = Date.now();
|
|
174
|
+
const user = input.target === "user" && input.id ? getUserAssertion(input.id) : void 0;
|
|
175
|
+
const slot = user && getAssertionSlot(user.slotId);
|
|
176
|
+
const knowledge = input.target === "knowledge" && input.id ? getKnowledgeItem(input.id) : void 0;
|
|
177
|
+
const current = user || knowledge;
|
|
178
|
+
const currentScope = slot?.scope ?? knowledge?.scope;
|
|
179
|
+
if (input.command !== "remember") {
|
|
180
|
+
if (!current || !currentScope || !visible(currentScope, context) || slot && slot.principalId !== "local-owner" || knowledge && (knowledge.principalId !== "local-owner" || knowledge.recordClass !== "memory" || !access.knowledgePolicy.scopes.includes(knowledge.scope.type) || !knowledgeContentSources(knowledge).every((kind) => access.knowledgePolicy.contentSources.includes(kind)))) throw new Error("memory_not_found");
|
|
181
|
+
if (!input.version || input.version !== memoryVersion(user ? {
|
|
182
|
+
assertion: user,
|
|
183
|
+
scope: currentScope
|
|
184
|
+
} : knowledge)) throw new Error("memory_version_conflict_read_again");
|
|
185
|
+
} else if (input.id || input.version) throw new Error("remember_does_not_accept_existing_id");
|
|
186
|
+
if (input.command !== "scope" && currentScope && requestedScope && currentScope.type !== requestedScope) throw new Error("requested_scope_mismatch");
|
|
187
|
+
const scope = input.command === "scope" ? input.scope ?? requestedScope ? resolveScope(input.scope ?? requestedScope) : void 0 : currentScope ?? resolveScope(input.scope ?? requestedScope ?? (input.target === "user" ? "global" : context.projectId ? "project" : "workspace"));
|
|
188
|
+
if (!scope) throw new Error("scope_required");
|
|
189
|
+
if (input.target === "knowledge" && input.command !== "forget" && (!access.knowledgePolicy.scopes.includes(scope.type) || !access.knowledgePolicy.contentSources.includes("memory"))) throw new Error("memory_scope_denied");
|
|
190
|
+
if (input.command !== "scope" && input.command !== "remember" && input.scope) {
|
|
191
|
+
const suppliedScope = resolveScope(input.scope);
|
|
192
|
+
if (suppliedScope.type !== scope.type || suppliedScope.id !== scope.id) throw new Error("use_scope_command_to_change_scope");
|
|
193
|
+
}
|
|
194
|
+
let id = input.id;
|
|
195
|
+
let status = "saved";
|
|
196
|
+
if (input.command === "forget") {
|
|
197
|
+
const links = db.prepare(`SELECT DISTINCT e.conversation_id FROM context_evidence e WHERE e.conversation_id IS NOT NULL
|
|
198
|
+
AND (e.evidence_id IN (SELECT evidence_id FROM user_assertion_evidence WHERE assertion_id IN (SELECT assertion_id FROM user_assertions WHERE slot_id = ?))
|
|
199
|
+
OR e.evidence_id IN (SELECT evidence_id FROM knowledge_evidence_links WHERE knowledge_id = ?)
|
|
200
|
+
OR e.message_id IN (SELECT value FROM knowledge_revisions r, json_each(r.source_json, '$.evidenceRefs') WHERE r.knowledge_id = ?))`).all(user?.slotId ?? "", knowledge?.id ?? "", knowledge?.id ?? "");
|
|
201
|
+
createCollaborationRule({
|
|
202
|
+
category: "boundary",
|
|
203
|
+
priority: 0,
|
|
204
|
+
scope,
|
|
205
|
+
status: "active",
|
|
206
|
+
conditions: {
|
|
207
|
+
enforcementLevel: "prompt",
|
|
208
|
+
forgottenHistoryEntries: [...new Set([
|
|
209
|
+
conversationId,
|
|
210
|
+
knowledge?.sourceConversationId,
|
|
211
|
+
...links.map((link) => link.conversation_id)
|
|
212
|
+
].filter(Boolean))].map((id) => `${id}:*`)
|
|
213
|
+
},
|
|
214
|
+
statement: "Do not automatically recall forgotten information from the marked original conversations."
|
|
215
|
+
});
|
|
216
|
+
if (!(user ? deleteUserAssertion(id) : deleteKnowledgeItem(id, now, { includeRelated: false }))) throw new Error("memory_delete_failed");
|
|
217
|
+
status = "forgotten";
|
|
218
|
+
} else if (input.command === "scope") if (user) status = canUseAssertion(setUserAssertionScope(id, scope), now, {
|
|
219
|
+
use: "answer",
|
|
220
|
+
agentId: context.agentId
|
|
221
|
+
}) ? "saved" : "pending";
|
|
222
|
+
else status = canUseKnowledge(setKnowledgeScope(id, scope), context, access.knowledgePolicy) ? "saved" : "pending";
|
|
223
|
+
else {
|
|
224
|
+
const content = input.content?.trim();
|
|
225
|
+
if (!content) throw new Error("content_required");
|
|
226
|
+
const sensitivity = inferMemorySensitivity(`${content}\n${input.userEvidence}`);
|
|
227
|
+
if (sensitivity === "secret" || sensitivity === "regulated") throw new Error("sensitive_memory_denied");
|
|
228
|
+
const personal = sensitivity === "personal" || user?.sensitivity === "personal";
|
|
229
|
+
const sensitivePolicy = config.userContext.userModel.sensitiveWritePolicy;
|
|
230
|
+
if (personal && sensitivePolicy === "deny") throw new Error("sensitive_memory_denied");
|
|
231
|
+
const evidence = createContextEvidence({
|
|
232
|
+
sourceType: "conversation",
|
|
233
|
+
sourceRef: `chat-memory:${source.entry_id}:${digest}`,
|
|
234
|
+
conversationId,
|
|
235
|
+
messageId: source.entry_id,
|
|
236
|
+
trustLevel: "owner",
|
|
237
|
+
redactedExcerpt: input.userEvidence,
|
|
238
|
+
observedAt: now
|
|
239
|
+
});
|
|
240
|
+
if (input.target === "user") {
|
|
241
|
+
if (!slot && !input.predicate) throw new Error("predicate_required");
|
|
242
|
+
const result = reconcileAssertion({
|
|
243
|
+
subject: slot?.subject ?? {
|
|
244
|
+
type: "user",
|
|
245
|
+
id: "self"
|
|
246
|
+
},
|
|
247
|
+
predicate: slot?.predicate ?? input.predicate,
|
|
248
|
+
cardinality: slot?.cardinality ?? "single",
|
|
249
|
+
scope,
|
|
250
|
+
kind: user?.kind ?? input.userKind ?? "preference",
|
|
251
|
+
value: content,
|
|
252
|
+
normalizedValue: content.normalize("NFKC").toLowerCase(),
|
|
253
|
+
statement: content,
|
|
254
|
+
authority: "user_explicit",
|
|
255
|
+
confidence: 1,
|
|
256
|
+
inferredImportance: user?.inferredImportance ?? .7,
|
|
257
|
+
consequence: user?.consequence ?? "medium",
|
|
258
|
+
actionability: user?.actionability ?? .8,
|
|
259
|
+
volatility: user?.volatility ?? (input.userKind === "current_state" ? "dynamic" : "stable"),
|
|
260
|
+
sensitivity: personal ? "personal" : user?.sensitivity ?? "normal",
|
|
261
|
+
disclosurePolicy: user?.disclosurePolicy ?? "referenceable",
|
|
262
|
+
applicability: user?.applicability,
|
|
263
|
+
domain: user?.domain,
|
|
264
|
+
layer: user?.layer,
|
|
265
|
+
sensitivityCategories: user?.sensitivityCategories,
|
|
266
|
+
purposeIds: user?.purposeIds,
|
|
267
|
+
allowedUses: user?.allowedUses,
|
|
268
|
+
allowedAgentIds: user?.allowedAgentIds,
|
|
269
|
+
validFrom: user?.validFrom,
|
|
270
|
+
reviewAt: user?.reviewAt,
|
|
271
|
+
deleteAfter: user?.deleteAfter,
|
|
272
|
+
validTo: input.validTo ?? user?.validTo,
|
|
273
|
+
observedAt: now,
|
|
274
|
+
createdBy: "user",
|
|
275
|
+
evidenceId: evidence.id,
|
|
276
|
+
...user ? { correctionOfAssertionId: user.id } : {}
|
|
277
|
+
});
|
|
278
|
+
if (!result.assertion) throw new Error("memory_suppressed");
|
|
279
|
+
id = result.assertion.id;
|
|
280
|
+
if (personal && sensitivePolicy === "confirm") setAssertionStatus(id, "needs_review", {
|
|
281
|
+
actor: "user",
|
|
282
|
+
reason: "Sensitive memory requires review."
|
|
283
|
+
});
|
|
284
|
+
status = canUseAssertion(getUserAssertion(id), now, {
|
|
285
|
+
use: "answer",
|
|
286
|
+
agentId: context.agentId
|
|
287
|
+
}) ? "saved" : "pending";
|
|
288
|
+
} else if (knowledge) {
|
|
289
|
+
if (input.validTo !== void 0) throw new Error("change_expiry_in_memory_management");
|
|
290
|
+
const item = reviewKnowledgeItem({
|
|
291
|
+
id,
|
|
292
|
+
action: "edit_and_approve",
|
|
293
|
+
content,
|
|
294
|
+
actor: "user",
|
|
295
|
+
reason: "Explicit correction in chat.",
|
|
296
|
+
expectedStatus: knowledge.status,
|
|
297
|
+
evidence: [{
|
|
298
|
+
id: evidence.id,
|
|
299
|
+
contentHash: evidence.contentHash
|
|
300
|
+
}],
|
|
301
|
+
source: {
|
|
302
|
+
tool: "personal_memory",
|
|
303
|
+
evidenceRefs: [source.entry_id]
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
if (!item) throw new Error("memory_not_found");
|
|
307
|
+
if (personal && sensitivePolicy === "confirm") throw new Error("sensitive_correction_requires_management_review");
|
|
308
|
+
status = canUseKnowledge(item, context, access.knowledgePolicy) ? "saved" : "pending";
|
|
309
|
+
} else {
|
|
310
|
+
const result = writeKnowledgeItem({
|
|
311
|
+
scope,
|
|
312
|
+
kind: input.knowledgeKind ?? "note",
|
|
313
|
+
content,
|
|
314
|
+
canonicalKey: `chat:${memoryVersion(content.normalize("NFKC").toLowerCase())}`,
|
|
315
|
+
status: personal && sensitivePolicy === "confirm" ? "needs_review" : "active",
|
|
316
|
+
verification: "supported",
|
|
317
|
+
claimMode: "explicit",
|
|
318
|
+
confidence: 1,
|
|
319
|
+
importance: .7,
|
|
320
|
+
originClass: "owner",
|
|
321
|
+
sourceAgentId: context.agentId,
|
|
322
|
+
sourceConversationId: conversationId,
|
|
323
|
+
sensitivity,
|
|
324
|
+
validTo: input.validTo,
|
|
325
|
+
evidence: [{
|
|
326
|
+
id: evidence.id,
|
|
327
|
+
contentHash: evidence.contentHash
|
|
328
|
+
}],
|
|
329
|
+
source: {
|
|
330
|
+
tool: "personal_memory",
|
|
331
|
+
evidenceRefs: [source.entry_id]
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
if (!result.item) throw new Error("memory_suppressed");
|
|
335
|
+
id = result.item.id;
|
|
336
|
+
status = canUseKnowledge(result.item, context, access.knowledgePolicy) ? "saved" : "pending";
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
return {
|
|
340
|
+
receiptId: operationId,
|
|
341
|
+
status,
|
|
342
|
+
command: input.command,
|
|
343
|
+
target: input.target,
|
|
344
|
+
id,
|
|
345
|
+
scope,
|
|
346
|
+
committedAt: now,
|
|
347
|
+
effectiveFrom: "next_turn",
|
|
348
|
+
...status === "forgotten" ? { originalSourcesRetained: true } : {}
|
|
349
|
+
};
|
|
350
|
+
});
|
|
351
|
+
notifyUserContextChange({
|
|
352
|
+
kind: "session",
|
|
353
|
+
id: conversationId
|
|
354
|
+
});
|
|
355
|
+
const assertion = receipt.target === "user" ? getUserAssertion(receipt.id) : void 0;
|
|
356
|
+
const item = receipt.target === "knowledge" ? getKnowledgeItem(receipt.id) : void 0;
|
|
357
|
+
const currentScope = assertion ? getAssertionSlot(assertion.slotId)?.scope : item?.scope;
|
|
358
|
+
const current = assertion ?? item;
|
|
359
|
+
const result = {
|
|
360
|
+
...receipt,
|
|
361
|
+
committedScope: receipt.scope,
|
|
362
|
+
scope: currentScope ?? receipt.scope,
|
|
363
|
+
...current ? { version: memoryVersion(assertion ? {
|
|
364
|
+
assertion,
|
|
365
|
+
scope: currentScope
|
|
366
|
+
} : item) } : {},
|
|
367
|
+
available: Boolean(current),
|
|
368
|
+
usable: assertion ? canUseAssertion(assertion, Date.now(), {
|
|
369
|
+
use: "answer",
|
|
370
|
+
agentId: context.agentId
|
|
371
|
+
}) : item ? canUseKnowledge(item, context, access.knowledgePolicy) : false
|
|
372
|
+
};
|
|
373
|
+
return {
|
|
374
|
+
content: [{
|
|
375
|
+
type: "text",
|
|
376
|
+
text: JSON.stringify(result)
|
|
377
|
+
}],
|
|
378
|
+
details: result
|
|
379
|
+
};
|
|
380
|
+
} catch (error) {
|
|
381
|
+
return fail(error instanceof Error ? error.message : "memory_operation_failed");
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
//#endregion
|
|
387
|
+
export { createPersonalMemoryTool };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { CapabilityDispatcher } from "../../capabilities/runtime/dispatcher.js";
|
|
1
2
|
import { isPersonalConversation } from "../../personal-agent/repository.js";
|
|
2
3
|
import { getEmbeddedExecutionSession } from "../embedded/execution-context.js";
|
|
3
4
|
import { LOCAL_READ_MAX_CHARS } from "./local-read-budget.js";
|
|
4
|
-
import { CapabilityDispatcher } from "../../capabilities/runtime/dispatcher.js";
|
|
5
5
|
import { registerNoteReadCapabilities } from "../../notes/capabilities/read.js";
|
|
6
6
|
import { registerAutomationReadCapabilities } from "../../automations/capabilities/read.js";
|
|
7
7
|
import { registerProjectReadCapabilities } from "../../projects/capabilities/read.js";
|
|
@@ -7,6 +7,8 @@ export interface SessionSearchToolDeps {
|
|
|
7
7
|
getPrimaryModel: () => Model<Api>;
|
|
8
8
|
getCurrentConversationId?: () => string | undefined;
|
|
9
9
|
canAccess?: () => boolean;
|
|
10
|
+
canRecallConversation?: (conversationId: string) => boolean;
|
|
11
|
+
canRecallEntry?: (conversationId: string, entryId: string, content: string) => boolean;
|
|
10
12
|
localOnly?: boolean;
|
|
11
13
|
getHistoryContext?: () => CaptureScopeContext;
|
|
12
14
|
getCurrentUserText?: () => string | undefined;
|