@opeoginni/opencode-copilot-auto 0.1.2 → 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/dist/index.js +28 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -22,8 +22,7 @@ function autoModel() {
|
|
|
22
22
|
api: {
|
|
23
23
|
id: "auto",
|
|
24
24
|
url: COPILOT_BASE_URL,
|
|
25
|
-
npm: "@ai-sdk/github-copilot"
|
|
26
|
-
endpoint: "responses"
|
|
25
|
+
npm: "@ai-sdk/github-copilot"
|
|
27
26
|
},
|
|
28
27
|
status: "active",
|
|
29
28
|
headers: {},
|
|
@@ -62,9 +61,13 @@ function installFetchAdapter() {
|
|
|
62
61
|
const model = await route(originalFetch, request.headers, session, payload);
|
|
63
62
|
const headers = new Headers(request.headers);
|
|
64
63
|
headers.set("copilot-session-token", session.token);
|
|
65
|
-
|
|
64
|
+
const next = usesResponses(model) ? toResponsesRequest(payload, model) : { ...payload, model };
|
|
65
|
+
const url = usesResponses(model) ? toResponsesUrl(request.url) : request.url;
|
|
66
|
+
return originalFetch(new Request(url, {
|
|
67
|
+
method: request.method,
|
|
66
68
|
headers,
|
|
67
|
-
body: JSON.stringify(
|
|
69
|
+
body: JSON.stringify(next),
|
|
70
|
+
signal: request.signal
|
|
68
71
|
}));
|
|
69
72
|
};
|
|
70
73
|
globalThis.fetch = Object.assign(adapter, originalFetch);
|
|
@@ -73,6 +76,27 @@ function isAutoRequest(request) {
|
|
|
73
76
|
const url = new URL(request.url);
|
|
74
77
|
return url.origin === COPILOT_BASE_URL && request.method === "POST" && (url.pathname.endsWith("/chat/completions") || url.pathname.endsWith("/responses"));
|
|
75
78
|
}
|
|
79
|
+
function usesResponses(modelID) {
|
|
80
|
+
const match = /^gpt-(\d+)/.exec(modelID);
|
|
81
|
+
return Boolean(match && Number(match[1]) >= 5 && !modelID.startsWith("gpt-5-mini"));
|
|
82
|
+
}
|
|
83
|
+
function toResponsesUrl(url) {
|
|
84
|
+
return url.replace(/\/chat\/completions\/?$/, "/responses");
|
|
85
|
+
}
|
|
86
|
+
function toResponsesRequest(payload, model) {
|
|
87
|
+
const messages = Array.isArray(payload.messages) ? payload.messages : undefined;
|
|
88
|
+
const input = messages ? promptText(messages) : typeof payload.input === "string" ? payload.input : promptText(payload.input);
|
|
89
|
+
return {
|
|
90
|
+
model,
|
|
91
|
+
input,
|
|
92
|
+
stream: payload.stream === true,
|
|
93
|
+
...typeof payload.temperature === "number" ? { temperature: payload.temperature } : {},
|
|
94
|
+
...typeof payload.top_p === "number" ? { top_p: payload.top_p } : {},
|
|
95
|
+
...typeof payload.max_tokens === "number" ? { max_output_tokens: payload.max_tokens } : typeof payload.max_completion_tokens === "number" ? { max_output_tokens: payload.max_completion_tokens } : {},
|
|
96
|
+
...Array.isArray(payload.tools) ? { tools: payload.tools } : {},
|
|
97
|
+
...payload.tool_choice !== undefined ? { tool_choice: payload.tool_choice } : {}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
76
100
|
async function getSession(fetcher, requestHeaders) {
|
|
77
101
|
const key = requestHeaders.get("authorization") ?? "anonymous";
|
|
78
102
|
const cached = sessions.get(key);
|