wake-bridge 0.9.0-preview.8

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.
Files changed (115) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +222 -0
  3. package/dist/src/adapters/botlingknows.d.ts +42 -0
  4. package/dist/src/adapters/botlingknows.js +141 -0
  5. package/dist/src/adapters/botlingknows.js.map +1 -0
  6. package/dist/src/adapters/group-chat.d.ts +43 -0
  7. package/dist/src/adapters/group-chat.js +120 -0
  8. package/dist/src/adapters/group-chat.js.map +1 -0
  9. package/dist/src/cli.d.ts +2 -0
  10. package/dist/src/cli.js +637 -0
  11. package/dist/src/cli.js.map +1 -0
  12. package/dist/src/connector-catalog.d.ts +17 -0
  13. package/dist/src/connector-catalog.js +43 -0
  14. package/dist/src/connector-catalog.js.map +1 -0
  15. package/dist/src/connectors/botlingknows-mcp.d.ts +15 -0
  16. package/dist/src/connectors/botlingknows-mcp.js +130 -0
  17. package/dist/src/connectors/botlingknows-mcp.js.map +1 -0
  18. package/dist/src/connectors/group-chat-http.d.ts +17 -0
  19. package/dist/src/connectors/group-chat-http.js +226 -0
  20. package/dist/src/connectors/group-chat-http.js.map +1 -0
  21. package/dist/src/connectors/mcp-http-client.d.ts +11 -0
  22. package/dist/src/connectors/mcp-http-client.js +108 -0
  23. package/dist/src/connectors/mcp-http-client.js.map +1 -0
  24. package/dist/src/core.d.ts +170 -0
  25. package/dist/src/core.js +1720 -0
  26. package/dist/src/core.js.map +1 -0
  27. package/dist/src/daemon.d.ts +31 -0
  28. package/dist/src/daemon.js +605 -0
  29. package/dist/src/daemon.js.map +1 -0
  30. package/dist/src/db.d.ts +31 -0
  31. package/dist/src/db.js +513 -0
  32. package/dist/src/db.js.map +1 -0
  33. package/dist/src/event-sdk.d.ts +43 -0
  34. package/dist/src/event-sdk.js +152 -0
  35. package/dist/src/event-sdk.js.map +1 -0
  36. package/dist/src/host-adapter-registry.d.ts +21 -0
  37. package/dist/src/host-adapter-registry.js +59 -0
  38. package/dist/src/host-adapter-registry.js.map +1 -0
  39. package/dist/src/index.d.ts +5 -0
  40. package/dist/src/index.js +6 -0
  41. package/dist/src/index.js.map +1 -0
  42. package/dist/src/instance-config.d.ts +46 -0
  43. package/dist/src/instance-config.js +176 -0
  44. package/dist/src/instance-config.js.map +1 -0
  45. package/dist/src/mcp.d.ts +51 -0
  46. package/dist/src/mcp.js +728 -0
  47. package/dist/src/mcp.js.map +1 -0
  48. package/dist/src/operator-control.d.ts +82 -0
  49. package/dist/src/operator-control.js +220 -0
  50. package/dist/src/operator-control.js.map +1 -0
  51. package/dist/src/out-of-process-host.d.ts +37 -0
  52. package/dist/src/out-of-process-host.js +196 -0
  53. package/dist/src/out-of-process-host.js.map +1 -0
  54. package/dist/src/policy-control.d.ts +3 -0
  55. package/dist/src/policy-control.js +120 -0
  56. package/dist/src/policy-control.js.map +1 -0
  57. package/dist/src/release-lifecycle.d.ts +98 -0
  58. package/dist/src/release-lifecycle.js +378 -0
  59. package/dist/src/release-lifecycle.js.map +1 -0
  60. package/dist/src/sdk-error.d.ts +6 -0
  61. package/dist/src/sdk-error.js +12 -0
  62. package/dist/src/sdk-error.js.map +1 -0
  63. package/dist/src/source-adapter.d.ts +32 -0
  64. package/dist/src/source-adapter.js +164 -0
  65. package/dist/src/source-adapter.js.map +1 -0
  66. package/dist/src/source-connector.d.ts +50 -0
  67. package/dist/src/source-connector.js +358 -0
  68. package/dist/src/source-connector.js.map +1 -0
  69. package/dist/src/source-control-client.d.ts +38 -0
  70. package/dist/src/source-control-client.js +61 -0
  71. package/dist/src/source-control-client.js.map +1 -0
  72. package/dist/src/source-ingress.d.ts +16 -0
  73. package/dist/src/source-ingress.js +47 -0
  74. package/dist/src/source-ingress.js.map +1 -0
  75. package/dist/src/source-sdk.d.ts +6 -0
  76. package/dist/src/source-sdk.js +53 -0
  77. package/dist/src/source-sdk.js.map +1 -0
  78. package/dist/src/transport-sdk.d.ts +102 -0
  79. package/dist/src/transport-sdk.js +222 -0
  80. package/dist/src/transport-sdk.js.map +1 -0
  81. package/dist/src/transport.d.ts +23 -0
  82. package/dist/src/transport.js +71 -0
  83. package/dist/src/transport.js.map +1 -0
  84. package/dist/src/types.d.ts +522 -0
  85. package/dist/src/types.js +2 -0
  86. package/dist/src/types.js.map +1 -0
  87. package/dist/src/util.d.ts +26 -0
  88. package/dist/src/util.js +136 -0
  89. package/dist/src/util.js.map +1 -0
  90. package/dist/src/version.d.ts +1 -0
  91. package/dist/src/version.js +2 -0
  92. package/dist/src/version.js.map +1 -0
  93. package/docs/adapters/botlingknows.md +40 -0
  94. package/docs/adapters/gmail-planned.md +16 -0
  95. package/docs/adapters/group-chat.md +126 -0
  96. package/docs/operations/connector-catalog.md +40 -0
  97. package/docs/operations/operator-control.md +83 -0
  98. package/docs/operations/out-of-process-host-adapter.md +150 -0
  99. package/docs/operations/policies.md +106 -0
  100. package/docs/operations/public-sdk.md +87 -0
  101. package/docs/operations/release-lifecycle.md +154 -0
  102. package/docs/operations/source-connectors.md +163 -0
  103. package/docs/operations/source-ingress.md +108 -0
  104. package/docs/operations/templates/botlingknows-connector.env.example +5 -0
  105. package/docs/operations/templates/sources.json.example +15 -0
  106. package/docs/quickstart.md +143 -0
  107. package/docs/releases/0.9.0-preview.8.md +44 -0
  108. package/docs/verification.md +19 -0
  109. package/examples/policies/botlingknows-conservative.json +44 -0
  110. package/examples/reference-host-adapter/README.md +41 -0
  111. package/examples/reference-host-adapter/adapter.mjs +173 -0
  112. package/examples/reference-host-adapter/host-adapters.json.example +26 -0
  113. package/package.json +94 -0
  114. package/schemas/event-v1.schema.json +26 -0
  115. package/schemas/policy-v1.schema.json +66 -0
