@holon-run/agentinbox 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,178 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 AgentInbox Contributors
package/README.md ADDED
@@ -0,0 +1,168 @@
1
+ # AgentInbox
2
+
3
+ `AgentInbox` is the local event inbox and activation service for agents.
4
+
5
+ It connects external and local event sources, stores them as durable streams,
6
+ routes them by subscription, and lets agents read, watch, acknowledge, and
7
+ reply through one boundary.
8
+
9
+ `AgentInbox` is not an agent runtime. It sits between outside systems and local
10
+ agent runtimes.
11
+
12
+ In practice, that means `AgentInbox` can:
13
+
14
+ - share one GitHub or Feishu source across multiple local agents
15
+ - materialize those events into durable inboxes
16
+ - wake or drive agent sessions running in `tmux` or `iTerm2`, even when the
17
+ agent runtime does not expose a notification API
18
+
19
+ ## Status
20
+
21
+ `AgentInbox` is public beta software.
22
+
23
+ - the local control plane, daemon model, inbox model, and activation targets
24
+ are implemented
25
+ - GitHub repo, GitHub repo CI, Feishu bot, and local event ingress source
26
+ adapters are implemented
27
+ - filtering and source model are still evolving
28
+ - first-run onboarding is currently skill-first rather than wizard-first
29
+
30
+ ## Install
31
+
32
+ Requires:
33
+
34
+ - Node.js 20 or newer
35
+ - `uxc` 0.13.3 or newer if you want to use GitHub or Feishu adapters
36
+
37
+ Install globally:
38
+
39
+ ```bash
40
+ npm install -g @holon-run/agentinbox
41
+ ```
42
+
43
+ Or run directly:
44
+
45
+ ```bash
46
+ npx @holon-run/agentinbox --help
47
+ ```
48
+
49
+ If you are developing from source:
50
+
51
+ ```bash
52
+ npm install
53
+ npm run build
54
+ node dist/src/cli.js --help
55
+ ```
56
+
57
+ ## Recommended Onboarding
58
+
59
+ If you are using Codex or Claude Code, start with the bundled AgentInbox skill:
60
+
61
+ - repo copy: [`skills/agentinbox/SKILL.md`](./skills/agentinbox/SKILL.md)
62
+ - docs site copy: `https://agentinbox.holon.run/skills/agentinbox/SKILL`
63
+
64
+ That skill is the recommended onboarding path. It can guide the agent through:
65
+
66
+ - checking or installing `agentinbox`
67
+ - checking or installing `uxc`
68
+ - importing GitHub auth from the local `gh` CLI via `uxc auth credential import github --from gh`
69
+ - registering the current terminal session as an agent
70
+ - adding GitHub sources and standing subscriptions using the docs-site examples
71
+
72
+ ## Quick Start
73
+
74
+ Start the local daemon:
75
+
76
+ ```bash
77
+ agentinbox daemon start
78
+ ```
79
+
80
+ Register the current terminal session:
81
+
82
+ ```bash
83
+ agentinbox agent register
84
+ agentinbox agent register --agent-id agent-alpha
85
+ ```
86
+
87
+ Create a local source and publish an event:
88
+
89
+ ```bash
90
+ agentinbox source add local_event local-demo
91
+ agentinbox subscription add <agent_id> <source_id>
92
+ agentinbox source event <source_id> --native-id demo-1 --event local.demo
93
+ agentinbox inbox read <agent_id>
94
+ ```
95
+
96
+ Remove a task-specific subscription without deleting the whole agent:
97
+
98
+ ```bash
99
+ agentinbox subscription remove <subscription_id>
100
+ ```
101
+
102
+ ## Docs
103
+
104
+ Public docs live in the mdorigin site under [`docs/site`](./docs/site).
105
+
106
+ - docs site: `https://agentinbox.holon.run`
107
+ - docs home: [`docs/site/README.md`](./docs/site/README.md)
108
+ - onboarding with the agent skill: [`docs/site/guides/onboarding-with-agent-skill.md`](./docs/site/guides/onboarding-with-agent-skill.md)
109
+ - getting started: [`docs/site/guides/getting-started.md`](./docs/site/guides/getting-started.md)
110
+ - review workflows: [`docs/site/guides/review-workflows.md`](./docs/site/guides/review-workflows.md)
111
+ - skill docs: [`docs/site/skills/README.md`](./docs/site/skills/README.md)
112
+ - CLI reference: [`docs/site/reference/cli.md`](./docs/site/reference/cli.md)
113
+ - source types: [`docs/site/reference/source-types.md`](./docs/site/reference/source-types.md)
114
+ - architecture: [`docs/site/concepts/architecture.md`](./docs/site/concepts/architecture.md)
115
+ - event bus design: [`docs/site/concepts/eventbus-backend.md`](./docs/site/concepts/eventbus-backend.md)
116
+ - event filtering RFC: [`docs/site/rfcs/event-filtering.md`](./docs/site/rfcs/event-filtering.md)
117
+
118
+ Preview the docs site locally:
119
+
120
+ ```bash
121
+ npm run docs:dev
122
+ ```
123
+
124
+ Build the Cloudflare deploy bundle:
125
+
126
+ ```bash
127
+ npm run docs:index
128
+ npm run docs:build
129
+ ```
130
+
131
+ ## Development
132
+
133
+ Run tests:
134
+
135
+ ```bash
136
+ npm test
137
+ ```
138
+
139
+ Build the CLI:
140
+
141
+ ```bash
142
+ npm run build
143
+ ```
144
+
145
+ Build docs directory indexes:
146
+
147
+ ```bash
148
+ npm run docs:index
149
+ ```
150
+
151
+ ## Release
152
+
153
+ `AgentInbox` releases are tag-driven.
154
+
155
+ - update [package.json](./package.json) and [CHANGELOG.md](./CHANGELOG.md) in a PR before release
156
+ - merge to `main`
157
+ - run the manual terminal smoke matrix in [testcases/manual/manual-terminal-qa.md](./testcases/manual/manual-terminal-qa.md)
158
+ - push a tag in the form `v<package.json version>`
159
+
160
+ Public beta tags such as `v0.1.0-beta.1` publish to npm with the `beta`
161
+ dist-tag. Stable tags such as `v0.1.0` publish with the `latest` dist-tag.
162
+
163
+ The operational checklist lives in
164
+ [testcases/manual/release-checklist.md](./testcases/manual/release-checklist.md).
165
+
166
+ ## License
167
+
168
+ Apache-2.0
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AdapterRegistry = void 0;
4
+ const feishu_1 = require("./sources/feishu");
5
+ const github_1 = require("./sources/github");
6
+ const github_ci_1 = require("./sources/github_ci");
7
+ class NoopSourceAdapter {
8
+ sourceType;
9
+ constructor(sourceType) {
10
+ this.sourceType = sourceType;
11
+ }
12
+ async ensureSource(_source) {
13
+ return;
14
+ }
15
+ async pollSource(sourceId) {
16
+ return {
17
+ sourceId,
18
+ sourceType: this.sourceType,
19
+ appended: 0,
20
+ deduped: 0,
21
+ eventsRead: 0,
22
+ note: `${this.sourceType} source has no background poller`,
23
+ };
24
+ }
25
+ }
26
+ class NoopDeliveryAdapter {
27
+ async send(_request, _attempt) {
28
+ return { status: "accepted", note: "accepted without provider-side delivery" };
29
+ }
30
+ }
31
+ class AdapterRegistry {
32
+ fixtureSource = new NoopSourceAdapter("fixture");
33
+ localEventSource = new NoopSourceAdapter("local_event");
34
+ remoteSource = new NoopSourceAdapter("remote_source");
35
+ feishuSource;
36
+ githubSource;
37
+ githubCiSource;
38
+ fixtureDelivery = new NoopDeliveryAdapter();
39
+ feishuDelivery = new feishu_1.FeishuDeliveryAdapter();
40
+ githubDelivery = new github_1.GithubDeliveryAdapter();
41
+ constructor(store, appendSourceEvent) {
42
+ this.feishuSource = new feishu_1.FeishuSourceRuntime(store, appendSourceEvent);
43
+ this.githubSource = new github_1.GithubSourceRuntime(store, appendSourceEvent);
44
+ this.githubCiSource = new github_ci_1.GithubCiSourceRuntime(store, appendSourceEvent);
45
+ }
46
+ sourceAdapterFor(type) {
47
+ if (type === "fixture") {
48
+ return this.fixtureSource;
49
+ }
50
+ if (type === "local_event") {
51
+ return this.localEventSource;
52
+ }
53
+ if (type === "remote_source") {
54
+ return this.remoteSource;
55
+ }
56
+ if (type === "github_repo") {
57
+ return this.githubSource;
58
+ }
59
+ if (type === "github_repo_ci") {
60
+ return this.githubCiSource;
61
+ }
62
+ if (type === "feishu_bot") {
63
+ return this.feishuSource;
64
+ }
65
+ return this.fixtureSource;
66
+ }
67
+ deliveryAdapterFor(provider) {
68
+ if (provider === "fixture") {
69
+ return this.fixtureDelivery;
70
+ }
71
+ if (provider === "feishu") {
72
+ return this.feishuDelivery;
73
+ }
74
+ if (provider === "github") {
75
+ return this.githubDelivery;
76
+ }
77
+ return this.fixtureDelivery;
78
+ }
79
+ async start() {
80
+ await this.feishuSource.start?.();
81
+ await this.githubSource.start?.();
82
+ await this.githubCiSource.start?.();
83
+ }
84
+ async stop() {
85
+ await this.feishuSource.stop?.();
86
+ await this.githubSource.stop?.();
87
+ await this.githubCiSource.stop?.();
88
+ }
89
+ async pollSource(source) {
90
+ const adapter = this.sourceAdapterFor(source.sourceType);
91
+ if (!adapter.pollSource) {
92
+ return {
93
+ sourceId: source.sourceId,
94
+ sourceType: source.sourceType,
95
+ appended: 0,
96
+ deduped: 0,
97
+ eventsRead: 0,
98
+ note: "source type does not support polling",
99
+ };
100
+ }
101
+ return adapter.pollSource(source.sourceId);
102
+ }
103
+ status() {
104
+ return {
105
+ feishu: this.feishuSource.status?.() ?? {},
106
+ github: this.githubSource.status?.() ?? {},
107
+ githubCi: this.githubCiSource.status?.() ?? {},
108
+ };
109
+ }
110
+ }
111
+ exports.AdapterRegistry = AdapterRegistry;
@@ -0,0 +1,175 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SqliteEventBusBackend = void 0;
4
+ exports.streamIdForSource = streamIdForSource;
5
+ exports.consumerIdForSubscription = consumerIdForSubscription;
6
+ exports.defaultInboxIdForAgent = defaultInboxIdForAgent;
7
+ exports.streamKeyForSource = streamKeyForSource;
8
+ exports.toAppendResult = toAppendResult;
9
+ const util_1 = require("./util");
10
+ class SqliteEventBusBackend {
11
+ store;
12
+ constructor(store) {
13
+ this.store = store;
14
+ }
15
+ async ensureStream(input) {
16
+ const existing = this.store.getStreamBySourceId(input.sourceId);
17
+ if (existing) {
18
+ return existing;
19
+ }
20
+ const stream = {
21
+ streamId: streamIdForSource(input.sourceId),
22
+ sourceId: input.sourceId,
23
+ streamKey: input.streamKey,
24
+ backend: input.backend,
25
+ createdAt: (0, util_1.nowIso)(),
26
+ };
27
+ this.store.insertStream(stream);
28
+ return stream;
29
+ }
30
+ async append(input) {
31
+ let appended = 0;
32
+ let deduped = 0;
33
+ let lastOffset = null;
34
+ for (const event of input.events) {
35
+ const result = this.store.insertStreamEvent(input.streamId, event);
36
+ appended += result.appended;
37
+ deduped += result.deduped;
38
+ lastOffset = result.lastOffset ?? lastOffset;
39
+ }
40
+ return { appended, deduped, lastOffset };
41
+ }
42
+ async ensureConsumer(input) {
43
+ const existing = this.store.getConsumerBySubscriptionId(input.subscriptionId);
44
+ if (existing) {
45
+ return existing;
46
+ }
47
+ const nextOffset = this.resolveInitialOffset(input.streamId, input.startPolicy, input.startOffset ?? null, input.startTime ?? null);
48
+ const consumer = {
49
+ consumerId: consumerIdForSubscription(input.subscriptionId),
50
+ streamId: input.streamId,
51
+ subscriptionId: input.subscriptionId,
52
+ consumerKey: input.consumerKey,
53
+ nextOffset,
54
+ startPolicy: input.startPolicy,
55
+ startOffset: input.startOffset ?? null,
56
+ startTime: input.startTime ?? null,
57
+ createdAt: (0, util_1.nowIso)(),
58
+ updatedAt: (0, util_1.nowIso)(),
59
+ };
60
+ this.store.insertConsumer(consumer);
61
+ return consumer;
62
+ }
63
+ async getConsumer(input) {
64
+ if (input.consumerId) {
65
+ return this.store.getConsumer(input.consumerId);
66
+ }
67
+ if (input.subscriptionId) {
68
+ return this.store.getConsumerBySubscriptionId(input.subscriptionId);
69
+ }
70
+ throw new Error("getConsumer requires consumerId or subscriptionId");
71
+ }
72
+ async deleteConsumer(input) {
73
+ const consumer = await this.getConsumer(input);
74
+ if (!consumer) {
75
+ return { removed: false };
76
+ }
77
+ this.store.deleteConsumer(consumer.consumerId);
78
+ return { removed: true };
79
+ }
80
+ async read(input) {
81
+ const consumer = this.store.getConsumer(input.consumerId);
82
+ if (!consumer) {
83
+ throw new Error(`unknown consumer: ${input.consumerId}`);
84
+ }
85
+ const events = this.store.readStreamEvents(input.streamId, consumer.nextOffset, input.limit);
86
+ const stats = this.store.getStreamStats(input.streamId);
87
+ return {
88
+ consumer,
89
+ events,
90
+ highWatermarkOffset: stats.highWatermarkOffset,
91
+ };
92
+ }
93
+ async commit(input) {
94
+ const consumer = this.store.getConsumer(input.consumerId);
95
+ if (!consumer) {
96
+ throw new Error(`unknown consumer: ${input.consumerId}`);
97
+ }
98
+ const nextOffset = input.committedOffset + 1;
99
+ const updated = this.store.updateConsumerOffset(input.consumerId, nextOffset, input.committedOffset);
100
+ return {
101
+ consumer: updated,
102
+ committedOffset: input.committedOffset,
103
+ };
104
+ }
105
+ async reset(input) {
106
+ const consumer = this.store.getConsumer(input.consumerId);
107
+ if (!consumer) {
108
+ throw new Error(`unknown consumer: ${input.consumerId}`);
109
+ }
110
+ const nextOffset = this.resolveInitialOffset(consumer.streamId, input.startPolicy, input.startOffset ?? null, input.startTime ?? null);
111
+ return this.store.resetConsumer(consumer.consumerId, {
112
+ startPolicy: input.startPolicy,
113
+ startOffset: input.startOffset ?? null,
114
+ startTime: input.startTime ?? null,
115
+ nextOffset,
116
+ });
117
+ }
118
+ async getStreamStats(streamId) {
119
+ return this.store.getStreamStats(streamId);
120
+ }
121
+ async getConsumerLag(input) {
122
+ const consumer = await this.getConsumer(input);
123
+ if (!consumer) {
124
+ throw new Error("unknown consumer");
125
+ }
126
+ const stats = this.store.getStreamStats(consumer.streamId);
127
+ const pendingEvents = this.store.countPendingEvents(consumer.streamId, consumer.nextOffset);
128
+ return {
129
+ consumerId: consumer.consumerId,
130
+ streamId: consumer.streamId,
131
+ pendingEvents,
132
+ highWatermarkOffset: stats.highWatermarkOffset,
133
+ nextOffset: consumer.nextOffset,
134
+ };
135
+ }
136
+ resolveInitialOffset(streamId, startPolicy, startOffset, startTime) {
137
+ const stats = this.store.getStreamStats(streamId);
138
+ if (startPolicy === "latest") {
139
+ return (stats.highWatermarkOffset ?? 0) + 1;
140
+ }
141
+ if (startPolicy === "earliest") {
142
+ return 1;
143
+ }
144
+ if (startPolicy === "at_offset") {
145
+ return Math.max(1, startOffset ?? 1);
146
+ }
147
+ if (startPolicy === "at_time") {
148
+ if (!startTime) {
149
+ throw new Error("at_time start policy requires startTime");
150
+ }
151
+ return this.store.findOffsetAtOrAfter(streamId, startTime) ?? ((stats.highWatermarkOffset ?? 0) + 1);
152
+ }
153
+ throw new Error(`unsupported start policy: ${String(startPolicy)}`);
154
+ }
155
+ }
156
+ exports.SqliteEventBusBackend = SqliteEventBusBackend;
157
+ function streamIdForSource(sourceId) {
158
+ return `stream_${sourceId}`;
159
+ }
160
+ function consumerIdForSubscription(subscriptionId) {
161
+ return `consumer_${subscriptionId}`;
162
+ }
163
+ function defaultInboxIdForAgent(agentId) {
164
+ return `inbox_${agentId}`;
165
+ }
166
+ function streamKeyForSource(sourceType, sourceKey) {
167
+ return `${sourceType}:${sourceKey}`;
168
+ }
169
+ function toAppendResult(result) {
170
+ return {
171
+ appended: result.appended,
172
+ deduped: result.deduped,
173
+ lastOffset: result.lastOffset,
174
+ };
175
+ }