@aria-cli/tools 1.0.9 → 1.0.11
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/package.json +9 -5
- package/src/__tests__/web-fetch-download.test.ts +0 -433
- package/src/__tests__/web-tools.test.ts +0 -619
- package/src/ask-user-interaction.ts +0 -33
- package/src/cache/web-cache.ts +0 -110
- package/src/definitions/arion.ts +0 -118
- package/src/definitions/browser/browser.ts +0 -502
- package/src/definitions/browser/index.ts +0 -5
- package/src/definitions/browser/pw-downloads.ts +0 -142
- package/src/definitions/browser/pw-interactions.ts +0 -282
- package/src/definitions/browser/pw-responses.ts +0 -98
- package/src/definitions/browser/pw-session.ts +0 -405
- package/src/definitions/browser/pw-shared.ts +0 -85
- package/src/definitions/browser/pw-snapshot.ts +0 -383
- package/src/definitions/browser/pw-state.ts +0 -101
- package/src/definitions/browser/types.ts +0 -203
- package/src/definitions/code-intelligence.ts +0 -526
- package/src/definitions/core.ts +0 -118
- package/src/definitions/delegation.ts +0 -567
- package/src/definitions/deploy.ts +0 -73
- package/src/definitions/filesystem.ts +0 -217
- package/src/definitions/frg.ts +0 -67
- package/src/definitions/index.ts +0 -28
- package/src/definitions/memory.ts +0 -150
- package/src/definitions/messaging.ts +0 -734
- package/src/definitions/meta.ts +0 -392
- package/src/definitions/network.ts +0 -179
- package/src/definitions/outlook.ts +0 -318
- package/src/definitions/patch/apply-patch.ts +0 -235
- package/src/definitions/patch/fuzzy-match.ts +0 -217
- package/src/definitions/patch/index.ts +0 -1
- package/src/definitions/patch/patch-parser.ts +0 -297
- package/src/definitions/patch/sandbox-paths.ts +0 -129
- package/src/definitions/process/index.ts +0 -5
- package/src/definitions/process/process-registry.ts +0 -303
- package/src/definitions/process/process.ts +0 -456
- package/src/definitions/process/pty-keys.ts +0 -298
- package/src/definitions/process/session-slug.ts +0 -147
- package/src/definitions/quip.ts +0 -225
- package/src/definitions/search.ts +0 -67
- package/src/definitions/session-history.ts +0 -79
- package/src/definitions/shell.ts +0 -202
- package/src/definitions/slack.ts +0 -211
- package/src/definitions/web.ts +0 -119
- package/src/executors/apply-patch.ts +0 -1035
- package/src/executors/arion.ts +0 -199
- package/src/executors/code-intelligence.ts +0 -1179
- package/src/executors/deploy.ts +0 -1066
- package/src/executors/filesystem.ts +0 -1428
- package/src/executors/frg-freshness.ts +0 -743
- package/src/executors/frg.ts +0 -394
- package/src/executors/index.ts +0 -280
- package/src/executors/learning-meta.ts +0 -1367
- package/src/executors/lsp-client.ts +0 -355
- package/src/executors/memory.ts +0 -978
- package/src/executors/meta.ts +0 -293
- package/src/executors/process-registry.ts +0 -570
- package/src/executors/pty-session-store.ts +0 -43
- package/src/executors/pty.ts +0 -342
- package/src/executors/restart.ts +0 -133
- package/src/executors/search-freshness.ts +0 -249
- package/src/executors/search-types.ts +0 -98
- package/src/executors/search.ts +0 -89
- package/src/executors/self-diagnose.ts +0 -552
- package/src/executors/session-history.ts +0 -435
- package/src/executors/shell-safety.ts +0 -519
- package/src/executors/shell.ts +0 -1243
- package/src/executors/utils.ts +0 -40
- package/src/executors/web.ts +0 -786
- package/src/extraction/content-extraction.ts +0 -281
- package/src/extraction/index.ts +0 -5
- package/src/headless-control-contract.ts +0 -1149
- package/src/index.ts +0 -788
- package/src/local-control-http-auth.ts +0 -2
- package/src/mcp/client.ts +0 -218
- package/src/mcp/connection.ts +0 -568
- package/src/mcp/index.ts +0 -11
- package/src/mcp/jsonrpc.ts +0 -195
- package/src/mcp/types.ts +0 -199
- package/src/network-control-adapter.ts +0 -88
- package/src/network-runtime/address-types.ts +0 -218
- package/src/network-runtime/db-owner-fencing.ts +0 -91
- package/src/network-runtime/delivery-receipts.ts +0 -372
- package/src/network-runtime/direct-endpoint-authority.ts +0 -35
- package/src/network-runtime/index.ts +0 -316
- package/src/network-runtime/local-control-contract.ts +0 -784
- package/src/network-runtime/node-store-contract.ts +0 -46
- package/src/network-runtime/pair-route-contract.ts +0 -97
- package/src/network-runtime/peer-capabilities.ts +0 -48
- package/src/network-runtime/peer-principal-ref.ts +0 -20
- package/src/network-runtime/peer-state-machine.ts +0 -160
- package/src/network-runtime/protocol-schemas.ts +0 -265
- package/src/network-runtime/runtime-bootstrap-contract.ts +0 -83
- package/src/outlook/desktop-session.ts +0 -409
- package/src/policy.ts +0 -171
- package/src/providers/brave.ts +0 -80
- package/src/providers/duckduckgo.ts +0 -199
- package/src/providers/exa.ts +0 -85
- package/src/providers/firecrawl.ts +0 -77
- package/src/providers/index.ts +0 -8
- package/src/providers/jina.ts +0 -70
- package/src/providers/router.ts +0 -121
- package/src/providers/search-provider.ts +0 -74
- package/src/providers/tavily.ts +0 -74
- package/src/quip/desktop-session.ts +0 -435
- package/src/registry/index.ts +0 -1
- package/src/registry/registry.ts +0 -905
- package/src/runtime-socket-local-control-client.ts +0 -632
- package/src/security/dns-normalization.ts +0 -34
- package/src/security/dns-pinning.ts +0 -138
- package/src/security/external-content.ts +0 -129
- package/src/security/ssrf.ts +0 -207
- package/src/slack/desktop-session.ts +0 -493
- package/src/tool-factory.ts +0 -91
- package/src/types.ts +0 -1341
- package/src/utils/retry.ts +0 -163
- package/src/utils/safe-parse-json.ts +0 -176
- package/src/utils/url.ts +0 -20
- package/tests/benchmarks/registry.bench.ts +0 -57
- package/tests/cache/web-cache.test.ts +0 -147
- package/tests/critical-integration.test.ts +0 -1465
- package/tests/definitions/apply-patch.test.ts +0 -586
- package/tests/definitions/browser.test.ts +0 -495
- package/tests/definitions/delegation-pause-resume.test.ts +0 -758
- package/tests/definitions/execution.test.ts +0 -671
- package/tests/definitions/messaging-inbox-scope.test.ts +0 -229
- package/tests/definitions/messaging.test.ts +0 -1468
- package/tests/definitions/outlook.test.ts +0 -30
- package/tests/definitions/process.test.ts +0 -469
- package/tests/definitions/slack.test.ts +0 -28
- package/tests/definitions/tool-inventory.test.ts +0 -218
- package/tests/e2e/delegation-quest-orchestration.e2e.test.ts +0 -433
- package/tests/e2e/memory-tool-discovery-contract.e2e.test.ts +0 -81
- package/tests/executors/apply-patch.test.ts +0 -538
- package/tests/executors/arion.test.ts +0 -309
- package/tests/executors/conversation-primitives.test.ts +0 -250
- package/tests/executors/deploy.test.ts +0 -746
- package/tests/executors/filesystem-tools.test.ts +0 -357
- package/tests/executors/filesystem.test.ts +0 -959
- package/tests/executors/frg-freshness.test.ts +0 -136
- package/tests/executors/frg-merge.test.ts +0 -70
- package/tests/executors/frg-session-content.test.ts +0 -40
- package/tests/executors/frg.test.ts +0 -56
- package/tests/executors/memory-bugfixes.test.ts +0 -257
- package/tests/executors/memory-real-memoria.integration.test.ts +0 -316
- package/tests/executors/memory.test.ts +0 -853
- package/tests/executors/meta-tools.test.ts +0 -411
- package/tests/executors/meta.test.ts +0 -683
- package/tests/executors/path-containment.test.ts +0 -51
- package/tests/executors/process-registry.test.ts +0 -505
- package/tests/executors/pty.test.ts +0 -664
- package/tests/executors/quest-security.test.ts +0 -249
- package/tests/executors/read-file-media.test.ts +0 -230
- package/tests/executors/recall-knowledge-schema.test.ts +0 -209
- package/tests/executors/recall-tags.test.ts +0 -278
- package/tests/executors/remember-null-safety.contract.test.ts +0 -41
- package/tests/executors/restart.test.ts +0 -67
- package/tests/executors/search-unified.test.ts +0 -381
- package/tests/executors/session-history.test.ts +0 -340
- package/tests/executors/session-transcript.test.ts +0 -561
- package/tests/executors/shell-abort.test.ts +0 -416
- package/tests/executors/shell-env-blocklist.test.ts +0 -648
- package/tests/executors/shell-env-process.test.ts +0 -245
- package/tests/executors/shell-process-registry.test.ts +0 -334
- package/tests/executors/shell-tools.test.ts +0 -393
- package/tests/executors/shell.test.ts +0 -690
- package/tests/executors/web-abort-vs-timeout.test.ts +0 -213
- package/tests/executors/web-integration.test.ts +0 -633
- package/tests/executors/web-symlink.test.ts +0 -18
- package/tests/executors/web.test.ts +0 -1400
- package/tests/executors/write-stdin.test.ts +0 -145
- package/tests/extraction/content-extraction.test.ts +0 -153
- package/tests/guards/tools-default-test-lane.integration.test.ts +0 -21
- package/tests/guards/tools-package-test-commands.e2e.test.ts +0 -43
- package/tests/guards/tools-test-lane-manifest.contract.test.ts +0 -76
- package/tests/guards/tools-vitest-workspace-alias.contract.test.ts +0 -63
- package/tests/helpers/async-waits.ts +0 -53
- package/tests/integration/headless-control-contract.integration.test.ts +0 -153
- package/tests/integration/memory-tool-schema-parity.integration.test.ts +0 -67
- package/tests/integration/meta-tools-round-trip.integration.test.ts +0 -506
- package/tests/integration/quest-round-trip.test.ts +0 -303
- package/tests/integration/registry-executor-flow.test.ts +0 -85
- package/tests/integration.test.ts +0 -177
- package/tests/loading-tier.test.ts +0 -126
- package/tests/mcp/client-reconnect.test.ts +0 -267
- package/tests/mcp/connection.test.ts +0 -846
- package/tests/mcp/injectable-logger.test.ts +0 -83
- package/tests/mcp/jsonrpc.test.ts +0 -109
- package/tests/mcp/lifecycle.test.ts +0 -879
- package/tests/network-runtime/address-types.contract.test.ts +0 -143
- package/tests/network-runtime/continuity-bind-schema.contract.test.ts +0 -203
- package/tests/network-runtime/local-control-contract.test.ts +0 -869
- package/tests/network-runtime/local-control-invite-token.contract.test.ts +0 -146
- package/tests/network-runtime/node-store-contract.test.ts +0 -11
- package/tests/network-runtime/pair-protocol-nodeid.contract.test.ts +0 -15
- package/tests/network-runtime/peer-state-machine.contract.test.ts +0 -148
- package/tests/network-runtime/protocol-schemas.contract.test.ts +0 -512
- package/tests/network-runtime/relay-pending-nodeid.contract.test.ts +0 -62
- package/tests/network-runtime/runtime-bootstrap-contract.test.ts +0 -227
- package/tests/network-runtime/runtime-socket-local-control-client.test.ts +0 -621
- package/tests/network-runtime/wait-for-message-script.test.ts +0 -288
- package/tests/parallel.test.ts +0 -71
- package/tests/policy.test.ts +0 -184
- package/tests/print-default-test-lane.ts +0 -14
- package/tests/print-test-lane-manifest.ts +0 -22
- package/tests/providers/brave.test.ts +0 -159
- package/tests/providers/duckduckgo.test.ts +0 -207
- package/tests/providers/exa.test.ts +0 -175
- package/tests/providers/firecrawl.test.ts +0 -168
- package/tests/providers/jina.test.ts +0 -144
- package/tests/providers/router.test.ts +0 -328
- package/tests/providers/tavily.test.ts +0 -165
- package/tests/registry/discovery.test.ts +0 -154
- package/tests/registry/injectable-logger.test.ts +0 -230
- package/tests/registry/input-validation.test.ts +0 -361
- package/tests/registry/interface-completeness.test.ts +0 -85
- package/tests/registry/mcp-integration.test.ts +0 -103
- package/tests/registry/mcp-read-only-hint.test.ts +0 -60
- package/tests/registry/memoria-discovery.test.ts +0 -390
- package/tests/registry/nested-validation.test.ts +0 -283
- package/tests/registry/pseudo-tool-filtering.test.ts +0 -258
- package/tests/registry/registration-lifecycle.test.ts +0 -133
- package/tests/registry-validation.test.ts +0 -424
- package/tests/registry.test.ts +0 -460
- package/tests/security/dns-pinning.test.ts +0 -162
- package/tests/security/external-content.test.ts +0 -144
- package/tests/security/ssrf.test.ts +0 -118
- package/tests/shell-safety-integration.test.ts +0 -32
- package/tests/shell-safety.test.ts +0 -365
- package/tests/slack/desktop-session.test.ts +0 -50
- package/tests/test-lane-manifest.ts +0 -440
- package/tests/test-utils.ts +0 -27
- package/tests/tool-factory.test.ts +0 -188
- package/tests/utils/retry.test.ts +0 -231
- package/tests/utils/url.test.ts +0 -63
- package/tsconfig.cjs.json +0 -24
- package/tsconfig.json +0 -12
- package/vitest.config.ts +0 -55
- package/vitest.e2e.config.ts +0 -24
- package/vitest.integration.config.ts +0 -24
- package/vitest.native.config.ts +0 -24
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared database-level ownership fencing for runtime-owned durable stores.
|
|
3
|
-
*
|
|
4
|
-
* All stores backed by the same SQLite database share one `owner_epoch` table.
|
|
5
|
-
* The runtime claims the epoch once at startup. Each store's write methods
|
|
6
|
-
* call `assertDbOwnership()` before durable mutations.
|
|
7
|
-
*
|
|
8
|
-
* A zombie runtime whose generation is stale gets StaleOwnerError on
|
|
9
|
-
* its next write — no external kill needed.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
interface SqliteStatementLike {
|
|
13
|
-
run(...params: unknown[]): { changes: number };
|
|
14
|
-
get(...params: unknown[]): unknown;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface OwnerEpochDb {
|
|
18
|
-
exec(sql: string): unknown;
|
|
19
|
-
prepare(sql: string): SqliteStatementLike;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export class StaleOwnerError extends Error {
|
|
23
|
-
readonly kind = "StaleOwnerError" as const;
|
|
24
|
-
readonly claimedGeneration: number;
|
|
25
|
-
readonly currentGeneration: number;
|
|
26
|
-
|
|
27
|
-
constructor(claimed: number, current: number) {
|
|
28
|
-
super(
|
|
29
|
-
`StaleOwnerError: runtime claims generation ${claimed} but store is at generation ${current}. ` +
|
|
30
|
-
`This runtime has been superseded and must shut down immediately.`,
|
|
31
|
-
);
|
|
32
|
-
this.name = "StaleOwnerError";
|
|
33
|
-
this.claimedGeneration = claimed;
|
|
34
|
-
this.currentGeneration = current;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Ensure the owner_epoch table exists in the given database.
|
|
40
|
-
* Safe to call multiple times (idempotent).
|
|
41
|
-
*/
|
|
42
|
-
export function ensureOwnerEpochTable(db: OwnerEpochDb): void {
|
|
43
|
-
db.exec(`
|
|
44
|
-
CREATE TABLE IF NOT EXISTS owner_epoch (
|
|
45
|
-
scope TEXT PRIMARY KEY DEFAULT 'runtime',
|
|
46
|
-
owner_generation INTEGER NOT NULL
|
|
47
|
-
)
|
|
48
|
-
`);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Atomically claim the owner epoch for this runtime.
|
|
53
|
-
* Throws StaleOwnerError if a newer generation already owns the database.
|
|
54
|
-
*/
|
|
55
|
-
export function claimDbOwnerEpoch(db: OwnerEpochDb, generation: number): void {
|
|
56
|
-
ensureOwnerEpochTable(db);
|
|
57
|
-
|
|
58
|
-
const result = db
|
|
59
|
-
.prepare(
|
|
60
|
-
`INSERT INTO owner_epoch (scope, owner_generation) VALUES ('runtime', ?)
|
|
61
|
-
ON CONFLICT(scope) DO UPDATE SET owner_generation = excluded.owner_generation
|
|
62
|
-
WHERE excluded.owner_generation > owner_epoch.owner_generation`,
|
|
63
|
-
)
|
|
64
|
-
.run(generation);
|
|
65
|
-
|
|
66
|
-
if (result.changes === 0) {
|
|
67
|
-
const row = db
|
|
68
|
-
.prepare("SELECT owner_generation FROM owner_epoch WHERE scope = 'runtime'")
|
|
69
|
-
.get() as { owner_generation: number } | undefined;
|
|
70
|
-
const current = row?.owner_generation ?? 0;
|
|
71
|
-
if (current > generation) {
|
|
72
|
-
throw new StaleOwnerError(generation, current);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Assert the calling runtime is still the current owner of this database.
|
|
79
|
-
* Must be called inside the same SQLite transaction as the write.
|
|
80
|
-
* Throws StaleOwnerError if superseded.
|
|
81
|
-
*/
|
|
82
|
-
export function assertDbOwnership(db: OwnerEpochDb, generation: number): void {
|
|
83
|
-
const row = db
|
|
84
|
-
.prepare("SELECT owner_generation FROM owner_epoch WHERE scope = 'runtime'")
|
|
85
|
-
.get() as { owner_generation: number } | undefined;
|
|
86
|
-
|
|
87
|
-
const current = row?.owner_generation ?? 0;
|
|
88
|
-
if (current > generation) {
|
|
89
|
-
throw new StaleOwnerError(generation, current);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
@@ -1,372 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
|
|
3
|
-
export const RuntimeTransportSchema = z.enum(["in_process", "local_runtime", "tunnel", "relay"]);
|
|
4
|
-
export type RuntimeTransport = z.infer<typeof RuntimeTransportSchema>;
|
|
5
|
-
|
|
6
|
-
export const DeliveryStateSchema = z.enum([
|
|
7
|
-
"accepted",
|
|
8
|
-
"queued_for_route",
|
|
9
|
-
"dispatching",
|
|
10
|
-
"sent",
|
|
11
|
-
"acked",
|
|
12
|
-
"expired",
|
|
13
|
-
"failed",
|
|
14
|
-
"rejected",
|
|
15
|
-
]);
|
|
16
|
-
export type DeliveryState = z.infer<typeof DeliveryStateSchema>;
|
|
17
|
-
|
|
18
|
-
export const SessionStateSchema = z.enum(["none", "handshaking", "connected", "reconnecting", "dead"]);
|
|
19
|
-
export type SessionState = z.infer<typeof SessionStateSchema>;
|
|
20
|
-
|
|
21
|
-
export const DeliveryReadinessSchema = z.enum([
|
|
22
|
-
"cannot_address",
|
|
23
|
-
"can_queue_only",
|
|
24
|
-
"can_send_now",
|
|
25
|
-
]);
|
|
26
|
-
export type DeliveryReadiness = z.infer<typeof DeliveryReadinessSchema>;
|
|
27
|
-
|
|
28
|
-
export const QueuedReasonSchema = z.enum([
|
|
29
|
-
"route_not_established",
|
|
30
|
-
"awaiting_remote_ack",
|
|
31
|
-
"transport_unavailable",
|
|
32
|
-
]);
|
|
33
|
-
export type QueuedReason = z.infer<typeof QueuedReasonSchema>;
|
|
34
|
-
|
|
35
|
-
export const OutboxReceiptStatusSchema = z.enum([
|
|
36
|
-
"queued_for_route",
|
|
37
|
-
"dispatching",
|
|
38
|
-
"acked",
|
|
39
|
-
"expired",
|
|
40
|
-
]);
|
|
41
|
-
export type OutboxReceiptStatus = z.infer<typeof OutboxReceiptStatusSchema>;
|
|
42
|
-
|
|
43
|
-
export const DeliveryReceiptInputSchema = z
|
|
44
|
-
.object({
|
|
45
|
-
transport: RuntimeTransportSchema,
|
|
46
|
-
delivered: z.boolean(),
|
|
47
|
-
queued: z.boolean(),
|
|
48
|
-
accepted: z.boolean().optional(),
|
|
49
|
-
deliveryState: DeliveryStateSchema.optional(),
|
|
50
|
-
sessionState: SessionStateSchema.optional(),
|
|
51
|
-
deliveryReadiness: DeliveryReadinessSchema.optional(),
|
|
52
|
-
queuedReason: QueuedReasonSchema.optional(),
|
|
53
|
-
})
|
|
54
|
-
.strict();
|
|
55
|
-
|
|
56
|
-
export type DeliveryReceiptInput = z.input<typeof DeliveryReceiptInputSchema>;
|
|
57
|
-
|
|
58
|
-
export interface CanonicalDeliveryReceipt {
|
|
59
|
-
transport: RuntimeTransport;
|
|
60
|
-
delivered: boolean;
|
|
61
|
-
queued: boolean;
|
|
62
|
-
accepted: boolean;
|
|
63
|
-
deliveryState: DeliveryState;
|
|
64
|
-
sessionState: SessionState;
|
|
65
|
-
deliveryReadiness: DeliveryReadiness;
|
|
66
|
-
queuedReason?: QueuedReason;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const DELIVERY_STATE_RESTRICTIVENESS: Record<DeliveryState, number> = {
|
|
70
|
-
rejected: 0,
|
|
71
|
-
failed: 1,
|
|
72
|
-
expired: 2,
|
|
73
|
-
queued_for_route: 3,
|
|
74
|
-
dispatching: 4,
|
|
75
|
-
accepted: 5,
|
|
76
|
-
sent: 6,
|
|
77
|
-
acked: 7,
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
const SESSION_STATE_RESTRICTIVENESS: Record<SessionState, number> = {
|
|
81
|
-
dead: 0,
|
|
82
|
-
none: 1,
|
|
83
|
-
handshaking: 2,
|
|
84
|
-
reconnecting: 3,
|
|
85
|
-
connected: 4,
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
const DELIVERY_READINESS_RESTRICTIVENESS: Record<DeliveryReadiness, number> = {
|
|
89
|
-
cannot_address: 0,
|
|
90
|
-
can_queue_only: 1,
|
|
91
|
-
can_send_now: 2,
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
function inferLegacyDeliveryState(input: DeliveryReceiptInput, accepted: boolean): DeliveryState {
|
|
95
|
-
if (!accepted) {
|
|
96
|
-
return input.deliveryState === "rejected" ? "rejected" : "failed";
|
|
97
|
-
}
|
|
98
|
-
if (input.delivered) {
|
|
99
|
-
return "acked";
|
|
100
|
-
}
|
|
101
|
-
if (input.queued) {
|
|
102
|
-
if (
|
|
103
|
-
input.queuedReason === "awaiting_remote_ack" ||
|
|
104
|
-
input.deliveryState === "dispatching" ||
|
|
105
|
-
input.deliveryState === "sent"
|
|
106
|
-
) {
|
|
107
|
-
return "dispatching";
|
|
108
|
-
}
|
|
109
|
-
return "queued_for_route";
|
|
110
|
-
}
|
|
111
|
-
if (input.deliveryState === "expired") {
|
|
112
|
-
return "expired";
|
|
113
|
-
}
|
|
114
|
-
return "sent";
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function normalizeExplicitDeliveryState(
|
|
118
|
-
input: DeliveryReceiptInput,
|
|
119
|
-
): DeliveryState | undefined {
|
|
120
|
-
if (!input.deliveryState) {
|
|
121
|
-
return undefined;
|
|
122
|
-
}
|
|
123
|
-
if (
|
|
124
|
-
input.deliveryState === "sent" &&
|
|
125
|
-
input.queued &&
|
|
126
|
-
input.queuedReason === "awaiting_remote_ack"
|
|
127
|
-
) {
|
|
128
|
-
return "dispatching";
|
|
129
|
-
}
|
|
130
|
-
return input.deliveryState;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function chooseMoreRestrictiveDeliveryState(
|
|
134
|
-
left: DeliveryState,
|
|
135
|
-
right: DeliveryState,
|
|
136
|
-
): DeliveryState {
|
|
137
|
-
return DELIVERY_STATE_RESTRICTIVENESS[left] <= DELIVERY_STATE_RESTRICTIVENESS[right]
|
|
138
|
-
? left
|
|
139
|
-
: right;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function inferSessionStateFromDeliveryState(
|
|
143
|
-
transport: RuntimeTransport,
|
|
144
|
-
deliveryState: DeliveryState,
|
|
145
|
-
): SessionState {
|
|
146
|
-
if (transport === "local_runtime") {
|
|
147
|
-
return "none";
|
|
148
|
-
}
|
|
149
|
-
switch (deliveryState) {
|
|
150
|
-
case "queued_for_route":
|
|
151
|
-
return "handshaking";
|
|
152
|
-
case "dispatching":
|
|
153
|
-
return "connected";
|
|
154
|
-
case "failed":
|
|
155
|
-
case "rejected":
|
|
156
|
-
case "expired":
|
|
157
|
-
return "none";
|
|
158
|
-
case "acked":
|
|
159
|
-
return "connected";
|
|
160
|
-
case "accepted":
|
|
161
|
-
case "sent":
|
|
162
|
-
return "connected";
|
|
163
|
-
default:
|
|
164
|
-
return "none";
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
function chooseMoreRestrictiveSessionState(
|
|
169
|
-
transport: RuntimeTransport,
|
|
170
|
-
explicit: SessionState | undefined,
|
|
171
|
-
inferred: SessionState,
|
|
172
|
-
): SessionState {
|
|
173
|
-
if (transport === "local_runtime") {
|
|
174
|
-
return "none";
|
|
175
|
-
}
|
|
176
|
-
if (!explicit) {
|
|
177
|
-
return inferred;
|
|
178
|
-
}
|
|
179
|
-
return SESSION_STATE_RESTRICTIVENESS[explicit] <= SESSION_STATE_RESTRICTIVENESS[inferred]
|
|
180
|
-
? explicit
|
|
181
|
-
: inferred;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
function inferDeliveryReadinessFromState(
|
|
185
|
-
transport: RuntimeTransport,
|
|
186
|
-
deliveryState: DeliveryState,
|
|
187
|
-
sessionState: SessionState,
|
|
188
|
-
): DeliveryReadiness {
|
|
189
|
-
if (deliveryState === "failed" || deliveryState === "rejected") {
|
|
190
|
-
return "cannot_address";
|
|
191
|
-
}
|
|
192
|
-
if (transport === "local_runtime" && deliveryState === "acked") {
|
|
193
|
-
return "can_queue_only";
|
|
194
|
-
}
|
|
195
|
-
if (deliveryState === "queued_for_route") {
|
|
196
|
-
return "can_queue_only";
|
|
197
|
-
}
|
|
198
|
-
if (deliveryState === "dispatching") {
|
|
199
|
-
return sessionState === "reconnecting" ? "can_queue_only" : "can_send_now";
|
|
200
|
-
}
|
|
201
|
-
if (deliveryState === "expired") {
|
|
202
|
-
return "cannot_address";
|
|
203
|
-
}
|
|
204
|
-
return sessionState === "connected" ? "can_send_now" : "can_queue_only";
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
function chooseMoreRestrictiveDeliveryReadiness(
|
|
208
|
-
explicit: DeliveryReadiness | undefined,
|
|
209
|
-
inferred: DeliveryReadiness,
|
|
210
|
-
): DeliveryReadiness {
|
|
211
|
-
if (!explicit) {
|
|
212
|
-
return inferred;
|
|
213
|
-
}
|
|
214
|
-
return DELIVERY_READINESS_RESTRICTIVENESS[explicit] <=
|
|
215
|
-
DELIVERY_READINESS_RESTRICTIVENESS[inferred]
|
|
216
|
-
? explicit
|
|
217
|
-
: inferred;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
function deriveCanonicalAccepted(
|
|
221
|
-
input: DeliveryReceiptInput,
|
|
222
|
-
deliveryState: DeliveryState,
|
|
223
|
-
): boolean {
|
|
224
|
-
if (deliveryState === "rejected") {
|
|
225
|
-
return false;
|
|
226
|
-
}
|
|
227
|
-
return input.accepted ?? true;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
function isQueuedDeliveryState(deliveryState: DeliveryState): boolean {
|
|
231
|
-
return deliveryState === "queued_for_route" || deliveryState === "dispatching";
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
function inferQueuedReason(
|
|
235
|
-
input: DeliveryReceiptInput,
|
|
236
|
-
deliveryState: DeliveryState,
|
|
237
|
-
queued: boolean,
|
|
238
|
-
): QueuedReason | undefined {
|
|
239
|
-
if (!queued) {
|
|
240
|
-
return undefined;
|
|
241
|
-
}
|
|
242
|
-
if (input.queuedReason) {
|
|
243
|
-
return input.queuedReason;
|
|
244
|
-
}
|
|
245
|
-
if (deliveryState === "dispatching") {
|
|
246
|
-
return "awaiting_remote_ack";
|
|
247
|
-
}
|
|
248
|
-
if (deliveryState === "queued_for_route") {
|
|
249
|
-
return "route_not_established";
|
|
250
|
-
}
|
|
251
|
-
return undefined;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
export function canonicalizeDeliveryReceipt(
|
|
255
|
-
input: DeliveryReceiptInput,
|
|
256
|
-
): CanonicalDeliveryReceipt {
|
|
257
|
-
const inferredDeliveryState = inferLegacyDeliveryState(input, input.accepted ?? true);
|
|
258
|
-
const explicitDeliveryState = normalizeExplicitDeliveryState(input);
|
|
259
|
-
const deliveryState = explicitDeliveryState
|
|
260
|
-
? chooseMoreRestrictiveDeliveryState(explicitDeliveryState, inferredDeliveryState)
|
|
261
|
-
: inferredDeliveryState;
|
|
262
|
-
const accepted = deriveCanonicalAccepted(input, deliveryState);
|
|
263
|
-
const delivered = deliveryState === "acked";
|
|
264
|
-
const queued = isQueuedDeliveryState(deliveryState);
|
|
265
|
-
const inferredSessionState = inferSessionStateFromDeliveryState(input.transport, deliveryState);
|
|
266
|
-
const sessionState = chooseMoreRestrictiveSessionState(
|
|
267
|
-
input.transport,
|
|
268
|
-
input.sessionState,
|
|
269
|
-
inferredSessionState,
|
|
270
|
-
);
|
|
271
|
-
const inferredDeliveryReadiness = inferDeliveryReadinessFromState(
|
|
272
|
-
input.transport,
|
|
273
|
-
deliveryState,
|
|
274
|
-
sessionState,
|
|
275
|
-
);
|
|
276
|
-
const deliveryReadiness = chooseMoreRestrictiveDeliveryReadiness(
|
|
277
|
-
input.deliveryReadiness,
|
|
278
|
-
inferredDeliveryReadiness,
|
|
279
|
-
);
|
|
280
|
-
const queuedReason = inferQueuedReason(input, deliveryState, queued);
|
|
281
|
-
|
|
282
|
-
return {
|
|
283
|
-
transport: input.transport,
|
|
284
|
-
delivered,
|
|
285
|
-
queued,
|
|
286
|
-
accepted,
|
|
287
|
-
deliveryState,
|
|
288
|
-
sessionState,
|
|
289
|
-
deliveryReadiness,
|
|
290
|
-
...(queuedReason ? { queuedReason } : {}),
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
export function createAckedDeliveryReceipt(input: {
|
|
295
|
-
transport: RuntimeTransport;
|
|
296
|
-
sessionState?: SessionState;
|
|
297
|
-
deliveryReadiness?: DeliveryReadiness;
|
|
298
|
-
}): CanonicalDeliveryReceipt {
|
|
299
|
-
return canonicalizeDeliveryReceipt({
|
|
300
|
-
transport: input.transport,
|
|
301
|
-
delivered: true,
|
|
302
|
-
queued: false,
|
|
303
|
-
accepted: true,
|
|
304
|
-
deliveryState: "acked",
|
|
305
|
-
...(input.sessionState ? { sessionState: input.sessionState } : {}),
|
|
306
|
-
...(input.deliveryReadiness ? { deliveryReadiness: input.deliveryReadiness } : {}),
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
export function createQueuedForRouteReceipt(input: {
|
|
311
|
-
transport: RuntimeTransport;
|
|
312
|
-
sessionState?: SessionState;
|
|
313
|
-
deliveryReadiness?: DeliveryReadiness;
|
|
314
|
-
}): CanonicalDeliveryReceipt {
|
|
315
|
-
return canonicalizeDeliveryReceipt({
|
|
316
|
-
transport: input.transport,
|
|
317
|
-
delivered: false,
|
|
318
|
-
queued: true,
|
|
319
|
-
accepted: true,
|
|
320
|
-
deliveryState: "queued_for_route",
|
|
321
|
-
queuedReason: "route_not_established",
|
|
322
|
-
...(input.sessionState ? { sessionState: input.sessionState } : {}),
|
|
323
|
-
...(input.deliveryReadiness ? { deliveryReadiness: input.deliveryReadiness } : {}),
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
export function createDispatchingDeliveryReceipt(input: {
|
|
328
|
-
transport: RuntimeTransport;
|
|
329
|
-
sessionState?: SessionState;
|
|
330
|
-
deliveryReadiness?: DeliveryReadiness;
|
|
331
|
-
}): CanonicalDeliveryReceipt {
|
|
332
|
-
return canonicalizeDeliveryReceipt({
|
|
333
|
-
transport: input.transport,
|
|
334
|
-
delivered: false,
|
|
335
|
-
queued: true,
|
|
336
|
-
accepted: true,
|
|
337
|
-
deliveryState: "dispatching",
|
|
338
|
-
queuedReason: "awaiting_remote_ack",
|
|
339
|
-
...(input.sessionState ? { sessionState: input.sessionState } : {}),
|
|
340
|
-
...(input.deliveryReadiness ? { deliveryReadiness: input.deliveryReadiness } : {}),
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
export function createSentDeliveryReceipt(input: {
|
|
345
|
-
transport: RuntimeTransport;
|
|
346
|
-
sessionState?: SessionState;
|
|
347
|
-
deliveryReadiness?: DeliveryReadiness;
|
|
348
|
-
}): CanonicalDeliveryReceipt {
|
|
349
|
-
return canonicalizeDeliveryReceipt({
|
|
350
|
-
transport: input.transport,
|
|
351
|
-
delivered: false,
|
|
352
|
-
queued: false,
|
|
353
|
-
accepted: true,
|
|
354
|
-
deliveryState: "sent",
|
|
355
|
-
...(input.sessionState ? { sessionState: input.sessionState } : {}),
|
|
356
|
-
...(input.deliveryReadiness ? { deliveryReadiness: input.deliveryReadiness } : {}),
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
export function canonicalizeOutboxReceiptStatus(status: string): OutboxReceiptStatus {
|
|
361
|
-
switch (status) {
|
|
362
|
-
case "queued":
|
|
363
|
-
case "queued_for_route":
|
|
364
|
-
return "queued_for_route";
|
|
365
|
-
case "dispatching":
|
|
366
|
-
case "acked":
|
|
367
|
-
case "expired":
|
|
368
|
-
return status;
|
|
369
|
-
default:
|
|
370
|
-
throw new Error(`[delivery-receipts] Unsupported outbox status: ${status}`);
|
|
371
|
-
}
|
|
372
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
function normalizeHost(host: string): string {
|
|
2
|
-
return host.trim().toLowerCase();
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export function isLoopbackDirectEndpointHost(host: string): boolean {
|
|
6
|
-
const normalized = normalizeHost(host);
|
|
7
|
-
return (
|
|
8
|
-
normalized === "localhost" ||
|
|
9
|
-
normalized === "::1" ||
|
|
10
|
-
normalized === "[::1]" ||
|
|
11
|
-
normalized.endsWith(".localhost") ||
|
|
12
|
-
/^127\./.test(normalized)
|
|
13
|
-
);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function canonicalizeAuthoritativeDirectEndpoint(input: {
|
|
17
|
-
endpointHost?: string | null;
|
|
18
|
-
endpointPort?: number | null;
|
|
19
|
-
}): {
|
|
20
|
-
endpointHost?: string;
|
|
21
|
-
endpointPort?: number;
|
|
22
|
-
} {
|
|
23
|
-
const rawHost = input.endpointHost?.trim();
|
|
24
|
-
const port = input.endpointPort;
|
|
25
|
-
if (!rawHost || typeof port !== "number" || !Number.isFinite(port)) {
|
|
26
|
-
return {};
|
|
27
|
-
}
|
|
28
|
-
if (isLoopbackDirectEndpointHost(rawHost)) {
|
|
29
|
-
return {};
|
|
30
|
-
}
|
|
31
|
-
return {
|
|
32
|
-
endpointHost: rawHost,
|
|
33
|
-
endpointPort: port,
|
|
34
|
-
};
|
|
35
|
-
}
|