@astrosheep/square 0.3.106 → 0.4.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/dist/activity-feed.js +1 -1
- package/dist/artifact-store.d.ts +41 -0
- package/dist/artifact-store.js +272 -0
- package/dist/artifact.d.ts +6 -12
- package/dist/artifact.js +43 -344
- package/dist/attention-presentation.d.ts +13 -7
- package/dist/attention-presentation.js +29 -68
- package/dist/boundary-presentation.d.ts +3 -16
- package/dist/boundary-presentation.js +29 -109
- package/dist/card-presentation.d.ts +1 -0
- package/dist/card-presentation.js +2 -0
- package/dist/catch-decisions.d.ts +2 -2
- package/dist/catch-decisions.js +7 -3
- package/dist/catch-selection.d.ts +8 -0
- package/dist/catch-selection.js +5 -0
- package/dist/claude-delivery.d.ts +14 -12
- package/dist/claude-delivery.js +42 -142
- package/dist/claude-mcp-context.js +2 -2
- package/dist/claude-mod.js +28 -140
- package/dist/claude-transport.d.ts +5 -0
- package/dist/claude-transport.js +34 -0
- package/dist/cli/context.d.ts +2 -2
- package/dist/cli/context.js +7 -10
- package/dist/cli/maintenance-commands.d.ts +0 -4
- package/dist/cli/maintenance-commands.js +2 -29
- package/dist/cli/observation-commands.d.ts +2 -0
- package/dist/cli/observation-commands.js +12 -2
- package/dist/cli/program.js +1 -1
- package/dist/cli/registry.js +4 -3
- package/dist/codex-address.d.ts +2 -2
- package/dist/codex-boundary-state.d.ts +1 -5
- package/dist/codex-boundary-state.js +0 -4
- package/dist/codex-hook.d.ts +7 -10
- package/dist/codex-hook.js +69 -33
- package/dist/codex-queue.d.ts +10 -11
- package/dist/codex-queue.js +32 -34
- package/dist/codex-watch.d.ts +2 -0
- package/dist/codex-watch.js +100 -0
- package/dist/decisions.js +3 -3
- package/dist/delivery-deferral.d.ts +1 -19
- package/dist/delivery-deferral.js +1 -29
- package/dist/delivery-frame.d.ts +7 -0
- package/dist/delivery-frame.js +11 -0
- package/dist/delivery-ledger-sqlite.d.ts +97 -0
- package/dist/delivery-ledger-sqlite.js +496 -0
- package/dist/delivery-ledger.d.ts +196 -0
- package/dist/delivery-ledger.js +268 -0
- package/dist/delivery-lifetime.d.ts +6 -0
- package/dist/delivery-lifetime.js +45 -0
- package/dist/harness-links.js +61 -7
- package/dist/harness.js +12 -17
- package/dist/help.js +3 -6
- package/dist/http-delivery.d.ts +5 -9
- package/dist/http-delivery.js +20 -79
- package/dist/inbox.d.ts +6 -57
- package/dist/inbox.js +24 -380
- package/dist/index.d.ts +7 -4
- package/dist/index.js +5 -2
- package/dist/mcp.d.ts +2 -1
- package/dist/mcp.js +40 -70
- package/dist/message.d.ts +7 -0
- package/dist/message.js +23 -0
- package/dist/model.d.ts +15 -91
- package/dist/model.js +2 -140
- package/dist/neutral.d.ts +72 -0
- package/dist/neutral.js +27 -0
- package/dist/notifications.d.ts +24 -26
- package/dist/notifications.js +39 -143
- package/dist/operation-control.d.ts +4 -0
- package/dist/operation-control.js +20 -0
- package/dist/operation-presentation.d.ts +1 -2
- package/dist/operation-presentation.js +1 -7
- package/dist/owner.d.ts +2 -2
- package/dist/owner.js +1 -1
- package/dist/packages/agent-delivery/src/claude-native.d.ts +2 -0
- package/dist/packages/agent-delivery/src/claude-native.js +5 -0
- package/dist/packages/agent-delivery/src/codex-boundary.d.ts +11 -6
- package/dist/packages/agent-delivery/src/codex-boundary.js +31 -40
- package/dist/packages/agent-delivery/src/codex-hook.d.ts +17 -12
- package/dist/packages/agent-delivery/src/codex-hook.js +26 -39
- package/dist/packages/agent-delivery/src/codex.d.ts +3 -0
- package/dist/packages/agent-delivery/src/codex.js +41 -4
- package/dist/packages/agent-delivery/src/index.d.ts +3 -1
- package/dist/packages/agent-delivery/src/index.js +1 -1
- package/dist/packages/agent-delivery/src/paseo.js +11 -2
- package/dist/packages/agent-delivery/src/types.d.ts +1 -0
- package/dist/paseo-delivery.d.ts +5 -5
- package/dist/paseo-delivery.js +19 -99
- package/dist/paseo.d.ts +1 -1
- package/dist/paseo.js +1 -1
- package/dist/plugins/opencode/index.d.ts +5 -3
- package/dist/plugins/opencode/index.js +99 -21
- package/dist/plugins/opencode-shared/delivery.d.ts +23 -0
- package/dist/plugins/opencode-shared/delivery.js +109 -0
- package/dist/plugins/opencode-v1/index.d.ts +28 -0
- package/dist/plugins/opencode-v1/index.js +41 -0
- package/dist/plugins/opencode-v1/runtime.d.ts +56 -0
- package/dist/plugins/opencode-v1/runtime.js +152 -0
- package/dist/plugins/opencode-v1/transport.d.ts +13 -0
- package/dist/plugins/opencode-v1/transport.js +50 -0
- package/dist/plugins/paseo/shared/card-presentation.d.ts +10 -0
- package/dist/plugins/paseo/shared/card-presentation.js +7 -0
- package/dist/ports.d.ts +33 -214
- package/dist/presentation.d.ts +5 -5
- package/dist/presentation.js +1 -0
- package/dist/runtime.js +2 -2
- package/dist/search.js +1 -1
- package/dist/session-lifecycle.d.ts +8 -7
- package/dist/session-lifecycle.js +40 -42
- package/dist/sqlite-framing.d.ts +8 -0
- package/dist/sqlite-framing.js +31 -0
- package/dist/sqlite-square.d.ts +16 -26
- package/dist/sqlite-square.js +199 -262
- package/dist/sqlite-values.d.ts +21 -0
- package/dist/sqlite-values.js +78 -0
- package/dist/square-api.d.ts +1 -1
- package/dist/square-api.js +5 -8
- package/dist/square-core.d.ts +0 -1
- package/dist/square-domain.d.ts +12 -10
- package/dist/square-domain.js +105 -223
- package/dist/square-facade.d.ts +25 -76
- package/dist/square-location.d.ts +6 -1
- package/dist/square-location.js +1 -1
- package/dist/square-post.d.ts +53 -0
- package/dist/square-post.js +4 -0
- package/dist/square-posting.d.ts +13 -0
- package/dist/square-posting.js +174 -0
- package/dist/square-producer-sqlite.d.ts +11 -0
- package/dist/square-producer-sqlite.js +210 -0
- package/dist/square-receive.d.ts +2 -3
- package/dist/square-sqlite.d.ts +33 -42
- package/dist/square-sqlite.js +236 -768
- package/dist/square-tools.d.ts +8 -0
- package/dist/square-tools.js +39 -0
- package/dist/square-values.d.ts +27 -0
- package/dist/square-values.js +90 -0
- package/dist/views.d.ts +6 -6
- package/dist/views.js +14 -9
- package/dist/wake-sink.d.ts +4 -11
- package/dist/wake-sink.js +8 -32
- package/dist/wake-transports.d.ts +4 -0
- package/dist/wake-transports.js +11 -0
- package/examples/symmetric-domains.mjs +29 -249
- package/guides/change-waits.md +13 -53
- package/guides/claude-native.md +19 -172
- package/guides/codex-delivery.md +55 -78
- package/guides/delivery-primitives.md +48 -207
- package/guides/operation-cancellation.md +2 -5
- package/guides/participant-ownership.md +25 -89
- package/guides/pi-native-delivery.md +19 -56
- package/guides/pi-tools.md +6 -8
- package/guides/row-runtime-delivery-evidence.md +2 -0
- package/guides/row-storage-design.md +19 -44
- package/guides/square-api.md +113 -538
- package/package.json +8 -8
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/hooks/hooks.json +1 -1
- package/plugins/claude/{hooks/register.js → mods/square.js} +4 -7
- package/plugins/claude/types.d.ts +1 -1
- package/plugins/codex/.codex-plugin/plugin.json +1 -1
- package/plugins/codex/hooks/hooks.json +11 -23
- package/plugins/opencode/index.ts +91 -23
- package/plugins/opencode-shared/delivery.ts +91 -0
- package/plugins/opencode-v1/index.ts +36 -0
- package/plugins/opencode-v1/runtime.ts +134 -0
- package/plugins/opencode-v1/transport.ts +41 -0
- package/plugins/paseo/OVERVIEW.md +5 -5
- package/plugins/paseo/README.md +7 -6
- package/plugins/paseo/client/markdown.tsx +5 -5
- package/plugins/paseo/client/square-message.tsx +28 -24
- package/plugins/paseo/client/transform.ts +8 -5
- package/plugins/paseo/shared/card-presentation.ts +16 -0
- package/plugins/paseo/shared/message.ts +6 -11
- package/plugins/pi/square-pi.js +167 -451
- package/dist/channel.d.ts +0 -74
- package/dist/channel.js +0 -92
- package/dist/claude-delivery-status.d.ts +0 -13
- package/dist/claude-delivery-status.js +0 -46
- package/dist/cmd/notify-once.d.ts +0 -2
- package/dist/cmd/notify-once.js +0 -29
- package/dist/delivery-attempts.d.ts +0 -52
- package/dist/delivery-attempts.js +0 -73
- package/dist/delivery-effects.d.ts +0 -139
- package/dist/delivery-effects.js +0 -163
- package/dist/delivery-health.d.ts +0 -51
- package/dist/delivery-health.js +0 -173
- package/dist/delivery-operations.d.ts +0 -9
- package/dist/delivery-operations.js +0 -168
- package/dist/delivery-primitives.d.ts +0 -5
- package/dist/delivery-primitives.js +0 -3
- package/dist/delivery.d.ts +0 -45
- package/dist/delivery.js +0 -106
- package/dist/plugins/opencode/delivery.d.ts +0 -19
- package/dist/plugins/opencode/delivery.js +0 -238
- package/dist/presentation-operations.d.ts +0 -18
- package/dist/presentation-operations.js +0 -86
- package/dist/square-index.d.ts +0 -16
- package/dist/square-index.js +0 -106
- package/dist/square-legacy-framing.d.ts +0 -11
- package/dist/square-legacy-framing.js +0 -64
- package/dist/square-migration-host-ledger.d.ts +0 -26
- package/dist/square-migration-host-ledger.js +0 -169
- package/dist/square-migration.d.ts +0 -30
- package/dist/square-migration.js +0 -599
- package/guides/migration.md +0 -156
- package/plugins/opencode/delivery.ts +0 -211
package/dist/model.d.ts
CHANGED
|
@@ -1,33 +1,16 @@
|
|
|
1
1
|
import type { Act, ActivityId } from './square-core.js';
|
|
2
|
-
|
|
2
|
+
import type { Owner } from './neutral.js';
|
|
3
|
+
import type { WakeAddress } from './square-values.js';
|
|
4
|
+
export { WAKE_ROUTE_KINDS, MESSAGE_METADATA_MAX_BYTES as ACTIVITY_METADATA_MAX_BYTES, MESSAGE_METADATA_MAX_DEPTH as ACTIVITY_METADATA_MAX_DEPTH, validateMessageMetadata as validateActivityMetadata, messageMetadataHasContent as activityMetadataHasContent, isWakeRouteKind, sameName, NAME_GRAPHEME_SOURCE, validateName } from './square-values.js';
|
|
5
|
+
export type { WakeRouteKind, JsonValue, MessageMetadata as ActivityMetadata, WakeAddress, WakeRoute } from './square-values.js';
|
|
6
|
+
export { SquareErrorBase, SquareError, InternalSquareError, isSquareError, validateOwner, nameKey } from './neutral.js';
|
|
7
|
+
export type { Owner, SquareErrorCode, InternalSquareErrorCode, SquareErrorFacts } from './neutral.js';
|
|
3
8
|
export type { Act, ActivityId, Audience, Reach } from './square-core.js';
|
|
4
|
-
export declare const WAKE_ROUTE_KINDS: readonly ["opencode-server", "codex-queue", "claude-native", "paseo", "http"];
|
|
5
|
-
export type WakeRouteKind = typeof WAKE_ROUTE_KINDS[number];
|
|
6
|
-
export type JsonValue = null | boolean | number | string | readonly JsonValue[] | {
|
|
7
|
-
readonly [key: string]: JsonValue;
|
|
8
|
-
};
|
|
9
|
-
export type ActivityMetadata = Readonly<Record<string, JsonValue>>;
|
|
10
|
-
export interface ActivityDelivery {
|
|
11
|
-
readonly mode: 'direct';
|
|
12
|
-
readonly preview?: string;
|
|
13
|
-
}
|
|
14
|
-
export declare function validateActivityDelivery(value: unknown): ActivityDelivery | undefined;
|
|
15
|
-
export declare const ACTIVITY_METADATA_MAX_BYTES: number;
|
|
16
|
-
export declare const ACTIVITY_METADATA_MAX_DEPTH = 256;
|
|
17
|
-
/** Validate the bounded, lossless JSON object carried by a say. */
|
|
18
|
-
export declare function validateActivityMetadata(value: unknown): ActivityMetadata | undefined;
|
|
19
|
-
export declare function activityMetadataHasContent(metadata: ActivityMetadata | undefined): boolean;
|
|
20
|
-
/** Opaque custody identity. Harness coordinates are adapter-owned. */
|
|
21
|
-
export type Owner = string;
|
|
22
|
-
export interface WakeAddress {
|
|
23
|
-
readonly kind: WakeRouteKind;
|
|
24
|
-
readonly address: Readonly<Record<string, string>>;
|
|
25
|
-
}
|
|
26
9
|
/** Artifact-owned custody binding. Generation is the join activity that established it. */
|
|
27
10
|
export interface Seat {
|
|
28
11
|
readonly participant: string;
|
|
29
12
|
readonly owner: Owner;
|
|
30
|
-
readonly generation:
|
|
13
|
+
readonly generation: string;
|
|
31
14
|
readonly attachment: 'attached' | 'detached';
|
|
32
15
|
readonly wakeAddress?: WakeAddress;
|
|
33
16
|
}
|
|
@@ -35,48 +18,6 @@ export interface SeatWatchLease {
|
|
|
35
18
|
readonly generation: ActivityId;
|
|
36
19
|
readonly lease: WatchLease;
|
|
37
20
|
}
|
|
38
|
-
export declare function validateOwner(owner: Owner): Owner;
|
|
39
|
-
export declare function isWakeRouteKind(value: unknown): value is WakeRouteKind;
|
|
40
|
-
export interface WakeRoute {
|
|
41
|
-
/** Ownership generation, when the receiver publishes a fenced route. */
|
|
42
|
-
epoch?: number;
|
|
43
|
-
location: string;
|
|
44
|
-
participant: string;
|
|
45
|
-
kind: WakeRouteKind;
|
|
46
|
-
address: Record<string, string>;
|
|
47
|
-
updatedAt: number;
|
|
48
|
-
}
|
|
49
|
-
export type SquareErrorCode = 'invalid_name' | 'invalid_args' | 'unknown_participant' | 'not_joined' | 'already_joined' | 'already_done' | 'capped' | 'throttled' | 'bell_quota' | 'behind' | 'io' | 'unavailable';
|
|
50
|
-
export type InternalSquareErrorCode = SquareErrorCode | 'not_found' | 'cap_reached' | 'conflict' | 'pending_peer';
|
|
51
|
-
export interface SquareErrorFacts {
|
|
52
|
-
/** Copyable recovery for a missing, detached or foreign seat. */
|
|
53
|
-
join?: string;
|
|
54
|
-
/** Express admission rejected before any activity was committed. */
|
|
55
|
-
activityUnsent?: true;
|
|
56
|
-
/** Refusal reason, including absent participants, conflicting reach, and inaccessible activities. */
|
|
57
|
-
reason?: 'never_joined' | 'not_standing' | 'bell_mention_conflict' | 'not_addressed' | 'migration_required' | 'invalid_reply' | 'invalid_done_body' | 'needs_seat';
|
|
58
|
-
/** The activity id a `catch --id` refusal named. */
|
|
59
|
-
activityId?: string;
|
|
60
|
-
/** The host ledger requiring offline migration, rather than the selected artifact. */
|
|
61
|
-
ledgerRoot?: string;
|
|
62
|
-
/** Requested recipient spellings, without parsing presentation copy. */
|
|
63
|
-
targets?: readonly string[];
|
|
64
|
-
/** Whether the artifact holds that activity at all; an unknown id needs an ordinary page. */
|
|
65
|
-
activityExists?: boolean;
|
|
66
|
-
pending?: number;
|
|
67
|
-
retryAfterMs?: number;
|
|
68
|
-
}
|
|
69
|
-
declare class SquareErrorBase<Code extends string> extends Error {
|
|
70
|
-
code: Code;
|
|
71
|
-
facts?: SquareErrorFacts | undefined;
|
|
72
|
-
operation?: import('./square-facade.js').OperationFailureDetail;
|
|
73
|
-
constructor(code: Code, message: string, facts?: SquareErrorFacts | undefined);
|
|
74
|
-
}
|
|
75
|
-
export declare class SquareError extends SquareErrorBase<SquareErrorCode> {
|
|
76
|
-
}
|
|
77
|
-
export declare class InternalSquareError extends SquareErrorBase<InternalSquareErrorCode> {
|
|
78
|
-
}
|
|
79
|
-
export declare function isSquareError(error: unknown): error is SquareError | InternalSquareError;
|
|
80
21
|
export type HardCap = number | null;
|
|
81
22
|
export interface BuildOptions {
|
|
82
23
|
force: boolean;
|
|
@@ -84,10 +25,16 @@ export interface BuildOptions {
|
|
|
84
25
|
template?: string;
|
|
85
26
|
throttlePerMinute?: number;
|
|
86
27
|
}
|
|
28
|
+
/** An upper publication draft: content and social facts before any index exists. */
|
|
29
|
+
export type ActDraft = Act & {
|
|
30
|
+
at: number;
|
|
31
|
+
};
|
|
32
|
+
/** A landed activity owns its content and social facts. */
|
|
87
33
|
export type StoredAct = Act & {
|
|
88
34
|
index: number;
|
|
89
35
|
at: number;
|
|
90
36
|
};
|
|
37
|
+
export type HydratedAct = StoredAct;
|
|
91
38
|
export type ObservationState = 'seen';
|
|
92
39
|
export interface ActivityObservation {
|
|
93
40
|
state: ObservationState;
|
|
@@ -104,39 +51,16 @@ export interface WatchLease {
|
|
|
104
51
|
filter?: WatchLeaseFilter;
|
|
105
52
|
}
|
|
106
53
|
export type DirectedNotificationRoute = import('./attention.js').AudienceRoute;
|
|
107
|
-
export interface InboxNotification {
|
|
108
|
-
actIndex: number;
|
|
109
|
-
actor: string;
|
|
110
|
-
at: number;
|
|
111
|
-
route: DirectedNotificationRoute;
|
|
112
|
-
body: string;
|
|
113
|
-
readonly delivery?: ActivityDelivery;
|
|
114
|
-
}
|
|
115
|
-
export interface LocatedSeat {
|
|
116
|
-
readonly location: string;
|
|
117
|
-
readonly seat: Seat;
|
|
118
|
-
readonly joinedAt: number;
|
|
119
|
-
}
|
|
120
|
-
export interface PendingMembership extends LocatedSeat {
|
|
121
|
-
readonly notifications: InboxNotification[];
|
|
122
|
-
readonly catchLease?: WatchLease;
|
|
123
|
-
readonly deliveryDeferralExpiry?: number;
|
|
124
|
-
}
|
|
125
54
|
export interface WatchOptions {
|
|
126
55
|
participants?: string[];
|
|
127
56
|
mention?: string;
|
|
128
57
|
replace?: boolean;
|
|
129
58
|
}
|
|
130
|
-
export type PublicAct = Extract<
|
|
59
|
+
export type PublicAct = Extract<HydratedAct, {
|
|
131
60
|
kind: 'say' | 'done';
|
|
132
61
|
}>;
|
|
133
|
-
export type RoomChangeAct = Extract<
|
|
62
|
+
export type RoomChangeAct = Extract<HydratedAct, {
|
|
134
63
|
kind: 'join' | 'done' | 'listen' | 'ignore' | 'unlisten';
|
|
135
64
|
}>;
|
|
136
65
|
export declare function formatHardCap(hardCap: HardCap): string;
|
|
137
66
|
export declare function parseParticipantList(value: string): string[];
|
|
138
|
-
export declare function nameKey(name: string): string;
|
|
139
|
-
export declare function sameName(a: string, b: string): boolean;
|
|
140
|
-
/** One name grapheme: Unicode letters, digits, marks, hyphens, or underscores (no isolated variation selectors), or a complete RGI emoji. Shared by name validation and body @mention scanning. */
|
|
141
|
-
export declare const NAME_GRAPHEME_SOURCE: string;
|
|
142
|
-
export declare function validateName(name: string): void;
|
package/dist/model.js
CHANGED
|
@@ -1,127 +1,6 @@
|
|
|
1
1
|
// Shared model and constants for Square.
|
|
2
|
-
export {
|
|
3
|
-
export
|
|
4
|
-
export function validateActivityDelivery(value) {
|
|
5
|
-
if (value === undefined)
|
|
6
|
-
return undefined;
|
|
7
|
-
if (value !== null && typeof value === 'object'
|
|
8
|
-
&& [Object.prototype, null].includes(Object.getPrototypeOf(value))
|
|
9
|
-
&& Object.getOwnPropertySymbols(value).length === 0) {
|
|
10
|
-
const keys = Object.getOwnPropertyNames(value);
|
|
11
|
-
const mode = Object.getOwnPropertyDescriptor(value, 'mode');
|
|
12
|
-
const preview = Object.getOwnPropertyDescriptor(value, 'preview');
|
|
13
|
-
if (mode?.enumerable && 'value' in mode && mode.value === 'direct') {
|
|
14
|
-
if (keys.length === 1)
|
|
15
|
-
return { mode: 'direct' };
|
|
16
|
-
if (keys.length === 2 && preview?.enumerable && 'value' in preview
|
|
17
|
-
&& typeof preview.value === 'string' && preview.value.trim() !== '')
|
|
18
|
-
return { mode: 'direct', preview: preview.value };
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
throw new SquareError('invalid_args', "Activity delivery must be { mode: 'direct', preview?: string }.");
|
|
22
|
-
}
|
|
23
|
-
export const ACTIVITY_METADATA_MAX_BYTES = 16 * 1024;
|
|
24
|
-
export const ACTIVITY_METADATA_MAX_DEPTH = 256;
|
|
25
|
-
/** Validate the bounded, lossless JSON object carried by a say. */
|
|
26
|
-
export function validateActivityMetadata(value) {
|
|
27
|
-
if (value === undefined)
|
|
28
|
-
return undefined;
|
|
29
|
-
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
30
|
-
throw new SquareError('invalid_args', 'Activity metadata must be a non-null JSON object.');
|
|
31
|
-
const visiting = new Set();
|
|
32
|
-
const stack = [{ value, depth: 0 }];
|
|
33
|
-
while (stack.length > 0) {
|
|
34
|
-
const frame = stack.pop();
|
|
35
|
-
if (frame.exit !== undefined) {
|
|
36
|
-
visiting.delete(frame.exit);
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
const item = frame.value;
|
|
40
|
-
if (item === null || typeof item === 'boolean' || typeof item === 'string')
|
|
41
|
-
continue;
|
|
42
|
-
if (typeof item === 'number') {
|
|
43
|
-
if (!Number.isFinite(item))
|
|
44
|
-
throw new SquareError('invalid_args', 'Activity metadata must contain only finite JSON values.');
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
if (typeof item !== 'object')
|
|
48
|
-
throw new SquareError('invalid_args', 'Activity metadata must contain only JSON values.');
|
|
49
|
-
if (frame.depth > ACTIVITY_METADATA_MAX_DEPTH)
|
|
50
|
-
throw new SquareError('invalid_args', `Activity metadata nesting cannot exceed ${ACTIVITY_METADATA_MAX_DEPTH} levels.`);
|
|
51
|
-
if (visiting.has(item))
|
|
52
|
-
throw new SquareError('invalid_args', 'Activity metadata cannot contain a cycle.');
|
|
53
|
-
visiting.add(item);
|
|
54
|
-
stack.push({ value: item, depth: frame.depth, exit: item });
|
|
55
|
-
if (Array.isArray(item)) {
|
|
56
|
-
if (Object.getOwnPropertySymbols(item).length > 0 || Object.keys(item).length !== item.length)
|
|
57
|
-
throw new SquareError('invalid_args', 'Activity metadata arrays must be dense JSON arrays.');
|
|
58
|
-
const names = Object.getOwnPropertyNames(item);
|
|
59
|
-
if (names.some(name => name !== 'length' && (!/^(0|[1-9]\d*)$/.test(name) || Number(name) >= item.length)))
|
|
60
|
-
throw new SquareError('invalid_args', 'Activity metadata arrays must contain only indexed values.');
|
|
61
|
-
for (const key of Object.keys(item).reverse()) {
|
|
62
|
-
const descriptor = Object.getOwnPropertyDescriptor(item, key);
|
|
63
|
-
if (descriptor === undefined || !('value' in descriptor))
|
|
64
|
-
throw new SquareError('invalid_args', 'Activity metadata cannot contain accessors.');
|
|
65
|
-
stack.push({ value: descriptor.value, depth: frame.depth + 1 });
|
|
66
|
-
}
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
const prototype = Object.getPrototypeOf(item);
|
|
70
|
-
if (prototype !== Object.prototype && prototype !== null)
|
|
71
|
-
throw new SquareError('invalid_args', 'Activity metadata must contain only plain JSON objects.');
|
|
72
|
-
if (Object.getOwnPropertySymbols(item).length > 0)
|
|
73
|
-
throw new SquareError('invalid_args', 'Activity metadata cannot contain symbol keys.');
|
|
74
|
-
const names = Object.getOwnPropertyNames(item);
|
|
75
|
-
if (names.some(name => !Object.prototype.propertyIsEnumerable.call(item, name)))
|
|
76
|
-
throw new SquareError('invalid_args', 'Activity metadata cannot contain non-enumerable properties.');
|
|
77
|
-
for (const name of names.reverse()) {
|
|
78
|
-
const descriptor = Object.getOwnPropertyDescriptor(item, name);
|
|
79
|
-
if (!('value' in descriptor))
|
|
80
|
-
throw new SquareError('invalid_args', 'Activity metadata cannot contain accessors.');
|
|
81
|
-
stack.push({ value: descriptor.value, depth: frame.depth + 1 });
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
let serialized;
|
|
85
|
-
try {
|
|
86
|
-
serialized = JSON.stringify(value);
|
|
87
|
-
}
|
|
88
|
-
catch {
|
|
89
|
-
throw new SquareError('invalid_args', 'Activity metadata must contain only lossless JSON values.');
|
|
90
|
-
}
|
|
91
|
-
if (serialized === undefined || Buffer.byteLength(serialized, 'utf8') > ACTIVITY_METADATA_MAX_BYTES)
|
|
92
|
-
throw new SquareError('invalid_args', `Activity metadata cannot exceed ${ACTIVITY_METADATA_MAX_BYTES} UTF-8 bytes.`);
|
|
93
|
-
return value;
|
|
94
|
-
}
|
|
95
|
-
export function activityMetadataHasContent(metadata) {
|
|
96
|
-
return metadata !== undefined && Object.keys(metadata).length > 0;
|
|
97
|
-
}
|
|
98
|
-
export function validateOwner(owner) {
|
|
99
|
-
if (typeof owner !== 'string' || !owner || Buffer.byteLength(owner, 'utf8') > 512 || /[\u0000-\u001f\u007f-\u009f]/u.test(owner)) {
|
|
100
|
-
throw new SquareError('invalid_args', 'A participant write requires a non-empty owner without control characters (at most 512 UTF-8 bytes).');
|
|
101
|
-
}
|
|
102
|
-
return owner;
|
|
103
|
-
}
|
|
104
|
-
export function isWakeRouteKind(value) {
|
|
105
|
-
return typeof value === 'string' && WAKE_ROUTE_KINDS.includes(value);
|
|
106
|
-
}
|
|
107
|
-
class SquareErrorBase extends Error {
|
|
108
|
-
code;
|
|
109
|
-
facts;
|
|
110
|
-
operation;
|
|
111
|
-
constructor(code, message, facts) {
|
|
112
|
-
super(message);
|
|
113
|
-
this.code = code;
|
|
114
|
-
this.facts = facts;
|
|
115
|
-
this.name = 'SquareError';
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
export class SquareError extends SquareErrorBase {
|
|
119
|
-
}
|
|
120
|
-
export class InternalSquareError extends SquareErrorBase {
|
|
121
|
-
}
|
|
122
|
-
export function isSquareError(error) {
|
|
123
|
-
return error instanceof SquareError || error instanceof InternalSquareError;
|
|
124
|
-
}
|
|
2
|
+
export { WAKE_ROUTE_KINDS, MESSAGE_METADATA_MAX_BYTES as ACTIVITY_METADATA_MAX_BYTES, MESSAGE_METADATA_MAX_DEPTH as ACTIVITY_METADATA_MAX_DEPTH, validateMessageMetadata as validateActivityMetadata, messageMetadataHasContent as activityMetadataHasContent, isWakeRouteKind, sameName, NAME_GRAPHEME_SOURCE, validateName } from './square-values.js';
|
|
3
|
+
export { SquareErrorBase, SquareError, InternalSquareError, isSquareError, validateOwner, nameKey } from './neutral.js';
|
|
125
4
|
export function formatHardCap(hardCap) {
|
|
126
5
|
return hardCap === null ? '-1' : String(hardCap);
|
|
127
6
|
}
|
|
@@ -131,20 +10,3 @@ export function parseParticipantList(value) {
|
|
|
131
10
|
.map((name) => name.trim())
|
|
132
11
|
.filter(Boolean);
|
|
133
12
|
}
|
|
134
|
-
export function nameKey(name) {
|
|
135
|
-
return name.toLocaleLowerCase();
|
|
136
|
-
}
|
|
137
|
-
export function sameName(a, b) {
|
|
138
|
-
return nameKey(a) === nameKey(b);
|
|
139
|
-
}
|
|
140
|
-
const TEXT_NAME_GRAPHEME_SOURCE = String.raw `[[\p{L}\p{N}\p{M}_\x2D]--[\p{Variation_Selector}]]`;
|
|
141
|
-
/** One name grapheme: Unicode letters, digits, marks, hyphens, or underscores (no isolated variation selectors), or a complete RGI emoji. Shared by name validation and body @mention scanning. */
|
|
142
|
-
export const NAME_GRAPHEME_SOURCE = String.raw `${TEXT_NAME_GRAPHEME_SOURCE}|\p{RGI_Emoji}`;
|
|
143
|
-
// Ordinary Unicode names need not trigger the full RGI emoji matcher’s cold compilation.
|
|
144
|
-
const TEXT_NAME_PATTERN = new RegExp(`^(?:${TEXT_NAME_GRAPHEME_SOURCE})+(?:/(?:${TEXT_NAME_GRAPHEME_SOURCE})+)*$`, 'v');
|
|
145
|
-
const NAME_PATTERN = new RegExp(`^(?:${NAME_GRAPHEME_SOURCE})+(?:/(?:${NAME_GRAPHEME_SOURCE})+)*$`, 'v');
|
|
146
|
-
export function validateName(name) {
|
|
147
|
-
if (!name || (!TEXT_NAME_PATTERN.test(name) && !NAME_PATTERN.test(name))) {
|
|
148
|
-
throw new SquareError('invalid_name', 'Invalid name: names must contain non-empty slash-separated segments using Unicode letters, digits, marks, hyphens, underscores, or complete RGI emoji graphemes.');
|
|
149
|
-
}
|
|
150
|
-
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/** Shared identity, error and paging types used below both Channel and Agora. */
|
|
2
|
+
export type Owner = string;
|
|
3
|
+
export type SquareErrorCode = 'invalid_name' | 'invalid_args' | 'unknown_participant' | 'not_joined' | 'already_joined' | 'already_done' | 'capped' | 'throttled' | 'bell_quota' | 'behind' | 'io' | 'unavailable';
|
|
4
|
+
export type InternalSquareErrorCode = SquareErrorCode | 'not_found' | 'cap_reached' | 'conflict' | 'pending_peer';
|
|
5
|
+
export interface SquareErrorFacts {
|
|
6
|
+
/** Copyable recovery for a missing, detached or foreign seat. */
|
|
7
|
+
join?: string;
|
|
8
|
+
/** Express admission rejected before any activity was committed. */
|
|
9
|
+
activityUnsent?: true;
|
|
10
|
+
/** Refusal reason, including absent participants, conflicting reach, and inaccessible activities. */
|
|
11
|
+
reason?: 'never_joined' | 'not_standing' | 'bell_mention_conflict' | 'not_addressed' | 'invalid_reply' | 'invalid_done_body' | 'needs_seat';
|
|
12
|
+
/** The activity id a `catch --id` refusal named. */
|
|
13
|
+
activityId?: string;
|
|
14
|
+
/** Requested recipient spellings, without parsing presentation copy. */
|
|
15
|
+
targets?: readonly string[];
|
|
16
|
+
/** Whether the artifact holds that activity at all; an unknown id needs an ordinary page. */
|
|
17
|
+
activityExists?: boolean;
|
|
18
|
+
pending?: number;
|
|
19
|
+
retryAfterMs?: number;
|
|
20
|
+
}
|
|
21
|
+
export interface CatchWaitStart {
|
|
22
|
+
readonly idleMs: number;
|
|
23
|
+
readonly replacementRequested: boolean;
|
|
24
|
+
readonly replaced: boolean;
|
|
25
|
+
}
|
|
26
|
+
export type OperationProgress = {
|
|
27
|
+
readonly kind: 'waiting';
|
|
28
|
+
readonly reason: 'throttled';
|
|
29
|
+
readonly delayMs?: number;
|
|
30
|
+
} | ({
|
|
31
|
+
readonly kind: 'catch-started';
|
|
32
|
+
readonly participant: string;
|
|
33
|
+
} & CatchWaitStart);
|
|
34
|
+
export interface OperationControl {
|
|
35
|
+
readonly signal?: AbortSignal;
|
|
36
|
+
readonly onProgress?: (progress: OperationProgress) => void;
|
|
37
|
+
}
|
|
38
|
+
export interface OperationFailureDetail {
|
|
39
|
+
readonly operation: 'express' | 'join' | 'catch' | 'history' | 'other';
|
|
40
|
+
readonly subject?: 'caller' | 'filter' | 'recipient';
|
|
41
|
+
readonly participant?: string;
|
|
42
|
+
readonly expressEffect?: 'unsent' | 'landed' | 'unknown';
|
|
43
|
+
readonly landedId?: string;
|
|
44
|
+
readonly historyBounds?: {
|
|
45
|
+
readonly maxLimit: number;
|
|
46
|
+
readonly totalMatches: number;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export interface OperationError extends Error {
|
|
50
|
+
readonly operation?: OperationFailureDetail;
|
|
51
|
+
}
|
|
52
|
+
export declare class SquareErrorBase<Code extends string> extends Error {
|
|
53
|
+
code: Code;
|
|
54
|
+
facts?: SquareErrorFacts | undefined;
|
|
55
|
+
operation?: OperationFailureDetail;
|
|
56
|
+
constructor(code: Code, message: string, facts?: SquareErrorFacts | undefined);
|
|
57
|
+
}
|
|
58
|
+
export declare class SquareError extends SquareErrorBase<SquareErrorCode> {
|
|
59
|
+
}
|
|
60
|
+
export declare class InternalSquareError extends SquareErrorBase<InternalSquareErrorCode> {
|
|
61
|
+
}
|
|
62
|
+
export declare function isSquareError(error: unknown): error is SquareError | InternalSquareError;
|
|
63
|
+
export declare function validateOwner(owner: Owner): Owner;
|
|
64
|
+
export declare function nameKey(name: string): string;
|
|
65
|
+
export interface IndexPage {
|
|
66
|
+
readonly edge: 'oldest' | 'newest';
|
|
67
|
+
readonly limit: number;
|
|
68
|
+
}
|
|
69
|
+
export interface FactPage<T> {
|
|
70
|
+
readonly items: readonly T[];
|
|
71
|
+
readonly hasMore: boolean;
|
|
72
|
+
}
|
package/dist/neutral.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export class SquareErrorBase extends Error {
|
|
2
|
+
code;
|
|
3
|
+
facts;
|
|
4
|
+
operation;
|
|
5
|
+
constructor(code, message, facts) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.code = code;
|
|
8
|
+
this.facts = facts;
|
|
9
|
+
this.name = 'SquareError';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export class SquareError extends SquareErrorBase {
|
|
13
|
+
}
|
|
14
|
+
export class InternalSquareError extends SquareErrorBase {
|
|
15
|
+
}
|
|
16
|
+
export function isSquareError(error) {
|
|
17
|
+
return error instanceof SquareError || error instanceof InternalSquareError;
|
|
18
|
+
}
|
|
19
|
+
export function validateOwner(owner) {
|
|
20
|
+
if (typeof owner !== 'string' || !owner || Buffer.byteLength(owner, 'utf8') > 512 || /[\u0000-\u001f\u007f-\u009f]/u.test(owner)) {
|
|
21
|
+
throw new SquareError('invalid_args', 'A participant write requires a non-empty owner without control characters (at most 512 UTF-8 bytes).');
|
|
22
|
+
}
|
|
23
|
+
return owner;
|
|
24
|
+
}
|
|
25
|
+
export function nameKey(name) {
|
|
26
|
+
return name.toLocaleLowerCase();
|
|
27
|
+
}
|
package/dist/notifications.d.ts
CHANGED
|
@@ -1,26 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
export declare function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
export declare function sweepPendingNotifications(squarePath: string, opts?: SweepPendingNotificationsOptions): Promise<number[]>;
|
|
26
|
-
export {};
|
|
1
|
+
import type { DeliveryLedger, DeliveryTransport, HandoffResult, PostResult } from './delivery-ledger.js';
|
|
2
|
+
import type { Owner } from './owner.js';
|
|
3
|
+
export { createDefaultDeliveryTransports } from './wake-transports.js';
|
|
4
|
+
/** Best-effort dispatch for currently eligible cards, including cards restored by release. */
|
|
5
|
+
export declare function dispatchEligibleCards(ledger: DeliveryLedger, owner: Owner, options?: {
|
|
6
|
+
readonly env?: NodeJS.ProcessEnv;
|
|
7
|
+
readonly signal?: AbortSignal;
|
|
8
|
+
readonly track?: (result: HandoffResult) => void;
|
|
9
|
+
readonly transports?: readonly DeliveryTransport[];
|
|
10
|
+
}): Promise<void>;
|
|
11
|
+
/** Post, then best-effort dispatch without consulting producer storage. */
|
|
12
|
+
export declare function postAndDispatch(ledger: DeliveryLedger, input: {
|
|
13
|
+
readonly owner: Owner;
|
|
14
|
+
readonly key: string;
|
|
15
|
+
readonly text: string;
|
|
16
|
+
readonly details?: Readonly<Record<string, unknown>>;
|
|
17
|
+
}, options?: {
|
|
18
|
+
readonly env?: NodeJS.ProcessEnv;
|
|
19
|
+
readonly signal?: AbortSignal;
|
|
20
|
+
readonly track?: (result: HandoffResult) => void;
|
|
21
|
+
readonly transports?: readonly DeliveryTransport[];
|
|
22
|
+
}): Promise<PostResult>;
|
|
23
|
+
/** Best-effort dispatch after a card has been posted; never inspect producer storage. */
|
|
24
|
+
export declare function dispatchPostedCard(ledger: DeliveryLedger, owner: Owner, key: string, track: (result: HandoffResult) => void, env?: NodeJS.ProcessEnv, signal?: AbortSignal, suppliedTransports?: readonly DeliveryTransport[]): Promise<void>;
|
package/dist/notifications.js
CHANGED
|
@@ -1,152 +1,48 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (!Number.isFinite(value) || value <= 0) {
|
|
12
|
-
throw new SquareError('invalid_args', 'Invalid SQUARE_NOTIFY_DELIVERY_WAIT_MS: expected a positive integer.');
|
|
13
|
-
}
|
|
14
|
-
return value;
|
|
15
|
-
}
|
|
16
|
-
/** Concrete transports use wall time; semantic state time belongs to Square operations. */
|
|
17
|
-
export async function createDefaultWakeTransport(env = process.env, suppliedTransports) {
|
|
18
|
-
if (suppliedTransports !== undefined)
|
|
19
|
-
return createWakeTransport(suppliedTransports);
|
|
20
|
-
const transports = {};
|
|
21
|
-
try {
|
|
22
|
-
const { CodexQueueTransport } = await import('./codex-queue.js');
|
|
23
|
-
transports['codex-queue'] = new CodexQueueTransport({ env });
|
|
24
|
-
}
|
|
25
|
-
catch { /* core-only builds may omit Codex */ }
|
|
26
|
-
if (env.SQUARE_DISABLE_PASEO_WAKE !== '1') {
|
|
27
|
-
try {
|
|
28
|
-
const { PaseoWakeTransport } = await import('./paseo-delivery.js');
|
|
29
|
-
transports.paseo = new PaseoWakeTransport();
|
|
30
|
-
}
|
|
31
|
-
catch { /* Paseo is optional */ }
|
|
32
|
-
}
|
|
33
|
-
const { createClaudeWakeTransport } = await import('./claude-delivery.js');
|
|
34
|
-
transports['claude-native'] = createClaudeWakeTransport(env);
|
|
35
|
-
const { HttpWakeTransport } = await import('./http-delivery.js');
|
|
36
|
-
transports.http = new HttpWakeTransport({ env });
|
|
37
|
-
return createWakeTransport(transports);
|
|
38
|
-
}
|
|
39
|
-
/** Route selection only: all implementations receive the same request and final gate. */
|
|
40
|
-
export function createWakeTransport(transports) {
|
|
41
|
-
const missing = (kind) => ({ outcome: 'not-capable', diagnostic: `no transport for ${kind}` });
|
|
42
|
-
return {
|
|
43
|
-
async probe(route) {
|
|
44
|
-
const transport = transports[route.kind];
|
|
45
|
-
if (transport === undefined)
|
|
46
|
-
return missing(route.kind);
|
|
47
|
-
try {
|
|
48
|
-
return await transport.probe?.(route) ?? true;
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
return { outcome: 'not-capable', diagnostic: error instanceof Error ? error.message : String(error) };
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
attempt: (request, timeoutMs, beforeSend) => transports[request.route.kind]?.attempt(request, timeoutMs, beforeSend)
|
|
55
|
-
?? Promise.resolve(missing(request.route.kind)),
|
|
56
|
-
};
|
|
1
|
+
import { createDefaultDeliveryTransports } from './wake-transports.js';
|
|
2
|
+
export { createDefaultDeliveryTransports } from './wake-transports.js';
|
|
3
|
+
/** Best-effort dispatch for currently eligible cards, including cards restored by release. */
|
|
4
|
+
export async function dispatchEligibleCards(ledger, owner, options = {}) {
|
|
5
|
+
const session = await ledger.session(owner);
|
|
6
|
+
if (!session || session.state !== 'attached' || options.signal?.aborted)
|
|
7
|
+
return;
|
|
8
|
+
const pending = await ledger.pending(owner, { generation: session.generation });
|
|
9
|
+
for (const card of pending)
|
|
10
|
+
await dispatchPostedCard(ledger, owner, card.key, options.track ?? (() => undefined), options.env, options.signal, options.transports);
|
|
57
11
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
const artifact = createArtifactPort(squarePath);
|
|
63
|
-
try {
|
|
64
|
-
await artifact.read(facts => facts.header());
|
|
65
|
-
const transport = await createDefaultWakeTransport(env, opts.transports);
|
|
12
|
+
/** Post, then best-effort dispatch without consulting producer storage. */
|
|
13
|
+
export async function postAndDispatch(ledger, input, options = {}) {
|
|
14
|
+
const result = await ledger.post(input);
|
|
15
|
+
if (result.status === 'posted' || result.status === 'duplicate') {
|
|
66
16
|
try {
|
|
67
|
-
await
|
|
17
|
+
await dispatchEligibleCards(ledger, input.owner, options);
|
|
68
18
|
}
|
|
69
|
-
catch { /*
|
|
70
|
-
}
|
|
71
|
-
catch (error) {
|
|
72
|
-
if (error instanceof InternalSquareError && error.code === 'not_found')
|
|
73
|
-
throw new SquareError('unavailable', `Square is unavailable at ${squarePath}`);
|
|
74
|
-
throw error;
|
|
75
|
-
}
|
|
76
|
-
finally {
|
|
77
|
-
await artifact.close();
|
|
19
|
+
catch { /* Posting is already committed. */ }
|
|
78
20
|
}
|
|
21
|
+
return result;
|
|
79
22
|
}
|
|
80
|
-
/**
|
|
81
|
-
export async function
|
|
82
|
-
|
|
83
|
-
if (remainingMs() === 0 || signal?.aborted)
|
|
23
|
+
/** Best-effort dispatch after a card has been posted; never inspect producer storage. */
|
|
24
|
+
export async function dispatchPostedCard(ledger, owner, key, track, env = process.env, signal, suppliedTransports) {
|
|
25
|
+
if (signal?.aborted)
|
|
84
26
|
return;
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
try {
|
|
88
|
-
for (const entry of await fs.promises.readdir(path.join(cwd, '.square'))) {
|
|
89
|
-
if (entry.endsWith('.square'))
|
|
90
|
-
paths.add(path.join(cwd, '.square', entry));
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
catch { /* no local square directory */ }
|
|
94
|
-
if (remainingMs() === 0 || signal?.aborted)
|
|
27
|
+
const session = await ledger.session(owner);
|
|
28
|
+
if (!session || session.state !== 'attached')
|
|
95
29
|
return;
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
break;
|
|
114
|
-
const configured = Number(env.SQUARE_NOTIFY_DELIVERY_WAIT_MS ?? 5000);
|
|
115
|
-
const timeoutMs = Math.max(1, Math.min(Number.isFinite(configured) && configured > 0 ? configured : 5000, remaining));
|
|
116
|
-
await deliverPending({ artifact, transport, location: squarePath, activity: actIndex, timeoutMs, now: Date.now() }).catch(() => undefined);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
finally {
|
|
120
|
-
await artifact.close();
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
catch { /* stale index entries are ignored by the hook */ }
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
/** Select old pending attention at a bounded action boundary for an explicit executor. */
|
|
127
|
-
export async function sweepPendingNotifications(squarePath, opts = {}) {
|
|
128
|
-
const env = opts.env ?? process.env;
|
|
129
|
-
if (env.SQUARE_DISABLE_PASEO_WAKE === '1')
|
|
130
|
-
return [];
|
|
131
|
-
const now = opts.now ?? Date.now();
|
|
132
|
-
const limit = opts.limit ?? 8;
|
|
133
|
-
const artifact = createArtifactPort(squarePath);
|
|
134
|
-
let selected;
|
|
135
|
-
try {
|
|
136
|
-
await artifact.read(facts => facts.header());
|
|
137
|
-
selected = await sweepPending({ artifact, location: squarePath, now, graceMs: wakeGraceMs(env), limit });
|
|
138
|
-
}
|
|
139
|
-
catch (error) {
|
|
140
|
-
if (error instanceof InternalSquareError && error.code === 'not_found')
|
|
141
|
-
throw new SquareError('unavailable', `Square is unavailable at ${squarePath}`);
|
|
142
|
-
throw error;
|
|
143
|
-
}
|
|
144
|
-
finally {
|
|
145
|
-
await artifact.close();
|
|
146
|
-
}
|
|
147
|
-
if (opts.dispatchCandidate !== undefined) {
|
|
148
|
-
for (const actIndex of selected)
|
|
149
|
-
await opts.dispatchCandidate(actIndex);
|
|
30
|
+
const transports = suppliedTransports ?? await createDefaultDeliveryTransports(env);
|
|
31
|
+
const configured = Number(env.SQUARE_NOTIFY_DELIVERY_WAIT_MS ?? 5000);
|
|
32
|
+
const timeoutMs = Number.isSafeInteger(configured) && configured > 0 ? configured : 5000;
|
|
33
|
+
for (const route of session.routes) {
|
|
34
|
+
// Codex custody belongs to its native receiver, including for callers that
|
|
35
|
+
// supply transports explicitly to the public producer API.
|
|
36
|
+
if (route.kind === 'codex-queue')
|
|
37
|
+
continue;
|
|
38
|
+
if (signal?.aborted)
|
|
39
|
+
return;
|
|
40
|
+
const transport = transports.find(candidate => candidate.kind === route.kind);
|
|
41
|
+
if (!transport)
|
|
42
|
+
continue;
|
|
43
|
+
const result = await ledger.dispatchHandoff(owner, key, transport, { generation: session.generation, timeoutMs, signal });
|
|
44
|
+
track(result);
|
|
45
|
+
if (result.outcome === 'accepted' || result.outcome === 'presented' || result.outcome === 'unknown')
|
|
46
|
+
return;
|
|
150
47
|
}
|
|
151
|
-
return selected;
|
|
152
48
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { OperationControl, OperationFailureDetail } from './neutral.js';
|
|
2
|
+
export declare function checkControl(control?: OperationControl): void;
|
|
3
|
+
export declare function squareClock(env: NodeJS.ProcessEnv, clock?: () => number): () => number;
|
|
4
|
+
export declare function failure(error: unknown, detail: OperationFailureDetail): Error;
|