@downcity/agent 1.1.43 → 1.1.51

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.
Files changed (171) hide show
  1. package/README.md +6 -8
  2. package/bin/agent/Agent.d.ts +31 -16
  3. package/bin/agent/Agent.d.ts.map +1 -1
  4. package/bin/agent/Agent.js +47 -63
  5. package/bin/agent/Agent.js.map +1 -1
  6. package/bin/agent/RemoteAgent.d.ts +6 -6
  7. package/bin/agent/RemoteAgent.d.ts.map +1 -1
  8. package/bin/agent/RemoteAgent.js +377 -267
  9. package/bin/agent/RemoteAgent.js.map +1 -1
  10. package/bin/config/AgentInitializer.d.ts +4 -4
  11. package/bin/config/AgentInitializer.d.ts.map +1 -1
  12. package/bin/config/AgentInitializer.js +14 -12
  13. package/bin/config/AgentInitializer.js.map +1 -1
  14. package/bin/config/Config.d.ts +9 -30
  15. package/bin/config/Config.d.ts.map +1 -1
  16. package/bin/config/Config.js +23 -70
  17. package/bin/config/Config.js.map +1 -1
  18. package/bin/config/Defaults.d.ts.map +1 -1
  19. package/bin/config/Defaults.js +1 -9
  20. package/bin/config/Defaults.js.map +1 -1
  21. package/bin/config/DowncitySchema.d.ts.map +1 -1
  22. package/bin/config/DowncitySchema.js +3 -111
  23. package/bin/config/DowncitySchema.js.map +1 -1
  24. package/bin/config/ExecutionBinding.d.ts +0 -15
  25. package/bin/config/ExecutionBinding.d.ts.map +1 -1
  26. package/bin/config/ExecutionBinding.js +1 -21
  27. package/bin/config/ExecutionBinding.js.map +1 -1
  28. package/bin/config/Paths.d.ts +4 -43
  29. package/bin/config/Paths.d.ts.map +1 -1
  30. package/bin/config/Paths.js +10 -30
  31. package/bin/config/Paths.js.map +1 -1
  32. package/bin/config/PlatformPaths.d.ts +0 -4
  33. package/bin/config/PlatformPaths.d.ts.map +1 -1
  34. package/bin/config/PlatformPaths.js +5 -1
  35. package/bin/config/PlatformPaths.js.map +1 -1
  36. package/bin/executor/composer/system/default/assets/init/PROFILE.md.d.ts +1 -1
  37. package/bin/executor/composer/system/default/assets/init/PROFILE.md.d.ts.map +1 -1
  38. package/bin/executor/composer/system/default/assets/init/PROFILE.md.js +1 -1
  39. package/bin/executor/composer/system/default/assets/init/PROFILE.md.js.map +1 -1
  40. package/bin/executor/tools/shell/ShellToolFormatting.js +2 -2
  41. package/bin/executor/tools/shell/ShellToolFormatting.js.map +1 -1
  42. package/bin/executor/types/SessionRun.d.ts +1 -1
  43. package/bin/index.d.ts +4 -6
  44. package/bin/index.d.ts.map +1 -1
  45. package/bin/index.js +5 -5
  46. package/bin/index.js.map +1 -1
  47. package/bin/plugin/core/PluginCommandRequest.d.ts +1 -1
  48. package/bin/plugin/core/PluginCommandRequest.js +1 -1
  49. package/bin/plugin/core/PluginLocalExecution.d.ts.map +1 -1
  50. package/bin/plugin/core/PluginLocalExecution.js +4 -8
  51. package/bin/plugin/core/PluginLocalExecution.js.map +1 -1
  52. package/bin/plugin/types/PluginApi.d.ts +1 -1
  53. package/bin/rpc/Client.d.ts +104 -0
  54. package/bin/rpc/Client.d.ts.map +1 -0
  55. package/bin/rpc/Client.js +300 -0
  56. package/bin/rpc/Client.js.map +1 -0
  57. package/bin/rpc/Server.d.ts +41 -0
  58. package/bin/rpc/Server.d.ts.map +1 -0
  59. package/bin/rpc/Server.js +164 -0
  60. package/bin/rpc/Server.js.map +1 -0
  61. package/bin/runtime/host/daemon/Api.d.ts +1 -1
  62. package/bin/runtime/host/daemon/Client.d.ts +1 -1
  63. package/bin/runtime/host/daemon/Client.d.ts.map +1 -1
  64. package/bin/runtime/host/daemon/Client.js +30 -20
  65. package/bin/runtime/host/daemon/Client.js.map +1 -1
  66. package/bin/runtime/server/http/control/OverviewRoutes.js +1 -1
  67. package/bin/runtime/server/http/control/OverviewRoutes.js.map +1 -1
  68. package/bin/session/index.d.ts +1 -1
  69. package/bin/session/index.d.ts.map +1 -1
  70. package/bin/session/index.js +1 -1
  71. package/bin/session/index.js.map +1 -1
  72. package/bin/session/storage/Paths.d.ts +0 -4
  73. package/bin/session/storage/Paths.d.ts.map +1 -1
  74. package/bin/session/storage/Paths.js +0 -6
  75. package/bin/session/storage/Paths.js.map +1 -1
  76. package/bin/types/agent/AgentTypes.d.ts +23 -52
  77. package/bin/types/agent/AgentTypes.d.ts.map +1 -1
  78. package/bin/types/config/AgentProject.d.ts +6 -5
  79. package/bin/types/config/AgentProject.d.ts.map +1 -1
  80. package/bin/types/config/DowncityConfig.d.ts +8 -66
  81. package/bin/types/config/DowncityConfig.d.ts.map +1 -1
  82. package/bin/types/config/LlmConfig.d.ts +1 -1
  83. package/bin/types/config/Start.d.ts +3 -0
  84. package/bin/types/config/Start.d.ts.map +1 -1
  85. package/bin/types/config/Start.js +2 -0
  86. package/bin/types/config/Start.js.map +1 -1
  87. package/bin/types/runtime/host/Store.d.ts +7 -50
  88. package/bin/types/runtime/host/Store.d.ts.map +1 -1
  89. package/bin/types/runtime/platform/Platform.d.ts +6 -6
  90. package/bin/types/runtime/platform/Platform.d.ts.map +1 -1
  91. package/bin/types/runtime/platform/PlatformGateway.d.ts +2 -2
  92. package/bin/types/runtime/platform/PlatformGateway.d.ts.map +1 -1
  93. package/bin/utils/Time.d.ts +0 -1
  94. package/bin/utils/Time.d.ts.map +1 -1
  95. package/bin/utils/Time.js +0 -7
  96. package/bin/utils/Time.js.map +1 -1
  97. package/bin/utils/storage/index.d.ts +0 -1
  98. package/bin/utils/storage/index.d.ts.map +1 -1
  99. package/bin/utils/storage/index.js +0 -6
  100. package/bin/utils/storage/index.js.map +1 -1
  101. package/package.json +4 -6
  102. package/src/agent/Agent.ts +54 -71
  103. package/src/agent/RemoteAgent.ts +515 -345
  104. package/src/config/AgentInitializer.ts +14 -12
  105. package/src/config/Config.ts +28 -85
  106. package/src/config/Defaults.ts +1 -9
  107. package/src/config/DowncitySchema.ts +3 -113
  108. package/src/config/ExecutionBinding.ts +1 -23
  109. package/src/config/Paths.ts +10 -43
  110. package/src/config/PlatformPaths.ts +5 -1
  111. package/src/executor/composer/system/default/assets/init/PROFILE.md.ts +1 -1
  112. package/src/executor/composer/system/default/assets/init/PROFILE.md.ts.txt +1 -2
  113. package/src/executor/tools/shell/ShellToolFormatting.ts +2 -2
  114. package/src/executor/types/SessionRun.ts +1 -1
  115. package/src/index.ts +7 -14
  116. package/src/plugin/core/PluginCommandRequest.ts +1 -1
  117. package/src/plugin/core/PluginLocalExecution.ts +4 -8
  118. package/src/plugin/types/PluginApi.ts +1 -1
  119. package/src/rpc/Client.ts +467 -0
  120. package/src/rpc/Server.ts +302 -0
  121. package/src/runtime/host/daemon/Api.ts +1 -1
  122. package/src/runtime/host/daemon/Client.ts +44 -22
  123. package/src/runtime/server/http/control/OverviewRoutes.ts +1 -1
  124. package/src/session/index.ts +0 -1
  125. package/src/session/storage/Paths.ts +0 -10
  126. package/src/types/agent/AgentTypes.ts +23 -57
  127. package/src/types/config/AgentProject.ts +6 -5
  128. package/src/types/config/DowncityConfig.ts +8 -67
  129. package/src/types/config/LlmConfig.ts +1 -1
  130. package/src/types/config/Start.ts +3 -0
  131. package/src/types/runtime/host/Store.ts +7 -53
  132. package/src/types/runtime/platform/Platform.ts +6 -6
  133. package/src/types/runtime/platform/PlatformGateway.ts +2 -2
  134. package/src/utils/Time.ts +0 -6
  135. package/src/utils/storage/index.ts +0 -7
  136. package/tsconfig.tsbuildinfo +1 -1
  137. package/bin/config/ConfigEnvResolver.d.ts +0 -22
  138. package/bin/config/ConfigEnvResolver.d.ts.map +0 -1
  139. package/bin/config/ConfigEnvResolver.js +0 -41
  140. package/bin/config/ConfigEnvResolver.js.map +0 -1
  141. package/bin/runtime/server/rpc/Server.d.ts +0 -18
  142. package/bin/runtime/server/rpc/Server.d.ts.map +0 -1
  143. package/bin/runtime/server/rpc/Server.js +0 -315
  144. package/bin/runtime/server/rpc/Server.js.map +0 -1
  145. package/bin/runtime/transport/rpc/Client.d.ts +0 -13
  146. package/bin/runtime/transport/rpc/Client.d.ts.map +0 -1
  147. package/bin/runtime/transport/rpc/Client.js +0 -98
  148. package/bin/runtime/transport/rpc/Client.js.map +0 -1
  149. package/bin/runtime/transport/rpc/Paths.d.ts +0 -14
  150. package/bin/runtime/transport/rpc/Paths.d.ts.map +0 -1
  151. package/bin/runtime/transport/rpc/Paths.js +0 -42
  152. package/bin/runtime/transport/rpc/Paths.js.map +0 -1
  153. package/bin/runtime/transport/rpc/Transport.d.ts +0 -21
  154. package/bin/runtime/transport/rpc/Transport.d.ts.map +0 -1
  155. package/bin/runtime/transport/rpc/Transport.js +0 -30
  156. package/bin/runtime/transport/rpc/Transport.js.map +0 -1
  157. package/bin/types/common/ResolvedConfigValue.d.ts +0 -12
  158. package/bin/types/common/ResolvedConfigValue.d.ts.map +0 -1
  159. package/bin/types/common/ResolvedConfigValue.js +0 -2
  160. package/bin/types/common/ResolvedConfigValue.js.map +0 -1
  161. package/bin/types/runtime/rpc/LocalRpc.d.ts +0 -69
  162. package/bin/types/runtime/rpc/LocalRpc.d.ts.map +0 -1
  163. package/bin/types/runtime/rpc/LocalRpc.js +0 -9
  164. package/bin/types/runtime/rpc/LocalRpc.js.map +0 -1
  165. package/src/config/ConfigEnvResolver.ts +0 -52
  166. package/src/runtime/server/rpc/Server.ts +0 -408
  167. package/src/runtime/transport/rpc/Client.ts +0 -113
  168. package/src/runtime/transport/rpc/Paths.ts +0 -50
  169. package/src/runtime/transport/rpc/Transport.ts +0 -43
  170. package/src/types/common/ResolvedConfigValue.ts +0 -16
  171. package/src/types/runtime/rpc/LocalRpc.ts +0 -72
