@looprun-ai/server 0.6.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/README.md +75 -0
- package/dist/handler.d.ts +9 -0
- package/dist/handler.d.ts.map +1 -0
- package/dist/handler.js +94 -0
- package/dist/handler.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/openai.d.ts +37 -0
- package/dist/openai.d.ts.map +1 -0
- package/dist/openai.js +65 -0
- package/dist/openai.js.map +1 -0
- package/dist/server.d.ts +3 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +83 -0
- package/dist/server.js.map +1 -0
- package/dist/session.d.ts +29 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +0 -0
- package/dist/session.js.map +1 -0
- package/dist/sse.d.ts +26 -0
- package/dist/sse.d.ts.map +1 -0
- package/dist/sse.js +43 -0
- package/dist/sse.js.map +1 -0
- package/dist/types.d.ts +64 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# @looprun-ai/server
|
|
2
|
+
|
|
3
|
+
Expose governed [LoopRun](https://looprun.ai) agents behind an **OpenAI-compatible endpoint** —
|
|
4
|
+
the "agent-as-model" pattern. Any harness that can point a custom provider at a `base_url`
|
|
5
|
+
(personal-agent frameworks, Open WebUI, IDE assistants, plain OpenAI SDKs) calls a governed agent
|
|
6
|
+
as if it were a model: the full governed turn (guards → tools → redrive) runs inside each
|
|
7
|
+
`/v1/chat/completions` request and returns one final assistant message.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { createModelServer } from '@looprun-ai/server';
|
|
11
|
+
import { LoopRunAgent } from '@looprun-ai/mastra';
|
|
12
|
+
|
|
13
|
+
const agent = new LoopRunAgent({ spec, world: worldFactory, toolDefs, model });
|
|
14
|
+
const server = await createModelServer({ agents: { 'inbox-triage': agent }, port: 8099 });
|
|
15
|
+
console.log(server.url); // http://127.0.0.1:8099/v1
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Point the harness at it:
|
|
19
|
+
|
|
20
|
+
```yaml
|
|
21
|
+
# e.g. a harness config.yaml
|
|
22
|
+
model:
|
|
23
|
+
provider: custom
|
|
24
|
+
base_url: "http://127.0.0.1:8099/v1" # model field selects the agent: "inbox-triage"
|
|
25
|
+
context_length: 128000
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## The mapping law (what the facade does with the incoming request)
|
|
29
|
+
|
|
30
|
+
The server implements the protocol as a **facade** — the harness believes it is talking to a
|
|
31
|
+
model, so parts of the request that would fight the spec are deliberately not honored:
|
|
32
|
+
|
|
33
|
+
| Incoming | Treatment | Why |
|
|
34
|
+
|---|---|---|
|
|
35
|
+
| `model` | routes to the registered agent | one server, N agents as N "models" |
|
|
36
|
+
| last `user` message | the governed turn's input | the agent's own session is the canonical memory |
|
|
37
|
+
| earlier history | **ignored** (transport-only) | harnesses compress/rewrite it; replay would desync the governed state |
|
|
38
|
+
| `system` message | **discarded** | the AgentSpec renders its own trunk (byte-stable, cache-friendly) |
|
|
39
|
+
| `tools`, `tool_choice` | **ignored** | the spec owns the tool surface; guards govern every call |
|
|
40
|
+
| `temperature` etc. | **ignored** | `spec.controls.sampling` governs |
|
|
41
|
+
| `stream: true` | honored (see below) | |
|
|
42
|
+
|
|
43
|
+
## Sessions
|
|
44
|
+
|
|
45
|
+
The protocol is stateless; the agent is stateful. Session id resolution, first hit wins:
|
|
46
|
+
|
|
47
|
+
1. `x-looprun-session` header (explicit — always safe; OpenAI SDKs support `default_headers`),
|
|
48
|
+
2. the OpenAI-standard `user` field,
|
|
49
|
+
3. fingerprint fallback: hash of `model` + the **first** user message — stable for a conversation
|
|
50
|
+
unless the harness compresses that message away (mitigated by the high `context_length`
|
|
51
|
+
reported by `/v1/models`). A changed fingerprint starts a fresh session: degraded, never unsafe.
|
|
52
|
+
|
|
53
|
+
Concurrent requests on the same session serialize; different sessions run concurrently.
|
|
54
|
+
Optional `sessionTtlMs` evicts idle sessions via `agent.endSession()`.
|
|
55
|
+
|
|
56
|
+
## Streaming
|
|
57
|
+
|
|
58
|
+
`stream: true` still runs the governed turn to completion (streaming cannot be governed at the
|
|
59
|
+
reply level), then emits a valid SSE stream: an immediate role delta, `: keepalive` comments while
|
|
60
|
+
the turn runs, one content delta with the full governed text, a finish chunk, `[DONE]`.
|
|
61
|
+
|
|
62
|
+
## Observability
|
|
63
|
+
|
|
64
|
+
Every response carries a non-standard `looprun` field (`sessionId`, `turnIndex`, `corrections`,
|
|
65
|
+
`exhausted`, `violations`) — OpenAI SDKs ignore it; integration harnesses can assert on it.
|
|
66
|
+
`onTurn` fires server-side after every governed turn with the same metadata.
|
|
67
|
+
|
|
68
|
+
## API
|
|
69
|
+
|
|
70
|
+
- `createModelServer(config) → { url, port, handler, close() }` — node:http server, ephemeral
|
|
71
|
+
port by default.
|
|
72
|
+
- `createOpenAiHandler(config) → (req: Request) => Promise<Response>` — the bare fetch-style
|
|
73
|
+
handler (embed it in any web server).
|
|
74
|
+
- `config`: `agents` (model id → `LoopRunAgent`), `port`, `hostname`, `contextLength`,
|
|
75
|
+
`apiKey` (optional bearer check), `resolveSession`, `sessionTtlMs`, `onTurn`.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SessionLocks, SessionTtl } from './session.js';
|
|
2
|
+
import type { ModelServerConfig } from './types.js';
|
|
3
|
+
export declare const DEFAULT_CONTEXT_LENGTH = 128000;
|
|
4
|
+
export interface HandlerInternals {
|
|
5
|
+
locks: SessionLocks;
|
|
6
|
+
ttl: SessionTtl;
|
|
7
|
+
}
|
|
8
|
+
export declare function createOpenAiHandler(config: ModelServerConfig, internals?: HandlerInternals): (req: Request) => Promise<Response>;
|
|
9
|
+
//# sourceMappingURL=handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../src/handler.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAkC,MAAM,cAAc,CAAC;AAExF,OAAO,KAAK,EAA8C,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEhG,eAAO,MAAM,sBAAsB,SAAU,CAAC;AAmB9C,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,YAAY,CAAC;IACpB,GAAG,EAAE,UAAU,CAAC;CACjB;AAED,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,iBAAiB,EACzB,SAAS,GAAE,gBAAuE,GACjF,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CA4FrC"}
|
package/dist/handler.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { buildCompletion, buildModelList, buildUsage, completionId, errorBody, } from './openai.js';
|
|
2
|
+
import { SessionLocks, SessionTtl, lastUserText, resolveSessionId } from './session.js';
|
|
3
|
+
import { streamCompletion } from './sse.js';
|
|
4
|
+
export const DEFAULT_CONTEXT_LENGTH = 128_000;
|
|
5
|
+
function json(status, body) {
|
|
6
|
+
return new Response(JSON.stringify(body), {
|
|
7
|
+
status,
|
|
8
|
+
headers: { 'content-type': 'application/json' },
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
function envelopeMeta(meta) {
|
|
12
|
+
return {
|
|
13
|
+
sessionId: meta.sessionId,
|
|
14
|
+
turnIndex: meta.turnIndex,
|
|
15
|
+
corrections: meta.corrections,
|
|
16
|
+
exhausted: meta.exhausted,
|
|
17
|
+
violations: meta.violations,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export function createOpenAiHandler(config, internals = { locks: new SessionLocks(), ttl: new SessionTtl() }) {
|
|
21
|
+
const contextLength = config.contextLength ?? DEFAULT_CONTEXT_LENGTH;
|
|
22
|
+
const { locks, ttl } = internals;
|
|
23
|
+
return async function handle(req) {
|
|
24
|
+
const url = new URL(req.url);
|
|
25
|
+
const path = url.pathname.replace(/\/+$/, '');
|
|
26
|
+
if (config.apiKey) {
|
|
27
|
+
const auth = req.headers.get('authorization') ?? '';
|
|
28
|
+
if (auth !== `Bearer ${config.apiKey}`) {
|
|
29
|
+
return json(401, errorBody('Incorrect API key provided.', 'invalid_request_error', 'invalid_api_key'));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (req.method === 'GET' && path === '/v1/models') {
|
|
33
|
+
return json(200, buildModelList(Object.keys(config.agents), contextLength));
|
|
34
|
+
}
|
|
35
|
+
if (req.method === 'POST' && path === '/v1/chat/completions') {
|
|
36
|
+
let body;
|
|
37
|
+
try {
|
|
38
|
+
body = (await req.json());
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return json(400, errorBody('Request body is not valid JSON.', 'invalid_request_error', null));
|
|
42
|
+
}
|
|
43
|
+
const agent = body.model ? config.agents[body.model] : undefined;
|
|
44
|
+
if (!agent) {
|
|
45
|
+
return json(404, errorBody(`The model '${String(body.model)}' does not exist.`, 'invalid_request_error', 'model_not_found', 'model'));
|
|
46
|
+
}
|
|
47
|
+
if (!Array.isArray(body.messages) || body.messages.length === 0) {
|
|
48
|
+
return json(400, errorBody("Missing required parameter: 'messages'.", 'invalid_request_error', null, 'messages'));
|
|
49
|
+
}
|
|
50
|
+
const userText = lastUserText(body.messages);
|
|
51
|
+
if (userText === null) {
|
|
52
|
+
return json(400, errorBody('No user message with text content found in `messages`.', 'invalid_request_error', null, 'messages'));
|
|
53
|
+
}
|
|
54
|
+
const sessionId = (config.resolveSession ?? resolveSessionId)(body, req.headers);
|
|
55
|
+
const id = completionId();
|
|
56
|
+
const runTurn = () => locks.run(`${body.model} ${sessionId}`, async () => {
|
|
57
|
+
const result = await agent.generate(userText, { loopRun: { sessionId } });
|
|
58
|
+
const meta = result.looprun;
|
|
59
|
+
ttl.touch(body.model, sessionId);
|
|
60
|
+
config.onTurn?.({ model: body.model, sessionId, meta });
|
|
61
|
+
return {
|
|
62
|
+
text: String(result.text ?? ''),
|
|
63
|
+
usage: buildUsage(userText, String(result.text ?? '')),
|
|
64
|
+
looprun: envelopeMeta(meta),
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
if (body.stream === true) {
|
|
68
|
+
const stream = streamCompletion({
|
|
69
|
+
id,
|
|
70
|
+
model: body.model,
|
|
71
|
+
turn: runTurn(),
|
|
72
|
+
onError: (error) => errorBody(error instanceof Error ? error.message : 'The governed turn failed.', 'api_error', 'api_error'),
|
|
73
|
+
});
|
|
74
|
+
return new Response(stream, {
|
|
75
|
+
status: 200,
|
|
76
|
+
headers: {
|
|
77
|
+
'content-type': 'text/event-stream; charset=utf-8',
|
|
78
|
+
'cache-control': 'no-cache',
|
|
79
|
+
connection: 'keep-alive',
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
const turn = await runTurn();
|
|
85
|
+
return json(200, buildCompletion({ id, model: body.model, text: turn.text, usage: turn.usage, looprun: turn.looprun }));
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
return json(500, errorBody(error instanceof Error ? error.message : 'The governed turn failed.', 'api_error', 'api_error'));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return json(404, errorBody(`Unknown request URL: ${req.method} ${path}.`, 'invalid_request_error', null));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S,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,2BAA2B,EAAE,WAAW,EAAE,WAAW,CAAC,CAC1G,CAAC;YACJ,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,wBAAwB,GAAG,CAAC,MAAM,IAAI,IAAI,GAAG,EAAE,uBAAuB,EAAE,IAAI,CAAC,CAAC,CAAC;IAC5G,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @looprun-ai/server — expose governed LoopRunAgents behind an OpenAI-compatible endpoint.
|
|
3
|
+
*
|
|
4
|
+
* `createModelServer({ agents: { 'my-agent': agent } })` serves `/v1/chat/completions` +
|
|
5
|
+
* `/v1/models`; any harness that speaks the OpenAI protocol (custom provider + base_url) then
|
|
6
|
+
* calls the governed agent as if it were a model. The full governed turn — guards, tools,
|
|
7
|
+
* redrive — runs inside each request and returns one final assistant message.
|
|
8
|
+
*/
|
|
9
|
+
export { createOpenAiHandler, DEFAULT_CONTEXT_LENGTH } from './handler.js';
|
|
10
|
+
export { createModelServer } from './server.js';
|
|
11
|
+
export { SESSION_HEADER, fingerprintSession, lastUserText, resolveSessionId } from './session.js';
|
|
12
|
+
export type { CompletionRequestBody, LoopRunEnvelopeMeta, ModelServer, ModelServerConfig, TurnEvent, WireMessage, } from './types.js';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAClG,YAAY,EACV,qBAAqB,EACrB,mBAAmB,EACnB,WAAW,EACX,iBAAiB,EACjB,SAAS,EACT,WAAW,GACZ,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @looprun-ai/server — expose governed LoopRunAgents behind an OpenAI-compatible endpoint.
|
|
3
|
+
*
|
|
4
|
+
* `createModelServer({ agents: { 'my-agent': agent } })` serves `/v1/chat/completions` +
|
|
5
|
+
* `/v1/models`; any harness that speaks the OpenAI protocol (custom provider + base_url) then
|
|
6
|
+
* calls the governed agent as if it were a model. The full governed turn — guards, tools,
|
|
7
|
+
* redrive — runs inside each request and returns one final assistant message.
|
|
8
|
+
*/
|
|
9
|
+
export { createOpenAiHandler, DEFAULT_CONTEXT_LENGTH } from './handler.js';
|
|
10
|
+
export { createModelServer } from './server.js';
|
|
11
|
+
export { SESSION_HEADER, fingerprintSession, lastUserText, resolveSessionId } from './session.js';
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/openai.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** OpenAI chat-completion envelope builders (non-stream + stream chunks) and error shapes. */
|
|
2
|
+
import type { LoopRunEnvelopeMeta } from './types.js';
|
|
3
|
+
/** Rough token estimate (ceil(chars/4), never zero) — harnesses expect nonzero usage. */
|
|
4
|
+
export declare function estimateTokens(text: string): number;
|
|
5
|
+
export interface CompletionUsage {
|
|
6
|
+
prompt_tokens: number;
|
|
7
|
+
completion_tokens: number;
|
|
8
|
+
total_tokens: number;
|
|
9
|
+
}
|
|
10
|
+
export declare function buildUsage(promptText: string, completionText: string): CompletionUsage;
|
|
11
|
+
export declare function completionId(): string;
|
|
12
|
+
export declare function buildCompletion(args: {
|
|
13
|
+
id: string;
|
|
14
|
+
model: string;
|
|
15
|
+
text: string;
|
|
16
|
+
usage: CompletionUsage;
|
|
17
|
+
looprun: LoopRunEnvelopeMeta;
|
|
18
|
+
}): Record<string, unknown>;
|
|
19
|
+
export declare function buildChunk(args: {
|
|
20
|
+
id: string;
|
|
21
|
+
model: string;
|
|
22
|
+
delta: Record<string, unknown>;
|
|
23
|
+
finishReason?: string | null;
|
|
24
|
+
usage?: CompletionUsage;
|
|
25
|
+
looprun?: LoopRunEnvelopeMeta;
|
|
26
|
+
}): Record<string, unknown>;
|
|
27
|
+
export declare function buildModelList(ids: string[], contextLength: number): Record<string, unknown>;
|
|
28
|
+
export type WireErrorCode = 'model_not_found' | 'invalid_request_error' | 'api_error' | 'invalid_api_key';
|
|
29
|
+
export declare function errorBody(message: string, type: string, code: WireErrorCode | null, param?: string | null): {
|
|
30
|
+
error: {
|
|
31
|
+
message: string;
|
|
32
|
+
type: string;
|
|
33
|
+
param: string | null;
|
|
34
|
+
code: WireErrorCode | null;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=openai.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../src/openai.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD,yFAAyF;AACzF,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED,MAAM,WAAW,eAAe;IAC9B,aAAa,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il(chars/4), never zero) — harnesses expect nonzero usage. */
|
|
2
|
+
export function estimateTokens(text) {
|
|
3
|
+
return Math.max(1, Math.ceil(text.length / 4));
|
|
4
|
+
}
|
|
5
|
+
export function buildUsage(promptText, completionText) {
|
|
6
|
+
const prompt = estimateTokens(promptText);
|
|
7
|
+
const completion = estimateTokens(completionText);
|
|
8
|
+
return { prompt_tokens: prompt, completion_tokens: completion, total_tokens: prompt + completion };
|
|
9
|
+
}
|
|
10
|
+
let counter = 0;
|
|
11
|
+
export function completionId() {
|
|
12
|
+
counter++;
|
|
13
|
+
return `chatcmpl-looprun-${Date.now().toString(36)}${counter.toString(36)}`;
|
|
14
|
+
}
|
|
15
|
+
export function buildCompletion(args) {
|
|
16
|
+
return {
|
|
17
|
+
id: args.id,
|
|
18
|
+
object: 'chat.completion',
|
|
19
|
+
created: Math.floor(Date.now() / 1000),
|
|
20
|
+
model: args.model,
|
|
21
|
+
choices: [
|
|
22
|
+
{
|
|
23
|
+
index: 0,
|
|
24
|
+
message: { role: 'assistant', content: args.text },
|
|
25
|
+
finish_reason: 'stop',
|
|
26
|
+
logprobs: null,
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
usage: args.usage,
|
|
30
|
+
// Non-standard extension (OpenAI SDKs ignore unknown fields): the governed-turn metadata.
|
|
31
|
+
looprun: args.looprun,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export function buildChunk(args) {
|
|
35
|
+
const chunk = {
|
|
36
|
+
id: args.id,
|
|
37
|
+
object: 'chat.completion.chunk',
|
|
38
|
+
created: Math.floor(Date.now() / 1000),
|
|
39
|
+
model: args.model,
|
|
40
|
+
choices: [{ index: 0, delta: args.delta, finish_reason: args.finishReason ?? null, logprobs: null }],
|
|
41
|
+
};
|
|
42
|
+
if (args.usage)
|
|
43
|
+
chunk.usage = args.usage;
|
|
44
|
+
if (args.looprun)
|
|
45
|
+
chunk.looprun = args.looprun;
|
|
46
|
+
return chunk;
|
|
47
|
+
}
|
|
48
|
+
export function buildModelList(ids, contextLength) {
|
|
49
|
+
const created = Math.floor(Date.now() / 1000);
|
|
50
|
+
return {
|
|
51
|
+
object: 'list',
|
|
52
|
+
data: ids.map((id) => ({
|
|
53
|
+
id,
|
|
54
|
+
object: 'model',
|
|
55
|
+
created,
|
|
56
|
+
owned_by: 'looprun',
|
|
57
|
+
// De-facto extension many harnesses read to size their context handling.
|
|
58
|
+
context_length: contextLength,
|
|
59
|
+
})),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export function errorBody(message, type, code, param = null) {
|
|
63
|
+
return { error: { message, type, param, code } };
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=openai.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai.js","sourceRoot":"","sources":["../src/openai.ts"],"names":[],"mappings":"AAGA,yFAAyF;AACzF,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;AACjD,CAAC;AAQD,MAAM,UAAU,UAAU,CAAC,UAAkB,EAAE,cAAsB;IACnE,MAAM,MAAM,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC;IAC1C,MAAM,UAAU,GAAG,cAAc,CAAC,cAAc,CAAC,CAAC;IAClD,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,iBAAiB,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,GAAG,UAAU,EAAE,CAAC;AACrG,CAAC;AAED,IAAI,OAAO,GAAG,CAAC,CAAC;AAChB,MAAM,UAAU,YAAY;IAC1B,OAAO,EAAE,CAAC;IACV,OAAO,oBAAoB,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;AAC9E,CAAC;AAED,MAAM,UAAU,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CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;IAC9C,OAAO;QACL,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;YACrB,EAAE;YACF,MAAM,EAAE,OAAO;YACf,OAAO;YACP,QAAQ,EAAE,SAAS;YACnB,yEAAyE;YACzE,cAAc,EAAE,aAAa;SAC9B,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC;AAID,MAAM,UAAU,SAAS,CAAC,OAAe,EAAE,IAAY,EAAE,IAA0B,EAAE,QAAuB,IAAI;IAC9G,OAAO,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC;AACnD,CAAC"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AA8BjE,wBAAsB,iBAAiB,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC,CA8CvF"}
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* node:http adapter around the fetch-style handler — no framework (the surface is two routes;
|
|
3
|
+
* WHATWG Request/Response are native on Node >= 22).
|
|
4
|
+
*/
|
|
5
|
+
import { createServer } from 'node:http';
|
|
6
|
+
import { Readable } from 'node:stream';
|
|
7
|
+
import { createOpenAiHandler } from './handler.js';
|
|
8
|
+
import { SessionLocks, SessionTtl } from './session.js';
|
|
9
|
+
function toRequest(req, base) {
|
|
10
|
+
const headers = new Headers();
|
|
11
|
+
for (const [key, value] of Object.entries(req.headers)) {
|
|
12
|
+
if (typeof value === 'string')
|
|
13
|
+
headers.set(key, value);
|
|
14
|
+
else if (Array.isArray(value))
|
|
15
|
+
for (const v of value)
|
|
16
|
+
headers.append(key, v);
|
|
17
|
+
}
|
|
18
|
+
const method = req.method ?? 'GET';
|
|
19
|
+
const body = method === 'GET' || method === 'HEAD' ? undefined : Readable.toWeb(req);
|
|
20
|
+
return new Request(new URL(req.url ?? '/', base), {
|
|
21
|
+
method,
|
|
22
|
+
headers,
|
|
23
|
+
body,
|
|
24
|
+
// Node requires this flag for streamed request bodies.
|
|
25
|
+
...(body ? { duplex: 'half' } : {}),
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
async function writeResponse(res, out) {
|
|
29
|
+
out.statusCode = res.status;
|
|
30
|
+
res.headers.forEach((value, key) => out.setHeader(key, value));
|
|
31
|
+
if (res.body) {
|
|
32
|
+
for await (const chunk of Readable.fromWeb(res.body)) {
|
|
33
|
+
out.write(chunk);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
out.end();
|
|
37
|
+
}
|
|
38
|
+
export async function createModelServer(config) {
|
|
39
|
+
const locks = new SessionLocks();
|
|
40
|
+
const ttl = new SessionTtl();
|
|
41
|
+
const handler = createOpenAiHandler(config, { locks, ttl });
|
|
42
|
+
let sweeper;
|
|
43
|
+
if (config.sessionTtlMs && config.sessionTtlMs > 0) {
|
|
44
|
+
const ttlMs = config.sessionTtlMs;
|
|
45
|
+
sweeper = setInterval(() => {
|
|
46
|
+
for (const expired of ttl.sweep(ttlMs)) {
|
|
47
|
+
config.agents[expired.model]?.endSession(expired.sessionId);
|
|
48
|
+
}
|
|
49
|
+
}, Math.min(ttlMs, 60_000));
|
|
50
|
+
sweeper.unref();
|
|
51
|
+
}
|
|
52
|
+
const hostname = config.hostname ?? '127.0.0.1';
|
|
53
|
+
let port = config.port ?? 0;
|
|
54
|
+
const server = createServer((req, res) => {
|
|
55
|
+
const base = `http://${hostname}:${port}`;
|
|
56
|
+
void handler(toRequest(req, base))
|
|
57
|
+
.then((response) => writeResponse(response, res))
|
|
58
|
+
.catch((error) => {
|
|
59
|
+
res.statusCode = 500;
|
|
60
|
+
res.setHeader('content-type', 'application/json');
|
|
61
|
+
res.end(JSON.stringify({ error: { message: String(error), type: 'api_error', param: null, code: 'api_error' } }));
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
await new Promise((resolve, reject) => {
|
|
65
|
+
server.once('error', reject);
|
|
66
|
+
server.listen(port, hostname, () => resolve());
|
|
67
|
+
});
|
|
68
|
+
const address = server.address();
|
|
69
|
+
if (address && typeof address === 'object')
|
|
70
|
+
port = address.port;
|
|
71
|
+
return {
|
|
72
|
+
url: `http://${hostname}:${port}/v1`,
|
|
73
|
+
port,
|
|
74
|
+
handler,
|
|
75
|
+
close: () => new Promise((resolve, reject) => {
|
|
76
|
+
if (sweeper)
|
|
77
|
+
clearInterval(sweeper);
|
|
78
|
+
server.close((error) => (error ? reject(error) : resolve()));
|
|
79
|
+
server.closeAllConnections();
|
|
80
|
+
}),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAGxD,SAAS,SAAS,CAAC,GAAoB,EAAE,IAAY;IACnD,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAC9B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;QACvD,IAAI,OAAO,KAAK,KAAK,QAAQ;YAAE,OAAO,CAAC,GAAG,C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import type { CompletionRequestBody, WireMessage } from './types.js';
|
|
2
|
+
export declare const SESSION_HEADER = "x-looprun-session";
|
|
3
|
+
/** The last `user` message's text — the governed turn's input. Null when absent/empty. */
|
|
4
|
+
export declare function lastUserText(messages: WireMessage[]): string | null;
|
|
5
|
+
export declare function fingerprintSession(model: string, messages: WireMessage[]): string;
|
|
6
|
+
export declare function resolveSessionId(body: CompletionRequestBody, headers: Headers): string;
|
|
7
|
+
/**
|
|
8
|
+
* Per-key promise-chain mutex: two concurrent requests on the SAME session run one governed
|
|
9
|
+
* turn at a time (different sessions stay fully concurrent — the agent's AsyncLocalStorage
|
|
10
|
+
* already isolates those).
|
|
11
|
+
*/
|
|
12
|
+
export declare class SessionLocks {
|
|
13
|
+
private readonly tails;
|
|
14
|
+
run<T>(key: string, task: () => Promise<T>): Promise<T>;
|
|
15
|
+
}
|
|
16
|
+
interface TouchRecord {
|
|
17
|
+
model: string;
|
|
18
|
+
sessionId: string;
|
|
19
|
+
lastSeen: number;
|
|
20
|
+
}
|
|
21
|
+
/** Idle-session tracker backing the optional TTL eviction sweep. */
|
|
22
|
+
export declare class SessionTtl {
|
|
23
|
+
private readonly touched;
|
|
24
|
+
touch(model: string, sessionId: string, now?: number): void;
|
|
25
|
+
/** Sessions idle beyond `ttlMs`; each is removed from the tracker as it is returned. */
|
|
26
|
+
sweep(ttlMs: number, now?: number): TouchRecord[];
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAErE,eAAO,MAAM,cAAc,sBAAsB,CAAC;AAalD,0FAA0F;AAC1F,wBAAgB,YAAY,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,MAAM,GAAG,IAAI,CAQnE;A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AAG,GAAG,IAAI,CAAC,GAAG,EAAE;QACtD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,IAAI,SAAS,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC;IACjF,CAAC;IAED,wFAAwF;IACxF,KAAK,CAAC,KAAa,EAAE,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE;QACnC,MAAM,OAAO,GAAkB,EAAE,CAAC;QAClC,KAAK,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACzC,IAAI,GAAG,GAAG,MAAM,CAAC,QAAQ,IAAI,KAAK,EAAE,CAAC;gBACnC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBACrB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAC3B,CAAC;QACH,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF"}
|
package/dist/sse.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SSE encoding for `stream: true`.
|
|
3
|
+
*
|
|
4
|
+
* The governed turn always runs to completion first (`agent.stream()` is the documented degraded
|
|
5
|
+
* mode — no reply finalization — so the server never uses it). The stream shape is:
|
|
6
|
+
* role delta (immediately, so the socket is live) → `: keepalive` comments while the turn runs →
|
|
7
|
+
* ONE content delta with the full governed text → finish chunk → [DONE].
|
|
8
|
+
* SSE comment lines are ignored by every OpenAI SDK parser, and a single big content delta is a
|
|
9
|
+
* fully valid stream.
|
|
10
|
+
*/
|
|
11
|
+
import type { CompletionUsage } from './openai.js';
|
|
12
|
+
import type { LoopRunEnvelopeMeta } from './types.js';
|
|
13
|
+
export declare function sseData(payload: Record<string, unknown>): Uint8Array;
|
|
14
|
+
export interface StreamedTurn {
|
|
15
|
+
text: string;
|
|
16
|
+
usage: CompletionUsage;
|
|
17
|
+
looprun: LoopRunEnvelopeMeta;
|
|
18
|
+
}
|
|
19
|
+
export declare function streamCompletion(args: {
|
|
20
|
+
id: string;
|
|
21
|
+
model: string;
|
|
22
|
+
turn: Promise<StreamedTurn>;
|
|
23
|
+
keepaliveMs?: number;
|
|
24
|
+
onError: (error: unknown) => Record<string, unknown>;
|
|
25
|
+
}): ReadableStream<Uint8Array>;
|
|
26
|
+
//# sourceMappingURL=sse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../src/sse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAItD,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,CAEpE;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,eAAe,CAAC;IACvB,OAAO,EAAE,mBAAmB,CAAC;CAC9B;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtD,GAAG,cAAc,CAAC,UAAU,CAAC,CAqC7B"}
|
package/dist/sse.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { buildChunk } from './openai.js';
|
|
2
|
+
const encoder = new TextEncoder();
|
|
3
|
+
export function sseData(payload) {
|
|
4
|
+
return encoder.encode(`data: ${JSON.stringify(payload)}\n\n`);
|
|
5
|
+
}
|
|
6
|
+
export function streamCompletion(args) {
|
|
7
|
+
const keepaliveMs = args.keepaliveMs ?? 10_000;
|
|
8
|
+
return new ReadableStream({
|
|
9
|
+
async start(controller) {
|
|
10
|
+
controller.enqueue(sseData(buildChunk({ id: args.id, model: args.model, delta: { role: 'assistant', content: '' } })));
|
|
11
|
+
const keepalive = setInterval(() => {
|
|
12
|
+
try {
|
|
13
|
+
controller.enqueue(encoder.encode(': keepalive\n\n'));
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
clearInterval(keepalive);
|
|
17
|
+
}
|
|
18
|
+
}, keepaliveMs);
|
|
19
|
+
try {
|
|
20
|
+
const turn = await args.turn;
|
|
21
|
+
controller.enqueue(sseData(buildChunk({ id: args.id, model: args.model, delta: { content: turn.text } })));
|
|
22
|
+
controller.enqueue(sseData(buildChunk({
|
|
23
|
+
id: args.id,
|
|
24
|
+
model: args.model,
|
|
25
|
+
delta: {},
|
|
26
|
+
finishReason: 'stop',
|
|
27
|
+
usage: turn.usage,
|
|
28
|
+
looprun: turn.looprun,
|
|
29
|
+
})));
|
|
30
|
+
controller.enqueue(encoder.encode('data: [DONE]\n\n'));
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
// Mid-stream failure: emit an OpenAI-style error event then terminate the stream.
|
|
34
|
+
controller.enqueue(sseData(args.onError(error)));
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
clearInterval(keepalive);
|
|
38
|
+
controller.close();
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=sse.js.map
|
package/dist/sse.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sse.js","sourceRoot":"","sources":["../src/sse.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAEl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K,EAAE,EAAE;oBACT,YAAY,EAAE,MAAM;oBACpB,KAAK,EAAE,IAAI,CAAC,KAAK;oBACjB,OAAO,EAAE,IAAI,CAAC,OAAO;iBACtB,CAAC,CACH,CACF,CAAC;gBACF,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC;YACzD,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,kFAAkF;gBAClF,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACnD,CAAC;oBAAS,CAAC;gBACT,aAAa,CAAC,SAAS,CAAC,CAAC;gBACzB,UAAU,CAAC,KAAK,EAAE,CAAC;YACrB,CAAC;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI chat-completions wire types (the subset the server speaks) + server config.
|
|
3
|
+
*
|
|
4
|
+
* The server deliberately implements the protocol as a FACADE: the harness believes it is talking
|
|
5
|
+
* to a model, while a full governed turn runs behind the endpoint. Incoming `system` messages,
|
|
6
|
+
* `tools`, `tool_choice` and sampling params are therefore ignored by design — the AgentSpec owns
|
|
7
|
+
* the trunk, the tool surface and the sampling (see README).
|
|
8
|
+
*/
|
|
9
|
+
import type { LoopRunAgent, LoopRunResultMeta } from '@looprun-ai/mastra';
|
|
10
|
+
/** One incoming OpenAI message. Content may be a string or an array of typed parts. */
|
|
11
|
+
export interface WireMessage {
|
|
12
|
+
role: 'system' | 'developer' | 'user' | 'assistant' | 'tool';
|
|
13
|
+
content: string | Array<{
|
|
14
|
+
type: string;
|
|
15
|
+
text?: string;
|
|
16
|
+
}> | null;
|
|
17
|
+
}
|
|
18
|
+
export interface CompletionRequestBody {
|
|
19
|
+
model: string;
|
|
20
|
+
messages: WireMessage[];
|
|
21
|
+
stream?: boolean;
|
|
22
|
+
/** OpenAI-standard end-user id — second precedence for the looprun session id. */
|
|
23
|
+
user?: string;
|
|
24
|
+
[ignored: string]: unknown;
|
|
25
|
+
}
|
|
26
|
+
/** Non-standard envelope extension carrying the governed-turn metadata (SDKs ignore it). */
|
|
27
|
+
export interface LoopRunEnvelopeMeta {
|
|
28
|
+
sessionId: string;
|
|
29
|
+
turnIndex: number;
|
|
30
|
+
corrections: string[];
|
|
31
|
+
exhausted: boolean;
|
|
32
|
+
violations: string[];
|
|
33
|
+
}
|
|
34
|
+
export interface TurnEvent {
|
|
35
|
+
model: string;
|
|
36
|
+
sessionId: string;
|
|
37
|
+
meta: LoopRunResultMeta;
|
|
38
|
+
}
|
|
39
|
+
export interface ModelServerConfig {
|
|
40
|
+
/** Registry: OpenAI `model` field → governed agent. */
|
|
41
|
+
agents: Record<string, LoopRunAgent>;
|
|
42
|
+
/** Listen port; 0 (default) = ephemeral. */
|
|
43
|
+
port?: number;
|
|
44
|
+
/** Bind hostname; default 127.0.0.1. */
|
|
45
|
+
hostname?: string;
|
|
46
|
+
/** `context_length` reported by /v1/models. High default keeps harnesses from compressing
|
|
47
|
+
* history, which would break the fingerprint session fallback. */
|
|
48
|
+
contextLength?: number;
|
|
49
|
+
/** When set, requests must carry `Authorization: Bearer <apiKey>`. */
|
|
50
|
+
apiKey?: string;
|
|
51
|
+
/** Override the session-id resolution chain (header → body.user → fingerprint). */
|
|
52
|
+
resolveSession?: (body: CompletionRequestBody, headers: Headers) => string;
|
|
53
|
+
/** Idle sessions older than this are disposed via agent.endSession(). Default: no eviction. */
|
|
54
|
+
sessionTtlMs?: number;
|
|
55
|
+
/** Observability: fires after every governed turn (the sim harness asserts through this). */
|
|
56
|
+
onTurn?: (event: TurnEvent) => void;
|
|
57
|
+
}
|
|
58
|
+
export interface ModelServer {
|
|
59
|
+
url: string;
|
|
60
|
+
port: number;
|
|
61
|
+
handler: (req: Request) => Promise<Response>;
|
|
62
|
+
close(): Promise<void>;
|
|
63
|
+
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AC,EAAE,MAAM,CAAC;IAClB;uEACmE;IACnE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,sEAAsE;IACtE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,mFAAmF;IACnF,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,qBAAqB,EAAE,OAAO,EAAE,OAAO,KAAK,MAAM,CAAC;IAC3E,+FAA+F;IAC/F,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,6FAA6F;IAC7F,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;CACrC;AAED,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC7C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@looprun-ai/server",
|
|
3
|
+
"version": "0.6.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "looprun model server: expose governed LoopRunAgents behind an OpenAI-compatible /v1/chat/completions endpoint, so any harness that speaks the OpenAI protocol can call a governed agent as if it were a model. The full governed turn (guards, tools, redrive) runs inside each request and returns one final assistant message.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"ai",
|
|
8
|
+
"agents",
|
|
9
|
+
"llm",
|
|
10
|
+
"governance",
|
|
11
|
+
"guardrails",
|
|
12
|
+
"agentspec",
|
|
13
|
+
"openai-compatible",
|
|
14
|
+
"model-server"
|
|
15
|
+
],
|
|
16
|
+
"license": "Apache-2.0",
|
|
17
|
+
"author": "LoopRun Team",
|
|
18
|
+
"homepage": "https://looprun.ai",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/looprun-ai/looprun.git",
|
|
22
|
+
"directory": "packages/server"
|
|
23
|
+
},
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/looprun-ai/looprun/issues"
|
|
26
|
+
},
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"default": "./dist/index.js"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist"
|
|
35
|
+
],
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=22"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@looprun-ai/core": "^0.6.1",
|
|
41
|
+
"@looprun-ai/mastra": "^0.6.1"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"@mastra/core": "^1.42.0",
|
|
45
|
+
"ai": "^6.0.0",
|
|
46
|
+
"zod": "^3.24.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@mastra/core": "^1.42.0",
|
|
50
|
+
"@types/node": "^22.0.0",
|
|
51
|
+
"ai": "^6.0.184",
|
|
52
|
+
"typescript": "^5.7.0",
|
|
53
|
+
"vitest": "^2.0.0",
|
|
54
|
+
"zod": "^3.24.0"
|
|
55
|
+
},
|
|
56
|
+
"scripts": {
|
|
57
|
+
"build": "tsc -p tsconfig.build.json",
|
|
58
|
+
"typecheck": "tsc --noEmit",
|
|
59
|
+
"test": "vitest run"
|
|
60
|
+
}
|
|
61
|
+
}
|