@loomwork/plugin-conversation-sse 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.
- package/LICENSE +202 -0
- package/NOTICE +8 -0
- package/README.md +39 -2
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/server.d.ts +106 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +669 -0
- package/dist/server.js.map +1 -0
- package/dist/sse.d.ts +29 -0
- package/dist/sse.d.ts.map +1 -0
- package/dist/sse.js +107 -0
- package/dist/sse.js.map +1 -0
- package/package.json +61 -3
- package/src/index.ts +7 -0
- package/src/server.ts +806 -0
- package/src/sse.ts +106 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
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.
|
|
202
|
+
|
package/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,40 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @loomwork/plugin-conversation-sse — the end-user gateway for `@loomwork/conversation`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An authenticated HTTP + Server-Sent-Events edge: a browser (or any client) starts a conversation, sends turns, and watches the durable messages and the live reply tokens arrive, resuming after a drop from where it left off.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { createConversationSseServer } from "@loomwork/plugin-conversation-sse";
|
|
7
|
+
|
|
8
|
+
const server = createConversationSseServer({
|
|
9
|
+
conversations, hub, eventStore,
|
|
10
|
+
authenticate: (req) => verifyBearer(req.headers.authorization), // -> { actor, tenant? } | undefined
|
|
11
|
+
allowedOrigins: ["https://app.example.com"],
|
|
12
|
+
});
|
|
13
|
+
await server.start(); // 127.0.0.1 by default
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
POST /conversations -> 201 { conversationId } (the server mints the id)
|
|
18
|
+
POST /conversations/:id/turns { text, messageId?, editOf? } -> 202 (a barge-in if a turn is running; editOf = ord of your earlier turn)
|
|
19
|
+
POST /conversations/:id/close
|
|
20
|
+
GET /conversations/:id -> status
|
|
21
|
+
GET /conversations/:id/history ?limit&cursor&direction=forward|backward (default forward)
|
|
22
|
+
GET /conversations/:id/events text/event-stream; Last-Event-ID or ?cursor resumes
|
|
23
|
+
GET /conversations/:id/reasoning ?cursor=<the reply's history cursor> a reply's durable model reasoning (opt-in, see below)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**History direction.** `direction` defaults to `forward`: oldest first, starting at the beginning of the log (or after `cursor`), and `done` is true at the live tip. To load the newest messages first (the usual chat opening), request `?direction=backward&limit=N`: you get the latest N, newest first, and `nextCursor` continues toward older ones (`done` is true at the start). A cursor continues in the direction that produced it; any other value of `direction` is a `400`. A client that renders the page must order it to match (for example loom-ui `ChatFeed.applyHistory` takes a matching direction argument).
|
|
27
|
+
|
|
28
|
+
SSE events: `status` (first), `partial` (the reply in progress), `message` (durable; its SSE `id` is the history cursor), `delta` / `reset` (live), `closed`, `reconnect`, `error`; with `reasoning` on, also `reasoning` and `reasoning-partial`. Render user text as **text**: it is untrusted.
|
|
29
|
+
|
|
30
|
+
**Reasoning (opt-in).** `reasoning` is off by default. `reasoning: true` (or `{ live: true }`) streams the `reasoning` / `reasoning-partial` SSE events; `reasoning: { store }` also serves a reply's durable reasoning at `GET /conversations/:id/reasoning?cursor=` from the `ReasoningStore` the model effect captured into. Only the turn's asker and the conversation's owner receive it (in a shared conversation never another participant); anyone else gets the same `404` as a missing conversation. It is model-derived text, so render it as **text** too. See [ADR 0133 D6](../../docs/adr/0133-model-reasoning-audit-capture.md).
|
|
31
|
+
|
|
32
|
+
## Security model
|
|
33
|
+
|
|
34
|
+
- Authentication is required to *create* the server (`insecure: true` is the explicit, warned opt-out; refused when the runtime is strict, which is the default derived from it). Loopback by default; an insecure server also answers only loopback `Host` names. A runtime with no fail-closed execution authorizer is refused unless `allowNoRuntimeAuthz`.
|
|
35
|
+
- Authorization is `@loomwork/conversation`'s, per conversation: OWNER-ONLY by default, or the participant set of a shared conversation (which also gets per-viewer filtering of history, the stream and live deltas, and `/participants` routes). A conversation the caller may not touch and one that does not exist are the same `404`, on every route, and authorization runs before any limit.
|
|
36
|
+
- A stream is keyed by one conversation; a cursor is a position inside that conversation's own log.
|
|
37
|
+
- `Origin` must be listed in `allowedOrigins` (`Host` never proves same-origin); CORS headers ride errors too; JSON-only bodies; `nosniff`; POSTs are rate-limited per principal; request/header timeouts are set.
|
|
38
|
+
- Limits: connections (total and per principal), subscribers per conversation, body size, stream lifetime, and per-connection pending bytes (a slow client's deltas are coalesced, then the client is closed and resumes from the log). Open streams re-authenticate every `reauthMs`.
|
|
39
|
+
|
|
40
|
+
See [ADR 0122 D6](../../docs/adr/0122-conversation-layer-streaming-transport-and-token-budgeting.md).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { REASONING_RESPONSE_MAX_BYTES, REASONING_RESPONSE_MAX_PARTS, createConversationSseServer, } from "./server";
|
|
2
|
+
export type { ConversationSseOptions, ConversationSseServer } from "./server";
|
|
3
|
+
export { SseSink, frame } from "./sse";
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,4BAA4B,EAC5B,2BAA2B,GAC5B,MAAM,UAAU,CAAC;AAClB,YAAY,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAC9E,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.frame = exports.SseSink = exports.createConversationSseServer = exports.REASONING_RESPONSE_MAX_PARTS = exports.REASONING_RESPONSE_MAX_BYTES = void 0;
|
|
4
|
+
var server_1 = require("./server");
|
|
5
|
+
Object.defineProperty(exports, "REASONING_RESPONSE_MAX_BYTES", { enumerable: true, get: function () { return server_1.REASONING_RESPONSE_MAX_BYTES; } });
|
|
6
|
+
Object.defineProperty(exports, "REASONING_RESPONSE_MAX_PARTS", { enumerable: true, get: function () { return server_1.REASONING_RESPONSE_MAX_PARTS; } });
|
|
7
|
+
Object.defineProperty(exports, "createConversationSseServer", { enumerable: true, get: function () { return server_1.createConversationSseServer; } });
|
|
8
|
+
var sse_1 = require("./sse");
|
|
9
|
+
Object.defineProperty(exports, "SseSink", { enumerable: true, get: function () { return sse_1.SseSink; } });
|
|
10
|
+
Object.defineProperty(exports, "frame", { enumerable: true, get: function () { return sse_1.frame; } });
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAIkB;AAHhB,sHAAA,4BAA4B,OAAA;AAC5B,sHAAA,4BAA4B,OAAA;AAC5B,qHAAA,2BAA2B,OAAA;AAG7B,6BAAuC;AAA9B,8FAAA,OAAO,OAAA;AAAE,4FAAA,KAAK,OAAA"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import * as http from "node:http";
|
|
2
|
+
import { type ConversationHub, type Conversations } from "@loomwork/conversation";
|
|
3
|
+
import type { PrincipalChain } from "@loomwork/effect-runtime";
|
|
4
|
+
import type { EventStore } from "@loomwork/event-runtime";
|
|
5
|
+
import { type ReasoningReader } from "@loomwork/llm";
|
|
6
|
+
/**
|
|
7
|
+
* ADR 0133 D6 - bounds on one `/reasoning` response. The turn's steps are selected before any blob is
|
|
8
|
+
* fetched, and a reply that still exceeds either cap returns its FIRST parts (log order) with
|
|
9
|
+
* `truncated: true`. 256 parts covers a long tool loop (a part per model call, a few per call); 1 MiB
|
|
10
|
+
* of readable text is far past a normal turn and bounds what one request can make the server read.
|
|
11
|
+
*/
|
|
12
|
+
export declare const REASONING_RESPONSE_MAX_PARTS = 256;
|
|
13
|
+
export declare const REASONING_RESPONSE_MAX_BYTES: number;
|
|
14
|
+
export interface ConversationSseOptions {
|
|
15
|
+
conversations: Conversations;
|
|
16
|
+
/** Where live deltas come from (the same hub the model effect's `onDelta` feeds). */
|
|
17
|
+
hub: ConversationHub;
|
|
18
|
+
/** The store the conversations' runtime appends to: its subscription wakes the stream. */
|
|
19
|
+
eventStore: EventStore;
|
|
20
|
+
port?: number;
|
|
21
|
+
/** Interface to bind. Default `"127.0.0.1"` (loopback only). */
|
|
22
|
+
host?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Authenticate AND identify the caller from connection facts (a verified bearer token, an mTLS
|
|
25
|
+
* peer): return its principal (`actor` required) or `undefined` to refuse (401). Never derive it
|
|
26
|
+
* from the body or the URL.
|
|
27
|
+
*/
|
|
28
|
+
authenticate?: (req: http.IncomingMessage) => PrincipalChain | undefined | Promise<PrincipalChain | undefined>;
|
|
29
|
+
/** Explicit opt-out of authentication: any caller that can reach the socket converses. Warned; refused under `strict`. */
|
|
30
|
+
insecure?: boolean;
|
|
31
|
+
/** Fail closed on a principal-less caller. DEFAULTS from the runtime (`requiresPrincipal`), as the A2A server does. */
|
|
32
|
+
strict?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Serve a runtime that has no fail-closed execution authorizer (`security.strict` / `executionAuthz:
|
|
35
|
+
* { requirePrincipal: true }`). Refused by default: this server is an edge, and an edge in front of a
|
|
36
|
+
* runtime that admits anonymous calls is a hole the application would have to remember.
|
|
37
|
+
*/
|
|
38
|
+
allowNoRuntimeAuthz?: boolean;
|
|
39
|
+
warn?: (message: string) => void;
|
|
40
|
+
/**
|
|
41
|
+
* Browser origins allowed to call this server, matched exactly. A request with an `Origin` that is
|
|
42
|
+
* not listed is refused: `Host` is attacker-influenced and never proves same-origin. Default none.
|
|
43
|
+
*/
|
|
44
|
+
allowedOrigins?: readonly string[];
|
|
45
|
+
/** Send `access-control-allow-credentials: true` to the listed origins (cookies / `EventSource` `withCredentials`). Default false. */
|
|
46
|
+
allowCredentials?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* `Host` header values accepted (hostname, port ignored). Default: the loopback names when `insecure`
|
|
49
|
+
* (DNS-rebinding protection for an unauthenticated server); unchecked otherwise.
|
|
50
|
+
*/
|
|
51
|
+
allowedHosts?: readonly string[];
|
|
52
|
+
/** Path prefix. Default `/conversations`. */
|
|
53
|
+
basePath?: string;
|
|
54
|
+
/** Concurrent streams, all callers. Default 256. */
|
|
55
|
+
maxConnections?: number;
|
|
56
|
+
/** Concurrent streams per principal (tenant + actor). Default 8. */
|
|
57
|
+
maxConnectionsPerPrincipal?: number;
|
|
58
|
+
/** Bytes a slow client may leave unread before its stream is closed. Default 1 MiB. */
|
|
59
|
+
maxPendingBytes?: number;
|
|
60
|
+
/** Request body cap, bytes. Default 64 KiB. */
|
|
61
|
+
maxBodyBytes?: number;
|
|
62
|
+
/** Comment heartbeat period, ms. Default 15 000. */
|
|
63
|
+
heartbeatMs?: number;
|
|
64
|
+
/** A stream is ended (the client reconnects with Last-Event-ID) after this long, ms. Default 15 min. */
|
|
65
|
+
maxStreamMs?: number;
|
|
66
|
+
/** How often an open stream re-authenticates and re-authorizes, ms. Default 30 000. */
|
|
67
|
+
reauthMs?: number;
|
|
68
|
+
/** Safety-net poll of the log when no notification arrives, ms. Default 2 000. */
|
|
69
|
+
pollMs?: number;
|
|
70
|
+
/** POSTs (start, turns, close, participants) one principal may make per window. Default 120 per minute. */
|
|
71
|
+
rateLimit?: {
|
|
72
|
+
max?: number;
|
|
73
|
+
windowMs?: number;
|
|
74
|
+
};
|
|
75
|
+
/** The clock the rate limit reads (tests). Default `Date.now`. */
|
|
76
|
+
now?: () => number;
|
|
77
|
+
/** Time a client may take to send its request, ms (slowloris). Default 30 000. */
|
|
78
|
+
requestTimeoutMs?: number;
|
|
79
|
+
/** Time a client may take to send its headers, ms. Default 15 000. */
|
|
80
|
+
headersTimeoutMs?: number;
|
|
81
|
+
/** Open sockets the server accepts at all (`http.Server.maxConnections`). Default 4096. */
|
|
82
|
+
maxSockets?: number;
|
|
83
|
+
/**
|
|
84
|
+
* ADR 0133 D6 - serve the model's reasoning. OFF by default. `true` (or `{ live: true }`) streams the
|
|
85
|
+
* `reasoning` / `reasoning-partial` SSE events; `{ store }` also serves a reply's durable reasoning at
|
|
86
|
+
* `GET <base>/:id/reasoning?cursor=<the reply's history cursor>` (the `ReasoningStore` the model effect
|
|
87
|
+
* captured into). In SHARED mode only the turn's asker and the conversation's owner receive any of it.
|
|
88
|
+
*/
|
|
89
|
+
reasoning?: boolean | {
|
|
90
|
+
live?: boolean;
|
|
91
|
+
store?: ReasoningReader;
|
|
92
|
+
};
|
|
93
|
+
/** Real error behind a 500, with the `errorId` the caller was given. */
|
|
94
|
+
onError?: (errorId: string, err: unknown) => void;
|
|
95
|
+
}
|
|
96
|
+
export interface ConversationSseServer {
|
|
97
|
+
start(): Promise<void>;
|
|
98
|
+
stop(): Promise<void>;
|
|
99
|
+
readonly url: string;
|
|
100
|
+
/** Open streams right now. */
|
|
101
|
+
readonly connections: number;
|
|
102
|
+
/** The underlying `http.Server` (timeouts and limits are set on it; exposed for operators and tests). */
|
|
103
|
+
readonly http: http.Server;
|
|
104
|
+
}
|
|
105
|
+
export declare function createConversationSseServer(options: ConversationSseOptions): ConversationSseServer;
|
|
106
|
+
//# sourceMappingURL=server.d.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