@@ -1,113 +0,0 @@
1
- /**
2
- * Local RPC 客户端。
3
- *
4
- * 关键点(中文)
5
- * - 只用于本机受信任 IPC,不附加 HTTP Bearer 鉴权。
6
- * - 返回结构与 HTTP `callServer()` 对齐,便于上层透明切换 transport。
7
- */
8
-
9
- import net from "node:net";
10
- import { nanoid } from "nanoid";
11
- import type {
12
- DaemonJsonApiCallParams,
13
- DaemonJsonApiCallResult,
14
- } from "@/runtime/host/daemon/Api.js";
15
- import type { LocalRpcRequest, LocalRpcResponse } from "@/types/runtime/rpc/LocalRpc.js";
16
- import { getLocalRpcEndpoint } from "./Paths.js";
17
-
18
- const LOCAL_RPC_TIMEOUT_MS = 5_000;
19
-
20
- function toLocalRpcRequest(params: DaemonJsonApiCallParams): LocalRpcRequest {
21
- return {
22
- requestId: nanoid(),
23
- path: String(params.path || "").trim(),
24
- method: params.method || "GET",
25
- ...(params.body !== undefined ? { body: params.body } : {}),
26
- };
27
- }
28
-
29
- /**
30
- * 通过本地 IPC 调用 agent runtime。
31
- */
32
- export async function callLocalServer<T>(
33
- params: DaemonJsonApiCallParams,
34
- ): Promise<DaemonJsonApiCallResult<T>> {
35
- const endpoint = getLocalRpcEndpoint(params.projectRoot);
36
- const request = toLocalRpcRequest(params);
37
- const timeoutMs =
38
- typeof params.timeoutMs === "number" &&
39
- Number.isFinite(params.timeoutMs) &&
40
- params.timeoutMs > 0
41
- ? Math.floor(params.timeoutMs)
42
- : LOCAL_RPC_TIMEOUT_MS;
43
-
44
- return await new Promise<DaemonJsonApiCallResult<T>>((resolve) => {
45
- const socket = net.createConnection(endpoint);
46
- let settled = false;
47
- let buffered = "";
48
-
49
- const finish = (result: DaemonJsonApiCallResult<T>): void => {
50
- if (settled) return;
51
- settled = true;
52
- socket.destroy();
53
- resolve(result);
54
- };
55
-
56
- socket.setEncoding("utf8");
57
- socket.setTimeout(timeoutMs);
58
-
59
- socket.on("connect", () => {
60
- socket.write(`${JSON.stringify(request)}\n`);
61
- });
62
-
63
- socket.on("data", (chunk) => {
64
- buffered += String(chunk || "");
65
- const newlineIndex = buffered.indexOf("\n");
66
- if (newlineIndex < 0) return;
67
- const raw = buffered.slice(0, newlineIndex).trim();
68
- if (!raw) {
69
- finish({
70
- success: false,
71
- error: `Local RPC returned empty payload from ${endpoint}`,
72
- });
73
- return;
74
- }
75
- try {
76
- const response = JSON.parse(raw) as LocalRpcResponse;
77
- finish({
78
- success: response.success,
79
- status: response.status,
80
- ...(response.data !== undefined ? { data: response.data as T } : {}),
81
- ...(response.error ? { error: response.error } : {}),
82
- });
83
- } catch (error) {
84
- finish({
85
- success: false,
86
- error: `Local RPC returned invalid JSON from ${endpoint}: ${String(error)}`,
87
- });
88
- }
89
- });
90
-
91
- socket.on("timeout", () => {
92
- finish({
93
- success: false,
94
- error: `Local RPC timed out after ${timeoutMs}ms (${endpoint})`,
95
- });
96
- });
97
-
98
- socket.on("error", (error) => {
99
- finish({
100
- success: false,
101
- error: `Local RPC unavailable at ${endpoint}: ${String(error)}`,
102
- });
103
- });
104
-
105
- socket.on("end", () => {
106
- if (settled) return;
107
- finish({
108
- success: false,
109
- error: `Local RPC closed without response (${endpoint})`,
110
- });
111
- });
112
- });
113
- }
@@ -1,50 +0,0 @@
1
- /**
2
- * Local RPC 路径工具。
3
- *
4
- * 关键点(中文)
5
- * - 本地受信任进程之间统一通过 IPC socket/pipe 通信。
6
- * - Unix 平台使用 city 全局 runtime 目录下的稳定 socket 文件,避免不同启动上下文
7
- * 的 `TMPDIR` 不一致,导致同一个 agent 被解析到两个不同 socket 路径。
8
- * - Windows 平台使用命名 pipe,并基于项目路径 hash 保证稳定唯一。
9
- */
10
-
11
- import crypto from "node:crypto";
12
- import path from "node:path";
13
- import { getPlatformRootDirPath } from "@/config/PlatformPaths.js";
14
-
15
- /**
16
- * 读取平台级运行目录。
17
- */
18
- function getPlatformRuntimeDirPath(): string {
19
- return path.join(getPlatformRootDirPath(), "main");
20
- }
21
-
22
- function buildProjectDigest(projectRoot: string): string {
23
- return crypto
24
- .createHash("sha1")
25
- .update(path.resolve(projectRoot))
26
- .digest("hex")
27
- .slice(0, 16);
28
- }
29
-
30
- function buildWindowsPipeName(projectRoot: string): string {
31
- const digest = buildProjectDigest(projectRoot);
32
- return `\\\\.\\pipe\\downcity-local-${digest}`;
33
- }
34
-
35
- function getLocalRpcUnixDirPath(): string {
36
- return path.join(getPlatformRuntimeDirPath(), "local-rpc");
37
- }
38
-
39
- /**
40
- * 返回本地 RPC endpoint。
41
- */
42
- export function getLocalRpcEndpoint(projectRoot: string): string {
43
- if (process.platform === "win32") {
44
- return buildWindowsPipeName(projectRoot);
45
- }
46
- return path.join(
47
- getLocalRpcUnixDirPath(),
48
- `downcity-local-${buildProjectDigest(projectRoot)}.sock`,
49
- );
50
- }
@@ -1,43 +0,0 @@
1
- /**
2
- * 本地/远程 transport 选择器。
3
- *
4
- * 关键点(中文)
5
- * - 本地受信任调用默认优先使用 IPC。
6
- * - 只有显式传入 `host/port` 时,才视为外部 HTTP 调用。
7
- * - 当前返回结构与 `callServer()` 保持一致,方便命令层复用。
8
- */
9
-
10
- import type {
11
- DaemonJsonApiCallParams,
12
- DaemonJsonApiCallResult,
13
- } from "@/runtime/host/daemon/Api.js";
14
- import { callServer } from "@/runtime/host/daemon/Client.js";
15
- import { callLocalServer } from "./Client.js";
16
-
17
- /**
18
- * 判断是否应强制使用 HTTP transport。
19
- */
20
- export function shouldUseHttpTransport(params: {
21
- host?: string;
22
- port?: number;
23
- }): boolean {
24
- return Boolean(
25
- (typeof params.host === "string" && params.host.trim()) ||
26
- typeof params.port === "number",
27
- );
28
- }
29
-
30
- /**
31
- * 统一调用 agent transport。
32
- */
33
- export async function callAgentTransport<T>(
34
- params: DaemonJsonApiCallParams,
35
- ): Promise<DaemonJsonApiCallResult<T>> {
36
- if (shouldUseHttpTransport({
37
- host: params.host,
38
- port: params.port,
39
- })) {
40
- return await callServer<T>(params);
41
- }
42
- return await callLocalServer<T>(params);
43
- }
@@ -1,16 +0,0 @@
1
- /**
2
- * 配置值递归结构类型。
3
- *
4
- * 职责说明(中文)
5
- * - 描述 `downcity.json` 在“读取原始 JSON -> 解析环境变量占位符”阶段可接受的值结构。
6
- * - 允许对象、数组、JSON 标量与 `undefined` 递归嵌套,供配置解析工具复用。
7
- * - 该类型只服务配置装配阶段,不承诺运行时最终配置的严格业务语义。
8
- */
9
- export type ResolvedConfigValue =
10
- | string
11
- | number
12
- | boolean
13
- | null
14
- | undefined
15
- | { [key: string]: ResolvedConfigValue }
16
- | ResolvedConfigValue[];
@@ -1,72 +0,0 @@
1
- /**
2
- * LocalRpc:本地 IPC 调用协议类型。
3
- *
4
- * 关键点(中文)
5
- * - 仅用于本机受信任进程之间的调用,不承担外部 HTTP 鉴权职责。
6
- * - 当前协议采用“一连接一请求一响应”的 JSON 行格式,便于调试与逐步演进。
7
- */
8
-
9
- import type { JsonValue } from "@/types/common/Json.js";
10
- import type { DaemonHttpMethod } from "@/runtime/host/daemon/Api.js";
11
-
12
- /**
13
- * 单次本地 RPC 请求。
14
- */
15
- export interface LocalRpcRequest {
16
- /**
17
- * 请求唯一标识。
18
- */
19
- requestId: string;
20
- /**
21
- * 目标 API 路径。
22
- */
23
- path: string;
24
- /**
25
- * 调用方法。
26
- */
27
- method: DaemonHttpMethod;
28
- /**
29
- * 可选结构化请求体。
30
- */
31
- body?: JsonValue;
32
- }
33
-
34
- /**
35
- * 单次本地 RPC 响应。
36
- */
37
- export interface LocalRpcResponse {
38
- /**
39
- * 对应请求标识。
40
- */
41
- requestId: string;
42
- /**
43
- * HTTP 风格状态码。
44
- */
45
- status: number;
46
- /**
47
- * 调用是否成功。
48
- */
49
- success: boolean;
50
- /**
51
- * 成功时的数据。
52
- */
53
- data?: JsonValue;
54
- /**
55
- * 失败时的错误信息。
56
- */
57
- error?: string;
58
- }
59
-
60
- /**
61
- * 本地 RPC server 句柄。
62
- */
63
- export interface LocalRpcServerHandle {
64
- /**
65
- * 当前绑定的 socket/pipe 地址。
66
- */
67
- endpoint: string;
68
- /**
69
- * 停止本地 RPC server。
70
- */
71
- stop(): Promise<void>;
72
- }