magpie-aws-quick-bridge 0.2.0 → 0.3.1
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.md +57 -183
- package/bin/cli.mjs +211 -0
- package/gateway/anthropic.mjs +192 -0
- package/gateway/ccswitch.mjs +38 -0
- package/gateway/responses.mjs +254 -0
- package/gateway/server.mjs +195 -0
- package/gateway/service.mjs +68 -0
- package/gateway/sse.mjs +113 -0
- package/gateway/store.mjs +118 -0
- package/index.mjs +1 -73
- package/package.json +13 -4
- package/plugin/messages.mjs +5 -4
- package/plugin/settings.mjs +78 -0
- package/plugin/toolbridge.mjs +1 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// The plugin's options and the models it lists, shared by the magpie plugin
|
|
2
|
+
// (index.mjs) and the standalone gateway (gateway/).
|
|
3
|
+
|
|
4
|
+
import { MODES, mapModel } from "./chat.mjs"
|
|
5
|
+
import * as oauth from "./oauth.mjs"
|
|
6
|
+
|
|
7
|
+
export const MODEL_NAMES = { smart: "Quick Smart", fast: "Quick Fast", balanced: "Quick Balanced", auto: "Quick Auto", advanced: "Quick Advanced" }
|
|
8
|
+
|
|
9
|
+
// "30s", "5m", "1h" or a number of seconds.
|
|
10
|
+
export function durationMs(value, fallback) {
|
|
11
|
+
if (typeof value === "number" && value > 0) return value * 1000
|
|
12
|
+
const m = /^\s*(\d+(?:\.\d+)?)\s*(ms|s|m|h)?\s*$/.exec(String(value ?? ""))
|
|
13
|
+
if (!m || !(Number(m[1]) > 0)) return fallback
|
|
14
|
+
return Number(m[1]) * { ms: 1, s: 1000, m: 60_000, h: 3_600_000 }[m[2] ?? "s"]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const text = (value, fallback = "") => (typeof value === "string" && value.trim() ? value.trim() : fallback)
|
|
18
|
+
|
|
19
|
+
// The plugin's options (plugins.json).
|
|
20
|
+
export function settings(options = {}) {
|
|
21
|
+
// 0 takes any free port
|
|
22
|
+
const port = typeof options.callback_port === "number" ? options.callback_port : Number(options.callback_port || NaN)
|
|
23
|
+
const effort = text(options.thinking_effort).toLowerCase()
|
|
24
|
+
return {
|
|
25
|
+
appVersion: text(options.app_version, "1.2.4660"),
|
|
26
|
+
surface: text(options.surface, "QUICK_WORK_DESKTOP_WINDOWS"),
|
|
27
|
+
outpostId: text(options.outpost_id),
|
|
28
|
+
workingSessionId: text(options.working_session_id),
|
|
29
|
+
timezone: text(options.timezone, "UTC"),
|
|
30
|
+
locale: text(options.locale, "en-US"),
|
|
31
|
+
thinkingEffort: ["off", "low", "medium", "high"].includes(effort) ? effort : "",
|
|
32
|
+
keepSessions: options.keep_sessions === true,
|
|
33
|
+
webSearch: options.web_search === true,
|
|
34
|
+
// false: every request starts a new thread and sends the whole conversation
|
|
35
|
+
stateful: options.stateful !== false,
|
|
36
|
+
attachments: options.attachments !== false,
|
|
37
|
+
// what a frame may weigh; Amazon Quick's limit is 64 KB (65536). 0 sends any size
|
|
38
|
+
maxFrameBytes: Number.isInteger(options.max_frame_bytes) && options.max_frame_bytes >= 0 ? options.max_frame_bytes : 60_000,
|
|
39
|
+
defaultModel: mapModel(options.default_model, "smart"),
|
|
40
|
+
requestTimeoutMs: durationMs(options.request_timeout, 5 * 60_000),
|
|
41
|
+
proxy: text(options.proxy),
|
|
42
|
+
provider: oauth.normalizedProvider(options.provider),
|
|
43
|
+
stage: oauth.normalizedStage(options.build_stage),
|
|
44
|
+
region: text(options.region),
|
|
45
|
+
callbackPort: Number.isInteger(port) && port >= 0 && port < 65536 ? port : 18080,
|
|
46
|
+
loginTimeoutMs: durationMs(options.login_timeout, 30 * 60_000),
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// The context window is what Amazon Quick reports with each turn's usage;
|
|
51
|
+
// the output limits are estimates, it publishes none.
|
|
52
|
+
export const model = (id) => ({
|
|
53
|
+
name: MODEL_NAMES[id] ?? `Quick ${id}`,
|
|
54
|
+
limit: { context: 1_000_000, output: id === "fast" ? 32_000 : 64_000 },
|
|
55
|
+
tool_call: true,
|
|
56
|
+
reasoning: true,
|
|
57
|
+
attachment: true,
|
|
58
|
+
variants: { low: {}, medium: {}, high: {} },
|
|
59
|
+
modalities: { input: ["text", "image"], output: ["text"] },
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
export const models = () => Object.fromEntries(MODES.map((id) => [id, model(id)]))
|
|
63
|
+
|
|
64
|
+
// The account's own list: its settings name the modes it may not use and
|
|
65
|
+
// say whether it has the advanced one.
|
|
66
|
+
export function accountModels(listed, account) {
|
|
67
|
+
const out = { ...listed }
|
|
68
|
+
const slots = account?.model_slots
|
|
69
|
+
const entries = Array.isArray(slots) ? slots.map((s) => [s?.id, s]) : Object.entries(slots && typeof slots === "object" ? slots : {})
|
|
70
|
+
let advanced = account?.advanced_mode_enabled === true
|
|
71
|
+
for (const [id, slot] of entries) {
|
|
72
|
+
if (typeof id !== "string" || !slot || typeof slot !== "object") continue
|
|
73
|
+
if (slot.enabled === false) delete out[id]
|
|
74
|
+
else if (id === "advanced") advanced = true
|
|
75
|
+
}
|
|
76
|
+
if (advanced && !out.advanced) out.advanced = { ...(listed.smart ?? {}), ...model("advanced"), id: "advanced" }
|
|
77
|
+
return out
|
|
78
|
+
}
|
package/plugin/toolbridge.mjs
CHANGED
|
@@ -72,6 +72,7 @@ export function buildToolBridgePrompt(tools, functions, mode, name, parallel, co
|
|
|
72
72
|
compact ? "(name(arguments): description; * marks a required argument)\n" + defs.map(signature).join("\n") : JSON.stringify(defs, null, 2),
|
|
73
73
|
"",
|
|
74
74
|
'Backend capability notice: this backend does not expose a native function-calling channel. Any earlier instruction that assumes native tool calls (for example, "use the native tool API" or "do not output tool calls as text") cannot be satisfied here. For the client tools listed above, the marker format below is the only supported mechanism. Keep all other instructions unchanged.',
|
|
75
|
+
"The caller's files, shell and working directory are on the caller's machine. This backend's own built-in tools (reading files, running code, search and the like) run on a remote service and cannot see that machine: for anything on the caller's machine use the client tools above, never the built-in ones.",
|
|
75
76
|
"To call a tool, output exactly one marker per call and no other text in that message:",
|
|
76
77
|
'<client_tool_call>{"name":"TOOL_NAME","arguments":{...}}</client_tool_call>',
|
|
77
78
|
"The caller executes the tool and returns a tool result. After receiving it, continue the task. Do not wrap a tool call in Markdown fences. Do not add prose around a tool call.",
|