@magpie-community/opencode-agy-tui-auth 0.1.21 → 0.1.22
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/index.mjs +27 -6
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -453,6 +453,24 @@ function toolResultText(message, media) {
|
|
|
453
453
|
return `[${status} of ${message.tool_call_id ?? "a call"}]\n${partsOf(message.content, media).trim()}`
|
|
454
454
|
}
|
|
455
455
|
|
|
456
|
+
// what a chat that ends on the assistant's own words (a client going on
|
|
457
|
+
// from a cut or finished reply) is typed with, as opencode-agy-cli-auth's
|
|
458
|
+
// continuation carrier says it
|
|
459
|
+
const CONTINUE_NOTE = "(system note: the last message above is part of your own reply; continue exactly from where it stops, and do not repeat it.)"
|
|
460
|
+
|
|
461
|
+
// continued is the chat with the user's note after a last message of the
|
|
462
|
+
// assistant's that is words alone, so it ends on a message agy can answer.
|
|
463
|
+
// A last message with calls nobody answered, or with no words, or a chat
|
|
464
|
+
// in which the user never spoke, is left as it is, for the caller to
|
|
465
|
+
// refuse.
|
|
466
|
+
export function continued(messages) {
|
|
467
|
+
const last = Array.isArray(messages) ? messages.at(-1) : null
|
|
468
|
+
if (last?.role !== "assistant" || (Array.isArray(last.tool_calls) && last.tool_calls.length)) return messages
|
|
469
|
+
if (!partsOf(last.content, []).trim()) return messages
|
|
470
|
+
if (!messages.some((m) => m?.role === "user")) return messages
|
|
471
|
+
return [...messages, { role: "user", content: CONTINUE_NOTE }]
|
|
472
|
+
}
|
|
473
|
+
|
|
456
474
|
// turnOf is what goes into agy's prompt: the images and videos, attached in
|
|
457
475
|
// the order they came, and the text pasted after them, the last user
|
|
458
476
|
// message alone, or with the instructions and the conversation before it.
|
|
@@ -469,6 +487,7 @@ function toolResultText(message, media) {
|
|
|
469
487
|
// see. One in an earlier turn stays, as what was said then.
|
|
470
488
|
export function turnOf(messages, budget = INPUT_BUDGET) {
|
|
471
489
|
if (!Array.isArray(messages) || !messages.length) throw refuse("no messages")
|
|
490
|
+
messages = continued(messages)
|
|
472
491
|
// read once to weigh the turns, then again with only the kept ones, so
|
|
473
492
|
// the images are numbered as they are attached
|
|
474
493
|
const read = (list, media) => {
|
|
@@ -560,6 +579,7 @@ const GOES_ON = "\n\n[continued in the next message]"
|
|
|
560
579
|
// came, as their marks in the steps say.
|
|
561
580
|
export function seedSteps(messages, budget = INPUT_BUDGET) {
|
|
562
581
|
if (!Array.isArray(messages) || !messages.length) throw refuse("no messages")
|
|
582
|
+
messages = continued(messages)
|
|
563
583
|
const media = []
|
|
564
584
|
const system = []
|
|
565
585
|
const groups = []
|
|
@@ -1889,30 +1909,31 @@ export async function handle(home, input, init = {}) {
|
|
|
1889
1909
|
let carried = null
|
|
1890
1910
|
try {
|
|
1891
1911
|
const tools = mcpToolsOf(body)
|
|
1912
|
+
const messages = continued(body.messages)
|
|
1892
1913
|
const resumable = (await agyHelp(agy)).includes("--conversation")
|
|
1893
1914
|
let paste = null
|
|
1894
1915
|
const rebuild = () => {
|
|
1895
1916
|
try {
|
|
1896
|
-
paste = turnOf(
|
|
1917
|
+
paste = turnOf(messages)
|
|
1897
1918
|
} catch (error) {
|
|
1898
1919
|
if (!error.long || !resumable || process.env.AGY_TUI_SEED === "0") throw error
|
|
1899
1920
|
}
|
|
1900
1921
|
if (resumable && (!paste || paste.cut) && process.env.AGY_TUI_SEED !== "0") {
|
|
1901
|
-
const seeded = seedOf(home,
|
|
1922
|
+
const seeded = seedOf(home, messages)
|
|
1902
1923
|
if (seeded) return seeded
|
|
1903
1924
|
}
|
|
1904
|
-
paste ??= turnOf(
|
|
1925
|
+
paste ??= turnOf(messages)
|
|
1905
1926
|
return null
|
|
1906
1927
|
}
|
|
1907
1928
|
const start = async (c) => {
|
|
1908
1929
|
const { prompt, media } = c ?? paste
|
|
1909
1930
|
// agy attaches a video for any model, but only Gemini's see one
|
|
1910
1931
|
if (media.some((m) => kindOf(m.type) === "video") && !/^gemini-/.test(model)) throw unfit(`${model || "this model"} takes no video; a Gemini model does`)
|
|
1911
|
-
return startTurn({ agy, home, model: agyModel, prompt, media, tools, signal, conversation: c?.id ?? null, place: c?.place ?? null, messages
|
|
1932
|
+
return startTurn({ agy, home, model: agyModel, prompt, media, tools, signal, conversation: c?.id ?? null, place: c?.place ?? null, messages, scope })
|
|
1912
1933
|
}
|
|
1913
1934
|
// Local state is an optimization. A different worker can start from
|
|
1914
1935
|
// the request history alone, even if agy has lost a retained session.
|
|
1915
|
-
carried = resumable ? await carriedOn(home,
|
|
1936
|
+
carried = resumable ? await carriedOn(home, messages, { agy, model: agyModel, tools, scope }) : null
|
|
1916
1937
|
carried ??= rebuild()
|
|
1917
1938
|
for (;;) {
|
|
1918
1939
|
try {
|
|
@@ -1926,7 +1947,7 @@ export async function handle(home, input, init = {}) {
|
|
|
1926
1947
|
// Rebuild once from the full request if the old session vanished.
|
|
1927
1948
|
// If agy also ignores a newly seeded store, use the prompt it takes.
|
|
1928
1949
|
if (!previous.seeded) carried = rebuild()
|
|
1929
|
-
else paste ??= turnOf(
|
|
1950
|
+
else paste ??= turnOf(messages)
|
|
1930
1951
|
}
|
|
1931
1952
|
}
|
|
1932
1953
|
} catch (error) {
|
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.22",
|
|
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",
|