@yachiyo-5i/xlyra-agent 1.3.1 → 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.
@@ -1791,6 +1791,7 @@ var EscalationRequiredError = class extends Error {
1791
1791
  };
1792
1792
  var EscalationGrants = class {
1793
1793
  grants = /* @__PURE__ */ new Map();
1794
+ oneShotGrants = /* @__PURE__ */ new Map();
1794
1795
  /** 会话级完全访问开关(前端 permission_mode=full 注入;ask 时撤销,不随消息残留) */
1795
1796
  fullAccess = /* @__PURE__ */ new Set();
1796
1797
  /** 完全访问模式:跳过一切路径与能力提权检查(用户已在 UI 二次确认) */
@@ -1815,24 +1816,48 @@ var EscalationGrants = class {
1815
1816
  grantCapability(sessionId, capability) {
1816
1817
  this.grant(sessionId, capability);
1817
1818
  }
1819
+ grantOnce(sessionId, resolvedPath) {
1820
+ let set = this.oneShotGrants.get(sessionId);
1821
+ if (!set) {
1822
+ set = /* @__PURE__ */ new Set();
1823
+ this.oneShotGrants.set(sessionId, set);
1824
+ }
1825
+ set.add(resolvedPath);
1826
+ }
1827
+ grantCapabilityOnce(sessionId, capability) {
1828
+ this.grantOnce(sessionId, capability);
1829
+ }
1818
1830
  /** 已授权路径或其子路径视为已放开;完全访问模式直接放行 */
1819
1831
  isGranted(sessionId, resolvedPath) {
1820
1832
  if (this.fullAccess.has(sessionId)) return true;
1821
1833
  const set = this.grants.get(sessionId);
1822
- if (!set) return false;
1823
- for (const prefix of set) {
1824
- const relative = path2.relative(prefix, resolvedPath);
1825
- if (relative === "" || !relative.startsWith("..") && !path2.isAbsolute(relative)) return true;
1834
+ if (set) {
1835
+ for (const prefix of set) {
1836
+ const relative = path2.relative(prefix, resolvedPath);
1837
+ if (relative === "" || !relative.startsWith("..") && !path2.isAbsolute(relative)) return true;
1838
+ }
1839
+ }
1840
+ const oneShot = this.oneShotGrants.get(sessionId);
1841
+ if (oneShot?.has(resolvedPath)) {
1842
+ oneShot.delete(resolvedPath);
1843
+ if (oneShot.size === 0) this.oneShotGrants.delete(sessionId);
1844
+ return true;
1826
1845
  }
1827
1846
  return false;
1828
1847
  }
1829
1848
  isCapabilityGranted(sessionId, capability) {
1830
1849
  if (this.fullAccess.has(sessionId)) return true;
1831
- return this.grants.get(sessionId)?.has(capability) ?? false;
1850
+ if (this.grants.get(sessionId)?.has(capability)) return true;
1851
+ const oneShot = this.oneShotGrants.get(sessionId);
1852
+ if (!oneShot?.has(capability)) return false;
1853
+ oneShot.delete(capability);
1854
+ if (oneShot.size === 0) this.oneShotGrants.delete(sessionId);
1855
+ return true;
1832
1856
  }
1833
1857
  /** 会话删除时清掉授权(授权随会话生命周期) */
1834
1858
  drop(sessionId) {
1835
1859
  this.grants.delete(sessionId);
1860
+ this.oneShotGrants.delete(sessionId);
1836
1861
  this.fullAccess.delete(sessionId);
1837
1862
  }
1838
1863
  };
@@ -4102,7 +4127,14 @@ function createAgentRoutes(ctx) {
4102
4127
  }
4103
4128
  );
4104
4129
  await recorder.begin(runId);
4105
- return { sessionId: args.sessionId, messageId, runId };
4130
+ const resolvedModel = ctx.resolver.resolve(args.model).modelId;
4131
+ return {
4132
+ sessionId: args.sessionId,
4133
+ messageId,
4134
+ runId,
4135
+ model: resolvedModel,
4136
+ agentInstanceId: args.agentInstanceId ?? ctx.agentInstanceId ?? "default"
4137
+ };
4106
4138
  }
