lark-remote 0.5.19 → 0.5.21

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 (136) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/bridge/approval-actions.d.ts +1 -1
  3. package/dist/bridge/approval-actions.js +1 -1
  4. package/dist/bridge/bash-run.d.ts +71 -0
  5. package/dist/bridge/bash-run.js +217 -0
  6. package/dist/bridge/compact.d.ts +155 -0
  7. package/dist/bridge/compact.js +450 -0
  8. package/dist/bridge/final-usage.js +4 -4
  9. package/dist/bridge/inbound-media.js +72 -46
  10. package/dist/bridge/index.d.ts +106 -153
  11. package/dist/bridge/index.js +400 -1000
  12. package/dist/bridge/job-watch.d.ts +68 -0
  13. package/dist/bridge/job-watch.js +146 -0
  14. package/dist/bridge/queue-manager.d.ts +3 -3
  15. package/dist/bridge/queue-manager.js +10 -29
  16. package/dist/card/approval-render.d.ts +2 -2
  17. package/dist/card/approval-render.js +141 -130
  18. package/dist/card/card-budget.js +123 -98
  19. package/dist/card/card-helpers.d.ts +3 -3
  20. package/dist/card/card-helpers.js +6 -6
  21. package/dist/card/final-answer-file.js +1 -1
  22. package/dist/card/run-renderer.d.ts +3 -3
  23. package/dist/card/run-renderer.js +114 -159
  24. package/dist/card/run-state.d.ts +1 -15
  25. package/dist/card/run-state.js +358 -292
  26. package/dist/card/tool-render.d.ts +1 -1
  27. package/dist/card/tool-render.js +21 -17
  28. package/dist/card/usage-format.d.ts +22 -7
  29. package/dist/card/usage-format.js +119 -100
  30. package/dist/cli.js +15 -3
  31. package/dist/clone.js +2 -2
  32. package/dist/common/text-width.js +36 -24
  33. package/dist/common/tool-summary.js +132 -90
  34. package/dist/config/codex-config.js +130 -106
  35. package/dist/config/index.d.ts +16 -2
  36. package/dist/config/index.js +23 -8
  37. package/dist/connector/index.js +6 -6
  38. package/dist/error-classification.js +3 -2
  39. package/dist/inbound/placeholder.d.ts +1 -1
  40. package/dist/inbound/placeholder.js +1 -1
  41. package/dist/index.js +387 -281
  42. package/dist/logger/index.js +6 -6
  43. package/dist/message-handlers.d.ts +0 -5
  44. package/dist/message-handlers.js +254 -237
  45. package/dist/model-catalog.d.ts +2 -2
  46. package/dist/model-catalog.js +3 -8
  47. package/dist/platform/identity.js +1 -1
  48. package/dist/platform/path.d.ts +1 -1
  49. package/dist/platform/path.js +1 -1
  50. package/dist/platform/sleep-blocker.js +1 -1
  51. package/dist/platform/terminator-win32.js +2 -1
  52. package/dist/router/commands/ls.d.ts +3 -0
  53. package/dist/router/commands/ls.js +256 -175
  54. package/dist/router/commands/order.js +184 -159
  55. package/dist/router/commands/resume.js +190 -152
  56. package/dist/router/commands/ws.js +219 -174
  57. package/dist/router/config/dsh.d.ts +4 -8
  58. package/dist/router/config/dsh.js +3 -10
  59. package/dist/router/config/kimi.js +1 -1
  60. package/dist/router/config/types.d.ts +1 -1
  61. package/dist/router/config-diff.js +1 -1
  62. package/dist/router/index.d.ts +56 -11
  63. package/dist/router/index.js +401 -391
  64. package/dist/runner/bash/runner.js +2 -4
  65. package/dist/runner/claude/session.d.ts +1 -1
  66. package/dist/runner/claude/session.js +6 -4
  67. package/dist/runner/codex/app-server/runner.d.ts +9 -2
  68. package/dist/runner/codex/app-server/runner.js +30 -25
  69. package/dist/runner/codex/app-server/translator.d.ts +2 -5
  70. package/dist/runner/codex/app-server/translator.js +291 -238
  71. package/dist/runner/common/acp/acp-approval.d.ts +1 -1
  72. package/dist/runner/common/acp/acp-approval.js +1 -1
  73. package/dist/runner/common/acp/base-acp-runner.d.ts +5 -2
  74. package/dist/runner/common/acp/base-acp-runner.js +26 -65
  75. package/dist/runner/common/acp/base-translator.d.ts +12 -2
  76. package/dist/runner/common/acp/base-translator.js +50 -26
  77. package/dist/runner/common/acp/protocol-types.d.ts +1 -1
  78. package/dist/runner/common/acp/protocol-types.js +2 -2
  79. package/dist/runner/common/connection-based-runner.d.ts +32 -1
  80. package/dist/runner/common/connection-based-runner.js +32 -2
  81. package/dist/runner/common/jsonl-stream.js +154 -187
  82. package/dist/runner/common/jsonrpc/client.d.ts +29 -0
  83. package/dist/runner/common/jsonrpc/client.js +43 -12
  84. package/dist/runner/common/jsonrpc/connection-manager.d.ts +2 -2
  85. package/dist/runner/common/jsonrpc/connection-manager.js +4 -4
  86. package/dist/runner/common/spawning-runner.d.ts +6 -1
  87. package/dist/runner/common/spawning-runner.js +9 -4
  88. package/dist/runner/common/turn-started.d.ts +8 -0
  89. package/dist/runner/common/turn-started.js +11 -0
  90. package/dist/runner/dsh/approval.js +84 -51
  91. package/dist/runner/dsh/catalog-probe.d.ts +17 -0
  92. package/dist/runner/dsh/catalog-probe.js +10 -0
  93. package/dist/runner/dsh/client.d.ts +7 -11
  94. package/dist/runner/dsh/client.js +356 -289
  95. package/dist/runner/dsh/exit-cancel.d.ts +2 -2
  96. package/dist/runner/dsh/exit-cancel.js +2 -2
  97. package/dist/runner/dsh/inflight.d.ts +1 -1
  98. package/dist/runner/dsh/inflight.js +1 -1
  99. package/dist/runner/dsh/mux-stream.js +28 -8
  100. package/dist/runner/dsh/runner.d.ts +44 -4
  101. package/dist/runner/dsh/runner.js +296 -199
  102. package/dist/runner/dsh/translator.d.ts +1 -31
  103. package/dist/runner/dsh/translator.js +180 -178
  104. package/dist/runner/index.d.ts +1 -1
  105. package/dist/runner/kimi/acp/runner.d.ts +1 -2
  106. package/dist/runner/kimi/acp/runner.js +82 -46
  107. package/dist/runner/kimi/acp/translator.d.ts +1 -1
  108. package/dist/runner/kimi/acp/translator.js +3 -4
  109. package/dist/runner/opencode/acp/error-monitor.js +5 -5
  110. package/dist/runner/opencode/acp/runner.d.ts +2 -2
  111. package/dist/runner/opencode/acp/runner.js +4 -4
  112. package/dist/runner/pi/rpc/client.js +4 -13
  113. package/dist/runner/pi/rpc/protocol-types.d.ts +1 -1
  114. package/dist/runner/pi/rpc/protocol-types.js +1 -1
  115. package/dist/runner/pi/rpc/runner.d.ts +3 -0
  116. package/dist/runner/pi/rpc/runner.js +27 -42
  117. package/dist/runner/pi/rpc/translator.js +61 -60
  118. package/dist/runner/types.d.ts +2 -2
  119. package/dist/runner/types.js +1 -1
  120. package/dist/session/claude/sessions.d.ts +45 -0
  121. package/dist/session/claude/sessions.js +160 -122
  122. package/dist/session/codex/rollout-reader.js +181 -182
  123. package/dist/session/common/throw-session-list-error.d.ts +10 -0
  124. package/dist/session/common/throw-session-list-error.js +16 -0
  125. package/dist/session/dsh/sessions.js +291 -235
  126. package/dist/session/kimi/sessions.d.ts +40 -8
  127. package/dist/session/kimi/sessions.js +373 -301
  128. package/dist/session/opencode/sessions.d.ts +142 -1
  129. package/dist/session/opencode/sessions.js +378 -321
  130. package/dist/session/pi/sessions.js +4 -5
  131. package/dist/session/session-store.d.ts +9 -1
  132. package/dist/session/session-store.js +99 -99
  133. package/dist/update/version-check.js +2 -1
  134. package/dist/workspace/index.d.ts +1 -1
  135. package/dist/workspace/index.js +1 -1
  136. package/package.json +1 -1
