@segmentstream/agent 0.0.0-stage → 0.1.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.
Files changed (52) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +2 -0
  3. package/README.md +178 -2
  4. package/dist/extension/_manifest.json +13 -0
  5. package/dist/extension/channels/telegram.d.ts +6 -0
  6. package/dist/extension/channels/telegram.mjs +15 -0
  7. package/dist/extension/config.d.ts +99 -0
  8. package/dist/extension/config.mjs +144 -0
  9. package/dist/extension/connections/ontology.d.ts +7 -0
  10. package/dist/extension/connections/ontology.mjs +11 -0
  11. package/dist/extension/extension.d.ts +19 -0
  12. package/dist/extension/extension.mjs +15 -0
  13. package/dist/extension/instructions.md +13 -0
  14. package/dist/extension/lib/connection-proxy.d.ts +57 -0
  15. package/dist/extension/lib/connection-proxy.mjs +113 -0
  16. package/dist/extension/lib/environment.d.ts +30 -0
  17. package/dist/extension/lib/environment.mjs +46 -0
  18. package/dist/extension/lib/identities.d.ts +65 -0
  19. package/dist/extension/lib/identities.mjs +133 -0
  20. package/dist/extension/lib/ontology-connection.d.ts +36 -0
  21. package/dist/extension/lib/ontology-connection.mjs +48 -0
  22. package/dist/extension/lib/runtime-token.d.ts +17 -0
  23. package/dist/extension/lib/runtime-token.mjs +31 -0
  24. package/dist/extension/lib/telegram/adapter.d.ts +29 -0
  25. package/dist/extension/lib/telegram/adapter.mjs +115 -0
  26. package/dist/extension/lib/telegram/bot.d.ts +4 -0
  27. package/dist/extension/lib/telegram/bot.mjs +45 -0
  28. package/dist/extension/lib/telegram/inbound-request.d.ts +22 -0
  29. package/dist/extension/lib/telegram/inbound-request.mjs +37 -0
  30. package/dist/extension/lib/telegram/inbound.d.ts +35 -0
  31. package/dist/extension/lib/telegram/inbound.mjs +117 -0
  32. package/dist/extension/lib/telegram/observed.d.ts +32 -0
  33. package/dist/extension/lib/telegram/observed.mjs +47 -0
  34. package/dist/extension/lib/telegram/principal.d.ts +20 -0
  35. package/dist/extension/lib/telegram/principal.mjs +40 -0
  36. package/dist/extension/lib/telegram/proxy-fetch.d.ts +28 -0
  37. package/dist/extension/lib/telegram/proxy-fetch.mjs +69 -0
  38. package/dist/extension/lib/telegram/router.d.ts +69 -0
  39. package/dist/extension/lib/telegram/router.mjs +64 -0
  40. package/dist/extension/lib/telegram/silent.d.ts +9 -0
  41. package/dist/extension/lib/telegram/silent.mjs +15 -0
  42. package/dist/extension/lib/telegram/voice.d.ts +52 -0
  43. package/dist/extension/lib/telegram/voice.mjs +115 -0
  44. package/dist/extension/lib/telegram/webhook.d.ts +13 -0
  45. package/dist/extension/lib/telegram/webhook.mjs +23 -0
  46. package/dist/extension/model.d.ts +29 -0
  47. package/dist/extension/model.mjs +23 -0
  48. package/dist/index.d.ts +4 -0
  49. package/dist/index.mjs +8 -0
  50. package/dist/tools/index.d.ts +2 -0
  51. package/dist/tools/index.mjs +7 -0
  52. package/package.json +76 -4
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/NOTICE ADDED
@@ -0,0 +1,2 @@
1
+ SegmentStream Agent SDK
2
+ Copyright 2026 SegmentStream
package/README.md CHANGED
@@ -1,3 +1,179 @@
1
- # Temporary Holding Version
1
+ # @segmentstream/agent
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The SegmentStream extension for a workspace's agent on [eve](https://www.npmjs.com/package/eve).
4
+ It gives the agent the workspace's ontology as tools, acting as the member who is talking to it,
5
+ and puts it behind the workspace's Telegram bot without a bot token in the deployment: Telegram
6
+ calls go through the workspace's connection, unknown senders pair with a member first, voice
7
+ messages become text, and group chats are answered only when the agent is addressed or asked for
8
+ something it does.
9
+
10
+ The package is built against one eve version, `0.76.3`, and the workspace's `agent/` pins the same
11
+ one. eve and the package move together.
12
+
13
+ ## Install
14
+
15
+ ```sh
16
+ npm install @segmentstream/agent eve@0.76.3
17
+ ```
18
+
19
+ ## Set up
20
+
21
+ The workspace's `agent/` directory is an eve app in eve's flat layout, a package of its own like
22
+ `ontology/`:
23
+
24
+ ```text
25
+ agent/
26
+ ├── package.json # eve and @segmentstream/agent, both pinned; "build": "eve build"
27
+ ├── segmentstream.json # what the extension mounts, and what the platform reads at deploy
28
+ ├── agent.ts # model, reasoning, limits
29
+ ├── instructions.md # who the company is, how the agent behaves
30
+ └── extensions/
31
+ └── segmentstream.ts # mounts this package with segmentstream.json
32
+ ```
33
+
34
+ **`extensions/segmentstream.ts`** mounts the extension. The file name is the mount's namespace, so
35
+ every contribution is named `segmentstream__…`:
36
+
37
+ ```ts
38
+ import { segmentstream } from "@segmentstream/agent/extension";
39
+
40
+ import config from "../segmentstream.json";
41
+
42
+ export default segmentstream(config);
43
+ ```
44
+
45
+ **`agent.ts`** chooses the model once per session:
46
+
47
+ ```ts
48
+ import { defineAgent } from "eve";
49
+ import { segmentstream } from "@segmentstream/agent";
50
+
51
+ export default defineAgent({
52
+ defaultTools: false,
53
+ model: segmentstream.model({
54
+ default: "spacexai/grok-4.7",
55
+ byRole: { finance: "anthropic/claude-opus-5.5" },
56
+ preview: "google/gemini-flash",
57
+ }),
58
+ reasoning: "medium",
59
+ limits: { maxTokenCostUsdPerSession: 2 },
60
+ });
61
+ ```
62
+
63
+ `segmentstream.model()` resolves on `session.started`. On a preview deployment it returns `preview`
64
+ when set. Otherwise it returns the model of the first `byRole` entry whose role the member holds, in
65
+ the order written, and `default` when none matches. The roles come from the member's pairing, not
66
+ from the message. The model is never switched mid-session, which keeps the provider's prompt cache.
67
+ A group shares one session, so its model follows the member who started it; each member's rights
68
+ are still their own, because the ontology connection acts as the member of the current turn.
69
+
70
+ Both entry points export the same handle: `@segmentstream/agent` and
71
+ `@segmentstream/agent/extension`.
72
+
73
+ ## `segmentstream.json`
74
+
75
+ ```json
76
+ {
77
+ "channels": {
78
+ "telegram": { "connection": "telegram", "policy": "smart" }
79
+ }
80
+ }
81
+ ```
82
+
83
+ | Field | Default | Meaning |
84
+ | ------------------------------ | --------------------- | ----------------------------------------------------------------------------------------------- |
85
+ | `channels.telegram.connection` | none | The Connect key whose credential is the bot token. Without `channels.telegram`, no Telegram. |
86
+ | `channels.telegram.policy` | `"smart"` | Group messages that do not address the bot: `smart` asks the decision model, `mention` observes |
87
+ | `models.stt` | `"spacexai/grok-stt"` | The AI Gateway transcription model for voice messages; `false` leaves them untranscribed |
88
+ | `models.decision` | `"typesafe-ai/jev"` | The AI Gateway decision model of the inbound router |
89
+ | `ontology.connection` | `true` | Whether the agent reaches the ontology over MCP |
90
+
91
+ An unknown field or an invalid value fails the mount with `SegmentStreamAgentConfigError`, naming
92
+ each path. `manifestOf(config)` returns the normalized configuration, defaults applied, for the
93
+ platform's deployment manifest.
94
+
95
+ ## What the extension contributes
96
+
97
+ | Name | Slot | What it does |
98
+ | ------------------------- | -------------- | --------------------------------------------------------------------------------------------------------------- |
99
+ | `segmentstream__ontology` | `connections` | The app's `/mcp`, resolved per turn for the turn's member. No member, no connection. |
100
+ | `segmentstream__telegram` | `channels` | `POST /eve/v1/telegram`: Telegram through the connection, with pairing, routing and voice. |
101
+ | platform rules | `instructions` | Changes go through actions; `describe` gives the catalog; tools are already narrowed; when to answer `[SILENT]` |
102
+
103
+ ### The ontology
104
+
105
+ The connection calls `{origin}/mcp` with the deployment's Vercel OIDC token as the bearer and the
106
+ member's id in `X-SegmentStream-Act-As`. The ontology service verifies the token, refuses a member
107
+ who is inactive or has no live pairing, lists only the tools the member may run and records the
108
+ member in history. A turn whose principal carries no `memberId`, such as an unpaired caller,
109
+ gets no ontology connection at all. Each member gets their own connection instance, so members who
110
+ share a group chat's session never share a client.
111
+
112
+ ### Telegram
113
+
114
+ - **Credentials.** eve's Telegram channel puts the bot token in the URL path. The adapter gives it a
115
+ placeholder token and an origin that does not resolve, and its `fetch` sends each method call to
116
+ the connection's `bot` API and each download to its `file` API through SegmentStream's connection
117
+ proxy. The token stays in SegmentStream.
118
+ - **Webhook.** A webhook is accepted only with `X-Telegram-Bot-Api-Secret-Token` equal to
119
+ `SEGMENTSTREAM_AGENT_WEBHOOK_SECRET`, compared in constant time. The platform generates the
120
+ secret and registers the webhook after each production deployment.
121
+ - **Production only.** Outside `VERCEL_ENV=production` the route answers 200 and does nothing, so a
122
+ preview never answers a real chat. Without `channels.telegram` it answers 404.
123
+ - **Pairing.** Messages from bots and channel posts are dropped. The sender's Telegram account is
124
+ looked up with the ontology service on every message, so a revocation stops at once. An unknown
125
+ sender who writes privately gets a link to `/agent/connect?code=…`, valid for ten minutes. In a
126
+ group, the agent only asks an unknown sender to message it privately, because anyone in the group
127
+ could open a link posted there. A revoked pairing or an inactive member gets a short refusal.
128
+ - **Who the agent is.** A paired sender's turn runs with the principal id `telegram:<user>`
129
+ (`telegram:<chat>:<user>` in groups) and the attributes `memberId`, `memberName`, `roles`,
130
+ `chatId`, `chatType` and `username`.
131
+ - **Routing.** A private chat, a mention of the bot, a reply to it and a command are always
132
+ answered. Under `smart`, any other group message is put to one `decide` question on the decision
133
+ model, with the agent's description and the chat's recent observed messages. A message that is not
134
+ answered joins a ring of the chat's last 30 observed messages. The next answered message carries
135
+ the ring into its turn as context. A failed decision observes.
136
+ - **Voice.** Voice messages, audio files and video notes are downloaded through the connection and
137
+ transcribed with `models.stt` through AI Gateway. The transcript becomes the message, with a note
138
+ such as `[voice message, 12 s]` in context. A file over the proxy's 2 MiB limit, or a failed
139
+ transcription, reaches the agent as a note saying so. Photos and documents up to 2 MiB reach the
140
+ agent as eve's file parts.
141
+ - **Silence.** When the model answers a routed message with exactly `[SILENT]` (or `NO_REPLY`), in
142
+ any case, nothing is sent to the chat. The turn stays in the session.
143
+
144
+ The observed ring lives in process memory, per chat and forum topic, because eve's durable
145
+ `defineState` is session state and an observed message has no session. A new function instance
146
+ starts with an empty ring.
147
+
148
+ ## Local development
149
+
150
+ `eve dev` in `agent/` runs the agent locally. The Telegram channel stays silent outside production.
151
+ To reach a local ontology service, set `SEGMENTSTREAM_AGENT_ONTOLOGY_URL=http://localhost:3000`.
152
+ `vercel env pull` writes a `VERCEL_OIDC_TOKEN` for the token. The ontology service admits only
153
+ production tokens of the workspace's project, though, so a local run gets the ontology only from a
154
+ local ontology service configured to accept that token.
155
+
156
+ Building the package needs Node.js 24, as eve does: `npm run build` runs `eve extension build`,
157
+ which writes the agent-shaped `dist/extension` tree, its declarations and eve's compatibility
158
+ manifest.
159
+
160
+ ## Environment
161
+
162
+ The platform sets every variable on the workspace's Vercel project. None of them is a model key or
163
+ a provider token.
164
+
165
+ | Variable | Used for |
166
+ | ------------------------------------ | ------------------------------------------------------------------------------- |
167
+ | `VERCEL_PROJECT_PRODUCTION_URL` | The app's origin: `/mcp`, `/api/ontology/agent/*` and the `/agent/connect` link |
168
+ | `SEGMENTSTREAM_AGENT_ONTOLOGY_URL` | Overrides that origin in local development |
169
+ | `SEGMENTSTREAM_URL` | backend-next, where the connection proxy answers |
170
+ | `SEGMENTSTREAM_WORKSPACE_ID` | The workspace in the proxy's path |
171
+ | `SEGMENTSTREAM_ORGANIZATION_ID` | The tenant the proxy selects |
172
+ | `SEGMENTSTREAM_AGENT_WEBHOOK_SECRET` | The Telegram webhook secret; the only secret |
173
+ | `VERCEL_ENV` | Channels run only in `production`; `preview` selects the preview model |
174
+ | `VERCEL_OIDC_TOKEN` | The runtime token outside a request; Vercel sends it on each request otherwise |
175
+ | `AI_GATEWAY_API_KEY` | Optional. AI Gateway uses the OIDC token when it is unset |
176
+
177
+ ## License
178
+
179
+ Apache-2.0
@@ -0,0 +1,13 @@
1
+ {
2
+ "kind": "eve-extension",
3
+ "formatVersion": 2,
4
+ "builtWithEve": "0.76.3",
5
+ "requires": {
6
+ "extension": 1,
7
+ "tool": 85,
8
+ "channel": 58,
9
+ "connection": 46,
10
+ "instructions": 2,
11
+ "config": 1
12
+ }
13
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * `segmentstream__telegram` at `POST /eve/v1/telegram`: the workspace's Telegram bot, reached
3
+ * through the connection named in `channels.telegram`. Without that setting the route answers 404.
4
+ */
5
+ declare const _default: import("eve/channels/telegram").TelegramChannel;
6
+ export default _default;
@@ -0,0 +1,15 @@
1
+ import { fileURLToPath as __eveFileURLToPath } from "node:url";
2
+ import { dirname as __eveDirname } from "node:path";
3
+ import { createRequire as __eveCreateRequire } from "node:module";
4
+ const __filename = __eveFileURLToPath(import.meta.url);
5
+ __eveDirname(__filename);
6
+ __eveCreateRequire(import.meta.url);
7
+ import segmentstream from "../extension.mjs";
8
+ import { segmentstreamTelegram } from "../lib/telegram/adapter.mjs";
9
+ import { decide } from "eve/ai";
10
+ var telegram_default = segmentstreamTelegram({
11
+ settings: () => segmentstream.config.channels.telegram,
12
+ models: () => segmentstream.config.models,
13
+ decide: (options) => decide(options)
14
+ });
15
+ export { telegram_default as default };
@@ -0,0 +1,99 @@
1
+ /**
2
+ * The extension's configuration: `agent/segmentstream.json`, mounted by
3
+ * `agent/extensions/segmentstream.ts` and read by the platform at deploy.
4
+ *
5
+ * eve validates a mount's configuration with a Standard Schema. The schema below is written by
6
+ * hand, so the package adds no second schema library next to the Effect Schema the rest of the
7
+ * repository uses.
8
+ */
9
+ export declare const TELEGRAM_POLICIES: readonly ["mention", "smart"];
10
+ /**
11
+ * How the Telegram channel treats group messages that do not address the bot: `smart` asks the
12
+ * decision model whether to answer, `mention` only observes them.
13
+ */
14
+ export type TelegramPolicy = (typeof TELEGRAM_POLICIES)[number];
15
+ /** The speech-to-text model voice messages are transcribed with, in the AI Gateway catalog. */
16
+ export declare const DEFAULT_STT_MODEL = "spacexai/grok-stt";
17
+ /** The decision model the inbound router asks; eve's `decide` default. */
18
+ export declare const DEFAULT_DECISION_MODEL = "typesafe-ai/jev";
19
+ /**
20
+ * `agent/segmentstream.json` as authored. A JSON import widens string literals to `string` and
21
+ * `false` to `boolean`, so the accepted types are wider than the values validation allows.
22
+ */
23
+ export interface SegmentStreamAgentConfigInput {
24
+ readonly channels?: {
25
+ readonly telegram?: {
26
+ /** The Connect key whose credential is the bot token, such as `telegram`. */
27
+ readonly connection: string;
28
+ /** `smart` (default) or `mention`. */
29
+ readonly policy?: string;
30
+ };
31
+ };
32
+ readonly models?: {
33
+ /** A Gateway transcription model, or `false` to leave voice messages untranscribed. */
34
+ readonly stt?: string | boolean;
35
+ /** The Gateway decision model of the inbound router. */
36
+ readonly decision?: string;
37
+ };
38
+ readonly ontology?: {
39
+ /** Whether the agent reaches the ontology over MCP. On by default. */
40
+ readonly connection?: boolean;
41
+ };
42
+ }
43
+ export interface TelegramSettings {
44
+ readonly connection: string;
45
+ readonly policy: TelegramPolicy;
46
+ }
47
+ /** The validated configuration with defaults applied. It stays JSON-serializable. */
48
+ export interface SegmentStreamAgentConfig {
49
+ readonly channels: {
50
+ readonly telegram: TelegramSettings | null;
51
+ };
52
+ readonly models: {
53
+ readonly stt: string | false;
54
+ readonly decision: string;
55
+ };
56
+ readonly ontology: {
57
+ readonly connection: boolean;
58
+ };
59
+ }
60
+ /** One validation failure, in Standard Schema's issue shape. */
61
+ export interface ConfigIssue {
62
+ readonly message: string;
63
+ readonly path: ReadonlyArray<string>;
64
+ }
65
+ type Validation = {
66
+ readonly value: SegmentStreamAgentConfig;
67
+ readonly issues?: undefined;
68
+ } | {
69
+ readonly issues: ReadonlyArray<ConfigIssue>;
70
+ };
71
+ /** `agent/segmentstream.json` is invalid. The message lists every issue with its path. */
72
+ export declare class SegmentStreamAgentConfigError extends Error {
73
+ readonly issues: ReadonlyArray<ConfigIssue>;
74
+ readonly name = "SegmentStreamAgentConfigError";
75
+ constructor(issues: ReadonlyArray<ConfigIssue>);
76
+ }
77
+ /** Validates the authored configuration and applies the defaults. */
78
+ export declare function validateConfig(input: unknown): Validation;
79
+ /**
80
+ * The Standard Schema eve validates the mount with. `types` exists only for type inference, as the
81
+ * Standard Schema specification allows.
82
+ */
83
+ export declare const configSchema: {
84
+ readonly "~standard": {
85
+ readonly version: 1;
86
+ readonly vendor: "segmentstream";
87
+ readonly validate: typeof validateConfig;
88
+ readonly types: {
89
+ readonly input: SegmentStreamAgentConfigInput;
90
+ readonly output: SegmentStreamAgentConfig;
91
+ };
92
+ };
93
+ };
94
+ /**
95
+ * The normalized configuration a mount declares, for the deployment manifest of later phases.
96
+ * Throws {@link SegmentStreamAgentConfigError} when the configuration is invalid.
97
+ */
98
+ export declare function manifestOf(config: SegmentStreamAgentConfigInput): SegmentStreamAgentConfig;
99
+ export {};
@@ -0,0 +1,144 @@
1
+ import { fileURLToPath as __eveFileURLToPath } from "node:url";
2
+ import { dirname as __eveDirname } from "node:path";
3
+ import { createRequire as __eveCreateRequire } from "node:module";
4
+ const __filename = __eveFileURLToPath(import.meta.url);
5
+ __eveDirname(__filename);
6
+ __eveCreateRequire(import.meta.url);
7
+ const CONNECTION_KEY = /^[a-z][a-z0-9_]{0,63}$/;
8
+ const TELEGRAM_POLICIES = ["mention", "smart"];
9
+ const DEFAULT_STT_MODEL = "spacexai/grok-stt";
10
+ const DEFAULT_DECISION_MODEL = "typesafe-ai/jev";
11
+ var SegmentStreamAgentConfigError = class extends Error {
12
+ issues;
13
+ name = "SegmentStreamAgentConfigError";
14
+ constructor(issues) {
15
+ super(`agent/segmentstream.json is invalid: ${issues.map((issue) => issue.path.length === 0 ? issue.message : `${issue.path.join(".")}: ${issue.message}`).join("; ")}`);
16
+ this.issues = issues;
17
+ }
18
+ };
19
+ function isRecord(value) {
20
+ return typeof value === "object" && value !== null && !Array.isArray(value);
21
+ }
22
+ function section(input) {
23
+ if (input.value === void 0) return;
24
+ if (!isRecord(input.value)) {
25
+ input.issues.push({
26
+ message: "must be an object",
27
+ path: input.path
28
+ });
29
+ return;
30
+ }
31
+ for (const key of Object.keys(input.value)) if (!input.allowed.includes(key)) input.issues.push({
32
+ message: "is not a known setting",
33
+ path: [...input.path, key]
34
+ });
35
+ return input.value;
36
+ }
37
+ function isTelegramPolicy(value) {
38
+ return TELEGRAM_POLICIES.some((policy) => policy === value);
39
+ }
40
+ function telegramSettings(value, issues) {
41
+ const path = ["channels", "telegram"];
42
+ const telegram = section({
43
+ value,
44
+ path,
45
+ allowed: ["connection", "policy"],
46
+ issues
47
+ });
48
+ if (telegram === void 0) return null;
49
+ const connection = telegram.connection;
50
+ const policy = telegram.policy ?? "smart";
51
+ if (typeof connection !== "string" || !CONNECTION_KEY.test(connection)) issues.push({
52
+ message: "must be a connection key such as telegram",
53
+ path: [...path, "connection"]
54
+ });
55
+ if (!isTelegramPolicy(policy)) issues.push({
56
+ message: "must be \"smart\" or \"mention\"",
57
+ path: [...path, "policy"]
58
+ });
59
+ return typeof connection === "string" && isTelegramPolicy(policy) ? {
60
+ connection,
61
+ policy
62
+ } : null;
63
+ }
64
+ function modelId(input) {
65
+ if (input.value === void 0) return input.fallback;
66
+ if (typeof input.value !== "string" || input.value === "" || input.value !== input.value.trim()) {
67
+ input.issues.push({
68
+ message: "must be a Gateway model id such as provider/model",
69
+ path: input.path
70
+ });
71
+ return input.fallback;
72
+ }
73
+ return input.value;
74
+ }
75
+ function validateConfig(input) {
76
+ const issues = [];
77
+ const root = section({
78
+ value: input ?? {},
79
+ path: [],
80
+ allowed: [
81
+ "channels",
82
+ "models",
83
+ "ontology"
84
+ ],
85
+ issues
86
+ });
87
+ const channels = section({
88
+ value: root?.channels,
89
+ path: ["channels"],
90
+ allowed: ["telegram"],
91
+ issues
92
+ });
93
+ const models = section({
94
+ value: root?.models,
95
+ path: ["models"],
96
+ allowed: ["stt", "decision"],
97
+ issues
98
+ });
99
+ const ontology = section({
100
+ value: root?.ontology,
101
+ path: ["ontology"],
102
+ allowed: ["connection"],
103
+ issues
104
+ });
105
+ const telegram = telegramSettings(channels?.telegram, issues);
106
+ const stt = models?.stt === false ? false : modelId({
107
+ value: models?.stt,
108
+ fallback: DEFAULT_STT_MODEL,
109
+ path: ["models", "stt"],
110
+ issues
111
+ });
112
+ const decision = modelId({
113
+ value: models?.decision,
114
+ fallback: DEFAULT_DECISION_MODEL,
115
+ path: ["models", "decision"],
116
+ issues
117
+ });
118
+ const connection = ontology?.connection ?? true;
119
+ if (typeof connection !== "boolean") issues.push({
120
+ message: "must be true or false",
121
+ path: ["ontology", "connection"]
122
+ });
123
+ if (issues.length > 0) return { issues };
124
+ return { value: {
125
+ channels: { telegram },
126
+ models: {
127
+ stt,
128
+ decision
129
+ },
130
+ ontology: { connection: connection === true }
131
+ } };
132
+ }
133
+ const configSchema = { "~standard": {
134
+ version: 1,
135
+ vendor: "segmentstream",
136
+ validate: validateConfig,
137
+ types: void 0
138
+ } };
139
+ function manifestOf(config) {
140
+ const validation = validateConfig(config);
141
+ if (validation.issues !== void 0) throw new SegmentStreamAgentConfigError(validation.issues);
142
+ return validation.value;
143
+ }
144
+ export { DEFAULT_DECISION_MODEL, DEFAULT_STT_MODEL, SegmentStreamAgentConfigError, TELEGRAM_POLICIES, configSchema, manifestOf, validateConfig };