@1agents/acp-service 0.5.1 → 0.5.2
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.
- package/package.json +1 -1
- package/vendor/dsh/README.md +2 -2
- package/vendor/dsh/adapter.d.ts +2 -0
- package/vendor/dsh/adapter.js +18 -5
- package/vendor/dsh/client.js +22 -4
- package/vendor/dsh/imports.d.ts +4 -2
- package/vendor/dsh/imports.js +16 -7
- package/vendor/dsh/state.d.ts +4 -1
- package/vendor/dsh/state.js +9 -1
package/package.json
CHANGED
package/vendor/dsh/README.md
CHANGED
|
@@ -34,14 +34,14 @@ With `@1agents/session-reader` installed, choose **在 DSH 中继续原会话**
|
|
|
34
34
|
|
|
35
35
|
Imported bindings use `session/resume` because the service does not own a complete ACP replay of earlier native history. Existing ordinary ACP bindings continue using `session/load`. Endpoint, source provider and native ID identify an import; repeated admission reuses its DSH session without refreshing or replacing history. Old history-only DSH copies are not adopted. Original Agent history can continue changing outside DSH; the imported DSH history is a snapshot.
|
|
36
36
|
|
|
37
|
-
The service ID is saved before DSH creation. A failed local creation or workspace attachment can be retried after restart without importing again.
|
|
37
|
+
The service ID is saved before DSH creation. A failed local creation or workspace attachment can be retried after restart without importing again. When the original session reports `already has an active writer`, DSH still creates and opens its historical session. The composer is disabled with an explanation; capability refresh retries the original identity and restores input after its writer releases it. A pending import survives plugin restart. Other native restoration and authentication failures are reported, never replaced by a new empty session. If the transport is lost before the import response reaches the plugin, the plugin cannot know the service ID and does not automatically retry that RPC.
|
|
38
38
|
|
|
39
39
|
### Plugin service API
|
|
40
40
|
|
|
41
41
|
`ctx.oneagentsAcpSessions` is a Cordis service owned by this plugin; consumers may declare it optional so history browsing works without ACP. Its TypeScript declarations are exported from `@1agents/acp-service/dsh/imports`. Consumers call the service from the Host and must not instantiate it or write its binding files.
|
|
42
42
|
|
|
43
43
|
- `availability(provider)` returns `{ available, agent?, reason? }` without restoring a session. It checks configuration and the service inventory; successful native restoration remains the final capability/authentication check.
|
|
44
|
-
- `importSession({ provider, nativeSessionId, cwd, events })` accepts current DSH events starting at sequence zero. It returns `{ success: true, dshSessionId, workspace, workspaceId, agent, continuation: 'native' }`
|
|
44
|
+
- `importSession({ provider, nativeSessionId, cwd, events })` accepts current DSH events starting at sequence zero. It returns `{ success: true, dshSessionId, workspace, workspaceId, agent, continuation: 'native', writable, blocked? }` after DSH creation and workspace attachment. An active native writer returns `writable: false, blocked: 'active-writer'` while leaving history available.
|
|
45
45
|
|
|
46
46
|
Provider mapping is `claude → claude`, `codex → codex`, `grok → grok-build`. The service validates history through DSH before restoring a new native binding. No DSH Session format changes are required.
|
|
47
47
|
|
package/vendor/dsh/adapter.d.ts
CHANGED
package/vendor/dsh/adapter.js
CHANGED
|
@@ -3,7 +3,7 @@ import { createHash } from 'node:crypto';
|
|
|
3
3
|
import { randomUUID } from 'node:crypto';
|
|
4
4
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
5
5
|
import { connect, object } from './transport.js';
|
|
6
|
-
import { State } from './state.js';
|
|
6
|
+
import { State, hasActiveWriter } from './state.js';
|
|
7
7
|
import { mergeTool } from './tool-events.js';
|
|
8
8
|
/** Producer/consumer queue; errors are delivered after already received chunks. */
|
|
9
9
|
class Queue {
|
|
@@ -82,10 +82,18 @@ export class AcpAdapter {
|
|
|
82
82
|
return this.config.agents.includes(name) ? name : undefined;
|
|
83
83
|
}
|
|
84
84
|
async describe(agent) {
|
|
85
|
-
|
|
85
|
+
const name = this.agentName(agent);
|
|
86
|
+
if (!name)
|
|
86
87
|
return null;
|
|
87
|
-
|
|
88
|
-
|
|
88
|
+
try {
|
|
89
|
+
await this.connection(agent);
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
if (!this.state.get(agent.id)?.imported || !hasActiveWriter(error))
|
|
93
|
+
throw error;
|
|
94
|
+
return { agent: name, commands: [], configOptions: [], writable: false, blocked: 'active-writer' };
|
|
95
|
+
}
|
|
96
|
+
return { ...this.capabilities.get(agent.id), writable: true };
|
|
89
97
|
}
|
|
90
98
|
async configure(agent, configId, value) {
|
|
91
99
|
if (this.controllers.has(agent.id))
|
|
@@ -214,6 +222,11 @@ export class AcpAdapter {
|
|
|
214
222
|
const existing = this.links.get(agent.id);
|
|
215
223
|
if (existing)
|
|
216
224
|
return existing;
|
|
225
|
+
if (binding?.imported && !binding.sessionId) {
|
|
226
|
+
// Retry the original native identity after its writer releases it; never open an empty replacement.
|
|
227
|
+
binding = { ...await this.importNative(name, cwd, binding.imported.nativeSessionId), imported: binding.imported };
|
|
228
|
+
this.state.save(agent.id, binding);
|
|
229
|
+
}
|
|
217
230
|
const operation = (async () => {
|
|
218
231
|
if (!this.commandContexts.has(agent.id)) {
|
|
219
232
|
const fiber = await agent.ctx.inject(['commands'], scope => {
|
|
@@ -414,7 +427,7 @@ export class AcpAdapter {
|
|
|
414
427
|
}
|
|
415
428
|
};
|
|
416
429
|
let active;
|
|
417
|
-
const cancel = () => { if (binding)
|
|
430
|
+
const cancel = () => { if (binding?.sessionId)
|
|
418
431
|
void active?.rpc.notify('session/cancel', { sessionId: binding.sessionId }).catch(() => { }); };
|
|
419
432
|
signal.addEventListener('abort', cancel, { once: true });
|
|
420
433
|
try {
|
package/vendor/dsh/client.js
CHANGED
|
@@ -111,10 +111,10 @@ var toolConversationDefinition = {
|
|
|
111
111
|
};
|
|
112
112
|
|
|
113
113
|
// src/client.js
|
|
114
|
-
var inject = ["slots", "sessions", "commandUi", "remote", "remote.session", "locale", "uiConversation"];
|
|
114
|
+
var inject = ["slots", "sessions", "commandUi", "remote", "remote.session", "locale", "uiConversation", "conversation"];
|
|
115
115
|
var dictionaries = {
|
|
116
|
-
zh: { toolRunning: "\u6267\u884C\u4E2D", toolFailed: "\u5931\u8D25", toolCompleted: "\u5DF2\u5B8C\u6210", toolNoOutput: "\u65E0\u8F93\u51FA", model: "\u6A21\u578B", choose: "\u9009\u62E9\u6A21\u578B", loading: "\u6B63\u5728\u8FDE\u63A5 Agent\u2026", retry: "\u91CD\u8BD5", mode: "\u6A21\u5F0F", command: "Agent \u6307\u4EE4", effort: "\u601D\u8003\u5F3A\u5EA6", unsupported: "Agent \u672A\u63D0\u4F9B\u53EF\u5207\u6362\u7684\u6A21\u578B", description: "\u9009\u62E9\u5F53\u524D Agent \u7684\u6A21\u578B", error: "\u8FDE\u63A5\u5931\u8D25", noCommands: "Agent \u5C1A\u672A\u63D0\u4F9B\u6307\u4EE4", native: "ACP \u8BBE\u7F6E" },
|
|
117
|
-
en: { toolRunning: "Running", toolFailed: "Failed", toolCompleted: "Completed", toolNoOutput: "No output", model: "Model", choose: "Select model", loading: "Connecting to Agent\u2026", retry: "Retry", mode: "Mode", command: "Agent commands", effort: "Reasoning effort", unsupported: "This Agent does not advertise model selection", description: "Select this Agent\u2019s model", error: "Connection failed", noCommands: "No commands advertised", native: "ACP settings" }
|
|
116
|
+
zh: { toolRunning: "\u6267\u884C\u4E2D", toolFailed: "\u5931\u8D25", toolCompleted: "\u5DF2\u5B8C\u6210", toolNoOutput: "\u65E0\u8F93\u51FA", model: "\u6A21\u578B", choose: "\u9009\u62E9\u6A21\u578B", loading: "\u6B63\u5728\u8FDE\u63A5 Agent\u2026", retry: "\u91CD\u8BD5", mode: "\u6A21\u5F0F", command: "Agent \u6307\u4EE4", effort: "\u601D\u8003\u5F3A\u5EA6", unsupported: "Agent \u672A\u63D0\u4F9B\u53EF\u5207\u6362\u7684\u6A21\u578B", description: "\u9009\u62E9\u5F53\u524D Agent \u7684\u6A21\u578B", error: "\u8FDE\u63A5\u5931\u8D25", noCommands: "Agent \u5C1A\u672A\u63D0\u4F9B\u6307\u4EE4", native: "ACP \u8BBE\u7F6E", activeWriter: "\u539F\u4F1A\u8BDD\u6B63\u5728\u5176\u4ED6\u5BA2\u6237\u7AEF\u8FD0\u884C\uFF0C\u53EF\u67E5\u770B\u5386\u53F2\uFF1B\u5360\u7528\u89E3\u9664\u540E\u81EA\u52A8\u6062\u590D\u8F93\u5165\u3002" },
|
|
117
|
+
en: { toolRunning: "Running", toolFailed: "Failed", toolCompleted: "Completed", toolNoOutput: "No output", model: "Model", choose: "Select model", loading: "Connecting to Agent\u2026", retry: "Retry", mode: "Mode", command: "Agent commands", effort: "Reasoning effort", unsupported: "This Agent does not advertise model selection", description: "Select this Agent\u2019s model", error: "Connection failed", noCommands: "No commands advertised", native: "ACP settings", activeWriter: "The original session is running in another client. History is available; input resumes when it is released." }
|
|
118
118
|
};
|
|
119
119
|
function choices(option) {
|
|
120
120
|
return (option.options ?? []).flatMap((item) => "group" in item ? item.options.map((value) => ({ ...value, group: item.name ?? item.group })) : [item]);
|
|
@@ -193,17 +193,34 @@ function apply(ctx) {
|
|
|
193
193
|
const native = /* @__PURE__ */ new Map();
|
|
194
194
|
const pending = /* @__PURE__ */ new Map();
|
|
195
195
|
const listeners = /* @__PURE__ */ new Map();
|
|
196
|
+
const blockedSessions = /* @__PURE__ */ new Set();
|
|
197
|
+
let disposed = false;
|
|
196
198
|
const presetOf = (id) => ctx.sessions.binding(id)?.session.projections.faceOf("agentPreset").getSnapshot();
|
|
197
199
|
const isAcp = (id) => String(presetOf(id) ?? "").startsWith("oneagents-acp-");
|
|
200
|
+
const block = (id, reason) => {
|
|
201
|
+
if (disposed) return;
|
|
202
|
+
if (reason) blockedSessions.add(id);
|
|
203
|
+
else blockedSessions.delete(id);
|
|
204
|
+
ctx.conversation.blocks.set(id, reason ? { reason } : void 0);
|
|
205
|
+
};
|
|
206
|
+
ctx.effect(() => () => {
|
|
207
|
+
disposed = true;
|
|
208
|
+
for (const id of blockedSessions) ctx.conversation.blocks.set(id, void 0);
|
|
209
|
+
});
|
|
198
210
|
const publish = (id, value) => {
|
|
199
211
|
native.set(id, value);
|
|
212
|
+
block(id, value?.writable === false ? t(value.blocked === "active-writer" ? "activeWriter" : "error") : void 0);
|
|
200
213
|
for (const fn of listeners.get(id) ?? []) fn();
|
|
201
214
|
};
|
|
202
215
|
const load = (id) => {
|
|
203
216
|
if (!pending.has(id)) {
|
|
217
|
+
if (!native.has(id)) block(id, t("loading"));
|
|
204
218
|
const operation = acpRequest(id).then((value) => {
|
|
205
219
|
publish(id, value);
|
|
206
220
|
return value;
|
|
221
|
+
}).catch((error) => {
|
|
222
|
+
block(id, `${t("error")}: ${error.message}`);
|
|
223
|
+
throw error;
|
|
207
224
|
}).finally(() => pending.delete(id));
|
|
208
225
|
pending.set(id, operation);
|
|
209
226
|
}
|
|
@@ -214,6 +231,7 @@ function apply(ctx) {
|
|
|
214
231
|
publish(id, updated);
|
|
215
232
|
};
|
|
216
233
|
const reset = () => {
|
|
234
|
+
for (const id of native.keys()) block(id, isAcp(id) ? t("loading") : void 0);
|
|
217
235
|
native.clear();
|
|
218
236
|
for (const set of listeners.values()) for (const fn of set) fn();
|
|
219
237
|
};
|
|
@@ -273,7 +291,7 @@ function apply(ctx) {
|
|
|
273
291
|
setBusy(false);
|
|
274
292
|
}
|
|
275
293
|
};
|
|
276
|
-
const disabled = locked || busy;
|
|
294
|
+
const disabled = locked || busy || external && capabilities?.writable === false;
|
|
277
295
|
const controls = [];
|
|
278
296
|
if (external && capabilities) {
|
|
279
297
|
const configs = capabilities.configOptions.filter((option) => option.type === "select");
|
package/vendor/dsh/imports.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export interface NativeSessionInput {
|
|
|
15
15
|
/** Current DSH events, contiguous from sequence zero. */
|
|
16
16
|
events: readonly SessionEvent[];
|
|
17
17
|
}
|
|
18
|
-
/**
|
|
18
|
+
/** Attached historical session, safe for navigation even while native writing is blocked. */
|
|
19
19
|
export interface ImportResult {
|
|
20
20
|
success: true;
|
|
21
21
|
dshSessionId: SessionId;
|
|
@@ -23,6 +23,8 @@ export interface ImportResult {
|
|
|
23
23
|
workspaceId: string;
|
|
24
24
|
agent: string;
|
|
25
25
|
continuation: 'native';
|
|
26
|
+
writable: boolean;
|
|
27
|
+
blocked?: 'active-writer';
|
|
26
28
|
}
|
|
27
29
|
declare module '@deepseek-ai/cordis' {
|
|
28
30
|
interface Context {
|
|
@@ -45,7 +47,7 @@ export declare class NativeSessions {
|
|
|
45
47
|
availability(provider: string): Promise<ImportAvailability>;
|
|
46
48
|
/** Restore one native session; repeated calls return its existing DSH identity and never replace its history.
|
|
47
49
|
* @param input Native identity, original workspace and historical events.
|
|
48
|
-
* @returns The attached DSH session
|
|
50
|
+
* @returns The attached DSH session and its native writing availability.
|
|
49
51
|
*/
|
|
50
52
|
importSession(input: NativeSessionInput): Promise<ImportResult>;
|
|
51
53
|
/** Stop new admissions and await callers already creating or attaching a session. */
|
package/vendor/dsh/imports.js
CHANGED
|
@@ -3,7 +3,7 @@ import { createHash } from 'node:crypto';
|
|
|
3
3
|
import { realpath, stat } from 'node:fs/promises';
|
|
4
4
|
import { isAbsolute } from 'node:path';
|
|
5
5
|
import { discoverPresets } from './discovery.js';
|
|
6
|
-
import { State } from './state.js';
|
|
6
|
+
import { State, hasActiveWriter } from './state.js';
|
|
7
7
|
const providers = { claude: 'claude', codex: 'codex', grok: 'grok-build' };
|
|
8
8
|
/** Owns import identities and serializes retries through remote import, local creation and workspace attachment. */
|
|
9
9
|
export class NativeSessions {
|
|
@@ -41,7 +41,7 @@ export class NativeSessions {
|
|
|
41
41
|
}
|
|
42
42
|
/** Restore one native session; repeated calls return its existing DSH identity and never replace its history.
|
|
43
43
|
* @param input Native identity, original workspace and historical events.
|
|
44
|
-
* @returns The attached DSH session
|
|
44
|
+
* @returns The attached DSH session and its native writing availability.
|
|
45
45
|
*/
|
|
46
46
|
async importSession(input) {
|
|
47
47
|
if (this.disposed)
|
|
@@ -105,10 +105,18 @@ export class NativeSessions {
|
|
|
105
105
|
this.ctx.sessions.prepare(id, { seed: input.events, meta: { cwd, agentPreset: preset } });
|
|
106
106
|
await this.ctx.agentPresets.resolve(preset);
|
|
107
107
|
}
|
|
108
|
+
let blocked = false;
|
|
108
109
|
if (!binding) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
const imported = { provider: input.provider, nativeSessionId: input.nativeSessionId, messageIds: [] };
|
|
111
|
+
try {
|
|
112
|
+
binding = { ...await this.adapter.importNative(agent, cwd, input.nativeSessionId), imported };
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
if (!hasActiveWriter(error))
|
|
116
|
+
throw error;
|
|
117
|
+
blocked = true;
|
|
118
|
+
binding = { agent, cwd, endpoint: endpoint.href, restoreMethod: 'session/resume', imported };
|
|
119
|
+
}
|
|
112
120
|
// The service ID survives local creation/attachment failure and plugin restart.
|
|
113
121
|
this.state.save(id, binding);
|
|
114
122
|
}
|
|
@@ -125,9 +133,10 @@ export class NativeSessions {
|
|
|
125
133
|
const resolved = await this.ctx.sessionController.resolveAgent(id);
|
|
126
134
|
if ('error' in resolved)
|
|
127
135
|
throw resolved.error;
|
|
128
|
-
await this.adapter.describe(resolved.agent);
|
|
136
|
+
const capabilities = blocked ? { writable: false, blocked: 'active-writer' } : await this.adapter.describe(resolved.agent);
|
|
129
137
|
const workspace = await this.ctx.workspaceRegistry.create(cwd);
|
|
130
138
|
await workspace.attachSession(id);
|
|
131
|
-
return { success: true, dshSessionId: id, workspace: cwd, workspaceId: workspace.id, agent, continuation: 'native'
|
|
139
|
+
return { success: true, dshSessionId: id, workspace: cwd, workspaceId: workspace.id, agent, continuation: 'native',
|
|
140
|
+
writable: capabilities?.writable !== false, ...(capabilities?.blocked ? { blocked: capabilities.blocked } : {}) };
|
|
132
141
|
}
|
|
133
142
|
}
|
package/vendor/dsh/state.d.ts
CHANGED
|
@@ -8,7 +8,8 @@ export interface Binding {
|
|
|
8
8
|
agent: string;
|
|
9
9
|
cwd: string;
|
|
10
10
|
endpoint: string;
|
|
11
|
-
|
|
11
|
+
/** Absent while the original native session has an active writer. Never use session/new for this binding. */
|
|
12
|
+
sessionId?: string;
|
|
12
13
|
/** Absent on bindings created before native imports were supported. */
|
|
13
14
|
restoreMethod?: 'session/load' | 'session/resume';
|
|
14
15
|
imported?: NativeImport;
|
|
@@ -20,3 +21,5 @@ export declare class State {
|
|
|
20
21
|
get(id: string): Binding | undefined;
|
|
21
22
|
save(id: string, binding: Binding): void;
|
|
22
23
|
}
|
|
24
|
+
/** Native writer ownership prevents execution, but must not prevent reading imported history. */
|
|
25
|
+
export declare function hasActiveWriter(error: unknown): boolean;
|
package/vendor/dsh/state.js
CHANGED
|
@@ -30,7 +30,11 @@ function decodeBinding(value) {
|
|
|
30
30
|
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
31
31
|
throw new Error('Invalid ACP binding');
|
|
32
32
|
const binding = value;
|
|
33
|
-
if (['agent', 'cwd', 'endpoint'
|
|
33
|
+
if (['agent', 'cwd', 'endpoint'].some(key => typeof binding[key] !== 'string' || !binding[key]))
|
|
34
|
+
throw new Error('Invalid ACP binding identity');
|
|
35
|
+
if (binding.sessionId !== undefined && (typeof binding.sessionId !== 'string' || !binding.sessionId))
|
|
36
|
+
throw new Error('Invalid ACP binding identity');
|
|
37
|
+
if (binding.sessionId === undefined && binding.imported === undefined)
|
|
34
38
|
throw new Error('Invalid ACP binding identity');
|
|
35
39
|
if (binding.restoreMethod !== undefined && binding.restoreMethod !== 'session/load' && binding.restoreMethod !== 'session/resume')
|
|
36
40
|
throw new Error('Invalid ACP restore method');
|
|
@@ -45,3 +49,7 @@ function decodeBinding(value) {
|
|
|
45
49
|
}
|
|
46
50
|
return value;
|
|
47
51
|
}
|
|
52
|
+
/** Native writer ownership prevents execution, but must not prevent reading imported history. */
|
|
53
|
+
export function hasActiveWriter(error) {
|
|
54
|
+
return error instanceof Error && /already has an active writer/.test(error.message);
|
|
55
|
+
}
|