opencode-copilot-account-switcher 0.2.5 → 0.2.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.
@@ -42,9 +42,6 @@ function isAbortError(error) {
42
42
  function getErrorMessage(error) {
43
43
  return String(error instanceof Error ? error.message : error).toLowerCase();
44
44
  }
45
- function isJsonContentType(headers) {
46
- return headers.get("content-type")?.toLowerCase().includes("application/json") === true;
47
- }
48
45
  function isInputIdTooLongErrorBody(payload) {
49
46
  if (!payload || typeof payload !== "object")
50
47
  return false;
@@ -52,6 +49,10 @@ function isInputIdTooLongErrorBody(payload) {
52
49
  const message = String(error?.message ?? "").toLowerCase();
53
50
  return message.includes("invalid 'input[") && message.includes(".id'") && message.includes("string too long");
54
51
  }
52
+ function isInputIdTooLongMessage(text) {
53
+ const message = text.toLowerCase();
54
+ return message.includes("invalid 'input[") && message.includes(".id'") && message.includes("string too long");
55
+ }
55
56
  function hasLongInputIds(payload) {
56
57
  const input = payload.input;
57
58
  if (!Array.isArray(input))
@@ -110,20 +111,53 @@ async function maybeRetryInputIdTooLong(request, init, response, baseFetch) {
110
111
  if (response.status !== 400)
111
112
  return response;
112
113
  const requestPayload = parseJsonBody(init);
113
- if (!requestPayload || !hasLongInputIds(requestPayload))
114
+ if (!requestPayload || !hasLongInputIds(requestPayload)) {
115
+ debugLog("skip input-id retry: request has no long ids");
114
116
  return response;
115
- if (!isJsonContentType(response.headers))
116
- return response;
117
- const bodyPayload = await response
117
+ }
118
+ debugLog("input-id retry candidate", {
119
+ status: response.status,
120
+ contentType: response.headers.get("content-type") ?? undefined,
121
+ });
122
+ const responseText = await response
118
123
  .clone()
119
- .json()
120
- .catch(() => undefined);
121
- if (!isInputIdTooLongErrorBody(bodyPayload))
124
+ .text()
125
+ .catch(() => "");
126
+ if (!responseText) {
127
+ debugLog("skip input-id retry: empty response body");
128
+ return response;
129
+ }
130
+ let matched = isInputIdTooLongMessage(responseText);
131
+ if (!matched) {
132
+ try {
133
+ const bodyPayload = JSON.parse(responseText);
134
+ matched = isInputIdTooLongErrorBody(bodyPayload);
135
+ }
136
+ catch {
137
+ matched = false;
138
+ }
139
+ }
140
+ debugLog("input-id retry detection", {
141
+ matched,
142
+ bodyPreview: responseText.slice(0, 200),
143
+ });
144
+ if (!matched)
122
145
  return response;
123
146
  const sanitized = stripLongInputIds(requestPayload);
124
- if (sanitized === requestPayload)
147
+ if (sanitized === requestPayload) {
148
+ debugLog("skip input-id retry: sanitize made no changes");
125
149
  return response;
126
- return baseFetch(request, buildRetryInit(init, sanitized));
150
+ }
151
+ debugLog("input-id retry triggered", {
152
+ removedLongIds: true,
153
+ hadPreviousResponseId: typeof requestPayload.previous_response_id === "string",
154
+ });
155
+ const retried = await baseFetch(request, buildRetryInit(init, sanitized));
156
+ debugLog("input-id retry response", {
157
+ status: retried.status,
158
+ contentType: retried.headers.get("content-type") ?? undefined,
159
+ });
160
+ return retried;
127
161
  }
128
162
  function toRetryableSystemError(error) {
129
163
  const base = error instanceof Error ? error : new Error(String(error));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-copilot-account-switcher",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "GitHub Copilot account switcher plugin for OpenCode",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",