lark-remote 0.1.6 → 0.1.7

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 (188) hide show
  1. package/CHANGELOG.md +23 -1
  2. package/README.en.md +9 -1
  3. package/README.md +14 -2
  4. package/dist/bridge/approval-coordinator.d.ts +57 -34
  5. package/dist/bridge/approval-coordinator.js +191 -40
  6. package/dist/bridge/inbound-media.d.ts +62 -0
  7. package/dist/bridge/inbound-media.js +282 -0
  8. package/dist/bridge/index.d.ts +78 -7
  9. package/dist/bridge/index.js +202 -79
  10. package/dist/bridge/queue-manager.d.ts +2 -1
  11. package/dist/bridge/queue-manager.js +1 -0
  12. package/dist/card/approval-render.js +152 -36
  13. package/dist/card/bash-card-session.d.ts +2 -24
  14. package/dist/card/bash-card-session.js +6 -73
  15. package/dist/card/bash-renderer.js +2 -3
  16. package/dist/card/card-budget.js +29 -75
  17. package/dist/card/card-session.d.ts +48 -0
  18. package/dist/card/card-session.js +86 -0
  19. package/dist/card/card-shared.d.ts +1 -12
  20. package/dist/card/card-shared.js +1 -26
  21. package/dist/card/run-card-session.d.ts +2 -55
  22. package/dist/card/run-card-session.js +6 -104
  23. package/dist/card/run-renderer.js +99 -232
  24. package/dist/card/run-state.d.ts +13 -0
  25. package/dist/card/run-state.js +25 -16
  26. package/dist/card/text-truncate.d.ts +13 -12
  27. package/dist/card/text-truncate.js +13 -63
  28. package/dist/common/fs.d.ts +8 -0
  29. package/dist/common/fs.js +17 -0
  30. package/dist/common/guards.d.ts +0 -20
  31. package/dist/common/guards.js +0 -43
  32. package/dist/common/sleep.d.ts +2 -0
  33. package/dist/common/sleep.js +5 -0
  34. package/dist/common/truncate.d.ts +39 -0
  35. package/dist/common/truncate.js +92 -0
  36. package/dist/config/codex-config.d.ts +1 -1
  37. package/dist/config/codex-config.js +1 -1
  38. package/dist/config/index.d.ts +88 -23
  39. package/dist/config/index.js +105 -34
  40. package/dist/connector/index.d.ts +69 -2
  41. package/dist/connector/index.js +107 -1
  42. package/dist/index.js +123 -105
  43. package/dist/instance-lock.js +4 -12
  44. package/dist/order/alias-resolve.d.ts +13 -0
  45. package/dist/order/alias-resolve.js +22 -0
  46. package/dist/order/alias-store.d.ts +38 -0
  47. package/dist/order/alias-store.js +106 -0
  48. package/dist/persistence/atomic-write.d.ts +8 -2
  49. package/dist/persistence/atomic-write.js +23 -7
  50. package/dist/restart.js +2 -1
  51. package/dist/router/card-helpers.d.ts +63 -0
  52. package/dist/router/card-helpers.js +146 -0
  53. package/dist/router/config/claude.js +25 -1
  54. package/dist/router/config/codex.js +29 -50
  55. package/dist/router/config/common/model-patch.d.ts +22 -0
  56. package/dist/router/config/common/model-patch.js +26 -0
  57. package/dist/router/config/common/render.js +5 -4
  58. package/dist/router/config/index.d.ts +12 -0
  59. package/dist/router/config/index.js +25 -1
  60. package/dist/router/config/kimi.d.ts +4 -1
  61. package/dist/router/config/kimi.js +27 -0
  62. package/dist/router/config/opencode.js +18 -5
  63. package/dist/router/config/pi.js +4 -5
  64. package/dist/router/config/types.d.ts +11 -2
  65. package/dist/router/index.d.ts +56 -21
  66. package/dist/router/index.js +373 -548
  67. package/dist/router/utils.d.ts +2 -0
  68. package/dist/router/utils.js +4 -0
  69. package/dist/runner/agent-choices-common.d.ts +16 -0
  70. package/dist/runner/agent-choices-common.js +31 -0
  71. package/dist/runner/claude/runner.d.ts +47 -10
  72. package/dist/runner/claude/runner.js +117 -46
  73. package/dist/runner/claude/session.d.ts +166 -0
  74. package/dist/runner/claude/session.js +749 -0
  75. package/dist/runner/codex/app-server/protocol-types.d.ts +31 -39
  76. package/dist/runner/codex/app-server/protocol-types.js +1 -12
  77. package/dist/runner/codex/app-server/runner.d.ts +42 -59
  78. package/dist/runner/codex/app-server/runner.js +160 -337
  79. package/dist/runner/codex/app-server/translator.d.ts +1 -21
  80. package/dist/runner/codex/app-server/translator.js +0 -18
  81. package/dist/runner/codex/index.d.ts +0 -2
  82. package/dist/runner/codex/index.js +0 -2
  83. package/dist/runner/common/acp/protocol-helpers.d.ts +14 -0
  84. package/dist/runner/common/acp/protocol-helpers.js +21 -0
  85. package/dist/runner/common/acp/protocol-types.d.ts +238 -0
  86. package/dist/runner/common/acp/protocol-types.js +75 -0
  87. package/dist/runner/common/connection-based-runner.d.ts +111 -0
  88. package/dist/runner/common/connection-based-runner.js +261 -0
  89. package/dist/runner/{codex/app-server → common/jsonrpc}/client.d.ts +14 -7
  90. package/dist/runner/{codex/app-server → common/jsonrpc}/client.js +27 -18
  91. package/dist/runner/common/jsonrpc/connection-manager.d.ts +125 -0
  92. package/dist/runner/{codex/app-server → common/jsonrpc}/connection-manager.js +63 -28
  93. package/dist/runner/{codex/app-server → common/jsonrpc}/transport.d.ts +5 -4
  94. package/dist/runner/{codex/app-server → common/jsonrpc}/transport.js +18 -19
  95. package/dist/runner/common/jsonrpc/types.d.ts +32 -0
  96. package/dist/runner/common/jsonrpc/types.js +9 -0
  97. package/dist/runner/common/process-stopper.d.ts +2 -1
  98. package/dist/runner/common/process-stopper.js +1 -0
  99. package/dist/runner/common/runner-utils.d.ts +6 -13
  100. package/dist/runner/common/runner-utils.js +6 -47
  101. package/dist/runner/common/spawning-runner.d.ts +24 -70
  102. package/dist/runner/common/spawning-runner.js +98 -152
  103. package/dist/runner/index.d.ts +4 -4
  104. package/dist/runner/index.js +4 -4
  105. package/dist/runner/kimi/acp/runner.d.ts +106 -0
  106. package/dist/runner/kimi/acp/runner.js +448 -0
  107. package/dist/runner/kimi/acp/translator.d.ts +124 -0
  108. package/dist/runner/kimi/acp/translator.js +336 -0
  109. package/dist/runner/kimi/index.d.ts +1 -1
  110. package/dist/runner/kimi/index.js +1 -1
  111. package/dist/runner/opencode/acp/index.d.ts +1 -0
  112. package/dist/runner/opencode/acp/index.js +2 -0
  113. package/dist/runner/opencode/acp/runner.d.ts +121 -0
  114. package/dist/runner/opencode/acp/runner.js +429 -0
  115. package/dist/runner/opencode/acp/translator.d.ts +119 -0
  116. package/dist/runner/opencode/acp/translator.js +345 -0
  117. package/dist/runner/opencode/index.d.ts +1 -1
  118. package/dist/runner/opencode/index.js +1 -1
  119. package/dist/runner/pi/index.d.ts +1 -1
  120. package/dist/runner/pi/index.js +1 -1
  121. package/dist/runner/pi/rpc/client.d.ts +52 -0
  122. package/dist/runner/pi/rpc/client.js +114 -0
  123. package/dist/runner/pi/rpc/index.d.ts +4 -0
  124. package/dist/runner/pi/rpc/index.js +4 -0
  125. package/dist/runner/pi/rpc/protocol-types.d.ts +127 -0
  126. package/dist/runner/pi/rpc/protocol-types.js +21 -0
  127. package/dist/runner/pi/rpc/runner.d.ts +80 -0
  128. package/dist/runner/pi/rpc/runner.js +199 -0
  129. package/dist/runner/pi/rpc/translator.d.ts +55 -0
  130. package/dist/runner/pi/rpc/translator.js +258 -0
  131. package/dist/runner/registry.d.ts +7 -8
  132. package/dist/runner/registry.js +3 -4
  133. package/dist/runner/resolve-agent-choices.js +18 -59
  134. package/dist/runner/sync-agent-choices.js +16 -67
  135. package/dist/runner/types.d.ts +43 -13
  136. package/dist/session/claude/session-index.js +2 -3
  137. package/dist/session/claude/session-reader.js +3 -6
  138. package/dist/session/claude/sessions.js +6 -13
  139. package/dist/session/codex/rollout-reader.d.ts +2 -2
  140. package/dist/session/codex/rollout-reader.js +14 -17
  141. package/dist/session/codex/sessions.d.ts +1 -1
  142. package/dist/session/codex/sessions.js +2 -2
  143. package/dist/session/common/content-blocks.d.ts +7 -0
  144. package/dist/session/common/content-blocks.js +13 -9
  145. package/dist/session/common/jsonl.d.ts +8 -25
  146. package/dist/session/common/jsonl.js +126 -261
  147. package/dist/session/common/pagination.d.ts +28 -0
  148. package/dist/session/common/pagination.js +33 -0
  149. package/dist/session/kimi/sessions.d.ts +34 -1
  150. package/dist/session/kimi/sessions.js +208 -98
  151. package/dist/session/opencode/sessions.d.ts +17 -3
  152. package/dist/session/opencode/sessions.js +29 -29
  153. package/dist/session/pi/sessions.d.ts +5 -1
  154. package/dist/session/pi/sessions.js +12 -16
  155. package/dist/session/session-store.d.ts +11 -1
  156. package/dist/session/session-store.js +75 -178
  157. package/dist/update/index.d.ts +2 -2
  158. package/dist/update/index.js +2 -2
  159. package/dist/update/install.d.ts +20 -2
  160. package/dist/update/install.js +51 -7
  161. package/package.json +1 -1
  162. package/dist/runner/codex/app-server/connection-manager.d.ts +0 -56
  163. package/dist/runner/codex/argv.d.ts +0 -33
  164. package/dist/runner/codex/argv.js +0 -40
  165. package/dist/runner/codex/factory.d.ts +0 -29
  166. package/dist/runner/codex/factory.js +0 -39
  167. package/dist/runner/codex/jsonl.d.ts +0 -37
  168. package/dist/runner/codex/jsonl.js +0 -221
  169. package/dist/runner/codex/runner.d.ts +0 -66
  170. package/dist/runner/codex/runner.js +0 -129
  171. package/dist/runner/common/exec-translator.d.ts +0 -73
  172. package/dist/runner/common/exec-translator.js +0 -105
  173. package/dist/runner/kimi/jsonl.d.ts +0 -28
  174. package/dist/runner/kimi/jsonl.js +0 -143
  175. package/dist/runner/kimi/runner.d.ts +0 -49
  176. package/dist/runner/kimi/runner.js +0 -105
  177. package/dist/runner/opencode/argv.d.ts +0 -32
  178. package/dist/runner/opencode/argv.js +0 -35
  179. package/dist/runner/opencode/jsonl.d.ts +0 -68
  180. package/dist/runner/opencode/jsonl.js +0 -295
  181. package/dist/runner/opencode/runner.d.ts +0 -61
  182. package/dist/runner/opencode/runner.js +0 -93
  183. package/dist/runner/pi/jsonl.d.ts +0 -128
  184. package/dist/runner/pi/jsonl.js +0 -249
  185. package/dist/runner/pi/runner.d.ts +0 -36
  186. package/dist/runner/pi/runner.js +0 -76
  187. package/dist/session/common/catch-up.d.ts +0 -12
  188. package/dist/session/common/catch-up.js +0 -31
