@bastani/atomic 0.9.40-alpha.2 → 0.9.41-alpha.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.
- package/CHANGELOG.md +80 -0
- package/README.md +1 -1
- package/dist/builtin/intercom/CHANGELOG.md +26 -0
- package/dist/builtin/intercom/README.md +1 -1
- package/dist/builtin/intercom/broker/broker.ts +24 -21
- package/dist/builtin/intercom/broker/client.ts +97 -6
- package/dist/builtin/intercom/broker/list-reply.ts +53 -0
- package/dist/builtin/intercom/index.bundle.mjs +278 -46
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/intercom/recoverable-disconnect.ts +27 -1
- package/dist/builtin/intercom/types.ts +8 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/CHANGELOG.md +45 -0
- package/dist/builtin/subagents/README.md +14 -0
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +99 -19
- package/dist/builtin/web-access/CHANGELOG.md +6 -0
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/CHANGELOG.md +44 -0
- package/dist/builtin/workflows/README.md +2 -0
- package/dist/builtin/workflows/package.json +1 -1
- package/dist/builtin/workflows/src/authoring.d.ts +1 -1
- package/dist/builtin/workflows/src/durable/journal/internal.d.ts +16 -0
- package/dist/builtin/workflows/src/durable/journal/legacy-journal-tables.d.ts +9 -0
- package/dist/builtin/workflows/src/durable/journal/sql-run-journal.d.ts +6 -0
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +441 -90
- package/dist/builtin/workflows/src/index.js +226 -34
- package/dist/builtin/workflows/src/shared/authoring-contract-stage.d.ts +17 -1
- package/dist/cli/credential-print.d.ts.map +1 -1
- package/dist/cli/credential-print.js +1 -1
- package/dist/cli/credential-print.js.map +1 -1
- package/dist/config.d.ts +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -0
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-extension-bindings.d.ts +2 -1
- package/dist/core/agent-session-extension-bindings.d.ts.map +1 -1
- package/dist/core/agent-session-extension-bindings.js +33 -18
- package/dist/core/agent-session-extension-bindings.js.map +1 -1
- package/dist/core/agent-session-methods.d.ts +2 -1
- package/dist/core/agent-session-methods.d.ts.map +1 -1
- package/dist/core/agent-session-methods.js.map +1 -1
- package/dist/core/agent-session-prompt.d.ts.map +1 -1
- package/dist/core/agent-session-prompt.js +114 -21
- package/dist/core/agent-session-prompt.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +1 -1
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +6 -0
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-state.d.ts +19 -1
- package/dist/core/agent-session-state.d.ts.map +1 -1
- package/dist/core/agent-session-state.js +41 -6
- package/dist/core/agent-session-state.js.map +1 -1
- package/dist/core/auth-storage-backends.d.ts +3 -1
- package/dist/core/auth-storage-backends.d.ts.map +1 -1
- package/dist/core/auth-storage-backends.js +79 -12
- package/dist/core/auth-storage-backends.js.map +1 -1
- package/dist/core/client-identity.d.ts +8 -0
- package/dist/core/client-identity.d.ts.map +1 -0
- package/dist/core/client-identity.js +16 -0
- package/dist/core/client-identity.js.map +1 -0
- package/dist/core/compaction/planner-outcome.d.ts.map +1 -1
- package/dist/core/compaction/planner-outcome.js +2 -1
- package/dist/core/compaction/planner-outcome.js.map +1 -1
- package/dist/core/execution-model-router.d.ts +18 -0
- package/dist/core/execution-model-router.d.ts.map +1 -1
- package/dist/core/execution-model-router.js +14 -8
- package/dist/core/execution-model-router.js.map +1 -1
- package/dist/core/extension-oauth-refresh-rejection.d.ts +12 -0
- package/dist/core/extension-oauth-refresh-rejection.d.ts.map +1 -0
- package/dist/core/extension-oauth-refresh-rejection.js +70 -0
- package/dist/core/extension-oauth-refresh-rejection.js.map +1 -0
- package/dist/core/extension-startup-failure.d.ts +30 -0
- package/dist/core/extension-startup-failure.d.ts.map +1 -0
- package/dist/core/extension-startup-failure.js +62 -0
- package/dist/core/extension-startup-failure.js.map +1 -0
- package/dist/core/extensions/context-types.d.ts +2 -0
- package/dist/core/extensions/context-types.d.ts.map +1 -1
- package/dist/core/extensions/context-types.js.map +1 -1
- package/dist/core/extensions/provider-types.d.ts +2 -0
- package/dist/core/extensions/provider-types.d.ts.map +1 -1
- package/dist/core/extensions/provider-types.js.map +1 -1
- package/dist/core/extensions/runner-context.d.ts +1 -0
- package/dist/core/extensions/runner-context.d.ts.map +1 -1
- package/dist/core/extensions/runner-context.js +8 -0
- package/dist/core/extensions/runner-context.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +1 -0
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +3 -0
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/runtime-types.d.ts +1 -0
- package/dist/core/extensions/runtime-types.d.ts.map +1 -1
- package/dist/core/extensions/runtime-types.js.map +1 -1
- package/dist/core/extensions/workflow-run-control-hub.d.ts +1 -0
- package/dist/core/extensions/workflow-run-control-hub.d.ts.map +1 -1
- package/dist/core/extensions/workflow-run-control-hub.js +3 -0
- package/dist/core/extensions/workflow-run-control-hub.js.map +1 -1
- package/dist/core/extensions/workflow-run-control.d.ts +8 -0
- package/dist/core/extensions/workflow-run-control.d.ts.map +1 -1
- package/dist/core/extensions/workflow-run-control.js.map +1 -1
- package/dist/core/model-fallback-failures.d.ts.map +1 -1
- package/dist/core/model-fallback-failures.js +12 -0
- package/dist/core/model-fallback-failures.js.map +1 -1
- package/dist/core/model-resolver-defaults.js +1 -1
- package/dist/core/model-resolver-defaults.js.map +1 -1
- package/dist/core/model-runtime-streaming.d.ts.map +1 -1
- package/dist/core/model-runtime-streaming.js +9 -3
- package/dist/core/model-runtime-streaming.js.map +1 -1
- package/dist/core/model-runtime.d.ts +5 -0
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +6 -0
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/provider-composer-internal.d.ts +6 -5
- package/dist/core/provider-composer-internal.d.ts.map +1 -1
- package/dist/core/provider-composer-internal.js +13 -2
- package/dist/core/provider-composer-internal.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +12 -4
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/storage/session/sql-session-store.d.ts +35 -0
- package/dist/core/storage/session/sql-session-store.d.ts.map +1 -1
- package/dist/core/storage/session/sql-session-store.js +158 -42
- package/dist/core/storage/session/sql-session-store.js.map +1 -1
- package/dist/core/structured-output/deadline.d.ts +40 -0
- package/dist/core/structured-output/deadline.d.ts.map +1 -0
- package/dist/core/structured-output/deadline.js +110 -0
- package/dist/core/structured-output/deadline.js.map +1 -0
- package/dist/core/structured-output/index.d.ts.map +1 -1
- package/dist/core/structured-output/index.js +103 -47
- package/dist/core/structured-output/index.js.map +1 -1
- package/dist/core/structured-output/rejection-detail.d.ts +9 -0
- package/dist/core/structured-output/rejection-detail.d.ts.map +1 -0
- package/dist/core/structured-output/rejection-detail.js +129 -0
- package/dist/core/structured-output/rejection-detail.js.map +1 -0
- package/dist/core/structured-output/types.d.ts +8 -1
- package/dist/core/structured-output/types.d.ts.map +1 -1
- package/dist/core/structured-output/types.js.map +1 -1
- package/dist/core/tasks/completion.d.ts +7 -1
- package/dist/core/tasks/completion.d.ts.map +1 -1
- package/dist/core/tasks/completion.js +28 -6
- package/dist/core/tasks/completion.js.map +1 -1
- package/dist/core/tasks/contracts.d.ts +6 -1
- package/dist/core/tasks/contracts.d.ts.map +1 -1
- package/dist/core/tasks/contracts.js.map +1 -1
- package/dist/core/tasks/pause.d.ts +2 -1
- package/dist/core/tasks/pause.d.ts.map +1 -1
- package/dist/core/tasks/pause.js +3 -2
- package/dist/core/tasks/pause.js.map +1 -1
- package/dist/core/tools/bash-pty-native.d.ts.map +1 -1
- package/dist/core/tools/bash-pty-native.js +10 -5
- package/dist/core/tools/bash-pty-native.js.map +1 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +16 -32
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/kill.d.ts.map +1 -1
- package/dist/core/tools/kill.js +17 -3
- package/dist/core/tools/kill.js.map +1 -1
- package/dist/core/tools/shell-task-render.d.ts +55 -0
- package/dist/core/tools/shell-task-render.d.ts.map +1 -0
- package/dist/core/tools/shell-task-render.js +123 -0
- package/dist/core/tools/shell-task-render.js.map +1 -0
- package/dist/core/tools/shell-task-status.d.ts +52 -0
- package/dist/core/tools/shell-task-status.d.ts.map +1 -0
- package/dist/core/tools/shell-task-status.js +184 -0
- package/dist/core/tools/shell-task-status.js.map +1 -0
- package/dist/core/tools/structured-output.d.ts +5 -0
- package/dist/core/tools/structured-output.d.ts.map +1 -1
- package/dist/core/tools/structured-output.js +3 -0
- package/dist/core/tools/structured-output.js.map +1 -1
- package/dist/extensions/codemode/execute.d.ts.map +1 -1
- package/dist/extensions/codemode/execute.js +134 -57
- package/dist/extensions/codemode/execute.js.map +1 -1
- package/dist/extensions/mcp/config.d.ts.map +1 -1
- package/dist/extensions/mcp/config.js +3 -2
- package/dist/extensions/mcp/config.js.map +1 -1
- package/dist/index-extensions.d.ts +1 -0
- package/dist/index-extensions.d.ts.map +1 -1
- package/dist/index-extensions.js +3 -0
- package/dist/index-extensions.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +19 -6
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/task-row.d.ts.map +1 -1
- package/dist/modes/interactive/components/task-row.js +11 -1
- package/dist/modes/interactive/components/task-row.js.map +1 -1
- package/dist/modes/interactive/interactive-auth-routing.js +12 -10
- package/dist/modes/interactive/interactive-auth-routing.js.map +1 -1
- package/dist/modes/interactive/interactive-extension-custom-ui.js +20 -30
- package/dist/modes/interactive/interactive-extension-custom-ui.js.map +1 -1
- package/dist/modes/interactive/interactive-extension-dialogs.js +23 -96
- package/dist/modes/interactive/interactive-extension-dialogs.js.map +1 -1
- package/dist/modes/interactive/interactive-extension-runtime.js +7 -8
- package/dist/modes/interactive/interactive-extension-runtime.js.map +1 -1
- package/dist/modes/interactive/interactive-input-handling.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-input-handling.js +27 -4
- package/dist/modes/interactive/interactive-input-handling.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-base.d.ts +20 -10
- package/dist/modes/interactive/interactive-mode-base.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-base.js +40 -5
- package/dist/modes/interactive/interactive-mode-base.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-deps.d.ts +1 -1
- package/dist/modes/interactive/interactive-mode-deps.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-deps.js +1 -1
- package/dist/modes/interactive/interactive-mode-deps.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-surface.d.ts +2 -4
- package/dist/modes/interactive/interactive-mode-surface.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-surface.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-types.d.ts +4 -1
- package/dist/modes/interactive/interactive-mode-types.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-types.js.map +1 -1
- package/dist/modes/interactive/interactive-prompt-restore.d.ts +3 -0
- package/dist/modes/interactive/interactive-prompt-restore.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-prompt-restore.js +9 -1
- package/dist/modes/interactive/interactive-prompt-restore.js.map +1 -1
- package/dist/modes/interactive/interactive-prompt-turn.js +30 -2
- package/dist/modes/interactive/interactive-prompt-turn.js.map +1 -1
- package/dist/modes/interactive/interactive-queueing.js +43 -8
- package/dist/modes/interactive/interactive-queueing.js.map +1 -1
- package/dist/modes/interactive/interactive-startup.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-startup.js +12 -3
- package/dist/modes/interactive/interactive-startup.js.map +1 -1
- package/dist/modes/interactive/theme/color-utils.d.ts +6 -1
- package/dist/modes/interactive/theme/color-utils.d.ts.map +1 -1
- package/dist/modes/interactive/theme/color-utils.js +39 -17
- package/dist/modes/interactive/theme/color-utils.js.map +1 -1
- package/dist/modes/interactive/theme/theme-class.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme-class.js +2 -2
- package/dist/modes/interactive/theme/theme-class.js.map +1 -1
- package/dist/modes/interactive/theme/theme-tokens.d.ts +6 -0
- package/dist/modes/interactive/theme/theme-tokens.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme-tokens.js +7 -3
- package/dist/modes/interactive/theme/theme-tokens.js.map +1 -1
- package/dist/modes/interactive-engine/isolated-auth.d.ts +3 -0
- package/dist/modes/interactive-engine/isolated-auth.d.ts.map +1 -1
- package/dist/modes/interactive-engine/isolated-auth.js +13 -1
- package/dist/modes/interactive-engine/isolated-auth.js.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.js +11 -2
- package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
- package/dist/modes/interactive-engine/remote-model-catalog.d.ts +8 -0
- package/dist/modes/interactive-engine/remote-model-catalog.d.ts.map +1 -1
- package/dist/modes/interactive-engine/remote-model-catalog.js +54 -0
- package/dist/modes/interactive-engine/remote-model-catalog.js.map +1 -1
- package/dist/modes/rpc/rpc-command-handler.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-command-handler.js +4 -13
- package/dist/modes/rpc/rpc-command-handler.js.map +1 -1
- package/dist/modes/rpc/rpc-model-catalog.d.ts +9 -0
- package/dist/modes/rpc/rpc-model-catalog.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-model-catalog.js +19 -0
- package/dist/modes/rpc/rpc-model-catalog.js.map +1 -0
- package/dist/modes/rpc/rpc-provider-auth.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-provider-auth.js +2 -6
- package/dist/modes/rpc/rpc-provider-auth.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +6 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/utils/changelog.d.ts +6 -0
- package/dist/utils/changelog.d.ts.map +1 -1
- package/dist/utils/changelog.js +11 -0
- package/dist/utils/changelog.js.map +1 -1
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js +4 -0
- package/dist/utils/clipboard.js.map +1 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +3 -2
- package/dist/utils/tools-manager.js.map +1 -1
- package/docs/background-tasks.md +5 -3
- package/docs/codemode.md +2 -2
- package/docs/custom-provider/oauth.md +42 -1
- package/docs/custom-provider/registration.md +2 -0
- package/docs/environment-variables.md +1 -0
- package/docs/extensions/api-reference.md +3 -4
- package/docs/extensions/authoring.md +1 -1
- package/docs/extensions/events.md +1 -1
- package/docs/providers.md +3 -3
- package/docs/rpc/protocol.md +4 -2
- package/docs/sdk/reference.md +2 -0
- package/docs/sdk/structured-decisions.md +7 -5
- package/docs/sdk.md +5 -2
- package/docs/settings.md +4 -2
- package/docs/subagents/reference.md +1 -1
- package/docs/subagents.md +15 -1
- package/docs/themes/reference.md +3 -1
- package/docs/usage.md +3 -1
- package/docs/workflows/api-reference.md +28 -0
- package/docs/workflows/operations.md +2 -2
- package/npm-shrinkwrap.json +32 -32
- package/package.json +3 -3
- package/dist/core/provider-attribution.d.ts +0 -4
- package/dist/core/provider-attribution.d.ts.map +0 -1
- package/dist/core/provider-attribution.js +0 -87
- package/dist/core/provider-attribution.js.map +0 -1
|
@@ -145,13 +145,26 @@ function isRecoverableIntercomDisconnect(error) {
|
|
|
145
145
|
return false;
|
|
146
146
|
if (current instanceof IntercomClientDisconnectedError)
|
|
147
147
|
return true;
|
|
148
|
+
if (current instanceof IntercomBrokerTimeoutError)
|
|
149
|
+
return true;
|
|
148
150
|
if (current instanceof IntercomLiveRouteRefusedError)
|
|
149
151
|
return current.transient;
|
|
150
152
|
current = current.cause;
|
|
151
153
|
}
|
|
152
154
|
return false;
|
|
153
155
|
}
|
|
154
|
-
|
|
156
|
+
function isIntercomBrokerTimeout(error) {
|
|
157
|
+
let current = error;
|
|
158
|
+
for (let depth = 0;depth <= MAX_CAUSE_DEPTH; depth += 1) {
|
|
159
|
+
if (!(current instanceof Error))
|
|
160
|
+
return false;
|
|
161
|
+
if (current instanceof IntercomBrokerTimeoutError)
|
|
162
|
+
return true;
|
|
163
|
+
current = current.cause;
|
|
164
|
+
}
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
var RECOVERABLE_DISCONNECT_MESSAGE = "Client disconnected", MAX_CAUSE_DEPTH = 8, IntercomClientDisconnectedError, IntercomBrokerTimeoutError;
|
|
155
168
|
var init_recoverable_disconnect = __esm(() => {
|
|
156
169
|
init_live_route_refusal();
|
|
157
170
|
IntercomClientDisconnectedError = class IntercomClientDisconnectedError extends Error {
|
|
@@ -161,6 +174,13 @@ var init_recoverable_disconnect = __esm(() => {
|
|
|
161
174
|
this.name = "IntercomClientDisconnectedError";
|
|
162
175
|
}
|
|
163
176
|
};
|
|
177
|
+
IntercomBrokerTimeoutError = class IntercomBrokerTimeoutError extends Error {
|
|
178
|
+
intercomRecoverableDisconnect = true;
|
|
179
|
+
constructor(message, options) {
|
|
180
|
+
super(message, options);
|
|
181
|
+
this.name = "IntercomBrokerTimeoutError";
|
|
182
|
+
}
|
|
183
|
+
};
|
|
164
184
|
});
|
|
165
185
|
|
|
166
186
|
// dist/builtin/intercom/retry-policy.ts
|
|
@@ -177,6 +197,10 @@ var init_retry_policy = __esm(() => {
|
|
|
177
197
|
function reconnectDelayMs(attempt) {
|
|
178
198
|
return BACKOFF_MS[Math.min(attempt, BACKOFF_MS.length - 1)];
|
|
179
199
|
}
|
|
200
|
+
function jitteredReconnectDelayMs(attempt, random = Math.random) {
|
|
201
|
+
const ceiling = reconnectDelayMs(attempt);
|
|
202
|
+
return Math.round(ceiling / 2 + ceiling / 2 * random());
|
|
203
|
+
}
|
|
180
204
|
var BACKOFF_MS;
|
|
181
205
|
var init_reconnect_backoff = __esm(() => {
|
|
182
206
|
BACKOFF_MS = [1000, 2000, 5000, 1e4, 30000];
|
|
@@ -838,7 +862,7 @@ function isWorkflowFutureStageRosterEntries(value) {
|
|
|
838
862
|
function isWorkflowStageRosterEntries(value) {
|
|
839
863
|
return Array.isArray(value) && value.every((entry) => typeof entry === "object" && entry !== null && entry.kind === "workflow-stage" && typeof entry.runId === "string" && typeof entry.stageId === "string" && typeof entry.stageName === "string" && typeof entry.target === "string" && (entry.lifecycle === "pending" || entry.lifecycle === "running") && typeof entry.group === "string" && (entry.sessionId === undefined || typeof entry.sessionId === "string"));
|
|
840
864
|
}
|
|
841
|
-
var BROKER_SOCKET, GROUP_REQUEST_TIMEOUT_MS = 5000, PRESENCE_ACK_TIMEOUT_MS = 5000, RESTORING_RECIPIENT_REQUEST_TIMEOUT_MS = 5000, HELD_SEND_GRACE_MS = 5000, IntercomClient;
|
|
865
|
+
var BROKER_SOCKET, BROKER_CONNECT_TIMEOUT_MS = 1e4, PENDING_STAGE_ROUTE_ACK_TIMEOUT_MS = 1e4, GROUP_REQUEST_TIMEOUT_MS = 5000, PRESENCE_ACK_TIMEOUT_MS = 5000, RESTORING_RECIPIENT_REQUEST_TIMEOUT_MS = 5000, HELD_SEND_GRACE_MS = 5000, IntercomClient;
|
|
842
866
|
var init_client = __esm(() => {
|
|
843
867
|
init_paths();
|
|
844
868
|
init_pending_send_registry();
|
|
@@ -851,7 +875,9 @@ var init_client = __esm(() => {
|
|
|
851
875
|
returnAddress;
|
|
852
876
|
preferredSessionId;
|
|
853
877
|
acknowledgesReceipt;
|
|
878
|
+
connectTimeoutMs;
|
|
854
879
|
brokerAcknowledgesReceipt = false;
|
|
880
|
+
brokerAcknowledgesPendingStageRoutes = false;
|
|
855
881
|
socket = null;
|
|
856
882
|
_sessionId = null;
|
|
857
883
|
_supervisorSessionId = null;
|
|
@@ -864,6 +890,7 @@ var init_client = __esm(() => {
|
|
|
864
890
|
pendingMemberships = new Map;
|
|
865
891
|
_groups = normalizeGroups();
|
|
866
892
|
pendingLiveWorkflowStageRoutes = new Map;
|
|
893
|
+
pendingStageRouteRegistrations = new Map;
|
|
867
894
|
pendingSupervisorAuthorizations = new Map;
|
|
868
895
|
pendingRestoringRecipientRequests = new Map;
|
|
869
896
|
disconnecting = false;
|
|
@@ -875,6 +902,7 @@ var init_client = __esm(() => {
|
|
|
875
902
|
this.returnAddress = returnAddress;
|
|
876
903
|
this.preferredSessionId = options.preferredSessionId;
|
|
877
904
|
this.acknowledgesReceipt = options.acknowledgesReceipt === true;
|
|
905
|
+
this.connectTimeoutMs = options.connectTimeoutMs ?? BROKER_CONNECT_TIMEOUT_MS;
|
|
878
906
|
}
|
|
879
907
|
failPending(error) {
|
|
880
908
|
this.pendingSends.rejectAll(error);
|
|
@@ -892,6 +920,8 @@ var init_client = __esm(() => {
|
|
|
892
920
|
pending.reject(error);
|
|
893
921
|
for (const pending of this.pendingLiveWorkflowStageRoutes.values())
|
|
894
922
|
pending.reject(error);
|
|
923
|
+
for (const pending of this.pendingStageRouteRegistrations.values())
|
|
924
|
+
pending.reject(error);
|
|
895
925
|
this.pendingLists.clear();
|
|
896
926
|
this.pendingGroupLists.clear();
|
|
897
927
|
this.pendingSupervisorAuthorizations.clear();
|
|
@@ -899,6 +929,7 @@ var init_client = __esm(() => {
|
|
|
899
929
|
this.pendingPresence.clear();
|
|
900
930
|
this.pendingMemberships.clear();
|
|
901
931
|
this.pendingLiveWorkflowStageRoutes.clear();
|
|
932
|
+
this.pendingStageRouteRegistrations.clear();
|
|
902
933
|
}
|
|
903
934
|
get sessionId() {
|
|
904
935
|
return this._sessionId;
|
|
@@ -945,9 +976,9 @@ var init_client = __esm(() => {
|
|
|
945
976
|
this.socket = null;
|
|
946
977
|
}
|
|
947
978
|
socket.destroy();
|
|
948
|
-
reject(new
|
|
979
|
+
reject(new IntercomBrokerTimeoutError("Connection timeout"));
|
|
949
980
|
}
|
|
950
|
-
},
|
|
981
|
+
}, this.connectTimeoutMs);
|
|
951
982
|
let connectionEstablished = false;
|
|
952
983
|
const onRegistered = () => {
|
|
953
984
|
settled = true;
|
|
@@ -980,6 +1011,7 @@ var init_client = __esm(() => {
|
|
|
980
1011
|
this._sessionId = null;
|
|
981
1012
|
this._supervisorSessionId = null;
|
|
982
1013
|
this.brokerAcknowledgesReceipt = false;
|
|
1014
|
+
this.brokerAcknowledgesPendingStageRoutes = false;
|
|
983
1015
|
this._messageSource = undefined;
|
|
984
1016
|
this.disconnectError = null;
|
|
985
1017
|
if (connectionEstablished && !wasDisconnecting) {
|
|
@@ -1057,7 +1089,7 @@ var init_client = __esm(() => {
|
|
|
1057
1089
|
}
|
|
1058
1090
|
switch (brokerMessage.type) {
|
|
1059
1091
|
case "registered": {
|
|
1060
|
-
if (typeof brokerMessage.sessionId !== "string" || brokerMessage.supervisorSessionId !== undefined && typeof brokerMessage.supervisorSessionId !== "string" || brokerMessage.acknowledgesReceipt !== undefined && brokerMessage.acknowledgesReceipt !== true) {
|
|
1092
|
+
if (typeof brokerMessage.sessionId !== "string" || brokerMessage.supervisorSessionId !== undefined && typeof brokerMessage.supervisorSessionId !== "string" || brokerMessage.acknowledgesReceipt !== undefined && brokerMessage.acknowledgesReceipt !== true || brokerMessage.acknowledgesPendingStageRoutes !== undefined && brokerMessage.acknowledgesPendingStageRoutes !== true) {
|
|
1061
1093
|
throw new Error("Invalid registered message");
|
|
1062
1094
|
}
|
|
1063
1095
|
if (this._sessionId !== null) {
|
|
@@ -1066,6 +1098,7 @@ var init_client = __esm(() => {
|
|
|
1066
1098
|
this._sessionId = brokerMessage.sessionId;
|
|
1067
1099
|
this._supervisorSessionId = typeof brokerMessage.supervisorSessionId === "string" ? brokerMessage.supervisorSessionId : null;
|
|
1068
1100
|
this.brokerAcknowledgesReceipt = this.acknowledgesReceipt && brokerMessage.acknowledgesReceipt === true;
|
|
1101
|
+
this.brokerAcknowledgesPendingStageRoutes = brokerMessage.acknowledgesPendingStageRoutes === true;
|
|
1069
1102
|
this.emit("_registered", { type: "registered", sessionId: brokerMessage.sessionId });
|
|
1070
1103
|
break;
|
|
1071
1104
|
}
|
|
@@ -1093,8 +1126,8 @@ var init_client = __esm(() => {
|
|
|
1093
1126
|
break;
|
|
1094
1127
|
}
|
|
1095
1128
|
case "sessions": {
|
|
1096
|
-
const { requestId, sessions, workflowStages, workflowFutureStages } = brokerMessage;
|
|
1097
|
-
if (typeof requestId !== "string" || !Array.isArray(sessions) || !sessions.every(isSessionInfo) || workflowStages !== undefined && !isWorkflowStageRosterEntries(workflowStages) || workflowFutureStages !== undefined && !isWorkflowFutureStageRosterEntries(workflowFutureStages)) {
|
|
1129
|
+
const { requestId, sessions, workflowStages, workflowFutureStages, restricted } = brokerMessage;
|
|
1130
|
+
if (typeof requestId !== "string" || !Array.isArray(sessions) || !sessions.every(isSessionInfo) || workflowStages !== undefined && !isWorkflowStageRosterEntries(workflowStages) || workflowFutureStages !== undefined && !isWorkflowFutureStageRosterEntries(workflowFutureStages) || restricted !== undefined && restricted !== true) {
|
|
1098
1131
|
throw new Error("Invalid sessions message");
|
|
1099
1132
|
}
|
|
1100
1133
|
const pending = this.pendingLists.get(requestId);
|
|
@@ -1104,7 +1137,8 @@ var init_client = __esm(() => {
|
|
|
1104
1137
|
pending.resolve({
|
|
1105
1138
|
sessions,
|
|
1106
1139
|
workflowStages: workflowStages ?? [],
|
|
1107
|
-
workflowFutureStages: workflowFutureStages ?? []
|
|
1140
|
+
workflowFutureStages: workflowFutureStages ?? [],
|
|
1141
|
+
...restricted === true ? { restricted: true } : {}
|
|
1108
1142
|
});
|
|
1109
1143
|
break;
|
|
1110
1144
|
}
|
|
@@ -1189,6 +1223,17 @@ var init_client = __esm(() => {
|
|
|
1189
1223
|
this.emit("pending_stage_route_revoked", { runId });
|
|
1190
1224
|
break;
|
|
1191
1225
|
}
|
|
1226
|
+
case "pending_stage_route_registered": {
|
|
1227
|
+
const { requestId } = brokerMessage;
|
|
1228
|
+
if (typeof requestId !== "string")
|
|
1229
|
+
throw new Error("Invalid pending-stage route registration acknowledgement");
|
|
1230
|
+
const pending = this.pendingStageRouteRegistrations.get(requestId);
|
|
1231
|
+
if (!pending)
|
|
1232
|
+
return;
|
|
1233
|
+
this.pendingStageRouteRegistrations.delete(requestId);
|
|
1234
|
+
pending.resolve();
|
|
1235
|
+
break;
|
|
1236
|
+
}
|
|
1192
1237
|
case "live_workflow_stage_route_registered": {
|
|
1193
1238
|
const { requestId } = brokerMessage;
|
|
1194
1239
|
if (typeof requestId !== "string")
|
|
@@ -1602,6 +1647,59 @@ var init_client = __esm(() => {
|
|
|
1602
1647
|
...dormant === true ? { dormant: true } : {}
|
|
1603
1648
|
});
|
|
1604
1649
|
}
|
|
1650
|
+
registerPendingStageRouteAcknowledged(runId, group, capability, stages, possibleStages, parent, dormant) {
|
|
1651
|
+
let socket;
|
|
1652
|
+
try {
|
|
1653
|
+
socket = this.requireActiveSocket();
|
|
1654
|
+
} catch (error) {
|
|
1655
|
+
return Promise.reject(toError(error));
|
|
1656
|
+
}
|
|
1657
|
+
if (!this.brokerAcknowledgesPendingStageRoutes) {
|
|
1658
|
+
try {
|
|
1659
|
+
this.registerPendingStageRoute(runId, group, capability, stages, possibleStages, parent, dormant);
|
|
1660
|
+
} catch (error) {
|
|
1661
|
+
return Promise.reject(toError(error));
|
|
1662
|
+
}
|
|
1663
|
+
return this.listSessions().then(() => {
|
|
1664
|
+
return;
|
|
1665
|
+
});
|
|
1666
|
+
}
|
|
1667
|
+
return new Promise((resolve, reject) => {
|
|
1668
|
+
const requestId = randomUUID2();
|
|
1669
|
+
const timeout = setTimeout(() => {
|
|
1670
|
+
if (!this.pendingStageRouteRegistrations.delete(requestId))
|
|
1671
|
+
return;
|
|
1672
|
+
reject(new IntercomBrokerTimeoutError("Pending-stage route registration timeout"));
|
|
1673
|
+
}, PENDING_STAGE_ROUTE_ACK_TIMEOUT_MS);
|
|
1674
|
+
this.pendingStageRouteRegistrations.set(requestId, {
|
|
1675
|
+
resolve: () => {
|
|
1676
|
+
clearTimeout(timeout);
|
|
1677
|
+
resolve();
|
|
1678
|
+
},
|
|
1679
|
+
reject: (error) => {
|
|
1680
|
+
clearTimeout(timeout);
|
|
1681
|
+
reject(error);
|
|
1682
|
+
}
|
|
1683
|
+
});
|
|
1684
|
+
try {
|
|
1685
|
+
writeMessage(socket, {
|
|
1686
|
+
type: "register_pending_stage_route",
|
|
1687
|
+
requestId,
|
|
1688
|
+
runId,
|
|
1689
|
+
group,
|
|
1690
|
+
capability,
|
|
1691
|
+
stages,
|
|
1692
|
+
possibleStages,
|
|
1693
|
+
...parent === undefined ? {} : { parent },
|
|
1694
|
+
...dormant === true ? { dormant: true } : {}
|
|
1695
|
+
});
|
|
1696
|
+
} catch (error) {
|
|
1697
|
+
clearTimeout(timeout);
|
|
1698
|
+
this.pendingStageRouteRegistrations.delete(requestId);
|
|
1699
|
+
reject(toError(error));
|
|
1700
|
+
}
|
|
1701
|
+
});
|
|
1702
|
+
}
|
|
1605
1703
|
registerLiveWorkflowStageRoute(runId, stageKeys, capability) {
|
|
1606
1704
|
let socket;
|
|
1607
1705
|
try {
|
|
@@ -3973,8 +4071,10 @@ ${lines.join(`
|
|
|
3973
4071
|
...peeked.workflowStages.map(formatWorkflowStageRow),
|
|
3974
4072
|
...(peeked.workflowFutureStages ?? []).map(formatWorkflowFutureStageRow)
|
|
3975
4073
|
];
|
|
3976
|
-
const
|
|
3977
|
-
|
|
4074
|
+
const heading = `**Group [${requestedGroup}] (read-only peek):**`;
|
|
4075
|
+
const section = peeked.restricted === true ? `${heading}
|
|
4076
|
+
Workflow group ${requestedGroup} is visible only to its members. Join it with \`intercom join\` to list its stages.` : rows.length === 0 ? `${heading}
|
|
4077
|
+
No sessions or workflow stages in this group.` : `${heading}
|
|
3978
4078
|
${rows.join(`
|
|
3979
4079
|
`)}`;
|
|
3980
4080
|
return {
|
|
@@ -3987,7 +4087,8 @@ ${section}` }],
|
|
|
3987
4087
|
groups: ownGroups,
|
|
3988
4088
|
peekGroup: requestedGroup,
|
|
3989
4089
|
workflowStages: peeked.workflowStages,
|
|
3990
|
-
...(peeked.workflowFutureStages?.length ?? 0) === 0 ? {} : { workflowFutureStages: peeked.workflowFutureStages }
|
|
4090
|
+
...(peeked.workflowFutureStages?.length ?? 0) === 0 ? {} : { workflowFutureStages: peeked.workflowFutureStages },
|
|
4091
|
+
...peeked.restricted === true ? { restricted: true } : {}
|
|
3991
4092
|
}
|
|
3992
4093
|
};
|
|
3993
4094
|
}
|
|
@@ -6917,6 +7018,63 @@ function clearRuntimeIntercomGroup(sessionId) {
|
|
|
6917
7018
|
}
|
|
6918
7019
|
var init_runtime_group = () => {};
|
|
6919
7020
|
|
|
7021
|
+
// dist/builtin/intercom/route-retry-waiters.ts
|
|
7022
|
+
class RouteRetryWaiters {
|
|
7023
|
+
pending = null;
|
|
7024
|
+
join() {
|
|
7025
|
+
this.pending ??= Promise.withResolvers();
|
|
7026
|
+
return this.pending.promise;
|
|
7027
|
+
}
|
|
7028
|
+
succeed() {
|
|
7029
|
+
this.settle()?.resolve();
|
|
7030
|
+
}
|
|
7031
|
+
fail(error) {
|
|
7032
|
+
this.settle()?.reject(error);
|
|
7033
|
+
}
|
|
7034
|
+
settle() {
|
|
7035
|
+
const pending = this.pending;
|
|
7036
|
+
this.pending = null;
|
|
7037
|
+
return pending;
|
|
7038
|
+
}
|
|
7039
|
+
}
|
|
7040
|
+
function scheduledRetryFailure(error) {
|
|
7041
|
+
if (isIntercomBrokerTimeout(error) || !isRecoverableIntercomDisconnect(error))
|
|
7042
|
+
return error;
|
|
7043
|
+
return new IntercomBrokerTimeoutError("Connection timeout: the run's route registration retry did not complete", {
|
|
7044
|
+
cause: error
|
|
7045
|
+
});
|
|
7046
|
+
}
|
|
7047
|
+
var init_route_retry_waiters = __esm(() => {
|
|
7048
|
+
init_recoverable_disconnect();
|
|
7049
|
+
});
|
|
7050
|
+
|
|
7051
|
+
// dist/builtin/intercom/route-connect-gate.ts
|
|
7052
|
+
function createConcurrencyGate(limit) {
|
|
7053
|
+
let active = 0;
|
|
7054
|
+
const waiting = [];
|
|
7055
|
+
const release = () => {
|
|
7056
|
+
const next = waiting.shift();
|
|
7057
|
+
if (next === undefined)
|
|
7058
|
+
active -= 1;
|
|
7059
|
+
else
|
|
7060
|
+
next();
|
|
7061
|
+
};
|
|
7062
|
+
return {
|
|
7063
|
+
async run(operation) {
|
|
7064
|
+
if (active < limit)
|
|
7065
|
+
active += 1;
|
|
7066
|
+
else
|
|
7067
|
+
await new Promise((resolve) => waiting.push(resolve));
|
|
7068
|
+
try {
|
|
7069
|
+
return await operation();
|
|
7070
|
+
} finally {
|
|
7071
|
+
release();
|
|
7072
|
+
}
|
|
7073
|
+
}
|
|
7074
|
+
};
|
|
7075
|
+
}
|
|
7076
|
+
var ROUTE_CLIENT_CONNECT_CONCURRENCY = 4;
|
|
7077
|
+
|
|
6920
7078
|
// dist/builtin/intercom/released-stage-peers.ts
|
|
6921
7079
|
function isReleasedStageAnnouncement(value) {
|
|
6922
7080
|
const route = value;
|
|
@@ -7207,6 +7365,7 @@ function piIntercomExtension(pi, testOverrides = {}) {
|
|
|
7207
7365
|
const inboundDeliveries = new InboundMessageAdmission;
|
|
7208
7366
|
const pendingStageRoutes = new Map;
|
|
7209
7367
|
const pendingStageRouteClients = new Map;
|
|
7368
|
+
const routeClientConnectGate = createConcurrencyGate(ROUTE_CLIENT_CONNECT_CONCURRENCY);
|
|
7210
7369
|
const supervisorAuthorizations = new SupervisorAuthorizationRegistry;
|
|
7211
7370
|
const releasedStagePeers = new ReleasedStagePeers({
|
|
7212
7371
|
prepare: () => spawnBrokerIfNeeded(config.brokerCommand, config.brokerArgs),
|
|
@@ -7756,17 +7915,35 @@ function piIntercomExtension(pi, testOverrides = {}) {
|
|
|
7756
7915
|
function pendingStageRouteClientIsCurrent(runId, state, context = runtimeContext, generation = runtimeGeneration) {
|
|
7757
7916
|
return pendingStageRouteClients.get(runId) === state && samePendingStageRoute(pendingStageRoutes.get(runId), state.route) && Boolean(getLiveContext(context, generation));
|
|
7758
7917
|
}
|
|
7918
|
+
function endPendingStageRouteBackoff(state, failure) {
|
|
7919
|
+
if (state.reconnectTimer)
|
|
7920
|
+
clearTimeout(state.reconnectTimer);
|
|
7921
|
+
state.reconnectTimer = null;
|
|
7922
|
+
if (failure === undefined)
|
|
7923
|
+
state.retryWaiters.succeed();
|
|
7924
|
+
else
|
|
7925
|
+
state.retryWaiters.fail(failure);
|
|
7926
|
+
}
|
|
7759
7927
|
function schedulePendingStageRouteReconnect(runId, state) {
|
|
7760
7928
|
if (state.reconnectTimer || state.promise || !pendingStageRouteClientIsCurrent(runId, state))
|
|
7761
7929
|
return;
|
|
7762
7930
|
const scheduledGeneration = runtimeGeneration;
|
|
7763
7931
|
state.reconnectTimer = setTimeout(() => {
|
|
7764
7932
|
state.reconnectTimer = null;
|
|
7765
|
-
if (!pendingStageRouteClientIsCurrent(runId, state, runtimeContext, scheduledGeneration))
|
|
7933
|
+
if (!pendingStageRouteClientIsCurrent(runId, state, runtimeContext, scheduledGeneration)) {
|
|
7934
|
+
endPendingStageRouteBackoff(state, new IntercomClientDisconnectedError);
|
|
7766
7935
|
return;
|
|
7936
|
+
}
|
|
7767
7937
|
state.reconnectAttempt += 1;
|
|
7768
|
-
ensurePendingStageRouteClient(runId, state.route).
|
|
7769
|
-
|
|
7938
|
+
ensurePendingStageRouteClient(runId, state.route).then(() => {
|
|
7939
|
+
state.retryWaiters.succeed();
|
|
7940
|
+
pi.events.emit(ROUTE_RETRY_OUTCOME_EVENT, { runId });
|
|
7941
|
+
}, (error) => {
|
|
7942
|
+
const failure = toError3(error);
|
|
7943
|
+
state.retryWaiters.fail(scheduledRetryFailure(failure));
|
|
7944
|
+
pi.events.emit(ROUTE_RETRY_OUTCOME_EVENT, { runId, error: failure });
|
|
7945
|
+
});
|
|
7946
|
+
}, jitteredReconnectDelayMs(state.reconnectAttempt));
|
|
7770
7947
|
}
|
|
7771
7948
|
function attachPendingStageRouteClientHandlers(runId, state, nextClient) {
|
|
7772
7949
|
nextClient.on("pending_stage_message", (request) => {
|
|
@@ -7787,9 +7964,7 @@ function piIntercomExtension(pi, testOverrides = {}) {
|
|
|
7787
7964
|
if (notice.runId !== runId || state.client !== nextClient)
|
|
7788
7965
|
return;
|
|
7789
7966
|
state.client = null;
|
|
7790
|
-
|
|
7791
|
-
clearTimeout(state.reconnectTimer);
|
|
7792
|
-
state.reconnectTimer = null;
|
|
7967
|
+
endPendingStageRouteBackoff(state, new IntercomClientDisconnectedError);
|
|
7793
7968
|
if (pendingStageRouteClients.get(runId) === state)
|
|
7794
7969
|
pendingStageRouteClients.delete(runId);
|
|
7795
7970
|
if (samePendingStageRoute(pendingStageRoutes.get(runId), state.route))
|
|
@@ -7798,7 +7973,7 @@ function piIntercomExtension(pi, testOverrides = {}) {
|
|
|
7798
7973
|
pi.events.emit(PENDING_STAGE_ROUTE_REVOKED_EVENT, { runId, capability: state.route.capability });
|
|
7799
7974
|
});
|
|
7800
7975
|
}
|
|
7801
|
-
async function ensurePendingStageRouteClient(runId, route) {
|
|
7976
|
+
async function ensurePendingStageRouteClient(runId, route, options = {}) {
|
|
7802
7977
|
const contextAtStart = getLiveContext();
|
|
7803
7978
|
const generationAtStart = runtimeGeneration;
|
|
7804
7979
|
if (!contextAtStart)
|
|
@@ -7806,8 +7981,7 @@ function piIntercomExtension(pi, testOverrides = {}) {
|
|
|
7806
7981
|
let existing = pendingStageRouteClients.get(runId);
|
|
7807
7982
|
if (existing && !samePendingStageRoute(existing.route, route)) {
|
|
7808
7983
|
pendingStageRouteClients.delete(runId);
|
|
7809
|
-
|
|
7810
|
-
clearTimeout(existing.reconnectTimer);
|
|
7984
|
+
endPendingStageRouteBackoff(existing, new IntercomClientDisconnectedError);
|
|
7811
7985
|
try {
|
|
7812
7986
|
await existing.promise;
|
|
7813
7987
|
} catch {}
|
|
@@ -7823,23 +7997,31 @@ function piIntercomExtension(pi, testOverrides = {}) {
|
|
|
7823
7997
|
client: null,
|
|
7824
7998
|
promise: null,
|
|
7825
7999
|
reconnectTimer: null,
|
|
7826
|
-
reconnectAttempt: 0
|
|
8000
|
+
reconnectAttempt: 0,
|
|
8001
|
+
retryWaiters: new RouteRetryWaiters
|
|
7827
8002
|
};
|
|
7828
8003
|
if (!existing)
|
|
7829
8004
|
pendingStageRouteClients.set(runId, state);
|
|
8005
|
+
state.route = route;
|
|
7830
8006
|
if (state.client?.isConnected()) {
|
|
7831
|
-
state.route
|
|
7832
|
-
state.client.registerPendingStageRoute(runId, normalizeGroup(route.group), route.capability, route.stages, route.possibleStages, route.parent, route.dormant === true);
|
|
7833
|
-
await state.client.listSessions();
|
|
8007
|
+
await state.client.registerPendingStageRouteAcknowledged(runId, normalizeGroup(route.group), route.capability, route.stages, route.possibleStages, route.parent, route.dormant === true);
|
|
7834
8008
|
return;
|
|
7835
8009
|
}
|
|
7836
8010
|
if (state.promise) {
|
|
7837
8011
|
await state.promise;
|
|
7838
|
-
return ensurePendingStageRouteClient(runId, route);
|
|
8012
|
+
return ensurePendingStageRouteClient(runId, route, options);
|
|
7839
8013
|
}
|
|
7840
|
-
|
|
8014
|
+
if (state.reconnectTimer !== null && options.bypassBackoff !== true)
|
|
8015
|
+
return state.retryWaiters.join();
|
|
8016
|
+
const promise = routeClientConnectGate.run(async () => {
|
|
8017
|
+
if (!pendingStageRouteClientIsCurrent(runId, state, contextAtStart, generationAtStart)) {
|
|
8018
|
+
throw new Error("Intercom runtime no longer active");
|
|
8019
|
+
}
|
|
7841
8020
|
await spawnBrokerIfNeeded(config.brokerCommand, config.brokerArgs);
|
|
7842
|
-
const
|
|
8021
|
+
const routeReturnAddress = `${currentSessionId}:pending-stage-route:${runId}`;
|
|
8022
|
+
const nextClient = new IntercomClient(routeReturnAddress, {
|
|
8023
|
+
connectTimeoutMs: testOverrides.connectTimeoutMs?.(routeReturnAddress)
|
|
8024
|
+
});
|
|
7843
8025
|
state.client = nextClient;
|
|
7844
8026
|
attachPendingStageRouteClientHandlers(runId, state, nextClient);
|
|
7845
8027
|
await nextClient.connect({ ...buildRegistration(), recipientPurpose: "control", name: undefined, groups: [normalizeGroup(route.group)], group: normalizeGroup(route.group) }, undefined, undefined, readSubagentMessageSource(runtimeContext?.subagentPolicy));
|
|
@@ -7847,14 +8029,14 @@ function piIntercomExtension(pi, testOverrides = {}) {
|
|
|
7847
8029
|
await nextClient.disconnect();
|
|
7848
8030
|
throw new Error("Intercom runtime no longer active");
|
|
7849
8031
|
}
|
|
7850
|
-
nextClient.
|
|
7851
|
-
await nextClient.listSessions();
|
|
8032
|
+
await nextClient.registerPendingStageRouteAcknowledged(runId, normalizeGroup(route.group), route.capability, route.stages, route.possibleStages, route.parent, route.dormant === true);
|
|
7852
8033
|
if (!pendingStageRouteClientIsCurrent(runId, state, contextAtStart, generationAtStart)) {
|
|
7853
8034
|
await nextClient.disconnect();
|
|
7854
8035
|
throw new Error("Intercom runtime no longer active");
|
|
7855
8036
|
}
|
|
7856
8037
|
state.reconnectAttempt = 0;
|
|
7857
|
-
|
|
8038
|
+
endPendingStageRouteBackoff(state);
|
|
8039
|
+
});
|
|
7858
8040
|
state.promise = promise;
|
|
7859
8041
|
try {
|
|
7860
8042
|
await promise;
|
|
@@ -7879,8 +8061,7 @@ function piIntercomExtension(pi, testOverrides = {}) {
|
|
|
7879
8061
|
const states = [...pendingStageRouteClients.values()];
|
|
7880
8062
|
pendingStageRouteClients.clear();
|
|
7881
8063
|
for (const state of states) {
|
|
7882
|
-
|
|
7883
|
-
clearTimeout(state.reconnectTimer);
|
|
8064
|
+
endPendingStageRouteBackoff(state, new IntercomClientDisconnectedError);
|
|
7884
8065
|
try {
|
|
7885
8066
|
await state.promise;
|
|
7886
8067
|
} catch {}
|
|
@@ -7893,13 +8074,14 @@ function piIntercomExtension(pi, testOverrides = {}) {
|
|
|
7893
8074
|
}
|
|
7894
8075
|
}
|
|
7895
8076
|
async function registerPendingStageRoute(activeClient, runId, route) {
|
|
7896
|
-
|
|
7897
|
-
|
|
7898
|
-
activeClient.registerPendingStageRoute(runId, routeGroup, route.capability, route.stages, route.possibleStages, route.parent);
|
|
7899
|
-
await activeClient.listSessions();
|
|
8077
|
+
if (registersOnMainClient(route)) {
|
|
8078
|
+
await activeClient.registerPendingStageRouteAcknowledged(runId, normalizeGroup(route.group), route.capability, route.stages, route.possibleStages, route.parent);
|
|
7900
8079
|
return;
|
|
7901
8080
|
}
|
|
7902
|
-
await ensurePendingStageRouteClient(runId, { ...route, group:
|
|
8081
|
+
await ensurePendingStageRouteClient(runId, { ...route, group: normalizeGroup(route.group) });
|
|
8082
|
+
}
|
|
8083
|
+
function registersOnMainClient(route) {
|
|
8084
|
+
return clientRegistrationGroup === normalizeGroup(route.group) && route.dormant !== true;
|
|
7903
8085
|
}
|
|
7904
8086
|
function persistedIntercomSessionId(ctx, sessionId) {
|
|
7905
8087
|
try {
|
|
@@ -7938,7 +8120,11 @@ function piIntercomExtension(pi, testOverrides = {}) {
|
|
|
7938
8120
|
const nextReconnectPromise = (async () => {
|
|
7939
8121
|
let connectFailed = false;
|
|
7940
8122
|
await ownershipRecorded.promise;
|
|
7941
|
-
const nextClient = new IntercomClient(sessionIdAtStart, {
|
|
8123
|
+
const nextClient = new IntercomClient(sessionIdAtStart, {
|
|
8124
|
+
preferredSessionId,
|
|
8125
|
+
acknowledgesReceipt: true,
|
|
8126
|
+
connectTimeoutMs: testOverrides.connectTimeoutMs?.(sessionIdAtStart)
|
|
8127
|
+
});
|
|
7942
8128
|
client = nextClient;
|
|
7943
8129
|
attachClientHandlers(nextClient);
|
|
7944
8130
|
try {
|
|
@@ -7951,7 +8137,11 @@ function piIntercomExtension(pi, testOverrides = {}) {
|
|
|
7951
8137
|
nextClient.updatePresence({ replyCapability: "terminal" });
|
|
7952
8138
|
await supervisorAuthorizations.restore(nextClient);
|
|
7953
8139
|
for (const [runId, route] of pendingStageRoutes) {
|
|
7954
|
-
|
|
8140
|
+
if (registersOnMainClient(route)) {
|
|
8141
|
+
await registerPendingStageRoute(nextClient, runId, route);
|
|
8142
|
+
continue;
|
|
8143
|
+
}
|
|
8144
|
+
ensurePendingStageRouteClient(runId, { ...route, group: normalizeGroup(route.group) }).catch(() => {});
|
|
7955
8145
|
}
|
|
7956
8146
|
const orchestration = contextAtStart.orchestrationContext;
|
|
7957
8147
|
if (orchestration?.kind === "workflow-stage" && orchestration.pendingStageDelivery !== undefined) {
|
|
@@ -8026,7 +8216,7 @@ function piIntercomExtension(pi, testOverrides = {}) {
|
|
|
8026
8216
|
throw new Error("Pending workflow route is unavailable");
|
|
8027
8217
|
if (client?.isConnected() && clientRegistrationGroup === normalizeGroup(route.group))
|
|
8028
8218
|
return client;
|
|
8029
|
-
await ensurePendingStageRouteClient(runId, route);
|
|
8219
|
+
await ensurePendingStageRouteClient(runId, route, { bypassBackoff: true });
|
|
8030
8220
|
const routeClient = pendingStageRouteClients.get(runId)?.client;
|
|
8031
8221
|
if (!routeClient?.isConnected())
|
|
8032
8222
|
throw new Error("Pending workflow route is disconnected");
|
|
@@ -8246,7 +8436,7 @@ function piIntercomExtension(pi, testOverrides = {}) {
|
|
|
8246
8436
|
syncPresenceIdentity
|
|
8247
8437
|
});
|
|
8248
8438
|
}
|
|
8249
|
-
var INTERCOM_SESSION_ID_ENV, PENDING_STAGE_ROUTE_EVENT = "atomic:workflow-pending-stage-route", PENDING_STAGE_MESSAGE_EVENT = "atomic:workflow-pending-stage-message", PENDING_STAGE_UNDELIVERABLE_EVENT = "atomic:workflow-pending-stage-undeliverable", STICKY_LIVE_DELIVERED_EVENT = "atomic:workflow-sticky-live-delivered", PENDING_STAGE_ROUTE_REVOKED_EVENT = "atomic:workflow-pending-stage-route-revoked";
|
|
8439
|
+
var INTERCOM_SESSION_ID_ENV, PENDING_STAGE_ROUTE_EVENT = "atomic:workflow-pending-stage-route", PENDING_STAGE_MESSAGE_EVENT = "atomic:workflow-pending-stage-message", PENDING_STAGE_UNDELIVERABLE_EVENT = "atomic:workflow-pending-stage-undeliverable", STICKY_LIVE_DELIVERED_EVENT = "atomic:workflow-sticky-live-delivered", ROUTE_RETRY_OUTCOME_EVENT = "atomic:intercom-route-retry-outcome", PENDING_STAGE_ROUTE_REVOKED_EVENT = "atomic:workflow-pending-stage-route-revoked";
|
|
8250
8440
|
var init_index_heavy = __esm(() => {
|
|
8251
8441
|
init_session_recovery();
|
|
8252
8442
|
init_client();
|
|
@@ -8275,6 +8465,8 @@ var init_index_heavy = __esm(() => {
|
|
|
8275
8465
|
init_group();
|
|
8276
8466
|
init_runtime_group();
|
|
8277
8467
|
init_reconnect_backoff();
|
|
8468
|
+
init_recoverable_disconnect();
|
|
8469
|
+
init_route_retry_waiters();
|
|
8278
8470
|
init_released_stage_peers();
|
|
8279
8471
|
init_supervisor_authorization_registry();
|
|
8280
8472
|
if (process.env.ATOMIC_TEST_LAZY_IMPORT_SENTINEL === "1") {
|
|
@@ -8322,8 +8514,9 @@ async function executeHeavyTool(loadHeavy, name, args) {
|
|
|
8322
8514
|
if (!recoverInitialization || !isRecoverableIntercomDisconnect(error))
|
|
8323
8515
|
throw error;
|
|
8324
8516
|
const delayMs = RECONNECT_DELAYS_MS[retries];
|
|
8325
|
-
if (delayMs === undefined)
|
|
8326
|
-
return initializationFailure("Client disconnected", retries);
|
|
8517
|
+
if (delayMs === undefined) {
|
|
8518
|
+
return initializationFailure(isIntercomBrokerTimeout(error) ? "Connection timeout" : "Client disconnected", retries);
|
|
8519
|
+
}
|
|
8327
8520
|
try {
|
|
8328
8521
|
await delay(delayMs, undefined, { signal: args[2] });
|
|
8329
8522
|
} catch {
|
|
@@ -8539,6 +8732,7 @@ var SUBAGENT_SUPERVISOR_AUTHORIZATION_EVENT2 = "subagent:supervisor-authorizatio
|
|
|
8539
8732
|
var WORKFLOW_STAGE_LATE_MESSAGE_EVENT = "atomic:workflow-stage-late-message";
|
|
8540
8733
|
var PENDING_STAGE_ROUTE_EVENT2 = "atomic:workflow-pending-stage-route";
|
|
8541
8734
|
var PENDING_STAGE_UNDELIVERABLE_EVENT2 = "atomic:workflow-pending-stage-undeliverable";
|
|
8735
|
+
var ROUTE_RETRY_OUTCOME_EVENT2 = "atomic:intercom-route-retry-outcome";
|
|
8542
8736
|
var RELEASED_STAGE_EVENT2 = "atomic:workflow-released-stage";
|
|
8543
8737
|
function isPendingStageUndeliverableRelay(value) {
|
|
8544
8738
|
if (typeof value !== "object" || value === null)
|
|
@@ -8600,6 +8794,23 @@ function reportRelayFailure(route, eventName, error) {
|
|
|
8600
8794
|
const detail = diagnosticDetail(error);
|
|
8601
8795
|
reportDiagnostic(route, `${prefix} ${detail}`, error, "error", prefix);
|
|
8602
8796
|
}
|
|
8797
|
+
var BROKER_OUTAGE_REPORT_AFTER_MS = 60000;
|
|
8798
|
+
|
|
8799
|
+
class BrokerOutage {
|
|
8800
|
+
startedAt = null;
|
|
8801
|
+
reported = false;
|
|
8802
|
+
timedOut(now) {
|
|
8803
|
+
this.startedAt ??= now;
|
|
8804
|
+
if (this.reported || now - this.startedAt < BROKER_OUTAGE_REPORT_AFTER_MS)
|
|
8805
|
+
return false;
|
|
8806
|
+
this.reported = true;
|
|
8807
|
+
return true;
|
|
8808
|
+
}
|
|
8809
|
+
recovered() {
|
|
8810
|
+
this.startedAt = null;
|
|
8811
|
+
this.reported = false;
|
|
8812
|
+
}
|
|
8813
|
+
}
|
|
8603
8814
|
var WARM_UP_RETRY_ATTEMPTS = 5;
|
|
8604
8815
|
function intercom(pi, options = {}) {
|
|
8605
8816
|
const inheritedDelegatedSessionName = readSubagentEnv("INTERCOM_SESSION_NAME");
|
|
@@ -8612,6 +8823,15 @@ function intercom(pi, options = {}) {
|
|
|
8612
8823
|
let activeLease = createLifecycleLease(nextLeaseId++);
|
|
8613
8824
|
let replayedGeneration = 0;
|
|
8614
8825
|
let replayAttempt = null;
|
|
8826
|
+
const brokerOutage = new BrokerOutage;
|
|
8827
|
+
function reportBackgroundRelayFailure(route, eventName, error) {
|
|
8828
|
+
if (isIntercomBrokerTimeout(error) && brokerOutage.timedOut(Date.now())) {
|
|
8829
|
+
const prefix = `Intercom broker has not answered for over ${BROKER_OUTAGE_REPORT_AFTER_MS / 1000}s; background relays keep retrying (${eventName}):`;
|
|
8830
|
+
reportDiagnostic(route, `${prefix} ${diagnosticDetail(error)}`, error, "error", prefix);
|
|
8831
|
+
return;
|
|
8832
|
+
}
|
|
8833
|
+
reportRelayFailure(route, eventName, error);
|
|
8834
|
+
}
|
|
8615
8835
|
const lifecycleForward = new SerializedLifecycleForwarder;
|
|
8616
8836
|
const invalidatedMessage = "Intercom initialization was invalidated by session shutdown";
|
|
8617
8837
|
const activeLifecycle = {
|
|
@@ -9106,6 +9326,18 @@ function intercom(pi, options = {}) {
|
|
|
9106
9326
|
const restored = await awaitRestoredIntercomPeers(pi.events, ctx.sessionManager.getSessionId());
|
|
9107
9327
|
return planIntercomRecoveryReplay(event.pending, peers, restored);
|
|
9108
9328
|
});
|
|
9329
|
+
pi.events.on(ROUTE_RETRY_OUTCOME_EVENT2, (payload) => {
|
|
9330
|
+
const outcome = payload;
|
|
9331
|
+
if (outcome?.error === undefined) {
|
|
9332
|
+
brokerOutage.recovered();
|
|
9333
|
+
return;
|
|
9334
|
+
}
|
|
9335
|
+
if (!isIntercomBrokerTimeout(outcome.error))
|
|
9336
|
+
return;
|
|
9337
|
+
const ctx = latestLifecycleContext();
|
|
9338
|
+
const diagnosticRoute = ctx ? captureDiagnosticRoute(ctx) : shutdownDiagnosticRoute ?? "console";
|
|
9339
|
+
reportBackgroundRelayFailure(diagnosticRoute, PENDING_STAGE_ROUTE_EVENT2, outcome.error);
|
|
9340
|
+
});
|
|
9109
9341
|
pi.events.on(PENDING_STAGE_UNDELIVERABLE_EVENT2, (payload) => {
|
|
9110
9342
|
if (!isPendingStageUndeliverableRelay(payload) || payload.handled === true)
|
|
9111
9343
|
return;
|
|
@@ -9119,7 +9351,7 @@ function intercom(pi, options = {}) {
|
|
|
9119
9351
|
handle.assertCurrent();
|
|
9120
9352
|
return forwarded.handled === true && forwarded.completion !== undefined ? await forwarded.completion : false;
|
|
9121
9353
|
}).catch((error) => {
|
|
9122
|
-
|
|
9354
|
+
reportBackgroundRelayFailure(diagnosticRoute, PENDING_STAGE_UNDELIVERABLE_EVENT2, error);
|
|
9123
9355
|
return false;
|
|
9124
9356
|
});
|
|
9125
9357
|
});
|
|
@@ -9145,9 +9377,9 @@ function intercom(pi, options = {}) {
|
|
|
9145
9377
|
if (eventName === PENDING_STAGE_ROUTE_EVENT2 && payload && typeof payload === "object") {
|
|
9146
9378
|
payload.completion = completion;
|
|
9147
9379
|
}
|
|
9148
|
-
completion.
|
|
9380
|
+
completion.then(() => brokerOutage.recovered(), (error) => {
|
|
9149
9381
|
rejectLazyResultRelay(pi, eventName, payload, error);
|
|
9150
|
-
|
|
9382
|
+
reportBackgroundRelayFailure(diagnosticRoute, eventName, error);
|
|
9151
9383
|
});
|
|
9152
9384
|
});
|
|
9153
9385
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bastani/intercom",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.41-alpha.1",
|
|
4
4
|
"private": true,
|
|
5
5
|
"description": "Atomic extension providing a private coordination channel between parent and child agent sessions. Fork of: https://github.com/nicobailon/pi-intercom",
|
|
6
6
|
"contributors": [
|