@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/{chunk-5AIZKDJO.js → chunk-KKPK4RMM.js} +57 -20
- package/dist/chunk-KKPK4RMM.js.map +1 -0
- package/dist/cli.cjs +56 -19
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.cjs +56 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-5AIZKDJO.js.map +0 -1
|
@@ -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 (
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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");
|
|
@@ -4296,6 +4328,12 @@ function createAgentRoutes(ctx) {
|
|
|
4296
4328
|
if (!esc || esc.type !== "escalation") fail(404, "\u63D0\u6743\u8BF7\u6C42\u4E0D\u5B58\u5728\u6216\u5DF2\u8FC7\u671F");
|
|
4297
4329
|
if (esc.resolved_path !== resolved_path) fail(400, "\u6388\u6743\u8DEF\u5F84\u4E0E\u63D0\u6743\u8BF7\u6C42\u4E0D\u4E00\u81F4");
|
|
4298
4330
|
if (esc.granted !== null && esc.granted !== void 0) fail(400, "\u8BE5\u63D0\u6743\u8BF7\u6C42\u5DF2\u5904\u7406\u8FC7");
|
|
4331
|
+
const lastModelEntry = [...entries].reverse().find(
|
|
4332
|
+
(entry) => isMessageEntry(entry) && Boolean(entry.model?.trim())
|
|
4333
|
+
);
|
|
4334
|
+
const model = lastModelEntry && isMessageEntry(lastModelEntry) ? lastModelEntry.model?.trim() ?? "" : "";
|
|
4335
|
+
if (!model) fail(400, "\u65E0\u6CD5\u786E\u5B9A\u4F1A\u8BDD\u4F7F\u7528\u7684\u6A21\u578B\uFF0C\u8BF7\u91CD\u65B0\u53D1\u9001\u6D88\u606F");
|
|
4336
|
+
ctx.resolver.resolve(model);
|
|
4299
4337
|
ctx.store.resolveEscalation(sessionId, escalation_id, granted);
|
|
4300
4338
|
if (!granted) {
|
|
4301
4339
|
const history2 = ctx.store.buildHistoryBeforeEscalation(sessionId, escalation_id);
|
|
@@ -4330,37 +4368,36 @@ function createAgentRoutes(ctx) {
|
|
|
4330
4368
|
}
|
|
4331
4369
|
}
|
|
4332
4370
|
}
|
|
4333
|
-
const { runId: runId2 } = await launchUserMessage({
|
|
4371
|
+
const { runId: runId2, model: resumedModel2, agentInstanceId: agentInstanceId2 } = await launchUserMessage({
|
|
4334
4372
|
sessionId,
|
|
4335
4373
|
content: "",
|
|
4336
|
-
model
|
|
4374
|
+
model,
|
|
4337
4375
|
history: history2,
|
|
4338
4376
|
entryCount: entries.length,
|
|
4339
4377
|
recordUser: false
|
|
4340
4378
|
});
|
|
4341
|
-
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);
|
|
4342
4380
|
}
|
|
4343
4381
|
if (esc.resource_type === "command") {
|
|
4344
|
-
ctx.grants.
|
|
4382
|
+
ctx.grants.grantCapabilityOnce(sessionId, resolved_path);
|
|
4345
4383
|
} else {
|
|
4346
|
-
ctx.grants.
|
|
4384
|
+
ctx.grants.grantOnce(sessionId, resolved_path);
|
|
4347
4385
|
}
|
|
4348
4386
|
const lastUser = [...entries].reverse().find(
|
|
4349
4387
|
(e) => isMessageEntry(e) && e.message.role === "user"
|
|
4350
4388
|
);
|
|
4351
4389
|
if (!lastUser || !isMessageEntry(lastUser)) fail(400, "\u4F1A\u8BDD\u4E2D\u6CA1\u6709\u53EF\u7EED\u8DD1\u7684\u7528\u6237\u6D88\u606F");
|
|
4352
|
-
ctx.resolver.resolve("");
|
|
4353
4390
|
const history = ctx.store.buildHistoryBeforeEscalation(sessionId, escalation_id);
|
|
4354
|
-
const { messageId, runId } = await launchUserMessage({
|
|
4391
|
+
const { messageId, runId, model: resumedModel, agentInstanceId } = await launchUserMessage({
|
|
4355
4392
|
sessionId,
|
|
4356
4393
|
content: "",
|
|
4357
|
-
model
|
|
4394
|
+
model,
|
|
4358
4395
|
history,
|
|
4359
4396
|
entryCount: entries.length,
|
|
4360
4397
|
recordUser: false
|
|
4361
4398
|
});
|
|
4362
4399
|
return c.json(
|
|
4363
|
-
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"),
|
|
4364
4401
|
202
|
|
4365
4402
|
);
|
|
4366
4403
|
});
|
|
@@ -4971,4 +5008,4 @@ export {
|
|
|
4971
5008
|
createAgentServer,
|
|
4972
5009
|
serveFromConfig
|
|
4973
5010
|
};
|
|
4974
|
-
//# sourceMappingURL=chunk-
|
|
5011
|
+
//# sourceMappingURL=chunk-KKPK4RMM.js.map
|