@sunerpy/opencode-kiro-auth 0.14.0 → 0.14.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.
|
@@ -242,8 +242,9 @@ export class RequestHandler {
|
|
|
242
242
|
try {
|
|
243
243
|
sdkResponse = await client.send(command, { abortSignal: signal });
|
|
244
244
|
}
|
|
245
|
-
|
|
245
|
+
catch (error) {
|
|
246
246
|
endUpstreamWait();
|
|
247
|
+
throw error;
|
|
247
248
|
}
|
|
248
249
|
sendResolved = true;
|
|
249
250
|
if (apiTimestamp) {
|
|
@@ -251,11 +252,19 @@ export class RequestHandler {
|
|
|
251
252
|
}
|
|
252
253
|
const response = await this.responseHandler.handleSdkSuccess(sdkResponse, model, sdkPrep.conversationId, sdkPrep.streaming, {
|
|
253
254
|
signal,
|
|
254
|
-
onUpstreamWaitStart: () =>
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
255
|
+
onUpstreamWaitStart: ({ eventIndex }) => {
|
|
256
|
+
if (eventIndex === 0) {
|
|
257
|
+
if (!this.config.sdk_response_timeout_enabled)
|
|
258
|
+
endUpstreamWait();
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
beginUpstreamWait('stream event', this.config.request_timeout_ms, {
|
|
262
|
+
model,
|
|
263
|
+
effectiveModel: sdkPrep.effectiveModel,
|
|
264
|
+
region: sdkPrep.region,
|
|
265
|
+
eventIndex
|
|
266
|
+
});
|
|
267
|
+
},
|
|
259
268
|
onUpstreamWaitEnd: endUpstreamWait,
|
|
260
269
|
onIterationError: (error, afterCompletionMetadata) => logger.warn('Kiro SDK event stream iteration failed', {
|
|
261
270
|
model,
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { SdkEventStreamIterationError } from './stream-error.js';
|
|
2
2
|
export interface SdkResponseLifecycle {
|
|
3
3
|
signal?: AbortSignal;
|
|
4
|
-
onUpstreamWaitStart?: (
|
|
4
|
+
onUpstreamWaitStart?: (context: {
|
|
5
|
+
eventIndex: number;
|
|
6
|
+
}) => void;
|
|
5
7
|
onUpstreamWaitEnd?: () => void;
|
|
6
8
|
onIterationError?: (error: unknown, afterCompletionMetadata: boolean) => void;
|
|
7
9
|
onComplete?: () => void | Promise<void>;
|
|
@@ -27,6 +27,7 @@ function wrapSdkEventStream(sdkResponse, signal, onUpstreamWaitStart, onUpstream
|
|
|
27
27
|
const rawIterator = eventStream[Symbol.asyncIterator]();
|
|
28
28
|
let closed = false;
|
|
29
29
|
let completionMetadataSeen = false;
|
|
30
|
+
let eventIndex = 0;
|
|
30
31
|
const closeRaw = async () => {
|
|
31
32
|
if (closed)
|
|
32
33
|
return;
|
|
@@ -38,26 +39,33 @@ function wrapSdkEventStream(sdkResponse, signal, onUpstreamWaitStart, onUpstream
|
|
|
38
39
|
await closeRaw();
|
|
39
40
|
throw abortReason(signal);
|
|
40
41
|
}
|
|
41
|
-
onUpstreamWaitStart?.();
|
|
42
|
+
onUpstreamWaitStart?.({ eventIndex });
|
|
42
43
|
try {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
44
|
+
let result;
|
|
45
|
+
if (!signal) {
|
|
46
|
+
result = await rawIterator.next();
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
result = await new Promise((resolve, reject) => {
|
|
50
|
+
let settled = false;
|
|
51
|
+
const settle = (callback) => {
|
|
52
|
+
if (settled)
|
|
53
|
+
return;
|
|
54
|
+
settled = true;
|
|
55
|
+
signal.removeEventListener('abort', onAbort);
|
|
56
|
+
callback();
|
|
57
|
+
};
|
|
58
|
+
const onAbort = () => {
|
|
59
|
+
void closeRaw();
|
|
60
|
+
settle(() => reject(abortReason(signal)));
|
|
61
|
+
};
|
|
62
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
63
|
+
Promise.resolve(rawIterator.next()).then((nextResult) => settle(() => resolve(nextResult)), (error) => settle(() => reject(error)));
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
if (!result.done)
|
|
67
|
+
eventIndex++;
|
|
68
|
+
return result;
|
|
61
69
|
}
|
|
62
70
|
finally {
|
|
63
71
|
onUpstreamWaitEnd?.();
|