@ai-workbench/remote-agent 0.9.0-toolbridge.13 → 0.9.0-toolbridge.15

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.
@@ -4,7 +4,8 @@ import { NeedError } from "./remote.js";
4
4
  export function isolateRpcIds(stream, onWrite) {
5
5
  const prefix = randomUUID() + '/';
6
6
  const pending = new Map();
7
- const readable = stream.readable.pipeThrough(new TransformStream({ transform(message, controller) {
7
+ let incoming;
8
+ const readable = stream.readable.pipeThrough(new TransformStream({ start(controller) { incoming = controller; }, transform(message, controller) {
8
9
  const raw = message;
9
10
  if (!raw.method && Object.hasOwn(raw, 'id')) {
10
11
  if (typeof raw.id !== 'string' || !pending.has(raw.id))
@@ -28,9 +29,22 @@ export function isolateRpcIds(stream, onWrite) {
28
29
  const params = raw.params;
29
30
  outgoing = { ...raw, params: { ...params, requestId: prefix + JSON.stringify(params.requestId) } };
30
31
  }
31
- const writer = stream.writable.getWriter();
32
+ // A known pre-dispatch steering rejection belongs to one request. Throwing
33
+ // from WritableStream.write would permanently poison the shared SDK channel.
34
+ // Deliver an explicit local RPC error on the public Stream instead. No native
35
+ // write or dispatch count occurs, and the namespaced pending entry is removed.
32
36
  try {
33
37
  onWrite?.(outgoing);
38
+ }
39
+ catch (error) {
40
+ if (raw.method !== '_session/steering' || !Object.hasOwn(raw, 'id') || !(error instanceof NeedError) || !['ACP_MESSAGE_TOO_LARGE', 'PERMISSION_POLICY_CHANGED'].includes(error.code))
41
+ throw error;
42
+ pending.delete(String(outgoing.id));
43
+ incoming.enqueue({ jsonrpc: '2.0', id: raw.id, error: { code: -32603, message: 'ACP_LOCAL_REQUEST_REJECTED', data: { localDispatchCode: error.code } } });
44
+ return;
45
+ }
46
+ const writer = stream.writable.getWriter();
47
+ try {
34
48
  await writer.write(outgoing);
35
49
  }
36
50
  finally {
@@ -15,4 +15,6 @@ export declare const sessionSourceSpec: {
15
15
  };
16
16
  };
17
17
  /** Official domain metadata, keyed by native session ID. No L files, local path probes or host identity hashes. */
18
- export declare function createSessionSources(ctx: Context, getApi: () => ConnectApi | undefined): (request: RuntimeRequest, api: ConnectApi) => Promise<SessionSource | undefined>;
18
+ export declare function createSessionSources(ctx: Context, getApi: () => ConnectApi | undefined): ((request: RuntimeRequest, api: ConnectApi) => Promise<SessionSource | undefined>) & {
19
+ read: (sessionId: string) => Promise<SessionSource | undefined>;
20
+ };
@@ -79,7 +79,7 @@ export function createSessionSources(ctx, getApi) {
79
79
  return;
80
80
  void save(session, api).catch(() => ctx.logger('remote-agent').warn('会话文件来源暂未保存;发送时将重试'));
81
81
  });
82
- return async (request, api) => {
82
+ const resolve = async (request, api) => {
83
83
  if (!request.sessionId || api.getContractInfo?.().workspaceLocations !== 1 && !request.hostSource)
84
84
  return;
85
85
  const session = ctx.get('sessions')?.get(SessionId(request.sessionId));
@@ -87,4 +87,5 @@ export function createSessionSources(ctx, getApi) {
87
87
  throw storageNeed();
88
88
  return save(session, api, request);
89
89
  };
90
+ return Object.assign(resolve, { read: async (sessionId) => { const source = (await open()).table('sessions').get(sessionId); return source ? Object.freeze({ ...source }) : undefined; } });
90
91
  }
@@ -1,4 +1,4 @@
1
- import { type GenerateOptions, type StreamChunk } from '@deepseek-ai/dsh-llm';
1
+ import { type GenerateOptions, type StreamChunk, type UserMessage } from '@deepseek-ai/dsh-llm';
2
2
  import { ToolBridge } from './toolbridge.ts';
3
3
  import type { ImageReader } from './input.ts';
4
4
  type Producer = (options: GenerateOptions, bridge: ToolBridge) => AsyncGenerator<StreamChunk>;
@@ -6,9 +6,10 @@ type Producer = (options: GenerateOptions, bridge: ToolBridge) => AsyncGenerator
6
6
  export declare class ToolBridgeLoop {
7
7
  private readImage?;
8
8
  private stopped?;
9
+ private isInjected?;
9
10
  private runs;
10
11
  private concluding;
11
- constructor(readImage?: ImageReader | undefined, stopped?: ((sessionId: string, notice: string) => void) | undefined);
12
+ constructor(readImage?: ImageReader | undefined, stopped?: ((sessionId: string, notice: string) => void) | undefined, isInjected?: ((sessionId: string, message: UserMessage) => boolean) | undefined);
12
13
  private launch;
13
14
  conclude(id: string, messages: GenerateOptions['messages']): Promise<void>;
14
15
  active(id: string): boolean;
@@ -44,11 +44,13 @@ class Projection {
44
44
  export class ToolBridgeLoop {
45
45
  readImage;
46
46
  stopped;
47
+ isInjected;
47
48
  runs = new Map();
48
49
  concluding = new Map();
49
- constructor(readImage, stopped) {
50
+ constructor(readImage, stopped, isInjected) {
50
51
  this.readImage = readImage;
51
52
  this.stopped = stopped;
53
+ this.isInjected = isInjected;
52
54
  }
53
55
  launch(options, producer) {
54
56
  const controller = new AbortController(), bridge = new ToolBridge(options, this.readImage);
@@ -181,7 +183,7 @@ export class ToolBridgeLoop {
181
183
  throw new NeedError('ABORTED', '本轮已取消,工具结果没有重放。', '确认主机取消状态');
182
184
  if (run.latest !== options) {
183
185
  for (const m of options.messages)
184
- if (m.role === 'user' && 'source' in m && m.source?.kind === 'user' && 'id' in m && typeof m.id === 'string' && !run.seen.has(m.id)) {
186
+ if (m.role === 'user' && 'source' in m && m.source?.kind === 'user' && 'id' in m && typeof m.id === 'string' && !run.seen.has(m.id) && !this.isInjected?.(key, m)) {
185
187
  run.seen.add(m.id);
186
188
  run.deferred.push(m);
187
189
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-workbench/remote-agent",
3
- "version": "0.9.0-toolbridge.13",
3
+ "version": "0.9.0-toolbridge.15",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -53,8 +53,14 @@
53
53
  "@deepseek-ai/dsh-client-ui-settings": "0.2.0-rc.2",
54
54
  "@deepseek-ai/dsh-compaction-basic": "0.2.0-rc.2",
55
55
  "@deepseek-ai/dsh-llm": "0.2.0-rc.2",
56
+ "@deepseek-ai/dsh-sandbox-policy": "0.2.0-rc.2",
56
57
  "@deepseek-ai/dsh-session": "0.2.0-rc.2",
58
+ "@deepseek-ai/dsh-session-persistence-jsonl": "0.2.0-rc.2",
59
+ "@deepseek-ai/dsh-session-projection": "0.2.0-rc.2",
60
+ "@deepseek-ai/dsh-storage-domain": "0.2.0-rc.2",
61
+ "@deepseek-ai/dsh-system-prompt": "0.2.0-rc.2",
57
62
  "@deepseek-ai/dsh-token-meter": "0.2.0-rc.2",
63
+ "@deepseek-ai/dsh-tools": "0.2.0-rc.2",
58
64
  "@deepseek-ai/dsh-typert-protocol": "0.2.0-rc.2",
59
65
  "@deepseek-ai/dsh-typert-registry": "0.2.0-rc.2",
60
66
  "@deepseek-ai/dsh-user-approval": "0.2.0-rc.2",
@@ -65,12 +71,7 @@
65
71
  "react": "18.3.1",
66
72
  "react-dom": "18.3.1",
67
73
  "typescript": "5.9.3",
68
- "zustand": "4.4.7",
69
- "@deepseek-ai/dsh-sandbox-policy": "0.2.0-rc.2",
70
- "@deepseek-ai/dsh-storage-domain": "0.2.0-rc.2",
71
- "@deepseek-ai/dsh-session-projection": "0.2.0-rc.2",
72
- "@deepseek-ai/dsh-system-prompt": "0.2.0-rc.2",
73
- "@deepseek-ai/dsh-tools": "0.2.0-rc.2"
74
+ "zustand": "4.4.7"
74
75
  },
75
76
  "peerDependencies": {
76
77
  "@ai-workbench/connect": "~0.7.37",
@@ -79,12 +80,12 @@
79
80
  "@deepseek-ai/dsh-agent": ">=0.2.0-rc.2 <0.3.0-0",
80
81
  "@deepseek-ai/dsh-attachment": ">=0.2.0-rc.2 <0.3.0-0",
81
82
  "@deepseek-ai/dsh-llm": ">=0.2.0-rc.2 <0.3.0-0",
83
+ "@deepseek-ai/dsh-sandbox-policy": ">=0.2.0-rc.2 <0.3.0-0",
82
84
  "@deepseek-ai/dsh-session": ">=0.2.0-rc.2 <0.3.0-0",
85
+ "@deepseek-ai/dsh-storage-domain": ">=0.2.0-rc.2 <0.3.0-0",
83
86
  "@deepseek-ai/dsh-typert-protocol": ">=0.2.0-rc.2 <0.3.0-0",
84
87
  "@deepseek-ai/dsh-user-approval": ">=0.2.0-rc.2 <0.3.0-0",
85
- "@deepseek-ai/schemastery": "^3.18.4",
86
- "@deepseek-ai/dsh-sandbox-policy": ">=0.2.0-rc.2 <0.3.0-0",
87
- "@deepseek-ai/dsh-storage-domain": ">=0.2.0-rc.2 <0.3.0-0"
88
+ "@deepseek-ai/schemastery": "^3.18.4"
88
89
  },
89
90
  "dsh": {
90
91
  "bundle": {