@magpie-community/opencode-agy-tui-auth 0.1.4 → 0.1.5
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/README.en.md +8 -4
- package/README.md +8 -4
- package/array-items.mjs +209 -0
- package/index.mjs +365 -70
- package/package.json +7 -2
- package/re2-pattern.mjs +606 -0
- package/tool-budget.mjs +157 -0
- package/tool-schema.mjs +672 -0
- package/tools.mjs +204 -0
package/README.en.md
CHANGED
|
@@ -12,20 +12,24 @@ Antigravity's models through agy's own interactive mode (its TUI). Each request
|
|
|
12
12
|
|
|
13
13
|
Each account has a home of its own (`~/.local/state/magpie-agy-tui/accounts/<id>`), where agy keeps its sign-in as a file. Your own `~/.gemini`, skills and MCP servers are neither used nor changed.
|
|
14
14
|
|
|
15
|
-
agy runs on its default agent, never a custom one (`--agent`), which agy 1.5.17 and newer bill at about four times the quota. The turn's folder holds an `AGENTS.md` telling the model to answer in text, an `.agents/skills.json` that leaves agy's bundled skills out, and a PreToolUse hook (`.agents/hooks.json`) that turns down every
|
|
15
|
+
agy runs on its default agent, never a custom one (`--agent`), which agy 1.5.17 and newer bill at about four times the quota. The turn's folder holds an `AGENTS.md` telling the model to answer in text, an `.agents/skills.json` that leaves agy's bundled skills out, and a PreToolUse hook (`.agents/hooks.json`) that turns down every call of agy's own tools.
|
|
16
|
+
|
|
17
|
+
## Tools
|
|
18
|
+
|
|
19
|
+
A request's tools (`tools`, function tools) are given to the model through magpie's tool server (`magpie mcp-helper`, which `tui-helper` starts): agy lists them as `mcp_magpie_<name>`, and only those get past the hook. When the model calls one, the response ends with that tool call (`finish_reason: "tool_calls"`), streamed or not, and agy waits, its turn kept, for the request that brings the call's result (`role: "tool"`, by its `tool_call_id`); the answer goes on from there in the same agy. A result that comes after the turn stopped waiting (10 minutes by default) starts a new turn, the conversation with its calls and results typed in as text. The tool server's config goes in a HOME of the turn's own, beside links to the account's, so turns of one account run side by side and the account's `mcp_config.json` is never written. `tool_choice: "none"` offers none. A tool result's text goes as it is, an image in it as an image (sent as a data: URL).
|
|
16
20
|
|
|
17
21
|
## Limits (v0.1)
|
|
18
22
|
|
|
19
|
-
- Text, images and videos: the caller's tools are not offered to the model, and a tool result is refused (400).
|
|
20
23
|
- Images (PNG, JPEG, GIF, WebP, BMP, TIFF, SVG; up to 10 MB each) and videos (MP4, MOV, WebM, AVI; up to 50 MB each), sent inline as a data: URL, go to agy as attachments, the way a file dragged into its prompt does: what agy 1.5.19's prompt attaches, at its own size limits. Images work with Gemini and Claude models, videos with Gemini models. Each file is written to the turn's folder and deleted with it.
|
|
21
24
|
- Anything else agy's prompt doesn't attach, so it is refused (400) with what it was, never dropped: a PDF, audio, a text or code file, a HEIC, a link to a file instead of the file itself, and a video for a Claude model.
|
|
22
|
-
- Each request is a new agy conversation; the conversation before it is pasted with it as text.
|
|
25
|
+
- Each request is a new agy conversation, but for a tool call's result, which goes on in the agy that made the call; the conversation before it is pasted with it as text.
|
|
23
26
|
- A streamed request gets the answer as the model writes it: agy commits each piece of the reply to its own conversation store (`conversations/<id>.db`), and the plugin reads what is new, read-only. When the store can't be read, the answer comes whole when the turn ends.
|
|
24
|
-
- It needs magpie
|
|
27
|
+
- It needs magpie 0.1.5217 or newer (with `tui-helper` and its tool server); an older magpie is told to update when a request has tools. Not yet tried on Windows.
|
|
25
28
|
|
|
26
29
|
## Options (environment)
|
|
27
30
|
|
|
28
31
|
- `AGY_PATH`: where agy is.
|
|
29
32
|
- `AGY_TUI_TURN_TIMEOUT_MS`: the longest a turn may take, 15 minutes by default.
|
|
33
|
+
- `AGY_TUI_PARK_TIMEOUT_MS`: how long a turn waits for a tool call's result, 10 minutes by default.
|
|
30
34
|
- `AGY_TUI_ATTACH_TIMEOUT_MS`: how long agy may take to attach a turn's images and videos, 15 seconds by default.
|
|
31
35
|
- `AGY_TUI_KEEP=1`: keep each turn's folder (its images and videos too) and agy's conversation, to look into a problem.
|
package/README.md
CHANGED
|
@@ -12,20 +12,24 @@
|
|
|
12
12
|
|
|
13
13
|
每个账号都有自己的 home(`~/.local/state/magpie-agy-tui/accounts/<id>`),agy 的登录信息以文件形式存在那里。你自己的 `~/.gemini`、skills 和 MCP 服务器都不会被用到,也不会被改动。
|
|
14
14
|
|
|
15
|
-
agy 运行的是它的默认 agent,不用自定义 agent(`--agent`):agy 1.5.17 起,自定义 agent 的会话大约按 4 倍额度计费。每轮的临时目录里放一个 `AGENTS.md`(让模型只用文字回答)、一个 `.agents/skills.json`(不加载 agy 自带的 skills),以及一个 PreToolUse hook(`.agents/hooks.json
|
|
15
|
+
agy 运行的是它的默认 agent,不用自定义 agent(`--agent`):agy 1.5.17 起,自定义 agent 的会话大约按 4 倍额度计费。每轮的临时目录里放一个 `AGENTS.md`(让模型只用文字回答)、一个 `.agents/skills.json`(不加载 agy 自带的 skills),以及一个 PreToolUse hook(`.agents/hooks.json`),拒绝 agy 自带工具的所有调用。
|
|
16
|
+
|
|
17
|
+
## 工具
|
|
18
|
+
|
|
19
|
+
请求里的工具(`tools`,function 工具)通过 magpie 的工具服务器(`magpie mcp-helper`,由 `tui-helper` 启动)交给模型:agy 把它们列为 `mcp_magpie_<name>`,hook 只放行这些。模型调用其中一个时,响应就以这个工具调用结束(`finish_reason: "tool_calls"`,流式和非流式都一样),agy 保留这一轮,等待带着调用结果的请求(`role: "tool"`,按 `tool_call_id` 对应),然后在同一个 agy 里继续回答。如果结果来时这一轮已经不再等待(默认 10 分钟),就开一轮新的,把对话连同其中的调用和结果整理成文字输入进去。工具服务器的配置放在本轮自己的 HOME 里,其余部分链接到账号的 home,所以同一账号的多轮可以同时运行,账号的 `mcp_config.json` 也不会被改写。`tool_choice: "none"` 时不提供工具。工具结果里的文字原样交给模型,图片(data: URL)作为图片交给模型。
|
|
16
20
|
|
|
17
21
|
## 限制(v0.1)
|
|
18
22
|
|
|
19
|
-
- 文本、图片和视频:调用方的工具不会交给模型,工具结果会被拒绝(400)。
|
|
20
23
|
- 图片(PNG、JPEG、GIF、WebP、BMP、TIFF、SVG,每张不超过 10 MB)和视频(MP4、MOV、WebM、AVI,每个不超过 50 MB)以 data: URL 内联发送,会像拖进 agy 输入框的文件一样作为附件交给 agy:正是 agy 1.5.19 输入框能附加的类型,大小限制也和 agy 自己的一样。图片适用于 Gemini 和 Claude 模型,视频只适用于 Gemini 模型。每个文件写进本轮的临时目录,随目录一起删除。
|
|
21
24
|
- 其它 agy 输入框不能附加的内容会被拒绝(400)并说明是什么,不会被悄悄丢掉:PDF、音频、文本或代码文件、HEIC、文件链接(而不是文件本身),以及发给 Claude 模型的视频。
|
|
22
|
-
- 每个请求都是一次新的 agy
|
|
25
|
+
- 每个请求都是一次新的 agy 会话(工具调用的结果除外,它会回到发起调用的那个 agy 里继续),之前的对话会整理成文字一起粘贴进去。
|
|
23
26
|
- 流式请求边生成边返回:agy 每收到模型的一段回答就写进它自己的对话库(`conversations/<id>.db`),插件只读地读出新增的部分发出去;读不到时在一轮结束后返回完整回答。
|
|
24
|
-
- 需要 magpie
|
|
27
|
+
- 需要 magpie 0.1.5217 或更新(带 `tui-helper` 及其工具服务器);magpie 太旧时,带工具的请求会提示更新 magpie。Windows 尚未测试。
|
|
25
28
|
|
|
26
29
|
## 选项(环境变量)
|
|
27
30
|
|
|
28
31
|
- `AGY_PATH`:agy 的路径。
|
|
29
32
|
- `AGY_TUI_TURN_TIMEOUT_MS`:一轮的最长时间,默认 15 分钟。
|
|
33
|
+
- `AGY_TUI_PARK_TIMEOUT_MS`:一轮等待工具调用结果的最长时间,默认 10 分钟。
|
|
30
34
|
- `AGY_TUI_ATTACH_TIMEOUT_MS`:agy 附加本轮图片和视频的最长等待时间,默认 15 秒。
|
|
31
35
|
- `AGY_TUI_KEEP=1`:保留每轮的临时目录(包括图片和视频)和 agy 的对话记录,方便排查。
|
package/array-items.mjs
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
// A copy of packages/agy-cli/array-items.mjs (each package is published alone): a
|
|
2
|
+
// change to one goes to the other.
|
|
3
|
+
// Fill a sibling `items` on array JSON Schemas so Gemini function_declarations
|
|
4
|
+
// are not rejected with `items: missing field`. Called as a tree walk after
|
|
5
|
+
// sanitizeInputSchema, so this module does not have to live inside that
|
|
6
|
+
// function (the RE2 PR also edits the end of sanitizeInputSchema).
|
|
7
|
+
|
|
8
|
+
function appendSchemaHint(node, hint) {
|
|
9
|
+
if (!hint) return
|
|
10
|
+
if (typeof node.description === "string" && node.description.trim()) {
|
|
11
|
+
if (!node.description.includes(hint)) node.description = `${node.description} (${hint})`
|
|
12
|
+
} else {
|
|
13
|
+
node.description = hint
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function nodeDeclaresArray(node) {
|
|
18
|
+
if (!node || typeof node !== "object" || Array.isArray(node)) return false
|
|
19
|
+
if (typeof node.type === "string") return node.type === "array"
|
|
20
|
+
if (Array.isArray(node.type)) return node.type.includes("array")
|
|
21
|
+
return false
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function typelessItems(items) {
|
|
25
|
+
if (items == null || items === true) return true
|
|
26
|
+
if (items === false) return false
|
|
27
|
+
if (Array.isArray(items)) return false
|
|
28
|
+
if (typeof items !== "object") return true
|
|
29
|
+
if (typeof items.$ref === "string" && items.$ref) return false
|
|
30
|
+
if (typeof items.type === "string" && items.type) return false
|
|
31
|
+
if (Array.isArray(items.type) && items.type.length) return false
|
|
32
|
+
return !items.anyOf && !items.oneOf && !items.allOf
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function cloneSchemaNode(node) {
|
|
36
|
+
if (Array.isArray(node)) return node.map((item) => cloneSchemaNode(item))
|
|
37
|
+
if (node && typeof node !== "object") return node
|
|
38
|
+
if (node && typeof node === "object") return { ...node }
|
|
39
|
+
return node
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function branchCanAcceptArray(branch) {
|
|
43
|
+
if (branch == null || branch === false) return false
|
|
44
|
+
if (branch === true) return true
|
|
45
|
+
if (typeof branch !== "object" || Array.isArray(branch)) return false
|
|
46
|
+
if (typeof branch.type === "string") return branch.type === "array"
|
|
47
|
+
if (Array.isArray(branch.type)) return branch.type.includes("array")
|
|
48
|
+
// Typeless schemas, including {}, accept arrays. Object-only keywords still
|
|
49
|
+
// accept non-objects in JSON Schema unless type is set, but a missing type
|
|
50
|
+
// must not be treated as "not an array" or an anyOf [{}] would be ignored.
|
|
51
|
+
return true
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function itemsFromCombinators(node) {
|
|
55
|
+
const collected = []
|
|
56
|
+
for (const key of ["anyOf", "oneOf", "allOf"]) {
|
|
57
|
+
if (!Array.isArray(node[key])) continue
|
|
58
|
+
let openArray = false
|
|
59
|
+
const definite = []
|
|
60
|
+
for (const branch of node[key]) {
|
|
61
|
+
if (!branchCanAcceptArray(branch)) continue
|
|
62
|
+
if (Array.isArray(branch.items)) continue
|
|
63
|
+
// An anyOf/oneOf alternative that accepts any array must not let a
|
|
64
|
+
// sibling's items become a global constraint (e.g. string items next to
|
|
65
|
+
// {} would reject [1]). allOf alternatives all apply, so typeless ones
|
|
66
|
+
// do not loosen the others.
|
|
67
|
+
if (typelessItems(branch.items)) {
|
|
68
|
+
if (key !== "allOf") openArray = true
|
|
69
|
+
continue
|
|
70
|
+
}
|
|
71
|
+
definite.push(cloneSchemaNode(branch.items))
|
|
72
|
+
}
|
|
73
|
+
if (openArray) return null
|
|
74
|
+
collected.push(...definite)
|
|
75
|
+
}
|
|
76
|
+
if (!collected.length) return null
|
|
77
|
+
const unique = []
|
|
78
|
+
const seen = new Set()
|
|
79
|
+
for (const item of collected) {
|
|
80
|
+
const sig = JSON.stringify(item)
|
|
81
|
+
if (seen.has(sig)) continue
|
|
82
|
+
seen.add(sig)
|
|
83
|
+
unique.push(item)
|
|
84
|
+
}
|
|
85
|
+
if (unique.length === 1) return unique[0]
|
|
86
|
+
return { anyOf: unique }
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function inferItemsFromExisting(existing) {
|
|
90
|
+
// Do not stamp type:"object" onto a properties-only items schema: JSON Schema
|
|
91
|
+
// would then reject non-object values that were previously allowed.
|
|
92
|
+
if (existing.properties || existing.additionalProperties !== undefined) {
|
|
93
|
+
return { ...existing }
|
|
94
|
+
}
|
|
95
|
+
if (Array.isArray(existing.enum) && existing.enum.length && !existing.type) {
|
|
96
|
+
const samples = existing.enum.filter((item) => item !== null && item !== undefined)
|
|
97
|
+
if (!samples.length) return null
|
|
98
|
+
const types = new Set(samples.map((sample) => (
|
|
99
|
+
typeof sample === "boolean" ? "boolean"
|
|
100
|
+
: typeof sample === "number" ? (Number.isInteger(sample) ? "integer" : "number")
|
|
101
|
+
: "string"
|
|
102
|
+
)))
|
|
103
|
+
if (types.has("number") && types.has("integer")) types.delete("integer")
|
|
104
|
+
if (types.size !== 1) return null
|
|
105
|
+
return { ...existing, type: [...types][0] }
|
|
106
|
+
}
|
|
107
|
+
return null
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export const PERMISSIVE_LEAF_TYPES = ["string", "number", "integer", "boolean", "object", "null"]
|
|
111
|
+
// Gemini Schema cannot express an unbounded nested array without $ref, which
|
|
112
|
+
// the translator may not honor. Eight levels is enough for tool arguments and
|
|
113
|
+
// is idempotent because the innermost array already has typed items.
|
|
114
|
+
export const PERMISSIVE_ARRAY_DEPTH = 8
|
|
115
|
+
const TUPLE_ITEMS_HINT = "tuple items were left as a list; positional tuples may not be honored"
|
|
116
|
+
const UNTYPED_ITEMS_HINT = "array items were untyped; a permissive items schema was added"
|
|
117
|
+
|
|
118
|
+
function leafSchemas() {
|
|
119
|
+
return PERMISSIVE_LEAF_TYPES.map((type) => ({ type }))
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function permissiveValueSchema(depth) {
|
|
123
|
+
const leaves = leafSchemas()
|
|
124
|
+
if (depth <= 1) {
|
|
125
|
+
return { anyOf: [...leaves, { type: "array", items: { anyOf: leaves.map((item) => ({ ...item })) } }] }
|
|
126
|
+
}
|
|
127
|
+
return { anyOf: [...leaves, { type: "array", items: permissiveValueSchema(depth - 1) }] }
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function permissiveItemSchema(existing = {}) {
|
|
131
|
+
return { ...existing, ...permissiveValueSchema(PERMISSIVE_ARRAY_DEPTH) }
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function mergeItems(fromCombo, existing) {
|
|
135
|
+
if (!existing || Object.keys(existing).length === 0) return fromCombo
|
|
136
|
+
// Keep constraints already on the typeless items node (e.g. maxLength).
|
|
137
|
+
return { ...fromCombo, ...existing }
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function fillGeminiArrayItems(node) {
|
|
141
|
+
if (!nodeDeclaresArray(node)) return
|
|
142
|
+
if (Array.isArray(node.items)) {
|
|
143
|
+
appendSchemaHint(node, TUPLE_ITEMS_HINT)
|
|
144
|
+
return
|
|
145
|
+
}
|
|
146
|
+
const existing = (node.items && typeof node.items === "object" && !Array.isArray(node.items))
|
|
147
|
+
? { ...node.items }
|
|
148
|
+
: {}
|
|
149
|
+
if (Array.isArray(node.prefixItems)) {
|
|
150
|
+
appendSchemaHint(node, TUPLE_ITEMS_HINT)
|
|
151
|
+
if (!typelessItems(node.items)) return
|
|
152
|
+
// prefixItems alone still leaves sibling items missing; fill a rest schema.
|
|
153
|
+
const fromCombo = itemsFromCombinators(node)
|
|
154
|
+
if (fromCombo) node.items = mergeItems(fromCombo, existing)
|
|
155
|
+
else {
|
|
156
|
+
const inferred = inferItemsFromExisting(existing)
|
|
157
|
+
node.items = inferred || permissiveItemSchema(existing)
|
|
158
|
+
if (!inferred) appendSchemaHint(node, UNTYPED_ITEMS_HINT)
|
|
159
|
+
}
|
|
160
|
+
return
|
|
161
|
+
}
|
|
162
|
+
if (!typelessItems(node.items)) return
|
|
163
|
+
const fromCombo = itemsFromCombinators(node)
|
|
164
|
+
if (fromCombo) {
|
|
165
|
+
node.items = mergeItems(fromCombo, existing)
|
|
166
|
+
return
|
|
167
|
+
}
|
|
168
|
+
const inferred = inferItemsFromExisting(existing)
|
|
169
|
+
if (inferred) {
|
|
170
|
+
node.items = inferred
|
|
171
|
+
return
|
|
172
|
+
}
|
|
173
|
+
node.items = permissiveItemSchema(existing)
|
|
174
|
+
appendSchemaHint(node, UNTYPED_ITEMS_HINT)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const SCHEMA_CHILD_KEYS = [
|
|
178
|
+
"additionalProperties", "propertyNames", "contains", "if", "then", "else",
|
|
179
|
+
"not", "unevaluatedProperties", "unevaluatedItems", "items",
|
|
180
|
+
]
|
|
181
|
+
const SCHEMA_ARRAY_KEYS = ["anyOf", "oneOf", "allOf", "prefixItems"]
|
|
182
|
+
const SCHEMA_MAP_KEYS = ["properties", "patternProperties", "dependentSchemas", "$defs", "definitions"]
|
|
183
|
+
|
|
184
|
+
function walk(node) {
|
|
185
|
+
if (!node || typeof node !== "object") return
|
|
186
|
+
if (Array.isArray(node)) {
|
|
187
|
+
for (const item of node) walk(item)
|
|
188
|
+
return
|
|
189
|
+
}
|
|
190
|
+
// Children first so combinator branches are filled before we copy items up.
|
|
191
|
+
for (const key of SCHEMA_CHILD_KEYS) walk(node[key])
|
|
192
|
+
for (const key of SCHEMA_ARRAY_KEYS) {
|
|
193
|
+
if (Array.isArray(node[key])) for (const item of node[key]) walk(item)
|
|
194
|
+
}
|
|
195
|
+
for (const key of SCHEMA_MAP_KEYS) {
|
|
196
|
+
const map = node[key]
|
|
197
|
+
if (map && typeof map === "object" && !Array.isArray(map)) {
|
|
198
|
+
for (const child of Object.values(map)) walk(child)
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
fillGeminiArrayItems(node)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Mutates and returns the schema tree so callers can write
|
|
205
|
+
// `ensureGeminiArrayItems(sanitizeInputSchema(raw))`.
|
|
206
|
+
export function ensureGeminiArrayItems(node) {
|
|
207
|
+
walk(node)
|
|
208
|
+
return node
|
|
209
|
+
}
|