@@ -7,51 +7,20 @@
7
7
  * (`item/agentMessage/delta`) and snake_case only where the server requires it
8
8
  * (e.g. permission profile fields).
9
9
  */
10
- export interface JsonRpcRequest {
11
- jsonrpc: '2.0';
12
- id: number | string;
13
- method: string;
14
- params?: unknown;
15
- }
16
- export interface JsonRpcNotification {
17
- jsonrpc: '2.0';
18
- method: string;
19
- params?: unknown;
20
- }
21
- export interface JsonRpcSuccessResponse {
22
- jsonrpc: '2.0';
23
- id: number | string;
24
- result: unknown;
25
- }
26
- export interface JsonRpcErrorResponse {
27
- jsonrpc: '2.0';
28
- id: number | string | null;
29
- error: {
30
- code: number;
31
- message: string;
32
- data?: unknown;
33
- };
34
- }
35
- export type ServerMessage = JsonRpcRequest | JsonRpcNotification | JsonRpcSuccessResponse | JsonRpcErrorResponse;
36
- /** Standard JSON-RPC error codes. */
37
- export declare const RpcErrorCode: {
38
- readonly PARSE_ERROR: -32700;
39
- readonly INVALID_REQUEST: -32600;
40
- readonly METHOD_NOT_FOUND: -32601;
41
- readonly INVALID_PARAMS: -32602;
42
- readonly INTERNAL_ERROR: -32603;
43
- /** Timeout error (custom, not standard JSON-RPC). */
44
- readonly TIMEOUT_ERROR: -32000;
45
- /** Connection lost / transport error (custom). */
46
- readonly CONNECTION_LOST: -32001;
47
- };
10
+ export type { JsonRpcRequest, JsonRpcNotification, JsonRpcSuccessResponse, JsonRpcErrorResponse, } from '../../common/jsonrpc/types.js';
48
11
  export interface ClientInfo {
49
12
  name: string;
50
13
  version: string;
51
14
  }
