@agent-proxy/agy 0.15.1 → 0.16.0
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/request.js +57 -0
- package/package.json +4 -4
package/dist/request.js
CHANGED
|
@@ -16,6 +16,61 @@ function fail(message) { throw new AgyRequestError(message); }
|
|
|
16
16
|
function record(value) {
|
|
17
17
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
18
18
|
}
|
|
19
|
+
/** AGY 保持独立转换:增补信封先提升为声明,避免进入普通历史回放。 */
|
|
20
|
+
function normalizeAdditionalTools(body) {
|
|
21
|
+
if (!Array.isArray(body.input))
|
|
22
|
+
return body;
|
|
23
|
+
const envelopes = body.input.filter((item) => record(item) && item.type === "additional_tools");
|
|
24
|
+
if (envelopes.length === 0)
|
|
25
|
+
return body;
|
|
26
|
+
if (body.tools !== undefined && !Array.isArray(body.tools))
|
|
27
|
+
fail("additional_tools 合并要求 tools 为数组");
|
|
28
|
+
const groups = [body.tools ?? []];
|
|
29
|
+
for (const envelope of envelopes) {
|
|
30
|
+
if (!Array.isArray(envelope.tools))
|
|
31
|
+
fail("additional_tools.tools 必须是数组");
|
|
32
|
+
groups.push(envelope.tools);
|
|
33
|
+
}
|
|
34
|
+
const merge = (entries, inNamespace = false) => {
|
|
35
|
+
const tools = [];
|
|
36
|
+
const indices = new Map();
|
|
37
|
+
for (const group of entries) {
|
|
38
|
+
for (const raw of group) {
|
|
39
|
+
if (!record(raw) || typeof raw.type !== "string" || !raw.type)
|
|
40
|
+
fail("additional_tools.tools 包含无效工具声明");
|
|
41
|
+
if (["function", "custom", "namespace"].includes(raw.type) && (typeof raw.name !== "string" || !raw.name)) {
|
|
42
|
+
fail("additional_tools 工具 name 必须是非空字符串");
|
|
43
|
+
}
|
|
44
|
+
if (raw.type === "function" && !record(raw.parameters))
|
|
45
|
+
fail(`additional_tools function 工具 ${String(raw.name)} 缺少对象 parameters`);
|
|
46
|
+
let tool = raw;
|
|
47
|
+
if (raw.type === "namespace") {
|
|
48
|
+
if (inNamespace || !Array.isArray(raw.tools))
|
|
49
|
+
fail("additional_tools namespace.tools 必须是工具数组且不得嵌套 namespace");
|
|
50
|
+
tool = { ...raw, tools: merge([raw.tools], true) };
|
|
51
|
+
}
|
|
52
|
+
// function/custom 共用名称身份,顶层声明优先于历史信封中的旧类型。
|
|
53
|
+
const type = tool.type === "function" || tool.type === "custom" ? "callable" : tool.type;
|
|
54
|
+
const key = JSON.stringify([type, tool.namespace ?? null, tool.name ?? null]);
|
|
55
|
+
const index = indices.get(key);
|
|
56
|
+
if (index === undefined) {
|
|
57
|
+
indices.set(key, tools.length);
|
|
58
|
+
tools.push(tool);
|
|
59
|
+
}
|
|
60
|
+
else if (tool.type === "namespace") {
|
|
61
|
+
const existing = tools[index];
|
|
62
|
+
tools[index] = { ...existing, tools: merge([existing.tools, tool.tools], true) };
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return tools;
|
|
67
|
+
};
|
|
68
|
+
return {
|
|
69
|
+
...body,
|
|
70
|
+
tools: merge(groups),
|
|
71
|
+
input: body.input.filter((item) => !record(item) || item.type !== "additional_tools"),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
19
74
|
function string(value, field) {
|
|
20
75
|
if (typeof value !== "string")
|
|
21
76
|
fail(`${field} 必须是字符串`);
|
|
@@ -476,6 +531,8 @@ function normalizeSourceItems(body, to) {
|
|
|
476
531
|
export function translateAgyRequest(body, upstreamModel, to = "responses") {
|
|
477
532
|
if (typeof upstreamModel !== "string" || !upstreamModel)
|
|
478
533
|
fail("上游模型不能为空");
|
|
534
|
+
if (to === "responses")
|
|
535
|
+
body = normalizeAdditionalTools(body);
|
|
479
536
|
body = normalizeSourceItems(body, to);
|
|
480
537
|
if (body.previous_response_id !== undefined && body.previous_response_id !== null && body.previous_response_id !== "") {
|
|
481
538
|
fail("Antigravity 不支持 previous_response_id;请提供完整 input 历史");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent-proxy/agy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "Agent Proxy agy 插件;保留基线转换行为。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
"url": "git+https://github.com/aceHubert/codex-cliproxy-gateway.git"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@agent-proxy/models": "0.
|
|
38
|
+
"@agent-proxy/models": "0.16.0"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@agent-proxy/plugin-api": "0.
|
|
41
|
+
"@agent-proxy/plugin-api": "0.16.0"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "062121f545d3391665789b2e8baae842029262be"
|
|
44
44
|
}
|