@yachiyo-5i/xlyra-agent 1.3.0 → 1.3.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/dist/cli.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  saveConfig,
8
8
  serveFromConfig,
9
9
  upsertEndpoint
10
- } from "./chunk-5AIZKDJO.js";
10
+ } from "./chunk-KKPK4RMM.js";
11
11
 
12
12
  // src/cli.ts
13
13
  import fs from "fs";
package/dist/index.cjs CHANGED
@@ -1929,6 +1929,7 @@ var EscalationRequiredError = class extends Error {
1929
1929
  };
1930
1930
  var EscalationGrants = class {
1931
1931
  grants = /* @__PURE__ */ new Map();
1932
+ oneShotGrants = /* @__PURE__ */ new Map();
1932
1933
  /** 会话级完全访问开关(前端 permission_mode=full 注入;ask 时撤销,不随消息残留) */
1933
1934
  fullAccess = /* @__PURE__ */ new Set();
1934
1935
  /** 完全访问模式:跳过一切路径与能力提权检查(用户已在 UI 二次确认) */
@@ -1953,24 +1954,48 @@ var EscalationGrants = class {
1953
1954
  grantCapability(sessionId, capability) {
1954
1955
  this.grant(sessionId, capability);
1955
1956
  }
1957
+ grantOnce(sessionId, resolvedPath) {
1958
+ let set = this.oneShotGrants.get(sessionId);
1959
+ if (!set) {
1960
+ set = /* @__PURE__ */ new Set();
1961
+ this.oneShotGrants.set(sessionId, set);
1962
+ }
1963
+ set.add(resolvedPath);
1964
+ }
1965
+ grantCapabilityOnce(sessionId, capability) {
1966
+ this.grantOnce(sessionId, capability);
1967
+ }
1956
1968
  /** 已授权路径或其子路径视为已放开;完全访问模式直接放行 */
1957
1969
  isGranted(sessionId, resolvedPath) {
1958
1970
  if (this.fullAccess.has(sessionId)) return true;
1959
1971
  const set = this.grants.get(sessionId);
1960
- if (!set) return false;
1961
- for (const prefix of set) {
1962
- const relative = import_node_path2.default.relative(prefix, resolvedPath);
1963
- if (relative === "" || !relative.startsWith("..") && !import_node_path2.default.isAbsolute(relative)) return true;
1972
+ if (set) {
1973
+ for (const prefix of set) {
1974
+ const relative = import_node_path2.default.relative(prefix, resolvedPath);
1975
+ if (relative === "" || !relative.startsWith("..") && !import_node_path2.default.isAbsolute(relative)) return true;
1976
+ }
1977
+ }
1978
+ const oneShot = this.oneShotGrants.get(sessionId);
1979
+ if (oneShot?.has(resolvedPath)) {
1980
+ oneShot.delete(resolvedPath);
1981
+ if (oneShot.size === 0) this.oneShotGrants.delete(sessionId);
1982
+ return true;
1964
1983
  }
1965
1984
  return false;
1966
1985
  }
1967
1986
  isCapabilityGranted(sessionId, capability) {
1968
1987
  if (this.fullAccess.has(sessionId)) return true;
1969
- return this.grants.get(sessionId)?.has(capability) ?? false;
1988
+ if (this.grants.get(sessionId)?.has(capability)) return true;
1989
+ const oneShot = this.oneShotGrants.get(sessionId);
1990
+ if (!oneShot?.has(capability)) return false;
1991
+ oneShot.delete(capability);
1992
+ if (oneShot.size === 0) this.oneShotGrants.delete(sessionId);
1993
+ return true;
1970
1994
  }
1971
1995
  /** 会话删除时清掉授权(授权随会话生命周期) */
1972
1996
  drop(sessionId) {
1973
1997
  this.grants.delete(sessionId);
1998
+ this.oneShotGrants.delete(sessionId);
1974
1999
  this.fullAccess.delete(sessionId);
1975
2000
  }
1976
2001
  };
@@ -4407,7 +4432,14 @@ function createAgentRoutes(ctx) {
4407
4432
  }
4408
4433
  );
4409
4434
  await recorder.begin(runId);
4410
- return { sessionId: args.sessionId, messageId, runId };
4435
+ const resolvedModel = ctx.resolver.resolve(args.model).modelId;
4436
+ return {
4437
+ sessionId: args.sessionId,
4438
+ messageId,
4439
+ runId,
4440
+ model: resolvedModel,
4441
+ agentInstanceId: args.agentInstanceId ?? ctx.agentInstanceId ?? "default"
4442
+ };
4411
4443
  }
