codex-copilot-dx 0.6.5 → 0.6.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.md +2 -2
- package/bin/cli.mjs +1 -0
- package/package.json +1 -1
- package/scripts/benchmark.mjs +58 -1
- package/src/adapter.mjs +1 -0
- package/src/cli-auth.mjs +2 -11
- package/src/cli-models.mjs +14 -7
- package/src/copilot-client.mjs +3 -1
- package/src/doctor.mjs +9 -8
- package/src/http-transport.mjs +114 -13
- package/src/image-optimization.mjs +33 -11
- package/src/legacy-command-warning.mjs +3 -2
- package/src/models.mjs +14 -10
- package/src/observability.mjs +18 -1
- package/src/pm-studio-setup.mjs +28 -4
- package/src/pm-studio-status.mjs +103 -9
- package/src/profile-routing.mjs +7 -16
- package/src/profile-runtime.mjs +12 -3
- package/src/response-history.mjs +12 -2
- package/src/responses-byte-budget.mjs +53 -26
- package/src/responses-chat-payload.mjs +35 -16
- package/src/responses-content.mjs +36 -4
- package/src/responses-handler.mjs +47 -27
- package/src/responses-image-limit.mjs +16 -2
- package/src/responses-image-pressure.mjs +10 -4
- package/src/responses-request.mjs +28 -10
|
@@ -54,6 +54,7 @@ function addPartContainer(records, refs, parts, options) {
|
|
|
54
54
|
};
|
|
55
55
|
let found = false;
|
|
56
56
|
for (let partIndex = 0; partIndex < parts.length; partIndex += 1) {
|
|
57
|
+
if ((partIndex & 63) === 0) options.assertActive?.();
|
|
57
58
|
const part = parts[partIndex];
|
|
58
59
|
if (!isImagePart(part)) continue;
|
|
59
60
|
found = true;
|
|
@@ -68,7 +69,7 @@ function addPartContainer(records, refs, parts, options) {
|
|
|
68
69
|
if (found) records.push(record);
|
|
69
70
|
}
|
|
70
71
|
|
|
71
|
-
function collectImages(inputItems) {
|
|
72
|
+
function collectImages(inputItems, assertActive) {
|
|
72
73
|
const records = [];
|
|
73
74
|
const refs = [];
|
|
74
75
|
const topLevelRecord = {
|
|
@@ -81,6 +82,7 @@ function collectImages(inputItems) {
|
|
|
81
82
|
let hasTopLevelImages = false;
|
|
82
83
|
|
|
83
84
|
for (let itemIndex = 0; itemIndex < inputItems.length; itemIndex += 1) {
|
|
85
|
+
if ((itemIndex & 63) === 0) assertActive?.();
|
|
84
86
|
const item = inputItems[itemIndex];
|
|
85
87
|
if (!item || typeof item !== "object") continue;
|
|
86
88
|
|
|
@@ -96,6 +98,7 @@ function collectImages(inputItems) {
|
|
|
96
98
|
|
|
97
99
|
if (item.type === "message") {
|
|
98
100
|
addPartContainer(records, refs, item.content, {
|
|
101
|
+
assertActive,
|
|
99
102
|
kind: "message",
|
|
100
103
|
role: item.role,
|
|
101
104
|
itemIndex,
|
|
@@ -105,6 +108,7 @@ function collectImages(inputItems) {
|
|
|
105
108
|
const toolOutput = readResponsesToolOutputParts(item);
|
|
106
109
|
if (!toolOutput) continue;
|
|
107
110
|
addPartContainer(records, refs, toolOutput.parts, {
|
|
111
|
+
assertActive,
|
|
108
112
|
kind: "tool-output",
|
|
109
113
|
itemIndex,
|
|
110
114
|
commit: toolOutput.commit,
|
|
@@ -138,6 +142,7 @@ function applyDrops(records, refs, dropped, maxImages) {
|
|
|
138
142
|
}
|
|
139
143
|
|
|
140
144
|
export function enforceResponsesImageLimit(inputItems, {
|
|
145
|
+
assertActive,
|
|
141
146
|
currentInputStart = 0,
|
|
142
147
|
maxImages = MAX_UPSTREAM_IMAGES,
|
|
143
148
|
beforeMutate = () => {},
|
|
@@ -149,7 +154,8 @@ export function enforceResponsesImageLimit(inputItems, {
|
|
|
149
154
|
return { total: 0, kept: 0, omitted: 0, duplicates: 0, historicalOmitted: 0, currentOmitted: 0 };
|
|
150
155
|
}
|
|
151
156
|
|
|
152
|
-
|
|
157
|
+
assertActive?.();
|
|
158
|
+
const { records, refs } = collectImages(inputItems, assertActive);
|
|
153
159
|
if (refs.length <= limit) {
|
|
154
160
|
return { total: refs.length, kept: refs.length, omitted: 0, duplicates: 0, historicalOmitted: 0, currentOmitted: 0 };
|
|
155
161
|
}
|
|
@@ -161,6 +167,7 @@ export function enforceResponsesImageLimit(inputItems, {
|
|
|
161
167
|
let duplicates = 0;
|
|
162
168
|
|
|
163
169
|
for (let index = refs.length - 1; index >= 0; index -= 1) {
|
|
170
|
+
if ((index & 63) === 0) assertActive?.();
|
|
164
171
|
const identity = refs[index].identity;
|
|
165
172
|
if (!identity) continue;
|
|
166
173
|
let seen = seenByKind.get(identity.kind);
|
|
@@ -177,6 +184,7 @@ export function enforceResponsesImageLimit(inputItems, {
|
|
|
177
184
|
|
|
178
185
|
duplicateCandidates.sort((left, right) => left - right);
|
|
179
186
|
for (const index of duplicateCandidates) {
|
|
187
|
+
if ((kept & 63) === 0) assertActive?.();
|
|
180
188
|
if (kept <= limit) break;
|
|
181
189
|
dropped.add(index);
|
|
182
190
|
kept -= 1;
|
|
@@ -184,6 +192,7 @@ export function enforceResponsesImageLimit(inputItems, {
|
|
|
184
192
|
}
|
|
185
193
|
|
|
186
194
|
for (let index = 0; index < refs.length && kept > limit; index += 1) {
|
|
195
|
+
if ((index & 63) === 0) assertActive?.();
|
|
187
196
|
if (dropped.has(index)) continue;
|
|
188
197
|
dropped.add(index);
|
|
189
198
|
kept -= 1;
|
|
@@ -191,12 +200,17 @@ export function enforceResponsesImageLimit(inputItems, {
|
|
|
191
200
|
|
|
192
201
|
let historicalOmitted = 0;
|
|
193
202
|
let currentOmitted = 0;
|
|
203
|
+
let omittedIndex = 0;
|
|
194
204
|
for (const index of dropped) {
|
|
205
|
+
if ((omittedIndex & 63) === 0) assertActive?.();
|
|
206
|
+
omittedIndex += 1;
|
|
195
207
|
if (refs[index].itemIndex >= currentInputStart) currentOmitted += 1;
|
|
196
208
|
else historicalOmitted += 1;
|
|
197
209
|
}
|
|
198
210
|
beforeMutate({ historicalOmitted, currentOmitted });
|
|
211
|
+
assertActive?.();
|
|
199
212
|
applyDrops(records, refs, dropped, limit);
|
|
213
|
+
assertActive?.();
|
|
200
214
|
|
|
201
215
|
return {
|
|
202
216
|
total: refs.length,
|
|
@@ -18,12 +18,15 @@ function normalizedPolicy(policy = {}) {
|
|
|
18
18
|
return { ...DEFAULT_RESPONSES_IMAGE_PRESSURE_POLICY, ...policy };
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
function bodyPayload(body) {
|
|
21
|
+
function bodyPayload(body, assertActive) {
|
|
22
|
+
assertActive?.();
|
|
22
23
|
const bodyText = JSON.stringify(body);
|
|
24
|
+
assertActive?.();
|
|
23
25
|
return { bodyText, bodyBytes: Buffer.byteLength(bodyText) };
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
export function applyResponsesImagePressure(reqContext, {
|
|
29
|
+
assertActive,
|
|
27
30
|
mode = "normal",
|
|
28
31
|
policy: policyOverrides,
|
|
29
32
|
} = {}) {
|
|
@@ -32,7 +35,8 @@ export function applyResponsesImagePressure(reqContext, {
|
|
|
32
35
|
const currentInputStart = Number.isFinite(reqContext?.currentInputStart)
|
|
33
36
|
? reqContext.currentInputStart
|
|
34
37
|
: 0;
|
|
35
|
-
|
|
38
|
+
assertActive?.();
|
|
39
|
+
const initialImages = responsesHistoricalImageStats(body?.input, currentInputStart, { assertActive });
|
|
36
40
|
if (initialImages.historicalImages === 0) {
|
|
37
41
|
return {
|
|
38
42
|
mode: "normal",
|
|
@@ -49,7 +53,7 @@ export function applyResponsesImagePressure(reqContext, {
|
|
|
49
53
|
};
|
|
50
54
|
}
|
|
51
55
|
|
|
52
|
-
const initial = bodyPayload(body);
|
|
56
|
+
const initial = bodyPayload(body, assertActive);
|
|
53
57
|
const pressureEligible = initialImages.historicalImages > 0 && (
|
|
54
58
|
initialImages.historicalImages > policy.triggerHistoricalImages
|
|
55
59
|
|| initial.bodyBytes > policy.triggerBodyBytes
|
|
@@ -80,6 +84,7 @@ export function applyResponsesImagePressure(reqContext, {
|
|
|
80
84
|
}
|
|
81
85
|
|
|
82
86
|
const trimmed = trimResponsesHistoricalImages(body, {
|
|
87
|
+
assertActive,
|
|
83
88
|
currentInputStart,
|
|
84
89
|
maxHistoricalImages,
|
|
85
90
|
targetBytes,
|
|
@@ -126,8 +131,9 @@ export function createResponsesImagePressureController({
|
|
|
126
131
|
};
|
|
127
132
|
|
|
128
133
|
return Object.freeze({
|
|
129
|
-
apply(reqContext) {
|
|
134
|
+
apply(reqContext, { assertActive } = {}) {
|
|
130
135
|
const result = applyResponsesImagePressure(reqContext, {
|
|
136
|
+
assertActive,
|
|
131
137
|
mode: modeFor(reqContext?.historyRootId),
|
|
132
138
|
policy,
|
|
133
139
|
});
|
|
@@ -13,18 +13,28 @@ function cloneJson(value) {
|
|
|
13
13
|
return value === undefined ? undefined : structuredClone(value);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
function responsesInputItems(input, { clone = true } = {}) {
|
|
16
|
+
function responsesInputItems(input, { assertActive, clone = true } = {}) {
|
|
17
17
|
if (input === undefined || input === null) return [];
|
|
18
18
|
if (typeof input === "string") {
|
|
19
19
|
return [{ type: "message", role: "user", content: [{ type: "input_text", text: input }] }];
|
|
20
20
|
}
|
|
21
|
-
if (Array.isArray(input))
|
|
22
|
-
|
|
21
|
+
if (Array.isArray(input)) {
|
|
22
|
+
assertActive?.();
|
|
23
|
+
const items = clone ? cloneJson(input) : input;
|
|
24
|
+
assertActive?.();
|
|
25
|
+
return items;
|
|
26
|
+
}
|
|
27
|
+
assertActive?.();
|
|
28
|
+
const item = clone ? cloneJson(input) : input;
|
|
29
|
+
assertActive?.();
|
|
30
|
+
return [item];
|
|
23
31
|
}
|
|
24
32
|
|
|
25
|
-
export function stripInternalResponsesInputFields(inputItems) {
|
|
33
|
+
export function stripInternalResponsesInputFields(inputItems, { assertActive } = {}) {
|
|
26
34
|
if (!Array.isArray(inputItems)) return inputItems;
|
|
27
|
-
for (
|
|
35
|
+
for (let index = 0; index < inputItems.length; index += 1) {
|
|
36
|
+
if ((index & 63) === 0) assertActive?.();
|
|
37
|
+
const item = inputItems[index];
|
|
28
38
|
if (!item || typeof item !== "object") continue;
|
|
29
39
|
for (const key of Object.keys(item)) {
|
|
30
40
|
if (key.startsWith("internal_")) delete item[key];
|
|
@@ -158,16 +168,20 @@ export async function openCopilotResponse(reqContext, upstream = copilotResponse
|
|
|
158
168
|
let imageNamespaceRetried = false;
|
|
159
169
|
let payloadPrepared = false;
|
|
160
170
|
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
171
|
+
options.assertPrepareActive?.();
|
|
161
172
|
const resp = await upstream(reqContext.body, {
|
|
173
|
+
assertActive: options.assertPrepareActive,
|
|
162
174
|
signal: options.signal,
|
|
163
175
|
currentInputStart: reqContext.currentInputStart,
|
|
164
176
|
onUpstreamStart: options.onUpstreamStart,
|
|
165
177
|
payloadPrepared,
|
|
166
178
|
});
|
|
179
|
+
options.assertPrepareActive?.();
|
|
167
180
|
payloadPrepared = true;
|
|
168
181
|
if (resp.ok) return { resp, reqContext };
|
|
169
182
|
|
|
170
183
|
const errorText = await resp.text();
|
|
184
|
+
options.assertPrepareActive?.();
|
|
171
185
|
if (!imageNamespaceRetried && isImageNamespaceCollisionError(resp.status, errorText)) {
|
|
172
186
|
const retryContext = sanitizeImageNamespaceCollisionRequest(reqContext);
|
|
173
187
|
if (retryContext) {
|
|
@@ -195,9 +209,11 @@ function isBuiltinImageTool(tool) {
|
|
|
195
209
|
return isImageNamespaceTool(tool);
|
|
196
210
|
}
|
|
197
211
|
|
|
198
|
-
export function prepareResponsesRequest(reqBody, { mutate = false } = {}) {
|
|
212
|
+
export function prepareResponsesRequest(reqBody, { assertActive, mutate = false } = {}) {
|
|
213
|
+
assertActive?.();
|
|
199
214
|
const body = mutate ? reqBody : cloneJson(reqBody);
|
|
200
|
-
|
|
215
|
+
assertActive?.();
|
|
216
|
+
const currentInputItems = responsesInputItems(body.input, { assertActive, clone: !mutate });
|
|
201
217
|
const currentInputRefs = new Set(
|
|
202
218
|
currentInputItems.filter((item) => item && typeof item === "object"),
|
|
203
219
|
);
|
|
@@ -206,7 +222,7 @@ export function prepareResponsesRequest(reqBody, { mutate = false } = {}) {
|
|
|
206
222
|
let historyRootId = null;
|
|
207
223
|
|
|
208
224
|
if (previousId !== undefined && previousId !== null) {
|
|
209
|
-
historyItems = materializeResponseHistory(previousId);
|
|
225
|
+
historyItems = materializeResponseHistory(previousId, { assertActive });
|
|
210
226
|
historyRootId = responseHistoryRootId(previousId);
|
|
211
227
|
body.input = [...historyItems, ...currentInputItems];
|
|
212
228
|
} else {
|
|
@@ -215,6 +231,7 @@ export function prepareResponsesRequest(reqBody, { mutate = false } = {}) {
|
|
|
215
231
|
|
|
216
232
|
let historyInputItems = currentInputItems;
|
|
217
233
|
const imageLimit = enforceResponsesImageLimit(body.input, {
|
|
234
|
+
assertActive,
|
|
218
235
|
currentInputStart: historyItems.length,
|
|
219
236
|
beforeMutate: ({ currentOmitted }) => {
|
|
220
237
|
if (currentOmitted > 0) historyInputItems = cloneJson(currentInputItems);
|
|
@@ -230,8 +247,9 @@ export function prepareResponsesRequest(reqBody, { mutate = false } = {}) {
|
|
|
230
247
|
body.tools = body.tools.filter((tool) => !isBuiltinImageTool(tool));
|
|
231
248
|
if (!body.tools.length) delete body.tools;
|
|
232
249
|
}
|
|
233
|
-
stripInternalResponsesInputFields(body.input);
|
|
234
|
-
stripInternalResponsesInputFields(historyInputItems);
|
|
250
|
+
stripInternalResponsesInputFields(body.input, { assertActive });
|
|
251
|
+
stripInternalResponsesInputFields(historyInputItems, { assertActive });
|
|
252
|
+
assertActive?.();
|
|
235
253
|
const retainedCurrentInputStart = body.input.findIndex((item) => currentInputRefs.has(item));
|
|
236
254
|
|
|
237
255
|
return {
|