15
+ export interface InitializeCapabilities {
16
+ experimentalApi?: boolean;
17
+ requestAttestation?: boolean;
18
+ optOutNotificationMethods?: string[];
19
+ mcpServerOpenaiFormElicitation?: boolean;
20
+ }
52
21
  export interface InitializeParams {
53
22
  clientInfo: ClientInfo;
54
- capabilities?: Record<string, unknown>;
23
+ capabilities?: InitializeCapabilities;
55
24
  }
56
25
  export interface InitializeResult {
57
26
  serverInfo?: {
@@ -121,6 +90,28 @@ export interface ThreadResumeResponse {
121
90
  model: string;
122
91
  modelProvider: string;
123
92
  }
93
+ /** `thread/settings/update` params (real v2 protocol). */
94
+ export interface ThreadSettingsUpdateParams {
95
+ threadId: string;
96
+ /** Override the approval policy for subsequent turns. */
97
+ approvalPolicy?: AskForApproval;
98
+ /** Override the sandbox policy for subsequent turns. */
99
+ sandboxPolicy?: SandboxPolicy;
100
+ /** Override the model for subsequent turns. */
101
+ model?: string | null;
102
+ /** Override the model provider for subsequent turns. */
103
+ modelProvider?: string | null;
104
+ }
105
+ export interface ThreadSettingsUpdateResponse {
106
+ }
107
+ /** Server→client notification after a settings update is applied. */
108
+ export interface ThreadSettingsUpdatedNotification {
109
+ method: 'thread/settings/updated';
110
+ params: {
111
+ threadId: string;
112
+ threadSettings: unknown;
113
+ };
114
+ }
124
115
  export interface ThreadCompactStartParams {
125
116
  threadId: string;
126
117
  }
@@ -268,6 +259,7 @@ export declare const NotificationMethod: {
268
259
  readonly WARNING: "warning";
269
260
  readonly THREAD_STARTED: "thread/started";
270
261
  readonly THREAD_STATUS_CHANGED: "thread/status/changed";
262
+ readonly THREAD_SETTINGS_UPDATED: "thread/settings/updated";
271
263
  readonly THREAD_COMPACTED: "thread/compacted";
272
264
  readonly MODEL_REROUTED: "model/rerouted";
273
265
  };
@@ -7,18 +7,6 @@
7
7
  * (`item/agentMessage/delta`) and snake_case only where the server requires it
8
8
  * (e.g. permission profile fields).
9
9
  */
10
- /** Standard JSON-RPC error codes. */
11
- export const RpcErrorCode = {
12
- PARSE_ERROR: -32700,
13
- INVALID_REQUEST: -32600,
14
- METHOD_NOT_FOUND: -32601,
15
- INVALID_PARAMS: -32602,
16
- INTERNAL_ERROR: -32603,
17
- /** Timeout error (custom, not standard JSON-RPC). */
18
- TIMEOUT_ERROR: -32000,
19
- /** Connection lost / transport error (custom). */
20
- CONNECTION_LOST: -32001,
21
- };
22
10
  // =============================================================================
23
11
  // Notifications (server → client)
24
12
  // =============================================================================
@@ -42,6 +30,7 @@ export const NotificationMethod = {
42
30
  WARNING: 'warning',
43
31
  THREAD_STARTED: 'thread/started',
44
32
  THREAD_STATUS_CHANGED: 'thread/status/changed',
33
+ THREAD_SETTINGS_UPDATED: 'thread/settings/updated',
45
34
  THREAD_COMPACTED: 'thread/compacted',
46
35
  MODEL_REROUTED: 'model/rerouted',
47
36
  };
@@ -5,9 +5,16 @@
5
5
  * Flow per run: acquire persistent connection → thread/start or thread/resume
6
6
  * → turn/start → consume notifications (agent message deltas, approval server
7
7
  * requests, …) until turn/completed → synthesize ResultEvent.
8
+ *
9
+ * Shares the ConnectionBasedRunner base with kimi/opencode: same notification
10
+ * queue + waitResolve pump, forceFinish/stopRequested semantics, turn idle
11
+ * watchdog, and ConnectionLostError respawn-and-retry-once.
8
12
  */
9
- import type { AgentKind, AgentSessionReader, AgentEvent, AgentRunner, AgentStatusInfo, SpawnOptions } from '../../types.js';
10
- import { type AskForApproval, type SandboxMode } from './protocol-types.js';
13
+ import type { AgentKind, AgentSessionReader, AgentEvent, AgentStatusInfo, SpawnOptions } from '../../types.js';
14
+ import { JsonRpcClient } from '../../common/jsonrpc/client.js';
15
+ import { type TranslatorEvent } from './translator.js';
16
+ import { type AskForApproval, type SandboxMode, type SandboxPolicy, type InitializeResult } from './protocol-types.js';
17
+ import { ConnectionBasedRunner } from '../../common/connection-based-runner.js';
11
18
  export interface CodexAppServerRunnerOptions {
12
19
  kind: AgentKind;
13
20
  sessionReader: AgentSessionReader;
@@ -31,90 +38,66 @@ export interface CodexAppServerRunnerOptions {
31
38
  /** Configured approval policy (Codex 官方 AskForApproval 标准值). */
32
39
  approvalPolicy?: AskForApproval;
33
40
  }
34
- export declare class CodexAppServerRunner implements AgentRunner {
35
- readonly kind: AgentKind;
36
- readonly sessionReader: AgentSessionReader;
37
- readonly lifetime: "workspace";
41
+ /**
42
+ * Map the client-side SandboxMode enum to the response-side SandboxPolicy
43
+ * object used by `thread/settings/update` (`sandboxPolicy`).
44
+ */
45
+ export declare function sandboxModeToSandboxPolicy(mode: SandboxMode): SandboxPolicy;
46
+ export declare class CodexAppServerRunner extends ConnectionBasedRunner<JsonRpcClient<InitializeResult>, TranslatorEvent> {
38
47
  private connectionManager;
39
- private currentClient;
40
48
  private currentTranslator;
41
- private currentThreadId;
42
- private currentTurnId;
43
- private lastEventAt;
44
- private _isRunning;
49
+ private activeThreadId;
45
50
  private model?;
46
51
  private modelProvider?;
47
52
  private reasoningEffort?;
48
53
  private sandboxConfig?;
49
54
  private approvalPolicyConfig?;
50
- private readonly turnTimeoutMs;
51
55
  /** Pending approval requests: requestId (JSON-RPC id) → kind + view. */
52
56
  private pendingApprovals;
53
- /** Notification queue consumed by the active run generator. */
54
- private notificationQueue;
55
- private waitResolve;
56
- private forceFinish;
57
- /** stop() 在 turn/start 响应前到达时置位,turn/start 完成后补发 interrupt。 */
58
- private stopRequested;
59
57
  constructor(opts: CodexAppServerRunnerOptions);
60
- get isRunning(): boolean;
61
- /**
62
- * Run a message in the current thread.
63
- *
64
- * 进程容错:若 app-server 子进程被外部误杀或自身异常退出(连接丢失),
65
- * 自动重拉进程并重试一次 setup(thread/start 或按 sessionId thread/resume
66
- * 继续处理),保证消费用户消息时进程挂了也能恢复。
67
- */
68
- run(message: string, opts: SpawnOptions): AsyncGenerator<AgentEvent>;
69
- /**
70
- * Acquire the connection and set up the turn: thread/start(新会话)或
71
- * thread/resume(按 sessionId 恢复既有线程)→ turn/start。
72
- */
73
- private setupTurn;
58
+ protected get logTag(): string;
59
+ protected get turnTimeoutErrorMessage(): string;
60
+ protected get turnInterruptedErrorMessage(): string;
61
+ protected currentSessionId(): string | null;
62
+ protected shouldDeferStop(): boolean;
63
+ protected cancelCurrentTurn(): Promise<void>;
64
+ protected clearTurnState(): void;
65
+ protected releaseConnection(cwd: string): Promise<void>;
66
+ protected notifyIdle(cwd: string): void;
67
+ protected disposeConnections(): Promise<void>;
74
68
  /**
75
69
  * Run a compact operation on the current thread.
76
70
  */
77
71
  runCompact(_message: string, opts: SpawnOptions): AsyncGenerator<AgentEvent>;
78
- /**
79
- * Stop the current turn by interrupting it.
80
- */
81
- stop(_opts?: {
82
- immediate?: boolean;
83
- }): Promise<void>;
84
72
  /**
85
73
  * Respond to an approval server request. `response` is the bridge
86
74
  * ApprovalAction (`{ action: 'accept' | 'accept_for_session' | 'decline' | 'cancel' }`).
87
75
  */
88
76
  respondApproval(requestId: number | string, response: unknown): Promise<void>;
77
+ getStatusInfo(): AgentStatusInfo;
89
78
  /**
90
- * Dispose the runner: release the connection.
79
+ * Unified approval-mode hot-update entry (called by the bridge via duck
80
+ * typing on active runs). Codex's `thread/settings/update` applies the new
81
+ * approval/sandbox policy to subsequent turns, even while the current turn
82
+ * is still active. This lets `/config` take effect without waiting for this
83
+ * workspace-lifetime runner to be recreated/evicted. Local fields are always
84
+ * updated so `/status` reflects the new config immediately; if there is no
85
+ * live thread, the next `thread/start`/`thread/resume` uses the new values
86
+ * anyway.
91
87
  */
92
- dispose(): Promise<void>;
93
- getUsageAuthority(): 'live';
94
- killOrphan(): void;
95
- registerExitHandlers(): void;
96
- unregisterExitHandlers(): void;
97
- getStatusInfo(): AgentStatusInfo;
88
+ updateApprovalMode(settings: {
89
+ approvalPolicy?: AskForApproval;
90
+ sandbox?: SandboxMode;
91
+ }): Promise<void>;
98
92
  private buildThreadParams;
99
93
  private buildTurnParams;
100
94
  /**
101
- * Consume the notification queue until a result event arrives or the turn
102
- * times out / is interrupted.
103
- */
104
- private consumeTurn;
105
- /**
106
- * Compute the current idle deadline. 0 disables the idle timeout; otherwise
107
- * the deadline is based on the last received event, not the turn start time.
95
+ * Acquire the connection and set up the turn: thread/start(新会话)或
96
+ * thread/resume(按 sessionId 恢复既有线程)→ turn/start。
108
97
  */
109
- private nextTurnIdleDeadline;
110
- private interruptCurrentTurn;
111
- private waitForEvents;
98
+ protected setupTurn(message: string, opts: SpawnOptions): Promise<void>;
112
99
  private handleNotification;
113
100
  private handleServerRequest;
114
- private pushEvents;
115
- private wakeWaiters;
116
- private failTurn;
117
- private resetRunState;
118
101
  private buildGrantedPermissions;
119
102
  /** 拒绝权限审批:空 fileSystem + 关闭网络(真实 GrantedPermissionProfile)。 */
120
103
  private denyAllPermissions;