@magpie-community/opencode-agy-tui-auth 0.1.5 → 0.1.6
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 +1 -1
- package/README.md +1 -1
- package/index.mjs +56 -25
- package/live.mjs +36 -15
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -23,7 +23,7 @@ A request's tools (`tools`, function tools) are given to the model through magpi
|
|
|
23
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.
|
|
24
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.
|
|
25
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.
|
|
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.
|
|
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. The model's thinking (agy asks Gemini for it) comes the same way, as `reasoning_content`, before the answer; not streamed, it is the message's `reasoning_content`. The response ends when the answer is whole, without waiting for agy to exit (it sends its own telemetry on the way out).
|
|
27
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.
|
|
28
28
|
|
|
29
29
|
## Options (environment)
|
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ agy 运行的是它的默认 agent,不用自定义 agent(`--agent`):agy
|
|
|
23
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 模型。每个文件写进本轮的临时目录,随目录一起删除。
|
|
24
24
|
- 其它 agy 输入框不能附加的内容会被拒绝(400)并说明是什么,不会被悄悄丢掉:PDF、音频、文本或代码文件、HEIC、文件链接(而不是文件本身),以及发给 Claude 模型的视频。
|
|
25
25
|
- 每个请求都是一次新的 agy 会话(工具调用的结果除外,它会回到发起调用的那个 agy 里继续),之前的对话会整理成文字一起粘贴进去。
|
|
26
|
-
- 流式请求边生成边返回:agy 每收到模型的一段回答就写进它自己的对话库(`conversations/<id>.db
|
|
26
|
+
- 流式请求边生成边返回:agy 每收到模型的一段回答就写进它自己的对话库(`conversations/<id>.db`),插件只读地读出新增的部分发出去;读不到时在一轮结束后返回完整回答。模型的思考(agy 向 Gemini 要了思考内容)同样边生成边作为 `reasoning_content` 返回,在回答之前;非流式时放在消息的 `reasoning_content` 里。回答写完就结束响应,不等 agy 退出(它退出前会先发完自己的遥测)。
|
|
27
27
|
- 需要 magpie 0.1.5217 或更新(带 `tui-helper` 及其工具服务器);magpie 太旧时,带工具的请求会提示更新 magpie。Windows 尚未测试。
|
|
28
28
|
|
|
29
29
|
## 选项(环境变量)
|
package/index.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import path from "node:path"
|
|
|
6
6
|
import { startLogin } from "./login.mjs"
|
|
7
7
|
import { writeDefaultAgentFiles } from "./default-agent.mjs"
|
|
8
8
|
import { agyTooOld, MIN_AGY_VERSION } from "./agy-version.mjs"
|
|
9
|
-
import {
|
|
9
|
+
import { liveReply } from "./live.mjs"
|
|
10
10
|
import { mcpToolsOf } from "./tools.mjs"
|
|
11
11
|
|
|
12
12
|
// agy-tui: Antigravity's models through agy's own interactive mode. Each
|
|
@@ -46,6 +46,18 @@ const MCP_FUNCTIONS = `mcp_${MCP_SERVER}_*`
|
|
|
46
46
|
const TOOL_INSTRUCTIONS = `agy's own tools are turned off in this session. The user's tools are given to you as ${MCP_FUNCTIONS.slice(0, -1)}<name>: each is the tool the conversation calls <name>, run on the user's computer. Call them when the task needs one.`
|
|
47
47
|
|
|
48
48
|
// What agy 1.5's footer says: waiting for a message, and in a turn.
|
|
49
|
+
// the turns whose agy is on its way out, after their client had the end
|
|
50
|
+
const going = new Set()
|
|
51
|
+
const leaving = (p) => {
|
|
52
|
+
going.add(p)
|
|
53
|
+
return p.finally(() => going.delete(p))
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// settled is when every turn's agy has gone and its files with it
|
|
57
|
+
export async function settled() {
|
|
58
|
+
while (going.size) await Promise.allSettled([...going])
|
|
59
|
+
}
|
|
60
|
+
|
|
49
61
|
export const READY = "? for shortcuts"
|
|
50
62
|
export const BUSY = "esc to cancel"
|
|
51
63
|
|
|
@@ -621,13 +633,16 @@ export async function startTurn({ agy, home, model, prompt, media = [], tools =
|
|
|
621
633
|
found = answerOf(brain, before, prompt, found?.id)
|
|
622
634
|
if (found?.id) claimed.add(found.id)
|
|
623
635
|
}
|
|
624
|
-
// what the model has said so far, from agy's
|
|
625
|
-
// (live.mjs), for a stream to send as it comes
|
|
626
|
-
const live = { text: "", listeners: new Set() }
|
|
627
|
-
const publish = (
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
636
|
+
// what the model has said so far, its text and its thinking, from agy's
|
|
637
|
+
// conversation store (live.mjs), for a stream to send as it comes
|
|
638
|
+
const live = { text: "", thinking: "", listeners: new Set() }
|
|
639
|
+
const publish = (reply) => {
|
|
640
|
+
let grew = false
|
|
641
|
+
for (const k of ["text", "thinking"]) {
|
|
642
|
+
const v = reply?.[k]
|
|
643
|
+
if (typeof v === "string" && v.length > live[k].length) { live[k] = v; grew = true }
|
|
644
|
+
}
|
|
645
|
+
if (grew) for (const fn of live.listeners) fn()
|
|
631
646
|
}
|
|
632
647
|
|
|
633
648
|
let buf = ""
|
|
@@ -648,7 +663,7 @@ export async function startTurn({ agy, home, model, prompt, media = [], tools =
|
|
|
648
663
|
// what the model wrote before the call goes first
|
|
649
664
|
pending.add(o.call.id)
|
|
650
665
|
if (!found?.id) look()
|
|
651
|
-
if (found?.id) publish(
|
|
666
|
+
if (found?.id) publish(liveReply(home, found.id))
|
|
652
667
|
stop({ call: o.call })
|
|
653
668
|
}
|
|
654
669
|
if (o.dropped) pending.delete(o.dropped)
|
|
@@ -744,8 +759,10 @@ export async function startTurn({ agy, home, model, prompt, media = [], tools =
|
|
|
744
759
|
|
|
745
760
|
const turn = {
|
|
746
761
|
live,
|
|
747
|
-
// the reply's text the client has had, in the responses
|
|
762
|
+
// the reply's text and thinking the client has had, in the responses
|
|
763
|
+
// before this one
|
|
748
764
|
sent: "",
|
|
765
|
+
thought: "",
|
|
749
766
|
ended: false,
|
|
750
767
|
next: async () => {
|
|
751
768
|
while (!stops.length) await new Promise((r) => { wake = r })
|
|
@@ -782,7 +799,7 @@ export async function startTurn({ agy, home, model, prompt, media = [], tools =
|
|
|
782
799
|
if (Date.now() - polled >= LIVE_POLL_MS) {
|
|
783
800
|
polled = Date.now()
|
|
784
801
|
if (!found?.id) look()
|
|
785
|
-
if (found?.id) publish(
|
|
802
|
+
if (found?.id) publish(liveReply(home, found.id))
|
|
786
803
|
}
|
|
787
804
|
return false
|
|
788
805
|
}
|
|
@@ -793,17 +810,18 @@ export async function startTurn({ agy, home, model, prompt, media = [], tools =
|
|
|
793
810
|
}, () => until)
|
|
794
811
|
if (!found?.answer) throw new Failure(502, `agy answered nothing${screenTail(screen) ? `:\n${screenTail(screen)}` : ""}`)
|
|
795
812
|
// the whole of it, read before the conversation goes
|
|
796
|
-
publish(
|
|
813
|
+
publish(liveReply(home, found.id))
|
|
797
814
|
last = { text: found.answer }
|
|
798
815
|
} catch (error) {
|
|
799
816
|
last = { error }
|
|
800
817
|
} finally {
|
|
801
|
-
// the end is told once
|
|
818
|
+
// the end is told at once: agy's exit can wait on its own network
|
|
819
|
+
// (a telemetry flush on the way out), and the client needn't. The
|
|
820
|
+
// turn's files go after, once agy has.
|
|
802
821
|
turn.ended = true
|
|
803
822
|
watch(null)
|
|
804
|
-
await cleanup()
|
|
805
|
-
forget(brain, found?.id)
|
|
806
823
|
stop(last)
|
|
824
|
+
await leaving(cleanup().then(() => forget(brain, found?.id)))
|
|
807
825
|
}
|
|
808
826
|
})()
|
|
809
827
|
return turn
|
|
@@ -885,15 +903,17 @@ function jsonError(status, message, headers = {}) {
|
|
|
885
903
|
const toolCallOf = (call, index) => ({ ...(index === undefined ? {} : { index }), id: call.id, type: "function", function: { name: call.name, arguments: JSON.stringify(call.arguments ?? {}) } })
|
|
886
904
|
|
|
887
905
|
// since is what of text is new to this response: past what the turn's
|
|
888
|
-
// earlier responses had, without the break
|
|
889
|
-
|
|
890
|
-
|
|
906
|
+
// earlier responses had (`had`, the text's by default), without the break
|
|
907
|
+
// before it
|
|
908
|
+
function since(turn, text, had = turn.sent) {
|
|
909
|
+
return text.startsWith(had) ? text.slice(had.length).replace(/^\n+/, "") : ""
|
|
891
910
|
}
|
|
892
911
|
|
|
893
912
|
// stopped ends a response at a call: the turn waits for its result
|
|
894
913
|
function stopped(turn, call) {
|
|
895
914
|
turn.watch(null)
|
|
896
915
|
turn.sent = turn.live.text
|
|
916
|
+
turn.thought = turn.live.thinking
|
|
897
917
|
park(call.id, turn)
|
|
898
918
|
}
|
|
899
919
|
|
|
@@ -911,12 +931,14 @@ function completion(id, model, message, finish) {
|
|
|
911
931
|
async function answered(id, model, turn) {
|
|
912
932
|
const s = await turn.next()
|
|
913
933
|
if (s.error) throw s.error
|
|
934
|
+
const thinking = since(turn, turn.live.thinking, turn.thought)
|
|
935
|
+
const reasoning = thinking ? { reasoning_content: thinking } : {}
|
|
914
936
|
if (s.call) {
|
|
915
937
|
const text = since(turn, turn.live.text)
|
|
916
938
|
stopped(turn, s.call)
|
|
917
|
-
return completion(id, model, { content: text || null, tool_calls: [toolCallOf(s.call)] }, "tool_calls")
|
|
939
|
+
return completion(id, model, { content: text || null, ...reasoning, tool_calls: [toolCallOf(s.call)] }, "tool_calls")
|
|
918
940
|
}
|
|
919
|
-
return completion(id, model, { content: turn.sent ? since(turn, turn.live.text) || s.text : s.text }, "stop")
|
|
941
|
+
return completion(id, model, { content: turn.sent ? since(turn, turn.live.text) || s.text : s.text, ...reasoning }, "stop")
|
|
920
942
|
}
|
|
921
943
|
|
|
922
944
|
// streamOf sends the turn's reply up to its next stop as agy's model
|
|
@@ -938,10 +960,19 @@ export function streamOf(id, model, turn) {
|
|
|
938
960
|
return new ReadableStream({
|
|
939
961
|
async start(c) {
|
|
940
962
|
let sent = ""
|
|
963
|
+
let thought = ""
|
|
941
964
|
// only what continues what was sent: agy writing a reply over is
|
|
942
|
-
// left to the end
|
|
943
|
-
|
|
944
|
-
|
|
965
|
+
// left to the end. The thinking goes as it comes, as
|
|
966
|
+
// reasoning_content, so a model that thinks a while before its first
|
|
967
|
+
// word shows it from the first thought
|
|
968
|
+
const send = () => {
|
|
969
|
+
const think = since(turn, live.thinking, turn.thought)
|
|
970
|
+
if (think.length > thought.length && think.startsWith(thought)) {
|
|
971
|
+
try { c.enqueue(enc.encode(chunk({ reasoning_content: think.slice(thought.length) }))) } catch { return }
|
|
972
|
+
thought = think
|
|
973
|
+
quiet = Date.now()
|
|
974
|
+
}
|
|
975
|
+
const full = since(turn, live.text)
|
|
945
976
|
if (full.length <= sent.length || !full.startsWith(sent)) return
|
|
946
977
|
try { c.enqueue(enc.encode(chunk({ content: full.slice(sent.length) }))) } catch { return }
|
|
947
978
|
sent = full
|
|
@@ -951,7 +982,7 @@ export function streamOf(id, model, turn) {
|
|
|
951
982
|
quiet = Date.now()
|
|
952
983
|
listen = send
|
|
953
984
|
live.listeners.add(listen)
|
|
954
|
-
send(
|
|
985
|
+
send()
|
|
955
986
|
// the turn may take minutes before its first word: a comment now
|
|
956
987
|
// and then keeps the connection from looking dead
|
|
957
988
|
keep = setInterval(() => {
|
|
@@ -963,7 +994,7 @@ export function streamOf(id, model, turn) {
|
|
|
963
994
|
const s = await turn.next()
|
|
964
995
|
halt()
|
|
965
996
|
if (s.error) throw s.error
|
|
966
|
-
send(
|
|
997
|
+
send()
|
|
967
998
|
if (s.call) {
|
|
968
999
|
stopped(turn, s.call)
|
|
969
1000
|
c.enqueue(enc.encode(chunk({ tool_calls: [toolCallOf(s.call, 0)] })))
|
package/live.mjs
CHANGED
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
// model's reply there as each piece of it arrives: a row of `steps` with
|
|
5
5
|
// step_type 15 (the PLANNER_RESPONSE the transcript gets at the end),
|
|
6
6
|
// status 8 while it comes and 3 once whole, its text, as the model wrote
|
|
7
|
-
// it, in field 20.1 of step_payload
|
|
7
|
+
// it, in field 20.1 of step_payload, and its thinking (the thought parts
|
|
8
|
+
// Gemini streams before the text, which agy asks for with includeThoughts)
|
|
9
|
+
// in field 20.3, filled in first. The transcript is written only when
|
|
8
10
|
// the reply is whole, and the screen shows it drawn (markup taken out,
|
|
9
11
|
// lines wrapped), so this is the one place the reply can be read as it
|
|
10
12
|
// comes. Read-only, never waiting on a lock; anything unreadable is null,
|
|
@@ -104,23 +106,35 @@ function fields(buf, fn) {
|
|
|
104
106
|
|
|
105
107
|
const bytesOf = (v) => v instanceof Uint8Array ? v : ArrayBuffer.isView(v) ? new Uint8Array(v.buffer, v.byteOffset, v.byteLength) : v instanceof ArrayBuffer ? new Uint8Array(v) : null
|
|
106
108
|
|
|
107
|
-
//
|
|
108
|
-
// "" when it has none yet
|
|
109
|
-
|
|
109
|
+
// stepOf is a PLANNER_RESPONSE step's text (field 20.1 of its payload)
|
|
110
|
+
// and thinking (field 20.3), each "" when it has none yet; null when the
|
|
111
|
+
// payload isn't one.
|
|
112
|
+
export function stepOf(payload) {
|
|
110
113
|
const buf = bytesOf(payload)
|
|
111
114
|
if (!buf) return null
|
|
112
115
|
let response = null
|
|
113
116
|
if (!fields(buf, (f, w, v) => { if (f === 20 && w === 2) response = v })) return null
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
117
|
+
const step = { text: "", thinking: "" }
|
|
118
|
+
if (!response) return step
|
|
119
|
+
const dec = new TextDecoder()
|
|
120
|
+
if (!fields(response, (f, w, v) => {
|
|
121
|
+
if (w !== 2) return
|
|
122
|
+
if (f === 1) step.text = dec.decode(v)
|
|
123
|
+
else if (f === 3) step.thinking = dec.decode(v)
|
|
124
|
+
})) return null
|
|
125
|
+
return step
|
|
118
126
|
}
|
|
119
127
|
|
|
120
|
-
//
|
|
121
|
-
// the
|
|
122
|
-
|
|
123
|
-
|
|
128
|
+
// replyOf is a PLANNER_RESPONSE step's text, "" when it has none yet, null
|
|
129
|
+
// when the payload isn't one.
|
|
130
|
+
export function replyOf(payload) {
|
|
131
|
+
return stepOf(payload)?.text ?? null
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// liveReply is what agy's model has said so far in the conversation id of
|
|
135
|
+
// the account at home: { text, thinking }, each the replies' own, in
|
|
136
|
+
// order, a blank line between two; null when the store can't be read.
|
|
137
|
+
export function liveReply(home, id) {
|
|
124
138
|
const file = conversationDb(home, id)
|
|
125
139
|
if (!file || !fs.existsSync(file)) return null
|
|
126
140
|
const open = loadOpener()
|
|
@@ -130,14 +144,21 @@ export function liveText(home, id) {
|
|
|
130
144
|
db = open(file)
|
|
131
145
|
const rows = db.all(`SELECT idx, step_payload FROM steps WHERE step_type = ${MODEL_STEP} ORDER BY idx`)
|
|
132
146
|
const texts = []
|
|
147
|
+
const thoughts = []
|
|
133
148
|
for (const row of rows) {
|
|
134
|
-
const
|
|
135
|
-
if (text) texts.push(text)
|
|
149
|
+
const step = stepOf(row.step_payload)
|
|
150
|
+
if (step?.text) texts.push(step.text)
|
|
151
|
+
if (step?.thinking) thoughts.push(step.thinking)
|
|
136
152
|
}
|
|
137
|
-
return texts.join("\n\n")
|
|
153
|
+
return { text: texts.join("\n\n"), thinking: thoughts.join("\n\n") }
|
|
138
154
|
} catch {
|
|
139
155
|
return null
|
|
140
156
|
} finally {
|
|
141
157
|
try { db?.close() } catch {}
|
|
142
158
|
}
|
|
143
159
|
}
|
|
160
|
+
|
|
161
|
+
// liveText is liveReply's text alone.
|
|
162
|
+
export function liveText(home, id) {
|
|
163
|
+
return liveReply(home, id)?.text ?? null
|
|
164
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@magpie-community/opencode-agy-tui-auth",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Magpie/OpenCode model provider that runs Antigravity's models through agy's own interactive mode: each request is typed into the real agy TUI and its answer streamed from agy's own conversation store as the model writes it",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./opencode.mjs",
|