@@ -0,0 +1,23 @@
1
+ import type { MockTransportCall, TransportContext, TransportResult, WakePayload, WakeTransport } from "./types.js";
2
+ /** In-memory transport used by tests and local demos. */
3
+ export declare class MockTransport implements WakeTransport {
4
+ readonly kind = "mock";
5
+ readonly calls: MockTransportCall[];
6
+ private failuresRemaining;
7
+ private readonly acceptedBatches;
8
+ failNext(count?: number): void;
9
+ dispatch(context: TransportContext): TransportResult;
10
+ hasAccepted(batchId: string): boolean;
11
+ }
12
+ /**
13
+ * File transport is intentionally boring: one JSON envelope per line. It is
14
+ * useful as a scriptable local adapter and never evaluates the envelope as a
15
+ * shell command or copies source正文 into it.
16
+ */
17
+ export declare class FileTransport implements WakeTransport {
18
+ readonly filePath: string;
19
+ readonly kind = "file";
20
+ constructor(filePath: string);
21
+ dispatch(context: TransportContext): TransportResult;
22
+ }
23
+ export type TransportFactory = (payload: WakePayload) => WakeTransport;
@@ -0,0 +1,71 @@
1
+ import { appendFileSync, mkdirSync } from "node:fs";
2
+ import { dirname } from "node:path";
3
+ /** In-memory transport used by tests and local demos. */
4
+ export class MockTransport {
5
+ kind = "mock";
6
+ calls = [];
7
+ failuresRemaining = 0;
8
+ acceptedBatches = new Set();
9
+ failNext(count = 1) {
10
+ this.failuresRemaining = Math.max(0, Math.floor(count));
11
+ }
12
+ dispatch(context) {
13
+ const call = {
14
+ attempt_id: context.attempt_id,
15
+ batch_id: context.batch.id,
16
+ endpoint_id: context.endpoint.id,
17
+ generation: context.binding.generation,
18
+ payload: context.payload,
19
+ at: new Date().toISOString(),
20
+ };
21
+ this.calls.push(call);
22
+ if (this.failuresRemaining > 0) {
23
+ this.failuresRemaining -= 1;
24
+ return {
25
+ accepted: false,
26
+ retryable: true,
27
+ error_class: "mock_failure",
28
+ error_message: "mock transport configured to fail",
29
+ };
30
+ }
31
+ this.acceptedBatches.add(context.batch.id);
32
+ return {
33
+ accepted: true,
34
+ transport_kind: this.kind,
35
+ receipt_details: { deduplicated: false },
36
+ };
37
+ }
38
+ hasAccepted(batchId) {
39
+ return this.acceptedBatches.has(batchId);
40
+ }
41
+ }
42
+ /**
43
+ * File transport is intentionally boring: one JSON envelope per line. It is
44
+ * useful as a scriptable local adapter and never evaluates the envelope as a
45
+ * shell command or copies source正文 into it.
46
+ */
47
+ export class FileTransport {
48
+ filePath;
49
+ kind = "file";
50
+ constructor(filePath) {
51
+ this.filePath = filePath;
52
+ mkdirSync(dirname(filePath), { recursive: true });
53
+ }
54
+ dispatch(context) {
55
+ const line = JSON.stringify({
56
+ attempt_id: context.attempt_id,
57
+ batch_id: context.batch.id,
58
+ endpoint_id: context.endpoint.id,
59
+ generation: context.binding.generation,
60
+ payload: context.payload,
61
+ accepted_at: new Date().toISOString(),
62
+ });
63
+ appendFileSync(this.filePath, `${line}\n`, { encoding: "utf8", mode: 0o600 });
64
+ return {
65
+ accepted: true,
66
+ transport_kind: this.kind,
67
+ receipt_details: { path: this.filePath },
68
+ };
69
+ }
70
+ }
71
+ //# sourceMappingURL=transport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.js","sourceRoot":"","sources":["../../src/transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASpC,yDAAyD;AACzD,MAAM,OAAO,aAAa;IACf,IAAI,GAAG,MAAM,CAAC;IACd,KAAK,GAAwB,EAAE,CAAC;IACjC,iBAAiB,GAAG,CAAC,CAAC;IACb,eAAe,GAAG,IAAI,GAAG,EAAU,CAAC;IAErD,QAAQ,CAAC,KAAK,GAAG,CAAC;QAChB,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;IAC1D,CAAC;IAED,QAAQ,CAAC,OAAyB;QAChC,MAAM,IAAI,GAAsB;YAC9B,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B,QAAQ,EAAE,OAAO,CAAC,KAAK,CAAC,EAAE;YAC1B,WAAW,EAAE,OAAO,CAAC,QAAQ,CAAC,EAAE;YAChC,UAAU,EAAE,OAAO,CAAC,OAAO,CAAC,UAAU;YACtC,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SAC7B,CAAC;QACF,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACtB,IAAI,IAAI,CAAC,iBAAiB,GAAG,CAAC,EAAE,CAAC;YAC/B,IAAI,CAAC,iBAAiB,IAAI,CAAC,CAAC;YAC5B,OAAO;gBACL,QAAQ,EAAE,KAAK;gBACf,SAAS,EAAE,IAAI;gBACf,WAAW,EAAE,cAAc;gBAC3B,aAAa,EAAE,mCAAmC;aACnD,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC3C,OAAO;YACL,QAAQ,EAAE,IAAI;YACd,cAAc,EAAE,IAAI,CAAC,IAAI;YACzB,eAAe,EAAE,EAAE,YAAY,EAAE,KAAK,EAAE;SACzC,CAAC;IACJ,CAAC;IAED,WAAW,CAAC,OAAe;QACzB,OAAO,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC3C,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,OAAO,aAAa;IAGH;IAFZ,IAAI,GAAG,MAAM,CAAC;IAEvB,YAAqB,QAAgB;QAAhB,aAAQ,GAAR,QAAQ,CAAQ;QACnC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACpD,CAAC;IAED,QAAQ,CAAC,OAAyB;QAChC,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC;YAC1B,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B,QAAQ,EAAE,OAAO,CAAC,KAAK,CAAC,EAAE;YAC1B,WAAW,EAAE,OAAO,CAAC,QAAQ,CAAC,EAAE;YAChC,UAAU,EAAE,OAAO,CAAC,OAAO,CAAC,UAAU;YACtC,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,WAAW,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SACtC,CAAC,CAAC;QACH,cAAc,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,IAAI,IAAI,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QAC9E,OAAO;YACL,QAAQ,EAAE,IAAI;YACd,cAAc,EAAE,IAAI,CAAC,IAAI;YACzB,eAAe,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE;SACzC,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,522 @@
1
+ import type { Server } from "node:http";
2
+ export type JsonPrimitive = string | number | boolean | null;
3
+ export type JsonValue = JsonPrimitive | JsonValue[] | {
4
+ [key: string]: JsonValue;
5
+ };
6
+ export type PriorityHint = "low" | "normal" | "high" | "urgent" | string;
7
+ export type EventState = "received" | "matched" | "suppressed" | "batched" | "consumed" | "expired";
8
+ export type ClaimOrigin = "policy" | "self_commitment" | "continuity_watch" | "inactivity_watch";
9
+ export type ClaimState = "pending" | "deferred" | "eligible" | "batched" | "consumed" | "dismissed" | "expired";
10
+ export type DeliveryMode = "immediate" | "scheduled" | "suppress";
11
+ export type QuietHoursPolicy = "defer" | "bypass";
12
+ export type ForegroundPresencePolicy = "defer" | "bypass";
13
+ export type BatchState = "pending" | "waiting_for_endpoint" | "waiting_for_waiter" | "dispatching" | "retry_wait" | "dispatched" | "seen" | "cancelled" | "needs_attention" | "dead_letter";
14
+ export type AttemptState = "leased" | "accepted" | "failed" | "expired";
15
+ export type ReceiptStage = "transport_accepted" | "agent_completed" | "agent_seen" | "agent_consumed" | "agent_acted";
16
+ export type SourceReadSideEffects = "none" | "marks_read" | "consumes" | "unknown";
17
+ export type SourceCredentialCustody = "none" | "connector" | "wake_bridge_process";
18
+ export type SourceUpstreamCredentialBreadth = "none" | "read_only" | "broad" | "unknown";
19
+ export type SourceCursor = JsonValue | null;
20
+ export interface ResourceRef {
21
+ uri: string;
22
+ cursor?: string | number | null;
23
+ [key: string]: unknown;
24
+ }
25
+ export interface WakeEventInput {
26
+ schema_version?: number;
27
+ type: string;
28
+ occurred_at?: string;
29
+ dedupe_key: string;
30
+ coalesce_key?: string | null;
31
+ priority_hint?: PriorityHint | null;
32
+ attention_channel_hint?: string | null;
33
+ actor_ref?: string | null;
34
+ resource: ResourceRef;
35
+ metadata?: Record<string, JsonValue>;
36
+ payload_preview?: string | null;
37
+ /** Optional caller idempotency key. It never changes source dedupe semantics. */
38
+ idempotency_key?: string | null;
39
+ }
40
+ /** Public capability declaration for one pull source adapter. */
41
+ export interface SourceAdapterManifest {
42
+ /** Public source SDK contract, independent from this adapter's release version. */
43
+ contract_version: 1;
44
+ id: string;
45
+ version: string;
46
+ /** Non-secret upstream principal chosen and confirmed by the source owner. */
47
+ subject_ref: string;
48
+ /** Non-secret sha256 fence for the connector's current upstream configuration. */
49
+ binding_fingerprint: string;
50
+ read_side_effects: SourceReadSideEffects;
51
+ /** Where the provider credential is actually held, not who owns the account. */
52
+ credential_custody: SourceCredentialCustody;
53
+ /** Honest breadth of the provider credential, which may be broader than this connector surface. */
54
+ upstream_credential_breadth: SourceUpstreamCredentialBreadth;
55
+ upstream_credential_scopes: string[];
56
+ /** The narrow operations exposed by the connector to its Wake source adapter. */
57
+ connector_capabilities: string[];
58
+ }
59
+ export interface SourcePollContext {
60
+ cursor: SourceCursor;
61
+ limit: number;
62
+ }
63
+ export interface SourcePollResult {
64
+ events: WakeEventInput[];
65
+ next_cursor: SourceCursor;
66
+ /** True asks the runner to schedule another bounded pass soon. */
67
+ has_more?: boolean;
68
+ }
69
+ export interface PullSourceAdapter {
70
+ readonly manifest: SourceAdapterManifest;
71
+ poll(context: SourcePollContext): Promise<SourcePollResult> | SourcePollResult;
72
+ }
73
+ export interface SourceCheckpoint {
74
+ instance_id: string;
75
+ source: string;
76
+ adapter_version: string;
77
+ subject_ref: string;
78
+ binding_fingerprint: string;
79
+ cursor: SourceCursor;
80
+ revision: number;
81
+ updated_at: string;
82
+ }
83
+ /** Agent-facing checkpoint metadata. Opaque provider cursors stay inside Core. */
84
+ export type SourceCheckpointSummary = Omit<SourceCheckpoint, "cursor" | "instance_id">;
85
+ export interface SourceRunResult {
86
+ source: string;
87
+ adapter_version: string;
88
+ checkpoint_revision: number;
89
+ events_seen: number;
90
+ events_inserted: number;
91
+ events_duplicate: number;
92
+ has_more: boolean;
93
+ }
94
+ /** Owner-controlled local connector. The token authenticates to the connector, not the provider. */
95
+ export interface SourceConnectorConfig {
96
+ id: string;
97
+ base_url: string;
98
+ token_env: string;
99
+ enabled?: boolean;
100
+ poll_interval_ms?: number;
101
+ max_backoff_ms?: number;
102
+ limit?: number;
103
+ max_pages_per_cycle?: number;
104
+ }
105
+ export interface SourceConnectorFile {
106
+ version: 1;
107
+ sources: SourceConnectorConfig[];
108
+ }
109
+ export type SourceSupervisorState = "idle" | "polling" | "healthy" | "backoff" | "needs_attention" | "stopped";
110
+ export interface SourceSupervisorStatus {
111
+ source: string;
112
+ enabled: boolean;
113
+ state: SourceSupervisorState;
114
+ last_started_at: string | null;
115
+ last_success_at: string | null;
116
+ last_error_at: string | null;
117
+ last_error_class: string | null;
118
+ consecutive_failures: number;
119
+ next_poll_at: string | null;
120
+ checkpoint_revision: number;
121
+ checkpoint_subject_ref: string | null;
122
+ checkpoint_binding_fingerprint: string | null;
123
+ last_run: SourceRunResult | null;
124
+ }
125
+ export interface SourceVerification {
126
+ source: string;
127
+ manifest: SourceAdapterManifest;
128
+ checkpoint: SourceCheckpointSummary | null;
129
+ binding_matches: boolean;
130
+ enabled: boolean;
131
+ }
132
+ export interface WakeEvent extends WakeEventInput {
133
+ id: string;
134
+ schema_version: number;
135
+ instance_id: string;
136
+ owner_id: string;
137
+ source: string;
138
+ occurred_at: string;
139
+ received_at: string;
140
+ state: EventState;
141
+ matched_policy_id?: string | null;
142
+ matched_policy_version?: number | null;
143
+ }
144
+ export interface PolicyMatch {
145
+ source?: string;
146
+ type?: string;
147
+ actor_ref?: string;
148
+ attention_channel_hint?: string;
149
+ metadata?: Record<string, JsonValue | undefined>;
150
+ /** Dot-path selectors are also accepted for convenient JSON policy files. */
151
+ [key: string]: unknown;
152
+ }
153
+ export interface PolicyDelivery {
154
+ mode: DeliveryMode;
155
+ scheduled_local_time?: string | null;
156
+ quiet_hours_policy?: QuietHoursPolicy;
157
+ foreground_presence_policy?: ForegroundPresencePolicy;
158
+ }
159
+ export interface PolicyBatch {
160
+ coalesce_by?: "coalesce_key" | "type" | "source" | "none" | string;
161
+ max_events?: number | null;
162
+ window_ms?: number | null;
163
+ }
164
+ export interface PolicyTarget {
165
+ attention_channel?: string | null;
166
+ }
167
+ export interface PolicyRule {
168
+ id: string;
169
+ version: number;
170
+ enabled?: boolean;
171
+ order?: number;
172
+ match?: PolicyMatch;
173
+ delivery: PolicyDelivery;
174
+ batch?: PolicyBatch;
175
+ target?: PolicyTarget;
176
+ reason_code?: string;
177
+ expires_after_ms?: number | null;
178
+ }
179
+ /**
180
+ * Read-only representation of policy rows created before public policy v1.
181
+ * Legacy fields are never accepted by current install surfaces and legacy
182
+ * rules do not participate in matching new events.
183
+ */
184
+ export interface InstalledPolicyRule extends Omit<PolicyRule, "delivery" | "target"> {
185
+ delivery: Omit<PolicyDelivery, "mode"> & {
186
+ mode: DeliveryMode | "debounce" | "digest";
187
+ debounce_ms?: number | null;
188
+ cadence_ms?: number | null;
189
+ max_delay_ms?: number | null;
190
+ };
191
+ target?: PolicyTarget & {
192
+ prefer_transport?: "warm" | "cold" | "any";
193
+ busy_behavior?: "queue" | "retry" | "steer";
194
+ };
195
+ }
196
+ /** Stable, owner-authored policy file contract. */
197
+ export interface PolicyFile {
198
+ schema_version: 1;
199
+ policies: PolicyRule[];
200
+ }
201
+ export interface PolicyMatchResult {
202
+ source: string;
203
+ type: string;
204
+ matched_policy: PolicyRule;
205
+ }
206
+ export interface PolicyPreviewResult extends PolicyMatchResult {
207
+ evaluated_at: string;
208
+ suppressed: boolean;
209
+ claim: null | {
210
+ attention_channel: string;
211
+ eligible_after: string;
212
+ expires_at: string | null;
213
+ reason_code: string;
214
+ defer_while_presence: boolean;
215
+ };
216
+ gates: {
217
+ quiet_hours: {
218
+ action: QuietHoursPolicy;
219
+ active: boolean;
220
+ defer_until: string | null;
221
+ };
222
+ foreground_presence: {
223
+ action: ForegroundPresencePolicy;
224
+ active: boolean;
225
+ defer_until: string | null;
226
+ };
227
+ };
228
+ batch: null | {
229
+ coalesce_by: string;
230
+ coalesce_key: string | null;
231
+ max_events: number;
232
+ window_ms: number;
233
+ };
234
+ }
235
+ export interface PolicyVersionStatus {
236
+ id: string;
237
+ version: number;
238
+ active: boolean;
239
+ enabled: boolean;
240
+ new_event_matching: "eligible" | "disabled" | "legacy_unsupported" | "historical";
241
+ }
242
+ export interface QuietHoursWindow {
243
+ start: string;
244
+ end: string;
245
+ }
246
+ export interface QuietHoursConfig {
247
+ timezone?: string;
248
+ windows: QuietHoursWindow[];
249
+ }
250
+ export interface BridgeConfig {
251
+ instance_id: string;
252
+ owner_id: string;
253
+ db_path: string;
254
+ timezone?: string;
255
+ admin_token?: string;
256
+ quiet_hours?: QuietHoursConfig | null;
257
+ presence_ttl_ms?: number;
258
+ activity_ttl_ms?: number;
259
+ endpoint_lease_ms?: number;
260
+ dispatch_lease_ms?: number;
261
+ retry_delay_ms?: number;
262
+ batch_window_ms?: number;
263
+ default_policy?: PolicyRule;
264
+ policies?: PolicyRule[];
265
+ }
266
+ export interface AttentionClaim {
267
+ id: string;
268
+ instance_id: string;
269
+ origin: ClaimOrigin;
270
+ event_ids: string[];
271
+ resource: ResourceRef;
272
+ policy_id: string;
273
+ policy_version: number;
274
+ attention_channel: string;
275
+ eligible_after: string;
276
+ expires_at?: string | null;
277
+ defer_while_presence: boolean;
278
+ state: ClaimState;
279
+ reason_code: string;
280
+ note?: string | null;
281
+ created_at: string;
282
+ updated_at: string;
283
+ snooze_until?: string | null;
284
+ consumed_result?: JsonValue | null;
285
+ dismissed_reason?: string | null;
286
+ }
287
+ export interface EndpointRoute {
288
+ kind: string;
289
+ priority?: number;
290
+ address: Record<string, JsonValue>;
291
+ }
292
+ export interface EndpointCapabilities {
293
+ cold_push?: boolean;
294
+ warm_resume?: boolean;
295
+ exact_live_route?: boolean;
296
+ requires_live_binding?: boolean;
297
+ queue_when_busy?: boolean;
298
+ steer_when_busy?: boolean;
299
+ foreground_presence_observable?: boolean;
300
+ session_activity_observable?: boolean;
301
+ activity_progress_observable?: boolean;
302
+ waiter_turn_settle_compatible?: boolean;
303
+ session_rebuild_takeover?: boolean;
304
+ receipt_upper_bound?: string;
305
+ support_tier?: string;
306
+ receipt_stages?: ReceiptStage[];
307
+ [key: string]: JsonValue | undefined;
308
+ }
309
+ export interface EndpointRegistration {
310
+ id?: string;
311
+ host_kind: string;
312
+ session_ref: string;
313
+ capabilities?: EndpointCapabilities;
314
+ routes?: EndpointRoute[];
315
+ lease_ms?: number;
316
+ }
317
+ export interface Endpoint {
318
+ id: string;
319
+ instance_id: string;
320
+ host_kind: string;
321
+ session_ref: string;
322
+ lease_token?: string;
323
+ lease_expires_at: string;
324
+ capabilities: EndpointCapabilities;
325
+ routes: EndpointRoute[];
326
+ registered_at: string;
327
+ updated_at: string;
328
+ }
329
+ export interface Binding {
330
+ instance_id: string;
331
+ attention_channel: string;
332
+ endpoint_id: string;
333
+ generation: number;
334
+ bound_at: string;
335
+ }
336
+ export interface PresenceLease {
337
+ instance_id: string;
338
+ attention_channel: string;
339
+ endpoint_id: string;
340
+ binding_generation: number;
341
+ renewed_at: string;
342
+ expires_at: string;
343
+ observed_by: string;
344
+ observation: string;
345
+ }
346
+ export interface PresenceRenewal {
347
+ attention_channel: string;
348
+ endpoint_id: string;
349
+ generation: number;
350
+ ttl_ms?: number;
351
+ lease_token?: string;
352
+ observed_by: string;
353
+ observation?: string;
354
+ }
355
+ export type ActivityKind = "owner_message_accepted" | "activity_started" | "activity_progress" | "activity_settled" | "wake_started" | "wake_progress" | "wake_settled";
356
+ export interface ActivityObservation {
357
+ attention_channel: string;
358
+ endpoint_id: string;
359
+ generation: number;
360
+ lease_token?: string;
361
+ observation_id: string;
362
+ kind: ActivityKind;
363
+ observed_at?: string;
364
+ ttl_ms?: number;
365
+ }
366
+ export interface ActivityObservationResult {
367
+ duplicate: boolean;
368
+ watch: ActivityWatch | null;
369
+ }
370
+ export interface ActivityWatchConfiguration {
371
+ attention_channel: string;
372
+ enabled: boolean;
373
+ idle_after_ms: number;
374
+ mode?: "once" | "repeat";
375
+ repeat_after_ms?: number;
376
+ }
377
+ export interface ActivityWatch {
378
+ instance_id: string;
379
+ attention_channel: string;
380
+ enabled: boolean;
381
+ idle_after_ms: number;
382
+ endpoint_id: string | null;
383
+ binding_generation: number | null;
384
+ epoch: number;
385
+ armed_at: string | null;
386
+ last_nonwake_activity_at: string | null;
387
+ activity_lease_expires_at: string | null;
388
+ fired_epoch: number | null;
389
+ mode: "once" | "repeat";
390
+ repeat_after_ms: number;
391
+ sequence: number;
392
+ last_triggered_at: string | null;
393
+ next_due_at: string | null;
394
+ condition_status: "disabled" | "waiting_for_endpoint" | "unsupported" | "waiting_for_activity" | "watching" | "inactive";
395
+ limits: {
396
+ min_interval_ms: number;
397
+ max_claims_per_tick: number;
398
+ };
399
+ updated_at: string;
400
+ }
401
+ export interface WakeBatch {
402
+ id: string;
403
+ instance_id: string;
404
+ policy_id: string;
405
+ policy_version: number;
406
+ attention_channel: string;
407
+ claim_ids: string[];
408
+ event_ids: string[];
409
+ coalesce_key?: string | null;
410
+ state: BatchState;
411
+ not_before: string;
412
+ deadline?: string | null;
413
+ attempt: number;
414
+ binding_generation?: number | null;
415
+ created_at: string;
416
+ updated_at: string;
417
+ lease_expires_at?: string | null;
418
+ last_error?: string | null;
419
+ }
420
+ export interface WakeBriefClaim {
421
+ claim_id: string;
422
+ event_id?: string;
423
+ source: string;
424
+ type: string;
425
+ resource: ResourceRef;
426
+ origin: ClaimOrigin;
427
+ reason_code: string;
428
+ }
429
+ export interface WakePayload {
430
+ schema_version: number;
431
+ instance_id: string;
432
+ wake_batch_id: string;
433
+ attention_channel: string;
434
+ claim_refs: WakeBriefClaim[];
435
+ binding_generation: number;
436
+ }
437
+ export interface TransportContext {
438
+ batch: WakeBatch;
439
+ endpoint: Endpoint;
440
+ binding: Binding;
441
+ payload: WakePayload;
442
+ attempt_id: string;
443
+ /** One-shot nonce generated and persisted by Core before transport dispatch. */
444
+ delivery_nonce: string;
445
+ }
446
+ export type DeliveryCorrelationState = "outstanding" | "consumed" | "discarded" | "expired";
447
+ export interface DeliveryCorrelation {
448
+ attempt_id: string;
449
+ batch_id: string;
450
+ endpoint_id: string;
451
+ binding_generation: number;
452
+ transport_kind: string;
453
+ nonce_hash: string;
454
+ state: DeliveryCorrelationState;
455
+ created_at: string;
456
+ expires_at: string;
457
+ consumed_at?: string | null;
458
+ }
459
+ export interface WakeEchoObservation {
460
+ attention_channel: string;
461
+ endpoint_id: string;
462
+ generation: number;
463
+ lease_token?: string;
464
+ observation_id: string;
465
+ delivery_nonce: string;
466
+ observed_at?: string;
467
+ ttl_ms?: number;
468
+ }
469
+ export interface TransportResult {
470
+ accepted: boolean;
471
+ transport_kind?: string;
472
+ receipt_details?: Record<string, JsonValue>;
473
+ retryable?: boolean;
474
+ /** Optional transport-directed delay before retrying this durable batch. */
475
+ retry_after_ms?: number;
476
+ error_class?: string;
477
+ error_message?: string;
478
+ }
479
+ export interface WakeTransport {
480
+ readonly kind: string;
481
+ readonly capabilities?: EndpointCapabilities;
482
+ dispatch(context: TransportContext): Promise<TransportResult> | TransportResult;
483
+ }
484
+ export interface MockTransportCall {
485
+ attempt_id: string;
486
+ batch_id: string;
487
+ endpoint_id: string;
488
+ generation: number;
489
+ payload: WakePayload;
490
+ at: string;
491
+ }
492
+ export interface Receipt {
493
+ id: string;
494
+ batch_id: string;
495
+ claim_id?: string | null;
496
+ stage: ReceiptStage;
497
+ at: string;
498
+ endpoint_id?: string | null;
499
+ binding_generation?: number | null;
500
+ transport_kind?: string | null;
501
+ details?: Record<string, JsonValue> | null;
502
+ }
503
+ export interface TickResult {
504
+ inactivity_claims_created: string[];
505
+ expired_claims: string[];
506
+ deferred_claims: string[];
507
+ eligible_claims: string[];
508
+ batches_created: string[];
509
+ batches_updated: string[];
510
+ }
511
+ export interface DispatchResult {
512
+ batch_id: string;
513
+ status: "accepted" | "waiting_for_endpoint" | "retry_wait" | "needs_attention" | "dead_letter" | "stale_generation" | "skipped";
514
+ attempt_id?: string;
515
+ endpoint_id?: string;
516
+ generation?: number;
517
+ error_class?: string;
518
+ }
519
+ export interface DaemonHandle {
520
+ server: Server;
521
+ close(): Promise<void>;
522
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,26 @@
1
+ import type { JsonValue, QuietHoursConfig } from "./types.js";
2
+ export declare const DEFAULT_TIMEZONE = "UTC";
3
+ export declare function id(prefix: string): string;
4
+ export declare function isoNow(now?: Date): string;
5
+ export declare function asDate(value: string | Date): Date;
6
+ export declare function addMs(value: string | Date, milliseconds: number): string;
7
+ export declare function sha256(value: string): string;
8
+ export declare function parseJson<T>(value: unknown, fallback: T): T;
9
+ export declare function stableJson(value: unknown): string;
10
+ export declare function getPath(value: unknown, path: string): unknown;
11
+ export declare function localParts(date: Date, timezone: string): {
12
+ date: string;
13
+ hour: number;
14
+ minute: number;
15
+ second: number;
16
+ };
17
+ export declare function localMinute(date: Date, timezone: string): number;
18
+ export declare function parseClock(value: string): number;
19
+ export declare function clockInWindow(minute: number, start: number, end: number): boolean;
20
+ export declare function quietWindowAt(date: Date, config: QuietHoursConfig | null | undefined, fallbackTimezone?: string): boolean;
21
+ /** Find the first minute at which a quiet-hours gate is open again. */
22
+ export declare function quietEndAfter(date: Date, config: QuietHoursConfig | null | undefined, fallbackTimezone?: string): Date;
23
+ /** Resolve the next occurrence of HH:mm in a timezone using a bounded search. */
24
+ export declare function nextLocalClock(date: Date, clock: string, timezone: string): Date;
25
+ export declare function jsonValue(value: unknown): JsonValue;
26
+ export declare function assertFiniteMs(value: number | null | undefined, field: string, fallback: number): number;