4107
4139
  app.post("/sessions", async (c) => {
4108
4140
  const payload = startPayloadSchema.parse(await c.req.json());
@@ -4129,7 +4161,7 @@ function createAgentRoutes(ctx) {
4129
4161
  if (payload.permission_mode !== void 0) {
4130
4162
  ctx.grants.setFullAccess(sessionId, payload.permission_mode === "full");
4131
4163
  }
4132
- const { messageId, runId } = await launchUserMessage({
4164
+ const { messageId, runId, model, agentInstanceId } = await launchUserMessage({
4133
4165
  sessionId,
4134
4166
  content: payload.content,
4135
4167
  model: payload.model,
@@ -4141,7 +4173,7 @@ function createAgentRoutes(ctx) {
4141
4173
  },
4142
4174
  ...payload.agent_instance_id ? { agentInstanceId: payload.agent_instance_id } : {}
4143
4175
  });
4144
- return c.json(ok({ session_id: sessionId, message_id: messageId, run_id: runId }, "\u7528\u6237\u6D88\u606F\u5DF2\u63D0\u4EA4"), 202);
4176
+ 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);
4145
4177
  });
4146
4178
  app.get("/sessions", (c) => {
4147
4179
  const limit = Math.min(Number(c.req.query("limit") ?? 50), 200);
@@ -4264,7 +4296,7 @@ function createAgentRoutes(ctx) {
4264
4296
  ctx.store.discardFromUserMessage(sessionId, payload.message_id);
4265
4297
  const history = ctx.store.buildHistory(sessionId);
4266
4298
  const remaining = ctx.store.read(sessionId).entries.length;
4267
- const { messageId, runId } = await launchUserMessage({
4299
+ const { messageId, runId, model, agentInstanceId } = await launchUserMessage({
4268
4300
  sessionId,
4269
4301
  content,
4270
4302
  model: payload.model,
@@ -4277,7 +4309,7 @@ function createAgentRoutes(ctx) {
4277
4309
  },
4278
4310
  ...payload.agent_instance_id ? { agentInstanceId: payload.agent_instance_id } : {}
4279
4311
  });
4280
- return c.json(ok({ session_id: sessionId, message_id: messageId, run_id: runId }, "\u5DF2\u91CD\u65B0\u63D0\u4EA4"), 202);
4312
+ return c.json(ok({ session_id: sessionId, message_id: messageId, run_id: runId, model, agent_instance_id: agentInstanceId }, "\u5DF2\u91CD\u65B0\u63D0\u4EA4"), 202);
4281
4313
  });
4282
4314
  app.post("/sessions/:id/grant-access", async (c) => {
4283
4315
  const sessionId = c.req.param("id");
@@ -4336,7 +4368,7 @@ function createAgentRoutes(ctx) {
4336
4368
  }
4337
4369
  }
4338
4370
  }
4339
- const { runId: runId2 } = await launchUserMessage({
4371
+ const { runId: runId2, model: resumedModel2, agentInstanceId: agentInstanceId2 } = await launchUserMessage({
4340
4372
  sessionId,
4341
4373
  content: "",
4342
4374
  model,
@@ -4344,19 +4376,19 @@ function createAgentRoutes(ctx) {
4344
4376
  entryCount: entries.length,
4345
4377
  recordUser: false
4346
4378
  });
4347
- 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);
4379
+ 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);
4348
4380
  }
4349
4381
  if (esc.resource_type === "command") {
4350
- ctx.grants.grantCapability(sessionId, resolved_path);
4382
+ ctx.grants.grantCapabilityOnce(sessionId, resolved_path);
4351
4383
  } else {
4352
- ctx.grants.grant(sessionId, resolved_path);
4384
+ ctx.grants.grantOnce(sessionId, resolved_path);
4353
4385
  }
4354
4386
  const lastUser = [...entries].reverse().find(
4355
4387
  (e) => isMessageEntry(e) && e.message.role === "user"
4356
4388
  );
4357
4389
  if (!lastUser || !isMessageEntry(lastUser)) fail(400, "\u4F1A\u8BDD\u4E2D\u6CA1\u6709\u53EF\u7EED\u8DD1\u7684\u7528\u6237\u6D88\u606F");
4358
4390
  const history = ctx.store.buildHistoryBeforeEscalation(sessionId, escalation_id);
4359
- const { messageId, runId } = await launchUserMessage({
4391
+ const { messageId, runId, model: resumedModel, agentInstanceId } = await launchUserMessage({
4360
4392
  sessionId,
4361
4393
  content: "",
4362
4394
  model,
@@ -4365,7 +4397,7 @@ function createAgentRoutes(ctx) {
4365
4397
  recordUser: false
4366
4398
  });
4367
4399
  return c.json(
4368
- ok({ session_id: sessionId, message_id: messageId, run_id: runId, granted_path: resolved_path }, "\u5DF2\u6388\u6743\u5E76\u7EE7\u7EED\u6267\u884C"),
4400
+ 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"),
4369
4401
  202
4370
4402
  );
4371
4403
  });
@@ -4976,4 +5008,4 @@ export {
4976
5008
  createAgentServer,
4977
5009
  serveFromConfig
4978
5010
  };
4979
- //# sourceMappingURL=chunk-BOTYL4W5.js.map
5011
+ //# sourceMappingURL=chunk-KKPK4RMM.js.map