@downcity/agent 1.1.328 → 1.1.331

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.
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Workspace 可扩展基类。
3
+ *
4
+ * 职责说明(中文)
5
+ * - 定义 Agent 依赖的 Workspace 资源契约与环境变量生命周期。
6
+ * - 不绑定本地文件系统、远程文件系统或具体执行后端。
7
+ * - 本地 Workspace 与 Cloudflare Computer Workspace 均通过该基类接入 Agent。
8
+ */
9
+
10
+ import type { Shell } from "@downcity/shell";
11
+ import type { AgentStore } from "@/types/store/AgentStore.js";
12
+ import type { FileSystem } from "@/types/workspace/FileSystem.js";
13
+ import { LocalAgentStore } from "@/workspace/store/LocalAgentStore.js";
14
+ import type { WorkspaceTools } from "@/types/workspace/WorkspaceTools.js";
15
+ import type {
16
+ WorkspaceEnvPatch,
17
+ WorkspaceEnvSubscriber,
18
+ WorkspaceEnvUnsubscribe,
19
+ } from "@/types/workspace/WorkspaceEnv.js";
20
+
21
+ /** Agent 所需的可扩展 Workspace 基类。 */
22
+ export abstract class WorkspaceBase {
23
+ /** 子类完成自身资源装配前调用的无状态基类构造函数。 */
24
+ protected constructor() {}
25
+
26
+ /** Workspace 的稳定逻辑根路径;远程实现可以使用虚拟路径。 */
27
+ abstract readonly path: string;
28
+
29
+ /** Workspace 内统一的文件与搜索能力。 */
30
+ abstract readonly files: FileSystem;
31
+
32
+ /** Workspace 提供给 Agent 的模型工具。 */
33
+ abstract readonly tools: WorkspaceTools;
34
+
35
+ /** Workspace 提供的可选命令执行能力。 */
36
+ abstract readonly shell?: Shell;
37
+
38
+ /** 返回当前 Workspace 环境变量快照。 */
39
+ abstract get_env(): Record<string, string>;
40
+
41
+ /** 整体替换 Workspace 环境变量。 */
42
+ abstract set_env(next: WorkspaceEnvPatch): void;
43
+
44
+ /** 增量修改 Workspace 环境变量。 */
45
+ abstract patch_env(patch: WorkspaceEnvPatch): void;
46
+
47
+ /** 订阅 Workspace 环境变量变化。 */
48
+ abstract subscribe_env(
49
+ subscriber: WorkspaceEnvSubscriber,
50
+ ): WorkspaceEnvUnsubscribe;
51
+
52
+ /** 将 Workspace 绑定到唯一 Agent,并返回该 Agent 的 Store。 */
53
+ abstract bind_agent(agent_id: string): AgentStore;
54
+
55
+ /** 使用当前 Workspace FileSystem 创建默认结构化 AgentStore。 */
56
+ protected create_agent_store(agent_id: string): AgentStore {
57
+ return new LocalAgentStore({ files: this.files, agent_id });
58
+ }
59
+
60
+ /** 释放 Workspace 持有的资源。 */
61
+ abstract dispose(): Promise<void>;
62
+ }