diff --git a/docs/en/Agent Integration Guide/Portal User Guide.md b/docs/en/Agent Integration Guide/Portal User Guide.md index f886ad372..4e5930c5f 100644 --- a/docs/en/Agent Integration Guide/Portal User Guide.md +++ b/docs/en/Agent Integration Guide/Portal User Guide.md @@ -149,3 +149,7 @@ read-only fields and shows a message when configuration is unavailable. | Memories are visible and model settings are read-only | Have the host check that configuration management is enabled, the configuration store is writable, and the identity has permission to edit settings. HTTP enables configuration management automatically only for a declared fixed personal identity. A host can also configure its own storage and authorization. | For more integration options, see the [Portal design](../../features/F05-personal-memory-portal.md#6-启动与打开页面). + +## Browse experience memory + +Pass `experience_space` in the JSON body of `POST /portal/api/launch` or as a keyword to the SDK Portal handle’s `launch_url`. Open the link and choose Memory Library → Experience Memory to search, filter by category and inspect read-only details. Links without a bound space retain the personal memory view. diff --git a/docs/features/F05-personal-memory-portal.md b/docs/features/F05-personal-memory-portal.md index 72f56e888..5dbe08692 100644 --- a/docs/features/F05-personal-memory-portal.md +++ b/docs/features/F05-personal-memory-portal.md @@ -95,7 +95,11 @@ KV 模式指由键值存储保存记忆。它能通过相同的公开接口提 切换时侧边栏保持选中记忆仓库。 团队记忆使用 `memory_class=team_memory`,用户画像使用 `memory_class=user_profile`。 项目知识显示 `long_term_memory` 或 `project_memory` 分类中的语义记忆。 -经验记忆使用 `memory_type=experience`。群体记录的列表和详情显示归属与标签,详情显示共享状态。 +经验记忆使用 `memory_type=experience`。签发链接时指定 `experience_space`,原「经验记忆」分类改为展示该空间的有效经验,支持按正文和类别筛选、分页及只读详情。群体记录的列表和详情显示归属与标签,详情显示共享状态。 + +经验列表显示最近一次整理的任务归因次数,详情只显示个人评价。个人评价按当前用户、空间和经验保存,可修改或撤回,不参加检索或整理。 +列表复用仓库搜索框、状态栏、筛选面板、批量选择、布局切换、分页与空态;来源及关联技能可打开 Portal 内只读视图并返回。列表在时间戳前显示三类任务反馈,尚无反馈的计数为零。列表只读取任务反馈计数;若条目在读取计数时已不可访问,显示“—”。有可读来源时,详情按复现记录展示相关任务与会话,按可读来源条目展示经验血缘,技能由同空间有效技能的 provenance 反查。 + 切换入口应用该入口的固定条件,并保留应用、Agent、项目、状态和文字条件。 重置清除附加条件并恢复有效状态,在「全部记忆」中也清除手动选择的分类和层级。 即使某一类型暂无记录,也保留当前视图。 diff --git a/docs/features/common/F04-security-interfaces-and-encryption.md b/docs/features/common/F04-security-interfaces-and-encryption.md index 4d3876dd9..8adc0703d 100644 --- a/docs/features/common/F04-security-interfaces-and-encryption.md +++ b/docs/features/common/F04-security-interfaces-and-encryption.md @@ -316,6 +316,8 @@ policy 或委托人事实。授予上界仅 ROOT 免除普通成员限制;ADMI 个人空间的唯一用户归属主体可点读本空间的系统经验。该例外仅适用于 `get`,且请求条目 和实际返回快照均按各自的真源类型、作者和空间进行判断。该例外排在委托判定之后, 适用的委托已声明时以委托结果为准。 +Portal 经验详情先检查经验条目的读取权限,再按原任务的 Scope 检查内容 READ。 +来源任务和会话仅在记录的组织、用户都与认证身份一致且来源鉴权通过时展示。 当前 `inspect/trace` 仍按 READ 判权,未应用该经验特例,也不经过经验检索 Selector; 有空间 READ 权限且知道条目 ID 的成员仍可经治理读取取得完整经验条目。这是直接读取 限制的现有覆盖缺口,不能把 `get/list` 的限制解释为所有查看入口均已收紧。 diff --git a/docs/specs/S02-memory-api.md b/docs/specs/S02-memory-api.md index acf60a5e1..383088330 100644 --- a/docs/specs/S02-memory-api.md +++ b/docs/specs/S02-memory-api.md @@ -5,7 +5,7 @@ | 项 | 值 | |---|---| | 关联模块 | jiuwen_memory/api/ | -| 最近一次修订日期 | 2026-11-28 | +| 最近一次修订日期 | 2026-11-30 | | 关联特性补充 | docs/features/api/F04-memory-metadata-separation.md,docs/features/api/F05-http-memory-api-alignment.md,docs/features/api/F06-access-parameter-forwarding.md,docs/features/api/F07-access-surface-error-semantics.md,docs/features/api/F09-sdk-runtime-logging.md,docs/features/F05-personal-memory-portal.md | | 关联特性文档 | docs/features/api/F01-memory-api-impl-design.md,docs/features/api/F02-write-infer-extract.md,docs/features/api/F03-batch-write-api.md,docs/features/api/F04-memory-metadata-separation.md,docs/features/api/F05-http-memory-api-alignment.md,docs/features/api/F06-access-parameter-forwarding.md,docs/features/api/F07-access-surface-error-semantics.md,docs/features/api/F09-sdk-runtime-logging.md,docs/features/api/F10-batch-update-api.md,docs/features/F01-system-spec-design.md,docs/features/construction/F02-dynamic-extraction-consolidation.md,docs/features/construction/F04-cc-memory-compat.md,docs/features/construction/F05-construction-spec-multimodal-design.md,docs/features/construction/F08-entity-schema-extension.md,docs/features/common/F01-memory-layer.md,docs/features/common/F03-scope-space-isolation.md,docs/features/common/F08-memory-tree.md,docs/features/common/F09-log-privacy.md,docs/features/retrieval/F03-metadata-filtering.md,docs/features/retrieval/F09-query-rewrite.md,docs/features/control/F04-permission-context-routing.md,docs/features/control/F05-cloud-engine-design.md,docs/features/config/F01-config-source.md,docs/features/control/F07-collective-memory-design.md,docs/features/construction/F13-dreaming.md,docs/features/ingest/F02-assets-ingestor-boundary.md、[F04 安全能力与设计决策](../features/common/F04-security-interfaces-and-encryption.md),docs/features/common/F11-new-trace.md,docs/features/control/F10-async-write-orchestration.md | @@ -173,8 +173,15 @@ SDK 和 HTTP 共用定位顺序,优先使用文档根目录,其次使用实 | 纠正记忆 | `/v1/update` | `scope`、`unit_id`、`patch.content` | 新版 `MemoryUnit`,通过 `supersedes` 指向旧版 | | 遗忘记忆 | `/v1/delete` | `selector.scope`、只含一个 ID 的 `selector.unit_ids`、`selector.mode: "forget"` | 已遗忘的 ID 数组 | | 配置 | `/v1/read_config`、`/v1/save_config` | 见 HTTP 托管配置接口。跨进程共享页面为指定实例的请求附加 `instance_id` | 同上。跨进程共享页面用空请求体调用 `read_config` 时返回 `instances`、`default_instance_id` | -| HTTP 宿主取得页面链接 | `/portal/api/launch` | 使用原认证凭据,可带 `write_target`(`space`、`agent`、`session`) | `portal_url` | -| 浏览器兑换会话 | `/portal/api/bootstrap` | `token`,可选 `embedded` | 普通独立页面建立 HttpOnly Cookie。iframe 和跨进程共享页面返回 `session_token`。跨进程共享页面另返回 `shared: true` | +| 经验列表 | `/v1/experience_list` | 可选 `query`、`category`、`source`、`agent`、`project`、`lifecycle`、`offset`、`limit` | `available`、`items`、`count` 及筛选选项 | +| 经验详情 | `/v1/experience_get` | `unit_id` | 有效经验、反馈、可读的来源与关联技能 | +| 个人评价 | `/v1/experience_rate` | `unit_id`、`choice`(`helpful`、`neutral`、`harmful`、`clear`) | 任务反馈汇总及当前用户的评价 | +| HTTP 宿主取得页面链接 | `/portal/api/launch` | 使用原认证凭据,可带 `write_target`(`space`、`agent`、`session`)和 `experience_space` | `portal_url` | +| 浏览器兑换会话 | `/portal/api/bootstrap` | `token`,可选 `embedded` | 普通独立页面建立 HttpOnly Cookie。iframe、跨进程共享页面和绑定经验空间的页面返回 `session_token`。共享页面另返回 `shared: true`,绑定经验空间的页面另返回 `experience_bound: true` | + +经验接口只接受 Portal 浏览器会话。宿主签发链接时绑定经验空间,显式提供的空间名最多 128 个字符,校验后去除首尾空白。组织取自认证身份,浏览器请求不能指定 Scope。 +未绑定经验空间时,经验列表、详情和评价均返回 404。SDK 宿主可在 Portal 句柄的 +`launch_url` 上传入 `experience_space`,Swarm Provider 会使用当前启用的经验空间。 页面从 `MemoryUnit.segments` 拼接正文,时间取 `temporal.t_ingest`。HTTP `write_target` 由宿主提供,与认证身份合成完整写入范围,随会话绑定。独立访问可以 diff --git a/docs/specs/S10-security.md b/docs/specs/S10-security.md index 989114581..aeba0fbb4 100644 --- a/docs/specs/S10-security.md +++ b/docs/specs/S10-security.md @@ -55,7 +55,10 @@ HTTP 启动先检查上述身份声明,再决定是否打开或创建配置库 授权只兑换一次,随后使用 1 小时有效的浏览器会话。使用 Cookie 时必须为 HttpOnly、 SameSite=Strict,路径限定为 `/v1/`。任意来源的宿主网页均可嵌入 Portal。 iframe 和跨进程共享页面兑换会话票据,经 `X-Memory-Portal-Session` 发送同源请求。 -普通 iframe 的票据保存在页面内存中。 +普通 iframe 的票据保存在页面内存中。宿主签发链接时可绑定经验空间,绑定后页面使用同一请求头,并在 +当前浏览器历史条目中记录会话票据以支持刷新。经验请求使用认证组织和绑定的空间,仍检查记录的读取权限。 +经验详情仅展示当前用户自己的来源任务和会话,并对每个来源 Scope 单独检查内容读取权限。 +共享 Portal 的经验请求只由签发链接的 Provider 处理,来源注销或断开后返回 401。 跨进程共享页面的票据保存在当前浏览器历史条目的状态中,供刷新后继续使用,收到 401 后清除。 共享会话绑定记忆库和签发时的可信身份。该身份可操作具有相同认证主体、角色、凭据标识 和委托的在线实例。 @@ -71,7 +74,7 @@ iframe 和跨进程共享页面兑换会话票据,经 `X-Memory-Portal-Session HTTP 的本机 Host 与 Origin 校验继续生效。 Portal 页面、浏览器会话请求和托管配置接口的响应使用 `Cache-Control: no-store`。 Portal 页面通过 `X-Memory-Portal-Browser: 1` 标记业务请求。此类请求必须有有效的浏览器 -会话,只能调用个人记忆管理和模型配置所需的接口。会话失效返回 401,页面提示重新打开。 +会话,只能调用个人记忆管理、经验记忆和模型配置所需的接口。会话失效返回 401,页面提示重新打开。 HTTP DEV 的直接 API 调用仍使用原认证规则。 SDK 每次请求重新取得并复核宿主的可信身份。HTTP 会话用原凭据重新认证,并保留原来的 diff --git "a/docs/zh/Agent\346\216\245\345\205\245\346\214\207\345\257\274/Portal\344\275\277\347\224\250\346\214\207\345\215\227.md" "b/docs/zh/Agent\346\216\245\345\205\245\346\214\207\345\257\274/Portal\344\275\277\347\224\250\346\214\207\345\215\227.md" index e314b48f1..8a1bba025 100644 --- "a/docs/zh/Agent\346\216\245\345\205\245\346\214\207\345\257\274/Portal\344\275\277\347\224\250\346\214\207\345\215\227.md" +++ "b/docs/zh/Agent\346\216\245\345\205\245\346\214\207\345\257\274/Portal\344\275\277\347\224\250\346\214\207\345\215\227.md" @@ -100,3 +100,7 @@ curl -fsS "${portal_base_url}/portal/api/launch" \ | 能读记忆,模型设置却不可编辑 | 由宿主检查是否启用了配置管理、配置库位置是否可写,以及当前身份是否有配置权限。HTTP 自动启用配置管理需要声明固定个人身份,宿主也可以显式装配配置存储和授权。 | 更多接入选项见 [Portal 设计说明](../../features/F05-personal-memory-portal.md#6-启动与打开页面)。 + +## 查看空间中的经验记忆 + +在 HTTP 签发接口 `POST /portal/api/launch` 的 JSON 请求体中传入 `{"experience_space":"你的空间名"}`,或在 SDK Portal 的 `launch_url` 中传入同名关键字参数。打开返回的链接,选择「记忆仓库 → 经验记忆」,可搜索正文、按类别筛选,点击条目查看适用条件、所需能力和操作建议。普通链接沿用个人记忆范围。 diff --git a/jiuwen_memory/api/memory_api_impl/query_ops.py b/jiuwen_memory/api/memory_api_impl/query_ops.py index dfd5c3af9..4386f2c79 100644 --- a/jiuwen_memory/api/memory_api_impl/query_ops.py +++ b/jiuwen_memory/api/memory_api_impl/query_ops.py @@ -4,12 +4,14 @@ from __future__ import annotations import asyncio +import hashlib import json from collections.abc import Awaitable, Callable from copy import deepcopy from dataclasses import dataclass, replace from datetime import UTC, datetime from functools import partial +from pathlib import PurePosixPath from typing import Any from jiuwen_memory.api.collective import collective_coordinates, dimensions_of @@ -27,6 +29,7 @@ PermissionDeniedError, ValidationError, ) +from jiuwen_memory.common.experience import UtilityStore from jiuwen_memory.common.log import get_logger, metadata_for_log, redact_for_log from jiuwen_memory.common.plaintext import PlaintextDataError from jiuwen_memory.common.security import principal, space_predicates @@ -49,6 +52,7 @@ FilterOp, HierarchyKind, HierarchyRole, + LifecycleState, MemoryUnit, Scope, and_merge, @@ -171,6 +175,14 @@ def _copy_search_extensions(extensions: dict[str, Any]) -> dict[str, Any]: return deepcopy(extensions, memo) +def _is_active_experience(unit: MemoryUnit, scope: Scope) -> bool: + return ( + unit.scope == scope + and unit.lifecycle is LifecycleState.ACTIVE + and unit.system_metadata.get("memory_type") == "experience" + ) + + class QueryOpsMixin: """Data-plane read/update/delete/evolve after PEP.""" @@ -969,6 +981,82 @@ def _list_scope( result.items = visible return result + def experience_task_sources(self, unit_id, scope, *, security): + """Disclose only the current user's authorized session and task references.""" + unit = self.get(unit_id, scope, security=security) + actor = security.auth.actor + if not actor.user or actor.org != scope.org or not _is_active_experience(unit, scope): + return [] + sources = {} + store = UtilityStore(self._engine.kv) + for coordinates, key, event in store.reproduction_sources(scope, unit_id): + org, space, user, agent, session = coordinates + if (org, user) != (actor.org, actor.user): + continue + target = Scope(org=org, space=space, user=user, agent=agent, session=session) + try: + self._authorize(security, target, Action.READ, "experience_source") + except (NotFoundError, PermissionDeniedError): + continue + ref = (session, key.trajectory_id) + if ref not in sources or key.revision > sources[ref]["revision"]: + sources[ref] = { + "session": session, "task": key.trajectory_id, "revision": key.revision, + "agent": agent, "outcome": event.get("outcome", ""), + "occurred_at": event.get("occurred_at", ""), + } + return [sources[ref] for ref in sorted(sources)] + + def experience_counts( + self, unit_id: str, scope: Scope, *, security: RequestSecurityContext, + ) -> tuple[MemoryUnit, dict]: + """Read the authorized experience and its aggregate task feedback.""" + unit = self.get(unit_id, scope, security=security) + actor = security.auth.actor + if scope.org != actor.org or not scope.space or not _is_active_experience(unit, scope): + raise NotFoundError("memory_unit", unit_id) + stats = UtilityStore(self._engine.kv).load_stats(scope, unit_id) + counts = { + "helpful": sum(stats.helpful.values()) if stats else 0, + "neutral": stats.neutral if stats else 0, + "harmful": sum(stats.harmful.values()) if stats else 0, + } + return unit, counts + + def experience_feedback( + self, unit_id: str, scope: Scope, *, security: RequestSecurityContext, + choice: str = "read", + ) -> tuple[MemoryUnit, dict]: + """Read an authorized experience and its stats; optionally replace my own assessment.""" + unit, counts = self.experience_counts(unit_id, scope, security=security) + if choice not in ("read", "clear", "helpful", "neutral", "harmful"): + raise ValidationError("invalid personal experience feedback") + actor = security.auth.actor + kv = self._engine.kv + feedback = {"counts": counts, "can_rate": bool(actor.user), "mine": None} + if not actor.user: + if choice != "read": + raise PermissionDeniedError(message="personal feedback requires a user") + return unit, feedback + owner = Scope(org=actor.org, user=actor.user) + target = json.dumps([actor.org, actor.user, scope.space, unit_id]).encode() + key = str(PurePosixPath("/experience/personal-rating", hashlib.sha256(target).hexdigest())) + if choice == "clear": + kv.delete(owner, key) + elif choice == "read": + try: + feedback["mine"] = kv.get(owner, key).decode("ascii") + except NotFoundError: + pass + else: + value = choice.encode("ascii") + try: + kv.insert(owner, key, value) + except ConflictError: + kv.update(owner, key, value) + feedback["mine"] = choice + return unit, feedback + def get( self, unit_id: str, diff --git a/jiuwen_memory/common/AGENTS.md b/jiuwen_memory/common/AGENTS.md index a5e831d08..1657fd367 100644 --- a/jiuwen_memory/common/AGENTS.md +++ b/jiuwen_memory/common/AGENTS.md @@ -15,16 +15,10 @@ |---|---| | `relations/legacy.py` | 旧关系到候选证据关系的显式纯函数映射;相似/共指不升级为证据 | | `relations/catalog.py` / `type_def/continuity.py` | 关系与职责启动目录、接续 DTO;职责与权限角色分离 | - -TaskRequest 的 title/description/parent_task_id/query/top_k 追加在旧位置字段之后; -find 上下文参数成对校验,语义候选不代表选定任务或拥有来源读取权限。 -创建带 parent_task_id 的任务时,continuity_task_parent 必须登记到 ENTRY_RULES 的内容 READ 轴, -与任务查询使用同一项目读取权限;不能落回条目级授权路径。 | `base.py` | Plugin 基类:所有共享插件的自描述契约 | | `bootstrap.py` | 统一触发各插件注册(per-layer bootstrap) | | `errors.py` | 自定义异常(含组件能力不匹配的 `UnsupportedCapabilityError`) | | `ingest_cancellation.py` | 摄入任务局部取消信号、检查点异常与可唤醒等待;不依赖 control、不读取业务 metadata | - | `text_split.py` | 摄入与内容型 prompt 共用段落切分;可选 boundary 回调只向前调整硬切点,不扩大长度上限 | | `_support.py` | 跨层共用的小工具:配置值布尔归一(`as_bool`)、本地模型来源与 CPU fp16 降级解析(`resolve_model_source`/`resolve_effective_fp16`)、SSL 配置读取与装配期校验(`SslConfig`/`build_ssl_config`/`require_tls_scheme`/`require_ca_file`/`outbound_verify`/`read_ssl_config`/`reject_url_tls_params`)、scope 命名空间渲染(`SCOPE_DIMS`/`scope_segments`)、后端异常归一(`wrap_backend`);storage、lock 与出站客户端共用,避免各写一份 | | `_import_support.py` | 导入容错样板的唯一归属地(`import_optional`/`import_required`/`import_required_attr`):装配各 `*_impl` 包触发 `@Producer.register` 时逐个隔离可选依赖,单个缺失只让该插件缺席、不连坐同批其他插件、不阻断 `MemoryAPI` 构造。刻意与 `_support.py` 分家——后者讲配置值语义且连带 `type_def`/`Factory`/`errors`,本模块讲导入机制且**只依赖标准库**(51 个 `*_impl`/bootstrap 消费点各自 import 一次,自身须停在零项目依赖);**不得**引入任何 `jiuwen_memory` 内部对象,以免装配期导入顺序反受各层先后影响。接入侧另有一份 `jiuwen_memory_entry/core/import_support.py`——Access 只允许依赖 `jiuwen_memory.api`(见 `tests/unit/api/test_access_api_boundary.py`),两侧不复用 | @@ -60,6 +54,12 @@ find 上下文参数成对校验,语义候选不代表选定任务或拥有来 | `trace/runtime.py` | 具名 Factory 插件、API/执行器策略绑定、后台独立作用域;资源由 runtime 收尾,详情见 trace/AGENTS.md | | `trace/` | TraceCollector 横切接口目录:请求级处理过程追踪(`trace/trace.py` 接口 + ContextVar 作用域 + 调用树;模块级 `trace_event(component, stage, data)` / `trace_span` / `@traced` 零参数埋点,`simple < info < debug` 三级详细程度,debug data 支持惰性 callable;`trace_impl/` 四种内置实现 noop/memory/log/memory_log)。config `trace.default.target` 选默认实现,请求级 `extensions["trace"] = "[:]"` 覆盖(入口层在参数校验前剥离);使用方法与边界见 [F11-new-trace.md](../../docs/features/common/F11-new-trace.md) | +TaskRequest 的 title/description/parent_task_id/query/top_k 追加在旧位置字段之后; +find 上下文参数成对校验,语义候选不代表选定任务或拥有来源读取权限。 +创建带 parent_task_id 的任务时,continuity_task_parent 必须登记到 ENTRY_RULES 的内容 READ 轴, +与任务查询使用同一项目读取权限;不能落回条目级授权路径。 +经验详情中的来源任务和会话按来源 Scope 单独授权,`experience_source` 登记为内容轴 READ。 + ### 隐私与用户访问控制能力 `security/privacy/base.py` 定义独立的 PrivacyProtection/PrivacyProducer; diff --git a/jiuwen_memory/common/experience.py b/jiuwen_memory/common/experience.py index 9b4fd55c7..77afd5ed1 100644 --- a/jiuwen_memory/common/experience.py +++ b/jiuwen_memory/common/experience.py @@ -475,6 +475,24 @@ def save_baseline(self, scope: Scope, baseline: Mapping[str, float]) -> None: except NotFoundError: self._kv.insert(scope, BASELINE_KEY, payload) + def reproduction_sources(self, scope: Scope, entry_id: str): + """Read the recorded task coordinates for one experience, across revisions.""" + for key, raw in self._kv.scan(scope, f"{UTILITY_KEY_PREFIX}{entry_id}/repro:"): + parsed = parse_utility_event_key(key) + if not parsed or parsed.entry_id != entry_id or not parsed.trajectory_id: + continue + try: + event = decode_payload(raw) + except ValueError: + continue + if not isinstance(event, dict) or event.get("trajectory_id") != parsed.trajectory_id: + continue + coordinates = event.get("source_scope") + if not isinstance(coordinates, list) or len(coordinates) != 5: + continue + if all(isinstance(value, str) for value in coordinates): + yield coordinates, parsed, event + def scan_events(self, scope: Scope) -> list[tuple[UtilityEventKey, dict[str, Any]]]: """按前缀扫出全部效用事件并解出键与载荷(聚合的输入,§2.5.2 第 1 步)。 diff --git a/jiuwen_memory/common/security/space_roles.py b/jiuwen_memory/common/security/space_roles.py index 69f7b0e7b..5f7bf20d1 100644 --- a/jiuwen_memory/common/security/space_roles.py +++ b/jiuwen_memory/common/security/space_roles.py @@ -209,6 +209,7 @@ class EntryRule: "search": EntryRule(SpaceAxis.CONTENT, SpaceAction.READ), "list": EntryRule(SpaceAxis.CONTENT, SpaceAction.READ), "get": EntryRule(SpaceAxis.CONTENT, SpaceAction.READ), + "experience_source": EntryRule(SpaceAxis.CONTENT, SpaceAction.READ), "inspect": EntryRule(SpaceAxis.CONTENT, SpaceAction.READ), "trace": EntryRule(SpaceAxis.CONTENT, SpaceAction.READ), # 取内容轴读动作、又不带条目信息,因此第 7 步对它另设排除:落第 10 步的 diff --git a/jiuwen_memory_adapter/jiuwenswarm/agent_memory_provider.py b/jiuwen_memory_adapter/jiuwenswarm/agent_memory_provider.py index 0c82d0387..c4a3f6d54 100644 --- a/jiuwen_memory_adapter/jiuwenswarm/agent_memory_provider.py +++ b/jiuwen_memory_adapter/jiuwenswarm/agent_memory_provider.py @@ -1086,12 +1086,17 @@ def portal_url(self): if handle is None: return None scope = self._portal_write_scope() - if self._portal_identity is None: - link = handle.launch_url(scope) - else: - link = handle.launch_url(scope, identity=self._portal_identity) + link = handle.launch_url(scope, **self._portal_launch_options()) return self._with_portal_language(link) if link is not None else None + def _portal_launch_options(self): + options = {} + if self._portal_identity is not None: + options["identity"] = self._portal_identity + if self._experience_enabled: + options["experience_space"] = self._experience_space + return options + def _with_portal_language(self, link: str) -> str: if self._portal_language is None: return link @@ -1132,9 +1137,11 @@ async def open_portal(self): try: scope = self._portal_write_scope() if self._portal_identity is None: - link = await asyncio.to_thread(handle.launch_url, scope) + link = await asyncio.to_thread( + handle.launch_url, scope, **self._portal_launch_options(), + ) else: - link = handle.launch_url(scope, identity=self._portal_identity) + link = handle.launch_url(scope, **self._portal_launch_options()) except Exception as exc: self._portal_error = type(exc).__name__ raise @@ -1143,7 +1150,10 @@ async def open_portal(self): opener = getattr(self._client, "open_portal", None) if callable(opener): try: - link = await opener(self.bound_scope()) + options = ( + {"experience_space": self._experience_space} if self._experience_enabled else {} + ) + link = await opener(self.bound_scope(), **options) except Exception as exc: self._portal_error = type(exc).__name__ raise @@ -2924,7 +2934,7 @@ async def evolve_extract(self, scope) -> None: job_id = await self._post_verb("evolve", payload, write=True) logger.info("[AgentMemoryMemoryProvider/http] /v1/evolve -> job_id=%s", job_id) - async def open_portal(self, scope=None): + async def open_portal(self, scope=None, *, experience_space=None): self.portal_available = False if self._http is None: await self.initialize() @@ -2932,6 +2942,8 @@ async def open_portal(self, scope=None): if scope is not None: mapped = self._scope_payload(scope) payload["write_target"] = {name: mapped[name] for name in ("space", "agent", "session")} + if experience_space is not None: + payload["experience_space"] = experience_space response = await self._http.post( f"{self._base_url}/portal/api/launch", json=payload, diff --git a/jiuwen_memory_entry/http_server/__main__.py b/jiuwen_memory_entry/http_server/__main__.py index 238bf62b3..e2710a3a2 100644 --- a/jiuwen_memory_entry/http_server/__main__.py +++ b/jiuwen_memory_entry/http_server/__main__.py @@ -43,7 +43,12 @@ from jiuwen_memory_entry.core.error_response import error_response from jiuwen_memory_entry.core.import_support import import_required, import_required_attr from jiuwen_memory_entry.http_server.human_view import handle_human_request -from jiuwen_memory_entry.portal.requests import BROWSER_VERBS, invoke_browser_api +from jiuwen_memory_entry.portal.requests import ( + BROWSER_VERBS, + EXPERIENCE_VERBS, + invoke_browser_api, + portal_experience_space, +) from jiuwen_memory_entry.portal.sessions import ( BROWSER_HEADER, SESSION_HEADER, @@ -344,7 +349,8 @@ def handle_post(self) -> None: if browser_request and verb not in BROWSER_VERBS: self._send_error("NotFound", request_id=request_id) return - if not is_known_verb(verb) and verb not in CONFIG_VERBS: + portal_experience = browser_request and verb in EXPERIENCE_VERBS + if not (is_known_verb(verb) or verb in CONFIG_VERBS or portal_experience): self._send_error("UnknownVerb", verb, request_id=request_id) return else: @@ -391,7 +397,7 @@ def handle_post(self) -> None: self._send(200, body, request_id=request_id, cookie=cookie) return credentials = credentials_from_headers(self.headers, peer_address=peer) - write_scope = None + write_scope = experience_space = None if browser_request: valid, access = srv.portal_sessions.lookup( self.headers.get("Cookie"), token=self.headers.get(SESSION_HEADER), @@ -399,7 +405,7 @@ def handle_post(self) -> None: if not valid: self._send_error("AuthenticationError", request_id=request_id) return - credentials, owner, write_scope = access + credentials, owner, write_scope, experience_space = access context_request_id = request_id try: with authenticated( @@ -443,12 +449,22 @@ def handle_post(self) -> None: ) return if is_portal: - if not isinstance(payload, dict) or payload.keys() - {"write_target"}: + if ( + not isinstance(payload, dict) + or payload.keys() - {"write_target", "experience_space"} + ): raise ValidationError("invalid Portal launch fields") owner = deepcopy(security.auth.actor) if "write_target" in payload: write_scope = _portal_write_scope(payload["write_target"], owner) - token = srv.portal_sessions.issue((credentials, owner, write_scope)) + if "experience_space" in payload: + experience_space = portal_experience_space( + payload["experience_space"] + ) + token = srv.portal_sessions.issue( + (credentials, owner, write_scope, experience_space), + page_bound=experience_space is not None, + ) body = { "portal_url": urlunsplit(( "http", self.headers["Host"], "/portal/", "", f"access={token}", @@ -458,6 +474,7 @@ def handle_post(self) -> None: body = invoke_browser_api( srv.api, verb, payload, configuration=srv.configuration, security=security, write_scope=write_scope, + experience_space=experience_space, ) elif verb in CONFIG_VERBS: body = invoke_configuration( diff --git a/jiuwen_memory_entry/portal/hosting.py b/jiuwen_memory_entry/portal/hosting.py index fe7c04031..f154e3e71 100644 --- a/jiuwen_memory_entry/portal/hosting.py +++ b/jiuwen_memory_entry/portal/hosting.py @@ -21,7 +21,11 @@ new_request_context, ) from jiuwen_memory_entry.core.api_contract import CONFIG_VERBS -from jiuwen_memory_entry.portal.requests import BROWSER_VERBS, invoke_browser_api +from jiuwen_memory_entry.portal.requests import ( + BROWSER_VERBS, + invoke_browser_api, + portal_experience_space, +) from jiuwen_memory_entry.portal.sessions import ( SESSION_HEADER, BrowserSessions, @@ -66,11 +70,13 @@ def process_request_thread(self, request, client_address): self.slots.release() -def runtime_request(runtime, auth, verb, payload, write_scope, *, peer="127.0.0.1"): +def runtime_request( + runtime, auth, verb, payload, write_scope, *, peer="127.0.0.1", experience_space=None, +): security = new_request_context(auth, surface=Surface.HTTP, peer=peer) return invoke_browser_api( runtime.api, verb, payload, security=security, write_scope=write_scope, - configuration=getattr(runtime, "configuration", None), + configuration=getattr(runtime, "configuration", None), experience_space=experience_space, ) @@ -190,10 +196,11 @@ def log_message(self, *_args): self.server.server_close() raise - def launch_url(self, write_scope=None): + def launch_url(self, write_scope=None, *, page_bound=False): if self.closed: return None - return self.address + "#access=" + self.sessions.issue(deepcopy(write_scope)) + token = self.sessions.issue(deepcopy(write_scope), page_bound=page_bound) + return self.address + "#access=" + token def close(self): with self.close_lock: @@ -256,7 +263,9 @@ def provider_entry(self, identity): return None return self._providers.get(identity) - def launch_url(self, write_scope=None, *, identity=None): + def launch_url(self, write_scope=None, *, identity=None, experience_space=None): + if experience_space is not None: + experience_space = portal_experience_space(experience_space) with self._providers_lock: if self.closed: return None @@ -266,7 +275,10 @@ def launch_url(self, write_scope=None, *, identity=None): identity = next(iter(self._providers)) if identity not in self._providers: raise PermissionDeniedError(message="Portal provider is not registered") - return super().launch_url({"write_scope": write_scope, "identity": identity}) + return super().launch_url({ + "write_scope": write_scope, "identity": identity, + "experience_space": experience_space, + }, page_bound=experience_space is not None) def dispatch(self, verb, payload, binding, peer): identity = binding.get("identity") if isinstance(binding, dict) else None @@ -283,6 +295,7 @@ def dispatch(self, verb, payload, binding, peer): } return 200, runtime_request( self.runtime, auth, verb, payload, binding.get("write_scope"), peer=peer, + experience_space=binding.get("experience_space"), ) def close(self): diff --git a/jiuwen_memory_entry/portal/index.html b/jiuwen_memory_entry/portal/index.html index d65d5a92c..8d76c4500 100644 --- a/jiuwen_memory_entry/portal/index.html +++ b/jiuwen_memory_entry/portal/index.html @@ -348,6 +348,33 @@ .source-count { grid-column:2; grid-row:1; } .source-name { white-space:normal; overflow-wrap:anywhere; } } +.experience-reactions,.experience-rating { display:inline-flex; align-items:center; gap:12px; flex-wrap:wrap; } +.experience-reactions { font-variant-numeric:tabular-nums; } +.experience-reactions .helpful { color:#23694f; } +.experience-reactions .neutral { color:#596574; } +.experience-reactions .harmful { color:#984b42; } +.experience-rating { gap:4px; } +.experience-rating .rating-choice { border:0; border-radius:999px; background:transparent; color:#545961; display:inline-flex; gap:5px; align-items:center; padding:5px 9px; } +.experience-rating .rating-choice:hover,.experience-rating .rating-choice[aria-pressed=true] { color:#184d85; background:#e8f0fb; } +.reaction-icon { font:20px/1 "Segoe UI Symbol",sans-serif; } +#experience-dialog .dialog-header { align-items:center; padding:16px 24px; border-bottom:1px solid var(--line); } +#experience-detail { padding:22px clamp(16px,4vw,26px) 28px; } +.experience-intro { padding-bottom:20px; border-bottom:1px solid var(--line); } +.experience-byline { display:flex; flex-wrap:wrap; gap:6px 12px; align-items:center; color:var(--muted); font-size:12px; } +.experience-category-tag { padding:2px 8px; border-radius:6px; background:#edf3fb; color:#375a80; font-weight:600; } +#experience-detail .experience-title { font-size:clamp(19px,4vw,23px); line-height:1.4; margin:12px 0 0; overflow-wrap:anywhere; } +.experience-copy { margin:9px 0 0; color:#434a54; line-height:1.75; white-space:pre-wrap; overflow-wrap:anywhere; } +.experience-conditions { display:grid; grid-template-columns:repeat(auto-fit,minmax(min(165px,100%),1fr)); gap:16px; margin:20px 0; } +.experience-conditions dt,.experience-step h3 { color:#495668; font-size:13px; font-weight:600; margin:0 0 5px; } +.experience-conditions dd { margin:0; line-height:1.65; white-space:pre-wrap; overflow-wrap:anywhere; } +.experience-step { margin:18px 0; padding:14px 16px; border-inline-start:3px solid #83a8d8; border-radius:0 8px 8px 0; background:#f2f6fb; } +.experience-step .experience-copy { margin:0; } +#experience-detail > h3:not(.detail-heading),.experience-review h3 { font-size:14px; margin:22px 0 8px; } +.experience-related { display:flex; width:100%; justify-content:space-between; gap:16px; border:0; border-bottom:1px solid #edf0f3; border-radius:0; padding:10px 2px; text-align:start; color:#345a84; overflow-wrap:anywhere; } +.experience-related::after { content:'›'; color:#728297; } +.experience-review { margin-top:22px; padding-top:14px; border-top:1px solid var(--line); } +.experience-review h3 { margin:0 0 6px; } +.experience-review [role=status]:empty { display:none; }
访问会话已失效,请从应用重新打开记忆管理。
@@ -529,6 +557,7 @@

筛选

记忆概览POST /v1/listoverview · lifecycle_counts
来源应用数统计所有可见记录中已标注的应用。来源分布统计有效记忆,日期按浏览器时区统计全部状态的写入。复制 / 导出 / 批量遗忘/v1/get, /v1/delete只处理本页所选记录;复制和导出前重新读取详情,导出 JSON 不含页面内部记录标识。遗忘逐条调用接口并报告部分失败。记忆列表与筛选POST /v1/listitems / count / snapshot;筛选后计数、再分页;sources / agents / projects / memory_classes 来自完整授权集合。 来源应用/v1/list, /v1/getsource ← system_metadata.source_app;缺失显示“未标注来源”。 Agent / 项目/v1/list, /v1/getagent ← scope.agent;agent_label 是显示名称。project ← 文档记忆的 system_metadata.project(直传)或 coords.project(router 回写),空值显示“跨项目 / 未标注”。 + 经验记忆/v1/experience_list, /v1/experience_get从打开页面时绑定的经验空间读取当前有权查看的有效经验。 内容快捷筛选POST /v1/list团队记忆使用 memory_class=team_memory。用户画像使用 memory_class=user_profile。项目知识使用 memory_class ∈ {long_term_memory, project_memory}, tier=semantic。经验记忆使用 memory_type=experience。其他筛选条件继续生效。层级 / 记忆分类/v1/list, /v1/gettier ← MemoryTier.value;筛选项对应六个认知层级。memory_class ← system_metadata.memory_class;memory_classes 来自授权集合,支持自定义分类。层级 archival 与生命周期 archived 是不同维度。 完整详情与时间POST /v1/get每次重读 segments / lifecycle / tags / source_ref / supersedes / temporal.t_ingest;时间来自 temporal.t_ingest,不是文件修改时间。 新增 / 纠正 / 遗忘/v1/add, /v1/update, /v1/delete新增提交正文、Agent 和可选项目;宿主可绑定实际 Agent 范围。纠正与遗忘通过 scope 和 unit_id 定位,服务端再次检查归属和权限。纠正创建 SUPERSEDE 新版;遗忘使用 FORGET。 @@ -548,6 +577,10 @@

筛选

+ + +

经验详情

+