@1agents/acp-service 0.8.2 → 0.8.3

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1agents/acp-service",
3
- "version": "0.8.2",
3
+ "version": "0.8.3",
4
4
  "description": "ACP runtime, CLI, HTTP/WebSocket service and DeepSeek Harness ACP/A2A plugins in one package.",
5
5
  "keywords": [
6
6
  "dreammate",
@@ -266,16 +266,17 @@ function installTranscriptView(ctx) {
266
266
  // src/client.js
267
267
  var inject = ["slots", "sessions", "commandUi", "remote", "remote.session", "locale", "uiConversation", "conversation"];
268
268
  var dictionaries = {
269
- zh: { toolGroup: "\u5DF2\u8C03\u7528 {count} \u4E2A\u5DE5\u5177", 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" },
270
- en: { toolGroup: "{count} tool calls", 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." }
269
+ zh: { toolGroup: "\u5DF2\u8C03\u7528 {count} \u4E2A\u5DE5\u5177", model: "\u6A21\u578B", choose: "\u9009\u62E9\u6A21\u578B", loading: "\u6B63\u5728\u8FDE\u63A5 Agent\u2026", loadingModels: "\u6B63\u5728\u52A0\u8F7D\u6A21\u578B\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" },
270
+ en: { toolGroup: "{count} tool calls", model: "Model", choose: "Select model", loading: "Connecting to Agent\u2026", loadingModels: "Loading models\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." }
271
271
  };
272
272
  function choices(option) {
273
273
  return (option.options ?? []).flatMap((item) => "group" in item ? item.options.map((value) => ({ ...value, group: item.name ?? item.group })) : [item]);
274
274
  }
275
- async function acpRequest(sessionId, change) {
275
+ async function acpRequest(sessionId, change, signal) {
276
276
  const response = await fetch(`/api/1agents-acp/session?id=${encodeURIComponent(sessionId)}`, {
277
277
  ...change ? { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(change) } : {},
278
- credentials: "same-origin"
278
+ credentials: "same-origin",
279
+ ...signal ? { signal } : {}
279
280
  });
280
281
  const value = await response.json();
281
282
  if (!response.ok) throw new Error(value.error || `HTTP ${response.status}`);
@@ -304,48 +305,93 @@ function apply(ctx) {
304
305
  const pending = /* @__PURE__ */ new Map();
305
306
  const listeners = /* @__PURE__ */ new Map();
306
307
  const blockedSessions = /* @__PURE__ */ new Set();
308
+ const revisions = /* @__PURE__ */ new Map();
309
+ const selectedPresets = /* @__PURE__ */ new Map();
307
310
  let disposed = false;
308
- const presetOf = (id) => ctx.sessions.binding(id)?.session.projections.faceOf("agentPreset").getSnapshot();
311
+ const revisionOf = (id) => revisions.get(id) ?? 0;
312
+ const presetOf = (id) => {
313
+ const projected = ctx.sessions.binding(id)?.session.projections.faceOf("agentPreset").getSnapshot();
314
+ const selected = selectedPresets.get(id);
315
+ if (selected === void 0) return projected;
316
+ if (projected === selected) selectedPresets.delete(id);
317
+ return selected;
318
+ };
309
319
  const isAcp = (id) => String(presetOf(id) ?? "").startsWith("oneagents-acp-");
310
320
  const block = (id, reason) => {
311
- if (disposed) return;
321
+ if (disposed || !reason && !blockedSessions.has(id)) return;
312
322
  if (reason) blockedSessions.add(id);
313
323
  else blockedSessions.delete(id);
314
324
  ctx.conversation.blocks.set(id, reason ? { reason } : void 0);
315
325
  };
326
+ const notify = (id) => {
327
+ for (const fn of listeners.get(id) ?? []) fn();
328
+ };
316
329
  ctx.effect(() => () => {
317
330
  disposed = true;
331
+ for (const request of pending.values()) request.controller.abort();
332
+ pending.clear();
318
333
  for (const id of blockedSessions) ctx.conversation.blocks.set(id, void 0);
334
+ blockedSessions.clear();
319
335
  });
320
336
  const publish = (id, value) => {
321
337
  native.set(id, value);
322
338
  block(id, value?.writable === false ? t(value.blocked === "active-writer" ? "activeWriter" : "error") : void 0);
323
- for (const fn of listeners.get(id) ?? []) fn();
339
+ notify(id);
324
340
  };
325
341
  const load = (id) => {
342
+ if (!isAcp(id)) {
343
+ block(id, void 0);
344
+ return Promise.resolve(void 0);
345
+ }
326
346
  if (!pending.has(id)) {
347
+ const revision = revisionOf(id);
348
+ const preset = presetOf(id);
349
+ const controller = new AbortController();
350
+ const request = { controller, operation: void 0 };
351
+ const current = () => !disposed && revision === revisionOf(id) && preset === presetOf(id);
327
352
  if (!native.has(id)) block(id, t("loading"));
328
- const operation = acpRequest(id).then((value) => {
353
+ request.operation = acpRequest(id, void 0, controller.signal).then((value) => {
354
+ if (!current()) return void 0;
329
355
  publish(id, value);
330
356
  return value;
331
357
  }).catch((error) => {
332
- block(id, `${t("error")}: ${error.message}`);
358
+ if (!current() || controller.signal.aborted) return void 0;
359
+ block(id, t("error") + ": " + error.message);
333
360
  throw error;
334
- }).finally(() => pending.delete(id));
335
- pending.set(id, operation);
361
+ }).finally(() => {
362
+ if (pending.get(id) === request) pending.delete(id);
363
+ });
364
+ pending.set(id, request);
336
365
  }
337
- return pending.get(id);
366
+ return pending.get(id).operation;
338
367
  };
339
368
  const configure = async (id, configId, value) => {
340
- const updated = await acpRequest(id, { configId, value });
341
- publish(id, updated);
369
+ const revision = revisionOf(id);
370
+ const preset = presetOf(id);
371
+ const current = () => !disposed && revision === revisionOf(id) && preset === presetOf(id) && isAcp(id);
372
+ try {
373
+ const updated = await acpRequest(id, { configId, value });
374
+ if (current()) publish(id, updated);
375
+ } catch (error) {
376
+ if (current()) throw error;
377
+ }
378
+ };
379
+ const invalidate = (id, selectedPreset) => {
380
+ const tracked = native.has(id) || pending.has(id) || blockedSessions.has(id) || listeners.has(id);
381
+ revisions.set(id, revisionOf(id) + 1);
382
+ if (selectedPreset !== void 0) selectedPresets.set(id, selectedPreset);
383
+ const request = pending.get(id);
384
+ pending.delete(id);
385
+ request?.controller.abort();
386
+ native.delete(id);
387
+ block(id, tracked && isAcp(id) ? t("loading") : void 0);
388
+ notify(id);
342
389
  };
343
390
  const reset = () => {
344
- for (const id of native.keys()) block(id, isAcp(id) ? t("loading") : void 0);
345
- native.clear();
346
- for (const set of listeners.values()) for (const fn of set) fn();
391
+ selectedPresets.clear();
392
+ for (const id of /* @__PURE__ */ new Set([...native.keys(), ...pending.keys(), ...blockedSessions, ...listeners.keys()])) invalidate(id);
347
393
  };
348
- ctx.remote.$on("agent-preset/selected", reset);
394
+ ctx.remote.$on("agent-preset/selected", (sessionId, agentPreset) => invalidate(sessionId, agentPreset));
349
395
  ctx.on("connection/reset", reset);
350
396
  function ModelControls({ sessionId, locked }) {
351
397
  const binding = ctx.sessions.binding(sessionId);
@@ -367,20 +413,30 @@ function apply(ctx) {
367
413
  const [loadError, setLoadError] = (0, import_react2.useState)("");
368
414
  const [busy, setBusy] = (0, import_react2.useState)(false);
369
415
  const [expanded, setExpanded] = (0, import_react2.useState)(false);
416
+ const changeSequence = (0, import_react2.useRef)(0);
370
417
  const refresh = async () => {
418
+ const revision = revisionOf(sessionId);
419
+ const current = () => !disposed && revision === revisionOf(sessionId) && presetOf(sessionId) === presetId;
371
420
  try {
372
421
  if (external) await load(sessionId);
373
422
  else {
423
+ block(sessionId, void 0);
374
424
  const result = await ctx.remote.session.modelCatalog();
425
+ if (!current()) return;
375
426
  if (!result.ok) throw new Error(result.error.message);
376
427
  setCatalog(result.value);
377
428
  }
378
- setLoadError("");
429
+ if (current()) setLoadError("");
379
430
  } catch (error2) {
380
- setLoadError(String(error2.message ?? error2));
431
+ if (current()) setLoadError(String(error2.message ?? error2));
381
432
  }
382
433
  };
383
434
  (0, import_react2.useEffect)(() => {
435
+ if (!external) block(sessionId, void 0);
436
+ setError("");
437
+ setLoadError("");
438
+ changeSequence.current += 1;
439
+ setBusy(false);
384
440
  void refresh();
385
441
  }, [sessionId, presetId]);
386
442
  (0, import_react2.useEffect)(() => {
@@ -391,14 +447,17 @@ function apply(ctx) {
391
447
  return () => clearInterval(timer);
392
448
  }, [external, sessionId, presetId]);
393
449
  const change = async (action) => {
450
+ const operation = ++changeSequence.current;
451
+ const revision = revisionOf(sessionId);
452
+ const current = () => !disposed && operation === changeSequence.current && revision === revisionOf(sessionId) && presetOf(sessionId) === presetId;
394
453
  setBusy(true);
395
454
  setError("");
396
455
  try {
397
456
  await action();
398
457
  } catch (error2) {
399
- setError(String(error2.message ?? error2));
458
+ if (current()) setError(String(error2.message ?? error2));
400
459
  } finally {
401
- setBusy(false);
460
+ if (operation === changeSequence.current) setBusy(false);
402
461
  }
403
462
  };
404
463
  const disabled = locked || busy || external && capabilities?.writable === false;
@@ -424,7 +483,7 @@ function apply(ctx) {
424
483
  controls.push((0, import_react2.createElement)(Select, { key: "dsh-model", title: t("model"), value: current?.provider === "1agents-acp" ? "" : JSON.stringify([current?.provider, current?.model]), rows, disabled, placeholder: t("choose"), onSelect: (value) => change(() => select(...JSON.parse(value))) }));
425
484
  const model = catalog.groups.find((g) => g.id === current?.provider)?.models.find((m) => m.id === current?.model);
426
485
  if (model?.reasoning) controls.push((0, import_react2.createElement)(Select, { key: "effort", title: t("effort"), value: current.reasoningEffort ?? model.reasoning.defaultEffort, rows: model.reasoning.efforts.map((e) => ({ value: e.id, name: e.name })), disabled, onSelect: (value) => change(() => select(current.provider, current.model, value)) }));
427
- } else if (!error && !loadError) controls.push((0, import_react2.createElement)("span", { key: "loading", style: { fontSize: 12 } }, t("loading")));
486
+ } else if (!error && !loadError) controls.push((0, import_react2.createElement)("span", { key: "loading", style: { fontSize: 12 } }, t(external ? "loading" : "loadingModels")));
428
487
  if (error || loadError) controls.push((0, import_react2.createElement)("span", { key: "error", role: "alert", style: { color: "#c64b45", fontSize: 12, maxWidth: 360 } }, error || loadError, " ", (0, import_react2.createElement)("button", { type: "button", onClick: () => {
429
488
  setError("");
430
489
  void refresh();
@@ -441,7 +500,8 @@ function apply(ctx) {
441
500
  options: async ({ sessionId }) => {
442
501
  if (isAcp(sessionId)) {
443
502
  const capabilities = await load(sessionId);
444
- const model = capabilities?.configOptions.find((option) => option.category === "model" || option.id === "model");
503
+ if (!capabilities) return [];
504
+ const model = capabilities.configOptions.find((option) => option.category === "model" || option.id === "model");
445
505
  if (!model) throw new Error(t("unsupported"));
446
506
  return choices(model).map((option) => ({ id: JSON.stringify([model.id, option.value]), label: option.name, detail: option.description, active: option.value === model.currentValue }));
447
507
  }