4412
4444
  app.post("/sessions", async (c) => {
4413
4445
  const payload = startPayloadSchema.parse(await c.req.json());
@@ -4434,7 +4466,7 @@ function createAgentRoutes(ctx) {
4434
4466
  if (payload.permission_mode !== void 0) {
4435
4467
  ctx.grants.setFullAccess(sessionId, payload.permission_mode === "full");
4436
4468
  }
4437
- const { messageId, runId } = await launchUserMessage({
4469
+ const { messageId, runId, model, agentInstanceId } = await launchUserMessage({
4438
4470
  sessionId,
4439
4471
  content: payload.content,
4440
4472
  model: payload.model,
@@ -4446,7 +4478,7 @@ function createAgentRoutes(ctx) {
4446
4478
  },
4447
4479
  ...payload.agent_instance_id ? { agentInstanceId: payload.agent_instance_id } : {}
4448
4480
  });
4449
- return c.json(ok({ session_id: sessionId, message_id: messageId, run_id: runId }, "\u7528\u6237\u6D88\u606F\u5DF2\u63D0\u4EA4"), 202);
4481
+ return c.json(ok({ session_id: sessionId, message_id: messageId, run_id: runId, model, agent_instance_id: agentInstanceId }, "\u7528\u6237\u6D88\u606F\u5DF2\u63D0\u4EA4"), 202);
4450
4482
  });
4451
4483
  app.get("/sessions", (c) => {
4452
4484
  const limit = Math.min(Number(c.req.query("limit") ?? 50), 200);
@@ -4569,7 +4601,7 @@ function createAgentRoutes(ctx) {
4569
4601
  ctx.store.discardFromUserMessage(sessionId, payload.message_id);
4570
4602
  const history = ctx.store.buildHistory(sessionId);
4571
4603
  const remaining = ctx.store.read(sessionId).entries.length;
4572
- const { messageId, runId } = await launchUserMessage({
4604
+ const { messageId, runId, model, agentInstanceId } = await launchUserMessage({
4573
4605
  sessionId,
4574
4606
  content,
4575
4607
  model: payload.model,
@@ -4582,7 +4614,7 @@ function createAgentRoutes(ctx) {
4582
4614
  },
4583
4615
  ...payload.agent_instance_id ? { agentInstanceId: payload.agent_instance_id } : {}
4584
4616
  });
4585
- return c.json(ok({ session_id: sessionId, message_id: messageId, run_id: runId }, "\u5DF2\u91CD\u65B0\u63D0\u4EA4"), 202);
4617
+ return c.json(ok({ session_id: sessionId, message_id: messageId, run_id: runId, model, agent_instance_id: agentInstanceId }, "\u5DF2\u91CD\u65B0\u63D0\u4EA4"), 202);
4586
4618
  });
4587
4619
  app.post("/sessions/:id/grant-access", async (c) => {
4588
4620
  const sessionId = c.req.param("id");
@@ -4601,6 +4633,12 @@ function createAgentRoutes(ctx) {
4601
4633
  if (!esc || esc.type !== "escalation") fail(404, "\u63D0\u6743\u8BF7\u6C42\u4E0D\u5B58\u5728\u6216\u5DF2\u8FC7\u671F");
4602
4634
  if (esc.resolved_path !== resolved_path) fail(400, "\u6388\u6743\u8DEF\u5F84\u4E0E\u63D0\u6743\u8BF7\u6C42\u4E0D\u4E00\u81F4");
4603
4635
  if (esc.granted !== null && esc.granted !== void 0) fail(400, "\u8BE5\u63D0\u6743\u8BF7\u6C42\u5DF2\u5904\u7406\u8FC7");
4636
+ const lastModelEntry = [...entries].reverse().find(
4637
+ (entry) => isMessageEntry(entry) && Boolean(entry.model?.trim())
4638
+ );
4639
+ const model = lastModelEntry && isMessageEntry(lastModelEntry) ? lastModelEntry.model?.trim() ?? "" : "";
4640
+ if (!model) fail(400, "\u65E0\u6CD5\u786E\u5B9A\u4F1A\u8BDD\u4F7F\u7528\u7684\u6A21\u578B\uFF0C\u8BF7\u91CD\u65B0\u53D1\u9001\u6D88\u606F");
4641
+ ctx.resolver.resolve(model);
4604
4642
  ctx.store.resolveEscalation(sessionId, escalation_id, granted);
4605
4643
  if (!granted) {
4606
4644
  const history2 = ctx.store.buildHistoryBeforeEscalation(sessionId, escalation_id);
@@ -4635,37 +4673,36 @@ function createAgentRoutes(ctx) {
4635
4673
  }
4636
4674
  }
4637
4675
  }
4638
- const { runId: runId2 } = await launchUserMessage({
4676
+ const { runId: runId2, model: resumedModel2, agentInstanceId: agentInstanceId2 } = await launchUserMessage({
4639
4677
  sessionId,
4640
4678
  content: "",
4641
- model: "",
4679
+ model,
4642
4680
  history: history2,
4643
4681
  entryCount: entries.length,
4644
4682
  recordUser: false
4645
4683
  });
4646
- return c.json(ok({ session_id: sessionId, granted: false, run_id: runId2 }, "\u5DF2\u62D2\u7EDD\u6388\u6743\uFF0C\u7531\u6A21\u578B\u7EE7\u7EED\u5E94\u7B54"), 202);
4684
+ return c.json(ok({ session_id: sessionId, granted: false, run_id: runId2, model: resumedModel2, agent_instance_id: agentInstanceId2 }, "\u5DF2\u62D2\u7EDD\u6388\u6743\uFF0C\u7531\u6A21\u578B\u7EE7\u7EED\u5E94\u7B54"), 202);
4647
4685
  }
4648
4686
  if (esc.resource_type === "command") {
4649
- ctx.grants.grantCapability(sessionId, resolved_path);
4687
+ ctx.grants.grantCapabilityOnce(sessionId, resolved_path);
4650
4688
  } else {
4651
- ctx.grants.grant(sessionId, resolved_path);
4689
+ ctx.grants.grantOnce(sessionId, resolved_path);
4652
4690
  }
4653
4691
  const lastUser = [...entries].reverse().find(
4654
4692
  (e) => isMessageEntry(e) && e.message.role === "user"
4655
4693
  );
4656
4694
  if (!lastUser || !isMessageEntry(lastUser)) fail(400, "\u4F1A\u8BDD\u4E2D\u6CA1\u6709\u53EF\u7EED\u8DD1\u7684\u7528\u6237\u6D88\u606F");
4657
- ctx.resolver.resolve("");
4658
4695
  const history = ctx.store.buildHistoryBeforeEscalation(sessionId, escalation_id);
4659
- const { messageId, runId } = await launchUserMessage({
4696
+ const { messageId, runId, model: resumedModel, agentInstanceId } = await launchUserMessage({
4660
4697
  sessionId,
4661
4698
  content: "",
4662
- model: "",
4699
+ model,
4663
4700
  history,
4664
4701
  entryCount: entries.length,
4665
4702
  recordUser: false
4666
4703
  });
4667
4704
  return c.json(
4668
- ok({ session_id: sessionId, message_id: messageId, run_id: runId, granted_path: resolved_path }, "\u5DF2\u6388\u6743\u5E76\u7EE7\u7EED\u6267\u884C"),
4705
+ ok({ session_id: sessionId, message_id: messageId, run_id: runId, model: resumedModel, agent_instance_id: agentInstanceId, granted_path: resolved_path }, "\u5DF2\u6388\u6743\u5E76\u7EE7\u7EED\u6267\u884C"),
4669
4706
  202
4670
4707
  );
4671
4708
  });