@@ -9,6 +9,70 @@
9
9
  * first.
10
10
  */
11
11
  import { getLogger } from '../../logger/index.js';
12
+ // --- 模块级命名函数:把状态显式传入,避免在方法内定义带决策点的闭包 ---
13
+ // crapper 会把方法内部闭包的决策点计入外层方法;抽到模块顶层后
14
+ // onWaterfall / waitForBinding 只剩选路。
15
+ /** 重连重投:刷新已绑定 waterfall 的应答通道,不产新 binding。 */
16
+ function refreshRedeliveredWaterfall(bindings, waterfallByCallId, approvalId, waterfall) {
17
+ const binding = bindings.get(approvalId);
18
+ if (!binding)
19
+ return;
20
+ binding.waterfall.clientId = waterfall.clientId;
21
+ if (waterfall.reason)
22
+ binding.waterfall.reason = waterfall.reason;
23
+ if (waterfall.callId)
24
+ waterfallByCallId.set(waterfall.callId, binding.waterfall);
25
+ }
26
+ /** 第一段:按 callId 精确匹配未绑定 audit。 */
27
+ function auditWithCallId(audits, bindings, callId) {
28
+ for (const audit of audits) {
29
+ if (audit.callId === callId && !bindings.has(audit.approvalId))
30
+ return audit;
31
+ }
32
+ return undefined;
33
+ }
34
+ /** 第二段:无 callId 的 audit,按 toolName 兜底配对。 */
35
+ function unboundAuditWithoutCallId(audits, bindings, toolName) {
36
+ for (const audit of audits) {
37
+ if (!audit.callId && !bindings.has(audit.approvalId) && audit.toolName === toolName) {
38
+ return audit;
39
+ }
40
+ }
41
+ return undefined;
42
+ }
43
+ /** 第三段:waterfall 无 callId 时,按 toolName 找最老未绑定 audit。 */
44
+ function unboundAuditByToolName(audits, bindings, toolName) {
45
+ for (const audit of audits) {
46
+ if (!bindings.has(audit.approvalId) && audit.toolName === toolName)
47
+ return audit;
48
+ }
49
+ return undefined;
50
+ }
51
+ /** 按 waterfall 是否有 callId 选路,顺序与原实现三段 for 循环一致。 */
52
+ function findPairableAudit(audits, bindings, waterfall) {
53
+ if (waterfall.callId) {
54
+ return (auditWithCallId(audits.values(), bindings, waterfall.callId) ??
55
+ unboundAuditWithoutCallId(audits.values(), bindings, waterfall.toolName));
56
+ }
57
+ return unboundAuditByToolName(audits.values(), bindings, waterfall.toolName);
58
+ }
59
+ /** 结束一次等待(幂等):清 timer、摘监听、从 waiters 移除、resolve。 */
60
+ function finishBindingWait(state, binding) {
61
+ if (state.settled)
62
+ return;
63
+ state.settled = true;
64
+ if (state.timer !== undefined)
65
+ clearTimeout(state.timer);
66
+ state.signal?.removeEventListener('abort', state.onAbort);
67
+ const set = state.waiters.get(state.approvalId);
68
+ set?.delete(state.finish);
69
+ if (set && set.size === 0)
70
+ state.waiters.delete(state.approvalId);
71
+ state.resolve(binding);
72
+ }
73
+ function abortBindingWait(state) {
74
+ finishBindingWait(state, undefined);
75
+ }
12
76
  export class DshApprovalTracker {
13
77
  audits = new Map();
14
78
  waterfallByCallId = new Map();
@@ -43,45 +107,15 @@ export class DshApprovalTracker {
43
107
  if (existingApprovalId) {
44
108
  // A reconnect re-delivers the same pending event with a new Client
45
109
  // identity. Keep the card binding but refresh the answer channel.
46
- const binding = this.bindings.get(existingApprovalId);
47
- if (binding) {
48
- binding.waterfall.clientId = waterfall.clientId;
49
- if (waterfall.reason)
50
- binding.waterfall.reason = waterfall.reason;
51
- if (waterfall.callId) {
52
- this.waterfallByCallId.set(waterfall.callId, binding.waterfall);
53
- }
54
- }
110
+ refreshRedeliveredWaterfall(this.bindings, this.waterfallByCallId, existingApprovalId, waterfall);
55
111
  return undefined;
56
112
  }
57
113
  if (waterfall.callId)
58
114
  this.waterfallByCallId.set(waterfall.callId, waterfall);
59
- if (waterfall.callId) {
60
- for (const audit of this.audits.values()) {
61
- if (audit.callId === waterfall.callId && !this.bindings.has(audit.approvalId)) {
62
- return this.bind(audit, waterfall);
63
- }
64
- }
65
- // Some approval types omit callId on the durable audit. Pair with the
66
- // oldest unbound audit for the same tool before falling back to Web UI.
67
- for (const audit of this.audits.values()) {
68
- if (!audit.callId &&
69
- !this.bindings.has(audit.approvalId) &&
70
- audit.toolName === waterfall.toolName) {
71
- return this.bind(audit, waterfall);
72
- }
73
- }
74
- }
75
- // A missing callId is unusual but not fatal: pair with the oldest unbound
76
- // audit for the same tool, preserving the audit id on the card.
77
- if (!waterfall.callId) {
78
- for (const audit of this.audits.values()) {
79
- if (!this.bindings.has(audit.approvalId) && audit.toolName === waterfall.toolName) {
80
- return this.bind(audit, waterfall);
81
- }
82
- }
83
- }
84
- return undefined;
115
+ // Some approval types omit callId on the durable audit: pair with the
116
+ // oldest unbound audit for the same tool before falling back to Web UI.
117
+ const audit = findPairableAudit(this.audits, this.bindings, waterfall);
118
+ return audit ? this.bind(audit, waterfall) : undefined;
85
119
  }
86
120
  /** Mark an audit resolved (local response or an external decision). */
87
121
  onDecided(approvalId) {
@@ -125,24 +159,23 @@ export class DshApprovalTracker {
125
159
  if (signal?.aborted)
126
160
  return undefined;
127
161
  return new Promise((resolve) => {
128
- let settled = false;
129
- const finish = (binding) => {
130
- if (settled)
131
- return;
132
- settled = true;
133
- clearTimeout(timer);
134
- signal?.removeEventListener('abort', onAbort);
135
- const set = this.waiters.get(approvalId);
136
- set?.delete(finish);
137
- if (set && set.size === 0)
138
- this.waiters.delete(approvalId);
139
- resolve(binding);
162
+ // 状态显式打包;finish/onAbort 用模块级函数 + bind 绑定状态,
163
+ // 不在方法内定义带决策点的闭包。
164
+ const state = {
165
+ settled: false,
166
+ onAbort: () => { },
167
+ approvalId,
168
+ waiters: this.waiters,
169
+ resolve,
170
+ signal,
171
+ finish: () => { },
140
172
  };
141
- const onAbort = () => finish(undefined);
142
- const timer = setTimeout(() => finish(undefined), timeoutMs);
143
- signal?.addEventListener('abort', onAbort, { once: true });
173
+ state.finish = finishBindingWait.bind(null, state);
174
+ state.onAbort = abortBindingWait.bind(null, state);
175
+ state.timer = setTimeout(abortBindingWait.bind(null, state), timeoutMs);
176
+ signal?.addEventListener('abort', state.onAbort, { once: true });
144
177
  const set = this.waiters.get(approvalId) ?? new Set();
145
- set.add(finish);
178
+ set.add(state.finish);
146
179
  this.waiters.set(approvalId, set);
147
180
  });
148
181
  }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * DSH 服务端目录探测(/config 卡片动态清单用)。
3
+ *
4
+ * 接口只声明卡片预取需要的三个 RPC 方法;具体传输客户端的构造(含 token
5
+ * 解析路径)收在本模块——router 只依赖接口,不持有 DshClient。
6
+ */
7
+ import type { DshModelCatalogValue, DshPermissionCatalogValue, DshPresetListValue } from '../../dsh/types.js';
8
+ /** 卡片预取只依赖的 client 方法子集。 */
9
+ export interface DshCatalogClient {
10
+ listModels(): Promise<DshModelCatalogValue>;
11
+ listPresets(): Promise<DshPresetListValue>;
12
+ listPermissionPresets(): Promise<DshPermissionCatalogValue>;
13
+ }
14
+ /** 目录预取客户端工厂类型(测试注入 fake 用)。 */
15
+ export type DshCatalogClientFactory = (baseUrl: string, token?: string, credentialsFile?: string) => DshCatalogClient;
16
+ /** 生产实现:卡片预取是交互路径,DSH 卡死时最多等 5 秒后回退固定清单。 */
17
+ export declare function createDshCatalogClient(baseUrl: string, token?: string, credentialsFile?: string): DshCatalogClient;
@@ -0,0 +1,10 @@
1
+ import { DshClient } from './client.js';
2
+ /** 生产实现:卡片预取是交互路径,DSH 卡死时最多等 5 秒后回退固定清单。 */
3
+ export function createDshCatalogClient(baseUrl, token, credentialsFile) {
4
+ return new DshClient(baseUrl, {
5
+ token,
6
+ credentialsFile,
7
+ requestTimeoutMs: 5_000,
8
+ });
9
+ }
10
+ //# sourceMappingURL=catalog-probe.js.map
@@ -19,7 +19,7 @@
19
19
  * `sessionEvents()` adds per-session filtering, reconnect + follow-snapshot
20
20
  * replay, and seq-based dedup.
21
21
  */
22
- import type { DshApprovalStreamItem, DshCommandResult, DshModelCatalogValue, DshModelSelection, DshOpenTurnState, DshPermissionCatalogValue, DshJobView, DshPresetListValue, DshProjectionItem, DshProjectionSnapshot, DshQuestion, DshRemoteEventOutcome, DshSessionPageValue, DshStreamItem, DshTokenUsage } from '../../dsh/types.js';
22
+ import type { DshApprovalStreamItem, DshCommandResult, DshFollowSnapshot, DshModelCatalogValue, DshModelSelection, DshOpenTurnState, DshPermissionCatalogValue, DshJobView, DshPresetListValue, DshProjectionItem, DshProjectionSnapshot, DshQuestion, DshRemoteEventOutcome, DshSessionEvent, DshSessionPageValue, DshStreamItem } from '../../dsh/types.js';
23
23
  import type { GoalView } from '../types.js';
24
24
  export { DshError } from './errors.js';
25
25
  interface WebSocketMessageEvent {
@@ -105,8 +105,11 @@ export declare class DshClient {
105
105
  signal?: AbortSignal;
106
106
  timeoutMs?: number;
107
107
  }): Promise<unknown>;
108
- /** Distinguish "run stopped" (abort) from "server did not answer" (timeout). */
109
- private abortError;
108
+ /** One unary POST attempt: obtain cookie, then post; both stages may ask to
109
+ * retry once (401 → re-mint cookie); all other failures throw DshError. */
110
+ private attemptUnary;
111
+ private obtainUnaryCookie;
112
+ private postUnary;
110
113
  /** Create a session. Pass `agentPreset` to pin the session's preset (fixed at
111
114
  * creation). */
112
115
  createSession(payload: {
@@ -157,8 +160,6 @@ export declare class DshClient {
157
160
  signal?: AbortSignal;
158
161
  timeoutMs?: number;
159
162
  }): Promise<void>;
160
- /** Hand one waterfall delivery back with `next` (another answerer owns it). */
161
- private delegateWaterfall;
162
163
  /**
163
164
  * Return the highest event `seq` currently persisted for the session.
164
165
  *
@@ -279,9 +280,6 @@ export declare class DshClient {
279
280
  * `next` so a different lark-remote workspace cannot park it.
280
281
  */
281
282
  approvalEvents(sessionId: string, signal: AbortSignal): AsyncGenerator<DshApprovalStreamItem>;
282
- /** Translate one durable event into a stream item (approvals are surfaced
283
- * separately; everything else is forwarded to the runner). */
284
- private eventItem;
285
283
  /**
286
284
  * Per-session subscription: yields session events, assistant stream chunks
287
285
  * and approval notices for `sessionId`, auto-reconnecting on stream
@@ -312,7 +310,7 @@ export declare class DshClient {
312
310
  * 返回 seq 升序的完整回放序列(回填 + 快照记录;与 lastSeq 重叠的条目
313
311
  * 由回放循环的 seq 去重兜住)。
314
312
  */
315
- private replaySnapshotGap;
313
+ replaySnapshotGap(sessionId: string, signal: AbortSignal, lastSeq: number, frame: DshFollowSnapshot): Promise<DshSessionEvent[]>;
316
314
  /**
317
315
  * Host-wide live projection stream (`session/control`).
318
316
  *
@@ -348,8 +346,6 @@ export declare class DshClient {
348
346
  jobKill(sessionId: string, jobId: string, opts?: {
349
347
  signal?: AbortSignal;
350
348
  }): Promise<boolean>;
351
- /** Extract TokenUsage from an assistant/message data payload (absent → undefined). */
352
- static usageOf(data: Record<string, unknown>): DshTokenUsage | undefined;
353
349
  }
354
350
  /** Stable client-side prompt identity persisted on the accepted user message. */
355
351
  export declare function newPromptRequestId(): string;