@yushaw/sanqian-chat 0.2.33 → 0.2.34
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/core/index.d.mts +10 -2
- package/dist/core/index.d.ts +10 -2
- package/dist/core/index.js +38 -25
- package/dist/core/index.mjs +38 -25
- package/dist/main/index.d.mts +8 -0
- package/dist/main/index.d.ts +8 -0
- package/dist/main/index.js +537 -499
- package/dist/main/index.mjs +537 -499
- package/dist/preload/factories.d.mts +1 -0
- package/dist/preload/factories.d.ts +1 -0
- package/dist/renderer/index.d.mts +11 -1
- package/dist/renderer/index.d.ts +11 -1
- package/dist/renderer/index.js +171 -77
- package/dist/renderer/index.mjs +202 -108
- package/package.json +6 -6
package/dist/core/index.d.mts
CHANGED
|
@@ -553,6 +553,14 @@ interface SendMessage {
|
|
|
553
553
|
role: 'user' | 'assistant';
|
|
554
554
|
content: string;
|
|
555
555
|
}
|
|
556
|
+
/**
|
|
557
|
+
* HITL response outcome.
|
|
558
|
+
*
|
|
559
|
+
* Keep `void` for backwards compatibility with legacy/custom adapters that
|
|
560
|
+
* predate boolean acknowledgement semantics. A future major release can remove
|
|
561
|
+
* `void` after a deprecation window.
|
|
562
|
+
*/
|
|
563
|
+
type HitlResponseOutcome = boolean | void | Promise<boolean | void>;
|
|
556
564
|
/** Chat adapter interface */
|
|
557
565
|
interface ChatAdapter {
|
|
558
566
|
connect(): Promise<void>;
|
|
@@ -582,7 +590,7 @@ interface ChatAdapter {
|
|
|
582
590
|
}): Promise<{
|
|
583
591
|
cancel: () => void;
|
|
584
592
|
}>;
|
|
585
|
-
sendHitlResponse?(response: HitlResponse, runId?: string, streamId?: string):
|
|
593
|
+
sendHitlResponse?(response: HitlResponse, runId?: string, streamId?: string): HitlResponseOutcome;
|
|
586
594
|
/** List available context providers */
|
|
587
595
|
listResourceProviders?(): Promise<ContextProviderInfo[]>;
|
|
588
596
|
/** Get resource list from a provider with search/pagination */
|
|
@@ -690,4 +698,4 @@ declare function parseToolCalls(toolCalls: unknown): ToolCall[] | undefined;
|
|
|
690
698
|
*/
|
|
691
699
|
declare function mergeConsecutiveAssistantMessages(rawMessages: ApiMessage[]): ChatMessage[];
|
|
692
700
|
|
|
693
|
-
export { type ApiMessage, type AttachConfig, type AttachPosition, type AttachState, type AttachedResource, type AttachmentMenuItem, type AttachmentMenuItemType, type ChatAdapter, type ChatAdapterConfig, type ChatFontSize, type ChatMessage, type ChatPanelConfig, type ChatPanelMode, type ChatPanelPosition, type ChatThemeMode, type ChatUiConfigSerializable, type ChatUiStrings, type ConnectionErrorCode, type ConnectionStatus, type ContextProviderInfo, type ConversationDetail, type ConversationInfo, type FloatingWindowConfig, type HitlInterruptData, type LinkClickEvent, type LinkHandlerConfig, type Locale, type MessageBlock, type MessageRole, type ResourcePickerItem, type ResourcePickerState, type SdkAdapterConfig, type SendMessage, type SessionResource, type SessionResourceEvent, type StoredSessionResource, type StreamEvent, type ToolCall, type ToolCallStatus, type WindowPosition, createChatAdapter, createSdkAdapter, mergeConsecutiveAssistantMessages, parseToolCalls };
|
|
701
|
+
export { type ApiMessage, type AttachConfig, type AttachPosition, type AttachState, type AttachedResource, type AttachmentMenuItem, type AttachmentMenuItemType, type ChatAdapter, type ChatAdapterConfig, type ChatFontSize, type ChatMessage, type ChatPanelConfig, type ChatPanelMode, type ChatPanelPosition, type ChatThemeMode, type ChatUiConfigSerializable, type ChatUiStrings, type ConnectionErrorCode, type ConnectionStatus, type ContextProviderInfo, type ConversationDetail, type ConversationInfo, type FloatingWindowConfig, type HitlInterruptData, type HitlResponseOutcome, type LinkClickEvent, type LinkHandlerConfig, type Locale, type MessageBlock, type MessageRole, type ResourcePickerItem, type ResourcePickerState, type SdkAdapterConfig, type SendMessage, type SessionResource, type SessionResourceEvent, type StoredSessionResource, type StreamEvent, type ToolCall, type ToolCallStatus, type WindowPosition, createChatAdapter, createSdkAdapter, mergeConsecutiveAssistantMessages, parseToolCalls };
|
package/dist/core/index.d.ts
CHANGED
|
@@ -553,6 +553,14 @@ interface SendMessage {
|
|
|
553
553
|
role: 'user' | 'assistant';
|
|
554
554
|
content: string;
|
|
555
555
|
}
|
|
556
|
+
/**
|
|
557
|
+
* HITL response outcome.
|
|
558
|
+
*
|
|
559
|
+
* Keep `void` for backwards compatibility with legacy/custom adapters that
|
|
560
|
+
* predate boolean acknowledgement semantics. A future major release can remove
|
|
561
|
+
* `void` after a deprecation window.
|
|
562
|
+
*/
|
|
563
|
+
type HitlResponseOutcome = boolean | void | Promise<boolean | void>;
|
|
556
564
|
/** Chat adapter interface */
|
|
557
565
|
interface ChatAdapter {
|
|
558
566
|
connect(): Promise<void>;
|
|
@@ -582,7 +590,7 @@ interface ChatAdapter {
|
|
|
582
590
|
}): Promise<{
|
|
583
591
|
cancel: () => void;
|
|
584
592
|
}>;
|
|
585
|
-
sendHitlResponse?(response: HitlResponse, runId?: string, streamId?: string):
|
|
593
|
+
sendHitlResponse?(response: HitlResponse, runId?: string, streamId?: string): HitlResponseOutcome;
|
|
586
594
|
/** List available context providers */
|
|
587
595
|
listResourceProviders?(): Promise<ContextProviderInfo[]>;
|
|
588
596
|
/** Get resource list from a provider with search/pagination */
|
|
@@ -690,4 +698,4 @@ declare function parseToolCalls(toolCalls: unknown): ToolCall[] | undefined;
|
|
|
690
698
|
*/
|
|
691
699
|
declare function mergeConsecutiveAssistantMessages(rawMessages: ApiMessage[]): ChatMessage[];
|
|
692
700
|
|
|
693
|
-
export { type ApiMessage, type AttachConfig, type AttachPosition, type AttachState, type AttachedResource, type AttachmentMenuItem, type AttachmentMenuItemType, type ChatAdapter, type ChatAdapterConfig, type ChatFontSize, type ChatMessage, type ChatPanelConfig, type ChatPanelMode, type ChatPanelPosition, type ChatThemeMode, type ChatUiConfigSerializable, type ChatUiStrings, type ConnectionErrorCode, type ConnectionStatus, type ContextProviderInfo, type ConversationDetail, type ConversationInfo, type FloatingWindowConfig, type HitlInterruptData, type LinkClickEvent, type LinkHandlerConfig, type Locale, type MessageBlock, type MessageRole, type ResourcePickerItem, type ResourcePickerState, type SdkAdapterConfig, type SendMessage, type SessionResource, type SessionResourceEvent, type StoredSessionResource, type StreamEvent, type ToolCall, type ToolCallStatus, type WindowPosition, createChatAdapter, createSdkAdapter, mergeConsecutiveAssistantMessages, parseToolCalls };
|
|
701
|
+
export { type ApiMessage, type AttachConfig, type AttachPosition, type AttachState, type AttachedResource, type AttachmentMenuItem, type AttachmentMenuItemType, type ChatAdapter, type ChatAdapterConfig, type ChatFontSize, type ChatMessage, type ChatPanelConfig, type ChatPanelMode, type ChatPanelPosition, type ChatThemeMode, type ChatUiConfigSerializable, type ChatUiStrings, type ConnectionErrorCode, type ConnectionStatus, type ContextProviderInfo, type ConversationDetail, type ConversationInfo, type FloatingWindowConfig, type HitlInterruptData, type HitlResponseOutcome, type LinkClickEvent, type LinkHandlerConfig, type Locale, type MessageBlock, type MessageRole, type ResourcePickerItem, type ResourcePickerState, type SdkAdapterConfig, type SendMessage, type SessionResource, type SessionResourceEvent, type StoredSessionResource, type StreamEvent, type ToolCall, type ToolCallStatus, type WindowPosition, createChatAdapter, createSdkAdapter, mergeConsecutiveAssistantMessages, parseToolCalls };
|
package/dist/core/index.js
CHANGED
|
@@ -313,7 +313,7 @@ function createChatAdapter(config) {
|
|
|
313
313
|
let sdkPromise = null;
|
|
314
314
|
let connectionStatus = "disconnected";
|
|
315
315
|
const connectionListeners = /* @__PURE__ */ new Set();
|
|
316
|
-
|
|
316
|
+
const streamRunIds = /* @__PURE__ */ new Map();
|
|
317
317
|
let reconnectAcquired = false;
|
|
318
318
|
const updateStatus = (status, error, errorCode) => {
|
|
319
319
|
connectionStatus = status;
|
|
@@ -462,16 +462,20 @@ function createChatAdapter(config) {
|
|
|
462
462
|
sessionResources: options?.sessionResources
|
|
463
463
|
}
|
|
464
464
|
);
|
|
465
|
+
const streamId = `stream-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
465
466
|
return processStreamEvents(stream, onEvent, sdk, (id) => {
|
|
466
|
-
|
|
467
|
-
|
|
467
|
+
if (id) streamRunIds.set(streamId, id);
|
|
468
|
+
else streamRunIds.delete(streamId);
|
|
469
|
+
}, streamId);
|
|
468
470
|
},
|
|
469
|
-
sendHitlResponse(response, runId) {
|
|
470
|
-
if (!sdkInstance) return;
|
|
471
|
-
const id = runId ||
|
|
471
|
+
sendHitlResponse(response, runId, streamId) {
|
|
472
|
+
if (!sdkInstance) return false;
|
|
473
|
+
const id = runId || (streamId ? streamRunIds.get(streamId) : void 0) || streamRunIds.values().next().value || null;
|
|
472
474
|
if (id) {
|
|
473
475
|
sdkInstance.sendHitlResponse(id, response);
|
|
476
|
+
return true;
|
|
474
477
|
}
|
|
478
|
+
return false;
|
|
475
479
|
},
|
|
476
480
|
// Session Resources (delegated to shared helper)
|
|
477
481
|
...createSessionResourceMethods(() => sdkInstance)
|
|
@@ -517,10 +521,14 @@ function createSessionResourceMethods(getSdk) {
|
|
|
517
521
|
}
|
|
518
522
|
};
|
|
519
523
|
}
|
|
520
|
-
function processStreamEvents(stream, onEvent, sdk, setCurrentRunId) {
|
|
524
|
+
function processStreamEvents(stream, onEvent, sdk, setCurrentRunId, streamId) {
|
|
521
525
|
const controller = new AbortController();
|
|
522
526
|
const signal = controller.signal;
|
|
523
527
|
let currentRunId = null;
|
|
528
|
+
const forward = (event) => {
|
|
529
|
+
if (streamId) event.stream_id = streamId;
|
|
530
|
+
onEvent(event);
|
|
531
|
+
};
|
|
524
532
|
(async () => {
|
|
525
533
|
try {
|
|
526
534
|
for await (const event of stream) {
|
|
@@ -530,22 +538,22 @@ function processStreamEvents(stream, onEvent, sdk, setCurrentRunId) {
|
|
|
530
538
|
if (event.run_id) {
|
|
531
539
|
currentRunId = event.run_id;
|
|
532
540
|
setCurrentRunId(event.run_id);
|
|
533
|
-
|
|
541
|
+
forward({ type: "start", run_id: event.run_id, conversationId: event.conversationId });
|
|
534
542
|
}
|
|
535
543
|
break;
|
|
536
544
|
case "text":
|
|
537
|
-
|
|
545
|
+
forward({ type: "text", content: event.content || "" });
|
|
538
546
|
break;
|
|
539
547
|
case "thinking":
|
|
540
|
-
|
|
548
|
+
forward({ type: "thinking", content: event.content || "" });
|
|
541
549
|
break;
|
|
542
550
|
case "tool_call":
|
|
543
551
|
if (event.tool_call) {
|
|
544
|
-
|
|
552
|
+
forward({ type: "tool_call", tool_call: event.tool_call });
|
|
545
553
|
}
|
|
546
554
|
break;
|
|
547
555
|
case "tool_args_chunk":
|
|
548
|
-
|
|
556
|
+
forward({
|
|
549
557
|
type: "tool_args_chunk",
|
|
550
558
|
tool_call_id: event.tool_call_id || "",
|
|
551
559
|
tool_name: event.tool_name,
|
|
@@ -553,7 +561,7 @@ function processStreamEvents(stream, onEvent, sdk, setCurrentRunId) {
|
|
|
553
561
|
});
|
|
554
562
|
break;
|
|
555
563
|
case "tool_args":
|
|
556
|
-
|
|
564
|
+
forward({
|
|
557
565
|
type: "tool_args",
|
|
558
566
|
tool_call_id: event.tool_call_id || "",
|
|
559
567
|
tool_name: event.tool_name,
|
|
@@ -561,20 +569,20 @@ function processStreamEvents(stream, onEvent, sdk, setCurrentRunId) {
|
|
|
561
569
|
});
|
|
562
570
|
break;
|
|
563
571
|
case "tool_result":
|
|
564
|
-
|
|
572
|
+
forward({ type: "tool_result", tool_call_id: event.tool_call_id || "", result: event.result });
|
|
565
573
|
break;
|
|
566
574
|
case "done":
|
|
567
|
-
|
|
575
|
+
forward({ type: "done", conversationId: event.conversationId || "", title: event.title });
|
|
568
576
|
currentRunId = null;
|
|
569
577
|
setCurrentRunId(null);
|
|
570
578
|
break;
|
|
571
579
|
case "cancelled":
|
|
572
|
-
|
|
580
|
+
forward({ type: "cancelled", run_id: event.run_id });
|
|
573
581
|
currentRunId = null;
|
|
574
582
|
setCurrentRunId(null);
|
|
575
583
|
break;
|
|
576
584
|
case "error":
|
|
577
|
-
|
|
585
|
+
forward({ type: "error", error: event.error || "Unknown error" });
|
|
578
586
|
currentRunId = null;
|
|
579
587
|
setCurrentRunId(null);
|
|
580
588
|
break;
|
|
@@ -585,7 +593,7 @@ function processStreamEvents(stream, onEvent, sdk, setCurrentRunId) {
|
|
|
585
593
|
currentRunId = evt.run_id;
|
|
586
594
|
setCurrentRunId(evt.run_id);
|
|
587
595
|
}
|
|
588
|
-
|
|
596
|
+
forward({
|
|
589
597
|
type: "interrupt",
|
|
590
598
|
interrupt_type: evt.interrupt_type || "",
|
|
591
599
|
interrupt_payload: evt.interrupt_payload,
|
|
@@ -598,7 +606,7 @@ function processStreamEvents(stream, onEvent, sdk, setCurrentRunId) {
|
|
|
598
606
|
}
|
|
599
607
|
} catch (e) {
|
|
600
608
|
if (!signal.aborted) {
|
|
601
|
-
|
|
609
|
+
forward({ type: "error", error: e instanceof Error ? e.message : "Stream error" });
|
|
602
610
|
}
|
|
603
611
|
}
|
|
604
612
|
})();
|
|
@@ -613,13 +621,14 @@ function processStreamEvents(stream, onEvent, sdk, setCurrentRunId) {
|
|
|
613
621
|
console.warn("[chat adapter] Failed to cancel run:", e);
|
|
614
622
|
}
|
|
615
623
|
}
|
|
624
|
+
setCurrentRunId(null);
|
|
616
625
|
}
|
|
617
626
|
};
|
|
618
627
|
}
|
|
619
628
|
function createSdkAdapter(config) {
|
|
620
629
|
let connectionStatus = "disconnected";
|
|
621
630
|
const connectionListeners = /* @__PURE__ */ new Set();
|
|
622
|
-
|
|
631
|
+
const streamRunIds = /* @__PURE__ */ new Map();
|
|
623
632
|
const updateStatus = (status, error, errorCode) => {
|
|
624
633
|
connectionStatus = status;
|
|
625
634
|
connectionListeners.forEach((cb) => cb(status, error, errorCode));
|
|
@@ -732,17 +741,21 @@ function createSdkAdapter(config) {
|
|
|
732
741
|
sessionResources: options?.sessionResources
|
|
733
742
|
}
|
|
734
743
|
);
|
|
744
|
+
const streamId = `stream-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
735
745
|
return processStreamEvents(stream, onEvent, sdk, (id) => {
|
|
736
|
-
|
|
737
|
-
|
|
746
|
+
if (id) streamRunIds.set(streamId, id);
|
|
747
|
+
else streamRunIds.delete(streamId);
|
|
748
|
+
}, streamId);
|
|
738
749
|
},
|
|
739
|
-
sendHitlResponse(response, runId) {
|
|
750
|
+
sendHitlResponse(response, runId, streamId) {
|
|
740
751
|
const sdk = config.getSdk();
|
|
741
|
-
if (!sdk) return;
|
|
742
|
-
const id = runId ||
|
|
752
|
+
if (!sdk) return false;
|
|
753
|
+
const id = runId || (streamId ? streamRunIds.get(streamId) : void 0) || streamRunIds.values().next().value || null;
|
|
743
754
|
if (id) {
|
|
744
755
|
sdk.sendHitlResponse(id, response);
|
|
756
|
+
return true;
|
|
745
757
|
}
|
|
758
|
+
return false;
|
|
746
759
|
},
|
|
747
760
|
// Session Resources (delegated to shared helper)
|
|
748
761
|
...createSessionResourceMethods(config.getSdk)
|
package/dist/core/index.mjs
CHANGED
|
@@ -274,7 +274,7 @@ function createChatAdapter(config) {
|
|
|
274
274
|
let sdkPromise = null;
|
|
275
275
|
let connectionStatus = "disconnected";
|
|
276
276
|
const connectionListeners = /* @__PURE__ */ new Set();
|
|
277
|
-
|
|
277
|
+
const streamRunIds = /* @__PURE__ */ new Map();
|
|
278
278
|
let reconnectAcquired = false;
|
|
279
279
|
const updateStatus = (status, error, errorCode) => {
|
|
280
280
|
connectionStatus = status;
|
|
@@ -423,16 +423,20 @@ function createChatAdapter(config) {
|
|
|
423
423
|
sessionResources: options?.sessionResources
|
|
424
424
|
}
|
|
425
425
|
);
|
|
426
|
+
const streamId = `stream-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
426
427
|
return processStreamEvents(stream, onEvent, sdk, (id) => {
|
|
427
|
-
|
|
428
|
-
|
|
428
|
+
if (id) streamRunIds.set(streamId, id);
|
|
429
|
+
else streamRunIds.delete(streamId);
|
|
430
|
+
}, streamId);
|
|
429
431
|
},
|
|
430
|
-
sendHitlResponse(response, runId) {
|
|
431
|
-
if (!sdkInstance) return;
|
|
432
|
-
const id = runId ||
|
|
432
|
+
sendHitlResponse(response, runId, streamId) {
|
|
433
|
+
if (!sdkInstance) return false;
|
|
434
|
+
const id = runId || (streamId ? streamRunIds.get(streamId) : void 0) || streamRunIds.values().next().value || null;
|
|
433
435
|
if (id) {
|
|
434
436
|
sdkInstance.sendHitlResponse(id, response);
|
|
437
|
+
return true;
|
|
435
438
|
}
|
|
439
|
+
return false;
|
|
436
440
|
},
|
|
437
441
|
// Session Resources (delegated to shared helper)
|
|
438
442
|
...createSessionResourceMethods(() => sdkInstance)
|
|
@@ -478,10 +482,14 @@ function createSessionResourceMethods(getSdk) {
|
|
|
478
482
|
}
|
|
479
483
|
};
|
|
480
484
|
}
|
|
481
|
-
function processStreamEvents(stream, onEvent, sdk, setCurrentRunId) {
|
|
485
|
+
function processStreamEvents(stream, onEvent, sdk, setCurrentRunId, streamId) {
|
|
482
486
|
const controller = new AbortController();
|
|
483
487
|
const signal = controller.signal;
|
|
484
488
|
let currentRunId = null;
|
|
489
|
+
const forward = (event) => {
|
|
490
|
+
if (streamId) event.stream_id = streamId;
|
|
491
|
+
onEvent(event);
|
|
492
|
+
};
|
|
485
493
|
(async () => {
|
|
486
494
|
try {
|
|
487
495
|
for await (const event of stream) {
|
|
@@ -491,22 +499,22 @@ function processStreamEvents(stream, onEvent, sdk, setCurrentRunId) {
|
|
|
491
499
|
if (event.run_id) {
|
|
492
500
|
currentRunId = event.run_id;
|
|
493
501
|
setCurrentRunId(event.run_id);
|
|
494
|
-
|
|
502
|
+
forward({ type: "start", run_id: event.run_id, conversationId: event.conversationId });
|
|
495
503
|
}
|
|
496
504
|
break;
|
|
497
505
|
case "text":
|
|
498
|
-
|
|
506
|
+
forward({ type: "text", content: event.content || "" });
|
|
499
507
|
break;
|
|
500
508
|
case "thinking":
|
|
501
|
-
|
|
509
|
+
forward({ type: "thinking", content: event.content || "" });
|
|
502
510
|
break;
|
|
503
511
|
case "tool_call":
|
|
504
512
|
if (event.tool_call) {
|
|
505
|
-
|
|
513
|
+
forward({ type: "tool_call", tool_call: event.tool_call });
|
|
506
514
|
}
|
|
507
515
|
break;
|
|
508
516
|
case "tool_args_chunk":
|
|
509
|
-
|
|
517
|
+
forward({
|
|
510
518
|
type: "tool_args_chunk",
|
|
511
519
|
tool_call_id: event.tool_call_id || "",
|
|
512
520
|
tool_name: event.tool_name,
|
|
@@ -514,7 +522,7 @@ function processStreamEvents(stream, onEvent, sdk, setCurrentRunId) {
|
|
|
514
522
|
});
|
|
515
523
|
break;
|
|
516
524
|
case "tool_args":
|
|
517
|
-
|
|
525
|
+
forward({
|
|
518
526
|
type: "tool_args",
|
|
519
527
|
tool_call_id: event.tool_call_id || "",
|
|
520
528
|
tool_name: event.tool_name,
|
|
@@ -522,20 +530,20 @@ function processStreamEvents(stream, onEvent, sdk, setCurrentRunId) {
|
|
|
522
530
|
});
|
|
523
531
|
break;
|
|
524
532
|
case "tool_result":
|
|
525
|
-
|
|
533
|
+
forward({ type: "tool_result", tool_call_id: event.tool_call_id || "", result: event.result });
|
|
526
534
|
break;
|
|
527
535
|
case "done":
|
|
528
|
-
|
|
536
|
+
forward({ type: "done", conversationId: event.conversationId || "", title: event.title });
|
|
529
537
|
currentRunId = null;
|
|
530
538
|
setCurrentRunId(null);
|
|
531
539
|
break;
|
|
532
540
|
case "cancelled":
|
|
533
|
-
|
|
541
|
+
forward({ type: "cancelled", run_id: event.run_id });
|
|
534
542
|
currentRunId = null;
|
|
535
543
|
setCurrentRunId(null);
|
|
536
544
|
break;
|
|
537
545
|
case "error":
|
|
538
|
-
|
|
546
|
+
forward({ type: "error", error: event.error || "Unknown error" });
|
|
539
547
|
currentRunId = null;
|
|
540
548
|
setCurrentRunId(null);
|
|
541
549
|
break;
|
|
@@ -546,7 +554,7 @@ function processStreamEvents(stream, onEvent, sdk, setCurrentRunId) {
|
|
|
546
554
|
currentRunId = evt.run_id;
|
|
547
555
|
setCurrentRunId(evt.run_id);
|
|
548
556
|
}
|
|
549
|
-
|
|
557
|
+
forward({
|
|
550
558
|
type: "interrupt",
|
|
551
559
|
interrupt_type: evt.interrupt_type || "",
|
|
552
560
|
interrupt_payload: evt.interrupt_payload,
|
|
@@ -559,7 +567,7 @@ function processStreamEvents(stream, onEvent, sdk, setCurrentRunId) {
|
|
|
559
567
|
}
|
|
560
568
|
} catch (e) {
|
|
561
569
|
if (!signal.aborted) {
|
|
562
|
-
|
|
570
|
+
forward({ type: "error", error: e instanceof Error ? e.message : "Stream error" });
|
|
563
571
|
}
|
|
564
572
|
}
|
|
565
573
|
})();
|
|
@@ -574,13 +582,14 @@ function processStreamEvents(stream, onEvent, sdk, setCurrentRunId) {
|
|
|
574
582
|
console.warn("[chat adapter] Failed to cancel run:", e);
|
|
575
583
|
}
|
|
576
584
|
}
|
|
585
|
+
setCurrentRunId(null);
|
|
577
586
|
}
|
|
578
587
|
};
|
|
579
588
|
}
|
|
580
589
|
function createSdkAdapter(config) {
|
|
581
590
|
let connectionStatus = "disconnected";
|
|
582
591
|
const connectionListeners = /* @__PURE__ */ new Set();
|
|
583
|
-
|
|
592
|
+
const streamRunIds = /* @__PURE__ */ new Map();
|
|
584
593
|
const updateStatus = (status, error, errorCode) => {
|
|
585
594
|
connectionStatus = status;
|
|
586
595
|
connectionListeners.forEach((cb) => cb(status, error, errorCode));
|
|
@@ -693,17 +702,21 @@ function createSdkAdapter(config) {
|
|
|
693
702
|
sessionResources: options?.sessionResources
|
|
694
703
|
}
|
|
695
704
|
);
|
|
705
|
+
const streamId = `stream-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
696
706
|
return processStreamEvents(stream, onEvent, sdk, (id) => {
|
|
697
|
-
|
|
698
|
-
|
|
707
|
+
if (id) streamRunIds.set(streamId, id);
|
|
708
|
+
else streamRunIds.delete(streamId);
|
|
709
|
+
}, streamId);
|
|
699
710
|
},
|
|
700
|
-
sendHitlResponse(response, runId) {
|
|
711
|
+
sendHitlResponse(response, runId, streamId) {
|
|
701
712
|
const sdk = config.getSdk();
|
|
702
|
-
if (!sdk) return;
|
|
703
|
-
const id = runId ||
|
|
713
|
+
if (!sdk) return false;
|
|
714
|
+
const id = runId || (streamId ? streamRunIds.get(streamId) : void 0) || streamRunIds.values().next().value || null;
|
|
704
715
|
if (id) {
|
|
705
716
|
sdk.sendHitlResponse(id, response);
|
|
717
|
+
return true;
|
|
706
718
|
}
|
|
719
|
+
return false;
|
|
707
720
|
},
|
|
708
721
|
// Session Resources (delegated to shared helper)
|
|
709
722
|
...createSessionResourceMethods(config.getSdk)
|
package/dist/main/index.d.mts
CHANGED
|
@@ -715,8 +715,12 @@ declare class FloatingWindow {
|
|
|
715
715
|
private savedState;
|
|
716
716
|
private stateSaveTimer;
|
|
717
717
|
private activeStreams;
|
|
718
|
+
private runOwnerByRunId;
|
|
718
719
|
private reconnectAcquired;
|
|
719
720
|
private resolveHitlRunId;
|
|
721
|
+
private rememberRunOwner;
|
|
722
|
+
private forgetRunOwner;
|
|
723
|
+
private waitForOwnedStreamRunId;
|
|
720
724
|
/**
|
|
721
725
|
* Get SDK instance from either getClient or getSdk
|
|
722
726
|
*/
|
|
@@ -790,6 +794,7 @@ declare class ChatPanel {
|
|
|
790
794
|
private registeredShortcuts;
|
|
791
795
|
private stateSaveTimer;
|
|
792
796
|
private activeStreams;
|
|
797
|
+
private runOwnerByRunId;
|
|
793
798
|
private sessionResourceCleanup;
|
|
794
799
|
constructor(config: ChatPanelConfig);
|
|
795
800
|
private hostResizeHandler;
|
|
@@ -927,6 +932,9 @@ declare class ChatPanel {
|
|
|
927
932
|
* Priority: explicit runId -> streamId-bound runId -> single active stream fallback.
|
|
928
933
|
*/
|
|
929
934
|
private resolveHitlRunId;
|
|
935
|
+
private rememberRunOwner;
|
|
936
|
+
private forgetRunOwner;
|
|
937
|
+
private waitForOwnedStreamRunId;
|
|
930
938
|
/**
|
|
931
939
|
* Setup session resource event forwarding from SDK to renderer
|
|
932
940
|
* Called when SDK becomes available (on connect)
|
package/dist/main/index.d.ts
CHANGED
|
@@ -715,8 +715,12 @@ declare class FloatingWindow {
|
|
|
715
715
|
private savedState;
|
|
716
716
|
private stateSaveTimer;
|
|
717
717
|
private activeStreams;
|
|
718
|
+
private runOwnerByRunId;
|
|
718
719
|
private reconnectAcquired;
|
|
719
720
|
private resolveHitlRunId;
|
|
721
|
+
private rememberRunOwner;
|
|
722
|
+
private forgetRunOwner;
|
|
723
|
+
private waitForOwnedStreamRunId;
|
|
720
724
|
/**
|
|
721
725
|
* Get SDK instance from either getClient or getSdk
|
|
722
726
|
*/
|
|
@@ -790,6 +794,7 @@ declare class ChatPanel {
|
|
|
790
794
|
private registeredShortcuts;
|
|
791
795
|
private stateSaveTimer;
|
|
792
796
|
private activeStreams;
|
|
797
|
+
private runOwnerByRunId;
|
|
793
798
|
private sessionResourceCleanup;
|
|
794
799
|
constructor(config: ChatPanelConfig);
|
|
795
800
|
private hostResizeHandler;
|
|
@@ -927,6 +932,9 @@ declare class ChatPanel {
|
|
|
927
932
|
* Priority: explicit runId -> streamId-bound runId -> single active stream fallback.
|
|
928
933
|
*/
|
|
929
934
|
private resolveHitlRunId;
|
|
935
|
+
private rememberRunOwner;
|
|
936
|
+
private forgetRunOwner;
|
|
937
|
+
private waitForOwnedStreamRunId;
|
|
930
938
|
/**
|
|
931
939
|
* Setup session resource event forwarding from SDK to renderer
|
|
932
940
|
* Called when SDK becomes available (on connect)
|