@nylorun/runtime 0.4.0-beta → 0.6.0-beta
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/CHANGELOG.md +55 -0
- package/README.md +29 -47
- package/dist/adapters/media.d.ts +2 -18
- package/dist/adapters/media.js +2 -52
- package/dist/adapters/observe.js +1 -1
- package/dist/config.d.ts +17 -10
- package/dist/configuration.d.ts +3 -0
- package/dist/configuration.js +3 -0
- package/dist/contracts.d.ts +5 -166
- package/dist/core/main.js +40 -0
- package/dist/core/provider.d.ts +12 -0
- package/dist/core/provider.js +60 -0
- package/dist/core/runtime.d.ts +50 -0
- package/dist/core/runtime.js +877 -0
- package/dist/core/store.d.ts +16 -0
- package/dist/core/store.js +101 -0
- package/dist/index.d.ts +6 -11
- package/dist/index.js +4 -6
- package/dist/media.d.ts +29 -0
- package/dist/media.js +53 -0
- package/dist/model/defaults.d.ts +17 -0
- package/dist/model/defaults.js +21 -0
- package/dist/model/http-model.d.ts +12 -0
- package/dist/model/http-model.js +299 -0
- package/dist/model/pi-model.d.ts +2 -1
- package/dist/model/pi-model.js +52 -7
- package/dist/node/index.d.ts +5 -0
- package/dist/node/index.js +5 -0
- package/dist/node/local-sessions.d.ts +5 -0
- package/dist/node/local-sessions.js +174 -0
- package/dist/redact.d.ts +1 -0
- package/dist/redact.js +14 -0
- package/dist/server/ag-ui.d.ts +1 -1
- package/dist/server/delivery.d.ts +24 -0
- package/dist/server/delivery.js +107 -0
- package/dist/server/host.d.ts +50 -7
- package/dist/server/host.js +304 -307
- package/dist/session/api.d.ts +10 -0
- package/dist/session/api.js +15 -0
- package/dist/session/default.d.ts +5 -0
- package/dist/session/default.js +30 -0
- package/dist/session/handle.d.ts +27 -0
- package/dist/session/handle.js +199 -0
- package/dist/session/index.d.ts +2 -0
- package/dist/session/index.js +2 -0
- package/dist/sessions/host.d.ts +39 -0
- package/dist/sessions/host.js +359 -0
- package/dist/sessions/store.d.ts +41 -0
- package/dist/sessions/store.js +33 -0
- package/package.json +23 -12
- package/dist/adapters/journal.d.ts +0 -35
- package/dist/adapters/journal.js +0 -130
- package/dist/cli.d.ts +0 -2
- package/dist/cli.js +0 -100
- package/dist/dev-entry.js +0 -2
- package/dist/dev.d.ts +0 -2
- package/dist/dev.js +0 -126
- package/dist/environment.d.ts +0 -2
- package/dist/environment.js +0 -64
- package/dist/launcher.d.ts +0 -1
- package/dist/launcher.js +0 -28
- package/dist/model/configure.d.ts +0 -12
- package/dist/model/configure.js +0 -155
- /package/dist/{dev-entry.d.ts → core/main.d.ts} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,60 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.6.0-beta
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 2898d02: Extract shared definitions and contracts into core and local orchestration into
|
|
8
|
+
CLI. Harness becomes execution-only; the SDK no longer installs the engine and
|
|
9
|
+
Runtime no longer depends on the SDK. Author applications through agents and
|
|
10
|
+
install cli for the unchanged nylorun commands. See the package architecture and
|
|
11
|
+
migration guide. Cloud installs published packages from npm independently.
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- 41e613c: Ship the local SDK registry workflow with an independent SQLite Runtime, connected tool executor, authenticated Studio proxy, and a text-and-tool starter. Replace the legacy Hono starter and AG-UI transport. Require Node 24 and include the SDK in exact release compatibility pins.
|
|
16
|
+
|
|
17
|
+
Break the Harness execution import from `/engine` to `/run` and rename hosted execution APIs to durable execution APIs, including RunBinding, BoundRunOptions, and createRunState. Update all consumers without compatibility aliases; retain persisted checkpoint fields and version pins.
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Pin core to the tested release.
|
|
22
|
+
- Pin harness to the tested release.
|
|
23
|
+
- Updated dependencies [41e613c]
|
|
24
|
+
- Updated dependencies [2898d02]
|
|
25
|
+
- Updated dependencies
|
|
26
|
+
- @nylorun/core@0.1.1-beta
|
|
27
|
+
- @nylorun/harness@0.15.0-beta
|
|
28
|
+
|
|
29
|
+
## 0.5.0-beta
|
|
30
|
+
|
|
31
|
+
### Minor Changes
|
|
32
|
+
|
|
33
|
+
- Breaking beta: Runtime hosts use Harness `info` (`getInfo` / `SubmitOptions.info`) instead of
|
|
34
|
+
`scope`. Session scheduling stays in Runtime; Node-only adapters remain under
|
|
35
|
+
`@nylorun/runtime/node`. Compatible with Harness capability manifests and ToolDescriptor-only
|
|
36
|
+
model requests.
|
|
37
|
+
- c5bbb1a: Breaking beta: make Harness `run()` a direct async state-in/state-out executor with
|
|
38
|
+
serializable pauses, application `info`, cancellation signals, awaited recording, and
|
|
39
|
+
agent-level output schemas. Runtime owns session scheduling with memory-default or exclusive
|
|
40
|
+
local storage and imports Harness contracts. Isolate Node adapters under `runtime/node`, stream
|
|
41
|
+
observations incrementally, and add opt-in bounded token previews with Studio reconciliation.
|
|
42
|
+
Migrate consumers and deployment guidance together; legacy event records remain archived, not
|
|
43
|
+
automatically replayed.
|
|
44
|
+
|
|
45
|
+
### Patch Changes
|
|
46
|
+
|
|
47
|
+
- Remove the experimental Cloud Agents API destination client and related
|
|
48
|
+
`RuntimeConfig.cloud` / `NYLORUN_*` Cloud-mode wiring from OSS Runtime.
|
|
49
|
+
Local `openSession` remains the only destination. Cloud upgrades published
|
|
50
|
+
packages from npm independently.
|
|
51
|
+
- Ignore Hono Node `context.env` stream bindings (`incoming`/`outgoing`) when
|
|
52
|
+
resolving model environment so Node `nylorun dev` uses process `.env` /
|
|
53
|
+
`piModel` instead of an empty portable HTTP adapter.
|
|
54
|
+
- Update Runtime's canonical Harness dependency to the tested release.
|
|
55
|
+
- Updated dependencies [c5bbb1a]
|
|
56
|
+
- @nylorun/harness@0.13.0-beta
|
|
57
|
+
|
|
3
58
|
## 0.4.0-beta
|
|
4
59
|
|
|
5
60
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -1,65 +1,47 @@
|
|
|
1
1
|
# @nylorun/runtime
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The independent OSS HTTP execution host consumes `@nylorun/harness/run` and `@nylorun/core/contracts`. Cloud installs published `@nylorun/harness` from npm and does not import this Runtime package. Client authoring, sessions and connected executors belong to `@nylorun/agents`.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
import { Runtime, serveAgents } from "@nylorun/runtime";
|
|
5
|
+
Requires Node 24+. Build from the repository root:
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
```sh
|
|
8
|
+
npm install
|
|
9
|
+
npm run build --workspace @nylorun/core
|
|
10
|
+
npm run build --workspace @nylorun/harness
|
|
11
|
+
npm run build --workspace @nylorun/runtime
|
|
12
|
+
NYLORUN_SERVER_KEY='<separate-secret-at-least-16-characters>' npm start --workspace @nylorun/runtime
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
The application owns Hono composition, authentication, CORS, logging, process lifecycle, and deployment. Runtime owns agent sessions, durability, media, and AG-UI/session protocol routes. Graceful shutdown is optional: if the application installs signal handlers and wants to drain live sessions, flush pending journal writes, and run optional agent cleanup, it should await `runtime.close()`. An application that does not install handlers exits normally on its host's shutdown policy; `runtime.close()` does not run on crash, OOM, or SIGKILL.
|
|
18
|
-
|
|
19
|
-
Runtime publishes root-relative discovery and endpoint URLs. It infers the Hono
|
|
20
|
-
mount from each request URL (so a separate consumer `hono` install still works).
|
|
21
|
-
Mount at `/agents` or `/api/agents` without repeating that path in `serveAgents`.
|
|
22
|
-
Pass explicit `basePath` when a reverse proxy rewrites the public prefix.
|
|
23
|
-
|
|
24
|
-
`nylorun dev` enables local Studio connections automatically by setting `NYLORUN_DEV=1` for its child application. This allows HTTP/HTTPS browser origins on `localhost`, `127.0.0.1`, or `[::1]`, including Studio's fallback ports. Ordinary production startup does not enable this policy; the application owns production CORS and authorization.
|
|
25
|
-
|
|
26
|
-
`getActor(context)` supplies an optional actor id and session context for newly created sessions. `getRequestMetadata(context)` supplies JSON-safe metadata for inbound messages. Application middleware remains responsible for authorizing every agent route.
|
|
15
|
+
Default address: `http://127.0.0.1:8787`. `HOST`, `PORT`, and `NYLORUN_SQLITE_PATH` configure binding and storage. Missing server credentials fail startup. The default model is a credential-free scripted development response. It does not simulate conversations, tools or provider compatibility.
|
|
27
16
|
|
|
28
|
-
|
|
17
|
+
`NYLORUN_EXECUTORS_JSON` is an array of `{token, agentId, manifestHash, implementationVersion}`. Each secret must differ from the application server key and every other executor token. The manifest hash is available from `@nylorun/core/compatibility` or saved definition registration. SDK clients use `NYLORUN_RUNTIME_URL`, `NYLORUN_SERVER_KEY`, and `NYLORUN_EXECUTOR_KEY`; runtime executor scope is configured explicitly, never broadened by client input.
|
|
29
18
|
|
|
30
|
-
|
|
31
|
-
- `nylorun dev [--no-studio] [--no-open]`
|
|
32
|
-
- `nylorun start [entry]` (default: `dist/src/index.js`)
|
|
33
|
-
- `nylorun studio --agent-url http://localhost:3000/agents [--port 4161] [--no-open]`
|
|
19
|
+
For a model gateway, set `NYLORUN_MODEL_GATEWAY_URL`, `NYLORUN_MODEL_GATEWAY_KEY`, and `NYLORUN_MODEL`. The gateway receives `{model, call, context}` and returns a harness ModelCandidate or string. Provider credentials remain host configuration. The generic gateway requires an implementation of this envelope; it does not claim arbitrary provider wire compatibility. Alternatively supply a `ModelProvider` to `startRuntime`.
|
|
34
20
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
MODEL_PROVIDER_BASE_URL=https://your-provider.example/v1
|
|
21
|
+
```ts
|
|
22
|
+
import { startRuntime } from '@nylorun/runtime/core';
|
|
23
|
+
const runtime = await startRuntime({
|
|
24
|
+
sqlitePath: './nylorun.sqlite',
|
|
25
|
+
serverToken: process.env.NYLORUN_SERVER_KEY!,
|
|
26
|
+
executors: [], // Configure exact scoped executor credentials before customer actions.
|
|
27
|
+
port: 8787,
|
|
28
|
+
});
|
|
29
|
+
// Application owns lifecycle.
|
|
30
|
+
await runtime.close();
|
|
46
31
|
```
|
|
47
32
|
|
|
48
|
-
|
|
33
|
+
The session-first `/v1` API is specified in [HOST_CONTRACT.md](../harness/HOST_CONTRACT.md). `/health` confirms HTTP liveness; `/ready` checks SQLite and scheduler availability. Readiness is not a provider connectivity probe or functional correctness claim. Application tokens authorize definition/session APIs, while exact scoped executor credentials authorize authenticated SSE `/v1/executors/connect`, action discovery, claims, renewal and results. Session observers cannot claim actions.
|
|
49
34
|
|
|
50
|
-
|
|
35
|
+
SQLite transactions persist session checkpoints, command receipts, individual effects/actions, waits and canonical history. Actions are committed before notifications. Accepted execution is detached from HTTP request lifetime. Restart schedules persisted runnable sessions; model intents lacking recorded outcomes become uncertain. Expired customer claims become uncertain and are not automatically repeated. `GET /v1/sessions/:id` exposes waits, outstanding actions and uncertain effect summaries. Cancellation ends the current turn; a later message can start another turn from the state preceding the cancelled turn. Canonical events and uncertain external work remain inspectable. Reconciliation operations are not implemented in this pass.
|
|
51
36
|
|
|
52
|
-
|
|
37
|
+
One process owns each SQLite database. A local PID lock rejects concurrent owners and recovers only when the recorded process no longer exists. Shared/network filesystems and multiple replicas are unsupported. Keep the database and its WAL/journal together; do not delete persisted effects separately from checkpoints. Invalid lock contents or PID reuse fail closed and require operator inspection. TLS and external ingress belong to deployment infrastructure.
|
|
53
38
|
|
|
54
|
-
|
|
39
|
+
## Local project workflow
|
|
55
40
|
|
|
56
|
-
|
|
41
|
+
Install `@nylorun/cli` (generated projects already include it). Use `npm run configure`, then `nylorun dev` in a generated project. It loads the exported `agents` registry from `agents/index.ts`, starts this Runtime in a separate process, registers manifests, connects scoped SDK executors, and opens Studio. Use `--no-studio` or `--no-open` as needed. Runtime binds loopback on port 8787 (`PORT` override). The CLI creates separate server and executor credentials with mode 0600 in `.nylorun/local-credentials.json`; SQLite defaults to `.nylorun/runtime.sqlite`.
|
|
57
42
|
|
|
58
|
-
|
|
59
|
-
2. Translate `model.json` fields `provider`, `model`, and `custom.baseUrl` into `MODEL_PROVIDER`, `MODEL`, and `MODEL_PROVIDER_BASE_URL`. Copy API keys into `MODEL_PROVIDER_API_KEY` or provider-native variables. Replace the old `NYLO_CUSTOM_API_KEY` variable with `MODEL_PROVIDER_API_KEY`.
|
|
60
|
-
3. Merge `integrations.env` variables into `.env`. Move OAuth records into `.nylorun/auth.json`. Add `.env`, `.env.local`, and `.nylorun/` to `.gitignore`; remove the old `.env/` exceptions.
|
|
61
|
-
4. Replace the entrypoint's `serve(...)` call and Node adapter import with `export default app`. Set scripts to `"dev": "nylorun dev"` and `"start": "nylorun start"`. Remove the application's `@hono/node-server` dependency if unused elsewhere. Keep your build and asset-copy steps.
|
|
43
|
+
`nylorun start [entry]` loads `dist/agents/index.js` by default and runs without Studio/watch. `nylorun studio --runtime-url http://127.0.0.1:8787` attaches using the project's local server credential (or `NYLORUN_SERVER_KEY`). Provider selection uses the existing `MODEL_PROVIDER`, `MODEL`, `MODEL_PROVIDER_API_KEY`, and optional `MODEL_PROVIDER_BASE_URL` configuration. No provider request occurs during configuration.
|
|
62
44
|
|
|
63
|
-
|
|
45
|
+
Definitions have no `agent.run()`; applications use `@nylorun/agents`. Remove old Hono `src/index.ts`, `Runtime`, `serveAgents`, and `openSession` usage from supported starters. Historical implementations remain internal for regression coverage and advanced examples; they are not root exports or supported hosting alternatives.
|
|
64
46
|
|
|
65
|
-
|
|
47
|
+
Source changes restart the local stack. Start a new session after definition or implementation edits; live upgrades are deferred. `GET /v1/agents` and `GET /v1/sessions?agentId=...` are server-authenticated local discovery conveniences. See the repository handoff for verification and remaining scope.
|
package/dist/adapters/media.d.ts
CHANGED
|
@@ -1,16 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export interface MediaAsset {
|
|
4
|
-
readonly id: string;
|
|
5
|
-
readonly mediaType: string;
|
|
6
|
-
readonly bytes: number;
|
|
7
|
-
readonly kind: "input" | "generated";
|
|
8
|
-
}
|
|
9
|
-
/** Opaque reference retained by Harness and resolved by the configured media adapter. */
|
|
10
|
-
export interface MediaReference {
|
|
11
|
-
readonly agentId: string;
|
|
12
|
-
readonly assetId: string;
|
|
13
|
-
}
|
|
1
|
+
import { type MediaAsset, type MediaReference } from "../media.js";
|
|
2
|
+
export * from "../media.js";
|
|
14
3
|
/** Explicit local asset store; agents receive only opaque references. */
|
|
15
4
|
export declare class MediaStore {
|
|
16
5
|
private readonly root;
|
|
@@ -30,11 +19,6 @@ export declare class MediaStore {
|
|
|
30
19
|
private readMetadata;
|
|
31
20
|
private directory;
|
|
32
21
|
}
|
|
33
|
-
/** Decode one canonical base64 image before it is persisted or sent to a provider. */
|
|
34
|
-
export declare function decodeImageBase64(mediaType: string, base64: string): Uint8Array;
|
|
35
|
-
/** Verify the asserted media type and lightweight file signature for a supported image. */
|
|
36
|
-
export declare function validateImageBytes(mediaType: string, bytes: Uint8Array): void;
|
|
37
22
|
export declare function localMedia(options?: {
|
|
38
23
|
root?: string;
|
|
39
24
|
}): MediaStore;
|
|
40
|
-
export type RuntimeMedia = Pick<MediaStore, "saveInput" | "saveGenerated" | "dataUrl" | "latestInput" | "read">;
|
package/dist/adapters/media.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import { mkdir, readFile, readdir, writeFile } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
"image/png",
|
|
7
|
-
"image/webp",
|
|
8
|
-
]);
|
|
9
|
-
export const MAX_IMAGE_BYTES = 8 * 1024 * 1024;
|
|
4
|
+
import { IMAGE_MEDIA_TYPES, MAX_IMAGE_BYTES, decodeImageBase64, validateImageBytes, } from "../media.js";
|
|
5
|
+
export * from "../media.js";
|
|
10
6
|
/** Explicit local asset store; agents receive only opaque references. */
|
|
11
7
|
export class MediaStore {
|
|
12
8
|
root;
|
|
@@ -91,52 +87,6 @@ export class MediaStore {
|
|
|
91
87
|
}
|
|
92
88
|
}
|
|
93
89
|
/** Decode one canonical base64 image before it is persisted or sent to a provider. */
|
|
94
|
-
export function decodeImageBase64(mediaType, base64) {
|
|
95
|
-
if (!IMAGE_MEDIA_TYPES.includes(mediaType))
|
|
96
|
-
throw new Error("Only JPEG, PNG, and WebP images are supported.");
|
|
97
|
-
if (typeof base64 !== "string" || base64 === "")
|
|
98
|
-
throw new Error("Image data is required.");
|
|
99
|
-
if (base64.length % 4 !== 0 || !/^[A-Za-z0-9+/]*={0,2}$/u.test(base64))
|
|
100
|
-
throw new Error("Image data must be canonical base64.");
|
|
101
|
-
const bytes = Buffer.from(base64, "base64");
|
|
102
|
-
if (bytes.toString("base64") !== base64)
|
|
103
|
-
throw new Error("Image data must be canonical base64.");
|
|
104
|
-
validateImageBytes(mediaType, bytes);
|
|
105
|
-
return bytes;
|
|
106
|
-
}
|
|
107
|
-
/** Verify the asserted media type and lightweight file signature for a supported image. */
|
|
108
|
-
export function validateImageBytes(mediaType, bytes) {
|
|
109
|
-
if (!IMAGE_MEDIA_TYPES.includes(mediaType))
|
|
110
|
-
throw new Error("Only JPEG, PNG, and WebP images are supported.");
|
|
111
|
-
if (bytes.byteLength === 0 || bytes.byteLength > MAX_IMAGE_BYTES)
|
|
112
|
-
throw new Error("Images must be no larger than 8 MiB.");
|
|
113
|
-
const signature = mediaType === "image/jpeg"
|
|
114
|
-
? bytes.byteLength >= 3 &&
|
|
115
|
-
bytes[0] === 0xff &&
|
|
116
|
-
bytes[1] === 0xd8 &&
|
|
117
|
-
bytes[2] === 0xff
|
|
118
|
-
: mediaType === "image/png"
|
|
119
|
-
? bytes.byteLength >= 8 &&
|
|
120
|
-
bytes[0] === 0x89 &&
|
|
121
|
-
bytes[1] === 0x50 &&
|
|
122
|
-
bytes[2] === 0x4e &&
|
|
123
|
-
bytes[3] === 0x47 &&
|
|
124
|
-
bytes[4] === 0x0d &&
|
|
125
|
-
bytes[5] === 0x0a &&
|
|
126
|
-
bytes[6] === 0x1a &&
|
|
127
|
-
bytes[7] === 0x0a
|
|
128
|
-
: bytes.byteLength >= 12 &&
|
|
129
|
-
bytes[0] === 0x52 &&
|
|
130
|
-
bytes[1] === 0x49 &&
|
|
131
|
-
bytes[2] === 0x46 &&
|
|
132
|
-
bytes[3] === 0x46 &&
|
|
133
|
-
bytes[8] === 0x57 &&
|
|
134
|
-
bytes[9] === 0x45 &&
|
|
135
|
-
bytes[10] === 0x42 &&
|
|
136
|
-
bytes[11] === 0x50;
|
|
137
|
-
if (!signature)
|
|
138
|
-
throw new Error(`Image bytes do not match ${mediaType}.`);
|
|
139
|
-
}
|
|
140
90
|
function validAsset(value) {
|
|
141
91
|
if (!value || typeof value !== "object")
|
|
142
92
|
return false;
|
package/dist/adapters/observe.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { appendFile, mkdir } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import { scrub } from "
|
|
3
|
+
import { scrub } from "../redact.js";
|
|
4
4
|
import { projectSecrets } from "../model/settings.js";
|
|
5
5
|
/** Local JSONL observer. Writes raw engine events beside session durability files. */
|
|
6
6
|
export function jsonlObserver(options) {
|
package/dist/config.d.ts
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type { RuntimeMedia } from "./
|
|
1
|
+
import type { ModelAdapter } from "@nylorun/core/define";
|
|
2
|
+
import type { SessionStore } from "./sessions/store.js";
|
|
3
|
+
import type { RuntimeMedia } from "./media.js";
|
|
4
|
+
import type { ModelEnvironment } from "./model/http-model.js";
|
|
4
5
|
export interface RuntimeConfig {
|
|
5
|
-
readonly onModelCall?:
|
|
6
|
-
readonly
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
readonly durability?: RuntimeDurability;
|
|
6
|
+
readonly onModelCall?: ModelAdapter;
|
|
7
|
+
readonly createModel?: (options: import("./model/defaults.js").ModelFactoryOptions) => ModelAdapter;
|
|
8
|
+
readonly observer?: (event: {
|
|
9
|
+
readonly type: string;
|
|
10
|
+
}) => void | Promise<void>;
|
|
11
|
+
readonly sessions?: SessionStore;
|
|
12
12
|
readonly media?: RuntimeMedia;
|
|
13
|
+
readonly environment?: ModelEnvironment;
|
|
14
|
+
readonly tokens?: boolean;
|
|
15
|
+
readonly delivery?: {
|
|
16
|
+
readonly previewBytes?: number;
|
|
17
|
+
readonly eventBytes?: number;
|
|
18
|
+
readonly eventCount?: number;
|
|
19
|
+
};
|
|
13
20
|
}
|
package/dist/contracts.d.ts
CHANGED
|
@@ -1,166 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
export type JsonValue
|
|
3
|
-
export type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export type UserContentPart = {
|
|
7
|
-
readonly type: "text";
|
|
8
|
-
readonly text: string;
|
|
9
|
-
} | {
|
|
10
|
-
readonly type: "media";
|
|
11
|
-
readonly mediaType: string;
|
|
12
|
-
readonly reference: JsonValue;
|
|
13
|
-
};
|
|
14
|
-
export type MessageInput = string | {
|
|
15
|
-
readonly text: string;
|
|
16
|
-
readonly metadata?: JsonObject;
|
|
17
|
-
} | {
|
|
18
|
-
readonly content: readonly UserContentPart[];
|
|
19
|
-
readonly metadata?: JsonObject;
|
|
20
|
-
};
|
|
21
|
-
export type InteractionReply = {
|
|
22
|
-
readonly kind: "approve";
|
|
23
|
-
readonly interactionId: string;
|
|
24
|
-
readonly approved: boolean;
|
|
25
|
-
} | {
|
|
26
|
-
readonly kind: "respond";
|
|
27
|
-
readonly interactionId: string;
|
|
28
|
-
readonly value: JsonValue;
|
|
29
|
-
};
|
|
30
|
-
export type RuntimeInput = MessageInput | InteractionReply;
|
|
31
|
-
export type RuntimeInputEvent = InteractionReply | {
|
|
32
|
-
readonly kind: "user-message" | "interrupt";
|
|
33
|
-
readonly text?: string;
|
|
34
|
-
readonly content?: readonly UserContentPart[];
|
|
35
|
-
};
|
|
36
|
-
/** Lifecycle events are delivered in completion order; other events are diagnostics. */
|
|
37
|
-
export interface RuntimeEvent {
|
|
38
|
-
readonly type: string;
|
|
39
|
-
readonly output?: JsonValue;
|
|
40
|
-
readonly event?: RuntimeInputEvent;
|
|
41
|
-
readonly interaction?: unknown;
|
|
42
|
-
readonly attributes?: unknown;
|
|
43
|
-
readonly tripwire?: {
|
|
44
|
-
readonly code: string;
|
|
45
|
-
readonly message?: string;
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
export interface RuntimeCompletion {
|
|
49
|
-
readonly status: "completed" | "waiting" | "rejected" | "cancelled" | "stopped";
|
|
50
|
-
readonly events: readonly RuntimeEvent[];
|
|
51
|
-
}
|
|
52
|
-
export interface RuntimeSession {
|
|
53
|
-
readonly id: string;
|
|
54
|
-
input(event: RuntimeInput, options?: {
|
|
55
|
-
readonly signal?: AbortSignal;
|
|
56
|
-
}): {
|
|
57
|
-
readonly completed: Promise<RuntimeCompletion>;
|
|
58
|
-
};
|
|
59
|
-
stream(): AsyncIterable<RuntimeEvent>;
|
|
60
|
-
stop(reason?: string): Promise<void>;
|
|
61
|
-
}
|
|
62
|
-
export interface RuntimeRunOptions {
|
|
63
|
-
readonly id?: string;
|
|
64
|
-
readonly userId?: string;
|
|
65
|
-
readonly context?: JsonObject;
|
|
66
|
-
readonly onModelCall: RuntimeModelAdapter;
|
|
67
|
-
readonly observer?: {
|
|
68
|
-
(event: {
|
|
69
|
-
readonly type: string;
|
|
70
|
-
}): void | Promise<void>;
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
export interface RuntimeAgent {
|
|
74
|
-
readonly id: string;
|
|
75
|
-
readonly name: string;
|
|
76
|
-
readonly manifest: {
|
|
77
|
-
readonly id: string;
|
|
78
|
-
readonly name: string;
|
|
79
|
-
};
|
|
80
|
-
run(options: RuntimeRunOptions): RuntimeSession;
|
|
81
|
-
close?(): Promise<void>;
|
|
82
|
-
}
|
|
83
|
-
export type PromptContentPart = Exclude<UserContentPart, {
|
|
84
|
-
readonly type: "text";
|
|
85
|
-
}> | {
|
|
86
|
-
readonly type: "text" | "reasoning";
|
|
87
|
-
readonly text: string;
|
|
88
|
-
readonly providerMetadata?: JsonObject;
|
|
89
|
-
} | {
|
|
90
|
-
readonly type: "tool-call";
|
|
91
|
-
readonly providerMetadata?: JsonObject;
|
|
92
|
-
readonly id: string;
|
|
93
|
-
readonly name: string;
|
|
94
|
-
readonly args: JsonObject;
|
|
95
|
-
};
|
|
96
|
-
export type PromptItem = {
|
|
97
|
-
readonly kind: "instructions";
|
|
98
|
-
readonly role: "system";
|
|
99
|
-
readonly content: readonly PromptContentPart[];
|
|
100
|
-
} | {
|
|
101
|
-
readonly kind: "message";
|
|
102
|
-
readonly role: "user" | "assistant";
|
|
103
|
-
readonly content: readonly PromptContentPart[];
|
|
104
|
-
} | {
|
|
105
|
-
readonly kind: "context";
|
|
106
|
-
readonly role: "user";
|
|
107
|
-
readonly content: readonly PromptContentPart[];
|
|
108
|
-
} | {
|
|
109
|
-
readonly kind: "tool-result";
|
|
110
|
-
readonly toolCallId: string;
|
|
111
|
-
readonly toolName: string;
|
|
112
|
-
readonly status: "completed" | "denied" | "failed";
|
|
113
|
-
readonly content: readonly PromptContentPart[];
|
|
114
|
-
};
|
|
115
|
-
export interface RuntimeModelCall {
|
|
116
|
-
readonly sessionId: string;
|
|
117
|
-
readonly prompt: readonly PromptItem[];
|
|
118
|
-
readonly tools: readonly {
|
|
119
|
-
readonly name: string;
|
|
120
|
-
readonly description?: string;
|
|
121
|
-
readonly inputSchema: JsonObject;
|
|
122
|
-
}[];
|
|
123
|
-
readonly outputSchema?: JsonObject;
|
|
124
|
-
readonly model?: {
|
|
125
|
-
readonly id?: string;
|
|
126
|
-
readonly controls?: {
|
|
127
|
-
readonly temperature?: number;
|
|
128
|
-
readonly maxOutputTokens?: number;
|
|
129
|
-
};
|
|
130
|
-
readonly config?: JsonObject;
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
export interface RuntimeModelCandidate {
|
|
134
|
-
readonly output: readonly ({
|
|
135
|
-
readonly type: "text" | "reasoning";
|
|
136
|
-
readonly text: string;
|
|
137
|
-
readonly providerMetadata?: JsonObject;
|
|
138
|
-
} | {
|
|
139
|
-
readonly type: "json";
|
|
140
|
-
readonly value: JsonValue;
|
|
141
|
-
} | {
|
|
142
|
-
readonly type: "tool-call";
|
|
143
|
-
readonly providerMetadata?: JsonObject;
|
|
144
|
-
readonly id: string;
|
|
145
|
-
readonly name: string;
|
|
146
|
-
readonly args: JsonObject;
|
|
147
|
-
})[];
|
|
148
|
-
readonly finishReason?: "stop" | "length" | "tool-calls" | "content-filter" | "other";
|
|
149
|
-
readonly usage?: {
|
|
150
|
-
readonly inputTokens?: number;
|
|
151
|
-
readonly outputTokens?: number;
|
|
152
|
-
readonly totalTokens?: number;
|
|
153
|
-
readonly costUsd?: number;
|
|
154
|
-
};
|
|
155
|
-
readonly evidence?: {
|
|
156
|
-
readonly resolvedModel?: string;
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
export interface RuntimeModelContext {
|
|
160
|
-
readonly signal: AbortSignal;
|
|
161
|
-
reportPreparedCall?(prepared: {
|
|
162
|
-
readonly adapter: string;
|
|
163
|
-
readonly call: JsonValue;
|
|
164
|
-
}): void;
|
|
165
|
-
}
|
|
166
|
-
export type RuntimeModelAdapter = (call: RuntimeModelCall, context: RuntimeModelContext) => Promise<RuntimeModelCandidate>;
|
|
1
|
+
/** Execution contracts are owned by Harness. */
|
|
2
|
+
export type { JsonValue, JsonObject, MessageInput, UserContentPart, PromptContentPart, PromptItem, ModelCall as RuntimeModelCall, ModelCandidate as RuntimeModelCandidate, ModelAdapter as RuntimeModelAdapter, ModelAdapterContext as RuntimeModelContext, InputEvent as RuntimeInputEvent } from "@nylorun/core/define";
|
|
3
|
+
export type { ExecutionInput as RuntimeInput, RunResult as RuntimeCompletion, ExecutionEvent as RuntimeEvent, Session, Turn, Event, Result, InputAccepted, AgentIdentity } from "@nylorun/harness";
|
|
4
|
+
export type { RunBinding, BoundRunOptions, } from "@nylorun/harness/run";
|
|
5
|
+
export type RuntimeAgent = import("@nylorun/core/define").BuiltAgent<any, any>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { piModel } from "../model/pi-model.js";
|
|
2
|
+
import { startRuntime } from "./runtime.js";
|
|
3
|
+
import { gatewayModel, scriptedModel, toolFixtureModel } from "./provider.js";
|
|
4
|
+
const serverToken = process.env.NYLORUN_SERVER_KEY;
|
|
5
|
+
if (!serverToken)
|
|
6
|
+
throw new Error("Set NYLORUN_SERVER_KEY (at least 16 characters)");
|
|
7
|
+
const executors = JSON.parse(process.env.NYLORUN_EXECUTORS_JSON ?? "[]");
|
|
8
|
+
const configured = piModel();
|
|
9
|
+
const projectModel = (effect, signal) => configured(effect.input, {
|
|
10
|
+
request: effect.context.request,
|
|
11
|
+
invocationId: String(effect.context.invocationId),
|
|
12
|
+
signal,
|
|
13
|
+
reportPreparedCall() { },
|
|
14
|
+
});
|
|
15
|
+
const model = process.env.NYLORUN_DEV_MODEL === "fixture"
|
|
16
|
+
? toolFixtureModel()
|
|
17
|
+
: process.env.NYLORUN_PROJECT_PROVIDER === "1"
|
|
18
|
+
? projectModel
|
|
19
|
+
: process.env.NYLORUN_MODEL_GATEWAY_URL
|
|
20
|
+
? gatewayModel({
|
|
21
|
+
url: process.env.NYLORUN_MODEL_GATEWAY_URL,
|
|
22
|
+
token: process.env.NYLORUN_MODEL_GATEWAY_KEY ?? "",
|
|
23
|
+
model: process.env.NYLORUN_MODEL ?? "",
|
|
24
|
+
})
|
|
25
|
+
: scriptedModel(process.env.NYLORUN_SCRIPTED_OUTPUT);
|
|
26
|
+
const runtime = await startRuntime({
|
|
27
|
+
sqlitePath: process.env.NYLORUN_SQLITE_PATH ?? "./nylorun.sqlite",
|
|
28
|
+
serverToken,
|
|
29
|
+
executors,
|
|
30
|
+
model,
|
|
31
|
+
port: Number(process.env.PORT ?? 8787),
|
|
32
|
+
hostname: process.env.HOST ?? "127.0.0.1",
|
|
33
|
+
});
|
|
34
|
+
console.log(`Nylorun Runtime listening at ${runtime.url}`);
|
|
35
|
+
process.send?.({ type: "ready", url: runtime.url });
|
|
36
|
+
let closing;
|
|
37
|
+
for (const signal of ["SIGINT", "SIGTERM"])
|
|
38
|
+
process.on(signal, () => {
|
|
39
|
+
closing ??= runtime.close().then(() => { process.exit(0); });
|
|
40
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { HostEffect } from "@nylorun/harness/run";
|
|
2
|
+
/** Providers are runtime-owned; neither credentials nor model selection enter manifests. */
|
|
3
|
+
export type ModelProvider = (effect: HostEffect, signal: AbortSignal) => Promise<unknown>;
|
|
4
|
+
export declare function scriptedModel(output?: string): ModelProvider;
|
|
5
|
+
/** A configured gateway receives the complete harness model call, including history and schemas. */
|
|
6
|
+
export declare function gatewayModel(options: {
|
|
7
|
+
url: string;
|
|
8
|
+
token: string;
|
|
9
|
+
model: string;
|
|
10
|
+
}): ModelProvider;
|
|
11
|
+
/** Deterministic release fixture; still uses the real engine and remote customer tool. */
|
|
12
|
+
export declare function toolFixtureModel(): ModelProvider;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export function scriptedModel(output = "Scripted development response") {
|
|
2
|
+
return async () => ({ output: [{ type: "text", text: output }] });
|
|
3
|
+
}
|
|
4
|
+
/** A configured gateway receives the complete harness model call, including history and schemas. */
|
|
5
|
+
export function gatewayModel(options) {
|
|
6
|
+
return async (effect, signal) => {
|
|
7
|
+
const response = await fetch(options.url, {
|
|
8
|
+
method: "POST",
|
|
9
|
+
signal,
|
|
10
|
+
headers: {
|
|
11
|
+
authorization: `Bearer ${options.token}`,
|
|
12
|
+
"content-type": "application/json",
|
|
13
|
+
},
|
|
14
|
+
body: JSON.stringify({
|
|
15
|
+
model: options.model,
|
|
16
|
+
call: effect.input,
|
|
17
|
+
context: effect.context,
|
|
18
|
+
}),
|
|
19
|
+
});
|
|
20
|
+
if (!response.ok)
|
|
21
|
+
throw new Error(`Model gateway returned ${response.status}`);
|
|
22
|
+
return response.json();
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/** Deterministic release fixture; still uses the real engine and remote customer tool. */
|
|
26
|
+
export function toolFixtureModel() {
|
|
27
|
+
return async (effect) => {
|
|
28
|
+
const call = effect.input;
|
|
29
|
+
const last = call.prompt.at(-1);
|
|
30
|
+
if (last?.kind === "tool-result")
|
|
31
|
+
return {
|
|
32
|
+
output: [
|
|
33
|
+
{
|
|
34
|
+
type: "text",
|
|
35
|
+
text: `Order lookup complete: ${last.content.map((part) => (part.type === "text" ? part.text : JSON.stringify(part))).join(" ")}`,
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
};
|
|
39
|
+
const users = call.prompt.filter((p) => p.kind === "message" && p.role === "user");
|
|
40
|
+
if (users.length > 1)
|
|
41
|
+
return {
|
|
42
|
+
output: [
|
|
43
|
+
{
|
|
44
|
+
type: "text",
|
|
45
|
+
text: `I remember: ${users[0].content.map((part) => (part.type === "text" ? part.text : "")).join(" ")}`,
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
output: [
|
|
51
|
+
{
|
|
52
|
+
type: "tool-call",
|
|
53
|
+
id: "fixture_lookup",
|
|
54
|
+
name: "lookup_order",
|
|
55
|
+
args: { orderId: "demo-123" },
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
}
|