@bastani/atomic 0.9.78-alpha.1 → 0.9.79-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 +58 -0
- package/dist/builtin/intercom/CHANGELOG.md +12 -0
- package/dist/builtin/intercom/broker/broker.ts +198 -72
- package/dist/builtin/intercom/broker/client-message-validation.ts +38 -0
- package/dist/builtin/intercom/broker/client.ts +150 -11
- package/dist/builtin/intercom/broker/delivery-failure-reason.ts +1 -0
- package/dist/builtin/intercom/broker/departed-children.ts +23 -0
- package/dist/builtin/intercom/broker/hosted-session-errors.ts +188 -0
- package/dist/builtin/intercom/broker/hosted-sessions.ts +113 -0
- package/dist/builtin/intercom/broker/multinode-router.ts +7 -2
- package/dist/builtin/intercom/broker/presence-handler.ts +2 -1
- package/dist/builtin/intercom/broker/protocol-version.ts +6 -1
- package/dist/builtin/intercom/broker/recipient-gone-errors.ts +46 -5
- package/dist/builtin/intercom/broker/released-reply-errors.ts +1 -1
- package/dist/builtin/intercom/broker/send-handler.ts +19 -3
- package/dist/builtin/intercom/broker/socket-writes.ts +20 -1
- package/dist/builtin/intercom/hosted-session-timeout-error.ts +59 -0
- package/dist/builtin/intercom/index.bundle.mjs +634 -125
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/intercom/types.ts +41 -3
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/CHANGELOG.md +8 -0
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +90 -34
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/CHANGELOG.md +9 -0
- package/dist/builtin/workflows/builtin/{chunk-89we7r4p.js → chunk-5hrzxynt.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-8yfssw01.js → chunk-m56qhe4b.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-wh2p4qjg.js → chunk-x8m4t2jy.js} +182 -33
- package/dist/builtin/workflows/builtin/goal.js +2 -2
- package/dist/builtin/workflows/builtin/index.js +3 -3
- package/dist/builtin/workflows/builtin/ralph.js +2 -2
- package/dist/builtin/workflows/package.json +1 -1
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +1243 -230
- package/dist/builtin/workflows/src/extension/local-worker-entry.mjs +854 -170
- package/dist/builtin/workflows/src/index.js +854 -170
- package/dist/builtin/workflows/src/local-worker-entry.mjs +854 -170
- package/dist/cli/startup-progress.d.ts +30 -0
- package/dist/cli/startup-progress.d.ts.map +1 -0
- package/dist/cli/startup-progress.js +78 -0
- package/dist/cli/startup-progress.js.map +1 -0
- package/dist/core/agent-session-events.d.ts.map +1 -1
- package/dist/core/agent-session-events.js +3 -0
- package/dist/core/agent-session-events.js.map +1 -1
- package/dist/core/agent-session-extension-bindings.d.ts.map +1 -1
- package/dist/core/agent-session-extension-bindings.js +2 -0
- package/dist/core/agent-session-extension-bindings.js.map +1 -1
- package/dist/core/agent-session-methods.d.ts +2 -0
- 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-state.d.ts +12 -4
- package/dist/core/agent-session-state.d.ts.map +1 -1
- package/dist/core/agent-session-state.js +82 -15
- package/dist/core/agent-session-state.js.map +1 -1
- package/dist/core/agent-session.d.ts +3 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +3 -0
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/builtin-resource-loader.d.ts.map +1 -1
- package/dist/core/builtin-resource-loader.js +3 -0
- package/dist/core/builtin-resource-loader.js.map +1 -1
- package/dist/core/debug.d.ts +2 -0
- package/dist/core/debug.d.ts.map +1 -1
- package/dist/core/debug.js +13 -0
- package/dist/core/debug.js.map +1 -1
- package/dist/core/export-html/ansi-to-html.d.ts +5 -0
- package/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
- package/dist/core/export-html/ansi-to-html.js +57 -20
- package/dist/core/export-html/ansi-to-html.js.map +1 -1
- package/dist/core/export-html/template.js +1 -1
- package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
- package/dist/core/export-html/tool-renderer.js +2 -3
- package/dist/core/export-html/tool-renderer.js.map +1 -1
- package/dist/core/extensions/workflow-activity-hub.d.ts +7 -0
- package/dist/core/extensions/workflow-activity-hub.d.ts.map +1 -1
- package/dist/core/extensions/workflow-activity-hub.js +104 -6
- package/dist/core/extensions/workflow-activity-hub.js.map +1 -1
- package/dist/core/keybindings.d.ts +0 -8
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +0 -1
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/mandatory-resource-loader.d.ts.map +1 -1
- package/dist/core/mandatory-resource-loader.js +3 -0
- package/dist/core/mandatory-resource-loader.js.map +1 -1
- package/dist/core/resume/session-resume.d.ts +7 -1
- package/dist/core/resume/session-resume.d.ts.map +1 -1
- package/dist/core/resume/session-resume.js +136 -16
- package/dist/core/resume/session-resume.js.map +1 -1
- package/dist/core/session-history-index.d.ts +31 -0
- package/dist/core/session-history-index.d.ts.map +1 -0
- package/dist/core/session-history-index.js +82 -0
- package/dist/core/session-history-index.js.map +1 -0
- package/dist/core/session-manager-core.d.ts +3 -0
- package/dist/core/session-manager-core.d.ts.map +1 -1
- package/dist/core/session-manager-core.js +22 -17
- package/dist/core/session-manager-core.js.map +1 -1
- package/dist/core/session-manager-history.d.ts +3 -3
- package/dist/core/session-manager-history.d.ts.map +1 -1
- package/dist/core/session-manager-history.js +6 -5
- package/dist/core/session-manager-history.js.map +1 -1
- package/dist/core/storage/session/history-load-observer.d.ts +11 -0
- package/dist/core/storage/session/history-load-observer.d.ts.map +1 -0
- package/dist/core/storage/session/history-load-observer.js +25 -0
- package/dist/core/storage/session/history-load-observer.js.map +1 -0
- package/dist/core/storage/session/sql-session-store.d.ts.map +1 -1
- package/dist/core/storage/session/sql-session-store.js +6 -0
- package/dist/core/storage/session/sql-session-store.js.map +1 -1
- package/dist/core/tool-deactivation.d.ts +11 -0
- package/dist/core/tool-deactivation.d.ts.map +1 -0
- package/dist/core/tool-deactivation.js +13 -0
- package/dist/core/tool-deactivation.js.map +1 -0
- package/dist/core/tool-status.d.ts +6 -1
- package/dist/core/tool-status.d.ts.map +1 -1
- package/dist/core/tool-status.js +11 -3
- package/dist/core/tool-status.js.map +1 -1
- package/dist/extensions/llama/errors.js +1 -1
- package/dist/extensions/llama/errors.js.map +1 -1
- package/dist/extensions/llama/provider.d.ts +1 -1
- package/dist/extensions/llama/provider.js +1 -1
- package/dist/extensions/llama/provider.js.map +1 -1
- package/dist/main-session.d.ts +14 -2
- package/dist/main-session.d.ts.map +1 -1
- package/dist/main-session.js +42 -9
- package/dist/main-session.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +4 -2
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +6 -0
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +13 -4
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/task-detail.d.ts +1 -1
- package/dist/modes/interactive/components/task-detail.d.ts.map +1 -1
- package/dist/modes/interactive/components/task-detail.js +1 -3
- package/dist/modes/interactive/components/task-detail.js.map +1 -1
- package/dist/modes/interactive/components/task-inspector.d.ts.map +1 -1
- package/dist/modes/interactive/components/task-inspector.js +1 -7
- package/dist/modes/interactive/components/task-inspector.js.map +1 -1
- package/dist/modes/interactive/components/task-navigation.d.ts +0 -1
- package/dist/modes/interactive/components/task-navigation.d.ts.map +1 -1
- package/dist/modes/interactive/components/task-navigation.js +1 -3
- package/dist/modes/interactive/components/task-navigation.js.map +1 -1
- package/dist/modes/interactive/interactive-agent-events.js +5 -9
- package/dist/modes/interactive/interactive-agent-events.js.map +1 -1
- package/dist/modes/interactive/interactive-deferred-startup.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-deferred-startup.js +8 -5
- package/dist/modes/interactive/interactive-deferred-startup.js.map +1 -1
- package/dist/modes/interactive/interactive-process-lifecycle.js +16 -10
- package/dist/modes/interactive/interactive-process-lifecycle.js.map +1 -1
- package/dist/modes/interactive/interactive-startup.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-startup.js +2 -0
- package/dist/modes/interactive/interactive-startup.js.map +1 -1
- package/dist/modes/interactive/interactive-unavailable-tools.d.ts +20 -0
- package/dist/modes/interactive/interactive-unavailable-tools.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-unavailable-tools.js +40 -0
- package/dist/modes/interactive/interactive-unavailable-tools.js.map +1 -0
- package/dist/modes/interactive-engine/remote-component.js +1 -1
- package/dist/modes/interactive-engine/remote-component.js.map +1 -1
- package/docs/background-tasks.md +1 -1
- package/docs/extensions/api-reference.md +1 -1
- package/docs/extensions/events.md +2 -0
- package/docs/intercom/operations.md +2 -2
- package/docs/intercom/reference.md +12 -1
- package/docs/keybindings.md +2 -3
- package/docs/llama-cpp.md +9 -10
- package/docs/models/reference.md +1 -1
- package/docs/models-configuration.md +1 -1
- package/docs/sessions.md +6 -2
- package/docs/subagents.md +3 -1
- package/docs/usage.md +1 -1
- package/docs/workflows/operations.md +2 -2
- package/docs/worktree-snapshots.md +3 -1
- package/npm-shrinkwrap.json +32 -32
- package/package.json +4 -4
- package/schemas/keybindings.schema.json +0 -4
- package/schemas/models.schema.json +1 -1
|
@@ -375,6 +375,8 @@ function subagentEndedCode(outcome) {
|
|
|
375
375
|
return ENDED_CODE[outcome];
|
|
376
376
|
}
|
|
377
377
|
function hintFor(code, childId) {
|
|
378
|
+
if (code === "recipient_stage_released")
|
|
379
|
+
return "Send to its workflow stage target (workflow:<rootRunId>/<stage>), which reaches the stage's current session or queues until it reopens, or resume the run.";
|
|
378
380
|
if (code === "recipient_cancelled")
|
|
379
381
|
return "It cannot be resumed; launch a fresh subagent if its work is still needed.";
|
|
380
382
|
if (code === "recipient_disconnected")
|
|
@@ -398,6 +400,9 @@ function isSubagentRecipientDisconnectedError(error) {
|
|
|
398
400
|
function isSubagentRecipientOwnerSuspendedError(error) {
|
|
399
401
|
return error instanceof SubagentRecipientOwnerSuspendedError || hasStructure2(error, OWNER_SUSPENDED_NAMES);
|
|
400
402
|
}
|
|
403
|
+
function isStageRecipientReleasedError(error) {
|
|
404
|
+
return error instanceof StageRecipientReleasedError || hasStructure2(error, STAGE_RELEASED_NAMES);
|
|
405
|
+
}
|
|
401
406
|
function isRetryableIntercomRecipientGoneError(error) {
|
|
402
407
|
let current = error;
|
|
403
408
|
for (let depth = 0;current !== undefined && depth <= MAX_CAUSE_DEPTH3; depth++) {
|
|
@@ -421,7 +426,9 @@ function serializeIntercomRecipientGoneError(error) {
|
|
|
421
426
|
function rehydrateIntercomRecipientGoneError(serialized) {
|
|
422
427
|
const options = serialized.cause === undefined ? undefined : { cause: rehydrateCause(serialized.cause, 1) };
|
|
423
428
|
const { code, fields } = serialized;
|
|
424
|
-
if (serialized.name ===
|
|
429
|
+
if (serialized.name === STAGE_RELEASED_NAME && code === "recipient_stage_released")
|
|
430
|
+
return new StageRecipientReleasedError(fields, options);
|
|
431
|
+
if (serialized.name === ENDED_NAME && code !== "recipient_disconnected" && code !== "recipient_owner_suspended" && code !== "recipient_stage_released")
|
|
425
432
|
return new SubagentRecipientEndedError(code, fields, options);
|
|
426
433
|
if (serialized.name === DISCONNECTED_NAME && code === "recipient_disconnected")
|
|
427
434
|
return new SubagentRecipientDisconnectedError(fields, options);
|
|
@@ -469,7 +476,7 @@ function readSerializedIntercomRecipientGoneError(value) {
|
|
|
469
476
|
...cause === undefined ? {} : { cause }
|
|
470
477
|
};
|
|
471
478
|
}
|
|
472
|
-
var SUBAGENT_ENDED_OUTCOMES, INTERCOM_RECIPIENT_GONE_ERROR_CODES, CODES2, ENDED_CODE, WHAT, BASE_NAME2 = "IntercomRecipientGoneError", ENDED_NAME = "SubagentRecipientEndedError", DISCONNECTED_NAME = "SubagentRecipientDisconnectedError", OWNER_SUSPENDED_NAME = "SubagentRecipientOwnerSuspendedError", IntercomRecipientGoneError, SubagentRecipientEndedError, SubagentRecipientDisconnectedError, SubagentRecipientOwnerSuspendedError, NAMES2, ENDED_NAMES, DISCONNECTED_NAMES, OWNER_SUSPENDED_NAMES, MAX_CAUSE_DEPTH3 = 4, isWireObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
479
|
+
var SUBAGENT_ENDED_OUTCOMES, INTERCOM_RECIPIENT_GONE_ERROR_CODES, CODES2, ENDED_CODE, WHAT, BASE_NAME2 = "IntercomRecipientGoneError", ENDED_NAME = "SubagentRecipientEndedError", DISCONNECTED_NAME = "SubagentRecipientDisconnectedError", OWNER_SUSPENDED_NAME = "SubagentRecipientOwnerSuspendedError", STAGE_RELEASED_NAME = "StageRecipientReleasedError", IntercomRecipientGoneError, SubagentRecipientEndedError, SubagentRecipientDisconnectedError, SubagentRecipientOwnerSuspendedError, StageRecipientReleasedError, NAMES2, STAGE_RELEASED_NAMES, ENDED_NAMES, DISCONNECTED_NAMES, OWNER_SUSPENDED_NAMES, MAX_CAUSE_DEPTH3 = 4, isWireObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
473
480
|
var init_recipient_gone_errors = __esm(() => {
|
|
474
481
|
init_released_child_errors();
|
|
475
482
|
SUBAGENT_ENDED_OUTCOMES = ["completed", "failed", "stopped", "cancelled"];
|
|
@@ -479,7 +486,8 @@ var init_recipient_gone_errors = __esm(() => {
|
|
|
479
486
|
"recipient_stopped",
|
|
480
487
|
"recipient_cancelled",
|
|
481
488
|
"recipient_disconnected",
|
|
482
|
-
"recipient_owner_suspended"
|
|
489
|
+
"recipient_owner_suspended",
|
|
490
|
+
"recipient_stage_released"
|
|
483
491
|
];
|
|
484
492
|
CODES2 = new Set(INTERCOM_RECIPIENT_GONE_ERROR_CODES);
|
|
485
493
|
ENDED_CODE = {
|
|
@@ -494,7 +502,8 @@ var init_recipient_gone_errors = __esm(() => {
|
|
|
494
502
|
recipient_stopped: "was stopped (paused or quit) and has no live session",
|
|
495
503
|
recipient_cancelled: "was cancelled for good and has no live session",
|
|
496
504
|
recipient_disconnected: "disconnected and has not reconnected",
|
|
497
|
-
recipient_owner_suspended: "is released and the session that launched it is suspended or disconnected, so nothing can wake it now"
|
|
505
|
+
recipient_owner_suspended: "is released and the session that launched it is suspended or disconnected, so nothing can wake it now",
|
|
506
|
+
recipient_stage_released: "was released and the session that answered for it has gone away"
|
|
498
507
|
};
|
|
499
508
|
IntercomRecipientGoneError = class IntercomRecipientGoneError extends Error {
|
|
500
509
|
name = BASE_NAME2;
|
|
@@ -506,7 +515,8 @@ var init_recipient_gone_errors = __esm(() => {
|
|
|
506
515
|
childId;
|
|
507
516
|
constructor(code, fields, options) {
|
|
508
517
|
const hint = hintFor(code, fields.childId);
|
|
509
|
-
|
|
518
|
+
const subject = code === "recipient_stage_released" ? "Workflow stage" : "Subagent";
|
|
519
|
+
super(`${subject} ${JSON.stringify(fields.childName)} ${WHAT[code]} (${code}). ${hint}`, options);
|
|
510
520
|
this.code = code;
|
|
511
521
|
this.hint = hint;
|
|
512
522
|
this.retryable = code === "recipient_disconnected" || code === "recipient_owner_suspended";
|
|
@@ -540,7 +550,20 @@ var init_recipient_gone_errors = __esm(() => {
|
|
|
540
550
|
super("recipient_owner_suspended", fields, options);
|
|
541
551
|
}
|
|
542
552
|
};
|
|
543
|
-
|
|
553
|
+
StageRecipientReleasedError = class StageRecipientReleasedError extends IntercomRecipientGoneError {
|
|
554
|
+
name = STAGE_RELEASED_NAME;
|
|
555
|
+
constructor(fields, options) {
|
|
556
|
+
super("recipient_stage_released", fields, options);
|
|
557
|
+
}
|
|
558
|
+
};
|
|
559
|
+
NAMES2 = new Set([
|
|
560
|
+
BASE_NAME2,
|
|
561
|
+
ENDED_NAME,
|
|
562
|
+
DISCONNECTED_NAME,
|
|
563
|
+
OWNER_SUSPENDED_NAME,
|
|
564
|
+
STAGE_RELEASED_NAME
|
|
565
|
+
]);
|
|
566
|
+
STAGE_RELEASED_NAMES = new Set([STAGE_RELEASED_NAME]);
|
|
544
567
|
ENDED_NAMES = new Set([ENDED_NAME]);
|
|
545
568
|
DISCONNECTED_NAMES = new Set([DISCONNECTED_NAME]);
|
|
546
569
|
OWNER_SUSPENDED_NAMES = new Set([OWNER_SUSPENDED_NAME]);
|
|
@@ -1166,6 +1189,30 @@ function isSessionInfo(value) {
|
|
|
1166
1189
|
return false;
|
|
1167
1190
|
return session.status === undefined || typeof session.status === "string";
|
|
1168
1191
|
}
|
|
1192
|
+
function isSessionRegistration(value) {
|
|
1193
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
1194
|
+
return false;
|
|
1195
|
+
}
|
|
1196
|
+
const session = value;
|
|
1197
|
+
if (typeof session.cwd !== "string" || typeof session.model !== "string" || typeof session.pid !== "number" || typeof session.startedAt !== "number" || typeof session.lastActivity !== "number") {
|
|
1198
|
+
return false;
|
|
1199
|
+
}
|
|
1200
|
+
if (session.name !== undefined && typeof session.name !== "string") {
|
|
1201
|
+
return false;
|
|
1202
|
+
}
|
|
1203
|
+
if (session.group !== undefined && typeof session.group !== "string") {
|
|
1204
|
+
return false;
|
|
1205
|
+
}
|
|
1206
|
+
if (session.replyCapability !== undefined && session.replyCapability !== "live" && session.replyCapability !== "terminal")
|
|
1207
|
+
return false;
|
|
1208
|
+
if (session.recipientPurpose !== undefined && session.recipientPurpose !== "agent" && session.recipientPurpose !== "control") {
|
|
1209
|
+
return false;
|
|
1210
|
+
}
|
|
1211
|
+
if (session.groups !== undefined && (!Array.isArray(session.groups) || !session.groups.every((group) => typeof group === "string"))) {
|
|
1212
|
+
return false;
|
|
1213
|
+
}
|
|
1214
|
+
return session.status === undefined || typeof session.status === "string";
|
|
1215
|
+
}
|
|
1169
1216
|
|
|
1170
1217
|
// dist/builtin/intercom/durable-inbox.ts
|
|
1171
1218
|
function inboxRecord(entry) {
|
|
@@ -1417,6 +1464,234 @@ var init_released_reply_errors = __esm(() => {
|
|
|
1417
1464
|
IN_FLIGHT_NAMES = new Set([IN_FLIGHT_NAME]);
|
|
1418
1465
|
});
|
|
1419
1466
|
|
|
1467
|
+
// dist/builtin/intercom/hosted-session-timeout-error.ts
|
|
1468
|
+
function isIntercomHostedSessionTimeoutError(value) {
|
|
1469
|
+
if (typeof value !== "object" || value === null)
|
|
1470
|
+
return false;
|
|
1471
|
+
const { name, code } = value;
|
|
1472
|
+
return name === "IntercomHostedSessionTimeoutError" && code === "hosted_session_timeout";
|
|
1473
|
+
}
|
|
1474
|
+
var HOSTED_SESSION_TIMEOUT_HINT = "Hosting is tried again on the next connection; run `atomic intercom restart` if the broker keeps timing out.", IntercomHostedSessionTimeoutError;
|
|
1475
|
+
var init_hosted_session_timeout_error = __esm(() => {
|
|
1476
|
+
init_recoverable_disconnect();
|
|
1477
|
+
IntercomHostedSessionTimeoutError = class IntercomHostedSessionTimeoutError extends IntercomBrokerTimeoutError {
|
|
1478
|
+
name = "IntercomHostedSessionTimeoutError";
|
|
1479
|
+
code = "hosted_session_timeout";
|
|
1480
|
+
phase = "hosted-session-request";
|
|
1481
|
+
retryable = true;
|
|
1482
|
+
hint = HOSTED_SESSION_TIMEOUT_HINT;
|
|
1483
|
+
requestType;
|
|
1484
|
+
sessionCount;
|
|
1485
|
+
timeoutMs;
|
|
1486
|
+
elapsedMs;
|
|
1487
|
+
constructor(fields, options) {
|
|
1488
|
+
super(`Hosted-session request timed out: ${fields.requestType} for ${fields.sessionCount} sessions, unanswered after ${fields.elapsedMs} ms of ${fields.timeoutMs} ms (hosted_session_timeout). ${HOSTED_SESSION_TIMEOUT_HINT}`, options);
|
|
1489
|
+
this.requestType = fields.requestType;
|
|
1490
|
+
this.sessionCount = fields.sessionCount;
|
|
1491
|
+
this.timeoutMs = fields.timeoutMs;
|
|
1492
|
+
this.elapsedMs = fields.elapsedMs;
|
|
1493
|
+
}
|
|
1494
|
+
};
|
|
1495
|
+
});
|
|
1496
|
+
|
|
1497
|
+
// dist/builtin/intercom/broker/hosted-sessions.ts
|
|
1498
|
+
function parseLiveRoute(value) {
|
|
1499
|
+
if (!isWireObject3(value))
|
|
1500
|
+
return false;
|
|
1501
|
+
const { runId, stageKeys, capability } = value;
|
|
1502
|
+
if (!isNonEmptyString(runId) || !isNonEmptyString(capability) || !Array.isArray(stageKeys))
|
|
1503
|
+
return false;
|
|
1504
|
+
if (stageKeys.length < 1 || stageKeys.length > 2 || !stageKeys.every(isNonEmptyString))
|
|
1505
|
+
return false;
|
|
1506
|
+
return { runId, stageKeys, capability };
|
|
1507
|
+
}
|
|
1508
|
+
function validateHostSessionsFrame(sessions) {
|
|
1509
|
+
if (!Array.isArray(sessions) || sessions.length === 0 || sessions.length > HOSTED_SESSION_FRAME_MAX) {
|
|
1510
|
+
return { ok: false, refusal: { code: "invalid_hosted_frame" } };
|
|
1511
|
+
}
|
|
1512
|
+
const keys = new Set;
|
|
1513
|
+
const parsed = [];
|
|
1514
|
+
for (const item of sessions) {
|
|
1515
|
+
if (!isWireObject3(item) || !isNonEmptyString(item.key) || keys.has(item.key)) {
|
|
1516
|
+
return {
|
|
1517
|
+
ok: false,
|
|
1518
|
+
refusal: isWireObject3(item) && typeof item.key === "string" ? { code: "invalid_hosted_frame", key: item.key } : { code: "invalid_hosted_frame" }
|
|
1519
|
+
};
|
|
1520
|
+
}
|
|
1521
|
+
const key = item.key;
|
|
1522
|
+
keys.add(key);
|
|
1523
|
+
const invalid = { ok: false, refusal: { code: "invalid_hosted_session", key } };
|
|
1524
|
+
const { session, returnAddress } = item;
|
|
1525
|
+
if (!isSessionRegistration(session) || !isNonEmptyString(session.name) || session.recipientPurpose === "control") {
|
|
1526
|
+
return invalid;
|
|
1527
|
+
}
|
|
1528
|
+
if (returnAddress !== undefined && !isNonEmptyString(returnAddress))
|
|
1529
|
+
return invalid;
|
|
1530
|
+
const liveRoute = item.liveRoute === undefined ? undefined : parseLiveRoute(item.liveRoute);
|
|
1531
|
+
if (liveRoute === false)
|
|
1532
|
+
return invalid;
|
|
1533
|
+
parsed.push({
|
|
1534
|
+
key,
|
|
1535
|
+
session,
|
|
1536
|
+
...returnAddress === undefined ? {} : { returnAddress },
|
|
1537
|
+
...liveRoute === undefined ? {} : { liveRoute }
|
|
1538
|
+
});
|
|
1539
|
+
}
|
|
1540
|
+
return { ok: true, sessions: parsed };
|
|
1541
|
+
}
|
|
1542
|
+
function readHostedSessionAssignments(value) {
|
|
1543
|
+
if (!Array.isArray(value))
|
|
1544
|
+
return;
|
|
1545
|
+
const assignments = [];
|
|
1546
|
+
for (const item of value) {
|
|
1547
|
+
if (!isWireObject3(item) || typeof item.key !== "string" || !isNonEmptyString(item.sessionId))
|
|
1548
|
+
return;
|
|
1549
|
+
const { liveRouteRefusal } = item;
|
|
1550
|
+
if (liveRouteRefusal !== undefined && !isLiveWorkflowStageRouteRefusalCode(liveRouteRefusal))
|
|
1551
|
+
return;
|
|
1552
|
+
assignments.push({
|
|
1553
|
+
key: item.key,
|
|
1554
|
+
sessionId: item.sessionId,
|
|
1555
|
+
...liveRouteRefusal === undefined ? {} : { liveRouteRefusal }
|
|
1556
|
+
});
|
|
1557
|
+
}
|
|
1558
|
+
return assignments;
|
|
1559
|
+
}
|
|
1560
|
+
var HOSTED_SESSION_FRAME_MAX = 500, isWireObject3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value), isNonEmptyString = (value) => typeof value === "string" && value.trim().length > 0;
|
|
1561
|
+
var init_hosted_sessions = __esm(() => {
|
|
1562
|
+
init_live_route_refusal();
|
|
1563
|
+
});
|
|
1564
|
+
|
|
1565
|
+
// dist/builtin/intercom/broker/hosted-session-errors.ts
|
|
1566
|
+
function isHostedSessionErrorCode(value) {
|
|
1567
|
+
return CODES4.has(value);
|
|
1568
|
+
}
|
|
1569
|
+
function hasStructure4(error, names) {
|
|
1570
|
+
const code = error.code;
|
|
1571
|
+
return names.has(error.name) && typeof code === "string" && isHostedSessionErrorCode(code);
|
|
1572
|
+
}
|
|
1573
|
+
function isIntercomHostedSessionError(error) {
|
|
1574
|
+
return error instanceof IntercomHostedSessionError || hasStructure4(error, NAMES4);
|
|
1575
|
+
}
|
|
1576
|
+
function isHostedSessionRequestError(error) {
|
|
1577
|
+
return error instanceof HostedSessionRequestError || hasStructure4(error, REQUEST_NAMES);
|
|
1578
|
+
}
|
|
1579
|
+
function isNotHostedSessionError(error) {
|
|
1580
|
+
return error instanceof NotHostedSessionError || hasStructure4(error, NOT_HOSTED_NAMES);
|
|
1581
|
+
}
|
|
1582
|
+
function fieldsOf(refusal) {
|
|
1583
|
+
return {
|
|
1584
|
+
...refusal.key === undefined ? {} : { key: refusal.key },
|
|
1585
|
+
...refusal.sessionId === undefined ? {} : { sessionId: refusal.sessionId }
|
|
1586
|
+
};
|
|
1587
|
+
}
|
|
1588
|
+
function hostedSessionErrorFor(refusal, options) {
|
|
1589
|
+
return refusal.code === "not_hosted_by_connection" ? new NotHostedSessionError(fieldsOf(refusal), options) : new HostedSessionRequestError(refusal.code, fieldsOf(refusal), options);
|
|
1590
|
+
}
|
|
1591
|
+
function serializeIntercomHostedSessionError(error) {
|
|
1592
|
+
return {
|
|
1593
|
+
name: error.name,
|
|
1594
|
+
code: error.code,
|
|
1595
|
+
message: error.message,
|
|
1596
|
+
hint: error.hint,
|
|
1597
|
+
retryable: false,
|
|
1598
|
+
fields: fieldsOf(error),
|
|
1599
|
+
...error.cause instanceof Error ? { cause: serializeCause(error.cause, 1) } : {}
|
|
1600
|
+
};
|
|
1601
|
+
}
|
|
1602
|
+
function rehydrateIntercomHostedSessionError(serialized) {
|
|
1603
|
+
const options = serialized.cause === undefined ? undefined : { cause: rehydrateCause(serialized.cause, 1) };
|
|
1604
|
+
if (serialized.name === NOT_HOSTED_NAME)
|
|
1605
|
+
return new NotHostedSessionError(serialized.fields, options);
|
|
1606
|
+
if (serialized.name === REQUEST_NAME)
|
|
1607
|
+
return new HostedSessionRequestError(serialized.code, serialized.fields, options);
|
|
1608
|
+
const error = new IntercomHostedSessionError(serialized.code, serialized.fields, options);
|
|
1609
|
+
Object.defineProperty(error, "name", { value: serialized.name });
|
|
1610
|
+
return error;
|
|
1611
|
+
}
|
|
1612
|
+
function readHostedSessionRefusal(value) {
|
|
1613
|
+
if (!isWireObject3(value))
|
|
1614
|
+
return;
|
|
1615
|
+
const { code, key, sessionId } = value;
|
|
1616
|
+
if (typeof code !== "string" || !isHostedSessionErrorCode(code))
|
|
1617
|
+
return;
|
|
1618
|
+
if (key !== undefined && typeof key !== "string" || sessionId !== undefined && typeof sessionId !== "string") {
|
|
1619
|
+
return;
|
|
1620
|
+
}
|
|
1621
|
+
return { code, ...key === undefined ? {} : { key }, ...sessionId === undefined ? {} : { sessionId } };
|
|
1622
|
+
}
|
|
1623
|
+
function readSerializedIntercomHostedSessionError(value) {
|
|
1624
|
+
if (!isWireObject3(value))
|
|
1625
|
+
return;
|
|
1626
|
+
const { name, code, message, hint, retryable, fields } = value;
|
|
1627
|
+
if (typeof name !== "string" || typeof code !== "string" || !isHostedSessionErrorCode(code))
|
|
1628
|
+
return;
|
|
1629
|
+
if (typeof message !== "string" || typeof hint !== "string" || retryable !== false)
|
|
1630
|
+
return;
|
|
1631
|
+
const refusal = isWireObject3(fields) ? readHostedSessionRefusal({ ...fields, code }) : undefined;
|
|
1632
|
+
if (refusal === undefined)
|
|
1633
|
+
return;
|
|
1634
|
+
const cause = readCause2(value.cause, 1);
|
|
1635
|
+
if (cause === false)
|
|
1636
|
+
return;
|
|
1637
|
+
return {
|
|
1638
|
+
name,
|
|
1639
|
+
code,
|
|
1640
|
+
message,
|
|
1641
|
+
hint,
|
|
1642
|
+
retryable: false,
|
|
1643
|
+
fields: fieldsOf(refusal),
|
|
1644
|
+
...cause === undefined ? {} : { cause }
|
|
1645
|
+
};
|
|
1646
|
+
}
|
|
1647
|
+
var HOSTED_SESSION_ERROR_CODES, CODES4, HINTS3, BASE_NAME4 = "IntercomHostedSessionError", REQUEST_NAME = "HostedSessionRequestError", NOT_HOSTED_NAME = "NotHostedSessionError", IntercomHostedSessionError, HostedSessionRequestError, NotHostedSessionError, NAMES4, REQUEST_NAMES, NOT_HOSTED_NAMES;
|
|
1648
|
+
var init_hosted_session_errors = __esm(() => {
|
|
1649
|
+
init_hosted_sessions();
|
|
1650
|
+
init_released_child_errors();
|
|
1651
|
+
init_released_reply_errors();
|
|
1652
|
+
HOSTED_SESSION_ERROR_CODES = [
|
|
1653
|
+
"invalid_hosted_frame",
|
|
1654
|
+
"invalid_hosted_session",
|
|
1655
|
+
"not_hosted_by_connection"
|
|
1656
|
+
];
|
|
1657
|
+
CODES4 = new Set(HOSTED_SESSION_ERROR_CODES);
|
|
1658
|
+
HINTS3 = {
|
|
1659
|
+
invalid_hosted_frame: "Send between 1 and 500 sessions per frame, each under a distinct non-empty key, or 1 to 500 session ids to remove.",
|
|
1660
|
+
invalid_hosted_session: "Give each hosted session a non-empty name and a valid agent registration (cwd, model, pid and timestamps).",
|
|
1661
|
+
not_hosted_by_connection: "Only the connection that hosts a session may send as it or remove it; host the session again after a reconnect."
|
|
1662
|
+
};
|
|
1663
|
+
IntercomHostedSessionError = class IntercomHostedSessionError extends Error {
|
|
1664
|
+
name = BASE_NAME4;
|
|
1665
|
+
code;
|
|
1666
|
+
hint;
|
|
1667
|
+
retryable = false;
|
|
1668
|
+
key;
|
|
1669
|
+
sessionId;
|
|
1670
|
+
constructor(code, fields = {}, options) {
|
|
1671
|
+
const subject = fields.key !== undefined ? `hosted session ${JSON.stringify(fields.key)}` : fields.sessionId !== undefined ? `session ${JSON.stringify(fields.sessionId)}` : "request";
|
|
1672
|
+
super(`Hosted-session request refused: ${subject} (${code}). ${HINTS3[code]}`, options);
|
|
1673
|
+
this.code = code;
|
|
1674
|
+
this.hint = HINTS3[code];
|
|
1675
|
+
if (fields.key !== undefined)
|
|
1676
|
+
this.key = fields.key;
|
|
1677
|
+
if (fields.sessionId !== undefined)
|
|
1678
|
+
this.sessionId = fields.sessionId;
|
|
1679
|
+
}
|
|
1680
|
+
};
|
|
1681
|
+
HostedSessionRequestError = class HostedSessionRequestError extends IntercomHostedSessionError {
|
|
1682
|
+
name = REQUEST_NAME;
|
|
1683
|
+
};
|
|
1684
|
+
NotHostedSessionError = class NotHostedSessionError extends IntercomHostedSessionError {
|
|
1685
|
+
name = NOT_HOSTED_NAME;
|
|
1686
|
+
constructor(fields, options) {
|
|
1687
|
+
super("not_hosted_by_connection", fields, options);
|
|
1688
|
+
}
|
|
1689
|
+
};
|
|
1690
|
+
NAMES4 = new Set([BASE_NAME4, REQUEST_NAME, NOT_HOSTED_NAME]);
|
|
1691
|
+
REQUEST_NAMES = new Set([REQUEST_NAME]);
|
|
1692
|
+
NOT_HOSTED_NAMES = new Set([NOT_HOSTED_NAME]);
|
|
1693
|
+
});
|
|
1694
|
+
|
|
1420
1695
|
// dist/builtin/intercom/subagent-reply-capability.ts
|
|
1421
1696
|
function registerSubagentReplyCapability(pi, client) {
|
|
1422
1697
|
let signal;
|
|
@@ -1562,9 +1837,9 @@ function isBrokerProtocolRange(value) {
|
|
|
1562
1837
|
function protocolRangeOf(value) {
|
|
1563
1838
|
return value === undefined ? LEGACY_BROKER_PROTOCOL : { min: value.min, max: value.max };
|
|
1564
1839
|
}
|
|
1565
|
-
var BROKER_PROTOCOL, LEGACY_BROKER_PROTOCOL, VERIFIED_REGISTRATION_PROTOCOL = 2;
|
|
1840
|
+
var BROKER_PROTOCOL, LEGACY_BROKER_PROTOCOL, VERIFIED_REGISTRATION_PROTOCOL = 2, HOSTED_SESSIONS_PROTOCOL = 3;
|
|
1566
1841
|
var init_protocol_version = __esm(() => {
|
|
1567
|
-
BROKER_PROTOCOL = { min: 1, max:
|
|
1842
|
+
BROKER_PROTOCOL = { min: 1, max: 3 };
|
|
1568
1843
|
LEGACY_BROKER_PROTOCOL = { min: 1, max: 1 };
|
|
1569
1844
|
});
|
|
1570
1845
|
|
|
@@ -1851,7 +2126,8 @@ var init_delivery_failure_reason = __esm(() => {
|
|
|
1851
2126
|
"recipient_not_restored",
|
|
1852
2127
|
"recipient_parked",
|
|
1853
2128
|
"released_reply_answered",
|
|
1854
|
-
"released_reply_in_flight"
|
|
2129
|
+
"released_reply_in_flight",
|
|
2130
|
+
"not_hosted_by_connection"
|
|
1855
2131
|
]);
|
|
1856
2132
|
});
|
|
1857
2133
|
|
|
@@ -2060,9 +2336,12 @@ var init_client = __esm(() => {
|
|
|
2060
2336
|
init_released_reply_errors();
|
|
2061
2337
|
init_released_children();
|
|
2062
2338
|
init_recipient_gone_errors();
|
|
2339
|
+
init_hosted_session_errors();
|
|
2340
|
+
init_hosted_sessions();
|
|
2063
2341
|
init_group();
|
|
2064
2342
|
init_recoverable_disconnect();
|
|
2065
2343
|
init_pending_stage_route_timeout_error();
|
|
2344
|
+
init_hosted_session_timeout_error();
|
|
2066
2345
|
init_socket_liveness();
|
|
2067
2346
|
init_protocol_version();
|
|
2068
2347
|
init_live_route_refusal();
|
|
@@ -2071,6 +2350,7 @@ var init_client = __esm(() => {
|
|
|
2071
2350
|
init_released_child_errors();
|
|
2072
2351
|
init_recipient_gone_errors();
|
|
2073
2352
|
init_released_reply_errors();
|
|
2353
|
+
init_hosted_session_errors();
|
|
2074
2354
|
ConnectionClosedBeforeRegistrationError = class ConnectionClosedBeforeRegistrationError extends Error {
|
|
2075
2355
|
constructor() {
|
|
2076
2356
|
super("Connection closed before registration");
|
|
@@ -2128,6 +2408,7 @@ var init_client = __esm(() => {
|
|
|
2128
2408
|
pendingStageRouteRegistrations = new Map;
|
|
2129
2409
|
pendingSupervisorAuthorizations = new Map;
|
|
2130
2410
|
pendingRestoringRecipientRequests = new Map;
|
|
2411
|
+
pendingHostedSessionRequests = new Map;
|
|
2131
2412
|
disconnecting = false;
|
|
2132
2413
|
disconnectError = null;
|
|
2133
2414
|
healthCheck;
|
|
@@ -2187,6 +2468,8 @@ var init_client = __esm(() => {
|
|
|
2187
2468
|
pending.reject(error);
|
|
2188
2469
|
for (const pending of this.pendingRestoringRecipientRequests.values())
|
|
2189
2470
|
pending.reject(error);
|
|
2471
|
+
for (const pending of this.pendingHostedSessionRequests.values())
|
|
2472
|
+
pending.reject(error);
|
|
2190
2473
|
for (const pending of this.pendingPresence.values())
|
|
2191
2474
|
pending.reject(error);
|
|
2192
2475
|
for (const pending of this.pendingMemberships.values())
|
|
@@ -2203,6 +2486,7 @@ var init_client = __esm(() => {
|
|
|
2203
2486
|
this.pendingGroupLists.clear();
|
|
2204
2487
|
this.pendingSupervisorAuthorizations.clear();
|
|
2205
2488
|
this.pendingRestoringRecipientRequests.clear();
|
|
2489
|
+
this.pendingHostedSessionRequests.clear();
|
|
2206
2490
|
this.pendingPresence.clear();
|
|
2207
2491
|
this.pendingMemberships.clear();
|
|
2208
2492
|
this.pendingLiveWorkflowStageRoutes.clear();
|
|
@@ -2535,11 +2819,14 @@ var init_client = __esm(() => {
|
|
|
2535
2819
|
break;
|
|
2536
2820
|
}
|
|
2537
2821
|
case "message": {
|
|
2538
|
-
const { from, message, channel } = brokerMessage;
|
|
2539
|
-
if (!isSessionInfo(from) || !isMessage(message) || channel !== undefined && channel !== "supervisor") {
|
|
2822
|
+
const { from, message, channel, hostedRecipient } = brokerMessage;
|
|
2823
|
+
if (!isSessionInfo(from) || !isMessage(message) || channel !== undefined && channel !== "supervisor" || hostedRecipient !== undefined && typeof hostedRecipient !== "string") {
|
|
2540
2824
|
throw new Error("Invalid message event");
|
|
2541
2825
|
}
|
|
2542
|
-
|
|
2826
|
+
if (hostedRecipient !== undefined)
|
|
2827
|
+
this.emit("hosted_message", hostedRecipient, from, message, channel);
|
|
2828
|
+
else
|
|
2829
|
+
this.emit("message", from, message, channel);
|
|
2543
2830
|
break;
|
|
2544
2831
|
}
|
|
2545
2832
|
case "pending_stage_message": {
|
|
@@ -2684,6 +2971,23 @@ var init_client = __esm(() => {
|
|
|
2684
2971
|
this.emit("released_child_reply", notice);
|
|
2685
2972
|
break;
|
|
2686
2973
|
}
|
|
2974
|
+
case "hosted_sessions_ack": {
|
|
2975
|
+
const { requestId, refusal, sessions } = brokerMessage;
|
|
2976
|
+
const parsedRefusal = readHostedSessionRefusal(refusal);
|
|
2977
|
+
const assignments = sessions === undefined ? [] : readHostedSessionAssignments(sessions);
|
|
2978
|
+
if (typeof requestId !== "string" || refusal !== undefined && parsedRefusal === undefined || assignments === undefined) {
|
|
2979
|
+
throw new Error("Invalid hosted_sessions_ack message");
|
|
2980
|
+
}
|
|
2981
|
+
const pending = this.pendingHostedSessionRequests.get(requestId);
|
|
2982
|
+
if (!pending)
|
|
2983
|
+
return;
|
|
2984
|
+
this.pendingHostedSessionRequests.delete(requestId);
|
|
2985
|
+
if (parsedRefusal === undefined)
|
|
2986
|
+
pending.resolve(assignments);
|
|
2987
|
+
else
|
|
2988
|
+
pending.reject(hostedSessionErrorFor(parsedRefusal));
|
|
2989
|
+
break;
|
|
2990
|
+
}
|
|
2687
2991
|
case "released_children_ack": {
|
|
2688
2992
|
const { requestId, refusal } = brokerMessage;
|
|
2689
2993
|
const parsed = refusal === undefined ? undefined : readReleasedChildRefusal(refusal);
|
|
@@ -2730,7 +3034,9 @@ var init_client = __esm(() => {
|
|
|
2730
3034
|
case "delivery_failed": {
|
|
2731
3035
|
const { messageId, attemptId, reason, reasonCode } = brokerMessage;
|
|
2732
3036
|
const wireError = brokerMessage.error;
|
|
2733
|
-
const
|
|
3037
|
+
const releasedReplyError = readSerializedIntercomReleasedReplyError(wireError);
|
|
3038
|
+
const hostedSessionError = readSerializedIntercomHostedSessionError(wireError);
|
|
3039
|
+
const error = releasedReplyError ?? hostedSessionError;
|
|
2734
3040
|
const wireRecipientError = brokerMessage.recipientError;
|
|
2735
3041
|
const recipientError = readSerializedIntercomRecipientGoneError(wireRecipientError);
|
|
2736
3042
|
if (typeof messageId !== "string" || attemptId !== undefined && typeof attemptId !== "string" || typeof reason !== "string" || reasonCode !== undefined && (typeof reasonCode !== "string" || !isDeliveryFailureReasonCode(reasonCode)) || wireError !== undefined && (error === undefined || error.code !== reasonCode) || wireRecipientError !== undefined && (recipientError === undefined || reasonCode !== undefined)) {
|
|
@@ -2741,7 +3047,8 @@ var init_client = __esm(() => {
|
|
|
2741
3047
|
delivered: false,
|
|
2742
3048
|
reason,
|
|
2743
3049
|
...reasonCode === undefined ? {} : { reasonCode },
|
|
2744
|
-
...
|
|
3050
|
+
...releasedReplyError === undefined ? {} : { error: rehydrateIntercomReleasedReplyError(releasedReplyError) },
|
|
3051
|
+
...hostedSessionError === undefined ? {} : { error: rehydrateIntercomHostedSessionError(hostedSessionError) },
|
|
2745
3052
|
...recipientError === undefined ? {} : { reasonCode: recipientError.code, error: rehydrateIntercomRecipientGoneError(recipientError) }
|
|
2746
3053
|
};
|
|
2747
3054
|
if (attemptId === undefined)
|
|
@@ -3151,15 +3458,76 @@ var init_client = __esm(() => {
|
|
|
3151
3458
|
});
|
|
3152
3459
|
return true;
|
|
3153
3460
|
}
|
|
3154
|
-
requireBrokerProtocol(feature) {
|
|
3461
|
+
requireBrokerProtocol(feature, requiredProtocol = VERIFIED_REGISTRATION_PROTOCOL) {
|
|
3155
3462
|
const broker = this._brokerProtocol;
|
|
3156
|
-
if (this._sessionId === null || broker.max >=
|
|
3463
|
+
if (this._sessionId === null || broker.max >= requiredProtocol)
|
|
3157
3464
|
return;
|
|
3158
3465
|
throw new IntercomBrokerProtocolError({
|
|
3159
3466
|
feature,
|
|
3160
3467
|
brokerProtocolMin: broker.min,
|
|
3161
3468
|
brokerProtocolMax: broker.max,
|
|
3162
|
-
requiredProtocol
|
|
3469
|
+
requiredProtocol
|
|
3470
|
+
});
|
|
3471
|
+
}
|
|
3472
|
+
async hostSessions(sessions) {
|
|
3473
|
+
this.requireBrokerProtocol("host_sessions", HOSTED_SESSIONS_PROTOCOL);
|
|
3474
|
+
const frames = [];
|
|
3475
|
+
for (let start = 0;start < sessions.length; start += HOSTED_SESSION_FRAME_MAX) {
|
|
3476
|
+
const frame = sessions.slice(start, start + HOSTED_SESSION_FRAME_MAX);
|
|
3477
|
+
const wire = JSON.parse(JSON.stringify(frame));
|
|
3478
|
+
const validation = validateHostSessionsFrame(wire);
|
|
3479
|
+
if (!validation.ok)
|
|
3480
|
+
throw hostedSessionErrorFor(validation.refusal);
|
|
3481
|
+
frames.push(frame);
|
|
3482
|
+
}
|
|
3483
|
+
const assigned = [];
|
|
3484
|
+
for (const frame of frames)
|
|
3485
|
+
assigned.push(...await this.hostedSessionRequest({ type: "host_sessions", sessions: frame }));
|
|
3486
|
+
return assigned;
|
|
3487
|
+
}
|
|
3488
|
+
async unhostSessions(sessionIds) {
|
|
3489
|
+
this.requireBrokerProtocol("unhost_sessions", HOSTED_SESSIONS_PROTOCOL);
|
|
3490
|
+
if (sessionIds.length === 0)
|
|
3491
|
+
throw new HostedSessionRequestError("invalid_hosted_frame");
|
|
3492
|
+
for (let start = 0;start < sessionIds.length; start += HOSTED_SESSION_FRAME_MAX) {
|
|
3493
|
+
await this.hostedSessionRequest({
|
|
3494
|
+
type: "unhost_sessions",
|
|
3495
|
+
sessionIds: sessionIds.slice(start, start + HOSTED_SESSION_FRAME_MAX)
|
|
3496
|
+
});
|
|
3497
|
+
}
|
|
3498
|
+
}
|
|
3499
|
+
hostedSessionRequest(frame) {
|
|
3500
|
+
const socket = this.requireActiveSocket();
|
|
3501
|
+
const requestId = randomUUID2();
|
|
3502
|
+
const startedAt = performance.now();
|
|
3503
|
+
return new Promise((resolve, reject) => {
|
|
3504
|
+
const timeout = setTimeout(() => {
|
|
3505
|
+
this.pendingHostedSessionRequests.delete(requestId);
|
|
3506
|
+
const timedOut = {
|
|
3507
|
+
requestType: frame.type === "unhost_sessions" ? "unhost_sessions" : "host_sessions",
|
|
3508
|
+
sessionCount: Array.isArray(frame.sessions) ? frame.sessions.length : Array.isArray(frame.sessionIds) ? frame.sessionIds.length : 0,
|
|
3509
|
+
timeoutMs: RESTORING_RECIPIENT_REQUEST_TIMEOUT_MS,
|
|
3510
|
+
elapsedMs: Math.round(performance.now() - startedAt)
|
|
3511
|
+
};
|
|
3512
|
+
this.requestTimeout(socket, new IntercomHostedSessionTimeoutError(timedOut)).then((error) => reject(error instanceof IntercomBrokerTimeoutError && !(error instanceof IntercomHostedSessionTimeoutError) ? new IntercomHostedSessionTimeoutError(timedOut, { cause: error }) : error));
|
|
3513
|
+
}, RESTORING_RECIPIENT_REQUEST_TIMEOUT_MS);
|
|
3514
|
+
this.pendingHostedSessionRequests.set(requestId, {
|
|
3515
|
+
resolve: (sessions) => {
|
|
3516
|
+
clearTimeout(timeout);
|
|
3517
|
+
resolve([...sessions]);
|
|
3518
|
+
},
|
|
3519
|
+
reject: (error) => {
|
|
3520
|
+
clearTimeout(timeout);
|
|
3521
|
+
reject(error);
|
|
3522
|
+
}
|
|
3523
|
+
});
|
|
3524
|
+
try {
|
|
3525
|
+
writeMessage(socket, { ...frame, requestId });
|
|
3526
|
+
} catch (error) {
|
|
3527
|
+
clearTimeout(timeout);
|
|
3528
|
+
this.pendingHostedSessionRequests.delete(requestId);
|
|
3529
|
+
reject(toError2(error));
|
|
3530
|
+
}
|
|
3163
3531
|
});
|
|
3164
3532
|
}
|
|
3165
3533
|
restoringRecipientRequest(frame) {
|
|
@@ -3418,6 +3786,7 @@ var init_client = __esm(() => {
|
|
|
3418
3786
|
...options.expectedRecipientId === undefined ? {} : { expectedRecipientId: options.expectedRecipientId },
|
|
3419
3787
|
...options.onReplyTarget === undefined ? {} : { resolveReplyTarget: true },
|
|
3420
3788
|
...type === "send" ? { awaitRestoringRecipient: true } : {},
|
|
3789
|
+
hostedSender: options.hostedSender,
|
|
3421
3790
|
message,
|
|
3422
3791
|
attemptId: acquired.attempt.attemptId,
|
|
3423
3792
|
...extra
|
|
@@ -8971,14 +9340,21 @@ function createConcurrencyGate(limit) {
|
|
|
8971
9340
|
var ROUTE_CLIENT_CONNECT_CONCURRENCY = 4;
|
|
8972
9341
|
|
|
8973
9342
|
// dist/builtin/intercom/released-stage-peers.ts
|
|
9343
|
+
import { randomUUID as randomUUID8 } from "node:crypto";
|
|
8974
9344
|
function isReleasedStageAnnouncement(value) {
|
|
8975
9345
|
const route = value;
|
|
8976
9346
|
const live = route.liveRoute;
|
|
8977
9347
|
return typeof route.runId === "string" && route.runId.length > 0 && typeof route.stageId === "string" && route.stageId.length > 0 && typeof route.stageName === "string" && typeof route.sessionId === "string" && route.sessionId.length > 0 && typeof route.group === "string" && (route.model === undefined || typeof route.model === "string") && typeof route.answer === "function" && (live === undefined || typeof live.capability === "string" && Array.isArray(live.stageKeys) && live.stageKeys.every((key) => typeof key === "string"));
|
|
8978
9348
|
}
|
|
9349
|
+
function isRetryableHostingFailure(error) {
|
|
9350
|
+
return error.retryable !== false;
|
|
9351
|
+
}
|
|
8979
9352
|
function peerKey(route) {
|
|
8980
9353
|
return `${route.runId}\x00${route.stageId}`;
|
|
8981
9354
|
}
|
|
9355
|
+
function sameRegistration(left, right) {
|
|
9356
|
+
return left.sessionId === right.sessionId && left.group === right.group && left.model === right.model && left.liveRoute?.capability === right.liveRoute?.capability && (left.liveRoute?.stageKeys ?? []).join("\x00") === (right.liveRoute?.stageKeys ?? []).join("\x00");
|
|
9357
|
+
}
|
|
8982
9358
|
function askPrompt(from, message) {
|
|
8983
9359
|
const attachments = message.content.attachments?.length ? formatAttachments(message.content.attachments) : "";
|
|
8984
9360
|
return [
|
|
@@ -8996,6 +9372,12 @@ function askPrompt(from, message) {
|
|
|
8996
9372
|
class ReleasedStagePeers {
|
|
8997
9373
|
deps;
|
|
8998
9374
|
peers = new Map;
|
|
9375
|
+
hostAddress = `released-stages:${randomUUID8()}`;
|
|
9376
|
+
client = null;
|
|
9377
|
+
connecting = null;
|
|
9378
|
+
reconnectTimer = null;
|
|
9379
|
+
reconnectAttempt = 0;
|
|
9380
|
+
epoch = 0;
|
|
8999
9381
|
constructor(deps) {
|
|
9000
9382
|
this.deps = deps;
|
|
9001
9383
|
}
|
|
@@ -9003,114 +9385,227 @@ class ReleasedStagePeers {
|
|
|
9003
9385
|
return this.peers.size;
|
|
9004
9386
|
}
|
|
9005
9387
|
async adopt(route) {
|
|
9388
|
+
if (this.reconnectTimer === null)
|
|
9389
|
+
this.reconnectAttempt = 0;
|
|
9390
|
+
const wire = JSON.parse(JSON.stringify([this.hostedSession(route)]));
|
|
9391
|
+
const validation = validateHostSessionsFrame(wire);
|
|
9392
|
+
if (!validation.ok)
|
|
9393
|
+
throw hostedSessionErrorFor(validation.refusal);
|
|
9006
9394
|
const key = peerKey(route);
|
|
9007
9395
|
const previous = this.peers.get(key);
|
|
9008
|
-
if (previous !== undefined)
|
|
9009
|
-
|
|
9010
|
-
|
|
9011
|
-
|
|
9012
|
-
|
|
9013
|
-
|
|
9014
|
-
connecting: null,
|
|
9015
|
-
reconnectTimer: null,
|
|
9016
|
-
reconnectAttempt: 0,
|
|
9017
|
-
closed: false,
|
|
9018
|
-
answering: new Set
|
|
9019
|
-
};
|
|
9396
|
+
if (previous !== undefined && sameRegistration(previous.route, route)) {
|
|
9397
|
+
previous.route = route;
|
|
9398
|
+
await this.host(previous);
|
|
9399
|
+
return;
|
|
9400
|
+
}
|
|
9401
|
+
const peer = { route, answering: new Set };
|
|
9020
9402
|
this.peers.set(key, peer);
|
|
9021
|
-
|
|
9403
|
+
if (previous !== undefined)
|
|
9404
|
+
await this.unhost(previous);
|
|
9405
|
+
await this.host(peer);
|
|
9022
9406
|
}
|
|
9023
9407
|
async disconnectAll() {
|
|
9024
|
-
|
|
9408
|
+
this.epoch += 1;
|
|
9025
9409
|
this.peers.clear();
|
|
9026
|
-
|
|
9410
|
+
clearTimeout(this.reconnectTimer ?? undefined);
|
|
9411
|
+
this.reconnectTimer = null;
|
|
9412
|
+
this.reconnectAttempt = 0;
|
|
9413
|
+
const client = this.client;
|
|
9414
|
+
this.client = null;
|
|
9415
|
+
await Promise.allSettled([this.connecting]);
|
|
9416
|
+
await client?.disconnect();
|
|
9417
|
+
}
|
|
9418
|
+
async host(peer) {
|
|
9419
|
+
let failure;
|
|
9420
|
+
try {
|
|
9421
|
+
const client = await this.connect();
|
|
9422
|
+
if (peer.hostedOn !== client)
|
|
9423
|
+
this.hostPending(client);
|
|
9424
|
+
failure = await peer.hosting;
|
|
9425
|
+
} catch (error) {
|
|
9426
|
+
failure = toError(error);
|
|
9427
|
+
}
|
|
9428
|
+
if (failure === undefined)
|
|
9429
|
+
return;
|
|
9430
|
+
if (isRetryableHostingFailure(failure))
|
|
9431
|
+
this.scheduleReconnect();
|
|
9432
|
+
throw failure;
|
|
9027
9433
|
}
|
|
9028
|
-
|
|
9029
|
-
|
|
9030
|
-
|
|
9031
|
-
|
|
9032
|
-
|
|
9033
|
-
|
|
9034
|
-
|
|
9035
|
-
|
|
9036
|
-
|
|
9037
|
-
|
|
9038
|
-
|
|
9039
|
-
|
|
9040
|
-
|
|
9041
|
-
|
|
9042
|
-
|
|
9434
|
+
async hostPending(client) {
|
|
9435
|
+
const pending = [...this.peers.values()].filter((peer) => peer.hostedOn !== client);
|
|
9436
|
+
const requests = [];
|
|
9437
|
+
for (let start = 0;start < pending.length; start += HOSTED_SESSION_FRAME_MAX) {
|
|
9438
|
+
const chunk = pending.slice(start, start + HOSTED_SESSION_FRAME_MAX);
|
|
9439
|
+
const byKey = new Map(chunk.map((peer) => [peerKey(peer.route), peer]));
|
|
9440
|
+
const request = client.hostSessions(chunk.map((peer) => this.hostedSession(peer.route))).then((assigned) => {
|
|
9441
|
+
for (const { key, sessionId } of assigned) {
|
|
9442
|
+
const peer = byKey.get(key);
|
|
9443
|
+
if (peer === undefined || peer.hostedOn !== client)
|
|
9444
|
+
continue;
|
|
9445
|
+
peer.sessionId = sessionId;
|
|
9446
|
+
}
|
|
9447
|
+
return;
|
|
9448
|
+
}, (error) => {
|
|
9449
|
+
for (const peer of chunk)
|
|
9450
|
+
if (peer.hostedOn === client)
|
|
9451
|
+
peer.hostedOn = undefined;
|
|
9452
|
+
if (isIntercomHostedSessionTimeoutError(error))
|
|
9453
|
+
this.dropConnection(client);
|
|
9454
|
+
return toError(error);
|
|
9455
|
+
});
|
|
9456
|
+
for (const peer of chunk) {
|
|
9457
|
+
peer.hostedOn = client;
|
|
9458
|
+
peer.sessionId = undefined;
|
|
9459
|
+
peer.hosting = request;
|
|
9460
|
+
}
|
|
9461
|
+
requests.push(request);
|
|
9462
|
+
}
|
|
9463
|
+
return (await Promise.all(requests)).find((failure) => failure !== undefined);
|
|
9464
|
+
}
|
|
9465
|
+
hostedSession(route) {
|
|
9466
|
+
const group = normalizeGroup(route.group);
|
|
9467
|
+
const now = Date.now();
|
|
9468
|
+
return {
|
|
9469
|
+
key: peerKey(route),
|
|
9470
|
+
session: {
|
|
9471
|
+
name: resolveIntercomPresenceName(undefined, route.sessionId),
|
|
9472
|
+
cwd: this.deps.cwd(),
|
|
9473
|
+
model: route.model ?? "unknown",
|
|
9474
|
+
pid: process.pid,
|
|
9475
|
+
startedAt: now,
|
|
9476
|
+
lastActivity: now,
|
|
9477
|
+
status: RELEASED_STAGE_STATUS,
|
|
9478
|
+
replyCapability: "live",
|
|
9479
|
+
groups: [group],
|
|
9480
|
+
group
|
|
9481
|
+
},
|
|
9482
|
+
returnAddress: `${route.sessionId}:released-stage`,
|
|
9483
|
+
...route.liveRoute === undefined || route.liveRoute.stageKeys.length === 0 ? {} : {
|
|
9484
|
+
liveRoute: {
|
|
9485
|
+
runId: route.runId,
|
|
9486
|
+
stageKeys: [...route.liveRoute.stageKeys],
|
|
9487
|
+
capability: route.liveRoute.capability
|
|
9488
|
+
}
|
|
9489
|
+
}
|
|
9043
9490
|
};
|
|
9044
|
-
attempt.then(settled, settled);
|
|
9045
|
-
return attempt;
|
|
9046
9491
|
}
|
|
9047
|
-
async
|
|
9048
|
-
|
|
9049
|
-
|
|
9050
|
-
|
|
9492
|
+
async unhost(peer) {
|
|
9493
|
+
await peer.hosting;
|
|
9494
|
+
const { hostedOn, sessionId } = peer;
|
|
9495
|
+
peer.hostedOn = undefined;
|
|
9496
|
+
peer.sessionId = undefined;
|
|
9497
|
+
if (sessionId === undefined || hostedOn !== this.client)
|
|
9051
9498
|
return;
|
|
9052
|
-
|
|
9053
|
-
|
|
9054
|
-
|
|
9055
|
-
|
|
9056
|
-
|
|
9057
|
-
|
|
9499
|
+
try {
|
|
9500
|
+
await hostedOn.unhostSessions([sessionId]);
|
|
9501
|
+
} catch {
|
|
9502
|
+
this.dropConnection(hostedOn);
|
|
9503
|
+
}
|
|
9504
|
+
}
|
|
9505
|
+
connect() {
|
|
9506
|
+
if (this.client !== null)
|
|
9507
|
+
return Promise.resolve(this.client);
|
|
9508
|
+
if (this.connecting === null) {
|
|
9509
|
+
const attempt = this.connectOnce();
|
|
9510
|
+
this.connecting = attempt;
|
|
9511
|
+
const settled = () => {
|
|
9512
|
+
this.connecting = null;
|
|
9513
|
+
};
|
|
9514
|
+
attempt.then(settled, settled);
|
|
9515
|
+
}
|
|
9516
|
+
return this.connecting;
|
|
9517
|
+
}
|
|
9518
|
+
async connectOnce() {
|
|
9519
|
+
const epoch = this.epoch;
|
|
9520
|
+
await this.deps.prepare();
|
|
9521
|
+
if (epoch !== this.epoch)
|
|
9522
|
+
throw new IntercomClientDisconnectedError;
|
|
9523
|
+
const client = this.deps.createClient(this.hostAddress);
|
|
9524
|
+
client.on("hosted_message", (recipient, from, message, channel) => {
|
|
9525
|
+
if (this.client === client)
|
|
9526
|
+
this.receive(client, recipient, from, message, channel);
|
|
9058
9527
|
});
|
|
9059
9528
|
client.on("disconnected", () => {
|
|
9060
|
-
if (
|
|
9529
|
+
if (this.client !== client)
|
|
9061
9530
|
return;
|
|
9062
|
-
|
|
9063
|
-
this.scheduleReconnect(
|
|
9531
|
+
this.client = null;
|
|
9532
|
+
this.scheduleReconnect();
|
|
9064
9533
|
});
|
|
9065
9534
|
client.on("error", () => {});
|
|
9066
|
-
|
|
9535
|
+
const now = Date.now();
|
|
9536
|
+
const group = this.hostAddress;
|
|
9067
9537
|
try {
|
|
9068
|
-
const now = Date.now();
|
|
9069
9538
|
await client.connect({
|
|
9070
|
-
name: resolveIntercomPresenceName(undefined, route.sessionId),
|
|
9071
9539
|
cwd: this.deps.cwd(),
|
|
9072
|
-
model:
|
|
9540
|
+
model: "unknown",
|
|
9073
9541
|
pid: process.pid,
|
|
9074
9542
|
startedAt: now,
|
|
9075
9543
|
lastActivity: now,
|
|
9076
|
-
|
|
9077
|
-
replyCapability: "live",
|
|
9544
|
+
recipientPurpose: "control",
|
|
9078
9545
|
groups: [group],
|
|
9079
9546
|
group
|
|
9080
9547
|
}, undefined, undefined, undefined, group);
|
|
9081
|
-
if (route.liveRoute !== undefined && route.liveRoute.stageKeys.length > 0) {
|
|
9082
|
-
try {
|
|
9083
|
-
await client.registerLiveWorkflowStageRoute(route.runId, [...route.liveRoute.stageKeys], route.liveRoute.capability);
|
|
9084
|
-
} catch (error) {
|
|
9085
|
-
if (!(error instanceof IntercomLiveRouteRefusedError))
|
|
9086
|
-
throw error;
|
|
9087
|
-
}
|
|
9088
|
-
}
|
|
9089
|
-
if (peer.closed) {
|
|
9090
|
-
peer.client = null;
|
|
9091
|
-
await client.disconnect();
|
|
9092
|
-
}
|
|
9093
9548
|
} catch (error) {
|
|
9094
|
-
|
|
9095
|
-
peer.client = null;
|
|
9096
|
-
try {
|
|
9097
|
-
await client.disconnect();
|
|
9098
|
-
} catch {}
|
|
9549
|
+
await client.disconnect();
|
|
9099
9550
|
throw error;
|
|
9100
9551
|
}
|
|
9552
|
+
if (epoch !== this.epoch) {
|
|
9553
|
+
await client.disconnect();
|
|
9554
|
+
throw new IntercomClientDisconnectedError;
|
|
9555
|
+
}
|
|
9556
|
+
this.client = client;
|
|
9557
|
+
return client;
|
|
9101
9558
|
}
|
|
9102
|
-
|
|
9103
|
-
if (
|
|
9559
|
+
dropConnection(client) {
|
|
9560
|
+
if (this.client !== client)
|
|
9104
9561
|
return;
|
|
9105
|
-
|
|
9106
|
-
|
|
9107
|
-
|
|
9108
|
-
|
|
9109
|
-
|
|
9110
|
-
|
|
9111
|
-
|
|
9562
|
+
this.client = null;
|
|
9563
|
+
client.disconnect().catch(() => {});
|
|
9564
|
+
}
|
|
9565
|
+
scheduleReconnect() {
|
|
9566
|
+
if (this.reconnectTimer !== null || this.peers.size === 0)
|
|
9567
|
+
return;
|
|
9568
|
+
if (this.reconnectAttempt >= RELEASED_STAGE_RECONNECT_ATTEMPTS_MAX) {
|
|
9569
|
+
this.deps.report?.({
|
|
9570
|
+
error: new IntercomClientDisconnectedError,
|
|
9571
|
+
retrying: false,
|
|
9572
|
+
attempt: this.reconnectAttempt,
|
|
9573
|
+
peers: this.peers.size
|
|
9574
|
+
});
|
|
9575
|
+
return;
|
|
9576
|
+
}
|
|
9577
|
+
this.reconnectTimer = setTimeout(() => {
|
|
9578
|
+
this.reconnectTimer = null;
|
|
9579
|
+
this.reconnectAttempt += 1;
|
|
9580
|
+
this.connect().then((client) => this.hostPending(client)).then((failure) => this.reconnectFailed(failure), (error) => this.reconnectFailed(toError(error)));
|
|
9581
|
+
}, reconnectDelayMs(this.reconnectAttempt));
|
|
9582
|
+
}
|
|
9583
|
+
reconnectFailed(failure) {
|
|
9584
|
+
if (failure === undefined) {
|
|
9585
|
+
this.reconnectAttempt = 0;
|
|
9586
|
+
return;
|
|
9587
|
+
}
|
|
9588
|
+
const retrying = isRetryableHostingFailure(failure) && this.reconnectAttempt < RELEASED_STAGE_RECONNECT_ATTEMPTS_MAX;
|
|
9589
|
+
this.deps.report?.({ error: failure, retrying, attempt: this.reconnectAttempt, peers: this.peers.size });
|
|
9590
|
+
if (retrying)
|
|
9591
|
+
this.scheduleReconnect();
|
|
9592
|
+
}
|
|
9593
|
+
peerHosting(recipient) {
|
|
9594
|
+
return [...this.peers.values()].find((candidate) => candidate.sessionId === recipient);
|
|
9595
|
+
}
|
|
9596
|
+
receive(client, recipient, from, message, channel) {
|
|
9597
|
+
const peer = this.peerHosting(recipient);
|
|
9598
|
+
if (peer !== undefined) {
|
|
9599
|
+
this.deliver(client, peer, recipient, from, message, channel);
|
|
9600
|
+
return;
|
|
9601
|
+
}
|
|
9602
|
+
Promise.all([...this.peers.values()].map((candidate) => candidate.hosting)).then(() => {
|
|
9603
|
+
const late = this.peerHosting(recipient);
|
|
9604
|
+
if (late !== undefined)
|
|
9605
|
+
this.deliver(client, late, recipient, from, message, channel);
|
|
9606
|
+
});
|
|
9112
9607
|
}
|
|
9113
|
-
|
|
9608
|
+
deliver(client, peer, recipient, from, message, channel) {
|
|
9114
9609
|
if (message.expectsReply !== true || channel !== undefined) {
|
|
9115
9610
|
this.deps.relay(from, message, channel);
|
|
9116
9611
|
return;
|
|
@@ -9118,9 +9613,9 @@ class ReleasedStagePeers {
|
|
|
9118
9613
|
if (peer.answering.has(message.id))
|
|
9119
9614
|
return;
|
|
9120
9615
|
peer.answering.add(message.id);
|
|
9121
|
-
this.answer(peer, client, from, message).finally(() => peer.answering.delete(message.id));
|
|
9616
|
+
this.answer(peer, client, recipient, from, message).finally(() => peer.answering.delete(message.id));
|
|
9122
9617
|
}
|
|
9123
|
-
async answer(peer, client, from, message) {
|
|
9618
|
+
async answer(peer, client, recipient, from, message) {
|
|
9124
9619
|
let reply;
|
|
9125
9620
|
try {
|
|
9126
9621
|
reply = { text: await peer.route.answer(askPrompt(from, message)) };
|
|
@@ -9128,47 +9623,37 @@ class ReleasedStagePeers {
|
|
|
9128
9623
|
const failure = `Released workflow stage could not answer: ${toError(error).message}`;
|
|
9129
9624
|
reply = { text: failure, replyError: failure };
|
|
9130
9625
|
}
|
|
9131
|
-
if (peer.
|
|
9132
|
-
return;
|
|
9133
|
-
try {
|
|
9134
|
-
await client.send(from.id, { ...reply, replyTo: message.id, requirePendingReply: true });
|
|
9135
|
-
} catch {}
|
|
9136
|
-
}
|
|
9137
|
-
async close(peer) {
|
|
9138
|
-
peer.closed = true;
|
|
9139
|
-
if (peer.reconnectTimer !== null)
|
|
9140
|
-
clearTimeout(peer.reconnectTimer);
|
|
9141
|
-
peer.reconnectTimer = null;
|
|
9142
|
-
if (this.peers.get(peerKey(peer.route)) === peer)
|
|
9143
|
-
this.peers.delete(peerKey(peer.route));
|
|
9144
|
-
try {
|
|
9145
|
-
await peer.connecting;
|
|
9146
|
-
} catch {}
|
|
9147
|
-
const client = peer.client;
|
|
9148
|
-
peer.client = null;
|
|
9149
|
-
if (client === null)
|
|
9626
|
+
if (peer.sessionId !== recipient || this.client !== client)
|
|
9150
9627
|
return;
|
|
9151
9628
|
try {
|
|
9152
|
-
await client.
|
|
9629
|
+
await client.send(from.id, {
|
|
9630
|
+
...reply,
|
|
9631
|
+
replyTo: message.id,
|
|
9632
|
+
requirePendingReply: true,
|
|
9633
|
+
hostedSender: recipient
|
|
9634
|
+
});
|
|
9153
9635
|
} catch {}
|
|
9154
9636
|
}
|
|
9155
9637
|
}
|
|
9156
|
-
var RELEASED_STAGE_EVENT = "atomic:workflow-released-stage", RELEASED_STAGE_STATUS = "closed · reply: post-mortem only";
|
|
9638
|
+
var RELEASED_STAGE_EVENT = "atomic:workflow-released-stage", RELEASED_STAGE_STATUS = "closed · reply: post-mortem only", RELEASED_STAGE_RECONNECT_ATTEMPTS_MAX = 30;
|
|
9157
9639
|
var init_released_stage_peers = __esm(() => {
|
|
9640
|
+
init_hosted_session_errors();
|
|
9641
|
+
init_hosted_sessions();
|
|
9158
9642
|
init_group();
|
|
9643
|
+
init_hosted_session_timeout_error();
|
|
9159
9644
|
init_intercom_utils();
|
|
9160
|
-
init_live_route_refusal();
|
|
9161
9645
|
init_reconnect_backoff();
|
|
9646
|
+
init_recoverable_disconnect();
|
|
9162
9647
|
});
|
|
9163
9648
|
|
|
9164
9649
|
// dist/builtin/intercom/supervisor-authorization-registry.ts
|
|
9165
|
-
import { randomUUID as
|
|
9650
|
+
import { randomUUID as randomUUID9 } from "node:crypto";
|
|
9166
9651
|
|
|
9167
9652
|
class SupervisorAuthorizationRegistry {
|
|
9168
9653
|
byChild = new Map;
|
|
9169
9654
|
dynamicSlots = new Map;
|
|
9170
9655
|
childByCapability = new Map;
|
|
9171
|
-
ownerToken =
|
|
9656
|
+
ownerToken = randomUUID9();
|
|
9172
9657
|
get size() {
|
|
9173
9658
|
return this.byChild.size + this.dynamicSlots.size;
|
|
9174
9659
|
}
|
|
@@ -9225,8 +9710,8 @@ var exports_index_heavy = {};
|
|
|
9225
9710
|
__export(exports_index_heavy, {
|
|
9226
9711
|
default: () => piIntercomExtension
|
|
9227
9712
|
});
|
|
9228
|
-
import { APP_NAME, createGitEnvironment, IntercomRoutingMismatchError, IntercomRoutingUnavailableError as IntercomRoutingUnavailableError3, isIntercomBrokerStopTimeoutError as isIntercomBrokerStopTimeoutError2, isIntercomBrokerUpgradeError, isIntercomRoutingChangedError, isIntercomRoutingMismatchError, isIntercomRoutingUnavailableError, isProjectGroupError as isProjectGroupError2, processStorageEnvironment, sessionScopedExtensionState } from "@bastani/atomic";
|
|
9229
|
-
import { randomUUID as
|
|
9713
|
+
import { APP_NAME, createGitEnvironment, IntercomRoutingMismatchError, IntercomRoutingUnavailableError as IntercomRoutingUnavailableError3, isIntercomBrokerStopTimeoutError as isIntercomBrokerStopTimeoutError2, isIntercomBrokerUpgradeError, isIntercomRoutingChangedError, isIntercomRoutingMismatchError, isIntercomRoutingUnavailableError, isProjectGroupError as isProjectGroupError2, processStorageEnvironment, reportDebug, sessionScopedExtensionState } from "@bastani/atomic";
|
|
9714
|
+
import { randomUUID as randomUUID10 } from "node:crypto";
|
|
9230
9715
|
import { appendFileSync as appendFileSync2 } from "node:fs";
|
|
9231
9716
|
import { dirname as dirname4 } from "node:path";
|
|
9232
9717
|
import { setTimeout as delay4 } from "node:timers/promises";
|
|
@@ -9309,7 +9794,7 @@ function piIntercomExtension(pi, testOverrides = {}) {
|
|
|
9309
9794
|
const launcherCapabilityFor = (runId) => {
|
|
9310
9795
|
let capability = launcherCapabilities.get(runId);
|
|
9311
9796
|
if (capability === undefined) {
|
|
9312
|
-
capability =
|
|
9797
|
+
capability = randomUUID10();
|
|
9313
9798
|
launcherCapabilities.set(runId, capability);
|
|
9314
9799
|
}
|
|
9315
9800
|
return capability;
|
|
@@ -9319,7 +9804,12 @@ function piIntercomExtension(pi, testOverrides = {}) {
|
|
|
9319
9804
|
const pendingStageRouteConnections = new Map;
|
|
9320
9805
|
const routeClientConnectGate = createConcurrencyGate(ROUTE_CLIENT_CONNECT_CONCURRENCY);
|
|
9321
9806
|
const supervisorAuthorizations = new SupervisorAuthorizationRegistry;
|
|
9807
|
+
function reportReleasedStageFailure(event, error, fields) {
|
|
9808
|
+
const { code } = error;
|
|
9809
|
+
reportDebug("workflow", event, { name: error.name, code: typeof code === "string" ? code : undefined, message: error.message, ...fields });
|
|
9810
|
+
}
|
|
9322
9811
|
const releasedStagePeers = new ReleasedStagePeers({
|
|
9812
|
+
report: ({ error, retrying, attempt, peers }) => reportReleasedStageFailure("released-stage-reconnect-failed", error, { retrying, attempt, peers }),
|
|
9323
9813
|
prepare: () => spawnBrokerIfNeeded(config.brokerCommand, config.brokerArgs, config.brokerStartupTimeoutMs),
|
|
9324
9814
|
createClient: (returnAddress) => new IntercomClient(returnAddress),
|
|
9325
9815
|
cwd: () => getLiveContext()?.cwd ?? process.cwd(),
|
|
@@ -10437,7 +10927,9 @@ function piIntercomExtension(pi, testOverrides = {}) {
|
|
|
10437
10927
|
return;
|
|
10438
10928
|
if (!getLiveContext())
|
|
10439
10929
|
return;
|
|
10440
|
-
releasedStagePeers.adopt(payload).catch(() => {
|
|
10930
|
+
releasedStagePeers.adopt(payload).catch((error) => {
|
|
10931
|
+
reportReleasedStageFailure("released-stage-adopt-failed", toError(error), { peers: releasedStagePeers.size });
|
|
10932
|
+
});
|
|
10441
10933
|
});
|
|
10442
10934
|
async function pendingStageNotificationClient(runId) {
|
|
10443
10935
|
const route = pendingStageRoutes.get(runId);
|
|
@@ -11131,6 +11623,8 @@ function createHeavyProxy(pi, captured) {
|
|
|
11131
11623
|
init_released_child_errors();
|
|
11132
11624
|
init_released_reply_errors();
|
|
11133
11625
|
init_recipient_gone_errors();
|
|
11626
|
+
init_hosted_session_timeout_error();
|
|
11627
|
+
init_hosted_session_errors();
|
|
11134
11628
|
var SUBAGENT_CONTROL_INTERCOM_EVENT2 = "subagent:control-intercom";
|
|
11135
11629
|
var SUBAGENT_SUPERVISOR_AUTHORIZATION_EVENT2 = "subagent:supervisor-authorization";
|
|
11136
11630
|
var WORKFLOW_STAGE_LATE_MESSAGE_EVENT = "atomic:workflow-stage-late-message";
|
|
@@ -11965,25 +12459,36 @@ Usage:
|
|
|
11965
12459
|
});
|
|
11966
12460
|
}
|
|
11967
12461
|
export {
|
|
12462
|
+
HOSTED_SESSION_ERROR_CODES,
|
|
12463
|
+
HostedSessionRequestError,
|
|
11968
12464
|
INTERCOM_RECIPIENT_GONE_ERROR_CODES,
|
|
12465
|
+
IntercomHostedSessionError,
|
|
12466
|
+
IntercomHostedSessionTimeoutError,
|
|
11969
12467
|
IntercomRecipientGoneError,
|
|
11970
12468
|
IntercomReleasedChildError,
|
|
11971
12469
|
IntercomReleasedReplyError,
|
|
12470
|
+
NotHostedSessionError,
|
|
11972
12471
|
RELEASED_CHILD_ERROR_CODES,
|
|
11973
12472
|
RELEASED_REPLY_ERROR_CODES,
|
|
11974
12473
|
ReleasedChildReservationError,
|
|
11975
12474
|
ReleasedReplyAnsweredError,
|
|
11976
12475
|
ReleasedReplyInFlightError,
|
|
11977
12476
|
SUBAGENT_ENDED_OUTCOMES,
|
|
12477
|
+
StageRecipientReleasedError,
|
|
11978
12478
|
SubagentRecipientDisconnectedError,
|
|
11979
12479
|
SubagentRecipientEndedError,
|
|
11980
12480
|
SubagentRecipientOwnerSuspendedError,
|
|
11981
12481
|
UnknownReleasedChildError,
|
|
11982
12482
|
intercom as default,
|
|
12483
|
+
isHostedSessionErrorCode,
|
|
12484
|
+
isHostedSessionRequestError,
|
|
12485
|
+
isIntercomHostedSessionError,
|
|
12486
|
+
isIntercomHostedSessionTimeoutError,
|
|
11983
12487
|
isIntercomRecipientGoneError,
|
|
11984
12488
|
isIntercomRecipientGoneErrorCode,
|
|
11985
12489
|
isIntercomReleasedChildError,
|
|
11986
12490
|
isIntercomReleasedReplyError,
|
|
12491
|
+
isNotHostedSessionError,
|
|
11987
12492
|
isReleasedChildErrorCode,
|
|
11988
12493
|
isReleasedChildReservationError,
|
|
11989
12494
|
isReleasedReplyAnsweredError,
|
|
@@ -11991,15 +12496,19 @@ export {
|
|
|
11991
12496
|
isReleasedReplyInFlightError,
|
|
11992
12497
|
isRetryableIntercomRecipientGoneError,
|
|
11993
12498
|
isRetryableIntercomReleasedReplyError,
|
|
12499
|
+
isStageRecipientReleasedError,
|
|
11994
12500
|
isSubagentRecipientDisconnectedError,
|
|
11995
12501
|
isSubagentRecipientEndedError,
|
|
11996
12502
|
isSubagentRecipientOwnerSuspendedError,
|
|
11997
12503
|
isUnknownReleasedChildError,
|
|
12504
|
+
readSerializedIntercomHostedSessionError,
|
|
11998
12505
|
readSerializedIntercomRecipientGoneError,
|
|
11999
12506
|
readSerializedIntercomReleasedReplyError,
|
|
12507
|
+
rehydrateIntercomHostedSessionError,
|
|
12000
12508
|
rehydrateIntercomRecipientGoneError,
|
|
12001
12509
|
rehydrateIntercomReleasedChildError,
|
|
12002
12510
|
rehydrateIntercomReleasedReplyError,
|
|
12511
|
+
serializeIntercomHostedSessionError,
|
|
12003
12512
|
serializeIntercomRecipientGoneError,
|
|
12004
12513
|
serializeIntercomReleasedChildError,
|
|
12005
12514
|
serializeIntercomReleasedReplyError,
|