@openmarket/rooms-client 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 +201 -0
- package/README.md +25 -0
- package/dist/agent/armed-mode.d.ts +187 -0
- package/dist/agent/armed-mode.js +306 -0
- package/dist/agent/clients/common.d.ts +70 -0
- package/dist/agent/clients/common.js +46 -0
- package/dist/agent/lane-draft.d.ts +15 -0
- package/dist/agent/lane-draft.js +43 -0
- package/dist/agent/lane-prompts.d.ts +102 -0
- package/dist/agent/lane-prompts.js +120 -0
- package/dist/agent/library-context.d.ts +38 -0
- package/dist/agent/library-context.js +57 -0
- package/dist/agent/library-model.d.ts +41 -0
- package/dist/agent/library-model.js +173 -0
- package/dist/agent/room-context.d.ts +151 -0
- package/dist/agent/room-context.js +251 -0
- package/dist/agent/sidebar-model.d.ts +86 -0
- package/dist/agent/sidebar-model.js +162 -0
- package/dist/agent/topic-inbox.d.ts +119 -0
- package/dist/agent/topic-inbox.js +266 -0
- package/dist/agent/topic-view-batcher.d.ts +54 -0
- package/dist/agent/topic-view-batcher.js +115 -0
- package/dist/client.d.ts +421 -0
- package/dist/client.js +1428 -0
- package/dist/doc-reconcile.d.ts +100 -0
- package/dist/doc-reconcile.js +110 -0
- package/dist/doc-uri.d.ts +29 -0
- package/dist/doc-uri.js +55 -0
- package/dist/endpoints.d.ts +9 -0
- package/dist/endpoints.js +13 -0
- package/dist/jwt.d.ts +10 -0
- package/dist/jwt.js +51 -0
- package/dist/library-publisher.d.ts +52 -0
- package/dist/library-publisher.js +49 -0
- package/dist/merge3.d.ts +50 -0
- package/dist/merge3.js +280 -0
- package/dist/names.d.ts +6 -0
- package/dist/names.js +35 -0
- package/dist/shared/emoji-data.d.ts +22 -0
- package/dist/shared/emoji-data.js +8834 -0
- package/dist/shared/mentions.d.ts +6 -0
- package/dist/shared/mentions.js +32 -0
- package/dist/shared/rooms-protocol.d.ts +1183 -0
- package/dist/shared/rooms-protocol.js +160 -0
- package/dist/social-client.d.ts +361 -0
- package/dist/social-client.js +686 -0
- package/dist/social-types.d.ts +338 -0
- package/dist/social-types.js +1 -0
- package/dist/suggestion-attribution.d.ts +10 -0
- package/dist/suggestion-attribution.js +56 -0
- package/dist/topic-uri.d.ts +26 -0
- package/dist/topic-uri.js +40 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.js +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +2 -0
- package/dist/ws-client.d.ts +115 -0
- package/dist/ws-client.js +491 -0
- package/package.json +180 -0
- package/src/agent/armed-mode.ts +368 -0
- package/src/agent/clients/common.ts +91 -0
- package/src/agent/lane-draft.ts +47 -0
- package/src/agent/lane-prompts.ts +267 -0
- package/src/agent/library-context.ts +97 -0
- package/src/agent/library-model.ts +210 -0
- package/src/agent/room-context.ts +351 -0
- package/src/agent/sidebar-model.ts +235 -0
- package/src/agent/topic-inbox.ts +297 -0
- package/src/agent/topic-view-batcher.ts +134 -0
- package/src/client.ts +2331 -0
- package/src/doc-reconcile.ts +160 -0
- package/src/doc-uri.ts +83 -0
- package/src/endpoints.ts +14 -0
- package/src/jwt.ts +59 -0
- package/src/library-publisher.ts +93 -0
- package/src/merge3.ts +326 -0
- package/src/names.ts +44 -0
- package/src/shared/emoji-data.ts +8868 -0
- package/src/shared/mentions.ts +32 -0
- package/src/shared/rooms-protocol.ts +1339 -0
- package/src/social-client.ts +1287 -0
- package/src/social-types.ts +376 -0
- package/src/suggestion-attribution.ts +83 -0
- package/src/topic-uri.ts +64 -0
- package/src/types.ts +83 -0
- package/src/version.ts +2 -0
- package/src/ws-client.ts +611 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
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
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# @openmarket/rooms-client
|
|
2
|
+
|
|
3
|
+
The OM Rooms protocol client: wire types and frame schemas, the WebSocket client, the REST social client, endpoint resolution, and the chat view-models (sidebar, topics, lanes) shared by every OM Chat surface (TUI, GUI, bots).
|
|
4
|
+
|
|
5
|
+
## Browser-safety contract
|
|
6
|
+
|
|
7
|
+
Everything in this package runs unmodified in a browser: no `node:` or `bun:` imports, no filesystem or OS access, static imports only. Environment reads go through `envString()` in `endpoints.ts`, which returns `undefined` where `process` does not exist. The repo's boundary gate enforces this on every CI run; if you need daemon-side facilities (SQLite, vault, HTTP server), they live in the `om` CLI, not here.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
There is no root export; import the surface you need by subpath:
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { createRoomSpace } from "@openmarket/rooms-client/social-client";
|
|
15
|
+
import { RoomClientMessageType, SUPPORTED_ROOM_PROTOCOL_VERSION } from "@openmarket/rooms-client/shared/rooms-protocol";
|
|
16
|
+
import type { RoomSpaceSummary } from "@openmarket/rooms-client/social-types";
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Subpaths: `client`, `ws-client`, `social-client`, `social-types`, `library-publisher`, `doc-reconcile`, `topic-uri`, `doc-uri`, `endpoints`, `jwt`, `names`, `suggestion-attribution`, `merge3`, `types`, `version`, `agent/{armed-mode, lane-draft, lane-prompts, library-context, library-model, room-context, sidebar-model, topic-inbox, topic-view-batcher}`, `agent/clients/common`, `shared/{rooms-protocol, mentions, emoji-data}`.
|
|
20
|
+
|
|
21
|
+
Bun consumers resolve raw TypeScript via the `bun` export condition; Node and bundlers get compiled JS plus `.d.ts` from `dist/`.
|
|
22
|
+
|
|
23
|
+
## Versioning
|
|
24
|
+
|
|
25
|
+
The npm version is managed by hand: bump `package.json` here, `npm publish`, then bump the consumers' pins. The monorepo's release script deliberately skips this package's `package.json`. `src/version.ts` is the exception: it carries the wire/runner version and is auto-bumped with every `om` release so the WebSocket handshake tracks the daemon.
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { mentionsHandleExplicit as mentionsAgentExplicit, normalizeHandle } from "../shared/mentions.js";
|
|
2
|
+
import type { RoomLedgerEntry } from "../types.js";
|
|
3
|
+
export { mentionsAgentExplicit, normalizeHandle };
|
|
4
|
+
/**
|
|
5
|
+
* ARMED MODE rules of engagement (RoE), the guardrails for autonomous in-room
|
|
6
|
+
* posting under the user's identity. These are the named, easy-to-change
|
|
7
|
+
* defaults. The whole point of armed mode is that the agent posts on its OWN
|
|
8
|
+
* initiative as the user, so every gate here is a SAFETY limit, not a nicety:
|
|
9
|
+
* each one independently blocks an autonomous post, and a post happens only when
|
|
10
|
+
* ALL of them allow it (see `canPostAutonomously`).
|
|
11
|
+
*
|
|
12
|
+
* Defaults DISARMED: with nothing armed there is zero autonomous posting and the
|
|
13
|
+
* TUI behaves exactly as before. Arming is in-memory per session, never
|
|
14
|
+
* persisted (a fresh launch is always disarmed).
|
|
15
|
+
*/
|
|
16
|
+
export declare const ARMED_RULES: {
|
|
17
|
+
/** Minimum gap between two autonomous posts in the SAME room. */
|
|
18
|
+
readonly cooldownMs: 30000;
|
|
19
|
+
/** Max autonomous posts per room in any rolling 60-minute window. When hit
|
|
20
|
+
* the loop PAUSES (skips) until the window frees; it does NOT disarm. */
|
|
21
|
+
readonly hourlyCap: 10;
|
|
22
|
+
/** Rolling window the hourly cap is measured over. */
|
|
23
|
+
readonly hourlyWindowMs: number;
|
|
24
|
+
/** Max autonomous posts in a row with no intervening human message. When hit
|
|
25
|
+
* the loop PAUSES until a human speaks; it does NOT disarm. */
|
|
26
|
+
readonly chainLimit: 3;
|
|
27
|
+
/** Hard per-armed-session TOKEN budget across all armed turns in a room.
|
|
28
|
+
* Token spend is read from turn-reported usage when the provider supplies it.
|
|
29
|
+
* Exceeding this AUTO-DISARMS the room (this is the cost guard). */
|
|
30
|
+
readonly tokenBudget: 200000;
|
|
31
|
+
/** Fallback hard cap on autonomous posts per armed session, used as the cost
|
|
32
|
+
* guard when the provider reports no token usage (most providers don't on
|
|
33
|
+
* streaming turns). Exceeding this ALSO auto-disarms. So the cost guard is
|
|
34
|
+
* always effective: whichever of tokens / posts trips first disarms. */
|
|
35
|
+
readonly maxPostsPerSession: 40;
|
|
36
|
+
/** Settle window before deciding, so a burst of messages is judged once with
|
|
37
|
+
* full context (reuses the room-monitor settle idea). */
|
|
38
|
+
readonly settleMs: 2500;
|
|
39
|
+
/** Hard cap on an autonomous post's length. Longer drafts are skipped, not
|
|
40
|
+
* truncated (a half-sentence posted as the user is worse than silence). */
|
|
41
|
+
readonly maxPostChars: 600;
|
|
42
|
+
/** Consecutive turn/post errors that auto-disarm the room (kill switch). */
|
|
43
|
+
readonly maxConsecutiveErrors: 3;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Per-verb grants for armed mode. Some verbs are too consequential to ride the
|
|
47
|
+
* default armed toolset (which is otherwise market/research reads only): they
|
|
48
|
+
* are OFF unless the operator explicitly grants them for the session. `secrets_send`
|
|
49
|
+
* lets an armed agent seal-and-post autonomously; default DENY, since an
|
|
50
|
+
* untrusted @mention must never be able to make the agent exfiltrate a sealed
|
|
51
|
+
* value. Grants are in-memory per session, never persisted (a fresh launch
|
|
52
|
+
* grants nothing).
|
|
53
|
+
*/
|
|
54
|
+
export declare const ARMED_GRANTABLE_VERBS: readonly ["secrets_send"];
|
|
55
|
+
export type ArmedGrantableVerb = (typeof ARMED_GRANTABLE_VERBS)[number];
|
|
56
|
+
export declare function grantArmedVerb(verb: ArmedGrantableVerb): void;
|
|
57
|
+
export declare function revokeArmedVerb(verb: ArmedGrantableVerb): void;
|
|
58
|
+
export declare function isArmedVerbGranted(verb: ArmedGrantableVerb): boolean;
|
|
59
|
+
/** The extra verb names an armed turn may advertise given the current grants.
|
|
60
|
+
* Appended to `armedSafeToolNames()` at the armed call site. */
|
|
61
|
+
export declare function grantedArmedVerbNames(): string[];
|
|
62
|
+
/** Test/lifecycle helper: drop every grant (a fresh session grants nothing). */
|
|
63
|
+
export declare function clearArmedVerbGrants(): void;
|
|
64
|
+
/**
|
|
65
|
+
* Mutable per-room armed state. Lives only in memory and only while the room is
|
|
66
|
+
* armed; `disarm` drops it. Caps are tracked here and checked BEFORE every
|
|
67
|
+
* autonomous post.
|
|
68
|
+
*/
|
|
69
|
+
export interface ArmedRoomState {
|
|
70
|
+
/** Room id (e.g. "room:btc") this state guards. */
|
|
71
|
+
readonly roomId: string;
|
|
72
|
+
/** Timestamps (ms) of autonomous posts this session, used for the cooldown
|
|
73
|
+
* and the rolling hourly cap. */
|
|
74
|
+
postTimes: number[];
|
|
75
|
+
/** Autonomous posts in a row with no intervening human message. Reset to 0
|
|
76
|
+
* whenever a human speaks in the room. */
|
|
77
|
+
consecutiveAutoPosts: number;
|
|
78
|
+
/** Total autonomous posts this armed session (cost-guard fallback counter). */
|
|
79
|
+
postsThisSession: number;
|
|
80
|
+
/** Total tokens spent by armed turns this session (cost guard, when the
|
|
81
|
+
* provider reports usage; otherwise stays 0 and the post counter governs). */
|
|
82
|
+
tokensThisSession: number;
|
|
83
|
+
/** Consecutive turn/post errors; resets on any clean turn. At
|
|
84
|
+
* `maxConsecutiveErrors` the room auto-disarms. */
|
|
85
|
+
consecutiveErrors: number;
|
|
86
|
+
/** The highest room seq this loop has already evaluated, so re-entry doesn't
|
|
87
|
+
* re-trigger on already-seen messages. */
|
|
88
|
+
lastEvaluatedSeq: number;
|
|
89
|
+
}
|
|
90
|
+
/** A fresh armed state for a newly armed room. */
|
|
91
|
+
export declare function makeArmedRoomState(roomId: string, lastSeq?: number): ArmedRoomState;
|
|
92
|
+
/**
|
|
93
|
+
* Whether a single incoming entry is a qualifying TRIGGER: a NEW human POST in
|
|
94
|
+
* the room that @mentions the user's own handle. Agent posts, system entries,
|
|
95
|
+
* the user's own posts, and non-mentions never trigger. Pure.
|
|
96
|
+
*/
|
|
97
|
+
export declare function isTriggeringEntry(entry: RoomLedgerEntry, ownHandle: string, ownUserId: string): boolean;
|
|
98
|
+
/**
|
|
99
|
+
* The newest qualifying trigger among entries strictly newer than
|
|
100
|
+
* `afterSeq`, or null if none. Used by the loop to decide whether the latest
|
|
101
|
+
* batch of room messages contains a reason to act. Pure.
|
|
102
|
+
*/
|
|
103
|
+
export declare function findTrigger(entries: ReadonlyArray<RoomLedgerEntry>, ownHandle: string, ownUserId: string, afterSeq: number): RoomLedgerEntry | null;
|
|
104
|
+
/** Autonomous posts inside the rolling hourly window as of `now`. */
|
|
105
|
+
export declare function postsInWindow(state: ArmedRoomState, now?: number): number;
|
|
106
|
+
/** Remaining cooldown (ms) before the next autonomous post is allowed; 0 when
|
|
107
|
+
* free. */
|
|
108
|
+
export declare function cooldownRemaining(state: ArmedRoomState, now?: number): number;
|
|
109
|
+
export type CapBlock = "cooldown" | "hourly" | "chain" | "budget";
|
|
110
|
+
/**
|
|
111
|
+
* Which cap (if any) blocks an autonomous post RIGHT NOW, or null when every
|
|
112
|
+
* cap allows it. Order matters only for the reported reason; all are hard. Pure
|
|
113
|
+
* and exported so each gate is unit-testable in isolation.
|
|
114
|
+
*
|
|
115
|
+
* - cooldown: < cooldownMs since the last autonomous post.
|
|
116
|
+
* - hourly: >= hourlyCap autonomous posts in the rolling window (PAUSE).
|
|
117
|
+
* - chain: >= chainLimit autonomous posts with no human between (PAUSE).
|
|
118
|
+
* - budget: token spend OR post count over the session cost guard (DISARM).
|
|
119
|
+
*/
|
|
120
|
+
export declare function capBlocking(state: ArmedRoomState, now?: number): CapBlock | null;
|
|
121
|
+
/**
|
|
122
|
+
* Whether the session cost guard is spent: token spend over budget OR (the
|
|
123
|
+
* provider-agnostic fallback) post count over the per-session max. Either
|
|
124
|
+
* tripping AUTO-DISARMS the room. Pure.
|
|
125
|
+
*/
|
|
126
|
+
export declare function budgetExceeded(state: ArmedRoomState): boolean;
|
|
127
|
+
export type ContentVerdict = {
|
|
128
|
+
ok: true;
|
|
129
|
+
text: string;
|
|
130
|
+
} | {
|
|
131
|
+
ok: false;
|
|
132
|
+
reason: string;
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* CONTENT GUARD applied to a candidate autonomous post BEFORE it is sent.
|
|
136
|
+
* Rejects: empty/whitespace, anything matching a secret/credential pattern,
|
|
137
|
+
* anything containing a link/URL, and anything over the length cap. On pass,
|
|
138
|
+
* returns the trimmed text to post. Pure and exported for unit testing: this
|
|
139
|
+
* is the last line of defense before text goes out as the user.
|
|
140
|
+
*/
|
|
141
|
+
export declare function guardAutonomousContent(raw: string): ContentVerdict;
|
|
142
|
+
export type PostDecision = {
|
|
143
|
+
post: true;
|
|
144
|
+
text: string;
|
|
145
|
+
} | {
|
|
146
|
+
post: false;
|
|
147
|
+
reason: string;
|
|
148
|
+
disarm: boolean;
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* THE single gate in front of every autonomous post. Returns `{ post: true }`
|
|
152
|
+
* ONLY when ALL hold:
|
|
153
|
+
* 1. the room is armed (the caller only invokes this for an armed room, and
|
|
154
|
+
* passes its live state),
|
|
155
|
+
* 2. there is a qualifying trigger (own-handle @mention in a new human msg),
|
|
156
|
+
* 3. every cap allows it (cooldown AND hourly AND chain AND budget), and
|
|
157
|
+
* 4. the content guard passes.
|
|
158
|
+
* Any failure returns `{ post: false }` with a reason; `disarm` is true only
|
|
159
|
+
* when the failure is the cost-guard (budget), the one cap that auto-disarms
|
|
160
|
+
* rather than pausing. Pure, so the full && chain is unit-testable end to end
|
|
161
|
+
* without a TUI or network.
|
|
162
|
+
*/
|
|
163
|
+
export declare function canPostAutonomously(input: {
|
|
164
|
+
state: ArmedRoomState;
|
|
165
|
+
trigger: RoomLedgerEntry | null;
|
|
166
|
+
candidate: string;
|
|
167
|
+
now?: number;
|
|
168
|
+
}): PostDecision;
|
|
169
|
+
/**
|
|
170
|
+
* Record a completed autonomous post against the caps: stamp the time (cooldown
|
|
171
|
+
* + hourly), bump the consecutive-chain and session counters. Call AFTER a
|
|
172
|
+
* successful `post()`. Mutates `state`.
|
|
173
|
+
*/
|
|
174
|
+
export declare function recordAutonomousPost(state: ArmedRoomState, now?: number): void;
|
|
175
|
+
/** Record token spend from an armed turn against the session cost guard. Reads
|
|
176
|
+
* `totalTokens` from a turn's `usage` (pi-ai shape) when present; a no-op when
|
|
177
|
+
* the provider reported nothing (the post counter is the fallback guard). */
|
|
178
|
+
export declare function recordArmedTurnUsage(state: ArmedRoomState, usage: Record<string, unknown> | undefined): void;
|
|
179
|
+
/** A human (non-agent) POST that is NOT our own resets the consecutive-chain
|
|
180
|
+
* counter, freeing a chain-limit pause. Pure. */
|
|
181
|
+
export declare function isHumanResetEntry(entry: RoomLedgerEntry, ownHandle: string, ownUserId: string): boolean;
|
|
182
|
+
/** Note a turn/post error against the kill switch; returns true once the room
|
|
183
|
+
* should auto-disarm (>= maxConsecutiveErrors in a row). Mutates `state`. */
|
|
184
|
+
export declare function noteArmedError(state: ArmedRoomState): boolean;
|
|
185
|
+
/** Reset the consecutive-error counter after a clean armed turn. */
|
|
186
|
+
export declare function clearArmedErrors(state: ArmedRoomState): void;
|
|
187
|
+
export declare function countConsecutiveAgentPosts(entries: RoomLedgerEntry[]): number;
|