@cadraos/sdk 0.1.11-test → 0.1.12
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/chat/index.cjs +899 -252
- package/dist/chat/index.cjs.map +1 -1
- package/dist/chat/index.d.cts +277 -39
- package/dist/chat/index.d.ts +277 -39
- package/dist/chat/index.js +894 -253
- package/dist/chat/index.js.map +1 -1
- package/dist/index.cjs +52 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +52 -3
- package/dist/index.js.map +1 -1
- package/package.json +14 -19
- package/dist/chat/styles.css +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -1115,6 +1115,8 @@ interface ExecutionStreamControllerOptions {
|
|
|
1115
1115
|
getExecution: (executionId: string) => Promise<AgentExecution>;
|
|
1116
1116
|
/** Streaming configuration */
|
|
1117
1117
|
config?: Partial<StreamingConfig>;
|
|
1118
|
+
/** Whether polling fallback is enabled (default: true) */
|
|
1119
|
+
pollingEnabled?: boolean;
|
|
1118
1120
|
}
|
|
1119
1121
|
/**
|
|
1120
1122
|
* Execution Stream Controller
|
package/dist/index.d.ts
CHANGED
|
@@ -1115,6 +1115,8 @@ interface ExecutionStreamControllerOptions {
|
|
|
1115
1115
|
getExecution: (executionId: string) => Promise<AgentExecution>;
|
|
1116
1116
|
/** Streaming configuration */
|
|
1117
1117
|
config?: Partial<StreamingConfig>;
|
|
1118
|
+
/** Whether polling fallback is enabled (default: true) */
|
|
1119
|
+
pollingEnabled?: boolean;
|
|
1118
1120
|
}
|
|
1119
1121
|
/**
|
|
1120
1122
|
* Execution Stream Controller
|
package/dist/index.js
CHANGED
|
@@ -575,9 +575,11 @@ var DEFAULT_STREAMING_CONFIG = {
|
|
|
575
575
|
activityTimeoutMs: 3e4,
|
|
576
576
|
pollingIntervalMs: 2e3
|
|
577
577
|
};
|
|
578
|
+
var DEFAULT_POLLING_ENABLED = true;
|
|
578
579
|
var ExecutionStreamControllerImpl = class {
|
|
579
580
|
options;
|
|
580
581
|
config;
|
|
582
|
+
pollingEnabled;
|
|
581
583
|
sseClient = null;
|
|
582
584
|
status = "connecting";
|
|
583
585
|
reconnectAttempts = 0;
|
|
@@ -611,6 +613,7 @@ var ExecutionStreamControllerImpl = class {
|
|
|
611
613
|
constructor(options) {
|
|
612
614
|
this.options = options;
|
|
613
615
|
this.config = { ...DEFAULT_STREAMING_CONFIG, ...options.config };
|
|
616
|
+
this.pollingEnabled = options.pollingEnabled ?? DEFAULT_POLLING_ENABLED;
|
|
614
617
|
}
|
|
615
618
|
/**
|
|
616
619
|
* Get the last event ID (for resume support)
|
|
@@ -951,15 +954,61 @@ var ExecutionStreamControllerImpl = class {
|
|
|
951
954
|
if (this.status === "closed") {
|
|
952
955
|
return;
|
|
953
956
|
}
|
|
957
|
+
await this.recoverState();
|
|
958
|
+
if (this.status === "closed") {
|
|
959
|
+
return;
|
|
960
|
+
}
|
|
954
961
|
try {
|
|
955
962
|
await this.connectSSE();
|
|
956
963
|
} catch {
|
|
957
964
|
await this.handleConnectionError(error);
|
|
958
965
|
}
|
|
959
966
|
} else {
|
|
960
|
-
this.
|
|
961
|
-
|
|
962
|
-
|
|
967
|
+
if (this.pollingEnabled) {
|
|
968
|
+
this.status = "fallback_polling";
|
|
969
|
+
this.emit("connectionChange", { connected: false, usingFallback: true });
|
|
970
|
+
this.startPolling();
|
|
971
|
+
} else {
|
|
972
|
+
this.handleError({
|
|
973
|
+
error: "SSE connection failed and polling is disabled",
|
|
974
|
+
errorCode: "connection_failed"
|
|
975
|
+
});
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
/**
|
|
980
|
+
* Recover state by checking execution status.
|
|
981
|
+
*
|
|
982
|
+
* Called during reconnection to catch any events missed while SSE was down.
|
|
983
|
+
* If the execution completed while disconnected, emits completion immediately.
|
|
984
|
+
* Otherwise, emits any new logs that weren't seen via SSE.
|
|
985
|
+
*/
|
|
986
|
+
async recoverState() {
|
|
987
|
+
try {
|
|
988
|
+
const execution = await this.options.getExecution(this.options.executionId);
|
|
989
|
+
if (execution.logs) {
|
|
990
|
+
for (const log of execution.logs) {
|
|
991
|
+
if (!this.seenEventIds.has(log.uuid)) {
|
|
992
|
+
this.seenEventIds.add(log.uuid);
|
|
993
|
+
this.emit("log", log);
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
if (execution.status === "completed") {
|
|
998
|
+
this.stopPolling();
|
|
999
|
+
this.handleComplete(execution);
|
|
1000
|
+
return;
|
|
1001
|
+
}
|
|
1002
|
+
if (execution.status === "failed" || execution.status === "cancelled") {
|
|
1003
|
+
this.stopPolling();
|
|
1004
|
+
this.handleError({
|
|
1005
|
+
error: execution.error ?? `Execution ${execution.status}`,
|
|
1006
|
+
errorCode: execution.status
|
|
1007
|
+
});
|
|
1008
|
+
return;
|
|
1009
|
+
}
|
|
1010
|
+
} catch (err) {
|
|
1011
|
+
console.warn("[SDK:StreamController] State recovery failed (non-fatal):", err);
|
|
963
1012
|
}
|
|
964
1013
|
}
|
|
965
1014
|
/**
|